Nemo  2.3.46
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< TTBDMI_SH >
 StatHandler ()
 
virtual ~StatHandler ()
 
virtual void clear ()
 Empties the _recorders list, they are destroyed in StatHandlerBase::reset(). More...
 
virtual StatRecorder< TTBDMI_SH > * add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(TTBDMI_SH::*getStatNoArg)(void), double(TTBDMI_SH::*getStatOneArg)(unsigned int), double(TTBDMI_SH::*getStatTwoArg)(unsigned int, unsigned int), void(TTBDMI_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< TTBDMI_SH >
typedef std::list
< StatRecorder< TTBDMI_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< TTBDMI_SH >
std::list< StatRecorder
< TTBDMI_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 ( TProtoBDMI TP)
inline
266  _patchFreq(0), _patchIcmp(0) {}
double * _patchIcmp
Definition: ttbdmi.h:262
double * _patchFreq
Definition: ttbdmi.h:262
virtual TTBDMI_SH::~TTBDMI_SH ( )
inlinevirtual

References _patchFreq, and _patchIcmp.

268 {if(_patchFreq)delete[]_patchFreq;if(_patchIcmp)delete[]_patchIcmp;}
double * _patchIcmp
Definition: ttbdmi.h:262
double * _patchFreq
Definition: ttbdmi.h:262

Member Function Documentation

void TTBDMI_SH::addStats ( age_t  AGE)

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

Referenced by setStatRecorders().

639 {
640  string prefix = (AGE == ADULTS ? "adlt." : "off.");
641  ostringstream name;
642  void (TTBDMI_SH::* setter) () = (AGE == ADULTS ?
645 
646  add("", prefix + "dmi.freq", AGE, 0, 0, &TTBDMI_SH::getFreq, 0, 0, setter);
647  add("", prefix + "dmi.icmp", AGE, 0, 0, &TTBDMI_SH::getFreqIcmp, 0, 0, 0);
648  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
649  name << prefix << "dmi.p" << i+1;
650  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchFreq, 0, 0);
651  name.str(""); //reset the string
652  }
653  for (unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
654  name << prefix << "icmp.p" << i+1;
655  add("", name.str(), AGE, i, 0, 0, &TTBDMI_SH::getPatchIcmp, 0, 0);
656  name.str("");
657  }
658 
659 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
double getFreqIcmp()
Definition: ttbdmi.h:279
void setAdultStats()
Definition: ttbdmi.cc:663
unsigned int getPatchNbr()
Definition: metapop.h:270
void setOffsprgStats()
Definition: ttbdmi.cc:671
double getFreq()
Definition: ttbdmi.h:278
virtual StatRecorder< TTBDMI_SH > * add(std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(TTBDMI_SH::*getStatNoArg)(void), double(TTBDMI_SH::*getStatOneArg)(unsigned int), double(TTBDMI_SH::*getStatTwoArg)(unsigned int, unsigned int), void(TTBDMI_SH::*setStat)(void))
Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.
Definition: stathandler.h:144
double getPatchFreq(unsigned int i)
Definition: ttbdmi.h:280
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
double getPatchIcmp(unsigned int i)
Definition: ttbdmi.h:281
StatHandler for the DBMI trait.
Definition: ttbdmi.h:259
void TTBDMI_SH::countAllele_diplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)

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

Referenced by setAdultStats(), and setOffsprgStats().

802 {
803  TT_BDMI* trait;
804  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_nb_locus()/2;
805 
806  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
807 
808  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
809 
810  l = 0;
811  for(unsigned int k = 0; k < num_pair; ++k) {
812 
813  a1 = trait->get_num_mut_diplo(l);
814  frqTab[patch->getID()][l++] += a1;
815 
816  a2 = trait->get_num_mut_diplo(l);
817  frqTab[patch->getID()][l++] += a2;
818 
819  icpTab[patch->getID()][k] += ((a1 == 1) && (a2 == 1));
820  }
821  }
822 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
unsigned int get_num_mut_diplo(unsigned int loc)
Definition: ttbdmi.h:198
Definition: ttbdmi.h:127
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
unsigned int getID()
Definition: metapop.h:469
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
int get_nb_locus()
Definition: ttbdmi.h:77
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:523
void TTBDMI_SH::countAllele_haplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
double **  frqTab,
double **  icpTab 
)

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

