mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 12:13:33 +08:00
Allow including paths in inputs json files.
This commit is contained in:
@@ -803,7 +803,8 @@ class Tool(Dictifiable):
|
||||
name = inputs_elem.get("name")
|
||||
filename = inputs_elem.get("filename", None)
|
||||
format = inputs_elem.get("format", "json")
|
||||
content = dict(format=format)
|
||||
data_style = inputs_elem.get("data_style", "skip")
|
||||
content = dict(format=format, handle_files=data_style)
|
||||
self.config_files.append((name, filename, content))
|
||||
for conf_elem in conf_parent_elem.findall("configfile"):
|
||||
name = conf_elem.get("name")
|
||||
|
||||
@@ -561,12 +561,13 @@ class ToolEvaluator(object):
|
||||
return content, True
|
||||
|
||||
content_format = content["format"]
|
||||
handle_files = content["handle_files"]
|
||||
if content_format != "json":
|
||||
template = "Galaxy can only currently convert inputs to json, format [%s] is unhandled"
|
||||
message = template % content_format
|
||||
raise Exception(message)
|
||||
|
||||
return json.dumps(wrapped_json.json_wrap(self.tool.inputs, self.param_dict)), False
|
||||
return json.dumps(wrapped_json.json_wrap(self.tool.inputs, self.param_dict, handle_files=handle_files)), False
|
||||
|
||||
def __write_workdir_file(self, config_filename, content, context, is_template=True):
|
||||
if is_template:
|
||||
|
||||
@@ -5,7 +5,7 @@ log = logging.getLogger(__name__)
|
||||
SKIP_INPUT = object()
|
||||
|
||||
|
||||
def json_wrap(inputs, input_values, as_dict=None, handle_files="SKIP"):
|
||||
def json_wrap(inputs, input_values, as_dict=None, handle_files="skip"):
|
||||
if as_dict is None:
|
||||
as_dict = {}
|
||||
|
||||
@@ -19,8 +19,15 @@ def json_wrap(inputs, input_values, as_dict=None, handle_files="SKIP"):
|
||||
return as_dict
|
||||
|
||||
|
||||
def _json_wrap_input(input, value, handle_files="SKIP"):
|
||||
def _json_wrap_input(input, value, handle_files="skip"):
|
||||
input_type = input.type
|
||||
|
||||
def _data_input_to_path(v):
|
||||
path = _cast_if_not_none(v, str)
|
||||
if path == "None":
|
||||
path = None
|
||||
return path
|
||||
|
||||
if input_type == "repeat":
|
||||
repeat_job_value = []
|
||||
for d in value:
|
||||
@@ -44,15 +51,21 @@ def _json_wrap_input(input, value, handle_files="SKIP"):
|
||||
json_wrap(input.inputs, values, section_job_value)
|
||||
json_value = section_job_value
|
||||
elif input_type == "data" and input.multiple:
|
||||
if handle_files == "SKIP":
|
||||
if handle_files == "paths":
|
||||
json_value = list(map(_data_input_to_path, value))
|
||||
elif handle_files == "skip":
|
||||
return SKIP_INPUT
|
||||
raise NotImplementedError()
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
elif input_type == "data":
|
||||
if handle_files == "SKIP":
|
||||
if handle_files == "paths":
|
||||
json_value = _data_input_to_path(value)
|
||||
elif handle_files == "skip":
|
||||
return SKIP_INPUT
|
||||
raise NotImplementedError()
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
elif input_type == "data_collection":
|
||||
if handle_files == "SKIP":
|
||||
if handle_files == "skip":
|
||||
return SKIP_INPUT
|
||||
raise NotImplementedError()
|
||||
elif input_type in ["select", "text", "color", "hidden"]:
|
||||
|
||||
@@ -4549,7 +4549,7 @@ the path to the file created with this directive.</xs:documentation>
|
||||
<xs:documentation xml:lang="en"><.
|
||||
|
||||
By default this file will not contain paths for data or collection inputs. To include simple
|
||||
paths for data parameters set the ``data_style`` attribute to ``paths`` (see [inputs_as_json_with_paths.xml](https://github.com/galaxyproject/galaxy/blob/dev/test/functional/tools/inputs_as_json_with_paths.xml) for an example).
|
||||
]]></xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:simpleContent>
|
||||
@@ -4590,6 +4593,11 @@ response to this directive.
|
||||
<xs:documentation xml:lang="en">Path relative to the working directory of the tool for the inputs JSON file created in response to this directive.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="data_stype" type="xs:string">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Set to 'paths' to include dataset paths in the resulting file.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
<tool id="inputs_as_json_with_paths" name="inputs_as_json_with_paths" version="1.0.0" profile="18.09">
|
||||
<command detect_errors="exit_code">
|
||||
python '$check_inputs' '$inputs' $test_case
|
||||
</command>
|
||||
<configfiles>
|
||||
<inputs name="inputs" data_style="paths" />
|
||||
<!-- Can specify with fixed path in working directory instead:
|
||||
<inputs name="inputs" filename="input.json" />
|
||||
-->
|
||||
<configfile name="check_inputs"><![CDATA[
|
||||
import json
|
||||
import sys
|
||||
|
||||
input_json_path = sys.argv[1]
|
||||
test_case = sys.argv[2]
|
||||
as_dict = json.load(open(input_json_path, "r"))
|
||||
|
||||
|
||||
def assert_equals(x, y):
|
||||
assert x == y, "%s != %s" % (x, y)
|
||||
|
||||
if test_case == "1":
|
||||
assert_equals(as_dict["test_case"], 1)
|
||||
assert_equals(as_dict["text_test"], "foo")
|
||||
assert_equals(as_dict["booltest"], True)
|
||||
assert_equals(as_dict["booltest2"], True)
|
||||
assert_equals(as_dict["inttest"], 12456)
|
||||
assert_equals(as_dict["floattest"], 6.789)
|
||||
assert_equals(as_dict["radio_select"], "a_radio")
|
||||
assert_equals(as_dict["repeat"][0]["r"], "000000")
|
||||
assert_equals(as_dict["repeat"][1]["r"], "FFFFFF")
|
||||
assert_equals(as_dict["cond"]["more_text"], "fdefault")
|
||||
assert_equals(as_dict["section_example"]["section_text"], "section_default")
|
||||
assert_equals(as_dict["data_input"], None)
|
||||
elif test_case == "2":
|
||||
assert_equals(as_dict["test_case"], 2)
|
||||
assert_equals(as_dict["text_test"], "bar")
|
||||
assert_equals(as_dict["booltest"], False)
|
||||
assert_equals(as_dict["booltest2"], False)
|
||||
assert_equals(as_dict["inttest"], None)
|
||||
assert_equals(as_dict["floattest"], 1.0)
|
||||
assert_equals(as_dict["radio_select"], "a_radio")
|
||||
assert_equals(as_dict["repeat"][0]["r"], "000000")
|
||||
assert_equals(as_dict["cond"]["cond_test"], "second")
|
||||
assert_equals(as_dict["cond"]["more_text"], "sdefault")
|
||||
assert_equals(as_dict["section_example"]["section_text"], "section_default")
|
||||
data_input = as_dict["data_input"]
|
||||
assert data_input is not None
|
||||
|
||||
with open("output", "w") as f:
|
||||
f.write("okay\n")
|
||||
]]></configfile>
|
||||
</configfiles>
|
||||
<inputs>
|
||||
<param name="test_case" type="integer" value="0" />
|
||||
<param name="text_test" type="text" />
|
||||
<param name="booltest" truevalue="booltrue" falsevalue="boolfalse" checked="false" type="boolean" />
|
||||
<param name="booltest2" truevalue="booltrue" falsevalue="boolfalse" checked="false" type="boolean" />
|
||||
<param name="inttest" type="integer" optional="true" />
|
||||
<param name="floattest" value="1.0" type="float" />
|
||||
<param name="radio_select" type="select" display="radio">
|
||||
<option value="a_radio" selected="true">A Radio</option>
|
||||
<option value="b_radio">B Radio</option>
|
||||
<option value="c_radio">C Radio</option>
|
||||
</param>
|
||||
<param name="data_input" type="data" optional="true" />
|
||||
<repeat name="repeat" title="Repeat" min="1">
|
||||
<param name="r" type="color" />
|
||||
</repeat>
|
||||
<conditional name="cond">
|
||||
<param name="cond_test" type="select">
|
||||
<option value="first" selected="true">First</option>
|
||||
<option value="second">Second</option>
|
||||
</param>
|
||||
<when value="first">
|
||||
<param name="more_text" type="text" value="fdefault" />
|
||||
</when>
|
||||
<when value="second">
|
||||
<param name="more_text" type="text" value="sdefault" />
|
||||
</when>
|
||||
</conditional>
|
||||
<section name="section_example" title="Section Example">
|
||||
<param name="section_text" type="text" value="section_default" />
|
||||
</section>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data name="out_file1" from_work_dir="output" format="txt" />
|
||||
</outputs>
|
||||
<tests>
|
||||
<test>
|
||||
<param name="test_case" value="1" />
|
||||
<param name="text_test" value="foo" />
|
||||
<param name="booltest" value="true" />
|
||||
<param name="booltest2" value="booltrue" />
|
||||
<param name="inttest" value="12456" />
|
||||
<param name="floattest" value="6.789" />
|
||||
<repeat name="repeat">
|
||||
<param name="r" value="000000"/>
|
||||
</repeat>
|
||||
<repeat name="repeat">
|
||||
<param name="r" value="FFFFFF"/>
|
||||
</repeat>
|
||||
<conditional name="cond">
|
||||
<param name="cond_test" value="first" />
|
||||
</conditional>
|
||||
<output name="out_file1">
|
||||
<assert_contents>
|
||||
<has_line line="okay" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<param name="test_case" value="2" />
|
||||
<param name="text_test" value="bar" />
|
||||
<param name="booltest" value="false" />
|
||||
<param name="booltest2" value="boolfalse" />
|
||||
<param name="data_input" value="simple_line.txt" />
|
||||
<!-- Testing null integers -->
|
||||
<!-- <param name="inttest" value="12456" /> -->
|
||||
<param name="r" value="000000" />
|
||||
<conditional name="cond">
|
||||
<param name="cond_test" value="second" />
|
||||
</conditional>
|
||||
<output name="out_file1">
|
||||
<assert_contents>
|
||||
<has_line line="okay" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
</tests>
|
||||
<help>
|
||||
Test tool demonstrating the special inputs config file.
|
||||
</help>
|
||||
</tool>
|
||||
@@ -29,6 +29,7 @@
|
||||
<tool file="tool_provided_metadata_9.xml" />
|
||||
<tool file="empty_datasets.xml" />
|
||||
<tool file="inputs_as_json.xml" />
|
||||
<tool file="inputs_as_json_with_paths.xml" />
|
||||
<tool file="dbkey_filter_input.xml" />
|
||||
<tool file="dbkey_filter_multi_input.xml" />
|
||||
<tool file="dbkey_output_action.xml" />
|
||||
|
||||
Reference in New Issue
Block a user