Question

So I have a file that looks like so:

#!/usr/bin/python
import MySQLdb
import subprocess
from subprocess import call
import re

conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens')
cursor = conx.cursor()
cursor.execute('select * from sequence')
row = cursor.fetchall()

f = open('/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta', 'w')

for i in row:
    f.write('>'+i[0].strip()+'\n')
    s = re.sub(r'[^\w]','',str(i[1]))
    s = ''.join(s)
    for k in range(0, len(s), 60):
        f.write('%s\n' % (s[k:k+60]))
    f.write('\n')

f.close()

subprocess.call(['formatdb', '-p', 'T', '-i', r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])

The file runs no problem from the command line but when I try and run it with crontab I get this error:

  File "/home/rv/ncbi-blast-2.2.23+/db/formatdb.py", line 29, in <module>
    subprocess.call(['formatdb', '-p', 'T', '-i',
r'/home/rv/ncbi-blast-2.2.23+/db/vdatabase.fasta'])
OSError: [Errno 2] No such file or directory

I don't understand, the file exist in that directory, I've double and triple checked. I tried converting the file path to a raw string hence the lower case "r" before the path but that didn't do it either.

Was it helpful?

Solution

I suspect it's complaining about the path to "formatdb" in your subprocess call. Try changing that to the full path:

subprocess.call(['/home/path/formatdb', ...])

OTHER TIPS

The cron daemon usually provides only a very limited PATH. Either put a more complete PATH in the crontab or use the full pathname in the Python code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top