-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
202 lines (167 loc) · 3.98 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
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
#!/usr/bin/env nextflow
params.sampleSheet = ""
params.gbzIndex = ""
params.minIndex = ""
params.distIndex = ""
params.refFasta = ""
params.refPath = ""
process GET_REF_PATHS {
input:
path("index.gbz")
val(refPath)
output:
path("ref_paths.txt")
"""
vg paths -x index.gbz -S $refPath -L > ref_paths.txt
"""
}
process SNARLS {
input:
path("index.gbz")
output:
path("index.snarls")
"""
vg snarls \
-t $task.cpus \
index.gbz \
> index.snarls
"""
}
process GIRAFFE {
input:
path(gbzIndex)
path(minIndex)
path(distIndex)
tuple val(sample), path(r1), path(r2)
output:
tuple val(sample), path("${sample}.gaf.gz")
"""
cp $distIndex local.dist
vg giraffe -t $task.cpus -p \
-Z $gbzIndex \
-m $minIndex \
-d local.dist \
-f $r1 -f $r2 \
-N $sample -R $sample \
-o gaf \
| gzip > ${sample}.gaf.gz
"""
}
process MERGE_GAFS {
input:
tuple val(sample), path(allGafs, stageAs: "?/*")
output:
tuple val(sample), path("${sample}_merged.gaf.gz")
shell:
def gafsString = allGafs instanceof List ? allGafs.join(" ") : allGafs
"""
cat $gafsString > ${sample}_merged.gaf.gz
"""
}
process PACK {
input:
path(gbzIndex)
tuple val(sample), path("${sample}.gaf.gz")
output:
tuple val(sample), path("${sample}.pack")
"""
vg pack \
-x $gbzIndex \
-a ${sample}.gaf.gz \
-o ${sample}.pack \
-Q 5 \
-s 5 \
-t $task.cpus
"""
}
process CALL {
input:
path(gbzIndex)
path(refPaths)
path(snarls)
tuple val(sample), path("${sample}.pack")
output:
tuple val(sample), path("${sample}.vcf")
"""
ref_path_args=""
while read path; do
ref_paths_args+="-p \$path "
done < $refPaths
vg call \
$gbzIndex \
-a \
-k ${sample}.pack \
-r $snarls \
-s ${sample} \
-t ${task.cpus} \
\$ref_paths_args \
> ${sample}.vcf
"""
}
process NORM {
input:
path(refFasta)
val(refPath)
tuple val(sample), path(inVcf)
output:
path("${sample}.norm.vcf.gz")
"""
bcftools head $inVcf | awk '{
if (/^##contig/) {
if (/$refPath/) {
sub(/ID=${refPath}#0#/, "ID=", \$0)
print
}
} else print}' > new_header.txt
bcftools reheader -h new_header.txt $inVcf \
| bcftools view -f.,PASS - \
| bcftools norm -f $refFasta - \
| bcftools sort -T . -m ${task.memory.giga * 0.6}G - \
| bgzip > ${sample}.norm.vcf.gz
"""
}
process MERGE_VCFS {
input:
path(allVcfs)
output:
path("merged.vcf.gz")
"""
for vcf in $allVcfs; do
bcftools index \$vcf
done
bcftools merge $allVcfs | bgzip > merged.vcf.gz
"""
}
workflow {
gbzIndex = file(params.gbzIndex)
minIndex = file(params.minIndex)
distIndex = file(params.distIndex)
refFasta = file(params.refFasta)
GET_REF_PATHS(gbzIndex, params.refPath)
Channel.fromPath(params.sampleSheet)
.splitCsv(header: true)
.map { row -> tuple(
row.sample_id,
file(row.r1),
file(row.r2)
) }
.set { reads }
reads
.map { tuple(it[0], 1) }
.groupTuple()
.map { tuple(it[0], it[1].sum()) }
.set { sampleLibraryCounts }
SNARLS(gbzIndex)
GIRAFFE(gbzIndex, minIndex, distIndex, reads)
sampleLibraryCounts
.cross(GIRAFFE.out)
.map { tuple(
groupKey(it[0][0], it[0][1]),
it[1][1]
) }
.groupTuple() | MERGE_GAFS
PACK(gbzIndex, MERGE_GAFS.out)
CALL(gbzIndex, GET_REF_PATHS.out, SNARLS.out, PACK.out)
NORM(refFasta, params.refPath, CALL.out)
MERGE_VCFS(NORM.out.collect())
}