| 1 |
package sort; |
| 2 |
|
| 3 |
import hiseq.FlowcellCoordinate; |
| 4 |
import stream.Read; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
public final class ReadComparatorFlowcell extends ReadComparator { |
| 13 |
|
| 14 |
private ReadComparatorFlowcell(){} |
| 15 |
|
| 16 |
@Override |
| 17 |
public int compare(Read r1, Read r2) { |
| 18 |
int x=compareInner(r1, r2); |
| 19 |
return ascending*x; |
| 20 |
} |
| 21 |
|
| 22 |
public int compareInner(Read r1, Read r2) { |
| 23 |
if(r1.id==null && r2.id==null){return r1.pairnum()-r2.pairnum();} |
| 24 |
if(r1.id==null){return -1;} |
| 25 |
if(r2.id==null){return 1;} |
| 26 |
|
| 27 |
FlowcellCoordinate fc1=tlc1.get(), fc2=tlc2.get(); |
| 28 |
if(fc1==null){ |
| 29 |
fc1=new FlowcellCoordinate(); |
| 30 |
fc2=new FlowcellCoordinate(); |
| 31 |
tlc1.set(fc1); |
| 32 |
tlc2.set(fc2); |
| 33 |
} |
| 34 |
fc1.setFrom(r1.id); |
| 35 |
fc2.setFrom(r2.id); |
| 36 |
|
| 37 |
int x=fc1.compareTo(fc2); |
| 38 |
if(x==0){return r1.pairnum()-r2.pairnum();} |
| 39 |
return x; |
| 40 |
} |
| 41 |
|
| 42 |
private int ascending=1; |
| 43 |
|
| 44 |
@Override |
| 45 |
public void setAscending(boolean asc){ |
| 46 |
ascending=(asc ? 1 : -1); |
| 47 |
} |
| 48 |
|
| 49 |
public ThreadLocal<FlowcellCoordinate> tlc1=new ThreadLocal<FlowcellCoordinate>(); |
| 50 |
public ThreadLocal<FlowcellCoordinate> tlc2=new ThreadLocal<FlowcellCoordinate>(); |
| 51 |
|
| 52 |
public static final ReadComparatorFlowcell comparator=new ReadComparatorFlowcell(); |
| 53 |
|
| 54 |
} |