bpp-phyl3  3.0.0
bpp::PGMA Class Reference

Compute WPGMA and UPGMA trees from a distance matrix. More...

#include <Bpp/Phyl/Distance/PGMA.h>

+ Inheritance diagram for bpp::PGMA:
+ Collaboration diagram for bpp::PGMA:

Public Member Functions

 PGMA (bool weighted=true)
 
 PGMA (const DistanceMatrix &matrix, bool weighted=true, bool verbose=true)
 Create a (U/W)PGMA object instance. More...
 
virtual ~PGMA ()
 
PGMAclone () const
 
std::string getName () const
 
void setDistanceMatrix (const DistanceMatrix &matrix)
 Set the distance matrix to use. More...
 
void setWeighted (bool weighted)
 
bool isWeighted () const
 
bool hasTree () const override
 
const Treetree () const override
 
void computeTree () override
 Compute the tree corresponding to the distance matrix. More...
 
void setVerbose (bool yn) override
 
bool isVerbose () const override
 

Protected Member Functions

std::vector< size_t > getBestPair ()
 Get the best pair of nodes to agglomerate. More...
 
std::vector< double > computeBranchLengthsForPair (const std::vector< size_t > &pair)
 Compute the branch lengths for two nodes to agglomerate. More...
 
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. More...
 
void finalStep (int idRoot)
 Method called when there ar eonly three remaining node to agglomerate, and creates the root node of the tree. More...
 
virtual NodegetLeafNode (int id, const std::string &name)
 Get a leaf node. More...
 
virtual NodegetParentNode (int id, Node *son1, Node *son2)
 Get an inner node. More...
 

Protected Attributes

bool weighted_
 
DistanceMatrix matrix_
 
std::unique_ptr< Treetree_
 
std::map< size_t, Node * > currentNodes_
 
bool verbose_
 
bool rootTree_
 

Detailed Description

Compute WPGMA and UPGMA trees from a distance matrix.

WPGMA = Weighted pair group method using arithmetic averaging, is equivalent to the average linkage hierarchical clustering method. The distance between two taxa is the average distance between all individuals in each taxa. The unweighted version (named UPGMA), uses a weighted average, with the number of individuals in a group as a weight.

Definition at line 32 of file PGMA.h.

Constructor & Destructor Documentation

◆ PGMA() [1/2]

bpp::PGMA::PGMA ( bool  weighted = true)
inline

Definition at line 39 of file PGMA.h.

Referenced by clone().

◆ PGMA() [2/2]

bpp::PGMA::PGMA ( const DistanceMatrix matrix,
bool  weighted = true,
bool  verbose = true 
)
inline

Create a (U/W)PGMA object instance.

Parameters
matrixInput distance matrix.
weightedTell if we should perform Weighted or Unweighted pair group method.
verboseAllow to display extra information, like progress bars.

Definition at line 50 of file PGMA.h.

References bpp::AbstractAgglomerativeDistanceMethod::computeTree().

◆ ~PGMA()

virtual bpp::PGMA::~PGMA ( )
inlinevirtual

Definition at line 56 of file PGMA.h.

Member Function Documentation

◆ clone()

PGMA* bpp::PGMA::clone ( ) const
inlinevirtual

Implements bpp::AgglomerativeDistanceMethodInterface.

Definition at line 58 of file PGMA.h.

References PGMA().

◆ computeBranchLengthsForPair()

vector< double > PGMA::computeBranchLengthsForPair ( const std::vector< size_t > &  pair)
protectedvirtual

Compute the branch lengths for two nodes to agglomerate.

+---l1-----N1
|
+---l2-----N2

This method compute l1 and l2 given N1 and N2.

Parameters
pairThe indices of the nodes to be agglomerated.
Returns
A size 2 vector with branch lengths.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 49 of file PGMA.cpp.

◆ computeDistancesFromPair()

double PGMA::computeDistancesFromPair ( const std::vector< size_t > &  pair,
const std::vector< double > &  branchLengths,
size_t  pos 
)
protectedvirtual

Actualizes the distance matrix according to a given pair and the corresponding branch lengths.

Parameters
pairThe indices of the nodes to be agglomerated.
branchLengthsThe corresponding branch lengths.
posThe index of the node whose distance ust be updated.
Returns
The distance between the 'pos' node and the agglomerated pair.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 58 of file PGMA.cpp.

◆ computeTree()

void AbstractAgglomerativeDistanceMethod::computeTree ( )
overridevirtualinherited

Compute the tree corresponding to the distance matrix.

This method implements the following algorithm: 1) Build all leaf nodes (getLeafNode method) 2) Get the best pair to agglomerate (getBestPair method) 3) Compute the branch lengths for this pair (computeBranchLengthsForPair method) 4) Build the parent node of the pair (getParentNode method) 5) For each remaining node, update distances from the pair (computeDistancesFromPair method) 6) Return to step 2 while there are more than 3 remaining nodes. 7) Perform the final step, and send a rooted or unrooted tree.

