validate and create SBML file from XML model

634 views
Skip to first unread message

mat Lamb

unread,
Mar 27, 2019, 3:51:00 AM3/27/19
to cobra pie
Hi everybody,

I'm knew at the Constraint Genome scale metabolic and I'm using the Cobrapy distribution to use a model of Chlorella Vulgaris UTEX395 the iCZ843 in open source. But when I'm trying to validate the xml model in Heterotrophy and create an SBML file from it, I have some errors. here his my code and the errors that occur :

import cobra
import os
from os.path import join
#%% Read the model
Auto_Model = cobra.io.read_sbml_model(join("iCZ843_hetero.xml"))
# %% Verify that the SBML model contains no errors by validating it : Need to convert it first since xml_validation is not available yet
from cobra.io.sbml import write_cobra_model_to_sbml_file
cobra.io.write_sbml_model(Auto_Model,"Auto_Model.sbml")

Errors :
Academic license - for non-commercial use only
cobra/core/reaction.py:443 UserWarning: malformed gene_reaction_rule '[]' for <Reaction VIOXANth at 0x7f8076738810>
failed on '[]' in <Reaction VIOXANth at 0x7f8076738810>
Traceback (most recent call last):
  File "iCZ843_h.py", line 13, in <module>
    cobra.io.write_sbml_model(Auto_Model,"Auto_Model.sbml")
  File "/home/mathieu/.local/lib/python2.7/site-packages/cobra/io/sbml3.py", line 721, in write_sbml_model
    xml = model_to_xml(cobra_model, **kwargs)
  File "/home/mathieu/.local/lib/python2.7/site-packages/cobra/io/sbml3.py", line 564, in model_to_xml
    raise e
TypeError: unsupported operation  <_ast.List object at 0x7f8077c08c90>

Thanks in advance guys :-)

Moritz Beber

unread,
Mar 28, 2019, 4:46:52 AM3/28/19
to cobra pie
Hi Mat,

I'm not completely sure what you are trying to achieve. You already seem to have an SBML file. If you want to validate it, you have two options: Either use the online validator http://sbml.org/validator/ or from cobra.io import validate_sbml_model. (You will need the latest cobra for that. pip install -U cobra). The error that you get happens upon writing the model back to SBML. Please try that again with the latest version, maybe that already solves your problem.

I hope that helps,
Moritz
--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-pie+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mat Lamb

unread,
Mar 28, 2019, 6:28:01 AM3/28/19
to cobra pie
Hi Moritz,
What I wnated to know is : the xml extension of the model can e considered as an SBML extension too ? if not What is the exact difference ?
I tried the SBML validator and I also upgraded my version of cobra with the following command line : pip install -U cobra.
The validator said "This document is valid SBML. However, one or more warnings have been issued."
And now I have another errors that I did not had when using the cobra.io.read_sbml_model python line Hereafter you have the code and the errors.
CODE:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import cobra
import os
import sklearn
from os.path import join
import gurobipy
Hetero_Model = cobra.io.read_sbml_model(join("Heterotrophy_Model.xml"))

MESSAGE ERROR:
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    Hetero_Model = cobra.io.read_sbml_model(join("Heterotrophy_Model.xml"))
  File "/home/mathieu/anaconda2/lib/python2.7/site-packages/cobra/io/sbml.py", line 204, in read_sbml_model
    raise e
IOError: [Errno The file with 'filename' does not exist, or is not an SBML string. Provide the path to an existing SBML file or a valid SBML string representation:
%s] Heterotrophy_Model.xml

Thanks a lot I know that I maybe mix up the different concept and sorry for the stupide question :p
To unsubscribe from this group and stop receiving emails from it, send an email to cobr...@googlegroups.com.

Moritz Beber

unread,
Mar 28, 2019, 6:54:47 PM3/28/19
to cobra pie
Dear Mat,

Apologies if the following sounds terse but I'm just trying to provide some clarity. XML is the extensible markup language. XML provides formal rules for encoding different documents. SBML is the systems biology markup language. It is one of the many XML extensions and it is a specification for encoding biological models. So you may interchangeably see both files with format .xml or .sbml since SBML uses the XML formalism.

The error simply points to the file not being where you think it is located. Maybe you executed your script from a different directory and thus the relative path to the model is no longer correct?

Best,
Moritz

mat Lamb

unread,
Apr 3, 2019, 6:05:34 AM4/3/19
to cobra pie
Dear Moritz,
I understand what you're saying however when I run this few lines of code below in the right directory just to read the XML model I have plenty of warinings that I did not have before.
CODE :
##I just import the module that I will use on the model
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import cobra
import os
import sklearn
import gurobipy
from os.path import join
from sklearn.metrics import r2_score
from cobra.flux_analysis import flux_variability_analysis
import logging
logging.basicConfig()
##Reading the model
model = cobra.io.read_sbml_model(join("iCZ843_Model_Heterotrophy.xml"))

Errors log  (I just give you the ten first warnings to give you an idea) :

WARNING:cobra.io.sbml:Model does not contain SBML fbc package information.

Academic license - for non-commercial use only
WARNING:cobra.io.sbml:SBML package 'layout' not supported by cobrapy,information is not parsed
WARNING:cobra.io.sbml:SBML package 'render' not supported by cobrapy,information is not parsed
WARNING:cobra.io.sbml:Use of FORMULA in the notes element is discouraged, use fbc:chemicalFormula instead: <Species M_10fthf_c "10-Formyltetrahydrofolate">
WARNING:cobra.io.sbml:Use of FORMULA in the notes element is discouraged, use fbc:chemicalFormula instead: <Species M_10fthf_h "10-Formyltetrahydrofolate">
WARNING:cobra.io.sbml:Use of FORMULA in the notes element is discouraged, use fbc:chemicalFormula instead: <Species M_10fthf_m "10-Formyltetrahydrofolate">
WARNING:cobra.io.sbml:Use of FORMULA in the notes element is discouraged, use fbc:chemicalFormula instead: <Species M_10fthf_x "10-Formyltetrahydrofolate">
WARNING:cobra.io.sbml:Use of FORMULA in the notes element is discouraged, use fbc:chemicalFormula instead: <Species M_10fthfglu_L_c "10 Formyltetrahydrofolyl L-glutamate">

And I did have this problem before. I even reinstalled my OS to start over but I have the same error. 
Thanks again for your time,
Regards.

Greg Medlock

unread,
Apr 3, 2019, 10:45:41 AM4/3/19
to mat Lamb, cobra pie
Hi Mat,

The warnings you're now getting just indicate that "best practices" weren't used when the author of the model encoded it in SBML--if you only got warnings, and no errors, the model should load into cobrapy just fine. Are there any errors further down in the latest log?

For the specific warnings raised in your text, it's just saying that the notes field was used to encode formula information--this is discouraged because there is a specific field dedicated for chemical formulas. Using this field makes the information fully machine-readable, thus is the preferred approach. However, as I said above, these warnings won't prevent the model from being loaded by cobrapy.

Greg

--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-pie+...@googlegroups.com.

Moritz Beber

unread,
Apr 3, 2019, 2:01:31 PM4/3/19
to cobra pie
This conversation has also been continued in this issue today https://github.com/opencobra/schema/issues/13

Matthias König

unread,
Apr 14, 2019, 9:46:04 AM4/14/19
to cobra pie
Just providing some additional information on the issue of new warnings with the SBML parser:
- as long as there are only warnings and no errors a cobra model object is returned and your SBML model loaded fine
- the warnings are there to clearly indicate such SBML files are discouraged and there is a much better solution to encode such information (better like in interoperable, reproducible, reusable, less-error prone)
- if you get errors then really something is wrong with your model and it cannot be loaded in a valid LP problem (this will raise a real error and no model object is returned)
- I know the warnings are annoying, but to be honest this is exactly what the should be (so models are updated to best practises)

You can just save the model as SBML then you will be rid of the warnings, because the SBML export uses the best practises
So by using `read_sbml_model` and then `write_sbml_model` you have a converter to get your model to SBML3FBC, i.e. SBML level 3 using fbc to encode your model.
At the current state of SBML support some model information could be lost which is stored in notes! or annotations. You should check if your model contains such information (and please open an issue for the information so we can support it in the future). If you have simple fbc models without custom annotations (which are 99% if all models) you should be save to just upconvert your model using `read_sbml_model` + `write_sbml_model` to get rid of the warnings.

If you have any questions please let us know.
Best Matthias
Reply all
Reply to author
Forward
0 new messages