Search in sources :

Example 6 with AlignmentStateMachine

use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.

the class PileupElementUnitTest method testPileupElementTest.

@Test(dataProvider = "PileupElementTest")
public void testPileupElementTest(final LIBSTest params) {
    final GATKRead read = params.makeRead();
    final AlignmentStateMachine state = new AlignmentStateMachine(read);
    final LIBS_position tester = new LIBS_position(read);
    while (state.stepForwardOnGenome() != null) {
        tester.stepForwardOnGenome();
        final PileupElement pe = state.makePileupElement();
        Assert.assertEquals(pe.getRead(), read);
        Assert.assertEquals(pe.getMappingQual(), read.getMappingQuality());
        Assert.assertEquals(pe.getOffset(), state.getReadOffset());
        Assert.assertEquals(pe.isDeletion(), state.getCigarOperator() == D);
        Assert.assertEquals(pe.isAfterInsertion(), tester.isAfterInsertion);
        Assert.assertEquals(pe.isBeforeInsertion(), tester.isBeforeInsertion);
        Assert.assertEquals(pe.isNextToSoftClip(), tester.isNextToSoftClip);
        if (!hasNeighboringPaddedOps(params.getElements(), pe.getCurrentCigarOffset())) {
            Assert.assertEquals(pe.isAfterDeletionEnd(), tester.isAfterDeletionEnd);
            Assert.assertEquals(pe.isBeforeDeletionStart(), tester.isBeforeDeletionStart);
        }
        Assert.assertEquals(pe.getOffsetInCurrentCigar(), tester.getCurrentPositionOnOperatorBase0(), "CigarElement index failure");
        Assert.assertTrue(pe.getOffsetInCurrentCigar() >= 0, "Offset into current cigar too small");
        Assert.assertTrue(pe.getOffsetInCurrentCigar() < pe.getCurrentCigarElement().getLength(), "Offset into current cigar too big");
        Assert.assertNotNull(pe.toString());
        Assert.assertEquals(pe.atEndOfCurrentCigar(), state.getOffsetIntoCurrentCigarElement() == state.getCurrentCigarElement().getLength() - 1, "atEndOfCurrentCigar failed");
        Assert.assertEquals(pe.atStartOfCurrentCigar(), state.getOffsetIntoCurrentCigarElement() == 0, "atStartOfCurrentCigar failed");
        Assert.assertEquals(pe.getBase(), pe.isDeletion() ? PileupElement.DELETION_BASE : read.getBases()[state.getReadOffset()]);
        Assert.assertEquals(pe.getQual(), pe.isDeletion() ? PileupElement.DELETION_QUAL : read.getBaseQualities()[state.getReadOffset()]);
        Assert.assertEquals(pe.getCurrentCigarElement(), state.getCurrentCigarElement());
        Assert.assertEquals(pe.getCurrentCigarOffset(), state.getCurrentCigarElementOffset());
        final int lengthOfImmediatelyFollowingIndel = pe.getLengthOfImmediatelyFollowingIndel();
        final String basesOfImmediatelyFollowingInsertion = pe.getBasesOfImmediatelyFollowingInsertion();
        Assert.assertTrue(lengthOfImmediatelyFollowingIndel != 0 || basesOfImmediatelyFollowingInsertion == null);
        Assert.assertTrue(basesOfImmediatelyFollowingInsertion == null || basesOfImmediatelyFollowingInsertion.length() == lengthOfImmediatelyFollowingIndel);
        // Don't test -- pe.getBaseIndex();
        if (pe.atEndOfCurrentCigar() && state.getCurrentCigarElementOffset() < read.numCigarElements() - 1) {
            final CigarElement nextElement = read.getCigar().getCigarElement(state.getCurrentCigarElementOffset() + 1);
            if (nextElement.getOperator() == CigarOperator.I) {
                Assert.assertTrue(pe.getBetweenNextPosition().size() >= 1);
                Assert.assertEquals(pe.getBetweenNextPosition().get(0), nextElement);
            }
            if (nextElement.getOperator() == M) {
                Assert.assertTrue(pe.getBetweenNextPosition().isEmpty());
            }
        } else {
            Assert.assertTrue(pe.getBetweenNextPosition().isEmpty());
        }
        if (pe.atStartOfCurrentCigar() && state.getCurrentCigarElementOffset() > 0) {
            final CigarElement prevElement = read.getCigar().getCigarElement(state.getCurrentCigarElementOffset() - 1);
            if (prevElement.getOperator() == CigarOperator.I) {
                Assert.assertTrue(pe.getBetweenPrevPosition().size() >= 1);
                Assert.assertEquals(pe.getBetweenPrevPosition().get(pe.getBetweenPrevPosition().size() - 1), prevElement);
            }
            if (prevElement.getOperator() == M) {
                Assert.assertTrue(pe.getBetweenPrevPosition().isEmpty());
            }
        } else {
            Assert.assertTrue(pe.getBetweenPrevPosition().isEmpty());
        }
        // TODO -- add meaningful tests
        pe.getBaseInsertionQual();
        pe.getBaseDeletionQual();
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) LIBS_position(org.broadinstitute.hellbender.utils.locusiterator.LIBS_position) CigarElement(htsjdk.samtools.CigarElement) AlignmentStateMachine(org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine) LocusIteratorByStateBaseTest(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest) Test(org.testng.annotations.Test) LIBSTest(org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)

Example 7 with AlignmentStateMachine

use of org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine in project gatk by broadinstitute.

the class PileupElementUnitTest method testImmediateBeforeAndAfterTest.

@Test(dataProvider = "PrevAndNextTest")
public void testImmediateBeforeAndAfterTest(final GATKRead read, final CigarOperator firstOp, final CigarOperator lastOp, final List<CigarOperator> ops) {
    final AlignmentStateMachine state = new AlignmentStateMachine(read);
    //before the first 'op' from the list
    state.stepForwardOnGenome();
    final PileupElement pe1 = state.makePileupElement();
    Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.PREV), null);
    Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.NEXT), ops.get(0));
    for (final CigarOperator op : CigarOperator.values()) {
        Assert.assertEquals(pe1.isImmediatelyBefore(op), ops.get(0) == op, op.toString());
        Assert.assertFalse(pe1.isImmediatelyAfter(op), op.toString());
    }
    //after the first 'op' from the list
    state.stepForwardOnGenome();
    final PileupElement pe2 = state.makePileupElement();
    Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.PREV), ops.get(ops.size() - 1));
    Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.NEXT), null);
    for (final CigarOperator op : CigarOperator.values()) {
        Assert.assertFalse(pe2.isImmediatelyBefore(op), "immediately before " + op);
        Assert.assertEquals(pe2.isImmediatelyAfter(op), op == ops.get(ops.size() - 1), "immediately after " + op);
    }
}
Also used : CigarOperator(htsjdk.samtools.CigarOperator) AlignmentStateMachine(org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine) LocusIteratorByStateBaseTest(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest) Test(org.testng.annotations.Test) LIBSTest(org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)

Aggregations

AlignmentStateMachine (org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine)7 LIBSTest (org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)4 LocusIteratorByStateBaseTest (org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest)4 Test (org.testng.annotations.Test)4 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)3 CigarOperator (htsjdk.samtools.CigarOperator)2 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 htsjdk.variant.vcf (htsjdk.variant.vcf)2 File (java.io.File)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2 MutableLong (org.apache.commons.lang.mutable.MutableLong)2 Argument (org.broadinstitute.barclay.argparser.Argument)2 CommandLineProgramProperties (org.broadinstitute.barclay.argparser.CommandLineProgramProperties)2 DocumentedFeature (org.broadinstitute.barclay.help.DocumentedFeature)2 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)2 VariantProgramGroup (org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup)2 org.broadinstitute.hellbender.engine (org.broadinstitute.hellbender.engine)2 GATKProtectedVariantContextUtils (org.broadinstitute.hellbender.utils.GATKProtectedVariantContextUtils)2