gpt4 book ai didi

bioinformatics - 是否可以将字符串变量而不是文件传递给 BLAST 搜索?

转载 作者:行者123 更新时间:2023-12-04 06:36:58 24 4
gpt4 key购买 nike

我正在编写一个 python 脚本,并希望将查询序列信息作为字符串变量而不是 FASTA 格式文件(如果可能)传递给 blastn。

我使用 Biopython 的 SeqIO 将多个转录名称存储为键,并将其序列存储为关联值。

所以它看起来像这样

transcripts = dict()
for record in SeqIO.parse("transcript_sequences.fasta", "fasta"):
transcripts[record.name] = record.seq

print transcripts

所以字典看起来像这样
{'var_F': Seq('CTTCATTCTCGTTTAGCGGCTGCTCGTGGAAATTTCGAAAAAATCTGAAACTAG...TGC', SingleLetterAlphabet())}

现在我想将字典中的序列信息解析成爆炸查询和主题。
subprocess.call("blastn -query " + transcript['var_F'] + ".txt" + " -subject " + transcript['var_B'] + " -outfmt 6 > tmp_blast.txt", shell=True)  

我知道 blast 只接受文件位置的文件名或字符串,但我只是想知道是否有解决方法。

提前感谢您阅读我的第一个问题:P

最佳答案

来自 BLAST 的 BioPython 模块:

http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc90

看来您是正确的,因为 biopython BLAST 不支持 SeqIO 对象或生物序列作为 BLAST 函数调用的参数,或者您使用 subprocess.call() 执行。 BLAST 二进制文件。唯一接受的输入序列参数是文件名。从教程:

>>> 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,并在文件 my_blast.xml 中有 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

关于bioinformatics - 是否可以将字符串变量而不是文件传递给 BLAST 搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40404450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com