diff --git a/conf/modules.config b/conf/modules.config index 4f86f82ac..9d1152ac1 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -23,323 +23,3 @@ process { saveAs: { filename -> filename.equals('versions.yml') ? null : filename } ] } - -// -// General alignment options -// - -if (!params.skip_alignment) { - process { - withName: 'NFCORE_RNASEQ:RNASEQ:.*:BAM_SORT_STATS_SAMTOOLS:BAM_STATS_SAMTOOLS:.*' { - ext.prefix = { "${meta.id}.sorted.bam" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/samtools_stats" }, - mode: params.publish_dir_mode, - pattern: "*.{stats,flagstat,idxstats}" - ] - } - - withName: 'NFCORE_RNASEQ:RNASEQ:.*:BAM_SORT_STATS_SAMTOOLS:SAMTOOLS_SORT' { - ext.prefix = { "${meta.id}.sorted" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: "*.bam", - enabled: ( ['star_salmon','hisat2'].contains(params.aligner) && - ( params.save_align_intermeds || - ( !params.with_umi && params.skip_markduplicates ) - ) - ) || params.save_align_intermeds || params.skip_markduplicates - ] - } - - withName: 'NFCORE_RNASEQ:RNASEQ:.*:BAM_SORT_STATS_SAMTOOLS:SAMTOOLS_INDEX' { - ext.args = params.bam_csi_index ? '-c' : '' - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: "*.{bai,csi}", - enabled: ( ['star_salmon','hisat2'].contains(params.aligner) && - ( params.save_align_intermeds || - ( !params.with_umi && params.skip_markduplicates ) - ) - ) || params.save_align_intermeds || params.skip_markduplicates - ] - } - } - - if (!params.skip_markduplicates && !params.with_umi) { - process { - withName: '.*:BAM_MARKDUPLICATES_PICARD:BAM_STATS_SAMTOOLS:.*' { - ext.prefix = { "${meta.id}.markdup.sorted.bam" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/samtools_stats" }, - mode: params.publish_dir_mode, - pattern: '*.{stats,flagstat,idxstats}' - ] - } - } - } - - if (params.with_umi && ['star_salmon','hisat2'].contains(params.aligner)) { - process { - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME:UMITOOLS_DEDUP' { - ext.args = { [ - meta.single_end ? '' : '--unpaired-reads=discard --chimeric-pairs=discard', - params.umitools_grouping_method ? "--method='${params.umitools_grouping_method}'" : '', - params.umitools_umi_separator ? "--umi-separator='${params.umitools_umi_separator}'" : '' - ].join(' ').trim() } - ext.prefix = { "${meta.id}.umi_dedup.sorted" } - publishDir = [ - [ - path: { "${params.outdir}/${params.aligner}/umitools" }, - mode: params.publish_dir_mode, - pattern: '*.tsv' - ], - [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.bam', - enabled: ( - params.save_align_intermeds || - params.with_umi || - params.save_umi_intermeds - ) - ] - ] - } - - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME:SAMTOOLS_INDEX' { - ext.args = params.bam_csi_index ? '-c' : '' - ext.prefix = { "${meta.id}.umi_dedup.sorted" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.{bai,csi}', - enabled: ( - params.save_align_intermeds || - params.with_umi || - params.save_umi_intermeds - ) - ] - } - - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME:BAM_STATS_SAMTOOLS:.*' { - ext.prefix = { "${meta.id}.umi_dedup.sorted.bam" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/samtools_stats" }, - mode: params.publish_dir_mode, - pattern: '*.{stats,flagstat,idxstats}' - ] - } - } - } - - if (!params.skip_bigwig) { - process { - withName: '.*:BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_FORWARD:UCSC_BEDCLIP' { - ext.prefix = { "${meta.id}.clip.forward" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - enabled: false - ] - } - - withName: '.*:BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_FORWARD:UCSC_BEDGRAPHTOBIGWIG' { - ext.prefix = { "${meta.id}.forward" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/bigwig" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - - withName: '.*:BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_REVERSE:UCSC_BEDCLIP' { - ext.prefix = { "${meta.id}.clip.reverse" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - enabled: false - ] - } - - withName: '.*:BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_REVERSE:UCSC_BEDGRAPHTOBIGWIG' { - ext.prefix = { "${meta.id}.reverse" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/bigwig" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - } - } -} - -// -// STAR Salmon alignment options -// - -if (!params.skip_alignment && params.aligner == 'star_salmon') { - process { - withName: '.*:QUANTIFY_STAR_SALMON:SALMON_QUANT' { - ext.args = params.extra_salmon_quant_args ?: '' - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') || filename.endsWith('_meta_info.json') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_STAR_SALMON:SALMON_TX2GENE' { - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_STAR_SALMON:SALMON_TXIMPORT' { - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_STAR_SALMON:SALMON_SE_.*' { - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - } - - if (params.with_umi) { - process { - withName: 'NFCORE_RNASEQ:RNASEQ:BAM_SORT_STATS_SAMTOOLS:SAMTOOLS_SORT' { - ext.prefix = { "${meta.id}.transcriptome.sorted" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.bam', - enabled: ( - params.save_align_intermeds || - params.save_umi_intermeds - ) - ] - } - - withName: 'NFCORE_RNASEQ:RNASEQ:BAM_SORT_STATS_SAMTOOLS:SAMTOOLS_INDEX' { - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.bai', - enabled: ( - params.save_align_intermeds || - params.save_umi_intermeds - ) - ] - } - - withName: 'NFCORE_RNASEQ:RNASEQ:BAM_SORT_STATS_SAMTOOLS:BAM_STATS_SAMTOOLS:.*' { - ext.prefix = { "${meta.id}.transcriptome.sorted.bam" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/samtools_stats" }, - mode: params.publish_dir_mode, - pattern: '*.{stats,flagstat,idxstats}', - enabled: ( - params.save_align_intermeds || - params.save_umi_intermeds - ) - ] - } - - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_TRANSCRIPTOME:UMITOOLS_DEDUP' { - ext.args = { [ - meta.single_end ? '' : '--unpaired-reads=discard --chimeric-pairs=discard', - params.umitools_grouping_method ? "--method='${params.umitools_grouping_method}'" : '', - params.umitools_umi_separator ? "--umi-separator='${params.umitools_umi_separator}'" : '' - ].join(' ').trim() } - ext.prefix = { "${meta.id}.umi_dedup.transcriptome.sorted" } - publishDir = [ - [ - path: { "${params.outdir}/${params.aligner}/umitools" }, - mode: params.publish_dir_mode, - pattern: '*.tsv' - ], - [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.bam', - enabled: ( - params.save_align_intermeds || - params.save_umi_intermeds - ) - ] - ] - } - - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_TRANSCRIPTOME:SAMTOOLS_INDEX' { - publishDir = [ - path: { "${params.outdir}/${params.aligner}" }, - mode: params.publish_dir_mode, - pattern: '*.bai', - enabled: ( - params.save_align_intermeds || - params.save_umi_intermeds - ) - ] - } - - withName: '.*:BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_TRANSCRIPTOME:BAM_STATS_SAMTOOLS:.*' { - ext.prefix = { "${meta.id}.umi_dedup.transcriptome.sorted.bam" } - publishDir = [ - path: { "${params.outdir}/${params.aligner}/samtools_stats" }, - mode: params.publish_dir_mode, - pattern: '*.{stats,flagstat,idxstats}' - ] - } - } - } -} - -// -// Salmon pseudo-alignment options -// - -if (!params.skip_pseudo_alignment && params.pseudo_aligner == 'salmon') { - process { - withName: '.*:QUANTIFY_SALMON:SALMON_QUANT' { - ext.args = params.extra_salmon_quant_args ?: '' - publishDir = [ - path: { "${params.outdir}/${params.pseudo_aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') || filename.endsWith('_meta_info.json') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_SALMON:SALMON_TX2GENE' { - publishDir = [ - path: { "${params.outdir}/${params.pseudo_aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_SALMON:SALMON_TXIMPORT' { - publishDir = [ - path: { "${params.outdir}/${params.pseudo_aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - - withName: '.*:QUANTIFY_SALMON:SALMON_SE_.*' { - publishDir = [ - path: { "${params.outdir}/${params.pseudo_aligner}" }, - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - } - } -} diff --git a/subworkflows/local/align_star.nf b/subworkflows/local/align_star.nf index 25e44dfd7..f9fab4b4d 100644 --- a/subworkflows/local/align_star.nf +++ b/subworkflows/local/align_star.nf @@ -48,18 +48,18 @@ workflow ALIGN_STAR { ].flatten().unique(false).join(' ').trim() align_publish_dir = [ [ - path: { "${params.outdir}/${params.aligner}/log" }, + path: "${params.outdir}/${params.aligner}/log", mode: params.publish_dir_mode, pattern: '*.{out,tab}' ], [ - path: { "${params.outdir}/${params.aligner}" }, + path: "${params.outdir}/${params.aligner}", mode: params.publish_dir_mode, pattern: '*.bam', enabled: params.save_align_intermeds ], [ - path: { "${params.outdir}/${params.aligner}/unmapped" }, + path: "${params.outdir}/${params.aligner}/unmapped", mode: params.publish_dir_mode, pattern: '*.fastq.gz', enabled: params.save_unaligned @@ -96,7 +96,40 @@ workflow ALIGN_STAR { // // Sort, index BAM file and run samtools stats, flagstat and idxstats // - BAM_SORT_STATS_SAMTOOLS ( ch_orig_bam, fasta ) + sort_ext_prefix = { "${meta.id}.sorted" } + sort_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.bam", + enabled: ( !params.with_umi && params.skip_markduplicates ) || + params.save_align_intermeds || + params.skip_markduplicates + ] + index_ext_args = params.bam_csi_index ? '-c' : '' + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.{bai,csi}", + enabled: ( !params.with_umi && params.skip_markduplicates ) || + params.save_align_intermeds || + params.skip_markduplicates + ] + stats_ext_prefix = { "${meta.id}.sorted.bam" } + stats_publish_dir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: "*.{stats,flagstat,idxstats}" + ] + BAM_SORT_STATS_SAMTOOLS ( + ch_orig_bam, + fasta, + sort_ext_prefix, + sort_publish_dir, + index_ext_args, + index_publish_dir, + stats_ext_prefix, + stats_publish_dir + ) ch_versions = ch_versions.mix(BAM_SORT_STATS_SAMTOOLS.out.versions) emit: diff --git a/subworkflows/local/quantify_rsem.nf b/subworkflows/local/quantify_rsem.nf index 0dc0934b7..53a2fe8c6 100644 --- a/subworkflows/local/quantify_rsem.nf +++ b/subworkflows/local/quantify_rsem.nf @@ -50,7 +50,38 @@ workflow QUANTIFY_RSEM { // // Sort, index BAM file and run samtools stats, flagstat and idxstats // - BAM_SORT_STATS_SAMTOOLS ( RSEM_CALCULATEEXPRESSION.out.bam_star, fasta ) + sort_ext_prefix = { "${meta.id}.sorted" } + sort_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.bam", + enabled: params.save_align_intermeds || + params.skip_markduplicates + ] + index_ext_args = params.bam_csi_index ? '-c' : '' + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.{bai,csi}", + enabled: params.save_align_intermeds || + params.skip_markduplicates + ] + stats_ext_prefix = { "${meta.id}.sorted.bam" } + stats_publish_dir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: "*.{stats,flagstat,idxstats}" + ] + BAM_SORT_STATS_SAMTOOLS ( + RSEM_CALCULATEEXPRESSION.out.bam_star, + fasta, + sort_ext_prefix, + sort_publish_dir, + index_ext_args, + index_publish_dir, + stats_ext_prefix, + stats_publish_dir + ) ch_versions = ch_versions.mix(BAM_SORT_STATS_SAMTOOLS.out.versions) // diff --git a/subworkflows/local/quantify_salmon.nf b/subworkflows/local/quantify_salmon.nf index 4ab996b2c..f156b2b1b 100644 --- a/subworkflows/local/quantify_salmon.nf +++ b/subworkflows/local/quantify_salmon.nf @@ -19,23 +19,39 @@ workflow QUANTIFY_SALMON { gtf // channel: /path/to/genome.gtf alignment_mode // bool: Run Salmon in alignment mode lib_type // val: String to override salmon library type + publish_dir_path main: ch_versions = Channel.empty() + publish_dir = [ + path: publish_dir_path, + mode: params.publish_dir_mode, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename } + ] + // // Quantify and merge counts across samples // + SALMON_QUANT.config.ext.args = params.extra_salmon_quant_args ?: '' + SALMON_QUANT.config.publishDir = [ + path: publish_dir_path, + mode: params.publish_dir_mode, + saveAs: { filename -> filename.equals('versions.yml') || filename.endsWith('_meta_info.json') ? null : filename } + ] SALMON_QUANT ( reads, index, gtf, transcript_fasta, alignment_mode, lib_type ) ch_versions = ch_versions.mix(SALMON_QUANT.out.versions.first()) + SALMON_TX2GENE.config.publishDir = publish_dir SALMON_TX2GENE ( SALMON_QUANT.out.results.collect{it[1]}, gtf ) ch_versions = ch_versions.mix(SALMON_TX2GENE.out.versions) + SALMON_TXIMPORT.config.publishDir = publish_dir SALMON_TXIMPORT ( SALMON_QUANT.out.results.collect{it[1]}, SALMON_TX2GENE.out.tsv.collect() ) ch_versions = ch_versions.mix(SALMON_TXIMPORT.out.versions) + SALMON_SE_GENE.config.publishDir = publish_dir SALMON_SE_GENE ( SALMON_TXIMPORT.out.counts_gene, SALMON_TXIMPORT.out.tpm_gene, @@ -43,18 +59,21 @@ workflow QUANTIFY_SALMON { ) ch_versions = ch_versions.mix(SALMON_SE_GENE.out.versions) + SALMON_SE_GENE_LENGTH_SCALED.config.publishDir = publish_dir SALMON_SE_GENE_LENGTH_SCALED ( SALMON_TXIMPORT.out.counts_gene_length_scaled, SALMON_TXIMPORT.out.tpm_gene, SALMON_TX2GENE.out.tsv.collect() ) + SALMON_SE_GENE_SCALED.config.publishDir = publish_dir SALMON_SE_GENE_SCALED ( SALMON_TXIMPORT.out.counts_gene_scaled, SALMON_TXIMPORT.out.tpm_gene, SALMON_TX2GENE.out.tsv.collect() ) + SALMON_SE_TRANSCRIPT.config.publishDir = publish_dir SALMON_SE_TRANSCRIPT ( SALMON_TXIMPORT.out.counts_transcript, SALMON_TXIMPORT.out.tpm_transcript, diff --git a/subworkflows/nf-core/bam_dedup_stats_samtools_umitools/main.nf b/subworkflows/nf-core/bam_dedup_stats_samtools_umitools/main.nf index 7c07084ff..33e569046 100644 --- a/subworkflows/nf-core/bam_dedup_stats_samtools_umitools/main.nf +++ b/subworkflows/nf-core/bam_dedup_stats_samtools_umitools/main.nf @@ -10,6 +10,11 @@ workflow BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS { take: ch_bam_bai // channel: [ val(meta), path(bam), path(bai/csi) ] val_get_dedup_stats // boolean: true/false + dedup_ext_prefix + index_ext_args + index_ext_prefix + index_publish_dir + stats_ext_prefix main: @@ -18,12 +23,37 @@ workflow BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS { // // UMI-tools dedup // + UMITOOLS_DEDUP.config.ext.args = { [ + meta.single_end ? '' : '--unpaired-reads=discard --chimeric-pairs=discard', + params.umitools_grouping_method ? "--method='${params.umitools_grouping_method}'" : '', + params.umitools_umi_separator ? "--umi-separator='${params.umitools_umi_separator}'" : '' + ].join(' ').trim() } + UMITOOLS_DEDUP.config.ext.prefix = dedup_ext_prefix + UMITOOLS_DEDUP.config.publishDir = [ + [ + path: "${params.outdir}/${params.aligner}/umitools", + mode: params.publish_dir_mode, + pattern: '*.tsv' + ], + [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: '*.bam', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] + ] UMITOOLS_DEDUP ( ch_bam_bai, val_get_dedup_stats ) ch_versions = ch_versions.mix(UMITOOLS_DEDUP.out.versions.first()) // // Index BAM file and run samtools stats, flagstat and idxstats // + SAMTOOLS_INDEX.config.ext.args = index_ext_args + SAMTOOLS_INDEX.config.ext.prefix = index_ext_prefix + SAMTOOLS_INDEX.config.publishDir = index_publish_dir SAMTOOLS_INDEX ( UMITOOLS_DEDUP.out.bam ) ch_versions = ch_versions.mix(SAMTOOLS_INDEX.out.versions.first()) @@ -39,6 +69,12 @@ workflow BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS { } } + BAM_STATS_SAMTOOLS.config.ext.prefix = stats_ext_prefix + BAM_STATS_SAMTOOLS.config.publishDir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: '*.{stats,flagstat,idxstats}' + ] BAM_STATS_SAMTOOLS ( ch_bam_bai_dedup, [ [:], [] ] ) ch_versions = ch_versions.mix(BAM_STATS_SAMTOOLS.out.versions) diff --git a/subworkflows/nf-core/bam_markduplicates_picard/main.nf b/subworkflows/nf-core/bam_markduplicates_picard/main.nf index ee5960ed7..59255fe43 100644 --- a/subworkflows/nf-core/bam_markduplicates_picard/main.nf +++ b/subworkflows/nf-core/bam_markduplicates_picard/main.nf @@ -56,7 +56,18 @@ workflow BAM_MARKDUPLICATES_PICARD { } } - BAM_STATS_SAMTOOLS ( ch_bam_bai, ch_fasta ) + samtools_ext_prefix = { "${meta.id}.markdup.sorted.bam" } + samtools_publish_dir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: '*.{stats,flagstat,idxstats}' + ] + BAM_STATS_SAMTOOLS ( + ch_bam_bai, + ch_fasta, + samtools_ext_prefix, + samtools_publish_dir + ) ch_versions = ch_versions.mix(BAM_STATS_SAMTOOLS.out.versions) emit: diff --git a/subworkflows/nf-core/bam_sort_stats_samtools/main.nf b/subworkflows/nf-core/bam_sort_stats_samtools/main.nf index fc1c652b9..c8ac28bab 100644 --- a/subworkflows/nf-core/bam_sort_stats_samtools/main.nf +++ b/subworkflows/nf-core/bam_sort_stats_samtools/main.nf @@ -10,14 +10,24 @@ workflow BAM_SORT_STATS_SAMTOOLS { take: ch_bam // channel: [ val(meta), [ bam ] ] ch_fasta // channel: [ val(meta), path(fasta) ] + sort_ext_prefix + sort_publish_dir + index_ext_args + index_publish_dir + stats_ext_prefix + stats_publish_dir main: ch_versions = Channel.empty() + SAMTOOLS_SORT.config.ext.prefix = sort_ext_prefix + SAMTOOLS_SORT.config.publishDir = sort_publish_dir SAMTOOLS_SORT ( ch_bam ) ch_versions = ch_versions.mix(SAMTOOLS_SORT.out.versions.first()) + SAMTOOLS_INDEX.config.ext.args = index_ext_args + SAMTOOLS_INDEX.config.publishDir = index_publish_dir SAMTOOLS_INDEX ( SAMTOOLS_SORT.out.bam ) ch_versions = ch_versions.mix(SAMTOOLS_INDEX.out.versions.first()) @@ -34,7 +44,12 @@ workflow BAM_SORT_STATS_SAMTOOLS { } .set { ch_bam_bai } - BAM_STATS_SAMTOOLS ( ch_bam_bai, ch_fasta ) + BAM_STATS_SAMTOOLS ( + ch_bam_bai, + ch_fasta, + stats_ext_prefix, + stats_publish_dir + ) ch_versions = ch_versions.mix(BAM_STATS_SAMTOOLS.out.versions) emit: diff --git a/subworkflows/nf-core/bam_stats_samtools/main.nf b/subworkflows/nf-core/bam_stats_samtools/main.nf index 44d4c010a..c95c56432 100644 --- a/subworkflows/nf-core/bam_stats_samtools/main.nf +++ b/subworkflows/nf-core/bam_stats_samtools/main.nf @@ -10,16 +10,24 @@ workflow BAM_STATS_SAMTOOLS { take: ch_bam_bai // channel: [ val(meta), path(bam), path(bai) ] ch_fasta // channel: [ val(meta), path(fasta) ] + ext_prefix + publish_dir main: ch_versions = Channel.empty() + SAMTOOLS_STATS.config.ext.prefix = ext_prefix + SAMTOOLS_STATS.config.publishDir = publish_dir SAMTOOLS_STATS ( ch_bam_bai, ch_fasta ) ch_versions = ch_versions.mix(SAMTOOLS_STATS.out.versions) + SAMTOOLS_FLAGSTAT.config.ext.prefix = ext_prefix + SAMTOOLS_FLAGSTAT.config.publishDir = publish_dir SAMTOOLS_FLAGSTAT ( ch_bam_bai ) ch_versions = ch_versions.mix(SAMTOOLS_FLAGSTAT.out.versions) + SAMTOOLS_IDXSTATS.config.ext.prefix = ext_prefix + SAMTOOLS_IDXSTATS.config.publishDir = publish_dir SAMTOOLS_IDXSTATS ( ch_bam_bai ) ch_versions = ch_versions.mix(SAMTOOLS_IDXSTATS.out.versions) diff --git a/subworkflows/nf-core/bedgraph_bedclip_bedgraphtobigwig/main.nf b/subworkflows/nf-core/bedgraph_bedclip_bedgraphtobigwig/main.nf index 6c3b7b0cb..fc7b9e262 100644 --- a/subworkflows/nf-core/bedgraph_bedclip_bedgraphtobigwig/main.nf +++ b/subworkflows/nf-core/bedgraph_bedclip_bedgraphtobigwig/main.nf @@ -9,6 +9,8 @@ workflow BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG { take: bedgraph // channel: [ val(meta), [ bedgraph ] ] sizes // path: chrom.sizes + clip_ext_prefix + bigwig_ext_prefix main: @@ -17,12 +19,23 @@ workflow BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG { // // Clip bedGraph file // + UCSC_BEDCLIP.config.ext.prefix = clip_ext_prefix + UCSC_BEDCLIP.config.publishDir = [ + path: "${params.outdir}/${params.aligner}", + enabled: false + ] UCSC_BEDCLIP ( bedgraph, sizes ) ch_versions = ch_versions.mix(UCSC_BEDCLIP.out.versions.first()) // // Convert bedGraph to bigWig // + UCSC_BEDGRAPHTOBIGWIG.config.ext.prefix = bigwig_ext_prefix + UCSC_BEDGRAPHTOBIGWIG.config.publishDir = [ + path: "${params.outdir}/${params.aligner}/bigwig", + mode: params.publish_dir_mode, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename } + ] UCSC_BEDGRAPHTOBIGWIG ( UCSC_BEDCLIP.out.bedgraph, sizes ) ch_versions = ch_versions.mix(UCSC_BEDGRAPHTOBIGWIG.out.versions.first()) diff --git a/subworkflows/nf-core/fastq_align_hisat2/main.nf b/subworkflows/nf-core/fastq_align_hisat2/main.nf index 3be1dc0b3..fd4c8820c 100644 --- a/subworkflows/nf-core/fastq_align_hisat2/main.nf +++ b/subworkflows/nf-core/fastq_align_hisat2/main.nf @@ -43,7 +43,40 @@ workflow FASTQ_ALIGN_HISAT2 { // // Sort, index BAM file and run samtools stats, flagstat and idxstats // - BAM_SORT_STATS_SAMTOOLS ( HISAT2_ALIGN.out.bam, ch_fasta ) + sort_ext_prefix = { "${meta.id}.sorted" } + sort_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.bam", + enabled: ( !params.with_umi && params.skip_markduplicates ) || + params.save_align_intermeds || + params.skip_markduplicates + ] + index_ext_args = params.bam_csi_index ? '-c' : '' + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: "*.{bai,csi}", + enabled: ( !params.with_umi && params.skip_markduplicates ) || + params.save_align_intermeds || + params.skip_markduplicates + ] + stats_ext_prefix = { "${meta.id}.sorted.bam" } + stats_publish_dir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: "*.{stats,flagstat,idxstats}" + ] + BAM_SORT_STATS_SAMTOOLS ( + HISAT2_ALIGN.out.bam, + ch_fasta, + sort_ext_prefix, + sort_publish_dir, + index_ext_args, + index_publish_dir, + stats_ext_prefix, + stats_publish_dir + ) ch_versions = ch_versions.mix(BAM_SORT_STATS_SAMTOOLS.out.versions) diff --git a/workflows/rnaseq.nf b/workflows/rnaseq.nf index b9e26e094..48bbd641d 100755 --- a/workflows/rnaseq.nf +++ b/workflows/rnaseq.nf @@ -447,9 +447,27 @@ workflow RNASEQ { // if (params.with_umi) { // Deduplicate genome BAM file before downstream analysis + dedup_ext_prefix = { "${meta.id}.umi_dedup.sorted" } + index_ext_args = params.bam_csi_index ? '-c' : '' + index_ext_prefix = { "${meta.id}.umi_dedup.sorted" } + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: '*.{bai,csi}', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] + stats_ext_prefix = { "${meta.id}.umi_dedup.sorted.bam" } BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME ( ch_genome_bam.join(ch_genome_bam_index, by: [0]), - params.umitools_dedup_stats + params.umitools_dedup_stats, + dedup_ext_prefix, + index_ext_args, + index_ext_prefix, + index_publish_dir, + stats_ext_prefix ) ch_genome_bam = BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME.out.bam ch_genome_bam_index = BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME.out.bai @@ -462,17 +480,71 @@ workflow RNASEQ { ch_versions = ch_versions.mix(BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_GENOME.out.versions) // Co-ordinate sort, index and run stats on transcriptome BAM + sort_ext_prefix = { "${meta.id}.transcriptome.sorted" } + sort_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: '*.bam', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] + index_ext_args = '' + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: '*.bai', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] + stats_ext_prefix = { "${meta.id}.transcriptome.sorted.bam" } + stats_publish_dir = [ + path: "${params.outdir}/${params.aligner}/samtools_stats", + mode: params.publish_dir_mode, + pattern: '*.{stats,flagstat,idxstats}', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] BAM_SORT_STATS_SAMTOOLS ( ch_transcriptome_bam, - PREPARE_GENOME.out.fasta.map { [ [:], it ] } + PREPARE_GENOME.out.fasta.map { [ [:], it ] }, + sort_ext_prefix, + sort_publish_dir, + index_ext_args, + index_publish_dir, + stats_ext_prefix, + stats_publish_dir ) ch_transcriptome_sorted_bam = BAM_SORT_STATS_SAMTOOLS.out.bam ch_transcriptome_sorted_bai = BAM_SORT_STATS_SAMTOOLS.out.bai // Deduplicate transcriptome BAM file before read counting with Salmon + dedup_ext_prefix = { "${meta.id}.umi_dedup.transcriptome.sorted" } + index_ext_args = '' + index_ext_prefix = '' + index_publish_dir = [ + path: "${params.outdir}/${params.aligner}", + mode: params.publish_dir_mode, + pattern: '*.bai', + enabled: ( + params.save_align_intermeds || + params.save_umi_intermeds + ) + ] + stats_ext_prefix = { "${meta.id}.umi_dedup.transcriptome.sorted.bam" } BAM_DEDUP_STATS_SAMTOOLS_UMITOOLS_TRANSCRIPTOME ( ch_transcriptome_sorted_bam.join(ch_transcriptome_sorted_bai, by: [0]), - params.umitools_dedup_stats + params.umitools_dedup_stats, + dedup_ext_prefix, + index_ext_args, + index_ext_prefix, + index_publish_dir, + stats_ext_prefix ) // Name sort BAM before passing to Salmon @@ -543,7 +615,8 @@ workflow RNASEQ { PREPARE_GENOME.out.transcript_fasta, PREPARE_GENOME.out.gtf, true, - params.salmon_quant_libtype ?: '' + params.salmon_quant_libtype ?: '', + "${params.outdir}/${params.aligner}" ) ch_versions = ch_versions.mix(QUANTIFY_STAR_SALMON.out.versions) @@ -835,15 +908,23 @@ workflow RNASEQ { // // SUBWORKFLOW: Convert bedGraph to bigWig // + clip_ext_prefix = { "${meta.id}.clip.forward" } + bigwig_ext_prefix = { "${meta.id}.forward" } BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_FORWARD ( BEDTOOLS_GENOMECOV.out.bedgraph_forward, - PREPARE_GENOME.out.chrom_sizes + PREPARE_GENOME.out.chrom_sizes, + clip_ext_prefix, + bigwig_ext_prefix ) ch_versions = ch_versions.mix(BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_FORWARD.out.versions) + clip_ext_prefix = { "${meta.id}.clip.reverse" } + bigwig_ext_prefix = { "${meta.id}.reverse" } BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_REVERSE ( BEDTOOLS_GENOMECOV.out.bedgraph_reverse, - PREPARE_GENOME.out.chrom_sizes + PREPARE_GENOME.out.chrom_sizes, + clip_ext_prefix, + bigwig_ext_prefix ) } @@ -968,7 +1049,8 @@ workflow RNASEQ { ch_dummy_file, PREPARE_GENOME.out.gtf, false, - params.salmon_quant_libtype ?: '' + params.salmon_quant_libtype ?: '', + "${params.outdir}/${params.pseudo_aligner}" ) ch_salmon_multiqc = QUANTIFY_SALMON.out.results ch_versions = ch_versions.mix(QUANTIFY_SALMON.out.versions)