forked from IARCbioinfo/nf_coverage_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_coverage.nf
More file actions
65 lines (49 loc) · 1.36 KB
/
Copy pathplot_coverage.nf
File metadata and controls
65 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Defines pipeline parameters
params.bam_folder = null
params.bed = null
// The bed file
bed = file(params.bed)
// Creates the `bam` channel
bam = Channel.fromPath( params.bam_folder+'/*.bam' )
// Step 1. launch bedtools software to calculate coverage at each position of the bed
process coverage {
input:
file bam
file bed
output:
file 'coverage.txt' into coverage
shell:
'''
bedtools coverage -d -a !{bed} -b !{bam} > coverage.txt
'''
}
// Step 2. launch custom awk script to calculate the mean coverage
process mean {
input:
file coverage
output:
stdout average
shell:
'''
awk '{ sum += $6 } END { if (NR > 0) print sum / NR }' !{coverage}
'''
}
// collect output of all means to a single file
all_average = average.collectFile(name: 'all_average.txt')
// Step 3: plot histogram of mean coverage using a custom R script
process plot {
input:
file all_average
output:
file 'coverage.pdf'
publishDir '.', mode: 'move'
shell:
'''
#!/usr/bin/env Rscript
library(ggplot2)
pdf("coverage.pdf")
data=read.table("all_average.txt")
ggplot(data, aes(x=V1)) + geom_histogram(aes(y=..density..), colour="black", fill="grey") + geom_density(alpha=.2, fill="#FF6666") + labs(x = "Mean Depth")
dev.off()
'''
}