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

    process {

        //
        // Statistics about the input sequences
        //

        withName: "CALCULATE_SEQSTATS" {
            publishDir = [
                path: { "${params.outdir}/summary/stats/sequences/seqstats" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml')|filename.contains('_summary.csv') ? null : filename }
            ]
        }

        withName: "CONCAT_SEQSTATS" {
            ext.prefix = { "summary_seqstats" }
        }

        withName: "EXTRACT_PLDDT"{
            publishDir = [
                path: { "${params.outdir}/summary/stats/structures/plddt" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml')|filename.contains('_summary.csv') ? null : filename }
            ]
        }

        withName: "CONCAT_PLDDT" {
            ext.prefix = { "summary_plddt" }
        }

        withName: TCOFFEE_SEQREFORMAT_SIM{
            ext.args = "-output=sim_idscore"
            publishDir = [
                path: { "${params.outdir}/summary/stats/sequences/perc_sim" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: "CONCAT_SIMSTATS" {
            ext.prefix = { "summary_simstats" }
        }

        withName: "MERGE_STATS"{
            ext.prefix = { "complete_summary_stats" }
            ext.args = "-f 1 -O"
            publishDir = [
                path: { "${params.outdir}/stats/" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        //
        // Tree building
        //

        withName: "FAMSA_GUIDETREE" {
            tag = {
                [
                    "${meta.id}",
                    meta.args_tree ? "args: ${meta.args_tree}" : ""
                ].join(' ').trim()
            }
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}" }
            ext.args = { "${meta.args_tree}" == "null" ? '' : "${meta.args_tree}" }
            publishDir = [
                path: { "${params.outdir}/trees/${meta.id}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: "CLUSTALO_GUIDETREE" {
            tag = {
                [
                    "${meta.id}",
                    meta.args_tree ? "args: ${meta.args_tree}" : ""
                ].join(' ').trim()
            }
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}" }
            ext.args   = { "${meta.args_tree}" == "null" ? '' : "${meta.args_tree}" }
            publishDir = [
                path: { "${params.outdir}/trees/${meta.id}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: "MAGUS_GUIDETREE" {
            tag = {
                [
                    "${meta.id}",
                    meta.args_tree ? "args: ${meta.args_tree}" : ""
                ].join(' ').trim()
            }
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}" }
            ext.args   = { "${meta.args_tree}" == "null" ? '' : "${meta.args_tree}" }
            publishDir = [
                path: { "${params.outdir}/trees/${meta.id}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        //
        // Alignment
        //

        withName: "CREATE_TCOFFEETEMPLATE" {
            ext.prefix = { "${meta.id}" }
        }
        withName: "CLUSTALO_ALIGN|FAMSA_ALIGN|FOLDMASON_EASYMSA|KALIGN_ALIGN|LEARNMSA_ALIGN|MAFFT|MAGUS_ALIGN|MUSCLE5_SUPER5|REGRESSIVE|TCOFFEE_ALIGN|TCOFFEE3D_ALIGN|UPP_ALIGN" {
            tag = {
                [
                    "${meta.id}",
                    meta.tree ? "tree: ${meta.tree}" : "",
                    meta.args_tree ? "argstree: ${meta.args_tree}" : "",
                    meta.args_aligner ? "args: ${meta.args_aligner}" : ""
                ].join(' ').trim()
            }
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}" }
            ext.args = { "${meta.args_aligner}" == "null" ? '' : "${meta.args_aligner}" }
            if(params.skip_compression){
                publishDir = [
                    path: { "${params.outdir}/alignment/${meta.id}" },
                    mode: params.publish_dir_mode,
                    saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
                ]
            }
        }

        withName: "MTMALIGN_ALIGN" {
            tag = {
                [
                    "${meta.id}",
                    meta.tree ? "tree: ${meta.tree}" : "",
                    meta.args_tree ? "argstree: ${meta.args_tree}" : "",
                    meta.args_aligner ? "args: ${meta.args_aligner}" : ""
                ].join(' ').trim()
            }
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}" }
            ext.args = { "${meta.args_aligner}" == "null" ? '' : "${meta.args_aligner}" }
            if(params.skip_compression){
                publishDir = [
                    path: { "${params.outdir}/alignment/${meta.id}" },
                    mode: params.publish_dir_mode,
                    saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                    pattern: "*.aln"
                ]
            }

        }

        withName: 'CONSENSUS'{
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}" }
            ext.args = { "-output fasta_aln" }
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        }

        withName:"PIGZ_COMPRESS"{
            publishDir = [
                path: { "${params.outdir}/alignment/${meta.id}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        //
        // Alignment evaluation
        //

        withName: 'PARSE_IRMSD' {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_irmsd" }
        }

        withName: 'TCOFFEE_ALNCOMPARE_SP' {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_sp" }
            ext.args = "-compare_mode sp"
        }

        withName: 'TCOFFEE_ALNCOMPARE_TC' {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_tc" }
            ext.args = "-compare_mode tc"
        }

        withName: 'TCOFFEE_IRMSD' {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_irmsd" }
            publishDir = [
                path: { "${params.outdir}/evaluation/${task.process.tokenize(':')[-1].toLowerCase()}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
            errorStrategy = 'retry'
        }

        withName: "CALC_GAPS" {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_gaps" }
        }

        withName: "CONCAT_IRMSD" {
            ext.prefix = { "summary_irmsd" }
        }

        withName: "CONCAT_GAPS" {
            ext.prefix = { "summary_gaps" }
        }

        withName: "CONCAT_SP" {
            ext.prefix = { "summary_sp" }
        }

        withName: "CONCAT_TC" {
            ext.prefix = { "summary_tc" }
        }

        withName: "CONCAT_TCS" {
            ext.prefix = { "summary_tcs" }
        }

        withName: 'TCOFFEE_TCS' {
            ext.prefix = { "${meta.id}_${meta.tree}-args-${meta.argstree_clean}_${meta.aligner}-args-${meta.args_aligner_clean}_tcs" }
            publishDir = [
                path: { "${params.outdir}/evaluation/${task.process.tokenize(':')[-1].toLowerCase()}" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: "MERGE_EVAL" {
            ext.prefix = { "complete_summary_eval" }
            ext.args = "-f 1,2,3,4,5,6,7 -O"
            publishDir = [
                path: { "${params.outdir}/evaluation/" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: "MERGE_STATS_EVAL" {
            ext.prefix = { "complete_summary_stats_eval" }
            ext.args = "-f 1 -O"
            publishDir = [
                path: { "${params.outdir}/summary/" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: 'MULTIQC' {
            ext.args   = { params.multiqc_title ? "--title \"$params.multiqc_title\"" : '' }
            publishDir = [
                path: { "${params.outdir}/multiqc" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        //
        // Shiny app
        //
        withName: 'PREPARE_SHINY' {
            publishDir = [
                path: { "${params.outdir}/shiny_app" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }
    }
