Better implementation for getSoftEnd() in GATKSAMRecord

This commit is contained in:
Eric Banks 2012-10-18 09:01:51 -04:00
parent 20ffbcc86e
commit 54f698422c
1 changed files with 12 additions and 15 deletions

View File

@ -31,6 +31,7 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -406,24 +407,20 @@ public class GATKSAMRecord extends BAMRecord {
* @return the unclipped end of the read taking soft clips (but not hard clips) into account * @return the unclipped end of the read taking soft clips (but not hard clips) into account
*/ */
public int getSoftEnd() { public int getSoftEnd() {
if (softEnd < 0) { if ( softEnd < 0 ) {
int stop = this.getUnclippedStart(); softEnd = getAlignmentEnd();
final List<CigarElement> cigs = getCigar().getCigarElements();
for (int i=cigs.size() - 1; i>=0; --i) {
final CigarElement cig = cigs.get(i);
final CigarOperator op = cig.getOperator();
if (ReadUtils.readIsEntirelyInsertion(this)) if (op == CigarOperator.SOFT_CLIP)
return stop; softEnd += cig.getLength();
else if (op != CigarOperator.HARD_CLIP)
int shift = 0; break;
CigarOperator lastOperator = null;
for (CigarElement cigarElement : this.getCigar().getCigarElements()) {
stop += shift;
lastOperator = cigarElement.getOperator();
if (cigarElement.getOperator().consumesReferenceBases() || cigarElement.getOperator() == CigarOperator.SOFT_CLIP || cigarElement.getOperator() == CigarOperator.HARD_CLIP)
shift = cigarElement.getLength();
else
shift = 0;
} }
softEnd = (lastOperator == CigarOperator.HARD_CLIP) ? stop-1 : stop+shift-1 ;
} }
return softEnd; return softEnd;
} }