Search in sources :

Example 6 with ReadPileup

use of org.broadinstitute.hellbender.utils.pileup.ReadPileup in project gatk by broadinstitute.

the class GATKProtectedVariantContextUtilsUnitTest method testGetPileup.

@Test
public void testGetPileup() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
    final Locatable loc = new SimpleInterval("chr1", 10, 10);
    final int readLength = 3;
    //this read doesn't overlap {@code loc}
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, readLength);
    read1.setBases(Utils.dupBytes((byte) 'A', readLength));
    read1.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
    read1.setCigar("3M");
    //this read overlaps {@code loc} with a Q30 'A'
    final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 0, 10, readLength);
    read2.setBases(Utils.dupBytes((byte) 'A', readLength));
    read2.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
    read2.setCigar("3M");
    //this read overlaps {@code loc} with a Q20 'C' (due to the deletion)
    final GATKRead read3 = ArtificialReadUtils.createArtificialRead(header, "read3", 0, 7, readLength);
    read3.setBases(Utils.dupBytes((byte) 'C', readLength));
    read3.setBaseQualities(Utils.dupBytes((byte) 20, readLength));
    read3.setCigar("1M1D2M");
    //this read doesn't overlap {@code loc} due to the deletion
    final GATKRead read4 = ArtificialReadUtils.createArtificialRead(header, "read4", 0, 7, readLength);
    read4.setBases(Utils.dupBytes((byte) 'C', readLength));
    read4.setBaseQualities(Utils.dupBytes((byte) 20, readLength));
    read4.setCigar("1M5D2M");
    final ReadPileup pileup = GATKProtectedVariantContextUtils.getPileup(loc, Arrays.asList(read1, read2, read3, read4));
    // the pileup should contain a Q30 'A' and a Q20 'C'
    final int[] counts = pileup.getBaseCounts();
    Assert.assertEquals(counts, new int[] { 1, 1, 0, 0 });
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Locatable(htsjdk.samtools.util.Locatable) Test(org.testng.annotations.Test)

Example 7 with ReadPileup

use of org.broadinstitute.hellbender.utils.pileup.ReadPileup 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 8 with ReadPileup

use of org.broadinstitute.hellbender.utils.pileup.ReadPileup 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 9 with ReadPileup

use of org.broadinstitute.hellbender.utils.pileup.ReadPileup 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 10 with ReadPileup

use of org.broadinstitute.hellbender.utils.pileup.ReadPileup in project gatk by broadinstitute.

the class LocusIteratorByStateUnitTest method getFirstPileupElement.

private PileupElement getFirstPileupElement(final AlignmentContext context) {
    final ReadPileup p = context.getBasePileup();
    Assert.assertEquals(p.size(), 1);
    return p.iterator().next();
}
Also used : ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup)

Aggregations

ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)36 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)24 Test (org.testng.annotations.Test)19 AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)14 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)13 SAMFileHeader (htsjdk.samtools.SAMFileHeader)11 Locatable (htsjdk.samtools.util.Locatable)11 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)9 PileupElement (org.broadinstitute.hellbender.utils.pileup.PileupElement)7 java.util (java.util)5 VariantContext (htsjdk.variant.variantcontext.VariantContext)4 Collectors (java.util.stream.Collectors)4 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)3 FeatureContext (org.broadinstitute.hellbender.engine.FeatureContext)3 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CigarOperator (htsjdk.samtools.CigarOperator)2 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)2 htsjdk.variant.vcf (htsjdk.variant.vcf)2 VCFConstants (htsjdk.variant.vcf.VCFConstants)2