-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
310 lines (214 loc) · 6.45 KB
/
main.cc
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
#include "controller.h"
#include <stdlib.h>
int main(int argc, char **argv){
char grid_file[128];
char data_file[128];
char zval_file[128];
char est_file[128];
char ld_file[128];
char out_file[128];
char log_file[128];
char gene_name[64];
char prior_file[128];
memset(gene_name,0,64);
memset(grid_file,0,128);
memset(out_file,0,128);
memset(log_file,0,128);
memset(data_file,0,128);
memset(ld_file,0,128);
memset(zval_file,0,128);
memset(est_file,0,128);
memset(prior_file,0,128);
int ld_format = 1; // for correlation matrix
double abf_option = -1;
int msize =-1;
int output_all = 0;
double pes = 1.0;
double pi1 = -1;
// double lambda = 0.5;
double ld_control = -1;
int size_limit = -1;
int sample_size = -1;
double syy = -1;
double snp_select_thresh = -1;
double size_select_thresh = -1;
// alternative non-fm running options
int run_scan = 0;
int extract_ss = 0;
int thread = 5;
for(int i=1;i<argc;i++){
// required data files and additional info
if(strcmp(argv[i], "-g")==0 || strcmp(argv[i], "-grid")==0){
strcpy(grid_file,argv[++i]);
continue;
}
if(strcmp(argv[i], "-d")==0 || strcmp(argv[i], "-data")==0){
strcpy(data_file,argv[++i]);
continue;
}
if(strcmp(argv[i], "-d_z")==0 || strcmp(argv[i], "-d_zval")==0 || strcmp(argv[i], "-data_zval")==0){
strcpy(zval_file,argv[++i]);
continue;
}
if(strcmp(argv[i], "-d_ld")==0 || strcmp(argv[i], "-data_ld")==0){
strcpy(ld_file,argv[++i]);
continue;
}
if(strcmp(argv[i], "-d_ld2")==0 || strcmp(argv[i], "-data_ld")==0){
strcpy(ld_file,argv[++i]);
ld_format = 2;
continue;
}
if(strcmp(argv[i], "-d_est")==0){
strcpy(est_file,argv[++i]);
continue;
}
if(strcmp(argv[i], "-d_n")==0){
sample_size = atoi(argv[++i]);
continue;
}
if(strcmp(argv[i], "-d_syy")==0){
syy = atof(argv[++i]);
continue;
}
// prior file
if(strcmp(argv[i], "-prior")==0 || strcmp(argv[i], "-p")==0 ){
strcpy(prior_file,argv[++i]);
continue;
}
// output file
if(strcmp(argv[i], "-o")==0 || strcmp(argv[i], "-output")==0){
strcpy(out_file, argv[++i]);
continue;
}
if(strcmp(argv[i], "-l")==0 || strcmp(argv[i], "-logfile")==0){
strcpy(log_file, argv[++i]);
continue;
}
// prior options
if(strcmp(argv[i], "-ens")==0 ){
pes = atof(argv[++i]);
continue;
}
if(strcmp(argv[i], "-pi1")==0){
pi1 = atof(argv[++i]);
continue;
}
if(strcmp(argv[i],"-abf")==0){
abf_option = atof(argv[++i]);
continue;
}
// thresholds
if(strcmp(argv[i],"-converg_thresh")==0){
size_select_thresh = atof(argv[++i]);
continue;
}
if(strcmp(argv[i],"-size_limit")==0){
size_limit = atoi(argv[++i]);
continue;
}
if(strcmp(argv[i],"--no_size_limit")==0){
size_limit = -1;
continue;
}
if(strcmp(argv[i],"-ld_control")==0){
ld_control = atof(argv[++i]);
continue;
}
// msize option for DAP-K
if(strcmp(argv[i],"-msize")==0 || strcmp(argv[i], "-dapk") ==0){
msize = atoi(argv[++i]);
continue;
}
// openmp threads
if(strcmp(argv[i], "-t")==0){
thread = atoi(argv[++i]);
continue;
}
// output option
if(strcmp(argv[i], "--all")==0 || strcmp(argv[i],"--output_all")==0){
output_all = 1;
continue;
}
// gene/locus name
if(strcmp(argv[i], "-name")==0 || strcmp(argv[i], "-n")==0){
strcpy(gene_name, argv[++i]);
continue;
}
// no finemappin, just sincle SNP analysis
if(strcmp(argv[i], "--scan")==0){
run_scan = 1;
continue;
}
if(strcmp(argv[i], "--dump_summary")==0){
extract_ss = 1;
continue;
}
if(strcmp(argv[i], "--dump_summary2")==0){
extract_ss = 2;
continue;
}
fprintf(stderr, "Error: unknown option \"%s\"\n",argv[i]);
exit(1);
}
controller con;
if(strlen(data_file)!=0){
con.initialize(data_file,grid_file);
}else if(strlen(zval_file)!=0 && strlen(ld_file)!=0 ){
con.initialize(zval_file, ld_file, grid_file,sample_size, ld_format);
}else if(strlen(ld_file)!=0 && strlen(est_file)!=0 && sample_size >0 && syy>0){
con.initialize(est_file, ld_file, grid_file, sample_size, syy,ld_format);
}else{
fprintf(stderr, "Error: no suitable input data specified \n");
exit(1);
}
// remember to delete the following line
// con.set_for_r(0);
con.set_outfile(out_file, log_file);
con.set_gene(gene_name);
con.set_abf_option(abf_option);
con.set_thread(thread);
con.set_size_limit(size_limit);
if(ld_control>=0)
con.set_ld_control(ld_control);
if(msize>=1){
con.set_max_size(msize);
}
if(pes>0){
con.set_ens(pes);
}
if(strlen(prior_file)==0){
if(pi1 != -1){
if(0<pi1 && pi1 <1){
con.set_prior(pi1);
}else{
fprintf(stderr, "Warning: pi1 specification is outside the range, ignored...\n");
con.set_prior_default();
}
}else{
// default
con.set_prior_default();
}
}else
con.set_prior(prior_file);
if(output_all == 1)
con.set_output_all();
if(snp_select_thresh>=0)
con.set_snp_select_thresh(snp_select_thresh);
if(size_select_thresh >=0)
con.set_size_select_thresh(size_select_thresh);
con.run_option = 0;
if(run_scan){
con.run_option = 1;
}
if(extract_ss==1){
con.run_option =2;
}
if(extract_ss==2){
con.run_option =3;
}
// all done, print all configs
con.print_dap_config();
con.run();
return 0;
}