comparison egglib/egglib-2.1.5/include/egglib-cpp/ParamSet.hpp @ 1:420b57c3c185 draft

Uploaded
author dereeper
date Fri, 10 Jul 2015 04:39:30 -0400
parents
children
comparison
equal deleted inserted replaced
0:3e19d0dfcf3e 1:420b57c3c185
1 /*
2 Copyright 2009-2010 Stéphane De Mita, Mathieu Siol
3
4 This file is part of the EggLib library.
5
6 EggLib is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 EggLib is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with EggLib. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef EGGLIB_PARAMSET_HPP
21 #define EGGLIB_PARAMSET_HPP
22
23
24 #include "DataMatrix.hpp"
25
26
27 namespace egglib {
28
29 class Change;
30 class Controller;
31
32
33 /** \brief Set of parameters
34 *
35 * \ingroup coalesce
36 *
37 */
38 class ParamSet {
39
40 public:
41
42 /** \brief Default constructor
43 *
44 * Initializes all parameters to reasonnable values (except
45 * that the sample size is null: 1 population, 0 samples,
46 * selfing rate of 0, recombination rate of 0, growth rate of
47 * 0, population size of 1 and no changes.
48 *
49 */
50 ParamSet();
51
52 /** \brief Destructor
53 *
54 */
55 ~ParamSet();
56
57 /** \brief Copy constructor
58 *
59 */
60 ParamSet(const ParamSet&);
61
62 /** \brief Assignment operator
63 *
64 */
65 ParamSet& operator=(const ParamSet&);
66
67 /** \brief Restores default value of all parameters
68 *
69 */
70 void reset();
71
72 /** \brief Gets the number of populations
73 *
74 */
75 unsigned int numberOfPopulations() const;
76
77 /** \brief Gets a pairwise migration rate
78 *
79 * It is allowed to access a diagonal value. Diagonal
80 * values contain the sum of values of the corresponding
81 * line (diagonal cell excepted, of course).
82 *
83 */
84 double pairwiseMigrationRate(unsigned int source, unsigned int dest) const;
85
86 /** \brief Sets a pairwise migration rate
87 *
88 * It is not allowed to set a value on the diagonal (this
89 * would raise an exception). The method takes care of
90 * modifying the diagonal accordingly (still this is not
91 * relevant for the client);
92 *
93 */
94 void pairwiseMigrationRate(unsigned int source, unsigned int dest, double value);
95
96 /** \brief Sets the migration rate for all matrix
97 *
98 */
99 void migrationRate(double value);
100
101 /** \brief Gets a population size
102 *
103 */
104 double populationSize(unsigned int populationIndex) const;
105
106 /** \brief Sets a population size
107 *
108 * The size must be strictly positive.
109 *
110 */
111 void populationSize(unsigned int populationIndex, double value);
112
113 /** \brief Gets a growth rate
114 *
115 */
116 double growthRate(unsigned int populationIndex) const;
117
118 /** \brief Sets a growth rate
119 *
120 */
121 void growthRate(unsigned int populationIndex, double value);
122
123 /** \brief Gets the recombination rate
124 *
125 */
126 double recombinationRate() const;
127
128 /** \brief Sets the recombination rate
129 *
130 */
131 void recombinationRate(double value);
132
133 /** \brief Gets the number of recombining segments
134 *
135 */
136 unsigned int numberOfSegments() const;
137
138 /** \brief Sets the number of recombining segments
139 *
140 */
141 void numberOfSegments(unsigned int value);
142
143 /** \brief Gets the selfing rate
144 *
145 */
146 double selfingRate() const;
147
148 /** \brief Sets the selfing rate
149 *
150 */
151 void selfingRate(double value);
152
153 /** \brief Adds a population to the model
154 *
155 * \param migr pairwise migration rate between other
156 * population and the new one.
157 *
158 * The parameters for the new population are equivalent to
159 * the default parameters.
160 *
161 */
162 void addPopulation(double migr);
163
164 /** \brief Adds a change
165 *
166 * The change can be of any type derived from Change. A
167 * const Change* must be passed, so ParamSet will neither
168 * modify or delete the object itself. All passed Change
169 * object must be kept available for use by ParamSet.
170 *
171 */
172 void addChange(const Change* change);
173
174 /** \brief Gets the date of the next change
175 *
176 * Returns -1 if no change is planned.
177 *
178 */
179 double nextChangeDate() const;
180
181 /** \brief Applies the next change event
182 *
183 * \param controller the Change event might need to have
184 * access to simulation controller (to trigger coalescent
185 * events, for example).
186 *
187 */
188 void nextChangeDo(Controller* controller);
189
190 /** \brief Gets the number of single sample from a population
191 *
192 */
193 unsigned int singles(unsigned int populationIndex) const;
194
195 /** \brief Sets the number of single sample from a population
196 *
197 */
198 void singles(unsigned int populationIndex, unsigned int value);
199
200 /** \brief Gets the number of double sample from a population
201 *
202 */
203 unsigned int doubles(unsigned int populationIndex) const;
204
205 /** \brief Sets the number of double sample from a population
206 *
207 */
208 void doubles(unsigned int populationIndex, unsigned int value);
209
210 /** \brief Computes the total number of samples
211 *
212 */
213 unsigned int numberOfSamples() const;
214
215 /** \brief Gives the date of the last size change
216 *
217 * \param populationIndex the index of the population.
218 * \return The date where the last change occurred, or 0. if
219 * no change occurred during the simulation.
220 *
221 */
222 double dateOfLastChange(unsigned int populationIndex) const;
223
224
225 /** \brief Sets the date of the last size change
226 *
227 * \param populationIndex the index of the population.
228 * \param date the date where the last change occurred, or 0.
229 * if no change occurred during the simulation.
230 *
231 */
232 void dateOfLastChange(unsigned int populationIndex, double date) const;
233
234
235 /** \brief Set groups labels
236 *
237 * Sets the group labels of the DataMatrix, according to the
238 * current state of population structure, and assuming that
239 * the DataMatrix was generated by the class Arg.
240 *
241 * \param dataMatrix the DataMatrix object to modify. The
242 * number of sequences must match the total number of samples
243 * defined by the ParamSet object this method is called on.
244 *
245 * \param labelIndividuals by default, labels the different
246 * samples depending on the population they come from (0
247 * being the label of the first population). If this flag is
248 * set to true, then the samples are labelled depending on
249 * the individual they come from, regardless of populations.
250 * In that case there can be only one or two genes for a
251 * given group label.
252 *
253 */
254 void setGroups(DataMatrix& dataMatrix, bool labelIndividuals=false);
255
256 private:
257
258 void clear();
259 void init();
260 void copy(const ParamSet&);
261
262 double _selfingRate;
263 double _recombinationRate;
264 unsigned int _numberOfSegments;
265 unsigned int _numberOfPopulations;
266 unsigned int* _singles;
267 unsigned int* _doubles;
268 double* _growthRates;
269 double* _populationSize;
270 double* _dateOfLastChange;
271 double** migrationMatrix;
272 unsigned int _numberOfChanges;
273 unsigned int nextChangeIndex;
274 Change const** changes;
275 };
276
277 }
278
279 #endif