//**********************************************************************************************************************
vector<string> GetSeqsCommand::getValidParameters(){
try {
- string Array[] = {"fasta","name", "group", "qfile","alignreport", "accnos", "dups", "list","taxonomy","outputdir","inputdir"};
+ string Array[] = {"fasta","name", "group", "qfile","alignreport", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
return myArray;
}
//**********************************************************************************************************************
GetSeqsCommand::GetSeqsCommand(){
try {
- abort = true;
- //initialize outputTypes
+ abort = true; calledHelp = true;
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
outputTypes["alignreport"] = tempOutNames;
outputTypes["list"] = tempOutNames;
outputTypes["qfile"] = tempOutNames;
+ outputTypes["accnosreport"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "GetSeqsCommand", "GetSeqsCommand");
//**********************************************************************************************************************
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 {
//valid paramters for this command
- string Array[] = {"fasta","name", "group", "alignreport", "qfile", "accnos", "dups", "list","taxonomy","outputdir","inputdir"};
+ string Array[] = {"fasta","name", "group", "alignreport", "qfile", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
OptionParser parser(option);
outputTypes["alignreport"] = tempOutNames;
outputTypes["list"] = tempOutNames;
outputTypes["qfile"] = tempOutNames;
+ outputTypes["accnosreport"] = 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 (path == "") { parameters["accnos"] = inputDir + it->second; }
}
+ it = parameters.find("accnos2");
+ //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["accnos2"] = inputDir + it->second; }
+ }
+
it = parameters.find("list");
//user has given a template file
if(it != parameters.end()){
if (accnosfile == "not open") { abort = true; }
else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); 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 = ""; }
string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "false"; usedDups = ""; }
dups = m->isTrue(temp);
- if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy, quality or listfile."); m->mothurOutEndLine(); abort = true; }
+ 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; }
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();
if (m->control_pressed) { return 0; }
//read through the correct file and output lines you want to keep
- if (namefile != "") { readName(); }
- if (fastafile != "") { readFasta(); }
- if (groupfile != "") { readGroup(); }
- if (alignfile != "") { readAlign(); }
- if (listfile != "") { readList(); }
- if (taxfile != "") { readTax(); }
- if (qualfile != "") { readQual(); }
+ if (namefile != "") { readName(); }
+ if (fastafile != "") { readFasta(); }
+ if (groupfile != "") { readGroup(); }
+ if (alignfile != "") { readAlign(); }
+ if (listfile != "") { readList(); }
+ if (taxfile != "") { readTax(); }
+ if (qualfile != "") { readQual(); }
+ if (accnosfile2 != "") { compareAccnos(); }
if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
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;
exit(1);
}
}
+//**********************************************************************************************************************
+
+int GetSeqsCommand::compareAccnos(){
+ try {
+
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(accnosfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + "accnos.report";
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+ ifstream in;
+ m->openInputFile(accnosfile2, in);
+ string name;
+
+ set<string> namesAccnos2;
+ 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);
+ }else { //you are in both so erase
+ namesAccnos.erase(name);
+ namesDups.insert(name);
+ }
+
+ m->gobble(in);
+ }
+ in.close();
+
+ out << "Names in both files : " + toString(namesDups.size()) << endl;
+ m->mothurOut("Names in both files : " + toString(namesDups.size())); m->mothurOutEndLine();
+
+ for (set<string>::iterator it = namesDups.begin(); it != namesDups.end(); it++) {
+ 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);
+ 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);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
+ }
+
+ out.close();
+
+ outputNames.push_back(outputFileName); outputTypes["accnosreport"].push_back(outputFileName);
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "readAccnos");
+ exit(1);
+ }
+}
+
//**********************************************************************************************************************