#include "includes.h" #include "grid.h" #include "vector.h" #include "declare.h" /* This file contains source code for functions called in function max() which estimates ancestral haplotype */ void makeinitcandanc(igrid &candanc, const int &C, const int &LE, const int &RE, const int &ctrall, const igrid &allelelist, int &numcand) { //This function generates a first list of candidate ancestral haplotypes; //the haplotypes consist of two adjacent markers and locus C. All //possibilities are listed. int i,j;//make variables for loops; int numCm1=0;//find out how many alleles at locus LE; int numCp1=0;//find out how many alleles at locus RE; //find out how many alleles at LE; for (i=0;i candanc.dimx()) { cout << "ERROR: Need more than " << candanc.dimx() << " rows in candanc matrix" << endl; exit(1); } //make center column; for (i=0;i candanc.dimx()) { cout << "ERROR: Need more than " << candanc.dimx() << " rows in candanc matrix" << endl; exit(1); } //copy core numCq1-1 times; for (i=1;i<=numCq1-1;i++)//copy index { for (j=LE;j<=RE;j++)//locus index { for (k=0;kRE) { for (j=0;j candres(row,loclik)) { rowswitchint(candanc,row,row1); rowswitchdou(candres,row,row1); } } } }//sortcandancbylik void rowswitchint(igrid &candanc, const int &row, const int &row1) { //this function switches two rows in a grid of integers int j; ivector temprow(candanc.dimy()); for (j=0;j0 && RE=x.dim()-1) dir = 0; else { if (LE <= 0) dir = 1; else dir = -1; } } return dir; }//whichdir int findnumkeep(const dgrid &candres, const int &dirjump, const double &threshfix, const double &threshvar, int &numcand) { //when estimating the extent of LD, not mapping, the number of candidate //ancestral haplotypes designated to continue being "grown" depends on //the magnitude of cstar. This function counts the number of candidates //fed into makecandanc(). //find column by which weve sorted; int pos; if (dirjump==-1) pos=6; else pos=7; int i; int dummy=1; int numkeep=0; //count number of haplotypes above the threshold; for (i=0;imax) max=candres(i,loclik+1); } //equalize null lik's and add to model lik. for (i=0;i max + 0.0001) cout << "WARNING: the null likelihood for the " << i << "th candidate ancestral haplotype (" << templiknull << ") does not differ from the max null lik (" << max << ") by a multiple of log(2)" << endl; } } }//correctlik