6 #include "allele_functions.h" 8 void print_allele_depths(std::vector<allele> ad){
9 std::cout <<
"AD Size: " << ad.size() <<
" " << std::endl;
10 for(std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
11 std::cout <<
"Nuc: " << it->nuc << std::endl;;
12 std::cout <<
"Depth: " << it->depth << std::endl;
13 std::cout <<
"Reverse: " << it->reverse <<std::endl;
14 std::cout <<
"Qual: " << (uint16_t) it->mean_qual << std::endl;
15 std::cout <<
"Beg: " << it->beg << std::endl;
16 std::cout <<
"End: " << it->end << std::endl;
20 int check_allele_exists(std::string n, std::vector<allele> ad){
21 for(std::vector<allele>::iterator it = ad.begin(); it != ad.end(); ++it) {
22 if(it->nuc.compare(n) == 0){
23 return it - ad.begin();
29 int find_ref_in_allele(std::vector<allele> ad,
char ref){
30 std::string ref_s(1, ref);
31 std::vector<allele>::iterator it = ad.begin();
33 if(it->nuc.compare(ref_s) == 0)
34 return (it - ad.begin());
40 std::vector<allele> update_allele_depth(
char ref,std::string bases, std::string qualities, uint8_t min_qual){
41 std::vector<allele> ad;
43 int i = 0, n =0, j = 0, q_ind = 0;
46 float num = 0, den = 0;
47 while (i < bases.length()){
58 q = qualities[q_ind] - 33;
65 end = (bases[i+1] ==
'$');
66 beg = (bases[i+1] ==
'^');
71 end = (bases[i+1] ==
'$');
72 beg = (bases[i+1] ==
'^');
79 while(isdigit(bases[j])){
83 n = stoi(bases.substr(i+1, j));
84 indel = bases.substr(i+1+j, n);
85 transform(indel.begin(), indel.end(), indel.begin(),::toupper);
88 if(indel[0]>=97 && indel[0] <= 122)
93 int asc_val = bases[i];
94 if(asc_val >= 65 && asc_val <= 90){
96 }
else if(bases[i]>=97 && bases[i]<=122){
97 b = bases[i] - (
'a' -
'A');
100 end = (bases[i+1] ==
'$');
101 beg = (bases[i+1] ==
'^');
103 int ind = check_allele_exists(b, ad);
108 tmp.tmp_mean_qual = q;
123 ad.at(ind).tmp_mean_qual = (ad.at(ind).tmp_mean_qual * ad.at(ind).depth + q)/(ad.at(ind).depth + 1);
124 ad.at(ind).depth += 1;
130 ad.at(ind).reverse += 1;
134 if(b[0] !=
'+' && b[0]!=
'-')
137 for(std::vector<allele>::iterator it = ad.begin(); it!=ad.end(); ++it){
138 it->mean_qual = (uint8_t) it->tmp_mean_qual;
141 std::sort(ad.begin(), ad.end());
145 int get_index(
char a){
215 char gt2iupac(
char a,
char b){
216 if(a ==
'*' || b ==
'*')
218 static const char iupac[14][14] = {
219 {
'Y',
'N',
'H',
'B',
'B',
'H',
'H',
'Y',
'B',
'Y',
'N',
'N',
'H',
'B'},
220 {
'N',
'R',
'D',
'V',
'D',
'V',
'R',
'D',
'R',
'V',
'D',
'V',
'N',
'N'},
221 {
'H',
'D',
'W',
'N',
'D',
'H',
'W',
'W',
'D',
'H',
'D',
'N',
'H',
'N'},
222 {
'B',
'V',
'N',
'S',
'B',
'V',
'V',
'B',
'S',
'S',
'N',
'V',
'N',
'B'},
223 {
'B',
'D',
'D',
'B',
'K',
'N',
'D',
'K',
'K',
'B',
'D',
'N',
'N',
'B'},
224 {
'H',
'V',
'H',
'V',
'N',
'M',
'M',
'H',
'V',
'M',
'N',
'V',
'H',
'N'},
225 {
'H',
'R',
'W',
'V',
'D',
'M',
'A',
'W',
'R',
'M',
'D',
'V',
'H',
'N'},
226 {
'Y',
'D',
'W',
'B',
'K',
'H',
'W',
'T',
'K',
'Y',
'D',
'N',
'H',
'B'},
227 {
'B',
'R',
'D',
'S',
'K',
'V',
'R',
'K',
'G',
'S',
'D',
'V',
'N',
'B'},
228 {
'Y',
'V',
'H',
'S',
'B',
'M',
'M',
'Y',
'S',
'C',
'N',
'V',
'H',
'B'},
229 {
'N',
'D',
'D',
'N',
'D',
'N',
'D',
'D',
'D',
'N',
'D',
'N',
'N',
'N'},
230 {
'N',
'V',
'N',
'V',
'N',
'V',
'V',
'N',
'V',
'V',
'N',
'V',
'N',
'N'},
231 {
'H',
'N',
'H',
'N',
'N',
'H',
'H',
'H',
'N',
'H',
'N',
'N',
'H',
'N'},
232 {
'B',
'N',
'N',
'B',
'B',
'N',
'N',
'B',
'B',
'B',
'N',
'N',
'N',
'B'}
234 if ( a>=
'a' ) a -=
'a' -
'A';
235 if ( b>=
'a' ) b -=
'a' -
'A';
239 if(_a == -1 || _b == -1)
241 return iupac[_a][_b];