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

    publishDir = [
        path: { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" },
        mode: params.publish_dir_mode,
        saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
    ]

    withName: MULTIQC {
        ext.args = ''
    }

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

    withName: CUSTOM_DUMPSOFTWAREVERSIONS {
        publishDir = [
            path: { "${params.outdir}/pipeline_info" },
            mode: params.publish_dir_mode,
            pattern: '*_versions.yml'
        ]
    }

    withName: EPYTOPE_CHECK_REQUESTED_MODELS {
        publishDir = [
            path: { "${params.outdir}/reports" },
            mode: params.publish_dir_mode
        ]
        ext.args = "--tools ${params.tools} "
    }

    withName: EPYTOPE_CHECK_REQUESTED_MODELS_PEP {
        publishDir = [
            path: { "${params.outdir}/reports" },
            mode: params.publish_dir_mode
        ]
        ext.args = "--tools ${params.tools} --peptides "
    }

    withName: EPYTOPE_GENERATE_PEPTIDES {
        publishDir = [
            path: { "${params.outdir}/generated_peptides/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
        ext.args = ''
    }

    withName: SPLIT_PEPTIDES_PEPTIDES {
        ext.args = "--min_size ${params.peptides_split_minchunksize} --max_chunks ${params.peptides_split_maxchunks} "
    }

    withName: SPLIT_PEPTIDES_PROTEIN {
        ext.args = "--min_size ${params.peptides_split_minchunksize} --max_chunks ${params.peptides_split_maxchunks} "
    }

    withName: EPYTOPE_PEPTIDE_PREDICTION_PROTEIN {
        publishDir = [
            path: { "${params.outdir}/split_predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
        // Argument list needs to end with --peptides
        ext.args = "--reference ${params.genome_version} --peptides"
    }

    withName: EPYTOPE_PEPTIDE_PREDICTION_PEP {
        publishDir = [
            path: { "${params.outdir}/split_predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
        // Argument list needs to end with --peptides
        ext.args = "--reference ${params.genome_version} --peptides"
    }

    withName: EPYTOPE_PEPTIDE_PREDICTION_VAR {
        publishDir = [
            path: { "${params.outdir}/split_predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
        // Argument list needs to end with --somatic_mutation
        ext.args = "--reference ${params.genome_version} --somatic_mutation"
    }

    withName: MERGE_JSON_SINGLE {
        ext.args = " --single_input "
    }

    withName: MERGE_JSON_MULTI {
        ext.args = " --input \$PWD "
    }

    withName: CAT_TSV {
        publishDir = [
            path: { "${params.outdir}/predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: CAT_FASTA {
        publishDir = [
            path: { "${params.outdir}/predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: CSVTK_CONCAT {
        publishDir = [
            path: { "${params.outdir}/predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: CSVTK_SPLIT {
        publishDir = [
            path: { "${params.outdir}/split_input/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: GET_PREDICTION_VERSIONS {
        publishDir = [
            path: { "${params.outdir}/reports" },
            mode: params.publish_dir_mode
        ]
    }

    withName: GUNZIP_VCF {
        publishDir  = [
            enabled: false
        ]
    }

    withName: MERGE_JSON {
        publishDir = [
            path: { "${params.outdir}/predictions/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: EPYTOPE_SHOW_SUPPORTED_MODELS {
        publishDir = [
            path: { "${params.outdir}/supported_models" },
            mode: params.publish_dir_mode
        ]
    }

    withName: VARIANT_SPLIT {
        publishDir = [
            path: { "${params.outdir}/split_input/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: SNPSIFT_SPLIT {
        publishDir = [
            path: { "${params.outdir}/split_input/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }

    withName: SPLIT_PEPTIDES {
        publishDir = [
            path: { "${params.outdir}/split_input/${meta.sample}" },
            mode: params.publish_dir_mode
        ]
    }
}
