modified: myjupyterlab.sh
[GalaxyCodeBases.git] / tools / simulators / popudepth / maf.r
blobc7339b1d7fac0609a33e21cb525fb6d402512aa0
1 # generate genotype for each individual
2 genotype=function(nsample,MAF) { # nsample为多少个个体,MAF为一维数组,存储所有SNP位点的MAF值
3 nsite=length(MAF)
4 a=array(runif(nsite*nsample*2,0,1),dim=c(nsite,2*nsample))
5 b=a
6 # generate genotype for each allele
7 for (i in 1:nsite){
8 for (j in 1:(2*nsample)){
9 if (a[i,j]>MAF[i]) { b[i,j] = 0 }
10 else { b[i,j] = 1 }
13 # generate genotype for each individual: 00->0;11->3;01->1,10->2
14 c=array(dim=c(nsite,nsample+2))
15 for (i in 1:nsite){
16 c[i,1] = i # site ID
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]
21 return (c)
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))