Skip to content

Commit f7681c9

Browse files
committed
Rewrote 'tiff_to_stack' function to work with Zocalo wrapper
1 parent a132b86 commit f7681c9

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

src/murfey/server/api/clem.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def lif_to_stack(
643643
)
644644

645645
# Use entry point if found
646-
if len(murfey_workflows) == 1:
646+
if murfey_workflows:
647647

648648
# Get instrument name from the database
649649
# This is needed in order to load the correct config file
@@ -673,6 +673,7 @@ def lif_to_stack(
673673
def tiff_to_stack(
674674
session_id: int, # Used by the decorator
675675
tiff_info: TIFFSeriesInfo,
676+
db: Session = murfey_db,
676677
):
677678
# Get command line entry point
678679
murfey_workflows = entry_points().select(
@@ -681,14 +682,26 @@ def tiff_to_stack(
681682

682683
# Use entry point if found
683684
if murfey_workflows:
685+
686+
# Load instrument name from database
687+
row: MurfeySession = db.exec(
688+
select(MurfeySession).where(MurfeySession.id == session_id)
689+
).one()
690+
instrument_name = row.instrument_name
691+
692+
# Pass arguments to correct workflow
684693
workflow: EntryPoint = list(murfey_workflows)[0]
685694
workflow.load()(
686695
# Match the arguments found in murfey.workflows.tiff_to_stack
687696
file=tiff_info.tiff_files[0], # Pass it only one file from the list
688697
root_folder="images",
698+
session_id=session_id,
699+
instrument_name=instrument_name,
689700
metadata=tiff_info.series_metadata,
690701
messenger=_transport_object,
691702
)
703+
return True
704+
692705
# Raise error if Murfey workflow not found
693706
else:
694707
raise RuntimeError("The relevant Murfey workflow was not found")

src/murfey/workflows/clem/tiff_to_stack.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,61 @@
66
from pathlib import Path
77
from typing import Optional
88

9+
from murfey.util.config import get_machine_config
10+
911
try:
1012
from murfey.server.ispyb import TransportManager # Session
1113
except AttributeError:
1214
pass # Ignore if ISPyB credentials environment variable not set
1315

1416

1517
def zocalo_cluster_request(
16-
file: Path,
18+
tiff_list: list[Path],
1719
root_folder: str,
20+
session_id: int,
21+
instrument_name: str,
1822
metadata: Optional[Path] = None,
1923
messenger: Optional[TransportManager] = None,
2024
):
2125
if messenger:
2226
# Construct path to session directory
23-
path_parts = list(file.parts)
24-
new_path = []
25-
for p in range(len(path_parts)):
26-
part = path_parts[p]
27-
# Remove leading slash for subsequent rejoining
28-
if part == "/":
29-
part = ""
30-
# Append up to, but not including, root folder
31-
if part.lower() == root_folder.lower():
32-
break
33-
new_path.append(part)
34-
session_dir = Path("/".join(new_path))
27+
path_parts = list(tiff_list[0].parts)
28+
# Replace leading "/" in Unix paths
29+
path_parts[0] = "" if path_parts[0] == "/" else path_parts[0]
30+
try:
31+
# Find the position of the root folder in the list
32+
root_index = [p.lower() for p in path_parts].index(root_folder.lower())
33+
except ValueError:
34+
raise Exception(
35+
f"Unable to find the root folder {root_folder!r} in the file path {tiff_list[0]!r}"
36+
)
37+
# Construct the session and job name
38+
session_dir = "/".join(path_parts[:root_index])
3539

3640
# If no metadata file provided, generate path to one
3741
if metadata is None:
38-
series_name = file.stem.split("--")[0]
39-
metadata = file.parent / "Metadata" / (series_name + ".xlif")
42+
series_name = tiff_list[0].stem.split("--")[0]
43+
metadata = tiff_list[0].parent / "Metadata" / (series_name + ".xlif")
44+
45+
# Load machine config to get the feedback queue
46+
machine_config = get_machine_config()
47+
feedback_queue = machine_config[instrument_name].feedback_queue
4048

4149
messenger.send(
4250
"processing_recipe",
4351
{
4452
"recipes": ["clem-tiff-to-stack"],
4553
"parameters": {
46-
"session_dir": str(session_dir),
47-
"tiff_path": str(file),
48-
"root_dir": root_folder,
54+
# Job parameters
55+
"tiff_list": tiff_list,
56+
"root_folder": root_folder,
4957
"metadata": str(metadata),
58+
"tiff_file": "null",
59+
# Other recipe parameters
60+
"session_dir": str(session_dir),
61+
"session_id": session_id,
62+
"job_name": series_name,
63+
"feedback_queue": feedback_queue,
5064
},
5165
},
5266
new_connection=True,

0 commit comments

Comments
 (0)