From 08e12f784e085adbf4ca6d384720443108f96cb6 Mon Sep 17 00:00:00 2001 From: jmoore Date: Wed, 13 Apr 2022 14:55:15 +0200 Subject: [PATCH] Add support for HCS output - skip parsing if plates exist - temporarily remove HashSHA1 due to parsing error (https://github.com/ome/bioformats/issues/3810) - insert MetadataOnly after Channel for validation (https://github.com/glencoesoftware/bioformats2raw/issues/137) --- src/ome_zarr_metadata/spec.py | 39 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/ome_zarr_metadata/spec.py b/src/ome_zarr_metadata/spec.py index 0365941..7bbbf11 100644 --- a/src/ome_zarr_metadata/spec.py +++ b/src/ome_zarr_metadata/spec.py @@ -32,11 +32,14 @@ def __init__(self, node: Node) -> None: super().__init__(node) try: data = self.handle(node) - for idx, image in enumerate(data.images): - series = node.zarr.create(str(idx)) - assert series.exists() - _logger.info(f"found {series}") - node.add(series) + if data.plates: + _logger.info("Plates detected. Skipping implicit loading") + else: + for idx, image in enumerate(data.images): + series = node.zarr.create(str(idx)) + assert series.exists(), f"{series} is missing" + _logger.info(f"found {series}") + node.add(series) node.metadata["ome-xml"] = data except Exception as e: _logger.error(f"failed to parse metadata: {e}") @@ -45,8 +48,32 @@ def fix_xml(self, ns, elem): """ Note: elem.insert() was not updating the object correctly. """ + if elem.tag == f"{ns}Pixels": - elem.append(ET.Element(f"{ns}MetadataOnly")) + + must_have = set([f"{ns}BinData", f"{ns}TiffData", f"{ns}MetadataOnly"]) + children = set([x.tag for x in elem]) + + if not any(x in children for x in must_have): + # Needs fixing + metadata_only = ET.Element(f"{ns}MetadataOnly") + + inserted = False + for idx, child in enumerate(elem): + if child.tag == f"{ns}Channel": + elem.insert(idx + 1, metadata_only) + inserted = True + + if not inserted: + # Append to the beginning + elem.insert(0, metadata_only) + + elif elem.tag == f"{ns}Plane": + remove = None + for idx, child in enumerate(elem): + if child.tag == f"{ns}HashSHA1": + remove = child + elem.remove(remove) def parse_xml(self, filename): # Parse the file and find the current schema