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
21 changes: 4 additions & 17 deletions src/murfey/client/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,10 @@ def _find_context(self, file_path: Path) -> bool:
# SIM workflow checks
# -----------------------------------------------------------------------------
if (
# CryoSIM raw data files have no extension, and end with specific suffixes
not file_path.suffix
and file_path.stem.endswith(
(
# Bright field
"_BF",
# Fluorescent
"_BR",
"_BFR",
"_GR",
"_GFR",
"_BR_FL",
"_BFR_FL",
"_GR_FL",
"_GFR_FL",
)
)
# CryoSIM raw data files have no extension
# Bright field files end with "_BF"
# Processing will be triggered on fluorescent files ending with "_FL"
not file_path.suffix and file_path.stem.endswith(("_BF", "_FL"))
):
if (context := _get_context("SIMContext")) is None:
return False
Expand Down
12 changes: 2 additions & 10 deletions src/murfey/client/contexts/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ def post_transfer(
return None

# Look for raw data files
# These have no extensions, and end with one of the listed suffixes
if not transferred_file.suffix and transferred_file.stem.endswith(
(
# Only SIM raw data files ending with '_FL' should be processed
"_BR_FL",
"_BFR_FL",
"_GR_FL",
"_GFR_FL",
)
):
# These have no extensions, and end with "_FL"
if not transferred_file.suffix and transferred_file.stem.endswith("_FL"):
source = _get_source(transferred_file, environment)
if source is None:
logger.warning(f"No source found for file {transferred_file}")
Expand Down
50 changes: 30 additions & 20 deletions src/murfey/server/api/workflow_sim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import re
from functools import lru_cache
from pathlib import Path
from typing import Any

Expand All @@ -24,6 +25,34 @@
)


COLOR_LOOKUP = {
452: "blue",
525: "green",
605: "red",
655: "far_red",
}


@lru_cache(maxsize=1)
def get_otf_files(otf_dir: Path):
"""
Look for OTF files in the specified directory and match them to their wavelengths
"""
otf_files: dict[str, Path] = {}
pattern = r"(?<!\d)\d{3}(?!\d)" # Regex match for EXACTLY 3 consecutive digits (wavelength)
for file in otf_dir.glob("*"):
if (
file.is_file()
and file.suffix.endswith((".tif", ".tiff"))
and "otf" in file.stem.lower()
and (match := re.search(pattern, file.stem))
):
wavelength = int(match.group())
if color := COLOR_LOOKUP.get(wavelength):
otf_files[color] = file
return otf_files


class SIMDataFile(BaseModel):
file: Path

Expand All @@ -50,27 +79,8 @@ def request_sim_reconstruction(
logger.error("Error querying session information from database", exc_info=True)
return None

# Look for OTF files in the saved directory and match them to wavelengths
COLOR_LOOKUP = {
452: "blue",
525: "green",
605: "red",
655: "far_red",
}
otf_files: dict[str, Path] = {}
pattern = r"(?<!\d)\d{3}(?!\d)" # Regex match for EXACTLY 3 consecutive digits (wavelength)
for file in otf_dir.glob("*"):
if (
file.is_file()
and file.suffix.endswith((".tif", ".tiff"))
and "otf" in file.stem.lower()
and (match := re.search(pattern, file.stem))
):
wavelength = int(match.group())
if color := COLOR_LOOKUP.get(wavelength):
otf_files[color] = file

# If 4 matches weren't found, log as an error and exit early
otf_files = get_otf_files(otf_dir)
if len(otf_files) < 4:
logger.error(
f"One or more OTF files missing from {otf_dir}\n"
Expand Down
8 changes: 4 additions & 4 deletions tests/client/test_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
# Bright field
"visit/raw/CtrlApr_G2/20260703_132856_CtrlApr_G2_F3A_BF",
# Fluorescent
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_BR",
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_BFR",
"visit/raw/44drug_G2/20260703_114348_44drug_G2_E2DR_GR",
"visit/raw/44drug_G2/20260703_113142_44drug_G2_E2DR_GFR",
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_B_FL",
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_G_FL",
"visit/raw/44drug_G2/20260703_114348_44drug_G2_E2DR_R_FL",
"visit/raw/44drug_G2/20260703_113142_44drug_G2_E2DR_FR_FL",
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_BR_FL",
"visit/raw/SR002_G1/20260707_112417_SR002G1_F1F_BFR_FL",
"visit/raw/44drug_G2/20260703_114348_44drug_G2_E2DR_GR_FL",
Expand Down
Loading