Nemo  2.4.2
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
359  _fit_WC_loc(0), _fst_matrix(0), _D(0)
360  { }
double * _fis_WC_loc
Definition: ttneutralgenes.h:344
TMatrix * _fst_matrix
Pairwise Fst matrix.
Definition: ttneutralgenes.h:348
unsigned int _table_set_gen
Definition: ttneutralgenes.h:325
TMatrix * _D
Definition: ttneutralgenes.h:351
double * _fst_WC_loc
Per-locus F-stats (Weir&Cockerham).
Definition: ttneutralgenes.h:344
double * _fit_WC_loc
Definition: ttneutralgenes.h:344
TMatrix * _coa_matrix
Definition: ttneutralgenes.h:330
bool _is_diallelic_bitstring
Definition: ttneutralgenes.h:326
unsigned int _table_set_age
Definition: ttneutralgenes.h:325
unsigned int _table_set_repl
Definition: ttneutralgenes.h:325

◆ ~TTNeutralGenesSH()

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

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 
)
44 {
45  unsigned int nb_patch = _pop->getPatchNbr();
46  unsigned int **sizes;
47 
48  sizes = new unsigned int * [nb_patch];
49 
50  for(unsigned int i = 0; i < nb_patch; ++i) {
51  sizes[i] = new unsigned int [loci];
52  for(unsigned int j = 0; j < loci; ++j)
53  sizes[i][j] = all;
54  }
55 
56  _alleleCountTable.allocate(nb_patch, loci, sizes);
57 
58  _alleleFreqTable.allocate(nb_patch, loci, sizes);
59 
60  _globalAlleleFreq.reset(loci, all);
61 
62  for(unsigned int i = 0; i < nb_patch; ++i)
63  delete [] sizes[i];
64  delete [] sizes;
65 
66  //reset the time info, to force recalculation after allocate
68  _table_set_gen = 0;
69  _table_set_repl = 0;
70 }
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:105
unsigned int getPatchNbr()
Definition: metapop.h:274
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:59
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:159
DataTable< unsigned int > _alleleCountTable
Definition: ttneutralgenes.h:321
TMatrix _globalAlleleFreq
Definition: ttneutralgenes.h:324
DataTable< double > _alleleFreqTable
Definition: ttneutralgenes.h:322
#define NONE
No age flag.
Definition: types.h:46

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
42 {
43  unsigned int p = 0;
44 
45  for (unsigned int k = 0; k < nb_locus; ++k)
46  p += (ind1->get_allele(k,0)==ind2->get_allele(k,0))
47  + (ind1->get_allele(k,0)==ind2->get_allele(k,1))
48  + (ind1->get_allele(k,1)==ind2->get_allele(k,0))
49  + (ind1->get_allele(k,1)==ind2->get_allele(k,1));
50 
51  return (double)p/(4.0*nb_locus);
52 }
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
415 {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.

413 {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.
527  {
528  unsigned int scale = (unsigned int)pow( 10.0, (int)log10((float)_coa_matrix->getNbCols()) + 1 );
529  return _coa_matrix->get(i/scale, i%scale);
530  }
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:213
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191

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

◆ getDxy()

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

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
561 {return getDxyPerPatch(ADLTx, patch1, patch2);}
@ ADLTx
Definition: types.h:40

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

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
469 {return _fis;}
double _fis
Definition: ttneutralgenes.h:338

References _fis.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFisWC()

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

References _fis_WC.

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ getFit()

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

References _fit.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFitWC()

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

References _fit_WC.

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ getFixLocGlobal()

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

References _fix_loc_global.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFixLocLocal()

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

References _fix_loc_local.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getFst()

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

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

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

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

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ getFstWC()

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

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
394  {
395  return _globalAlleleFreq.get(loc, all);
396  }

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.

420 {return &_globalAlleleFreq;}

References _globalAlleleFreq.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getHeteroTable()

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

References _heteroTable.

Referenced by TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getHeterozygosity()

double TTNeutralGenesSH::getHeterozygosity ( unsigned int  loc)
inline
398  {
399  double het = 0;
400  for(unsigned int i = 0; i < _heteroTable.getNumGroups(); ++i )
401  het += _heteroTable.get(i, loc, 0);
402  return het/_heteroTable.getNumGroups(); //mean per patch heterozygosity
403  }
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:226
unsigned int getNumGroups()
Definition: datatable.h:256

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
465 {return _ho;}
double _ho
F-statistics.
Definition: ttneutralgenes.h:337

References _ho.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getHs()

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

References _hs.

◆ getHsnei()

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

References _hsnei.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getHt()

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

References _ht.

◆ getHtnei()

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

References _htnei.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getMeanAlpha()

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

References _mean_alpha.

◆ getMeanNeiGeneticDistance()

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

References _meanD.

Referenced by setNeiGeneticDistanceRecorders().

+ Here is the caller graph for this function:

◆ getMeanTheta()

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

References _mean_theta.

◆ getNbAllGlobal()

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

References _nb_all_global.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getNbAllLocal()

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

References _nb_all_local.

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ getNeiGeneticDistance()

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

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
542 {return _sib_coa[i];}
double _sib_coa[4]
Definition: ttneutralgenes.h:334

References _sib_coa.

◆ getSibProportions()

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

References _sib_prop.

◆ getTheta_FF()

double TTNeutralGenesSH::getTheta_FF ( )
inline

Gives the mean within females coancestry coefficient.

534 {return Theta_FF;}
double Theta_FF
Definition: ttneutralgenes.h:328

References Theta_FF.

◆ getTheta_FM()

double TTNeutralGenesSH::getTheta_FM ( )
inline

Gives the mean between males and females coancestry coefficient.

538 {return Theta_FM;}
double Theta_FM
Definition: ttneutralgenes.h:328

References Theta_FM.

◆ getTheta_MM()

double TTNeutralGenesSH::getTheta_MM ( )
inline

Gives the mean within males coancestry coefficient.

536 {return Theta_MM;}
double Theta_MM
Definition: ttneutralgenes.h:328

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

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

References _fst_WH.

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ init()

void TTNeutralGenesSH::init ( )
virtual

Reimplemented from StatHandlerBase.

2064 {
2066 
2068 
2069  // For diallelic bitstring, defer DataTable allocation.
2070  // setFstat_bitstring() computes F-stats in streaming mode without DataTables.
2071  // Other stat methods (fstat2, fstWC, etc.) will trigger lazy allocation if needed.
2074 }
virtual void init()
Definition: stathandler.cc:37
unsigned int get_allele_num()
Definition: ttneutralgenes.h:199
void allocateTables(unsigned int loci, unsigned int all)
Definition: stats_fstat.cc:43

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:1457

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:74

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:251

References ADULTS, and setHeterozygosity().

Referenced by setFreqRecorders().

+ Here is the caller graph for this function:

◆ setAdults_Theta()

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

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

◆ setAdultsCoaBetween()

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

References ADLTx, and setCoaMatrix().

◆ setAdultsCoaMatrix()

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

References ADLTx, and setCoaMatrix().

◆ setAdultsCoaWithin()

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

References ADLTx, and setCoaMatrix().

◆ setAdultsFstat()

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

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:974

References ADULTS, and setFstatWeirCockerham().

Referenced by setFstatWCRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstBetween()

void TTNeutralGenesSH::setAdultsFstBetween ( )
inline
434 {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:868

References ADULTS, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstMatrix()

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

References ADULTS, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setAdultsFstWithin()

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

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

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

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)
2389 {
2390  string prefix = (AGE == OFFSPRG ? "off." : "adlt.");
2391 
2392  void (TTNeutralGenesSH::* setter) () = (AGE == ADULTS ? &TTNeutralGenesSH::setAdultAlleleFreq :
2394 
2395  unsigned int nb_allele = _SHLinkedTrait->get_allele_num();
2396  unsigned int nb_locus = _SHLinkedTrait->get_locus_num();
2397 
2398  for (unsigned int l = 0; l < nb_locus; ++l) {
2399  for (unsigned int u = 0; u < nb_allele-1; ++u) {
2400  add("", prefix + "ntrl.l" + tstring::int2str(l+1) + ".a" + tstring::int2str(u+1), AGE, l, u,
2401  0, 0, &TTNeutralGenesSH::getGlobalAlleleFreq, setter);
2402  }
2403  }
2404 
2405  setter = (AGE == ADULTS ? &TTNeutralGenesSH::setAdultHeterozygosity :
2407 
2408  for (unsigned int l = 0; l < nb_locus; ++l) {
2409  add("", prefix + "ntrl.l" + tstring::int2str(l+1) + ".Het", AGE, l, 0, 0,
2411  // add("", prefix + "ntrl.l" + tstring::int2str(l) + ".Hom", AGE, l, 0, 0,
2412  // &TTNeutralGenesSH::getHomozygosity, 0, 0);
2413  }
2414 
2415 }
The stat handler for neutral markers.
Definition: ttneutralgenes.h:319
void setAdultHeterozygosity()
Definition: ttneutralgenes.h:391
double getGlobalAlleleFreq(unsigned int loc, unsigned int all)
Definition: ttneutralgenes.h:394
double getHeterozygosity(unsigned int loc)
Definition: ttneutralgenes.h:398
void setAdultAlleleFreq()
Definition: ttneutralgenes.h:388
void setOffspringHeterozygosity()
Definition: ttneutralgenes.h:392
void setOffspringAlleleFreq()
Definition: ttneutralgenes.h:389

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.

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

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

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

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.

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

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

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

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

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

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.

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

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.

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

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

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

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

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)
252 {
253  unsigned int patchNbr = this->_pop->getPatchNbr();
254  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
255  unsigned int nb_allele = this->_SHLinkedTrait->get_allele_num();
256  Patch* patch;
257  age_idx age_pos = (AGE == ADULTS ? ADLTx : OFFSx);
258 
259  setHeteroTable(AGE);
260 
261  for (unsigned int i = 0, size; i < patchNbr; ++i) {
262 
263  patch = _pop->getPatch(i);
264  size = patch->size(age_pos);
265 
266  if(!size) continue;
267 
268  for (unsigned int l = 0; l < nb_locus; ++l) {
269  for (unsigned int u = 0; u < nb_allele; ++u) {
270  _heteroTable.divide(i, l , u, size);
271  }
272  }
273  }
274 
275 
276 }
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:250

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

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.

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

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)
594 {
595  unsigned int i, k, x, nb_patch=0;
596  double hs = 0;
597  unsigned int nbLoc = _SHLinkedTrait->get_locus_num(), nbAll = _SHLinkedTrait->get_allele_num();
598  unsigned int patchNbr = _pop->getPatchNbr();
599  deque<double>genehet(nbLoc,1);
600  deque<double>hspop(patchNbr,0);
601  double freq;
602  Patch* current_patch;
603 
604  //compute the expected heterozygosity for each patch and return average:
605  for (i = 0; i < patchNbr; ++i) {
606 
607  current_patch = _pop->getPatch(i);
608 
609  genehet.assign(nbLoc, 1);
610 
611  if(current_patch->size(age_pos) != 0) {
612 
613  nb_patch++;
614 
615  for (k = 0; k < nbLoc; ++k) {
616 
617  for (x = 0; x < nbAll; ++x) {
618 
619  freq = _alleleFreqTable.get(i, k, x);
620 
621  freq *= freq; //squared frequencies (expected _homozygosity)
622 
623  genehet[k] -= freq; //1 - sum of p2 = expected heterozygosity
624  }
625  //expected heterozygosity:
626  hspop[i] += genehet[k];
627  }
628  }//end_if size!=0
629 
630  hs += hspop[i];
631  }//end patch loop
632 
633  return (nb_patch !=0 ? hs/(nbLoc*nb_patch) : 0.0);
634 }
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:559

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

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

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

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.

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

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

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

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
519 {setCoaMatrix(OFFSx, 2);}

References OFFSx, and setCoaMatrix().

◆ setOffsprgCoaMatrix()

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

References OFFSx, and setCoaMatrix().

◆ setOffsprgCoaWithin()

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

References OFFSx, and setCoaMatrix().

◆ setOffsprgFstat()

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

References OFFSPRG, and setFstat().

Referenced by setFstatRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstBetween()

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

References OFFSPRG, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstMatrix()

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

References OFFSPRG, and setFstMatrix().

Referenced by setFstMatrixRecorders().

+ Here is the caller graph for this function:

◆ setOffsprgFstWithin()

void TTNeutralGenesSH::setOffsprgFstWithin ( )
inline
436 {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 
)
348 {
349  unsigned int nb_locus = this->_SHLinkedTrait->get_locus_num();
350  //non sibs [3]
351  if((I1->getMotherID() != I2->getMotherID()) && (I1->getFatherID() != I2->getFatherID())) {
352  _sib_prop[3]++;
355  nb_locus);
356  }
357  //maternal half sibs [2]
358  else if((I1->getMotherID() == I2->getMotherID()) && (I1->getFatherID() != I2->getFatherID())) {
359  _sib_prop[2]++;
362  nb_locus);
363  }
364  //paternal half sibs [1]
365  else if((I1->getMotherID() != I2->getMotherID()) && (I1->getFatherID() == I2->getFatherID())) {
366  _sib_prop[1]++;
369  nb_locus);
370  }
371  //full sibs [0]
372  else if((I1->getMotherID() == I2->getMotherID()) && (I1->getFatherID() == I2->getFatherID())) {
373  _sib_prop[0]++;
376  nb_locus);
377  }
378 }
unsigned long getMotherID()
Definition: individual.h:123
unsigned long getFatherID()
Definition: individual.h:122

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

◆ setSibStats()

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

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

◆ setStatRecorders()

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

Implements StatHandlerBase.

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

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.2 by  doxygen 1.9.1

Catalogued on GSR