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