From 5f7e0175300dedf82b32ce6c142ee8955c10be44 Mon Sep 17 00:00:00 2001 From: cb-Hades <81743695+cb-Hades@users.noreply.github.com> Date: Tue, 28 May 2024 15:30:28 +0200 Subject: [PATCH] cmpb update + user input #8 --- docs/source/conf.py | 5 +- pyproject.toml | 2 +- src/specimen/cmpb/workflow.py | 41 +++++++++-- src/specimen/util/set_up.py | 133 +++++++++++++++++++++++++++++++++- 4 files changed, 171 insertions(+), 10 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index f734956..ecf009b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,6 +19,7 @@ # import os import sys +from pathlib import Path sys.path.insert(0, os.path.abspath('../../src/')) # -- General configuration --------------------------------------------------- @@ -56,14 +57,14 @@ html_css_files = ['custom_theme.css'] # Adds logo to documentation page -html_logo = 'images/LogoSPECIMEN.png' +html_logo = str(Path('images','LogoSPECIMEN.png')) html_theme_options = { 'logo_only': True, 'display_version': False } #Adds logo as favicon to tab -html_favicon = 'images/LogoSPECIMEN.png' +html_favicon = str(Path('images','LogoSPECIMEN.png')) # Changes code highlighting pygments_style = 'blinds-light' diff --git a/pyproject.toml b/pyproject.toml index 424af61..cc07a1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ dependencies = [ 'seaborn', 'tqdm', 'z3-solver', - 'multiprocess~>=0.70.16' + 'multiprocess>=0.70.16' ] # additional missing tools: # EntrezDirect diff --git a/src/specimen/cmpb/workflow.py b/src/specimen/cmpb/workflow.py index a27e3bf..9f43f21 100644 --- a/src/specimen/cmpb/workflow.py +++ b/src/specimen/cmpb/workflow.py @@ -10,11 +10,12 @@ import pandas as pd from datetime import date from pathlib import Path +from typing import Union import warnings import yaml -from cobra import Reaction +from cobra import Reaction,Model from libsbml import readSBML from refinegems.analysis import growth @@ -48,9 +49,28 @@ # in the run function: current_model means the cobrapy model, # while current_libmodel means the libsbml model -def run(configpath:str): - - def between_growth_test(model, cfg, step): +def run(configpath:Union[str,None]=None): + """Run the CarveMe + + Args: + - configpath (Union[str,None]): + The Path to a configuration file. If none given, prompts the user to enter the needed + information step by step. + Defaults to None. + """ + + def between_growth_test(model: Model, cfg:dict, step:str): + """Helper function for :py:func:`~specimen.cmpb.workflow.run`. + Run a growth test on a model with the options set in the config file. + + Args: + - model (Model): + The cobra.Model for testing the growth. + - cfg (dict): + The loaded configuration file. + - step (str): + Descriptive string for the current step of the pipeline (important for saving the output). + """ # try to set objective to growth growth_func_list = test_biomass_presence(model) if growth_func_list: @@ -66,7 +86,18 @@ def between_growth_test(model, cfg, step): mes = f'No growth/biomass function detected, growth simulation for step {step} will be skipped.' warnings.warn(mes) - def between_analysis(model, cfg, step): + def between_analysis(model: Model, cfg:dict, step:str): + """Helper function for :py:func:`~specimen.cmpb.workflow.run`. + Run a memote and/or stats test on a model with the options set in the config file. + + Args: + - model (Model): + The cobra.Model for testing. + - cfg (dict): + The loaded configuration file. + - step (str): + Descriptive string for the current step of the pipeline (important for saving the output). + """ # optional analysis if cfg['general']['memote_always_on']: run_memote(model, 'html', diff --git a/src/specimen/util/set_up.py b/src/specimen/util/set_up.py index 5ea1546..acf162d 100644 --- a/src/specimen/util/set_up.py +++ b/src/specimen/util/set_up.py @@ -16,7 +16,7 @@ from importlib.resources import files from pathlib import Path from tqdm import tqdm -from typing import Literal +from typing import Literal,Union from refinegems.utility.set_up import download_config as rg_config from refinegems.utility.io import load_a_table_from_database @@ -302,7 +302,7 @@ def dict_recursive_check(dictA:dict, key:str=None): # @TODO # is it still correct after all the changes??? -def save_cmpb_user_input(configpath: str) -> dict[str: str]: +def old_save_cmpb_user_input(configpath: str) -> dict[str: str]: """This aims to collect user input from the command line to create a cmpb config file, will also save the user input to a config if no config was given @@ -482,3 +482,132 @@ def save_cmpb_user_input(configpath: str) -> dict[str: str]: print('Your input was saved as yaml to '+ user_input['out_path'] + 'user_input_' + str(today) + '.yaml') return user_input + +def save_cmpb_user_input(configpath: Union[str,None]=None) -> dict[str: str]: + + print('No config or no valid config given, you will be asked for input') + user_input = {} + + config_file = files('specimen.data.config').joinpath('cmpb_config.yaml') + with open(config_file, "r") as cfg: + config = yaml.load(cfg, Loader=yaml.loader.FullLoader) + + # if model, get path + has_model = click.prompt('Do you already have a draft model e.g. created with CarveMe? (y/n)') + while(True): + match has_model: + case 'y': + modelpath = click.prompt('Enter the path to your model') + config['input']['modelpath'] = modelpath + break + case 'n': + break + case _: + has_model = click.prompt('') + + # required input + # -------------- + print('------------') + print('The following information is REQUIRED for the pipeline') + print('------------') + config['input']['annotated_genome'] = click.prompt('Enter the path to your annotated genome file') + config['input']['mediapath'] = click.prompt('Enter the path to a media configuration file for growth simulation') + + # general options + # --------------- + print('------------') + print('General options') + print('------------') + + # output directory + config['general']['dir'] = click.prompt('Enter your desired output directory path') + + # colour + set_col = click.prompt('Do you want to use the default colour map YlGn for the visualisation? (y/n)') + while(True): + match set_col: + case 'n': + colours = click.prompt('Enter your choosen colour scheme') + config['general']['colours'] = colours + break + case 'y': + break + case _: + set_col = click.prompt('') + + # save all models or not + save_models = click.prompt('Do you want to save the model separatly after each step? (y/n)') + while(True): + match save_models: + case 'y': + config['general']['save_all_models'] = True + break + case 'n': + config['general']['save_all_models'] = False + break + case _: + save_models = click.prompt('') + + # run memote always y/n + run_memote = click.prompt('Do you want run memote after each step? (y/n)') + while(True): + match run_memote: + case 'y': + config['general']['memote_always_on'] = True + break + case 'n': + config['general']['memote_always_on'] = False + break + case _: + run_memote = click.prompt('') + + # run stats always y/n + models_stats = click.prompt('Do you want run memote after each step? (y/n)') + while(True): + match models_stats: + case 'y': + config['general']['stats_always_on'] = True + break + case 'n': + config['general']['stats_always_on'] = False + break + case _: + models_stats = click.prompt('') + + # some additional, sometimes required, sometimes optional files + refseq = click.prompt('If you want to run a gap analysis with KEGG or have a CarveMe model, please enter the path to your refseq gff file') + config['general']['refseq_organism_id'] = refseq + + kegg_org_id = click.prompt('If you want to run a gap analysis with KEGG or have a CarveMe model, please enter the path to your refseq gff file') + config['general']['refseq_organism_id'] = kegg_org_id + + # part-specific + # ------------- + print('------------') + print('Part-specific options') + print('------------') + + # model polish + + # gapfilling + # RECYCLE OLD FUNCTION + + # kegg pathways as groups + kegg_pw_groups = click.prompt('Do you want to add KEGG pathways as groups to the model? (y/n)') + config['kegg_pathway_groups'] = kegg_pw_groups + + # resolve duplicates + + # BOF + + + + + + + + + + + + \ No newline at end of file