1 //
2 // C++ Implementation: 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 #include "phylonode.h"
13 
14 
clearForwardPartialLh(Node * dad)15 void PhyloNeighbor::clearForwardPartialLh(Node *dad) {
16 	clearPartialLh();
17 	for (NeighborVec::iterator it = node->neighbors.begin(); it != node->neighbors.end(); it ++)
18 		if ((*it)->node != dad)
19 			((PhyloNeighbor*)*it)->clearForwardPartialLh(node);
20 }
21 
clearReversePartialLh(PhyloNode * dad)22 void PhyloNode::clearReversePartialLh(PhyloNode *dad) {
23 //	PhyloNeighbor *node_nei = (PhyloNeighbor*)findNeighbor(dad);
24 //	assert(node_nei);
25 //	node_nei->partial_lh_computed = 0;
26 	for (NeighborVec::iterator it = neighbors.begin(); it != neighbors.end(); it ++)
27 		if ((*it)->node != dad) {
28             PhyloNeighbor *nei = (PhyloNeighbor*)(*it)->node->findNeighbor(this);
29 			nei->partial_lh_computed = 0;
30             nei->size = 0;
31 			((PhyloNode*)(*it)->node)->clearReversePartialLh(this);
32 		}
33 }
34 
clearAllPartialLh(bool make_null,PhyloNode * dad)35 void PhyloNode::clearAllPartialLh(bool make_null, PhyloNode *dad) {
36 	PhyloNeighbor *node_nei = (PhyloNeighbor*)findNeighbor(dad);
37 	node_nei->partial_lh_computed = 0;
38 	if (make_null) node_nei->partial_lh = NULL;
39 
40 
41     if (Params::getInstance().lh_mem_save == LM_MEM_SAVE)
42         node_nei->size = 0;
43 
44 	node_nei = (PhyloNeighbor*)dad->findNeighbor(this);
45 	node_nei->partial_lh_computed = 0;
46 	if (make_null) node_nei->partial_lh = NULL;
47 
48     if (Params::getInstance().lh_mem_save == LM_MEM_SAVE)
49         node_nei->size = 0;
50 
51 	for (NeighborVec::iterator it = neighbors.begin(); it != neighbors.end(); it ++)
52 		if ((*it)->node != dad)
53 			((PhyloNode*)(*it)->node)->clearAllPartialLh(make_null, this);
54 }
55 
56 
PhyloNode()57 PhyloNode::PhyloNode()
58  : Node()
59 {
60 	init();
61 }
62 
63 
PhyloNode(int aid)64 PhyloNode::PhyloNode(int aid) : Node(aid)
65 {
66 	init();
67 }
68 
PhyloNode(int aid,int aname)69 PhyloNode::PhyloNode(int aid, int aname) : Node (aid, aname) {
70 	init();
71 }
72 
73 
PhyloNode(int aid,const char * aname)74 PhyloNode::PhyloNode(int aid, const char *aname) : Node(aid, aname) {
75 	init();
76 }
77 
init()78 void PhyloNode::init() {
79 	//partial_lh = NULL;
80 }
81 
82 
addNeighbor(Node * node,double length,int id)83 void PhyloNode::addNeighbor(Node *node, double length, int id) {
84 	neighbors.push_back(new PhyloNeighbor(node, length, id));
85 }
86 
87 
computeSize(Node * dad)88 int PhyloNode::computeSize(Node *dad) {
89     PhyloNeighbor *nei = (PhyloNeighbor*)dad->findNeighbor(this);
90     if (nei->size > 0)
91         return nei->size;
92 
93     if (isLeaf()) {
94         nei->size = 1;
95         return nei->size;
96     }
97     nei->size = 0;
98     FOR_NEIGHBOR_IT(this, dad, it) {
99         nei->size += ((PhyloNode*)(*it)->node)->computeSize(this);
100     }
101     return nei->size;
102 }
103 
104