-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_options.cpp
More file actions
371 lines (300 loc) · 15.5 KB
/
user_options.cpp
File metadata and controls
371 lines (300 loc) · 15.5 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
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
/*
*
* user_options.cpp
* Hetero2
*
* CSIRO Open Source Software License Agreement (variation of the BSD / MIT License)
* Copyright (c) 2014, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.
* All rights reserved. CSIRO is willing to grant you a license to this Hetero Version 2 on the following terms,
* except where otherwise indicated for third party material.
* Redistribution and use of this software in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* • Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* • Neither the name of CSIRO nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission of CSIRO.
* EXCEPT AS EXPRESSLY STATED IN THIS AGREEMENT AND TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE
* IS PROVIDED "AS-IS". CSIRO MAKES NO REPRESENTATIONS, WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS REGARDING THE CONTENTS OR ACCURACY
* OF THE SOFTWARE, OR OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, THE ABSENCE
* OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE.
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL CSIRO BE LIABLE ON ANY LEGAL THEORY (INCLUDING,
* WITHOUT LIMITATION, IN AN ACTION FOR BREACH OF CONTRACT, NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR
* OTHER LIABILITY HOWSOEVER INCURRED. WITHOUT LIMITING THE SCOPE OF THE PREVIOUS SENTENCE THE EXCLUSION OF LIABILITY
* SHALL INCLUDE: LOSS OF PRODUCTION OR OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS OF
* ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL,
* INDIRECT, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, ACCESS
* OF THE SOFTWARE OR ANY OTHER DEALINGS WITH THE SOFTWARE, EVEN IF CSIRO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* CLAIM, LOSS, DAMAGES OR OTHER LIABILITY.
* APPLICABLE LEGISLATION SUCH AS THE AUSTRALIAN CONSUMER LAW MAY APPLY REPRESENTATIONS, WARRANTIES, OR CONDITIONS, OR
* IMPOSES OBLIGATIONS OR LIABILITY ON CSIRO THAT CANNOT BE EXCLUDED, RESTRICTED OR MODIFIED TO THE FULL EXTENT SET OUT
* IN THE EXPRESS TERMS OF THIS CLAUSE ABOVE "CONSUMER GUARANTEES". TO THE EXTENT THAT SUCH CONSUMER GUARANTEES
* CONTINUE TO APPLY, THEN TO THE FULL EXTENT PERMITTED BY THE APPLICABLE LEGISLATION, THE LIABILITY OF CSIRO UNDER
* THE RELEVANT CONSUMER GUARANTEE IS LIMITED (WHERE PERMITTED AT CSIRO’S OPTION) TO ONE OF FOLLOWING REMEDIES OR
* SUBSTANTIALLY EQUIVALENT REMEDIES:
* (a) THE REPLACEMENT OF THE SOFTWARE, THE SUPPLY OF EQUIVALENT SOFTWARE, OR SUPPLYING RELEVANT SERVICES AGAIN;
* (b) THE REPAIR OF THE SOFTWARE;
* (c) THE PAYMENT OF THE COST OF REPLACING THE SOFTWARE, OF ACQUIRING EQUIVALENT SOFTWARE, HAVING THE RELEVANT
* SERVICES SUPPLIED AGAIN, OR HAVING THE SOFTWARE REPAIRED.
* IN THIS CLAUSE, CSIRO INCLUDES ANY THIRD PARTY AUTHOR OR OWNER OF ANY PART OF THE SOFTWARE OR MATERIAL DISTRIBUTED
* WITH IT. CSIRO MAY ENFORCE ANY RIGHTS ON BEHALF OF THE RELEVANT THIRD PARTY.
* Third Party Components
* The following third party components are distributed with the Software. You agree to comply with the license terms
* for these components as part of accessing the Software. Other third party software may also be identified in
* separate files distributed with the Software.
* ___________________________________________________________________
*
* JACOBI_EIGENVALUE.C (http://people.sc.fsu.edu/~jburkardt/c_src/jacobi_eigenvalue/jacobi_eigenvalue.c)
* Copyright (C) 2003-2013 John Burkardt
* This software is licensed under GNU LGPL (http://www.gnu.org/licenses/lgpl.html)
* ___________________________________________________________________
*/
#include "user_options.h"
// read the arguments and collect the options
void GetOptions::read(int argc, char** argv) {
int i;
char* currArg;
int currLen;
char flag;
string value;
for (i=1; i<argc; i++) {
// skip the first argument
currArg = argv[i];
currLen = (int) strlen(currArg);
if (currArg[0]=='-' && currLen>1) {
// get the flag
flag=currArg[1];
// get the value
if (currLen>2) {
value = (&currArg[2]);
} else if (argc > i+1 && argv[i+1][0]!='-') {
i++;
value = argv[i];
} else {
value = "";
}
flags.push_back(flag);
values.push_back(value);
}
}
}
int GetOptions::size() {
return (int) flags.size();
}
// constructor
UserOptions::UserOptions() {
//initialize the variables
// outputFormat : the format of the output multiple sequence alignment file
// 1 - FASTA format
// 2 - sequential PHYLIP format
// (default: 2)
outputFormat = 2;
// seqLen : the length of sequences to be simulated
seqLen = DEFAULT_SEQ_LEN;
// edgeRepresent : edge length representation
// 1 - Average number of substitutions per site
// 2 - Time
// (default: 1)
edgeRepresent = 1;
perfectSeq = 0;
seed_number = 0;
}
// To show the usage of the program
void UserOptions::outputUsage(char* progName) {
cout << "================================================================================" << endl;
cout << " Welcome to Hetero 2 version " << VERSION << endl << endl;
cout << "Syntax:" << endl;
cout << " " << progName << " <tree file> <site info file> <param file list> <other options>" << endl;
cout << " " << progName << " -h" << endl << endl;
cout << " <tree file> : \"Tree file\" lists the tree of each site category, the" << endl;
cout << " edge lengths and the labels of terminal/internal nodes" << endl << endl;
cout << " <site info file> : \"Site info file\" lists the detailed information of" << endl;
cout << " each site category, including the site proportion and" << endl;
cout << " the nucleotide distribution at the root" << endl << endl;
cout << " <param file list> : \"Param file list\" shows the name of the parameter file" << endl;
cout << " of each variant site category" << endl << endl;
cout << "Note: one may refer to the examples to understand the format of the files" << endl << endl;
cout << "other options:" << endl << endl;
cout << " -l <sequence length> : The length of sequences to be simulated" << endl;
cout << " (default: " << DEFAULT_SEQ_LEN << ")" << endl << endl;
cout << " -f <output format> : The format of simulated multiple sequence alignment" << endl;
cout << " 1 - FASTA format" << endl;
cout << " 2 - Sequential PHYLIP format (default)" << endl << endl;
cout << " -o <output prefix> : Prefix for output files" << endl;
cout << " (default: <tree file> w/o .ext)" << endl << endl;
cout << " -e < 1 or 2 > : Representation of tree edges" << endl;
cout << " 1 - Average number of substitutions per site" << endl;
cout << " 2 - Time" << endl;
cout << " (default: 1)" << endl << endl;
cout << " -p : Perfect sequence simulation" << endl << endl;
cout << " -s : Seed number" << endl << endl;
cout << " -h : This help page" << endl << endl;
cout << "Output files:" << endl;
cout << " <output prefix>.out : The simulated multiple sequence alignment file" << endl << endl;
cout << "Example:" << endl;
cout << " Example tree file : trees.txt" << endl;
cout << " Example site info file : site_info_file.txt" << endl;
cout << " Example param file list: param_file_list.txt" << endl;
cout << " Example parameter files: parameter_1.txt, parameter_2.txt" << endl;
cout << " To execute the Hetero2 program using the default parameters:" << endl;
cout << " $ " << progName << " trees.txt site_info_file.txt param_file_list.txt" << endl << endl;
cout << "Contact: " << CONTACTPERSON << endl;
cout << " " << CONTACTPERSON2 << endl;
cout << "================================================================================" << endl;
}
// read the arguments and collect the user options
int UserOptions::readArguments(int argc, char** argv, string* errMsg) {
// return:
// 0 if the user options are valid
// 1 if there exists error message
// 2 if a help menu is called
int i;
bool duplicateOption = false;
bool emptyOption = false;
vector<string> token;
int minArgNum = 4; // minimum number of arguments
bool l_option_assigned = false;
bool f_option_assigned = false;
bool o_option_assigned = false;
bool e_option_assigned = false;
bool s_option_assigned = false;
*errMsg = "";
if (argc < minArgNum) {
// invoke the help menu
return 2;
}
treeFile = argv[1];
siteIntoFile = argv[2];
paramFileList = argv[3];
// get the other options if there is any
if (argc > minArgNum) {
GetOptions options;
options.read(argc, argv);
for (i=0; i<options.size(); i++) {
char flag = options.flags[i];
string value = options.values[i];
switch (flag) {
case 'l':
if (l_option_assigned)
duplicateOption = true;
else if (value.length() == 0)
emptyOption = true;
else {
l_option_assigned = true;
int valueInt = atoi(value.c_str());
if (valueInt <= 0)
*errMsg = "Error! The value for '-l' has to be greater than 0";
else
seqLen = valueInt;
}
break;
case 'f':
if (f_option_assigned)
duplicateOption = true;
else if (value.length() == 0)
emptyOption = true;
else {
f_option_assigned = true;
int valueInt = atoi(value.c_str());
if (valueInt < 1 || valueInt > 2)
*errMsg = "Error! The value for '-f' has to be 1 or 2";
else
outputFormat = valueInt;
}
break;
case 'e':
if (e_option_assigned)
duplicateOption = true;
else if (value.length() == 0)
emptyOption = true;
else {
e_option_assigned = true;
int valueInt = atoi(value.c_str());
if (valueInt < 1 || valueInt > 2)
*errMsg = "Error! The value for '-e' has to be 1 or 2";
else
edgeRepresent = valueInt;
}
break;
case 'o':
if (o_option_assigned)
duplicateOption = true;
else {
o_option_assigned = true;
if (value.length()==0)
emptyOption = true;
else
outputPrefix = value;
}
break;
case 'p':
perfectSeq = 1;
break;
case 'h':
return 2;
break;
case 's':
if (s_option_assigned)
duplicateOption = true;
else if (value.length() == 0)
emptyOption = true;
else {
s_option_assigned = true;
unsigned long valueLong = strtoul(value.c_str(), NULL, 10);
if (valueLong <= 0)
*errMsg = "Error! The value for '-s' has to be greater than 0";
else
seed_number = valueLong;
}
break;
default:
*errMsg = "Unknown option '-" + string(1,flag);
break;
} // case
if (duplicateOption) {
*errMsg = "Error! Duplicate option -" + string(1,flag);
} else if (emptyOption) {
*errMsg = "Error! Empty value for the option -" + string(1,flag);
}
if (*errMsg != "") {
return 1;
}
}
}
if (outputPrefix == "") {
setDefaultOutputPrefix();
}
// initialize the random seed
if (seed_number == 0) {
seed_number = mix(clock(), time(NULL), getpid());
}
return 0;
}
// by default, prefixOut = <alignment file> w/o .ext
void UserOptions::setDefaultOutputPrefix() {
outputPrefix = removeExtension(treeFile);
}
// To show the summary of the parameters
void UserOptions::showSummary() {
cout << "================================================================================" << endl;
cout << " Welcome to Hetero 2 - Version " << VERSION << endl << endl;
cout << "Tree file ............................................. " << treeFile << endl;
cout << "Site info file ........................................ " << siteIntoFile << endl;
cout << "Param file list ....................................... " << paramFileList << endl;
cout << "Length of sequences to be simulated ................... " << seqLen << endl;
cout << "Format of output alignment ............................ ";
switch (outputFormat) {
case 1:
cout << "FASTA" << endl;
break;
case 2:
cout << "sequential PHYLIP" << endl;
break;
}
cout << "Input parameters in ................................... " << outputPrefix << ".stat" << endl;
cout << "Output file ........................................... " << outputPrefix << ".out" << endl;
cout << "Seed number ........................................... " << seed_number << endl;
cout << "================================================================================" << endl;
}