Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/galaxy/tool_util/parser/cwl.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 import logging | |
2 import os | |
3 from collections import OrderedDict | |
4 | |
5 from galaxy.tool_util.cwl.parser import tool_proxy | |
6 from galaxy.tool_util.deps import requirements | |
7 from .interface import ( | |
8 PageSource, | |
9 PagesSource, | |
10 ToolSource, | |
11 ) | |
12 from .output_actions import ToolOutputActionGroup | |
13 from .output_objects import ToolOutput | |
14 from .stdio import ( | |
15 StdioErrorLevel, | |
16 ToolStdioExitCode, | |
17 ) | |
18 from .yaml import YamlInputSource | |
19 | |
20 log = logging.getLogger(__name__) | |
21 | |
22 | |
23 class CwlToolSource(ToolSource): | |
24 | |
25 def __init__(self, tool_file, strict_cwl_validation=True): | |
26 self._cwl_tool_file = tool_file | |
27 self._id, _ = os.path.splitext(os.path.basename(tool_file)) | |
28 self._tool_proxy = None | |
29 self._source_path = tool_file | |
30 self._strict_cwl_validation = strict_cwl_validation | |
31 | |
32 @property | |
33 def source_path(self): | |
34 return self._source_path | |
35 | |
36 @property | |
37 def tool_proxy(self): | |
38 if self._tool_proxy is None: | |
39 self._tool_proxy = tool_proxy(self._source_path, strict_cwl_validation=self._strict_cwl_validation) | |
40 return self._tool_proxy | |
41 | |
42 def parse_tool_type(self): | |
43 return 'cwl' | |
44 | |
45 def parse_id(self): | |
46 return self._id | |
47 | |
48 def parse_name(self): | |
49 return self.tool_proxy.label() or self.parse_id() | |
50 | |
51 def parse_command(self): | |
52 return "$__cwl_command" | |
53 | |
54 def parse_environment_variables(self): | |
55 environment_variables = [] | |
56 # TODO: Is this even possible from here, should instead this be moved | |
57 # into the job. | |
58 | |
59 # for environment_variable_el in environment_variables_el.findall("environment_variable"): | |
60 # definition = { | |
61 # "name": environment_variable_el.get("name"), | |
62 # "template": environment_variable_el.text, | |
63 # } | |
64 # environment_variables.append( | |
65 # definition | |
66 # ) | |
67 | |
68 return environment_variables | |
69 | |
70 def parse_edam_operations(self): | |
71 return [] | |
72 | |
73 def parse_edam_topics(self): | |
74 return [] | |
75 | |
76 def parse_help(self): | |
77 return self.tool_proxy.doc() | |
78 | |
79 def parse_sanitize(self): | |
80 return False | |
81 | |
82 def parse_strict_shell(self): | |
83 return True | |
84 | |
85 def parse_stdio(self): | |
86 # TODO: remove duplication with YAML | |
87 # New format - starting out just using exit code. | |
88 exit_code_lower = ToolStdioExitCode() | |
89 exit_code_lower.range_start = float("-inf") | |
90 exit_code_lower.range_end = -1 | |
91 exit_code_lower.error_level = StdioErrorLevel.FATAL | |
92 exit_code_high = ToolStdioExitCode() | |
93 exit_code_high.range_start = 1 | |
94 exit_code_high.range_end = float("inf") | |
95 exit_code_lower.error_level = StdioErrorLevel.FATAL | |
96 return [exit_code_lower, exit_code_high], [] | |
97 | |
98 def parse_interpreter(self): | |
99 return None | |
100 | |
101 def parse_version(self): | |
102 return "0.0.1" | |
103 | |
104 def parse_description(self): | |
105 return self.tool_proxy.description() | |
106 | |
107 def parse_interactivetool(self): | |
108 return [] | |
109 | |
110 def parse_input_pages(self): | |
111 page_source = CwlPageSource(self.tool_proxy) | |
112 return PagesSource([page_source]) | |
113 | |
114 def parse_outputs(self, tool): | |
115 output_instances = self.tool_proxy.output_instances() | |
116 outputs = OrderedDict() | |
117 output_defs = [] | |
118 for output_instance in output_instances: | |
119 output_defs.append(self._parse_output(tool, output_instance)) | |
120 # TODO: parse outputs collections | |
121 for output_def in output_defs: | |
122 outputs[output_def.name] = output_def | |
123 return outputs, OrderedDict() | |
124 | |
125 def _parse_output(self, tool, output_instance): | |
126 name = output_instance.name | |
127 # TODO: handle filters, actions, change_format | |
128 output = ToolOutput(name) | |
129 if "File" in output_instance.output_data_type: | |
130 output.format = "_sniff_" | |
131 else: | |
132 output.format = "expression.json" | |
133 output.change_format = [] | |
134 output.format_source = None | |
135 output.metadata_source = "" | |
136 output.parent = None | |
137 output.label = None | |
138 output.count = None | |
139 output.filters = [] | |
140 output.tool = tool | |
141 output.hidden = "" | |
142 output.dataset_collector_descriptions = [] | |
143 output.actions = ToolOutputActionGroup(output, None) | |
144 return output | |
145 | |
146 def parse_requirements_and_containers(self): | |
147 containers = [] | |
148 docker_identifier = self.tool_proxy.docker_identifier() | |
149 if docker_identifier: | |
150 containers.append({"type": "docker", | |
151 "identifier": docker_identifier}) | |
152 | |
153 software_requirements = self.tool_proxy.software_requirements() | |
154 return requirements.parse_requirements_from_dict(dict( | |
155 requirements=list(map(lambda r: {"name": r[0], "version": r[1], "type": "package"}, software_requirements)), | |
156 containers=containers, | |
157 )) | |
158 | |
159 def parse_profile(self): | |
160 return "16.04" | |
161 | |
162 def parse_python_template_version(self): | |
163 return '3.5' | |
164 | |
165 | |
166 class CwlPageSource(PageSource): | |
167 | |
168 def __init__(self, tool_proxy): | |
169 cwl_instances = tool_proxy.input_instances() | |
170 self._input_list = list(map(self._to_input_source, cwl_instances)) | |
171 | |
172 def _to_input_source(self, input_instance): | |
173 as_dict = input_instance.to_dict() | |
174 return YamlInputSource(as_dict) | |
175 | |
176 def parse_input_sources(self): | |
177 return self._input_list |