Debian Codegraph @

src/NonCall.cpp

raw
1 #include "NonCall.h"
2
3 NonCall NonCalls::aggregateAll(void) {
4 NonCall aggregate;
5 bool first = true;
6 for (NonCalls::const_iterator nc = this->begin(); nc != this->end(); ++nc) {
7 for (map<long, map<string, NonCall> >::const_iterator p
8 = nc->second.begin(); p != nc->second.end(); ++p) {
9 for (map<string, NonCall>::const_iterator s = p->second.begin();
10 s != p->second.end(); ++s) {
11 const NonCall& nonCall = s->second;
12 aggregate.refCount += nonCall.refCount;
13 aggregate.altCount += nonCall.altCount;
14 aggregate.reflnQ += nonCall.reflnQ;
15 aggregate.altlnQ += nonCall.altlnQ;
16 aggregate.nCount += 1;
17 if (first) {
18 aggregate.minDepth = nonCall.refCount + nonCall.altCount;
19 first = false;
20 } else {
21 aggregate.minDepth = min(aggregate.minDepth,
22 nonCall.refCount + nonCall.altCount);
23 }
24 }
25 }
26 }
27 return aggregate;
28 }
29
30 void NonCalls::aggregatePerSample(map<string, NonCall>& perSample) {
31 set<string> seen;
32 for (NonCalls::const_iterator nc = this->begin(); nc != this->end(); ++nc) {
33 for (map<long, map<string, NonCall> >::const_iterator p = nc->second.begin();
34 p != nc->second.end(); ++p) {
35 for (map<string, NonCall>::const_iterator s = p->second.begin();
36 s != p->second.end(); ++s) {
37 const string& name = s->first;
38 const NonCall& nonCall = s->second;
39 NonCall& aggregate = perSample[name];
40 aggregate.refCount += nonCall.refCount;
41 aggregate.altCount += nonCall.altCount;
42 aggregate.reflnQ += nonCall.reflnQ;
43 aggregate.altlnQ += nonCall.altlnQ;
44 aggregate.nCount += 1;
45 if (!seen.count(name)) {
46 aggregate.minDepth = nonCall.refCount + nonCall.altCount;
47 seen.insert(name);
48 } else {
49 aggregate.minDepth = min(aggregate.minDepth, nonCall.refCount + nonCall.altCount);
50 }
51 }
52 }
53 }
54 }
55
56 void NonCalls::record(const string& seqName, long pos, const Samples& samples) {
57 map<string, NonCall>& site = (*this)[seqName][pos];
58 for (Samples::const_iterator s = samples.begin(); s != samples.end(); ++s) {
59 // tally ref and non-ref alleles
60 const string& name = s->first;
61 const Sample& sample = s->second;
62 NonCall& noncall = site[name];
63 for (Sample::const_iterator a = sample.begin(); a != sample.end(); ++a) {
64 const vector<Allele*>& alleles = a->second;
65 for (vector<Allele*>::const_iterator o = alleles.begin(); o != alleles.end(); ++o) {
66 Allele& allele = **o;
67 if (allele.isReference()) {
68 ++noncall.refCount;
69 noncall.reflnQ += allele.lnquality;
70 } else {
71 ++noncall.altCount;
72 noncall.altlnQ += allele.lnquality;
73 }
74 }
75 }
76 }
77 }
78
79 pair<string, long> NonCalls::firstPos(void) {
80 const string& startChrom = begin()->first;
81 long startPos = begin()->second.begin()->first;
82 return make_pair(startChrom, startPos);
83 }
84
85 pair<string, long> NonCalls::lastPos(void) {
86 const string& endChrom = rbegin()->first;
87 long endPos = rbegin()->second.rbegin()->first;
88 return make_pair(endChrom, endPos);
89 }