-
Notifications
You must be signed in to change notification settings - Fork 5
/
SampleBasicStatsCollector.h
55 lines (40 loc) · 1.86 KB
/
SampleBasicStatsCollector.h
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
#ifndef SAMPLEBASICSTATSCOLLECTOR_H
#define SAMPLEBASICSTATSCOLLECTOR_H
#pragma once
#include "BasicStatsCollector.h"
#include <set>
namespace VcfStatsAlive {
class SampleBasicStatsCollector : public BasicStatsCollector {
public:
SampleBasicStatsCollector(int qualLower, int qualUpper, bool logScaleAF):
BasicStatsCollector(qualLower, qualUpper, logScaleAF) {}
virtual void processVariantImpl(bcf_hdr_t* hdr, bcf1_t* var) override {
// increment total variant counter
++_stats[kTotalRecords];
int32_t ngt, *gt_arr=nullptr, ngt_arr=0;
ngt = bcf_get_genotypes(hdr, var, >_arr, &ngt_arr);
if (ngt <= 0) return; // no genotype info present
bool isSnp = bcf_is_snp(var);
int refLength = strlen(var->d.allele[0]);
std::set<int> processedGenotypes;
int observedAltLen = 0;
for(int altIndex = 0; altIndex < ngt_arr; altIndex++) {
int gt = (gt_arr[altIndex] >> 1) - 1;
if(gt <= 0) continue; // either missing or reference
// skip already processed genotype
if(processedGenotypes.find(gt) != processedGenotypes.end())
continue;
int altLen = strlen(var->d.allele[gt]);
updateTsTvRatio(var, gt, isSnp);
updateMutationSpectrum(var, gt, isSnp);
if(observedAltLen != altLen) updateVariantTypeDist(var, gt, refLength);
processedGenotypes.insert(gt);
observedAltLen = altLen;
}
updateAlleleFreqHist(hdr, var);
updateQualityDist(var->qual);
free(gt_arr);
}
};
};
#endif