'USAGE message in BLAST search with python

I am trying to filter a blast web search through the taxids of Bacteria and Achaea, this is my code:

from Bio.Blast.Applications import NcbiblastnCommandline
blastn_command = NcbiblastnCommandline(query="test.fasta", db="nt", outfmt="'7 qseqid sseqid qcovs qlen slen qstart qend'", out="blastn2.tab",remote=True,entrez_query="txid2157[ORGN] OR txid2[ORGN]")
stdout, stderr = blastn_command()

And I get this error message:

Traceback (most recent call last):
   File "test.py", line 3, in <module>
     stdout, stderr = blastn_command()
   File "/usr/lib/python2.7/dist-packages/Bio/Application/__init__.py", line 517, in __call__
     stdout_str, stderr_str)
Bio.Application.ApplicationError: Non-zero return code 1 from "blastn -out blastn2.tab -outfmt '7 qseqid sseqid qcovs qlen slen qstart qend' -query teste.fasta -db nt -entrez_query txid2157[ORGN] OR txid2[ORGN] -remote", message 'USAGE'


Solution 1:[1]

TLDR

Double quote the entrez_query parameter (same as the outfmt).

The error is most probably caused by the fact, that the entrez_query parameter contain spaces and is not double quoted. As can be seen from the error message blast string, the --entrez_query is passed unquoted to the command-line (compare it with the outfmt, which you have double quoted).

The USAGE message is the first line of the actual error message produced by blastn that further contains following lines:

Error: Too many positional arguments (1), the offending value: OR
Error:  (CArgException::eSynopsis) Too many positional arguments (1), the offending value: OR

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marek Schwarz