bpp-phyl  2.2.0
DRTreeParsimonyScore.h
Go to the documentation of this file.
1 //
2 // File: DRTreeParsimonyScore.h
3 // Created by: Julien Dutheil
4 // Created on: Thu Jul 28 18:31 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 _DRTREEPARSIMONYSCORE_H_
41 #define _DRTREEPARSIMONYSCORE_H_
42 
44 #include "DRTreeParsimonyData.h"
45 #include "../NNISearchable.h"
46 #include "../TreeTools.h"
47 
48 namespace bpp
49 {
57  public virtual NNISearchable
58 {
59 private:
62 
63 public:
65  const Tree& tree,
66  const SiteContainer& data,
67  bool verbose = true,
68  bool includeGaps = false)
69  throw (Exception);
70 
72  const Tree& tree,
73  const SiteContainer& data,
74  const StateMap* statesMap,
75  bool verbose = true)
76  throw (Exception);
77 
79 
80  DRTreeParsimonyScore& operator=(const DRTreeParsimonyScore& tp);
81 
82  virtual ~DRTreeParsimonyScore();
83 
84 #ifndef NO_VIRTUAL_COV
86 #else
87  Clonable*
88 #endif
89  clone() const { return new DRTreeParsimonyScore(*this); }
90 
91 private:
92  void init_(const SiteContainer& data, bool verbose);
93 
94 protected:
100  virtual void computeScores();
104  virtual void computeScoresPreorder(const Node*);
108  virtual void computeScoresPostorder(const Node*);
109 
110 public:
111  unsigned int getScore() const;
112  unsigned int getScoreForSite(size_t site) const;
113 
121  static void computeScoresPostorderForNode(
122  const DRTreeParsimonyNodeData& pData,
123  std::vector<Bitset>& rBitsets,
124  std::vector<unsigned int>& rScores);
125 
134  static void computeScoresPreorderForNode(
135  const DRTreeParsimonyNodeData& pData,
136  const Node* source,
137  std::vector<Bitset>& rBitsets,
138  std::vector<unsigned int>& rScores);
139 
147  static void computeScoresForNode(
148  const DRTreeParsimonyNodeData& pData, std::vector<Bitset>& rBitsets,
149  std::vector<unsigned int>& rScores);
150 
163  static void computeScoresFromArrays(
164  const std::vector<const std::vector<Bitset>*>& iBitsets,
165  const std::vector<const std::vector<unsigned int>*>& iScores,
166  std::vector<Bitset>& oBitsets,
167  std::vector<unsigned int>& oScores);
168 
174  double getTopologyValue() const throw (Exception) { return getScore(); }
175 
176  double testNNI(int nodeId) const throw (NodeException);
177 
178  void doNNI(int nodeId) throw (NodeException);
179 
180  // Tree& getTopology() { return getTree(); } do we realy need this one?
181  const Tree& getTopology() const { return getTree(); }
182 
184  {
186  computeScores();
187  }
188 
191 };
192 } // end of namespace bpp.
193 
194 #endif // _DRTREEPARSIMONYSCORE_H_
195 
Parsimony data structure for a node.
static void computeScoresFromArrays(const std::vector< const std::vector< Bitset > *> &iBitsets, const std::vector< const std::vector< unsigned int > *> &iScores, std::vector< Bitset > &oBitsets, std::vector< unsigned int > &oScores)
Compute bitsets and scores from an array of arrays.
double testNNI(int nodeId) const
Send the score of a NNI movement, without performing it.
Double recursive implementation of interface TreeParsimonyScore.
Interface for Nearest Neighbor Interchanges algorithms.
Definition: NNISearchable.h:96
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual void computeScoresPreorder(const Node *)
Compute scores (preorder algorithm).
void init_(const SiteContainer &data, bool verbose)
void doNNI(int nodeId)
Perform a NNI movement.
static void computeScoresForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in all directions.
static void computeScoresPostorderForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in postorder.
void topologyChangeSuccessful(const TopologyChangeEvent &event)
Tell that a topology change is definitive.
virtual void computeScoresPostorder(const Node *)
Compute scores (postorder algorithm).
void topologyChangeTested(const TopologyChangeEvent &event)
Notify a topology change event.
Class for notifying new toplogy change events.
The phylogenetic node class.
Definition: Node.h:90
Partial implementation of the TreeParsimonyScore interface.
virtual void computeScores()
Compute all scores.
Parsimony data structure for double-recursive (DR) algorithm.
DRTreeParsimonyData * parsimonyData_
DRTreeParsimonyScore * clone() const
unsigned int getScore() const
Get the score for the current tree, i.e. the total minimum number of changes in the tree...
const Tree & getTopology() const
Get the tree associated to this NNISearchable object.
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58
static void computeScoresPreorderForNode(const DRTreeParsimonyNodeData &pData, const Node *source, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in preorder.
unsigned int getScoreForSite(size_t site) const
Get the score for a given site for the current tree, i.e. the total minimum number of changes in the ...
General exception thrown when something is wrong with a particular node.
DRTreeParsimonyScore(const Tree &tree, const SiteContainer &data, bool verbose=true, bool includeGaps=false)
double getTopologyValue() const
Get the current score of this NNISearchable object.
virtual const Tree & getTree() const
Get the tree for wich scores are computed.