92
|
1 import logging
|
|
2 import xml.etree.ElementTree as ET
|
|
3
|
|
4 import galaxyxml.tool as gxt
|
|
5 import galaxyxml.tool.parameters as gxtp
|
|
6
|
|
7 logging.basicConfig(level=logging.INFO)
|
|
8 logger = logging.getLogger(__name__)
|
|
9
|
|
10
|
|
11 class GalaxyXmlParser(object):
|
|
12 """
|
|
13 Class to import content from an existing Galaxy XML wrapper.
|
|
14 """
|
|
15
|
|
16 def _init_tool(self, xml_root):
|
|
17 """
|
|
18 Init tool from existing xml tool.
|
|
19
|
|
20 :param xml_root: root of the galaxy xml file.
|
|
21 :type xml_root: :class:`xml.etree._Element`
|
|
22 """
|
|
23 version_cmd = None
|
|
24 description = None
|
|
25 for child in xml_root:
|
|
26 if child.tag == "description":
|
|
27 description = child.text
|
|
28 elif child.tag == "command":
|
|
29 executable = child.text.split()[0]
|
|
30 command = child.text
|
|
31 elif child.tag == "version_command":
|
|
32 version_cmd = child.text
|
|
33
|
|
34 tool = gxt.Tool(
|
|
35 xml_root.attrib["name"],
|
|
36 xml_root.attrib["id"],
|
|
37 xml_root.attrib.get("version", None),
|
|
38 description,
|
|
39 executable,
|
|
40 hidden=xml_root.attrib.get("hidden", False),
|
|
41 tool_type=xml_root.attrib.get("tool_type", None),
|
|
42 URL_method=xml_root.attrib.get("URL_method", None),
|
|
43 workflow_compatible=xml_root.attrib.get("workflow_compatible", True),
|
|
44 version_command=version_cmd,
|
|
45 )
|
|
46 tool.command = command
|
|
47 return tool
|
|
48
|
|
49 def _load_description(self, tool, desc_root):
|
|
50 """
|
|
51 <description> is already loaded during initiation.
|
|
52
|
|
53 :param tool: Tool object from galaxyxml.
|
|
54 :type tool: :class:`galaxyxml.tool.Tool`
|
|
55 :param desc_root: root of <description> tag.
|
|
56 :type desc_root: :class:`xml.etree._Element`
|
|
57 """
|
|
58 logger.info("<description> is loaded during initiation of the object.")
|
|
59
|
|
60 def _load_version_command(self, tool, vers_root):
|
|
61 """
|
|
62 <version_command> is already loaded during initiation.
|
|
63
|
|
64 :param tool: Tool object from galaxyxml.
|
|
65 :type tool: :class:`galaxyxml.tool.Tool`
|
|
66 :param vers_root: root of <version_command> tag.
|
|
67 :type vers_root: :class:`xml.etree._Element`
|
|
68 """
|
|
69 logger.info("<version_command> is loaded during initiation of the object.")
|
|
70
|
|
71 def _load_stdio(self, tool, stdio_root):
|
|
72 """
|
|
73 So far, <stdio> is automatically generated by galaxyxml.
|
|
74
|
|
75 :param tool: Tool object from galaxyxml.
|
|
76 :type tool: :class:`galaxyxml.tool.Tool`
|
|
77 :param desc_root: root of <stdio> tag.
|
|
78 :type desc_root: :class:`xml.etree._Element`
|
|
79 """
|
|
80 logger.info("<stdio> is not loaded but automatically generated by galaxyxml.")
|
|
81
|
|
82 def _load_command(self, tool, desc_root):
|
|
83 """
|
|
84 <command> is already loaded during initiation.
|
|
85
|
|
86 :param tool: Tool object from galaxyxml.
|
|
87 :type tool: :class:`galaxyxml.tool.Tool`
|
|
88 :param desc_root: root of <command> tag.
|
|
89 :type desc_root: :class:`xml.etree._Element`
|
|
90 """
|
|
91 logger.info("<command> is loaded during initiation of the object.")
|
|
92
|
|
93 def _load_help(self, tool, help_root):
|
|
94 """
|
|
95 Load the content of the <help> into the tool.
|
|
96
|
|
97 :param tool: Tool object from galaxyxml.
|
|
98 :type tool: :class:`galaxyxml.tool.Tool`
|
|
99 :param requirements_root: root of <help> tag.
|
|
100 :type requirements_root: :class:`xml.etree._Element`
|
|
101 """
|
|
102 tool.help = help_root.text
|
|
103
|
|
104 def _load_requirements(self, tool, requirements_root):
|
|
105 """
|
|
106 Add <requirements> to the tool.
|
|
107
|
|
108 :param tool: Tool object from galaxyxml.
|
|
109 :type tool: :class:`galaxyxml.tool.Tool`
|
|
110 :param requirements_root: root of <requirements> tag.
|
|
111 :type requirements_root: :class:`xml.etree._Element`
|
|
112 """
|
|
113 tool.requirements = gxtp.Requirements()
|
|
114 for req in requirements_root:
|
|
115 req_type = req.attrib["type"]
|
|
116 value = req.text
|
|
117 if req.tag == "requirement":
|
|
118 version = req.attrib.get("version", None)
|
|
119 tool.requirements.append(gxtp.Requirement(req_type, value, version=version))
|
|
120 elif req.tag == "container":
|
|
121 tool.requirements.append(gxtp.Container(req_type, value))
|
|
122 else:
|
|
123 logger.warning(req.tag + " is not a valid tag for requirements child")
|
|
124
|
|
125 def _load_edam_topics(self, tool, topics_root):
|
|
126 """
|
|
127 Add <edam_topics> to the tool.
|
|
128
|
|
129 :param tool: Tool object from galaxyxml.
|
|
130 :type tool: :class:`galaxyxml.tool.Tool`
|
|
131 :param topics_root: root of <edam_topics> tag.
|
|
132 :type topics_root: :class:`xml.etree._Element`
|
|
133 """
|
|
134 tool.edam_topics = gxtp.EdamTopics()
|
|
135 for edam_topic in topics_root:
|
|
136 tool.edam_topics.append(gxtp.EdamTopic(edam_topic.text))
|
|
137
|
|
138 def _load_edam_operations(self, tool, operations_root):
|
|
139 """
|
|
140 Add <edam_operations> to the tool.
|
|
141
|
|
142 :param tool: Tool object from galaxyxml.
|
|
143 :type tool: :class:`galaxyxml.tool.Tool`
|
|
144 :param operations_root: root of <edam_operations> tag.
|
|
145 :type operations_root: :class:`xml.etree._Element`
|
|
146 """
|
|
147 tool.edam_operations = gxtp.EdamOperations()
|
|
148 for edam_op in operations_root:
|
|
149 tool.edam_operations.append(gxtp.EdamOperation(edam_op.text))
|
|
150
|
|
151 def _load_configfiles(self, tool, configfiles_root):
|
|
152 """
|
|
153 Add <configfiles> to the tool.
|
|
154
|
|
155 :param tool: Tool object from galaxyxml.
|
|
156 :type tool: :class:`galaxyxml.tool.Tool`
|
|
157 :param configfiles_root: root of <configfiles> tag.
|
|
158 :type configfiles_root: :class:`xml.etree._Element`
|
|
159 """
|
|
160 tool.configfiles = gxtp.Configfiles()
|
|
161 for conf in configfiles_root:
|
|
162 name = conf.attrib["name"]
|
|
163 value = conf.text
|
|
164 tool.configfiles.append(gxtp.Configfile(name, value))
|
|
165
|
|
166 def _load_citations(self, tool, citations_root):
|
|
167 """
|
|
168 Add <citations> to the tool.
|
|
169
|
|
170 :param tool: Tool object from galaxyxml.
|
|
171 :type tool: :class:`galaxyxml.tool.Tool`
|
|
172 :param citations_root: root of <citations> tag.
|
|
173 :type citations_root: :class:`xml.etree._Element`
|
|
174 """
|
|
175 tool.citations = gxtp.Citations()
|
|
176 for cit in citations_root:
|
|
177 cit_type = cit.attrib["type"]
|
|
178 value = cit.text
|
|
179 tool.citations.append(gxtp.Citation(cit_type, value))
|
|
180
|
|
181 def _load_inputs(self, tool, inputs_root):
|
|
182 """
|
|
183 Add <inputs> to the tool using the :class:`galaxyxml.tool.import_xml.InputsParser` object.
|
|
184
|
|
185 :param tool: Tool object from galaxyxml.
|
|
186 :type tool: :class:`galaxyxml.tool.Tool`
|
|
187 :param inputs_root: root of <inputs> tag.
|
|
188 :type inputs_root: :class:`xml.etree._Element`
|
|
189 """
|
|
190 tool.inputs = gxtp.Inputs()
|
|
191 inp_parser = InputsParser()
|
|
192 inp_parser.load_inputs(tool.inputs, inputs_root)
|
|
193
|
|
194 def _load_outputs(self, tool, outputs_root):
|
|
195 """
|
|
196 Add <outputs> to the tool using the :class:`galaxyxml.tool.import_xml.OutputsParser` object.
|
|
197
|
|
198 :param tool: Tool object from galaxyxml.
|
|
199 :type tool: :class:`galaxyxml.tool.Tool`
|
|
200 :param outputs_root: root of <outputs> tag.
|
|
201 :type outputs_root: :class:`xml.etree._Element`
|
|
202 """
|
|
203 tool.outputs = gxtp.Outputs()
|
|
204 out_parser = OutputsParser()
|
|
205 out_parser.load_outputs(tool.outputs, outputs_root)
|
|
206
|
|
207 def _load_tests(self, tool, tests_root):
|
|
208 """
|
|
209 Add <tests> to the tool using the :class:`galaxyxml.tool.import_xml.TestsParser` object.
|
|
210
|
|
211 :param tool: Tool object from galaxyxml.
|
|
212 :type tool: :class:`galaxyxml.tool.Tool`
|
|
213 :param tests_root: root of <tests> tag.
|
|
214 :type tests_root: :class:`xml.etree._Element`
|
|
215 """
|
|
216 tool.tests = gxtp.Tests()
|
|
217 tests_parser = TestsParser()
|
|
218 tests_parser.load_tests(tool.tests, tests_root)
|
|
219
|
|
220 def import_xml(self, xml_path):
|
|
221 """
|
|
222 Load existing xml into the :class:`galaxyxml.tool.Tool` object.
|
|
223
|
|
224 :param xml_path: Path of the XML to be loaded.
|
|
225 :type xml_path: STRING
|
|
226 :return: XML content in the galaxyxml model.
|
|
227 :rtype: :class:`galaxyxml.tool.Tool`
|
|
228 """
|
|
229 xml_root = ET.parse(xml_path).getroot()
|
|
230 tool = self._init_tool(xml_root)
|
|
231 # Now we import each tag's field
|
|
232 for child in xml_root:
|
|
233 try:
|
|
234 getattr(self, "_load_{}".format(child.tag))(tool, child)
|
|
235 except AttributeError:
|
|
236 logger.warning(child.tag + " tag is not processed.")
|
|
237 return tool
|
|
238
|
|
239
|
|
240 class InputsParser(object):
|
|
241 """
|
|
242 Class to parse content of the <inputs> tag from a Galaxy XML wrapper.
|
|
243 """
|
|
244
|
|
245 def _load_text_param(self, root, text_param):
|
|
246 """
|
|
247 Add <param type="text" /> to the root.
|
|
248
|
|
249 :param root: root to append the param to.
|
|
250 :param text_param: root of <param> tag.
|
|
251 :type text_param: :class:`xml.etree._Element`
|
|
252 """
|
|
253 root.append(
|
|
254 gxtp.TextParam(
|
|
255 text_param.attrib["name"],
|
|
256 optional=text_param.get("optional", None),
|
|
257 label=text_param.get("label", None),
|
|
258 help=text_param.get("help", None),
|
|
259 value=text_param.get("value", None),
|
|
260 )
|
|
261 )
|
|
262
|
|
263 def _load_data_param(self, root, data_param):
|
|
264 """
|
|
265 Add <param type="data" /> to the root.
|
|
266
|
|
267 :param root: root to append the param to.
|
|
268 :param data_param: root of <param> tag.
|
|
269 :type data_param: :class:`xml.etree._Element`
|
|
270 """
|
|
271 root.append(
|
|
272 gxtp.DataParam(
|
|
273 data_param.attrib["name"],
|
|
274 optional=data_param.attrib.get("optional", None),
|
|
275 label=data_param.attrib.get("label", None),
|
|
276 help=data_param.attrib.get("help", None),
|
|
277 format=data_param.attrib.get("format", None),
|
|
278 multiple=data_param.attrib.get("multiple", None),
|
|
279 )
|
|
280 )
|
|
281
|
|
282 def _load_boolean_param(self, root, bool_param):
|
|
283 """
|
|
284 Add <param type="boolean" /> to the root.
|
|
285
|
|
286 :param root: root to append the param to.
|
|
287 :param bool_param: root of <param> tag.
|
|
288 :type bool_param: :class:`xml.etree._Element`
|
|
289 """
|
|
290 root.append(
|
|
291 gxtp.BooleanParam(
|
|
292 bool_param.attrib["name"],
|
|
293 optional=bool_param.attrib.get("optional", None),
|
|
294 label=bool_param.attrib.get("label", None),
|
|
295 help=bool_param.attrib.get("help", None),
|
|
296 checked=bool_param.attrib.get("checked", False),
|
|
297 truevalue=bool_param.attrib.get("truevalue", None),
|
|
298 falsevalue=bool_param.attrib.get("falsevalue", None),
|
|
299 )
|
|
300 )
|
|
301
|
|
302 def _load_integer_param(self, root, int_param):
|
|
303 """
|
|
304 Add <param type="integer" /> to the root.
|
|
305
|
|
306 :param root: root to append the param to.
|
|
307 :param int_param: root of <param> tag.
|
|
308 :type int_param: :class:`xml.etree._Element`
|
|
309 """
|
|
310 root.append(
|
|
311 gxtp.IntegerParam(
|
|
312 int_param.attrib["name"],
|
|
313 int_param.attrib.get("value", None),
|
|
314 optional=int_param.attrib.get("optional", None),
|
|
315 label=int_param.attrib.get("label", None),
|
|
316 help=int_param.attrib.get("help", None),
|
|
317 min=int_param.attrib.get("min", None),
|
|
318 max=int_param.attrib.get("max", None),
|
|
319 )
|
|
320 )
|
|
321
|
|
322 def _load_float_param(self, root, float_param):
|
|
323 """
|
|
324 Add <param type="float" /> to the root.
|
|
325
|
|
326 :param root: root to append the param to.
|
|
327 :param float_param: root of <param> tag.
|
|
328 :type float_param: :class:`xml.etree._Element`
|
|
329 """
|
|
330 root.append(
|
|
331 gxtp.FloatParam(
|
|
332 float_param.attrib["name"],
|
|
333 float_param.attrib.get("value", None),
|
|
334 optional=float_param.attrib.get("optional", None),
|
|
335 label=float_param.attrib.get("label", None),
|
|
336 help=float_param.attrib.get("help", None),
|
|
337 min=float_param.attrib.get("min", None),
|
|
338 max=float_param.attrib.get("max", None),
|
|
339 )
|
|
340 )
|
|
341
|
|
342 def _load_option_select(self, root, option):
|
|
343 """
|
|
344 Add <option> to the root (usually <param type="select" />).
|
|
345
|
|
346 :param root: root to append the param to.
|
|
347 :param option: root of <option> tag.
|
|
348 :type float_param: :class:`xml.etree._Element`
|
|
349 """
|
|
350 root.append(
|
|
351 gxtp.SelectOption(
|
|
352 option.attrib.get("value", None), option.text, selected=option.attrib.get("selected", False)
|
|
353 )
|
|
354 )
|
|
355
|
|
356 def _load_column_options(self, root, column):
|
|
357 """
|
|
358 Add <column> to the root (usually <options>).
|
|
359
|
|
360 :param root: root to append the param to.
|
|
361 :param option: root of <column> tag.
|
|
362 :type float_param: :class:`xml.etree._Element`
|
|
363 """
|
|
364 root.append(gxtp.Column(column.attrib["name"], column.attrib["index"]))
|
|
365
|
|
366 def _load_filter_options(self, root, filter):
|
|
367 """
|
|
368 Add <filter> to the root (usually <options>).
|
|
369
|
|
370 :param root: root to append the param to.
|
|
371 :param option: root of <filter> tag.
|
|
372 :type float_param: :class:`xml.etree._Element`
|
|
373 """
|
|
374 root.append(
|
|
375 gxtp.Filter(
|
|
376 filter.attrib["type"],
|
|
377 column=filter.attrib.get("column", None),
|
|
378 name=filter.attrib.get("name", None),
|
|
379 ref=filter.attrib.get("ref", None),
|
|
380 key=filter.attrib.get("key", None),
|
|
381 multiple=filter.attrib.get("multiple", None),
|
|
382 separator=filter.attrib.get("separator", None),
|
|
383 keep=filter.attrib.get("keep", None),
|
|
384 value=filter.attrib.get("value", None),
|
|
385 ref_attribute=filter.attrib.get("ref_attribute", None),
|
|
386 index=filter.attrib.get("index", None),
|
|
387 )
|
|
388 )
|
|
389
|
|
390 def _load_options_select(self, root, options):
|
|
391 """
|
|
392 Add <options> to the root (usually <param type="select" />).
|
|
393
|
|
394 :param root: root to append the param to.
|
|
395 :param option: root of <options> tag.
|
|
396 :type float_param: :class:`xml.etree._Element`
|
|
397 """
|
|
398 opts = gxtp.Options(
|
|
399 from_dataset=options.attrib.get("from_dataset", None),
|
|
400 from_file=options.attrib.get("from_file", None),
|
|
401 from_data_table=options.attrib.get("from_data_table", None),
|
|
402 from_parameter=options.attrib.get("from_parameter", None),
|
|
403 )
|
|
404 # Deal with child nodes (usually filter and column)
|
|
405 for opt_child in options:
|
|
406 try:
|
|
407 getattr(self, "_load_{}_options".format(opt_child.tag))(opts, opt_child)
|
|
408 except AttributeError:
|
|
409 logger.warning(opt_child.tag + " tag is not processed for <options>.")
|
|
410 root.append(opts)
|
|
411
|
|
412 def _load_select_param(self, root, sel_param):
|
|
413 """
|
|
414 Add <param type="select" /> to the root.
|
|
415
|
|
416 :param root: root to append the param to.
|
|
417 :param sel_param: root of <param> tag.
|
|
418 :type sel_param: :class:`xml.etree._Element`
|
|
419 """
|
|
420 select_param = gxtp.SelectParam(
|
|
421 sel_param.attrib["name"],
|
|
422 optional=sel_param.attrib.get("optional", None),
|
|
423 label=sel_param.attrib.get("label", None),
|
|
424 help=sel_param.attrib.get("help", None),
|
|
425 data_ref=sel_param.attrib.get("data_ref", None),
|
|
426 display=sel_param.attrib.get("display", None),
|
|
427 multiple=sel_param.attrib.get("multiple", None),
|
|
428 )
|
|
429 # Deal with child nodes (usually option and options)
|
|
430 for sel_child in sel_param:
|
|
431 try:
|
|
432 getattr(self, "_load_{}_select".format(sel_child.tag))(select_param, sel_child)
|
|
433 except AttributeError:
|
|
434 logger.warning(sel_child.tag + " tag is not processed for <param type='select'>.")
|
|
435 root.append(select_param)
|
|
436
|
|
437 def _load_param(self, root, param_root):
|
|
438 """
|
|
439 Method to select which type of <param> is being added to the root.
|
|
440
|
|
441 :param root: root to attach param to.
|
|
442 :param param_root: root of <param> tag.
|
|
443 :type param_root: :class:`xml.etree._Element`
|
|
444 """
|
|
445 param_type = param_root.attrib["type"]
|
|
446 try:
|
|
447 getattr(self, "_load_{}_param".format(param_type))(root, param_root)
|
|
448 except AttributeError:
|
|
449 logger.warning(param_type + " tag is not processed for <param>.")
|
|
450
|
|
451 def _load_when(self, root, when_root):
|
|
452 """
|
|
453 Add <when> to the root (usually <conditional>).
|
|
454
|
|
455 :param root: root to append when to.
|
|
456 :param when_root: root of <when> tag.
|
|
457 :type when_root: :class:`xml.etree._Element`
|
|
458 """
|
|
459 when = gxtp.When(when_root.attrib["value"])
|
|
460 # Deal with child nodes
|
|
461 self.load_inputs(when, when_root)
|
|
462 root.append(when)
|
|
463
|
|
464 def _load_conditional(self, root, conditional_root):
|
|
465 """
|
|
466 Add <conditional> to the root.
|
|
467
|
|
468 :param root: root to append conditional to.
|
|
469 :param conditional_root: root of <conditional> tag.
|
|
470 :type conditional_root: :class:`xml.etree._Element`
|
|
471 """
|
|
472 value_ref_in_group = conditional_root.attrib.get("value_ref_in_group", None)
|
|
473 # Other optional parameters need to be added to conditional object
|
|
474 conditional = gxtp.Conditional(
|
|
475 conditional_root.attrib["name"],
|
|
476 value_from=conditional_root.attrib.get("value_from", None),
|
|
477 value_ref=conditional_root.attrib.get("value_ref", None),
|
|
478 value_ref_in_group=value_ref_in_group,
|
|
479 label=conditional_root.attrib.get("label", None),
|
|
480 )
|
|
481 # Deal with child nodes
|
|
482 self.load_inputs(conditional, conditional_root)
|
|
483 root.append(conditional)
|
|
484
|
|
485 def _load_section(self, root, section_root):
|
|
486 """
|
|
487 Add <section> to the root.
|
|
488
|
|
489 :param root: root to append conditional to.
|
|
490 :param section_root: root of <section> tag.
|
|
491 :type section_root: :class:`xml.etree._Element`
|
|
492 """
|
|
493 section = gxtp.Section(
|
|
494 section_root.attrib["name"],
|
|
495 section_root.attrib["title"],
|
|
496 expanded=section_root.attrib.get("expanded", None),
|
|
497 help=section_root.attrib.get("help", None),
|
|
498 )
|
|
499 # Deal with child nodes
|
|
500 self.load_inputs(section, section_root)
|
|
501 root.append(section)
|
|
502
|
|
503 def _load_repeat(self, root, repeat_root):
|
|
504 """
|
|
505 Add <repeat> to the root.
|
|
506
|
|
507 :param root: root to append repeat to.
|
|
508 :param repeat_root: root of <repeat> tag.
|
|
509 :param repeat_root: :class:`xml.etree._Element`
|
|
510 """
|
|
511 repeat = gxtp.Repeat(
|
|
512 repeat_root.attrib["name"],
|
|
513 repeat_root.attrib["title"],
|
|
514 min=repeat_root.attrib.get("min", None),
|
|
515 max=repeat_root.attrib.get("max", None),
|
|
516 default=repeat_root.attrib.get("default", None),
|
|
517 )
|
|
518 # Deal with child nodes
|
|
519 self.load_inputs(repeat, repeat_root)
|
|
520 root.append(repeat)
|
|
521
|
|
522 def load_inputs(self, root, inputs_root):
|
|
523 """
|
|
524 Add <inputs.tag> to the root (it can be any tags with children such as
|
|
525 <inputs>, <repeat>, <section> ...)
|
|
526
|
|
527 :param root: root to attach inputs to (either <inputs> or <when>).
|
|
528 :param inputs_root: root of <inputs> tag.
|
|
529 :type inputs_root: :class:`xml.etree._Element`
|
|
530 """
|
|
531 for inp_child in inputs_root:
|
|
532 try:
|
|
533 getattr(self, "_load_{}".format(inp_child.tag))(root, inp_child)
|
|
534 except AttributeError:
|
|
535 logger.warning(inp_child.tag + " tag is not processed for <" + inputs_root.tag + "> tag.")
|
|
536
|
|
537
|
|
538 class OutputsParser(object):
|
|
539 """
|
|
540 Class to parse content of the <outputs> tag from a Galaxy XML wrapper.
|
|
541 """
|
|
542
|
|
543 def _load_data(self, outputs_root, data_root):
|
|
544 """
|
|
545 Add <data> to <outputs>.
|
|
546
|
|
547 :param outputs_root: <outputs> root to append <data> to.
|
|
548 :param data_root: root of <data> tag.
|
|
549 :param data_root: :class:`xml.etree._Element`
|
|
550 """
|
|
551 data = gxtp.OutputData(
|
|
552 data_root.attrib.get("name", None),
|
|
553 data_root.attrib.get("format", None),
|
|
554 format_source=data_root.attrib.get("format_source", None),
|
|
555 metadata_source=data_root.attrib.get("metadata_source", None),
|
|
556 label=data_root.attrib.get("label", None),
|
|
557 from_work_dir=data_root.attrib.get("from_work_dir", None),
|
|
558 hidden=data_root.attrib.get("hidden", False),
|
|
559 )
|
|
560 # Deal with child nodes
|
|
561 for data_child in data_root:
|
|
562 try:
|
|
563 getattr(self, "_load_{}".format(data_child.tag))(data, data_child)
|
|
564 except AttributeError:
|
|
565 logger.warning(data_child.tag + " tag is not processed for <data>.")
|
|
566 outputs_root.append(data)
|
|
567
|
|
568 def _load_change_format(self, root, chfmt_root):
|
|
569 """
|
|
570 Add <change_format> to root (<data>).
|
|
571
|
|
572 :param root: root to append <change_format> to.
|
|
573 :param chfm_root: root of <change_format> tag.
|
|
574 :param chfm_root: :class:`xml.etree._Element`
|
|
575 """
|
|
576 change_format = gxtp.ChangeFormat()
|
|
577 for chfmt_child in chfmt_root:
|
|
578 change_format.append(
|
|
579 gxtp.ChangeFormatWhen(
|
|
580 chfmt_child.attrib["input"], chfmt_child.attrib["format"], chfmt_child.attrib["value"]
|
|
581 )
|
|
582 )
|
|
583 root.append(change_format)
|
|
584
|
|
585 def _load_collection(self, outputs_root, coll_root):
|
|
586 """
|
|
587 Add <collection> to <outputs>.
|
|
588
|
|
589 :param outputs_root: <outputs> root to append <collection> to.
|
|
590 :param coll_root: root of <collection> tag.
|
|
591 :param coll_root: :class:`xml.etree._Element`
|
|
592 """
|
|
593 collection = gxtp.OutputCollection(
|
|
594 coll_root.attrib["name"],
|
|
595 type=coll_root.attrib.get("type", None),
|
|
596 label=coll_root.attrib.get("label", None),
|
|
597 format_source=coll_root.attrib.get("format_source", None),
|
|
598 type_source=coll_root.attrib.get("type_source", None),
|
|
599 structured_like=coll_root.attrib.get("structured_like", None),
|
|
600 inherit_format=coll_root.attrib.get("inherit_format", None),
|
|
601 )
|
|
602 # Deal with child nodes
|
|
603 for coll_child in coll_root:
|
|
604 try:
|
|
605 getattr(self, "_load_{}".format(coll_child.tag))(collection, coll_child)
|
|
606 except AttributeError:
|
|
607 logger.warning(coll_child.tag + " tag is not processed for <collection>.")
|
|
608 outputs_root.append(collection)
|
|
609
|
|
610 def _load_discover_datasets(self, root, disc_root):
|
|
611 """
|
|
612 Add <discover_datasets> to root (<collection>).
|
|
613
|
|
614 :param root: root to append <collection> to.
|
|
615 :param disc_root: root of <discover_datasets> tag.
|
|
616 :param disc_root: :class:`xml.etree._Element`
|
|
617 """
|
|
618 root.append(
|
|
619 gxtp.DiscoverDatasets(
|
|
620 disc_root.attrib["pattern"],
|
|
621 directory=disc_root.attrib.get("directory", None),
|
|
622 format=disc_root.attrib.get("format", None),
|
|
623 ext=disc_root.attrib.get("ext", None),
|
|
624 visible=disc_root.attrib.get("visible", None),
|
|
625 )
|
|
626 )
|
|
627
|
|
628 def _load_filter(self, root, filter_root):
|
|
629 """
|
|
630 Add <filter> to root (<collection> or <data>).
|
|
631
|
|
632 :param root: root to append <collection> to.
|
|
633 :param coll_root: root of <filter> tag.
|
|
634 :param coll_root: :class:`xml.etree._Element`
|
|
635 """
|
|
636 root.append(gxtp.OutputFilter(filter_root.text))
|
|
637
|
|
638 def load_outputs(self, root, outputs_root):
|
|
639 """
|
|
640 Add <outputs> to the root.
|
|
641
|
|
642 :param root: root to attach <outputs> to (<tool>).
|
|
643 :param tests_root: root of <outputs> tag.
|
|
644 :type tests_root: :class:`xml.etree._Element`
|
|
645 """
|
|
646 for out_child in outputs_root:
|
|
647 try:
|
|
648 getattr(self, "_load_{}".format(out_child.tag))(root, out_child)
|
|
649 except AttributeError:
|
|
650 logger.warning(out_child.tag + " tag is not processed for <outputs>.")
|
|
651
|
|
652
|
|
653 class TestsParser(object):
|
|
654 """
|
|
655 Class to parse content of the <tests> tag from a Galaxy XML wrapper.
|
|
656 """
|
|
657
|
|
658 def _load_param(self, test_root, param_root):
|
|
659 """
|
|
660 Add <param> to the <test>.
|
|
661
|
|
662 :param root: <test> root to append <param> to.
|
|
663 :param repeat_root: root of <param> tag.
|
|
664 :param repeat_root: :class:`xml.etree._Element`
|
|
665 """
|
|
666 test_root.append(
|
|
667 gxtp.TestParam(
|
|
668 param_root.attrib["name"],
|
|
669 value=param_root.attrib.get("value", None),
|
|
670 ftype=param_root.attrib.get("ftype", None),
|
|
671 dbkey=param_root.attrib.get("dbkey", None),
|
|
672 )
|
|
673 )
|
|
674
|
|
675 def _load_output(self, test_root, output_root):
|
|
676 """
|
|
677 Add <output> to the <test>.
|
|
678
|
|
679 :param root: <test> root to append <output> to.
|
|
680 :param repeat_root: root of <output> tag.
|
|
681 :param repeat_root: :class:`xml.etree._Element`
|
|
682 """
|
|
683 test_root.append(
|
|
684 gxtp.TestOutput(
|
|
685 name=output_root.attrib.get("name", None),
|
|
686 file=output_root.attrib.get("file", None),
|
|
687 ftype=output_root.attrib.get("ftype", None),
|
|
688 sort=output_root.attrib.get("sort", None),
|
|
689 value=output_root.attrib.get("value", None),
|
|
690 md5=output_root.attrib.get("md5", None),
|
|
691 checksum=output_root.attrib.get("checksum", None),
|
|
692 compare=output_root.attrib.get("compare", None),
|
|
693 lines_diff=output_root.attrib.get("lines_diff", None),
|
|
694 delta=output_root.attrib.get("delta", None),
|
|
695 )
|
|
696 )
|
|
697
|
|
698 def load_tests(self, root, tests_root):
|
|
699 """
|
|
700 Add <tests> to the root.
|
|
701
|
|
702 :param root: root to attach <tests> to (<tool>).
|
|
703 :param tests_root: root of <tests> tag.
|
|
704 :type tests_root: :class:`xml.etree._Element`
|
|
705 """
|
|
706 for test_root in tests_root:
|
|
707 test = gxtp.Test()
|
|
708 for test_child in test_root:
|
|
709 try:
|
|
710 getattr(self, "_load_{}".format(test_child.tag))(test, test_child)
|
|
711 except AttributeError:
|
|
712 logger.warning(test_child.tag + " tag is not processed within <test>.")
|
|
713 root.append(test)
|