@Test(dataProvider = "PhredScaleDoubleOps") public void testPhredScaleDoubleOps(final double errorRate, final double expectedPhredScaled) { final double actualError = QualityUtils.phredScaleErrorRate(errorRate); Assert.assertEquals(actualError, expectedPhredScaled, TOLERANCE); final double trueRate = 1 - errorRate; final double actualTrue = QualityUtils.phredScaleCorrectRate(trueRate); if (trueRate == 1.0) { Assert.assertEquals(actualTrue, QualityUtils.MIN_PHRED_SCALED_QUAL); } else { final double tol = errorRate < 1e-10 ? 10.0 : 1e-3; Assert.assertEquals(actualTrue, expectedPhredScaled, tol); } }
@Test() public void testBoundingDefault() { for (int qual = 0; qual < 1000; qual++) { final byte expected = (byte) Math.max(Math.min(qual, QualityUtils.MAX_SAM_QUAL_SCORE), 1); Assert.assertEquals(QualityUtils.boundQual(qual), expected); } }
private VariantCallContext estimateReferenceConfidence( VariantContext vc, Map<String, AlignmentContext> contexts, double theta, boolean ignoreCoveredSamples, double initialPofRef) { if (contexts == null) return null; double P_of_ref = initialPofRef; // for each sample that we haven't examined yet for (String sample : samples) { boolean isCovered = contexts.containsKey(sample); if (ignoreCoveredSamples && isCovered) continue; int depth = 0; if (isCovered) { depth = contexts.get(sample).getBasePileup().depthOfCoverage(); } P_of_ref *= 1.0 - (theta / 2.0) * getRefBinomialProb(depth); } return new VariantCallContext( vc, QualityUtils.phredScaleErrorRate(1.0 - P_of_ref) >= UAC.STANDARD_CONFIDENCE_FOR_CALLING, false); }
@Test public void testTrueProbWithVerySmallValue() { final byte actual = QualityUtils.trueProbToQual(1.7857786272673852E-19); Assert.assertEquals( actual, 1, "Failed to convert true prob of very small value 1.7857786272673852E-19 to 1 qual"); }
@Test() public void testQualToErrorProbDouble() { for (double qual = 3.0; qual < 255.0; qual += 0.1) { final double expected = Math.pow(10.0, qual / -10.0); Assert.assertEquals( QualityUtils.qualToErrorProb(qual), expected, TOLERANCE, "failed qual->error prob for double qual " + qual); } }
@Test() public void testBoundingWithMax() { for (int max = 10; max < 255; max += 50) { for (int qual = 0; qual < 1000; qual++) { final int expected = Math.max(Math.min(qual, max), 1); Assert.assertEquals( QualityUtils.boundQual(qual, (byte) (max & 0xFF)) & 0xFF, expected & 0xFF, "qual " + qual + " max " + max); } } }
/** Example testng test using MyDataProvider */ @Test(dataProvider = "QualTest") public void testMyData(final byte qual, final double errorRate) { final double trueRate = 1 - errorRate; final double actualErrorRate = QualityUtils.qualToErrorProb(qual); Assert.assertEquals(actualErrorRate, errorRate, TOLERANCE); final double actualTrueRate = QualityUtils.qualToProb(qual); Assert.assertEquals(actualTrueRate, trueRate, TOLERANCE); // log10 tests final double actualLog10ErrorRate = QualityUtils.qualToErrorProbLog10(qual); Assert.assertEquals(actualLog10ErrorRate, Math.log10(errorRate), TOLERANCE); final double actualLog10TrueRate = QualityUtils.qualToProbLog10(qual); Assert.assertEquals(actualLog10TrueRate, Math.log10(trueRate), TOLERANCE); // test that we can convert our error rates to quals, accounting for boundaries final int expectedQual = Math.max(Math.min(qual & 0xFF, QualityUtils.MAX_SAM_QUAL_SCORE), 1); final byte actualQual = QualityUtils.trueProbToQual(trueRate); Assert.assertEquals(actualQual, expectedQual & 0xFF); final byte actualQualFromErrorRate = QualityUtils.errorProbToQual(errorRate); Assert.assertEquals(actualQualFromErrorRate, expectedQual & 0xFF); for (int maxQual = 10; maxQual < QualityUtils.MAX_SAM_QUAL_SCORE; maxQual++) { final byte maxAsByte = (byte) (maxQual & 0xFF); final byte expectedQual2 = (byte) (Math.max(Math.min(qual & 0xFF, maxQual), 1) & 0xFF); final byte actualQual2 = QualityUtils.trueProbToQual(trueRate, maxAsByte); Assert.assertEquals(actualQual2, expectedQual2, "Failed with max " + maxQual); final byte actualQualFromErrorRate2 = QualityUtils.errorProbToQual(errorRate, maxAsByte); Assert.assertEquals(actualQualFromErrorRate2, expectedQual2, "Failed with max " + maxQual); // test the integer routines final byte actualQualInt2 = QualityUtils.trueProbToQual(trueRate, maxQual); Assert.assertEquals(actualQualInt2, expectedQual2, "Failed with max " + maxQual); final byte actualQualFromErrorRateInt2 = QualityUtils.errorProbToQual(errorRate, maxQual); Assert.assertEquals(actualQualFromErrorRateInt2, expectedQual2, "Failed with max " + maxQual); } }
@Test public void testQualCaches() { Assert.assertEquals(QualityUtils.qualToErrorProb((byte) 20), 0.01, 1e-6); Assert.assertEquals(QualityUtils.qualToErrorProbLog10((byte) 20), -2.0, 1e-6); Assert.assertEquals(QualityUtils.qualToProb((byte) 20), 0.99, 1e-6); Assert.assertEquals(QualityUtils.qualToProbLog10((byte) 20), -0.0043648054, 1e-6); Assert.assertEquals(QualityUtils.qualToErrorProb((byte) 30), 0.001, 1e-6); Assert.assertEquals(QualityUtils.qualToErrorProbLog10((byte) 30), -3.0, 1e-6); Assert.assertEquals(QualityUtils.qualToProb((byte) 30), 0.999, 1e-6); Assert.assertEquals(QualityUtils.qualToProbLog10((byte) 30), -0.000434511774, 1e-6); Assert.assertEquals(QualityUtils.qualToErrorProb((byte) 40), 0.0001, 1e-6); Assert.assertEquals(QualityUtils.qualToErrorProbLog10((byte) 40), -4.0, 1e-6); Assert.assertEquals(QualityUtils.qualToProb((byte) 40), 0.9999, 1e-6); Assert.assertEquals(QualityUtils.qualToProbLog10((byte) 40), -4.34316198e-5, 1e-6); }
@Test public void testTrueProbWithMinDouble() { final byte actual = QualityUtils.trueProbToQual(Double.MIN_VALUE); Assert.assertEquals(actual, 1, "Failed to convert true prob of min double to 1 qual"); }
protected boolean confidentlyCalled(double conf, double PofF) { return conf >= UAC.STANDARD_CONFIDENCE_FOR_CALLING || (UAC.GenotypingMode == GenotypeLikelihoodsCalculationModel.GENOTYPING_MODE.GENOTYPE_GIVEN_ALLELES && QualityUtils.phredScaleErrorRate(PofF) >= UAC.STANDARD_CONFIDENCE_FOR_CALLING); }