Search in sources :

Example 31 with Locatable

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

the class GenomeLocParserUnitTest method testCreationFromLocatable.

@Test
public void testCreationFromLocatable() {
    final Locatable locatable = new SimpleInterval("1", 1, 5);
    final GenomeLoc loc = genomeLocParser.createGenomeLoc(locatable);
    Assert.assertEquals(loc.getContig(), locatable.getContig());
    Assert.assertEquals(loc.getStart(), locatable.getStart());
    Assert.assertEquals(loc.getStop(), locatable.getEnd());
}
Also used : Locatable(htsjdk.samtools.util.Locatable) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 32 with Locatable

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

the class SparkSharderUnitTest method testContigBoundary.

@Test
public void testContigBoundary() throws IOException {
    JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
    // Consider the following reads (divided into four partitions), and intervals.
    // This test counts the number of reads that overlap each interval.
    //                      1                   2
    //    1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
    // ---------------------------------------------------------
    // Reads in partition 0
    //   [-----] chr 1
    //           [-----] chr 1
    //               [-----] chr 1
    //   [-----] chr 2
    //     [-----] chr 2
    // ---------------------------------------------------------
    // Per-partition read extents
    //   [-----------------] chr 1
    //   [-------] chr 2
    // ---------------------------------------------------------
    // Intervals
    //     [-----] chr 1
    //                 [---------] chr 1
    //   [-----------------------] chr 2
    // ---------------------------------------------------------
    //    1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
    JavaRDD<TestRead> reads = ctx.parallelize(ImmutableList.of(new TestRead("1", 1, 3), new TestRead("1", 5, 7), new TestRead("1", 7, 9), new TestRead("2", 1, 3), new TestRead("2", 2, 4)), 1);
    List<SimpleInterval> intervals = ImmutableList.of(new SimpleInterval("1", 2, 4), new SimpleInterval("1", 8, 12), new SimpleInterval("2", 1, 12));
    List<ShardBoundary> shardBoundaries = intervals.stream().map(si -> new ShardBoundary(si, si)).collect(Collectors.toList());
    ImmutableMap<SimpleInterval, Integer> expectedReadsPerInterval = ImmutableMap.of(intervals.get(0), 1, intervals.get(1), 1, intervals.get(2), 2);
    JavaPairRDD<Locatable, Integer> readsPerInterval = SparkSharder.shard(ctx, reads, TestRead.class, sequenceDictionary, shardBoundaries, STANDARD_READ_LENGTH, false).flatMapToPair(new CountOverlappingReadsFunction());
    assertEquals(readsPerInterval.collectAsMap(), expectedReadsPerInterval);
    JavaPairRDD<Locatable, Integer> readsPerIntervalShuffle = SparkSharder.shard(ctx, reads, TestRead.class, sequenceDictionary, shardBoundaries, STANDARD_READ_LENGTH, true).flatMapToPair(new CountOverlappingReadsFunction());
    assertEquals(readsPerIntervalShuffle.collectAsMap(), expectedReadsPerInterval);
}
Also used : Locatable(htsjdk.samtools.util.Locatable) OverlapDetector(htsjdk.samtools.util.OverlapDetector) java.util(java.util) PairFlatMapFunction(org.apache.spark.api.java.function.PairFlatMapFunction) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) IOException(java.io.IOException) Tuple2(scala.Tuple2) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Collectors(java.util.stream.Collectors) Shard(org.broadinstitute.hellbender.engine.Shard) Serializable(java.io.Serializable) UserException(org.broadinstitute.hellbender.exceptions.UserException) ShardBoundary(org.broadinstitute.hellbender.engine.ShardBoundary) Assert.assertTrue(org.testng.Assert.assertTrue) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) com.google.common.collect(com.google.common.collect) Assert.assertFalse(org.testng.Assert.assertFalse) JavaRDD(org.apache.spark.api.java.JavaRDD) ShardBoundary(org.broadinstitute.hellbender.engine.ShardBoundary) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Locatable(htsjdk.samtools.util.Locatable) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 33 with Locatable

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

the class HaplotypeBAMWriterUnitTest method makeReadsLikelikhoodData.

