Parsing MATHML formula

238 views
Skip to first unread message

Rani

unread,
May 31, 2016, 9:48:05 AM5/31/16
to sbml-discuss
Hi All,
I am writing a SBML parser for our simulator in doing that I am struck at this point where I am unable to parse MathML formula in python libsbml.

E.g
        <math xmlns="http://www.w3.org/1998/Math/MathML">
          <apply>
            <plus/>
            <ci> PKC-DAG-AA_p </ci>
            <ci> PKC-Ca-memb_p </ci>
            <ci> PKC-Ca-AA_p </ci>
            <ci> PKC-DAG-memb_p </ci>
            <ci> PKC-basal_p </ci>
            <ci> PKC-AA_p </ci>
            <ci> globalParameter</ci>
        <cn> 4 </ci>
          </apply>
        </math>

I need to get list of species (1st 6 are species) , globalParameter and constant from the MathML, i.e list of children from mathML,
This belongs to assignment rule and we don't have provision to specify global parameter, so I need to replace the global parameter with the constant which is associated with it.
I have install libsbml.5.9.0
I have done

rule = model.getRule(r)
ruleMath = rule.getMath()
num = ruleMath.getNumChildren()
for i in range(0,num):
     child = ruleMath.getChild(i)
     print child.getName()

But ruleMath.getNumChildren() return 2 and with for loop I just get one species name.

I read a post saying ruleMath.getNumChildren() return 2 should I use any patch for libsbml?

Through this if I can get all the children then I can parse species,global parameter and constant separately as per my requirement

Thank you

Frank Bergmann

unread,
May 31, 2016, 11:08:41 AM5/31/16
to sbml-discuss
Hello Rani, 

I have attached an example that shows how you can do it. The point is that the ASTNode elements will be a tree, so it could be that you were getting a recursive set of elements. Just be careful, that the identifiers you have are not valid. The names in the ASTNodes have to be valid SIds, and your species Ids have hyphens in them. 

best
Frank
traverse_math.py

Rani

unread,
Jun 1, 2016, 2:18:16 AM6/1/16
to sbml-discuss
Thank you Frank for the reply. It works.

Regards
Rani
Reply all
Reply to author
Forward
0 new messages