File: commandLine.cpp

package info (click to toggle)
gwama 2.2.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 564 kB
  • sloc: cpp: 6,448; perl: 239; xml: 38; makefile: 24; sh: 11
file content (428 lines) | stat: -rwxr-xr-x 14,495 bytes parent folder | download | duplicates (5)
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/*************************************************************************
GWAMA software:  May, 2010

Contributors:
    * Andrew P Morris amorris@well.ox.ac.uk
    * Reedik Magi reedik@well.ox.ac.uk

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************/


#include <iostream>
#include <map>
#include <vector>
#include <stdlib.h>
#include <fstream>
#include "marker.h"
#include "study.h"
#include <math.h>
#include <cctype> // std::toupper

#include "global.h"
#include "tools.h"

using namespace std;

void printVersion(string version)
{
   cout << "GWAMA version: " << version << endl;
   exit(0);
}
void printHelp(string version)
{
   string v;
   double len =17 -  version.size()-1;
   int f = (int) ((len/2.0)+0.6);
   int r = (int) ((len/2.0));
   for (int i=0; i < f;i++)v+=" ";
   v+='v';
   v+=version;
   for (int i=0; i < r;i++)v+=" ";
   cout << endl;
   cout << "@----------------------------------------------------------@" << endl;
   cout << "|      GWAMA        |" << v << "|    May, 2010       |" << endl;
   cout << "|----------------------------------------------------------|" << endl;
   cout << "|           (C) 2008 Reedik Magi & Andrew P Morris         |" << endl;
   cout << "|                    BSD 3-Clause License                  |" << endl;
   cout << "|----------------------------------------------------------|" << endl;
   cout << "|  For documentation, citation & bug-report instructions:  |" << endl;
   cout << "|              http://www.well.ox.ac.uk/GWAMA/             |" << endl;
   cout << "@----------------------------------------------------------@" << endl;
   cout << endl;	     
   cout << endl;	     
   cout << "Command line options:"<<endl;
   cout << endl;
   cout << "GWAMA --filelist {filename} or -i {filename} Specify     "<<endl;
   cout << "                    studies' result files. Default =     "<<endl;
   cout << "                    gwama.in                             "<<endl<<endl; 
   cout << "    --output {fileroot} or -o  {fileroot} Specify file   "<<endl;
   cout << "                    root for output of analysis. Default "<<endl;
   cout << "                    <gwama> (gwama.out)                  "<<endl<<endl;
   cout << "    --random or -r  Use random effect correction         "<<endl<<endl;;
   cout << "    --genomic_control or -gc  Use genomic control for    "<<endl;
   cout << "                    adjusting studies' result files      "<<endl<<endl;
   cout << "    --genomic_control_output or -gco      Use  genomic   "<<endl;
   cout << "                    control on meta-analysis summary.    "<<endl;
   cout << "                    (i.e. results  of meta-              "<<endl;
   cout << "                    analysis are corrected for gc)       "<<endl<<endl;
   cout << "    --quantitative or -qt    Use this option, if trait is"<<endl;
   cout << "                    quantitative (columns BETA & SE).    "<<endl;
   cout << "                    Default is binary trait (columns OR, "<<endl;
   cout << "                    OR95_U, OR_95_L)                     "<<endl<<endl;
   cout << "    --threshold {0-1} or -t {0-1} The p-value threshold  "<<endl;
   cout << "                    for showing direction. Default = 1   "<<endl<<endl;
   cout << "    --map {filename} or -m {filename} Marker position    "<<endl;
   cout << "                    file for chromosome and position info"<<endl<<endl;
   cout << "    --no_alleles    No allele information has been given."<<endl;
   cout << "                    Expecting always the same EA.        "<<endl<<endl;
   cout << "    --indel_alleles   Allele labes might contain more    "<<endl;
   cout << "                    than single letter. No strand checks."<<endl<<endl;    
   cout << "    --sex           Run gender-differentiated and gender-"<<endl;
   cout << "                    heterogeneity analysis. Gender info  "<<endl;
   cout << "                    must be provided in filelist file.   "<<endl;
   cout << "                    (second column after file names is   "<<endl;
   cout << "                    either M or F) More info in tutorial."<<endl<<endl;
   cout << "    --filter        Set a filtering based on column      "<<endl;    
   cout << "                    header. It needs 3 arguments: column "<<endl; 
   cout << "                    name, equation [>,<,>=,<=,==,!=],    "<<endl;  
   cout << "                    filter value. Multiple filters can be"<<endl; 
   cout << "                    set.                                 "<<endl<<endl;    
   cout << "    --name_marker   alternative header to marker name col"<<endl<<endl;
   cout << "    --name_strand   alternative header to strand column  "<<endl<<endl;
   cout << "    --name_n        alternative header to sample size col"<<endl<<endl;
   cout << "    --name_eaf      alternative header to EAF column     "<<endl<<endl;
   cout << "    --name_beta     alternative header to beta column    "<<endl<<endl;
   cout << "    --name_se       alternative header to std. err. col  "<<endl<<endl;
   cout << "    --name_or	    alternative header to OR column      "<<endl<<endl;
   cout << "    --name_or_95l   alternative header to OR 95L column  "<<endl<<endl;
   cout << "    --name_or_95u   alternative header to OR 95U column  "<<endl<<endl;
   cout << "    --help or -h    Print this help                      "<<endl<<endl;
   cout << "    --version or -v  Print GWAMA version number          "<<endl<<endl;   
   exit (0);
}


