试图计算具有固定gc含量(10%,20%,30%,...,90%)的随机RNA序列的平均转录本长度
def bias_rna(gc_content):
rna = 'AUG'
stop_codon = ['UAG','UAA','UGA']
while rna[-3:] not in stop_codon:
for _ in range(3):
rna += random.choice(('A'+'U')*(100-(gc_content))+('C'+'G')*(gc_content))
return rna
for numb in [range(10,91,10)]:
rna2_list = []
for _ in range(1001):
rna2_list.append(bias_rna(numb))
rna2_len = []
for s in rna2_list:
rna2_len.append(len(s))
print ('Average random rna length with cg: %.2f' % (sum(rna_len)/(len(rna_len))))
然而,该计划没有工作......建议?
答案 0 :(得分:0)
我做了一些小修改,虽然我不知道关于DNA的事情,但似乎有效:
import random
def bias_rna(gc_content):
rna = 'AUG'
stop_codon = ['UAG','UAA','UGA']
while rna[-3:] not in stop_codon:
for _ in range(3):
rna += random.choice(('A'+'U')*(100-(gc_content))+('C'+'G')*(gc_content))
return rna
for numb in range(10,91,10):
rna2_list = []
for _ in range(1001):
rna2_list.append(bias_rna(numb))
rna2_len = []
for s in rna2_list:
rna2_len.append(len(s))
print ('Average random rna length with cg: %.2f' % (sum(rna2_len)/(len(rna2_len))))
基本上,你需要
random
range(10,91,10)
周围的括号(这导致您循环遍历包含单个range
对象的列表,而不是范围本身的内容)rna_len
重命名为rna2_len
,在行动here中查看。