]> git.donarmstrong.com Git - mothur.git/blob - validcalculator.cpp
created mothurOut class to handle logfiles
[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["simpson"]           = "simpson";
213                 single["bergerparker"]  = "bergerparker";
214                 single["bootstrap"]     = "bootstrap";
215                 single["geometric"]     = "geometric";
216                 single["logseries"]         = "logseries";
217                 single["qstat"]         = "qstat";
218                 single["bstick"]        = "bstick";
219                 single["goodscoverage"] = "goodscoverage";
220                 single["nseqs"]                 = "nseqs";
221                 single["coverage"]              = "coverage";
222                 single["efron"]         = "efron";
223                 single["boneh"]         = "boneh";
224                 single["solow"]         = "solow";
225                 single["shen"]          = "shen";
226                 single["default"]           = "default";
227         }
228         catch(exception& e) {
229                 m->errorOut(e, "ValidCalculator", "initialSingle");
230                 exit(1);
231         }
232 }
233
234 /********************************************************************/
235 void ValidCalculators::initialShared() {
236         try {   
237                 shared["sharedsobs"]                    = "sharedsobs";
238                 shared["sharedchao"]                    = "sharedchao";
239                 shared["sharedace"]                             = "sharedace";
240                 shared["jabund"]                                = "jabund";
241                 shared["sorabund"]                              = "sorabund";
242                 shared["jclass"]                                = "jclass";
243                 shared["sorclass"]                              = "sorclass";
244                 shared["jest"]                                  = "jest";
245                 shared["sorest"]                                = "sorest";
246                 shared["thetayc"]                               = "thetayc";
247                 shared["thetan"]                                = "thetan";
248                 shared["kstest"]                                = "kstest";
249                 shared["whittaker"]                         = "whittaker";
250                 shared["sharednseqs"]                   = "sharednseqs";
251                 shared["ochiai"]                                = "ochiai";
252                 shared["anderberg"]                             = "anderberg";
253                 shared["kulczynski"]                    = "kulczynski";
254                 shared["kulczynskicody"]                = "kulczynskicody";
255                 shared["lennon"]                                = "lennon";
256                 shared["morisitahorn"]                  = "morisitahorn";
257                 shared["braycurtis"]                    = "braycurtis";
258                 shared["default"]                   = "default";
259         }
260         catch(exception& e) {
261                 m->errorOut(e, "ValidCalculator", "initialShared");
262                 exit(1);
263         }
264 }
265
266 /********************************************************************/
267 void ValidCalculators::initialRarefaction() {
268         try {   
269                 rarefaction["sobs"]                     = "sobs";
270                 rarefaction["chao"]                     = "chao";
271                 rarefaction["ace"]                      = "ace";
272                 rarefaction["jack"]                     = "jack";
273                 rarefaction["shannon"]          = "shannon";
274                 rarefaction["npshannon"]        = "npshannon";
275                 rarefaction["simpson"]          = "simpson";
276                 rarefaction["bootstrap"]        = "bootstrap";
277                 rarefaction["nseqs"]            = "nseqs";
278                 rarefaction["coverage"]         = "coverage";
279                 rarefaction["default"]      = "default";
280         }
281         catch(exception& e) {
282                 m->errorOut(e, "ValidCalculator", "initialRarefaction");
283                 exit(1);
284         }
285 }
286
287 /********************************************************************/
288
289 void ValidCalculators::initialSummary() {
290         try {   
291                 summary["sobs"]                 = "sobs";
292                 summary["chao"]                 = "chao";
293                 summary["ace"]                  = "ace";
294                 summary["jack"]                 = "jack";
295                 summary["shannon"]              = "shannon";
296                 summary["npshannon"]    = "npshannon";
297                 summary["simpson"]              = "simpson";
298                 summary["bergerparker"] = "bergerparker";
299                 summary["geometric"]    = "geometric";
300                 summary["bootstrap"]    = "bootstrap";
301                 summary["logseries"]    = "logseries";
302                 summary["qstat"]        = "qstat";
303                 summary["bstick"]       = "bstick";
304                 summary["nseqs"]                = "nseqs";
305                 summary["goodscoverage"]= "goodscoverage";
306                 summary["coverage"]             = "coverage";
307                 summary["efron"]        = "efron";
308                 summary["boneh"]        = "boneh";
309                 summary["solow"]        = "solow";
310                 summary["shen"]         = "shen";
311                 summary["default"]          = "default";
312         }
313         catch(exception& e) {
314                 m->errorOut(e, "ValidCalculator", "initialSummary");
315                 exit(1);
316         }
317 }
318
319 /********************************************************************/
320 void ValidCalculators::initialSharedSummary() {
321         try {   
322                 sharedsummary["sharedsobs"]                             = "sharedsobs";
323                 sharedsummary["sharedchao"]                             = "sharedchao";
324                 sharedsummary["sharedace"]                              = "sharedace";
325                 sharedsummary["jabund"]                                 = "jabund";
326                 sharedsummary["sorabund"]                       = "sorabund";
327                 sharedsummary["jclass"]                                 = "jclass";
328                 sharedsummary["sorclass"]                               = "sorclass";
329                 sharedsummary["jest"]                                   = "jest";
330                 sharedsummary["sorest"]                                 = "sorest";
331                 sharedsummary["thetayc"]                                = "thetayc";
332                 sharedsummary["thetan"]                                 = "thetan";
333                 sharedsummary["kstest"]                                 = "kstest";
334                 sharedsummary["whittaker"]                              = "whittaker";
335                 sharedsummary["sharednseqs"]                    = "sharednseqs";
336                 sharedsummary["ochiai"]                                 = "ochiai";
337                 sharedsummary["anderberg"]                              = "anderberg";
338                 sharedsummary["kulczynski"]                             = "kulczynski";
339                 sharedsummary["kulczynskicody"]                 = "kulczynskicody";
340                 sharedsummary["lennon"]                                 = "lennon";
341                 sharedsummary["morisitahorn"]                   = "morisitahorn";
342                 sharedsummary["braycurtis"]                             = "braycurtis";
343                 sharedsummary["default"]                                = "default";
344         }
345         catch(exception& e) {
346                 m->errorOut(e, "ValidCalculator", "initialSharedSummary");
347                 exit(1);
348         }
349 }
350
351
352 /********************************************************************/
353
354 void ValidCalculators::initialSharedRarefact() {
355         try {   
356                 sharedrarefaction["sharedobserved"]     = "sharedobserved";
357                 sharedrarefaction["sharednseqs"]        = "sharednseqs";
358                 sharedrarefaction["default"]        = "default";
359         }
360         catch(exception& e) {
361                 m->errorOut(e, "ValidCalculator", "initialSharedRarefact");
362                 exit(1);
363         }
364 }
365
366
367 /********************************************************************/
368 void ValidCalculators::initialVennSingle() {
369         try {
370                 vennsingle["sobs"]              = "sobs";
371                 vennsingle["chao"]                  = "chao";
372                 vennsingle["ace"]                       = "ace";
373                 vennsingle["jack"]                  = "jack";
374                 vennsingle["default"]           = "default";
375         }
376         catch(exception& e) {
377                 m->errorOut(e, "ValidCalculator", "initialVennSingle");
378                 exit(1);
379         }
380 }
381
382 /********************************************************************/
383 void ValidCalculators::initialVennShared() {
384         try {
385                 vennshared["sharedsobs"]        = "sharedsobs";
386                 vennshared["sharedchao"]        = "sharedchao";
387                 vennshared["sharedace"]         = "sharedace";
388                 vennshared["default"]           = "default";
389         }
390         catch(exception& e) {
391                 m->errorOut(e, "ValidCalculator", "initialVennShared");
392                 exit(1);
393         }
394 }
395
396 /********************************************************************/
397 void ValidCalculators::initialTreeGroups() {
398         try {   
399                 treegroup["jabund"]                                     = "jabund";
400                 treegroup["sorabund"]                           = "sorabund";
401                 treegroup["jclass"]                                     = "jclass";
402                 treegroup["sorclass"]                           = "sorclass";
403                 treegroup["jest"]                                       = "jest";
404                 treegroup["sorest"]                                     = "sorest";
405                 treegroup["thetayc"]                            = "thetayc";
406                 treegroup["thetan"]                                     = "thetan";
407                 treegroup["morisitahorn"]                       = "morisitahorn";
408                 treegroup["braycurtis"]                         = "braycurtis";
409         }
410         catch(exception& e) {
411                 m->errorOut(e, "ValidCalculator", "initialTreeGroups");
412                 exit(1);
413         }
414 }
415 /********************************************************************/
416 void ValidCalculators::initialHeat() {
417         try {   
418                 heat["jabund"]                          = "jabund";
419                 heat["sorabund"]                        = "sorabund";
420                 heat["jclass"]                          = "jclass";
421                 heat["sorclass"]                        = "sorclass";
422                 heat["jest"]                            = "jest";
423                 heat["sorest"]                          = "sorest";
424                 heat["thetayc"]                         = "thetayc";
425                 heat["thetan"]                          = "thetan";
426                 heat["morisitahorn"]            = "morisitahorn";
427                 heat["braycurtis"]                      = "braycurtis";
428         }
429         catch(exception& e) {
430                 m->errorOut(e, "ValidCalculator", "initialHeat");
431                 exit(1);
432         }
433 }
434
435 /********************************************************************/
436 void ValidCalculators::initialMatrix() {
437         try {   
438                 matrix["jabund"]                                = "jabund";
439                 matrix["sorabund"]                              = "sorabund";
440                 matrix["jclass"]                                = "jclass";
441                 matrix["sorclass"]                              = "sorclass";
442                 matrix["jest"]                                  = "jest";
443                 matrix["sorest"]                                = "sorest";
444                 matrix["thetayc"]                               = "thetayc";
445                 matrix["thetan"]                                = "thetan";
446                 matrix["morisitahorn"]                  = "morisitahorn";
447                 matrix["braycurtis"]                    = "braycurtis";
448         }
449         catch(exception& e) {
450                 m->errorOut(e, "ValidCalculator", "initialMatrix");
451                 exit(1);
452         }
453 }
454
455 /********************************************************************/
456 void ValidCalculators::initialBoot() {
457         try {   
458                 boot["jabund"]                          = "jabund";
459                 boot["sorabund"]                        = "sorabund";
460                 boot["jclass"]                          = "jclass";
461                 boot["sorclass"]                        = "orclass";
462                 boot["jest"]                            = "jest";
463                 boot["sorest"]                          = "sorest";
464                 boot["thetayc"]                         = "thetayc";
465                 boot["thetan"]                          = "thetan";
466                 boot["morisitahorn"]            = "morisitahorn";
467                 boot["braycurtis"]                      = "braycurtis";
468         }
469         catch(exception& e) {
470                 m->errorOut(e, "ValidCalculator", "initialBoot");
471                 exit(1);
472         }
473 }
474 /********************************************************************/
475 void ValidCalculators::initialDistance() {
476         try {   
477                 distance["nogaps"]              = "nogaps";
478                 distance["eachgap"]             = "eachgap";
479                 distance["onegap"]              = "onegap";
480         }
481         catch(exception& e) {
482                 m->errorOut(e, "ValidCalculator", "initialDistance");
483                 exit(1);
484         }
485 }
486
487 /********************************************************************/
488 void ValidCalculators::printCalc(string parameter, ostream& out) {
489         try{
490                 out << "The available estimators for calc are ";
491                 //are you looking for a calculator for a single parameter
492                 if (parameter == "single") {
493                         for (it = single.begin(); it != single.end(); it++) {
494                                 out << it->first << ", ";
495                         }
496                 //are you looking for a calculator for a shared parameter
497                 }else if (parameter == "shared") {
498                         for (it = shared.begin(); it != shared.end(); it++) {
499                                 out << it->first << ", ";
500                         }
501                 //are you looking for a calculator for a rarefaction parameter
502                 }else if (parameter == "rarefaction") {
503                         for (it = rarefaction.begin(); it != rarefaction.end(); it++) {
504                                 out << it->first << ", ";
505                         }
506                 //are you looking for a calculator for a summary parameter
507                 }else if (parameter == "summary") {
508                         for (it = summary.begin(); it != summary.end(); it++) {
509                                 out << it->first << ", ";
510                         }
511                 //are you looking for a calculator for a sharedsummary parameter
512                 }else if (parameter == "sharedsummary") {
513                         for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) {
514                                 out << it->first << ", ";
515                         }
516                 }else if (parameter == "sharedrarefaction") {
517                         for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) {
518                                 out << it->first << ", ";
519                         }
520                 }else if (parameter == "vennsingle") {
521                         for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
522                                 out << it->first << ", ";
523                         }
524                 }else if (parameter == "vennshared") {
525                         for (it = vennshared.begin(); it != vennshared.end(); it++) {
526                                 out << it->first << ", ";
527                         }
528                 }else if (parameter == "treegroup") {
529                         for (it = treegroup.begin(); it != treegroup.end(); it++) {
530                                 out << it->first << ", ";
531                         }
532                 }else if (parameter == "matrix") {
533                         for (it = matrix.begin(); it != matrix.end(); it++) {
534                                 out << it->first << ", ";
535                         }
536                 }else if (parameter == "heat") {
537                         for (it = heat.begin(); it != heat.end(); it++) {
538                                 out << it->first << ", ";
539                         }
540                 }else if (parameter == "boot") {
541                         for (it = boot.begin(); it != boot.end(); it++) {
542                                 out << it->first << ", ";
543                         }
544                 }else if (parameter == "distance") {
545                         for (it = distance.begin(); it != distance.end(); it++) {
546                                 out << it->first << ", ";
547                         }
548                 }
549
550                 out << endl;
551         }
552         catch(exception& e) {
553                 m->errorOut(e, "ValidCalculator", "printCalc");
554                 exit(1);
555         }
556 }
557 /********************************************************************/
558