Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZarrReader: Update handling of pre-existing plate metadata #49

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions src/loci/formats/in/ZarrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import ome.xml.meta.MetadataRoot;
import ome.xml.model.MapAnnotation;
import ome.xml.model.OME;
import ome.xml.model.Plate;
import ome.xml.model.Screen;
import ome.xml.model.StructuredAnnotations;
import ome.xml.model.primitives.NonNegativeInteger;
import ome.xml.model.primitives.PositiveInteger;
Expand Down Expand Up @@ -548,19 +550,31 @@ private void parsePlate(String root, String key, MetadataStore store) throws IOE
}
}
}
for (int c = 0; c < columns.size(); c++) {
Map<String, Object> column = (Map<String, Object>) columns.get(c);
String colName = (String) column.get("name");
}

// TODO: Likely remove as values unused
// for (int c = 0; c < columns.size(); c++) {
// Map<String, Object> column = (Map<String, Object>) columns.get(c);
// String colName = (String) column.get("name");
// }
// for (int r = 0; r < rows.size(); r++) {
// Map<String, Object> row = (Map<String, Object>) rows.get(r);
// String rowName = (String) row.get("name");
// }

//Create empty wells for each row and column
wellCount = rows.size() * columns.size();
for (int r = 0; r < rows.size(); r++) {
Map<String, Object> row = (Map<String, Object>) rows.get(r);
String rowName = (String) row.get("name");
for (int c = 0; c < columns.size(); c++) {
int wellIndex = (r * columns.size()) + c;
String well_id = MetadataTools.createLSID("Well", 0, wellIndex);
store.setWellID(well_id, 0, wellIndex);
store.setWellRow(new NonNegativeInteger(r), 0, wellIndex);
store.setWellColumn(new NonNegativeInteger(c), 0, wellIndex);
}
}
for (int w = 0; w < wells.size(); w++) {
Map<String, Object> well = (Map<String, Object>) wells.get(w);
String wellPath = (String) well.get("path");
String well_id = MetadataTools.createLSID("Well", wellCount);
store.setWellID(well_id, 0, w);

// column_index & row_index stored as Integer in bioformats2raw 0.3
Integer wellColIndex = (Integer) well.get("column_index");
Expand All @@ -570,29 +584,23 @@ private void parsePlate(String root, String key, MetadataStore store) throws IOE
wellColIndex = (Integer) well.get("columnIndex");
wellRowIndex = (Integer) well.get("rowIndex");
}
if (wellColIndex != null && wellRowIndex != null) {
store.setWellRow(new NonNegativeInteger(wellRowIndex), 0, w);
store.setWellColumn(new NonNegativeInteger(wellColIndex), 0, w);
}
else {
if (wellColIndex == null || wellRowIndex == null) {
// for OME-NGFF v0.2 parse row and column index from the path
String[] parts = wellPath.split("/");
String wellRow = parts[parts.length - 2];
String wellCol = parts[parts.length - 1];
int rowIndex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(wellRow.toUpperCase());
if (rowIndex == -1) {
rowIndex = Integer.parseInt(wellRow);
wellRowIndex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(wellRow.toUpperCase());
if (wellRowIndex == -1) {
wellRowIndex = Integer.parseInt(wellRow);
}
int colIndex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(wellCol.toUpperCase());
if (colIndex == -1) {
colIndex = Integer.parseInt(wellCol);
wellColIndex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(wellCol.toUpperCase());
if (wellColIndex == -1) {
wellColIndex = Integer.parseInt(wellCol);
}
store.setWellRow(new NonNegativeInteger(rowIndex), 0, w);
store.setWellColumn(new NonNegativeInteger(colIndex), 0, w);
}
store.setWellExternalIdentifier(wellPath, 0, w);
parseWells(root, wellPath, store, 0, w, acqIdsIndexMap);
wellCount++;
int wellIndex = (wellRowIndex * columns.size()) + wellColIndex;
store.setWellExternalIdentifier(wellPath, 0, wellIndex);
parseWells(root, wellPath, store, 0, wellIndex, acqIdsIndexMap);
}
}
}
Expand All @@ -611,7 +619,7 @@ private void parseWells(String root, String key, MetadataStore store, int plateI
if (acqIdsIndexMap.containsKey(acquisition)) {
acquisition = acqIdsIndexMap.get(acquisition);
}
String site_id = MetadataTools.createLSID("WellSample", wellSamplesCount);
String site_id = MetadataTools.createLSID("WellSample", plateIndex, wellIndex, i);
store.setWellSampleID(site_id, plateIndex, wellIndex, i);
store.setWellSampleIndex(new NonNegativeInteger(i), plateIndex, wellIndex, i);
String imageRefPath = "" + i;
Expand Down Expand Up @@ -814,6 +822,19 @@ private void parseOMEXML(Location omeMetaFile, MetadataStore store) throws IOExc
root.setStructuredAnnotations(annotations);
omexmlMeta.setRoot((MetadataRoot) root);
}

// Remove old Screen and Plate metadata
int screenSize = root.sizeOfScreenList();
for (int i = 0; i < screenSize; i++) {
root.removeScreen(root.getScreen(i));
}

int plateSize = root.sizeOfPlateList();
for (int i = 0; i < plateSize; i++) {
root.removePlate(root.getPlate(i));
}

omexmlMeta.setRoot((MetadataRoot) root);

MetadataConverter.convertMetadata( omexmlMeta, store );
}
Expand Down