Skip to content

Commit

Permalink
Sort TIFF files by well label
Browse files Browse the repository at this point in the history
...instead of strictly alphabetically.  This allows the wells to appear
in "A1, A2, ..., A10" order, instead of "A1, A10, A2, ..." order.

Noticed by Rubén Muñoz.  Closes #7950.

To test:

ant -Dtestng.directory=$DATA/scanr/ test-automated
  • Loading branch information
melissalinkert committed Feb 6, 2012
1 parent 2bf824e commit e0d985f
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion components/bio-formats/src/loci/formats/in/ScanrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

package loci.formats.in;

import java.io.File;
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Vector;

Expand Down Expand Up @@ -362,7 +364,42 @@ else if (!isGroupFiles() && checkSuffix(id, "tif")) {
}

tiffs = new String[nChannels * nWells * nPos * nTimepoints * nSlices];
Arrays.sort(list);

Arrays.sort(list, new Comparator<String>() {
public int compare(String s1, String s2) {
int lastSeparator1 = s1.lastIndexOf(File.separator) + 1;
int lastSeparator2 = s2.lastIndexOf(File.separator) + 1;
String dir1 = s1.substring(0, lastSeparator1);
String dir2 = s2.substring(0, lastSeparator2);

if (!dir1.equals(dir2)) {
return dir1.compareTo(dir2);
}

int dash1 = s1.indexOf("-", lastSeparator1);
int dash2 = s2.indexOf("-", lastSeparator2);

String label1 = dash1 < 0 ? "" : s1.substring(lastSeparator1, dash1);
String label2 = dash2 < 0 ? "" : s2.substring(lastSeparator2, dash2);

if (label1.equals(label2)) {
String remainder1 = dash1 < 0 ? s1 : s1.substring(dash1);
String remainder2 = dash2 < 0 ? s2 : s2.substring(dash2);
return remainder1.compareTo(remainder2);
}

Integer index1 = wellLabels.get(label1);
Integer index2 = wellLabels.get(label2);

if (index1 == null && index2 != null) {
return 1;
}
else if (index1 != null && index2 == null) {
return -1;
}
return index1.compareTo(index2);
}
});
int lastListIndex = 0;

int next = 0;
Expand Down

0 comments on commit e0d985f

Please sign in to comment.