Mercurial > repos > fubar > brokenandnotdeletablebyowneroradmin
comparison rgToolFactory.py @ 19:a87a262220a4
Adding proof of concept for optional output formats.
Updated readme again
author | ross lazarus ross.lazarus@gmail.com |
---|---|
date | Tue, 05 Jun 2012 21:54:58 +1000 |
parents | 8594478e8d2c |
children | 3f58115c6c5b |
comparison
equal
deleted
inserted
replaced
18:943d4f0ee7c1 | 19:a87a262220a4 |
---|---|
1 # rgToolFactory.py | 1 # rgToolFactory.py |
2 # derived from | 2 # https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home |
3 # rgBaseScriptWrapper.py | 3 |
4 # but designed to run arbitrary user supplied code | 4 # this is a tool factory for simple scripts in python, R or whatever ails ye. |
5 # extremely dangerous!! | 5 # you paste and run your script |
6 # trusted users only - private site only | 6 # Only works for simple scripts that read one input from the history. |
7 # a list in the xml is searched for users permitted to run this tool. | 7 # Optionally can write one new history dataset, |
8 # DO NOT install on a public or important site - local instance only | 8 # and optionally collect any number of outputs into links on an autogenerated HTML page. |
9 # generated tools are fine as they just run normally and their user cannot do anything unusually insecure | 9 |
10 # DO NOT install on a public or important site - please. | |
11 | |
12 # installed generated tools are fine if the script is safe. | |
13 # They just run normally and their user cannot do anything unusually insecure | |
14 # but please, practice safe toolshed. | |
15 # Read the fucking code before you install any tool | |
16 # especially this one | |
17 | |
18 # After you get the script working on some test data, you can | |
19 # optionally generate a toolshed compatible gzip file | |
20 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for | |
21 # safe and largely automated installation in a production Galaxy. | |
22 | |
23 # If you opt for an HTML output, you get all the script outputs arranged | |
24 # as a single Html history item - all output files are linked, thumbnails for all the pdfs. | |
25 # Ugly but really inexpensive. | |
26 # | |
27 # Patches appreciated please. | |
10 # | 28 # |
11 # copyright ross lazarus (ross.lazarus@gmail.com) May 2012 | 29 # |
30 # long route to June 2012 product | |
31 # Behold the awesome power of Galaxy and the toolshed with the tool factory binds to bind them | |
32 # derived from an integrated script model | |
33 # called rgBaseScriptWrapper.py | |
34 # Note to the unwary: | |
35 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user | |
36 # There is nothing stopping a malicious user doing whatever they choose | |
37 # Extremely dangerous!! | |
38 # Totally insecure. So, trusted users only | |
39 # | |
40 # preferred model is a developer using their throw away workstation instance - ie a private site. | |
41 # no real risk. | |
42 # a list in the xml source file is searched for users permitted to run this tool. | |
43 # PUT some IDs in the list in the XML before you restart Galaxy to load this new tool please | |
44 # otherwise, the tool won't run for anybody. | |
45 # | |
46 | |
47 # | |
48 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012 | |
12 # | 49 # |
13 # all rights reserved | 50 # all rights reserved |
14 # Licensed under the LGPL for your pleasure | 51 # Licensed under the LGPL if you want to improve it, feel free https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home |
15 # Derived from rgDGE.py in May 2012 | |
16 # generalized to run required interpreter | |
17 # to make your own tools based on a given script and interpreter such as perl or python | |
18 # clone this and the corresponding xml wrapper | |
19 # replace the parameters/inputs/outputs and the configfile contents with your script | |
20 # Use the $foo syntax to place your parameter values inside the script to assign them - at run time, the script will be used as a template | |
21 # and returned as part of the output to the user - with the right values for all the parameters. | |
22 # Note that this assumes you want all the outputs arranged as a single Html file output | |
23 # after this generic script runner runs your script with the specified interpreter, | |
24 # it will collect all output files into the specified output_html, making thumbnails for all the pdfs it finds and making links for all the other files. | |
25 | 52 |
26 import sys | 53 import sys |
27 import shutil | 54 import shutil |
28 import subprocess | 55 import subprocess |
29 import os | 56 import os |
50 """class is a wrapper for an arbitrary script | 77 """class is a wrapper for an arbitrary script |
51 """ | 78 """ |
52 | 79 |
53 def __init__(self,opts=None): | 80 def __init__(self,opts=None): |
54 """ | 81 """ |
55 run the script | 82 cleanup inputs, setup some outputs |
56 | 83 |
57 """ | 84 """ |
58 if opts.output_dir: # simplify for the tool tarball | 85 if opts.output_dir: # simplify for the tool tarball |
59 os.chdir(opts.output_dir) | 86 os.chdir(opts.output_dir) |
60 self.thumbformat = 'jpg' | 87 self.thumbformat = 'jpg' |
91 | 118 |
92 | 119 |
93 def makeXML(self): | 120 def makeXML(self): |
94 """ | 121 """ |
95 Create a Galaxy xml tool wrapper for the new script as a string to write out | 122 Create a Galaxy xml tool wrapper for the new script as a string to write out |
96 fixme - use templating or something less fugly than this. | 123 fixme - use templating or something less fugly than this example of what we produce |
97 Here's an example of what we produce | |
98 | 124 |
99 <tool id="reverse" name="reverse" version="0.01"> | 125 <tool id="reverse" name="reverse" version="0.01"> |
100 <description>a tabular file</description> | 126 <description>a tabular file</description> |
101 <command interpreter="python"> | 127 <command interpreter="python"> |
102 reverse.py --script_path "$runMe" --interpreter "python" | 128 reverse.py --script_path "$runMe" --interpreter "python" |
291 <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> | 317 <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> |
292 </head> | 318 </head> |
293 <body> | 319 <body> |
294 <div class="document"> | 320 <div class="document"> |
295 """ | 321 """ |
296 galhtmlattr = """<hr/><b><a href="http://rgenetics.org">Galaxy Tool Factory Script Wrapper</a> tool output %s run at %s</b><br/>""" | 322 galhtmlattr = """<hr/><b><a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory Script Wrapper</a> tool output %s run at %s</b><br/>""" |
297 galhtmlpostfix = """</div></body></html>\n""" | 323 galhtmlpostfix = """</div></body></html>\n""" |
298 | 324 |
299 flist = os.listdir(self.opts.output_dir) | 325 flist = os.listdir(self.opts.output_dir) |
300 flist = [x for x in flist if x <> 'Rplots.pdf'] | 326 flist = [x for x in flist if x <> 'Rplots.pdf'] |
301 flist.sort() | 327 flist.sort() |
377 a('--make_HTML',default=None) | 403 a('--make_HTML',default=None) |
378 a('--help_text',default=None) | 404 a('--help_text',default=None) |
379 a('--tool_desc',default=None) | 405 a('--tool_desc',default=None) |
380 a('--new_tool',default=None) | 406 a('--new_tool',default=None) |
381 opts, args = op.parse_args() | 407 opts, args = op.parse_args() |
382 assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user | 408 assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin to add their ID to %s.xml' % (opts.bad_user,os.path.splitext(self.myname)[0]) |
383 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' | 409 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' |
384 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' | 410 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' |
385 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' | 411 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' |
386 if opts.output_dir: | 412 if opts.output_dir: |
387 try: | 413 try: |