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

// MANTA

process {

    withName: 'MANTA.*' {
        ext.prefix       = { meta.num_intervals <= 1 ? "${meta.id}.manta" : "${meta.id}.manta.${target_bed.simpleName}" }
        ext.args         = { params.wes ? "--exome" : "" }
        ext.when         = { params.tools && params.tools.split(',').contains('manta') }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/" },
            pattern: "*{diploid_sv,tumor_sv,somatic_sv}.{vcf.gz,vcf.gz.tbi}",
            saveAs: { meta.num_intervals > 1 ? null : "manta/${meta.id}/${it}" }
        ]
    }

    withName: 'MERGE_MANTA.*' {
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/manta/${meta.id}/" },
            pattern: "*{diploid_sv,tumor_sv,somatic_sv}.{vcf.gz,vcf.gz.tbi}"
        ]
    }

    withName: 'MERGE_MANTA_DIPLOID' {
        ext.prefix       = {"${meta.id}.manta.diploid_sv"}
    }

    withName: 'MERGE_MANTA_SMALL_INDELS' {
        ext.prefix       = {"${meta.id}.manta.candidate_small_indels"}
    }

    withName: 'MERGE_MANTA_SV' {
        ext.prefix       = {"${meta.id}.manta.candidate_sv"}
    }

    withName: 'MERGE_MANTA_TUMOR' {
        ext.prefix       = {"${meta.id}.manta.tumor_sv"}
    }

    withName: 'MERGE_MANTA_SOMATIC' {
        ext.prefix       = {"${meta.id}.manta.somatic_sv"}
    }
}
