Search in sources :

Example 1 with AlignmentContext

use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method testIndelsInRegularPileup.

@Test
public void testIndelsInRegularPileup() {
    final byte[] bases = { 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A' };
    final byte[] indelBases = { 'A', 'A', 'A', 'A', 'C', 'T', 'A', 'A', 'A', 'A', 'A', 'A' };
    final GATKRead before = ArtificialReadUtils.createArtificialRead(header, "before", 0, 1, 10);
    before.setBases(bases);
    before.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
    before.setCigar("10M");
    final GATKRead during = ArtificialReadUtils.createArtificialRead(header, "during", 0, 2, 10);
    during.setBases(indelBases);
    during.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
    during.setCigar("4M2I6M");
    final GATKRead after = ArtificialReadUtils.createArtificialRead(header, "after", 0, 3, 10);
    after.setBases(bases);
    after.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
    after.setCigar("10M");
    final List<GATKRead> reads = Arrays.asList(before, during, after);
    // create the iterator by state with the fake reads and fake records
    final LocusIteratorByState li;
    li = makeLIBS(reads, header);
    boolean foundIndel = false;
    while (li.hasNext()) {
        final AlignmentContext context = li.next();
        final ReadPileup pileup = context.getBasePileup().makeFilteredPileup(pe -> pe.getQual() >= 10);
        for (final PileupElement p : pileup) {
            if (p.isBeforeInsertion()) {
                foundIndel = true;
                Assert.assertEquals(p.getLengthOfImmediatelyFollowingIndel(), 2, "Wrong event length");
                Assert.assertEquals(p.getBasesOfImmediatelyFollowingInsertion(), "CT", "Inserted bases are incorrect");
                break;
            }
        }
    }
    Assert.assertTrue(foundIndel, "Indel in pileup not found");
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) Test(org.testng.annotations.Test)

Example 2 with AlignmentContext

use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method testKeepingNs.

/**
     * Test to make sure that if there are reads with Ns are keeped
     */
@Test
public void testKeepingNs() {
    final int firstLocus = 44367788, secondLocus = firstLocus + 1;
    final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "read1", 0, secondLocus, 1);
    read.setBases(Utils.dupBytes((byte) 'N', 1));
    read.setBaseQualities(Utils.dupBytes((byte) '@', 1));
    read.setCigar("1I");
    // create the iterator by state with the fake reads and fake records
    LocusIteratorByState libs = makeLIBSwithNs(Collections.singletonList(read), header);
    while (libs.hasNext()) {
        final AlignmentContext alignmentContext = libs.next();
        final ReadPileup rp = alignmentContext.getBasePileup();
        Assert.assertEquals(rp.size(), 1);
        final PileupElement pe = rp.iterator().next();
        Assert.assertEquals(pe.getBase(), (byte) 'N');
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) Test(org.testng.annotations.Test)

Example 3 with AlignmentContext

use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method testLIBS.

@Test(enabled = true, dataProvider = "MyLIBSTest")
public void testLIBS(final LIBSTest params) {
    // create the iterator by state with the fake reads and fake records
    final GATKRead read = params.makeRead();
    final LocusIteratorByState li;
    li = makeLIBS(Arrays.asList(read), null, false, header);
    final LIBS_position tester = new LIBS_position(read);
    int bpVisited = 0;
    int lastOffset = 0;
    while (li.hasNext()) {
        bpVisited++;
        final AlignmentContext alignmentContext = li.next();
        final ReadPileup p = alignmentContext.getBasePileup();
        Assert.assertEquals(p.size(), 1);
        final PileupElement pe = p.iterator().next();
        Assert.assertEquals(p.getNumberOfElements(el -> el.isDeletion()), pe.isDeletion() ? 1 : 0, "wrong number of deletions in the pileup");
        Assert.assertEquals(p.getNumberOfElements(el -> el.getRead().getMappingQuality() == 0), pe.getRead().getMappingQuality() == 0 ? 1 : 0, "wront number of mapq reads in the pileup");
        tester.stepForwardOnGenome();
        if (!hasNeighboringPaddedOps(params.getElements(), pe.getCurrentCigarOffset())) {
            Assert.assertEquals(pe.isBeforeDeletionStart(), tester.isBeforeDeletionStart, "before deletion start failure");
            Assert.assertEquals(pe.isAfterDeletionEnd(), tester.isAfterDeletionEnd, "after deletion end failure");
        }
        Assert.assertEquals(pe.isBeforeInsertion(), tester.isBeforeInsertion, "before insertion failure");
        Assert.assertEquals(pe.isAfterInsertion(), tester.isAfterInsertion, "after insertion failure");
        Assert.assertEquals(pe.isNextToSoftClip(), tester.isNextToSoftClip, "next to soft clip failure");
        Assert.assertTrue(pe.getOffset() >= lastOffset, "Somehow read offsets are decreasing: lastOffset " + lastOffset + " current " + pe.getOffset());
        Assert.assertEquals(pe.getOffset(), tester.getCurrentReadOffset(), "Read offsets are wrong at " + bpVisited);
        Assert.assertEquals(pe.getCurrentCigarElement(), read.getCigar().getCigarElement(tester.currentOperatorIndex), "CigarElement index failure");
        Assert.assertEquals(pe.getOffsetInCurrentCigar(), tester.getCurrentPositionOnOperatorBase0(), "CigarElement index failure");
        Assert.assertEquals(read.getCigar().getCigarElement(pe.getCurrentCigarOffset()), pe.getCurrentCigarElement(), "Current cigar element isn't what we'd get from the read itself");
        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.assertEquals(pe.getOffset(), tester.getCurrentReadOffset(), "Read offset failure");
        lastOffset = pe.getOffset();
    }
    final int expectedBpToVisit = read.getEnd() - read.getStart() + 1;
    Assert.assertEquals(bpVisited, expectedBpToVisit, "Didn't visit the expected number of bp");
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) DownsampleType(org.broadinstitute.hellbender.utils.downsampling.DownsampleType) java.util(java.util) DataProvider(org.testng.annotations.DataProvider) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) CigarOperator(htsjdk.samtools.CigarOperator) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) QualityUtils(org.broadinstitute.hellbender.utils.QualityUtils) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) NGSPlatform(org.broadinstitute.hellbender.utils.NGSPlatform) ArtificialBAMBuilder(org.broadinstitute.hellbender.utils.read.ArtificialBAMBuilder) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) Utils(org.broadinstitute.hellbender.utils.Utils) DownsamplingMethod(org.broadinstitute.hellbender.utils.downsampling.DownsamplingMethod) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) Test(org.testng.annotations.Test)

Example 4 with AlignmentContext

use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method testAdvance.

@Test
public void testAdvance() {
    final int readLength = "ACTG".length();
    final GATKRead mapped1 = ArtificialReadUtils.createArtificialRead(header, "mapped1", 0, 1, readLength);
    mapped1.setBases("ACTG".getBytes());
    final List<GATKRead> reads = Arrays.asList(mapped1);
    final LocusIteratorByState li;
    li = makeLIBS(reads, DownsamplingMethod.NONE, true, header);
    final AlignmentContext alignmentContext2 = li.advanceToLocus(2, true);
    Assert.assertEquals(alignmentContext2.getPosition(), 2);
    final AlignmentContext alignmentContext3 = li.advanceToLocus(3, true);
    Assert.assertEquals(alignmentContext3.getPosition(), 3);
    final AlignmentContext alignmentContext10 = li.advanceToLocus(10, true);
    Assert.assertNull(alignmentContext10);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) Test(org.testng.annotations.Test)

Example 5 with AlignmentContext

use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method testWholeIndelReadRepresentedTest.

/**
     * Test to make sure that reads supporting only an indel (example cigar string: 76I) are represented properly
     */
@Test
public void testWholeIndelReadRepresentedTest() {
    final int firstLocus = 44367788, secondLocus = firstLocus + 1;
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, secondLocus, 1);
    read1.setBases(Utils.dupBytes((byte) 'A', 1));
    read1.setBaseQualities(Utils.dupBytes((byte) '@', 1));
    read1.setCigar("1I");
    List<GATKRead> reads = Arrays.asList(read1);
    // create the iterator by state with the fake reads and fake records
    LocusIteratorByState li;
    li = makeLIBS(reads, null, false, header);
    while (li.hasNext()) {
        final AlignmentContext alignmentContext = li.next();
        final ReadPileup p = alignmentContext.getBasePileup();
        Assert.assertTrue(p.size() == 1);
        PileupElement pe = p.iterator().next();
        Assert.assertTrue(pe.isBeforeInsertion());
        Assert.assertFalse(pe.isAfterInsertion());
        Assert.assertEquals(pe.getBasesOfImmediatelyFollowingInsertion(), "A");
    }
    final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 0, secondLocus, 10);
    read2.setBases(Utils.dupBytes((byte) 'A', 10));
    read2.setBaseQualities(Utils.dupBytes((byte) '@', 10));
    read2.setCigar("10I");
    reads = Arrays.asList(read2);
    // create the iterator by state with the fake reads and fake records
    li = makeLIBS(reads, null, false, header);
    while (li.hasNext()) {
        final AlignmentContext alignmentContext = li.next();
        final ReadPileup p = alignmentContext.getBasePileup();
        Assert.assertTrue(p.size() == 1);
        PileupElement pe = p.iterator().next();
        Assert.assertTrue(pe.isBeforeInsertion());
        Assert.assertFalse(pe.isAfterInsertion());
        Assert.assertEquals(pe.getBasesOfImmediatelyFollowingInsertion(), "AAAAAAAAAA");
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) Test(org.testng.annotations.Test)

Aggregations

AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)25 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)17 Test (org.testng.annotations.Test)16 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)14 SAMFileHeader (htsjdk.samtools.SAMFileHeader)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)6 LocusIteratorByState (org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByState)6 Utils (org.broadinstitute.hellbender.utils.Utils)5 Assert (org.testng.Assert)5 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)4 File (java.io.File)4 IntStream (java.util.stream.IntStream)4 StreamSupport (java.util.stream.StreamSupport)4 ReadsDataSource (org.broadinstitute.hellbender.engine.ReadsDataSource)4 ReadFilterLibrary (org.broadinstitute.hellbender.engine.filters.ReadFilterLibrary)4 WellformedReadFilter (org.broadinstitute.hellbender.engine.filters.WellformedReadFilter)4 IntervalUtils (org.broadinstitute.hellbender.utils.IntervalUtils)4