@DataProvider(name = "ReadsLikelikhoodData")
public Object[][] makeReadsLikelikhoodData() {
    final String haplotypeBaseSignature = "ACTGAAGGTTCC";
    final Haplotype haplotype = makeHaplotype(haplotypeBaseSignature);
    final int[] sampleCounts = { 2, 2 };
    final Locatable loc = new SimpleInterval("20", 10, 20);
    final ReadLikelihoods<Haplotype> readLikelihoods = generateReadLikelihoods(sampleCounts);
    return new Object[][] { { haplotypeBaseSignature, Collections.singletonList(haplotype), loc, readLikelihoods } };
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) DataProvider(org.testng.annotations.DataProvider)

Example 34 with Locatable

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

the class IntervalsSkipListUnitTest method intervals.

@DataProvider(name = "intervals")
public Object[][] intervals() {
    ArrayList<Locatable> input = Lists.newArrayList(new SimpleInterval("1", 10, 100), new SimpleInterval("2", 200, 300));
    ArrayList<Locatable> empty = new ArrayList<>();
    ArrayList<Locatable> contig1 = Lists.newArrayList(new SimpleInterval("1", 10, 100));
    ArrayList<Locatable> contig2 = Lists.newArrayList(new SimpleInterval("2", 200, 300));
    // returns input, query range, expected SimpleIntervals
    return new Object[][] { // it picks the correct contig and can deal with not-yet-mentioned contigs.
    new Object[] { input, new SimpleInterval("1", 100, 200), contig1 }, new Object[] { input, new SimpleInterval("1", 1, 5), empty }, new Object[] { input, new SimpleInterval("2", 100, 200), contig2 }, new Object[] { input, new SimpleInterval("3", 100, 200), empty } };
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) DataProvider(org.testng.annotations.DataProvider)

Example 35 with Locatable

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

the class LocusIteratorByState method lazyLoadNextAlignmentContext.

/**
     * Creates the next alignment context from the given state.  Note that this is implemented as a
     * lazy load method. nextAlignmentContext MUST BE null in order for this method to advance to the
     * next entry.
     */
private void lazyLoadNextAlignmentContext() {
    while (nextAlignmentContext == null && readStates.hasNext()) {
        readStates.collectPendingReads();
        final Locatable location = getLocation();
        final Map<String, ReadPileup> fullPileupPerSample = new LinkedHashMap<>();
        for (final Map.Entry<String, PerSampleReadStateManager> sampleStatePair : readStates) {
            final String sample = sampleStatePair.getKey();
            final PerSampleReadStateManager readState = sampleStatePair.getValue();
            final Iterator<AlignmentStateMachine> iterator = readState.iterator();
            final List<PileupElement> pile = new ArrayList<>(readState.size());
            while (iterator.hasNext()) {
                // state object with the read/offset information
                final AlignmentStateMachine state = iterator.next();
                final GATKRead read = state.getRead();
                final CigarOperator op = state.getCigarOperator();
                if (!includeReadsWithNsAtLoci && op == CigarOperator.N) {
                    continue;
                }
                if (!dontIncludeReadInPileup(read, location.getStart())) {
                    if (!includeReadsWithDeletionAtLoci && op == CigarOperator.D) {
                        continue;
                    }
                    pile.add(state.makePileupElement());
                }
            }
            if (!pile.isEmpty()) {
                // if this pileup added at least one base, add it to the full pileup
                fullPileupPerSample.put(sample, new ReadPileup(location, pile));
            }
        }
        // critical - must be called after we get the current state offsets and location
        readStates.updateReadStates();
        if (!fullPileupPerSample.isEmpty()) {
            // if we got reads with non-D/N over the current position, we are done
            nextAlignmentContext = new AlignmentContext(location, new ReadPileup(location, fullPileupPerSample));
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) CigarOperator(htsjdk.samtools.CigarOperator) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) Locatable(htsjdk.samtools.util.Locatable)

Aggregations

Locatable (htsjdk.samtools.util.Locatable)38 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)24 Test (org.testng.annotations.Test)22 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)20 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)11 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)10 SAMFileHeader (htsjdk.samtools.SAMFileHeader)6 ArrayList (java.util.ArrayList)5 UserException (org.broadinstitute.hellbender.exceptions.UserException)5 DataProvider (org.testng.annotations.DataProvider)4 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)3 com.google.common.collect (com.google.common.collect)2 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 OverlapDetector (htsjdk.samtools.util.OverlapDetector)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 java.util (java.util)2 LinkedHashMap (java.util.LinkedHashMap)2 Collectors (java.util.stream.Collectors)2