-
Notifications
You must be signed in to change notification settings - Fork 0
/
bamNpairs2Juicer.nf
142 lines (113 loc) · 2.92 KB
/
bamNpairs2Juicer.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
#!/usr/bin/env nextflow
params.expDir = 'working'
params.expName = 'DHockemeyer_cellLine'
patt = 'CTTCCTTC'
Channel
.fromPath("/mnt/ebs/ref_push/${params.expDir}/${params.expName}/bam/*.bam")
.map { file -> tuple(file.name.toString().replaceFirst(/.bam/,''),file) }
.set{bam_ch}
Channel
.fromFilePairs("/mnt/ebs/ref_push/${params.expDir}/${params.expName}/coolerFiles/**.{valid.pairs.gz,valid.pairs.gz.px2}",flat: true)
.set{pairs_ch}
bam_ch
.join(pairs_ch)
.set{ch1}
process make_chr_size {
container 'mblanche/bwa-samtools'
input:
tuple val(id), path(bam), path(pairs), path(idx) from ch1
output:
tuple id, path('chr_size.tsv'), path(pairs), path(idx) into cooler_sort_ch, juicer_ch
script:
"""
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 cooler_sort {
echo true
tag "_${id}"
label "batch"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
input:
tuple id, path(chr_sizes), path(pairs), path(idx) from cooler_sort_ch
output:
tuple id, path(chr_sizes), path("*.gz"), path("*.px2") into pairs_ch_cooler
script:
"""
cooler csort \
-c1 2 -p1 3 -c2 4 -p2 5 \
-i pairix \
-p ${task.cpus} \
--out ${id}_sorted.valid.pairs.gz \
${pairs} \
${chr_sizes}
"""
}
process cooler_cload {
echo true
tag "_${id}"
label "batch"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${HOME}/ebs/ref_push/${params.expDir}/${params.expName}/coolerFiles/${id}",
mode: 'copy'
input:
tuple id, path(chr_sizes), path(pairs), path(idx) from pairs_ch_cooler
output:
tuple id, path("*.cool") into cooler_ch
script:
"""
cooler cload pairix \
-p ${task.cpus} \
${chr_sizes}:1000 \
${pairs} \
${id}.cool
"""
}
process cooler_zoomify {
tag "_${id}"
label "batch"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${HOME}/ebs/ref_push/${params.expDir}/${params.expName}/coolerFiles/${id}",
mode: 'copy'
input:
tuple id, path(cooler) from cooler_ch
output:
path "*.mcool" into mcool_ch
script:
"""
cooler zoomify --balance -p ${task.cpus} ${cooler}
"""
}
process juicer {
tag "_${id}"
label "batch"
cpus 24
memory '24 GB'
container 'mblanche/juicer'
publishDir "${HOME}/ebs/ref_push/${params.expDir}/${params.expName}/hicFiles",
mode: 'copy'
input:
tuple id, path(chr_sizes), path(pairs), path(idx) from juicer_ch
output:
path "*.hic" into juicer_out_ch
script:
"""
java -Xmx24000m -Djava.awt.headless=true \
-jar /juicer_tools_1.22.01.jar pre \
--threads ${task.cpus} \
-j ${task.cpus} \
-k VC,VC_SQRT,KR,SCALE \
${pairs} \
${id}.hic \
${chr_sizes}
"""
}