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);
40 validCalculator = new ValidCalculators();
41 for (i=0; i<globaldata->Estimators.size(); i++) {
42 if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) {
43 if (globaldata->Estimators[i] == "sobs") {
44 cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
45 }else if (globaldata->Estimators[i] == "chao") {
46 cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
47 }else if (globaldata->Estimators[i] == "nseqs") {
48 cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
49 }else if (globaldata->Estimators[i] == "coverage") {
50 cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
51 }else if (globaldata->Estimators[i] == "ace") {
52 convert(globaldata->getAbund(), abund);
53 cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
54 }else if (globaldata->Estimators[i] == "jack") {
55 cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
56 }else if (globaldata->Estimators[i] == "shannon") {
57 cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
58 }else if (globaldata->Estimators[i] == "npshannon") {
59 cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
60 }else if (globaldata->Estimators[i] == "simpson") {
61 cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
62 }else if (globaldata->Estimators[i] == "bootstrap") {
63 cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
64 }else if (globaldata->Estimators[i] == "geometric") {
65 cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
66 }else if (globaldata->Estimators[i] == "qstat") {
67 cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
68 }else if (globaldata->Estimators[i] == "logseries") {
69 cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
70 }else if (globaldata->Estimators[i] == "bergerparker") {
71 cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
72 }else if (globaldata->Estimators[i] == "bstick") {
73 cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
74 }else if (globaldata->Estimators[i] == "goodscoverage") {
75 cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
76 }else if (globaldata->Estimators[i] == "efron") {
77 convert(globaldata->getSize(), size);
78 cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
79 }else if (globaldata->Estimators[i] == "boneh") {
80 convert(globaldata->getSize(), size);
81 cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
82 }else if (globaldata->Estimators[i] == "solow") {
83 convert(globaldata->getSize(), size);
84 cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
85 }else if (globaldata->Estimators[i] == "shen") {
86 convert(globaldata->getSize(), size);
87 cDisplays.push_back(new CollectDisplay(new Shen(size), new OneColumnFile(fileNameRoot+"shen")));
92 //reset calc for next command
93 globaldata->setCalc("");
96 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 //**********************************************************************************************************************
108 CollectCommand::~CollectCommand(){
115 //**********************************************************************************************************************
117 int CollectCommand::execute(){
121 //if the users entered no valid calculators don't execute command
122 if (cDisplays.size() == 0) { return 0; }
124 read = new ReadOTUFile(globaldata->inputFileName);
125 read->read(&*globaldata);
127 order = globaldata->gorder;
128 input = globaldata->ginput;
129 set<string> orderList;
131 while(order != NULL){
133 orderList.insert(order->getLabel());
134 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
135 cCurve = new Collect(order, cDisplays);
136 convert(globaldata->getFreq(), freq);
137 cCurve->getCurve(freq);
141 cout << order->getLabel() << '\t' << count << endl;
145 order = (input->getOrderVector());
148 set<string>::iterator i;
149 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
150 if(orderList.count(*i) == 0)
151 cout << "'" << *i << "'" << " is not a valid label.\n";
152 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
155 catch(exception& e) {
156 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165 //**********************************************************************************************************************