]> git.donarmstrong.com Git - mothur.git/commitdiff
added smart distance feature and optimized all commands using line by line processing
authorwestcott <westcott>
Tue, 2 Jun 2009 16:02:18 +0000 (16:02 +0000)
committerwestcott <westcott>
Tue, 2 Jun 2009 16:02:18 +0000 (16:02 +0000)
30 files changed:
binsequencecommand.cpp
binsequencecommand.h
bootstrapsharedcommand.cpp
bootstrapsharedcommand.h
collectcommand.cpp
collectcommand.h
collectsharedcommand.cpp
errorchecking.cpp
getoturepcommand.cpp
getoturepcommand.h
globaldata.cpp
heatmapcommand.cpp
matrixoutputcommand.cpp
matrixoutputcommand.h
mothur.h
parselistcommand.cpp
parselistcommand.h
rarefactcommand.cpp
rarefactsharedcommand.cpp
shared.cpp
shared.h
sharedcommand.cpp
sharedrabundvector.cpp
sharedrabundvector.h
summarycommand.cpp
summarysharedcommand.cpp
summarysharedcommand.h
treegroupscommand.cpp
treegroupscommand.h
venncommand.cpp

index f1ba8b5f38effa755a215e93a87dcf322001dc6d..c21757850b858d4a53173619da911ffcab5d24a3 100644 (file)
@@ -53,7 +53,7 @@ BinSeqCommand::~BinSeqCommand(){
 int BinSeqCommand::execute(){
        try {
                int count = 1;
-               string binnames, name, sequence;
+               int error = 0;
                
                //read fastafile
                fasta->readFastaFile(in);
@@ -72,11 +72,117 @@ int BinSeqCommand::execute(){
                
                input = globaldata->ginput;
                list = globaldata->gListVector;
+               ListVector* lastList = list;
+               
+               //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(list != NULL){
+               while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                        
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
                                
+                               error = process(list, count);   
+                               if (error == 1) { return 0; }   
+                                                       
+                               processedLabels.insert(list->getLabel());
+                               userLabels.erase(list->getLabel());
+
+                       }
+                       
+                       if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+                               
+                               error = process(lastList, count);       
+                               if (error == 1) { return 0; }
+                                                                                                       
+                               processedLabels.insert(lastList->getLabel());
+                               userLabels.erase(lastList->getLabel());
+                               
+                       }
+                       
+                       if (count != 1) { delete lastList; }
+                       lastList = list;                        
+
+                       list = input->getListVector();
+                       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(lastList->getLabel()) != 1) {
+                               cout << ". I will use " << lastList->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       error = process(lastList, count);       
+                       if (error == 1) { return 0; }                   
+               }
+               
+               delete lastList;
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BinSeqCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
+void BinSeqCommand::readNamesFile() {
+       try {
+               vector<string> dupNames;
+               openInputFile(namesfile, inNames);
+               
+               string name, names, sequence;
+       
+               while(inNames){
+                       inNames >> name;                        //read from first column  A
+                       inNames >> names;               //read from second column  A,B,C,D
+                       
+                       dupNames.clear();
+                       
+                       //parse names into vector
+                       splitAtComma(names, dupNames);
+                       
+                       //store names in fasta map
+                       sequence = fasta->getSequence(name);
+                       for (int i = 0; i < dupNames.size(); i++) {
+                               fasta->push_back(dupNames[i], sequence);
+                       }
+               
+                       gobble(inNames);
+               }
+               inNames.close();
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function readNamesFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BinSeqCommand class function readNamesFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+//**********************************************************************************************************************
+//return 1 if error, 0 otherwise
+int BinSeqCommand::process(ListVector* list, int count) {
+       try {
+                               string binnames, name, sequence;
                                string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".fasta";
                                openOutputFile(outputFileName, out);
 
@@ -103,7 +209,7 @@ int BinSeqCommand::execute(){
                                                                if (group == "not found") {  
                                                                        cout << name << " is missing from your group file. Please correct. " << endl;
                                                                        remove(outputFileName.c_str());
-                                                                       return 0;
+                                                                       return 1;
                                                                }else{
                                                                        name = name + "|" + group + "|" + toString(i+1);
                                                                        out << ">" << name << endl;
@@ -113,7 +219,7 @@ int BinSeqCommand::execute(){
                                                }else { 
                                                        cout << name << " is missing from your fasta or name file. Please correct. " << endl; 
                                                        remove(outputFileName.c_str());
-                                                       return 0;
+                                                       return 1;
                                                }
                                                
                                        }
@@ -131,7 +237,7 @@ int BinSeqCommand::execute(){
                                                        if (group == "not found") {  
                                                                cout << binnames << " is missing from your group file. Please correct. " << endl;
                                                                remove(outputFileName.c_str());
-                                                               return 0;
+                                                               return 1;
                                                        }else{
                                                                binnames = binnames + "|" + group + "|" + toString(i+1);
                                                                out << ">" << binnames << endl;
@@ -141,56 +247,12 @@ int BinSeqCommand::execute(){
                                        }else { 
                                                cout << binnames << " is missing from your fasta or name file. Please correct. " << endl; 
                                                remove(outputFileName.c_str());
-                                               return 0;
+                                               return 1;
                                        }
-                                       
                                }
+                                       
                                out.close();
-                       }
-                       
-                       delete list;
-                       list = input->getListVector();
-                       count++;
-               }
-               
-               return 0;
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the BinSeqCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-}
-
-//**********************************************************************************************************************
-void BinSeqCommand::readNamesFile() {
-       try {
-               vector<string> dupNames;
-               openInputFile(namesfile, inNames);
-               
-               string name, names, sequence;
-       
-               while(inNames){
-                       inNames >> name;                        //read from first column  A
-                       inNames >> names;               //read from second column  A,B,C,D
-                       
-                       dupNames.clear();
-                       
-                       //parse names into vector
-                       splitAtComma(names, dupNames);
-                       
-                       //store names in fasta map
-                       sequence = fasta->getSequence(name);
-                       for (int i = 0; i < dupNames.size(); i++) {
-                               fasta->push_back(dupNames[i], sequence);
-                       }
-               
-                       gobble(inNames);
-               }
-               inNames.close();
+                               return 0;
 
        }
        catch(exception& e) {
@@ -205,4 +267,3 @@ void BinSeqCommand::readNamesFile() {
 //**********************************************************************************************************************
 
 
-
index e2ff648283a9c00569a8d2a4170a040b4a494902..bc2f883fe5f3e232d935780f7660e5a53647b18b 100644 (file)
@@ -40,6 +40,7 @@ private:
        ifstream in, inNames;
        
        void readNamesFile();
+       int process(ListVector*, int);
 };
 
 #endif
index 6b1f338661820d5f205556f9e62b347664e5cb4d..2835061392732dfa402f626a3d339726a601435a 100644 (file)
@@ -90,8 +90,6 @@ BootSharedCommand::~BootSharedCommand(){
 int BootSharedCommand::execute(){
        try {
                int count = 1;  
-               EstOutput data;
-               vector<SharedRAbundVector*> subset;
        
                //if the users entered no valid calculators don't execute command
                if (treeCalculators.size() == 0) { return 0; }
@@ -101,6 +99,11 @@ int BootSharedCommand::execute(){
                read->read(&*globaldata); 
                input = globaldata->ginput;
                order = input->getSharedOrderVector();
+               SharedOrderVector* lastOrder = order;
+               
+               //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 users groups
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup");
@@ -117,69 +120,57 @@ int BootSharedCommand::execute(){
                tmap->makeSim(globaldata->gGroupmap);
                globaldata->gTreemap = tmap;
                        
-               while(order != NULL){
+               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
                                
                                cout << order->getLabel() << '\t' << count << endl;
+                               process(order);
                                
-                               //open an ostream for each calc to print to
-                               for (int z = 0; z < treeCalculators.size(); z++) {
-                                       //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre";
-                                       openOutputFile(outputFile, *(out[z]));
-                               }
-                               
-                               //create a file for each calculator with the 1000 trees in it.
-                               for (int p = 0; p < iters; p++) {
-                                       
-                                       util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
-                               
-                                       //for each calculator                                                                                           
-                                       for(int i = 0 ; i < treeCalculators.size(); i++) {
-                                       
-                                               //initialize simMatrix
-                                               simMatrix.clear();
-                                               simMatrix.resize(numGroups);
-                                               for (int m = 0; m < simMatrix.size(); m++)      {
-                                                       for (int j = 0; j < simMatrix.size(); j++)      {
-                                                               simMatrix[m].push_back(0.0);
-                                                       }
-                                               }
-                               
-                                               //initialize index
-                                               index.clear();
-                                               for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
-                                                       
-                                               for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare
-                                                       for (int l = k; l < lookup.size(); l++) {
-                                                               if (k != l) { //we dont need to similiarity of a groups to itself
-                                                                       subset.clear(); //clear out old pair of sharedrabunds
-                                                                       //add new pair of sharedrabunds
-                                                                       subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
-                                                                       
-                                                                       //get estimated similarity between 2 groups
-                                                                       data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
-                                                                       //save values in similarity matrix
-                                                                       simMatrix[k][l] = data[0];
-                                                                       simMatrix[l][k] = data[0];
-                                                               }
-                                                       }
-                                               }
+                               processedLabels.insert(order->getLabel());
+                               userLabels.erase(order->getLabel());
                                
-                                               //creates tree from similarity matrix and write out file
-                                               createTree(out[i]);
-                                       }
-                               }
-                               //close ostream for each calc
-                               for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); }
+                       //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)) {
+                                                                                       
+                               cout << lastOrder->getLabel() << '\t' << count << endl;
+                               process(lastOrder);
+
+                               processedLabels.insert(lastOrder->getLabel());
+                               userLabels.erase(lastOrder->getLabel());
+                       }
+                       
+                       if (count != 1) { delete lastOrder; }
+                       lastOrder = order;                      
+
                        //get next line to process
                        order = input->getSharedOrderVector();
                        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(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)  {
+                       process(lastOrder);                     
+                       cout << lastOrder->getLabel() << '\t' << count << endl;
+               }
+               
+               delete lastOrder;
+
                //reset groups parameter
                globaldata->Groups.clear();  globaldata->setGroups("");
 
@@ -293,5 +284,73 @@ void BootSharedCommand::printSims() {
        }               
 }
 /***********************************************************/
+void BootSharedCommand::process(SharedOrderVector* order) {
+       try{
+                               EstOutput data;
+                               vector<SharedRAbundVector*> subset;
+                               
+                               //open an ostream for each calc to print to
+                               for (int z = 0; z < treeCalculators.size(); z++) {
+                                       //create a new filename
+                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre";
+                                       openOutputFile(outputFile, *(out[z]));
+                               }
+                               
+                               //create a file for each calculator with the 1000 trees in it.
+                               for (int p = 0; p < iters; p++) {
+                                       
+                                       util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
+                               
+                                       //for each calculator                                                                                           
+                                       for(int i = 0 ; i < treeCalculators.size(); i++) {
+                                       
+                                               //initialize simMatrix
+                                               simMatrix.clear();
+                                               simMatrix.resize(numGroups);
+                                               for (int m = 0; m < simMatrix.size(); m++)      {
+                                                       for (int j = 0; j < simMatrix.size(); j++)      {
+                                                               simMatrix[m].push_back(0.0);
+                                                       }
+                                               }
+                               
+                                               //initialize index
+                                               index.clear();
+                                               for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
+                                                       
+                                               for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare
+                                                       for (int l = k; l < lookup.size(); l++) {
+                                                               if (k != l) { //we dont need to similiarity of a groups to itself
+                                                                       subset.clear(); //clear out old pair of sharedrabunds
+                                                                       //add new pair of sharedrabunds
+                                                                       subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
+                                                                       
+                                                                       //get estimated similarity between 2 groups
+                                                                       data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
+                                                                       //save values in similarity matrix
+                                                                       simMatrix[k][l] = data[0];
+                                                                       simMatrix[l][k] = data[0];
+                                                               }
+                                                       }
+                                               }
+                               
+                                               //creates tree from similarity matrix and write out file
+                                               createTree(out[i]);
+                                       }
+                               }
+                               //close ostream for each calc
+                               for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BootSharedCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BootSharedCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************/
+
 
 
index 322cd28571d83ea08d080fb6c4098fbff1c67364..b632acede61e9f06c576ea236e7eac4b7c896153 100644 (file)
@@ -12,7 +12,6 @@
  
 #include "command.hpp"
 #include "sharedordervector.h"
-#include "sharedlistvector.h"
 #include "inputdata.h"
 #include "groupmap.h"
 #include "readotu.h"
@@ -33,6 +32,8 @@ public:
 private:
        void createTree(ostream*);
        void printSims();
+       void process(SharedOrderVector*);
+       
        
        GlobalData* globaldata;
        SharedUtil* util;
@@ -45,7 +46,6 @@ private:
        map<int, int> index;  //maps row in simMatrix to vector index in the tree       
        InputData* input;
        ValidCalculators* validCalculator;
-       SharedListVector* SharedList;
        SharedOrderVector* order;
        vector<SharedRAbundVector*> lookup;
        string format, outputFile;
index d317a06aff4ebf68557a081475cd15a4df58c86a..01f2fff68b93596a52fc60703bce790559b0fbec 100644 (file)
@@ -36,8 +36,10 @@ CollectCommand::CollectCommand(){
                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") { 
@@ -125,31 +127,68 @@ int CollectCommand::execute(){
                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;
+               
+               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.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());
+                       
+                       //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());
                        }
                        
-                       delete order;
+                       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) {
index 8057f9ff78fc1f749a986772f53664ae4e03c75d..7c5ec4278bf75e95043b28ea68eda32e54b17837 100644 (file)
@@ -45,6 +45,7 @@ private:
        GlobalData* globaldata;
        ReadOTUFile* read;
        OrderVector* order;
+       OrderVector* lastOrder;
        InputData* input;
        Collect* cCurve;
        ValidCalculators* validCalculator;
index 582628d8f6a98151efb9a525bf9cdc26383be379..fd28e841faee71bf35ed49a3f6ff21e4455cb8fa 100644 (file)
@@ -42,6 +42,7 @@ CollectSharedCommand::CollectSharedCommand(){
                string fileNameRoot;
                fileNameRoot = getRootName(globaldata->inputFileName);
                format = globaldata->getFormat();
+               convert(globaldata->getFreq(), freq);
                validCalculator = new ValidCalculators();
                util = new SharedUtil();
                
@@ -134,39 +135,74 @@ int CollectSharedCommand::execute(){
                        
                input = globaldata->ginput;
                order = input->getSharedOrderVector();
+               SharedOrderVector* lastOrder = order;
                
-               set<string> orderList;
-               
+               //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 users groups
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
                util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
 
-               while(order != NULL){
+               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
 
-                       orderList.insert(order->getLabel());
-                       
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
                                
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);
-                               convert(globaldata->getFreq(), freq);
                                cCurve->getSharedCurve(freq);
-                       
                                delete cCurve;
                        
                                cout << order->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(order->getLabel());
+                               userLabels.erase(order->getLabel());
+
+                       //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)) {
+                               //create collectors curve
+                               cCurve = new Collect(lastOrder, cDisplays);
+                               cCurve->getSharedCurve(freq);
+                               delete cCurve;
+                       
+                               cout << lastOrder->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(lastOrder->getLabel());
+                               userLabels.erase(lastOrder->getLabel());
                        }
                        
+                       if (count != 1) { delete lastOrder; }
+                       lastOrder = order;                      
+                       
                        //get next line to process
-                       delete order;
                        order = input->getSharedOrderVector();
                        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";
-                               
+               
+               //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];    }       
                
                //reset groups parameter
index e4c1877907e272c89a0be023ec21ad6bf2947f50..39fb17e47a4e2f72692f5d5be15f19866fca2bef 100644 (file)
@@ -298,6 +298,7 @@ bool ErrorCheck::checkInput(string input) {
                                errorFree = false;
                        }
                        if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
+                       if (fastafile == "") { cout << "fasta is a required parameter for the get.oturep command." << endl; errorFree = false; }
                        validateBinFiles();
                } 
 
index e5f87c25f014afe8be7dda943e6f0b5e3e255908..acb9372ff173b211685ea555531643966f8addc1 100644 (file)
@@ -62,8 +62,6 @@ GetOTURepCommand::GetOTURepCommand(){
 //**********************************************************************************************************************
 
 GetOTURepCommand::~GetOTURepCommand(){
-       delete matrix;
-       delete list;
        delete input;
        delete read;
        delete fasta;
@@ -77,7 +75,7 @@ GetOTURepCommand::~GetOTURepCommand(){
 int GetOTURepCommand::execute(){
        try {
                int count = 1;
-               string nameRep, name, sequence;
+               int error;
                
                //read fastafile
                fasta->readFastaFile(in);
@@ -96,50 +94,66 @@ int GetOTURepCommand::execute(){
                
                input = globaldata->ginput;
                list = globaldata->gListVector;
+               ListVector* lastList = list;
                
-               while(list != 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((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                        
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
-                               
-                               //create output file
-                               string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".rep.fasta";
-                               openOutputFile(outputFileName, out);
-
-                               cout << list->getLabel() << '\t' << count << endl;
-                               
-                               //for each bin in the list vector
-                               for (int i = 0; i < list->size(); i++) {
-                                       string groups;
-                                       nameRep = FindRep(i, groups);
+                                       cout << list->getLabel() << '\t' << count << endl;
+                                       error = process(list);
+                                       if (error == 1) { return 0; } //there is an error in hte input files, abort command
                                        
-                                       //print out name and sequence for that bin
-                                       sequence = fasta->getSequence(nameRep);
-
-                                       if (sequence != "not found") {
-                                               if (groupfile == "") {
-                                                       nameRep = nameRep + "|" + toString(i+1);
-                                                       out << ">" << nameRep << endl;
-                                                       out << sequence << endl;
-                                               }else {
-                                                       nameRep = nameRep + "|" + groups + "|" + toString(i+1);
-                                                       out << ">" << nameRep << endl;
-                                                       out << sequence << endl;
-                                               }
-                                       }else { 
-                                               cout << nameRep << " is missing from your fasta or name file. Please correct. " << endl; 
-                                               remove(outputFileName.c_str());
-                                               return 0;
-                                       }
-                               }
-                               
-                               out.close();
+                                       processedLabels.insert(list->getLabel());
+                                       userLabels.erase(list->getLabel());
+                       }
+                       
+                       if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+                                       cout << lastList->getLabel() << '\t' << count << endl;
+                                       error = process(lastList);
+                                       if (error == 1) { return 0; } //there is an error in hte input files, abort command
+                                       
+                                       processedLabels.insert(lastList->getLabel());
+                                       userLabels.erase(lastList->getLabel());
                        }
                        
+                       if (count != 1) { delete lastList; }
+                       lastList = list;                        
+                       
                        list = input->getListVector();
                        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(lastList->getLabel()) != 1) {
+                               cout << ". I will use " << lastList->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastList->getLabel() << '\t' << count << endl;
+                       error = process(lastList);
+                       if (error == 1) { return 0; } //there is an error in hte input files, abort command
+               }
+               delete lastList;
+               
+               delete matrix;
+               globaldata->gSparseMatrix = NULL;
+               delete list;
+               globaldata->gListVector = NULL;
+
                return 0;
        }
        catch(exception& e) {
@@ -191,7 +205,7 @@ void GetOTURepCommand::readNamesFile() {
        }       
 }
 //**********************************************************************************************************************
-string GetOTURepCommand::FindRep(int bin, string& group) {
+string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
        try{
                vector<string> names;
                map<string, float> sums;
@@ -203,7 +217,7 @@ string GetOTURepCommand::FindRep(int bin, string& group) {
                map<string, string> groups;
                map<string, string>::iterator groupIt;
                
-               binnames = list->get(bin);
+               binnames = thisList->get(bin);
        
                //parse names into vector
                splitAtComma(binnames, names);
@@ -282,6 +296,56 @@ string GetOTURepCommand::FindRep(int bin, string& group) {
        }       
 }
 
+//**********************************************************************************************************************
+int GetOTURepCommand::process(ListVector* processList) {
+       try{
+                               string nameRep, name, sequence;
+
+                               //create output file
+                               string outputFileName = getRootName(globaldata->getListFile()) + processList->getLabel() + ".rep.fasta";
+                               openOutputFile(outputFileName, out);
+                               
+                               //for each bin in the list vector
+                               for (int i = 0; i < processList->size(); i++) {
+                                       string groups;
+                                       nameRep = FindRep(i, groups, processList);
+                                       
+                                       //print out name and sequence for that bin
+                                       sequence = fasta->getSequence(nameRep);
+
+                                       if (sequence != "not found") {
+                                               if (groupfile == "") {
+                                                       nameRep = nameRep + "|" + toString(i+1);
+                                                       out << ">" << nameRep << endl;
+                                                       out << sequence << endl;
+                                               }else {
+                                                       nameRep = nameRep + "|" + groups + "|" + toString(i+1);
+                                                       out << ">" << nameRep << endl;
+                                                       out << sequence << endl;
+                                               }
+                                       }else { 
+                                               cout << nameRep << " is missing from your fasta or name file. Please correct. " << endl; 
+                                               remove(outputFileName.c_str());
+                                               return 1;
+                                       }
+                               }
+                               
+                               out.close();
+                               return 0;
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GetOTURepCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GetOTURepCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
+
 
 
 
index deafc78c5512edc5039a0425910aaa979eb8f639..8153c3645fc5de028a6a9812426889297991ab85 100644 (file)
@@ -52,7 +52,8 @@ private:
        map<string, int>::iterator it3;
        
        void readNamesFile();
-       string FindRep(int, string&); // returns name of "representative" sequence of given bin. //and fill a string containing the groups in that bin if a groupfile is given
+       int process(ListVector*);
+       string FindRep(int, string&, ListVector*); // returns name of "representative" sequence of given bin. //and fill a string containing the groups in that bin if a groupfile is given
 
 };
 
index 405e646a5276e9afa8acaa2b5d0dee776e35b94e..a8e88c52ffbd9d9fe9bb711d4be2cf0c361c9212 100644 (file)
@@ -97,21 +97,22 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                                if (key == "gapopen")           { gapopen = value;              }
                                if (key == "gapextend" )        { gapextend = value;    }
                                
-                               if (key == "line") {//stores lines to be used in a set
+                               if (key == "line") {//stores lines to be used in a vector
                                        lines.clear();
                                        labels.clear();
                                        line = value;
                                        label = "";
-                                       splitAtDash(value, lines);
-                                       allLines = 0;
+                                       if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
+                                       else { allLines = 1;  }
                                }
-                               if (key == "label") {//stores labels to be used in a set
+                       
+                               if (key == "label") {//stores lines to be used in a vector
                                        labels.clear();
                                        lines.clear();
                                        label = value;
                                        line = "";
-                                       splitAtDash(value, labels);
-                                       allLines = 0;
+                                       if (label != "all") {  splitAtDash(value, labels);  allLines = 0;  }
+                                       else { allLines = 1;  }
                                }
 
                                if (key == "groups") {//stores groups to be used in a vector
index 09dfb5a15bde8e52a967c1ef9cdae0e4130a0b3a..c9f6ae524fe7121d59b6538f061830ad522182cd 100644 (file)
@@ -40,6 +40,8 @@ HeatMapCommand::~HeatMapCommand(){
 int HeatMapCommand::execute(){
        try {
                int count = 1;  
+               RAbundVector* lastRAbund;
+               vector<SharedRAbundVector*> lastLookup;
        
                if (format == "sharedfile") {
                        //you have groups
@@ -48,50 +50,126 @@ int HeatMapCommand::execute(){
                        
                        input = globaldata->ginput;
                        lookup = input->getSharedRAbundVectors();
+                       lastLookup = lookup;
                }else if (format == "list") {
                        //you are using just a list file and have only one group
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
                        
                        rabund = globaldata->rabund;
+                       lastRAbund = globaldata->rabund;
                        input = globaldata->ginput;             
                }
                
+               //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;
+
                if (format != "list") { 
                
-                       while(lookup[0] != NULL){
+                       //as long as you are not at the end of the file or done wih the lines you want
+                       while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
        
                                        cout << lookup[0]->getLabel() << '\t' << count << endl;
                                        heatmap->getPic(lookup);
+                                       
+                                       processedLabels.insert(lookup[0]->getLabel());
+                                       userLabels.erase(lookup[0]->getLabel());
                                }
                                
-                               //prevent memory leak
-                               for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                               if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                                       heatmap->getPic(lastLookup);
+                                       
+                                       processedLabels.insert(lastLookup[0]->getLabel());
+                                       userLabels.erase(lastLookup[0]->getLabel());
+                               }
                                
+                               //prevent memory leak
+                               if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                               lastLookup = lookup;                    
+
                                //get next line to process
                                lookup = input->getSharedRAbundVectors();                               
                                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(lastLookup[0]->getLabel()) != 1) {
+                                       cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                                       needToRun = true;
+                               }else {
+                                       cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                               }
+                       }
+               
+                       //run last line if you need to
+                       if (needToRun == true)  {
+                               cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                               heatmap->getPic(lastLookup);
+                       }
+               
+                       for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+                       
                        //reset groups parameter
                        globaldata->Groups.clear();  
                        
                }else{
                
-                       while(rabund != NULL){
-               
+                       while((rabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){                      
        
                                        cout << rabund->getLabel() << '\t' << count << endl;
                                        heatmap->getPic(rabund);
+                                       
+                                       processedLabels.insert(rabund->getLabel());
+                                       userLabels.erase(rabund->getLabel());
                                }
                                
-                               delete rabund;
+                               if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastRAbund->getLabel()) != 1)) {
+
+                                       cout << lastRAbund->getLabel() << '\t' << count << endl;
+                                       heatmap->getPic(lastRAbund);
+                                       
+                                       processedLabels.insert(lastRAbund->getLabel());
+                                       userLabels.erase(lastRAbund->getLabel());
+                               }               
+                               
+                               if (count != 1) { delete lastRAbund; }
+                               lastRAbund = rabund;                    
+
                                rabund = input->getRAbundVector();
                                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(lastRAbund->getLabel()) != 1) {
+                                       cout << ". I will use " << lastRAbund->getLabel() << "." << endl;
+                                       needToRun = true;
+                               }else {
+                                       cout << ". Please refer to " << lastRAbund->getLabel() << "." << endl;
+                               }
+                       }
+               
+                       //run last line if you need to
+                       if (needToRun == true)  {
+                               cout << lastRAbund->getLabel() << '\t' << count << endl;
+                               heatmap->getPic(lastRAbund);
+                       }
+               
+                       delete lastRAbund;
+
                }
                
                globaldata->setGroups("");
index c792cc91e966203505733979cf9133a025393912..3ecf6df36e5ea33266d409fecee2620aec7a2d9f 100644 (file)
@@ -79,9 +79,7 @@ MatrixOutputCommand::~MatrixOutputCommand(){
 int MatrixOutputCommand::execute(){
        try {
                int count = 1;  
-               EstOutput data;
-               vector<SharedRAbundVector*> subset;
-               
+                               
                //if the users entered no valid calculators don't execute command
                if (matrixCalculators.size() == 0) { cout << "No valid calculators." << endl; return 0; }
 
@@ -91,62 +89,66 @@ int MatrixOutputCommand::execute(){
                        
                input = globaldata->ginput;
                lookup = input->getSharedRAbundVectors();
+               vector<SharedRAbundVector*> lastLookup = lookup;
+               
+               //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;
                                
                if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; return 0;}
                
                numGroups = globaldata->Groups.size();
                                
-               while(lookup[0] != NULL){
+               //as long as you are not at the end of the file or done wih the lines you want
+               while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
-                               
                                cout << lookup[0]->getLabel() << '\t' << count << endl;
+                               process(lookup);
                                
-                               //for each calculator                                                                                           
-                               for(int i = 0 ; i < matrixCalculators.size(); i++) {
-                                       
-                                       //initialize simMatrix
-                                       simMatrix.clear();
-                                       simMatrix.resize(numGroups);
-                                       for (int m = 0; m < simMatrix.size(); m++)      {
-                                               for (int j = 0; j < simMatrix.size(); j++)      {
-                                                       simMatrix[m].push_back(0.0);
-                                               }
-                                       }
-                               
-                                       for (int k = 0; k < lookup.size(); k++) { 
-                                               for (int l = k; l < lookup.size(); l++) {
-                                                       if (k != l) { //we dont need to similiarity of a groups to itself
-                                                               //get estimated similarity between 2 groups
-                                                               
-                                                               subset.clear(); //clear out old pair of sharedrabunds
-                                                               //add new pair of sharedrabunds
-                                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
-                                                               
-                                                               data = matrixCalculators[i]->getValues(subset); //saves the calculator outputs
-                                                               //save values in similarity matrix
-                                                               simMatrix[k][l] = 1.0 - data[0];  //convert similiarity to distance
-                                                               simMatrix[l][k] = 1.0 - data[0];  //convert similiarity to distance
-                                                       }
-                                               }
-                                       }
-                                       
-                                       exportFileName = getRootName(globaldata->inputFileName) + matrixCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".dist";
-                                       openOutputFile(exportFileName, out);
-                                       printSims(out);
-                                       out.close();
-                                       
-                               }
+                               processedLabels.insert(lookup[0]->getLabel());
+                               userLabels.erase(lookup[0]->getLabel());
                        }
                        
+                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                               cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                               process(lastLookup);
+                               
+                               processedLabels.insert(lastLookup[0]->getLabel());
+                               userLabels.erase(lastLookup[0]->getLabel());
+                       }
+
                        //prevent memory leak
-                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
+                       if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                       lastLookup = lookup;                    
                        
                        //get next line to process
                        lookup = input->getSharedRAbundVectors();
                        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(lastLookup[0]->getLabel()) != 1) {
+                               cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                       process(lastLookup);            
+               }
+               
+               for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+
+               
                //reset groups parameter
                globaldata->Groups.clear();  globaldata->setGroups("");
 
@@ -187,5 +189,61 @@ void MatrixOutputCommand::printSims(ostream& out) {
        }               
 }
 /***********************************************************/
+void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
+       try {
+       
+                               EstOutput data;
+                               vector<SharedRAbundVector*> subset;
+
+                               //for each calculator                                                                                           
+                               for(int i = 0 ; i < matrixCalculators.size(); i++) {
+                                       
+                                       //initialize simMatrix
+                                       simMatrix.clear();
+                                       simMatrix.resize(numGroups);
+                                       for (int m = 0; m < simMatrix.size(); m++)      {
+                                               for (int j = 0; j < simMatrix.size(); j++)      {
+                                                       simMatrix[m].push_back(0.0);
+                                               }
+                                       }
+                               
+                                       for (int k = 0; k < thisLookup.size(); k++) { 
+                                               for (int l = k; l < thisLookup.size(); l++) {
+                                                       if (k != l) { //we dont need to similiarity of a groups to itself
+                                                               //get estimated similarity between 2 groups
+                                                               
+                                                               subset.clear(); //clear out old pair of sharedrabunds
+                                                               //add new pair of sharedrabunds
+                                                               subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
+                                                               
+                                                               data = matrixCalculators[i]->getValues(subset); //saves the calculator outputs
+                                                               //save values in similarity matrix
+                                                               simMatrix[k][l] = 1.0 - data[0];  //convert similiarity to distance
+                                                               simMatrix[l][k] = 1.0 - data[0];  //convert similiarity to distance
+                                                       }
+                                               }
+                                       }
+                                       
+                                       exportFileName = getRootName(globaldata->inputFileName) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
+                                       openOutputFile(exportFileName, out);
+                                       printSims(out);
+                                       out.close();
+                                       
+                               }
+
+       
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the MatrixOutputCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the MatrixOutputCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************/
+
 
 
index 04d0ccbf8e46145591acca443d37039809da88d0..547b567c62e67c01d2dcce2b4cd573c5ad1c08bc 100644 (file)
@@ -30,6 +30,7 @@ public:
        
 private:
        void printSims(ostream&);
+       void process(vector<SharedRAbundVector*>);
        
        GlobalData* globaldata;
        ReadOTUFile* read;
@@ -41,6 +42,7 @@ private:
        string exportFileName;
        int numGroups;
        ofstream out;
+       
 
 };
        
index 2c9595ebe53c4055179f2297372bb1e691fff8ab..07bb971347d974066ab5449614172c5e68d4c2a6 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -73,6 +73,19 @@ inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
 }
 //**********************************************************************************************************************
 
+template<typename T>
+inline bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+       {
+               return false;
+       } 
+       return true;
+}
+
+//**********************************************************************************************************************
+
 template<typename T>
 inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
        istringstream i(s);
@@ -465,8 +478,87 @@ inline bool inUsersGroups(string groupname, vector<string> Groups) {
        }
 }
 
-/**************************************************************************************************/
+/***********************************************************************/
+//this function determines if the user has given us labels that are smaller than the given label.
+//if so then it returns true so that the calling function can run the previous valid distance.
+//it's a "smart" distance function.  It also checks for invalid labels.
+inline bool anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
+       try {
+               set<string>::iterator it;
+               vector<float> orderFloat;
+               map<string, float> userMap;  //the conversion process removes trailing 0's which we need to put back
+               map<string, float>::iterator it2;
+               float labelFloat;
+               bool smaller = false;
+               
+               //unique is the smallest line
+               if (label == "unique") {  return false;  }
+               else { convert(label, labelFloat); }
+               
+               //go through users set and make them floats
+               for(it = userLabels.begin(); it != userLabels.end(); ++it) {
+                       
+                       float temp;
+                       if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
+                               convert(*it, temp);
+                               orderFloat.push_back(temp);
+                               userMap[*it] = temp;
+                       }else if (*it == "unique") { 
+                               orderFloat.push_back(-1.0);
+                               userMap["unique"] = -1.0;
+                       }else {
+                               if (errorOff == "") {  cout << *it << " is not a valid label." << endl;  }
+                               userLabels.erase(*it); 
+                               it--;
+                       }
+               }
+               
+               //sort order
+               sort(orderFloat.begin(), orderFloat.end());
+               
+               /*************************************************/
+               //is this label bigger than any of the users labels
+               /*************************************************/
+                               
+               //loop through order until you find a label greater than label
+               for (int i = 0; i < orderFloat.size(); i++) {
+                       if (orderFloat[i] < labelFloat) {
+                               smaller = true;
+                               if (orderFloat[i] == -1) { 
+                                       if (errorOff == "") { cout << "Your file does not include the label unique." <<  endl; }
+                                       userLabels.erase("unique");
+                               }
+                               else {  
+                                       if (errorOff == "") { cout << "Your file does not include the label "; }
+                                       string s = "";
+                                       for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {  
+                                               if (it2->second == orderFloat[i]) {  
+                                                       s = it2->first;  
+                                                       //remove small labels
+                                                       userLabels.erase(s);
+                                                       break;
+                                               }
+                                       }
+                                       if (errorOff == "") { cout << s << ". I will use the next smallest distance. "  <<  endl; }
+                               }
+                       //since they are sorted once you find a bigger one stop looking
+                       }else { break; }
+               }
+               
+               return smaller;
+                                               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function anyLabelsToProcess. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function anyLabelsToProcess. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
 
+}
 
+/**************************************************************************************************/
 #endif
 
index f1447980cd918a6f712447a928621cb689f35efe..20f92f73b3e8107bd47a1e99f253779e67d2a423 100644 (file)
@@ -17,7 +17,8 @@ ParseListCommand::ParseListCommand(){
                //read in group map info.
                groupMap = new GroupMap(globaldata->getGroupFile());
                groupMap->readMap();
-                       
+
+               
                //fill filehandles with neccessary ofstreams
                int i;
                ofstream* temp;
@@ -44,7 +45,7 @@ ParseListCommand::ParseListCommand(){
        }
 }
 /***********************************************************************/
-void ParseListCommand::parse(int index) {
+void ParseListCommand::parse(int index, SharedListVector* list) {
        try {
                string prefix, suffix, groupsName;
                suffix = list->get(index);
@@ -93,49 +94,71 @@ int ParseListCommand::execute(){
                        read->read(&*globaldata); 
                        input = globaldata->ginput;
                        list = globaldata->gSharedList;
+                       SharedListVector* lastList = list;
+               
+                       //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;
 
                        //read in group map info.
                        groupMap = new GroupMap(globaldata->getGroupFile());
                        groupMap->readMap();
                        
-                       string seq, label;
-                       int i;
                        //create new list vectors to fill with parsed data
-                       for (i=0; i<groupMap->getNumGroups(); i++) {
+                       for (int i=0; i<groupMap->getNumGroups(); i++) {
                                groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector();
                        }
                        
+                                               
                        //parses and sets each groups listvector
-                       while(list != NULL){
-                               label = list->getLabel();
-                               
-                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(label) == 1){
-                               
-                                       for(i=0; i<list->size(); i++) {
-                                               parse(i); //parses data[i] list of sequence names
-                                               for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
-                                                       seq = it->second;
-                                                       seq = seq.substr(1, seq.length()); //rips off extra comma
-                                                       groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
-                                               }
-                                               listGroups.clear();
-                                       }
-                                       //prints each new list file
-                                       for (i=0; i<groupMap->getNumGroups(); i++) {
-                                               groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label);
-                                               groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
-                                               groupOfLists[groupMap->namesOfGroups[i]]->clear();
-                                       }
+                       //as long as you are not at the end of the file or done wih the lines you want
+                       while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                                                               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
+                                       cout << list->getLabel() << '\t' << count << endl;
+                                       process(list);
                                        
-                                       cout << label << '\t' << count << endl;
+                                       processedLabels.insert(list->getLabel());
+                                       userLabels.erase(list->getLabel());
                                }
                                
+                               if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+                                       cout << lastList->getLabel() << '\t' << count << endl;
+                                       process(lastList);
+                                       
+                                       processedLabels.insert(lastList->getLabel());
+                                       userLabels.erase(lastList->getLabel());
+                               }
+
+                               if (count != 1) { delete lastList; }
+                               lastList = list;                        
+
                                list = input->getSharedListVector();
                                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(lastList->getLabel()) != 1) {
+                                       cout << ". I will use " << lastList->getLabel() << "." << endl;
+                                       needToRun = true;
+                               }else {
+                                       cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+                               }
+                       }
+               
+                       //run last line if you need to
+                       if (needToRun == true)  {
+                               cout << lastList->getLabel() << '\t' << count << endl;
+                               process(lastList);
+                       }
+                       delete lastList;
+
                        //set groupmap for .shared commands
-                       //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
+                       if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
                        globaldata->gGroupmap = groupMap; 
                        
                        return 0;
@@ -158,3 +181,33 @@ ParseListCommand::~ParseListCommand(){
        delete read;    
 }
 //**********************************************************************************************************************
+void ParseListCommand::process(SharedListVector* thisList) {
+       try {
+                       string seq;
+
+                       for(int i=0; i<thisList->size(); i++) {
+                               parse(i, thisList); //parses data[i] list of sequence names
+                               for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
+                                       seq = it->second;
+                                       seq = seq.substr(1, seq.length()); //rips off extra comma
+                                       groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+                               }
+                               listGroups.clear();
+                       }
+                       //prints each new list file
+                       for (int i=0; i<groupMap->getNumGroups(); i++) {
+                               groupOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
+                               groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+                               groupOfLists[groupMap->namesOfGroups[i]]->clear();
+                       }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ParseListCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
\ No newline at end of file
index 0477acdb06e26ada0f64a25370138a75dc7a06ff..4aa4ccdae8d9235299156bdfbc15b9c47e5b6866 100644 (file)
@@ -43,9 +43,9 @@ private:
        SharedListVector* list;
        map<string, string> listGroups; //maps group name to sequences from that group in a specific OTU
        map<string, string>::iterator it;
-       map<string, SharedListVector*>::iterator it2;
        map<string, ofstream*>::iterator it3;
-       void parse(int);
+       void parse(int, SharedListVector*);
+       void process(SharedListVector*);
        string fileroot;
 };
 
index 981f077969b1e734b2dc39fb05b372daa2a5f455..752ff62298ed183f18e033982b1e0c20513bd963 100644 (file)
@@ -27,6 +27,8 @@ RareFactCommand::RareFactCommand(){
                globaldata = GlobalData::getInstance();
                string fileNameRoot;
                fileNameRoot = getRootName(globaldata->inputFileName);
+               convert(globaldata->getFreq(), freq);
+               convert(globaldata->getIters(), nIters);
                validCalculator = new ValidCalculators();
                
                int i;
@@ -96,28 +98,68 @@ int RareFactCommand::execute(){
                read->read(&*globaldata); 
 
                order = globaldata->gorder;
+               OrderVector* lastOrder = order;
                input = globaldata->ginput;
-       
-               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;
+       
+               //as long as you are not at the end of the file or done wih the lines you want
+               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
                        
                                rCurve = new Rarefact(order, rDisplays);
-                               convert(globaldata->getFreq(), freq);
-                               convert(globaldata->getIters(), nIters);
                                rCurve->getCurve(freq, nIters);
-                       
                                delete rCurve;
                        
                                cout << order->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(order->getLabel());
+                               userLabels.erase(order->getLabel());
+                       }
+                       
+                       if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
+                               rCurve = new Rarefact(lastOrder, rDisplays);
+                               rCurve->getCurve(freq, nIters);
+                               delete rCurve;
+                       
+                               cout << lastOrder->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(lastOrder->getLabel());
+                               userLabels.erase(lastOrder->getLabel());
                        }
                        
-                       delete order;
+                       if (count != 1) { delete lastOrder; }
+                       lastOrder = order;                      
+
                        order = (input->getOrderVector());
                        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(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)  {
+                       rCurve = new Rarefact(lastOrder, rDisplays);
+                       rCurve->getCurve(freq, nIters);
+                       delete rCurve;
+                       
+                       cout << lastOrder->getLabel() << '\t' << count << endl;
+               }
+               
+               delete lastOrder;
+
                for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
                return 0;
        }
index 0928d2e6b439b9775e62b5abd8c91b4254216e67..efcbe8437c0ba18902d493ef3a2c7abfe420c960 100644 (file)
@@ -19,6 +19,8 @@ RareFactSharedCommand::RareFactSharedCommand(){
                string fileNameRoot;
                fileNameRoot = getRootName(globaldata->inputFileName);
                format = globaldata->getFormat();
+               convert(globaldata->getFreq(), freq);
+               convert(globaldata->getIters(), nIters);
                validCalculator = new ValidCalculators();
                                
                int i;
@@ -70,36 +72,74 @@ int RareFactSharedCommand::execute(){
                        
                input = globaldata->ginput;
                lookup = input->getSharedRAbundVectors();
+               vector<SharedRAbundVector*> lastLookup = lookup;
                
                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(lookup[0] != 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;
+       
+               //as long as you are not at the end of the file or done wih the lines you want
+               while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
-                               //create collectors curve
+                               
                                rCurve = new Rarefact(lookup, rDisplays);
-                               convert(globaldata->getFreq(), freq);
-                               convert(globaldata->getIters(), nIters);
                                rCurve->getSharedCurve(freq, nIters);
-                       
                                delete rCurve;
                        
                                cout << lookup[0]->getLabel() << '\t' << count << endl;
+                               processedLabels.insert(lookup[0]->getLabel());
+                               userLabels.erase(lookup[0]->getLabel());
                        }
                        
-                       //prevent memory leak
-                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
+                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                                       rCurve = new Rarefact(lastLookup, rDisplays);
+                                       rCurve->getSharedCurve(freq, nIters);
+                                       delete rCurve;
+
+                                       processedLabels.insert(lastLookup[0]->getLabel());
+                                       userLabels.erase(lastLookup[0]->getLabel());
+                       }
                                
+                       //prevent memory leak
+                       if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                       lastLookup = lookup;
+                       
                        //get next line to process
                        lookup = input->getSharedRAbundVectors();
                        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(lastLookup[0]->getLabel()) != 1) {
+                               cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                       rCurve = new Rarefact(lastLookup, rDisplays);
+                       rCurve->getSharedCurve(freq, nIters);
+                       delete rCurve;
+               }
+               
+               for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+
                for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
                
                //reset groups parameter
index 91c4ce5f3411971484f8849aa0510b3a289c7a62..73f283ae7b697c95ec5eacf5195a809162ca94a8 100644 (file)
@@ -16,7 +16,7 @@ Shared::Shared(){
 }
 
 /**************************************************************************************************/
-void Shared::getSharedVectors(int index, SharedListVector* list) {
+void Shared::getSharedVectors(SharedListVector* list) {
                string label, group;
                int i,j;
                label = list->getLabel();
index 7445b5ad52c0c69d0548e65b8438681e95430ad9..a3f55d5215d5f4b722f069bf53c2501e419eaec4 100644 (file)
--- a/shared.h
+++ b/shared.h
@@ -20,8 +20,8 @@ using namespace std;
 class Shared {
        public:
                Shared();
-               ~Shared();
-               void getSharedVectors(int, SharedListVector*);
+               ~Shared() {};
+               void getSharedVectors(SharedListVector*);
                map<string, SharedRAbundVector*> sharedGroups; //string is groupname, SharedVector* is out info for that group
                
        private:
index c29d5499808e13bd9246098f50706337b3f9e592..b4de07b082fb0274c02ba71793c0e3023d192a35 100644 (file)
@@ -36,26 +36,70 @@ SharedCommand::SharedCommand(){
 int SharedCommand::execute(){
        try {
                globaldata = GlobalData::getInstance();
+               int count = 1;
+               string errorOff = "no error";
                        
                //read in listfile
                read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
                input = globaldata->ginput;
                SharedList = globaldata->gSharedList;
+               SharedListVector* lastList = SharedList;
+               
+               //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;
                
                shared = new Shared();
-               int i = 0;
-               while(SharedList != NULL){
                
-                       if(globaldata->allLines == 1 || globaldata->lines.count(i+1) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
+               while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       
+                                               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
                        
-                               shared->getSharedVectors(i, SharedList); //fills sharedGroups with new info and updates sharedVector
-                               printSharedData(); //prints info to the .shared file
+                                       shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
+                                       printSharedData(); //prints info to the .shared file
+                               
+                                       processedLabels.insert(SharedList->getLabel());
+                                       userLabels.erase(SharedList->getLabel());
                        }
                        
+                       if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
+                                       shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
+                                       printSharedData(); //prints info to the .shared file
+
+                                       processedLabels.insert(lastList->getLabel());
+                                       userLabels.erase(lastList->getLabel());
+                       }
+                       
+                       if (count != 1) { delete lastList; }
+                       lastList = SharedList;                  
+
                        SharedList = input->getSharedListVector(); //get new list vector to process
-                       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(lastList->getLabel()) != 1) {
+                               //cout << ". I will use " << lastList->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
+                       printSharedData(); //prints info to the .shared file
+               }
+               
+               delete lastList;
+               delete shared;
+               
                return 0;
        }
        catch(exception& e) {
@@ -93,6 +137,7 @@ void SharedCommand::printSharedData() {
 SharedCommand::~SharedCommand(){
        //delete list;
        delete read;
+       
 }
 
 //**********************************************************************************************************************
index 386017d9367f7eed2e5bfd984ffedb775a26a31a..ca24b91fdc9ffde552be61dbcd09730e32ec9aa5 100644 (file)
@@ -153,12 +153,6 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0),
 
 /***********************************************************************/
 
-SharedRAbundVector::~SharedRAbundVector() {
-
-}
-
-/***********************************************************************/
-
 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
        try {
                int oldBinSize = data[binNumber].abundance;
index 0c71394689e8aad4d522e5f1ba6948466b218f56..8944a26b871b22ddc01ade5837770773dd62ee36 100644 (file)
@@ -32,7 +32,7 @@ public:
        //SharedRAbundVector(string, vector<int>);
        SharedRAbundVector(const SharedRAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs){};
     SharedRAbundVector(ifstream&);
-       ~SharedRAbundVector();
+       ~SharedRAbundVector(){};
 
        int getNumBins();               
        int getNumSeqs();                                                       
index b649582758636370f812a51cf182ce7813bc3e02..e7fda2e5dedcd8052b3c610931964377e356a7af 100644 (file)
@@ -115,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; }
 
@@ -125,7 +126,11 @@ int SummaryCommand::execute(){
        
                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();
@@ -136,14 +141,18 @@ 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++){
@@ -151,13 +160,57 @@ int SummaryCommand::execute(){
                                        outputFileHandle << '\t';
                                        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) {
index d1d1be0bf4f21879e20429bc5e292273f1cda59a..fafc290b0cdf8dd9bce4c7cb626797c6bf1ba4af 100644 (file)
@@ -133,6 +133,7 @@ int SummarySharedCommand::execute(){
                        
                input = globaldata->ginput;
                lookup = input->getSharedRAbundVectors();
+               vector<SharedRAbundVector*> lastLookup = lookup;
                
                //output estimator names as column headers
                outputFileHandle << "label" <<'\t' << "comparison" << '\t'; 
@@ -165,29 +166,98 @@ int SummarySharedCommand::execute(){
                        return 0;
                }
                                        
+               //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(lookup[0] != NULL){
+               //as long as you are not at the end of the file or done wih the lines you want
+               while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
-       
                                cout << lookup[0]->getLabel() << '\t' << count << endl;
+                               process(lookup);
                                
+                               processedLabels.insert(lookup[0]->getLabel());
+                               userLabels.erase(lookup[0]->getLabel());
+                       }
+                       
+                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                                       process(lastLookup);
+                                       
+                                       processedLabels.insert(lastLookup[0]->getLabel());
+                                       userLabels.erase(lastLookup[0]->getLabel());
+                       }
+
+               
+                       //prevent memory leak
+                       if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                       lastLookup = lookup;                    
+                               
+                       //get next line to process
+                       lookup = input->getSharedRAbundVectors();
+                       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(lastLookup[0]->getLabel()) != 1) {
+                               cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                       process(lastLookup);
+               }
+               
+               for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+               
+               //close files
+               outputFileHandle.close();
+               if (mult == true) {  outAll.close();  }
+
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************/
+void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
+       try {
                                //loop through calculators and add to file all for all calcs that can do mutiple groups
                                if (mult == true) {
                                        //output label
-                                       outAll << lookup[0]->getLabel() << '\t';
+                                       outAll << thisLookup[0]->getLabel() << '\t';
                                        
                                        //output groups names
                                        string outNames = "";
-                                       for (int j = 0; j < lookup.size(); j++) {
-                                               outNames += lookup[j]->getGroup() +  "-";
+                                       for (int j = 0; j < thisLookup.size(); j++) {
+                                               outNames += thisLookup[j]->getGroup() +  "-";
                                        }
                                        outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
                                        outAll << outNames << '\t';
                                        
                                        for(int i=0;i<sumCalculators.size();i++){
                                                if (sumCalculators[i]->getMultiple() == true) { 
-                                                       sumCalculators[i]->getValues(lookup);
+                                                       sumCalculators[i]->getValues(thisLookup);
                                                        outAll << '\t';
                                                        sumCalculators[i]->print(outAll);
                                                }
@@ -197,20 +267,20 @@ int SummarySharedCommand::execute(){
        
                                int n = 1; 
                                vector<SharedRAbundVector*> subset;
-                               for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
-                                       for (int l = n; l < lookup.size(); l++) {
+                               for (int k = 0; k < (thisLookup.size() - 1); k++) { // pass cdd each set of groups to commpare
+                                       for (int l = n; l < thisLookup.size(); l++) {
                                                
-                                               outputFileHandle << lookup[0]->getLabel() << '\t';
+                                               outputFileHandle << thisLookup[0]->getLabel() << '\t';
                                                
                                                subset.clear(); //clear out old pair of sharedrabunds
                                                //add new pair of sharedrabunds
-                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
+                                               subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
                                                
                                                //sort groups to be alphanumeric
-                                               if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
-                                                       outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
+                                               if (thisLookup[k]->getGroup() > thisLookup[l]->getGroup()) {
+                                                       outputFileHandle << (thisLookup[l]->getGroup() +'\t' + thisLookup[k]->getGroup()) << '\t'; //print out groups
                                                }else{
-                                                       outputFileHandle << (lookup[k]->getGroup() +'\t' + lookup[l]->getGroup()) << '\t'; //print out groups
+                                                       outputFileHandle << (thisLookup[k]->getGroup() +'\t' + thisLookup[l]->getGroup()) << '\t'; //print out groups
                                                }
                                                
                                                for(int i=0;i<sumCalculators.size();i++) {
@@ -223,33 +293,16 @@ int SummarySharedCommand::execute(){
                                        }
                                        n++;
                                }
-                       }
-               
-                       //prevent memory leak
-                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
-                               
-                       //get next line to process
-                       lookup = input->getSharedRAbundVectors();
-                       count++;
-               }
-               
-               //reset groups parameter
-               globaldata->Groups.clear();  globaldata->setGroups("");
-               
-               //close files
-               outputFileHandle.close();
-               if (mult == true) {  outAll.close();  }
 
-               return 0;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
        catch(...) {
-               cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "An unknown error has occurred in the SummarySharedCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }               
 }
 
-/***********************************************************/
+/***********************************************************/
\ No newline at end of file
index e73714a3e294f0af471838d38beb39b49d8c1938..0f2f75386b23382699fbb2b524268fee373dfc25 100644 (file)
@@ -53,6 +53,7 @@ private:
        string outputFileName, format, outAllFileName;
        ofstream outputFileHandle, outAll;
        bool mult;
+       void process(vector<SharedRAbundVector*>);
 
 };
 
index a21c47afcb1df45fc858c4877c43cc7fe9a586e2..7f97ef3e31bb802b01aa0f86eb2262c50b230ac8 100644 (file)
@@ -94,6 +94,7 @@ int TreeGroupCommand::execute(){
                        
                        input = globaldata->ginput;
                        lookup = input->getSharedRAbundVectors();
+                       lastLookup = lookup;
                        
                        if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; return 0; }
                
@@ -314,11 +315,7 @@ void TreeGroupCommand::makeSimsDist() {
 void TreeGroupCommand::makeSimsShared() {
        try {
                int count = 1;  
-               EstOutput data;
-               vector<SharedRAbundVector*> subset;
        
-               numGroups = globaldata->Groups.size();
-               
                //clear globaldatas old tree names if any
                globaldata->Treenames.clear();
                
@@ -330,11 +327,75 @@ void TreeGroupCommand::makeSimsShared() {
                tmap->makeSim(globaldata->gGroupmap);
                globaldata->gTreemap = tmap;
                
-               while(lookup[0] != NULL){
+               set<string> processedLabels;
+               set<string> userLabels = globaldata->labels;
+
+               //as long as you are not at the end of the file or done wih the lines you want
+               while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
-                               
                                cout << lookup[0]->getLabel() << '\t' << count << endl;
+                               process(lookup);
+                               
+                               processedLabels.insert(lookup[0]->getLabel());
+                               userLabels.erase(lookup[0]->getLabel());
+                       }
+                       
+                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                               cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                               process(lastLookup);
+                                       
+                               processedLabels.insert(lastLookup[0]->getLabel());
+                               userLabels.erase(lastLookup[0]->getLabel());
+                       }
+
+                       //prevent memory leak
+                       if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                       lastLookup = lookup;                    
+                       
+                       //get next line to process
+                       lookup = input->getSharedRAbundVectors();
+                       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(lastLookup[0]->getLabel()) != 1) {
+                               cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                               needToRun = true;
+                       }else {
+                               cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                       }
+               }
+               
+               //run last line if you need to
+               if (needToRun == true)  {
+                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                       process(lastLookup);
+               }
+               
+               for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+               for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************/
+void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
+       try{
+                               EstOutput data;
+                               vector<SharedRAbundVector*> subset;
+                               numGroups = globaldata->Groups.size();
                                
                                //for each calculator                                                                                           
                                for(int i = 0 ; i < treeCalculators.size(); i++) {
@@ -352,16 +413,16 @@ void TreeGroupCommand::makeSimsShared() {
                                        for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
                
                                        //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".tre";                             
+                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                         
                                                                                                
-                                       for (int k = 0; k < lookup.size(); k++) { 
-                                               for (int l = k; l < lookup.size(); l++) {
+                                       for (int k = 0; k < thisLookup.size(); k++) { 
+                                               for (int l = k; l < thisLookup.size(); l++) {
                                                        if (k != l) { //we dont need to similiarity of a groups to itself
                                                                //get estimated similarity between 2 groups
                                                                
                                                                subset.clear(); //clear out old pair of sharedrabunds
                                                                //add new pair of sharedrabunds
-                                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
+                                                               subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
                                                                
                                                                data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
                                                                //save values in similarity matrix
@@ -374,28 +435,18 @@ void TreeGroupCommand::makeSimsShared() {
                                        //creates tree from similarity matrix and write out file
                                        createTree();
                                }
-                       }
-                       
-                       //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 < treeCalculators.size(); i++) {  delete treeCalculators[i]; }
+
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
        catch(...) {
-               cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "An unknown error has occurred in the TreeGroupCommand class function process. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }               
 }
-
 /***********************************************************/
 
+       
 
index 3f145e92b4780fa4f40a45ed1849150dafffc800..989c699c877ead1e27ea20a1c59a53a901bfa71a 100644 (file)
@@ -58,10 +58,13 @@ private:
        InputData* input;
        ValidCalculators* validCalculator;
        vector<SharedRAbundVector*> lookup;
+       vector<SharedRAbundVector*> lastLookup;
        string format, outputFile, groupNames, filename;
        int numGroups;
        ofstream out;
        float precision, cutoff;
+       //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+       void process(vector<SharedRAbundVector*>);
 
 };
        
index ced4c4851180c05d03399feb780010b7a3d9e697..519e6cbec1be64d87fbb1af2f54208df1e04e46f 100644 (file)
@@ -87,7 +87,9 @@ VennCommand::~VennCommand(){
 
 int VennCommand::execute(){
        try {
-               int count = 1;  
+               int count = 1;
+               SAbundVector* lastSAbund;
+               vector<SharedRAbundVector*> lastLookup; 
                
                //if the users entered no valid calculators don't execute command
                if (vennCalculators.size() == 0) { return 0; }
@@ -99,60 +101,138 @@ int VennCommand::execute(){
                        
                        input = globaldata->ginput;
                        lookup = input->getSharedRAbundVectors();
+                       lastLookup = lookup;
                }else if (format == "list") {
                        //you are using just a list file and have only one group
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
                
                        sabund = globaldata->sabund;
+                       lastSAbund = globaldata->sabund;
                        input = globaldata->ginput;
                }
-
+               
+               //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;
                
                if (format != "list") { 
                        
-                       while(lookup[0] != NULL){
+                       //as long as you are not at the end of the file or done wih the lines you want
+                       while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
                
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
-       
                                        cout << lookup[0]->getLabel() << '\t' << count << endl;
+                                       processedLabels.insert(lookup[0]->getLabel());
+                                       userLabels.erase(lookup[0]->getLabel());
                                        
                                        if (lookup.size() > 4) {
                                                cout << "Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile." << endl;
-                                               for (int i = lookup.size(); i > 3; i--) { delete lookup[i]; lookup.pop_back(); }
+                                               for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
                                        }
-                               
-                                       //util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
                                        venn->getPic(lookup, vennCalculators);
                                }
                                
-                               //prevent memory leak
-                               for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
+                               if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
+                                       cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                                       processedLabels.insert(lastLookup[0]->getLabel());
+                                       userLabels.erase(lastLookup[0]->getLabel());
+
+                                       if (lastLookup.size() > 4) {
+                                               cout << "Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile." << endl;
+                                               for (int i = lastLookup.size(); i > 4; i--) { lastLookup.pop_back(); } //no memmory leak because pop_back calls destructor
+                                       }                               
+                                       venn->getPic(lastLookup, vennCalculators);
+                               }
                                
+                               //prevent memory leak
+                               if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
+                               lastLookup = lookup;    
+                                               
                                //get next line to process
                                lookup = input->getSharedRAbundVectors();
                                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(lastLookup[0]->getLabel()) != 1) {
+                                       cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
+                                       needToRun = true;
+                               }else {
+                                       cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
+                               }
+                       }
+               
+                       //run last line if you need to
+                       if (needToRun == true)  {
+                               cout << lastLookup[0]->getLabel() << '\t' << count << endl;
+                               if (lastLookup.size() > 4) {
+                                       cout << "Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile." << endl;
+                                       for (int i = lastLookup.size(); i > 3; i--) { delete lastLookup[i]; lastLookup.pop_back(); }
+                               }                               
+                               venn->getPic(lastLookup, vennCalculators);
+                       }
+               
+                       for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  }
+
                        //reset groups parameter
                        globaldata->Groups.clear();  
                        
                }else{
                
-                       while(sabund != NULL){
+                       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;
                                        venn->getPic(sabund, vennCalculators);
+                                       
+                                       processedLabels.insert(sabund->getLabel());
+                                       userLabels.erase(sabund->getLabel());
                                }
                                
-                               delete sabund;
+                               if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastSAbund->getLabel()) != 1)) {
+
+                                       cout << lastSAbund->getLabel() << '\t' << count << endl;
+                                       venn->getPic(lastSAbund, vennCalculators);
+                                       
+                                       processedLabels.insert(lastSAbund->getLabel());
+                                       userLabels.erase(lastSAbund->getLabel());
+                               }               
+                               
+                               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;
+                               venn->getPic(lastSAbund, vennCalculators);
+                       }
+                       delete lastSAbund;
                }
                
+               
                globaldata->setGroups("");
                return 0;
        }