Skip to content

Commit

Permalink
Merge branch 'master' into s3
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmoore authored Jun 29, 2021
2 parents f6ac52b + 382ad05 commit b435320
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
26 changes: 17 additions & 9 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ public class Converter implements Callable<Void> {
)
private volatile boolean noHCS = false;

@Option(
names = "--no-ome-meta-export",
description = "Turn off OME metadata exporting " +
"[Will break compatibility with raw2ometiff]"
)
private volatile boolean noOMEMeta = false;

@Option(
names = "--no-root-group",
description = "Turn off creation of root group and corresponding " +
Expand Down Expand Up @@ -523,7 +530,7 @@ public void convert()
memoizer.setMetadataOptions(options);
}

memoizer.setOriginalMetadataPopulated(true);
memoizer.setOriginalMetadataPopulated(!noOMEMeta);
memoizer.setFlattenedResolutions(false);
memoizer.setMetadataFiltered(true);
memoizer.setMetadataStore(createMetadata());
Expand Down Expand Up @@ -601,16 +608,17 @@ public void convert()
}
}

String xml = getService().getOMEXML(meta);
if (!noOMEMeta) {
String xml = getService().getOMEXML(meta);

// write the original OME-XML to a file
Path metadataPath = getRootPath().resolve("OME");
if (!Files.exists(metadataPath)) {
Files.createDirectories(metadataPath);
// write the original OME-XML to a file
Path metadataPath = getRootPath().resolve("OME");
if (!Files.exists(metadataPath)) {
Files.createDirectories(metadataPath);
}
Path omexmlFile = metadataPath.resolve(METADATA_FILE);
Files.write(omexmlFile, xml.getBytes(Constants.ENCODING));
}

Path omexmlFile = metadataPath.resolve(METADATA_FILE);
Files.write(omexmlFile, xml.getBytes(Constants.ENCODING));
}
catch (ServiceException se) {
LOGGER.error("Could not retrieve OME-XML", se);
Expand Down
41 changes: 31 additions & 10 deletions src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,25 @@ public class MiraxReader extends FormatReader {

/** Constructs a new Mirax reader. */
public MiraxReader() {
super("Mirax", "mrxs");
super("Mirax", new String[] {"mrxs", "ini"});
domains = new String[] {FormatTools.HISTOLOGY_DOMAIN};
datasetDescription = "One .vms file plus several .jpg files";
datasetDescription =
"A directory of .ini and .dat files, and an optional .mrxs file";
suffixNecessary = true;
suffixSufficient = false;
}

// -- IFormatReader API methods --

/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
@Override
public boolean isThisType(String name, boolean open) {
if (checkSuffix(name, "mrxs")) {
return true;
}
return new Location(name).getName().equals(SLIDE_DATA);
}

/* @see loci.formats.IFormatReader#getOptimalTileWidth() */
@Override
public int getOptimalTileWidth() {
Expand Down Expand Up @@ -172,7 +183,9 @@ public String[] getSeriesUsedFiles(boolean noPixels) {

ArrayList<String> f = new ArrayList<String>();
f.add(currentId);
f.add(iniPath);
if (!iniPath.equals(currentId)) {
f.add(iniPath);
}
for (String file : files) {
if (!checkSuffix(file, "dat") || !noPixels) {
f.add(file);
Expand Down Expand Up @@ -366,13 +379,21 @@ public void reopenFile() throws IOException {
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);

offsets = new TreeMap<TilePointer, List<TilePointer>>();
Location slideDirectory = null;

Location dir = new Location(id.substring(0, id.lastIndexOf(".")));
Location slideData = new Location(dir, SLIDE_DATA);
iniPath = slideData.getAbsolutePath();
if (checkSuffix(id, "mrxs")) {
slideDirectory = new Location(id.substring(0, id.lastIndexOf(".")));
Location slideData = new Location(slideDirectory, SLIDE_DATA);
iniPath = slideData.getAbsolutePath();
}
else {
slideDirectory = new Location(id).getParentFile();
iniPath = new Location(id).getAbsolutePath();
}

offsets = new TreeMap<TilePointer, List<TilePointer>>();

String ini = DataTools.readFile(slideData.getAbsolutePath());
String ini = DataTools.readFile(iniPath);
ini = ini.substring(ini.indexOf("["));
IniParser parser = new IniParser();
IniList data = parser.parseINI(new BufferedReader(new StringReader(ini)));
Expand All @@ -394,7 +415,7 @@ protected void initFile(String id) throws FormatException, IOException {
}

String indexFile = hierarchy.get("INDEXFILE");
Location index = new Location(dir, indexFile);
Location index = new Location(slideDirectory, indexFile);
if (!index.exists()) {
throw new IOException(
"Index file " + index.getAbsolutePath() + " missing");
Expand Down Expand Up @@ -424,7 +445,7 @@ protected void initFile(String id) throws FormatException, IOException {
int nFiles = Integer.parseInt(fileTable.get("FILE_COUNT"));

for (int i=0; i<nFiles; i++) {
Location f = new Location(dir, fileTable.get("FILE_" + i));
Location f = new Location(slideDirectory, fileTable.get("FILE_" + i));
if (!f.exists()) {
throw new IOException("Data file " + f.getAbsolutePath() + " missing");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ void assertTool(String...additionalArgs) throws IOException {
try {
converter = new Converter();
CommandLine.call(converter, args.toArray(new String[]{}));
assertTrue(Files.exists(
output.resolve("OME").resolve("METADATA.ome.xml")));
}
catch (RuntimeException rt) {
throw rt;
Expand Down Expand Up @@ -1053,6 +1051,31 @@ public void testNoRootGroupOption() throws Exception {
assertTrue(!Files.exists(output.resolve(".zgroup")));
}

/**
* Check that a OME metadata is exported.
*/
@Test
public void testOmeMetaExportOption() throws Exception {
input = fake();
assertTool();

assertTrue(Files.exists(
output.resolve("OME").resolve("METADATA.ome.xml")));
}

/**
* Convert with the --no-ome-meta-export option. Conversion should succeed,
* but no OME metadata should be exported.
*/
@Test
public void testNoOmeMetaExportOption() throws Exception {
input = fake();
assertTool("--no-ome-meta-export");

assertTrue(!Files.exists(
output.resolve("OME").resolve("METADATA.ome.xml")));
}

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

0 comments on commit b435320

Please sign in to comment.