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