-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbam2cool.nf
259 lines (199 loc) · 5.45 KB
/
bam2cool.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env nextflow
params.outDir = false
params.bamDir = false
params.resolutions = false
params.ABresolutions = false
params.mapQ = 0
params.help = false
def helpMessage() {
log.info"""
Usage:
The typical command for running the pipeline is as follows:
bam2cool --bamDir ~/path/to/bamDir --outDir ~/ebs/ref_push/prodEpi/myExpName
Mandatory arguments:
--bamDir [path] Path of a directory containing the bam file(s) to be cooled, can be local or an S3 accessible bucket.
--outDir [pathOfDir] Path of where to publish the data, can be local or an S3 accessible bucket.
Additional parameters:
--mapQ [int] Quqlity score to filter reads. Integer between 0 and 60. Default: 0.
--resolutions [integers] Arrowhead and hiccup resolutions. Comma-seperated list of resolutions in kb for loops finding. Default: [5,10]
--ABresolutions [integers] ABcomp resolutions. Comma-seperated list of resolutions in kb. Default: [32,64,128]
""".stripIndent()
}
if (params.help){
helpMessage()
exit 0
}
if ( !(params.bamDir && params.outDir) ){
exit 1, "--bamDir and --outDir are required arguments. Use --help to get the full usage."
}
if (params.resolutions){
resolutions = params.resolutions.split(/,/,-1)
} else {
resolutions = [5,10]
}
if (params.ABresolutions){
ABresolutions = params.ABresolutions.toString().split(/,/,-1)
} else {
ABresolutions = [32,64,128]
}
process chr_size {
tag "_${id}"
label "mezzo"
container 'mblanche/bwa-samtools'
publishDir "${params.outDir}/chr_size_res",
mode: 'copy'
input:
path(bam) from Channel.fromPath("${params.bamDir}/*.bam")
output:
tuple id, path(bam), path("*.tsv") into pairtools_parse_ch, cooler_chrsize_ch
script:
id = (bam.name.toString().split(/\./))[0]
"""
samtools view -H ${bam} | \
awk -v OFS='\t' '/^@SQ/ && !(\$2 ~ /:(chr|"")M/) {split(\$2,chr,":");split(\$3,ln,":");print chr[2],ln[2]}' | \
sort -V -k1,1 \
> chr_size.tsv
"""
}
process pairtools_parse {
tag "_${id}"
label "cpu"
container 'mblanche/pairtools'
input:
tuple id, path(bam), path(chr_sizes) from pairtools_parse_ch
output:
tuple id, path("*.pairsam.gz") into pairsam_ch
script:
"""
pairtools parse \
--min-mapq ${params.mapQ} \
--walks-policy 5unique \
--max-inter-align-gap 30 \
--nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--chroms-path ${chr_sizes} \
--output ${id}.pairsam.gz \
${bam}
"""
}
process pairtools_sort {
tag "_${id}"
label "cpu"
container 'mblanche/pairtools'
input:
tuple id, path(pairsam) from pairsam_ch
output:
tuple id, path("*_sorted.pairsam.gz") into sorted_ps_ch
script:
"""
pairtools sort \
--nproc ${task.cpus} \
--output ${id}_sorted.pairsam.gz \
$pairsam
"""
}
process pairtools_dedup {
echo true
tag "_${id}"
label "cpu"
container 'mblanche/pairtools'
publishDir "${params.outDir}/pairtools_stat",
mode: 'copy',
saveAs: {filename -> filename.endsWith('.stats') ? filename : null}
input:
tuple id, path(pairsam) from sorted_ps_ch
output:
tuple id, path("*_dedup.pairsam.gz") into dedup_ps_ch
path("*.stats")
script:
"""
echo redoing
pairtools dedup --nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--mark-dups \
--output-stats ${id}_pairtools.stats \
--output ${id}_dedup.pairsam.gz \
${pairsam}
"""
}
process pairtools_split_dedup {
tag "_${id}"
label "cpu"
container 'mblanche/pairtools'
publishDir "${params.outDir}/valid_pairs",
mode: 'copy'
input:
tuple id, path(pairsam) from dedup_ps_ch
output:
tuple id, path("*.valid.pairs.gz") into pairs_ch
script:
"""
pairtools split --nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--output-pairs ${id}_PT.valid.pairs.gz \
${pairsam}
"""
}
process index_pairs {
tag "_${id}"
label "mezzo"
container 'mblanche/pairtools'
publishDir "${params.outDir}/valid_pairs",
mode: 'copy'
input:
tuple id, path(pairs) from pairs_ch
output:
tuple id, path(pairs), path("*.px2") into pairs_ch_cooler
script:
"""
pairix ${pairs}
"""
}
/*
process cooler_cload {
tag "_${id}"
label "cpu"
container 'mblanche/cooler'
input:
tuple id, path(pairs), path(idx) from pairs_ch_cooler
path(chr_sizes) from cooler_chrsize_ch
output:
tuple id, path("*.cool") into balance_cooler_ch
script:
"""
cooler cload pairix \
-p ${task.cpus} \
${chr_sizes}:1000 \
${pairs} \
${id}.cool
"""
}
/*
process balance_cooler {
tag "_${id}"
label "large"
container 'mblanche/cooler'
publishDir "${params.outDir}/coolerFiles",
mode: 'copy'
input:
tuple id, path(cooler) from balance_cooler_ch
output:
tuple id, path(cooler) into zoomify_cooler_ch
script:
"""
cooler balance --force -p ${task.cpus} ${cooler}
"""
}
process cooler_zoomify {
tag "_${id}"
label "cpu"
container 'mblanche/cooler'
publishDir "${params.outDir}/coolerFiles",
mode: 'copy'
input:
tuple id, path(cooler) from zoomify_cooler_ch
output:
tuple id, path("*.mcool") into mustache_mcool_ch, abcomp_mcool_ch
script:
"""
cooler zoomify --balance -p ${task.cpus} ${cooler}
"""
}
*/