|
bpp-phyl
2.1.0
|
00001 // 00002 // File: YNGKP_M2.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_M2.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_M2::YNGKP_M2(const GeneticCode* gc, FrequenciesSet* codonFreqs) : 00052 AbstractBiblioMixedSubstitutionModel("YNGKP_M2."), 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); v1.push_back(2); 00061 v2.push_back(0.333333); v2.push_back(0.333333); v2.push_back(0.333334); 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 // mapping the parameters 00072 00073 ParameterList pl = pmixmodel_->getParameters(); 00074 for (unsigned int i = 0; i < pl.size(); i++) 00075 { 00076 lParPmodel_.addParameter(Parameter(pl[i])); 00077 } 00078 00079 vector<std::string> v = dynamic_cast<YN98*>(pmixmodel_->getNModel(0))->getFrequenciesSet()->getParameters().getParameterNames(); 00080 00081 for (size_t i = 0; i < v.size(); i++) 00082 { 00083 mapParNamesFromPmodel_[v[i]] = getParameterNameWithoutNamespace("YNGKP_M2." + v[i].substr(5)); 00084 } 00085 00086 mapParNamesFromPmodel_["YN98.kappa"] = "kappa"; 00087 mapParNamesFromPmodel_["YN98.omega_Simple.V1"] = "omega0"; 00088 mapParNamesFromPmodel_["YN98.omega_Simple.theta1"] = "theta1"; 00089 mapParNamesFromPmodel_["YN98.omega_Simple.V3"] = "omega2"; 00090 mapParNamesFromPmodel_["YN98.omega_Simple.theta2"] = "theta2"; 00091 00092 // specific parameters 00093 00094 string st; 00095 for (map<string, string>::iterator it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++) 00096 { 00097 st = pmixmodel_->getParameterNameWithoutNamespace(it->first); 00098 if (it->second.substr(0, 5) != "omega") 00099 addParameter_(new Parameter("YNGKP_M2." + it->second, pmixmodel_->getParameterValue(st), 00100 pmixmodel_->getParameter(st).hasConstraint() ? pmixmodel_->getParameter(st).getConstraint()->clone() : 0, true)); 00101 } 00102 00103 addParameter_(new Parameter("YNGKP_M2.omega0", 0.5, new IntervalConstraint(NumConstants::MILLI(), 1, true, false), true)); 00104 00105 addParameter_(new Parameter("YNGKP_M2.omega2", 2, new IntervalConstraint(1, 999, false, false, NumConstants::MILLI()), true)); 00106 00107 // look for synonymous codons 00108 for (synfrom_ = 1; synfrom_ < (int)gc->getSourceAlphabet()->getSize(); synfrom_++) 00109 { 00110 for (synto_ = 0; synto_ < synfrom_; synto_++) 00111 { 00112 if ((gc->areSynonymous(synfrom_, synto_)) 00113 && (pmixmodel_->getNModel(0)->Qij(synfrom_, synto_) != 0) 00114 && (pmixmodel_->getNModel(1)->Qij(synfrom_, synto_) != 0)) 00115 break; 00116 } 00117 if (synto_ < synfrom_) 00118 break; 00119 } 00120 00121 if (synto_ == (int)gc->getSourceAlphabet()->getSize()) 00122 throw Exception("Impossible to find synonymous codons"); 00123 00124 // update Matrices 00125 00126 updateMatrices(); 00127 } 00128 00129 YNGKP_M2::YNGKP_M2(const YNGKP_M2& mod2) : AbstractBiblioMixedSubstitutionModel(mod2), 00130 pmixmodel_(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)), 00131 synfrom_(mod2.synfrom_), 00132 synto_(mod2.synto_) 00133 {} 00134 00135 YNGKP_M2& YNGKP_M2::operator=(const YNGKP_M2& mod2) 00136 { 00137 AbstractBiblioMixedSubstitutionModel::operator=(mod2); 00138 00139 pmixmodel_.reset(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)); 00140 synfrom_ = mod2.synfrom_; 00141 synto_ = mod2.synto_; 00142 00143 return *this; 00144 } 00145 00146 YNGKP_M2::~YNGKP_M2() {} 00147 00148 void YNGKP_M2::updateMatrices() 00149 { 00150 AbstractBiblioSubstitutionModel::updateMatrices(); 00151 00152 // homogeneization of the synonymous substittion rates 00153 00154 Vdouble vd; 00155 00156 vd.push_back(1 / pmixmodel_->getNModel(0)->Qij(synfrom_, synto_)); 00157 vd.push_back(1 / pmixmodel_->getNModel(1)->Qij(synfrom_, synto_)); 00158 vd.push_back(1 / pmixmodel_->getNModel(2)->Qij(synfrom_, synto_)); 00159 00160 pmixmodel_->setVRates(vd); 00161 } 00162