X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getseqscommand.cpp;h=a4697ca3fded8c34ec5320630a588e243601373d;hb=f06fdb807822f8e06db003ed809c87250905cfc8;hp=6d4bff2c38cf495a843b9c57ff7eff802a7ee72f;hpb=e2c0017527ca0cc9baff39ab41d5c61a9507100c;p=mothur.git diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 6d4bff2..a4697ca 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -12,21 +12,54 @@ #include "listvector.hpp" //********************************************************************************************************************** -vector GetSeqsCommand::getValidParameters(){ +vector GetSeqsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "qfile","alignreport", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"}; - vector 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 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; calledHelp = true; + abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -43,40 +76,16 @@ GetSeqsCommand::GetSeqsCommand(){ } } //********************************************************************************************************************** -vector GetSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"accnos"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetSeqsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(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", "alignreport", "qfile", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -185,7 +194,14 @@ GetSeqsCommand::GetSeqsCommand(string option) { //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; + } + } if (accnosfile2 == "not found") { accnosfile2 = ""; } @@ -217,14 +233,16 @@ GetSeqsCommand::GetSeqsCommand(string option) { if (qualfile == "not open") { abort = true; } else if (qualfile == "not found") { 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 = "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; } - } } @@ -235,24 +253,6 @@ GetSeqsCommand::GetSeqsCommand(string option) { } //********************************************************************************************************************** -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 { @@ -539,15 +539,7 @@ int GetSeqsCommand::readName(){ if (dups) { hold = secondCol; } vector 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 validSecond; for (int i = 0; i < parsedNames.size(); i++) { @@ -838,7 +830,15 @@ int GetSeqsCommand::compareAccnos(){ 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);