File tree Expand file tree Collapse file tree 6 files changed +13
-69
lines changed
Expand file tree Collapse file tree 6 files changed +13
-69
lines changed Original file line number Diff line number Diff line change 11import argparse
22from pathlib import Path
33
4- from murfey .util .clem import convert_lif_to_tiff
4+ from murfey .util .clem . lif import convert_lif_to_tiff
55
66
77def run ():
Original file line number Diff line number Diff line change 11import argparse
22from pathlib import Path
33
4- from murfey .util .clem import convert_tiff_to_stack
4+ from murfey .util .clem . tiff import convert_tiff_to_stack
55
66
77def run ():
Original file line number Diff line number Diff line change 55from fastapi import APIRouter
66
77from murfey .server import _transport_object
8- from murfey .util .clem import convert_lif_to_tiff , convert_tiff_to_stack
8+ from murfey .util .clem .lif import convert_lif_to_tiff
9+ from murfey .util .clem .tiff import convert_tiff_to_stack
910from murfey .util .models import LifFileInfo , TiffSeriesInfo
1011
1112# Create APIRouter class object
Original file line number Diff line number Diff line change 1- """
2- Functions to call for processing LIF and TIFF files generated as part of the cryo-CLEM
3- workflow.
4- """
5-
6- import logging
7- from pathlib import Path
8- from typing import List , Optional
9-
10- from murfey .util .clem import lif , tiff
11-
12- # Create logger object to output messages with
13- logger = logging .getLogger ("murfey.util.clem" )
14-
15-
16- def convert_lif_to_tiff (
17- file : Path ,
18- root_folder : str , # Name of the folder to treat as the root folder for LIF files
19- number_of_processes : int = 1 , # Number of processing threads to run
20- ):
21- """
22- Wrapper for the actual function in lif.py
23- """
24- result = lif .convert_lif_to_tiff (
25- file ,
26- root_folder ,
27- number_of_processes ,
28- )
29- if result :
30- return True
31- else :
32- return False
33-
34-
35- def convert_tiff_to_stack (
36- tiff_list : List [Path ], # List of TIFFs from a single series
37- root_folder : str , # Name of the folder to treat as the root folder for TIFF files
38- metadata_file : Optional [Path ] = None , # Option to manually provide metadata file
39- ):
40- """
41- Wrapper for the actual function in tiff.py
42- """
43- result = tiff .convert_tiff_to_stack (
44- tiff_list ,
45- root_folder ,
46- metadata_file ,
47- )
48- if result :
49- return True
50- else :
51- return False
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def process_lif_file(
2626 scene_num : int ,
2727 metadata : ET .Element ,
2828 save_dir : Path ,
29- ):
29+ ) -> bool :
3030 """
3131 Takes the LIF file and its corresponding metadata and loads the relevant sub-stack,
3232 with each channel as its own array. Rescales their intensity values to utilise the
@@ -141,7 +141,7 @@ def convert_lif_to_tiff(
141141 file : Path ,
142142 root_folder : str , # Name of the folder to treat as the root folder for LIF files
143143 number_of_processes : int = 1 , # Number of processing threads to run
144- ):
144+ ) -> bool :
145145 """
146146 Takes a LIF file, extracts its metadata as an XML tree, then parses through the
147147 sub-images stored inside it, saving each channel in the sub-image as a separate
@@ -198,7 +198,7 @@ def convert_lif_to_tiff(
198198 f"Subpath { sanitise (root_folder )} was not found in image path "
199199 f"{ sanitise (str (file ))} "
200200 )
201- return None
201+ return False
202202
203203 # Create folders if not already present
204204 processed_dir = Path ("/" .join (path_parts )).parent / file_name # Processed images
@@ -255,6 +255,5 @@ def convert_lif_to_tiff(
255255 result = pool .starmap (process_lif_file , pool_args )
256256
257257 if result :
258- return True
259- else :
260- return None
258+ return all (result )
259+ return False
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def process_tiff_files(
2626 tiff_list : List [Path ],
2727 metadata_file : Path ,
2828 save_dir : Path ,
29- ):
29+ ) -> bool :
3030 """
3131 Opens the TIFF files as NumPy arrays and stacks them.
3232 """
@@ -225,7 +225,7 @@ def convert_tiff_to_stack(
225225 f"Subpath { sanitise (root_folder )} was not found in file path "
226226 f"{ sanitise (str (parent_dir ))} "
227227 )
228- return None
228+ return False
229229 # Make directory for processed files
230230 processed_dir = Path ("/" .join (path_parts )) # Images
231231 if not processed_dir .exists ():
@@ -241,13 +241,8 @@ def convert_tiff_to_stack(
241241 logger .info (f"Metadata file found at { xml_file } " )
242242 else :
243243 logger .error (f"No metadata file found at { xml_file } " )
244- return None
244+ return False
245245 else :
246246 xml_file = metadata_file
247247
248- result = process_tiff_files (tiff_list , xml_file , processed_dir )
249-
250- if result :
251- return True
252- else :
253- return None
248+ return process_tiff_files (tiff_list , xml_file , processed_dir )
You can’t perform that action at this time.
0 commit comments