From fe052594f4e6bbdeae83ecd99296ad31b8dbe6b8 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 22 Apr 2019 08:38:25 -0500 Subject: [PATCH] Flex: use plate barcode for grouping, so that truncated files are kept 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. --- .../src/loci/formats/in/FlexReader.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/components/formats-gpl/src/loci/formats/in/FlexReader.java b/components/formats-gpl/src/loci/formats/in/FlexReader.java index 6b89bb01867..cc53bbd648a 100644 --- a/components/formats-gpl/src/loci/formats/in/FlexReader.java +++ b/components/formats-gpl/src/loci/formats/in/FlexReader.java @@ -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. @@ -1211,6 +1217,7 @@ private void groupFiles(String[] fileList, MetadataStore store) HashMap> v = new HashMap>(); Boolean firstCompressed = null; int firstIFDCount = 0; + String firstBarcode = null; for (String file : fileList) { LOGGER.warn("parsing {}", file); IFD firstIFD = null; @@ -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];