Referenced by setAdultStats(), and setOffsprgStats().

777 {
778  TT_BDMI* trait;
779  unsigned int l, a1, a2, num_pair = _SHLinkedTrait->get_nb_locus()/2;
780 
781  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
782 
783  trait = dynamic_cast< TT_BDMI* > ( patch->get( SEX, AGE, j )->getTrait( _SHLinkedTraitIndex ) );
784 
785  l = 0;
786  for(unsigned int k = 0; k < num_pair; ++k) {
787 
788  a1 = trait->get_num_mut_haplo(l);
789  frqTab[patch->getID()][l++] += a1;
790 
791  a2 = trait->get_num_mut_haplo(l);
792  frqTab[patch->getID()][l++] += a2;
793 
794  icpTab[patch->getID()][k] += a1 ^ a2;
795  }
796  }
797 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Definition: ttbdmi.h:127
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
unsigned int getID()
Definition: metapop.h:469
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
int get_nb_locus()
Definition: ttbdmi.h:77
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:523
unsigned int get_num_mut_haplo(unsigned int loc)
Definition: ttbdmi.h:197
double TTBDMI_SH::getFreq ( )
inline

References _freq.

Referenced by addStats().

278 {return _freq;}
double _freq
Definition: ttbdmi.h:261
double TTBDMI_SH::getFreqIcmp ( )
inline

References _freqIcomp.

Referenced by addStats().

279 {return _freqIcomp;}
double _freqIcomp
Definition: ttbdmi.h:261
double TTBDMI_SH::getPatchFreq ( unsigned int  i)
inline

Referenced by addStats().

280 {return _patchFreq[i];}
double * _patchFreq
Definition: ttbdmi.h:262
double TTBDMI_SH::getPatchIcmp ( unsigned int  i)
inline

Referenced by addStats().

281 {return _patchIcmp[i];}
double * _patchIcmp
Definition: ttbdmi.h:262
void TTBDMI_SH::setAdultStats ( )

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

Referenced by addStats().

664 {
667 }
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:679
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
bool isHaploid()
Definition: ttbdmi.h:79
Definition: types.h:42
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:776
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:801
void TTBDMI_SH::setOffsprgStats ( )

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

Referenced by addStats().

672 {
675 }
void setStats(age_idx agex, void(TTBDMI_SH::*cntFunc)(Patch *, sex_t, age_idx, double **, double **))
Definition: ttbdmi.cc:679
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
bool isHaploid()
Definition: ttbdmi.h:79
Definition: types.h:42
void countAllele_haplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:776
void countAllele_diplo(Patch *patch, sex_t SEX, age_idx AGE, double **frqTab, double **icpTab)
Definition: ttbdmi.cc:801
bool TTBDMI_SH::setStatRecorders ( std::string &  token)
virtual

Implements StatHandlerBase.

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

613 {
614 #ifdef _DEBUG_
615  message("-TTBDMI_SH::setStatRecorders ");
616 #endif
617  if(token == "dmi") {
618 
619  addStats(OFFSPRG);
620  addStats(ADULTS);
621 
622  } else if(token == "off.dmi") {
623 
624  addStats(OFFSPRG);
625 
626  } else if(token == "adlt.dmi") {
627 
628  addStats(ADULTS);
629 
630  } else
631  return false;
632 
633  return true;
634 }
void message(const char *message,...)
Definition: output.cc:40
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
void addStats(age_t AGE)
Definition: ttbdmi.cc:638
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
void TTBDMI_SH::setStats ( age_idx  agex,
void(TTBDMI_SH::*)(Patch *, sex_t, age_idx, double **, double **)  cntFunc 
)

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

Referenced by setAdultStats(), and setOffsprgStats().

