Commits

peterjc committed 17c2a47

Use wrapper script to hide BLAST warnings on stderr (see issue 325)

  • Participants
  • Parent commits c4c2e7d

Comments (0)

Files changed (6)

tools/ncbi_blast_plus/hide_stderr.py

+#!/usr/bin/env python
+"""A simple script to redirect stderr to stdout when the return code is zero.
+
+See https://bitbucket.org/galaxy/galaxy-central/issue/325/
+
+Currently Galaxy ignores the return code from command line tools (even if it
+is non-zero which by convention indicates an error) and treats any output on
+stderr as an error (even though by convention stderr is used for errors or
+warnings).
+
+This script runs the given command line, capturing all stdout and stderr in
+memory, and gets the return code. For a zero return code, any stderr (which
+should be warnings only) is added to the stdout. That way Galaxy believes
+everything is fine. For a non-zero return code, we output stdout as is, and
+any stderr, plus the return code to ensure there is some output on stderr.
+That way Galaxy treats this as an error.
+
+Once issue 325 is fixed, this script will not be needed.
+"""
+import sys
+import subprocess
+
+#Sadly passing the list directly to subprocess didn't seem to work.
+words = []
+for w in sys.argv[1:]:
+    if " " in w:
+        words.append('"%s"' % w)
+    else:
+        words.append(w)
+cmd = " ".join(words)
+child = subprocess.Popen(cmd, shell=True,
+                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+#Use .communicate as can get deadlocks with .wait(),
+stdout, stderr = child.communicate()
+return_code = child.returncode
+
+if return_code:
+    sys.stdout.write(stdout)
+    sys.stderr.write(stderr)
+    sys.stderr.write("Return error code %i from command:\n" % return_code)
+    sys.stderr.write("%s\n" % cmd)
+else:
+    sys.stdout.write(stdout)
+    sys.stdout.write(stderr)

tools/ncbi_blast_plus/ncbi_blastn_wrapper.xml

 <tool id="ncbi_blastn_wrapper" name="NCBI BLAST+ blastn" version="0.0.8">
     <description>Search nucleotide database with nucleotide query sequence(s)</description>
-    <command>
+    <command interpreter="python">hide_stderr.py
 ## The command is a Cheetah template which allows some Python based syntax.
 ## Lines starting hash hash are comments. Galaxy will turn newlines into spaces
 blastn

tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml

 <tool id="ncbi_blastp_wrapper" name="NCBI BLAST+ blastp" version="0.0.8">
     <description>Search protein database with protein query sequence(s)</description>
-    <command>
+    <command interpreter="python">hide_stderr.py
 ## The command is a Cheetah template which allows some Python based syntax.
 ## Lines starting hash hash are comments. Galaxy will turn newlines into spaces
 blastp

tools/ncbi_blast_plus/ncbi_blastx_wrapper.xml

 <tool id="ncbi_blastx_wrapper" name="NCBI BLAST+ blastx" version="0.0.8">
     <description>Search protein database with translated nucleotide query sequence(s)</description>
-    <command>
+    <command interpreter="python">hide_stderr.py
 ## The command is a Cheetah template which allows some Python based syntax.
 ## Lines starting hash hash are comments. Galaxy will turn newlines into spaces
 blastx

tools/ncbi_blast_plus/ncbi_tblastn_wrapper.xml

 <tool id="ncbi_tblastn_wrapper" name="NCBI BLAST+ tblastn" version="0.0.8">
     <description>Search translated nucleotide database with protein query sequence(s)</description>
-    <command>
-## The command is a Cheetah template which allows some Python based syntax.
+    <command interpreter="python">hide_stderr.py
+# The command is a Cheetah template which allows some Python based syntax.
 ## Lines starting hash hash are comments. Galaxy will turn newlines into spaces
 tblastn
 -query "$query"

tools/ncbi_blast_plus/ncbi_tblastx_wrapper.xml

 <tool id="ncbi_tblastx_wrapper" name="NCBI BLAST+ tblastx" version="0.0.8">
     <description>Search translated nucleotide database with translated nucleotide query sequence(s)</description>
-    <command>
+    <command interpreter="python">hide_stderr.py
 ## The command is a Cheetah template which allows some Python based syntax.
 ## Lines starting hash hash are comments. Galaxy will turn newlines into spaces
 tblastx