From bb41c55622d160c321e491646c131221d46cb323 Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:48:35 +0000 Subject: [PATCH] Change usage of file pattern in reader --- calcium_imaging_automation/core/reader.py | 14 ++++++-------- examples/example_usage.py | 15 ++------------- examples/example_usage.sh | 1 + 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/calcium_imaging_automation/core/reader.py b/calcium_imaging_automation/core/reader.py index f1ccf9e..65d1630 100644 --- a/calcium_imaging_automation/core/reader.py +++ b/calcium_imaging_automation/core/reader.py @@ -6,11 +6,9 @@ class ReadAllPathsInFolder: def __init__( self, raw_data_folder: Path, - filetypes_of_interest: List[str], folder_read_pattern: str, - file_read_pattern: str, + file_read_pattern: list, ): - self.filetypes_of_interest = filetypes_of_interest self.folder_read_pattern = folder_read_pattern self.file_read_pattern = file_read_pattern @@ -25,19 +23,19 @@ def get_folders_first_layer(self, file_path: Path) -> List[Path]: def get_files_paths(self, folder: Path) -> List[Path]: return [ file - for filetype in self.filetypes_of_interest - for file in folder.rglob(f"*.{filetype}") + for pattern in self.folder_read_pattern + for file in folder.rglob(pattern) ] - def total_objects_by_filetype(self, folder: Path) -> dict: + def total_objects_by_format(self, folder: Path) -> dict: return { filetype: len(self.get_files_paths(folder)) - for filetype in self.filetypes_of_interest + for filetype in self.folder_read_pattern.split(".")[-1] } def max_session_number(self, filetype="tif", max_allowed=5) -> int: total_tif_number = [ - self.total_objects_by_filetype(dataset_path).get(filetype, 0) + self.total_objects_by_format(dataset_path).get(filetype, 0) for dataset_path in self.datasets_paths ] diff --git a/examples/example_usage.py b/examples/example_usage.py index 616138b..d3a48b5 100644 --- a/examples/example_usage.py +++ b/examples/example_usage.py @@ -9,7 +9,6 @@ def main( raw_data_path: Path, output_path: Path, - filetypes_of_interest: list, folder_read_pattern: str, file_read_pattern: str, ): @@ -25,7 +24,6 @@ def main( reader = ReadAllPathsInFolder( raw_data_path, - filetypes_of_interest, folder_read_pattern, file_read_pattern, ) @@ -53,13 +51,6 @@ def main( parser.add_argument( "output_path", type=Path, help="Path to the output data." ) - parser.add_argument( - "--filetypes", - type=list, - nargs="+", - help="Filetypes of interest.", - default=["tif", "bin"], - ) parser.add_argument( "--folder_read_pattern", type=str, @@ -68,22 +59,20 @@ def main( ) parser.add_argument( "--file_read_pattern", - type=str, + type=list, help="Glob pattern for reading files.", - default="*", + default=["*.tif", "*.bin"], ) args = parser.parse_args() raw_data_path = args.raw_data_path output_path = args.output_path - file_types = args.filetypes folder_read_pattern = args.folder_read_pattern file_read_pattern = args.file_read_pattern main( raw_data_path, output_path, - file_types, folder_read_pattern, file_read_pattern, ) diff --git a/examples/example_usage.sh b/examples/example_usage.sh index 890024f..9998c69 100755 --- a/examples/example_usage.sh +++ b/examples/example_usage.sh @@ -3,3 +3,4 @@ python ./examples/example_usage.py \ /nfs/winstor/margrie/SimonWeiler/RawData/Invivo_imaging/3photon_rotation/shared/ \ /ceph/margrie/laura/cimaut/ \ --folder_read_pattern '2*' \ + --file_read_pattern 'rotation_00001.tif, *.bin' \