]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
added cluster.fragments command as well as the nseqs parameter to the venn command
[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["default"]           = "default";
390         }
391         catch(exception& e) {
392                 m->errorOut(e, "ValidCalculator", "initialVennSingle");
393                 exit(1);
394         }
395 }
396
397 /********************************************************************/
398 void ValidCalculators::initialVennShared() {
399         try {
400                 vennshared["sharedsobs"]        = "sharedsobs";
401                 vennshared["sharedchao"]        = "sharedchao";
402                 vennshared["sharedace"]         = "sharedace";
403                 vennshared["default"]           = "default";
404         }
405         catch(exception& e) {
406                 m->errorOut(e, "ValidCalculator", "initialVennShared");
407                 exit(1);
408         }
409 }
410
411 /********************************************************************/
412 void ValidCalculators::initialTreeGroups() {
413         try {   
414                 treegroup["jabund"]                                     = "jabund";
415                 treegroup["sorabund"]                           = "sorabund";
416                 treegroup["jclass"]                                     = "jclass";
417                 treegroup["sorclass"]                           = "sorclass";
418                 treegroup["jest"]                                       = "jest";
419                 treegroup["sorest"]                                     = "sorest";
420                 treegroup["thetayc"]                            = "thetayc";
421                 treegroup["thetan"]                                     = "thetan";
422                 treegroup["morisitahorn"]                       = "morisitahorn";
423                 treegroup["braycurtis"]                         = "braycurtis";
424         }
425         catch(exception& e) {
426                 m->errorOut(e, "ValidCalculator", "initialTreeGroups");
427                 exit(1);
428         }
429 }
430 /********************************************************************/
431 void ValidCalculators::initialHeat() {
432         try {   
433                 heat["jabund"]                          = "jabund";
434                 heat["sorabund"]                        = "sorabund";
435                 heat["jclass"]                          = "jclass";
436                 heat["sorclass"]                        = "sorclass";
437                 heat["jest"]                            = "jest";
438                 heat["sorest"]                          = "sorest";
439                 heat["thetayc"]                         = "thetayc";
440                 heat["thetan"]                          = "thetan";
441                 heat["morisitahorn"]            = "morisitahorn";
442                 heat["braycurtis"]                      = "braycurtis";
443         }
444         catch(exception& e) {
445                 m->errorOut(e, "ValidCalculator", "initialHeat");
446                 exit(1);
447         }
448 }
449
450 /********************************************************************/
451 void ValidCalculators::initialMatrix() {
452         try {   
453                 matrix["jabund"]                                = "jabund";
454                 matrix["sorabund"]                              = "sorabund";
455                 matrix["jclass"]                                = "jclass";
456                 matrix["sorclass"]                              = "sorclass";
457                 matrix["jest"]                                  = "jest";
458                 matrix["sorest"]                                = "sorest";
459                 matrix["thetayc"]                               = "thetayc";
460                 matrix["thetan"]                                = "thetan";
461                 matrix["morisitahorn"]                  = "morisitahorn";
462                 matrix["braycurtis"]                    = "braycurtis";
463         }
464         catch(exception& e) {
465                 m->errorOut(e, "ValidCalculator", "initialMatrix");
466                 exit(1);
467         }
468 }
469
470 /********************************************************************/
471 void ValidCalculators::initialBoot() {
472         try {   
473                 boot["jabund"]                          = "jabund";
474                 boot["sorabund"]                        = "sorabund";
475                 boot["jclass"]                          = "jclass";
476                 boot["sorclass"]                        = "orclass";
477                 boot["jest"]                            = "jest";
478                 boot["sorest"]                          = "sorest";
479                 boot["thetayc"]                         = "thetayc";
480                 boot["thetan"]                          = "thetan";
481                 boot["morisitahorn"]            = "morisitahorn";
482                 boot["braycurtis"]                      = "braycurtis";
483         }
484         catch(exception& e) {
485                 m->errorOut(e, "ValidCalculator", "initialBoot");
486                 exit(1);
487         }
488 }
489 /********************************************************************/
490 void ValidCalculators::initialDistance() {
491         try {   
492                 distance["nogaps"]              = "nogaps";
493                 distance["eachgap"]             = "eachgap";
494                 distance["onegap"]              = "onegap";
495         }
496         catch(exception& e) {
497                 m->errorOut(e, "ValidCalculator", "initialDistance");
498                 exit(1);
499         }
500 }
501
502 /********************************************************************/
503 void ValidCalculators::printCalc(string parameter, ostream& out) {
504         try{
505                 out << "The available estimators for calc are ";
506                 //are you looking for a calculator for a single parameter
507                 if (parameter == "single") {
508                         for (it = single.begin(); it != single.end(); it++) {
509                                 out << it->first << ", ";
510                         }
511                 //are you looking for a calculator for a shared parameter
512                 }else if (parameter == "shared") {
513                         for (it = shared.begin(); it != shared.end(); it++) {
514                                 out << it->first << ", ";
515                         }
516                 //are you looking for a calculator for a rarefaction parameter
517                 }else if (parameter == "rarefaction") {
518                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
519                                 out << it->first << ", ";
520                         }
521                 //are you looking for a calculator for a summary parameter
522                 }else if (parameter == "summary") {
523                         for (it = summary.begin(); it != summary.end(); it++) {
524                                 out << it->first << ", ";
525                         }
526                 //are you looking for a calculator for a sharedsummary parameter
527                 }else if (parameter == "sharedsummary") {
528                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
529                                 out << it->first << ", ";
530                         }
531                 }else if (parameter == "sharedrarefaction") {
532                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
533                                 out << it->first << ", ";
534                         }
535                 }else if (parameter == "vennsingle") {
536                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
537                                 out << it->first << ", ";
538                         }
539                 }else if (parameter == "vennshared") {
540                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
541                                 out << it->first << ", ";
542                         }
543                 }else if (parameter == "treegroup") {
544                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
545                                 out << it->first << ", ";
546                         }
547                 }else if (parameter == "matrix") {
548                         for (it = matrix.begin(); it != matrix.end(); it++) {
549                                 out << it->first << ", ";
550                         }
551                 }else if (parameter == "heat") {
552                         for (it = heat.begin(); it != heat.end(); it++) {
553                                 out << it->first << ", ";
554                         }
555                 }else if (parameter == "boot") {
556                         for (it = boot.begin(); it != boot.end(); it++) {
557                                 out << it->first << ", ";
558                         }
559                 }else if (parameter == "distance") {
560                         for (it = distance.begin(); it != distance.end(); it++) {
561                                 out << it->first << ", ";
562                         }
563                 }
564
565                 out << endl;
566         }
567         catch(exception& e) {
568                 m->errorOut(e, "ValidCalculator", "printCalc");
569                 exit(1);
570         }
571 }
572 /********************************************************************/
573