more comparisons
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1059 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
58b132ee10
commit
aef519b427
|
|
@ -5,9 +5,11 @@ import net.sf.samtools.SAMRecord;
|
||||||
public class ComparableSAMRecord implements Comparable<ComparableSAMRecord> {
|
public class ComparableSAMRecord implements Comparable<ComparableSAMRecord> {
|
||||||
|
|
||||||
private SAMRecord record;
|
private SAMRecord record;
|
||||||
|
private GenomeLoc loc;
|
||||||
|
|
||||||
public ComparableSAMRecord(SAMRecord record) {
|
public ComparableSAMRecord(SAMRecord record) {
|
||||||
this.record = record;
|
this.record = record;
|
||||||
|
this.loc = new GenomeLoc(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAMRecord getRecord() {
|
public SAMRecord getRecord() {
|
||||||
|
|
@ -16,13 +18,28 @@ public class ComparableSAMRecord implements Comparable<ComparableSAMRecord> {
|
||||||
|
|
||||||
public int compareTo(ComparableSAMRecord o) {
|
public int compareTo(ComparableSAMRecord o) {
|
||||||
// first sort by start position
|
// first sort by start position
|
||||||
GenomeLoc myLoc = new GenomeLoc(record);
|
int comparison = loc.compareTo(o.loc);
|
||||||
GenomeLoc hisLoc = new GenomeLoc(o.getRecord());
|
|
||||||
int comparison = myLoc.compareTo(hisLoc);
|
|
||||||
// if the reads have the same start position, we must give a non-zero comparison
|
// if the reads have the same start position, we must give a non-zero comparison
|
||||||
// (because java Sets often require "consistency with equals")
|
// (because java Sets often require "consistency with equals")
|
||||||
if ( comparison == 0 )
|
if ( comparison == 0 )
|
||||||
comparison = record.getReadName().compareTo(o.getRecord().getReadName());
|
comparison = record.getReadName().compareTo(o.getRecord().getReadName());
|
||||||
|
// if the read names are the same, use the first of the pair if appropriate
|
||||||
|
if ( comparison == 0 )
|
||||||
|
comparison = ( record.getFirstOfPairFlag() ? -1 : 1);
|
||||||
return comparison;
|
return comparison;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if ( !(obj instanceof ComparableSAMRecord) )
|
||||||
|
return false;
|
||||||
|
if ( this == obj )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
ComparableSAMRecord csr = (ComparableSAMRecord)obj;
|
||||||
|
if ( loc.compareTo(csr.loc) != 0 )
|
||||||
|
return false;
|
||||||
|
if ( !record.getReadName().equals(csr.getRecord().getReadName()) )
|
||||||
|
return false;
|
||||||
|
return ( record.getFirstOfPairFlag() == csr.record.getFirstOfPairFlag() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue