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

Allelic frequency initialiser for the DBMI trait. More...

#include <ttbdmi.h>

+ Inheritance diagram for LCE_Init_BDMI:
+ Collaboration diagram for LCE_Init_BDMI:

Public Member Functions

 LCE_Init_BDMI ()
 
virtual ~LCE_Init_BDMI ()
 
bool setSpatialPattern (TMatrix &freq_mat, unsigned int patchNbr)
 
bool setPatchFreq (TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
 
void init_value (sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
 
virtual void execute ()
 
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 _nLocus
 

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

Allelic frequency initialiser for the DBMI trait.

It executes at the first generation of each replicate only.

Constructor & Destructor Documentation

◆ LCE_Init_BDMI()

LCE_Init_BDMI::LCE_Init_BDMI ( )
900 : LifeCycleEvent("dmi_init","dmi")
901{
902 add_parameter("dmi_init_freq", MAT, true, false, 0, 0, 0);
903 add_parameter("dmi_init_patch", MAT, false, false, 0, 0, 0);
904// add_parameter("dmi_inoculum_alleles", MAT, false, false, 0, 0, 0);
905// add_parameter("dmi_inoculum_size", INT, false, false, 0, 0, 0);
906}
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_Init_BDMI()

virtual LCE_Init_BDMI::~LCE_Init_BDMI ( )
inlinevirtual
308{ }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Init_BDMI::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

326{return 0;}

◆ clone()

virtual LifeCycleEvent * LCE_Init_BDMI::clone ( )
inlinevirtual

Implements LifeCycleEvent.

317{return new LCE_Init_BDMI();}
LCE_Init_BDMI()
Definition: ttbdmi.cc:900

References LCE_Init_BDMI().

◆ execute()

void LCE_Init_BDMI::execute ( )
virtual

Implements LifeCycleEvent.

1028{
1029
1030 if(!(_popPtr->getCurrentGeneration() == 1)) return;
1031
1032 unsigned int patchNbr = _popPtr->getPatchNbr();
1033 double *values = new double[_nLocus];
1034 TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
1035
1036 for (unsigned int i = 0; i < patchNbr ; i++) {
1037
1038 _init_freq.getRowView(i, _nLocus, values);
1039
1040 proto->set_init_freq(values, _nLocus);
1041
1046
1047 }
1048
1049 delete [] values;
1050}
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
TMatrix _init_freq
Definition: ttbdmi.h:301
unsigned int _nLocus
Definition: ttbdmi.h:302
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:1054
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
Definition: ttbdmi.h:50
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:197
@ 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, _nLocus, LifeCycleEvent::_popPtr, ADLTx, ADULTS, FEM, Metapop::getCurrentGeneration(), Metapop::getPatchNbr(), TMatrix::getRowView(), IndFactory::getTraitPrototype(), init_value(), MAL, OFFSPRG, OFFSx, TProtoBDMI::set_init_freq(), and Metapop::size().

◆ init_value()

void LCE_Init_BDMI::init_value ( sex_t  SEX,
age_idx  age,
unsigned int  size,
unsigned int  deme 
)
1055{
1056 Individual* ind;
1057 TT_BDMI* trait;
1058
1059 for (unsigned int i = 0; i < size ; i++) {
1060 ind = _popPtr->get(SEX, age, i, deme);
1061 trait = dynamic_cast<TT_BDMI*> ( ind->getTrait(_LCELinkedTraitIndex) );
1062 trait->init_sequence();
1063 trait->set_value();
1064 }
1065}
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
Definition: ttbdmi.h:134
virtual void set_value()
Definition: ttbdmi.h:217
virtual void init_sequence()
Definition: ttbdmi.cc:403

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_Init_BDMI::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

322{}

◆ loadStatServices()

virtual void LCE_Init_BDMI::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

323{}

◆ removeAgeClass()

virtual age_t LCE_Init_BDMI::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

325{return 0;}

◆ requiredAgeClass()

virtual age_t LCE_Init_BDMI::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

327{return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

324{return false;}

◆ setParameters()

bool LCE_Init_BDMI::setParameters ( )
virtual

Implements SimComponent.

911{
912 TMatrix freq_mat, pat_mat;
913 unsigned int patchNbr = _popPtr->getPatchNbr();
914 TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
915 bool isPatchSpecific = false;
916
917 _nLocus = proto->get_nb_locus();
918
919 _paramSet->getMatrix("dmi_init_freq", &freq_mat);
920
921 if(get_parameter("dmi_init_patch")->isSet()) {
922 _paramSet->getMatrix("dmi_init_patch", &pat_mat);
923 isPatchSpecific = true;
924 }
925
926 unsigned int ncol = freq_mat.getNbCols(); //nbr of loci = nbr of col
927 unsigned int npat = freq_mat.getNbRows(); //nbr of diff. value / locus, may be <= patchNbr
928
929 //we have two possible configurations:
930 // 1. ncol == 1; same value for all loci in a patch but varies among patches, with possible repetition of a pattern
931 // 2. ncol == no loci && npat <= no patches; locus freq change in each patch following a pattern (same if npat == 1)
932 if(npat > patchNbr) {
933 error("The number of rows in \"dmi_init_freq\" is greater than the number of patches, must be at least equal to it.");
934 return false;
935 }
936 if(ncol > _nLocus) {
937 error("The number of columns in \"dmi_init_freq\" is greater than number of loci, must be at least equal to it.\n");
938 return false;
939 }
940
941 _init_freq.reset(patchNbr, _nLocus);
942
943 bool status;
944 if ( isPatchSpecific )
945 status = setPatchFreq(freq_mat, pat_mat, patchNbr);
946 else
947 status = setSpatialPattern(freq_mat, patchNbr);
948
949 return status;
950}
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:955
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:993
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:304
bool isSet()
Definition: param.h:140
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
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:116
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:166
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:169
int get_nb_locus()
Definition: ttbdmi.h:77
int error(const char *str,...)
Definition: output.cc:77

References _init_freq, _nLocus, SimComponent::_paramSet, LifeCycleEvent::_popPtr, error(), TProtoBDMI::get_nb_locus(), SimComponent::get_parameter(), ParamSet::getMatrix(), TMatrix::getNbCols(), TMatrix::getNbRows(), Metapop::getPatchNbr(), IndFactory::getTraitPrototype(), Param::isSet(), TMatrix::reset(), setPatchFreq(), and setSpatialPattern().

◆ setPatchFreq()

bool LCE_Init_BDMI::setPatchFreq ( TMatrix freq_mat,
TMatrix pat_mat,
unsigned int  patchNbr 
)
994{
995 unsigned int ncol = freq_mat.getNbCols();
996 unsigned int nrow = freq_mat.getNbRows();
997 unsigned int npatch = pat_mat.getNbCols();
998
999 if(nrow != npatch && nrow != 1) {
1000 error("Row num. of \"dmi_init_freq\" is greater than column num. of \"dmi_init_patch\"\n\
1001 must match it or be 1.\n");
1002 return false;
1003 }
1004
1005 for(unsigned int i = 0, pat, row; i < npatch; ++i) {
1006
1007 pat = pat_mat.get(0, i) - 1; //patch index starts at 0!
1008
1009 row = (nrow == 1 ? 0 : i);
1010
1011 if(ncol == 1)
1012 for(unsigned int j = 0; j < _nLocus; j++)
1013 _init_freq.set(pat, j, freq_mat.get(row, 0));
1014 else if (ncol < _nLocus)
1015 for(unsigned int j = 0; j < _nLocus; j++)
1016 _init_freq.set(pat, j, freq_mat.get(row, j % ncol));
1017 else
1018 for(unsigned int j = 0; j < _nLocus; j++)
1019 _init_freq.set(pat, j, freq_mat.get(row, j));
1020 }
1021
1022 return true;
1023}
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147

References _init_freq, _nLocus, error(), TMatrix::get(), TMatrix::getNbCols(), TMatrix::getNbRows(), and TMatrix::set().

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ setSpatialPattern()

bool LCE_Init_BDMI::setSpatialPattern ( TMatrix freq_mat,
unsigned int  patchNbr 
)
956{
957 unsigned int ncol = freq_mat.getNbCols();
958 unsigned int npat = freq_mat.getNbRows();
959
960 for(unsigned int i = 0; i < patchNbr; ++i) {
961
962 if(npat < patchNbr) {//repetition of a pattern
963
964 if(ncol == 1)
965 for(unsigned int j = 0; j < _nLocus; j++)
966 _init_freq.set(i, j, freq_mat.get(i % npat, 0));
967 else if (ncol < _nLocus)
968 for(unsigned int j = 0; j < _nLocus; j++)
969 _init_freq.set(i, j, freq_mat.get(i % npat, j % ncol));
970 else
971 for(unsigned int j = 0; j < _nLocus; j++)
972 _init_freq.set(i, j, freq_mat.get(i % npat, j));
973
974 } else {//different values for each Patch
975
976 if(ncol == 1)
977 for(unsigned int j = 0; j < _nLocus; j++)
978 _init_freq.set(i, j, freq_mat.get(i, 0));
979 else if (ncol < _nLocus)
980 for(unsigned int j = 0; j < _nLocus; j++)
981 _init_freq.set(i, j, freq_mat.get(i, j % ncol));
982 else
983 for(unsigned int j = 0; j < _nLocus; j++)
984 _init_freq.set(i, j, freq_mat.get(i, j));
985 }
986 }
987
988 return true;
989}

References _init_freq, _nLocus, TMatrix::get(), TMatrix::getNbCols(), TMatrix::getNbRows(), and TMatrix::set().

Referenced by setParameters().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _init_freq

TMatrix LCE_Init_BDMI::_init_freq
private

◆ _nLocus

unsigned int LCE_Init_BDMI::_nLocus
private

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