這是由我的教授發佈並由學生修改的羣體遺傳學程序。Python 2.7:L + = branch_length導致NameError:name'L'未定義
基本上它應該用給定的樣本,總體和突變率(u)來模擬20次預期的突變數。然而,關鍵部分是總分支長度(L),它是各種較小分支長度(分支長度)的總和。然而,當我如下定義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"
我只是失去了一些東西真的,真的很明顯?提前致謝。
工作就像一個魅力。我知道這很簡單。 謝謝! – user984748