Search in sources :

Example 11 with Interval

use of htsjdk.samtools.util.Interval in project gatk by broadinstitute.

the class HetPulldownCalculatorUnitTest method inputGetTumorHetPulldown15.

@DataProvider(name = "inputGetTumorHetPulldownMin15")
public Object[][] inputGetTumorHetPulldown15() {
    final Pulldown tumorHetPulldown = new Pulldown(normalHeader);
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8));
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9));
    final IntervalList normalHetIntervals = new IntervalList(tumorHeader);
    normalHetIntervals.add(new Interval("1", 14630, 14630));
    normalHetIntervals.add(new Interval("2", 14689, 14689));
    return new Object[][] { { normalHetIntervals, tumorHetPulldown } };
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Interval(htsjdk.samtools.util.Interval) DataProvider(org.testng.annotations.DataProvider)

Example 12 with Interval

use of htsjdk.samtools.util.Interval in project gatk-protected by broadinstitute.

the class HetPulldownCalculatorUnitTest method inputGetPileupBaseCount.

@DataProvider(name = "inputGetPileupBaseCount")
public Object[][] inputGetPileupBaseCount() throws IOException {
    try (final SamReader bamReader = SamReaderFactory.makeDefault().open(NORMAL_BAM_FILE)) {
        final IntervalList intervals = new IntervalList(bamReader.getFileHeader());
        intervals.add(new Interval("1", 100, 100));
        intervals.add(new Interval("1", 11000, 11000));
        intervals.add(new Interval("1", 14000, 14000));
        intervals.add(new Interval("1", 14630, 14630));
        final SamLocusIterator locusIterator = new SamLocusIterator(bamReader, intervals);
        final Nucleotide.Counter baseCounts1 = makeBaseCounts(0, 0, 0, 0);
        final Nucleotide.Counter baseCounts2 = makeBaseCounts(0, 9, 0, 0);
        final Nucleotide.Counter baseCounts3 = makeBaseCounts(12, 0, 0, 0);
        final Nucleotide.Counter baseCounts4 = makeBaseCounts(0, 0, 8, 9);
        if (!locusIterator.hasNext()) {
            throw new SAMException("Can't get locus to start iteration. Check that " + NORMAL_BAM_FILE.toString() + " contains 1:0-16000.");
        }
        final SamLocusIterator.LocusInfo locus1 = locusIterator.next();
        final SamLocusIterator.LocusInfo locus2 = locusIterator.next();
        final SamLocusIterator.LocusInfo locus3 = locusIterator.next();
        final SamLocusIterator.LocusInfo locus4 = locusIterator.next();
        locusIterator.close();
        return new Object[][] { { locus1, baseCounts1 }, { locus2, baseCounts2 }, { locus3, baseCounts3 }, { locus4, baseCounts4 } };
    }
}
Also used : SamLocusIterator(htsjdk.samtools.util.SamLocusIterator) IntervalList(htsjdk.samtools.util.IntervalList) Nucleotide(org.broadinstitute.hellbender.utils.Nucleotide) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Interval(htsjdk.samtools.util.Interval) DataProvider(org.testng.annotations.DataProvider)

Example 13 with Interval

use of htsjdk.samtools.util.Interval in project gatk-protected by broadinstitute.

the class HetPulldownCalculatorUnitTest method inputGetTumorHetPulldown.

@DataProvider(name = "inputGetTumorHetPulldown")
public Object[][] inputGetTumorHetPulldown() {
    final Pulldown tumorHetPulldown = new Pulldown(normalHeader);
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 11522, 11522), 7, 4));
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 12098, 12098), 8, 6));
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8));
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9));
    tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14982, 14982), 6, 5));
    final IntervalList normalHetIntervals = new IntervalList(tumorHeader);
    normalHetIntervals.add(new Interval("1", 11522, 11522));
    normalHetIntervals.add(new Interval("1", 12098, 12098));
    normalHetIntervals.add(new Interval("1", 14630, 14630));
    normalHetIntervals.add(new Interval("2", 14689, 14689));
    normalHetIntervals.add(new Interval("2", 14982, 14982));
    return new Object[][] { { normalHetIntervals, tumorHetPulldown } };
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Interval(htsjdk.samtools.util.Interval) DataProvider(org.testng.annotations.DataProvider)

Example 14 with Interval

use of htsjdk.samtools.util.Interval in project gatk by broadinstitute.

the class RnaSeqMetricsCollector method makeOverlapDetector.

