diff --git a/conf/modules.config b/conf/modules.config index 0db62c81..2e815e4f 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -131,7 +131,7 @@ process { withName: '.*:CONVERT_STATS:SAMTOOLS_CRAM' { beforeScript = { "export REF_PATH=spoof"} - ext.prefix = { "${fasta.baseName}.${meta.datatype}.${meta.id}" } + ext.prefix = { "${input.baseName}" } ext.args = '--output-fmt cram --write-index' } @@ -158,20 +158,24 @@ process { ext.args = { (meta.datatype == "pacbio" ? "-y pbccs " : "") + "-O bam" } } - withName: '.*:CONVERT_STATS:SAMTOOLS_.*|BGZIP_BEDGRAPH|CHANGE_NAME' { + withName: '.*:CONVERT_STATS:SAMTOOLS_.*|BGZIP_BEDGRAPH' { beforeScript = { "export REF_PATH=spoof" } publishDir = [ path: { "${params.outdir}/read_mapping/${meta.datatype}${meta.merged ? '/merged' : ''}" }, mode: params.publish_dir_mode, - // Only publish BAM/CRAM from SAMTOOLS_REHEADER if params.header is true, else from: CHANGE_NAME and SAMTOOLS_CRAM + // Only publish BAM/CRAM from SAMTOOLS_REHEADER if params.header is true, else from: SAMTOOLS_INDEX (BAM) and SAMTOOLS_CRAM (CRAM) saveAs: { filename -> - filename == 'versions.yml' || ((task.process =~ /CHANGE_NAME|SAMTOOLS_CRAM/) && params.header) ? null : filename + filename == 'versions.yml' + || ((task.process == 'CHANGE_NAME') || (task.process == 'SAMTOOLS_CRAM' && !file.name.endsWith('.cram')) + && params.header) + || ((task.process =~ /SAMTOOLS_CRAM/) && filename.endsWith(".bam")) + ? null : filename } ] } withName: 'BLOBTK_DEPTH' { - ext.prefix = { "${meta.fasta}.${meta.datatype}.${meta.id}" } + ext.prefix = { "${bam.baseName}" } } withName: 'BGZIP_BEDGRAPH' { @@ -179,7 +183,7 @@ process { } withName: 'CHANGE_NAME' { - ext.prefix = { "${meta.fasta}.${meta.datatype}.${meta.id}" } + ext.prefix = { "${fasta.baseName}.${meta.datatype}.${meta.id}" } } withName: FASTQC { diff --git a/modules.json b/modules.json index 32d0ca5c..ec2d606a 100644 --- a/modules.json +++ b/modules.json @@ -58,7 +58,8 @@ "samtools/index": { "branch": "master", "git_sha": "46eca555142d6e597729fcb682adcc791796f514", - "installed_by": ["modules"] + "installed_by": ["modules"], + "patch": "modules/nf-core/samtools/index/samtools-index.diff" }, "samtools/merge": { "branch": "master", diff --git a/modules/local/change_name.nf b/modules/local/change_name.nf index a6aba96b..f2b6b1ca 100644 --- a/modules/local/change_name.nf +++ b/modules/local/change_name.nf @@ -4,6 +4,7 @@ process CHANGE_NAME { input: tuple val(meta), path(file) + tuple val(meta2), path(fasta) output: tuple val(meta), path("*.${file.extension}"), emit: file diff --git a/modules/nf-core/samtools/index/main.nf b/modules/nf-core/samtools/index/main.nf index e002585b..2f4c52f3 100644 --- a/modules/nf-core/samtools/index/main.nf +++ b/modules/nf-core/samtools/index/main.nf @@ -11,6 +11,7 @@ process SAMTOOLS_INDEX { tuple val(meta), path(input) output: + tuple val(meta), path("${input}"), emit: input tuple val(meta), path("*.bai") , optional:true, emit: bai tuple val(meta), path("*.csi") , optional:true, emit: csi tuple val(meta), path("*.crai"), optional:true, emit: crai diff --git a/modules/nf-core/samtools/index/samtools-index.diff b/modules/nf-core/samtools/index/samtools-index.diff new file mode 100644 index 00000000..c086fede --- /dev/null +++ b/modules/nf-core/samtools/index/samtools-index.diff @@ -0,0 +1,20 @@ +Changes in component 'nf-core/samtools/index' +'modules/nf-core/samtools/index/meta.yml' is unchanged +Changes in 'samtools/index/main.nf': +--- modules/nf-core/samtools/index/main.nf ++++ modules/nf-core/samtools/index/main.nf +@@ -11,6 +11,7 @@ + tuple val(meta), path(input) + + output: ++ tuple val(meta), path("${input}"), emit: input + tuple val(meta), path("*.bai") , optional:true, emit: bai + tuple val(meta), path("*.csi") , optional:true, emit: csi + tuple val(meta), path("*.crai"), optional:true, emit: crai + +'modules/nf-core/samtools/index/environment.yml' is unchanged +'modules/nf-core/samtools/index/tests/csi.nextflow.config' is unchanged +'modules/nf-core/samtools/index/tests/main.nf.test' is unchanged +'modules/nf-core/samtools/index/tests/tags.yml' is unchanged +'modules/nf-core/samtools/index/tests/main.nf.test.snap' is unchanged +************************************************************ diff --git a/subworkflows/local/convert_stats.nf b/subworkflows/local/convert_stats.nf index cc32345d..b78d754f 100644 --- a/subworkflows/local/convert_stats.nf +++ b/subworkflows/local/convert_stats.nf @@ -32,12 +32,6 @@ workflow CONVERT_STATS { // Split outfmt parameter into a list def outfmt_options = params.outfmt.split(',').collect { it.trim() } - // Reserve fasta base name for prefix of CHANGE_NAME and BLOBTK_DEPTH - bam - .combine( fasta ) - .map{ meta, bam, meta1, fasta -> [ meta +[fasta:fasta.baseName], bam]} - .set { bam } - // (Optionally) Compress the quality scores of Illumina and PacBio CCS alignments if ( params.compression == "crumble" ) { bam @@ -53,30 +47,33 @@ workflow CONVERT_STATS { CRUMBLE.out.bam | mix( crumble_selector.no_crumble ) - | map { meta, bam -> [meta, bam, []] } - | set { ch_bams_for_conversion } + | set { ch_bams_for_renaming } } else { - bam - | map { meta, bam -> [meta, bam, []] } - | set { ch_bams_for_conversion } + ch_bams_for_renaming = bam } + // Change name of BAM files to final name for publishing + CHANGE_NAME ( ch_bams_for_renaming, fasta ) + + CHANGE_NAME.out.file + | map { meta, bam -> [meta, bam, []] } + | set { ch_renamed_bams } + + // (Optionally) convert to CRAM if it's specified in outfmt ch_cram = Channel.empty() ch_crai = Channel.empty() if ("cram" in outfmt_options) { - SAMTOOLS_CRAM ( ch_bams_for_conversion, fasta, [] ) + SAMTOOLS_CRAM ( ch_renamed_bams, fasta, [] ) ch_versions = ch_versions.mix( SAMTOOLS_CRAM.out.versions.first() ) // Combine CRAM and CRAI into one channel ch_cram = SAMTOOLS_CRAM.out.cram ch_crai = SAMTOOLS_CRAM.out.crai - ch_data_for_stats = ch_cram.join( ch_crai ) - } else { - ch_data_for_stats = ch_bams_for_conversion + ch_for_stats = ch_cram.join( ch_crai ) } @@ -85,23 +82,21 @@ workflow CONVERT_STATS { ch_bai = Channel.empty() if ("bam" in outfmt_options) { - ch_bams_to_index = ch_bams_for_conversion.map{ it -> [it[0], it[1]]} - // Change name of BAM files to final name for publishing - ch_bam = CHANGE_NAME ( ch_bams_to_index ).file - // Reindex BAM - SAMTOOLS_INDEX ( ch_bam ) + SAMTOOLS_INDEX ( CHANGE_NAME.out.file ) ch_versions = ch_versions.mix( SAMTOOLS_INDEX.out.versions.first() ) // Set the BAM and BAI channels for emission + ch_bam = CHANGE_NAME.out.file ch_bai = SAMTOOLS_INDEX.out.bai.mix(SAMTOOLS_INDEX.out.csi) - // If using BAM for stats, use the reindexed BAM - if ( !("cram" in outfmt_options) ) { - ch_data_for_stats = ch_bam.join ( SAMTOOLS_INDEX.out.bai ) + if ( !('cram' in outfmt_options) ) { + ch_for_stats = ch_bam.join( ch_bai ) } + } + // Optionally insert params.header information to bams if ( params.header ) { ch_bam = SAMTOOLS_REHEADER_BAM ( ch_bam, header.first() ).bam @@ -112,25 +107,22 @@ workflow CONVERT_STATS { // Calculate read depth - BLOBTK_DEPTH ( ch_bams_for_conversion ) + BLOBTK_DEPTH ( ch_renamed_bams ) ch_versions = ch_versions.mix( BLOBTK_DEPTH.out.versions.first() ) BGZIP_BEDGRAPH ( BLOBTK_DEPTH.out.bedgraph ) ch_versions = ch_versions.mix( BGZIP_BEDGRAPH.out.versions.first() ) - // Calculate statistics - SAMTOOLS_STATS ( ch_data_for_stats, fasta ) + SAMTOOLS_STATS (ch_for_stats, [[], []] ) ch_versions = ch_versions.mix( SAMTOOLS_STATS.out.versions.first() ) - // Calculate statistics based on flag values - SAMTOOLS_FLAGSTAT ( ch_data_for_stats ) + SAMTOOLS_FLAGSTAT ( ch_for_stats ) ch_versions = ch_versions.mix( SAMTOOLS_FLAGSTAT.out.versions.first() ) - // Calculate index statistics - SAMTOOLS_IDXSTATS ( ch_data_for_stats ) + SAMTOOLS_IDXSTATS ( ch_for_stats ) ch_versions = ch_versions.mix( SAMTOOLS_IDXSTATS.out.versions.first() )