Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
COBREXA.jl
Commits
3ae6fbff
Commit
3ae6fbff
authored
Oct 14, 2021
by
Miroslav Kratochvil
Committed by
Miroslav Kratochvil
Oct 15, 2021
Browse files
fix API of screen() to avoid unbounded type parameters
parent
0a220c9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/analysis/flux_variability_analysis.jl
View file @
3ae6fbff
...
...
@@ -93,7 +93,7 @@ function flux_variability_analysis(
end
,
],
),
args
=
[
-
reactions
reactions
],
args
=
[(
x
,)
for
x
in
[
-
reactions
reactions
]
]
,
analysis
=
(
_
,
opt_model
,
ridx
)
->
_max_variability_flux
(
opt_model
,
ridx
,
ret
),
workers
=
workers
,
)
...
...
src/analysis/screening.jl
View file @
3ae6fbff
"""
_check
_screen_
mods_args(mods, args
, modsname)
_screen_
args(argtuple, kwargtuple
, modsname)
Internal helper to check the presence and shape of modification and argument
arrays in [`screen`](@ref) and pals.
"""
function
_check
_screen_
mods_
args
(
mods
::
Maybe
{
Array
{
V
,
N
}},
args
::
Maybe
{
Array
{
A
,
N
}},
modsname
,
)
where
{
V
,
A
,
N
}
function
_screen_args
(
argtuple
,
kwargtuple
,
modsname
)
mods
=
get
(
kwargtuple
,
modsname
,
nothing
)
args
=
get
(
kwargtuple
,
:
args
,
nothing
)
if
isnothing
(
mods
)
if
isnothing
(
args
)
throw
(
DomainError
(
args
,
"at least one of `
$
modsname` and `args` must be non-empty"
,
),
DomainError
(
args
,
"at least one of `
$
modsname` and `args` must be defined"
),
)
end
([[]
for
_
in
args
]
,
Array
{
A
,
N
}(
args
))
return
NamedTuple
{(
modsname
,)}(
Ref
([[]
for
_
in
args
]))
elseif
isnothing
(
args
)
(
Array
{
V
,
N
}(
mods
),
[()
for
_
in
mods
])
return
(
args
=
[()
for
_
in
mods
]
,
)
else
if
size
(
mods
)
!=
size
(
args
)
throw
(
...
...
@@ -31,17 +28,18 @@ function _check_screen_mods_args(
),
)
end
return
()
end
end
"""
function
screen(
screen(
model::MetabolicModel;
variants::
Maybe{
Array{V
,N}} = nothing
,
analysis,
args::
Maybe{Array{A,N}} = nothing
,
variants::Array{V
ector}, N}
,
analysis
::Function
,
args::
Array{Vector{Tuple}, N}
,
workers = [myid()],
)::Array where {
V<:AbstractVector,A,
N}
)::Array where {N}
Take an array of model-modifying function vectors in `variants`, and execute
the function `analysis` on all variants of the `model` specified by `variants`.
...
...
@@ -79,6 +77,9 @@ JuMP models that contain pointers to allocated C structures (such as
[`flux_balance_analysis`](@ref) used with `GLPK` or `Gurobi` otimizers) will
generally not in this context.
Note: this function is a thin argument-handling wrapper around
[`_screen_impl`](@ref).
# Example
```
function reverse_reaction(i::Int)
...
...
@@ -91,31 +92,43 @@ end
m = load_model(CoreModel, "
e_coli_core
.
xml
")
screen
_variants
(m,
[
[reverse_reaction(5)],
[reverse_reaction(3), reverse_reaction(6)]
],
mod -> mod.S[:,3]) # observe the changes in S
screen(m,
variants =
[
[reverse_reaction(5)],
[reverse_reaction(3), reverse_reaction(6)]
],
analysis =
mod -> mod.S[:,3]) # observe the changes in S
screen
_variants
(m,
[
screen(m,
variants =
[
[reverse_reaction(5)],
[reverse_reaction(3), reverse_reaction(6)]
],
mod -> flux_balance_analysis_vec(mod, GLPK.Optimizer))
# run analysis
analysis =
mod -> flux_balance_analysis_vec(mod, GLPK.Optimizer))
```
"""
function
screen
(
screen
(
args
...
;
kwargs
...
)
=
_screen_impl
(
args
...
;
kwargs
...
,
_screen_args
(
args
,
kwargs
,
:
variants
)
...
)
"""
_screen_impl(
model::MetabolicModel;
variants::Array{Vector, N},
analysis::Function,
args::Array{Tuple, N},
workers = [myid()],
)::Array where {N}
The actual implementation of [`screen`](@ref).
"""
function
_screen_impl
(
model
::
MetabolicModel
;
variants
::
Maybe
{
Array
{
V
,
N
}
}
=
nothing
,
variants
::
Array
{
V
,
N
},
analysis
,
args
::
Maybe
{
Array
{
A
,
N
}
}
=
nothing
,
args
::
Array
{
A
,
N
},
workers
=
[
myid
()],
)
::
Array
where
{
V
<:
AbstractVector
,
A
,
N
}
(
variants
,
args
)
=
_check_screen_mods_args
(
variants
,
args
,
:
variants
)
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
,
get_from
.
(
workers
,
Ref
(
:
(
precache!
(
cobrexa_screen_variants_model
)))))
...
...
@@ -199,15 +212,15 @@ function _screen_optmodel_item((mods, args))
end
"""
function
screen_optmodel_modifications(
screen_optmodel_modifications(
model::MetabolicModel,
optimizer;
common_modifications::V,
modifications::
Maybe{
Array{V
,N}} = nothing
,
args::
Maybe{Array{T,N}} = nothing
,
analysis
= screen_optimize_objective
,
common_modifications::V
ector = []
,
modifications::Array{V
ector,N}
,
args::
Array{Vector{Tuple},N}
,
analysis
::Function
,
workers = [myid()],
) where
{V<:AbstractVector,T<:Tuple,N}
) where
N
Screen multiple modifications of the same optimization model.
...
...
@@ -230,18 +243,38 @@ have 2 base parameters (as opposed to 1 with [`screen`](@ref)): first is the
`model` (carried through as-is), second is the prepared JuMP optimization model
that may be modified and acted upon. As an example, you can use modification
[`change_constraint`](@ref) and analysis [`screen_optimize_objective`](@ref).
Note: This function is a thin argument-handling wrapper around
[`_screen_optmodel_modifications_impl`](@ref).
"""
screen_optmodel_modifications
(
args
...
;
kwargs
...
)
=
_screen_optmodel_modifications_impl
(
args
...
;
kwargs
...
,
_screen_args
(
args
,
kwargs
,
:
modifications
)
...
,
)
"""
function
screen_optmodel_modifications
(
_screen_optmodel_modifications_impl(
model::MetabolicModel,
optimizer;
common_modifications::Vector = [],
modifications::Array{Vector,N},
args::Array{Tuple,N},
analysis::Function,
workers = [myid()],
) where N
The actual implementation of [`screen_optmodel_modifications`](@ref).
"""
function
_screen_optmodel_modifications_impl
(
model
::
MetabolicModel
,
optimizer
;
common_modifications
::
V
ector
=
[],
modifications
::
Maybe
{
Array
{
V
,
N
}
}
=
nothing
,
args
::
Maybe
{
Array
{
A
,
N
}
}
=
nothing
,
analysis
::
Any
,
common_modifications
::
V
F
=
[],
modifications
::
Array
{
V
,
N
},
args
::
Array
{
A
,
N
},
analysis
::
Function
,
workers
=
[
myid
()],
)
where
{
V
<:
AbstractVector
,
A
,
N
}
(
modifications
,
args
)
=
_check_screen_mods_args
(
modifications
,
args
,
:
modifications
)
)
::
Array
where
{
V
<:
AbstractVector
,
VF
<:
AbstractVector
,
A
,
N
}
map
(
fetch
,
...
...
test/analysis/screening.jl
View file @
3ae6fbff
...
...
@@ -5,8 +5,8 @@
# nothing to analyze
@test_throws
DomainError
screen
(
m
;
analysis
=
identity
)
# array dimensionalities must match
(this is actually caught by typechecker)
@test_throws
Method
Error
screen
(
# array dimensionalities must match
@test_throws
Domain
Error
screen
(
m
;
analysis
=
identity
,
variants
=
[[],
[]],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment