Nemo  2.4.0b
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 ( )
2635  : LifeCycleEvent("ntrl_init","ntrl"), _nLoci(0)
2636 {
2637  add_parameter("ntrl_init_patch_freq",MAT,1,0,0,0);
2638 }
unsigned int _nLoci
Definition: ttneutralgenes.h:521
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
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().

◆ ~LCE_NtrlInit()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_NtrlInit::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

542 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_NtrlInit::clone ( )
inlinevirtual

Implements LifeCycleEvent.

533 {return new LCE_NtrlInit();}
LCE_NtrlInit()
Definition: ttneutralgenes.cc:2635

References LCE_NtrlInit().

◆ execute()

void LCE_NtrlInit::execute ( )
virtual

Implements LifeCycleEvent.

2667 {
2668  if(!(_popPtr->getCurrentGeneration() == 1)) return;
2669 
2670  unsigned int patchNbr = _popPtr->getPatchNbr();
2671 
2672  double *values = new double[_nLoci];
2673 
2674  for (unsigned int i = 0; i < patchNbr ; i++) {
2675 
2676  _init_freq.getRowView(i, _nLoci, values);
2677 
2678  init_allele_freq(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i, values);
2679  init_allele_freq(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i, values);
2680  init_allele_freq(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i, values);
2681  init_allele_freq(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i, values);
2682  }
2683 
2684  if(values) delete [] values;
2685 }
TMatrix _init_freq
Definition: ttneutralgenes.h:520
void init_allele_freq(sex_t SEX, age_idx AGE, unsigned int size, unsigned int deme, double *values)
Definition: ttneutralgenes.cc:2690
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:312
unsigned int getPatchNbr()
Definition: metapop.h:276
unsigned int getCurrentGeneration()
Definition: metapop.h:296
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:242
@ 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 _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 
)
2691 {
2692  if(!size) return;
2693 
2694  Individual* ind;
2695  TTNeutralGenes* trait;
2696  unsigned int num_A, num_a;
2697  unsigned int *ind_A = 0, *ind_a = 0;
2698 
2699  for(unsigned a = 0; a < 2; a++) {
2700  for(unsigned l = 0; l < _nLoci; l++) {
2701 
2702  num_A = (unsigned int)(size * values[l]); //number of '0' allele
2703  num_a = size - num_A; //number of '1' allele
2704 
2705  ind_A = new unsigned int [num_A];
2706  ind_a = new unsigned int [num_a];
2707 
2708  RAND::SampleSeqWithReciprocal(0, size, 1, num_A, (int*)ind_A, num_a, (int*)ind_a); //sample individuals within deme, without replacement
2709 
2710  for (unsigned int i = 0; i < num_A ; i++) {
2711  ind = _popPtr->get(SEX, age, ind_A[i], deme);
2712  trait = dynamic_cast<TTNeutralGenes*> ( ind->getTrait(_LCELinkedTraitIndex) );
2713  trait->set_allele(l, a, 0);
2714  }
2715 
2716  for (unsigned int i = 0; i < num_a ; i++) {
2717  ind = _popPtr->get(SEX, age, ind_a[i], deme);
2718  trait = dynamic_cast<TTNeutralGenes*> ( ind->getTrait(_LCELinkedTraitIndex) );
2719  trait->set_allele(l, a, 1);
2720  }
2721 
2722  delete [] ind_A;
2723  delete [] ind_a;
2724  }
2725  }
2726 }
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:834
static void SampleSeqWithReciprocal(int from, int to, int by, unsigned int num1, int *result1, unsigned int num2, int *result2)
Definition: Uniform.h:782
Microsatellites genome.
Definition: ttneutralgenes.h:56
void set_allele(unsigned int loc, unsigned int al, unsigned char val)
Definition: ttneutralgenes.h:87

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

Referenced by execute().

◆ loadFileServices()

virtual void LCE_NtrlInit::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

538 {}

◆ loadStatServices()

virtual void LCE_NtrlInit::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

539 {}

◆ removeAgeClass()

virtual age_t LCE_NtrlInit::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

541 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_NtrlInit::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

543 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

540 {return false;}

◆ setParameters()

bool LCE_NtrlInit::setParameters ( )
virtual

Implements SimComponent.

2643 {
2644  TMatrix pat_mat;
2645  unsigned int patchNbr = _popPtr->getPatchNbr();
2646  TProtoNeutralGenes* proto = dynamic_cast<TProtoNeutralGenes*> ( _popPtr->getTraitPrototype("ntrl") );
2647 
2648  if(proto->get_allele_num() > 2) {
2649  error("LCE ntrl_init only works for di-allelic neutral loci, sorry.\n\
2650  Please consider using an FSTAT input file for more complex cases.\n");
2651  return false;
2652  }
2653 
2654  _nLoci = proto->get_locus_num();
2655 
2656  _paramSet->getMatrix("ntrl_init_patch_freq", &pat_mat);
2657 
2658  if( !setSpatialMatrix("ntrl_init_patch_freq", "num of neutral loci", &pat_mat, &_init_freq, _nLoci, patchNbr) )
2659  return false;
2660 
2661  return true;
2662 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:304
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:50
Prototype class for the TTNeutralGenes trait class.
Definition: ttneutralgenes.h:131
unsigned int get_locus_num()
Definition: ttneutralgenes.h:159
unsigned int get_allele_num()
Definition: ttneutralgenes.h:160
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:115

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.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR