Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Peter Schubert
networkred
Commits
1dde60f4
Commit
1dde60f4
authored
Nov 05, 2021
by
Peter Schubert
Browse files
added support function to load_raw_protected_data(fname)
parent
dafaae94
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
1dde60f4
...
...
@@ -43,8 +43,52 @@ $ pip3 install networkred@git+https://gitlab.cs.uni-duesseldorf.de/schubert/net
```
python
>>>
import
networkred
>>>
....
(
yet
to
be
filled
)
import
os
import
pandas
as
pd
data_dir
=
'sample_data/data'
model_name
=
'Deniz_model_fba'
protected_parts_file
=
'Deniz_model_fba_nrp.xlsx'
import
networkred
original_sbml
=
'sample_data/SBML_models/Deniz_model_fba.xml'
reduced_sbml
=
'sample_data/SBML_models/Deniz_model_fba_red.xml'
# import original SBML file
red_model
=
networkred
.
ReduceModel
(
original_sbml
)
# set protected parts
protect_name
=
os
.
path
.
join
(
data_dir
,
protected_parts_file
)
print
(
'load reduction parameters from:'
,
protect_name
)
protect_rids
=
None
protect_mids
=
None
protect_funcs
=
None
with
pd
.
ExcelFile
(
protect_name
)
as
xlsx
:
if
'reactions'
in
xlsx
.
sheet_names
:
protect_rids
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'reactions'
,
index_col
=
0
).
index
.
tolist
()
if
'metabolites'
in
xlsx
.
sheet_names
:
protect_mids
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'metabolites'
,
index_col
=
0
).
index
.
tolist
()
if
'functions'
in
xlsx
.
sheet_names
:
protect_funcs
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'functions'
,
index_col
=
0
)
if
'bounds'
in
xlsx
.
sheet_names
:
temp_fbc_bounds
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'bounds'
,
index_col
=
0
)
red_model
.
set_reduction_params
(
protect_rids
=
protect_rids
,
protect_mids
=
protect_mids
,
protect_funcs
=
protect_funcs
,
temp_fbc_bounds
=
temp_fbc_bounds
,
model_base
=
'original'
)
# reduce the network
red_model
.
reduce
()
# export reduced model to sbml
red_model
.
write_sbml
(
reduced_sbml
)
>>>
```
...
...
networkred/__init__.py
View file @
1dde60f4
from
networkred.reduce_model
import
ReduceModel
from
networkred._version
import
__version__
from
networkred.reduce_model
import
ReduceModel
,
load_raw_protected_data
__author__
=
'Peter Schubert'
\ No newline at end of file
__author__
=
'Peter Schubert'
networkred/reduce_model.py
View file @
1dde60f4
...
...
@@ -33,10 +33,12 @@ reduction process. Essential reactions are identified earlier.
### References
[1]: Kamp A, Thiele S, Haedicke O, Klamt S. (2017) Use of CellNetAnalyzer
in biotechnology and metabolic engineering. Journal of Biotechnolgy 261: 221-228.
in biotechnology and metabolic engineering. Journal of Biotechnolgy 261:
221-228.
[2]: Ebrahim, A., Lerman, J.A., Palsson, B.O. et al. COBRApy: COnstraints-Based Reconstruction
and Analysis for Python. BMC Syst Biol 7, 74 (2013). https://doi.org/10.1186/1752-0509-7-74
[2]: Ebrahim, A., Lerman, J.A., Palsson, B.O. et al. COBRApy:
COnstraints-Based Reconstruction and Analysis for Python. BMC Syst Biol 7, 74
(2013). https://doi.org/10.1186/1752-0509-7-74
Peter Schubert, Computational Cell Biology, HHU Duesseldorf, November 2021
"""
...
...
@@ -55,6 +57,36 @@ from cobra.flux_analysis import flux_variability_analysis, find_blocked_reaction
from
cobra.util.array
import
create_stoichiometric_matrix
def
load_raw_protected_data
(
fname
):
"""Load raw protected parts from excel file.
Reaction/metabolite identifiers not modified.
:param fname: file name with protected parts
:type fname: str
:returns: dict with protected parts including:
list of pretected reactions or None,
list of protected metabolites or None,
DataFrame of protected functions or None,
DataFrame of temporary flux bounds or None
:rtype: dict
"""
nrp
=
{
'reactions'
:
None
,
'metabolites'
:
None
,
'functions'
:
None
,
'bounds'
:
None
}
if
type
(
fname
)
==
str
:
if
fname
.
endswith
(
'.xlsx'
)
and
os
.
path
.
exists
(
fname
):
print
(
'loading protected parts from:'
,
fname
)
with
pd
.
ExcelFile
(
fname
)
as
xlsx
:
for
key
in
nrp
.
keys
():
if
key
in
xlsx
.
sheet_names
:
nrp
[
key
]
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
key
,
index_col
=
0
)
if
key
in
[
'reactions'
,
'metabolites'
]:
nrp
[
key
]
=
nrp
[
key
].
index
.
tolist
()
return
nrp
def
get_items
(
items_str
,
delim
=
';'
):
"""Generator to return individual records.
...
...
@@ -195,7 +227,8 @@ class ReduceModel:
self
.
_orig_fbc_bounds
=
{}
def
set_reduction_params
(
self
,
protect_rids
=
None
,
protect_mids
=
None
,
protect_funcs
=
None
,
temp_fbc_bounds
=
None
,
model_base
=
'original'
):
protect_funcs
=
None
,
temp_fbc_bounds
=
None
,
model_base
=
'original'
):
"""Set protected parts of the model.
reaction ids and metabolite ids get converted to cobra ids (i.e. stripping of 'R_' and 'M_').
...
...
sample_data/SBML_models/Deniz_model_fba_reduced.xml
View file @
1dde60f4
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by sbmlxdf version 0.2.5 on 2021-11-05 1
1:24
with libSBML version 5.19.0. -->
<!-- Created by sbmlxdf version 0.2.5 on 2021-11-05 1
2:13
with libSBML version 5.19.0. -->
<sbml
xmlns=
"http://www.sbml.org/sbml/level3/version2/core"
xmlns:fbc=
"http://www.sbml.org/sbml/level3/version1/fbc/version2"
level=
"3"
version=
"2"
fbc:required=
"false"
>
<model
metaid=
"Deniz_model_fba"
id=
"Deniz_model_fba_reduced"
name=
"Deniz_model_fba"
substanceUnits=
"substance"
timeUnits=
"time"
extentUnits=
"substance"
fbc:strict=
"true"
>
<notes>
...
...
sample_reduce_model.py
View file @
1dde60f4
...
...
@@ -4,10 +4,10 @@
import
sys
import
os
import
logging
import
pandas
as
pd
import
networkred
def
reduce_model
():
# activate logging
...
...
@@ -28,44 +28,27 @@ def reduce_model():
print
(
'working directory :'
,
os
.
getcwd
())
# file names and directories
sbml_dir
=
'sample_data/SBML_models'
data_dir
=
'sample_data/data'
model_name
=
'Deniz_model_fba'
protected_parts_file
=
'Deniz_model_fba_nrp.xlsx'
original_sbml
=
'sample_data/SBML_models/Deniz_model_fba.xml'
reduced_sbml
=
'sample_data/SBML_models/Deniz_model_fba_reduced.xml'
protected_parts
=
'sample_data/data/Deniz_model_fba_nrp.xlsx'
# load the original model
sbml_file
=
os
.
path
.
join
(
sbml_dir
,
model_name
)
+
'.xml'
red_model
=
networkred
.
ReduceModel
(
sbml_file
)
# set protected parts
protect_name
=
os
.
path
.
join
(
data_dir
,
protected_parts_file
)
print
(
'load reduction parameters from:'
,
protect_name
)
protect_rids
=
None
protect_mids
=
None
protect_funcs
=
None
with
pd
.
ExcelFile
(
protect_name
)
as
xlsx
:
if
'reactions'
in
xlsx
.
sheet_names
:
protect_rids
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'reactions'
,
index_col
=
0
).
index
.
tolist
()
if
'metabolites'
in
xlsx
.
sheet_names
:
protect_mids
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'metabolites'
,
index_col
=
0
).
index
.
tolist
()
if
'functions'
in
xlsx
.
sheet_names
:
protect_funcs
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'functions'
,
index_col
=
0
)
if
'bounds'
in
xlsx
.
sheet_names
:
temp_fbc_bounds
=
pd
.
read_excel
(
xlsx
,
sheet_name
=
'bounds'
,
index_col
=
0
)
red_model
.
set_reduction_params
(
protect_rids
=
protect_rids
,
protect_mids
=
protect_mids
,
protect_funcs
=
protect_funcs
,
temp_fbc_bounds
=
temp_fbc_bounds
,
red_model
=
networkred
.
ReduceModel
(
original_sbml
)
# load protected parts for network reduction
nrp
=
networkred
.
load_raw_protected_data
(
protected_parts
)
red_model
.
set_reduction_params
(
protect_rids
=
nrp
[
'reactions'
],
protect_mids
=
nrp
[
'metabolites'
],
protect_funcs
=
nrp
[
'functions'
],
temp_fbc_bounds
=
nrp
[
'bounds'
],
model_base
=
'original'
)
# prune network (for specific dof, rmin), create snapshots every two reduced reactions
print
(
'---- network pruning -----'
)
print
(
'---- network reduction -----'
)
red_model
.
reduce
()
# write reduced model to sbml
reduced_name
=
os
.
path
.
join
(
sbml_dir
,
model_name
)
+
'_reduced.xml'
red_model
.
write_sbml
(
reduced_name
)
print
(
'reduced model converted to SBML:'
,
reduced_name
)
red_model
.
write_sbml
(
reduced_sbml
)
print
(
'reduced model converted to SBML:'
,
reduced_sbml
)
logging
.
info
(
'Finished'
)
...
...
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