Skip to content

Commit

Permalink
Added EGCs func to cmpb #19
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-Hades committed Dec 9, 2024
1 parent 5fcbb75 commit 05d494c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/source/cmpb/cmpb-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 36 additions & 1 deletion src/specimen/cmpb/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down Expand Up @@ -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
#########
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/specimen/data/config/cmpb_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/specimen/util/set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 05d494c

Please sign in to comment.