Would time.sleep() work?
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
1 answer
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()
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.
The simplest might be just to add .wait() to the end of the 2 lines that start with "Popen"
Log in to answer this question.