Search in sources :

Example 51 with SimpleInterval

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

the class ReadsContextUnitTest method getValidReadsContextData.

@DataProvider(name = "ReadsContextFilteringDataProvider")
public Object[][] getValidReadsContextData() {
    // Default-constructed ReadsContexts and ReadsContexts constructed from null ReadsDataSources/intervals
    // should behave as empty context objects.
    ReadNameReadFilter readNameFilter = new ReadNameReadFilter();
    readNameFilter.readName = "d";
    return new Object[][] { { new ReadsContext(new ReadsDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam")), // query over small interval, with no read filter
    new SimpleInterval("1", 200, 210), ReadFilterLibrary.ALLOW_ALL_READS), new String[] { "a", "b", "c" } }, { new ReadsContext(new ReadsDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam")), // query over larger interval with readNameFilter on "d"
    new SimpleInterval("1", 200, 1000), readNameFilter), new String[] { "d" } } };
}
Also used : ReadNameReadFilter(org.broadinstitute.hellbender.engine.filters.ReadNameReadFilter) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) DataProvider(org.testng.annotations.DataProvider)

Example 52 with SimpleInterval

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

the class ReadsDataSourceUnitTest method testHandleUnindexedFileQuery.

@Test(expectedExceptions = UserException.class)
public void testHandleUnindexedFileQuery() {
    // Construction should succeed, since we don't pass in any intervals, but the query should throw.
    final Path unindexed = IOUtils.getPath(READS_DATA_SOURCE_TEST_DIRECTORY + "unindexed.bam");
    Assert.assertNull(SamFiles.findIndex(unindexed), "Expected file to have no index, but found an index file" + unindexed.toAbsolutePath());
    ReadsDataSource readsSource = new ReadsDataSource(unindexed);
    readsSource.query(new SimpleInterval("1", 1, 5));
}
Also used : Path(java.nio.file.Path) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 53 with SimpleInterval

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

the class ReadsDataSourceUnitTest method traversalWithUnmappedReadsTestData.

@DataProvider(name = "TraversalWithUnmappedReadsTestData")
public Object[][] traversalWithUnmappedReadsTestData() {
    // This bam has only mapped reads
    final Path mappedBam = IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam");
    // This bam has mapped reads from various contigs, plus a few unmapped reads with no mapped mate
    final Path unmappedBam = IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1_with_unmapped.bam");
    // This is a snippet of the CEUTrio.HiSeq.WGS.b37.NA12878 bam from large, with mapped reads
    // from chromosome 20 (with one mapped read having an unmapped mate), plus several unmapped
    // reads with no mapped mate.
    final Path ceuSnippet = IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/CEUTrio.HiSeq.WGS.b37.NA12878.snippet_with_unmapped.bam");
    return new Object[][] { // One interval, no unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 200, 1000)), false, Arrays.asList("a", "b", "c", "d") }, // One interval, with unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 200, 1000)), true, Arrays.asList("a", "b", "c", "d", "u1", "u2", "u3", "u4", "u5") }, // Multiple intervals, no unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 200, 1000), new SimpleInterval("2", 500, 700), new SimpleInterval("4", 700, 701)), false, Arrays.asList("a", "b", "c", "d", "f", "g", "h", "k") }, // Multiple intervals, with unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 200, 1000), new SimpleInterval("2", 500, 700), new SimpleInterval("4", 700, 701)), true, Arrays.asList("a", "b", "c", "d", "f", "g", "h", "k", "u1", "u2", "u3", "u4", "u5") }, // Interval with no overlapping reads, no unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 3000, 4000)), false, Collections.<String>emptyList() }, // Interval with no overlapping reads, with unmapped
    { unmappedBam, Arrays.asList(new SimpleInterval("1", 3000, 4000)), true, Arrays.asList("u1", "u2", "u3", "u4", "u5") }, // Interval with no overlapping reads, with unmapped, but no unmapped reads in bam
    { mappedBam, Arrays.asList(new SimpleInterval("1", 3000, 4000)), true, Collections.<String>emptyList() }, // Interval with overlapping reads, with unmapped, but no unmapped reads in bam
    { mappedBam, Arrays.asList(new SimpleInterval("1", 200, 1000)), true, Arrays.asList("a", "b", "c", "d") }, // Null intervals, with unmapped
    { unmappedBam, null, true, Arrays.asList("u1", "u2", "u3", "u4", "u5") }, // Empty intervals, with unmapped
    { unmappedBam, Collections.<SimpleInterval>emptyList(), true, Arrays.asList("u1", "u2", "u3", "u4", "u5") }, // Null intervals, with unmapped, but no unmapped reads in bam
    { mappedBam, null, true, Collections.<String>emptyList() }, // Empty intervals, with unmapped, but no unmapped reads in bam
    { mappedBam, Collections.<SimpleInterval>emptyList(), true, Collections.<String>emptyList() }, // Null intervals, no unmapped (an unbounded traversal, so we expect all the reads)
    { unmappedBam, null, false, Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "u1", "u2", "u3", "u4", "u5") }, // Empty intervals, no unmapped (an unbounded traversal, so we expect all the reads)
    { unmappedBam, Collections.<SimpleInterval>emptyList(), false, Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "u1", "u2", "u3", "u4", "u5") }, // Interval containing mapped read with unmapped mate, no unmapped
    { ceuSnippet, Arrays.asList(new SimpleInterval("20", 10000011, 10000013)), false, Arrays.asList("a", "b", "c", "d", "e", "f", "f") }, // Interval containing mapped read with unmapped mate, with unmapped
    { ceuSnippet, Arrays.asList(new SimpleInterval("20", 10000011, 10000013)), true, Arrays.asList("a", "b", "c", "d", "e", "f", "f", "g", "h", "h", "i", "i") }, // Interval not containing mapped read with unmapped mate, no unmapped
    { ceuSnippet, Arrays.asList(new SimpleInterval("20", 10000009, 10000011)), false, Arrays.asList("a", "b", "c", "d", "e") }, // Interval not containing mapped read with unmapped mate, with unmapped
    { ceuSnippet, Arrays.asList(new SimpleInterval("20", 10000009, 10000011)), true, Arrays.asList("a", "b", "c", "d", "e", "g", "h", "h", "i", "i") } };
}
Also used : Path(java.nio.file.Path) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) DataProvider(org.testng.annotations.DataProvider)

