Nemo  2.3.46
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, double **all_val)
 
virtual LifeCycleEventclone ()
 
virtual bool setParameters ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
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...
 

Private Attributes

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

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 ( )

References SimComponent::add_parameter(), and MAT.

Referenced by clone().

41  : LifeCycleEvent("quanti_init","quant"), _doByTraitValue(0),
43  {
44  add_parameter("quanti_init_trait_values",MAT,0,0,0,0);
45  add_parameter("quanti_init_freq",MAT,0,0,0,0);
46  }
bool _doByAlleleFreq
Definition: LCEquanti.h:43
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Definition: types.h:78
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
bool _doByTraitValue
Definition: LCEquanti.h:43
virtual LCE_QuantiInit::~LCE_QuantiInit ( )
inlinevirtual
50 { }

Member Function Documentation

virtual age_t LCE_QuantiInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

64 {return 0;}
virtual LifeCycleEvent* LCE_QuantiInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

References LCE_QuantiInit().

56 {return new LCE_QuantiInit();}
LCE_QuantiInit()
Definition: LCEquanti.cc:41
void LCE_QuantiInit::execute ( )
virtual

Implements LifeCycleEvent.

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

100 {
101  if(!(_popPtr->getCurrentGeneration() == 1)) return;
102 
103  unsigned int patchNbr = _popPtr->getPatchNbr();
104 
105  double *values = NULL;
106 
107  if (_doByTraitValue) {
108 
109  values = new double[_nTraits];
110 
111  for (unsigned int i = 0; i < patchNbr ; i++) {
112 
113  _init_values.getRowView(i, _nTraits, values);
114 
115  init_trait_value(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values);
116  init_trait_value(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values);
117  init_trait_value(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values);
118  init_trait_value(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values);
119  }
120  }
121 
122  if (_doByAlleleFreq) {
123 
124  if(values) delete [] values;
125 
126  values = new double[_nLoci];
127 
128  double **allele_val = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant") )->get_allele_values();
129 
130  for (unsigned int i = 0; i < patchNbr ; i++) {
131 
132  _init_freq.getRowView(i, _nLoci, values);
133 
134  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values, allele_val);
135  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values, allele_val);
136  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values, allele_val);
137  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values, allele_val);
138  }
139  }
140 
141  if(values) delete [] values;
142 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
bool _doByAlleleFreq
Definition: LCEquanti.h:43
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
unsigned int getCurrentGeneration()
Definition: metapop.h:286
void init_trait_value(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
Definition: LCEquanti.cc:146
TProtoQuanti.
Definition: ttquanti.h:147
unsigned int getPatchNbr()
Definition: metapop.h:270
unsigned int _nTraits
Definition: LCEquanti.h:44
Definition: types.h:42
TMatrix _init_values
Definition: LCEquanti.h:42
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:169
unsigned int _nLoci
Definition: LCEquanti.h:44
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values, double **all_val)
Definition: LCEquanti.cc:164
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
TMatrix _init_freq
Definition: LCEquanti.h:42
Definition: types.h:37
bool _doByTraitValue
Definition: LCEquanti.h:43
void LCE_QuantiInit::init_allele_freq ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values,
double **  all_val 
)

References LifeCycleEvent::_LCELinkedTraitIndex, _nLoci, LifeCycleEvent::_popPtr, Metapop::get(), Individual::getTrait(), RAND::SampleSeqWithReciprocal(), TTQuanti::set_allele(), and TTQuanti::set_value().

Referenced by execute().

165 {
166  if(!size) return;
167 
168  Individual* ind;
169  TTQuanti* trait;
170  unsigned int num_A, num_a;
171  unsigned int *ind_A = 0, *ind_a = 0;
172 
173  for(unsigned a = 0; a < 2; a++) {
174  for(unsigned l = 0; l < _nLoci; l++) {
175 
176  num_A = (unsigned int)(size * values[l]);
177  num_a = size - num_A;
178 
179  ind_A = new unsigned int [num_A];
180  ind_a = new unsigned int [num_a];
181 
182  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, (int*)ind_A, num_a, (int*)ind_a); //sample individuals within deme, without replacement
183 
184  for (unsigned int i = 0; i < num_A ; i++) {
185  ind = _popPtr->get(SEX, age, ind_A[i], deme);
186  trait = dynamic_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
187  trait->set_allele(l, a, all_val[l][0]);
188  }
189  for (unsigned int i = 0; i < num_a ; i++) {
190  ind = _popPtr->get(SEX, age, ind_a[i], deme);
191  trait = dynamic_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
192  trait->set_allele(l, a, all_val[l][1]);
193  }
194 
195  delete [] ind_A;
196  delete [] ind_a;
197  }
198  }
199 
200  for (unsigned int i = 0; i < size; ++i) {
201  ind = _popPtr->get(SEX, age, i, deme);
202  trait = dynamic_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
203  trait->set_value();
204  }
205 
206 }
TTQuanti.
Definition: ttquanti.h:55
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:578
void set_allele(int locus, int allele, double value)
Definition: ttquanti.h:124
unsigned int _nLoci
Definition: LCEquanti.h:44
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:783
virtual void set_value()
Definition: ttquanti.cc:1082
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void LCE_QuantiInit::init_trait_value ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values 
)

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

Referenced by execute().

147 {
148  Individual* ind;
149  TTQuanti* trait;
150 // for(unsigned h = 0; h < _nTraits; h++)
151 
152  for (unsigned int i = 0; i < size ; i++) {
153  ind = _popPtr->get(SEX, age, i, deme);
154  trait = dynamic_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
155  trait->set_init_value(values);
156  trait->init_sequence();
157  trait->set_value();
158  }
159 
160 }
TTQuanti.
Definition: ttquanti.h:55
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
void set_init_value(double *val, unsigned int doInit)
Definition: ttquanti.cc:840
virtual void init_sequence()
Definition: ttquanti.cc:879
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:783
virtual void set_value()
Definition: ttquanti.cc:1082
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
virtual void LCE_QuantiInit::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

61 {}
virtual void LCE_QuantiInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

62 {}
virtual age_t LCE_QuantiInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

63 {return 0;}
virtual age_t LCE_QuantiInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

65 {return 0;}
bool LCE_QuantiInit::setParameters ( )
virtual

Implements SimComponent.

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

51 {
52  TMatrix pat_mat;
53  unsigned int patchNbr = _popPtr->getPatchNbr();
54  TProtoQuanti* proto = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant") );
55 
56  _nTraits = proto -> get_nb_traits();
57  _nLoci = proto->get_nb_locus();
58 
59  if(_paramSet->isSet("quanti_init_trait_values")) {
60 
61  if(!get_parameter("quanti_init_trait_values")->isMatrix()) {
62  fatal("\"quanti_init_trait_values\" accepts only a matrix as argument.\n");
63  return false;
64  }
65  _paramSet->getMatrix("quanti_init_trait_values", &pat_mat);
66 
67  _doByTraitValue = setSpatialMatrix("quanti_init_trait_values", "num of quanti traits", &pat_mat, &_init_values, _nTraits, patchNbr);
68 
69  }
70 
71  if(_paramSet->isSet("quanti_init_freq")) {
72 
73  if (proto->get_allele_model() > 2) {
74  error("allelic model of quanti trait incompatible with initialization by allele frequency.\n");
75  error("allelic model must be di-allelic instead of continuous.\n");
76  return false;
77  }
78  _paramSet->getMatrix("quanti_init_freq", &pat_mat);
79 
80  _doByAlleleFreq = setSpatialMatrix("quanti_init_freq", "num of quanti trait loci", &pat_mat, &_init_freq, _nLoci, patchNbr);
81 
82  }
83 
85  warning("LCE_QuantiInit:: trying to init quanti traits both by trait values and allele frequencies.");
86  warning("LCE_QuantiInit:: forcing initialization by allele frequencies.\n");
87  _doByTraitValue = false;
88  }
89 
91  error("either \"quanti_init_trait_values\" or \"quanti_init_freq\" are missing for LCE quanti_init\n");
92  }
93 
94  return (_doByTraitValue || _doByAlleleFreq);
95 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
bool _doByAlleleFreq
Definition: LCEquanti.h:43
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:87
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
void fatal(const char *str,...)
Definition: output.cc:90
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
TProtoQuanti.
Definition: ttquanti.h:147
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
unsigned int _nTraits
Definition: LCEquanti.h:44
void warning(const char *str,...)
Definition: output.cc:56
TMatrix _init_values
Definition: LCEquanti.h:42
unsigned int _nLoci
Definition: LCEquanti.h:44
unsigned int get_allele_model()
Definition: ttquanti.h:161
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
bool isSet()
Accessor to the status flag.
Definition: param.h:273
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
TMatrix _init_freq
Definition: LCEquanti.h:42
unsigned int get_nb_locus()
Definition: ttquanti.h:156
bool _doByTraitValue
Definition: LCEquanti.h:43

Member Data Documentation

bool LCE_QuantiInit::_doByAlleleFreq
private

Referenced by execute(), and setParameters().

bool LCE_QuantiInit::_doByTraitValue
private

Referenced by execute(), and setParameters().

TMatrix LCE_QuantiInit::_init_freq
private

Referenced by execute(), and setParameters().

TMatrix LCE_QuantiInit::_init_values
private

Referenced by execute(), and setParameters().

unsigned int LCE_QuantiInit::_nLoci
private
unsigned int LCE_QuantiInit::_nTraits
private

Referenced by execute(), and setParameters().


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

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