bpp-phyl3 3.0.0
DRTreeParsimonyData.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_PARSIMONY_DRTREEPARSIMONYDATA_H
6#define BPP_PHYL_PARSIMONY_DRTREEPARSIMONYDATA_H
7
8
9#include "../Model/StateMap.h"
11
12// From SeqLib
14
15// From the STL:
16#include <bitset>
17
18namespace bpp
19{
20typedef std::bitset<21> Bitset; // 20AA + gaps, codon not lalowed so far :s
21
35{
36private:
37 mutable std::map<int, std::vector<Bitset>> nodeBitsets_;
38 mutable std::map<int, std::vector<unsigned int>> nodeScores_;
39 const Node* node_;
40
41public:
45 node_(0)
46 {}
47
51 node_(tpnd.node_)
52 {}
53
55 {
58 node_ = tpnd.node_;
59 return *this;
60 }
61
63
64public:
65 const Node* getNode() const { return node_; }
66
67 void setNode(const Node* node) { node_ = node; }
68
69 std::vector<Bitset>& getBitsetsArrayForNeighbor(int neighborId)
70 {
71 return nodeBitsets_[neighborId];
72 }
73 const std::vector<Bitset>& getBitsetsArrayForNeighbor(int neighborId) const
74 {
75 return nodeBitsets_[neighborId];
76 }
77 std::vector<unsigned int>& getScoresArrayForNeighbor(int neighborId)
78 {
79 return nodeScores_[neighborId];
80 }
81 const std::vector<unsigned int>& getScoresArrayForNeighbor(int neighborId) const
82 {
83 return nodeScores_[neighborId];
84 }
85
86 bool isNeighbor(int neighborId) const
87 {
88 return nodeBitsets_.find(neighborId) != nodeBitsets_.end();
89 }
90
92 {
93 nodeBitsets_.erase(nodeBitsets_.begin(), nodeBitsets_.end());
94 nodeScores_.erase(nodeScores_.begin(), nodeScores_.end());
95 }
96};
97
109{
110private:
111 mutable std::vector<Bitset> leafBitsets_;
112 const Node* leaf_;
113
114public:
116 leafBitsets_(),
117 leaf_(0)
118 {}
119
122 leaf_(tpld.leaf_)
123 {}
124
126 {
128 leaf_ = tpld.leaf_;
129 return *this;
130 }
131
132
134
135public:
136 const Node* getNode() const { return leaf_; }
137 void setNode(const Node* node) { leaf_ = node; }
138
139 std::vector<Bitset>& getBitsetsArray()
140 {
141 return leafBitsets_;
142 }
143 const std::vector<Bitset>& getBitsetsArray() const
144 {
145 return leafBitsets_;
146 }
147};
148
162{
163private:
164 mutable std::map<int, DRTreeParsimonyNodeData> nodeData_;
165 mutable std::map<int, DRTreeParsimonyLeafData> leafData_;
166 mutable std::vector<Bitset> rootBitsets_;
167 mutable std::vector<unsigned int> rootScores_;
168 std::unique_ptr<SiteContainerInterface> shrunkData_;
169 size_t nbSites_;
170 size_t nbStates_;
172
173public:
176 nodeData_(),
177 leafData_(),
178 rootBitsets_(),
179 rootScores_(),
180 shrunkData_(nullptr),
181 nbSites_(0),
182 nbStates_(0),
184 {}
185
187
189
191
192 DRTreeParsimonyData* clone() const override { return new DRTreeParsimonyData(*this); }
193
194public:
204 void setTree(std::shared_ptr<const TreeTemplate<Node>> tree)
205 {
207 for (auto& it : nodeData_)
208 {
209 int id = it.second.getNode()->getId();
210 it.second.setNode(tree_->getNode(id));
211 }
212 for (auto& it : leafData_)
213 {
214 int id = it.second.getNode()->getId();
215 it.second.setNode(tree_->getNode(id));
216 }
217 }
218
219 DRTreeParsimonyNodeData& nodeData(int nodeId) override
220 {
221 return nodeData_[nodeId];
222 }
223 const DRTreeParsimonyNodeData& nodeData(int nodeId) const override
224 {
225 return nodeData_[nodeId];
226 }
227
229 {
230 return leafData_[nodeId];
231 }
232 const DRTreeParsimonyLeafData& leafData(int nodeId) const
233 {
234 return leafData_[nodeId];
235 }
236
237 std::vector<Bitset>& getBitsetsArray(int nodeId, int neighborId)
238 {
239 return nodeData_[nodeId].getBitsetsArrayForNeighbor(neighborId);
240 }
241 const std::vector<Bitset>& getBitsetsArray(int nodeId, int neighborId) const
242 {
243 return nodeData_[nodeId].getBitsetsArrayForNeighbor(neighborId);
244 }
245
246 std::vector<unsigned int>& getScoresArray(int nodeId, int neighborId)
247 {
248 return nodeData_[nodeId].getScoresArrayForNeighbor(neighborId);
249 }
250 const std::vector<unsigned int>& getScoresArray(int nodeId, int neighborId) const
251 {
252 return nodeData_[nodeId].getScoresArrayForNeighbor(neighborId);
253 }
254
255 size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const override
256 {
257 return currentPosition;
258 }
259
260 std::vector<Bitset>& getRootBitsets() { return rootBitsets_; }
261 const std::vector<Bitset>& getRootBitsets() const { return rootBitsets_; }
262 const Bitset& getRootBitset(size_t i) const { return rootBitsets_[i]; }
263
264 std::vector<unsigned int>& getRootScores() { return rootScores_; }
265 const std::vector<unsigned int>& getRootScores() const { return rootScores_; }
266 unsigned int getRootScore(size_t i) const { return rootScores_[i]; }
267
269 size_t getNumberOfSites() const { return nbSites_; }
270 size_t getNumberOfStates() const { return nbStates_; }
271
272 void init(std::shared_ptr<const SiteContainerInterface> sites,
273 std::shared_ptr<const StateMapInterface> stateMap);
274 void reInit();
275
276protected:
277 void init_(const Node* node,
278 std::shared_ptr<const SiteContainerInterface> sites,
279 std::shared_ptr<const StateMapInterface> stateMap);
280
281 void reInit_(const Node* node);
282};
283} // end of namespace bpp.
284#endif // BPP_PHYL_PARSIMONY_DRTREEPARSIMONYDATA_H
Partial implementation of the TreeParsimonyData interface.
void setTree(std::shared_ptr< const TreeTemplate< Node > > tree)
std::shared_ptr< const TreeTemplate< Node > > tree_
const TreeTemplate< Node > & tree() const override
Parsimony data structure for double-recursive (DR) algorithm.
std::unique_ptr< SiteContainerInterface > shrunkData_
void reInit_(const Node *node)
size_t getNumberOfDistinctSites() const
std::vector< Bitset > rootBitsets_
unsigned int getRootScore(size_t i) const
std::vector< unsigned int > & getRootScores()
std::vector< Bitset > & getRootBitsets()
const DRTreeParsimonyNodeData & nodeData(int nodeId) const override
DRTreeParsimonyNodeData & nodeData(int nodeId) override
void init(std::shared_ptr< const SiteContainerInterface > sites, std::shared_ptr< const StateMapInterface > stateMap)
const Bitset & getRootBitset(size_t i) const
const std::vector< unsigned int > & getRootScores() const
DRTreeParsimonyLeafData & leafData(int nodeId)
const DRTreeParsimonyLeafData & leafData(int nodeId) const
void setTree(std::shared_ptr< const TreeTemplate< Node > > tree)
Set the tree associated to the data.
const std::vector< unsigned int > & getScoresArray(int nodeId, int neighborId) const
size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const override
void init_(const Node *node, std::shared_ptr< const SiteContainerInterface > sites, std::shared_ptr< const StateMapInterface > stateMap)
std::map< int, DRTreeParsimonyLeafData > leafData_
DRTreeParsimonyData & operator=(const DRTreeParsimonyData &data)
const std::vector< Bitset > & getRootBitsets() const
const std::vector< Bitset > & getBitsetsArray(int nodeId, int neighborId) const
std::vector< unsigned int > & getScoresArray(int nodeId, int neighborId)
std::vector< Bitset > & getBitsetsArray(int nodeId, int neighborId)
DRTreeParsimonyData(std::shared_ptr< const TreeTemplate< Node > > tree)
DRTreeParsimonyData * clone() const override
std::vector< unsigned int > rootScores_
std::map< int, DRTreeParsimonyNodeData > nodeData_
Parsimony data structure for a leaf.
const Node * getNode() const
Get the node associated to this data structure.
DRTreeParsimonyLeafData & operator=(const DRTreeParsimonyLeafData &tpld)
std::vector< Bitset > & getBitsetsArray()
void setNode(const Node *node)
Set the node associated to this data.
DRTreeParsimonyLeafData * clone() const
const std::vector< Bitset > & getBitsetsArray() const
std::vector< Bitset > leafBitsets_
DRTreeParsimonyLeafData(const DRTreeParsimonyLeafData &tpld)
Parsimony data structure for a node.
const Node * getNode() const
Get the node associated to this data structure.
DRTreeParsimonyNodeData(const DRTreeParsimonyNodeData &tpnd)
DRTreeParsimonyNodeData * clone() const
const std::vector< Bitset > & getBitsetsArrayForNeighbor(int neighborId) const
bool isNeighbor(int neighborId) const
std::map< int, std::vector< Bitset > > nodeBitsets_
std::vector< Bitset > & getBitsetsArrayForNeighbor(int neighborId)
const std::vector< unsigned int > & getScoresArrayForNeighbor(int neighborId) const
DRTreeParsimonyNodeData & operator=(const DRTreeParsimonyNodeData &tpnd)
std::vector< unsigned int > & getScoresArrayForNeighbor(int neighborId)
void setNode(const Node *node)
Set the node associated to this data.
std::map< int, std::vector< unsigned int > > nodeScores_
The phylogenetic node class.
Definition: Node.h:59
TreeParsimonyScore node data structure.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
Defines the basic types of data flow nodes.
std::bitset< 21 > Bitset