Skip to content

Commit b5b540a

Browse files
authored
Merge pull request #251 from melissalinkert/no-original-metadata
Add "--no-original-metadata" option to omit original metadata from METADATA.ome.xml
2 parents fca5108 + 76c993a commit b5b540a

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ which can then be used to create a hierarchy by date, username, and ID:
234234
Prevents the input file's OME-XML metadata from being saved. There will no longer be an `OME` directory
235235
under the top-level output directory.
236236

237+
#### --no-original-metadata
238+
239+
Prevents `OriginalMetadata` annotations from being written to `OME/METADATA.ome.xml`.
240+
This can reduce the size of the OME-XML, and as discussed in [#250](https://github.com/glencoesoftware/bioformats2raw/issues/250),
241+
is one way to guard against unwanted experimental metadata being included in the conversion.
242+
237243
#### --no-root-group
238244

239245
By default, a Zarr group (`.zgroup` file) is written in the top-level output directory.

src/main/java/com/glencoesoftware/bioformats2raw/Converter.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public class Converter implements Callable<Integer> {
139139
private volatile boolean progressBars = false;
140140
private volatile boolean printVersion = false;
141141
private volatile boolean help = false;
142+
private volatile boolean originalMetadata = true;
142143

143144
private volatile int maxWorkers;
144145
private volatile int maxCachedTiles;
@@ -777,6 +778,22 @@ public void setNoOMEMeta(boolean noOMEMetaWriting) {
777778
noOMEMeta = noOMEMetaWriting;
778779
}
779780

781+
/**
782+
* Set whether or not to write original metadata key/value pairs in
783+
* OME-XML metadata.
784+
* By default, original metadata is written.
785+
*
786+
* @param noOriginalMetadata true if original metadata should not be written
787+
*/
788+
@Option(
789+
names = "--no-original-metadata",
790+
description = "Turn off original metadata exporting",
791+
defaultValue = "false"
792+
)
793+
public void setNoOriginalMetadata(boolean noOriginalMetadata) {
794+
originalMetadata = !noOriginalMetadata;
795+
}
796+
780797
/**
781798
* Set whether or not to write a root Zarr group.
782799
* By default, the root group is written.
@@ -1076,6 +1093,13 @@ public boolean getNoOMEMeta() {
10761093
return noOMEMeta;
10771094
}
10781095

1096+
/**
1097+
* @return true if original metadata will be written in the OME-XML
1098+
*/
1099+
public boolean getOriginalMetadata() {
1100+
return originalMetadata;
1101+
}
1102+
10791103
/**
10801104
* @return true if a root Zarr group will not be written
10811105
*/
@@ -1261,7 +1285,7 @@ public void convert()
12611285
memoizer.setMetadataOptions(options);
12621286
}
12631287

1264-
memoizer.setOriginalMetadataPopulated(!noOMEMeta);
1288+
memoizer.setOriginalMetadataPopulated(!noOMEMeta && originalMetadata);
12651289
memoizer.setFlattenedResolutions(false);
12661290
memoizer.setMetadataFiltered(true);
12671291
memoizer.setMetadataStore(createMetadata());

src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,32 @@ public void testNoOmeMetaExportOption() throws Exception {
16581658
output.resolve("OME").resolve(".zattrs")));
16591659
}
16601660

1661+
/**
1662+
* Convert with the "--no-original-metadata" option.
1663+
* Conversion should succeed and OME-XML should be written,
1664+
* but there should be no original metadata annotations despite
1665+
* original metadata being present in the input data.
1666+
*/
1667+
@Test
1668+
public void testNoOriginalMetadata() throws Exception {
1669+
Map<String, String> originalMetadata = new HashMap<String, String>();
1670+
originalMetadata.put("key1", "value1");
1671+
originalMetadata.put("key2", "value2");
1672+
1673+
input = fake(null, null, originalMetadata);
1674+
assertTool("--no-original-metadata");
1675+
Path omexml = output.resolve("OME").resolve("METADATA.ome.xml");
1676+
StringBuilder xml = new StringBuilder();
1677+
Files.lines(omexml).forEach(v -> xml.append(v));
1678+
1679+
OMEXMLService service =
1680+
new ServiceFactory().getInstance(OMEXMLService.class);
1681+
OMEXMLMetadata retrieve =
1682+
(OMEXMLMetadata) service.createOMEXMLMetadata(xml.toString());
1683+
Hashtable convertedMetadata = service.getOriginalMetadata(retrieve);
1684+
assertEquals(convertedMetadata, null);
1685+
}
1686+
16611687
/**
16621688
* Convert with the --use-existing-resolutions option. Conversion should
16631689
* produce multiscales matching the input resolution numbers and scale.

0 commit comments

Comments
 (0)