//*************************************************************************************************************** ChimeraPerseusCommand::ChimeraPerseusCommand(string option) { try { abort = false; calledHelp = false; //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("chimera.uchime"); 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; } } vector<string> tempOutNames; outputTypes["chimera"] = tempOutNames; outputTypes["accnos"] = 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 = ""; } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { //if there is a current fasta file, use it string filename = m->getFastaFile(); if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->splitAtDash(fastafile, 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]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(fastaFileNames[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() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; }else { m->setFastaFile(fastaFileNames[i]); } } } //make sure there is at least one valid file left if (fastaFileNames.size() == 0) { m->mothurOut("[ERROR]: no valid files."); m->mothurOutEndLine(); abort = true; } } //check for required parameters bool hasName = true; namefile = validParameter.validFile(parameters, "name", false); if (namefile == "not found") { //if there is a current fasta file, use it string filename = m->getNameFile(); if (filename != "") { nameFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the name parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile and the name parameter is required."); m->mothurOutEndLine(); abort = true; } hasName = false; }else { m->splitAtDash(namefile, nameFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < nameFileNames.size(); i++) { bool ignore = false; if (nameFileNames[i] == "current") { nameFileNames[i] = m->getNameFile(); if (nameFileNames[i] != "") { m->mothurOut("Using " + nameFileNames[i] + " as input file for the name parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list nameFileNames.erase(nameFileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(nameFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { nameFileNames[i] = inputDir + nameFileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(nameFileNames[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() + m->getSimpleName(nameFileNames[i]); m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); nameFileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(nameFileNames[i]); m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); nameFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + nameFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list nameFileNames.erase(nameFileNames.begin()+i); i--; }else { m->setNameFile(nameFileNames[i]); } } } //make sure there is at least one valid file left if (nameFileNames.size() == 0) { m->mothurOut("[ERROR]: no valid name files."); m->mothurOutEndLine(); abort = true; } } if (hasName && (nameFileNames.size() != fastaFileNames.size())) { m->mothurOut("[ERROR]: The number of namefiles does not match the number of fastafiles, please correct."); m->mothurOutEndLine(); abort=true; } bool hasGroup = true; groupfile = validParameter.validFile(parameters, "group", false); if (groupfile == "not found") { groupfile = ""; hasGroup = false; } else { m->splitAtDash(groupfile, groupFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < groupFileNames.size(); i++) { bool ignore = false; if (groupFileNames[i] == "current") { groupFileNames[i] = m->getGroupFile(); if (groupFileNames[i] != "") { m->mothurOut("Using " + groupFileNames[i] + " as input file for the group parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list groupFileNames.erase(groupFileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(groupFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { groupFileNames[i] = inputDir + groupFileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(groupFileNames[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() + m->getSimpleName(groupFileNames[i]); m->mothurOut("Unable to open " + groupFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); groupFileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(groupFileNames[i]); m->mothurOut("Unable to open " + groupFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); groupFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + groupFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list groupFileNames.erase(groupFileNames.begin()+i); i--; }else { m->setGroupFile(groupFileNames[i]); } } } //make sure there is at least one valid file left if (groupFileNames.size() == 0) { m->mothurOut("[ERROR]: no valid group files."); m->mothurOutEndLine(); abort = true; } } if (hasGroup && (groupFileNames.size() != fastaFileNames.size())) { m->mothurOut("[ERROR]: The number of groupfiles does not match the number of fastafiles, please correct."); m->mothurOutEndLine(); 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 = ""; } string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "0.50"; } m->mothurConvert(temp, cutoff); temp = validParameter.validFile(parameters, "alpha", false); if (temp == "not found"){ temp = "-5.54"; } m->mothurConvert(temp, alpha); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "0.33"; } m->mothurConvert(temp, beta); } } catch(exception& e) { m->errorOut(e, "ChimeraPerseusCommand", "ChimeraPerseusCommand"); exit(1); } }
SeqSummaryCommand::SeqSummaryCommand(string option) { try { abort = false; calledHelp = false; //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("summary.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 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("name"); //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["name"] = inputDir + it->second; } } it = parameters.find("count"); //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["count"] = inputDir + it->second; } } } //initialize outputTypes vector<string> tempOutNames; outputTypes["summary"] = tempOutNames; //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } else if (fastafile == "not found") { fastafile = m->getFastaFile(); if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->setFastaFile(fastafile); } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } else { m->setNameFile(namefile); } countfile = validParameter.validFile(parameters, "count", true); if (countfile == "not open") { abort = true; countfile = ""; } else if (countfile == "not found") { countfile = ""; } else { m->setCountTableFile(countfile); } if ((countfile != "") && (namefile != "")) { m->mothurOut("You must enter ONLY ONE of the following: count or name."); m->mothurOutEndLine(); 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 = ""; outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); if (countfile == "") { if (namefile == "") { vector<string> files; files.push_back(fastafile); parser.getNameFile(files); } } } } catch(exception& e) { m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); exit(1); } }
//*************************************************************************************************************** ChimeraCheckCommand::ChimeraCheckCommand(string option) { try { abort = false; calledHelp = false; ReferenceDB* rdb = ReferenceDB::getInstance(); //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("chimera.check"); 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; } } vector<string> tempOutNames; outputTypes["chimera"] = 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 { it = parameters.find("reference"); //user has given a template file if(it != parameters.end()){ string path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["reference"] = inputDir + it->second; } } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { //if there is a current fasta file, use it string filename = m->getFastaFile(); if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->splitAtDash(fastafile, 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]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(fastaFileNames[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() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } //if you can't open it, try default location if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + fastaFileNames[i] +". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; }else { m->setFastaFile(fastaFileNames[i]); } } } //make sure there is at least one valid file left if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); 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 = ""; } namefile = validParameter.validFile(parameters, "name", false); if (namefile == "not found") { namefile = ""; } else { m->splitAtDash(namefile, nameFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < nameFileNames.size(); i++) { bool ignore = false; if (nameFileNames[i] == "current") { nameFileNames[i] = m->getNameFile(); if (nameFileNames[i] != "") { m->mothurOut("Using " + nameFileNames[i] + " as input file for the name parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list nameFileNames.erase(nameFileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(nameFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { nameFileNames[i] = inputDir + nameFileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(nameFileNames[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() + m->getSimpleName(nameFileNames[i]); m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); nameFileNames[i] = tryPath; } } //if you can't open it, try default location if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(nameFileNames[i]); m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); nameFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + nameFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list nameFileNames.erase(nameFileNames.begin()+i); i--; }else { m->setNameFile(nameFileNames[i]); } } } //make sure there is at least one valid file left if (nameFileNames.size() != 0) { if (nameFileNames.size() != fastaFileNames.size()) { m->mothurOut("Different number of valid name files and fasta files, aborting command."); m->mothurOutEndLine(); abort = true; } } } string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "save", false); if (temp == "not found"){ temp = "f"; } save = m->isTrue(temp); rdb->save = save; if (save) { //clear out old references rdb->clearMemory(); } //this has to go after save so that if the user sets save=t and provides no reference we abort templatefile = validParameter.validFile(parameters, "reference", true); if (templatefile == "not found") { //check for saved reference sequences if (rdb->referenceSeqs.size() != 0) { templatefile = "saved"; }else { m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required."); m->mothurOutEndLine(); abort = true; } }else if (templatefile == "not open") { abort = true; } else { if (save) { rdb->setSavedReference(templatefile); } } temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found") { temp = "7"; } m->mothurConvert(temp, ksize); temp = validParameter.validFile(parameters, "svg", false); if (temp == "not found") { temp = "F"; } svg = m->isTrue(temp); if (nameFileNames.size() != 0) { svg = true; } temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "10"; } m->mothurConvert(temp, increment); } } catch(exception& e) { m->errorOut(e, "ChimeraCheckCommand", "ChimeraCheckCommand"); exit(1); } }
//********************************************************************************************************************** AlignCommand::AlignCommand(string option) { try { abort = false; calledHelp = false; //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("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; } } //initialize outputTypes vector<string> tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["alignreport"] = tempOutNames; outputTypes["accnos"] = tempOutNames; //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("reference"); //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["reference"] = inputDir + it->second; } } } candidateFileName = validParameter.validFile(parameters, "fasta", false); if (candidateFileName == "not found") { //if there is a current fasta file, use it string filename = m->getFastaFile(); if (filename != "") { candidateFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the candidate parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->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++) { //candidateFileNames[i] = m->getFullPathName(candidateFileNames[i]); bool ignore = false; if (candidateFileNames[i] == "current") { candidateFileNames[i] = m->getFastaFile(); if (candidateFileNames[i] != "") { m->mothurOut("Using " + candidateFileNames[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 candidateFileNames.erase(candidateFileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->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 = m->openInputFile(candidateFileNames[i], in, "noerror"); in.close(); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set string tryPath = m->getDefaultPath() + m->getSimpleName(candidateFileNames[i]); m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); candidateFileNames[i] = tryPath; } } //if you can't open it, try output location if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(candidateFileNames[i]); m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); candidateFileNames[i] = tryPath; } } 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--; }else { m->setFastaFile(candidateFileNames[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"; } m->mothurConvert(temp, kmerSize); temp = validParameter.validFile(parameters, "match", false); if (temp == "not found"){ temp = "1.0"; } m->mothurConvert(temp, match); temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found"){ temp = "-1.0"; } m->mothurConvert(temp, misMatch); temp = validParameter.validFile(parameters, "gapopen", false); if (temp == "not found"){ temp = "-5.0"; } m->mothurConvert(temp, gapOpen); temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-2.0"; } m->mothurConvert(temp, gapExtend); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "f"; } flip = m->isTrue(temp); //this has to go after save so that if the user sets save=t and provides no reference we abort templateFileName = validParameter.validFile(parameters, "reference", true); if (templateFileName == "not found") { m->mothurOut("[ERROR]: The reference parameter is a required for the align.seqs command, aborting.\n"); abort = true; }else if (templateFileName == "not open") { abort = true; } temp = validParameter.validFile(parameters, "threshold", false); if (temp == "not found"){ temp = "0.50"; } m->mothurConvert(temp, threshold); search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; } if ((search != "suffix") && (search != "kmer") && (search != "blast")) { m->mothurOut("invalid search option: choices are kmer, suffix or blast."); m->mothurOutEndLine(); abort=true; } align = validParameter.validFile(parameters, "align", false); if (align == "not found"){ align = "needleman"; } if ((align != "needleman") && (align != "gotoh") && (align != "blast") && (align != "noalign")) { m->mothurOut("invalid align option: choices are needleman, gotoh, blast or noalign."); m->mothurOutEndLine(); abort=true; } } } catch(exception& e) { m->errorOut(e, "AlignCommand", "AlignCommand"); exit(1); } }
//********************************************************************************************************************** DistanceCommand::DistanceCommand(string option) { try { abort = false; calledHelp = false; Estimators.clear(); //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("dist.seqs"); map<string, string>::iterator it2; //check to make sure all parameters are valid for command for (it2 = parameters.begin(); it2 != parameters.end(); it2++) { if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; } } //initialize outputTypes vector<string> tempOutNames; outputTypes["phylip"] = tempOutNames; outputTypes["column"] = 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; it2 = parameters.find("fasta"); //user has given a template file if(it2 != parameters.end()){ path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it2->second; } } it2 = parameters.find("oldfasta"); //user has given a template file if(it2 != parameters.end()){ path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["oldfasta"] = inputDir + it2->second; } } it2 = parameters.find("column"); //user has given a template file if(it2 != parameters.end()){ path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it2->second; } } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not found") { fastafile = m->getFastaFile(); if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); ifstream inFASTA; m->openInputFile(fastafile, inFASTA); alignDB = SequenceDB(inFASTA); inFASTA.close(); }else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else if (fastafile == "not open") { abort = true; } else{ ifstream inFASTA; m->openInputFile(fastafile, inFASTA); alignDB = SequenceDB(inFASTA); inFASTA.close(); m->setFastaFile(fastafile); } oldfastafile = validParameter.validFile(parameters, "oldfasta", true); if (oldfastafile == "not found") { oldfastafile = ""; } else if (oldfastafile == "not open") { abort = true; } column = validParameter.validFile(parameters, "column", true); if (column == "not found") { column = ""; } else if (column == "not open") { abort = true; } else { m->setColumnFile(column); } //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(fastafile); //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... calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "onegap"; } else { if (calc == "default") { calc = "onegap"; } } m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "countends", false); if(temp == "not found"){ temp = "T"; } convert(temp, countends); temp = validParameter.validFile(parameters, "cutoff", false); if(temp == "not found"){ temp = "1.0"; } m->mothurConvert(temp, cutoff); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "compress", false); if(temp == "not found"){ temp = "F"; } convert(temp, compress); output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "column"; } if (output == "phylip") { output = "lt"; } if (((column != "") && (oldfastafile == "")) || ((column == "") && (oldfastafile != ""))) { m->mothurOut("If you provide column or oldfasta, you must provide both."); m->mothurOutEndLine(); abort=true; } if ((column != "") && (oldfastafile != "") && (output != "column")) { m->mothurOut("You have provided column and oldfasta, indicating you want to append distances to your column file. Your output must be in column format to do so."); m->mothurOutEndLine(); abort=true; } if ((output != "column") && (output != "lt") && (output != "square")) { m->mothurOut(output + " is not a valid output form. Options are column, lt and square. I will use column."); m->mothurOutEndLine(); output = "column"; } } } catch(exception& e) { m->errorOut(e, "DistanceCommand", "DistanceCommand"); exit(1); } }
FilterSeqsCommand::FilterSeqsCommand(string option) { try { abort = false; calledHelp = false; recalced = 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]; } } ifstream in; int ableToOpen = m->openInputFile(fastafileNames[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() + m->getSimpleName(fastafileNames[i]); m->mothurOut("Unable to open " + fastafileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastafileNames[i] = tryPath; } } //if you can't open it, try default location if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(fastafileNames[i]); m->mothurOut("Unable to open " + fastafileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastafileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + fastafileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastafileNames.erase(fastafileNames.begin()+i); i--; }else{ string simpleName = m->getSimpleName(fastafileNames[i]); filterFileName += simpleName.substr(0, simpleName.find_first_of('.')); m->setFastaFile(fastafileNames[i]); } in.close(); } } //make sure there is at least one valid file left if (fastafileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; } } if (!abort) { //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(fastafileNames[0]); //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; hard = validParameter.validFile(parameters, "hard", true); if (hard == "not found") { hard = ""; } else if (hard == "not open") { hard = ""; abort = true; } temp = validParameter.validFile(parameters, "trump", false); if (temp == "not found") { temp = "*"; } trump = temp[0]; temp = validParameter.validFile(parameters, "soft", false); if (temp == "not found") { soft = 0; } else { soft = (float)atoi(temp.c_str()) / 100.0; } temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); vertical = validParameter.validFile(parameters, "vertical", false); if (vertical == "not found") { if ((hard == "") && (trump == '*') && (soft == 0)) { vertical = "T"; } //you have not given a hard file or set the trump char. else { vertical = "F"; } } numSeqs = 0; } } catch(exception& e) { m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); exit(1); } }
//*************************************************************************************************************** ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { try { abort = false; calledHelp = false; //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("chimera.bellerophon"); 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["chimera"] = tempOutNames; outputTypes["accnos"] = 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 = ""; } fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { //if there is a current fasta file, use it string filename = m->getFastaFile(); if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->splitAtDash(fastafile, 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]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(fastaFileNames[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() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } //if you can't open it, try default location if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; }else { m->setFastaFile(fastaFileNames[i]); } } } //make sure there is at least one valid file left if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); 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 = ""; } string temp; temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } filter = m->isTrue(temp); temp = validParameter.validFile(parameters, "correction", false); if (temp == "not found") { temp = "T"; } correction = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; } m->mothurConvert(temp, window); temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "25"; } m->mothurConvert(temp, increment); } } catch(exception& e) { m->errorOut(e, "ChimeraBellerophonCommand", "ChimeraBellerophonCommand"); exit(1); } }
//********************************************************************************************************************** ClassifySeqsCommand::ClassifySeqsCommand(string option) { try { abort = false; calledHelp = false; hasName = false; hasCount=false; //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("classify.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)) { abort = true; } } //initialize outputTypes vector<string> tempOutNames; outputTypes["taxonomy"] = tempOutNames; outputTypes["taxsummary"] = tempOutNames; outputTypes["matchdist"] = tempOutNames; outputTypes["accnos"] = tempOutNames; //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.valid(parameters, "outputdir"); 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.valid(parameters, "inputdir"); if (inputDir == "not found"){ inputDir = ""; } else { string path; it = parameters.find("reference"); //user has given a template file if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["reference"] = inputDir + it->second; } } it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } it = parameters.find("count"); //user has given a template file if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["count"] = inputDir + it->second; } } it = parameters.find("fasta"); if(it != parameters.end()){ path = util.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("name"); if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } it = parameters.find("group"); if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } } fastafile = validParameter.validFile(parameters, "fasta"); if (fastafile == "not found") { fastafile = current->getFastaFile(); if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter.\n"); } else { m->mothurOut("[ERROR]: You have no current fasta file and the fasta parameter is required.\n"); abort = true; } } else if (fastafile == "not open") { abort = true; } else { current->setFastaFile(fastafile); } namefile = validParameter.validFile(parameters, "name"); if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } else { current->setNameFile(namefile); } if (namefile != "") { hasName = true; } //check for required parameters countfile = validParameter.validFile(parameters, "count"); if (countfile == "not open") { countfile = ""; abort = true; } else if (countfile == "not found") { countfile = ""; } else { current->setCountFile(countfile); } if (countfile != "") { hasCount = true; } //make sure there is at least one valid file left if (hasName && hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or name.\n"); abort = true; } bool hasGroup = false; groupfile = validParameter.validFile(parameters, "group"); if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } else { current->setGroupFile(groupfile); hasGroup = true; } if (hasGroup && hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or group.\n"); abort = true; } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.valid(parameters, "outputdir"); if (outputDir == "not found"){ outputDir = ""; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... string temp; temp = validParameter.valid(parameters, "processors"); if (temp == "not found"){ temp = current->getProcessors(); } processors = current->setProcessors(temp); //this has to go after save so that if the user sets save=t and provides no reference we abort templateFileName = validParameter.validFile(parameters, "reference"); if (templateFileName == "not found") { m->mothurOut("[ERROR]: The reference parameter is a required for the classify.seqs command.\n"); abort = true; }else if (templateFileName == "not open") { abort = true; } //this has to go after save so that if the user sets save=t and provides no reference we abort taxonomyFileName = validParameter.validFile(parameters, "taxonomy"); if (taxonomyFileName == "not found") { m->mothurOut("[ERROR]: The taxonomy parameter is a required for the classify.seqs command.\n"); abort = true; }else if (taxonomyFileName == "not open") { abort = true; } search = validParameter.valid(parameters, "search"); if (search == "not found"){ search = "kmer"; } method = validParameter.valid(parameters, "method"); if (method == "not found"){ method = "wang"; } temp = validParameter.valid(parameters, "ksize"); if (temp == "not found"){ temp = "8"; if (method == "zap") { temp = "7"; } } util.mothurConvert(temp, kmerSize); temp = validParameter.valid(parameters, "match"); if (temp == "not found"){ temp = "1.0"; } util.mothurConvert(temp, match); temp = validParameter.valid(parameters, "printlevel"); if (temp == "not found"){ temp = "-1"; } util.mothurConvert(temp, printlevel); temp = validParameter.valid(parameters, "mismatch"); if (temp == "not found"){ temp = "-1.0"; } util.mothurConvert(temp, misMatch); temp = validParameter.valid(parameters, "gapopen"); if (temp == "not found"){ temp = "-2.0"; } util.mothurConvert(temp, gapOpen); temp = validParameter.valid(parameters, "gapextend"); if (temp == "not found"){ temp = "-1.0"; } util.mothurConvert(temp, gapExtend); temp = validParameter.valid(parameters, "numwanted"); if (temp == "not found"){ temp = "10"; } util.mothurConvert(temp, numWanted); temp = validParameter.valid(parameters, "cutoff"); if (temp == "not found"){ temp = "80"; } util.mothurConvert(temp, cutoff); temp = validParameter.valid(parameters, "probs"); if (temp == "not found"){ temp = "true"; } probs = util.isTrue(temp); temp = validParameter.valid(parameters, "relabund"); if (temp == "not found"){ temp = "false"; } relabund = util.isTrue(temp); temp = validParameter.valid(parameters, "shortcuts"); if (temp == "not found"){ temp = "true"; } writeShortcuts = util.isTrue(temp); flip = true; temp = validParameter.valid(parameters, "iters"); if (temp == "not found") { temp = "100"; } util.mothurConvert(temp, iters); output = validParameter.valid(parameters, "output"); if(output == "not found"){ output = "detail"; } if ((output != "simple") && (output != "detail")) { m->mothurOut(output + " is not a valid output form. Options are simple and detail. I will use detail."); m->mothurOutEndLine(); output = "detail"; } if ((method == "wang") && (search != "kmer")) { m->mothurOut("The wang method requires the kmer search. " + search + " will be disregarded, and kmer will be used." ); m->mothurOutEndLine(); search = "kmer"; } if ((method == "zap") && ((search != "kmer") && (search != "align"))) { m->mothurOut("The zap method requires the kmer or align search. " + search + " will be disregarded, and kmer will be used." ); m->mothurOutEndLine(); search = "kmer"; } if (!abort) { if (!hasCount) { if (namefile == ""){ if (fastafile != "") { vector<string> files; files.push_back(fastafile); if (!current->getMothurCalling()) { parser.getNameFile(files); } } } } } } } catch(exception& e) { m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); exit(1); } }
//********************************************************************************************************************** AlignCommand::AlignCommand(string option) { try { abort = false; calledHelp = false; //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("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)) { abort = true; } } //initialize outputTypes vector<string> tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["alignreport"] = tempOutNames; outputTypes["accnos"] = tempOutNames; //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.valid(parameters, "outputdir"); 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.valid(parameters, "inputdir"); if (inputDir == "not found"){ inputDir = ""; } else { string path; //user has given a template file it = parameters.find("reference"); if(it != parameters.end()){ path = util.hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["reference"] = inputDir + it->second; } } it = parameters.find("fasta"); if(it != parameters.end()){ path = util.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; } } } templateFileName = validParameter.validFile(parameters, "reference"); if (templateFileName == "not found") { m->mothurOut("[ERROR]: The reference parameter is a required for the align.seqs command, aborting.\n"); abort = true; }else if (templateFileName == "not open") { abort = true; } fastafile = validParameter.validFile(parameters, "fasta"); if (fastafile == "not found") { fastafile = current->getFastaFile(); if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter.\n"); } else { m->mothurOut("[ERROR]: You have no current fasta file and the fasta parameter is required.\n"); abort = true; } } else if (fastafile == "not open") { abort = true; } else { current->setFastaFile(fastafile); } //check for optional parameter and set defaults // ...at some point should added some additional type checking... string temp; temp = validParameter.valid(parameters, "ksize"); if (temp == "not found"){ temp = "8"; } util.mothurConvert(temp, kmerSize); temp = validParameter.valid(parameters, "match"); if (temp == "not found"){ temp = "1.0"; } util.mothurConvert(temp, match); temp = validParameter.valid(parameters, "mismatch"); if (temp == "not found"){ temp = "-1.0"; } util.mothurConvert(temp, misMatch); temp = validParameter.valid(parameters, "gapopen"); if (temp == "not found"){ temp = "-5.0"; } util.mothurConvert(temp, gapOpen); temp = validParameter.valid(parameters, "gapextend"); if (temp == "not found"){ temp = "-2.0"; } util.mothurConvert(temp, gapExtend); temp = validParameter.valid(parameters, "processors"); if (temp == "not found"){ temp = current->getProcessors(); } processors = current->setProcessors(temp); temp = validParameter.valid(parameters, "flip"); if (temp == "not found"){ temp = "t"; } flip = util.isTrue(temp); temp = validParameter.valid(parameters, "threshold"); if (temp == "not found"){ temp = "0.50"; } util.mothurConvert(temp, threshold); search = validParameter.valid(parameters, "search"); if (search == "not found"){ search = "kmer"; } if ((search != "suffix") && (search != "kmer") && (search != "blast")) { m->mothurOut("invalid search option: choices are kmer, suffix or blast."); m->mothurOutEndLine(); abort=true; } align = validParameter.valid(parameters, "align"); if (align == "not found"){ align = "needleman"; } if ((align != "needleman") && (align != "gotoh") && (align != "blast") && (align != "noalign")) { m->mothurOut("invalid align option: choices are needleman, gotoh, blast or noalign."); m->mothurOutEndLine(); abort=true; } } } catch(exception& e) { m->errorOut(e, "AlignCommand", "AlignCommand"); exit(1); } }
//********************************************************************************************************************** ClassifySeqsCommand::ClassifySeqsCommand(string option) { try { abort = false; calledHelp = false; hasName = false; hasCount=false; //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("classify.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["taxonomy"] = tempOutNames; outputTypes["taxsummary"] = tempOutNames; outputTypes["matchdist"] = tempOutNames; outputTypes["accnos"] = tempOutNames; //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("reference"); //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["reference"] = inputDir + it->second; } } it = parameters.find("taxonomy"); //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["taxonomy"] = inputDir + it->second; } } } fastaFileName = validParameter.validFile(parameters, "fasta", false); if (fastaFileName == "not found") { //if there is a current fasta file, use it string filename = m->getFastaFile(); if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } } else { m->splitAtDash(fastaFileName, 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]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(fastaFileNames[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() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); fastaFileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; }else { m->setFastaFile(fastaFileNames[i]); } } } //make sure there is at least one valid file left if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; } } namefile = validParameter.validFile(parameters, "name", false); if (namefile == "not found") { namefile = ""; } else { m->splitAtDash(namefile, namefileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < namefileNames.size(); i++) { bool ignore = false; if (namefileNames[i] == "current") { namefileNames[i] = m->getNameFile(); if (namefileNames[i] != "") { m->mothurOut("Using " + namefileNames[i] + " as input file for the name parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list namefileNames.erase(namefileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(namefileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { namefileNames[i] = inputDir + namefileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(namefileNames[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() + m->getSimpleName(namefileNames[i]); m->mothurOut("Unable to open " + namefileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); namefileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(namefileNames[i]); m->mothurOut("Unable to open " + namefileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); namefileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + namefileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); abort = true; //erase from file list namefileNames.erase(namefileNames.begin()+i); i--; }else { m->setNameFile(namefileNames[i]); } } } } if (namefileNames.size() != 0) { hasName = true; } if (namefile != "") { if (namefileNames.size() != fastaFileNames.size()) { abort = true; m->mothurOut("If you provide a name file, you must have one for each fasta file."); m->mothurOutEndLine(); } } //check for required parameters countfile = validParameter.validFile(parameters, "count", false); if (countfile == "not found") { countfile = ""; }else { m->splitAtDash(countfile, countfileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < countfileNames.size(); i++) { bool ignore = false; if (countfileNames[i] == "current") { countfileNames[i] = m->getCountTableFile(); if (countfileNames[i] != "") { m->mothurOut("Using " + countfileNames[i] + " as input file for the count parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current count file, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list countfileNames.erase(countfileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(countfileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { countfileNames[i] = inputDir + countfileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(countfileNames[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() + m->getSimpleName(countfileNames[i]); m->mothurOut("Unable to open " + countfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); countfileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(countfileNames[i]); m->mothurOut("Unable to open " + countfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); countfileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + countfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list countfileNames.erase(countfileNames.begin()+i); i--; }else { m->setCountTableFile(countfileNames[i]); } } } } if (countfileNames.size() != 0) { hasCount = true; if (countfileNames.size() != fastaFileNames.size()) {m->mothurOut("If you provide a count file, you must have one for each fasta file."); m->mothurOutEndLine(); } } //make sure there is at least one valid file left if (hasName && hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or name."); m->mothurOutEndLine(); abort = true; } groupfile = validParameter.validFile(parameters, "group", false); if (groupfile == "not found") { groupfile = ""; } else { m->splitAtDash(groupfile, groupfileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < groupfileNames.size(); i++) { bool ignore = false; if (groupfileNames[i] == "current") { groupfileNames[i] = m->getGroupFile(); if (groupfileNames[i] != "") { m->mothurOut("Using " + groupfileNames[i] + " as input file for the group parameter where you had given current."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current group file, ignoring current."); m->mothurOutEndLine(); ignore=true; //erase from file list groupfileNames.erase(groupfileNames.begin()+i); i--; } } if (!ignore) { if (inputDir != "") { string path = m->hasPath(groupfileNames[i]); //cout << path << '\t' << inputDir << endl; //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { groupfileNames[i] = inputDir + groupfileNames[i]; } } int ableToOpen; ifstream in; ableToOpen = m->openInputFile(groupfileNames[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() + m->getSimpleName(groupfileNames[i]); m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); groupfileNames[i] = tryPath; } } if (ableToOpen == 1) { if (m->getOutputDir() != "") { //default path is set string tryPath = m->getOutputDir() + m->getSimpleName(groupfileNames[i]); m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); ifstream in2; ableToOpen = m->openInputFile(tryPath, in2, "noerror"); in2.close(); groupfileNames[i] = tryPath; } } in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + groupfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list groupfileNames.erase(groupfileNames.begin()+i); i--; }else { m->setGroupFile(groupfileNames[i]); } } } } if (groupfile != "") { if (groupfileNames.size() != fastaFileNames.size()) { abort = true; m->mothurOut("If you provide a group file, you must have one for each fasta file."); m->mothurOutEndLine(); } if (hasCount) { m->mothurOut("[ERROR]: You must enter ONLY ONE of the following: count or group."); m->mothurOutEndLine(); abort = true; } }else { for (int i = 0; i < fastaFileNames.size(); i++) { groupfileNames.push_back(""); } } //check for optional parameter and set defaults // ...at some point should added some additional type checking... string temp; temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); m->mothurConvert(temp, processors); //this has to go after save so that if the user sets save=t and provides no reference we abort templateFileName = validParameter.validFile(parameters, "reference", true); if (templateFileName == "not found") { m->mothurOut("[ERROR]: The reference parameter is a required for the classify.seqs command.\n"); abort = true; }else if (templateFileName == "not open") { abort = true; } //this has to go after save so that if the user sets save=t and provides no reference we abort taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true); if (taxonomyFileName == "not found") { m->mothurOut("[ERROR]: The taxonomy parameter is a required for the classify.seqs command.\n"); abort = true; }else if (taxonomyFileName == "not open") { abort = true; } search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; } method = validParameter.validFile(parameters, "method", false); if (method == "not found"){ method = "wang"; } temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found"){ temp = "8"; if (method == "zap") { temp = "7"; } } m->mothurConvert(temp, kmerSize); temp = validParameter.validFile(parameters, "match", false); if (temp == "not found"){ temp = "1.0"; } m->mothurConvert(temp, match); temp = validParameter.validFile(parameters, "printlevel", false); if (temp == "not found"){ temp = "-1"; } m->mothurConvert(temp, printlevel); temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found"){ temp = "-1.0"; } m->mothurConvert(temp, misMatch); temp = validParameter.validFile(parameters, "gapopen", false); if (temp == "not found"){ temp = "-2.0"; } m->mothurConvert(temp, gapOpen); temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-1.0"; } m->mothurConvert(temp, gapExtend); temp = validParameter.validFile(parameters, "numwanted", false); if (temp == "not found"){ temp = "10"; } m->mothurConvert(temp, numWanted); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "80"; } m->mothurConvert(temp, cutoff); temp = validParameter.validFile(parameters, "probs", false); if (temp == "not found"){ temp = "true"; } probs = m->isTrue(temp); temp = validParameter.validFile(parameters, "relabund", false); if (temp == "not found"){ temp = "false"; } relabund = m->isTrue(temp); temp = validParameter.validFile(parameters, "shortcuts", false); if (temp == "not found"){ temp = "true"; } writeShortcuts = m->isTrue(temp); //temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "T"; } //flip = m->isTrue(temp); flip = true; temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "100"; } m->mothurConvert(temp, iters); output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "detail"; } if ((output != "simple") && (output != "detail")) { m->mothurOut(output + " is not a valid output form. Options are simple and detail. I will use detail."); m->mothurOutEndLine(); output = "detail"; } if ((method == "wang") && (search != "kmer")) { m->mothurOut("The wang method requires the kmer search. " + search + " will be disregarded, and kmer will be used." ); m->mothurOutEndLine(); search = "kmer"; } if ((method == "zap") && ((search != "kmer") && (search != "align"))) { m->mothurOut("The zap method requires the kmer or align search. " + search + " will be disregarded, and kmer will be used." ); m->mothurOutEndLine(); search = "kmer"; } if (!abort) { if (!hasCount) { if (namefileNames.size() == 0){ if (fastaFileNames.size() != 0) { vector<string> files; files.push_back(fastaFileNames[fastaFileNames.size()-1]); parser.getNameFile(files); } } } } } } catch(exception& e) { m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); exit(1); } }