-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdriver.cpp
336 lines (264 loc) · 9.47 KB
/
pdriver.cpp
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//////////////////////////////////////////////////////////////////
// //
// PLINK (c) 2005-2008 Shaun Purcell //
// //
// This file is distributed under the GNU General Public //
// License, Version 2. Please see the file COPYING for more //
// details //
// //
//////////////////////////////////////////////////////////////////
#include <iomanip>
#include "plink.h"
#include "options.h"
#include "helper.h"
#include "phase.h"
void Plink::proxyWrapper()
{
if (!par::SNP_major)
Ind2SNP();
if ( par::proxy_glm )
par::assoc_glm_without_main_snp = true;
/////////////////////////////////////////////////////
// Use 'pos' slot in Locus to store genotyping
// rate information, as we need access to this often
for (int l=0 ; l<nl_all; l++)
locus[l]->pos = genotypingRate(*this,l);
string f = par::output_file_name;
string f2 = par::output_file_name;
if ( par::proxy_impute )
{
f += ".proxy.impute";
f2 += ".proxy.impute.dosage";
}
else if ( par::proxy_error )
{
f += ".proxy.genocheck";
}
else if ( par::proxy_all && ! par::proxy_full_report )
{
if ( par::proxy_CC )
{
if ( par::qt )
f += ".qassoc.proxy";
else
f += ".assoc.proxy";
}
else
f += ".tdt.proxy";
}
else
f += ".proxy.report";
haplo->HTEST.open(f.c_str(),ios::out);
haplo->HTEST.precision(3);
if ( par::proxy_record_dosage )
{
OUTFILE.open(f2.c_str(),ios::out);
OUTFILE.precision(3);
}
printLOG("\n");
/* printLOG("Criteria for selecting proxy SNPs:\n");
printLOG(" Selecting at most " + int2str( par::proxy_snp_filter ) + " proxy SNPs (--proxy-maxsnp)\n");
printLOG(" Searching up to " + int2str( par::proxy_window ) + " SNPs around reference (--proxy-window)\n");
printLOG(" Searching within " + dbl2str(par::proxy_kb) +" kb around reference (--proxy-kb)\n");
printLOG(" Proxy genotype missingness threshold is "+dbl2str(par::proxy_geno)+" (--proxy-geno)\n");
printLOG(" Proxy MAF threshold is " + dbl2str(par::proxy_maf) +" (--proxy-maf)\n");
if ( par::proxy_r2_filter )
{
printLOG(" Proxy r-sq filters of "
+ dbl2str( par::proxy_r2_filter_A ) + ", "
+ dbl2str( par::proxy_r2_filter_B ) + ", "
+ dbl2str( par::proxy_r2_filter_C ) + " (--proxy-r2)\n");
}
else
{
printLOG(" No proxy r-sq filter selected (--proxy-no-r2-filter)\n");
}
*/
printLOG("Criteria for selecting proxy SNPs using frequency based metrics:\n");
printLOG("For SNPs with MAF above, then below " + dbl2str(par::proxy_planB_threshold) + ", \n");
printLOG(" Selecting at most " + int2str( par::proxy_snp_filter_planA ) + ","
+ int2str( par::proxy_snp_filter_planB )
+ " proxy SNPs (--proxy-maxsnp)\n");
printLOG(" Searching up to " + int2str( par::proxy_window_planA ) + ","
+ int2str( par::proxy_window_planB ) + ","
+ " SNPs around reference (--proxy-window)\n");
printLOG(" Searching within " + dbl2str(par::proxy_kb_planA) +","
+ dbl2str(par::proxy_kb_planB) +","
+" kb around reference (--proxy-kb)\n");
printLOG(" Proxy genotype missingness threshold is "+dbl2str(par::proxy_geno)+" (--proxy-geno)\n");
printLOG(" Proxy MAF threshold is " + dbl2str(par::proxy_maf) +" (--proxy-maf)\n");
printLOG(" Proxy r-sq filters of "
+ dbl2str( par::proxy_r2_filter_A_planA ) + ", "
+ dbl2str( par::proxy_r2_filter_B_planA ) + ", "
+ dbl2str( par::proxy_r2_filter_C_planA ) + " and "
+ dbl2str( par::proxy_r2_filter_A_planB ) + ", "
+ dbl2str( par::proxy_r2_filter_B_planB ) + ", "
+ dbl2str( par::proxy_r2_filter_C_planB )
+ " (--proxy-r2)\n");
if ( par::proxy_impute )
{
int reference_panel = 0;
for ( int i = 0 ; i < n ; i++ )
if ( sample[i]->missing )
reference_panel++;
if ( reference_panel == 0 )
error("No reference panel for imputation (i.e. individuals with missing phenotypes)\n");
printLOG("Imputation reference panel of "
+ int2str(reference_panel) + " individuals\n");
}
if ( ( ! par::proxy_impute ) && ( ( !par::proxy_all ) || par::proxy_full_report ) )
{
printLOG("Criteria for selecting proxy subhaplotypes:\n");
printLOG(" Haplotype frequency threshold " +dbl2str(par::proxy_mhf)+" (--proxy-mhf)\n");
printLOG(" r-squared threshold to reference " + dbl2str(par::proxy_r2) +" (--proxy-sub-r2)\n");
printLOG(" Maximum of " + int2str(par::proxy_maxhap) + " SNPs per subhaplotype (--proxy-sub-maxsnp)\n");
}
printLOG("\n");
printLOG("Writing haplotype-based proxy tests to [ " + f + " ] \n");
if ( par::proxy_record_dosage )
printLOG("Writing dosage imputation information to [ " + f2 + " ]\n");
// Either condsider all markers, with reduced output (i.e.
// just the haplotype based test for that SNP, or a single
// marker with extended outout
if ( par::proxy_all )
{
set<int> plocus;
if ( par::proxy_all_list )
{
// read list of SNPs to use as reference SNP
// for proxy
map<string,int> mlocus;
for (int l=0; l<nl_all; l++)
mlocus.insert(make_pair( locus[l]->name,l));
ifstream PLIST;
checkFileExists(par::proxy_all_list_file);
PLIST.open(par::proxy_all_list_file.c_str(), ios::in);
while ( ! PLIST.eof() )
{
string marker ;
PLIST >> marker;
map<string,int>::iterator mi = mlocus.find( marker );
if ( mi != mlocus.end() )
plocus.insert( mi->second );
}
PLIST.close();
}
// And we might want a full report for each?
// Turn off 'all' mode in that case to get
// verbose output
if ( par::proxy_full_report )
par::proxy_all = false;
else
{
if ( par::proxy_impute )
{
haplo->HTEST << setw(4) << "CHR" << " "
<< setw(par::pp_maxsnp) << "SNP" << " "
<< setw(4) << "NPRX" << " "
<< setw(8) << "INFO" << " "
<< setw(8) << "TOTAL_N" << " "
<< setw(8) << "OBSERVD" << " "
<< setw(8) << "IMPUTED" << " "
<< setw(8) << "OVERLAP" << " "
<< setw(8) << "CONCORD" << " ";
if ( par::proxy_impute_genotypic_concordance )
haplo->HTEST << setw(8) << "F_AA" << " "
<< setw(8) << "I_AA" << " "
<< setw(8) << "C_AA" << " "
<< setw(8) << "F_AB" << " "
<< setw(8) << "I_AB" << " "
<< setw(8) << "C_AB" << " "
<< setw(8) << "F_BB" << " "
<< setw(8) << "I_BB" << " "
<< setw(8) << "C_BB" << " ";
if ( par::proxy_list_proxies )
haplo->HTEST << "PROXIES";
haplo->HTEST << "\n";
}
else
{
//haplo->HTEST.setf(ios::scientific);
haplo->HTEST << setw(4) << "CHR" << " "
<< setw(par::pp_maxsnp) << "SNP" << " "
<< setw(12) << "BP" << " "
<< setw(4) << "A1" << " "
<< setw(4) << "A2" << " "
<< setw(10) << "GENO" << " "
<< setw(4) << "NPRX" << " "
<< setw(8) << "INFO" << " ";
if ( par::proxy_CC )
{
if ( par::qt || par::proxy_glm )
{
haplo->HTEST << setw(8) << "F" << " ";
if ( par::qt )
haplo->HTEST << setw(8) << "BETA" << " ";
else
haplo->HTEST << setw(8) << "ODDS" << " ";
}
else
haplo->HTEST << setw(8) << "F_A" << " "
<< setw(8) << "F_U" << " "
<< setw(8) << "OR" << " ";
}
else if ( par::proxy_TDT )
haplo->HTEST << setw(8) << "T" << " "
<< setw(8) << "U" << " "
<< setw(8) << "OR" << " ";
haplo->HTEST << setw(10) << "P" << " ";
if ( par::proxy_list_proxies )
haplo->HTEST << "PROXIES";
haplo->HTEST << "\n";
}
}
////////////////////////////////////////
// Set-up cache for LD values
proxyLD.clear();
////////////////////////////////////////
// Iterate over all SNPs specified
int similar = 0;
for ( int l = 0 ; l < nl_all ; l++ )
{
// cout << "testing " << locus[l]->name << "\n";
/////////////////////////
// Skip if not on list
if ( par::proxy_all_list )
if ( plocus.find(l) == plocus.end() )
continue;
/////////////////////////////////////////
// Have we already seen an identical SNP?
// (SKIP THIS PART FOR NOW -- DOESN'T
// PRACTICALLY ADD MUCH AT ALL)
// if ( l != 0 && identicalSNPs( this, l-1, l ) )
// {
// ++similar;
// continue;
// }
if ( ! par::silent )
{
cout << l+1 << " of " << nl_all << " performed \r";
cout.flush();
}
///////////////////////////////////
// Perform actual proxy-based test
performProxyTests(l);
// cout << "done!\n";
///////////////////////////////////
// Clear the LD cache occassionally
if ( proxyLD.size() > 50000 )
proxyLD.clear();
}
if ( ! par::silent )
cout << "\n";
}
else
{
int l = getMarkerNumber(*this,par::proxy_assoc_snp);
if ( l < 0 )
error("Cannot find proxy SNP [ " + par::proxy_assoc_snp + " ]\n");
performProxyTests(l);
}
haplo->HTEST.close();
if ( par::proxy_record_dosage )
OUTFILE.close();
}