seed2lp 2.0.0__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.
Files changed (53) hide show
  1. seed2lp/__init__.py +12 -0
  2. seed2lp/__main__.py +837 -0
  3. seed2lp/_version.py +2 -0
  4. seed2lp/argument.py +717 -0
  5. seed2lp/asp/atom_for_transfers.lp +7 -0
  6. seed2lp/asp/community_heuristic.lp +3 -0
  7. seed2lp/asp/community_search.lp +14 -0
  8. seed2lp/asp/constraints_targets.lp +15 -0
  9. seed2lp/asp/definition_atoms.lp +87 -0
  10. seed2lp/asp/enum-cc.lp +50 -0
  11. seed2lp/asp/flux.lp +70 -0
  12. seed2lp/asp/limit_transfers.lp +9 -0
  13. seed2lp/asp/maximize_flux.lp +2 -0
  14. seed2lp/asp/maximize_produced_target.lp +7 -0
  15. seed2lp/asp/minimize.lp +8 -0
  16. seed2lp/asp/seed-solving.lp +116 -0
  17. seed2lp/asp/seed_external.lp +1 -0
  18. seed2lp/asp/show_seeds.lp +2 -0
  19. seed2lp/asp/show_tranfers.lp +1 -0
  20. seed2lp/asp/test.lp +61 -0
  21. seed2lp/clingo_lpx.py +236 -0
  22. seed2lp/color.py +34 -0
  23. seed2lp/config.yaml +56 -0
  24. seed2lp/description.py +424 -0
  25. seed2lp/file.py +151 -0
  26. seed2lp/flux.py +365 -0
  27. seed2lp/linear.py +431 -0
  28. seed2lp/log_conf.yaml +25 -0
  29. seed2lp/logger.py +112 -0
  30. seed2lp/metabolite.py +46 -0
  31. seed2lp/network.py +1921 -0
  32. seed2lp/reaction.py +207 -0
  33. seed2lp/reasoning.py +459 -0
  34. seed2lp/reasoningcom.py +753 -0
  35. seed2lp/reasoninghybrid.py +791 -0
  36. seed2lp/resmod.py +74 -0
  37. seed2lp/sbml.py +307 -0
  38. seed2lp/scope.py +124 -0
  39. seed2lp/solver.py +333 -0
  40. seed2lp/temp_flux_com.py +74 -0
  41. seed2lp/utils.py +237 -0
  42. seed2lp-2.0.0.dist-info/METADATA +404 -0
  43. seed2lp-2.0.0.dist-info/RECORD +53 -0
  44. seed2lp-2.0.0.dist-info/WHEEL +5 -0
  45. seed2lp-2.0.0.dist-info/entry_points.txt +2 -0
  46. seed2lp-2.0.0.dist-info/licenses/LICENCE.txt +145 -0
  47. seed2lp-2.0.0.dist-info/top_level.txt +2 -0
  48. tests/__init__.py +0 -0
  49. tests/fba.py +147 -0
  50. tests/full_network.py +166 -0
  51. tests/normalization.py +188 -0
  52. tests/target.py +286 -0
  53. tests/utils.py +181 -0
tests/target.py ADDED
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Description:
6
+ Test seed2lp
7
+ """
8
+ from os import path
9
+ from .utils import search_seed
10
+
11
+ ##### ###### ##### DIRECTORIES AND FILES ###################
12
+ TEST_DIR = path.dirname(path.abspath(__file__))
13
+
14
+ # All reaction are not reversible
15
+ # except import/export reaction for exchange metabolite S1, S2 C and G
16
+ INFILE = path.join(TEST_DIR,'network/sbml/toy_paper_no_reversible.sbml')
17
+ ########################################################
18
+
19
+
20
+ ################### FIXED VARIABLES ####################
21
+ RUN_MODE="target"
22
+ ########################################################
23
+
24
+
25
+ ################# EXPECTED SOLUTIONS ###################
26
+
27
+ # Seeds for Reasoning, filter, Gues-Check, Guess-Check Diversty and Hybrid
28
+ SEEDS_SUBMIN_TAF= [{"M_B_c", "M_D_c", "M_E_c"},
29
+ {"M_B_c", "M_D_c", "M_I_c"},
30
+ {"M_B_c", "M_D_c", "M_H_c"},
31
+ {"M_B_c", "M_I_c", "M_S2_e"},
32
+ {"M_B_c", "M_E_c", "M_S2_e"},
33
+ {"M_B_c", "M_H_c", "M_S2_e"},
34
+ {"M_I_c", "M_J_c", "M_S1_e", "M_S2_e"},
35
+ {"M_D_c", "M_I_c", "M_J_c", "M_S1_e"},
36
+ {"M_H_c", "M_J_c", "M_S1_e", "M_S2_e"},
37
+ {"M_E_c", "M_J_c", "M_S1_e", "M_S2_e"},
38
+ {"M_D_c", "M_H_c", "M_J_c", "M_S1_e"},
39
+ {"M_D_c", "M_E_c", "M_J_c", "M_S1_e"}
40
+ ]
41
+ SIZE_SUBMIN_TAF=len(SEEDS_SUBMIN_TAF)
42
+
43
+ SEEDS_MIN_TAF = [{"M_B_c", "M_D_c", "M_E_c"} ,
44
+ {"M_B_c", "M_D_c", "M_I_c"} ,
45
+ {"M_B_c", "M_D_c", "M_H_c"} ,
46
+ {"M_B_c", "M_I_c", "M_S2_e"} ,
47
+ {"M_B_c", "M_E_c", "M_S2_e"} ,
48
+ {"M_B_c", "M_H_c", "M_S2_e"}
49
+ ]
50
+ SIZE_MIN_TAF=len(SEEDS_MIN_TAF)
51
+
52
+
53
+ SEEDS_SUBMIN_TAS= [{"M_B_c", "M_D_c", "M_E_c"},
54
+ {"M_B_c", "M_D_c", "M_I_c"},
55
+ {"M_B_c", "M_D_c", "M_H_c"},
56
+ {"M_B_c", "M_D_c", "M_F_c"},
57
+ {"M_B_c", "M_I_c", "M_S2_e"},
58
+ {"M_B_c", "M_E_c", "M_S2_e"},
59
+ {"M_B_c", "M_H_c", "M_S2_e"},
60
+ {"M_B_c", "M_F_c", "M_S2_e"},
61
+ {"M_I_c", "M_J_c", "M_S1_e", "M_S2_e"},
62
+ {"M_F_c", "M_J_c", "M_S1_e", "M_S2_e"},
63
+ {"M_D_c", "M_I_c", "M_J_c", "M_S1_e"},
64
+ {"M_D_c", "M_F_c", "M_J_c", "M_S1_e"},
65
+ {"M_H_c", "M_J_c", "M_S1_e", "M_S2_e"},
66
+ {"M_E_c", "M_J_c", "M_S1_e", "M_S2_e"},
67
+ {"M_D_c", "M_H_c", "M_J_c", "M_S1_e"},
68
+ {"M_D_c", "M_E_c", "M_J_c", "M_S1_e"}
69
+ ]
70
+ SIZE_SUBMIN_TAS=len(SEEDS_SUBMIN_TAS)
71
+
72
+ SEEDS_MIN_TAS = [{"M_B_c", "M_D_c", "M_E_c"} ,
73
+ {"M_B_c", "M_D_c", "M_I_c"} ,
74
+ {"M_B_c", "M_D_c", "M_H_c"} ,
75
+ {"M_B_c", "M_D_c", "M_F_c"} ,
76
+ {"M_B_c", "M_I_c", "M_S2_e"} ,
77
+ {"M_B_c", "M_E_c", "M_S2_e"} ,
78
+ {"M_B_c", "M_H_c", "M_S2_e"},
79
+ {"M_B_c", "M_F_c", "M_S2_e"} ,
80
+ ]
81
+ SIZE_MIN_TAS=len(SEEDS_MIN_TAS)
82
+
83
+ ########################################################
84
+
85
+
86
+
87
+
88
+
89
+
90
+ ######################### TESTS ########################
91
+ #TODO:
92
+ # - test with accumulation
93
+ # - test keep import reaction and topological injection
94
+ # - find Network to have different value in Reasoning / Filter / Gues_check / Guess_Check_Div
95
+ # - find Network to have different value with accumulation authorized
96
+ # - test without maximization for hybrid
97
+ # - test unsat
98
+ # - test possible_seeds (subset of seed that maximize number of producible targets)
99
+ # - test changing objective
100
+ # - test target file
101
+
102
+ # solve values: 'reasoning', 'filter', 'guess_check', 'guess_check_div', 'hybrid'
103
+ # optim values: 'submin', 'min'
104
+
105
+ # ---------------------- TARGET ARE FORBIDDEN ----------------------
106
+ # ----------- SUBSETMIN -----------
107
+ def test_reasoning_submin_taf():
108
+ solve="reasoning"
109
+ optim="submin"
110
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
111
+ for solution in list_solution:
112
+ assert set(solution) in SEEDS_SUBMIN_TAF
113
+ assert len(list_solution) == SIZE_SUBMIN_TAF
114
+
115
+ def test_filter_submin_taf():
116
+ solve="filter"
117
+ optim="submin"
118
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
119
+ for solution in list_solution:
120
+ assert set(solution) in SEEDS_SUBMIN_TAF
121
+ assert len(list_solution) == SIZE_SUBMIN_TAF
122
+
123
+ def test_gc_submin_taf():
124
+ solve="guess_check"
125
+ optim="submin"
126
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
127
+ for solution in list_solution:
128
+ assert set(solution) in SEEDS_SUBMIN_TAF
129
+ assert len(list_solution) == SIZE_SUBMIN_TAF
130
+
131
+ def test_gcd_submin_taf():
132
+ solve="guess_check_div"
133
+ optim="submin"
134
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
135
+ for solution in list_solution:
136
+ assert set(solution) in SEEDS_SUBMIN_TAF
137
+ assert len(list_solution) == SIZE_SUBMIN_TAF
138
+
139
+
140
+ def test_hybrid_submin_taf():
141
+ solve="hybrid"
142
+ optim="submin"
143
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
144
+ for solution in list_solution:
145
+ assert set(solution) in SEEDS_SUBMIN_TAF
146
+ assert len(list_solution) == SIZE_SUBMIN_TAF
147
+
148
+
149
+ # ----------- MINIMIZE -----------
150
+ def test_reasoning_min_taf():
151
+ solve="reasoning"
152
+ optim="min"
153
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
154
+ for solution in list_solution:
155
+ assert set(solution) in SEEDS_MIN_TAF
156
+ assert len(list_solution) == SIZE_MIN_TAF
157
+
158
+ def test_filter_min_taf():
159
+ solve="filter"
160
+ optim="min"
161
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
162
+ for solution in list_solution:
163
+ assert set(solution) in SEEDS_MIN_TAF
164
+ assert len(list_solution) == SIZE_MIN_TAF
165
+
166
+ def test_gc_min_taf():
167
+ solve="guess_check"
168
+ optim="min"
169
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
170
+ for solution in list_solution:
171
+ assert set(solution) in SEEDS_MIN_TAF
172
+ assert len(list_solution) == SIZE_MIN_TAF
173
+
174
+ def test_gcd_min_taf():
175
+ solve="guess_check_div"
176
+ optim="min"
177
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
178
+ for solution in list_solution:
179
+ assert set(solution) in SEEDS_MIN_TAF
180
+ assert len(list_solution) == SIZE_MIN_TAF
181
+
182
+
183
+ def test_hybrid_min_taf():
184
+ solve="hybrid"
185
+ optim="min"
186
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim)
187
+ for solution in list_solution:
188
+ assert set(solution) in SEEDS_MIN_TAF
189
+ assert len(list_solution) == SIZE_MIN_TAF
190
+
191
+
192
+ # ---------------------- TARGET AS SEEDS ----------------------
193
+ # ----------- SUBSETMIN -----------
194
+ def test_reasoning_submin_tas():
195
+ solve="reasoning"
196
+ optim="submin"
197
+ targets_as_seeds=True
198
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
199
+ for solution in list_solution:
200
+ assert set(solution) in SEEDS_SUBMIN_TAS
201
+ assert len(list_solution) == SIZE_SUBMIN_TAS
202
+
203
+ def test_filter_submin_tas():
204
+ solve="filter"
205
+ optim="submin"
206
+ targets_as_seeds=True
207
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
208
+ for solution in list_solution:
209
+ assert set(solution) in SEEDS_SUBMIN_TAS
210
+ assert len(list_solution) == SIZE_SUBMIN_TAS
211
+
212
+ def test_gc_submin_tas():
213
+ solve="guess_check"
214
+ optim="submin"
215
+ targets_as_seeds=True
216
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
217
+ for solution in list_solution:
218
+ assert set(solution) in SEEDS_SUBMIN_TAS
219
+ assert len(list_solution) == SIZE_SUBMIN_TAS
220
+
221
+ def test_gcd_submin_tas():
222
+ solve="guess_check_div"
223
+ optim="submin"
224
+ targets_as_seeds=True
225
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
226
+ for solution in list_solution:
227
+ assert set(solution) in SEEDS_SUBMIN_TAS
228
+ assert len(list_solution) == SIZE_SUBMIN_TAS
229
+
230
+
231
+ def test_hybrid_submin_tas():
232
+ solve="hybrid"
233
+ optim="submin"
234
+ targets_as_seeds=True
235
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
236
+ for solution in list_solution:
237
+ assert set(solution) in SEEDS_SUBMIN_TAS
238
+ assert len(list_solution) == SIZE_SUBMIN_TAS
239
+
240
+
241
+ # ----------- MINIMIZE -----------
242
+ def test_reasoning_min_tas():
243
+ solve="reasoning"
244
+ optim="min"
245
+ targets_as_seeds=True
246
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
247
+ for solution in list_solution:
248
+ assert set(solution) in SEEDS_MIN_TAS
249
+ assert len(list_solution) == SIZE_MIN_TAS
250
+
251
+ def test_filter_min_tas():
252
+ solve="filter"
253
+ optim="min"
254
+ targets_as_seeds=True
255
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
256
+ for solution in list_solution:
257
+ assert set(solution) in SEEDS_MIN_TAS
258
+ assert len(list_solution) == SIZE_MIN_TAS
259
+
260
+ def test_gc_min_tas():
261
+ solve="guess_check"
262
+ optim="min"
263
+ targets_as_seeds=True
264
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
265
+ for solution in list_solution:
266
+ assert set(solution) in SEEDS_MIN_TAS
267
+ assert len(list_solution) == SIZE_MIN_TAS
268
+
269
+ def test_gcd_min_tas():
270
+ solve="guess_check_div"
271
+ optim="min"
272
+ targets_as_seeds=True
273
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
274
+ for solution in list_solution:
275
+ assert set(solution) in SEEDS_MIN_TAS
276
+ assert len(list_solution) == SIZE_MIN_TAS
277
+
278
+
279
+ def test_hybrid_min_tas():
280
+ solve="hybrid"
281
+ optim="min"
282
+ targets_as_seeds=True
283
+ list_solution=search_seed(INFILE, RUN_MODE, solve, optim, targets_as_seeds)
284
+ for solution in list_solution:
285
+ assert set(solution) in SEEDS_MIN_TAS
286
+ assert len(list_solution) == SIZE_MIN_TAS
tests/utils.py ADDED
@@ -0,0 +1,181 @@
1
+ from os import path
2
+ from seed2lp.network import Network
3
+ from seed2lp.reasoning import Reasoning
4
+ from seed2lp.linear import Hybrid, FBA
5
+ from seed2lp.__main__ import get_reaction_options, get_input_datas
6
+ from seed2lp import logger
7
+ from seed2lp.file import is_valid_dir
8
+
9
+ ################ DIRECTORIES AND FILES ###################
10
+ TEST_DIR = path.dirname(path.abspath(__file__))
11
+ RESULT_DIR=path.join(TEST_DIR,"results")
12
+ TMP_DIR=path.join(TEST_DIR,"tmp")
13
+ is_valid_dir(RESULT_DIR)
14
+ is_valid_dir(TMP_DIR)
15
+ logger.set_log_dir(path.join(TEST_DIR, RESULT_DIR,"logs"))
16
+ is_valid_dir(logger.LOG_DIR)
17
+ ########################################################
18
+
19
+
20
+ ################### FIXED VARIABLES ####################
21
+ TIME_LIMIT = 0
22
+ NB_SOLUTION = 0
23
+ CLINGO_CONF='jumpy'
24
+ CLINGO_STRAT="none"
25
+ INTERSECTION=False
26
+ UNION=False
27
+ VERBOSE=False
28
+ ########################################################
29
+
30
+ ####################### METHODS ########################
31
+
32
+ # solve values: 'reasoning', 'filter', 'guess_check', 'guess_check_div', 'hybrid'
33
+ # optim values: 'submin', 'min'
34
+ def search_seed(infile:str, run_mode:str, solve:str, optim:str, targets_as_seeds:bool=False):
35
+ """
36
+ Test FN without accumulation, remove import reaction, for:
37
+ - Remove import reaction
38
+ - No accumulation
39
+ - Subset minimal / Minimize
40
+ - Reasoning / Filter / Guess_Check / Guess_Check_div / Hybrid
41
+ - Maximization
42
+ - No file given, no objectif modification
43
+ """
44
+ reasoning_submin = list()
45
+ filter_submin = list()
46
+ gc_submin = list()
47
+ gcd_submin = list()
48
+ reasoning_min = list()
49
+ filter_min = list()
50
+ gc_min = list()
51
+ gcd_min = list()
52
+ hybrid_submin = list()
53
+ hybrid_min = list()
54
+ fba_submin = list()
55
+ fba_min = list()
56
+
57
+ topological_injection= False
58
+ keep_import_reactions= False
59
+ accumulation = False
60
+ maximization = True
61
+
62
+
63
+
64
+ match optim:
65
+ case "submin":
66
+ subset_minimal = True
67
+ minimize = False
68
+ case "min":
69
+ subset_minimal = False
70
+ minimize = True
71
+ case _:
72
+ subset_minimal = True
73
+ minimize = True
74
+
75
+
76
+ options=get_reaction_options(keep_import_reactions,topological_injection,
77
+ targets_as_seeds,maximization,run_mode,accumulation,solve)
78
+
79
+
80
+
81
+
82
+ network= get_network(infile, run_mode, targets_as_seeds, topological_injection,
83
+ keep_import_reactions, accumulation, opt_short=options['short'])
84
+ network.convert_to_facts()
85
+ network.simplify()
86
+
87
+ if run_mode != "fba":
88
+ model = Reasoning(run_mode, solve, network, TIME_LIMIT, NB_SOLUTION,
89
+ CLINGO_CONF,CLINGO_STRAT, INTERSECTION, UNION, minimize, subset_minimal,
90
+ TMP_DIR, options['short'], VERBOSE)
91
+ model.search_seed()
92
+
93
+ model = Hybrid(run_mode, solve, network, TIME_LIMIT, NB_SOLUTION,
94
+ CLINGO_CONF,CLINGO_STRAT, INTERSECTION, UNION, minimize, subset_minimal,
95
+ maximization, TMP_DIR, options['short'], VERBOSE)
96
+ model.search_seed()
97
+ else:
98
+ model = FBA(run_mode, network, TIME_LIMIT, NB_SOLUTION,
99
+ CLINGO_CONF,CLINGO_STRAT, INTERSECTION, UNION, minimize, subset_minimal,
100
+ maximization, TMP_DIR, options['short'], VERBOSE)
101
+ model.search_seed()
102
+
103
+ for result in network.result_seeds:
104
+ match result.solver_type, result.search_mode,result.search_type:
105
+ case "REASONING","Subset Minimal","Enumeration":
106
+ reasoning_submin.append(result.seeds_list)
107
+ case "REASONING FILTER","Subset Minimal","Enumeration":
108
+ filter_submin.append(result.seeds_list)
109
+ case "REASONING GUESS-CHECK","Subset Minimal","Enumeration":
110
+ gc_submin.append(result.seeds_list)
111
+ case "REASONING GUESS-CHECK DIVERSITY","Subset Minimal","Enumeration":
112
+ gcd_submin.append(result.seeds_list)
113
+
114
+ case "REASONING","Minimize","Enumeration":
115
+ reasoning_min.append(result.seeds_list)
116
+ case "REASONING FILTER","Minimize","Enumeration":
117
+ filter_min.append(result.seeds_list)
118
+ case "REASONING GUESS-CHECK","Minimize","Enumeration":
119
+ gc_min.append(result.seeds_list)
120
+ case "REASONING GUESS-CHECK DIVERSITY","Minimize","Enumeration":
121
+ gcd_min.append(result.seeds_list)
122
+
123
+ case "HYBRID","Subset Minimal","Enumeration":
124
+ hybrid_submin.append(result.seeds_list)
125
+
126
+ case "HYBRID","Minimize","Enumeration":
127
+ hybrid_min.append(result.seeds_list)
128
+
129
+ case "FBA","Subset Minimal","Enumeration":
130
+ fba_submin.append(result.seeds_list)
131
+
132
+ case "FBA","Minimize","Enumeration":
133
+ fba_min.append(result.seeds_list)
134
+
135
+ # solve value : 'reasoning', 'filter', 'guess_check', 'guess_check_div', 'hybrid', 'all' (-for FBA)
136
+ match solve, optim:
137
+ case 'reasoning','submin':
138
+ return reasoning_submin
139
+ case 'filter','submin':
140
+ return filter_submin
141
+ case 'guess_check','submin':
142
+ return gc_submin
143
+ case 'guess_check_div','submin':
144
+ return gcd_submin
145
+ case 'hybrid','submin':
146
+ return hybrid_submin
147
+ case 'all','submin':
148
+ return fba_submin
149
+
150
+
151
+ case 'reasoning','min':
152
+ return reasoning_min
153
+ case 'filter','min':
154
+ return filter_min
155
+ case 'guess_check','min':
156
+ return gc_min
157
+ case 'guess_check_div','min':
158
+ return gcd_min
159
+ case 'hybrid','min':
160
+ return hybrid_min
161
+ case 'all','min':
162
+ return fba_min
163
+
164
+
165
+ # TODO: Possible seeds, forbidden seeds, seeds, target and obejctive modification
166
+ def get_network(infile:str, run_mode:str, targets_as_seeds:bool,
167
+ topological_injection:bool, keep_import_reactions:bool, accumulation:bool=False,
168
+ seeds_file:str=None, forbidden_seeds_file:str=None, possible_seeds_file:str=None,
169
+ opt_short:str="test"):
170
+
171
+ logger.get_logger(infile, opt_short, VERBOSE)
172
+ input_dict = get_input_datas(seeds_file, forbidden_seeds_file, possible_seeds_file)
173
+ network = Network(infile, run_mode, targets_as_seeds,
174
+ topological_injection, keep_import_reactions,
175
+ input_dict, accumulation)
176
+
177
+ if not targets_as_seeds:
178
+ network.forbidden_seeds += network.targets
179
+ return network
180
+
181
+ ########################################################