#include "sharedutilities.h"
//**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getValidParameters(){
+vector<string> RemoveGroupsCommand::setParameters(){
try {
- string Array[] = {"fasta","name", "group", "accnos", "groups","list","taxonomy","outputdir","inputdir" };
- vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
+ CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname);
+ CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup);
+ CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist);
+ CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy);
+ CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
+ CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
+ 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, "RemoveGroupsCommand", "getValidParameters");
+ m->errorOut(e, "RemoveGroupsCommand", "setParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+string RemoveGroupsCommand::getHelpString(){
+ try {
+ string helpString = "";
+ helpString += "The remove.groups command removes sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n";
+ helpString += "It outputs a file containing the sequences NOT in the those specified groups.\n";
+ helpString += "The remove.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required, unless you have a current group file.\n";
+ helpString += "You must also provide an accnos containing the list of groups to remove or set the groups parameter to the groups you wish to remove.\n";
+ helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like removed. You can separate group names with dashes.\n";
+ helpString += "The remove.groups command should be in the following format: remove.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n";
+ helpString += "Example remove.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n";
+ helpString += "or remove.groups(groups=pasture, fasta=amazon.fasta, amazon.groups).\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, "RemoveGroupsCommand", "getHelpString");
exit(1);
}
}
+
//**********************************************************************************************************************
RemoveGroupsCommand::RemoveGroupsCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
}
}
//**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getRequiredParameters(){
- try {
- string Array[] = {"group"};
- vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- return myArray;
- }
- catch(exception& e) {
- m->errorOut(e, "RemoveGroupsCommand", "getRequiredParameters");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getRequiredFiles(){
- try {
- vector<string> myArray;
- return myArray;
- }
- catch(exception& e) {
- m->errorOut(e, "RemoveGroupsCommand", "getRequiredFiles");
- exit(1);
- }
-}
-//**********************************************************************************************************************
RemoveGroupsCommand::RemoveGroupsCommand(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 {
- //valid paramters for this command
- string Array[] = {"fasta","name", "group", "accnos", "groups", "list","taxonomy","outputdir","inputdir" };
- vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ vector<string> myArray = setParameters();
OptionParser parser(option);
map<string,string> parameters = parser.getParameters();
accnosfile = validParameter.validFile(parameters, "accnos", true);
if (accnosfile == "not open") { abort = true; }
else if (accnosfile == "not found") { accnosfile = ""; }
+ else { m->setAccnosFile(accnosfile); }
fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not open") { abort = true; }
else if (fastafile == "not found") { fastafile = ""; }
+ else { m->setFastaFile(fastafile); }
namefile = validParameter.validFile(parameters, "name", true);
if (namefile == "not open") { abort = true; }
else if (namefile == "not found") { namefile = ""; }
+ else { m->setNameFile(namefile); }
groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
- else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; }
+ else if (groupfile == "not found") {
+ //if there is a current group file, use it
+ groupfile = m->getGroupFile();
+ if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
+ else { m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; }
+ }else { m->setGroupFile(groupfile); }
listfile = validParameter.validFile(parameters, "list", true);
if (listfile == "not open") { abort = true; }
else if (listfile == "not found") { listfile = ""; }
+ else { m->setListFile(listfile); }
taxfile = validParameter.validFile(parameters, "taxonomy", true);
if (taxfile == "not open") { abort = true; }
else if (taxfile == "not found") { taxfile = ""; }
+ else { m->setTaxonomyFile(taxfile); }
groups = validParameter.validFile(parameters, "groups", false);
if (groups == "not found") { groups = ""; }
}
//**********************************************************************************************************************
-void RemoveGroupsCommand::help(){
- try {
- m->mothurOut("The remove.groups command removes sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n");
- m->mothurOut("It outputs a file containing the sequences NOT in the those specified groups.\n");
- m->mothurOut("The remove.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required.\n");
- m->mothurOut("You must also provide an accnos containing the list of groups to remove or set the groups parameter to the groups you wish to remove.\n");
- m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like removed. You can separate group names with dashes.\n");
- m->mothurOut("The remove.groups command should be in the following format: remove.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n");
- m->mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n");
- m->mothurOut("or remove.seqs(groups=pasture, fasta=amazon.fasta, amazon.groups).\n");
- m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
- }
- catch(exception& e) {
- m->errorOut(e, "RemoveGroupsCommand", "help");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-
int RemoveGroupsCommand::execute(){
try {
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
m->mothurOut("Removed " + toString(names.size()) + " sequences. From the groups: "); m->mothurOutEndLine();
- for (int i = 0; i < Groups.size(); i++) { m->mothurOut(Groups[i]); m->mothurOutEndLine(); }
+ for (int i = 0; i < Groups.size(); i++) { m->mothurOut(Groups[i]); m->mothurOut("\t" + toString(groupMap->getNumSeqs(Groups[i]))); m->mothurOutEndLine(); }
m->mothurOutEndLine();
if (outputNames.size() != 0) {