Returns the phred-scaled error probability of no errors given a set of independent error sources - Java java.lang

Java examples for java.lang:Math Function

Description

Returns the phred-scaled error probability of no errors given a set of independent error sources

Demo Code


//package com.java2s;

public class Main {
    /**//ww  w.java2  s. c o  m
     * Returns the phred-scaled error probability of no
     * errors given a set of independent error sources
     * @param score phred-scaled error probabilities of each error source
     * @return
     */
    public static double phredOr(double... phredScore) {
        assert (phredScore.length > 0);
        double resultPhred = phredScore[0];
        // -10 * log10(1 - (1 - 10^(-a/10)) * (1 - 10^(-b/10)))
        // = -10 * log10(10^(-a/10)+10^(-b/10)-10^((-a-b)/10))
        for (int i = 1; i < phredScore.length; i++) {
            resultPhred = prToPhred(phredToPr(resultPhred)
                    + phredToPr(phredScore[i])
                    - phredToPr(resultPhred + phredScore[i]));
        }
        return resultPhred;
    }

    public static double prToPhred(double pr) {
        if (pr == 0)
            return 0;
        return -10 * Math.log10(pr);
    }

    public static double phredToPr(double phred) {
        return Math.pow(10, -phred / 10);
    }
}

Related Tutorials