diff tools/blast2go/blast2go.py @ 10:8664c4c94764 draft default tip

v0.0.11 - Assorted packaging updates (overdue upload)
author peterjc
date Tue, 06 Dec 2022 16:29:50 +0000
parents 887adf823bc0
children
line wrap: on
line diff
--- a/tools/blast2go/blast2go.py	Tue Dec 06 16:26:16 2022 +0000
+++ b/tools/blast2go/blast2go.py	Tue Dec 06 16:29:50 2022 +0000
@@ -26,9 +26,11 @@
 This script is under version control here:
 https://github.com/peterjc/galaxy_blast/tree/master/blast2go
 """
-import sys
+from __future__ import print_function
+
 import os
 import subprocess
+import sys
 
 # You may need to edit this to match your local setup,
 blast2go_dir = os.environ.get("B2G4PIPE", "/opt/b2g4pipe_v2.5/")
@@ -41,7 +43,10 @@
     sys.exit("Missing sister file massage_xml_for_blast2go.py")
 
 if len(sys.argv) != 4:
-    sys.exit("Require three arguments: XML filename, properties filename, output tabular filename")
+    sys.exit(
+        "Require three arguments: XML filename, "
+        "properties filename, output tabular filename"
+    )
 
 xml_file, prop_file, tabular_file = sys.argv[1:]
 
@@ -65,11 +70,14 @@
 
 
 def run(cmd):
+    """Run the given command line string via subprocess."""
     # Avoid using shell=True when we call subprocess to ensure if the Python
     # script is killed, so too is the child process.
     try:
-        child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    except Exception, err:
+        child = subprocess.Popen(
+            cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
+        )
+    except Exception as err:
         sys.exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
     stdout, stderr = child.communicate()
     return_code = child.returncode
@@ -91,7 +99,7 @@
         error_msg = "No sequences processed!"
 
     if error_msg:
-        print error_msg
+        print(error_msg)
         sys.exit(error_msg)
 
 
@@ -105,14 +113,21 @@
 # We will have write access wherever the output should be,
 # so we'll ask Blast2GO to use that as the stem for its output
 # (it will append .annot to the filename)
-cmd = ["java", "-cp", blast2go_classpath, "es.blast2go.prog.B2GAnnotPipe",
-       "-in", tmp_xml_file,
-       "-prop", prop_file,
-       "-out", tabular_file,  # Used as base name for output files
-       "-annot",  # Generate *.annot tabular file
-       # NOTE: For v2.3.5 must use -a, for v2.5 must use -annot instead
-       # "-img", # Generate images, feature not in v2.3.5
-       ]
+cmd = [
+    "java",
+    "-cp",
+    blast2go_classpath,
+    "es.blast2go.prog.B2GAnnotPipe",
+    "-in",
+    tmp_xml_file,
+    "-prop",
+    prop_file,
+    "-out",
+    tabular_file,  # Used as base name for output files
+    "-annot",  # Generate *.annot tabular file
+    # NOTE: For v2.3.5 must use -a, for v2.5 must use -annot instead
+    # "-img", # Generate images, feature not in v2.3.5
+]
 # print " ".join(cmd)
 run(cmd)
 
@@ -126,4 +141,4 @@
 # Move the output file where Galaxy expects it to be:
 os.rename(out_file, tabular_file)
 
-print "Done"
+print("Done")