diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculator.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculator.java index febdebb9c..abfddab82 100644 --- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculator.java +++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AlleleFrequencyCalculator.java @@ -159,8 +159,15 @@ public final class AlleleFrequencyCalculator extends AFCalculator { pOfNonZeroAltAlleles[alleleIndex] += genotypePosterior); } + // Make sure that we handle appropriately pOfNonZeroAltAlleles that are close to 1; values just over 1.0 due to + // rounding error would result in NaN. + // As every allele is present in at least one genotype, the p-non-zero-count for + // any allele is bound above by 1.0 - minimum genotype posterior because at least one genotype + // does not contain this allele. + final double maximumPNonZeroCount = 1.0 - MathUtils.arrayMin(genotypePosteriors); + for (int allele = 0; allele < numAlleles; allele++) { - log10POfZeroCountsByAllele[allele] += Math.log10(1 - pOfNonZeroAltAlleles[allele]); + log10POfZeroCountsByAllele[allele] += Math.log10(1.0 - Math.min(maximumPNonZeroCount, pOfNonZeroAltAlleles[allele])); } } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java index 98b806f40..47e813204 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java @@ -681,4 +681,13 @@ public class GenotypeGVCFsIntegrationTest extends WalkerTest { spec.disableShadowBCF(); executeTest("testGenotypingSpanningDeletionAcrossLines", spec); } + + @Test + public void testNewQualNaNBugFix() { + final WalkerTestSpec spec = new WalkerTestSpec( + baseTestString(" -newQual -V " + privateTestDir + "input-newqual-nan-bug-fix.vcf", b37KGReferenceWithDecoy), + Collections.singletonList("503f4193c22fbcc451bd1c425b8b6bf8")); + spec.disableShadowBCF(); + executeTest("testNewQualNaNBugFix", spec); + } } \ No newline at end of file