bpp-phyl3  3.0.0
MarginalAncestralStateReconstruction.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 _LEGACY_MARGINAL_ANCESTRAL_STATES_RECONSTRUCTION_H_
6 #define _LEGACY_MARGINAL_ANCESTRAL_STATES_RECONSTRUCTION_H_
7 
8 #include "../AncestralStateReconstruction.h"
9 #include "DRTreeLikelihood.h"
10 
11 // From bpp-seq:
14 #include <Bpp/Seq/Sequence.h>
15 
16 // From the STL:
17 #include <vector>
18 
19 namespace bpp
20 {
29 {
30 private:
31  std::shared_ptr<const DRTreeLikelihoodInterface> likelihood_;
33  std::shared_ptr<const Alphabet> alphabet_;
34  size_t nbSites_;
36  size_t nbClasses_;
37  size_t nbStates_;
38  std::vector<size_t> rootPatternLinks_;
39  std::vector<double> r_;
40  std::vector<double> l_;
41 
42 public:
43  LegacyMarginalAncestralStateReconstruction(std::shared_ptr<const DRTreeLikelihoodInterface> drl) :
44  likelihood_ (drl),
45  tree_ (drl->tree()),
46  alphabet_ (drl->getAlphabet()),
47  nbSites_ (drl->likelihoodData().getNumberOfSites()),
48  nbDistinctSites_ (drl->likelihoodData().getNumberOfDistinctSites()),
49  nbClasses_ (drl->likelihoodData().getNumberOfClasses()),
50  nbStates_ (drl->likelihoodData().getNumberOfStates()),
51  rootPatternLinks_(drl->likelihoodData().getRootArrayPositions()),
52  r_ (drl->rateDistribution().getProbabilities()),
53  l_ (drl->likelihoodData().getRootRateSiteLikelihoodArray())
54  {}
55 
57 
59 
61 
63 
64 public:
80  std::vector<size_t> getAncestralStatesForNode(int nodeId, VVdouble& probs, bool sample) const;
81 
82  std::vector<size_t> getAncestralStatesForNode(int nodeId) const override
83  {
84  VVdouble probs(nbSites_);
85  return getAncestralStatesForNode(nodeId, probs, false);
86  }
87 
88  std::map<int, std::vector<size_t>> getAllAncestralStates() const override;
89 
101  std::unique_ptr<Sequence> getAncestralSequenceForNode(int nodeId, VVdouble* probs, bool sample) const;
102 
103  std::unique_ptr<Sequence> getAncestralSequenceForNode(int nodeId) const override
104  {
105  return getAncestralSequenceForNode(nodeId, 0, false);
106  }
107 
108  std::unique_ptr<SiteContainerInterface> getAncestralSequences() const override
109  {
110  return getAncestralSequences(false);
111  }
112 
113  std::unique_ptr<SiteContainerInterface> getAncestralSequences(bool sample) const;
114 
115 private:
117  const Node* node,
118  std::map<int, std::vector<size_t>>& ancestors,
119  AlignedSequenceContainer& data) const;
120 };
121 } // end of namespace bpp.
122 
123 #endif // _LEGACY_MARGINAL_ANCESTRAL_STATES_RECONSTRUCTION_H_
Interface for ancestral states reconstruction methods.
Likelihood ancestral states reconstruction: marginal method.
LegacyMarginalAncestralStateReconstruction * clone() const
std::shared_ptr< const DRTreeLikelihoodInterface > likelihood_
std::map< int, std::vector< size_t > > getAllAncestralStates() const override
Get all ancestral states for all nodes.
LegacyMarginalAncestralStateReconstruction(std::shared_ptr< const DRTreeLikelihoodInterface > drl)
LegacyMarginalAncestralStateReconstruction(const LegacyMarginalAncestralStateReconstruction &masr)=default
std::vector< size_t > getAncestralStatesForNode(int nodeId) const override
Get ancestral states for a given node as a vector of int.
std::unique_ptr< Sequence > getAncestralSequenceForNode(int nodeId, VVdouble *probs, bool sample) const
Get the ancestral sequence for a given node.
std::vector< size_t > getAncestralStatesForNode(int nodeId, VVdouble &probs, bool sample) const
Get ancestral states for a given node as a vector of int.
std::unique_ptr< Sequence > getAncestralSequenceForNode(int nodeId) const override
Get the ancestral sequence for a given node.
void recursiveMarginalAncestralStates(const Node *node, std::map< int, std::vector< size_t >> &ancestors, AlignedSequenceContainer &data) const
LegacyMarginalAncestralStateReconstruction & operator=(const LegacyMarginalAncestralStateReconstruction &masr)=default
std::unique_ptr< SiteContainerInterface > getAncestralSequences() const override
Get all the ancestral sequences for all nodes.
The phylogenetic node class.
Definition: Node.h:59
The phylogenetic tree class.
Definition: TreeTemplate.h:59
Defines the basic types of data flow nodes.
std::vector< Vdouble > VVdouble