Commit e8c48bb9 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

WIP: more type golfing

parent 6a61931c
Pipeline #48332 failed with stages
in 5 minutes and 58 seconds
...@@ -93,7 +93,7 @@ function flux_variability_analysis( ...@@ -93,7 +93,7 @@ function flux_variability_analysis(
end, end,
], ],
), ),
args = [-reactions reactions], args = [(x,) for x in [-reactions reactions]],
analysis = (_, opt_model, ridx) -> _max_variability_flux(opt_model, ridx, ret), analysis = (_, opt_model, ridx) -> _max_variability_flux(opt_model, ridx, ret),
workers = workers, workers = workers,
) )
......
""" """
_with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, modsname, fn) _screen_args(argtuple, kwargtuple, modsname)
Internal helper to check the presence and shape of modification and argument Internal helper to check the presence and shape of modification and argument
arrays in [`screen`](@ref) and pals. arrays in [`screen`](@ref) and pals.
""" """
function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, modsname, fn) function _screen_args(argtuple, kwargtuple, modsname)
mods = get(kwargtuple, modsname, nothing) mods = get(kwargtuple, modsname, nothing)
args = get(kwargtuple, :args, nothing) args = get(kwargtuple, :args, nothing)
...@@ -16,9 +16,9 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods ...@@ -16,9 +16,9 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods
DomainError(args, "at least one of `$modsname` and `args` must be defined"), DomainError(args, "at least one of `$modsname` and `args` must be defined"),
) )
end end
fn(argtuple...; kwargtuple..., NamedTuple([modsname => ([[] for _ in args])])) return NamedTuple{(modsname,)}(Ref([[] for _ in args]))
elseif isnothing(args) elseif isnothing(args)
fn(argtuple...; kwargtuple..., args = [() for _ in mods]) return (args = [() for _ in mods],)
else else
if size(mods) != size(args) if size(mods) != size(args)
throw( throw(
...@@ -28,18 +28,18 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods ...@@ -28,18 +28,18 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods
), ),
) )
end end
fn(argtuple...; kwargtuple...) return ()
end end
end end
""" """
screen( screen(
model::MetabolicModel; model::MetabolicModel;
variants::Array{Vector{Function}, N}, variants::Array{Vector}, N},
analysis::Function, analysis::Function,
args::Array{Vector{Tuple}, N}, args::Array{Vector{Tuple}, N},
workers = [myid()], workers = [myid()],
)::Array where N )::Array where {N}
Take an array of model-modifying function vectors in `variants`, and execute Take an array of model-modifying function vectors in `variants`, and execute
the function `analysis` on all variants of the `model` specified by `variants`. the function `analysis` on all variants of the `model` specified by `variants`.
...@@ -108,26 +108,26 @@ screen(m, ...@@ -108,26 +108,26 @@ screen(m,
``` ```
""" """
screen(args...; kwargs...) = screen(args...; kwargs...) =
_with_screen_args_checked(args, kwargs, :variants, _screen_impl) _screen_impl(args...; kwargs..., _screen_args(args, kwargs, :variants)...)
""" """
_screen_impl( _screen_impl(
model::MetabolicModel; model::MetabolicModel;
variants::Array{Vector{Function}, N}, variants::Array{Vector, N},
analysis::Function, analysis::Function,
args::Array{Vector{Tuple}, N}, args::Array{Tuple, N},
workers = [myid()], workers = [myid()],
)::Array where N )::Array where {N}
The actual implementation of [`screen`](@ref). The actual implementation of [`screen`](@ref).
""" """
function _screen_impl( function _screen_impl(
model::MetabolicModel; model::MetabolicModel;
variants::Array{Vector{Function},N}, variants::Array{V,N},
analysis::Function, analysis,
args::Array{Vector{Tuple},N}, args::Array{A,N},
workers = [myid()], workers = [myid()],
)::Array where {N} )::Array where {V <: AbstractVector,A,N}
map(fetch, save_at.(workers, :cobrexa_screen_variants_model, Ref(model))) map(fetch, save_at.(workers, :cobrexa_screen_variants_model, Ref(model)))
map(fetch, save_at.(workers, :cobrexa_screen_variants_analysis_fn, Ref(analysis))) map(fetch, save_at.(workers, :cobrexa_screen_variants_analysis_fn, Ref(analysis)))
...@@ -215,8 +215,8 @@ end ...@@ -215,8 +215,8 @@ end
screen_optmodel_modifications( screen_optmodel_modifications(
model::MetabolicModel, model::MetabolicModel,
optimizer; optimizer;
common_modifications::Vector{Function} = [], common_modifications::Vector = [],
modifications::Array{Vector{Function},N}, modifications::Array{Vector,N},
args::Array{Vector{Tuple},N}, args::Array{Vector{Tuple},N},
analysis::Function, analysis::Function,
workers = [myid()], workers = [myid()],
...@@ -247,20 +247,19 @@ that may be modified and acted upon. As an example, you can use modification ...@@ -247,20 +247,19 @@ that may be modified and acted upon. As an example, you can use modification
Note: This function is a thin argument-handling wrapper around Note: This function is a thin argument-handling wrapper around
[`_screen_optmodel_modifications_impl`](@ref). [`_screen_optmodel_modifications_impl`](@ref).
""" """
screen_optmodel_modifications(args...; kwargs...) = _with_screen_args_checked( screen_optmodel_modifications(args...; kwargs...) = _screen_optmodel_modifications_impl(
args, args...;
kwargs, kwargs...,
:modifications, _screen_args(args, kwargs, :modifications)...,
_screen_optmodel_modifications_impl,
) )
""" """
_screen_optmodel_modifications_impl( _screen_optmodel_modifications_impl(
model::MetabolicModel, model::MetabolicModel,
optimizer; optimizer;
common_modifications::Vector{Function} = [], common_modifications::Vector = [],
modifications::Array{Vector{Function},N}, modifications::Array{Vector,N},
args::Array{Vector{Tuple},N}, args::Array{Tuple,N},
analysis::Function, analysis::Function,
workers = [myid()], workers = [myid()],
) where N ) where N
...@@ -270,14 +269,12 @@ The actual implementation of [`screen_optmodel_modifications`](@ref). ...@@ -270,14 +269,12 @@ The actual implementation of [`screen_optmodel_modifications`](@ref).
function _screen_optmodel_modifications_impl( function _screen_optmodel_modifications_impl(
model::MetabolicModel, model::MetabolicModel,
optimizer; optimizer;
common_modifications::Vector{Function} = [], common_modifications::V = [],
modifications::Array{Vector{Function},N}, modifications::Array{V,N},
args::Array{Vector{Tuple},N}, args::Array{A,N},
analysis::Function, analysis::Function,
workers = [myid()], workers = [myid()],
) where {N} )::Array where {V <: AbstractVector,A,N}
(modifications, args) = _check_screen_mods_args(modifications, args, :modifications)
map( map(
fetch, fetch,
......
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