Nemo  2.4.0
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
268  _freq(0), _freqIcomp(0), _patchFreq(0), _patchIcmp(0) {}
double * _patchFreq
Definition: ttbdmi.h:264
double * _patchIcmp
Definition: ttbdmi.h:264
double _freq
Definition: ttbdmi.h:263
double _freqIcomp
Definition: ttbdmi.h:263

◆ ~TTBDMI_SH()

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

References _patchFreq, and _patchIcmp.

Member Function Documentation

◆ addStats()

void TTBDMI_SH::addStats ( age_t  AGE)
852 {
853  string prefix = (AGE == ADULTS ? "adlt." : "off.");
854  ostringstream name;
855  void (TTBDMI_SH::* setter) () = (AGE == ADULTS ?
858 
859  add("", prefix + "dmi.freq", AGE, 0, 0, &TTBDMI_SH::getFreq, 0, 0, setter);
860  add("", prefix + "dmi.icmp", AGE, 0, 0, &TTBDMI_SH::getFreqIcmp, 0, 0, 0);
861  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
862  name << prefix << "dmi.p" << i+1;
863  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchFreq, 0, 0);
864  name.str(""); //reset the string
865  }
866  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
867  name << prefix << "icmp.p" << i+1;
868  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchIcmp, 0, 0);
869  name.str("");
870  }
871 
872 }
unsigned int getPatchNbr()
Definition: metapop.h:275
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:60
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:143
StatHandler for the DBMI trait.
Definition: ttbdmi.h:261
double getPatchIcmp(unsigned int i)
Definition: ttbdmi.h:283
void setAdultStats()
Definition: ttbdmi.cc:876
void setOffsprgStats()
Definition: ttbdmi.cc:884
double getFreqIcmp()
Definition: ttbdmi.h:281
double getFreq()
Definition: ttbdmi.h:280
double getPatchFreq(unsigned int i)
Definition: ttbdmi.h:282
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53

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

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ countAllele_diplo()

void TTBDMI_SH::countAllele_diplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)
1015 {
1016  TT_BDMI* trait;
1017  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_num_locus()/2;
1018 
1019  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
1020 
1021  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
1022 
1023  l = 0;
1024  for(unsigned int k = 0; k < num_pair; ++k) {
1025 
1026  a1 = trait->get_num_mut_diplo(l);
1027  frqTab[patch->getID()][l++] += a1;
1028 
1029  a2 = trait->get_num_mut_diplo(l);
1030  frqTab[patch->getID()][l++] += a2;
1031 
1032  icpTab[patch->getID()][k] += ((a1 == 1) && (a2 == 1));
1033  }
1034  }
1035 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497
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:533
unsigned int getID()
Definition: metapop.h:480
int get_num_locus()
Definition: ttbdmi.h:81
Definition: ttbdmi.h:149
unsigned int get_num_mut_diplo(unsigned int loc)
Definition: ttbdmi.h:193
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:172
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:170

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

+ Here is the caller graph for this function:

◆ countAllele_haplo()

void TTBDMI_SH::countAllele_haplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)
990 {
991  TT_BDMI* trait;
992  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_num_locus()/2;
993 
994  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
995 
996  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
997 
998  l = 0;
999  for(unsigned int k = 0; k < num_pair; ++k) {
1000 
1001  a1 = trait->get_num_mut_haplo(l);
1002  frqTab[patch->getID()][l++] += a1;
1003 
1004  a2 = trait->get_num_mut_haplo(l);
1005  frqTab[patch->getID()][l++] += a2;
1006 
1007  icpTab[patch->getID()][k] += a1 ^ a2;
1008  }
1009  }
1010 }
unsigned int get_num_mut_haplo(unsigned int loc)
Definition: ttbdmi.h:192

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

+ Here is the caller graph for this function:

◆ getFreq()

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

References _freq.

Referenced by addStats().

+ Here is the caller graph for this function:

◆ getFreqIcmp()

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

References _freqIcomp.

Referenced by addStats().

+ Here is the caller graph for this function:

◆ getPatchFreq()

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

References _patchFreq.

Referenced by addStats().

+ Here is the caller graph for this function:

◆ getPatchIcmp()

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

References _patchIcmp.

Referenced by addStats().

+ Here is the caller graph for this function:

◆ setAdultStats()

void TTBDMI_SH::setAdultStats ( )
877 {
880 }
bool isHaploid()
Definition: ttbdmi.h:83
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:989
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:892
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:1014
@ ADLTx
Definition: types.h:41

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

Referenced by addStats().

+ Here is the caller graph for this function:

◆ setOffsprgStats()

void TTBDMI_SH::setOffsprgStats ( )
885 {
888 }
@ OFFSx
Definition: types.h:41

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

Referenced by addStats().

+ Here is the caller graph for this function:

◆ setStatRecorders()

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

Implements StatHandlerBase.

826 {
827 #ifdef _DEBUG_
828  message("-TTBDMI_SH::setStatRecorders ");
829 #endif
830  if(token == "dmi") {
831 
832  addStats(OFFSPRG);
833  addStats(ADULTS);
834 
835  } else if(token == "off.dmi") {
836 
837  addStats(OFFSPRG);
838 
839  } else if(token == "adlt.dmi") {
840 
841  addStats(ADULTS);
842 
843  } else
844  return false;
845 
846  return true;
847 }
void addStats(age_t AGE)
Definition: ttbdmi.cc:851
void message(const char *message,...)
Definition: output.cc:39
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49

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

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

+ Here is the caller graph for this function:

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

Locations of visitors to this page
Catalogued on GSR