bpp-phyl3 3.0.0
MarginalAncestralReconstruction.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_LIKELIHOOD_MARGINALANCESTRALRECONSTRUCTION_H
6#define BPP_PHYL_LIKELIHOOD_MARGINALANCESTRALRECONSTRUCTION_H
7
8
9#include "../AncestralStateReconstruction.h"
12
13// From bpp-seq:
16#include <Bpp/Seq/Sequence.h>
17
18// From the STL:
19#include <vector>
20
21namespace bpp
22{
30 public virtual AncestralStateReconstruction
31{
32private:
33 std::shared_ptr<LikelihoodCalculationSingleProcess> likelihood_;
34 std::shared_ptr<const ParametrizablePhyloTree> tree_;
35 mutable std::shared_ptr<const Alphabet> alphabet_;
36 size_t nbSites_;
38 // size_t nbClasses_;
39 size_t nbStates_;
41
42public:
43 MarginalAncestralReconstruction(std::shared_ptr<LikelihoodCalculationSingleProcess> drl) :
44 likelihood_ (drl),
45 tree_ (drl->substitutionProcess().getParametrizablePhyloTree()),
46 alphabet_ (drl->stateMap().getAlphabet()),
47 nbSites_ (drl->getNumberOfSites()),
48 nbDistinctSites_ (drl->getNumberOfDistinctSites()),
49 nbStates_ (drl->stateMap().getNumberOfModelStates()),
50 rootPatternLinks_(drl->getRootArrayPositions())
51 {
52 if (!tree_)
53 throw Exception("MarginalAncestralReconstruction::MarginalAncestralReconstruction: missing ParametrizablePhyloTree.");
54 }
55
58 tree_ (masr.tree_),
59 alphabet_ (masr.alphabet_),
60 nbSites_ (masr.nbSites_),
62 nbStates_ (masr.nbStates_),
64 {}
65
67 {
69 tree_ = masr.tree_;
70 alphabet_ = masr.alphabet_;
71 nbSites_ = masr.nbSites_;
73 nbStates_ = masr.nbStates_;
75 return *this;
76 }
77
78
80
82
83public:
84 std::shared_ptr<const Alphabet> getAlphabet() const
85 {
86 return alphabet_;
87 }
88
109 std::vector<size_t> getAncestralStatesForNode(uint nodeId, VVdouble& probs, bool sample) const;
110
111 std::vector<size_t> getAncestralStatesForNode(uint nodeId) const override
112 {
113 VVdouble probs(nbSites_);
114 return getAncestralStatesForNode(nodeId, probs, false);
115 }
116
117 std::map<uint, std::vector<size_t>> getAllAncestralStates() const override;
118
136 std::unique_ptr<Sequence> getAncestralSequenceForNode(uint nodeId, VVdouble* probs, bool sample) const;
137
138 std::unique_ptr<Sequence> getAncestralSequenceForNode(uint nodeId) const override
139 {
140 return getAncestralSequenceForNode(nodeId, 0, false);
141 }
142
143 std::unique_ptr<AlignedSequenceContainer> getAncestralSequences() const override
144 {
145 return getAncestralSequences(false);
146 }
147
148 std::unique_ptr<AlignedSequenceContainer> getAncestralSequences(bool sample) const;
149
150private:
152 const std::shared_ptr<PhyloNode> node,
153 std::map<uint, std::vector<size_t>>& ancestors,
154 AlignmentDataInterface& data) const;
155};
156} // end of namespace bpp.
157#endif // BPP_PHYL_LIKELIHOOD_MARGINALANCESTRALRECONSTRUCTION_H
Interface for ancestral states reconstruction methods.
Likelihood ancestral states reconstruction: marginal method.
void recursiveMarginalAncestralStates(const std::shared_ptr< PhyloNode > node, std::map< uint, std::vector< size_t > > &ancestors, AlignmentDataInterface &data) const
MarginalAncestralReconstruction & operator=(const MarginalAncestralReconstruction &masr)
MarginalAncestralReconstruction * clone() const
std::vector< size_t > getAncestralStatesForNode(uint nodeId) const override
Get ancestral states for a given node as a vector of int.
MarginalAncestralReconstruction(std::shared_ptr< LikelihoodCalculationSingleProcess > drl)
MarginalAncestralReconstruction(const MarginalAncestralReconstruction &masr)
std::unique_ptr< Sequence > getAncestralSequenceForNode(uint nodeId) const override
Get the ancestral sequence for a given node.
std::shared_ptr< const Alphabet > getAlphabet() const
std::shared_ptr< const ParametrizablePhyloTree > tree_
std::unique_ptr< Sequence > getAncestralSequenceForNode(uint nodeId, VVdouble *probs, bool sample) const
Get an ancestral sequence for a given node.
std::shared_ptr< LikelihoodCalculationSingleProcess > likelihood_
std::map< uint, std::vector< size_t > > getAllAncestralStates() const override
Get all ancestral states for all nodes.
std::unique_ptr< AlignedSequenceContainer > getAncestralSequences() const override
Get all the ancestral sequences for all nodes.
std::vector< size_t > getAncestralStatesForNode(uint nodeId, VVdouble &probs, bool sample) const
Get ancestral states for a given node as a vector of int.
Defines the basic types of data flow nodes.
Eigen::Matrix< size_t, -1, 1 > PatternType
std::vector< Vdouble > VVdouble