/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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   = When to run the module.
----------------------------------------------------------------------------------------
*/

// UMI

process {

    withName: 'FASTQTOBAM' {
        ext.prefix       = {"${meta.id}"}
        ext.args         = { "--read-structures $params.umi_read_structure" }
        publishDir       = [
            //specify to avoid publishing, overwritten otherwise
            enabled: false
        ]
    }

    withName: 'BAM2FASTQ' {
        ext.args         = '-T RX'
        ext.when         = { params.umi_read_structure }
        publishDir       = [
            //specify to avoid publishing, overwritten otherwise
            enabled: false
        ]
    }

    if (params.umi_read_structure) {
        withName: "NFCORE_SAREK:SAREK:FASTQ_CREATE_UMI_CONSENSUS_FGBIO:ALIGN_UMI:BWAMEM.*_MEM" {
            ext.args         = { "-K 100000000 -p -C -Y -R ${meta.read_group}" }
            ext.args2        = '-bS'
            ext.prefix       = {"${meta.id}.umi_unsorted"}
            publishDir       = [
                //specify to avoid publishing, overwritten otherwise
                enabled: false
            ]
        }

        withName: "NFCORE_SAREK:SAREK:FASTQ_CREATE_UMI_CONSENSUS_FGBIO:ALIGN_UMI:DRAGMAP_ALIGN" {
            ext.args2        = '-bS'
            ext.prefix       = {"${meta.id}.umi_unsorted"}
            publishDir       = [
                //specify to avoid publishing, overwritten otherwise
                enabled: false
            ]
        }
    }

    withName: 'SAMBLASTER' {
        ext.args         = '-M --addMateTags'
        ext.prefix       = {"${meta.id}_unsorted_tagged"}
        publishDir       = [
            //specify to avoid publishing, overwritten otherwise
            enabled: false
        ]
    }

    withName: 'GROUPREADSBYUMI' {
        publishDir       = [
            [   path: { "${params.outdir}/reports/umi/" },
                mode: params.publish_dir_mode,
                pattern: "*.{txt}"
            ]
        ]
    }

    withName: 'CALLUMICONSENSUS' {
        ext.args         = '-M 1 -S Coordinate'
        ext.prefix       = {"${meta.id}_umi-consensus"}
        publishDir       = [
            path: { "${params.outdir}/preprocessing/umi/${meta.sample}" },
            mode: params.publish_dir_mode,
            pattern: "*.{bam}"
        ]
    }
}
