]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
fixed linking error in collect, collectshared, and errorcheckor
[mothur.git] / collectcommand.cpp
1 /*
2  *  collectcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "collectcommand.h"
11 #include "ace.h"
12 #include "sobs.h"
13 #include "chao1.h"
14 #include "bootstrap.h"
15 #include "simpson.h"
16 #include "npshannon.h"
17 #include "shannon.h"
18 #include "jackknife.h"
19
20
21 //**********************************************************************************************************************
22
23
24 CollectCommand::CollectCommand(){
25         try {
26                 globaldata = GlobalData::getInstance();
27                 string fileNameRoot;
28                 fileNameRoot = getRootName(globaldata->inputFileName);
29                 int i;
30                 validCalculator = new ValidCalculators();
31                 
32                 for (i=0; i<globaldata->Estimators.size(); i++) {
33                         if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { 
34                                 if (globaldata->Estimators[i] == "sobs") { 
35                                         cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
36                                 }else if (globaldata->Estimators[i] == "chao") { 
37                                         cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
38                                 }else if (globaldata->Estimators[i] == "ace") { 
39                                 convert(globaldata->getAbund(), abund);
40                                         cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
41                                 }else if (globaldata->Estimators[i] == "jack") { 
42                                         cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
43                                 }else if (globaldata->Estimators[i] == "shannon") { 
44                                         cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
45                                 }else if (globaldata->Estimators[i] == "npshannon") { 
46                                         cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
47                                 }else if (globaldata->Estimators[i] == "simpson") { 
48                                         cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
49                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
50                                         cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
51                                 }
52                         }
53                 }
54                 
55                 //reset calc for next command
56                 globaldata->setCalc("");
57         }
58         catch(exception& e) {
59                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60                 exit(1);
61         }
62         catch(...) {
63                 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64                 exit(1);
65         }       
66                         
67 }
68
69 //**********************************************************************************************************************
70
71 CollectCommand::~CollectCommand(){
72         delete order;
73         delete input;
74         delete cCurve;
75         delete read;
76 }
77
78 //**********************************************************************************************************************
79
80 int CollectCommand::execute(){
81         try {
82                 int count = 1;
83                 
84                 //if the users entered no valid calculators don't execute command
85                 if (cDisplays.size() == 0) { return 0; }
86
87                 read = new ReadPhilFile(globaldata->inputFileName);     
88                 read->read(&*globaldata); 
89                 
90                 order = globaldata->gorder;
91                 input = globaldata->ginput;
92                 set<string> orderList;  
93                 
94                 while(order != NULL){
95                 
96                         orderList.insert(order->getLabel());
97                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
98                                 cCurve = new Collect(order, cDisplays);
99                                 convert(globaldata->getFreq(), freq);
100                                 cCurve->getCurve(freq);
101                         
102                                 delete cCurve;
103                         
104                                 cout << order->getLabel() << '\t' << count << endl;
105                         }
106                         order = (input->getOrderVector());
107                         count++;
108                 }
109                 set<string>::iterator i;
110                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
111                         if(orderList.count(*i) == 0)
112                                 cout << "'" << *i << "'" << " is not a valid label.\n";
113                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
114                 return 0;
115         }
116         catch(exception& e) {
117                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
118                 exit(1);
119         }
120         catch(...) {
121                 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122                 exit(1);
123         }       
124 }
125
126 //**********************************************************************************************************************