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> {
|
||||
|
||||
private SAMRecord record;
|
||||
private GenomeLoc loc;
|
||||
|
||||
public ComparableSAMRecord(SAMRecord record) {
|
||||
this.record = record;
|
||||
this.loc = new GenomeLoc(record);
|
||||
}
|
||||
|
||||
public SAMRecord getRecord() {
|
||||
|
|
@ -16,13 +18,28 @@ public class ComparableSAMRecord implements Comparable<ComparableSAMRecord> {
|
|||
|
||||
public int compareTo(ComparableSAMRecord o) {
|
||||
// first sort by start position
|
||||
GenomeLoc myLoc = new GenomeLoc(record);
|
||||
GenomeLoc hisLoc = new GenomeLoc(o.getRecord());
|
||||
int comparison = myLoc.compareTo(hisLoc);
|
||||
int comparison = loc.compareTo(o.loc);
|
||||
// if the reads have the same start position, we must give a non-zero comparison
|
||||
// (because java Sets often require "consistency with equals")
|
||||
if ( comparison == 0 )
|
||||
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;
|
||||
}
|
||||
|
||||
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