Skip to content

Commit

Permalink
Remove nested ifs in nallo.nf (#493)
Browse files Browse the repository at this point in the history
* Refactor nallo.nf

* review suggestions
  • Loading branch information
fellen31 authored Nov 11, 2024
1 parent c88bafb commit 42ec814
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 377 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#486](https://github.com/genomic-medicine-sweden/nallo/pull/486) - Updated nf-core modules
- [#487](https://github.com/genomic-medicine-sweden/nallo/pull/487) - Changed CI tests to only run tests where changes have been made
- [#489](https://github.com/genomic-medicine-sweden/nallo/pull/489) - Updated nf-core template to 3.0.2
- [#493](https://github.com/genomic-medicine-sweden/nallo/pull/493) - Refactored `nallo.nf` to remove many nested ifs and easier to follow logic
- [#493](https://github.com/genomic-medicine-sweden/nallo/pull/493) - Updated rank_variants dependencies with sv_annotation

### `Removed`

Expand Down
14 changes: 8 additions & 6 deletions subworkflows/local/convert_input_files.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ workflow CONVERT_INPUT_FILES {

take:
ch_sample // channel: [ val(meta), reads ]
convert_bam // bool
convert_fastq // bool

main:
Expand All @@ -20,19 +21,20 @@ workflow CONVERT_INPUT_FILES {
ch_bam = ch_filetypes.bam
ch_fastq = ch_filetypes.fastq

if(convert_fastq) {
if(convert_bam) {
SAMTOOLS_FASTQ ( ch_filetypes.bam, false )
ch_versions = ch_versions.mix(SAMTOOLS_FASTQ.out.versions)

// Mix converted files back in
ch_fastq = ch_fastq.mix(SAMTOOLS_FASTQ.out.other)
}
if(convert_fastq) {
SAMTOOLS_IMPORT ( ch_filetypes.fastq )
ch_versions = ch_versions.mix(SAMTOOLS_IMPORT.out.versions)

SAMTOOLS_IMPORT ( ch_filetypes.fastq )
ch_versions = ch_versions.mix(SAMTOOLS_IMPORT.out.versions)

// Mix converted files back in
ch_bam = ch_bam.mix(SAMTOOLS_IMPORT.out.bam)
// Mix converted files back in
ch_bam = ch_bam.mix(SAMTOOLS_IMPORT.out.bam)
}

emit:
bam = ch_bam // channel: [ val(meta), bam ]
Expand Down
4 changes: 2 additions & 2 deletions subworkflows/local/methylation/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ nextflow_workflow {
[ id:'hg38' ],
file(params.pipelines_testdata_base_path + 'reference/hg38.test.fa.gz', checkIfExists: true)
])
input[1] = true
input[2] = Channel.empty()
input[1] = Channel.empty()
input[2] = true
input[3] = false
"""
}
Expand Down
28 changes: 13 additions & 15 deletions subworkflows/local/prepare_genome.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ include { UNTAR as UNTAR_VEP_CACHE } from '../../modules/nf-core/untar/main'
workflow PREPARE_GENOME {

take:
fasta_in // channel: [mandatory] [ val(meta), path(fasta) ]
gunzip_fasta // bool: should we gunzip fasta
ch_vep_cache // channel: [optional] [ val(meta), path(cache) ]
split_vep_files // bool: are there vep extra files
fasta_in // channel: [ val(meta), path(fasta) ]
ch_vep_cache // channel: [ val(meta), path(cache) ]
gunzip_fasta // boolean: should we gunzip fasta
untar_vep_cache // boolean: should we untar vep cache

main:
ch_versions = Channel.empty()
Expand All @@ -35,17 +35,15 @@ workflow PREPARE_GENOME {
MINIMAP2_INDEX ( ch_fasta )
ch_versions = ch_versions.mix(MINIMAP2_INDEX.out.versions)

UNTAR_VEP_CACHE (ch_vep_cache)
ch_versions = ch_versions.mix(UNTAR_VEP_CACHE.out.versions)

UNTAR_VEP_CACHE.out.untar
.collect()
.set { untarred_vep }
if (untar_vep_cache) {
UNTAR_VEP_CACHE (ch_vep_cache)
ch_versions = ch_versions.mix(UNTAR_VEP_CACHE.out.versions)
}

emit:
mmi = MINIMAP2_INDEX.out.index.collect() // channel: [ val(meta), path(mmi) ]
fai = SAMTOOLS_FAIDX.out.fai.collect() // channel: [ val(meta), path(fai) ]
fasta = ch_fasta // channel: [ val(meta), path(fasta) ]
vep_resources = untarred_vep // channel: [ val(meta), path(cache) ]
versions = ch_versions // channel: [ versions.yml ]
mmi = MINIMAP2_INDEX.out.index.collect() // channel: [ val(meta), path(mmi) ]
fai = SAMTOOLS_FAIDX.out.fai.collect() // channel: [ val(meta), path(fai) ]
fasta = ch_fasta // channel: [ val(meta), path(fasta) ]
vep_resources = untar_vep_cache ? UNTAR_VEP_CACHE.out.untar.collect() : ch_vep_cache // channel: [ val(meta), path(cache) ]
versions = ch_versions // channel: [ versions.yml ]
}
4 changes: 2 additions & 2 deletions subworkflows/local/rank_variants/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ nextflow_workflow {
[ id:'hg38' ],
file(params.pipelines_testdata_base_path + 'reference/hg38.test.fa.gz', checkIfExists: true)
])
input[1] = true
input[2] = [
input[1] = [
[ id: 'vep_cache' ],
file(params.pipelines_testdata_base_path + 'reference/vep_cache_test_data.tar.gz', checkIfExists:true)
]
input[2] = true
input[3] = true
"""
}
Expand Down
9 changes: 7 additions & 2 deletions subworkflows/local/utils_nfcore_nallo_pipeline/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def workflowDependencies = [
snv_annotation : ["mapping", "snv_calling"],
cnv_calling : ["mapping", "snv_calling"],
phasing : ["mapping", "snv_calling"],
rank_variants : ["mapping", "snv_calling", "snv_annotation"],
rank_variants : ["mapping", "snv_calling", "snv_annotation", "sv_annotation"],
repeat_calling : ["mapping", "snv_calling", "phasing"],
repeat_annotation: ["mapping", "snv_calling", "phasing", "repeat_calling"],
methylation : ["mapping", "snv_calling"]
Expand Down Expand Up @@ -165,6 +165,7 @@ workflow PIPELINE_INITIALISATION {
// Custom validation for pipeline parameters
//
validateInputParameters(parameterStatus, workflowSkips, workflowDependencies, fileDependencies)
validatePacBioLicense()

//
// Create channel from input file provided through params.input
Expand Down Expand Up @@ -322,7 +323,6 @@ def toolCitationText() {

def citation_text = [
"MultiQC (Ewels et al. 2016)",
"SAMtools (Danecek et al. 2021)",
]
if (!params.skip_mapping_wf) {
if (params.parallel_alignments > 1) {
Expand Down Expand Up @@ -653,3 +653,8 @@ def createReferenceChannelFromSamplesheet(param, schema, defaultValue = '') {
return param ? Channel.fromList(samplesheetToList(param, schema)) : defaultValue
}

def validatePacBioLicense() {
if (params.phaser.matches('hiphase') && params.preset == 'ONT_R10') {
error "ERROR: The HiPhase license only permits analysis of data from PacBio."
}
}
18 changes: 15 additions & 3 deletions tests/samplesheet.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test profile": {
"content": [
112,
113,
{
"ADD_FOUND_IN_TAG": {
"bcftools": 1.2,
Expand Down Expand Up @@ -87,6 +87,9 @@
"ENSEMBLVEP_SNV": {
"ensemblvep": 110.0
},
"ENSEMBLVEP_SV": {
"ensemblvep": 110.0
},
"FASTQC": {
"fastqc": "0.12.1"
},
Expand Down Expand Up @@ -206,18 +209,27 @@
"svdb": "2.8.2",
"bcftools": 1.21
},
"SVDB_QUERY": {
"svdb": "2.8.2"
},
"TABIX_BGZIPTABIX": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SNV": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SV": {
"tabix": 1.2
},
"TABIX_LONGPHASE_PHASE": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE_SVS_CNVS": {
"tabix": 1.2
},
"TABIX_TABIX": {
"tabix": 1.2
},
Expand Down Expand Up @@ -656,6 +668,6 @@
"nf-test": "0.9.0",
"nextflow": "24.04.4"
},
"timestamp": "2024-11-06T10:59:47.782981349"
"timestamp": "2024-11-07T12:46:21.477060114"
}
}
}
18 changes: 15 additions & 3 deletions tests/samplesheet_multisample_bam.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"samplesheet_multisample_bam | --phaser hiphase": {
"content": [
155,
156,
{
"ADD_FOUND_IN_TAG": {
"bcftools": 1.2,
Expand Down Expand Up @@ -87,6 +87,9 @@
"ENSEMBLVEP_SNV": {
"ensemblvep": 110.0
},
"ENSEMBLVEP_SV": {
"ensemblvep": 110.0
},
"FASTQC": {
"fastqc": "0.12.1"
},
Expand Down Expand Up @@ -203,15 +206,24 @@
"svdb": "2.8.2",
"bcftools": 1.21
},
"SVDB_QUERY": {
"svdb": "2.8.2"
},
"TABIX_BGZIPTABIX": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SNV": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SV": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE_SVS_CNVS": {
"tabix": 1.2
},
"TABIX_TABIX": {
"tabix": 1.2
},
Expand Down Expand Up @@ -855,6 +867,6 @@
"nf-test": "0.9.0",
"nextflow": "24.04.4"
},
"timestamp": "2024-11-06T11:01:42.969612471"
"timestamp": "2024-11-07T12:48:14.873817687"
}
}
}
16 changes: 14 additions & 2 deletions tests/samplesheet_multisample_ont_bam.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"samplesheet_multisample_ont_bam | --preset ONT_R10 --phaser whatshap --parallel_alignments 1 --parallel_snv 1": {
"content": [
104,
105,
{
"ADD_FOUND_IN_TAG": {
"bcftools": 1.2,
Expand Down Expand Up @@ -75,6 +75,9 @@
"ENSEMBLVEP_SNV": {
"ensemblvep": 110.0
},
"ENSEMBLVEP_SV": {
"ensemblvep": 110.0
},
"FASTQC": {
"fastqc": "0.12.1"
},
Expand Down Expand Up @@ -158,15 +161,24 @@
"svdb": "2.8.2",
"bcftools": 1.21
},
"SVDB_QUERY": {
"svdb": "2.8.2"
},
"TABIX_BGZIPTABIX": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SNV": {
"tabix": 1.2
},
"TABIX_ENSEMBLVEP_SV": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE": {
"tabix": 1.2
},
"TABIX_SVDB_MERGE_SVS_CNVS": {
"tabix": 1.2
},
"TABIX_TABIX": {
"tabix": 1.2
},
Expand Down Expand Up @@ -624,6 +636,6 @@
"nf-test": "0.9.0",
"nextflow": "24.04.4"
},
"timestamp": "2024-11-06T09:55:21.893675661"
"timestamp": "2024-11-07T12:51:02.903461641"
}
}
Loading

0 comments on commit 42ec814

Please sign in to comment.