From 008df545754ce9dee93a0f0de29056385bea73b2 Mon Sep 17 00:00:00 2001 From: Ryan Poplin Date: Mon, 22 Oct 2012 14:21:52 -0400 Subject: [PATCH] Bug fix in GATKSAMRecord.getSoftEnd() for reads that are entirely clipped. --- .../sting/utils/sam/GATKSAMRecord.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java b/public/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java index 1feb76517..9fdb48b34 100755 --- a/public/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java +++ b/public/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java @@ -60,8 +60,9 @@ public class GATKSAMRecord extends BAMRecord { private String mReadString = null; private GATKSAMReadGroupRecord mReadGroup = null; private byte[] reducedReadCounts = null; - private int softStart = -1; - private int softEnd = -1; + private final static int UNINITIALIZED = -1; + private int softStart = UNINITIALIZED; + private int softEnd = UNINITIALIZED; // because some values can be null, we don't want to duplicate effort private boolean retrievedReadGroup = false; @@ -386,7 +387,7 @@ public class GATKSAMRecord extends BAMRecord { * @return the unclipped start of the read taking soft clips (but not hard clips) into account */ public int getSoftStart() { - if (softStart < 0) { + if ( softStart == UNINITIALIZED ) { softStart = getAlignmentStart(); for (final CigarElement cig : getCigar().getCigarElements()) { final CigarOperator op = cig.getOperator(); @@ -408,17 +409,23 @@ public class GATKSAMRecord extends BAMRecord { * @return the unclipped end of the read taking soft clips (but not hard clips) into account */ public int getSoftEnd() { - if ( softEnd < 0 ) { + if ( softEnd == UNINITIALIZED ) { + boolean foundAlignedBase = false; softEnd = getAlignmentEnd(); final List cigs = getCigar().getCigarElements(); - for (int i=cigs.size() - 1; i>=0; --i) { + for (int i = cigs.size() - 1; i >= 0; --i) { final CigarElement cig = cigs.get(i); final CigarOperator op = cig.getOperator(); - if (op == CigarOperator.SOFT_CLIP) + if (op == CigarOperator.SOFT_CLIP) // assumes the soft clip that we found is at the end of the aligned read softEnd += cig.getLength(); - else if (op != CigarOperator.HARD_CLIP) + else if (op != CigarOperator.HARD_CLIP) { + foundAlignedBase = true; break; + } + } + if( !foundAlignedBase ) { // for example 64H14S, the soft end is actually the same as the alignment end + softEnd = getAlignmentEnd(); } }