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);
+ }
+}
/***********************************************************/
/***********************************************************/
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; }
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; }
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
}
/***********************************************************************/
+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 = "";
//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&);
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
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
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") {
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;
}
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);
}
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();
}
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;
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