5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "rarefactcommand.h"
15 #include "bootstrap.h"
17 #include "npshannon.h"
19 #include "jackknife.h"
22 //**********************************************************************************************************************
25 RareFactCommand::RareFactCommand(){
27 globaldata = GlobalData::getInstance();
29 fileNameRoot = getRootName(globaldata->inputFileName);
30 convert(globaldata->getFreq(), freq);
31 convert(globaldata->getIters(), nIters);
32 validCalculator = new ValidCalculators();
35 for (i=0; i<globaldata->Estimators.size(); i++) {
36 if (validCalculator->isValidCalculator("rarefaction", globaldata->Estimators[i]) == true) {
37 if (globaldata->Estimators[i] == "sobs") {
38 rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
39 }else if (globaldata->Estimators[i] == "chao") {
40 rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
41 }else if (globaldata->Estimators[i] == "ace") {
42 convert(globaldata->getAbund(), abund);
45 rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace")));
46 }else if (globaldata->Estimators[i] == "jack") {
47 rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
48 }else if (globaldata->Estimators[i] == "shannon") {
49 rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
50 }else if (globaldata->Estimators[i] == "npshannon") {
51 rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
52 }else if (globaldata->Estimators[i] == "simpson") {
53 rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
54 }else if (globaldata->Estimators[i] == "bootstrap") {
55 rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
56 }else if (globaldata->Estimators[i] == "coverage") {
57 rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(fileNameRoot+"r_coverage")));
58 }else if (globaldata->Estimators[i] == "nseqs") {
59 rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(fileNameRoot+"r_nseqs")));
64 //reset calc for next command
65 globaldata->setCalc("");
69 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 cout << "An unknown error has occurred in the RareFactCommand class function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
79 //**********************************************************************************************************************
81 RareFactCommand::~RareFactCommand(){
88 //**********************************************************************************************************************
90 int RareFactCommand::execute(){
94 //if the users entered no valid calculators don't execute command
95 if (rDisplays.size() == 0) { return 0; }
97 read = new ReadOTUFile(globaldata->inputFileName);
98 read->read(&*globaldata);
100 order = globaldata->gorder;
101 OrderVector* lastOrder = order;
102 input = globaldata->ginput;
104 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
105 set<string> processedLabels;
106 set<string> userLabels = globaldata->labels;
108 //as long as you are not at the end of the file or done wih the lines you want
109 while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
111 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
113 rCurve = new Rarefact(order, rDisplays);
114 rCurve->getCurve(freq, nIters);
117 cout << order->getLabel() << '\t' << count << endl;
118 processedLabels.insert(order->getLabel());
119 userLabels.erase(order->getLabel());
122 if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
123 rCurve = new Rarefact(lastOrder, rDisplays);
124 rCurve->getCurve(freq, nIters);
127 cout << lastOrder->getLabel() << '\t' << count << endl;
128 processedLabels.insert(lastOrder->getLabel());
129 userLabels.erase(lastOrder->getLabel());
132 if (count != 1) { delete lastOrder; }
135 order = (input->getOrderVector());
139 //output error messages about any remaining user labels
140 set<string>::iterator it;
141 bool needToRun = false;
142 for (it = userLabels.begin(); it != userLabels.end(); it++) {
143 cout << "Your file does not include the label "<< *it;
144 if (processedLabels.count(lastOrder->getLabel()) != 1) {
145 cout << ". I will use " << lastOrder->getLabel() << "." << endl;
148 cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
152 //run last line if you need to
153 if (needToRun == true) {
154 rCurve = new Rarefact(lastOrder, rDisplays);
155 rCurve->getCurve(freq, nIters);
158 cout << lastOrder->getLabel() << '\t' << count << endl;
163 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
166 catch(exception& e) {
167 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
171 cout << "An unknown error has occurred in the RareFactCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 //**********************************************************************************************************************