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

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/CodonNeutralReversibleSubstitutionModel.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: CodonReversibleSubstitutionModel.cpp
 
3
// Created by:  Laurent Gueguen
 
4
// Created on: Feb 2009
 
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 "CodonNeutralReversibleSubstitutionModel.h"
 
40
 
 
41
 
 
42
using namespace bpp;
 
43
 
 
44
using namespace std;
 
45
 
 
46
/******************************************************************************/
 
47
 
 
48
CodonNeutralReversibleSubstitutionModel::CodonNeutralReversibleSubstitutionModel(
 
49
    const CodonAlphabet* palph,
 
50
    NucleotideSubstitutionModel* pmod1) :
 
51
  AbstractCodonReversibleSubstitutionModel(palph, pmod1, "CodonNeutral.")
 
52
{
 
53
  int i;
 
54
 
 
55
  // relative rates
 
56
  for (i = 0; i < 2; i++)
 
57
  {
 
58
    addParameter_(Parameter("CodonNeutral.relrate" + TextTools::toString(i + 1), 1.0 / (3 - i), &Parameter::PROP_CONSTRAINT_EX));
 
59
  }
 
60
 
 
61
  updateMatrices();
 
62
}
 
63
 
 
64
CodonNeutralReversibleSubstitutionModel::CodonNeutralReversibleSubstitutionModel(const CodonAlphabet* palph,
 
65
                                                                                 NucleotideSubstitutionModel* pmod1,
 
66
                                                                                 NucleotideSubstitutionModel* pmod2,
 
67
                                                                                 NucleotideSubstitutionModel* pmod3) : AbstractCodonReversibleSubstitutionModel(palph, pmod1, pmod2, pmod3, "CodonNeutral.")
 
68
{
 
69
   int i;
 
70
 
 
71
  // relative rates
 
72
  for (i = 0; i < 2; i++)
 
73
  {
 
74
    addParameter_(Parameter("CodonNeutral.relrate" + TextTools::toString(i+1), 1.0 / (3 - i),&Parameter::PROP_CONSTRAINT_EX));
 
75
  }
 
76
 
 
77
  updateMatrices();
 
78
}
 
79
 
 
80
string CodonNeutralReversibleSubstitutionModel::getName() const
 
81
{
 
82
  string s = "CodonNeutralReversibleSubstitutionModel model:";
 
83
  for (size_t i = 0; i < VSubMod_.size(); i++)
 
84
  {
 
85
    s += " " + VSubMod_[i]->getName();
 
86
  }
 
87
 
 
88
  return s;
 
89
}
 
90
 
 
91
void CodonNeutralReversibleSubstitutionModel::completeMatrices()
 
92
{
 
93
  unsigned int i, j;
 
94
  unsigned int salph = getNumberOfStates();
 
95
  
 
96
  const CodonAlphabet* ca = dynamic_cast<const CodonAlphabet*>(alphabet_);
 
97
 
 
98
  for (i = 0; i < salph; i++)
 
99
  {
 
100
    for (j = 0; j < salph; j++)
 
101
    {
 
102
      if (ca->isStop(i) || ca->isStop(j))
 
103
      {
 
104
        generator_(i,j) = 0;
 
105
      }
 
106
    }
 
107
  }
 
108
}
 
109
 
 
110
 
 
111
void CodonNeutralReversibleSubstitutionModel::updateMatrices()
 
112
{
 
113
  int i, nbmod = VSubMod_.size();
 
114
  double x;
 
115
  int k;
 
116
  for (k = nbmod - 1; k >= 0; k--)
 
117
  {
 
118
    x = 1.0;
 
119
    for (i = 0; i < k; i++)
 
120
    {
 
121
      x *= 1 - getParameterValue("relrate" + TextTools::toString(i + 1));
 
122
    }
 
123
    if (k != nbmod - 1)
 
124
      x *= getParameterValue("relrate" + TextTools::toString(k + 1));
 
125
    Vrate_[k] = x;
 
126
  }
 
127
 
 
128
  AbstractCodonReversibleSubstitutionModel::updateMatrices();
 
129
}