Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expanding equations when passed to @reaction_network #1041

Merged
merged 15 commits into from
Sep 9, 2024
12 changes: 10 additions & 2 deletions src/dsl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))

# Get macro options.
if length(unique(arg.args[1] for arg in option_lines)) < length(option_lines)
error("Some options where given multiple times.")
error("Some options were given multiple times.")
end
options = Dict(map(arg -> Symbol(String(arg.args[1])[2:end]) => arg,
option_lines))
Expand Down Expand Up @@ -376,7 +376,8 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
push!(rxexprs.args, get_rxexprs(reaction))
end
for equation in equations
push!(rxexprs.args, equation)
equation = expand_equation_RHS!(equation)
push!(rxexprs.args, (equation))
isaacsas marked this conversation as resolved.
Show resolved Hide resolved
end

quote
Expand Down Expand Up @@ -915,6 +916,13 @@ function recursive_expand_functions!(expr::ExprValues)
expr
end

# Recursively expand the right-hand-side of an equation written using user-defined functions and special function calls like "hill(...)" with the actual corresponding expression.
function expand_equation_RHS!(eq::Expr)
rhs = recursive_expand_functions!(eq.args[3])
eq.args[3] = rhs
eq
end
isaacsas marked this conversation as resolved.
Show resolved Hide resolved

# Returns the length of a expression tuple, or 1 if it is not an expression tuple (probably a Symbol/Numerical).
function tup_leng(ex::ExprValues)
(typeof(ex) == Expr && ex.head == :tuple) && (return length(ex.args))
Expand Down
Loading