diff --git a/CHANGELOG.md b/CHANGELOG.md index 532dcfd0..1de7c494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### `Added` +- A new parameter `bwa_as_fallback` to switch aligner to bwa in case bwamem2 fails [#551](https://github.com/nf-core/raredisease/pull/551) + ### `Changed` - Changed valid values for sex according to the PED file format [#550](https://github.com/nf-core/raredisease/pull/550) diff --git a/conf/modules/align_bwa_bwamem2.config b/conf/modules/align_bwa_bwamem2.config index 30d14cf4..2ff7ea89 100644 --- a/conf/modules/align_bwa_bwamem2.config +++ b/conf/modules/align_bwa_bwamem2.config @@ -21,14 +21,18 @@ process { ext.args = { "-M -K 100000000 -R ${meta.read_group}" } ext.args2 = { "-T ./samtools_sort_tmp" } ext.prefix = { "${meta.id}_sorted" } - ext.when = { params.aligner.equals("bwamem2") } + } + + withName: '.*ALIGN:ALIGN_BWA_BWAMEM2:BWAMEM_FALLBACK' { + ext.args = { "-M -K 100000000 -R ${meta.read_group}" } + ext.args2 = { "-T ./samtools_sort_tmp" } + ext.prefix = { "${meta.id}_sorted" } } withName: '.*ALIGN:ALIGN_BWA_BWAMEM2:BWA_MEM' { ext.args = { "-M -K 100000000 -R ${meta.read_group}" } ext.args2 = { "-T ./samtools_sort_tmp" } ext.prefix = { "${meta.id}_sorted" } - ext.when = { params.aligner.equals("bwa") } } withName: '.*ALIGN:ALIGN_BWA_BWAMEM2:SAMTOOLS_STATS' { diff --git a/nextflow.config b/nextflow.config index a0dcaa43..5cba4e97 100644 --- a/nextflow.config +++ b/nextflow.config @@ -22,6 +22,7 @@ params { // Main options analysis_type = 'wgs' + bwa_as_fallback = false bait_padding = 100 run_rtgvcfeval = false save_mapped_as_cram = false diff --git a/nextflow_schema.json b/nextflow_schema.json index 8e5ed746..674c19c8 100644 --- a/nextflow_schema.json +++ b/nextflow_schema.json @@ -465,6 +465,12 @@ "fa_icon": "fas fa-align-center", "enum": ["wgs", "wes", "mito"] }, + "bwa_as_fallback": { + "type": "boolean", + "description": "Specifies whether or not to use bwa as a fallback aligner in case bwamem2 throws an error.", + "help_text": "errorStrategy needs to be set to ignore for the bwamem2 process for the fallback to work. Turned off by default.", + "fa_icon": "fas fa-toggle-on" + }, "platform": { "type": "string", "default": "illumina", diff --git a/subworkflows/local/alignment/align_bwa_bwamem2.nf b/subworkflows/local/alignment/align_bwa_bwamem2.nf index ab5b8d9b..b846cad3 100644 --- a/subworkflows/local/alignment/align_bwa_bwamem2.nf +++ b/subworkflows/local/alignment/align_bwa_bwamem2.nf @@ -3,6 +3,7 @@ // include { BWA_MEM } from '../../../modules/nf-core/bwa/mem/main' +include { BWA_MEM as BWAMEM_FALLBACK } from '../../../modules/nf-core/bwa/mem/main' include { BWAMEM2_MEM } from '../../../modules/nf-core/bwamem2/mem/main' include { SAMTOOLS_INDEX as SAMTOOLS_INDEX_ALIGN } from '../../../modules/nf-core/samtools/index/main' include { SAMTOOLS_INDEX as SAMTOOLS_INDEX_MARKDUP } from '../../../modules/nf-core/samtools/index/main' @@ -30,8 +31,25 @@ workflow ALIGN_BWA_BWAMEM2 { ch_versions = ch_versions.mix(BWA_MEM.out.versions.first()) } else { BWAMEM2_MEM ( ch_reads_input, ch_bwamem2_index, true ) - ch_align = BWAMEM2_MEM.out.bam + ch_align = BWAMEM2_MEM.out.bam ch_versions = ch_versions.mix(BWAMEM2_MEM.out.versions.first()) + + if (params.bwa_as_fallback) { + ch_reads_input + .join(BWAMEM2_MEM.out.bam, remainder: true) + .branch { it -> + ERROR: it[2].equals(null) + return [it[0], it[1]] // return reads + SUCCESS: !it[2].equals(null) + return [it[0], it[2]] // return bam + } + .set { ch_fallback } + + BWAMEM_FALLBACK ( ch_fallback.ERROR, ch_bwa_index, true ) + ch_align = ch_fallback.SUCCESS.mix(BWAMEM_FALLBACK.out.bam) + ch_versions = ch_versions.mix(BWAMEM_FALLBACK.out.versions.first()) + } + } SAMTOOLS_INDEX_ALIGN ( ch_align )