sys-bio / tellurium

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

Overlap between IndependentFloatingSpeciesIds and DependentFloatingSpeciesIds #366

Closed willigott closed 6 years ago

willigott commented 6 years ago

I was looking for a function to get all species IDs; for reactions I can use .getReactionIds(). As I did not find a function .getSpeciesIds(), I used the .getIndependentFloatingSpeciesIds() and .getDependentFloatingSpeciesIds(); my expection was that the union of the two will then give me all the species IDS but that's not the case.

Let's say I use:

import tellurium as te

r = te.loada("""
    model dummy()

    # reactions 
    J1: x1 -> x2 + x3; 10 * c * x1 / (p1  + x1);
    J2: x2 + x3 -> x4; x3 * x2 - c * x4;
    J3: x5 + x3 -> x6; x3 * x5 - c * x6;
    J4: x1 + x3 -> x7; x3 * x1 - c * x7;

    # parameters
    p1 = 1.0;

    c := 0.5 - x3;  # not sure whether -const- is required

    # species
    species x1, x2, x3, x4, x5, x6, x7;
    x1 = 150.0;
    x2 = 4.0;
    x3 = 0.0;
    x4 = 0.0;
    x5 = 3.0;
    x6 = 0.0;
    x7 = 0.0;    

    end
""")

print(r.getIndependentFloatingSpeciesIds())
print(r.getDependentFloatingSpeciesIds())
print(r.getGlobalParameterIds())

then this will print:

['x1', 'x2', 'x3', 'x7']
['x5', 'x6', 'x7']
['p1', 'c']

So, while x7 appears twice, x4 is missing in those lists completely. Why is that? Is there a way to get the species IDs in a straightforward manner?

The only way I found is via libsbml itself (which then also allows to distinguish between constant and not constant parameters):

import libsbml

sbml_string = r.getSBML()
sbml_doc = libsbml.readSBMLFromString(sbml_string)
mod = sbml_doc.getModel()
for si in mod.getListOfSpecies():
    print(si.getId())

for pi in mod.getListOfParameters():
    print(pi.getId())
    print(pi.constant)
hsauro commented 6 years ago

That must be a bug of some kind. Both lists should be independent. It is a bit surprising however, the conservation routines have been tested extensively. We'll take a look.

Use getFloatingSpeciesIds to get all floating species.

Herbert Sauro

On Tue, May 29, 2018 at 5:40 AM willigott notifications@github.com wrote:

I was looking for a function to get all species IDs; for reactions I can use .getReactionIds(). As I did not find a function .getSpeciesIds(), I used the .getIndependentFloatingSpeciesIds() and .getDependentFloatingSpeciesIds(); my expection was that the union of the two will then give me all the species IDS but that's not the case.

Let's say I use:

import tellurium as te

r = te.loada(""" model dummy()

# reactions
J1: x1 -> x2 + x3; 10 * c * x1 / (p1  + x1);
J2: x2 + x3 -> x4; x3 * x2 - c * x4;
J3: x5 + x3 -> x6; x3 * x5 - c * x6;
J4: x1 + x3 -> x7; x3 * x1 - c * x7;

# parameters
p1 = 1.0;

c := 0.5 - x3;  # not sure whether -const- is required

# species
species x1, x2, x3, x4, x5, x6, x7;
x1 = 150.0;
x2 = 4.0;
x3 = 0.0;
x4 = 0.0;
x5 = 3.0;
x6 = 0.0;
x7 = 0.0;

end

""")

print(r.getIndependentFloatingSpeciesIds()) print(r.getDependentFloatingSpeciesIds()) print(r.getGlobalParameterIds())

then this will print:

['x1', 'x2', 'x3', 'x7'] ['x5', 'x6', 'x7'] ['p1', 'c']

So, while x7 appears twice, x4 is missing in those lists completely. Why is that? Is there a way to get the species IDs in a straightforward manner?

Not worth an own thread so I put it here; how would I get all parameters of the model?

When I use getGlobalParameterIds(), I receive p1 and c as parameters. Is there a way to get only p1? c still depends on x3, so I would like to exclude it from the parameters list...

— 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/366, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZDr4b_RGPA8NBHsADgaU15kRxZ4LAks5t3UF0gaJpZM4URaWy .

