---------------------------------------------------------------------------
CobraSBMLError Traceback (most recent call last)
File ~/.local/lib/python3.8/site-packages/cobra/io/sbml.py:249, in read_sbml_model(filename, number, f_replace, **kwargs)
248 doc = _get_doc_from_filename(filename)
--> 249 return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
250 except IOError as e:
File ~/.local/lib/python3.8/site-packages/cobra/io/sbml.py:522, in _sbml_to_model(doc, number, f_replace, set_missing_bounds, **kwargs)
519 for (
520 gp
521 ) in model_fbc.getListOfGeneProducts(): # noqa: E501 type: libsbml.GeneProduct
--> 522 gid = _check_required(gp, gp.getIdAttribute(), "id")
523 if f_replace and F_GENE in f_replace:
File ~/.local/lib/python3.8/site-packages/cobra/io/sbml.py:1352, in _check_required(sbase, value, attribute)
1351 msg += " with metaId '%s'" % sbase.getName()
-> 1352 raise CobraSBMLError(msg)
1353 if attribute == "id":
CobraSBMLError: Required attribute 'id' cannot be found or parsed in '<GeneProduct>'.
The above exception was the direct cause of the following exception:
CobraSBMLError Traceback (most recent call last)
Input In [8], in <cell line: 1>()
----> 1 model = cobra.io.read_sbml_model(xmlFile)
File ~/.local/lib/python3.8/site-packages/cobra/io/sbml.py:263, in read_sbml_model(filename, number, f_replace, **kwargs)
253 except Exception as original_error:
254 cobra_error = CobraSBMLError(
255 "Something went wrong reading the SBML model. Most likely the SBML"
256 " model is not valid. Please check that your model is valid using "
(...)
261 "at https://github.com/opencobra/cobrapy/issues ."
262 )
--> 263 raise cobra_error from original_error
CobraSBMLError: Something went wrong reading the SBML model. Most likely the SBML model is not valid. Please check that your model is valid using the `cobra.io.sbml.validate_sbml_model` function or via the online validator at http://sbml.org/validator .
`(model, errors) = validate_sbml_model(filename)`
If the model is valid and cannot be read please open an issue at https://github.com/opencobra/cobrapy/issues .
(None,
{'SBML_FATAL': [],
'SBML_ERROR': ["E1 (Error): SBML component consistency (fbc, L299114); Allowed fbc attributes on <GeneProduct>; A <GeneProduct> object must have the required attributes 'fbc:id' and 'fbc:label' may have the optional attributes 'fbc:name' and 'fbc:associatedSpecies'. No other attributes from the SBML Level 3 Flux Balance Constraints namespace are permitted on a <GeneProduct> object. \nReference: L3V1 Fbc V3 Section 3.5\n Fbc attribute 'id' is missing from 'geneProduct' object.\n",
"E3 (Error): SBML component consistency (fbc, L299114); Allowed fbc attributes on <GeneProduct>; A <GeneProduct> object must have the required attributes 'fbc:id' and 'fbc:label' may have the optional attributes 'fbc:name' and 'fbc:associatedSpecies'. No other attributes from the SBML Level 3 Flux Balance Constraints namespace are permitted on a <GeneProduct> object. \nReference: L3V1 Fbc V3 Section 3.5\n Fbc attribute 'id' is missing from 'geneProduct' object.\n"],
'SBML_SCHEMA_ERROR': [],
'SBML_WARNING': ['E0 (Warning): General SBML conformance (core, L3); RDF does not contain valid ModelHistory; LibSBML expected to read the annotation into a ModelHistory object. Unfortunately, some attributes were not present or correct and the resulting ModelHistory object will not correctly produce the annotation. This functionality will be improved in later versions of libSBML. \nReference: L3V1 Section 6.3\n An invalid ModelHistory element has been stored.\n',
'E2 (Warning): General SBML conformance (core, L3); RDF does not contain valid ModelHistory; LibSBML expected to read the annotation into a ModelHistory object. Unfortunately, some attributes were not present or correct and the resulting ModelHistory object will not correctly produce the annotation. This functionality will be improved in later versions of libSBML. \nReference: L3V1 Section 6.3\n An invalid ModelHistory element has been stored.\n'],
'COBRA_FATAL': [],
'COBRA_ERROR': ["Required attribute 'id' cannot be found or parsed in '<GeneProduct>'."],
'COBRA_WARNING': [],
'COBRA_CHECK': []})
I would expect to be able to parse the Fruitfly-GEM.xml which will have identifiers synchronized with metabolites.tsv
and yml
files.
# https://cobrapy.readthedocs.io/en/latest/io.html#SBML
import cobra
import os
import requests
# Human-GEM e.g.,
model_name = 'Fruitfly-GEM'
outputfdr = f"../../output/ATLAS_collection/{model_name}"
try:
os.makedirs(outputfdr)
except:
None
BRANCH = 'main'
XML = os.path.join(outputfdr,f'{model_name}.xml')
with open(XML, 'w') as f:
r = requests.get(f'https://github.com/SysBioChalmers/{model_name}/blob/' + BRANCH + f'/model/{model_name}.xml?raw=true')
f.write(r.text)
with open(XML, 'r') as f:
xmlFile = f.read()
model = cobra.io.read_sbml_model(xmlFile)