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