bool
readCommandline (int argc, char *argv[], global & _g)
{
	for (int i = 1; i < argc; i++)
	{
		if (string(argv[i]).compare("--version")==0 || string(argv[i]).compare("-v")==0)
		 {
			printVersion(_g._version);
			return 1;
		 }
		else if (string(argv[i]).compare("--help")==0 || string(argv[i]).compare("-h")==0)
		 {
			printHelp(_g._version);
			return 1;
		 }
		else if (string(argv[i]).compare("--genomic_control")==0 || string(argv[i]).compare("-gc")==0)
		 {
			_g._genomicControl=true;
			cout << "Genomic control enabled"  << endl;
		 }
		else if (string(argv[i]).compare("--no_alleles")==0)
		 {
			_g._noAlleles=true;
			cout << "All effects are expected to be according to the same allele."  << endl;
		 }

		else if (string(argv[i]).compare("--random")==0 || string(argv[i]).compare("-r")==0)
		 {
			_g._randomEffect=true;
			cout << "Using random effect correction"  << endl;
		 }
		else if (string(argv[i]).compare("--quantitative")==0 || string(argv[i]).compare("-qt")==0)
		 {
			 _g._binaryTrait = false;
			cout << "Quantitative trait (BETA+SE)"  << endl;

		 }
		else if (string(argv[i]).compare("--genomic_control_output")==0 || string(argv[i]).compare("-gco")==0)
		 {
			 _g._genomicControlOutput=true;
			cout << "Genomic control for meta-analysis output enabled"  << endl;
		 }
		else if (string(argv[i]).compare("--sex")==0)
		 {
			 _g._genderHet=true;
			cout << "Gender-specific heterogeneity analysis enabled"  << endl;
		 }
        else if (string(argv[i]).compare("--indel_alleles")==0)
        {
            _g._indel=true;
			cout << "Indel allele names enabled. No strand checks"  << endl;
        }
		else if (string(argv[i]).compare("--name_marker")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative marker column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeMarkerNames.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_marker\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_ea")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative effect allele column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeEffectAlleles.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_ea\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_nea")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative other allele column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeOtherAlleles.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_nea\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_or")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative OR column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeORs.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_or\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_or_95l")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative lower CI of OR column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeOR_95Ls.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_or_95l\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_or_95u")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative upper CI of OR column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeOR_95Us.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_or_95u\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_beta")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative beta column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeBetas.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_beta\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_se")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative std. error column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeSEs.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_se\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_n")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative sample size column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeNs.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_n\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_eaf")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative effect allele frequency column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeEffectAlleleFreqs.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_eaf\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--name_strand")==0)
		{
			if (i != argc-1) 
			{
				cout<<"Alternative strand column name: " << uc(string(argv[i+1])) << endl;; 
				_g._alternativeStrands.push_back(uc(string(argv[i+1])));
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --name_strand\n"; 
				return 0;
			}	
			i++;
		}

		else if (string(argv[i]).compare("--filelist")==0 || string(argv[i]).compare("-i")==0)
		{
			if (i != argc-1) 
			{
				_g._fileList = string(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --filelist\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--output")==0 || string(argv[i]).compare("-o")==0)
		{
			if (i != argc-1) 
			{
				_g._outputRoot = string(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --output\n"; 
				return 0;
			}	
			i++;
		}
		else if (string(argv[i]).compare("--map")==0 || string(argv[i]).compare("-m")==0)
		{
			if (i != argc-1) 
			{
				_g._markerMap = string(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --map\n"; 
				return 0;
			}	
			i++;
		}
        else if (string(argv[i]).compare("--filter")==0)
		{
            string a = "";
            string b = "";
            double c = -9999;
			if (i != argc-1) 
			{
				a = string(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --filter\n"; 
				return 0;
			}	
            i++;
            if (i != argc-1) 
			{
				b = string(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --filter\n"; 
				return 0;
			}	
            i++;
			if (i != argc-1) 
			{
				c = atof(argv[i+1]);
			}
			if (i == argc-1 ) 
			{
				cout<<"ERROR: Missing a value for --filter\n"; 
				return 0;
			}	
            i++;

            filter _filter(a,b,c);
            if (! _filter.valid())
            {
                cout<<"ERROR: Filter not valid. Please check the format\n"; 
				return 0; 
            }
            cout << "Setting filter for column: " << a << " to filter out samples with values " << b << " " << c << endl;
            _g.filters.push_back(_filter);
		}
		else if (string(argv[i]).compare("--threshold")==0 || string(argv[i]).compare("-t")==0)
		{
			if (i != argc-1)
			{
				if (atof(argv[i+1]) >0 && atof(argv[i+1]) <= 1)
				_g._thresholdPValDir = atof(argv[i+1]);
			}
			if (i == argc-1) 
			{
				cout<<"ERROR: Missing or errogeneous value for --threshold\n"; 
				return 0;
			}	
			i++;
		}
		else
		{
				cout<<"Unknown command line option: " << string(argv[i]) << ". Exit program.\n"; 
			return false;
		}
	}
	return true;
}