annotate rgedgeR/rgToolFactory.py @ 6:cd586457aced draft

Uploaded
author fubar
date Sat, 27 Jul 2013 01:07:52 -0400
parents 2122e630b13a
children 372ce0323554
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
1 # rgToolFactory.py
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
2 # see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
3 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
5 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
6 # all rights reserved
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
7 # Licensed under the LGPL
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
9 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
10 # july 2013
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
11 # added ability to combine images and individual log files into html output
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
12 # just make sure there's a log file foo.log and it will be output
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
13 # together with all images named like "foo_*.pdf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
14 # otherwise old format for html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
15 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
16 # January 2013
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
17 # problem pointed out by Carlos Borroto
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
18 # added escaping for <>$ - thought I did that ages ago...
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
19 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
20 # August 11 2012
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
21 # changed to use shell=False and cl as a sequence
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
22
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
23 # This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
24 # It also serves as the wrapper for the new tool.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
25 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
26 # you paste and run your script
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
27 # Only works for simple scripts that read one input from the history.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
28 # Optionally can write one new history dataset,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
29 # and optionally collect any number of outputs into links on an autogenerated HTML page.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
30
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
31 # DO NOT install on a public or important site - please.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
32
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
33 # installed generated tools are fine if the script is safe.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
34 # They just run normally and their user cannot do anything unusually insecure
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
35 # but please, practice safe toolshed.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
36 # Read the fucking code before you install any tool
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
37 # especially this one
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
38
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
39 # After you get the script working on some test data, you can
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
40 # optionally generate a toolshed compatible gzip file
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
41 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
42 # safe and largely automated installation in a production Galaxy.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
43
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
44 # If you opt for an HTML output, you get all the script outputs arranged
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
45 # as a single Html history item - all output files are linked, thumbnails for all the pdfs.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
46 # Ugly but really inexpensive.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
47 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
48 # Patches appreciated please.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
49 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
50 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
51 # long route to June 2012 product
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
52 # Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
53 # derived from an integrated script model
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
54 # called rgBaseScriptWrapper.py
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
55 # Note to the unwary:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
56 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
57 # There is nothing stopping a malicious user doing whatever they choose
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
58 # Extremely dangerous!!
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
59 # Totally insecure. So, trusted users only
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
60 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
61 # preferred model is a developer using their throw away workstation instance - ie a private site.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
62 # no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
63 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
64
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
65 import sys
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
66 import shutil
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
67 import subprocess
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
68 import os
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
69 import time
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
70 import tempfile
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
71 import optparse
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
72 import tarfile
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
73 import re
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
74 import shutil
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
75 import math
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
76
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
77 progname = os.path.split(sys.argv[0])[1]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
78 myversion = 'V000.2 June 2012'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
79 verbose = False
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
80 debug = False
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
81 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
82
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
83 def timenow():
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
84 """return current time as a string
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
85 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
86 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
87
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
88 html_escape_table = {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
89 "&": "&amp;",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
90 ">": "&gt;",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
91 "<": "&lt;",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
92 "$": "\$"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
93 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
94
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
95 def html_escape(text):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
96 """Produce entities within text."""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
97 return "".join(html_escape_table.get(c,c) for c in text)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
98
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
99 def cmd_exists(cmd):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
100 return subprocess.call("type " + cmd, shell=True,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
101 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
102
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
103
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
104 class ScriptRunner:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
105 """class is a wrapper for an arbitrary script
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
106 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
107
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
108 def __init__(self,opts=None,treatbashSpecial=True):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
109 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
110 cleanup inputs, setup some outputs
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
111
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
112 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
113 self.useGM = cmd_exists('gm')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
114 self.useIM = cmd_exists('convert')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
115 self.useGS = cmd_exists('gs')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
116 self.treatbashSpecial = treatbashSpecial
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
117 if opts.output_dir: # simplify for the tool tarball
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
118 os.chdir(opts.output_dir)
6
cd586457aced Uploaded
fubar
parents: 0
diff changeset
119 self.thumbformat = 'png'
0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
120 self.opts = opts
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
121 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but..
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
122 self.toolid = self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
123 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
124 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
125 self.xmlfile = '%s.xml' % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
126 s = open(self.opts.script_path,'r').readlines()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
127 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
128 self.script = '\n'.join(s)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
129 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
130 tscript = open(self.sfile,'w') # use self.sfile as script source for Popen
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
131 tscript.write(self.script)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
132 tscript.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
133 self.indentedScript = '\n'.join([' %s' % x for x in s]) # for restructured text in help
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
134 self.escapedScript = '\n'.join([html_escape(x) for x in s])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
135 if opts.output_dir: # may not want these complexities
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
136 self.tlog = os.path.join(self.opts.output_dir,"%s_runner.log" % self.toolname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
137 art = '%s.%s' % (self.toolname,opts.interpreter)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
138 artpath = os.path.join(self.opts.output_dir,art) # need full path
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
139 artifact = open(artpath,'w') # use self.sfile as script source for Popen
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
140 artifact.write(self.script)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
141 artifact.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
142 self.cl = []
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
143 self.html = []
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
144 a = self.cl.append
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
145 a(opts.interpreter)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
146 if self.treatbashSpecial and opts.interpreter in ['bash','sh']:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
147 a(self.sfile)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
148 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
149 a('-') # stdin
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
150 a(opts.input_tab)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
151 a(opts.output_tab)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
152 self.outFormats = 'tabular' # TODO make this an option at tool generation time
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
153 self.inputFormats = 'tabular' # TODO make this an option at tool generation time
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
154 self.test1Input = '%s_test1_input.xls' % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
155 self.test1Output = '%s_test1_output.xls' % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
156 self.test1HTML = '%s_test1_output.html' % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
157
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
158 def makeXML(self):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
159 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
160 Create a Galaxy xml tool wrapper for the new script as a string to write out
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
161 fixme - use templating or something less fugly than this example of what we produce
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
162
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
163 <tool id="reverse" name="reverse" version="0.01">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
164 <description>a tabular file</description>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
165 <command interpreter="python">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
166 reverse.py --script_path "$runMe" --interpreter "python"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
167 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
168 </command>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
169 <inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
170 <param name="input1" type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
171
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
172 </inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
173 <outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
174 <data format="tabular" name="tab_file" label="${job_name}"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
175
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
176 </outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
177 <help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
178
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
179 **What it Does**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
180
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
181 Reverse the columns in a tabular file
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
182
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
183 </help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
184 <configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
185 <configfile name="runMe">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
186
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
187 # reverse order of columns in a tabular file
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
188 import sys
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
189 inp = sys.argv[1]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
190 outp = sys.argv[2]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
191 i = open(inp,'r')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
192 o = open(outp,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
193 for row in i:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
194 rs = row.rstrip().split('\t')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
195 rs.reverse()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
196 o.write('\t'.join(rs))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
197 o.write('\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
198 i.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
199 o.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
200
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
201
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
202 </configfile>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
203 </configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
204 </tool>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
205
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
206 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
207 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="%(tool_version)s">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
208 %(tooldesc)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
209 %(command)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
210 <inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
211 %(inputs)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
212 </inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
213 <outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
214 %(outputs)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
215 </outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
216 <configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
217 <configfile name="runMe">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
218 %(script)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
219 </configfile>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
220 </configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
221 %(tooltests)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
222 <help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
223 %(help)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
224 </help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
225 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
226
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
227 newCommand="""<command interpreter="python">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
228 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
229 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
230 </command>""" # may NOT be an input or htmlout
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
231 tooltestsTabOnly = """<tests><test>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
232 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
233 <param name="job_name" value="test1"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
234 <param name="runMe" value="$runMe"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
235 <output name="tab_file" file="%(test1Output)s" ftype="tabular"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
236 </test></tests>"""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
237 tooltestsHTMLOnly = """<tests><test>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
238 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
239 <param name="job_name" value="test1"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
240 <param name="runMe" value="$runMe"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
241 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="5"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
242 </test></tests>"""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
243 tooltestsBoth = """<tests><test>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
244 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
245 <param name="job_name" value="test1"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
246 <param name="runMe" value="$runMe"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
247 <output name="tab_file" file="%(test1Output)s" ftype="tabular" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
248 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="10"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
249 </test></tests>"""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
250 xdict = {}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
251 xdict['tool_version'] = self.opts.tool_version
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
252 xdict['test1Input'] = self.test1Input
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
253 xdict['test1HTML'] = self.test1HTML
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
254 xdict['test1Output'] = self.test1Output
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
255 if self.opts.make_HTML and self.opts.output_tab <> 'None':
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
256 xdict['tooltests'] = tooltestsBoth % xdict
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
257 elif self.opts.make_HTML:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
258 xdict['tooltests'] = tooltestsHTMLOnly % xdict
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
259 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
260 xdict['tooltests'] = tooltestsTabOnly % xdict
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
261 xdict['script'] = self.escapedScript
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
262 # configfile is least painful way to embed script to avoid external dependencies
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
263 # but requires escaping of <, > and $ to avoid Mako parsing
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
264 if self.opts.help_text:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
265 xdict['help'] = open(self.opts.help_text,'r').read()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
266 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
267 xdict['help'] = 'Please ask the tool author for help as none was supplied at tool generation'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
268 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
269 coda.append(self.indentedScript)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
270 coda.append('**Attribution** This Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.' % (self.opts.user_email,timenow()))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
271 coda.append('See %s for details of that project' % (toolFactoryURL))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
272 coda.append('Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team. ')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
273 coda.append('Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
274 xdict['help'] = '%s\n%s' % (xdict['help'],'\n'.join(coda))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
275 if self.opts.tool_desc:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
276 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
277 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
278 xdict['tooldesc'] = ''
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
279 xdict['command_outputs'] = ''
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
280 xdict['outputs'] = ''
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
281 if self.opts.input_tab <> 'None':
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
282 xdict['command_inputs'] = '--input_tab "$input1" ' # the space may matter a lot if we append something
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
283 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/> \n' % self.inputFormats
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
284 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
285 xdict['command_inputs'] = '' # assume no input - eg a random data generator
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
286 xdict['inputs'] = ''
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
287 xdict['inputs'] += '<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="%s"/> \n' % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
288 xdict['toolname'] = self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
289 xdict['toolid'] = self.toolid
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
290 xdict['interpreter'] = self.opts.interpreter
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
291 xdict['scriptname'] = self.sfile
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
292 if self.opts.make_HTML:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
293 xdict['command_outputs'] += ' --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes" '
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
294 xdict['outputs'] += ' <data format="html" name="html_file" label="${job_name}.html"/>\n'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
295 if self.opts.output_tab <> 'None':
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
296 xdict['command_outputs'] += ' --output_tab "$tab_file"'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
297 xdict['outputs'] += ' <data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
298 xdict['command'] = newCommand % xdict
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
299 xmls = newXML % xdict
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
300 xf = open(self.xmlfile,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
301 xf.write(xmls)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
302 xf.write('\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
303 xf.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
304 # ready for the tarball
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
305
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
306
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
307 def makeTooltar(self):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
308 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
309 a tool is a gz tarball with eg
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
310 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ...
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
311 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
312 retval = self.run()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
313 if retval:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
314 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
315 sys.exit(1)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
316 self.makeXML()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
317 tdir = self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
318 os.mkdir(tdir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
319 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe..
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
320 testdir = os.path.join(tdir,'test-data')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
321 os.mkdir(testdir) # make tests directory
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
322 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
323 if self.opts.output_tab <> 'None':
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
324 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
325 if self.opts.make_HTML:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
326 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
327 if self.opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
328 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log'))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
329 op = '%s.py' % self.toolname # new name
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
330 outpiname = os.path.join(tdir,op) # path for the tool tarball
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
331 pyin = os.path.basename(self.pyfile) # our name - we rewrite ourselves (TM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
332 notes = ['# %s - a self annotated version of %s generated by running %s\n' % (op,pyin,pyin),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
333 notes.append('# to make a new Galaxy tool called %s\n' % self.toolname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
334 notes.append('# User %s at %s\n' % (self.opts.user_email,timenow()))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
335 pi = open(self.pyfile,'r').readlines() # our code becomes new tool wrapper (!) - first Galaxy worm
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
336 notes += pi
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
337 outpi = open(outpiname,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
338 outpi.write(''.join(notes))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
339 outpi.write('\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
340 outpi.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
341 stname = os.path.join(tdir,self.sfile)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
342 if not os.path.exists(stname):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
343 shutil.copyfile(self.sfile, stname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
344 xtname = os.path.join(tdir,self.xmlfile)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
345 if not os.path.exists(xtname):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
346 shutil.copyfile(self.xmlfile,xtname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
347 tarpath = "%s.gz" % self.toolname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
348 tar = tarfile.open(tarpath, "w:gz")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
349 tar.add(tdir,arcname=self.toolname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
350 tar.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
351 shutil.copyfile(tarpath,self.opts.new_tool)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
352 shutil.rmtree(tdir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
353 ## TODO: replace with optional direct upload to local toolshed?
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
354 return retval
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
355
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
356
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
357 def compressPDF(self,inpdf=None,thumbformat='png'):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
358 """need absolute path to pdf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
359 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
360 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
361 hf,hlog = tempfile.mkstemp(suffix="%s.log" % self.toolname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
362 sto = open(hlog,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
363 outpdf = '%s_compressed' % inpdf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
364 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dBATCH","-dPDFSETTINGS=/printer", "-sOutputFile=%s" % outpdf,inpdf]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
365 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
366 retval1 = x.wait()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
367 if retval1 == 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
368 os.unlink(inpdf)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
369 shutil.move(outpdf,inpdf)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
370 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
371 if self.useGM:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
372 cl2 = ['gm convert', inpdf, outpng]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
373 else: # assume imagemagick
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
374 cl2 = ['convert', inpdf, outpng]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
375 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
376 retval2 = x.wait()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
377 sto.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
378 retval = retval1 or retval2
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
379 return retval
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
380
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
381
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
382 def getfSize(self,fpath,outpath):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
383 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
384 format a nice file size string
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
385 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
386 size = ''
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
387 fp = os.path.join(outpath,fpath)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
388 if os.path.isfile(fp):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
389 size = '0 B'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
390 n = float(os.path.getsize(fp))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
391 if n > 2**20:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
392 size = '%1.1f MB' % (n/2**20)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
393 elif n > 2**10:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
394 size = '%1.1f KB' % (n/2**10)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
395 elif n > 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
396 size = '%d B' % (int(n))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
397 return size
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
398
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
399 def makeHtml(self):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
400 """ Create an HTML file content to list all the artifacts found in the output_dir
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
401 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
402
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
403 galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
404 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
405 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
406 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
407 <title></title>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
408 <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
409 </head>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
410 <body>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
411 <div class="toolFormBody">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
412 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
413 galhtmlattr = """<hr/><div class="infomessage">This tool (%s) was generated by the <a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory</a></div><br/>"""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
414 galhtmlpostfix = """</div></body></html>\n"""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
415
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
416 flist = os.listdir(self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
417 flist = [x for x in flist if x <> 'Rplots.pdf']
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
418 flist.sort()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
419 html = []
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
420 html.append(galhtmlprefix % progname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
421 html.append('<div class="infomessage">Galaxy Tool "%s" run at %s</div><br/>' % (self.toolname,timenow()))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
422 fhtml = []
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
423 if len(flist) > 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
424 logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
425 logfiles.sort()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
426 logfiles = [x for x in logfiles if os.path.abspath(x) <> os.path.abspath(self.tlog)]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
427 logfiles.append(os.path.abspath(self.tlog)) # make it the last one
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
428 pdflist = []
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
429 npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf'])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
430 for rownum,fname in enumerate(flist):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
431 dname,e = os.path.splitext(fname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
432 sfsize = self.getfSize(fname,self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
433 if e.lower() == '.pdf' : # compress and make a thumbnail
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
434 thumb = '%s.%s' % (dname,self.thumbformat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
435 pdff = os.path.join(self.opts.output_dir,fname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
436 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
437 if retval == 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
438 pdflist.append((fname,thumb))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
439 if (rownum+1) % 2 == 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
440 fhtml.append('<tr class="odd_row"><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
441 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
442 fhtml.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
443 for logfname in logfiles: # expect at least tlog - if more
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
444 if os.path.abspath(logfname) == os.path.abspath(self.tlog): # handled later
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
445 sectionname = 'All tool run'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
446 if (len(logfiles) > 1):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
447 sectionname = 'Other'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
448 ourpdfs = pdflist
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
449 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
450 realname = os.path.basename(logfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
451 sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
452 ourpdfs = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] == sectionname]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
453 pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] <> sectionname] # remove
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
454 nacross = 1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
455 npdf = len(ourpdfs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
456
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
457 if npdf > 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
458 nacross = math.sqrt(npdf) ## int(round(math.log(npdf,2)))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
459 if int(nacross)**2 != npdf:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
460 nacross += 1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
461 nacross = int(nacross)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
462 width = min(400,int(1200/nacross))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
463 html.append('<div class="toolFormTitle">%s images and outputs</div>' % sectionname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
464 html.append('(Click on a thumbnail image to download the corresponding original PDF image)<br/>')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
465 ntogo = nacross # counter for table row padding with empty cells
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
466 html.append('<div><table class="simple" cellpadding="2" cellspacing="2">\n<tr>')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
467 for i,paths in enumerate(ourpdfs):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
468 fname,thumb = paths
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
469 s= """<td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="5" width="%d"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
470 alt="Image called %s"/></a></td>\n""" % (fname,thumb,fname,width,fname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
471 if ((i+1) % nacross == 0):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
472 s += '</tr>\n'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
473 ntogo = 0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
474 if i < (npdf - 1): # more to come
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
475 s += '<tr>'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
476 ntogo = nacross
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
477 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
478 ntogo -= 1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
479 html.append(s)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
480 if html[-1].strip().endswith('</tr>'):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
481 html.append('</table></div>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
482 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
483 if ntogo > 0: # pad
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
484 html.append('<td>&nbsp;</td>'*ntogo)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
485 html.append('</tr></table></div>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
486 logt = open(logfname,'r').readlines()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
487 logtext = [x for x in logt if x.strip() > '']
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
488 html.append('<div class="toolFormTitle">%s log output</div>' % sectionname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
489 if len(logtext) > 1:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
490 html.append('\n<pre>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
491 html += logtext
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
492 html.append('\n</pre>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
493 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
494 html.append('%s is empty<br/>' % logfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
495 if len(fhtml) > 0:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
496 fhtml.insert(0,'<div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
497 fhtml.append('</table></div><br/>')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
498 html.append('<div class="toolFormTitle">All output files available for downloading</div>\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
499 html += fhtml # add all non-pdf files to the end of the display
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
500 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
501 html.append('<div class="warningmessagelarge">### Error - %s returned no files - please confirm that parameters are sane</div>' % self.opts.interpreter)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
502 html.append(galhtmlpostfix)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
503 htmlf = file(self.opts.output_html,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
504 htmlf.write('\n'.join(html))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
505 htmlf.write('\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
506 htmlf.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
507 self.html = html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
508
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
509
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
510 def run(self):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
511 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
512 scripts must be small enough not to fill the pipe!
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
513 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
514 if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
515 retval = self.runBash()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
516 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
517 if self.opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
518 sto = open(self.tlog,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
519 sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
520 sto.flush()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
521 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
522 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
523 p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
524 p.stdin.write(self.script)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
525 p.stdin.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
526 retval = p.wait()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
527 if self.opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
528 sto.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
529 if self.opts.make_HTML:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
530 self.makeHtml()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
531 return retval
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
532
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
533 def runBash(self):
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
534 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
535 cannot use - for bash so use self.sfile
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
536 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
537 if self.opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
538 s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
539 sto = open(self.tlog,'w')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
540 sto.write(s)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
541 sto.flush()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
542 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
543 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
544 p = subprocess.Popen(self.cl,shell=False)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
545 retval = p.wait()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
546 if self.opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
547 sto.close()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
548 if self.opts.make_HTML:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
549 self.makeHtml()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
550 return retval
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
551
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
552
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
553 def main():
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
554 u = """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
555 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
556 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
557 </command>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
558 """
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
559 op = optparse.OptionParser()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
560 a = op.add_option
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
561 a('--script_path',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
562 a('--tool_name',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
563 a('--interpreter',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
564 a('--output_dir',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
565 a('--output_html',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
566 a('--input_tab',default="None")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
567 a('--output_tab',default="None")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
568 a('--user_email',default='Unknown')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
569 a('--bad_user',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
570 a('--make_Tool',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
571 a('--make_HTML',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
572 a('--help_text',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
573 a('--tool_desc',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
574 a('--new_tool',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
575 a('--tool_version',default=None)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
576 opts, args = op.parse_args()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
577 assert not opts.bad_user,'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user,opts.bad_user)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
578 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
579 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
580 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R'
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
581 if opts.output_dir:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
582 try:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
583 os.makedirs(opts.output_dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
584 except:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
585 pass
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
586 r = ScriptRunner(opts)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
587 if opts.make_Tool:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
588 retcode = r.makeTooltar()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
589 else:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
590 retcode = r.run()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
591 os.unlink(r.sfile)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
592 if retcode:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
593 sys.exit(retcode) # indicate failure to job runner
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
594
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
595
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
596 if __name__ == "__main__":
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
597 main()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
598
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
599