1 // 2 // C++ Interface: phylonode 3 // 4 // Description: 5 // 6 // 7 // Author: BUI Quang Minh, Steffen Klaere, Arndt von Haeseler <minh.bui@univie.ac.at>, (C) 2008 8 // 9 // Copyright: See COPYING file that comes with this distribution 10 // 11 // 12 #ifndef PHYLONODE_H 13 #define PHYLONODE_H 14 15 #include "node.h" 16 17 typedef unsigned short UBYTE; 18 19 /** 20 * direction of a Neighbor from the root, for rooted tree only 21 */ 22 enum RootDirection {UNDEFINED_DIRECTION, TOWARD_ROOT, AWAYFROM_ROOT}; 23 24 /** 25 A neighbor in a phylogenetic tree 26 27 @author BUI Quang Minh, Steffen Klaere, Arndt von Haeseler <minh.bui@univie.ac.at> 28 */ 29 class PhyloNeighbor : public Neighbor { 30 friend class PhyloNode; 31 friend class PhyloTree; 32 friend class IQTree; 33 friend class PhyloSuperTree; 34 friend class PhyloTreeMixlen; 35 friend class MemSlotVector; 36 friend class ParsTree; 37 38 public: 39 friend class TinaTree; 40 friend class PhyloSuperTreePlen; 41 42 /** 43 construct class with a node and length 44 @param anode the other end of the branch 45 @param alength length of branch 46 */ PhyloNeighbor(Node * anode,double alength)47 PhyloNeighbor(Node *anode, double alength) : Neighbor(anode, alength) { 48 partial_lh = NULL; 49 scale_num = NULL; 50 partial_lh_computed = 0; 51 lh_scale_factor = 0.0; 52 partial_pars = NULL; 53 direction = UNDEFINED_DIRECTION; 54 size = 0; 55 } 56 57 /** 58 construct class with a node and length 59 @param anode the other end of the branch 60 @param alength length of branch 61 @param aid branch ID 62 */ PhyloNeighbor(Node * anode,double alength,int aid)63 PhyloNeighbor(Node *anode, double alength, int aid) : Neighbor(anode, alength, aid) { 64 partial_lh = NULL; 65 scale_num = NULL; 66 partial_lh_computed = 0; 67 lh_scale_factor = 0.0; 68 partial_pars = NULL; 69 direction = UNDEFINED_DIRECTION; 70 size = 0; 71 } 72 73 /** 74 construct class with another Neighbor 75 @param nei another Neighbor 76 */ PhyloNeighbor(PhyloNeighbor * nei)77 PhyloNeighbor(PhyloNeighbor *nei) : Neighbor(nei) { 78 partial_lh = NULL; 79 scale_num = NULL; 80 partial_lh_computed = 0; 81 lh_scale_factor = 0.0; 82 partial_pars = NULL; 83 direction = nei->direction; 84 size = nei->size; 85 } 86 87 88 /** 89 allocate a new Neighbor by just copying from this one 90 @return pointer to newly created Neighbor 91 */ newNeighbor()92 virtual Neighbor* newNeighbor() { 93 return (new PhyloNeighbor(this)); 94 } 95 96 /** 97 tell that the partial likelihood vector is not computed 98 */ clearPartialLh()99 inline void clearPartialLh() { 100 partial_lh_computed = 0; 101 } 102 103 /** 104 * tell that the partial likelihood vector is computed 105 */ unclearPartialLh()106 inline void unclearPartialLh() { 107 partial_lh_computed = 1; 108 } 109 110 /** 111 clear all partial likelihood recursively in forward direction 112 @param dad dad of this neighbor 113 */ 114 void clearForwardPartialLh(Node *dad); 115 116 /** 117 DEPRECATED, moved to PhyloTree 118 if partial_lh is NULL, reorient partial_lh (LM_PER_NODE technique) 119 @param dad dad of this neighbor 120 */ 121 // void reorientPartialLh(Node *dad); 122 123 /** 124 * For Upper Bounds analysis: get partial likelihood and lh scale factor 125 */ get_partial_lh()126 double* get_partial_lh(){ 127 return partial_lh; 128 } 129 get_lh_scale_factor()130 double get_lh_scale_factor(){ 131 return lh_scale_factor; 132 } 133 get_partial_lh_computed()134 int get_partial_lh_computed(){ 135 return partial_lh_computed; 136 } 137 138 /** 139 * true if this Neighbor is directed towards the root 140 */ isTowardsRoot()141 bool isTowardsRoot() { 142 ASSERT(direction != UNDEFINED_DIRECTION); 143 return (direction == TOWARD_ROOT); 144 } 145 getSize()146 int getSize() { 147 return size; 148 } 149 150 private: 151 152 /** 153 true if the partial likelihood was computed 154 */ 155 int partial_lh_computed; 156 157 /** 158 vector containing the partial likelihoods 159 */ 160 double *partial_lh; 161 162 /** 163 likelihood scaling factor 164 */ 165 double lh_scale_factor; 166 167 /** 168 vector containing number of scaling events per pattern // NEW! 169 */ 170 UBYTE *scale_num; 171 172 /** 173 vector containing the partial parsimony scores 174 */ 175 UINT *partial_pars; 176 177 /** 178 * direction of the Neighbor in a rooted tree 179 */ 180 RootDirection direction; 181 182 /** size of subtree below this neighbor in terms of number of taxa */ 183 int size; 184 185 }; 186 187 /** 188 A node in a phylogenetic tree 189 190 @author BUI Quang Minh, Steffen Klaere, Arndt von Haeseler <minh.bui@univie.ac.at> 191 */ 192 class PhyloNode : public Node { 193 friend class PhyloTree; 194 195 public: 196 /** 197 constructor 198 */ 199 PhyloNode(); 200 201 /** 202 constructor 203 @param aid id of this node 204 */ 205 PhyloNode(int aid); 206 207 /** 208 constructor 209 @param aid id of this node 210 @param aname name of this node 211 */ 212 PhyloNode(int aid, int aname); 213 214 /** 215 constructor 216 @param aid id of this node 217 @param aname name of this node 218 */ 219 PhyloNode(int aid, const char *aname); 220 221 /** 222 initialization 223 */ 224 void init(); 225 226 /** 227 add a neighbor 228 @param node the neighbor node 229 @param length branch length 230 @param id branch ID 231 */ 232 virtual void addNeighbor(Node *node, double length, int id = -1); 233 234 235 236 /** 237 tell that all partial likelihood vectors below this node are not computed 238 */ 239 void clearAllPartialLh(bool make_null, PhyloNode *dad); 240 241 /** 242 tell that all partial likelihood vectors (in reverse direction) below this node are not computed 243 */ 244 void clearReversePartialLh(PhyloNode *dad); 245 246 void computeReversePartialLh(PhyloNode *dad); 247 248 /** 249 compute the size (#taxa) of the subtree rooted at this node 250 using buffered 'size' attribute if computed beforehand 251 @param dad dad of this node 252 */ 253 int computeSize(Node *dad); 254 255 }; 256 257 258 /** 259 Node vector 260 */ 261 typedef vector<PhyloNode*> PhyloNodeVector; 262 263 264 #endif 265