Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TTBDMI_SH Class Reference

StatHandler for the DBMI trait. More...

#include <ttbdmi.h>

+ Inheritance diagram for TTBDMI_SH:
+ Collaboration diagram for TTBDMI_SH:

Public Member Functions

 TTBDMI_SH (TProtoBDMI *TP)
 
virtual ~TTBDMI_SH ()
 
virtual bool setStatRecorders (std::string &token)
 
void addStats (age_t AGE)
 
void setAdultStats ()
 
void setOffsprgStats ()
 
void setStats (age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
 
void countAllele_haplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
 
void countAllele_diplo (Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
 
double getFreq ()
 
double getFreqIcmp ()
 
double getPatchFreq (unsigned int i)
 
double getPatchIcmp (unsigned int i)
 
- Public Member Functions inherited from TraitStatHandler< TProtoBDMI, TTBDMI_SH >
 TraitStatHandler (TProtoBDMI *trait_proto)
 
virtual ~TraitStatHandler ()
 
- Public Member Functions inherited from StatHandler< SH >
 StatHandler ()
 
virtual ~StatHandler ()
 
virtual void clear ()
 Empties the _recorders list, they are destroyed in StatHandlerBase::reset(). More...
 
virtual StatRecorder< SH > * add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
 Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list. More...
 
- Public Member Functions inherited from StatHandlerBase
 StatHandlerBase ()
 
virtual ~StatHandlerBase ()
 
virtual void reset ()
 Empties the _stats list and calls clear() (defined in the derived class). More...
 
Metapopget_pop_ptr ()
 
void set_service (StatServices *srv)
 
StatServicesget_service ()
 
unsigned int getOccurrence ()
 
unsigned int getNumOccurrences ()
 
unsigned int getCurrentOccurrence ()
 
unsigned int getNbRecorders ()
 
std::list< StatRecBase * > & getStats ()
 
virtual void add (StatRecBase *rec)
 
virtual void init ()
 
virtual void update ()
 This function is left empty as the StatServices calls StatRecorder::setVal directly. More...
 
- Public Member Functions inherited from Handler
virtual ~Handler ()
 

Private Attributes

double _freq
 
double _freqIcomp
 
double * _patchFreq
 
double * _patchIcmp
 

Additional Inherited Members

- Protected Types inherited from StatHandler< SH >
typedef std::list< StatRecorder< SH > * >::iterator REC_IT
 
- Protected Attributes inherited from TraitStatHandler< TProtoBDMI, TTBDMI_SH >
TProtoBDMI_SHLinkedTrait
 Pointer to a TraitProtoype object. More...
 
int _SHLinkedTraitIndex
 Index of the trait in the Individual::Traits table. More...
 
- Protected Attributes inherited from StatHandler< SH >
std::list< StatRecorder< SH > * > _recorders
 The list of stat recorders. More...
 
- Protected Attributes inherited from StatHandlerBase
Metapop_pop
 Link to the current population, set through the link to the StatService. More...
 

Detailed Description

StatHandler for the DBMI trait.

Records the average allele frequencies at all loci, and the frequencies of incompatibilities (i.e. double heterozygotes).

Constructor & Destructor Documentation

◆ TTBDMI_SH()

TTBDMI_SH::TTBDMI_SH ( TProtoBDMI TP)
inline
259  _freq(0), _freqIcomp(0), _patchFreq(0), _patchIcmp(0) {}
double * _patchFreq
Definition: ttbdmi.h:255
double * _patchIcmp
Definition: ttbdmi.h:255
double _freq
Definition: ttbdmi.h:254
double _freqIcomp
Definition: ttbdmi.h:254

◆ ~TTBDMI_SH()

virtual TTBDMI_SH::~TTBDMI_SH ( )
inlinevirtual
261 {if(_patchFreq)delete[]_patchFreq;if(_patchIcmp)delete[]_patchIcmp;}

References _patchFreq, and _patchIcmp.

Member Function Documentation

◆ addStats()

void TTBDMI_SH::addStats ( age_t  AGE)
839 {
840  string prefix = (AGE == ADULTS ? "adlt." : "off.");
841  ostringstream name;
842  void (TTBDMI_SH::* setter) () = (AGE == ADULTS ?
845 
846  add("", prefix + "dmi.freq", AGE, 0, 0, &TTBDMI_SH::getFreq, 0, 0, setter);
847  add("", prefix + "dmi.icmp", AGE, 0, 0, &TTBDMI_SH::getFreqIcmp, 0, 0, 0);
848  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
849  name << prefix << "dmi.p" << i+1;
850  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchFreq, 0, 0);
851  name.str(""); //reset the string
852  }
853  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
854  name << prefix << "icmp.p" << i+1;
855  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchIcmp, 0, 0);
856  name.str("");
857  }
858 
859 }
unsigned int getPatchNbr()
Definition: metapop.h:276
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
virtual StatRecorder< SH > * add(std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.
Definition: stathandler.h:144
StatHandler for the DBMI trait.
Definition: ttbdmi.h:252
double getPatchIcmp(unsigned int i)
Definition: ttbdmi.h:274
void setAdultStats()
Definition: ttbdmi.cc:863
void setOffsprgStats()
Definition: ttbdmi.cc:871
double getFreqIcmp()
Definition: ttbdmi.h:272
double getFreq()
Definition: ttbdmi.h:271
double getPatchFreq(unsigned int i)
Definition: ttbdmi.h:273
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54

References StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, getFreq(), getFreqIcmp(), getPatchFreq(), getPatchIcmp(), Metapop::getPatchNbr(), setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ countAllele_diplo()

void TTBDMI_SH::countAllele_diplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)
1002 {
1003  TT_BDMI* trait;
1004  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_num_locus()/2;
1005 
1006  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
1007 
1008  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
1009 
1010  l = 0;
1011  for(unsigned int k = 0; k < num_pair; ++k) {
1012 
1013  a1 = trait->get_num_mut_diplo(l);
1014  frqTab[patch->getID()][l++] += a1;
1015 
1016  a2 = trait->get_num_mut_diplo(l);
1017  frqTab[patch->getID()][l++] += a2;
1018 
1019  icpTab[patch->getID()][k] += ((a1 == 1) && (a2 == 1));
1020  }
1021  }
1022 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:498
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:534
unsigned int getID()
Definition: metapop.h:481
int get_num_locus()
Definition: ttbdmi.h:82
Definition: ttbdmi.h:141
unsigned int get_num_mut_diplo(unsigned int loc)
Definition: ttbdmi.h:185
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171

References TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTrait, TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTraitIndex, Patch::get(), TProtoBDMI::get_num_locus(), TT_BDMI::get_num_mut_diplo(), Patch::getID(), Individual::getTrait(), and Patch::size().

Referenced by setAdultStats(), and setOffsprgStats().

◆ countAllele_haplo()

void TTBDMI_SH::countAllele_haplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)
977 {
978  TT_BDMI* trait;
979  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_num_locus()/2;
980 
981  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
982 
983  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
984 
985  l = 0;
986  for(unsigned int k = 0; k < num_pair; ++k) {
987 
988  a1 = trait->get_num_mut_haplo(l);
989  frqTab[patch->getID()][l++] += a1;
990 
991  a2 = trait->get_num_mut_haplo(l);
992  frqTab[patch->getID()][l++] += a2;
993 
994  icpTab[patch->getID()][k] += a1 ^ a2;
995  }
996  }
997 }
unsigned int get_num_mut_haplo(unsigned int loc)
Definition: ttbdmi.h:184

References TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTrait, TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTraitIndex, Patch::get(), TProtoBDMI::get_num_locus(), TT_BDMI::get_num_mut_haplo(), Patch::getID(), Individual::getTrait(), and Patch::size().

Referenced by setAdultStats(), and setOffsprgStats().

◆ getFreq()

double TTBDMI_SH::getFreq ( )
inline
271 {return _freq;}

References _freq.

Referenced by addStats().

◆ getFreqIcmp()

double TTBDMI_SH::getFreqIcmp ( )
inline
272 {return _freqIcomp;}

References _freqIcomp.

Referenced by addStats().

◆ getPatchFreq()

double TTBDMI_SH::getPatchFreq ( unsigned int  i)
inline
273 {return _patchFreq[i];}

References _patchFreq.

Referenced by addStats().

◆ getPatchIcmp()

double TTBDMI_SH::getPatchIcmp ( unsigned int  i)
inline
274 {return _patchIcmp[i];}

References _patchIcmp.

Referenced by addStats().

◆ setAdultStats()

void TTBDMI_SH::setAdultStats ( )
864 {
867 }
bool isHaploid()
Definition: ttbdmi.h:84
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:976
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:879
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:1001
@ ADLTx
Definition: types.h:42

References TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTrait, ADLTx, countAllele_diplo(), countAllele_haplo(), TProtoBDMI::isHaploid(), and setStats().

Referenced by addStats().

◆ setOffsprgStats()

◆ setStatRecorders()

bool TTBDMI_SH::setStatRecorders ( std::string &  token)
virtual

Implements StatHandlerBase.

813 {
814 #ifdef _DEBUG_
815  message("-TTBDMI_SH::setStatRecorders ");
816 #endif
817  if(token == "dmi") {
818 
819  addStats(OFFSPRG);
820  addStats(ADULTS);
821 
822  } else if(token == "off.dmi") {
823 
824  addStats(OFFSPRG);
825 
826  } else if(token == "adlt.dmi") {
827 
828  addStats(ADULTS);
829 
830  } else
831  return false;
832 
833  return true;
834 }
void addStats(age_t AGE)
Definition: ttbdmi.cc:838
void message(const char *message,...)
Definition: output.cc:40
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References addStats(), ADULTS, message(), and OFFSPRG.

◆ setStats()

void TTBDMI_SH::setStats ( age_idx  agex,
void(TTBDMI_SH::*)(Patch *, sex_t, age_idx, double **, double **)  cntFunc 
)
880 {
881  unsigned int i, nb_ind = 0, nb_patch = 0;
882  unsigned int nb_locus = _SHLinkedTrait->get_num_locus();
883  unsigned int num_pair;
884  unsigned int psize=0;
885  unsigned int npatch=_pop->getPatchNbr();
886 
887  Patch* current_patch;
888 
889  num_pair = nb_locus/2;
890 
891  double* freqTable = new double [nb_locus];
892  double* icmpTable = new double [num_pair];
893  double** patchFreqTable = new double* [npatch];
894  double** patchIcmpTable = new double* [npatch];
895 
896  for(i = 0; i < nb_locus; ++i)
897  freqTable[i] = 0;
898 
899  for(i = 0; i < num_pair; ++i)
900  icmpTable[i] = 0;
901 
902  //init patch tables:
903  if(_patchFreq) delete [] _patchFreq;
904  _patchFreq = new double [npatch];
905 
906  if(_patchIcmp) delete [] _patchIcmp;
907  _patchIcmp = new double [npatch];
908 
909  //patch loop:
910  for(i = 0; i < npatch; ++i) {
911 
912  current_patch = _pop->getPatch(i);
913 
914  patchFreqTable[i] = new double [nb_locus];
915  for(unsigned int j = 0; j < nb_locus; ++j) patchFreqTable[i][j] = 0;
916 
917  patchIcmpTable[i] = new double [num_pair];
918  for(unsigned int j = 0; j < num_pair; ++j) patchIcmpTable[i][j] = 0;
919 
920  _patchFreq[i] = 0;
921  _patchIcmp[i] = 0;
922 
923  if( (psize = current_patch->size(agex)) == 0) continue;
924 
925  nb_patch++;
926 
927  nb_ind += psize;
928 
929  (this->* cntFunc) (current_patch, FEM, agex, patchFreqTable, patchIcmpTable);
930  (this->* cntFunc) (current_patch, MAL, agex, patchFreqTable, patchIcmpTable);
931 
932  //mut frequ.
933  for(unsigned int k = 0; k < nb_locus; ++k)
934  _patchFreq[i] += patchFreqTable[i][k]/psize;
935 
936  if(_SHLinkedTrait->isHaploid()) _patchFreq[i] /= nb_locus;
937  else _patchFreq[i] /= 2*nb_locus;
938 
939  //incompatibilities:
940  for(unsigned int k = 0; k < num_pair; ++k)
941  _patchIcmp[i] += patchIcmpTable[i][k]/psize;
942 
943  _patchIcmp[i] /= num_pair;
944 
945 
946  }//end for Patch
947 
948  //set pop means
949  //mut frequ:
950  _freq = 0;
951 
952  for(i = 0; i < npatch; ++i) _freq += _patchFreq[i];
953 
954  _freq /= npatch;
955 
956  //Incompatibilities:
957  _freqIcomp = 0;
958 
959  for(i = 0; i < npatch; ++i) _freqIcomp += _patchIcmp[i];
960 
961  _freqIcomp /= npatch;
962 
963 
964  delete [] freqTable;
965  delete [] icmpTable;
966  for(i = 0; i < npatch; ++i) {
967  delete [] patchFreqTable[i];
968  delete [] patchIcmpTable[i];
969  }
970  delete [] patchFreqTable;
971  delete [] patchIcmpTable;
972 }
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References _freq, _freqIcomp, _patchFreq, _patchIcmp, StatHandlerBase::_pop, TraitStatHandler< TProtoBDMI, TTBDMI_SH >::_SHLinkedTrait, FEM, TProtoBDMI::get_num_locus(), Metapop::getPatch(), Metapop::getPatchNbr(), TProtoBDMI::isHaploid(), MAL, and Patch::size().

Referenced by setAdultStats(), and setOffsprgStats().

Member Data Documentation

◆ _freq

double TTBDMI_SH::_freq
private

Referenced by getFreq(), and setStats().

◆ _freqIcomp

double TTBDMI_SH::_freqIcomp
private

Referenced by getFreqIcmp(), and setStats().

◆ _patchFreq

double* TTBDMI_SH::_patchFreq
private

Referenced by getPatchFreq(), setStats(), and ~TTBDMI_SH().

◆ _patchIcmp

double * TTBDMI_SH::_patchIcmp
private

Referenced by getPatchIcmp(), setStats(), and ~TTBDMI_SH().


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