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

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/RN95s.h

  • 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: RN95s.h
 
3
// Created by: Laurent Guéguen
 
4
// Created on: samedi 12 mars 2011, à 06h 49
 
5
//
 
6
 
 
7
/*
 
8
  Copyright or © or Copr. CNRS, (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
#ifndef _RN95s_H_
 
41
#define _RN95s_H_
 
42
 
 
43
#include "NucleotideSubstitutionModel.h"
 
44
#include "AbstractSubstitutionModel.h"
 
45
 
 
46
#include <Bpp/Numeric/Constraints.h>
 
47
 
 
48
// From SeqLib:
 
49
#include <Bpp/Seq/Alphabet/NucleicAlphabet.h>
 
50
 
 
51
namespace bpp
 
52
{
 
53
 
 
54
  /**
 
55
   * @brief Intersection of models RN95 and L95.
 
56
   *
 
57
   * The two hypotheses are that the transversion rates are only
 
58
   * dependent of the target nucleotide, and strand symmetry.
 
59
   *
 
60
   * After normalization this model has 3 parameters:
 
61
   * \f[
 
62
   * Q= \frac 1P
 
63
   * \begin{pmatrix}
 
64
   * . & \gamma & \alpha & \delta \\
 
65
   * \delta & . &  \gamma & \beta \\
 
66
   * \beta & \gamma & . & \delta \\
 
67
   * \delta & \alpha & \gamma & .\\
 
68
   * \end{pmatrix}\f]
 
69
   *
 
70
   * so in the parametrization process we set: \f[\gamma+\delta=\frac 12\f]
 
71
   *
 
72
   * The stationnary distribution
 
73
   * \f[
 
74
   * \pi = \left(\pi_A, \pi_C, \pi_G, \pi_T\right)
 
75
   * \f]
 
76
   * is such as \f[\pi_A=\pi_T\f] and \f[\pi_C=\pi_G\f]. It can be computed analytically.
 
77
   *
 
78
   * We use as  parameters:
 
79
   *
 
80
   *\f[
 
81
   * \begin{cases}
 
82
   * \pi_A \in ]0;1/2[\\
 
83
   * \gamma \in ]0;1/2[\\
 
84
   * \alpha' > 1
 
85
   * \end{cases}
 
86
   * \f]
 
87
   *
 
88
   * where \f[\alpha'=\frac{2\alpha\pi_A+min(0.5-\pi_A,\gamma)}{0.5-\pi_A}\f].
 
89
   *
 
90
   * The generator is then computed as:
 
91
   *
 
92
   *\f[
 
93
   * \begin{cases}
 
94
   * \delta=\frac 12-\gamma\\
 
95
   * \alpha=\frac{\alpha'(0.5-\pi_A)-min(0.5-\pi_A,\gamma)}{2\pi_A}\\
 
96
   * \beta=\frac{\delta-2*\pi_A*(\alpha+\frac 12)}{2*\pi_A-1}\\
 
97
   * \end{cases}
 
98
   * \f]
 
99
   *
 
100
   * and \f[P\f] is set for normalization.
 
101
   *
 
102
   * The parameters are named \c "piA", \c "gamma", \c "alphaP".
 
103
   *
 
104
   * References:
 
105
   * - Rhetsky A. \& Ney M. (1995) MBE 12(1) 131-151.
 
106
   * - Lobry J R (1995), Journal_ Of Molecular Evolution_ 40 326-330.
 
107
   * - Schadt, Sinsheimer \& Lange (1998) Genome Research 8 222-233.
 
108
   */
 
109
  
 
110
  class RN95s:
 
111
    public virtual NucleotideSubstitutionModel,
 
112
    public AbstractSubstitutionModel
 
113
  {
 
114
  private:
 
115
    double alpha_, beta_, gamma_, delta_;
 
116
    double r_;
 
117
    /**
 
118
     * For calculation purposes as in Schadt & al. (with c1_=1)
 
119
     */
 
120
    double c3_, c4_, c8_;
 
121
    mutable RowMatrix<double> p_;
 
122
    mutable double exp1_,exp3_,l_;
 
123
 
 
124
  public:
 
125
    RN95s(
 
126
         const NucleicAlphabet* alphabet,
 
127
         double alpha = 1,
 
128
         double beta = 1,
 
129
         double gamma = 1,
 
130
         double delta = 1);
 
131
  
 
132
    virtual ~RN95s() {}
 
133
  
 
134
#ifndef NO_VIRTUAL_COV
 
135
    RN95s*
 
136
#else
 
137
    Clonable*
 
138
#endif
 
139
    clone() const { return new RN95s(*this); }
 
140
  
 
141
  public:
 
142
  public:
 
143
    double Pij_t    (int i, int j, double d) const;
 
144
    double dPij_dt  (int i, int j, double d) const;
 
145
    double d2Pij_dt2(int i, int j, double d) const;
 
146
    const Matrix<double>& getPij_t    (double d) const;
 
147
    const Matrix<double>& getdPij_dt  (double d) const;
 
148
    const Matrix<double>& getd2Pij_dt2(double d) const;
 
149
 
 
150
    std::string getName() const { return "RN95s"; }
 
151
  
 
152
    void updateMatrices();
 
153
  
 
154
    /**
 
155
     * @brief This method takes the average value between observed \f[\pi_A\f] and \f[\pi_T\f].
 
156
     */
 
157
    
 
158
    void setFreq(std::map<int, double>&);
 
159
  };
 
160
 
 
161
} //end of namespace bpp.
 
162
 
 
163
#endif  //_RN95s_H_
 
164