annotate tools/blast2go/blast2go.py @ 5:e4419efbefad draft

Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
author peterjc
date Fri, 22 Feb 2013 08:47:27 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
1 #!/usr/bin/env python
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
2 """Galaxy wrapper for Blast2GO for pipelines, b2g4pipe v2.5.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
3
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
4 This script takes exactly three command line arguments:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
5 * Input BLAST XML filename
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
6 * Blast2GO properties filename (settings file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
7 * Output tabular filename
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
8
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
9 The properties filename can be a fully qualified path, but if not
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
10 this will look next to the blast2go.jar file.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
11
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
12 Sadly b2g4pipe (at least v2.3.5 to v2.5.0) cannot cope with current
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
13 style large BLAST XML files (e.g. from BLAST 2.2.25+), so we reformat
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
14 these to avoid it crashing with a Java heap space OutOfMemoryError.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
15
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
16 As part of this reformatting, we check for BLASTP or BLASTX output
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
17 (otherwise raise an error), and print the query count.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
18
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
19 It then calls the Java command line tool, and moves the output file to
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
20 the location Galaxy is expecting, and removes the tempory XML file.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
21 """
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
22 import sys
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
23 import os
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
24 import subprocess
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
25
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
26 #You may need to edit this to match your local setup,
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
27 #blast2go_jar = "/opt/b2g4pipe/blast2go.jar"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
28 blast2go_jar = "/opt/b2g4pipe_v2.5/blast2go.jar"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
29
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
30
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
31 def stop_err(msg, error_level=1):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
32 """Print error message to stdout and quit with given error level."""
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
33 sys.stderr.write("%s\n" % msg)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
34 sys.exit(error_level)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
35
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
36 if len(sys.argv) != 4:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
37 stop_err("Require three arguments: XML filename, properties filename, output tabular filename")
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
38
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
39 xml_file, prop_file, tabular_file = sys.argv[1:]
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
40
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
41 #We should have write access here:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
42 tmp_xml_file = tabular_file + ".tmp.xml"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
43
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
44 if not os.path.isfile(blast2go_jar):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
45 stop_err("Blast2GO JAR file not found: %s" % blast2go_jar)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
46
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
47 if not os.path.isfile(xml_file):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
48 stop_err("Input BLAST XML file not found: %s" % xml_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
49
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
50 if not os.path.isfile(prop_file):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
51 tmp = os.path.join(os.path.split(blast2go_jar)[0], prop_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
52 if os.path.isfile(tmp):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
53 #The properties file seems to have been given relative to the JAR
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
54 prop_file = tmp
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
55 else:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
56 stop_err("Blast2GO configuration file not found: %s" % prop_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
57 del tmp
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
58
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
59 def prepare_xml(original_xml, mangled_xml):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
60 """Reformat BLAST XML to suit Blast2GO.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
61
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
62 Blast2GO can't cope with 1000s of <Iteration> tags within a
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
63 single <BlastResult> tag, so instead split this into one
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
64 full XML record per interation (i.e. per query). This gives
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
65 a concatenated XML file mimicing old versions of BLAST.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
66
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
67 This also checks for BLASTP or BLASTX output, and outputs
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
68 the number of queries. Galaxy will show this as "info".
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
69 """
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
70 in_handle = open(original_xml)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
71 footer = " </BlastOutput_iterations>\n</BlastOutput>\n"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
72 header = ""
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
73 while True:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
74 line = in_handle.readline()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
75 if not line:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
76 #No hits?
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
77 stop_err("Problem with XML file?")
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
78 if line.strip() == "<Iteration>":
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
79 break
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
80 header += line
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
81
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
82 if "<BlastOutput_program>blastx</BlastOutput_program>" in header:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
83 print "BLASTX output identified"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
84 elif "<BlastOutput_program>blastp</BlastOutput_program>" in header:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
85 print "BLASTP output identified"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
86 else:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
87 in_handle.close()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
88 stop_err("Expect BLASTP or BLASTX output")
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
89
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
90 out_handle = open(mangled_xml, "w")
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
91 out_handle.write(header)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
92 out_handle.write(line)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
93 count = 1
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
94 while True:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
95 line = in_handle.readline()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
96 if not line:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
97 break
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
98 elif line.strip() == "<Iteration>":
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
99 #Insert footer/header
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
100 out_handle.write(footer)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
101 out_handle.write(header)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
102 count += 1
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
103 out_handle.write(line)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
104
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
105 out_handle.close()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
106 in_handle.close()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
107 print "Input has %i queries" % count
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
108
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
109
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
110 def run(cmd):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
111 #Avoid using shell=True when we call subprocess to ensure if the Python
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
112 #script is killed, so too is the child process.
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
113 try:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
114 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
115 except Exception, err:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
116 stop_err("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
117 #Use .communicate as can get deadlocks with .wait(),
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
118 stdout, stderr = child.communicate()
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
119 return_code = child.returncode
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
120
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
121 #keep stdout minimal as shown prominently in Galaxy
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
122 #Record it in case a silent error needs diagnosis
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
123 if stdout:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
124 sys.stderr.write("Standard out:\n%s\n\n" % stdout)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
125 if stderr:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
126 sys.stderr.write("Standard error:\n%s\n\n" % stderr)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
127
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
128 error_msg = None
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
129 if return_code:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
130 cmd_str = " ".join(cmd)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
131 error_msg = "Return code %i from command:\n%s" % (return_code, cmd_str)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
132 elif "Database or network connection (timeout) error" in stdout+stderr:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
133 error_msg = "Database or network connection (timeout) error"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
134 elif "Annotation of 0 seqs with 0 annots finished." in stdout+stderr:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
135 error_msg = "No sequences processed!"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
136
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
137 if error_msg:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
138 print error_msg
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
139 stop_err(error_msg)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
140
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
141
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
142 blast2go_classpath = os.path.split(blast2go_jar)[0]
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
143 assert os.path.isdir(blast2go_classpath)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
144 blast2go_classpath = "%s/*:%s/ext/*:" % (blast2go_classpath, blast2go_classpath)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
145
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
146 prepare_xml(xml_file, tmp_xml_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
147 #print "XML file prepared for Blast2GO"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
148
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
149 #We will have write access wherever the output should be,
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
150 #so we'll ask Blast2GO to use that as the stem for its output
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
151 #(it will append .annot to the filename)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
152 cmd = ["java", "-cp", blast2go_classpath, "es.blast2go.prog.B2GAnnotPipe",
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
153 "-in", tmp_xml_file,
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
154 "-prop", prop_file,
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
155 "-out", tabular_file, #Used as base name for output files
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
156 "-annot", # Generate *.annot tabular file
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
157 #NOTE: For v2.3.5 must use -a, for v2.5 must use -annot instead
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
158 #"-img", # Generate images, feature not in v2.3.5
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
159 ]
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
160 #print " ".join(cmd)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
161 run(cmd)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
162
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
163 #Remove the temp XML file
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
164 os.remove(tmp_xml_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
165
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
166 out_file = tabular_file + ".annot"
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
167 if not os.path.isfile(out_file):
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
168 stop_err("ERROR - No output annotation file from Blast2GO")
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
169
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
170 #Move the output file where Galaxy expects it to be:
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
171 os.rename(out_file, tabular_file)
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
172
e4419efbefad Uploaded v0.0.6 of wrapper, which now supports b2g4pipe v2.5 (and no longer works with b2g4pipe v2.3.5). See manual install instructions!
peterjc
parents:
diff changeset
173 print "Done"