Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
2d847b13
Unverified
Commit
2d847b13
authored
Jul 19, 2021
by
Miroslav Kratochvil
🚴
Committed by
GitHub
Jul 19, 2021
Browse files
Merge pull request #128 from LCSB-BioCore/mk-relational-ops
fix parsing of relational operators
parents
63c09484
fba1a4fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/math.jl
View file @
2d847b13
...
...
@@ -16,6 +16,25 @@ parse_math_children(ast::VPtr)::Vector{Math} = [
i
=
1
:
ccall
(
sbml
(
:
ASTNode_getNumChildren
),
Cuint
,
(
VPtr
,),
ast
)
]
# Mapping of AST node type value subset to relational operations. Depends on
# `ASTNodeType.h` (also see below the case with AST_NAME_TIME)
const
relational_opers
=
Dict
{
Int32
,
String
}(
308
=>
"eq"
,
309
=>
"geq"
,
310
=>
"gt"
,
311
=>
"leq"
,
312
=>
"lt"
,
313
=>
"neq"
,
)
function
relational_oper
(
t
::
Int
)
haskey
(
relational_opers
,
t
)
||
throw
(
DomainError
(
t
,
"Unknown ASTNodeType value for relational operator"
))
relational_opers
[
t
]
end
"""
parse_math(ast::VPtr)::Math
...
...
@@ -42,11 +61,16 @@ function parse_math(ast::VPtr)::Math
return
MathVal
(
ccall
(
sbml
(
:
ASTNode_getReal
),
Cdouble
,
(
VPtr
,),
ast
))
elseif
ast_is
(
ast
,
:
ASTNode_isFunction
)
return
MathApply
(
get_string
(
ast
,
:
ASTNode_getName
),
parse_math_children
(
ast
))
elseif
ast_is
(
ast
,
:
ASTNode_isOperator
)
||
ast_is
(
ast
,
:
ASTNode_isRelational
)
elseif
ast_is
(
ast
,
:
ASTNode_isOperator
)
return
MathApply
(
string
(
Char
(
ccall
(
sbml
(
:
ASTNode_getCharacter
),
Cchar
,
(
VPtr
,),
ast
))),
parse_math_children
(
ast
),
)
elseif
ast_is
(
ast
,
:
ASTNode_isRelational
)
return
MathApply
(
relational_oper
(
Int
(
ccall
(
sbml
(
:
ASTNode_getType
),
Cint
,
(
VPtr
,),
ast
))),
parse_math_children
(
ast
),
)
elseif
ast_is
(
ast
,
:
ASTNode_isLambda
)
children
=
parse_math_children
(
ast
)
if
!
isempty
(
children
)
...
...
src/symbolics.jl
View file @
2d847b13
...
...
@@ -45,6 +45,7 @@ const default_symbolics_mapping = Dict{String,Any}(
"ln"
=>
:
log
,
"log"
=>
:
sbmlLog
,
"lt"
=>
:<
,
"neq"
=>
:
(
sbmlNeq
),
"piecewise"
=>
:
(
sbmlPiecewise
),
"power"
=>
:^
,
"root"
=>
:
sbmlRoot
,
...
...
@@ -66,6 +67,7 @@ function sbmlPiecewise(args...)
end
end
sbmlNeq
(
a
,
b
)
=
!
isequal
(
a
,
b
)
sbmlLog
(
x
)
=
log
(
x
,
10
)
sbmlLog
(
base
,
x
)
=
log
(
base
,
x
)
...
...
test/loadmodels.jl
View file @
2d847b13
...
...
@@ -56,6 +56,14 @@ sbmlfiles = [
0
,
0
,
),
# this contains a relational operator
(
joinpath
(
@__DIR__
,
"data"
,
"sbml00191.xml"
),
"https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/00191/00191-sbml-l3v2.xml"
,
"c474e94888767d70f9e9e03b32778f18069641563953de60dabac7daa7f481ce"
,
4
,
2
,
),
]
@testset
"Loading of models from various sources"
begin
...
...
@@ -163,3 +171,10 @@ end
@test
test_math
.
args
[
2
]
.
fn
==
"sin"
@test
test_math
.
args
[
2
]
.
args
[
1
]
.
val
==
2.1
end
@testset
"relational operators are decoded correctly"
begin
test_math
=
readSBML
(
joinpath
(
@__DIR__
,
"data"
,
"sbml00191.xml"
))
.
reactions
[
"reaction2"
]
.
kinetic_math
@test
test_math
.
args
[
2
]
.
fn
==
"geq"
end
cylon-x
🤖
@cylon-x
mentioned in commit
84fb2b54
·
Jul 19, 2021
mentioned in commit
84fb2b54
mentioned in commit 84fb2b549f70a67efaeca9d26c6983f92913b3ee
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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