680 {
681  unsigned int i, nb_ind = 0, nb_patch = 0;
682  unsigned int nb_locus = _SHLinkedTrait->get_nb_locus();
683  unsigned int num_pair;
684  unsigned int psize=0;
685  unsigned int npatch=_pop->getPatchNbr();
686 
687  Patch* current_patch;
688 
689  num_pair = nb_locus/2;
690 
691  double* freqTable = new double [nb_locus];
692  double* icmpTable = new double [num_pair];
693  double** patchFreqTable = new double* [npatch];
694  double** patchIcmpTable = new double* [npatch];
695 
696  for(i = 0; i < nb_locus; ++i)
697  freqTable[i] = 0;
698 
699  for(i = 0; i < num_pair; ++i)
700  icmpTable[i] = 0;
701 
702  //init patch tables:
703  if(_patchFreq) delete [] _patchFreq;
704  _patchFreq = new double [npatch];
705 
706  if(_patchIcmp) delete [] _patchIcmp;
707  _patchIcmp = new double [npatch];
708 
709  //patch loop:
710  for(i = 0; i < npatch; ++i) {
711 
712  current_patch = _pop->getPatch(i);
713 
714  patchFreqTable[i] = new double [nb_locus];
715  for(unsigned int j = 0; j < nb_locus; ++j) patchFreqTable[i][j] = 0;
716 
717  patchIcmpTable[i] = new double [num_pair];
718  for(unsigned int j = 0; j < num_pair; ++j) patchIcmpTable[i][j] = 0;
719 
720  _patchFreq[i] = 0;
721  _patchIcmp[i] = 0;
722 
723  if( (psize = current_patch->size(agex)) == 0) continue;
724 
725  nb_patch++;
726 
727  nb_ind += psize;
728 
729  (this->* cntFunc) (current_patch, FEM, agex, patchFreqTable, patchIcmpTable);
730  (this->* cntFunc) (current_patch, MAL, agex, patchFreqTable, patchIcmpTable);
731 
732  //mut frequ.
733  for(unsigned int k = 0; k < nb_locus; ++k)
734  _patchFreq[i] += patchFreqTable[i][k]/psize;
735 
736  if(_SHLinkedTrait->isHaploid()) _patchFreq[i] /= nb_locus;
737  else _patchFreq[i] /= 2*nb_locus;
738 
739  //incompatibilities:
740  for(unsigned int k = 0; k < num_pair; ++k)
741  _patchIcmp[i] += patchIcmpTable[i][k]/psize;
742 
743  _patchIcmp[i] /= num_pair;
744 
745 
746  }//end for Patch
747 
748  //set pop means
749  //mut frequ:
750  _freq = 0;
751 
752  for(i = 0; i < npatch; ++i) _freq += _patchFreq[i];
753 
754  _freq /= npatch;
755 
756  //Incompatibilities:
757  _freqIcomp = 0;
758 
759  for(i = 0; i < npatch; ++i) _freqIcomp += _patchIcmp[i];
760 
761  _freqIcomp /= npatch;
762 
763 
764  delete [] freqTable;
765  delete [] icmpTable;
766  for(i = 0; i < npatch; ++i) {
767  delete [] patchFreqTable[i];
768  delete [] patchIcmpTable[i];
769  }
770  delete [] patchFreqTable;
771  delete [] patchIcmpTable;
772 }
double * _patchIcmp
Definition: ttbdmi.h:262
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
TProtoBDMI * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
bool isHaploid()
Definition: ttbdmi.h:79
unsigned int getPatchNbr()
Definition: metapop.h:270
int get_nb_locus()
Definition: ttbdmi.h:77
double * _patchFreq
Definition: ttbdmi.h:262
Definition: types.h:37
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
double _freq
Definition: ttbdmi.h:261
Definition: types.h:37
double _freqIcomp
Definition: ttbdmi.h:261

Member Data Documentation

double TTBDMI_SH::_freq
private

Referenced by getFreq(), and setStats().

double TTBDMI_SH::_freqIcomp
private

Referenced by getFreqIcmp(), and setStats().

double* TTBDMI_SH::_patchFreq
private

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

double * TTBDMI_SH::_patchIcmp
private

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


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