]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug with windows version of trim.seqs when run with 1 processor. fixed file...
authorSarah Westcott <mothur.westcott@gmail.com>
Wed, 11 Apr 2012 15:35:07 +0000 (11:35 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Wed, 11 Apr 2012 15:35:07 +0000 (11:35 -0400)
commandfactory.cpp
commandfactory.hpp
mothurout.cpp
mothurout.h
setdircommand.cpp
shhhercommand.cpp
trimseqscommand.cpp

index 0c9504d09a109a39168af9b9d582ef20732e6647..d81045e500d71b138efe15ba4b178395d17f7ba4 100644 (file)
@@ -304,7 +304,49 @@ CommandFactory::~CommandFactory(){
        delete shellcommand;
        delete pipecommand;
 }
+/***********************************************************/
 
+/***********************************************************/
+int CommandFactory::checkForRedirects(string optionString) {
+    try {
+        
+        int pos = optionString.find("outputdir");
+        if (pos != string::npos) { //user has set outputdir in command option string
+            string outputOption = "";
+            bool foundEquals = false;
+            for(int i=pos;i<optionString.length();i++){
+                if(optionString[i] == ',')       { break;               }              
+                else if(optionString[i] == '=')  { foundEquals = true; }
+                if (foundEquals)       {   outputOption += optionString[i]; }
+            }
+            if(m->dirCheck(outputOption)){ 
+                setOutputDirectory(outputOption); 
+                m->mothurOut("Setting output directory to: " + outputOption); m->mothurOutEndLine();
+            }
+        }
+        
+        pos = optionString.find("inputdir");
+        if (pos != string::npos) { //user has set inputdir in command option string
+            string intputOption = "";
+            bool foundEquals = false;
+            for(int i=pos;i<optionString.length();i++){
+                if(optionString[i] == ',')       { break;               }              
+                else if(optionString[i] == '=')  { foundEquals = true; }
+                if (foundEquals)       {   intputOption += optionString[i]; }
+            }
+            if(m->dirCheck(intputOption)){ 
+                setInputDirectory(intputOption); 
+                m->mothurOut("Setting input directory to: " + intputOption); m->mothurOutEndLine();
+            }
+        }
+        
+        return 0;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CommandFactory", "getCommand");
+               exit(1);
+       }
+}
 /***********************************************************/
 
 /***********************************************************/
@@ -313,7 +355,9 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
        try {
         
                delete command;   //delete the old command
-               
+        
+        checkForRedirects(optionString);
+                       
                //user has opted to redirect output from dir where input files are located to some other place
                if (outputDir != "") { 
                        if (optionString != "") { optionString += ", outputdir=" + outputDir; }
@@ -463,6 +507,8 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str
        try {
                delete pipecommand;   //delete the old command
                
+        checkForRedirects(optionString);
+        
                //user has opted to redirect output from dir where input files are located to some other place
                if (outputDir != "") { 
                        if (optionString != "") { optionString += ", outputdir=" + outputDir; }
index 3c19e87cdde276b42aeb7488243de568812ffbca..e95db8016a4149c9c2defdbb9e7933ff6ee3905a 100644 (file)
@@ -48,6 +48,8 @@ private:
        string outputDir, inputDir, logFileName;\r
        bool append;\r
        \r
+    int checkForRedirects(string);\r
+    \r
        static CommandFactory* _uniqueInstance;\r
        CommandFactory( const CommandFactory& ); // Disable copy constructor\r
        void operator=( const CommandFactory& ); // Disable assignment operator\r
index 98f5ce09608855690a9fc7442814841a064db379..d5f1534f7535052c75888b04d28211fd522a0410 100644 (file)
@@ -598,6 +598,48 @@ string MothurOut::getPathName(string longName){
 }
 /***********************************************************************/
 
+bool MothurOut::dirCheck(string& dirName){
+       try {
+        
+        string tag = "";
+        #ifdef USE_MPI
+            int pid; 
+            MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+               
+            tag = toString(pid);
+        #endif
+
+        //add / to name if needed
+        string lastChar = dirName.substr(dirName.length()-1);
+        #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+        if (lastChar != "/") { dirName += "/"; }
+        #else
+        if (lastChar != "\\") { dirName += "\\"; }     
+        #endif
+
+        //test to make sure directory exists
+        dirName = getFullPathName(dirName);
+        string outTemp = dirName + tag + "temp";
+        ofstream out;
+        out.open(outTemp.c_str(), ios::trunc);
+        if(!out) {
+            mothurOut(dirName + " directory does not exist or is not writable."); mothurOutEndLine(); 
+        }else{
+            out.close();
+            mothurRemove(outTemp);
+            return true;
+        }
+        
+        return false;
+    }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "dirCheck");
+               exit(1);
+       }       
+    
+}
+/***********************************************************************/
+
 string MothurOut::hasPath(string longName){
        try {
                string path = "";
index e1c8222ae1938e8b63422cc9ee6567d309b668f5..0659e4e3628ccb28fdfc024427fe6cebf5af5446 100644 (file)
@@ -73,6 +73,7 @@ class MothurOut {
                
                //functions from mothur.h
                //file operations
+        bool dirCheck(string&); //completes path, appends appropriate / or \, makes sure dir is writable.
                vector<unsigned long long> divideFile(string, int&);
                int divideFile(string, int&, vector<string>&);
                vector<unsigned long long> setFilePosEachLine(string, int&);
index 081a306d712a8ee10bb67cf1d72bbf0663d0ff07..55b752dba4f40e76f11a46d2608e75d43c0de506 100644 (file)
@@ -101,14 +101,6 @@ int SetDirectoryCommand::execute(){
                
                commandFactory = CommandFactory::getInstance();
                
-               string tag = "";
-#ifdef USE_MPI
-               int pid; 
-               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-               
-               tag = toString(pid);
-#endif
-               
                m->mothurOut("Mothur's directories:"); m->mothurOutEndLine();
                
                //redirect output
@@ -120,27 +112,10 @@ int SetDirectoryCommand::execute(){
                        m->mothurOut("outputDir=" + 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) || (__linux__) || (__unix__) || (__unix)
-                               if (lastChar != "/") { output += "/"; }
-                       #else
-                               if (lastChar != "\\") { output += "\\"; }       
-                       #endif
-                       
-                       //test to make sure directory exists
-                       output = m->getFullPathName(output);
-                       string outTemp = output + tag + "temp";
-                       ofstream out;
-                       out.open(outTemp.c_str(), ios::trunc);
-                       if(!out) {
-                               m->mothurOut(output + " directory does not exist or is not writable."); m->mothurOutEndLine(); 
-                       }else{
-                               out.close();
-                               m->mothurRemove(outTemp);
-                               m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
+            if (m->dirCheck(output)) {
+                m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
                                commandFactory->setOutputDirectory(output);
-                       }
+            }
                }
                
                //redirect input
@@ -152,28 +127,11 @@ int SetDirectoryCommand::execute(){
                        m->mothurOut("inputDir=" + 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) || (__linux__) || (__unix__) || (__unix)
-                               if (lastChar != "/") { input += "/"; }
-                       #else
-                               if (lastChar != "\\") { input += "\\"; }        
-                       #endif
-                       
-                       //test to make sure directory exists
-                       input = m->getFullPathName(input);
-                       string inTemp = input + tag + "temp";
-                       ofstream in;
-                       in.open(inTemp.c_str(), ios::trunc);
-                       if(!in) {
-                               m->mothurOut(input + " directory does not exist or is not writable."); m->mothurOutEndLine(); 
-                       }else{
-                               in.close();
-                               m->mothurRemove(inTemp);
-                               m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
+            if (m->dirCheck(input)) {
+                m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
                                commandFactory->setInputDirectory(input); 
-                       }
-               }
+            }
+        }
                
                //set default
                if (tempdefault == "clear") {  
@@ -194,28 +152,11 @@ int SetDirectoryCommand::execute(){
                        m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
                        m->setDefaultPath(tempdefault);
                }else {
-                       //add / to name if needed
-                       string lastChar = tempdefault.substr(tempdefault.length()-1);
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
-                               if (lastChar != "/") { tempdefault += "/"; }
-                       #else
-                               if (lastChar != "\\") { tempdefault += "\\"; }  
-                       #endif
-                       
-                       //test to make sure directory exists
-                       tempdefault = m->getFullPathName(tempdefault);
-                       string inTemp = tempdefault + tag + "temp";
-                       ofstream in;
-                       in.open(inTemp.c_str(), ios::trunc);
-                       if(!in) {
-                               m->mothurOut(tempdefault + " directory does not exist or is not writable."); m->mothurOutEndLine(); 
-                       }else{
-                               in.close();
-                               m->mothurRemove(inTemp);
-                               m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
-                               m->setDefaultPath(tempdefault);
-                       }
-               }
+            if (m->dirCheck(tempdefault)) {
+                m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
+                               m->setDefaultPath(tempdefault); 
+            }
+        }
 
                return 0;
        }
index 6ef9532790a5fc63905cb598f1e7bc4baa4c9871..89d78288639e6cca3e8eebca34dd01174c3963da 100644 (file)
@@ -128,8 +128,10 @@ ShhherCommand::ShhherCommand(string option) {
                                        if (path == "") {       parameters["file"] = inputDir + it->second;             }
                                }
                        }
-                       
-                       
+            
+            //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 = ""; }
+            
                        //check for required parameters
                        flowFileName = validParameter.validFile(parameters, "flow", true);
                        flowFilesFileName = validParameter.validFile(parameters, "file", true);
@@ -146,13 +148,15 @@ ShhherCommand::ShhherCommand(string option) {
                        }
                        else{
                                ofstream temp;
-
+                
+                string thisoutputDir = m->hasPath(flowFilesFileName); //if user entered a file with a path then preserve it
+                
                                //flow.files = 9 character offset
-                               compositeFASTAFileName = flowFilesFileName.substr(0, flowFilesFileName.length()-10) + "shhh.fasta";
+                               compositeFASTAFileName = thisoutputDir + flowFilesFileName.substr(0, flowFilesFileName.length()-10) + "shhh.fasta";
                                m->openOutputFile(compositeFASTAFileName, temp);
                                temp.close();
                                
-                               compositeNamesFileName = flowFilesFileName.substr(0, flowFilesFileName.length()-10) + "shhh.names";
+                               compositeNamesFileName = thisoutputDir + flowFilesFileName.substr(0, flowFilesFileName.length()-10) + "shhh.names";
                                m->openOutputFile(compositeNamesFileName, temp);
                                temp.close();
                        }
@@ -214,17 +218,10 @@ ShhherCommand::ShhherCommand(string option) {
                 if (flowFileVector.size() == 0) {  m->mothurOut("[ERROR]: no valid files."); m->mothurOutEndLine(); abort = true; }
             }
             else{
+                outputDir += m->hasPath(flowFileName);
                 flowFileVector.push_back(flowFileName);
             }
-
-                       
-                       //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 += m->hasPath(flowFileName); //if user entered a file with a path then preserve it    
-                       }
-                       
-                       
+               
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
index b480702695a2ff6f24c7bcf6657e2f11fb3be86b..9f8fafb24e14a807baa8dd5a981c93556c46e3b7 100644 (file)
@@ -1190,9 +1190,8 @@ int TrimSeqsCommand::setLines(string filename, string qfilename) {
                 cout << fastaFilePos[startIndex] << '\t' << numSeqsPerProcessor << endl;
                 if (qfilename != "") {  qLines.push_back(linePair(qfileFilePos[startIndex], numSeqsPerProcessor)); }
             }
-        
-            if(qfilename == "")        {       qLines = lines; } //files with duds
         }
+            if(qfilename == "")        {       qLines = lines; } //files with duds
                        return 1;
                
                #endif