-
Notifications
You must be signed in to change notification settings - Fork 0
/
MutationCall_RNA_pipe.nf
executable file
·314 lines (225 loc) · 8.42 KB
/
MutationCall_RNA_pipe.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
#!/usr/bin/env nextflow
params.bam = ''
params.ref = ''
params.known = ''
sequences = Channel.fromPath( params.bam ).map { file -> tuple(file.baseName, file) }
sequencesintomutationalcalling = Channel.fromPath( params.bam ).map { file -> tuple(file.baseName, file) } // You cannot use the same input twice in a channel, therefore we are copying it in twice
ref_index = file(params.ref)
ref_known = file(params.known)
params.outdir = ''
//Something is of with the transfer of the files
//----------------------Samtools-------------------------------
process run_samtools {
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
module 'samtools/1.9'
input:
set file_ID, file(bamfile) from sequences
output:
set file_ID, "${file_ID}.*" into samtools_out
script:
"""
samtools index ${bamfile}
samtools flagstat ${bamfile} > ${file_ID}.flagstat
samtools idxstats ${bamfile} > ${file_ID}.idxstat
"""
}
//----------------------AddReadsGroups-------------------------------
process run_addingReadsGroups {
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(bamfile) from sequencesintomutationalcalling
output:
set file_ID, "${file_ID}.With_RG.bam", "${file_ID}.With_RG.bai" into rg_out
script:
"""
java -jar /apps/bio/apps/picard/2.1.0/picard.jar AddOrReplaceReadGroups I=${bamfile} O=${file_ID}.With_RG.bam SORT_ORDER=coordinate RGID=${file_ID} RGLB=${file_ID} RGPL=illumina RGPU=${file_ID} RGSM=${file_ID} CREATE_INDEX=True
"""
}
//----------------------RemovePCRduplicates-------------------------------
process runRemovePCRdup {
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(rgbam), file(rgbai) from rg_out
output:
set file_ID, "${file_ID}.rmdup.bam","${file_ID}.rmdup.bai" into rmdup_out
script:
"""
java -Xmx4g -jar /apps/bio/apps/picard/2.1.0/picard.jar MarkDuplicates I=${rgbam} O=${file_ID}.rmdup.bam CREATE_INDEX=True M=${file_ID}.marked_dup_metrics.txt
"""
}
//----------------------SplitNCigar-------------------------------
// SplitNcigar is important when having RNA seq data
// Important to Note is that this is extremely memory consuming. Run it with many cores on your largest node!
process runSplitNCigar {
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 10'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(rdupbam), file(rdupbai) from rmdup_out
output:
set file_ID, "${file_ID}.Split.bam" into split_bam1, split_bam2
script:
"""
java -Xmx50g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T SplitNCigarReads -R ${ref_index} -I ${rdupbam} -o ${file_ID}.Split.bam -rf ReassignOneMappingQuality -RMQF 255 -RMQT 60 -U ALLOW_N_CIGAR_READS
"""
}
//----------------------RealignTargetCreator-------------------------------
process run_realignTargetCreator {
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 4'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(splitbam) from split_bam1
output:
set file_ID, "${file_ID}.intervals" into intervals
script:
"""
/apps/bio/apps/samtools/1.6/samtools index ${splitbam}
java -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T RealignerTargetCreator -I ${splitbam} -o ${file_ID}.intervals -R ${ref_index} --known ${ref_known}
"""
}
//----------------------IndelRealignment-------------------------------
process run_indelrealigner{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 4'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(interval) from intervals
set file_ID, file(splitbam) from split_bam2
output:
set file_ID, "${file_ID}.realigned.bam" into realigned1, realigned2
script:
"""
/apps/bio/apps/samtools/1.6/samtools index ${splitbam}
java -Xmx10g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T IndelRealigner -R ${ref_index} --targetIntervals ${interval} -known ${ref_known} -I ${splitbam} -o ${file_ID}.realigned.bam
"""
}
//----------------------BaseRecalibration-------------------------------
process run_baserecalibrat{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(realbam) from realigned1
output:
set file_ID, "${file_ID}.grp" into grps
script:
"""
/apps/bio/apps/samtools/1.6/samtools index ${realbam}
java -Xmx10g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T BaseRecalibrator -R ${ref_index} -knownSites ${ref_known} -I ${realbam} -o ${file_ID}.grp
"""
}
//----------------------PrintReads-------------------------------
process run_PrintReads{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(group) from grps
set file_ID, file(realbam) from realigned2
output:
set file_ID, "${file_ID}.recal.bam" into recal
script:
"""
/apps/bio/apps/samtools/1.6/samtools index ${realbam}
java -Xmx4g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T PrintReads -R ${ref_index} -I ${realbam} -BQSR ${group} -o ${file_ID}.recal.bam
"""
}
//----------------------SNPCalling-------------------------------
process run_SNPcalling{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(recalbam) from recal
output:
set file_ID, "${file_ID}.vcf" into rawsnps
script:
"""
/apps/bio/apps/samtools/1.6/samtools index ${recalbam}
java -Xmx4g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T HaplotypeCaller -R ${ref_index} -I ${recalbam} -o ${file_ID}.vcf
"""
}
//----------------------HardFilter-------------------------------
process run_HardFilter{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(unfilteredvcf) from rawsnps
output:
set file_ID, "${file_ID}.flag.vcf" into hardfilteredsnps
script:
"""
java -Xmx4g -jar /apps/bio/apps/gatk/3.5/GenomeAnalysisTK.jar -T VariantFiltration -R ${ref_index} --variant ${unfilteredvcf} -o ${file_ID}.flag.vcf --filterExpression "DP < 50" --filterName "LowDP" --filterExpression "QD < 2.0" --filterName "QD" --filterExpression "MQ < 40.0" --filterName "MQ"
"""
}
//----------------------PassedHardFilter-------------------------------
process run_greppassed{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(filteredvcf) from hardfilteredsnps
output:
set file_ID, "${file_ID}.Passed.vcf" into passedfilteredsnps
script:
"""
grep -E '^#|PASS' ${filteredvcf} > ${file_ID}.Passed.vcf
"""
}
//----------------------SortingVCF-------------------------------
process run_sortVCF{
publishDir params.outdir, mode: 'copy', overwrite: true
//errorStrategy 'ignore'
clusterOptions='-pe mpi 1'
executor 'sge'
queue '[email protected]'
queue '[email protected]'
input:
set file_ID, file(passedvcf) from passedfilteredsnps
output:
set file_ID, "${file_ID}.Sorted.vcf" into sortedvcf
script:
"""
java -jar /apps/bio/apps/picard/2.1.0/picard.jar SortVcf I=${passedvcf} O=${file_ID}.Sorted.vcf
"""
}