Search in sources :

Example 21 with CopyNumberTriState

use of org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState in project gatk 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);
    }
}
Also used : Target(org.broadinstitute.hellbender.tools.exome.Target) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) CopyNumberTriStateTransitionProbabilityCache(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriStateTransitionProbabilityCache) Test(org.testng.annotations.Test)

Example 22 with CopyNumberTriState

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

the class XHMMModelUnitTest method assertTransitionProbabilities.

// CopyNumberTriStateTransitionProbabilityCache is thoroughly tested.
// Here we simply test that it is invoked  properly
private void assertTransitionProbabilities(double eventStartProbability, double meanEventSize, XHMMModel model, Target fromTarget, Target toTarget) {
    final CopyNumberTriStateTransitionProbabilityCache logTransitionProbabilityCache = new CopyNumberTriStateTransitionProbabilityCache(meanEventSize, eventStartProbability);
    final double distance = XHMMModel.calculateDistance(fromTarget, toTarget);
    for (final CopyNumberTriState from : CopyNumberTriState.values()) {
        for (final CopyNumberTriState to : CopyNumberTriState.values()) {
            Assert.assertEquals(model.logTransitionProbability(from, fromTarget, to, toTarget), logTransitionProbabilityCache.logProbability((int) distance, to, from), EPSILON);
        }
    }
}
Also used : CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) CopyNumberTriStateTransitionProbabilityCache(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriStateTransitionProbabilityCache)

Example 23 with CopyNumberTriState

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

the class ConvertGSVariantsToSegmentsIntegrationTest method composeExpectedSegments.

private List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> composeExpectedSegments(final File vcf, final TargetCollection<Target> targets) throws IOException {
    final VCFFileReader reader = new VCFFileReader(vcf, false);
    final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> result = new ArrayList<>();
    reader.iterator().forEachRemaining(vc -> {
        final int targetCount = targets.indexRange(vc).size();
        for (final Genotype genotype : vc.getGenotypes()) {
            final int cn = Integer.parseInt(genotype.getExtendedAttribute("CN").toString());
            final double[] cnp = Stream.of(genotype.getExtendedAttribute("CNP").toString().replaceAll("\\[\\]", "").split(",")).mapToDouble(Double::parseDouble).toArray();
            final double cnpSum = MathUtils.approximateLog10SumLog10(cnp);
            final CopyNumberTriState call = expectedCall(cn);
            final double exactLog10Prob = expectedExactLog10(call, cnp);
            final HiddenStateSegment<CopyNumberTriState, Target> expectedSegment = new HiddenStateSegment<>(new SimpleInterval(vc), targetCount, Double.parseDouble(genotype.getExtendedAttribute("CNF").toString()), 0.000, call, -10.0 * exactLog10Prob, Double.NaN, Double.NaN, Double.NaN, -10.0 * (cnp[ConvertGSVariantsToSegments.NEUTRAL_COPY_NUMBER_DEFAULT] - cnpSum));
            result.add(new HiddenStateSegmentRecord<>(genotype.getSampleName(), expectedSegment));
        }
    });
    return result;
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) ArrayList(java.util.ArrayList) Genotype(htsjdk.variant.variantcontext.Genotype) Target(org.broadinstitute.hellbender.tools.exome.Target) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) HiddenStateSegment(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegment) HiddenStateSegmentRecord(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecord) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 24 with CopyNumberTriState

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

the class CopyNumberTriStateUnitTest method testAlleleListsLogic.

@Test
public void testAlleleListsLogic() {
    Assert.assertEquals(CopyNumberTriState.ALL_ALLELES.size(), CopyNumberTriState.values().length);
    Assert.assertEquals(CopyNumberTriState.ALL_ALLELES.subList(1, CopyNumberTriState.ALL_ALLELES.size()), CopyNumberTriState.ALTERNATIVE_ALLELES);
    Assert.assertFalse(CopyNumberTriState.ALTERNATIVE_ALLELES.stream().anyMatch(Allele::isReference));
    Assert.assertTrue(CopyNumberTriState.ALL_ALLELES.get(0).isReference());
    Assert.assertEquals(CopyNumberTriState.ALL_ALLELES.get(0), CopyNumberTriState.NEUTRAL.allele);
    final List<Allele> expectedOrder = new ArrayList<>();
    for (final CopyNumberTriState state : CopyNumberTriState.values()) {
        if (state == CopyNumberTriState.NEUTRAL) {
            continue;
        }
        expectedOrder.add(state.allele);
    }
    Assert.assertEquals(CopyNumberTriState.ALTERNATIVE_ALLELES, expectedOrder);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

CopyNumberTriState (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState)24 Target (org.broadinstitute.hellbender.tools.exome.Target)20 HiddenStateSegmentRecord (org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecord)10 Test (org.testng.annotations.Test)10 Genotype (htsjdk.variant.variantcontext.Genotype)8 IndexRange (org.broadinstitute.hellbender.utils.IndexRange)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)8 Allele (htsjdk.variant.variantcontext.Allele)6 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 VariantContext (htsjdk.variant.variantcontext.VariantContext)4 htsjdk.variant.vcf (htsjdk.variant.vcf)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)4 TargetArgumentCollection (org.broadinstitute.hellbender.tools.exome.TargetArgumentCollection)4 CopyNumberTriStateAllele (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriStateAllele)4 CopyNumberTriStateTransitionProbabilityCache (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriStateTransitionProbabilityCache)4