Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XBanalysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Schubert
XBanalysis
Commits
abd06b7d
Commit
abd06b7d
authored
Sep 14, 2022
by
Peter Schubert
Browse files
Options
Downloads
Patches
Plain Diff
gba_sflux_problem variable names aligned with gba_problem
parent
798da8ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
xbanalysis/problems/gba_sflux_problem.py
+52
-51
52 additions, 51 deletions
xbanalysis/problems/gba_sflux_problem.py
with
52 additions
and
51 deletions
xbanalysis/problems/gba_sflux_problem.py
+
52
−
51
View file @
abd06b7d
...
@@ -35,46 +35,49 @@ class GbaSfluxProblem:
...
@@ -35,46 +35,49 @@ class GbaSfluxProblem:
# while XBA model contains enzymes for all metabolic reactions with related synthesis reactions,
# while XBA model contains enzymes for all metabolic reactions with related synthesis reactions,
# in scaled flux GBA optimization one a single protein (here we use the ribosome) is used
# in scaled flux GBA optimization one a single protein (here we use the ribosome) is used
metab_sids
=
[
s
.
id
for
s
in
xba_model
.
species
.
values
()
if
s
.
sboterm
.
is_in_branch
(
'
SBO:0000247
'
)]
metab_sids
=
[
s
.
id
for
s
in
xba_model
.
species
.
values
()
if
s
.
sboterm
.
is_in_branch
(
'
SBO:0000247
'
)]
self
.
sids_e
=
[
sid
for
sid
in
metab_sids
if
xba_model
.
species
[
sid
].
constant
is
True
]
self
.
const_metab_sids
=
[
sid
for
sid
in
metab_sids
if
xba_model
.
species
[
sid
].
constant
is
True
]
sids_s
=
[
sid
for
sid
in
metab_sids
if
xba_model
.
species
[
sid
].
constant
is
False
]
self
.
var_metab_sids
=
[
sid
for
sid
in
metab_sids
if
xba_model
.
species
[
sid
].
constant
is
False
]
sid_p
=
[
s
.
id
for
s
in
xba_model
.
species
.
values
()
if
s
.
sboterm
.
is_in_branch
(
'
SBO:0000250
'
)][
0
]
sid_ribo
=
[
s
.
id
for
s
in
xba_model
.
species
.
values
()
if
s
.
sboterm
.
is_in_branch
(
'
SBO:0000250
'
)][
0
]
self
.
sids_sp
=
sids_s
+
[
sid_p
]
self
.
var_sids
=
self
.
var_metab_sids
+
[
sid_ribo
]
self
.
sids_esp
=
self
.
sids_e
+
self
.
sids_sp
self
.
sids
=
self
.
const_metab_sids
+
self
.
var_sids
self
.
sid2idx
=
{
msid
:
idx
for
idx
,
msid
in
enumerate
(
self
.
sids
)}
rids_be
=
[
r
.
id
for
r
in
xba_model
.
reactions
.
values
()
if
r
.
sboterm
.
is_in_branch
(
'
SBO:0000167
'
)]
rid_r
=
xba_model
.
species
[
sid_p
].
ps_rid
self
.
mr_rids
=
[
r
.
id
for
r
in
xba_model
.
reactions
.
values
()
self
.
rids_ber
=
rids_be
+
[
rid_r
]
if
r
.
sboterm
.
is_in_branch
(
'
SBO:0000167
'
)]
rid_ps_ribo
=
xba_model
.
species
[
sid_ribo
].
ps_rid
self
.
mw_esp
=
np
.
array
([
xba_model
.
species
[
sid
].
mw
for
sid
in
self
.
sids_esp
])
self
.
rids
=
self
.
mr_rids
+
[
rid_ps_ribo
]
self
.
mw_ber
=
np
.
array
([
xba_model
.
species
[
xba_model
.
reactions
[
rid
].
enzyme
].
mw
self
.
rid2idx
=
{
mrid
:
idx
for
idx
,
mrid
in
enumerate
(
self
.
rids
)}
for
rid
in
self
.
rids_ber
])
# mw_ber is used for scaling of kcats, weight for protein synthesis needs to be rescaled
self
.
mw_sids
=
np
.
array
([
xba_model
.
species
[
sid
].
mw
for
sid
in
self
.
sids
])
s
=
xba_model
.
species
[
sid_p
]
self
.
mw_enz
=
np
.
array
([
xba_model
.
species
[
xba_model
.
reactions
[
rid
].
enzyme
].
mw
for
rid
in
self
.
rids
])
# mw_enz is used for scaling of kcats, weight for protein synthesis needs to be rescaled
s
=
xba_model
.
species
[
sid_ribo
]
if
hasattr
(
s
,
'
rba_process_costs
'
):
if
hasattr
(
s
,
'
rba_process_costs
'
):
p_len
=
s
.
rba_process_costs
[
'
translation
'
]
p_len
=
s
.
rba_process_costs
[
'
translation
'
]
else
:
else
:
r
=
xba_model
.
reactions
[
rid_
r
]
r
=
xba_model
.
reactions
[
rid_
ps_ribo
]
p_len
=
min
(
r
.
reactants
.
values
())
p_len
=
min
(
r
.
reactants
.
values
())
self
.
mw_
ber
[
-
1
]
*=
p_len
self
.
mw_
enz
[
-
1
]
*=
p_len
# retrieve S-matrix: internal metabos + total protein and metabolic reaction + ribosome synthesis
# retrieve S-matrix: internal metabos + total protein and metabolic reaction + ribosome synthesis
s
m_espxber
=
xba_model
.
get_stoic_matrix
(
self
.
sids
_esp
,
self
.
rids
_ber
)
s
ids_x_rids
=
xba_model
.
get_stoic_matrix
(
self
.
sids
,
self
.
rids
)
# calulate mass turnover in gram reactants/products per mol reactions (g/mol)
# calulate mass turnover in gram reactants/products per mol reactions (g/mol)
s
m_espxber
_react
=
np
.
where
(
s
m_espxber
>
0
,
0
,
sm_espxber
)
s
ids_x_rids
_react
=
np
.
where
(
s
ids_x_rids
>
0
,
0
,
sids_x_rids
)
s
m_espxber
_prod
=
np
.
where
(
s
m_espxber
<
0
,
0
,
sm_espxber
)
s
ids_x_rids
_prod
=
np
.
where
(
s
ids_x_rids
<
0
,
0
,
sids_x_rids
)
mass_turnover_react
=
-
s
m_espxber
_react
.
T
.
dot
(
self
.
mw_
esp
)
mass_turnover_react
=
-
s
ids_x_rids
_react
.
T
.
dot
(
self
.
mw_
sids
)
mass_turnover_prod
=
s
m_espxber
_prod
.
T
.
dot
(
self
.
mw_
esp
)
mass_turnover_prod
=
s
ids_x_rids
_prod
.
T
.
dot
(
self
.
mw_
sids
)
self
.
mass_turnover
=
np
.
max
((
mass_turnover_react
,
mass_turnover_prod
),
axis
=
0
)
self
.
mass_turnover
=
np
.
max
((
mass_turnover_react
,
mass_turnover_prod
),
axis
=
0
)
# mass normalized stoichiometric matrix
# mass normalized stoichiometric matrix
self
.
s
mmn_espxber
=
(
sm_espxber
*
self
.
mw_
esp
.
reshape
(
-
1
,
1
))
/
self
.
mass_turnover
self
.
s
idx_x_rids_mn
=
(
sids_x_rids
*
self
.
mw_
sids
.
reshape
(
-
1
,
1
))
/
self
.
mass_turnover
self
.
rho
=
xba_model
.
parameters
[
'
rho
'
].
value
self
.
rho
=
xba_model
.
parameters
[
'
rho
'
].
value
self
.
c
emn
=
np
.
array
([
xba_model
.
species
[
sid
].
initial_conc
*
xba_model
.
species
[
sid
].
mw
self
.
e
xt_conc_
mn
=
np
.
array
([
xba_model
.
species
[
sid
].
initial_conc
*
xba_model
.
species
[
sid
].
mw
for
sid
in
self
.
sids
_e
])
for
sid
in
self
.
const_metab_
sids
])
self
.
ci
mn
=
np
.
array
([
xba_model
.
species
[
sid
].
initial_conc
*
xba_model
.
species
[
sid
].
mw
self
.
var_initial_
mn
=
np
.
array
([
xba_model
.
species
[
sid
].
initial_conc
*
xba_model
.
species
[
sid
].
mw
for
sid
in
sid
s_
s
])
for
sid
in
s
elf
.
var_metab_s
ids
])
# identify unit ids for kinetic parameters
# identify unit ids for kinetic parameters
units_per_s
=
[
XbaUnit
({
'
kind
'
:
'
second
'
,
'
exp
'
:
-
1.0
,
'
scale
'
:
0
,
'
mult
'
:
1.0
})]
units_per_s
=
[
XbaUnit
({
'
kind
'
:
'
second
'
,
'
exp
'
:
-
1.0
,
'
scale
'
:
0
,
'
mult
'
:
1.0
})]
...
@@ -163,37 +166,35 @@ class GbaSfluxProblem:
...
@@ -163,37 +166,35 @@ class GbaSfluxProblem:
:return: gba model mass normalized as per Hugo Dourado
:return: gba model mass normalized as per Hugo Dourado
:rtype: dict of pandas DataFrames
:rtype: dict of pandas DataFrames
"""
"""
protein_mn
=
self
.
rho
-
sum
(
self
.
ci
mn
)
protein_mn
=
self
.
rho
-
sum
(
self
.
var_initial_
mn
)
kcats
=
np
.
array
([
self
.
get_kcats
(
rid
)
for
rid
in
self
.
rids
_ber
]).
T
kcats
=
np
.
array
([
self
.
get_kcats
(
rid
)
for
rid
in
self
.
rids
]).
T
skcats
=
kcats
*
3600.0
*
self
.
mass_turnover
/
self
.
mw_
ber
skcats
=
kcats
*
3600.0
*
self
.
mass_turnover
/
self
.
mw_
enz
km
=
np
.
zeros_like
(
self
.
smmn_espxber
)
km
=
np
.
zeros_like
(
self
.
sidx_x_rids_mn
)
ki
=
np
.
zeros_like
(
self
.
smmn_espxber
)
ki
=
np
.
zeros_like
(
self
.
sidx_x_rids_mn
)
rid2idx
=
{
mrid
:
idx
for
idx
,
mrid
in
enumerate
(
self
.
rids_ber
)}
for
rid
in
self
.
rids
:
sid2idx
=
{
msid
:
idx
for
idx
,
msid
in
enumerate
(
self
.
sids_esp
)}
for
rid
in
self
.
rids_ber
:
kms
,
kis
=
self
.
get_kms
(
rid
)
kms
,
kis
=
self
.
get_kms
(
rid
)
for
sid
,
val
in
kms
.
items
():
for
sid
,
val
in
kms
.
items
():
km
[
sid2idx
[
sid
],
rid2idx
[
rid
]]
=
val
km
[
self
.
sid2idx
[
sid
],
self
.
rid2idx
[
rid
]]
=
val
for
sid
,
val
in
kis
.
items
():
for
sid
,
val
in
kis
.
items
():
ki
[
sid2idx
[
sid
],
rid2idx
[
rid
]]
=
val
ki
[
self
.
sid2idx
[
sid
],
self
.
rid2idx
[
rid
]]
=
val
# scale Michaelis constants with molecluar weights
# scale Michaelis constants with molecluar weights
skm
=
km
*
self
.
mw_
esp
.
reshape
(
-
1
,
1
)
skm
=
km
*
self
.
mw_
sids
.
reshape
(
-
1
,
1
)
ski
=
ki
*
self
.
mw_
esp
.
reshape
(
-
1
,
1
)
ski
=
ki
*
self
.
mw_
sids
.
reshape
(
-
1
,
1
)
ska
=
np
.
zeros_like
(
self
.
s
mmn_espxber
)
ska
=
np
.
zeros_like
(
self
.
s
idx_x_rids_mn
)
mn_model
=
{
mn_model
=
{
'
N
'
:
pd
.
DataFrame
(
self
.
s
mmn_espxber
,
index
=
self
.
sids
_esp
,
columns
=
self
.
rids
_ber
),
'
N
'
:
pd
.
DataFrame
(
self
.
s
idx_x_rids_mn
,
index
=
self
.
sids
,
columns
=
self
.
rids
),
'
KM
'
:
pd
.
DataFrame
(
skm
,
index
=
self
.
sids
_esp
,
columns
=
self
.
rids
_ber
),
'
KM
'
:
pd
.
DataFrame
(
skm
,
index
=
self
.
sids
,
columns
=
self
.
rids
),
'
KI
'
:
pd
.
DataFrame
(
ski
,
index
=
self
.
sids
_esp
,
columns
=
self
.
rids
_ber
),
'
KI
'
:
pd
.
DataFrame
(
ski
,
index
=
self
.
sids
,
columns
=
self
.
rids
),
'
KA
'
:
pd
.
DataFrame
(
ska
,
index
=
self
.
sids
_esp
,
columns
=
self
.
rids
_ber
),
'
KA
'
:
pd
.
DataFrame
(
ska
,
index
=
self
.
sids
,
columns
=
self
.
rids
),
'
kcat
'
:
pd
.
DataFrame
(
skcats
,
index
=
[
'
kcat_f
'
,
'
kcat_b
'
],
columns
=
self
.
rids
_ber
),
'
kcat
'
:
pd
.
DataFrame
(
skcats
,
index
=
[
'
kcat_f
'
,
'
kcat_b
'
],
columns
=
self
.
rids
),
'
conditions
'
:
pd
.
DataFrame
(
np
.
hstack
((
self
.
rho
,
self
.
c
emn
)),
'
conditions
'
:
pd
.
DataFrame
(
np
.
hstack
((
self
.
rho
,
self
.
e
xt_conc_
mn
)),
index
=
[
'
rho
'
]
+
self
.
sids
_e
,
columns
=
[
1
]),
index
=
[
'
rho
'
]
+
self
.
const_metab_
sids
,
columns
=
[
1
]),
'
lower_c
'
:
pd
.
DataFrame
(
np
.
zeros
(
len
(
self
.
sids
_sp
)),
'
lower_c
'
:
pd
.
DataFrame
(
np
.
zeros
(
len
(
self
.
var_
sids
)),
index
=
self
.
sids
_sp
,
columns
=
[
'
lower
'
]),
index
=
self
.
var_
sids
,
columns
=
[
'
lower
'
]),
'
initial
'
:
pd
.
DataFrame
(
np
.
hstack
((
self
.
ci
mn
,
protein_mn
)),
'
initial
'
:
pd
.
DataFrame
(
np
.
hstack
((
self
.
var_initial_
mn
,
protein_mn
)),
index
=
self
.
sids
_sp
,
columns
=
[
'
initial
'
]),
index
=
self
.
var_
sids
,
columns
=
[
'
initial
'
]),
}
}
return
mn_model
return
mn_model
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