1414from functools import cached_property
1515from importlib .metadata import entry_points
1616from pathlib import Path
17- from typing import Literal , Optional
17+ from typing import Literal , Optional , TypeAlias
1818
1919from pydantic import BaseModel , computed_field
2020from sqlmodel import Session , select
2929
3030logger = logging .getLogger ("murfey.workflows.clem.register_preprocessing_results" )
3131
32+ ColorChannels : TypeAlias = Literal [
33+ "gray" , "red" , "green" , "blue" , "cyan" , "magenta" , "yellow"
34+ ]
35+
36+ CC_MODES = ("_ICC" , "_Lng_LVCC" , "_Lng_SVCC" )
37+
3238
3339class CLEMPreprocessingResult (BaseModel ):
3440 series_name : str
3541 number_of_members : int
3642 is_stack : bool
3743 is_montage : bool
38- output_files : dict [
39- Literal ["gray" , "red" , "green" , "blue" , "cyan" , "magenta" , "yellow" ], Path
40- ]
41- thumbnails : dict [
42- Literal ["gray" , "red" , "green" , "blue" , "cyan" , "magenta" , "yellow" ], Path
43- ] = {}
44+ output_files : dict [ColorChannels , Path ]
45+ thumbnails : dict [ColorChannels , Path ] = {}
4446 thumbnail_size : Optional [tuple [int , int ]] = None # height, width
4547 metadata : Path
4648 parent_lif : Optional [Path ] = None
47- parent_tiffs : dict [
48- Literal ["gray" , "red" , "green" , "blue" , "cyan" , "magenta" , "yellow" ], list [Path ]
49- ] = {}
49+ parent_tiffs : dict [ColorChannels , list [Path ]] = {}
5050 pixels_x : int
5151 pixels_y : int
5252 units : str
@@ -57,25 +57,37 @@ class CLEMPreprocessingResult(BaseModel):
5757 # Valid Pydantic decorator not supported by MyPy
5858 @computed_field # type: ignore
5959 @cached_property
60- def is_denoised (self ) -> bool :
60+ def is_cc (self ) -> bool :
6161 """
62- The "_Lng_LVCC" and "_Lng_SVCC" suffixes appended to a CLEM dataset's position
63- name indicate that it's a denoised image set of the same position. They should
64- override or supersede the original ones if they're present
62+ The "_ICC", " _Lng_LVCC", and "_Lng_SVCC" suffixes appended to a CLEM dataset's
63+ position name indicate that it's a computationally cleared image set of the
64+ same position. They should override or supersede the original ones if present.
6565 """
66- return any (
67- pattern in self .series_name for pattern in ("_Lng_LVCC" , "_Lng_SVCC" )
68- )
66+ return any (self .series_name .endswith (pattern ) for pattern in CC_MODES )
67+
68+ # Valid Pydantic decorator not supported by MyPy
69+ @computed_field # type: ignore
70+ @cached_property
71+ def cc_mode (self ) -> str | None :
72+ """
73+ Store the computational clearing mode used as an attribute
74+ """
75+ for pattern in CC_MODES :
76+ if self .series_name .endswith (pattern ):
77+ return pattern [1 :]
78+ return None
6979
7080 # Valid Pydantic decorator not supported by MyPy
7181 @computed_field # type: ignore
7282 @cached_property
7383 def site_name (self ) -> str :
7484 """
75- Extract just the name of the site by removing the "_Lng_LVCC" suffix from
85+ Extract just the name of the site by removing the clearing mode suffix from
7686 the series name.
7787 """
78- return self .series_name .replace ("_Lng_LVCC" , "" ).replace ("_Lng_SVCC" , "" )
88+ if self .cc_mode is not None :
89+ return self .series_name [: - (len (self .cc_mode ) + 1 )]
90+ return self .series_name
7991
8092 # Valid Pydantic decorator not supported by MyPy
8193 @computed_field # type: ignore
@@ -123,7 +135,7 @@ def _register_clem_imaging_site(
123135 """
124136 Creates an ImagingSite database entry for the current CLEM preprocessing result
125137 if one doesn't already exist, or modifies the existing one if it does. Each entry
126- corresponds to a unique site on the sample grid, and results containing denoised
138+ corresponds to a unique site on the sample grid, and results containing cleared
127139 data will supersede existing rows for the same position that contain only raw
128140 data. Returns the created/queried entry.
129141 """
@@ -186,8 +198,8 @@ def _populate(
186198 )
187199 clem_img_site = _populate (clem_img_site , result )
188200
189- # Prepare to overwrite existing entry if current result is a denoised dataset
190- if result .is_denoised :
201+ # Prepare to overwrite existing entry if current result is a cleared dataset
202+ if result .is_cc :
191203 # Proceed with overwrite if current result is different from existing entry
192204 output_file = list (result .output_files .values ())[0 ]
193205 if str (output_file .parent / "*.tiff" ) != clem_img_site .image_path :
0 commit comments