Search in sources :

Example 6 with ACNVModeledSegment

use of org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment in project gatk by broadinstitute.

the class AllelicSplitCallerModelStateUnitTest method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    final ACNVModeledSegment acnvModeledSegment = new ACNVModeledSegment(new SimpleInterval("1", 1000, 1500), new PosteriorSummary(-4000, -4001, -4002), new PosteriorSummary(-4000, -4001, -4002));
    final List<ACNVModeledSegment> tempList = new ArrayList<>();
    tempList.add(acnvModeledSegment);
    final AllelicBalanceCallerModelState state = AllelicBalanceCallerModelState.createInitialCNLOHCallerModelState(0.2, tempList, HomoSapiensConstants.DEFAULT_PLOIDY, CNLOHCaller.NUM_RHOS);
    SparkTestUtils.roundTripInKryo(state, AllelicBalanceCallerModelState.class, SparkContextFactory.getTestSparkContext().getConf());
}
Also used : PosteriorSummary(org.broadinstitute.hellbender.utils.mcmc.PosteriorSummary) ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with ACNVModeledSegment

use of org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment in project gatk by broadinstitute.

the class AllelicSplitCallerUnitTest method testMakeCalls.

@Test
public void testMakeCalls() {
    // This mostly just checks that the calling does not crash and does produce results.
    final CNLOHCaller cnlohCaller = new CNLOHCaller();
    final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
    final List<ACNVModeledSegment> segs = SegmentUtils.readACNVModeledSegmentFile(ACNV_SEG_FILE);
    SparkTestUtils.roundTripInKryo(segs.get(0), ACNVModeledSegment.class, ctx.getConf());
    // Make sure the CNLOH Caller is serializable before making calls.
    SparkTestUtils.roundTripInKryo(cnlohCaller, CNLOHCaller.class, ctx.getConf());
    final List<AllelicCalls> calls = cnlohCaller.makeCalls(segs, 2, ctx);
    Assert.assertNotNull(calls);
    Assert.assertTrue(calls.size() > 0);
    Assert.assertTrue(calls.stream().allMatch(c -> c.getBalancedCall() != null));
    Assert.assertTrue(calls.stream().allMatch(c -> c.getCnlohCall() != null));
    Assert.assertTrue(calls.stream().allMatch(c -> c.getAcnvSegment() != null));
    // Make sure the CNLOH Caller is serializable after making calls.
    SparkTestUtils.roundTripInKryo(cnlohCaller, CNLOHCaller.class, ctx.getConf());
    SparkTestUtils.roundTripInKryo(calls.get(0), AllelicCalls.class, ctx.getConf());
}
Also used : Arrays(java.util.Arrays) Pair(org.apache.commons.math3.util.Pair) DataProvider(org.testng.annotations.DataProvider) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Test(org.testng.annotations.Test) SegmentUtils(org.broadinstitute.hellbender.tools.exome.SegmentUtils) File(java.io.File) List(java.util.List) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) Assert(org.testng.Assert) SparkContextFactory(org.broadinstitute.hellbender.engine.spark.SparkContextFactory) HomoSapiensConstants(org.broadinstitute.hellbender.utils.variant.HomoSapiensConstants) SparkTestUtils(org.broadinstitute.hellbender.utils.test.SparkTestUtils) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with ACNVModeledSegment

use of org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment in project gatk-protected by broadinstitute.

the class AllelicSplitCallerModelStateUnitTest method testBasicInit.

@Test
public void testBasicInit() {
    final ACNVModeledSegment acnvModeledSegment = new ACNVModeledSegment(new SimpleInterval("1", 1000, 1500), new PosteriorSummary(-4000, -4001, -4002), new PosteriorSummary(-4000, -4001, -4002));
    final List<ACNVModeledSegment> tempList = new ArrayList<>();
    tempList.add(acnvModeledSegment);
    final AllelicBalanceCallerModelState state = AllelicBalanceCallerModelState.createInitialCNLOHCallerModelState(0.2, tempList, HomoSapiensConstants.DEFAULT_PLOIDY, CNLOHCaller.NUM_RHOS);
    Assert.assertNotNull(state);
    Assert.assertNotNull(state.getEffectivePis());
    Assert.assertTrue(state.getEffectivePis().length > 0);
    Assert.assertTrue(state.getmVals().length > 0);
    Assert.assertTrue(state.getnVals().length > 0);
    Assert.assertEquals(MathUtils.sum(state.getEffectivePis()), 1.0, 1e-10);
}
Also used : PosteriorSummary(org.broadinstitute.hellbender.utils.mcmc.PosteriorSummary) ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 9 with ACNVModeledSegment

use of org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment in project gatk-protected by broadinstitute.

the class AllelicSplitCallerUnitTest method testMakeCalls.

