Learning2programme
Learning2programme

Reputation: 11

NCBIblastPcommandline Errors

I'm trying to automate blast outputs from several files in a directory. Variables here are hardcoded but will be user defined later on. My infiles will be changed via a loop but i'm having issues running NcbiblastpCommandline on the files from within python. Aiming to run blast locally with inputs of several batches of larger fasta files so blast will run sequentially each batch file,output into a tsv where i parse data and pass to clustalw local alignment.

Input_file="minifasta.fasta"
data="uniprot_database"
E_Value_Thresh=1e-10
counter=1
Filename2= 'Batch'+str(counter)
from Bio.Blast.Applications import NcbiblastpCommandline
blast_output_file='blastout.tsv'
NcbiblastpCommandline.outfile=Filename2
from Bio.Blast.Applications import NcbiblastpCommandline
cline = NcbiblastpCommandline(query=Input_file, db=data,outfmt=6, 
out=blast_output_file, evalue= E_Value_Thresh)
print(cline)
stdt, stdr= cline()

I keep receiving an error saying ''NcbiblastpCommandline' object is not iterable.' and i'm being directed to the stdt,stdr line but without stdt,stdr another error saying the command isnt recogised comes up and error messages directing to stdout_str, stderr_str. I cant find up to date examples of NcbiblastpCommandline usage in python 3 to guide me.

Complete error i receive is:

ApplicationError: Non-zero return code 127 from 'blastp -out blastout.tsv -outfmt 6 -query minifasta.fasta -db uniprot_database -evalue 1e-10', message '/bin/sh: blastp: command not found'.

  File "/Users/me/anaconda3/lib/python3.6/site-packages/Bio/Application/__init__.py", line 523, in __call__
    stdout_str, stderr_str)

Upvotes: 1

Views: 1786

Answers (2)

3nrique0
3nrique0

Reputation: 378

I just ran into this problem too. I fixed it by adding the path to the NCBI blast commands into my path, and re-opening python. To add the path to blast into your $PATH do this: export PATH=/path/to/blast:$PATH. Here are some commands which can solve the problem if you don't know how to do all this:

# Find where it is installed and put it in a variable:
# 'command -v blastp' and  'which blastp' will give the same results
path_to_blast=$(dirname $(command -v blastp))
export PATH=$path_to_blast:$PATH

Else you can add it to your ~/.bashrc:

# Put path to executables of blast in a variable
path_to_blast=$(dirname $(command -v blastp))
# Append a comment to the ~/.bashrc
echo -e '\n# Add path to blast executable' >> ~/.bashrc
# Add the export command to update the $PATH.
# Double quotes will allow the inerpretation of the $path_to_blast
echo "export PATH=$path_to_blast:$PATH" >> ~/.bashrc
# Source the ~/.bashrc to update your session
source ~/.bashrc

In both cases, re-open python. This will work without admin privileges.

Upvotes: 1

BioGeek
BioGeek

Reputation: 22847

First run which blastp to find the full path to blastp and give that as argument to NcbiblastpCommandline.

from Bio.Blast.Applications import NcbiblastpCommandline
blastp_path = '/path/to/blastp'
cline = NcbiblastpCommandline(cmd=blastp_path, query=Input_file, db=data,outfmt=6, 
out=blast_output_file, evalue= E_Value_Thresh)

If you now do print(cline) it should print out the full command that is going to be run. Doublecheck that this works by copy/pasting this output and running it from the commandline.

Upvotes: 3

Related Questions