Skip to content

Commit

Permalink
[AVOCADO-215] Improve test coverage for org.bdgenomics.avocado.util.L…
Browse files Browse the repository at this point in the history
…ogPhred.

Resolves bigdatagenomics#215. Adds test suite and removes unused success probability method.
  • Loading branch information
fnothaft committed Mar 1, 2017
1 parent 110e21a commit de2522d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ object LogPhred {

private val LOG10 = mathLog(10.0)

/**
* Conversion between log _success_ probabilities and Phred scores.
*
* Q = -10 log_{10} (1 - p)
*
* If l = ln p, then:
*
* l_e = ln 1 + ln (1 - exp(l_e / 1))
* = ln(1 - exp(l_e))
* Q = -10 l_e / ln 10
*
* @note Just remember kids: if you want to live a happy, fulfilling life, don't use Phred!
* @note We don't have a conversion the other way around because it doesn't really make sense.
*
* @param l Log probability.
* @return Returns the Phred score corresponding to that log probability.
*/
def logSuccessToPhred(l: Double): Double = {
(-10.0 * mathLog(-expm1(l)) / LOG10)
}

/**
* Conversion between log _error_ probabilities and Phred scores.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Licensed to Big Data Genomics (BDG) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The BDG licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bdgenomics.avocado.util

import org.scalatest.FunSuite
import scala.math.log

class LogPhredSuite extends FunSuite {

test("convert log error probabilities to phred scores") {
val phred10 = LogPhred.logErrorToPhred(log(0.1))
assert(phred10 > 9.999 && phred10 < 10.001)
val phred50 = LogPhred.logErrorToPhred(log(0.00001))
assert(phred50 > 49.999 && phred50 < 50.001)
}
}

0 comments on commit de2522d

Please sign in to comment.