#include "includes.h" #include "grid.h" #include "vector.h" #include extern ofstream errorfs; //declarations #include "declare.h" /* This file contains source code for functions involved in estimation of 1/tau and p given the location of the gene and the ancestral hap., assuming genotypes from affecteds-- much of code parallels that in estfunctions.C */ void makenullsharegen(dgrid &nullprobs, const igrid &data, const igrid &freqallele, const dgrid &freqfreq, const dgrid &condfreq2l, const dgrid &condfreq2r, const dgrid &condfreq2C, const ivector &allelecounts, const int &LE, const int &RE, const int &C) { //this function computes parts of observation probabilities that do //not involve the parameters-- it stores these pieces in nullprobs int i,j; const int numgen=data.dimx()/2; double f0,f1,cf00,cf10,cf01,cf11; int LHSle, LHSre, RHSle, RHSre, Cadj=-1; if (LERE) assert(-0.00001A scratchvec(1)=0;//A->N scratchvec(3)= (1 - freqC * (1-p) * exp( -tau * x[t+1]) )/ (1 - freqC * (1-p) * exp( -tau * x[t]) );//N->N scratchvec(2)=1-scratchvec(3);//N->A } else { if (REA scratchvec(1)=0;//A->N scratchvec(3)= (1 - freqC * (1-p))/ (1 - freqC * (1-p) * exp( -tau * x[RE]) );//N->N scratchvec(2)=1-scratchvec(3); //N->A } else { //RHS if (CA scratchvec(1)=1- scratchvec(0);//A->N scratchvec(2)=0;//N->A scratchvec(3)=1;//N->N } else { scratchvec(0)= exp( -tau * x[RE]);//A<-A scratchvec(1)=0;//A<-N scratchvec(2)= 1- scratchvec(0);//N<-A scratchvec(3)=1;//N<-N } } for (l=0;l<2;l++) { for (k=0;k<2;k++) { for (i=0;i<2;i++) { for (j=0;j<2;j++) { transstoreC(8*l+4*k+2*i+j,col)= scratchvec(2*l+i)*scratchvec(2*k+j); } } } } //account for phase indicators in statespace if (col==0) { if (C-1!=LE) { for (i=1;i<4;i++) { for (j=0;j<4;j++) { transstoreC(4*i+j,col)*=0.5; } } } } else { if (C9) tsi=9; //needed to get transstore entry else { if (i>6) tsi=6; else tsi=3; } } if ( (33) { if (i==1 || i==4) adj=1; else { if (i==2 || i==5) adj=-1; else adj=0; } } else adj=0; sum+= alpha(13*g+i,t)*transstore(4*(i-tsi+adj)+(j-tsj),t)* obsprobs(7*g+j,t+1); } alpha(13*g+j,t+1)=sum; } } if (LE9) tsi=9; //needed to get transstore entry else { if (i>6) tsi=6; else tsi=3; } } if ( (33) { if (i==1 || i==4) adj=1; else { if (i==2 || i==5) adj=-1; else adj=0; } } else adj=0; sum+= alpha(13*g+i,RE)*transstore(4*(i-tsi+adj)+(j-tsj),RE)* obsprobs(7*g+j,C); } if (initstore(j-tsj,1)==0) { if (sum!=0) { errorfs << "ERROR: alpha(13*" << g << "+" << j << ",C) = " << "P(A|B) = P(A&B)/P(B) =!0/0" << endl; exit(1); } } else sum/=initstore(j-tsj,1); alpha(13*g+j,C)=sum; } } } //check that all entries are between 0 and 1 for (i=0;i=RHSle;t--) { if (t==C && (LE9) tsi=9; //needed to get transstore entry else { if (i>6) tsi=6; else { if (i>3) tsi=3; else tsi=0; } } for (j=0;j=LHSle;t--) { if (t==LE && LE3) { if (i==1 || i==4) adj=1; else { if (i==2 || i==5) adj=-1; else adj=0; } } else adj=0; sum+= beta(13*g+j,t+1)*transstore(4*(i-tsi+adj)+(j-tsj),t)* obsprobs(7*g+j,t+1); } beta(13*g+i,t)=sum; } } if (C9) tsi=9; //needed to get transstore entry else { if (i>6) tsi=6; else { if (i>3) tsi=3; else tsi=0; } } for (j=0;j