]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefactcommand.cpp
fixed memory leak in rarefact
[mothur.git] / rarefactcommand.cpp
index c2204e7a573969a2f4d1d80f41eb9defb3c53070..981f077969b1e734b2dc39fb05b372daa2a5f455 100644 (file)
 #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"
 
 //**********************************************************************************************************************
 
@@ -25,28 +27,41 @@ RareFactCommand::RareFactCommand(){
                globaldata = GlobalData::getInstance();
                string fileNameRoot;
                fileNameRoot = getRootName(globaldata->inputFileName);
+               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";
@@ -73,7 +88,11 @@ RareFactCommand::~RareFactCommand(){
 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;
@@ -92,7 +111,8 @@ int RareFactCommand::execute(){
                        
                                cout << order->getLabel() << '\t' << count << endl;
                        }
-               
+                       
+                       delete order;
                        order = (input->getOrderVector());
                        count++;