X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=phylotypecommand.cpp;h=fbc7c6003989044eba397ba7d8d6d58fa37c768a;hb=67ea6ccd74dbd64828d31b952808255f206364ff;hp=00f960bbbab8d07ecbee08dc01b78907c60c0185;hpb=0ca63a8165baa0afa459e644ebe140ba496d5ba0;p=mothur.git diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index 00f960b..fbc7c60 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -16,12 +16,12 @@ //********************************************************************************************************************** vector PhylotypeCommand::setParameters(){ try { - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcutoff("cutoff", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","list-rabund-sabund",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcutoff("cutoff", "Number", "", "-1", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + 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); } @@ -53,7 +53,23 @@ string PhylotypeCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PhylotypeCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "list") { pattern = "[filename],[tag],list"; } + else if (type == "rabund") { pattern = "[filename],[tag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[tag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "getOutputPattern"); + exit(1); + } +} //********************************************************************************************************************** PhylotypeCommand::PhylotypeCommand(){ try { @@ -128,11 +144,11 @@ PhylotypeCommand::PhylotypeCommand(string option) { m->mothurOut("No valid current files. taxonomy is a required parameter."); m->mothurOutEndLine(); abort = true; } - }else if (taxonomyFileName == "not open") { abort = true; } + }else if (taxonomyFileName == "not open") { taxonomyFileName = ""; abort = true; } else { m->setTaxonomyFile(taxonomyFileName); } 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 { readNamesFile(); m->setNameFile(namefile); } @@ -153,6 +169,11 @@ PhylotypeCommand::PhylotypeCommand(string option) { else { allLines = 1; } } + if (namefile == "") { + vector files; files.push_back(taxonomyFileName); + parser.getNameFile(files); + } + } } catch(exception& e) { @@ -191,15 +212,17 @@ int PhylotypeCommand::execute(){ if (m->control_pressed) { delete tree; return 0; } string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName)); - - ofstream outList; - string outputListFile = fileroot + "tx.list"; + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = "tx"; + ofstream outList; + string outputListFile = getOutputFileName("list",variables); m->openOutputFile(outputListFile, outList); ofstream outSabund; - string outputSabundFile = fileroot + "tx.sabund"; + string outputSabundFile = getOutputFileName("sabund",variables); m->openOutputFile(outputSabundFile, outSabund); ofstream outRabund; - string outputRabundFile = fileroot + "tx.rabund"; + string outputRabundFile = getOutputFileName("rabund",variables); m->openOutputFile(outputRabundFile, outRabund); outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile); @@ -227,6 +250,7 @@ int PhylotypeCommand::execute(){ ListVector list; list.setLabel(level); + //go through nodes and build listvector for (itCurrent = currentNodes.begin(); itCurrent != currentNodes.end(); itCurrent++) { @@ -239,18 +263,23 @@ int PhylotypeCommand::execute(){ //make the names compatable with listvector string name = ""; for (int i = 0; i < names.size(); i++) { - if (namefile != "") { - map::iterator itNames = namemap.find(names[i]); //make sure this name is in namefile - - if (itNames != namemap.end()) { name += namemap[names[i]] + ","; } //you found it in namefile - else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1); } - - }else{ name += names[i] + ","; } + + if (names[i] != "unknown") { + if (namefile != "") { + map::iterator itNames = namemap.find(names[i]); //make sure this name is in namefile + + if (itNames != namemap.end()) { name += namemap[names[i]] + ","; } //you found it in namefile + else { m->mothurOut("[ERROR]: " + names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } + + }else{ name += names[i] + ","; } + } } + + if (m->control_pressed) { break; } + name = name.substr(0, name.length()-1); //rip off extra ',' - //add bin to list vector - list.push_back(name); + if (name != "") { list.push_back(name); } //caused by unknown } //print listvector