-- Herbert Sauro, Associate Professor University of Washington, Bioengineering 206-685-2119, www.sys-bio.org hsauro@uw.edu Books: http://books.analogmachine.org/

hsauro commented 6 years ago

I just tried your example on the version of tellurium I have and I get the correct answer, ie

['x3', 'x1', 'x4', 'x5'] ['x2', 'x6', 'x7'] ['p1', 'c']

I am running version:

te.getVersionInfo() Out[29]: [('tellurium', '2.0.15'), ('roadrunner', '1.4.24'), ('antimony', '2.9.4'), ('libsbml', '5.15.0'), ('libsedml', '0.4.2'), ('phrasedml', '1.0.8'), ('pySBOL', '2.2.0')]

Can you check what you're running?

Herbert Sauro

On Tue, May 29, 2018 at 5:39 AM, willigott notifications@github.com wrote:

I was looking for a function to get all species IDs; for reactions I can use .getReactionIds(). As I did not find a function .getSpeciesIds(), I used the .getIndependentFloatingSpeciesIds() and . getDependentFloatingSpeciesIds(); my expection was that the union of the two will then give me all the species IDS but that's not the case.

Let's say I use:

import tellurium as te

r = te.loada(""" model dummy()

# reactions
J1: x1 -> x2 + x3; 10 * c * x1 / (p1  + x1);
J2: x2 + x3 -> x4; x3 * x2 - c * x4;
J3: x5 + x3 -> x6; x3 * x5 - c * x6;
J4: x1 + x3 -> x7; x3 * x1 - c * x7;

# parameters
p1 = 1.0;

c := 0.5 - x3;  # not sure whether -const- is required

# species
species x1, x2, x3, x4, x5, x6, x7;
x1 = 150.0;
x2 = 4.0;
x3 = 0.0;
x4 = 0.0;
x5 = 3.0;
x6 = 0.0;
x7 = 0.0;

end

""")

print(r.getIndependentFloatingSpeciesIds()) print(r.getDependentFloatingSpeciesIds()) print(r.getGlobalParameterIds())

then this will print:

['x1', 'x2', 'x3', 'x7'] ['x5', 'x6', 'x7'] ['p1', 'c']

So, while x7 appears twice, x4 is missing in those lists completely. Why is that? Is there a way to get the species IDs in a straightforward manner?

Not worth an own thread so I put it here; how would I get all parameters of the model?

When I use getGlobalParameterIds(), I receive p1 and c as parameters. Is there a way to get only p1? c still depends on x3, so I would like to exclude it from the parameters list...

— 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/366, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZDr4b_RGPA8NBHsADgaU15kRxZ4LAks5t3UF0gaJpZM4URaWy .

-- Herbert Sauro, Associate Professor University of Washington, Bioengineering 206-685-2119, www.sys-bio.org hsauro@uw.edu Books: http://books.analogmachine.org/

willigott commented 6 years ago

Thanks for the immediate reply and the .getFloatingSpeciesIds(); exactly what I was looking for originally!

Not worth an own thread but is there then also a way to get all parameters with value constant (in the example above, I would only like to get p1 and not c)? Via libsbml I could filter those easily (see above) but do you already have a built-in for that? If not, maybe one could add a flag return_only_constant to .getGlobalParameterIds()?!

I am using (here still on python 2.7.)

[('tellurium', '2.0.12'),
 ('roadrunner', '1.4.24'),
 ('antimony', '2.9.4'),
 ('libsbml', '5.15.0'),
 ('libsedml', '403'),
 ('phrasedml', '1.0.9')]

Problem still exists after upgrading to latest version:

[('tellurium', '2.0.18'),
 ('roadrunner', '1.4.24'),
 ('antimony', '2.9.4'),
 ('libsbml', '5.15.0'),
 ('libsedml', '403'),
 ('phrasedml', '1.0.9')]
kirichoi commented 6 years ago

I cannot reproduce this issue either. Could you tell us which platform are you using?

As for getting constant parameters, I don't think there's an easy way to do this through roadrunner, but it might be something worth implementing in the future. If you would like to see this feature added, please open a new issue.

willigott commented 6 years ago

Seems to be indeed a platform related issue: Here I am on an old ubuntu version (14.04 LTS); when I try it on a 16.04 machine, the output looks as expected. I therefore close the issue (and will open another one for the parameter part later on).