[Debian-med-packaging] Bug#1009111: python-cobra: (autopkgtest) needs update for python3.10: module 'collections' has no attribute 'Iterable'
Paul Gevers
elbrus at debian.org
Thu Apr 7 12:03:05 BST 2022
Source: python-cobra
Version: 0.23.0-1
Severity: serious
Tags: sid bookworm
User: debian-ci at lists.debian.org
Usertags: needs-update
User: debian-python at lists.debian.org
Usertags: python3.10
Control: affects -1 src:python3-defaults
Dear maintainer(s),
We are in the transition of making python3.10 the default Python
versions [0]. With a recent upload of python3-defaults the autopkgtest
of python-cobra fails in testing when that autopkgtest is run with the
binary packages of python3-defaults from unstable. It passes when run
with only packages from testing. In tabular form:
pass fail
python3-defaults from testing 3.10.4-1
python-cobra from testing 0.23.0-1
all others from testing from testing
I copied some of the output at the bottom of this report.
Currently this regression is blocking the migration of python3-defaults
to testing [1]. https://docs.python.org/3/whatsnew/3.10.html lists
what's new in Python3.10, it may help to identify what needs to be
updated. https://docs.python.org/3.9/library/collections.html says:
"""
Deprecated since version 3.3, will be removed in version 3.10: Moved
Collections Abstract Base Classes to the collections.abc module. For
backwards compatibility, they continue to be visible in this module
through Python 3.9.
"""
Time to move on.
More information about this bug and the reason for filing it can be found on
https://wiki.debian.org/ContinuousIntegration/RegressionEmailInformation
Paul
[0] https://bugs.debian.org/1006836
[1] https://qa.debian.org/excuses.php?package=python3-defaults
https://ci.debian.net/data/autopkgtest/testing/amd64/p/python-cobra/20649526/log.gz
==================================== ERRORS
====================================
____________________ ERROR at setup of test_sbo_annotation
_____________________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
_________ ERROR at setup of test_prune_unused_metabolites_output_type
__________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
____________ ERROR at setup of test_prune_unused_metabolites_sanity
____________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
__________ ERROR at setup of test_prune_unused_reactions_output_type
___________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
____________ ERROR at setup of test_prune_unused_rxns_functionality
____________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
_____________________ ERROR at setup of test_gene_knockout
_____________________
medium_model = <Model Salmonella_consensus_build_1 at 0x7f121e1676d0>
@pytest.fixture(scope="function")
def salmonella(medium_model):
> return medium_model.copy()
/usr/lib/python3/dist-packages/cobra/test/conftest.py:72: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/core/model.py:324: in copy
new = self.__class__()
/usr/lib/python3/dist-packages/cobra/core/model.py:115: in __init__
self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: in _populate_solver
self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: in add_cons_vars
add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: in
add_cons_vars_to_problem
model.solver.add(what, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e167790>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
______________________ ERROR at setup of test_escape_ids
_______________________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
_____________________ ERROR at setup of test_rename_genes
______________________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
_________________ ERROR at setup of test_validate_mass_balance
_________________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
_____________ ERROR at setup of test_validate_formula_compartment
______________
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
> return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:249: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
set_missing_bounds = False, kwargs = {}
model = <libsbml.Model; proxy of <Swig Object of type 'Model_t *' at
0x7f121e2cd890> >
model_fbc = <libsbml.FbcModelPlugin; proxy of <Swig Object of type
'FbcModelPlugin *' at 0x7f121e2cda70> >
doc_fbc = <libsbml.FbcSBMLDocumentPlugin; proxy of <Swig Object of type
'FbcSBMLDocumentPlugin *' at 0x7f121e2cda40> >
fbc_version = 2, model_id = 'e_coli_core'
def _sbml_to_model(
doc, number=float, f_replace=F_REPLACE,
set_missing_bounds=False, **kwargs
):
"""Creates cobra model from SBMLDocument.
Parameters
----------
doc: libsbml.SBMLDocument
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
set_missing_bounds : flag to set missing bounds
Returns
-------
cobra.core.Model
"""
if f_replace is None:
f_replace = {}
# SBML model
model = doc.getModel() # type: libsbml.Model
if model is None:
raise CobraSBMLError("No SBML model detected in file.")
model_fbc = model.getPlugin("fbc") # type: libsbml.FbcModelPlugin
if not model_fbc:
LOGGER.warning("Model does not contain SBML fbc package
information.")
else:
if not model_fbc.isSetStrict():
LOGGER.warning('Loading SBML model without
fbc:strict="true"')
# fbc-v1 (legacy)
doc_fbc = doc.getPlugin("fbc") # type:
libsbml.FbcSBMLDocumentPlugin
fbc_version = doc_fbc.getPackageVersion()
if fbc_version == 1:
LOGGER.warning(
"Loading SBML with fbc-v1 (models should be
encoded" " using fbc-v2)"
)
conversion_properties = libsbml.ConversionProperties()
conversion_properties.addOption(
"convert fbc v1 to fbc v2", True, "Convert FBC-v1
model to FBC-v2"
)
result = doc.convert(conversion_properties)
if result != libsbml.LIBSBML_OPERATION_SUCCESS:
raise Exception("Conversion of SBML fbc v1 to fbc
v2 failed")
# Model
model_id = model.getIdAttribute()
if not libsbml.SyntaxChecker.isValidSBMLSId(model_id):
LOGGER.error("'%s' is not a valid SBML 'SId'." % model_id)
> cobra_model = Model(model_id)
/usr/lib/python3/dist-packages/cobra/io/sbml.py:371: _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, id_or_model = 'e_coli_core'
name = None
def __init__(self, id_or_model=None, name=None):
if isinstance(id_or_model, Model):
Object.__init__(self, name=name)
self.__setstate__(id_or_model.__dict__)
if not hasattr(self, "name"):
self.name = None
self._solver = id_or_model.solver
else:
Object.__init__(self, id_or_model, name=name)
self._trimmed = False
self._trimmed_genes = []
self._trimmed_reactions = {}
self.genes = DictList()
self.reactions = DictList() # A list of cobra.Reactions
self.metabolites = DictList() # A list of cobra.Metabolites
self.groups = DictList() # A list of cobra.Groups
# genes based on their ids {Gene.id: Gene}
self._compartments = {}
self._contexts = []
# from cameo ...
# if not hasattr(self, '_solver'): # backwards
compatibility
# with older cobrapy pickles?
interface = check_solver(configuration.solver)
self._solver = interface.Model()
self._solver.objective = interface.Objective(Zero)
> self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:115: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, reaction_list = []
metabolite_list = []
def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in metabolite_list:
to_add += [self.problem.Constraint(Zero, name=met.id,
lb=0, ub=0)]
> self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars(self, what, **kwargs):
"""Add constraints and variables to the model's mathematical
problem.
Useful for variables and constraints that can not be
expressed with
reactions and simple lower and upper bounds.
Additions are reversed upon exit if the model itself is used as
context.
Parameters
----------
what : list or tuple of optlang variables or constraints.
The variables or constraints to add to the model. Must be of
class `optlang.interface.Variable` or
`optlang.interface.Constraint`.
**kwargs : keyword arguments
Passed to solver.add()
"""
> add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
model = <Model e_coli_core at 0x7f121e2cd540>, what = [], kwargs = {}
def add_cons_vars_to_problem(
model: "Model",
what: Union[List[CONS_VARS], Tuple[CONS_VARS], Components],
**kwargs,
) -> None:
"""Add variables and constraints to a model's solver object.
Useful for variables and constraints that can not be
expressed with
reactions and lower/upper bounds. It will integrate with the
model's
context manager in order to revert changes upon leaving the
context.
Parameters
----------
model : cobra.Model
The model to which to add the variables and constraints.
what : list or tuple of optlang.interface.Variable or
optlang.interface.Constraint
The variables and constraints to add to the model.
**kwargs : keyword arguments
Keyword arguments passed to solver's add() method.
"""
> model.solver.add(what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e2cd600>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
The above exception was the direct cause of the following exception:
@pytest.fixture(scope="session")
def small_model():
> return create_test_model("textbook")
/usr/lib/python3/dist-packages/cobra/test/conftest.py:47: _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/cobra/test/__init__.py:37: in
create_test_model
return read_sbml_model(textbook_sbml)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
filename = '/usr/lib/python3/dist-packages/cobra/test/data/textbook.xml.gz'
number = <class 'float'>
f_replace = {'F_GENE': <function _f_gene at 0x7f121f630550>,
'F_GENE_REV': <function _f_gene_rev at 0x7f121f6305e0>, 'F_GROUP':
<function _f_group at 0x7f121f6308b0>, 'F_GROUP_REV': <function
_f_group_rev at 0x7f121f630940>, ...}
kwargs = {}
doc = <libsbml.SBMLDocument; proxy of <Swig Object of type 'SBMLDocument
*' at 0x7f121e2ce610> >
cobra_error = CobraSBMLError('Something went wrong reading the SBML
model. Most likely the SBML model is not valid. Please check
tha...ame)`\nIf the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .')
def read_sbml_model(filename, number=float, f_replace=F_REPLACE,
**kwargs):
"""Reads SBML model from given filename.
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
ignored.
To read a gzip/zip file, libSBML needs to be configured and
linked
with the zlib library at compile time. It also needs to be linked
with the bzip2 library to read files in bzip2 format. (Both of
these
are the default configurations for libSBML.)
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.
Parameters
----------
filename : path to SBML file, or SBML string, or SBML file handle
SBML which is read into cobra model
number: data type of stoichiometry: {float, int}
In which data type should the stoichiometry be parsed.
f_replace : dict of replacement functions for id replacement
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={}, None
Returns
-------
cobra.core.Model
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.
"""
try:
doc = _get_doc_from_filename(filename)
return _sbml_to_model(doc, number=number,
f_replace=f_replace, **kwargs)
except IOError as e:
raise e
except Exception as original_error:
cobra_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 .\n"
"\t`(model, errors) = validate_sbml_model(filename)`"
"\nIf the model is valid and cannot be read please open
an issue "
"at https://github.com/opencobra/cobrapy/issues ."
)
> raise cobra_error from original_error
E cobra.io.sbml.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 .
E `(model, errors) = validate_sbml_model(filename)`
E If the model is valid and cannot be read please open an
issue at https://github.com/opencobra/cobrapy/issues .
/usr/lib/python3/dist-packages/cobra/io/sbml.py:263: CobraSBMLError
=================================== FAILURES
===================================
______________________________ test_remove_genes
_______________________________
def test_remove_genes() -> None:
"""Test gene removal."""
> m = Model("test")
/usr/lib/python3/dist-packages/cobra/test/test_manipulation/test_delete.py:161:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ /usr/lib/python3/dist-packages/cobra/core/model.py:115: in __init__
self._populate_solver(self.reactions, self.metabolites)
/usr/lib/python3/dist-packages/cobra/core/model.py:1003: in _populate_solver
self.add_cons_vars(to_add)
/usr/lib/python3/dist-packages/cobra/core/model.py:895: in add_cons_vars
add_cons_vars_to_problem(self, what, **kwargs)
/usr/lib/python3/dist-packages/cobra/util/solver.py:384: in
add_cons_vars_to_problem
model.solver.add(what, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _
self = <optlang.glpk_interface.Model object at 0x7f121e313940>, stuff = []
sloppy = False
def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or
a single variable or constraint.
sloppy : bool
Check constraints for variables that are not part of the
model yet.
Returns
-------
None
"""
if self._pending_modifications.toggle == 'remove':
self.update()
self._pending_modifications.toggle = 'add'
> if isinstance(stuff, collections.Iterable):
E AttributeError: module 'collections' has no attribute 'Iterable'
/usr/lib/python3/dist-packages/optlang/interface.py:1358: AttributeError
========================= 1 failed, 10 errors in 3.03s
=========================
make: ***
[/tmp/autopkgtest-lxc._v0wc4wp/downtmp/build.NT2/src/debian/tests/Makefile:9:
py3-test] Error 1
autopkgtest [09:17:37]: test command1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <http://alioth-lists.debian.net/pipermail/debian-med-packaging/attachments/20220407/8d0ea747/attachment-0001.sig>
More information about the Debian-med-packaging
mailing list