]> git.donarmstrong.com Git - mothur.git/blobdiff - tree.cpp
added otu.association command. added calcSpearman, calcKendall and calcPearson functi...
[mothur.git] / tree.cpp
index cd3d7a6789c9179066899ac62f0db115f14e295b..b99373510ba4d6e9d3e0d323021178227ede92e7 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -51,8 +51,8 @@ Tree::Tree(TreeMap* t) : tmap(t) {
                tree.resize(numNodes);
                        
                //initialize groupNodeInfo
-               for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                       groupNodeInfo[tmap->namesOfGroups[i]].resize(0);
+               for (int i = 0; i < (tmap->getNamesOfGroups()).size(); i++) {
+                       groupNodeInfo[(tmap->getNamesOfGroups())[i]].resize(0);
                }
                
                //initialize tree with correct number of nodes, name and group info.
@@ -632,8 +632,8 @@ void Tree::randomLabels(vector<string> g) {
        try {
        
                //initialize groupNodeInfo
-               for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                       groupNodeInfo[tmap->namesOfGroups[i]].resize(0);
+               for (int i = 0; i < (tmap->getNamesOfGroups()).size(); i++) {
+                       groupNodeInfo[(tmap->getNamesOfGroups())[i]].resize(0);
                }
                
                for(int i = 0; i < numLeaves; i++){
@@ -872,6 +872,11 @@ try {
                                if (tree[node].getBranchLength() != -1) {
                                        out << ":" << tree[node].getBranchLength();
                                }
+                       }else if (mode == "deunique") {
+                               //if there is a branch length then print it
+                               if (tree[node].getBranchLength() != -1) {
+                                       out << ":" << tree[node].getBranchLength();
+                               }
                        }
                }else { //you are a leaf
                        string leafGroup = tmap->getGroup(tree[node].getName());
@@ -897,6 +902,53 @@ try {
                                if (tree[node].getBranchLength() != -1) {
                                        out << ":" << tree[node].getBranchLength();
                                }
+                       }else if (mode == "deunique") {
+                               map<string, string>::iterator itNames = m->names.find(tree[node].getName());
+                               
+                               string outputString = "";
+                               if (itNames != m->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;
                        }
                }