Nemo  2.3.46
ttwolbachia.h
Go to the documentation of this file.
1 
31 #ifndef TTWOLBACHIA_H
32 #define TTWOLBACHIA_H
33 
34 #include "ttrait.h"
35 #include "lifecycleevent.h"
36 #include "filehandler.h"
37 #include "stathandler.h"
38 #include "binarystoragebuffer.h"
39 #include "Uniform.h"
40 #include "LCEbreed.h"
41 
42 class TTWolbachiaSH;
43 
44 // ------------------------------------------------------------------------------
45 
46 // TTWolbachia
47 
48 // ------------------------------------------------------------------------------
53 class TTWolbachia : public TTrait
54 {
55 private:
56  double _transmit_rate;
58 
59 public:
60 
62  : _transmit_rate(0), _is_infected(0) { }
63 
65  : _transmit_rate(T._transmit_rate), _is_infected(T._is_infected) { }
66 
67 
68  virtual ~TTWolbachia () {}
69 
70  void set_transmit_rate (double val) {_transmit_rate = val;}
71 
72  virtual void init () {_is_infected = 0;}
73  virtual void init_sequence () {_is_infected = 0;}
74  virtual void reset () {_is_infected = 0;}
75  virtual void inherit (TTrait* mother, TTrait* father)
76  { _is_infected = *(bool*)mother->getValue(); }
77  virtual void mutate ()
78  { _is_infected &= (RAND::Uniform() < _transmit_rate); }
79  virtual void* set_trait (void* value)
80  { _is_infected = *(bool*)value; return &_is_infected; }
81  virtual void set_sequence (void** seq) { }
82  virtual void set_value () { }
83  virtual void* getValue () const {return (void*)&_is_infected;}
84  virtual trait_t get_type () const {return WOLB;}
85  virtual void** get_sequence () const {return NULL;}
86  virtual double get_allele_value(int loc, int all) {return _is_infected;}
87  virtual void set_allele_value(unsigned int locus, unsigned int allele, double value) {_is_infected=(bool)value;}
88  virtual void show_up () {}
89  virtual TTWolbachia* clone () {return new TTWolbachia(*this);}
90  virtual TTWolbachia& operator= (const TTrait& T);
91  virtual bool operator== (const TTrait& T);
92  virtual bool operator!= (const TTrait& T);
93 
94  virtual void store_data (BinaryStorageBuffer* saver)
95  {
96  unsigned char dummy = static_cast<unsigned char>(_is_infected);
97  saver->store(&dummy, 1);
98  }
99  virtual bool retrieve_data (BinaryStorageBuffer* reader)
100  {
101  unsigned char dummy;
102  reader->read(&dummy, 1);
103  _is_infected = dummy;
104  return true;
105  }
106 
107 };
108 
109 // ------------------------------------------------------------------------------
110 
111 // TProtoWolbachia
112 
113 // ------------------------------------------------------------------------------
116 public:
117  TProtoWolbachia();
120 
121  virtual void init(){}
122  virtual void reset(){}
123  virtual bool setParameters()
124  { _transmit_rate = get_parameter_value("wolbachia_transmission_rate"); return true;}
125 
126  virtual TTWolbachia* hatch()
127  {
128  TTWolbachia* new_trait = new TTWolbachia();
129  new_trait->set_transmit_rate(_transmit_rate);
130  return new_trait;
131  }
132 
133  virtual TProtoWolbachia* clone() {return new TProtoWolbachia(*this);}
134 
135  virtual trait_t get_type ( ) const {return WOLB;}
136 
137  virtual void store_data (BinaryStorageBuffer* saver) {/*we have nothing to save...*/}
138  virtual bool retrieve_data (BinaryStorageBuffer* reader) {return true;}
139 
140  virtual void loadFileServices ( FileServices* loader ) {}
141  virtual void loadStatServices ( StatServices* loader );
142 
143 private:
144 
147 };
148 
149 // ------------------------------------------------------------------------------
150 
151 // TTWolbachiaSH
152 
153 // ------------------------------------------------------------------------------
155 class TTWolbachiaSH : public TraitStatHandler<TProtoWolbachia, TTWolbachiaSH> {
156 
158  int _TTidx;
160 public:
161 
164  _trait(TT), _TTidx(TT->get_index()), _Fmean(0), _Mmean(0), _var(0), _extrate(0) {}
165 
166  virtual ~TTWolbachiaSH ( ) { }
167 
168  virtual bool setStatRecorders (string& token);
169 
170  void setInfectionStats ( );
171  double getMeanInfection (unsigned int sex) {return ((bool)sex ? _Fmean : _Mmean);}
172  double getMeanOffsprgInfection (unsigned int sex);
173  double getMeanFemaleInfection_perPatch (unsigned int patch);
174  double getMeanMaleInfection_perPatch (unsigned int patch);
175  double getMeanOffsprgFemaleInfection_perPatch (unsigned int patch);
176  double getMeanOffsprgMaleInfection_perPatch (unsigned int patch);
177  double getIcompatibleMatingFreq ( );
178  double getDemicInfectionVar ( ) {return _var;}
179  double getDemicExtinctionRate ( ) {return _extrate;}
180 };
181 
182 
183 
184 class TTWolbachiaFH;
185 
186 
190 class LCE_Breed_Wolbachia : public virtual LCE_Breed_base {
191 
192  double _incomp_cost;
193  double _fec_cost;
196  unsigned int _inoculum_time;
197  unsigned int _model;
198 
200 
202 
203  void inoculate_wolbachia();
204  double hasInfectedFemale ();
205 
206 public:
207 
209 
210  virtual ~LCE_Breed_Wolbachia ( );
211 
212  void wolbachia_model_1 ();
213  void wolbachia_model_2 ();
214 
215  virtual bool setParameters ();
216  virtual void execute ();
217 
218  virtual LifeCycleEvent* clone ( )
219  { return new LCE_Breed_Wolbachia(); }
220 
221 
222  virtual void loadFileServices ( FileServices* loader );
223  virtual void loadStatServices ( StatServices* loader ) {}
224  virtual age_t removeAgeClass ( ) {return 0;}
225  virtual age_t addAgeClass ( ) {return OFFSPRG;}
226  virtual age_t requiredAgeClass () {return ADULTS;}
227 };
228 
229 // ------------------------------------------------------------------------------
230 
231 // ****** TTWolbachiaFH ******
232 
233 // ------------------------------------------------------------------------------
238 class TTWolbachiaFH: public EventFileHandler<LCE_Breed_Wolbachia> {
239 
240  map< unsigned int, unsigned int > _times;
241  vector< double > _rate;
242 
243 public:
244 
246  : EventFileHandler<LCE_Breed_Wolbachia> (TP, ".wolb")
247  { }
248 
249  //TTWolbachiaFH ( ) { }
250  virtual ~TTWolbachiaFH ( ) { }
251 
252  void record (unsigned int repl, unsigned int gen, double infection);
253 
254  virtual void FHwrite ();
255 
256  virtual void FHread (string& filename) {}
257 
258 };
259 
260 #endif //TTWOLBACHIA_H
261 
Template class for the LCEs StatHandler classes.
Definition: filehandler.h:247
double _Mmean
Definition: ttwolbachia.h:159
void inoculate_wolbachia()
Definition: ttwolbachia.cc:378
virtual void mutate()
Definition: ttwolbachia.h:77
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttwolbachia.h:94
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
double getMeanOffsprgFemaleInfection_perPatch(unsigned int patch)
Definition: stats_wolbachia.cc:155
double _incomp_cost
Definition: ttwolbachia.h:192
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
std::string trait_t
Trait types.
Definition: types.h:63
virtual void show_up()
Definition: ttwolbachia.h:88
virtual void * getValue() const
Definition: ttwolbachia.h:83
unsigned int _model
Definition: ttwolbachia.h:197
double _transmit_rate
Definition: ttwolbachia.h:145
virtual void init()
Definition: ttwolbachia.h:121
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
void setInfectionStats()
Definition: stats_wolbachia.cc:35
virtual bool operator==(const TTrait &T)
Definition: ttwolbachia.cc:87
virtual double get_allele_value(int loc, int all)
Definition: ttwolbachia.h:86
Trait used to study the dynamics of spread of Wolbachia, an endosymbiotic parasite causing cytoplasmi...
Definition: ttwolbachia.h:53
virtual ~TTWolbachia()
Definition: ttwolbachia.h:68
unsigned int age_t
Age class flags.
Definition: types.h:46
virtual void loadFileServices(FileServices *loader)
Definition: ttwolbachia.h:140
double getMeanOffsprgInfection(unsigned int sex)
Definition: stats_wolbachia.cc:105
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttwolbachia.h:99
double getIcompatibleMatingFreq()
Definition: stats_wolbachia.cc:181
double getDemicExtinctionRate()
Definition: ttwolbachia.h:179
virtual void FHwrite()
Definition: ttwolbachia.cc:435
TTWolbachiaFH * _writer
Definition: ttwolbachia.h:201
TTWolbachia(const TTWolbachia &T)
Definition: ttwolbachia.h:64
double getMeanFemaleInfection_perPatch(unsigned int patch)
Definition: stats_wolbachia.cc:131
virtual void loadStatServices(StatServices *loader)
Definition: ttwolbachia.h:223
FileHandler of the Wolbachia trait.
Definition: ttwolbachia.h:238
virtual ~TTWolbachiaFH()
Definition: ttwolbachia.h:250
virtual age_t removeAgeClass()
Definition: ttwolbachia.h:224
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:46
virtual age_t addAgeClass()
Definition: ttwolbachia.h:225
virtual TTWolbachia * hatch()
Definition: ttwolbachia.h:126
virtual void store_data(BinaryStorageBuffer *saver)
Definition: ttwolbachia.h:137
virtual bool retrieve_data(BinaryStorageBuffer *reader)
Definition: ttwolbachia.h:138
virtual void execute()
Definition: ttwolbachia.cc:247
double _fec_cost
Definition: ttwolbachia.h:193
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:130
double _infected_fec
Definition: ttwolbachia.h:194
virtual void reset()
Definition: ttwolbachia.h:122
TTWolbachiaFH(LCE_Breed_Wolbachia *TP)
Definition: ttwolbachia.h:245
TTWolbachiaSH(TProtoWolbachia *TT)
Definition: ttwolbachia.h:162
double hasInfectedFemale()
Definition: ttwolbachia.cc:404
virtual TProtoWolbachia * clone()
Definition: ttwolbachia.h:133
double _extrate
Definition: ttwolbachia.h:159
Base class for the breeding (and mating) life cycle events.
Definition: LCEbreed.h:43
unsigned int _inoculum_time
Definition: ttwolbachia.h:196
virtual bool setParameters()
Definition: ttwolbachia.h:123
Template class for the trait's StatHandler.
Definition: stathandler.h:168
TProtoWolbachia * _trait
Definition: ttwolbachia.h:157
virtual void set_sequence(void **seq)
Definition: ttwolbachia.h:81
Breeding LCE when individuals carry the Wolbachia endosymbiotic parasite.
Definition: ttwolbachia.h:190
virtual void * set_trait(void *value)
Definition: ttwolbachia.h:79
double getMeanMaleInfection_perPatch(unsigned int patch)
Definition: stats_wolbachia.cc:143
~TProtoWolbachia()
Definition: ttwolbachia.cc:58
virtual ~TTWolbachiaSH()
Definition: ttwolbachia.h:166
A class to store any kind of data in a char buffer before unloading it in a binary data file...
Definition: binarystoragebuffer.h:40
Prototype of the Wolbachia trait.
Definition: ttwolbachia.h:115
virtual void * getValue() const =0
Genotype to phenotype mapper.
int _TTidx
Definition: ttwolbachia.h:158
#define WOLB
Definition: types.h:73
virtual bool setStatRecorders(string &token)
Definition: ttwolbachia.cc:114
double getMeanInfection(unsigned int sex)
Definition: ttwolbachia.h:171
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
virtual void reset()
Definition: ttwolbachia.h:74
double getMeanOffsprgMaleInfection_perPatch(unsigned int patch)
Definition: stats_wolbachia.cc:168
StatHandler of the Wolbachia trait.
Definition: ttwolbachia.h:155
void read(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:147
double getDemicInfectionVar()
Definition: ttwolbachia.h:178
virtual void inherit(TTrait *mother, TTrait *father)
Definition: ttwolbachia.h:75
TTrait setter.
Definition: ttrait.h:125
vector< double > _rate
Definition: ttwolbachia.h:241
void wolbachia_model_1()
Definition: ttwolbachia.cc:284
virtual void loadStatServices(StatServices *loader)
Definition: ttwolbachia.cc:65
virtual void loadFileServices(FileServices *loader)
Definition: ttwolbachia.cc:233
LCE_Breed_Wolbachia()
Definition: ttwolbachia.cc:170
virtual bool setParameters()
Definition: ttwolbachia.cc:191
virtual void set_value()
Definition: ttwolbachia.h:82
double _var
Definition: ttwolbachia.h:159
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
virtual void set_allele_value(unsigned int locus, unsigned int allele, double value)
Definition: ttwolbachia.h:87
virtual TTWolbachia * clone()
Definition: ttwolbachia.h:89
void wolbachia_model_2()
Definition: ttwolbachia.cc:330
double _transmit_rate
Definition: ttwolbachia.h:56
void set_transmit_rate(double val)
Definition: ttwolbachia.h:70
TProtoWolbachia()
Definition: ttwolbachia.cc:41
void(LCE_Breed_Wolbachia::* _breed_func_ptr)()
Definition: ttwolbachia.h:199
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
virtual TTWolbachia & operator=(const TTrait &T)
Definition: ttwolbachia.cc:75
virtual LifeCycleEvent * clone()
Definition: ttwolbachia.h:218
double _Fmean
Definition: ttwolbachia.h:159
virtual void FHread(string &filename)
Definition: ttwolbachia.h:256
virtual trait_t get_type() const
Definition: ttwolbachia.h:135
virtual age_t requiredAgeClass()
Definition: ttwolbachia.h:226
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
virtual void init()
Definition: ttwolbachia.h:72
TTWolbachiaSH * _stats
Definition: ttwolbachia.h:146
virtual void ** get_sequence() const
Definition: ttwolbachia.h:85
virtual void init_sequence()
Definition: ttwolbachia.h:73
virtual ~LCE_Breed_Wolbachia()
Definition: ttwolbachia.cc:184
TTWolbachia()
Definition: ttwolbachia.h:61
bool _is_infected
Definition: ttwolbachia.h:57
virtual trait_t get_type() const
Definition: ttwolbachia.h:84
TMatrix * _inoculum_size
Definition: ttwolbachia.h:195
virtual bool operator!=(const TTrait &T)
Definition: ttwolbachia.cc:99
void record(unsigned int repl, unsigned int gen, double infection)
Definition: ttwolbachia.cc:427
map< unsigned int, unsigned int > _times
Definition: ttwolbachia.h:240

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