bpp-phyl  2.1.0
Bpp/Phyl/Model/Codon/YNGKP_M1.cpp
Go to the documentation of this file.
00001 //
00002 // File: YNGKP_M1.cpp
00003 // Created by:  Laurent Gueguen
00004 // Created on: May 2010
00005 //
00006 
00007 /*
00008    Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
00009    This software is a computer program whose purpose is to provide classes
00010    for phylogenetic data analysis.
00011 
00012    This software is governed by the CeCILL  license under French law and
00013    abiding by the rules of distribution of free software.  You can  use,
00014    modify and/ or redistribute the software under the terms of the CeCILL
00015    license as circulated by CEA, CNRS and INRIA at the following URL
00016    "http://www.cecill.info".
00017 
00018    As a counterpart to the access to the source code and  rights to copy,
00019    modify and redistribute granted by the license, users are provided only
00020    with a limited warranty  and the software's author,  the holder of the
00021    economic rights,  and the successive licensors  have only  limited
00022    liability.
00023 
00024    In this respect, the user's attention is drawn to the risks associated
00025    with loading,  using,  modifying and/or developing or reproducing the
00026    software by the user in light of its specific status of free software,
00027    that may mean  that it is complicated to manipulate,  and  that  also
00028    therefore means  that it is reserved for developers  and  experienced
00029    professionals having in-depth computer knowledge. Users are therefore
00030    encouraged to load and test the software's suitability as regards their
00031    requirements in conditions enabling the security of their systems and/or
00032    data to be ensured and,  more generally, to use and operate it in the
00033    same conditions as regards security.
00034 
00035    The fact that you are presently reading this means that you have had
00036    knowledge of the CeCILL license and that you accept its terms.
00037  */
00038 
00039 #include "YNGKP_M1.h"
00040 #include "YN98.h"
00041 
00042 #include <Bpp/Numeric/NumConstants.h>
00043 #include <Bpp/Numeric/Prob/SimpleDiscreteDistribution.h>
00044 
00045 using namespace bpp;
00046 
00047 using namespace std;
00048 
00049 /******************************************************************************/
00050 
00051 YNGKP_M1::YNGKP_M1(const GeneticCode* gc, FrequenciesSet* codonFreqs) :
00052   AbstractBiblioMixedSubstitutionModel("YNGKP_M1."),
00053   pmixmodel_(0),
00054   synfrom_(-1),
00055   synto_(-1)
00056 {
00057   // build the submodel
00058 
00059   vector<double> v1, v2;
00060   v1.push_back(0.5); v1.push_back(1);
00061   v2.push_back(0.5); v2.push_back(0.5);
00062 
00063   SimpleDiscreteDistribution* psdd = new SimpleDiscreteDistribution(v1, v2);
00064 
00065   map<string, DiscreteDistribution*> mpdd;
00066   mpdd["omega"] = psdd;
00067 
00068   pmixmodel_.reset(new MixtureOfASubstitutionModel(gc->getSourceAlphabet(), new YN98(gc, codonFreqs), mpdd));
00069   delete psdd;
00070 
00071   // map the parameters
00072 
00073   lParPmodel_.addParameters(pmixmodel_->getParameters());
00074 
00075   vector<std::string> v = dynamic_cast<YN98*>(pmixmodel_->getNModel(0))->getFrequenciesSet()->getParameters().getParameterNames();
00076 
00077   for (size_t i = 0; i < v.size(); i++)
00078   {
00079     mapParNamesFromPmodel_[v[i]] = v[i].substr(5);
00080   }
00081 
00082   mapParNamesFromPmodel_["YN98.kappa"] = "kappa";
00083   mapParNamesFromPmodel_["YN98.omega_Simple.V1"] = "omega";
00084   mapParNamesFromPmodel_["YN98.omega_Simple.theta1"] = "p0";
00085 
00086   // specific parameters
00087 
00088   string st;
00089   for (map<string, string>::iterator it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++)
00090   {
00091     st = pmixmodel_->getParameterNameWithoutNamespace(it->first);
00092     if (st != "omega_Simple.V1")
00093     {
00094       addParameter_(new Parameter("YNGKP_M1." + it->second, pmixmodel_->getParameterValue(st),
00095                               pmixmodel_->getParameter(st).hasConstraint() ? pmixmodel_->getParameter(st).getConstraint()->clone() : 0, true));
00096     }
00097   }
00098 
00099   addParameter_(new Parameter("YNGKP_M1.omega", 0.5, new IntervalConstraint(NumConstants::MILLI(), 1, true, false, NumConstants::MILLI()), true));
00100 
00101   // look for synonymous codons
00102   for (synfrom_ = 1; synfrom_ < static_cast<int>(gc->getSourceAlphabet()->getSize()); synfrom_++)
00103   {
00104     for (synto_ = 0; synto_ < synfrom_; synto_++)
00105     {
00106       if ((gc->areSynonymous(synfrom_, synto_))
00107           && (pmixmodel_->getNModel(0)->Qij(synfrom_, synto_) != 0)
00108           && (pmixmodel_->getNModel(1)->Qij(synfrom_, synto_) != 0))
00109         break;
00110     }
00111     if (synto_ < synfrom_)
00112       break;
00113   }
00114 
00115   if (synto_ == static_cast<int>(gc->getSourceAlphabet()->getSize()))
00116     throw Exception("Impossible to find synonymous codons");
00117 
00118   // update matrice
00119 
00120   updateMatrices();
00121 }
00122 
00123 YNGKP_M1::YNGKP_M1(const YNGKP_M1& mod2) : AbstractBiblioMixedSubstitutionModel(mod2),
00124   pmixmodel_(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)),
00125   synfrom_(mod2.synfrom_),
00126   synto_(mod2.synto_)
00127 {}
00128 
00129 YNGKP_M1& YNGKP_M1::operator=(const YNGKP_M1& mod2)
00130 {
00131   AbstractBiblioSubstitutionModel::operator=(mod2);
00132 
00133   pmixmodel_.reset(new MixtureOfASubstitutionModel(*mod2.pmixmodel_));
00134   synfrom_ = mod2.synfrom_;
00135   synto_ = mod2.synto_;
00136 
00137   return *this;
00138 }
00139 
00140 YNGKP_M1::~YNGKP_M1() {}
00141 
00142 void YNGKP_M1::updateMatrices()
00143 {
00144   AbstractBiblioSubstitutionModel::updateMatrices();
00145 
00146   // homogeneization of the synonymous substitution rates
00147 
00148   Vdouble vd;
00149 
00150   vd.push_back(1. / pmixmodel_->getNModel(0)->Qij(synfrom_, synto_));
00151   vd.push_back(1. / pmixmodel_->getNModel(1)->Qij(synfrom_, synto_));
00152 
00153   pmixmodel_->setVRates(vd);
00154 }
00155 
 All Classes Namespaces Files Functions Variables Typedefs Friends