Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
individual.h
Go to the documentation of this file.
1 
28 #ifndef INDIVIDUAL_H
29 #define INDIVIDUAL_H
30 #include <map>
31 #include <deque>
32 #include <limits>
33 #include "types.h"
34 #include "ttrait.h"
35 #include "ttrait_with_map.h"
36 #include "binarystoragebuffer.h"
37 
47 class Individual {
48 private:
50  unsigned long _id;
52  unsigned short _age;
56  unsigned long _motherID, _fatherID;
60  unsigned short _home;
68  unsigned char _pedigreeClass;
70  double _fecundity;
72  unsigned short _matings[5];
74  unsigned short _realizedFecundity[5];
76  unsigned int _trait_nb;
77 
78 public:
79 
81  static unsigned long currentID;
82 
83  typedef int IDX;
84 
86  std::deque<TTrait*> Traits;
87 
88  Individual ();
93  Individual* init ();
98  void reset ();
99 
102  void setID (unsigned long value) {_id = value;}
103  void setAge (unsigned short value) {_age = value;}
104  void Aging () {_age++;}
105  void setFatherID (unsigned long value) {_fatherID = value;}
106  void setMotherID (unsigned long value) {_motherID = value;}
107  void setFather (Individual* f) {_father = f;}
108  void setMother (Individual* m) {_mother = m;}
109  void setHome (unsigned short value) {_home = value;}
110  void setSex (sex_t sex) {_sex = sex;}
111  void setCurrentID (unsigned long value) {currentID = value;}
112  void setIsSelfed (bool s) {_pedigreeClass = (s ? 4 : 0);}
113  void setPedigreeClass (Individual* mother, Individual* father) {_pedigreeClass = getPedigreeClass(mother,father);}
114  void setPedigreeClass (unsigned char ped) {_pedigreeClass = ped;}
115 
117 
120  unsigned long getID () {return _id;}
121  unsigned short getAge () {return _age;}
122  unsigned long getFatherID () {return _fatherID;}
123  unsigned long getMotherID () {return _motherID;}
126  unsigned short getHome () {return _home;}
127  sex_t getSex () {return _sex;}
128  bool isFemale () {return (_sex == FEM);}
129  bool getIsSelfed () {return (_pedigreeClass == 4);}
130  unsigned long getcurrentID () {return currentID;}
131  double getFecundity () {return _fecundity;}
140  unsigned short getMatings (unsigned int cat)
141  {
142  return _matings[cat];
143  }
145  unsigned short getLocalMatings ( )
146  {
147  return _matings[1]+_matings[2]+_matings[3]+_matings[4];
148  }
150  unsigned int getTotMatings ( )
151  {
152  return _matings[0] + getLocalMatings();
153  }
162  unsigned short getRealizedFecundity (unsigned int cat)
163  {
164  return _realizedFecundity[cat];
165  }
166 
169  {
171  }
172 
175 
177  unsigned int getPedigreeClass ( )
178  {
179  return _pedigreeClass;
180  }
191  unsigned int getPedigreeClass (Individual* mother, Individual* father);
193 
196  void store_data ( BinaryStorageBuffer* saver );
197 
198  void retrieve_data ( BinaryStorageBuffer* reader );
200 
203 
205  double setFecundity (double value) {_fecundity = value; return value;}
206 
208  void reset_counters ( )
209  {
210  for(unsigned int i = 0; i < 5; i++) {
211  _matings[i] = 0; _realizedFecundity[i] = 0;
212  } }
213 
217  void addMating (unsigned int category)
218  { _matings[category]++; }
219 
223  void DidHaveABaby (unsigned int category)
224  { _matings[category]++; _realizedFecundity[category]++; }
225 
228  {
229  unsigned short mate = getLocalMatings();
230  return (mate != 0 ? (double) getLocalRealizedFecundity()/mate : 0.0);
231  }
236  {
237  return (_matings[0] != 0 ? (double) _realizedFecundity[0]/_matings[0] : 0.0);
238  }
240 
243 
245  unsigned int getTraitNumber() { return _trait_nb;}
246 
249  std::deque<TTrait *>& getTraits() {return Traits;}
250 
254  void* setTrait (IDX T, void* value)
255  { return getTrait(T)->set_trait(value); }
256 
260  { getTrait(T)->set_value(); }
261 
263  void setTraitValue ()
264  { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->set_value(); }
265 
269  void* getTraitValue (IDX T)
270  { return getTrait(T)->getValue(); }
271 
276  { if( T == -1 || !(T < (int)_trait_nb) )
277  fatal("Individual::Trying to access a trait not present in the traits table (at %i, size %i)\n",T,_trait_nb);
278  return Traits[T];
279  }
280 
286  void addTrait (TTrait* theTrait, IDX pos)
287  { if((int)_trait_nb != pos)
288  fatal("Individual::adding a trait to the wrong position (at %i, size %i)!\n",pos,_trait_nb);
289  Traits.push_back(theTrait); _trait_nb++;
290  }
291 
294  void removeTrait (IDX T)
295  { delete Traits[T]; Traits.erase(Traits.begin() + T); _trait_nb--;}
296 
298  void clearTraits ( )
299  { if(_trait_nb != 0) {for(unsigned int i = 0; i < Traits.size(); ++i) delete Traits[i];
300  Traits.clear(); _trait_nb = 0;}
301  }
302 
307  void inheritTrait (IDX T, Individual* mother, Individual* father)
308  {
309  recombine(_id);
310  getTrait(T)->inherit(mother->getTrait(T), father->getTrait(T));
311  }
312 
315  void mutateTrait (IDX T)
316  { getTrait(T)->mutate(); }
317 
323  void createTrait (IDX i, Individual* mother, Individual* father)
324  { if(!(mother && father))
325  fatal("Individual::create::received null pointer!!!\n");
326  TTrait* T = Traits[i];
327  recombine(_id);
328  T->inherit(mother->getTrait(i),father->getTrait(i));
329  T->mutate();
330  T->set_value();
331  }
332 
337  Individual* createTrait (IDX i, bool do_inherit, bool do_mutate)
338  {
339  if(do_inherit) inheritTrait(i, _mother, _father);
340  if(do_mutate) mutateTrait(i);
341  setTraitValue(i);
342  return this;
343  }
344 
347  {
348  for(unsigned int i = 0; i < _trait_nb; i++) {
349  Traits[i]->init_sequence();
350  Traits[i]->set_value();
351  }
352  //we have to set the parents ids otherwise the first offspring generation will be made of full sibs only.
353  static unsigned long ID = std::numeric_limits< unsigned long >::max();
354  _motherID = ID--;
355  _fatherID = ID--;
356  return this;
357  }
358 
361  {
363  mutate();
364  setTraitValue();
365  return this;
366  }
370  Individual* create (bool do_inherit, bool do_mutate)
371  {
372  if(do_inherit) inherit(_mother, _father);
373  if(do_mutate) mutate();
374  setTraitValue();
375  return this;
376  }
377 
382  {
383  if(!(mother && father))
384  fatal("Individual::create::received null parents pointer!!!\n");
385  TTrait *TT;
386  recombine(_id);
387  for(unsigned int i = 0; i < _trait_nb; i++) {
388  TT = Traits[i];
389  TT->inherit(mother->getTrait(i), father->getTrait(i));
390  TT->mutate();
391  TT->set_value();
392  }
393  return this;
394  }
395 
399  void inherit (Individual* mother, Individual* father)
400  {
401  recombine(_id);
402  for(unsigned int i = 0; i < _trait_nb; i++)
403  Traits[i]->inherit(mother->getTrait(i), father->getTrait(i));
404  }
405 
407  void mutate ()
408  { for(unsigned int i = 0; i < _trait_nb; i++) Traits[i]->mutate(); }
409 
410  void recombine (unsigned long ID)
413 
415  void show_up();
416 
418  Individual* clone ();
419 
422 
423  Individual& operator=(const Individual& i);
425  bool operator==(const Individual& i);
426  bool operator!=(const Individual& i);
428 };
429 
430 #endif //INDIVIDUAL_H
431 
A class to store any kind of data in a char buffer before unloading it in a binary data file.
Definition: binarystoragebuffer.h:42
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
unsigned long _motherID
Parents ID tags.
Definition: individual.h:56
void inheritTrait(IDX T, Individual *mother, Individual *father)
Calls the inheritance procedure of a particular trait.
Definition: individual.h:307
void setFather(Individual *f)
Definition: individual.h:107
double getFecWithHomePatchMate()
Returns the proportion of succesfull local matings (i.e.
Definition: individual.h:227
void retrieve_data(BinaryStorageBuffer *reader)
Definition: individual.cc:115
Individual * init()
Inits parameters and traits.
Definition: individual.cc:51
unsigned int _trait_nb
Number of traits in the table.
Definition: individual.h:76
void createTrait(IDX i, Individual *mother, Individual *father)
Sets a particular trait's genotype and phenotype values from the two parents.
Definition: individual.h:323
unsigned long _fatherID
Definition: individual.h:56
void Aging()
Definition: individual.h:104
unsigned int getTotMatings()
Gives the total number of matings of an individual.
Definition: individual.h:150
double getFecWithOtherPatchMate()
Returns the proportion of successfull remote matings.
Definition: individual.h:235
void setCurrentID(unsigned long value)
Definition: individual.h:111
~Individual()
Definition: individual.h:89
void * setTrait(IDX T, void *value)
Sets the phenotype/value of a trait to a particular value.
Definition: individual.h:254
Individual * _mother
Parents pointers.
Definition: individual.h:58
void setID(unsigned long value)
Definition: individual.h:102
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:360
void recombine(unsigned long ID)
Definition: individual.h:410
Individual()
Definition: individual.cc:39
static unsigned long currentID
The ID counter, reset at the beginning of each simulation.
Definition: individual.h:81
void setTraitValue(IDX T)
Calls the value setting procedure of a particular trait.
Definition: individual.h:259
sex_t _sex
Sex tag.
Definition: individual.h:54
unsigned long getID()
Definition: individual.h:120
void mutateTrait(IDX T)
Calls the mutation procedure of a particular trait.
Definition: individual.h:315
void reset_counters()
Resets the mating and fecundity counters.
Definition: individual.h:208
Individual & operator=(const Individual &i)
Assignment, make a deep copy of the parameter values and traits.
Definition: individual.cc:160
unsigned short getHome()
Definition: individual.h:126
unsigned int getTotRealizedFecundity()
Gives the total number of surviving offspring for all categories of mating.
Definition: individual.h:174
unsigned short getMatings(unsigned int cat)
Gives the number of matings that individual had with mates from a given pedigree class.
Definition: individual.h:140
unsigned char _pedigreeClass
Pedigree class of the individual.
Definition: individual.h:68
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:245
void mutate()
Calls the mutation procedure of all the traits present in the individual.
Definition: individual.h:407
unsigned short _realizedFecundity[5]
Number of surviving offspring from the different mating categories (see matings).
Definition: individual.h:74
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:113
void setMother(Individual *m)
Definition: individual.h:108
unsigned short getAge()
Definition: individual.h:121
void clearTraits()
Clears the traits container.
Definition: individual.h:298
unsigned short _home
Natal Patch tag.
Definition: individual.h:60
double _fecundity
Assigned fecundity.
Definition: individual.h:70
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
Individual * getMother()
Definition: individual.h:125
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:269
void reset()
Resets parameters and traits values.
Definition: individual.cc:77
unsigned short _age
Age.
Definition: individual.h:52
void addTrait(TTrait *theTrait, IDX pos)
Adds a trait to the table.
Definition: individual.h:286
Individual * create(Individual *mother, Individual *father)
Creates an individual, inherit, mutate and set all its trait's values.
Definition: individual.h:381
double getFecundity()
Definition: individual.h:131
void store_data(BinaryStorageBuffer *saver)
Definition: individual.cc:100
double setFecundity(double value)
Sets the fecundity to the value given and returns it.
Definition: individual.h:205
void inherit(Individual *mother, Individual *father)
Calls the inheritance procedure of all the traits present in the individual.
Definition: individual.h:399
void setIsSelfed(bool s)
Definition: individual.h:112
void setHome(unsigned short value)
Definition: individual.h:109
unsigned long getMotherID()
Definition: individual.h:123
int IDX
Definition: individual.h:83
void show_up()
Write some info to stdout.
Definition: individual.cc:130
std::deque< TTrait * > Traits
The traits table.
Definition: individual.h:86
Individual * clone()
Cloning procedure, clones all the traits present in the individual.
Definition: individual.cc:148
void setMotherID(unsigned long value)
Definition: individual.h:106
Individual * getFather()
Definition: individual.h:124
void removeTrait(IDX T)
Removes a trait from the table.
Definition: individual.h:294
void setSex(sex_t sex)
Definition: individual.h:110
unsigned short getRealizedFecundity(unsigned int cat)
Gives the number of surviving offspring for a given pedigree class of mating.
Definition: individual.h:162
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:337
sex_t getSex()
Definition: individual.h:127
void DidHaveABaby(unsigned int category)
Increments the mating and realized fecundity counters according to the pedigree class of the offsprin...
Definition: individual.h:223
void setTraitValue()
Calls the value setting procedure of all traits present in an individual.
Definition: individual.h:263
unsigned int getLocalRealizedFecundity()
Gives the total number of surviving offspring when mating occures with mates of the same patch.
Definition: individual.h:168
unsigned short _matings[5]
Mating counter.
Definition: individual.h:72
unsigned long _id
ID tag, unique for one simulation.
Definition: individual.h:50
void setFatherID(unsigned long value)
Definition: individual.h:105
void setAge(unsigned short value)
Definition: individual.h:103
Individual * _father
Definition: individual.h:58
void setPedigreeClass(unsigned char ped)
Definition: individual.h:114
bool operator==(const Individual &i)
Only checks for traits equivalence.
Definition: individual.cc:203
bool isFemale()
Definition: individual.h:128
bool operator!=(const Individual &i)
Definition: individual.cc:221
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:177
unsigned long getFatherID()
Definition: individual.h:122
unsigned long getcurrentID()
Definition: individual.h:130
std::deque< TTrait * > & getTraits()
Accessot to the traits table itself.
Definition: individual.h:249
bool getIsSelfed()
Definition: individual.h:129
Individual * create(bool do_inherit, bool do_mutate)
Creates an individual's genotypes and phenotypes with optional recombination or mutations.
Definition: individual.h:370
unsigned short getLocalMatings()
Gives the number of times an individual mated with an individual from the same patch.
Definition: individual.h:145
Individual * create_first_gen()
Creates an individual's genotypes and phenotypes for first generation.
Definition: individual.h:346
void addMating(unsigned int category)
Increments the mating counter according to the pedigree class of the offspring.
Definition: individual.h:217
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:44
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:98
Nemo2.
Nemo2.
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
@ FEM
Definition: types.h:35

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR