process {
	publishDir = [
	    path: { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" },
	    mode: params.publish_dir_mode,
	    enabled: false
	]

	withName: CALCULATE_STATISTICS {
		publishDir = [
			path: {"${params.outdir}/01.statistics"},
			mode: params.publish_dir_mode
		]
	}

	withName: EXTRACT_INTRON_STATS {
		publishDir = [
			path: {"${params.outdir}/01.statistics"},
			mode: params.publish_dir_mode
		]
	}

	withName: PLOT_INTRON_PHASE {
		publishDir = [
			path: {"${params.outdir}/01.statistics"},
			mode: params.publish_dir_mode
		]
	}

	withName: EXTRACT_PROTEOME {
		publishDir = [
			path: {"${params.outdir}/02.protein"},
			mode: params.publish_dir_mode
		]
	}

	withName: BUSCO {
	    publishDir = [
	        path: {"${params.outdir}/01.statistics/01.busco"},
	        mode: params.publish_dir_mode
	    ]
	}

	withName: OMAMER {
		publishDir = [
			path: {"${params.outdir}/01.statistics/02.omark"},
			mode: params.publish_dir_mode
		]
	}

	withName: OMARK {
		publishDir = [
			path: {"${params.outdir}/01.statistics/02.omark"},
			mode: params.publish_dir_mode
		]
	}

	withName: PLOT_OMARK {
		publishDir = [
			path: {"${params.outdir}/01.statistics/02.omark"},
			mode: params.publish_dir_mode
		]
	}

	withName: PSAURON {
		publishDir = [
			path: {"${params.outdir}/01.statistics/03.psauron"},
			mode: params.publish_dir_mode
		]
	}

	withName: PLOT_PSAURON {
		publishDir = [
			path: {"${params.outdir}/01.statistics/03.psauron"},
			mode: params.publish_dir_mode
		]
	}

	withName: QUERY_NCBI_PROT {
		publishDir = [
			path: {"${params.outdir}/02.protein"},
			mode: params.publish_dir_mode
		]
	}

	withName: BLASTP {
		publishDir = [
			path: {"${params.outdir}/02.protein/01.blast"},
			mode: params.publish_dir_mode
		]
	}

	withName: DIAMOND_BLASTP {
		publishDir = [
			path: {"${params.outdir}/02.protein/01.diamond"},
			mode: params.publish_dir_mode
		]
	}

	withName: FIND_ORTHOLOG {
		publishDir = [
			path: {"${params.outdir}/02.protein/02.ortholog"},
			mode: params.publish_dir_mode
		]
	}

	withName: COMPARE_DISTRIBUTION {
		publishDir = [
			path: {"${params.outdir}/02.protein"},
			mode: params.publish_dir_mode
		]
	}

	withName: PLOT_DISTRIBUTION {
		publishDir = [
			path: {"${params.outdir}/02.protein"},
			mode: params.publish_dir_mode
		]
	}

	withName: MERGEBAM {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/02.bam"},
			mode: params.publish_dir_mode
		]
	}

	withName: FLAGSTAT {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq"},
			mode: params.publish_dir_mode
		]
	}

	withName: CUSTOM_GFF2GTF {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq"},
			mode: params.publish_dir_mode
		]
	}

	withName: FEATURECOUNTS {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq"},
			mode: params.publish_dir_mode
		]
	}

	withName: JUNCTION_EXTRACT {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/intron_stats"},
			mode: params.publish_dir_mode
		]
	}

	withName: EXTRACT_INTRON_BED {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/intron_stats"},
			mode: params.publish_dir_mode
		]
	}

	withName: BEDTOOLS_INTERSECT {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/intron_stats"},
			mode: params.publish_dir_mode
		]
	}

	withName: BEDTOOLS_GETFASTA {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/intron_stats"},
			mode: params.publish_dir_mode
		]
	}

	withName: CALCULATE_CANONICAL {
		publishDir = [
			path: {"${params.outdir}/03.rnaseq/intron_stats"},
			mode: params.publish_dir_mode
		]
	}

	withName: COMBINE_REPORT {
		publishDir = [
			path: {"${params.outdir}/04.evaluation_output"}, 
			mode: params.publish_dir_mode
		]
	}

	withName: GENERATE_PDF {
		publishDir = [
			path: {"${params.outdir}/04.evaluation_output"},  
			mode: params.publish_dir_mode
		]
	}

}