#include "rarefactcommand.h"
#include "ace.h"
#include "sobs.h"
+#include "nseqs.h"
#include "chao1.h"
#include "bootstrap.h"
#include "simpson.h"
#include "npshannon.h"
#include "shannon.h"
#include "jackknife.h"
+#include "coverage.h"
//**********************************************************************************************************************
globaldata = GlobalData::getInstance();
string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
+ convert(globaldata->getFreq(), freq);
+ convert(globaldata->getIters(), nIters);
+ validCalculator = new ValidCalculators();
+
int i;
- for (i=0; i<globaldata->rareEstimators.size(); i++) {
- if (globaldata->rareEstimators[i] == "sobs") {
- rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
- }else if (globaldata->rareEstimators[i] == "chao") {
- rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
- }else if (globaldata->rareEstimators[i] == "ace") {
- rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace")));
- }else if (globaldata->rareEstimators[i] == "jack") {
- rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
- }else if (globaldata->rareEstimators[i] == "shannon") {
- rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
- }else if (globaldata->rareEstimators[i] == "npshannon") {
- rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
- }else if (globaldata->rareEstimators[i] == "simpson") {
- rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
- }else if (globaldata->rareEstimators[i] == "bootstrap") {
- rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
+ for (i=0; i<globaldata->Estimators.size(); i++) {
+ if (validCalculator->isValidCalculator("rarefaction", globaldata->Estimators[i]) == true) {
+ if (globaldata->Estimators[i] == "sobs") {
+ rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
+ }else if (globaldata->Estimators[i] == "chao") {
+ rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
+ }else if (globaldata->Estimators[i] == "ace") {
+ convert(globaldata->getAbund(), abund);
+ if(abund < 5)
+ abund = 10;
+ rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace")));
+ }else if (globaldata->Estimators[i] == "jack") {
+ rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
+ }else if (globaldata->Estimators[i] == "shannon") {
+ rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
+ }else if (globaldata->Estimators[i] == "npshannon") {
+ rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
+ }else if (globaldata->Estimators[i] == "simpson") {
+ rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
+ }else if (globaldata->Estimators[i] == "bootstrap") {
+ rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
+ }else if (globaldata->Estimators[i] == "coverage") {
+ rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(fileNameRoot+"r_coverage")));
+ }else if (globaldata->Estimators[i] == "nseqs") {
+ rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(fileNameRoot+"r_nseqs")));
+ }
}
}
-
-
+
+ //reset calc for next command
+ globaldata->setCalc("");
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
int RareFactCommand::execute(){
try {
int count = 1;
- read = new ReadPhilFile(globaldata->inputFileName);
+
+ //if the users entered no valid calculators don't execute command
+ if (rDisplays.size() == 0) { return 0; }
+
+ read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
order = globaldata->gorder;
+ OrderVector* lastOrder = order;
input = globaldata->ginput;
-
- while(order != NULL){
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = globaldata->labels;
+ set<int> userLines = globaldata->lines;
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
+
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
rCurve = new Rarefact(order, rDisplays);
- convert(globaldata->getFreq(), freq);
- convert(globaldata->getIters(), nIters);
rCurve->getCurve(freq, nIters);
-
delete rCurve;
cout << order->getLabel() << '\t' << count << endl;
+ processedLabels.insert(order->getLabel());
+ userLabels.erase(order->getLabel());
+ userLines.erase(count);
}
-
+
+ if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+ rCurve = new Rarefact(lastOrder, rDisplays);
+ rCurve->getCurve(freq, nIters);
+ delete rCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ processedLabels.insert(lastOrder->getLabel());
+ userLabels.erase(lastOrder->getLabel());
+ }
+
+ if (count != 1) { delete lastOrder; }
+ lastOrder = order;
+
order = (input->getOrderVector());
count++;
+ }
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ cout << "Your file does not include the label "<< *it;
+ if (processedLabels.count(lastOrder->getLabel()) != 1) {
+ cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+ needToRun = true;
+ }else {
+ cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+ }
}
-
+
+ //run last line if you need to
+ if (needToRun == true) {
+ rCurve = new Rarefact(lastOrder, rDisplays);
+ rCurve->getCurve(freq, nIters);
+ delete rCurve;
+
+ cout << lastOrder->getLabel() << '\t' << count << endl;
+ }
+
+ delete lastOrder;
+
for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
return 0;
}