1from __future__ import absolute_import
2from __future__ import print_function
3# #START_LICENSE###########################################################
4#
5#
6# This file is part of the Environment for Tree Exploration program
7# (ETE).  http://etetoolkit.org
8#
9# ETE is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# ETE is distributed in the hope that it will be useful, but WITHOUT
15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17# License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with ETE.  If not, see <http://www.gnu.org/licenses/>.
21#
22#
23#                     ABOUT THE ETE PACKAGE
24#                     =====================
25#
26# ETE is distributed under the GPL copyleft license (2008-2015).
27#
28# If you make use of ETE in published work, please cite:
29#
30# Jaime Huerta-Cepas, Joaquin Dopazo and Toni Gabaldon.
31# ETE: a python Environment for Tree Exploration. Jaime BMC
32# Bioinformatics 2010,:24doi:10.1186/1471-2105-11-24
33#
34# Note that extra references to the specific methods implemented in
35# the toolkit may be available in the documentation.
36#
37# More info at http://etetoolkit.org. Contact: huerta@embl.de
38#
39#
40# #END_LICENSE#############################################################
41#!/usr/bin/env python
42# -*- coding: utf-8 -*-
43
44#
45# Generated Mon Jun 27 10:13:43 2011 by generateDS.py version 2.5b.
46#
47
48import sys
49import getopt
50import re as re_
51import six
52from six.moves import range
53
54etree_ = None
55Verbose_import_ = False
56(   XMLParser_import_none, XMLParser_import_lxml,
57    XMLParser_import_elementtree
58    ) = list(range(3))
59XMLParser_import_library = None
60try:
61    # lxml
62    from lxml import etree as etree_
63    XMLParser_import_library = XMLParser_import_lxml
64    if Verbose_import_:
65        print("running with lxml.etree")
66except ImportError:
67    try:
68        # cElementTree from Python 2.5+
69        import xml.etree.cElementTree as etree_
70        XMLParser_import_library = XMLParser_import_elementtree
71        if Verbose_import_:
72            print("running with cElementTree on Python 2.5+")
73    except ImportError:
74        try:
75            # ElementTree from Python 2.5+
76            import xml.etree.ElementTree as etree_
77            XMLParser_import_library = XMLParser_import_elementtree
78            if Verbose_import_:
79                print("running with ElementTree on Python 2.5+")
80        except ImportError:
81            try:
82                # normal cElementTree install
83                import cElementTree as etree_
84                XMLParser_import_library = XMLParser_import_elementtree
85                if Verbose_import_:
86                    print("running with cElementTree")
87            except ImportError:
88                try:
89                    # normal ElementTree install
90                    import elementtree.ElementTree as etree_
91                    XMLParser_import_library = XMLParser_import_elementtree
92                    if Verbose_import_:
93                        print("running with ElementTree")
94                except ImportError:
95                    raise ImportError("Failed to import ElementTree from any known place")
96
97def parsexml_(*args, **kwargs):
98    if (XMLParser_import_library == XMLParser_import_lxml and
99        'parser' not in kwargs):
100        # Use the lxml ElementTree compatible parser so that, e.g.,
101        #   we ignore comments.
102        kwargs['parser'] = etree_.ETCompatXMLParser()
103    doc = etree_.parse(*args, **kwargs)
104    return doc
105
106#
107# User methods
108#
109# Calls to the methods in these classes are generated by generateDS.py.
110# You can replace these methods by re-implementing the following class
111#   in a module named generatedssuper.py.
112
113try:
114    from generatedssuper import GeneratedsSuper
115except ImportError as exp:
116
117    class GeneratedsSuper(object):
118        def gds_format_string(self, input_data, input_name=''):
119            return input_data
120        def gds_validate_string(self, input_data, node, input_name=''):
121            return input_data
122        def gds_format_integer(self, input_data, input_name=''):
123            return '%d' % input_data
124        def gds_validate_integer(self, input_data, node, input_name=''):
125            return input_data
126        def gds_format_integer_list(self, input_data, input_name=''):
127            return '%s' % input_data
128        def gds_validate_integer_list(self, input_data, node, input_name=''):
129            values = input_data.split()
130            for value in values:
131                try:
132                    fvalue = float(value)
133                except (TypeError, ValueError) as exp:
134                    raise_parse_error(node, 'Requires sequence of integers')
135            return input_data
136        def gds_format_float(self, input_data, input_name=''):
137            return '%f' % input_data
138        def gds_validate_float(self, input_data, node, input_name=''):
139            return input_data
140        def gds_format_float_list(self, input_data, input_name=''):
141            return '%s' % input_data
142        def gds_validate_float_list(self, input_data, node, input_name=''):
143            values = input_data.split()
144            for value in values:
145                try:
146                    fvalue = float(value)
147                except (TypeError, ValueError) as exp:
148                    raise_parse_error(node, 'Requires sequence of floats')
149            return input_data
150        def gds_format_double(self, input_data, input_name=''):
151            return '%e' % input_data
152        def gds_validate_double(self, input_data, node, input_name=''):
153            return input_data
154        def gds_format_double_list(self, input_data, input_name=''):
155            return '%s' % input_data
156        def gds_validate_double_list(self, input_data, node, input_name=''):
157            values = input_data.split()
158            for value in values:
159                try:
160                    fvalue = float(value)
161                except (TypeError, ValueError) as exp:
162                    raise_parse_error(node, 'Requires sequence of doubles')
163            return input_data
164        def gds_format_boolean(self, input_data, input_name=''):
165            return '%s' % input_data
166        def gds_validate_boolean(self, input_data, node, input_name=''):
167            return input_data
168        def gds_format_boolean_list(self, input_data, input_name=''):
169            return '%s' % input_data
170        def gds_validate_boolean_list(self, input_data, node, input_name=''):
171            values = input_data.split()
172            for value in values:
173                if value not in ('true', '1', 'false', '0', ):
174                    raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")')
175            return input_data
176        def gds_str_lower(self, instring):
177            return instring.lower()
178        def get_path_(self, node):
179            path_list = []
180            self.get_path_list_(node, path_list)
181            path_list.reverse()
182            path = '/'.join(path_list)
183            return path
184        Tag_strip_pattern_ = re_.compile(r'\{.*\}')
185        def get_path_list_(self, node, path_list):
186            if node is None:
187                return
188            tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
189            if tag:
190                path_list.append(tag)
191            self.get_path_list_(node.getparent(), path_list)
192
193
194#
195# If you have installed IPython you can uncomment and use the following.
196# IPython is available from http://ipython.scipy.org/.
197#
198
199## from IPython.Shell import IPShellEmbed
200## args = ''
201## ipshell = IPShellEmbed(args,
202##     banner = 'Dropping into IPython',
203##     exit_msg = 'Leaving Interpreter, back to program.')
204
205# Then use the following line where and when you want to drop into the
206# IPython shell:
207#    ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
208
209#
210# Globals
211#
212
213ExternalEncoding = 'utf-8'
214Tag_pattern_ = re_.compile(r'({.*})?(.*)')
215STRING_CLEANUP_PAT = re_.compile(r"[\n\r\s]+")
216
217#
218# Support/utility functions.
219#
220
221def showIndent(outfile, level):
222    for idx in range(level):
223        outfile.write('    ')
224
225def quote_xml(inStr):
226    if not inStr:
227        return ''
228    s1 = (isinstance(inStr, six.string_types) and inStr or
229          '%s' % inStr)
230    s1 = s1.replace('&', '&amp;')
231    s1 = s1.replace('<', '&lt;')
232    s1 = s1.replace('>', '&gt;')
233    return s1
234
235def quote_attrib(inStr):
236    s1 = (isinstance(inStr, six.string_types) and inStr or
237          '%s' % inStr)
238    s1 = s1.replace('&', '&amp;')
239    s1 = s1.replace('<', '&lt;')
240    s1 = s1.replace('>', '&gt;')
241    if '"' in s1:
242        if "'" in s1:
243            s1 = '"%s"' % s1.replace('"', "&quot;")
244        else:
245            s1 = "'%s'" % s1
246    else:
247        s1 = '"%s"' % s1
248    return s1
249
250def quote_python(inStr):
251    s1 = inStr
252    if s1.find("'") == -1:
253        if s1.find('\n') == -1:
254            return "'%s'" % s1
255        else:
256            return "'''%s'''" % s1
257    else:
258        if s1.find('"') != -1:
259            s1 = s1.replace('"', '\\"')
260        if s1.find('\n') == -1:
261            return '"%s"' % s1
262        else:
263            return '"""%s"""' % s1
264
265def get_all_text_(node):
266    if node.text is not None:
267        text = node.text
268    else:
269        text = ''
270    for child in node:
271        if child.tail is not None:
272            text += child.tail
273    return text
274
275def find_attr_value_(attr_name, node):
276    attrs = node.attrib
277    # First try with no namespace.
278    value = attrs.get(attr_name)
279    if value is None:
280        # Now try the other possible namespaces.
281        namespaces = six.itervalues(node.nsmap)
282        for namespace in namespaces:
283            value = attrs.get('{%s}%s' % (namespace, attr_name, ))
284            if value is not None:
285                break
286    return value
287
288
289class GDSParseError(Exception):
290    pass
291
292def raise_parse_error(node, msg):
293    if XMLParser_import_library == XMLParser_import_lxml:
294        msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, )
295    else:
296        msg = '%s (element %s)' % (msg, node.tag, )
297    raise GDSParseError(msg)
298
299
300class MixedContainer:
301    # Constants for category:
302    CategoryNone = 0
303    CategoryText = 1
304    CategorySimple = 2
305    CategoryComplex = 3
306    # Constants for content_type:
307    TypeNone = 0
308    TypeText = 1
309    TypeString = 2
310    TypeInteger = 3
311    TypeFloat = 4
312    TypeDecimal = 5
313    TypeDouble = 6
314    TypeBoolean = 7
315    def __init__(self, category, content_type, name, value):
316        self.category = category
317        self.content_type = content_type
318        self.name = name
319        self.value = value
320    def getCategory(self):
321        return self.category
322    def getContenttype(self, content_type):
323        return self.content_type
324    def getValue(self):
325        return self.value
326    def getName(self):
327        return self.name
328    def export(self, outfile, level, name, namespace):
329        if self.category == MixedContainer.CategoryText:
330            # Prevent exporting empty content as empty lines.
331            if self.value.strip():
332                outfile.write(self.value)
333        elif self.category == MixedContainer.CategorySimple:
334            self.exportSimple(outfile, level, name)
335        else:    # category == MixedContainer.CategoryComplex
336            self.value.export(outfile, level, namespace,name)
337    def exportSimple(self, outfile, level, name):
338        if self.content_type == MixedContainer.TypeString:
339            outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))
340        elif self.content_type == MixedContainer.TypeInteger or \
341                self.content_type == MixedContainer.TypeBoolean:
342            outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))
343        elif self.content_type == MixedContainer.TypeFloat or \
344                self.content_type == MixedContainer.TypeDecimal:
345            outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))
346        elif self.content_type == MixedContainer.TypeDouble:
347            outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))
348    def exportLiteral(self, outfile, level, name):
349        if self.category == MixedContainer.CategoryText:
350            showIndent(outfile, level)
351            outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
352                (self.category, self.content_type, self.name, self.value))
353        elif self.category == MixedContainer.CategorySimple:
354            showIndent(outfile, level)
355            outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
356                (self.category, self.content_type, self.name, self.value))
357        else:    # category == MixedContainer.CategoryComplex
358            showIndent(outfile, level)
359            outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \
360                (self.category, self.content_type, self.name,))
361            self.value.exportLiteral(outfile, level + 1)
362            showIndent(outfile, level)
363            outfile.write(')\n')
364
365
366class MemberSpec_(object):
367    def __init__(self, name='', data_type='', container=0):
368        self.name = name
369        self.data_type = data_type
370        self.container = container
371    def set_name(self, name): self.name = name
372    def get_name(self): return self.name
373    def set_data_type(self, data_type): self.data_type = data_type
374    def get_data_type_chain(self): return self.data_type
375    def get_data_type(self):
376        if isinstance(self.data_type, list):
377            if len(self.data_type) > 0:
378                return self.data_type[-1]
379            else:
380                return 'xs:string'
381        else:
382            return self.data_type
383    def set_container(self, container): self.container = container
384    def get_container(self): return self.container
385
386def _cast(typ, value):
387    if typ is None or value is None:
388        return value
389    return typ(value)
390
391#
392# Data representation classes.
393#
394
395class orthoXML(GeneratedsSuper):
396    """The OrthoXML root element. The source program/database of the file
397    for instance OMA or InParanoid. The version number of the file.
398    The version or release number of the source program/database at
399    time the file was generated."""
400    subclass = None
401    superclass = None
402    def __init__(self, origin=None, version=None, originVersion=None, notes=None, species=None, scores=None, groups=None, valueOf_=None):
403        self.origin = _cast(None, origin)
404        self.version = _cast(float, version)
405        self.originVersion = _cast(None, originVersion)
406        self.notes = notes
407        if species is None:
408            self.species = []
409        else:
410            self.species = species
411        self.scores = scores
412        self.groups = groups
413    def factory(*args_, **kwargs_):
414        if orthoXML.subclass:
415            return orthoXML.subclass(*args_, **kwargs_)
416        else:
417            return orthoXML(*args_, **kwargs_)
418    factory = staticmethod(factory)
419    def get_notes(self): return self.notes
420    def set_notes(self, notes): self.notes = notes
421    def get_species(self): return self.species
422    def set_species(self, species): self.species = species
423    def add_species(self, value): self.species.append(value)
424    def insert_species(self, index, value): self.species[index] = value
425    def get_scores(self): return self.scores
426    def set_scores(self, scores): self.scores = scores
427    def get_groups(self): return self.groups
428    def set_groups(self, groups): self.groups = groups
429    def get_origin(self): return self.origin
430    def set_origin(self, origin): self.origin = origin
431    def get_version(self): return self.version
432    def set_version(self, version): self.version = version
433    def get_originVersion(self): return self.originVersion
434    def set_originVersion(self, originVersion): self.originVersion = originVersion
435    def export(self, outfile, level, namespace_='ortho:', name_='orthoXML', namespacedef_=''):
436        showIndent(outfile, level)
437        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
438        already_processed = []
439        self.exportAttributes(outfile, level, already_processed, namespace_, name_='orthoXML')
440        if self.hasContent_():
441            outfile.write('>\n')
442            self.exportChildren(outfile, level + 1, namespace_, name_)
443            showIndent(outfile, level)
444            outfile.write('</%s%s>\n' % (namespace_, name_))
445        else:
446            outfile.write('/>\n')
447    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='orthoXML'):
448        if self.origin is not None and 'origin' not in already_processed:
449            already_processed.append('origin')
450            outfile.write(' origin=%s' % (self.gds_format_string(quote_attrib(self.origin).encode(ExternalEncoding), input_name='origin'), ))
451        if self.version is not None and 'version' not in already_processed:
452            already_processed.append('version')
453            outfile.write(' version="%s"' % self.gds_format_float(self.version, input_name='version'))
454        if self.originVersion is not None and 'originVersion' not in already_processed:
455            already_processed.append('originVersion')
456            outfile.write(' originVersion=%s' % (self.gds_format_string(quote_attrib(self.originVersion).encode(ExternalEncoding), input_name='originVersion'), ))
457    def exportChildren(self, outfile, level, namespace_='ortho:', name_='orthoXML', fromsubclass_=False):
458        if self.notes:
459            self.notes.export(outfile, level, namespace_, name_='notes')
460        for species_ in self.species:
461            species_.export(outfile, level, namespace_, name_='species')
462        if self.scores:
463            self.scores.export(outfile, level, namespace_, name_='scores')
464        if self.groups:
465            self.groups.export(outfile, level, namespace_, name_='groups', )
466    def hasContent_(self):
467        if (
468            self.notes is not None or
469            self.species or
470            self.scores is not None or
471            self.groups is not None
472            ):
473            return True
474        else:
475            return False
476    def exportLiteral(self, outfile, level, name_='orthoXML'):
477        level += 1
478        self.exportLiteralAttributes(outfile, level, [], name_)
479        if self.hasContent_():
480            self.exportLiteralChildren(outfile, level, name_)
481    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
482        if self.origin is not None and 'origin' not in already_processed:
483            already_processed.append('origin')
484            showIndent(outfile, level)
485            outfile.write('origin = "%s",\n' % (self.origin,))
486        if self.version is not None and 'version' not in already_processed:
487            already_processed.append('version')
488            showIndent(outfile, level)
489            outfile.write('version = %f,\n' % (self.version,))
490        if self.originVersion is not None and 'originVersion' not in already_processed:
491            already_processed.append('originVersion')
492            showIndent(outfile, level)
493            outfile.write('originVersion = "%s",\n' % (self.originVersion,))
494    def exportLiteralChildren(self, outfile, level, name_):
495        if self.notes is not None:
496            showIndent(outfile, level)
497            outfile.write('notes=model_.notes(\n')
498            self.notes.exportLiteral(outfile, level)
499            showIndent(outfile, level)
500            outfile.write('),\n')
501        showIndent(outfile, level)
502        outfile.write('species=[\n')
503        level += 1
504        for species_ in self.species:
505            showIndent(outfile, level)
506            outfile.write('model_.species(\n')
507            species_.exportLiteral(outfile, level)
508            showIndent(outfile, level)
509            outfile.write('),\n')
510        level -= 1
511        showIndent(outfile, level)
512        outfile.write('],\n')
513        if self.scores is not None:
514            showIndent(outfile, level)
515            outfile.write('scores=model_.scores(\n')
516            self.scores.exportLiteral(outfile, level)
517            showIndent(outfile, level)
518            outfile.write('),\n')
519        if self.groups is not None:
520            showIndent(outfile, level)
521            outfile.write('groups=model_.groups(\n')
522            self.groups.exportLiteral(outfile, level)
523            showIndent(outfile, level)
524            outfile.write('),\n')
525    def build(self, node):
526        self.buildAttributes(node, node.attrib, [])
527        for child in node:
528            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
529            self.buildChildren(child, node, nodeName_)
530    def buildAttributes(self, node, attrs, already_processed):
531        value = find_attr_value_('origin', node)
532        if value is not None and 'origin' not in already_processed:
533            already_processed.append('origin')
534            self.origin = value
535        value = find_attr_value_('version', node)
536        if value is not None and 'version' not in already_processed:
537            already_processed.append('version')
538            try:
539                self.version = float(value)
540            except ValueError as exp:
541                raise ValueError('Bad float/double attribute (version): %s' % exp)
542        value = find_attr_value_('originVersion', node)
543        if value is not None and 'originVersion' not in already_processed:
544            already_processed.append('originVersion')
545            self.originVersion = value
546            self.originVersion = ' '.join(self.originVersion.split())
547    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
548        if nodeName_ == 'notes':
549            obj_ = notes.factory()
550            obj_.build(child_)
551            self.set_notes(obj_)
552        elif nodeName_ == 'species':
553            obj_ = species.factory()
554            obj_.build(child_)
555            self.species.append(obj_)
556        elif nodeName_ == 'scores':
557            obj_ = scores.factory()
558            obj_.build(child_)
559            self.set_scores(obj_)
560        elif nodeName_ == 'groups':
561            obj_ = groups.factory()
562            obj_.build(child_)
563            self.set_groups(obj_)
564# end class orthoXML
565
566
567class species(GeneratedsSuper):
568    """The species element contains all sequences of one species. The NCBI
569    Taxonomy identifier of the species to identify it unambiguously.
570    The name of the species."""
571    subclass = None
572    superclass = None
573    def __init__(self, name=None, NCBITaxId=None, database=None, notes=None, valueOf_=None):
574        self.name = _cast(None, name)
575        self.NCBITaxId = _cast(int, NCBITaxId)
576        if database is None:
577            self.database = []
578        else:
579            self.database = database
580        self.notes = notes
581    def factory(*args_, **kwargs_):
582        if species.subclass:
583            return species.subclass(*args_, **kwargs_)
584        else:
585            return species(*args_, **kwargs_)
586    factory = staticmethod(factory)
587    def get_database(self): return self.database
588    def set_database(self, database): self.database = database
589    def add_database(self, value): self.database.append(value)
590    def insert_database(self, index, value): self.database[index] = value
591    def get_notes(self): return self.notes
592    def set_notes(self, notes): self.notes = notes
593    def get_name(self): return self.name
594    def set_name(self, name): self.name = name
595    def get_NCBITaxId(self): return self.NCBITaxId
596    def set_NCBITaxId(self, NCBITaxId): self.NCBITaxId = NCBITaxId
597    def export(self, outfile, level, namespace_='ortho:', name_='species', namespacedef_=''):
598        showIndent(outfile, level)
599        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
600        already_processed = []
601        self.exportAttributes(outfile, level, already_processed, namespace_, name_='species')
602        if self.hasContent_():
603            outfile.write('>\n')
604            self.exportChildren(outfile, level + 1, namespace_, name_)
605            showIndent(outfile, level)
606            outfile.write('</%s%s>\n' % (namespace_, name_))
607        else:
608            outfile.write('/>\n')
609    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='species'):
610        if self.name is not None and 'name' not in already_processed:
611            already_processed.append('name')
612            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
613        if self.NCBITaxId is not None and 'NCBITaxId' not in already_processed:
614            already_processed.append('NCBITaxId')
615            outfile.write(' NCBITaxId="%s"' % self.gds_format_integer(self.NCBITaxId, input_name='NCBITaxId'))
616    def exportChildren(self, outfile, level, namespace_='ortho:', name_='species', fromsubclass_=False):
617        for database_ in self.database:
618            database_.export(outfile, level, namespace_, name_='database')
619        if self.notes:
620            self.notes.export(outfile, level, namespace_, name_='notes')
621    def hasContent_(self):
622        if (
623            self.database or
624            self.notes is not None
625            ):
626            return True
627        else:
628            return False
629    def exportLiteral(self, outfile, level, name_='species'):
630        level += 1
631        self.exportLiteralAttributes(outfile, level, [], name_)
632        if self.hasContent_():
633            self.exportLiteralChildren(outfile, level, name_)
634    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
635        if self.name is not None and 'name' not in already_processed:
636            already_processed.append('name')
637            showIndent(outfile, level)
638            outfile.write('name = "%s",\n' % (self.name,))
639        if self.NCBITaxId is not None and 'NCBITaxId' not in already_processed:
640            already_processed.append('NCBITaxId')
641            showIndent(outfile, level)
642            outfile.write('NCBITaxId = %d,\n' % (self.NCBITaxId,))
643    def exportLiteralChildren(self, outfile, level, name_):
644        showIndent(outfile, level)
645        outfile.write('database=[\n')
646        level += 1
647        for database_ in self.database:
648            showIndent(outfile, level)
649            outfile.write('model_.database(\n')
650            database_.exportLiteral(outfile, level)
651            showIndent(outfile, level)
652            outfile.write('),\n')
653        level -= 1
654        showIndent(outfile, level)
655        outfile.write('],\n')
656        if self.notes is not None:
657            showIndent(outfile, level)
658            outfile.write('notes=model_.notes(\n')
659            self.notes.exportLiteral(outfile, level)
660            showIndent(outfile, level)
661            outfile.write('),\n')
662    def build(self, node):
663        self.buildAttributes(node, node.attrib, [])
664        for child in node:
665            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
666            self.buildChildren(child, node, nodeName_)
667    def buildAttributes(self, node, attrs, already_processed):
668        value = find_attr_value_('name', node)
669        if value is not None and 'name' not in already_processed:
670            already_processed.append('name')
671            self.name = value
672        value = find_attr_value_('NCBITaxId', node)
673        if value is not None and 'NCBITaxId' not in already_processed:
674            already_processed.append('NCBITaxId')
675            try:
676                self.NCBITaxId = int(value)
677            except ValueError as exp:
678                raise_parse_error(node, 'Bad integer attribute: %s' % exp)
679    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
680        if nodeName_ == 'database':
681            obj_ = database.factory()
682            obj_.build(child_)
683            self.database.append(obj_)
684        elif nodeName_ == 'notes':
685            obj_ = notes.factory()
686            obj_.build(child_)
687            self.set_notes(obj_)
688# end class species
689
690
691class database(GeneratedsSuper):
692    """A database element contains all genes from a single database/source.
693    A Uniform Resource Identifier (URI) pointing to the gene. In the
694    simplest case one could imagine a URL which in concatenation
695    with the gene identifier links to the website of the gene in the
696    source database. However, how this is used depends on the source
697    of the orthoXML file. Name of the database. A Uniform Resource
698    Identifier (URI) pointing to the protein. A Uniform Resource
699    Identifier (URI) pointing to the transcript. Version number of
700    the database."""
701    subclass = None
702    superclass = None
703    def __init__(self, transcriptLink=None, protLink=None, geneLink=None, name=None, version=None, genes=None, valueOf_=None):
704        self.transcriptLink = _cast(None, transcriptLink)
705        self.protLink = _cast(None, protLink)
706        self.geneLink = _cast(None, geneLink)
707        self.name = _cast(None, name)
708        self.version = _cast(None, version)
709        self.genes = genes
710    def factory(*args_, **kwargs_):
711        if database.subclass:
712            return database.subclass(*args_, **kwargs_)
713        else:
714            return database(*args_, **kwargs_)
715    factory = staticmethod(factory)
716    def get_genes(self): return self.genes
717    def set_genes(self, genes): self.genes = genes
718    def get_transcriptLink(self): return self.transcriptLink
719    def set_transcriptLink(self, transcriptLink): self.transcriptLink = transcriptLink
720    def get_protLink(self): return self.protLink
721    def set_protLink(self, protLink): self.protLink = protLink
722    def get_geneLink(self): return self.geneLink
723    def set_geneLink(self, geneLink): self.geneLink = geneLink
724    def get_name(self): return self.name
725    def set_name(self, name): self.name = name
726    def get_version(self): return self.version
727    def set_version(self, version): self.version = version
728    def export(self, outfile, level, namespace_='ortho:', name_='database', namespacedef_=''):
729        showIndent(outfile, level)
730        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
731        already_processed = []
732        self.exportAttributes(outfile, level, already_processed, namespace_, name_='database')
733        if self.hasContent_():
734            outfile.write('>\n')
735            self.exportChildren(outfile, level + 1, namespace_, name_)
736            showIndent(outfile, level)
737            outfile.write('</%s%s>\n' % (namespace_, name_))
738        else:
739            outfile.write('/>\n')
740    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='database'):
741        if self.transcriptLink is not None and 'transcriptLink' not in already_processed:
742            already_processed.append('transcriptLink')
743            outfile.write(' transcriptLink=%s' % (self.gds_format_string(quote_attrib(self.transcriptLink).encode(ExternalEncoding), input_name='transcriptLink'), ))
744        if self.protLink is not None and 'protLink' not in already_processed:
745            already_processed.append('protLink')
746            outfile.write(' protLink=%s' % (self.gds_format_string(quote_attrib(self.protLink).encode(ExternalEncoding), input_name='protLink'), ))
747        if self.geneLink is not None and 'geneLink' not in already_processed:
748            already_processed.append('geneLink')
749            outfile.write(' geneLink=%s' % (self.gds_format_string(quote_attrib(self.geneLink).encode(ExternalEncoding), input_name='geneLink'), ))
750        if self.name is not None and 'name' not in already_processed:
751            already_processed.append('name')
752            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
753        if self.version is not None and 'version' not in already_processed:
754            already_processed.append('version')
755            outfile.write(' version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
756    def exportChildren(self, outfile, level, namespace_='ortho:', name_='database', fromsubclass_=False):
757        if self.genes:
758            self.genes.export(outfile, level, namespace_, name_='genes', )
759    def hasContent_(self):
760        if (
761            self.genes is not None
762            ):
763            return True
764        else:
765            return False
766    def exportLiteral(self, outfile, level, name_='database'):
767        level += 1
768        self.exportLiteralAttributes(outfile, level, [], name_)
769        if self.hasContent_():
770            self.exportLiteralChildren(outfile, level, name_)
771    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
772        if self.transcriptLink is not None and 'transcriptLink' not in already_processed:
773            already_processed.append('transcriptLink')
774            showIndent(outfile, level)
775            outfile.write('transcriptLink = "%s",\n' % (self.transcriptLink,))
776        if self.protLink is not None and 'protLink' not in already_processed:
777            already_processed.append('protLink')
778            showIndent(outfile, level)
779            outfile.write('protLink = "%s",\n' % (self.protLink,))
780        if self.geneLink is not None and 'geneLink' not in already_processed:
781            already_processed.append('geneLink')
782            showIndent(outfile, level)
783            outfile.write('geneLink = "%s",\n' % (self.geneLink,))
784        if self.name is not None and 'name' not in already_processed:
785            already_processed.append('name')
786            showIndent(outfile, level)
787            outfile.write('name = "%s",\n' % (self.name,))
788        if self.version is not None and 'version' not in already_processed:
789            already_processed.append('version')
790            showIndent(outfile, level)
791            outfile.write('version = "%s",\n' % (self.version,))
792    def exportLiteralChildren(self, outfile, level, name_):
793        if self.genes is not None:
794            showIndent(outfile, level)
795            outfile.write('genes=model_.genes(\n')
796            self.genes.exportLiteral(outfile, level)
797            showIndent(outfile, level)
798            outfile.write('),\n')
799    def build(self, node):
800        self.buildAttributes(node, node.attrib, [])
801        for child in node:
802            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
803            self.buildChildren(child, node, nodeName_)
804    def buildAttributes(self, node, attrs, already_processed):
805        value = find_attr_value_('transcriptLink', node)
806        if value is not None and 'transcriptLink' not in already_processed:
807            already_processed.append('transcriptLink')
808            self.transcriptLink = value
809        value = find_attr_value_('protLink', node)
810        if value is not None and 'protLink' not in already_processed:
811            already_processed.append('protLink')
812            self.protLink = value
813        value = find_attr_value_('geneLink', node)
814        if value is not None and 'geneLink' not in already_processed:
815            already_processed.append('geneLink')
816            self.geneLink = value
817        value = find_attr_value_('name', node)
818        if value is not None and 'name' not in already_processed:
819            already_processed.append('name')
820            self.name = value
821        value = find_attr_value_('version', node)
822        if value is not None and 'version' not in already_processed:
823            already_processed.append('version')
824            self.version = value
825    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
826        if nodeName_ == 'genes':
827            obj_ = genes.factory()
828            obj_.build(child_)
829            self.set_genes(obj_)
830# end class database
831
832
833class genes(GeneratedsSuper):
834    """A gene element represents a list of genes."""
835    subclass = None
836    superclass = None
837    def __init__(self, gene=None, valueOf_=None):
838        if gene is None:
839            self.gene = []
840        else:
841            self.gene = gene
842    def factory(*args_, **kwargs_):
843        if genes.subclass:
844            return genes.subclass(*args_, **kwargs_)
845        else:
846            return genes(*args_, **kwargs_)
847    factory = staticmethod(factory)
848    def get_gene(self): return self.gene
849    def set_gene(self, gene): self.gene = gene
850    def add_gene(self, value): self.gene.append(value)
851    def insert_gene(self, index, value): self.gene[index] = value
852    def export(self, outfile, level, namespace_='ortho:', name_='genes', namespacedef_=''):
853        showIndent(outfile, level)
854        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
855        already_processed = []
856        self.exportAttributes(outfile, level, already_processed, namespace_, name_='genes')
857        if self.hasContent_():
858            outfile.write('>\n')
859            self.exportChildren(outfile, level + 1, namespace_, name_)
860            showIndent(outfile, level)
861            outfile.write('</%s%s>\n' % (namespace_, name_))
862        else:
863            outfile.write('/>\n')
864    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='genes'):
865        pass
866    def exportChildren(self, outfile, level, namespace_='ortho:', name_='genes', fromsubclass_=False):
867        for gene_ in self.gene:
868            gene_.export(outfile, level, namespace_, name_='gene')
869    def hasContent_(self):
870        if (
871            self.gene
872            ):
873            return True
874        else:
875            return False
876    def exportLiteral(self, outfile, level, name_='genes'):
877        level += 1
878        self.exportLiteralAttributes(outfile, level, [], name_)
879        if self.hasContent_():
880            self.exportLiteralChildren(outfile, level, name_)
881    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
882        pass
883    def exportLiteralChildren(self, outfile, level, name_):
884        showIndent(outfile, level)
885        outfile.write('gene=[\n')
886        level += 1
887        for gene_ in self.gene:
888            showIndent(outfile, level)
889            outfile.write('model_.gene(\n')
890            gene_.exportLiteral(outfile, level)
891            showIndent(outfile, level)
892            outfile.write('),\n')
893        level -= 1
894        showIndent(outfile, level)
895        outfile.write('],\n')
896    def build(self, node):
897        self.buildAttributes(node, node.attrib, [])
898        for child in node:
899            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
900            self.buildChildren(child, node, nodeName_)
901    def buildAttributes(self, node, attrs, already_processed):
902        pass
903    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
904        if nodeName_ == 'gene':
905            obj_ = gene.factory()
906            obj_.build(child_)
907            self.gene.append(obj_)
908# end class genes
909
910
911class gene(GeneratedsSuper):
912    """The gene element represents a single gene, protein or transcript. It
913    is in fact a set of identifiers: one internal identifier that is
914    used to link from geneRef elements in ortholog clusters and gene
915    identifiers, transcript identifiers and protein identifiers to
916    identify the molecule. The proper term for this element would
917    therefore rather be molecule. However, as the general purpose of
918    orthoXML is to represent orthology data for genes the term gene
919    is used instead. Gene, protein and transcipt identifiers are
920    optional but at least one of the three should be given. The
921    source database of the gene is defined through the database
922    element in which the gene element lies and the identifiers
923    should stem from this source. Identifier of the gene in the
924    source database. Multiple splice forms are possible by having
925    the same geneId more than once. Internal identifier to link to
926    the gene via the geneRef elements. Identifier of the protein in
927    the source database. Identifier of the transcript in the source
928    database."""
929    subclass = None
930    superclass = None
931    def __init__(self, protId=None, id=None, geneId=None, transcriptId=None, valueOf_=None):
932        self.protId = _cast(None, protId)
933        self.id = _cast(int, id)
934        self.geneId = _cast(None, geneId)
935        self.transcriptId = _cast(None, transcriptId)
936        pass
937    def factory(*args_, **kwargs_):
938        if gene.subclass:
939            return gene.subclass(*args_, **kwargs_)
940        else:
941            return gene(*args_, **kwargs_)
942    factory = staticmethod(factory)
943    def get_protId(self): return self.protId
944    def set_protId(self, protId): self.protId = protId
945    def get_id(self): return self.id
946    def set_id(self, id): self.id = id
947    def get_geneId(self): return self.geneId
948    def set_geneId(self, geneId): self.geneId = geneId
949    def get_transcriptId(self): return self.transcriptId
950    def set_transcriptId(self, transcriptId): self.transcriptId = transcriptId
951    def export(self, outfile, level, namespace_='ortho:', name_='gene', namespacedef_=''):
952        showIndent(outfile, level)
953        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
954        already_processed = []
955        self.exportAttributes(outfile, level, already_processed, namespace_, name_='gene')
956        if self.hasContent_():
957            outfile.write('>\n')
958            self.exportChildren(outfile, level + 1, namespace_, name_)
959            outfile.write('</%s%s>\n' % (namespace_, name_))
960        else:
961            outfile.write('/>\n')
962    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='gene'):
963        if self.protId is not None and 'protId' not in already_processed:
964            already_processed.append('protId')
965            outfile.write(' protId=%s' % (self.gds_format_string(quote_attrib(self.protId).encode(ExternalEncoding), input_name='protId'), ))
966        if self.id is not None and 'id' not in already_processed:
967            already_processed.append('id')
968            outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
969        if self.geneId is not None and 'geneId' not in already_processed:
970            already_processed.append('geneId')
971            outfile.write(' geneId=%s' % (self.gds_format_string(quote_attrib(self.geneId).encode(ExternalEncoding), input_name='geneId'), ))
972        if self.transcriptId is not None and 'transcriptId' not in already_processed:
973            already_processed.append('transcriptId')
974            outfile.write(' transcriptId=%s' % (self.gds_format_string(quote_attrib(self.transcriptId).encode(ExternalEncoding), input_name='transcriptId'), ))
975    def exportChildren(self, outfile, level, namespace_='ortho:', name_='gene', fromsubclass_=False):
976        pass
977    def hasContent_(self):
978        if (
979
980            ):
981            return True
982        else:
983            return False
984    def exportLiteral(self, outfile, level, name_='gene'):
985        level += 1
986        self.exportLiteralAttributes(outfile, level, [], name_)
987        if self.hasContent_():
988            self.exportLiteralChildren(outfile, level, name_)
989    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
990        if self.protId is not None and 'protId' not in already_processed:
991            already_processed.append('protId')
992            showIndent(outfile, level)
993            outfile.write('protId = "%s",\n' % (self.protId,))
994        if self.id is not None and 'id' not in already_processed:
995            already_processed.append('id')
996            showIndent(outfile, level)
997            outfile.write('id = %d,\n' % (self.id,))
998        if self.geneId is not None and 'geneId' not in already_processed:
999            already_processed.append('geneId')
1000            showIndent(outfile, level)
1001            outfile.write('geneId = "%s",\n' % (self.geneId,))
1002        if self.transcriptId is not None and 'transcriptId' not in already_processed:
1003            already_processed.append('transcriptId')
1004            showIndent(outfile, level)
1005            outfile.write('transcriptId = "%s",\n' % (self.transcriptId,))
1006    def exportLiteralChildren(self, outfile, level, name_):
1007        pass
1008    def build(self, node):
1009        self.buildAttributes(node, node.attrib, [])
1010        for child in node:
1011            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1012            self.buildChildren(child, node, nodeName_)
1013    def buildAttributes(self, node, attrs, already_processed):
1014        value = find_attr_value_('protId', node)
1015        if value is not None and 'protId' not in already_processed:
1016            already_processed.append('protId')
1017            self.protId = value
1018        value = find_attr_value_('id', node)
1019        if value is not None and 'id' not in already_processed:
1020            already_processed.append('id')
1021            try:
1022                self.id = int(value)
1023            except ValueError as exp:
1024                raise_parse_error(node, 'Bad integer attribute: %s' % exp)
1025        value = find_attr_value_('geneId', node)
1026        if value is not None and 'geneId' not in already_processed:
1027            already_processed.append('geneId')
1028            self.geneId = value
1029        value = find_attr_value_('transcriptId', node)
1030        if value is not None and 'transcriptId' not in already_processed:
1031            already_processed.append('transcriptId')
1032            self.transcriptId = value
1033    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1034        pass
1035# end class gene
1036
1037
1038class scores(GeneratedsSuper):
1039    """A list of score definitions."""
1040    subclass = None
1041    superclass = None
1042    def __init__(self, scoreDef=None, valueOf_=None):
1043        if scoreDef is None:
1044            self.scoreDef = []
1045        else:
1046            self.scoreDef = scoreDef
1047    def factory(*args_, **kwargs_):
1048        if scores.subclass:
1049            return scores.subclass(*args_, **kwargs_)
1050        else:
1051            return scores(*args_, **kwargs_)
1052    factory = staticmethod(factory)
1053    def get_scoreDef(self): return self.scoreDef
1054    def set_scoreDef(self, scoreDef): self.scoreDef = scoreDef
1055    def add_scoreDef(self, value): self.scoreDef.append(value)
1056    def insert_scoreDef(self, index, value): self.scoreDef[index] = value
1057    def export(self, outfile, level, namespace_='ortho:', name_='scores', namespacedef_=''):
1058        showIndent(outfile, level)
1059        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1060        already_processed = []
1061        self.exportAttributes(outfile, level, already_processed, namespace_, name_='scores')
1062        if self.hasContent_():
1063            outfile.write('>\n')
1064            self.exportChildren(outfile, level + 1, namespace_, name_)
1065            showIndent(outfile, level)
1066            outfile.write('</%s%s>\n' % (namespace_, name_))
1067        else:
1068            outfile.write('/>\n')
1069    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='scores'):
1070        pass
1071    def exportChildren(self, outfile, level, namespace_='ortho:', name_='scores', fromsubclass_=False):
1072        for scoreDef_ in self.scoreDef:
1073            scoreDef_.export(outfile, level, namespace_, name_='scoreDef')
1074    def hasContent_(self):
1075        if (
1076            self.scoreDef
1077            ):
1078            return True
1079        else:
1080            return False
1081    def exportLiteral(self, outfile, level, name_='scores'):
1082        level += 1
1083        self.exportLiteralAttributes(outfile, level, [], name_)
1084        if self.hasContent_():
1085            self.exportLiteralChildren(outfile, level, name_)
1086    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1087        pass
1088    def exportLiteralChildren(self, outfile, level, name_):
1089        showIndent(outfile, level)
1090        outfile.write('scoreDef=[\n')
1091        level += 1
1092        for scoreDef_ in self.scoreDef:
1093            showIndent(outfile, level)
1094            outfile.write('model_.scoreDef(\n')
1095            scoreDef_.exportLiteral(outfile, level)
1096            showIndent(outfile, level)
1097            outfile.write('),\n')
1098        level -= 1
1099        showIndent(outfile, level)
1100        outfile.write('],\n')
1101    def build(self, node):
1102        self.buildAttributes(node, node.attrib, [])
1103        for child in node:
1104            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1105            self.buildChildren(child, node, nodeName_)
1106    def buildAttributes(self, node, attrs, already_processed):
1107        pass
1108    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1109        if nodeName_ == 'scoreDef':
1110            obj_ = scoreDef.factory()
1111            obj_.build(child_)
1112            self.scoreDef.append(obj_)
1113# end class scores
1114
1115
1116class groups(GeneratedsSuper):
1117    """Represents the list of ortholog groups. Note that the purpose of
1118    OrthoXML is to store orthology assignment hence on the top level
1119    only ortholog groups are allowed."""
1120    subclass = None
1121    superclass = None
1122    def __init__(self, orthologGroup=None, valueOf_=None):
1123        if orthologGroup is None:
1124            self.orthologGroup = []
1125        else:
1126            self.orthologGroup = orthologGroup
1127    def factory(*args_, **kwargs_):
1128        if groups.subclass:
1129            return groups.subclass(*args_, **kwargs_)
1130        else:
1131            return groups(*args_, **kwargs_)
1132    factory = staticmethod(factory)
1133    def get_orthologGroup(self): return self.orthologGroup
1134    def set_orthologGroup(self, orthologGroup): self.orthologGroup = orthologGroup
1135    def add_orthologGroup(self, value): self.orthologGroup.append(value)
1136    def insert_orthologGroup(self, index, value): self.orthologGroup[index] = value
1137    def export(self, outfile, level, namespace_='ortho:', name_='groups', namespacedef_=''):
1138        showIndent(outfile, level)
1139        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1140        already_processed = []
1141        self.exportAttributes(outfile, level, already_processed, namespace_, name_='groups')
1142        if self.hasContent_():
1143            outfile.write('>\n')
1144            self.exportChildren(outfile, level + 1, namespace_, name_)
1145            showIndent(outfile, level)
1146            outfile.write('</%s%s>\n' % (namespace_, name_))
1147        else:
1148            outfile.write('/>\n')
1149    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='groups'):
1150        pass
1151    def exportChildren(self, outfile, level, namespace_='ortho:', name_='groups', fromsubclass_=False):
1152        for orthologGroup_ in self.orthologGroup:
1153            orthologGroup_.export(outfile, level, namespace_, name_='orthologGroup')
1154    def hasContent_(self):
1155        if (
1156            self.orthologGroup
1157            ):
1158            return True
1159        else:
1160            return False
1161    def exportLiteral(self, outfile, level, name_='groups'):
1162        level += 1
1163        self.exportLiteralAttributes(outfile, level, [], name_)
1164        if self.hasContent_():
1165            self.exportLiteralChildren(outfile, level, name_)
1166    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1167        pass
1168    def exportLiteralChildren(self, outfile, level, name_):
1169        showIndent(outfile, level)
1170        outfile.write('orthologGroup=[\n')
1171        level += 1
1172        for orthologGroup_ in self.orthologGroup:
1173            showIndent(outfile, level)
1174            outfile.write('model_.group(\n')
1175            orthologGroup_.exportLiteral(outfile, level, name_='group')
1176            showIndent(outfile, level)
1177            outfile.write('),\n')
1178        level -= 1
1179        showIndent(outfile, level)
1180        outfile.write('],\n')
1181    def build(self, node):
1182        self.buildAttributes(node, node.attrib, [])
1183        for child in node:
1184            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1185            self.buildChildren(child, node, nodeName_)
1186    def buildAttributes(self, node, attrs, already_processed):
1187        pass
1188    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1189        if nodeName_ == 'orthologGroup':
1190            obj_ = group.factory()
1191            obj_.build(child_)
1192            self.orthologGroup.append(obj_)
1193# end class groups
1194
1195
1196class group(GeneratedsSuper):
1197    """A group of genes or nested groups. In case of a orothologGroup
1198    element, all genes in the group or in the nested groups are
1199    orthologs to each other i.e. stem from the same gene in the last
1200    common ancester of the species. In case of a paralogGroup the
1201    genes are paralogs to each other. Subgroups within the group
1202    allow the represention of phylogenetic trees. For more details
1203    and examples see http://orthoxml.org/orthoxml_doc.html. A group
1204    can may contain two or more of the three alternatives geneRef,
1205    paralogGroup, and orthologGroup. By combining these, complex
1206    phylogenies are possible. Identifier for the group in context of
1207    the resource. This attribute is not required but if your
1208    resource provides identifiers for the ortholog groups we
1209    strongly recommend to use it at least for the top level groups."""
1210    subclass = None
1211    superclass = None
1212    def __init__(self, id=None, score=None, property=None, geneRef=None, paralogGroup=None, orthologGroup=None, notes=None, valueOf_=None):
1213        self.id = _cast(None, id)
1214        if score is None:
1215            self.score = []
1216        else:
1217            self.score = score
1218        if property is None:
1219            self.property = []
1220        else:
1221            self.property = property
1222        if geneRef is None:
1223            self.geneRef = []
1224        else:
1225            self.geneRef = geneRef
1226        if paralogGroup is None:
1227            self.paralogGroup = []
1228        else:
1229            self.paralogGroup = paralogGroup
1230        if orthologGroup is None:
1231            self.orthologGroup = []
1232        else:
1233            self.orthologGroup = orthologGroup
1234        self.notes = notes
1235    def factory(*args_, **kwargs_):
1236        if group.subclass:
1237            return group.subclass(*args_, **kwargs_)
1238        else:
1239            return group(*args_, **kwargs_)
1240    factory = staticmethod(factory)
1241    def get_score(self): return self.score
1242    def set_score(self, score): self.score = score
1243    def add_score(self, value): self.score.append(value)
1244    def insert_score(self, index, value): self.score[index] = value
1245    def get_property(self): return self.property
1246    def set_property(self, property): self.property = property
1247    def add_property(self, value): self.property.append(value)
1248    def insert_property(self, index, value): self.property[index] = value
1249    def get_geneRef(self): return self.geneRef
1250    def set_geneRef(self, geneRef): self.geneRef = geneRef
1251    def add_geneRef(self, value): self.geneRef.append(value)
1252    def insert_geneRef(self, index, value): self.geneRef[index] = value
1253    def get_paralogGroup(self): return self.paralogGroup
1254    def set_paralogGroup(self, paralogGroup): self.paralogGroup = paralogGroup
1255    def add_paralogGroup(self, value): self.paralogGroup.append(value)
1256    def insert_paralogGroup(self, index, value): self.paralogGroup[index] = value
1257    def get_orthologGroup(self): return self.orthologGroup
1258    def set_orthologGroup(self, orthologGroup): self.orthologGroup = orthologGroup
1259    def add_orthologGroup(self, value): self.orthologGroup.append(value)
1260    def insert_orthologGroup(self, index, value): self.orthologGroup[index] = value
1261    def get_notes(self): return self.notes
1262    def set_notes(self, notes): self.notes = notes
1263    def get_id(self): return self.id
1264    def set_id(self, id): self.id = id
1265    def export(self, outfile, level, namespace_='ortho:', name_='group', namespacedef_=''):
1266        showIndent(outfile, level)
1267        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1268        already_processed = []
1269        self.exportAttributes(outfile, level, already_processed, namespace_, name_='group')
1270        if self.hasContent_():
1271            outfile.write('>\n')
1272            self.exportChildren(outfile, level + 1, namespace_, name_)
1273            showIndent(outfile, level)
1274            outfile.write('</%s%s>\n' % (namespace_, name_))
1275        else:
1276            outfile.write('/>\n')
1277    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='group'):
1278        if self.id is not None and 'id' not in already_processed:
1279            already_processed.append('id')
1280            outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
1281    def exportChildren(self, outfile, level, namespace_='ortho:', name_='group', fromsubclass_=False):
1282        for score_ in self.score:
1283            score_.export(outfile, level, namespace_, name_='score')
1284        for property_ in self.property:
1285            property_.export(outfile, level, namespace_, name_='property')
1286        for geneRef_ in self.geneRef:
1287            geneRef_.export(outfile, level, namespace_, name_='geneRef')
1288        for paralogGroup_ in self.paralogGroup:
1289            paralogGroup_.export(outfile, level, namespace_, name_='paralogGroup')
1290        for orthologGroup_ in self.orthologGroup:
1291            orthologGroup_.export(outfile, level, namespace_, name_='orthologGroup')
1292        if self.notes:
1293            self.notes.export(outfile, level, namespace_, name_='notes')
1294    def hasContent_(self):
1295        if (
1296            self.score or
1297            self.property or
1298            self.geneRef or
1299            self.paralogGroup or
1300            self.orthologGroup or
1301            self.notes is not None
1302            ):
1303            return True
1304        else:
1305            return False
1306    def exportLiteral(self, outfile, level, name_='group'):
1307        level += 1
1308        self.exportLiteralAttributes(outfile, level, [], name_)
1309        if self.hasContent_():
1310            self.exportLiteralChildren(outfile, level, name_)
1311    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1312        if self.id is not None and 'id' not in already_processed:
1313            already_processed.append('id')
1314            showIndent(outfile, level)
1315            outfile.write('id = "%s",\n' % (self.id,))
1316    def exportLiteralChildren(self, outfile, level, name_):
1317        showIndent(outfile, level)
1318        outfile.write('score=[\n')
1319        level += 1
1320        for score_ in self.score:
1321            showIndent(outfile, level)
1322            outfile.write('model_.score(\n')
1323            score_.exportLiteral(outfile, level)
1324            showIndent(outfile, level)
1325            outfile.write('),\n')
1326        level -= 1
1327        showIndent(outfile, level)
1328        outfile.write('],\n')
1329        showIndent(outfile, level)
1330        outfile.write('property=[\n')
1331        level += 1
1332        for property_ in self.property:
1333            showIndent(outfile, level)
1334            outfile.write('model_.property(\n')
1335            property_.exportLiteral(outfile, level)
1336            showIndent(outfile, level)
1337            outfile.write('),\n')
1338        level -= 1
1339        showIndent(outfile, level)
1340        outfile.write('],\n')
1341        showIndent(outfile, level)
1342        outfile.write('geneRef=[\n')
1343        level += 1
1344        for geneRef_ in self.geneRef:
1345            showIndent(outfile, level)
1346            outfile.write('model_.geneRef(\n')
1347            geneRef_.exportLiteral(outfile, level)
1348            showIndent(outfile, level)
1349            outfile.write('),\n')
1350        level -= 1
1351        showIndent(outfile, level)
1352        outfile.write('],\n')
1353        showIndent(outfile, level)
1354        outfile.write('paralogGroup=[\n')
1355        level += 1
1356        for paralogGroup_ in self.paralogGroup:
1357            showIndent(outfile, level)
1358            outfile.write('model_.group(\n')
1359            paralogGroup_.exportLiteral(outfile, level, name_='group')
1360            showIndent(outfile, level)
1361            outfile.write('),\n')
1362        level -= 1
1363        showIndent(outfile, level)
1364        outfile.write('],\n')
1365        showIndent(outfile, level)
1366        outfile.write('orthologGroup=[\n')
1367        level += 1
1368        for orthologGroup_ in self.orthologGroup:
1369            showIndent(outfile, level)
1370            outfile.write('model_.group(\n')
1371            orthologGroup_.exportLiteral(outfile, level, name_='group')
1372            showIndent(outfile, level)
1373            outfile.write('),\n')
1374        level -= 1
1375        showIndent(outfile, level)
1376        outfile.write('],\n')
1377        if self.notes is not None:
1378            showIndent(outfile, level)
1379            outfile.write('notes=model_.notes(\n')
1380            self.notes.exportLiteral(outfile, level)
1381            showIndent(outfile, level)
1382            outfile.write('),\n')
1383    def build(self, node):
1384        self.buildAttributes(node, node.attrib, [])
1385        for child in node:
1386            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1387            self.buildChildren(child, node, nodeName_)
1388    def buildAttributes(self, node, attrs, already_processed):
1389        value = find_attr_value_('id', node)
1390        if value is not None and 'id' not in already_processed:
1391            already_processed.append('id')
1392            self.id = value
1393    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1394        if nodeName_ == 'score':
1395            obj_ = score.factory()
1396            obj_.build(child_)
1397            self.score.append(obj_)
1398        elif nodeName_ == 'property':
1399            obj_ = property.factory()
1400            obj_.build(child_)
1401            self.property.append(obj_)
1402        elif nodeName_ == 'geneRef':
1403            obj_ = geneRef.factory()
1404            obj_.build(child_)
1405            self.geneRef.append(obj_)
1406        elif nodeName_ == 'paralogGroup':
1407            obj_ = group.factory()
1408            obj_.build(child_)
1409            self.paralogGroup.append(obj_)
1410        elif nodeName_ == 'orthologGroup':
1411            obj_ = group.factory()
1412            obj_.build(child_)
1413            self.orthologGroup.append(obj_)
1414        elif nodeName_ == 'notes':
1415            obj_ = notes.factory()
1416            obj_.build(child_)
1417            self.set_notes(obj_)
1418# end class group
1419
1420
1421class geneRef(GeneratedsSuper):
1422    """The geneRef element is a link to the gene definition under the
1423    species element. It defines the members of an ortholog or
1424    paralog group. The same gene can be referenced muliple times.
1425    The geneRef element can have multiple score elements and a notes
1426    elements as children. The notes element can for instance be used
1427    for special, ortholog-database-specific information (with
1428    InParanoid, for example, we could use it to mark the seed
1429    orthologs). Internal identifier for a gene element defined under
1430    the species element."""
1431    subclass = None
1432    superclass = None
1433    def __init__(self, id=None, score=None, notes=None, valueOf_=None):
1434        self.id = _cast(int, id)
1435        if score is None:
1436            self.score = []
1437        else:
1438            self.score = score
1439        self.notes = notes
1440    def factory(*args_, **kwargs_):
1441        if geneRef.subclass:
1442            return geneRef.subclass(*args_, **kwargs_)
1443        else:
1444            return geneRef(*args_, **kwargs_)
1445    factory = staticmethod(factory)
1446    def get_score(self): return self.score
1447    def set_score(self, score): self.score = score
1448    def add_score(self, value): self.score.append(value)
1449    def insert_score(self, index, value): self.score[index] = value
1450    def get_notes(self): return self.notes
1451    def set_notes(self, notes): self.notes = notes
1452    def get_id(self): return self.id
1453    def set_id(self, id): self.id = id
1454    def export(self, outfile, level, namespace_='ortho:', name_='geneRef', namespacedef_=''):
1455        showIndent(outfile, level)
1456        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1457        already_processed = []
1458        self.exportAttributes(outfile, level, already_processed, namespace_, name_='geneRef')
1459        if self.hasContent_():
1460            outfile.write('>\n')
1461            self.exportChildren(outfile, level + 1, namespace_, name_)
1462            showIndent(outfile, level)
1463            outfile.write('</%s%s>\n' % (namespace_, name_))
1464        else:
1465            outfile.write('/>\n')
1466    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='geneRef'):
1467        if self.id is not None and 'id' not in already_processed:
1468            already_processed.append('id')
1469            outfile.write(' id="%s"' % self.gds_format_integer(self.id, input_name='id'))
1470    def exportChildren(self, outfile, level, namespace_='ortho:', name_='geneRef', fromsubclass_=False):
1471        for score_ in self.score:
1472            score_.export(outfile, level, namespace_, name_='score')
1473        if self.notes:
1474            self.notes.export(outfile, level, namespace_, name_='notes')
1475    def hasContent_(self):
1476        if (
1477            self.score or
1478            self.notes is not None
1479            ):
1480            return True
1481        else:
1482            return False
1483    def exportLiteral(self, outfile, level, name_='geneRef'):
1484        level += 1
1485        self.exportLiteralAttributes(outfile, level, [], name_)
1486        if self.hasContent_():
1487            self.exportLiteralChildren(outfile, level, name_)
1488    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1489        if self.id is not None and 'id' not in already_processed:
1490            already_processed.append('id')
1491            showIndent(outfile, level)
1492            outfile.write('id = %d,\n' % (self.id,))
1493    def exportLiteralChildren(self, outfile, level, name_):
1494        showIndent(outfile, level)
1495        outfile.write('score=[\n')
1496        level += 1
1497        for score_ in self.score:
1498            showIndent(outfile, level)
1499            outfile.write('model_.score(\n')
1500            score_.exportLiteral(outfile, level)
1501            showIndent(outfile, level)
1502            outfile.write('),\n')
1503        level -= 1
1504        showIndent(outfile, level)
1505        outfile.write('],\n')
1506        if self.notes is not None:
1507            showIndent(outfile, level)
1508            outfile.write('notes=model_.notes(\n')
1509            self.notes.exportLiteral(outfile, level)
1510            showIndent(outfile, level)
1511            outfile.write('),\n')
1512    def build(self, node):
1513        self.buildAttributes(node, node.attrib, [])
1514        for child in node:
1515            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1516            self.buildChildren(child, node, nodeName_)
1517    def buildAttributes(self, node, attrs, already_processed):
1518        value = find_attr_value_('id', node)
1519        if value is not None and 'id' not in already_processed:
1520            already_processed.append('id')
1521            try:
1522                self.id = int(value)
1523            except ValueError as exp:
1524                raise_parse_error(node, 'Bad integer attribute: %s' % exp)
1525    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1526        if nodeName_ == 'score':
1527            obj_ = score.factory()
1528            obj_.build(child_)
1529            self.score.append(obj_)
1530        elif nodeName_ == 'notes':
1531            obj_ = notes.factory()
1532            obj_.build(child_)
1533            self.set_notes(obj_)
1534# end class geneRef
1535
1536
1537class scoreDef(GeneratedsSuper):
1538    """The scoreDef element defines a score. One of the concepts of
1539    orthoXML is to be as flexible as possible but still uniformly
1540    parsable. Part of this is to allow every ortholog resource to
1541    give their own types of scores for groups or group members,
1542    which is done using score elements. Score elements can be
1543    defined to apply to either groups or geneRefs. It is possible to
1544    define multiple scores. An internal identifier to link to the
1545    scoreDef from a score element. Description of the score."""
1546    subclass = None
1547    superclass = None
1548    def __init__(self, id=None, desc=None, valueOf_=None):
1549        self.id = _cast(None, id)
1550        self.desc = _cast(None, desc)
1551        pass
1552    def factory(*args_, **kwargs_):
1553        if scoreDef.subclass:
1554            return scoreDef.subclass(*args_, **kwargs_)
1555        else:
1556            return scoreDef(*args_, **kwargs_)
1557    factory = staticmethod(factory)
1558    def get_id(self): return self.id
1559    def set_id(self, id): self.id = id
1560    def get_desc(self): return self.desc
1561    def set_desc(self, desc): self.desc = desc
1562    def export(self, outfile, level, namespace_='ortho:', name_='scoreDef', namespacedef_=''):
1563        showIndent(outfile, level)
1564        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1565        already_processed = []
1566        self.exportAttributes(outfile, level, already_processed, namespace_, name_='scoreDef')
1567        if self.hasContent_():
1568            outfile.write('>\n')
1569            self.exportChildren(outfile, level + 1, namespace_, name_)
1570            outfile.write('</%s%s>\n' % (namespace_, name_))
1571        else:
1572            outfile.write('/>\n')
1573    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='scoreDef'):
1574        if self.id is not None and 'id' not in already_processed:
1575            already_processed.append('id')
1576            outfile.write(' id=%s' % (quote_attrib(self.id), ))
1577        if self.desc is not None and 'desc' not in already_processed:
1578            already_processed.append('desc')
1579            outfile.write(' desc=%s' % (self.gds_format_string(quote_attrib(self.desc).encode(ExternalEncoding), input_name='desc'), ))
1580    def exportChildren(self, outfile, level, namespace_='ortho:', name_='scoreDef', fromsubclass_=False):
1581        pass
1582    def hasContent_(self):
1583        if (
1584
1585            ):
1586            return True
1587        else:
1588            return False
1589    def exportLiteral(self, outfile, level, name_='scoreDef'):
1590        level += 1
1591        self.exportLiteralAttributes(outfile, level, [], name_)
1592        if self.hasContent_():
1593            self.exportLiteralChildren(outfile, level, name_)
1594    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1595        if self.id is not None and 'id' not in already_processed:
1596            already_processed.append('id')
1597            showIndent(outfile, level)
1598            outfile.write('id = "%s",\n' % (self.id,))
1599        if self.desc is not None and 'desc' not in already_processed:
1600            already_processed.append('desc')
1601            showIndent(outfile, level)
1602            outfile.write('desc = "%s",\n' % (self.desc,))
1603    def exportLiteralChildren(self, outfile, level, name_):
1604        pass
1605    def build(self, node):
1606        self.buildAttributes(node, node.attrib, [])
1607        for child in node:
1608            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1609            self.buildChildren(child, node, nodeName_)
1610    def buildAttributes(self, node, attrs, already_processed):
1611        value = find_attr_value_('id', node)
1612        if value is not None and 'id' not in already_processed:
1613            already_processed.append('id')
1614            self.id = value
1615        value = find_attr_value_('desc', node)
1616        if value is not None and 'desc' not in already_processed:
1617            already_processed.append('desc')
1618            self.desc = value
1619    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1620        pass
1621# end class scoreDef
1622
1623
1624class score(GeneratedsSuper):
1625    """The score element gives the value of a score and links it to the
1626    scoreDef element, which defines the score. It can be child of a
1627    group or a geneRef element to allow scoring on different levels.
1628    An identifier linking to the scoreDef element, which defines the
1629    score. The actual value of the score. For instance a confidence
1630    score of a group member."""
1631    subclass = None
1632    superclass = None
1633    def __init__(self, id=None, value=None, valueOf_=None):
1634        self.id = _cast(None, id)
1635        self.value = _cast(float, value)
1636        pass
1637    def factory(*args_, **kwargs_):
1638        if score.subclass:
1639            return score.subclass(*args_, **kwargs_)
1640        else:
1641            return score(*args_, **kwargs_)
1642    factory = staticmethod(factory)
1643    def get_id(self): return self.id
1644    def set_id(self, id): self.id = id
1645    def get_value(self): return self.value
1646    def set_value(self, value): self.value = value
1647    def export(self, outfile, level, namespace_='ortho:', name_='score', namespacedef_=''):
1648        showIndent(outfile, level)
1649        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1650        already_processed = []
1651        self.exportAttributes(outfile, level, already_processed, namespace_, name_='score')
1652        if self.hasContent_():
1653            outfile.write('>\n')
1654            self.exportChildren(outfile, level + 1, namespace_, name_)
1655            outfile.write('</%s%s>\n' % (namespace_, name_))
1656        else:
1657            outfile.write('/>\n')
1658    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='score'):
1659        if self.id is not None and 'id' not in already_processed:
1660            already_processed.append('id')
1661            outfile.write(' id=%s' % (quote_attrib(self.id), ))
1662        if self.value is not None and 'value' not in already_processed:
1663            already_processed.append('value')
1664            outfile.write(' value="%s"' % self.gds_format_float(self.value, input_name='value'))
1665    def exportChildren(self, outfile, level, namespace_='ortho:', name_='score', fromsubclass_=False):
1666        pass
1667    def hasContent_(self):
1668        if (
1669
1670            ):
1671            return True
1672        else:
1673            return False
1674    def exportLiteral(self, outfile, level, name_='score'):
1675        level += 1
1676        self.exportLiteralAttributes(outfile, level, [], name_)
1677        if self.hasContent_():
1678            self.exportLiteralChildren(outfile, level, name_)
1679    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1680        if self.id is not None and 'id' not in already_processed:
1681            already_processed.append('id')
1682            showIndent(outfile, level)
1683            outfile.write('id = "%s",\n' % (self.id,))
1684        if self.value is not None and 'value' not in already_processed:
1685            already_processed.append('value')
1686            showIndent(outfile, level)
1687            outfile.write('value = %f,\n' % (self.value,))
1688    def exportLiteralChildren(self, outfile, level, name_):
1689        pass
1690    def build(self, node):
1691        self.buildAttributes(node, node.attrib, [])
1692        for child in node:
1693            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1694            self.buildChildren(child, node, nodeName_)
1695    def buildAttributes(self, node, attrs, already_processed):
1696        value = find_attr_value_('id', node)
1697        if value is not None and 'id' not in already_processed:
1698            already_processed.append('id')
1699            self.id = value
1700        value = find_attr_value_('value', node)
1701        if value is not None and 'value' not in already_processed:
1702            already_processed.append('value')
1703            try:
1704                self.value = float(value)
1705            except ValueError as exp:
1706                raise ValueError('Bad float/double attribute (value): %s' % exp)
1707    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1708        pass
1709# end class score
1710
1711
1712class property(GeneratedsSuper):
1713    """Key-value pair for group annotations, for instance statistics about
1714    the group members. The key of the key-value annotation pair. The
1715    value of the key-value annotation pair. Optional to allow flag
1716    like annotations."""
1717    subclass = None
1718    superclass = None
1719    def __init__(self, name=None, value=None, valueOf_=None):
1720        self.name = _cast(None, name)
1721        self.value = _cast(None, value)
1722        pass
1723    def factory(*args_, **kwargs_):
1724        if property.subclass:
1725            return property.subclass(*args_, **kwargs_)
1726        else:
1727            return property(*args_, **kwargs_)
1728    factory = staticmethod(factory)
1729    def get_name(self): return self.name
1730    def set_name(self, name): self.name = name
1731    def get_value(self): return self.value
1732    def set_value(self, value): self.value = value
1733    def export(self, outfile, level, namespace_='ortho:', name_='property', namespacedef_=''):
1734        showIndent(outfile, level)
1735        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1736        already_processed = []
1737        self.exportAttributes(outfile, level, already_processed, namespace_, name_='property')
1738        if self.hasContent_():
1739            outfile.write('>\n')
1740            self.exportChildren(outfile, level + 1, namespace_, name_)
1741            outfile.write('</%s%s>\n' % (namespace_, name_))
1742        else:
1743            outfile.write('/>\n')
1744    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='property'):
1745        if self.name is not None and 'name' not in already_processed:
1746            already_processed.append('name')
1747            outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), ))
1748        if self.value is not None and 'value' not in already_processed:
1749            already_processed.append('value')
1750            outfile.write(' value=%s' % (self.gds_format_string(quote_attrib(self.value).encode(ExternalEncoding), input_name='value'), ))
1751    def exportChildren(self, outfile, level, namespace_='ortho:', name_='property', fromsubclass_=False):
1752        pass
1753    def hasContent_(self):
1754        if (
1755
1756            ):
1757            return True
1758        else:
1759            return False
1760    def exportLiteral(self, outfile, level, name_='property'):
1761        level += 1
1762        self.exportLiteralAttributes(outfile, level, [], name_)
1763        if self.hasContent_():
1764            self.exportLiteralChildren(outfile, level, name_)
1765    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1766        if self.name is not None and 'name' not in already_processed:
1767            already_processed.append('name')
1768            showIndent(outfile, level)
1769            outfile.write('name = "%s",\n' % (self.name,))
1770        if self.value is not None and 'value' not in already_processed:
1771            already_processed.append('value')
1772            showIndent(outfile, level)
1773            outfile.write('value = "%s",\n' % (self.value,))
1774    def exportLiteralChildren(self, outfile, level, name_):
1775        pass
1776    def build(self, node):
1777        self.buildAttributes(node, node.attrib, [])
1778        for child in node:
1779            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1780            self.buildChildren(child, node, nodeName_)
1781    def buildAttributes(self, node, attrs, already_processed):
1782        value = find_attr_value_('name', node)
1783        if value is not None and 'name' not in already_processed:
1784            already_processed.append('name')
1785            self.name = value
1786        value = find_attr_value_('value', node)
1787        if value is not None and 'value' not in already_processed:
1788            already_processed.append('value')
1789            self.value = value
1790    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1791        pass
1792# end class property
1793
1794
1795class notes(GeneratedsSuper):
1796    """The notes element is a special element, which allows adding
1797    information that is not general enough to be part of the
1798    standard. I.e. something specific to a particular ortholog
1799    database or algorithm. Notes elements will not be validated, so
1800    any child elements are legal. Notes elements can be children of
1801    the root element orthoXML, the species element, the
1802    orthologGroup element, the paralogGroup element, or the geneRef
1803    element."""
1804    subclass = None
1805    superclass = None
1806    def __init__(self, valueOf_=None, mixedclass_=None, content_=None):
1807        self.valueOf_ = valueOf_
1808        if mixedclass_ is None:
1809            self.mixedclass_ = MixedContainer
1810        else:
1811            self.mixedclass_ = mixedclass_
1812        if content_ is None:
1813            self.content_ = []
1814        else:
1815            self.content_ = content_
1816        self.valueOf_ = valueOf_
1817    def factory(*args_, **kwargs_):
1818        if notes.subclass:
1819            return notes.subclass(*args_, **kwargs_)
1820        else:
1821            return notes(*args_, **kwargs_)
1822    factory = staticmethod(factory)
1823    def get_valueOf_(self): return self.valueOf_
1824    def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
1825    def export(self, outfile, level, namespace_='ortho:', name_='notes', namespacedef_=''):
1826        showIndent(outfile, level)
1827        outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
1828        already_processed = []
1829        self.exportAttributes(outfile, level, already_processed, namespace_, name_='notes')
1830        outfile.write('>')
1831        self.exportChildren(outfile, level + 1, namespace_, name_)
1832        outfile.write('</%s%s>\n' % (namespace_, name_))
1833    def exportAttributes(self, outfile, level, already_processed, namespace_='ortho:', name_='notes'):
1834        pass
1835    def exportChildren(self, outfile, level, namespace_='ortho:', name_='notes', fromsubclass_=False):
1836        pass
1837    def hasContent_(self):
1838        if (
1839            self.valueOf_
1840            ):
1841            return True
1842        else:
1843            return False
1844    def exportLiteral(self, outfile, level, name_='notes'):
1845        level += 1
1846        self.exportLiteralAttributes(outfile, level, [], name_)
1847        if self.hasContent_():
1848            self.exportLiteralChildren(outfile, level, name_)
1849        showIndent(outfile, level)
1850        outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
1851    def exportLiteralAttributes(self, outfile, level, already_processed, name_):
1852        pass
1853    def exportLiteralChildren(self, outfile, level, name_):
1854        pass
1855    def build(self, node):
1856        self.buildAttributes(node, node.attrib, [])
1857        self.valueOf_ = get_all_text_(node)
1858        if node.text is not None:
1859            obj_ = self.mixedclass_(MixedContainer.CategoryText,
1860                MixedContainer.TypeNone, '', node.text)
1861            self.content_.append(obj_)
1862        for child in node:
1863            nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
1864            self.buildChildren(child, node, nodeName_)
1865    def buildAttributes(self, node, attrs, already_processed):
1866        pass
1867    def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
1868        if not fromsubclass_ and child_.tail is not None:
1869            obj_ = self.mixedclass_(MixedContainer.CategoryText,
1870                MixedContainer.TypeNone, '', child_.tail)
1871            self.content_.append(obj_)
1872        pass
1873# end class notes
1874
1875
1876USAGE_TEXT = """
1877Usage: python <Parser>.py [ -s ] <in_xml_file>
1878"""
1879
1880def usage():
1881    print(USAGE_TEXT)
1882    sys.exit(1)
1883
1884
1885def get_root_tag(node):
1886    tag = Tag_pattern_.match(node.tag).groups()[-1]
1887    rootClass = globals().get(tag)
1888    return tag, rootClass
1889
1890
1891def parse(inFileName):
1892    doc = parsexml_(inFileName)
1893    rootNode = doc.getroot()
1894    rootTag, rootClass = get_root_tag(rootNode)
1895    if rootClass is None:
1896        rootTag = 'orthoXML'
1897        rootClass = orthoXML
1898    rootObj = rootClass.factory()
1899    rootObj.build(rootNode)
1900    # Enable Python to collect the space used by the DOM.
1901    doc = None
1902##     sys.stdout.write('<?xml version="1.0" ?>\n')
1903##     rootObj.export(sys.stdout, 0, name_=rootTag,
1904##         namespacedef_='xmlns:ortho="http://orthoXML.org/2011/"')
1905    return rootObj
1906
1907
1908def parseString(inString):
1909    from StringIO import StringIO
1910    doc = parsexml_(StringIO(inString))
1911    rootNode = doc.getroot()
1912    rootTag, rootClass = get_root_tag(rootNode)
1913    if rootClass is None:
1914        rootTag = 'orthoXML'
1915        rootClass = orthoXML
1916    rootObj = rootClass.factory()
1917    rootObj.build(rootNode)
1918    # Enable Python to collect the space used by the DOM.
1919    doc = None
1920##     sys.stdout.write('<?xml version="1.0" ?>\n')
1921##     rootObj.export(sys.stdout, 0, name_="orthoXML",
1922##         namespacedef_='xmlns:ortho="http://orthoXML.org/2011/"')
1923    return rootObj
1924
1925
1926def parseLiteral(inFileName):
1927    doc = parsexml_(inFileName)
1928    rootNode = doc.getroot()
1929    rootTag, rootClass = get_root_tag(rootNode)
1930    if rootClass is None:
1931        rootTag = 'orthoXML'
1932        rootClass = orthoXML
1933    rootObj = rootClass.factory()
1934    rootObj.build(rootNode)
1935    # Enable Python to collect the space used by the DOM.
1936    doc = None
1937##     sys.stdout.write('#from orthoxml import *\n\n')
1938##     sys.stdout.write('import orthoxml as model_\n\n')
1939##     sys.stdout.write('rootObj = model_.rootTag(\n')
1940##     rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
1941##     sys.stdout.write(')\n')
1942    return rootObj
1943
1944
1945def main():
1946    args = sys.argv[1:]
1947    if len(args) == 1:
1948        parse(args[0])
1949    else:
1950        usage()
1951
1952
1953if __name__ == '__main__':
1954    #import pdb; pdb.set_trace()
1955    main()
1956
1957
1958__all__ = [
1959    "database",
1960    "gene",
1961    "geneRef",
1962    "genes",
1963    "group",
1964    "groups",
1965    "notes",
1966    "orthoXML",
1967    "property",
1968    "score",
1969    "scoreDef",
1970    "scores",
1971    "species"
1972    ]
1973