Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
COBREXA.jl
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LCSB-BioCore
COBREXA.jl
Commits
7f0fc9d2
Unverified
Commit
7f0fc9d2
authored
3 years ago
by
St. Elmo
Browse files
Options
Downloads
Patches
Plain Diff
added constraint modification callback
parent
56052b41
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/analysis/fba.jl
+12
-11
12 additions, 11 deletions
src/analysis/fba.jl
src/base/utilities.jl
+12
-0
12 additions, 0 deletions
src/base/utilities.jl
with
24 additions
and
11 deletions
src/analysis/fba.jl
+
12
−
11
View file @
7f0fc9d2
...
@@ -65,16 +65,23 @@ sol = fba(model, biomass, optimizer; solver_attributes=atts)
...
@@ -65,16 +65,23 @@ sol = fba(model, biomass, optimizer; solver_attributes=atts)
function
fba
(
function
fba
(
model
::
CobraModel
,
model
::
CobraModel
,
optimizer
;
optimizer
;
objective_func
::
Union
{
Reaction
,
Array
{
Reaction
,
1
}}
=
Reaction
[],
modifications
=
[(
model
,
opt_model
)
->
nothing
]
weights
=
Float64
[],
solver_attributes
=
Dict
{
Any
,
Any
}(),
constraints
=
Dict
{
String
,
Tuple
{
Float64
,
Float64
}}(),
sense
=
MOI
.
MAX_SENSE
,
)
)
objective_func
::
Union
{
Reaction
,
Array
{
Reaction
,
1
}}
=
Reaction
[]
weights
=
Float64
[]
solver_attributes
=
Dict
{
Any
,
Any
}()
sense
=
MOI
.
MAX_SENSE
# get core optimization problem
# get core optimization problem
cbm
=
make_optimization_model
(
model
,
optimizer
,
sense
=
sense
)
cbm
=
make_optimization_model
(
model
,
optimizer
,
sense
=
sense
)
v
=
cbm
[
:
x
]
# fluxes
v
=
cbm
[
:
x
]
# fluxes
# apply callbacks
for
mod
in
modifications
mod
(
model
,
cbm
)
end
# modify core optimization problem according to user specifications
# modify core optimization problem according to user specifications
if
!
isempty
(
solver_attributes
)
# set other attributes
if
!
isempty
(
solver_attributes
)
# set other attributes
for
(
k
,
val
)
in
solver_attributes
for
(
k
,
val
)
in
solver_attributes
...
@@ -82,12 +89,6 @@ function fba(
...
@@ -82,12 +89,6 @@ function fba(
end
end
end
end
# set additional constraints
for
(
rxnid
,
con
)
in
constraints
ind
=
model
.
reactions
[
findfirst
(
model
.
reactions
,
rxnid
)]
set_bound
(
ind
,
cbm
;
lb
=
con
[
1
],
ub
=
con
[
2
])
end
# if an objective function is supplied, modify the default objective
# if an objective function is supplied, modify the default objective
if
typeof
(
objective_func
)
==
Reaction
||
!
isempty
(
objective_func
)
if
typeof
(
objective_func
)
==
Reaction
||
!
isempty
(
objective_func
)
# ensure that an array of objective indices are fed in
# ensure that an array of objective indices are fed in
...
...
This diff is collapsed.
Click to expand it.
src/base/utilities.jl
+
12
−
0
View file @
7f0fc9d2
...
@@ -34,3 +34,15 @@ function set_bound(vind, opt_model; ub = 1000, lb = -1000)
...
@@ -34,3 +34,15 @@ function set_bound(vind, opt_model; ub = 1000, lb = -1000)
end
end
set_normalized_rhs
(
opt_model
[
:
ubs
][
vind
],
ub
)
set_normalized_rhs
(
opt_model
[
:
ubs
][
vind
],
ub
)
end
end
"""
modify_constraint(reaction::Reaction, lb, ub)
Modify constraints of model reaction.
"""
function
modify_constraint
(
reaction
::
Reaction
,
lb
,
ub
)
(
model
,
opt_model
)
->
begin
ind
=
model
.
reactions
[
reaction
]
set_bound
(
ind
,
opt_model
,
lb
=
lb
,
ub
=
ub
)
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment