]> git.donarmstrong.com Git - mothur.git/blobdiff - getrabundcommand.cpp
added set.current and get.current commands and modified existing commands to update...
[mothur.git] / getrabundcommand.cpp
index b7dd7153609ada80c297d5d51cab70d3cae5ebc4..3b03f3694967d6d480ba0dc00153454c7e8b074f 100644 (file)
 #include "getrabundcommand.h"
 
 //**********************************************************************************************************************
-
+vector<string> GetRAbundCommand::getValidParameters(){ 
+       try {
+               string Array[] =  {"label","sorted","outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetRAbundCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetRAbundCommand::GetRAbundCommand(){  
+       try {
+               abort = true; calledHelp = true; 
+               vector<string> tempOutNames;
+               outputTypes["rabund"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetRAbundCommand::getRequiredParameters(){      
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetRAbundCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetRAbundCommand::getRequiredFiles(){   
+       try {
+               string Array[] =  {"list"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetRAbundCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 GetRAbundCommand::GetRAbundCommand(string option)  {
        try {
                globaldata = GlobalData::getInstance();
-               abort = false;
+               abort = false; calledHelp = false;   
                allLines = 1;
                labels.clear();
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
                        //valid paramters for this command
@@ -42,6 +89,10 @@ GetRAbundCommand::GetRAbundCommand(string option)  {
                                outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it       
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["rabund"] = tempOutNames;
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getListFile() == "") { m->mothurOut("You must read a listfile before you can use the get.rabund command."); m->mothurOutEndLine(); abort = true; }
                        
@@ -106,7 +157,7 @@ GetRAbundCommand::~GetRAbundCommand(){}
 int GetRAbundCommand::execute(){
        try {
        
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //read first line
                read = new ReadOTUFile(globaldata->inputFileName);      
@@ -120,7 +171,7 @@ int GetRAbundCommand::execute(){
                set<string> processedLabels;
                set<string> userLabels = labels;
                
-               if (m->control_pressed) {  out.close(); remove(filename.c_str());  delete list; globaldata->gListVector = NULL;  return 0; }
+               if (m->control_pressed) {  outputTypes.clear();  out.close(); remove(filename.c_str());  delete list; globaldata->gListVector = NULL;  return 0; }
                
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
@@ -129,7 +180,7 @@ int GetRAbundCommand::execute(){
                                        rabund = new RAbundVector();                            
                                        *rabund = (list->getRAbundVector());
                                        
-                                       if (m->control_pressed) {  out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+                                       if (m->control_pressed) {   outputTypes.clear(); out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
 
                                        
                                        if(sorted)      {   rabund->print(out);                         }
@@ -151,7 +202,7 @@ int GetRAbundCommand::execute(){
                                        rabund = new RAbundVector();
                                        *rabund = (list->getRAbundVector());
                                        
-                                       if (m->control_pressed) {  out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+                                       if (m->control_pressed) {   outputTypes.clear(); out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
                                        
                                        if(sorted)      {   rabund->print(out);                         }
                                        else            {       rabund->nonSortedPrint(out);    }
@@ -193,7 +244,7 @@ int GetRAbundCommand::execute(){
                        rabund = new RAbundVector();
                        *rabund = (list->getRAbundVector());
                        
-                       if (m->control_pressed) {  out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+                       if (m->control_pressed) {  outputTypes.clear(); out.close(); remove(filename.c_str());  delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
                        
                        if(sorted)      {   rabund->print(out);                         }
                        else            {       rabund->nonSortedPrint(out);    }
@@ -204,13 +255,20 @@ int GetRAbundCommand::execute(){
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
-               m->mothurOut(filename); m->mothurOutEndLine();  
+               m->mothurOut(filename); m->mothurOutEndLine();  outputNames.push_back(filename); outputTypes["rabund"].push_back(filename);
                m->mothurOutEndLine();
                
                out.close(); 
                
                globaldata->gListVector = NULL;
                
+               //set rabund file as new current rabundfile
+               string current = "";
+               itTypes = outputTypes.find("rabund");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); }
+               }
+               
                return 0;               
        }