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

The stat handler for neutral markers. More...

#include <ttneutralgenes.h>

+ Inheritance diagram for TTNeutralGenesSH:
+ Collaboration diagram for TTNeutralGenesSH:

Public Member Functions

 TTNeutralGenesSH (TProtoNeutralGenes *TP)
 
virtual ~TTNeutralGenesSH ()
 
virtual void init ()
 
virtual bool setStatRecorders (std::string &token)
 
void setFreqRecorders (age_t AGE)
 
void setFreqRecordersPerPatch (age_t AGE)
 
void setFstatRecorders (age_t AGE)
 
void setFstatWCRecorders (age_t AGE)
 
void setCoaMatrixRecorders (age_t AGE, unsigned char dim)
 
void setFstMatrixRecorders (age_t AGE, unsigned char dim)
 
void setNeiGeneticDistanceRecorders (age_t AGE, bool pairwise)
 
void setDxyRecorders (age_t AGE, bool patchwise)
 
Allele and genotype frequencies:
void setAdultAlleleFreq ()
 
void setOffspringAlleleFreq ()
 
void setHeterozygosity (age_t AGE)
 
void setAdultHeterozygosity ()
 
void setOffspringHeterozygosity ()
 
double getGlobalAlleleFreq (unsigned int loc, unsigned int all)
 
double getHeterozygosity (unsigned int loc)
 
F-stats:
void setAlleleTables (age_t AGE)
 
void setHeteroTable (age_t AGE)
 
void allocateTables (unsigned int loci, unsigned int all)
 
DataTable< double > * getAlleleFreqTable ()
 Accessor to the table of allele frequencies, per patch. More...
 
DataTable< unsigned int > * getAlleleCountTable ()
 
DataTable< double > * getHeteroTable ()
 
TMatrixgetGlobalFreqs ()
 Accessor to the table of allele frequencies in the whole population. More...
 
void setFstMatrix (age_t AGE, unsigned char dim)
 Computes the weighted within and between patch Fst's as well as the overall Fst (Theta). More...
 
void setAdultsFstMatrix ()
 
void setAdultsFstWithin ()
 
void setAdultsFstBetween ()
 
void setOffsprgFstMatrix ()
 
void setOffsprgFstWithin ()
 
void setOffsprgFstBetween ()
 
double getWeightedFst ()
 Returns the weighted Fst using Weir & Hill (2002) method. More...
 
double getFst_ij (unsigned int i)
 Accessor to the Fst matrix as set by setFstMatrix(). More...
 
void setFst_li (unsigned int N, unsigned int L, double **array)
 Computes the per-locus per-patch Fst values using Weir&Hill 2002 approach. More...
 
void setFstat (age_t AGE)
 Computes the F-statistics following Nei & Chesser (1983). More...
 
void setFstat_bitstring (age_t AGE)
 Streaming F-stat computation for diallelic bitstring traits. More...
 
void setOffsprgFstat ()
 
void setAdultsFstat ()
 
double setHo (age_idx age_pos)
 
double setHs (age_idx age_pos)
 
double setHt (age_idx age_pos)
 
double getHsnei ()
 
double getHtnei ()
 
double getHo ()
 
double getHs ()
 
double getHt ()
 
double getFst ()
 
double getFis ()
 
double getFit ()
 
deque< double > setHo2 (age_idx age_pos)
 New version of Nei & Chesser. More...
 
deque< double > setHs2 (age_idx age_pos)
 
deque< double > setHt2 (age_idx age_pos)
 
void setFstatWeirCockerham (age_t AGE)
 Computes the Weir & Cockerham (1984) Fstat values (Theta, F, and f). More...
 
void setFstatWeirCockerham_bitstring (age_t AGE)
 Streaming W&C Fstat for diallelic bitstring traits. More...
 
void setFstatWeirCockerham_MS (age_t AGE)
 
void setOffspringFstatWeirCockerham ()
 
void setAdultsFstatWeirCockerham ()
 
double getFstWC ()
 
double getFisWC ()
 
double getFitWC ()
 
void setLociDivCounter (age_t AGE)
 Sets the allelic diversity counters. More...
 
double getNbAllLocal ()
 
double getNbAllGlobal ()
 
double getFixLocLocal ()
 
double getFixLocGlobal ()
 
Coancestries
double Coancestry (const TTrait *ind1, const TTrait *ind2, unsigned int nb_locus)
 Gives the coancestry (probability of identity by state) of two gene sequences. More...
 
void setCoaMatrix (age_idx age_pos, unsigned char dim)
 Computes the within and between patches coancestry coefficients. More...
 
void setAdultsCoaMatrix ()
 
void setOffsprgCoaMatrix ()
 
void setAdultsCoaWithin ()
 
void setOffsprgCoaWithin ()
 
void setAdultsCoaBetween ()
 
void setOffsprgCoaBetween ()
 
void setAdults_Theta ()
 
double getCoa (unsigned int i)
 Gets the given coancestry coefficient from the coancestry matrix. More...
 
double getMeanTheta ()
 
double getMeanAlpha ()
 
double getTheta_FF ()
 Gives the mean within females coancestry coefficient. More...
 
double getTheta_MM ()
 Gives the mean within males coancestry coefficient. More...
 
double getTheta_FM ()
 Gives the mean between males and females coancestry coefficient. More...
 
void setSibStats ()
 
void setSibCoa (Individual *I1, Individual *I2)
 
double getSibProportions (unsigned int i)
 
double getSibCoaMeans (unsigned int i)
 
Nei's genetic distance:
void setAdltNeiGeneticDistance ()
 
void setOffsprgNeiGeneticDistance ()
 
void setNeiGeneticDistance (age_t AGE)
 
double getNeiGeneticDistance (unsigned int i)
 
double getMeanNeiGeneticDistance ()
 
Sequence divergence: Dxy (Nei & Li 1979; Nei 1987)
double getDxyOffspringPerPatch (unsigned int patch1, unsigned patch2)
 
double getDxyAdultPerPatch (unsigned int patch1, unsigned patch2)
 
double getDxyPerPatch (age_idx age, unsigned int patch1, unsigned patch2)
 
double getDxy (unsigned int age_class)
 
- Public Member Functions inherited from TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >
 TraitStatHandler (TProtoNeutralGenes *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

DataTable< unsigned int > _alleleCountTable
 
DataTable< double > _alleleFreqTable
 
DataTable< double > _heteroTable
 
TMatrix _globalAlleleFreq
 
unsigned int _table_set_gen
 
unsigned int _table_set_age
 
unsigned int _table_set_repl
 
bool _is_diallelic_bitstring
 
double Theta_FF
 
double Theta_MM
 
double Theta_FM
 
double _mean_theta
 
double _mean_alpha
 
TMatrix_coa_matrix
 
double _sib_prop [4]
 Kinship classes proportions. More...
 
double _sib_coa [4]
 
double _ho
 F-statistics. More...
 
double _hs
 
double _ht
 
double _hsnei
 
double _htnei
 
double _nb_all_local
 
double _nb_all_global
 
double _fst
 
double _fis
 
double _fit
 
double _fix_loc_local
 
double _fix_loc_global
 
double _fst_WH
 Weir & Hill (2002) F-stat estimates. More...
 
double _fst_WC
 Weir & Cockerham (1984) F-stat estimates. More...
 
double _fis_WC
 
double _fit_WC
 
double * _fst_WC_loc
 Per-locus F-stats (Weir&Cockerham). More...
 
double * _fis_WC_loc
 
double * _fit_WC_loc
 
double _fst_W1
 
double _fst_W2
 
TMatrix_fst_matrix
 Pairwise Fst matrix. More...
 
TMatrix_D
 
double _meanD
 

Additional Inherited Members

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

The stat handler for neutral markers.

Constructor & Destructor Documentation

◆ TTNeutralGenesSH()

TTNeutralGenesSH::TTNeutralGenesSH ( TProtoNeutralGenes TP)
inline
360  _fit_WC_loc(0), _fst_matrix(0), _D(0)
361  { }
double * _fis_WC_loc
Definition: ttneutralgenes.h:345
TMatrix * _fst_matrix
Pairwise Fst matrix.
Definition: ttneutralgenes.h:349
unsigned int _table_set_gen
Definition: ttneutralgenes.h:326
TMatrix * _D
Definition: ttneutralgenes.h:352
double * _fst_WC_loc
Per-locus F-stats (Weir&Cockerham).
Definition: ttneutralgenes.h:345
double * _fit_WC_loc
Definition: ttneutralgenes.h:345
TMatrix * _coa_matrix
Definition: ttneutralgenes.h:331
bool _is_diallelic_bitstring
Definition: ttneutralgenes.h:327
unsigned int _table_set_age
Definition: ttneutralgenes.h:326
unsigned int _table_set_repl
Definition: ttneutralgenes.h:326

◆ ~TTNeutralGenesSH()

virtual TTNeutralGenesSH::~TTNeutralGenesSH ( )
inlinevirtual
364  {
365  if(_coa_matrix != NULL) delete _coa_matrix;
366  if(_fst_matrix != NULL) delete _fst_matrix;
367  if(_fst_WC_loc) delete[]_fst_WC_loc;
368  if(_fis_WC_loc) delete[]_fis_WC_loc;
369  if(_fit_WC_loc) delete[]_fit_WC_loc;
370  if(_D != NULL) delete _D;
371  }

References _coa_matrix, _D, _fis_WC_loc, _fit_WC_loc, _fst_matrix, and _fst_WC_loc.

Member Function Documentation

◆ allocateTables()

void TTNeutralGenesSH::allocateTables ( unsigned int  loci,
unsigned int  all 
)
45 {
46  unsigned int nb_patch = _pop->getPatchNbr();
47  unsigned int **sizes;
48 
49  sizes = new unsigned int * [nb_patch];
50 
51  for(unsigned int i = 0; i < nb_patch; ++i) {
52  sizes[i] = new unsigned int [loci];
53  for(unsigned int j = 0; j < loci; ++j)
54  sizes[i][j] = all;
55  }
56 
57  _alleleCountTable.allocate(nb_patch, loci, sizes);
58 
59  _alleleFreqTable.allocate(nb_patch, loci, sizes);
60 
61  _globalAlleleFreq.reset(loci, all);
62 
63  for(unsigned int i = 0; i < nb_patch; ++i)
64  delete [] sizes[i];
65  delete [] sizes;
66 
67  //reset the time info, to force recalculation after allocate
69  _table_set_gen = 0;
70  _table_set_repl = 0;
71 }
void allocate(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Creates a table of size given by the sum of all classes passed by the 'classSizes' matrix.
Definition: datatable.h:106
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
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160
DataTable< unsigned int > _alleleCountTable
Definition: ttneutralgenes.h:322
TMatrix _globalAlleleFreq
Definition: ttneutralgenes.h:325
DataTable< double > _alleleFreqTable
Definition: ttneutralgenes.h:323
#define NONE
No age flag.
Definition: types.h:47

References _alleleCountTable, _alleleFreqTable, _globalAlleleFreq, StatHandlerBase::_pop, _table_set_age, _table_set_gen, _table_set_repl, DataTable< T >::allocate(), Metapop::getPatchNbr(), NONE, and TMatrix::reset().

Referenced by init(), setAlleleTables(), setFstat(), TTNeutralGenesFH::write_Fst_i(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ Coancestry()

double TTNeutralGenesSH::Coancestry ( const TTrait ind1,
const TTrait ind2,
unsigned int  nb_locus 
)

Gives the coancestry (probability of identity by state) of two gene sequences.

The probability returned is the average probability of having two identical alleles at a locus between the two sequences.

Parameters
ind1first _sequence, treated as of type (unsigned char**)
ind2second _sequence, treated as of type (unsigned char**)
nb_locusnumber of loci present in each _sequence
43 {
44  unsigned int p = 0;
45 
46  for (unsigned int k = 0; k < nb_locus; ++k)
47  p += (ind1->get_allele(k,0)==ind2->get_allele(k,0))
48  + (ind1->get_allele(k,0)==ind2->get_allele(k,1))
49  + (ind1->get_allele(k,1)==ind2->get_allele(k,0))
50  + (ind1->get_allele(k,1)==ind2->get_allele(k,1));
51 
52  return (double)p/(4.0*nb_locus);
53 }
virtual unsigned int get_allele(int loc, int all) const =0
Called to read the allele identity at a locus.

References TTrait::get_allele().

◆ getAlleleCountTable()

DataTable< unsigned int >* TTNeutralGenesSH::getAlleleCountTable ( )
inline
416 {return &_alleleCountTable;}

References _alleleCountTable.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getAlleleFreqTable()

DataTable<double>* TTNeutralGenesSH::getAlleleFreqTable ( )
inline

Accessor to the table of allele frequencies, per patch.

414 {return &_alleleFreqTable;}

References _alleleFreqTable.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getCoa()

double TTNeutralGenesSH::getCoa ( unsigned int  i)
inline

Gets the given coancestry coefficient from the coancestry matrix.

Parameters
icombination of the row and column indexes (see setCoaMatrixRecorders()).
Note
the upper half and the diagonal of the matrix are filled, other positions are set to 0.
528  {
529  unsigned int scale = (unsigned int)pow( 10.0, (int)log10((float)_coa_matrix->getNbCols()) + 1 );
530  return _coa_matrix->get(i/scale, i%scale);
531  }
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:214
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192

References _coa_matrix, TMatrix::get(), and TMatrix::getNbCols().

◆ getDxy()

double TTNeutralGenesSH::getDxy ( unsigned int  age_class)
1540 {
1541  double D = 0;
1542  unsigned int p = 0;
1543 
1544  age_t AGE = (static_cast<age_idx>(age_class) == OFFSx ? OFFSPRG : ADULTS);
1545 
1546  for (unsigned int p1 = 0; p1 < _pop->getPatchNbr(); ++p1) {
1547 
1548  if( !_pop->size( AGE , p1) ) continue;
1549 
1550  for (unsigned int p2 = p1 + 1; p2 < _pop->getPatchNbr(); ++p2) {
1551 
1552  if( !_pop->size( AGE , p2) ) continue;
1553 
1554  D += getDxyPerPatch(static_cast<age_idx>(age_class), p1, p2);
1555 
1556  p++;
1557  }
1558  }
1559 
1560  return (p != 0 ? D/p : nanf("NULL"));
1561 }
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
double getDxyPerPatch(age_idx age, unsigned int patch1, unsigned patch2)
Definition: stats_fstat.cc:1565
unsigned int age_t
Age class flags.
Definition: types.h:45
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:40
@ OFFSx
Definition: types.h:41

References StatHandlerBase::_pop, ADULTS, getDxyPerPatch(), Metapop::getPatchNbr(), OFFSPRG, OFFSx, and Metapop::size().

Referenced by setDxyRecorders().

+ Here is the caller graph for this function:

◆ getDxyAdultPerPatch()

double TTNeutralGenesSH::getDxyAdultPerPatch ( unsigned int  patch1,
unsigned  patch2 
)
inline
562 {return getDxyPerPatch(ADLTx, patch1, patch2);}
@ ADLTx
Definition: types.h:41

References ADLTx, and getDxyPerPatch().

Referenced by setDxyRecorders().

+ Here is the caller graph for this function:

◆ getDxyOffspringPerPatch()

double TTNeutralGenesSH::getDxyOffspringPerPatch ( unsigned int  patch1,
unsigned  patch2 
)
inline
561 {return getDxyPerPatch(OFFSx, patch1, patch2);}

References getDxyPerPatch(), and OFFSx.

Referenced by setDxyRecorders().

+ Here is the caller graph for this function:

◆ getDxyPerPatch()

double TTNeutralGenesSH::getDxyPerPatch ( age_idx  age,
unsigned int  patch1,
unsigned  patch2 
)
1566 {
1567  double D = 0;
1568  Patch* patch_1 = _pop->getPatchPtr(patch1);
1569  Patch* patch_2 = _pop->getPatchPtr(patch2);
1570  unsigned int size_1 = patch_1->size(FEM, age);
1571  unsigned int size_2 = patch_2->size(FEM, age);
1572  unsigned int N = 0;//4*size_1 * size_2;// (2N)^2, tot num of haplotype comparisons
1573 
1574 
1575  unsigned int num_loc = _SHLinkedTrait->get_locus_num();
1576 
1577  TTrait *trait_1, *trait_2;
1578 
1579  //females:
1580  for (unsigned int i = 0; i < size_1; ++i) {
1581 
1582  trait_1 = patch_1->get(FEM, age, i)->getTrait(_SHLinkedTraitIndex);
1583 
1584  for (unsigned int j = 0; j < size_2; ++j) {
1585 
1586  trait_2 = patch_2->get(FEM, age, j)->getTrait(_SHLinkedTraitIndex);
1587 
1588  for (unsigned int l = 0; l < num_loc; ++l) {
1589  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 0));
1590  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 1));
1591  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 1));
1592  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 0));
1593  }
1594  N += 4;
1595  }
1596 
1597  for (unsigned int j = 0; j < patch_2->size(MAL, age); ++j) {
1598 
1599  trait_2 = patch_2->get(MAL, age, j)->getTrait(_SHLinkedTraitIndex);
1600 
1601  for (unsigned int l = 0; l < num_loc; ++l) {
1602  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 0));
1603  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 1));
1604  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 1));
1605  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 0));
1606  }
1607  N += 4;
1608 
1609  }
1610  }
1611 
1612  //same for the males:
1613  size_1 = patch_1->size(MAL, age);
1614  size_2 = patch_2->size(MAL, age);
1615 
1616 // N += 4 * size_1 * size_2;
1617 
1618 // if( N == 0) return 0; //needless to go further
1619 
1620  for (unsigned int i = 0; i < size_1; ++i) {
1621 
1622  trait_1 = patch_1->get(MAL, age, i)->getTrait(_SHLinkedTraitIndex);
1623 
1624  for (unsigned int j = 0; j < size_2; ++j) {
1625 
1626  trait_2 = patch_2->get(MAL, age, j)->getTrait(_SHLinkedTraitIndex);
1627 
1628  for (unsigned int l = 0; l < num_loc; ++l) {
1629  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 0));
1630  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 1));
1631  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 1));
1632  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 0));
1633  }
1634  N += 4;
1635  }
1636 
1637  for (unsigned int j = 0; j < patch_2->size(FEM, age); ++j) {
1638 
1639  trait_2 = patch_2->get(FEM, age, j)->getTrait(_SHLinkedTraitIndex);
1640 
1641  for (unsigned int l = 0; l < num_loc; ++l) {
1642  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 0));
1643  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 1));
1644  D += (trait_1->get_allele(l, 0) != trait_2->get_allele(l, 1));
1645  D += (trait_1->get_allele(l, 1) != trait_2->get_allele(l, 0));
1646  }
1647  N += 4;
1648 
1649  }
1650  }
1651 
1652  if( N == 0) return 0;
1653 
1654  return D/N;
1655 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:259
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
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 get_locus_num()
Definition: ttneutralgenes.h:199
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:172
TProtoNeutralGenes * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:170
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36

References StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, FEM, Patch::get(), TTrait::get_allele(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchPtr(), Individual::getTrait(), MAL, and Patch::size().

Referenced by getDxy(), getDxyAdultPerPatch(), and getDxyOffspringPerPatch().

+ Here is the caller graph for this function:

◆ getFis()

double TTNeutralGenesSH::getFis ( )
inline
470 {return _fis;}
double _fis
Definition: ttneutralgenes.h:339

References _fis.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFisWC()

double TTNeutralGenesSH::getFisWC ( )
inline
488 {return _fis_WC;}
double _fis_WC
Definition: ttneutralgenes.h:343

References _fis_WC.

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ getFit()

double TTNeutralGenesSH::getFit ( )
inline
471 {return _fit;}
double _fit
Definition: ttneutralgenes.h:339

References _fit.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFitWC()

double TTNeutralGenesSH::getFitWC ( )
inline
489 {return _fit_WC;}
double _fit_WC
Definition: ttneutralgenes.h:343

References _fit_WC.

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ getFixLocGlobal()

double TTNeutralGenesSH::getFixLocGlobal ( )
inline
495 {return _fix_loc_global;}
double _fix_loc_global
Definition: ttneutralgenes.h:339

References _fix_loc_global.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFixLocLocal()

double TTNeutralGenesSH::getFixLocLocal ( )
inline
494 {return _fix_loc_local;}
double _fix_loc_local
Definition: ttneutralgenes.h:339

References _fix_loc_local.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFst()

double TTNeutralGenesSH::getFst ( )
inline
469 {return _fst;}
double _fst
Definition: ttneutralgenes.h:339

References _fst.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFst_ij()

double TTNeutralGenesSH::getFst_ij ( unsigned int  i)
inline

Accessor to the Fst matrix as set by setFstMatrix().

444  {
445  unsigned int scale = (unsigned int)pow( 10.0, (int)log10((float)_fst_matrix->getNbCols()) + 1 );
446  return _fst_matrix->get(i/scale, i%scale);
447  }

References _fst_matrix, TMatrix::get(), and TMatrix::getNbCols().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ getFstWC()

double TTNeutralGenesSH::getFstWC ( )
inline
487 {return _fst_WC;}
double _fst_WC
Weir & Cockerham (1984) F-stat estimates.
Definition: ttneutralgenes.h:343

References _fst_WC.

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ getGlobalAlleleFreq()

double TTNeutralGenesSH::getGlobalAlleleFreq ( unsigned int  loc,
unsigned int  all 
)
inline
395  {
396  return _globalAlleleFreq.get(loc, all);
397  }

References _globalAlleleFreq, and TMatrix::get().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ getGlobalFreqs()

TMatrix* TTNeutralGenesSH::getGlobalFreqs ( )
inline

Accessor to the table of allele frequencies in the whole population.

421 {return &_globalAlleleFreq;}

References _globalAlleleFreq.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getHeteroTable()

DataTable<double>* TTNeutralGenesSH::getHeteroTable ( )
inline
418 {return &_heteroTable;}
DataTable< double > _heteroTable
Definition: ttneutralgenes.h:324

References _heteroTable.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getHeterozygosity()

double TTNeutralGenesSH::getHeterozygosity ( unsigned int  loc)
inline
399  {
400  double het = 0;
401  for(unsigned int i = 0; i < _heteroTable.getNumGroups(); ++i )
402  het += _heteroTable.get(i, loc, 0);
403  return het/_heteroTable.getNumGroups(); //mean per patch heterozygosity
404  }
T get(unsigned int group, unsigned int Class, unsigned int elmnt)
Returns value stored of the element 'elmnt' of the class 'Class' in the group 'group'.
Definition: datatable.h:227
unsigned int getNumGroups()
Definition: datatable.h:257

References _heteroTable, DataTable< T >::get(), and DataTable< T >::getNumGroups().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ getHo()

double TTNeutralGenesSH::getHo ( )
inline
466 {return _ho;}
double _ho
F-statistics.
Definition: ttneutralgenes.h:338

References _ho.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getHs()

double TTNeutralGenesSH::getHs ( )
inline
467 {return _hs;}
double _hs
Definition: ttneutralgenes.h:338

References _hs.

◆ getHsnei()

double TTNeutralGenesSH::getHsnei ( )
inline
464 {return _hsnei;}
double _hsnei
Definition: ttneutralgenes.h:338

References _hsnei.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getHt()

double TTNeutralGenesSH::getHt ( )
inline
468 {return _ht;}
double _ht
Definition: ttneutralgenes.h:338

References _ht.

◆ getHtnei()

double TTNeutralGenesSH::getHtnei ( )
inline
465 {return _htnei;}
double _htnei
Definition: ttneutralgenes.h:338

References _htnei.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getMeanAlpha()

double TTNeutralGenesSH::getMeanAlpha ( )
inline
533 {return _mean_alpha;}
double _mean_alpha
Definition: ttneutralgenes.h:330

References _mean_alpha.

◆ getMeanNeiGeneticDistance()

double TTNeutralGenesSH::getMeanNeiGeneticDistance ( )
inline
556 {return _meanD;}
double _meanD
Definition: ttneutralgenes.h:353

References _meanD.

Referenced by setNeiGeneticDistanceRecorders().

+ Here is the caller graph for this function:

◆ getMeanTheta()

double TTNeutralGenesSH::getMeanTheta ( )
inline
532 {return _mean_theta;}
double _mean_theta
Definition: ttneutralgenes.h:330

References _mean_theta.

◆ getNbAllGlobal()

double TTNeutralGenesSH::getNbAllGlobal ( )
inline
493 {return _nb_all_global;}
double _nb_all_global
Definition: ttneutralgenes.h:338

References _nb_all_global.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getNbAllLocal()

double TTNeutralGenesSH::getNbAllLocal ( )
inline
492 {return _nb_all_local;}
double _nb_all_local
Definition: ttneutralgenes.h:338

References _nb_all_local.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getNeiGeneticDistance()

double TTNeutralGenesSH::getNeiGeneticDistance ( unsigned int  i)
inline
552  {
553  unsigned int scale = (unsigned int)pow( 10.0, (int)log10((float)_D->getNbCols()) + 1 );
554  return _D->get(i/scale,i%scale);
555  }

References _D, TMatrix::get(), and TMatrix::getNbCols().

Referenced by setNeiGeneticDistanceRecorders().

+ Here is the caller graph for this function:

◆ getSibCoaMeans()

double TTNeutralGenesSH::getSibCoaMeans ( unsigned int  i)
inline
543 {return _sib_coa[i];}
double _sib_coa[4]
Definition: ttneutralgenes.h:335

References _sib_coa.

◆ getSibProportions()

double TTNeutralGenesSH::getSibProportions ( unsigned int  i)
inline
542 {return _sib_prop[i];}
double _sib_prop[4]
Kinship classes proportions.
Definition: ttneutralgenes.h:334

References _sib_prop.

◆ getTheta_FF()

double TTNeutralGenesSH::getTheta_FF ( )
inline

Gives the mean within females coancestry coefficient.

535 {return Theta_FF;}
double Theta_FF
Definition: ttneutralgenes.h:329

References Theta_FF.

◆ getTheta_FM()

double TTNeutralGenesSH::getTheta_FM ( )
inline

Gives the mean between males and females coancestry coefficient.

539 {return Theta_FM;}
double Theta_FM
Definition: ttneutralgenes.h:329

References Theta_FM.

◆ getTheta_MM()

double TTNeutralGenesSH::getTheta_MM ( )
inline

Gives the mean within males coancestry coefficient.

537 {return Theta_MM;}
double Theta_MM
Definition: ttneutralgenes.h:329

References Theta_MM.

◆ getWeightedFst()

double TTNeutralGenesSH::getWeightedFst ( )
inline

Returns the weighted Fst using Weir & Hill (2002) method.

This Fst is set by a previous call to setFstMatrix().

441 {return _fst_WH;}
double _fst_WH
Weir & Hill (2002) F-stat estimates.
Definition: ttneutralgenes.h:341

References _fst_WH.

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ init()

void TTNeutralGenesSH::init ( )
virtual

Reimplemented from StatHandlerBase.

2065 {
2067 
2069 
2070  // For diallelic bitstring, defer DataTable allocation.
2071  // setFstat_bitstring() computes F-stats in streaming mode without DataTables.
2072  // Other stat methods (fstat2, fstWC, etc.) will trigger lazy allocation if needed.
2075 }
virtual void init()
Definition: stathandler.cc:38
unsigned int get_allele_num()
Definition: ttneutralgenes.h:200
void allocateTables(unsigned int loci, unsigned int all)
Definition: stats_fstat.cc:44

References _is_diallelic_bitstring, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, allocateTables(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), and StatHandlerBase::init().

◆ setAdltNeiGeneticDistance()

void TTNeutralGenesSH::setAdltNeiGeneticDistance ( )
inline
void setNeiGeneticDistance(age_t AGE)
Definition: stats_fstat.cc:1458

References ADULTS, and setNeiGeneticDistance().

Referenced by setNeiGeneticDistanceRecorders().

+ Here is the caller graph for this function:

◆ setAdultAlleleFreq()

void TTNeutralGenesSH::setAdultAlleleFreq ( )
inline
void setAlleleTables(age_t AGE)
Definition: stats_fstat.cc:75

References ADULTS, and setAlleleTables().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ setAdultHeterozygosity()

void TTNeutralGenesSH::setAdultHeterozygosity ( )
inline
void setHeterozygosity(age_t AGE)
Definition: stats_fstat.cc:252

References ADULTS, and setHeterozygosity().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ setAdults_Theta()

void TTNeutralGenesSH::setAdults_Theta ( )
202 {
203  unsigned int Fsize,Msize,i,j,k, FFsize, MMsize, FMsize;
204  unsigned int patchNbr = this->_pop->getPatchNbr();
205  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
206  Patch *P1;
207  double mean = 0, grand_mean = 0;
208 
209  Theta_FF = 0;
210  Theta_MM = 0;
211  Theta_FM = 0;
212 
213  _mean_theta = 0;
214 
215  for(i = 0; i < patchNbr; ++i) {
216 
217  P1 = _pop->getPatch(i);
218  Fsize = P1->size(FEM, ADLTx);
219  Msize = P1->size(MAL, ADLTx);
220 
221  FFsize = Fsize*(Fsize-1)/2;
222  MMsize = Msize*(Msize-1)/2;
223  FMsize = Fsize*Msize;
224 
225  grand_mean = 0;
226 
227  if(Fsize != 0 || Msize != 0) {
228 
229  if(Fsize != 0) {
230  mean = 0;
231  for(j = 0; j < Fsize-1;++j)
232  for(k = j+1; k < Fsize;++k)
233  mean += Coancestry(P1->get(FEM, ADLTx, j)->getTrait(_SHLinkedTraitIndex),
235  nb_locus);
236  Theta_FF += mean/FFsize;
237  grand_mean += mean;
238  }
239 
240  if(Msize != 0) {
241  mean = 0;
242  for(j = 0; j < Msize-1;++j)
243  for(k = j+1; k < Msize;++k)
244  mean += Coancestry(P1->get(MAL, ADLTx, j)->getTrait(_SHLinkedTraitIndex),
246  nb_locus);
247  Theta_MM += mean/MMsize;
248  grand_mean += mean;
249  }
250 
251 
252  if(Fsize != 0 && Msize != 0) {
253  mean = 0;
254  for(j = 0; j < Fsize;++j)
255  for(k = 0; k < Msize;++k)
256  mean += Coancestry(P1->get(FEM, ADLTx, j)->getTrait(_SHLinkedTraitIndex),
258  nb_locus);
259  Theta_FM += mean/FMsize;
260  grand_mean += mean;
261  }
262  _mean_theta += grand_mean / (FFsize + MMsize + FMsize);
263  }
264  }
265 
266  _mean_theta /= patchNbr;
267  Theta_FF /= patchNbr;
268  Theta_MM /= patchNbr;
269  Theta_FM /= patchNbr;
270 }
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
double Coancestry(const TTrait *ind1, const TTrait *ind2, unsigned int nb_locus)
Gives the coancestry (probability of identity by state) of two gene sequences.
Definition: stats_coa.cc:42

References ADLTx, FEM, Patch::get(), Individual::getTrait(), MAL, and Patch::size().

◆ setAdultsCoaBetween()

void TTNeutralGenesSH::setAdultsCoaBetween ( )
inline
519 {setCoaMatrix(ADLTx, 2);}
void setCoaMatrix(age_idx age_pos, unsigned char dim)
Computes the within and between patches coancestry coefficients.
Definition: stats_coa.cc:57

References ADLTx, and setCoaMatrix().

◆ setAdultsCoaMatrix()

void TTNeutralGenesSH::setAdultsCoaMatrix ( )
inline
515 {setCoaMatrix(ADLTx, 3);}

References ADLTx, and setCoaMatrix().

◆ setAdultsCoaWithin()

void TTNeutralGenesSH::setAdultsCoaWithin ( )
inline
517 {setCoaMatrix(ADLTx, 1);}

References ADLTx, and setCoaMatrix().

◆ setAdultsFstat()

void TTNeutralGenesSH::setAdultsFstat ( )
inline
460 {setFstat(ADULTS);}
void setFstat(age_t AGE)
Computes the F-statistics following Nei & Chesser (1983).
Definition: stats_fstat.cc:281

References ADULTS, and setFstat().

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstatWeirCockerham()

void TTNeutralGenesSH::setAdultsFstatWeirCockerham ( )
inline
void setFstatWeirCockerham(age_t AGE)
Computes the Weir & Cockerham (1984) Fstat values (Theta, F, and f).
Definition: stats_fstat.cc:975

References ADULTS, and setFstatWeirCockerham().

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstBetween()

void TTNeutralGenesSH::setAdultsFstBetween ( )
inline
435 {setFstMatrix(ADULTS, 2);}
void setFstMatrix(age_t AGE, unsigned char dim)
Computes the weighted within and between patch Fst's as well as the overall Fst (Theta).
Definition: stats_fstat.cc:869

References ADULTS, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstMatrix()

void TTNeutralGenesSH::setAdultsFstMatrix ( )
inline
433 {setFstMatrix(ADULTS, 3);}

References ADULTS, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstWithin()

void TTNeutralGenesSH::setAdultsFstWithin ( )
inline
434 {setFstMatrix(ADULTS, 1);}

References ADULTS, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setAlleleTables()

void TTNeutralGenesSH::setAlleleTables ( age_t  AGE)
76 {
77 
78  if(_table_set_age == AGE
81  return;
82 
83  unsigned int nb_locus = _SHLinkedTrait->get_locus_num(), nb_allele = _SHLinkedTrait->get_allele_num();
84  unsigned int patch_size, patchNbr = _pop->getPatchNbr();
85  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
86  Patch* crnt_patch;
87  TTrait* trait;
88 
89  //check if the population size has changed:
90  if(_alleleCountTable.getNumGroups() != patchNbr)
92 
94 
96 
97  unsigned int* count1 = new unsigned int[nb_locus]();
98 
99  for(unsigned int k = 0; k < patchNbr; ++k) {
100 
101  crnt_patch = _pop->getPatch(k);
102  memset(count1, 0, nb_locus * sizeof(unsigned int));
103 
104  for (int sx = 0; sx < 2; ++sx) {
105 
106  for(unsigned int i = 0, size = crnt_patch->size(sex_t(sx), age_pos); i < size; ++i) {
107 
108  const TTNeutralGenes_bitstring* bs = static_cast<const TTNeutralGenes_bitstring*>(
109  crnt_patch->get(sex_t(sx), age_pos, i)->getTrait(_SHLinkedTraitIndex));
110 
111  for (int chr = 0; chr < 2; ++chr) {
112  const bitstring& seq = bs->get_bit_sequence(chr);
113  size_t nwords = seq.nb_words();
114  for (size_t w = 0; w < nwords; ++w) {
115  bitstring::_ul word = *seq.getword_atIdx(w);
116  while (word) {
117  count1[w * BITS_PER_WORD + __builtin_ctzl(word)]++;
118  word &= word - 1;
119  }
120  }
121  }
122  }
123  }
124 
125  for (unsigned int j = 0; j < nb_locus; ++j) {
126  _alleleCountTable.set(k, j, 1, count1[j]);
127  _alleleCountTable.set(k, j, 0,
128  crnt_patch->size(age_pos) * 2 - count1[j]);
129  }
130  }
131 
132  delete[] count1;
133 
134  } else {
135 
136  //counting the copies of each allele present in each patch:
137  for(unsigned int k = 0; k < patchNbr; ++k) {
138 
139  crnt_patch = _pop->getPatch(k);
140 
141  for (int sx = 0; sx < 2; ++sx) {
142 
143  for(unsigned int i = 0, size = crnt_patch->size(sex_t(sx), age_pos); i < size; ++i) {
144 
145  trait = crnt_patch->get(sex_t(sx), age_pos, i)->getTrait(_SHLinkedTraitIndex);
146 
147  for (unsigned int j = 0; j < nb_locus; ++j)
148  _alleleCountTable.increment(k, j, trait->get_allele(j, 0));
149 
150  for (unsigned int j = 0; j < nb_locus; ++j)
151  _alleleCountTable.increment(k, j, trait->get_allele(j, 1));
152 
153  }
154  }
155  }
156  }
157 
158  //allelic frequencies:
159  for (unsigned int i = 0; i < patchNbr; ++i) {
160 
161  patch_size = _pop->getPatch(i)->size(age_pos) * 2;
162 
163  if (patch_size) {
164 
165  for (unsigned int l = 0; l < nb_locus; ++l)
166  for (unsigned int u = 0; u < nb_allele; ++u)
167  _alleleFreqTable.set(i, l, u, (double)_alleleCountTable.get(i, l, u) / (double)patch_size);
168 
169  } else {
170  for (unsigned int l = 0; l < nb_locus; ++l)
171  for (unsigned int u = 0; u < nb_allele; ++u)
172  _alleleFreqTable.set(i, l, u, 0 );
173  }
174  }
175 
176  //population-wide allelic frequencies:
177  unsigned int tot_size = _pop->size(AGE) * 2;
178 
180 
181  for(unsigned int i = 0; i < patchNbr; i++)
182  for (unsigned int l = 0; l < nb_locus; ++l)
183  for (unsigned int u = 0; u < nb_allele; ++u)
185 
186  for (unsigned int l = 0; l < nb_locus; ++l)
187  for (unsigned int u = 0; u < nb_allele; ++u)
188  _globalAlleleFreq.divide(l, u, tot_size);
189 
190  _table_set_age = AGE;
191 
193 
195 }
#define BITS_PER_WORD
Definition: bitstring.h:40
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:231
void init(T val)
Sets all elements of the table to value 'val'.
Definition: datatable.h:255
void increment(unsigned int group, unsigned int Class, unsigned int elmnt)
Increments 'elmnt' of the class 'Class' in the group 'group' by one.
Definition: datatable.h:235
unsigned int getCurrentReplicate()
Definition: metapop.h:294
unsigned int getCurrentGeneration()
Definition: metapop.h:295
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:154
void divide(unsigned int i, unsigned int j, double value)
Divide an element of the matrix by a value.
Definition: tmatrix.h:315
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:255
TTNeutralGenes_bitstring : diallelic neutral loci encoded as bitstrings.
Definition: ttneutralgenes_bitstring.h:39
const bitstring & get_bit_sequence(bool chromosome) const
Definition: ttneutralgenes_bitstring.h:51
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
unsigned long _ul
Definition: bitstring.h:60
_ul * getword_atIdx(size_t index) const
Definition: bitstring.h:158
size_t nb_words() const
Definition: bitstring.h:163
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35

References _alleleCountTable, _alleleFreqTable, _globalAlleleFreq, _is_diallelic_bitstring, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, _table_set_age, _table_set_gen, _table_set_repl, ADLTx, ADULTS, allocateTables(), TMatrix::assign(), BITS_PER_WORD, TMatrix::divide(), Patch::get(), DataTable< T >::get(), TTrait::get_allele(), TProtoNeutralGenes::get_allele_num(), TTNeutralGenes_bitstring::get_bit_sequence(), TProtoNeutralGenes::get_locus_num(), Metapop::getCurrentGeneration(), Metapop::getCurrentReplicate(), DataTable< T >::getNumGroups(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), bitstring::getword_atIdx(), DataTable< T >::increment(), DataTable< T >::init(), bitstring::nb_words(), OFFSx, TMatrix::plus(), DataTable< T >::set(), Metapop::size(), and Patch::size().

Referenced by setAdultAlleleFreq(), setFst_li(), setFstat(), setFstatWeirCockerham(), setFstatWeirCockerham_MS(), setFstMatrix(), setNeiGeneticDistance(), setOffspringAlleleFreq(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ setCoaMatrix()

void TTNeutralGenesSH::setCoaMatrix ( age_idx  age_pos,
unsigned char  dim 
)

Computes the within and between patches coancestry coefficients.

Parameters
age_posthe age class index
dimthe dimension of the matrix to fill:
  • 1 = the diagonal (i.e. the wihtin patch coancestries or theta's)
  • 2 = the upper half (i.e. the between patch coancestries or alpha's)
  • 3 = both
58 {
59  unsigned int Fsize,Msize,tot_size,size_i,size_l, wt;
60  unsigned int nb_coeff = 0;
61  unsigned int i, j, k, l;
62  unsigned int patchNbr = this->_pop->getPatchNbr();
63  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
64  Patch *P1, *P2;
65 
66  if(_coa_matrix == NULL)
67 
68  _coa_matrix = new TMatrix(patchNbr, patchNbr);
69 
70  else if( _coa_matrix->length() != patchNbr * patchNbr)
71 
72  _coa_matrix->reset(patchNbr, patchNbr);
73 
74  _coa_matrix->assign(0);
75 
76  if(dim & 1) {
77 
78  _mean_theta = 0;
79 
80  wt = 0;
81 
82  //first fill the diagonale: within deme coancestry (theta)
83  for(i = 0; i < patchNbr; ++i) {
84 
85  P1 = _pop->getPatch(i);
86  Fsize = P1->size(FEM, age_pos);
87  Msize = P1->size(MAL, age_pos);
88 
89  tot_size = Fsize + Msize;
90 
91  if(tot_size != 0) {
92 
93  //fem-fem coa
94  for(j = 0; j < Fsize; ++j)
95  for(k = j+1; k < Fsize; ++k)
96  _coa_matrix->plus(i, i, Coancestry(P1->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex),
97  P1->get(FEM, age_pos, k)->getTrait(_SHLinkedTraitIndex),
98  nb_locus));
99  //mal-mal coa
100  for(j = 0; j < Msize; ++j)
101  for(k = j+1; k < Msize; ++k)
102  _coa_matrix->plus(i, i, Coancestry(P1->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex),
103  P1->get(MAL, age_pos, k)->getTrait(_SHLinkedTraitIndex),
104  nb_locus));
105  //fem-mal coa
106  for(j = 0; j < Fsize; ++j)
107  for(k = 0; k < Msize; ++k)
108  _coa_matrix->plus(i, i, Coancestry(P1->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex),
109  P1->get(MAL, age_pos, k)->getTrait(_SHLinkedTraitIndex),
110  nb_locus));
111 
112  _coa_matrix->divide(i, i, tot_size*(tot_size -1)/2.0);
113  }//end if
114 
115  _mean_theta += tot_size * _coa_matrix->get(i, i);
116 
117  wt += tot_size;
118 
119  }//end for patchNbr
120 
121  //weighted average:
122  _mean_theta /= wt;
123 
124  } //end if diag
125 
126  if(dim & 2) {
127  //fill the first upper half of the matrix: between deme coancestry (alpha)
128 
129  _mean_alpha = 0;
130 
131  wt = 0;
132 
133  for(i = 0; i < patchNbr-1; ++i) {
134 
135  P1 = _pop->getPatch(i);
136 
137  for(l = i+1; l < patchNbr; ++l) {
138 
139  P2 = _pop->getPatch(l);
140 
141  tot_size = P1->size(age_pos) * P2->size(age_pos);
142 
143  if(tot_size != 0) {
144  //females i vs. females l
145  size_i = P1->size(FEM, age_pos);
146  size_l = P2->size(FEM, age_pos);
147  nb_coeff = size_i * size_l;
148 
149  for(j = 0; j < size_i; ++j)
150  for(k = 0; k < size_l; ++k)
151  _coa_matrix->plus(i, l, Coancestry(P1->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex),
152  P2->get(FEM, age_pos, k)->getTrait(_SHLinkedTraitIndex),
153  nb_locus));
154  //females i vs. males l
155  size_l = P2->size(MAL, age_pos);
156  nb_coeff += size_i * size_l;
157 
158  for(j = 0; j < size_i; ++j)
159  for(k = 0; k < size_l; ++k)
160  _coa_matrix->plus(i, l, Coancestry(P1->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex),
161  P2->get(MAL, age_pos, k)->getTrait(_SHLinkedTraitIndex),
162  nb_locus));
163  //males i vs. males l
164  size_i = P1->size(MAL, age_pos);
165  size_l = P2->size(MAL, age_pos);
166  nb_coeff += size_i * size_l;
167 
168  for(j = 0; j < size_i; ++j)
169  for(k = 0; k < size_l; ++k)
170  _coa_matrix->plus(i, l, Coancestry(P1->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex),
171  P2->get(MAL, age_pos, k)->getTrait(_SHLinkedTraitIndex),
172  nb_locus));
173  //males i vs. females l
174  size_l = P2->size(FEM, age_pos);
175  nb_coeff += size_i * size_l;
176 
177  for(j = 0; j < size_i; ++j)
178  for(k = 0; k < size_l; ++k)
179  _coa_matrix->plus(i, l, Coancestry(P1->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex),
180  P2->get(FEM, age_pos, k)->getTrait(_SHLinkedTraitIndex),
181  nb_locus));
182  _coa_matrix->divide(i, l, nb_coeff);
183  }//endif
184 
185  _mean_alpha += tot_size * _coa_matrix->get(i, l);
186 
187  wt += tot_size;
188 
189  }//end for P2
190  }//end for P1
191 
192  //weighted average:
193  _mean_alpha /= wt;
194 
195  }//end if upper half
196 
197 }
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:217

References FEM, Patch::get(), Individual::getTrait(), MAL, and Patch::size().

Referenced by setAdultsCoaBetween(), setAdultsCoaMatrix(), setAdultsCoaWithin(), setOffsprgCoaBetween(), setOffsprgCoaMatrix(), and setOffsprgCoaWithin().

+ Here is the caller graph for this function:

◆ setCoaMatrixRecorders()

void TTNeutralGenesSH::setCoaMatrixRecorders ( age_t  AGE,
unsigned char  dim 
)

◆ setDxyRecorders()

void TTNeutralGenesSH::setDxyRecorders ( age_t  AGE,
bool  patchwise 
)
2576 {
2577  string prefix = (AGE == OFFSPRG ? "off." : "adlt.");
2578  age_idx age = (AGE == OFFSPRG ? OFFSx : ADLTx );
2579  string name = "Sequence divergence - Dxy";
2580  string sub_name = "Dxy";
2581 
2582 
2583  if (!patchwise) {
2584 
2585  add(name, prefix + sub_name, AGE, (unsigned int)age, 0, 0, &TTNeutralGenesSH::getDxy, 0, 0);
2586 
2587  } else {
2588 
2589  for (unsigned int p1 = 0; p1 < _pop->getPatchNbr(); ++p1) {
2590  for (unsigned int p2 = p1 + 1; p2 < _pop->getPatchNbr(); ++p2) {
2591  add(name, prefix + sub_name + ".p" + tstring::int2str(p1+1) + "p" + tstring::int2str(p2+1),
2592  AGE, p1, p2,
2595  0);
2596  }
2597  }
2598 
2599  }
2600 }
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
double getDxyAdultPerPatch(unsigned int patch1, unsigned patch2)
Definition: ttneutralgenes.h:562
double getDxy(unsigned int age_class)
Definition: stats_fstat.cc:1539
double getDxyOffspringPerPatch(unsigned int patch1, unsigned patch2)
Definition: ttneutralgenes.h:561
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:94

References StatHandlerBase::_pop, StatHandler< SH >::add(), ADLTx, getDxy(), getDxyAdultPerPatch(), getDxyOffspringPerPatch(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, and OFFSx.

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setFreqRecorders()

void TTNeutralGenesSH::setFreqRecorders ( age_t  AGE)
2390 {
2391  string prefix = (AGE == OFFSPRG ? "off." : "adlt.");
2392 
2393  void (TTNeutralGenesSH::* setter) () = (AGE == ADULTS ? &TTNeutralGenesSH::setAdultAlleleFreq :
2395 
2396  unsigned int nb_allele = _SHLinkedTrait->get_allele_num();
2397  unsigned int nb_locus = _SHLinkedTrait->get_locus_num();
2398 
2399  for (unsigned int l = 0; l < nb_locus; ++l) {
2400  for (unsigned int u = 0; u < nb_allele-1; ++u) {
2401  add("", prefix + "ntrl.l" + tstring::int2str(l+1) + ".a" + tstring::int2str(u+1), AGE, l, u,
2402  0, 0, &TTNeutralGenesSH::getGlobalAlleleFreq, setter);
2403  }
2404  }
2405 
2406  setter = (AGE == ADULTS ? &TTNeutralGenesSH::setAdultHeterozygosity :
2408 
2409  for (unsigned int l = 0; l < nb_locus; ++l) {
2410  add("", prefix + "ntrl.l" + tstring::int2str(l+1) + ".Het", AGE, l, 0, 0,
2412  // add("", prefix + "ntrl.l" + tstring::int2str(l) + ".Hom", AGE, l, 0, 0,
2413  // &TTNeutralGenesSH::getHomozygosity, 0, 0);
2414  }
2415 
2416 }
The stat handler for neutral markers.
Definition: ttneutralgenes.h:320
void setAdultHeterozygosity()
Definition: ttneutralgenes.h:392
double getGlobalAlleleFreq(unsigned int loc, unsigned int all)
Definition: ttneutralgenes.h:395
double getHeterozygosity(unsigned int loc)
Definition: ttneutralgenes.h:399
void setAdultAlleleFreq()
Definition: ttneutralgenes.h:389
void setOffspringHeterozygosity()
Definition: ttneutralgenes.h:393
void setOffspringAlleleFreq()
Definition: ttneutralgenes.h:390

References TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, StatHandler< SH >::add(), ADULTS, TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), getGlobalAlleleFreq(), getHeterozygosity(), tstring::int2str(), OFFSPRG, setAdultAlleleFreq(), setAdultHeterozygosity(), setOffspringAlleleFreq(), and setOffspringHeterozygosity().

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setFreqRecordersPerPatch()

void TTNeutralGenesSH::setFreqRecordersPerPatch ( age_t  AGE)

◆ setFst_li()

void TTNeutralGenesSH::setFst_li ( unsigned int  N,
unsigned int  L,
double **  array 
)

Computes the per-locus per-patch Fst values using Weir&Hill 2002 approach.

1387 {
1388  unsigned int patchNbr = this->_pop->getPatchNbr();
1389  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
1390  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
1391 
1392  assert(N == patchNbr);
1393  assert(L == nb_locus);
1394 
1396 
1397  double *pop_weights = new double[patchNbr];
1398  double *pop_sizes = new double[patchNbr];
1399  double *denominator = new double[nb_locus];
1400  double sum_weights = 0;
1401 
1402  double tot_size = _pop->size(ADULTS) * 2; //diploids!
1403 
1404  for(unsigned int i = 0; i < patchNbr; ++i) {
1405  pop_sizes[i] = _pop->size(ADULTS, i) * 2;
1406  pop_weights[i] = pop_sizes[i] - (pop_sizes[i] * pop_sizes[i] / tot_size); //n_ic in Weir & Hill 2002
1407  sum_weights += pop_weights[i];
1408  for(unsigned int j = 0; j < nb_locus; ++j)
1409  array[i][j] = nanf("NULL");
1410  }
1411 
1412  for(unsigned int l = 0; l < nb_locus; ++l)
1413  denominator[l] = 0;
1414 
1415  double p, pq, var;
1416 
1417  for (unsigned int i = 0; i < patchNbr; ++i) {
1418 
1419  if( !pop_sizes[i] ) continue;
1420 
1421  for (unsigned int l = 0; l < nb_locus; ++l) {
1422 
1423  array[i][l] = 0;
1424 
1425  for (unsigned int u = 0; u < nb_allele; ++u) {
1426 
1427  p = _alleleFreqTable.get(i, l, u); //p_liu
1428 
1429  pq = p * (1 - p);
1430 
1431  var = p - _globalAlleleFreq.get(l, u); //(p_liu - pbar_u)
1432 
1433  var *= var;
1434 
1435  array[i][l] += pq * pop_sizes[i] / (pop_sizes[i] -1);
1436 
1437  denominator[l] += pop_sizes[i] * var + pop_weights[i] * pq;
1438 
1439  } // end for allele
1440  }// end for locus
1441  }//end for pop
1442 
1443 
1444  for (unsigned int i = 0; i < patchNbr; ++i) {
1445  if( !pop_sizes[i] ) continue;
1446  for (unsigned int l = 0; l < nb_locus; ++l)
1447  array[i][l] = 1 - ( array[i][l] * sum_weights / denominator[l]);
1448  }
1449 
1450  delete [] pop_weights;
1451  delete [] pop_sizes;
1452  delete [] denominator;
1453 }

References _alleleFreqTable, _globalAlleleFreq, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, ADULTS, DataTable< T >::get(), TMatrix::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), setAlleleTables(), and Metapop::size().

Referenced by TTNeutralGenesFH::write_Fst_i().

+ Here is the caller graph for this function:

◆ setFstat()

void TTNeutralGenesSH::setFstat ( age_t  AGE)

Computes the F-statistics following Nei & Chesser (1983).

282 {
284  setFstat_bitstring(AGE);
285  return;
286  }
287 
288  double harmonic = 0, nbpatch = 0, nbind;
289  unsigned int patchNbr = _pop->getPatchNbr();
290  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
291 
292  //check if the population size has changed:
293  if(_alleleCountTable.getNumGroups() != patchNbr)
295 
296  setAlleleTables(AGE);
297 
298  setLociDivCounter(AGE);
299 
300  //harmonic mean of patch sizes:
301  for (unsigned int i = 0; i < patchNbr; ++i){
302 
303  nbind = _pop->size(AGE, i);
304  if(nbind != 0){
305  nbpatch++;
306  harmonic += 1.0/nbind;
307  }
308  }
309 
310  harmonic = nbpatch / harmonic;
311 
312  _ho = setHo(age_pos);
313  _hs = setHs(age_pos);
314  _ht = setHt(age_pos);
315  //Nei's corrections:
316  _hsnei = (nbpatch != 0 ? harmonic/(harmonic-1.0)*(_hs-(_ho/(2.0*harmonic))) : nanf("NULL") );
317  _htnei = (nbpatch != 0 ? _ht + (_hsnei/(harmonic*nbpatch))
318  -(_ho/(2.0*harmonic*nbpatch)) : nanf("NULL") );
319 
320  _fis = ( _hsnei ? 1.0-(_ho/_hsnei) : nanf("NULL") );
321  _fit = ( _htnei ? 1.0-(_ho/_htnei) : nanf("NULL") );
322  _fst = ( _htnei ? 1.0-(_hsnei/_htnei) : nanf("NULL") );
323 }
double setHo(age_idx age_pos)
Definition: stats_fstat.cc:534
double setHt(age_idx age_pos)
Definition: stats_fstat.cc:639
void setLociDivCounter(age_t AGE)
Sets the allelic diversity counters.
Definition: stats_fstat.cc:466
void setFstat_bitstring(age_t AGE)
Streaming F-stat computation for diallelic bitstring traits.
Definition: stats_fstat.cc:327
double setHs(age_idx age_pos)
Definition: stats_fstat.cc:594

References _alleleCountTable, _fis, _fit, _fst, _ho, _hs, _hsnei, _ht, _htnei, _is_diallelic_bitstring, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, ADLTx, ADULTS, allocateTables(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), DataTable< T >::getNumGroups(), Metapop::getPatchNbr(), OFFSx, setAlleleTables(), setFstat_bitstring(), setHo(), setHs(), setHt(), setLociDivCounter(), and Metapop::size().

Referenced by setAdultsFstat(), and setOffsprgFstat().

+ Here is the caller graph for this function:

◆ setFstat_bitstring()

void TTNeutralGenesSH::setFstat_bitstring ( age_t  AGE)

Streaming F-stat computation for diallelic bitstring traits.

Processes loci in word-sized chunks (64 loci) to avoid allocating per-patch x per-locus DataTables.

328 {
329  unsigned int patchNbr = _pop->getPatchNbr();
330  unsigned int nloc = _SHLinkedTrait->get_locus_num();
331  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
332 
333  // harmonic mean of non-empty patch sizes
334  double harmonic = 0, nbpatch = 0;
335  unsigned int* patch_2N = new unsigned int[patchNbr];
336 
337  for (unsigned int i = 0; i < patchNbr; ++i) {
338  unsigned int psize = _pop->size(AGE, i);
339  patch_2N[i] = psize * 2;
340  if (psize != 0) {
341  nbpatch++;
342  harmonic += 1.0 / psize;
343  }
344  }
345  harmonic = (nbpatch > 0) ? nbpatch / harmonic : 0;
346 
347  unsigned int total_2N = _pop->size(AGE) * 2;
348 
349  // Ho: use existing bitstring-optimized method (no DataTables needed)
350  _ho = setHo(age_pos);
351 
352  // Streaming computation of Hs, Ht, and loci diversity counters.
353  // Process BITS_PER_WORD loci at a time to avoid per-patch x per-locus DataTables.
354  size_t nwords = BITSET_WORDS(nloc);
355 
356  double hs_sum = 0, ht_sum = 0;
357  unsigned int nb_all_local_sum = 0;
358  unsigned int fix_loc_local_count = 0, fix_loc_global_count = 0;
359  bool pop_has_allele1, pop_has_allele0;
360  double nb_all_global_sum = 0;
361 
362  // per-patch allele-1 count for each bit in current word
363  unsigned int* count1 = new unsigned int[patchNbr * BITS_PER_WORD];
364 
365  for (size_t w = 0; w < nwords; ++w) {
366 
367  unsigned int loci_in_word = (unsigned int)BITS_PER_WORD;
368  if (w == nwords - 1 && nloc % BITS_PER_WORD != 0)
369  loci_in_word = nloc % BITS_PER_WORD;
370 
371  memset(count1, 0, patchNbr * BITS_PER_WORD * sizeof(unsigned int));
372 
373  // accumulate allele "1" counts per patch for this word
374  for (unsigned int k = 0; k < patchNbr; ++k) {
375  Patch* patch = _pop->getPatch(k);
376  unsigned int base = k * BITS_PER_WORD;
377 
378  for (int sx = 0; sx < 2; ++sx) {
379  for (unsigned int ind = 0, sz = patch->size(sex_t(sx), age_pos);
380  ind < sz; ++ind)
381  {
382  const TTNeutralGenes_bitstring* bs =
383  static_cast<const TTNeutralGenes_bitstring*>(
384  patch->get(sex_t(sx), age_pos, ind)->getTrait(_SHLinkedTraitIndex));
385 
386  for (int chr = 0; chr < 2; ++chr) {
387  bitstring::_ul word = *bs->get_bit_sequence(chr).getword_atIdx(w);
388  while (word) {
389  count1[base + __builtin_ctzl(word)]++;
390  word &= word - 1;
391  }
392  }
393  }
394  }
395  }
396 
397  // compute stats for each locus in this word
398  for (unsigned int bit = 0; bit < loci_in_word; ++bit) {
399 
400  unsigned int global_count1 = 0;
401  pop_has_allele1 = false;
402  pop_has_allele0 = false;
403 
404  for (unsigned int k = 0; k < patchNbr; ++k) {
405  if (patch_2N[k] == 0) continue;
406 
407  unsigned int c1 = count1[k * BITS_PER_WORD + bit];
408  unsigned int c0 = patch_2N[k] - c1;
409  global_count1 += c1;
410 
411  // Hs: within-patch expected heterozygosity 1 - p^2 - q^2 = 2pq
412  double p = (double)c1 / patch_2N[k];
413  hs_sum += 2.0 * p * (1.0 - p);
414 
415  // allelic diversity per patch: count alleles present
416  nb_all_local_sum += (c0 > 0) + (c1 > 0);
417 
418  // fixed loci per patch
419  fix_loc_local_count += (c1 == 0 || c1 == patch_2N[k]);
420 
421  pop_has_allele1 |= (c1 > 0);
422  pop_has_allele0 |= (c0 > 0);
423  }
424 
425  // Ht: total expected heterozygosity
426  if (total_2N > 0) {
427  double p_global = (double)global_count1 / total_2N;
428  ht_sum += 2.0 * p_global * (1.0 - p_global);
429  }
430 
431  // global allelic diversity
432  nb_all_global_sum += (pop_has_allele0 ? 1.0 : 0.0)
433  + (pop_has_allele1 ? 1.0 : 0.0);
434 
435  // fixed loci globally
436  fix_loc_global_count += (global_count1 == 0 || global_count1 == total_2N);
437  }
438  }
439 
440  delete[] count1;
441  delete[] patch_2N;
442 
443  _hs = (nbpatch > 0) ? hs_sum / (nloc * nbpatch) : 0;
444  _ht = (nloc > 0) ? ht_sum / nloc : 0;
445 
446  _nb_all_local = (nbpatch > 0) ? nb_all_local_sum / (double)(nloc * nbpatch)
447  : nanf("NULL");
448  _nb_all_global = nb_all_global_sum / nloc;
449  _fix_loc_local = (nbpatch > 0) ? (double)fix_loc_local_count / nbpatch : 0;
450  _fix_loc_global = fix_loc_global_count;
451 
452  // Nei's corrections
453  _hsnei = (nbpatch > 0 ? harmonic/(harmonic-1.0)*(_hs-(_ho/(2.0*harmonic)))
454  : nanf("NULL") );
455  _htnei = (nbpatch > 0 ? _ht + (_hsnei/(harmonic*nbpatch))
456  -(_ho/(2.0*harmonic*nbpatch))
457  : nanf("NULL") );
458 
459  _fis = ( _hsnei ? 1.0-(_ho/_hsnei) : nanf("NULL") );
460  _fit = ( _htnei ? 1.0-(_ho/_htnei) : nanf("NULL") );
461  _fst = ( _htnei ? 1.0-(_hsnei/_htnei) : nanf("NULL") );
462 }
#define BITSET_WORDS(__n)
Definition: bitstring.h:44

References _fis, _fit, _fix_loc_global, _fix_loc_local, _fst, _ho, _hs, _hsnei, _ht, _htnei, _nb_all_global, _nb_all_local, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, ADLTx, ADULTS, BITS_PER_WORD, BITSET_WORDS, Patch::get(), TTNeutralGenes_bitstring::get_bit_sequence(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), bitstring::getword_atIdx(), OFFSx, setHo(), Metapop::size(), and Patch::size().

Referenced by setFstat().

+ Here is the caller graph for this function:

◆ setFstatRecorders()

void TTNeutralGenesSH::setFstatRecorders ( age_t  AGE)
2422 {
2423  if(AGE & OFFSPRG) {
2424  add("Nbr of Alleles per Locus - local (offsprg)","off.allnbp",OFFSPRG,0,0,
2426  add("Nbr of Alleles per Locus - global (offsprg)","off.allnb",OFFSPRG,0,0,&TTNeutralGenesSH::getNbAllGlobal,0,0,0);
2427  add("Nbr of Fixed Loci per Patch (offsprg)","off.fixlocp",OFFSPRG,0,0,&TTNeutralGenesSH::getFixLocLocal,0,0,0);
2428  add("Nbr of Fixed Loci in the Pop (offsprg)","off.fixloc",OFFSPRG,0,0,&TTNeutralGenesSH::getFixLocGlobal,0,0,0);
2429  add("Ho (offsprg)","off.ho",OFFSPRG,0,0,&TTNeutralGenesSH::getHo,0,0,0);
2430  add("Hs-Nei (offsprg)","off.hsnei",OFFSPRG,0,0,&TTNeutralGenesSH::getHsnei,0,0,0);
2431  add("Ht-Nei (offsprg)","off.htnei",OFFSPRG,0,0,&TTNeutralGenesSH::getHtnei,0,0,0);
2432  add("Fis (offsprg)","off.fis",OFFSPRG,0,0,&TTNeutralGenesSH::getFis,0,0,0);
2433  add("Fst (offsprg)","off.fst",OFFSPRG,0,0,&TTNeutralGenesSH::getFst,0,0,0);
2434  add("Fit (offsprg)","off.fit",OFFSPRG,0,0,&TTNeutralGenesSH::getFit,0,0,0);
2435  }
2436 
2437  if(AGE & ADULTS) {
2438  add("Nbr of Alleles per Locus - local (adult)","adlt.allnbp",ADULTS,0,0,
2440  add("Nbr of Alleles per Locus - global (adult)","adlt.allnb",ADULTS,0,0,&TTNeutralGenesSH::getNbAllGlobal,0,0,0);
2441  add("Nbr of Fixed Loci per Patch (adult)","adlt.fixlocp",ADULTS,0,0,&TTNeutralGenesSH::getFixLocLocal,0,0,0);
2442  add("Nbr of Fixed Loci in the Pop (adult)","adlt.fixloc",ADULTS,0,0,&TTNeutralGenesSH::getFixLocGlobal,0,0,0);
2443  add("Ho (adult)","adlt.ho",ADULTS,0,0,&TTNeutralGenesSH::getHo,0,0,0);
2444  add("Hs-Nei (adult)","adlt.hsnei",ADULTS,0,0,&TTNeutralGenesSH::getHsnei,0,0,0);
2445  add("Ht-Nei (adult)","adlt.htnei",ADULTS,0,0,&TTNeutralGenesSH::getHtnei,0,0,0);
2446  add("Fis (adult)","adlt.fis",ADULTS,0,0,&TTNeutralGenesSH::getFis,0,0,0);
2447  add("Fst (adult)","adlt.fst",ADULTS,0,0,&TTNeutralGenesSH::getFst,0,0,0);
2448  add("Fit (adult)","adlt.fit",ADULTS,0,0,&TTNeutralGenesSH::getFit,0,0,0);
2449  }
2450 }
double getHsnei()
Definition: ttneutralgenes.h:464
double getFixLocGlobal()
Definition: ttneutralgenes.h:495
double getFit()
Definition: ttneutralgenes.h:471
void setAdultsFstat()
Definition: ttneutralgenes.h:460
double getNbAllGlobal()
Definition: ttneutralgenes.h:493
double getHo()
Definition: ttneutralgenes.h:466
double getFis()
Definition: ttneutralgenes.h:470
double getNbAllLocal()
Definition: ttneutralgenes.h:492
double getFixLocLocal()
Definition: ttneutralgenes.h:494
double getHtnei()
Definition: ttneutralgenes.h:465
void setOffsprgFstat()
Definition: ttneutralgenes.h:459
double getFst()
Definition: ttneutralgenes.h:469

References StatHandler< SH >::add(), ADULTS, getFis(), getFit(), getFixLocGlobal(), getFixLocLocal(), getFst(), getHo(), getHsnei(), getHtnei(), getNbAllGlobal(), getNbAllLocal(), OFFSPRG, setAdultsFstat(), and setOffsprgFstat().

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setFstatWCRecorders()

void TTNeutralGenesSH::setFstatWCRecorders ( age_t  AGE)
2478 {
2479  if(AGE & OFFSPRG) {
2480 
2481  add("Fis Weir & Cockerham","off.fis.WC",OFFSPRG,0,0,&TTNeutralGenesSH::getFisWC,0,0,&TTNeutralGenesSH::setOffspringFstatWeirCockerham);
2482  add("Fst Weir & Cockerham","off.fst.WC",OFFSPRG,0,0,&TTNeutralGenesSH::getFstWC,0,0,0);
2483  add("Fit Weir & Cockerham","off.fit.WC",OFFSPRG,0,0,&TTNeutralGenesSH::getFitWC,0,0,0);
2484  }
2485 
2486  if(AGE & ADULTS) {
2487 
2488  add("Fis Weir & Cockerham","adlt.fis.WC",ADULTS,0,0,&TTNeutralGenesSH::getFisWC,0,0,&TTNeutralGenesSH::setAdultsFstatWeirCockerham);
2489  add("Fst Weir & Cockerham","adlt.fst.WC",ADULTS,0,0,&TTNeutralGenesSH::getFstWC,0,0,0);
2490  add("Fit Weir & Cockerham","adlt.fit.WC",ADULTS,0,0,&TTNeutralGenesSH::getFitWC,0,0,0);
2491 
2492  }
2493 }
void setAdultsFstatWeirCockerham()
Definition: ttneutralgenes.h:486
void setOffspringFstatWeirCockerham()
Definition: ttneutralgenes.h:485
double getFitWC()
Definition: ttneutralgenes.h:489
double getFstWC()
Definition: ttneutralgenes.h:487
double getFisWC()
Definition: ttneutralgenes.h:488

References StatHandler< SH >::add(), ADULTS, getFisWC(), getFitWC(), getFstWC(), OFFSPRG, setAdultsFstatWeirCockerham(), and setOffspringFstatWeirCockerham().

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setFstatWeirCockerham()

void TTNeutralGenesSH::setFstatWeirCockerham ( age_t  AGE)

Computes the Weir & Cockerham (1984) Fstat values (Theta, F, and f).

976 {
979  return;
980  }
981  unsigned int patchNbr = this->_pop->getPatchNbr();
982  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
983  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
984  //age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
985 
986  setAlleleTables(AGE);
987  setHeteroTable(AGE);
988 
989  //init
990  double *pop_sizes = new double [patchNbr];
991  double tot_size, inv_ntot;
992  double sum_weights = 0;
993  double nbar, nc, inv_nbar;
994  unsigned int extantPs = 0;
995 
996  tot_size = _pop->size(AGE);
997 
998  for(unsigned int i = 0; i < patchNbr; i++) {
999  pop_sizes[i] = _pop->size(AGE, i);
1000  if(pop_sizes[i]) {
1001  extantPs++;
1002  sum_weights += (pop_sizes[i] * pop_sizes[i] / tot_size);
1003  }
1004  }
1005  nbar = tot_size/extantPs;
1006  nc = (tot_size - sum_weights)/(extantPs-1);
1007  inv_nbar = 1/(nbar - 1);
1008  inv_ntot = 1/tot_size;
1009 
1010  double var;
1011  double s2, pbar, hbar;
1012  double s2_denom = 1.0/((extantPs-1)*nbar),
1013  r = (double)(extantPs-1)/extantPs,
1014  hbar_factor=(2*nbar-1)/(4*nbar);
1015  double a = 0, b = 0, c = 0, x;
1016 
1017  for (unsigned int l = 0; l < nb_locus; ++l) {
1018 
1019  for (unsigned int u = 0; u < nb_allele; ++u) {
1020 
1021  s2 = pbar = hbar = 0;
1022 
1023  for (unsigned int i = 0; i < patchNbr; ++i) {
1024 
1025  var = _alleleFreqTable.get(i, l, u) - _globalAlleleFreq.get(l, u); //(p_liu - pbar_u)^2
1026 
1027  var *= var;
1028 
1029  s2 += var * pop_sizes[i];
1030 
1031  hbar += _heteroTable.get(i, l, u);
1032 
1033  }//end for pop
1034 
1035  s2 *= s2_denom;
1036  pbar = _globalAlleleFreq.get(l, u);
1037  hbar *= inv_ntot;
1038 
1039  x = pbar * (1 - pbar) - r * s2;
1040  a += s2 - inv_nbar*( x - 0.25 * hbar);
1041  b += x - hbar_factor * hbar;
1042  c += hbar;
1043 
1044 
1045  } // end for allele
1046 
1047  }// end for locus
1048 
1049  a *= nbar/nc;
1050  b *= nbar/(nbar - 1);
1051  c *= 0.5;
1052 
1053  _fst_WC = a / (a + b + c);
1054  _fit_WC = (a + b) / (a + b + c);
1055  _fis_WC = b / (b + c);
1056 
1057  delete [] pop_sizes;
1058 }
void setFstatWeirCockerham_bitstring(age_t AGE)
Streaming W&C Fstat for diallelic bitstring traits.
Definition: stats_fstat.cc:1062
void setHeteroTable(age_t AGE)
Definition: stats_fstat.cc:199

References _alleleFreqTable, _fis_WC, _fit_WC, _fst_WC, _globalAlleleFreq, _heteroTable, _is_diallelic_bitstring, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, DataTable< T >::get(), TMatrix::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), setAlleleTables(), setFstatWeirCockerham_bitstring(), setHeteroTable(), and Metapop::size().

Referenced by setAdultsFstatWeirCockerham(), and setOffspringFstatWeirCockerham().

+ Here is the caller graph for this function:

◆ setFstatWeirCockerham_bitstring()

void TTNeutralGenesSH::setFstatWeirCockerham_bitstring ( age_t  AGE)

Streaming W&C Fstat for diallelic bitstring traits.

1063 {
1064  unsigned int patchNbr = _pop->getPatchNbr();
1065  unsigned int nloc = _SHLinkedTrait->get_locus_num();
1066  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
1067 
1068  // patch sizes and W&C constants
1069  double *pop_sizes = new double[patchNbr];
1070  double tot_size = _pop->size(AGE);
1071  double inv_ntot = 1.0 / tot_size;
1072  double sum_weights = 0;
1073  unsigned int extantPs = 0;
1074 
1075  for (unsigned int i = 0; i < patchNbr; i++) {
1076  pop_sizes[i] = _pop->size(AGE, i);
1077  if (pop_sizes[i]) {
1078  extantPs++;
1079  sum_weights += (pop_sizes[i] * pop_sizes[i] / tot_size);
1080  }
1081  }
1082 
1083  double nbar = tot_size / extantPs;
1084  double nc = (tot_size - sum_weights) / (extantPs - 1);
1085  double inv_nbar = 1.0 / (nbar - 1);
1086  double s2_denom = 1.0 / ((extantPs - 1) * nbar);
1087  double r = (double)(extantPs - 1) / extantPs;
1088  double hbar_factor = (2 * nbar - 1) / (4 * nbar);
1089 
1090  double a = 0, b = 0, c = 0;
1091 
1092  size_t nwords = BITSET_WORDS(nloc);
1093 
1094  // per-patch allele-1 count and heterozygote count for each bit in current word
1095  unsigned int* count1 = new unsigned int[patchNbr * BITS_PER_WORD];
1096  unsigned int* het = new unsigned int[patchNbr * BITS_PER_WORD];
1097 
1098  for (size_t w = 0; w < nwords; ++w) {
1099 
1100  unsigned int loci_in_word = (unsigned int)BITS_PER_WORD;
1101  if (w == nwords - 1 && nloc % BITS_PER_WORD != 0)
1102  loci_in_word = nloc % BITS_PER_WORD;
1103 
1104  memset(count1, 0, patchNbr * BITS_PER_WORD * sizeof(unsigned int));
1105  memset(het, 0, patchNbr * BITS_PER_WORD * sizeof(unsigned int));
1106 
1107  for (unsigned int k = 0; k < patchNbr; ++k) {
1108  Patch* patch = _pop->getPatch(k);
1109  unsigned int base = k * BITS_PER_WORD;
1110 
1111  for (int sx = 0; sx < 2; ++sx) {
1112  for (unsigned int ind = 0, sz = patch->size(sex_t(sx), age_pos);
1113  ind < sz; ++ind)
1114  {
1115  const TTNeutralGenes_bitstring* bs =
1116  static_cast<const TTNeutralGenes_bitstring*>(
1117  patch->get(sex_t(sx), age_pos, ind)->getTrait(_SHLinkedTraitIndex));
1118 
1121 
1122  // allele 1 count from both chromosomes
1123  bitstring::_ul word = w0;
1124  while (word) { count1[base + __builtin_ctzl(word)]++; word &= word - 1; }
1125  word = w1;
1126  while (word) { count1[base + __builtin_ctzl(word)]++; word &= word - 1; }
1127 
1128  // heterozygote count from XOR
1129  word = w0 ^ w1;
1130  while (word) { het[base + __builtin_ctzl(word)]++; word &= word - 1; }
1131  }
1132  }
1133  }
1134 
1135  // W&C variance components for each locus in this word.
1136  // For 2 alleles the contributions from allele 0 and allele 1 are identical,
1137  // so computing for one allele gives the same Fst ratios (factor of 2 cancels).
1138  for (unsigned int bit = 0; bit < loci_in_word; ++bit) {
1139 
1140  unsigned int global_count1 = 0;
1141  double hbar = 0;
1142 
1143  for (unsigned int k = 0; k < patchNbr; ++k) {
1144  if (pop_sizes[k] == 0) continue;
1145  global_count1 += count1[k * BITS_PER_WORD + bit];
1146  hbar += het[k * BITS_PER_WORD + bit];
1147  }
1148 
1149  double pbar = (double)global_count1 / (2.0 * tot_size);
1150  hbar *= inv_ntot;
1151 
1152  double s2 = 0;
1153  for (unsigned int k = 0; k < patchNbr; ++k) {
1154  if (pop_sizes[k] == 0) continue;
1155  double p_i = (double)count1[k * BITS_PER_WORD + bit] / (2.0 * pop_sizes[k]);
1156  double var = p_i - pbar;
1157  s2 += var * var * pop_sizes[k];
1158  }
1159  s2 *= s2_denom;
1160 
1161  double x = pbar * (1 - pbar) - r * s2;
1162  a += s2 - inv_nbar * (x - 0.25 * hbar);
1163  b += x - hbar_factor * hbar;
1164  c += hbar;
1165  }
1166  }
1167 
1168  a *= nbar / nc;
1169  b *= nbar / (nbar - 1);
1170  c *= 0.5;
1171 
1172  _fst_WC = a / (a + b + c);
1173  _fit_WC = (a + b) / (a + b + c);
1174  _fis_WC = b / (b + c);
1175 
1176  delete[] count1;
1177  delete[] het;
1178  delete[] pop_sizes;
1179 }

References _fis_WC, _fit_WC, _fst_WC, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, ADLTx, ADULTS, BITS_PER_WORD, BITSET_WORDS, Patch::get(), TTNeutralGenes_bitstring::get_bit_sequence(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), bitstring::getword_atIdx(), OFFSx, Metapop::size(), and Patch::size().

Referenced by setFstatWeirCockerham().

+ Here is the caller graph for this function:

◆ setFstatWeirCockerham_MS()

void TTNeutralGenesSH::setFstatWeirCockerham_MS ( age_t  AGE)

Computes W&C F-stats using the Mean Squares approach, similar to the implementation in Hierfstat. This code gives the exact same results as the other version.

1184 {
1187  unsigned int patchNbr = this->_pop->getPatchNbr();
1188  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
1189  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
1190  //age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
1191 
1192  setAlleleTables(AGE);
1193  setHeteroTable(AGE);
1194 
1195  //init
1196  double *pop_sizes = new double [patchNbr];
1197  double tot_size;
1198  double sum_weights = 0;
1199  double nc;
1200  unsigned int extantPs = 0;
1201 
1202  tot_size = _pop->size(AGE);
1203 
1204  for(unsigned int i = 0; i < patchNbr; i++) {
1205  pop_sizes[i] = _pop->size(AGE, i);
1206  if(pop_sizes[i]) {
1207  extantPs++;
1208  sum_weights += (pop_sizes[i] * pop_sizes[i] / tot_size);
1209  }
1210  }
1211 
1212  nc = (tot_size - sum_weights)/(extantPs-1);
1213 
1214 // unsigned int np = extantPs;
1215  unsigned int npl = extantPs; //all loci typed in all patches
1216 
1217  //p = _alleleFreqTable
1218  //pb = _globalAlleleFreq
1219 
1220  unsigned int *alploc = new unsigned int [nb_locus];
1221 
1222  unsigned int **alploc_table = new unsigned int* [nb_locus];
1223 
1224  for(unsigned int i = 0; i < nb_locus; ++i)
1225  alploc_table[i] = new unsigned int[nb_allele];
1226 
1227  unsigned int tot_num_allele = 0;
1228 
1229  for(unsigned int l = 0; l < nb_locus; ++l){
1230 
1231  alploc[l] = 0;
1232 
1233  for(unsigned int cnt, a = 0; a < nb_allele; ++a) {
1234 
1235  cnt=0;
1236 
1237  for(unsigned int i = 0; i < patchNbr; i++) {
1238 
1239  cnt += _alleleCountTable.get(i,l,a);
1240 
1241  }
1242  alploc_table[l][a] = (cnt != 0);
1243  alploc[l] += (cnt != 0);
1244  }
1245 
1246  tot_num_allele += alploc[l];
1247  }
1248 
1249  //n, and nal are given by pop_sizes, same num ind typed at all loci in each patch
1250  //nc is the same for each locus
1251  //nt is given by tot_size, same tot num of ind typed for all loci
1252 
1253  //SSG: het/2 for each allele
1254  double *SSG = new double[tot_num_allele];
1255  double *SSP = new double[tot_num_allele];
1256  double *SSi = new double[tot_num_allele];
1257 
1258  unsigned int all_cntr = 0;
1259 
1260  double het, freq, var;
1261 
1262  for(unsigned int l = 0; l < nb_locus; ++l) {
1263 
1264  for(unsigned int a = 0; a < nb_allele & all_cntr < tot_num_allele; ++a) {
1265 
1266  if(alploc_table[l][a] == 0) continue; //do not consider alleles not present in the pop
1267 
1268  SSG[all_cntr] = 0;
1269  SSi[all_cntr] = 0;
1270  SSP[all_cntr] = 0;
1271 
1272  for(unsigned int p = 0; p < patchNbr; ++p){
1273 
1274  if(!_pop->size(AGE, p)) continue; //skip empty patches
1275 
1276  het = _heteroTable.get(p, l, a);
1277 
1278  freq = _alleleFreqTable.get(p, l, a);
1279 
1280  var = freq - _globalAlleleFreq.get(l, a); //(p_liu - pbar_u)^2
1281 
1282  var *= var;
1283 
1284  SSG[all_cntr] += het;
1285 
1286  SSi[all_cntr] += 2*pop_sizes[p]*freq*(1-freq) - het/2;
1287 
1288  SSP[all_cntr] += 2*pop_sizes[p]*var;
1289  }
1290 
1291  all_cntr++;
1292  }
1293 
1294  }
1295 
1296 
1297  assert(all_cntr == tot_num_allele);
1298 
1299  double *MSG = new double[tot_num_allele];
1300  double *MSP = new double[tot_num_allele];
1301  double *MSI = new double[tot_num_allele];
1302  double *sigw = new double[tot_num_allele];
1303  double *siga = new double[tot_num_allele];
1304  double *sigb = new double[tot_num_allele];
1305 
1306 // double *FST_pal = new double[tot_num_allele];
1307 // double *FIS_pal = new double[tot_num_allele];
1308 
1309  double SIGA = 0, SIGB = 0, SIGW = 0;
1310 
1311  for(unsigned int i = 0; i < tot_num_allele; ++i){
1312 
1313  MSG[i] = SSG[i] / (2 * tot_size);
1314  sigw[i] = MSG[i]; //wasted!
1315 
1316  MSP[i] = SSP[i] / (npl-1);
1317 
1318  MSI[i] = SSi[i]/ (tot_size - npl);
1319 
1320  sigb[i] = 0.5*(MSI[i] - MSG[i]);
1321 
1322  siga[i] = (MSP[i] - MSI[i])/(2*nc);
1323 
1324 // FST_pal[i] = siga[i]/(siga[i]+sigb[i]+sigw[i]);
1325 // FIS_pal[i] = sigb[i]/(sigb[i]+sigw[i]);
1326 
1327  SIGA += siga[i];
1328  SIGB += sigb[i];
1329  SIGW += sigw[i];
1330  }
1331 
1332  //per locus stats:
1333  if(_fst_WC_loc) delete [] _fst_WC_loc; _fst_WC_loc = new double [nb_locus];
1334  if(_fis_WC_loc) delete [] _fis_WC_loc; _fis_WC_loc = new double [nb_locus];
1335  if(_fit_WC_loc) delete [] _fit_WC_loc; _fit_WC_loc = new double [nb_locus];
1336 
1337  double lsiga, lsigb, lsigw;
1338 
1339 // cout<<" computing sigma per locus\n";
1340 
1341  for(unsigned int allcntr = 0, i = 0; i < nb_locus; ++i) {
1342 
1343  lsiga = lsigb = lsigw = 0;
1344 
1345  for(unsigned int l = 0; l < alploc[i]; ++l) {
1346 
1347  lsiga += siga[allcntr];
1348  lsigb += sigb[allcntr];
1349  lsigw += sigw[allcntr];
1350 
1351  allcntr++;
1352 
1353  }
1354 
1355  _fst_WC_loc[i] = lsiga /(lsiga + lsigb + lsigw);
1356  _fis_WC_loc[i] = lsigb /(lsigb + lsigw);
1357  _fit_WC_loc[i] = (lsiga +lsigb) /(lsiga + lsigb + lsigw);
1358 
1359  }
1360 
1361 
1362  // Total F-stats
1363  _fst_WC = SIGA / (SIGA + SIGB + SIGW);
1364  _fit_WC = (SIGA + SIGB) / (SIGA + SIGB + SIGW);
1365  _fis_WC = SIGB / (SIGB + SIGW);
1366 
1367  delete[]pop_sizes;
1368  delete[]alploc;
1369  for(unsigned int i = 0; i < nb_locus; ++i)
1370  delete[]alploc_table[i];
1371  delete[]alploc_table;
1372  delete[]SSG;
1373  delete[]SSi;
1374  delete[]SSP;
1375  delete[]MSG;
1376  delete[]MSI;
1377  delete[]MSP;
1378  delete[]sigw;
1379  delete[]siga;
1380  delete[]sigb;
1381 
1382 }

References _alleleCountTable, _alleleFreqTable, _fis_WC, _fis_WC_loc, _fit_WC, _fit_WC_loc, _fst_WC, _fst_WC_loc, _globalAlleleFreq, _heteroTable, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, DataTable< T >::get(), TMatrix::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), setAlleleTables(), setHeteroTable(), and Metapop::size().

◆ setFstMatrix()

void TTNeutralGenesSH::setFstMatrix ( age_t  AGE,
unsigned char  dim 
)

Computes the weighted within and between patch Fst's as well as the overall Fst (Theta).

The method used here is that of Weir & Hill 2002, Ann. Rev. Genet. 36:721-750. The weighting is done for samples (patches) of unequal sizes.

Parameters
AGEthe age class
dimthe dimension of the matrix to fill:
  • 1 = the diagonal (i.e. the wihtin patch Fst or theta_ii)
  • 2 = the upper half (i.e. the between patch Fst or theta_ii')
  • 3 = both
870 {
871  unsigned int patchNbr = this->_pop->getPatchNbr();
872  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
873  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
874 
875  setAlleleTables(AGE);
876 
877  if(_fst_matrix == NULL)
878 
879  _fst_matrix = new TMatrix(patchNbr, patchNbr);
880 
881  else if( _fst_matrix->length() != patchNbr * patchNbr)
882 
883  _fst_matrix->reset(patchNbr, patchNbr);
884 
885  _fst_matrix->assign(nanf("NULL"));
886 
887  //init
888  double *pop_weights = new double[patchNbr];
889  double *pop_sizes = new double[patchNbr];
890  double **numerator = new double*[patchNbr];
891  for(unsigned int i = 0; i < patchNbr; i++) numerator[i] = new double [patchNbr];
892  double tot_size;
893  double numerator_W = 0;
894  double denominator = 0;
895  double sum_weights = 0;
896 
897  tot_size = _pop->size(AGE) * 2;
898 
899  for(unsigned int i = 0; i < patchNbr; ++i) {
900  pop_sizes[i] = _pop->size(AGE, i) * 2;
901  pop_weights[i] = pop_sizes[i] - (pop_sizes[i] * pop_sizes[i] / tot_size); //n_ic in Weir & Hill 2002
902  sum_weights += pop_weights[i];
903  for(unsigned int j = 0; j < patchNbr; j++)
904  numerator[i][j] = 0;
905  }
906 
907  double p, pq, var, num;
908 
909  for (unsigned int i = 0; i < patchNbr; ++i) {
910 
911  if( !pop_sizes[i] ) continue;
912 
913  for (unsigned int l = 0; l < nb_locus; ++l) {
914 
915  for (unsigned int u = 0; u < nb_allele; ++u) {
916 
917  p = _alleleFreqTable.get(i, l, u); //p_liu
918 
919  pq = p * (1 - p);
920 
921  var = p - _globalAlleleFreq.get(l, u); //(p_liu - pbar_u)^2
922 
923  var *= var;
924 
925  num = pq * pop_sizes[i] / (pop_sizes[i] -1);
926 
927  numerator[i][i] += num;
928 
929  numerator_W += num * pop_sizes[i]; //see equ. 9, Weir & Hill 2002
930 
931  denominator += pop_sizes[i] * var + pop_weights[i] * pq; //common denominator
932 
933  } // end for allele
934  }// end for locus
935  }//end for pop
936 
937  for (unsigned int i = 0; i < patchNbr; ++i) {
938  if( !pop_sizes[i] ) continue;
939  _fst_matrix->set(i, i, 1 - (numerator[i][i] * sum_weights / denominator) );
940  }
941  _fst_WH = 1 - ((numerator_W * sum_weights) / (denominator * tot_size)); //equ. 9 Weir & Hill 2002
942 
943  //pairwise Fst:
944  if(dim & 2) {
945  double pi, pj;
946  for (unsigned int l = 0; l < nb_locus; ++l)
947  for (unsigned int u = 0; u < nb_allele; ++u)
948  for (unsigned int i = 0; i < patchNbr - 1; ++i) {
949  if( !pop_sizes[i] ) continue;
950  for (unsigned int j = i + 1; j < patchNbr; ++j) {
951  if( !pop_sizes[j] ) continue;
952  pi = _alleleFreqTable.get(i, l, u);
953  pj = _alleleFreqTable.get(j, l, u);
954  numerator[i][j] += pi * (1 - pj) + pj * (1 - pi); //equ. 7 of Weir & Hill 2002
955  }
956  }
957  for (unsigned int i = 0; i < patchNbr - 1; ++i){
958  if( !pop_sizes[i] ) continue;
959  for (unsigned int j = i + 1; j < patchNbr; ++j){
960  if( !pop_sizes[j] ) continue;
961  _fst_matrix->set(i, j, 1 - ( (numerator[i][j] * sum_weights) / (2 * denominator)) );
962  }
963  }
964  }
965 
966 
967  delete [] pop_weights;
968  delete [] pop_sizes;
969  for(unsigned int i = 0; i < patchNbr; i++) delete [] numerator[i];
970  delete [] numerator;
971 }
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102

References _alleleFreqTable, _fst_matrix, _fst_WH, _globalAlleleFreq, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TMatrix::assign(), DataTable< T >::get(), TMatrix::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), TMatrix::length(), TMatrix::reset(), TMatrix::set(), setAlleleTables(), and Metapop::size().

Referenced by setAdultsFstBetween(), setAdultsFstMatrix(), setAdultsFstWithin(), setOffsprgFstBetween(), setOffsprgFstMatrix(), and setOffsprgFstWithin().

+ Here is the caller graph for this function:

◆ setFstMatrixRecorders()

void TTNeutralGenesSH::setFstMatrixRecorders ( age_t  AGE,
unsigned char  dim 
)
2498 {
2499  std::ostringstream name, sub_name;
2500 
2501  void (TTNeutralGenesSH::* setter) () = (AGE == ADULTS ?
2508 
2509  const char *prefix = (AGE == ADULTS ? "adlt." : "off.");
2510 
2511  unsigned int nbpatch = _pop->getPatchNbr();
2512  unsigned int scale = (unsigned int)pow(10.0, (int)log10((float)nbpatch) + 1);
2513 
2514  name<<"Weir&Hill weighted Fst ("<<prefix<<")";
2515  sub_name<< prefix << "fst.WH";
2516  add(name.str(), sub_name.str(), AGE, 0, 0, &TTNeutralGenesSH::getWeightedFst, 0, 0, setter);
2517  name.str("");
2518  sub_name.str("");
2519 
2520  if(dim & 1) {
2521  for(unsigned int i = 0; i < nbpatch; ++i) {
2522  name<<"Weighted Fst "<<i+1<<"."<<i+1;
2523  sub_name<< prefix << "fst" << i+1 << "." << i+1;
2524  add(name.str(), sub_name.str(), AGE, i*scale + i, 0, 0, &TTNeutralGenesSH::getFst_ij, 0, 0);
2525  name.str("");
2526  sub_name.str("");
2527  }
2528  }
2529  if(dim & 2){
2530  for(unsigned int i = 0; i < nbpatch; ++i) {
2531  for(unsigned int j = i+1; j < nbpatch; ++j) {
2532  name<<"Weighted Fst "<<i+1<< "." <<j+1;
2533  sub_name<< prefix << "fst" << i+1 << "." << j+1;
2534  add(name.str(), sub_name.str(), AGE, i*scale + j, 0, 0, &TTNeutralGenesSH::getFst_ij, 0, 0);
2535  name.str("");
2536  sub_name.str("");
2537  }
2538  }
2539  }
2540 
2541 }
double getWeightedFst()
Returns the weighted Fst using Weir & Hill (2002) method.
Definition: ttneutralgenes.h:441
void setAdultsFstBetween()
Definition: ttneutralgenes.h:435
void setOffsprgFstBetween()
Definition: ttneutralgenes.h:438
void setAdultsFstMatrix()
Definition: ttneutralgenes.h:433
void setOffsprgFstWithin()
Definition: ttneutralgenes.h:437
double getFst_ij(unsigned int i)
Accessor to the Fst matrix as set by setFstMatrix().
Definition: ttneutralgenes.h:443
void setAdultsFstWithin()
Definition: ttneutralgenes.h:434
void setOffsprgFstMatrix()
Definition: ttneutralgenes.h:436

References StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, getFst_ij(), Metapop::getPatchNbr(), getWeightedFst(), setAdultsFstBetween(), setAdultsFstMatrix(), setAdultsFstWithin(), setOffsprgFstBetween(), setOffsprgFstMatrix(), and setOffsprgFstWithin().

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setHeteroTable()

void TTNeutralGenesSH::setHeteroTable ( age_t  AGE)
200 {
201  unsigned int patchNbr = this->_pop->getPatchNbr();
202  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
203  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
204  Patch* patch;
205  unsigned int isHetero, a0, a1;
206  TTrait* trait;
207  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
208 
209  unsigned int **sizes;
210 
211  sizes = new unsigned int * [patchNbr];
212 
213  for(unsigned int i = 0; i < patchNbr; ++i) {
214  sizes[i] = new unsigned int [nb_locus];
215  for(unsigned int j = 0; j < nb_locus; ++j)
216  sizes[i][j] = nb_allele;
217  }
218 
219  _heteroTable.update(patchNbr, nb_locus, sizes);
220  _heteroTable.init(0);
221 
222 
223  for (unsigned int i = 0; i < patchNbr; ++i) {
224 
225  patch = _pop->getPatch(i);
226 
227  if(!patch->size(age_pos)) continue;
228 
229  for (int sx = 0; sx < 2; ++sx) {
230 
231  for(unsigned int j = 0, size = patch->size(sex_t(sx), age_pos); j < size; ++j) {
232 
233  trait = patch->get(sex_t(sx), age_pos, j)->getTrait(_SHLinkedTraitIndex);
234 
235  for (unsigned int l = 0; l < nb_locus; ++l) {
236  a0 = trait->get_allele(l, 0);
237  a1 = trait->get_allele(l, 1);
238  isHetero = (a0 != a1);
239  _heteroTable.plus(i, l, a0, isHetero);
240  _heteroTable.plus(i, l, a1, isHetero);
241  }
242  }
243  }
244  }
245  for(unsigned int i = 0; i < patchNbr; ++i) delete [] sizes[i];
246  delete [] sizes;
247 
248 }
void plus(unsigned int group, unsigned int Class, unsigned int elmnt, T val)
Adds 'val' to 'elmnt' in the class 'Class' in the group 'group'.
Definition: datatable.h:239
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:153

References _heteroTable, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, ADLTx, ADULTS, Patch::get(), TTrait::get_allele(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), DataTable< T >::init(), OFFSx, DataTable< T >::plus(), Patch::size(), and DataTable< T >::update().

Referenced by setFstatWeirCockerham(), setFstatWeirCockerham_MS(), setHeterozygosity(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ setHeterozygosity()

void TTNeutralGenesSH::setHeterozygosity ( age_t  AGE)
253 {
254  unsigned int patchNbr = this->_pop->getPatchNbr();
255  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
256  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
257  Patch* patch;
258  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
259 
260  setHeteroTable(AGE);
261 
262  for (unsigned int i = 0, size; i < patchNbr; ++i) {
263 
264  patch = _pop->getPatch(i);
265  size = patch->size(age_pos);
266 
267  if(!size) continue;
268 
269  for (unsigned int l = 0; l < nb_locus; ++l) {
270  for (unsigned int u = 0; u < nb_allele; ++u) {
271  _heteroTable.divide(i, l , u, size);
272  }
273  }
274  }
275 
276 
277 }
void divide(unsigned int group, unsigned int Class, unsigned int elmnt, T val)
Subdivide 'elmnt' of the class 'Class' in the group 'group' by 'val'.
Definition: datatable.h:251

References _heteroTable, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, ADLTx, ADULTS, DataTable< T >::divide(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), OFFSx, setHeteroTable(), and Patch::size().

Referenced by setAdultHeterozygosity(), and setOffspringHeterozygosity().

+ Here is the caller graph for this function:

◆ setHo()

double TTNeutralGenesSH::setHo ( age_idx  age_pos)
535 {
536  unsigned int nloc = _SHLinkedTrait->get_locus_num(), nbpatch = _pop->getPatchNbr(), psize;
537  double indloc = 0, hetero = 0;
538  Patch* current_patch;
539 
541 
542  for (unsigned int i = 0; i < nbpatch; ++i) {
543  current_patch = _pop->getPatch(i);
544 
545  psize = current_patch->size(FEM, age_pos);
546  indloc += psize;
547  for(unsigned int j = 0; j < psize; ++j) {
548  const TTNeutralGenes_bitstring* bs = static_cast<const TTNeutralGenes_bitstring*>(
549  current_patch->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex));
550  hetero += bs->get_bit_sequence(0).count_xor(bs->get_bit_sequence(1));
551  }
552 
553  psize = current_patch->size(MAL, age_pos);
554  indloc += psize;
555  for(unsigned int j = 0; j < psize; ++j) {
556  const TTNeutralGenes_bitstring* bs = static_cast<const TTNeutralGenes_bitstring*>(
557  current_patch->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex));
558  hetero += bs->get_bit_sequence(0).count_xor(bs->get_bit_sequence(1));
559  }
560  }
561 
562  } else {
563 
564  TTrait* trait;
565 
566  for (unsigned int i = 0; i < nbpatch; ++i) {
567  current_patch = _pop->getPatch(i);
568  psize = current_patch->size(FEM, age_pos);
569  indloc += psize;
570  for(unsigned int j = 0; j < psize; ++j) {
571  trait = current_patch->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex);
572  for (unsigned int k = 0; k < nloc; ++k) hetero += (trait->get_allele(k, 0) != trait->get_allele(k, 1));
573  }
574  }
575  for (unsigned int i = 0; i < nbpatch; ++i) {
576  current_patch = _pop->getPatch(i);
577  psize = current_patch->size(MAL, age_pos);
578  indloc += psize;
579  for(unsigned int j = 0; j < psize; ++j) {
580  trait = current_patch->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex);
581  for (unsigned int k = 0; k < nloc; ++k) hetero += (trait->get_allele(k, 0) != trait->get_allele(k, 1));
582  }
583  }
584  }
585 
586  indloc *= nloc;
587 
588  return (indloc != 0 ? hetero/indloc : 0.0);
589 }
unsigned int count_xor(const bitstring &other) const
Fused XOR popcount: count set bits in (this XOR other).
Definition: bitstring.h:308

References _is_diallelic_bitstring, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, bitstring::count_xor(), FEM, Patch::get(), TTrait::get_allele(), TTNeutralGenes_bitstring::get_bit_sequence(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), MAL, and Patch::size().

Referenced by setFstat(), and setFstat_bitstring().

+ Here is the caller graph for this function:

◆ setHo2()

deque< double > TTNeutralGenesSH::setHo2 ( age_idx  age_pos)

New version of Nei & Chesser.

730 {
731  unsigned int nloc = _SHLinkedTrait->get_locus_num(), nbpatch = _pop->getPatchNbr();
732  unsigned int psize;
733  deque<double> hetero(nloc,0);
734  Patch* current_patch;
735 
737 
738  for (unsigned int i = 0; i < nbpatch; ++i) {
739  current_patch = _pop->getPatch(i);
740 
741  for (int sx = 0; sx < 2; ++sx) {
742  sex_t sex = (sx == 0) ? FEM : MAL;
743  for(unsigned int j = 0, size = current_patch->size(sex, age_pos); j < size; ++j) {
744  const TTNeutralGenes_bitstring* bs = static_cast<const TTNeutralGenes_bitstring*>(
745  current_patch->get(sex, age_pos, j)->getTrait(_SHLinkedTraitIndex));
746  const bitstring& s0 = bs->get_bit_sequence(0);
747  const bitstring& s1 = bs->get_bit_sequence(1);
748  size_t nwords = s0.nb_words();
749  for (size_t w = 0; w < nwords; ++w) {
750  bitstring::_ul xword = *s0.getword_atIdx(w) ^ *s1.getword_atIdx(w);
751  while (xword) {
752  hetero[w * BITS_PER_WORD + __builtin_ctzl(xword)]++;
753  xword &= xword - 1;
754  }
755  }
756  }
757  }
758  }
759 
760  } else {
761 
762  TTrait* trait;
763 
764  for (unsigned int i = 0; i < nbpatch; ++i) {
765  current_patch = _pop->getPatch(i);
766 
767  for(unsigned int j = 0, fsize = current_patch->size(FEM, age_pos); j < fsize; ++j) {
768  trait = current_patch->get(FEM, age_pos, j)->getTrait(_SHLinkedTraitIndex);
769  for (unsigned int k = 0; k < nloc; ++k)
770  hetero[k] += (trait->get_allele(k, 0) != trait->get_allele(k, 1));
771  }
772 
773  for(unsigned int j = 0, msize = current_patch->size(MAL, age_pos); j < msize; ++j) {
774  trait = current_patch->get(MAL, age_pos, j)->getTrait(_SHLinkedTraitIndex);
775  for (unsigned int k = 0; k < nloc; ++k)
776  hetero[k] += (trait->get_allele(k, 0) != trait->get_allele(k, 1));
777  }
778  }
779  }
780 
781  psize = _pop->size(age_pos);
782 
783  if(psize != 0)
784  for (unsigned int k = 0; k < nloc; ++k)
785  hetero[k] /= psize;
786 
787  return hetero;
788 }

References _is_diallelic_bitstring, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTraitIndex, BITS_PER_WORD, FEM, Patch::get(), TTrait::get_allele(), TTNeutralGenes_bitstring::get_bit_sequence(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), bitstring::getword_atIdx(), MAL, bitstring::nb_words(), Metapop::size(), and Patch::size().

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ setHs()

double TTNeutralGenesSH::setHs ( age_idx  age_pos)
595 {
596  unsigned int i, k, x, nb_patch=0;
597  double hs = 0;
598  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
599  unsigned int patchNbr = _pop->getPatchNbr();
600  deque<double>genehet(nbLoc,1);
601  deque<double>hspop(patchNbr,0);
602  double freq;
603  Patch* current_patch;
604 
605  //compute the expected heterozygosity for each patch and return average:
606  for (i = 0; i < patchNbr; ++i) {
607 
608  current_patch = _pop->getPatch(i);
609 
610  genehet.assign(nbLoc, 1);
611 
612  if(current_patch->size(age_pos) != 0) {
613 
614  nb_patch++;
615 
616  for (k = 0; k < nbLoc; ++k) {
617 
618  for (x = 0; x < nbAll; ++x) {
619 
620  freq = _alleleFreqTable.get(i, k, x);
621 
622  freq *= freq; //squared frequencies (expected _homozygosity)
623 
624  genehet[k] -= freq; //1 - sum of p2 = expected heterozygosity
625  }
626  //expected heterozygosity:
627  hspop[i] += genehet[k];
628  }
629  }//end_if size!=0
630 
631  hs += hspop[i];
632  }//end patch loop
633 
634  return (nb_patch !=0 ? hs/(nbLoc*nb_patch) : 0.0);
635 }
void assign(sex_t SEX, age_idx AGE, size_t n)
Assigns a new container of given size for the sex and age class passed, sets all values to NULL.
Definition: metapop.h:560

References _alleleFreqTable, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, Patch::assign(), DataTable< T >::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), and Patch::size().

Referenced by setFstat().

+ Here is the caller graph for this function:

◆ setHs2()

deque< double > TTNeutralGenesSH::setHs2 ( age_idx  age_pos)
794 {
795  unsigned int i, k, x, nb_patch = 0;
796  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
797  unsigned int patchNbr = _pop->getPatchNbr();
798  deque<double>genehet(nbLoc,1);
799  deque<double>hsloc(nbLoc,0);
800  double freq;
801  Patch* current_patch;
802 
803  for (i = 0; i < patchNbr; ++i) {
804  if(_pop->size(age_pos, i) != 0)
805  nb_patch++;
806  }
807 
808  //compute the expected heterozygosity for each patch and return average:
809  for (k = 0; k < nbLoc; ++k) {
810 
811  for (i = 0; i < patchNbr; ++i) {
812 
813  current_patch = _pop->getPatch(i);
814 
815  genehet[k] = 1;
816 
817  if(current_patch->size(age_pos) != 0) {
818 
819  for (x = 0; x < nbAll; ++x) {
820 
821  freq = _alleleFreqTable.get(i, k, x);
822 
823  freq *= freq; //squared frequencies (expected _homozygosity)
824 
825  genehet[k] -= freq; //1 - sum of p2 = expected heterozygosity
826  }
827 
828  }//end_if size!=0
829 
830  hsloc[k] += genehet[k];
831 
832  }//end patch loop
833 
834  if(nb_patch !=0) hsloc[k] /= nb_patch;
835 
836  }//end loci loop
837 
838  return hsloc;
839 }

References _alleleFreqTable, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, DataTable< T >::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatch(), Metapop::getPatchNbr(), Metapop::size(), and Patch::size().

◆ setHt()

double TTNeutralGenesSH::setHt ( age_idx  age_pos)
640 {
641  double ht = 0;
642  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
643  deque<double> genehet(nbLoc, 1);
644  double freq;
645 
646  //get global allele frequencies per locus
647  for (unsigned int l = 0; l < nbLoc; ++l) {
648  for (unsigned int u = 0; u < nbAll; ++u) {
649 
650  freq = _globalAlleleFreq.get(l, u);
651 
652  freq *= freq; //squared frequencies
653 
654  genehet[l] -= freq; //1 - sum of p2 = expected heterozygosity
655  }
656 
657  ht += genehet[l];
658  }
659 
660  return (ht/nbLoc);
661 }

References _globalAlleleFreq, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TMatrix::get(), TProtoNeutralGenes::get_allele_num(), and TProtoNeutralGenes::get_locus_num().

Referenced by setFstat().

+ Here is the caller graph for this function:

◆ setHt2()

deque< double > TTNeutralGenesSH::setHt2 ( age_idx  age_pos)
844 {
845  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
846  deque<double> genehet(nbLoc, 1);
847  double freq;
848 
849  //get global allele frequencies per locus
850  for (unsigned int l = 0; l < nbLoc; ++l) {
851 
852  for (unsigned int u = 0; u < nbAll; ++u) {
853 
854  freq = _globalAlleleFreq.get(l, u);
855 
856  freq *= freq; //squared frequencies
857 
858  genehet[l] -= freq; //1 - sum of p2 = expected heterozygosity
859  }
860  }
861 
862  return genehet;
863 }

References _globalAlleleFreq, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TMatrix::get(), TProtoNeutralGenes::get_allele_num(), and TProtoNeutralGenes::get_locus_num().

◆ setLociDivCounter()

void TTNeutralGenesSH::setLociDivCounter ( age_t  AGE)

Sets the allelic diversity counters.

467 {
468  unsigned int i, j, k;
469  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
470  unsigned int nbpatch = 0, patchNbr = _pop->getPatchNbr();
471  double patch_mean, pop_mean = 0;
472  bool **pop_div;
473 
474  //number of alleles per locus, Patch and pop counters:
475  pop_div = new bool * [nbLoc];
476 
477  for(i = 0; i < nbLoc; ++i) {
478  pop_div[i] = new bool [nbAll];
479  for(j = 0; j < nbAll;++j)
480  pop_div[i][j] = 0;
481  }
482 
483  for(k = 0; k < patchNbr; ++k)
484  nbpatch += (_pop->size(AGE, k) != 0);
485 
486  for(k = 0; k < patchNbr; ++k) {
487 
488  patch_mean = 0;
489 
490  for(i = 0; i < nbLoc; ++i)
491  for(j = 0; j < nbAll;++j) {
492  patch_mean += (_alleleCountTable.get(k,i,j) != 0);
493  pop_div[i][j] |= (_alleleCountTable.get(k,i,j) != 0);
494  }
495  //add mean nb of alleles per locus for Patch k to the pop mean
496  pop_mean += patch_mean/nbLoc;
497  }
498 
499  _nb_all_local = (nbpatch ? pop_mean/nbpatch : nanf("NULL"));
500 
501  _nb_all_global = 0;
502 
503  for(i = 0; i < nbLoc; ++i)
504  for(j = 0; j < nbAll;++j)
505  _nb_all_global += pop_div[i][j];
506 
507  _nb_all_global /= nbLoc;
508 
509  for(i = 0; i < nbLoc; ++i)
510  delete [] pop_div[i];
511  delete [] pop_div;
512 
513  //number of fixed loci, local and global counters:
514  _fix_loc_local = 0;
515 
516  for (k = 0; k < patchNbr; ++k)
517  for (i = 0; i < nbLoc; ++i)
518  for (j = 0; j < nbAll; ++j)
519  _fix_loc_local += ( _alleleFreqTable.get(k, i, j) == 1 );
520 
521  _fix_loc_local /= nbpatch;
522 
523  _fix_loc_global = 0;
524 
525  //globally:
526  for (i = 0; i < nbLoc; ++i)
527  for (j = 0; j < nbAll; ++j)
528  _fix_loc_global += ( _globalAlleleFreq.get(i, j) == 1 );
529 
530 }

References _alleleCountTable, _alleleFreqTable, _fix_loc_global, _fix_loc_local, _globalAlleleFreq, _nb_all_global, _nb_all_local, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, DataTable< T >::get(), TMatrix::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), and Metapop::size().

Referenced by setFstat().

+ Here is the caller graph for this function:

◆ setNeiGeneticDistance()

void TTNeutralGenesSH::setNeiGeneticDistance ( age_t  AGE)
1459 {
1460  //see: Nei, M. 1978. Genetics 89:583-590
1461  unsigned int patchNbr = this->_pop->getPatchNbr();
1462  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
1463  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
1464 
1465  setAlleleTables(AGE);
1466 
1467  if(_D == NULL)
1468 
1469  _D = new TMatrix(patchNbr, patchNbr);
1470 
1471  else if( _D->length() != patchNbr*patchNbr )
1472 
1473  _D->reset(patchNbr, patchNbr);
1474 
1475  _D->assign(nanf("NULL"));
1476 
1477  double num, denom, p1, p2, sum;
1478  double *sum_square = new double [patchNbr];
1479  double *sample_size = new double [patchNbr];
1480 
1481  for(unsigned int i = 0; i < patchNbr; ++i) {
1482 
1483  sample_size[i] = 2 * _pop->size(AGE, i);
1484 
1485  sum_square[i] = 0;
1486 
1487  if( !sample_size[i] ) continue;
1488 
1489  for(unsigned int l = 0; l < nb_locus; ++l) {
1490 
1491  sum = 0;
1492 
1493  for(unsigned int u = 0; u < nb_allele ; ++u) {
1494  p1 = _alleleFreqTable.get(i, l, u);
1495  sum += p1*p1;
1496  }
1497 
1498  sum_square[i] += (sample_size[i] * sum -1) / (sample_size[i] -1); //unbiased estimate, equ. 6 in Nei 1978 (Genetics)
1499  }
1500  }
1501 
1502  unsigned int pairs = 0;
1503  double Dpair;
1504  _meanD = 0;
1505 
1506  for(unsigned int i = 0; i < patchNbr-1; ++i) {
1507 
1508  if( !sample_size[i] ) continue;
1509 
1510  for(unsigned int j = i + 1; j < patchNbr; ++j) {
1511 
1512  if( !sample_size[j] ) continue;
1513 
1514  num = 0;
1515  pairs++;
1516 
1517  for(unsigned int l = 0; l < nb_locus; ++l) {
1518  for(unsigned int u = 0; u < nb_allele ; ++u) {
1519  p1 = _alleleFreqTable.get(i, l, u);
1520  p2 = _alleleFreqTable.get(j, l, u);
1521  num += p1*p2;
1522  }
1523  }
1524 
1525  denom = sqrt(sum_square[i] * sum_square[j]);
1526  Dpair = -log(num/denom);
1527  _meanD += Dpair;
1528  _D->set(i, j, Dpair);
1529  }
1530  }
1531  _meanD /= pairs;
1532 
1533  delete [] sum_square;
1534  delete [] sample_size;
1535 }

References _alleleFreqTable, _D, _meanD, StatHandlerBase::_pop, TraitStatHandler< TProtoNeutralGenes, TTNeutralGenesSH >::_SHLinkedTrait, TMatrix::assign(), DataTable< T >::get(), TProtoNeutralGenes::get_allele_num(), TProtoNeutralGenes::get_locus_num(), Metapop::getPatchNbr(), TMatrix::length(), TMatrix::reset(), TMatrix::set(), setAlleleTables(), and Metapop::size().

Referenced by setAdltNeiGeneticDistance(), and setOffsprgNeiGeneticDistance().

+ Here is the caller graph for this function:

◆ setNeiGeneticDistanceRecorders()

void TTNeutralGenesSH::setNeiGeneticDistanceRecorders ( age_t  AGE,
bool  pairwise 
)
2546 {
2547  string name, sub_name;
2548  unsigned int nbpatch = _pop->getPatchNbr();
2549  string prefix = (AGE == ADULTS ? "adlt." : "off.");
2550  unsigned int scale = (unsigned int)pow(10.0, (int)log10((float)nbpatch) + 1);
2551 
2552  void (TTNeutralGenesSH::* setter) () = (AGE == ADULTS ?
2555 
2556  sub_name = prefix + "D";
2557  add("Average between pop Nei's D", sub_name, AGE, 0, 0,
2559 
2560  if(pairwise) {
2561 
2562  for(unsigned int i = 0; i < nbpatch -1; i++){
2563  for(unsigned int j = i+1; j < nbpatch; j++) {
2564  name = "Nei's D between pop" + tstring::int2str(i+1) + " and pop" + tstring::int2str(j+1);
2565  sub_name = prefix + "D.p" + tstring::int2str(i+1) + "p" + tstring::int2str(j+1);
2566  add(name, sub_name, AGE, i*scale + j, 0, 0, &TTNeutralGenesSH::getNeiGeneticDistance, 0, 0);
2567  }
2568  }
2569  }
2570 }
double getNeiGeneticDistance(unsigned int i)
Definition: ttneutralgenes.h:551
void setOffsprgNeiGeneticDistance()
Definition: ttneutralgenes.h:549
void setAdltNeiGeneticDistance()
Definition: ttneutralgenes.h:548
double getMeanNeiGeneticDistance()
Definition: ttneutralgenes.h:556

References StatHandlerBase::_pop, StatHandler< SH >::add(), ADULTS, getMeanNeiGeneticDistance(), getNeiGeneticDistance(), Metapop::getPatchNbr(), tstring::int2str(), setAdltNeiGeneticDistance(), and setOffsprgNeiGeneticDistance().

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgCoaBetween()

void TTNeutralGenesSH::setOffsprgCoaBetween ( )
inline
520 {setCoaMatrix(OFFSx, 2);}

References OFFSx, and setCoaMatrix().

◆ setOffsprgCoaMatrix()

void TTNeutralGenesSH::setOffsprgCoaMatrix ( )
inline
516 {setCoaMatrix(OFFSx, 3);}

References OFFSx, and setCoaMatrix().

◆ setOffsprgCoaWithin()

void TTNeutralGenesSH::setOffsprgCoaWithin ( )
inline
518 {setCoaMatrix(OFFSx, 1);}

References OFFSx, and setCoaMatrix().

◆ setOffsprgFstat()

void TTNeutralGenesSH::setOffsprgFstat ( )
inline
459 {setFstat(OFFSPRG);}

References OFFSPRG, and setFstat().

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstBetween()

void TTNeutralGenesSH::setOffsprgFstBetween ( )
inline
438 {setFstMatrix(OFFSPRG, 2);}

References OFFSPRG, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstMatrix()

void TTNeutralGenesSH::setOffsprgFstMatrix ( )
inline
436 {setFstMatrix(OFFSPRG, 3);}

References OFFSPRG, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstWithin()

void TTNeutralGenesSH::setOffsprgFstWithin ( )
inline
437 {setFstMatrix(OFFSPRG, 1);}

References OFFSPRG, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgNeiGeneticDistance()

void TTNeutralGenesSH::setOffsprgNeiGeneticDistance ( )
inline

References OFFSPRG, and setNeiGeneticDistance().

Referenced by setNeiGeneticDistanceRecorders().

+ Here is the caller graph for this function:

◆ setOffspringAlleleFreq()

void TTNeutralGenesSH::setOffspringAlleleFreq ( )
inline

References OFFSPRG, and setAlleleTables().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ setOffspringFstatWeirCockerham()

void TTNeutralGenesSH::setOffspringFstatWeirCockerham ( )
inline

References OFFSPRG, and setFstatWeirCockerham().

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ setOffspringHeterozygosity()

void TTNeutralGenesSH::setOffspringHeterozygosity ( )
inline

References OFFSPRG, and setHeterozygosity().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ setSibCoa()

void TTNeutralGenesSH::setSibCoa ( Individual I1,
Individual I2 
)
349 {
350  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
351  //non sibs [3]
352  if((I1->getMotherID() != I2->getMotherID()) && (I1->getFatherID() != I2->getFatherID())) {
353  _sib_prop[3]++;
356  nb_locus);
357  }
358  //maternal half sibs [2]
359  else if((I1->getMotherID() == I2->getMotherID()) && (I1->getFatherID() != I2->getFatherID())) {
360  _sib_prop[2]++;
363  nb_locus);
364  }
365  //paternal half sibs [1]
366  else if((I1->getMotherID() != I2->getMotherID()) && (I1->getFatherID() == I2->getFatherID())) {
367  _sib_prop[1]++;
370  nb_locus);
371  }
372  //full sibs [0]
373  else if((I1->getMotherID() == I2->getMotherID()) && (I1->getFatherID() == I2->getFatherID())) {
374  _sib_prop[0]++;
377  nb_locus);
378  }
379 }
unsigned long getMotherID()
Definition: individual.h:124
unsigned long getFatherID()
Definition: individual.h:123

References Individual::getFatherID(), Individual::getMotherID(), and Individual::getTrait().

◆ setSibStats()

