Blast Results Wont Return
1
3
Entering edit mode
14.5 years ago
Harpal ▴ 30

This isnt my usual way if doing things but because im using Plone it has to be done this way.

The function below takes a variable "x" which is the query sequence. Its is then formatted to a blast-able format and then blasted against the database. When results are retuned the file is empty. Any idea why? I had this working but now its not...

def print_query(x):
    f = open('/home/rv/ncbi-blast-2.2.23+/db/test.txt', 'w')
    f.write(x)
    from subprocess import Popen
    Popen(["formatdb", "-p", "T", "-i", "/home/rv/ncbi-blast-2.2.23+/db/test.txt"])
    Popen(["blastall", "-d", "/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta", "-i", "/home/rv/ncbi-blast-2.2.23+/db/test.txt", "-p", "blastp", "-m", "8", "-e", "0.01", "-o", "/home/rv/ncbi-blast-2.2.23+/db/output.blast"])
    return open('/home/rv/ncbi-blast-2.2.23+/db/output.blast', 'r').read()

P.S. I know im using the outdated BLAST I'm planning on switching when i have this working

python blast • 3.1k views
ADD COMMENT
4
Entering edit mode
14.5 years ago

The culprit is most likely that you are not waiting for the Popen process to finish.

There are several alternatives that you can try, the simplest being:

subprocess.call(*popenargs, **kwargs)

Docs say: Run command with arguments. Wait for command to complete, then return the returncode attribute.

But it is probably best if you first consult the documentation for the subprocess module.

PS: also make sure to close the open filehandle before the Popen call:

f.close()
ADD COMMENT
1
Entering edit mode

There is no need to call sleep explicitly. The subprocess.call() will wait for the process to finish. So would the wait() method on the popen object.

ADD REPLY
1
Entering edit mode

The simplest might be just to add .wait() to the end of the 2 lines that start with "Popen"

ADD REPLY
0
Entering edit mode

Would time.sleep() work?

ADD REPLY

Login before adding your answer.

Traffic: 1499 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6