Example 54 with SimpleInterval

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

the class ReadsDataSourceUnitTest method testHandleUnindexedFileWithIntervals.

@Test(expectedExceptions = UserException.class)
public void testHandleUnindexedFileWithIntervals() {
    // Cannot initialize a reads source with intervals unless all files are indexed
    final Path unindexed = IOUtils.getPath(READS_DATA_SOURCE_TEST_DIRECTORY + "unindexed.bam");
    Assert.assertNull(SamFiles.findIndex(unindexed), "Expected file to have no index, but found an index file. " + unindexed.toAbsolutePath());
    ReadsDataSource readsSource = new ReadsDataSource(unindexed);
    readsSource.setTraversalBounds(Arrays.asList(new SimpleInterval("1", 1, 5)));
}
Also used : Path(java.nio.file.Path) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 55 with SimpleInterval

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

the class ReadsDataSourceUnitTest method testManuallySpecifiedIndicesWithCustomReaderFactoryAndNullWrappers.

@Test(dataProvider = "manuallySpecifiedIndexTestData")
public void testManuallySpecifiedIndicesWithCustomReaderFactoryAndNullWrappers(final List<Path> bams, final List<Path> indices) {
    final SamReaderFactory customFactory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT);
    // ReadsDataSource should not be using the wrapper since the files are not on the Google cloud.
    // So we pass this invalid wrapper: if the code tries to use it, it'll blow up.
    Function<SeekableByteChannel, SeekableByteChannel> nullWrapper = (SeekableByteChannel) -> null;
    try (final ReadsDataSource readsSource = new ReadsDataSource(bams, indices, customFactory, nullWrapper, nullWrapper)) {
        Assert.assertTrue(readsSource.indicesAvailable(), "Explicitly-provided indices not detected for bams: " + bams);
        final Iterator<GATKRead> queryReads = readsSource.query(new SimpleInterval("1", 1, 300));
        int queryCount = 0;
        while (queryReads.hasNext()) {
            ++queryCount;
            queryReads.next();
        }
        Assert.assertEquals(queryCount, 5, "Wrong number of reads returned in query");
    }
}
Also used : java.util(java.util) DataProvider(org.testng.annotations.DataProvider) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) XorWrapper(org.broadinstitute.hellbender.utils.test.XorWrapper) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Function(java.util.function.Function) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) ReadUtils(org.broadinstitute.hellbender.utils.read.ReadUtils) SeekableByteChannel(java.nio.channels.SeekableByteChannel) UserException(org.broadinstitute.hellbender.exceptions.UserException) Assert(org.testng.Assert) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) htsjdk.samtools(htsjdk.samtools) Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

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