Skip to content

Commit

Permalink
Merge pull request #400 from bjlang/dev
Browse files Browse the repository at this point in the history
use subworkflows/local/bam_peaks_call_qc_annotate_macs2_homer from nf-core/atacseq
  • Loading branch information
bjlang committed Jul 8, 2024
2 parents 1096fc1 + 561b73b commit 209e589
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 125 deletions.
50 changes: 25 additions & 25 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,21 @@ process {
]
}

withName: 'BAM_REMOVE_ORPHANS' {
ext.args = '--only_fr_pairs'
ext.prefix = { "${meta.id}.mLb.clN" }
withName: 'NFCORE_CHIPSEQ:CHIPSEQ:BAM_FILTER_BAMTOOLS:SAMTOOLS_INDEX' {
ext.prefix = { "${meta.id}.mLb.clN.sorted" }
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library" },
mode: params.publish_dir_mode,
pattern: '*.bam',
enabled: params.save_align_intermeds
pattern: '*.{bai,csi}'
]
}

withName: 'NFCORE_CHIPSEQ:CHIPSEQ:BAM_FILTER_BAMTOOLS:BAM_STATS_SAMTOOLS:.*' {
ext.prefix = { "${meta.id}.mLb.clN.sorted.bam" }
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/samtools_stats" },
mode: params.publish_dir_mode,
pattern: "*.{stats,flagstat,idxstats}"
]
}

Expand All @@ -391,21 +398,14 @@ process {
]
}

withName: 'NFCORE_CHIPSEQ:CHIPSEQ:BAM_FILTER_BAMTOOLS:SAMTOOLS_INDEX' {
ext.prefix = { "${meta.id}.mLb.clN.sorted" }
withName: 'BAM_REMOVE_ORPHANS' {
ext.args = '--only_fr_pairs'
ext.prefix = { "${meta.id}.mLb.clN" }
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library" },
mode: params.publish_dir_mode,
pattern: '*.{bai,csi}'
]
}

withName: 'NFCORE_CHIPSEQ:CHIPSEQ:BAM_FILTER_BAMTOOLS:BAM_STATS_SAMTOOLS:.*' {
ext.prefix = { "${meta.id}.mLb.clN.sorted.bam" }
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/samtools_stats" },
mode: params.publish_dir_mode,
pattern: "*.{stats,flagstat,idxstats}"
pattern: '*.bam',
enabled: params.save_align_intermeds
]
}

Expand All @@ -427,7 +427,7 @@ process {
]
}

withName: 'BEDTOOLS_GENOMECOV' {
withName: '.*:BAM_BEDGRAPH_BIGWIG_BEDTOOLS_UCSC:BEDTOOLS_GENOMECOV' {
ext.args = { (meta.single_end && params.fragment_size > 0) ? "-fs ${params.fragment_size}" : '' }
ext.prefix = { "${meta.id}.mLB.clN" }
publishDir = [
Expand All @@ -444,7 +444,7 @@ process {
]
}

withName: 'UCSC_BEDGRAPHTOBIGWIG' {
withName: '.*:BAM_BEDGRAPH_BIGWIG_BEDTOOLS_UCSC:UCSC_BEDGRAPHTOBIGWIG' {
ext.prefix = { "${meta.id}.mLb.clN" }
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/bigwig" },
Expand Down Expand Up @@ -540,7 +540,7 @@ if (!params.skip_plot_fingerprint) {
}

process {
withName: 'MACS2_CALLPEAK' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:MACS2_CALLPEAK' {
ext.args = [
'--keep-dup all',
params.narrow_peak ? '' : "--broad --broad-cutoff ${params.broad_cutoff}",
Expand All @@ -559,15 +559,15 @@ process {
]
}

withName: 'FRIP_SCORE' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:FRIP_SCORE' {
ext.args = '-bed -c -f 0.20'
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/macs2/${params.narrow_peak ? '/narrow_peak' : '/broad_peak'}/qc" },
enabled: false
]
}

withName: 'MULTIQC_CUSTOM_PEAKS' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:MULTIQC_CUSTOM_PEAKS' {
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/macs2/${params.narrow_peak ? '/narrow_peak' : '/broad_peak'}/qc" },
mode: params.publish_dir_mode,
Expand All @@ -578,7 +578,7 @@ process {

if (!params.skip_peak_annotation) {
process {
withName: 'HOMER_ANNOTATEPEAKS_MACS2' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:HOMER_ANNOTATEPEAKS' {
ext.args = '-gid'
ext.prefix = { "${meta.id}_peaks" }
publishDir = [
Expand All @@ -591,7 +591,7 @@ if (!params.skip_peak_annotation) {

if (!params.skip_peak_qc) {
process {
withName: 'PLOT_MACS2_QC' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:PLOT_MACS2_QC' {
ext.args = '-o ./ -p macs2_peak'
publishDir = [
path: { "${params.outdir}/${params.aligner}/merged_library/macs2/${params.narrow_peak ? '/narrow_peak' : '/broad_peak'}/qc" },
Expand All @@ -600,7 +600,7 @@ if (!params.skip_peak_annotation) {
]
}

withName: 'PLOT_HOMER_ANNOTATEPEAKS' {
withName: '.*:BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER:PLOT_HOMER_ANNOTATEPEAKS' {
ext.args = '-o ./'
ext.prefix = 'macs2_annotatePeaks'
publishDir = [
Expand Down
155 changes: 155 additions & 0 deletions subworkflows/local/bam_peaks_call_qc_annotate_macs2_homer.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//
// Call peaks with MACS2, annotate with HOMER and perform downstream QC
//

include { MACS2_CALLPEAK } from '../../modules/nf-core/macs2/callpeak/main'
include { HOMER_ANNOTATEPEAKS } from '../../modules/nf-core/homer/annotatepeaks/main'

include { FRIP_SCORE } from '../../modules/local/frip_score'
include { MULTIQC_CUSTOM_PEAKS } from '../../modules/local/multiqc_custom_peaks'
include { PLOT_MACS2_QC } from '../../modules/local/plot_macs2_qc'
include { PLOT_HOMER_ANNOTATEPEAKS } from '../../modules/local/plot_homer_annotatepeaks'

workflow BAM_PEAKS_CALL_QC_ANNOTATE_MACS2_HOMER {
take:
ch_bam // channel: [ val(meta), [ ip_bam ], [ control_bam ] ]
ch_fasta // channel: [ fasta ]
ch_gtf // channel: [ gtf ]
macs_gsize // integer: value for --macs_gsize parameter
annotate_peaks_suffix // string: suffix for input HOMER annotate peaks files to be trimmed off
ch_peak_count_header_multiqc // channel: [ header_file ]
ch_frip_score_multiqc // channel: [ header_file ]
ch_peak_annotation_header_multiqc // channel: [ header_file ]
is_narrow_peak // boolean: true/false
skip_peak_annotation // boolean: true/false
skip_peak_qc // boolean: true/false

main:

ch_versions = Channel.empty()

//
// Call peaks with MACS2
//
MACS2_CALLPEAK (
ch_bam,
macs_gsize
)
ch_versions = ch_versions.mix(MACS2_CALLPEAK.out.versions.first())

//
// Filter out samples with 0 MACS2 peaks called
//
MACS2_CALLPEAK
.out
.peak
.filter {
meta, peaks ->
peaks.size() > 0
}
.set { ch_macs2_peaks }

// Create channels: [ meta, ip_bam, peaks ]
ch_bam
.join(ch_macs2_peaks, by: [0])
.map {
meta, ip_bam, control_bam, peaks ->
[ meta, ip_bam, peaks ]
}
.set { ch_bam_peaks }

//
// Calculate FRiP score
//
FRIP_SCORE (
ch_bam_peaks
)
ch_versions = ch_versions.mix(FRIP_SCORE.out.versions.first())

// Create channels: [ meta, peaks, frip ]
ch_bam_peaks
.join(FRIP_SCORE.out.txt, by: [0])
.map {
meta, ip_bam, peaks, frip ->
[ meta, peaks, frip ]
}
.set { ch_bam_peak_frip }

//
// FRiP score custom content for MultiQC
//
MULTIQC_CUSTOM_PEAKS (
ch_bam_peak_frip,
ch_peak_count_header_multiqc,
ch_frip_score_multiqc
)
ch_versions = ch_versions.mix(MULTIQC_CUSTOM_PEAKS.out.versions.first())

ch_homer_annotatepeaks = Channel.empty()
ch_plot_macs2_qc_txt = Channel.empty()
ch_plot_macs2_qc_pdf = Channel.empty()
ch_plot_homer_annotatepeaks_txt = Channel.empty()
ch_plot_homer_annotatepeaks_pdf = Channel.empty()
ch_plot_homer_annotatepeaks_tsv = Channel.empty()
if (!skip_peak_annotation) {
//
// Annotate peaks with HOMER
//
HOMER_ANNOTATEPEAKS (
ch_macs2_peaks,
ch_fasta,
ch_gtf
)
ch_homer_annotatepeaks = HOMER_ANNOTATEPEAKS.out.txt
ch_versions = ch_versions.mix(HOMER_ANNOTATEPEAKS.out.versions.first())

if (!skip_peak_qc) {
//
// MACS2 QC plots with R
//
PLOT_MACS2_QC (
ch_macs2_peaks.collect{it[1]},
is_narrow_peak
)
ch_plot_macs2_qc_txt = PLOT_MACS2_QC.out.txt
ch_plot_macs2_qc_pdf = PLOT_MACS2_QC.out.pdf
ch_versions = ch_versions.mix(PLOT_MACS2_QC.out.versions)

//
// Peak annotation QC plots with R
//
PLOT_HOMER_ANNOTATEPEAKS (
HOMER_ANNOTATEPEAKS.out.txt.collect{it[1]},
ch_peak_annotation_header_multiqc,
annotate_peaks_suffix
)
ch_plot_homer_annotatepeaks_txt = PLOT_HOMER_ANNOTATEPEAKS.out.txt
ch_plot_homer_annotatepeaks_pdf = PLOT_HOMER_ANNOTATEPEAKS.out.pdf
ch_plot_homer_annotatepeaks_tsv = PLOT_HOMER_ANNOTATEPEAKS.out.tsv
ch_versions = ch_versions.mix(PLOT_HOMER_ANNOTATEPEAKS.out.versions)
}
}

emit:
peaks = ch_macs2_peaks // channel: [ val(meta), [ peaks ] ]
xls = MACS2_CALLPEAK.out.xls // channel: [ val(meta), [ xls ] ]
gapped_peaks = MACS2_CALLPEAK.out.gapped // channel: [ val(meta), [ gapped_peak ] ]
bed = MACS2_CALLPEAK.out.bed // channel: [ val(meta), [ bed ] ]
bedgraph = MACS2_CALLPEAK.out.bdg // channel: [ val(meta), [ bedgraph ] ]

frip_txt = FRIP_SCORE.out.txt // channel: [ val(meta), [ txt ] ]

frip_multiqc = MULTIQC_CUSTOM_PEAKS.out.frip // channel: [ val(meta), [ frip ] ]
peak_count_multiqc = MULTIQC_CUSTOM_PEAKS.out.count // channel: [ val(meta), [ counts ] ]

homer_annotatepeaks = ch_homer_annotatepeaks // channel: [ val(meta), [ txt ] ]

plot_macs2_qc_txt = ch_plot_macs2_qc_txt // channel: [ txt ]
plot_macs2_qc_pdf = ch_plot_macs2_qc_pdf // channel: [ pdf ]

plot_homer_annotatepeaks_txt = ch_plot_homer_annotatepeaks_txt // channel: [ txt ]
plot_homer_annotatepeaks_pdf = ch_plot_homer_annotatepeaks_pdf // channel: [ pdf ]
plot_homer_annotatepeaks_tsv = ch_plot_homer_annotatepeaks_tsv // channel: [ tsv ]

versions = ch_versions // channel: [ versions.yml ]
}
Loading

0 comments on commit 209e589

Please sign in to comment.