seed2lp 2.0.0__py3-none-any.whl → 2.1.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.
- seed2lp/__main__.py +124 -70
- seed2lp/_version.py +1 -1
- seed2lp/argument.py +6 -6
- seed2lp/asp/enum-cc.lp +3 -3
- seed2lp/clingo_lpx.py +14 -6
- seed2lp/description.py +44 -33
- seed2lp/file.py +6 -3
- seed2lp/flux.py +23 -17
- seed2lp/linear.py +37 -36
- seed2lp/log_conf.yaml +4 -4
- seed2lp/logger.py +83 -39
- seed2lp/network.py +55 -68
- seed2lp/reaction.py +4 -2
- seed2lp/reasoning.py +29 -26
- seed2lp/reasoningcom.py +27 -20
- seed2lp/reasoninghybrid.py +30 -25
- seed2lp/sbml.py +4 -2
- seed2lp/scope.py +14 -12
- seed2lp/solver.py +44 -41
- seed2lp/utils.py +7 -3
- seed2lp-2.1.0.dist-info/METADATA +621 -0
- {seed2lp-2.0.0.dist-info → seed2lp-2.1.0.dist-info}/RECORD +28 -28
- {seed2lp-2.0.0.dist-info → seed2lp-2.1.0.dist-info}/WHEEL +1 -1
- tests/normalization.py +8 -8
- tests/utils.py +18 -10
- seed2lp-2.0.0.dist-info/METADATA +0 -404
- {seed2lp-2.0.0.dist-info → seed2lp-2.1.0.dist-info}/entry_points.txt +0 -0
- {seed2lp-2.0.0.dist-info → seed2lp-2.1.0.dist-info}/licenses/LICENCE.txt +0 -0
- {seed2lp-2.0.0.dist-info → seed2lp-2.1.0.dist-info}/top_level.txt +0 -0
seed2lp/__main__.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import argparse
|
|
6
|
+
import argparse, logging
|
|
7
7
|
|
|
8
8
|
from time import time
|
|
9
9
|
from sys import exit
|
|
@@ -21,11 +21,13 @@ from .description import Description
|
|
|
21
21
|
from .file import load_json
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
from .scope import Scope
|
|
24
|
-
from . import logger
|
|
24
|
+
#from . import logger
|
|
25
|
+
from .logger import get_logger#, set_log_dir
|
|
25
26
|
|
|
26
27
|
#Global variable needed
|
|
27
28
|
PROJECT_DIR = path.dirname(path.abspath(__file__))
|
|
28
|
-
CLEAN_TEMP=
|
|
29
|
+
CLEAN_TEMP=True
|
|
30
|
+
LOG_DIR:str
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
####################### FUNCTIONS ##########################
|
|
@@ -186,7 +188,7 @@ def chek_inputs(sbml_file:str, input_dict:dict):
|
|
|
186
188
|
raise ValueError(f"Metabolite {metabolite} does not exist in network file {sbml_file}\n")
|
|
187
189
|
|
|
188
190
|
|
|
189
|
-
def get_input_datas(seeds_file:str=None,
|
|
191
|
+
def get_input_datas(logger:logging, seeds_file:str=None,
|
|
190
192
|
forbidden_seeds:str=None, possible_seeds:str=None,
|
|
191
193
|
forbidden_transfers_file:str=None):
|
|
192
194
|
"""Get data from files given by user
|
|
@@ -202,30 +204,30 @@ def get_input_datas(seeds_file:str=None,
|
|
|
202
204
|
input_dict = dict()
|
|
203
205
|
if seeds_file:
|
|
204
206
|
if file.file_is_empty(seeds_file):
|
|
205
|
-
logger.
|
|
207
|
+
logger.warning(f"\n{seeds_file} is empty.\nPlease check your file and launch again\n")
|
|
206
208
|
else:
|
|
207
209
|
input_dict["Seeds"] = utils.get_ids_from_file(seeds_file, 'seed_user')
|
|
208
210
|
if forbidden_seeds:
|
|
209
211
|
if file.file_is_empty(forbidden_seeds):
|
|
210
|
-
logger.
|
|
212
|
+
logger.warning(f"\n{forbidden_seeds} is empty.\nPlease check your file and launch again\n")
|
|
211
213
|
else:
|
|
212
214
|
input_dict["Forbidden seeds"] = utils.get_ids_from_file(forbidden_seeds, 'forbidden')
|
|
213
215
|
if possible_seeds:
|
|
214
216
|
if file.file_is_empty(possible_seeds):
|
|
215
|
-
logger.
|
|
217
|
+
logger.warning(f"\n{possible_seeds} is empty.\nPlease check your file and launch again\n")
|
|
216
218
|
possible_seeds=None
|
|
217
219
|
else:
|
|
218
220
|
input_dict["Possible seeds"] = utils.get_ids_from_file(possible_seeds, 'sub_seed')
|
|
219
221
|
if forbidden_transfers_file:
|
|
220
222
|
if file.file_is_empty(forbidden_transfers_file):
|
|
221
|
-
logger.
|
|
223
|
+
logger.warning(f"\n{forbidden_transfers_file} is empty.\nPlease check your file and launch again\n")
|
|
222
224
|
#TODO: Finish forbidden transfers file
|
|
223
225
|
#else:
|
|
224
226
|
# input_dict["Forbidden transfers"] = utils.get_list_transfers(forbidden_transfers_file)
|
|
225
227
|
return input_dict
|
|
226
228
|
|
|
227
229
|
|
|
228
|
-
def get_targets(targets_file:str, input_dict:dict, is_community:bool) -> dict :
|
|
230
|
+
def get_targets(logger:logging,targets_file:str, input_dict:dict, is_community:bool) -> dict :
|
|
229
231
|
"""Get metabolites target and objective reaction from file
|
|
230
232
|
Check if the given data exist into SBML file
|
|
231
233
|
ONLY USED WITH TARGET MODE
|
|
@@ -240,13 +242,13 @@ def get_targets(targets_file:str, input_dict:dict, is_community:bool) -> dict :
|
|
|
240
242
|
"""
|
|
241
243
|
|
|
242
244
|
if file.file_is_empty(targets_file):
|
|
243
|
-
logger.
|
|
245
|
+
logger.warning(f"\n{targets_file} is empty.\nPlease check your file and launch again\n")
|
|
244
246
|
exit(1)
|
|
245
247
|
try:
|
|
246
248
|
input_dict["Targets"], input_dict["Objective"] = utils.get_targets_from_file(targets_file, is_community)
|
|
247
249
|
except ValueError as ve:
|
|
248
|
-
logger.
|
|
249
|
-
logger.
|
|
250
|
+
logger.error(str(ve))
|
|
251
|
+
logger.warning("Please check your file and launch again\n")
|
|
250
252
|
exit(1)
|
|
251
253
|
except NotImplementedError as nie:
|
|
252
254
|
print(str(nie))
|
|
@@ -288,7 +290,7 @@ def get_temp_dir(args):
|
|
|
288
290
|
return file.is_valid_dir(temp)
|
|
289
291
|
|
|
290
292
|
|
|
291
|
-
def init_s2pl(args:dict, run_mode:str, is_community:bool=False):
|
|
293
|
+
def init_s2pl(log_dir:str, args:dict, run_mode:str, is_community:bool=False):
|
|
292
294
|
"""Check and validate input data, and get the options used
|
|
293
295
|
|
|
294
296
|
Args:
|
|
@@ -323,7 +325,16 @@ def init_s2pl(args:dict, run_mode:str, is_community:bool=False):
|
|
|
323
325
|
infile=args['infile']
|
|
324
326
|
elif 'comfile' in args:
|
|
325
327
|
infile=args['comfile']
|
|
326
|
-
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
#logger=get_logger(infile, options["short"], args['verbose'])
|
|
331
|
+
#get_logger(infile, options["short"], LOG_DIR, args['verbose'])
|
|
332
|
+
logger, log_path = get_logger(
|
|
333
|
+
log_dir=log_dir,
|
|
334
|
+
sbml_file=infile,
|
|
335
|
+
short_option= options["short"],
|
|
336
|
+
verbose=args['verbose']
|
|
337
|
+
)
|
|
327
338
|
|
|
328
339
|
temp = get_temp_dir(args)
|
|
329
340
|
|
|
@@ -341,16 +352,16 @@ def init_s2pl(args:dict, run_mode:str, is_community:bool=False):
|
|
|
341
352
|
###############################################################
|
|
342
353
|
|
|
343
354
|
# Getting the networks from sbml file
|
|
344
|
-
input_dict = get_input_datas(args['seeds_file'], args['forbidden_seeds_file'],
|
|
355
|
+
input_dict = get_input_datas(logger, args['seeds_file'], args['forbidden_seeds_file'],
|
|
345
356
|
args['possible_seeds_file'],forbidden_transfers_file)
|
|
346
357
|
if 'targets_file' in args and args['targets_file']: # only in target mode
|
|
347
|
-
input_dict = get_targets(args['targets_file'], input_dict, is_community)
|
|
358
|
+
input_dict = get_targets(logger, args['targets_file'], input_dict, is_community)
|
|
348
359
|
if 'objective' in args and args['objective']: # only in full network mode
|
|
349
360
|
input_dict = get_objective(args['objective'], input_dict)
|
|
350
|
-
return options, input_dict, out_dir, temp
|
|
361
|
+
return options, input_dict, out_dir, temp, logger, log_path
|
|
351
362
|
|
|
352
363
|
|
|
353
|
-
def initiate_results(network:Network, options:dict, args:dict, run_mode:str):
|
|
364
|
+
def initiate_results(logger:logging, network:Network, options:dict, args:dict, run_mode:str):
|
|
354
365
|
"""Initiate the result dictionnary with users options and given data such as forbidden seed,
|
|
355
366
|
possible seed and defined seeds.
|
|
356
367
|
|
|
@@ -378,7 +389,7 @@ def initiate_results(network:Network, options:dict, args:dict, run_mode:str):
|
|
|
378
389
|
if args['mode'] == 'minimize' or args['mode'] == 'all':
|
|
379
390
|
user_data['POSSIBLE SEEDS'] = network.possible_seeds
|
|
380
391
|
else:
|
|
381
|
-
logger.
|
|
392
|
+
logger.error("Possible seed can be used only with minimize mode")
|
|
382
393
|
exit(1)
|
|
383
394
|
|
|
384
395
|
res_option['REACTION'] = options['reaction']
|
|
@@ -423,7 +434,7 @@ def initiate_results(network:Network, options:dict, args:dict, run_mode:str):
|
|
|
423
434
|
|
|
424
435
|
|
|
425
436
|
#----------------------- SEED2LP ---------------------------
|
|
426
|
-
def run_seed2lp(args:dict, run_mode):
|
|
437
|
+
def run_seed2lp(args:dict, run_mode, log_dir:str):
|
|
427
438
|
"""Launch seed searching for one network after normalising it.
|
|
428
439
|
|
|
429
440
|
Args:
|
|
@@ -433,24 +444,24 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
433
444
|
subset_minimal=False
|
|
434
445
|
solutions = dict()
|
|
435
446
|
|
|
436
|
-
options, input_dict, out_dir, temp = init_s2pl(args, run_mode)
|
|
447
|
+
options, input_dict, out_dir, temp, logger, log_path = init_s2pl(log_dir, args, run_mode)
|
|
437
448
|
# Verify if input data exist into sbml file
|
|
438
449
|
try:
|
|
439
450
|
chek_inputs(args['infile'], input_dict)
|
|
440
451
|
except ValueError as e :
|
|
441
|
-
logger.
|
|
452
|
+
logger.error(str(e))
|
|
442
453
|
exit(1)
|
|
443
454
|
|
|
444
455
|
time_data_extraction = time()
|
|
445
456
|
network = Network(args['infile'], run_mode, args['targets_as_seeds'],
|
|
446
457
|
args['topological_injection'], args['keep_import_reactions'],
|
|
447
|
-
input_dict, args['accumulation'])
|
|
458
|
+
input_dict, args['accumulation'], verbose=args['verbose'])
|
|
448
459
|
|
|
449
460
|
|
|
450
461
|
time_data_extraction = time() - time_data_extraction
|
|
451
462
|
|
|
452
463
|
|
|
453
|
-
results = initiate_results(network,options,args,run_mode)
|
|
464
|
+
results = initiate_results(logger, network,options,args,run_mode)
|
|
454
465
|
network.convert_to_facts()
|
|
455
466
|
|
|
456
467
|
if args['instance']:
|
|
@@ -478,16 +489,16 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
478
489
|
end_message = " aborted! No Objective found.\n"
|
|
479
490
|
match run_solve,run_mode:
|
|
480
491
|
case _,"target":
|
|
481
|
-
logger.
|
|
492
|
+
logger.error(f"Mode Target {end_message}")
|
|
482
493
|
case 'filter','full':
|
|
483
|
-
logger.
|
|
494
|
+
logger.error(f"Solve Filter {end_message}")
|
|
484
495
|
case 'guess_check','full':
|
|
485
|
-
logger.
|
|
496
|
+
logger.error(f"Solve Guess Check {end_message}")
|
|
486
497
|
case 'guess_check_div','full':
|
|
487
|
-
logger.
|
|
498
|
+
logger.error(f"Solve Guess Check Diversity {end_message}")
|
|
488
499
|
# In reasoning classic, in Full Network, no need to have an objective reaction (event it is deleted)
|
|
489
500
|
case 'all','full': # | 'reasoning','target':
|
|
490
|
-
model = Reasoning(run_mode, "reasoning", network, args['time_limit'], args['number_solution'],
|
|
501
|
+
model = Reasoning(run_mode, "reasoning", network, log_path, args['time_limit'], args['number_solution'],
|
|
491
502
|
args['clingo_configuration'], args['clingo_strategy'],
|
|
492
503
|
args['intersection'], args['union'], minimize, subset_minimal,
|
|
493
504
|
temp, options['short'],
|
|
@@ -497,13 +508,13 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
497
508
|
results["RESULTS"] = solutions
|
|
498
509
|
# Intermediar saving in case of hybrid mode fails
|
|
499
510
|
file.save(f'{network.name}_{options["short"]}_results',out_dir, results, 'json')
|
|
500
|
-
logger.
|
|
511
|
+
logger.error(f"Solve Filter / Guess Check / Guess Check Diversity {end_message}")
|
|
501
512
|
solutions['REASONING-OTHER'] = "No objective found"
|
|
502
513
|
elif run_mode == "target" and not network.targets:
|
|
503
|
-
logger.
|
|
514
|
+
logger.error(f"Mode REASONING aborted! No target found")
|
|
504
515
|
solutions['REASONING'] = "No target found"
|
|
505
516
|
else:
|
|
506
|
-
model = Reasoning(run_mode, run_solve, network, args['time_limit'], args['number_solution'],
|
|
517
|
+
model = Reasoning(run_mode, run_solve, network, log_path, args['time_limit'], args['number_solution'],
|
|
507
518
|
args['clingo_configuration'], args['clingo_strategy'],
|
|
508
519
|
args['intersection'], args['union'], minimize, subset_minimal,
|
|
509
520
|
temp, options['short'],
|
|
@@ -516,10 +527,10 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
516
527
|
|
|
517
528
|
if run_solve == "hybrid" or run_solve == 'all':
|
|
518
529
|
if not network.objectives or network.is_objective_error:
|
|
519
|
-
logger.
|
|
530
|
+
logger.error(f"Mode HYBRID aborted! No objective found")
|
|
520
531
|
solutions['HYBRID'] = "No objective found"
|
|
521
532
|
else:
|
|
522
|
-
model = Hybrid(run_mode, run_solve, network, args['time_limit'], args['number_solution'],
|
|
533
|
+
model = Hybrid(run_mode, run_solve, network, log_path, args['time_limit'], args['number_solution'],
|
|
523
534
|
args['clingo_configuration'], args['clingo_strategy'],
|
|
524
535
|
args['intersection'], args['union'], minimize, subset_minimal,
|
|
525
536
|
args['maximize_flux'], temp,
|
|
@@ -529,10 +540,10 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
529
540
|
results["RESULTS"] = solutions
|
|
530
541
|
case "fba":
|
|
531
542
|
if not network.objectives or network.is_objective_error:
|
|
532
|
-
logger.
|
|
543
|
+
logger.error(f"Mode FBA aborted! No objective found")
|
|
533
544
|
solutions['FBA'] = "No objective found"
|
|
534
545
|
else:
|
|
535
|
-
model = FBA(run_mode, network, args['time_limit'], args['number_solution'],
|
|
546
|
+
model = FBA(run_mode, network, log_path, args['time_limit'], args['number_solution'],
|
|
536
547
|
args['clingo_configuration'], args['clingo_strategy'],
|
|
537
548
|
args['intersection'], args['union'], minimize, subset_minimal,
|
|
538
549
|
args['maximize_flux'], temp,
|
|
@@ -555,7 +566,7 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
555
566
|
time_mess += f'\nTIME {name.center(namewidth)}: {value}'
|
|
556
567
|
|
|
557
568
|
print(time_mess)
|
|
558
|
-
logger.
|
|
569
|
+
logger.info(time_mess)
|
|
559
570
|
print("\n")
|
|
560
571
|
|
|
561
572
|
# Save the result into json file
|
|
@@ -573,7 +584,7 @@ def run_seed2lp(args:dict, run_mode):
|
|
|
573
584
|
|
|
574
585
|
|
|
575
586
|
#------------------ COMMUNITY SEED SEARCHING -------------------
|
|
576
|
-
def community(args:argparse, run_mode):
|
|
587
|
+
def community(args:argparse, run_mode, log_dir:str):
|
|
577
588
|
"""Launch seed searching for a community after merging Networks and normalising it
|
|
578
589
|
|
|
579
590
|
Args:
|
|
@@ -583,17 +594,17 @@ def community(args:argparse, run_mode):
|
|
|
583
594
|
community_mode = args['community_mode']
|
|
584
595
|
run_solve = args['solve']
|
|
585
596
|
|
|
586
|
-
options, input_dict, out_dir, temp = init_s2pl(args, community_mode, is_community=True)
|
|
597
|
+
options, input_dict, out_dir, temp, logger, log_path = init_s2pl(log_dir, args, community_mode, is_community=True)
|
|
587
598
|
|
|
588
599
|
|
|
589
600
|
time_data_extraction = time()
|
|
590
601
|
|
|
591
602
|
network=Netcom(args["comfile"], args["sbmldir"], temp, run_mode, run_solve, community_mode, args['targets_as_seeds'], args['topological_injection'],
|
|
592
603
|
args['keep_import_reactions'], input_dict, args['accumulation'], to_print=True,
|
|
593
|
-
write_sbml=True, equality_flux=args["equality_flux"])
|
|
604
|
+
write_sbml=True, equality_flux=args["equality_flux"], verbose=args['verbose'])
|
|
594
605
|
time_data_extraction = time() - time_data_extraction
|
|
595
606
|
|
|
596
|
-
results = initiate_results(network,options,args,run_mode)
|
|
607
|
+
results = initiate_results(logger, network,options,args,run_mode)
|
|
597
608
|
network.convert_to_facts()
|
|
598
609
|
|
|
599
610
|
|
|
@@ -605,10 +616,10 @@ def community(args:argparse, run_mode):
|
|
|
605
616
|
# we force this whatever it is given or not
|
|
606
617
|
if network.is_objective_error and (run_solve != "reasoning" or run_mode == "community"):
|
|
607
618
|
end_message = " aborted! \nMissing objective at least for one network.\n"
|
|
608
|
-
logger.
|
|
619
|
+
logger.error(f"Mode community {end_message}")
|
|
609
620
|
|
|
610
621
|
else:
|
|
611
|
-
model = ComReasoning(run_mode, run_solve, network, args['time_limit'], args['number_solution'],
|
|
622
|
+
model = ComReasoning(run_mode, run_solve, network, log_path, args['time_limit'], args['number_solution'],
|
|
612
623
|
args['clingo_configuration'], args['clingo_strategy'],
|
|
613
624
|
args['intersection'], args['union'],
|
|
614
625
|
temp, options['short'],
|
|
@@ -638,7 +649,7 @@ def community(args:argparse, run_mode):
|
|
|
638
649
|
time_mess += f'\nTIME {name.center(namewidth)}: {value}'
|
|
639
650
|
|
|
640
651
|
print(time_mess)
|
|
641
|
-
logger.
|
|
652
|
+
logger.info(time_mess)
|
|
642
653
|
print("\n")
|
|
643
654
|
|
|
644
655
|
# Save all fluxes into tsv file
|
|
@@ -655,7 +666,7 @@ def community(args:argparse, run_mode):
|
|
|
655
666
|
|
|
656
667
|
|
|
657
668
|
#---------------------- NETWORK ---------------------------
|
|
658
|
-
def network_rendering(args:argparse):
|
|
669
|
+
def network_rendering(args:argparse, log_dir:str):
|
|
659
670
|
"""Launch rendering as Network description (reaction formula)
|
|
660
671
|
or as Graphs
|
|
661
672
|
|
|
@@ -666,7 +677,15 @@ def network_rendering(args:argparse):
|
|
|
666
677
|
reac_status="import_rxn_"
|
|
667
678
|
else:
|
|
668
679
|
reac_status="rm_rxn_"
|
|
669
|
-
|
|
680
|
+
|
|
681
|
+
#logger.get_logger(args['infile'], f"{reac_status}network_render", args['verbose'])
|
|
682
|
+
#get_logger(args['infile'], f"{reac_status}network_render", LOG_DIR, args['verbose'])
|
|
683
|
+
logger, log_path = get_logger(
|
|
684
|
+
log_dir=log_dir,
|
|
685
|
+
sbml_file=args['infile'],
|
|
686
|
+
short_option= f"{reac_status}network_render",
|
|
687
|
+
verbose=args['verbose']
|
|
688
|
+
)
|
|
670
689
|
|
|
671
690
|
network = Description(args['infile'], args['keep_import_reactions'],
|
|
672
691
|
args['output_dir'], details = args['network_details'],
|
|
@@ -688,7 +707,7 @@ def network_rendering(args:argparse):
|
|
|
688
707
|
|
|
689
708
|
|
|
690
709
|
#---------------------- FLUX ---------------------------
|
|
691
|
-
def network_flux(args:argparse):
|
|
710
|
+
def network_flux(args:argparse, log_dir:str):
|
|
692
711
|
"""Check the Network flux using cobra from a seed2lp result file.
|
|
693
712
|
Needs the sbml file of the network.
|
|
694
713
|
Write the file in output directory.
|
|
@@ -696,13 +715,21 @@ def network_flux(args:argparse):
|
|
|
696
715
|
Args:
|
|
697
716
|
args (argparse): List or arguments
|
|
698
717
|
"""
|
|
699
|
-
logger.get_logger(args['infile'], "check_fluxes", args['verbose'])
|
|
718
|
+
# logger.get_logger(args['infile'], "check_fluxes", args['verbose'])
|
|
719
|
+
#get_logger(args['infile'], "check_fluxes", LOG_DIR, args['verbose'])
|
|
720
|
+
logger, log_path = get_logger(
|
|
721
|
+
log_dir=log_dir,
|
|
722
|
+
sbml_file=args['infile'],
|
|
723
|
+
short_option= "check_fluxes",
|
|
724
|
+
verbose=args['verbose']
|
|
725
|
+
)
|
|
726
|
+
|
|
700
727
|
input_dict=dict()
|
|
701
728
|
|
|
702
729
|
data = load_json(args['result_file'])
|
|
703
|
-
input_dict["Objective"] = data["NETWORK"]["OBJECTIVE"]
|
|
730
|
+
input_dict["Objective"] = data["NETWORK"]["OBJECTIVE"][0][1]
|
|
704
731
|
|
|
705
|
-
network = Network(args['infile'], to_print=False, input_dict=input_dict)
|
|
732
|
+
network = Network(args['infile'], to_print=False, input_dict=input_dict, verbose=args['verbose'])
|
|
706
733
|
maximize, solve = network.convert_data_to_resmod(data)
|
|
707
734
|
network.check_fluxes(maximize, args["flux_parallel"])
|
|
708
735
|
|
|
@@ -713,7 +740,7 @@ def network_flux(args:argparse):
|
|
|
713
740
|
file.save(f'{network.name}_{options["short"]}_fluxes_from_result', args['output_dir'], network.fluxes, 'tsv')
|
|
714
741
|
|
|
715
742
|
|
|
716
|
-
def network_flux_community(args:argparse):
|
|
743
|
+
def network_flux_community(args:argparse, log_dir:str):
|
|
717
744
|
"""Check the Network flux using cobra from a seed2lp result file.
|
|
718
745
|
Needs a community file containing a list of networks and the sbml directory.
|
|
719
746
|
Write the file in output directory.
|
|
@@ -721,7 +748,15 @@ def network_flux_community(args:argparse):
|
|
|
721
748
|
Args:
|
|
722
749
|
args (argparse): List or arguments
|
|
723
750
|
"""
|
|
724
|
-
logger.get_logger(args['comfile'], "check_fluxes", args['verbose'])
|
|
751
|
+
# logger.get_logger(args['comfile'], "check_fluxes", args['verbose'])
|
|
752
|
+
#get_logger(args['comfile'], "check_fluxes", LOG_DIR, args['verbose'])
|
|
753
|
+
logger, log_path = get_logger(
|
|
754
|
+
log_dir=log_dir,
|
|
755
|
+
sbml_file=args['comfile'],
|
|
756
|
+
short_option= "check_fluxes",
|
|
757
|
+
verbose=args['verbose']
|
|
758
|
+
)
|
|
759
|
+
|
|
725
760
|
input_dict=dict()
|
|
726
761
|
|
|
727
762
|
data = load_json(args['result_file'])
|
|
@@ -736,7 +771,7 @@ def network_flux_community(args:argparse):
|
|
|
736
771
|
temp = get_temp_dir(args)
|
|
737
772
|
|
|
738
773
|
network=Netcom(args["comfile"], args["sbmldir"], temp, run_solve=run_solve, input_dict=input_dict, to_print=False,
|
|
739
|
-
write_sbml=True, equality_flux=args["equality_flux"])
|
|
774
|
+
write_sbml=True, equality_flux=args["equality_flux"], verbose=args['verbose'])
|
|
740
775
|
|
|
741
776
|
maximize, solve = network.convert_data_to_resmod(data)
|
|
742
777
|
|
|
@@ -749,7 +784,7 @@ def network_flux_community(args:argparse):
|
|
|
749
784
|
|
|
750
785
|
|
|
751
786
|
#---------------------- SCOPE ---------------------------
|
|
752
|
-
def scope(args:argparse):
|
|
787
|
+
def scope(args:argparse, log_dir:str):
|
|
753
788
|
"""Check the Network flux using cobra from a seed2lp result file.
|
|
754
789
|
Needs the sbml file of the network.
|
|
755
790
|
Write the file in output directory.
|
|
@@ -757,9 +792,17 @@ def scope(args:argparse):
|
|
|
757
792
|
Args:
|
|
758
793
|
args (argparse): List or arguments
|
|
759
794
|
"""
|
|
760
|
-
logger.get_logger(args['infile'], "scope", args['verbose'])
|
|
795
|
+
# logger.get_logger(args['infile'], "scope", args['verbose'])
|
|
796
|
+
#get_logger(args['infile'], "scope", LOG_DIR, args['verbose'])
|
|
797
|
+
logger, log_path = get_logger(
|
|
798
|
+
log_dir=log_dir,
|
|
799
|
+
sbml_file=args['infile'],
|
|
800
|
+
short_option= "scope",
|
|
801
|
+
verbose=args['verbose']
|
|
802
|
+
)
|
|
803
|
+
|
|
761
804
|
input_dict=dict()
|
|
762
|
-
network = Network(args['infile'], to_print=False, input_dict=input_dict)
|
|
805
|
+
network = Network(args['infile'], to_print=False, input_dict=input_dict, verbose=args['verbose'])
|
|
763
806
|
data = load_json(args['result_file'])
|
|
764
807
|
network.convert_data_to_resmod(data)
|
|
765
808
|
scope = Scope(args['infile'], network, args['output_dir'])
|
|
@@ -780,22 +823,30 @@ def save_conf(args:argparse):
|
|
|
780
823
|
|
|
781
824
|
|
|
782
825
|
#------------------ WRITE TARGETS ----------------------
|
|
783
|
-
def get_objective_targets(args:argparse):
|
|
826
|
+
def get_objective_targets(args:argparse, log_dir:str):
|
|
784
827
|
"""Get the metabolites reactant of objective reaction or found
|
|
785
828
|
|
|
786
829
|
Args:
|
|
787
830
|
args (argparse): List or arguments
|
|
788
831
|
"""
|
|
789
|
-
logger.get_logger(args['infile'], "objective_targets", args['verbose'])
|
|
790
|
-
|
|
832
|
+
# logger.get_logger(args['infile'], "objective_targets", args['verbose'])
|
|
833
|
+
#get_logger(args['infile'], "objective_targets", LOG_DIR, args['verbose'])
|
|
834
|
+
logger, log_path = get_logger(
|
|
835
|
+
log_dir=log_dir,
|
|
836
|
+
sbml_file=args['infile'],
|
|
837
|
+
short_option= "objective_targets",
|
|
838
|
+
verbose=args['verbose']
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
input_dict = get_input_datas(logger)
|
|
791
842
|
if 'objective' in args and args['objective']: # only in full network mode
|
|
792
843
|
input_dict = get_objective(args['objective'], input_dict)
|
|
793
844
|
try:
|
|
794
845
|
chek_inputs(args['infile'], input_dict)
|
|
795
846
|
except ValueError as e :
|
|
796
|
-
logger.
|
|
847
|
+
logger.error(str(e))
|
|
797
848
|
exit(1)
|
|
798
|
-
network = Network(args['infile'], run_mode="target", input_dict=input_dict, to_print=False)
|
|
849
|
+
network = Network(args['infile'], run_mode="target", input_dict=input_dict, to_print=False, verbose=args['verbose'])
|
|
799
850
|
|
|
800
851
|
print("List of targets: ",[*network.targets])
|
|
801
852
|
file.save(f"{network.name}_targets", args['output_dir'],[*network.targets],"txt")
|
|
@@ -808,29 +859,32 @@ def get_objective_targets(args:argparse):
|
|
|
808
859
|
|
|
809
860
|
|
|
810
861
|
def main():
|
|
862
|
+
global LOG_DIR
|
|
811
863
|
args = argument.parse_args()
|
|
812
864
|
cfg = argument.get_config(args, PROJECT_DIR)
|
|
813
865
|
|
|
814
|
-
|
|
815
|
-
is_valid_dir(
|
|
866
|
+
# LOG_DIR =path.join(args.output_dir,"logs")
|
|
867
|
+
# is_valid_dir(LOG_DIR)
|
|
868
|
+
log_dir=path.join(args.output_dir,"logs")
|
|
869
|
+
is_valid_dir(log_dir)
|
|
816
870
|
|
|
817
871
|
match args.cmd:
|
|
818
872
|
case "target" | "full" | "fba":
|
|
819
|
-
run_seed2lp(cfg, args.cmd)
|
|
873
|
+
run_seed2lp(cfg, args.cmd, log_dir)
|
|
820
874
|
case "network":
|
|
821
|
-
network_rendering(cfg)
|
|
875
|
+
network_rendering(cfg, log_dir)
|
|
822
876
|
case "flux":
|
|
823
|
-
network_flux(cfg)
|
|
877
|
+
network_flux(cfg, log_dir)
|
|
824
878
|
case "scope":
|
|
825
|
-
scope(cfg)
|
|
879
|
+
scope(cfg, log_dir)
|
|
826
880
|
case "conf":
|
|
827
881
|
save_conf(cfg)
|
|
828
882
|
case "objective_targets":
|
|
829
|
-
get_objective_targets(cfg)
|
|
883
|
+
get_objective_targets(cfg, log_dir)
|
|
830
884
|
case "community":
|
|
831
|
-
community(cfg, args.cmd)
|
|
885
|
+
community(cfg, args.cmd, log_dir)
|
|
832
886
|
case "fluxcom":
|
|
833
|
-
network_flux_community(cfg)
|
|
887
|
+
network_flux_community(cfg, log_dir)
|
|
834
888
|
|
|
835
889
|
if __name__ == '__main__':
|
|
836
890
|
main()
|
seed2lp/_version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_info__ = ('2', '
|
|
1
|
+
__version_info__ = ('2', '1', '0')
|
|
2
2
|
__version__ = '.'.join(__version_info__)
|
seed2lp/argument.py
CHANGED
|
@@ -165,7 +165,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
165
165
|
- guess_check : Only reasoning with guess and check results using cobra (adapts rules) \n \
|
|
166
166
|
- guess_check_div : Only reasoning with guess and check results using cobra (adapts rules) and add diversity \n \
|
|
167
167
|
- filter : Only reasoning with a cobra filter validation during search (do not adapt rules) \n \
|
|
168
|
-
- all : Compute reasoning then hybrid
|
|
168
|
+
- all : Compute reasoning then hybrid",
|
|
169
169
|
required=False
|
|
170
170
|
)
|
|
171
171
|
pp_solve_com = argparse.ArgumentParser(add_help=False, formatter_class=argparse.RawTextHelpFormatter)
|
|
@@ -177,7 +177,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
177
177
|
- guess_check : Only reasoning with guess and check results using cobra (adapts rules) \n \
|
|
178
178
|
- guess_check_div : Only reasoning with guess and check results using cobra (adapts rules) and add diversity \n \
|
|
179
179
|
- filter : Only reasoning with a cobra filter validation during search (do not adapt rules) \n \
|
|
180
|
-
- all : Compute reasoning
|
|
180
|
+
- all : Compute reasoning",
|
|
181
181
|
required=False
|
|
182
182
|
)
|
|
183
183
|
pp_intersection = argparse.ArgumentParser(add_help=False)
|
|
@@ -551,7 +551,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
551
551
|
],
|
|
552
552
|
description=
|
|
553
553
|
"""
|
|
554
|
-
From Seed2lp seed searching results json file, this functionnality
|
|
554
|
+
From Seed2lp seed searching results json file, this functionnality determine scope inferred by seeeds using Network Expansion.
|
|
555
555
|
Can be used for other tool results if the results file has the same json structure.
|
|
556
556
|
The scope calculation is done with MeneTools.
|
|
557
557
|
""",
|
|
@@ -589,7 +589,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
589
589
|
- Write the reactants of the given objectve (-o/--objective) into a file
|
|
590
590
|
""",
|
|
591
591
|
usage="""
|
|
592
|
-
seed2lp
|
|
592
|
+
seed2lp objective_targets [output_directory] \n
|
|
593
593
|
"""
|
|
594
594
|
)
|
|
595
595
|
|
|
@@ -624,7 +624,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
624
624
|
- guess_check_div: Guess check but also forbids subset of seed as next result in order to reduce intersection of solutions
|
|
625
625
|
""",
|
|
626
626
|
usage="""
|
|
627
|
-
seed2lp community community_file_text sbml_directory
|
|
627
|
+
seed2lp community [community_file_text] [sbml_directory] [result_directory] \n
|
|
628
628
|
"""
|
|
629
629
|
)
|
|
630
630
|
|
|
@@ -643,7 +643,7 @@ def cli_parser() -> argparse.ArgumentParser:
|
|
|
643
643
|
Can be used for other tool results if the results file has the same json structure.
|
|
644
644
|
""",
|
|
645
645
|
usage="""
|
|
646
|
-
seed2lp fluxcom community_file_text sbml_directory seed2lp_result_file output_directory \n
|
|
646
|
+
seed2lp fluxcom [community_file_text] [sbml_directory] [seed2lp_result_file] [output_directory] \n
|
|
647
647
|
"""
|
|
648
648
|
)
|
|
649
649
|
|
seed2lp/asp/enum-cc.lp
CHANGED
|
@@ -11,11 +11,11 @@ reaction(R) :- dreaction(R).
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
% the edges are linking reactants to products of each reaction.
|
|
14
|
-
oedge(T,P) :- reactant(T,R) ; product(P,R).
|
|
14
|
+
oedge(T,P) :- reactant(T,_,R,_,_,_) ; product(P,_,R,_,_,_).
|
|
15
15
|
|
|
16
16
|
% the nodes
|
|
17
|
-
node(M) :- reactant(M,_).
|
|
18
|
-
node(M) :- product(M,_).
|
|
17
|
+
node(M) :- reactant(M,_,_,_,_,_).
|
|
18
|
+
node(M) :- product(M,_,_,_,_,_).
|
|
19
19
|
|
|
20
20
|
% #show oedge/2.
|
|
21
21
|
% #show node/1.
|
seed2lp/clingo_lpx.py
CHANGED
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
Clingo lpx functions for launching command and extract results.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
import subprocess
|
|
5
|
+
import subprocess, logging
|
|
6
6
|
import json
|
|
7
|
-
from resource import getrusage, RUSAGE_CHILDREN
|
|
7
|
+
#from resource import getrusage, RUSAGE_CHILDREN
|
|
8
8
|
from .utils import repair_json
|
|
9
|
-
from . import logger
|
|
9
|
+
from . import color #logger
|
|
10
|
+
try:
|
|
11
|
+
from resource import getrusage, RUSAGE_CHILDREN
|
|
12
|
+
except ImportError:
|
|
13
|
+
RUSAGE_CHILDREN = 0
|
|
14
|
+
def getrusage(x):
|
|
15
|
+
class ret:
|
|
16
|
+
ru_maxrss = 2**20
|
|
17
|
+
return ret
|
|
10
18
|
|
|
11
19
|
|
|
12
20
|
def command(files:list, options:list, nb_model:int=0, time_limit:int=0) -> iter:
|
|
@@ -59,7 +67,7 @@ def solve(cmd:list, time_limit:int):
|
|
|
59
67
|
Returns:
|
|
60
68
|
proc_output (str), err_output (str), error_code (int), memory (float), is_killed (bool)
|
|
61
69
|
"""
|
|
62
|
-
|
|
70
|
+
logger = logging.getLogger("s2lp")
|
|
63
71
|
cmd.append(f'--outf=2')
|
|
64
72
|
is_killed=False
|
|
65
73
|
try:
|
|
@@ -67,7 +75,7 @@ def solve(cmd:list, time_limit:int):
|
|
|
67
75
|
if time_limit:
|
|
68
76
|
process.wait(timeout=time_limit+60)
|
|
69
77
|
except subprocess.TimeoutExpired:
|
|
70
|
-
logger.
|
|
78
|
+
logger.error(f'Timeout: {time_limit/60} min expired')
|
|
71
79
|
process.kill()
|
|
72
80
|
process.wait()
|
|
73
81
|
is_killed=True
|
|
@@ -78,7 +86,7 @@ def solve(cmd:list, time_limit:int):
|
|
|
78
86
|
if is_killed:
|
|
79
87
|
error_code=0
|
|
80
88
|
if error_code==1:
|
|
81
|
-
logger.
|
|
89
|
+
logger.error(f'Timeout: {time_limit/60} min expired')
|
|
82
90
|
return str(proc_output, 'UTF-8'), err_output, error_code, round(memory,3), is_killed
|
|
83
91
|
|
|
84
92
|
|