5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "collectcommand.h"
15 #include "bootstrap.h"
17 #include "npshannon.h"
19 #include "jackknife.h"
23 #include "bergerparker.h"
25 #include "goodscoverage.h"
33 //**********************************************************************************************************************
34 CollectCommand::CollectCommand(){
36 globaldata = GlobalData::getInstance();
38 fileNameRoot = getRootName(globaldata->inputFileName);
39 convert(globaldata->getFreq(), freq);
41 validCalculator = new ValidCalculators();
43 for (i=0; i<globaldata->Estimators.size(); i++) {
44 if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) {
45 if (globaldata->Estimators[i] == "sobs") {
46 cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
47 }else if (globaldata->Estimators[i] == "chao") {
48 cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
49 }else if (globaldata->Estimators[i] == "nseqs") {
50 cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
51 }else if (globaldata->Estimators[i] == "coverage") {
52 cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
53 }else if (globaldata->Estimators[i] == "ace") {
54 convert(globaldata->getAbund(), abund);
55 cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
56 }else if (globaldata->Estimators[i] == "jack") {
57 cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
58 }else if (globaldata->Estimators[i] == "shannon") {
59 cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
60 }else if (globaldata->Estimators[i] == "npshannon") {
61 cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
62 }else if (globaldata->Estimators[i] == "simpson") {
63 cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
64 }else if (globaldata->Estimators[i] == "bootstrap") {
65 cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
66 }else if (globaldata->Estimators[i] == "geometric") {
67 cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
68 }else if (globaldata->Estimators[i] == "qstat") {
69 cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
70 }else if (globaldata->Estimators[i] == "logseries") {
71 cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
72 }else if (globaldata->Estimators[i] == "bergerparker") {
73 cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
74 }else if (globaldata->Estimators[i] == "bstick") {
75 cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
76 }else if (globaldata->Estimators[i] == "goodscoverage") {
77 cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
78 }else if (globaldata->Estimators[i] == "efron") {
79 convert(globaldata->getSize(), size);
80 cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
81 }else if (globaldata->Estimators[i] == "boneh") {
82 convert(globaldata->getSize(), size);
83 cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
84 }else if (globaldata->Estimators[i] == "solow") {
85 convert(globaldata->getSize(), size);
86 cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
87 }else if (globaldata->Estimators[i] == "shen") {
88 convert(globaldata->getSize(), size);
89 cDisplays.push_back(new CollectDisplay(new Shen(size), new OneColumnFile(fileNameRoot+"shen")));
94 //reset calc for next command
95 globaldata->setCalc("");
98 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 //**********************************************************************************************************************
110 CollectCommand::~CollectCommand(){
117 //**********************************************************************************************************************
119 int CollectCommand::execute(){
123 //if the users entered no valid calculators don't execute command
124 if (cDisplays.size() == 0) { return 0; }
126 read = new ReadOTUFile(globaldata->inputFileName);
127 read->read(&*globaldata);
129 order = globaldata->gorder;
131 input = globaldata->ginput;
133 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
134 set<string> processedLabels;
135 set<string> userLabels = globaldata->labels;
136 set<int> userLines = globaldata->lines;
138 while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
140 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
142 cCurve = new Collect(order, cDisplays);
143 cCurve->getCurve(freq);
146 cout << order->getLabel() << '\t' << count << endl;
147 processedLabels.insert(order->getLabel());
148 userLabels.erase(order->getLabel());
149 userLines.erase(count);
151 //you have a label the user want that is smaller than this line and the last line has not already been processed
154 if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
155 cCurve = new Collect(lastOrder, cDisplays);
156 cCurve->getCurve(freq);
159 cout << lastOrder->getLabel() << '\t' << count << endl;
160 processedLabels.insert(lastOrder->getLabel());
161 userLabels.erase(lastOrder->getLabel());
164 if (count != 1) { delete lastOrder; }
166 order = (input->getOrderVector());
170 //output error messages about any remaining user labels
171 set<string>::iterator it;
172 bool needToRun = false;
173 for (it = userLabels.begin(); it != userLabels.end(); it++) {
174 cout << "Your file does not include the label "<< *it;
175 if (processedLabels.count(lastOrder->getLabel()) != 1) {
176 cout << ". I will use " << lastOrder->getLabel() << "." << endl;
179 cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
183 //run last line if you need to
184 if (needToRun == true) {
185 cCurve = new Collect(lastOrder, cDisplays);
186 cCurve->getCurve(freq);
189 cout << lastOrder->getLabel() << '\t' << count << endl;
193 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
196 catch(exception& e) {
197 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
206 //**********************************************************************************************************************