Skip to content

Commit

Permalink
refactor: use tagAlign for sicer and bam for macs2 & GEM
Browse files Browse the repository at this point in the history
  • Loading branch information
kelly-sovacool committed Sep 11, 2023
1 parent 3467e83 commit 2b24fb1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Binary file modified assets/dag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 20 additions & 8 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,37 @@ workflow {

// peak calling

genome_frac = CALC_GENOME_FRAC(chrom_sizes)
// create channel with [ meta, chip_tag, input_tag, fraglen, genome_frac]
DEDUPLICATE.out.tag_align
.combine(DEDUPLICATE.out.tag_align)
.map {
meta1, tag1, meta2, tag2 ->
meta1.control == meta2.id ? [ meta1, tag1, tag2 ]: null
}
.join(frag_lengths)
.combine(genome_frac)
.set { ch_sicer }

DEDUPLICATE.out.bam
.combine(DEDUPLICATE.out.bam)
.map {
meta1, bam1, bai1, meta2, bam2, bai2 ->
meta1.control == meta2.id ? [ meta1, bam1, bam2, [bai1, bai2] ]: null
}
.set { ch_ip_ctrl_bam }
// create channel with [ meta, chip_tag, input_tag, fraglen, genome_frac]
genome_frac = CALC_GENOME_FRAC(chrom_sizes)
ch_ip_ctrl_bam
.join(frag_lengths)
.combine(genome_frac)
.set { ch_bam_macs }

ch_bam_macs | SICER
ch_bam_macs | MACS_BROAD
ch_bam_macs | MACS_NARROW
.set { ch_macs }

ch_ip_ctrl_bam
.combine(Channel.fromPath(params.gem_read_dists))
.combine(chrom_sizes) | GEM
.combine(chrom_sizes)
.set {ch_gem}

ch_sicer | SICER
ch_macs | MACS_BROAD
ch_macs | MACS_NARROW
ch_gem | GEM
}
11 changes: 7 additions & 4 deletions modules/local/peaks.nf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ process SICER {
label 'process_high'

input:
tuple val(meta), path(chip), path(input), path(bais), val(fraglen), val(genome_frac)
tuple val(meta), path(chip), path(input), val(fraglen), val(genome_frac)

//output:
output:
tuple path("*.scoreisland"), path("*normalized.wig"), path("*islands-summary"), path("*island.bed")

script:
"""
Expand Down Expand Up @@ -83,6 +84,7 @@ process MACS_BROAD {

script:
"""
ls $chip > debug.txt
macs2 callpeak \\
-t ${chip} \\
-c ${input} \\
Expand Down Expand Up @@ -142,7 +144,8 @@ process GEM {
input:
tuple val(meta), path(chip), path(input), path(bais), path(read_dists), path(chrom_sizes)

//output:
output:
path("*.GEM_events.narrowPeak")

script:
// $GEMJAR is defined in the docker container
Expand All @@ -158,7 +161,7 @@ process GEM {
--k_max 13 \\
--outNP \\
--nrf \\
-f SAM
--f SAM
"""

stub:
Expand Down
6 changes: 3 additions & 3 deletions modules/local/qc.nf
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ process DEDUPLICATE {
tuple val(meta), path(bam), path(chrom_sizes)

output:
tuple val(meta), path("${meta.id}.TagAlign"), emit: tag_align
tuple val(meta), path("${meta.id}.TagAlign.bed"), emit: tag_align
tuple val(meta), path("${bam.baseName}.dedup.bam"), path("${bam.baseName}.dedup.bam.bai"), emit: bam
tuple path("${bam.baseName}.dedup.bam.flagstat"), path("${bam.baseName}.dedup.bam.idxstat"), emit: flagstat

Expand All @@ -196,8 +196,8 @@ process DEDUPLICATE {
macs2 filterdup -i ${bam} -g ${params.align.effective_genome_size} --keep-dup="auto" -o TmpTagAlign1
awk -F"\\t" -v OFS="\\t" '{{if (\$2>0 && \$3>0) {{print}}}}' TmpTagAlign1 > TmpTagAlign2
awk -F"\\t" -v OFS="\\t" '{{print \$1,1,\$2}}' ${chrom_sizes} | sort -k1,1 -k2,2n > GenomeFile.bed
bedtools intersect -wa -f 1.0 -a TmpTagAlign2 -b GenomeFile.bed > ${meta.id}.TagAlign
bedtools bedtobam -i ${meta.id}.TagAlign -g ${chrom_sizes} | samtools sort -@ ${task.cpus} -o ${bam.baseName}.dedup.bam
bedtools intersect -wa -f 1.0 -a TmpTagAlign2 -b GenomeFile.bed > ${meta.id}.TagAlign.bed
bedtools bedtobam -i ${meta.id}.TagAlign.bed -g ${chrom_sizes} | samtools sort -@ ${task.cpus} -o ${bam.baseName}.dedup.bam
samtools index ${bam.baseName}.dedup.bam
samtools flagstat ${bam.baseName}.dedup.bam > ${bam.baseName}.dedup.bam.flagstat
samtools idxstats ${bam.baseName}.dedup.bam > ${bam.baseName}.dedup.bam.idxstat
Expand Down

0 comments on commit 2b24fb1

Please sign in to comment.