use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class LocusIteratorByStateUnitTest method testLIBS_NotHoldingTooManyReads.
@Test(enabled = true, dataProvider = "LIBS_NotHoldingTooManyReads")
public void testLIBS_NotHoldingTooManyReads(final int nReadsPerLocus, final int downsampleTo, final int payloadInBytes) {
logger.warn(String.format("testLIBS_NotHoldingTooManyReads %d %d %d", nReadsPerLocus, downsampleTo, payloadInBytes));
final int readLength = 10;
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 100000);
final int nSamples = 1;
final List<String> samples = new ArrayList<>(nSamples);
for (int i = 0; i < nSamples; i++) {
final SAMReadGroupRecord rg = new SAMReadGroupRecord("rg" + i);
final String sample = "sample" + i;
samples.add(sample);
rg.setSample(sample);
rg.setPlatform(NGSPlatform.ILLUMINA.getDefaultPlatform());
header.addReadGroup(rg);
}
final boolean downsample = downsampleTo != -1;
final DownsamplingMethod downsampler = downsample ? new DownsamplingMethod(DownsampleType.BY_SAMPLE, downsampleTo, null) : new DownsamplingMethod(DownsampleType.NONE, null, null);
final WeakReadTrackingIterator iterator = new WeakReadTrackingIterator(nReadsPerLocus, readLength, payloadInBytes, header);
final LocusIteratorByState li;
li = new LocusIteratorByState(iterator, downsampler, false, samples, header, true);
while (li.hasNext()) {
final AlignmentContext next = li.next();
Assert.assertTrue(next.getBasePileup().size() <= downsampleTo, "Too many elements in pileup " + next);
// TODO -- assert that there are <= X reads in memory after GC for some X
}
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class LocusIteratorByStateUnitTest method testWholeIndelRead.
/**
* Test to make sure that reads supporting only an indel (example cigar string: 76I) do
* not negatively influence the ordering of the pileup.
*/
@Test
public void testWholeIndelRead() {
final int firstLocus = 44367788, secondLocus = firstLocus + 1;
final GATKRead leadingRead = ArtificialReadUtils.createArtificialRead(header, "leading", 0, firstLocus, 76);
leadingRead.setBases(Utils.dupBytes((byte) 'A', 76));
leadingRead.setBaseQualities(Utils.dupBytes((byte) '@', 76));
leadingRead.setCigar("1M75I");
final GATKRead indelOnlyRead = ArtificialReadUtils.createArtificialRead(header, "indelOnly", 0, secondLocus, 76);
indelOnlyRead.setBases(Utils.dupBytes((byte) 'A', 76));
indelOnlyRead.setBaseQualities(Utils.dupBytes((byte) '@', 76));
indelOnlyRead.setCigar("76I");
final GATKRead fullMatchAfterIndel = ArtificialReadUtils.createArtificialRead(header, "fullMatch", 0, secondLocus, 76);
fullMatchAfterIndel.setBases(Utils.dupBytes((byte) 'A', 76));
fullMatchAfterIndel.setBaseQualities(Utils.dupBytes((byte) '@', 76));
fullMatchAfterIndel.setCigar("75I1M");
final List<GATKRead> reads = Arrays.asList(leadingRead, indelOnlyRead, fullMatchAfterIndel);
// create the iterator by state with the fake reads and fake records
final LocusIteratorByState li;
li = makeLIBS(reads, null, false, header);
int currentLocus = firstLocus;
int numAlignmentContextsFound = 0;
while (li.hasNext()) {
final AlignmentContext alignmentContext = li.next();
Assert.assertEquals(alignmentContext.getLocation().getStart(), currentLocus, "Current locus returned by alignment context is incorrect");
if (currentLocus == firstLocus) {
final List<GATKRead> readsAtLocus = alignmentContext.getBasePileup().getReads();
Assert.assertEquals(readsAtLocus.size(), 1, "Wrong number of reads at locus " + currentLocus);
Assert.assertSame(readsAtLocus.get(0), leadingRead, "leadingRead absent from pileup at locus " + currentLocus);
} else if (currentLocus == secondLocus) {
final List<GATKRead> readsAtLocus = alignmentContext.getBasePileup().getReads();
Assert.assertEquals(readsAtLocus.size(), 1, "Wrong number of reads at locus " + currentLocus);
Assert.assertSame(readsAtLocus.get(0), fullMatchAfterIndel, "fullMatchAfterIndel absent from pileup at locus " + currentLocus);
}
currentLocus++;
numAlignmentContextsFound++;
}
Assert.assertEquals(numAlignmentContextsFound, 2, "Found incorrect number of alignment contexts");
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class LocusIteratorByStateUnitTest method testXandEQOperators.
@Test
public void testXandEQOperators() {
final byte[] bases1 = { 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A' };
final byte[] bases2 = { 'A', 'A', 'A', 'C', 'A', 'A', 'A', 'A', 'A', 'C' };
final GATKRead r1 = ArtificialReadUtils.createArtificialRead(header, "r1", 0, 1, 10);
r1.setBases(bases1);
r1.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
r1.setCigar("10M");
final GATKRead r2 = ArtificialReadUtils.createArtificialRead(header, "r2", 0, 1, 10);
r2.setBases(bases2);
r2.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
r2.setCigar("3=1X5=1X");
final GATKRead r3 = ArtificialReadUtils.createArtificialRead(header, "r3", 0, 1, 10);
r3.setBases(bases2);
r3.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
r3.setCigar("3=1X5M1X");
final GATKRead r4 = ArtificialReadUtils.createArtificialRead(header, "r4", 0, 1, 10);
r4.setBases(bases2);
r4.setBaseQualities(new byte[] { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
r4.setCigar("10M");
final List<GATKRead> reads = Arrays.asList(r1, r2, r3, r4);
// create the iterator by state with the fake reads and fake records
final LocusIteratorByState li;
li = makeLIBS(reads, header);
while (li.hasNext()) {
final AlignmentContext context = li.next();
final ReadPileup pileup = context.getBasePileup();
Assert.assertEquals(pileup.size(), 4);
}
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class IntervalAlignmentContextIteratorUnitTest method testSimple.
@Test
public void testSimple() {
// Note: IGV was used to determine coverage in the input bam file. (chr20:9,999,875-9,999,945)
// Make sure that viewing is *not* downsampled and *includes* dupe reads
// Totally uncovered
final SimpleInterval record_20_9999600_9999600 = new SimpleInterval("20:9999600-9999600");
// Partially covered
final SimpleInterval record_20_9999900_9999910 = new SimpleInterval("20:9999900-9999910");
// Totally covered
final SimpleInterval record_20_9999910_9999913 = new SimpleInterval("20:9999910-9999913");
final List<SimpleInterval> locusIntervals = new ArrayList<>(3);
locusIntervals.add(record_20_9999600_9999600);
locusIntervals.add(record_20_9999900_9999910);
locusIntervals.add(record_20_9999910_9999913);
final List<AlignmentContext> allAlignmentContexts = getAlignmentContexts(locusIntervals, BAM_FILE_NAME);
Assert.assertEquals(allAlignmentContexts.size(), 16);
Assert.assertTrue(allAlignmentContexts.stream().allMatch(ac -> ac != null));
// No reads in the first three alignment contexts
Assert.assertEquals(allAlignmentContexts.get(0).getBasePileup().getReads().size(), 0);
Assert.assertEquals(allAlignmentContexts.get(1).getBasePileup().getReads().size(), 0);
Assert.assertEquals(allAlignmentContexts.get(2).getBasePileup().getReads().size(), 0);
// Make sure that at least one locus-interval has at least one read
Assert.assertTrue(allAlignmentContexts.stream().anyMatch(ac -> ac.getBasePileup().getReads().size() > 0));
Assert.assertTrue(allAlignmentContexts.stream().anyMatch(ac -> ac.getBasePileup().getReads().size() == 0));
Assert.assertEquals(allAlignmentContexts.get(3).getBasePileup().getReads().size(), 2);
Assert.assertEquals(allAlignmentContexts.get(4).getBasePileup().getReads().size(), 4);
Assert.assertEquals(allAlignmentContexts.get(13).getBasePileup().getReads().size(), 17);
}
use of org.broadinstitute.hellbender.engine.AlignmentContext in project gatk by broadinstitute.
the class IntervalAlignmentContextIteratorUnitTest method testPileupToNextPileup.
@Test
public void testPileupToNextPileup() {
// Test reading the end of one pileup then no coverage then beginning of one pileup in one interval
// IGV: chr20:10,098,446-10,098,587
final SimpleInterval record_20_10098490_10098560 = new SimpleInterval("20:10098490-10098560");
final List<SimpleInterval> locusIntervals = new ArrayList<>(1);
locusIntervals.add(record_20_10098490_10098560);
final List<AlignmentContext> allAlignmentContexts = getAlignmentContexts(locusIntervals, BAM_FILE_NAME);
Assert.assertEquals(allAlignmentContexts.size(), 71);
Assert.assertTrue(allAlignmentContexts.stream().allMatch(ac -> ac.getBasePileup().getReads().size() < 2));
Assert.assertTrue(IntStream.range(0, 6).allMatch(i -> allAlignmentContexts.get(i).size() == 1));
Assert.assertTrue(IntStream.range(6, 62).allMatch(i -> allAlignmentContexts.get(i).size() == 0));
Assert.assertTrue(IntStream.range(62, 71).allMatch(i -> allAlignmentContexts.get(i).size() == 1));
Assert.assertTrue(allAlignmentContexts.stream().allMatch(ac -> ac != null));
}
Aggregations