+//**********************************************************************************************************************
+vector<string> FilterSeqsCommand::setParameters(){
+ try {
+ CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-filter",false,true, true); parameters.push_back(pfasta);
+ CommandParameter phard("hard", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(phard);
+ CommandParameter ptrump("trump", "String", "", "*", "", "", "","",false,false, true); parameters.push_back(ptrump);
+ CommandParameter psoft("soft", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psoft);
+ CommandParameter pvertical("vertical", "Boolean", "", "T", "", "", "","",false,false, true); parameters.push_back(pvertical);
+ CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false, true); parameters.push_back(pprocessors);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
+
+ vector<string> myArray;
+ for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "FilterSeqsCommand", "setParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+string FilterSeqsCommand::getHelpString(){
+ try {
+ string helpString = "";
+ helpString += "The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n";
+ helpString += "The filter.seqs command parameters are fasta, trump, soft, hard, processors and vertical. \n";
+ helpString += "The fasta parameter is required, unless you have a valid current fasta file. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n";
+ helpString += "For example: fasta=abrecovery.fasta-amazon.fasta \n";
+ helpString += "The trump option will remove a column if the trump character is found at that position in any sequence of the alignment. Default=*, meaning no trump. \n";
+ helpString += "A soft mask removes any column where the dominant base (i.e. A, T, G, C, or U) does not occur in at least a designated percentage of sequences. Default=0.\n";
+ helpString += "The hard parameter allows you to enter a file containing the filter you want to use.\n";
+ helpString += "The vertical parameter removes columns where all sequences contain a gap character. The default is T.\n";
+ helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n";
+ helpString += "The filter.seqs command should be in the following format: \n";
+ helpString += "filter.seqs(fasta=yourFastaFile, trump=yourTrump) \n";
+ helpString += "Example filter.seqs(fasta=abrecovery.fasta, trump=.).\n";
+ helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
+ return helpString;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "FilterSeqsCommand", "getHelpString");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+string FilterSeqsCommand::getOutputPattern(string type) {
+ try {
+ string pattern = "";
+
+ if (type == "fasta") { pattern = "[filename],filter.fasta"; }
+ else if (type == "filter") { pattern = "[filename],filter"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
+
+ return pattern;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "FilterSeqsCommand", "getOutputPattern");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+FilterSeqsCommand::FilterSeqsCommand(){
+ try {
+ abort = true; calledHelp = true;
+ setParameters();
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["filter"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand");
+ exit(1);
+ }
+}
+/**************************************************************************************/
+FilterSeqsCommand::FilterSeqsCommand(string option) {
+ try {
+ abort = false; calledHelp = false;
+ filterFileName = "";
+
+ //allow user to run help
+ if(option == "help") { help(); abort = true; calledHelp = true; }
+ else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+
+ else {
+ vector<string> myArray = setParameters();
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter("filter.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; }
+ }
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["filter"] = tempOutNames;
+
+ //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("fasta");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["fasta"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("hard");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["hard"] = inputDir + it->second; }
+ }
+ }
+
+ //check for required parameters
+ fasta = validParameter.validFile(parameters, "fasta", false);
+ if (fasta == "not found") {
+ fasta = m->getFastaFile();
+ if (fasta != "") {
+ fastafileNames.push_back(fasta);
+ m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine();
+ string simpleName = m->getSimpleName(fasta);
+ filterFileName += simpleName.substr(0, simpleName.find_first_of('.'));
+ }
+ else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
+ }
+ else {
+ m->splitAtDash(fasta, fastafileNames);
+
+ //go through files and make sure they are good, if not, then disregard them
+ for (int i = 0; i < fastafileNames.size(); i++) {
+
+ bool ignore = false;
+ if (fastafileNames[i] == "current") {
+ fastafileNames[i] = m->getFastaFile();
+ if (fastafileNames[i] != "") { m->mothurOut("Using " + fastafileNames[i] + " as input file for the fasta parameter where you had given current."); m->mothurOutEndLine(); }
+ else {
+ m->mothurOut("You have no current fastafile, ignoring current."); m->mothurOutEndLine(); ignore=true;
+ //erase from file list
+ fastafileNames.erase(fastafileNames.begin()+i);
+ i--;
+ }
+ }
+
+ if (!ignore) {
+ if (inputDir != "") {
+ string path = m->hasPath(fastafileNames[i]);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { fastafileNames[i] = inputDir + fastafileNames[i]; }
+ }