From aef519b42704813ce1a67561e4ceb0a857ac0fc0 Mon Sep 17 00:00:00 2001 From: ebanks Date: Fri, 19 Jun 2009 16:46:05 +0000 Subject: [PATCH] more comparisons git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1059 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/ComparableSAMRecord.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/ComparableSAMRecord.java b/java/src/org/broadinstitute/sting/utils/ComparableSAMRecord.java index 9e9716b5e..27540bb77 100755 --- a/java/src/org/broadinstitute/sting/utils/ComparableSAMRecord.java +++ b/java/src/org/broadinstitute/sting/utils/ComparableSAMRecord.java @@ -5,9 +5,11 @@ import net.sf.samtools.SAMRecord; public class ComparableSAMRecord implements Comparable { 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 { 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() ); + } } \ No newline at end of file