Implements bpp::DistanceMethodInterface.

Reimplemented in bpp::BioNJ.

Definition at line 26 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::ApplicationTools::displayGauge(), and bpp::Node::setDistanceToFather().

Referenced by bpp::HierarchicalClustering::HierarchicalClustering(), bpp::NeighborJoining::NeighborJoining(), and PGMA().

◆ finalStep()

void PGMA::finalStep ( int  idRoot)
protectedvirtual

Method called when there ar eonly three remaining node to agglomerate, and creates the root node of the tree.

Parameters
idRootThe id of the root node.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 74 of file PGMA.cpp.

References bpp::Node::addSon(), and bpp::Node::setDistanceToFather().

◆ getBestPair()

vector< size_t > PGMA::getBestPair ( )
protectedvirtual

Get the best pair of nodes to agglomerate.

Define the criterion to chose the next pair of nodes to agglomerate. This criterion uses the matrix_ distance matrix.

Returns
A size 2 vector with the indices of the nodes.
Exceptions
ExceptionIf an error occurred.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 19 of file PGMA.cpp.

References bpp::numeric::log().

◆ getLeafNode()

Node * PGMA::getLeafNode ( int  id,
const std::string &  name 
)
protectedvirtual

Get a leaf node.

Create a new node with the given id and name.

Parameters
idThe id of the node.
nameThe name of the node.
Returns
A pointer toward a new node object.

Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 91 of file PGMA.cpp.

References bpp::PGMAInfos::numberOfLeaves, bpp::NodeTemplate< NodeInfos >::setInfos(), and bpp::PGMAInfos::time.

◆ getName()

std::string bpp::PGMA::getName ( ) const
inlinevirtual
Returns
The name of the distance method.

Implements bpp::DistanceMethodInterface.

Definition at line 61 of file PGMA.h.

References weighted_.

◆ getParentNode()

Node * PGMA::getParentNode ( int  id,
Node son1,
Node son2 
)
protectedvirtual

Get an inner node.

Create a new node with the given id, and set its sons.

Parameters
idThe id of the node.
son1The first son of the node.
son2The second son of the node.
Returns
A pointer toward a new node object.

Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 101 of file PGMA.cpp.

References bpp::Node::addSon(), bpp::Node::getDistanceToFather(), bpp::PGMAInfos::numberOfLeaves, and bpp::PGMAInfos::time.

◆ hasTree()

bool bpp::AbstractAgglomerativeDistanceMethod::hasTree ( ) const
inlineoverridevirtualinherited
Returns
True if a tree has been computed.

Implements bpp::DistanceMethodInterface.

Definition at line 86 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::tree_.

◆ isVerbose()

bool bpp::AbstractAgglomerativeDistanceMethod::isVerbose ( ) const
inlineoverridevirtualinherited
Returns
True if verbose mode is enabled.

Implements bpp::DistanceMethodInterface.

Definition at line 114 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::verbose_.

◆ isWeighted()

bool bpp::PGMA::isWeighted ( ) const
inline

Definition at line 69 of file PGMA.h.

References weighted_.

◆ setDistanceMatrix()

void bpp::PGMA::setDistanceMatrix ( const DistanceMatrix matrix)
inlinevirtual

Set the distance matrix to use.

Parameters
matrixThe matrix to use.
Exceptions
ExceptionIn case an incorrect matrix is provided (eg smaller than 3).

Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 63 of file PGMA.h.

References bpp::AbstractAgglomerativeDistanceMethod::setDistanceMatrix().

◆ setVerbose()

void bpp::AbstractAgglomerativeDistanceMethod::setVerbose ( bool  yn)
inlineoverridevirtualinherited
Parameters
ynEnable/Disable verbose mode.

Implements bpp::DistanceMethodInterface.

Definition at line 113 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::verbose_.

◆ setWeighted()

void bpp::PGMA::setWeighted ( bool  weighted)
inline

Definition at line 68 of file PGMA.h.

References weighted_.

◆ tree()

const Tree& bpp::AbstractAgglomerativeDistanceMethod::tree ( ) const
inlineoverridevirtualinherited
Returns
A reference toward the computed tree. Throws an exception if no tree was computed.

Implements bpp::DistanceMethodInterface.

Definition at line 91 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::tree_.

Member Data Documentation

◆ currentNodes_

std::map<size_t, Node*> bpp::AbstractAgglomerativeDistanceMethod::currentNodes_
protectedinherited

◆ matrix_

DistanceMatrix bpp::AbstractAgglomerativeDistanceMethod::matrix_
protectedinherited

◆ rootTree_

bool bpp::AbstractAgglomerativeDistanceMethod::rootTree_
protectedinherited

◆ tree_

◆ verbose_

◆ weighted_

bool bpp::PGMA::weighted_
protected

Definition at line 36 of file PGMA.h.

Referenced by getName(), isWeighted(), and setWeighted().


The documentation for this class was generated from the following files: