Nemo  2.3.46
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 
42 class TTBDMI_SH;
43 class TTBDMI_FH;
44 class TT_BDMI;
45 // ------------------------------------------------------------------------------
46 
47 // TProtoBDMI
48 
49 // ------------------------------------------------------------------------------
50 class TProtoBDMI : public TTProtoWithMap {
51 
53 
54  bool _isHaploid;
55  unsigned int _nb_locus;
56  double _mut_rate;
58  double _recomb_rate;
59  double* _init_freq;
60  bool _isInitSet;
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 
71 public:
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  return _genoTable->get(row, _diploGenotTableCoding[posA][posB] );
91  }
92 
93  double getGenoFitnessDiplo (unsigned int row, unsigned int pos){
94  assert(pos < 9);
95  return _genoTable->get(row, pos);
96  }
97 
98  void setGenoFitnessValue(unsigned int row, unsigned int geno, double value)
99  { _genoTable->set(row, geno, value); }
100 
101  void showGenoTable (unsigned int nrows);
102 
103  void inherit (sex_t SEX, bitstring* seq, bitstring** parent);
104 
107  virtual void init () {setParameters();}
108  virtual TTrait* hatch ();
109  virtual TraitPrototype* clone () {return new TProtoBDMI(*this);}
110  virtual trait_t get_type () const {return _type;}
111 
112  //implements StorageComponent
113  virtual void store_data (BinaryStorageBuffer* saver) {}
114  virtual bool retrieve_data (BinaryStorageBuffer* reader) {return true;}
115  //implements SimComponent
116  virtual bool setParameters ( );
117  virtual void loadFileServices ( FileServices* loader );
118  virtual void loadStatServices ( StatServices* loader );
120 
121 };
122 // ------------------------------------------------------------------------------
123 
124 // TT_BDMI
125 
126 // ------------------------------------------------------------------------------
127 class TT_BDMI : public TTrait {
128 
130 
132 
133  double _phenotype;
134 
136 
137  unsigned int _nb_locus;
138  double _mut_rate;
140  double _recomb_rate;
141 
143  void (TT_BDMI::* _mutation_func_ptr) (void);
144  double (TT_BDMI::* _viability_func_ptr) (void);
145 
146  static unsigned int *_recomb_template, *_rSites;
147  static unsigned char *_sites;
148  static unsigned int _haploGenotCoding[2][2];
149  static unsigned int _diploGenotCoding[2][2];
150 
151 public:
152  //cstor & dstor
154  : _myProto(0), _phenotype(0), _isHaploid(0), _nb_locus(0), _mut_rate(0), _genomic_mut_rate(0),
155  _recomb_rate(0), _inherit_func_ptr(0), _mutation_func_ptr(0), _viability_func_ptr(0)
156  {_sequence[0] = _sequence[1] = NULL;}
157 
158  TT_BDMI(const TT_BDMI& T)
159  : _myProto(T._myProto), _phenotype(0), _isHaploid(T._isHaploid), _nb_locus(T._nb_locus),
160  _mut_rate(T._mut_rate), _genomic_mut_rate(T._genomic_mut_rate), _recomb_rate(T._recomb_rate),
163  {_sequence[0] = _sequence[1] = NULL;}
164 
165  virtual ~TT_BDMI() { }
166 
169  void set_nb_locus (int val) {_nb_locus = val;}
170  void set_mut_rate (double val) {_mut_rate = val;}
171  void set_geno_rate (double val) {_genomic_mut_rate = val;}
172  void set_recomb_rate (double val) {_recomb_rate = val;}
173  void set_isHaploid (bool val) {_isHaploid = val;}
174  void set_inherit_func_ptr (void(TT_BDMI::* theFunc)(TTrait*, TTrait*))
175  {_inherit_func_ptr = theFunc;}
176  void set_mutation_func_ptr (void (TT_BDMI::* theFunc) (void))
177  {_mutation_func_ptr = theFunc;}
178  void set_viability_func_ptr (double (TT_BDMI::* theFunc) (void))
179  {_viability_func_ptr = theFunc;}
180 
181  void set_proto (TProtoBDMI* proto) {_myProto = proto;}
183 
184  void set_sequence (bitstring** seq);
185 
186  //inheritance routines:
187  void inherit_haplo (TTrait* mother, TTrait* father);
188  void inherit_diplo (TTrait* mother, TTrait* father);
189 
190  //mutation routines:
191  void mutate_haplo ( );
192  void mutate_diplo ( );
193 
194  double viability_haplo ( );
195  double viability_diplo ( );
196 
197  unsigned int get_num_mut_haplo (unsigned int loc) {return (*_sequence[0])[loc];}
198  unsigned int get_num_mut_diplo (unsigned int loc) {return (*_sequence[0])[loc]+(*_sequence[1])[loc];}
199 
200 
203  virtual void init ();
204  virtual void init_sequence ();
205  virtual void reset ();
206  virtual void inherit (TTrait* mother, TTrait* father){(this->* _inherit_func_ptr) (mother, father);}
207  virtual void mutate () {(this->*_mutation_func_ptr)();}
208  virtual void* set_trait (void* value) {return NULL;}
209  virtual void set_sequence (void** seq) {}
210  virtual void set_value () {_phenotype = (this->*_viability_func_ptr)();}
211  virtual void* getValue () const {return (void*)&_phenotype;}
212  virtual trait_t get_type () const {return _myProto->get_type();}
213  virtual void** get_sequence () const {return (void**)&_sequence[0];}
214  virtual double get_allele_value (int loc, int all);
215  virtual void set_allele_value (unsigned int locus, unsigned int allele, double value);
216  virtual void show_up ();
217 
218  virtual TT_BDMI* clone () {return new TT_BDMI(*this);}
219  virtual TT_BDMI& operator= (const TTrait&);
220  virtual bool operator== (const TTrait&);
221  virtual bool operator!= (const TTrait&);
222  //implements StorableComponent:
223  virtual void store_data (BinaryStorageBuffer* saver) {}
224  virtual bool retrieve_data (BinaryStorageBuffer* reader) {return true;}
226 
227 };
228 
229 // ------------------------------------------------------------------------------
230 
231 // TTBDMI_FH
232 
233 // ------------------------------------------------------------------------------
236 class TTBDMI_FH : public TraitFileHandler< TProtoBDMI > {
237 
238 public:
239 
241  virtual ~TTBDMI_FH ( ) { }
242 
243  void write_haplo (Patch* patch, sex_t SEX, age_idx AGE, ofstream& FH);
244  void write_diplo (Patch* patch, sex_t SEX, age_idx AGE, ofstream& FH);
245 
246  virtual void FHwrite ();
247  virtual void FHread (string& filename) {}
248 
249 };
250 
251 // ------------------------------------------------------------------------------
252 
253 // TTBDMI_SH
254 
255 // ------------------------------------------------------------------------------
259 class TTBDMI_SH : public TraitStatHandler< TProtoBDMI, TTBDMI_SH > {
260 
261  double _freq, _freqIcomp;
263 
264 public:
266  _patchFreq(0), _patchIcmp(0) {}
267 
268  virtual ~TTBDMI_SH(){if(_patchFreq)delete[]_patchFreq;if(_patchIcmp)delete[]_patchIcmp;}
269 
270  virtual bool setStatRecorders (std::string& token);
271 
272  void addStats (age_t AGE);
273  void setAdultStats () ;
274  void setOffsprgStats ();
275  void setStats (age_idx agex, void(TTBDMI_SH::* cntFunc)(Patch*,sex_t,age_idx,double**,double**));
276  void countAllele_haplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab);
277  void countAllele_diplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab);
278  double getFreq () {return _freq;}
279  double getFreqIcmp () {return _freqIcomp;}
280  double getPatchFreq (unsigned int i) {return _patchFreq[i];}
281  double getPatchIcmp (unsigned int i) {return _patchIcmp[i];}
282 
283 };
284 
285 // ------------------------------------------------------------------------------
286 
287 // LCE_Init_BDMI
288 
289 // ------------------------------------------------------------------------------
293 
295  unsigned int _nLocus;
296 
297 public:
298 
299  LCE_Init_BDMI ( );
300 
301  virtual ~LCE_Init_BDMI ( ) { }
302 
303  bool setSpatialPattern(TMatrix& freq_mat, unsigned int patchNbr);
304  bool setPatchFreq(TMatrix& freq_mat,TMatrix& pat_mat, unsigned int patchNbr);
305  void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme);
306 
307  //LifeCycleEvent implementation:
308  virtual void execute ();
309 
310  virtual LifeCycleEvent* clone ( ) {return new LCE_Init_BDMI();}
311 
312  virtual bool setParameters ();
313 
314  //SimComponent implementation:
315  virtual void loadFileServices ( FileServices* loader ) {}
316  virtual void loadStatServices ( StatServices* loader ) {}
317  virtual age_t removeAgeClass ( ) {return 0;}
318  virtual age_t addAgeClass ( ) {return 0;}
319  virtual age_t requiredAgeClass () {return 0;}
320 };
321 
322 #endif
virtual bool setParameters()
Definition: ttbdmi.cc:88
virtual void * set_trait(void *value)
Definition: ttbdmi.h:208
virtual bool operator!=(const TTrait &)
Definition: ttbdmi.cc:319
FileHandler for the DBMI trait.
Definition: ttbdmi.h:236
TMatrix _init_freq
Definition: ttbdmi.h:294
Template class for the trait's FileHandler.
Definition: filehandler.h:217
TT_BDMI(const TT_BDMI &T)
Definition: ttbdmi.h:158
TMatrix * _genoTable
Definition: ttbdmi.h:67
LCE_Init_BDMI()
Definition: ttbdmi.cc:832
virtual void * getValue() const
Definition: ttbdmi.h:211
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:679
virtual bool setParameters()
Definition: ttbdmi.cc:842
double * _patchIcmp
Definition: ttbdmi.h:262
void inherit(sex_t SEX, bitstring *seq, bitstring **parent)
Definition: ttbdmi.cc:232
double get_init_freq(unsigned int i)
Definition: ttbdmi.h:81
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
virtual void FHread(string &filename)
Definition: ttbdmi.h:247
void set_recomb_rate(double val)
Definition: ttbdmi.h:172
std::string trait_t
Trait types.
Definition: types.h:63
virtual void loadFileServices(FileServices *loader)
Definition: ttbdmi.cc:137
virtual ~TT_BDMI()
Definition: ttbdmi.h:165
void set_mutation_func_ptr(void(TT_BDMI::*theFunc)(void))
Definition: ttbdmi.h:176
void set_nb_locus(int val)
Definition: ttbdmi.h:169
double getFreqIcmp()
Definition: ttbdmi.h:279
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
virtual age_t requiredAgeClass()
Definition: ttbdmi.h:319
virtual TraitPrototype * clone()
Definition: ttbdmi.h:109
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:925
virtual ~TProtoBDMI()
Definition: ttbdmi.cc:79
virtual void mutate()
Definition: ttbdmi.h:207
unsigned int get_num_mut_diplo(unsigned int loc)
Definition: ttbdmi.h:198
virtual bool operator==(const TTrait &)
Definition: ttbdmi.cc:305
Definition: ttbdmi.h:50
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttbdmi.h:223
void(TT_BDMI::* _inherit_func_ptr)(TTrait *, TTrait *)
Definition: ttbdmi.h:142
TTBDMI_SH(TProtoBDMI *TP)
Definition: ttbdmi.h:265
unsigned int age_t
Age class flags.
Definition: types.h:46
virtual void inherit(TTrait *mother, TTrait *father)
Definition: ttbdmi.h:206
Definition: ttbdmi.h:127
void set_isHaploid(bool val)
Definition: ttbdmi.h:173
TTProtoWithMap.
Definition: ttrait_with_map.h:165
virtual trait_t get_type() const
Definition: ttbdmi.h:212
void set_proto(TProtoBDMI *proto)
Definition: ttbdmi.h:181
double getGenoFitnessDiplo(unsigned int row, unsigned int posA, unsigned int posB)
Definition: ttbdmi.h:89
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
virtual void set_allele_value(unsigned int locus, unsigned int allele, double value)
Definition: ttbdmi.cc:341
unsigned int _nb_locus
Definition: ttbdmi.h:137
void setAdultStats()
Definition: ttbdmi.cc:663
double _mut_rate
Definition: ttbdmi.h:56
double _recomb_rate
Definition: ttbdmi.h:58
double _genomic_mut_rate
Definition: ttbdmi.h:57
virtual void execute()
Definition: ttbdmi.cc:959
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void set_viability_func_ptr(double(TT_BDMI::*theFunc)(void))
Definition: ttbdmi.h:178
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:46
void write_diplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:586
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
bool isHaploid()
Definition: ttbdmi.h:79
virtual TT_BDMI & operator=(const TTrait &)
Definition: ttbdmi.cc:277
virtual ~LCE_Init_BDMI()
Definition: ttbdmi.h:301
virtual void set_sequence(void **seq)
Definition: ttbdmi.h:209
static unsigned char * _sites
Definition: ttbdmi.h:147
virtual void loadStatServices(StatServices *loader)
Definition: ttbdmi.h:316
double get_mut_rate()
Definition: ttbdmi.h:78
void set_mut_rate(double val)
Definition: ttbdmi.h:170
virtual double get_allele_value(int loc, int all)
Definition: ttbdmi.cc:329
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttbdmi.h:113
void mutate_haplo()
Definition: ttbdmi.cc:429
double _genomic_mut_rate
Definition: ttbdmi.h:139
virtual ~TTBDMI_FH()
Definition: ttbdmi.h:241
virtual LifeCycleEvent * clone()
Definition: ttbdmi.h:310
virtual bool setStatRecorders(std::string &token)
Definition: ttbdmi.cc:612
void setOffsprgStats()
Definition: ttbdmi.cc:671
virtual void init_sequence()
Definition: ttbdmi.cc:379
virtual void show_up()
Definition: ttbdmi.cc:495
virtual void set_value()
Definition: ttbdmi.h:210
void addStats(age_t AGE)
Definition: ttbdmi.cc:638
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:986
double viability_diplo()
Definition: ttbdmi.cc:475
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
virtual TT_BDMI * clone()
Definition: ttbdmi.h:218
TProtoBDMI * _myProto
Definition: ttbdmi.h:129
Template class for the trait's StatHandler.
Definition: stathandler.h:168
virtual void reset()
Definition: ttbdmi.cc:359
void inherit_diplo(TTrait *mother, TTrait *father)
Definition: ttbdmi.cc:406
void setGenoFitnessValue(unsigned int row, unsigned int geno, double value)
Definition: ttbdmi.h:98
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:197
virtual void loadFileServices(FileServices *loader)
Definition: ttbdmi.h:315
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
static unsigned int _diploGenotTableCoding[3][3]
Definition: ttbdmi.h:61
double getFreq()
Definition: ttbdmi.h:278
TProtoBDMI()
Definition: ttbdmi.cc:39
bool _isHaploid
Definition: ttbdmi.h:135
Allelic frequency initialiser for the DBMI trait.
Definition: ttbdmi.h:292
virtual age_t removeAgeClass()
Definition: ttbdmi.h:317
double * _init_freq
Definition: ttbdmi.h:59
static unsigned int * _rSites
Definition: ttbdmi.h:146
double getGenoFitnessHaplo(unsigned int row, unsigned int pos)
Definition: ttbdmi.h:84
void(TT_BDMI::* _inherit_func_ptr)(TTrait *, TTrait *)
Definition: ttbdmi.h:63
A class to store any kind of data in a char buffer before unloading it in a binary data file...
Definition: binarystoragebuffer.h:40
void inherit_haplo(TTrait *mother, TTrait *father)
Definition: ttbdmi.cc:417
int get_nb_locus()
Definition: ttbdmi.h:77
virtual void init()
Definition: ttbdmi.h:107
double * _patchFreq
Definition: ttbdmi.h:262
void set_inherit_func_ptr(void(TT_BDMI::*theFunc)(TTrait *, TTrait *))
Definition: ttbdmi.h:174
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
bool _isHaploid
Definition: ttbdmi.h:54
static unsigned int _haploGenotCoding[2][2]
Definition: ttbdmi.h:148
double getPatchFreq(unsigned int i)
Definition: ttbdmi.h:280
double _phenotype
Definition: ttbdmi.h:133
TTrait setter.
Definition: ttrait.h:125
trait_t _type
Definition: ttbdmi.h:52
virtual ~TTBDMI_SH()
Definition: ttbdmi.h:268
void set_sequence(bitstring **seq)
Definition: ttbdmi.cc:370
virtual void loadStatServices(StatServices *loader)
Definition: ttbdmi.cc:168
virtual age_t addAgeClass()
Definition: ttbdmi.h:318
double _recomb_rate
Definition: ttbdmi.h:140
virtual TTrait * hatch()
Definition: ttbdmi.cc:180
double viability_haplo()
Definition: ttbdmi.cc:461
void set_geno_rate(double val)
Definition: ttbdmi.h:171
TT_BDMI()
Definition: ttbdmi.h:153
TTBDMI_FH * _writer
Definition: ttbdmi.h:69
unsigned int _nb_locus
Definition: ttbdmi.h:55
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttbdmi.h:224
void write_haplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:565
virtual trait_t get_type() const
Definition: ttbdmi.h:110
unsigned int _nLocus
Definition: ttbdmi.h:295
void mutate_diplo()
Definition: ttbdmi.cc:445
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:887
unsigned int get_num_mut_haplo(unsigned int loc)
Definition: ttbdmi.h:197
double getPatchIcmp(unsigned int i)
Definition: ttbdmi.h:281
TTBDMI_FH(TProtoBDMI *TP)
Definition: ttbdmi.h:240
void showGenoTable(unsigned int nrows)
Definition: ttbdmi.cc:212
double(TT_BDMI::* _viability_func_ptr)(void)
Definition: ttbdmi.h:65
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
virtual void ** get_sequence() const
Definition: ttbdmi.h:213
void(TT_BDMI::* _mutation_func_ptr)(void)
Definition: ttbdmi.h:143
virtual void init()
Definition: ttbdmi.cc:348
double _freq
Definition: ttbdmi.h:261
bitstring * _sequence[2]
Definition: ttbdmi.h:131
bool _isInitSet
Definition: ttbdmi.h:60
bool isInitSet()
Definition: ttbdmi.h:82
void(TT_BDMI::* _mutation_func_ptr)(void)
Definition: ttbdmi.h:64
static unsigned int _diploGenotCoding[2][2]
Definition: ttbdmi.h:149
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
double _mut_rate
Definition: ttbdmi.h:138
double _freqIcomp
Definition: ttbdmi.h:261
double getGenoFitnessDiplo(unsigned int row, unsigned int pos)
Definition: ttbdmi.h:93
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttbdmi.h:114
TTBDMI_SH * _stater
Definition: ttbdmi.h:68
double(TT_BDMI::* _viability_func_ptr)(void)
Definition: ttbdmi.h:144
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:776
static unsigned int * _recomb_template
Definition: ttbdmi.h:146
virtual void FHwrite()
Definition: ttbdmi.cc:525
StatHandler for the DBMI trait.
Definition: ttbdmi.h:259
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:801

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR