From 9099173ea17b13be96563c7579ecc8dc2ef65d20 Mon Sep 17 00:00:00 2001 From: pschloss Date: Tue, 24 Feb 2009 13:04:56 +0000 Subject: [PATCH] print tree debugger --- Mothur.xcodeproj/project.pbxproj | 3 +- parsimony.cpp | 5 +++ tree.cpp | 17 +++++++- tree.h | 72 ++++++++++++++++---------------- treenode.cpp | 17 ++++++-- treenode.h | 2 +- 6 files changed, 73 insertions(+), 43 deletions(-) diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index ac5bd2d..62d929a 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -712,7 +712,7 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; + GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( "_GLIBCXX_DEBUG=1", "_GLIBCXX_DEBUG_PEDANTIC=1", @@ -728,6 +728,7 @@ buildSettings = { DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 3; INSTALL_PATH = /usr/local/bin; PRODUCT_NAME = mothur; }; diff --git a/parsimony.cpp b/parsimony.cpp index 8c7e3e4..e76a7b0 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -38,8 +38,13 @@ EstOutput Parsimony::getValues(Tree* t) { else if(iSize > rcSize || iSize > lcSize){ score++; } + cout << i << ' ' << score << ": "; + t->tree[i].printNode(); } + string hold; + cin >> hold; + data[0] = score; return data; diff --git a/tree.cpp b/tree.cpp index d332f47..eea3af4 100644 --- a/tree.cpp +++ b/tree.cpp @@ -493,7 +493,7 @@ void Tree::printBranch(int node) { printBranch(tree[node].getRChild()); out << ")"; }else { //you are a leaf - tree[node].printNode(out); //prints out name and branch length + tree[node].printNode(); //prints out name and branch length } } @@ -508,6 +508,7 @@ void Tree::printBranch(int node) { } /*****************************************************************/ + void Tree::setGroups() { try { //if the user has not entered specific groups to analyze then do them all @@ -546,3 +547,17 @@ void Tree::setGroups() { } +/*****************************************************************/ + +void Tree::printTree() { + + for(int i=0;i mergeUserGroups(int); //returns a map with a groupname and the number of times that group was seen in the children - - //this function takes the leaf info and populates the non leaf nodes - void assembleTree(); - - vector tree; //the first n nodes are the leaves, where n is the number of sequences. - - private: - GlobalData* globaldata; - int numNodes, numLeaves; - ofstream out; - string filename; - - map::iterator it, it2; - map mergeGroups(int); //returns a map with a groupname and the number of times that group was seen in the children - - map Tree::mergeGcounts(int); - void randomTopology(); - void randomBlengths(); - void randomLabels(); - int findRoot(); //return index of root node - void printBranch(int); //recursively print out tree - void setGroups(); +public: + Tree(); //to generate a tree from a file + ~Tree() {}; + + + void getCopy(Tree*); //makes tree a copy of the one passed in. + void assembleRandomTree(); + void assembleRandomUnifracTree(); + void createNewickFile(); + int getIndex(string); + void setIndex(string, int); + int getNumNodes() { return numNodes; } + int getNumLeaves(){ return numLeaves; } + map mergeUserGroups(int); //returns a map with a groupname and the number of times that group was seen in the children + void printTree(); + + //this function takes the leaf info and populates the non leaf nodes + void assembleTree(); + + vector tree; //the first n nodes are the leaves, where n is the number of sequences. +private: + GlobalData* globaldata; + int numNodes, numLeaves; + ofstream out; + string filename; + + map::iterator it, it2; + map mergeGroups(int); //returns a map with a groupname and the number of times that group was seen in the children + + map Tree::mergeGcounts(int); + void randomTopology(); + void randomBlengths(); + void randomLabels(); + int findRoot(); //return index of root node + void printBranch(int); //recursively print out tree + void setGroups(); }; #endif diff --git a/treenode.cpp b/treenode.cpp index ae7d0e4..7fff2c1 100644 --- a/treenode.cpp +++ b/treenode.cpp @@ -48,14 +48,23 @@ int Node::getRChild() { return rchild; } int Node::getIndex() { return vectorIndex; } /****************************************************************/ //to be used by printTree in the Tree class to print the leaf info -void Node::printNode(ostream& out) { +void Node::printNode() { try{ - out << name; - + cout << parent << ' ' << lchild << ' ' << rchild << ' ' << group; //there is a branch length if (branchLength != -1) { - out << ":" << setprecision(4) << branchLength; + cout << ' ' << setprecision(4) << branchLength; + } + cout << " |"; + map::iterator it; + for(it=pGroups.begin();it!=pGroups.end();it++){ + cout << ' ' << it->first << ':' << it->second; + } + cout << " |"; + for(it=pcount.begin();it!=pcount.end();it++){ + cout << ' ' << it->first << ':' << it->second; } + cout << endl; } catch(exception& e) { diff --git a/treenode.h b/treenode.h index 7353248..a5c3916 100644 --- a/treenode.h +++ b/treenode.h @@ -36,7 +36,7 @@ class Node { int getLChild(); int getRChild(); int getIndex(); - void printNode(ostream&); //prints out the name and the branch length + void printNode(); //prints out the name and the branch length //pGroup is the parsimony group info. i.e. for a leaf node it would contain 1 enter pGroup["groupname"] = 1; -- 2.39.2