]> git.donarmstrong.com Git - mothur.git/blobdiff - summarycommand.cpp
added smart distance feature and optimized all commands using line by line processing
[mothur.git] / summarycommand.cpp
index 8c8a2aadf93440ab0e6271381e641bdae2167686..e7fda2e5dedcd8052b3c610931964377e356a7af 100644 (file)
 #include "qstat.h"
 #include "bergerparker.h"
 #include "bstick.h"
+#include "goodscoverage.h"
+#include "coverage.h"
+#include "efron.h"
+#include "boneh.h"
+#include "solow.h"
+#include "shen.h"
 
 //**********************************************************************************************************************
 
@@ -33,14 +39,15 @@ SummaryCommand::SummaryCommand(){
                
                for (i=0; i<globaldata->Estimators.size(); i++) {
                        if (validCalculator->isValidCalculator("summary", globaldata->Estimators[i]) == true) { 
-                       
                                if(globaldata->Estimators[i] == "sobs"){
                                        sumCalculators.push_back(new Sobs());
                                }else if(globaldata->Estimators[i] == "chao"){
                                        sumCalculators.push_back(new Chao1());
-                               }else if(globaldata->Estimators[i] == "geom"){
+                               }else if(globaldata->Estimators[i] == "coverage"){
+                                       sumCalculators.push_back(new Coverage());
+                               }else if(globaldata->Estimators[i] == "geometric"){
                                        sumCalculators.push_back(new Geom());
-                               }else if(globaldata->Estimators[i] == "logsd"){
+                               }else if(globaldata->Estimators[i] == "logseries"){
                                        sumCalculators.push_back(new LogSD());
                                }else if(globaldata->Estimators[i] == "qstat"){
                                        sumCalculators.push_back(new QStat());
@@ -65,6 +72,20 @@ SummaryCommand::SummaryCommand(){
                                        sumCalculators.push_back(new Bootstrap());
                                }else if (globaldata->Estimators[i] == "nseqs") { 
                                        sumCalculators.push_back(new NSeqs());
+                               }else if (globaldata->Estimators[i] == "goodscoverage") { 
+                                       sumCalculators.push_back(new GoodsCoverage());
+                               }else if (globaldata->Estimators[i] == "efron") { 
+                                       convert(globaldata->getSize(), size);
+                                       sumCalculators.push_back(new Efron(size));
+                               }else if (globaldata->Estimators[i] == "boneh") { 
+                                       convert(globaldata->getSize(), size);
+                                       sumCalculators.push_back(new Boneh(size));
+                               }else if (globaldata->Estimators[i] == "solow") { 
+                                       convert(globaldata->getSize(), size);
+                                       sumCalculators.push_back(new Solow(size));
+                               }else if (globaldata->Estimators[i] == "shen") { 
+                                       convert(globaldata->getSize(), size);
+                                       sumCalculators.push_back(new Shen(size));
                                }
                        }
                }
@@ -94,7 +115,8 @@ SummaryCommand::~SummaryCommand(){
 
 int SummaryCommand::execute(){
        try {
-       
+               int count = 1;
+               
                //if the users entered no valid calculators don't execute command
                if (sumCalculators.size() == 0) { return 0; }
 
@@ -102,9 +124,13 @@ int SummaryCommand::execute(){
                openOutputFile(outputFileName, outputFileHandle);
                outputFileHandle << "label";
        
-               read = new ReadPhilFile(globaldata->inputFileName);     
+               read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
-
+               
+               sabund = globaldata->sabund;
+               SAbundVector* lastSAbund = sabund;
+               input = globaldata->ginput;
+               
                for(int i=0;i<sumCalculators.size();i++){
                        if(sumCalculators[i]->getCols() == 1){
                                outputFileHandle << '\t' << sumCalculators[i]->getName();
@@ -115,28 +141,76 @@ int SummaryCommand::execute(){
                }
                outputFileHandle << endl;
                
-               sabund = globaldata->sabund;
-               input = globaldata->ginput;
-               int count = 1;
-               while(sabund != 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;
                
+               while((sabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){                      
        
                                cout << sabund->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(sabund->getLabel());
+                               userLabels.erase(sabund->getLabel());
+
                                
                                outputFileHandle << sabund->getLabel();
                                for(int i=0;i<sumCalculators.size();i++){
                                        vector<double> data = sumCalculators[i]->getValues(sabund);
                                        outputFileHandle << '\t';
-                                       //sumCalculators[i]->print(outputFileHandle);
+                                       sumCalculators[i]->print(outputFileHandle);
                                }
-                               
                                outputFileHandle << endl;
                        }
+                       
+                       if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) {
+
+                               cout << lastSAbund->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(lastSAbund->getLabel());
+                               userLabels.erase(lastSAbund->getLabel());
+                               
+                               outputFileHandle << lastSAbund->getLabel();
+                               for(int i=0;i<sumCalculators.size();i++){
+                                       vector<double> data = sumCalculators[i]->getValues(lastSAbund);
+                                       outputFileHandle << '\t';
+                                       sumCalculators[i]->print(outputFileHandle);
+                               }
+                               outputFileHandle << endl;
+                       }               
+
+                       if (count != 1) { delete lastSAbund; }
+                       lastSAbund = sabund;                    
+
                        sabund = input->getSAbundVector();
                        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(lastSAbund->getLabel()) != 1) {
+                               cout << ". I will use " << lastSAbund->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastSAbund->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastSAbund->getLabel() << '\t' << count << endl;
+                       outputFileHandle << lastSAbund->getLabel();
+                       for(int i=0;i<sumCalculators.size();i++){
+                               vector<double> data = sumCalculators[i]->getValues(lastSAbund);
+                               outputFileHandle << '\t';
+                               sumCalculators[i]->print(outputFileHandle);
+                       }
+                       outputFileHandle << endl;
+               }
+               
+               delete lastSAbund;
                return 0;
        }
        catch(exception& e) {