bpp-phyl  2.2.0
AbstractBiblioSubstitutionModel.cpp
Go to the documentation of this file.
1 //
2 // File: AbstractBiblioSubstitutionModel.cpp
3 // Created by: Laurent Guéguen
4 // Created on: lundi 11 juillet 2011, à 21h 12
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
41 
42 using namespace bpp;
43 using namespace std;
44 
45 AbstractBiblioSubstitutionModel::AbstractBiblioSubstitutionModel(const std::string& prefix) : AbstractParameterAliasable(prefix),
46  mapParNamesFromPmodel_(),
47  lParPmodel_()
48 {}
49 
50 /******************************************************************************/
51 
53  AbstractParameterAliasable(model),
54  mapParNamesFromPmodel_(model.mapParNamesFromPmodel_),
55  lParPmodel_(model.lParPmodel_)
56 {}
57 
58 /******************************************************************************/
59 
61 {
62  AbstractParameterAliasable::operator=(model);
64  lParPmodel_ = model.lParPmodel_;
65  return *this;
66 }
67 
68 /******************************************************************************/
69 
71 {
72  for (size_t i = 0; i < lParPmodel_.size(); i++)
73  {
74  if (mapParNamesFromPmodel_.find(lParPmodel_[i].getName()) != mapParNamesFromPmodel_.end()) {
75  lParPmodel_[i].setValue(getParameter(getParameterNameWithoutNamespace(mapParNamesFromPmodel_[lParPmodel_[i].getName()])).getValue());
76  }
77  }
78 
79  getModel().matchParametersValues(lParPmodel_);
80 }
81 
82 /******************************************************************************/
83 
85 {
87  addParameter_(new Parameter(getNamespace() + "rate", getModel().getRate(), &Parameter::R_PLUS_STAR));
88  mapParNamesFromPmodel_[getNamespace() + "rate"] = "rate";
89  lParPmodel_.reset();
90  lParPmodel_.addParameters(getModel().getParameters());
91 }
92 
93 /******************************************************************************/
94 
95 void AbstractBiblioSubstitutionModel::setFreq(std::map<int, double>& m)
96 {
97  getModel().setFreq(m);
98 
99  map<string, string>::iterator it;
100  ParameterList pl;
101  for (it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++)
102  {
103  pl.addParameter(Parameter(getNamespace() + it->second, getModel().getParameterValue(getModel().getParameterNameWithoutNamespace(it->first))));
104  }
105 
106  matchParametersValues(pl);
107 }
108 
109 
110 void AbstractBiblioSubstitutionModel::setFreqFromData(const SequenceContainer& data, double pseudoCount)
111 {
112  getModel().setFreqFromData(data, pseudoCount);
113  map<string, string>::iterator it;
114  ParameterList pl;
115  for (it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++)
116  {
117  pl.addParameter(Parameter(getNamespace() + it->second, getModel().getParameterValue(getModel().getParameterNameWithoutNamespace(it->first))));
118  }
119 
120  matchParametersValues(pl);
121 }
122 
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
Partial implementation of the SubstitutionModel interface for models that are set for matching the bi...
STL namespace.
AbstractBiblioSubstitutionModel & operator=(const AbstractBiblioSubstitutionModel &model)
virtual void addRateParameter()=0
virtual void setFreqFromData(const SequenceContainer &data, double pseudoCount=0)=0
Set equilibrium frequencies equal to the frequencies estimated from the data.
virtual void setFreq(std::map< int, double > &frequencies)
Set equilibrium frequencies.
virtual std::string getName() const =0
Get the name of the model.
void setFreqFromData(const SequenceContainer &data, double pseudoCount=0)
Set equilibrium frequencies equal to the frequencies estimated from the data.
void setFreq(std::map< int, double > &frequ)
Set equilibrium frequencies.
virtual const SubstitutionModel & getModel() const =0