Skip to content

Commit

Permalink
Merge pull request ome#3356 from melissalinkert/flex-truncated-well
Browse files Browse the repository at this point in the history
Flex: use plate barcode for grouping, so that truncated files are kept
  • Loading branch information
dgault authored Jun 3, 2019
2 parents 82e887c + fe05259 commit ff4b393
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 ff4b393

Please sign in to comment.