annotate README.md @ 25:9fe74bd23af2 draft

Uploaded
author fubar
date Mon, 02 Mar 2015 05:18:21 -0500
parents
children db35d39e1de9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
1 toolfactory_2
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
2 =============
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
3
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
4 This is an upgrade to the tool factory but with added parameters
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
5 (optionally editable in the generated tool form - otherwise fixed) and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
6 multiple input files.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
7
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
8 Specify any number of parameters - well at
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
9 least up to the limit of your patience with repeat groups.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
10
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
11 Parameter values supplied at tool generation time are defaults and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
12 can be optionally editable by the user - names cannot be changed once
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
13 a tool has been generated.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
14
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
15 If not editable, they act as hidden parameters passed to the script
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
16 and are not editable on the tool form.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
17
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
18 Note! There will be Galaxy default sanitization for all
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
19 user input parameters which your script may need to dance around.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
20
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
21 Any number of input files can be passed to your script, but of course it
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
22 has to deal with them. Both path and metadata name are supplied either in the environment
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
23 (bash/sh) or as command line parameters (python,perl,rscript) that need to be parsed and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
24 dealt with in the script. This is complicated by the common use case of needing file names
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
25 for (eg) column headers, as well as paths. Try the examples are show on the tool factory
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
26 form to see how Galaxy file and user supplied parameter values can be recovered in each
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
27 of the 4 scripting environments supported.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
28
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
29 Best way to deal with multiple outputs is to let the tool factory generate an HTML
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
30 page for your users. It automagically lays out pdf images as thumbnail galleries
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
31 and can have separate results sections gathering all similarly prefixed files, such as
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
32 a Foo section taking text and results from text (foo_whatever.log) and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
33 artifacts (eg foo_MDS_plot.pdf) file names. All artifacts are linked for download.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
34 A copy of the actual script is provided for provenance - be warned, it exposes
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
35 real file paths.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
36
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
37
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
38 tldr;
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
39
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
40 ```
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
41
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
42 # WARNING before you start
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
43 # Install this tool on a private Galaxy ONLY
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
44 # Please NEVER on a public or production instance
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
45 # updated august 2014 by John Chilton adding citation support
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
46 #
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
47 # updated august 8 2014 to fix bugs reported by Marius van den Beek
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
48 # please cite the resource at
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
49 http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
50 # if you use this tool in your published work.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
51
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
52 *Short Story*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
53
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
54 This is an unusual Galaxy tool capable of generating new Galaxy tools.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
55 It works by exposing *unrestricted* and therefore extremely dangerous scripting
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
56 to all designated administrators of the host Galaxy server, allowing them to
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
57 run scripts in R, python, sh and perl over multiple selected input data sets,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
58 writing a single new data set as output.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
59
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
60 *Differences between TF2 and the original Tool Factory*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
61
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
62 1. TF2 (this one) allows any number of either fixed or user-editable parameters to be defined
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
63 for the new tool. If these are editable, the user can change them but otherwise, they are passed
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
64 as fixed and invisible parameters for each execution. Obviously, there are substantial security
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
65 implications with editable parameters, but these are always sanitized by Galaxy's inbuilt
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
66 parameter sanitization so you may need to "unsanitize" characters - eg translate all "__lt__"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
67 into "<" for certain parameters where that is needed. Please practise safe toolshed.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
68
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
69 2. Any number of (the same datatype) of input files may be defined.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
70
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
71 These changes substantially complicate the way your supplied script is supplied with
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
72 all the new and variable parameters. Examples in each scripting language are shown
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
73 in the tool help
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
74
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
75 *Automated outputs in named sections*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
76
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
77 If your script writes to the current directory path, arbitrary mix of (eg)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
78 pdfs, tabular analysis results and run logs,the tool factory can optionally
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
79 auto-generate a linked Html page with separate sections showing a thumbnail
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
80 grid for all pdfs and the log text, grouping all artifacts sharing a file
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
81 name and log name prefix::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
82
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
83 eg: if "foo.log" is emitted then *all* other outputs matching foo_* will
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
84 all be grouped together - eg
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
85 foo_baz.pdf
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
86 foo_bar.pdf and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
87 foo_zot.xls
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
88 would all be displayed and linked in the same section with foo.log's contents
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
89 - to form the "Foo" section of the Html page. Sections appear in alphabetic
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
90 order and there are no limits on the number of files or sections.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
91
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
92 *Automated generation of new Galaxy tools for installation into any Galaxy*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
93
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
94 Once a script is working correctly, this tool optionally generates a
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
95 new Galaxy tool, effectively freezing the supplied script into a new,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
96 ordinary Galaxy tool that runs it over one or more input files selected by
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
97 the user. Generated tools are installed via a tool shed by an administrator
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
98 and work exactly like all other Galaxy tools for your users.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
99
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
100 If you use the Html output option, please ensure that sanitize_all_html is
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
101 set to False and uncommented in universe_wsgi.ini - it should show::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
102
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
103 # By default, all tool output served as 'text/html' will be sanitized
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
104 sanitize_all_html = False
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
105
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
106 This opens potential security risks and may not be acceptable for public
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
107 sites where the lack of stylesheets may make Html pages damage onlookers'
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
108 eyeballs but should still be correct.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
109
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
110
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
111 *More Detail*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
112
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
113 To use the ToolFactory, you should have prepared a script to paste into a
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
114 text box, and a small test input example ready to select from your history
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
115 to test your new script.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
116
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
117 There is an example in each scripting language on the Tool Factory form. You
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
118 can just cut and paste these to try it out - remember to select the right
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
119 interpreter please. You'll also need to create a small test data set using
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
120 the Galaxy history add new data tool.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
121
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
122 If the script fails somehow, use the "redo" button on the tool output in
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
123 your history to recreate the form complete with broken script. Fix the bug
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
124 and execute again. Rinse, wash, repeat.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
125
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
126 Once the script runs sucessfully, a new Galaxy tool that runs your script
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
127 can be generated. Select the "generate" option and supply some help text and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
128 names. The new tool will be generated in the form of a new Galaxy datatype
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
129 - toolshed.gz - as the name suggests, it's an archive ready to upload to a
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
130 Galaxy ToolShed as a new tool repository.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
131
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
132 Once it's in a ToolShed, it can be installed into any local Galaxy server
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
133 from the server administrative interface.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
134
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
135 Once the new tool is installed, local users can run it - each time, the script
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
136 that was supplied when it was built will be executed with the input chosen
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
137 from the user's history. In other words, the tools you generate with the
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
138 ToolFactory run just like any other Galaxy tool,but run your script every time.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
139
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
140 Tool factory tools are perfect for workflow components. One input, one output,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
141 no variables.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
142
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
143 *To fully and safely exploit the awesome power* of this tool,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
144 Galaxy and the ToolShed, you should be a developer installing this
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
145 tool on a private/personal/scratch local instance where you are an
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
146 admin_user. Then, if you break it, you get to keep all the pieces see
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
147 https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
148
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
149 ** Installation **
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
150 This is a Galaxy tool. You can install it most conveniently using the
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
151 administrative "Search and browse tool sheds" link. Find the Galaxy Main
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
152 toolshed at https://toolshed.g2.bx.psu.edu/ and search for the toolfactory
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
153 repository. Open it and review the code and select the option to install it.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
154
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
155 (
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
156 If you can't get the tool that way, the xml and py files here need to be
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
157 copied into a new tools
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
158 subdirectory such as tools/toolfactory Your tool_conf.xml needs a new entry
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
159 pointing to the xml
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
160 file - something like::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
161
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
162 <section name="Tool building tools" id="toolbuilders">
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
163 <tool file="toolfactory/rgToolFactory.xml"/>
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
164 </section>
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
165
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
166 If not already there (I just added it to datatypes_conf.xml.sample),
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
167 please add:
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
168 <datatype extension="toolshed.gz" type="galaxy.datatypes.binary:Binary"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
169 mimetype="multipart/x-gzip" subclass="True" />
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
170 to your local data_types_conf.xml.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
171 )
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
172
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
173 Of course, R, python, perl etc are needed on your path if you want to test
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
174 scripts using those interpreters. Adding new ones to this tool code should
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
175 be easy enough. Please make suggestions as bitbucket issues and code. The
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
176 HTML file code automatically shrinks R's bloated pdfs, and depends on
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
177 ghostscript. The thumbnails require imagemagick .
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
178
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
179 * Restricted execution *
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
180 The tool factory tool itself will then be usable ONLY by admin users -
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
181 people with IDs in admin_users in universe_wsgi.ini **Yes, that's right. ONLY
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
182 admin_users can run this tool** Think about it for a moment. If allowed to
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
183 run any arbitrary script on your Galaxy server, the only thing that would
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
184 impede a miscreant bent on destroying all your Galaxy data would probably
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
185 be lack of appropriate technical skills.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
186
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
187 *What it does* This is a tool factory for simple scripts in python, R and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
188 perl currently. Functional tests are automatically generated. How cool is that.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
189
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
190 LIMITED to simple scripts that read one input from the history. Optionally can
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
191 write one new history dataset, and optionally collect any number of outputs
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
192 into links on an autogenerated HTML index page for the user to navigate -
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
193 useful if the script writes images and output files - pdf outputs are shown
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
194 as thumbnails and R's bloated pdf's are shrunk with ghostscript so that and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
195 imagemagik need to be available.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
196
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
197 Generated tools can be edited and enhanced like any Galaxy tool, so start
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
198 small and build up since a generated script gets you a serious leg up to a
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
199 more complex one.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
200
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
201 *What you do* You paste and run your script, you fix the syntax errors and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
202 eventually it runs. You can use the redo button and edit the script before
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
203 trying to rerun it as you debug - it works pretty well.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
204
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
205 Once the script works on some test data, you can generate a toolshed compatible
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
206 gzip file containing your script ready to run as an ordinary Galaxy tool in
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
207 a repository on your local toolshed. That means safe and largely automated
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
208 installation in any production Galaxy configured to use your toolshed.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
209
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
210 *Generated tool Security* Once you install a generated tool, it's just
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
211 another tool - assuming the script is safe. They just run normally and their
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
212 user cannot do anything unusually insecure but please, practice safe toolshed.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
213 Read the fucking code before you install any tool. Especially this one -
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
214 it is really scary.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
215
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
216 If you opt for an HTML output, you get all the script outputs arranged
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
217 as a single Html history item - all output files are linked, thumbnails for
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
218 all the pdfs. Ugly but really inexpensive.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
219
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
220 Patches and suggestions welcome as bitbucket issues please?
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
221
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
222 copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
223
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
224 all rights reserved
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
225 Licensed under the LGPL if you want to improve it, feel free
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
226 https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
227
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
228 Material for our more enthusiastic and voracious readers continues below -
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
229 we salute you.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
230
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
231 **Motivation** Simple transformation, filtering or reporting scripts get
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
232 written, run and lost every day in most busy labs - even ours where Galaxy is
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
233 in use. This 'dark script matter' is pervasive and generally not reproducible.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
234
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
235 **Benefits** For our group, this allows Galaxy to fill that important dark
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
236 script gap - all those "small" bioinformatics tasks. Once a user has a working
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
237 R (or python or perl) script that does something Galaxy cannot currently do
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
238 (eg transpose a tabular file) and takes parameters the way Galaxy supplies
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
239 them (see example below), they:
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
240
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
241 1. Install the tool factory on a personal private instance
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
242
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
243 2. Upload a small test data set
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
244
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
245 3. Paste the script into the 'script' text box and iteratively run the
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
246 insecure tool on test data until it works right - there is absolutely no
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
247 reason to do this anywhere other than on a personal private instance.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
248
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
249 4. Once it works right, set the 'Generate toolshed gzip' option and run
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
250 it again.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
251
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
252 5. A toolshed style gzip appears ready to upload and install like any other
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
253 Toolshed entry.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
254
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
255 6. Upload the new tool to the toolshed
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
256
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
257 7. Ask the local admin to check the new tool to confirm it's not evil and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
258 install it in the local production galaxy
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
259
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
260
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
261
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
262 **Parameter passing and file inputs**
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
263
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
264 Your script will receive up to 3 named parameters
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
265 INPATHS is a comma separated list of input file paths
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
266 INNAMES is a comma separated list of input file names in the same order
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
267 OUTPATH is optional if a file is being generated, your script should write there
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
268 Your script should open and write files in the provided working directory if you are using the Html
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
269 automatic presentation option.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
270
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
271 Python script command lines will have --INPATHS and --additional_arguments etc. to make it easy to use argparse
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
272
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
273 Rscript will need to use commandArgs(TRUE) - see the example below - additional arguments will
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
274 appear as themselves - eg foo="bar" will mean that foo is defined as "bar" for the script.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
275
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
276 Bash and sh will see any additional parameters on their command lines and the 3 named parameters
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
277 in their environment magically - well, using env on the CL
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
278
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
279 ***python***::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
280
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
281 # argparse for 3 possible comma separated lists
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
282 # additional parameters need to be parsed !
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
283 # then echo parameters to the output file
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
284 import sys
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
285 import argparse
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
286 argp=argparse.ArgumentParser()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
287 argp.add_argument('--INNAMES',default=None)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
288 argp.add_argument('--INPATHS',default=None)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
289 argp.add_argument('--OUTPATH',default=None)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
290 argp.add_argument('--additional_parameters',default=[],action="append")
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
291 argp.add_argument('otherargs', nargs=argparse.REMAINDER)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
292 args = argp.parse_args()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
293 f= open(args.OUTPATH,'w')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
294 s = '### args=%s\n' % str(args)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
295 f.write(s)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
296 s = 'sys.argv=%s\n' % sys.argv
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
297 f.write(s)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
298 f.close()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
299
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
300
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
301
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
302 ***Rscript***::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
303
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
304 # tool factory Rscript parser suggested by Forester
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
305 # http://www.r-bloggers.com/including-arguments-in-r-cmd-batch-mode/
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
306 # additional parameters will appear in the ls() below - they are available
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
307 # to your script
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
308 # echo parameters to the output file
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
309 ourargs = commandArgs(TRUE)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
310 if(length(ourargs)==0){
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
311 print("No arguments supplied.")
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
312 }else{
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
313 for(i in 1:length(ourargs)){
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
314 eval(parse(text=ourargs[[i]]))
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
315 }
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
316 sink(OUTPATH)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
317 cat('INPATHS=',INPATHS,'\n')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
318 cat('INNAMES=',INNAMES,'\n')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
319 cat('OUTPATH=',OUTPATH,'\n')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
320 x=ls()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
321 cat('all objects=',x,'\n')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
322 sink()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
323 }
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
324 sessionInfo()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
325 print.noquote(date())
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
326
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
327
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
328 ***bash/sh***::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
329
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
330 # tool factory sets up these environmental variables
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
331 # this example writes those to the output file
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
332 # additional params appear on command line
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
333 if [ ! -f "$OUTPATH" ] ; then
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
334 touch "$OUTPATH"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
335 fi
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
336 echo "INPATHS=$INPATHS" >> "$OUTPATH"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
337 echo "INNAMES=$INNAMES" >> "$OUTPATH"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
338 echo "OUTPATH=$OUTPATH" >> "$OUTPATH"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
339 echo "CL=$@" >> "$OUTPATH"
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
340
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
341 ***perl***::
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
342
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
343 (my $INPATHS,my $INNAMES,my $OUTPATH ) = @ARGV;
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
344 open(my $fh, '>', $OUTPATH) or die "Could not open file '$OUTPATH' $!";
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
345 print $fh "INPATHS=$INPATHS\n INNAMES=$INNAMES\n OUTPATH=$OUTPATH\n";
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
346 close $fh;
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
347
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
348
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
349
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
350 Galaxy as an IDE for developing API scripts
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
351 If you need to develop Galaxy API scripts and you like to live dangerously,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
352 please read on.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
353
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
354 Galaxy as an IDE?
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
355 Amazingly enough, blend-lib API scripts run perfectly well *inside*
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
356 Galaxy when pasted into a Tool Factory form. No need to generate a new
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
357 tool. Galaxy+Tool_Factory = IDE I think we need a new t-shirt. Seriously,
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
358 it is actually quite useable.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
359
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
360 Why bother - what's wrong with Eclipse
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
361 Nothing. But, compared with developing API scripts in the usual way outside
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
362 Galaxy, you get persistence and other framework benefits plus at absolutely
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
363 no extra charge, a ginormous security problem if you share the history or
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
364 any outputs because they contain the api script with key so development
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
365 servers only please!
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
366
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
367 Workflow
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
368 Fire up the Tool Factory in Galaxy.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
369
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
370 Leave the input box empty, set the interpreter to python, paste and run an
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
371 api script - eg working example (substitute the url and key) below.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
372
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
373 It took me a few iterations to develop the example below because I know
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
374 almost nothing about the API. I started with very simple code from one of the
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
375 samples and after each run, the (edited..) api script is conveniently recreated
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
376 using the redo button on the history output item. So each successive version
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
377 of the developing api script you run is persisted - ready to be edited and
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
378 rerun easily. It is ''very'' handy to be able to add a line of code to the
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
379 script and run it, then view the output to (eg) inspect dicts returned by
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
380 API calls to help move progressively deeper iteratively.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
381
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
382 Give the below a whirl on a private clone (install the tool factory from
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
383 the main toolshed) and try adding complexity with few rerun/edit/rerun cycles.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
384
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
385 Eg tool factory api script
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
386 import sys
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
387 from blend.galaxy import GalaxyInstance
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
388 ourGal = 'http://x.x.x.x:xxxx'
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
389 ourKey = 'xxx'
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
390 gi = GalaxyInstance(ourGal, key=ourKey)
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
391 libs = gi.libraries.get_libraries()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
392 res = []
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
393 # libs looks like
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
394 # u'url': u'/galaxy/api/libraries/441d8112651dc2f3', u'id':
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
395 u'441d8112651dc2f3', u'name':.... u'Demonstration sample RNA data',
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
396 for lib in libs:
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
397 res.append('%s:\n' % lib['name'])
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
398 res.append(str(gi.libraries.show_library(lib['id'],contents=True)))
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
399 outf=open(sys.argv[2],'w')
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
400 outf.write('\n'.join(res))
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
401 outf.close()
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
402
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
403 **Attribution**
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
404 Creating re-usable tools from scripts: The Galaxy Tool Factory
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
405 Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
406 Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
407
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
408 http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
409
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
410 **Licensing**
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
411 Copyright Ross Lazarus 2010
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
412 ross lazarus at g mail period com
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
413
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
414 All rights reserved.
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
415
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
416 Licensed under the LGPL
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
417
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
418 **Obligatory screenshot**
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
419
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
420 http://bitbucket.org/fubar/galaxytoolmaker/src/fda8032fe989/images/dynamicScriptTool.png
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
421
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
422
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
423 ```
9fe74bd23af2 Uploaded
fubar
parents:
diff changeset
424