Search in sources :

Example 56 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class ReferenceContextUnitTest method testDynamicallyChangingWindow.

@Test
public void testDynamicallyChangingWindow() {
    try (final ReferenceDataSource reference = new ReferenceFileSource(TEST_REFERENCE)) {
        final SimpleInterval interval = new SimpleInterval("1", 11210, 11220);
        final ReferenceContext refContext = new ReferenceContext(reference, interval);
        final String intervalBases = "CGGTGCTGTGC";
        Assert.assertEquals(interval, refContext.getWindow());
        Assert.assertEquals(refContext.numWindowLeadingBases(), 0);
        Assert.assertEquals(refContext.numWindowTrailingBases(), 0);
        checkReferenceContextBases(refContext, intervalBases);
        Assert.assertEquals(refContext.getBase(), intervalBases.getBytes()[0]);
        Assert.assertEquals(refContext.getForwardBases(), intervalBases.getBytes());
        refContext.setWindow(5, 5);
        Assert.assertEquals(refContext.getWindow(), new SimpleInterval(interval.getContig(), interval.getStart() - 5, interval.getEnd() + 5));
        Assert.assertEquals(refContext.numWindowLeadingBases(), 5);
        Assert.assertEquals(refContext.numWindowTrailingBases(), 5);
        checkReferenceContextBases(refContext, "GCTCA" + intervalBases + "CAGGG");
        Assert.assertEquals(refContext.getBase(), intervalBases.getBytes()[0]);
        Assert.assertEquals(refContext.getForwardBases(), (intervalBases + "CAGGG").getBytes());
        refContext.setWindow(0, 10);
        Assert.assertEquals(refContext.getWindow(), new SimpleInterval(interval.getContig(), interval.getStart(), interval.getEnd() + 10));
        Assert.assertEquals(refContext.numWindowLeadingBases(), 0);
        Assert.assertEquals(refContext.numWindowTrailingBases(), 10);
        checkReferenceContextBases(refContext, intervalBases + "CAGGGCGCCC");
        Assert.assertEquals(refContext.getBase(), intervalBases.getBytes()[0]);
        Assert.assertEquals(refContext.getForwardBases(), (intervalBases + "CAGGGCGCCC").getBytes());
        refContext.setWindow(20, 3);
        Assert.assertEquals(refContext.getWindow(), new SimpleInterval(interval.getContig(), interval.getStart() - 20, interval.getEnd() + 3));
        Assert.assertEquals(refContext.numWindowLeadingBases(), 20);
        Assert.assertEquals(refContext.numWindowTrailingBases(), 3);
        checkReferenceContextBases(refContext, "CTACAGGACCCGCTTGCTCA" + intervalBases + "CAG");
        Assert.assertEquals(refContext.getBase(), intervalBases.getBytes()[0]);
        Assert.assertEquals(refContext.getForwardBases(), (intervalBases + "CAG").getBytes());
        refContext.setWindow(0, 0);
        Assert.assertEquals(interval, refContext.getWindow());
        Assert.assertEquals(refContext.numWindowLeadingBases(), 0);
        Assert.assertEquals(refContext.numWindowTrailingBases(), 0);
        checkReferenceContextBases(refContext, intervalBases);
        Assert.assertEquals(refContext.getBase(), intervalBases.getBytes()[0]);
        Assert.assertEquals(refContext.getForwardBases(), intervalBases.getBytes());
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 57 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class ProgressMeterUnitTest method testCantStartTwice.

@Test(expectedExceptions = IllegalStateException.class)
public void testCantStartTwice() throws Exception {
    ProgressMeter pm = new ProgressMeter();
    pm.start();
    pm.update(new SimpleInterval("1", 1, 1));
    pm.start();
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 58 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class ProgressMeterUnitTest method testSecondsSinceLastPrint.

@Test
public void testSecondsSinceLastPrint() {
    final ListBasedTimeFunction timeFunction = new ListBasedTimeFunction(Arrays.asList(1000l, 1500l, 2000l, 2500l, 3000l));
    final ProgressMeter meter = new ProgressMeter(1.0, timeFunction);
    final List<Double> expectedSecondsSinceLastPrint = Arrays.asList(0.5, 0.0, 0.5, 0.0);
    meter.start();
    // start() consumes one timestamp from our function, so we need to process size() - 1 more timestamps
    for (int i = 1; i <= timeFunction.size() - 1; ++i) {
        for (int j = 1; j <= ProgressMeter.DEFAULT_RECORDS_BETWEEN_TIME_CHECKS; ++j) {
            meter.update(new SimpleInterval("1", 1, 1));
        }
        Assert.assertEquals(meter.secondsSinceLastPrint(), expectedSecondsSinceLastPrint.get(i - 1), "Wrong number of seconds reported since last print");
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 59 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class ReadWalkerGCSSupportIntegrationTest method testReadBAMOnGCS.

@Test(dataProvider = "GCSTestCases", groups = { "bucket" })
public void testReadBAMOnGCS(final String bam, final List<SimpleInterval> intervals, final boolean includeUnmapped, final String expectedOutput) throws IOException {
    final StringBuilder intervalArgBuilder = new StringBuilder("");
    if (intervals != null) {
        for (final SimpleInterval interval : intervals) {
            intervalArgBuilder.append(" -L ");
            intervalArgBuilder.append(interval.toString());
        }
    }
    if (includeUnmapped) {
        intervalArgBuilder.append(" -L ");
        intervalArgBuilder.append("unmapped");
    }
    String intervalArg = intervalArgBuilder.toString();
    final IntegrationTestSpec testSpec = new IntegrationTestSpec(" -I " + getGCPTestInputPath() + bam + intervalArg + " -O %s", Collections.singletonList(expectedOutput));
    testSpec.executeTest("testReadBAMOnGCS", this);
}
Also used : IntegrationTestSpec(org.broadinstitute.hellbender.utils.test.IntegrationTestSpec) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 60 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class LocalReadShardUnitTest method divideIntervalIntoShardsTestData.

@DataProvider(name = "DivideIntervalIntoShardsTestData")
public Object[][] divideIntervalIntoShardsTestData() {
    // Doesn't matter which bam we use to back the reads source for the purposes of these tests.
    final ReadsDataSource readsSource = new ReadsDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam"));
    final SAMSequenceDictionary dictionary = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord("1", 16000)));
    return new Object[][] { // shardSize == 100, shardStep == 100, shardPadding == 0, start of contig
    { new SimpleInterval("1", 1, 100), 100, 100, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 1, 100), new SimpleInterval("1", 1, 100), readsSource)) }, // shardSize == 100, shardStep == 100, shardPadding == 10, start of contig
    { new SimpleInterval("1", 1, 100), 100, 100, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 1, 100), new SimpleInterval("1", 1, 110), readsSource)) }, // shardSize == 50, shardStep == 50, shardPadding == 0, start of contig
    { new SimpleInterval("1", 1, 100), 50, 50, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 1, 50), new SimpleInterval("1", 1, 50), readsSource), new LocalReadShard(new SimpleInterval("1", 51, 100), new SimpleInterval("1", 51, 100), readsSource)) }, // shardSize == 50, shardStep == 50, shardPadding == 10, start of contig
    { new SimpleInterval("1", 1, 100), 50, 50, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 1, 50), new SimpleInterval("1", 1, 60), readsSource), new LocalReadShard(new SimpleInterval("1", 51, 100), new SimpleInterval("1", 41, 110), readsSource)) }, // shardSize == 50, shardStep == 50, shardPadding == 0
    { new SimpleInterval("1", 51, 200), 50, 50, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 100), new SimpleInterval("1", 51, 100), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 150), new SimpleInterval("1", 101, 150), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 200), new SimpleInterval("1", 151, 200), readsSource)) }, // shardSize == 50, shardStep == 50, shardPadding == 10
    { new SimpleInterval("1", 51, 200), 50, 50, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 100), new SimpleInterval("1", 41, 110), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 150), new SimpleInterval("1", 91, 160), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 200), new SimpleInterval("1", 141, 210), readsSource)) }, // shardSize == 70, shardStep == 70, shardPadding == 0
    { new SimpleInterval("1", 51, 200), 70, 70, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 120), new SimpleInterval("1", 51, 120), readsSource), new LocalReadShard(new SimpleInterval("1", 121, 190), new SimpleInterval("1", 121, 190), readsSource), new LocalReadShard(new SimpleInterval("1", 191, 200), new SimpleInterval("1", 191, 200), readsSource)) }, // shardSize == 70, shardStep == 70, shardPadding == 10
    { new SimpleInterval("1", 51, 200), 70, 70, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 120), new SimpleInterval("1", 41, 130), readsSource), new LocalReadShard(new SimpleInterval("1", 121, 190), new SimpleInterval("1", 111, 200), readsSource), new LocalReadShard(new SimpleInterval("1", 191, 200), new SimpleInterval("1", 181, 210), readsSource)) }, // shardSize == 100, shardStep == 100, shardPadding == 10, end of contig
    { new SimpleInterval("1", 15999, 16000), 100, 100, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 15999, 16000), new SimpleInterval("1", 15989, 16000), readsSource)) }, // shardSize == 100, shardStep == 100, shardPadding == 0
    { new SimpleInterval("1", 51, 300), 100, 100, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 150), new SimpleInterval("1", 51, 150), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 250), new SimpleInterval("1", 151, 250), readsSource), new LocalReadShard(new SimpleInterval("1", 251, 300), new SimpleInterval("1", 251, 300), readsSource)) }, // shardSize == 100, shardStep == 50, shardPadding == 0
    { new SimpleInterval("1", 51, 300), 100, 50, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 150), new SimpleInterval("1", 51, 150), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 200), new SimpleInterval("1", 101, 200), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 250), new SimpleInterval("1", 151, 250), readsSource), new LocalReadShard(new SimpleInterval("1", 201, 300), new SimpleInterval("1", 201, 300), readsSource), new LocalReadShard(new SimpleInterval("1", 251, 300), new SimpleInterval("1", 251, 300), readsSource)) }, // shardSize == 100, shardStep == 50, shardPadding == 10
    { new SimpleInterval("1", 51, 300), 100, 50, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 150), new SimpleInterval("1", 41, 160), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 200), new SimpleInterval("1", 91, 210), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 250), new SimpleInterval("1", 141, 260), readsSource), new LocalReadShard(new SimpleInterval("1", 201, 300), new SimpleInterval("1", 191, 310), readsSource), new LocalReadShard(new SimpleInterval("1", 251, 300), new SimpleInterval("1", 241, 310), readsSource)) }, // shardSize == 100, shardStep == 25 shardPadding == 0
    { new SimpleInterval("1", 51, 300), 100, 25, 0, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 150), new SimpleInterval("1", 51, 150), readsSource), new LocalReadShard(new SimpleInterval("1", 76, 175), new SimpleInterval("1", 76, 175), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 200), new SimpleInterval("1", 101, 200), readsSource), new LocalReadShard(new SimpleInterval("1", 126, 225), new SimpleInterval("1", 126, 225), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 250), new SimpleInterval("1", 151, 250), readsSource), new LocalReadShard(new SimpleInterval("1", 176, 275), new SimpleInterval("1", 176, 275), readsSource), new LocalReadShard(new SimpleInterval("1", 201, 300), new SimpleInterval("1", 201, 300), readsSource), new LocalReadShard(new SimpleInterval("1", 226, 300), new SimpleInterval("1", 226, 300), readsSource), new LocalReadShard(new SimpleInterval("1", 251, 300), new SimpleInterval("1", 251, 300), readsSource), new LocalReadShard(new SimpleInterval("1", 276, 300), new SimpleInterval("1", 276, 300), readsSource)) }, // shardSize == 100, shardStep == 25, shardPadding == 10
    { new SimpleInterval("1", 51, 300), 100, 25, 10, readsSource, dictionary, Arrays.asList(new LocalReadShard(new SimpleInterval("1", 51, 150), new SimpleInterval("1", 41, 160), readsSource), new LocalReadShard(new SimpleInterval("1", 76, 175), new SimpleInterval("1", 66, 185), readsSource), new LocalReadShard(new SimpleInterval("1", 101, 200), new SimpleInterval("1", 91, 210), readsSource), new LocalReadShard(new SimpleInterval("1", 126, 225), new SimpleInterval("1", 116, 235), readsSource), new LocalReadShard(new SimpleInterval("1", 151, 250), new SimpleInterval("1", 141, 260), readsSource), new LocalReadShard(new SimpleInterval("1", 176, 275), new SimpleInterval("1", 166, 285), readsSource), new LocalReadShard(new SimpleInterval("1", 201, 300), new SimpleInterval("1", 191, 310), readsSource), new LocalReadShard(new SimpleInterval("1", 226, 300), new SimpleInterval("1", 216, 310), readsSource), new LocalReadShard(new SimpleInterval("1", 251, 300), new SimpleInterval("1", 241, 310), readsSource), new LocalReadShard(new SimpleInterval("1", 276, 300), new SimpleInterval("1", 266, 310), readsSource)) } };
}
Also used : SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) DataProvider(org.testng.annotations.DataProvider)

Aggregations

SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)545 Test (org.testng.annotations.Test)287 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)202 File (java.io.File)102 ArrayList (java.util.ArrayList)66 DataProvider (org.testng.annotations.DataProvider)64 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)60 Collectors (java.util.stream.Collectors)53 java.util (java.util)41 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)40 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)40 UserException (org.broadinstitute.hellbender.exceptions.UserException)39 VariantContext (htsjdk.variant.variantcontext.VariantContext)36 IntStream (java.util.stream.IntStream)34 Target (org.broadinstitute.hellbender.tools.exome.Target)34 IOException (java.io.IOException)32 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)28 Assert (org.testng.Assert)27 Locatable (htsjdk.samtools.util.Locatable)26 List (java.util.List)26