sys-bio / tellurium

Python Environment for Modeling and Simulating Biological Systems
http://tellurium.analogmachine.org/
Apache License 2.0
108 stars 36 forks source link

Antimony from SBML - MODEL1303260018 - Smallbone2013 - Glycolysis in S.cerevisiae - Iteration 18 #349

Open NaiaW opened 6 years ago

NaiaW commented 6 years ago

Getting the Antimony from the SBML model "MODEL1303260018 - Smallbone2013 - Glycolysis in S.cerevisiae - Iteration 18" (https://www.ebi.ac.uk/biomodels-main/MODEL1303260018) does not work.

I am on Windows and using Python 3.6.4. The same error is observed on OS X for both python 2.7 and 3.6

r = te.loadSBMLModel("/Users/narisa/Downloads/MODEL1303260018_level3_version1.xml") antimony_model = r.getCurrentAntimony()


Exception Traceback (most recent call last)

in () 4 #te.sbmlToAntimony(r) 5 #See the current biomodel ----> 6 antimony_model = r.getCurrentAntimony() 7 #print(antimony_model) 8 #Solve and plot model ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tellurium\roadrunner\extended_roadrunner.py in getCurrentAntimony(self) 125 :rtype: str 126 """ --> 127 return self.getAntimony(current=True) 128 129 def getCellML(self, current=False): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tellurium\roadrunner\extended_roadrunner.py in getAntimony(self, current) 116 sbml = self.__getSBML(current) 117 from .. import sbmlToAntimony --> 118 return sbmlToAntimony(sbml) 119 120 def getCurrentAntimony(self): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tellurium\tellurium.py in sbmlToAntimony(sbml) 628 else: 629 code = antimony.loadSBMLString(str(sbml)) --> 630 _checkAntimonyReturnCode(code) 631 return antimony.getAntimonyString(None) 632 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tellurium\tellurium.py in _checkAntimonyReturnCode(code) 286 """ 287 if code < 0: --> 288 raise Exception('Antimony: {}'.format(antimony.getLastError())) 289 290 def colorCycle(color,polyNumber): Exception: Antimony: 1 SBML error(s) when creating module '__main'. libAntimony tries to catch these errors before libSBML complains, but sometimes cannot. Error message(s) from libSBML: The only permitted MathML 2.0 elements in SBML Level 2 are the following: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and . SBML L3V2 added , , , and . Reference: L3V1 Section 3.4.1 is not valid in SBML Level 3 Version 1.
kirichoi commented 6 years ago

The issue seems to be coming from the fact that the model is using max operator. However, max operator was never supported by SBML L3V1 according to the specification.

We are working on SBML L3V2 support which will be able to understand min and max operators.

kirichoi commented 6 years ago

Also, I don't think we even have Antimony notations for min and max specified yet.

@luciansmith: Any thoughts?

luciansmith commented 6 years ago

Antimony does now support l3v2, and therefore should support max and min. But as noted, those are not allowed in l3v1 models. You might simply try changing the level/version to l3v2 and see if Antimony will read it as-is. It will not be automatically convertible to l3v1, though.

matthiaskoenig commented 6 years ago

This looks like a bug to me. The model is valid and defines a own max function with the name "max". This does not have anything todo with L3V2, but somehow the parser gets confused by the funcion id "max". Probably you are checking for the "max" symbol and complain if not L3V2. Best M

On Mon, Mar 19, 2018 at 6:03 PM, Lucian Smith notifications@github.com wrote:

Antimony does now support l3v2, and therefore should support max and min. But as noted, those are not allowed in l3v1 models. You might simply try changing the level/version to l3v2 and see if Antimony will read it as-is. It will not be automatically convertible to l3v1, though.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sys-bio/tellurium/issues/349#issuecomment-374288601, or mute the thread https://github.com/notifications/unsubscribe-auth/AA29ukYgObwKVLizm-2VUV65LQ8R70k7ks5tf-TsgaJpZM4SwBjG .

-- Matthias König, PhD. Junior Group Leader LiSyM - Systems Medicine of the Liver Humboldt Universität zu Berlin, Institute of Biology, Institute for Theoretical Biology https://livermetabolism.com konigmatt@googlemail.com https://twitter.com/konigmatt https://github.com/matthiaskoenig Tel: +49 30 20938450

luciansmith commented 6 years ago

Oh! Yeah, that would make sense. The libsbml parser now understands 'max' itself, so parses it as a mathML function, not an SBML function. There are a few places we could subvert that process; I'll look into it. In the meantime, a quick fix would be to replace 'max' in this model with 'localmax' or something.

(If anyone else wants to try delving into Antimony code, the first thing to check would be to see if adding 'max' and 'min' to the 'reserved words' section in Antimony would work--it would convert them to 'max' and 'min'.)

kirichoi commented 6 years ago

Hmm, that might be true. The error message is originating from libSBML btw. We might not be able to fix it on our end.

luciansmith commented 6 years ago

The SBML error is for the translated model that Antimony generates, so we can indeed fix it on our end.

matthiaskoenig commented 6 years ago

@NaiaW Where did you get the L3V1 model version. I tried on biomodels and some time ago they had the L1V3 models for download, but could not find them any more on the homepage?

There are even more issues with the model conversion to antimony. I created a replaced model version with localmin and localmax (see attached).

MODEL1303260018_localminmax.xml.zip

Now antimony has problems with volume. Probably another restricted keyword. There is a parameter volume in the model.

In [3]: r = te.loads("MODEL1303260018_localminmax.xml")

In [4]: a = r.getCurrentAntimony()
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-4-1f54f60d99e5> in <module>()
----> 1 a = r.getCurrentAntimony()

~/envs/test/lib/python3.6/site-packages/tellurium/roadrunner/extended_roadrunner.py in getCurrentAntimony(self)
    125         :rtype: str
    126         """
--> 127         return self.getAntimony(current=True)
    128 
    129     def getCellML(self, current=False):

~/envs/test/lib/python3.6/site-packages/tellurium/roadrunner/extended_roadrunner.py in getAntimony(self, current)
    116         sbml = self.__getSBML(current)
    117         from .. import sbmlToAntimony
--> 118         return sbmlToAntimony(sbml)
    119 
    120     def getCurrentAntimony(self):

~/envs/test/lib/python3.6/site-packages/tellurium/tellurium.py in sbmlToAntimony(sbml)
    634     else:
    635         code = antimony.loadSBMLString(str(sbml))
--> 636     _checkAntimonyReturnCode(code)
    637     return antimony.getAntimonyString(None)
    638 

~/envs/test/lib/python3.6/site-packages/tellurium/tellurium.py in _checkAntimonyReturnCode(code)
    292     """
    293     if code < 0:
--> 294         raise Exception('Antimony: {}'.format(antimony.getLastError()))
    295 
    296 def colorCycle(color,polyNumber):

Exception: Antimony: 105 SBML error(s) when creating module 'MODEL1303260018'.  libAntimony tries to catch these errors before libSBML complains, but sometimes cannot.  Error message(s) from libSBML:

Outside of a <functionDefinition>, if a <ci> element is not the first element within a MathML <apply>, then the <ci>'s value can only be chosen from the set of identifiers of (in L2V1) <species>, <compartment>, or <parameter> objects; (in L2V2-L2V5), <species>, <compartment>, <parameter> or <reaction> objects; (in L3V1) <species>, <compartment>, <parameter>, <reaction> or <speciesReference> objects and (in L3V2) <species>, <compartment>, <parameter>, <reaction>, <speciesReference> objects or L3 package objects with defined mathematical meaning. 
Reference: L3V1 Section 3.4.3
 The formula 'volume' in the math element of the <assignmentRule> uses 'volume' that is not the id of a species/compartment/parameter/reaction/speciesReference.
....
kirichoi commented 6 years ago

Can confirm this. Antimony has reserved keywords such as 'volume', 'area', 'length', etc. Attached is a model that fixed all the issues and will work with Antimony.

MODEL1303260018.zip

NaiaW commented 6 years ago

Thanks a lot for your quick respond and help to my question. That really helped me a lot.

@matthiaskoenig I tried to solve the problem by conversion of the model to the L3V1 model version using COPASI.

Best Naia

matthiaskoenig commented 6 years ago

Antimony must be able to handle models which use arbitrary ids (even if this overlap with internal keywords). Variable ids like "max", "min", "area", "volume", "compartment", ... are very common in models. Lucian mentioned these can be added to a list in antimony so that they are replaced. It would be great to have one solution which solves this issue, for instance checking the model ids against reserved keywords and replacing them or something similar.