opencobra / memote

memote – the genome-scale metabolic model test suite
https://memote.readthedocs.io/
Apache License 2.0
127 stars 27 forks source link

Mass balance not calculated, charge balance not calculated, annotations not detected #612

Closed matthiaskoenig closed 5 years ago

matthiaskoenig commented 5 years ago

Problem description

With the minimal example attached the model report gives very incorrect results. All species are annotated to chebi and kegg.compound; reactions are annotated to Uniprot. Everything has SBO terms. Nothing of this is detected in the report. In addition mass and charge balance should exist for all reactions but are not reported.

Please explain:

Code Sample

memote report snapshot tiny_example_8.xml

Model and results are attached results.zip

Context

Please run the following code and paste the output inside the details block.

import memote
memote.show_versions()
System Information ================== OS Linux OS-release 4.15.0-45-generic Python 3.5.2 Package Versions ================ Jinja2 2.10 click 6.7 click-configfile 0.2.3 click-log 0.3.2 cobra 0.14.2 cookiecutter 1.6.0 depinfo 1.5.0 equilibrator-api 0.1.26 future 0.17.1 gitpython 2.1.11 goodtables 1.0.0 importlib-resources 1.0.2 lxml 4.3.1 memote 0.9.3 numpydoc 0.8.0 pandas 0.23.4 pip 19.0.2 pygithub 1.43.5 pylru 1.1.0 pytest 4.2.1 python-libsbml 5.17.0 requests 2.21.0 ruamel.yaml 0.15.88 setuptools 40.8.0 six 1.12.0 sqlalchemy 1.2.17 sympy 1.3 travis-encrypt 1.1.2 travispy 0.3.5 wheel 0.33.0
Midnighter commented 5 years ago

So there are a couple of things at play.

Annotation

This is an issue with cobrapy. Both metabolite and reaction annotations turn up empty. This is a problem with the parser.

In [13]: for rxn in model.reactions:
    ...:     print(rxn.id, rxn.annotation)
    ...: 
GK {}
ATPASE {}

In [14]: for met in model.metabolites:
    ...:     print(met.id, met.annotation)
    ...: 
glc {}
g6p {}
atp {}
adp {}

Balances

If you look at charges, the glucose charge of 0 is wrongly parsed as None.

In [15]: for met in model.metabolites:
    ...:     print(met.id, met.charge)
    ...: 
glc None
g6p -2
atp -4
adp -3

The metabolite formulae are parsed correctly but the reactions are actually mass unbalanced:

In [16]: for met, coef in model.reactions.ATPASE.metabolites.items():
    ...:     print(met.id, met.elements, coef)
    ...: 
atp {'C': 10, 'H': 12, 'N': 5, 'O': 13, 'P': 3} -1.0
adp {'C': 10, 'H': 12, 'N': 5, 'O': 10, 'P': 2} 1.0

In [17]: for met, coef in model.reactions.GK.metabolites.items():
    ...:     print(met.id, met.elements, coef)
    ...: 
glc {'C': 6, 'H': 12, 'O': 6} -1.0
atp {'C': 10, 'H': 12, 'N': 5, 'O': 13, 'P': 3} -1.0
g6p {'C': 6, 'H': 11, 'O': 9, 'P': 1} 1.0
adp {'C': 10, 'H': 12, 'N': 5, 'O': 10, 'P': 2} 1.0

Again this is a problem of the parser that wrongly parses the reactions. I think the problem here is that cobrapy is not yet compatible with SBML level 3 version 2.

matthiaskoenig commented 5 years ago

So it is my own issue somehow. We have to fix the SBML parser in cobrapy. This will most likely also fix this issue. The reactions are mass balanced, the parser is just dropping metabolites from the reactions (I think constant metabolites). So SBML is mass balanced, the SBML parser in cobrapy is introducing the problems. I you look at the SBML you can see

    <listOfReactants>
          <speciesReference species="glc" stoichiometry="1" constant="true"/>
          <speciesReference species="atp" stoichiometry="1" constant="true"/>
        </listOfReactants>
        <listOfProducts>
          <speciesReference species="g6p" stoichiometry="1" constant="true"/>
          <speciesReference species="adp" stoichiometry="1" constant="true"/>
          <speciesReference species="hydron" stoichiometry="1" constant="true"/>
        </listOfProducts>

Same for other reaction, where hydron, water and hydrogenphosphate are dropped from reaction equation.

Midnighter commented 5 years ago

What tool are you using to generate the model? Directly via libsbml?

matthiaskoenig commented 5 years ago

Yes, model is directly written with libsbml.

Model is completely valid, no errors or warnings. I could imagine that the current cobrapy SBML parser is dropping constant boundarySpecies from the reaction equations.

On Thu, Feb 14, 2019 at 9:30 AM Moritz E. Beber notifications@github.com wrote:

What tool are you using to generate the model? Directly via libsbml?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/opencobra/memote/issues/612#issuecomment-463537848, or mute the thread https://github.com/notifications/unsubscribe-auth/AA29ugs3WtYPqKtVdaHRsyyIoaHBnrfyks5vNR6LgaJpZM4a550h .

-- Matthias König, PhD. Junior Group Leader LiSyM - Systems Medicine of the Liver Humboldt Universität zu Berlin, Institute of Biology, Institute for Theoretical Biology https://livermetabolism.com konigmatt@googlemail.com https://twitter.com/konigmatt https://github.com/matthiaskoenig Tel: +49 30 2093 98435

Midnighter commented 5 years ago

Actually, that has always been the case yes. I didn't pay attention to that.

Midnighter commented 5 years ago

I'll close this issue in favor of the one on cobrapy. Let's find a solution for this soon :wink:

matthiaskoenig commented 5 years ago

Just for anybody running in the same issues. This is solved in https://github.com/opencobra/cobrapy/pull/685 Just use the libsbml branch of cobrapy with memote to make things work https://github.com/opencobra/cobrapy/tree/libsbml