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