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"
31 //**********************************************************************************************************************
32 CollectCommand::CollectCommand(){
34 globaldata = GlobalData::getInstance();
36 fileNameRoot = getRootName(globaldata->inputFileName);
38 validCalculator = new ValidCalculators();
39 for (i=0; i<globaldata->Estimators.size(); i++) {
40 if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) {
41 if (globaldata->Estimators[i] == "sobs") {
42 cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
43 }else if (globaldata->Estimators[i] == "chao") {
44 cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
45 }else if (globaldata->Estimators[i] == "nseqs") {
46 cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
47 }else if (globaldata->Estimators[i] == "coverage") {
48 cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
49 }else if (globaldata->Estimators[i] == "ace") {
50 convert(globaldata->getAbund(), abund);
51 cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
52 }else if (globaldata->Estimators[i] == "jack") {
53 cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
54 }else if (globaldata->Estimators[i] == "shannon") {
55 cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
56 }else if (globaldata->Estimators[i] == "npshannon") {
57 cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
58 }else if (globaldata->Estimators[i] == "simpson") {
59 cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
60 }else if (globaldata->Estimators[i] == "bootstrap") {
61 cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
62 }else if (globaldata->Estimators[i] == "geometric") {
63 cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
64 }else if (globaldata->Estimators[i] == "qstat") {
65 cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
66 }else if (globaldata->Estimators[i] == "logseries") {
67 cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
68 }else if (globaldata->Estimators[i] == "bergerparker") {
69 cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
70 }else if (globaldata->Estimators[i] == "bstick") {
71 cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
72 }else if (globaldata->Estimators[i] == "goodscoverage") {
73 cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
78 //reset calc for next command
79 globaldata->setCalc("");
82 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
92 //**********************************************************************************************************************
94 CollectCommand::~CollectCommand(){
101 //**********************************************************************************************************************
103 int CollectCommand::execute(){
107 //if the users entered no valid calculators don't execute command
108 if (cDisplays.size() == 0) { return 0; }
110 read = new ReadOTUFile(globaldata->inputFileName);
111 read->read(&*globaldata);
113 order = globaldata->gorder;
114 input = globaldata->ginput;
115 set<string> orderList;
117 while(order != NULL){
119 orderList.insert(order->getLabel());
120 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
121 cCurve = new Collect(order, cDisplays);
122 convert(globaldata->getFreq(), freq);
123 cCurve->getCurve(freq);
127 cout << order->getLabel() << '\t' << count << endl;
131 order = (input->getOrderVector());
134 set<string>::iterator i;
135 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
136 if(orderList.count(*i) == 0)
137 cout << "'" << *i << "'" << " is not a valid label.\n";
138 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
141 catch(exception& e) {
142 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 //**********************************************************************************************************************