diff --git a/cobrawap/__main__.py b/cobrawap/__main__.py index 69dac792..d537855f 100755 --- a/cobrawap/__main__.py +++ b/cobrawap/__main__.py @@ -192,10 +192,10 @@ def initialize(output_path=None, config_path=None, **kwargs): # populate config_path with template config files if any(config_path.iterdir()): - overwrite = (input(f"The config direcotry {config_path} already exists "\ + overwrite = (input(f"The config directory {config_path} already exists "\ "and is not empty. Create template config files "\ - "anyway? [Y/n]").lower() == 'y' - or True) + "anyway? [y/N]").lower() == 'y' + or False) else: overwrite = True if overwrite: @@ -232,8 +232,10 @@ def create(profile=None, parent_profile=None, data_path=None, profile=config_name, parent=parent_profile) - setup_entry_stage(profile=profile, parent_profile=parent_profile, - data_path=data_path, loading_script_name=loading_script_name) + setup_entry_stage(profile=profile, + parent_profile=parent_profile, + data_path=data_path, + loading_script_name=loading_script_name) return None @@ -303,7 +305,7 @@ def run_stage(profile=None, stage=None, extra_args=None, **kwargs): # select stage while stage not in stages.keys(): - stage = input("Which stage should be executed?\n" + stage = input("Which stage should be executed?\n " +"\n ".join(f"{k} {v}" for k,v in get_setting('stages').items()) +"\nSelect the stage index: ") stage = stages[stage] diff --git a/cobrawap/cmd_utils.py b/cobrawap/cmd_utils.py index b535a483..3903dfd7 100644 --- a/cobrawap/cmd_utils.py +++ b/cobrawap/cmd_utils.py @@ -34,13 +34,24 @@ def create_new_configfile(profile, stage=None, stage_number=None, parent=None): config_path = Path(get_setting('config_path')) parent = f'_{parent}' if parent else '' - template_config_path = config_path / stage / 'configs' \ - / f'config{parent}.yaml' - new_config_path = config_path / stage / 'configs' \ - / f'config_{profile}.yaml' + config_dir = config_path / stage / 'configs' + template_config_path = config_dir / f'config{parent}.yaml' + new_config_path = config_dir / f'config_{profile}.yaml' + if new_config_path.exists(): log.debug(f"config file `{new_config_path}` already exists. Skip.") return None + + if not template_config_path.exists(): + log.debug(f"parent config file `{template_config_path}` doesn't exist.") + potential_parents = [f.name for f in config_dir.iterdir() \ + if f.name.startswith(f'config{parent}')] + if potential_parents: + log.debug(f"Using `{potential_parents[0]}` instead.") + template_config_path = config_dir / potential_parents[0] + else: + raise FileNotFoundError("No parent config file fitting the name " + f"`{parent.strip('_')}` found!") shutil.copy(template_config_path, new_config_path) update_configfile(new_config_path, {'PROFILE':profile}) @@ -113,12 +124,12 @@ def setup_entry_stage(profile, parent_profile=None, stages = get_setting('stages') loading_script_path = config_path / stages['1'] / 'scripts' \ - / f'{loading_script_name}' + / f'{loading_script_name}' if loading_script_path.exists(): log.info(f"`{loading_script_name}` already exists. Skip.") else: shutil.copy(config_path / stages['1'] / 'scripts' \ - / 'enter_data_template.py', + / 'enter_data_template.py', loading_script_path) # update stage 01 config diff --git a/pipeline/utils/snakefile.py b/pipeline/utils/snakefile.py index 441f141e..7e8771cb 100644 --- a/pipeline/utils/snakefile.py +++ b/pipeline/utils/snakefile.py @@ -45,10 +45,10 @@ def set_setting(setting: dict) -> None: key_overlap = [k for k in setting.keys() if k in settings.keys()] if key_overlap: overwrite = (input(f"There are already settings for {key_overlap}! "\ - "Overwrite? [Y/n]").lower() == 'y' - or True) + "Overwrite? [y/N]").lower() == 'y' + or False) if not overwrite: - setting.pop[key_overlap, None] + _ = [setting.pop(k, None) for k in key_overlap] settings.update(setting) with open(SETTINGS_PATH, 'w') as f: