]> git.donarmstrong.com Git - mothur.git/blob - treenode.cpp
working on chimeras
[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         label = -1;
23         
24 }
25 /****************************************************************/
26 void Node::setName(string Name) {  name = Name; }
27 /****************************************************************/
28 void Node::setGroup(vector<string> groups)  { group =groups; }
29 /****************************************************************/
30 void Node::setBranchLength(float l) { branchLength = l; }
31 /****************************************************************/
32 void Node::setLabel(float l) { label = l; }
33 /****************************************************************/
34 void Node::setLengthToLeaves(float l) { length2leaf = l; }
35 /****************************************************************/
36 void Node::setParent(int p)  { parent = p; }
37 /****************************************************************/
38 void Node::setIndex(int i)  { vectorIndex = i; }
39 /****************************************************************/
40 void Node::setChildren(int lc, int rc) { lchild = lc; rchild = rc; }    //leftchild, rightchild
41 /****************************************************************/
42 string Node::getName() { return name; }
43 /****************************************************************/
44 vector<string> Node::getGroup() { return group; }
45 /****************************************************************/
46 float Node::getBranchLength() { return branchLength; }
47 /****************************************************************/
48 float Node::getLabel() { return label; }
49 /****************************************************************/
50 float Node::getLengthToLeaves() { return length2leaf; }
51 /****************************************************************/
52 int Node::getParent() { return parent; }
53 /****************************************************************/
54 int Node::getLChild() { return lchild; }
55 /****************************************************************/
56 int Node::getRChild() { return rchild; }
57 /****************************************************************/
58 int Node::getIndex() { return vectorIndex; }
59 /****************************************************************/
60 //to be used by printTree in the Tree class to print the leaf info                      
61 void Node::printNode() {
62         try{
63                 mothurOut(toString(parent) + " " + toString(lchild) + " " + toString(rchild) + " ");
64                 
65                 for (int i = 0; i < group.size(); i++) {  mothurOut( group[i] + " "); }
66                 
67                 //there is a branch length
68                 if (branchLength != -1) { 
69                         mothurOut(" " + toString(branchLength)); 
70                 }
71                 mothurOut(" |");
72                 
73                 map<string, int>::iterator it;
74                 for(it=pGroups.begin();it!=pGroups.end();it++){
75                         mothurOut(" " + it->first + ":" + toString(it->second));
76                 }
77                 mothurOut(" |");
78                 for(it=pcount.begin();it!=pcount.end();it++){
79                         mothurOut(" " + it->first + ":" + toString(it->second));
80                 }
81                 mothurOutEndLine();
82                 
83                 
84         }
85         catch(exception& e) {
86                 errorOut(e, "Node", "printNode");
87                 exit(1);
88         }
89 }
90 /****************************************************************/