-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSRR_to_SNVlist.nf
372 lines (262 loc) · 8.32 KB
/
SRR_to_SNVlist.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
if(file(params.FASTQ_input).isFile()) {
SRRlist_paired = file(params.FASTQ_input).readLines()
SRRlist_single = file(params.FASTQ_input).readLines()
SRRnum = file(params.FASTQ_input).countLines();
FASTQ_files_paired = Channel.empty()
FASTQ_files_single = Channel.empty()
params.download = true
}else if(file(params.FASTQ_input).isDirectory()){
if(params.library_preparation == 'paired') {
FASTQ_files_paired = Channel.fromFilePairs("${params.FASTQ_input}/*_{1,2}.fastq*")
FASTQ_files_single = Channel.empty()
SRRnum = new File(params.FASTQ_input).listFiles().count { it.name ==~ /.*1\.fastq.*/ }
}else{
FASTQ_files_single = Channel.fromPath("${params.FASTQ_input}/*.fastq*")
FASTQ_files_paired = Channel.empty()
SRRnum = file(params.FASTQ_input).list()((d, name) -> name.contains(".fastq")).count()
}
params.download = false
SRRlist_paired = Channel.empty()
SRRlist_single = Channel.empty()
}else{
error "Wrong input: ${params.FASTQ_input}. It must be a .txt file with a SRR number on each line or a directory with the fastq files."
}
println """\
VirMutSig - Preprocess pipeline
================================
SRR from: ${params.FASTQ_input}
# of SRR: ${SRRnum}
Download: ${params.download}
Library layout: ${params.library_preparation} reads
Author: Davide Maspero
Mail: [email protected]
"""
.stripIndent()
genomeFAch = Channel.value(file(params.fasta))
process Generate_Ref_files {
storeDir "${genomeFA.toRealPath().getParent()}"
input:
path genomeFA from genomeFAch
output:
tuple path('*.fasta.amb'),
path('*.fasta.ann'),
path('*.fasta.bwt'),
path('*.fasta.fai'),
path('*.fasta.pac'),
path('*.fasta.sa') into genomeIndexed
"""
samtools faidx ${genomeFA} -o ${genomeFA}.fai
bwa index ${genomeFA}
"""
}
// ############## PAIRED READS ################
process FASTQs_download_paired {
storeDir params.FASTQdir
tag "${SRR}"
input:
val SRR from SRRlist_paired
output:
tuple val(SRR), path("${SRR}_*.fastq.gz") into FASTQ_paired
when:
params.library_preparation == 'paired' && params.download
"""
fastq-dump --split-files --gzip ${SRR}
"""
}
process Trimming_paired {
tag "${SRR}"
input:
tuple val(SRR), path(fastq_1_2) from FASTQ_paired.mix(FASTQ_files_paired)
output:
tuple val("${SRR}"),
path("${SRR}_1.trim.fastq.gz"),
path("${SRR}_2.trim.fastq.gz") into TRIMMED_paired
when:
params.library_preparation == 'paired'
"""
TrimmomaticPE -phred33 \
-threads ${task.cpus} \
-summary ${SRR}.trim.summary \
-quiet -validatePairs \
${fastq_1_2} \
${SRR}_1.trim.fastq.gz ${SRR}_1_unpaired.trim.fastq.gz \
${SRR}_2.trim.fastq.gz ${SRR}_2_unpaired.trim.fastq.gz \
${params.trimmomatic_setting}
"""
}
process Alignment_and_sorting_paired {
storeDir params.BAMdir
tag "${SRR}"
input:
path "genome.fasta" from genomeFAch
tuple path('genome.fasta.amb'),
path('genome.fasta.ann'),
path('genome.fasta.bwt'),
path('genome.fasta.fai'),
path('genome.fasta.pac'),
path('genome.fasta.sa') from genomeIndexed
tuple val(SRR), path(fastq_1), path(fastq_2) from TRIMMED_paired
output:
tuple val(SRR), path("${SRR}.sorted.bam") into SORTED_paired_depth, SORTED_paired_nodup, SORTED_paired_calling
when:
params.library_preparation == 'paired'
"""
bwa mem genome.fasta \
-t ${task.cpus} \
${fastq_1} ${fastq_2} \
| samtools sort -@${task.cpus} -o ${SRR}.sorted.bam
"""
}
// ############## SINGLE READS ################
process FASTQs_download_single {
storeDir params.FASTQdir
tag "${SRR}"
input:
val SRR from SRRlist_single
output:
path "${SRR}.fastq.gz" into FASTQ_single
when:
params.library_preparation == 'single' && params.download
"""
fastq-dump --gzip ${SRR}
"""
}
process Trimming_single {
tag "${fastq.simpleName}"
input:
path fastq from FASTQ_single.mix(FASTQ_files_single)
output:
tuple val("${fastq.simpleName}"),
path("${fastq.simpleName}.trim.fastq.gz") into TRIMMED_single
when:
params.library_preparation == 'single'
"""
TrimmomaticSE -phred33 \
-threads ${task.cpus} \
-summary ${fastq.simpleName}.trim.summary \
-quiet \
${fastq} \
${fastq.simpleName}.trim.fastq.gz \
${params.trimmomatic_setting}
"""
}
process Alignment_and_sorting_single {
storeDir params.BAMdir
tag "${SRR}"
input:
path "genome.fasta" from genomeFAch
tuple path('genome.fasta.amb'),
path('genome.fasta.ann'),
path('genome.fasta.bwt'),
path('genome.fasta.fai'),
path('genome.fasta.pac'),
path('genome.fasta.sa') from genomeIndexed
tuple val(SRR), path(fastq) from TRIMMED_single
output:
tuple val(SRR), path("${SRR}.sorted.bam") into SORTED_single_depth, SORTED_single_nodup, SORTED_single_calling
when:
params.library_preparation == 'single'
"""
bwa mem genome.fasta \
-t ${task.cpus} \
${fastq} \
| samtools sort -@${task.cpus} -o ${SRR}.sorted.bam
"""
}
// ######################################################
process Remove_duplicated_reads {
storeDir params.BAMdir
tag "${SRR}"
input:
tuple val(SRR), path(sorted_bam) from SORTED_paired_nodup.mix(SORTED_single_nodup)
output:
tuple val(SRR), path("${SRR}.nodup.sorted.bam") into NODUP_depth, NODUP_var_call
when:
params.remove_duplicates
"""
PicardCommandLine MarkDuplicates I=${sorted_bam} O=${SRR}.nodup.sorted.bam M=${SRR}.nodup.sorted.metrics.txt REMOVE_DUPLICATES=true
"""
}
process Extract_coverage_nodup {
storeDir params.COVERAGEdir
tag "${SRR}"
input:
tuple val(SRR), path(sorted_bam) from NODUP_depth
output:
path "${SRR}.depth.txt" into DEPTH_nodup
when:
params.remove_duplicates
"""
samtools index -b ${sorted_bam}
samtools depth -a ${sorted_bam} > ${SRR}.depth.txt
"""
}
process Extract_coverage {
storeDir params.COVERAGEdir
tag "${SRR}"
input:
tuple val(SRR), path(sorted_bam) from SORTED_paired_depth.mix(SORTED_single_depth)
output:
path "${SRR}.depth.txt" into DEPTH
when:
!params.remove_duplicates
"""
samtools index -b ${sorted_bam}
samtools depth -a ${sorted_bam} > ${SRR}.depth.txt
"""
}
process Variant_calling_nodup {
storeDir params.VCFdir
tag "${SRR}"
input:
tuple val(SRR), path(sorted_bam) from NODUP_var_call
path 'genome.fasta' from genomeFAch
tuple path('genome.fasta.amb'),
path('genome.fasta.ann'),
path('genome.fasta.bwt'),
path('genome.fasta.fai'),
path('genome.fasta.pac'),
path('genome.fasta.sa') from genomeIndexed
output:
path "${SRR}.vcf" into VCF_nodup
when:
params.remove_duplicates
"""
samtools mpileup -f genome.fasta ${sorted_bam} --output sample.mpileup
varscan pileup2snp sample.mpileup ${params.varscan} > ${SRR}.vcf
"""
}
process Variant_calling {
storeDir params.VCFdir
tag "${SRR}"
input:
tuple val(SRR), path(sorted_bam) from SORTED_paired_calling.mix(SORTED_single_calling)
path "genome.fasta" from genomeFAch
tuple path('genome.fasta.amb'),
path('genome.fasta.ann'),
path('genome.fasta.bwt'),
path('genome.fasta.fai'),
path('genome.fasta.pac'),
path('genome.fasta.sa') from genomeIndexed
output:
path "${SRR}.vcf" into VCF
when:
!params.remove_duplicates
"""
samtools mpileup -f genome.fasta ${sorted_bam} --output sample.mpileup
varscan pileup2snp sample.mpileup ${params.varscan} > ${SRR}.vcf
"""
}
process make_SNV_list {
publishDir params.SNVlistdir, mode:'move'
input:
path "genome.fasta" from genomeFAch
path VCFs from VCF.mix(VCF_nodup).collect()
path DEPTHs from DEPTH.mix(DEPTH_nodup).collect()
output:
path 'SNV_list.txt'
script:
"""
Rscript /VirMutSig/preprocessing/bin/makeSNVlist.R ./ ./ genome.fasta ${params.SNV_filters}
"""
}