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