5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "collectcommand.h"
14 #include "bootstrap.h"
16 #include "npshannon.h"
18 #include "jackknife.h"
21 //**********************************************************************************************************************
24 CollectCommand::CollectCommand(){
26 globaldata = GlobalData::getInstance();
28 fileNameRoot = getRootName(globaldata->inputFileName);
30 validCalculator = new ValidCalculators();
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")));
55 //reset calc for next command
56 globaldata->setCalc("");
59 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
69 //**********************************************************************************************************************
71 CollectCommand::~CollectCommand(){
78 //**********************************************************************************************************************
80 int CollectCommand::execute(){
84 //if the users entered no valid calculators don't execute command
85 if (cDisplays.size() == 0) { return 0; }
87 read = new ReadPhilFile(globaldata->inputFileName);
88 read->read(&*globaldata);
90 order = globaldata->gorder;
91 input = globaldata->ginput;
92 set<string> orderList;
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);
104 cout << order->getLabel() << '\t' << count << endl;
106 order = (input->getOrderVector());
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]; }
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";
121 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 //**********************************************************************************************************************