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