Skip to content

Commit 70ec8e3

Browse files
authored
Merge pull request #247 from LCSB-BioCore/mk-more-cvterms
support more CVTerms and annotations
2 parents 0eb0a44 + ec30ebe commit 70ec8e3

7 files changed

Lines changed: 140 additions & 42 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.1"
4+
version = "1.4.2"
55

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

src/readsbml.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ get_parameter(p::VPtr)::Pair{String,Parameter} =
298298
units = get_optional_string(p, :Parameter_getUnits),
299299
constant = get_optional_bool(p, :Parameter_isSetConstant, :Parameter_getConstant),
300300
metaid = get_optional_string(p, :SBase_getMetaId),
301+
notes = get_notes(p),
302+
annotation = get_annotation(p),
301303
sbo = get_sbo_term(p),
302304
cv_terms = get_cv_terms(p),
303305
)
@@ -611,9 +613,12 @@ function get_model(mdl::VPtr)::SBML.Model
611613
function_definitions[get_string(fd, :FunctionDefinition_getId)] =
612614
FunctionDefinition(
613615
name = get_optional_string(fd, :FunctionDefinition_getName),
616+
metaid = get_optional_string(fd, :SBase_getMetaId),
614617
body = def,
615618
notes = get_notes(fd),
616619
annotation = get_annotation(fd),
620+
sbo = get_sbo_term(fd),
621+
cv_terms = get_cv_terms(fd),
617622
)
618623
end
619624

@@ -744,5 +749,7 @@ function get_model(mdl::VPtr)::SBML.Model
744749
volume_units = get_optional_string(mdl, :Model_getVolumeUnits),
745750
notes = get_notes(mdl),
746751
annotation = get_annotation(mdl),
752+
sbo = get_sbo_term(mdl),
753+
cv_terms = get_cv_terms(mdl),
747754
)
748755
end

src/structs.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ Base.@kwdef struct Parameter
208208
units::Maybe{String} = nothing
209209
constant::Maybe{Bool} = nothing
210210
metaid::Maybe{String} = nothing
211+
notes::Maybe{String} = nothing
212+
annotation::Maybe{String} = nothing
211213
sbo::Maybe{String} = nothing
212214
cv_terms::Vector{CVTerm} = []
213215
end
@@ -389,9 +391,12 @@ $(TYPEDFIELDS)
389391
"""
390392
Base.@kwdef struct FunctionDefinition
391393
name::Maybe{String} = nothing
394+
metaid::Maybe{String} = nothing
392395
body::Maybe{Math} = nothing
393396
notes::Maybe{String} = nothing
394397
annotation::Maybe{String} = nothing
398+
sbo::Maybe{String} = nothing
399+
cv_terms::Vector{CVTerm} = []
395400
end
396401

397402
"""
@@ -479,4 +484,6 @@ Base.@kwdef struct Model
479484
volume_units::Maybe{String} = nothing
480485
notes::Maybe{String} = nothing
481486
annotation::Maybe{String} = nothing
487+
sbo::Maybe{String} = nothing
488+
cv_terms::Vector{CVTerm} = []
482489
end

src/writesbml.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ function set_parameter_ptr!(parameter_ptr::VPtr, id::String, parameter::Paramete
102102
set_string!(parameter_ptr, :Parameter_setUnits, parameter.units)
103103
add_cvterms!(parameter_ptr, parameter.cv_terms)
104104
set_bool!(parameter_ptr, :Parameter_setConstant, parameter.constant)
105+
set_string!(parameter_ptr, :SBase_setAnnotationString, parameter.annotation)
106+
set_string!(parameter_ptr, :SBase_setNotesString, parameter.notes)
105107
set_sbo_term!(parameter_ptr, parameter.sbo)
106108
return parameter_ptr
107109
end
@@ -429,6 +431,8 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr
429431
functiondefinition_ptr =
430432
ccall(sbml(:Model_createFunctionDefinition), VPtr, (VPtr,), model)
431433
set_string!(functiondefinition_ptr, :FunctionDefinition_setId, id)
434+
set_string!(functiondefinition_ptr, :SBase_setMetaId, func_def.metaid)
435+
add_cvterms!(functiondefinition_ptr, func_def.cv_terms)
432436
set_string!(functiondefinition_ptr, :FunctionDefinition_setName, func_def.name)
433437
isnothing(func_def.body) ||
434438
ccall(
@@ -441,6 +445,7 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr
441445
error("setting function definition math failed!")
442446
set_string!(functiondefinition_ptr, :SBase_setNotesString, func_def.notes)
443447
set_string!(functiondefinition_ptr, :SBase_setAnnotationString, func_def.annotation)
448+
set_sbo_term!(functiondefinition_ptr, func_def.sbo)
444449
end
445450

446451
# Add rules
@@ -506,8 +511,10 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr
506511
set_string!(model, :Model_setVolumeUnits, mdl.volume_units)
507512

508513
# Notes and annotations
514+
add_cvterms!(model, mdl.cv_terms)
509515
set_string!(model, :SBase_setNotesString, mdl.notes)
510516
set_string!(model, :SBase_setAnnotationString, mdl.annotation)
517+
set_sbo_term!(model, mdl.sbo)
511518

512519
# We can finally return the model
513520
return model

test/common.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const NON_ANNOTATED_TYPES = Union{
1414
SBML.Objective,
1515
SBML.RateRule,
1616
SBML.Trigger,
17-
SBML.UnitDefinition,
1817
}
1918
function Base.:(==)(a::T, b::T) where {T<:NON_ANNOTATED_TYPES}
2019
return getproperties(a) == getproperties(b)
@@ -26,9 +25,11 @@ const ANNOTATED_TYPES = Union{
2625
SBML.Compartment,
2726
SBML.FunctionDefinition,
2827
SBML.GeneProduct,
28+
SBML.Model,
2929
SBML.Parameter,
3030
SBML.Reaction,
3131
SBML.Species,
32+
SBML.UnitDefinition,
3233
}
3334
function Base.:(==)(a::T, b::T) where {T<:ANNOTATED_TYPES}
3435
nta = getproperties(a)

test/data/Dasgupta2020-written.xml

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ response to activation both in 2D and in 3D</p>
9797
</rdf:RDF>
9898
</annotation>
9999
<listOfFunctionDefinitions>
100-
<functionDefinition id="R3_flux" name="R3_flux">
100+
<functionDefinition metaid="COPASI18" id="R3_flux" name="R3_flux">
101101
<annotation>
102102
<COPASI xmlns="http://www.copasi.org/static/sbml">
103103
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
@@ -127,7 +127,7 @@ response to activation both in 2D and in 3D</p>
127127
</lambda>
128128
</math>
129129
</functionDefinition>
130-
<functionDefinition id="R4_flux" name="R4_flux">
130+
<functionDefinition metaid="COPASI19" id="R4_flux" name="R4_flux">
131131
<annotation>
132132
<COPASI xmlns="http://www.copasi.org/static/sbml">
133133
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
@@ -161,7 +161,7 @@ response to activation both in 2D and in 3D</p>
161161
</lambda>
162162
</math>
163163
</functionDefinition>
164-
<functionDefinition id="R5_flux" name="R5_flux">
164+
<functionDefinition metaid="COPASI20" id="R5_flux" name="R5_flux">
165165
<annotation>
166166
<COPASI xmlns="http://www.copasi.org/static/sbml">
167167
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
@@ -195,7 +195,7 @@ response to activation both in 2D and in 3D</p>
195195
</lambda>
196196
</math>
197197
</functionDefinition>
198-
<functionDefinition id="R2_flux" name="R2_flux">
198+
<functionDefinition metaid="COPASI17" id="R2_flux" name="R2_flux">
199199
<annotation>
200200
<COPASI xmlns="http://www.copasi.org/static/sbml">
201201
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
@@ -230,7 +230,7 @@ response to activation both in 2D and in 3D</p>
230230
</lambda>
231231
</math>
232232
</functionDefinition>
233-
<functionDefinition id="R1_flux" name="R1_flux">
233+
<functionDefinition metaid="COPASI21" id="R1_flux" name="R1_flux">
234234
<annotation>
235235
<COPASI xmlns="http://www.copasi.org/static/sbml">
236236
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
@@ -378,14 +378,116 @@ response to activation both in 2D and in 3D</p>
378378
</species>
379379
</listOfSpecies>
380380
<listOfParameters>
381-
<parameter metaid="COPASI10" id="p0" name="p0" value="10000" constant="true"/>
382-
<parameter metaid="COPASI8" id="k3" name="k3" value="1.16" constant="true"/>
383-
<parameter id="ModelValue_6" name="Initial for p0" value="10000" constant="true"/>
384-
<parameter metaid="COPASI7" id="k_2" name="k_2" value="0.03" constant="true"/>
385-
<parameter metaid="COPASI4" id="k1" name="k1" value="0.00021" constant="true"/>
386-
<parameter metaid="COPASI9" id="s" name="s" constant="false"/>
387-
<parameter metaid="COPASI5" id="k2" name="k2" value="7.5e-06" constant="true"/>
388-
<parameter metaid="COPASI6" id="k_1" name="k_1" value="6.6e-09" constant="true"/>
381+
<parameter metaid="COPASI10" id="p0" name="p0" value="10000" constant="true">
382+
<annotation>
383+
<COPASI xmlns="http://www.copasi.org/static/sbml">
384+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
385+
<rdf:Description rdf:about="#COPASI10">
386+
<dcterms:created>
387+
<rdf:Description>
388+
<dcterms:W3CDTF>2020-10-30T15:33:48Z</dcterms:W3CDTF>
389+
</rdf:Description>
390+
</dcterms:created>
391+
</rdf:Description>
392+
</rdf:RDF>
393+
</COPASI>
394+
</annotation>
395+
</parameter>
396+
<parameter metaid="COPASI8" id="k3" name="k3" value="1.16" constant="true">
397+
<annotation>
398+
<COPASI xmlns="http://www.copasi.org/static/sbml">
399+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
400+
<rdf:Description rdf:about="#COPASI8">
401+
<dcterms:created>
402+
<rdf:Description>
403+
<dcterms:W3CDTF>2020-10-30T15:33:19Z</dcterms:W3CDTF>
404+
</rdf:Description>
405+
</dcterms:created>
406+
</rdf:Description>
407+
</rdf:RDF>
408+
</COPASI>
409+
</annotation>
410+
</parameter>
411+
<parameter id="ModelValue_6" name="Initial for p0" value="10000" constant="true">
412+
<annotation>
413+
<initialValue xmlns="http://copasi.org/initialValue" parent="p0"/>
414+
</annotation>
415+
</parameter>
416+
<parameter metaid="COPASI7" id="k_2" name="k_2" value="0.03" constant="true">
417+
<annotation>
418+
<COPASI xmlns="http://www.copasi.org/static/sbml">
419+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
420+
<rdf:Description rdf:about="#COPASI7">
421+
<dcterms:created>
422+
<rdf:Description>
423+
<dcterms:W3CDTF>2020-10-30T15:33:17Z</dcterms:W3CDTF>
424+
</rdf:Description>
425+
</dcterms:created>
426+
</rdf:Description>
427+
</rdf:RDF>
428+
</COPASI>
429+
</annotation>
430+
</parameter>
431+
<parameter metaid="COPASI4" id="k1" name="k1" value="0.00021" constant="true">
432+
<annotation>
433+
<COPASI xmlns="http://www.copasi.org/static/sbml">
434+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
435+
<rdf:Description rdf:about="#COPASI4">
436+
<dcterms:created>
437+
<rdf:Description>
438+
<dcterms:W3CDTF>2020-10-30T15:32:40Z</dcterms:W3CDTF>
439+
</rdf:Description>
440+
</dcterms:created>
441+
</rdf:Description>
442+
</rdf:RDF>
443+
</COPASI>
444+
</annotation>
445+
</parameter>
446+
<parameter metaid="COPASI9" id="s" name="s" constant="false">
447+
<annotation>
448+
<COPASI xmlns="http://www.copasi.org/static/sbml">
449+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
450+
<rdf:Description rdf:about="#COPASI9">
451+
<dcterms:created>
452+
<rdf:Description>
453+
<dcterms:W3CDTF>2020-10-30T15:33:36Z</dcterms:W3CDTF>
454+
</rdf:Description>
455+
</dcterms:created>
456+
</rdf:Description>
457+
</rdf:RDF>
458+
</COPASI>
459+
</annotation>
460+
</parameter>
461+
<parameter metaid="COPASI5" id="k2" name="k2" value="7.5e-06" constant="true">
462+
<annotation>
463+
<COPASI xmlns="http://www.copasi.org/static/sbml">
464+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
465+
<rdf:Description rdf:about="#COPASI5">
466+
<dcterms:created>
467+
<rdf:Description>
468+
<dcterms:W3CDTF>2020-10-30T15:32:44Z</dcterms:W3CDTF>
469+
</rdf:Description>
470+
</dcterms:created>
471+
</rdf:Description>
472+
</rdf:RDF>
473+
</COPASI>
474+
</annotation>
475+
</parameter>
476+
<parameter metaid="COPASI6" id="k_1" name="k_1" value="6.6e-09" constant="true">
477+
<annotation>
478+
<COPASI xmlns="http://www.copasi.org/static/sbml">
479+
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
480+
<rdf:Description rdf:about="#COPASI6">
481+
<dcterms:created>
482+
<rdf:Description>
483+
<dcterms:W3CDTF>2020-10-30T15:32:52Z</dcterms:W3CDTF>
484+
</rdf:Description>
485+
</dcterms:created>
486+
</rdf:Description>
487+
</rdf:RDF>
488+
</COPASI>
489+
</annotation>
490+
</parameter>
389491
</listOfParameters>
390492
<listOfInitialAssignments>
391493
<initialAssignment symbol="ModelValue_6">

test/writemodels.jl

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,6 @@ end
6666
# re-read the unmodified model, fix constantness and compare again
6767
model = readSBML(file)
6868
fix_constant!(model)
69-
@test model.parameters == round_trip_model.parameters
70-
@test model.units == round_trip_model.units
71-
@test model.compartments == round_trip_model.compartments
72-
@test model.species == round_trip_model.species
73-
@test model.initial_assignments == round_trip_model.initial_assignments
74-
@test model.rules == round_trip_model.rules
75-
@test model.constraints == round_trip_model.constraints
76-
@test model.reactions == round_trip_model.reactions
77-
@test model.objectives == round_trip_model.objectives
78-
@test model.active_objective == round_trip_model.active_objective
79-
@test model.gene_products == round_trip_model.gene_products
80-
@test model.function_definitions == round_trip_model.function_definitions
81-
@test model.events == round_trip_model.events
82-
@test model.name == round_trip_model.name
83-
@test model.id == round_trip_model.id
84-
@test model.metaid == round_trip_model.metaid
85-
@test model.conversion_factor == round_trip_model.conversion_factor
86-
@test model.area_units == round_trip_model.area_units
87-
@test model.extent_units == round_trip_model.extent_units
88-
@test model.length_units == round_trip_model.length_units
89-
@test model.substance_units == round_trip_model.substance_units
90-
@test model.time_units == round_trip_model.time_units
91-
@test model.volume_units == round_trip_model.volume_units
92-
@test model.notes == round_trip_model.notes
93-
# We can't compare the two strings verbatim because `writeSBML` may write some
94-
# elements of the annotation in a slightly different order.
95-
@test isnothing(model.annotation) == isnothing(round_trip_model.annotation)
69+
@test model == round_trip_model
9670
end
9771
end

0 commit comments

Comments
 (0)