Loss of annotation when reading and writing models

142 views
Skip to first unread message

Roland Sauter

unread,
Oct 14, 2016, 9:01:03 AM10/14/16
to cobra pie
Hi,

First of all: thank you all the work you guys put in. It really shows, and to me using COBRApy is much more enjoyable than anything comparable.

Unfortunately, however, I'm having some issues with annotations when reading and writing models.
I have multiple automatically generated SBML (currently L2V4) models that I would like to merge into one single model.
The procedure itself works just fine, but I lose all annotation in the process. The same happens when I read and write single models.
(Using cobra.io.read_sbml_model(...) and cobra.io.write.sbml_model(...))

Is there a way to avoid this happening?

Thank you very much, again.

Mike Mundy

unread,
Oct 18, 2016, 8:46:53 PM10/18/16
to cobra pie
I checked with some single species models that are SBML L3V1 and the annotations are preserved when reading and writing the models with cobra.io.read_sbml_model() and write_sbml_model(). Can you a post a small SBML file that demonstrates the problem?

Mike Mundy

Roland Sauter

unread,
Oct 19, 2016, 4:18:28 AM10/19/16
to cobra pie
Hi Mike,

So far, that problem has only arisen when using L2V4 files.
Attached are the input read and the output written.
The output is L3V1 as opposed to the input, which is L2V4.

Roland
input.xml
output.xml

Mike Mundy

unread,
Oct 21, 2016, 9:42:07 AM10/21/16
to cobra pie
Thanks for posting the files. It looks like the input SBML model uses <annotation> for the annotations and I don't think that is being handled the SBML parser. To be honest, I don't know the details of all the various SBML versions so I'm not sure if that is valid for L2V4.

After reading the SBML file, the cobra.Reaction objects in the model do not have the gene_reaction_rule attribute set so the annotation is not available when writing the model to SBML (which by default is L3V1).

Mike


Christian Diener

unread,
Oct 21, 2016, 6:04:12 PM10/21/16
to cobra pie
Yes, the parser for SBML2 unfortunately ignores <annotation> tags at the moment and only respects the notes field. Only the parser for SBML3 does read annotations. I added an issue to the Github repo (https://github.com/opencobra/cobrapy/issues/300) so let's hope we can change that in the near future :)

Roland Sauter

unread,
Oct 24, 2016, 4:01:18 AM10/24/16
to cobra pie
Thank you very much for the information and your efforts.
In that case, I suppose it's time to switch to L3.

On a different note:
Am I correct in assuming that merging of models via _add__ or _iadd_ also ignores annotation?

Roland

Christian Diener

unread,
Oct 26, 2016, 5:06:58 PM10/26/16
to cobra pie
No, that should work. Annotations are attributes of the reactions and metabolites. During __add__ it basically adds all reactions and metabolites from
the other model, thus, also adding the annotations. 

However, annotations are not used to check whether two reactions are the same or anything like that. This is difficult since a reaction might have the same
annotation but can still have a different composition. For instance, if I have one model that considers H+ and another one that does not. In that case the same
reaction might contain H+ in one model but not the other. Different reversibility due to pH might be another example. If you want something like that and
have a set of identities when you consider a reaction the same I could help you set up a code that does this. In general you would start by mapping
metabolites to each other by id and annotation, followed by identifying similar reactions and mapping their metabolites.

Cheers

Roland Sauter

unread,
Nov 1, 2016, 9:32:39 AM11/1/16
to cobra pie
Sorry for the late response. I was working on some follow-up problems, but now everything is working as it should.
The problems with proton balance and reversibility luckily haven't affected me until now.

Again, thank you very much for the help.
Reply all
Reply to author
Forward
0 new messages