bpp-phyl  2.2.0
DRTreeParsimonyData.h
Go to the documentation of this file.
1 //
2 // File: DRTreeParsimonyData.h
3 // Created by: Julien Dutheil
4 // Created on: Tue Jan 09 17:15 2007
5 // From file DRTreeParsimonyScore.h
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 _DRTREEPARSIMONYDATA_H_
42 #define _DRTREEPARSIMONYDATA_H_
43 
45 #include "../Model/StateMap.h"
46 
47 // From SeqLib
48 #include <Bpp/Seq/Container/SiteContainer.h>
49 
50 // From the STL:
51 #include <bitset>
52 
53 namespace bpp
54 {
55 typedef std::bitset<21> Bitset; // 20AA + gaps, codon not lalowed so far :s
56 
70 {
71 private:
72  mutable std::map<int, std::vector<Bitset> > nodeBitsets_;
73  mutable std::map<int, std::vector<unsigned int> > nodeScores_;
74  const Node* node_;
75 
76 public:
78  nodeBitsets_(),
79  nodeScores_(),
80  node_(0)
81  {}
82 
86  node_(tpnd.node_)
87  {}
88 
90  {
92  nodeScores_ = tpnd.nodeScores_;
93  node_ = tpnd.node_;
94  return *this;
95  }
96 
97  DRTreeParsimonyNodeData* clone() const { return new DRTreeParsimonyNodeData(*this); }
98 
99 public:
100  const Node* getNode() const { return node_; }
101 
102  void setNode(const Node* node) { node_ = node; }
103 
104  std::vector<Bitset>& getBitsetsArrayForNeighbor(int neighborId)
105  {
106  return nodeBitsets_[neighborId];
107  }
108  const std::vector<Bitset>& getBitsetsArrayForNeighbor(int neighborId) const
109  {
110  return nodeBitsets_[neighborId];
111  }
112  std::vector<unsigned int>& getScoresArrayForNeighbor(int neighborId)
113  {
114  return nodeScores_[neighborId];
115  }
116  const std::vector<unsigned int>& getScoresArrayForNeighbor(int neighborId) const
117  {
118  return nodeScores_[neighborId];
119  }
120 
121  bool isNeighbor(int neighborId) const
122  {
123  return nodeBitsets_.find(neighborId) != nodeBitsets_.end();
124  }
125 
127  {
128  nodeBitsets_.erase(nodeBitsets_.begin(), nodeBitsets_.end());
129  nodeScores_.erase(nodeScores_.begin(), nodeScores_.end());
130  }
131 };
132 
143  public TreeParsimonyNodeData
144 {
145 private:
146  mutable std::vector<Bitset> leafBitsets_;
147  const Node* leaf_;
148 
149 public:
151  leafBitsets_(),
152  leaf_(0)
153  {}
154 
157  leaf_(tpld.leaf_)
158  {}
159 
161  {
162  leafBitsets_ = tpld.leafBitsets_;
163  leaf_ = tpld.leaf_;
164  return *this;
165  }
166 
167 
168  DRTreeParsimonyLeafData* clone() const { return new DRTreeParsimonyLeafData(*this); }
169 
170 public:
171  const Node* getNode() const { return leaf_; }
172  void setNode(const Node* node) { leaf_ = node; }
173 
174  std::vector<Bitset>& getBitsetsArray()
175  {
176  return leafBitsets_;
177  }
178  const std::vector<Bitset>& getBitsetsArray() const
179  {
180  return leafBitsets_;
181  }
182 };
183 
197 {
198 private:
199  mutable std::map<int, DRTreeParsimonyNodeData> nodeData_;
200  mutable std::map<int, DRTreeParsimonyLeafData> leafData_;
201  mutable std::vector<Bitset> rootBitsets_;
202  mutable std::vector<unsigned int> rootScores_;
203  SiteContainer* shrunkData_;
204  size_t nbSites_;
205  size_t nbStates_;
207 
208 public:
211  nodeData_(),
212  leafData_(),
213  rootBitsets_(),
214  rootScores_(),
215  shrunkData_(0),
216  nbSites_(0),
217  nbStates_(0),
219  {}
220 
222 
224 
225  virtual ~DRTreeParsimonyData() { delete shrunkData_; }
226 
227  DRTreeParsimonyData* clone() const { return new DRTreeParsimonyData(*this); }
228 
229 public:
239  void setTree(const TreeTemplate<Node>* tree)
240  {
242  for (std::map<int, DRTreeParsimonyNodeData>::iterator it = nodeData_.begin(); it != nodeData_.end(); it++)
243  {
244  int id = it->second.getNode()->getId();
245  it->second.setNode(tree_->getNode(id));
246  }
247  for (std::map<int, DRTreeParsimonyLeafData>::iterator it = leafData_.begin(); it != leafData_.end(); it++)
248  {
249  int id = it->second.getNode()->getId();
250  it->second.setNode(tree_->getNode(id));
251  }
252  }
253 
255  {
256  return nodeData_[nodeId];
257  }
258  const DRTreeParsimonyNodeData& getNodeData(int nodeId) const
259  {
260  return nodeData_[nodeId];
261  }
262 
264  {
265  return leafData_[nodeId];
266  }
267  const DRTreeParsimonyLeafData& getLeafData(int nodeId) const
268  {
269  return leafData_[nodeId];
270  }
271 
272  std::vector<Bitset>& getBitsetsArray(int nodeId, int neighborId)
273  {
274  return nodeData_[nodeId].getBitsetsArrayForNeighbor(neighborId);
275  }
276  const std::vector<Bitset>& getBitsetsArray(int nodeId, int neighborId) const
277  {
278  return nodeData_[nodeId].getBitsetsArrayForNeighbor(neighborId);
279  }
280 
281  std::vector<unsigned int>& getScoresArray(int nodeId, int neighborId)
282  {
283  return nodeData_[nodeId].getScoresArrayForNeighbor(neighborId);
284  }
285  const std::vector<unsigned int>& getScoresArray(int nodeId, int neighborId) const
286  {
287  return nodeData_[nodeId].getScoresArrayForNeighbor(neighborId);
288  }
289 
290  size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const
291  {
292  return currentPosition;
293  }
294 
295  std::vector<Bitset>& getRootBitsets() { return rootBitsets_; }
296  const std::vector<Bitset>& getRootBitsets() const { return rootBitsets_; }
297  const Bitset& getRootBitset(size_t i) const { return rootBitsets_[i]; }
298 
299  std::vector<unsigned int>& getRootScores() { return rootScores_; }
300  const std::vector<unsigned int>& getRootScores() const { return rootScores_; }
301  unsigned int getRootScore(size_t i) const { return rootScores_[i]; }
302 
303  size_t getNumberOfDistinctSites() const { return nbDistinctSites_; }
304  size_t getNumberOfSites() const { return nbSites_; }
305  size_t getNumberOfStates() const { return nbStates_; }
306 
307  void init(const SiteContainer& sites, const StateMap& stateMap) throw (Exception);
308  void reInit() throw (Exception);
309 
310 protected:
311  void init(const Node* node, const SiteContainer& sites, const StateMap& stateMap) throw (Exception);
312  void reInit(const Node* node) throw (Exception);
313 };
314 } // end of namespace bpp.
315 
316 #endif // _DRTREEPARSIMONYDATA_H_
317 
Parsimony data structure for a node.
unsigned int getRootScore(size_t i) const
std::map< int, std::vector< Bitset > > nodeBitsets_
std::vector< Bitset > & getBitsetsArrayForNeighbor(int neighborId)
void setTree(const TreeTemplate< Node > *tree)
Set the tree associated to the data.
DRTreeParsimonyNodeData(const DRTreeParsimonyNodeData &tpnd)
std::vector< Bitset > leafBitsets_
DRTreeParsimonyNodeData & operator=(const DRTreeParsimonyNodeData &tpnd)
const std::vector< Bitset > & getBitsetsArrayForNeighbor(int neighborId) const
TreeParsimonyScore node data structure.
const std::vector< Bitset > & getRootBitsets() const
std::map< int, std::vector< unsigned int > > nodeScores_
std::vector< unsigned int > & getScoresArray(int nodeId, int neighborId)
const DRTreeParsimonyLeafData & getLeafData(int nodeId) const
The phylogenetic tree class.
DRTreeParsimonyLeafData * clone() const
const Bitset & getRootBitset(size_t i) const
std::vector< Bitset > & getBitsetsArray(int nodeId, int neighborId)
bool isNeighbor(int neighborId) const
const TreeTemplate< Node > * tree_
DRTreeParsimonyNodeData & getNodeData(int nodeId)
void setNode(const Node *node)
Set the node associated to this data.
std::vector< unsigned int > & getRootScores()
std::vector< unsigned int > & getScoresArrayForNeighbor(int neighborId)
Parsimony data structure for a leaf.
void setTreeP_(const TreeTemplate< Node > *tree)
std::map< int, DRTreeParsimonyLeafData > leafData_
const Node * getNode() const
Get the node associated to this data structure.
const Node * getNode() const
Get the node associated to this data structure.
const DRTreeParsimonyNodeData & getNodeData(int nodeId) const
void init(const SiteContainer &sites, const StateMap &stateMap)
const std::vector< unsigned int > & getScoresArrayForNeighbor(int neighborId) const
std::vector< Bitset > & getRootBitsets()
const std::vector< Bitset > & getBitsetsArray(int nodeId, int neighborId) const
DRTreeParsimonyLeafData(const DRTreeParsimonyLeafData &tpld)
std::vector< unsigned int > rootScores_
size_t getNumberOfDistinctSites() const
DRTreeParsimonyData * clone() const
The phylogenetic node class.
Definition: Node.h:90
std::bitset< 21 > Bitset
DRTreeParsimonyData & operator=(const DRTreeParsimonyData &data)
const std::vector< Bitset > & getBitsetsArray() const
const std::vector< unsigned int > & getRootScores() const
std::map< int, DRTreeParsimonyNodeData > nodeData_
Parsimony data structure for double-recursive (DR) algorithm.
DRTreeParsimonyData(const TreeTemplate< Node > *tree)
const std::vector< unsigned int > & getScoresArray(int nodeId, int neighborId) const
Partial implementation of the TreeParsimonyData interface.
size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const
std::vector< Bitset > & getBitsetsArray()
std::vector< Bitset > rootBitsets_
DRTreeParsimonyNodeData * clone() const
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58
void setNode(const Node *node)
Set the node associated to this data.
DRTreeParsimonyLeafData & operator=(const DRTreeParsimonyLeafData &tpld)
DRTreeParsimonyLeafData & getLeafData(int nodeId)