我把一个基因组序列分成了不同的基因,我想把它们写在一个文本文件中。我想在每个基因序列之前添加一个标题(基因的名称)。我已经创建了一个基因名称列表,将其添加为标题。它们需要按照列表中给出的顺序添加。这是我尝试过的代码:
with open('output.txt', 'w') as f:
for i in genes:
for rec in i:
for name in Features:
print(">" + name, file = f)
print(rec.seq, file = f)
print("\n", file = f)
break特征是包含基因名称的列表。此代码的输出为:
>Anchored capsid protein:
>C:
>membrane glycoprotein precursor M:
>protein PR:
>M:
>E:
>NSI:
>NS2A:
>NS2B:
>NS3:
>NS4A:
>NS4B:
>NS5:
>
ATGAATA...当它应该是:
>Anchored capsid protein:
ATGAATA...
>C:
ATGAATA...
>membrane protein:
TTCCATT...
>precursor:
TTCCATT...发布于 2020-04-03 17:10:30
如果我理解你的列表结构,这可能行得通:
with open('output.txt', 'w') as f:
for i in genes:
for name, rec in zip(Features, i):
f.write(">{}\n{}\n".format(name, rec.seq))
breakhttps://stackoverflow.com/questions/60987679
复制相似问题