X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=classifyotucommand.cpp;h=c8896375b016ef6c45462351a18e8e520bfe75c2;hb=2bb9267aa4b4ecdf8488b06605cc9f3f36fa4332;hp=5ac7e2c4bd618dac3ce498a0a883ca6722980311;hpb=1d898dc6edaf9e9f287fab53bf1f21fb29757a17;p=mothur.git diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index 5ac7e2c..c889637 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -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,18 +175,21 @@ 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(); } else if (refTaxonomy == "not open") { abort = true; } namefile = validParameter.validFile(parameters, "name", true); - if (namefile == "not open") { abort = true; } + if (namefile == "not open") { namefile = ""; 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... @@ -201,7 +206,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { if ((basis != "otu") && (basis != "sequence")) { m->mothurOut("Invalid option for basis. basis options are otu and sequence, using otu."); m->mothurOutEndLine(); } string temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "51"; } - convert(temp, cutoff); + m->mothurConvert(temp, cutoff); temp = validParameter.validFile(parameters, "probs", false); if (temp == "not found"){ temp = "true"; } probs = m->isTrue(temp); @@ -209,6 +214,11 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { if ((cutoff < 51) || (cutoff > 100)) { m->mothurOut("cutoff must be above 50, and no greater than 100."); m->mothurOutEndLine(); abort = true; } + if (namefile == ""){ + vector files; files.push_back(taxfile); + parser.getNameFile(files); + } + } } catch(exception& e) { @@ -239,7 +249,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 +257,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 +272,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 +308,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(); @@ -363,7 +373,7 @@ int ClassifyOtuCommand::readTaxonomyFile() { m->gobble(in); //are there confidence scores, if so remove them - if (tax.find_first_of('(') != -1) { removeConfidences(tax); } + if (tax.find_first_of('(') != -1) { m->removeConfidences(tax); } taxMap[name] = tax; @@ -446,7 +456,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 +485,7 @@ vector ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* th }else{ conTax += bestChild.name + ";"; } + myLevel++; }else{ //if no, quit break; } @@ -483,7 +494,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; @@ -539,7 +555,7 @@ int ClassifyOtuCommand::process(ListVector* processList) { out << (i+1) << '\t' << size << '\t' << conTax << endl; string noConfidenceConTax = conTax; - removeConfidences(noConfidenceConTax); + m->removeConfidences(noConfidenceConTax); //add this bins taxonomy to summary if (basis == "sequence") { @@ -566,31 +582,30 @@ int ClassifyOtuCommand::process(ListVector* processList) { } } /**************************************************************************************************/ -void ClassifyOtuCommand::removeConfidences(string& tax) { - try { - - string taxon; - string newTax = ""; +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(';')); - - int pos = taxon.find_first_of('('); - if (pos != -1) { - taxon = taxon.substr(0, pos); //rip off confidence - } - - 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++; } - tax = newTax; + return newTax; } catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "removeConfidences"); + m->errorOut(e, "ClassifyOtuCommand", "addUnclassifieds"); exit(1); } }