6471 error(
"TTQOhtaStats::quanti trait and population are not compatible with Ohta stats (min. 2 patches, one di-allelic trait), file will not be written.\n");
6490 Patch* current_patch;
6492 vector<double> Dis(num_comb, 0.0),
6494 Disp(num_comb, 0.0),
6495 Dstp(num_comb, 0.0);
6497 vector< vector<double> > rSquare = vector< vector<double> > (patchNbr, vector<double>(num_comb, 0.0));
6499 vector<bool> NA(num_comb,
false);
6502 int extant_patches = 0;
6504 vector<int> patchSizes(patchNbr, 0);
6508 for(
int patch = 0; patch < patchNbr; patch++) {
6510 current_patch = pop->
getPatch(patch);
6514 if(patchSizes[patch]) ++extant_patches;
6516 total_size += patchSizes[patch];
6520 message(
"TTQOhtaStats::FHwrite:: computing association stats of %i combinations\n", num_comb);
6524 unsigned int a1, a2;
6525 unsigned int twoLocHapMap[2][2] = {{0,1},{2,3}};
6526 unsigned int reverseHapMap[4][2] = {{0,2},{0,3},{1,2},{1,3}};
6528 vector< double > meanAlleleFreq(4,0.0);
6529 vector< double > meanHapFreq(4,0.0);
6531 vector< vector< double > > alleleFreq = vector< vector< double > > (patchNbr, vector< double >(4,0.0));
6532 vector< vector< double > > hapFreq = vector< vector< double > > (patchNbr, vector< double >(4,0.0));
6535 for (
size_t pcomb = 0; pcomb < num_comb; pcomb++) {
6540 meanAlleleFreq.assign(4, 0.0);
6541 meanHapFreq.assign(4,0.0);
6543 for(
int patch = 0; patch < patchNbr; patch++) {
6545 current_patch = pop->
getPatch(patch);
6547 alleleFreq[patch].
assign(4,0.0);
6548 hapFreq[patch].assign(4,0.0);
6550 if(patchSizes[patch] == 0)
continue;
6554 for(
unsigned int s =0; s < 2; ++s) {
6556 for(
unsigned int j = 0, size = current_patch->
size(
sex_t(s),
ADLTx); j < size; j++) {
6565 ++alleleFreq[patch][0];
6569 ++alleleFreq[patch][1];
6575 ++alleleFreq[patch][2];
6579 ++alleleFreq[patch][3];
6583 ++hapFreq[patch][ twoLocHapMap[a1][a2] ];
6588 ++alleleFreq[patch][0];
6592 ++alleleFreq[patch][1];
6598 ++alleleFreq[patch][2];
6602 ++alleleFreq[patch][3];
6606 ++hapFreq[patch][ twoLocHapMap[a1][a2] ];
6611 for (
size_t geno = 0; geno < 4; geno++) {
6612 alleleFreq[patch][geno] /= patchSizes[patch];
6613 meanAlleleFreq[ geno ] += alleleFreq[patch][ geno ];
6616 for (
size_t hap = 0; hap < 4; hap++) {
6617 hapFreq[patch][hap] /= patchSizes[patch];
6618 meanHapFreq[hap] += hapFreq[patch][hap];
6622 for (
size_t geno = 0; geno < 4; geno++)
6623 meanAlleleFreq[geno] /= extant_patches;
6625 for (
size_t hap = 0; hap < 4; hap++)
6626 meanHapFreq[hap] /= extant_patches;
6629 if ( !(meanAlleleFreq[0]*meanAlleleFreq[1]) && !(meanAlleleFreq[2] * meanAlleleFreq[3]))
6634 for(
int patch = 0; patch < patchNbr; patch++) {
6636 if(!patchSizes[patch])
continue;
6638 for (
size_t hap = 0; hap < 4; hap++) {
6640 Dis[pcomb] += pow(hapFreq[patch][hap] -
6641 (alleleFreq[patch][ reverseHapMap[hap][0] ] * alleleFreq[patch][ reverseHapMap[hap][1]] ), 2);
6644 Dst[pcomb] += pow((alleleFreq[patch][reverseHapMap[hap][0]] * alleleFreq[patch][reverseHapMap[hap][1]]) -
6645 (meanAlleleFreq[reverseHapMap[hap][0]] * meanAlleleFreq[reverseHapMap[hap][1]]), 2);
6648 Disp[pcomb] += pow(hapFreq[patch][hap] - meanHapFreq[hap], 2);
6651 Dstp[pcomb] += pow(meanHapFreq[hap] -
6652 (meanAlleleFreq[reverseHapMap[hap][0]] * meanAlleleFreq[reverseHapMap[hap][1]]), 2);
6655 double denom = alleleFreq[patch][0] * alleleFreq[patch][1] * alleleFreq[patch][2] * alleleFreq[patch][3];
6658 rSquare[patch][pcomb] = 0;
6660 rSquare[patch][pcomb] = pow(hapFreq[patch][0] - alleleFreq[patch][0]*alleleFreq[patch][2], 2)
6665 Dis[pcomb] /= extant_patches;
6666 Dst[pcomb] /= extant_patches;
6667 Disp[pcomb] /= extant_patches;
6668 Dstp[pcomb] /= extant_patches;
6699 FILE.open(filename.c_str(), ios::out);
6700 std::ios_base::sync_with_stdio(
false);
6702 if(!FILE)
fatal(
"Trait quanti could not open output file: \"%s\"\n",filename.c_str());
6705 message(
"TTQOhtaStats::FHwrite (%s)\n",filename.c_str());
6710 FILE <<
"loc1\tloc2\tDst\tDis\tDstp\tDisp";
6712 for(
int patch = 0; patch < patchNbr; patch++)
6713 FILE <<
"\tr_" << patch+1;
6716 for (
size_t pcomb = 0; pcomb < num_comb; pcomb++) {
6719 << Dst[pcomb] <<
"\t" << Dis[pcomb] <<
"\t" << Dstp[pcomb] <<
"\t" << Disp[pcomb];
6720 for(
int patch = 0; patch < patchNbr; patch++)
6721 FILE <<
"\t" << rSquare[patch][pcomb];
6727 std::ios_base::sync_with_stdio(
true);
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:149
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:101
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:137
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:196
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
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
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
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:76
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191
unsigned int nrows() const
Definition: tmatrix.h:211
unsigned int get_allele_model()
Definition: ttquanti.h:432
unsigned int get_num_locus()
Definition: ttquanti.h:422
unsigned int get_num_traits()
Definition: ttquanti.h:421
TMatrix _pairwiseCombs
Definition: ttquanti.h:855
TTQuanti_diallelic.
Definition: ttquanti.h:279
virtual bool get_allele_bit(unsigned int position, unsigned int allele) const
Definition: ttquanti.cc:3966
int _FHLinkedTraitIndex
Definition: filehandler.h:222
TProtoQuanti * _FHLinkedTrait
Definition: filehandler.h:221
void fatal(const char *str,...)
Definition: output.cc:98
int error(const char *str,...)
Definition: output.cc:77
void message(const char *message,...)
Definition: output.cc:38
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35
@ ADLTx
Definition: types.h:40
TMatrix nChooseKVec(int n, int k)
Definition: utils.cc:196