Skip to content

Commit

Permalink
Flex: use plate barcode for grouping, so that truncated files are kept
Browse files Browse the repository at this point in the history
Without this change, a truncated file would be rejected from the used file list,
which could completely break plate detection.  With an added barcode
check, plates can include truncated files, and files from different
plates will not be inadvertantly grouped together.
  • Loading branch information
melissalinkert committed Apr 22, 2019
1 parent 8f611f4 commit fe05259
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions components/formats-gpl/src/loci/formats/in/FlexReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
new RandomAccessInputStream(getFileHandle(file.file))) {
IFD ifd;
if (file.offsets == null) {
ifd = file.ifds.get(imageNumber);
factor = 1d;
if (imageNumber < file.ifds.size()) {
ifd = file.ifds.get(imageNumber);
factor = 1d;
}
else {
Arrays.fill(buf, (byte) 0);
return buf;
}
}
else {
// Only the first IFD was read. Hack the IFD to adjust the offset.
Expand Down Expand Up @@ -1211,6 +1217,7 @@ private void groupFiles(String[] fileList, MetadataStore store)
HashMap<String, ArrayList<String>> v = new HashMap<String, ArrayList<String>>();
Boolean firstCompressed = null;
int firstIFDCount = 0;
String firstBarcode = null;
for (String file : fileList) {
LOGGER.warn("parsing {}", file);
IFD firstIFD = null;
Expand All @@ -1226,7 +1233,23 @@ private void groupFiles(String[] fileList, MetadataStore store)
firstCompressed = compressed;
firstIFDCount = ifdCount;
}
if (compressed == firstCompressed && ifdCount == firstIFDCount) {
String xml = XMLTools.sanitizeXML(firstIFD.getIFDStringValue(FLEX));
int barcodeIndex = xml.indexOf("Barcode");
String barcode = "";
if (barcodeIndex >= 0) {
int start = xml.indexOf(">", barcodeIndex) + 1;
int end = xml.indexOf("<", barcodeIndex);
if (start > 0 && end > 0) {
barcode = xml.substring(start, end);
}
}
if (firstBarcode == null) {
firstBarcode = barcode;
}

if (compressed == firstCompressed && barcode.equals(firstBarcode) &&
ifdCount <= firstIFDCount)
{
int[] well = getWell(file);
int field = getField(file);
if (well[0] > nRows) nRows = well[0];
Expand Down

0 comments on commit fe05259

Please sign in to comment.