Mercurial > repos > iuc > map_param_value
comparison map_param_value.xml @ 0:43d7b3642a30 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/map_param_value commit 9cbf1d6cb6a59b8b4172d09449aac695ba10687d
author | iuc |
---|---|
date | Sun, 16 Oct 2022 08:05:37 +0000 |
parents | |
children | a01f088d0e5e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:43d7b3642a30 |
---|---|
1 <tool name="Map parameter value" id="map_param_value" version="0.1.0" tool_type="expression" profile="22.01"> | |
2 <macros> | |
3 <xml name="when_element" tokens="type_selection"> | |
4 <param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Map this parameter value to a different value"/> | |
5 <repeat name="mappings" label="Add value mapping"> | |
6 <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"></param> | |
7 <param name="to" type="text" label="to this value" help="This value must be coercable to the selected output parameter type"></param> | |
8 </repeat> | |
9 </xml> | |
10 </macros> | |
11 <expression type="ecma5.1"> | |
12 <![CDATA[{ | |
13 const source = $job.input_param_type.input_param; | |
14 const mappings = $job.input_param_type.mappings; | |
15 | |
16 const coerceToOutput = function(value) { | |
17 switch($job.output_param_type) { | |
18 case "integer": | |
19 return parseInt(value) | |
20 case "float": | |
21 return parseFloat(value) | |
22 case "boolean": | |
23 if (value == "false" || value == "False") { | |
24 return false | |
25 } | |
26 return !!value | |
27 case "text": | |
28 return value | |
29 } | |
30 } | |
31 | |
32 for ( var i = 0; i < mappings.length; i++ ) { | |
33 if ( String(mappings[i].from) == source ) { | |
34 return { output: coerceToOutput(mappings[i].to) }; | |
35 } | |
36 } | |
37 if ( $job.unmapped.on_unmapped == "fail" ) { | |
38 return { __error_message: `text_param ${source} not found in mapping values.` }; | |
39 } else if ( $job.unmapped.on_unmapped == "default" ) { | |
40 return { output: coerceToOutput($job.unmapped.default_value) }; | |
41 } | |
42 return { output: coerceToOutput(source) }; | |
43 }]]> | |
44 </expression> | |
45 <inputs> | |
46 <conditional name="input_param_type"> | |
47 <param name="type" type="select" label="Select type of input parameter to match"> | |
48 <option value="text" selected="true">Text</option> | |
49 <option value="integer">Integer</option> | |
50 <option value="float">Float</option> | |
51 <option value="boolean">Boolean</option> | |
52 </param> | |
53 <when value="text"> | |
54 <expand macro="when_element" type_selection="text"/> | |
55 </when> | |
56 <when value="integer"> | |
57 <expand macro="when_element" type_selection="integer"/> | |
58 </when> | |
59 <when value="float"> | |
60 <expand macro="when_element" type_selection="float"/> | |
61 </when> | |
62 <when value="boolean"> | |
63 <expand macro="when_element" type_selection="boolean"/> | |
64 </when> | |
65 </conditional> | |
66 <param name="output_param_type" type="select" label="Select type of parameter to output"> | |
67 <option value="text">Text</option> | |
68 <option value="integer">Integer</option> | |
69 <option value="float">Float</option> | |
70 <option value="boolean">Boolean</option> | |
71 </param> | |
72 <conditional name="unmapped"> | |
73 <param name="on_unmapped" type="select" label="Select how"> | |
74 <option value="input">Use unmodified input parameter value if input parameter value not found in mappings</option> | |
75 <option value="fail">Fail if input parameter value not found in mappings</option> | |
76 <option value="default">Provide a default value to use if input parameter value not found in mappings</option> | |
77 </param> | |
78 <when value="input" /> | |
79 <when value="fail" /> | |
80 <when value="default"> | |
81 <param name="default_value" type="text" label="Use this value if the input parameter value was not found in mappings"/> | |
82 </when> | |
83 </conditional> | |
84 </inputs> | |
85 <outputs> | |
86 <output type="text" name="output_param_text" from="output"> | |
87 <filter>output_param_type == 'text'</filter> | |
88 </output> | |
89 <output type="integer" name="output_param_integer" from="output"> | |
90 <filter>output_param_type == 'integer'</filter> | |
91 </output> | |
92 <output type="float" name="output_param_float" from="output"> | |
93 <filter>output_param_type == 'float'</filter> | |
94 </output> | |
95 <output type="boolean" name="output_param_boolean" from="output"> | |
96 <filter>output_param_type == 'boolean'</filter> | |
97 </output> | |
98 </outputs> | |
99 <tests> | |
100 <test expect_num_outputs="1"> | |
101 <conditional name="input_param_type"> | |
102 <param name="type" value="text"/> | |
103 <param name="input_param" value="A" /> | |
104 <repeat name="mappings"> | |
105 <param name="from" value="A" /> | |
106 <param name="to" value="B" /> | |
107 </repeat> | |
108 </conditional> | |
109 <output name="output_param_text" value_json=""B"" /> | |
110 </test> | |
111 <test expect_num_outputs="1"> | |
112 <conditional name="input_param_type"> | |
113 <param name="input_param" value="C" /> | |
114 <repeat name="mappings"> | |
115 <param name="from" value="A" /> | |
116 <param name="to" value="B" /> | |
117 </repeat> | |
118 </conditional> | |
119 <output name="output_param_text" value_json=""C"" /> | |
120 </test> | |
121 <test expect_num_outputs="1" expect_failure="true"> | |
122 <conditional name="input_param_type"> | |
123 <param name="input_param" value="C" /> | |
124 <repeat name="mappings"> | |
125 <param name="from" value="A" /> | |
126 <param name="to" value="B" /> | |
127 </repeat> | |
128 </conditional> | |
129 <conditional name="unmapped"> | |
130 <param name="on_unmapped" value="fail"/> | |
131 </conditional> | |
132 </test> | |
133 <test expect_num_outputs="1"> | |
134 <conditional name="input_param_type"> | |
135 <param name="input_param" value="C" /> | |
136 <repeat name="mappings"> | |
137 <param name="from" value="A" /> | |
138 <param name="to" value="B" /> | |
139 </repeat> | |
140 </conditional> | |
141 <conditional name="unmapped"> | |
142 <param name="on_unmapped" value="default"/> | |
143 <param name="default_value" value="D"/> | |
144 </conditional> | |
145 <param name="output_param_text" value_json=""D"" /> | |
146 </test> | |
147 <test expect_num_outputs="1"> | |
148 <conditional name="input_param_type"> | |
149 <param name="input_param" value="C" /> | |
150 <repeat name="mappings"> | |
151 <param name="from" value="A" /> | |
152 <param name="to" value="B" /> | |
153 </repeat> | |
154 </conditional> | |
155 <conditional name="unmapped"> | |
156 <param name="on_unmapped" value="default"/> | |
157 <param name="default_value" value="X"/> | |
158 </conditional> | |
159 <param name="output_param_text" value_json=""X"" /> | |
160 </test> | |
161 <test expect_num_outputs="1"> | |
162 <conditional name="input_param_type"> | |
163 <param name="input_param" value="C" /> | |
164 <repeat name="mappings"> | |
165 <param name="from" value="A" /> | |
166 <param name="to" value="B" /> | |
167 </repeat> | |
168 <repeat name="mappings"> | |
169 <param name="from" value="C" /> | |
170 <param name="to" value="D" /> | |
171 </repeat> | |
172 </conditional> | |
173 <param name="output_param_text" value_json=""D"" /> | |
174 </test> | |
175 <test expect_num_outputs="1"> | |
176 <conditional name="input_param_type"> | |
177 <param name="type" value="integer" /> | |
178 <param name="input_param" value="42" /> | |
179 <repeat name="mappings"> | |
180 <param name="from" value="42" /> | |
181 <param name="to" value="true" /> | |
182 </repeat> | |
183 </conditional> | |
184 <param name="output_param_type" value="boolean"/> | |
185 <param name="output_param_boolean" value_json="true" /> | |
186 </test> | |
187 <test expect_num_outputs="1"> | |
188 <conditional name="input_param_type"> | |
189 <param name="type" value="float" /> | |
190 <param name="input_param" value="1.2" /> | |
191 <repeat name="mappings"> | |
192 <param name="from" value="42" /> | |
193 <param name="to" value="true" /> | |
194 </repeat> | |
195 </conditional> | |
196 <conditional name="unmapped"> | |
197 <param name="on_unmapped" value="default"/> | |
198 <param name="default_value" value="False"/> | |
199 </conditional> | |
200 <param name="output_param_type" value="boolean"/> | |
201 <param name="output_param_boolean" value_json="false" /> | |
202 </test> | |
203 <test expect_num_outputs="1"> | |
204 <conditional name="input_param_type"> | |
205 <param name="type" value="integer" /> | |
206 <param name="input_param" value="1" /> | |
207 <repeat name="mappings"> | |
208 <param name="from" value="1" /> | |
209 <param name="to" value="1.1" /> | |
210 </repeat> | |
211 </conditional> | |
212 <param name="output_param_type" value="float"/> | |
213 <param name="output_param_float" value_json="1.1" /> | |
214 </test> | |
215 <test expect_num_outputs="1"> | |
216 <conditional name="input_param_type"> | |
217 <param name="type" value="string" /> | |
218 <param name="input_param" value="A" /> | |
219 <repeat name="mappings"> | |
220 <param name="from" value="A" /> | |
221 <param name="to" value="2" /> | |
222 </repeat> | |
223 </conditional> | |
224 <param name="output_param_type" value="integer"/> | |
225 <param name="output_param_float" value_json="2" /> | |
226 </test> | |
227 </tests> | |
228 <help><![CDATA[ | |
229 **What it does** | |
230 | |
231 Maps a parameter value to another value. | |
232 This can be used to transform any non-data value (text, integer, float and boolean) to a different value of a different type. | |
233 | |
234 **Settings** | |
235 | |
236 If the value is not found in the mapping the unmodified value is returned by default. | |
237 Select ``Fail if input parameter value not found in mappings`` if you wish the job to fail if an input could not be mapped. | |
238 | |
239 Select ``Provide a default value to use if input parameter value not found in mappings`` to provide a default value to use in case the input parameter value could not be mapped. | |
240 Select the proper input and output parameter types based on your workflow input and output connections. | |
241 | |
242 **Examples** | |
243 | |
244 You want a user to select from 3 simple options in a workflow, e.g. ``low``, ``medium``, ``high``, which correspond to distinct integer values. | |
245 | |
246 Turn ``Map this parameter value to a different value`` into a a connectable workflow input by clicking on "Add connection to module". | |
247 | |
248 Set the input parameter type to ``Text``, and add 3 mappings: | |
249 | |
250 .. | |
251 | |
252 #. | |
253 | |
254 * Map from this value: ``low`` | |
255 * to this value: ``1`` | |
256 | |
257 #. | |
258 | |
259 * Map from this value: ``medium`` | |
260 * to this value: ``2`` | |
261 | |
262 #. | |
263 | |
264 * Map from this value: ``high`` | |
265 * to this value: ``3`` | |
266 | |
267 Set ``Select type of parameter to output`` to ``Integer``. | |
268 You can now connect the output to any connectable Integer input in your workflow. | |
269 | |
270 ]]></help> | |
271 </tool> |