Skip to content

Commit

Permalink
cmpb update + user input #8
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-Hades committed May 28, 2024
1 parent a861cbb commit 5f7e017
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 10 deletions.
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
import os
import sys
from pathlib import Path
sys.path.insert(0, os.path.abspath('../../src/'))

# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
'seaborn',
'tqdm',
'z3-solver',
'multiprocess~>=0.70.16'
'multiprocess>=0.70.16'
]
# additional missing tools:
# EntrezDirect
Expand Down
41 changes: 36 additions & 5 deletions src/specimen/cmpb/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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',
Expand Down
133 changes: 131 additions & 2 deletions src/specimen/util/set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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












0 comments on commit 5f7e017

Please sign in to comment.