#include "genotypetrio.h" Genotypetrio::Genotypetrio(Genotype * offspring, Genotype * par1, Genotype * par2, int typed_o, int typed_par1, int typed_par2, int size) { if(size==0) return; this->offspring = offspring; this->par1 = par1; this->par2 = par2; this->typed_o = typed_o; this->typed_par1 = typed_par1; this->typed_par2 = typed_par2; this->size = size; // # of SNPs this->count=0; record_trio_hap_structure(); determin_phase(); } Genotypetrio::Genotypetrio(Genotype * offspring, int typed_o, int typed_par1, int typed_par2, int size) // for founder { if(size==0) return; if(typed_par1==1) printf("Constructor of Genotypetrio for founder fails. Please check\n"); if(typed_par2==1) printf("Constructor of Genotypetrio for founder fails. Please check\n"); this->offspring = offspring; this->typed_o = typed_o; this->typed_par1 = typed_par1; this->typed_par2 = typed_par2; this->size = size; // # of SNPs this->count=0; record_trio_hap_structure(); determin_phase(); } void Genotypetrio::show_gstat() // print trio genotype with its count { printf("\nOffspring has genotype: "); int *a=offspring->get_gcode(); for(int i=0;iget_gcode(); for(int i=0;iget_gcode(); for(int i=0;i & hap) { int h1 = hap.first; for(int j=0;j>j; // get the jth last bit printf("%d", b1); if(j!=size-1) printf("-"); else printf("\n"); } int h2 = hap.second; for(int j=0;j>j; printf("%d", b2); if(j!=size-1) printf("-"); else printf("\n"); } } void Genotypetrio::push_vec(const vector > & hap_vec, int f0, int f1, int m0, int m1, int a, int b) { int min = a<=b ? a : b; int max = a+b-min; if(is_in(hap_vec,min,max)) { inheritance m; m.hp_par1 = pair(f0,f1); m.hp_par2 = pair(m0,m1); m.hp_offspring = pair(min,max); inh_vec.push_back(m); } } void Genotypetrio::push_vec(int f0, int f1, int m0, int m1, int a, int b) { int min = a<=b ? a : b; int max = a+b-min; inheritance m; m.hp_par1 = pair(f0,f1); m.hp_par2 = pair(m0,m1); m.hp_offspring = pair(min,max); inh_vec.push_back(m); } void Genotypetrio::push_vec_complete(const vector > & hap_vec, int f0, int f1, int m0, int m1, int a, int b) { int min = a<=b ? a : b; int max = a+b-min; if(is_in(hap_vec,min,max)) { inheritance m; m.hp_par1 = pair(f0,f1); m.hp_par2 = pair(m0,m1); m.hp_offspring = pair(min,max); inh_vec_complete.push_back(m); } } void Genotypetrio::push_vec_complete(int f0, int f1, int m0, int m1, int a, int b) { int min = a<=b ? a : b; int max = a+b-min; inheritance m; m.hp_par1 = pair(f0,f1); m.hp_par2 = pair(m0,m1); m.hp_offspring = pair(min,max); inh_vec_complete.push_back(m); } void Genotypetrio::record_trio_hap_structure() { if(typed_o==1 && typed_par1==1 && typed_par2==1) { vector > hap_vec_o = offspring->get_hap_vec(); vector > hap_vec_f = par1->get_hap_vec(); vector > hap_vec_m = par2->get_hap_vec(); int f0, f1, m0, m1; for(int i=0;i > hap_vec_f = par1->get_hap_vec(); vector > hap_vec_m = par2->get_hap_vec(); int f0, f1, m0, m1; for(int i=0;i > hap_vec_o = offspring->get_hap_vec(); vector > hap_vec_f = par1->get_hap_vec(); int f0, f1, o0, o1; for(int i=0;i(f0,f1); m.hp_par2 = pair(-1,-1); m.hp_offspring = pair(o0,o1); inh_vec.push_back(m); } } // complete j } // complete i } // parent 1 is typed else if(typed_par1==0 && typed_par2==0) { vector > hap_vec_o = offspring->get_hap_vec(); int o0, o1; for(int i=0;i(-1,-1); m.hp_par2 = pair(-1,-1); m.hp_offspring = pair(o0,o1); inh_vec.push_back(m); } } // both parents are untyped if(inh_vec.size()==0) info = 0; else info = 1; if(typed_o==1 && typed_par1==1 && typed_par2==0) { vector > hap_vec_o = offspring->get_hap_vec(); vector > hap_vec_f = par1->get_hap_vec(); vector > hap_vec_m = par2->get_hap_vec(); int f0, f1, m0, m1; for(int i=0;i > hap_vec_f = par1->get_hap_vec(); vector > hap_vec_m = par2->get_hap_vec(); int f0, f1, m0, m1; for(int i=0;i > hap_vec_o = offspring->get_hap_vec(); if(hap_vec_o.size()==1) phase = 1; else if(hap_vec_o.size()>1) { if(inh_vec.size()==1) phase = 1; else if(inh_vec.size()>1) { int flag = 0; int a0 = (inh_vec[0].hp_offspring).first; int a1 = (inh_vec[0].hp_offspring).second; for(int i=1;i & hap_freq_table, double *freq, map, double> & geno_freq_table, map, int> & hap_pair_map, int **count, const vector & sites) { hap_num.clear(); int loc; if(inh_vec.size()>0) { if(phase==1) { pair hp_offspring = inh_vec[0].hp_offspring; loc = hap_pair_map[hp_offspring]; for(int j=0;j hp_offspring = inh_vec[j].hp_offspring; pair hp_father = inh_vec[j].hp_par1; pair hp_mother = inh_vec[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); Pi+=value; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) hap_num[k]+=count[sites[k]][loc]*value; } } } else if(typed_par1==1 && typed_par2==0) { for(int j=0;j hp_offspring = inh_vec[j].hp_offspring; pair hp_father = inh_vec[j].hp_par1; value = geno_freq_table[hp_father]*transProbonep(hp_offspring,hp_father,hap_freq_table,geno_freq_table,1); Pi+=value; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) hap_num[k]+=count[sites[k]][loc]*value; } } } else if(typed_par1==0 && typed_par2==0) { for(int j=0;j hp_offspring = inh_vec[j].hp_offspring; Pi+=geno_freq_table[hp_offspring]; loc = hap_pair_map[hp_offspring]; for(int k=0;k0) hap_num[k]+=count[sites[k]][loc]*geno_freq_table[hp_offspring]; } } } for(int j=0;j > & hap_vec, int o1, int o2) { for(int i=0;i