Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_QuantiInit Class Reference

Set patch-specifiec initial genotypes values. More...

#include <LCEquanti.h>

+ Inheritance diagram for LCE_QuantiInit:
+ Collaboration diagram for LCE_QuantiInit:

Public Member Functions

 LCE_QuantiInit ()
 
virtual ~LCE_QuantiInit ()
 
virtual void execute ()
 
void init_trait_value (sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
 
void init_allele_freq (sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values, const TMatrix &all_val)
 
virtual LifeCycleEventclone ()
 
virtual bool setParameters ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Private Attributes

TMatrix _init_values
 
TMatrix _init_freq
 
bool _doByTraitValue
 
bool _doByAlleleFreq
 
unsigned int _nTraits
 
unsigned int _nLoci
 
TProtoQuanti_QuantiProto
 

Additional Inherited Members

- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

Set patch-specifiec initial genotypes values.

Constructor & Destructor Documentation

◆ LCE_QuantiInit()

LCE_QuantiInit::LCE_QuantiInit ( )
40  : LifeCycleEvent("quanti_init","quant"), _doByTraitValue(0),
42  {
43  add_parameter("quanti_init_trait_values",MAT,0,0,0,0);
44  add_parameter("quanti_init_freq",MAT,0,0,0,0);
45  }
bool _doByAlleleFreq
Definition: LCEquanti.h:42
TProtoQuanti * _QuantiProto
Definition: LCEquanti.h:44
bool _doByTraitValue
Definition: LCEquanti.h:42
unsigned int _nLoci
Definition: LCEquanti.h:43
unsigned int _nTraits
Definition: LCEquanti.h:43
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ MAT
Definition: types.h:77

References SimComponent::add_parameter(), and MAT.

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~LCE_QuantiInit()

virtual LCE_QuantiInit::~LCE_QuantiInit ( )
inlinevirtual
50 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_QuantiInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

65 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_QuantiInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

56 {return new LCE_QuantiInit();}
LCE_QuantiInit()
Definition: LCEquanti.cc:40

References LCE_QuantiInit().

◆ execute()

void LCE_QuantiInit::execute ( )
virtual

Implements LifeCycleEvent.

105 {
106  if(!(_popPtr->getCurrentGeneration() == 1)) return;
107 
108  unsigned int patchNbr = _popPtr->getPatchNbr();
109 
110  if (_doByTraitValue) {
111 
112  double values[_nTraits];
113 
114  for (unsigned int i = 0; i < patchNbr ; i++) {
115 
116  _init_values.getRowView(i, _nTraits, &values[0]);
117 
118  _QuantiProto->set_init_values(&values[0], _nTraits); // the individuals use the proto to set the init values
119 
120  init_trait_value(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, &values[0]);
121  init_trait_value(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, &values[0]);
122  init_trait_value(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, &values[0]);
123  init_trait_value(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, &values[0]);
124  }
125  }
126 
127  if (_doByAlleleFreq) {
128 
129 #ifdef _DEBUG_
130  message("--- Initializing trait QUANT by frequency ---\n");
131 #endif
132 
133  double ifreq[_nLoci];
134 
135  const TMatrix allele_val = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant") )->get_diallele_values();
136 
137  for (unsigned int i = 0; i < patchNbr ; i++) {
138 
139  _init_freq.getRowView(i, _nLoci, &ifreq[0]);
140 
141  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, &ifreq[0], allele_val);
142  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, &ifreq[0], allele_val);
143  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, &ifreq[0], allele_val);
144  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, &ifreq[0], allele_val);
145  }
146  }
147 
148 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:139
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values, const TMatrix &all_val)
Definition: LCEquanti.cc:167
TMatrix _init_values
Definition: LCEquanti.h:41
void init_trait_value(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
Definition: LCEquanti.cc:152
TMatrix _init_freq
Definition: LCEquanti.h:41
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
unsigned int getPatchNbr()
Definition: metapop.h:275
unsigned int getCurrentGeneration()
Definition: metapop.h:295
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:241
TProtoQuanti.
Definition: ttquanti.h:414
void set_init_values(const double *values, unsigned int nval)
Definition: ttquanti.cc:2500
void message(const char *message,...)
Definition: output.cc:39
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

References _doByAlleleFreq, _doByTraitValue, _init_freq, _init_values, _nLoci, _nTraits, LifeCycleEvent::_popPtr, _QuantiProto, ADLTx, ADULTS, FEM, Metapop::getCurrentGeneration(), Metapop::getPatchNbr(), TMatrix::getRowView(), IndFactory::getTraitPrototype(), init_allele_freq(), init_trait_value(), MAL, message(), OFFSPRG, OFFSx, TProtoQuanti::set_init_values(), and Metapop::size().

◆ init_allele_freq()

void LCE_QuantiInit::init_allele_freq ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values,
const TMatrix all_val 
)
169 {
170  if(!size) return;
171 
172  Individual* ind;
173  TTQuanti* trait;
174 
175 
176  if(size == 1) { // just one individual in a patch
177 
178  unsigned int allele;
179 
180  for(unsigned a = 0; a < 2; a++) {
181  for(unsigned l = 0; l < _nLoci; ++l) {
182 
183  if(RAND::Uniform() < ifreq[l])
184  allele = 0;
185  else
186  allele = 1;
187 
188  ind = _popPtr->get(SEX, age, 0, deme);
189  trait = static_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
190  trait->set_allele_bit(l, a, bool(allele));
191  }
192  }
193 
194  } else {
195 
196  unsigned int num_A, num_a;
197 
198  for(unsigned a = 0; a < 2; a++) {
199  for(unsigned l = 0; l < _nLoci; ++l) {
200 
201  num_A = (unsigned int)(size * ifreq[l]);
202 
203  num_a = size - num_A;
204 
205  int ind_A[num_A];
206  int ind_a[num_a];
207 
208  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, &ind_A[0], num_a, &ind_a[0]); //sample individuals within deme, without replacement
209 
210  for (unsigned int i = 0; i < num_A ; i++) {
211  ind = _popPtr->get(SEX, age, ind_A[i], deme);
212  trait = static_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
213  trait->set_allele_bit(l, a, 0);
214  }
215 
216  for (unsigned int i = 0; i < num_a ; i++) {
217  ind = _popPtr->get(SEX, age, ind_a[i], deme);
218  trait = static_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
219  trait->set_allele_bit(l, a, 1);
220  }
221  }
222  }
223  }
224 
225  for (unsigned int i = 0; i < size; ++i) {
226  _popPtr->get(SEX, age, i, deme)->setTraitValue(_LCELinkedTraitIndex);
227  }
228 
229 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
void setTraitValue(IDX T)
Calls the value setting procedure of a particular trait.
Definition: individual.h:260
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:88
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:835
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:782
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126
TTQuanti.
Definition: ttquanti.h:60
virtual void set_allele_bit(unsigned int position, unsigned int allele, bool value)=0

References LifeCycleEvent::_LCELinkedTraitIndex, _nLoci, LifeCycleEvent::_popPtr, Metapop::get(), Individual::getTrait(), RAND::SampleSeqWithReciprocal(), TTQuanti::set_allele_bit(), Individual::setTraitValue(), and RAND::Uniform().

Referenced by execute().

+ Here is the caller graph for this function:

◆ init_trait_value()

void LCE_QuantiInit::init_trait_value ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values 
)
154 {
155  TTrait* trait;
156 
157  for (unsigned int i = 0; i < size ; i++) {
158  trait = _popPtr->get(SEX, age, i, deme)->getTrait(_LCELinkedTraitIndex);
159  trait->init_sequence(); // this function reads the init values from the trait prototype
160  trait->set_value();
161  }
162 
163 }
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
virtual void set_value()=0
Tells the trait to set its phenotype from genotype, should be used instead of getValue().
virtual void init_sequence()=0
Called at the start of each replicate, sets the initial genotypes.

References LifeCycleEvent::_LCELinkedTraitIndex, LifeCycleEvent::_popPtr, Metapop::get(), Individual::getTrait(), TTrait::init_sequence(), and TTrait::set_value().

Referenced by execute().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_QuantiInit::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

61 {}

◆ loadStatServices()

virtual void LCE_QuantiInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

62 {}

◆ removeAgeClass()

virtual age_t LCE_QuantiInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

64 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_QuantiInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

66 {return 0;}

◆ resetParameterFromSource()

virtual bool LCE_QuantiInit::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

63 {return false;}

◆ setParameters()

bool LCE_QuantiInit::setParameters ( )
virtual

Implements SimComponent.

50 {
51  TMatrix pat_mat;
52 
53  // setting default values
54  unsigned int patchNbr = _popPtr->getPatchNbr();
55  _QuantiProto = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant") );
56 
57  _nTraits = _QuantiProto -> get_num_traits();
59 
60  _doByAlleleFreq = false;
61  _doByTraitValue = false;
62 
63  // checking user's options
64  if(_paramSet->isSet("quanti_init_trait_values")) {
65 
66  if(!get_parameter("quanti_init_trait_values")->isMatrix()) {
67  fatal("\"quanti_init_trait_values\" accepts only a matrix as argument.\n");
68  }
69 
70  _paramSet->getMatrix("quanti_init_trait_values", &pat_mat);
71 
72  _doByTraitValue = setSpatialMatrix("quanti_init_trait_values", "num of quanti traits", &pat_mat, &_init_values, _nTraits, patchNbr);
73 
74  }
75 
76  if(_paramSet->isSet("quanti_init_freq")) {
77 
78  if (_QuantiProto->get_allele_model() > 2) {
79  error("quanti_init::allelic model of quanti trait incompatible with initialization by allele frequency.\n");
80  error("quanti_init::allelic model must be di-allelic instead of continuous.\n");
81  return false;
82  }
83  _paramSet->getMatrix("quanti_init_freq", &pat_mat);
84 
85  _doByAlleleFreq = setSpatialMatrix("quanti_init_freq", "num of quanti trait loci", &pat_mat, &_init_freq, _nLoci, patchNbr);
86 
87  }
88 
90  warning("quanti_init::trying to initialize quanti traits both by trait values and allele frequencies.");
91  warning("quanti_init::forcing initialization by allele frequencies.\n");
92  _doByTraitValue = false;
93  }
94 
96  error("quanti_init::either \"quanti_init_trait_values\" or \"quanti_init_freq\" are missing.\n");
97  }
98 
99  return (_doByTraitValue || _doByAlleleFreq);
100 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
bool isSet()
Accessor to the status flag.
Definition: param.h:287
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
unsigned int get_allele_model()
Definition: ttquanti.h:433
unsigned int get_num_locus()
Definition: ttquanti.h:423
void fatal(const char *str,...)
Definition: output.cc:99
int error(const char *str,...)
Definition: output.cc:78
void warning(const char *str,...)
Definition: output.cc:57
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:114

References _doByAlleleFreq, _doByTraitValue, _init_freq, _init_values, _nLoci, _nTraits, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _QuantiProto, error(), fatal(), TProtoQuanti::get_allele_model(), TProtoQuanti::get_num_locus(), SimComponent::get_parameter(), ParamSet::getMatrix(), Metapop::getPatchNbr(), IndFactory::getTraitPrototype(), ParamSet::isSet(), setSpatialMatrix(), and warning().

Member Data Documentation

◆ _doByAlleleFreq

bool LCE_QuantiInit::_doByAlleleFreq
private

Referenced by execute(), and setParameters().

◆ _doByTraitValue

bool LCE_QuantiInit::_doByTraitValue
private

Referenced by execute(), and setParameters().

◆ _init_freq

TMatrix LCE_QuantiInit::_init_freq
private

Referenced by execute(), and setParameters().

◆ _init_values

TMatrix LCE_QuantiInit::_init_values
private

Referenced by execute(), and setParameters().

◆ _nLoci

unsigned int LCE_QuantiInit::_nLoci
private

◆ _nTraits

unsigned int LCE_QuantiInit::_nTraits
private

Referenced by execute(), and setParameters().

◆ _QuantiProto

TProtoQuanti* LCE_QuantiInit::_QuantiProto
private

Referenced by execute(), and setParameters().


The documentation for this class was generated from the following files:

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