]> git.donarmstrong.com Git - mothur.git/blob - validparameter.cpp
documentation
[mothur.git] / validparameter.cpp
1 /*
2  *  validparameter.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/5/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "validparameter.h"
11
12 /***********************************************************************/
13
14 ValidParameters::ValidParameters() {
15         try {
16                 initialReaddist();
17                 initialReadotu();
18                 initialReadtree();
19                 initialCluster();
20                 initialDeconvolute();
21                 initialParsimony();
22                 initialCollectsingle();
23                 initialCollectshared();
24                 initialRarefactsingle();
25                 initialRarefactshared();
26                 initialSummarysingle();
27                 initialSummaryshared();
28                 initialUnifracweighted();
29                 initialUnifracunweighted();
30                 initialLibshuff();
31         }
32         catch(exception& e) {
33                 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34                 exit(1);
35         }
36         catch(...) {
37                 cout << "An unknown error has occurred in the ValidParameters class function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }       
40 }
41
42 /***********************************************************************/
43
44 ValidParameters::~ValidParameters() {}
45
46 /***********************************************************************/
47 bool ValidParameters::isValidParameter(string parameter, string command) {
48         try {   
49         
50                 if (command == "read.dist") {
51                         //is it valid
52                         if ((readdist.find(parameter)) != (readdist.end())) {
53                                 return true;
54                         }else { 
55                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
56                                 for (it = readdist.begin(); it != readdist.end(); it++) {
57                                         cout << it->first << ", ";
58                                 }
59                                 cout << endl;
60                                 return false; }
61                 }else if (command == "read.otu") {
62                         //is it valid
63                         if ((readotu.find(parameter)) != (readotu.end())) {
64                                 return true;
65                         }else { 
66                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
67                                 for (it = readotu.begin(); it != readotu.end(); it++) {
68                                         cout << it->first << ", ";
69                                 }
70                                 cout << endl;
71                                 return false; }
72                 //are you looking for a calculator for a rarefaction parameter
73                 }else if (command == "read.tree") {
74                         //is it valid
75                         if ((readtree.find(parameter)) != (readtree.end())) {
76                                 return true;
77                         }else { 
78                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
79                                 for (it = readtree.begin(); it != readtree.end(); it++) {
80                                         cout << it->first << ", ";
81                                 }
82                                 cout << endl;
83                                 return false; }
84                 //are you looking for a calculator for a summary parameter
85                 }else if (command == "cluster") {
86                         //is it valid
87                         if ((cluster.find(parameter)) != (cluster.end())) {
88                                 return true;
89                         }else { 
90                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
91                                 for (it = cluster.begin(); it != cluster.end(); it++) {
92                                         cout << it->first << ", ";
93                                 }
94                                 cout << endl;
95                                 return false; }         //are you looking for a calculator for a sharedsummary parameter
96                 }else if (command == "deconvolute") {
97                         //is it valid
98                         if ((deconvolute.find(parameter)) != (deconvolute.end())) {
99                                 return true;
100                         }else { 
101                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
102                                 for (it = deconvolute.begin(); it != deconvolute.end(); it++) {
103                                         cout << it->first;
104                                 }
105                                 cout << endl;
106                                 return false; }
107                 }else if (command == "parsimony") {
108                         //is it valid
109                         if ((parsimony.find(parameter)) != (parsimony.end())) {
110                                 return true;
111                         }else { 
112                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
113                                 for (it = parsimony.begin(); it != parsimony.end(); it++) {
114                                         cout << it->first << ", ";
115                                 }
116                                 cout << endl;
117                                 return false; }
118                 }else if (command == "collect.single") {
119                         //is it valid
120                         if ((collectsingle.find(parameter)) != (collectsingle.end())) {
121                                 return true;
122                         }else { 
123                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
124                                 for (it = collectsingle.begin(); it != collectsingle.end(); it++) {
125                                         cout << it->first << ", ";
126                                 }
127                                 cout << endl;
128                                 return false; }
129                 }else if (command == "collect.shared") {
130                         //is it valid
131                         if ((collectshared.find(parameter)) != (collectshared.end())) {
132                                 return true;
133                         }else { 
134                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
135                                 for (it = collectshared.begin(); it != collectshared.end(); it++) {
136                                         cout << it->first << ", ";
137                                 }
138                                 cout << endl;
139                                 return false; }
140                 }else if (command == "rarefaction.single") {
141                         //is it valid
142                         if ((rarefactsingle.find(parameter)) != (rarefactsingle.end())) {
143                                 return true;
144                         }else { 
145                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
146                                 for (it = rarefactsingle.begin(); it != rarefactsingle.end(); it++) {
147                                         cout << it->first << ", ";
148                                 }
149                                 cout << endl;
150                                 return false; }
151                 }else if (command == "rarefaction.shared") {
152                         //is it valid
153                         if ((rarefactshared.find(parameter)) != (rarefactshared.end())) {
154                                 return true;
155                         }else { 
156                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
157                                 for (it = rarefactshared.begin(); it != rarefactshared.end(); it++) {
158                                         cout << it->first << ", ";
159                                 }
160                                 cout << endl;
161                                 return false; }
162                 }else if (command == "summary.single") {
163                         //is it valid
164                         if ((summarysingle.find(parameter)) != (summarysingle.end())) {
165                                 return true;
166                         }else { 
167                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
168                                 for (it = summarysingle.begin(); it != summarysingle.end(); it++) {
169                                         cout << it->first << ", ";
170                                 }
171                                 cout << endl;
172                                 return false; }
173                 }else if (command == "summary.shared") {
174                         //is it valid
175                         if ((summaryshared.find(parameter)) != (summaryshared.end())) {
176                                 return true;
177                         }else { 
178                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
179                                 for (it = summaryshared.begin(); it != summaryshared.end(); it++) {
180                                         cout << it->first << ", ";
181                                 }
182                                 cout << endl;
183                                 return false; }
184                 }else if (command == "unifrac.weighted") {
185                         //is it valid
186                         if ((unifracweighted.find(parameter)) != (unifracweighted.end())) {
187                                 return true;
188                         }else { 
189                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
190                                 for (it = unifracweighted.begin(); it != unifracweighted.end(); it++) {
191                                         cout << it->first << ", ";
192                                 }
193                                 cout << endl;
194                                 return false; }
195                 }else if (command == "unifrac.unweighted") {
196                         //is it valid
197                         if ((unifracunweighted.find(parameter)) != (unifracunweighted.end())) {
198                                 return true;
199                         }else { 
200                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
201                                 for (it = unifracunweighted.begin(); it != unifracunweighted.end(); it++) {
202                                         cout << it->first << ", ";
203                                 }
204                                 cout << endl;
205                                 return false; }
206                 }else if (command == "libshuff") {
207                         //is it valid
208                         if ((libshuff.find(parameter)) != (libshuff.end())) {
209                                 return true;
210                         }else { 
211                                 cout << parameter << " is not a valid parameter for the " + command + " command. Valid parameters are ";
212                                 for (it = libshuff.begin(); it != libshuff.end(); it++) {
213                                         cout << it->first << ", ";
214                                 }
215                                 cout << endl;
216                                 return false; }
217                 //not a valid paramter
218                 }else if (command == "help") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl;  
219                 }else if (command == "quit") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl; 
220                 }else if (command == "get.group") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl; 
221                 }else if (command == "get.label") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl; 
222                 }else if (command == "get.line") { cout << parameter << " is not a valid parameter for the " + command + " command. There are no vaild parameters." << endl; }
223                 
224                 return false; 
225                 
226         }
227         catch(exception& e) {
228                 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
229                 exit(1);
230         }
231         catch(...) {
232                 cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
233                 exit(1);
234         }
235 }
236
237 /***********************************************************************/
238 void ValidParameters::initialReaddist() {
239         readdist["phylip"]              = "phylip";
240         readdist["column"]              = "column";
241         readdist["name"]                = "name"; 
242         readdist["group"]               = "group"; 
243         readdist["cutoff"]              = "cutoff"; 
244         readdist["precision"]   = "precision"; 
245 }
246 /***********************************************************************/
247 void ValidParameters::initialReadotu() {
248         readotu["list"]                 = "list"; 
249         readotu["rabund"]               = "rabund"; 
250         readotu["sabund"]               = "sabund";
251         readotu["shared"]               = "shared";
252         readotu["group"]                = "group"; 
253         readotu["order"]                = "order"; 
254         readotu["label"]                = "label"; 
255         readotu["line"]                 = "line";
256 }
257 /***********************************************************************/
258 void ValidParameters::initialReadtree() {
259         readtree["group"]       = "group"; 
260         readtree["tree"]        = "tree";
261 }
262 /***********************************************************************/
263 void ValidParameters::initialCluster() {
264         cluster["cutoff"]               = "cutoff"; 
265         cluster["method"]               = "method";
266         cluster["precision"]    = "precision"; 
267 }
268 /***********************************************************************/
269 void ValidParameters::initialDeconvolute() {
270         deconvolute["fasta"]    = "fasta"; 
271 }
272 /***********************************************************************/
273 void ValidParameters::initialParsimony() {
274         parsimony["iters"]              = "iters"; 
275         parsimony["random"]             = "random";
276         parsimony["groups"]             = "groups";
277 }
278 /***********************************************************************/
279 void ValidParameters::initialCollectsingle() {
280         collectsingle["label"]          = "label"; 
281         collectsingle["line"]           = "line";
282         collectsingle["freq"]           = "freq"; 
283         collectsingle["calc"]           = "calc";
284 }
285 /***********************************************************************/
286 void ValidParameters::initialCollectshared() {
287         collectshared["label"]          = "label"; 
288         collectshared["line"]           = "line";
289         collectshared["freq"]           = "freq"; 
290         collectshared["calc"]           = "calc";
291         collectshared["jumble"]         = "jumble";
292 }
293 /***********************************************************************/
294 void ValidParameters::initialRarefactsingle() {
295         rarefactsingle["label"]         = "label"; 
296         rarefactsingle["line"]          = "line";
297         rarefactsingle["freq"]          = "freq"; 
298         rarefactsingle["calc"]          = "calc";
299         rarefactsingle["iters"]         = "iters"; 
300 }
301 /***********************************************************************/
302 void ValidParameters::initialRarefactshared() {
303         rarefactshared["label"]         = "label"; 
304         rarefactshared["line"]          = "line";
305         rarefactshared["jumble"]        = "jumble";
306         rarefactshared["calc"]          = "calc";
307         rarefactshared["iters"]         = "iters"; 
308 }
309 /***********************************************************************/
310 void ValidParameters::initialSummarysingle() {
311         summarysingle["label"]          = "label"; 
312         summarysingle["line"]           = "line";
313         summarysingle["calc"]           = "calc";
314 }
315 /***********************************************************************/
316 void ValidParameters::initialSummaryshared() {
317         summaryshared["label"]          = "label"; 
318         summaryshared["line"]           = "line";
319         summaryshared["calc"]           = "calc";
320         summaryshared["jumble"]         = "jumble";
321
322 }
323 /***********************************************************************/
324 void ValidParameters::initialUnifracweighted() {
325         unifracweighted["iters"]                = "iters"; 
326         unifracweighted["groups"]               = "groups";
327 }
328 /***********************************************************************/
329 void ValidParameters::initialUnifracunweighted() {
330         unifracunweighted["iters"]              = "iters"; 
331         unifracunweighted["groups"]             = "groups";
332 }
333 /***********************************************************************/
334 void ValidParameters::initialLibshuff() {
335         libshuff["cutoff"]              = "cutoff"; 
336         libshuff["iters"]               = "iters"; 
337         libshuff["groups"]              = "groups";
338         libshuff["step"]                = "step";
339         libshuff["form"]                = "form";
340 }
341 /***********************************************************************/