Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions lib/Validation.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import groovy.json.JsonSlurper
import groovy.util.logging.Log

class Validation {

/*
* Function to loop over all parameters defined in schema and check
* whether the given paremeters adhere to the specificiations
*/
private static void validateParameters(params, json_schema, log, workflow){

def json = new File(json_schema).text
def Map json_params = (Map) new JsonSlurper().parseText(json).get('definitions')
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
def specified_param_keys = params.keySet()
def nf_params = ['profile', 'config', 'c', 'C', 'syslog', 'd', 'dockerize',
'bg', 'h', 'log', 'quiet', 'q', 'v', 'version']
def valid_params = []
def expected_params = []
def blacklist = ['hostnames'] // ignored parameters
Comment thread
KevinMenden marked this conversation as resolved.
Outdated


// Loop over all parameters in schema and compare to given parameters
for (group in json_params){
for (p in group.value['properties']){
if (!blacklist.contains(p.key)){
valid_params.push(validateParamPair(params[p.key], p, log))
expected_params.push(p.key)
}
}
}

// Exit if any invalid params where found
if (valid_params.contains(false)){
System.exit(0)
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
}

// Check for nextflow core params and unexpected params
for (specified_param in specified_param_keys){
// nextflow params
if (nf_params.contains(specified_param)){
log.error "ERROR: You have overwritten the core Nextflow parameter -${specified_param} with --${specified_param}!"
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
System.exit(0)
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
}
// unexpected params
if (!expected_params.contains(specified_param)){
log.warn "Unexpected parameter specified: ${specified_param}"
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
}

}

}



/*
* Compare a pair of params (schema, command line) and check whether
* they are valid
*/
private static boolean validateParamPair(given_param, json_param, log){
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
def param_type = json_param.value['type']
def valid_param = true
def required = json_param.value['required']
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
def param_enum = json_param.value['enum']
def param_pattern = json_param.value['pattern']

// Check only if required or parameter is given
if (required || given_param){
def given_param_class = given_param.getClass()
Comment thread
KevinMenden marked this conversation as resolved.
Outdated

switch(param_type) {
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
case 'string':
// If pattern given, check that param adheres to it
if (param_pattern){
valid_param = given_param ==~ param_pattern
}
// If enum given, check that param is within choices
else if (param_enum){
valid_param = param_enum.contains(given_param)
}
// else just check whether valid String
else {
valid_param = given_param_class == String
}
break
case 'boolean':
if (given_param_class == Boolean){
valid_param = true
}
else if (given_param){
valid_param = true
}
break
case 'integer':
valid_param = given_param_class == Integer
break
case 'number':
valid_param = given_param_class == BigDecimal
break
}

if (!valid_param){
log.error "ERROR: Parameter ${json_param.key} is wrong type! Expected ${param_type}, found ${given_param_class}, ${given_param}"
if (param_enum){
log.error "Must be one of: ${param_enum}"
}
if (param_pattern){
log.error "Parameter must adhere to the following pattern: ${param_pattern}"
}
}

}
return valid_param
}

}
4 changes: 4 additions & 0 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if (params.help) {
exit 0
}

////////////////////////////////////////////////////
/* -- VALIDATE PARAMETERS -- */
////////////////////////////////////////////////////
Validation.validateParameters(params, json_schema, log, workflow)
////////////////////////////////////////////////////
/* -- PRINT PARAMETER SUMMARY -- */
////////////////////////////////////////////////////
Expand Down
22 changes: 11 additions & 11 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
params {

// Workflow flags
genome = false
input = 'data/*R1.fastq.gz'
genome = ''
input = ''
outdir = './results'
publish_dir_mode = 'copy'

Expand All @@ -20,7 +20,7 @@ params {
save_reference = false
min_aln_length = 15
star_ignore_sjdbgtf = false
seq_center = false
seq_center = ''
Comment thread
KevinMenden marked this conversation as resolved.
Outdated

// Trimming options
save_trimmed = false
Expand Down Expand Up @@ -48,7 +48,7 @@ params {
ribo_database_manifest = "$baseDir/assets/rrna-db-defaults.txt"

//Output options
bigwig=false
bigwig = false

//Clustering options
min_cluster = 30
Expand All @@ -59,9 +59,9 @@ params {

// Boilerplate options
enable_conda = false
name = false
clusterOptions = false
multiqc_config = false
name = ''
clusterOptions = ''
multiqc_config = ''
email = false
email_on_fail = false
max_multiqc_email_size = 25.MB
Expand All @@ -73,10 +73,10 @@ params {
igenomes_ignore = false
custom_config_version = 'master'
custom_config_base = "https://raw.githubusercontent.com/nf-core/configs/${params.custom_config_version}"
hostnames = false
config_profile_description = false
config_profile_contact = false
config_profile_url = false
hostnames = ''
config_profile_description = ''
config_profile_contact = ''
config_profile_url = ''
skip_multiqc = false

// Defaults only, expecting to be overwritten
Expand Down
3 changes: 3 additions & 0 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"description": "File size limit when attaching MultiQC reports to summary emails.",
"default": "25.MB",
"fa_icon": "fas fa-file-upload",
"pattern": "\\d+\\.?\\s*[KMGT]?B?",
"hidden": true,
"help_text": "If file generated by pipeline exceeds the threshold, it will not be attached."
},
Expand Down Expand Up @@ -392,6 +393,7 @@
"description": "Maximum amount of memory that can be requested for any single job.",
"default": "128.GB",
"fa_icon": "fas fa-memory",
"pattern": "\\d+\\.?\\s*[KMGT]?B?",
Comment thread
KevinMenden marked this conversation as resolved.
Outdated
"hidden": true,
"help_text": "Use to set an upper-limit for the memory requirement for each process. Should be a string in the format integer-unit e.g. `--max_memory '8.GB'`"
},
Expand All @@ -401,6 +403,7 @@
"default": "240.h",
"fa_icon": "far fa-clock",
"hidden": true,
"pattern": "\\d+\\.?\\s*[mhd]",
"help_text": "Use to set an upper-limit for the time requirement for each process. Should be a string in the format integer-unit e.g. `--max_time '2.h'`"
}
}
Expand Down