/*
========================================================================================
    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: 'copy',
        saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
    ]

    withName: MULTIQC {
        ext.args = ''
    }

    withName: SAMPLESHEET_CHECK {
        publishDir = [
            path: { "${params.outdir}/pipeline_info" },
            mode: 'copy',
        ]
    }

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

    withName: CHECK_REQUESTED_MODELS {
        publishDir = [
            path: { "${params.outdir}/reports" },
        ]
        ext.args = "--tools ${params.tools} --max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} "
    }

    withName: CHECK_REQUESTED_MODELS_PEP {
        publishDir = [
            path: { "${params.outdir}/reports" },
        ]
        ext.args = "--tools ${params.tools} --max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} --peptides "
    }

    withName: FRED2_GENERATEPEPTIDES {
        ext.args = "--max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} "
    }

    withName: SPLIT_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: PEPTIDE_PREDICTION_PROTEIN {
        publishDir = [
            path: { "${params.outdir}/predictions" },
        ]
        // Argument list needs to end with --peptides
        ext.args = "--tools ${params.tools} --mhcclass ${params.mhc_class} --max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} --reference ${params.genome_version} --peptides"
    }

    withName: PEPTIDE_PREDICTION_PEP {
        publishDir = [
            path: { "${params.outdir}/predictions" },
        ]
        // Argument list needs to end with --peptides
        ext.args = "--tools ${params.tools} --mhcclass ${params.mhc_class} --max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} --reference ${params.genome_version} --peptides"
    }

    withName: PEPTIDE_PREDICTION_VAR {
        publishDir = [
            path: { "${params.outdir}/predictions" },
        ]
        // Argument list needs to end with --somatic_mutation
        ext.args = "--tools ${params.tools} --mhcclass ${params.mhc_class} --max_length ${params.max_peptide_length} --min_length ${params.min_peptide_length} --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}/merged_predictions" },
        ]
    }

    withName: CAT_FASTA {
        publishDir = [
            path: { "${params.outdir}/merged_predictions" },
        ]
    }

    withName: CSVTK_CONCAT {
        publishDir = [
            path: { "${params.outdir}/merged_predictions" },
        ]
    }

    withName: CSVTK_SPLIT {
        publishDir = [
            path: { "${params.outdir}/splitted" },
        ]
    }

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

    withName: MERGE_JSON {
        publishDir = [
            path: { "${params.outdir}/merged_predictions" },
        ]
    }

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

    withName: SNPSIFT_SPLIT {
        publishDir = [
            path: { "${params.outdir}/splitted" },
        ]
    }

    withName: SPLIT_PEPTIDES {
        publishDir = [
            path: { "${params.outdir}/splitted" },
        ]
    }
}
