diff --git a/avocado-core/src/main/scala/org/bdgenomics/avocado/util/LogPhred.scala b/avocado-core/src/main/scala/org/bdgenomics/avocado/util/LogPhred.scala index cbad1819..b4651d83 100644 --- a/avocado-core/src/main/scala/org/bdgenomics/avocado/util/LogPhred.scala +++ b/avocado-core/src/main/scala/org/bdgenomics/avocado/util/LogPhred.scala @@ -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. * diff --git a/avocado-core/src/test/scala/org/bdgenomics/avocado/util/LogPhredSuite.scala b/avocado-core/src/test/scala/org/bdgenomics/avocado/util/LogPhredSuite.scala new file mode 100644 index 00000000..c2f1cf72 --- /dev/null +++ b/avocado-core/src/test/scala/org/bdgenomics/avocado/util/LogPhredSuite.scala @@ -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) + } +}