- 6. 家系図の情報を使って、ジェノタイプを作る
- 両親の不明な個人のジェノタイプは、HWEを仮定したMake.Haplotype()関数を使う
- 両親がわかっている個人のジェノタイプは、MakeOffspring()関数を使う
- 親子関係行列を作るときに、子のIDが親のIDより大きいように作ってあるので、親子関係行列の上の行から下の行へと順番にジェノタイプを作っていけばよい
- 順番に処理するときにはループ処理を使う
n.rows<-length(M.cousins[,1])
sim.G<-list()
for(i in 1:n.rows){
tmp.father<-M.cousins[i,1]
tmp.mother<-M.cousins[i,2]
if(tmp.father==0){
father.genotype<-MakeHaplotype(NaS,PaS,2)
}else{
father.genotype<-sim.G[[tmp.father]]
}
if(tmp.mother==0){
mother.genotype<-MakeHaplotype(NaS,PaS,2)
}else{
mother.genotype<-sim.G[[tmp.mother]]
}
sim.G[[i]]<-MakeOffspring(father.genotype,mother.genotype,Dg)
}
sim.G
M.cousins
-
- 親子関係からsim.Gが適切かどうかを目視で確認してみる
- 関数化する
Simulate.Genotype<-function(M,NaS,PaS,Dg){
n.rows<-length(M.cousins[,1])
sim.G<-list()
for(i in 1:n.rows){
tmp.father<-M.cousins[i,1]
tmp.mother<-M.cousins[i,2]
if(tmp.father==0){
father.genotype<-MakeHaplotype(NaS,PaS,2)
}else{
father.genotype<-sim.G[[tmp.father]]
}
if(tmp.mother==0){
mother.genotype<-MakeHaplotype(NaS,PaS,2)
}else{
mother.genotype<-sim.G[[tmp.mother]]
}
sim.G[[i]]<-MakeOffspring(father.genotype,mother.genotype,Dg)
}
sim.G
}
sim.G<-Simulate.Genotype(M.cousins,NaS,PaS,Dg)
sim.G