Nemo  2.3.46
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 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...
 

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 ( )

References SimComponent::add_parameter(), and MAT.

Referenced by clone().

832  : LifeCycleEvent("dmi_init","dmi")
833 {
834  add_parameter("dmi_init_freq", MAT, true, false, 0, 0, 0);
835  add_parameter("dmi_init_patch", MAT, false, false, 0, 0, 0);
836 // add_parameter("dmi_inoculum_alleles", MAT, false, false, 0, 0, 0);
837 // add_parameter("dmi_inoculum_size", INT, false, false, 0, 0, 0);
838 }
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Definition: types.h:78
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
virtual LCE_Init_BDMI::~LCE_Init_BDMI ( )
inlinevirtual
301 { }

Member Function Documentation

virtual age_t LCE_Init_BDMI::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

318 {return 0;}
virtual LifeCycleEvent* LCE_Init_BDMI::clone ( )
inlinevirtual

Implements LifeCycleEvent.

References LCE_Init_BDMI().

310 {return new LCE_Init_BDMI();}
LCE_Init_BDMI()
Definition: ttbdmi.cc:832
void LCE_Init_BDMI::execute ( )
virtual

Implements LifeCycleEvent.

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().

960 {
961 
962  if(!(_popPtr->getCurrentGeneration() == 1)) return;
963 
964  unsigned int patchNbr = _popPtr->getPatchNbr();
965  double *values = new double[_nLocus];
966  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
967 
968  for (unsigned int i = 0; i < patchNbr ; i++) {
969 
970  _init_freq.getRowView(i, _nLocus, values);
971 
972  proto->set_init_freq(values, _nLocus);
973 
974  init_value(FEM, OFFSx, _popPtr->size(FEM, OFFSPRG, i), i);
975  init_value(MAL, OFFSx, _popPtr->size(MAL, OFFSPRG, i), i);
976  init_value(FEM, ADLTx, _popPtr->size(FEM, ADULTS, i), i);
977  init_value(MAL, ADLTx, _popPtr->size(MAL, ADULTS, i), i);
978 
979  }
980 
981  delete [] values;
982 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
TMatrix _init_freq
Definition: ttbdmi.h:294
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
Definition: ttbdmi.h:50
unsigned int getCurrentGeneration()
Definition: metapop.h:286
unsigned int getPatchNbr()
Definition: metapop.h:270
void init_value(sex_t SEX, age_idx age, unsigned int size, unsigned int deme)
Definition: ttbdmi.cc:986
void set_init_freq(double *val, unsigned int size)
Definition: ttbdmi.cc:197
Definition: types.h:42
void getRowView(unsigned int row, unsigned int n, double *array)
Gives access to a row of the matrix.
Definition: tmatrix.h:169
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int _nLocus
Definition: ttbdmi.h:295
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
void LCE_Init_BDMI::init_value ( sex_t  SEX,
age_idx  age,
unsigned int  size,
unsigned int  deme 
)

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

Referenced by execute().

987 {
988  Individual* ind;
989  TT_BDMI* trait;
990 
991  for (unsigned int i = 0; i < size ; i++) {
992  ind = _popPtr->get(SEX, age, i, deme);
993  trait = dynamic_cast<TT_BDMI*> ( ind->getTrait(_LCELinkedTraitIndex) );
994  trait->init_sequence();
995  trait->set_value();
996  }
997 }
Definition: ttbdmi.h:127
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
virtual void init_sequence()
Definition: ttbdmi.cc:379
virtual void set_value()
Definition: ttbdmi.h:210
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:783
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
virtual void LCE_Init_BDMI::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

315 {}
virtual void LCE_Init_BDMI::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

316 {}
virtual age_t LCE_Init_BDMI::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

317 {return 0;}
virtual age_t LCE_Init_BDMI::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

319 {return 0;}
bool LCE_Init_BDMI::setParameters ( )
virtual

Implements SimComponent.

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(), TMatrix::reset(), setPatchFreq(), and setSpatialPattern().

843 {
844  TMatrix freq_mat, pat_mat;
845  unsigned int patchNbr = _popPtr->getPatchNbr();
846  TProtoBDMI* proto = dynamic_cast<TProtoBDMI*> ( _popPtr->getTraitPrototype("dmi") );
847  bool isPatchSpecific = false;
848 
849  _nLocus = proto->get_nb_locus();
850 
851  _paramSet->getMatrix("dmi_init_freq", &freq_mat);
852 
853  if(get_parameter("dmi_init_patch")->isSet()) {
854  _paramSet->getMatrix("dmi_init_patch", &pat_mat);
855  isPatchSpecific = true;
856  }
857 
858  unsigned int ncol = freq_mat.getNbCols(); //nbr of loci = nbr of col
859  unsigned int npat = freq_mat.getNbRows(); //nbr of diff. value / locus, may be <= patchNbr
860 
861  //we have two possible configurations:
862  // 1. ncol == 1; same value for all loci in a patch but varies among patches, with possible repetition of a pattern
863  // 2. ncol == no loci && npat <= no patches; locus freq change in each patch following a pattern (same if npat == 1)
864  if(npat > patchNbr) {
865  error("The number of rows in \"dmi_init_freq\" is greater than the number of patches, must be at least equal to it.");
866  return false;
867  }
868  if(ncol > _nLocus) {
869  error("The number of columns in \"dmi_init_freq\" is greater than number of loci, must be at least equal to it.\n");
870  return false;
871  }
872 
873  _init_freq.reset(patchNbr, _nLocus);
874 
875  bool status;
876  if ( isPatchSpecific )
877  status = setPatchFreq(freq_mat, pat_mat, patchNbr);
878  else
879  status = setSpatialPattern(freq_mat, patchNbr);
880 
881  return status;
882 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
TMatrix _init_freq
Definition: ttbdmi.h:294
bool setPatchFreq(TMatrix &freq_mat, TMatrix &pat_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:925
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
Definition: ttbdmi.h:50
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
int get_nb_locus()
Definition: ttbdmi.h:77
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
unsigned int _nLocus
Definition: ttbdmi.h:295
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
bool setSpatialPattern(TMatrix &freq_mat, unsigned int patchNbr)
Definition: ttbdmi.cc:887
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
bool LCE_Init_BDMI::setPatchFreq ( TMatrix freq_mat,
TMatrix pat_mat,
unsigned int  patchNbr 
)

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

Referenced by setParameters().

926 {
927  unsigned int ncol = freq_mat.getNbCols();
928  unsigned int nrow = freq_mat.getNbRows();
929  unsigned int npatch = pat_mat.getNbCols();
930 
931  if(nrow != npatch && nrow != 1) {
932  error("Row num. of \"dmi_init_freq\" is greater than column num. of \"dmi_init_patch\"\n\
933  must match it or be 1.\n");
934  return false;
935  }
936 
937  for(unsigned int i = 0, pat, row; i < npatch; ++i) {
938 
939  pat = pat_mat.get(0, i) - 1; //patch index starts at 0!
940 
941  row = (nrow == 1 ? 0 : i);
942 
943  if(ncol == 1)
944  for(unsigned int j = 0; j < _nLocus; j++)
945  _init_freq.set(pat, j, freq_mat.get(row, 0));
946  else if (ncol < _nLocus)
947  for(unsigned int j = 0; j < _nLocus; j++)
948  _init_freq.set(pat, j, freq_mat.get(row, j % ncol));
949  else
950  for(unsigned int j = 0; j < _nLocus; j++)
951  _init_freq.set(pat, j, freq_mat.get(row, j));
952  }
953 
954  return true;
955 }
TMatrix _init_freq
Definition: ttbdmi.h:294
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
int error(const char *str,...)
Definition: output.cc:73
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
unsigned int _nLocus
Definition: ttbdmi.h:295
bool LCE_Init_BDMI::setSpatialPattern ( TMatrix freq_mat,
unsigned int  patchNbr 
)

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

Referenced by setParameters().

888 {
889  unsigned int ncol = freq_mat.getNbCols();
890  unsigned int npat = freq_mat.getNbRows();
891 
892  for(unsigned int i = 0; i < patchNbr; ++i) {
893 
894  if(npat < patchNbr) {//repetition of a pattern
895 
896  if(ncol == 1)
897  for(unsigned int j = 0; j < _nLocus; j++)
898  _init_freq.set(i, j, freq_mat.get(i % npat, 0));
899  else if (ncol < _nLocus)
900  for(unsigned int j = 0; j < _nLocus; j++)
901  _init_freq.set(i, j, freq_mat.get(i % npat, j % ncol));
902  else
903  for(unsigned int j = 0; j < _nLocus; j++)
904  _init_freq.set(i, j, freq_mat.get(i % npat, j));
905 
906  } else {//different values for each Patch
907 
908  if(ncol == 1)
909  for(unsigned int j = 0; j < _nLocus; j++)
910  _init_freq.set(i, j, freq_mat.get(i, 0));
911  else if (ncol < _nLocus)
912  for(unsigned int j = 0; j < _nLocus; j++)
913  _init_freq.set(i, j, freq_mat.get(i, j % ncol));
914  else
915  for(unsigned int j = 0; j < _nLocus; j++)
916  _init_freq.set(i, j, freq_mat.get(i, j));
917  }
918  }
919 
920  return true;
921 }
TMatrix _init_freq
Definition: ttbdmi.h:294
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
unsigned int _nLocus
Definition: ttbdmi.h:295

Member Data Documentation

TMatrix LCE_Init_BDMI::_init_freq
private
unsigned int LCE_Init_BDMI::_nLocus
private

The documentation for this class was generated from the following files:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR