Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
individual.h
Go to the documentation of this file.
1
30#ifndef INDIVIDUAL_H
31#define INDIVIDUAL_H
32#include <map>
33#include <deque>
34#include <limits>
35#include "types.h"
36#include "ttrait.h"
37#include "ttrait_with_map.h"
38#include "binarystoragebuffer.h"
39
50private:
52 unsigned long _id;
54 unsigned short _age;
58 unsigned long _motherID, _fatherID;
62 unsigned short _home;
70 unsigned char _pedigreeClass;
72 double _fecundity;
74 unsigned short _matings[5];
76 unsigned short _realizedFecundity[5];
78 unsigned int _trait_nb;
79
80public:
81
83 static unsigned long currentID;
84
85 typedef int IDX;
86
88 std::deque<TTrait*> Traits;
89
90 Individual ();
95 Individual* init ();
100 void reset ();
101
104 void setID (unsigned long value) {_id = value;}
105 void setAge (unsigned short value) {_age = value;}
106 void Aging () {_age++;}
107 void setFatherID (unsigned long value) {_fatherID = value;}
108 void setMotherID (unsigned long value) {_motherID = value;}
109 void setFather (Individual* f) {_father = f;}
110 void setMother (Individual* m) {_mother = m;}
111 void setHome (unsigned short value) {_home = value;}
112 void setSex (sex_t sex) {_sex = sex;}
113 void setCurrentID (unsigned long value) {currentID = value;}
114 void setIsSelfed (bool s) {_pedigreeClass = (s ? 4 : 0);}
115 void setPedigreeClass (Individual* mother, Individual* father) {_pedigreeClass = getPedigreeClass(mother,father);}
116 void setPedigreeClass (unsigned char ped) {_pedigreeClass = ped;}
117
119
122 unsigned long getID () {return _id;}
123 unsigned short getAge () {return _age;}
124 unsigned long getFatherID () {return _fatherID;}
125 unsigned long getMotherID () {return _motherID;}
128 unsigned short getHome () {return _home;}
129 sex_t getSex () {return _sex;}
130 bool isFemale () {return (_sex == FEM);}
131 bool getIsSelfed () {return (_pedigreeClass == 4);}
132 unsigned long getcurrentID () {return currentID;}
133 double getFecundity () {return _fecundity;}
142 unsigned short getMatings (unsigned int cat)
143 {
144 return _matings[cat];
145 }
147 unsigned short getLocalMatings ( )
148 {
149 return _matings[1]+_matings[2]+_matings[3]+_matings[4];
150 }
152 unsigned int getTotMatings ( )
153 {
154 return _matings[0] + getLocalMatings();
155 }
164 unsigned short getRealizedFecundity (unsigned int cat)
165 {
166 return _realizedFecundity[cat];
167 }
168
171 {
173 }
174
177
179 unsigned int getPedigreeClass ( )
180 {
181 return _pedigreeClass;
182 }
193 unsigned int getPedigreeClass (Individual* mother, Individual* father);
195
198 void store_data ( BinaryStorageBuffer* saver );
199
200 void retrieve_data ( BinaryStorageBuffer* reader );
202
205
207 double setFecundity (double value) {_fecundity = value; return value;}
208
211 {
212 for(unsigned int i = 0; i < 5; i++) {
213 _matings[i] = 0; _realizedFecundity[i] = 0;
214 } }
215
219 void addMating (unsigned int category)
220 { _matings[category]++; }
221
225 void DidHaveABaby (unsigned int category)
226 { _matings[category]++; _realizedFecundity[category]++; }
227
230 {
231 unsigned short mate = getLocalMatings();
232 return (mate != 0 ? (double) getLocalRealizedFecundity()/mate : 0.0);
233 }
238 {
239 return (_matings[0] != 0 ? (double) _realizedFecundity[0]/_matings[0] : 0.0);
240 }
242
245
247 unsigned int getTraitNumber() { return _trait_nb;}
248
251 std::deque<TTrait *>& getTraits() {return Traits;}
252
256 void* setTrait (IDX T, void* value)
257 { return getTrait(T)->set_trait(value); }
258
262 { getTrait(T)->set_value(); }
263
266 { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->set_value(); }
267
272 { return getTrait(T)->getValue(); }
273
278 { if( T == -1 || !(T < (int)_trait_nb) )
279 fatal("Individual::Trying to access a trait not present in the traits table (at %i, size %i)\n",T,_trait_nb);
280 return Traits[T];
281 }
282
288 void addTrait (TTrait* theTrait, IDX pos)
289 { if((int)_trait_nb != pos)
290 fatal("Individual::adding a trait to the wrong position (at %i, size %i)!\n",pos,_trait_nb);
291 Traits.push_back(theTrait); _trait_nb++;
292 }
293
297 { delete Traits[T]; Traits.erase(Traits.begin() + T); _trait_nb--;}
298
300 void clearTraits ( )
301 { if(_trait_nb != 0) {for(unsigned int i = 0; i < Traits.size(); ++i) delete Traits[i];
302 Traits.clear(); _trait_nb = 0;}
303 }
304
309 void inheritTrait (IDX T, Individual* mother, Individual* father)
310 {
311 recombine(_id);
312 getTrait(T)->inherit(mother->getTrait(T), father->getTrait(T));
313 }
314
318 { getTrait(T)->mutate(); }
319
325 void createTrait (IDX i, Individual* mother, Individual* father)
326 { if(!(mother && father))
327 fatal("Individual::create::received null pointer!!!\n");
328 TTrait* T = Traits[i];
329 recombine(_id);
330 T->inherit(mother->getTrait(i),father->getTrait(i));
331 T->mutate();
332 T->set_value();
333 }
334
339 Individual* createTrait (IDX i, bool do_inherit, bool do_mutate)
340 {
341 if(do_inherit) inheritTrait(i, _mother, _father);
342 if(do_mutate) mutateTrait(i);
343 setTraitValue(i);
344 return this;
345 }
346
349 {
350 for(unsigned int i = 0; i < _trait_nb; i++) {
351 Traits[i]->init_sequence();
352 Traits[i]->set_value();
353 }
354 //we have to set the parents ids otherwise the first offspring generation will be made of full sibs only.
355 static unsigned long ID = std::numeric_limits< unsigned long >::max();
356 _motherID = ID--;
357 _fatherID = ID--;
358 return this;
359 }
360
363 {
365 mutate();
367 return this;
368 }
372 Individual* create (bool do_inherit, bool do_mutate)
373 {
374 if(do_inherit) inherit(_mother, _father);
375 if(do_mutate) mutate();
377 return this;
378 }
379
384 {
385 if(!(mother && father))
386 fatal("Individual::create::received null parents pointer!!!\n");
387 TTrait *TT;
388 recombine(_id);
389 for(unsigned int i = 0; i < _trait_nb; i++) {
390 TT = Traits[i];
391 TT->inherit(mother->getTrait(i), father->getTrait(i));
392 TT->mutate();
393 TT->set_value();
394 }
395 return this;
396 }
397
401 void inherit (Individual* mother, Individual* father)
402 {
403 recombine(_id);
404 for(unsigned int i = 0; i < _trait_nb; i++)
405 Traits[i]->inherit(mother->getTrait(i), father->getTrait(i));
406 }
407
409 void mutate ()
410 { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->mutate(); }
411
412 void recombine (unsigned long ID)
415
417 void show_up();
418
420 Individual* clone ();
421
424
427 bool operator==(const Individual& i);
428 bool operator!=(const Individual& i);
430};
431
432#endif //INDIVIDUAL_H
433
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:44
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
unsigned long _motherID
Parents ID tags.
Definition: individual.h:58
void inheritTrait(IDX T, Individual *mother, Individual *father)
Calls the inheritance procedure of a particular trait.
Definition: individual.h:309
void setFather(Individual *f)
Definition: individual.h:109
double getFecWithHomePatchMate()
Returns the proportion of succesfull local matings (i.e.
Definition: individual.h:229
void retrieve_data(BinaryStorageBuffer *reader)
Definition: individual.cc:117
Individual * init()
Inits parameters and traits.
Definition: individual.cc:53
unsigned int _trait_nb
Number of traits in the table.
Definition: individual.h:78
void createTrait(IDX i, Individual *mother, Individual *father)
Sets a particular trait's genotype and phenotype values from the two parents.
Definition: individual.h:325
unsigned long _fatherID
Definition: individual.h:58
void Aging()
Definition: individual.h:106
unsigned int getTotMatings()
Gives the total number of matings of an individual.
Definition: individual.h:152
double getFecWithOtherPatchMate()
Returns the proportion of successfull remote matings.
Definition: individual.h:237
void setCurrentID(unsigned long value)
Definition: individual.h:113
~Individual()
Definition: individual.h:91
Individual * _mother
Parents pointers.
Definition: individual.h:60
void setID(unsigned long value)
Definition: individual.h:104
Individual * getFather()
Definition: individual.h:126
void recombine(unsigned long ID)
Definition: individual.h:412
Individual()
Definition: individual.cc:41
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:83
void setTraitValue(IDX T)
Calls the value setting procedure of a particular trait.
Definition: individual.h:261
sex_t _sex
Sex tag.
Definition: individual.h:56
unsigned long getID()
Definition: individual.h:122
void mutateTrait(IDX T)
Calls the mutation procedure of a particular trait.
Definition: individual.h:317
void reset_counters()
Resets the mating and fecundity counters.
Definition: individual.h:210
Individual & operator=(const Individual &i)
Assignment, make a deep copy of the parameter values and traits.
Definition: individual.cc:161
unsigned short getHome()
Definition: individual.h:128
unsigned int getTotRealizedFecundity()
Gives the total number of surviving offspring for all categories of mating.
Definition: individual.h:176
Individual * getMother()
Definition: individual.h:127
unsigned short getMatings(unsigned int cat)
Gives the number of matings that individual had with mates from a given pedigree class.
Definition: individual.h:142
unsigned char _pedigreeClass
Pedigree class of the individual.
Definition: individual.h:70
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:247
std::deque< TTrait * > & getTraits()
Accessot to the traits table itself.
Definition: individual.h:251
void mutate()
Calls the mutation procedure of all the traits present in the individual.
Definition: individual.h:409
unsigned short _realizedFecundity[5]
Number of surviving offspring from the different mating categories (see matings).
Definition: individual.h:76
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:115
void setMother(Individual *m)
Definition: individual.h:110
Individual * create(bool do_inherit, bool do_mutate)
Creates an individual's genotypes and phenotypes with optional recombination or mutations.
Definition: individual.h:372
unsigned short getAge()
Definition: individual.h:123
void clearTraits()
Clears the traits container.
Definition: individual.h:300
unsigned short _home
Natal Patch tag.
Definition: individual.h:62
double _fecundity
Assigned fecundity.
Definition: individual.h:72
void reset()
Resets parameters and traits values.
Definition: individual.cc:79
unsigned short _age
Age.
Definition: individual.h:54
void addTrait(TTrait *theTrait, IDX pos)
Adds a trait to the table.
Definition: individual.h:288
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
double getFecundity()
Definition: individual.h:133
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:362
Individual * createTrait(IDX i, bool do_inherit, bool do_mutate)
Creates an individual's genotypes and phenotypes with optional recombination or mutations on one trai...
Definition: individual.h:339
void store_data(BinaryStorageBuffer *saver)
Definition: individual.cc:102
double setFecundity(double value)
Sets the fecundity to the value given and returns it.
Definition: individual.h:207
void inherit(Individual *mother, Individual *father)
Calls the inheritance procedure of all the traits present in the individual.
Definition: individual.h:401
void setIsSelfed(bool s)
Definition: individual.h:114
void setHome(unsigned short value)
Definition: individual.h:111
unsigned long getMotherID()
Definition: individual.h:125
int IDX
Definition: individual.h:85
void * setTrait(IDX T, void *value)
Sets the phenotype/value of a trait to a particular value.
Definition: individual.h:256
void show_up()
Write some info to stdout.
Definition: individual.cc:132
std::deque< TTrait * > Traits
The traits table.
Definition: individual.h:88
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:149
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
void setMotherID(unsigned long value)
Definition: individual.h:108
void removeTrait(IDX T)
Removes a trait from the table.
Definition: individual.h:296
void setSex(sex_t sex)
Definition: individual.h:112
unsigned short getRealizedFecundity(unsigned int cat)
Gives the number of surviving offspring for a given pedigree class of mating.
Definition: individual.h:164
sex_t getSex()
Definition: individual.h:129
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:225
Individual * create_first_gen()
Creates an individual's genotypes and phenotypes for first generation.
Definition: individual.h:348
void setTraitValue()
Calls the value setting procedure of all traits present in an individual.
Definition: individual.h:265
unsigned int getLocalRealizedFecundity()
Gives the total number of surviving offspring when mating occures with mates of the same patch.
Definition: individual.h:170
unsigned short _matings[5]
Mating counter.
Definition: individual.h:74
unsigned long _id
ID tag, unique for one simulation.
Definition: individual.h:52
void setFatherID(unsigned long value)
Definition: individual.h:107
void setAge(unsigned short value)
Definition: individual.h:105
Individual * _father
Definition: individual.h:60
Individual * create(Individual *mother, Individual *father)
Creates an individual, inherit, mutate and set all its trait's values.
Definition: individual.h:383
void setPedigreeClass(unsigned char ped)
Definition: individual.h:116
bool operator==(const Individual &i)
Only checks for traits equivalence.
Definition: individual.cc:204
bool isFemale()
Definition: individual.h:130
bool operator!=(const Individual &i)
Definition: individual.cc:222
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
unsigned long getFatherID()
Definition: individual.h:124
unsigned long getcurrentID()
Definition: individual.h:132
bool getIsSelfed()
Definition: individual.h:131
unsigned short getLocalMatings()
Gives the number of times an individual mated with an individual from the same patch.
Definition: individual.h:147
void addMating(unsigned int category)
Increments the mating counter according to the pedigree class of the offspring.
Definition: individual.h:219
static void recombine(unsigned long indID)
Definition: ttrait_with_map.cc:591
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:46
virtual void * set_trait(void *value)=0
Called to set the phenotypic to a particular value or to give context-dependant value(s) to the trait...
virtual void inherit(TTrait *mother, TTrait *father)=0
Inheritance procedure, creates a new trait from mother's and father's traits.
virtual void mutate()=0
Mutation procedure, perform mutations on the genes sequence.
virtual void set_value()=0
Tells the trait to set its phenotype from genotype, should be used instead of getValue().
virtual void * getValue() const =0
Genotype to phenotype mapper.
void fatal(const char *str,...)
Definition: output.cc:96
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
@ FEM
Definition: types.h:37

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