+
+ abort = false;
+
+ //allow user to run help
+ if(option == "help") { help(); abort = true; }
+
+ else {
+
+ //valid paramters for this command
+ string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
+
+ ValidParameters validParameter("align.seqs");
+ map<string, string>::iterator it;
+
+ //check to make sure all parameters are valid for command
+ 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") {
+ m->mothurOut("template is a required parameter for the align.seqs command.");
+ m->mothurOutEndLine();
+ abort = true;
+ }else if (templateFileName == "not open") { abort = true; }
+
+ candidateFileName = validParameter.validFile(parameters, "candidate", false);
+ if (candidateFileName == "not found") { m->mothurOut("candidate is a required parameter for the align.seqs command."); m->mothurOutEndLine(); abort = true; }
+ else {
+ splitAtDash(candidateFileName, candidateFileNames);
+
+ //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, "noerror");
+
+ //if you can't open it, try default location
+ if (ableToOpen == 1) {
+ if (m->getDefaultPath() != "") { //default path is set
+ string tryPath = m->getDefaultPath() + getSimpleName(candidateFileNames[i]);
+ m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ableToOpen = openInputFile(tryPath, in, "noerror");
+ candidateFileNames[i] = tryPath;
+ }
+ }
+ in.close();
+
+ if (ableToOpen == 1) {
+ m->mothurOut("Unable to open " + candidateFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
+ //erase from file list
+ candidateFileNames.erase(candidateFileNames.begin()+i);
+ i--;
+ }
+
+ }
+
+ //make sure there is at least one valid file left
+ if (candidateFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
+ }
+
+ //check for optional parameter and set defaults
+ // ...at some point should added some additional type checking...
+ string temp;
+ temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found"){ temp = "8"; }
+ convert(temp, kmerSize);
+
+ temp = validParameter.validFile(parameters, "match", false); if (temp == "not found"){ temp = "1.0"; }
+ convert(temp, match);
+
+ temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found"){ temp = "-1.0"; }
+ convert(temp, misMatch);
+
+ temp = validParameter.validFile(parameters, "gapopen", false); if (temp == "not found"){ temp = "-2.0"; }
+ convert(temp, gapOpen);
+
+ temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-1.0"; }
+ convert(temp, gapExtend);
+
+ temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
+ convert(temp, processors);
+
+ temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "f"; }
+ flip = isTrue(temp);
+
+ temp = validParameter.validFile(parameters, "threshold", false); if (temp == "not found"){ temp = "0.50"; }
+ convert(temp, threshold);
+
+ search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; }
+
+ align = validParameter.validFile(parameters, "align", false); if (align == "not found"){ align = "needleman"; }