bpp-phyl3 3.0.0
RateAcrossSitesSubstitutionProcess.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
8
9using namespace bpp;
10using namespace std;
11
12RateAcrossSitesSubstitutionProcess::RateAcrossSitesSubstitutionProcess(
13 std::shared_ptr<BranchModelInterface> model,
14 std::shared_ptr<DiscreteDistributionInterface> rdist,
15 std::shared_ptr<const PhyloTree> tree,
16 std::shared_ptr<FrequencySetInterface> rootFrequencies) :
18 AbstractAutonomousSubstitutionProcess(tree, rootFrequencies, model ? model->getNamespace() : ""),
19 model_(model),
20 rDist_(rdist)
21{
22 if (!model)
23 throw Exception("RateAcrossSitesSubstitutionProcess. A model instance must be provided.");
24 if (!rdist)
25 throw Exception("RateAcrossSitesSubstitutionProcess. A rate distribution instance must be provided.");
26
27 addParameters_(model->getIndependentParameters()); // Substitution model
28
29 addParameters_(rdist->getIndependentParameters()); // Rate
30 // distribution
31}
32
34 std::shared_ptr<BranchModelInterface> model,
35 std::shared_ptr<DiscreteDistributionInterface> rdist,
36 std::shared_ptr<ParametrizablePhyloTree> tree,
37 std::shared_ptr<FrequencySetInterface> rootFrequencies) :
39 AbstractAutonomousSubstitutionProcess(tree, rootFrequencies, model ? model->getNamespace() : ""),
40 model_(model),
41 rDist_(rdist)
42{
43 if (!model)
44 throw Exception("RateAcrossSitesSubstitutionProcess. A model instance must be provided.");
45 if (!rdist)
46 throw Exception("RateAcrossSitesSubstitutionProcess. A rate distribution instance must be provided.");
47
48 addParameters_(model->getIndependentParameters()); // Substitution model
49
50 addParameters_(rdist->getIndependentParameters()); // Rate
51 // distribution
52}
53
57 model_(rassp.model_->clone()),
58 rDist_(rassp.rDist_->clone())
59{
61 modelScenario_->changeModel(std::dynamic_pointer_cast<MixedTransitionModelInterface>(rassp.model_), std::dynamic_pointer_cast<MixedTransitionModelInterface>(model_));
62}
63
64
66{
69 model_.reset(rassp.model_->clone());
70 rDist_.reset(rassp.rDist_->clone());
71
73 modelScenario_->changeModel(std::dynamic_pointer_cast<MixedTransitionModelInterface>(rassp.model_), std::dynamic_pointer_cast<MixedTransitionModelInterface>(model_));
74
75 return *this;
76}
77
78void RateAcrossSitesSubstitutionProcess::setModelScenario(std::shared_ptr<ModelScenario> modelpath)
79{
80 auto vmod = modelpath->getModels();
81
82 if (vmod.size() == 0) // as if no scenario
83 return;
84
85 if (vmod.size() != 1)
86 throw Exception("RateAcrossSitesSubstitutionProcess::setModelScenario: model path must have exactly one model.");
87
88 if (vmod[0] != model_)
89 throw Exception("RateAcrossSitesSubstitutionProcess::setModelScenario: models are different " + vmod[0]->getNModel(0)->getName() + " != " + model_->getName());
90
91 modelScenario_ = modelpath;
92}
93
95{
96 // Update rate distribution:
97 rDist_->matchParametersValues(pl);
98 model_->matchParametersValues(pl);
99
100 // Transition probabilities have changed and need to be recomputed:
102}
A partial implementation of the SubstitutionProcess interface.
void fireParameterChanged(const ParameterList &pl)
AbsractParametrizable interface.
AbstractAutonomousSubstitutionProcess & operator=(const AbstractAutonomousSubstitutionProcess &asp)
void addParameters_(const ParameterList &parameters)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
virtual const ParameterList & getIndependentParameters() const=0
void setModelScenario(std::shared_ptr< ModelScenario > modelpath) override
Set the modelPath, after checking it is valid (ie modelpath has only the model of the process).
const BranchModelInterface & model(size_t n) const override
RateAcrossSitesSubstitutionProcess & operator=(const RateAcrossSitesSubstitutionProcess &rassp)
void fireParameterChanged(const ParameterList &pl) override
AbsractParametrizable interface.
std::shared_ptr< DiscreteDistributionInterface > rDist_
std::shared_ptr< BranchModelInterface > model_
RateAcrossSitesSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< const PhyloTree > tree=nullptr, std::shared_ptr< FrequencySetInterface > rootFrequencies=nullptr)
Defines the basic types of data flow nodes.