use of org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState in project gatk-protected by broadinstitute.
the class XHMMSegmentCallerIntegrationTest method assertSampleSegmentsCoverAllTargets.
private void assertSampleSegmentsCoverAllTargets(final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> sampleRecords, final TargetCollection<Target> targets) {
int next = 0;
for (final HiddenStateSegmentRecord<CopyNumberTriState, Target> record : sampleRecords) {
final IndexRange range = targets.indexRange(record.getSegment());
Assert.assertEquals(range.from, next);
next = range.to;
}
}
use of org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState in project gatk-protected by broadinstitute.
the class XHMMSegmentGenotyperIntegrationTest method assertVariantSegmentsAreCovered.
private void assertVariantSegmentsAreCovered(final List<VariantContext> variants, final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> variantSegments) {
for (final HiddenStateSegmentRecord<CopyNumberTriState, Target> variantSegment : variantSegments) {
final Optional<VariantContext> match = variants.stream().filter(vc -> new SimpleInterval(vc).equals(variantSegment.getSegment().getInterval())).findFirst();
Assert.assertTrue(match.isPresent());
final VariantContext matchedVariant = match.get();
final Genotype genotype = matchedVariant.getGenotype(variantSegment.getSampleName());
final String discovery = genotype.getAnyAttribute(XHMMSegmentGenotyper.DISCOVERY_KEY).toString();
Assert.assertTrue(discovery.equals(XHMMSegmentGenotyper.DISCOVERY_TRUE));
final CopyNumberTriState call = variantSegment.getSegment().getCall();
final List<Allele> gt = genotype.getAlleles();
Assert.assertEquals(gt.size(), 1);
// The call may not be the same for case where the event-quality is relatively low.
if (variantSegment.getSegment().getEventQuality() > 10) {
Assert.assertEquals(CopyNumberTriStateAllele.valueOf(gt.get(0)).state, call, genotype.toString());
}
final String[] SQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.SOME_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double someQual = variantSegment.getSegment().getSomeQuality();
Assert.assertEquals(Double.parseDouble(SQ[call == CopyNumberTriState.DELETION ? 0 : 1]), someQual, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
final String[] LQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.START_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double startQuality = variantSegment.getSegment().getStartQuality();
Assert.assertEquals(Double.parseDouble(LQ[call == CopyNumberTriState.DELETION ? 0 : 1]), startQuality, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
final String[] RQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.END_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double endQuality = variantSegment.getSegment().getEndQuality();
Assert.assertEquals(Double.parseDouble(RQ[call == CopyNumberTriState.DELETION ? 0 : 1]), endQuality, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
// Check the PL.
final int[] PL = genotype.getPL();
final int observedGQFromPL = Math.min(XHMMSegmentGenotyper.MAX_GQ, PL[CopyNumberTriStateAllele.REF.index()] - PL[CopyNumberTriStateAllele.valueOf(call).index()]);
final double expectedCallPL = GATKProtectedMathUtils.roundPhred(QualityUtils.phredScaleErrorRate(QualityUtils.qualToProb(variantSegment.getSegment().getExactQuality())), HMMPostProcessor.PHRED_SCORE_PRECISION);
final double expectedRefPL = GATKProtectedMathUtils.roundPhred(QualityUtils.phredScaleCorrectRate(QualityUtils.qualToProb(variantSegment.getSegment().getEventQuality())), HMMPostProcessor.PHRED_SCORE_PRECISION);
final int expectedGQFromPL = Math.min(XHMMSegmentGenotyper.MAX_GQ, (int) Math.round(expectedRefPL - expectedCallPL));
Assert.assertTrue(Math.abs(observedGQFromPL - expectedGQFromPL) <= 1, genotype.toString() + " " + variantSegment.getSegment().getEventQuality());
}
}
use of org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState 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.germlinehmm.CopyNumberTriState 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.germlinehmm.CopyNumberTriState in project gatk by broadinstitute.
the class XHMMSegmentGenotyperIntegrationTest method assertVariantSegmentsAreCovered.
private void assertVariantSegmentsAreCovered(final List<VariantContext> variants, final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> variantSegments) {
for (final HiddenStateSegmentRecord<CopyNumberTriState, Target> variantSegment : variantSegments) {
final Optional<VariantContext> match = variants.stream().filter(vc -> new SimpleInterval(vc).equals(variantSegment.getSegment().getInterval())).findFirst();
Assert.assertTrue(match.isPresent());
final VariantContext matchedVariant = match.get();
final Genotype genotype = matchedVariant.getGenotype(variantSegment.getSampleName());
final String discovery = genotype.getAnyAttribute(XHMMSegmentGenotyper.DISCOVERY_KEY).toString();
Assert.assertTrue(discovery.equals(XHMMSegmentGenotyper.DISCOVERY_TRUE));
final CopyNumberTriState call = variantSegment.getSegment().getCall();
final List<Allele> gt = genotype.getAlleles();
Assert.assertEquals(gt.size(), 1);
// The call may not be the same for case where the event-quality is relatively low.
if (variantSegment.getSegment().getEventQuality() > 10) {
Assert.assertEquals(CopyNumberTriStateAllele.valueOf(gt.get(0)).state, call, genotype.toString());
}
final String[] SQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.SOME_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double someQual = variantSegment.getSegment().getSomeQuality();
Assert.assertEquals(Double.parseDouble(SQ[call == CopyNumberTriState.DELETION ? 0 : 1]), someQual, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
final String[] LQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.START_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double startQuality = variantSegment.getSegment().getStartQuality();
Assert.assertEquals(Double.parseDouble(LQ[call == CopyNumberTriState.DELETION ? 0 : 1]), startQuality, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
final String[] RQ = genotype.getAnyAttribute(XHMMSegmentGenotyper.END_QUALITY_KEY).toString().split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR);
final double endQuality = variantSegment.getSegment().getEndQuality();
Assert.assertEquals(Double.parseDouble(RQ[call == CopyNumberTriState.DELETION ? 0 : 1]), endQuality, XHMMSegmentGenotyper.PHRED_SCORE_PRECISION, variantSegment.getSampleName() + " => " + genotype.toString());
// Check the PL.
final int[] PL = genotype.getPL();
final int observedGQFromPL = Math.min(XHMMSegmentGenotyper.MAX_GQ, PL[CopyNumberTriStateAllele.REF.index()] - PL[CopyNumberTriStateAllele.valueOf(call).index()]);
final double expectedCallPL = GATKProtectedMathUtils.roundPhred(QualityUtils.phredScaleErrorRate(QualityUtils.qualToProb(variantSegment.getSegment().getExactQuality())), HMMPostProcessor.PHRED_SCORE_PRECISION);
final double expectedRefPL = GATKProtectedMathUtils.roundPhred(QualityUtils.phredScaleCorrectRate(QualityUtils.qualToProb(variantSegment.getSegment().getEventQuality())), HMMPostProcessor.PHRED_SCORE_PRECISION);
final int expectedGQFromPL = Math.min(XHMMSegmentGenotyper.MAX_GQ, (int) Math.round(expectedRefPL - expectedCallPL));
Assert.assertTrue(Math.abs(observedGQFromPL - expectedGQFromPL) <= 1, genotype.toString() + " " + variantSegment.getSegment().getEventQuality());
}
}
Aggregations