forked from elixir-no-nels/Selma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
341 lines (322 loc) · 11.2 KB
/
Snakefile
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
#SAMPLES = ['L001','L002','L003','L004','L005','L006','L007','L008']
SAMPLES = ['Sample1']
INTERVALS = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
CONTIGS = [1,2,3,4,5,6,7,8,9,10,11,12,13]
GATHERCONTIGS = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
rule all:
input:
expand("intervals/16-lists/{directory}_of_16/scattered.bed", directory=INTERVALS),
expand("intervals/bed-contigs/{contigs}_of_13/scattered.bed", contigs=CONTIGS),
"Outputs/ApplyVqsrSnp/SnpApplyVQSR.g.vcf.gz",
"Outputs/ApplyVqsrIndel/IndelApplyVQSR.g.vcf.gz",
rule BwaMem:
input:
fasta = "/references/Homo_sapiens_assembly38.fasta",
read1 = "fastq/{sample}.R1.fastq.gz",
read2 = "fastq/{sample}.R2.fastq.gz",
output:
"Outputs/BwaMem/{sample}_mapped.bam",
priority: 3
threads: 12
shell:
"bwa mem -M -t 12 {input.fasta} {input.read1} {input.read2} | samtools view -Sb - > {output}"
rule FastqtoSam:
input:
fasta = "/references/Homo_sapiens_assembly38.fasta",
read1 = "fastq/{sample}.R1.fastq.gz",
read2 = "fastq/{sample}.R2.fastq.gz",
output:
bam = "Outputs/FastqToSam/{sample}_unmapped.bam",
tmp = "Outputs/FastqToSam/{sample}_tmp",
priority: 2
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
FastqToSam \
--FASTQ {input.read1} \
--FASTQ2 {input.read2} \
-O {output.bam} \
--SAMPLE_NAME Sample1 \
--READ_GROUP_NAME RGname \
--LIBRARY_NAME Lib-1 \
--PLATFORM ILLUMINA \
--TMP_DIR {output.tmp}"
rule MergeBamAlignment:
input:
fasta = "/references/Homo_sapiens_assembly38.fasta",
unmapped = "Outputs/FastqToSam/{sample}_unmapped.bam",
mapped = "Outputs/BwaMem/{sample}_mapped.bam"
output:
bam = "Outputs/MergeBamAlignment/{sample}_merged.bam",
tmp = "Outputs/MergeBamAlignment/{sample}_tmp",
priority: 1
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
MergeBamAlignment \
--VALIDATION_STRINGENCY SILENT \
--EXPECTED_ORIENTATIONS FR \
--ATTRIBUTES_TO_RETAIN X0 \
--ALIGNED_BAM {input.mapped} \
--UNMAPPED_BAM {input.unmapped} \
-O {output.bam} \
--REFERENCE_SEQUENCE {input.fasta} \
--SORT_ORDER coordinate \
--IS_BISULFITE_SEQUENCE false \
--ALIGNED_READS_ONLY false \
--CLIP_ADAPTERS false \
--MAX_RECORDS_IN_RAM 200000 \
--ADD_MATE_CIGAR true \
--MAX_INSERTIONS_OR_DELETIONS -1 \
--PRIMARY_ALIGNMENT_STRATEGY MostDistant \
--PROGRAM_RECORD_ID 'bwamem' \
--PROGRAM_GROUP_VERSION '0.7.12-r1039' \
--PROGRAM_GROUP_COMMAND_LINE 'bwa mem -t 18 -R -M Input1 Input2 > output.sam' \
--PROGRAM_GROUP_NAME 'bwamem' \
--TMP_DIR {output.tmp}"
rule MarkDup:
input:
expand("Outputs/MergeBamAlignment/{sample}_merged.bam", sample=SAMPLES)
output:
"Outputs/MarkDuplicates/markedDuplicates.bam",
run:
INPUTS = " ".join(["--INPUT {}".format(x) for x in input])
shell("gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
MarkDuplicates \
{INPUTS} \
-O Outputs/MarkDuplicates/markedDuplicates.bam \
--VALIDATION_STRINGENCY LENIENT \
--METRICS_FILE Outputs/MarkDuplicates/markedDuplicates.metrics \
--MAX_FILE_HANDLES_FOR_READ_ENDS_MAP 200000 \
--CREATE_INDEX true \
--TMP_DIR Outputs/MarkDuplicates/tmp".format(INPUTS=INPUTS))
rule BaseRecalibrator:
input:
bam = "Outputs/MarkDuplicates/markedDuplicates.bam",
fasta = "/references/Homo_sapiens_assembly38.fasta",
dbsnp = "/references/dbsnp_146.hg38.vcf.gz",
v1000g = "/references/1000G_phase1.snps.high_confidence.hg38.vcf.gz",
mills = "/references/Mills_and_1000G_gold_standard.indels.hg38.vcf.gz",
contigs = "intervals/bed-contigs/{contigs}_of_13/scattered.bed",
output:
grp = "Outputs/BaseRecalibrator/BQSR_{contigs}.grp",
# threads: 2
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
BaseRecalibrator \
--reference {input.fasta} \
--input {input.bam} \
-O {output.grp} \
--known-sites {input.dbsnp} \
--known-sites {input.v1000g} \
--known-sites {input.mills} \
--intervals {input.contigs} \
--tmp-dir Outputs/BaseRecalibrator/"
rule GatherBQSR:
input:
expand("Outputs/BaseRecalibrator/BQSR_{directory}.grp", directory=CONTIGS),
output:
"Outputs/GatherBQSR/GatheredBQSR.grp"
run:
INPUTS = " ".join(["--input {}".format(x) for x in input])
shell("gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
GatherBQSRReports \
{INPUTS} \
-O Outputs/GatherBQSR/GatheredBQSR.grp".format(INPUTS=INPUTS))
rule ApplyBQSR:
input:
bam = "Outputs/MarkDuplicates/markedDuplicates.bam",
grp = "Outputs/GatherBQSR/GatheredBQSR.grp",
fasta = "/references/Homo_sapiens_assembly38.fasta",
contigs = "intervals/bed-contigs/{contigs}_of_13/scattered.bed",
output:
bam = "Outputs/ApplyBQSR/{contigs}_recalibrated.bam",
# threads: 2
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
ApplyBQSR \
--reference {input.fasta} \
--input {input.bam} \
-O {output.bam} \
--create-output-bam-index true \
-bqsr {input.grp} \
--intervals {input.contigs} \
--tmp-dir Outputs/ApplyBQSR/"
rule ApplyBQSRunmapped:
input:
bam = "Outputs/MarkDuplicates/markedDuplicates.bam",
grp = "Outputs/GatherBQSR/GatheredBQSR.grp",
fasta = "/references/Homo_sapiens_assembly38.fasta",
output:
bam = "Outputs/ApplyBQSR/14_recalibrated.bam",
priority: 1
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
ApplyBQSR \
--reference {input.fasta} \
--input {input.bam} \
-O {output.bam} \
--create-output-bam-index true \
-bqsr {input.grp} \
--intervals unmapped \
--tmp-dir Outputs/ApplyBQSR/"
rule GatherBamFiles:
input:
expand("Outputs/ApplyBQSR/{directory}_recalibrated.bam", directory=GATHERCONTIGS),
output:
"Outputs/GatherBamFiles/GatheredBamFiles.bam"
run:
INPUTS = " ".join(["--INPUT {}".format(x) for x in input])
shell("gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
GatherBamFiles \
{INPUTS} \
-O Outputs/GatherBamFiles/GatheredBamFiles.bam \
--CREATE_INDEX true".format(INPUTS=INPUTS))
rule HaplotypeCaller:
input:
bam = "Outputs/GatherBamFiles/GatheredBamFiles.bam",
fasta = "/references/Homo_sapiens_assembly38.fasta",
intervals = "intervals/16-lists/{directory}_of_16/scattered.bed",
output:
vcf = "Outputs/HaplotypeCaller/{directory}_rawVariants.g.vcf.gz",
threads: 1
shell:
"gatk --java-options '-Xmx3500M -Djava.io.tempdir=`pwd`/tmp' \
HaplotypeCaller \
-R {input.fasta} \
-O {output.vcf} \
-I {input.bam} \
-L {input.intervals} \
--use-new-qual-calculator \
--native-pair-hmm-threads 1 \
-ERC GVCF \
--tmp-dir Outputs/HaplotypeCaller/"
rule GatherVCFs:
input:
expand("Outputs/HaplotypeCaller/{directory}_rawVariants.g.vcf.gz", directory=INTERVALS)
output:
"Outputs/GatherVCFs/GatheredVCFs.g.vcf.gz",
run:
INPUTS = " ".join(["--INPUT {}".format(x) for x in input])
shell("gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
MergeVcfs \
{INPUTS} \
-O Outputs/GatherVCFs/GatheredVCFs.g.vcf.gz \
--CREATE_INDEX true".format(INPUTS=INPUTS))
rule GenotypeGVCFs:
input:
vcf = "Outputs/GatherVCFs/GatheredVCFs.g.vcf.gz",
fasta = "/references/Homo_sapiens_assembly38.fasta",
intervals = "intervals/bed-contigs/{contigs}_of_13/scattered.bed",
output:
vcf = "Outputs/GenotypeGVCFs/{contigs}_genotypes.g.vcf.gz",
shell:
"gatk --java-options '-Xmx3500M -Djava.io.tempdir=`pwd`/tmp' \
GenotypeGVCFs \
-R {input.fasta} \
-O {output.vcf} \
-V {input.vcf} \
-L {input.intervals} \
--tmp-dir Outputs/GenotypeGVCFs/"
rule GatherVCFs2:
input:
expand("Outputs/GenotypeGVCFs/{contigs}_genotypes.g.vcf.gz", contigs=CONTIGS)
output:
"Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz",
run:
INPUTS = " ".join(["--INPUT {}".format(x) for x in input])
shell("gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
MergeVcfs \
{INPUTS} \
-O Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz \
--CREATE_INDEX true".format(INPUTS=INPUTS))
rule VariantRecalibratorSNP:
input:
vcf = "Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz",
fasta = "/references/Homo_sapiens_assembly38.fasta",
dbsnp = "/references/dbsnp_146.hg38.vcf.gz",
v1000g = "/references/1000G_phase1.snps.high_confidence.hg38.vcf.gz",
omni = "/references/1000G_omni2.5.hg38.vcf.gz",
hapmap = "/references/hapmap_3.3.hg38.vcf.gz"
output:
recal = "Outputs/VariantRecalibratorSNP/SnpVQSR.recal",
tranches = "Outputs/VariantRecalibratorSNP/SnpVQSR.tranches",
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
VariantRecalibrator \
-R {input.fasta} \
-V {input.vcf} \
--mode SNP \
--resource v1000G,known=false,training=true,truth=false,prior=10.0:{input.v1000g} \
--resource omni,known=false,training=true,truth=true,prior=12.0:{input.omni} \
--resource dbsnp,known=true,training=false,truth=false,prior=2.0:{input.dbsnp} \
--resource hapmap,known=false,training=true,truth=true,prior=15.0:{input.hapmap} \
-an QD -an MQ -an DP -an MQRankSum -an ReadPosRankSum -an FS -an SOR \
-tranche 100.0 -tranche 99.95 -tranche 99.9 -tranche 99.8 -tranche 99.6 \
-tranche 99.5 -tranche 99.4 -tranche 99.3 -tranche 99.0 -tranche 98.0 \
-tranche 97.0 -tranche 90.0 \
--tranches-file {output.tranches} \
--output {output.recal} \
--max-gaussians 4 \
--tmp-dir Outputs/VariantRecalibratorSNP/"
rule VariantRecalibratorINDEL:
input:
vcf = "Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz",
fasta = "/references/Homo_sapiens_assembly38.fasta",
dbsnp = "/references/dbsnp_146.hg38.vcf.gz",
mills = "/references/Mills_and_1000G_gold_standard.indels.hg38.vcf.gz",
output:
recal = "Outputs/VariantRecalibratorINDEL/IndelVQSR.recal",
tranches = "Outputs/VariantRecalibratorINDEL/IndelVQSR.tranches",
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
VariantRecalibrator \
-R {input.fasta} \
-V {input.vcf} \
--mode INDEL \
--resource mills,known=false,training=true,truth=true,prior=12.0:{input.mills} \
--resource dbsnp,known=true,training=false,truth=false,prior=2.0:{input.dbsnp} \
-an QD -an DP -an FS -an SOR -an ReadPosRankSum -an MQRankSum -tranche 100.0 \
-tranche 99.95 -tranche 99.9 -tranche 99.5 -tranche 99.0 -tranche 97.0 -tranche 96.0 \
-tranche 95.0 -tranche 94.0 -tranche 93.5 -tranche 93.0 -tranche 92.0 -tranche 91.0 \
-tranche 90.0 \
--tranches-file {output.tranches} \
--output {output.recal} \
--tmp-dir Outputs/VariantRecalibratorINDEL/ \
--max-gaussians 4"
rule ApplyVqsrSnp:
input:
vcf = "Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz",
fasta = "/references/Homo_sapiens_assembly38.fasta",
recal = "Outputs/VariantRecalibratorSNP/SnpVQSR.recal",
tranches = "Outputs/VariantRecalibratorSNP/SnpVQSR.tranches"
output:
vcf = "Outputs/ApplyVqsrSnp/SnpApplyVQSR.g.vcf.gz",
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
ApplyVQSR \
-V {input.vcf} \
-R {input.fasta} \
--mode SNP \
-ts-filter-level 99.6 \
-tranches-file {input.tranches} \
-recal-file {input.recal} \
-O {output.vcf} \
--tmp-dir Outputs/ApplyVqsrSnp/"
rule ApplyVqsrIndel:
input:
vcf = "Outputs/GatherVCFs2/GatheredVCFs2.g.vcf.gz",
fasta = "/references/Homo_sapiens_assembly38.fasta",
recal = "Outputs/VariantRecalibratorINDEL/IndelVQSR.recal",
tranches = "Outputs/VariantRecalibratorINDEL/IndelVQSR.tranches"
output:
vcf = "Outputs/ApplyVqsrIndel/IndelApplyVQSR.g.vcf.gz",
shell:
"gatk --java-options -Djava.io.tempdir=`pwd`/tmp \
ApplyVQSR \
-V {input.vcf} \
-R {input.fasta} \
--mode INDEL \
-ts-filter-level 95.0 \
-tranches-file {input.tranches} \
-recal-file {input.recal} \
-O {output.vcf} \
--tmp-dir Outputs/ApplyVqsrIndel/"