-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeQTLPolyG.cpp
175 lines (160 loc) · 5.92 KB
/
MeQTLPolyG.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
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <math.h>
#include <unistd.h>
#include <armadillo>
#ifndef _UTIL_H
#define _UTIL_H
#include "Util.h"
#endif
#ifndef _POSTCAL_H
#define _POSTCAL_H
#include "PostCal.h"
#endif
#ifndef _TOPKSNP_H
#define _TOPKSNP_H
#include "TopKSNP.h"
#endif
#ifndef _MEQTLPOLYGMODEL_H
#define _MEQTLPOLYGMODEL_H
#include "MeQTLPolyGModel.h"
#endif
#include "conditional_function.h"
#include <sys/stat.h>
using namespace std;
int main( int argc, char *argv[] ){
if (argc <= 1) {
cout<<"Error, parameter(s) needed"<<endl;
return EXIT_SUCCESS;
}
if (argc==2 && argv[1][0] == '-' && argv[1][1] == 'c') {
return EXIT_SUCCESS;
}
int totalCausalSNP = 1;
double gamma = 0.01;
float rho = 0.95;
bool histFlag = false;
int oc = 0;
string yFile = "";
string outputFileName = "";
string geneMapFile = "";
string weight = "";
string covariate = "";
string grm_test ="";
string gene="PolyQTL_output";
vector<string> grm_file;
string X_file="";
string geno_file="";
int number;
int nthread=1;
int mode=-1;
string input="";
while ((oc = getopt(argc, argv, "vhl:t:o:x:Z:p:n:w:g:r:c:G:w:f:m:P:T:")) != -1) {
switch (oc) {
case 'v':
cout << "version 1.0:" << endl;
case 'h':
cout << "Options: " << endl;
cout << "-h, --help show this help message and exit " << endl;
cout << "-o OUTFILE, --out=OUTFILE specify the output file" << endl;
cout << "-l LDFILE, --ld_file=LDFILE the ld input file" << endl;
cout << "-p yFILE, --y_file=yFILE phenotype" << endl;
cout << "-r RHO, --rho-prob=RHO set $pho$ probability (default 0.95)" << endl;
cout << "-g GAMMA, --gamma set $gamma$ the prior of a SNP being causal (default 0.01)" << endl;
cout << "-c causal set the maximum number of causal SNPs" << endl;
cout << "-C covariate, --covariate set the covariate matrix "<<endl;
cout << "-T output folder, --target gene name "<<endl;
cout << "-G genetic relatedness matrix, --GRM set the genetic relatedness matrix "<<endl;
cout << "-f 1 to out the probaility of different number of causal SNP" << endl;
cout << "-w Weight file, --weight set the biological annotation to use" << endl;
cout << "-n Number of samples, --number set the biological annotation to use" << endl;
cout << "-x genotype information, genotype file for explored variants" << endl;
cout << "-t threads to use, --nthread set the threads to use" << endl;
exit(0);
case 'n':
number = atoi(optarg);
break;
// case 'm':
// conditional = atoi(optarg);
// break;
case 'o':
outputFileName = string(optarg);
break;
case 'T':
gene =string(optarg);
break;
case 'P':
input = string(optarg);
break;
case 'p':
yFile = string(optarg);
break;
case 'r':
rho = atof(optarg);
break;
case 'x':
X_file = string(optarg);
break;
case 'c':
totalCausalSNP = atoi(optarg);
break;
case 'g':
gamma = atof(optarg);
break;
case 'w':
weight=string(optarg);
break;
case 't':
nthread=atoi(optarg);
case 'f':
histFlag = true;
break;
case 'G':
grm_test =string(optarg);
grm_file.push_back(grm_test);
break;
case 'C':
covariate=string(optarg);
break;
case 'Z':
geno_file=string(optarg);
break;
case ':':
case '?':
default:
cout << "Strange" << endl;
break;
}
}
cout<<"Getting parameter information is over"<<endl;
cout<<"input is: "<<input<<endl;
cout<<"gene is: "<<gene<<endl;
ifstream check_dir2("output/");
if (!check_dir2) {
mkdir("output", S_IRWXU|S_IRGRP|S_IROTH);
}
//If input is setting, run in conditional analysis mode
if(input!="")
{
cout<<"input is: "<<input<<endl;
cout<<"gene is: "<<gene<<endl;
cout<<"Perform conditional analysis"<<endl;
ifstream check_dir(gene);
if (!check_dir) {
mkdir(gene.c_str(), S_IRWXU|S_IRGRP|S_IROTH);
}
// conditional_analysis(input,gene, totalCausalSNP,rho, histFlag, gamma,weight, nthread,covariate, grm_file);
conditional_analysis(input,gene, totalCausalSNP,rho, histFlag, gamma,weight, nthread,covariate, grm_file,outputFileName, geno_file);
// conditional_analysis(input,gene, totalCausalSNP,rho, histFlag);
return 0;
} else
{
//Run in one-step mode
MeQTLPolyGModel MeQTLPoly(yFile, outputFileName, totalCausalSNP,rho, histFlag, gamma,weight, nthread,covariate, grm_file,X_file);
MeQTLPoly.run();
MeQTLPoly.finishUp();
return 0;
}
}