#include "rarefactsharedcommand.h"
#include "sharedsobs.h"
+#include "sharednseqs.h"
//**********************************************************************************************************************
RareFactSharedCommand::RareFactSharedCommand(){
try {
globaldata = GlobalData::getInstance();
- string fileNameRoot, groups;
+ string fileNameRoot;
fileNameRoot = getRootName(globaldata->inputFileName);
- groupmap = globaldata->gGroupmap;
-
- //initialize groups for label
- groups = "";
- for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {
- groups = groups + groupmap->namesOfGroups[i];
- }
-
+ format = globaldata->getFormat();
+ validCalculator = new ValidCalculators();
+
int i;
- for (i=0; i<globaldata->sharedRareEstimators.size(); i++) {
- if (globaldata->sharedRareEstimators[i] == "sharedobserved") {
- rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"sharedObserved", groups)));
+ for (i=0; i<globaldata->Estimators.size(); i++) {
+ if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) {
+ if (globaldata->Estimators[i] == "sharedobserved") {
+ rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
+ }else if (globaldata->Estimators[i] == "sharednseqs") {
+ rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", "")));
+ }
+
}
}
+
+ //reset calc for next command
+ globaldata->setCalc("");
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
//**********************************************************************************************************************
RareFactSharedCommand::~RareFactSharedCommand(){
- delete order;
delete input;
delete rCurve;
delete read;
int RareFactSharedCommand::execute(){
try {
int count = 1;
- read = new ReadPhilFile(globaldata->inputFileName);
- read->read(&*globaldata);
+ //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);
+
input = globaldata->ginput;
- list = globaldata->glist;
- order = list->getSharedOrderVector();
+ lookup = input->getSharedRAbundVectors();
+
+ if (lookup.size() < 2) {
+ cout << "I cannot run the command without at least 2 valid groups.";
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ return 0;
+ }
+
- while(order != NULL){
+ while(lookup[0] != NULL){
- if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+ if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
//create collectors curve
- rCurve = new Rarefact(order, rDisplays);
+ rCurve = new Rarefact(lookup, rDisplays);
convert(globaldata->getFreq(), freq);
convert(globaldata->getIters(), nIters);
rCurve->getSharedCurve(freq, nIters);
delete rCurve;
- cout << order->getLabel() << '\t' << count << endl;
+ cout << lookup[0]->getLabel() << '\t' << count << endl;
}
- list = input->getListVector(); //get new list vector to process
- if (list != NULL) {
- order = list->getSharedOrderVector(); //gets new order vector with group info.
- count++;
- }else {
- break;
- }
-
+ //prevent memory leak
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+
+ //get next line to process
+ lookup = input->getSharedRAbundVectors();
+ count++;
}
for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
+
+ //reset groups parameter
+ globaldata->Groups.clear(); globaldata->setGroups("");
+
return 0;
}
catch(exception& e) {