Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -158,28 +158,32 @@ 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' {
ext.prefix = { "${input.baseName}" }
}

withName: 'CHANGE_NAME' {
ext.prefix = { "${meta.fasta}.${meta.datatype}.${meta.id}" }
ext.prefix = { "${fasta.baseName}.${meta.datatype}.${meta.id}" }
}

withName: FASTQC {
Expand Down
3 changes: 2 additions & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions modules/local/change_name.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/nf-core/samtools/index/main.nf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions modules/nf-core/samtools/index/samtools-index.diff

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 22 additions & 30 deletions subworkflows/local/convert_stats.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
}


Expand All @@ -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
Expand All @@ -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() )


Expand Down