diff --git a/docs/source/cmpb/cmpb-config.rst b/docs/source/cmpb/cmpb-config.rst index 5a4644b..20ee772 100644 --- a/docs/source/cmpb/cmpb-config.rst +++ b/docs/source/cmpb/cmpb-config.rst @@ -130,6 +130,13 @@ Below, the configuration file with the underlying defaults, is displayed. # Additionally, remove unused metabolites (possibly reduces knowledge-base) remove_unused_metabs: False + # Finding and solvong Energy Generating Cycles (EGCs) + # --------------------------------------------------- + EGCs: + solver: NULL # solver gives the algorithm to use for solving EGCs + # if NULL, only searches for EGCs without trying to solve them + # options include: greedy + # BOFdat / Biomass objective function # ----------------------------------- BOF: diff --git a/src/specimen/cmpb/workflow.py b/src/specimen/cmpb/workflow.py index ec1eb4c..358793a 100644 --- a/src/specimen/cmpb/workflow.py +++ b/src/specimen/cmpb/workflow.py @@ -34,9 +34,16 @@ from refinegems.utility.connections import run_memote, perform_mcc, adjust_BOF, run_SBOannotator from refinegems.utility.io import load_model, write_model_to_file from refinegems.developement.decorators import implement +from refinegems.classes import egcs from ..util.set_up import save_cmpb_user_input, validate_config +################################################################################ +# setup logging +################################################################################ +# general logging +logger = logging.getLogger(__name__) + ################################################################################ # functions ################################################################################ @@ -149,6 +156,14 @@ def between_analysis(model: Model, cfg:dict, step:str): # ---------- today = date.today().strftime("%Y%m%d") log_file = Path(dir, 'cmpb_out', 'logs', f'specimen_cmpb_{str(today)}.log') + handler = logging.handlers.RotatingFileHandler(log_file, + mode='w', + backupCount=10, + encoding='utf-8', + delay=0) + handler.setFormatter(logging.Formatter("{levelname} \t {name} \t {message}", + style="{",)) + logger.addHandler(handler) # CarveMe ######### @@ -409,7 +424,27 @@ def between_analysis(model: Model, cfg:dict, step:str): # in-between testing between_growth_test(current_model,config,step='after_duplicate_removal') between_analysis(current_model,config,step='after_duplicate_removal') - + + # find and solve energy generating cycles + # --------------------------------------- + current_model = load_model(str(current_modelpath),'cobra') + match config['EGCs']['solver']: + # greedy solver + case 'greedy': + print('Using GreedyEGCSolver...') + solver = egcs.GreedyEGCSolver() + results = solver.solve_egcs(current_model,namespace=config['general']['namespace']) # @NOTE automatically uses c,p as compartments + if results: + logger.info('results:') + for k,v in results.items(): + logger.info(f'\t{k}: {v}') + + # no solver = EGCs will only be reported + case _: + solver = egcs.EGCSolver() + logger.info(f'\tFound EGCs:\n') + logger.info(f'\t{solver.find_egcs(current_model,with_reacs=True,namespace=config['general']['namespace'])}') # @NOTE automatically uses c,p as compartments + # BOF # --- # BOFdat - optional diff --git a/src/specimen/data/config/cmpb_config.yaml b/src/specimen/data/config/cmpb_config.yaml index a20dbd5..5ac4ff0 100644 --- a/src/specimen/data/config/cmpb_config.yaml +++ b/src/specimen/data/config/cmpb_config.yaml @@ -133,6 +133,13 @@ duplicates: # Additionally, remove unused metabolites (possibly reduces knowledge-base) remove_unused_metabs: False +# Finding and solvong Energy Generating Cycles (EGCs) +# --------------------------------------------------- +EGCs: + solver: NULL # solver gives the algorithm to use for solving EGCs + # if NULL, only searches for EGCs without trying to solve them + # options include: greedy + # BOFdat / Biomass objective function # ----------------------------------- BOF: diff --git a/src/specimen/util/set_up.py b/src/specimen/util/set_up.py index 51fc6e6..3d53783 100644 --- a/src/specimen/util/set_up.py +++ b/src/specimen/util/set_up.py @@ -619,6 +619,11 @@ def save_cmpb_user_input(configpath:Union[str,None]=None) -> dict: config['duplicates']['remove_unused_metabs'] = True case 'n': config['duplicates']['remove_unused_metabs'] = False + + # handling EGCs + egc_solver = click.prompt('Choose a solver (or none) for handling energy generating cycles.', type=click.Choice(['none','greedy']), show_choices=True) + if egc_solver == 'none': + egc_solver = None # @TODO: Ask for any biomass correction # BOF