Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
ttbdmi.h
Go to the documentation of this file.
1
29#ifndef _TTDBMI_H_
30#define _TTDBMI_H_
31
32#include "ttrait.h"
33#include "types.h"
34#include "stathandler.h"
35#include "filehandler.h"
36#include "lifecycleevent.h"
37#include "metapop.h"
38#include "bitstring.h"
39#include "tmatrix.h"
40#include "Uniform.h"
41
42class TTBDMI_SH;
43class TTBDMI_FH;
44class TT_BDMI;
45// ------------------------------------------------------------------------------
46
47// TProtoBDMI
48
49// ------------------------------------------------------------------------------
50class TProtoBDMI : public TTProtoWithMap {
51
53
55 unsigned int _nb_locus;
56 double _mut_rate;
59 double* _init_freq;
61 static unsigned int _diploGenotTableCoding[3][3];
62
64 void (TT_BDMI::* _mutation_func_ptr) (void);
65 double (TT_BDMI::* _viability_func_ptr) (void);
66
70
71public:
72
73 TProtoBDMI();
74 TProtoBDMI(const TProtoBDMI& TP);
75 virtual ~TProtoBDMI();
76
77 int get_nb_locus ( ) {return _nb_locus;}
78 double get_mut_rate ( ) {return _mut_rate;}
79 bool isHaploid ( ) {return _isHaploid;}
80 void set_init_freq (double* val, unsigned int size);
81 double get_init_freq (unsigned int i) {return _init_freq[i];}
82 bool isInitSet ( ) {return _isInitSet;}
83
84 double getGenoFitnessHaplo (unsigned int row, unsigned int pos){
85 assert(pos < 4);
86 return _genoTable->get(row, pos);
87 }
88
89 double getGenoFitnessDiplo (unsigned int row, unsigned int posA, unsigned int posB)
90 {
91 return _genoTable->get(row, _diploGenotTableCoding[posA][posB] );
92 }
93
94 double getGenoFitnessDiplo (unsigned int row, unsigned int pos)
95 {
96 assert(pos < 9);
97 return _genoTable->get(row, pos);
98 }
99
100 void setGenoFitnessValue(unsigned int row, unsigned int geno, double value)
101 { _genoTable->set(row, geno, value); }
102
103 void showGenoTable (unsigned int nrows);
104
105 void inherit (sex_t SEX, bitstring* seq, bitstring** parent);
106
109 virtual void init () {setParameters();}
110 virtual TTrait* hatch ();
111 virtual TraitPrototype* clone () {return new TProtoBDMI(*this);}
112 virtual trait_t get_type () const {return _type;}
113
114 //implements StorageComponent
115 virtual void store_data (BinaryStorageBuffer* saver)
116 {
117 saver->store(&_nb_locus, sizeof(int));
118 saver->store(&_isHaploid, sizeof(bool));
119 }
120 virtual bool retrieve_data (BinaryStorageBuffer* reader);
121 //implements SimComponent
122 virtual bool setParameters ( );
123 virtual void loadFileServices ( FileServices* loader );
124 virtual void loadStatServices ( StatServices* loader );
125 virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
127
128};
129// ------------------------------------------------------------------------------
130
131// TT_BDMI
132
133// ------------------------------------------------------------------------------
134class TT_BDMI : public TTrait {
135
137
139
141
143
144 unsigned int _nb_locus;
145 double _mut_rate;
148
150 void (TT_BDMI::* _mutation_func_ptr) (void);
151 double (TT_BDMI::* _viability_func_ptr) (void);
152
153 static unsigned int *_recomb_template, *_rSites;
154 static unsigned char *_sites;
155 static unsigned int _haploGenotCoding[2][2];
156 static unsigned int _diploGenotCoding[2][2];
157
158public:
159 //cstor & dstor
163 {_sequence[0] = _sequence[1] = NULL;}
164
165 TT_BDMI(const TT_BDMI& T)
170 {_sequence[0] = _sequence[1] = NULL;}
171
172 virtual ~TT_BDMI() { }
173
176 void set_nb_locus (int val) {_nb_locus = val;}
177 void set_mut_rate (double val) {_mut_rate = val;}
178 void set_geno_rate (double val) {_genomic_mut_rate = val;}
179 void set_recomb_rate (double val) {_recomb_rate = val;}
180 void set_isHaploid (bool val) {_isHaploid = val;}
181 void set_inherit_func_ptr (void(TT_BDMI::* theFunc)(TTrait*, TTrait*))
182 {_inherit_func_ptr = theFunc;}
183 void set_mutation_func_ptr (void (TT_BDMI::* theFunc) (void))
184 {_mutation_func_ptr = theFunc;}
185 void set_viability_func_ptr (double (TT_BDMI::* theFunc) (void))
186 {_viability_func_ptr = theFunc;}
187
188 void set_proto (TProtoBDMI* proto) {_myProto = proto;}
190
191 void set_sequence (bitstring** seq);
192
193 //inheritance routines:
194 void inherit_haplo (TTrait* mother, TTrait* father);
195 void inherit_diplo (TTrait* mother, TTrait* father);
196
197 //mutation routines:
198 void mutate_haplo ( );
199 void mutate_diplo ( );
200
201 double viability_haplo ( );
202 double viability_diplo ( );
203
204 unsigned int get_num_mut_haplo (unsigned int loc) {return (*_sequence[0])[loc];}
205 unsigned int get_num_mut_diplo (unsigned int loc) {return (*_sequence[0])[loc]+(*_sequence[1])[loc];}
206
207
210 virtual void init ();
211 virtual void init_sequence ();
212 virtual void reset ();
213 virtual void inherit (TTrait* mother, TTrait* father){(this->* _inherit_func_ptr) (mother, father);}
214 virtual void mutate () {(this->*_mutation_func_ptr)();}
215 virtual void* set_trait (void* value) {return NULL;}
216 virtual void set_sequence (void** seq) {}
217 virtual void set_value () {_phenotype = (this->*_viability_func_ptr)();}
218 virtual void* getValue () const {return (void*)&_phenotype;}
219 virtual trait_t get_type () const {return _myProto->get_type();}
220 virtual void** get_sequence () const {return (void**)&_sequence[0];}
221 virtual double get_allele_value (int loc, int all);
222 virtual void set_allele_value (unsigned int locus, unsigned int allele, double value);
223 virtual void show_up ();
224
225 virtual TT_BDMI* clone () {return new TT_BDMI(*this);}
226 virtual TT_BDMI& operator= (const TTrait&);
227 virtual bool operator== (const TTrait&);
228 virtual bool operator!= (const TTrait&);
229 //implements StorableComponent:
230 virtual void store_data (BinaryStorageBuffer* saver);
231 virtual bool retrieve_data (BinaryStorageBuffer* reader);
233
234};
235
236// ------------------------------------------------------------------------------
237
238// TTBDMI_FH
239
240// ------------------------------------------------------------------------------
243class TTBDMI_FH : public TraitFileHandler< TProtoBDMI > {
244
245public:
246
248 virtual ~TTBDMI_FH ( ) { }
249
250 void write_haplo (Patch* patch, sex_t SEX, age_idx AGE, ofstream& FH);
251 void write_diplo (Patch* patch, sex_t SEX, age_idx AGE, ofstream& FH);
252
253 virtual void FHwrite ();
254 virtual void FHread (string& filename) {}
255
256};
257
258// ------------------------------------------------------------------------------
259
260// TTBDMI_SH
261
262// ------------------------------------------------------------------------------
266class TTBDMI_SH : public TraitStatHandler< TProtoBDMI, TTBDMI_SH > {
267
270
271public:
273 _patchFreq(0), _patchIcmp(0) {}
274
275 virtual ~TTBDMI_SH(){if(_patchFreq)delete[]_patchFreq;if(_patchIcmp)delete[]_patchIcmp;}
276
277 virtual bool setStatRecorders (std::string& token);
278
279 void addStats (age_t AGE);
280 void setAdultStats () ;
281 void setOffsprgStats ();
282 void setStats (age_idx agex, void(TTBDMI_SH::* cntFunc)(Patch*,sex_t,age_idx,double**,double**));
283 void countAllele_haplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab);
284 void countAllele_diplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab);
285 double getFreq () {return _freq;}
286 double getFreqIcmp () {return _freqIcomp;}
287 double getPatchFreq (unsigned int i) {return _patchFreq[i];}
288 double getPatchIcmp (unsigned int i) {return _patchIcmp[i];}
289
290};
291
292// ------------------------------------------------------------------------------
293
294// LCE_Init_BDMI
295
296// ------------------------------------------------------------------------------
300
302 unsigned int _nLocus;
303
304public:
305
306 LCE_Init_BDMI ( );
307
308 virtual ~LCE_Init_BDMI ( ) { }
309
310 bool setSpatialPattern(TMatrix& freq_mat, unsigned int patchNbr);
311 bool setPatchFreq(TMatrix& freq_mat,TMatrix& pat_mat, unsigned int patchNbr);
312 void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme);
313
314 //LifeCycleEvent implementation:
315 virtual void execute ();
316
317 virtual LifeCycleEvent* clone ( ) {return new LCE_Init_BDMI();}
318
319 virtual bool setParameters ();
320
321 //SimComponent implementation:
322 virtual void loadFileServices ( FileServices* loader ) {}
323 virtual void loadStatServices ( StatServices* loader ) {}
324 virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
325 virtual age_t removeAgeClass ( ) {return 0;}
326 virtual age_t addAgeClass ( ) {return 0;}
327 virtual age_t requiredAgeClass () {return 0;}
328};
329
330#endif
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:44
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.cc:16
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
Allelic frequency initialiser for the DBMI trait.
Definition: ttbdmi.h:299
virtual age_t removeAgeClass()
Definition: ttbdmi.h:325
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:955
virtual void loadFileServices(FileServices *loader)
Definition: ttbdmi.h:322
TMatrix _init_freq
Definition: ttbdmi.h:301
unsigned int _nLocus
Definition: ttbdmi.h:302
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:993
virtual age_t requiredAgeClass()
Definition: ttbdmi.h:327
virtual bool setParameters()
Definition: ttbdmi.cc:910
virtual age_t addAgeClass()
Definition: ttbdmi.h:326
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:1054
virtual LifeCycleEvent * clone()
Definition: ttbdmi.h:317
virtual void loadStatServices(StatServices *loader)
Definition: ttbdmi.h:323
LCE_Init_BDMI()
Definition: ttbdmi.cc:900
virtual ~LCE_Init_BDMI()
Definition: ttbdmi.h:308
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: ttbdmi.h:324
virtual void execute()
Definition: ttbdmi.cc:1027
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147
Definition: ttbdmi.h:50
int get_nb_locus()
Definition: ttbdmi.h:77
virtual TraitPrototype * clone()
Definition: ttbdmi.h:111
bool _isHaploid
Definition: ttbdmi.h:54
double * _init_freq
Definition: ttbdmi.h:59
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttbdmi.cc:270
double get_init_freq(unsigned int i)
Definition: ttbdmi.h:81
double getGenoFitnessHaplo(unsigned int row, unsigned int pos)
Definition: ttbdmi.h:84
double _recomb_rate
Definition: ttbdmi.h:58
void(TT_BDMI::* _inherit_func_ptr)(TTrait *, TTrait *)
Definition: ttbdmi.h:63
virtual void loadStatServices(StatServices *loader)
Definition: ttbdmi.cc:168
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttbdmi.h:115
void inherit(sex_t SEX, bitstring *seq, bitstring **parent)
Definition: ttbdmi.cc:232
double _genomic_mut_rate
Definition: ttbdmi.h:57
TTBDMI_FH * _writer
Definition: ttbdmi.h:69
trait_t _type
Definition: ttbdmi.h:52
virtual void init()
Definition: ttbdmi.h:109
bool isInitSet()
Definition: ttbdmi.h:82
virtual TTrait * hatch()
Definition: ttbdmi.cc:180
double getGenoFitnessDiplo(unsigned int row, unsigned int posA, unsigned int posB)
Definition: ttbdmi.h:89
double _mut_rate
Definition: ttbdmi.h:56
double(TT_BDMI::* _viability_func_ptr)(void)
Definition: ttbdmi.h:65
virtual ~TProtoBDMI()
Definition: ttbdmi.cc:79
bool _isInitSet
Definition: ttbdmi.h:60
TMatrix * _genoTable
Definition: ttbdmi.h:67
void setGenoFitnessValue(unsigned int row, unsigned int geno, double value)
Definition: ttbdmi.h:100
double getGenoFitnessDiplo(unsigned int row, unsigned int pos)
Definition: ttbdmi.h:94
void(TT_BDMI::* _mutation_func_ptr)(void)
Definition: ttbdmi.h:64
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: ttbdmi.h:125
virtual trait_t get_type() const
Definition: ttbdmi.h:112
virtual void loadFileServices(FileServices *loader)
Definition: ttbdmi.cc:137
virtual bool setParameters()
Definition: ttbdmi.cc:88
TProtoBDMI()
Definition: ttbdmi.cc:39
void showGenoTable(unsigned int nrows)
Definition: ttbdmi.cc:212
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:197
bool isHaploid()
Definition: ttbdmi.h:79
double get_mut_rate()
Definition: ttbdmi.h:78
TTBDMI_SH * _stater
Definition: ttbdmi.h:68
unsigned int _nb_locus
Definition: ttbdmi.h:55
static unsigned int _diploGenotTableCoding[3][3]
Definition: ttbdmi.h:61
FileHandler for the DBMI trait.
Definition: ttbdmi.h:243
void write_haplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:634
virtual ~TTBDMI_FH()
Definition: ttbdmi.h:248
TTBDMI_FH(TProtoBDMI *TP)
Definition: ttbdmi.h:247
virtual void FHread(string &filename)
Definition: ttbdmi.h:254
virtual void FHwrite()
Definition: ttbdmi.cc:587
void write_diplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:655
StatHandler for the DBMI trait.
Definition: ttbdmi.h:266
double getPatchIcmp(unsigned int i)
Definition: ttbdmi.h:288
double * _patchFreq
Definition: ttbdmi.h:269
double * _patchIcmp
Definition: ttbdmi.h:269
virtual bool setStatRecorders(std::string &token)
Definition: ttbdmi.cc:681
virtual ~TTBDMI_SH()
Definition: ttbdmi.h:275
void addStats(age_t AGE)
Definition: ttbdmi.cc:707
TTBDMI_SH(TProtoBDMI *TP)
Definition: ttbdmi.h:272
double _freq
Definition: ttbdmi.h:268
void setAdultStats()
Definition: ttbdmi.cc:732
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:845
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:748
void setOffsprgStats()
Definition: ttbdmi.cc:740
double getFreqIcmp()
Definition: ttbdmi.h:286
double getFreq()
Definition: ttbdmi.h:285
double getPatchFreq(unsigned int i)
Definition: ttbdmi.h:287
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:870
double _freqIcomp
Definition: ttbdmi.h:268
TTProtoWithMap.
Definition: ttrait_with_map.h:176
Definition: ttbdmi.h:134
double _genomic_mut_rate
Definition: ttbdmi.h:146
virtual void set_value()
Definition: ttbdmi.h:217
double _recomb_rate
Definition: ttbdmi.h:147
unsigned int get_num_mut_haplo(unsigned int loc)
Definition: ttbdmi.h:204
void mutate_diplo()
Definition: ttbdmi.cc:469
virtual void inherit(TTrait *mother, TTrait *father)
Definition: ttbdmi.h:213
virtual double get_allele_value(int loc, int all)
Definition: ttbdmi.cc:353
static unsigned int * _recomb_template
Definition: ttbdmi.h:153
bool _isHaploid
Definition: ttbdmi.h:142
virtual void * set_trait(void *value)
Definition: ttbdmi.h:215
void(TT_BDMI::* _inherit_func_ptr)(TTrait *, TTrait *)
Definition: ttbdmi.h:149
virtual void init()
Definition: ttbdmi.cc:372
virtual void reset()
Definition: ttbdmi.cc:383
virtual bool operator==(const TTrait &)
Definition: ttbdmi.cc:329
virtual TT_BDMI * clone()
Definition: ttbdmi.h:225
void inherit_diplo(TTrait *mother, TTrait *father)
Definition: ttbdmi.cc:430
void set_inherit_func_ptr(void(TT_BDMI::*theFunc)(TTrait *, TTrait *))
Definition: ttbdmi.h:181
virtual void mutate()
Definition: ttbdmi.h:214
virtual void show_up()
Definition: ttbdmi.cc:521
void set_nb_locus(int val)
Definition: ttbdmi.h:176
void set_isHaploid(bool val)
Definition: ttbdmi.h:180
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttbdmi.cc:562
double viability_diplo()
Definition: ttbdmi.cc:500
virtual trait_t get_type() const
Definition: ttbdmi.h:219
TT_BDMI()
Definition: ttbdmi.h:160
double viability_haplo()
Definition: ttbdmi.cc:485
void set_mut_rate(double val)
Definition: ttbdmi.h:177
void set_recomb_rate(double val)
Definition: ttbdmi.h:179
static unsigned int * _rSites
Definition: ttbdmi.h:153
virtual bool operator!=(const TTrait &)
Definition: ttbdmi.cc:343
virtual void set_sequence(void **seq)
Definition: ttbdmi.h:216
void set_viability_func_ptr(double(TT_BDMI::*theFunc)(void))
Definition: ttbdmi.h:185
virtual void * getValue() const
Definition: ttbdmi.h:218
void set_sequence(bitstring **seq)
Definition: ttbdmi.cc:394
void inherit_haplo(TTrait *mother, TTrait *father)
Definition: ttbdmi.cc:441
bitstring * _sequence[2]
Definition: ttbdmi.h:138
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttbdmi.cc:546
TProtoBDMI * _myProto
Definition: ttbdmi.h:136
virtual ~TT_BDMI()
Definition: ttbdmi.h:172
static unsigned int _haploGenotCoding[2][2]
Definition: ttbdmi.h:155
void mutate_haplo()
Definition: ttbdmi.cc:453
void set_proto(TProtoBDMI *proto)
Definition: ttbdmi.h:188
double _phenotype
Definition: ttbdmi.h:140
unsigned int get_num_mut_diplo(unsigned int loc)
Definition: ttbdmi.h:205
void set_mutation_func_ptr(void(TT_BDMI::*theFunc)(void))
Definition: ttbdmi.h:183
double _mut_rate
Definition: ttbdmi.h:145
virtual void ** get_sequence() const
Definition: ttbdmi.h:220
void set_geno_rate(double val)
Definition: ttbdmi.h:178
static unsigned char * _sites
Definition: ttbdmi.h:154
virtual void set_allele_value(unsigned int locus, unsigned int allele, double value)
Definition: ttbdmi.cc:365
virtual void init_sequence()
Definition: ttbdmi.cc:403
double(TT_BDMI::* _viability_func_ptr)(void)
Definition: ttbdmi.h:151
TT_BDMI(const TT_BDMI &T)
Definition: ttbdmi.h:165
static unsigned int _diploGenotCoding[2][2]
Definition: ttbdmi.h:156
void(TT_BDMI::* _mutation_func_ptr)(void)
Definition: ttbdmi.h:150
unsigned int _nb_locus
Definition: ttbdmi.h:144
virtual TT_BDMI & operator=(const TTrait &)
Definition: ttbdmi.cc:301
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:46
Template class for the trait's FileHandler.
Definition: filehandler.h:217
TTrait setter.
Definition: ttrait.h:125
Template class for the trait's StatHandler.
Definition: stathandler.h:168
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
std::string trait_t
Trait types.
Definition: types.h:63
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
unsigned int age_t
Age class flags.
Definition: types.h:46
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR