Nemo  2.3.56
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, double **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 ( )
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
TProtoQuanti * _QuantiProto
Definition: LCEquanti.h:45
bool _doByTraitValue
Definition: LCEquanti.h:43
unsigned int _nLoci
Definition: LCEquanti.h:44
unsigned int _nTraits
Definition: LCEquanti.h:44
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ MAT
Definition: types.h:78

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
51{ }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_QuantiInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

66{return 0;}

◆ clone()

virtual LifeCycleEvent * LCE_QuantiInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

57{return new LCE_QuantiInit();}
LCE_QuantiInit()
Definition: LCEquanti.cc:41

References LCE_QuantiInit().

◆ execute()

void LCE_QuantiInit::execute ( )
virtual

Implements LifeCycleEvent.

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

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

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

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 
)
153{
154 Individual* ind;
155 TTQuanti* trait;
156
157 for (unsigned int i = 0; i < size ; i++) {
158 ind = _popPtr->get(SEX, age, i, deme);
159 trait = dynamic_cast<TTQuanti*> ( ind->getTrait(_LCELinkedTraitIndex) );
160// trait->set_init_value(values);
161 trait->init_sequence(); // this function reads the init values from the trait prototype
162 trait->set_value();
163 }
164
165}
virtual void init_sequence()
Definition: ttquanti.cc:1478

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_QuantiInit::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

62{}

◆ loadStatServices()

virtual void LCE_QuantiInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

63{}

◆ removeAgeClass()

virtual age_t LCE_QuantiInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

65{return 0;}

◆ requiredAgeClass()

virtual age_t LCE_QuantiInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

67{return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

64{return false;}

◆ setParameters()

bool LCE_QuantiInit::setParameters ( )
virtual

Implements SimComponent.

51{
52 TMatrix pat_mat;
53
54 // setting default values
55 unsigned int patchNbr = _popPtr->getPatchNbr();
56 _QuantiProto = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant") );
57 _nTraits = _QuantiProto -> get_nb_traits();
59 _doByAlleleFreq = false;
60 _doByTraitValue = false;
61
62 // checking user's options
63 if(_paramSet->isSet("quanti_init_trait_values")) {
64
65 if(!get_parameter("quanti_init_trait_values")->isMatrix()) {
66 fatal("\"quanti_init_trait_values\" accepts only a matrix as argument.\n");
67 return false;
68 }
69 _paramSet->getMatrix("quanti_init_trait_values", &pat_mat);
70
71 _doByTraitValue = setSpatialMatrix("quanti_init_trait_values", "num of quanti traits", &pat_mat, &_init_values, _nTraits, patchNbr);
72
73 }
74
75 if(_paramSet->isSet("quanti_init_freq")) {
76
77 if (_QuantiProto->get_allele_model() > 2) {
78 error("allelic model of quanti trait incompatible with initialization by allele frequency.\n");
79 error("allelic model must be di-allelic instead of continuous.\n");
80 return false;
81 }
82 _paramSet->getMatrix("quanti_init_freq", &pat_mat);
83
84 _doByAlleleFreq = setSpatialMatrix("quanti_init_freq", "num of quanti trait loci", &pat_mat, &_init_freq, _nLoci, patchNbr);
85
86 }
87
89 warning("LCE_QuantiInit:: trying to init quanti traits both by trait values and allele frequencies.");
90 warning("LCE_QuantiInit:: forcing initialization by allele frequencies.\n");
91 _doByTraitValue = false;
92 }
93
95 error("either \"quanti_init_trait_values\" or \"quanti_init_freq\" are missing for LCE quanti_init\n");
96 }
97
99}
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:304
bool isSet()
Accessor to the status flag.
Definition: param.h:288
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
unsigned int get_nb_locus()
Definition: ttquanti.h:122
unsigned int get_allele_model()
Definition: ttquanti.h:130
void fatal(const char *str,...)
Definition: output.cc:96
int error(const char *str,...)
Definition: output.cc:77
void warning(const char *str,...)
Definition: output.cc:58
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_nb_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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR