~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/LLG08_EX3.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: LLG08_EX3.cpp
 
3
// Created by:  Laurent Gueguen
 
4
// Created on: jeudi 21 octobre 2010, à 13h 50
 
5
//
 
6
 
 
7
/*
 
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.
 
11
 
 
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". 
 
17
 
 
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
 
22
liability. 
 
23
 
 
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. 
 
34
 
 
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.
 
37
*/
 
38
 
 
39
#include "LLG08_EX3.h"
 
40
#include "YN98.h"
 
41
#include "FrequenciesSet.h"
 
42
 
 
43
#include <Bpp/Numeric/NumConstants.h>
 
44
#include <Bpp/Numeric/Prob/SimpleDiscreteDistribution.h>
 
45
 
 
46
using namespace bpp;
 
47
 
 
48
using namespace std;
 
49
 
 
50
/******************************************************************************/
 
51
 
 
52
LLG08_EX3::LLG08_EX3(const ProteicAlphabet* alpha) : 
 
53
  AbstractMixedSubstitutionModel(alpha, "LLG08_EX3."), pmixmodel_(0),
 
54
  mapParNamesFromPmodel_(), lParPmodel_()
 
55
{
 
56
  // build the submodel
 
57
 
 
58
  vector<SubstitutionModel*> vpSM;
 
59
  vpSM.push_back(new LLG08_EX3::EmbeddedModel(alpha,"EX3_Buried"));
 
60
  vpSM.push_back(new LLG08_EX3::EmbeddedModel(alpha,"EX3_Intermediate"));
 
61
  vpSM.push_back(new LLG08_EX3::EmbeddedModel(alpha,"EX3_HExposed"));
 
62
 
 
63
  Vdouble vrate, vproba;
 
64
  
 
65
  for (unsigned int i=0;i<vpSM.size();i++){
 
66
    vproba.push_back((dynamic_cast<LLG08_EX3::EmbeddedModel*> (vpSM[i]))->getProportion());
 
67
    vrate.push_back(vpSM[i]->getRate());
 
68
  }
 
69
 
 
70
  pmixmodel_= new MixtureOfSubstitutionModels(alpha, vpSM, vproba, vrate);
 
71
 
 
72
  string name,st;
 
73
  ParameterList pl=pmixmodel_->getParameters();
 
74
  for (unsigned int i=0;i<pl.size();i++){
 
75
    name=pl[i].getName();
 
76
    lParPmodel_.addParameter(Parameter(pl[i]));
 
77
    st=pmixmodel_->getParameterNameWithoutNamespace(name);
 
78
    mapParNamesFromPmodel_[name]=st;
 
79
    addParameter_(Parameter("LLG08_EX3."+st,
 
80
                            pmixmodel_->getParameterValue(st),
 
81
                            pmixmodel_->getParameter(st).hasConstraint()? pmixmodel_->getParameter(st).getConstraint()->clone():0,true));
 
82
  }
 
83
 
 
84
  updateMatrices();
 
85
}
 
86
 
 
87
LLG08_EX3::LLG08_EX3(const LLG08_EX3& mod2) : AbstractMixedSubstitutionModel(mod2),
 
88
                                              pmixmodel_(new MixtureOfSubstitutionModels(*mod2.pmixmodel_)),
 
89
                                              mapParNamesFromPmodel_(mod2.mapParNamesFromPmodel_),
 
90
                                              lParPmodel_(mod2.lParPmodel_)
 
91
{
 
92
  
 
93
}
 
94
 
 
95
LLG08_EX3& LLG08_EX3::operator=(const LLG08_EX3& mod2)
 
96
{
 
97
  AbstractMixedSubstitutionModel::operator=(mod2);
 
98
 
 
99
  pmixmodel_=new MixtureOfSubstitutionModels(*mod2.pmixmodel_);
 
100
  mapParNamesFromPmodel_=mod2.mapParNamesFromPmodel_;
 
101
  lParPmodel_=mod2.lParPmodel_;
 
102
  
 
103
  return *this;
 
104
}
 
105
 
 
106
LLG08_EX3::~LLG08_EX3()
 
107
{
 
108
  if (pmixmodel_)
 
109
    delete pmixmodel_;
 
110
}
 
111
 
 
112
void LLG08_EX3::updateMatrices()
 
113
{
 
114
  for (unsigned int i=0;i<lParPmodel_.size();i++)
 
115
    if (hasParameter(mapParNamesFromPmodel_[lParPmodel_[i].getName()]))
 
116
      lParPmodel_[i].setValue(getParameter(mapParNamesFromPmodel_[lParPmodel_[i].getName()]).getValue());
 
117
  
 
118
  pmixmodel_->matchParametersValues(lParPmodel_);
 
119
}
 
120
 
 
121
void LLG08_EX3::setFreq(std::map<int,double>& m){
 
122
  pmixmodel_->setFreq(m);
 
123
  matchParametersValues(pmixmodel_->getParameters());
 
124
}
 
125
 
 
126
void LLG08_EX3::setVRates(Vdouble & vd){
 
127
  pmixmodel_->setVRates(vd);
 
128
  matchParametersValues(pmixmodel_->getParameters());
 
129
}
 
130
 
 
131
/**************** sub model classes *///////////
 
132
 
 
133
LLG08_EX3::EmbeddedModel::EmbeddedModel(const ProteicAlphabet* alpha, string name) :
 
134
  AbstractReversibleSubstitutionModel(alpha, ""), proportion_(1), name_(name)
 
135
{
 
136
#include "__LLG08_EX3ExchangeabilityCode"
 
137
#include "__LLG08_EX3FrequenciesCode"
 
138
#include "__LLG08_EX3RatesProps"
 
139
  updateMatrices();
 
140
}
 
141
 
 
142
 
 
143