-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.h
253 lines (200 loc) · 6.4 KB
/
tests.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef GAURD_TESTS
#define GAURD_TESTS
std::ostream& den_writer(const double P,const EM_data& EM_data_O,const vcf_line_cols& O,const each_line_data& ELDO,std::ostream& out){
out.precision(20);
const std::vector<std::string>& split_line(ELDO.split_line);
const size_t INFO_col(O.INFO_col);
for(size_t i(0);i<split_line.size()-1;++i){
out<<split_line[i];
if(i!=INFO_col){
out<<"\t";
continue;
}
out<<";P_denovo="<<P<<";rho="<<EM_data_O.rho_new<<";GF="<<EM_data_O.prior_new<<";ExAC_AF_computed="<<ELDO.INFO_data_obj.CSQ_data_obj.ExAC_AF;
out<<";MDC="<<ELDO.INFO_data_obj.CSQ_data_obj.MDQ;
out<<";MDC_rank="<<ELDO.INFO_data_obj.CSQ_data_obj.MDQ_rank;
out<<";CSQ_gene="<<ELDO.INFO_data_obj.CSQ_data_obj.gene;
out<<"\t";
}
out<<split_line[split_line.size()-1];
return out;
}
class calls_record{
public:
static std::list<std::string> all_records;
static size_t INFO_col;
static void updater(const double P,const EM_data& EM_data_O,const vcf_line_cols& O,const each_line_data& ELDO);
static bool compare_individual_records(const std::string&,const std::string&);
static void sort_record();
static void writer(std::ostream& out);
};
void calls_record::writer(std::ostream& out){
using namespace std;
list<string>::const_iterator I( all_records.begin() );
for(;I!=all_records.end();++I)
out<<(*I)<<"\n";
}
size_t calls_record::INFO_col=0;
std::list<std::string> calls_record::all_records(0);
void calls_record::sort_record(){
using namespace std;
all_records.sort(compare_individual_records);
}
bool calls_record::compare_individual_records(const std::string& line1,const std::string& line2){
using namespace std;
vector<string> split_line,split_INFO;
string INFO;
double P1,P2;
split_line=split(line1);
INFO=split_line[INFO_col];
split_INFO=split(INFO,';');
for(size_t I(0);I<split_INFO.size();++I){
const string element(split_INFO[I]);
if( element.size()>9 ){
const string temp( element.begin(),element.begin()+9 );
if(temp=="P_denovo="){
const string val( element.begin()+9,element.end() );
P1=atof( val.c_str() );
}
}
}
split_line=split(line2);
INFO=split_line[INFO_col];
split_INFO=split(INFO,';');
for(size_t I(0);I<split_INFO.size();++I){
const string element(split_INFO[I]);
if( element.size()>9 ){
const string temp( element.begin(),element.begin()+9 );
if(temp=="P_denovo="){
const string val( element.begin()+9,element.end() );
P2=atof( val.c_str() );
}
}
}
return P1>P2;
}
void calls_record::updater(const double P,const EM_data& EM_data_O,const vcf_line_cols& O,const each_line_data& ELDO){
using namespace std;
const std::vector<std::string>& split_line(ELDO.split_line);
INFO_col=O.INFO_col;
string temp;
for(size_t i(0);i<split_line.size()-1;++i){
temp+=split_line[i];
if(i!=INFO_col){
temp+="\t";
continue;
}
ostringstream OS_P;
OS_P.precision(30);
OS_P<<P;
temp+= ";P_denovo="+OS_P.str();
ostringstream OS_rho;
OS_rho.precision(30);
OS_rho<<EM_data_O.rho_new;
temp+= ";rho="+OS_rho.str();
ostringstream OS_GF;
OS_GF.precision(30);
OS_GF<<EM_data_O.prior_new;
temp+= ";GF="+OS_GF.str();
ostringstream OS_EAC;
OS_EAC.precision(30);
OS_EAC<<ELDO.INFO_data_obj.CSQ_data_obj.ExAC_AF;
temp+= ";ExAC_AF_computed="+OS_EAC.str();
ostringstream OS_MDC;
OS_MDC.precision(30);
OS_MDC<<ELDO.INFO_data_obj.CSQ_data_obj.MDQ;
temp+= ";MDC="+OS_MDC.str();
ostringstream OS_MDC_rank;
OS_MDC_rank.precision(30);
OS_MDC_rank<<ELDO.INFO_data_obj.CSQ_data_obj.MDQ_rank;
temp+= ";MDC_rank="+OS_MDC_rank.str();
ostringstream OS_CSQ_gene;
OS_CSQ_gene.precision(30);
OS_CSQ_gene<<ELDO.INFO_data_obj.CSQ_data_obj.gene;
temp+= ";CSQ_gene="+OS_CSQ_gene.str();
temp+="\t";
}
temp+=split_line[split_line.size()-1];
all_records.push_back(temp);
}
void denovo_worker(std::istream& fin,const std::string& trio_ID_filename,std::ostream& fout,const std::string& X_choice,const double PP_thresh,const double ExAC_thresh){
using namespace std;
string line;
getline(fin,line);
while(! vcf_line_cols::CSQ_line_checker(line) )
getline(fin,line);
const string CSQ_line(line);
while(line[0]=='#' && line[1]=='#')
getline(fin,line);
const string header_line(line);
vcf_line_cols O(header_line,trio_ID_filename,CSQ_line);
O.tables_memory_obj.set_table(1,1e-8);
cout<<O;
size_t DD(0);
size_t upper_limit;
if(X_choice=="1")
upper_limit=23;
else
upper_limit=22;
getline(fin,line);
each_line_data ELDO(line,O);
EM_data EM_data_obj(0.8,ELDO.combos);
const double& ExAC_AF(ELDO.INFO_data_obj.CSQ_data_obj.ExAC_AF);
const int& MDQ_rank(ELDO.INFO_data_obj.CSQ_data_obj.MDQ_rank);
if(ELDO.LOC.chrom>=1 && ELDO.LOC.chrom<=upper_limit && ExAC_AF<ExAC_thresh && MDQ_rank>=17){
EM_data_obj.EM_full(ELDO.AD_list,O.parent_cols,O.GT_likelihood_wrt_allele_L_table[0],1);
ELDO.GL_L_list_updater(EM_data_obj.rho_new,O);
double PP( ELDO.denovo_BGM(O,EM_data_obj.prior_L_new) );
if(PP>PP_thresh){
calls_record::updater(PP,EM_data_obj,O,ELDO);
++DD;
}
}
size_t count(0);
getline(fin,line);
while(line.size()>0){
++count;
if(count%1000000==0){
cout<<count<<" ";
cout.flush();
}
ELDO.mem_set(line,O);
EM_data EM_data_obj(0.8,ELDO.combos);
const double& ExAC_AF(ELDO.INFO_data_obj.CSQ_data_obj.ExAC_AF);
const int& MDQ_rank(ELDO.INFO_data_obj.CSQ_data_obj.MDQ_rank);
if(ELDO.LOC.chrom>=1 && ELDO.LOC.chrom<=upper_limit && ExAC_AF<ExAC_thresh && MDQ_rank>=17){
EM_data_obj.EM_full(ELDO.AD_list,O.parent_cols,O.GT_likelihood_wrt_allele_L_table[0],1);
ELDO.GL_L_list_updater(EM_data_obj.rho_new,O);
double PP( ELDO.denovo_BGM(O,EM_data_obj.prior_L_new) );
if(PP>PP_thresh){
calls_record::updater(PP,EM_data_obj,O,ELDO);
++DD;
}
}
getline(fin,line);
}
cout<<"\n";
cout<<"count="<<count<<"\n";
calls_record::sort_record();
calls_record::writer(fout);
}
void tester_1(){
using namespace std;
const string filename("/net/data/bgm/cases/bgm0058_wes/analysis/upstream/bgm0058_final.vep.vcf");
const string trio_id_filename("trio_ID_bgm0058.txt");
ifstream fin(filename.c_str());
string line;
getline(fin,line);
while(! vcf_line_cols::CSQ_line_checker(line) )
getline(fin,line);
const string CSQ_line(line);
while(line[0]=='#' && line[1]=='#')
getline(fin,line);
const string header_line(line);
vcf_line_cols O(header_line,trio_id_filename,CSQ_line);
getline(fin,line);
each_line_data ELDO(line,O);
cout<<O;
cout<<ELDO;
}
#endif