Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 7 additions & 42 deletions src/murfey/server/api/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
TiltSeries,
)
from murfey.util.models import ProcessingParametersSPA, ProcessingParametersTomo
from murfey.util.processing_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters, motion_corrected_mrc
from murfey.util.tomo import midpoint

logger = getLogger("murfey.server.api.workflow")
Expand Down Expand Up @@ -365,29 +365,7 @@
machine_config = get_machine_config(instrument_name=instrument_name)[
instrument_name
]
parts = [secure_filename(p) for p in Path(proc_file.path).parts]
visit_idx = parts.index(visit_name)
core = Path("/") / Path(*parts[: visit_idx + 1])
ppath = Path("/") / Path(*parts)
sub_dataset = ppath.relative_to(core).parts[0]
extra_path = machine_config.processed_extra_directory
for i, p in enumerate(ppath.parts):
if p.startswith("raw"):
movies_path_index = i
break
else:
raise ValueError(f"{proc_file.path} does not contain a raw directory")
mrc_out = (
core
/ machine_config.processed_directory_name
/ sub_dataset
/ extra_path
/ "MotionCorr"
/ "job002"
/ "Movies"
/ "/".join(ppath.parts[movies_path_index + 1 : -1])
/ str(ppath.stem + "_motion_corrected.mrc")
)
mrc_out = motion_corrected_mrc(Path(proc_file.path), visit_name, machine_config)

Check warning on line 368 in src/murfey/server/api/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/workflow.py#L368

Added line #L368 was not covered by tests
try:
collected_ids = db.exec(
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
Expand Down Expand Up @@ -491,7 +469,8 @@
_transport_object.send("processing_recipe", zocalo_message)
else:
logger.error(
f"Pe-processing was requested for {sanitise(ppath.name)} but no Zocalo transport object was found"
f"Pre-processing was requested for {sanitise(Path(proc_file.path).name)} "
"but no Zocalo transport object was found"
)
return proc_file

Expand Down Expand Up @@ -646,22 +625,7 @@
machine_config = get_machine_config(instrument_name=instrument_name)[
instrument_name
]
visit_idx = Path(proc_file.path).parts.index(visit_name)
core = Path(*Path(proc_file.path).parts[: visit_idx + 1])
ppath = Path("/".join(secure_filename(p) for p in Path(proc_file.path).parts))
sub_dataset = "/".join(ppath.relative_to(core).parts[:-1])
extra_path = machine_config.processed_extra_directory
mrc_out = (
core
/ machine_config.processed_directory_name
/ sub_dataset
/ extra_path
/ "MotionCorr"
/ "job002"
/ "Movies"
/ str(ppath.stem + "_motion_corrected.mrc")
)
mrc_out = Path("/".join(secure_filename(p) for p in mrc_out.parts))
mrc_out = motion_corrected_mrc(Path(proc_file.path), visit_name, machine_config)

Check warning on line 628 in src/murfey/server/api/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/workflow.py#L628

Added line #L628 was not covered by tests

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

Expand Down Expand Up @@ -732,7 +696,8 @@
_transport_object.send("processing_recipe", zocalo_message)
else:
logger.error(
f"Pe-processing was requested for {sanitise(ppath.name)} but no Zocalo transport object was found"
f"Pre-processing was requested for {sanitise(Path(proc_file.path).name)} "
f"but no Zocalo transport object was found"
)
return proc_file
else:
Expand Down
33 changes: 6 additions & 27 deletions src/murfey/server/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
get_microscope,
get_security_config,
)
from murfey.util.processing_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters, motion_corrected_mrc
from murfey.util.tomo import midpoint

logger = logging.getLogger("murfey.server.feedback")
Expand Down Expand Up @@ -106,37 +106,16 @@
).all()
if not complete_results:
return []
visit_name = complete_results[0][2].visit

Check warning on line 109 in src/murfey/server/feedback.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/feedback.py#L109

Added line #L109 was not covered by tests
instrument_name = complete_results[0][2].instrument_name
results = [r[0] for r in complete_results]
machine_config = get_machine_config(instrument_name=instrument_name)[
instrument_name
]

def _mc_path(mov_path: Path) -> str:
for p in mov_path.parts:
if "-" in p and p.startswith(("bi", "nr", "nt", "cm", "sw")):
visit_name = p
break
else:
raise ValueError(f"No visit found in {mov_path}")
visit_idx = Path(mov_path).parts.index(visit_name)
core = Path(*Path(mov_path).parts[: visit_idx + 1])
ppath = Path(mov_path)
sub_dataset = "/".join(ppath.relative_to(core).parts[:-1])
extra_path = machine_config.processed_extra_directory
mrc_out = (
core
/ machine_config.processed_directory_name
/ sub_dataset
/ extra_path
/ "MotionCorr"
/ "job002"
/ "Movies"
/ str(ppath.stem + "_motion_corrected.mrc")
)
return str(mrc_out)

return [_mc_path(Path(r.movie_path)) for r in results]
return [

Check warning on line 115 in src/murfey/server/feedback.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/feedback.py#L115

Added line #L115 was not covered by tests
str(motion_corrected_mrc(Path(r.movie_path), visit_name, machine_config))
for r in results
]


def get_job_ids(tilt_series_id: int, appid: int) -> JobIDs:
Expand Down
1 change: 1 addition & 0 deletions src/murfey/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MachineConfig(BaseModel): # type: ignore
processing_enabled: bool = True
process_by_default: bool = True
gain_directory_name: str = "processing"
process_multiple_datasets: bool = True
processed_directory_name: str = "processed"
processed_extra_directory: str = ""
recipes: dict[str, str] = {
Expand Down
30 changes: 30 additions & 0 deletions src/murfey/util/processing_params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
from pathlib import Path
from typing import Literal, Optional

from pydantic import BaseModel
from werkzeug.utils import secure_filename

from murfey.util.config import MachineConfig


def motion_corrected_mrc(
input_movie: Path, visit_name: str, machine_config: MachineConfig
):
parts = [secure_filename(p) for p in input_movie.parts]
visit_idx = parts.index(visit_name)
core = Path("/") / Path(*parts[: visit_idx + 1])
ppath = Path("/") / Path(*parts)

Check warning on line 16 in src/murfey/util/processing_params.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/processing_params.py#L13-L16

Added lines #L13 - L16 were not covered by tests
if machine_config.process_multiple_datasets:
sub_dataset = ppath.relative_to(core).parts[0]

Check warning on line 18 in src/murfey/util/processing_params.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/processing_params.py#L18

Added line #L18 was not covered by tests
else:
sub_dataset = ""
extra_path = machine_config.processed_extra_directory
mrc_out = (

Check warning on line 22 in src/murfey/util/processing_params.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/processing_params.py#L20-L22

Added lines #L20 - L22 were not covered by tests
core
/ machine_config.processed_directory_name
/ sub_dataset
/ extra_path
/ "MotionCorr"
/ "job002"
/ "Movies"
/ ppath.parent.relative_to(core / sub_dataset)
/ str(ppath.stem + "_motion_corrected.mrc")
)
return Path("/".join(secure_filename(p) for p in mrc_out.parts))

Check warning on line 33 in src/murfey/util/processing_params.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/processing_params.py#L33

Added line #L33 was not covered by tests


class CLEMAlignAndMergeParameters(BaseModel):
Expand Down