26
|
1 <tool id="rgTF" name="Tool Factory" version="1.11">
|
|
2 <description>Makes scripts into tools</description>
|
|
3 <requirements>
|
|
4 <requirement type="package" version="9.10">ghostscript</requirement>
|
|
5 <requirement type="package" version="1.3.18">graphicsmagick</requirement>
|
|
6 </requirements>
|
|
7 <command interpreter="python">
|
|
8 #if ( $__user_email__ not in $__admin_users__ ):
|
|
9 rgToolFactory.py --bad_user $__user_email__
|
|
10 #else:
|
|
11 rgToolFactory.py --script_path "$runme" --interpreter "$interpreter"
|
|
12 --tool_name "$tool_name" --user_email "$__user_email__"
|
|
13 #if $make_TAB.value=="yes":
|
|
14 --output_tab "$tab_file"
|
|
15 #end if
|
|
16 #if $makeMode.make_Tool=="yes":
|
|
17 --make_Tool "$makeMode.make_Tool"
|
|
18 --tool_desc "$makeMode.tool_desc"
|
|
19 --tool_version "$makeMode.tool_version"
|
|
20 --new_tool "$new_tool"
|
|
21 --help_text "$helpme"
|
|
22 #if $make_HTML.value=="yes":
|
|
23 --include_dependencies "${makeMode.include_deps}"
|
|
24 #end if
|
|
25 #end if
|
|
26 #if $make_HTML.value=="yes":
|
|
27 --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
|
|
28 #else:
|
|
29 --output_dir "."
|
|
30 #end if
|
|
31 #if $input1 != 'None':
|
|
32 --input_tab "$input1"
|
|
33 #end if
|
|
34 #end if
|
|
35 </command>
|
|
36 <inputs>
|
|
37 <param name="input1" type="data" label="Select an input file from your history" optional="true" size="120"
|
|
38 help="Most scripts will need an input - your script MUST be ready for whatever format you choose"/>
|
|
39 <param name="tool_name" type="text" value="My dynamic script" label="New tool ID and title for outputs" size="60"
|
|
40 help="This will become the toolshed repository name so please choose thoughtfully to avoid namespace clashes with other tool writers">
|
|
41 <sanitizer invalid_char="">
|
|
42 <valid initial="string.letters,string.digits"/>
|
|
43 </sanitizer>
|
|
44 </param>
|
|
45 <conditional name="makeMode">
|
|
46 <param name="make_Tool" type="select" label="Create a tar.gz file ready for local toolshed entry" help="Ready to deploy securely!" size="60">
|
|
47 <option value="yes">Generate a Galaxy ToolShed compatible toolshed.gz</option>
|
|
48 <option value="" selected="true">No. Just run the script please</option>
|
|
49 </param>
|
|
50 <when value = "yes">
|
|
51 <param name="tool_version" label="Tool Version - bump this to warn users trying to redo old analyses" type="text" value="0.01"
|
|
52 help="If you change your script and regenerate the 'same' tool, you should inform Galaxy (and users) by changing (bumping is traditional) this number"/>
|
|
53 <param name="tool_desc" label="Tool Description" type="text" value="" size="40"
|
|
54 help="Supply a brief tool description for the Galaxy tool menu entry (optional - appears after the tool name)" />
|
|
55 <param name="help_text" label="Tool form documentation and help text for users" type="text" area="true"
|
|
56 size="8x120" value="**What it Does**"
|
|
57 help="Supply the brief user documentation to appear on the new tool form as reStructured text - http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html" >
|
|
58 <sanitizer>
|
|
59 <valid initial="string.printable">
|
|
60 </valid>
|
|
61 <mapping initial="none"/>
|
|
62 </sanitizer>
|
|
63 </param>
|
|
64 <param name="include_deps" type="select" label="Include ghostscript and graphicsmagick dependencies in generated tool" size="60"
|
|
65 help="If an HTML file is being created, including dependencies is recommended. Otherwise this setting has no effect">
|
|
66 <option value="">Rely on system ghostscript and graphicsmagick rather than include these as dependencies</option>
|
|
67 <option value="yes" selected="true">Include dependencies so target installations will always work if HTML is being generated</option>
|
|
68 </param>
|
|
69
|
|
70 </when>
|
|
71 <when value = "">
|
|
72 </when>
|
|
73 </conditional>
|
|
74 <param name="make_HTML" type="select" label="Create an HTML report with links to all output files and thumbnail links to PDF images" size="60"
|
|
75 help="Recommended for presenting complex outputs in an accessible manner. Turn off for simple tools so they just create one output">
|
|
76 <option value="yes">Yes, arrange all outputs produced by my script as an HTML output</option>
|
|
77 <option value="" selected="true">No, no HTML output file thanks</option>
|
|
78 </param>
|
|
79 <param name="make_TAB" type="select" label="Create a new (default tabular) history output with or without an HTML file specified above"
|
|
80 help="This is useful if your script creates a single new tabular file you want to appear in the history after the tool executes">
|
|
81 <option value="yes" selected="true">My script writes to a new history output</option>
|
|
82 <option value="">I do not want a new history output file</option>
|
|
83 </param>
|
|
84 <param name="out_format" type="select" label="Galaxy datatype for your tool's output file if any" help="You may need to edit the xml to extend this list">
|
|
85 <option value="tabular" selected="true">Tabular</option>
|
|
86 <option value="interval">Interval</option>
|
|
87 <option value="gz">gz</option>
|
|
88 <option value="text">text</option>
|
|
89 </param>
|
|
90 <param name="interpreter" type="select" label="Select the interpreter for your code. This must be available on the path of the execution host">
|
|
91 <option value="Rscript" selected="true">Rscript</option>
|
|
92 <option value="python">python</option>
|
|
93 <option value="perl">perl</option>
|
|
94 <option value="sh">sh</option>
|
|
95 </param>
|
|
96 <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="" area="True" size="8x120"
|
|
97 help="Script must deal with two command line parameters: Path to input tabular file path (or 'None' if none selected) and path to output tabular history file (or 'None').">
|
|
98 <sanitizer>
|
|
99 <valid initial="string.printable">
|
|
100 </valid>
|
|
101 <mapping initial="none"/>
|
|
102 </sanitizer>
|
|
103 </param>
|
|
104 </inputs>
|
|
105 <outputs>
|
|
106 <data format="tabular" name="tab_file" label="${tool_name}.${out_format}">
|
|
107 <filter>make_TAB=="yes"</filter>
|
|
108 <change_format>
|
|
109 <when input="out_format" value="interval" format="interval" />
|
|
110 <when input="out_format" value="gz" format="gz" />
|
|
111 <when input="out_format" value="text" format="text" />
|
|
112 </change_format>
|
|
113 </data>
|
|
114 <data format="html" name="html_file" label="${tool_name}.html">
|
|
115 <filter>make_HTML == "yes"</filter>
|
|
116 </data>
|
|
117 <data format="toolshed.gz" name="new_tool" label="${tool_name}.toolshed.gz">
|
|
118 <filter>makeMode['make_Tool'] == "yes"</filter>
|
|
119 </data>
|
|
120 </outputs>
|
|
121 <configfiles>
|
|
122 <configfile name="runme">$dynScript</configfile>
|
|
123 <configfile name="helpme">
|
|
124 #if $makeMode.make_Tool == "yes":
|
|
125 ${makeMode.help_text}
|
|
126 #end if
|
|
127 </configfile>
|
|
128 </configfiles>
|
|
129 <help>
|
|
130
|
|
131 .. class:: warningmark
|
|
132
|
|
133 **Details and attribution** GTF_
|
|
134
|
|
135 **Local Admins ONLY** Only users whose IDs found in the local admin_user configuration setting in universe_wsgi.ini can run this tool.
|
|
136
|
|
137 **If you find a bug** please raise an issue at the bitbucket repository GTFI_
|
|
138
|
|
139 **What it does** This tool enables a user to paste and submit an arbitrary R/python/perl script to Galaxy.
|
|
140
|
|
141 **Input options** This version is limited to simple transformation or reporting requiring only a single input file selected from the history.
|
|
142
|
|
143 **Output options** Optional script outputs include one single new history tabular file, or for scripts that create multiple outputs,
|
|
144 a new HTML report linking all the files and images created by the script can be automatically generated.
|
|
145
|
|
146 **Tool Generation option** Once the script is working with test data, this tool will optionally generate a new Galaxy tool in a gzip file
|
|
147 ready to upload to your local toolshed for sharing and installation. Provide a small sample input when you run generate the tool because
|
|
148 it will become the input for the generated functional test.
|
|
149
|
|
150 .. class:: warningmark
|
|
151
|
|
152 **Note to system administrators** This tool offers *NO* built in protection against malicious scripts. It should only be installed on private/personnal Galaxy instances.
|
|
153 Admin_users will have the power to do anything they want as the Galaxy user if you install this tool.
|
|
154
|
|
155 .. class:: warningmark
|
|
156
|
|
157 **Use on public servers** is STRONGLY discouraged for obvious reasons
|
|
158
|
|
159 The tools generated by this tool will run just as securely as any other normal installed Galaxy tool but like any other new tools, should always be checked carefully before installation.
|
|
160 We recommend that you follow the good code hygiene practices associated with safe toolshed.
|
|
161
|
|
162 **Scripting conventions** The pasted script will be executed with the path to the (optional) input tabular data file path or NONE if you do not select one, and the path to the optional
|
|
163 output file or None if none is wanted, as the first and second command line parameters. The script must deal appropriately with these - see Rscript examples below.
|
|
164 Note that if an optional HTML output is selected, all the output files created by the script will be nicely presented as links, with pdf images linked as thumbnails in that output.
|
|
165 This can be handy for complex scripts creating lots of output.
|
|
166
|
|
167 **Examples**
|
|
168 <![CDATA[
|
|
169
|
|
170 Each of these following trivial examples can be cut and pasted into the script box for testing.
|
|
171 Please make sure you choose the appropriate interpreter and upload and select a suitable small matching test data input
|
|
172
|
|
173 A simple Rscript "filter" showing how the command line parameters can be handled, takes an input file, does something (transpose in this case) and
|
|
174 writes the results to a new tabular file. Note the use of colClasses to ensure that no fiddling takes place with numeric values by treating everything
|
|
175 as a string::
|
|
176
|
|
177 # transpose a tabular input file and write as a tabular output file
|
|
178 ourargs = commandArgs(TRUE)
|
|
179 inf = ourargs[1]
|
|
180 outf = ourargs[2]
|
|
181 inp = read.table(inf,head=F,row.names=NULL,sep='\t',colClasses="character")
|
|
182 outp = t(inp)
|
|
183 write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F)
|
|
184
|
|
185 Calculate a multiple test adjusted p value from a column of p values - for this script to be useful, it needs the right column for the input to be specified in the code for the
|
|
186 given input file type(s) specified when the tool is generated ::
|
|
187
|
|
188 # use p.adjust - assumes a HEADER row and column 1 - please fix for any real use
|
|
189 column = 1 # adjust if necessary for some other kind of input
|
|
190 ourargs = commandArgs(TRUE)
|
|
191 inf = ourargs[1]
|
|
192 outf = ourargs[2]
|
|
193 inp = read.table(inf,head=T,row.names=NULL,sep='\t')
|
|
194 p = inp[,column]
|
|
195 q = p.adjust(p,method='BH')
|
|
196 outp = cbind(inp,'BH Adjusted p-value'=q)
|
|
197 write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=T)
|
|
198
|
|
199
|
|
200 A demonstration Rscript example takes no input file but generates some random data based pdf images
|
|
201 You must make sure the option to create an HTML output file is
|
|
202 turned on for this to work. Images (pdf) are linked via thumbnails and
|
|
203 all files have a link on the resulting HTML page::
|
|
204
|
|
205 # note this script takes NO input or output because it generates random data
|
|
206 for (i in 1:10) {
|
|
207 foo = runif(100)
|
|
208 bar = rnorm(100)
|
|
209 bar = foo + 0.05*bar
|
|
210 pdf(paste('yet',i,"anotherplot.pdf",sep='_'))
|
|
211 plot(foo,bar,main=paste("Foo by Bar plot #",i),col="maroon", pch=3,cex=0.6)
|
|
212 dev.off()
|
|
213 foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100))
|
|
214 bar = as.matrix(foo)
|
|
215 pdf(paste('yet',i,"anotherheatmap.pdf",sep='_'))
|
|
216 heatmap(bar,main='Random Heatmap')
|
|
217 dev.off()
|
|
218 }
|
|
219
|
|
220 A slight variation taking an input tabular file from which we read the first number as nreps
|
|
221
|
|
222 # note this script takes a single parameter
|
|
223 # number of replicates
|
|
224 ourargs = commandArgs(TRUE)
|
|
225 infname = ourargs[1]
|
|
226 nreps = read.table(infname,head=F)
|
|
227 nreps = unlist(nreps)[1]
|
|
228 nreps = max(c(1,nreps))
|
|
229 nreps = min(c(20,nreps))
|
|
230 print(paste("Using nreps=",nreps))
|
|
231 for (i in 1:nreps) {
|
|
232 foo = runif(100)
|
|
233 bar = rnorm(100)
|
|
234 bar = foo + 0.2*bar
|
|
235 pdf(paste("yet",i,"anotherplot.pdf",sep="_"))
|
|
236 plot(foo,bar,main=paste("Foo by Bar plot ",i),col="maroon", pch=3,cex=0.6)
|
|
237 dev.off()
|
|
238 foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100))
|
|
239 bar = as.matrix(foo)
|
|
240 pdf(paste("yet",i,"anotherheatmap.pdf",sep="_"))
|
|
241 heatmap(bar,main="Random Heatmap")
|
|
242 dev.off()
|
|
243 }
|
|
244
|
|
245 A Python example that reverses each row of a tabular file (you'll need to remove the leading spaces
|
|
246 for this to work if cut and pasted into the script box)::
|
|
247
|
|
248 # reverse order of columns in a tabular file
|
|
249 import sys
|
|
250 inp = sys.argv[1]
|
|
251 outp = sys.argv[2]
|
|
252 i = open(inp,'r')
|
|
253 o = open(outp,'w')
|
|
254 for row in i:
|
|
255 rs = row.rstrip().split('\t')
|
|
256 rs.reverse()
|
|
257 o.write('\t'.join(rs))
|
|
258 o.write('\n')
|
|
259 i.close()
|
|
260 o.close()
|
|
261
|
|
262 A trivial shell script example to show that it works::
|
|
263
|
|
264 #!/bin/bash
|
|
265 INF=$1
|
|
266 OUTF=$2
|
|
267 cut -c2,4,6,8,10,12 $INF > $OUTF
|
|
268
|
|
269 A trivial perl script example to show that even perl works::
|
|
270
|
|
271 #
|
|
272 # change all occurances of a string in a file to another string
|
|
273 #
|
|
274 $oldfile = $ARGV[0];
|
|
275 $newfile = $ARGV[1];
|
|
276 $old = "gene";
|
|
277 $new = "foo";
|
|
278 open(OF, $oldfile);
|
|
279 open(NF, ">$newfile");
|
|
280 # read in each line of the file
|
|
281 while ($line = <OF>) {
|
|
282 $line =~ s/$old/$new/;
|
|
283 print NF $line;
|
|
284 }
|
|
285 close(OF);
|
|
286 close(NF);
|
|
287
|
|
288 ]]>
|
|
289
|
|
290 **Citation**
|
|
291
|
|
292
|
|
293 Paper_ :
|
|
294
|
|
295 Creating re-usable tools from scripts: The Galaxy Tool Factory
|
|
296 Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team
|
|
297 Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573
|
|
298
|
|
299
|
|
300 **Licensing**
|
|
301
|
|
302 Copyright Ross Lazarus (ross period lazarus at gmail period com) May 2012
|
|
303 All rights reserved.
|
|
304 Licensed under the LGPL_
|
|
305
|
|
306 .. _LGPL: http://www.gnu.org/copyleft/lesser.html
|
|
307 .. _GTF: https://bitbucket.org/fubar/galaxytoolfactory
|
|
308 .. _GTFI: https://bitbucket.org/fubar/galaxytoolfactory/issues
|
|
309 .. _Paper: http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
|
|
310
|
|
311
|
|
312 </help>
|
|
313
|
|
314 </tool>
|
|
315
|
|
316
|