bpp-phyl  2.2.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) throw (Exception)
 Set the distance matrix to use. More...
 
virtual TreeTemplate< Node > * getTree () const
 Get the computed tree, if there is one. More...
 
virtual void computeTree () throw (Exception)
 Compute the tree corresponding to the distance matrix. More...
 
void setVerbose (bool yn)
 
bool isVerbose () const
 
virtual std::string getName () const =0
 

Protected Member Functions

Specific methods.
virtual std::vector< size_t > getBestPair ()=0 throw (Exception)
 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_
 
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 62 of file AbstractAgglomerativeDistanceMethod.h.

Constructor & Destructor Documentation

◆ AbstractAgglomerativeDistanceMethod() [1/3]

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

Definition at line 77 of file AbstractAgglomerativeDistanceMethod.h.

◆ AbstractAgglomerativeDistanceMethod() [2/3]

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

Definition at line 80 of file AbstractAgglomerativeDistanceMethod.h.

References setDistanceMatrix().

◆ ~AbstractAgglomerativeDistanceMethod()

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

Definition at line 86 of file AbstractAgglomerativeDistanceMethod.h.

References tree_.

◆ AbstractAgglomerativeDistanceMethod() [3/3]

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

Definition at line 92 of file AbstractAgglomerativeDistanceMethod.h.

References tree_.

Member Function Documentation

◆ 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::NeighborJoining, bpp::PGMA, 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::NeighborJoining, bpp::PGMA, bpp::BioNJ, and bpp::HierarchicalClustering.

◆ computeTree()

void AbstractAgglomerativeDistanceMethod::computeTree ( )
throw (Exception
)
virtual

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::DistanceMethod.

Reimplemented in bpp::BioNJ.

Definition at line 62 of file AbstractAgglomerativeDistanceMethod.cpp.

References 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::NeighborJoining, bpp::PGMA, and bpp::HierarchicalClustering.

◆ getBestPair()

virtual std::vector<size_t> bpp::AbstractAgglomerativeDistanceMethod::getBestPair ( )
throw (Exception
)
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 occured.

Implemented in bpp::NeighborJoining, bpp::PGMA, 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 111 of file AbstractAgglomerativeDistanceMethod.cpp.

◆ getName()

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

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

◆ 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 116 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::Node::addSon().

◆ getTree()

virtual TreeTemplate<Node>* bpp::AbstractAgglomerativeDistanceMethod::getTree ( ) const
inlinevirtual

Get the computed tree, if there is one.

Returns
A copy of the computed tree if there is one, 0 otherwise.

Implements bpp::DistanceMethod.

Reimplemented in bpp::HierarchicalClustering, and bpp::PGMA.

Definition at line 127 of file AbstractAgglomerativeDistanceMethod.h.

References tree_.

Referenced by bpp::TreeTools::MRP(), and bpp::TreeTools::MRPMultilabel().

◆ isVerbose()

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

Implements bpp::DistanceMethod.

Definition at line 149 of file AbstractAgglomerativeDistanceMethod.h.

References verbose_.

◆ operator=()

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

Definition at line 100 of file AbstractAgglomerativeDistanceMethod.h.

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

◆ setDistanceMatrix()

void AbstractAgglomerativeDistanceMethod::setDistanceMatrix ( const DistanceMatrix &  matrix)
throw (Exception
)
virtual

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::DistanceMethod.

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

Definition at line 53 of file AbstractAgglomerativeDistanceMethod.cpp.

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

◆ setVerbose()

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

Implements bpp::DistanceMethod.

Definition at line 148 of file AbstractAgglomerativeDistanceMethod.h.

References verbose_.

Member Data Documentation

◆ currentNodes_

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

Definition at line 69 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ matrix_

DistanceMatrix bpp::AbstractAgglomerativeDistanceMethod::matrix_
protected

Definition at line 66 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ rootTree_

bool bpp::AbstractAgglomerativeDistanceMethod::rootTree_
protected

Definition at line 71 of file AbstractAgglomerativeDistanceMethod.h.

Referenced by operator=().

◆ tree_

Tree* bpp::AbstractAgglomerativeDistanceMethod::tree_
protected

◆ verbose_

bool bpp::AbstractAgglomerativeDistanceMethod::verbose_
protected

Definition at line 70 of file AbstractAgglomerativeDistanceMethod.h.

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


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