]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
added shen calculator
[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["efron"]         = "efron";
205                 single["boneh"]         = "boneh";
206                 single["solow"]         = "solow";
207                 single["shen"]          = "shen";
208                 single["default"]           = "default";
209         }
210         catch(exception& e) {
211                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
212                 exit(1);
213         }
214         catch(...) {
215                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
216                 exit(1);
217         }       
218 }
219
220 /********************************************************************/
221 void ValidCalculators::initialShared() {
222         try {   
223                 shared["sharedsobs"]                    = "sharedsobs";
224                 shared["sharedchao"]                    = "sharedchao";
225                 shared["sharedace"]                             = "sharedace";
226                 shared["jabund"]                                = "jabund";
227                 shared["sorabund"]                              = "sorabund";
228                 shared["jclass"]                                = "jclass";
229                 shared["sorclass"]                              = "sorclass";
230                 shared["jest"]                                  = "jest";
231                 shared["sorest"]                                = "sorest";
232                 shared["thetayc"]                               = "thetayc";
233                 shared["thetan"]                                = "thetan";
234                 shared["kstest"]                                = "kstest";
235                 shared["whittaker"]                         = "whittaker";
236                 shared["sharednseqs"]                   = "sharednseqs";
237                 shared["ochiai"]                                = "ochiai";
238                 shared["anderberg"]                             = "anderberg";
239                 shared["kulczynski"]                    = "kulczynski";
240                 shared["kulczynskicody"]                = "kulczynskicody";
241                 shared["lennon"]                                = "lennon";
242                 shared["morisitahorn"]                  = "morisitahorn";
243                 shared["braycurtis"]                    = "braycurtis";
244                 shared["default"]                   = "default";
245         }
246         catch(exception& e) {
247                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
248                 exit(1);
249         }
250         catch(...) {
251                 cout << "An unknown error has occurred in the ValidCalculator class function initialShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
252                 exit(1);
253         }       
254 }
255
256 /********************************************************************/
257 void ValidCalculators::initialRarefaction() {
258         try {   
259                 rarefaction["sobs"]                     = "sobs";
260                 rarefaction["chao"]                     = "chao";
261                 rarefaction["ace"]                      = "ace";
262                 rarefaction["jack"]                     = "jack";
263                 rarefaction["shannon"]          = "shannon";
264                 rarefaction["npshannon"]        = "npshannon";
265                 rarefaction["simpson"]          = "simpson";
266                 rarefaction["bootstrap"]        = "bootstrap";
267                 rarefaction["nseqs"]            = "nseqs";
268                 rarefaction["coverage"]         = "coverage";
269                 rarefaction["default"]      = "default";
270         }
271         catch(exception& e) {
272                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
273                 exit(1);
274         }
275         catch(...) {
276                 cout << "An unknown error has occurred in the ValidCalculator class function initialRarefaction. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
277                 exit(1);
278         }       
279 }
280
281 /********************************************************************/
282
283 void ValidCalculators::initialSummary() {
284         try {   
285                 summary["sobs"]                 = "sobs";
286                 summary["chao"]                 = "chao";
287                 summary["ace"]                  = "ace";
288                 summary["jack"]                 = "jack";
289                 summary["shannon"]              = "shannon";
290                 summary["npshannon"]    = "npshannon";
291                 summary["simpson"]              = "simpson";
292                 summary["bergerparker"] = "bergerparker";
293                 summary["geometric"]    = "geometric";
294                 summary["bootstrap"]    = "bootstrap";
295                 summary["logseries"]    = "logseries";
296                 summary["qstat"]        = "qstat";
297                 summary["bstick"]       = "bstick";
298                 summary["nseqs"]                = "nseqs";
299                 summary["goodscoverage"]= "goodscoverage";
300                 summary["coverage"]             = "coverage";
301                 summary["efron"]        = "efron";
302                 summary["boneh"]        = "boneh";
303                 summary["solow"]        = "solow";
304                 summary["shen"]         = "shen";
305                 summary["default"]          = "default";
306         }
307         catch(exception& e) {
308                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
309                 exit(1);
310         }
311         catch(...) {
312                 cout << "An unknown error has occurred in the ValidCalculator class function initialSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
313                 exit(1);
314         }       
315 }
316
317 /********************************************************************/
318 void ValidCalculators::initialSharedSummary() {
319         try {   
320                 sharedsummary["sharedsobs"]                             = "sharedsobs";
321                 sharedsummary["sharedchao"]                             = "sharedchao";
322                 sharedsummary["sharedace"]                              = "sharedace";
323                 sharedsummary["jabund"]                                 = "jabund";
324                 sharedsummary["sorabund"]                       = "sorabund";
325                 sharedsummary["jclass"]                                 = "jclass";
326                 sharedsummary["sorclass"]                               = "sorclass";
327                 sharedsummary["jest"]                                   = "jest";
328                 sharedsummary["sorest"]                                 = "sorest";
329                 sharedsummary["thetayc"]                                = "thetayc";
330                 sharedsummary["thetan"]                                 = "thetan";
331                 sharedsummary["kstest"]                                 = "kstest";
332                 sharedsummary["whittaker"]                              = "whittaker";
333                 sharedsummary["sharednseqs"]                    = "sharednseqs";
334                 sharedsummary["ochiai"]                                 = "ochiai";
335                 sharedsummary["anderberg"]                              = "anderberg";
336                 sharedsummary["kulczynski"]                             = "kulczynski";
337                 sharedsummary["kulczynskicody"]                 = "kulczynskicody";
338                 sharedsummary["lennon"]                                 = "lennon";
339                 sharedsummary["morisitahorn"]                   = "morisitahorn";
340                 sharedsummary["braycurtis"]                             = "braycurtis";
341                 sharedsummary["default"]                                = "default";
342         }
343         catch(exception& e) {
344                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
345                 exit(1);
346         }
347         catch(...) {
348                 cout << "An unknown error has occurred in the ValidCalculator class function initialSharedSummary. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
349                 exit(1);
350         }       
351 }
352
353
354 /********************************************************************/
355
356 void ValidCalculators::initialSharedRarefact() {
357         try {   
358                 sharedrarefaction["sharedobserved"]     = "sharedobserved";
359                 sharedrarefaction["sharednseqs"]        = "sharednseqs";
360                 sharedrarefaction["default"]        = "default";
361         }
362         catch(exception& e) {
363                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSharedRarefact. 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 initialSharedRarefact. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368                 exit(1);
369         }       
370 }
371
372
373 /********************************************************************/
374 void ValidCalculators::initialVennSingle() {
375         try {
376                 vennsingle["sobs"]              = "sobs";
377                 vennsingle["chao"]                  = "chao";
378                 vennsingle["ace"]                       = "ace";
379                 vennsingle["jack"]                  = "jack";
380                 vennsingle["default"]           = "default";
381         }
382         catch(exception& e) {
383                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
384                 exit(1);
385         }
386         catch(...) {
387                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
388                 exit(1);
389         }       
390 }
391
392 /********************************************************************/
393 void ValidCalculators::initialVennShared() {
394         try {
395                 vennshared["sharedsobs"]        = "sharedsobs";
396                 vennshared["sharedchao"]        = "sharedchao";
397                 vennshared["sharedace"]         = "sharedace";
398                 vennshared["default"]           = "default";
399         }
400         catch(exception& e) {
401                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
402                 exit(1);
403         }
404         catch(...) {
405                 cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
406                 exit(1);
407         }       
408 }
409
410 /********************************************************************/
411 void ValidCalculators::initialTreeGroups() {
412         try {   
413                 treegroup["jabund"]                                     = "jabund";
414                 treegroup["sorabund"]                           = "sorabund";
415                 treegroup["jclass"]                                     = "jclass";
416                 treegroup["sorclass"]                           = "sorclass";
417                 treegroup["jest"]                                       = "jest";
418                 treegroup["sorest"]                                     = "sorest";
419                 treegroup["thetayc"]                            = "thetayc";
420                 treegroup["thetan"]                                     = "thetan";
421                 treegroup["morisitahorn"]                       = "morisitahorn";
422                 treegroup["braycurtis"]                         = "braycurtis";
423         }
424         catch(exception& e) {
425                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
426                 exit(1);
427         }
428         catch(...) {
429                 cout << "An unknown error has occurred in the ValidCalculator class function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
430                 exit(1);
431         }       
432 }
433 /********************************************************************/
434 void ValidCalculators::initialBoot() {
435         try {   
436                 boot["jabund"]                          = "jabund";
437                 boot["sorabund"]                        = "sorabund";
438                 boot["jclass"]                          = "jclass";
439                 boot["sorclass"]                        = "orclass";
440                 boot["jest"]                            = "jest";
441                 boot["sorest"]                          = "sorest";
442                 boot["thetayc"]                         = "thetayc";
443                 boot["thetan"]                          = "thetan";
444                 boot["morisitahorn"]            = "morisitahorn";
445                 boot["braycurtis"]                      = "braycurtis";
446         }
447         catch(exception& e) {
448                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
449                 exit(1);
450         }
451         catch(...) {
452                 cout << "An unknown error has occurred in the ValidCalculator class function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
453                 exit(1);
454         }       
455 }
456 /********************************************************************/
457 void ValidCalculators::initialDistance() {
458         try {   
459                 distance["nogaps"]              = "nogaps";
460                 distance["eachgap"]             = "eachgap";
461                 distance["onegap"]              = "onegap";
462         }
463         catch(exception& e) {
464                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialDistance. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
465                 exit(1);
466         }
467         catch(...) {
468                 cout << "An unknown error has occurred in the ValidCalculator class function initialDistance. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
469                 exit(1);
470         }       
471 }
472
473 /********************************************************************/
474 void ValidCalculators::printCalc(string parameter, ostream& out) {
475         try{
476                 out << "The available estimators for calc are ";
477                 //are you looking for a calculator for a single parameter
478                 if (parameter == "single") {
479                         for (it = single.begin(); it != single.end(); it++) {
480                                 out << it->first << ", ";
481                         }
482                 //are you looking for a calculator for a shared parameter
483                 }else if (parameter == "shared") {
484                         for (it = shared.begin(); it != shared.end(); it++) {
485                                 out << it->first << ", ";
486                         }
487                 //are you looking for a calculator for a rarefaction parameter
488                 }else if (parameter == "rarefaction") {
489                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
490                                 out << it->first << ", ";
491                         }
492                 //are you looking for a calculator for a summary parameter
493                 }else if (parameter == "summary") {
494                         for (it = summary.begin(); it != summary.end(); it++) {
495                                 out << it->first << ", ";
496                         }
497                 //are you looking for a calculator for a sharedsummary parameter
498                 }else if (parameter == "sharedsummary") {
499                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
500                                 out << it->first << ", ";
501                         }
502                 }else if (parameter == "sharedrarefaction") {
503                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
504                                 out << it->first << ", ";
505                         }
506                 }else if (parameter == "vennsingle") {
507                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
508                                 out << it->first << ", ";
509                         }
510                 }else if (parameter == "vennshared") {
511                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
512                                 out << it->first << ", ";
513                         }
514                 }else if (parameter == "treegroup") {
515                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
516                                 out << it->first << ", ";
517                         }
518                 }else if (parameter == "boot") {
519                         for (it = boot.begin(); it != boot.end(); it++) {
520                                 out << it->first << ", ";
521                         }
522                 }else if (parameter == "distance") {
523                         for (it = distance.begin(); it != distance.end(); it++) {
524                                 out << it->first << ", ";
525                         }
526                 }
527
528                 out << endl;
529         }
530         catch(exception& e) {
531                 cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
532                 exit(1);
533         }
534         catch(...) {
535                 cout << "An unknown error has occurred in the ValidCalculator class function printCalc. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
536                 exit(1);
537         }       
538
539 }
540 /********************************************************************/
541