Nemo  2.3.46
LCE_NtrlInit Class Reference

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

#include <LCEquanti.h>

+ Inheritance diagram for LCE_NtrlInit:
+ Collaboration diagram for LCE_NtrlInit:

Public Member Functions

 LCE_NtrlInit ()
virtual ~LCE_NtrlInit ()
virtual void execute ()
void init_allele_freq (sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
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_freq
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...
 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
 The parameters container. More...

Detailed Description

Set patch-specifiec initial genotypes values.

Constructor & Destructor Documentation

LCE_NtrlInit::LCE_NtrlInit ( )

References SimComponent::add_parameter(), and MAT.

Referenced by clone().

213  : LifeCycleEvent("ntrl_init","ntrl"), _nLoci(0)
214 {
215  add_parameter("ntrl_init_patch_freq",MAT,1,0,0,0);
216 }
LifeCycleEvent(const char *name, const char *trait_link)
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
unsigned int _nLoci
Definition: LCEquanti.h:78
virtual LCE_NtrlInit::~LCE_NtrlInit ( )
84 { }

Member Function Documentation

virtual age_t LCE_NtrlInit::addAgeClass ( )

Implements LifeCycleEvent.

98 {return 0;}
virtual LifeCycleEvent* LCE_NtrlInit::clone ( )

Implements LifeCycleEvent.

References LCE_NtrlInit().

90 {return new LCE_NtrlInit();}
void LCE_NtrlInit::execute ( )

Implements LifeCycleEvent.

References _init_freq, _nLoci, LifeCycleEvent::_popPtr, ADLTx, ADULTS, FEM, Metapop::getCurrentGeneration(), Metapop::getPatchNbr(), TMatrix::getRowView(), init_allele_freq(), MAL, OFFSPRG, OFFSx, and Metapop::size().

245 {
246  if(!(_popPtr->getCurrentGeneration() == 1)) return;
248  unsigned int patchNbr = _popPtr->getPatchNbr();
250  double *values = new double[_nLoci];
252  for (unsigned int i = 0; i < patchNbr ; i++) {
254  _init_freq.getRowView(i, _nLoci, values);
256  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values);
257  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values);
258  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values);
259  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values);
260  }
262  if(values) delete [] values;
263 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
unsigned int getCurrentGeneration()
Definition: metapop.h:286
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:42
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:169
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int _nLoci
Definition: LCEquanti.h:78
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
TMatrix _init_freq
Definition: LCEquanti.h:77
void LCE_NtrlInit::init_allele_freq ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values 

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

Referenced by execute().

269 {
270  if(!size) return;
272  Individual* ind;
273  TTNeutralGenes* trait;
274  unsigned int num_A, num_a;
275  unsigned int *ind_A = 0, *ind_a = 0;
277  for(unsigned a = 0; a < 2; a++) {
278  for(unsigned l = 0; l < _nLoci; l++) {
280  num_A = (unsigned int)(size * values[l]); //number of '0' allele
281  num_a = size - num_A; //number of '1' allele
283  ind_A = new unsigned int [num_A];
284  ind_a = new unsigned int [num_a];
286  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, (int*)ind_A, num_a, (int*)ind_a); //sample individuals within deme, without replacement
288  for (unsigned int i = 0; i < num_A ; i++) {
289  ind = _popPtr->get(SEX, age, ind_A[i], deme);
290  trait = dynamic_cast<TTNeutralGenes*> ( ind->getTrait(_LCELinkedTraitIndex) );
291  trait->set_allele(l, a, 0);
292  }
294  for (unsigned int i = 0; i < num_a ; i++) {
295  ind = _popPtr->get(SEX, age, ind_a[i], deme);
296  trait = dynamic_cast<TTNeutralGenes*> ( ind->getTrait(_LCELinkedTraitIndex) );
297  trait->set_allele(l, a, 1);
298  }
300  delete [] ind_A;
301  delete [] ind_a;
302  }
303  }
304 }
void set_allele(unsigned int loc, unsigned int al, unsigned char val)
Definition: ttneutralgenes.h:106
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
Microsatellites genome.
Definition: ttneutralgenes.h:52
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:578
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
unsigned int _nLoci
Definition: LCEquanti.h:78
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_NtrlInit::loadFileServices ( FileServices loader)

Implements SimComponent.

95 {}
virtual void LCE_NtrlInit::loadStatServices ( StatServices loader)

Implements SimComponent.

96 {}
virtual age_t LCE_NtrlInit::removeAgeClass ( )

Implements LifeCycleEvent.

97 {return 0;}
virtual age_t LCE_NtrlInit::requiredAgeClass ( )

Implements LifeCycleEvent.

99 {return 0;}
bool LCE_NtrlInit::setParameters ( )

Implements SimComponent.

References _init_freq, _nLoci, SimComponent::_paramSet, LifeCycleEvent::_popPtr, error(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), ParamSet::getMatrix(), Metapop::getPatchNbr(), IndFactory::getTraitPrototype(), and setSpatialMatrix().

221 {
222  TMatrix pat_mat;
223  unsigned int patchNbr = _popPtr->getPatchNbr();
224  TProtoNeutralGenes* proto = dynamic_cast<TProtoNeutralGenes*> ( _popPtr->getTraitPrototype("ntrl") );
226  if(proto->get_allele_num() > 2) {
227  error("LCE ntrl_init only works for di-allelic neutral loci, sorry.\n\
228  Please consider using an FSTAT input file for more complex cases.\n");
229  return false;
230  }
232  _nLoci = proto->get_locus_num();
234  _paramSet->getMatrix("ntrl_init_patch_freq", &pat_mat);
236  if( !setSpatialMatrix("ntrl_init_patch_freq", "num of neutral loci", &pat_mat, &_init_freq, _nLoci, patchNbr) )
237  return false;
239  return true;
240 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
unsigned int get_allele_num()
Definition: ttneutralgenes.h:189
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
Prototype class for the TTNeutralGenes trait class.
Definition: ttneutralgenes.h:163
unsigned int _nLoci
Definition: LCEquanti.h:78
unsigned int get_locus_num()
Definition: ttneutralgenes.h:188
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
TMatrix _init_freq
Definition: LCEquanti.h:77

Member Data Documentation

TMatrix LCE_NtrlInit::_init_freq

Referenced by execute(), and setParameters().

unsigned int LCE_NtrlInit::_nLoci

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