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

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

#include <ttneutralgenes.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 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_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...
 
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_NtrlInit()

LCE_NtrlInit::LCE_NtrlInit ( )
2612  : LifeCycleEvent("ntrl_init","ntrl"), _nLoci(0)
2613 {
2614  add_parameter("ntrl_init_patch_freq",MAT,1,0,0,0);
2615 }
unsigned int _nLoci
Definition: ttneutralgenes.h:581
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_NtrlInit()

virtual LCE_NtrlInit::~LCE_NtrlInit ( )
inlinevirtual
587 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_NtrlInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

602 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_NtrlInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

593 {return new LCE_NtrlInit();}
LCE_NtrlInit()
Definition: ttneutralgenes.cc:2612

References LCE_NtrlInit().

◆ execute()

void LCE_NtrlInit::execute ( )
virtual

Implements LifeCycleEvent.

2644 {
2645  if(!(_popPtr->getCurrentGeneration() == 1)) return;
2646 
2647  unsigned int patchNbr = _popPtr->getPatchNbr();
2648 
2649  double *values = new double[_nLoci];
2650 
2651  for (unsigned int i = 0; i < patchNbr ; i++) {
2652 
2653  _init_freq.getRowView(i, _nLoci, values);
2654 
2655  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values);
2656  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values);
2657  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values);
2658  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values);
2659  }
2660 
2661  if(values) delete [] values;
2662 }
TMatrix _init_freq
Definition: ttneutralgenes.h:580
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
Definition: ttneutralgenes.cc:2667
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
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:241
@ 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 _init_freq, _nLoci, LifeCycleEvent::_popPtr, ADLTx, ADULTS, FEM, Metapop::getCurrentGeneration(), Metapop::getPatchNbr(), TMatrix::getRowView(), init_allele_freq(), MAL, OFFSPRG, OFFSx, and Metapop::size().

◆ init_allele_freq()

void LCE_NtrlInit::init_allele_freq ( sex_t  SEX,
age_idx  AGE,
unsigned int  size,
unsigned int  deme,
double *  values 
)
2668 {
2669  if(!size) return;
2670 
2671  Individual* ind;
2672  TTrait* trait;
2673  unsigned int num_A, num_a;
2674  unsigned int *ind_A = 0, *ind_a = 0;
2675 
2676  for(unsigned a = 0; a < 2; a++) {
2677  for(unsigned l = 0; l < _nLoci; l++) {
2678 
2679  num_A = (unsigned int)(size * values[l]); //number of '0' allele
2680  num_a = size - num_A; //number of '1' allele
2681 
2682  ind_A = new unsigned int [num_A];
2683  ind_a = new unsigned int [num_a];
2684 
2685  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, (int*)ind_A, num_a, (int*)ind_a); //sample individuals within deme, without replacement
2686 
2687  for (unsigned int i = 0; i < num_A ; i++) {
2688  ind = _popPtr->get(SEX, age, ind_A[i], deme);
2689  trait = ind->getTrait(_LCELinkedTraitIndex);
2690  trait->set_allele_value(l, a, 0.0);
2691  }
2692 
2693  for (unsigned int i = 0; i < num_a ; i++) {
2694  ind = _popPtr->get(SEX, age, ind_a[i], deme);
2695  trait = ind->getTrait(_LCELinkedTraitIndex);
2696  trait->set_allele_value(l, a, 1.0);
2697  }
2698 
2699  delete [] ind_A;
2700  delete [] ind_a;
2701  }
2702  }
2703 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
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
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
virtual void set_allele_value(unsigned int locus, unsigned int allele, double value)=0
Called to change the allelic value at a particular locus.

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_NtrlInit::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

598 {}

◆ loadStatServices()

virtual void LCE_NtrlInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

599 {}

◆ removeAgeClass()

virtual age_t LCE_NtrlInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

601 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_NtrlInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

603 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

600 {return false;}

◆ setParameters()

bool LCE_NtrlInit::setParameters ( )
virtual

Implements SimComponent.

2620 {
2621  TMatrix pat_mat;
2622  unsigned int patchNbr = _popPtr->getPatchNbr();
2623  TProtoNeutralGenes* proto = dynamic_cast<TProtoNeutralGenes*> ( _popPtr->getTraitPrototype("ntrl") );
2624 
2625  if(proto->get_allele_num() > 2) {
2626  error("LCE ntrl_init only works for di-allelic neutral loci, sorry.\n\
2627  Please consider using an FSTAT input file for more complex cases.\n");
2628  return false;
2629  }
2630 
2631  _nLoci = proto->get_locus_num();
2632 
2633  _paramSet->getMatrix("ntrl_init_patch_freq", &pat_mat);
2634 
2635  if( !setSpatialMatrix("ntrl_init_patch_freq", "num of neutral loci", &pat_mat, &_init_freq, _nLoci, patchNbr) )
2636  return false;
2637 
2638  return true;
2639 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:139
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
Prototype class for the TTNeutralGenes trait class.
Definition: ttneutralgenes.h:171
unsigned int get_locus_num()
Definition: ttneutralgenes.h:199
unsigned int get_allele_num()
Definition: ttneutralgenes.h:200
int error(const char *str,...)
Definition: output.cc:78
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:114

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

Member Data Documentation

◆ _init_freq

TMatrix LCE_NtrlInit::_init_freq
private

Referenced by execute(), and setParameters().

◆ _nLoci

unsigned int LCE_NtrlInit::_nLoci
private

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