#include "includes.h" #include "grid.h" #include "vector.h" #include "time.h" #include extern ofstream errorfs; #include "declare.h" /* This file contains source code for estimating two-locus haplotype frequencies jointly using an HMM-- this complication is necessary to get "consistent" estimates across overlapping pairs of loci when there are missing alleles, ie., alleles not typed */ /* Following this, there is source code for adjustments to these frequencies for the following cases: 1. Allele appears in affected genotypes/haps. but not in controls (assigning freq. of 0 seems to harsh and will lead to loglik of -inf) 2. Haplotype appears in affecteds (or is compatible with genotypes) but either does not appear in controls or the estimate of freq. is vanishingly small (once again, seems too harsh a penalty) This is not trivial, because changing one joint frequency could change freq's at neighboring marker-pairs, etc., if not done correctly. */ void makehap2fr_hmm_Gcon(dvectors &h_freq_lists, const ivectors &a_lists, const igrid &controls, const int &debug) { //this routine estimates two-marker haplotype frequencies, for genotype //controls, using a HMM int l,g,i,iter,conv,loop; double diff, loglik=0, loglik_test=0; const int numloc=controls.dimy(); const int numgen=controls.dimx()/2; //delete me //for (l=0;lloglik_test) { loglik_test=loglik; for (l=0;l=0;l--) { for (i=0;i=0;l--) { for (i=0;i0) { entry=e/(additionalalleles[0]*non0); for (i=0;i0) { //cout << l << " " << num_i << " " << e/(k_i_lp1*num_i) << " "; for (j=0;j0) { mg_genoteype_res.init(numgen); for (g=0;g0) { flag = 1; for (k=0; k0); //print to screen if (debug) { cout << "Allelecounts: " << endl; for (j=0;j0) { flag = 1; for (k=0; k=0.0 ); } } if (debug) { cout << "genotype_res [E-step]" << endl; for (g=0; g0) { flag = 1; //check that it is not in c_allele_lists for (k=0; kc_allele_lists[loc].dim()) { place=c_allele_lists[loc].dim(); for (i=0; i0) { flag = 1; //check that it is not in c_allele_lists for (k=0; kmax) max=hap_freq[l].dim(); //initialize jointfreq2 jointfreq2.init(max,hap_freq.dim()); jointfreq2.clear(0); for (l=0;l=0.0 && jointfreq2(i,l)<=1.0 ); } } if (debug) { cout << "jointfreq2" << endl; for (i=0;imax) max=allele_list[l].dim(); //initialize freqallele freqallele.init(max,allele_list.dim()); freqallele.clear(0); for (l=0;l=0.0 && freqfreq(i,l)<=1.0 ); } } if (debug) { cout << "freqfreq" << endl; for (i=0;i0) { conv=1; break; } if (conv==0) trans[l][i*a_lists[l+1].dim() ]=1.0; } }//l //check trans for (l=0;l=0;l--) { for (i=0;i