Assume I have an infix expression such as k1*s1, how do I use libsbml to translate this expression to mathml using the python interface?
Asked
Active
Viewed 107 times
6
-
Welcome to the site. Can you include examples if what you have already tried? β Bioathlete Jul 18 '19 at 15:52
-
See answer below. It works, I tried it. β rhody Jul 18 '19 at 17:14
1 Answers
4
Itβs quite straightforward to convert infix to mathml using libsbml. Make sure you have libsbml installed in python by typing
pip install python-libsbml
at the windows/Mac/Linux command line or
!pip install python-libsbml
if you are running a Jupyter notebook. Some tools such as Tellurium already have libsbml preinstalled.
At the python command line type
import libsbml
to import the package. To enter the infix expression type the following:
p = libsbml.parseFormula ('k1*s1')
To generate the mathml type
print (libsbml.writeMathMLToString (p))
-
One should use the newer
libsbml.parseL3Formulawhich provides the full set of SBML Level 3 formula parsing. I recommend using the extendedlibsbml.parseL3FormulaWithModel(formula, model)which uses a model instance to resolve the actual symbols in the formula. Thereby it is clear if all the symbols exist in the model. If the functions returnNonemake sure to check thegetLastParseL3Errorto find out what went wrong. β matthiaskoenig Jul 29 '19 at 06:47