use of org.broadinstitute.hellbender.tools.exome.Target in project gatk-protected by broadinstitute.
the class XHMMSegmentGenotyperIntegrationTest method assertVariantsAreCoveredBySegments.
private void assertVariantsAreCoveredBySegments(final List<VariantContext> variants, final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> variantSegments) {
for (final VariantContext variant : variants) {
final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> matches = variantSegments.stream().filter(s -> new SimpleInterval(variant).equals(s.getSegment().getInterval())).collect(Collectors.toList());
Assert.assertFalse(matches.isEmpty());
for (final Genotype genotype : variant.getGenotypes()) {
final boolean discovery = genotype.getExtendedAttribute(XHMMSegmentGenotyper.DISCOVERY_KEY).toString().equals(XHMMSegmentGenotyper.DISCOVERY_TRUE);
if (discovery) {
Assert.assertTrue(matches.stream().anyMatch(s -> s.getSampleName().equals(genotype.getSampleName())));
} else {
Assert.assertTrue(matches.stream().noneMatch(s -> s.getSampleName().equals(genotype.getSampleName())));
}
}
}
}
use of org.broadinstitute.hellbender.tools.exome.Target in project gatk-protected by broadinstitute.
the class XHMMModelUnitTest method testLogPrior.
//the prior should be the infinite distance limit of the transition matrix
@Test(dataProvider = "testData", dependsOnMethods = "testInstantiation")
public void testLogPrior(final double eventStartProbability, final double meanEventSize, final double deletionMean, final double duplicationMean) {
final XHMMModel model = new XHMMModel(eventStartProbability, meanEventSize, deletionMean, duplicationMean);
final Target target = new Target("NAME");
final CopyNumberTriStateTransitionProbabilityCache logTransitionProbabilityCache = new CopyNumberTriStateTransitionProbabilityCache(meanEventSize, eventStartProbability);
for (final CopyNumberTriState state : CopyNumberTriState.values()) {
Assert.assertEquals(model.logPriorProbability(state, target), logTransitionProbabilityCache.logProbability(Integer.MAX_VALUE, state, CopyNumberTriState.NEUTRAL), 1e-10);
}
}
use of org.broadinstitute.hellbender.tools.exome.Target in project gatk-protected by broadinstitute.
the class XHMMModelUnitTest method testLogEmissionProbability.
@Test(dataProvider = "testData", dependsOnMethods = "testInstantiation")
public void testLogEmissionProbability(final double eventStartProbability, final double meanEventSize, final double deletionMean, final double duplicationMean) {
final XHMMModel model = new XHMMModel(eventStartProbability, meanEventSize, deletionMean, duplicationMean);
final Target target = new Target("NAME");
final double logDenominator = Math.log(Math.sqrt(2 * Math.PI));
final Function<Double, Double> neutralEmission = x -> -.5 * (x * x) - logDenominator;
final Function<Double, Double> deletionEmission = x -> -.5 * Math.pow(x - deletionMean, 2) - logDenominator;
final Function<Double, Double> duplicationEmission = x -> -.5 * Math.pow(x - duplicationMean, 2) - logDenominator;
for (final double coverage : TEST_COVERAGE_VALUES) {
final double neutralObserved = model.logEmissionProbability(new XHMMEmissionData(coverage), CopyNumberTriState.NEUTRAL, target);
final double deletionObserved = model.logEmissionProbability(new XHMMEmissionData(coverage), CopyNumberTriState.DELETION, target);
final double duplicationObserved = model.logEmissionProbability(new XHMMEmissionData(coverage), CopyNumberTriState.DUPLICATION, target);
final double neutralExpected = neutralEmission.apply(coverage);
final double deletionExpected = deletionEmission.apply(coverage);
final double duplicationExpected = duplicationEmission.apply(coverage);
Assert.assertEquals(neutralObserved, neutralExpected, "neutral emission for " + coverage);
Assert.assertEquals(deletionObserved, deletionExpected);
Assert.assertEquals(duplicationObserved, duplicationExpected);
}
}
use of org.broadinstitute.hellbender.tools.exome.Target in project gatk-protected by broadinstitute.
the class XHMMModelUnitTest method testDistance.
@Test(dependsOnMethods = "testInstantiation")
public void testDistance() {
final XHMMModel model = new XHMMModel(0.5, 10, -1, 1);
// different chromosomes
Assert.assertEquals(XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 1, 100)), new Target("target2", new SimpleInterval("2", 1, 100))), Double.POSITIVE_INFINITY);
// commutativity
Assert.assertEquals(XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 1, 100)), new Target("target2", new SimpleInterval("1", 200, 300))), XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 200, 300)), new Target("target2", new SimpleInterval("1", 1, 100))));
Assert.assertEquals(XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 100, 200)), new Target("target2", new SimpleInterval("1", 200, 300))), 100, EPSILON);
Assert.assertEquals(XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 100, 200)), new Target("target2", new SimpleInterval("1", 100, 110))), 45, EPSILON);
Assert.assertEquals(XHMMModel.calculateDistance(new Target("target1", new SimpleInterval("1", 100, 200)), new Target("target2", new SimpleInterval("1", 150, 250))), 50, EPSILON);
}
use of org.broadinstitute.hellbender.tools.exome.Target in project gatk-protected by broadinstitute.
the class XHMMModelUnitTest method testLogTransitionProbabilityWithNoDistance.
@Test(dataProvider = "testData", dependsOnMethods = "testInstantiation", expectedExceptions = IllegalArgumentException.class)
public void testLogTransitionProbabilityWithNoDistance(final double eventStartProbability, final double meanEventSize, final double deletionMean, final double duplicationMean) {
final XHMMModel model = new XHMMModel(eventStartProbability, meanEventSize, deletionMean, duplicationMean);
final Target fromTarget = new Target("target1");
final Target toTarget = new Target("target2");
assertTransitionProbabilities(eventStartProbability, meanEventSize, model, fromTarget, toTarget);
}
Aggregations