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

prepare a macro for inheriting the accessors for model data #588

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/base/macros/model_wrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
@_inherit_model_methods

Generates trivial accessor functions listed in `fns` for a model that is
wrapped in type `mtype` as field `member`.
"""
macro _inherit_model_methods(mtype::Symbol, arglist, member::Symbol, fwdlist, fns...)
Expr(
:block,
(
begin
header = Expr(:call, fn, :(model::$mtype), arglist.args...)
call = Expr(:call, fn, :(model.$member), fwdlist.args...)
esc(
Expr(
:macrocall,
Symbol("@doc"),
__source__,
"""
$header

Evaluates [`$fn`](@ref) on the model contained in $mtype.
""",
Expr(:(=), header, Expr(:block, __source__, call)),
),
)
end for fn in fns
)...,
)
end
4 changes: 2 additions & 2 deletions src/base/macros/serialized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@_serialized_change_unwrap function

Creates a simple wrapper structure that calls the `function` transparently on
the internal precached model. Internal type is returned (because this would
break the consistency of serialization).
the internal precached model. The internal type is returned (otherwise this
would break the consistency of serialization).
"""
macro _serialized_change_unwrap(fn::Symbol)
docstring = """
Expand Down
82 changes: 3 additions & 79 deletions src/base/types/CoreModelCoupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,7 @@ mutable struct CoreModelCoupled <: MetabolicModel
end
end

"""
reactions(a::CoreModelCoupled)

Extract reactions from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
reactions(a::CoreModelCoupled) = reactions(a.lm)

"""
metabolites(a::CoreModelCoupled)

Extract metabolites from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
metabolites(a::CoreModelCoupled) = metabolites(a.lm)

"""
stoichiometry(a::CoreModelCoupled)

Extract stoichiometry from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
stoichiometry(a::CoreModelCoupled) = stoichiometry(a.lm)

"""
bounds(a::CoreModelCoupled)

Extract bounds from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
bounds(a::CoreModelCoupled) = bounds(a.lm)

"""
balance(a::CoreModelCoupled)

Extract balance from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
balance(a::CoreModelCoupled) = balance(a.lm)

"""
objective(a::CoreModelCoupled)

Extract objective from [`CoreModelCoupled`](@ref) (uses the internal
[`CoreModel`](@ref)).
"""
objective(a::CoreModelCoupled) = objective(a.lm)
@_inherit_model_methods CoreModelCoupled () lm () reactions metabolites stoichiometry bounds balance objective

"""
coupling(a::CoreModelCoupled)::SparseMat
Expand All @@ -92,21 +46,8 @@ Coupling bounds for a `CoreModelCoupled`.
"""
coupling_bounds(a::CoreModelCoupled)::Tuple{Vector{Float64},Vector{Float64}} = (a.cl, a.cu)

"""
reaction_stoichiometry(model::CoreModelCoupled, rid::String)::Dict{String, Float64}

Return the stoichiometry of reaction with ID `rid`.
"""
reaction_stoichiometry(m::CoreModelCoupled, rid::String) = reaction_stoichiometry(m.lm, rid)

"""
reaction_stoichiometry(model::CoreModelCoupled, ridx)::Dict{String, Float64}

Return the stoichiometry of reaction at index `ridx`.
"""
function reaction_stoichiometry(m::CoreModelCoupled, ridx)::Dict{String,Float64}
reaction_stoichiometry(m.lm, ridx)
end
@_inherit_model_methods CoreModelCoupled (rid::String,) lm (rid,) reaction_stoichiometry reaction_gene_association
@_inherit_model_methods CoreModelCoupled (ridx::Int,) lm (ridx,) reaction_stoichiometry

"""
reaction_gene_association_vec(model::CoreModelCoupled)::Vector{Maybe{GeneAssociation}}
Expand All @@ -117,23 +58,6 @@ same order as `reactions(model)`.
reaction_gene_association_vec(model::CoreModelCoupled)::Vector{Maybe{GeneAssociation}} =
reaction_gene_association_vec(model.lm)

"""
reaction_gene_association(model::CoreModelCoupled, ridx::Int)::Maybe{GeneAssociation}

Retrieve the [`GeneAssociation`](@ref) from [`CoreModelCoupled`](@ref) by reaction
index.
"""
reaction_gene_association(model::CoreModelCoupled, ridx::Int)::Maybe{GeneAssociation} =
reaction_gene_association(model.lm, ridx)

"""
reaction_gene_association(model::CoreModelCoupled, rid::String)::Maybe{GeneAssociation}

Retrieve the [`GeneAssociation`](@ref) from [`CoreModelCoupled`](@ref) by reaction ID.
"""
reaction_gene_association(model::CoreModelCoupled, rid::String)::Maybe{GeneAssociation} =
reaction_gene_association(model.lm, rid)

"""
Base.convert(::Type{CoreModelCoupled}, mm::MetabolicModel)

Expand Down