| 1 |
package sort; |
| 2 |
|
| 3 |
import stream.Read; |
| 4 |
import stream.SamLine; |
| 5 |
import var2.ScafMap; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public final class ReadComparatorPosition extends ReadComparator { |
| 14 |
|
| 15 |
private ReadComparatorPosition(){} |
| 16 |
|
| 17 |
@Override |
| 18 |
public int compare(Read r1, Read r2) { |
| 19 |
int x=compareInner(r1, r2); |
| 20 |
return ascending*x; |
| 21 |
} |
| 22 |
|
| 23 |
public static int compareInner(Read r1, Read r2) { |
| 24 |
int x=compareInner(r1.samline, r2.samline); |
| 25 |
if(x!=0){return x;} |
| 26 |
if(r1.id==null && r2.id==null){return 0;} |
| 27 |
if(r1.id==null){return -1;} |
| 28 |
if(r2.id==null){return 1;} |
| 29 |
return r1.id.compareTo(r2.id); |
| 30 |
} |
| 31 |
|
| 32 |
public static int compareInner(SamLine a, SamLine b) { |
| 33 |
if(a.scafnum<0){a.setScafnum(scafMap);} |
| 34 |
if(b.scafnum<0){b.setScafnum(scafMap);} |
| 35 |
if(a.scafnum!=b.scafnum){return a.scafnum-b.scafnum;} |
| 36 |
if(a.pos!=b.pos){return a.pos-b.pos;} |
| 37 |
if(a.strand()!=b.strand()){return a.strand()-b.strand();} |
| 38 |
if(a.pnext!=b.pnext){return a.pnext-b.pnext;} |
| 39 |
if(a.pairnum()!=b.pairnum()){return a.pairnum()-b.pairnum();} |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
private int ascending=1; |
| 44 |
|
| 45 |
@Override |
| 46 |
public void setAscending(boolean asc){ |
| 47 |
ascending=(asc ? 1 : -1); |
| 48 |
} |
| 49 |
|
| 50 |
public static final ReadComparatorPosition comparator=new ReadComparatorPosition(); |
| 51 |
public static ScafMap scafMap=null; |
| 52 |
|
| 53 |
} |