Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_to_sbml() fails with TypeError #1408

Open
hariszaf opened this issue Sep 26, 2024 · 0 comments
Open

write_to_sbml() fails with TypeError #1408

hariszaf opened this issue Sep 26, 2024 · 0 comments

Comments

@hariszaf
Copy link

Hi there!
Thanks a lot for the great resource!! 👍
I may have found something funny but since I am not sure if it's a system-dependent issue apologies in advance for any unnecessary trouble.

Here is what I noticed:

>>> import libsbml, cobra
>>> libsbml.getLibSBMLDottedVersion()
'5.20.2'
>>> cobra.__version__
'0.29.0'
>>> cobra.io.write_sbml_model(model, "test.xml")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/miniconda3/lib/python3.12/site-packages/cobra/io/sbml.py", line 1171, in write_sbml_model
    doc = _model_to_sbml(cobra_model, f_replace=f_replace, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.12/site-packages/cobra/io/sbml.py", line 1363, in _model_to_sbml
    reaction.setReversible(cobra_reaction.lower_bound < 0)
  File "/opt/miniconda3/lib/python3.12/site-packages/libsbml/__init__.py", line 31714, in setReversible
    return _libsbml.Reaction_setReversible(self, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'Reaction_setReversible', argument 2 of type 'bool'

When I just edited line:

reaction.setReversible((cobra_reaction.lower_bound < 0))

adding a bool() around
reaction.setReversible((cobra_reaction.lower_bound < 0))
I was able to write the SBML model..

So my working version would be:

reaction.setReversible(bool(cobra_reaction.lower_bound < 0))

It's funny since when you ask the type of the cobra_reaction.lower_bound < 0 it is a bool.

I guess since it's a rather basic function and no other issue was there, maybe it's something on my set-up that I am missing.

In any case hope this helps. 😅

@hariszaf hariszaf changed the title write_to_sbml() fails with `TypeError: write_to_sbml() fails with TypeError Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant