2 * rarefactsharedcommand.cpp
5 * Created by Sarah Westcott on 1/6/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "rarefactsharedcommand.h"
11 #include "sharedsobs.h"
12 #include "sharednseqs.h"
14 //**********************************************************************************************************************
16 RareFactSharedCommand::RareFactSharedCommand(){
18 globaldata = GlobalData::getInstance();
20 fileNameRoot = getRootName(globaldata->inputFileName);
21 format = globaldata->getFormat();
22 validCalculator = new ValidCalculators();
25 for (i=0; i<globaldata->Estimators.size(); i++) {
26 if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) {
27 if (globaldata->Estimators[i] == "sharedobserved") {
28 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
29 }else if (globaldata->Estimators[i] == "sharednseqs") {
30 rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", "")));
36 //reset calc for next command
37 globaldata->setCalc("");
41 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 //**********************************************************************************************************************
53 RareFactSharedCommand::~RareFactSharedCommand(){
59 //**********************************************************************************************************************
61 int RareFactSharedCommand::execute(){
65 //if the users entered no valid calculators don't execute command
66 if (rDisplays.size() == 0) { return 0; }
68 read = new ReadOTUFile(globaldata->inputFileName);
69 read->read(&*globaldata);
71 input = globaldata->ginput;
72 lookup = input->getSharedRAbundVectors();
74 if (lookup.size() < 2) {
75 cout << "I cannot run the command without at least 2 valid groups.";
76 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
81 while(lookup[0] != NULL){
83 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
84 //create collectors curve
85 rCurve = new Rarefact(lookup, rDisplays);
86 convert(globaldata->getFreq(), freq);
87 convert(globaldata->getIters(), nIters);
88 rCurve->getSharedCurve(freq, nIters);
92 cout << lookup[0]->getLabel() << '\t' << count << endl;
96 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
98 //get next line to process
99 lookup = input->getSharedRAbundVectors();
103 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
105 //reset groups parameter
106 globaldata->Groups.clear(); globaldata->setGroups("");
110 catch(exception& e) {
111 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
115 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 //**********************************************************************************************************************