bpp-phyl  2.2.0
AbstractAgglomerativeDistanceMethod.h
Go to the documentation of this file.
1 //
2 // File: AbstractAgglomerativeDistanceMethod.h
3 // Created by: Julien Dutheil
4 // Vincent Ranwez
5 // Created on: Wed jun 22 10:00 2005
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10 
11 This software is a computer program whose purpose is to provide classes
12 for phylogenetic data analysis.
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 _ABSTRACTAGGLOMERATIVEDISTANCEMETHOD_H_
42 #define _ABSTRACTAGGLOMERATIVEDISTANCEMETHOD_H_
43 
44 #include "DistanceMethod.h"
45 #include "../Node.h"
46 #include "../TreeTemplate.h"
47 
48 // From the STL:
49 #include <map>
50 
51 namespace bpp
52 {
53 
63  public virtual AgglomerativeDistanceMethod
64 {
65  protected:
66  DistanceMatrix matrix_;
68 
69  std::map<size_t, Node*> currentNodes_;
70  bool verbose_;
71  bool rootTree_;
72 
73  public:
74  //AbstractAgglomerativeDistanceMethod() :
75  // matrix_(0), tree_(0), currentNodes_(), verbose_(true), rootTree_(false) {}
76 
77  AbstractAgglomerativeDistanceMethod(bool verbose = true, bool rootTree = false) :
78  matrix_(0), tree_(0), currentNodes_(), verbose_(verbose), rootTree_(rootTree) {}
79 
80  AbstractAgglomerativeDistanceMethod(const DistanceMatrix& matrix, bool verbose = true, bool rootTree = false) :
81  matrix_(0), tree_(0), currentNodes_(), verbose_(verbose), rootTree_(rootTree)
82  {
83  setDistanceMatrix(matrix);
84  }
85 
87  {
88  if (tree_)
89  delete tree_;
90  }
91 
94  {
95  // Hard copy of inner tree:
96  if (a.tree_)
97  tree_ = new TreeTemplate<Node>(* a.tree_);
98  }
99 
101  {
102  matrix_ = a.matrix_;
103  // Hard copy of inner tree:
104  if (a.tree_)
105  tree_ = new TreeTemplate<Node>(* a.tree_);
106  else tree_ = 0;
107  currentNodes_.clear();
108  verbose_ = a.verbose_;
109  rootTree_ = a.rootTree_;
110  return *this;
111  }
112 
113  public:
114  virtual void setDistanceMatrix(const DistanceMatrix& matrix) throw (Exception);
115 
121  virtual
122 #if defined(NO_VIRTUAL_COV)
123  Tree *
124 #else
126 #endif
127  getTree() const
128  {
129  //Node * root = TreeTools::cloneSubtree<Node>(* dynamic_cast<TreeTemplate<Node> *>(tree_) -> getRootNode());
130  //return new TreeTemplate<Node>(* root);
131  return tree_ == 0 ? 0 : new TreeTemplate<Node>(*tree_);
132  }
133 
146  virtual void computeTree() throw (Exception);
147 
148  void setVerbose(bool yn) { verbose_ = yn; }
149  bool isVerbose() const { return verbose_; }
150 
151  protected:
167  virtual std::vector<size_t> getBestPair() throw (Exception) = 0;
168 
182  virtual std::vector<double> computeBranchLengthsForPair(const std::vector<size_t> & pair) = 0;
183 
192  virtual double computeDistancesFromPair(const std::vector<size_t>& pair, const std::vector<double>& branchLengths, size_t pos) = 0;
193 
199  virtual void finalStep(int idRoot) = 0;
200 
210  virtual Node* getLeafNode(int id, const std::string& name);
211 
222  virtual Node* getParentNode(int id, Node * son1, Node * son2);
225 };
226 
227 } //end of namespace bpp.
228 
229 #endif //_ABSTRACTAGGLOMERATIVEDISTANCEMETHOD_H_
230 
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...
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
AbstractAgglomerativeDistanceMethod & operator=(const AbstractAgglomerativeDistanceMethod &a)
virtual std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)=0
Compute the branch lengths for two nodes to agglomerate.
Partial implementation of the AgglomerativeDistanceMethod interface.
virtual void setDistanceMatrix(const DistanceMatrix &matrix)
Set the distance matrix to use.
virtual TreeTemplate< Node > * getTree() const
Get the computed tree, if there is one.
STL namespace.
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
Interface for agglomerative distance methods.
AbstractAgglomerativeDistanceMethod(const DistanceMatrix &matrix, bool verbose=true, bool rootTree=false)
virtual void computeTree()
Compute the tree corresponding to the distance matrix.
AbstractAgglomerativeDistanceMethod(const AbstractAgglomerativeDistanceMethod &a)
The phylogenetic node class.
Definition: Node.h:90
AbstractAgglomerativeDistanceMethod(bool verbose=true, bool rootTree=false)
virtual void finalStep(int idRoot)=0
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
virtual std::vector< size_t > getBestPair()=0
Get the best pair of nodes to agglomerate.
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.