bpp-phyl3 3.0.0
PGMA.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_DISTANCE_PGMA_H
6#define BPP_PHYL_DISTANCE_PGMA_H
7
8
9#include "../Tree/Tree.h"
10#include "../Tree/TreeTemplate.h"
12
13namespace bpp
14{
19{
21 double time;
22};
23
32class PGMA :
34{
35protected:
37
38public:
39 PGMA(bool weighted = true) :
41 weighted_(weighted) {}
42
50 PGMA(const DistanceMatrix& matrix, bool weighted = true, bool verbose = true) :
51 AbstractAgglomerativeDistanceMethod(matrix, verbose, true),
52 weighted_(weighted)
53 {
55 }
56 virtual ~PGMA() {}
57
58 PGMA* clone() const { return new PGMA(*this); }
59
60public:
61 std::string getName() const { return std::string(weighted_ ? "W" : "U") + "PGMA"; }
62
64 {
66 }
67
68 void setWeighted(bool weighted) { weighted_ = weighted; }
69 bool isWeighted() const { return weighted_; }
70
71protected:
72 std::vector<size_t> getBestPair();
73 std::vector<double> computeBranchLengthsForPair(const std::vector<size_t>& pair);
74 double computeDistancesFromPair(const std::vector<size_t>& pair, const std::vector<double>& branchLengths, size_t pos);
75 void finalStep(int idRoot);
76 virtual Node* getLeafNode(int id, const std::string& name);
77 virtual Node* getParentNode(int id, Node* son1, Node* son2);
78};
79} // end of namespace bpp.
80#endif // BPP_PHYL_DISTANCE_PGMA_H
Partial implementation of the AgglomerativeDistanceMethod interface.
virtual void setDistanceMatrix(const DistanceMatrix &matrix) override
Set the distance matrix to use.
void computeTree() override
Compute the tree corresponding to the distance matrix.
The phylogenetic node class.
Definition: Node.h:59
Compute WPGMA and UPGMA trees from a distance matrix.
Definition: PGMA.h:34
std::string getName() const
Definition: PGMA.h:61
PGMA * clone() const
Definition: PGMA.h:58
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
Definition: PGMA.cpp:49
void setDistanceMatrix(const DistanceMatrix &matrix)
Set the distance matrix to use.
Definition: PGMA.h:63
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.
Definition: PGMA.cpp:101
virtual ~PGMA()
Definition: PGMA.h:56
PGMA(bool weighted=true)
Definition: PGMA.h:39
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.
Definition: PGMA.cpp:58
void setWeighted(bool weighted)
Definition: PGMA.h:68
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
Definition: PGMA.cpp:19
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
Definition: PGMA.cpp:91
bool weighted_
Definition: PGMA.h:36
bool isWeighted() const
Definition: PGMA.h:69
PGMA(const DistanceMatrix &matrix, bool weighted=true, bool verbose=true)
Create a (U/W)PGMA object instance.
Definition: PGMA.h:50
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
Definition: PGMA.cpp:74
Defines the basic types of data flow nodes.
Inner data structure for WPGMA and UPGMA distance methods.
Definition: PGMA.h:19
size_t numberOfLeaves
Definition: PGMA.h:20
double time
Definition: PGMA.h:21