-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepiPipeBam.nf
433 lines (337 loc) · 8.86 KB
/
epiPipeBam.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/usr/bin/env nextflow
params.bamDir = false
params.outDir = false
params.help = false
params.genome = 'hg38'
params.resolutions = false
params.ABresolutions = false
params.capture = false
params.hichip = false
def helpMessage() {
log.info"""
Usage:
The typical command for running the pipeline is as follows:
bam2bw --bamDir ~/path/to/bam/location
or
bam2bw --bamDir ~/path/to/bam/location --outDir ~/path/to/where/to/save/files
Mandatory arguments:
--bamDir [path] Name of the a direcoty with bam files and their index to compute coverages (can be local or valid S3 location.
Facultative arguments
--outDir [path] Path to a diectory to save the bigwig coveage files (can be local or valid S3 location.
Alignment:
--genome [str] Name of the genome to use. Possible choice: hg38, hg19, mm10, dm3. Default: hg38.
Arrowhead parameters:
--resolutions [integers] Comma-seperated list of resolutions in kb for loops finding. Default: [5,10]
--ABresolutions [integers] Comma-seperated list of resolutions in kb. Default: [32,64,128]
Sub-Steps:
--capture Runs only steps required for HiC capture. Will not permoform AB, TAD and loop calls.
--hichip Runs only steps required for HiChIP. Will not permoform AB, TAD and loop calls.
""".stripIndent()
}
if (!params.bamDir) {
exit 1, "--bamDir is a required arguments. Use --help to get the full usage."
}
if(!params.outDir){
outDir = file(params.bamDir).getParent()
} else {
outDir = params.outDir
}
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]
}
if (!params.genome =~ /hg19|hg38|mm10|dm3/){
exit 1, "Only hg38, mm10 and dm3 genomes are currently offered"
} else {
Channel
.fromFilePairs("${HOME}/ebs/genome/nextflow/${params.genome}/*.{amb,sa,pac,ann,bwt,fa}", size: -1, checkIfExists: true)
.ifEmpty { exit 1, "BWA index not found: ${params.genome}" }
.set { bwa_index }
Channel
.fromPath("${HOME}/ebs/genome/nextflow/${params.genome}/${params.genome}.fa", checkIfExists: true)
.ifEmpty { exit 1, "Genome not found: ${params.genome}" }
.set { abcomp_genome_ch }
}
if (params.help){
helpMessage()
exit 0
}
Channel
.fromPath("${params.bamDir}/*.bam")
.set{bam_ch}
process bamFilter {
label 'bamFilter'
tag "_${id}"
cpus 8
memory '32 GB'
container 'mblanche/bwa-samtools'
input:
path(bam) from bam_ch.first()
output:
tuple id, path("${id}_filtered.bam") into bamFilt_ch
//tuple id, path("${id}_filtered.bam"), path("${id}_filtered.bam.bai") into bam2bwIn_ch
script:
id = bam.name.toString().take(bam.name.toString().lastIndexOf('.'))
"""
samtools view -h -f1 -F 3328 ${bam} | samtools sort -n -O BAM -@ ${task.cpus} -o ${id}_filtered.bam -
##samtools index ${id}_filtered.bam
"""
}
/*
process bam2bw {
tag "_${id}"
cpus 20
memory '150 GB'
container 'mblanche/r-cov'
publishDir "${outDir}/bigwigs",
mode: 'copy'
input:
tuple id, path(bam), path(bai) from bam2bwIn_ch
output:
tuple id, path("*.bw") into bigwig_out_ch
script:
"""
bam2bw ${bam} ${id}.bw ${task.cpus}
"""
}
*/
process bam2pairs {
label 'bam2pairs'
tag "_${id}"
cpus 16
memory '64 GB'
container 'dovetailg/pairtools'
publishDir "${outDir}/validPairs",
mode: 'copy'
input:
tuple id, path(bam) from bamFilt_ch
output:
tuple id, path("*.gz"), path("*.px2") into pairs_chrSize_ch
script:
"""
bam2pairs ${bam} ${id}
#mv ${id}.bsorted.pairs.gz ${id}.valid.pairs.gz
#mv ${id}.bsorted.pairs.gz.px2 ${id}.valid.pairs.gz.px2
"""
}
process chr_size {
tag "_${id}"
cpus 8
memory '32 GB'
container 'dovetailg/pairtools'
input:
tuple id, path(pairs), path(idx) from pairs_chrSize_ch
output:
tuple id, path(pairs), path(idx), path("*.tsv") into pairs_ch_cooler, pairs_ch_juicer
script:
"""
pairix -H -f ${pairs} \
| awk -v OFS='\t' '/^#chromsize/ {print \$2,\$3}' \
| sort -V -k1,1 \
> chr_size.tsv
"""
}
process cooler_sort {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
input:
tuple id, path(pairs), path(idx), path(chr_sizes) from pairs_ch_cooler
output:
tuple id, path("*.pairs.sorted.txt.gz"), path("*pairs.sorted.txt.gz.px2"), path(chr_sizes) into sort_cload_ch
script:
"""
cooler csort \
-c1 2 -p1 3 -c2 4 -p2 5 \
-i pairix \
-p ${task.cpus} \
--out ${id}.pairs.sorted.txt.gz \
$pairs \
$chr_sizes
"""
}
process cooler_cload {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
input:
tuple id, path(pairs), path(idx), path(chr_sizes) from sort_cload_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}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${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}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${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}
"""
}
process juicer {
tag "_${id}"
cpus 24
memory '150 GB'
container 'mblanche/juicer'
publishDir "${outDir}/hicFiles",
mode: 'copy'
input:
tuple id, path(pairs), path(idx), path(chr_sizes) from pairs_ch_juicer
output:
tuple id, path("*.hic") into arrowhead_ch, hiccups_ch
script:
"""
java -Xmx96000m -Djava.awt.headless=true \
-jar /juicer_tools.jar pre \
--threads ${task.cpus} \
-j ${task.cpus} \
-k VC,VC_SQRT,KR,SCALE \
${pairs} \
${id}.hic \
${chr_sizes}
"""
}
if (!(params.capture|params.hichip)){
process arrowhead {
tag "_${id}"
cpus 12
memory '40 GB'
container "mblanche/juicer"
publishDir "${outDir}/arrowHead",
mode: 'copy'
input:
tuple id, path(hic), val(res) from arrowhead_ch
.combine(Channel.from(resolutions))
output:
tuple id, path("${id}_${res}kb") into arrowhead_out_ch
script:
bpRes = res.toInteger() * 1000
"""
mkdir -p ${id}_${res}kb && touch ${id}_${res}kb/${bpRes}_blocks.bedpe
java -Xmx24000m \
-jar /juicer_tools.jar \
arrowhead \
--threads ${task.cpus} \
--ignore-sparsity \
-r ${bpRes} \
-k KR \
${hic} \
${id}_${res}kb
"""
}
process hiccups {
tag "_${id}"
label 'gpu'
accelerator 1
cpus 6
memory '32 GB'
container "mblanche/hiccups-gpu"
publishDir "${outDir}/hiccups/",
mode: 'copy'
input:
tuple id, path(hic), val(res) from hiccups_ch
.combine(Channel.from(resolutions.collect{it*1000}.join(',')))
output:
tuple id, path("${id}_loops") into hiccups_out_ch
script:
"""
java -Xmx24000m \
-jar /juicer_tools.jar \
hiccups \
--threads ${task.cpus} \
--ignore-sparsity \
-m 500 \
-r ${res} \
-k KR \
${hic} \
${id}_loops
"""
}
process mustache {
tag "_${id}"
cpus 24
memory '48 GB'
container "mblanche/mustache"
publishDir "${outDir}/mustache",
mode: 'copy'
input:
tuple id, path(mcool), val(res) from mustache_mcool_ch
.combine(Channel.from(1000,4000,16000))
output:
tuple id, path("*.tsv") into mustache_2_merge_ch
script:
"""
touch ${id}_${res}kb_loops.tsv
mustache -p ${task.cpus} \
-f ${mcool} \
-r ${res} \
-o ${id}_${res}kb_loops.tsv
"""
}
process ABcomp {
tag "_${id}"
cpus 1
memory '12 GB'
container "mblanche/fan-c"
publishDir "${outDir}/AB_comp",
mode: 'copy'
input:
tuple id, path(cool), val(resKB) from abcomp_mcool_ch
.combine(Channel.from(ABresolutions))
path(genome) from abcomp_genome_ch.first()
output:
tuple id, path("*.bed"), path("*.ab") into fanc_out_ch
script:
res = resKB.toInteger() * 1000
"""
fanc compartments \
-f \
-v ${id}_eigenV_${resKB}kb.bed \
-d ${id}_AB_${resKB}kb.bed \
-g ${genome} \
${cool}@${res} \
${id}_${resKB}kb.ab
"""
}
}
*/