]> git.donarmstrong.com Git - mothur.git/blobdiff - getrabundcommand.cpp
added name option to read.tree for use in unifrac and parimony commands
[mothur.git] / getrabundcommand.cpp
index 04b1b0badcf7dfc009296ac145aa49da50a3de50..df9754b14219548719305cd53498b5d46b05d42c 100644 (file)
@@ -23,7 +23,7 @@ GetRAbundCommand::GetRAbundCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","sorted"};
+                       string Array[] =  {"label","sorted","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +36,12 @@ GetRAbundCommand::GetRAbundCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getListFile() == "") { mothurOut("You must read a listfile before you can use the get.rabund command."); mothurOutEndLine(); abort = true; }
                        
@@ -60,7 +66,7 @@ GetRAbundCommand::GetRAbundCommand(string option){
                        }
                                
                        if (abort == false) {
-                               filename = getRootName(globaldata->inputFileName) + "rabund";
+                               filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "rabund";
                                openOutputFile(filename, out);
                        }
                }
@@ -133,6 +139,8 @@ int GetRAbundCommand::execute(){
                        }
                        
                        if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+                                       string saveLabel = list->getLabel();
+                                       
                                        delete list;
                                        list = input->getListVector(lastLabel);
                                        
@@ -147,6 +155,9 @@ int GetRAbundCommand::execute(){
 
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
+                                       
+                                       //restore real lastlabel to save below
+                                       list->setLabel(saveLabel);
                        }
                        
                        lastLabel = list->getLabel();