Nemo  2.4.0b
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 ( )
1031  : LifeCycleEvent("dmi_init","dmi"), _nLocus(0)
1032 {
1033  add_parameter("dmi_init_freq", MAT, true, false, 0, 0, 0);
1034  add_parameter("dmi_init_patch", MAT, false, false, 0, 0, 0);
1035 // add_parameter("dmi_inoculum_alleles", MAT, false, false, 0, 0, 0);
1036 // add_parameter("dmi_inoculum_size", INT, false, false, 0, 0, 0);
1037 }
unsigned int _nLocus
Definition: ttbdmi.h:288
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_Init_BDMI()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Init_BDMI::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

312 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_Init_BDMI::clone ( )
inlinevirtual

Implements LifeCycleEvent.

303 {return new LCE_Init_BDMI();}
LCE_Init_BDMI()
Definition: ttbdmi.cc:1031

References LCE_Init_BDMI().

◆ execute()

void LCE_Init_BDMI::execute ( )
virtual

Implements LifeCycleEvent.

1157 {
1158 
1159  if(!(_popPtr->getCurrentGeneration() == 1)) return;
1160 
1161  unsigned int patchNbr = _popPtr->getPatchNbr();
1162  double *values = new double[_nLocus];
1163  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
1164 
1165  for (unsigned int i = 0; i < patchNbr ; i++) {
1166 
1167  _init_freq.getRowView(i, _nLocus, values);
1168 
1169  proto->set_init_freq(values, _nLocus);
1170 
1171  init_value(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i);
1172  init_value(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i);
1173  init_value(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i);
1174  init_value(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i);
1175 
1176  }
1177 
1178  delete [] values;
1179 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
TMatrix _init_freq
Definition: ttbdmi.h:287
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:1183
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
Definition: ttbdmi.h:50
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:246
@ 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 
)
1184 {
1185  Individual* ind;
1186  TT_BDMI* trait;
1187 
1188  for (unsigned int i = 0; i < size ; i++) {
1189  ind = _popPtr->get(SEX, age, i, deme);
1190  trait = dynamic_cast<TT_BDMI*> ( ind->getTrait(_LCELinkedTraitIndex) );
1191  trait->init_sequence();
1192  trait->set_value();
1193  }
1194 }
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
Definition: ttbdmi.h:141
virtual void set_value()
Definition: ttbdmi.cc:596
virtual void init_sequence()
Definition: ttbdmi.cc:502

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

Referenced by execute().

◆ loadFileServices()

virtual void LCE_Init_BDMI::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

308 {}

◆ loadStatServices()

virtual void LCE_Init_BDMI::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

309 {}

◆ removeAgeClass()

virtual age_t LCE_Init_BDMI::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

311 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_Init_BDMI::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

313 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

310 {return false;}

◆ setParameters()

bool LCE_Init_BDMI::setParameters ( )
virtual

Implements SimComponent.

