Skip to content
Snippets Groups Projects
Commit ef68b765 authored by Dominik Burri's avatar Dominik Burri
Browse files

validate config on required and optional fields #174

parent b5db2001
No related branches found
No related tags found
1 merge request!91Config validation
Pipeline #12872 failed
--- ---
# Required fields
samples: "../input_files/samples.tsv" samples: "../input_files/samples.tsv"
rule_config: "../input_files/rule_config.yaml" rule_config: "../input_files/rule_config.yaml"
output_dir: "results" output_dir: "results"
...@@ -7,9 +8,11 @@ ...@@ -7,9 +8,11 @@
salmon_indexes: "results/salmon_indexes" salmon_indexes: "results/salmon_indexes"
star_indexes: "results/star_indexes" star_indexes: "results/star_indexes"
alfa_indexes: "results/alfa_indexes" alfa_indexes: "results/alfa_indexes"
report_description: "No description provided by user" # Optional fields
report_logo: "../../images/logo.128px.png" optional:
report_url: "https://zavolan.biozentrum.unibas.ch/" report_description: "No description provided by user"
author_name: "NA" report_logo: "../../images/logo.128px.png"
author_email: "NA" report_url: "https://zavolan.biozentrum.unibas.ch/"
author_name: "NA"
author_email: "NA"
... ...
...@@ -17,6 +17,37 @@ samples_table = pd.read_csv( ...@@ -17,6 +17,37 @@ samples_table = pd.read_csv(
sep="\t", 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 # Parse YAML rule config file
if 'rule_config' in config and config['rule_config']: if 'rule_config' in config and config['rule_config']:
try: try:
...@@ -1544,11 +1575,11 @@ rule prepare_multiqc_config: ...@@ -1544,11 +1575,11 @@ rule prepare_multiqc_config:
"multiqc_config.yaml") "multiqc_config.yaml")
params: params:
logo_path = config['report_logo'], logo_path = config['optional']['report_logo'],
multiqc_intro_text = config['report_description'], multiqc_intro_text = config['optional']['report_description'],
url = config['report_url'], url = config['optional']['report_url'],
author_name = config['author_name'], author_name = config['optional']['author_name'],
author_email = config['author_email'], author_email = config['optional']['author_email'],
additional_params = parse_rule_config( additional_params = parse_rule_config(
rule_config, rule_config,
current_rule=current_rule, current_rule=current_rule,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment