bpp-phyl
2.2.0
|
Hierarchical clustering. More...
#include <Bpp/Phyl/Distance/HierarchicalClustering.h>
Public Member Functions | |
HierarchicalClustering (const std::string &method, bool verbose=false) | |
Builds a new clustering object. More... | |
HierarchicalClustering (const std::string &method, const DistanceMatrix &matrix, bool verbose=false) throw (Exception) | |
virtual | ~HierarchicalClustering () |
HierarchicalClustering * | clone () const |
std::string | getName () const |
TreeTemplate< Node > * | getTree () const |
Get the computed tree, if there is one. More... | |
virtual void | setDistanceMatrix (const DistanceMatrix &matrix) throw (Exception) |
Set the distance matrix to use. More... | |
virtual void | computeTree () throw (Exception) |
Compute the tree corresponding to the distance matrix. More... | |
void | setVerbose (bool yn) |
bool | isVerbose () const |
Static Public Attributes | |
static const std::string | COMPLETE = "Complete" |
static const std::string | SINGLE = "Single" |
static const std::string | AVERAGE = "Average" |
static const std::string | MEDIAN = "Median" |
static const std::string | WARD = "Ward" |
static const std::string | CENTROID = "Centroid" |
Protected Member Functions | |
std::vector< size_t > | getBestPair () throw (Exception) |
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 Node * | getLeafNode (int id, const std::string &name) |
Get a leaf node. More... | |
virtual Node * | getParentNode (int id, Node *son1, Node *son2) |
Get an inner node. More... | |
Protected Attributes | |
std::string | method_ |
DistanceMatrix | matrix_ |
Tree * | tree_ |
std::map< size_t, Node * > | currentNodes_ |
bool | verbose_ |
bool | rootTree_ |
Hierarchical clustering.
This class implements the complete, single, average (= UPGMA), median, ward and centroid linkage methods.
Definition at line 64 of file HierarchicalClustering.h.
|
inline |
Builds a new clustering object.
method | The linkage method to use. should be one of COMPLETE, SINGLE, AVERAGE, MEDIAN, WARD, CENTROID. |
verbose | Tell if some progress information should be displayed. |
Definition at line 85 of file HierarchicalClustering.h.
Referenced by clone().
|
inline |
Definition at line 88 of file HierarchicalClustering.h.
References bpp::AbstractAgglomerativeDistanceMethod::computeTree().
|
inlinevirtual |
Definition at line 95 of file HierarchicalClustering.h.
|
inline |
Definition at line 97 of file HierarchicalClustering.h.
References HierarchicalClustering().
|
protectedvirtual |
Compute the branch lengths for two nodes to agglomerate.
This method compute l1 and l2 given N1 and N2.
pair | The indices of the nodes to be agglomerated. |
Implements bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 104 of file HierarchicalClustering.cpp.
|
protectedvirtual |
Actualizes the distance matrix according to a given pair and the corresponding branch lengths.
pair | The indices of the nodes to be agglomerated. |
branchLengths | The corresponding branch lengths. |
pos | The index of the node whose distance ust be updated. |
Implements bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 113 of file HierarchicalClustering.cpp.
|
virtualinherited |
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 HierarchicalClustering(), bpp::NeighborJoining::NeighborJoining(), and bpp::PGMA::PGMA().
|
protectedvirtual |
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of the tree.
idRoot | The id of the root node. |
Implements bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 173 of file HierarchicalClustering.cpp.
References bpp::Node::addSon(), and bpp::Node::setDistanceToFather().
|
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.
Exception | If an error occured. |
Implements bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 60 of file HierarchicalClustering.cpp.
|
protectedvirtual |
Get a leaf node.
Create a new node with the given id and name.
id | The id of the node. |
name | The name of the node. |
Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 190 of file HierarchicalClustering.cpp.
References bpp::ClusterInfos::length, bpp::ClusterInfos::numberOfLeaves, and bpp::NodeTemplate< NodeInfos >::setInfos().
|
inlinevirtual |
Implements bpp::DistanceMethod.
Definition at line 100 of file HierarchicalClustering.h.
References method_.
Get an inner node.
Create a new node with the given id, and set its sons.
id | The id of the node. |
son1 | The first son of the node. |
son2 | The second son of the node. |
Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 200 of file HierarchicalClustering.cpp.
References bpp::Node::addSon(), bpp::Node::getDistanceToFather(), bpp::ClusterInfos::length, and bpp::ClusterInfos::numberOfLeaves.
|
virtual |
Get the computed tree, if there is one.
Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.
Definition at line 54 of file HierarchicalClustering.cpp.
|
inlinevirtualinherited |
Implements bpp::DistanceMethod.
Definition at line 149 of file AbstractAgglomerativeDistanceMethod.h.
References bpp::AbstractAgglomerativeDistanceMethod::verbose_.
|
virtualinherited |
Set the distance matrix to use.
matrix | The matrix to use. |
Exception | In 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 bpp::AbstractAgglomerativeDistanceMethod::AbstractAgglomerativeDistanceMethod(), bpp::PGMA::setDistanceMatrix(), and bpp::NeighborJoining::setDistanceMatrix().
|
inlinevirtualinherited |
yn | Enable/Disable verbose mode. |
Implements bpp::DistanceMethod.
Definition at line 148 of file AbstractAgglomerativeDistanceMethod.h.
References bpp::AbstractAgglomerativeDistanceMethod::verbose_.
|
static |
Definition at line 70 of file HierarchicalClustering.h.
|
static |
Definition at line 73 of file HierarchicalClustering.h.
|
static |
Definition at line 68 of file HierarchicalClustering.h.
|
protectedinherited |
Definition at line 69 of file AbstractAgglomerativeDistanceMethod.h.
Referenced by bpp::AbstractAgglomerativeDistanceMethod::operator=().
|
protectedinherited |
Definition at line 66 of file AbstractAgglomerativeDistanceMethod.h.
Referenced by bpp::AbstractAgglomerativeDistanceMethod::operator=().
|
static |
Definition at line 71 of file HierarchicalClustering.h.
|
protected |
Definition at line 76 of file HierarchicalClustering.h.
Referenced by getName().
|
protectedinherited |
Definition at line 71 of file AbstractAgglomerativeDistanceMethod.h.
Referenced by bpp::AbstractAgglomerativeDistanceMethod::operator=().
|
static |
Definition at line 69 of file HierarchicalClustering.h.
|
protectedinherited |
Definition at line 67 of file AbstractAgglomerativeDistanceMethod.h.
Referenced by bpp::AbstractAgglomerativeDistanceMethod::AbstractAgglomerativeDistanceMethod(), bpp::AbstractAgglomerativeDistanceMethod::getTree(), bpp::AbstractAgglomerativeDistanceMethod::operator=(), and bpp::AbstractAgglomerativeDistanceMethod::~AbstractAgglomerativeDistanceMethod().
|
protectedinherited |
Definition at line 70 of file AbstractAgglomerativeDistanceMethod.h.
Referenced by bpp::AbstractAgglomerativeDistanceMethod::isVerbose(), bpp::AbstractAgglomerativeDistanceMethod::operator=(), and bpp::AbstractAgglomerativeDistanceMethod::setVerbose().
|
static |
Definition at line 72 of file HierarchicalClustering.h.