gsrap 0.10.1__py3-none-any.whl → 0.10.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gsrap/.ipynb_checkpoints/__init__-checkpoint.py +11 -13
- gsrap/__init__.py +11 -13
- gsrap/commons/.ipynb_checkpoints/biomass-checkpoint.py +1 -1
- gsrap/commons/.ipynb_checkpoints/coeffs-checkpoint.py +1 -1
- gsrap/commons/.ipynb_checkpoints/downloads-checkpoint.py +3 -3
- gsrap/commons/.ipynb_checkpoints/escherutils-checkpoint.py +147 -1
- gsrap/commons/.ipynb_checkpoints/medium-checkpoint.py +1 -1
- gsrap/commons/.ipynb_checkpoints/metrics-checkpoint.py +10 -10
- gsrap/commons/biomass.py +1 -1
- gsrap/commons/coeffs.py +1 -1
- gsrap/commons/downloads.py +3 -3
- gsrap/commons/escherutils.py +147 -1
- gsrap/commons/medium.py +1 -1
- gsrap/commons/metrics.py +10 -10
- gsrap/parsedb/.ipynb_checkpoints/annotation-checkpoint.py +16 -6
- gsrap/parsedb/.ipynb_checkpoints/introduce-checkpoint.py +35 -35
- gsrap/parsedb/.ipynb_checkpoints/parsedb-checkpoint.py +19 -10
- gsrap/parsedb/.ipynb_checkpoints/repeating-checkpoint.py +12 -13
- gsrap/parsedb/annotation.py +16 -6
- gsrap/parsedb/introduce.py +35 -35
- gsrap/parsedb/parsedb.py +19 -10
- gsrap/parsedb/repeating.py +12 -13
- {gsrap-0.10.1.dist-info → gsrap-0.10.2.dist-info}/METADATA +2 -2
- {gsrap-0.10.1.dist-info → gsrap-0.10.2.dist-info}/RECORD +27 -27
- {gsrap-0.10.1.dist-info → gsrap-0.10.2.dist-info}/WHEEL +0 -0
- {gsrap-0.10.1.dist-info → gsrap-0.10.2.dist-info}/entry_points.txt +0 -0
- {gsrap-0.10.1.dist-info → gsrap-0.10.2.dist-info}/licenses/LICENSE.txt +0 -0
gsrap/commons/metrics.py
CHANGED
|
@@ -58,8 +58,8 @@ def show_contributions(logger, db, goodbefore):
|
|
|
58
58
|
return 0
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
# create a counter for each
|
|
62
|
-
cnt = {
|
|
61
|
+
# create a counter for each curator
|
|
62
|
+
cnt = {curator: 0 for curator in db['curators']['username']}
|
|
63
63
|
cnt_tot = 0
|
|
64
64
|
|
|
65
65
|
|
|
@@ -67,9 +67,9 @@ def show_contributions(logger, db, goodbefore):
|
|
|
67
67
|
if type(row['curator']) != str:
|
|
68
68
|
logger.error(f"Missing curator in tab 'R', rid '{row['rid']}'.")
|
|
69
69
|
return 1
|
|
70
|
-
for
|
|
71
|
-
|
|
72
|
-
cnt[
|
|
70
|
+
for curator in row['curator'].split(';'):
|
|
71
|
+
curator = curator.rstrip().strip()
|
|
72
|
+
cnt[curator] += 1
|
|
73
73
|
cnt_tot += 1
|
|
74
74
|
|
|
75
75
|
|
|
@@ -77,18 +77,18 @@ def show_contributions(logger, db, goodbefore):
|
|
|
77
77
|
if type(row['curator']) != str:
|
|
78
78
|
logger.error(f"Missing curator in tab 'T', rid '{row['rid']}'.")
|
|
79
79
|
return 1
|
|
80
|
-
for
|
|
81
|
-
|
|
82
|
-
cnt[
|
|
80
|
+
for curator in row['curator'].split(';'):
|
|
81
|
+
curator = curator.rstrip().strip()
|
|
82
|
+
cnt[curator] += 1
|
|
83
83
|
cnt_tot += 1
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
# compute percentages:
|
|
87
|
-
pct = {
|
|
87
|
+
pct = {curator: cnt[curator]/cnt_tot*100 for curator in cnt.keys()}
|
|
88
88
|
# sort in descending order:
|
|
89
89
|
pct = dict(sorted(pct.items(), key=lambda item: item[1], reverse=True))
|
|
90
90
|
# convert to string:
|
|
91
|
-
pct = {
|
|
91
|
+
pct = {curator: f'{round(pct[curator],2)}%' for curator in pct.keys()}
|
|
92
92
|
logger.debug(f"Contributions: {pct}.")
|
|
93
93
|
|
|
94
94
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import threading
|
|
2
|
+
import copy
|
|
2
3
|
|
|
3
4
|
import cobra
|
|
4
5
|
|
|
@@ -106,7 +107,7 @@ def translate_annotate_genes(logger, model, idcollection_dict):
|
|
|
106
107
|
|
|
107
108
|
|
|
108
109
|
|
|
109
|
-
def set_up_groups(logger, model, idcollection_dict):
|
|
110
|
+
def set_up_groups(logger, model, idcollection_dict, goodbefore):
|
|
110
111
|
|
|
111
112
|
|
|
112
113
|
logger.debug("Introducing groups...")
|
|
@@ -160,18 +161,27 @@ def set_up_groups(logger, model, idcollection_dict):
|
|
|
160
161
|
model.add_groups([actual_group])
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
# insert custom groups:
|
|
165
|
-
custom_groups = get_custom_groups()
|
|
166
|
-
#
|
|
167
164
|
# create a group for transporters on-the-fly
|
|
165
|
+
custom_groups = get_custom_groups()
|
|
168
166
|
custom_groups['gr_transport'] = []
|
|
169
167
|
for r in model.reactions:
|
|
170
168
|
if len(r.metabolites) == 1 and list(r.metabolites)[0].id.rsplit('_',1)[-1] != 'c': # just exchanges (esclude sinks/demands)
|
|
171
169
|
custom_groups['gr_transport'].append(r.id)
|
|
172
170
|
if len(set([m.id.rsplit('_', 1)[-1] for m in r.metabolites])) > 1: # transport reactions
|
|
173
171
|
custom_groups['gr_transport'].append(r.id)
|
|
174
|
-
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# handle eventual removed reactions as consequence of --goodbefore:
|
|
175
|
+
if type(goodbefore) == list:
|
|
176
|
+
modeled_rids = [r.id for r in model.reactions]
|
|
177
|
+
for group_id in custom_groups.keys():
|
|
178
|
+
for rid in copy.deepcopy(custom_groups[group_id]):
|
|
179
|
+
if rid not in modeled_rids:
|
|
180
|
+
logger.warning(f"Removing reaction '{rid}' from group '{group_id}' as consequence of --goodbefore.")
|
|
181
|
+
custom_groups[group_id].remove(rid)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# actually insert custom groups:
|
|
175
185
|
for group_id in custom_groups.keys():
|
|
176
186
|
actual_group = cobra.core.Group(
|
|
177
187
|
group_id,
|
|
@@ -3,7 +3,7 @@ import sys
|
|
|
3
3
|
import pandas as pnd
|
|
4
4
|
import cobra
|
|
5
5
|
|
|
6
|
-
from .repeating import
|
|
6
|
+
from .repeating import check_curator
|
|
7
7
|
from .repeating import check_rstring_arrow
|
|
8
8
|
from .repeating import check_gpr
|
|
9
9
|
from .repeating import add_reaction
|
|
@@ -14,7 +14,7 @@ from .manual import get_manual_demands
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to_others, outdir, goodbefore,
|
|
17
|
+
def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to_others, outdir, goodbefore, onlycurator):
|
|
18
18
|
goodbefore_reached = False
|
|
19
19
|
|
|
20
20
|
|
|
@@ -44,24 +44,24 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
44
44
|
goodbefore_reached = True
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
# manage goodbefore/
|
|
47
|
+
# manage goodbefore/onlycurator
|
|
48
48
|
if goodbefore != None and goodbefore_reached:
|
|
49
|
-
if
|
|
49
|
+
if onlycurator == None:
|
|
50
50
|
logger.warning(f"Skipping metabolite '{pure_mid}' as requested with --goodbefore[0] '{goodbefore}'.")
|
|
51
51
|
continue
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
# parse and get curators
|
|
55
|
-
response =
|
|
55
|
+
response = check_curator(logger, pure_mid, row, db, 'M')
|
|
56
56
|
if type(response) == int: return 1
|
|
57
|
-
else:
|
|
57
|
+
else: curators = response
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
# manage goodbefore/
|
|
60
|
+
# manage goodbefore/onlycurator
|
|
61
61
|
if goodbefore != None and goodbefore_reached:
|
|
62
|
-
if
|
|
63
|
-
|
|
64
|
-
logger.warning(f"Skipping metabolite '{pure_mid}' (
|
|
62
|
+
if onlycurator != None and onlycurator not in curators:
|
|
63
|
+
curators_string = '; '.join(curators)
|
|
64
|
+
logger.warning(f"Skipping metabolite '{pure_mid}' (curators '{curators_string}') as requested with --goodbefore[0] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
65
65
|
continue
|
|
66
66
|
|
|
67
67
|
|
|
@@ -122,7 +122,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
122
122
|
eqbiggids.add(eqbiggid)
|
|
123
123
|
if pure_mid not in eqbiggids and eqbiggids != set():
|
|
124
124
|
with open(f"{outdir}/logs/M.inbigg.txt", 'a') as f:
|
|
125
|
-
print(f"Metabolites '{'; '.join(kc_ids)}' already in BiGG as {eqbiggids} ({
|
|
125
|
+
print(f"Metabolites '{'; '.join(kc_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{pure_mid}').", file=f)
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
# add metabolite to model
|
|
@@ -136,7 +136,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
# write curators as annotations
|
|
139
|
-
m.annotation['curator_codes'] =
|
|
139
|
+
m.annotation['curator_codes'] = curators
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
# add annotations to model (same order of Memote)
|
|
@@ -197,7 +197,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
|
|
200
|
-
def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore,
|
|
200
|
+
def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore, onlycurator):
|
|
201
201
|
goodbefore_reached = False
|
|
202
202
|
|
|
203
203
|
|
|
@@ -226,24 +226,24 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
226
226
|
goodbefore_reached = True
|
|
227
227
|
|
|
228
228
|
|
|
229
|
-
# manage goodbefore/
|
|
229
|
+
# manage goodbefore/onlycurator
|
|
230
230
|
if goodbefore != None and goodbefore_reached:
|
|
231
|
-
if
|
|
231
|
+
if onlycurator == None:
|
|
232
232
|
logger.warning(f"Skipping reaction '{rid}' as requested with --goodbefore[1] '{goodbefore}'.")
|
|
233
233
|
continue
|
|
234
234
|
|
|
235
235
|
|
|
236
236
|
# parse and get curators
|
|
237
|
-
response =
|
|
237
|
+
response = check_curator(logger, rid, row, db, 'R')
|
|
238
238
|
if type(response) == int: return 1
|
|
239
|
-
else:
|
|
239
|
+
else: curators = response
|
|
240
240
|
|
|
241
241
|
|
|
242
|
-
# manage goodbefore/
|
|
242
|
+
# manage goodbefore/onlycurator
|
|
243
243
|
if goodbefore != None and goodbefore_reached:
|
|
244
|
-
if
|
|
245
|
-
|
|
246
|
-
logger.warning(f"Skipping reaction '{rid}' (
|
|
244
|
+
if onlycurator != None and onlycurator not in curators:
|
|
245
|
+
curators_string = '; '.join(curators)
|
|
246
|
+
logger.warning(f"Skipping reaction '{rid}' (curators '{curators_string}') as requested with --goodbefore[1] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
247
247
|
continue
|
|
248
248
|
|
|
249
249
|
|
|
@@ -284,11 +284,11 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
284
284
|
eqbiggids.add(eqbiggid)
|
|
285
285
|
if rid not in eqbiggids and eqbiggids != set():
|
|
286
286
|
with open(f"{outdir}/logs/R.inbigg.txt", 'a') as f:
|
|
287
|
-
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({
|
|
287
|
+
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{rid}').", file=f)
|
|
288
288
|
|
|
289
289
|
|
|
290
290
|
# add reaction to model
|
|
291
|
-
response = add_reaction(logger, model, rid,
|
|
291
|
+
response = add_reaction(logger, model, rid, curators, row, kr_ids, kegg_reaction_to_others, 'R', outdir)
|
|
292
292
|
if response == 1: return 1
|
|
293
293
|
|
|
294
294
|
|
|
@@ -308,7 +308,7 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
308
308
|
|
|
309
309
|
|
|
310
310
|
|
|
311
|
-
def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore,
|
|
311
|
+
def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore, onlycurator):
|
|
312
312
|
goodbefore_reached = False
|
|
313
313
|
|
|
314
314
|
|
|
@@ -373,24 +373,24 @@ def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_t
|
|
|
373
373
|
return 1
|
|
374
374
|
|
|
375
375
|
|
|
376
|
-
# manage goodbefore/
|
|
376
|
+
# manage goodbefore/onlycurator
|
|
377
377
|
if goodbefore != None and goodbefore_reached:
|
|
378
|
-
if
|
|
378
|
+
if onlycurator == None:
|
|
379
379
|
logger.warning(f"Skipping transport '{rid}' as requested with --goodbefore[2] '{goodbefore}'.")
|
|
380
380
|
continue
|
|
381
381
|
|
|
382
382
|
|
|
383
|
-
# parse
|
|
384
|
-
response =
|
|
383
|
+
# parse curator
|
|
384
|
+
response = check_curator(logger, rid, row, db, 'T')
|
|
385
385
|
if type(response) == int: return 1
|
|
386
|
-
else:
|
|
386
|
+
else: curators = response
|
|
387
387
|
|
|
388
388
|
|
|
389
|
-
# manage goodbefore/
|
|
389
|
+
# manage goodbefore/onlycurator
|
|
390
390
|
if goodbefore != None and goodbefore_reached:
|
|
391
|
-
if
|
|
392
|
-
|
|
393
|
-
logger.warning(f"Skipping transport '{rid}' (
|
|
391
|
+
if onlycurator != None and onlycurator not in curators:
|
|
392
|
+
curators_string = '; '.join(curators)
|
|
393
|
+
logger.warning(f"Skipping transport '{rid}' (curators '{curators_string}') as requested with --goodbefore[2] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
394
394
|
continue
|
|
395
395
|
|
|
396
396
|
|
|
@@ -454,11 +454,11 @@ def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_t
|
|
|
454
454
|
eqbiggids.add(eqbiggid)
|
|
455
455
|
if rid not in eqbiggids and eqbiggids != set():
|
|
456
456
|
with open(f"{outdir}/logs/T.inbigg.txt", 'a') as f:
|
|
457
|
-
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({
|
|
457
|
+
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{rid}').", file=f)
|
|
458
458
|
|
|
459
459
|
|
|
460
460
|
# add reaction to model
|
|
461
|
-
response = add_reaction(logger, model, rid,
|
|
461
|
+
response = add_reaction(logger, model, rid, curators, row, kr_ids, kegg_reaction_to_others, 'T', outdir)
|
|
462
462
|
if response == 1: return 1
|
|
463
463
|
rids_parsed.append(rid) # update list of rids in model
|
|
464
464
|
|
|
@@ -17,7 +17,7 @@ from ..commons import write_excel_model
|
|
|
17
17
|
from ..commons import show_contributions
|
|
18
18
|
from ..commons import adjust_biomass_precursors
|
|
19
19
|
from ..commons import count_undrawn_rids_focus
|
|
20
|
-
|
|
20
|
+
from ..commons import parse_zipped_escher
|
|
21
21
|
from ..commons import format_expansion
|
|
22
22
|
from ..commons import check_taxon
|
|
23
23
|
from ..commons import download_keggorg
|
|
@@ -50,6 +50,9 @@ def main(args, logger):
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
53
56
|
###### PRE-PARSING
|
|
54
57
|
|
|
55
58
|
# adjust out folder path
|
|
@@ -72,9 +75,9 @@ def main(args, logger):
|
|
|
72
75
|
return 1
|
|
73
76
|
|
|
74
77
|
|
|
75
|
-
# check 'goodbefore' and '
|
|
76
|
-
if args.goodbefore == '-' and args.
|
|
77
|
-
logger.error(f"--
|
|
78
|
+
# check 'goodbefore' and 'onlycurator' params
|
|
79
|
+
if args.goodbefore == '-' and args.onlycurator != '-':
|
|
80
|
+
logger.error(f"--onlycurator must be used in conjunction with --goodbefore.")
|
|
78
81
|
return 1
|
|
79
82
|
if args.goodbefore == '-': args.goodbefore = [None, None, None]
|
|
80
83
|
elif len(args.goodbefore.split('-')) != 3:
|
|
@@ -85,7 +88,7 @@ def main(args, logger):
|
|
|
85
88
|
if args.goodbefore[0] == 'None': args.goodbefore[0] = None
|
|
86
89
|
if args.goodbefore[1] == 'None': args.goodbefore[1] = None
|
|
87
90
|
if args.goodbefore[2] == 'None': args.goodbefore[2] = None
|
|
88
|
-
if args.
|
|
91
|
+
if args.onlycurator == '-': args.onlycurator = None
|
|
89
92
|
|
|
90
93
|
|
|
91
94
|
# check and extract the required 'gsrap.maps' file
|
|
@@ -147,17 +150,17 @@ def main(args, logger):
|
|
|
147
150
|
|
|
148
151
|
|
|
149
152
|
# introduce M
|
|
150
|
-
universe = introduce_metabolites(logger, dbuni, universe, idcollection_dict, kegg_compound_to_others, args.outdir, args.goodbefore[0], args.
|
|
153
|
+
universe = introduce_metabolites(logger, dbuni, universe, idcollection_dict, kegg_compound_to_others, args.outdir, args.goodbefore[0], args.onlycurator)
|
|
151
154
|
if type(universe)==int: return 1
|
|
152
155
|
|
|
153
156
|
|
|
154
157
|
# introduce R
|
|
155
|
-
universe = introduce_reactions(logger, dbuni, universe, idcollection_dict, kegg_reaction_to_others, args.outdir, args.goodbefore[1], args.
|
|
158
|
+
universe = introduce_reactions(logger, dbuni, universe, idcollection_dict, kegg_reaction_to_others, args.outdir, args.goodbefore[1], args.onlycurator)
|
|
156
159
|
if type(universe)==int: return 1
|
|
157
160
|
|
|
158
161
|
|
|
159
162
|
# introduce T
|
|
160
|
-
universe = introduce_transporters(logger, dbuni, universe, idcollection_dict, kegg_reaction_to_others, args.outdir, args.goodbefore[2], args.
|
|
163
|
+
universe = introduce_transporters(logger, dbuni, universe, idcollection_dict, kegg_reaction_to_others, args.outdir, args.goodbefore[2], args.onlycurator)
|
|
161
164
|
if type(universe)==int: return 1
|
|
162
165
|
|
|
163
166
|
|
|
@@ -177,10 +180,16 @@ def main(args, logger):
|
|
|
177
180
|
|
|
178
181
|
|
|
179
182
|
# introduce collections (groups of Rs as maps/modules)
|
|
180
|
-
universe = set_up_groups(logger, universe, idcollection_dict)
|
|
183
|
+
universe = set_up_groups(logger, universe, idcollection_dict, args.goodbefore)
|
|
181
184
|
if type(universe)==int: return 1
|
|
182
185
|
|
|
183
186
|
|
|
187
|
+
# introduce hand-drwn escher map annotation
|
|
188
|
+
if args.escherzip != '-':
|
|
189
|
+
universe = parse_zipped_escher(logger, universe, args.escherzip, args.outdir)
|
|
190
|
+
if type(universe) == int: return 1
|
|
191
|
+
|
|
192
|
+
|
|
184
193
|
|
|
185
194
|
###### POST-PARSING
|
|
186
195
|
|
|
@@ -199,7 +208,7 @@ def main(args, logger):
|
|
|
199
208
|
|
|
200
209
|
# remove disconnected metabolites
|
|
201
210
|
if args.keepdisconn == False:
|
|
202
|
-
universe = remove_disconnected(logger, universe) #
|
|
211
|
+
universe = remove_disconnected(logger, universe) # keep disconnected metabolites when using booster.py
|
|
203
212
|
|
|
204
213
|
|
|
205
214
|
# avoid time-consuming activities
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import pandas as pnd
|
|
2
2
|
import cobra
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
from .manual import get_deprecated_kos
|
|
6
5
|
from .manual import get_rids_with_mancheck_gpr
|
|
7
6
|
from .manual import get_rids_with_mancheck_balancing
|
|
@@ -90,7 +89,7 @@ def check_rstring_arrow(logger, rid, row, addtype='R'):
|
|
|
90
89
|
|
|
91
90
|
|
|
92
91
|
|
|
93
|
-
def
|
|
92
|
+
def check_curator(logger, mrid, row, db, addtype='R'):
|
|
94
93
|
|
|
95
94
|
|
|
96
95
|
# define itemtype:
|
|
@@ -101,23 +100,23 @@ def check_author(logger, mrid, row, db, addtype='R'):
|
|
|
101
100
|
else: itemtype = 'Transporter'
|
|
102
101
|
|
|
103
102
|
|
|
104
|
-
# check if
|
|
103
|
+
# check if curator was indicated:
|
|
105
104
|
if pnd.isna(row['curator']):
|
|
106
105
|
logger.error(f"{itemtype} '{mrid}' has no curator.")
|
|
107
106
|
return 1
|
|
108
107
|
|
|
109
108
|
|
|
110
|
-
# check if the are valid
|
|
111
|
-
|
|
112
|
-
for
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if
|
|
116
|
-
logger.error(f"{itemtype} '{mrid}' has invalid curator: '{
|
|
109
|
+
# check if the are valid curators
|
|
110
|
+
curators = set()
|
|
111
|
+
for curator in row['curator'].split(';'):
|
|
112
|
+
curator = curator.strip()
|
|
113
|
+
curators.add(curator)
|
|
114
|
+
if curator not in db['curators']['username'].to_list():
|
|
115
|
+
logger.error(f"{itemtype} '{mrid}' has invalid curator: '{curator}'.")
|
|
117
116
|
return 1
|
|
118
117
|
|
|
119
118
|
|
|
120
|
-
return list(
|
|
119
|
+
return list(curators)
|
|
121
120
|
|
|
122
121
|
|
|
123
122
|
|
|
@@ -137,7 +136,7 @@ def get_curator_notes(logger, row):
|
|
|
137
136
|
|
|
138
137
|
|
|
139
138
|
|
|
140
|
-
def add_reaction(logger, model, rid,
|
|
139
|
+
def add_reaction(logger, model, rid, curators, row, kr_ids, kegg_reaction_to_others, addtype, outdir):
|
|
141
140
|
|
|
142
141
|
|
|
143
142
|
# define the itemtype:
|
|
@@ -180,7 +179,7 @@ def add_reaction(logger, model, rid, authors, row, kr_ids, kegg_reaction_to_othe
|
|
|
180
179
|
|
|
181
180
|
|
|
182
181
|
# write curators as annotations
|
|
183
|
-
r.annotation['curator_codes'] =
|
|
182
|
+
r.annotation['curator_codes'] = curators
|
|
184
183
|
|
|
185
184
|
|
|
186
185
|
# add annotations to model (same order of Memote)
|
gsrap/parsedb/annotation.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import threading
|
|
2
|
+
import copy
|
|
2
3
|
|
|
3
4
|
import cobra
|
|
4
5
|
|
|
@@ -106,7 +107,7 @@ def translate_annotate_genes(logger, model, idcollection_dict):
|
|
|
106
107
|
|
|
107
108
|
|
|
108
109
|
|
|
109
|
-
def set_up_groups(logger, model, idcollection_dict):
|
|
110
|
+
def set_up_groups(logger, model, idcollection_dict, goodbefore):
|
|
110
111
|
|
|
111
112
|
|
|
112
113
|
logger.debug("Introducing groups...")
|
|
@@ -160,18 +161,27 @@ def set_up_groups(logger, model, idcollection_dict):
|
|
|
160
161
|
model.add_groups([actual_group])
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
# insert custom groups:
|
|
165
|
-
custom_groups = get_custom_groups()
|
|
166
|
-
#
|
|
167
164
|
# create a group for transporters on-the-fly
|
|
165
|
+
custom_groups = get_custom_groups()
|
|
168
166
|
custom_groups['gr_transport'] = []
|
|
169
167
|
for r in model.reactions:
|
|
170
168
|
if len(r.metabolites) == 1 and list(r.metabolites)[0].id.rsplit('_',1)[-1] != 'c': # just exchanges (esclude sinks/demands)
|
|
171
169
|
custom_groups['gr_transport'].append(r.id)
|
|
172
170
|
if len(set([m.id.rsplit('_', 1)[-1] for m in r.metabolites])) > 1: # transport reactions
|
|
173
171
|
custom_groups['gr_transport'].append(r.id)
|
|
174
|
-
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# handle eventual removed reactions as consequence of --goodbefore:
|
|
175
|
+
if type(goodbefore) == list:
|
|
176
|
+
modeled_rids = [r.id for r in model.reactions]
|
|
177
|
+
for group_id in custom_groups.keys():
|
|
178
|
+
for rid in copy.deepcopy(custom_groups[group_id]):
|
|
179
|
+
if rid not in modeled_rids:
|
|
180
|
+
logger.warning(f"Removing reaction '{rid}' from group '{group_id}' as consequence of --goodbefore.")
|
|
181
|
+
custom_groups[group_id].remove(rid)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# actually insert custom groups:
|
|
175
185
|
for group_id in custom_groups.keys():
|
|
176
186
|
actual_group = cobra.core.Group(
|
|
177
187
|
group_id,
|
gsrap/parsedb/introduce.py
CHANGED
|
@@ -3,7 +3,7 @@ import sys
|
|
|
3
3
|
import pandas as pnd
|
|
4
4
|
import cobra
|
|
5
5
|
|
|
6
|
-
from .repeating import
|
|
6
|
+
from .repeating import check_curator
|
|
7
7
|
from .repeating import check_rstring_arrow
|
|
8
8
|
from .repeating import check_gpr
|
|
9
9
|
from .repeating import add_reaction
|
|
@@ -14,7 +14,7 @@ from .manual import get_manual_demands
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to_others, outdir, goodbefore,
|
|
17
|
+
def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to_others, outdir, goodbefore, onlycurator):
|
|
18
18
|
goodbefore_reached = False
|
|
19
19
|
|
|
20
20
|
|
|
@@ -44,24 +44,24 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
44
44
|
goodbefore_reached = True
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
# manage goodbefore/
|
|
47
|
+
# manage goodbefore/onlycurator
|
|
48
48
|
if goodbefore != None and goodbefore_reached:
|
|
49
|
-
if
|
|
49
|
+
if onlycurator == None:
|
|
50
50
|
logger.warning(f"Skipping metabolite '{pure_mid}' as requested with --goodbefore[0] '{goodbefore}'.")
|
|
51
51
|
continue
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
# parse and get curators
|
|
55
|
-
response =
|
|
55
|
+
response = check_curator(logger, pure_mid, row, db, 'M')
|
|
56
56
|
if type(response) == int: return 1
|
|
57
|
-
else:
|
|
57
|
+
else: curators = response
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
# manage goodbefore/
|
|
60
|
+
# manage goodbefore/onlycurator
|
|
61
61
|
if goodbefore != None and goodbefore_reached:
|
|
62
|
-
if
|
|
63
|
-
|
|
64
|
-
logger.warning(f"Skipping metabolite '{pure_mid}' (
|
|
62
|
+
if onlycurator != None and onlycurator not in curators:
|
|
63
|
+
curators_string = '; '.join(curators)
|
|
64
|
+
logger.warning(f"Skipping metabolite '{pure_mid}' (curators '{curators_string}') as requested with --goodbefore[0] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
65
65
|
continue
|
|
66
66
|
|
|
67
67
|
|
|
@@ -122,7 +122,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
122
122
|
eqbiggids.add(eqbiggid)
|
|
123
123
|
if pure_mid not in eqbiggids and eqbiggids != set():
|
|
124
124
|
with open(f"{outdir}/logs/M.inbigg.txt", 'a') as f:
|
|
125
|
-
print(f"Metabolites '{'; '.join(kc_ids)}' already in BiGG as {eqbiggids} ({
|
|
125
|
+
print(f"Metabolites '{'; '.join(kc_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{pure_mid}').", file=f)
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
# add metabolite to model
|
|
@@ -136,7 +136,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
# write curators as annotations
|
|
139
|
-
m.annotation['curator_codes'] =
|
|
139
|
+
m.annotation['curator_codes'] = curators
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
# add annotations to model (same order of Memote)
|
|
@@ -197,7 +197,7 @@ def introduce_metabolites(logger, db, model, idcollection_dict, kegg_compound_to
|
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
|
|
200
|
-
def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore,
|
|
200
|
+
def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore, onlycurator):
|
|
201
201
|
goodbefore_reached = False
|
|
202
202
|
|
|
203
203
|
|
|
@@ -226,24 +226,24 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
226
226
|
goodbefore_reached = True
|
|
227
227
|
|
|
228
228
|
|
|
229
|
-
# manage goodbefore/
|
|
229
|
+
# manage goodbefore/onlycurator
|
|
230
230
|
if goodbefore != None and goodbefore_reached:
|
|
231
|
-
if
|
|
231
|
+
if onlycurator == None:
|
|
232
232
|
logger.warning(f"Skipping reaction '{rid}' as requested with --goodbefore[1] '{goodbefore}'.")
|
|
233
233
|
continue
|
|
234
234
|
|
|
235
235
|
|
|
236
236
|
# parse and get curators
|
|
237
|
-
response =
|
|
237
|
+
response = check_curator(logger, rid, row, db, 'R')
|
|
238
238
|
if type(response) == int: return 1
|
|
239
|
-
else:
|
|
239
|
+
else: curators = response
|
|
240
240
|
|
|
241
241
|
|
|
242
|
-
# manage goodbefore/
|
|
242
|
+
# manage goodbefore/onlycurator
|
|
243
243
|
if goodbefore != None and goodbefore_reached:
|
|
244
|
-
if
|
|
245
|
-
|
|
246
|
-
logger.warning(f"Skipping reaction '{rid}' (
|
|
244
|
+
if onlycurator != None and onlycurator not in curators:
|
|
245
|
+
curators_string = '; '.join(curators)
|
|
246
|
+
logger.warning(f"Skipping reaction '{rid}' (curators '{curators_string}') as requested with --goodbefore[1] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
247
247
|
continue
|
|
248
248
|
|
|
249
249
|
|
|
@@ -284,11 +284,11 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
284
284
|
eqbiggids.add(eqbiggid)
|
|
285
285
|
if rid not in eqbiggids and eqbiggids != set():
|
|
286
286
|
with open(f"{outdir}/logs/R.inbigg.txt", 'a') as f:
|
|
287
|
-
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({
|
|
287
|
+
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{rid}').", file=f)
|
|
288
288
|
|
|
289
289
|
|
|
290
290
|
# add reaction to model
|
|
291
|
-
response = add_reaction(logger, model, rid,
|
|
291
|
+
response = add_reaction(logger, model, rid, curators, row, kr_ids, kegg_reaction_to_others, 'R', outdir)
|
|
292
292
|
if response == 1: return 1
|
|
293
293
|
|
|
294
294
|
|
|
@@ -308,7 +308,7 @@ def introduce_reactions(logger, db, model, idcollection_dict, kegg_reaction_to_o
|
|
|
308
308
|
|
|
309
309
|
|
|
310
310
|
|
|
311
|
-
def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore,
|
|
311
|
+
def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_to_others, outdir, goodbefore, onlycurator):
|
|
312
312
|
goodbefore_reached = False
|
|
313
313
|
|
|
314
314
|
|
|
@@ -373,24 +373,24 @@ def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_t
|
|
|
373
373
|
return 1
|
|
374
374
|
|
|
375
375
|
|
|
376
|
-
# manage goodbefore/
|
|
376
|
+
# manage goodbefore/onlycurator
|
|
377
377
|
if goodbefore != None and goodbefore_reached:
|
|
378
|
-
if
|
|
378
|
+
if onlycurator == None:
|
|
379
379
|
logger.warning(f"Skipping transport '{rid}' as requested with --goodbefore[2] '{goodbefore}'.")
|
|
380
380
|
continue
|
|
381
381
|
|
|
382
382
|
|
|
383
|
-
# parse
|
|
384
|
-
response =
|
|
383
|
+
# parse curator
|
|
384
|
+
response = check_curator(logger, rid, row, db, 'T')
|
|
385
385
|
if type(response) == int: return 1
|
|
386
|
-
else:
|
|
386
|
+
else: curators = response
|
|
387
387
|
|
|
388
388
|
|
|
389
|
-
# manage goodbefore/
|
|
389
|
+
# manage goodbefore/onlycurator
|
|
390
390
|
if goodbefore != None and goodbefore_reached:
|
|
391
|
-
if
|
|
392
|
-
|
|
393
|
-
logger.warning(f"Skipping transport '{rid}' (
|
|
391
|
+
if onlycurator != None and onlycurator not in curators:
|
|
392
|
+
curators_string = '; '.join(curators)
|
|
393
|
+
logger.warning(f"Skipping transport '{rid}' (curators '{curators_string}') as requested with --goodbefore[2] '{goodbefore}' and --onlycurator '{onlycurator}'.")
|
|
394
394
|
continue
|
|
395
395
|
|
|
396
396
|
|
|
@@ -454,11 +454,11 @@ def introduce_transporters(logger, db, model, idcollection_dict, kegg_reaction_t
|
|
|
454
454
|
eqbiggids.add(eqbiggid)
|
|
455
455
|
if rid not in eqbiggids and eqbiggids != set():
|
|
456
456
|
with open(f"{outdir}/logs/T.inbigg.txt", 'a') as f:
|
|
457
|
-
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({
|
|
457
|
+
print(f"Reactions '{'; '.join(kr_ids)}' already in BiGG as {eqbiggids} ({curators} gave '{rid}').", file=f)
|
|
458
458
|
|
|
459
459
|
|
|
460
460
|
# add reaction to model
|
|
461
|
-
response = add_reaction(logger, model, rid,
|
|
461
|
+
response = add_reaction(logger, model, rid, curators, row, kr_ids, kegg_reaction_to_others, 'T', outdir)
|
|
462
462
|
if response == 1: return 1
|
|
463
463
|
rids_parsed.append(rid) # update list of rids in model
|
|
464
464
|
|