diff --git a/scripts/func_defs.py b/scripts/func_defs.py index 7ea7895..4f1f271 100755 --- a/scripts/func_defs.py +++ b/scripts/func_defs.py @@ -86,6 +86,12 @@ def bail(msg): print(msg, file=sys.stderr) exit(1) + +# print a warning +def warn(msg): + """Print the warning message to stderr.""" + print(f"WARNING: {msg}", file=sys.stderr) + def TrueOrFalse(value): value = repr(value) if value: diff --git a/scripts/validate_config.py b/scripts/validate_config.py index 58ff969..e9e815c 100644 --- a/scripts/validate_config.py +++ b/scripts/validate_config.py @@ -20,7 +20,7 @@ import os import csv from glob import glob -from func_defs import bail +from func_defs import bail, warn # ============================================================================== # @@ -101,12 +101,35 @@ def parse_samples(lines): outputdict[row[2]] = sampleid_dict return { 'SAMPLES': outputdict } +def update_config_layout(config): + # check for new annotation layout + if not 'differential-methylation' in config['general']: + return config + + differential_methylation = config['general']['differential-methylation'] + if not 'annotation' in differential_methylation: + return config + + warn("The specification of annotation files has changed in version 0.1.9 \n"+ + "For now updating configuration file with the new default settings layout.\n"+ + "In the future, please retrieve the new default settings layout with 'pigx-bsseq --init settings'.") + ## move cpgisland and refgene files to location dict + if 'cpgIsland-bedfile' in differential_methylation['annotation']: + config['locations']['cpgIsland-bedfile'] = differential_methylation['annotation']['cpgIsland-bedfile'] + if 'refGenes-bedfile' in differential_methylation['annotation']: + config['locations']['refGenes-bedfile'] = differential_methylation['annotation']['refGenes-bedfile'] + ## remove annotation section + differential_methylation.pop('annotation') + + config['general']['differential-methylation'] = differential_methylation + + return config + + # -------------------------------------- # validation of Config # -------------------------------------- - - # check for common input/configuration errors: def validate_config(config): # Check that all locations exist @@ -149,14 +172,6 @@ def validate_config(config): bail("ERROR: The specification of treatment groups and differential analysis has changed.\n"+ "Please retrieve the new default settings layout with 'pigx-bsseq --init settings'.\n") - - # check for new annotation layout - if 'annotation' in config['general']['differential-methylation']: - bail("ERROR: The specification of annotation files has changed.\n"+ - "Please retrieve the new default settings layout with 'pigx-bsseq --init settings'.\n") - - - # Check for a any Assembly string if not config['general']['assembly']: bail("ERROR: Please set a genome assembly string in the settings file at general::assembly.") diff --git a/snakefile.py b/snakefile.py index 257d41c..3cd1045 100644 --- a/snakefile.py +++ b/snakefile.py @@ -25,6 +25,7 @@ include : os.path.join(config['locations']['pkglibexecdir'], 'scripts/update_pigx_work.py') include : os.path.join(config['locations']['pkglibexecdir'], 'scripts/validate_config.py') +config = update_config_layout(config) validate_config(config) update_pigx_work(config)