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

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Init_BDMI::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

321 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_Init_BDMI::clone ( )
inlinevirtual

Implements LifeCycleEvent.

312 {return new LCE_Init_BDMI();}
LCE_Init_BDMI()
Definition: ttbdmi.cc:1044

References LCE_Init_BDMI().

◆ execute()

void LCE_Init_BDMI::execute ( )
virtual

Implements LifeCycleEvent.

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

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.

317 {}

◆ loadStatServices()

virtual void LCE_Init_BDMI::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

318 {}

◆ removeAgeClass()

virtual age_t LCE_Init_BDMI::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

320 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_Init_BDMI::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

322 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

319 {return false;}

◆ setParameters()

bool LCE_Init_BDMI::setParameters ( )
virtual

Implements SimComponent.

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

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

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

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

Locations of visitors to this page
Catalogued on GSR