【发布时间】:2020-11-11 21:37:17
【问题描述】:
你好,
我正在尝试创建一个 for 循环来读取 DNA 序列列表和 获取所有对的值。这个想法是阅读当前和 下一项用该对的特定值对其进行数学运算,然后 将其附加到最终列表中。
这是一个例子:
AA= 5
AT=6
AC=13
AG=8
CA= 6
TG= 12
...[等]
DNA_seq= [A,A,C,A,T,G]
这 5 对 (AA,AC,CA,AT,TG) 应该给我 42 的值所以,这就是我正在尝试的;我首先定义一个方法来获取下一个 item:
(我知道有一个内置的 next 函数,但它不是 工作)
def nextbase():
next_base= next(base)
return next_base
然后:
AA=5
AT=4
AC=3
AG=2
TA=5
TT=4
TC=3
TG=2
CA=5
CT=4
CC=3
CG=2
GA=5
GT=4
GC=3
GG=2
stacking= []
for strand in dsDNA:
for b in strand:
base= iter(b)
if base =='A':
if nextbase() == 'A':
append.stacking(AA)
elif nextbase() == 'T':
append.stacking(AT)
elif nextbase() == 'C':
append.stacking(AC)
elif nextbase() == 'G':
append.stacking(AG)
elif base=='G':
if nextbase() == 'A':
append.stacking(GA)
elif nextbase() == 'T':
append.stacking(GT)
elif nextbase() == 'C':
append.stacking(GC)
elif nextbase() == 'G':
append.stacking(GG)
elif base=='c':
if nextbase() == 'A':
append.stacking(CA)
elif nextbase() == 'T':
append.stacking(CT)
elif nextbase() == 'C':
print('yes')
append.stacking(CC)
elif nextbase() == 'G':
append.stacking(CG)
elif base=='T':
if nextbase() == 'A':
append.stacking(TA)
elif nextbase() == 'T':
append.stacking(TT)
elif nextbase() == 'C':
append.stacking(TC)
elif nextbase() == 'G':
append.stacking(TG)
else:
print('eror')
print(stacking)
但是它只是不工作它只会打印错误,因为它无法识别任何东西,有谁知道是否有任何有效的方法可以做到这一点? 谢谢!!
【问题讨论】:
标签: python loops iterator next dna-sequence