Skip to content

Commit

Permalink
Add "--no-original-metadata" option to omit original metadata from ME…
Browse files Browse the repository at this point in the history
…TADATA.ome.xml

Fixes glencoesoftware#250.
  • Loading branch information
melissalinkert committed May 20, 2024
1 parent fca5108 commit a6eb1b3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public class Converter implements Callable<Integer> {
private volatile boolean progressBars = false;
private volatile boolean printVersion = false;
private volatile boolean help = false;
private volatile boolean originalMetadata = true;

private volatile int maxWorkers;
private volatile int maxCachedTiles;
Expand Down Expand Up @@ -777,6 +778,22 @@ public void setNoOMEMeta(boolean noOMEMetaWriting) {
noOMEMeta = noOMEMetaWriting;
}

/**
* Set whether or not to write original metadata key/value pairs in
* OME-XML metadata.
* By default, original metadata is written.
*
* @param noOriginalMetadata true if original metadata should not be written
*/
@Option(
names = "--no-original-metadata",
description = "Turn off original metadata exporting",
defaultValue = "false"
)
public void setNoOriginalMetadata(boolean noOriginalMetadata) {
originalMetadata = !noOriginalMetadata;
}

/**
* Set whether or not to write a root Zarr group.
* By default, the root group is written.
Expand Down Expand Up @@ -1076,6 +1093,13 @@ public boolean getNoOMEMeta() {
return noOMEMeta;
}

/**
* @return true if original metadata will be written in the OME-XML
*/
public boolean getOriginalMetadata() {
return originalMetadata;
}

/**
* @return true if a root Zarr group will not be written
*/
Expand Down Expand Up @@ -1261,7 +1285,7 @@ public void convert()
memoizer.setMetadataOptions(options);
}

memoizer.setOriginalMetadataPopulated(!noOMEMeta);
memoizer.setOriginalMetadataPopulated(!noOMEMeta && originalMetadata);
memoizer.setFlattenedResolutions(false);
memoizer.setMetadataFiltered(true);
memoizer.setMetadataStore(createMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,32 @@ public void testNoOmeMetaExportOption() throws Exception {
output.resolve("OME").resolve(".zattrs")));
}

/**
* Convert with the "--no-original-metadata" option.
* Conversion should succeed and OME-XML should be written,
* but there should be no original metadata annotations despite
* original metadata being present in the input data.
*/
@Test
public void testNoOriginalMetadata() throws Exception {
Map<String, String> originalMetadata = new HashMap<String, String>();
originalMetadata.put("key1", "value1");
originalMetadata.put("key2", "value2");

input = fake(null, null, originalMetadata);
assertTool("--no-original-metadata");
Path omexml = output.resolve("OME").resolve("METADATA.ome.xml");
StringBuilder xml = new StringBuilder();
Files.lines(omexml).forEach(v -> xml.append(v));

OMEXMLService service =
new ServiceFactory().getInstance(OMEXMLService.class);
OMEXMLMetadata retrieve =
(OMEXMLMetadata) service.createOMEXMLMetadata(xml.toString());
Hashtable convertedMetadata = service.getOriginalMetadata(retrieve);
assertEquals(convertedMetadata, null);
}

/**
* Convert with the --use-existing-resolutions option. Conversion should
* produce multiscales matching the input resolution numbers and scale.
Expand Down

0 comments on commit a6eb1b3

Please sign in to comment.