41 #include "../NodeTemplate.h" 43 #include "../TreeTemplate.h" 44 #include "../TreeTemplateTools.h" 62 vector<size_t> bestPair(2);
63 double distMin = -std::log(0.);
64 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
67 map<size_t, Node*>::iterator j = i;
69 for ( ; j != currentNodes_.end(); j++)
72 double dist = matrix_(
id, jd);
82 if (distMin == -std::log(0.))
84 throw Exception(
"Unexpected error: no minimum found in the distance matrix.");
93 double dist = matrix_(pair[0], pair[1]) / 2.;
109 w1 =
static_cast<double>(
dynamic_cast<NodeTemplate<PGMAInfos>*
>(currentNodes_[pair[0]])->getInfos().numberOfLeaves);
110 w2 =
static_cast<double>(
dynamic_cast<NodeTemplate<PGMAInfos>*
>(currentNodes_[pair[1]])->getInfos().numberOfLeaves);
112 return (w1 * matrix_(pair[0], pos) + w2 * matrix_(pair[1], pos)) / (w1 + w2);
118 map<size_t, Node*>::iterator it = currentNodes_.begin();
119 size_t i1 = it->first;
120 Node* n1 = it->second;
122 size_t i2 = it->first;
123 Node* n2 = it->second;
124 double d = matrix_(i1, i2) / 2;
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.
virtual void addSon(size_t pos, Node *node)
virtual void setInfos(const NodeInfos &infos)
Set the information to be associated to this node.
TreeTemplate< Node > * getTree() const
Get the computed tree, if there is one.
The phylogenetic tree class.
virtual double getDistanceToFather() const
Get the distance to the father node is there is one, otherwise throw a NodeException.
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
double computeDistancesFromPair(const std::vector< size_t > &pair, const std::vector< double > &branchLengths, size_t pos)
Actualizes the distance matrix according to a given pair and the corresponding branch lengths...
Inner data structure for WPGMA and UPGMA distance methods.
The phylogenetic node class.
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...