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

TTQuantiSH. More...

#include <ttquanti.h>

+ Inheritance diagram for TTQuantiSH:
+ Collaboration diagram for TTQuantiSH:

Public Member Functions

 TTQuantiSH (TProtoQuanti *TP)
 
virtual ~TTQuantiSH ()
 
void resetPtrs ()
 
virtual void init ()
 
virtual bool setStatRecorders (std::string &token)
 
void addQuanti (age_t AGE)
 
void addEigen (age_t AGE)
 
void addEigenValues (age_t AGE)
 
void addEigenVect1 (age_t AGE)
 
void addQuantiPerPatch (age_t AGE)
 
void addAvgPerPatch (age_t AGE)
 
void addGenotPerPatch (age_t AGE)
 
void addVarPerPatch (age_t AGE)
 
void addCovarPerPatch (age_t AGE)
 
void addEigenPerPatch (age_t AGE)
 
void addEigenValuesPerPatch (age_t AGE)
 
void addEigenVect1PerPatch (age_t AGE)
 
void addEigenStatsPerPatcg (age_t AGE)
 
void addSkewPerPatch (age_t AGE)
 
void addQuantiEpistasis (age_t AGE)
 
void addEffectStats (age_t AGE)
 
void setDataTables (age_t AGE)
 
void setAdultStats ()
 
void setOffsprgStats ()
 
void setStats (age_t AGE)
 
double getMeanGenot (unsigned int i)
 
double getMeanPhenot (unsigned int i)
 
double getVa (unsigned int i)
 
double getVg (unsigned int i)
 
double getVb (unsigned int i)
 
double getVp (unsigned int i)
 
double getQst (unsigned int i)
 
double getCovar (unsigned int i)
 
double getEigenValue (unsigned int i)
 
double getEigenVectorElt (unsigned int t1, unsigned int t2)
 
double getVaH ()
 
double getNbAlleles (unsigned int i)
 
double getMeanEffectSize (unsigned int i)
 
double getMeanGenotPerPatch (unsigned int i, unsigned int p)
 
double getMeanPhenotPerPatch (unsigned int i, unsigned int p)
 
double getVaPerPatch (unsigned int i, unsigned int p)
 
double getVpPerPatch (unsigned int i, unsigned int p)
 
double getEigenValuePerPatch (unsigned int i, unsigned int p)
 
double getCovarPerPatch (unsigned int p, unsigned int i)
 
double getEigenVectorEltPerPatch (unsigned int p, unsigned int v)
 
double getSkewPerPatch (unsigned int i, unsigned int p)
 
vector< double > getSNPalleleFreqInPatch (Patch *patch, const age_idx AGE)
 
vector< double > getVaWithDominance (Patch *curPop, const age_idx AGE)
 computation of the additive genetic variance from the average excess of each allele exact under random mating only More...
 
vector< double > getVaNoDominance (Patch *curPop, const age_idx AGE)
 
- Public Member Functions inherited from TraitStatHandler< TProtoQuanti, TTQuantiSH >
 TraitStatHandler (TProtoQuanti *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 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 _VaH
 
double * _meanP
 
double * _meanG
 
double * _Va
 
double * _Vg
 
double * _Vb
 
double * _Vp
 
double * _covar
 
double * _eigval
 
double ** _eigvect
 
double * _meanEffectSize
 
double ** _pmeanP
 
double ** _pmeanG
 
double ** _pVa
 
double ** _pVp
 
double ** _pcovar
 
double ** _peigval
 
double ** _peigvect
 
double ** _pmeanL
 
double ** _pVaL
 
double ** _pmeanEpiL
 
unsigned int _num_locus
 
unsigned int _num_trait
 
unsigned int _patchNbr
 
bool _eVar
 
bool _epistats
 
bool _alleleStats
 
set< long int > * _uniqueEffectSizes
 
map< long int, int > * _countUniqueEffects
 
gsl_matrix * _G
 
gsl_matrix * _evec
 
gsl_vector * _eval
 
gsl_eigen_symmv_workspace * _ws
 
DataTable< double > _phenoTable
 
DataTable< double > _genoTable
 
DataTable< double > _lociTable
 
DataTable< double > _lociRefTable
 
unsigned int _table_set_gen
 
unsigned int _table_set_age
 
unsigned int _table_set_repl
 

Additional Inherited Members

- Protected Types inherited from StatHandler< SH >
typedef std::list< StatRecorder< SH > * >::iterator REC_IT
 
- Protected Attributes inherited from TraitStatHandler< TProtoQuanti, TTQuantiSH >
TProtoQuanti_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

Constructor & Destructor Documentation

◆ TTQuantiSH()

TTQuantiSH::TTQuantiSH ( TProtoQuanti TP)
inline
727  _VaH(0), _meanP(0), _meanG(0), _Va(0), _Vg(0), _Vb(0), _Vp(0), _covar(0), _eigval(0), _eigvect(0), _meanEffectSize(0),
728  _pmeanP(0), _pmeanG(0), _pVa(0), _pVp(0), _pcovar(0), _peigval(0), _peigvect(0), _pmeanL(0), _pVaL(0), _pmeanEpiL(0),
731  _G(0), _evec(0),_eval(0),_ws(0),
732  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
733  {}
double * _Vp
Definition: ttquanti.h:705
double ** _pVa
Definition: ttquanti.h:706
double * _Vb
Definition: ttquanti.h:705
double ** _pVaL
Definition: ttquanti.h:707
unsigned int _num_locus
Definition: ttquanti.h:710
double ** _pmeanEpiL
Definition: ttquanti.h:707
double * _meanP
Definition: ttquanti.h:705
bool _epistats
Definition: ttquanti.h:711
double ** _pVp
Definition: ttquanti.h:706
bool _eVar
Definition: ttquanti.h:711
gsl_matrix * _evec
Definition: ttquanti.h:716
double * _meanEffectSize
Definition: ttquanti.h:705
set< long int > * _uniqueEffectSizes
Definition: ttquanti.h:713
unsigned int _table_set_age
Definition: ttquanti.h:721
double _VaH
Definition: ttquanti.h:704
double ** _pmeanP
Definition: ttquanti.h:706
double * _meanG
Definition: ttquanti.h:705
bool _alleleStats
Definition: ttquanti.h:711
gsl_vector * _eval
Definition: ttquanti.h:717
double * _covar
Definition: ttquanti.h:705
gsl_matrix * _G
Definition: ttquanti.h:716
double ** _peigvect
Definition: ttquanti.h:706
unsigned int _table_set_repl
Definition: ttquanti.h:721
gsl_eigen_symmv_workspace * _ws
Definition: ttquanti.h:718
unsigned int _table_set_gen
Definition: ttquanti.h:721
unsigned int _num_trait
Definition: ttquanti.h:710
double * _Va
Definition: ttquanti.h:705
double * _Vg
Definition: ttquanti.h:705
double ** _peigval
Definition: ttquanti.h:706
double ** _pmeanL
Definition: ttquanti.h:707
unsigned int _patchNbr
Definition: ttquanti.h:710
map< long int, int > * _countUniqueEffects
Definition: ttquanti.h:714
double ** _pcovar
Definition: ttquanti.h:706
double ** _pmeanG
Definition: ttquanti.h:706
double * _eigval
Definition: ttquanti.h:705
double ** _eigvect
Definition: ttquanti.h:705

◆ ~TTQuantiSH()

virtual TTQuantiSH::~TTQuantiSH ( )
inlinevirtual
735 {resetPtrs();}
void resetPtrs()
Definition: ttquanti.cc:4451

References resetPtrs().

Member Function Documentation

◆ addAvgPerPatch()

void TTQuantiSH::addAvgPerPatch ( age_t  AGE)
4874 {
4875  if (AGE == ALL) {
4878  return;
4879  }
4880 
4881  unsigned int patchNbr = _pop->getPatchNbr();
4882 
4883  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4884  string name;
4885  string patch;
4886  string t1;
4887 
4888  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4890 
4891  add("Mean phenotype of trait 1 in patch 1", suffix + "q1.p1", AGE, 0, 0, 0, 0,
4893 
4894  for(unsigned int p = 0; p < patchNbr; p++) {
4895  for(unsigned int i = 0; i < _num_trait; i++) {
4896  if(p == 0 && i == 0) continue;
4897  name = "Mean phenotype of trait " + tstring::int2str(i+1) + " in patch " + tstring::int2str(p+1);
4898  t1 = "q" + tstring::int2str(i+1);
4899  patch = ".p" + tstring::int2str(p+1);
4900  add(name, suffix + t1 + patch, AGE, i, p, 0, 0, &TTQuantiSH::getMeanPhenotPerPatch, 0);
4901  }
4902  }
4903 
4904 }
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
TTQuantiSH.
Definition: ttquanti.h:702
void addAvgPerPatch(age_t AGE)
Definition: ttquanti.cc:4873
double getMeanPhenotPerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.h:779
void setAdultStats()
Definition: ttquanti.h:761
void setOffsprgStats()
Definition: ttquanti.h:762
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
#define ALL
All ages age class flag.
Definition: types.h:56
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, ALL, getMeanPhenotPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by addQuantiPerPatch(), and setStatRecorders().

◆ addCovarPerPatch()

void TTQuantiSH::addCovarPerPatch ( age_t  AGE)
4997 {
4998  if(_num_trait < 2) {
4999  // warning("not recording traits covariance with only one \"quanti\" trait!");
5000  return;
5001  }
5002 
5003  if (AGE == ALL) {
5006  return;
5007  }
5008 
5009  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5010  string patch;
5011  string cov;
5012  unsigned int patchNbr = _pop->getPatchNbr();
5013 
5014  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5016 
5017  add("Genetic covariance of trait 1 and trait 2 in patch 1", suffix + "cov.q12.p1", AGE, 0, 0, 0, 0,
5018  &TTQuantiSH::getCovarPerPatch, setter);
5019 
5020  unsigned int c;
5021  for(unsigned int p = 0; p < patchNbr; p++) {
5022  patch = ".p" + tstring::int2str(p+1);
5023  c = 0;
5024  for(unsigned int t = 0; t < _num_trait; ++t) {
5025  for(unsigned int v = t + 1; v < _num_trait; ++v){
5026  if(p==0 && t==0 && v==1) {c++; continue;} //this on is already recorder above
5027  cov = tstring::int2str((t+1)*10+v+1);
5028  add("", suffix + "cov.q" + cov + patch, AGE, c++, p, 0, 0, &TTQuantiSH::getCovarPerPatch, 0);
5029  }
5030  }
5031  }
5032 
5033 }
void addCovarPerPatch(age_t AGE)
Definition: ttquanti.cc:4996
double getCovarPerPatch(unsigned int p, unsigned int i)
Definition: ttquanti.h:783

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, ALL, getCovarPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by addQuantiPerPatch(), and setStatRecorders().

◆ addEffectStats()

void TTQuantiSH::addEffectStats ( age_t  AGE)
5231 {
5232  if (AGE == ALL) {
5235  return;
5236  }
5237 
5238  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5239  string name = suffix + "q";
5240  string t1, t2;
5241 
5242  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5244 
5245  add("",suffix + "q1.alleles",AGE,0,0,0,&TTQuantiSH::getNbAlleles,0,setter);
5246 
5247  //Alleles
5248  for(unsigned int i = 1; i < _num_trait; i++) {
5249  t1 = tstring::int2str(i+1);
5250  add("", name + t1 +".alleles",AGE,i,0,0,&TTQuantiSH::getNbAlleles,0,0);
5251  }
5252 
5253  //MeanEffect
5254  for(unsigned int i = 0; i < _num_trait; i++) {
5255  t1 = tstring::int2str(i+1);
5256  add("", name + t1 +".mean.effect",AGE,i,0,0,&TTQuantiSH::getMeanEffectSize,0,0);
5257  }
5258 }
void addEffectStats(age_t AGE)
Definition: ttquanti.cc:5230
double getMeanEffectSize(unsigned int i)
Definition: ttquanti.h:776
double getNbAlleles(unsigned int i)
Definition: ttquanti.h:775

References _num_trait, StatHandler< SH >::add(), ADULTS, ALL, getMeanEffectSize(), getNbAlleles(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ addEigen()

void TTQuantiSH::addEigen ( age_t  AGE)
4770 {
4771  if(_num_trait < 2) {
4772  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
4773  return;
4774  }
4775 
4776  if (AGE == ALL) {
4777  addEigen(ADULTS);
4778  addEigen(OFFSPRG);
4779  return;
4780  }
4781 
4782  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4783 
4784  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4786 
4787  add("", suffix + "q.eval1",AGE,0,0,0,&TTQuantiSH::getEigenValue, 0, setter); //this one calls the setter
4788 
4789  for(unsigned int t = 1; t < _num_trait; ++t)
4790  add("", suffix + "q.eval" + tstring::int2str(t+1),AGE,t,0,0,&TTQuantiSH::getEigenValue, 0, 0);
4791 
4792  for(unsigned int t = 0; t< _num_trait; ++t)
4793  for(unsigned int v = 0; v < _num_trait; ++v)
4794  add("", suffix + "q.evect" + tstring::int2str((t+1)*10+(v+1)),AGE,t,v,0,0,&TTQuantiSH::getEigenVectorElt,0);
4795 
4796 }
double getEigenVectorElt(unsigned int t1, unsigned int t2)
Definition: ttquanti.h:773
void addEigen(age_t AGE)
Definition: ttquanti.cc:4769
double getEigenValue(unsigned int i)
Definition: ttquanti.h:772
void warning(const char *str,...)
Definition: output.cc:58

References _num_trait, StatHandler< SH >::add(), ADULTS, ALL, getEigenValue(), getEigenVectorElt(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

Referenced by addEigenValues(), and addEigenVect1().

◆ addEigenPerPatch()

void TTQuantiSH::addEigenPerPatch ( age_t  AGE)
5038 {
5039  if(_num_trait < 2) {
5040  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
5041  return;
5042  }
5043 
5044  if (AGE == ALL) {
5047  return;
5048  }
5049 
5050  unsigned int patchNbr = _pop->getPatchNbr();
5051  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5052  string patch;
5053  unsigned int pv =0;
5054 
5055  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5057 
5058 
5059  add("First G-matrix eigenvalue in patch 1", suffix + "qeval1.p1", AGE, 0, 0, 0, 0,
5061 
5062  for(unsigned int p = 0; p < patchNbr; ++p) {
5063  patch = ".p" + tstring::int2str(p+1);
5064  for(unsigned int t = 0; t < _num_trait; ++t) {
5065  if(p==0 && t==0) continue;
5066  add("", suffix + "qeval" + tstring::int2str(t+1) + patch, AGE, t, p, 0, 0, &TTQuantiSH::getEigenValuePerPatch,0);
5067  }
5068  }
5069  for(unsigned int p = 0; p < patchNbr; ++p) {
5070  patch = ".p" + tstring::int2str(p+1);
5071  pv = 0;
5072  for(unsigned int t = 0; t < _num_trait; ++t)
5073  for(unsigned int v = 0; v < _num_trait; ++v)
5074  add("", suffix + "qevect" + tstring::int2str((t+1)*10+v+1) + patch, AGE, p, pv++, 0, 0, &TTQuantiSH::getEigenVectorEltPerPatch,0);
5075  }
5076 
5077 }
double getEigenVectorEltPerPatch(unsigned int p, unsigned int v)
Definition: ttquanti.h:784
double getEigenValuePerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.h:782
void addEigenPerPatch(age_t AGE)
Definition: ttquanti.cc:5037

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, ALL, getEigenValuePerPatch(), getEigenVectorEltPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

Referenced by addEigenValuesPerPatch(), addEigenVect1PerPatch(), and setStatRecorders().

◆ addEigenStatsPerPatcg()

void TTQuantiSH::addEigenStatsPerPatcg ( age_t  AGE)

◆ addEigenValues()

void TTQuantiSH::addEigenValues ( age_t  AGE)
4801 {
4802  if(_num_trait < 2) {
4803  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
4804  return;
4805  }
4806 
4807  if (AGE == ALL) {
4808  addEigen(ADULTS);
4809  addEigen(OFFSPRG);
4810  return;
4811  }
4812 
4813  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4814 
4815  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4817 
4818  add("", suffix + "q.eval1",AGE,0,0,0,&TTQuantiSH::getEigenValue, 0, setter);
4819 
4820  for(unsigned int t = 1; t < _num_trait; ++t)
4821  add("", suffix + "q.eval" + tstring::int2str(t+1),AGE,t,0,0,&TTQuantiSH::getEigenValue, 0, 0);
4822 
4823 
4824 }

References _num_trait, StatHandler< SH >::add(), addEigen(), ADULTS, ALL, getEigenValue(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

◆ addEigenValuesPerPatch()

void TTQuantiSH::addEigenValuesPerPatch ( age_t  AGE)
5082 {
5083  if(_num_trait < 2) {
5084  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
5085  return;
5086  }
5087 
5088  if (AGE == ALL) {
5091  return;
5092  }
5093 
5094  unsigned int patchNbr = _pop->getPatchNbr();
5095  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5096  string patch;
5097 
5098  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5100 
5101  add("First G-matrix eigenvalue in patch 1", suffix + "qeval1.p1", AGE, 0, 0, 0, 0,
5103 
5104  for(unsigned int p = 0; p < patchNbr; ++p) {
5105  patch = ".p" + tstring::int2str(p+1);
5106  for(unsigned int t = 0; t < _num_trait; ++t) {
5107  if(p==0 && t==0) continue;
5108  add("", suffix + "qeval" + tstring::int2str(t+1) + patch, AGE, t, p, 0, 0, &TTQuantiSH::getEigenValuePerPatch,0);
5109  }
5110  }
5111 }

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), addEigenPerPatch(), ADULTS, ALL, getEigenValuePerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

Referenced by setStatRecorders().

◆ addEigenVect1()

void TTQuantiSH::addEigenVect1 ( age_t  AGE)
4829 {
4830  if(_num_trait < 2) {
4831  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
4832  return;
4833  }
4834 
4835  if (AGE == ALL) {
4836  addEigen(ADULTS);
4837  addEigen(OFFSPRG);
4838  return;
4839  }
4840 
4841  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4842 
4843  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4845 
4846  add("", suffix + "q.evect11",AGE,0,0,0,0,&TTQuantiSH::getEigenVectorElt,setter);
4847 
4848  for(unsigned int v = 1; v < _num_trait; ++v)
4849  add("", suffix + "q.evect1" + tstring::int2str(v+1),AGE,0,v,0,0,&TTQuantiSH::getEigenVectorElt,0);
4850 
4851 }

References _num_trait, StatHandler< SH >::add(), addEigen(), ADULTS, ALL, getEigenVectorElt(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

◆ addEigenVect1PerPatch()

void TTQuantiSH::addEigenVect1PerPatch ( age_t  AGE)
5116 {
5117  if(_num_trait < 2) {
5118  warning("not recording G-matrix eigen stats with only one \"quanti\" trait!\n");
5119  return;
5120  }
5121 
5122  if (AGE == ALL) {
5125  return;
5126  }
5127 
5128  unsigned int patchNbr = _pop->getPatchNbr();
5129  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5130  string patch;
5131  unsigned int pv =0;
5132 
5133  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5136 
5137 
5138  add("First G-matrix eigenvector in patch 1", suffix + "qevect11.p1", AGE, 0, 0, 0, 0,
5140 
5141  for(unsigned int p = 0; p < patchNbr; ++p) {
5142  patch = ".p" + tstring::int2str(p+1);
5143  pv = 0;
5144  // for(unsigned int t = 0; t < _num_trait; ++t)
5145  for(unsigned int v = 0; v < _num_trait; ++v){
5146  if(p==0 && v==0) {pv++; continue;}
5147  add("", suffix + "qevect1" + tstring::int2str(v+1) + patch, AGE, p, pv++, 0, 0, &TTQuantiSH::getEigenVectorEltPerPatch,0);
5148  }
5149  }
5150 }

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), addEigenPerPatch(), ADULTS, ALL, getEigenVectorEltPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), setOffsprgStats(), and warning().

Referenced by setStatRecorders().

◆ addGenotPerPatch()

void TTQuantiSH::addGenotPerPatch ( age_t  AGE)
4909 {
4910  if (AGE == ALL) {
4913  return;
4914  }
4915 
4916  unsigned int patchNbr = _pop->getPatchNbr();
4917 
4918  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4919  string name;
4920  string patch;
4921  string t1;
4922 
4923  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4925 
4926  add("Mean genotype of trait 1 in patch 1", suffix + "g1.p1", AGE, 0, 0, 0, 0,
4928 
4929  for(unsigned int p = 0; p < patchNbr; p++) {
4930  for(unsigned int i = 0; i < _num_trait; i++) {
4931  if(p == 0 && i == 0) continue;
4932  name = "Mean genotype of trait " + tstring::int2str(i+1) + " in patch " + tstring::int2str(p+1);
4933  t1 = "g" + tstring::int2str(i+1);
4934  patch = ".p" + tstring::int2str(p+1);
4935  add(name, suffix + t1 + patch, AGE, i, p, 0, 0, &TTQuantiSH::getMeanGenotPerPatch, 0);
4936  }
4937  }
4938 
4939 }
double getMeanGenotPerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.h:778
void addGenotPerPatch(age_t AGE)
Definition: ttquanti.cc:4908

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, ALL, getMeanGenotPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ addQuanti()

void TTQuantiSH::addQuanti ( age_t  AGE)
4701 {
4702  if (AGE == ALL) {
4703  addQuanti(ADULTS);
4704  addQuanti(OFFSPRG);
4705  return;
4706  }
4707 
4708  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4709  string name = suffix + "q";
4710  string t1, t2;
4711 
4712  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4714 
4715  add("",suffix + "q1",AGE,0,0,0,&TTQuantiSH::getMeanPhenot,0,setter);
4716 
4717  for(unsigned int i = 1; i < _num_trait; i++) {
4718  t1 = tstring::int2str(i+1);
4719  add("", name + t1,AGE,i,0,0,&TTQuantiSH::getMeanPhenot,0,0);
4720  }
4721 
4722  //Va, no dominance, no epistasis
4724  for(unsigned int i = 0; i < _num_trait; i++) {
4725  t1 = tstring::int2str(i+1);
4726  add("", name + t1 +".Va",AGE,i,0,0,&TTQuantiSH::getVa,0,0);
4727  }
4728  } else {
4729  //if dominance or epistasis, then what we record is Vg, not Va
4730  for(unsigned int i = 0; i < _num_trait; i++) {
4731  t1 = tstring::int2str(i+1);
4732  add("", name + t1 +".Vg",AGE,i,0,0,&TTQuantiSH::getVa,0,0);
4733  }
4734  }
4735 
4736  //Vp
4737  if(_eVar) {
4738  for(unsigned int i = 0; i < _num_trait; i++) {
4739  t1 = tstring::int2str(i+1);
4740  add("", name + t1 +".Vp",AGE,i,0,0,&TTQuantiSH::getVp,0,0);
4741  }
4742  }
4743  //Vb
4744  if(_pop->getPatchNbr() > 1){
4745  for(unsigned int i = 0; i < _num_trait; i++) {
4746  t1 = tstring::int2str(i+1);
4747  add("", name + t1 +".Vb",AGE,i,0,0,&TTQuantiSH::getVb,0,0);
4748  }
4749  //Qst
4750  for(unsigned int i = 0; i < _num_trait; i++) {
4751  t1 = tstring::int2str(i+1);
4752  add("", name + t1 +".Qst",AGE,i,0,0,&TTQuantiSH::getQst,0,0);
4753  }
4754  }
4755 
4756  if (_num_trait > 1) {
4757  unsigned int c = 0;
4758  for(unsigned int t = 0; t < _num_trait; ++t) {
4759  for(unsigned int v = t + 1; v < _num_trait; ++v) {
4760  t1 = tstring::int2str((t+1)*10+(v+1));
4761  add("", name + t1 +".cov", AGE, c++, 0,0,&TTQuantiSH::getCovar,0,0);
4762  }
4763  }
4764  }
4765 }
bool do_epistasis()
Definition: ttquanti.h:547
unsigned int get_dominance_model()
Definition: ttquanti.h:461
void addQuanti(age_t AGE)
Definition: ttquanti.cc:4700
double getVa(unsigned int i)
Definition: ttquanti.h:766
double getVb(unsigned int i)
Definition: ttquanti.h:768
double getMeanPhenot(unsigned int i)
Definition: ttquanti.h:765
double getQst(unsigned int i)
Definition: ttquanti.h:770
double getVp(unsigned int i)
Definition: ttquanti.h:769
double getCovar(unsigned int i)
Definition: ttquanti.h:771
TProtoQuanti * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171

References _eVar, _num_trait, StatHandlerBase::_pop, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, StatHandler< SH >::add(), ADULTS, ALL, TProtoQuanti::do_epistasis(), TProtoQuanti::get_dominance_model(), getCovar(), getMeanPhenot(), Metapop::getPatchNbr(), getQst(), getVa(), getVb(), getVp(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ addQuantiEpistasis()

void TTQuantiSH::addQuantiEpistasis ( age_t  AGE)
5206 {
5207  if (AGE == ALL) {
5210  return;
5211  }
5212 
5213  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5214  string name = suffix + "q";
5215  string t1, t2;
5216 
5217  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5219 
5220  add("",suffix + "q1.VaH",AGE,0,0,&TTQuantiSH::getVaH,0,0,setter);
5221 
5222 // for(unsigned int i = 1; i < _num_trait; i++) {
5223 // t1 = tstring::int2str(i+1);
5224 // add("", name + t1 + ".std",AGE,i,0,0,&TTQuantiSH::getVaH,0,0);
5225 // }
5226 }
double getVaH()
Definition: ttquanti.h:774
void addQuantiEpistasis(age_t AGE)
Definition: ttquanti.cc:5205

References StatHandler< SH >::add(), ADULTS, ALL, getVaH(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ addQuantiPerPatch()

void TTQuantiSH::addQuantiPerPatch ( age_t  AGE)
4856 {
4857 
4858  if (AGE == ALL) {
4861  return;
4862  }
4863 
4864  addAvgPerPatch(AGE);
4865  addVarPerPatch(AGE);
4866  addCovarPerPatch(AGE);
4867  // addEigenPerPatch(AGE);
4868 
4869 }
void addVarPerPatch(age_t AGE)
Definition: ttquanti.cc:4943
void addQuantiPerPatch(age_t AGE)
Definition: ttquanti.cc:4855

References addAvgPerPatch(), addCovarPerPatch(), addVarPerPatch(), ADULTS, ALL, and OFFSPRG.

Referenced by setStatRecorders().

◆ addSkewPerPatch()

void TTQuantiSH::addSkewPerPatch ( age_t  AGE)
5155 {
5156  if (AGE == ALL) {
5159  return;
5160  }
5161 
5162  unsigned int patchNbr = _pop->getPatchNbr();
5163 
5164  string suffix = (AGE == ADULTS ? "adlt.":"off.");
5165  string name;
5166  string patch;
5167  string t1;
5168 
5169  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
5172 
5173  add("Genetic skew of trait 1 in patch 1", suffix + "Sk.q1.p1", AGE, 0, 0, 0, 0,
5174  &TTQuantiSH::getSkewPerPatch, setter);
5175 
5176  for(unsigned int p = 0; p < patchNbr; p++) {
5177  for(unsigned int i = 0; i < _num_trait; i++) {
5178  if(p == 0 && i == 0) continue;
5179  name = "Genetic skew of trait " + tstring::int2str(i+1) + " in patch " + tstring::int2str(p+1);
5180  t1 = "q" + tstring::int2str(i+1);
5181  patch = ".p" + tstring::int2str(p+1);
5182  add(name, suffix + "Sk." + t1 + patch, AGE, i, p, 0, 0, &TTQuantiSH::getSkewPerPatch, 0);
5183  }
5184  }
5185 
5186 }
double getSkewPerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.cc:5190
void addSkewPerPatch(age_t AGE)
Definition: ttquanti.cc:5154

References _num_trait, StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, ALL, Metapop::getPatchNbr(), getSkewPerPatch(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by setStatRecorders().

◆ addVarPerPatch()

void TTQuantiSH::addVarPerPatch ( age_t  AGE)
4944 {
4945  if (AGE == ALL) {
4948  return;
4949  }
4950 
4951  unsigned int patchNbr = _pop->getPatchNbr();
4952 
4953  string suffix = (AGE == ADULTS ? "adlt.":"off.");
4954  string name;
4955  string patch;
4956  string t1;
4957  string Vtype;
4958 
4959 
4961  Vtype = "Vg.";
4962  else
4963  Vtype = "Va.";
4964 
4965  void (TTQuantiSH::* setter) (void) = (AGE == ADULTS ?
4968 
4969  add("Genetic variance of trait 1 in patch 1", suffix + Vtype + "q1.p1", AGE, 0, 0, 0, 0,
4970  &TTQuantiSH::getVaPerPatch, setter);
4971 
4972  for(unsigned int p = 0; p < patchNbr; p++) {
4973  for(unsigned int i = 0; i < _num_trait; i++) {
4974  if(p == 0 && i == 0) continue;
4975  name = "Genetic variance of trait " + tstring::int2str(i+1) + " in patch " + tstring::int2str(p+1);
4976  t1 = "q" + tstring::int2str(i+1);
4977  patch = ".p" + tstring::int2str(p+1);
4978  add(name, suffix + Vtype + t1 + patch, AGE, i, p, 0, 0, &TTQuantiSH::getVaPerPatch, 0);
4979  }
4980  }
4981 
4982  if(_eVar) {
4983  for(unsigned int p = 0; p < patchNbr; p++) {
4984  for(unsigned int i = 0; i < _num_trait; i++) {
4985  name = "Phenotypic variance of trait " + tstring::int2str(i+1) + " in patch " + tstring::int2str(p+1);
4986  t1 = "q" + tstring::int2str(i+1);
4987  patch = ".p" + tstring::int2str(p+1);
4988  add(name, suffix + "Vp." + t1 + patch, AGE, i, p, 0, 0, &TTQuantiSH::getVpPerPatch, 0);
4989  }
4990  }
4991  }
4992 }
double getVpPerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.h:781
double getVaPerPatch(unsigned int i, unsigned int p)
Definition: ttquanti.h:780

References _eVar, _num_trait, StatHandlerBase::_pop, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, StatHandler< SH >::add(), ADULTS, ALL, TProtoQuanti::do_epistasis(), TProtoQuanti::get_dominance_model(), Metapop::getPatchNbr(), getVaPerPatch(), getVpPerPatch(), tstring::int2str(), OFFSPRG, setAdultStats(), and setOffsprgStats().

Referenced by addQuantiPerPatch(), and setStatRecorders().

◆ getCovar()

double TTQuantiSH::getCovar ( unsigned int  i)
inline
771 {return _covar[i];}

References _covar.

Referenced by addQuanti().

◆ getCovarPerPatch()

double TTQuantiSH::getCovarPerPatch ( unsigned int  p,
unsigned int  i 
)
inline
783 {return _pcovar[p][i];}

References _pcovar.

Referenced by addCovarPerPatch().

◆ getEigenValue()

double TTQuantiSH::getEigenValue ( unsigned int  i)
inline
772 {return _eigval[i];}

References _eigval.

Referenced by addEigen(), and addEigenValues().

◆ getEigenValuePerPatch()

double TTQuantiSH::getEigenValuePerPatch ( unsigned int  i,
unsigned int  p 
)
inline
782 {return _peigval[i][p];}

References _peigval.

Referenced by addEigenPerPatch(), and addEigenValuesPerPatch().

◆ getEigenVectorElt()

double TTQuantiSH::getEigenVectorElt ( unsigned int  t1,
unsigned int  t2 
)
inline
773 {return _eigvect[t2][t1];}//eigenvectors arranged column-wise

References _eigvect.

Referenced by addEigen(), and addEigenVect1().

◆ getEigenVectorEltPerPatch()

double TTQuantiSH::getEigenVectorEltPerPatch ( unsigned int  p,
unsigned int  v 
)
inline
784 {return _peigvect[p][v];}

References _peigvect.

Referenced by addEigenPerPatch(), and addEigenVect1PerPatch().

◆ getMeanEffectSize()

double TTQuantiSH::getMeanEffectSize ( unsigned int  i)
inline
776 {return _meanEffectSize[i];}

References _meanEffectSize.

Referenced by addEffectStats().

◆ getMeanGenot()

double TTQuantiSH::getMeanGenot ( unsigned int  i)
inline
764 {return _meanG[i];}

References _meanG.

◆ getMeanGenotPerPatch()

double TTQuantiSH::getMeanGenotPerPatch ( unsigned int  i,
unsigned int  p 
)
inline
778 {return _pmeanG[i][p];}

References _pmeanG.

Referenced by addGenotPerPatch().

◆ getMeanPhenot()

double TTQuantiSH::getMeanPhenot ( unsigned int  i)
inline
765 {return _meanP[i];}

References _meanP.

Referenced by addQuanti().

◆ getMeanPhenotPerPatch()

double TTQuantiSH::getMeanPhenotPerPatch ( unsigned int  i,
unsigned int  p 
)
inline
779 {return _pmeanP[i][p];}

References _pmeanP.

Referenced by addAvgPerPatch().

◆ getNbAlleles()

double TTQuantiSH::getNbAlleles ( unsigned int  i)
inline
775 {return double(_uniqueEffectSizes[i].size()/_num_locus);}

References _num_locus, and _uniqueEffectSizes.

Referenced by addEffectStats().

◆ getQst()

double TTQuantiSH::getQst ( unsigned int  i)
inline
770 {return _Vb[i]/(_Vb[i]+2*_Va[i]);}

References _Va, and _Vb.

Referenced by addQuanti().

◆ getSkewPerPatch()

double TTQuantiSH::getSkewPerPatch ( unsigned int  i,
unsigned int  p 
)
5191 {
5192  double skew = 0;
5193 
5194  double *phenot = _phenoTable.getClassWithinGroup(i, p);
5195  unsigned int patch_size = _phenoTable.size(i, p);
5196 
5197  for(unsigned int k = 0; k < patch_size; ++k)
5198  skew += pow( phenot[k] - _pmeanP[i][p], 3); //the mean has been set by setStats()
5199 
5200  return skew / patch_size;
5201 }
unsigned int size(unsigned int i, unsigned int j)
Definition: datatable.h:260
T * getClassWithinGroup(unsigned int group, unsigned int Class)
Accessor to a class array whithin a group.
Definition: datatable.h:225
DataTable< double > _phenoTable
Definition: ttquanti.h:720

References _phenoTable, _pmeanP, DataTable< T >::getClassWithinGroup(), and DataTable< T >::size().

Referenced by addSkewPerPatch().

◆ getSNPalleleFreqInPatch()

vector< double > TTQuantiSH::getSNPalleleFreqInPatch ( Patch patch,
const age_idx  AGE 
)
5583 {
5584  //ONLY IMPLEMENTED FOR DIALLELIC LOCI!
5585  if(_SHLinkedTrait->get_allele_model() > 1)
5586  fatal("TTQuantiSH::getSNPalleleFreqInPatch::SNP allele frequencies can only be computed for di-allelic loci, sorry!\n");
5587 
5588  Individual* ind;
5589  TTQuanti* Qtrait;
5590 
5591  if(!_SHLinkedTrait) fatal("TTQuantiSH::getSNPalleleFreqInPatch:: Pointer to trait prototype is not set!\n");
5592 
5593  unsigned int seqLength = _SHLinkedTrait->get_seq_length();
5594 
5595  //create a null vector of the total sequence size, including alleles affecting all traits (max 2 for di-allelic loci)
5596  vector<double> snp_tab(seqLength, 0.0);
5597 
5598  for(unsigned int s = 0; s < 2; ++s){
5599 
5600  for(unsigned int j = 0, size = patch->size(sex_t(s), AGE); j < size; ++j) {
5601 
5602  ind = patch->get(sex_t(s), AGE, j);
5603 
5604  Qtrait = dynamic_cast<TTQuanti*>(ind->getTrait(_SHLinkedTraitIndex));
5605 
5606  //compute allele freq at all positions, we count allele 0 (freq 'p' is for trait-increasing allele in diallelic model)
5607  for(unsigned int i = 0; i < seqLength; ++i) {
5608  snp_tab[i] += !Qtrait->get_allele_bit(i, 0) + !Qtrait->get_allele_bit(i, 1);
5609  }
5610 
5611  }
5612 
5613  }
5614 
5615  // pre-compute 1/2N :
5616  double inv_size = 1.0/(2.0*patch->size(AGE));
5617 
5618  std::transform(snp_tab.cbegin(), snp_tab.cend(), snp_tab.begin(), [inv_size](double i){return i*inv_size;});
5619 
5620  return snp_tab;
5621 }
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
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 get_allele_model()
Definition: ttquanti.h:428
unsigned int get_seq_length()
Definition: ttquanti.h:421
TTQuanti.
Definition: ttquanti.h:59
virtual bool get_allele_bit(unsigned int position, unsigned int allele) const =0
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
void fatal(const char *str,...)
Definition: output.cc:96
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36

References TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTraitIndex, fatal(), Patch::get(), TTQuanti::get_allele_bit(), TProtoQuanti::get_allele_model(), TProtoQuanti::get_seq_length(), Individual::getTrait(), and Patch::size().

Referenced by getVaNoDominance(), and getVaWithDominance().

◆ getVa()

double TTQuantiSH::getVa ( unsigned int  i)
inline
766 {return _Va[i];}

References _Va.

Referenced by addQuanti().

◆ getVaH()

double TTQuantiSH::getVaH ( )
inline
774 {return _VaH;}

References _VaH.

Referenced by addQuantiEpistasis().

◆ getVaNoDominance()

vector< double > TTQuantiSH::getVaNoDominance ( Patch curPop,
const age_idx  AGE 
)

CYCLE THROUGH ALL TRAITS

5626 {
5627  // function called by LCE_QuantiModifier when setting fixed h^2
5628  unsigned int sizeF = patch->size(FEM, AGE),
5629  sizeM = patch->size(MAL, AGE);
5630  unsigned int size = sizeF + sizeM;
5631 
5632  if(!size) {return vector<double>(_num_trait, -1.0);}
5633 
5634  TTQuanti* trait;
5635 
5636  double G, meanG;
5637 
5638  vector< double > varA(_num_trait, 0.0);
5639 
5640  double *genot = new double[size];
5641 
5643  for(unsigned int TRAIT = 0; TRAIT < _num_trait; ++TRAIT)
5644  {
5645 
5646  meanG = 0;
5647 
5648  // females
5649 
5650  Individual* curInd;
5651  unsigned int gpos = 0;
5652 
5653  for(unsigned int i = 0; i < sizeF && gpos < size; ++i )
5654  {
5655  curInd = patch->get(FEM, AGE, i);
5656 
5657  trait = dynamic_cast<TTQuanti*>(curInd->getTrait(_SHLinkedTraitIndex));
5658 
5659  G = trait->get_additive_genotype(TRAIT); // genotype value
5660 
5661  genot[gpos++] = G;
5662 
5663  meanG += G;
5664 
5665  } // for each female
5666 
5667  // males
5668  for(unsigned int i = 0; i < sizeM && gpos < size; ++i )
5669  {
5670  curInd = patch->get(MAL, AGE, i);
5671 
5672  trait = dynamic_cast<TTQuanti*>(curInd->getTrait(_SHLinkedTraitIndex));
5673 
5674  G = trait->get_additive_genotype(TRAIT); // genotype value
5675 
5676  genot[gpos++] = G;
5677 
5678  meanG += G;
5679 
5680  } // for each male
5681 
5682  assert(gpos == size);
5683 
5684  meanG /= size;
5685 
5686  varA[TRAIT] = my_variance_with_fixed_mean(genot, size, meanG); // not a sample variance
5687 
5688  // record the genotypic variance in the stater
5689  _Vg[TRAIT] = varA[TRAIT];
5690 
5691 #ifdef _DEBUG_
5692  message("TTQuantiSH::getVaNoDominance:: Va = %d\n",varA[TRAIT]);
5693 
5694  const TMatrix& allele_value = _SHLinkedTrait->get_diallele_values(); // nlocus x 2
5695  double Vacheck = 0, a, d,avG;
5696  //compute the allele frequencies:
5697  vector< double > freqs = getSNPalleleFreqInPatch(patch, AGE); //it has num locus x num traits elements, in a 1D array
5698 
5699  for(unsigned int l = 0, pos; l < _num_locus; ++l)
5700  {
5701  pos = l * _num_trait + TRAIT;
5702  a = abs(allele_value.get(l,0) - allele_value.get(l,1))/2;
5703  d = allele_value.get(l,0)+allele_value.get(l,1);
5704  avG = a + d*(1-2*freqs[pos]);
5705  Vacheck += 2*freqs[pos]*(1 - freqs[pos])*avG*avG;
5706  }
5707 
5708  message("TTQuantiSH::getVaNoDominance:: Va check = %d\n",Vacheck);
5709 #endif
5710 
5711  }
5712 
5713  delete [] genot;
5714 
5715  return varA;
5716 }
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
const TMatrix & get_diallele_values()
Definition: ttquanti.h:429
vector< double > getSNPalleleFreqInPatch(Patch *patch, const age_idx AGE)
Definition: ttquanti.cc:5582
virtual double get_additive_genotype(const unsigned int trait) const =0
void message(const char *message,...)
Definition: output.cc:40
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
double my_variance_with_fixed_mean(double *data, unsigned int size, double mean)
Definition: utils.cc:63

References _num_locus, _num_trait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTraitIndex, _Vg, FEM, Patch::get(), TMatrix::get(), TTQuanti::get_additive_genotype(), TProtoQuanti::get_diallele_values(), getSNPalleleFreqInPatch(), Individual::getTrait(), MAL, message(), my_variance_with_fixed_mean(), and Patch::size().

Referenced by LCE_QuantiModifier::setParameters(), and LCE_Breed_Quanti::setParameters().

◆ getVaPerPatch()

double TTQuantiSH::getVaPerPatch ( unsigned int  i,
unsigned int  p 
)
inline
780 {return _pVa[i][p];}

References _pVa.

Referenced by addVarPerPatch().

◆ getVaWithDominance()

vector< double > TTQuantiSH::getVaWithDominance ( Patch curPop,
const age_idx  AGE 
)

computation of the additive genetic variance from the average excess of each allele exact under random mating only

CYCLE THROUGH ALL TRAITS

5725 {
5726  // function called by LCE_QuantiModifier when setting fixed h^2
5727  if(_SHLinkedTrait->get_allele_model() > 2)
5728  fatal("Quanti Trait StatHandler::Va with dominance can only be estimated for di-allelic loci, sorry!\n");
5729 
5730  unsigned int size = patch->size(AGE);
5731 
5732 #ifdef _DEBUG_
5733  message("\nTTQuantiSH::getVaWithDominance in patch %i; size = %i\n", patch->getID(), size);
5734 #endif
5735 
5736  if(!size)
5737  return vector<double>(_num_trait, -1.0);
5738 
5739 
5740  //compute the allele frequencies:
5741  vector< double > freqs = getSNPalleleFreqInPatch(patch, AGE); //it has num locus x num traits elements, in a 1D array
5742 
5743  unsigned int numLocus, pos, a1, a2;
5744  TTQuanti* trait;
5745  const TMatrix& allele_value = _SHLinkedTrait->get_diallele_values(); // nlocus x 2
5746 
5747  double G, meanG;
5748  vector< double > genotypeValues[3];
5749  vector< double > genotypeFreq[3];
5750 
5751  double *genot = new double[size];
5752 
5753  vector< double > varA(_num_trait, 0.0);
5754 
5756  for(unsigned int TRAIT = 0; TRAIT < _num_trait; ++TRAIT)
5757  {
5758 
5759  numLocus = _SHLinkedTrait->get_num_locus(TRAIT);
5760 
5761  meanG = 0;
5762 
5763  genotypeValues[0].assign(numLocus, 0.0); //AA
5764  genotypeValues[1].assign(numLocus, 0.0); //Aa/aA
5765  genotypeValues[2].assign(numLocus, 0.0); //aa
5766 
5767  genotypeFreq[0].assign(numLocus, 0.0); //AA
5768  genotypeFreq[1].assign(numLocus, 0.0); //Aa/aA
5769  genotypeFreq[2].assign(numLocus, 0.0); //aa
5770 
5771  for(unsigned int l = 0, locID; l < numLocus; ++l)
5772  {
5773  locID = _SHLinkedTrait->get_locus_ID(l, TRAIT);
5774  genotypeValues[0][l] = _SHLinkedTrait->get_genotype_with_dominance( allele_value.get(locID,0), allele_value.get(locID,0), locID, TRAIT);
5775  genotypeValues[1][l] = _SHLinkedTrait->get_genotype_with_dominance( allele_value.get(locID,0), allele_value.get(locID,1), locID, TRAIT);
5776  genotypeValues[2][l] = _SHLinkedTrait->get_genotype_with_dominance( allele_value.get(locID,1), allele_value.get(locID,1), locID, TRAIT);
5777  }
5778 
5779  // cycle trhough all individuals:
5780 
5781  Individual* curInd;
5782  unsigned int gpos = 0, fpos = 0;
5783 
5784  for(unsigned int s = 0; s < 2; ++s) {
5785  for(unsigned int i = 0; i < patch->size(sex_t(s), AGE) && gpos < size; ++i )
5786  {
5787  curInd = patch->get(sex_t(s), AGE, i);
5788 
5789  trait = dynamic_cast<TTQuanti*>(curInd->getTrait(_SHLinkedTraitIndex));
5790 
5791  G = trait->get_full_genotype(TRAIT); // genotype value
5792 
5793  meanG += G;
5794 
5795  genot[gpos++] = G;
5796 
5797  for(unsigned int l = 0; l < numLocus; ++l)
5798  {
5799  pos = _SHLinkedTrait->get_locus_seq_pos(l, TRAIT); //l * _num_trait + TRAIT;
5800 
5801  a1 = trait->get_allele_bit(pos, 0);
5802  a2 = trait->get_allele_bit(pos, 1);
5803 
5804  fpos = a1 + a2; //which genotype: 0 = AA, 1 = Aa/aA, 2 = aa
5805 
5806  genotypeFreq[fpos][l]++;
5807 
5808  // if( genotypeValues[fpos][l] != _SHLinkedTrait->get_genotype_with_dominance( genes[0][pos], genes[1][pos], locID, TRAIT))
5809  // {
5810  // cout << "assert failure: genot table value: "<<genotypeValues[fpos][l]<<" at "<<fpos
5811  // <<"; genot value: "<<_SHLinkedTrait->get_genotype_with_dominance( genes[0][pos], genes[1][pos], locID, TRAIT)
5812  // <<" ("<< genes[0][pos]<<", "<< genes[1][pos] <<", "<<_SHLinkedTrait->get_dominance(locID, TRAIT)<<")\n";
5813  // }
5814  }
5815 
5816 
5817  } // for each female
5818  }
5819 
5820  assert(gpos == size);
5821 
5822  meanG /= size;
5823 
5824  // record the genotypic variance in the stater, will be needed to comput Ve
5825  _Vg[TRAIT] = my_variance_with_fixed_mean(genot, size, meanG);
5826 
5827  for(unsigned int l = 0; l < numLocus; ++l)
5828  {
5829  genotypeFreq[0][l] /= size;
5830  genotypeFreq[1][l] /= size;
5831  genotypeFreq[2][l] /= size;
5832  }
5833 
5834 
5835  // compute the average excess (alphaStar) which is identical to the additive effects under random mating
5836 
5837  // !!! THIS DOESN'T WORK AT ALL !!!
5838 
5839 // vector< double > alphaStar[2];
5840 // alphaStar[0].assign(_num_locus, 0.0);
5841 // alphaStar[1].assign(_num_locus, 0.0);
5842 //
5843 // double mean_alpha = 0;
5844 //
5845 // for(unsigned int l = 0; l < _num_locus; ++l)
5846 // {
5847 //
5848 // pos = l * _num_trait + TRAIT;
5849 //
5850 // // average excess of each allele; the frequency table contains the frequency of the first allele only
5851 // // here, we condition on the genotype being present in the population, in case HW equilibrium is not reached
5852 // // eq 4.13b Lynch & Walsh 98
5853 // // allele frequency freq[pos] is that of the first allele at [0]
5854 // alphaStar[0][l] = genotypeValues[1][l] * (1.0 - freqs[pos]) + genotypeValues[0][l] * freqs[pos] - meanG; // alpha*_1
5855 //
5856 // alphaStar[1][l] = genotypeValues[1][l] * freqs[pos] + genotypeValues[2][l] * (1.0-freqs[pos]) - meanG; // alpha*_2
5857 //
5861 //
5862 // mean_alpha += (alphaStar[0][l] + alphaStar[1][l])/2;
5863 //
5864 // varA[TRAIT] += alphaStar[0][l]*alphaStar[0][l]*freqs[pos] + alphaStar[1][l]*alphaStar[1][l]*(1-freqs[pos]); // SUM(p_i*alpha_i^2)
5865 //
5866 // }
5867 // varA[TRAIT] *= 2; // for diploids
5868 //
5869 // cout <<"TTQuantiSH::getVaWithDominance:: Va = "<<varA[TRAIT]<< " (mean alpha = "<<mean_alpha/_num_locus<<")"<<endl;
5870 
5871 
5872  // check form general formula Va = 2pq[a + d(q-p)]^2 !! q here is 1-freqs[pos], freq of smaller allele (reducing value) which has index [1]
5873  double Vacheck = 0, a, d,avG, VDcheck = 0, vd, p, q, pq;
5874  for(unsigned int l = 0; l < numLocus; ++l)
5875  {
5876  // the freq vector has same arrangement of loci as the quanti sequence in the genome
5877  pos = _SHLinkedTrait->get_locus_seq_pos(l, TRAIT);
5878  p = freqs[pos];
5879  q = 1 - freqs[pos];
5880  pq= p*q;
5881  a = abs(genotypeValues[0][l] - genotypeValues[2][l])/2.0;
5882  d = genotypeValues[1][l];
5883  avG = a + d*(1-2*p); //'freqs' stores 'p' not 'q', at same location in the array as loci in the sequences
5884  Vacheck += 2*pq*avG*avG;
5885  vd = 2*pq*d;
5886  VDcheck += vd*vd;
5887  }
5888 
5890  varA [TRAIT] = _Vg[TRAIT];
5891  else
5892  varA[TRAIT] = Vacheck;
5893 
5894 #ifdef _DEBUG_
5895  message("TTQuantiSH::getVaWithDominance:: mean genotype = %d\n", meanG);
5896  message("TTQuantiSH::getVaWithDominance:: var genotype Vg = %d\n",_Vg[TRAIT]);
5897  message("TTQuantiSH::getVaWithDominance:: estimates: Va = %d, Vd = %d, Vg = %d\n", Vacheck, VDcheck, Vacheck+VDcheck);
5898 #endif
5899 
5900  } //for each trait
5901 
5902  delete [] genot;
5903 
5904  return varA;
5905 }
unsigned int get_locus_ID(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:442
unsigned int get_locus_seq_pos(unsigned int loc, unsigned int trait)
Definition: ttquanti.h:440
unsigned int get_num_locus()
Definition: ttquanti.h:418
bool get_h2_isBroad()
Definition: ttquanti.h:427
double get_genotype_with_dominance(const double a1, const double a2, const unsigned int locus, const unsigned int trait)
Definition: ttquanti.cc:2504
virtual double get_full_genotype(unsigned int trait)=0

References _num_trait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTraitIndex, _Vg, fatal(), Patch::get(), TMatrix::get(), TTQuanti::get_allele_bit(), TProtoQuanti::get_allele_model(), TProtoQuanti::get_diallele_values(), TTQuanti::get_full_genotype(), TProtoQuanti::get_genotype_with_dominance(), TProtoQuanti::get_h2_isBroad(), TProtoQuanti::get_locus_ID(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), Patch::getID(), getSNPalleleFreqInPatch(), Individual::getTrait(), message(), my_variance_with_fixed_mean(), and Patch::size().

Referenced by LCE_QuantiModifier::setParameters(), and LCE_Breed_Quanti::setParameters().

◆ getVb()

double TTQuantiSH::getVb ( unsigned int  i)
inline
768 {return _Vb[i];}

References _Vb.

Referenced by addQuanti().

◆ getVg()

double TTQuantiSH::getVg ( unsigned int  i)
inline
767 {return _Vg[i];}

References _Vg.

Referenced by LCE_QuantiModifier::setVefromVa().

◆ getVp()

double TTQuantiSH::getVp ( unsigned int  i)
inline
769 {return _Vp[i];}

References _Vp.

Referenced by addQuanti().

◆ getVpPerPatch()

double TTQuantiSH::getVpPerPatch ( unsigned int  i,
unsigned int  p 
)
inline
781 {return _pVp[i][p];}

References _pVp.

Referenced by addVarPerPatch().

◆ init()

void TTQuantiSH::init ( )
virtual

Reimplemented from StatHandlerBase.

4545 {
4547 
4549 
4550  _eVar = (!_SHLinkedTrait->get_env_var().empty() || !_SHLinkedTrait->get_heritability().empty());
4551 
4552  resetPtrs(); //deallocate anything that was previously allocated
4553 
4554  if(_patchNbr != _pop->getPatchNbr())
4555  _patchNbr = _pop->getPatchNbr();
4556 
4559 
4562 
4563  _meanP = new double [_num_trait];
4564  _meanG = new double [_num_trait];
4565  _Va = new double [_num_trait];
4566  _Vg = new double [_num_trait];
4567  _Vb = new double [_num_trait];
4568  _Vp = new double [_num_trait];
4569 // _eigval = new double [_num_trait]; // this was used to store the among-patch D-matrix eigenvalues
4570  _uniqueEffectSizes = new set<long int> [_num_trait];
4571  _countUniqueEffects = new map<long int, int> [_num_trait];
4572  _meanEffectSize = new double [_num_trait];
4573 
4574 
4575  _pVa = new double* [_num_trait];
4576  _pVp = new double* [_num_trait];
4577  _pmeanP = new double* [_num_trait];
4578  _pmeanG = new double* [_num_trait];
4579 
4580  for(unsigned int i=0; i < _num_trait; ++i) {
4581 
4582  _pVa[i] = new double [_patchNbr];
4583  _pVp[i] = new double [_patchNbr];
4584  _pmeanP[i] = new double [_patchNbr];
4585  _pmeanG[i] = new double [_patchNbr];
4586 
4587  }
4588 
4589 
4590  _pVaL = new double* [_num_locus];
4591  _pmeanL = new double* [_num_locus];
4592  _pmeanEpiL = new double* [_num_locus];
4593  for(unsigned int i=0; i < _num_locus; ++i) {
4594  _pVaL[i] = new double [_patchNbr];
4595  _pmeanL[i] = new double [_patchNbr];
4596  _pmeanEpiL[i] = new double [_patchNbr];
4597  }
4598 
4599 
4600 
4601  if(_num_trait > 1) {
4602 
4603  _G = gsl_matrix_alloc(_num_trait,_num_trait);
4604  _eval = gsl_vector_alloc (_num_trait);
4605  _evec = gsl_matrix_alloc (_num_trait, _num_trait);
4606  _ws = gsl_eigen_symmv_alloc (_num_trait);
4607 
4608  _peigval = new double* [_num_trait];
4609 // _eigvect = new double* [_num_trait];
4610 
4611  for(unsigned int i=0; i < _num_trait; ++i) {
4612 // _eigvect[i] = new double [_num_trait];
4613  _peigval[i] = new double [_patchNbr];
4614  }
4615 
4616  _peigvect = new double* [_patchNbr];
4617 
4618  for(unsigned int i = 0; i < _patchNbr; i++)
4619  _peigvect[i] = new double [_num_trait*_num_trait];
4620 
4621  _covar = new double [_num_trait*(_num_trait -1)/2];
4622 
4623  _pcovar = new double* [_num_trait*(_num_trait - 1)/2];
4624 
4625  for(unsigned int i = 0; i < _num_trait*(_num_trait - 1)/2; i++)
4626  _pcovar[i] = new double [_patchNbr];
4627 
4628  }
4629 
4630 }
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:128
virtual void init()
Definition: stathandler.cc:39
vector< double > get_heritability()
Definition: ttquanti.h:425
virtual trait_t get_type() const
Definition: ttquanti.h:555
unsigned int get_num_traits()
Definition: ttquanti.h:417
vector< double > get_env_var()
Definition: ttquanti.h:424

References _countUniqueEffects, _covar, _eval, _eVar, _evec, _G, _meanEffectSize, _meanG, _meanP, _num_locus, _num_trait, _patchNbr, _pcovar, _peigval, _peigvect, _pmeanEpiL, _pmeanG, _pmeanL, _pmeanP, StatHandlerBase::_pop, _pVa, _pVaL, _pVp, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTraitIndex, _uniqueEffectSizes, _Va, _Vb, _Vg, _Vp, _ws, TProtoQuanti::get_env_var(), TProtoQuanti::get_heritability(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), TProtoQuanti::get_type(), Metapop::getPatchNbr(), IndFactory::getTraitIndex(), StatHandlerBase::init(), and resetPtrs().

◆ resetPtrs()

void TTQuantiSH::resetPtrs ( )
4452 {
4453 
4454  if(_G) gsl_matrix_free(_G);
4455  if(_eval) gsl_vector_free(_eval);
4456  if(_evec) gsl_matrix_free(_evec);
4457  if(_ws) gsl_eigen_symmv_free (_ws);
4458 
4459  if(_meanP) delete [] _meanP; _meanP = NULL;
4460  if(_meanG) delete [] _meanG; _meanG = NULL;
4461  if(_Va) delete [] _Va; _Va = NULL;
4462  if(_Vg) delete [] _Vg; _Vg = NULL;
4463  if(_Vb) delete [] _Vb; _Vb = NULL;
4464  if(_Vp) delete [] _Vp; _Vp = NULL;
4465 
4466 
4467  if(_pVa) {
4468  for(unsigned int i=0; i < _num_trait; ++i) delete [] _pVa[i];
4469  delete [] _pVa; _pVa = NULL;
4470  }
4471  if(_pVp) {
4472  for(unsigned int i=0; i < _num_trait; ++i) delete [] _pVp[i];
4473  delete [] _pVp; _pVp = NULL;
4474  }
4475  if(_pmeanP) {
4476  for(unsigned int i=0; i < _num_trait; ++i) delete [] _pmeanP[i];
4477  delete [] _pmeanP; _pmeanP = NULL;
4478  }
4479  if(_pmeanG) {
4480  for(unsigned int i=0; i < _num_trait; ++i) delete [] _pmeanG[i];
4481  delete [] _pmeanG; _pmeanG = NULL;
4482  }
4483 
4484  // tables whose allocation depends on trait options need to be set to NULL
4485 
4486 // if(_eigval) delete [] _eigval;
4487 // _eigval = NULL;
4488 //
4489 // if(_eigvect) {
4490 // for(unsigned int i=0; i < _num_trait; ++i) delete [] _eigvect[i];
4491 // delete [] _eigvect;
4492 // _eigvect = NULL;
4493 // }
4494 
4495  if(_peigval) {
4496  for(unsigned int i=0; i < _num_trait; ++i) delete [] _peigval[i];
4497  delete [] _peigval;
4498  _peigval = NULL;
4499  }
4500 
4501  if(_covar) delete [] _covar;
4502  _covar = NULL;
4503 
4504  if(_pcovar) {
4505  for(unsigned int i = 0; i < (_num_trait*(_num_trait - 1)/2); i++) delete [] _pcovar[i];
4506  delete [] _pcovar;
4507  _pcovar = NULL;
4508  }
4509 
4510  if(_peigvect) {
4511  for(unsigned int i = 0; i < _patchNbr; i++) delete [] _peigvect[i];
4512  delete [] _peigvect;
4513  _peigvect = NULL;
4514  }
4515 
4516  if(_pVaL) {
4517  for(unsigned int i=0; i < _num_locus; ++i) delete [] _pVaL[i];
4518  delete [] _pVaL;
4519  _pVaL = NULL;
4520  }
4521  if(_pmeanL) {
4522  for(unsigned int i=0; i < _num_locus; ++i) delete [] _pmeanL[i];
4523  delete [] _pmeanL;
4524  _pmeanL = NULL;
4525  }
4526  if(_pmeanEpiL) {
4527  for(unsigned int i=0; i < _num_locus; ++i) delete [] _pmeanEpiL[i];
4528  delete [] _pmeanEpiL;
4529  _pmeanEpiL = NULL;
4530  }
4531 
4532  if(_meanEffectSize) delete [] _meanEffectSize;
4533  _meanEffectSize = NULL;
4534 
4536  _countUniqueEffects = NULL;
4537 
4538  if(_meanEffectSize) delete [] _meanEffectSize;
4539  _meanEffectSize = NULL;
4540 }

References _countUniqueEffects, _covar, _eval, _evec, _G, _meanEffectSize, _meanG, _meanP, _num_locus, _num_trait, _patchNbr, _pcovar, _peigval, _peigvect, _pmeanEpiL, _pmeanG, _pmeanL, _pmeanP, _pVa, _pVaL, _pVp, _Va, _Vb, _Vg, _Vp, and _ws.

Referenced by init(), and ~TTQuantiSH().

◆ setAdultStats()

◆ setDataTables()

void TTQuantiSH::setDataTables ( age_t  AGE)
5263 {
5264  unsigned int **sizes;
5265  unsigned int **lsizes;
5266  unsigned int nb_patch = _pop->getPatchNbr();
5267  const TMatrix& epiCoefs = _SHLinkedTrait->get_epi_coefs();
5268  const TMatrix& epiCoefsIdxs = _SHLinkedTrait->get_epi_coef_index();
5269 
5270  sizes = new unsigned int * [_num_trait];
5271 
5272  for(unsigned int i = 0; i < _num_trait; ++i) {
5273  sizes[i] = new unsigned int [nb_patch];
5274  for(unsigned int j = 0; j < nb_patch; ++j)
5275  sizes[i][j] = _pop->size(AGE, j);
5276  }
5277 
5278  _phenoTable.update(_num_trait, nb_patch, sizes);
5279  _genoTable.update(_num_trait, nb_patch, sizes);
5280 
5281  for(unsigned int i = 0; i < _num_trait; ++i)
5282  delete [] sizes[i];
5283  delete [] sizes;
5284 
5285  Patch* patch;
5286  age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
5287 
5288 
5289  if (_epistats) {
5290 
5291  lsizes = new unsigned int * [_num_locus];
5292 
5293  for(unsigned int i = 0; i < _num_locus; ++i) {
5294  lsizes[i] = new unsigned int [_patchNbr];
5295  for(unsigned int j = 0; j < _patchNbr; ++j)
5296  lsizes[i][j] = _pop->size(AGE, j);
5297  }
5298 
5301 
5302  for(unsigned int i = 0; i < _num_locus; ++i)
5303  delete [] lsizes[i];
5304  delete [] lsizes;
5305  }
5306 
5307  if (_alleleStats) {
5308  for(unsigned int k = 0; k < _num_trait; k++) {
5309  _uniqueEffectSizes[k].clear();
5310  _countUniqueEffects[k].clear();
5311  }
5312  }
5313 
5314  for(unsigned int i = 0, n, m; i < nb_patch; i++) {
5315 
5316  patch = _pop->getPatch(i);
5317 
5318  n = 0, m = 0;
5319 
5320  if ((patch->size(MAL, age)+patch->size(FEM, age)) != _phenoTable.size(0,i)) {
5321  fatal("problem while recording quanti trait values; table size doesn't match patch size.\n");
5322  }
5323  store_quanti_trait_values(patch, i, patch->size(MAL, age), &n, MAL, age, &_phenoTable, &_genoTable,
5325 
5326  store_quanti_trait_values(patch, i, patch->size(FEM, age), &n, FEM, age, &_phenoTable, &_genoTable,
5328 
5329  if (n != _phenoTable.size(0,i) || n != _genoTable.size(0,i)) {
5330  fatal("problem while recording quanti trait values; size counter doesn't match table size.\n");
5331  }
5332 
5333 
5334  unsigned int loc;
5335  TTQuanti_diallelic *trait;
5336 
5337  if (_epistats) {
5338 
5339  for(unsigned int s = 0; s < 2; ++s) {
5340 
5341  for(unsigned int j = 0; j < patch->size(sex_t(s), age); ++j) {
5342 
5343  trait = dynamic_cast<TTQuanti_diallelic*> (patch->get(sex_t(s), age, j)->getTrait(_SHLinkedTraitIndex));
5344 
5345  // "Relative pairwise epistasis factor", cf. second term of Eq.2 from Carter et al. (2005, TPB)
5346  map< int, double > epiFacPerLocus;
5347 
5348  for(unsigned int l = 0; l < epiCoefs.length(); l++) {
5349 
5350  epiFacPerLocus[epiCoefsIdxs.get(l,0)] +=
5351  epiCoefs.get(0,l) * (trait->get_allele_value(epiCoefsIdxs.get(l,1), 0) + trait->get_allele_value(epiCoefsIdxs.get(l,1), 1));
5352 
5353  epiFacPerLocus[epiCoefsIdxs.get(l,1)] +=
5354  epiCoefs.get(0,l) * (trait->get_allele_value(epiCoefsIdxs.get(l,0), 0) + trait->get_allele_value(epiCoefsIdxs.get(l,0), 1));
5355  }
5356 
5357  for(unsigned int l = 0; l < _num_locus; l++) {
5358  _lociTable.set(l, i, m, trait->get_allele_value(l, 0) + trait->get_allele_value(l, 1));
5359  _lociRefTable.set(l, i, m, 1 + epiFacPerLocus[l]);
5360  }
5361  m++;
5362  }
5363  }
5364  } // end epistasis
5365 
5366  if (_alleleStats) {
5367 
5368  for(unsigned int s = 0; s < 2; ++s) {
5369 
5370  for(unsigned int j = 0; j < patch->size(MAL, age); ++j) {
5371 
5372  trait = dynamic_cast<TTQuanti_diallelic*> (patch->get(MAL, age, j)->getTrait(_SHLinkedTraitIndex));
5373 
5374  for(unsigned int k = 0; k < _num_trait; k++) {
5375  for(unsigned int l = 0; l < _num_locus; l++) {
5376  loc = l * _num_trait + k;
5377  _uniqueEffectSizes[k].insert(trait->get_allele_value(loc, 0) * 1000000);
5378  _uniqueEffectSizes[k].insert(trait->get_allele_value(loc, 1) * 1000000);
5379  ++_countUniqueEffects[k][trait->get_allele_value(loc, 0) * 1000000];
5380  ++_countUniqueEffects[k][trait->get_allele_value(loc, 1) * 1000000];
5381  }
5382  }
5383  } // end for each individual
5384  } // end for each sex
5385  } //allele stats
5386 
5387  } // end for patches
5388 }
void set(unsigned int group, unsigned int Class, unsigned int elmnt, T val)
Sets the element 'elmnt' of the class 'Class' in the group 'group' to the value 'val'.
Definition: datatable.h:232
void update(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Updates the group and classe sizes and re-allocates the table according to its new length.
Definition: datatable.h:154
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:312
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
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:218
const TMatrix & get_epi_coefs() const
Definition: ttquanti.h:548
const TMatrix & get_epi_coef_index() const
Definition: ttquanti.h:549
DataTable< double > _lociTable
Definition: ttquanti.h:720
DataTable< double > _lociRefTable
Definition: ttquanti.h:720
DataTable< double > _genoTable
Definition: ttquanti.h:720
TTQuanti_diallelic.
Definition: ttquanti.h:276
virtual double get_allele_value(int locus, int allele) const
Definition: ttquanti.cc:3908
void store_quanti_trait_values(Patch *patch, unsigned int patchID, unsigned int size, unsigned int *cntr, sex_t SEX, age_idx AGE, DataTable< double > *ptable, DataTable< double > *gtable, unsigned int nTrait, unsigned int TraitIndex)
Definition: ttquanti.cc:5392
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References _alleleStats, _countUniqueEffects, _epistats, _genoTable, _lociRefTable, _lociTable, _num_locus, _num_trait, _patchNbr, _phenoTable, StatHandlerBase::_pop, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTraitIndex, _uniqueEffectSizes, ADLTx, ADULTS, fatal(), FEM, Patch::get(), TMatrix::get(), TTQuanti_diallelic::get_allele_value(), TProtoQuanti::get_epi_coef_index(), TProtoQuanti::get_epi_coefs(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), TMatrix::length(), MAL, OFFSx, DataTable< T >::set(), Metapop::size(), Patch::size(), DataTable< T >::size(), store_quanti_trait_values(), and DataTable< T >::update().

Referenced by setStats().

◆ setOffsprgStats()

◆ setStatRecorders()

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

Implements StatHandlerBase.

4635 {
4636 #ifdef _DEBUG_
4637  message("-TTQuantiSH::setStatRecorders ");
4638 #endif
4639  string age_tag = token.substr(0,token.find_first_of("."));
4640  string sub_token;
4641  age_t AGE = ALL;
4642 
4643  if (age_tag.size() != 0 && age_tag.size() != string::npos) {
4644 
4645  if (age_tag == "adlt") AGE = ADULTS;
4646 
4647  else if (age_tag == "off") AGE = OFFSPRG;
4648 
4649  else age_tag = "";
4650 
4651  } else {
4652  age_tag = "";
4653  }
4654 
4655  if (age_tag.size() != 0)
4656  sub_token = token.substr(token.find_first_of(".") + 1, string::npos);
4657  else
4658  sub_token = token;
4659 
4660  if(sub_token == "quanti") {
4661  addQuanti(AGE);
4662 // } else if(sub_token == "quanti.eigen") { //based on Vb; among-patch (D) matrix
4663 // addEigen(AGE);
4664 // } else if(sub_token == "quanti.eigenvalues") { //based on Vb; among-patch (D) matrix
4665 // addEigenValues(AGE);
4666 // } else if(sub_token == "quanti.eigenvect1") { //based on Vb; among-patch (D) matrix
4667 // addEigenVect1(AGE);
4668  } else if(sub_token == "quanti.patch") {
4669  addQuantiPerPatch(AGE);
4670  } else if(sub_token == "quanti.mean.patch") {
4671  addAvgPerPatch(AGE);
4672  } else if(sub_token == "quanti.geno.patch") {
4673  addGenotPerPatch(AGE);
4674  } else if(sub_token == "quanti.var.patch") {
4675  addVarPerPatch(AGE);
4676  } else if(sub_token == "quanti.covar.patch") {
4677  addCovarPerPatch(AGE);
4678  } else if(sub_token == "quanti.eigen.patch") {
4679  addEigenPerPatch(AGE);
4680  } else if(sub_token == "quanti.eigenvalues.patch") {
4682  } else if(sub_token == "quanti.eigenvect1.patch") {
4683  addEigenVect1PerPatch(AGE);
4684  } else if(sub_token == "quanti.skew.patch") {
4685  addSkewPerPatch(AGE);
4686  } else if((sub_token == "quanti.epistasis") && (_SHLinkedTrait->do_epistasis())) {
4687  addQuantiEpistasis(AGE);
4688  _epistats = true;
4689  } else if(sub_token == "quanti.effect.stats") {
4690  addEffectStats(AGE);
4691  _alleleStats = true;
4692  } else
4693  return false;
4694 
4695  return true;
4696 }
void addEigenVect1PerPatch(age_t AGE)
Definition: ttquanti.cc:5115
void addEigenValuesPerPatch(age_t AGE)
Definition: ttquanti.cc:5081
unsigned int age_t
Age class flags.
Definition: types.h:46

References _alleleStats, _epistats, TraitStatHandler< TProtoQuanti, TTQuantiSH >::_SHLinkedTrait, addAvgPerPatch(), addCovarPerPatch(), addEffectStats(), addEigenPerPatch(), addEigenValuesPerPatch(), addEigenVect1PerPatch(), addGenotPerPatch(), addQuanti(), addQuantiEpistasis(), addQuantiPerPatch(), addSkewPerPatch(), addVarPerPatch(), ADULTS, ALL, TProtoQuanti::do_epistasis(), message(), and OFFSPRG.

◆ setStats()

void TTQuantiSH::setStats ( age_t  AGE)
5417 {
5418  if(_table_set_age == AGE
5421  return;
5422 
5423  unsigned int pop_size = _pop->size(AGE);
5424  unsigned int patch_size;
5425  double *phenot1, *genot1, *genot2, *meanL, *meanEpiL;
5426 
5427  unsigned int nb_patch = _pop->getPatchNbr();
5428 
5429  if(nb_patch < _patchNbr) {
5430  warning("increase in patch number detected (in Quanti Stat Handler),");
5431  warning("stats for quanti trait will not be recorded in new patches, patch identity may have changed.\n");
5432  _patchNbr = nb_patch; // record stat only in remaining patches
5433  }
5434 
5435  if(nb_patch > _patchNbr) nb_patch = _patchNbr; //tables have been allocated for _patchNbr patches
5436 
5437  setDataTables(AGE);
5438 
5439 #ifdef HAS_GSL
5440  unsigned int c = 0; //covariance position counter
5441  unsigned int pv = 0; //eigenvector position counter
5442 
5443  //within deme stats:
5444  for(unsigned int j = 0; j < nb_patch; j++) {
5445 
5446  patch_size = _pop->size(AGE, j);
5447 
5448  for(unsigned int t=0; t < _num_trait; t++) {
5449 
5450  phenot1 = _phenoTable.getClassWithinGroup(t,j);
5451  genot1 = _genoTable.getClassWithinGroup(t,j);
5452 
5453  _pmeanP[t][j] = my_mean (phenot1, patch_size );
5454  _pmeanG[t][j] = my_mean (genot1, patch_size );
5455  _pVp[t][j] = my_variance_with_fixed_mean (phenot1, patch_size, _pmeanP[t][j]);
5456  _pVa[t][j] = my_variance_with_fixed_mean (genot1, patch_size, _pmeanG[t][j]);
5457 
5458  }
5459 
5460  if (_epistats) { // note: this works for one trait only
5461  for(unsigned int l=0; l < _num_locus; l++) {
5462  meanL = _lociTable.getClassWithinGroup(l,j);
5463  _pmeanL[l][j] = my_mean(meanL, patch_size);
5464  _pVaL[l][j] = my_variance_with_fixed_mean(meanL, patch_size, _pmeanL[l][j]);
5465  meanEpiL = _lociRefTable.getClassWithinGroup(l,j);
5466  _pmeanEpiL[l][j] = my_mean(meanEpiL, patch_size);
5467  }
5468  }
5469 
5470  if(_num_trait > 1) {
5471  c = 0;
5472  // calculate the covariances and G, need to adjust dimensions in class declaration
5473  for(unsigned int t1 = 0; t1 < _num_trait; t1++) {
5474  // set the diagonal elements of G here
5475 
5476  gsl_matrix_set(_G, t1, t1, _pVa[t1][j]);
5477 
5478  for(unsigned int t2 = t1 + 1; t2 < _num_trait; t2++) {
5479 
5480  genot1 = _genoTable.getClassWithinGroup(t1,j);
5481  genot2 = _genoTable.getClassWithinGroup(t2,j);
5482 
5483  _pcovar[c][j] = gsl_stats_covariance_m (genot1, 1, genot2, 1, patch_size,
5484  _pmeanG[t1][j], _pmeanG[t2][j]);
5485 
5486  gsl_matrix_set(_G, t1, t2, _pcovar[c][j]);
5487  gsl_matrix_set(_G, t2, t1, _pcovar[c++][j]);
5488  }
5489  }
5490 
5491  gsl_eigen_symmv (_G, _eval, _evec, _ws);
5492  gsl_eigen_symmv_sort (_eval, _evec, GSL_EIGEN_SORT_VAL_DESC);
5493 
5494  pv = 0;
5495 
5496  for(unsigned int t = 0; t < _num_trait; t++) {
5497  _peigval[t][j] = gsl_vector_get (_eval, t);
5498  for(unsigned int v = 0; v < _num_trait; v++)
5499  _peigvect[j][pv++] = gsl_matrix_get (_evec, v, t); //read eigenvectors column-wise
5500  }
5501  }
5502  } //_end_ for patch
5503 
5504  double meanGamong1;
5505  c = 0; //reset covariance positioner
5506 
5507  //among demes stats:
5508  for(unsigned int t1 = 0; t1 < _num_trait; t1++) {
5509 
5510  phenot1 = _phenoTable.getGroup(t1);
5511  genot1 = _genoTable.getGroup(t1);
5512 
5513  _meanP[t1] = my_mean (phenot1, pop_size ); //grand mean, pooling all individuals
5514  _meanG[t1] = my_mean (genot1, pop_size ); //grand mean, pooling all individuals
5515 
5516  _Vp[t1] = my_mean_no_nan (_pVp[t1], nb_patch); //mean within patch variance
5517  _Va[t1] = my_mean_no_nan (_pVa[t1], nb_patch); //mean within patch variance
5518 
5519  meanGamong1 = my_mean_no_nan (_pmeanG[t1], nb_patch); //mean of within patch mean genotypic values
5520 
5521  _Vb[t1] = my_variance_with_fixed_mean_no_nan (_pmeanG[t1], nb_patch, meanGamong1); //variance of patch means
5522 
5523  //_G here becomes the D-matrix, the among-deme (Difference) covariance matrix
5524  // DEPRECATED
5525 // gsl_matrix_set(_G, t1, t1, _Vb[t1]);
5526 
5527  for(unsigned int t2 = t1 + 1; t2 < _num_trait; t2++) {
5528 
5529  _covar[c] = my_covariance_no_nan(_pmeanG[t1], _pmeanG[t2], nb_patch, nb_patch);
5530 
5531 // gsl_matrix_set(_G, t1, t2, _covar[c]);
5532 // gsl_matrix_set(_G, t2, t1, _covar[c]);
5533 
5534  //set covariance to the mean covariance within patch for recording
5535  _covar[c] = my_mean_no_nan (_pcovar[c], nb_patch);
5536 
5537  c++;
5538  }
5539 
5540  if (_alleleStats) {
5541  for (set<long int>::iterator it = _uniqueEffectSizes[t1].begin(); it != _uniqueEffectSizes[t1].end(); it++)
5542  _meanEffectSize[t1] += *it * _countUniqueEffects[t1][*it] / 1000000;
5543  _meanEffectSize[t1] /= (_num_locus * pop_size);
5544  }
5545 
5546 
5547  } //_end_ for trait
5548 
5549  if (_epistats) {
5550  _VaH = 0;
5551  for(unsigned int l=0; l < _num_locus; l++) {
5552  _VaH += pow(_pmeanEpiL[l][0], 2) * _pVaL[l][0];
5553  }
5554  }
5555 
5556  // This is for the D-matrix, among-patch divergence matrix
5557  // DEPRECATED
5558 // if(_num_trait > 1) {
5559 // gsl_eigen_symmv (_G, _eval, _evec, _ws);
5560 // gsl_eigen_symmv_sort (_eval, _evec, GSL_EIGEN_SORT_VAL_DESC);
5561 //
5562 // for(unsigned int t1 = 0; t1 < _num_trait; t1++) {
5563 // _eigval[t1] = gsl_vector_get (_eval, t1);
5564 // for(unsigned int t2 = 0; t2 < _num_trait; t2++) {
5565 // _eigvect[t2][t1] = gsl_matrix_get (_evec, t2, t1);
5566 // }
5567 // }
5568 // }
5569 
5570 #else
5571  fatal("install the GSL library to get the quanti stats!\n");
5572 #endif
5573 
5574  _table_set_age = AGE;
5577 
5578 }
T * getGroup(unsigned int group)
Accessor to a group array.
Definition: datatable.h:223
unsigned int getCurrentReplicate()
Definition: metapop.h:295
unsigned int getCurrentGeneration()
Definition: metapop.h:296
void setDataTables(age_t AGE)
Definition: ttquanti.cc:5262
double my_variance_with_fixed_mean_no_nan(double *data, unsigned int size, double mean)
Definition: utils.cc:74
double my_mean(double *data, unsigned int size)
Definition: utils.cc:38
double my_mean_no_nan(double *data, unsigned int size)
Definition: utils.cc:49
double my_covariance_no_nan(double *data1, double *data2, unsigned int size1, unsigned int size2)
Definition: utils.cc:88

References _alleleStats, _countUniqueEffects, _covar, _epistats, _eval, _evec, _G, _genoTable, _lociRefTable, _lociTable, _meanEffectSize, _meanG, _meanP, _num_locus, _num_trait, _patchNbr, _pcovar, _peigval, _peigvect, _phenoTable, _pmeanEpiL, _pmeanG, _pmeanL, _pmeanP, StatHandlerBase::_pop, _pVa, _pVaL, _pVp, _table_set_age, _table_set_gen, _table_set_repl, _uniqueEffectSizes, _Va, _VaH, _Vb, _Vp, _ws, fatal(), DataTable< T >::getClassWithinGroup(), Metapop::getCurrentGeneration(), Metapop::getCurrentReplicate(), DataTable< T >::getGroup(), Metapop::getPatchNbr(), my_covariance_no_nan(), my_mean(), my_mean_no_nan(), my_variance_with_fixed_mean(), my_variance_with_fixed_mean_no_nan(), setDataTables(), Metapop::size(), and warning().

Referenced by setAdultStats(), and setOffsprgStats().

Member Data Documentation

◆ _alleleStats

bool TTQuantiSH::_alleleStats
private

◆ _countUniqueEffects

map<long int, int>* TTQuantiSH::_countUniqueEffects
private

◆ _covar

double * TTQuantiSH::_covar
private

Referenced by getCovar(), init(), resetPtrs(), and setStats().

◆ _eigval

double * TTQuantiSH::_eigval
private

Referenced by getEigenValue().

◆ _eigvect

double ** TTQuantiSH::_eigvect
private

Referenced by getEigenVectorElt().

◆ _epistats

bool TTQuantiSH::_epistats
private

◆ _eval

gsl_vector* TTQuantiSH::_eval
private

Referenced by init(), resetPtrs(), and setStats().

◆ _eVar

bool TTQuantiSH::_eVar
private

Referenced by addQuanti(), addVarPerPatch(), and init().

◆ _evec

gsl_matrix * TTQuantiSH::_evec
private

Referenced by init(), resetPtrs(), and setStats().

◆ _G

gsl_matrix* TTQuantiSH::_G
private

Referenced by init(), resetPtrs(), and setStats().

◆ _genoTable

DataTable< double > TTQuantiSH::_genoTable
private

Referenced by setDataTables(), and setStats().

◆ _lociRefTable

DataTable< double > TTQuantiSH::_lociRefTable
private

Referenced by setDataTables(), and setStats().

◆ _lociTable

DataTable< double > TTQuantiSH::_lociTable
private

Referenced by setDataTables(), and setStats().

◆ _meanEffectSize

double * TTQuantiSH::_meanEffectSize
private

◆ _meanG

double * TTQuantiSH::_meanG
private

◆ _meanP

double* TTQuantiSH::_meanP
private

◆ _num_locus

unsigned int TTQuantiSH::_num_locus
private

◆ _num_trait

◆ _patchNbr

unsigned int TTQuantiSH::_patchNbr
private

◆ _pcovar

double ** TTQuantiSH::_pcovar
private

◆ _peigval

double ** TTQuantiSH::_peigval
private

◆ _peigvect

double ** TTQuantiSH::_peigvect
private

◆ _phenoTable

DataTable< double > TTQuantiSH::_phenoTable
private

◆ _pmeanEpiL

double ** TTQuantiSH::_pmeanEpiL
private

Referenced by init(), resetPtrs(), and setStats().

◆ _pmeanG

double ** TTQuantiSH::_pmeanG
private

◆ _pmeanL

double** TTQuantiSH::_pmeanL
private

Referenced by init(), resetPtrs(), and setStats().

◆ _pmeanP

double** TTQuantiSH::_pmeanP
private

◆ _pVa

double ** TTQuantiSH::_pVa
private

◆ _pVaL

double ** TTQuantiSH::_pVaL
private

Referenced by init(), resetPtrs(), and setStats().

◆ _pVp

double ** TTQuantiSH::_pVp
private

◆ _table_set_age

unsigned int TTQuantiSH::_table_set_age
private

Referenced by setStats().

◆ _table_set_gen

unsigned int TTQuantiSH::_table_set_gen
private

Referenced by setStats().

◆ _table_set_repl

unsigned int TTQuantiSH::_table_set_repl
private

Referenced by setStats().

◆ _uniqueEffectSizes

set< long int >* TTQuantiSH::_uniqueEffectSizes
private

◆ _Va

double * TTQuantiSH::_Va
private

Referenced by getQst(), getVa(), init(), resetPtrs(), and setStats().

◆ _VaH

double TTQuantiSH::_VaH
private

Referenced by getVaH(), and setStats().

◆ _Vb

double * TTQuantiSH::_Vb
private

Referenced by getQst(), getVb(), init(), resetPtrs(), and setStats().

◆ _Vg

double * TTQuantiSH::_Vg
private

◆ _Vp

double * TTQuantiSH::_Vp
private

Referenced by getVp(), init(), resetPtrs(), and setStats().

◆ _ws

gsl_eigen_symmv_workspace* TTQuantiSH::_ws
private

Referenced by init(), resetPtrs(), and setStats().


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