我写了一个代码来模拟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
答案 0 :(得分:0)
看起来你想要一个多树:
https://en.wikipedia.org/wiki/Multitree
我发现的只有multiTree:
http://psycho3.uni-mannheim.de/Home/Research/Software/multiTree/
有R代码与此接口:
http://www.ncbi.nlm.nih.gov/pubmed/20160285
但是,看起来这个包不在CRAN上,摘要中引用的网站不再存在。