Unverified Commit 19945dde authored by Laurent Heirendt's avatar Laurent Heirendt Committed by GitHub
Browse files

Merge pull request #28 from LCSB-BioCore/mk-associations

parents 744310aa 26c13d0a
...@@ -51,6 +51,38 @@ getNotes(x::VPtr)::Maybe{String} = getOptionalString(x, :SBase_getNotesString) ...@@ -51,6 +51,38 @@ getNotes(x::VPtr)::Maybe{String} = getOptionalString(x, :SBase_getNotesString)
getAnnotation(x::VPtr)::Maybe{String} = getOptionalString(x, :SBase_getAnnotationString) getAnnotation(x::VPtr)::Maybe{String} = getOptionalString(x, :SBase_getAnnotationString)
""" """
function getAssociation(x::VPtr)::GeneProductAssociation
Convert a pointer to SBML `FbcAssociation_t` to the `GeneProductAssociation`
tree structure.
"""
function getAssociation(x::VPtr)::GeneProductAssociation
# libsbml C API is currently missing functions to check this in a normal
# way, so we use a bit of a hack.
typecode = ccall(sbml(:SBase_getTypeCode), Cint, (VPtr,), x)
if typecode == 808 # SBML_FBC_GENEPRODUCTREF
return GPARef(
unsafe_string(ccall(sbml(:GeneProductRef_getGeneProduct), Cstring, (VPtr,), x)),
)
elseif typecode == 809 # SBML_FBC_AND
return GPAAnd([
getAssociation(
ccall(sbml(:FbcAnd_getAssociation), VPtr, (VPtr, Cuint), x, i - 1),
) for i = 1:ccall(sbml(:FbcAnd_getNumAssociations), Cuint, (VPtr,), x)
])
elseif typecode == 810 # SBML_FBC_OR
return GPAOr([
getAssociation(
ccall(sbml(:FbcOr_getAssociation), VPtr, (VPtr, Cuint), x, i - 1),
) for i = 1:ccall(sbml(:FbcOr_getNumAssociations), Cuint, (VPtr,), x)
])
else
throw(ErrorException("Unsupported FbcAssociation type"))
end
end
""""
function extractModel(mdl::VPtr)::Model function extractModel(mdl::VPtr)::Model
Take the `SBMLModel_t` pointer and extract all information required to make a Take the `SBMLModel_t` pointer and extract all information required to make a
...@@ -152,7 +184,6 @@ function extractModel(mdl::VPtr)::Model ...@@ -152,7 +184,6 @@ function extractModel(mdl::VPtr)::Model
mdl_fbc, mdl_fbc,
i - 1, i - 1,
) )
for j = 1:ccall(sbml(:Objective_getNumFluxObjectives), Cuint, (VPtr,), o) for j = 1:ccall(sbml(:Objective_getNumFluxObjectives), Cuint, (VPtr,), o)
fo = ccall(sbml(:Objective_getFluxObjective), VPtr, (VPtr, Cuint), o, j - 1) fo = ccall(sbml(:Objective_getFluxObjective), VPtr, (VPtr, Cuint), o, j - 1)
objectives_fbc[unsafe_string( objectives_fbc[unsafe_string(
...@@ -231,12 +262,28 @@ function extractModel(mdl::VPtr)::Model ...@@ -231,12 +262,28 @@ function extractModel(mdl::VPtr)::Model
add_stoi(sr, 1) add_stoi(sr, 1)
end end
association = nothing
if re_fbc != C_NULL
gpa = ccall(
sbml(:FbcReactionPlugin_getGeneProductAssociation),
VPtr,
(VPtr,),
re_fbc,
)
if gpa != C_NULL
a = ccall(sbml(:GeneProductAssociation_getAssociation), VPtr, (VPtr,), gpa)
a != C_NULL
association = getAssociation(a)
end
end
reid = unsafe_string(ccall(sbml(:Reaction_getId), Cstring, (VPtr,), re)) reid = unsafe_string(ccall(sbml(:Reaction_getId), Cstring, (VPtr,), re))
reactions[reid] = Reaction( reactions[reid] = Reaction(
stoi, stoi,
lb, lb,
ub, ub,
haskey(objectives_fbc, reid) ? objectives_fbc[reid] : oc, haskey(objectives_fbc, reid) ? objectives_fbc[reid] : oc,
association,
getNotes(re), getNotes(re),
getAnnotation(re), getAnnotation(re),
) )
......
...@@ -28,6 +28,34 @@ struct UnitPart ...@@ -28,6 +28,34 @@ struct UnitPart
UnitPart(k, e, s, m) = new(k, e, s, m) UnitPart(k, e, s, m) = new(k, e, s, m)
end end
"""
Abstract type for all kinds of gene product associations
"""
abstract type GeneProductAssociation end
"""
Gene product reference in the association expression
"""
struct GPARef <: GeneProductAssociation
gene_product::String
end
"""
Boolean binary "and" in the association expression
"""
struct GPAAnd <: GeneProductAssociation
terms::Vector{GeneProductAssociation}
end
"""
Boolean binary "or" in the association expression
"""
struct GPAOr <: GeneProductAssociation
terms::Vector{GeneProductAssociation}
end
""" """
Reaction with stoichiometry that assigns reactants and products their relative Reaction with stoichiometry that assigns reactants and products their relative
consumption/production rates (accessible in field `stoichiometry`), lower/upper consumption/production rates (accessible in field `stoichiometry`), lower/upper
...@@ -39,9 +67,10 @@ struct Reaction ...@@ -39,9 +67,10 @@ struct Reaction
lb::Tuple{Float64,String} lb::Tuple{Float64,String}
ub::Tuple{Float64,String} ub::Tuple{Float64,String}
oc::Float64 oc::Float64
gene_product_association::Maybe{GeneProductAssociation}
notes::Maybe{String} notes::Maybe{String}
annotation::Maybe{String} annotation::Maybe{String}
Reaction(s, l, u, o, n = nothing, a = nothing) = new(s, l, u, o, n, a) Reaction(s, l, u, o, as, n = nothing, an = nothing) = new(s, l, u, o, as, n, an)
end end
""" """
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment