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?
$\begingroup$
$\endgroup$
2
-
$\begingroup$ Welcome to the site. Can you include examples if what you have already tried? $\endgroup$– BioathleteCommented Jul 18, 2019 at 15:52
-
$\begingroup$ See answer below. It works, I tried it. $\endgroup$– user4894Commented Jul 18, 2019 at 17:14
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
1
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))
-
$\begingroup$ One should use the newer
libsbml.parseL3Formula
which 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 returnNone
make sure to check thegetLastParseL3Error
to find out what went wrong. $\endgroup$ Commented Jul 29, 2019 at 6:47