运行 BLAST (bl2seq) 而不创建序列文件

发布于 2024-08-21 09:33:15 字数 337 浏览 4 评论 0 原文

我有一个执行 BLAST 查询 (bl2seq) 的脚本

该脚本的工作原理如下:

  1. 获取序列a,序列b
  2. 将序列a写入文件a
  3. 将序列b写入文件b
  4. 运行命令“bl2seq -i filea -j fileb -nblastn”
  5. 从 STDOUT 获取输出,解析
  6. 重复 2000 万次

程序bl2seq不支持管道。 有什么方法可以做到这一点并避免写入/读取硬盘?

顺便说一句,我正在使用 Python。

I have a script that performs BLAST queries (bl2seq)

The script works like this:

  1. Get sequence a, sequence b
  2. write sequence a to filea
  3. write sequence b to fileb
  4. run command 'bl2seq -i filea -j fileb -n blastn'
  5. get output from STDOUT, parse
  6. repeat 20 million times

The program bl2seq does not support piping.
Is there any way to do this and avoid writing/reading to the harddrive?

I'm using Python BTW.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

真心难拥有 2024-08-28 09:33:15

根据您运行的操作系统,您可能可以使用类似 的内容bash 的进程替换。我不确定你如何在 Python 中设置它,但你基本上使用命名管道(或命名文件描述符)。如果 bl2seq 尝试在文件中查找,则该方法将不起作用,但如果它只是按顺序读取它们,则应该可以工作。

Depending on what OS you're running on, you may be able to use something like bash's process substitution. I'm not sure how you'd set that up in Python, but you're basically using a named pipe (or named file descriptor). That won't work if bl2seq tries to seek within the files, but it should work if it just reads them sequentially.

秋叶绚丽 2024-08-28 09:33:15

你怎么知道bl2seq不支持管道?顺便说一句,管道是操作系统的一项功能,而不是程序。如果您的 bl2seq 程序输出某些内容,无论是 STDOUT 还是文件,您应该能够解析输出。检查 bl2seq 的帮助文件以获取输出到文件的选项,例如 -o 选项。然后就可以解析该文件了。

另外,由于您使用的是 Python,因此您可以使用 BioPython 模块。

How do you know bl2seq does not support piping.? By the way, pipes is an OS feature, not the program. If your bl2seq program outputs something, whether to STDOUT or to a file, you should be able to parse the output. Check the help file of bl2seq for options to output to file as well, eg -o option. Then you can parse the file.

Also, since you are using Python, an alternative you can use is BioPython module.

沩ん囻菔务 2024-08-28 09:33:15

这是来自 bl2seq 程序吗? ="nofollow noreferrer">BioPerl?如果是这样,您似乎无法对其进行管道处理。不过,您可以使用 Bio::Tools::Run::AnalysisFactory::Pise 编写自己的黑客代码,这是推荐的方法。不过,您必须在 Perl 中执行此操作。

如果这是不同的 bl2seq,则忽略该消息。无论如何,您可能应该提供更多细节。

Is this the bl2seq program from BioPerl? If so, it doesn't look like you can do piping to it. You can, however, code your own hack using Bio::Tools::Run::AnalysisFactory::Pise, which is the recommended way of going about it. You'd have to do it in Perl, though.

If this is a different bl2seq, then disregard the message. In any case, you should probably provide some more detail.

橘亓 2024-08-28 09:33:15

哇。我已经弄清楚了。

答案是使用python的子进程模块和管道!

编辑:忘记提及我正在使用blast2,它确实支持管道。

(这是类的一部分)

def _query(self):
    from subprocess import Popen, PIPE, STDOUT
    pipe = Popen([BLAST,
    '-p', 'blastn',
    '-d', self.database,
    '-m', '8'],
    stdin=PIPE,
    stdout=PIPE)
    pipe.stdin.write('%s\n' % self.sequence)
    print pipe.communicate()[0]

其中 self.database 是包含数据库文件名的字符串,即“nt.fa”
self.sequence 是一个包含查询序列的字符串,

这会将输出打印到屏幕上,但您可以轻松地解析它。没有缓慢的磁盘 I/O。没有缓慢的 XML 解析。我将为此编写一个模块并将其放在 github 上。

另外,我还没有做到这一点,但我认为您可以执行多个查询,这样就不需要为每个查询读取blast数据库并将其加载到RAM中。

Wow. I have it figured out.

The answer is to use python's subprocess module and pipes!

EDIT: forgot to mention that I'm using blast2 which does support piping.

(this is part of a class)

def _query(self):
    from subprocess import Popen, PIPE, STDOUT
    pipe = Popen([BLAST,
    '-p', 'blastn',
    '-d', self.database,
    '-m', '8'],
    stdin=PIPE,
    stdout=PIPE)
    pipe.stdin.write('%s\n' % self.sequence)
    print pipe.communicate()[0]

where self.database is a string containing the database filename, ie 'nt.fa'
self.sequence is a string containing the query sequence

This prints the output to the screen but you can easily just parse it. No slow disk I/O. No slow XML parsing. I'm going to write a module for this and put it on github.

Also, I haven't gotten this far yet but I think you can do multiple queries so that the blast database does not need to be read and loaded into RAM for each query.

独守阴晴ぅ圆缺 2024-08-28 09:33:15

我使用 R 脚本调用blast2:

....
system("mkfifo seq1")
system("mkfifo seq2")
system("echo  sequence1 > seq1"), wait = FALSE)
system("echo  sequence2 > seq2"), wait = FALSE)
system("blast2 -p blastp -i seq1 -j seq2 -m 8", intern = TRUE)
....

与从硬盘驱动器写入和读取相比,这慢了 2 倍(!)!

I call blast2 using R script:

....
system("mkfifo seq1")
system("mkfifo seq2")
system("echo  sequence1 > seq1"), wait = FALSE)
system("echo  sequence2 > seq2"), wait = FALSE)
system("blast2 -p blastp -i seq1 -j seq2 -m 8", intern = TRUE)
....

This is 2 times slower(!) vs. writing and reading from hard drive!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文