Search in sources :

Example 6 with CigarOperator

use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.

the class CigarUtils method hasConsecutiveIndels.

/**
     * Checks if cigar has consecutive I/D elements.
     */
private static boolean hasConsecutiveIndels(final List<CigarElement> elems) {
    boolean prevIndel = false;
    for (final CigarElement elem : elems) {
        final CigarOperator op = elem.getOperator();
        final boolean isIndel = (op == CigarOperator.INSERTION || op == CigarOperator.DELETION);
        if (prevIndel && isIndel) {
            return true;
        }
        prevIndel = isIndel;
    }
    return false;
}
Also used : CigarOperator(htsjdk.samtools.CigarOperator) CigarElement(htsjdk.samtools.CigarElement)

Example 7 with CigarOperator

use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method makeIndelLengthAndBasesTest.

/////////////////////////////////////////////
// get event length and bases calculations //
/////////////////////////////////////////////
@DataProvider(name = "IndelLengthAndBasesTest")
public Object[][] makeIndelLengthAndBasesTest() {
    final String EVENT_BASES = "ACGTACGTACGT";
    final List<Object[]> tests = new LinkedList<>();
    for (int eventSize = 1; eventSize < 10; eventSize++) {
        for (final CigarOperator indel : Arrays.asList(CigarOperator.D, CigarOperator.I)) {
            final String cigar = String.format("2M%d%s1M", eventSize, indel.toString());
            final String eventBases = indel == CigarOperator.D ? "" : EVENT_BASES.substring(0, eventSize);
            final int readLength = 3 + eventBases.length();
            final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "read", 0, 1, readLength);
            read.setBases(("TT" + eventBases + "A").getBytes());
            final byte[] quals = new byte[readLength];
            for (int i = 0; i < readLength; i++) quals[i] = (byte) (i % QualityUtils.MAX_SAM_QUAL_SCORE);
            read.setBaseQualities(quals);
            read.setCigar(cigar);
            tests.add(new Object[] { read, indel, eventSize, eventBases.equals("") ? null : eventBases });
        }
    }
    return tests.toArray(new Object[][] {});
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) CigarOperator(htsjdk.samtools.CigarOperator) DataProvider(org.testng.annotations.DataProvider)

Example 8 with CigarOperator

use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.

the class PileupElementUnitTest method makePrevAndNextTest_simple.

@DataProvider(name = "PrevAndNextTest_simple")
public Object[][] makePrevAndNextTest_simple() {
    final List<Object[]> tests = new LinkedList<>();
    for (final CigarOperator firstOp : Arrays.asList(M)) {
        for (final CigarOperator lastOp : Arrays.asList(M)) {
            for (final CigarOperator middleOp : Arrays.asList(CigarOperator.I, CigarOperator.P, CigarOperator.S)) {
                final int readLength = 3;
                final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "read", 0, 1, readLength);
                read.setBases(Utils.dupBytes((byte) 'A', readLength));
                read.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
                String cigar = "1" + firstOp;
                cigar += "1" + middleOp;
                cigar += "1" + lastOp;
                read.setCigar(cigar);
                tests.add(new Object[] { read, middleOp });
            }
        }
    }
    return tests.toArray(new Object[][] {});
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) CigarOperator(htsjdk.samtools.CigarOperator) DataProvider(org.testng.annotations.DataProvider)

Example 9 with CigarOperator

use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.

the class PileupElementUnitTest method testIsImmediatelyAfter_afterLastM.

@Test
public void testIsImmediatelyAfter_afterLastM() {
    final GATKRead read = ArtificialReadUtils.createArtificialRead("10M10D10M");
    final PileupElement pe = PileupElement.createPileupForReadAndOffset(read, 9);
    Assert.assertFalse(pe.atStartOfCurrentCigar(), "atStartOfCurrentCigar");
    Assert.assertTrue(pe.atEndOfCurrentCigar(), "atEndOfCurrentCigar");
    for (final CigarOperator op : CigarOperator.values()) {
        Assert.assertFalse(pe.isImmediatelyAfter(op), "isImmediatelyAfter " + op);
    }
    Assert.assertTrue(pe.isImmediatelyBefore(D));
    for (final CigarOperator op : CigarOperator.values()) {
        if (op != D) {
            Assert.assertFalse(pe.isImmediatelyBefore(op), "isImmediatelyBefore " + op);
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) CigarOperator(htsjdk.samtools.CigarOperator) LocusIteratorByStateBaseTest(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest) Test(org.testng.annotations.Test) LIBSTest(org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)

Example 10 with CigarOperator

use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.

the class PileupElementUnitTest method testAdjacentElements.

@Test(dataProvider = "adjacentElementTestData")
public void testAdjacentElements(GATKRead read, int goodOffset, boolean atStartOfCurrentCigar, boolean atEndOfCurrentCigar, CigarOperator prev, CigarOperator next) throws Exception {
    final PileupElement pe = PileupElement.createPileupForReadAndOffset(read, goodOffset);
    Assert.assertEquals(pe.atStartOfCurrentCigar(), atStartOfCurrentCigar, "atStartOfCurrentCigar");
    Assert.assertEquals(pe.atEndOfCurrentCigar(), atEndOfCurrentCigar, "atEndOfCurrentCigar");
    Assert.assertEquals(pe.getAdjacentOperator(PileupElement.Direction.PREV), prev, "prev");
    Assert.assertEquals(pe.getAdjacentOperator(PileupElement.Direction.NEXT), next, "next");
    for (final CigarOperator op : CigarOperator.values()) {
        Assert.assertEquals(pe.isImmediatelyAfter(op), atStartOfCurrentCigar && op == prev);
        Assert.assertEquals(pe.isImmediatelyBefore(op), atEndOfCurrentCigar && op == next);
    }
}
Also used : CigarOperator(htsjdk.samtools.CigarOperator) LocusIteratorByStateBaseTest(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest) Test(org.testng.annotations.Test) LIBSTest(org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)

Aggregations

CigarOperator (htsjdk.samtools.CigarOperator)18 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)8 LIBSTest (org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)7 LocusIteratorByStateBaseTest (org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest)7 Test (org.testng.annotations.Test)7 CigarElement (htsjdk.samtools.CigarElement)5 DataProvider (org.testng.annotations.DataProvider)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Cigar (htsjdk.samtools.Cigar)2 AlignmentStateMachine (org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine)2 Locatable (htsjdk.samtools.util.Locatable)1 ArrayList (java.util.ArrayList)1 AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)1 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)1 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)1 PileupElement (org.broadinstitute.hellbender.utils.pileup.PileupElement)1 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)1