bpp-phyl3  3.0.0
SimpleSubstitutionProcess.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 
7 using namespace bpp;
8 using namespace std;
9 
11  std::shared_ptr<BranchModelInterface> model,
12  std::shared_ptr<ParametrizablePhyloTree> tree,
13  std::shared_ptr<FrequencySetInterface> rootFrequencies) :
15  AbstractAutonomousSubstitutionProcess(tree, rootFrequencies, model ? model->getNamespace() : ""),
16  model_(model)
17 {
18  if (!model)
19  throw Exception("SimpleSubstitutionProcess. A model instance must be provided.");
20 
21  // Add parameters:
22  addParameters_(model->getIndependentParameters()); // Substitution model
23 }
24 
26  std::shared_ptr<BranchModelInterface> model,
27  std::shared_ptr<const PhyloTree> tree,
28  std::shared_ptr<FrequencySetInterface> rootFrequencies) :
30  AbstractAutonomousSubstitutionProcess(tree, rootFrequencies, model ? model->getNamespace() : ""),
31  model_(model)
32 {
33  if (!model)
34  throw Exception("SimpleSubstitutionProcess. A model instance must be provided.");
35 
36  // Add parameters:
37  addParameters_(model->getIndependentParameters()); // Substitution model
38 }
39 
43  model_(ssp.model_->clone())
44 {
45  if (modelScenario_)
46  modelScenario_->changeModel(dynamic_pointer_cast<MixedTransitionModelInterface>(ssp.model_), dynamic_pointer_cast<MixedTransitionModelInterface>(model_));
47 }
48 
50 {
53  model_.reset(ssp.model_->clone());
54 
55  if (modelScenario_)
56  modelScenario_->changeModel(dynamic_pointer_cast<MixedTransitionModelInterface>(ssp.model_), dynamic_pointer_cast<MixedTransitionModelInterface>(model_));
57 
58  return *this;
59 }
60 
61 void SimpleSubstitutionProcess::setModelScenario(std::shared_ptr<ModelScenario> modelpath)
62 {
63  auto vmod = modelpath->getModels();
64 
65  if (vmod.size() == 0) // as if no scenario
66  return;
67 
68  if (vmod.size() != 1)
69  throw Exception("SimpleSubstitutionProcess::setModelScenario: model path must have exactly one model.");
70 
71  auto mixed_ = dynamic_pointer_cast<MixedTransitionModelInterface>(model_);
72  if (!mixed_)
73  throw Exception("SimpleSubstitutionProcess::setModelScenario: model must be mixed.");
74 
75  if (vmod[0] != mixed_)
76  throw Exception("SimpleSubstitutionProcess::setModelScenario: models are different " + vmod[0]->getNModel(0)->getName() + " != " + mixed_->getNModel(0)->getName());
77 
78  modelScenario_ = modelpath;
79 }
80 
82 {
83  // Transition probabilities have changed and need to be recomputed:
85 
86  model_->matchParametersValues(pl);
87 }
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
Space and time homogeneous substitution process, without mixture.
std::shared_ptr< BranchModelInterface > model_
const BranchModelInterface & model(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
void fireParameterChanged(const ParameterList &pl) override
AbsractParametrizable interface.
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).
SimpleSubstitutionProcess & operator=(const SimpleSubstitutionProcess &ssp)
SimpleSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< const PhyloTree > tree=nullptr, std::shared_ptr< FrequencySetInterface > rootFrequencies=nullptr)
Defines the basic types of data flow nodes.