来自 BLAST 的 BioPython 模块:
http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc90
您似乎是正确的,因为 biopython BLAST 不支持 SeqIO 对象或生物序列作为 BLAST 函数调用的参数,或者您使用 BLAST 二进制文件的subprocess.call() 执行。唯一接受的输入序列参数是文件名。来自教程:
>>> from Bio.Blast.Applications import NcbiblastxCommandline
>>> help(NcbiblastxCommandline)
...
>>> blastx_cline = NcbiblastxCommandline(query="opuntia.fasta", db="nr", evalue=0.001,
... outfmt=5, out="opuntia.xml")
>>> blastx_cline
NcbiblastxCommandline(cmd='blastx', out='opuntia.xml', outfmt=5, query='opuntia.fasta',
db='nr', evalue=0.001)
>>> print(blastx_cline)
blastx -out opuntia.xml -outfmt 5 -query opuntia.fasta -db nr -evalue 0.001
>>> stdout, stderr = blastx_cline()
因此,您唯一的选择是使用实际的 FASTA 文件作为输入。如果您想一次查询一个序列,则需要将每个序列保存到一个文件中。但是,除非您有理由这样做,否则我建议您不要这样做。如果所有查询序列都在同一个文件中,我认为 BLAST 可能执行得更快。您还可以使用 BioPython 读取生成的 BLAST 输出以迭代每个查询的结果,请参阅:
http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc92
示例取自上述链接:
如果您以其他方式运行 BLAST,并将 BLAST 输出(XML 格式)保存在文件 my_blast.xml 中,您只需打开文件进行读取:
>>> result_handle = open("my_blast.xml")
>>> from Bio.Blast import NCBIXML
>>> blast_record = NCBIXML.read(result_handle)
或者,如果您有很多结果(即,多个查询序列):
>>> from Bio.Blast import NCBIXML
>>> blast_records = NCBIXML.parse(result_handle)
就像 Bio.SeqIO 和 Bio.AlignIO(参见第 5 章和第 6 章)一样,我们有一对输入函数 read 和 parse,其中 read 用于当您只有一个对象时,而 parse 是用于何时的迭代器你可以有很多对象——但我们不是获取 SeqRecord 或 MultipleSeqAlignment 对象,而是获取 BLAST 记录对象。
为了能够处理 BLAST 文件可能很大、包含数千个结果的情况,NCBIXML.parse() 返回一个迭代器。简单来说,迭代器允许您单步执行 BLAST 输出,为每个 BLAST 搜索结果逐一检索 BLAST 记录:
>>> from Bio.Blast import NCBIXML
>>> blast_records = NCBIXML.parse(result_handle)
>>> blast_record = next(blast_records)
# ... do something with blast_record
>>> blast_record = next(blast_records)
# ... do something with blast_record
>>> blast_record = next(blast_records)
# ... do something with blast_record
>>> blast_record = next(blast_records)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
# No further records