#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; this->ind_clus=0; this->ind_1df=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; this->ind_clus=0; this->ind_1df=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, int **count, double **rst, double ***drst) { 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]; value = transProb(hp_offspring,hp_father,hp_mother,hap_freq_table,geno_freq_table,1); for(int k=0;k0) { matrix2[l][k]+=count[sites[l]][loc]*value1; matrix4[l][k]+=count[sites[l]][loc]*value2; matrix6[l][k]+=count[sites[l]][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) { 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]; value = transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); for(int k=0;k0) { matrix2[l][k]+=count[sites[l]][loc]*value1; matrix4[l][k]+=count[sites[l]][loc]*value2; matrix6[l][k]+=count[sites[l]][loc]*value3; } } } } for(int j=0;j & hap_freq_table, double **mul_clus, int col_clus){ if(dim>0){ ind_clus = 1; int row = hap_freq_table.size(); derivative_clus = multiply(derivative,dim,row-1,mul_clus,row-1,col_clus); } } void Missingtrio::compute_deriv1to3_cluster(map & hap_freq_table, double **mul_clus, int col_clus){ if(dim>0){ ind_clus = 1; int row = hap_freq_table.size(); deriv1_clus = multiply(deriv1,dim,row-1,mul_clus,row-1,col_clus); deriv2_clus = multiply(deriv2,dim,row-1,mul_clus,row-1,col_clus); deriv3_clus = multiply(deriv3,dim,row-1,mul_clus,row-1,col_clus); } } void Missingtrio::compute_derivative_1df(map & hap_freq_table, double **mul_1df, int col_1df){ if(dim>0){ ind_1df = 1; int row = hap_freq_table.size(); derivative_1df = multiply(derivative,dim,row-1,mul_1df,row-1,col_1df); } } void Missingtrio::compute_deriv1to3_1df(map & hap_freq_table, double **mul_1df, int col_1df){ if(dim>0){ ind_1df = 1; int row = hap_freq_table.size(); deriv1_1df = multiply(deriv1,dim,row-1,mul_1df,row-1,col_1df); deriv2_1df = multiply(deriv2,dim,row-1,mul_1df,row-1,col_1df); deriv3_1df = multiply(deriv3,dim,row-1,mul_1df,row-1,col_1df); } } void Missingtrio::keep(const map & 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]); } */ 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 & s, int m){ for(int i=0;i