]> git.donarmstrong.com Git - mothur.git/blobdiff - engine.cpp
unifrac parallelization done, changed dist.seqs output=square to calc all distance...
[mothur.git] / engine.cpp
index 7bacec5c0e757c7b77d3c8801970c17bd3cc5a4a..5e82d1344d9fa068078e0176b1e655a8290cd42b 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;
+               mout->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;
 }
 
 /***********************************************************************/
@@ -159,7 +199,7 @@ string Engine::getCommand()  {
                                string nextCommand = "";
                                
                                mout->mothurOut("mothur > ");
-                               getline(cin, nextCommand);
+                               m->getline(cin, nextCommand);
                                mout->mothurOutJustToLog(toString(nextCommand));
                                
                                return nextCommand;
@@ -178,7 +218,48 @@ BatchEngine::BatchEngine(string path, string batchFileName){
        try {
                globaldata = GlobalData::getInstance();
        
-               openedBatch = openInputFile(batchFileName, inputBatchFile);
+               openedBatch = mout->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;
+                       mout->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;
                                
        }
@@ -289,7 +370,7 @@ bool BatchEngine::getInput(){
                                }
                                
                        }
-                       gobble(inputBatchFile);
+                       mout->gobble(inputBatchFile);
                }
                
                inputBatchFile.close();
@@ -307,7 +388,7 @@ string BatchEngine::getNextCommand(ifstream& inputBatchFile) {
                string nextcommand = "";
                
                if (inputBatchFile.eof()) { nextcommand = "quit()"; }
-               else { nextcommand = getline(inputBatchFile); }
+               else { nextcommand = mout->getline(inputBatchFile); }
                
                return nextcommand;
        }
@@ -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;
+                       mout->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;