X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=classifytreecommand.cpp;h=79a82454d14304d997a2a46efbc62ffbeac63f60;hb=70491a12902e89b85cfa6b44a7b7fbe066ee2ac1;hp=69da8e0d74e58d54d7ae59c78c7ad7f91e9f4b29;hpb=90708fe9701e3827e477c82fb3652539c3bf2a0d;p=mothur.git diff --git a/classifytreecommand.cpp b/classifytreecommand.cpp index 69da8e0..79a8245 100644 --- a/classifytreecommand.cpp +++ b/classifytreecommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector ClassifyTreeCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "", "", "none",false,true); parameters.push_back(ptree); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "", "", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "", "", "none","tree-summary",false,true,true); parameters.push_back(ptree); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "", "", "none","",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "","",false,true); parameters.push_back(pcutoff); + 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); } @@ -52,25 +52,20 @@ string ClassifyTreeCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClassifyTreeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClassifyTreeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //is this a type this command creates - it = outputTypes.find(type); - if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } - else { - if (type == "tree") { outputFileName = "taxonomy.tre"; } - else if (type == "summary") { outputFileName = "taxonomy.summary"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return outputFileName; - } - catch(exception& e) { - m->errorOut(e, "ClassifyTreeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],taxonomy.summary"; } //makes file like: amazon.0.03.fasta + else if (type == "tree") { pattern = "[filename],taxonomy.tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClassifyTreeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClassifyTreeCommand::ClassifyTreeCommand(){ @@ -286,7 +281,9 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(treefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(treefile)); + string outputFileName = getOutputFileName("summary", variables); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -300,12 +297,13 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string treeOutputDir = outputDir; if (outputDir == "") { treeOutputDir += m->hasPath(treefile); } - string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); + variables["[filename]"] = treeOutputDir + m->getRootName(m->getSimpleName(treefile)); + string outputTreeFileName = getOutputFileName("tree", variables); //create a map from tree node index to names of descendants, save time later map > > nodeToDescendants; //node# -> (groupName -> groupMembers) for (int i = 0; i < T->getNumNodes(); i++) { - if (m->control_pressed) { return 0; } + if (m->control_pressed) { return 0; } nodeToDescendants[i] = getDescendantList(T, i, nodeToDescendants); } @@ -329,7 +327,7 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ tax = getTaxonomy(nodeToDescendants[i][group], size); out << (i+1) << '\t' << size << '\t' << tax << endl; } - + T->tree[i].setLabel((i+1)); } out.close(); @@ -358,7 +356,6 @@ string ClassifyTreeCommand::getTaxonomy(set names, int& size) { for (set::iterator it = names.begin(); it != names.end(); it++) { - //if namesfile include the names if (namefile != "") { @@ -379,7 +376,7 @@ string ClassifyTreeCommand::getTaxonomy(set names, int& size) { }else{ //add seq to tree int num = nameCount[(*it)]; // we know its there since we found it in nameMap - for (int i = 0; i < num; i++) { phylo->addSeqToTree((*it)+toString(i), it2->second); } + for (int i = 0; i < num; i++) { phylo->addSeqToTree((*it)+toString(i), itTax->second); } size += num; } }