From: Sarah Westcott Date: Wed, 11 Apr 2012 15:35:07 +0000 (-0400) Subject: fixed bug with windows version of trim.seqs when run with 1 processor. fixed file... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=eb4bb52af987ff4df7354d95d60cd763aec537e1 fixed bug with windows version of trim.seqs when run with 1 processor. fixed file output redirect for shhh.slows command. modified mothur so that you can set input and output directories using the parameters in the command. --- diff --git a/commandfactory.cpp b/commandfactory.cpp index 0c9504d..d81045e 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -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;imothurOutEndLine(); //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; } diff --git a/shhhercommand.cpp b/shhhercommand.cpp index 6ef9532..89d7828 100644 --- a/shhhercommand.cpp +++ b/shhhercommand.cpp @@ -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; diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index b480702..9f8fafb 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -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