-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
293 lines (227 loc) · 7.33 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
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
process COLLECT_BASECALLED {
tag "COLLECT_BASECALLED on $sample.name using $task.cpus CPUs and $task.memory memory"
label "small_process"
input:
val(sample)
output:
tuple val(sample), path("*.fastq.gz")
script:
"""
echo COLLECT_BASECALLED $sample.name
cp /mnt/share/710000-CEITEC/713000-cmm/713003-pospisilova/base/sequencing_results/primary_data/*${sample.run}/raw_fastq/${sample.name}* ./
"""
}
process TRIMMING {
tag "trimming on $sample.name using $task.cpus CPUs and $task.memory memory"
label "small_process"
input:
tuple val(sample), path(reads)
output:
tuple val(sample), path("*.fastq.gz")
script:
"""
cutadapt -m 50 -o ${sample.name}.trimmed.R1.fastq.gz -p ${sample.name}.trimmed.R2.fastq.gz $reads
"""
}
process FIRST_ALIGN_BAM {
tag "first align on $sample.name using $task.cpus CPUs and $task.memory memory"
publishDir "${params.outDirectory}/${sample.run}/mapped/", mode:'copy'
label "medium_cpu"
label "large_mem"
input:
tuple val(sample), path(reads)
output:
tuple val(sample), path("${sample.name}.sorted.bam")
tuple val(sample), path("${sample.name}.sorted.bai")
script:
rg = "\"@RG\\tID:${sample.name}\\tSM:${sample.name}\\tLB:${sample.name}\\tPL:ILLUMINA\""
"""
bwa mem -R ${rg} -t 4 ${params.refindex} $reads \
| samtools view -Sb -o - - | samtools sort -o ${sample.name}.sorted.bam
samtools index ${sample.name}.sorted.bam ${sample.name}.sorted.bai
"""
}
process FIRST_QC {
tag "first QC on $sample.name using $task.cpus CPUs and $task.memory memory"
label "smallest_process"
container 'registry.gitlab.ics.muni.cz:443/450402/btk_k8s:16'
input:
tuple val(sample), path(bam)
output:
path "*"
script:
"""
samtools flagstat $bam > ${sample.name}.flagstat
samtools stats $bam > ${sample.name}.samstats
picard BedToIntervalList I=${params.covbed} O=${sample.name}.interval_list SD=${params.ref}.dict
picard CollectHsMetrics I=$bam BAIT_INTERVALS=${sample.name}.interval_list TARGET_INTERVALS=${sample.name}.interval_list R=${params.ref}.fasta O=${sample.name}.aln_metrics
"""
}
process MARK_DUPLICATES {
tag "Mark duplicates on $sample.name using $task.cpus CPUs and $task.memory memory"
label "small_process"
input:
tuple val(sample), path(bam)
output:
path "*.txt"
tuple val(sample), path("*first.md.bam")
path "*.bai"
script:
"""
picard MarkDuplicates I=$bam M=${sample.name}.MD.metrics.txt O=${sample.name}.first.md.bam
samtools index ${sample.name}.first.md.bam
"""
}
process MULTIQC {
tag "MultiQC using $task.cpus CPUs and $task.memory memory"
publishDir "${params.outDirectory}/multiqc_reports/", mode:'copy'
label "smallest_process"
container "staphb/multiqc:1.19"
// container 'registry.gitlab.ics.muni.cz:443/450402/tp53_nf:5'
input:
path '*'
output:
path '*.html'
script:
"""
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
multiqc . -n MultiQC-"`date +"%d-%m-%Y"`".html
"""
}
process MUTECT2 {
tag "MUTECT2 on $sample.name using $task.cpus CPUs and $task.memory memory"
input:
tuple val(sample), path(bam)
output:
tuple val(sample), path ('*.vcf')
path '*'
script:
"""
gatk Mutect2 --reference ${params.ref}.fasta --input ${bam} --annotation StrandArtifact --min-base-quality-score 10 --intervals $params.covbed -bamout ${sample.name}.bamout.bam --output ${sample.name}.mutect.vcf
"""
}
process FILTER_MUTECT {
tag "filter mutect on $sample.name using $task.cpus CPUs and $task.memory memory"
label "smallest_process"
input:
tuple val(sample), path(vcf_input)
output:
tuple val(sample), path ('*.vcf')
script:
"""
gatk FilterMutectCalls -V $vcf_input -O ${sample.name}.mutect.filt.vcf
"""
}
process NORMALIZE_MUTECT {
tag "normalize filtered mutect on $sample.name using $task.cpus CPUs $task.memory"
label "smallest_process"
input:
tuple val(sample), path(vcf_input)
output:
tuple val(sample), path ('*.vcf')
script:
"""
bcftools norm -m-both $vcf_input > ${sample.name}.mutect.filt.norm.vcf
"""
}
process ANNOTATE_MUTECT {
tag "annotate mutect on $sample.name using $task.cpus CPUs $task.memory"
container "ensemblorg/ensembl-vep:release_108.0"
publishDir "${params.outDirectory}/${sample.run}/variants/", mode:'copy'
label "smallest_process"
input:
tuple val(sample), path(vcf_input)
output:
tuple val(sample), path('*.vcf')
script:
"""
vep -i $vcf_input --cache --cache_version 108 --dir_cache $params.vep \
--fasta ${params.ref}.fasta --merged --mane_select --offline --vcf --everything -o ${sample.name}.mutect2.filt.norm.vep.vcf
"""
}
process JOIN_VARS_TO_FILE {
tag "JOIN_VARS_TO_FILE using $task.cpus CPUs $task.memory"
publishDir "${params.variantsDBdir}/", mode:'copy'
label "smallest_process"
input:
path "VcfsToMerge"
output:
path "DB.bed"
script:
"""
for vcf_file in $VcfsToMerge; do bcftools query -f '%CHROM\\t%POS\\t%REF\\t%ALT[\\t%SAMPLE]\\n' "\$vcf_file" >> temp.bed; done
awk '!seen[\$0]++' temp.bed ${params.variantsDBdir}/DB.bed >> DB.bed
# make sure there are no duplicates
"""
}
process CREATE_FULL_TABLE {
tag "creating full table on $sample.name using $task.cpus CPUs $task.memory"
publishDir "${params.outDirectory}/${sample.run}/create_full_table/", mode:'copy'
label "smallest_process"
input:
tuple val(sample), path(vcf_input)
output:
tuple val(sample), path("${sample.name}.mutect2.filt.norm.vep.full.csv")
script:
"""
python $params.vcftbl simple --build GRCh38 -i $vcf_input -t ${sample.name} -o ${sample.name}.mutect2.filt.norm.vep.full.csv
"""
}
process ALTER_FULL_TABLE {
tag "ALTER_FULL_TABLE on $sample.name using $task.cpus CPUs $task.memory"
publishDir "${params.outDirectory}/${sample.run}/variants/", mode:'copy'
label "smallest_process"
input:
tuple val(sample), path(variantsTableCsv), path(joinedTsv)//, val(ntotal)
output:
tuple val(sample), path("${sample.name}.final.csv")
script:
"""
echo alter full table on $sample.name
python ${params.mergetables} --table $variantsTableCsv --varlist $joinedTsv --outname ${sample.name}.final.csv
"""
}
process COVERAGE {
tag "calculating coverage on $sample.name using $task.cpus CPUs $task.memory"
publishDir "${params.outDirectory}/${sample.run}/coverage/", mode:'copy'
input:
tuple val(sample), path(bam)
output:
tuple val(sample), path('*.PBcov.txt')
script:
"""
bedtools coverage -abam $params.covbed -b $bam -d > ${sample.name}.PBcov.txt
"""
}
process COVERAGE_R {
tag "R coverage on $sample.name using $task.cpus CPUs $task.memory"
publishDir "${params.outDirectory}/${sample.run}/coverage/", mode:'copy'
label "smallest_process"
input:
tuple val(sample), path(pbcov)
script:
"""
Rscript --vanilla $params.coverstat $pbcov ${params.outDirectory}/${sample.run}/coverage/${sample.name}.perexon_stat.txt
"""
}
workflow {
runlist = channel.fromList(params.samples)
rawfastq = COLLECT_BASECALLED(runlist)
trimmed = TRIMMING(rawfastq)
sortedbam = FIRST_ALIGN_BAM(trimmed)
qc_files = FIRST_QC(sortedbam[0])
qcdup_file = MARK_DUPLICATES(sortedbam[0])
MULTIQC(qc_files.collect())
raw_vcf = MUTECT2(qcdup_file[1]) //markdup.bam
filtered = FILTER_MUTECT(raw_vcf[0])
normalized = NORMALIZE_MUTECT(filtered)
annotated = ANNOTATE_MUTECT(normalized)
full_table = CREATE_FULL_TABLE(annotated)
Vcf_paths = normalized.map({it -> [it[1]]})
Vcf_paths_collected = Vcf_paths.collect()
joined_vars = JOIN_VARS_TO_FILE(Vcf_paths_collected)
ALTER_FULL_TABLE(full_table.combine(joined_vars))
pbcov = COVERAGE(sortedbam[0])
COVERAGE_R(pbcov)
}