diff --git a/tests/input_files/config.yaml b/tests/input_files/config.yaml index f7a7410cc34e51d3dff5a149abba32491e8d3309..f3cb261f4dea3e5ab0016ab1ee4138c0391f4aaa 100644 --- a/tests/input_files/config.yaml +++ b/tests/input_files/config.yaml @@ -1,4 +1,5 @@ --- + # Required fields samples: "../input_files/samples.tsv" rule_config: "../input_files/rule_config.yaml" output_dir: "results" @@ -7,9 +8,11 @@ salmon_indexes: "results/salmon_indexes" star_indexes: "results/star_indexes" alfa_indexes: "results/alfa_indexes" - report_description: "No description provided by user" - report_logo: "../../images/logo.128px.png" - report_url: "https://zavolan.biozentrum.unibas.ch/" - author_name: "NA" - author_email: "NA" + # Optional fields + optional: + report_description: "No description provided by user" + report_logo: "../../images/logo.128px.png" + report_url: "https://zavolan.biozentrum.unibas.ch/" + author_name: "NA" + author_email: "NA" ... diff --git a/workflow/Snakefile b/workflow/Snakefile index 5f2434e746701bca255949bb9b1639cc25f238e4..b5e295d6cd3a6c0498671004e229b9ee5f50fc46 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -17,6 +17,37 @@ samples_table = pd.read_csv( sep="\t", ) +# Validate config with template config +template_config_path = os.path.join( + workflow.current_basedir, + '..', + 'tests', + 'input_files', + 'config.yaml') +try: + with open(template_config_path) as _file: + template_config = yaml.safe_load(_file) + logger.info(f"Loaded template config from {template_config_path}.") + # Check if config contains required fields in example config + for key in template_config: + if key != 'optional': + assert key in config +except FileNotFoundError: + logger.error(f"No config file found at {template_config_path}! ") + raise +except AssertionError: + logger.error(f"Required config fields from {template_config_path} do not match {config.keys()}") + raise +# Check if optional field available +if 'optional' not in config: + config['optional'] = {} +# Check optional fields and include in config if not present +for optkey, value in template_config['optional'].items(): + if optkey not in config['optional']: + config['optional'][optkey] = value + logger.info(f"Added optional field: \"{optkey}\" with value: \"{value}\" to config.") + + # Parse YAML rule config file if 'rule_config' in config and config['rule_config']: try: @@ -1544,11 +1575,11 @@ rule prepare_multiqc_config: "multiqc_config.yaml") params: - logo_path = config['report_logo'], - multiqc_intro_text = config['report_description'], - url = config['report_url'], - author_name = config['author_name'], - author_email = config['author_email'], + logo_path = config['optional']['report_logo'], + multiqc_intro_text = config['optional']['report_description'], + url = config['optional']['report_url'], + author_name = config['optional']['author_name'], + author_email = config['optional']['author_email'], additional_params = parse_rule_config( rule_config, current_rule=current_rule,