@@ -71,6 +71,9 @@ def __init__(
7171 )
7272
7373 def _find_extension (self , file_path : Path ):
74+ """
75+ Identifies the file extension and stores that information in the class.
76+ """
7477 if (
7578 required_substrings := self ._murfey_config .get (
7679 "data_required_substrings" , {}
@@ -81,28 +84,40 @@ def _find_extension(self, file_path: Path):
8184 if not any (r in file_path .name for r in required_substrings ):
8285 return []
8386
87+ # Checks for MRC, TIFF, TIF, and EER files if no extension has been defined
8488 if (
8589 file_path .suffix in (".mrc" , ".tiff" , ".tif" , ".eer" )
8690 and not self ._extension
8791 ):
8892 logger .info (f"File extension determined: { file_path .suffix } " )
8993 self ._extension = file_path .suffix
94+ # Check for TIFF, TIF, or EER if the file's already been assigned an extension
9095 elif (
9196 file_path .suffix in (".tiff" , ".tif" , ".eer" )
9297 and self ._extension != file_path .suffix
9398 ):
9499 logger .info (f"File extension re-evaluated: { file_path .suffix } " )
95100 self ._extension = file_path .suffix
101+ # Check for LIF files separately
96102 elif file_path .suffix == ".lif" :
97103 self ._extension = file_path .suffix
98104
99105 def _find_context (self , file_path : Path ) -> bool :
106+ """
107+ Using various conditionals, identifies what workflow the file is part of, and
108+ assigns the necessary context class to it for subsequent stages of processing
109+ """
110+
111+ # CLEM workflow check
112+ # Look for LIF files
100113 if file_path .suffix == ".lif" :
101114 self ._role = "detector"
102115 self ._context = CLEMContext ("leica" , self ._basepath )
103116 return True
117+
104118 split_file_name = file_path .name .split ("_" )
105119 if split_file_name :
120+ # Files starting with "FoilHole" belong to the SPA workflow
106121 if split_file_name [0 ].startswith ("FoilHole" ):
107122 if not self ._context :
108123 logger .info ("Acquisition software: EPU" )
@@ -123,9 +138,12 @@ def _find_context(self, file_path: Path) -> bool:
123138 else SPAContext ("epu" , self ._basepath )
124139 )
125140 self .parameters_model = ProcessingParametersSPA
141+ # Assign it the detector attribute if not already present
126142 if not self ._role :
127143 self ._role = "detector"
128144 return True
145+
146+ # Files starting with "Position" belong to the standard tomography workflow
129147 if (
130148 split_file_name [0 ] == "Position"
131149 or "[" in file_path .name
@@ -136,25 +154,34 @@ def _find_context(self, file_path: Path) -> bool:
136154 logger .info ("Acquisition software: tomo" )
137155 self ._context = TomographyContext ("tomo" , self ._basepath )
138156 self .parameters_model = PreprocessingParametersTomo
157+ # Assign role if not already present
139158 if not self ._role :
159+ # Fractions files attributed to the detector
140160 if (
141161 "Fractions" in split_file_name [- 1 ]
142162 or "fractions" in split_file_name [- 1 ]
143163 ):
144164 self ._role = "detector"
165+ # MDOC files attributed to the microscope
145166 elif (
146167 file_path .suffix == ".mdoc"
147168 or file_path .with_suffix (".mdoc" ).is_file ()
148169 ):
149170 self ._role = "microscope"
171+ # Attribute all other files to the detector
150172 else :
151173 self ._role = "detector"
152174 return True
175+
176+ # Files with these suffixes belong to the serial EM tomography workflow
153177 if file_path .suffix in (".mrc" , ".tiff" , ".tif" , ".eer" ):
178+ # Ignore batch files and search maps
154179 if any (p in file_path .parts for p in ("Batch" , "SearchMaps" )):
155180 return False
181+ # Ignore JPG files
156182 if file_path .with_suffix (".jpg" ).is_file ():
157183 return False
184+ # Ignore the averaged movies written out by the Falcon
158185 if (
159186 len (
160187 list (
@@ -165,7 +192,6 @@ def _find_context(self, file_path: Path) -> bool:
165192 )
166193 > 1
167194 ):
168- # This covers the case of ignoring the averaged movies written out by the Falcon
169195 return False
170196 self ._context = TomographyContext ("serialem" , self ._basepath )
171197 self .parameters_model = PreprocessingParametersTomo
0 commit comments