Skip to content

Commit 4521d32

Browse files
fixes new qual regression in 4.0.5.0 (#4980)
1 parent b34b189 commit 4521d32

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/main/java/org/broadinstitute/hellbender/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public AFCalculationResult getLog10PNonRef(final VariantContext vc, final int de
101101
nonVariantIndicesByPloidy.computeIfAbsent(ploidy, p -> genotypeIndicesWithOnlyRefAndSpanDel(p, alleles));
102102
final int[] nonVariantIndices = nonVariantIndicesByPloidy.get(ploidy);
103103
final double[] nonVariantLog10Posteriors = MathUtils.applyToArray(nonVariantIndices, n -> log10GenotypePosteriors[n]);
104-
log10PNoVariant += MathUtils.log10SumLog10(nonVariantLog10Posteriors);
104+
// when the only alt allele is the spanning deletion the probability that the site is non-variant
105+
// may be so close to 1 that finite precision error in log10SumLog10 yields a positive value,
106+
// which is bogus. Thus we cap it at 0.
107+
log10PNoVariant += Math.min(0,MathUtils.log10SumLog10(nonVariantLog10Posteriors));
105108
}
106109

107110
// per allele non-log space probabilities of zero counts for this sample

src/test/java/org/broadinstitute/hellbender/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculatorUnitTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ public void testSpanningDeletionIsNotConsideredVariant() {
178178
final AlleleFrequencyCalculator afCalc = new AlleleFrequencyCalculator(1, 0.1, 0.1, ploidy);
179179
final List<Allele> alleles = Arrays.asList(A, B, Allele.SPAN_DEL);
180180

181-
//{AA}, {AB}, {BB}, {AC}, {BC}, {CC}
182-
183181
// some pls that have high likelihood for span del allele but not for the SNP (B)
184182
final int[] spanDelPls = new int[] {50, 100, 100, 0, 100, 100};
185183

@@ -246,6 +244,19 @@ public void testPresenceOfUnlikelySpanningDeletionDoesntAffectResults() {
246244
Assert.assertEquals(log10PVariantWithoutSpanDel, log10PVariantWithSpanDel, 0.0001);
247245
}
248246

247+
// test that a finite precision bug for span del sites with a very unlikely alt allele doesn't occur
248+
@Test
249+
public void testSpanningDeletionWithVeryUnlikelyAltAllele() {
250+
final int ploidy = 4;
251+
final AlleleFrequencyCalculator afCalc = new AlleleFrequencyCalculator(1, 0.1, 0.1, ploidy);
252+
final List<Allele> alleles = Arrays.asList(A, Allele.SPAN_DEL, B);
253+
254+
// make PLs that don't support the alt allele
255+
final List<int[]> pls = Arrays.asList(new int[] {0,10000,10000,10000,10000, 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000});
256+
final VariantContext vc = makeVC(alleles, pls.stream().map(pl -> makeGenotype(ploidy, pl)).collect(Collectors.toList()));
257+
final double log10PVariant = afCalc.getLog10PNonRef(vc).getLog10LikelihoodOfAFGT0();
258+
}
259+
249260
// make PLs that correspond to an obvious call i.e. one PL is relatively big and the rest are zero
250261
// alleleCounts is the GenotypeAlleleCounts format for the obvious genotype, with repeats but in no particular order
251262
private static int[] PLsForObviousCall(final int ploidy, final int numAlleles, final int[] alleleCounts, final int PL) {

0 commit comments

Comments
 (0)