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
a0326317
Commit
a0326317
authored
Jun 17, 2021
by
paulflang
Browse files
add sbml2symbolics conversion
parent
0949dfac
Changes
5
Hide whitespace changes
Inline
Side-by-side
Project.toml
View file @
a0326317
...
...
@@ -4,11 +4,13 @@ authors = ["Mirek Kratochvil <miroslav.kratochvil@uni.lu>", "LCSB R3 team <lcsb-
version
=
"0.5.0"
[deps]
IfElse
=
"615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Libdl
=
"8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg
=
"44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SBML_jll
=
"bb12108a-f4ef-5f88-8ef3-0b33ff7017f1"
SHA
=
"ea8e919c-243c-51af-8825-aaa63cd721ce"
SparseArrays
=
"2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Symbolics
=
"0c5d862f-8b57-4792-8d23-62f2024744c7"
Test
=
"8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
...
...
src/SBML.jl
View file @
a0326317
...
...
@@ -2,6 +2,7 @@ module SBML
using
SBML_jll
,
Libdl
,
Pkg
using
SparseArrays
using
Symbolics
include
(
"structs.jl"
)
include
(
"version.jl"
)
...
...
@@ -10,6 +11,7 @@ include("readsbml.jl")
include
(
"converters.jl"
)
include
(
"math.jl"
)
include
(
"utils.jl"
)
include
(
"sbml2symbolics.jl"
)
sbml
=
(
sym
::
Symbol
)
->
dlsym
(
SBML_jll
.
libsbml_handle
,
sym
)
...
...
src/sbml2symbolics.jl
0 → 100644
View file @
a0326317
@register
Base
.
factorial
(
x
)
# Todo: remove this line once factorial is registered per default
function
parse_piecewise
(
val
,
cond
,
other
)
IfElse
.
ifelse
(
cond
,
val
,
other
)
end
allowed_funs
=
Dict
(
# Operators
"+"
=>
:+
,
"-"
=>
:-
,
"*"
=>
:*
,
"/"
=>
:/
,
"power"
=>
:^
,
# Relational functions
"lt"
=>
:<
,
"leq"
=>
:<=
,
"geq"
=>
:>=
,
"gt"
=>
:>
,
# Other
"factorial"
=>
:
factorial
,
"ceiling"
=>
:
ceil
,
"floor"
=>
:
floor
,
"piecewise"
=>
SBML
.
parse_piecewise
,
#TODO add further translations of SBML functions to Julia
)
allowed_sym
(
x
)
=
haskey
(
allowed_funs
,
x
)
?
allowed_funs
[
x
]
:
throw
(
DomainError
(
x
,
"Unknown SBML function"
))
function
Base.convert
(
::
Type
{
Num
},
x
::
SBML
.
Math
)
conv
(
x
::
SBML
.
MathApply
)
=
eval
(
allowed_sym
(
x
.
fn
))(
conv
.
(
x
.
args
)
...
)
conv
(
x
::
SBML
.
MathIdent
)
=
Num
(
Variable
(
Symbol
(
x
.
id
)))
.
val
conv
(
x
::
SBML
.
MathVal
)
=
x
.
val
conv
(
x
::
SBML
.
MathLambda
)
=
throw
(
DomainError
(
x
,
"can't translate lambdas to symbolics"
))
conv
(
x
)
end
test/runtests.jl
View file @
a0326317
...
...
@@ -8,4 +8,5 @@ import Pkg
include
(
"version.jl"
)
include
(
"ecoli_flux.jl"
)
include
(
"loadmodels.jl"
)
include
(
"sbml2symbolics.jl"
)
end
test/sbml2symbolics.jl
0 → 100644
View file @
a0326317
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