Nemo  2.4.2
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 ( )
1043  : LifeCycleEvent("dmi_init","dmi"), _nLocus(0)
1044 {
1045  add_parameter("dmi_init_freq", MAT, true, false, 0, 0, 0);
1046  add_parameter("dmi_init_patch", MAT, false, false, 0, 0, 0);
1047 // add_parameter("dmi_inoculum_alleles", MAT, false, false, 0, 0, 0);
1048 // add_parameter("dmi_inoculum_size", INT, false, false, 0, 0, 0);
1049 }
unsigned int _nLocus
Definition: ttbdmi.h:296
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_Init_BDMI()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Init_BDMI::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

320 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_Init_BDMI::clone ( )
inlinevirtual

Implements LifeCycleEvent.

311 {return new LCE_Init_BDMI();}
LCE_Init_BDMI()
Definition: ttbdmi.cc:1043

References LCE_Init_BDMI().

◆ execute()

void LCE_Init_BDMI::execute ( )
virtual

Implements LifeCycleEvent.

1169 {
1170 
1171  if(!(_popPtr->getCurrentGeneration() == 1)) return;
1172 
1173  unsigned int patchNbr = _popPtr->getPatchNbr();
1174  double *values = new double[_nLocus];
1175  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
1176 
1177  for (unsigned int i = 0; i < patchNbr ; i++) {
1178 
1179  _init_freq.getRowView(i, _nLocus, values);
1180 
1181  proto->set_init_freq(values, _nLocus);
1182 
1183  init_value(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i);
1184  init_value(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i);
1185  init_value(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i);
1186  init_value(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i);
1187 
1188  }
1189 
1190  delete [] values;
1191 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:138
TMatrix _init_freq
Definition: ttbdmi.h:295
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:1195
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
Definition: ttbdmi.h:48
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:249
@ 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, _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 
)
1196 {
1197  Individual* ind;
1198  TT_BDMI* trait;
1199 
1200  for (unsigned int i = 0; i < size ; i++) {
1201  ind = _popPtr->get(SEX, age, i, deme);
1202  trait = dynamic_cast<TT_BDMI*> ( ind->getTrait(_LCELinkedTraitIndex) );
1203  trait->init_sequence();
1204  trait->set_value();
1205  }
1206 }
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
Definition: ttbdmi.h:148
virtual void set_value()
Definition: ttbdmi.cc:607
virtual void init_sequence()
Definition: ttbdmi.cc:513

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.

316 {}

◆ loadStatServices()

virtual void LCE_Init_BDMI::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

317 {}

◆ removeAgeClass()

virtual age_t LCE_Init_BDMI::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

319 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_Init_BDMI::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

321 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

318 {return false;}

◆ setParameters()

bool LCE_Init_BDMI::setParameters ( )
virtual

Implements SimComponent.

1054 {
1055  TMatrix freq_mat, pat_mat;
1056  unsigned int patchNbr = _popPtr->getPatchNbr();
1057  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
1058  bool isPatchSpecific = false;
1059 
1060  _nLocus = proto->get_num_locus();
1061 
1062  _paramSet->getMatrix("dmi_init_freq", &freq_mat);
1063 
1064  if(get_parameter("dmi_init_patch")->isSet()) {
1065  _paramSet->getMatrix("dmi_init_patch", &pat_mat);
1066  isPatchSpecific = true;
1067  }
1068 
1069  unsigned int ncol = freq_mat.ncols(); //nbr of loci = nbr of col
1070  unsigned int npat = freq_mat.nrows(); //nbr of diff. value / locus, may be <= patchNbr
1071 
1072  //we have two possible configurations:
1073  // 1. ncol == 1; same value for all loci in a patch but varies among patches, with possible repetition of a pattern
1074  // 2. ncol == no loci && npat <= no patches; locus freq change in each patch following a pattern (same if npat == 1)
1075  if(npat > patchNbr) {
1076  return error("The number of rows in \"dmi_init_freq\" is greater than the number of patches, must be at least equal to it.");
1077  }
1078  if(ncol > _nLocus) {
1079  return error("The number of columns in \"dmi_init_freq\" is greater than number of loci, must be at least equal to it.\n");
1080  }
1081 
1082  _init_freq.reset(patchNbr, _nLocus);
1083 
1084  bool status;
1085  if ( isPatchSpecific )
1086  status = setPatchFreq(freq_mat, pat_mat, patchNbr);
1087  else
1088  status = setSpatialPattern(freq_mat, patchNbr);
1089 
1090  return status;
1091 }
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:1096
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:1134
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:312
bool isSet()
Definition: param.h:146
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:137
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
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:159
unsigned int ncols() const
Definition: tmatrix.h:214
unsigned int nrows() const
Definition: tmatrix.h:211
int get_num_locus()
Definition: ttbdmi.h:80
int error(const char *str,...)
Definition: output.cc:77

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

