Add contract to ensure that getAdapterBoundary returns the right result

-- Also renamed the function to getAdaptorBoundary for consistency across the codebase
This commit is contained in:
Mark DePristo 2013-01-25 16:00:06 -05:00
parent e445c71161
commit b8c0b05785
3 changed files with 5 additions and 3 deletions

View File

@ -25,6 +25,7 @@
package org.broadinstitute.sting.utils.sam; package org.broadinstitute.sting.utils.sam;
import com.google.java.contract.Ensures;
import net.sf.samtools.*; import net.sf.samtools.*;
import org.broadinstitute.sting.utils.NGSPlatform; import org.broadinstitute.sting.utils.NGSPlatform;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
@ -579,7 +580,8 @@ public class GATKSAMRecord extends BAMRecord {
* *
* @return the result of calling ReadUtils.getAdaptorBoundary on this read * @return the result of calling ReadUtils.getAdaptorBoundary on this read
*/ */
public int getAdapterBoundary() { @Ensures("result == ReadUtils.getAdaptorBoundary(this)")
public int getAdaptorBoundary() {
if ( adapterBoundary == null ) if ( adapterBoundary == null )
adapterBoundary = ReadUtils.getAdaptorBoundary(this); adapterBoundary = ReadUtils.getAdaptorBoundary(this);
return adapterBoundary; return adapterBoundary;

View File

@ -169,7 +169,7 @@ public class ReadUtils {
* @return whether or not the base is in the adaptor * @return whether or not the base is in the adaptor
*/ */
public static boolean isBaseInsideAdaptor(final GATKSAMRecord read, long basePos) { public static boolean isBaseInsideAdaptor(final GATKSAMRecord read, long basePos) {
final int adaptorBoundary = read.getAdapterBoundary(); final int adaptorBoundary = read.getAdaptorBoundary();
if (adaptorBoundary == CANNOT_COMPUTE_ADAPTOR_BOUNDARY || read.getInferredInsertSize() > DEFAULT_ADAPTOR_SIZE) if (adaptorBoundary == CANNOT_COMPUTE_ADAPTOR_BOUNDARY || read.getInferredInsertSize() > DEFAULT_ADAPTOR_SIZE)
return false; return false;

View File

@ -48,7 +48,7 @@ public class ReadUtilsUnitTest extends BaseTest {
}}); }});
tests.add( new Object[]{ new GetAdaptorFunc() { tests.add( new Object[]{ new GetAdaptorFunc() {
@Override public int getAdaptor(final GATKSAMRecord record) { return record.getAdapterBoundary(); } @Override public int getAdaptor(final GATKSAMRecord record) { return record.getAdaptorBoundary(); }
}}); }});
return tests.toArray(new Object[][]{}); return tests.toArray(new Object[][]{});