@Test
public void testMakeCalls() {
    // This mostly just checks that the calling does not crash and does produce results.
    final CNLOHCaller cnlohCaller = new CNLOHCaller();
    final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
    final List<ACNVModeledSegment> segs = SegmentUtils.readACNVModeledSegmentFile(ACNV_SEG_FILE);
    SparkTestUtils.roundTripInKryo(segs.get(0), ACNVModeledSegment.class, ctx.getConf());
    // Make sure the CNLOH Caller is serializable before making calls.
    SparkTestUtils.roundTripInKryo(cnlohCaller, CNLOHCaller.class, ctx.getConf());
    final List<AllelicCalls> calls = cnlohCaller.makeCalls(segs, 2, ctx);
    Assert.assertNotNull(calls);
    Assert.assertTrue(calls.size() > 0);
    Assert.assertTrue(calls.stream().allMatch(c -> c.getBalancedCall() != null));
    Assert.assertTrue(calls.stream().allMatch(c -> c.getCnlohCall() != null));
    Assert.assertTrue(calls.stream().allMatch(c -> c.getAcnvSegment() != null));
    // Make sure the CNLOH Caller is serializable after making calls.
    SparkTestUtils.roundTripInKryo(cnlohCaller, CNLOHCaller.class, ctx.getConf());
    SparkTestUtils.roundTripInKryo(calls.get(0), AllelicCalls.class, ctx.getConf());
}
Also used : Arrays(java.util.Arrays) Pair(org.apache.commons.math3.util.Pair) DataProvider(org.testng.annotations.DataProvider) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Test(org.testng.annotations.Test) SegmentUtils(org.broadinstitute.hellbender.tools.exome.SegmentUtils) File(java.io.File) List(java.util.List) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) Assert(org.testng.Assert) SparkContextFactory(org.broadinstitute.hellbender.engine.spark.SparkContextFactory) HomoSapiensConstants(org.broadinstitute.hellbender.utils.variant.HomoSapiensConstants) SparkTestUtils(org.broadinstitute.hellbender.utils.test.SparkTestUtils) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 10 with ACNVModeledSegment

use of org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment in project gatk by broadinstitute.

the class CNLOHCaller method calcNewRhos.

private double[] calcNewRhos(final List<ACNVModeledSegment> segments, final List<double[][][]> responsibilitiesBySeg, final double lambda, final double[] rhos, final int[] mVals, final int[] nVals, final JavaSparkContext ctx) {
    // Since, we pass in the entire responsibilities matrix, we need the correct index for each rho.  That, and the
    //  fact that this is a univariate objective function, means we need to create an instance for each rho.  And
    //  then we blast across Spark.
    final List<Pair<? extends Function<Double, Double>, SearchInterval>> objectives = IntStream.range(0, rhos.length).mapToObj(i -> new Pair<>(new Function<Double, Double>() {

        @Override
        public Double apply(Double rho) {
            return calculateESmnObjective(rho, segments, responsibilitiesBySeg, mVals, nVals, lambda, i);
        }
    }, new SearchInterval(0.0, 1.0, rhos[i]))).collect(Collectors.toList());
    final JavaRDD<Pair<? extends Function<Double, Double>, SearchInterval>> objectivesRDD = ctx.parallelize(objectives);
    final List<Double> resultsAsDouble = objectivesRDD.map(objective -> optimizeIt(objective.getFirst(), objective.getSecond())).collect();
    return resultsAsDouble.stream().mapToDouble(Double::doubleValue).toArray();
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) RealVector(org.apache.commons.math3.linear.RealVector) Function(java.util.function.Function) ParamUtils(org.broadinstitute.hellbender.utils.param.ParamUtils) GammaDistribution(org.apache.commons.math3.distribution.GammaDistribution) Gamma(org.apache.commons.math3.special.Gamma) ACNVModeledSegment(org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment) BaseAbstractUnivariateIntegrator(org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator) GoalType(org.apache.commons.math3.optim.nonlinear.scalar.GoalType) MatrixUtils(org.apache.commons.math3.linear.MatrixUtils) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector) SimpsonIntegrator(org.apache.commons.math3.analysis.integration.SimpsonIntegrator) JavaRDD(org.apache.spark.api.java.JavaRDD) GATKProtectedMathUtils(org.broadinstitute.hellbender.utils.GATKProtectedMathUtils) Pair(org.apache.commons.math3.util.Pair) Collectors(java.util.stream.Collectors) BrentOptimizer(org.apache.commons.math3.optim.univariate.BrentOptimizer) Serializable(java.io.Serializable) List(java.util.List) Percentile(org.apache.commons.math3.stat.descriptive.rank.Percentile) Logger(org.apache.logging.log4j.Logger) MathUtils(org.broadinstitute.hellbender.utils.MathUtils) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) Variance(org.apache.commons.math3.stat.descriptive.moment.Variance) Utils(org.broadinstitute.hellbender.utils.Utils) RealMatrix(org.apache.commons.math3.linear.RealMatrix) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HomoSapiensConstants(org.broadinstitute.hellbender.utils.variant.HomoSapiensConstants) MaxEval(org.apache.commons.math3.optim.MaxEval) LogManager(org.apache.logging.log4j.LogManager) Function(java.util.function.Function) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) Pair(org.apache.commons.math3.util.Pair)

Aggregations

ACNVModeledSegment (org.broadinstitute.hellbender.tools.exome.ACNVModeledSegment)16 Test (org.testng.annotations.Test)10 List (java.util.List)8 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)8 File (java.io.File)6 Arrays (java.util.Arrays)6 Collectors (java.util.stream.Collectors)6 Pair (org.apache.commons.math3.util.Pair)6 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)6 HomoSapiensConstants (org.broadinstitute.hellbender.utils.variant.HomoSapiensConstants)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Serializable (java.io.Serializable)4 Function (java.util.function.Function)4 IntStream (java.util.stream.IntStream)4 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)4 BaseAbstractUnivariateIntegrator (org.apache.commons.math3.analysis.integration.BaseAbstractUnivariateIntegrator)4 SimpsonIntegrator (org.apache.commons.math3.analysis.integration.SimpsonIntegrator)4 GammaDistribution (org.apache.commons.math3.distribution.GammaDistribution)4 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)4 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)4