Mercurial > repos > iuc > map_param_value
comparison map_param_value.xml @ 1:e8d7ccfa372f draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/map_param_value commit 49eab9a9d601cccd50401e5a0221264b5681b64d
| author | iuc |
|---|---|
| date | Wed, 19 Oct 2022 11:36:53 +0000 |
| parents | 8d4a765f5bcb |
| children |
comparison
equal
deleted
inserted
replaced
| 0:8d4a765f5bcb | 1:e8d7ccfa372f |
|---|---|
| 1 <tool name="Map parameter value" id="map_param_value" version="0.1.0" tool_type="expression" profile="22.01"> | 1 <tool name="Map parameter value" id="map_param_value" version="0.1.1" tool_type="expression" profile="22.01"> |
| 2 <macros> | 2 <macros> |
| 3 <xml name="when_element" tokens="type_selection"> | 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"/> | 4 <param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Value to map"> |
| 5 <sanitizer sanitize="false"/> | |
| 6 </param> | |
| 5 <repeat name="mappings" label="Add value mapping"> | 7 <repeat name="mappings" label="Add value mapping"> |
| 6 <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"></param> | 8 <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"> |
| 7 <param name="to" type="text" label="to this value" help="This value must be coercable to the selected output parameter type"></param> | 9 <sanitizer sanitize="false"/> |
| 10 </param> | |
| 11 <param name="to" type="text" optional="true" label="to this value" help="This value must be coercable to the selected output parameter type"> | |
| 12 <sanitizer sanitize="false"/> | |
| 13 </param> | |
| 8 </repeat> | 14 </repeat> |
| 9 </xml> | 15 </xml> |
| 10 </macros> | 16 </macros> |
| 11 <expression type="ecma5.1"> | 17 <expression type="ecma5.1"> |
| 12 <![CDATA[{ | 18 <![CDATA[{ |
| 28 return value | 34 return value |
| 29 } | 35 } |
| 30 } | 36 } |
| 31 | 37 |
| 32 for ( var i = 0; i < mappings.length; i++ ) { | 38 for ( var i = 0; i < mappings.length; i++ ) { |
| 33 if ( String(mappings[i].from) == source ) { | 39 if ( String(mappings[i].from) == String(source) ) { |
| 34 return { output: coerceToOutput(mappings[i].to) }; | 40 return { output: coerceToOutput(mappings[i].to) }; |
| 35 } | 41 } |
| 36 } | 42 } |
| 37 if ( $job.unmapped.on_unmapped == "fail" ) { | 43 if ( $job.unmapped.on_unmapped == "fail" ) { |
| 38 return { __error_message: `text_param ${source} not found in mapping values.` }; | 44 return { __error_message: `input_param ${source} not found in mapping values.` }; |
| 39 } else if ( $job.unmapped.on_unmapped == "default" ) { | 45 } else if ( $job.unmapped.on_unmapped == "default" ) { |
| 40 return { output: coerceToOutput($job.unmapped.default_value) }; | 46 return { output: coerceToOutput($job.unmapped.default_value) }; |
| 41 } | 47 } |
| 42 return { output: coerceToOutput(source) }; | 48 return { output: coerceToOutput(source) }; |
| 43 }]]> | 49 }]]> |
| 61 </when> | 67 </when> |
| 62 <when value="boolean"> | 68 <when value="boolean"> |
| 63 <expand macro="when_element" type_selection="boolean"/> | 69 <expand macro="when_element" type_selection="boolean"/> |
| 64 </when> | 70 </when> |
| 65 </conditional> | 71 </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"> | 72 <conditional name="unmapped"> |
| 73 <param name="on_unmapped" type="select" label="Select how"> | 73 <param name="on_unmapped" type="select" label="Select how to handle unmapped values"> |
| 74 <option value="input">Use unmodified input parameter value if input parameter value not found in mappings</option> | 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> | 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> | 76 <option value="default">Provide a default value to use if input parameter value not found in mappings</option> |
| 77 </param> | 77 </param> |
| 78 <when value="input" /> | 78 <when value="input" /> |
| 79 <when value="fail" /> | 79 <when value="fail" /> |
| 80 <when value="default"> | 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"/> | 81 <param name="default_value" type="text" label="Use this value if the input parameter value was not found in mappings"/> |
| 82 </when> | 82 </when> |
| 83 </conditional> | 83 </conditional> |
| 84 <param name="output_param_type" type="select" label="Select type of parameter to output"> | |
| 85 <option value="text">Text</option> | |
| 86 <option value="integer">Integer</option> | |
| 87 <option value="float">Float</option> | |
| 88 <option value="boolean">Boolean</option> | |
| 89 </param> | |
| 84 </inputs> | 90 </inputs> |
| 85 <outputs> | 91 <outputs> |
| 86 <output type="text" name="output_param_text" from="output"> | 92 <output type="text" name="output_param_text" from="output"> |
| 87 <filter>output_param_type == 'text'</filter> | 93 <filter>output_param_type == 'text'</filter> |
| 88 </output> | 94 </output> |
| 96 <filter>output_param_type == 'boolean'</filter> | 102 <filter>output_param_type == 'boolean'</filter> |
| 97 </output> | 103 </output> |
| 98 </outputs> | 104 </outputs> |
| 99 <tests> | 105 <tests> |
| 100 <test expect_num_outputs="1"> | 106 <test expect_num_outputs="1"> |
| 107 <!-- map string A to string B --> | |
| 101 <conditional name="input_param_type"> | 108 <conditional name="input_param_type"> |
| 102 <param name="type" value="text"/> | 109 <param name="type" value="text"/> |
| 103 <param name="input_param" value="A" /> | 110 <param name="input_param" value="A" /> |
| 104 <repeat name="mappings"> | 111 <repeat name="mappings"> |
| 105 <param name="from" value="A" /> | 112 <param name="from" value="A" /> |
| 107 </repeat> | 114 </repeat> |
| 108 </conditional> | 115 </conditional> |
| 109 <output name="output_param_text" value_json=""B"" /> | 116 <output name="output_param_text" value_json=""B"" /> |
| 110 </test> | 117 </test> |
| 111 <test expect_num_outputs="1"> | 118 <test expect_num_outputs="1"> |
| 119 <!-- test that mapping works in the presence of usually sanitized characters --> | |
| 120 <conditional name="input_param_type"> | |
| 121 <param name="type" value="text"/> | |
| 122 <param name="input_param" value="echo $abc > 1" /> | |
| 123 <repeat name="mappings"> | |
| 124 <param name="from" value="echo $abc > 1" /> | |
| 125 <param name="to" value="echo $abc > 2" /> | |
| 126 </repeat> | |
| 127 </conditional> | |
| 128 <output name="output_param_text" value_json=""echo $abc > 2"" /> | |
| 129 </test> | |
| 130 <test expect_num_outputs="1"> | |
| 131 <!-- keep unmodified input if no match in mapping values --> | |
| 112 <conditional name="input_param_type"> | 132 <conditional name="input_param_type"> |
| 113 <param name="input_param" value="C" /> | 133 <param name="input_param" value="C" /> |
| 114 <repeat name="mappings"> | 134 <repeat name="mappings"> |
| 115 <param name="from" value="A" /> | 135 <param name="from" value="A" /> |
| 116 <param name="to" value="B" /> | 136 <param name="to" value="B" /> |
| 117 </repeat> | 137 </repeat> |
| 118 </conditional> | 138 </conditional> |
| 119 <output name="output_param_text" value_json=""C"" /> | 139 <output name="output_param_text" value_json=""C"" /> |
| 120 </test> | 140 </test> |
| 121 <test expect_num_outputs="1" expect_failure="true"> | 141 <test expect_failure="true"> |
| 142 <!-- fail job if no mapping found and on_unmapped is set to fail --> | |
| 122 <conditional name="input_param_type"> | 143 <conditional name="input_param_type"> |
| 123 <param name="input_param" value="C" /> | 144 <param name="input_param" value="C" /> |
| 124 <repeat name="mappings"> | 145 <repeat name="mappings"> |
| 125 <param name="from" value="A" /> | 146 <param name="from" value="A" /> |
| 126 <param name="to" value="B" /> | 147 <param name="to" value="B" /> |
| 129 <conditional name="unmapped"> | 150 <conditional name="unmapped"> |
| 130 <param name="on_unmapped" value="fail"/> | 151 <param name="on_unmapped" value="fail"/> |
| 131 </conditional> | 152 </conditional> |
| 132 </test> | 153 </test> |
| 133 <test expect_num_outputs="1"> | 154 <test expect_num_outputs="1"> |
| 134 <conditional name="input_param_type"> | 155 <!-- map unspecified option text to string default via unmapped default value --> |
| 135 <param name="input_param" value="C" /> | 156 <conditional name="input_param_type"> |
| 136 <repeat name="mappings"> | 157 <repeat name="mappings"> |
| 137 <param name="from" value="A" /> | 158 <param name="from" value="A" /> |
| 138 <param name="to" value="B" /> | 159 <param name="to" value="B" /> |
| 139 </repeat> | 160 </repeat> |
| 140 </conditional> | 161 </conditional> |
| 141 <conditional name="unmapped"> | 162 <conditional name="unmapped"> |
| 142 <param name="on_unmapped" value="default"/> | 163 <param name="on_unmapped" value="default"/> |
| 143 <param name="default_value" value="D"/> | 164 <param name="default_value" value="default"/> |
| 144 </conditional> | 165 </conditional> |
| 145 <param name="output_param_text" value_json=""D"" /> | 166 <output name="output_param_text" value_json=""default"" /> |
| 146 </test> | 167 </test> |
| 147 <test expect_num_outputs="1"> | 168 <test expect_num_outputs="1"> |
| 169 <!-- map string C to string X via default value --> | |
| 148 <conditional name="input_param_type"> | 170 <conditional name="input_param_type"> |
| 149 <param name="input_param" value="C" /> | 171 <param name="input_param" value="C" /> |
| 150 <repeat name="mappings"> | 172 <repeat name="mappings"> |
| 151 <param name="from" value="A" /> | 173 <param name="from" value="A" /> |
| 152 <param name="to" value="B" /> | 174 <param name="to" value="B" /> |
| 154 </conditional> | 176 </conditional> |
| 155 <conditional name="unmapped"> | 177 <conditional name="unmapped"> |
| 156 <param name="on_unmapped" value="default"/> | 178 <param name="on_unmapped" value="default"/> |
| 157 <param name="default_value" value="X"/> | 179 <param name="default_value" value="X"/> |
| 158 </conditional> | 180 </conditional> |
| 159 <param name="output_param_text" value_json=""X"" /> | 181 <output name="output_param_text" value_json=""X"" /> |
| 160 </test> | 182 </test> |
| 161 <test expect_num_outputs="1"> | 183 <test expect_num_outputs="1"> |
| 184 <!-- map string C to string D in presence of multiple mappings --> | |
| 162 <conditional name="input_param_type"> | 185 <conditional name="input_param_type"> |
| 163 <param name="input_param" value="C" /> | 186 <param name="input_param" value="C" /> |
| 164 <repeat name="mappings"> | 187 <repeat name="mappings"> |
| 165 <param name="from" value="A" /> | 188 <param name="from" value="A" /> |
| 166 <param name="to" value="B" /> | 189 <param name="to" value="B" /> |
| 168 <repeat name="mappings"> | 191 <repeat name="mappings"> |
| 169 <param name="from" value="C" /> | 192 <param name="from" value="C" /> |
| 170 <param name="to" value="D" /> | 193 <param name="to" value="D" /> |
| 171 </repeat> | 194 </repeat> |
| 172 </conditional> | 195 </conditional> |
| 173 <param name="output_param_text" value_json=""D"" /> | 196 <output name="output_param_text" value_json=""D"" /> |
| 174 </test> | 197 </test> |
| 175 <test expect_num_outputs="1"> | 198 <test expect_num_outputs="1"> |
| 199 <!-- map integer 42 to integer true value --> | |
| 176 <conditional name="input_param_type"> | 200 <conditional name="input_param_type"> |
| 177 <param name="type" value="integer" /> | 201 <param name="type" value="integer" /> |
| 178 <param name="input_param" value="42" /> | 202 <param name="input_param" value="42" /> |
| 179 <repeat name="mappings"> | 203 <repeat name="mappings"> |
| 180 <param name="from" value="42" /> | 204 <param name="from" value="42" /> |
| 181 <param name="to" value="true" /> | 205 <param name="to" value="true" /> |
| 182 </repeat> | 206 </repeat> |
| 183 </conditional> | 207 </conditional> |
| 184 <param name="output_param_type" value="boolean"/> | 208 <param name="output_param_type" value="boolean"/> |
| 185 <param name="output_param_boolean" value_json="true" /> | 209 <output name="output_param_boolean" value_json="true" /> |
| 186 </test> | 210 </test> |
| 187 <test expect_num_outputs="1"> | 211 <test expect_num_outputs="1"> |
| 212 <!-- map float 1.2 to boolean false via unmapped default value --> | |
| 188 <conditional name="input_param_type"> | 213 <conditional name="input_param_type"> |
| 189 <param name="type" value="float" /> | 214 <param name="type" value="float" /> |
| 190 <param name="input_param" value="1.2" /> | 215 <param name="input_param" value="1.2" /> |
| 191 <repeat name="mappings"> | 216 <repeat name="mappings"> |
| 192 <param name="from" value="42" /> | 217 <param name="from" value="42" /> |
| 196 <conditional name="unmapped"> | 221 <conditional name="unmapped"> |
| 197 <param name="on_unmapped" value="default"/> | 222 <param name="on_unmapped" value="default"/> |
| 198 <param name="default_value" value="False"/> | 223 <param name="default_value" value="False"/> |
| 199 </conditional> | 224 </conditional> |
| 200 <param name="output_param_type" value="boolean"/> | 225 <param name="output_param_type" value="boolean"/> |
| 201 <param name="output_param_boolean" value_json="false" /> | 226 <output name="output_param_boolean" value_json="false" /> |
| 202 </test> | 227 </test> |
| 203 <test expect_num_outputs="1"> | 228 <test expect_num_outputs="1"> |
| 229 <!-- map integer 1 to float 1.1 --> | |
| 204 <conditional name="input_param_type"> | 230 <conditional name="input_param_type"> |
| 205 <param name="type" value="integer" /> | 231 <param name="type" value="integer" /> |
| 206 <param name="input_param" value="1" /> | 232 <param name="input_param" value="1" /> |
| 207 <repeat name="mappings"> | 233 <repeat name="mappings"> |
| 208 <param name="from" value="1" /> | 234 <param name="from" value="1" /> |
| 209 <param name="to" value="1.1" /> | 235 <param name="to" value="1.1" /> |
| 210 </repeat> | 236 </repeat> |
| 211 </conditional> | 237 </conditional> |
| 212 <param name="output_param_type" value="float"/> | 238 <param name="output_param_type" value="float"/> |
| 213 <param name="output_param_float" value_json="1.1" /> | 239 <output name="output_param_float" value_json="1.1" /> |
| 214 </test> | 240 </test> |
| 215 <test expect_num_outputs="1"> | 241 <test expect_num_outputs="1"> |
| 216 <conditional name="input_param_type"> | 242 <!-- map string A to integer 2 --> |
| 217 <param name="type" value="string" /> | 243 <conditional name="input_param_type"> |
| 244 <param name="type" value="text" /> | |
| 218 <param name="input_param" value="A" /> | 245 <param name="input_param" value="A" /> |
| 219 <repeat name="mappings"> | 246 <repeat name="mappings"> |
| 220 <param name="from" value="A" /> | 247 <param name="from" value="A" /> |
| 221 <param name="to" value="2" /> | 248 <param name="to" value="2" /> |
| 222 </repeat> | 249 </repeat> |
| 223 </conditional> | 250 </conditional> |
| 224 <param name="output_param_type" value="integer"/> | 251 <param name="output_param_type" value="integer"/> |
| 225 <param name="output_param_float" value_json="2" /> | 252 <output name="output_param_integer" value_json="2" /> |
| 226 </test> | 253 </test> |
| 254 <test expect_num_outputs="1">A | |
| 255 <!-- map string False to boolean false --> | |
| 256 <conditional name="input_param_type"> | |
| 257 <param name="type" value="text" /> | |
| 258 <param name="input_param" value="False" /> | |
| 259 <repeat name="mappings"> | |
| 260 <param name="from" value="False" /> | |
| 261 <param name="to" value="false" /> | |
| 262 </repeat> | |
| 263 </conditional> | |
| 264 <conditional name="unmapped"> | |
| 265 <param name="on_unmapped" value="fail"/> | |
| 266 </conditional> | |
| 267 <param name="output_param_type" value="boolean"/> | |
| 268 <output name="output_param_boolean" value_json="false" /> | |
| 269 </test> | |
| 270 <test expect_num_outputs="1"> | |
| 271 <!-- map boolean false to boolean true --> | |
| 272 <conditional name="input_param_type"> | |
| 273 <param name="type" value="boolean" /> | |
| 274 <param name="input_param" value="false" /> | |
| 275 <repeat name="mappings"> | |
| 276 <param name="from" value="false" /> | |
| 277 <param name="to" value="true" /> | |
| 278 </repeat> | |
| 279 </conditional> | |
| 280 <conditional name="unmapped"> | |
| 281 <param name="on_unmapped" value="fail"/> | |
| 282 </conditional> | |
| 283 <param name="output_param_type" value="boolean"/> | |
| 284 <output name="output_param_boolean" value_json="true" /> | |
| 285 </test> | |
| 286 <test expect_num_outputs="1"> | |
| 287 <!-- map integer 0 to boolean false via default value coercion --> | |
| 288 <conditional name="input_param_type"> | |
| 289 <param name="type" value="integer" /> | |
| 290 <param name="input_param" value="0" /> | |
| 291 </conditional> | |
| 292 <param name="output_param_type" value="boolean"/> | |
| 293 <output name="output_param_boolean" value_json="false" /> | |
| 294 </test> | |
| 295 <test expect_num_outputs="1"> | |
| 296 <!-- map null text value to boolean true --> | |
| 297 <conditional name="input_param_type"> | |
| 298 <param name="type" value="text" /> | |
| 299 <param name="input_param" value_json="null" /> | |
| 300 <repeat name="mappings"> | |
| 301 <param name="from" value_json="null" /> | |
| 302 <param name="to" value="true" /> | |
| 303 </repeat> | |
| 304 </conditional> | |
| 305 <param name="output_param_type" value="boolean"/> | |
| 306 <output name="output_param_boolean" value_json="true" /> | |
| 307 </test> | |
| 308 <test expect_num_outputs="1" doc="map null integer value to boolean true"> | |
| 309 <!-- map null integer value to boolean true --> | |
| 310 <conditional name="input_param_type"> | |
| 311 <param name="type" value="integer" /> | |
| 312 <param name="input_param" value_json="null" /> | |
| 313 <repeat name="mappings"> | |
| 314 <param name="from" value_json="null" /> | |
| 315 <param name="to" value="true" /> | |
| 316 </repeat> | |
| 317 </conditional> | |
| 318 <param name="output_param_type" value="boolean"/> | |
| 319 <output name="output_param_boolean" value_json="true" /> | |
| 320 </test> | |
| 321 <test expect_num_outputs="1"> | |
| 322 <!-- map integer value to null text --> | |
| 323 <conditional name="input_param_type"> | |
| 324 <param name="type" value="integer" /> | |
| 325 <param name="input_param" value="1" /> | |
| 326 <repeat name="mappings"> | |
| 327 <param name="from" value="1" /> | |
| 328 <param name="to" value_json="null" /> | |
| 329 </repeat> | |
| 330 </conditional> | |
| 331 <param name="output_param_type" value="text"/> | |
| 332 <output name="output_param_text" value_json="null" /> | |
| 333 </test> | |
| 334 <!-- Old Galaxy issue, optional unset text input still recorded as "" | |
| 335 We could work around this with a conditional, but no usecase yet | |
| 336 and we should better fix this in Galaxy | |
| 337 <test expect_num_outputs="1"> | |
| 338 <conditional name="input_param_type"> | |
| 339 <param name="input_param" value="A" /> | |
| 340 <repeat name="mappings"> | |
| 341 <param name="from" value="A" /> | |
| 342 </repeat> | |
| 343 </conditional> | |
| 344 <output name="output_param_text" value_json="null" /> | |
| 345 </test> | |
| 346 --> | |
| 227 </tests> | 347 </tests> |
| 228 <help><