Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve workflow logic for fastq_align_dedup_bismark #7005

Merged
merged 8 commits into from
Nov 18, 2024
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
127 changes: 64 additions & 63 deletions subworkflows/nf-core/fastq_align_dedup_bismark/main.nf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include { BISMARK_ALIGN } from '../../../modules/nf-core/bismark/align/main'
include { BISMARK_DEDUPLICATE } from '../../../modules/nf-core/bismark/deduplicate/main'
include { BISMARK_METHYLATIONEXTRACTOR } from '../../../modules/nf-core/bismark/methylationextractor/main'
include { BISMARK_COVERAGE2CYTOSINE } from '../../../modules/nf-core/bismark/coverage2cytosine/main'
include { BISMARK_REPORT } from '../../../modules/nf-core/bismark/report/main'
include { BISMARK_SUMMARY } from '../../../modules/nf-core/bismark/summary/main'
include { SAMTOOLS_SORT as SAMTOOLS_SORT_DEDUPLICATED } from '../../../modules/nf-core/samtools/sort/main'
include { SAMTOOLS_INDEX as SAMTOOLS_INDEX_DEDUPLICATED } from '../../../modules/nf-core/samtools/index/main'
include { BISMARK_ALIGN } from '../../../modules/nf-core/bismark/align/main'
include { BISMARK_DEDUPLICATE } from '../../../modules/nf-core/bismark/deduplicate/main'
include { SAMTOOLS_SORT } from '../../../modules/nf-core/samtools/sort/main'
include { SAMTOOLS_INDEX } from '../../../modules/nf-core/samtools/index/main'
include { BISMARK_METHYLATIONEXTRACTOR } from '../../../modules/nf-core/bismark/methylationextractor/main'
include { BISMARK_COVERAGE2CYTOSINE } from '../../../modules/nf-core/bismark/coverage2cytosine/main'
include { BISMARK_REPORT } from '../../../modules/nf-core/bismark/report/main'
include { BISMARK_SUMMARY } from '../../../modules/nf-core/bismark/summary/main'

workflow FASTQ_ALIGN_DEDUP_BISMARK {

Expand All @@ -17,18 +17,20 @@ workflow FASTQ_ALIGN_DEDUP_BISMARK {
cytosine_report // boolean: whether the run coverage2cytosine

main:
ch_versions = Channel.empty()
ch_coverage2cytosine_coverage = Channel.empty()
ch_coverage2cytosine_report = Channel.empty()
ch_coverage2cytosine_summary = Channel.empty()
ch_alignments = Channel.empty()
ch_alignment_reports = Channel.empty()
ch_methylation_bedgraph = Channel.empty()
ch_methylation_calls = Channel.empty()
ch_methylation_coverage = Channel.empty()
ch_methylation_report = Channel.empty()
ch_methylation_mbias = Channel.empty()
ch_coverage2cytosine_coverage = Channel.empty()
ch_coverage2cytosine_report = Channel.empty()
ch_coverage2cytosine_summary = Channel.empty()
ch_bismark_report = Channel.empty()
ch_bismark_summary = Channel.empty()
ch_multiqc_files = Channel.empty()
ch_versions = Channel.empty()

/*
* Align with bismark
Expand All @@ -38,28 +40,44 @@ workflow FASTQ_ALIGN_DEDUP_BISMARK {
ch_fasta,
ch_bismark_index
)
ch_alignments = BISMARK_ALIGN.out.bam
ch_alignment_reports = BISMARK_ALIGN.out.report.map{ meta, report -> [ meta, report, [] ] }
ch_versions = ch_versions.mix(BISMARK_ALIGN.out.versions)

if (skip_deduplication) {
alignments = BISMARK_ALIGN.out.bam
alignment_reports = BISMARK_ALIGN.out.report.map{ meta, report -> [ meta, report, [] ] }
} else {
if (!skip_deduplication) {
/*
* Run deduplicate_bismark
*/
BISMARK_DEDUPLICATE (
BISMARK_ALIGN.out.bam
)
alignments = BISMARK_DEDUPLICATE.out.bam
alignment_reports = BISMARK_ALIGN.out.report.join(BISMARK_DEDUPLICATE.out.report)
ch_versions = ch_versions.mix(BISMARK_DEDUPLICATE.out.versions)
ch_alignments = BISMARK_DEDUPLICATE.out.bam
ch_alignment_reports = BISMARK_ALIGN.out.report.join(BISMARK_DEDUPLICATE.out.report)
ch_versions = ch_versions.mix(BISMARK_DEDUPLICATE.out.versions)
}

/*
* MODULE: Run samtools sort on aligned or deduplicated bam
*/
SAMTOOLS_SORT (
ch_alignments,
[[:],[]] // [ [meta], [fasta]]
)
ch_versions = ch_versions.mix(SAMTOOLS_SORT.out.versions)

/*
* MODULE: Run samtools index on aligned or deduplicated bam
*/
SAMTOOLS_INDEX (
SAMTOOLS_SORT.out.bam
)
ch_versions = ch_versions.mix(SAMTOOLS_INDEX.out.versions)

/*
* Run bismark_methylation_extractor
*/
BISMARK_METHYLATIONEXTRACTOR (
alignments,
ch_alignments,
ch_bismark_index
)
ch_methylation_bedgraph = BISMARK_METHYLATIONEXTRACTOR.out.bedgraph
Expand All @@ -74,7 +92,7 @@ workflow FASTQ_ALIGN_DEDUP_BISMARK {
*/
if (cytosine_report) {
BISMARK_COVERAGE2CYTOSINE (
BISMARK_METHYLATIONEXTRACTOR.out.coverage,
ch_methylation_coverage,
ch_fasta,
ch_bismark_index
)
Expand All @@ -88,7 +106,7 @@ workflow FASTQ_ALIGN_DEDUP_BISMARK {
* Generate bismark sample reports
*/
BISMARK_REPORT (
alignment_reports
ch_alignment_reports
.join(ch_methylation_report)
.join(ch_methylation_mbias)
)
Expand All @@ -100,54 +118,37 @@ workflow FASTQ_ALIGN_DEDUP_BISMARK {
*/
BISMARK_SUMMARY (
BISMARK_ALIGN.out.bam.collect{ meta, bam -> bam.name },
alignment_reports.collect{ meta, align_report, dedup_report -> align_report },
alignment_reports.collect{ meta, align_report, dedup_report -> dedup_report }.ifEmpty([]),
BISMARK_METHYLATIONEXTRACTOR.out.report.collect{ meta, report -> report },
BISMARK_METHYLATIONEXTRACTOR.out.mbias.collect{ meta, mbias -> mbias }
ch_alignment_reports.collect{ meta, align_report, dedup_report -> align_report },
ch_alignment_reports.collect{ meta, align_report, dedup_report -> dedup_report }.ifEmpty([]),
ch_methylation_report.collect{ meta, report -> report },
ch_methylation_mbias.collect{ meta, mbias -> mbias }
)
ch_bismark_summary = BISMARK_SUMMARY.out.summary
ch_versions = ch_versions.mix(BISMARK_SUMMARY.out.versions)

/*
* MODULE: Run samtools sort on dedup bam
*/
SAMTOOLS_SORT_DEDUPLICATED (
alignments,
[[:],[]] // [ [meta], [fasta]]
)
ch_versions = ch_versions.mix(SAMTOOLS_SORT_DEDUPLICATED.out.versions)

/*
* MODULE: Run samtools index on dedup bam
*/
SAMTOOLS_INDEX_DEDUPLICATED (
SAMTOOLS_SORT_DEDUPLICATED.out.bam
)
ch_versions = ch_versions.mix(SAMTOOLS_INDEX_DEDUPLICATED.out.versions)

/*
* Collect MultiQC inputs
*/
ch_multiqc_files = BISMARK_SUMMARY.out.summary
.mix(alignment_reports.collect{ meta, align_report, dedup_report -> align_report })
.mix(alignment_reports.collect{ meta, align_report, dedup_report -> dedup_report })
.mix(BISMARK_METHYLATIONEXTRACTOR.out.report.collect{ meta, report -> report })
.mix(BISMARK_METHYLATIONEXTRACTOR.out.mbias.collect{ meta, mbias -> mbias })
.mix(BISMARK_REPORT.out.report.collect{ meta, report -> report })
ch_multiqc_files = ch_bismark_summary
.mix(ch_alignment_reports.collect{ meta, align_report, dedup_report -> align_report })
.mix(ch_alignment_reports.collect{ meta, align_report, dedup_report -> dedup_report })
.mix(ch_methylation_report.collect{ meta, report -> report })
.mix(ch_methylation_mbias.collect{ meta, mbias -> mbias })
.mix(ch_bismark_report.collect{ meta, report -> report })

emit:
dedup_bam = SAMTOOLS_SORT_DEDUPLICATED.out.bam // channel: [ val(meta), [ bam ] ]
dedup_bam_index = SAMTOOLS_INDEX_DEDUPLICATED.out.bai // channel: [ val(meta), [ bai ] ]
coverage2cytosine_coverage = ch_coverage2cytosine_coverage // channel: [ val(meta), [ coverage ] ]
coverage2cytosine_report = ch_coverage2cytosine_report // channel: [ val(meta), [ report ] ]
coverage2cytosine_summary = ch_coverage2cytosine_summary // channel: [ val(meta), [ summary ] ]
methylation_bedgraph = ch_methylation_bedgraph // channel: [ val(meta), [ bedgraph ] ]
methylation_calls = ch_methylation_calls // channel: [ val(meta), [ methylation_calls ] ]
methylation_coverage = ch_methylation_coverage // channel: [ val(meta), [ coverage ] ]
methylation_report = ch_methylation_report // channel: [ val(meta), [ report ] ]
methylation_mbias = ch_methylation_mbias // channel: [ val(meta), [ mbias ] ]
bismark_report = ch_bismark_report // channel: [ val(meta), [ report ] ]
bismark_summary = ch_bismark_summary // channel: [ val(meta), [ summary ] ]
multiqc = ch_multiqc_files // path: *{html,txt}
versions = ch_versions // path: *.version.txt
bam = SAMTOOLS_SORT.out.bam // channel: [ val(meta), [ bam ] ]
bai = SAMTOOLS_INDEX.out.bai // channel: [ val(meta), [ bai ] ]
coverage2cytosine_coverage = ch_coverage2cytosine_coverage // channel: [ val(meta), [ coverage ] ]
coverage2cytosine_report = ch_coverage2cytosine_report // channel: [ val(meta), [ report ] ]
coverage2cytosine_summary = ch_coverage2cytosine_summary // channel: [ val(meta), [ summary ] ]
methylation_bedgraph = ch_methylation_bedgraph // channel: [ val(meta), [ bedgraph ] ]
methylation_calls = ch_methylation_calls // channel: [ val(meta), [ methylation_calls ] ]
methylation_coverage = ch_methylation_coverage // channel: [ val(meta), [ coverage ] ]
methylation_report = ch_methylation_report // channel: [ val(meta), [ report ] ]
methylation_mbias = ch_methylation_mbias // channel: [ val(meta), [ mbias ] ]
bismark_report = ch_bismark_report // channel: [ val(meta), [ report ] ]
bismark_summary = ch_bismark_summary // channel: [ val(meta), [ summary ] ]
multiqc = ch_multiqc_files // path: *{html,txt}
versions = ch_versions // path: *.version.txt
}
10 changes: 5 additions & 5 deletions subworkflows/nf-core/fastq_align_dedup_bismark/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ input:
description: |
Structure: [ val(meta), path(fasta) ]
pattern: "*.{fa,fa.gz}"
- ch_index:
- ch_bismark_index:
description: |
Bismark genome index files
Structure: [ val(meta), path(index) ]
Expand All @@ -46,16 +46,16 @@ input:
description: |
Produce coverage2cytosine reports that relates methylation calls back to genomic cytosine contexts
output:
- dedup_bam:
- bam:
type: file
description: |
Channel containing deduplicated BAM files.
Channel containing aligned or deduplicated BAM files.
Structure: [ val(meta), path(bam) ]
pattern: "*.bam"
- dedup_bam_index:
- bai:
type: file
description: |
Channel containing deduplicated BAM index files.
Channel containing aligned or deduplicated BAM index files.
Structure: [ val(meta), path(bam.bai) ]
pattern: "*.bai"
- coverage2cytosine_coverage:
Expand Down
Loading
Loading