]> git.donarmstrong.com Git - mothur.git/commitdiff
added code to check path for uchime and catchall executables
authorSarah Westcott <mothur.westcott@gmail.com>
Tue, 29 May 2012 16:48:28 +0000 (12:48 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Tue, 29 May 2012 16:48:28 +0000 (12:48 -0400)
catchallcommand.cpp
chimerauchimecommand.cpp
chimerauchimecommand.h
engine.cpp
engine.hpp
mothurout.cpp
mothurout.h

index cc99e6d992cb182f7495e412b674298a643981f6..329b56a2c24dcf024ca66cab0f160b76438c0922 100644 (file)
@@ -175,16 +175,14 @@ int CatchAllCommand::execute() {
                path = m->getFullPathName(path);
                
         if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
-        
+       
                savedOutputDir = outputDir;
                string catchAllCommandExe = "";
         string catchAllTest = "";
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                       catchAllCommandExe += "mono " + path + "CatchAllcmdL.exe ";
                        if (outputDir == "") { outputDir = "./"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
             catchAllTest = path + "CatchAllcmdL.exe";
                #else
-                       catchAllCommandExe += "\"" + path + "CatchAllcmdW.exe\"" + " ";
                        if (outputDir == "") { outputDir = ".\\"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
             catchAllTest = path + "CatchAllcmdW.exe";
                #endif
@@ -193,12 +191,34 @@ int CatchAllCommand::execute() {
                ifstream in;
                catchAllTest = m->getFullPathName(catchAllTest);
                int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
-               if(ableToOpen == 1) {   m->mothurOut("[ERROR]: " + catchAllTest + " file does not exist. mothur requires the catchall executable to run the catchall command."); m->mothurOutEndLine(); m->control_pressed = true; return 0;  }
+               if(ableToOpen == 1) {   
+            m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
+            //check to see if uchime is in the path??
+            
+            string programName = "CatchAllcmdW.exe";
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+            programName = "CatchAllcmdL.exe";
+#endif
+            string cLocation = m->findProgramPath(programName);
+            
+            ifstream in2;
+            ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();
+
+            if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine();  return 0; } 
+            else {  m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
+        }
+        catchAllTest = m->getFullPathName(catchAllTest);
+        
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+        catchAllCommandExe += "mono " + catchAllTest + " ";
+#else
+        catchAllCommandExe += "\"" + catchAllTest + "\" ";
+#endif
         
                //prepare full output directory
                outputDir = m->getFullPathName(outputDir);
                
-        if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + ".\n [DEBUG]: outputDir = " + outputDir + ".\n"); }
+        if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
         
                vector<string> inputFileNames;
                if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);   }
@@ -219,7 +239,7 @@ int CatchAllCommand::execute() {
                        string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "catchall.summary";
                        summaryfilename = m->getFullPathName(summaryfilename);
                        
-            if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n [DEBUG]: inputdata address = " + toString(&input) + ".\n [DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } 
+            if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } 
             
                        ofstream out;
                        m->openOutputFile(summaryfilename, out);        
index e28775f016c4e992d2d8f2d23904c93c6e3f74ef..be0421a73097bc47aa98934ba4ae59a320e02010 100644 (file)
@@ -481,8 +481,26 @@ ChimeraUchimeCommand::ChimeraUchimeCommand(string option)  {
                        ifstream in;
                        uchimeCommand = m->getFullPathName(uchimeCommand);
                        int ableToOpen = m->openInputFile(uchimeCommand, in, "no error"); in.close();
-                       if(ableToOpen == 1) {   m->mothurOut("[ERROR]: " + uchimeCommand + " file does not exist. mothur requires the uchime executable."); m->mothurOutEndLine(); abort = true; }
-               }
+                       if(ableToOpen == 1) {   
+                m->mothurOut(uchimeCommand + " file does not exist. Checking path... \n");
+                //check to see if uchime is in the path??
+                
+                string uLocation = m->findProgramPath("uchime");
+                
+                
+                ifstream in2;
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                ableToOpen = m->openInputFile(uLocation, in2, "no error"); in2.close();
+#else
+                ableToOpen = m->openInputFile((uLocation + ".exe"), in2, "no error"); in2.close();
+#endif
+
+                if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + uLocation + " file does not exist. mothur requires the uchime executable."); m->mothurOutEndLine(); abort = true; } 
+                else {  m->mothurOut("Found uchime in your path, using " + uLocation + "\n");uchimeLocation = uLocation; }
+            }else {  uchimeLocation = uchimeCommand; }
+            
+            uchimeLocation = m->getFullPathName(uchimeLocation);
+        }
        }
        catch(exception& e) {
                m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand");
@@ -1010,16 +1028,10 @@ int ChimeraUchimeCommand::driver(string outputFName, string filename, string acc
                                
                vector<char*> cPara;
                
-               string path = m->argv;
-               string tempPath = path;
-               for (int i = 0; i < path.length(); i++) { tempPath[i] = tolower(path[i]); }
-               path = path.substr(0, (tempPath.find_last_of('m')));
-               
-               string uchimeCommand = path;
+               string uchimeCommand = uchimeLocation;
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-               uchimeCommand += "uchime ";
+               uchimeCommand += " ";
 #else
-               uchimeCommand += "uchime";
                uchimeCommand = "\"" + uchimeCommand + "\"";
 #endif
                
@@ -1258,6 +1270,7 @@ int ChimeraUchimeCommand::driver(string outputFName, string filename, string acc
 #else
                commandString = "\"" + commandString + "\"";
 #endif
+        if (m->debug) { m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
                system(commandString.c_str());
                
                //free memory
@@ -1430,7 +1443,7 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                        // Allocate memory for thread data.
                        string extension = toString(i) + ".temp";
                        
-                       uchimeData* tempUchime = new uchimeData(outputFileName+extension, templatefile, files[i], "", "", "", accnos+extension, alns+extension, dummy, m, 0, 0,  i);
+                       uchimeData* tempUchime = new uchimeData(outputFileName+extension, uchimeLocation, templatefile, files[i], "", "", "", accnos+extension, alns+extension, dummy, m, 0, 0,  i);
                        tempUchime->setBooleans(useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract);
                        tempUchime->setVariables(abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract);
                        
@@ -1562,7 +1575,7 @@ int ChimeraUchimeCommand::createProcessesGroups(SequenceParser& parser, string o
                        // Allocate memory for thread data.
                        string extension = toString(i) + ".temp";
                        
-                       uchimeData* tempUchime = new uchimeData(outputFName+extension, templatefile, filename+extension, fastaFile, nameFile, groupFile, accnos+extension, alns+extension, groups, m, lines[i].start, lines[i].end,  i);
+                       uchimeData* tempUchime = new uchimeData(outputFName+extension, uchimeLocation, templatefile, filename+extension, fastaFile, nameFile, groupFile, accnos+extension, alns+extension, groups, m, lines[i].start, lines[i].end,  i);
                        tempUchime->setBooleans(useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract);
                        tempUchime->setVariables(abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract);
                        
index b7da889701f3ac2bc7883cf5c39356550eb2e25d..dfb410f1acf31390df8c511b87e5a0f9dce74283 100644 (file)
@@ -45,7 +45,7 @@ private:
        int createProcesses(string, string, string, string, int&);
                
        bool abort, useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
-       string fastafile, groupfile, templatefile, outputDir, namefile, abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract;
+       string fastafile, groupfile, templatefile, outputDir, namefile, abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract, uchimeLocation;
        int processors;
        
        
@@ -74,7 +74,7 @@ struct uchimeData {
        string namefile; 
        string groupfile;
        string outputFName;
-       string accnos, alns, filename, templatefile;
+       string accnos, alns, filename, templatefile, uchimeLocation;
        MothurOut* m;
        int start;
        int end;
@@ -84,7 +84,7 @@ struct uchimeData {
        string abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract;
        
        uchimeData(){}
-       uchimeData(string o, string t, string file, string f, string n, string g, string ac,  string al, vector<string> gr, MothurOut* mout, int st, int en, int tid) {
+       uchimeData(string o, string uloc, string t, string file, string f, string n, string g, string ac,  string al, vector<string> gr, MothurOut* mout, int st, int en, int tid) {
                fastafile = f;
                namefile = n;
                groupfile = g;
@@ -100,6 +100,7 @@ struct uchimeData {
                groups = gr;
                count = 0;
                numChimeras = 0;
+        uchimeLocation = uloc;
        }
        void setBooleans(bool Abskew, bool calns, bool MinH, bool Mindiv, bool Xn, bool Dn, bool Xa, bool Chunks, bool Minchunk, bool Idsmoothwindow, bool Minsmoothid, bool Maxp, bool skipgap, bool skipgap2, bool Minlen, bool Maxlen, bool uc, bool Queryfract) {
                useAbskew = Abskew;
@@ -183,18 +184,8 @@ static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){
                        
                        vector<char*> cPara;
                        
-                       string path = pDataArray->m->argv;
-                       string tempPath = path;
-                       for (int j = 0; j < path.length(); j++) { tempPath[j] = tolower(path[j]); }
-                       path = path.substr(0, (tempPath.find_last_of('m')));
-                       
-                       string uchimeCommand = path;
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                       uchimeCommand += "uchime ";
-#else
-                       uchimeCommand += "uchime";
-                       uchimeCommand = "\"" + uchimeCommand + "\"";
-#endif                 
+            string uchimeCommand = pDataArray->uchimeLocation;
+            uchimeCommand = "\"" + uchimeCommand + "\"";
                        
                        char* tempUchime;
                        tempUchime= new char[uchimeCommand.length()+1]; 
@@ -403,10 +394,10 @@ static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){
                        
                        //uchime_main(numArgs, uchimeParameters); 
                        //cout << "commandString = " << commandString << endl;
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-#else
                        commandString = "\"" + commandString + "\"";
-#endif
+            
+            if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
+            
                        system(commandString.c_str());
                        
                        //free memory
@@ -505,11 +496,14 @@ static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){
                
                vector<char*> cPara;
                
-               char* tempUchime;
-               tempUchime= new char[8]; 
-               *tempUchime = '\0';
-               strncat(tempUchime, "uchime ", 7); 
-               cPara.push_back(tempUchime);
+               string uchimeCommand = pDataArray->uchimeLocation;
+        uchimeCommand = "\"" + uchimeCommand + "\"";
+        
+        char* tempUchime;
+        tempUchime= new char[uchimeCommand.length()+1]; 
+        *tempUchime = '\0';
+        strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
+        cPara.push_back(tempUchime);
                
                char* tempIn = new char[8]; 
                *tempIn = '\0'; strncat(tempIn, "--input", 7);
@@ -722,6 +716,7 @@ static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){
                
                //uchime_main(numArgs, uchimeParameters); 
                //cout << "commandString = " << commandString << endl;
+        if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
                system(commandString.c_str());
                
                //free memory
index 98d730c31c2d03e3222057f8cef3da571aca0877..48f782ab2a590d71a292e7b83125ba8ce0f3fffe 100644 (file)
@@ -26,78 +26,7 @@ Engine::Engine(){
        }
 }
 /***********************************************************************/
-string Engine::findMothursPath(){
-       try { 
-               
-               string envPath = getenv("PATH");
-               string mothurPath = "";
-               
-               //delimiting path char
-               char delim;
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                       delim = ':';
-               #else
-                       delim = ';';
-               #endif
-               
-               //break apart path variable by ':'
-               vector<string> dirs;
-               mout->splitAtChar(envPath, dirs, delim);
-               
-        if (mout->debug) { mout->mothurOut("[DEBUG]: dir's in path: \n"); }
-        
-               //get path related to mothur
-               for (int i = 0; i < dirs.size(); i++) {
-            
-            if (mout->debug) { mout->mothurOut("[DEBUG]: " + dirs[i] + "\n"); }
-            
-                       //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;  }
-               }
-        
-               if (mout->debug) { mout->mothurOut("[DEBUG]: mothurPath = " + mothurPath + "\n"); }
-        
-               if (mothurPath != "") {
-                       //add mothur so it looks like what argv would look like
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                               mothurPath += "/mothur";
-                       #else
-                               mothurPath += "\\mothur";
-                       #endif
-               }else {
-                       //okay mothur is not in the path, so the folder mothur is in must be in the path
-                       //lets find out which one
-                       
-                       //get path related to mothur
-                       for (int i = 0; i < dirs.size(); i++) {
-                                                               
-                               //is this mothurs path?
-                               ifstream in;
-                               string tempIn = dirs[i];
-                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                                       tempIn += "/mothur";
-                               #else
-                                       tempIn += "\\mothur";
-                               #endif
-                               mout->openInputFile(tempIn, in, "");
-                               
-                               //if this file exists
-                               if (in) { in.close(); mothurPath = tempIn;  break; if (mout->debug) { mout->mothurOut("[DEBUG]: found it, mothurPath = " + mothurPath + "\n"); }  }
-                       }
-               }
-               
-               return mothurPath;
-               
-       }
-       catch(exception& e) {
-               mout->errorOut(e, "Engine", "findMothursPath");
-               exit(1);
-       }
-}
+
 /***********************************************************************/
 
 InteractEngine::InteractEngine(string path){
@@ -106,7 +35,7 @@ InteractEngine::InteractEngine(string path){
        string temppath = path.substr(0, (path.find_last_of("othur")-5));
        
        //this will happen if you set the path variable to contain mothur's exe location
-       if (temppath == "") { path = findMothursPath(); }
+       if (temppath == "") { path = mout->findProgramPath("mothur"); }
        
        mout->argv = path;
 }
@@ -273,7 +202,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){
                string temppath = path.substr(0, (path.find_last_of("othur")-5));
        
                //this will happen if you set the path variable to contain mothur's exe location
-               if (temppath == "") { path = findMothursPath(); }
+               if (temppath == "") { path = mout->findProgramPath("mothur"); }
                
                mout->argv = path;
                                
@@ -441,7 +370,7 @@ ScriptEngine::ScriptEngine(string path, string commandString){
                string temppath = path.substr(0, (path.find_last_of("othur")-5));
 
                //this will happen if you set the path variable to contain mothur's exe location
-               if (temppath == "") { path = findMothursPath(); }
+               if (temppath == "") { path = mout->findProgramPath("mothur"); }
                
                mout->argv = path;
                                
index 5311da9e1e3aafb3c447b2e51ec411cb29c79d14..460e245bf5312d81f5b15d70387cf9ec63d472f6 100644 (file)
@@ -33,7 +33,6 @@ protected:
        vector<string> options;
        CommandFactory* cFactory;
        MothurOut* mout;
-       string findMothursPath();
 };
 
 
index 61b39514e43b79bc146eb3e37ed4dc8d41017a62..6ecb86f94e5533165551ed5ae571f0c51f3c9ff9 100644 (file)
@@ -117,6 +117,81 @@ void MothurOut::clearCurrentFiles()  {
                exit(1);
        }
 }
+/***********************************************************************/
+string MothurOut::findProgramPath(string programName){
+       try { 
+               
+               string envPath = getenv("PATH");
+               string pPath = "";
+               
+               //delimiting path char
+               char delim;
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+        delim = ':';
+#else
+        delim = ';';
+#endif
+               
+               //break apart path variable by ':'
+               vector<string> dirs;
+               splitAtChar(envPath, dirs, delim);
+               
+        if (debug) { mothurOut("[DEBUG]: dir's in path: \n"); }
+        
+               //get path related to mothur
+               for (int i = 0; i < dirs.size(); i++) {
+            
+            if (debug) { mothurOut("[DEBUG]: " + dirs[i] + "\n"); }
+            
+                       //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(programName) != -1) {  pPath = dirs[i]; break;  }
+               }
+        
+               if (debug) { mothurOut("[DEBUG]: programPath = " + pPath + "\n"); }
+        
+               if (pPath != "") {
+                       //add programName so it looks like what argv would look like
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+            pPath += "/" + programName;
+#else
+            pPath += "\\" + programName;
+#endif
+               }else {
+                       //okay programName is not in the path, so the folder programName is in must be in the path
+                       //lets find out which one
+                       
+                       //get path related to the program
+                       for (int i = 0; i < dirs.size(); i++) {
+                
+                if (debug) { mothurOut("[DEBUG]: looking in " + dirs[i] + " for " + programName + " \n"); }
+                
+                               //is this the programs path?
+                               ifstream in;
+                               string tempIn = dirs[i];
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                tempIn += "/" + programName;
+#else
+                tempIn += "\\" + programName;
+#endif
+                               openInputFile(tempIn, in, "");
+                               
+                               //if this file exists
+                               if (in) { in.close(); pPath = tempIn; if (debug) { mothurOut("[DEBUG]: found it, programPath = " + pPath + "\n"); } break;   }
+                       }
+               }
+               
+               return pPath;
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "findProgramPath");
+               exit(1);
+       }
+}
 /*********************************************************************************************/
 void MothurOut::setFileName(string filename)  {
        try {
index 0e31f8414a3a3477c1d8ab928d79aee0ccdc9957..cc8bfb6b101b13b0ebe45a2eb2f5472600d6e0fc 100644 (file)
@@ -82,6 +82,7 @@ class MothurOut {
                int appendFiles(string, string);
                int renameFile(string, string); //oldname, newname
                string getFullPathName(string);
+        string findProgramPath(string programName);
                string hasPath(string);
                string getExtension(string);
                string getPathName(string);