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

Merge pull request #18 from LCSB-BioCore/mk-fix-nulls

Fix problems for reactions that don't have kinetic laws associated
parents a085176e e6d8f33f
......@@ -68,9 +68,9 @@ uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[SBML_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "4787b76c8914002ab3a9d2b1ae002fe82376bfba"
git-tree-sha1 = "247cd7b890c0405a73ed2fe3fdf4b44503954cdf"
uuid = "bb12108a-f4ef-5f88-8ef3-0b33ff7017f1"
version = "5.19.0+1"
version = "5.19.0+2"
[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
......
......@@ -33,12 +33,12 @@ end
function extractModel(mdl::VPtr)::Model
units = Dict{String,Vector{UnitPart}}()
for i = 0:ccall(sbml(:Model_getNumUnitDefinitions), Cuint, (VPtr,), mdl)-1
ud = ccall(sbml(:Model_getUnitDefinition), VPtr, (VPtr, Cuint), mdl, i)
for i = 1:ccall(sbml(:Model_getNumUnitDefinitions), Cuint, (VPtr,), mdl)
ud = ccall(sbml(:Model_getUnitDefinition), VPtr, (VPtr, Cuint), mdl, i - 1)
id = unsafe_string(ccall(sbml(:UnitDefinition_getId), Cstring, (VPtr,), ud))
units[id] = [
begin
u = ccall(sbml(:UnitDefinition_getUnit), VPtr, (VPtr, Cuint), ud, j)
u = ccall(sbml(:UnitDefinition_getUnit), VPtr, (VPtr, Cuint), ud, j - 1)
UnitPart(
unsafe_string(
ccall(
......@@ -52,7 +52,7 @@ function extractModel(mdl::VPtr)::Model
ccall(sbml(:Unit_getScale), Cint, (VPtr,), u),
ccall(sbml(:Unit_getMultiplier), Cdouble, (VPtr,), u),
)
end for j = 0:ccall(sbml(:UnitDefinition_getNumUnits), Cuint, (VPtr,), ud)-1
end for j = 1:ccall(sbml(:UnitDefinition_getNumUnits), Cuint, (VPtr,), ud)
]
end
......@@ -62,14 +62,14 @@ function extractModel(mdl::VPtr)::Model
sbml(:Compartment_getId),
Cstring,
(VPtr,),
ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i),
ccall(sbml(:Model_getCompartment), VPtr, (VPtr, Cuint), mdl, i - 1),
),
) for i = 0:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl)-1
) for i = 1:ccall(sbml(:Model_getNumCompartments), Cuint, (VPtr,), mdl)
]
species = Dict{String,Species}()
for i = 0:ccall(sbml(:Model_getNumSpecies), Cuint, (VPtr,), mdl)-1
sp = ccall(sbml(:Model_getSpecies), VPtr, (VPtr, Cuint), mdl, i)
for i = 1:ccall(sbml(:Model_getNumSpecies), Cuint, (VPtr,), mdl)
sp = ccall(sbml(:Model_getSpecies), VPtr, (VPtr, Cuint), mdl, i - 1)
species[unsafe_string(ccall(sbml(:Species_getId), Cstring, (VPtr,), sp))] = Species(
unsafe_string(ccall(sbml(:Species_getName), Cstring, (VPtr,), sp)),
unsafe_string(ccall(sbml(:Species_getCompartment), Cstring, (VPtr,), sp)),
......@@ -77,24 +77,29 @@ function extractModel(mdl::VPtr)::Model
end
reactions = Dict{String,Reaction}()
for i = 0:ccall(sbml(:Model_getNumReactions), Cuint, (VPtr,), mdl)-1
re = ccall(sbml(:Model_getReaction), VPtr, (VPtr, Cuint), mdl, i)
kl = ccall(sbml(:Reaction_getKineticLaw), VPtr, (VPtr,), re)
for i = 1:ccall(sbml(:Model_getNumReactions), Cuint, (VPtr,), mdl)
re = ccall(sbml(:Model_getReaction), VPtr, (VPtr, Cuint), mdl, i - 1)
lb = (-Inf, "")
ub = (Inf, "")
oc = 0.0
for j = 0:ccall(sbml(:KineticLaw_getNumParameters), Cuint, (VPtr,), kl)-1
p = ccall(sbml(:KineticLaw_getParameter), VPtr, (VPtr, Cuint), kl, j)
id = unsafe_string(ccall(sbml(:Parameter_getId), Cstring, (VPtr,), p))
pval = () -> ccall(sbml(:Parameter_getValue), Cdouble, (VPtr,), p)
punit =
() -> unsafe_string(ccall(sbml(:Parameter_getUnits), Cstring, (VPtr,), p))
if id == "LOWER_BOUND"
lb = (pval(), punit())
elseif id == "UPPER_BOUND"
ub = (pval(), punit())
elseif id == "OBJECTIVE_COEFFICIENT"
oc = pval()
kl = ccall(sbml(:Reaction_getKineticLaw), VPtr, (VPtr,), re)
if kl != C_NULL
for j = 1:ccall(sbml(:KineticLaw_getNumParameters), Cuint, (VPtr,), kl)
p = ccall(sbml(:KineticLaw_getParameter), VPtr, (VPtr, Cuint), kl, j - 1)
id = unsafe_string(ccall(sbml(:Parameter_getId), Cstring, (VPtr,), p))
pval = () -> ccall(sbml(:Parameter_getValue), Cdouble, (VPtr,), p)
punit =
() ->
unsafe_string(ccall(sbml(:Parameter_getUnits), Cstring, (VPtr,), p))
if id == "LOWER_BOUND"
lb = (pval(), punit())
elseif id == "UPPER_BOUND"
ub = (pval(), punit())
elseif id == "OBJECTIVE_COEFFICIENT"
oc = pval()
end
end
end
......@@ -107,13 +112,13 @@ function extractModel(mdl::VPtr)::Model
ccall(sbml(:SpeciesReference_getStoichiometry), Cdouble, (VPtr,), sr) *
factor
for j = 0:ccall(sbml(:Reaction_getNumReactants), Cuint, (VPtr,), re)-1
sr = ccall(sbml(:Reaction_getReactant), VPtr, (VPtr, Cuint), re, j)
for j = 1:ccall(sbml(:Reaction_getNumReactants), Cuint, (VPtr,), re)
sr = ccall(sbml(:Reaction_getReactant), VPtr, (VPtr, Cuint), re, j - 1)
add_stoi(sr, -1)
end
for j = 0:ccall(sbml(:Reaction_getNumProducts), Cuint, (VPtr,), re)-1
sr = ccall(sbml(:Reaction_getProduct), VPtr, (VPtr, Cuint), re, j)
for j = 1:ccall(sbml(:Reaction_getNumProducts), Cuint, (VPtr,), re)
sr = ccall(sbml(:Reaction_getProduct), VPtr, (VPtr, Cuint), re, j - 1)
add_stoi(sr, 1)
end
......
sbmlfile = "EColi.xml"
sbmlfile = "Ec_core_flux1.xml"
if !isfile(sbmlfile)
download("http://systemsbiology.ucsd.edu/sites/systemsbiology.ucsd.edu/files/Attachments/Images/InSilicoOrganisms/Ecoli/Ecoli_SBML/Ec_core_flux1.xml", sbmlfile)
......@@ -10,11 +10,12 @@ if cksum != "01a883b364fa60582101ca1e270515e7fcb3fb2f60084d92e5ee45f9f72bbe50"
@warn "The downloaded E Coli core flux model seems to be different from the expected one. Tests will likely fail." cksum
end
@testset "SBML model loading" begin
@testset "SBML flux model loading" begin
mdl = readSBML(sbmlfile)
@test typeof(mdl) == Model
@info "The next warning is an expected side-effect of testing an error condition"
@test_throws AssertionError readSBML(sbmlfile * ".does.not.really.exist")
@test length(mdl.compartments) == 2
......
sbmlfiles = [
# a test model from BIGG
("e_coli_core.xml",
"http://bigg.ucsd.edu/static/models/e_coli_core.xml",
"b4db506aeed0e434c1f5f1fdd35feda0dfe5d82badcfda0e9d1342335ab31116",
72,
95),
# a relatively new non-curated model from biomodels
("T1M1133.xml",
"https://www.ebi.ac.uk/biomodels/model/download/MODEL1909260004.4?filename=T1M1133.xml",
"2b1e615558b6190c649d71052ac9e0dc1635e3ad281e541bc7d4fdf2892a5967",
2517,
3956),
# a curated model from biomodels
("Dasgupta2020.xml",
"https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000973.3?filename=Dasgupta2020.xml",
"958b131d4df2f215dae68255433542f228601db0326d26a54efd08ddcf823489",
2, 6),
]
@testset "Loading of models from various sources" begin
for (sbmlfile, url, hash, expected_mets, expected_rxns) in sbmlfiles
if !isfile(sbmlfile)
download(url, sbmlfile)
end
cksum = bytes2hex(sha256(open(sbmlfile)))
if cksum != hash
@warn "The downloaded model `$sbmlfile' seems to be different from the expected one. Tests will likely fail." cksum
end
@testset "Loading of $sbmlfile" begin
mdl = readSBML(sbmlfile)
@test typeof(mdl) == Model
mets, rxns, _ = getS(mdl)
@test length(mets) == expected_mets
@test length(rxns) == expected_rxns
end
end
end
......@@ -5,5 +5,6 @@ import Pkg
@testset "SBML test suite" begin
include("version.jl")
include("loadEColi.jl")
include("ecoli_flux.jl")
include("loadmodels.jl")
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