/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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: 'SEQFU_STATS_BEFORE' {
        ext.prefix = { "${meta.id}_before" }
        publishDir = [
            path: { "${params.outdir}/qc/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

    withName: '.*:FAA_SEQFU_SEQKIT:SEQKIT_SEQ' {
        ext.args = [
            "--remove-gaps",
            "--upper-case",
            "--validate-seq",
            "--min-len ${params.min_seq_length}",
            "--max-len ${params.max_seq_length}"
        ].join(' ').trim()
        ext.prefix = "intermediate_seqkit_seq"
        publishDir = [
            path: { "${params.outdir}/qc/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'SEQKIT_REPLACE' {
        ext.args   = '-p "/" -r "_"'
        ext.suffix = "fasta"
        ext.prefix = "intermediate_seqkit_replace"
        publishDir = [
            path: { "${params.outdir}/qc/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'SEQKIT_RMDUP' {
        ext.args   = { params.remove_duplicates_on_sequence ? "--by-seq" : '' }
        publishDir = [
            path: { "${params.outdir}/qc/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

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

    withName: 'CAT_HMM' {
        publishDir = [
            path: { "${params.outdir}/update_families/hmmer/concatenated" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'CAT_FASTA' {
        ext.prefix = { "${meta.id}_${meta.family}" }
        tag = { "${meta.id}_${meta.family}" }
        publishDir = [
            path: { "${params.outdir}/update_families/fasta" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

    withName: '.*:REMOVE_REDUNDANCY:FIND_CONCATENATE_HMMS' {
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/hmmer/concatenated" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:FIND_CONCATENATE_SKIP_IDS' {
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/skipped_ids" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:SEQKIT_SEQ' {
        ext.args = "--remove-gaps"
        ext.prefix = { "${meta.id}_${meta.family}" }
        tag = { "${meta.id}_${meta.family}" }
        publishDir = [
            path: { "${params.outdir}/seqkit/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'MMSEQS_CREATEDB' {
        publishDir = [
            path: { "${params.outdir}/mmseqs/initial_clustering/mmseqs_createdb/" },
            mode: params.publish_dir_mode,
            enabled: params.save_mmseqs_db,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:MMSEQS_FASTA_CLUSTER:MMSEQS_CREATEDB' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/mmseqs/update_families/mmseqs_createdb/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:MMSEQS_FASTA_CLUSTER:MMSEQS_CREATEDB' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/mmseqs/redundancy_clustering/mmseqs_createdb/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'MMSEQS_CLUSTER' {
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity}",
            "-c ${params.cluster_coverage}",
            "--cov-mode ${params.cluster_cov_mode}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/initial_clustering/mmseqs_cluster/" },
            mode: params.publish_dir_mode,
            enabled: params.save_mmseqs_clustering,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES_CLUSTERING:MMSEQS_FASTA_CLUSTER:MMSEQS_CLUSTER' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity_for_redundancy}",
            "-c ${params.cluster_coverage_for_redundancy}",
            "--cov-mode ${params.cluster_cov_mode_for_redundancy}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/update_families/mmseqs_cluster/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:MMSEQS_FASTA_CLUSTER:MMSEQS_CLUSTER' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity_for_redundancy}",
            "-c ${params.cluster_coverage_for_redundancy}",
            "--cov-mode ${params.cluster_cov_mode_for_redundancy}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/redundancy_clustering/mmseqs_cluster/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'MMSEQS_LINCLUST' {
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity}",
            "-c ${params.cluster_coverage}",
            "--cov-mode ${params.cluster_cov_mode}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/initial_clustering/mmseqs_linclust/" },
            mode: params.publish_dir_mode,
            enabled: params.save_mmseqs_clustering,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:MMSEQS_FASTA_CLUSTER:MMSEQS_LINCLUST' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity_for_redundancy}",
            "-c ${params.cluster_coverage_for_redundancy}",
            "--cov-mode ${params.cluster_cov_mode_for_redundancy}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/update_families/mmseqs_linclust/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:MMSEQS_FASTA_CLUSTER:MMSEQS_LINCLUST' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        ext.args = [
            "--min-seq-id ${params.cluster_seq_identity_for_redundancy}",
            "-c ${params.cluster_coverage_for_redundancy}",
            "--cov-mode ${params.cluster_cov_mode_for_redundancy}",
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/mmseqs/redundancy_clustering/mmseqs_linclust/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

    withName: '.*:UPDATE_FAMILIES:MMSEQS_FASTA_CLUSTER:MMSEQS_CREATETSV' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/mmseqs/update_families/mmseqs_createtsv/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:MMSEQS_FASTA_CLUSTER:MMSEQS_CREATETSV' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/mmseqs/redundancy_clustering/mmseqs_createtsv/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

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

    withName: 'FAMSA_ALIGN' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/seed_msa/raw/famsa_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:ALIGN_SEQUENCES:FAMSA_ALIGN' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/seed_msa/raw/famsa_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:ALIGN_SEQUENCES:FAMSA_ALIGN' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/full_msa/famsa_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:ALIGN_SEQUENCES:FAMSA_ALIGN' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/full_msa/filtered/famsa_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'MAFFT_ALIGN' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/seed_msa/raw/mafft_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:ALIGN_SEQUENCES:MAFFT_ALIGN' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/seed_msa/raw/mafft_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:ALIGN_SEQUENCES:MAFFT_ALIGN' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/full_msa/mafft_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:ALIGN_SEQUENCES:MAFFT_ALIGN' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/full_msa/filtered/mafft_align/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'CLIPKIT' {
        ext.args = [
            "-m gappy --gaps ${params.gap_threshold}",
            params.trim_ends_only ? "--ends_only" : ''
        ].join(' ').trim()
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/seed_msa/raw/clipkit/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.${params.clipkit_out_format}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:CLIPKIT' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        ext.args = [
            "-m gappy --gaps ${params.gap_threshold}",
            params.trim_ends_only ? "--ends_only" : ''
        ].join(' ').trim()
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/seed_msa/raw/clipkit/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.${params.clipkit_out_format}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:CLIPKIT' {
        ext.args = [
            "-m gappy --gaps ${params.gap_threshold}",
            params.trim_ends_only ? "--ends_only" : ''
        ].join(' ').trim()
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/full_msa/clipkit/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.${params.clipkit_out_format}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'HMMER_HMMBUILD' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/hmm/raw/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{hmm.gz}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:HMMER_HMMBUILD' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/hmm/raw/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{hmm.gz}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:HMMER_HMMBUILD' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/hmm/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{hmm.gz}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'HMMER_HMMSEARCH' {
        ext.args   = { "-E ${params.hmmsearch_evalue_cutoff}" }
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/hmmer/hmmsearch/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.domtbl.gz",
            enabled: params.save_hmmsearch_results,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:HMMER_HMMSEARCH' {
        ext.args   = { "-E ${params.hmmsearch_evalue_cutoff}" }
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/hmmer/hmmsearch/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{domtbl.gz}",
            enabled: params.save_hmmsearch_results,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:HMMER_HMMSEARCH' {
        ext.args   = { "-E ${params.hmmsearch_evalue_cutoff}" }
        ext.prefix = { "${meta.id}" }
        tag = { "${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/hmmer/hmmsearch/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{domtbl.gz}",
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:REMOVE_REDUNDANCY:HMMER_HMMSEARCH' {
        ext.args   = { "-E ${params.hmmsearch_evalue_cutoff}" }
        ext.prefix = { "${meta.id}" }
        tag = { "${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/hmmer/hmmsearch/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.{domtbl.gz}",
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'FILTER_RECRUITED' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/fasta/hmmsearch_filtered_recruited/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: params.save_hmmsearch_filtered_fasta,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:FILTER_RECRUITED' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/fasta/hmmsearch_filtered_recruited/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: params.save_hmmsearch_filtered_fasta,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'HMMER_HMMALIGN' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/full_msa/raw/hmmer_hmmalign/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.sto.gz",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:MERGE_FAMILIES:GENERATE_FAMILIES:HMMER_HMMALIGN' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/full_msa/raw/hmmer_hmmalign/${meta.id}/" },
            mode: params.publish_dir_mode,
            pattern: "*.sto.gz",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

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

    withName: 'MERGE_SEEDS' {
        ext.prefix = { "${meta.merged_id}" }
        tag = { "${meta.merged_id}" }
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/merge_families/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

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

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

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

    withName: 'REMOVE_REDUNDANT_SEQS' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/fasta/non_redundant_sequences_filtered/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: params.save_non_redundant_seqs_fasta,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'HHSUITE_REFORMAT_FILTERED' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/full_msa/filtered/hhsuite_reformat/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'HHSUITE_REFORMAT_RAW' {
        ext.prefix = { "${meta.id}_${meta.chunk}" }
        tag = { "${meta.id}_${meta.chunk}" }
        publishDir = [
            path: { "${params.outdir}/full_msa/raw/hhsuite_reformat/${meta.id}/" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*:UPDATE_FAMILIES:REMOVE_REDUNDANT_SEQS' {
        ext.prefix = { "${meta.family}" }
        tag = { "${meta.family}_${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/update_families/non_redundant_sequences/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: false,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

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

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

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

    withName: '.*:REMOVE_REDUNDANCY:EXTRACT_FAMILY_REPS' {
        publishDir = [
            path: { "${params.outdir}/remove_redundancy/family_reps/${meta.id}/" },
            mode: params.publish_dir_mode,
            enabled: false,
            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 }
        ]
    }

}
