From 6413c41d1d96833a07be1a39eb345ccd3054e678 Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 22 May 2026 14:41:19 +0200 Subject: [PATCH 1/4] fix: create data structure from ome.tif --- cellacdc/acdc_regex.py | 22 +++++++++++++++++++--- cellacdc/dataStruct.py | 5 ++++- cellacdc/load.py | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cellacdc/acdc_regex.py b/cellacdc/acdc_regex.py index fc355f4d..dfbcb53a 100644 --- a/cellacdc/acdc_regex.py +++ b/cellacdc/acdc_regex.py @@ -23,13 +23,29 @@ def get_function_names(text, include_class_methods=True): pattern = r'\ndef\s+([a-zA-Z_]\w*)\s*\(' return re.findall(pattern, text) -def is_alphanumeric_filename(text, allow_space=True): +def is_alphanumeric_filename( + text, + allow_space=True, + allowed: str | list[str] | None=None + ): if allow_space: pattern = r'^[\w\-_. ]+$' else: pattern = r'^[\w\-_.]+$' - is_single_or_no_dot = len(re.findall(r'\.', text)) <= 1 - return bool(re.match(pattern, text)) and is_single_or_no_dot + + if isinstance(allowed, str): + allowed = (allowed,) + + max_num_dots = 1 + if allowed is not None: + max_num_dots += sum([txt.count('.') for txt in allowed]) + + for allowed_text in allowed: + allowed_text = re.escape(allowed_text) + pattern = pattern.replace(r'+$', fr'+({allowed_text})?$') + + is_less_max_num_dots = len(re.findall(r'\.', text)) <= max_num_dots + return bool(re.match(pattern, text)) and is_less_max_num_dots def get_non_alphanumeric_characters(text): return re.findall(r'[^\w\-.]', text) diff --git a/cellacdc/dataStruct.py b/cellacdc/dataStruct.py index b41dbbc2..c865ab0f 100755 --- a/cellacdc/dataStruct.py +++ b/cellacdc/dataStruct.py @@ -1927,8 +1927,11 @@ def checkFileFormat(self, raw_src_path): return files def checkFileNames(self, raw_filenames, raw_src_path): + allowed = ( + '.ome.tif', + ) for file in raw_filenames: - if not acdc_regex.is_alphanumeric_filename(file): + if not acdc_regex.is_alphanumeric_filename(file, allowed=allowed): msg = widgets.myMessageBox(wrapText=False) txt = html_utils.paragraph( f""" diff --git a/cellacdc/load.py b/cellacdc/load.py index 62a33646..3c912110 100755 --- a/cellacdc/load.py +++ b/cellacdc/load.py @@ -3698,6 +3698,9 @@ def read_omexml_string(self): def parse_metadata(self): self.omexml_string = self.read_omexml_string() + if self.omexml_string is None: + return + self.root = ET.fromstring(self.omexml_string) self.ome_schema = re.findall(r'({.+})OME', self.root.tag)[0] From 220c41701329dbf3bb4b1959d147fb91fb2ad72a Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 28 May 2026 12:58:36 +0200 Subject: [PATCH 2/4] fix: address copilot comments --- cellacdc/acdc_regex.py | 3 +++ cellacdc/load.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/cellacdc/acdc_regex.py b/cellacdc/acdc_regex.py index dfbcb53a..e4550bfb 100644 --- a/cellacdc/acdc_regex.py +++ b/cellacdc/acdc_regex.py @@ -33,6 +33,9 @@ def is_alphanumeric_filename( else: pattern = r'^[\w\-_.]+$' + if allowed is None: + allowed = [] + if isinstance(allowed, str): allowed = (allowed,) diff --git a/cellacdc/load.py b/cellacdc/load.py index 3c912110..22a4d8ab 100755 --- a/cellacdc/load.py +++ b/cellacdc/load.py @@ -3697,6 +3697,8 @@ def read_omexml_string(self): return tif.ome_metadata def parse_metadata(self): + self.root = None + self.ome_schema = None self.omexml_string = self.read_omexml_string() if self.omexml_string is None: return @@ -3706,6 +3708,9 @@ def parse_metadata(self): def instrument(self): instrument = OMEXML_intrument() + if self.root is None: + return instrument + instrument_xml = self.root.find(f'{self.ome_schema}Instrument') if instrument_xml is None: return instrument @@ -3719,9 +3724,15 @@ def instrument(self): return instrument def get_image_count(self): + if self.root is None: + return 1 + return len(self.root.findall(f'{self.ome_schema}Image')) def image(self): + if self.root is None: + return 'undefined' + Image = self.root.find(f'{self.ome_schema}Image') Pixels = Image.find(f'{self.ome_schema}Pixels') image = OMEXML_image(Pixels, self.ome_schema) From 1f021ee4b1de1911538dc3256cf8368679dd7f16 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 28 May 2026 15:33:13 +0200 Subject: [PATCH 3/4] fix: address copilot comments 2 --- cellacdc/load.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cellacdc/load.py b/cellacdc/load.py index 22a4d8ab..a047a887 100755 --- a/cellacdc/load.py +++ b/cellacdc/load.py @@ -3683,7 +3683,10 @@ def __init__(self, Pixels, node, ome_schema) -> None: self.PhysicalSizeZ = node.get('PhysicalSizeZ', 1.0) def Channel(self, channel_index=0): - Channel = self.Pixels.findall(f'{self.ome_schema}Channel')[channel_index] + try: + Channel = self.Pixels.findall(f'{self.ome_schema}Channel')[channel_index] + except Exception as err: + Channel = 'not_found' return OMEXML_Channel(Channel) class OMEXML: @@ -3731,7 +3734,7 @@ def get_image_count(self): def image(self): if self.root is None: - return 'undefined' + return OMEXML_image(None, 'not_found') Image = self.root.find(f'{self.ome_schema}Image') Pixels = Image.find(f'{self.ome_schema}Pixels') From c2879083771d59bbd43f4a7fd0adfecc672e69c1 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 28 May 2026 15:41:11 +0200 Subject: [PATCH 4/4] fix: address copilot comments 2 --- cellacdc/load.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cellacdc/load.py b/cellacdc/load.py index a047a887..60dc6ced 100755 --- a/cellacdc/load.py +++ b/cellacdc/load.py @@ -3659,8 +3659,12 @@ def __init__(self): class OMEXML_Channel: def __init__(self, Channel) -> None: - self.Name = Channel.attrib.get('Name', '') - self.node = Channel.attrib + if not Channel or Channel is None: + self.Name = 'not_found' + self.node = None + else: + self.Name = Channel.attrib.get('Name', '') + self.node = Channel.attrib class OMEXML_Pixels: def __init__(self, Pixels, node, ome_schema) -> None: @@ -3686,7 +3690,7 @@ def Channel(self, channel_index=0): try: Channel = self.Pixels.findall(f'{self.ome_schema}Channel')[channel_index] except Exception as err: - Channel = 'not_found' + Channel = None return OMEXML_Channel(Channel) class OMEXML: