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

« back to all changes in this revision

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

  • 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: AbstractWordSubstitutionModel.h
 
3
// Created by: Laurent Gueguen
 
4
// Created on: Jan 2009
 
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
#ifndef _ABSTRACTWORDSUBSTITUTIONMODEL_H_
 
41
#define _ABSTRACTWORDSUBSTITUTIONMODEL_H_
 
42
 
 
43
#include "AbstractSubstitutionModel.h"
 
44
 
 
45
// From the STL:
 
46
#include <vector>
 
47
 
 
48
namespace bpp
 
49
{
 
50
/**
 
51
 * @brief Abstract Basal class for words of substitution models.
 
52
 * @author Laurent Guéguen
 
53
 *
 
54
 * Objects of this class are built from several substitution models.
 
55
 * Each model corresponds to a position in the word. No model is
 
56
 * directly accessible. </p>
 
57
 *
 
58
 * Only substitutions with one letter changed are accepted. </p>
 
59
 *
 
60
 * There is one substitution per word per unit of time
 
61
 * on the equilibrium frequency, and each position has its specific rate.
 
62
 * For example, if there are @f$n@f$ models and \f$\rho_i\f$ is the rate of
 
63
 * model i (@f$\sum_{i=1}^{n} \rho_i = 1@f$):
 
64
 * @f{eqnarray*}
 
65
 * Q_{abc \rightarrow abd} &=& \rho_2 Q^{(2)}_{c \rightarrow d}\\
 
66
 * Q_{abc \rightarrow aed} &=& 0\\
 
67
 * Q_{abc \rightarrow abc} &=& \rho_0 Q^{(0)}_{a \rightarrow a} + \rho_1 Q^{(1)}_{b \rightarrow b} + \rho_2 Q^{(2)}_{c \rightarrow c})
 
68
 * @f}
 
69
 *
 
70
 * The parameters of this word model are the same as the ones of the
 
71
 * models used. Their names have a new suffix, "phi_" where i stands
 
72
 * for the position (i.e. the phase) in the word.
 
73
 *
 
74
 */
 
75
class AbstractWordSubstitutionModel :
 
76
    public virtual AbstractSubstitutionModel
 
77
{
 
78
private:
 
79
  /**
 
80
   * @ brief boolean flag to check if a specific WordAlphabet has been built
 
81
   */
 
82
  bool new_alphabet_;
 
83
 
 
84
protected:
 
85
  std::vector<SubstitutionModel*> VSubMod_;
 
86
  std::vector<std::string> VnestedPrefix_;
 
87
 
 
88
  std::vector<double> Vrate_;
 
89
 
 
90
protected:
 
91
  static Alphabet* extractAlph(const std::vector<SubstitutionModel*>& modelVector);
 
92
 
 
93
protected:
 
94
  void updateMatrices();
 
95
 
 
96
  /**
 
97
   * @brief Called by updateMatrices to handle specific modifications
 
98
   * for inheriting classes
 
99
   */
 
100
  virtual void completeMatrices() = 0;
 
101
 
 
102
public:
 
103
  /**
 
104
   * @brief Build a new AbstractWordSubstitutionModel object from a
 
105
   * vector of pointers to SubstitutionModels.
 
106
   *
 
107
   * @param modelVector the vector of substitution models to use, in
 
108
   *   the order of the positions in the words from left to right. All
 
109
   *   the models must be different objects to avoid parameters
 
110
   *   redundancy, otherwise only the first model is used. The used models
 
111
   *   are owned by the instance.
 
112
   * @param st the Namespace.
 
113
   */
 
114
  AbstractWordSubstitutionModel(
 
115
    const std::vector<SubstitutionModel*>& modelVector,
 
116
    const std::string& st);
 
117
 
 
118
  /**
 
119
   * @brief Build a new AbstractWordSubstitutionModel object from a
 
120
   * pointer to an SubstitutionModel and a number of
 
121
   * desired models.
 
122
   *
 
123
   * @param pmodel A pointer to the substitution model to use in all
 
124
   * the positions. It will be owned by the instance.
 
125
   * @param num The number of models involved.
 
126
   * @param st the Namespace.
 
127
   */
 
128
  AbstractWordSubstitutionModel(
 
129
    SubstitutionModel* pmodel,
 
130
    unsigned int num,
 
131
    const std::string& st);
 
132
 
 
133
  AbstractWordSubstitutionModel(const AbstractWordSubstitutionModel&);
 
134
 
 
135
  AbstractWordSubstitutionModel& operator=(const AbstractWordSubstitutionModel&);
 
136
 
 
137
  virtual ~AbstractWordSubstitutionModel();
 
138
 
 
139
  void setNamespace(const std::string& prefix);
 
140
 
 
141
protected:
 
142
  /**
 
143
   *@brief Constructor for the derived classes only
 
144
   */
 
145
  AbstractWordSubstitutionModel(const Alphabet* alph, const std::string&);
 
146
 
 
147
public:
 
148
  virtual unsigned int getNumberOfStates() const;
 
149
 
 
150
  /**
 
151
   *@brief Estimation of the parameters of the models so that the
 
152
   *equilibrium frequencies match the given ones.
 
153
   *
 
154
   *@param freqs  map of the frequencies
 
155
   *
 
156
   * When there is one submodel for all the positions, the submodel
 
157
   * parameters are fit on the means of the frequencies on each
 
158
   * position. Otherwise, each model is fit on the frequencies on its
 
159
   * corresponding position in the word.
 
160
   *
 
161
   **/
 
162
  
 
163
  virtual void setFreq(std::map<int, double>& freqs);
 
164
};
 
165
} // end of namespace bpp.
 
166
 
 
167
#endif  // ABSTRACTWORDSUBSTITUTIONMODEL_
 
168