1 # generate genotype for each individual
2 genotype
=function(nsample
,MAF
) { # nsample为多少个个体,MAF为一维数组,存储所有SNP位点的MAF值
4 a
=array(runif(nsite
*nsample
*2,0,1),dim
=c(nsite
,2*nsample
))
6 # generate genotype for each allele
8 for (j
in 1:(2*nsample
)){
9 if (a
[i
,j
]>MAF
[i
]) { b
[i
,j
] = 0 }
13 # generate genotype for each individual: 00->0;11->3;01->1,10->2
14 c
=array(dim
=c(nsite
,nsample
+2))
17 c
[i
,2] = MAF
[i
] # MAF value
18 for (j
in seq(from
=1,to
=(2*nsample
),by
=2))
19 c
[i
,(j
+1)/2+2]=b
[i
,j
]*2+b
[i
,j
+1]
24 genotype(5,c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1))
25 genotype(12,c(0,.05,.1,.2,.3,.4,.5))