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

// SENTIEON_DEDUP

process {

    withName: 'SENTIEON_DEDUP' {
        ext.prefix       = { "${meta.id}.dedup" }
        ext.when         = { params.tools && params.tools.split(',').contains('sentieon_dedup') }
        publishDir       = [
            [
                mode: params.publish_dir_mode,
                path: { "${params.outdir}/preprocessing/sentieon_dedup/${meta.id}/" },
                pattern: "*{cram,crai}",
                saveAs: { !params.save_output_as_bam ? it : null }
            ],
            [
                mode: params.publish_dir_mode,
                path: { "${params.outdir}/reports/" },
                pattern: "*{metrics,metrics.multiqc.tsv}",
                saveAs: { !(params.skip_tools && params.skip_tools.split(',').contains('sentieon_dedup_report')) ? "sentieon_dedup/${meta.id}/${it}" : null}
            ]
        ]
    }

    if (params.tools && params.tools.contains('sentieon_dedup')) {
        withName: 'NFCORE_SAREK:SAREK:BAM_SENTIEON_DEDUP:CRAM_QC_MOSDEPTH_SAMTOOLS:SAMTOOLS_STATS' {
            ext.when         = { !(params.skip_tools && params.skip_tools.split(',').contains('samtools')) }
            ext.prefix       = { "${meta.id}.dedup.cram" }
            publishDir       = [
                mode: params.publish_dir_mode,
                path: { "${params.outdir}/reports/samtools/${meta.id}" },
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }
    }

}
