3
// Created by: Laurent Gueguen
4
// Created on: May 2010
8
Copyright or © or Copr. CNRS, (November 16, 2004)
9
This software is a computer program whose purpose is to provide classes
10
for phylogenetic data analysis.
12
This software is governed by the CeCILL license under French law and
13
abiding by the rules of distribution of free software. You can use,
14
modify and/ or redistribute the software under the terms of the CeCILL
15
license as circulated by CEA, CNRS and INRIA at the following URL
16
"http://www.cecill.info".
18
As a counterpart to the access to the source code and rights to copy,
19
modify and redistribute granted by the license, users are provided only
20
with a limited warranty and the software's author, the holder of the
21
economic rights, and the successive licensors have only limited
24
In this respect, the user's attention is drawn to the risks associated
25
with loading, using, modifying and/or developing or reproducing the
26
software by the user in light of its specific status of free software,
27
that may mean that it is complicated to manipulate, and that also
28
therefore means that it is reserved for developers and experienced
29
professionals having in-depth computer knowledge. Users are therefore
30
encouraged to load and test the software's suitability as regards their
31
requirements in conditions enabling the security of their systems and/or
32
data to be ensured and, more generally, to use and operate it in the
33
same conditions as regards security.
35
The fact that you are presently reading this means that you have had
36
knowledge of the CeCILL license and that you accept its terms.
41
#include "FrequenciesSet.h"
43
#include <Bpp/Numeric/Prob.all>
44
#include <Bpp/Text/TextTools.h>
50
/******************************************************************************/
52
YNGKP_M8::YNGKP_M8(const GeneticCode* gc, FrequenciesSet* codonFreqs, unsigned int nbclass) :
53
AbstractMixedSubstitutionModel(gc->getSourceAlphabet(), "YNGKP_M8."), pmixmodel_(0),
54
synfrom_(-1), synto_(-1),
55
mapParNamesFromPmodel_(), lParPmodel_()
58
throw Exception("Bad number of classes for model YNGKP_M8: " + TextTools::toString(nbclass));
62
BetaDiscreteDistribution* pbdd=new BetaDiscreteDistribution(nbclass,2,2);
64
vector<double> val; val.push_back(2);
65
vector<double> prob; prob.push_back(1);
66
SimpleDiscreteDistribution* psdd=new SimpleDiscreteDistribution(val,prob);
68
vector<DiscreteDistribution*> v_distr;
69
v_distr.push_back(pbdd); v_distr.push_back(psdd);
70
prob.clear(); prob.push_back(0.5); prob.push_back(0.5);
72
MixtureOfDiscreteDistributions* pmodd=new MixtureOfDiscreteDistributions(v_distr, prob);
74
map<string, DiscreteDistribution*> mpdd;
77
pmixmodel_= new MixtureOfASubstitutionModel(gc->getSourceAlphabet(),
78
new YN98(gc, codonFreqs),
82
// mapping the parameters
84
ParameterList pl=pmixmodel_->getParameters();
85
for (unsigned int i=0;i<pl.size();i++)
86
lParPmodel_.addParameter(Parameter(pl[i]));
88
vector<std::string> v=dynamic_cast<YN98*>(pmixmodel_->getNModel(0))->getFreq().getParameters().getParameterNames();
90
for (unsigned int i=0;i<v.size();i++)
91
mapParNamesFromPmodel_[v[i]]=getParameterNameWithoutNamespace("YNGKP_M8."+v[i].substr(5));
93
mapParNamesFromPmodel_["YN98.kappa"]="kappa";
94
mapParNamesFromPmodel_["YN98.omega_Mixture.theta1"]="p0";
95
mapParNamesFromPmodel_["YN98.omega_Mixture.1_Beta.alpha"]="p";
96
mapParNamesFromPmodel_["YN98.omega_Mixture.1_Beta.beta"]="q";
97
mapParNamesFromPmodel_["YN98.omega_Mixture.2_Simple.V1"]="omegas";
99
// specific parameters
102
for (map<string,string>::iterator it=mapParNamesFromPmodel_.begin(); it!= mapParNamesFromPmodel_.end(); it++){
103
st=pmixmodel_->getParameterNameWithoutNamespace(it->first);
104
if (it->second!="omegas")
105
addParameter_(Parameter("YNGKP_M8."+it->second, pmixmodel_->getParameterValue(st),
106
pmixmodel_->getParameter(st).hasConstraint()? pmixmodel_->getParameter(st).getConstraint()->clone():0,true));
109
addParameter_(Parameter("YNGKP_M8.omegas",2.,new ExcludingPositiveReal(1),true));
111
// look for synonymous codons
112
for (synfrom_=1;synfrom_<(int)gc->getSourceAlphabet()->getSize();synfrom_++){
113
for (synto_=0;synto_<synfrom_;synto_++)
114
if ((gc->areSynonymous(synfrom_,synto_))
115
&& (pmixmodel_->getNModel(0)->Qij(synfrom_,synto_)!=0)
116
&& (pmixmodel_->getNModel(1)->Qij(synfrom_,synto_)!=0))
122
if (synto_==(int)gc->getSourceAlphabet()->getSize())
123
throw Exception("Impossible to find synonymous codons");
129
YNGKP_M8::YNGKP_M8(const YNGKP_M8& mod2) : AbstractMixedSubstitutionModel(mod2),
130
pmixmodel_(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)),
131
synfrom_(mod2.synfrom_), synto_(mod2.synto_),
132
mapParNamesFromPmodel_(mod2.mapParNamesFromPmodel_),
133
lParPmodel_(mod2.lParPmodel_)
138
YNGKP_M8& YNGKP_M8::operator=(const YNGKP_M8& mod2)
140
AbstractMixedSubstitutionModel::operator=(mod2);
142
pmixmodel_=new MixtureOfASubstitutionModel(*mod2.pmixmodel_);
143
mapParNamesFromPmodel_=mod2.mapParNamesFromPmodel_;
144
lParPmodel_=mod2.lParPmodel_;
145
synfrom_=mod2.synfrom_;
151
YNGKP_M8::~YNGKP_M8()
157
void YNGKP_M8::updateMatrices()
159
map<string,string>::iterator it;
161
for (it=mapParNamesFromPmodel_.begin();it!=mapParNamesFromPmodel_.end();it++)
162
lParPmodel_.setParameterValue(it->first,getParameter(it->second).getValue());
164
pmixmodel_->matchParametersValues(lParPmodel_);
166
// homogeneization of the synonymous substittion rates
170
for (unsigned int i=0;i<pmixmodel_->getNumberOfModels();i++)
171
vd.push_back(1/pmixmodel_->getNModel(i)->Qij(synfrom_,synto_));
173
pmixmodel_->setVRates(vd);
176
void YNGKP_M8::setFreq(std::map<int,double>& m)
178
pmixmodel_->setFreq(m);
179
map<string,string>::iterator it;
182
for (it=mapParNamesFromPmodel_.begin();it!=mapParNamesFromPmodel_.end();it++)
183
pl.addParameter(Parameter(getNamespace()+it->second,pmixmodel_->getParameterValue(it->first)));
185
matchParametersValues(pl);