comparison general.xml @ 0:9512201417a5 draft

planemo upload for repository https://github.com/bernt-matthias/mb-galaxy-tools/tree/master/tools/scripting/ commit 9e9a0860d255a1fd6c43edd0fde9ea538ee679de
author mbernt
date Sun, 06 Aug 2023 15:21:11 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9512201417a5
1 <tool id="singularity_scriptrunner" name="scriptrunner" version="0.1" profile="22.05">
2 <description>singularity</description>
3 <creator>
4 <person givenName="Matthias" familyName="Bernt" email="m.bernt@ufz.de" />
5 <organization name="Helmholtz Centre for Environmental Research - UFZ" url="https://www.ufz.de/"/>
6 </creator>
7 <command detect_errors="aggressive"><![CDATA[
8 #import re
9
10 ## cp script to JWD
11 mkdir script &&
12 cp '$script' script/script &&
13
14 mkdir inputs &&
15 #for $p in $parameters
16 #if $p.type_cond.type_sel == "data"
17 #if $p.type_cond.filename != ''
18 #set fname = $p.type_cond.filename
19 #else
20 #set fname=re.sub('[^\s\w\.]', '_', str($p.type_cond.param.element_identifier)) + "." + $p.type_cond.param.ext
21 #end if
22 ln -s '$p.type_cond.param' inputs/'$fname' &&
23 #end if
24 #end for
25
26 $image.fields.container_type
27 exec
28 ## --cpus 1 # disabled because rootless cgroups requires cgroups v2
29 ## --memory "\$((1024 * \${GALAY_MEMORY_MB:-8192}))" # not needed on EVE
30 ## bind Galaxy's file dir, otherwise we need to copy input file to JWD
31 --bind '$__app__.config.file_path:$__app__.config.file_path'
32 $image.fields.container_params
33 '$image.fields.image'
34 $image.fields.interpreter 'script/script'
35 #for $p in $parameters
36 #if $p.type_cond.type_sel == "data"
37 #if $p.type_cond.filename != ''
38 #set fname = $p.type_cond.filename
39 #else
40 #set fname=re.sub('[^\s\w\.]', '_', str($p.type_cond.param.element_identifier)) + "." + $p.type_cond.param.ext
41 #end if
42 inputs/'$fname'
43 #else
44 '$p.type_cond.param'
45 #end if
46 #end for
47 ]]></command>
48 <configfiles>
49 <configfile name="script">$code</configfile>
50 </configfiles>
51 <inputs>
52 <param name="interpreter" type="select" label="Interpreter">
53 <options from_data_table="scripting_images">
54 <column name="name" index="3"/>
55 <column name="value" index="3"/>
56 <filter type="regexp" column="4" value="singularity|apptainer"/>
57 </options>
58 <validator type="no_options" message="No interpreter available. Contact you Galaxy administrator." />
59 </param>
60 <param name="image" type="select" label="Image" >
61 <options from_data_table="scripting_images">
62 <filter type="regexp" column="4" value="singularity|apptainer"/>
63 <filter type="param_value" column="3" ref="interpreter"/>
64 </options>
65 <validator type="no_options" message="No interpreter / image is available. Contact you Galaxy administrator." />
66 </param>
67 <repeat name="parameters" title="Parameters" min="1" default="1" help="Supply one or more parameters">
68 <conditional name="type_cond">
69 <param name="type_sel" type="select" label="Parameter type">
70 <option value="data">Dataset</option>
71 <option value="text">Text</option>
72 <!-- Not sure if int/float make sense .. can they be connected to text in WFs? -->
73 </param>
74 <when value="data">
75 <param name="param" type="data" format="data" label="Dataset"/>
76 <param name="filename" type="text" label="File name" help="Set if you want to access the data set with a specific file name. Only alphanumeric characters, dash and underscore are allowed (all other characters are replaced by an undercore). Default is Galaxy's data set name.">
77 <sanitizer invalid_char="_">
78 <valid initial="string.ascii_letters,string.digits">
79 <add value="_" />
80 <add value="-" />
81 <add value="." />
82 </valid>
83 </sanitizer>
84 <!-- file names must not start with dash -->
85 <validator type="regex" negate="true" message="Filenames must not start with a dash">^[-].*$</validator>
86 </param>
87 </when>
88 <when value="text">
89 <param name="param" type="text" label="Text parameter" help=""/>
90 </when>
91 </conditional>
92 </repeat>
93 <param name="code" type="text" area="true" label="Script to execute" help="">
94 <sanitizer>
95 <valid initial="string.printable"/>
96 </sanitizer>
97 </param>
98 </inputs>
99 <outputs>
100 <collection name="output" type="list" label="Outputs">
101 <discover_datasets pattern="__designation_and_ext__"/>
102 </collection>
103 </outputs>
104 <tests>
105 <!-- read tsv write csv -->
106 <test>
107 <param name="interpreter" value="python"/>
108 <param name="image" value="python_continuumio_anaconda"/>
109 <repeat name="parameters">
110 <conditional name="type_cond">
111 <param name="type_sel" value="data"/>
112 <param name="param" value="test.tsv" ftype="tabular"/>
113 </conditional>
114 </repeat>
115 <param name="code" value='import sys; import pandas as pd; df = pd.read_csv(sys.argv[1], sep="\t"); df.to_csv("data.csv", index=False, sep=",");'/>
116 <output_collection name="output" type="list" count="1">
117 <element name="data" ftype="csv">
118 <assert_contents>
119 <has_line line="1,2" />
120 <has_n_lines n="3"/>
121 <has_n_columns n="2" sep=","/>
122 </assert_contents>
123 </element>
124 </output_collection>
125 <!-- but the data table this should use singularity and not use additional parameters to it (\-\-cleanenv) -->
126 <assert_command>
127 <has_text text="singularity"/>
128 <has_text text="--cleanenv"/>
129 </assert_command>
130 </test>
131 <!-- plot w matplotlib -->
132 <test>
133 <param name="interpreter" value="python"/>
134 <param name="image" value="python_continuumio_anaconda"/>
135 <repeat name="parameters">
136 <conditional name="type_cond">
137 <param name="param" value="test.tsv" ftype="tabular"/>
138 <param name="filename" value="custom_name.tsv"/>
139 </conditional>
140 </repeat>
141 <param name="code" value='import sys; import pandas as pd; from matplotlib.backends.backend_pdf import PdfPages; df = pd.read_csv(sys.argv[1], sep="\t"); fh = PdfPages("points.pdf"); plt = df.plot(); fh.savefig(); fh.close(); print(f"plotted {sys.argv[1]}")'/>
142 <output_collection name="output" type="list" count="1">
143 <element name="points" ftype="pdf">
144 <assert_contents>
145 <has_text text="PDF" />
146 </assert_contents>
147 </element>
148 </output_collection>
149 <assert_stdout>
150 <has_line line="plotted inputs/custom_name.tsv"/>
151 </assert_stdout>
152 </test>
153 <!-- install libraries ("forbidden") -->
154 <test expect_failure="true">
155 <param name="interpreter" value="python"/>
156 <param name="image" value="python_continuumio_anaconda"/>
157 <param name="code" value='import pip; pip.main(["install", "biopython"]); import Bio'/>
158 </test>
159 <!-- read binary files (eg feather) -->
160 <test>
161 <param name="interpreter" value="python"/>
162 <param name="image" value="python_continuumio_anaconda"/>
163 <repeat name="parameters">
164 <conditional name="type_cond">
165 <param name="param" value="test.h5" ftype="h5"/>
166 </conditional>
167 </repeat>
168 <param name="code" value='import sys; import os; import pandas as pd; df = pd.read_hdf(sys.argv[1]); df.to_csv("data.csv", index=False, sep=",");'/>
169 <output_collection name="output" type="list" count="1">
170 <element name="data" ftype="csv">
171 <assert_contents>
172 <has_line line="1,2" />
173 <has_n_lines n="3"/>
174 <has_n_columns n="2" sep=","/>
175 </assert_contents>
176 </element>
177 </output_collection>
178 </test>
179 <!-- parameters -->
180 <test>
181 <param name="interpreter" value="python"/>
182 <param name="image" value="python_continuumio_anaconda"/>
183 <repeat name="parameters">
184 <conditional name="type_cond">
185 <param name="type_sel" value="text"/>
186 <param name="param" value="filename.csv"/>
187 </conditional>
188 </repeat>
189 <repeat name="parameters">
190 <conditional name="type_cond">
191 <param name="type_sel" value="text"/>
192 <param name="param" value="some value"/>
193 </conditional>
194 </repeat>
195 <param name="code" value='import sys; fh = open(sys.argv[1], "w"); fh.write("Hello,world\n"); fh.write("Bye,world\n"); fh.close(); print(sys.argv[2]);'/>
196 <output_collection name="output" type="list" count="1">
197 <element name="filename" ftype="csv">
198 <assert_contents>
199 <has_line line="Hello,world"/>
200 <has_n_lines n="2"/>
201 <has_n_columns n="2" sep=","/>
202 </assert_contents>
203 </element>
204 </output_collection>
205 <assert_stdout>
206 <has_line line='some value'/>
207 </assert_stdout>
208 </test>
209
210 <!-- read tsv write csv -->
211 <test>
212 <param name="interpreter" value="Rscript"/>
213 <param name="image" value="r_rocker_tidyverse"/>
214 <repeat name="parameters">
215 <conditional name="type_cond">
216 <param name="param" value="test.tsv" ftype="tabular"/>
217 </conditional>
218 </repeat>
219 <param name="code" value='args = commandArgs(trailingOnly = TRUE); data = read.delim(args[1]); write.csv(data, "data.csv", row.names=FALSE)'/>
220 <output_collection name="output" type="list" count="1">
221 <element name="data" ftype="csv">
222 <assert_contents>
223 <has_line line="1,2" />
224 <has_n_lines n="3"/>
225 <has_n_columns n="2" sep=","/>
226 </assert_contents>
227 </element>
228 </output_collection>
229 <!-- but the data table this should use apptainer and not use any additional parameters to it -->
230 <assert_command>
231 <has_text text="apptainer"/>
232 <has_text text="--cleanenv" negate="true"/>
233 </assert_command>
234 </test>
235 <!-- use a tidyverse library -->
236 <test>
237 <param name="interpreter" value="Rscript"/>
238 <param name="image" value="r_rocker_tidyverse"/>
239 <repeat name="parameters">
240 <conditional name="type_cond">
241 <param name="param" value="test.tsv" ftype="tabular"/>
242 <param name="filename" value="custom_name.tsv"/>
243 </conditional>
244 </repeat>
245 <param name="code" value='library(ggplot2); args = commandArgs(trailingOnly = TRUE); data = read.delim(args[1]); pdf("points.pdf"); ggplot(data, aes(x=A, y=B)) + geom_point(); dev.off(); print(paste("plotted", args[1]))'/>
246 <output_collection name="output" type="list" count="1">
247 <element name="points" ftype="pdf">
248 <assert_contents>
249 <has_text text="PDF" />
250 </assert_contents>
251 </element>
252 </output_collection>
253 <assert_stdout>
254 <has_line line='[1] "plotted inputs/custom_name.tsv"'/>
255 </assert_stdout>
256 </test>
257 <!-- install libraries fails -->
258 <test expect_failure="true">
259 <param name="interpreter" value="Rscript"/>
260 <param name="image" value="r_rocker_tidyverse"/>
261 <param name="code" value='install.packages("maybe"); library(maybe); print("success")'/>
262 </test>
263 <test expect_failure="true">
264 <param name="interpreter" value="Rscript"/>
265 <param name="image" value="r_rocker_tidyverse"/>
266 <param name="code" value='install.packages("BiocManager"); BiocManager::install("multtest"); print("success")'/>
267 </test>
268 <!-- read binary files (eg rds) -->
269 <test>
270 <param name="interpreter" value="Rscript"/>
271 <param name="image" value="r_rocker_tidyverse"/>
272 <repeat name="parameters">
273 <conditional name="type_cond">
274 <param name="param" value="test.rds" ftype="rds"/>
275 </conditional>
276 </repeat>
277 <param name="code" value='args = commandArgs(trailingOnly = TRUE); data = readRDS(args[1]); write.csv(data, "data.csv", row.names=FALSE)'/>
278 <output_collection name="output" type="list" count="1">
279 <element name="data" ftype="csv">
280 <assert_contents>
281 <has_line line="1,2" />
282 <has_n_lines n="3"/>
283 <has_n_columns n="2" sep=","/>
284 </assert_contents>
285 </element>
286 </output_collection>
287 </test>
288 <!-- optional input and parameters -->
289 <test>
290 <param name="interpreter" value="Rscript"/>
291 <param name="image" value="r_rocker_tidyverse"/>
292 <repeat name="parameters">
293 <conditional name="type_cond">
294 <param name="type_sel" value="text"/>
295 <param name="param" value="filename.csv"/>
296 </conditional>
297 </repeat>
298 <repeat name="parameters">
299 <conditional name="type_cond">
300 <param name="type_sel" value="text"/>
301 <param name="param" value="some value"/>
302 </conditional>
303 </repeat>
304 <param name="code" value='args = commandArgs(trailingOnly = TRUE); fileConn = file(args[1]); writeLines(c("Hello,world","Bye,world"), fileConn); close(fileConn); print(args[2]);'/>
305 <output_collection name="output" type="list" count="1">
306 <element name="filename" ftype="csv">
307 <assert_contents>
308 <has_line line="Hello,world"/>
309 <has_n_lines n="2"/>
310 <has_n_columns n="2" sep=","/>
311 </assert_contents>
312 </element>
313 </output_collection>
314 <assert_stdout>
315 <has_line line='[1] "some value"'/>
316 </assert_stdout>
317 </test>
318
319 <!-- some tests with bash-->
320 <test>
321 <param name="interpreter" value="bash"/>
322 <param name="image" value="bash_continuumio_anaconda"/>
323 <repeat name="parameters">
324 <conditional name="type_cond">
325 <param name="param" value="test.tsv" ftype="tabular"/>
326 </conditional>
327 </repeat>
328 <param name="code" value="sed -e 's/\t/,/' $1 > data.csv"/>
329 <output_collection name="output" type="list" count="1">
330 <element name="data" ftype="csv">
331 <assert_contents>
332 <has_line line="1,2" />
333 <has_n_lines n="3"/>
334 <has_n_columns n="2" sep=","/>
335 </assert_contents>
336 </element>
337 </output_collection>
338 </test>
339
340 <!-- check that we can turn off networking -->
341 <test expect_failure="true">
342 <param name="interpreter" value="bash"/>
343 <param name="image" value="bash_continuumio_anaconda"/>
344 <repeat name="parameters">
345 <conditional name="type_cond">
346 <param name="param" value="test.tsv" ftype="tabular"/>
347 </conditional>
348 </repeat>
349 <param name="code" value="curl -iL https://www.galaxyproject.org"/>
350 </test>
351 </tests>
352 <help><![CDATA[
353 **Warning**
354
355 .. class:: warningmark
356
357 **Make sure that you know what you are doing. When used wrong the tool may lead to
358 data loss of files that you can write to.**
359
360 .. class:: warningmark
361
362 This tool is only intended to serve for single-use, ad-hoc exploratory analysis
363 of data sets with small scripts. This is because the tool has a limited
364 reusuability (in particular on other Galaxy servers).
365
366 .. class:: warningmark
367
368 If you use this tool repeatedly with the same script and/or have the impression
369 that other Galaxy users could profit from this script then contact your local
370 Galaxy administrator or the Galaxy community, e.g. at https://github.com/galaxyproject/tools-iuc/,
371 and ask if your script can be turned into a proper Galaxy tool.
372 One of the main advantages of a proper Galaxy tool is that they are tested and
373 maintained. Furthermore the whole Galaxy community may profit.
374
375 **What it does**
376
377 Executes an interpreted script (in a container). The available scripting
378 languages (e.g. python, R, bash, etc) and containers are configured by the
379 Galaxy administrator.
380
381 An arbitrary number of data or text parameters can be given to the script.
382 Data parameters are by default named like the datasets name and the datatype
383 is used as extension. This can be overwritten with the filename parameter
384 for the corresponding dataset.
385
386 **Inputs**
387
388 A python script can access data set parameters via the ``sys.argv`` list
389 where the i-th parameter corresponds to the i-th list element (counting from 1).
390 A tab delimited file, for instance, can be read with ``pandas`` as follows:
391
392 ::
393
394 import sys
395 import pandas as pd
396 df = pd.read_csv(sys.argv[1], sep="\t")
397
398 In an R script the list obtained by ``args <- commandArgs(trailingOnly = TRUE);``
399 contains (again the i-th list element contains the i-th parameter, starting from 1).
400 Reading a tab separated file in R could be done as follows:
401
402 ::
403
404 args <- commandArgs(trailingOnly = TRUE);
405 first_arg <- file(args[1])
406 df <- read.delim(args[1]);
407
408 **Outputs**
409
410 Output datasets are read from the current working directory and put into a
411 single collection. The collection elements will be named as the file names
412 (without the extension). The file extension determines the datatype of the
413 datasets (or Galaxy will try to autodetect the data type).
414 ]]></help>
415 </tool>