@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"); }
/** 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 testTrueProbWithMinDouble() { final byte actual = QualityUtils.trueProbToQual(Double.MIN_VALUE); Assert.assertEquals(actual, 1, "Failed to convert true prob of min double to 1 qual"); }