]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
*** empty log message ***
[mothur.git] / validcalculator.cpp
1 /*
2  *  validcalculator.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 "validcalculator.h"
11
12 /********************************************************************/
13 ValidCalculators::ValidCalculators() {
14         try {
15                  initialSingle();
16                  initialShared();
17                  initialRarefaction();
18                  initialSharedRarefact();
19                  initialSummary();
20                  initialSharedSummary();
21                  initialVennSingle();
22                  initialVennShared();
23                  initialTreeGroups();
24                  initialBoot();
25         }
26         catch(exception& e) {
27                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28                 exit(1);
29         }
30         catch(...) {
31                 cout << "An unknown error has occurred in the ValidCalculator class function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
32                 exit(1);
33         }                
34 }
35
36 /********************************************************************/
37
38 ValidCalculators::~ValidCalculators() {}
39
40 /********************************************************************/
41
42 bool ValidCalculators::isValidCalculator(string parameter, string calculator) {
43         try {   
44                 //are you looking for a calculator for a single parameter
45                 if (parameter == "single") {
46                         //is it valid
47                         if ((single.find(calculator)) != (single.end())) {
48                                 return true;
49                         }else { 
50                                 cout << calculator << " is not a valid estimator for the collect.single command and will be disregarded. Valid estimators are ";
51                                 for (it = single.begin(); it != single.end(); it++) {
52                                         cout << it->first << ", ";
53                                 }
54                                 cout << endl;
55                                 return false; }
56                 //are you looking for a calculator for a shared parameter
57                 }else if (parameter == "shared") {
58                         //is it valid
59                         if ((shared.find(calculator)) != (shared.end())) {
60                                 return true;
61                         }else { 
62                                 cout << calculator << " is not a valid estimator for the collect.shared command and will be disregarded.  Valid estimators are ";
63                                 for (it = shared.begin(); it != shared.end(); it++) {
64                                         cout << it->first << ", ";
65                                 }
66                                 cout << endl;
67                                 return false; }
68                 //are you looking for a calculator for a rarefaction parameter
69                 }else if (parameter == "rarefaction") {
70                         //is it valid
71                         if ((rarefaction.find(calculator)) != (rarefaction.end())) {
72                                 return true;
73                         }else { 
74                                 cout << calculator << " is not a valid estimator for the rarefaction.single command and will be disregarded. Valid estimators are ";
75                                 for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
76                                         cout << it->first << ", ";
77                                 }
78                                 cout << endl;
79                                 return false; }
80                 //are you looking for a calculator for a summary parameter
81                 }else if (parameter == "summary") {
82                         //is it valid
83                         if ((summary.find(calculator)) != (summary.end())) {
84                                 return true;
85                         }else { 
86                                 cout << calculator << " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are ";
87                                 for (it = summary.begin(); it != summary.end(); it++) {
88                                         cout << it->first << ", ";
89                                 }
90                                 cout << endl;
91                                 return false; }
92                 //are you looking for a calculator for a sharedsummary parameter
93                 }else if (parameter == "sharedsummary") {
94                         //is it valid
95                         if ((sharedsummary.find(calculator)) != (sharedsummary.end())) {
96                                 return true;
97                         }else { 
98                                 cout << calculator << " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are ";
99                                 for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
100                                         cout << it->first << ", ";
101                                 }
102                                 cout << endl;
103                                 return false; }
104                 }else if (parameter == "sharedrarefaction") {
105                         //is it valid
106                         if ((sharedrarefaction.find(calculator)) != (sharedrarefaction.end())) {
107                                 return true;
108                         }else { 
109                                 cout << calculator << " is not a valid estimator for the rarefaction.shared command and will be disregarded. Valid estimator is ";
110                                 for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
111                                         cout << it->first << ", ";
112                                 }
113                                 cout << endl;
114                                 return false; }
115                 }else if (parameter == "vennsingle") {
116                         //is it valid
117                         if ((vennsingle.find(calculator)) != (vennsingle.end())) {
118                                 return true;
119                         }else { 
120                                 cout << calculator << " is not a valid estimator for the venn command in single mode and will be disregarded. Valid estimators are ";
121                                 for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
122                                         cout << it->first << ", ";
123                                 }
124                                 cout << endl;
125                                 return false; }
126                 }else if (parameter == "vennshared") {
127                         //is it valid
128                         if ((vennshared.find(calculator)) != (vennshared.end())) {
129                                 return true;
130                         }else { 
131                                 cout << calculator << " is not a valid estimator for the venn command in shared mode and will be disregarded. Valid estimators are ";
132                                 for (it = vennshared.begin(); it != vennshared.end(); it++) {
133                                         cout << it->first << ", ";
134                                 }
135                                 cout << endl;
136                                 return false; }
137                 }else if (parameter == "treegroup") {
138                         //is it valid
139                         if ((treegroup.find(calculator)) != (treegroup.end())) {
140                                 return true;
141                         }else { 
142                                 cout << calculator << " is not a valid estimator for the tree.shared command in shared mode and will be disregarded. Valid estimators are ";
143                                 for (it = treegroup.begin(); it != treegroup.end(); it++) {
144                                         cout << it->first << ", ";
145                                 }
146                                 cout << endl;
147                                 return false; }
148                 }else if (parameter == "boot") {
149                         //is it valid
150                         if ((boot.find(calculator)) != (boot.end())) {
151                                 return true;
152                         }else { 
153                                 cout << calculator << " is not a valid estimator for the bootstrap.shared command in shared mode and will be disregarded. Valid estimators are ";
154                                 for (it = boot.begin(); it != boot.end(); it++) {
155                                         cout << it->first << ", ";
156                                 }
157                                 cout << endl;
158                                 return false; }
159                 //not a valid parameter
160                 }else { return false; }
161                 
162         }
163         catch(exception& e) {
164                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function isValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165                 exit(1);
166         }
167         catch(...) {
168                 cout << "An unknown error has occurred in the ValidCalculator class function isValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
169                 exit(1);
170         }       
171 }
172
173 /********************************************************************/
174 void ValidCalculators::initialSingle() {
175         try {   
176                 single["sobs"]          = "sobs";
177                 single["chao"]              = "chao";
178                 single["ace"]               = "ace";
179                 single["jack"]              = "jack";
180                 single["shannon"]           = "shannon";
181                 single["npshannon"]     = "npshannon";
182                 single["simpson"]           = "simpson";
183                 single["bergerparker"]  = "bergerparker";
184                 single["bootstrap"]     = "bootstrap";
185                 single["geometric"]     = "geometric";
186                 single["logseries"]         = "logseries";
187                 single["qstat"]         = "qstat";
188                 single["bstick"]        = "bstick";
189                 single["goodscoverage"] = "goodscoverage";
190                 single["nseqs"]                 = "nseqs";
191                 single["coverage"]              = "coverage";
192                 single["default"]           = "default";
193         }
194         catch(exception& e) {
195                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
196                 exit(1);
197         }
198         catch(...) {
199                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
200                 exit(1);
201         }       
202 }
203
204 /********************************************************************/
205 void ValidCalculators::initialShared() {
206         try {   
207                 shared["sharedsobs"]                    = "sharedsobs";
208                 shared["sharedchao"]                    = "sharedchao";
209                 shared["sharedace"]                             = "sharedace";
210                 shared["jabund"]                                = "jabund";
211                 shared["sorabund"]                      = "sorabund";
212                 shared["jclass"]                                = "jclass";
213                 shared["sorclass"]                              = "sorclass";
214                 shared["jest"]                                  = "jest";
215                 shared["sorest"]                                = "sorest";
216                 shared["thetayc"]                               = "thetayc";
217                 shared["thetan"]                                = "thetan";
218                 shared["kstest"]                                = "kstest";
219                 shared["whittaker"]                         = "whittaker";
220                 shared["sharednseqs"]                   = "sharednseqs";
221                 shared["ochiai"]                                = "ochiai";
222                 shared["anderberg"]                             = "anderberg";
223                 shared["kulczynski"]                    = "kulczynski";
224                 shared["kulczynskicody"]                = "kulczynskicody";
225                 shared["lennon"]                                = "lennon";
226                 shared["morisitahorn"]                  = "morisitahorn";
227                 shared["braycurtis"]                    = "braycurtis";
228                 shared["default"]                   = "default";
229         }
230         catch(exception& e) {
231                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
232                 exit(1);
233         }
234         catch(...) {
235                 cout << "An unknown error has occurred in the ValidCalculator class function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
236                 exit(1);
237         }       
238 }
239
240 /********************************************************************/
241 void ValidCalculators::initialRarefaction() {
242         try {   
243                 rarefaction["sobs"]                     = "sobs";
244                 rarefaction["chao"]                     = "chao";
245                 rarefaction["ace"]                      = "ace";
246                 rarefaction["jack"]                     = "jack";
247                 rarefaction["shannon"]          = "shannon";
248                 rarefaction["npshannon"]        = "npshannon";
249                 rarefaction["simpson"]          = "simpson";
250                 rarefaction["bootstrap"]        = "bootstrap";
251                 rarefaction["nseqs"]            = "nseqs";
252                 rarefaction["coverage"]         = "coverage";
253                 rarefaction["default"]      = "default";
254         }
255         catch(exception& e) {
256                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
257                 exit(1);
258         }
259         catch(...) {
260                 cout << "An unknown error has occurred in the ValidCalculator class function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
261                 exit(1);
262         }       
263 }
264
265 /********************************************************************/
266
267 void ValidCalculators::initialSummary() {
268         try {   
269                 summary["sobs"]                 = "sobs";
270                 summary["chao"]                 = "chao";
271                 summary["ace"]                  = "ace";
272                 summary["jack"]                 = "jack";
273                 summary["shannon"]              = "shannon";
274                 summary["npshannon"]    = "npshannon";
275                 summary["simpson"]              = "simpson";
276                 summary["bergerparker"] = "bergerparker";
277                 summary["geometric"]    = "geometric";
278                 summary["bootstrap"]    = "bootstrap";
279                 summary["logseries"]    = "logseries";
280                 summary["qstat"]        = "qstat";
281                 summary["bstick"]       = "bstick";
282                 summary["nseqs"]                = "nseqs";
283                 summary["goodscoverage"]= "goodscoverage";
284                 summary["coverage"]             = "coverage";
285                 summary["default"]          = "default";
286         }
287         catch(exception& e) {
288                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
289                 exit(1);
290         }
291         catch(...) {
292                 cout << "An unknown error has occurred in the ValidCalculator class function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
293                 exit(1);
294         }       
295 }
296
297 /********************************************************************/
298 void ValidCalculators::initialSharedSummary() {
299         try {   
300                 sharedsummary["sharedsobs"]                             = "sharedsobs";
301                 sharedsummary["sharedchao"]                             = "sharedchao";
302                 sharedsummary["sharedace"]                              = "sharedace";
303                 sharedsummary["jabund"]                                 = "jabund";
304                 sharedsummary["sorabund"]                       = "sorabund";
305                 sharedsummary["jclass"]                                 = "jclass";
306                 sharedsummary["sorclass"]                               = "sorclass";
307                 sharedsummary["jest"]                                   = "jest";
308                 sharedsummary["sorest"]                                 = "sorest";
309                 sharedsummary["thetayc"]                                = "thetayc";
310                 sharedsummary["thetan"]                                 = "thetan";
311                 sharedsummary["kstest"]                                 = "kstest";
312                 sharedsummary["whittaker"]                              = "whittaker";
313                 sharedsummary["sharednseqs"]                    = "sharednseqs";
314                 sharedsummary["ochiai"]                                 = "ochiai";
315                 sharedsummary["anderberg"]                              = "anderberg";
316                 sharedsummary["kulczynski"]                             = "kulczynski";
317                 sharedsummary["kulczynskicody"]                 = "kulczynskicody";
318                 sharedsummary["lennon"]                                 = "lennon";
319                 sharedsummary["morisitahorn"]                   = "morisitahorn";
320                 sharedsummary["braycurtis"]                             = "braycurtis";
321                 sharedsummary["default"]                                = "default";
322         }
323         catch(exception& e) {
324                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
325                 exit(1);
326         }
327         catch(...) {
328                 cout << "An unknown error has occurred in the ValidCalculator class function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
329                 exit(1);
330         }       
331 }
332
333
334 /********************************************************************/
335
336 void ValidCalculators::initialSharedRarefact() {
337         try {   
338                 sharedrarefaction["sharedobserved"]     = "sharedobserved";
339                 sharedrarefaction["sharednseqs"]        = "sharednseqs";
340                 sharedrarefaction["default"]        = "default";
341         }
342         catch(exception& e) {
343                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedRarefact. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
344                 exit(1);
345         }
346         catch(...) {
347                 cout << "An unknown error has occurred in the ValidCalculator class function initialSharedRarefact. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
348                 exit(1);
349         }       
350 }
351
352
353 /********************************************************************/
354 void ValidCalculators::initialVennSingle() {
355         try {
356                 vennsingle["sobs"]              = "sobs";
357                 vennsingle["chao"]                  = "chao";
358                 vennsingle["ace"]                       = "ace";
359                 vennsingle["jack"]                  = "jack";
360                 vennsingle["default"]           = "default";
361         }
362         catch(exception& e) {
363                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
364                 exit(1);
365         }
366         catch(...) {
367                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368                 exit(1);
369         }       
370 }
371
372 /********************************************************************/
373 void ValidCalculators::initialVennShared() {
374         try {
375                 vennshared["sharedsobs"]        = "sharedsobs";
376                 vennshared["sharedchao"]        = "sharedchao";
377                 vennshared["sharedace"]         = "sharedace";
378                 vennshared["default"]           = "default";
379         }
380         catch(exception& e) {
381                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
382                 exit(1);
383         }
384         catch(...) {
385                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
386                 exit(1);
387         }       
388 }
389
390 /********************************************************************/
391 void ValidCalculators::initialTreeGroups() {
392         try {   
393                 treegroup["jabund"]                                     = "jabund";
394                 treegroup["sorabund"]                   = "sorabund";
395                 treegroup["jclass"]                                     = "jclass";
396                 treegroup["sorclass"]                           = "sorclass";
397                 treegroup["jest"]                                       = "jest";
398                 treegroup["sorest"]                                     = "sorest";
399                 treegroup["thetayc"]                            = "thetayc";
400                 treegroup["thetan"]                                     = "thetan";
401                 treegroup["morisitahorn"]                       = "morisitahorn";
402                 treegroup["braycurtis"]                 = "braycurtis";
403         }
404         catch(exception& e) {
405                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
406                 exit(1);
407         }
408         catch(...) {
409                 cout << "An unknown error has occurred in the ValidCalculator class function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
410                 exit(1);
411         }       
412 }
413 /********************************************************************/
414 void ValidCalculators::initialBoot() {
415         try {   
416                 boot["jabund"]                          = "jabund";
417                 boot["sorabund"]                = "sorabund";
418                 boot["jclass"]                          = "jclass";
419                 boot["sorclass"]                        = "orclass";
420                 boot["jest"]                            = "jest";
421                 boot["sorest"]                          = "sorest";
422                 boot["thetayc"]                         = "thetayc";
423                 boot["thetan"]                          = "thetan";
424                 boot["morisitahorn"]            = "morisitahorn";
425                 boot["braycurtis"]                      = "braycurtis";
426         }
427         catch(exception& e) {
428                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
429                 exit(1);
430         }
431         catch(...) {
432                 cout << "An unknown error has occurred in the ValidCalculator class function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
433                 exit(1);
434         }       
435 }
436
437 /********************************************************************/
438 void ValidCalculators::printCalc(string parameter, ostream& out) {
439         try{
440                 out << "The available estimators for calc are ";
441                 //are you looking for a calculator for a single parameter
442                 if (parameter == "single") {
443                         for (it = single.begin(); it != single.end(); it++) {
444                                 out << it->first << ", ";
445                         }
446                 //are you looking for a calculator for a shared parameter
447                 }else if (parameter == "shared") {
448                         for (it = shared.begin(); it != shared.end(); it++) {
449                                 out << it->first << ", ";
450                         }
451                 //are you looking for a calculator for a rarefaction parameter
452                 }else if (parameter == "rarefaction") {
453                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
454                                 out << it->first << ", ";
455                         }
456                 //are you looking for a calculator for a summary parameter
457                 }else if (parameter == "summary") {
458                         for (it = summary.begin(); it != summary.end(); it++) {
459                                 out << it->first << ", ";
460                         }
461                 //are you looking for a calculator for a sharedsummary parameter
462                 }else if (parameter == "sharedsummary") {
463                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
464                                 out << it->first << ", ";
465                         }
466                 }else if (parameter == "sharedrarefaction") {
467                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
468                                 out << it->first << ", ";
469                         }
470                 }else if (parameter == "vennsingle") {
471                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
472                                 out << it->first << ", ";
473                         }
474                 }else if (parameter == "vennshared") {
475                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
476                                 out << it->first << ", ";
477                         }
478                 }else if (parameter == "treegroup") {
479                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
480                                 out << it->first << ", ";
481                         }
482                 }else if (parameter == "boot") {
483                         for (it = boot.begin(); it != boot.end(); it++) {
484                                 out << it->first << ", ";
485                         }
486                 }
487                 out << endl;
488         }
489         catch(exception& e) {
490                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
491                 exit(1);
492         }
493         catch(...) {
494                 cout << "An unknown error has occurred in the ValidCalculator class function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
495                 exit(1);
496         }       
497
498 }
499 /********************************************************************/
500