3

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.

2 Answers 2

5

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', ...])
Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

I've entered the path into the crontab file, I'll try entering the full path in the python file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.