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

community SBML model is not being read #1075

Open
shumantov opened this issue Apr 6, 2021 · 4 comments
Open

community SBML model is not being read #1075

shumantov opened this issue Apr 6, 2021 · 4 comments

Comments

@shumantov
Copy link

shumantov commented Apr 6, 2021

Hi all,

I've created a community model for 156 genomes using carveme, and it's not being read by cobra.
This is the error I get:

KeyError                                  Traceback (most recent call last)
~\AppData\Roaming\Python\Python38\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, **kwargs)
    250         doc = _get_doc_from_filename(filename)
--> 251         return _sbml_to_model(doc, number=number, f_replace=f_replace, **kwargs)
    252     except IOError as e:

~\AppData\Roaming\Python\Python38\site-packages\cobra\io\sbml.py in _sbml_to_model(doc, number, f_replace, set_missing_bounds, **kwargs)
    711         for met_id in stoichiometry:
--> 712             metabolite = cobra_model.metabolites.get_by_id(met_id)
    713             object_stoichiometry[metabolite] = stoichiometry[met_id]

~\AppData\Roaming\Python\Python38\site-packages\cobra\core\dictlist.py in get_by_id(self, id)
     57         """return the element with a matching id"""
---> 58         return list.__getitem__(self, self._dict[id])
     59 

KeyError: '5drib_c'

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

CobraSBMLError                            Traceback (most recent call last)
<ipython-input-3-6a2c51e0c0c8> in <module>
      1 base_folder = r'C:/Users/ginatta/desktop/Work/'
      2 com_mod = 'meta_wrap_community.xml'
----> 3 community_model = cobra.io.read_sbml_model(base_folder + com_mod)

~\AppData\Roaming\Python\Python38\site-packages\cobra\io\sbml.py in read_sbml_model(filename, number, f_replace, **kwargs)
    263             "at https://github.com/opencobra/cobrapy/issues ."
    264         )
--> 265         raise_from(cobra_error, original_error)
    266 
    267 

~\AppData\Roaming\Python\Python38\site-packages\six.py in raise_from(value, from_value)

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 .

This model is too big for sbml validator to validate, and also the cobra validation does not work (throws the same error), so I'm not sure whether there is something wrong with the model itself, maybe its size, or with cobra trying to read it. any ideas for how should I handle this?

Your help regarding this issue would be much appreciated!

Alon

@matthiaskoenig matthiaskoenig mentioned this issue Apr 6, 2021
3 tasks
@matthiaskoenig
Copy link
Contributor

I am pretty sure you have invalid SBML identifiers in your model. Identifiers are not allowed which start with numbers. So the 5drib_c is very likely an invalid identifier. You could try to read the model without replacements of identifiers, i.e. set the argument f_replace = None in the read_sbml_model.
You can validate the model using other tools such as sbmlutils. Just let me know if you need support here.

@shumantov
Copy link
Author

Hi matthiaskoenig,
Thank you for your response!

What exactly does it mean that my Identifiers are invalid? Does this related exclusively to the tool generating the models? And, is there a way to remove those identifiers, or to modify them, so they will be valid?

I've tried setting f_replace = None, and the key error is different, yet still present:
KeyError: 'M_5drib_c'

instead of:

KeyError: '5drib_c'

The rest is similar:

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 .

So it still doesn't work.

I would love some support!

Do you see a way I can make this particular community model to be read?

Or maybe do you know a different tool, for the creation of community models? Again, I've been using carveme, which is OK as far as I know, but I'm open for other ideas if you have any, since this is quite crucial for my work.

Thank you again.

Alon

@matthiaskoenig
Copy link
Contributor

SBML identifiers must follow a certain syntax, e.g. are not allowed to start with numbers or have special characters.
This has many advantages, among others they can be used as variable names. Often these conditions are not fullfilled so tools are doing replacements on the identifiers (e.g. adding M_ prefixes to the identifiers) to get valid identifiers.

Some people thought it is a good idea to try to do back-replacements on the SBML import in cobrapy, e.g. removing prefixes and replacing special characters. I am strongly opposed to that because it breaks things all over the place. Basically half the issues on the cobrapy issue tracker are due to the replacements on model import! This includes things like invalid CPLEX and GUROBI variable names up to completely confused users who cannot find there SBML species because the ids changed.
If I had one wish free for cobrapy it would be stopping id replacements on import/export.

In your case your model is most likely invalid and misses certain elements. I would run the SBML validation on it to see what is broken in the model.

@xuejun1214
Copy link

Did you figure out to resolve this issue?

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

3 participants