File: BlasrQualityValue.cpp

package info (click to toggle)
pbseqlib 5.3.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,020 kB
  • sloc: cpp: 77,246; python: 331; sh: 103; makefile: 42
file content (65 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <pbdata/defs.h>
#include <pbdata/PrettyException.hpp>
#include <pbdata/qvs/QualityValue.hpp>

#include <cassert>
#include <cmath>

QualityValue ProbabilityToQualityValue(QualityProbability pErr, QVScale qvScale)
{
    if (qvScale == POverOneMinusP) {
        QualityProbability pe;
        QualityProbability maxReportedErrorProb = 0.499;
        pe = MIN(pErr, maxReportedErrorProb);
        return MIN(255, -100 * log10(pe / (1 - pe)));
    } else if (qvScale == PHRED) {
        return -10 * log10(pErr);
    } else {
        BLASR_THROW("Unknown qvScale!");
    }
}

QualityValue PacBioQVToPhred(QualityValue pbQV)
{
    // yanked from Aaron's code.
    return (unsigned char)floor(10.0 * log10(1.0 + pow(10.0, pbQV / 100.0)) + 0.5);
}

QualityValue ToPhred(QualityValue qv, QVScale qvScale)
{
    //
    // Nothing to do when the quality is already in phred.
    //
    if (qvScale == PHRED) {
        return qv;
    } else {
        return PacBioQVToPhred(qv);
    }
}

QualityProbability QualityValueToProbability(QualityValue qv, QVScale qvScale)
{
    if (qvScale == POverOneMinusP) {
        QualityProbability pp;
        pp = pow(10, qv / -100.0);
        return pp / (1 + pp);
    } else if (qvScale == PHRED) {
        return pow(10, qv / -10.0);
    } else {
        BLASR_THROW("Unknown qvScale!");
    }
}

QVScale DetermineQVScaleFromChangeListID(ChangeListID &cl)
{
    ChangeListID phredCL;
    phredCL.intVer.resize(3);
    phredCL.intVer[0] = 1;
    phredCL.intVer[1] = 2;
    phredCL.intVer[2] = 2;
    if (cl.LessThan(phredCL)) {
        return POverOneMinusP;
    } else {
        return PHRED;
    }
}