File: phylonode.cpp

package info (click to toggle)
iqtree 1.6.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,140 kB
  • sloc: cpp: 111,752; ansic: 53,619; python: 242; sh: 195; makefile: 52
file content (103 lines) | stat: -rw-r--r-- 2,532 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// C++ Implementation: phylonode
//
// Description: 
//
//
// Author: BUI Quang Minh, Steffen Klaere, Arndt von Haeseler <minh.bui@univie.ac.at>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "phylonode.h"


void PhyloNeighbor::clearForwardPartialLh(Node *dad) {
	clearPartialLh();
	for (NeighborVec::iterator it = node->neighbors.begin(); it != node->neighbors.end(); it ++)
		if ((*it)->node != dad)
			((PhyloNeighbor*)*it)->clearForwardPartialLh(node);
}

void PhyloNode::clearReversePartialLh(PhyloNode *dad) {
//	PhyloNeighbor *node_nei = (PhyloNeighbor*)findNeighbor(dad);
//	assert(node_nei);
//	node_nei->partial_lh_computed = 0;
	for (NeighborVec::iterator it = neighbors.begin(); it != neighbors.end(); it ++)
		if ((*it)->node != dad) {
            PhyloNeighbor *nei = (PhyloNeighbor*)(*it)->node->findNeighbor(this);
			nei->partial_lh_computed = 0;
            nei->size = 0;
			((PhyloNode*)(*it)->node)->clearReversePartialLh(this);
		}
}

void PhyloNode::clearAllPartialLh(bool make_null, PhyloNode *dad) {
	PhyloNeighbor *node_nei = (PhyloNeighbor*)findNeighbor(dad);
	node_nei->partial_lh_computed = 0;
	if (make_null) node_nei->partial_lh = NULL;


    if (Params::getInstance().lh_mem_save == LM_MEM_SAVE)
        node_nei->size = 0;

	node_nei = (PhyloNeighbor*)dad->findNeighbor(this);
	node_nei->partial_lh_computed = 0;
	if (make_null) node_nei->partial_lh = NULL;

    if (Params::getInstance().lh_mem_save == LM_MEM_SAVE)
        node_nei->size = 0;

	for (NeighborVec::iterator it = neighbors.begin(); it != neighbors.end(); it ++)
		if ((*it)->node != dad)
			((PhyloNode*)(*it)->node)->clearAllPartialLh(make_null, this);
}


PhyloNode::PhyloNode()
 : Node()
{
	init();
}


PhyloNode::PhyloNode(int aid) : Node(aid)
{
	init();
}

PhyloNode::PhyloNode(int aid, int aname) : Node (aid, aname) {
	init();
}


PhyloNode::PhyloNode(int aid, const char *aname) : Node(aid, aname) {
	init();
}

void PhyloNode::init() {
	//partial_lh = NULL;
}


void PhyloNode::addNeighbor(Node *node, double length, int id) {
	neighbors.push_back(new PhyloNeighbor(node, length, id));
}


int PhyloNode::computeSize(Node *dad) {
    PhyloNeighbor *nei = (PhyloNeighbor*)dad->findNeighbor(this);
    if (nei->size > 0)
        return nei->size;

    if (isLeaf()) {
        nei->size = 1;
        return nei->size;
    }
    nei->size = 0;
    FOR_NEIGHBOR_IT(this, dad, it) {
        nei->size += ((PhyloNode*)(*it)->node)->computeSize(this);
    }
    return nei->size;
}