bpp-phyl3 3.0.0
DRASDRTreeLikelihoodData.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_LEGACY_LIKELIHOOD_DRASDRTREELIKELIHOODDATA_H
6#define BPP_PHYL_LEGACY_LIKELIHOOD_DRASDRTREELIKELIHOODDATA_H
7
8
9#include "../../Model/SubstitutionModel.h"
10#include "../../SitePatterns.h"
11#include "../../PatternTools.h"
13
14// From SeqLib:
16
17// From the STL:
18#include <map>
19
20namespace bpp
21{
32 public virtual TreeLikelihoodNodeData
33{
34private:
36 const Node* leaf_;
37
38public:
40
43
45 {
47 leaf_ = data.leaf_;
48 return *this;
49 }
50
52 {
53 return new DRASDRTreeLikelihoodLeafData(*this);
54 }
55
56public:
57 const Node* getNode() const { return leaf_; }
58 void setNode(const Node* node) { leaf_ = node; }
59
61};
62
73 public virtual TreeLikelihoodNodeData
74{
75private:
89 mutable std::map<int, VVVdouble> nodeLikelihoods_;
100
111
112 const Node* node_;
113
114public:
116
121 node_(data.node_)
122 {}
123
125 {
129 node_ = data.node_;
130 return *this;
131 }
132
134
136 {
137 return new DRASDRTreeLikelihoodNodeData(*this);
138 }
139
140public:
141 const Node* getNode() const { return node_; }
142
143 void setNode(const Node* node) { node_ = node; }
144
145 const std::map<int, VVVdouble>& getLikelihoodArrays() const { return nodeLikelihoods_; }
146
147 std::map<int, VVVdouble>& getLikelihoodArrays() { return nodeLikelihoods_; }
148
150 {
151 return nodeLikelihoods_[neighborId];
152 }
153
154 const VVVdouble& getLikelihoodArrayForNeighbor(int neighborId) const
155 {
156 return nodeLikelihoods_[neighborId];
157 }
158
160
162
164
166
167 bool isNeighbor(int neighborId) const
168 {
169 return nodeLikelihoods_.find(neighborId) != nodeLikelihoods_.end();
170 }
171
173 {
177 }
178};
179
184 public virtual AbstractTreeLikelihoodData
185{
186private:
187 mutable std::map<int, DRASDRTreeLikelihoodNodeData> nodeData_;
188 mutable std::map<int, DRASDRTreeLikelihoodLeafData> leafData_;
192
193 std::shared_ptr<AlignmentDataInterface> shrunkData_;
194 size_t nbSites_;
195 size_t nbStates_;
198
199public:
200 DRASDRTreeLikelihoodData(std::shared_ptr< const TreeTemplate<Node>> tree, size_t nbClasses) :
203 shrunkData_(nullptr), nbSites_(0), nbStates_(0), nbClasses_(nbClasses), nbDistinctSites_(0)
204 {}
205
212 shrunkData_(nullptr),
215 {
216 if (data.shrunkData_)
217 shrunkData_ = std::shared_ptr<AlignmentDataInterface>(data.shrunkData_->clone());
218 }
219
221 {
223 nodeData_ = data.nodeData_;
224 leafData_ = data.leafData_;
228 nbSites_ = data.nbSites_;
229 nbStates_ = data.nbStates_;
230 nbClasses_ = data.nbClasses_;
232 if (data.shrunkData_)
233 shrunkData_ = std::shared_ptr<AlignmentDataInterface>(data.shrunkData_->clone());
234 else
235 shrunkData_ = nullptr;
236 return *this;
237 }
238
240
242
243public:
253 void setTree(std::shared_ptr< const TreeTemplate<Node>> tree)
254 {
255 tree_ = tree;
256 for (auto& it : nodeData_)
257 {
258 int id = it.second.getNode()->getId();
259 it.second.setNode(tree_->getNode(id));
260 }
261 for (auto& it : leafData_)
262 {
263 int id = it.second.getNode()->getId();
264 it.second.setNode(tree_->getNode(id));
265 }
266 }
267
269 {
270 return nodeData_[nodeId];
271 }
272
274 {
275 return nodeData_[nodeId];
276 }
277
279 {
280 return leafData_[nodeId];
281 }
282
284 {
285 return leafData_[nodeId];
286 }
287
288 size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const
289 {
290 return currentPosition;
291 }
292
293 const std::map<int, VVVdouble>& getLikelihoodArrays(int nodeId) const
294 {
295 return nodeData_[nodeId].getLikelihoodArrays();
296 }
297
298 std::map<int, VVVdouble>& getLikelihoodArrays(int nodeId)
299 {
300 return nodeData_[nodeId].getLikelihoodArrays();
301 }
302
303 VVVdouble& getLikelihoodArray(int parentId, int neighborId)
304 {
305 return nodeData_[parentId].getLikelihoodArrayForNeighbor(neighborId);
306 }
307
308 const VVVdouble& getLikelihoodArray(int parentId, int neighborId) const
309 {
310 return nodeData_[parentId].getLikelihoodArrayForNeighbor(neighborId);
311 }
312
314 {
315 return nodeData_[nodeId].getDLikelihoodArray();
316 }
317
318 const Vdouble& getDLikelihoodArray(int nodeId) const
319 {
320 return nodeData_[nodeId].getDLikelihoodArray();
321 }
322
324 {
325 return nodeData_[nodeId].getD2LikelihoodArray();
326 }
327
328 const Vdouble& getD2LikelihoodArray(int nodeId) const
329 {
330 return nodeData_[nodeId].getD2LikelihoodArray();
331 }
332
334 {
335 return leafData_[nodeId].getLikelihoodArray();
336 }
337
338 const VVdouble& getLeafLikelihoods(int nodeId) const
339 {
340 return leafData_[nodeId].getLikelihoodArray();
341 }
342
345
348
351
353
354 size_t getNumberOfSites() const { return nbSites_; }
355
356 size_t getNumberOfStates() const { return nbStates_; }
357
358 size_t getNumberOfClasses() const { return nbClasses_; }
359
360 std::shared_ptr<const AlignmentDataInterface> getShrunkData() const { return shrunkData_; }
361
363
371 void initLikelihoods(const AlignmentDataInterface& sites, const TransitionModelInterface& model);
372
380 void reInit();
381
382 void reInit(const Node* node);
383
384protected:
401 void initLikelihoods(const Node* node, const AlignmentDataInterface& sites, const TransitionModelInterface& model);
402};
403} // end of namespace bpp.
404#endif // BPP_PHYL_LEGACY_LIKELIHOOD_DRASDRTREELIKELIHOODDATA_H
Partial implementation of the TreeLikelihoodData interface.
AbstractTreeLikelihoodData & operator=(const AbstractTreeLikelihoodData &atd)
std::shared_ptr< const TreeTemplate< Node > > tree_
Likelihood data structure for rate across sites models, using a double-recursive algorithm.
const std::map< int, VVVdouble > & getLikelihoodArrays(int nodeId) const
VVVdouble & getLikelihoodArray(int parentId, int neighborId)
const DRASDRTreeLikelihoodLeafData & getLeafData(int nodeId) const
const Vdouble & getRootRateSiteLikelihoodArray() const
VVdouble & getLeafLikelihoods(int nodeId)
DRASDRTreeLikelihoodData(const DRASDRTreeLikelihoodData &data)
const DRASDRTreeLikelihoodNodeData & getNodeData(int nodeId) const
std::shared_ptr< const AlignmentDataInterface > getShrunkData() const
DRASDRTreeLikelihoodNodeData & getNodeData(int nodeId)
DRASDRTreeLikelihoodData * clone() const
void setTree(std::shared_ptr< const TreeTemplate< Node > > tree)
Set the tree associated to the data.
std::map< int, VVVdouble > & getLikelihoodArrays(int nodeId)
void reInit()
Rebuild likelihood arrays at inner nodes.
const VVVdouble & getRootLikelihoodArray() const
DRASDRTreeLikelihoodData & operator=(const DRASDRTreeLikelihoodData &data)
const VVVdouble & getLikelihoodArray(int parentId, int neighborId) const
const Vdouble & getD2LikelihoodArray(int nodeId) const
DRASDRTreeLikelihoodData(std::shared_ptr< const TreeTemplate< Node > > tree, size_t nbClasses)
const VVdouble & getRootSiteLikelihoodArray() const
const VVdouble & getLeafLikelihoods(int nodeId) const
const Vdouble & getDLikelihoodArray(int nodeId) const
const AlignmentDataInterface & shrunkData() const
void initLikelihoods(const AlignmentDataInterface &sites, const TransitionModelInterface &model)
Resize and initialize all likelihood arrays according to the given data set and substitution model.
std::map< int, DRASDRTreeLikelihoodNodeData > nodeData_
std::map< int, DRASDRTreeLikelihoodLeafData > leafData_
size_t getArrayPosition(int parentId, int sonId, size_t currentPosition) const
std::shared_ptr< AlignmentDataInterface > shrunkData_
DRASDRTreeLikelihoodLeafData & getLeafData(int nodeId)
Vdouble & getD2LikelihoodArray(int nodeId)
Likelihood data structure for a leaf.
DRASDRTreeLikelihoodLeafData & operator=(const DRASDRTreeLikelihoodLeafData &data)
DRASDRTreeLikelihoodLeafData * clone() const
const Node * getNode() const
Get the node associated to this data structure.
DRASDRTreeLikelihoodLeafData(const DRASDRTreeLikelihoodLeafData &data)
void setNode(const Node *node)
Set the node associated to this data.
Likelihood data structure for a node.
const Node * getNode() const
Get the node associated to this data structure.
void setNode(const Node *node)
Set the node associated to this data.
const std::map< int, VVVdouble > & getLikelihoodArrays() const
VVVdouble & getLikelihoodArrayForNeighbor(int neighborId)
const Vdouble & getD2LikelihoodArrayForNeighbor() const
DRASDRTreeLikelihoodNodeData * clone() const
Vdouble nodeDLikelihoods_
This contains all likelihood first order derivatives values used for computation.
std::map< int, VVVdouble > & getLikelihoodArrays()
DRASDRTreeLikelihoodNodeData & operator=(const DRASDRTreeLikelihoodNodeData &data)
std::map< int, VVVdouble > nodeLikelihoods_
This contains all likelihood values used for computation.
DRASDRTreeLikelihoodNodeData(const DRASDRTreeLikelihoodNodeData &data)
const VVVdouble & getLikelihoodArrayForNeighbor(int neighborId) const
Vdouble nodeD2Likelihoods_
This contains all likelihood second order derivatives values used for computation.
The phylogenetic node class.
Definition: Node.h:59
Interface for all transition models.
TreeLikelihood partial data structure.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble