matthiaskoenig / fbc_curation

FROG analysis in python for the reproducibility of FBC models
https://runfrog.de
GNU Lesser General Public License v3.0
8 stars 3 forks source link

valid SBML-file throws non-valid SBML error #62

Closed uliebal closed 2 years ago

uliebal commented 2 years ago

my model raises an cobra_error although the model works nicely in cobrapy and is valid SBML according to the validator (just 3722 warnings). cameo=0.13.6 and cobra=0.23.0. The fbc_curation tests and another of my models are fine.

* CuratorCobrapy: metadata
* CuratorCobrapy: objective
Scaling...
 A: min|aij| =  1.000e+00  max|aij| =  1.000e+00  ratio =  1.000e+00
Problem data seem to be well scaled
Traceback (most recent call last):
  File "/home/ulf/.local/lib/python3.8/site-packages/cobra/io/sbml.py", line 249, in read_sbml_model
    return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
  File "/home/ulf/.local/lib/python3.8/site-packages/cobra/io/sbml.py", line 750, in _sbml_to_model
    cobra_model.add_reactions(reactions)
  File "/home/ulf/.local/lib/python3.8/site-packages/cobra/core/model.py", line 713, in add_reactions
    self._populate_solver(pruned)
  File "/home/ulf/.local/lib/python3.8/site-packages/cobra/core/model.py", line 1008, in _populate_solver
    reverse_variable = self.problem.Variable(reaction.reverse_id)
  File "/home/ulf/.local/lib/python3.8/site-packages/optlang/symbolics.py", line 129, in __new__
    obj.name = name
  File "/home/ulf/.local/lib/python3.8/site-packages/optlang/glpk_interface.py", line 148, in name
    _glpk_validate_id(value)
  File "/home/ulf/.local/lib/python3.8/site-packages/optlang/glpk_interface.py", line 77, in _glpk_validate_id
    raise ValueError("GLPK does not support ID's longer than 256 characters")
ValueError: GLPK does not support ID's longer than 256 characters

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ulf/.local/bin/fbc_curation", line 8, in <module>
    sys.exit(main())
  File "/home/ulf/.local/lib/python3.8/site-packages/fbc_curation/curation.py", line 159, in main
    results = curator.run()  # type: CuratorResults
  File "/home/ulf/.local/lib/python3.8/site-packages/fbc_curation/curator/curator.py", line 87, in run
    objective = self.objective()
  File "/home/ulf/.local/lib/python3.8/site-packages/fbc_curation/curator/cobrapy_curator.py", line 48, in objective
    model = self.read_model()
  File "/home/ulf/.local/lib/python3.8/site-packages/fbc_curation/curator/cobrapy_curator.py", line 34, in read_model
    return read_sbml_model(str(self.model_path), f_replace={})
  File "/home/ulf/.local/lib/python3.8/site-packages/cobra/io/sbml.py", line 263, in read_sbml_model
    raise cobra_error from original_error
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 .
    `(model, errors) = validate_sbml_model(filename)`
If the model is valid and cannot be read please open an issue at https://github.com/opencobra/cobrapy/issues .
matthiaskoenig commented 2 years ago

Hi @uliebal,

this is a known issue with cobrapy, please see discussion in https://github.com/opencobra/cobrapy/issues/609.

The only workaround for now is to use ids with <256 characters. So you should rename the affected id(s). As a side note, I highly recommend to do this, because many tools will fail with such long ids. If you need help finding the ids in questions let me know and provide the model.

Best Matthias

uliebal commented 2 years ago

thanks @matthiaskoenig ! Due to the special characters in my reaction names the conversion to SBML generated long ids. While I did not find the culprits, I just replaced the very complex reaction names that contain / with the one-liner below. Because the shortened ids are non-unique, I also added a reaction count to the end of the new id: [setattr(my, 'id', my.id.split('/')[0]+str(idx)) for idx, my in enumerate(model.reactions) if '/' in my.id]

With that correction alone fbc_curation works.

Ed0u66 commented 7 months ago

Hi @uliebal,

this is a known issue with cobrapy, please see discussion in opencobra/cobrapy#609.

The only workaround for now is to use ids with <256 characters. So you should rename the affected id(s). As a side note, I highly recommend to do this, because many tools will fail with such long ids. If you need help finding the ids in questions let me know and provide the model.

Best Matthias

Hye Matthias,

I'm sorry to bother you, i've got the same problem than @uliebal
(first the same problem of invalid characters than #964 then i saw you advice in #955 so i read the model with f_replace={} but now it's the long ids problem's.) I wanted to know how to find the ids in questions (cause i will have 2 model to "cure") but let me share you one of my model
model_41.zip

Thank you a lot for all the help that you provide here.