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());
}
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);
}
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 } };
}
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 } };
}
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));
}
}
}
Aggregations