-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.tpl
309 lines (263 loc) · 10.1 KB
/
Makefile.tpl
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
{# TODO: add FASTQC and trimming#}
# Autogenerated using smake {{ root }}
FASTQ1 =
FASTQ2 =
ROOT = {{ root }}
THREADS = 24
MEMORY = 16g
GATK = java -Xmx$(MEMORY) -jar ~/tools/GATK/GenomeAnalysisTK.jar
SNPEFF = java -Xmx$(MEMORY) -jar ~/tools/snpEff/snpEff.jar
THIS := $(abspath $(lastword $(MAKEFILE_LIST)))
.SECONDARY:
.PHONY: all
all: output.vcf
############################ RESOURCES ############################
{# TODO use variables instead of full paths with version numbers #}
#Get reference genome file from 1kG
~/db/human_g1k_v37.fasta:
wget "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/human_g1k_v37.fasta.gz" -O - \
| gunzip > $@
~/db/human_g1k_v37.fasta.fai:
wget "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/human_g1k_v37.fasta.fai" -O $@
~/db/human_g1k_v37.dict: ~/db/human_g1k_v37.fasta
picard-tools CreateSequenceDictionary R=$< O=$@
~/db/human_g1k_v37.fasta.bwt: ~/db/human_g1k_v37.fasta
bwa index -a bwtsw $<
#Get indel sites from 1kG
~/db/1000G_phase1.indels.b37.vcf:
wget "ftp://gsapubftp-anonymous:@ftp.broadinstitute.org/bundle/2.8/b37/1000G_phase1.indels.b37.vcf.gz" -O - \
| gunzip > $@
#Get capture files
~/db/Agilent/S04380110_Covered.bed:
$(error 'Capture .bed is missing. To get the capture .bed, download the data from https://earray.chem.agilent.com/suredesign. Just create an account, log in, and select the "Find Designs" tab, then "SureSelect DNA" then under that select "Agilent Catalog", then there should be a list of the different SureSelect related bed files and whatnot.')
~/db/Agilent/S04380110_Covered_noprefix.bed: ~/db/Agilent/S04380110_Covered.bed
grep -v '^(browser|track)' $< | sed 's/^chr//' > $@
#Get dbSNP database
~/db/dbSNP/GRCh37p13_dbsnp146_00-All.vcf:
wget "ftp://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606_b146_GRCh37p13/VCF/00-All.vcf.gz" -O - \
| gunzip > $@
# Get VQSR resources
~/db/hapmap_3.3.b37.vcf:
wget "ftp://[email protected]/bundle/2.8/b37/hapmap_3.3.b37.vcf.gz" -O - \
| gunzip > $@
~/db/hapmap_3.3.b37.vcf.idx:
wget "ftp://[email protected]/bundle/2.8/b37/hapmap_3.3.b37.vcf.idx.gz" -O - \
| gunzip > $@
~/db/1000G_omni2.5.b37.vcf:
wget "ftp://[email protected]/bundle/2.8/b37/1000G_omni2.5.b37.vcf.gz" - O - \
| gunzip > $@
~/db/1000G_omni2.5.b37.vcf.idx:
wget "ftp://[email protected]/bundle/2.8/b37/1000G_omni2.5.b37.vcf.idx.gz" -O - \
| gunzip > $@
~/db/1000G_phase1.snps.high_confidence.b37.vcf:
wget "ftp://[email protected]/bundle/2.8/b37/1000G_phase1.snps.high_confidence.b37.vcf.gz" -O - \
| gunzip > $@
~/db/1000G_phase1.snps.high_confidence.b37.vcf.idx:
wget "ftp://[email protected]/bundle/2.8/b37/1000G_phase1.snps.high_confidence.b37.vcf.idx.gz" - O - \
| gunzip > $@
~/db/dbsnp_138.b37.vcf:
wget "ftp://[email protected]/bundle/2.8/b37/dbsnp_138.b37.vcf.gz" -O - \
| gunzip > $@
~/db/dbsnp_138.b37.vcf.idx:
wget "ftp://[email protected]/bundle/2.8/b37/dbsnp_138.b37.vcf.idx.gz" -O - \
| gunzip > $@
~/db/Mills_and_1000G_gold_standard.indels.b37.vcf:
wget "ftp://[email protected]/bundle/2.8/b37/Mills_and_1000G_gold_standard.indels.b37.vcf.gz" -O - \
| gunzip > $@
~/db/Mills_and_1000G_gold_standard.indels.b37.vcf.idx:
wget "ftp://[email protected]/bundle/2.8/b37/Mills_and_1000G_gold_standard.indels.b37.vcf.idx.gz" -O - \
| gunzip > $@
############################ ALIGNMENT ############################
{# TODO add cutadapt if necessary (cf. FASTQC) #}
#Align with BWA
#-M Mark shorter split hits as secondary (for Picard compatibility)
#-R Complete read group header line
%.raw.sam: ~/db/human_g1k_v37.fasta $(FASTQ1) $(FASTQ2)
bwa mem -t $(THREADS) -M -R "@RG\tID:exome\tSM:$(basename $(notdir $@))\tPL:illumina\tLB:agilent_v5" $^ > $@
%.raw.bam: %.raw.sam
samtools view -hb $< > $@
%.sorted.bam: %.raw.bam
samtools sort -o -@ $(THREADS) $< _ > $@
#Flag BAM duplicates with Picard
%.duplicates.bam: %.sorted.bam
picard-tools MarkDuplicates REMOVE_DUPLICATES=false METRICS_FILE=$*.dup.log I=$< O=$@
%.dup.log: %.duplicates.bam
touch $@
%.duplicates.bai: %.duplicates.bam
samtools index $<
#Realign indels
%.target.list: %.duplicates.bam %.duplicates.bai ~/db/Agilent/S04380110_Covered_noprefix.bed ~/db/human_g1k_v37.fasta ~/db/1000G_phase1.indels.b37.vcf
$(GATK) \
-nt $(THREADS) \
-T RealignerTargetCreator \
-L ~/db/Agilent/S04380110_Covered_noprefix.bed \
-R ~/db/human_g1k_v37.fasta \
-known ~/db/1000G_phase1.indels.b37.vcf \
-I $< \
-o $@
%.realigned.bam: %.duplicates.bam %.target.list ~/db/human_g1k_v37.fasta ~/db/1000G_phase1.indels.b37.vcf
$(GATK) \
-T IndelRealigner \
-R ~/db/human_g1k_v37.fasta \
-I $< \
-known ~/db/1000G_phase1.indels.b37.vcf \
-targetIntervals $*.target.list \
-filterMBQ \
-o $@
#Recalibrate bases
%.bases: %.realigned.bam ~/db/Agilent/S04380110_Covered_noprefix.bed ~/db/human_g1k_v37.fasta ~/db/dbSNP/GRCh37p13_dbsnp146_00-All.vcf
$(GATK) \
-nct $(THREADS) \
-T BaseRecalibrator \
-L ~/db/Agilent/S04380110_Covered_noprefix.bed \
-R ~/db/human_g1k_v37.fasta \
-I $< \
-knownSites ~/db/dbSNP/GRCh37p13_dbsnp146_00-All.vcf \
-o $@
%.recalibrated.bam: %.realigned.bam %.bases ~/db/human_g1k_v37.fasta
$(GATK) \
-nct $(THREADS) \
-T PrintReads \
-R ~/db/human_g1k_v37.fasta \
-I $< \
-BQSR $*.bases \
-o $@
############################ CALLING ############################
{# TODO
#Split the Capture .bed file into $(THREADS) files
#For now, not used in the calling. I have to implement this.
nb_line_bed=$(wc -l ~/db/Agilent/S04380110_Covered_noprefix.bed | awk '{print $1}')
nb_line_split=$(((nb_line_bed+THREADS-1)/THREADS))
for i in $(seq THREADS)
do
test -f ~/db/Agilent/S04380110_Covered_noprefix_$i.bed || \
# sed -n "$((nb_line_split*(i-1))),$((nb_line_split*i-1)) p" ~/db/Agilent/S04380110_Covered_noprefix.bed > ~/db/Agilent/S04380110_Covered_noprefix_$i.bed
done
#}
#Call variants with GATK HaplotypeCaller in gVCF
%.raw.gvcf: %.recalibrated.bam ~/db/Agilent/S04380110_Covered_noprefix.bed ~/db/human_g1k_v37.fasta ~/db/dbSNP/GRCh37p13_dbsnp146_00-All.vcf ~/db/human_g1k_v37.dict
$(GATK) \
-nct $(THREADS) \
-T HaplotypeCaller \
-ERC GVCF \
--variant_index_type LINEAR \
--variant_index_parameter 128000 \
-L:capture,BED ~/db/Agilent/S04380110_Covered_noprefix.bed \
-R ~/db/human_g1k_v37.fasta \
-stand_call_conf 30.0 \
-stand_emit_conf 10.0 \
-S SILENT \
-I $< \
--dbsnp:vcfinput,VCF ~/db/dbSNP/GRCh37p13_dbsnp146_00-All.vcf \
-o $@
{% for vcf, fastqs in rules.items() %}
{{ vcf }}/{{ vcf }}.raw.gvcf: $(ROOT)/{{ fastqs['fastq1'] }} $(ROOT)/{{ fastqs['fastq2'] }}
mkdir -p $(dir $@)
make -f $(THIS) -C $(dir $@) \
FASTQ1=$(ROOT)/{{ fastqs['fastq1'] }} \
FASTQ2=$(ROOT)/{{ fastqs['fastq2'] }} \
THREADS=$(THREADS) \
MEMORY=$(MEMORY) \
$(notdir $@)
{% endfor %}
# Generate VCF from gVCF
output.raw.vcf: \
{% for vcf in rules.keys() %}
{{ vcf }}/{{ vcf }}.raw.gvcf \
{% endfor %}
~/db/Agilent/S04380110_Covered_noprefix.bed ~/db/human_g1k_v37.fasta
$(GATK) \
-nt $(THREADS) \
-T GenotypeGVCFs \
-L ~/db/Agilent/S04380110_Covered_noprefix.bed \
-R ~/db/human_g1k_v37.fasta \
{% for vcf in rules.keys() %}
-V {{ vcf }}/{{ vcf }}.raw.gvcf \
{% endfor %}
-o $@
# Compute VQSR model for SNPs
%.raw.vcf.SNP.recal: %.raw.vcf ~/db/human_g1k_v37.fasta ~/db/hapmap_3.3.b37.vcf ~/db/1000G_omni2.5.b37.vcf ~/db/1000G_phase1.snps.high_confidence.b37.vcf.idx ~/db/dbsnp_138.b37.vcf
$(GATK) \
-nt $(THREADS) \
-T VariantRecalibrator \
-mode SNP \
-R ~/db/human_g1k_v37.fasta \
-input $< \
-resource:hapmap,known=false,training=true,truth=true,prior=15.0 ~/db/hapmap_3.3.b37.vcf \
-resource:omni,known=false,training=true,truth=true,prior=12.0 ~/db/1000G_omni2.5.b37.vcf \
-resource:1000G,known=false,training=true,truth=false,prior=10.0 ~/db/1000G_phase1.snps.high_confidence.b37.vcf \
-resource:dbsnp,known=true,training=false,truth=false,prior=2.0 ~/db/dbsnp_138.b37.vcf \
-an FS \
-an MQ \
-an MQRankSum \
-an QD \
-an ReadPosRankSum \
-an SOR \
-recalFile $@ \
-tranchesFile $*.raw.vcf.SNP.tranches
%.raw.vcf.SNP.tranches: %.raw.vcf.SNP.recal
touch $@
{# TODO if nbSamples > 10 and unrelated, add -an InbreedingCoeff #}
# Apply VQSR model for SNPs
%.snp_recalibrated.vcf: %.raw.vcf %.raw.vcf.SNP.recal %.raw.vcf.SNP.tranches ~/db/human_g1k_v37.fasta
$(GATK) \
-T ApplyRecalibration \
-mode SNP \
-R ~/db/human_g1k_v37.fasta \
-input $< \
--ts_filter_level 99.5 \
-recalFile $*.raw.vcf.SNP.recal \
-tranchesFile $*.raw.vcf.SNP.tranches \
-o $@
# Compute VQSR model for indels
%.raw.vcf.indels.recal: %.snp_recalibrated.vcf ~/db/human_g1k_v37.fasta ~/db/Mills_and_1000G_gold_standard.indels.b37.vcf ~/db/dbsnp_138.b37.vcf
$(GATK) \
-nt $(THREADS) \
-T VariantRecalibrator \
-mode INDEL \
-R ~/db/human_g1k_v37.fasta \
-input $< \
-resource:mills,known=false,training=true,truth=true,prior=12.0 ~/db/Mills_and_1000G_gold_standard.indels.b37.vcf \
-resource:dbsnp,known=true,training=false,truth=false,prior=2.0 ~/db/dbsnp_138.b37.vcf \
-an FS \
-an MQRankSum \
-an QD \
-an ReadPosRankSum \
-an SOR \
--maxGaussians 4 \
-recalFile $@ \
-tranchesFile $*.raw.vcf.indels.tranches
%.raw.vcf.indels.tranches: %.raw.vcf.indels.recal
touch $@
# Apply VQSR model for SNPs
%.all_recalibrated.vcf: %.snp_recalibrated.vcf %.raw.vcf.indels.recal %.raw.vcf.indels.tranches ~/db/human_g1k_v37.fasta
$(GATK) \
-T ApplyRecalibration \
-mode INDEL \
-R ~/db/human_g1k_v37.fasta \
-input $< \
--ts_filter_level 99.0 \
-recalFile $*.raw.vcf.indels.recal \
-tranchesFile $*.raw.vcf.indels.tranches \
-o $@
# Select variants on VQSR results
%.all_selected.vcf: %.all_recalibrated.vcf ~/db/human_g1k_v37.fasta
$(GATK) \
-nt $(THREADS) \
-T SelectVariants \
-env \
-R ~/db/human_g1k_v37.fasta \
-V $< \
-o $@
%.vcf: %.all_selected.vcf
$(SNPEFF) \
ann GRCh37.75 \
-i vcf \
-o vcf \
-sequenceOntology \
-lof \
-stats $*.snpeff.stats.html \
$< \
> $@
%.snpeff.stats.html: %.vcf
touch $@