comparison egglib/egglib-2.1.5/include/egglib-cpp/ChangeTypes.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_CHANGETYPES_HPP
21 #define EGGLIB_CHANGETYPES_HPP
22
23 #include "ParamSet.hpp"
24 #include "Controller.hpp"
25
26 namespace egglib {
27
28 /**********************************************************************/
29
30 /** \brief Pure virtual base class for parameter changes
31 *
32 * \ingroup coalesce
33 *
34 */
35 class Change {
36 public:
37
38 /** \brief Default constructor
39 *
40 * The default date is 0.
41 *
42 */
43 Change();
44
45 /** \brief Standard constructor
46 *
47 * \param date the event date.
48 *
49 */
50 Change(double date);
51
52 /// Gets the event date value
53 double date() const;
54
55 /// Sets the event date value
56 void date(double value);
57
58 /** \brief Applies the event
59 *
60 * \param paramSet the ParamSet instance to which the Change
61 * instance is attached.
62 * \param controller the Controller instance of the
63 * simulation.
64 *
65 */
66 virtual void apply(ParamSet* paramSet, Controller* controller) const = 0;
67
68 protected:
69 double _date;
70
71 };
72
73 /**********************************************************************/
74
75 /** \brief Pure virtual base class for single parameter changes
76 *
77 * \ingroup coalesce
78 *
79 */
80 class SingleParamChange : public Change {
81 public:
82
83 /** \brief Default constructor
84 *
85 * The default date is 0., the default parameter value is 0.
86 *
87 */
88 SingleParamChange();
89
90 /** \brief Standard constructor
91 *
92 * \param date the event date.
93 * \param value the parameter value.
94 *
95 */
96 SingleParamChange(double date, double value);
97
98 /// Gets the parameter value
99 double value() const;
100
101 /// Sets the parameter value
102 void value(double value);
103
104 protected:
105 double _value;
106
107 };
108
109 /**********************************************************************/
110
111 /** \brief Single parameter changes applied to a single population
112 *
113 * \ingroup coalesce
114 *
115 */
116 class PopulationParamChange : public SingleParamChange {
117 public:
118
119 /** \brief Default constructor
120 *
121 * The default date is 0., the default parameter value is 0.,
122 * the default population is 0
123 *
124 */
125 PopulationParamChange();
126
127 /** \brief Standard constructor
128 *
129 * \param date the event date.
130 * \param population the population index.
131 * \param value the parameter value.
132 *
133 */
134 PopulationParamChange(double date, unsigned int population, double value);
135
136 /// Gets the population index
137 unsigned int population() const;
138
139 /// Sets the population index
140 void population(unsigned int value);
141
142 protected:
143
144 unsigned int _population;
145
146 };
147
148
149 /**********************************************************************/
150
151 /** \brief Bottleneck event
152 *
153 * \ingroup coalesce
154 *
155 * The bottleneck parameter is its strength, corresponding to an
156 * amount of time where time is locked and only coalescences are
157 * allowed (resulting in a given - and random - number of
158 * instantaneous coalescence with branches).
159 *
160 */
161 class Bottleneck : public SingleParamChange {
162 public:
163 Bottleneck(double date, double param) : SingleParamChange(date, param) {}
164 void apply(ParamSet* paramSet, Controller* controller) const;
165 };
166
167 /**********************************************************************/
168
169 /** \brief Population-specific bottleneck event
170 *
171 * \ingroup coalesce
172 *
173 */
174 class PopulationBottleneck : public PopulationParamChange {
175 public:
176 PopulationBottleneck(double date, unsigned int population, double value) : PopulationParamChange(date, population, value) {}
177 void apply(ParamSet* paramSet, Controller* controller) const;
178 };
179
180
181 /**********************************************************************/
182
183 /** \brief Change of the size of all populations
184 *
185 * The parameter is the new size (applied to all populations)
186 *
187 * \ingroup coalesce
188 *
189 */
190 class AllPopulationSizeChange : public SingleParamChange {
191 public:
192 AllPopulationSizeChange(double date, double value) : SingleParamChange(date, value) {}
193 void apply(ParamSet* paramSet, Controller* controller) const;
194 };
195
196
197 /**********************************************************************/
198
199 /** \brief Change of a single population size
200 *
201 * \ingroup coalesce
202 *
203 */
204 class SinglePopulationSizeChange : public PopulationParamChange {
205 public:
206 SinglePopulationSizeChange(double date, unsigned int population, double value) : PopulationParamChange(date, population, value) {}
207 void apply(ParamSet* paramSet, Controller* controller) const;
208 };
209
210
211
212 /**********************************************************************/
213
214 /** \brief Change of the growth rate of all populations
215 *
216 * The parameter is the new rate (applied to all populations)
217 *
218 * \ingroup coalesce
219 *
220 */
221 class GrowthRateChange : public SingleParamChange {
222 public:
223 GrowthRateChange(double date, double value) : SingleParamChange(date, value) {}
224 void apply(ParamSet* paramSet, Controller* controller) const;
225 };
226
227
228 /**********************************************************************/
229
230 /** \brief Change of a single population's growth rate
231 *
232 * \ingroup coalesce
233 *
234 */
235 class PopulationGrowthRateChange : public PopulationParamChange {
236 public:
237 PopulationGrowthRateChange(double date, unsigned int population, double value) : PopulationParamChange(date, population, value) {}
238 void apply(ParamSet* paramSet, Controller* controller) const;
239 };
240
241 /**********************************************************************/
242
243 /** \brief Change of the selfing rate
244 *
245 * The parameter is the new rate
246 *
247 * \ingroup coalesce
248 *
249 */
250 class SelfingRateChange : public SingleParamChange {
251 public:
252 SelfingRateChange(double date, double value) : SingleParamChange(date, value) {}
253 void apply(ParamSet* paramSet, Controller* controller) const;
254 };
255
256 /**********************************************************************/
257
258 /** \brief Fusion of two populations
259 *
260 * \ingroup coalesce
261 *
262 */
263 class PopulationFusion : public Change {
264 public:
265 /** \brief Default constructor
266 *
267 * The default date is 0., the default mother is 0, the
268 * default daughter is 0.
269 *
270 */
271 PopulationFusion();
272
273 /** \brief Standard constructor
274 *
275 * \param date the date of the event.
276 * \param mother first population to merge.
277 * \param daughter second population to merge.
278 *
279 * A time date, all the lineages from the daughter population
280 * are moved to the mother population and all mutation rates
281 * to the daughter population are cancelled. This functions
282 * emulates a population split (forward in time).
283 *
284 */
285 PopulationFusion(double date, unsigned int mother, unsigned int daughter);
286
287 void apply(ParamSet* paramSet, Controller* controller) const;
288
289 /// Sets the daughter population
290 void daughter(unsigned int);
291
292 /// Gets the daughter population
293 unsigned int daughter() const;
294
295 /// Sets the mother population
296 void mother(unsigned int);
297
298 /// Gets the mother population
299 unsigned int mother() const;
300
301 protected:
302 unsigned int _mother;
303 unsigned int _daughter;
304 };
305
306
307 /**********************************************************************/
308
309 /** \brief Split of a population
310 *
311 * \ingroup coalesce
312 *
313 */
314 class PopulationSplit : public Change {
315 public:
316 /** \brief Default constructor
317 *
318 * The default date is 0., the default population is 0, the
319 * default probability is 0.5.
320 *
321 */
322 PopulationSplit();
323
324 /** \brief Standard constructor
325 *
326 * A the time given by date, the specified population is
327 * split in two. An additional population (whose index is
328 * incremented from the current total number of population)
329 * is created and lineages are randomly picked and moved to
330 * the new population. The parameter proba gives the
331 * probability that a lineage from the population number pop
332 * moves instantly to the new population. If proba is 0,
333 * the program emulates the creation of an empty population
334 * (thinking forward in time, this is a population
335 * extinction). In general, forward in time, this is a
336 * population fusion.
337 *
338 * \param date the date of the event.
339 * \param pop population index.
340 * \param proba the probability that lineages move to the
341 * new population.
342 *
343 */
344 PopulationSplit(double date, unsigned int pop, double proba);
345
346 void apply(ParamSet* paramSet, Controller* controller) const;
347
348 /// Gets the population index
349 unsigned int population() const;
350
351 /// Sets the population index
352 void population(unsigned int);
353
354 /// Gets the probability of instant migration
355 double probability() const;
356
357 /// Sets the probability of instant migration
358 void probability(double);
359
360 protected:
361 unsigned int _population;
362 double _probability;
363 };
364
365 /**********************************************************************/
366
367 /** \brief Change of the migration rate of all population pairs
368 *
369 * The parameter is the new rate (applied to all population pairs)
370 *
371 * \ingroup coalesce
372 *
373 */
374 class AllMigrationRateChange : public SingleParamChange {
375 public:
376 AllMigrationRateChange(double date, double value) : SingleParamChange(date, value) {}
377 void apply(ParamSet* paramSet, Controller* controller) const;
378 };
379
380 /**********************************************************************/
381
382 /** \brief Change of a single migration rate
383 *
384 * \ingroup coalesce
385 *
386 */
387 class SingleMigrationRateChange : public SingleParamChange {
388 public:
389 /** \brief Default constructor
390 *
391 * The default date is 0., the default parameter value is 0.,
392 * the default source population is 0, the default
393 * destination population 1.
394 *
395 */
396 SingleMigrationRateChange();
397
398 /** \brief Standard constructor
399 *
400 * \param date the date of the event.
401 * \param source index of the source population.
402 * \param dest index of the destination population.
403 * \param migr new value of the pairwise migration rate.
404 *
405 */
406 SingleMigrationRateChange(double date, unsigned int source, unsigned int dest, double migr);
407
408 /// Gets the source population index
409 unsigned source() const;
410
411 /// Sets the source population index
412 void source(unsigned int);
413
414 /// Gets the dest population index
415 unsigned dest() const;
416
417 /// Sets the dest population index
418 void dest(unsigned int);
419
420 void apply(ParamSet* paramSet, Controller* controller) const;
421
422 protected:
423 unsigned int _source;
424 unsigned int _dest;
425 };
426 }
427
428 #endif