Skip to content

Commit

Permalink
Add support for HCS output
Browse files Browse the repository at this point in the history
- skip parsing if plates exist
- temporarily remove HashSHA1 due to parsing error
  (ome/bioformats#3810)
- insert MetadataOnly after Channel for validation
  (glencoesoftware/bioformats2raw#137)
  • Loading branch information
joshmoore committed Apr 13, 2022
1 parent 93aad09 commit 08e12f7
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/ome_zarr_metadata/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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
Expand Down

0 comments on commit 08e12f7

Please sign in to comment.