X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=classifyotucommand.cpp;h=7b1a04f3658bcb0a3e919fefe34a30dedcfaa882;hb=ba2b95b22ab8947d5583ca2c2da74557870b6861;hp=a70be07e955180d17208b47f50d92f82ba2fa438;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index a70be07..7b1a04f 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -54,7 +54,7 @@ string ClassifyOtuCommand::getHelpString(){ helpString += "The probs parameter shuts off the outputting of the consensus confidence results. The default is true, meaning you want the confidence to be shown.\n"; helpString += "The classify.otu command should be in the following format: classify.otu(taxonomy=yourTaxonomyFile, list=yourListFile, name=yourNamesFile, label=yourLabels).\n"; helpString += "Example classify.otu(taxonomy=abrecovery.silva.full.taxonomy, list=abrecovery.fn.list, label=0.10).\n"; - helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n"; return helpString; } catch(exception& e) { @@ -87,7 +87,8 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { //allow user to run help if (option == "help") { help(); abort = true; calledHelp = true; - } else { + }else if(option == "citation") { citation(); abort = true; calledHelp = true;} + else { vector myArray = setParameters(); OptionParser parser(option); @@ -165,6 +166,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { else { m->mothurOut("You have no current listfile and the list parameter is required."); m->mothurOutEndLine(); abort = true; } } else if (listfile == "not open") { abort = true; } + else { m->setListFile(listfile); } taxfile = validParameter.validFile(parameters, "taxonomy", true); if (taxfile == "not found") { //if there is a current list file, use it @@ -173,6 +175,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; } } else if (taxfile == "not open") { abort = true; } + else { m->setTaxonomyFile(taxfile); } refTaxonomy = validParameter.validFile(parameters, "reftaxonomy", true); if (refTaxonomy == "not found") { refTaxonomy = ""; m->mothurOut("reftaxonomy is not required, but if given will keep the rankIDs in the summary file static."); m->mothurOutEndLine(); } @@ -181,10 +184,12 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { 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); } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -239,7 +244,7 @@ int ClassifyOtuCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { outputTypes.clear(); delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -247,7 +252,7 @@ int ClassifyOtuCommand::execute(){ m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine(); process(list); - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -262,7 +267,7 @@ int ClassifyOtuCommand::execute(){ process(list); - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -298,12 +303,12 @@ int ClassifyOtuCommand::execute(){ process(list); delete list; - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; delete list; return 0; } } delete input; - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -446,7 +451,7 @@ vector ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* th phylo->assignHeirarchyIDs(0); TaxNode currentNode = phylo->get(0); - + int myLevel = 0; //at each level while (currentNode.children.size() != 0) { //you still have more to explore @@ -475,6 +480,7 @@ vector ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* th }else{ conTax += bestChild.name + ";"; } + myLevel++; }else{ //if no, quit break; } @@ -483,7 +489,12 @@ vector ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* th currentNode = bestChild; } - + if (myLevel != phylo->getMaxLevel()) { + while (myLevel != phylo->getMaxLevel()) { + conTax += "unclassified;"; + myLevel++; + } + } if (conTax == "") { conTax = "no_consensus;"; } delete phylo; @@ -565,6 +576,35 @@ int ClassifyOtuCommand::process(ListVector* processList) { exit(1); } } +/**************************************************************************************************/ +string ClassifyOtuCommand::addUnclassifieds(string tax, int maxlevel) { + try{ + string newTax, taxon; + int level = 0; + + //keep what you have counting the levels + while (tax.find_first_of(';') != -1) { + //get taxon + taxon = tax.substr(0,tax.find_first_of(';'))+';'; + tax = tax.substr(tax.find_first_of(';')+1, tax.length()); + newTax += taxon; + level++; + } + + //add "unclassified" until you reach maxLevel + while (level < maxlevel) { + newTax += "unclassified;"; + level++; + } + + return newTax; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "addUnclassifieds"); + exit(1); + } +} + /**************************************************************************************************/ void ClassifyOtuCommand::removeConfidences(string& tax) { try {