Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
individual.h
Go to the documentation of this file.
1 
29 #ifndef INDIVIDUAL_H
30 #define INDIVIDUAL_H
31 #include <map>
32 #include <deque>
33 #include <limits>
34 #include "types.h"
35 #include "ttrait.h"
36 #include "ttrait_with_map.h"
37 #include "binarystoragebuffer.h"
38 
48 class Individual {
49 private:
51  unsigned long _id;
53  unsigned short _age;
57  unsigned long _motherID, _fatherID;
61  unsigned short _home;
69  unsigned char _pedigreeClass;
71  double _fecundity;
73  unsigned short _matings[5];
75  unsigned short _realizedFecundity[5];
77  unsigned int _trait_nb;
78 
79 public:
80 
82  static unsigned long currentID;
83 
84  typedef int IDX;
85 
87  std::deque<TTrait*> Traits;
88 
89  Individual ();
94  Individual* init ();
99  void reset ();
100 
103  void setID (unsigned long value) {_id = value;}
104  void setAge (unsigned short value) {_age = value;}
105  void Aging () {_age++;}
106  void setFatherID (unsigned long value) {_fatherID = value;}
107  void setMotherID (unsigned long value) {_motherID = value;}
108  void setFather (Individual* f) {_father = f;}
109  void setMother (Individual* m) {_mother = m;}
110  void setHome (unsigned short value) {_home = value;}
111  void setSex (sex_t sex) {_sex = sex;}
112  void setCurrentID (unsigned long value) {currentID = value;}
113  void setIsSelfed (bool s) {_pedigreeClass = (s ? 4 : 0);}
114  void setPedigreeClass (Individual* mother, Individual* father) {_pedigreeClass = getPedigreeClass(mother,father);}
115  void setPedigreeClass (unsigned char ped) {_pedigreeClass = ped;}
116 
118 
121  unsigned long getID () {return _id;}
122  unsigned short getAge () {return _age;}
123  unsigned long getFatherID () {return _fatherID;}
124  unsigned long getMotherID () {return _motherID;}
127  unsigned short getHome () {return _home;}
128  sex_t getSex () {return _sex;}
129  bool isFemale () {return (_sex == FEM);}
130  bool getIsSelfed () {return (_pedigreeClass == 4);}
131  unsigned long getcurrentID () {return currentID;}
132  double getFecundity () {return _fecundity;}
141  unsigned short getMatings (unsigned int cat)
142  {
143  return _matings[cat];
144  }
146  unsigned short getLocalMatings ( )
147  {
148  return _matings[1]+_matings[2]+_matings[3]+_matings[4];
149  }
151  unsigned int getTotMatings ( )
152  {
153  return _matings[0] + getLocalMatings();
154  }
163  unsigned short getRealizedFecundity (unsigned int cat)
164  {
165  return _realizedFecundity[cat];
166  }
167 
170  {
172  }
173 
176 
178  unsigned int getPedigreeClass ( )
179  {
180  return _pedigreeClass;
181  }
192  unsigned int getPedigreeClass (Individual* mother, Individual* father);
194 
197  void store_data ( BinaryStorageBuffer* saver );
198 
199  void retrieve_data ( BinaryStorageBuffer* reader );
201 
204 
206  double setFecundity (double value) {_fecundity = value; return value;}
207 
209  void reset_counters ( )
210  {
211  for(unsigned int i = 0; i < 5; i++) {
212  _matings[i] = 0; _realizedFecundity[i] = 0;
213  } }
214 
218  void addMating (unsigned int category)
219  { _matings[category]++; }
220 
224  void DidHaveABaby (unsigned int category)
225  { _matings[category]++; _realizedFecundity[category]++; }
226 
229  {
230  unsigned short mate = getLocalMatings();
231  return (mate != 0 ? (double) getLocalRealizedFecundity()/mate : 0.0);
232  }
237  {
238  return (_matings[0] != 0 ? (double) _realizedFecundity[0]/_matings[0] : 0.0);
239  }
241 
244 
246  unsigned int getTraitNumber() { return _trait_nb;}
247 
250  std::deque<TTrait *>& getTraits() {return Traits;}
251 
255  void* setTrait (IDX T, void* value)
256  { return getTrait(T)->set_trait(value); }
257 
261  { getTrait(T)->set_value(); }
262 
264  void setTraitValue ()
265  { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->set_value(); }
266 
270  void* getTraitValue (IDX T)
271  { return getTrait(T)->getValue(); }
272 
277  { if( T == -1 || !(T < (int)_trait_nb) )
278  fatal("Individual::Trying to access a trait not present in the traits table (at %i, size %i)\n",T,_trait_nb);
279  return Traits[T];
280  }
281 
287  void addTrait (TTrait* theTrait, IDX pos)
288  { if((int)_trait_nb != pos)
289  fatal("Individual::adding a trait to the wrong position (at %i, size %i)!\n",pos,_trait_nb);
290  Traits.push_back(theTrait); _trait_nb++;
291  }
292 
295  void removeTrait (IDX T)
296  { delete Traits[T]; Traits.erase(Traits.begin() + T); _trait_nb--;}
297 
299  void clearTraits ( )
300  { if(_trait_nb != 0) {for(unsigned int i = 0; i < Traits.size(); ++i) delete Traits[i];
301  Traits.clear(); _trait_nb = 0;}
302  }
303 
308  void inheritTrait (IDX T, Individual* mother, Individual* father)
309  {
310  recombine(_id);
311  getTrait(T)->inherit(mother->getTrait(T), father->getTrait(T));
312  }
313 
316  void mutateTrait (IDX T)
317  { getTrait(T)->mutate(); }
318 
324  void createTrait (IDX i, Individual* mother, Individual* father)
325  { if(!(mother && father))
326  fatal("Individual::create::received null pointer!!!\n");
327  TTrait* T = Traits[i];
328  recombine(_id);
329  T->inherit(mother->getTrait(i),father->getTrait(i));
330  T->mutate();
331  T->set_value();
332  }
333 
338  Individual* createTrait (IDX i, bool do_inherit, bool do_mutate)
339  {
340  if(do_inherit) inheritTrait(i, _mother, _father);
341  if(do_mutate) mutateTrait(i);
342  setTraitValue(i);
343  return this;
344  }
345 
348  {
349  for(unsigned int i = 0; i < _trait_nb; i++) {
350  Traits[i]->init_sequence();
351  Traits[i]->set_value();
352  }
353  //we have to set the parents ids otherwise the first offspring generation will be made of full sibs only.
354  static unsigned long ID = std::numeric_limits< unsigned long >::max();
355  _motherID = ID--;
356  _fatherID = ID--;
357  return this;
358  }
359 
362  {
364  mutate();
365  setTraitValue();
366  return this;
367  }
371  Individual* create (bool do_inherit, bool do_mutate)
372  {
373  if(do_inherit) inherit(_mother, _father);
374  if(do_mutate) mutate();
375  setTraitValue();
376  return this;
377  }
378 
383  {
384  if(!(mother && father))
385  fatal("Individual::create::received null parents pointer!!!\n");
386  TTrait *TT;
387  recombine(_id);
388  for(unsigned int i = 0; i < _trait_nb; i++) {
389  TT = Traits[i];
390  TT->inherit(mother->getTrait(i), father->getTrait(i));
391  TT->mutate();
392  TT->set_value();
393  }
394  return this;
395  }
396 
400  void inherit (Individual* mother, Individual* father)
401  {
402  recombine(_id);
403  for(unsigned int i = 0; i < _trait_nb; i++)
404  Traits[i]->inherit(mother->getTrait(i), father->getTrait(i));
405  }
406 
408  void mutate ()
409  { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->mutate(); }
410 
411  void recombine (unsigned long ID)
414 
416  void show_up();
417 
419  Individual* clone ();
420 
423 
424  Individual& operator=(const Individual& i);
426  bool operator==(const Individual& i);
427  bool operator!=(const Individual& i);
429 };
430 
431 #endif //INDIVIDUAL_H
432 
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:43
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
unsigned long _motherID
Parents ID tags.
Definition: individual.h:57
void inheritTrait(IDX T, Individual *mother, Individual *father)
Calls the inheritance procedure of a particular trait.
Definition: individual.h:308
void setFather(Individual *f)
Definition: individual.h:108
double getFecWithHomePatchMate()
Returns the proportion of succesfull local matings (i.e.
Definition: individual.h:228
void retrieve_data(BinaryStorageBuffer *reader)
Definition: individual.cc:116
Individual * init()
Inits parameters and traits.
Definition: individual.cc:52
unsigned int _trait_nb
Number of traits in the table.
Definition: individual.h:77
void createTrait(IDX i, Individual *mother, Individual *father)
Sets a particular trait's genotype and phenotype values from the two parents.
Definition: individual.h:324
unsigned long _fatherID
Definition: individual.h:57
void Aging()
Definition: individual.h:105
unsigned int getTotMatings()
Gives the total number of matings of an individual.
Definition: individual.h:151
double getFecWithOtherPatchMate()
Returns the proportion of successfull remote matings.
Definition: individual.h:236
void setCurrentID(unsigned long value)
Definition: individual.h:112
~Individual()
Definition: individual.h:90
void * setTrait(IDX T, void *value)
Sets the phenotype/value of a trait to a particular value.
Definition: individual.h:255
Individual * _mother
Parents pointers.
Definition: individual.h:59
void setID(unsigned long value)
Definition: individual.h:103
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:361
void recombine(unsigned long ID)
Definition: individual.h:411
Individual()
Definition: individual.cc:40
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:82
void setTraitValue(IDX T)
Calls the value setting procedure of a particular trait.
Definition: individual.h:260
sex_t _sex
Sex tag.
Definition: individual.h:55
unsigned long getID()
Definition: individual.h:121
void mutateTrait(IDX T)
Calls the mutation procedure of a particular trait.
Definition: individual.h:316
void reset_counters()
Resets the mating and fecundity counters.
Definition: individual.h:209
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:127
unsigned int getTotRealizedFecundity()
Gives the total number of surviving offspring for all categories of mating.
Definition: individual.h:175
unsigned short getMatings(unsigned int cat)
Gives the number of matings that individual had with mates from a given pedigree class.
Definition: individual.h:141
unsigned char _pedigreeClass
Pedigree class of the individual.
Definition: individual.h:69
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:246
void mutate()
Calls the mutation procedure of all the traits present in the individual.
Definition: individual.h:408
unsigned short _realizedFecundity[5]
Number of surviving offspring from the different mating categories (see matings).
Definition: individual.h:75
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:114
void setMother(Individual *m)
Definition: individual.h:109
unsigned short getAge()
Definition: individual.h:122
void clearTraits()
Clears the traits container.
Definition: individual.h:299
unsigned short _home
Natal Patch tag.
Definition: individual.h:61
double _fecundity
Assigned fecundity.
Definition: individual.h:71
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
Individual * getMother()
Definition: individual.h:126
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:270
void reset()
Resets parameters and traits values.
Definition: individual.cc:78
unsigned short _age
Age.
Definition: individual.h:53
void addTrait(TTrait *theTrait, IDX pos)
Adds a trait to the table.
Definition: individual.h:287
Individual * create(Individual *mother, Individual *father)
Creates an individual, inherit, mutate and set all its trait's values.
Definition: individual.h:382
double getFecundity()
Definition: individual.h:132
void store_data(BinaryStorageBuffer *saver)
Definition: individual.cc:101
double setFecundity(double value)
Sets the fecundity to the value given and returns it.
Definition: individual.h:206
void inherit(Individual *mother, Individual *father)
Calls the inheritance procedure of all the traits present in the individual.
Definition: individual.h:400
void setIsSelfed(bool s)
Definition: individual.h:113
void setHome(unsigned short value)
Definition: individual.h:110
unsigned long getMotherID()
Definition: individual.h:124
int IDX
Definition: individual.h:84
void show_up()
Write some info to stdout.
Definition: individual.cc:131
std::deque< TTrait * > Traits
The traits table.
Definition: individual.h:87
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:149
void setMotherID(unsigned long value)
Definition: individual.h:107
Individual * getFather()
Definition: individual.h:125
void removeTrait(IDX T)
Removes a trait from the table.
Definition: individual.h:295
void setSex(sex_t sex)
Definition: individual.h:111
unsigned short getRealizedFecundity(unsigned int cat)
Gives the number of surviving offspring for a given pedigree class of mating.
Definition: individual.h:163
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:338
sex_t getSex()
Definition: individual.h:128
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:224
void setTraitValue()
Calls the value setting procedure of all traits present in an individual.
Definition: individual.h:264
unsigned int getLocalRealizedFecundity()
Gives the total number of surviving offspring when mating occures with mates of the same patch.
Definition: individual.h:169
unsigned short _matings[5]
Mating counter.
Definition: individual.h:73
unsigned long _id
ID tag, unique for one simulation.
Definition: individual.h:51
void setFatherID(unsigned long value)
Definition: individual.h:106
void setAge(unsigned short value)
Definition: individual.h:104
Individual * _father
Definition: individual.h:59
void setPedigreeClass(unsigned char ped)
Definition: individual.h:115
bool operator==(const Individual &i)
Only checks for traits equivalence.
Definition: individual.cc:204
bool isFemale()
Definition: individual.h:129
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:178
unsigned long getFatherID()
Definition: individual.h:123
unsigned long getcurrentID()
Definition: individual.h:131
std::deque< TTrait * > & getTraits()
Accessot to the traits table itself.
Definition: individual.h:250
bool getIsSelfed()
Definition: individual.h:130
Individual * create(bool do_inherit, bool do_mutate)
Creates an individual's genotypes and phenotypes with optional recombination or mutations.
Definition: individual.h:371
unsigned short getLocalMatings()
Gives the number of times an individual mated with an individual from the same patch.
Definition: individual.h:146
Individual * create_first_gen()
Creates an individual's genotypes and phenotypes for first generation.
Definition: individual.h:347
void addMating(unsigned int category)
Increments the mating counter according to the pedigree class of the offspring.
Definition: individual.h:218
static void recombine(unsigned long indID)
Definition: ttrait_with_map.cc:592
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
virtual void * getValue() const =0
Genotype to phenotype mapper.
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 inherit(const TTrait *mother, const TTrait *father)=0
Inheritance procedure, creates a new trait from mother's and father's traits.
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...
void fatal(const char *str,...)
Definition: output.cc:99
Nemo2.
Nemo2.
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35
@ FEM
Definition: types.h:36

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR