From eb702f7cd6bcee75bc0757d9d33761502231349f Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 28 Aug 2023 10:12:32 +0200 Subject: [PATCH 1/2] side fix of the unilu logo --- docs/src/assets/unilu.svg | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/src/assets/unilu.svg b/docs/src/assets/unilu.svg index 1e63bb53..a40f6a1b 100644 --- a/docs/src/assets/unilu.svg +++ b/docs/src/assets/unilu.svg @@ -1,8 +1,31 @@ - - - - - - - - + + + + + + + From df38e09007659d15eb51f46546c9ddb6ce821b9c Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 28 Aug 2023 10:30:51 +0200 Subject: [PATCH 2/2] remove the mandatory ID from the SBML events Closes #254 SBML says that IDs on events are actually not mandatory, this softens the data structure so that the ID-less events are supported. The vector-of-pairs implementation is chosen for backwards compatibility (iteration through a vector of pairs should work precisely like iteration through the dictionary that was there before). Notably, this might look like a breaking change _but_ it is not -- the main use case that is broken by this commit is indexing the events by ID, which was actually broken already. --- Project.toml | 2 +- src/readsbml.jl | 10 ++++++---- src/structs.jl | 2 +- src/writesbml.jl | 2 +- test/loaddynamicmodels.jl | 22 ++++++++++++++++++++++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 581ec26f..ef3dcffb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SBML" uuid = "e5567a89-2604-4b09-9718-f5f78e97c3bb" authors = ["Mirek Kratochvil ", "LCSB R3 team "] -version = "1.4.4" +version = "1.5.0" [deps] DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" diff --git a/src/readsbml.jl b/src/readsbml.jl index 70ac6b74..03cf15a9 100644 --- a/src/readsbml.jl +++ b/src/readsbml.jl @@ -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) @@ -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, @@ -674,7 +675,8 @@ function get_model(mdl::VPtr)::SBML.Model name = get_optional_string(ev, :Event_getName), trigger, event_assignments, - ) + ), + ) end # Rules diff --git a/src/structs.jl b/src/structs.jl index 26be394e..7ab121fb 100644 --- a/src/structs.jl +++ b/src/structs.jl @@ -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 diff --git a/src/writesbml.jl b/src/writesbml.jl index 99bf1f2f..5f7a3390 100644 --- a/src/writesbml.jl +++ b/src/writesbml.jl @@ -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, diff --git a/test/loaddynamicmodels.jl b/test/loaddynamicmodels.jl index f384808f..144795d1 100644 --- a/test/loaddynamicmodels.jl +++ b/test/loaddynamicmodels.jl @@ -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