0
|
1 # WARNING before you start
|
|
2 # Install this tool for test purposes only
|
|
3 # Please NEVER on a public or production instance
|
|
4 # updated august 8 2014 to fix bugs reported by Marius van den Beek
|
|
5
|
|
6 Please report bugs concerning Docker to m.vandenbeek at gmail . com
|
|
7 or at https://bitbucket.org/mvdbeek/dockertoolfactory.
|
|
8
|
|
9
|
|
10 *Installation instructions*
|
|
11
|
|
12 This is a fork of toolfactory that makes use of Docker to sandbox the generated script.
|
|
13 As such you need to have the system user under which galaxy tools are executed be able to run Docker. On Ubuntu you can do this by
|
|
14 adding your galaxy user to the docker group (http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo).
|
|
15 Here is the short form for installing Docker from the official docker Ubuntu Trusty repository:
|
|
16
|
|
17 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
|
|
18 sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
|
|
19 sudo apt-get update
|
|
20 sudo apt-get install lxc-docker
|
|
21 sudo gpasswd -a galaxy docker
|
|
22 sudo service docker restart
|
|
23
|
|
24 Eventually the galaxy process might need ot be restarted.
|
|
25
|
|
26 Note that this could bring severe security problems in case untrusted users can become this user.
|
|
27 If you want to use this tool, read and understand the following article:
|
|
28 https://docs.docker.com/articles/security/#docker-daemon-attack-surface
|
|
29
|
|
30 Work is ongoing, some important features are missing, like being able to manage containers and
|
|
31 to limit resource useage.
|
|
32
|
|
33 This is an alpha-stage, potentially dangerous tool.
|
|
34
|
|
35
|
|
36 Please cite:
|
|
37 http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
|
|
38 if you use this tool in your published work.
|
|
39
|
|
40 *Short Story*
|
|
41
|
|
42 This is an unusual Galaxy tool that exposes unrestricted and therefore extremely dangerous
|
|
43 scripting to designated administrative users of a Galaxy server, allowing them to run scripts
|
|
44 in R, python, sh and perl over a single input data set, writing a single new data set as output.
|
|
45
|
|
46 In addition, this tool optionally generates very simple new Galaxy tools, that effectively
|
|
47 freeze the supplied script into a new, ordinary Galaxy tool that runs it over one or more input files,
|
|
48 working just like any other Galaxy tool for your users.
|
|
49
|
|
50 To use the ToolFactory, you should have prepared a script to paste into a text box,
|
|
51 and a small test input example ready to select from your history to test your new script.
|
|
52 There is an example in each scripting language on the Tool Factory form. You can just
|
|
53 cut and paste these to try it out - remember to select the right interpreter please. You'll
|
|
54 also need to create a small test data set using the Galaxy history add new data tool.
|
|
55
|
|
56 If the script fails somehow, use the "redo" button on the tool output in your history to
|
|
57 recreate the form complete with broken script. Fix the bug and execute again. Rinse, wash, repeat.
|
|
58
|
|
59 Once the script runs sucessfully, a new Galaxy tool that runs your script can be generated.
|
|
60 Select the "generate" option and supply some help text and names. The new tool will be
|
|
61 generated in the form of a new Galaxy datatype - toolshed.gz - as the name suggests,
|
|
62 it's an archive ready to upload to a Galaxy ToolShed as a new tool repository.
|
|
63
|
|
64 Once it's in a ToolShed, it can be installed into any local Galaxy server from
|
|
65 the server administrative interface.
|
|
66
|
|
67 Once the new tool is installed, local users can run it - each time, the script that was supplied
|
|
68 when it was built will be executed with the input chosen from the user's history. In other words,
|
|
69 the tools you generate with the ToolFactory run just like any other Galaxy tool,
|
|
70 but run your script every time.
|
|
71
|
|
72 Tool factory tools are perfect for workflow components. One input, one output, no variables.
|
|
73
|
|
74 *Reasons to read further*
|
|
75
|
|
76 If you use Galaxy to support your research;
|
|
77
|
|
78 You and fellow users are sometimes forced to take data out of Galaxy, process it with ugly
|
|
79 little perl/awk/sed/R... scripts and put it back;
|
|
80
|
|
81 You do this when you can't do some transformation in Galaxy (the 90/10 rule);
|
|
82
|
|
83 You don't have enough developer resources for wrapping dozens of even relatively simple tools;
|
|
84
|
|
85 Your research and your institution would be far better off if those feral scripts were all tucked
|
|
86 safely in your local toolshed and Galaxy histories.
|
|
87
|
|
88 *The good news* If it can be trivially scripted, it can be running safely in your
|
|
89 local Galaxy via your own local toolshed in a few minutes - with functional tests.
|
|
90
|
|
91
|
|
92 *Value proposition* The ToolFactory allows Galaxy to efficiently take over most of your lab's
|
|
93 dark script matter, making it reproducible in Galaxy and shareable through the ToolShed.
|
|
94
|
|
95 That's what this tool does. You paste a simple script and the tool returns
|
|
96 a new, real Galaxy tool, ready to be installed from the local toolshed to local servers.
|
|
97 Scripts can be wrapped and online literally within minutes.
|
|
98
|
|
99 *To fully and safely exploit the awesome power* of this tool, Galaxy and the ToolShed,
|
|
100 you should be a developer installing this tool on a private/personal/scratch local instance where you
|
|
101 are an admin_user. Then, if you break it, you get to keep all the pieces
|
|
102 see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
|
|
103
|
|
104 ** Installation **
|
|
105 This is a Galaxy tool. You can install it most conveniently using the administrative "Search and browse tool sheds" link.
|
|
106 Find the Galaxy Test toolshed (not main) and search for the toolfactory repository.
|
|
107 Open it and review the code and select the option to install it.
|
|
108
|
|
109 If you can't get the tool that way, the xml and py files here need to be copied into a new tools
|
|
110 subdirectory such as tools/toolfactory Your tool_conf.xml needs a new entry pointing to the xml
|
|
111 file - something like::
|
|
112
|
|
113 <section name="Tool building tools" id="toolbuilders">
|
|
114 <tool file="toolfactory/rgToolFactory.xml"/>
|
|
115 </section>
|
|
116
|
|
117 If not already there (I just added it to datatypes_conf.xml.sample), please add:
|
|
118 <datatype extension="toolshed.gz" type="galaxy.datatypes.binary:Binary" mimetype="multipart/x-gzip" subclass="True" />
|
|
119 to your local data_types_conf.xml.
|
|
120
|
|
121 Ensure that html sanitization is set to False and uncommented in universe_wsgi.ini
|
|
122
|
|
123 You'll have to restart the server for the new tool to be available.
|
|
124
|
|
125 Of course, R, python, perl etc are needed on your path if you want to test scripts using those interpreters.
|
|
126 Adding new ones to this tool code should be easy enough. Please make suggestions as bitbucket issues and code.
|
|
127 The HTML file code automatically shrinks R's bloated pdfs, and depends on ghostscript. The thumbnails require imagemagick .
|
|
128
|
|
129 * Restricted execution *
|
|
130 The new tool factory tool will then be usable ONLY by admin users - people with IDs in admin_users in universe_wsgi.ini
|
|
131 **Yes, that's right. ONLY admin_users can run this tool** Think about it for a moment. If allowed to run any
|
|
132 arbitrary script on your Galaxy server, the only thing that would impede a miscreant bent on destroying all your
|
|
133 Galaxy data would probably be lack of appropriate technical skills.
|
|
134
|
|
135 *What it does* This is a tool factory for simple scripts in python, R and perl currently.
|
|
136 Functional tests are automatically generated. How cool is that.
|
|
137
|
|
138 LIMITED to simple scripts that read one input from the history.
|
|
139 Optionally can write one new history dataset,
|
|
140 and optionally collect any number of outputs into links on an autogenerated HTML
|
|
141 index page for the user to navigate - useful if the script writes images and output files - pdf outputs
|
|
142 are shown as thumbnails and R's bloated pdf's are shrunk with ghostscript so that and imagemagik need to
|
|
143 be avaailable.
|
|
144
|
|
145 Generated tools can be edited and enhanced like any Galaxy tool, so start small and build up since
|
|
146 a generated script gets you a serious leg up to a more complex one.
|
|
147
|
|
148 *What you do* You paste and run your script
|
|
149 you fix the syntax errors and eventually it runs
|
|
150 You can use the redo button and edit the script before
|
|
151 trying to rerun it as you debug - it works pretty well.
|
|
152
|
|
153 Once the script works on some test data, you can
|
|
154 generate a toolshed compatible gzip file
|
|
155 containing your script ready to run as an ordinary Galaxy tool in a
|
|
156 repository on your local toolshed. That means safe and largely automated installation in any
|
|
157 production Galaxy configured to use your toolshed.
|
|
158
|
|
159 *Generated tool Security* Once you install a generated tool, it's just
|
|
160 another tool - assuming the script is safe. They just run normally and their user cannot do anything unusually insecure
|
|
161 but please, practice safe toolshed.
|
|
162 Read the fucking code before you install any tool.
|
|
163 Especially this one - it is really scary.
|
|
164
|
|
165 If you opt for an HTML output, you get all the script outputs arranged
|
|
166 as a single Html history item - all output files are linked, thumbnails for all the pdfs.
|
|
167 Ugly but really inexpensive.
|
|
168
|
|
169 Patches and suggestions welcome as bitbucket issues please?
|
|
170
|
|
171 long route to June 2012 product
|
|
172 derived from an integrated script model
|
|
173 called rgBaseScriptWrapper.py
|
|
174 Note to the unwary:
|
|
175 This tool allows arbitrary scripting on your Galaxy as the Galaxy user
|
|
176 There is nothing stopping a malicious user doing whatever they choose
|
|
177 Extremely dangerous!!
|
|
178 Totally insecure. So, trusted users only
|
|
179
|
|
180
|
|
181
|
|
182
|
|
183 copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
|
|
184
|
|
185 all rights reserved
|
|
186 Licensed under the LGPL if you want to improve it, feel free https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
|
|
187
|
|
188 Material for our more enthusiastic and voracious readers continues below - we salute you.
|
|
189
|
|
190 **Motivation** Simple transformation, filtering or reporting scripts get written, run and lost every day in most busy labs
|
|
191 - even ours where Galaxy is in use. This 'dark script matter' is pervasive and generally not reproducible.
|
|
192
|
|
193 **Benefits** For our group, this allows Galaxy to fill that important dark script gap - all those "small" bioinformatics
|
|
194 tasks. Once a user has a working R (or python or perl) script that does something Galaxy cannot currently do (eg transpose a
|
|
195 tabular file) and takes parameters the way Galaxy supplies them (see example below), they:
|
|
196
|
|
197 1. Install the tool factory on a personal private instance
|
|
198
|
|
199 2. Upload a small test data set
|
|
200
|
|
201 3. Paste the script into the 'script' text box and iteratively run the insecure tool on test data until it works right -
|
|
202 there is absolutely no reason to do this anywhere other than on a personal private instance.
|
|
203
|
|
204 4. Once it works right, set the 'Generate toolshed gzip' option and run it again.
|
|
205
|
|
206 5. A toolshed style gzip appears ready to upload and install like any other Toolshed entry.
|
|
207
|
|
208 6. Upload the new tool to the toolshed
|
|
209
|
|
210 7. Ask the local admin to check the new tool to confirm it's not evil and install it in the local production galaxy
|
|
211
|
|
212 **Simple examples on the tool form**
|
|
213
|
|
214 A simple Rscript "filter" showing how the command line parameters can be handled, takes an input file,
|
|
215 does something (transpose in this case) and writes the results to a new tabular file::
|
|
216
|
|
217 # transpose a tabular input file and write as a tabular output file
|
|
218 ourargs = commandArgs(TRUE)
|
|
219 inf = ourargs[1]
|
|
220 outf = ourargs[2]
|
|
221 inp = read.table(inf,head=F,row.names=NULL,sep='\t')
|
|
222 outp = t(inp)
|
|
223 write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F)
|
|
224
|
|
225 Calculate a multiple test adjusted p value from a column of p values - for this script to be useful,
|
|
226 it needs the right column for the input to be specified in the code for the
|
|
227 given input file type(s) specified when the tool is generated ::
|
|
228
|
|
229 # use p.adjust - assumes a HEADER row and column 1 - please fix for any real use
|
|
230 column = 1 # adjust if necessary for some other kind of input
|
|
231 fdrmeth = 'BH'
|
|
232 ourargs = commandArgs(TRUE)
|
|
233 inf = ourargs[1]
|
|
234 outf = ourargs[2]
|
|
235 inp = read.table(inf,head=T,row.names=NULL,sep='\t')
|
|
236 p = inp[,column]
|
|
237 q = p.adjust(p,method=fdrmeth)
|
|
238 newval = paste(fdrmeth,'p-value',sep='_')
|
|
239 q = data.frame(q)
|
|
240 names(q) = newval
|
|
241 outp = cbind(inp,newval=q)
|
|
242 write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=T)
|
|
243
|
|
244
|
|
245
|
|
246 Another Rscript example without any input file - generates a random heatmap pdf - you must make sure the option to create an HTML output file is
|
|
247 turned on for this to work. The heatmap will be presented as a thumbnail linked to the pdf in the resulting HTML page::
|
|
248
|
|
249 # note this script takes NO input or output because it generates random data
|
|
250 foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100))
|
|
251 bar = as.matrix(foo)
|
|
252 pdf( "heattest.pdf" )
|
|
253 heatmap(bar,main='Random Heatmap')
|
|
254 dev.off()
|
|
255
|
|
256 A Python example that reverses each row of a tabular file. You'll need to remove the leading spaces for this to work if cut
|
|
257 and pasted into the script box. Note that you can already do this in Galaxy by setting up the cut columns tool with the
|
|
258 correct number of columns in reverse order,but this script will work for any number of columns so is completely generic::
|
|
259
|
|
260 # reverse order of columns in a tabular file
|
|
261 import sys
|
|
262 inp = sys.argv[1]
|
|
263 outp = sys.argv[2]
|
|
264 i = open(inp,'r')
|
|
265 o = open(outp,'w')
|
|
266 for row in i:
|
|
267 rs = row.rstrip().split('\t')
|
|
268 rs.reverse()
|
|
269 o.write('\t'.join(rs))
|
|
270 o.write('\n')
|
|
271 i.close()
|
|
272 o.close()
|
|
273
|
|
274
|
|
275 Galaxy as an IDE for developing API scripts
|
|
276 If you need to develop Galaxy API scripts and you like to live dangerously, please read on.
|
|
277
|
|
278 Galaxy as an IDE?
|
|
279 Amazingly enough, blend-lib API scripts run perfectly well *inside* Galaxy when pasted into a Tool Factory form. No need to generate a new tool. Galaxy+Tool_Factory = IDE I think we need a new t-shirt. Seriously, it is actually quite useable.
|
|
280
|
|
281 Why bother - what's wrong with Eclipse
|
|
282 Nothing. But, compared with developing API scripts in the usual way outside Galaxy, you get persistence and other framework benefits plus at absolutely no extra charge, a ginormous security problem if you share the history or any outputs because they contain the api script with key so development servers only please!
|
|
283
|
|
284 Workflow
|
|
285 Fire up the Tool Factory in Galaxy.
|
|
286
|
|
287 Leave the input box empty, set the interpreter to python, paste and run an api script - eg working example (substitute the url and key) below.
|
|
288
|
|
289 It took me a few iterations to develop the example below because I know almost nothing about the API. I started with very simple code from one of the samples and after each run, the (edited..) api script is conveniently recreated using the redo button on the history output item. So each successive version of the developing api script you run is persisted - ready to be edited and rerun easily. It is ''very'' handy to be able to add a line of code to the script and run it, then view the output to (eg) inspect dicts returned by API calls to help move progressively deeper iteratively.
|
|
290
|
|
291 Give the below a whirl on a private clone (install the tool factory from the main toolshed) and try adding complexity with few rerun/edit/rerun cycles.
|
|
292
|
|
293 Eg tool factory api script
|
|
294 import sys
|
|
295 from blend.galaxy import GalaxyInstance
|
|
296 ourGal = 'http://x.x.x.x:xxxx'
|
|
297 ourKey = 'xxx'
|
|
298 gi = GalaxyInstance(ourGal, key=ourKey)
|
|
299 libs = gi.libraries.get_libraries()
|
|
300 res = []
|
|
301 # libs looks like
|
|
302 # u'url': u'/galaxy/api/libraries/441d8112651dc2f3', u'id': u'441d8112651dc2f3', u'name':.... u'Demonstration sample RNA data',
|
|
303 for lib in libs:
|
|
304 res.append('%s:\n' % lib['name'])
|
|
305 res.append(str(gi.libraries.show_library(lib['id'],contents=True)))
|
|
306 outf=open(sys.argv[2],'w')
|
|
307 outf.write('\n'.join(res))
|
|
308 outf.close()
|
|
309
|
|
310 **Attribution**
|
|
311 Creating re-usable tools from scripts: The Galaxy Tool Factory
|
|
312 Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team
|
|
313 Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573
|
|
314
|
|
315 http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
|
|
316
|
|
317 **Licensing**
|
|
318 Copyright Ross Lazarus 2010
|
|
319 ross lazarus at g mail period com
|
|
320
|
|
321 All rights reserved.
|
|
322
|
|
323 Licensed under the LGPL
|
|
324
|
|
325 **Obligatory screenshot**
|
|
326
|
|
327 http://bitbucket.org/fubar/galaxytoolmaker/src/fda8032fe989/images/dynamicScriptTool.png
|