如何使用Biopython将多个序列上传到BLAST?

如何使用Biopython将多个序列上传到BLAST?,python,sequences,biopython,fasta,blast,Python,Sequences,Biopython,Fasta,Blast,我正在尝试从单个FASTA文件中运行多个序列的BLASTN搜索。我可以很容易地从一个文件中查询一个序列,但我很难在一个文件中查询所有序列。由于这些是相对较短的读取,我不希望将文件拆分为单独的序列,并分别查询每个序列 这就是我迄今为止所尝试的: from Bio import SeqIO from Bio.Blast import NCBIWWW f_iterator = SeqIO.parse("file.fasta", "fasta") f_record = f_iterator.next(

我正在尝试从单个FASTA文件中运行多个序列的BLASTN搜索。我可以很容易地从一个文件中查询一个序列,但我很难在一个文件中查询所有序列。由于这些是相对较短的读取,我不希望将文件拆分为单独的序列,并分别查询每个序列

这就是我迄今为止所尝试的:

from Bio import SeqIO
from Bio.Blast import NCBIWWW

f_iterator = SeqIO.parse("file.fasta", "fasta")
f_record = f_iterator.next()
result_handle = NCBIWWW.qblast("blastn", "nt", f_record)
save_result = open("blast_result.xml", "w")
save_result.write(result_handle.read())
save_result.close()
result_handle.close()

有人有什么想法吗?

难道你不能简单地给出一个多序列文件的全部内容(直接从文件中读取)而不是单个记录吗

来自Bio.Blast导入NCBIWWW
打开(“file.fasta”、“r”)作为fasta\u文件:
sequences=fasta_file.read()
fasta_file.close()
结果_handle=NCBIWWW.qblast(“blastn”,“nt”,序列)
save_result=open(“blast_result.xml”、“w”)
保存\u result.write(result\u handle.read())
保存结果。关闭()
结果_handle.close()

如果您的文件已经是FASTA格式,您可以使用open/read。这是直接摘自Biopython食谱

我一直在运行这样一个简单的脚本:

from Bio.Blast import NCBIWWW

fasta_string = open("file.fasta").read()

result_handle = qblast(
"blastn",
"nt",
fasta_string,
)
save_file = open("out.xml", "w")

save_file.write(result_handle.read())

save_file.close()

result_handle.close()
如果这不起作用,请检查以确保您的FASTA格式正确。这里有一个转换器


@mikhael-很明显,你是对的,但我没有代表对此发表评论,所以我想我会根据你的答案来做。
from Bio.Blast import NCBIWWW

fasta_string = open("file.fasta").read()

result_handle = qblast(
"blastn",
"nt",
fasta_string,
)
save_file = open("out.xml", "w")

save_file.write(result_handle.read())

save_file.close()

result_handle.close()