bpp-phyl3  3.0.0
FromMixtureSubstitutionModel.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 
10 /******************************************************************************/
11 
13  const MixedTransitionModelInterface& mixedModel,
14  const std::string& subModelName,
15  const std::string& mixtDesc) :
16  AbstractParameterAliasable(mixedModel.getName() + "_" + subModelName + "."),
17  AbstractWrappedModel(mixedModel.getName() + "_" + subModelName + "."),
18  AbstractWrappedTransitionModel(mixedModel.getName() + "_" + subModelName + "."),
19  AbstractTotallyWrappedTransitionModel(mixedModel.getName() + "_" + subModelName + "."),
20  AbstractWrappedSubstitutionModel(mixedModel.getName() + "_" + subModelName + "."),
21  AbstractTotallyWrappedSubstitutionModel(mixedModel.getName() + "_" + subModelName + "."),
22  subModel_(),
23  mixtName_(mixtDesc)
24 {
25  try
26  {
27  auto& tm = mixedModel.model(subModelName);
28  try
29  {
30  auto& sm = dynamic_cast<const SubstitutionModelInterface&>(tm);
31  subModel_ = std::unique_ptr<SubstitutionModelInterface>(sm.clone());
32  subModel_->setNamespace(getNamespace());
33  subModel_->setRate(1);
34  addParameters_(subModel_->getParameters());
35  }
36  catch (bad_cast&)
37  {
38  throw Exception("FromMixtureSubstitutionModel::FromMixtureSubstitutionModel : model " + subModelName + " is not a substitution model.");
39  }
40  }
41  catch (NullPointerException&)
42  {
43  throw ParameterNotFoundException("FromMixtureSubstitutionModel::FromMixtureSubstitutionModel : unknown model name", subModelName);
44  }
45 }
46 
48  const MixedTransitionModelInterface& mixedModel,
49  size_t subModelNumber,
50  const std::string& mixtDesc) :
51  AbstractParameterAliasable(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
52  AbstractWrappedModel(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
53  AbstractWrappedTransitionModel(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
54  AbstractTotallyWrappedTransitionModel(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
55  AbstractWrappedSubstitutionModel(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
56  AbstractTotallyWrappedSubstitutionModel(mixedModel.getName() + "_" + TextTools::toString(subModelNumber) + "."),
57  subModel_(),
58  mixtName_(mixtDesc)
59 {
60  if (subModelNumber >= mixedModel.getNumberOfModels())
61  throw ParameterNotFoundException("FromMixtureSubstitutionModel::FromMixtureSubstitutionModel : bad model number", TextTools::toString(subModelNumber));
62 
63  auto& tm = mixedModel.nModel(subModelNumber);
64  try
65  {
66  auto& sm = dynamic_cast<const SubstitutionModelInterface&>(tm);
67  subModel_ = std::unique_ptr<SubstitutionModelInterface>(sm.clone());
68  subModel_->setNamespace(getNamespace());
69  subModel_->setRate(1);
70  addParameters_(subModel_->getParameters());
71  }
72  catch (bad_cast&)
73  {
74  throw Exception("FromMixtureSubstitutionModel::FromMixtureSubstitutionModel : model with number " + TextTools::toString(subModelNumber) + " is not a substitution model.");
75  }
76 }
77 
78 
79 /******************************************************************************/
80 
88  subModel_(fmsm.subModel_->clone()),
89  mixtName_(fmsm.mixtName_)
90 {}
91 
92 
93 /******************************************************************************/
94 
96 {
98 
99  subModel_.reset(fmsm.subModel_->clone());
100  mixtName_ = fmsm.mixtName_;
101 
102  return *this;
103 }
void addParameters_(const ParameterList &parameters)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
std::string getNamespace() const override
Abstract class of Wrapping model class, where all methods are redirected from model().
Model taken from a SubModel of a Mixture of SubstitutionModels.
FromMixtureSubstitutionModel & operator=(const FromMixtureSubstitutionModel &fmsm)
std::unique_ptr< SubstitutionModelInterface > subModel_
The subModel taken from the AbstractTotallyWrappedSubstitutionModel.
std::string mixtName_
The name of the mixture model (for io purpose).
FromMixtureSubstitutionModel(const MixedTransitionModelInterface &mixedModel, const std::string &subModelName, const std::string &mixtDesc)
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual const TransitionModelInterface & nModel(size_t i) const =0
Returns a specific model from the mixture.
virtual size_t getNumberOfModels() const =0
virtual const TransitionModelInterface & model(const std::string &name) const =0
Access the submodel with the given name.
Interface for all substitution models.
std::string toString(T t)
Defines the basic types of data flow nodes.