Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBML write returns error when values are integers #724

Closed
paxelito opened this issue Jun 13, 2018 · 6 comments
Closed

SBML write returns error when values are integers #724

paxelito opened this issue Jun 13, 2018 · 6 comments
Assignees
Labels
SBML Related to reading and writing SBML models.

Comments

@paxelito
Copy link

paxelito commented Jun 13, 2018

Problem description

Hi, while saving a model by using cobra.io.write_sbml_model the system returns the error reported below.

cobra.io.write_sbml_model(some_model, "some_model.sbml")
# Every reaction has the following annotation
{'confidence_level': 2, 'genome_annotation': 'NCBI'} # NOT WORKING
{'confidence_level': [2], 'genome_annotation': 'NCBI'} # IT WORKS

Actual Output


TypeError Traceback (most recent call last)
in ()
----> 1 cobra.io.write_sbml_model(myWT5260_NCBI_v1, "Streptomyces-rimosus-WT5260/models/GBM_WT5260_ver1.0.sbml")
2 myWT5260_NCBI_v2 = deepcopy(myWT5260_NCBI_v1)
3 myWT5260_NCBI_v2.model_summary()

~/Documents/git-projects/genome-based-models/env_gbm/lib/python3.6/site-packages/cobra/io/sbml3.py in write_sbml_model(cobra_model, filename, use_fbc_package, **kwargs)
715 return
716 # create xml
--> 717 xml = model_to_xml(cobra_model, **kwargs)
718 write_args = {"encoding": "UTF-8", "xml_declaration": True}
719 if _with_lxml:

~/Documents/git-projects/genome-based-models/env_gbm/lib/python3.6/site-packages/cobra/io/sbml3.py in model_to_xml(cobra_model, units)
512 reversible=str(reaction.lower_bound < 0).lower())
513 set_attrib(sbml_reaction, "name", reaction.name)
--> 514 annotate_sbml_from_cobra(sbml_reaction, reaction)
515 # add in bounds
516 set_attrib(sbml_reaction, "fbc:upperFluxBound",

~/Documents/git-projects/genome-based-models/env_gbm/lib/python3.6/site-packages/cobra/io/sbml3.py in annotate_sbml_from_cobra(sbml_element, cobra_element)
248 if isinstance(identifiers, string_types):
249 identifiers = (identifiers,)
--> 250 for identifier in identifiers:
251 li = SubElement(bag, ns("rdf:li"))
252 set_attrib(li, "rdf:resource", "http://identifiers.org/%s/%s" %

TypeError: 'int' object is not iterable

Expected Output

Save goes successfully

Dependency Information

Please paste the output of python -c "from cobra import show_versions; show_versions()" in the details block below.

System Information

OS Darwin
OS-release 17.5.0
Python 3.6.2

Package Versions

cobra 0.13.0
depinfo 1.3.0
future 0.16.0
numpy 1.14.3
optlang 1.4.2
pandas 0.23.0
pip 9.0.3
ruamel.yaml 0.14.12
setuptools 39.0.1
six 1.11.0
swiglpk 1.4.4
tabulate 0.8.2

@Midnighter Midnighter added the SBML Related to reading and writing SBML models. label Jun 13, 2018
@cdiener
Copy link
Member

cdiener commented Jun 13, 2018

Hi thanks for the report.

Even though it does not say that anywhere in the docs model annotations currently have to be compliant with http://identifiers.org/. So annotations can currently not be anything different from strings. There is an ongoing discussion on how to implement evidence annotations and it is definitely on the radar.

@Midnighter
Copy link
Member

@matthiaskoenig is re-working the SBML parser/writer at the moment. I don't think a simple integer will work because the SBML specification requires annotations to be proper XML elements with namespace URI (cf. pp. 15 of the SBML spec PDF http://sbml.org/Documents/Specifications).

For reference you can also take a look at discussions in:

@paxelito
Copy link
Author

First of all thanks for replying so quickly. @Midnighter do you mean that I should add my annotations (to compounds and reactions) in the form like
<mysim:molecule xmlns:mysim="http://www.mysim.org/ns" mysim:weight="18.02" mysim:atoms="3"/>
?

@Midnighter
Copy link
Member

Short answer: Not at the moment.

As @cdiener said and as you can see in your above error trace we expect all annotations (except SBO) to resolve to identifiers.org:

"http://identifiers.org/%s/%s" % (provider, identifier)

where 'provider' and 'identifier' are key and value(s) from the 'annotation' dictionary.

However, the SBML spec says that tools should leave annotations that they don't use/can't read alone so it might be an idea to create a separate annotation attribute that contains pure XML. You could then add your own arbitrary XML there. What do you think @matthiaskoenig?

@matthiaskoenig
Copy link
Contributor

@Midnighter I thought in the same direction. Because how things are currently handled all annotations which are not RDF triplets to ontologies are lost during the round trip read - write SBML. I will finish the libsbml issues during the next few days and will have a look at this issue.

But yes, everything which is not annotations must be valid XML.

@matthiaskoenig matthiaskoenig self-assigned this Feb 27, 2019
@matthiaskoenig
Copy link
Contributor

This will be solved as part of #684.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SBML Related to reading and writing SBML models.
Projects
None yet
Development

No branches or pull requests

4 participants