mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
97 lines
3.7 KiB
XML
97 lines
3.7 KiB
XML
<tool name="Parse parameter value" id="param_value_from_file" version="0.1.0" tool_type="expression" profile="19.05">
|
|
<description>from dataset</description>
|
|
<macros>
|
|
<import>expression_macros.xml</import>
|
|
</macros>
|
|
<expression type="ecma5.1">{
|
|
var output;
|
|
if ($job.remove_newlines || $job.param_type != 'text') {
|
|
$job.input1.contents = $job.input1.contents.trim();
|
|
}
|
|
if ($job.param_type == 'integer') {
|
|
output = parseInt($job.input1.contents);
|
|
} else if ($job.param_type == 'float') {
|
|
output = parseFloat($job.input1.contents);
|
|
} else if ($job.param_type == 'boolean') {
|
|
const trueValues = ['yes', 'true', '1']
|
|
const falseValues = ['no', 'false', '0']
|
|
let lowerCaseContents = $job.input1.contents.toLowerCase();
|
|
if (trueValues.includes(lowerCaseContents)) {
|
|
output = true;
|
|
} else if (falseValues.includes(lowerCaseContents)) {
|
|
output = false;
|
|
}
|
|
else {
|
|
return 'NOT A BOOLEAN VALUE';
|
|
}
|
|
} else {
|
|
output = $job.input1.contents;
|
|
}
|
|
return {'output': output};
|
|
}</expression>
|
|
<inputs>
|
|
<param type="data" label="Input file containing parameter to parse out of" load_contents="64000" name="input1" />
|
|
<param name="param_type" type="select" label="Select type of parameter to parse">
|
|
<option value="text">Text</option>
|
|
<option value="integer">Integer</option>
|
|
<option value="float">Float</option>
|
|
<option value="boolean">Boolean</option>
|
|
</param>
|
|
<param name="remove_newlines" checked="true" type="boolean" label="Remove newlines ?" help="Uncheck this only if newlines should be preserved in parameter"/>
|
|
</inputs>
|
|
<expand macro="typed_outputs" />
|
|
<tests>
|
|
<test expect_num_outputs="1">
|
|
<param name="input1" value="simple_line.txt"/>
|
|
<param name="param_type" value="text"/>
|
|
<param name="remove_newlines" value="true"/>
|
|
<output name="text_param">
|
|
<assert_contents>
|
|
<has_line line=""This is a line of text.""/>
|
|
</assert_contents>
|
|
</output>
|
|
</test>
|
|
<test expect_num_outputs="1">
|
|
<param name="input1" value="simple_line.txt"/>
|
|
<param name="param_type" value="text"/>
|
|
<param name="remove_newlines" value="false"/>
|
|
<output name="text_param">
|
|
<assert_contents>
|
|
<has_line line=""This is a line of text.\n""/>
|
|
</assert_contents>
|
|
</output>
|
|
</test>
|
|
<test expect_num_outputs="1">
|
|
<param name="input1" value="1.integer.txt"/>
|
|
<param name="param_type" value="integer"/>
|
|
<param name="remove_newlines" value="false"/>
|
|
<output name="integer_param">
|
|
<assert_contents>
|
|
<has_line line="1"/>
|
|
</assert_contents>
|
|
</output>
|
|
</test>
|
|
<test expect_num_outputs="1">
|
|
<param name="input1" value="1.integer.txt"/>
|
|
<param name="param_type" value="float"/>
|
|
<param name="remove_newlines" value="false"/>
|
|
<output name="float_param">
|
|
<assert_contents>
|
|
<has_line line="1"/>
|
|
</assert_contents>
|
|
</output>
|
|
</test>
|
|
<test expect_num_outputs="1">
|
|
<param name="input1" value="1.bool.txt"/>
|
|
<param name="param_type" value="boolean"/>
|
|
<param name="remove_newlines" value="false"/>
|
|
<output name="boolean_param">
|
|
<assert_contents>
|
|
<has_line line="false"/>
|
|
</assert_contents>
|
|
</output>
|
|
</test>
|
|
</tests>
|
|
<help></help>
|
|
</tool>
|