Skip to content

Commit

Permalink
[ADAM-1964] Lower point where phred conversions are done using log code.
Browse files Browse the repository at this point in the history
Resolves bigdatagenomics#1964. There was an underflow somewhere causing round trip from
log space values to Phred to mismatch for values between 164 and 254.
This change lowers the point where we switch from using the precomputed
table to where we use the log math. Also, we add a unit test checking
round trip values using PhredUtils.
  • Loading branch information
Frank Austin Nothaft committed Mar 23, 2018
1 parent dc3f4a5 commit 394f9f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object PhredUtils extends Serializable {
* @return The input phred score as a log success probability.
*/
def phredToLogProbability(phred: Int): Double = {
if (phred < 255) {
if (phred < 156) {
log(phredToSuccessProbability(phred)).toFloat
} else {
log1p(-exp(phred * MLOG10_DIV10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ class PhredUtilsSuite extends FunSuite {
val phred = PhredUtils.logProbabilityToPhred(-0.0)
assert(phred === 3233)
}

test("round trip log probabilities") {
def roundTrip(i: Int): Int = {
PhredUtils.logProbabilityToPhred(PhredUtils.phredToLogProbability(i))
}

(0 to 3228).foreach(i => {
assert(i === roundTrip(i))
})

// there is roundoff above 3228 due to floating point underflow
assert(3228 === roundTrip(3229))
assert(3230 === roundTrip(3230))
assert(3230 === roundTrip(3231))
assert(3233 === roundTrip(3232))
assert(3233 === roundTrip(3233))
}
}

0 comments on commit 394f9f6

Please sign in to comment.