Hi, I want to run some blast locally. I have some queries and a lot of fasta files that would be my databases. But I need to convert from fasta to "database" format. I know how to do it with commandline (makeblastdb), but they are several fasta files, so I want to write a script and do it with (bio)python. I have been looking how to do it, but I haven't find out how. Can any one help me, please? Thanks!
2 answers
just use shell as @genomax2 suggested;
Put your fasta files you want to make into dbs into a dir:
for file in *.fasta; do /path/to/blast_install/bin/makeblastdb -in $file -dbtype prot/nucl; done
if you need to use python:
#!/usr/bin/env python
import glob, subprocess
for file in glob.glob("*.fasta"):
subprocess.call("/path/to/blast_install/bin/makeblastdb -in " + file + " -db type prot/nucl", shell=True)
I agree with this being a much better idea through a standard shell script but if you're adamant about doing it through python (perhaps incorporating it as part of a much longer and more complicated pipeline), you need to do something like this:
Use the subprocess module:
import subprocess
blastdb_cmd = 'makeblastdb -in {0} -dbtype nucl -title temp_blastdb'.format(fasta)
DB_process = subprocess.Popen(blastdb_cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
DB_process.wait()
This is taken from my script here if you want to 'see it in action'.
Log in to answer this question.
While you could use biopython, why not do that using a simple shell script?
Using BioPython to
makeblastdba bunch of files is neither a smart learning process nor an efficient way to actually get your task done. Why use anything but the shell?Thanks for your answers!
Do not add an answer unless you're answering the question. This should be a comment reply. I'm moving it to a comment on the top level post now.
Well, I know I'm preety late for the topc conversation but. If you're up to UNIX, or to any other system that you can install BLAST local.
Instead of using bioblast or any other module, you'll simply call the os to run in the background of the shell. If found this a little bit more efficient than using bioblast/biopython, however in terms of speed I can't say if it's faster or not. Hope it helps