void TTNeutralGenesSH::setSibStats ( )
278 {
279  unsigned int i,j,k;
280  unsigned int patchNbr = this->_pop->getPatchNbr(), Fsize, Msize;
281  Patch* current_patch;
282  Individual *I1, *I2;
283 
284  for(i = 0;i < 4; ++i) {
285  _sib_prop[i] = 0.0;
286  _sib_coa[i] = 0.0;
287  }
288 
289  for( i = 0; i < patchNbr; ++i) {
290 
291  current_patch = _pop->getPatch(i);
292 
293  if ( (Fsize = current_patch->size(FEM, OFFSx)) != 0) {
294 
295  for(j = 0; j < Fsize -1; ++j) {
296 
297  I1 = current_patch->get(FEM, OFFSx, j);
298 
299  for(k = j+1; k < Fsize; ++k) {
300 
301  I2 = current_patch->get(FEM, OFFSx, k);
302 
303  setSibCoa(I1, I2);
304  }
305  }
306  }
307 
308  if ( (Msize = current_patch->size(MAL, OFFSx)) != 0) {
309 
310  for(j = 0; j < Msize -1; ++j) {
311 
312  I1 = current_patch->get(MAL, OFFSx, j);
313 
314  for(k = j+1; k < Msize; ++k) {
315 
316  I2 = current_patch->get(MAL, OFFSx, k);
317 
318  setSibCoa(I1, I2);
319  }
320  }
321  }
322 
323  //male-female
324  for(j = 0; j < Msize; ++j) {
325 
326  I1 = current_patch->get(MAL, OFFSx, j);
327 
328  for(k = 0; k < Fsize; ++k) {
329 
330  I2 = current_patch->get(FEM, OFFSx, k);
331 
332  setSibCoa(I1, I2);
333  }
334  }
335 
336  }
337 
338  double tot = _sib_prop[0] + _sib_prop[1] + _sib_prop[2] + _sib_prop[3];
339 
340  for(i = 0 ; i < 4; ++i) {
341  _sib_coa[i] = ( (_sib_prop[i] != 0) ? _sib_coa[i]/_sib_prop[i] : nanf("NULL"));
342  _sib_prop[i] /= tot;
343  }
344 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
void setSibCoa(Individual *I1, Individual *I2)
Definition: stats_coa.cc:348

References FEM, Patch::get(), MAL, OFFSx, and Patch::size().

◆ setStatRecorders()

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

Implements StatHandlerBase.

2080 {
2081 #ifdef _DEBUG_
2082  message("-TTNeutralGenesSH::setStatRecorders ");
2083 #endif
2084 // if(token == "coa") {
2085 //
2086 // add("Wtn Patch Coancestry (offsprg)","off.theta",OFFSPRG,0,0,
2087 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setOffsprgCoaMatrix);
2088 // add("Btn Patch Coancestry (offsprg)","off.alpha",OFFSPRG,0,0,&TTNeutralGenesSH::getMeanAlpha,0,0,0);
2089 //
2090 // add("Wtn Patch Coancestry (adult)","adlt.theta",ADULTS,0,0,
2091 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setAdultsCoaMatrix);
2092 // add("Btn Patch Coancestry (adult)","adlt.alpha",ADULTS,0,0,&TTNeutralGenesSH::getMeanAlpha,0,0,0);
2093 //
2094 // } else if(token == "adlt.coa") {
2095 //
2096 // add("Wtn Patch Coancestry (adult)","adlt.theta",ADULTS,0,0,
2097 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setAdultsCoaMatrix);
2098 // add("Btn Patch Coancestry (adult)","adlt.alpha",ADULTS,0,0,&TTNeutralGenesSH::getMeanAlpha,0,0,0);
2099 //
2100 // } else if(token == "off.coa") {
2101 //
2102 // add("Wtn Patch Coancestry (offsprg)","off.theta",OFFSPRG,0,0,
2103 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setOffsprgCoaMatrix);
2104 // add("Btn Patch Coancestry (offsprg)","off.alpha",OFFSPRG,0,0,&TTNeutralGenesSH::getMeanAlpha,0,0,0);
2105 //
2106 // } else if(token == "adlt.coa.persex") {
2107 //
2108 // add("Female Theta (adult)","adlt.theta",ADULTS,0,0,
2109 // &TTNeutralGenesSH::getMeanTheta, 0, 0, &TTNeutralGenesSH::setAdults_Theta);
2110 // add("Female Theta (adult)","adlt.thetaFF",ADULTS,0,0,&TTNeutralGenesSH::getTheta_FF,0,0,0);
2111 // add("Male Theta (adult)","adlt.thetaMM",ADULTS,0,0,&TTNeutralGenesSH::getTheta_MM,0,0,0);
2112 // add("Female-Male Theta (adult)","adlt.thetaFM",ADULTS,0,0,&TTNeutralGenesSH::getTheta_FM,0,0,0);
2113 //
2114 // } else if(token == "adlt.coa.within") {
2115 //
2116 // add("Wtn Patch Coancestry (adult)","adlt.theta",ADULTS,0,0,
2117 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setAdultsCoaWithin);
2118 //
2119 // } else if(token == "off.coa.within") {
2120 //
2121 // add("Wtn Patch Coancestry (offsprg)","off.theta",OFFSPRG,0,0,
2122 // &TTNeutralGenesSH::getMeanTheta,0,0,&TTNeutralGenesSH::setOffsprgCoaWithin);
2123 //
2124 // } else if(token == "adlt.coa.between") {
2125 //
2126 // add("Btn Patch Coancestry (adult)","adlt.alpha",ADULTS,0,0,
2127 // &TTNeutralGenesSH::getMeanAlpha,0,0,&TTNeutralGenesSH::setAdultsCoaBetween);
2128 //
2129 // } else if(token == "off.coa.between") {
2130 //
2131 // add("Btn Patch Coancestry (offsprg)","off.alpha",OFFSPRG,0,0,
2132 // &TTNeutralGenesSH::getMeanAlpha,0,0,&TTNeutralGenesSH::setOffsprgCoaBetween);
2133 //
2134 // } else if(token == "coa.matrix") {
2135 //
2136 // setCoaMatrixRecorders(OFFSPRG, 3);
2137 // setCoaMatrixRecorders(ADULTS, 3);
2138 //
2139 // } else if(token == "off.coa.matrix") {
2140 //
2141 // setCoaMatrixRecorders(OFFSPRG, 3);
2142 //
2143 // } else if(token == "adlt.coa.matrix") {
2144 //
2145 // setCoaMatrixRecorders(ADULTS, 3);
2146 //
2147 // } else if(token == "coa.matrix.within") {
2148 //
2149 // setCoaMatrixRecorders(OFFSPRG, 1);
2150 // setCoaMatrixRecorders(ADULTS, 1);
2151 //
2152 // } else if(token == "off.coa.matrix.within") {
2153 //
2154 // setCoaMatrixRecorders(OFFSPRG, 1);
2155 //
2156 // } else if(token == "adlt.coa.matrix.within") {
2157 //
2158 // setCoaMatrixRecorders(ADULTS, 1);
2159 //
2160 // } else if(token == "sibcoa") {
2161 //
2162 // add("Proportion of full-sib offspring","prop.fsib",OFFSPRG,0,0,
2163 // 0,&TTNeutralGenesSH::getSibProportions,0,&TTNeutralGenesSH::setSibStats);
2164 // add("Proportion of paternal half-sib ","prop.phsib",OFFSPRG,1,0,0,&TTNeutralGenesSH::getSibProportions,0,0);
2165 // add("Proportion of maternal half-sib ","prop.mhsib",OFFSPRG,2,0,0, &TTNeutralGenesSH::getSibProportions,0,0);
2166 // add("Proportion of non-sib offspring ","prop.nsib",OFFSPRG,3,0,0,&TTNeutralGenesSH::getSibProportions,0,0);
2167 // add("Coancestry of full-sib offspring","coa.fsib",OFFSPRG,0,0,0,&TTNeutralGenesSH::getSibCoaMeans,0,0);
2168 // add("Coancestry of paternal half-sib ","coa.phsib",OFFSPRG,1,0,0,&TTNeutralGenesSH::getSibCoaMeans,0,0);
2169 // add("Coancestry of maternal half-sib ","coa.mhsib",OFFSPRG,2,0,0,&TTNeutralGenesSH::getSibCoaMeans,0,0);
2170 // add("Coancestry of non-sib offspring ","coa.nsib",OFFSPRG,3,0,0,&TTNeutralGenesSH::getSibCoaMeans,0,0);
2171 //
2172 // } else
2173  if (token == "ntrl.freq") {
2174 
2177 
2178  } else if (token == "off.ntrl.freq") {
2179 
2181 
2182  } else if (token == "adlt.ntrl.freq") {
2183 
2185 
2186  // } else if (token == "ntrl.freq.patch") {
2187  //
2188  // setFreqRecordersPerPatch(ALL);
2189  //
2190  // } else if (token == "off.ntrl.freq.patch") {
2191  //
2192  // setFreqRecordersPerPatch(OFFSPRG);
2193  //
2194  // } else if (token == "adlt.ntrl.freq.patch") {
2195  //
2196  // setFreqRecordersPerPatch(ADULTS);
2197 
2198  } else if(token == "off.fstat") {
2199 
2201 
2202  } else if(token == "adlt.fstat") {
2203 
2205 
2206  } else if(token == "fstat") {
2207 
2209 
2210 // } else if(token == "off.fstat2") {
2211 //
2212 // setFstat2Recorders(OFFSPRG);
2213 //
2214 // } else if(token == "adlt.fstat2") {
2215 //
2216 // setFstat2Recorders(ADULTS);
2217 //
2218 // } else if(token == "fstat2") {
2219 //
2220 // setFstat2Recorders(ALL);
2221 
2222  } else if(token == "fstWC" || token == "fstatWC") {
2223 
2225 
2226  } else if(token == "off.fstWC" || token == "off.fstatWC") {
2227 
2229 
2230  } else if(token == "adlt.fstWC" || token == "adlt.fstatWC") {
2231 
2233 
2234  } else if(token == "weighted.fst") {
2235 
2238 
2239  } else if(token == "off.weighted.fst") {
2240 
2242 
2243  } else if(token == "adlt.weighted.fst") {
2244 
2246 
2247  } else if(token == "weighted.fst.matrix") {
2248 
2251 
2252  } else if(token == "off.weighted.fst.matrix") {
2253 
2255 
2256  } else if(token == "adlt.weighted.fst.matrix") {
2257 
2259 
2260  } else if(token == "weighted.fst.within") {
2261 
2264 
2265  } else if(token == "off.weighted.fst.within") {
2266 
2268 
2269  } else if(token == "adlt.weighted.fst.within") {
2270 
2272 
2273  } else if(token == "adlt.NeiDistance") {
2274 
2276 
2277  } else if(token == "off.NeiDistance") {
2278 
2280 
2281  } else if(token == "NeiDistance") {
2282 
2285 
2286  } else if(token == "mean.NeiDistance") {
2287 
2290 
2291  } else if(token == "adlt.mean.NeiDistance") {
2292 
2294 
2295  } else if(token == "off.mean.NeiDistance") {
2296 
2298 
2299  } else if(token == "Dxy") {
2300 
2301  setDxyRecorders(ADULTS, false);
2302  setDxyRecorders(OFFSPRG, false);
2303 
2304  } else if(token == "off.Dxy") {
2305 
2306  setDxyRecorders(OFFSPRG, false);
2307 
2308  } else if(token == "adlt.Dxy") {
2309 
2310  setDxyRecorders(ADULTS, false);
2311 
2312  } else if(token == "Dxy.patch") {
2313 
2314  setDxyRecorders(ADULTS, true);
2315  setDxyRecorders(OFFSPRG, true);
2316 
2317  } else if(token == "off.Dxy.patch") {
2318 
2319  setDxyRecorders(OFFSPRG, true);
2320 
2321  } else if(token == "adlt.Dxy.patch") {
2322 
2323  setDxyRecorders(ADULTS, true);
2324 
2325  } else
2326  return false;
2327 
2328  return true;
2329 }
void setDxyRecorders(age_t AGE, bool patchwise)
Definition: ttneutralgenes.cc:2575
void setFstatRecorders(age_t AGE)
Definition: ttneutralgenes.cc:2421
void setFreqRecorders(age_t AGE)
Definition: ttneutralgenes.cc:2389
void setFstatWCRecorders(age_t AGE)
Definition: ttneutralgenes.cc:2477
void setFstMatrixRecorders(age_t AGE, unsigned char dim)
Definition: ttneutralgenes.cc:2497
void setNeiGeneticDistanceRecorders(age_t AGE, bool pairwise)
Definition: ttneutralgenes.cc:2545
void message(const char *message,...)
Definition: output.cc:39
#define ALL
All ages age class flag.
Definition: types.h:55

References ADULTS, ALL, message(), OFFSPRG, setDxyRecorders(), setFreqRecorders(), setFstatRecorders(), setFstatWCRecorders(), setFstMatrixRecorders(), and setNeiGeneticDistanceRecorders().

Member Data Documentation

◆ _alleleCountTable

DataTable< unsigned int > TTNeutralGenesSH::_alleleCountTable
private

◆ _alleleFreqTable

◆ _coa_matrix

TMatrix* TTNeutralGenesSH::_coa_matrix
private

Referenced by getCoa(), and ~TTNeutralGenesSH().

◆ _D

TMatrix* TTNeutralGenesSH::_D
private

◆ _fis

double TTNeutralGenesSH::_fis
private

◆ _fis_WC

double TTNeutralGenesSH::_fis_WC
private

◆ _fis_WC_loc

double * TTNeutralGenesSH::_fis_WC_loc
private

◆ _fit

double TTNeutralGenesSH::_fit
private

◆ _fit_WC

double TTNeutralGenesSH::_fit_WC
private

◆ _fit_WC_loc

double * TTNeutralGenesSH::_fit_WC_loc
private

◆ _fix_loc_global

double TTNeutralGenesSH::_fix_loc_global
private

◆ _fix_loc_local

double TTNeutralGenesSH::_fix_loc_local
private

◆ _fst

double TTNeutralGenesSH::_fst
private

◆ _fst_matrix

TMatrix* TTNeutralGenesSH::_fst_matrix
private

Pairwise Fst matrix.

Referenced by getFst_ij(), setFstMatrix(), and ~TTNeutralGenesSH().

◆ _fst_W1

double TTNeutralGenesSH::_fst_W1
private

◆ _fst_W2

double TTNeutralGenesSH::_fst_W2
private

◆ _fst_WC

double TTNeutralGenesSH::_fst_WC
private

Weir & Cockerham (1984) F-stat estimates.

Referenced by getFstWC(), setFstatWeirCockerham(), setFstatWeirCockerham_bitstring(), and setFstatWeirCockerham_MS().

◆ _fst_WC_loc

double* TTNeutralGenesSH::_fst_WC_loc
private

Per-locus F-stats (Weir&Cockerham).

Referenced by setFstatWeirCockerham_MS(), and ~TTNeutralGenesSH().

◆ _fst_WH

double TTNeutralGenesSH::_fst_WH
private

Weir & Hill (2002) F-stat estimates.

Referenced by getWeightedFst(), and setFstMatrix().

◆ _globalAlleleFreq

◆ _heteroTable

◆ _ho

double TTNeutralGenesSH::_ho
private

F-statistics.

Referenced by getHo(), setFstat(), and setFstat_bitstring().

◆ _hs

double TTNeutralGenesSH::_hs
private

Referenced by getHs(), setFstat(), and setFstat_bitstring().

◆ _hsnei

double TTNeutralGenesSH::_hsnei
private

◆ _ht

double TTNeutralGenesSH::_ht
private

Referenced by getHt(), setFstat(), and setFstat_bitstring().

◆ _htnei

double TTNeutralGenesSH::_htnei
private

◆ _is_diallelic_bitstring

bool TTNeutralGenesSH::_is_diallelic_bitstring
private

◆ _mean_alpha

double TTNeutralGenesSH::_mean_alpha
private

Referenced by getMeanAlpha().

◆ _mean_theta

double TTNeutralGenesSH::_mean_theta
private

Referenced by getMeanTheta().

◆ _meanD

double TTNeutralGenesSH::_meanD
private

◆ _nb_all_global

double TTNeutralGenesSH::_nb_all_global
private

◆ _nb_all_local

double TTNeutralGenesSH::_nb_all_local
private

◆ _sib_coa

double TTNeutralGenesSH::_sib_coa[4]
private

Referenced by getSibCoaMeans().

◆ _sib_prop

double TTNeutralGenesSH::_sib_prop[4]
private

Kinship classes proportions.

Referenced by getSibProportions().

◆ _table_set_age

unsigned int TTNeutralGenesSH::_table_set_age
private

Referenced by allocateTables(), and setAlleleTables().

◆ _table_set_gen

unsigned int TTNeutralGenesSH::_table_set_gen
private

Referenced by allocateTables(), and setAlleleTables().

◆ _table_set_repl

unsigned int TTNeutralGenesSH::_table_set_repl
private

Referenced by allocateTables(), and setAlleleTables().

◆ Theta_FF

double TTNeutralGenesSH::Theta_FF
private

Referenced by getTheta_FF().

◆ Theta_FM

double TTNeutralGenesSH::Theta_FM
private

Referenced by getTheta_FM().

◆ Theta_MM

double TTNeutralGenesSH::Theta_MM
private

Referenced by getTheta_MM().


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