-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcargs.cpp
More file actions
323 lines (257 loc) · 7.58 KB
/
Copy pathcargs.cpp
File metadata and controls
323 lines (257 loc) · 7.58 KB
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
// Standard Includes
#include <iostream>
#include <string>
// Namespace
using std::cout;
using std::string;
// Custom headers
#include "cargs.h"
#include "helper.h"
#include "options.h"
#include "output.h"
// Functions
CArgs::CArgs( int n, char *params[] ): parameterCount( n )
{
fillVector(parsed, false, n);
parameters.reserve( n );
parsed[0] = true; // Filename automatically returned
for (int i = 0; i < n; ++i) { addParameter( params[i] ); }
}
void CArgs::validity()
{
vector<int> badOptions;
for (unsigned int i = 0; i < getParCount(); ++i)
{
if (parsed[i] == false) { badOptions.push_back( i ); }
}
if (badOptions.size())
{
string badopt = "Unrecognized command-line switch(es):\n";
for (unsigned int i = 0; i < badOptions.size(); ++i)
{
badopt += parameters[ badOptions[i] ] + "\n";
}
badopt += "Bad command-line options selected";
screenError( badopt );
}
}
bool CArgs::search( string const& s )
{
for (unsigned int i = 0; i < getParCount(); ++i)
{
if (parameters[i] == s)
{
parsed[i] = true;
return true;
}
}
return false;
}
int CArgs::valueIndex( string const& s )
{
for (unsigned int i = 0; i < getParCount(); ++i)
{
if (parameters[i] == s and i + 1 < getParCount())
{
parsed[i + 1] = true;
return i + 1;
}
}
screenError( "Missing argument for command [" + s + "]" );
return -10;
}
void CArgs::write()
{
writeLog( "Command-line Options Set:\n" );
for (unsigned int i = 0; i < commandCount(); ++i)
{
writeLog( commandLineList[i] + " " + commandLineValue[i] + "\n");
}
writeLog("\n");
}
void CArgs::parse()
{
// Help data
if (search("--help") or search("-h") or getParCount() == 1)
{
cout << "\nsnpduo v" + VERSION + RELEASE + "\n" + DATE + "\n\n";
cout << ("\n"
"snpduo --file <fileroot> Specify .ped and .map files\n"
" --ped <ped file> Specify .ped file name (requires --map)\n"
" --map <map file> Specify .map file name\n"
" --tfile <fileroot> Specify .tfam and .tped files\n"
" --tped <tped file> Specify .tped file name (requires --tfam)\n"
" --tfam <tfam file> Specify .tfam file name\n"
" --genome <filename> Specify a PLINK .genome file for input\n"
" **Warning: Cannot get expected relationships from\n"
" this file\n"
"\n"
" --out <fileroot> Specify the root name for output files\n"
"\n"
" --counts Prints IBS 0,1,2 and 2* (AB->AB) counts to .count\n"
" file\n"
" --summary Prints counts + Mean and Standard Deviation of IBS\n"
" and informative percents to .summary file\n"
" --specified Prints relationships specified in input to\n"
" the .specified file\n"
" --calculated Prints the calculated relationships using IBS*,\n"
" Mean, and SD to .theoretical file\n"
" --oldcalculated Prints calculated relationships from Mean and SD to\n"
" .theoretical file (deprecated)*\n"
" --conflicting Prints comparisons where specified relationship is\n"
" different from calculated\n"
" relationship to .conflicting file\n"
" * Note: to get conflicting relationships by the old\n"
" algorithm you MUST specify --oldcalculated AND\n"
" --conflicting\n"
"\n"
" --map3 Specifies no genetic distance column\n"
"\n"
" --recode Recodes data into ped/map files when used alone\n"
" --transpose When used with --recode outputs a tped/tfam files\n"
" --webDuo When used with --recode outputs file compatible with\n"
" the web version of SNPDuo (Custom format)\n"
" **Warning: Uses A/B coding but will NOT be the same\n"
" as the platform's A/B coding scheme. Only for\n"
" Web SNPDuo!\n"
"\n"
" --silent No messages printed to screen\n"
" --version Print version information and exit\n"
"\n"
" --help / -h Invokes this help menu\n");
shutdown();
}
// Print version information and exit
if (search("--version"))
{
cout << "\nsnpduo v" + VERSION + RELEASE + "\n" + DATE + "\n\n";
shutdown();
}
// File reading options
if (search("--file"))
{
par::file = parameters[ valueIndex("--file") ];
if (par::pedFile != "null" or par::mapFile != "null") error ("Cannot specify a map or pedFile while using the --file option");
par::pedFile = par::file + ".ped";
par::mapFile = par::file + ".map";
addToList("--file");
addToValue(par::file);
}
if (search("--ped"))
{
if (par::file != "null") error ("Cannot specify --file and --ped at the same time");
par::pedFile = parameters[ valueIndex("--ped") ];
addToList("--ped");
addToValue(par::pedFile);
}
if (search("--map"))
{
if (par::file != "null") error ("Cannot specify --file and --map at the same time");
par::mapFile = parameters[ valueIndex("--map") ];
addToList("--map");
addToValue( par::mapFile );
}
if (search("--tfile"))
{
par::tfile = parameters[ valueIndex("--tfile") ];
if (par::tpedFile != "null" or par::tfamfile != "null") error ("Cannot specify a tped file or tfam file while using the --tfile option");
par::tpedFile = par::tfile + ".tped";
par::tfamfile = par::tfile + ".tfam";
addToList("--tfile");
addToValue( par::tfile );
}
if (search("--tped"))
{
if (par::tfile != "null") error ("Cannot specify --tfile and --tped at the same time");
par::tpedFile = parameters[ valueIndex("--tped") ];
addToList("--tped");
addToValue(par::tfamfile);
}
if (search("--tfam"))
{
if (par::tfile != "null") error ("Cannot specify --tfile and --tfam at the same time");
par::tfamfile = parameters[ valueIndex("--tfam") ];
addToList("--tfam");
addToValue( par::tfamfile );
}
// File writing options
if (search("--recode"))
{
par::recode = true;
addToList("--recode");
addToValue(" ");
}
if (search("--transpose"))
{
par::transpose = true;
addToList("--transpose");
addToValue(" ");
}
if (search("--webDuo"))
{
par::webDuo = true;
addToList("--webDuo");
addToValue(" ");
}
if (search("--genome"))
{
par::genome = true;
par::genomeFile = parameters[ valueIndex("--genome") ];
addToList("--genome");
addToValue(" ");
}
if (search("--out"))
{
par::out = parameters[ valueIndex("--out") ];
addToList("--out");
addToValue(par::out);
}
if (search("--map3"))
{
par::map3 = true;
addToList("--map3");
addToValue(" ");
}
if (search("--silent"))
{
par::verbose = false;
addToList("--silent");
addToValue(" ");
}
if (search("--counts"))
{
par::counts = true;
addToList("--counts");
addToValue(" ");
}
if (search("--summary"))
{
par::summary = true;
addToList("--summary");
addToValue(" ");
}
if (search("--specified"))
{
par::specified = true;
addToList("--specified");
addToValue(" ");
}
if (search("--calculated"))
{
par::calculated = true;
addToList("--calculated");
addToValue(" ");
}
if (search("--oldcalculated"))
{
par::oldCalculated = true;
addToList("--oldCalculated");
addToValue(" ");
}
if (search("--conflicting"))
{
par::conflicting = true;
addToList("--conflicting");
addToValue(" ");
}
}