File: QualityValueProfile.cpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (41 lines) | stat: -rw-r--r-- 1,327 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
#include "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);
        }
    }
}