X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=aligncommand.cpp;h=708a85472dc53fecec1f022ce86512a82d620c30;hb=5a1e62397b91f57d0d3aff635891df04b8999a88;hp=3b3afc1795b2d73c709ef4474b07b88acf93e0dc;hpb=92f998cc7debc4bf3e8594848586b8153d96db16;p=mothur.git diff --git a/aligncommand.cpp b/aligncommand.cpp index 3b3afc1..708a854 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -39,27 +39,49 @@ AlignCommand::AlignCommand(string option){ else { //valid paramters for this command - string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold"}; + string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); OptionParser parser(option); map parameters = parser.getParameters(); ValidParameters validParameter; + map::iterator it; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + 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); + //if the user has not given a path then, add inputdir. else leave path alone. + 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(); abort = true; - } - else if (templateFileName == "not open") { abort = true; } + }else if (templateFileName == "not open") { abort = true; } candidateFileName = validParameter.validFile(parameters, "candidate", false); if (candidateFileName == "not found") { mothurOut("candidate is a required parameter for the align.seqs command."); mothurOutEndLine(); abort = true; } @@ -68,6 +90,12 @@ AlignCommand::AlignCommand(string option){ //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < candidateFileNames.size(); i++) { + if (inputDir != "") { + string path = hasPath(candidateFileNames[i]); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { candidateFileNames[i] = inputDir + candidateFileNames[i]; } + } + int ableToOpen; ifstream in; ableToOpen = openInputFile(candidateFileNames[i], in); @@ -83,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... @@ -149,8 +176,8 @@ void AlignCommand::help(){ mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse compement if a sequence falls below the threshold. The default is false.\n"); - mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. \n"); + mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold. The default is false.\n"); + mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment.\n"); mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n"); mothurOut("The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed.\n"); mothurOut("The align.seqs command should be in the following format: \n"); @@ -187,9 +214,11 @@ int AlignCommand::execute(){ for (int s = 0; s < candidateFileNames.size(); s++) { mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); mothurOutEndLine(); - string alignFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "align"; - string reportFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "align.report"; - string accnosFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "flip.accnos"; + if (outputDir == "") { outputDir += hasPath(candidateFileNames[s]); } + string alignFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align"; + string reportFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align.report"; + string accnosFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "flip.accnos"; + bool hasAccnos = true; int numFastaSeqs = 0; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); @@ -279,20 +308,20 @@ int AlignCommand::execute(){ mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); }else{ mothurOut(" If the reverse compliment proved to be better it was reported."); } mothurOutEndLine(); - } + }else{ hasAccnos = false; } } #else ifstream inFASTA; - openInputFile(candidateFileName[s], inFASTA); + openInputFile(candidateFileNames[s], inFASTA); numFastaSeqs=count(istreambuf_iterator(inFASTA),istreambuf_iterator(), '>'); inFASTA.close(); lines.push_back(new linePair(0, numFastaSeqs)); - driver(lines[0], alignFileName, reportFileName, accnosFileName); + driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); //delete accnos file if its blank else report to user - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); } + if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } else { mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { @@ -303,7 +332,10 @@ int AlignCommand::execute(){ #endif - + mothurOut("Output File Names: " + alignFileName + ", " + reportFileName); + if (hasAccnos) { mothurOut(", " + accnosFileName + "."); } + else { mothurOut("."); } + mothurOutEndLine(); mothurOut("It took " + toString(time(NULL) - start) + " secs to align " + toString(numFastaSeqs) + " sequences."); mothurOutEndLine();