]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
added mothur executable to cvs
[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                  m = MothurOut::getInstance();
16                 
17                  initialSingle();
18                  initialShared();
19                  initialRarefaction();
20                  initialSharedRarefact();
21                  initialSummary();
22                  initialSharedSummary();
23                  initialVennSingle();
24                  initialVennShared();
25                  initialTreeGroups();
26                  initialBoot();
27                  initialDistance();
28                  initialMatrix();
29                  initialHeat();
30         }
31         catch(exception& e) {
32                 m->errorOut(e, "ValidCalculator", "ValidCalculator");
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
54                                 }
55                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
66                                 }
67                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
78                                 }
79                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
90                                 }
91                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
102                                 }
103                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
113                                 }
114                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
124                                 }
125                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
135                                 }
136                                 m->mothurOutEndLine();
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                                 m->mothurOut(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                                         m->mothurOut(it->first + ", ");
146                                 }
147                                 m->mothurOutEndLine();
148                                 return false; }
149                 }else if (parameter == "matrix") {
150                         //is it valid
151                         if ((matrix.find(calculator)) != (matrix.end())) {
152                                 return true;
153                         }else { 
154                                 m->mothurOut(calculator +  " is not a valid estimator for the matrix.output command and will be disregarded. Valid estimators are ");
155                                 for (it = matrix.begin(); it != matrix.end(); it++) {
156                                         m->mothurOut(it->first + ", ");
157                                 }
158                                 m->mothurOutEndLine();
159                                 return false; }
160                 }else if (parameter == "heat") {
161                         //is it valid
162                         if ((heat.find(calculator)) != (heat.end())) {
163                                 return true;
164                         }else { 
165                                 m->mothurOut(calculator + " is not a valid estimator for the heatmap.sim command and will be disregarded. Valid estimators are ");
166                                 for (it = heat.begin(); it != heat.end(); it++) {
167                                         m->mothurOut(it->first + ", ");
168                                 }
169                                 m->mothurOutEndLine();
170                                 return false; }
171                 }else if (parameter == "boot") {
172                         //is it valid
173                         if ((boot.find(calculator)) != (boot.end())) {
174                                 return true;
175                         }else { 
176                                 m->mothurOut(calculator + " is not a valid estimator for the bootstrap.shared command and will be disregarded. Valid estimators are ");
177                                 for (it = boot.begin(); it != boot.end(); it++) {
178                                         m->mothurOut(it->first + ", ");
179                                 }
180                                 m->mothurOutEndLine();
181                                 return false; }
182                 }else if (parameter == "distance") {
183                         //is it valid
184                         if ((distance.find(calculator)) != (distance.end())) {
185                                 return true;
186                         }else { 
187                                 m->mothurOut(calculator +  " is not a valid estimator for the distance command and will be disregarded. Valid calculators are ");
188                                 for (it = distance.begin(); it != distance.end(); it++) {
189                                         m->mothurOut(it->first + ", ");
190                                 }
191                                 m->mothurOutEndLine();
192                                 return false; }
193                 //not a valid parameter
194                 }else { return false; }
195                 
196         }
197         catch(exception& e) {
198                 m->errorOut(e, "ValidCalculator", "isValidCalculator");
199                 exit(1);
200         }
201 }
202
203 /********************************************************************/
204 void ValidCalculators::initialSingle() {
205         try {   
206                 single["sobs"]          = "sobs";
207                 single["chao"]              = "chao";
208                 single["ace"]               = "ace";
209                 single["jack"]              = "jack";
210                 single["shannon"]           = "shannon";
211                 single["npshannon"]     = "npshannon";
212                 single["shannoneven"]   = "shannoneven";
213                 single["smithwilson"]   = "smithwilson";
214                 single["heip"]                  = "heip";
215                 single["simpson"]           = "simpson";
216                 single["simpsoneven"]   = "simpsoneven";
217                 single["invsimpson"]    = "invsimpson";
218                 single["bergerparker"]  = "bergerparker";
219                 single["bootstrap"]     = "bootstrap";
220                 single["geometric"]     = "geometric";
221                 single["logseries"]             = "logseries";
222                 single["qstat"]         = "qstat";
223                 single["bstick"]        = "bstick";
224                 single["goodscoverage"] = "goodscoverage";
225                 single["nseqs"]                 = "nseqs";
226                 single["coverage"]              = "coverage";
227                 single["efron"]         = "efron";
228                 single["boneh"]         = "boneh";
229                 single["solow"]         = "solow";
230                 single["shen"]          = "shen";
231                 single["default"]           = "default";
232         }
233         catch(exception& e) {
234                 m->errorOut(e, "ValidCalculator", "initialSingle");
235                 exit(1);
236         }
237 }
238
239 /********************************************************************/
240 void ValidCalculators::initialShared() {
241         try {   
242                 shared["sharedsobs"]                    = "sharedsobs";
243                 shared["sharedchao"]                    = "sharedchao";
244                 shared["sharedace"]                             = "sharedace";
245                 shared["jabund"]                                = "jabund";
246                 shared["sorabund"]                              = "sorabund";
247                 shared["jclass"]                                = "jclass";
248                 shared["sorclass"]                              = "sorclass";
249                 shared["jest"]                                  = "jest";
250                 shared["sorest"]                                = "sorest";
251                 shared["thetayc"]                               = "thetayc";
252                 shared["thetan"]                                = "thetan";
253                 shared["kstest"]                                = "kstest";
254                 shared["whittaker"]                         = "whittaker";
255                 shared["sharednseqs"]                   = "sharednseqs";
256                 shared["ochiai"]                                = "ochiai";
257                 shared["anderberg"]                             = "anderberg";
258                 shared["kulczynski"]                    = "kulczynski";
259                 shared["kulczynskicody"]                = "kulczynskicody";
260                 shared["lennon"]                                = "lennon";
261                 shared["morisitahorn"]                  = "morisitahorn";
262                 shared["braycurtis"]                    = "braycurtis";
263                 shared["default"]                   = "default";
264         }
265         catch(exception& e) {
266                 m->errorOut(e, "ValidCalculator", "initialShared");
267                 exit(1);
268         }
269 }
270
271 /********************************************************************/
272 void ValidCalculators::initialRarefaction() {
273         try {   
274                 rarefaction["sobs"]                     = "sobs";
275                 rarefaction["chao"]                     = "chao";
276                 rarefaction["ace"]                      = "ace";
277                 rarefaction["jack"]                     = "jack";
278                 rarefaction["shannon"]          = "shannon";
279                 rarefaction["smithwilson"]      = "smithwilson";
280                 rarefaction["heip"]                     = "heip";
281                 rarefaction["npshannon"]        = "npshannon";
282                 rarefaction["shannoneven"]      = "shannoneven";
283                 rarefaction["simpson"]          = "simpson";
284                 rarefaction["invsimpson"]       = "invsimpson";
285                 rarefaction["simpsoneven"]      = "simpsoneven";
286                 rarefaction["bootstrap"]        = "bootstrap";
287                 rarefaction["nseqs"]            = "nseqs";
288                 rarefaction["coverage"]         = "coverage";
289                 rarefaction["default"]      = "default";
290         }
291         catch(exception& e) {
292                 m->errorOut(e, "ValidCalculator", "initialRarefaction");
293                 exit(1);
294         }
295 }
296
297 /********************************************************************/
298
299 void ValidCalculators::initialSummary() {
300         try {   
301                 summary["sobs"]                 = "sobs";
302                 summary["chao"]                 = "chao";
303                 summary["ace"]                  = "ace";
304                 summary["jack"]                 = "jack";
305                 summary["shannon"]              = "shannon";
306                 summary["heip"]                 = "heip";
307                 summary["shannoneven"]  = "shannoneven";
308                 summary["smithwilson"]  = "smithwilson";
309                 summary["invsimpson"]   = "invsimpson";
310                 summary["npshannon"]    = "npshannon";
311                 summary["simpson"]              = "simpson";
312                 summary["simpsoneven"]  = "simpsoneven";
313                 summary["bergerparker"] = "bergerparker";
314                 summary["geometric"]    = "geometric";
315                 summary["bootstrap"]    = "bootstrap";
316                 summary["logseries"]    = "logseries";
317                 summary["qstat"]        = "qstat";
318                 summary["bstick"]       = "bstick";
319                 summary["nseqs"]                = "nseqs";
320                 summary["goodscoverage"]= "goodscoverage";
321                 summary["coverage"]             = "coverage";
322                 summary["efron"]        = "efron";
323                 summary["boneh"]        = "boneh";
324                 summary["solow"]        = "solow";
325                 summary["shen"]         = "shen";
326                 summary["default"]          = "default";
327         }
328         catch(exception& e) {
329                 m->errorOut(e, "ValidCalculator", "initialSummary");
330                 exit(1);
331         }
332 }
333
334 /********************************************************************/
335 void ValidCalculators::initialSharedSummary() {
336         try {   
337                 sharedsummary["sharedsobs"]                             = "sharedsobs";
338                 sharedsummary["sharedchao"]                             = "sharedchao";
339                 sharedsummary["sharedace"]                              = "sharedace";
340                 sharedsummary["jabund"]                                 = "jabund";
341                 sharedsummary["sorabund"]                       = "sorabund";
342                 sharedsummary["jclass"]                                 = "jclass";
343                 sharedsummary["sorclass"]                               = "sorclass";
344                 sharedsummary["jest"]                                   = "jest";
345                 sharedsummary["sorest"]                                 = "sorest";
346                 sharedsummary["thetayc"]                                = "thetayc";
347                 sharedsummary["thetan"]                                 = "thetan";
348                 sharedsummary["kstest"]                                 = "kstest";
349                 sharedsummary["whittaker"]                              = "whittaker";
350                 sharedsummary["sharednseqs"]                    = "sharednseqs";
351                 sharedsummary["ochiai"]                                 = "ochiai";
352                 sharedsummary["anderberg"]                              = "anderberg";
353                 sharedsummary["kulczynski"]                             = "kulczynski";
354                 sharedsummary["kulczynskicody"]                 = "kulczynskicody";
355                 sharedsummary["lennon"]                                 = "lennon";
356                 sharedsummary["morisitahorn"]                   = "morisitahorn";
357                 sharedsummary["braycurtis"]                             = "braycurtis";
358                 sharedsummary["default"]                                = "default";
359         }
360         catch(exception& e) {
361                 m->errorOut(e, "ValidCalculator", "initialSharedSummary");
362                 exit(1);
363         }
364 }
365
366
367 /********************************************************************/
368
369 void ValidCalculators::initialSharedRarefact() {
370         try {   
371                 sharedrarefaction["sharedobserved"]     = "sharedobserved";
372                 sharedrarefaction["sharednseqs"]        = "sharednseqs";
373                 sharedrarefaction["default"]        = "default";
374         }
375         catch(exception& e) {
376                 m->errorOut(e, "ValidCalculator", "initialSharedRarefact");
377                 exit(1);
378         }
379 }
380
381
382 /********************************************************************/
383 void ValidCalculators::initialVennSingle() {
384         try {
385                 vennsingle["sobs"]              = "sobs";
386                 vennsingle["chao"]                  = "chao";
387                 vennsingle["ace"]                       = "ace";
388                 vennsingle["jack"]                  = "jack";
389                 vennsingle["nseqs"]                 = "nseqs";
390                 vennsingle["default"]           = "default";
391         }
392         catch(exception& e) {
393                 m->errorOut(e, "ValidCalculator", "initialVennSingle");
394                 exit(1);
395         }
396 }
397
398 /********************************************************************/
399 void ValidCalculators::initialVennShared() {
400         try {
401                 vennshared["sharedsobs"]        = "sharedsobs";
402                 vennshared["sharedchao"]        = "sharedchao";
403                 vennshared["sharedace"]         = "sharedace";
404                 vennshared["nseqs"]                     = "nseqs";
405                 vennshared["default"]           = "default";
406         }
407         catch(exception& e) {
408                 m->errorOut(e, "ValidCalculator", "initialVennShared");
409                 exit(1);
410         }
411 }
412
413 /********************************************************************/
414 void ValidCalculators::initialTreeGroups() {
415         try {   
416                 treegroup["jabund"]                                     = "jabund";
417                 treegroup["sorabund"]                           = "sorabund";
418                 treegroup["jclass"]                                     = "jclass";
419                 treegroup["sorclass"]                           = "sorclass";
420                 treegroup["jest"]                                       = "jest";
421                 treegroup["sorest"]                                     = "sorest";
422                 treegroup["thetayc"]                            = "thetayc";
423                 treegroup["thetan"]                                     = "thetan";
424                 treegroup["morisitahorn"]                       = "morisitahorn";
425                 treegroup["braycurtis"]                         = "braycurtis";
426         }
427         catch(exception& e) {
428                 m->errorOut(e, "ValidCalculator", "initialTreeGroups");
429                 exit(1);
430         }
431 }
432 /********************************************************************/
433 void ValidCalculators::initialHeat() {
434         try {   
435                 heat["jabund"]                          = "jabund";
436                 heat["sorabund"]                        = "sorabund";
437                 heat["jclass"]                          = "jclass";
438                 heat["sorclass"]                        = "sorclass";
439                 heat["jest"]                            = "jest";
440                 heat["sorest"]                          = "sorest";
441                 heat["thetayc"]                         = "thetayc";
442                 heat["thetan"]                          = "thetan";
443                 heat["morisitahorn"]            = "morisitahorn";
444                 heat["braycurtis"]                      = "braycurtis";
445         }
446         catch(exception& e) {
447                 m->errorOut(e, "ValidCalculator", "initialHeat");
448                 exit(1);
449         }
450 }
451
452 /********************************************************************/
453 void ValidCalculators::initialMatrix() {
454         try {   
455                 matrix["jabund"]                                = "jabund";
456                 matrix["sorabund"]                              = "sorabund";
457                 matrix["jclass"]                                = "jclass";
458                 matrix["sorclass"]                              = "sorclass";
459                 matrix["jest"]                                  = "jest";
460                 matrix["sorest"]                                = "sorest";
461                 matrix["thetayc"]                               = "thetayc";
462                 matrix["thetan"]                                = "thetan";
463                 matrix["morisitahorn"]                  = "morisitahorn";
464                 matrix["braycurtis"]                    = "braycurtis";
465         }
466         catch(exception& e) {
467                 m->errorOut(e, "ValidCalculator", "initialMatrix");
468                 exit(1);
469         }
470 }
471
472 /********************************************************************/
473 void ValidCalculators::initialBoot() {
474         try {   
475                 boot["jabund"]                          = "jabund";
476                 boot["sorabund"]                        = "sorabund";
477                 boot["jclass"]                          = "jclass";
478                 boot["sorclass"]                        = "orclass";
479                 boot["jest"]                            = "jest";
480                 boot["sorest"]                          = "sorest";
481                 boot["thetayc"]                         = "thetayc";
482                 boot["thetan"]                          = "thetan";
483                 boot["morisitahorn"]            = "morisitahorn";
484                 boot["braycurtis"]                      = "braycurtis";
485         }
486         catch(exception& e) {
487                 m->errorOut(e, "ValidCalculator", "initialBoot");
488                 exit(1);
489         }
490 }
491 /********************************************************************/
492 void ValidCalculators::initialDistance() {
493         try {   
494                 distance["nogaps"]              = "nogaps";
495                 distance["eachgap"]             = "eachgap";
496                 distance["onegap"]              = "onegap";
497         }
498         catch(exception& e) {
499                 m->errorOut(e, "ValidCalculator", "initialDistance");
500                 exit(1);
501         }
502 }
503
504 /********************************************************************/
505 void ValidCalculators::printCalc(string parameter, ostream& out) {
506         try{
507                 out << "The available estimators for calc are ";
508                 //are you looking for a calculator for a single parameter
509                 if (parameter == "single") {
510                         for (it = single.begin(); it != single.end(); it++) {
511                                 out << it->first << ", ";
512                         }
513                 //are you looking for a calculator for a shared parameter
514                 }else if (parameter == "shared") {
515                         for (it = shared.begin(); it != shared.end(); it++) {
516                                 out << it->first << ", ";
517                         }
518                 //are you looking for a calculator for a rarefaction parameter
519                 }else if (parameter == "rarefaction") {
520                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
521                                 out << it->first << ", ";
522                         }
523                 //are you looking for a calculator for a summary parameter
524                 }else if (parameter == "summary") {
525                         for (it = summary.begin(); it != summary.end(); it++) {
526                                 out << it->first << ", ";
527                         }
528                 //are you looking for a calculator for a sharedsummary parameter
529                 }else if (parameter == "sharedsummary") {
530                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
531                                 out << it->first << ", ";
532                         }
533                 }else if (parameter == "sharedrarefaction") {
534                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
535                                 out << it->first << ", ";
536                         }
537                 }else if (parameter == "vennsingle") {
538                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
539                                 out << it->first << ", ";
540                         }
541                 }else if (parameter == "vennshared") {
542                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
543                                 out << it->first << ", ";
544                         }
545                 }else if (parameter == "treegroup") {
546                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
547                                 out << it->first << ", ";
548                         }
549                 }else if (parameter == "matrix") {
550                         for (it = matrix.begin(); it != matrix.end(); it++) {
551                                 out << it->first << ", ";
552                         }
553                 }else if (parameter == "heat") {
554                         for (it = heat.begin(); it != heat.end(); it++) {
555                                 out << it->first << ", ";
556                         }
557                 }else if (parameter == "boot") {
558                         for (it = boot.begin(); it != boot.end(); it++) {
559                                 out << it->first << ", ";
560                         }
561                 }else if (parameter == "distance") {
562                         for (it = distance.begin(); it != distance.end(); it++) {
563                                 out << it->first << ", ";
564                         }
565                 }
566
567                 out << endl;
568         }
569         catch(exception& e) {
570                 m->errorOut(e, "ValidCalculator", "printCalc");
571                 exit(1);
572         }
573 }
574 /********************************************************************/
575