Search in sources :

Example 1 with PileupElement

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

the class ArtificialReadPileupTestProvider method createPileupElements.

private List<PileupElement> createPileupElements(String allele, GenomeLoc loc, int numReadsPerAllele, String sample, int readStart, String altBases, boolean addErrors, int phredScaledErrorRate, int refAlleleLength, boolean isReference) {
    int alleleLength = allele.length();
    List<PileupElement> pileupElements = new ArrayList<>();
    int readCounter = 0;
    for (int d = 0; d < numReadsPerAllele; d++) {
        byte[] readBases = trueHaplotype(allele, refAlleleLength, readLength);
        if (addErrors)
            addBaseErrors(readBases, phredScaledErrorRate);
        byte[] readQuals = new byte[readBases.length];
        Arrays.fill(readQuals, (byte) phredScaledErrorRate);
        GATKRead read = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(SAMRecord.NO_ALIGNMENT_CIGAR));
        read.setBaseQualities(readQuals);
        read.setBases(readBases);
        read.setName(artificialReadName + readCounter++);
        boolean isBeforeDeletion = alleleLength < refAlleleLength;
        boolean isBeforeInsertion = alleleLength > refAlleleLength;
        int eventLength = alleleLength - refAlleleLength;
        if (isReference)
            read.setCigar(readBases.length + "M");
        else {
            if (isBeforeDeletion || isBeforeInsertion)
                read.setCigar((readOffset + 1) + "M" + Math.abs(eventLength) + (isBeforeDeletion ? "D" : "I") + (readBases.length - readOffset) + "M");
            else
                // SNP case
                read.setCigar(readBases.length + "M");
        }
        read.setIsPaired(false);
        read.setPosition(loc.getContig(), readStart);
        read.setMappingQuality(artificialMappingQuality);
        read.setIsReverseStrand(false);
        read.setReadGroup(sampleRG(sample).getId());
        pileupElements.add(PileupElement.createPileupForReadAndOffset(read, readOffset));
    }
    return pileupElements;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement)

Example 2 with PileupElement

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

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

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

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

the class LocusIteratorByStateUnitTest method AssertWellOrderedPileup.

private void AssertWellOrderedPileup(final ReadPileup pileup) {
    if (!pileup.isEmpty()) {
        final int leftMostPos = -1;
        for (final PileupElement pe : pileup) {
            Assert.assertTrue(pileup.getLocation().getContig().equals(pe.getRead().getContig()), "ReadPileup contains an element " + pe + " that's on a different contig than the pileup itself");
            Assert.assertTrue(pe.getRead().getStart() >= leftMostPos, "ReadPileup contains an element " + pe + " whose read's alignment start " + pe.getRead().getStart() + " occurs before the leftmost position we've seen previously " + leftMostPos);
        }
    }
}
Also used : PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement)

Aggregations

PileupElement (org.broadinstitute.hellbender.utils.pileup.PileupElement)17 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)10 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)7 Test (org.testng.annotations.Test)7 AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 CigarOperator (htsjdk.samtools.CigarOperator)2 Locatable (htsjdk.samtools.util.Locatable)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)1 java.util (java.util)1 LinkedHashMap (java.util.LinkedHashMap)1 NGSPlatform (org.broadinstitute.hellbender.utils.NGSPlatform)1 QualityUtils (org.broadinstitute.hellbender.utils.QualityUtils)1 Utils (org.broadinstitute.hellbender.utils.Utils)1 DownsampleType (org.broadinstitute.hellbender.utils.downsampling.DownsampleType)1 DownsamplingMethod (org.broadinstitute.hellbender.utils.downsampling.DownsamplingMethod)1 ArtificialBAMBuilder (org.broadinstitute.hellbender.utils.read.ArtificialBAMBuilder)1