1042 {
1043  TMatrix freq_mat, pat_mat;
1044  unsigned int patchNbr = _popPtr->getPatchNbr();
1045  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
1046  bool isPatchSpecific = false;
1047 
1048  _nLocus = proto->get_num_locus();
1049 
1050  _paramSet->getMatrix("dmi_init_freq", &freq_mat);
1051 
1052  if(get_parameter("dmi_init_patch")->isSet()) {
1053  _paramSet->getMatrix("dmi_init_patch", &pat_mat);
1054  isPatchSpecific = true;
1055  }
1056 
1057  unsigned int ncol = freq_mat.ncols(); //nbr of loci = nbr of col
1058  unsigned int npat = freq_mat.nrows(); //nbr of diff. value / locus, may be <= patchNbr
1059 
1060  //we have two possible configurations:
1061  // 1. ncol == 1; same value for all loci in a patch but varies among patches, with possible repetition of a pattern
1062  // 2. ncol == no loci && npat <= no patches; locus freq change in each patch following a pattern (same if npat == 1)
1063  if(npat > patchNbr) {
1064  return error("The number of rows in \"dmi_init_freq\" is greater than the number of patches, must be at least equal to it.");
1065  }
1066  if(ncol > _nLocus) {
1067  return error("The number of columns in \"dmi_init_freq\" is greater than number of loci, must be at least equal to it.\n");
1068  }
1069 
1070  _init_freq.reset(patchNbr, _nLocus);
1071 
1072  bool status;
1073  if ( isPatchSpecific )
1074  status = setPatchFreq(freq_mat, pat_mat, patchNbr);
1075  else
1076  status = setSpatialPattern(freq_mat, patchNbr);
1077 
1078  return status;
1079 }
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:1084
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:1122
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:50
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:161
unsigned int ncols() const
Definition: tmatrix.h:216
unsigned int nrows() const
Definition: tmatrix.h:213
int get_num_locus()
Definition: ttbdmi.h:82
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 
)
1123 {
1124  unsigned int ncol = freq_mat.getNbCols();
1125  unsigned int nrow = freq_mat.getNbRows();
1126  unsigned int npatch = pat_mat.getNbCols();
1127 
1128  if(nrow != npatch && nrow != 1) {
1129  error("Row num. of \"dmi_init_freq\" is greater than column num. of \"dmi_init_patch\"\n\
1130  must match it or be 1.\n");
1131  return false;
1132  }
1133 
1134  for(unsigned int i = 0, pat, row; i < npatch; ++i) {
1135 
1136  pat = pat_mat.get(0, i) - 1; //patch index starts at 0!
1137 
1138  row = (nrow == 1 ? 0 : i);
1139 
1140  if(ncol == 1)
1141  for(unsigned int j = 0; j < _nLocus; j++)
1142  _init_freq.set(pat, j, freq_mat.get(row, 0));
1143  else if (ncol < _nLocus)
1144  for(unsigned int j = 0; j < _nLocus; j++)
1145  _init_freq.set(pat, j, freq_mat.get(row, j % ncol));
1146  else
1147  for(unsigned int j = 0; j < _nLocus; j++)
1148  _init_freq.set(pat, j, freq_mat.get(row, j));
1149  }
1150 
1151  return true;
1152 }
unsigned int getNbRows() const
Gives the number of rows.
Definition: tmatrix.h:212
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:215
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:103
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193

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

Referenced by setParameters().

◆ setSpatialPattern()

bool LCE_Init_BDMI::setSpatialPattern ( TMatrix freq_mat,
unsigned int  patchNbr 
)
1085 {
1086  unsigned int ncol = freq_mat.getNbCols();
1087  unsigned int npat = freq_mat.getNbRows();
1088 
1089  for(unsigned int i = 0; i < patchNbr; ++i) {
1090 
1091  if(npat < patchNbr) {//repetition of a pattern
1092 
1093  if(ncol == 1)
1094  for(unsigned int j = 0; j < _nLocus; j++)
1095  _init_freq.set(i, j, freq_mat.get(i % npat, 0));
1096  else if (ncol < _nLocus)
1097  for(unsigned int j = 0; j < _nLocus; j++)
1098  _init_freq.set(i, j, freq_mat.get(i % npat, j % ncol));
1099  else
1100  for(unsigned int j = 0; j < _nLocus; j++)
1101  _init_freq.set(i, j, freq_mat.get(i % npat, j));
1102 
1103  } else {//different values for each Patch
1104 
1105  if(ncol == 1)
1106  for(unsigned int j = 0; j < _nLocus; j++)
1107  _init_freq.set(i, j, freq_mat.get(i, 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, j % ncol));
1111  else
1112  for(unsigned int j = 0; j < _nLocus; j++)
1113  _init_freq.set(i, j, freq_mat.get(i, j));
1114  }
1115  }
1116 
1117  return true;
1118 }

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

Referenced by setParameters().

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

Locations of visitors to this page
Catalogued on GSR