Commit a0326317 authored by paulflang's avatar paulflang
Browse files

add sbml2symbolics conversion

parent 0949dfac
......@@ -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]
......
......@@ -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)
......
@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
......@@ -8,4 +8,5 @@ import Pkg
include("version.jl")
include("ecoli_flux.jl")
include("loadmodels.jl")
include("sbml2symbolics.jl")
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