]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
fixed bug with trim.seqs- when a file is blank for a grouping mothur removed it,...
[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["odum"]                                  = "odum";
264                 shared["canberra"]                              = "canberra";
265                 shared["stricteuclidean"]               = "stricteuclidean";
266                 shared["strictchord"]                   = "strictchord";
267                 shared["hellinger"]                             = "hellinger";
268                 shared["manhattan"]                             = "manhattan";
269                 shared["strictpearson"]                 = "strictpearson";
270                 shared["soergel"]                               = "soergel";
271                 shared["spearman"]                              = "spearman";
272                 shared["strictkulczynski"]              = "strictkulczynski";
273                 shared["speciesprofile"]                = "speciesprofile";
274                 shared["hamming"]                               = "hamming";
275                 shared["default"]                   = "default";
276         }
277         catch(exception& e) {
278                 m->errorOut(e, "ValidCalculator", "initialShared");
279                 exit(1);
280         }
281 }
282
283 /********************************************************************/
284 void ValidCalculators::initialRarefaction() {
285         try {   
286                 rarefaction["sobs"]                     = "sobs";
287                 rarefaction["chao"]                     = "chao";
288                 rarefaction["ace"]                      = "ace";
289                 rarefaction["jack"]                     = "jack";
290                 rarefaction["shannon"]          = "shannon";
291                 rarefaction["smithwilson"]      = "smithwilson";
292                 rarefaction["heip"]                     = "heip";
293                 rarefaction["npshannon"]        = "npshannon";
294                 rarefaction["shannoneven"]      = "shannoneven";
295                 rarefaction["simpson"]          = "simpson";
296                 rarefaction["invsimpson"]       = "invsimpson";
297                 rarefaction["simpsoneven"]      = "simpsoneven";
298                 rarefaction["bootstrap"]        = "bootstrap";
299                 rarefaction["nseqs"]            = "nseqs";
300                 rarefaction["coverage"]         = "coverage";
301                 rarefaction["default"]      = "default";
302         }
303         catch(exception& e) {
304                 m->errorOut(e, "ValidCalculator", "initialRarefaction");
305                 exit(1);
306         }
307 }
308
309 /********************************************************************/
310
311 void ValidCalculators::initialSummary() {
312         try {   
313                 summary["sobs"]                 = "sobs";
314                 summary["chao"]                 = "chao";
315                 summary["ace"]                  = "ace";
316                 summary["jack"]                 = "jack";
317                 summary["shannon"]              = "shannon";
318                 summary["heip"]                 = "heip";
319                 summary["shannoneven"]  = "shannoneven";
320                 summary["smithwilson"]  = "smithwilson";
321                 summary["invsimpson"]   = "invsimpson";
322                 summary["npshannon"]    = "npshannon";
323                 summary["simpson"]              = "simpson";
324                 summary["simpsoneven"]  = "simpsoneven";
325                 summary["bergerparker"] = "bergerparker";
326                 summary["geometric"]    = "geometric";
327                 summary["bootstrap"]    = "bootstrap";
328                 summary["logseries"]    = "logseries";
329                 summary["qstat"]        = "qstat";
330                 summary["bstick"]       = "bstick";
331                 summary["nseqs"]                = "nseqs";
332                 summary["goodscoverage"]= "goodscoverage";
333                 summary["coverage"]             = "coverage";
334                 summary["efron"]        = "efron";
335                 summary["boneh"]        = "boneh";
336                 summary["solow"]        = "solow";
337                 summary["shen"]         = "shen";
338                 summary["default"]          = "default";
339         }
340         catch(exception& e) {
341                 m->errorOut(e, "ValidCalculator", "initialSummary");
342                 exit(1);
343         }
344 }
345
346 /********************************************************************/
347 void ValidCalculators::initialSharedSummary() {
348         try {   
349                 sharedsummary["sharedsobs"]                             = "sharedsobs";
350                 sharedsummary["sharedchao"]                             = "sharedchao";
351                 sharedsummary["sharedace"]                              = "sharedace";
352                 sharedsummary["jabund"]                                 = "jabund";
353                 sharedsummary["sorabund"]                               = "sorabund";
354                 sharedsummary["jclass"]                                 = "jclass";
355                 sharedsummary["sorclass"]                               = "sorclass";
356                 sharedsummary["jest"]                                   = "jest";
357                 sharedsummary["sorest"]                                 = "sorest";
358                 sharedsummary["thetayc"]                                = "thetayc";
359                 sharedsummary["thetan"]                                 = "thetan";
360                 sharedsummary["kstest"]                                 = "kstest";
361                 sharedsummary["whittaker"]                              = "whittaker";
362                 sharedsummary["sharednseqs"]                    = "sharednseqs";
363                 sharedsummary["ochiai"]                                 = "ochiai";
364                 sharedsummary["anderberg"]                              = "anderberg";
365                 sharedsummary["kulczynski"]                             = "kulczynski";
366                 sharedsummary["kulczynskicody"]                 = "kulczynskicody";
367                 sharedsummary["lennon"]                                 = "lennon";
368                 sharedsummary["morisitahorn"]                   = "morisitahorn";
369                 sharedsummary["braycurtis"]                             = "braycurtis";
370                 sharedsummary["odum"]                                   = "odum";
371                 sharedsummary["canberra"]                               = "canberra";
372                 sharedsummary["stricteuclidean"]                = "stricteuclidean";
373                 sharedsummary["strictchord"]                    = "strictchord";
374                 sharedsummary["hellinger"]                              = "hellinger";
375                 sharedsummary["manhattan"]                              = "manhattan";
376                 sharedsummary["strictpearson"]                  = "strictpearson";
377                 sharedsummary["strictkulczynski"]               = "strictkulczynski";
378                 sharedsummary["soergel"]                                = "soergel";
379                 sharedsummary["spearman"]                               = "spearman";
380                 sharedsummary["speciesprofile"]                 = "speciesprofile";
381                 sharedsummary["hamming"]                                = "hamming";
382                 sharedsummary["default"]                                = "default";
383         }
384         catch(exception& e) {
385                 m->errorOut(e, "ValidCalculator", "initialSharedSummary");
386                 exit(1);
387         }
388 }
389
390
391 /********************************************************************/
392
393 void ValidCalculators::initialSharedRarefact() {
394         try {   
395                 sharedrarefaction["sharedobserved"]     = "sharedobserved";
396                 sharedrarefaction["sharednseqs"]        = "sharednseqs";
397                 sharedrarefaction["default"]        = "default";
398         }
399         catch(exception& e) {
400                 m->errorOut(e, "ValidCalculator", "initialSharedRarefact");
401                 exit(1);
402         }
403 }
404
405
406 /********************************************************************/
407 void ValidCalculators::initialVennSingle() {
408         try {
409                 vennsingle["sobs"]              = "sobs";
410                 vennsingle["chao"]                  = "chao";
411                 vennsingle["ace"]                       = "ace";
412                 vennsingle["jack"]                  = "jack";
413                 vennsingle["default"]           = "default";
414         }
415         catch(exception& e) {
416                 m->errorOut(e, "ValidCalculator", "initialVennSingle");
417                 exit(1);
418         }
419 }
420
421 /********************************************************************/
422 void ValidCalculators::initialVennShared() {
423         try {
424                 vennshared["sharedsobs"]        = "sharedsobs";
425                 vennshared["sharedchao"]        = "sharedchao";
426                 vennshared["sharedace"]         = "sharedace";
427                 vennshared["default"]           = "default";
428         }
429         catch(exception& e) {
430                 m->errorOut(e, "ValidCalculator", "initialVennShared");
431                 exit(1);
432         }
433 }
434
435 /********************************************************************/
436 void ValidCalculators::initialTreeGroups() {
437         try {   
438                 treegroup["jabund"]                                     = "jabund";
439                 treegroup["sorabund"]                           = "sorabund";
440                 treegroup["jclass"]                                     = "jclass";
441                 treegroup["sorclass"]                           = "sorclass";
442                 treegroup["jest"]                                       = "jest";
443                 treegroup["sorest"]                                     = "sorest";
444                 treegroup["thetayc"]                            = "thetayc";
445                 treegroup["thetan"]                                     = "thetan";
446                 treegroup["morisitahorn"]                       = "morisitahorn";
447                 treegroup["braycurtis"]                         = "braycurtis";
448         }
449         catch(exception& e) {
450                 m->errorOut(e, "ValidCalculator", "initialTreeGroups");
451                 exit(1);
452         }
453 }
454 /********************************************************************/
455 void ValidCalculators::initialHeat() {
456         try {   
457                 heat["jabund"]                          = "jabund";
458                 heat["sorabund"]                        = "sorabund";
459                 heat["jclass"]                          = "jclass";
460                 heat["sorclass"]                        = "sorclass";
461                 heat["jest"]                            = "jest";
462                 heat["sorest"]                          = "sorest";
463                 heat["thetayc"]                         = "thetayc";
464                 heat["thetan"]                          = "thetan";
465                 heat["morisitahorn"]            = "morisitahorn";
466                 heat["braycurtis"]                      = "braycurtis";
467         }
468         catch(exception& e) {
469                 m->errorOut(e, "ValidCalculator", "initialHeat");
470                 exit(1);
471         }
472 }
473
474 /********************************************************************/
475 void ValidCalculators::initialMatrix() {
476         try {   
477                 matrix["jabund"]                                = "jabund";
478                 matrix["sorabund"]                              = "sorabund";
479                 matrix["jclass"]                                = "jclass";
480                 matrix["sorclass"]                              = "sorclass";
481                 matrix["jest"]                                  = "jest";
482                 matrix["sorest"]                                = "sorest";
483                 matrix["thetayc"]                               = "thetayc";
484                 matrix["thetan"]                                = "thetan";
485                 matrix["morisitahorn"]                  = "morisitahorn";
486                 matrix["braycurtis"]                    = "braycurtis";
487         }
488         catch(exception& e) {
489                 m->errorOut(e, "ValidCalculator", "initialMatrix");
490                 exit(1);
491         }
492 }
493
494 /********************************************************************/
495 void ValidCalculators::initialBoot() {
496         try {   
497                 boot["jabund"]                          = "jabund";
498                 boot["sorabund"]                        = "sorabund";
499                 boot["jclass"]                          = "jclass";
500                 boot["sorclass"]                        = "orclass";
501                 boot["jest"]                            = "jest";
502                 boot["sorest"]                          = "sorest";
503                 boot["thetayc"]                         = "thetayc";
504                 boot["thetan"]                          = "thetan";
505                 boot["morisitahorn"]            = "morisitahorn";
506                 boot["braycurtis"]                      = "braycurtis";
507         }
508         catch(exception& e) {
509                 m->errorOut(e, "ValidCalculator", "initialBoot");
510                 exit(1);
511         }
512 }
513 /********************************************************************/
514 void ValidCalculators::initialDistance() {
515         try {   
516                 distance["nogaps"]              = "nogaps";
517                 distance["eachgap"]             = "eachgap";
518                 distance["onegap"]              = "onegap";
519         }
520         catch(exception& e) {
521                 m->errorOut(e, "ValidCalculator", "initialDistance");
522                 exit(1);
523         }
524 }
525
526 /********************************************************************/
527 void ValidCalculators::printCalc(string parameter, ostream& out) {
528         try{
529                 out << "The available estimators for calc are ";
530                 //are you looking for a calculator for a single parameter
531                 if (parameter == "single") {
532                         for (it = single.begin(); it != single.end(); it++) {
533                                 out << it->first << ", ";
534                         }
535                 //are you looking for a calculator for a shared parameter
536                 }else if (parameter == "shared") {
537                         for (it = shared.begin(); it != shared.end(); it++) {
538                                 out << it->first << ", ";
539                         }
540                 //are you looking for a calculator for a rarefaction parameter
541                 }else if (parameter == "rarefaction") {
542                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
543                                 out << it->first << ", ";
544                         }
545                 //are you looking for a calculator for a summary parameter
546                 }else if (parameter == "summary") {
547                         for (it = summary.begin(); it != summary.end(); it++) {
548                                 out << it->first << ", ";
549                         }
550                 //are you looking for a calculator for a sharedsummary parameter
551                 }else if (parameter == "sharedsummary") {
552                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
553                                 out << it->first << ", ";
554                         }
555                 }else if (parameter == "sharedrarefaction") {
556                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
557                                 out << it->first << ", ";
558                         }
559                 }else if (parameter == "vennsingle") {
560                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
561                                 out << it->first << ", ";
562                         }
563                 }else if (parameter == "vennshared") {
564                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
565                                 out << it->first << ", ";
566                         }
567                 }else if (parameter == "treegroup") {
568                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
569                                 out << it->first << ", ";
570                         }
571                 }else if (parameter == "matrix") {
572                         for (it = matrix.begin(); it != matrix.end(); it++) {
573                                 out << it->first << ", ";
574                         }
575                 }else if (parameter == "heat") {
576                         for (it = heat.begin(); it != heat.end(); it++) {
577                                 out << it->first << ", ";
578                         }
579                 }else if (parameter == "boot") {
580                         for (it = boot.begin(); it != boot.end(); it++) {
581                                 out << it->first << ", ";
582                         }
583                 }else if (parameter == "distance") {
584                         for (it = distance.begin(); it != distance.end(); it++) {
585                                 out << it->first << ", ";
586                         }
587                 }
588
589                 out << endl;
590         }
591         catch(exception& e) {
592                 m->errorOut(e, "ValidCalculator", "printCalc");
593                 exit(1);
594         }
595 }
596 /********************************************************************/
597