public static OverlapDetector<Interval> makeOverlapDetector(final File samFile, final SAMFileHeader header, final File ribosomalIntervalsFile) {
    OverlapDetector<Interval> ribosomalSequenceOverlapDetector = new OverlapDetector<>(0, 0);
    if (ribosomalIntervalsFile != null) {
        final IntervalList ribosomalIntervals = IntervalList.fromFile(ribosomalIntervalsFile);
        try {
            SequenceUtil.assertSequenceDictionariesEqual(header.getSequenceDictionary(), ribosomalIntervals.getHeader().getSequenceDictionary());
        } catch (SequenceUtil.SequenceListsDifferException e) {
            throw new UserException("Sequence dictionaries differ in " + samFile.getAbsolutePath() + " and " + ribosomalIntervalsFile.getAbsolutePath(), e);
        }
        final IntervalList uniquedRibosomalIntervals = ribosomalIntervals.uniqued();
        final List<Interval> intervals = uniquedRibosomalIntervals.getIntervals();
        ribosomalSequenceOverlapDetector.addAll(intervals, intervals);
    }
    return ribosomalSequenceOverlapDetector;
}
Also used : SequenceUtil(htsjdk.samtools.util.SequenceUtil) IntervalList(htsjdk.samtools.util.IntervalList) UserException(org.broadinstitute.hellbender.exceptions.UserException) OverlapDetector(htsjdk.samtools.util.OverlapDetector) Interval(htsjdk.samtools.util.Interval)

Example 15 with Interval

use of htsjdk.samtools.util.Interval in project gatk by broadinstitute.

the class IntervalListScatterer method scatter.

public List<IntervalList> scatter(final IntervalList sourceIntervalList, final int scatterCount, final boolean isUniqued) {
    Utils.validateArg(scatterCount >= 1, "scatterCount < 1");
    final IntervalList uniquedList = isUniqued ? sourceIntervalList : sourceIntervalList.uniqued();
    final long idealSplitLength = deduceIdealSplitLength(uniquedList, scatterCount);
    final List<IntervalList> accumulatedIntervalLists = new ArrayList<>();
    IntervalList runningIntervalList = new IntervalList(uniquedList.getHeader());
    final ArrayDeque<Interval> intervalQueue = new ArrayDeque<>(uniquedList.getIntervals());
    while (!intervalQueue.isEmpty() && accumulatedIntervalLists.size() < scatterCount - 1) {
        final Interval interval = intervalQueue.pollFirst();
        final long projectedSize = runningIntervalList.getBaseCount() + interval.length();
        if (projectedSize <= idealSplitLength) {
            runningIntervalList.add(interval);
        } else {
            switch(mode) {
                case INTERVAL_SUBDIVISION:
                    final int amountToConsume = (int) (idealSplitLength - runningIntervalList.getBaseCount());
                    final Interval left = new Interval(interval.getContig(), interval.getStart(), interval.getStart() + amountToConsume - 1, interval.isNegativeStrand(), interval.getName());
                    final Interval right = new Interval(interval.getContig(), interval.getStart() + amountToConsume, interval.getEnd(), interval.isNegativeStrand(), interval.getName());
                    runningIntervalList.add(left);
                    // Push back the excess back onto our queue for reconsideration.
                    intervalQueue.addFirst(right);
                    break;
                case BALANCING_WITHOUT_INTERVAL_SUBDIVISION:
                    if (runningIntervalList.getIntervals().isEmpty()) {
                        runningIntervalList.add(interval);
                    } else {
                        // Push this interval into the next scatter; re-inject it into the queue, then advance the scatter.
                        intervalQueue.addFirst(interval);
                        accumulatedIntervalLists.add(runningIntervalList.uniqued());
                        runningIntervalList = new IntervalList(uniquedList.getHeader());
                    }
                    break;
            }
        }
        if (runningIntervalList.getBaseCount() >= idealSplitLength) {
            accumulatedIntervalLists.add(runningIntervalList.uniqued());
            runningIntervalList = new IntervalList(uniquedList.getHeader());
        }
    }
    // Flush the remaining intervals into the last split.
    while (!intervalQueue.isEmpty()) {
        runningIntervalList.add(intervalQueue.pollFirst());
    }
    if (!runningIntervalList.getIntervals().isEmpty()) {
        accumulatedIntervalLists.add(runningIntervalList.uniqued());
    }
    return accumulatedIntervalLists;
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) Interval(htsjdk.samtools.util.Interval)

Aggregations

Interval (htsjdk.samtools.util.Interval)24 IntervalList (htsjdk.samtools.util.IntervalList)23 File (java.io.File)10 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)8 SAMFileHeader (htsjdk.samtools.SAMFileHeader)6 DataProvider (org.testng.annotations.DataProvider)6 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 Test (org.testng.annotations.Test)5 QueryInterval (htsjdk.samtools.QueryInterval)4 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)4 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)3 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)3 SAMFileWriter (htsjdk.samtools.SAMFileWriter)2 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)2 SAMRecord (htsjdk.samtools.SAMRecord)2 SAMRecordSetBuilder (htsjdk.samtools.SAMRecordSetBuilder)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 MetricsFile (htsjdk.samtools.metrics.MetricsFile)2 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 SamLocusIterator (htsjdk.samtools.util.SamLocusIterator)2