comparison rgToolFactoryMultIn.xml @ 34:c6fdf2c6d0f4 draft

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