Repository 'map_param_value'
hg clone https://toolshed.g2.bx.psu.edu/repos/iuc/map_param_value

Changeset 0:43d7b3642a30 (2022-10-16)
Next changeset 1:a01f088d0e5e (2022-10-19)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/map_param_value commit 9cbf1d6cb6a59b8b4172d09449aac695ba10687d
added:
map_param_value.xml
b
diff -r 000000000000 -r 43d7b3642a30 map_param_value.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/map_param_value.xml Sun Oct 16 08:05:37 2022 +0000
[
b'@@ -0,0 +1,271 @@\n+<tool name="Map parameter value" id="map_param_value" version="0.1.0" tool_type="expression" profile="22.01">\n+    <macros>\n+        <xml name="when_element" tokens="type_selection">\n+            <param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Map this parameter value to a different value"/>\n+            <repeat name="mappings" label="Add value mapping">\n+                <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"></param>\n+                <param name="to" type="text" label="to this value" help="This value must be coercable to the selected output parameter type"></param>\n+            </repeat>\n+        </xml>\n+    </macros>\n+    <expression type="ecma5.1">\n+        <![CDATA[{\n+const source = $job.input_param_type.input_param;\n+const mappings = $job.input_param_type.mappings;\n+\n+const coerceToOutput = function(value) {\n+    switch($job.output_param_type) {\n+        case "integer":\n+            return parseInt(value)\n+        case "float":\n+            return parseFloat(value)\n+        case "boolean":\n+            if (value == "false" || value == "False") {\n+                return false\n+            }\n+            return !!value\n+        case "text":\n+            return value\n+    }\n+}\n+\n+for ( var i = 0; i < mappings.length; i++ ) {\n+    if ( String(mappings[i].from) == source ) {\n+        return { output: coerceToOutput(mappings[i].to) };\n+    }\n+}\n+if ( $job.unmapped.on_unmapped == "fail" ) {\n+    return { __error_message: `text_param ${source} not found in mapping values.` };\n+} else if ( $job.unmapped.on_unmapped == "default" ) {\n+    return { output: coerceToOutput($job.unmapped.default_value) };\n+}\n+return { output: coerceToOutput(source) };\n+}]]>\n+    </expression>\n+    <inputs>\n+        <conditional name="input_param_type">\n+            <param name="type" type="select" label="Select type of input parameter to match">\n+                <option value="text" selected="true">Text</option>\n+                <option value="integer">Integer</option>\n+                <option value="float">Float</option>\n+                <option value="boolean">Boolean</option>\n+            </param>\n+            <when value="text">\n+                <expand macro="when_element" type_selection="text"/>\n+            </when>\n+            <when value="integer">\n+                <expand macro="when_element" type_selection="integer"/>\n+            </when>\n+            <when value="float">\n+                <expand macro="when_element" type_selection="float"/>\n+            </when>\n+            <when value="boolean">\n+                <expand macro="when_element" type_selection="boolean"/>\n+            </when>\n+        </conditional>\n+        <param name="output_param_type" type="select" label="Select type of parameter to output">\n+            <option value="text">Text</option>\n+            <option value="integer">Integer</option>\n+            <option value="float">Float</option>\n+            <option value="boolean">Boolean</option>\n+        </param>\n+        <conditional name="unmapped">\n+            <param name="on_unmapped" type="select" label="Select how">\n+                <option value="input">Use unmodified input parameter value if input parameter value not found in mappings</option>\n+                <option value="fail">Fail if input parameter value not found in mappings</option>\n+                <option value="default">Provide a default value to use if input parameter value not found in mappings</option>\n+            </param>\n+            <when value="input" />\n+            <when value="fail" />\n+            <when value="default">\n+                <param name="default_value" type="text" label="Use this value if the input parameter value was not found in mappings"/>\n+            </when>\n+        </conditional>\n+    </inputs>\n+    <outputs>\n+        <output type="text" name="output_param_text" from="output">\n+            <filter>output_param_type == \'text\'</filter>\n'..b'         <param name="output_param_text" value_json="&quot;D&quot;" />\n+        </test>\n+        <test expect_num_outputs="1">\n+            <conditional name="input_param_type">\n+                <param name="type" value="integer" />\n+                <param name="input_param" value="42" />\n+                <repeat name="mappings">\n+                    <param name="from" value="42" />\n+                    <param name="to" value="true" />\n+                </repeat>\n+            </conditional>\n+            <param name="output_param_type" value="boolean"/>\n+            <param name="output_param_boolean" value_json="true" />\n+        </test>\n+        <test expect_num_outputs="1">\n+            <conditional name="input_param_type">\n+                <param name="type" value="float" />\n+                <param name="input_param" value="1.2" />\n+                <repeat name="mappings">\n+                    <param name="from" value="42" />\n+                    <param name="to" value="true" />\n+                </repeat>\n+            </conditional>\n+            <conditional name="unmapped">\n+                <param name="on_unmapped" value="default"/>\n+                <param name="default_value" value="False"/>\n+            </conditional>\n+            <param name="output_param_type" value="boolean"/>\n+            <param name="output_param_boolean" value_json="false" />\n+        </test>\n+        <test expect_num_outputs="1">\n+            <conditional name="input_param_type">\n+                <param name="type" value="integer" />\n+                <param name="input_param" value="1" />\n+                <repeat name="mappings">\n+                    <param name="from" value="1" />\n+                    <param name="to" value="1.1" />\n+                </repeat>\n+            </conditional>\n+            <param name="output_param_type" value="float"/>\n+            <param name="output_param_float" value_json="1.1" />\n+        </test>\n+        <test expect_num_outputs="1">\n+            <conditional name="input_param_type">\n+                <param name="type" value="string" />\n+                <param name="input_param" value="A" />\n+                <repeat name="mappings">\n+                    <param name="from" value="A" />\n+                    <param name="to" value="2" />\n+                </repeat>\n+            </conditional>\n+            <param name="output_param_type" value="integer"/>\n+            <param name="output_param_float" value_json="2" />\n+        </test>\n+    </tests>\n+    <help><![CDATA[\n+**What it does**\n+\n+Maps a parameter value to another value.\n+This can be used to transform any non-data value (text, integer, float and boolean) to a different value of a different type.\n+\n+**Settings**\n+\n+ If the value is not found in the mapping the unmodified value is returned by default.\n+ Select ``Fail if input parameter value not found in mappings`` if you wish the job to fail if an input could not be mapped.\n+\n+ 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.\n+ Select the proper input and output parameter types based on your workflow input and output connections.\n+\n+**Examples**\n+\n+You want a user to select from 3 simple options in a workflow, e.g. ``low``, ``medium``, ``high``, which correspond to distinct integer values.\n+\n+Turn ``Map this parameter value to a different value`` into a a connectable workflow input by clicking on "Add connection to module".\n+\n+Set the input parameter type to ``Text``, and add 3 mappings:\n+\n+..\n+\n+  #.\n+\n+    * Map from this value: ``low``\n+    * to this value: ``1``\n+\n+  #.\n+\n+    * Map from this value: ``medium``\n+    * to this value: ``2``\n+\n+  #.\n+\n+    * Map from this value: ``high``\n+    * to this value: ``3``\n+\n+Set ``Select type of parameter to output`` to ``Integer``.\n+You can now connect the output to any connectable Integer input in your workflow.\n+\n+    ]]></help>\n+</tool>\n'