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
b87478e9
Unverified
Commit
b87478e9
authored
3 years ago
by
St. Elmo
Browse files
Options
Downloads
Patches
Plain Diff
small updates
parent
0e04a8bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/analysis/fba.jl
+32
-0
32 additions, 0 deletions
src/analysis/fba.jl
src/analysis/fva.jl
+57
-15
57 additions, 15 deletions
src/analysis/fva.jl
with
89 additions
and
15 deletions
src/analysis/fba.jl
+
32
−
0
View file @
b87478e9
...
...
@@ -89,6 +89,7 @@ sense = MOI.MAX_SENSE
end
end
<<<<<<<
Updated
upstream
# if an objective function is supplied, modify the default objective
if
typeof
(
objective_func
)
==
Reaction
||
!
isempty
(
objective_func
)
# ensure that an array of objective indices are fed in
...
...
@@ -123,10 +124,32 @@ sense = MOI.MAX_SENSE
optimize!
(
cbm
)
=======
function
flux_balance_analysis_vec
(
args
)
cbm
=
flux_balance_analysis
(
args
...
)
status
=
(
termination_status
(
cbm
)
==
MOI
.
OPTIMAL
||
termination_status
(
cbm
)
==
MOI
.
LOCALLY_SOLVED
)
if
status
return
value
.
(
cbm
[
:
x
])
else
@warn
"Optimization issues occurred."
return
Vector
{
Float64
}[]
end
end
function
flux_balance_analysis_dict
(
model
,
args
)
cbm
=
flux_balance_analysis
(
model
,
args
...
)
>>>>>>>
Stashed
changes
status
=
(
termination_status
(
cbm
)
==
MOI
.
OPTIMAL
||
termination_status
(
cbm
)
==
MOI
.
LOCALLY_SOLVED
)
<<<<<<<
Updated
upstream
if
status
return
map_fluxes
(
v
,
model
)
...
...
@@ -134,4 +157,13 @@ sense = MOI.MAX_SENSE
@warn
"Optimization issues occurred."
return
Dict
{
String
,
Float64
}()
end
=======
if
status
return
Dict
(
zip
(
reactions
(
model
),
value
.
(
cbm
[
:
x
])))
else
@warn
"Optimization issues occurred."
return
Dict
{
String
,
Float64
}()
end
>>>>>>>
Stashed
changes
end
This diff is collapsed.
Click to expand it.
src/analysis/fva.jl
+
57
−
15
View file @
b87478e9
...
...
@@ -38,7 +38,7 @@ function flux_variability_analysis(
end
optimization_model
=
flux_balance_analysis
(
model
,
optimizer
)
Z0
=
JuMP
.
objective_value
(
optimization_model
)
Z0
=
COBREXA
.
JuMP
.
objective_value
(
optimization_model
)
optimization_model
=
nothing
# we won't need this one anymore, so free the memory
# store a JuMP optimization model at all workers
...
...
@@ -92,7 +92,7 @@ Internal helper function for adding constraints to a model. Exists mainly
because for avoiding namespace problems on remote workers.
"""
function
_FVA_add_constraint
(
model
,
c
,
x
,
Z0
,
gamma
)
JuMP
.
@constraint
(
model
,
c
'
*
x
≥
gamma
*
Z0
)
COBREXA
.
JuMP
.
@constraint
(
model
,
c
'
*
x
≥
gamma
*
Z0
)
end
"""
...
...
@@ -103,11 +103,11 @@ namespace problems.
"""
function
_FVA_optimize_reaction
(
model
,
rid
)
sense
=
rid
>
0
?
MOI
.
MAX_SENSE
:
MOI
.
MIN_SENSE
var
=
JuMP
.
all_variables
(
model
)[
abs
(
rid
)]
var
=
COBREXA
.
JuMP
.
all_variables
(
model
)[
abs
(
rid
)]
JuMP
.
@objective
(
model
,
sense
,
var
)
JuMP
.
optimize!
(
model
)
return
JuMP
.
objective_value
(
model
)
COBREXA
.
JuMP
.
@objective
(
model
,
sense
,
var
)
COBREXA
.
JuMP
.
optimize!
(
model
)
return
COBREXA
.
JuMP
.
objective_value
(
model
)
end
"""
...
...
@@ -134,20 +134,60 @@ fva_max, fva_min = fva(model, biomass, optimizer; solver_attributes=atts)
function
fva
(
model
::
CobraModel
,
optimizer
;
objective_func
::
Union
{
Reaction
,
Array
{
Reaction
,
1
}}
=
Reaction
[],
optimum_bound
=
0.9999
,
modifications
=
[(
model
,
opt_model
)
->
nothing
]
weights
=
Float64
[],
solver_attributes
=
Dict
{
Any
,
Any
}(),
constraints
=
Dict
{
String
,
Tuple
{
Float64
,
Float64
}}(),
sense
=
MOI
.
MAX_SENSE
,
)
<<<<<<<
Updated
upstream
cbm
=
make_optimization_model
(
model
,
optimizer
,
sense
=
sense
)
v
=
cbm
[
:
x
]
=======
# get core optimization problem
cbm
=
make_optimization_model
(
model
,
optimizer
)
v
=
cbm
[
:
x
]
>>>>>>>
Stashed
changes
if
!
isempty
(
solver_attributes
)
# set other attributes
for
(
k
,
v
)
in
solver_attributes
set_optimizer_attribute
(
cbm
,
k
,
v
)
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
# apply callbacks - user can also just put in a function
if
typeof
(
modifications
)
<:
Vector
for
mod
in
modifications
mod
(
model
,
cbm
)
end
else
modifications
(
model
,
cbm
)
# if an objective function is supplied, modify the default objective
if
typeof
(
objective_func
)
==
Reaction
||
!
isempty
(
objective_func
)
# ensure that an array of objective indices are fed in
if
typeof
(
objective_func
)
==
Reaction
objective_indices
=
[
model
[
objective_func
]]
else
objective_indices
=
[
model
[
rxn
]
for
rxn
in
objective_func
]
end
if
isempty
(
weights
)
weights
=
ones
(
length
(
objective_indices
))
end
opt_weights
=
zeros
(
length
(
model
.
reactions
))
# update the objective function tracker
# don't update model objective function - silly thing to do
wcounter
=
1
for
i
in
eachindex
(
model
.
reactions
)
if
i
in
objective_indices
# model.reactions[i].objective_coefficient = weights[wcounter]
opt_weights
[
i
]
=
weights
[
wcounter
]
wcounter
+=
1
# else
# model.reactions[i].objective_coefficient = 0.0
end
end
@objective
(
cbm
,
sense
,
sum
(
opt_weights
[
i
]
*
v
[
i
]
for
i
in
objective_indices
))
end
optimize!
(
cbm
)
...
...
@@ -166,6 +206,8 @@ function fva(
end
# Now do FVA
v
=
cbm
[
:
x
]
λ
=
objective_value
(
cbm
)
# objective value
@constraint
(
cbm
,
...
...
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