Nemo  2.4.2
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 ( )
2611  : LifeCycleEvent("ntrl_init","ntrl"), _nLoci(0)
2612 {
2613  add_parameter("ntrl_init_patch_freq",MAT,1,0,0,0);
2614 }
unsigned int _nLoci
Definition: ttneutralgenes.h:580
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:96
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:110
@ MAT
Definition: types.h:76

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_NtrlInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

601 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_NtrlInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

592 {return new LCE_NtrlInit();}
LCE_NtrlInit()
Definition: ttneutralgenes.cc:2611

References LCE_NtrlInit().

◆ execute()

void LCE_NtrlInit::execute ( )
virtual

Implements LifeCycleEvent.

2643 {
2644  if(!(_popPtr->getCurrentGeneration() == 1)) return;
2645 
2646  unsigned int patchNbr = _popPtr->getPatchNbr();
2647 
2648  double *values = new double[_nLoci];
2649 
2650  for (unsigned int i = 0; i < patchNbr ; i++) {
2651 
2652  _init_freq.getRowView(i, _nLoci, values);
2653 
2654  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values);
2655  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values);
2656  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values);
2657  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values);
2658  }
2659 
2660  if(values) delete [] values;
2661 }
TMatrix _init_freq
Definition: ttneutralgenes.h:579
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
Definition: ttneutralgenes.cc:2666
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:79
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:274
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:240
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:52
#define OFFSPRG
Offspring age class flag.
Definition: types.h:48
@ OFFSx
Definition: types.h:40
@ ADLTx
Definition: types.h:40

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 
)
2667 {
2668  if(!size) return;
2669 
2670  Individual* ind;
2671  TTrait* trait;
2672  unsigned int num_A, num_a;
2673  unsigned int *ind_A = 0, *ind_a = 0;
2674 
2675  for(unsigned a = 0; a < 2; a++) {
2676  for(unsigned l = 0; l < _nLoci; l++) {
2677 
2678  num_A = (unsigned int)(size * values[l]); //number of '0' allele
2679  num_a = size - num_A; //number of '1' allele
2680 
2681  ind_A = new unsigned int [num_A];
2682  ind_a = new unsigned int [num_a];
2683 
2684  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, (int*)ind_A, num_a, (int*)ind_a); //sample individuals within deme, without replacement
2685 
2686  for (unsigned int i = 0; i < num_A ; i++) {
2687  ind = _popPtr->get(SEX, age, ind_A[i], deme);
2688  trait = ind->getTrait(_LCELinkedTraitIndex);
2689  trait->set_allele_value(l, a, 0.0);
2690  }
2691 
2692  for (unsigned int i = 0; i < num_a ; i++) {
2693  ind = _popPtr->get(SEX, age, ind_a[i], deme);
2694  trait = ind->getTrait(_LCELinkedTraitIndex);
2695  trait->set_allele_value(l, a, 1.0);
2696  }
2697 
2698  delete [] ind_A;
2699  delete [] ind_a;
2700  }
2701  }
2702 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:87
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:834
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:792
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:44
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.

597 {}

◆ loadStatServices()

virtual void LCE_NtrlInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

598 {}

◆ removeAgeClass()

virtual age_t LCE_NtrlInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

600 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_NtrlInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

602 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

599 {return false;}

◆ setParameters()

bool LCE_NtrlInit::setParameters ( )
virtual

Implements SimComponent.

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

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.2 by  doxygen 1.9.1

Catalogued on GSR