Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
54b60a1c
Commit
54b60a1c
authored
Jul 15, 2021
by
Miroslav Kratochvil
Browse files
allow switching off reporting of certain error severities
fixes terminal flood on many existing models
parent
1d41046a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/readsbml.jl
View file @
54b60a1c
...
@@ -72,7 +72,11 @@ function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
...
@@ -72,7 +72,11 @@ function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
end
end
"""
"""
function readSBML(fn::String, sbml_conversion = model->nothing)::SBML.Model
readSBML(
fn::String,
sbml_conversion = document -> nothing;
report_severities = ["
Fatal
", "
Error
"],
)::SBML.Model
Read the SBML from a XML file in `fn` and return the contained `SBML.Model`.
Read the SBML from a XML file in `fn` and return the contained `SBML.Model`.
...
@@ -82,6 +86,9 @@ single parameter, which is the C pointer to the loaded SBML document (C type
...
@@ -82,6 +86,9 @@ single parameter, which is the C pointer to the loaded SBML document (C type
[`set_level_and_version`](@ref), [`libsbml_convert`](@ref), and
[`set_level_and_version`](@ref), [`libsbml_convert`](@ref), and
[`convert_simplify_math`](@ref).
[`convert_simplify_math`](@ref).
`report_severities` switches on and off reporting of certain errors; see the
documentation of [`get_error_messages`](@ref) for details.
# Example
# Example
```
```
m = readSBML("
my_model
.
xml
", doc -> begin
m = readSBML("
my_model
.
xml
", doc -> begin
...
@@ -90,10 +97,18 @@ m = readSBML("my_model.xml", doc -> begin
...
@@ -90,10 +97,18 @@ m = readSBML("my_model.xml", doc -> begin
end)
end)
```
```
"""
"""
function
readSBML
(
fn
::
String
,
sbml_conversion
=
document
->
nothing
)
::
SBML
.
Model
function
readSBML
(
fn
::
String
,
sbml_conversion
=
document
->
nothing
;
report_severities
=
[
"Fatal"
,
"Error"
],
)
::
SBML
.
Model
doc
=
ccall
(
sbml
(
:
readSBML
),
VPtr
,
(
Cstring
,),
fn
)
doc
=
ccall
(
sbml
(
:
readSBML
),
VPtr
,
(
Cstring
,),
fn
)
try
try
get_error_messages
(
doc
,
AssertionError
(
"Opening SBML document has reported errors"
))
get_error_messages
(
doc
,
AssertionError
(
"Opening SBML document has reported errors"
),
report_severities
,
)
sbml_conversion
(
doc
)
sbml_conversion
(
doc
)
...
...
src/utils.jl
View file @
54b60a1c
...
@@ -132,12 +132,15 @@ function extensive_kinetic_math(m::SBML.Model, formula::SBML.Math)
...
@@ -132,12 +132,15 @@ function extensive_kinetic_math(m::SBML.Model, formula::SBML.Math)
end
end
"""
"""
get_error_messages(doc::Ptr
{Cvoid}
, error::Exception)
get_error_messages(doc::
V
Ptr, error::Exception
, report_severities
)
Show the error messages reported by SBML in the `doc` document and throw the
Show the error messages reported by SBML in the `doc` document and throw the
`error` if they are more than 1.
`error` if they are more than 1.
`report_severities` switches the reporting of certain error types defined by
libsbml; you can choose from `["
Fatal
", "
Error
", "
Warning
", "
Informational
"]`.
"""
"""
function
get_error_messages
(
doc
::
VPtr
,
error
::
Exception
)
function
get_error_messages
(
doc
::
VPtr
,
error
::
Exception
,
report_severities
)
n_errs
=
ccall
(
sbml
(
:
SBMLDocument_getNumErrors
),
Cuint
,
(
VPtr
,),
doc
)
n_errs
=
ccall
(
sbml
(
:
SBMLDocument_getNumErrors
),
Cuint
,
(
VPtr
,),
doc
)
do_throw
=
false
do_throw
=
false
for
i
=
1
:
n_errs
for
i
=
1
:
n_errs
...
@@ -146,15 +149,15 @@ function get_error_messages(doc::VPtr, error::Exception)
...
@@ -146,15 +149,15 @@ function get_error_messages(doc::VPtr, error::Exception)
sev
=
string
(
strip
(
get_string
(
err
,
:
XMLError_getSeverityAsString
)))
sev
=
string
(
strip
(
get_string
(
err
,
:
XMLError_getSeverityAsString
)))
# keywords from `libsbml/src/sbml/xml/XMLError.cpp` xmlSeverityStringTable:
# keywords from `libsbml/src/sbml/xml/XMLError.cpp` xmlSeverityStringTable:
if
sev
==
"Fatal"
if
sev
==
"Fatal"
@error
"SBML reported fatal error:
$(msg)
"
sev
in
report_severities
&&
@error
"SBML reported fatal error:
$(msg)
"
do_throw
=
true
do_throw
=
true
elseif
sev
==
"Error"
elseif
sev
==
"Error"
@error
"SBML reported error:
$(msg)
"
sev
in
report_severities
&&
@error
"SBML reported error:
$(msg)
"
do_throw
=
true
do_throw
=
true
elseif
sev
==
"Warning"
elseif
sev
==
"Warning"
@warn
"SBML reported warning:
$(msg)
"
sev
in
report_severities
&&
@warn
"SBML reported warning:
$(msg)
"
else
#
sev=="Informational"
else
if
sev
==
"Informational"
@info
"SBML reported:
$(msg)
"
sev
in
report_severities
&&
@info
"SBML reported:
$(msg)
"
end
end
end
end
do_throw
&&
throw
(
error
)
do_throw
&&
throw
(
error
)
...
@@ -162,7 +165,12 @@ function get_error_messages(doc::VPtr, error::Exception)
...
@@ -162,7 +165,12 @@ function get_error_messages(doc::VPtr, error::Exception)
end
end
"""
"""
check_errors(success::Integer, doc::Ptr{Cvoid}, error::Exception)
check_errors(
success::Integer,
doc::VPtr,
error::Exception,
report_severities = ["
Fatal
", "
Error
"],
)
If success is a 0-valued `Integer` (a logical `false`), then call
If success is a 0-valued `Integer` (a logical `false`), then call
[`get_error_messages`](@ref) to show the error messages reported by SBML in the
[`get_error_messages`](@ref) to show the error messages reported by SBML in the
...
@@ -170,5 +178,9 @@ If success is a 0-valued `Integer` (a logical `false`), then call
...
@@ -170,5 +178,9 @@ If success is a 0-valued `Integer` (a logical `false`), then call
typically the value returned by an SBML C function operating on `doc` which
typically the value returned by an SBML C function operating on `doc` which
returns a boolean flag to signal a successful operation.
returns a boolean flag to signal a successful operation.
"""
"""
check_errors
(
success
::
Integer
,
doc
::
VPtr
,
error
::
Exception
)
=
check_errors
(
Bool
(
success
)
||
get_error_messages
(
doc
,
error
)
success
::
Integer
,
doc
::
VPtr
,
error
::
Exception
,
report_severities
=
[
"Fatal"
,
"Error"
],
)
=
Bool
(
success
)
||
get_error_messages
(
doc
,
error
,
report_severities
)
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