~ubuntu-branches/ubuntu/saucy/libbpp-phyl/saucy

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Julien Dutheil
  • Date: 2013-02-09 16:00:00 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130209160000-5v65ba68z8032nzj
Tags: 2.0.3-1
* Reorganized model hierarchy
* New pairwise models
* Several bugs fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
//
6
6
 
7
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
 
*/
 
8
   Copyright or © or Copr. Bio++ Development Team, (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
38
 
39
39
#include "YN98.h"
 
40
#include "K80.h"
40
41
#include "FrequenciesSet.h"
 
42
#include <Bpp/Numeric/NumConstants.h>
41
43
 
42
44
using namespace bpp;
43
45
 
46
48
/******************************************************************************/
47
49
 
48
50
YN98::YN98(const GeneticCode* gc, FrequenciesSet* codonFreqs) :
49
 
  AbstractReversibleSubstitutionModel(gc->getSourceAlphabet(), "YN98."),
50
 
  pmodel_(gc, codonFreqs), mapParNamesFromPmodel_(), lParPmodel_()
 
51
  AbstractBiblioSubstitutionModel("YN98."),
 
52
  pmodel_(new CodonDistanceFrequenciesSubstitutionModel(gc, new K80(dynamic_cast<const CodonAlphabet*>(gc->getSourceAlphabet())->getNucleicAlphabet()), codonFreqs))
51
53
{
52
54
  addParameter_(Parameter("YN98.kappa", 1, &Parameter::R_PLUS_STAR));
53
 
  addParameter_(Parameter("YN98.omega", 1, &Parameter::R_PLUS_STAR));//new IncludingInterval(0.0001, 999), true));
 
55
  addParameter_(Parameter("YN98.omega", 1, new IncludingInterval(NumConstants::SMALL, 999), true));
54
56
 
55
 
  pmodel_.setNamespace("YN98.");
 
57
  pmodel_->setNamespace("YN98.");
56
58
  addParameters_(codonFreqs->getParameters());
57
59
 
58
 
  lParPmodel_.addParameters(pmodel_.getParameters());
59
 
  
60
 
  vector<std::string> v=pmodel_.getFreq().getParameters().getParameterNames();
61
 
 
62
 
  for (unsigned int i=0;i<v.size();i++)
63
 
    mapParNamesFromPmodel_[v[i]]=getParameterNameWithoutNamespace(v[i]);
64
 
 
65
 
  mapParNamesFromPmodel_["YN98.123_K80.kappa"]="kappa";
66
 
  mapParNamesFromPmodel_["YN98.beta"]="omega";
67
 
  
 
60
  lParPmodel_.addParameters(pmodel_->getParameters());
 
61
 
 
62
  vector<std::string> v = pmodel_->getFreq().getParameters().getParameterNames();
 
63
 
 
64
  for (size_t i = 0; i < v.size(); i++)
 
65
  {
 
66
    mapParNamesFromPmodel_[v[i]] = getParameterNameWithoutNamespace(v[i]);
 
67
  }
 
68
  mapParNamesFromPmodel_["YN98.123_K80.kappa"] = "kappa";
 
69
  mapParNamesFromPmodel_["YN98.beta"] = "omega";
 
70
 
68
71
  updateMatrices();
69
72
}
70
73
 
71
 
void YN98::updateMatrices()
72
 
{
73
 
  for (unsigned int i=0;i<lParPmodel_.size();i++){
74
 
    lParPmodel_[i].setValue(getParameter(mapParNamesFromPmodel_[lParPmodel_[i].getName()]).getValue());}
75
 
 
76
 
  pmodel_.matchParametersValues(lParPmodel_);
77
 
}
78
 
 
79
 
void YN98::setFreq(std::map<int, double>& m)
80
 
{
81
 
  pmodel_.setFreq(m);
82
 
  matchParametersValues(pmodel_.getParameters());
83
 
}
84
 
 
85
 
void YN98::addRateParameter(){
86
 
  AbstractSubstitutionModel::addRateParameter();
87
 
  pmodel_.addRateParameter();
88
 
  mapParNamesFromPmodel_["YN98.rate"]="rate";
89
 
  lParPmodel_.reset();
90
 
  lParPmodel_.addParameters(pmodel_.getParameters());
 
74
 
 
75
YN98::YN98(const YN98& yn98) : AbstractBiblioSubstitutionModel(yn98),
 
76
  pmodel_(new CodonDistanceFrequenciesSubstitutionModel(*yn98.pmodel_))
 
77
{}
 
78
 
 
79
YN98& YN98::operator=(const YN98& yn98)
 
80
{
 
81
  AbstractBiblioSubstitutionModel::operator=(yn98);
 
82
  pmodel_ = new CodonDistanceFrequenciesSubstitutionModel(*yn98.pmodel_);
 
83
  return *this;
 
84
}
 
85
 
 
86
YN98::~YN98()
 
87
{
 
88
  if (pmodel_)
 
89
    delete pmodel_;
91
90
}