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