Skip to content

Commit a7215c0

Browse files
committed
Make those a common function
1 parent d63b6da commit a7215c0

File tree

2 files changed

+37
-43
lines changed

2 files changed

+37
-43
lines changed

src/murfey/server/api/workflow.py

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
TiltSeries,
5959
)
6060
from murfey.util.models import ProcessingParametersSPA, ProcessingParametersTomo
61-
from murfey.util.processing_params import default_spa_parameters
61+
from murfey.util.processing_params import default_spa_parameters, motion_corrected_mrc
6262
from murfey.util.tomo import midpoint
6363

6464
logger = getLogger("murfey.server.api.workflow")
@@ -365,26 +365,7 @@ async def request_spa_preprocessing(
365365
machine_config = get_machine_config(instrument_name=instrument_name)[
366366
instrument_name
367367
]
368-
parts = [secure_filename(p) for p in Path(proc_file.path).parts]
369-
visit_idx = parts.index(visit_name)
370-
core = Path("/") / Path(*parts[: visit_idx + 1])
371-
ppath = Path("/") / Path(*parts)
372-
if machine_config.process_multiple_datasets:
373-
sub_dataset = ppath.relative_to(core).parts[0]
374-
else:
375-
sub_dataset = ""
376-
extra_path = machine_config.processed_extra_directory
377-
mrc_out = (
378-
core
379-
/ machine_config.processed_directory_name
380-
/ sub_dataset
381-
/ extra_path
382-
/ "MotionCorr"
383-
/ "job002"
384-
/ "Movies"
385-
/ ppath.parent.relative_to(core / sub_dataset)
386-
/ str(ppath.stem + "_motion_corrected.mrc")
387-
)
368+
mrc_out = motion_corrected_mrc(Path(proc_file.path), visit_name, machine_config)
388369
try:
389370
collected_ids = db.exec(
390371
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
@@ -488,7 +469,8 @@ async def request_spa_preprocessing(
488469
_transport_object.send("processing_recipe", zocalo_message)
489470
else:
490471
logger.error(
491-
f"Pe-processing was requested for {sanitise(ppath.name)} but no Zocalo transport object was found"
472+
f"Pre-processing was requested for {sanitise(Path(proc_file.path).name)} "
473+
"but no Zocalo transport object was found"
492474
)
493475
return proc_file
494476

@@ -643,26 +625,7 @@ async def request_tomography_preprocessing(
643625
machine_config = get_machine_config(instrument_name=instrument_name)[
644626
instrument_name
645627
]
646-
parts = [secure_filename(p) for p in Path(proc_file.path).parts]
647-
visit_idx = parts.index(visit_name)
648-
core = Path("/") / Path(*parts[: visit_idx + 1])
649-
ppath = Path("/") / Path(*parts)
650-
if machine_config.process_multiple_datasets:
651-
sub_dataset = ppath.relative_to(core).parts[0]
652-
else:
653-
sub_dataset = ""
654-
extra_path = machine_config.processed_extra_directory
655-
mrc_out = (
656-
core
657-
/ machine_config.processed_directory_name
658-
/ sub_dataset
659-
/ extra_path
660-
/ "MotionCorr"
661-
/ "job002"
662-
/ "Movies"
663-
/ str(ppath.stem + "_motion_corrected.mrc")
664-
)
665-
mrc_out = Path("/".join(secure_filename(p) for p in mrc_out.parts))
628+
mrc_out = motion_corrected_mrc(Path(proc_file.path), visit_name, machine_config)
666629

667630
recipe_name = machine_config.recipes.get("em-tomo-preprocess", "em-tomo-preprocess")
668631

@@ -733,7 +696,8 @@ async def request_tomography_preprocessing(
733696
_transport_object.send("processing_recipe", zocalo_message)
734697
else:
735698
logger.error(
736-
f"Pe-processing was requested for {sanitise(ppath.name)} but no Zocalo transport object was found"
699+
f"Pre-processing was requested for {sanitise(Path(proc_file.path).name)} "
700+
f"but no Zocalo transport object was found"
737701
)
738702
return proc_file
739703
else:

src/murfey/util/processing_params.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
from pathlib import Path
12
from typing import Literal, Optional
23

34
from pydantic import BaseModel
5+
from werkzeug.utils import secure_filename
6+
7+
from murfey.util.config import MachineConfig
8+
9+
10+
def motion_corrected_mrc(
11+
input_movie: Path, visit_name: str, machine_config: MachineConfig
12+
):
13+
parts = [secure_filename(p) for p in input_movie.parts]
14+
visit_idx = parts.index(visit_name)
15+
core = Path("/") / Path(*parts[: visit_idx + 1])
16+
ppath = Path("/") / Path(*parts)
17+
if machine_config.process_multiple_datasets:
18+
sub_dataset = ppath.relative_to(core).parts[0]
19+
else:
20+
sub_dataset = ""
21+
extra_path = machine_config.processed_extra_directory
22+
mrc_out = (
23+
core
24+
/ machine_config.processed_directory_name
25+
/ sub_dataset
26+
/ extra_path
27+
/ "MotionCorr"
28+
/ "job002"
29+
/ "Movies"
30+
/ ppath.parent.relative_to(core / sub_dataset)
31+
/ str(ppath.stem + "_motion_corrected.mrc")
32+
)
33+
return Path("/".join(secure_filename(p) for p in mrc_out.parts))
434

535

636
class CLEMAlignAndMergeParameters(BaseModel):

0 commit comments

Comments
 (0)