Search in sources :

Example 6 with AlignmentContext

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

the class ReferenceConfidenceModel method getPileupsOverReference.

/**
     * Get a list of pileups that span the entire active region span, in order, one for each position
     */
private List<ReadPileup> getPileupsOverReference(final Haplotype refHaplotype, final Collection<Haplotype> calledHaplotypes, final SimpleInterval paddedReferenceLoc, final AssemblyRegion activeRegion, final SimpleInterval activeRegionSpan, final ReadLikelihoods<Haplotype> readLikelihoods) {
    Utils.validateArg(calledHaplotypes.contains(refHaplotype), "calledHaplotypes must contain the refHaplotype");
    Utils.validateArg(readLikelihoods.numberOfSamples() == 1, () -> "readLikelihoods must contain exactly one sample but it contained " + readLikelihoods.numberOfSamples());
    final List<GATKRead> reads = activeRegion.getReads();
    final LocusIteratorByState libs = new LocusIteratorByState(reads.iterator(), LocusIteratorByState.NO_DOWNSAMPLING, false, samples.asSetOfSamples(), activeRegion.getHeader(), true);
    final int startPos = activeRegionSpan.getStart();
    final List<ReadPileup> pileups = new ArrayList<>(activeRegionSpan.getEnd() - startPos);
    AlignmentContext next = libs.advanceToLocus(startPos, true);
    for (int curPos = startPos; curPos <= activeRegionSpan.getEnd(); curPos++) {
        if (next != null && next.getLocation().getStart() == curPos) {
            pileups.add(next.getBasePileup());
            next = libs.hasNext() ? libs.next() : null;
        } else {
            // no data, so we create empty pileups
            pileups.add(new ReadPileup(new SimpleInterval(activeRegionSpan.getContig(), curPos, curPos)));
        }
    }
    return pileups;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) LocusIteratorByState(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByState) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 7 with AlignmentContext

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

the class ReferenceConfidenceModel method getPileupsOverReference.

/**
     * Get a list of pileups that span the entire active region span, in order, one for each position
     */
private List<ReadPileup> getPileupsOverReference(final Haplotype refHaplotype, final Collection<Haplotype> calledHaplotypes, final SimpleInterval paddedReferenceLoc, final AssemblyRegion activeRegion, final SimpleInterval activeRegionSpan, final ReadLikelihoods<Haplotype> readLikelihoods) {
    Utils.validateArg(calledHaplotypes.contains(refHaplotype), "calledHaplotypes must contain the refHaplotype");
    Utils.validateArg(readLikelihoods.numberOfSamples() == 1, () -> "readLikelihoods must contain exactly one sample but it contained " + readLikelihoods.numberOfSamples());
    final List<GATKRead> reads = activeRegion.getReads();
    final LocusIteratorByState libs = new LocusIteratorByState(reads.iterator(), LocusIteratorByState.NO_DOWNSAMPLING, false, samples.asSetOfSamples(), activeRegion.getHeader(), true);
    final int startPos = activeRegionSpan.getStart();
    final List<ReadPileup> pileups = new ArrayList<>(activeRegionSpan.getEnd() - startPos);
    AlignmentContext next = libs.advanceToLocus(startPos, true);
    for (int curPos = startPos; curPos <= activeRegionSpan.getEnd(); curPos++) {
        if (next != null && next.getLocation().getStart() == curPos) {
            pileups.add(next.getBasePileup());
            next = libs.hasNext() ? libs.next() : null;
        } else {
            // no data, so we create empty pileups
            pileups.add(new ReadPileup(new SimpleInterval(activeRegionSpan.getContig(), curPos, curPos)));
        }
    }
    return pileups;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) LocusIteratorByState(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByState) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 8 with AlignmentContext

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

the class PileupSpark method pileupFunction.

private static Function<LocusWalkerContext, String> pileupFunction(List<FeatureInput<Feature>> metadata, boolean outputInsertLength, boolean showVerbose) {
    return (Function<LocusWalkerContext, String>) context -> {
        AlignmentContext alignmentContext = context.getAlignmentContext();
        ReferenceContext referenceContext = context.getReferenceContext();
        FeatureContext featureContext = context.getFeatureContext();
        final String features = getFeaturesString(featureContext, metadata);
        final ReadPileup basePileup = alignmentContext.getBasePileup();
        final StringBuilder s = new StringBuilder();
        s.append(String.format("%s %s", basePileup.getPileupString((referenceContext.hasBackingDataSource()) ? (char) referenceContext.getBase() : 'N'), features));
        if (outputInsertLength) {
            s.append(" ").append(insertLengthOutput(basePileup));
        }
        if (showVerbose) {
            s.append(" ").append(createVerboseOutput(basePileup));
        }
        s.append("\n");
        return s.toString();
    };
}
Also used : Function(org.apache.spark.api.java.function.Function) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext)

Example 9 with AlignmentContext

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

the class IntervalAlignmentContextIterator method next.

@Override
public AlignmentContext next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    final boolean isOverlaps = currentInterval.overlaps(currentAlignmentContext);
    AlignmentContext result;
    // Get ready to return result and determine what should go the next time next() is called.
    if (isOverlaps) {
        result = currentAlignmentContext;
        advanceIntervalLocus();
        advanceAlignmentContextToCurrentInterval();
    } else {
        result = createEmptyAlignmentContext(currentInterval);
        advanceIntervalLocus();
        if (currentInterval != null) {
            final int comparison = IntervalUtils.compareLocatables(currentInterval, currentAlignmentContext, dictionary);
            //  Interval is after the next alignment context when comparison is greater than zero.
            if (comparison > 0) {
                advanceAlignmentContextToCurrentInterval();
            }
        }
    }
    return result;
}
Also used : AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with AlignmentContext

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

the class IntervalAlignmentContextIteratorUnitTest method testCoveredOnly.

@Test
public void testCoveredOnly() {
    // This test is good at finding places where the alignment contexts start behind the interval.
    // Totally covered
    final SimpleInterval record_20_9999910_9999913 = new SimpleInterval("20:9999910-9999913");
    final List<SimpleInterval> locusIntervals = new ArrayList<>(1);
    locusIntervals.add(record_20_9999910_9999913);
    final List<AlignmentContext> allAlignmentContexts = getAlignmentContexts(locusIntervals, BAM_FILE_NAME);
    Assert.assertEquals(allAlignmentContexts.size(), 4);
    Assert.assertTrue(allAlignmentContexts.stream().allMatch(ac -> ac != null));
}
Also used : IntStream(java.util.stream.IntStream) ReadsDataSource(org.broadinstitute.hellbender.engine.ReadsDataSource) java.util(java.util) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Test(org.testng.annotations.Test) LocusIteratorByState(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByState) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Collectors(java.util.stream.Collectors) File(java.io.File) IntervalUtils(org.broadinstitute.hellbender.utils.IntervalUtils) Stream(java.util.stream.Stream) Assert(org.testng.Assert) WellformedReadFilter(org.broadinstitute.hellbender.engine.filters.WellformedReadFilter) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) Utils(org.broadinstitute.hellbender.utils.Utils) StreamSupport(java.util.stream.StreamSupport) ReadFilterLibrary(org.broadinstitute.hellbender.engine.filters.ReadFilterLibrary) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) 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