Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-mandatory event IDs #255

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SBML"
uuid = "e5567a89-2604-4b09-9718-f5f78e97c3bb"
authors = ["Mirek Kratochvil <[email protected]>", "LCSB R3 team <[email protected]>"]
version = "1.4.4"
version = "1.5.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
39 changes: 31 additions & 8 deletions docs/src/assets/unilu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions src/readsbml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function get_model(mdl::VPtr)::SBML.Model
end

# events
events = Dict{String,Event}()
events = Pair{Maybe{String},Event}[]
num_events = ccall(sbml(:Model_getNumEvents), Cuint, (VPtr,), mdl)
for n = 0:(num_events-1)
ev = ccall(sbml(:Model_getEvent), VPtr, (VPtr, Cuint), mdl, n)
Expand Down Expand Up @@ -663,8 +663,9 @@ function get_model(mdl::VPtr)::SBML.Model
math = trig_math_ptr == C_NULL ? nothing : parse_math(trig_math_ptr),
)

events[unsafe_string(ccall(sbml(:Event_getId), Cstring, (VPtr,), ev))] =
SBML.Event(;
push!(
events,
get_optional_string(ev, :Event_getId) => SBML.Event(;
use_values_from_trigger_time = ccall(
sbml(:Event_getUseValuesFromTriggerTime),
Cint,
Expand All @@ -674,7 +675,8 @@ function get_model(mdl::VPtr)::SBML.Model
name = get_optional_string(ev, :Event_getName),
trigger,
event_assignments,
)
),
)
end

# Rules
Expand Down
2 changes: 1 addition & 1 deletion src/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ Base.@kwdef struct Model
active_objective::Maybe{String} = nothing
gene_products::Dict{String,GeneProduct} = Dict()
function_definitions::Dict{String,FunctionDefinition} = Dict()
events::Dict{String,Event} = Dict()
events::Vector{Pair{Maybe{String},Event}} = Pair{Maybe{String},Event}[]
name::Maybe{String} = nothing
id::Maybe{String} = nothing
metaid::Maybe{String} = nothing
Expand Down
2 changes: 1 addition & 1 deletion src/writesbml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr
# Add events
for (id, event) in mdl.events
event_ptr = ccall(sbml(:Model_createEvent), VPtr, (VPtr,), model)
set_string!(event_ptr, :Event_setId, id)
isnothing(id) || set_string!(event_ptr, :Event_setId, id)
set_bool!(
event_ptr,
:Event_setUseValuesFromTriggerTime,
Expand Down
22 changes: 22 additions & 0 deletions test/loaddynamicmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ sbmlfiles = [
("reaction1", SBML.MathApply("*", [SBML.MathApply("*", [compartment, k2]), S1])),
("S1", 0.01125),
),
# case 00928 with an ID-less event
(
joinpath(@__DIR__, "data", "00928-sbml-l3v2.xml"),
SBML.test_suite_url(928, level = 3, version = 2),
"d2a95aee820712696a2056bb09fd7d3befcd99e331809105e12ee081073a4985",
x -> nothing,
1,
(
"reaction1",
SBML.MathApply(
"*",
SBML.Math[
SBML.MathApply(
"*",
SBML.Math[SBML.MathIdent("C"), SBML.MathIdent("k1")],
),
SBML.MathIdent("S1"),
],
),
),
("S1", 0.0),
),
]

@testset "Loading of models from sbml_test_suite" begin
Expand Down
Loading