mass.io.sbml
SBML import and export using the python-libsbml
package.
The SBML importer supports all versions of SBML that are compatible with the
roadrunner
package.The
sbml
module supports the latest version of python-libsbml that is compatible with theroadrunner
package.The SBML importer supports the ‘fbc’ and ‘groups’ package extension.
The SBML exporter writes SBML Level 3 models.
Annotation information is stored on the
mass
objects.Information from the ‘groups’ package is read.
All equations are written via MathML.
Parsing of models using the fbc extension was implemented as efficiently as possible, whereas (discouraged) fallback solutions are not optimized for efficiency. Futhermore, because the SBML kinetic law is used for the reaction kinetic laws, fbc information will NOT be written into or read from the SBML kinetic laws. Whether the fbc package extension is disabled or enabled will not change this behavior with kinetic laws.
Notes are only supported in a minimal way relevant for kinetic models, i.e. structured information from notes in the form:
"<p>key: value</p>"
Notes are read into the notes
attribute of mass
objects when
reading SBML files. On writing, the notes
attribute of mass
objects dictionary is serialized to the SBML notes information.
Attribute information for EnzymeModuleForm
s and
EnzymeModuleReaction
s are written into the SBML object notes
field. Upon import of the SBML, the information is read into the
enzyme specific attribute as long as the "key"
in the notes matches the
attribute name precisely.
The information specific to attributes of the EnzymeModule
and
EnzymeModuleDict
information is stored using the
groups extension
by creating an SBML ‘group’ representing the enzyme module containing
additional SBML group objects for enzyme module ligands, forms, and reactions
for the categories of the enzyme module categorized dictionary attributes.
The remaining information is written to the the notes field of the main SBML
group for the enzyme module. Disabling use of the ‘groups’ package extension
will result in the loss of the enzyme specific information, but it will not
prevent EnzymeModuleForm
s and EnzymeModuleReaction
s
from being written to the SBML model as species and reactions, respectively.
Annotations are read and written via annotation
attribute for
mass
objects.
Some SBML related issues are still open, please refer to the respective issue:
update annotation format and support qualifiers (depends on decision for new annotation format; https://github.com/opencobra/cobrapy/issues/684)
write compartment annotations and notes (depends on updated first-class compartments; see https://github.com/opencobra/cobrapy/issues/760)
support compression on file handles (depends on solution for https://github.com/opencobra/cobrapy/issues/812)
Module Contents
Functions
|
Read SBML model from the given filename into a |
|
Write |
|
Validate the SBML model and returns the model along with the errors. |
|
Validate export of a |
Attributes
Logger for the |
|
Current level and version supported for SBML export. |
|
Current version of the SBML 'fbc' package extension. |
|
Current version of the SBML 'groups' package extension. |
|
Regex for ASCII character removal. |
|
Regex for |
|
Regex for SBML moiety replacements. |
|
Regex for recognizing and rate constants. |
|
SBO term for the modeling framework |
|
Unit definition for |
|
String to use as a prefix for identifiers starting with a number. |
|
Key in |
|
Key in |
|
Key in |
|
Key in |
|
Key in |
|
Key in |
|
Contains functions for ID clipping/adding of prefixes. |
|
Contains ASCII characters and the value for their replacement. |
- mass.io.sbml.SBML_LEVEL_VERSION = [3, 1][source]
Current level and version supported for SBML export.
- Type
- mass.io.sbml.GROUPS_VERSION = 1[source]
Current version of the SBML ‘groups’ package extension.
- Type
- mass.io.sbml.NUMBER_ID_PREFIX = _[source]
String to use as a prefix for identifiers starting with a number.
- Type
- mass.io.sbml.F_GENE_REV = F_GENE_REV[source]
Key in
F_REPLACE
for the gene prefix adding function.- Type
- mass.io.sbml.F_SPECIE = F_SPECIE[source]
Key in
F_REPLACE
for the specie prefix clipping function.- Type
- mass.io.sbml.F_SPECIE_REV = F_SPECIE_REV[source]
Key in
F_REPLACE
for the specie prefix adding function.- Type
- mass.io.sbml.F_REACTION = F_REACTION[source]
Key in
F_REPLACE
for the reaction prefix clipping function.- Type
- mass.io.sbml.F_REACTION_REV = F_REACTION_REV[source]
Key in
F_REPLACE
for the reaction prefix adding function.- Type
- mass.io.sbml.ASCII_REPLACE[source]
Contains ASCII characters and the value for their replacement.
- Type
- mass.io.sbml.read_sbml_model(filename, f_replace=None, **kwargs)[source]
Read SBML model from the given filename into a
mass
model.If the given filename ends with the suffix
'.gz'
(for example,'myfile.xml.gz'
), the file is assumed to be compressed in gzip format and will be automatically decompressed upon reading. Similarly, if the given filename ends with'.zip'
or'.bz2'
, the file is assumed to be compressed in zip or bzip2 format (respectively).Files whose names lack these suffixes will be read uncompressed. Note that if the file is in zip format but the archive contains more than one file, only the first file in the archive will be read and the rest are ignored.
To read a gzip/zip file,
libSBML
needs to be configured and linked with thezlib
library at compile time. It also needs to be linked with thebz2
library to read files in bzip2 format. (Both of these are the default configurations forlibSBML
.)This function supports SBML with FBC-v1 and FBC-v2. FBC-v1 models are converted to FBC-v2 models before reading.
The parser tries to fall back to information in notes dictionaries if information is not available in the FBC packages, e.g., CHARGE, FORMULA on species, or GENE_ASSOCIATION, SUBSYSTEM on reactions.
Notes
Provided file handles cannot be opened in binary mode, i.e., use:
with open(path, "r" as f): read_sbml_model(f)
File handles to compressed files are not supported yet.
- Parameters
filename (path to SBML file, SBML string, or SBML file handle) – SBML which is read into a
mass
model.f_replace (dict) –
Dictionary of replacement functions for gene, specie, and reaction. By default the following id changes are performed on import: clip
'G_'
from genes, clip'M_'
from species, clip'R_'
from reactions.If no replacements should be performed, set
f_replace={}
.**kwargs –
- number :
In which data type should the stoichiometry be parsed. Can be
float
orint
.Default is
float
.- set_missing_bounds :
bool
indicating whether to set missing bounds to the default bounds from theMassConfiguration
.Default is
True
.- remove_char :
bool
indicating whether to remove ASCII characters from IDs.Default is
True
.- stop_on_conversion_failbool
bool
indicating whether to stop trying to load the model if a conversion process fails. IfFalse
, then the loading of the model will be attempted anyways, despite a potential loss of information.Default is
True
.
- Returns
The generated
mass
model.- Return type
- Raises
MassSBMLError – Errors due to :mass model specific requirements.
- mass.io.sbml.write_sbml_model(mass_model, filename, f_replace=None, **kwargs)[source]
Write
mass
model tofilename
in SBML format.The created model is SBML level 3 version 1 core (L3V1) using packages ‘fbc-v2’ and ‘groups-v1’ for optimal exporting. Not including these packages may result in some information loss when exporting the model.
If the given filename ends with the suffix
'.gz'
(for example,'myfile.xml.gz'
),libSBML
assumes the caller wants the file to be written compressed in gzip format. Similarly, if the given filename ends with'.zip'
or'.bz2'
,libSBML
assumes the caller wants the file to be compressed in zip or bzip2 format (respectively). Files whose names lack these suffixes will be written uncompressed.Special considerations for the zip format: If the given filename ends with
'.zip'
, the file placed in the zip archive will have the suffix".xml"
or".sbml"
. For example, the file in the zip archive will be named"test.xml"
if the given filename is"test.xml.zip"
or"test.zip"
. Similarly, the filename in the archive will be"test.sbml"
if the given filename is"test.sbml.zip"
.- Parameters
mass_model (MassModel or EnzymeModule) – The
mass
model to write to into an SBML compliant modle file.filename (str) – Path to which the model should be written
f_replace (dict) –
Dictionary of replacement functions for gene, specie, and reaction. By default the following id changes are performed on import: add
'G_'
to genes, add'M_'
to species, add'R_'
to reactions.If no replacements should be performed,set
f_replace={}
.**kwargs –
- use_fbc_package :
bool
indicating whether SBML ‘fbc’ package extension should be used.Default is
True
.- use_groups_package :
bool
indicating whether SBML ‘groups’ package extension should be used.Default is
True
.- units :
bool
indicating whether units should be written into the SBMLDocument.Default is
True
.- local_parameters :
bool
indicating whether reaction kinetic parameters should be written as local parameters of the kinetic law (default), or as global model parameters in the SBML model file.Default is
True
to write parameters as local parameters.- write_objective :
bool
indicating whether the model objective(s) should also be written into the SBML model file.Default is
False
.
- Raises
MassSBMLError – Errors due to :mass model specific requirements.
Warning
Setting the
use_fbc_package=False
may result in some information loss when writing the model.Setting the
use_groups_package=False
may result in some information loss when writing the model. Information lost will include some attributes associated with enzyme modules and will likely result in an exportedEnzymeModule
becoming aMassModel
upon reloading the model.
- mass.io.sbml.validate_sbml_model(filename, check_model=True, internal_consistency=True, check_units_consistency=False, check_modeling_practice=False, **kwargs)[source]
Validate the SBML model and returns the model along with the errors.
kwargs
are passed toread_sbml_model()
.- Parameters
filename (str) – The filename (or SBML string) of the SBML model to be validated.
check_model (bool) – Check some basic model properties. Default is
True
.internal_consistency (bool) – Check internal consistency. Default is
True
.check_units_consistency (bool) – Check consistency of units. Default is
False
.check_modeling_practice (bool) – Check modeling practice. Default is
False
.**kwargs –
- number :
In which data type should the stoichiometry be parsed. Can be
float
orint
.Default is
float
.- set_missing_bounds :
bool
indicating whether to set missing bounds to the default bounds from theMassConfiguration
.Default is
True
.- remove_char :
bool
indicating whether to remove ASCII characters from IDs.Default is
True
.- stop_on_conversion_failbool
bool
indicating whether to stop trying to load the model if a conversion process fails. IfFalse
, then the loading of the model will be attempted anyways, despite a potential loss of information.Default is
True
.
- Returns
tuple (model, errors)
model (
MassModel
orEnzymeModule
, orNone
) – Themass
model if the file could be read successfully. If the file was not successfully read,None
will be returned.errors (dict) – Warnings and errors grouped by their respective types.
- mass.io.sbml.validate_sbml_model_export(mass_model, filename, f_replace=None, **kwargs)[source]
Validate export of a
mass
model to SBML, returning any errors.If no SBML errors or MASS fatal errors occur, the model will be written to the
'filename'
.kwargs
are passed to eitherwrite_sbml_model()
orvalidate_sbml_model()
.- Parameters
mass_model (MassModel or EnzymeModule) – The
mass
model to write to into an SBML compliant modle file.filename (str) – Path to which the model should be written
f_replace (dict) –
Dictionary of replacement functions for gene, specie, and reaction. By default the following id changes are performed on import: add
'G_'
to genes, add'M_'
to species, add'R_'
to reactions.If no replacements should be performed,set
f_replace={}
.**kwargs –
- use_fbc_package :
bool
indicating whether SBML ‘fbc’ package extension should be used.Default is
True
.- use_groups_package :
bool
indicating whether SBML ‘groups’ package extension should be used.Default is
True
.- units :
bool
indicating whether units should be written into the SBMLDocument.Default is
True
.- local_parameters :
bool
indicating whether reaction kinetic parameters should be written as local parameters of the kinetic law (default), or as global model parameters in the SBML model file.Default is
True
to write parameters as local parameters.- write_objective :
bool
indicating whether the model objective(s) should also be written into the SBML model file.Default is
False
.- check_modelbool
bool
indicating whether to check some basic model properties.Default is
True
.- internal_consistencybool
bool
indicating whether to check internal consistency.Default is
True
.- check_units_consistencybool
bool
indicating whether to check consistency of units.Default is
False
.- check_modeling_practicebool
bool
indicating whether to check modeling practice.Default is
False
.- number :
In which data type should the stoichiometry be parsed. Can be
float
orint
.Default is
float
.- set_missing_bounds :
bool
indicating whether to set missing bounds to the default bounds from theMassConfiguration
.Default is
True
.- remove_char :
bool
indicating whether to remove ASCII characters from IDs.Default is
True
.- stop_on_conversion_failbool
bool
indicating whether to stop trying to load the model if a conversion process fails. IfFalse
, then the loading of the model will be attempted anyways, despite a potential loss of information.Default is
True
.
- Returns
tuple (success, errors)
success (bool) –
bool
indicating whether the model was successfully exported to'filename'
.errors (dict) – Warnings and errors grouped by their respective types.