annotate toolfactory/galaxyxml/tool/import_xml.py @ 35:5d38cb3d9be8 draft

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