◆ setPatchFreq()

bool LCE_Init_BDMI::setPatchFreq ( TMatrix freq_mat,
TMatrix pat_mat,
unsigned int  patchNbr 
)
1135 {
1136  unsigned int ncol = freq_mat.getNbCols();
1137  unsigned int nrow = freq_mat.getNbRows();
1138  unsigned int npatch = pat_mat.getNbCols();
1139 
1140  if(nrow != npatch && nrow != 1) {
1141  error("Row num. of \"dmi_init_freq\" is greater than column num. of \"dmi_init_patch\"\n\
1142  must match it or be 1.\n");
1143  return false;
1144  }
1145 
1146  for(unsigned int i = 0, pat, row; i < npatch; ++i) {
1147 
1148  pat = pat_mat.get(0, i) - 1; //patch index starts at 0!
1149 
1150  row = (nrow == 1 ? 0 : i);
1151 
1152  if(ncol == 1)
1153  for(unsigned int j = 0; j < _nLocus; j++)
1154  _init_freq.set(pat, j, freq_mat.get(row, 0));
1155  else if (ncol < _nLocus)
1156  for(unsigned int j = 0; j < _nLocus; j++)
1157  _init_freq.set(pat, j, freq_mat.get(row, j % ncol));
1158  else
1159  for(unsigned int j = 0; j < _nLocus; j++)
1160  _init_freq.set(pat, j, freq_mat.get(row, j));
1161  }
1162 
1163  return true;
1164 }
unsigned int getNbRows() const
Gives the number of rows.
Definition: tmatrix.h:210
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:213
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:101
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191

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 
)
1097 {
1098  unsigned int ncol = freq_mat.getNbCols();
1099  unsigned int npat = freq_mat.getNbRows();
1100 
1101  for(unsigned int i = 0; i < patchNbr; ++i) {
1102 
1103  if(npat < patchNbr) {//repetition of a pattern
1104 
1105  if(ncol == 1)
1106  for(unsigned int j = 0; j < _nLocus; j++)
1107  _init_freq.set(i, j, freq_mat.get(i % npat, 0));
1108  else if (ncol < _nLocus)
1109  for(unsigned int j = 0; j < _nLocus; j++)
1110  _init_freq.set(i, j, freq_mat.get(i % npat, j % ncol));
1111  else
1112  for(unsigned int j = 0; j < _nLocus; j++)
1113  _init_freq.set(i, j, freq_mat.get(i % npat, j));
1114 
1115  } else {//different values for each Patch
1116 
1117  if(ncol == 1)
1118  for(unsigned int j = 0; j < _nLocus; j++)
1119  _init_freq.set(i, j, freq_mat.get(i, 0));
1120  else if (ncol < _nLocus)
1121  for(unsigned int j = 0; j < _nLocus; j++)
1122  _init_freq.set(i, j, freq_mat.get(i, j % ncol));
1123  else
1124  for(unsigned int j = 0; j < _nLocus; j++)
1125  _init_freq.set(i, j, freq_mat.get(i, j));
1126  }
1127  }
1128 
1129  return true;
1130 }

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

Catalogued on GSR