-
Notifications
You must be signed in to change notification settings - Fork 0
/
procs.nf
executable file
·264 lines (212 loc) · 5.04 KB
/
procs.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
process fastqc {
input:
path(fastq)
val(tag)
output:
path("*.zip"), emit: zips
path("*.html"), emit: htmls
script:
"""
fastqc --nogroup ${fastq}
"""
}
process multiqc {
input:
path(files)
val(tag)
output:
path("*.html")
script:
"""
multiqc . --title "${tag} Report" --filename "${tag}_multiqc.html"
"""
}
process trim {
input:
tuple val(id), path(fastqs)
output:
tuple val(id), path('*_trimmed_R{1,2}.fq.gz'), emit: trimmed_pairs // for subsequent mapping, etc
path('*.gz'), emit: trimmed_fastqs // for fastqc
path('*.txt'), emit: reports // for multiqc
script:
"""
cutadapt \
--cores 4 \
--error-rate 0.1 \
--overlap 1 \
--quality-cutoff 20 \
--trim-n \
--minimum-length 20 \
-n 7 \
-a AGATCGGAAGAGC \
-A AGATCGGAAGAGC \
-o ${id}_trimmed_R1.fq.gz -p ${id}_trimmed_R2.fq.gz \
${fastqs[0]} ${fastqs[1]} > ${id}_trimming_report.txt
"""
}
process align {
input:
tuple val(id), path(fastqs)
path(ref)
output:
tuple val(id), path("*.bam")
script:
ref = params.ref.(params.genome)
"""
biscuit align -@ 14 ${ref} ${fastqs[0]} ${fastqs[1]} | samblaster | samtools sort -O BAM -o ${id}.bam -
"""
}
process index {
input:
tuple val(id), path(bam)
val(tag)
output:
tuple val(id), path('*.bam', includeInputs: true), path("*.bai")
script:
"""
samtools index -@ 4 ${bam}
"""
}
process bsconv {
input:
tuple val(id), path(bam), path(bai)
path(ref)
output:
tuple val(id), path("*_bsconv-cph-filter.bam")
script:
ref = params.ref.(params.genome)
"""
biscuit bsconv -f ${params.bsconv_filter} ${ref} ${bam} ${id}_bsconv-cph-filter.bam
"""
}
process stats {
input:
tuple val(id), path(bam), path(index)
path(ref)
output:
path("*.txt")
script:
ref = params.ref.(params.genome)
"""
samtools stats -@ 2 -r ${ref} ${bam} > ${id}_stats.txt
"""
}
process filter_bam {
input:
tuple val(id), path(bam), path(bai)
path(bed_file)
output:
tuple val(id), path("*.bam"), path("*.bai")
script:
"""
samtools view --write-index -hb -L ${bed_file} ${bam} -o ${id}_filtered.bam##idx##${id}_filtered.bam.bai
"""
}
process pileup {
input:
tuple val(id), path(bam), path(bai)
path(ref)
output:
tuple val(id), path("*_pileup.vcf.gz")
script:
ref = params.ref.(params.genome)
"""
biscuit pileup -@ 4 ${ref} ${bam} | bgzip -f > ${id}_pileup.vcf.gz
"""
}
process tabix_vcf {
input:
tuple val(id), path(vcf)
output:
tuple val(id), path("*.vcf.gz", includeInputs: true), path("*.tbi")
script:
"""
tabix -p vcf ${vcf}
"""
}
process vcf2bed {
input:
tuple val(id), path(vcf), path(tbi)
output:
tuple val(id), path("*.bed.gz")
script:
"""
biscuit vcf2bed -k 1 -t cg -s ALL ${vcf} | bgzip > ${id}_pileup.bed.gz
"""
}
process tabix_bed {
input:
tuple val(id), path(bed)
output:
tuple val(id), path("*.bed.gz", includeInputs: true), path("*.tbi")
script:
"""
tabix -p bed ${bed}
"""
}
process mergecg {
input:
tuple val(id), path(bed), path(tbi)
path(ref)
output:
tuple val(id), path("*.bed.gz")
script:
ref = params.ref.(params.genome)
"""
biscuit mergecg ${params.ref} ${bed} | bgzip > ${id}_pileup_mergecg.bed.gz
"""
}
process biscuiteer {
input:
tuple val(id), path(bed), path(bed_tbi), path (vcf), path(vcf_tbi)
output:
tuple val(id), path("*.rds")
script:
"""
#!/usr/bin/env Rscript --vanilla
library(biscuiteer)
bisc <- readBiscuit(BEDfile = "${bed}", VCFfile = "${vcf}", merged = T, genome = "${params.genome}", sparse = T)
saveRDS(bisc, file = "${id}.rds", compress = F)
"""
}
process biscuit_qc {
input:
tuple val(id), path(bam), path(bai), path(vcf)
path(ref)
path(assets)
output:
path("*.txt")
script:
ref = params.ref.(params.genome)
assets = params.bqc_assets.(params.genome)
"""
${params.bqc_path} -o . -v ${vcf} ${assets} ${ref} ${id} ${bam}
"""
}
process bamtobed {
input:
tuple val(id), path(bam), path(bai)
output:
tuple val(id), path("*.bed")
script:
"""
bedtools bamtobed -i ${bam} | LC_ALL=C sort -k1,1 -k2,2n | cut -f1-3 > ${id}.bed
"""
}
process preseq {
input:
tuple val(id), path(bed)
output:
path("*.tsv")
script:
defects = ["", "-defects", "-defects -Q"][task.attempt - 1]
// defects = "-defects -Q"
"""
preseq gc_extrap \
-o preseq_gc-extrap_${id}.tsv \
-e 3E9 \
-s 10E6 \
-bed \
${defects} ${bed}
"""
}