#include "includes.h" #include "grid.h" #include "vector.h" #include extern ofstream errorfs; #include "declare.h" /* This file contains source code for functions called before the estimation routines (some may not be used) */ //source code void countalleles(ivector &allelecounts, const igrid &freqallele) { //this function yields a vector of the number of alleles at each locus int i,j, ind=0; const int numloc=allelecounts.dim(); int maxnum=freqallele.dimx(); for (j=0;jfreqfreq(row,L)) ) errorfs << "WARNING: freq. retrieved from freqfreq is <=0" << endl; return freqfreq(row,L); }//getfreq double getjointfreq2C(const igrid &freqallele, const dgrid &jointfreq2C, const int &Lallele, const int &L, const int &callele, const int &C) { //this function retrieves a haplotype frequency int i; int rowL=-1,rowC=-1; //find location of Lallele in column L for (i=0;i0); return jointfreq2C(rowC*freqallele.dimx()+rowL,L); } double getjointfreq2(const igrid &freqallele, const ivector &allelecounts, const dgrid &jointfreq2, const int &ilocus, const int &iallele, const int &jallele) { //this function retrieves a 2-locus haplotype frequency int k; int ipos=-1, jpos=-1; //find positions for iallele and jallele for (k=0;kjointfreq2(ipos*allelecounts(ilocus+1)+jpos,ilocus)) ) errorfs << "WARNING: freq. retrieved from jointfreq2 is <=0" << endl; return jointfreq2(ipos*allelecounts(ilocus+1)+jpos,ilocus); } double getcondfreq2l(const igrid &freqallele, const ivector &allelecounts, const dgrid &condfreq2l, const int &ilocus, const int &iallele, const int &jallele) { //this function retrieves a conditional allele frequency int k; int ipos=-1, jpos=-1; //find positions for iallele and jallele for (k=0;kcondfreq2l(ipos*allelecounts(ilocus+1)+jpos,ilocus)) ) errorfs <<"WARNING: freq. retrieved from condfreq2l is <=0" << endl; return condfreq2l(ipos*allelecounts(ilocus+1)+jpos,ilocus); } double getcondfreq2r(const igrid &freqallele, const ivector &allelecounts, const dgrid &condfreq2r, const int &ilocus, const int &iallele, const int &jallele, const int &C) { //this function retrieves a conditional allele frequency int k; int ipos=-1, jpos=-1; //find positions for iallele and jallele for (k=0;kcondfreq2r(ipos*allelecounts(ilocus+1)+jpos,ilocus-C)) ) errorfs << "WARNING: freq. retrieved from condfreq2r is <=0" << endl; return condfreq2r(ipos*allelecounts(ilocus+1)+jpos,ilocus-C); } double getjointfreq3(const igrid &freqallele, const ivector &allelecounts, const dvector &jointfreq3, const int &ilocus, const int &iallele, const int &jallele, const int &kallele) { //this function retrieves a 3-locus haplotype frequency int k; int ipos=-1, jpos=-1, kpos=-1; //find positions for iallele and jallele and kallele for (k=0;kjointfreq3(ipos*allelecounts(ilocus+1)*allelecounts(ilocus+2)+ jpos*allelecounts(ilocus+2)+kpos)) ) errorfs << "WARNING: freq. retrieved from jointfreq3 is <=0" << endl; return jointfreq3(ipos*allelecounts(ilocus+1)*allelecounts(ilocus+2)+ jpos*allelecounts(ilocus+2)+kpos); } double getcondfreq3F(const igrid &freqallele, const ivector &allelecounts, const dgrid &condfreq3F, const int &C, const int &iallele, const int &kallele, const int &cond) { //this function retrieves a 3-locus conditional haplotype frequency int k; int ipos=-1, kpos=-1; //find positions for iallele and kallele for (k=0;k