/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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
----------------------------------------------------------------------------------------
*/

//
// Sentieon alignment options
//

process {

    if (params.aligner.equals("sentieon")) {
        withName: '.*ALIGN:ALIGN_SENTIEON:SENTIEON_BWAMEM' {
            ext.args = { "-M -K 10000000 -R ${meta.read_group} " }
            ext.prefix = { "${meta.id}.sorted" }
        }

        withName: '.*ALIGN:ALIGN_SENTIEON:SENTIEON_DATAMETRICS' {
            ext.prefix = { "${meta.id}_datametrics" }
        }

        withName: '.*ALIGN:ALIGN_SENTIEON:SENTIEON_READWRITER' {
            ext.prefix = { "${meta.id}_merged" }
        }

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