9 #include<htslib/kfunc.h> 10 #include "htslib/kfunc.h" 12 #include "allele_functions.h" 15 const float sig_level = 0.01;
17 std::vector<allele>::iterator get_ref_allele(std::vector<allele> &ad,
char ref){
18 for(std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
26 int call_variants_from_plup(std::istream &cin, std::string out_file, uint8_t min_qual,
double min_threshold){
27 std::string line, cell, bases, qualities, region;
28 std::ofstream fout(out_file+
".tsv");
29 fout <<
"REGION\tPOS\tREF\tALT\tAD\tRAD\tDP\tFREQ\tQUAL\tPVAL\tPASS"<<std::endl;
30 int ctr = 0, pos = 0, mdepth = 0;
31 double pval_left, pval_right, pval_twotailed, freq, err;
32 std::stringstream lineStream;
34 std::vector<allele> ad;
35 std::vector<allele>::iterator ref_it;
36 while (std::getline(cin, line)){
39 while(std::getline(lineStream,cell,
'\t')){
64 ad = update_allele_depth(ref, bases, qualities, min_qual);
69 ref_it = get_ref_allele(ad, ref);
72 for(std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
73 if(it->nuc[0]==
'*' || it->nuc[0] ==
'+' || it->nuc[0] ==
'-')
77 for(std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
78 if((*it == *ref_it) || it->nuc[0]==
'*')
80 freq = it->depth/(double)mdepth;
81 if(freq < min_threshold)
83 fout << region <<
"\t";
86 fout << it->nuc <<
"\t";
87 fout << it->depth <<
"\t";
88 fout << it->reverse <<
"\t";
89 fout << mdepth <<
"\t";
91 fout << (uint16_t)it->mean_qual <<
"\t";
97 err = pow(10, ( -1 * (it->mean_qual)/10));
98 kt_fisher_exact((err * mdepth), (1-err) * mdepth, it->depth, ref_it->depth, &pval_left, &pval_right, &pval_twotailed);
99 fout << pval_left <<
"\t";
100 if(pval_left <= sig_level){