]> git.donarmstrong.com Git - mothur.git/blob - treenode.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[mothur.git] / treenode.cpp
1 /*
2  *  treenode.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/23/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "treenode.h"
11
12
13 /****************************************************************/      
14 Node::Node() {
15         //initialize node
16         name = "";
17         branchLength = -1;
18         parent = -1;
19         lchild = -1;
20         rchild = -1;
21         length2leaf = 0.0;
22         
23 }
24 /****************************************************************/
25 void Node::setName(string Name) {  name = Name; }
26 /****************************************************************/
27 void Node::setGroup(string groups)  { group =groups; }
28 /****************************************************************/
29 void Node::setBranchLength(float l) { branchLength = l; }
30 /****************************************************************/
31 void Node::setLengthToLeaves(float l) { length2leaf = l; }
32 /****************************************************************/
33 void Node::setParent(int p)  { parent = p; }
34 /****************************************************************/
35 void Node::setIndex(int i)  { vectorIndex = i; }
36 /****************************************************************/
37 void Node::setChildren(int lc, int rc) { lchild = lc; rchild = rc; }    //leftchild, rightchild
38 /****************************************************************/
39 string Node::getName() { return name; }
40 /****************************************************************/
41 string Node::getGroup() { return group; }
42 /****************************************************************/
43 float Node::getBranchLength() { return branchLength; }
44 /****************************************************************/
45 float Node::getLengthToLeaves() { return length2leaf; }
46 /****************************************************************/
47 int Node::getParent() { return parent; }
48 /****************************************************************/
49 int Node::getLChild() { return lchild; }
50 /****************************************************************/
51 int Node::getRChild() { return rchild; }
52 /****************************************************************/
53 int Node::getIndex() { return vectorIndex; }
54 /****************************************************************/
55 //to be used by printTree in the Tree class to print the leaf info                      
56 void Node::printNode() {
57         try{
58                 cout << parent << ' ' << lchild << ' ' << rchild << ' ' << group;
59                 //there is a branch length
60                 if (branchLength != -1) { 
61                         cout << ' ' << setprecision(4) << branchLength; 
62                 }
63                 cout << " |";
64                 map<string, int>::iterator it;
65                 for(it=pGroups.begin();it!=pGroups.end();it++){
66                         cout << ' ' << it->first << ':' << it->second;
67                 }
68                 cout << " |";
69                 for(it=pcount.begin();it!=pcount.end();it++){
70                         cout << ' ' << it->first << ':' << it->second;
71                 }
72                 cout << endl; 
73                 
74                 
75         }
76         catch(exception& e) {
77                 cout << "Standard Error: " << e.what() << " has occurred in the Node class Function printNode. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
78                 exit(1);
79         }
80         catch(...) {
81                 cout << "An unknown error has occurred in the Node class function printNode. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82                 exit(1);
83         }               
84 }
85 /****************************************************************/