bpp-phyl  2.2.0
HierarchicalClustering.h
Go to the documentation of this file.
1 //
2 // File: HierarchicalClustering.h
3 // From file Cluster.h in CoMap package.
4 // Created by: Julien Dutheil
5 // Created on: Tue Aug 30 17:19 2005
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
10 
11  This software is a computer program whose purpose is to map substitutions
12  on a tree and to detect co-evolving positions in a dataset.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39  */
40 
41 #ifndef _HIERARCHICALCLUSTERING_H_
42 #define _HIERARCHICALCLUSTERING_H_
43 
45 
46 namespace bpp
47 {
49 {
50 public:
52  double length;
53 
54 public:
56  length(0) {}
57 };
58 
66 {
67 public:
68  static const std::string COMPLETE;
69  static const std::string SINGLE;
70  static const std::string AVERAGE;
71  static const std::string MEDIAN;
72  static const std::string WARD;
73  static const std::string CENTROID;
74 
75 protected:
76  std::string method_;
77 
78 public:
85  HierarchicalClustering(const std::string& method, bool verbose = false) :
87  method_(method) {}
88  HierarchicalClustering(const std::string& method, const DistanceMatrix& matrix, bool verbose = false) throw (Exception) :
89  AbstractAgglomerativeDistanceMethod(matrix, verbose, true),
90  method_(method)
91  {
92  computeTree();
93  }
94 
96 
97  HierarchicalClustering* clone() const { return new HierarchicalClustering(*this); }
98 
99 public:
100  std::string getName() const { return "Hierarchical clustering: " + method_; }
101 
102  TreeTemplate<Node>* getTree() const;
103 
104 protected:
105  std::vector<size_t> getBestPair() throw (Exception);
106  std::vector<double> computeBranchLengthsForPair(const std::vector<size_t>& pair);
107  double computeDistancesFromPair(const std::vector<size_t>& pair, const std::vector<double>& branchLengths, size_t pos);
108  void finalStep(int idRoot);
109  virtual Node* getLeafNode(int id, const std::string& name);
110  virtual Node* getParentNode(int id, Node* son1, Node* son2);
111 };
112 } // end of namespace bpp.
113 
114 #endif // _HIERARCHICALCLUSTERING_H_
115 
HierarchicalClustering * clone() const
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
Partial implementation of the AgglomerativeDistanceMethod interface.
HierarchicalClustering(const std::string &method, bool verbose=false)
Builds a new clustering object.
static const std::string SINGLE
STL namespace.
Hierarchical clustering.
The phylogenetic tree class.
static const std::string COMPLETE
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...
static const std::string CENTROID
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
virtual void computeTree()
Compute the tree corresponding to the distance matrix.
The phylogenetic node class.
Definition: Node.h:90
HierarchicalClustering(const std::string &method, const DistanceMatrix &matrix, bool verbose=false)
TreeTemplate< Node > * getTree() const
Get the computed tree, if there is one.
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
static const std::string WARD
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.
static const std::string MEDIAN
static const std::string AVERAGE