7 #include "../Tree/Node.h"
19 if (matrix.
size() <= 3)
20 throw Exception(
"AbstractAgglomerativeDistanceMethod::setDistanceMatrix(): matrix must be at least of dimension 3.");
22 currentNodes_.clear();
29 for (
size_t i = 0; i < matrix_.size(); ++i)
31 currentNodes_[i] = getLeafNode(
static_cast<int>(i), matrix_.getName(i));
33 int idNextNode =
static_cast<int>(matrix_.size());
34 vector<double> newDist(matrix_.size());
37 while (currentNodes_.size() > (rootTree_ ? 2 : 3))
41 vector<size_t> bestPair = getBestPair();
42 vector<double> distances = computeBranchLengthsForPair(bestPair);
43 Node* best1 = currentNodes_[bestPair[0]];
44 Node* best2 = currentNodes_[bestPair[1]];
48 Node* parent = getParentNode(idNextNode, best1, best2);
50 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
53 if (
id != bestPair[0] &&
id != bestPair[1])
55 assert (
id < newDist.size());
56 newDist[id] = computeDistancesFromPair(bestPair, distances,
id);
64 currentNodes_[bestPair[0]] = parent;
65 currentNodes_.erase(bestPair[1]);
66 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
69 matrix_(bestPair[0],
id) = matrix_(
id, bestPair[0]) = newDist[id];
72 finalStep(idNextNode);
77 return new Node(
id, name);
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
virtual void setDistanceMatrix(const DistanceMatrix &matrix) override
Set the distance matrix to use.
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.
void computeTree() override
Compute the tree corresponding to the distance matrix.
The phylogenetic node class.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.
virtual void addSon(size_t pos, Node *node)
Defines the basic types of data flow nodes.