Unverified Commit 3ee30322 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #107 from LCSB-BioCore/mk-cleaning-055

0.5.5 release prep (cleaning)
parents 9604c34a d62072fd
......@@ -59,6 +59,13 @@ julia> Matrix(S)
# Function reference
## Helper types
```@autodocs
Modules = [SBML]
Pages = ["types.jl"]
```
## Data structures
```@autodocs
......
......@@ -4,14 +4,15 @@ using SBML_jll, Libdl
using SparseArrays
using Symbolics
include("types.jl")
include("structs.jl")
include("version.jl")
include("utils.jl")
include("readsbml.jl")
include("converters.jl")
include("math.jl")
include("readsbml.jl")
include("symbolics.jl")
include("utils.jl")
sbml(sym::Symbol) = dlsym(SBML_jll.libsbml_handle, sym)
......
......@@ -6,11 +6,18 @@ A converter to pass into [`readSBML`](@ref) that enforces certain SBML level
and version.
"""
set_level_and_version(level, version) =
doc -> check_errors(ccall(sbml(:SBMLDocument_setLevelAndVersion), Cint,
(VPtr, Cint, Cint),
doc, level, version),
doc,
ErrorException("Setting of level and version did not succeed"))
doc -> check_errors(
ccall(
sbml(:SBMLDocument_setLevelAndVersion),
Cint,
(VPtr, Cint, Cint),
doc,
level,
version,
),
doc,
ErrorException("Setting of level and version did not succeed"),
)
"""
libsbml_convert(conversion_options::Vector{Pair{String, Dict{String, String}}})
......@@ -38,8 +45,11 @@ libsbml_convert(
opt,
)
end
check_errors(ccall(sbml(:SBMLDocument_convert), Cint, (VPtr, VPtr), doc, props),
doc, ErrorException("Conversion returned errors"))
check_errors(
ccall(sbml(:SBMLDocument_convert), Cint, (VPtr, VPtr), doc, props),
doc,
ErrorException("Conversion returned errors"),
)
end
end
......
......@@ -93,8 +93,7 @@ end)
function readSBML(fn::String, sbml_conversion = document -> nothing)::SBML.Model
doc = ccall(sbml(:readSBML), VPtr, (Cstring,), fn)
try
get_error_messages(doc,
AssertionError("Opening SBML document has reported errors"))
get_error_messages(doc, AssertionError("Opening SBML document has reported errors"))
sbml_conversion(doc)
......
"""
Maybe{X}
Type shortcut for "`X` or nothing" or "nullable `X`" in javaspeak. Name
got inspired by our functional friends.
"""
const Maybe{X} = Union{Nothing,X}
"""
Part of a measurement unit definition that corresponds to the SBML definition
of `Unit`. For example, the unit "per square megahour", Mh^(-2), is written as:
......
"""
Maybe{X}
Type shortcut for "`X` or nothing" or "nullable `X`" in javaspeak. Name
got inspired by our functional friends.
"""
const Maybe{X} = Union{Nothing,X}
"""
VPtr
A convenience wrapper for "any" (C `void`) pointer.
"""
const VPtr = Ptr{Cvoid}
const VPtr = Ptr{Cvoid}
"""
function getS(m::SBML.Model; zeros=spzeros)::Tuple{Vector{String},Vector{String},AbstractMatrix{Float64}}
......@@ -142,7 +140,7 @@ Show the error messages reported by SBML in the `doc` document and throw the
function get_error_messages(doc::VPtr, error::Exception)
n_errs = ccall(sbml(:SBMLDocument_getNumErrors), Cuint, (VPtr,), doc)
for i = 1:n_errs
err = ccall(sbml(:SBMLDocument_getError), VPtr, (VPtr, Cuint), doc, i-1)
err = ccall(sbml(:SBMLDocument_getError), VPtr, (VPtr, Cuint), doc, i - 1)
msg = string(strip(get_string(err, :XMLError_getMessage)))
@error "SBML reported error: $(msg)"
end
......
......@@ -134,7 +134,7 @@ end
@test isequal(convert(Num, m.reactions["J29"].kinetic_math), 2.0 * S29 * S29b)
end
@testset "converters fail gracefully" begin
@testset "converters work and fail gracefully" begin
@test_logs (:error, r"^SBML reported error:") (:error, r"^SBML reported error:") @test_throws ErrorException readSBML(
joinpath(@__DIR__, "data", "sbml01289.xml"),
doc -> begin
......@@ -142,4 +142,13 @@ end
convert_simplify_math(doc)
end,
)
test_math =
readSBML(
joinpath(@__DIR__, "data", "sbml01565.xml"),
libsbml_convert("expandInitialAssignments"),
).reactions["J31"].kinetic_math
@test test_math.args[2].fn == "sin"
@test test_math.args[2].args[1].val == 2.1
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment