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