]> git.donarmstrong.com Git - mothur.git/commitdiff
modified the engine to extract the path of mothur executable if argv does not contain...
authorwestcott <westcott>
Tue, 3 Aug 2010 16:16:46 +0000 (16:16 +0000)
committerwestcott <westcott>
Tue, 3 Aug 2010 16:16:46 +0000 (16:16 +0000)
clearcutcommand.cpp
engine.cpp
mothur.h
setdircommand.cpp
setdircommand.h

index 2ffb65598a8fc75041190f764742342202e4ed52..7bea292ee6b1dfd7afe9a2ce1300e6b71f2b1324 100644 (file)
@@ -72,7 +72,7 @@ ClearcutCommand::ClearcutCommand(string option)  {
 
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
-                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = ""; }
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = hasPath(inputFile); }
                        
                        string temp;
                        temp = validParameter.validFile(parameters, "version", false);          if (temp == "not found"){       temp = "F";                     }
@@ -182,13 +182,8 @@ int ClearcutCommand::execute() {
                string path = globaldata->argv;
                path = path.substr(0, (path.find_last_of('m')));
                
-               string clearcutCommand = "";
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       clearcutCommand = path + "clearcut/clearcut ";
-               #else
-                       clearcutCommand = path + "clearcut\\clearcut ";
-               #endif
-               
+               string clearcutCommand = path + "clearcut ";
+                               
                //you gave us a distance matrix
                if (phylipfile != "") { clearcutCommand += "--distance ";       }
                
index 7bacec5c0e757c7b77d3c8801970c17bd3cc5a4a..fbf986dc6965de7d9d269c31f35e99ed85467a9d 100644 (file)
@@ -31,8 +31,48 @@ Engine::Engine(){
 InteractEngine::InteractEngine(string path){
 
        globaldata = GlobalData::getInstance();
-       globaldata->argv = path;
        
+       string temppath = path.substr(0, (path.find_last_of('m')));
+       
+       //this will happen if you set the path variable to contain mothur's exe location
+       if (temppath == "") { 
+       
+               string envPath = getenv("PATH");
+               
+               //delimiting path char
+               char delim;
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       delim = ':';
+               #else
+                       delim = ';';
+               #endif
+               
+               //break apart path variable by ':'
+               vector<string> dirs;
+               splitAtChar(envPath, dirs, delim);
+               
+               //get path related to mothur
+               string mothurPath = "";
+               for (int i = 0; i < dirs.size(); i++) {
+                       //to lower so we can find it
+                       string tempLower = "";
+                       for (int j = 0; j < dirs[i].length(); j++) {  tempLower += tolower(dirs[i][j]);  }
+                       
+                       //is this mothurs path?
+                       if (tempLower.find("mothur") != -1) {  mothurPath = dirs[i]; break;  }
+               }
+               
+               //add mothur so it looks like what argv would look like
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       mothurPath += "/mothur";
+               #else
+                       mothurPath += "\\mothur";
+               #endif
+               
+               path = mothurPath;
+       }
+       
+       globaldata->argv = path;
 }
 
 /***********************************************************************/
@@ -179,6 +219,47 @@ BatchEngine::BatchEngine(string path, string batchFileName){
                globaldata = GlobalData::getInstance();
        
                openedBatch = openInputFile(batchFileName, inputBatchFile);
+               
+               string temppath = path.substr(0, (path.find_last_of('m')));
+       
+               //this will happen if you set the path variable to contain mothur's exe location
+               if (temppath == "") { 
+               
+                       string envPath = getenv("PATH");
+                       
+                       //delimiting path char
+                       char delim;
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               delim = ':';
+                       #else
+                               delim = ';';
+                       #endif
+                       
+                       //break apart path variable by ':'
+                       vector<string> dirs;
+                       splitAtChar(envPath, dirs, delim);
+                       
+                       //get path related to mothur
+                       string mothurPath = "";
+                       for (int i = 0; i < dirs.size(); i++) {
+                               //to lower so we can find it
+                               string tempLower = "";
+                               for (int j = 0; j < dirs[i].length(); j++) {  tempLower += tolower(dirs[i][j]);  }
+                               
+                               //is this mothurs path?
+                               if (tempLower.find("mothur") != -1) {  mothurPath = dirs[i]; break;  }
+                       }
+                       
+                       //add mothur so it looks like what argv would look like
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               mothurPath += "/mothur";
+                       #else
+                               mothurPath += "\\mothur";
+                       #endif
+                       
+                       path = mothurPath;
+               }
+
                globaldata->argv = path;
                                
        }
@@ -326,6 +407,46 @@ ScriptEngine::ScriptEngine(string path, string commandString){
                
                //remove quotes
                listOfCommands = commandString.substr(1, (commandString.length()-1));
+               
+               string temppath = path.substr(0, (path.find_last_of('m')));
+       
+               //this will happen if you set the path variable to contain mothur's exe location
+               if (temppath == "") { 
+               
+                       string envPath = getenv("PATH");
+                       
+                       //delimiting path char
+                       char delim;
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               delim = ':';
+                       #else
+                               delim = ';';
+                       #endif
+                       
+                       //break apart path variable by ':'
+                       vector<string> dirs;
+                       splitAtChar(envPath, dirs, delim);
+                       
+                       //get path related to mothur
+                       string mothurPath = "";
+                       for (int i = 0; i < dirs.size(); i++) {
+                               //to lower so we can find it
+                               string tempLower = "";
+                               for (int j = 0; j < dirs[i].length(); j++) {  tempLower += tolower(dirs[i][j]);  }
+                               
+                               //is this mothurs path?
+                               if (tempLower.find("mothur") != -1) {  mothurPath = dirs[i]; break;  }
+                       }
+                       
+                       //add mothur so it looks like what argv would look like
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               mothurPath += "/mothur";
+                       #else
+                               mothurPath += "\\mothur";
+                       #endif
+                       
+                       path = mothurPath;
+               }
 
                globaldata->argv = path;
                                
index 1434482e9a9785485e0f898f88e352e6f7757659..f1b13920d0a4c8941214dbf3e42c96ed4ce39486 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -662,6 +662,29 @@ inline bool inVector(string member, vector<string> group){
 }
 /***********************************************************************/
 
+//This function parses the estimator options and puts them in a vector
+inline void splitAtChar(string& estim, vector<string>& container, char symbol) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of(symbol) != -1) {
+                       individual = estim.substr(0,estim.find_first_of(symbol));
+                       if ((estim.find_first_of(symbol)+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of(symbol)+1, estim.length());
+                               container.push_back(individual);
+                       }
+               }
+               //get last one
+               container.push_back(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
 //This function parses the estimator options and puts them in a vector
 inline void splitAtDash(string& estim, vector<string>& container) {
        try {
@@ -788,6 +811,7 @@ inline void splitAtEquals(string& key, string& value){
                exit(1);
        }       
 }
+
 /**************************************************************************************************/
 
 inline bool inUsersGroups(string groupname, vector<string> Groups) {
index 001ae235dd11ff0f015ebeba76de10ee3bcb2dbf..043c0acc8ec524c1b510da28c36c149d300f215a 100644 (file)
@@ -60,8 +60,11 @@ void SetDirectoryCommand::help(){
                m->mothurOut("The set.dir command can also be used to override or set the default location mothur will look for files if it is unable to find them, the directory must exist.\n");
                m->mothurOut("The set.dir command parameters are input, output and tempdefault and one is required.\n");
                m->mothurOut("To return the output to the same directory as the input files you may enter: output=clear.\n");
-               m->mothurOut("To return the input to the same directory as the mothur.exe you may enter: input=clear.\n");
+               m->mothurOut("To return the input to the current working directory you may enter: input=clear.\n");
+               m->mothurOut("To set the output to the directory where mothur.exe is located you may enter: output=default.\n");
+               m->mothurOut("To set the input to the directory where mothur.exe is located you may enter: input=default.\n");
                m->mothurOut("To return the tempdefault to the default you provided at compile time you may enter: tempdefault=clear.\n");
+               m->mothurOut("To set the tempdefault to the directory where mothur.exe is located you may enter: tempdefault=default.\n");
                m->mothurOut("The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory, tempdefault=yourTempDefault).\n");
                m->mothurOut("Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n\n");
@@ -86,7 +89,14 @@ int SetDirectoryCommand::execute(){
                
                //redirect output
                if ((output == "clear") || (output == "")) {  output = "";  commandFactory->setOutputDirectory(output);  }
-               else {
+               else if (output == "default") { 
+                       GlobalData* globaldata = GlobalData::getInstance();
+                       string exepath = globaldata->argv;
+                       output = exepath.substr(0, (exepath.find_last_of('m')));
+                       
+                       m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine();  
+                       commandFactory->setOutputDirectory(output);
+               }else {
                        //add / to name if needed
                        string lastChar = output.substr(output.length()-1);
                        #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
@@ -112,7 +122,14 @@ int SetDirectoryCommand::execute(){
                
                //redirect input
                if ((input == "clear") || (input == "")) {  input = "";  commandFactory->setInputDirectory(input);  }
-               else {
+               else if (input == "default") { 
+                       GlobalData* globaldata = GlobalData::getInstance();
+                       string exepath = globaldata->argv;
+                       input = exepath.substr(0, (exepath.find_last_of('m')));
+                       
+                       m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine();  
+                       commandFactory->setInputDirectory(input);
+               }else {
                        //add / to name if needed
                        string lastChar = input.substr(input.length()-1);
                        #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
@@ -148,6 +165,13 @@ int SetDirectoryCommand::execute(){
                                m->setDefaultPath(temp);
                        #endif
                }else if (tempdefault == "") {  //do nothing
+               }else if (tempdefault == "default") { 
+                       GlobalData* globaldata = GlobalData::getInstance();
+                       string exepath = globaldata->argv;
+                       tempdefault = exepath.substr(0, (exepath.find_last_of('m')));
+                       
+                       m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine();  
+                       m->setDefaultPath(tempdefault);
                }else {
                        //add / to name if needed
                        string lastChar = tempdefault.substr(tempdefault.length()-1);
index 565b839aadb6ce8f2f440e6bd8b75be44afba227..330adf14ee11061c9b049b6aab2bde783113d6d0 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "command.hpp"
 #include "commandfactory.hpp"
+#include "globaldata.hpp"
 
 /**********************************************************/