opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
467 stars 218 forks source link

Fix type for SBML history dates #1301

Closed cdiener closed 2 years ago

cdiener commented 2 years ago

Current behavior

Python 3.10.8 (main, Nov  4 2022, 09:21:25) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from cobra.io import load_model

In [2]: mod = load_model("BIOMD0000000003")
Model does not contain SBML fbc package information.
Restricted license - for non-production use only - expires 2023-10-25
SBML package 'layout' not supported by cobrapy, information is not parsed
SBML package 'render' not supported by cobrapy, information is not parsed
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction1 "creation of cyclin">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction1 "creation of cyclin">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction2 "default degradation of cyclin">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction2 "default degradation of cyclin">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction3 "cdc2 kinase triggered degration of cyclin">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction3 "cdc2 kinase triggered degration of cyclin">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction4 "activation of cdc2 kinase">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction4 "activation of cdc2 kinase">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction5 "deactivation of cdc2 kinase">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction5 "deactivation of cdc2 kinase">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction6 "activation of cyclin protease">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction6 "activation of cyclin protease">'
Missing lower flux bound set to '-1000.0' for reaction: '<Reaction reaction7 "deactivation of cyclin protease">'
Missing upper flux bound set to '1000.0' for reaction: '<Reaction reaction7 "deactivation of cyclin protease">'
No objective coefficients in model. Unclear what should be optimized
Missing flux bounds on reactions set to default bounds.As best practise and to avoid confusion flux bounds should be set explicitly on all reactions.

In [3]: import pickle

In [4]: s = pickle.dumps(mod)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 s = pickle.dumps(mod)

TypeError: cannot pickle 'SwigPyObject' object

In [5]: mod._sbml["created"]
Out[5]: <libsbml.Date; proxy of <Swig Object of type 'Date_t *' at 0x7f3c8b80fa20> >

This will also affect any parallel code on Mac and Windows since those use spawn for new processes which will pickle the model.

Fix

This PR casts the date to a Python string which fixes the behavior.

codecov-commenter commented 2 years ago

Codecov Report

Base: 84.46% // Head: 83.90% // Decreases project coverage by -0.56% :warning:

Coverage data is based on head (2f28894) compared to base (4ef4d79). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## devel #1301 +/- ## ========================================== - Coverage 84.46% 83.90% -0.57% ========================================== Files 66 66 Lines 5499 5499 Branches 1257 1257 ========================================== - Hits 4645 4614 -31 - Misses 538 568 +30 - Partials 316 317 +1 ``` | [Impacted Files](https://codecov.io/gh/opencobra/cobrapy/pull/1301?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra) | Coverage Δ | | |---|---|---| | [src/cobra/io/sbml.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL2lvL3NibWwucHk=) | `80.02% <100.00%> (ø)` | | | [src/cobra/util/process\_pool.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL3V0aWwvcHJvY2Vzc19wb29sLnB5) | `39.53% <0.00%> (-27.91%)` | :arrow_down: | | [src/cobra/sampling/optgp.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL3NhbXBsaW5nL29wdGdwLnB5) | `75.38% <0.00%> (-16.93%)` | :arrow_down: | | [src/cobra/flux\_analysis/deletion.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL2ZsdXhfYW5hbHlzaXMvZGVsZXRpb24ucHk=) | `82.45% <0.00%> (-7.02%)` | :arrow_down: | | [src/cobra/flux\_analysis/variability.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL2ZsdXhfYW5hbHlzaXMvdmFyaWFiaWxpdHkucHk=) | `85.41% <0.00%> (-5.21%)` | :arrow_down: | | [src/cobra/sampling/core.py](https://codecov.io/gh/opencobra/cobrapy/pull/1301/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra#diff-c3JjL2NvYnJhL3NhbXBsaW5nL2NvcmUucHk=) | `93.93% <0.00%> (+15.15%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opencobra)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.