bpp-phyl3  3.0.0
bpp::AbstractAgglomerativeDistanceMethod Class Referenceabstract

Partial implementation of the AgglomerativeDistanceMethod interface. More...

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

+ Inheritance diagram for bpp::AbstractAgglomerativeDistanceMethod:
+ Collaboration diagram for bpp::AbstractAgglomerativeDistanceMethod:

Public Member Functions

 AbstractAgglomerativeDistanceMethod (bool verbose=true, bool rootTree=false)
 
 AbstractAgglomerativeDistanceMethod (const DistanceMatrix &matrix, bool verbose=true, bool rootTree=false)
 
virtual ~AbstractAgglomerativeDistanceMethod ()
 
 AbstractAgglomerativeDistanceMethod (const AbstractAgglomerativeDistanceMethod &a)
 
AbstractAgglomerativeDistanceMethodoperator= (const AbstractAgglomerativeDistanceMethod &a)
 
virtual void setDistanceMatrix (const DistanceMatrix &matrix) override
 Set the distance matrix to use. More...
 
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
 
virtual AgglomerativeDistanceMethodInterfaceclone () const override=0
 
virtual std::string getName () const =0
 

Protected Member Functions

Specific methods.
virtual std::vector< size_t > getBestPair ()=0
 Get the best pair of nodes to agglomerate. More...
 
virtual std::vector< double > computeBranchLengthsForPair (const std::vector< size_t > &pair)=0
 Compute the branch lengths for two nodes to agglomerate. More...
 
virtual double computeDistancesFromPair (const std::vector< size_t > &pair, const std::vector< double > &branchLengths, size_t pos)=0
 Actualizes the distance matrix according to a given pair and the corresponding branch lengths. More...
 
virtual void finalStep (int idRoot)=0
 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

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

Detailed Description

Partial implementation of the AgglomerativeDistanceMethod interface.

This class provides a DistanceMatrix object for computations, and a map with pivot indices and a pointer toward the corresponding subtree.

Several methods, commons to several algorithm are provided.

Definition at line 26 of file AbstractAgglomerativeDistanceMethod.h.

Constructor & Destructor Documentation

◆ AbstractAgglomerativeDistanceMethod() [1/3]

bpp::AbstractAgglomerativeDistanceMethod::AbstractAgglomerativeDistanceMethod ( bool  verbose = true,
bool  rootTree = false 
)
inline

Definition at line 38 of file AbstractAgglomerativeDistanceMethod.h.

◆ AbstractAgglomerativeDistanceMethod() [2/3]

bpp::AbstractAgglomerativeDistanceMethod::AbstractAgglomerativeDistanceMethod ( const DistanceMatrix matrix,
bool  verbose = true,
bool  rootTree = false 
)
inline

Definition at line 47 of file AbstractAgglomerativeDistanceMethod.h.

References setDistanceMatrix().

◆ ~AbstractAgglomerativeDistanceMethod()

virtual bpp::AbstractAgglomerativeDistanceMethod::~AbstractAgglomerativeDistanceMethod ( )
inlinevirtual

Definition at line 60 of file AbstractAgglomerativeDistanceMethod.h.

◆ AbstractAgglomerativeDistanceMethod() [3/3]

bpp::AbstractAgglomerativeDistanceMethod::AbstractAgglomerativeDistanceMethod ( const AbstractAgglomerativeDistanceMethod a)
inline

Definition at line 62 of file AbstractAgglomerativeDistanceMethod.h.

References tree_.

Member Function Documentation

◆ clone()

virtual AgglomerativeDistanceMethodInterface* bpp::AgglomerativeDistanceMethodInterface::clone ( ) const
overridepure virtualinherited

◆ computeBranchLengthsForPair()

virtual std::vector<double> bpp::AbstractAgglomerativeDistanceMethod::computeBranchLengthsForPair ( const std::vector< size_t > &  pair)
protectedpure virtual

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.

Implemented in bpp::PGMA, bpp::NeighborJoining, and bpp::HierarchicalClustering.

◆ computeDistancesFromPair()

virtual double bpp::AbstractAgglomerativeDistanceMethod::computeDistancesFromPair ( const std::vector< size_t > &  pair,
const std::vector< double > &  branchLengths,
size_t  pos 
)
protectedpure virtual

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.

Implemented in bpp::PGMA, bpp::NeighborJoining, bpp::HierarchicalClustering, and bpp::BioNJ.

◆ computeTree()

void AbstractAgglomerativeDistanceMethod::computeTree ( )
overridevirtual

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 bpp::PGMA::PGMA().

◆ finalStep()

virtual void bpp::AbstractAgglomerativeDistanceMethod::finalStep ( int  idRoot)
protectedpure virtual

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.

Implemented in bpp::PGMA, bpp::NeighborJoining, and bpp::HierarchicalClustering.

◆ getBestPair()

virtual std::vector<size_t> bpp::AbstractAgglomerativeDistanceMethod::getBestPair ( )
protectedpure virtual

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.

Implemented in bpp::PGMA, bpp::NeighborJoining, and bpp::HierarchicalClustering.

◆ getLeafNode()

Node * AbstractAgglomerativeDistanceMethod::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 in bpp::PGMA, and bpp::HierarchicalClustering.

Definition at line 75 of file AbstractAgglomerativeDistanceMethod.cpp.

◆ getName()

virtual std::string bpp::DistanceMethodInterface::getName ( ) const
pure virtualinherited
Returns
The name of the distance method.

Implemented in bpp::PGMA, bpp::NeighborJoining, bpp::HierarchicalClustering, and bpp::BioNJ.

◆ getParentNode()

Node * AbstractAgglomerativeDistanceMethod::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 in bpp::PGMA, and bpp::HierarchicalClustering.

Definition at line 80 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::Node::addSon().

◆ hasTree()

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

Implements bpp::DistanceMethodInterface.

Definition at line 86 of file AbstractAgglomerativeDistanceMethod.h.

References tree_.

◆ isVerbose()

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

Implements bpp::DistanceMethodInterface.

Definition at line 114 of file AbstractAgglomerativeDistanceMethod.h.

References verbose_.

◆ operator=()

AbstractAgglomerativeDistanceMethod& bpp::AbstractAgglomerativeDistanceMethod::operator= ( const AbstractAgglomerativeDistanceMethod a)
inline

Definition at line 70 of file AbstractAgglomerativeDistanceMethod.h.

References currentNodes_, matrix_, rootTree_, tree_, and verbose_.

◆ setDistanceMatrix()

void AbstractAgglomerativeDistanceMethod::setDistanceMatrix ( const DistanceMatrix matrix)
overridevirtual

Set the distance matrix to use.

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

Implements bpp::DistanceMethodInterface.

Reimplemented in bpp::PGMA, bpp::NeighborJoining, and bpp::BioNJ.

Definition at line 17 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::DistanceMatrix::reset(), and bpp::DistanceMatrix::size().

Referenced by AbstractAgglomerativeDistanceMethod(), bpp::NeighborJoining::setDistanceMatrix(), and bpp::PGMA::setDistanceMatrix().

◆ setVerbose()

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

Implements bpp::DistanceMethodInterface.

Definition at line 113 of file AbstractAgglomerativeDistanceMethod.h.

References verbose_.

◆ tree()

const Tree& bpp::AbstractAgglomerativeDistanceMethod::tree ( ) const
inlineoverridevirtual
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 tree_.

Member Data Documentation

◆ currentNodes_

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

Definition at line 33 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ matrix_

DistanceMatrix bpp::AbstractAgglomerativeDistanceMethod::matrix_
protected

Definition at line 30 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ rootTree_

bool bpp::AbstractAgglomerativeDistanceMethod::rootTree_
protected

Definition at line 35 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ tree_

std::unique_ptr<Tree> bpp::AbstractAgglomerativeDistanceMethod::tree_
protected

◆ verbose_

bool bpp::AbstractAgglomerativeDistanceMethod::verbose_
protected

Definition at line 34 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by isVerbose(), operator=(), and setVerbose().


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