From e057ab99eca7d45544c83ca6665a042b934b661b Mon Sep 17 00:00:00 2001 From: pschloss Date: Thu, 4 Feb 2010 15:14:07 +0000 Subject: [PATCH] pat's ../ bug fix --- aligncommand.cpp | 10 +++++++--- chimeraseqscommand.cpp | 4 ++-- chimeraslayer.cpp | 2 +- mothur.h | 19 ++++++++++++++----- preclustercommand.cpp | 42 ++++++------------------------------------ validparameter.cpp | 3 +++ 6 files changed, 33 insertions(+), 47 deletions(-) diff --git a/aligncommand.cpp b/aligncommand.cpp index 7841557..7782d1e 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -52,16 +52,20 @@ AlignCommand::AlignCommand(string option){ for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + //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 = ""; } + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); + if (inputDir == "not found"){ inputDir = ""; } else { string path; + it = parameters.find("template"); + //user has given a template file if(it != parameters.end()){ path = hasPath(it->second); @@ -69,9 +73,10 @@ AlignCommand::AlignCommand(string option){ if (path == "") { parameters["template"] = inputDir + it->second; } } } - + //check for required parameters templateFileName = validParameter.validFile(parameters, "template", true); + if (templateFileName == "not found") { mothurOut("template is a required parameter for the align.seqs command."); mothurOutEndLine(); @@ -106,7 +111,6 @@ AlignCommand::AlignCommand(string option){ //make sure there is at least one valid file left if (candidateFileNames.size() == 0) { mothurOut("no valid files."); mothurOutEndLine(); abort = true; } } - //check for optional parameter and set defaults // ...at some point should added some additional type checking... diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index 4941488..b06d369 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -228,8 +228,8 @@ void ChimeraSeqsCommand::help(){ mothurOut("\t\tparameters: fasta=required, template=required, filter=F, mask=no mask, processors=1, window=10% of length, numwanted=20\n"); mothurOut("\tchimeracheck: \n"); mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, ksize=7, svg=F, name=none\n\n"); - //mothurOut("\tchimeraslayer: \n"); - //mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, mask=no mask, numwanted=10, match=5, mismatch=-4, divergence=1.0, minsim=90, parents=5, iters=1000, window=100. \n\n"); + mothurOut("\tchimeraslayer: \n"); + mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, mask=no mask, numwanted=10, match=5, mismatch=-4, divergence=1.0, minsim=90, parents=5, iters=1000, window=100. \n\n"); mothurOut("The chimera.seqs command should be in the following format: \n"); mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n"); mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, method=bellerophon, window=200) \n"); diff --git a/chimeraslayer.cpp b/chimeraslayer.cpp index ab4bd1f..5d3d670 100644 --- a/chimeraslayer.cpp +++ b/chimeraslayer.cpp @@ -33,7 +33,7 @@ void ChimeraSlayer::print(ostream& out) { for (int i = 0; i < querySeqs.size(); i++) { if (chimeraFlags[i] == "yes") { - cout << i << endl; +// cout << i << endl; if ((chimeraResults[i][0].bsa >= 90.0) || (chimeraResults[i][0].bsb >= 90.0)) { mothurOut(querySeqs[i]->getName() + "\tyes"); mothurOutEndLine(); out << querySeqs[i]->getName() << "\tyes" << endl; diff --git a/mothur.h b/mothur.h index a63d7ae..8190152 100644 --- a/mothur.h +++ b/mothur.h @@ -487,7 +487,7 @@ inline bool isBlank(string fileName){ /***********************************************************************/ inline string getFullPathName(string fileName){ - + try{ string path = hasPath(fileName); string newFileName; int pos; @@ -504,10 +504,12 @@ inline string getFullPathName(string fileName){ else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name char* cwdpath = new char[1024]; + size_t size; cwdpath=getcwd(cwdpath,size); - cwd = cwdpath; + cwd = cwdpath; + //rip off first '/' string simpleCWD; if (cwd.length() > 0) { simpleCWD = cwd.substr(1); } @@ -521,9 +523,10 @@ inline string getFullPathName(string fileName){ } //get last one // ex. ../../../filename = /user/work/desktop/filename dirs.push_back(simpleCWD); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop - + + int index = dirs.size()-1; - + while((pos = path.rfind("./")) != -1) { //while you don't have a complete path if (path[(pos-1)] == '.') { //you want your parent directory ../ path = path.substr(0, pos-1); @@ -583,6 +586,12 @@ inline string getFullPathName(string fileName){ #endif } + } + catch(exception& e) { + errorOut(e, "getFullPathName", "getFullPathName"); + exit(1); + } + } /***********************************************************************/ @@ -606,7 +615,7 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){ inline int openInputFile(string fileName, ifstream& fileHandle){ //get full path name string completeFileName = getFullPathName(fileName); - + fileHandle.open(completeFileName.c_str()); if(!fileHandle) { mothurOut("Error: Could not open " + completeFileName); mothurOutEndLine(); diff --git a/preclustercommand.cpp b/preclustercommand.cpp index d97ffc7..fa5329b 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -179,43 +179,11 @@ int PreClusterCommand::execute(){ exit(1); } } -/************************************************************************************************** -int PreClusterCommand::readFASTA(){ - try { -// ifstream inFasta; -// openInputFile(fastafile, inFasta); -// length = 0; -//// map::iterator it; -// -// while (!inFasta.eof()) { -// Sequence temp(inFasta); //read seq -// -// if (temp.getName() != "") { -// if (namefile != "") { -// //make sure fasta and name files match -// it = names.find(temp.getName()); -// if (it == names.end()) { mothurOut(temp.getName() + " is not in your names file, please correct."); mothurOutEndLine(); exit(1); } -// }else { sizes[temp.getName()] = 1; } -// -// seqPNode tempNode(sizes[temp.getName()], temp); -// alignSeqs.push_back(tempNode); -// active[temp.getName()] = true; -// } -// gobble(inFasta); -// } -// inFasta.close(); -// -// if (alignSeqs.size() != 0) { length = alignSeqs[0].seq.getAligned().length(); } -// - return alignSeqs.size(); - } - catch(exception& e) { - errorOut(e, "PreClusterCommand", "readFASTA"); - exit(1); - } -} + /**************************************************************************************************/ -//this seems to require the names and fasta file to be in the same order??? + +//this requires the names and fasta file to be in the same order + int PreClusterCommand::readFASTA(){ try { //ifstream inNames; @@ -316,7 +284,9 @@ void PreClusterCommand::printData(string newfasta, string newname){ exit(1); } } + /**************************************************************************************************/ + void PreClusterCommand::readNameFile(){ try { ifstream in; diff --git a/validparameter.cpp b/validparameter.cpp index ad8038e..a978f0f 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -204,8 +204,11 @@ string ValidParameters::validFile(map container, string paramete it = container.find(parameter); if(it != container.end()){ //no parameter given + if(isFile == true) { + ableToOpen = openInputFile(it->second, in); + if (ableToOpen == 1) { return "not open"; } in.close(); } -- 2.39.2