X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=removelineagecommand.cpp;h=cf26ea07385360e9b5180b68b901970f6fc4a732;hb=d4429ccc354708f3c9a13c809ba9b57c22908d2b;hp=893b2100cc60aeb26806a6b47620d3aca468f72d;hpb=348de0f8b17d84ede77081dcf67bd6ef43496677;p=mothur.git diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index 893b210..cf26ea0 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -12,21 +12,58 @@ #include "listvector.hpp" //********************************************************************************************************************** -vector RemoveLineageCommand::getValidParameters(){ +vector RemoveLineageCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport", "taxon", "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,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon); + 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); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getValidParameters"); + m->errorOut(e, "RemoveLineageCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string RemoveLineageCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The remove.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"; + helpString += "It outputs a file containing only the sequences from the taxonomy file that are not from the taxon you requested to be removed.\n"; + helpString += "The remove.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy unless you have a valid current taxonomy file.\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 taxon parameter allows you to select the taxons you would like to remove, and is required.\n"; + helpString += "You may enter your taxons with confidence scores, doing so will remove only those sequences that belong to the taxonomy and whose cofidence scores fall below the scores you give.\n"; + helpString += "If they belong to the taxonomy and have confidences above those you provide the sequence will not be removed.\n"; + helpString += "The remove.lineage command should be in the following format: remove.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"; + helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"; + helpString += "Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"; + helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\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, "RemoveLineageCommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -41,29 +78,6 @@ RemoveLineageCommand::RemoveLineageCommand(){ } } //********************************************************************************************************************** -vector RemoveLineageCommand::getRequiredParameters(){ - try { - string Array[] = {"taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveLineageCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(string option) { try { abort = false; calledHelp = false; @@ -72,9 +86,7 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -177,7 +189,11 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { taxfile = validParameter.validFile(parameters, "taxonomy", true); if (taxfile == "not open") { abort = true; } - else if (taxfile == "not found") { taxfile = ""; m->mothurOut("The taxonomy parameter is required for the get.lineage command."); m->mothurOutEndLine(); abort = true; } + else if (taxfile == "not found") { + taxfile = m->getTaxonomyFile(); + if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; } + } string usedDups = "true"; string temp = validParameter.validFile(parameters, "dups", false); @@ -210,29 +226,6 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { } //********************************************************************************************************************** -void RemoveLineageCommand::help(){ - try { - m->mothurOut("The remove.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"); - m->mothurOut("It outputs a file containing only the sequences from the taxonomy file that are not from the taxon you requested to be removed.\n"); - m->mothurOut("The remove.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy and taxon.\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 taxon parameter allows you to select the taxons you would like to remove.\n"); - m->mothurOut("You may enter your taxons with confidence scores, doing so will remove only those sequences that belong to the taxonomy and whose cofidence scores fall below the scores you give.\n"); - m->mothurOut("If they belong to the taxonomy and have confidences above those you provide the sequence will not be removed.\n"); - m->mothurOut("The remove.lineage command should be in the following format: remove.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"); - m->mothurOut("Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"); - m->mothurOut("Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"); - m->mothurOut("Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\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, "RemoveLineageCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveLineageCommand::execute(){ try { @@ -434,16 +427,8 @@ int RemoveLineageCommand::readName(){ in >> 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); - } + m->splitAtComma(secondCol, parsedNames); - //get name after last , - parsedNames.push_back(secondCol); - vector validSecond; validSecond.clear(); for (int i = 0; i < parsedNames.size(); i++) { if (names.count(parsedNames[i]) == 0) { @@ -556,7 +541,7 @@ int RemoveLineageCommand::readTax(){ bool wroteSomething = false; bool taxonsHasConfidence = false; - vector< map > searchTaxons; + vector< map > searchTaxons; string noConfidenceTaxons = taxons; int hasConPos = taxons.find_first_of('('); if (hasConPos != string::npos) { @@ -618,7 +603,7 @@ int RemoveLineageCommand::readTax(){ if (pos != string::npos) { //if yes, then are the confidences okay bool remove = false; - vector< map > usersTaxon = getTaxons(newtax); + vector< map > usersTaxon = getTaxons(newtax); //the usersTaxon is most likely longer than the searchTaxons, and searchTaxon[0] may relate to userTaxon[4] //we want to "line them up", so we will find the the index where the searchstring starts @@ -686,10 +671,10 @@ int RemoveLineageCommand::readTax(){ } } /**************************************************************************************************/ -vector< map > RemoveLineageCommand::getTaxons(string tax) { +vector< map > RemoveLineageCommand::getTaxons(string tax) { try { - vector< map > t; + vector< map > t; string taxon = ""; int taxLength = tax.length(); for(int i=0;i > RemoveLineageCommand::getTaxons(string tax) { newtaxon = taxon; confidence = "0"; } - int con = 0; + float con = 0; convert(confidence, con); - map temp; + map temp; temp[newtaxon] = con; t.push_back(temp);