Skip to content

Annotations not properly parsed #21

@sulheim

Description

@sulheim

Reframed currently only parses the human readable part of the annotations in an SBML model file.

Example

model = reframed.load_cbmodel('bigg_universe.xml')
print(model.reactions.R_G1PP.metadata)

OrderedDict([('SBOTerm', 'SBO:0000176'),
             ('XMLAnnotation',
              '<annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">\n  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:vCard4="http://www.w3.org/2006/vcard/ns#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">\n    <rdf:Description rdf:about="#R_G1PP">\n      <bqbiol:is>\n        <rdf:Bag>\n          <rdf:li rdf:resource="http://identifiers.org/rhea/19933"/>\n          <rdf:li rdf:resource="http://identifiers.org/rhea/19934"/>\n          <rdf:li rdf:resource="http://identifiers.org/rhea/19935"/>\n          <rdf:li rdf:resource="http://identifiers.org/rhea/19936"/>\n          <rdf:li rdf:resource="http://identifiers.org/ec-code/3.1.3.10"/>\n          <rdf:li rdf:resource="http://identifiers.org/biocyc/META:GLUCOSE-1-PHOSPHAT-RXN"/>\n          <rdf:li rdf:resource="http://identifiers.org/biocyc/META:RXN-17330"/>\n          <rdf:li rdf:resource="http://identifiers.org/metanetx.reaction/MNXR99844"/>\n          <rdf:li rdf:resource="http://identifiers.org/kegg.reaction/R00304"/>\n          <rdf:li rdf:resource="http://identifiers.org/seed.reaction/rxn00221"/>\n        </rdf:Bag>\n      </bqbiol:is>\n    </rdf:Description>\n  </rdf:RDF>\n</annotation>')])

Workaround

Until a proper parser is implemented it is possible to use a workaround like this (which uses the xmltodixt package):

def convert_xml_to_annotation_dict(x):
    """
    x can be a reaction or a metabolite
    """
    
    ann_dict = {}
    try:
        ann_string = x.metadata['XMLAnnotation']
        temp_dic = xmltodict.parse(ann_string)
        entries = temp_dic['annotation']['rdf:RDF']['rdf:Description']['bqbiol:is']['rdf:Bag']['rdf:li']
    except (TypeError, KeyError) as e:
        pass
    else:
        for entry in entries:
            try:
                key = entry['@rdf:resource']
            except TypeError:
                pass
            else:
                db, value = key.split('/')[-2:]
                ann_dict[db]=value
            
    return ann_dict

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions