これは、私の教授が配布し、学生が修正した集団遺伝学プログラムです。
基本的に、特定のサンプル、母集団、および突然変異率 (u) で、予想される突然変異数を 20 回シミュレートすることになっています。ただし、重要な部分は、枝の長さの合計 (L) です。これは、さまざまな短い枝の長さ (branch_length) の合計です。ただし、L を以下のように定義すると、エラーが返され続けます。
L += branch_length
NameError: name 'L' is not defined
tree_depth は同じように定義されており、問題なく動作するため、何が問題なのかわかりません。
完全なコードは次のとおりです。
from random import expovariate
from pgen import poidev
K = 77 # sample size (number of gene copies)
twoN = 5000 # population size
u = .001
tree_depth = 0.0 # age of last common ancestor in generations
# Each pass through loop deals with one coalescent interval.
for A in range(20):
while K > 1:
h = K*(K-1)/(2.0*twoN) # hazard of a coalescent event
t = expovariate(h) # time until next coalescent event
tree_depth += t
branch_length = t*K
K -= 1
L += branch_length
S = poidev(u*L)
print "Simulation:", A+1, "Total Mutations:", S
print "Total tree depth (L):", L, "generations"
本当に、本当に明らかな何かが欠けているだけですか?前もって感謝します。