From dfa346ebe6eddb4d79c063a7da432f40b74d2a8c Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil <miroslav.kratochvil@uni.lu> Date: Mon, 18 Oct 2021 14:57:25 +0200 Subject: [PATCH] add unwrapping model modifications for Serialized model --- src/base/macros/serialized.jl | 17 +++++++++++++++++ src/reconstruction/SerializedModel.jl | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/base/macros/serialized.jl create mode 100644 src/reconstruction/SerializedModel.jl diff --git a/src/base/macros/serialized.jl b/src/base/macros/serialized.jl new file mode 100644 index 000000000..f2c654df7 --- /dev/null +++ b/src/base/macros/serialized.jl @@ -0,0 +1,17 @@ +""" + _serialized_change_unwrap(fn::Symbol) + +Creates a simple wrapper structure that calls a function transparently on the +internal precached model. Internal type is returned (because this would break +the consistency of serialization). +""" +macro _serialized_change_unwrap(fn::Symbol) + docstring = """ + $fn(model::Serialized, ...) + + Calls [$fn](@ref) of the internal serialized model type. + Returns the modified un-serialized model. + """ + :(@doc $docstring $fn(model::Serialized, args...; kwargs...) = + $fn(unwrap_serialized(model), args...; kwargs...)) +end diff --git a/src/reconstruction/SerializedModel.jl b/src/reconstruction/SerializedModel.jl new file mode 100644 index 000000000..1ded654ad --- /dev/null +++ b/src/reconstruction/SerializedModel.jl @@ -0,0 +1,20 @@ + +# this just generates the necessary wrappers + +@_serialized_change_unwrap change_bound +@_serialized_change_unwrap change_bounds +@_serialized_change_unwrap add_reaction +@_serialized_change_unwrap remove_reaction +@_serialized_change_unwrap remove_reactions +@_serialized_change_unwrap remove_metabolite +@_serialized_change_unwrap remove_metabolites + +""" + unwrap_serialized(model::Serialized) + +Returns the model stored in the serialized structure. +""" +function unwrap_serialized(model::Serialized) + precache!(model) + model.m +end -- GitLab