]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefactsharedcommand.cpp
fixed memory leak in rarefact
[mothur.git] / rarefactsharedcommand.cpp
index 4ed479555ab7ac66a75e789e71f9be5053ec3ae2..4a25cb3208f2695fc50308a8ff7df83deda163a8 100644 (file)
@@ -9,28 +9,34 @@
 
 #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();
+               util = new SharedUtil();
+                               
                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";
@@ -50,6 +56,7 @@ RareFactSharedCommand::~RareFactSharedCommand(){
        delete input;
        delete rCurve;
        delete read;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -57,12 +64,18 @@ RareFactSharedCommand::~RareFactSharedCommand(){
 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();
+               order = input->getSharedOrderVector();
+                               
+               //set users groups
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
                
                while(order != NULL){
                
@@ -78,17 +91,17 @@ int RareFactSharedCommand::execute(){
                                cout << order->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;
-                       }
-               
+                       //get next line to process
+                       delete order;
+                       order = input->getSharedOrderVector();
+                       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) {