]> git.donarmstrong.com Git - mothur.git/blobdiff - getrabundcommand.cpp
changed how we do "smart" distancing
[mothur.git] / getrabundcommand.cpp
index 0dfaa63129e8269b7446bad82ae38290760643a0..b8c692bf7f64b4566311a3f9232f933aec100800 100644 (file)
@@ -126,7 +126,7 @@ int GetRAbundCommand::execute(){
                        
                input = globaldata->ginput;
                list = globaldata->gListVector;
-               ListVector* lastList = list;
+               string lastLabel = list->getLabel();
                
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> processedLabels;
@@ -148,20 +148,23 @@ int GetRAbundCommand::execute(){
                                        userLines.erase(count);
                        }
                        
-                       if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
-                                       cout << lastList->getLabel() << '\t' << count << endl;
+                       if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+                                       delete list;
+                                       list = input->getListVector(lastLabel);
+                                       
+                                       cout << list->getLabel() << '\t' << count << endl;
                                        rabund = new RAbundVector();
-                                       *rabund = (lastList->getRAbundVector());
+                                       *rabund = (list->getRAbundVector());
                                        rabund->print(out);
                                        delete rabund;
 
-                                       processedLabels.insert(lastList->getLabel());
-                                       userLabels.erase(lastList->getLabel());
+                                       processedLabels.insert(list->getLabel());
+                                       userLabels.erase(list->getLabel());
                        }
                        
-                       if (count != 1) { delete lastList; }
-                       lastList = list;                        
+                       lastLabel = list->getLabel();           
                        
+                       delete list;
                        list = input->getListVector();
                        count++;
                }
@@ -171,23 +174,26 @@ int GetRAbundCommand::execute(){
                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;
+                       if (processedLabels.count(lastLabel) != 1) {
+                               cout << ". I will use " << lastLabel << "." << endl;
                                needToRun = true;
                        }else {
-                               cout << ". Please refer to " << lastList->getLabel() << "." << endl;
+                               cout << ". Please refer to " << lastLabel << "." << endl;
                        }
                }
                
                //run last line if you need to
                if (needToRun == true)  {
-                       cout << lastList->getLabel() << '\t' << count << endl;
+                       delete list;
+                       list = input->getListVector(lastLabel);
+                       
+                       cout << list->getLabel() << '\t' << count << endl;
                        rabund = new RAbundVector();
-                       *rabund = (lastList->getRAbundVector());
+                       *rabund = (list->getRAbundVector());
                        rabund->print(out);
                        delete rabund;
+                       delete list;
                }
-               delete lastList;
 
                out.close(); 
                return 0;