diff --git a/src/main/java/com/glencoesoftware/zarr/Convert.java b/src/main/java/com/glencoesoftware/zarr/Convert.java index f10b53d..a8acd26 100644 --- a/src/main/java/com/glencoesoftware/zarr/Convert.java +++ b/src/main/java/com/glencoesoftware/zarr/Convert.java @@ -39,6 +39,7 @@ import java.util.concurrent.Callable; import java.util.Arrays; import java.util.List; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -61,6 +62,13 @@ public class Convert implements Callable { private static final String RESERVED_KEY = "zarr.json"; + private static final String[] OME_NGFF_KEYS = new String[]{ + "bioformats2raw.layout", + "plate", + "well", + "multiscales" + }; + private String inputLocation; private String outputLocation; private String logLevel = "INFO"; @@ -176,6 +184,23 @@ public Integer call() throws Exception { return 0; } + /** + * Convert OME-NGFF attributes from 0.4 to 0.5 according to RFC-2 + */ + public Map convertToV3(Map attributes) throws Exception { + Map ome = new HashMap(); + for (String key: OME_NGFF_KEYS) { + if (attributes.containsKey(key)) { + ome.put(key, attributes.get(key)); + attributes.remove(key); + } + } + ome.put("version", "0.5"); + attributes.put("ome", ome); + return attributes; + } + + /** * Read v2 input data with jzarr, and write to v3 using zarr-java. */ @@ -199,11 +224,11 @@ public void convertToV3() throws Exception { LOGGER.debug("opening v3 root group: {}", outputLocation); FilesystemStore outputStore = new FilesystemStore(outputLocation); Group outputRootGroup = Group.create(outputStore.resolve()); - outputRootGroup.setAttributes(attributes); + outputRootGroup.setAttributes(convertToV3(attributes)); // copy OME-XML file Group outputOMEGroup = Group.create(outputStore.resolve("OME")); - outputOMEGroup.setAttributes(omeGroup.getAttributes()); + outputOMEGroup.setAttributes(convertToV3(omeGroup.getAttributes())); Files.copy(Paths.get(inputLocation, "OME", "METADATA.ome.xml"), Paths.get(outputLocation, "OME", "METADATA.ome.xml")); @@ -221,7 +246,7 @@ public void convertToV3() throws Exception { LOGGER.info("got {} series attributes", seriesAttributes.size()); Group outputSeriesGroup = Group.create(outputStore.resolve(seriesGroupKey)); - outputSeriesGroup.setAttributes(seriesAttributes); + outputSeriesGroup.setAttributes(convertToV3(seriesAttributes)); Set columnKeys = seriesGroup.getGroupKeys(); // "pass through" if this is not HCS @@ -241,7 +266,7 @@ public void convertToV3() throws Exception { if (!columnKey.isEmpty()) { Map columnAttributes = column.getAttributes(); Group outputColumnGroup = Group.create(outputStore.resolve(seriesGroupKey, columnKey)); - outputColumnGroup.setAttributes(columnAttributes); + outputColumnGroup.setAttributes(convertToV3(columnAttributes)); } Set fieldKeys = column.getGroupKeys(); @@ -259,7 +284,7 @@ public void convertToV3() throws Exception { Map fieldAttributes = field.getAttributes(); if (!fieldKey.isEmpty()) { Group outputFieldGroup = Group.create(outputStore.resolve(seriesGroupKey, columnKey, fieldKey)); - outputFieldGroup.setAttributes(fieldAttributes); + outputFieldGroup.setAttributes(convertToV3(fieldAttributes)); } // calculate the number of resolutions