#include "listvector.hpp"
//**********************************************************************************************************************
-vector<string> GetSeqsCommand::getValidParameters(){
+vector<string> GetSeqsCommand::setParameters(){
try {
- string Array[] = {"fasta","name", "group", "qfile","alignreport", "accnos", "accnos2","dups", "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,false); 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 palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport);
+ CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile);
+ CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
+ CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+ CommandParameter paccnos2("accnos2", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos2);
+
+ 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, "GetSeqsCommand", "getValidParameters");
+ m->errorOut(e, "GetSeqsCommand", "setParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+string GetSeqsCommand::getHelpString(){
+ try {
+ string helpString = "";
+ helpString += "The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n";
+ helpString += "It outputs a file containing only the sequences in the .accnos file.\n";
+ helpString += "The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos unless you have a valid current accnos file, and at least one of the other parameters.\n";
+ helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n";
+ helpString += "The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n";
+ helpString += "Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\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, "GetSeqsCommand", "getHelpString");
exit(1);
}
}
+
//**********************************************************************************************************************
GetSeqsCommand::GetSeqsCommand(){
try {
- abort = true;
- //initialize outputTypes
+ abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
}
}
//**********************************************************************************************************************
-vector<string> GetSeqsCommand::getRequiredParameters(){
- try {
- string Array[] = {"accnos"};
- vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- return myArray;
- }
- catch(exception& e) {
- m->errorOut(e, "GetSeqsCommand", "getRequiredParameters");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-vector<string> GetSeqsCommand::getRequiredFiles(){
- try {
- vector<string> myArray;
- return myArray;
- }
- catch(exception& e) {
- m->errorOut(e, "GetSeqsCommand", "getRequiredFiles");
- exit(1);
- }
-}
-//**********************************************************************************************************************
GetSeqsCommand::GetSeqsCommand(string option) {
try {
- abort = false;
+ abort = false; calledHelp = false;
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ 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", "alignreport", "qfile", "accnos", "accnos2","dups", "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();
//check for required parameters
accnosfile = validParameter.validFile(parameters, "accnos", true);
if (accnosfile == "not open") { abort = true; }
- else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; }
+ else if (accnosfile == "not found") {
+ accnosfile = m->getAccnosFile();
+ if (accnosfile != "") { m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); }
+ else {
+ m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine();
+ abort = true;
+ }
+ }else { m->setAccnosFile(accnosfile); }
- accnosfile2 = validParameter.validFile(parameters, "accnos2", true);
- if (accnosfile2 == "not open") { abort = true; }
+ if (accnosfile2 == "not found") { accnosfile2 = ""; }
fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not open") { abort = true; }
- else if (fastafile == "not found") { fastafile = ""; }
+ 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 = ""; }
+ else { m->setGroupFile(groupfile); }
alignfile = validParameter.validFile(parameters, "alignreport", true);
if (alignfile == "not open") { abort = true; }
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); }
qualfile = validParameter.validFile(parameters, "qfile", true);
if (qualfile == "not open") { abort = true; }
else if (qualfile == "not found") { qualfile = ""; }
+ else { m->setQualFile(qualfile); }
+
+ accnosfile2 = validParameter.validFile(parameters, "accnos2", true);
+ if (accnosfile2 == "not open") { abort = true; }
+ else if (accnosfile2 == "not found") { accnosfile2 = ""; }
+
string usedDups = "true";
- string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "false"; usedDups = ""; }
+ string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "true"; usedDups = ""; }
dups = m->isTrue(temp);
if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "") && (accnosfile2 == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy, quality or listfile."); m->mothurOutEndLine(); abort = true; }
-
- if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; }
-
}
}
}
//**********************************************************************************************************************
-void GetSeqsCommand::help(){
- try {
- m->mothurOut("The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n");
- m->mothurOut("It outputs a file containing only the sequences in the .accnos file.\n");
- m->mothurOut("The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the other parameters.\n");
- m->mothurOut("The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n");
- m->mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
- m->mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\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, "GetSeqsCommand", "help");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-
int GetSeqsCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
//get names you want to keep
readAccnos();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
+
+ //set fasta file as new current fastafile
+ string current = "";
+ itTypes = outputTypes.find("fasta");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+ }
+
+ itTypes = outputTypes.find("name");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
+ }
+
+ itTypes = outputTypes.find("group");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
+ }
+
+ itTypes = outputTypes.find("list");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
+ }
+
+ itTypes = outputTypes.find("taxonomy");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
+ }
+
+ itTypes = outputTypes.find("qfile");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
+ }
+
}
return 0;
if (dups) { hold = secondCol; }
vector<string> parsedNames;
- //parse second column saving each name
- while (secondCol.find_first_of(',') != -1) {
- name = secondCol.substr(0,secondCol.find_first_of(','));
- secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
- parsedNames.push_back(name);
- }
-
- //get name after last ,
- parsedNames.push_back(secondCol);
+ m->splitAtComma(secondCol, parsedNames);
vector<string> validSecond;
for (int i = 0; i < parsedNames.size(); i++) {
set<string> namesDups;
set<string> namesAccnos = names;
+ map<string, int> nameCount;
+
+ if (namefile != "") {
+ ifstream inName;
+ m->openInputFile(namefile, inName);
+
+
+ while(!inName.eof()){
+
+ if (m->control_pressed) { inName.close(); return 0; }
+
+ string thisname, repnames;
+
+ inName >> thisname; m->gobble(inName); //read from first column
+ inName >> repnames; //read from second column
+
+ int num = m->getNumNames(repnames);
+ nameCount[thisname] = num;
+
+ m->gobble(inName);
+ }
+ inName.close();
+ }
+
while(!in.eof()){
in >> name;
if (namesAccnos.count(name) == 0){ //name unique to accnos2
- namesAccnos2.insert(name);
+ int pos = name.find_last_of('_');
+ string tempName = name;
+ if (pos != string::npos) { tempName = tempName.substr(pos+1); cout << tempName << endl; }
+ if (namesAccnos.count(tempName) == 0){
+ namesAccnos2.insert(name);
+ }else { //you are in both so erase
+ namesAccnos.erase(name);
+ namesDups.insert(name);
+ }
}else { //you are in both so erase
namesAccnos.erase(name);
namesDups.insert(name);
m->mothurOut("Names in both files : " + toString(namesDups.size())); m->mothurOutEndLine();
for (set<string>::iterator it = namesDups.begin(); it != namesDups.end(); it++) {
- out << (*it) << endl;
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
}
out << "Names unique to " + accnosfile + " : " + toString(namesAccnos.size()) << endl;
m->mothurOut("Names unique to " + accnosfile + " : " + toString(namesAccnos.size())); m->mothurOutEndLine();
for (set<string>::iterator it = namesAccnos.begin(); it != namesAccnos.end(); it++) {
- out << (*it) << endl;
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
}
out << "Names unique to " + accnosfile2 + " : " + toString(namesAccnos2.size()) << endl;
m->mothurOut("Names unique to " + accnosfile2 + " : " + toString(namesAccnos2.size())); m->mothurOutEndLine();
for (set<string>::iterator it = namesAccnos2.begin(); it != namesAccnos2.end(); it++) {
- out << (*it) << endl;
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
}
out.close();