]> git.donarmstrong.com Git - mothur.git/blobdiff - collectcommand.cpp
added get.rabund and get.sabund command and fixed bug introduced by line by line...
[mothur.git] / collectcommand.cpp
index b3e8d8fbfa817900f6f1802310d9c18680bc1c15..3d7f1b0fead598d628491f6214ed3701bd65edea 100644 (file)
 #include "logsd.h"
 #include "bergerparker.h"
 #include "bstick.h"
+#include "goodscoverage.h"
+#include "efron.h"
+#include "boneh.h"
+#include "solow.h"
+#include "shen.h"
+#include "coverage.h"
 
 
 //**********************************************************************************************************************
-
-
 CollectCommand::CollectCommand(){
        try {
                globaldata = GlobalData::getInstance();
                string fileNameRoot;
                fileNameRoot = getRootName(globaldata->inputFileName);
+               convert(globaldata->getFreq(), freq);
                int i;
                validCalculator = new ValidCalculators();
+               
                for (i=0; i<globaldata->Estimators.size(); i++) {
                        if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { 
                                if (globaldata->Estimators[i] == "sobs") { 
@@ -42,6 +48,8 @@ CollectCommand::CollectCommand(){
                                        cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
                                }else if (globaldata->Estimators[i] == "nseqs") { 
                                        cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
+                               }else if (globaldata->Estimators[i] == "coverage") { 
+                                       cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
                                }else if (globaldata->Estimators[i] == "ace") { 
                                        convert(globaldata->getAbund(), abund);
                                        cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
@@ -55,16 +63,30 @@ CollectCommand::CollectCommand(){
                                        cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
                                }else if (globaldata->Estimators[i] == "bootstrap") { 
                                        cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
-                               }else if (globaldata->Estimators[i] == "geom") { 
-                                       cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geom")));
+                               }else if (globaldata->Estimators[i] == "geometric") { 
+                                       cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
                                }else if (globaldata->Estimators[i] == "qstat") { 
                                        cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
-                               }else if (globaldata->Estimators[i] == "logsd") { 
-                                       cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logsd")));
+                               }else if (globaldata->Estimators[i] == "logseries") { 
+                                       cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
                                }else if (globaldata->Estimators[i] == "bergerparker") { 
                                        cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
                                }else if (globaldata->Estimators[i] == "bstick") { 
-                                       cDisplays.push_back(new CollectDisplay(new BStick(), new OneColumnFile(fileNameRoot+"bstick")));
+                                       cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
+                               }else if (globaldata->Estimators[i] == "goodscoverage") { 
+                                       cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
+                               }else if (globaldata->Estimators[i] == "efron") {
+                                       convert(globaldata->getSize(), size); 
+                                       cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
+                               }else if (globaldata->Estimators[i] == "boneh") {
+                                       convert(globaldata->getSize(), size); 
+                                       cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
+                               }else if (globaldata->Estimators[i] == "solow") {
+                                       convert(globaldata->getSize(), size); 
+                                       cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
+                               }else if (globaldata->Estimators[i] == "shen") {
+                                       convert(globaldata->getSize(), size); 
+                                       cDisplays.push_back(new CollectDisplay(new Shen(size), new OneColumnFile(fileNameRoot+"shen")));
                                }
                        }
                }
@@ -101,33 +123,74 @@ int CollectCommand::execute(){
                //if the users entered no valid calculators don't execute command
                if (cDisplays.size() == 0) { return 0; }
 
-               read = new ReadPhilFile(globaldata->inputFileName);     
+               read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
                
                order = globaldata->gorder;
+               lastOrder = order;
                input = globaldata->ginput;
-               set<string> orderList;  
                
-               while(order != 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;
+               set<int> userLines = globaldata->lines;
+               
+               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
                
-                       orderList.insert(order->getLabel());
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                               
                                cCurve = new Collect(order, cDisplays);
-                               convert(globaldata->getFreq(), freq);
                                cCurve->getCurve(freq);
-                       
                                delete cCurve;
                        
                                cout << order->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(order->getLabel());
+                               userLabels.erase(order->getLabel());
+                               userLines.erase(count);
+                       
+                       //you have a label the user want that is smaller than this line and the last line has not already been processed 
                        }
+                       
+                       if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+                               cCurve = new Collect(lastOrder, cDisplays);
+                               cCurve->getCurve(freq);
+                               delete cCurve;
+                       
+                               cout << lastOrder->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(lastOrder->getLabel());
+                               userLabels.erase(lastOrder->getLabel());
+                       }
+                       
+                       if (count != 1) { delete lastOrder; }
+                       lastOrder = order;                      
                        order = (input->getOrderVector());
                        count++;
                }
-               set<string>::iterator i;
-               for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
-                       if(orderList.count(*i) == 0)
-                               cout << "'" << *i << "'" << " is not a valid label.\n";
-               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
+               
+               //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(lastOrder->getLabel()) != 1) {
+                               cout << ". I will use " << lastOrder->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cCurve = new Collect(lastOrder, cDisplays);
+                       cCurve->getCurve(freq);
+                       delete cCurve;
+                       
+                       cout << lastOrder->getLabel() << '\t' << count << endl;
+               }
+               
+               delete lastOrder;
+               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
                return 0;
        }
        catch(exception& e) {