/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Config file for defining DSL2 per module options and publishing paths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Available keys to override module options:
        ext.args            = Additional arguments appended to command in module.
        ext.args2           = Second set of arguments appended to command in module (multi-tool modules).
        ext.args3           = Third set of arguments appended to command in module (multi-tool modules).
        ext.prefix          = File name prefix for output files.
        ext.when            = Conditional clause
----------------------------------------------------------------------------------------
*/

//
// Bwamem2 alignment options
//

process {
    withName: '.*ALIGN_BWAMEM2:.*' {
        ext.when = params.aligner.equals("bwamem2")
    }

    withName: '.*ALIGN:ALIGN_BWAMEM2:BWAMEM2_MEM' {
        ext.args = { "-M -K 100000000 -R ${meta.read_group}" }
    }

    withName: '.*ALIGN:ALIGN_BWAMEM2:SAMTOOLS_STATS' {
        ext.args = '-s --remove-overlaps'
    }

    withName: '.*ALIGN:ALIGN_BWAMEM2:SAMTOOLS_MERGE' {
        ext.prefix = { "${meta.id}_sorted_merged" }
    }

    withName: '.*ALIGN:ALIGN_BWAMEM2:MARKDUPLICATES' {
        ext.prefix = { "${meta.id}_sorted_md" }
        publishDir = [
            enabled: !params.save_mapped_as_cram,
            path: { "${params.outdir}/alignment" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*ALIGN:ALIGN_BWAMEM2:SAMTOOLS_INDEX_MARKDUP' {
        publishDir = [
            enabled: !params.save_mapped_as_cram,
            path: { "${params.outdir}/alignment" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

}
