Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parameters validation #69

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6e50215
FastQC updated to allow more than 512MB memory per thread
fellen31 Mar 15, 2024
f42334e
Allow bcftools merge to run on a single file
fellen31 Mar 15, 2024
dfd2c89
Memory requirements shouldn't be hardcoded
fellen31 Mar 15, 2024
03b72f4
Add BED-file usage in modkit/pileup
fellen31 Mar 18, 2024
722ea5d
Move dipcall alignment argument to conf, needed for low-memory test p…
fellen31 Mar 18, 2024
fdf5521
Allow reference to be gzipped
fellen31 Mar 20, 2024
b8f5b86
forgot to add module
fellen31 Mar 20, 2024
e928c57
Merge dev into prepare-pipeline-for-test-profile
fellen31 Mar 22, 2024
4b1da4b
Lower memory requirements for assembly
fellen31 Mar 22, 2024
58a8f67
Add docker runoptions
fellen31 Mar 22, 2024
74483a4
add comment
fellen31 Mar 22, 2024
21d09dc
Update changelog
fellen31 Mar 22, 2024
8305665
Initial template commit
fellen31 Mar 22, 2024
5cb61a3
merge template
fellen31 Mar 22, 2024
4409265
merge
fellen31 Mar 22, 2024
a528dd7
patch bcftools/merge
fellen31 Mar 22, 2024
4ea6471
working merge
fellen31 Mar 22, 2024
175a98c
update modules.json
fellen31 Mar 22, 2024
a775cb1
remove acidentally (?) commited orig-files
fellen31 Mar 22, 2024
bcaf240
refactor parameters validations
fellen31 Mar 22, 2024
95265ac
merge
fellen31 Apr 5, 2024
844f50f
wip
fellen31 Apr 5, 2024
c4c9256
wip
fellen31 Apr 5, 2024
b87b468
fix merge mistakes
fellen31 Apr 5, 2024
06d8d9f
fix more merge mistakes
fellen31 Apr 5, 2024
f8cd385
typo
fellen31 Apr 5, 2024
9b85dc5
small fixes
fellen31 Apr 5, 2024
44f2827
remove file
fellen31 Apr 5, 2024
b7ba23c
regenerate fastq patch
fellen31 Apr 5, 2024
3042d23
Update CHANGELOG
fellen31 Apr 5, 2024
3d3e220
Merge branch 'dev' into refactor-parameters-validation
fellen31 Apr 5, 2024
159a83b
update explanations
fellen31 Apr 5, 2024
7c1b560
Add back fromSamplesheet
fellen31 Apr 5, 2024
1a14fd9
Update CHANGELOG.md
fellen31 Apr 8, 2024
f1ccc65
Update workflows/skierfe.nf
fellen31 Apr 8, 2024
6b2d984
Remove double quotes
fellen31 Apr 15, 2024
ae544c7
Merge branch 'dev' into refactor-parameters-validation
fellen31 Apr 15, 2024
5065c0e
simplify maps
fellen31 Apr 16, 2024
3ea38d2
rename workflow variable
fellen31 Apr 16, 2024
aeeeacb
formatting
fellen31 Apr 17, 2024
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
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ Initial release of genomic-medicine-sweden/skierfe, created with the [nf-core](h

### `Added`

- Refactored conditionally required parameters validation [#69](https://github.com/genomic-medicine-sweden/skierfe/pull/69)
- Added CNV workflow to test profile [#68](https://github.com/genomic-medicine-sweden/skierfe/pull/68)
- Update and rename output directories [#65](https://github.com/genomic-medicine-sweden/skierfe/pull/65)
- Update GLNexus version [#58](https://github.com/genomic-medicine-sweden/skierfe/pull/58)
- Updated and rename output directories [#65](https://github.com/genomic-medicine-sweden/skierfe/pull/65)
- Updated GLNexus version [#58](https://github.com/genomic-medicine-sweden/skierfe/pull/58)
- Added uBAM support and multisample test [#51](https://github.com/genomic-medicine-sweden/skierfe/pull/51)
- Added Revio BAM test data [#50](https://github.com/genomic-medicine-sweden/skierfe/pull/50)
- Update template to 2.13.1 [#38](https://github.com/genomic-medicine-sweden/skierfe/pull/38)
- Update pipeline to run with a small test dataset [#35](https://github.com/genomic-medicine-sweden/skierfe/pull/35)
- Updated template to 2.13.1 [#38](https://github.com/genomic-medicine-sweden/skierfe/pull/38)
- Updated pipeline to run with a small test dataset [#35](https://github.com/genomic-medicine-sweden/skierfe/pull/35)
- Added test data and test profile [#33](https://github.com/genomic-medicine-sweden/skierfe/pull/33)

### `Fixed`
Expand Down
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ params {
dipcall_par = null
extra_snfs = null
extra_gvcfs = null
skip_qc = null
skip_qc = false
skip_assembly_wf = false
skip_mapping_wf = false
skip_methylation_wf = false
Expand Down
196 changes: 194 additions & 2 deletions subworkflows/local/utils_nfcore_skierfe_pipeline/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,81 @@ include { imNotification } from '../../nf-core/utils_nfcore_pipeline'
include { UTILS_NFCORE_PIPELINE } from '../../nf-core/utils_nfcore_pipeline'
include { workflowCitation } from '../../nf-core/utils_nfcore_pipeline'

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DEFINE DEPENDENCIES (FILES AND WORKFLOWS) FOR OTHER WORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

// nf-validation does not support contitional file and params validation,
// add these here.
//
// For workflows:
// - The cnv_calling workflow depends on the mapping and short_variant_calling workflows.
// It can't be run if either of --skip_mapping_wf or --skip_short_variant_calling is active.
//
// For files:
// - Since the assembly workflow relies on the dipcall dipcall_par file,
// dipcall_par has to be set whenever --skip_assembly_wf is not active.
//
// For presets:
// - Preset "pacbio" can't be run without --skip_methylation_wf.
fellen31 marked this conversation as resolved.
Show resolved Hide resolved
//

def parameterDependencies = [
workflow: [
skip_assembly_wf : [],
skip_short_variant_calling: ["skip_mapping_wf"],
skip_snv_annotation : ["skip_mapping_wf", "skip_short_variant_calling"],
skip_cnv_calling : ["skip_mapping_wf", "skip_short_variant_calling"],
skip_phasing_wf : ["skip_mapping_wf", "skip_short_variant_calling"],
skip_repeat_wf : ["skip_mapping_wf", "skip_short_variant_calling", "skip_phasing_wf"],
skip_methylation_wf : ["skip_mapping_wf", "skip_short_variant_calling", "skip_phasing_wf"],
],
files: [
dipcall_par : ["skip_assembly_wf"],
snp_db : ["skip_snv_annotation"],
vep_cache : ["skip_snv_annotation"],
hificnv_xy : ["skip_cnv_calling"],
hificnv_xx : ["skip_cnv_calling"],
hificnv_exclude: ["skip_cnv_calling"],
trgt_repeats : ["skip_repeat_wf"],
],
preset: [
pacbio : ["skip_methylation_wf"],
ONT_R10: ["skip_assembly_wf", "skip_cnv_calling"],
revio : [],
]
]

def parameterStatus = [
workflow: [
skip_short_variant_calling: params.skip_short_variant_calling,
skip_phasing_wf : params.skip_phasing_wf,
skip_methylation_wf : params.skip_methylation_wf,
skip_repeat_wf : params.skip_repeat_wf,
skip_snv_annotation : params.skip_snv_annotation,
skip_cnv_calling : params.skip_cnv_calling,
skip_mapping_wf : params.skip_mapping_wf,
skip_qc : params.skip_qc,
skip_assembly_wf : params.skip_assembly_wf,
],
files: [
dipcall_par : params.dipcall_par,
snp_db : params.snp_db,
vep_cache : params.vep_cache,
hificnv_xy : params.hificnv_xy,
hificnv_xx : params.hificnv_xx,
hificnv_exclude: params.hificnv_exclude,
trgt_repeats : params.trgt_repeats,
],
preset: [
pacbio : params.preset == "pacbio",
revio : params.preset == "revio",
ONT_R10: params.preset == "ONT_R10",
]
]

/*
========================================================================================
SUBWORKFLOW TO INITIALISE PIPELINE
Expand Down Expand Up @@ -75,7 +150,7 @@ workflow PIPELINE_INITIALISATION {
//
// Custom validation for pipeline parameters
//
validateInputParameters()
validateInputParameters(parameterDependencies, parameterStatus)

//
// Create channel from input file provided through params.input
Expand Down Expand Up @@ -137,8 +212,10 @@ workflow PIPELINE_COMPLETION {
//
// Check and validate pipeline parameters
//
def validateInputParameters() {

def validateInputParameters(statusMap, paramsMap) {
genomeExistsError()
validateParameterCombinations(statusMap, paramsMap)
}

//
Expand Down Expand Up @@ -228,3 +305,118 @@ def methodsDescriptionText(mqc_methods_yaml) {

return description_html.toString()
}

//
// Validate preset and workflow skip combinations
//
def validateParameterCombinations(combinationsMap, statusMap) {
// Array to store errors
def errors = []
// For each of the "workflow", "files", "preset"
statusMap.each { paramsType, allParams ->
// Go through all params and their status
statusMap[paramsType].each { param, paramStatus ->
switch (paramsType) {
case "files":
checkFileDependencies(param, combinationsMap[paramsType], statusMap, errors)
case "workflow":
checkWorkflowDependencies(param, combinationsMap[paramsType], statusMap, errors)
case "preset":
checkPresetDependencies(param, combinationsMap[paramsType], statusMap, errors)
default:
break
}
}
}
// Give error if there are any
if(errors) {
def error_string =
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" " + errors.join("\n ") + "\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
error(error_string)
}
}

//
// Lookup all other workflows that needs to be active for a certain workflow
//
def checkPresetDependencies(String preset, Map combinationsMap, Map statusMap, List errors) {
// Get the status of param
presetIsActive = statusMap["preset"][preset]
// If preset is not active, then give no error
if(!presetIsActive) {
return
}
// Get all required skips for a preset
def requiredSkips = combinationsMap[preset] as Set
// If there are no required skips, give no error
if(requiredSkips.size() == 0) {
return
}
// Collect the required --skips that are not active for the current preset
def dependencyString = findRequiredSkips("workflow", requiredSkips, statusMap)
.collect { "--$it" }
.join(" ")
errors << "--preset $preset is active, the pipeline has to be run with: $dependencyString"
return errors
}

def checkWorkflowDependencies(String workflow, Map combinationsMap, Map statusMap, List errors) {
// Get the status of param
paramStatus = statusMap["workflow"][workflow]
// If skip-parameter is not set, then workflow is active
activeWorkflow = !paramStatus
// If workflow is active, give no error
if(activeWorkflow) {
return
}
// Get all other worflows that need to be skipped when a certain workflow is skipped
def requiredWorkflows = combinationsMap.findAll { it.value.contains(workflow) }.keySet()
// If there are no required parameters, give no error
if(requiredWorkflows.size() == 0) {
return
}
// Collect the required --skips that are not active for the current workflow
def dependencyString = findRequiredSkips("workflow", requiredWorkflows, statusMap)
.collect { "--$it" }
.join(" ")

errors << "--$workflow is active, the pipeline has to be run with: $dependencyString"
return errors
}
//
// Lookup if a file is required by any workflows, and add to errors
//
def checkFileDependencies(String fileParam, Map combinationsMap, Map statusMap, List errors) {
// Get the the workflow required by file (a file should only be required by one workflow)
def workflowThatRequiresFile = combinationsMap[fileParam][0]
// Get status of that workflow
def WorkflowIsOff = statusMap["workflow"][workflowThatRequiresFile]
def WorkflowIsActive = !WorkflowIsOff
// Get the file path
def FilePath = statusMap["files"][fileParam]
// If the workflow that requires the file is active & theres no file available
if(WorkflowIsActive && FilePath == null) {
errors << "--$workflowThatRequiresFile is NOT active, the following files are required: --$fileParam"
}
return errors
}
//
// Find the workflow skips that are not active
//
def findRequiredSkips(presetType, Set<String> requiredWorkflows, Map statusMap) {
// Define a list to hold which additional parameters that need to be set
def skipsNeededToBeActive = []
// For all required workflows, check which are not skipped
for (requiredWorkflow in requiredWorkflows) {
// Get the status of the required workflow
requiredWorkflowIsSkipped = statusMap[presetType][requiredWorkflow]
// If that workflow is not skipped
if(!requiredWorkflowIsSkipped) {
// Add it to list of workflows that need to be skipped
skipsNeededToBeActive << requiredWorkflow
}
}
return skipsNeededToBeActive
}
Loading
Loading