#include "missingtrio.h" Missingtrio::Missingtrio(Missing * M_offspring, Missing * M_par1, Missing * M_par2, int typed_o, int typed_par1, int typed_par2, const map & hap_list, const vector & content, int size) { if(size==0) return; this->M_offspring = M_offspring; this->M_par1 = M_par1; this->M_par2 = M_par2; this->typed_o = typed_o; this->typed_par1 = typed_par1; this->typed_par2 = typed_par2; this->size = size; // # of SNPs this->count=0; set_vec(); keep(hap_list,content); dim = sites.size(); int row=hap_list.size(); if(row==0) row=1<0) { weight = new double*[dim]; for(int i=0;i & hap_list, const vector & content, int size) { if(size==0) return; if(typed_par1==1) printf("Constructor of Missingtrio for founder fails. Please check\n"); if(typed_par2==1) printf("Constructor of Missingtrio for founder fails. Please check\n"); this->M_offspring = M_offspring; this->typed_o = typed_o; this->typed_par1 = typed_par1; this->typed_par2 = typed_par2; this->size = size; // # of SNPs this->count=0; set_vec(); keep(hap_list,content); dim = sites.size(); int row=hap_list.size(); if(row==0) row=1<0) { weight = new double*[dim]; for(int i=0;i offspring = M_offspring->get_missing_pat_genotype(); const vector father = M_par1->get_missing_pat_genotype(); const vector mother = M_par2->get_missing_pat_genotype(); for(int i=0;i iv = trio_geno->get_inh_vec(); if(iv.size()>0) missing_pat_trio_genotype.push_back(trio_geno); else delete trio_geno; } } else if(typed_par1==0 && typed_par2==0) { const vector offspring = M_offspring->get_missing_pat_genotype(); for(int i=0;i iv = trio_geno->get_inh_vec(); if(iv.size()>0) missing_pat_trio_genotype.push_back(trio_geno); else delete trio_geno; } } // both parents are untyped } void Missingtrio::set_weight(map & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map, int **count) { int col = missing_pat_trio_genotype.size(); for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==1) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; gfreq[i]+=geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } pair hp_offspring = iv[0].hp_offspring; loc = hap_pair_map[hp_offspring]; for(int j=0;j0) weight[j][i] = double(count[sites[j]][loc])/2.0; } } else { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; value = geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); gfreq[i]+=value; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) weight[k][i]+=count[sites[k]][loc]*value; } } for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==1) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; gfreq[i]+=geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); } pair hp_offspring = iv[0].hp_offspring; loc = hap_pair_map[hp_offspring]; for(int j=0;j0) weight[j][i] = double(count[sites[j]][loc])/2.0; } } else { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; value = geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); gfreq[i]+=value; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) weight[k][i]+=count[sites[k]][loc]*value; } } for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==1) { for(int j=0;j hp_offspring = iv[j].hp_offspring; gfreq[i]+=geno_freq_table[hp_offspring]; } pair hp_offspring = iv[0].hp_offspring; loc = hap_pair_map[hp_offspring]; for(int j=0;j0) weight[j][i] = double(count[sites[j]][loc])/2.0; } } else { for(int j=0;j hp_offspring = iv[j].hp_offspring; gfreq[i]+=geno_freq_table[hp_offspring]; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) weight[k][i]+=count[sites[k]][loc]*geno_freq_table[hp_offspring]; } } for(int j=0;j & hap_freq_table, double *freq, map, double> & geno_freq_table){ for(int i=0;i0){ nonzero.push_back(i); break; } } } for(int i=0;i & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map, int **count, double **rst, double ***hst){ int row = hap_freq_table.size(); for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==0) { memset(matrix1,0,(row-1)*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; loc = hap_pair_map[hp_offspring]; loc_f = hap_pair_map[hp_father]; loc_m = hap_pair_map[hp_mother]; for(int k=0;k0) matrix2[l][k]+=count[sites[l]][loc]*value; } } } for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==0) { memset(matrix1,0,(row-1)*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; loc = hap_pair_map[hp_offspring]; loc_f = hap_pair_map[hp_father]; for(int k=0;k0) matrix2[l][k]+=count[sites[l]][loc]*value; } } } for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==0) { memset(matrix1,0,(row-1)*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) { for(int l=0;l & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map, map & hap_weight, int **count) { memset(deriv1,0,dim*sizeof(double)); memset(deriv2,0,dim*sizeof(double)); memset(deriv3,0,dim*sizeof(double)); double value; double value1, value2, value3; int loc; int loc_f, loc_m; double matrix1 = 0; double *matrix2 = new double[dim]; memset(matrix2,0,dim*sizeof(double)); double matrix3 = 0; double *matrix4 = new double[dim]; memset(matrix4,0,dim*sizeof(double)); double matrix5 = 0; double *matrix6 = new double[dim]; memset(matrix6,0,dim*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==0) { matrix1 = 0; memset(matrix2,0,dim*sizeof(double)); matrix3 = 0; memset(matrix4,0,dim*sizeof(double)); matrix5 = 0; memset(matrix6,0,dim*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; loc = hap_pair_map[hp_offspring]; loc_f = hap_pair_map[hp_father]; loc_m = hap_pair_map[hp_mother]; value = geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); value1 = value*(hap_weight[hp_offspring.first]+hap_weight[hp_offspring.second]); value2 = value*(hap_weight[hp_father.first]+hap_weight[hp_father.second]); value3 = value*(hap_weight[hp_mother.first]+hap_weight[hp_mother.second]); matrix1+=value1; matrix3+=value2; matrix5+=value3; for(int k=0;k0) { matrix2[k]+=count[sites[k]][loc]*value1; matrix4[k]+=count[sites[k]][loc]*value2; matrix6[k]+=count[sites[k]][loc]*value3; } } } for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { if(missing_pat_trio_genotype[i]->phase==0) { matrix1 = 0; memset(matrix2,0,dim*sizeof(double)); matrix3 = 0; memset(matrix4,0,dim*sizeof(double)); matrix5 = 0; memset(matrix6,0,dim*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; loc = hap_pair_map[hp_offspring]; loc_f = hap_pair_map[hp_father]; value = geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); value1 = value*(hap_weight[hp_offspring.first]+hap_weight[hp_offspring.second]); value2 = value*(hap_weight[hp_father.first]+hap_weight[hp_father.second]); int trans_hap; if(hp_father.first==hp_father.second) { if(hp_offspring.first==hp_father.first) trans_hap = hp_offspring.second; else if(hp_offspring.second==hp_father.first) trans_hap = hp_offspring.first; } else { if(hp_offspring.first==hp_offspring.second) { if(hp_offspring.first==hp_father.first || hp_offspring.first==hp_father.second) trans_hap = hp_offspring.second; } else { if(hp_offspring.first==hp_father.first && hp_offspring.second==hp_father.second) trans_hap = -1; else if(hp_offspring.first==hp_father.first || hp_offspring.first==hp_father.second) trans_hap = hp_offspring.second; else if(hp_offspring.second==hp_father.first || hp_offspring.second==hp_father.second) trans_hap = hp_offspring.first; } } if(trans_hap==-1) value3 = value*(hap_freq_table[hp_offspring.first]*hap_weight[hp_offspring.first]+hap_freq_table[hp_offspring.second]*hap_weight[hp_offspring.second])/(hap_freq_table[hp_offspring.first]+hap_freq_table[hp_offspring.second]); else value3 = value*hap_weight[trans_hap]; matrix1+=value1; matrix3+=value2; matrix5+=value3; for(int k=0;k0) { matrix2[k]+=count[sites[k]][loc]*value1; matrix4[k]+=count[sites[k]][loc]*value2; matrix6[k]+=count[sites[k]][loc]*value3; } } } for(int j=0;j, double> & geno_freq_table, map, int> & hap_pair_map, map & hap_weight, vector & h_weight, int **count) { memset(deriv_r,0,dim*sizeof(double)); int loc; double value; double matrix1 = 0; double *matrix2 = new double[dim]; memset(matrix2,0,dim*sizeof(double)); for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>1) { matrix1 = 0; memset(matrix2,0,dim*sizeof(double)); for(int j=0;j hp_offspring = iv[j].hp_offspring; loc = hap_pair_map[hp_offspring]; value = geno_freq_table[hp_offspring]*(hap_weight[hp_offspring.first]+hap_weight[hp_offspring.second]); matrix1+=value; for(int k=0;k0) matrix2[k]+=count[sites[k]][loc]*value; } } for(int j=0;j & hap_list, const vector & content) { sites.clear(); if((typed_par1==1 || typed_par2==1) && typed_o==1) { int tot = 1<dim==full_dim-1) { for(int i=0;i missing_site; if(typed_par1==1 && typed_par2==1) { int *a_o=M_offspring->get_gcode(); int *a_f=M_par1->get_gcode(); int *a_m=M_par2->get_gcode(); for(int i=0;iget_gcode(); int *a_f=M_par1->get_gcode(); for(int i=0;i0 && missing_site.size() hcom_hinc; if(hap_list.size()==0 || hap_list.size()==tot) { int *hcode = new int[size]; memset(hcode,0,size*sizeof(int)); vector *vec=complete_missing_haplotype(hcode,0); for(int i=0;iclear(); delete vec; } else { int hap_num = content.size(); for(int i=0;i e_map; int loc=0; map::iterator iter = hcom_hinc.begin(); while(iter!=hcom_hinc.end()) { int h_part = iter->second; if(e_map.find(h_part)==e_map.end()) e_map[h_part] = loc; loc++; iter++; } loc=0; iter = e_map.begin(); while(loc!=e_map.size()-1) { sites.push_back(iter->second); iter++; loc++; } } missing_site.clear(); } } else { for(int i=0;idim;i++) sites.push_back(M_offspring->sites[i]); } } vector *Missingtrio::complete_missing_haplotype(int *hcode, int index) { int code = hcode[index]; if(index==size-1) { vector *vec = new vector(); if(code==-1) { int *a1 = new int[size]; memset(a1,0,size*sizeof(int)); a1[size-1] = code; vec->push_back(a1); } else if(code==0) { int *a1 = new int[size]; int *a2 = new int[size]; memset(a1,0,size*sizeof(int)); memset(a2,0,size*sizeof(int)); a1[size-1]=0; a2[size-1]=1; vec->push_back(a1); vec->push_back(a2); } return vec; } vector *vec = complete_missing_haplotype(hcode,index+1); int pos = index; if(code==-1) { for(int i=0;isize();i++) (*vec)[i][pos] = code; return vec; } // else if code == 0 int vsize = vec->size(); for(int i=0;ipush_back(a1); } return vec; } void Missingtrio::show_gstat() // print trio genotype patten { printf("\nOffspring has genotype patten: "); int *a=M_offspring->get_gcode(); for(int i=0;iget_gcode(); for(int i=0;iget_gcode(); for(int i=0;i0) { for(int i=0;i & hap_freq_table, double *freq, map, double> & geno_freq_table, map, int> & hap_pair_map, int **count){ for(int i=0;iexpected_hap_num(hap_freq_table,freq,geno_freq_table,hap_pair_map,count,sites); } // calculate E(Z-h|event) void Missingtrio::cond_par1_one(double **result, map & hap_freq_table, map, double> & geno_freq_table, map & hap_map){ // result is of dim*h_size int row = hap_freq_table.size(); double *matrix1 = new double[row]; memset(matrix1,0,row*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_father.first==hp_father.second) matrix1[hap_map[hp_father.first]] += hap_freq_table[hp_father.first]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); else{ matrix1[hap_map[hp_father.first]] += hap_freq_table[hp_father.second]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]] += hap_freq_table[hp_father.first]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; if(hp_father.first==hp_father.second) matrix1[hap_map[hp_father.first]] += hap_freq_table[hp_father.first]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); else{ matrix1[hap_map[hp_father.first]] += hap_freq_table[hp_father.second]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]] += hap_freq_table[hp_father.first]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map){ // result is of dim*g_size int col = geno_freq_table.size(); double *matrix1 = new double[col]; memset(matrix1,0,col*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_father]] += geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; matrix1[hap_pair_map[hp_father]] += transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map & hap_map){ // result is of dim*h_size int row = hap_freq_table.size(); double *matrix1 = new double[row]; memset(matrix1,0,row*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_mother.first==hp_mother.second) matrix1[hap_map[hp_mother.first]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); else{ matrix1[hap_map[hp_mother.first]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_mother.second]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec_complete(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_mother.first==hp_mother.second) matrix1[hap_map[hp_mother.first]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); else{ matrix1[hap_map[hp_mother.first]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_mother.second]] += geno_freq_table[hp_father]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map){ // result is of dim*g_size int col = geno_freq_table.size(); double *matrix1 = new double[col]; memset(matrix1,0,col*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_mother]] += geno_freq_table[hp_father]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec_complete(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_mother]] += geno_freq_table[hp_father]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map & hap_map){ // result is of dim*h_size int row = hap_freq_table.size(); double *matrix1 = new double[row]; memset(matrix1,0,row*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_offspring.first==hp_offspring.second) matrix1[hap_map[hp_offspring.first]] += geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1)/hap_freq_table[hp_offspring.first]; else{ matrix1[hap_map[hp_offspring.first]] += geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1)/(2.0*hap_freq_table[hp_offspring.first]); matrix1[hap_map[hp_offspring.second]] += geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1)/(2.0*hap_freq_table[hp_offspring.second]); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; if(hp_offspring.first==hp_offspring.second) matrix1[hap_map[hp_offspring.first]] += geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1)/hap_freq_table[hp_offspring.first]; else{ matrix1[hap_map[hp_offspring.first]] += geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1)/(2.0*hap_freq_table[hp_offspring.first]); matrix1[hap_map[hp_offspring.second]] += geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1)/(2.0*hap_freq_table[hp_offspring.second]); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; if(hp_offspring.first==hp_offspring.second) matrix1[hap_map[hp_offspring.first]] += hap_freq_table[hp_offspring.first]; else{ matrix1[hap_map[hp_offspring.first]] += hap_freq_table[hp_offspring.second]; matrix1[hap_map[hp_offspring.second]] += hap_freq_table[hp_offspring.first]; } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map){ // result is of dim*g_size int col = geno_freq_table.size(); double *matrix1 = new double[col]; memset(matrix1,0,col*sizeof(double)); if(typed_par1==1 && typed_par2==1) { for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_offspring]] += geno_freq_table[hp_father]*geno_freq_table[hp_mother]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1)/geno_freq_table[hp_offspring]; } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; matrix1[hap_pair_map[hp_offspring]] += geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1)/geno_freq_table[hp_offspring]; } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; matrix1[hap_pair_map[hp_offspring]] += 1; } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map & hap_map){ // result is of dim*h_size*h_size int row = hap_freq_table.size(); double **matrix1 = new double*[row]; for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_father.first==hp_father.second && hp_mother.first==hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first==hp_father.second && hp_mother.first!=hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.first]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first!=hp_father.second && hp_mother.first==hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first!=hp_father.second && hp_mother.first!=hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.first]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec_complete(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; if(hp_father.first==hp_father.second && hp_mother.first==hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first==hp_father.second && hp_mother.first!=hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.first]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first!=hp_father.second && hp_mother.first==hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } else if(hp_father.first!=hp_father.second && hp_mother.first!=hp_mother.second){ matrix1[hap_map[hp_father.first]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.first]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.second]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.first]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.second]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); matrix1[hap_map[hp_father.second]][hap_map[hp_mother.second]] += hap_freq_table[hp_father.first]*hap_freq_table[hp_mother.first]*transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j & hap_freq_table, map, double> & geno_freq_table, map, int> & hap_pair_map){ // for sibs // result is of dim*g_size*g_size int col = geno_freq_table.size(); double **matrix1 = new double*[col]; for(int i=0;i iv = missing_pat_trio_genotype[i]->get_inh_vec(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_father]][hap_pair_map[hp_mother]] += transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j iv = missing_pat_trio_genotype[i]->get_inh_vec_complete(); if(iv.size()>0) { for(int j=0;j hp_offspring = iv[j].hp_offspring; pair hp_father = iv[j].hp_par1; pair hp_mother = iv[j].hp_par2; matrix1[hap_pair_map[hp_father]][hap_pair_map[hp_mother]] += transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); } const vector hap_num = missing_pat_trio_genotype[i]->get_hap_num(); for(int j=0;j