我对使用 python 还很陌生,我喜欢它。但是我被这个问题困住了,我希望你能给我一个关于我所缺少的东西。
我在一个 excel 文件中有一个基因 ID 列表,我正在尝试使用 xrld 和 biopython 来检索序列并将我的结果(以 fasta 格式)保存到文本文档中。到目前为止,我的代码允许我在 shell 中查看结果,但它只将最后一个序列保存在文档中。
这是我的代码:
import xlrd
import re
book = xlrd.open_workbook('ids.xls')
sh = book.sheet_by_index(0)
for rx in range(sh.nrows):
if sh.row(rx)[0].value:
from Bio import Entrez
from Bio import SeqIO
Entrez.email = "mail@xxx.com"
in_handle = Entrez.efetch(db="nucleotide", rettype="fasta", id=sh.row(rx)[0].value)
record = SeqIO.parse(in_handle, "fasta")
for record in SeqIO.parse(in_handle, "fasta"):
print record.format("fasta")
out_handle = open("example.txt", "w")
SeqIO.write(record, out_handle, "fasta")
in_handle.close()
out_handle.close()
正如我所提到的,文件“example.txt”只有最后一个显示外壳的序列(fasta 格式)。
谁能帮我在同一个文档中获取我从 NCBI 检索到的所有序列?
非常感谢
安东尼奥