+ if (tree[node].getLChild() != -1) {
+ out << "(";
+ printBranch(tree[node].getLChild(), out, names);
+ out << ",";
+ printBranch(tree[node].getRChild(), out, names);
+ out << ")";
+
+ //if there is a branch length then print it
+ if (tree[node].getBranchLength() != -1) {
+ out << ":" << tree[node].getBranchLength();
+ }
+
+ }else { //you are a leaf
+ map<string, string>::iterator itNames = names.find(tree[node].getName());
+
+ string outputString = "";
+ if (itNames != names.end()) {
+
+ vector<string> dupNames;
+ m->splitAtComma((itNames->second), dupNames);
+
+ if (dupNames.size() == 1) {
+ outputString += tree[node].getName();
+ if (tree[node].getBranchLength() != -1) {
+ outputString += ":" + toString(tree[node].getBranchLength());
+ }
+ }else {
+ outputString += "(";
+
+ for (int u = 0; u < dupNames.size()-1; u++) {
+ outputString += dupNames[u];
+
+ if (tree[node].getBranchLength() != -1) {
+ outputString += ":" + toString(0.0);
+ }
+ outputString += ",";
+ }
+
+ outputString += dupNames[dupNames.size()-1];
+ if (tree[node].getBranchLength() != -1) {
+ outputString += ":" + toString(0.0);
+ }
+
+ outputString += ")";
+ if (tree[node].getBranchLength() != -1) {
+ outputString += ":" + toString(tree[node].getBranchLength());
+ }
+ }
+ }else {
+ outputString = tree[node].getName();
+ //if there is a branch length then print it
+ if (tree[node].getBranchLength() != -1) {
+ outputString += ":" + toString(tree[node].getBranchLength());
+ }
+
+ m->mothurOut("[ERROR]: " + tree[node].getName() + " is not in your namefile, please correct."); m->mothurOutEndLine();
+ }
+
+ out << outputString;
+ }
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Tree", "printBranch");
+ exit(1);
+ }
+}
+/*****************************************************************/
+void Tree::printBranch(int node, ostream& out, string mode) {
+ try {
+
+ // you are not a leaf