Mercurial > repos > iuc > pick_value
comparison pick_value.xml @ 0:bf793b71559a draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/pick_value commit ef564483fa8dc267c599af8745aab4e03b0c57e0
author | iuc |
---|---|
date | Tue, 07 Nov 2023 09:02:42 +0000 |
parents | |
children | b19e21af9c52 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf793b71559a |
---|---|
1 <tool name="Pick parameter value" id="pick_value" version="0.1.0" profile="21.01" tool_type="expression"> | |
2 <macros> | |
3 <xml name="booleans"> | |
4 <repeat name="pick_from" title="Pick from"> | |
5 <param name="value" type="boolean" optional="true" label="Value" /> | |
6 </repeat> | |
7 </xml> | |
8 <xml name="integers"> | |
9 <repeat name="pick_from" title="Pick from"> | |
10 <param name="value" type="integer" label="Value" optional="true" /> | |
11 </repeat> | |
12 </xml> | |
13 <xml name="floats"> | |
14 <repeat name="pick_from" title="Pick from"> | |
15 <param name="value" type="float" label="Value" optional="true" /> | |
16 </repeat> | |
17 </xml> | |
18 <xml name="texts"> | |
19 <repeat name="pick_from" title="Pick from"> | |
20 <param name="value" type="text" optional="true" label="Value" /> | |
21 </repeat> | |
22 </xml> | |
23 <xml name="datas"> | |
24 <repeat name="pick_from" title="Pick from"> | |
25 <param name="value" type="data" format="data" optional="true" label="Value" /> | |
26 </repeat> | |
27 </xml> | |
28 <xml name="param_type"> | |
29 <param name="param_type" type="select" label="Select type of parameter to select from"> | |
30 <option value="data">Dataset</option> | |
31 <option value="text">Text</option> | |
32 <option value="integer">Integer</option> | |
33 <option value="float">Float</option> | |
34 <option value="boolean">Boolean</option> | |
35 </param> | |
36 </xml> | |
37 <xml name="param_pick_style"> | |
38 <param name="pick_style" type="select" label="Picking behavior" help="How should the case when not exactly one value is non-null be handled?"> | |
39 <option value="first">Pick first value</option> | |
40 <option value="first_or_default">Pick first value (or provide default)</option> | |
41 <option value="first_or_error">Pick first value (or fail)</option> | |
42 <option value="only">Pick only value</option> | |
43 </param> | |
44 </xml> | |
45 <xml name="type_conditional"> | |
46 <conditional name="type_cond"> | |
47 <expand macro="param_type" /> | |
48 <when value="text"> | |
49 <expand macro="texts" /> | |
50 </when> | |
51 <when value="integer"> | |
52 <expand macro="integers" /> | |
53 </when> | |
54 <when value="float"> | |
55 <expand macro="floats" /> | |
56 </when> | |
57 <when value="boolean"> | |
58 <expand macro="booleans" /> | |
59 </when> | |
60 <when value="data"> | |
61 <expand macro="datas" /> | |
62 </when> | |
63 </conditional> | |
64 </xml> | |
65 <xml name="type_conditional_with_default"> | |
66 <conditional name="type_cond"> | |
67 <expand macro="param_type" /> | |
68 <when value="text"> | |
69 <expand macro="texts" /> | |
70 <param name="default_value" type="text" label="Default Value" /> | |
71 </when> | |
72 <when value="integer"> | |
73 <expand macro="integers" /> | |
74 <param name="default_value" type="integer" optional="true" label="Default Value" /> | |
75 </when> | |
76 <when value="float"> | |
77 <expand macro="floats" /> | |
78 <param name="default_value" type="float" optional="true" label="Default Value" /> | |
79 </when> | |
80 <when value="boolean"> | |
81 <expand macro="booleans" /> | |
82 <param name="default_value" type="boolean" label="Default Value" /> | |
83 </when> | |
84 <when value="data"> | |
85 <expand macro="datas" /> | |
86 <param name="default_value" type="data" format="data" label="Default Value" /> | |
87 </when> | |
88 </conditional> | |
89 </xml> | |
90 <xml name="style_conditional"> | |
91 <conditional name="style_cond"> | |
92 <expand macro="param_pick_style" /> | |
93 <when value="first"> | |
94 <expand macro="type_conditional" /> | |
95 </when> | |
96 <when value="first_or_default"> | |
97 <expand macro="type_conditional_with_default" /> | |
98 </when> | |
99 <when value="first_or_error"> | |
100 <expand macro="type_conditional" /> | |
101 </when> | |
102 <when value="only"> | |
103 <expand macro="type_conditional" /> | |
104 </when> | |
105 </conditional> | |
106 </xml> | |
107 </macros> | |
108 <expression type="ecma5.1"><![CDATA[{ | |
109 var out = null; | |
110 var pickStyle = $job.style_cond.pick_style; | |
111 var paramType = $job.style_cond.type_cond.param_type; | |
112 var pickFrom = $job.style_cond.type_cond.pick_from; | |
113 for ( var i = 0; i < pickFrom.length; i++ ) { | |
114 if ( pickFrom[i].value !== null ) { | |
115 if ( pickStyle == 'only' && out !== null ) { | |
116 return { '__error_message': 'Multiple null values found, only one allowed.' }; | |
117 } else if ( out == null ) { | |
118 out = pickFrom[i].value; | |
119 } | |
120 } | |
121 } | |
122 if ( out == null && pickStyle == 'first_or_default' ) { | |
123 out = $job.style_cond.type_cond.default_value; | |
124 } | |
125 if ( paramType == "data" && out ) { | |
126 out = out.src; | |
127 } | |
128 if ( out == null && ( pickStyle == "first_or_error" || pickStyle == "only" ) ) { | |
129 return { '__error_message': 'No non-null values found among tool inputs.' }; | |
130 } | |
131 return { 'output': out }; | |
132 }]]></expression> | |
133 <inputs> | |
134 <expand macro="style_conditional" /> | |
135 </inputs> | |
136 <outputs> | |
137 <output type="text" name="text_param" from="output"> | |
138 <filter>style_cond['type_cond']['param_type'] == 'text'</filter> | |
139 </output> | |
140 <output type="integer" name="integer_param" from="output"> | |
141 <filter>style_cond['type_cond']['param_type'] == 'integer'</filter> | |
142 </output> | |
143 <output type="float" name="float_param" from="output"> | |
144 <filter>style_cond['type_cond']['param_type'] == 'float'</filter> | |
145 </output> | |
146 <output type="boolean" name="boolean_param" from="output"> | |
147 <filter>style_cond['type_cond']['param_type'] == 'boolean'</filter> | |
148 </output> | |
149 <output type="data" name="data_param" from="output"> | |
150 <filter>style_cond['type_cond']['param_type'] == 'data'</filter> | |
151 </output> | |
152 </outputs> | |
153 <help> | |
154 A "null" value is an empty value, it means some input wasn't specified or some tool produced | |
155 an empty value or was skipped entirely. This can be thought of as an NA in Excel or a None value | |
156 in Python. This expression tool can be fed multiple values - from parameter inputs or the | |
157 outputs or other tools or workflows - and pick one. This allows building workflows which can | |
158 skip steps and branch in complex ways. | |
159 | |
160 There are subtle but important distinctions between the selection style - though they all | |
161 essentially pick the first value that is non-null (i.e. the first input with a real value). | |
162 | |
163 - "Pick first value" is the default and will just return its own null value if none of the inputs | |
164 are non-null. | |
165 - "Pick first value (or provide default)" allows picking a default value that will be used if none of the | |
166 inputs are non-null. | |
167 - "Pick first value (or fail)" will cause the tool execution to fail if none of the selections are | |
168 non-null. This can be important because it provides a clearer indication that something went | |
169 wrong and can prevent the further evaluation of a workflow. | |
170 - "Pick only value" is like "First value (or fail)" in that it will cause an error if none of the | |
171 inputs are non-null but it will go further to ensure that exactly one value is non-null. When | |
172 building conditonal paths through a workflow this can ensure that at most one path is | |
173 taken. | |
174 </help> | |
175 <tests> | |
176 <test expect_num_outputs="1"> | |
177 <conditional name="style_cond"> | |
178 <param name="pick_style" value="first" /> | |
179 <conditional name="type_cond"> | |
180 <param name="param_type" value="data" /> | |
181 <repeat name="pick_from"> | |
182 <param name="value" value_json="null" /> | |
183 </repeat> | |
184 <repeat name="pick_from"> | |
185 <param name="value" value_json="null" /> | |
186 </repeat> | |
187 <repeat name="pick_from"> | |
188 <param name="value" value="simple_line.txt" /> | |
189 </repeat> | |
190 <repeat name="pick_from"> | |
191 <param name="value" value="simple_line_alternative.txt" /> | |
192 </repeat> | |
193 </conditional> | |
194 </conditional> | |
195 <output name="data_param" value="simple_line.txt" /> | |
196 </test> | |
197 <test expect_num_outputs="1"> | |
198 <conditional name="style_cond"> | |
199 <param name="pick_style" value="first" /> | |
200 <conditional name="type_cond"> | |
201 <param name="param_type" value="boolean" /> | |
202 <repeat name="pick_from"> | |
203 <param name="value" value_json="true" /> | |
204 </repeat> | |
205 </conditional> | |
206 </conditional> | |
207 <output name="boolean_param" value_json="true" /> | |
208 </test> | |
209 <test expect_num_outputs="1"> | |
210 <conditional name="style_cond"> | |
211 <param name="pick_style" value="first" /> | |
212 <conditional name="type_cond"> | |
213 <param name="param_type" value="boolean" /> | |
214 <repeat name="pick_from"> | |
215 <param name="value" value_json="null" /> | |
216 </repeat> | |
217 <repeat name="pick_from"> | |
218 <param name="value" value_json="true" /> | |
219 </repeat> | |
220 </conditional> | |
221 </conditional> | |
222 <output name="boolean_param" value_json="true" /> | |
223 </test> | |
224 <test expect_num_outputs="1"> | |
225 <conditional name="style_cond"> | |
226 <param name="pick_style" value="first" /> | |
227 <conditional name="type_cond"> | |
228 <param name="param_type" value="boolean" /> | |
229 <repeat name="pick_from"> | |
230 <param name="value" value_json="false" /> | |
231 </repeat> | |
232 </conditional> | |
233 </conditional> | |
234 <output name="boolean_param" value_json="false" /> | |
235 </test> | |
236 <test expect_num_outputs="1"> | |
237 <conditional name="style_cond"> | |
238 <param name="pick_style" value="first" /> | |
239 <conditional name="type_cond"> | |
240 <param name="param_type" value="boolean" /> | |
241 <repeat name="pick_from"> | |
242 <param name="value" value_json="null" /> | |
243 </repeat> | |
244 <repeat name="pick_from"> | |
245 <param name="value" value_json="false" /> | |
246 </repeat> | |
247 <repeat name="pick_from"> | |
248 <param name="value" value_json="true" /> | |
249 </repeat> | |
250 </conditional> | |
251 </conditional> | |
252 <output name="boolean_param" value_json="false" /> | |
253 </test> | |
254 <test expect_num_outputs="1"> | |
255 <conditional name="style_cond"> | |
256 <param name="pick_style" value="first" /> | |
257 <conditional name="type_cond"> | |
258 <param name="param_type" value="boolean" /> | |
259 <repeat name="pick_from"> | |
260 <param name="value" value_json="null" /> | |
261 </repeat> | |
262 <repeat name="pick_from"> | |
263 <param name="value" value_json="true" /> | |
264 </repeat> | |
265 <repeat name="pick_from"> | |
266 <param name="value" value_json="false" /> | |
267 </repeat> | |
268 </conditional> | |
269 </conditional> | |
270 <output name="boolean_param" value_json="true" /> | |
271 </test> | |
272 <test expect_failure="true"> | |
273 <conditional name="style_cond"> | |
274 <param name="pick_style" value="only" /> | |
275 <conditional name="type_cond"> | |
276 <param name="param_type" value="boolean" /> | |
277 <repeat name="pick_from"> | |
278 <param name="value" value_json="true" /> | |
279 </repeat> | |
280 <repeat name="pick_from"> | |
281 <param name="value" value_json="false" /> | |
282 </repeat> | |
283 </conditional> | |
284 </conditional> | |
285 </test> | |
286 <test expect_failure="true"> | |
287 <conditional name="style_cond"> | |
288 <param name="pick_style" value="first_or_error" /> | |
289 <conditional name="type_cond"> | |
290 <param name="param_type" value="boolean" /> | |
291 <repeat name="pick_from"> | |
292 <param name="value" value_json="null" /> | |
293 </repeat> | |
294 <repeat name="pick_from"> | |
295 <param name="value" value_json="null" /> | |
296 </repeat> | |
297 </conditional> | |
298 </conditional> | |
299 </test> | |
300 <test expect_failure="true"> | |
301 <conditional name="style_cond"> | |
302 <param name="pick_style" value="only" /> | |
303 <conditional name="type_cond"> | |
304 <param name="param_type" value="boolean" /> | |
305 <repeat name="pick_from"> | |
306 <param name="value" value_json="null" /> | |
307 </repeat> | |
308 <repeat name="pick_from"> | |
309 <param name="value" value_json="null" /> | |
310 </repeat> | |
311 </conditional> | |
312 </conditional> | |
313 </test> | |
314 <test expect_num_outputs="1"> | |
315 <conditional name="style_cond"> | |
316 <param name="pick_style" value="first" /> | |
317 <conditional name="type_cond"> | |
318 <param name="param_type" value="boolean" /> | |
319 <repeat name="pick_from"> | |
320 <param name="value" value_json="null" /> | |
321 </repeat> | |
322 </conditional> | |
323 </conditional> | |
324 <output name="boolean_param" value_json="null" /> | |
325 </test> | |
326 <test expect_num_outputs="1"> | |
327 <conditional name="style_cond"> | |
328 <param name="pick_style" value="first_or_default" /> | |
329 <conditional name="type_cond"> | |
330 <param name="param_type" value="boolean" /> | |
331 <repeat name="pick_from"> | |
332 <param name="value" value_json="null" /> | |
333 </repeat> | |
334 <param name="default_value" value_json="true" /> | |
335 </conditional> | |
336 </conditional> | |
337 <output name="boolean_param" value_json="true" /> | |
338 </test> | |
339 <test expect_num_outputs="1"> | |
340 <conditional name="style_cond"> | |
341 <param name="pick_style" value="first_or_default" /> | |
342 <conditional name="type_cond"> | |
343 <param name="param_type" value="boolean" /> | |
344 <repeat name="pick_from"> | |
345 <param name="value" value_json="null" /> | |
346 </repeat> | |
347 <repeat name="pick_from"> | |
348 <param name="value" value_json="null" /> | |
349 </repeat> | |
350 <param name="default_value" value_json="false" /> | |
351 </conditional> | |
352 </conditional> | |
353 <output name="boolean_param" value_json="false" /> | |
354 </test> | |
355 <test expect_num_outputs="1"> | |
356 <conditional name="style_cond"> | |
357 <param name="pick_style" value="first_or_default" /> | |
358 <conditional name="type_cond"> | |
359 <param name="param_type" value="data" /> | |
360 <repeat name="pick_from"> | |
361 <param name="value" value_json="null" /> | |
362 </repeat> | |
363 <repeat name="pick_from"> | |
364 <param name="value" value_json="null" /> | |
365 </repeat> | |
366 <param name="default_value" value="simple_line.txt" /> | |
367 </conditional> | |
368 </conditional> | |
369 <output name="data_param" value="simple_line.txt" /> | |
370 </test> | |
371 </tests> | |
372 </tool> | |
373 |