【发布时间】:2016-08-31 01:11:59
【问题描述】:
我编写了一个代码来模拟 Wright-Fisher 遗传漂变模型。这意味着 N 个不同个体的原始种群将有无限的后代种群,然后随机选择决定下一代。我想创建一个图表,可以在这些世代中遵循每条线,如下图所示。 Here one particular ancestor's line is highlighted. Any sort of tracking of ancestor lines would be ideal.
谢谢!我在下面提供了我的代码:
Simulates Wright-Fisher model for N different haploid individuals
N <- 10 # Number of individuals
gens <- 40 # Number of generations model will run
init.j <- 1:1:N # Creates vector of initial population lines
p <- 1/N # Frequency of each individual's alleles
# note that two indiv may share same allele but are considered different
p.vector <- rep(p,N) # creates vector of length N with the prob 1/N in each position
p.pick <- cumsum(p.vector)
j=matrix(init.j,N,gens+1) #Creates matrix that will track each individual's progeny line
for(i in 1:gens+1){
for(k in 1:N){
y = runif(1, min=0, max=1)
x <- p.pick - y
b <- min(x[which(x > 0,arr.ind = TRUE)])
j[k,i] = match(b,x)
}
}
J = apply(j, 2, sort) #Sorts each column to align ancestors with next generation which helps for visualization of genealogy
【问题讨论】: