-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
136 lines (112 loc) · 2.6 KB
/
main.nf
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
// Bedtools slop parameters
params.slop_left = 400
params.slop_right = 400
workflow {
main:
quantilize(params.genome, params.variable_bedgraph, params.target)
}
workflow quantilize {
take: genome
variable_bedgraph
target
main:
variable_bedgraph_ch = Channel.fromPath(variable_bedgraph) | \
prepareBedgraph
genome_file = Channel.fromPath(genome)
target_ch = Channel.fromPath(target) | \
sortGff
slopped = slop(target_ch, genome_file)
intersect(slopped, variable_bedgraph_ch) |
gzipIntersection |
maultaschify
maultaschify.out.intervals | plotQuantiles
maultaschify.out.warnings.toList().forEach { if(it) print it.trim() }
}
process prepareBedgraph {
container 'debian:stable-slim'
input:
path f
output:
path "*.gz"
script:
if (f.getExtension().equals("gz") )
"""
gunzip -c ${f} | sort -k1,1 -k2,2n -k3,3n | gzip -c > ${f}.gz
"""
else if (f.getExtension().equals("bg"))
"""
cat ${f} | sort -k1,1 -k2,2n -k3,3n | gzip -c > "${f}.gz"
"""
else
error "unknown file extension: ${f}"
}
process gzipIntersection {
container 'debian:stable-slim'
input:
path f
output:
path "*.gz"
script:
"""
cat ${f} | gzip -c > "${f}.gz"
"""
}
process intersect {
container 'biocontainers/bedtools:v2.27.1dfsg-4-deb_cv1'
input:
path slop
path bedGraph
output:
path "*.flanked"
"""
bedtools intersect -a "${slop}" -b ${bedGraph} -wb -s -wa | \
awk -v OFS="," '{print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$11,\$12,\$14}' > "${slop}.flanked"
# Add dummy line at the end for subsequent process
echo "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1" >> "${slop}.flanked"
"""
}
process maultaschify {
container 'python:slim'
input:
path csv
output:
path "intervals.tsv.gz", emit: intervals
stdout emit: warnings
"""
maultaschify.py ${csv}
"""
}
process sortGff {
container 'debian:stable-slim'
input:
path a
output:
path "${a}.sorted"
"""
sort -k1,1 -k4,4n -k5,5n ${a} > ${a}.sorted
"""
}
process slop {
container 'biocontainers/bedtools:v2.27.1dfsg-4-deb_cv1'
input:
path target
path genome
output:
path "*.slop"
"""
bedtools slop -l ${params.slop_left} -r ${params.slop_right} -g ${genome} -i ${target} > ${target}.slop
"""
}
process plotQuantiles {
publishDir ".", mode: "copy"
container 'rocker/tidyverse'
input:
path csv
output:
path "*.png"
"""
plot_quantiles.R ${csv} ${params.tag}
"""
}