From 11c115c802602be50e106aae56969e15d2c49a62 Mon Sep 17 00:00:00 2001 From: westcott Date: Tue, 3 Aug 2010 16:16:46 +0000 Subject: [PATCH] modified the engine to extract the path of mothur executable if argv does not contain it. added default setting to set.dir to change directories to where mothur.exe is located. added splitAtChar to mothur.h which splits a string by the character passed in. --- clearcutcommand.cpp | 11 ++-- engine.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++- mothur.h | 24 +++++++++ setdircommand.cpp | 30 +++++++++-- setdircommand.h | 1 + 5 files changed, 177 insertions(+), 12 deletions(-) diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index 2ffb655..7bea292 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -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 "; } diff --git a/engine.cpp b/engine.cpp index 7bacec5..fbf986d 100644 --- a/engine.cpp +++ b/engine.cpp @@ -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 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 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 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; diff --git a/mothur.h b/mothur.h index 1434482..f1b1392 100644 --- a/mothur.h +++ b/mothur.h @@ -662,6 +662,29 @@ inline bool inVector(string member, vector group){ } /***********************************************************************/ +//This function parses the estimator options and puts them in a vector +inline void splitAtChar(string& estim, vector& 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& container) { try { @@ -788,6 +811,7 @@ inline void splitAtEquals(string& key, string& value){ exit(1); } } + /**************************************************************************************************/ inline bool inUsersGroups(string groupname, vector Groups) { diff --git a/setdircommand.cpp b/setdircommand.cpp index 001ae23..043c0ac 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -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); diff --git a/setdircommand.h b/setdircommand.h index 565b839..330adf1 100644 --- a/setdircommand.h +++ b/setdircommand.h @@ -12,6 +12,7 @@ #include "command.hpp" #include "commandfactory.hpp" +#include "globaldata.hpp" /**********************************************************/ -- 2.39.2