File: QualityValueProfile.cpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,020 kB
  • sloc: cpp: 77,250; python: 331; sh: 103; makefile: 41
file content (44 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (4)
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
#include <alignment/qvs/QualityValueProfile.hpp>

QualityValueProfile::QualityValueProfile(int _wordSize, int _numQualityValues)
{
    wordSize = _wordSize;
    numQualityValues = _numQualityValues;
    // Initialize the tuple metrics to map from seq->index
    tm.Initialize(wordSize);
    nWords = 1 << (2 * wordSize);
    // Initialize the matrix of quality values.
    profile.Grow(nWords, numQualityValues);
    profile.Initialize(0);
}

void QualityValueProfile::Update(Nucleotide *seq, QualityValue qv)
{
    DNATuple tuple;
    if (tuple.FromStringLR(seq, tm)) {
        profile.Set(tuple.tuple, qv, profile(tuple.tuple, qv) + 1);
    }
}

void QualityValueProfile::Print(std::ofstream &out)
{
    out << wordSize << " " << numQualityValues << " " << CDF_GRANULARITY << std::endl;
    profile.Print(out);
}

void QualityValueProfile::ProfileToCDF()
{
    int qv;
    int wordIndex;
    for (wordIndex = 0; wordIndex < nWords; wordIndex++) {
        int totalSamples = 0;
        for (qv = 0; qv < numQualityValues; qv++) {
            totalSamples += profile(wordIndex, qv);
            profile.Set(wordIndex, qv, totalSamples);
        }
        for (qv = 0; qv < numQualityValues; qv++) {
            profile.Set(wordIndex, qv,
                        ((profile(wordIndex, qv) * 1.0) / totalSamples) * CDF_GRANULARITY);
        }
    }
}