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

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/AbstractBiblioSubstitutionModel.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:
 
1
//
 
2
// File: AbstractBiblioSubstitutionModel.cpp
 
3
// Created by: Laurent Guéguen
 
4
// Created on: lundi 11 juillet 2011, à 21h 12
 
5
//
 
6
 
 
7
/*
 
8
   Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
 
9
 
 
10
   This software is a computer program whose purpose is to provide classes
 
11
   for phylogenetic data analysis.
 
12
 
 
13
   This software is governed by the CeCILL  license under French law and
 
14
   abiding by the rules of distribution of free software.  You can  use,
 
15
   modify and/ or redistribute the software under the terms of the CeCILL
 
16
   license as circulated by CEA, CNRS and INRIA at the following URL
 
17
   "http://www.cecill.info".
 
18
 
 
19
   As a counterpart to the access to the source code and  rights to copy,
 
20
   modify and redistribute granted by the license, users are provided only
 
21
   with a limited warranty  and the software's author,  the holder of the
 
22
   economic rights,  and the successive licensors  have only  limited
 
23
   liability.
 
24
 
 
25
   In this respect, the user's attention is drawn to the risks associated
 
26
   with loading,  using,  modifying and/or developing or reproducing the
 
27
   software by the user in light of its specific status of free software,
 
28
   that may mean  that it is complicated to manipulate,  and  that  also
 
29
   therefore means  that it is reserved for developers  and  experienced
 
30
   professionals having in-depth computer knowledge. Users are therefore
 
31
   encouraged to load and test the software's suitability as regards their
 
32
   requirements in conditions enabling the security of their systems and/or
 
33
   data to be ensured and,  more generally, to use and operate it in the
 
34
   same conditions as regards security.
 
35
 
 
36
   The fact that you are presently reading this means that you have had
 
37
   knowledge of the CeCILL license and that you accept its terms.
 
38
 */
 
39
 
 
40
#include "AbstractBiblioSubstitutionModel.h"
 
41
 
 
42
using namespace bpp;
 
43
using namespace std;
 
44
 
 
45
AbstractBiblioSubstitutionModel::AbstractBiblioSubstitutionModel(const std::string& prefix) : AbstractParameterAliasable(prefix), mapParNamesFromPmodel_(), lParPmodel_()
 
46
  {};
 
47
 
 
48
/******************************************************************************/
 
49
 
 
50
AbstractBiblioSubstitutionModel::AbstractBiblioSubstitutionModel(const AbstractBiblioSubstitutionModel& model) :
 
51
  AbstractParameterAliasable(model), 
 
52
  mapParNamesFromPmodel_(model.mapParNamesFromPmodel_),
 
53
  lParPmodel_(model.lParPmodel_)
 
54
{}    
 
55
 
 
56
/******************************************************************************/
 
57
 
 
58
AbstractBiblioSubstitutionModel& AbstractBiblioSubstitutionModel::operator=(const AbstractBiblioSubstitutionModel& model)
 
59
{
 
60
  AbstractParameterAliasable::operator=(model);
 
61
  mapParNamesFromPmodel_ = model.mapParNamesFromPmodel_;
 
62
  lParPmodel_            = model.lParPmodel_;
 
63
  return *this;
 
64
}
 
65
 
 
66
/******************************************************************************/
 
67
 
 
68
void AbstractBiblioSubstitutionModel::updateMatrices()
 
69
{
 
70
  for (unsigned int i = 0; i < lParPmodel_.size(); i++) {
 
71
    if (mapParNamesFromPmodel_.find(lParPmodel_[i].getName()) != mapParNamesFromPmodel_.end())
 
72
      lParPmodel_[i].setValue(getParameter(getParameterNameWithoutNamespace(mapParNamesFromPmodel_[lParPmodel_[i].getName()])).getValue());
 
73
  }
 
74
 
 
75
  getModel()->matchParametersValues(lParPmodel_);
 
76
}
 
77
 
 
78
/******************************************************************************/
 
79
 
 
80
void AbstractBiblioSubstitutionModel::addRateParameter()
 
81
{
 
82
  getModel()->addRateParameter();
 
83
  addParameter_(Parameter(getNamespace()+"rate", getModel()->getRate(), &Parameter::R_PLUS_STAR));
 
84
  mapParNamesFromPmodel_[getNamespace()+"rate"]="rate";
 
85
  lParPmodel_.reset();
 
86
  lParPmodel_.addParameters(getModel()->getParameters());
 
87
}
 
88
 
 
89
/******************************************************************************/
 
90
 
 
91
void AbstractBiblioSubstitutionModel::setFreq(std::map<int, double>& m)
 
92
{
 
93
  getModel()->setFreq(m);
 
94
 
 
95
  map<string,string>::iterator it;
 
96
  ParameterList pl;
 
97
  for (it=mapParNamesFromPmodel_.begin();it!=mapParNamesFromPmodel_.end();it++){
 
98
    pl.addParameter(Parameter(getNamespace()+it->second,getModel()->getParameterValue(getModel()->getParameterNameWithoutNamespace(it->first))));
 
99
  }
 
100
  
 
101
  matchParametersValues(pl);
 
102
}
 
103
 
 
104
 
 
105
void AbstractBiblioSubstitutionModel::setFreqFromData(const SequenceContainer& data, unsigned int pseudoCount)
 
106
{
 
107
  getModel()->setFreqFromData(data, pseudoCount);
 
108
  map<string,string>::iterator it;
 
109
  ParameterList pl;
 
110
  for (it=mapParNamesFromPmodel_.begin();it!=mapParNamesFromPmodel_.end();it++){
 
111
    pl.addParameter(Parameter(getNamespace()+it->second,getModel()->getParameterValue(getModel()->getParameterNameWithoutNamespace(it->first))));
 
112
  }
 
113
  
 
114
  matchParametersValues(pl);
 
115
}
 
116