Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
84d39477
Unverified
Commit
84d39477
authored
Jun 11, 2021
by
Miroslav Kratochvil
Committed by
GitHub
Jun 11, 2021
Browse files
Merge pull request #55 from LCSB-BioCore/mk-conversions
add support for running SBML converters
parents
81d112ec
ac7485a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/SBML.jl
View file @
84d39477
...
...
@@ -5,13 +5,15 @@ using SparseArrays
include
(
"structs.jl"
)
include
(
"version.jl"
)
include
(
"readsbml.jl"
)
include
(
"converters.jl"
)
include
(
"math.jl"
)
include
(
"utils.jl"
)
sbml
=
(
sym
::
Symbol
)
->
dlsym
(
SBML_jll
.
libsbml_handle
,
sym
)
export
SBMLVersion
,
readSBML
,
getS
,
getLBs
,
getUBs
,
getOCs
export
SBMLVersion
,
readSBML
,
getS
,
getLBs
,
getUBs
,
getOCs
export
convert_level_and_version
,
libsbml_convert
,
convert_simplify_math
end
# module
src/converters.jl
0 → 100644
View file @
84d39477
"""
convert_level_and_version(level, version)
A converter to pass into [`readSBML`](@ref) that enforces certain SBML level
and version.
"""
convert_level_and_version
(
level
,
version
)
=
doc
->
begin
ccall
(
sbml
(
:
SBMLDocument_setLevelAndVersion
),
Cint
,
(
VPtr
,
Cint
,
Cint
),
doc
,
level
,
version
,
)
end
"""
libsbml_convert(conversion_options::Vector{Pair{String, Dict{String, String}}})
A converter that runs the SBML conversion routine, with specified conversion
options. The argument is a vector of pairs to allow specifying the order of
conversions.
"""
libsbml_convert
(
conversion_options
::
Vector
{
Pair
{
String
,
Dict
{
String
,
String
}}})
=
doc
->
begin
for
(
converter
,
options
)
in
conversion_options
props
=
ccall
(
sbml
(
:
ConversionProperties_create
),
VPtr
,
())
opt
=
ccall
(
sbml
(
:
ConversionOption_create
),
VPtr
,
(
Cstring
,),
converter
)
ccall
(
sbml
(
:
ConversionProperties_addOption
),
Cvoid
,
(
VPtr
,
VPtr
),
props
,
opt
)
for
(
k
,
v
)
in
options
opt
=
ccall
(
sbml
(
:
ConversionOption_create
),
VPtr
,
(
Cstring
,),
k
)
ccall
(
sbml
(
:
ConversionOption_setValue
),
Cvoid
,
(
VPtr
,
Cstring
),
opt
,
v
)
ccall
(
sbml
(
:
ConversionProperties_addOption
),
Cvoid
,
(
VPtr
,
VPtr
),
props
,
opt
,
)
end
ccall
(
sbml
(
:
SBMLDocument_convert
),
Cint
,
(
VPtr
,
VPtr
),
doc
,
props
)
end
end
"""
convert_simplify_math
Shortcut for [`libsbml_convert`](@ref) that expands functions, local
parameters, and initial assignments in the SBML document.
"""
convert_simplify_math
=
libsbml_convert
(
[
"promoteLocalParameters"
,
"expandFunctionDefinitions"
,
"setLevelAndVersion"
]
.=>
Ref
(
Dict
{
String
,
String
}()),
)
src/readsbml.jl
View file @
84d39477
...
...
@@ -75,11 +75,11 @@ function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
end
"""
function readSBML(fn::String)::SBML.Model
function readSBML(fn::String
, sbml_conversion = model->nothing
)::SBML.Model
Read the SBML from a XML file in `fn` and return the contained `SBML.Model`.
"""
function
readSBML
(
fn
::
String
)
::
SBML
.
Model
function
readSBML
(
fn
::
String
,
sbml_conversion
=
document
->
nothing
)
::
SBML
.
Model
doc
=
ccall
(
sbml
(
:
readSBML
),
VPtr
,
(
Cstring
,),
fn
)
try
n_errs
=
ccall
(
sbml
(
:
SBMLDocument_getNumErrors
),
Cuint
,
(
VPtr
,),
doc
)
...
...
@@ -92,6 +92,8 @@ function readSBML(fn::String)::SBML.Model
throw
(
AssertionError
(
"Opening SBML document has reported errors"
))
end
sbml_conversion
(
doc
)
if
0
==
ccall
(
sbml
(
:
SBMLDocument_isSetModel
),
Cint
,
(
VPtr
,),
doc
)
throw
(
AssertionError
(
"SBML document contains no model"
))
end
...
...
cylon-x
🤖
@cylon-x
mentioned in commit
780872af
·
Jun 11, 2021
mentioned in commit
780872af
mentioned in commit 780872afcfaa8f248a5e033eeb6770c9e4c3940b
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment