Function in libSBML to return parameter/species names specified by an assignment rule from XML string?

10 views
Skip to first unread message

ver...@uw.edu

unread,
Jan 18, 2019, 2:58:49 PM1/18/19
to sbml-interoperability
Hello,

Are there functions within libSBML that return only the parameter or species names which are defined by an assignment rule from an XML string from the full parameter/species list? 

Thank you,
Veronica


Herbert Sauro

unread,
Jan 18, 2019, 7:09:31 PM1/18/19
to sbml-interoperability
Use getRule (n) on the model instance, eg

ar = model.getRule (n)
print (ar.getId())

I think that should do it. I've not checked but I imagine there will be something to check if the selected rule is an assignment rule.

Herbert

Lucian Smith

unread,
Jan 18, 2019, 7:16:44 PM1/18/19
to SBML Software Interoperability Discussion List
On Fri, Jan 18, 2019 at 4:09 PM Herbert Sauro <hsa...@gmail.com> wrote:
Use getRule (n) on the model instance, eg

ar = model.getRule (n)
print (ar.getId())

I think that should do it. I've not checked but I imagine there will be something to check if the selected rule is an assignment rule.

If you know all your rules are assignment rules, that'll work; if there is or might be a mix, you can check first:

ar = model.getRule(n)
if (ar.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE):
  print(ar.getVariable())


-Lucian

Herbert Sauro

unread,
Jan 18, 2019, 7:20:39 PM1/18/19
to sbml-inter...@googlegroups.com
That's the bit I didn't know.

Herbert

--
You received this message because you are subscribed to the Google Groups "sbml-interoperability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sbml-interoperab...@googlegroups.com.
To post to this group, send email to sbml-inter...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sbml-interoperability/CAHLmBr27o6pJLs%2BUrKi19XdauuTkhVLzb5UJsMmjfPwmX4nwTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

ver...@uw.edu

unread,
Jan 18, 2019, 7:30:45 PM1/18/19
to sbml-interoperability
Thank you, Lucian and Herbert.
 
Taking your responses, I find this solves the problem and returns a list of all parameter names associated with assignment rules: 

import libsbml
doc = libsbml.readSBMLFromFile ('someSBMLmodel.xml')
model = doc.getModel();
lenListRules = len(model.getListOfRules())
ruleParams = []
for i in range(lenListRules):
    rule = model.getRule(i)
    if (rule.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE):
        ruleId = rule.getVariable()
        ruleParams.append(ruleId)



On Friday, January 18, 2019 at 4:20:39 PM UTC-8, Herbert Sauro wrote:
That's the bit I didn't know.

Herbert

On Fri, Jan 18, 2019 at 4:16 PM Lucian Smith <luciano...@gmail.com> wrote:
On Fri, Jan 18, 2019 at 4:09 PM Herbert Sauro <hsa...@gmail.com> wrote:
Use getRule (n) on the model instance, eg

ar = model.getRule (n)
print (ar.getId())

I think that should do it. I've not checked but I imagine there will be something to check if the selected rule is an assignment rule.

If you know all your rules are assignment rules, that'll work; if there is or might be a mix, you can check first:

ar = model.getRule(n)
if (ar.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE):
  print(ar.getVariable())


-Lucian

--
You received this message because you are subscribed to the Google Groups "sbml-interoperability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sbml-interoperability+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages