Search in sources :

Example 16 with SimpleInterval

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

the class TargetCollectionUnitTest method testForEachExhaustiveRanges.

@Test(dataProvider = "targetDBData")
public void testForEachExhaustiveRanges(final TargetCollection<SimpleInterval> targetCollection) {
    final int min = 0;
    final int max = targetCollection.targetCount();
    for (int i = min; i < max; i++) {
        final SimpleInterval iInterval = targetCollection.target(i);
        final String contig = iInterval.getContig();
        final int start = (iInterval.getStart() + iInterval.getEnd()) >> 1;
        for (int j = i; j < max; j++) {
            final SimpleInterval jInterval = targetCollection.target(j);
            if (!jInterval.getContig().equals(contig)) {
                break;
            }
            final int end = (jInterval.getStart() + jInterval.getEnd() + 1) >> 1;
            if (start > end) {
                continue;
            }
            final SimpleInterval loc = TargetsToolsTestUtils.createInterval(contig, start, end);
            final List<SimpleInterval> visited = new ArrayList<>(j - i + 1);
            final int iFinal = i;
            targetCollection.forEachTarget(loc, (idx, e) -> {
                Assert.assertEquals(idx, iFinal + visited.size());
                Assert.assertEquals(e, targetCollection.target(idx));
                visited.add(e);
            });
            Assert.assertEquals(visited.size(), j - i + 1);
        }
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 17 with SimpleInterval

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

the class TargetCollectionUnitTest method testForEachSingleCallExactMatch.

@Test(dataProvider = "targetDBData")
public void testForEachSingleCallExactMatch(final TargetCollection<SimpleInterval> targetCollection) {
    for (int i = 0; i < targetCollection.targetCount(); i++) {
        final SimpleInterval simpleInterval = targetCollection.target(i);
        final SimpleInterval loc = TargetsToolsTestUtils.createInterval(simpleInterval.getContig(), simpleInterval.getStart(), simpleInterval.getEnd());
        final int expectedIdx = i;
        final int[] totalCalls = new int[] { 0 };
        targetCollection.forEachTarget(loc, (idx, target) -> {
            Assert.assertEquals(target, simpleInterval);
            Assert.assertEquals(idx, expectedIdx);
            totalCalls[0]++;
        });
        Assert.assertEquals(totalCalls[0], 1);
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 18 with SimpleInterval

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

the class TargetCollectionUnitTest method testTargetsByLocationExhaustiveZeroRanges.

@Test(dataProvider = "targetDBData")
public void testTargetsByLocationExhaustiveZeroRanges(final TargetCollection<SimpleInterval> targetCollection) {
    final int min = 0;
    final int max = targetCollection.targetCount();
    for (int i = min; i < max - 1; i++) {
        final SimpleInterval iInterval = targetCollection.target(i);
        final SimpleInterval jInterval = targetCollection.target(i + 1);
        if (!jInterval.getContig().equals(iInterval.getContig()))
            continue;
        final int start = iInterval.getEnd() + 1;
        final int end = jInterval.getStart() - 1;
        if (start < end)
            continue;
        final List<SimpleInterval> observed = targetCollection.targets(TargetsToolsTestUtils.createInterval(iInterval.getContig(), start, end));
        Assert.assertEquals(observed.size(), 0);
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 19 with SimpleInterval

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

the class TargetUnitTest method testGetEndWithInterval.

@Test()
public void testGetEndWithInterval() {
    final Target subject = new Target("my-name", new SimpleInterval("1", 1, 2));
    Assert.assertEquals(subject.getEnd(), 2);
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Test(org.testng.annotations.Test)

Example 20 with SimpleInterval

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

the class TargetUnitTest method testConstructorWithInterval.

@Test()
public void testConstructorWithInterval() {
    final Target subject1 = new Target("my-name", null);
    Assert.assertEquals(subject1.getName(), "my-name");
    Assert.assertNull(subject1.getInterval());
    final Target subject2 = new Target("my-name", new SimpleInterval("1", 1, 2));
    Assert.assertEquals(subject2.getName(), "my-name");
    Assert.assertEquals(subject2.getInterval(), new SimpleInterval("1", 1, 2));
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) 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