Search in sources :

Example 31 with IndexRange

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

the class HashedListTargetCollectionUnitTest method testTargetFullRangeObject.

@Test(dependsOnMethods = { "testCorrectInitialization", "testCorrectRangeObjectInitialization" })
public void testTargetFullRangeObject() {
    final IndexRange range = new IndexRange(0, targetDB.targetCount());
    final List<SimpleInterval> targets = targetDB.targets(range);
    Assert.assertNotNull(targets);
    Assert.assertEquals(targets.size(), nonOverlappingTargetIntervals.size());
    for (int i = 0; i < targets.size(); i++) {
        Assert.assertEquals(targets.get(i), nonOverlappingTargetIntervals.get(i));
    }
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 32 with IndexRange

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

the class SomaticLikelihoodsEngineUnitTest method testEvidence.

@Test
public void testEvidence() {
    // one exact limit for the evidence is when the likelihoods of each read are so peaked (i.e. the most likely allele
    // of each read is much likelier than all other alleles) that the sum over latent read-to-allele assignments
    // (that is, over the indicator z in the notes) is dominated by the max-likelihood allele configuration
    // and thus the evidence reduces to exactly integrating out the Dirichlet allele fractions
    final double[] prior = new double[] { 1, 2 };
    final RealMatrix log10Likelihoods = new Array2DRowRealMatrix(2, 4);
    log10Likelihoods.setRow(0, new double[] { 0.1, 4.0, 3.0, -10 });
    log10Likelihoods.setRow(1, new double[] { -12, -9, -5.0, 0.5 });
    final double calculatedLog10Evidence = SomaticLikelihoodsEngine.log10Evidence(log10Likelihoods, prior);
    final double[] maxLikelihoodCounts = new double[] { 3, 1 };
    final double expectedLog10Evidence = SomaticLikelihoodsEngine.log10DirichletNormalization(prior) - SomaticLikelihoodsEngine.log10DirichletNormalization(MathArrays.ebeAdd(prior, maxLikelihoodCounts)) + new IndexRange(0, log10Likelihoods.getColumnDimension()).sum(read -> log10Likelihoods.getColumnVector(read).getMaxValue());
    Assert.assertEquals(calculatedLog10Evidence, expectedLog10Evidence, 1e-5);
    // when there's just one read we can calculate the likelihood exactly
    final double[] prior2 = new double[] { 1, 2 };
    final RealMatrix log10Likelihoods2 = new Array2DRowRealMatrix(2, 1);
    log10Likelihoods2.setRow(0, new double[] { 0.1 });
    log10Likelihoods2.setRow(1, new double[] { 0.5 });
    final double calculatedLog10Evidence2 = SomaticLikelihoodsEngine.log10Evidence(log10Likelihoods2, prior2);
    final double[] delta0 = new double[] { 1, 0 };
    final double[] delta1 = new double[] { 0, 1 };
    final double expectedLog10Evidence2 = MathUtils.log10SumLog10(log10Likelihoods2.getEntry(0, 0) + SomaticLikelihoodsEngine.log10DirichletNormalization(prior2) - SomaticLikelihoodsEngine.log10DirichletNormalization(MathArrays.ebeAdd(prior2, delta0)), +log10Likelihoods2.getEntry(1, 0) + SomaticLikelihoodsEngine.log10DirichletNormalization(prior2) - SomaticLikelihoodsEngine.log10DirichletNormalization(MathArrays.ebeAdd(prior2, delta1)));
    Assert.assertEquals(calculatedLog10Evidence2, expectedLog10Evidence2, 0.05);
}
Also used : BetaDistribution(org.apache.commons.math3.distribution.BetaDistribution) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) MathUtils(org.broadinstitute.hellbender.utils.MathUtils) Assert(org.testng.Assert) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) MathArrays(org.apache.commons.math3.util.MathArrays) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Test(org.testng.annotations.Test) Assert(org.junit.Assert) IndexRange(org.broadinstitute.hellbender.utils.IndexRange) IndexRange(org.broadinstitute.hellbender.utils.IndexRange) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

IndexRange (org.broadinstitute.hellbender.utils.IndexRange)32 Test (org.testng.annotations.Test)11 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)9 IntStream (java.util.stream.IntStream)7 Target (org.broadinstitute.hellbender.tools.exome.Target)7 CopyNumberTriState (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState)7 MathUtils (org.broadinstitute.hellbender.utils.MathUtils)7 Allele (htsjdk.variant.variantcontext.Allele)5 VariantContext (htsjdk.variant.variantcontext.VariantContext)5 Collectors (java.util.stream.Collectors)5 MathArrays (org.apache.commons.math3.util.MathArrays)5 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)5 Utils (org.broadinstitute.hellbender.utils.Utils)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 File (java.io.File)4 java.util (java.util)4 Genotype (htsjdk.variant.variantcontext.Genotype)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3