How to find name and compartment for a species?
Closed this issue ยท 4 comments
Another request for metadata like #61
Consider:
<species metaid="_704563" id="cpep" name="Phosphoenol pyruvate" compartment="cytosol" initialConcentration="2.67">
I would like to get the compartment and name for all the species in my model.
I can get the id
and the initialConcentration
from prn.u0
but not sure if/how to ge tthe others.
I see the compartment is captured here:
SBMLImporter.jl/src/species.jl
Line 16 in 943a75b
But I am not sure the name is at all.
And I am not sure how to get at the compartment once it is loaded.
This is also a good suggestion!
The compartment = specie.compartment
is the compartment name, but, it is also part of the internal structs that I would not like to expose to the user.
The best and most consistent solution would be to set compartment
as metadata
to the species
, and that then it would be possible to retrieve the compartment with setmetadata
. However, the species metadata field seems to be less flexible than the field for a Catalyst.Reaction
.
@TorkelE the following fails for me:
using Catalyst
# Create model.
t = default_t
model = @reaction_network begin
@species S(t) [compartment="C1"]
kB, S + E --> SE
kD, SE --> S + E
kP, SE --> P + E
end
Is it something I miss about setting custom metadata field for a specie
?
Yes. Species metadata is a bit of a mess. It uses the symbolic variables metadata which is implemented by Symbolics.jl. here, each metadata field need a specific implementation (I think the reason is to prevent two different packages from implementing a metadata with the same name but different purposes, without that getting detected).
If you check Catalyst, you can see how e.g. the CompoundSpecies metadata is implemented. I've requested a dev doc in Symbolics describing this for a while, and at this point I might just write it myself at some point.
Then implementing a fix similar to how CompoundSpecies is handled but for compartments sounds like the best solution.
While I implement support for this (which I should get done this week), @oxinabox you can up to then use the following workaround with the help of SBML.jl to access the compartment for each model specie:
using SBML
model = readSBML(path_sbml)
# Dict with specie info. Id must be a string
model.species[id].compartment
Note that here id
must be a string.
This is closed by #69
Basically, all species now get a compartment metadata field, that can be accessed via the getcompartment
function, for example to now get the compartment of the first model specie do:
# Get compartment for first model specie
using SBMLImporter, Catalyst
prn, cb = load_SBML(path_SBML)
sbml_species = species(prn.rn)
c = getcompartment(sbml_species[1])
As Catalyst does not have a compartment concept yet (but would be a good idea for the future), the getcompartment
currently lives in the SBMLImporter package.