Skip to content

Commit 1c7c5e3

Browse files
authored
Merge pull request #255 from LCSB-BioCore/mk-fix-event-ids
Fix non-mandatory event IDs
2 parents a30bd51 + df38e09 commit 1c7c5e3

6 files changed

Lines changed: 62 additions & 15 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SBML"
22
uuid = "e5567a89-2604-4b09-9718-f5f78e97c3bb"
33
authors = ["Mirek Kratochvil <miroslav.kratochvil@uni.lu>", "LCSB R3 team <lcsb-r3@uni.lu>"]
4-
version = "1.4.4"
4+
version = "1.5.0"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

docs/src/assets/unilu.svg

Lines changed: 31 additions & 8 deletions
Loading

src/readsbml.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function get_model(mdl::VPtr)::SBML.Model
630630
end
631631

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

666-
events[unsafe_string(ccall(sbml(:Event_getId), Cstring, (VPtr,), ev))] =
667-
SBML.Event(;
666+
push!(
667+
events,
668+
get_optional_string(ev, :Event_getId) => SBML.Event(;
668669
use_values_from_trigger_time = ccall(
669670
sbml(:Event_getUseValuesFromTriggerTime),
670671
Cint,
@@ -674,7 +675,8 @@ function get_model(mdl::VPtr)::SBML.Model
674675
name = get_optional_string(ev, :Event_getName),
675676
trigger,
676677
event_assignments,
677-
)
678+
),
679+
)
678680
end
679681

680682
# Rules

src/structs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ Base.@kwdef struct Model
471471
active_objective::Maybe{String} = nothing
472472
gene_products::Dict{String,GeneProduct} = Dict()
473473
function_definitions::Dict{String,FunctionDefinition} = Dict()
474-
events::Dict{String,Event} = Dict()
474+
events::Vector{Pair{Maybe{String},Event}} = Pair{Maybe{String},Event}[]
475475
name::Maybe{String} = nothing
476476
id::Maybe{String} = nothing
477477
metaid::Maybe{String} = nothing

src/writesbml.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr
456456
# Add events
457457
for (id, event) in mdl.events
458458
event_ptr = ccall(sbml(:Model_createEvent), VPtr, (VPtr,), model)
459-
set_string!(event_ptr, :Event_setId, id)
459+
isnothing(id) || set_string!(event_ptr, :Event_setId, id)
460460
set_bool!(
461461
event_ptr,
462462
:Event_setUseValuesFromTriggerTime,

test/loaddynamicmodels.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ sbmlfiles = [
5858
("reaction1", SBML.MathApply("*", [SBML.MathApply("*", [compartment, k2]), S1])),
5959
("S1", 0.01125),
6060
),
61+
# case 00928 with an ID-less event
62+
(
63+
joinpath(@__DIR__, "data", "00928-sbml-l3v2.xml"),
64+
SBML.test_suite_url(928, level = 3, version = 2),
65+
"d2a95aee820712696a2056bb09fd7d3befcd99e331809105e12ee081073a4985",
66+
x -> nothing,
67+
1,
68+
(
69+
"reaction1",
70+
SBML.MathApply(
71+
"*",
72+
SBML.Math[
73+
SBML.MathApply(
74+
"*",
75+
SBML.Math[SBML.MathIdent("C"), SBML.MathIdent("k1")],
76+
),
77+
SBML.MathIdent("S1"),
78+
],
79+
),
80+
),
81+
("S1", 0.0),
82+
),
6183
]
6284

6385
@testset "Loading of models from sbml_test_suite" begin

0 commit comments

Comments
 (0)