forked from AG-Boerries/MIRACUM-Pipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_alignment_VC_CNV.sh
executable file
·395 lines (305 loc) · 12.6 KB
/
make_alignment_VC_CNV.sh
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
###########################################
## WES Pipeline for somatic and germline ##
###########################################
# script to run the actual analysis
# Version 05.02.2019
case=$1; # somatic or somaticGermline
task=$2; # GD or TD (alignment)
num=$3; # 73
sex=$4;
##################################################################################################################
#### Parameters which have to be adjusted accoridng the the environment or the users needs
## General
homedata="/path/to/data" # folder contatining the raw data (.fastq files)
annot="/path/to/annotation" # folder containing annotation files like captureRegions.bed
motherpath="/path/to/output"
mtb="${motherpath}/${case}_${num}" # folder containing output
wes="${mtb}/WES"
ana="${mtb}/Analysis"
RscriptPath="${motherpath}/RScripts"
DatabasePath="${motherpath}/Databases"
tempdir="${mtb}/tmp" # temporary folder
## Genome
GENOME="/path/to/ref/genome/including/index/hg19.fa"
Chromosomes="/path/to/ref/genome/chromosomes"
ChromoLength="/path/to/ref/chromosomes/length/hg19_chr.len"
## SureSelect (Capture Kit)
CaptureRegions="${annot}/CaptureRegions.bed"
## dbSNP vcf File
dbSNPvcf="/path/to/dbSNP/dbSNP/snp150hg19.vcf.gz "
### Software
## Parameters
## General
# Cores to use
nCore="12"
minBaseQual="28"
minVAF="0.10"
# VarScan somatic
minCoverage="8"
TumorPurity="0.5"
minFreqForHom="0.75" # VAF to call homozygote
# VarScan fpfilter
minVarCount="4"
# ANNOVAR Databases
protocol='refGene,gnomad_exome,exac03,esp6500siv2_ea,EUR.sites.2015_08,avsnp150,clinvar_20180603,intervar_20180118,dbnsfp35a,cosmic86_coding,cosmic86_noncoding'
argop='g,f,f,f,f,f,f,f,f,f,f'
## Tools and paths
# Paths
soft="/path/to/tools/software" # folder containing all used tools
java="${soft}/bin/java -Djava.io.tmpdir=${tempdir} " # path to java
# Pre-Processing
FASTQC="${soft}/FastQC/fastqc -t ${nCore} --extract "
TRIM="${java} -Xmx150g -jar ${soft}/Trimmomatic-0.36/trimmomatic-0.36.jar PE -threads ${nCore} -phred33 "
TrimmomaticAdapter="/home/miracum/Trimmomatic-0.38/adapters"
CUT="cut -f1,2,3"
# Alignment
BWAMEM="${soft}/bin/bwa mem -M "
# BAM-Readcount
BamReadcount="${soft}/bin/bam-readcount -q 1 -b 20 -w 1 -f ${GENOME} "
# SAMTOOLS
SAMTOOLS="${soft}/bin/samtools" # path to samtools
SAMVIEW="${SAMTOOLS} view -@ ${nCore} "
SAMSORT="${SAMTOOLS} sort -@ ${nCore} "
SAMRMDUP="${SAMTOOLS} rmdup "
SAMINDEX="${SAMTOOLS} index "
MPILEUP="${SAMTOOLS} mpileup -B -C 50 -f ${GENOME} -q 1 --min-BQ ${minBaseQual}"
STATS="${SAMTOOLS} stats "
# GATK
GATK="${soft}/bin/gatk"
RealignerTargetCreator="${GATK} -T RealignerTargetCreator -R ${GENOME} -nt ${nCore} "
IndelRealigner="${GATK} -R ${GENOME} -T IndelRealigner "
BaseRecalibrator="${GATK} -T BaseRecalibrator -l INFO -R ${GENOME} -knownSites ${dbSNPvcf} -nct ${nCore} "
PrintReads="${GATK} -T PrintReads -R ${GENOME} -nct ${nCore} "
# PICARD
FixMate="${soft}/bin/picard FixMateInformation "
# VARSCAN
VarScan="${soft}/bin/varscan"
SOMATIC="${VarScan} somatic"
PROCESSSOMATIC="${VarScan} processSomatic"
# ANNOVAR
ANNOVAR="${soft}/bin/annovar"
ANNOVARData="${ANNOVAR}/humandb"
CONVERT2ANNOVAR2="${ANNOVAR}/convert2annovar.pl --format vcf4old --outfile "
CONVERT2ANNOVAR3="${ANNOVAR}/convert2annovar.pl --format vcf4old --includeinfo --comment --outfile "
CONVERT2ANNOVAR="${ANNOVAR}/convert2annovar.pl --format vcf4 --includeinfo --comment --withzyg --outfile "
TABLEANNOVAR="${ANNOVAR}/table_annovar.pl"
# COVERAGE
COVERAGE="${soft}/bedtools2/bin/bedtools coverage -hist -g ${GENOME}.fai -sorted "
# SNPEFF
SNPEFF="${java} -Xmx150g -jar ${soft}/snpEff/snpEff.jar GRCh37.75 -c ${soft}/snpEff/snpEff.config -canon -v"
# ControlFREEC
freec="${soft}/bin/freec "
gemMappabilityFile="${soft}/FREEC-11.0/mappability/out100m2_hg19.gem"
# R
Rscript="${soft}/bin/Rscript"
##################################################################################################################
##########
## MAIN ##
##########
# SAMPLE
NameD=${case}_${num}_${task}
xx=${4};
InputPath=${homedata}/ngs/$xx/fastq ## change later !!!
Input1File=${5}1; # filename without extension
Input2File=${5}2; # filename without extension
# temp files
fastq1=${InputPath}/${Input1File}.fastq.gz
fastq2=${InputPath}/${Input2File}.fastq.gz
fastq_o1_p_t=${tempdir}/${NameD}_output1_paired_trimmed.fastq.gz
fastq_o1_u_t=${tempdir}/${NameD}_output1_unpaired_trimmed.fastq.gz
fastq_o2_p_t=${tempdir}/${NameD}_output2_paired_trimmed.fastq.gz
fastq_o2_u_t=${tempdir}/${NameD}_output2_unpaired_trimmed.fastq.gz
bam=${tempdir}/${NameD}_output.bam
prefixsort=${tempdir}/${NameD}_output.sort
sortbam=${tempdir}/${NameD}_output.sort.bam
rmdupbam=${tempdir}/${NameD}_output.sort.filtered.rmdup.bam
bai=${tempdir}/${NameD}_output.sort.filtered.rmdup.bai
bamlist=${tempdir}/${NameD}_output.sort.filtered.rmdup.bam.list
realignedbam=${tempdir}/${NameD}_output.sort.filtered.rmdup.realigned.bam
realignedbai=${tempdir}/${NameD}_output.sort.filtered.rmdup.realigned.bai
fixedbam=${tempdir}/${NameD}_output.sort.filtered.rmdup.realigned.fixed.bam
fixedbai=${tempdir}/${NameD}_output.sort.filtered.rmdup.realigned.fixed.bai
csv=${tempdir}/${NameD}_output.sort.filtered.rmdup.realigned.fixed.recal_data.csv
recalbam=${wes}/${NameD}_output.sort.filtered.rmdup.realigned.fixed.recal.bam
statstxt=${wes}/${NameD}_stats.txt
coveragetxt=${wes}/${NameD}_coverage.all.txt
### program calls
## alignment -----------------------------------------------------------------------------------------------------
if [ ${task} = GD ] || [ ${task} = TD ]
then
if [ ! -d ${tempdir} ]; then
mkdir ${tempdir}
fi
# fastqc zip to WES
${FASTQC} ${fastq1} -o ${wes}
${FASTQC} ${fastq2} -o ${wes}
# trim fastq
${TRIM} ${fastq1} ${fastq2} ${fastq_o1_p_t} ${fastq_o1_u_t} ${fastq_o2_p_t} ${fastq_o2_u_t} ILLUMINACLIP:${TrimmomaticAdapter}/TruSeq3-PE-2.fa:2:30:10 HEADCROP:3 TRAILING:10 MINLEN:25
${FASTQC} ${fastq_o1_p_t} -o ${wes}
${FASTQC} ${fastq_o2_p_t} -o ${wes}
# make bam
${BWAMEM} -R "@RG\tID:${NameD}\tSM:${NameD}\tPL:illumina\tLB:lib1\tPU:unit1" -t 12 ${GENOME} ${fastq_o1_p_t} ${fastq_o2_p_t} | ${SAMVIEW} -bS - > ${bam}
# stats
${STATS} ${bam} > ${statstxt}
# sort bam
${SAMSORT} ${bam} -T ${prefixsort} -o ${sortbam}
# rmdup bam
${SAMVIEW} -b -f 0x2 -q1 ${sortbam} | ${SAMRMDUP} - ${rmdupbam}
# make bai
${SAMINDEX} ${rmdupbam} ${bai}
# make bam list
${RealignerTargetCreator} -o ${bamlist} -I ${rmdupbam}
# realign bam
${IndelRealigner} -I ${rmdupbam} -targetIntervals ${bamlist} -o ${realignedbam}
# fix bam
${FixMate} INPUT=${realignedbam} OUTPUT=${fixedbam} SO=coordinate VALIDATION_STRINGENCY=LENIENT CREATE_INDEX=true
# make csv
${BaseRecalibrator} -I ${fixedbam} -cov ReadGroupCovariate -cov QualityScoreCovariate -cov CycleCovariate -cov ContextCovariate -o ${csv}
# recal bam
${PrintReads} -I ${fixedbam} -BQSR ${csv} -o ${recalbam}
# coverage
${COVERAGE} -b ${recalbam} -a ${CaptureRegions} | grep '^all' > ${coveragetxt}
# zip
${FASTQC} ${recalbam} -o ${wes}
fi
# eo alignment
## variantCalling ------------------------------------------------------------------------------------------------
if [ $task = VC ]
then
if [ ! -d ${tempdir} ]; then
mkdir ${tempdir}
fi
NameD=${case}_${num}_${task}
NameGD=${case}_${num}_GD
NameTD=${case}_${num}_TD
recalbamGD=${wes}/${NameGD}_output.sort.filtered.rmdup.realigned.fixed.recal.bam
recalbamTD=${wes}/${NameTD}_output.sort.filtered.rmdup.realigned.fixed.recal.bam
snpvcf=${wes}/${NameD}.output.snp.vcf
indelvcf=${wes}/${NameD}.output.indel.vcf
${MPILEUP} ${recalbamGD} ${recalbamTD} | ${SOMATIC} --output-snp ${snpvcf} --output-indel ${indelvcf} --min-coverage ${minCoverage} --tumor-purity ${TumorPurity} --min-var-freq ${minVAF} --min-freq-for-hom ${minFreqForHom} --min-avg-qual ${minBaseQual} --output-vcf 1 --mpileup 1
# Processing of somatic mutations
${PROCESSSOMATIC} ${snpvcf} --min-tumor-freq ${minVAF}
${PROCESSSOMATIC} ${indelvcf} --min-tumor-freq ${minVAF}
# FP Filter: snp.Somatic.hc snp.LOH.hc snp.Germline.hc
# FP Filter: indel.Somatic.hc indel.LOH.hc indel.Germline.hc
names1="snp indel"
for name1 in ${names1}
do
if [ ${case} = somatic ]; then
names2="Somatic LOH"
else
names2="Somatic LOH Germline"
fi
for name2 in ${names2}
do
hc_vcf=${wes}/${NameD}.output.${name1}.${name2}.hc.vcf
hc_avi=${wes}/${NameD}.output.${name1}.${name2}.hc.avinput
hc_rci=${wes}/${NameD}.output.${name1}.${name2}.hc.readcount.input
hc_rcs=${wes}/${NameD}.output.${name1}.${name2}.hc.readcounts
hc_fpf=${wes}/${NameD}.output.${name1}.${name2}.hc.fpfilter.vcf
if [ ${name2} = Somatic ]; then
recalbam=${recalbamTD}
else
recalbam=${recalbamGD}
fi
${CONVERT2ANNOVAR2} ${hc_avi} ${hc_vcf}
${CUT} ${hc_avi} > ${hc_rci}
${BamReadcount} -l ${hc_rci} ${recalbam} > ${hc_rcs}
${VarScan} fpfilter ${hc_vcf} ${hc_rcs} --output-file ${hc_fpf} --keep-failures 1 --min-ref-basequal ${minBaseQual} --min-var-basequal ${minBaseQual} --min-var-count ${minVarCount} --min-var-freq ${minVAF}
done
done
data=${wes}
for name1 in ${names1}
do
# Annotation snp.Somatic.hc $data/NameD.output.snp.Somatic.hc.fpfilter.vcf
# Annotation indel.Somatic.hc $data/NameD.output.indel.Somatic.hc.fpfilter.vcf
hc_=${data}/${NameD}.output.${name1}.Somatic.hc
hc_fpf=${data}/${NameD}.output.${name1}.Somatic.hc.fpfilter.vcf
hc_T_avi=${data}/${NameD}.output.${name1}.Somatic.hc.TUMOR.avinput
hc_T_avi_multi=${data}/${NameD}.output.${name1}.Somatic.hc.TUMOR.avinput.hg19_multianno.csv
${CONVERT2ANNOVAR} ${hc_} ${hc_fpf} -allsample
${TABLEANNOVAR} ${hc_T_avi} ${ANNOVARData} -protocol ${protocol} -buildver hg19 -operation ${argop} -csvout -otherinfo -remove -nastring NA
hc_snpeff=$data/${NameD}.output.$name1.Somatic.SnpEff.vcf
${SNPEFF} ${hc_fpf} > ${hc_snpeff}
if [ $case = somaticGermline ]; then
# Annotation snp.Germline.hc $data/NameD.output.snp.Germline.hc.fpfilter.vcf
# Annotation indel.Germline.hc $data/NameD.output.indel.Germline.hc.fpfilter.vcf
hc_=${data}/${NameD}.output.${name1}.Germline.hc
hc_fpf=${data}/${NameD}.output.${name1}.Germline.hc.fpfilter.vcf
hc_N_avi=${data}/${NameD}.output.${name1}.Germline.hc.NORMAL.avinput
hc_N_avi_multi=${data}/${NameD}.output.${name1}.Germline.hc.NORMAL.avinput.hg19_multianno.csv
${CONVERT2ANNOVAR} ${hc_} ${hc_fpf} -allsample
${TABLEANNOVAR} ${hc_N_avi} ${ANNOVARData} -protocol ${protocol} -buildver hg19 -operation ${argop} -csvout -otherinfo -remove -nastring NA
hc_N_snpeff=${data}/${NameD}.output.${name1}.NORMAL.SnpEff.vcf
${SNPEFF} ${hc_fpf} > ${hc_N_snpeff}
fi
# Annotation snp.LOH.hc
# Annotation indel.LOH.hc
hc_vcf=${data}/${NameD}.output.${name1}.LOH.hc.vcf
hc_fpf=${data}/${NameD}.output.${name1}.LOH.hc.fpfilter.vcf
hc_avi=${data}/${NameD}.output.${name1}.LOH.hc.avinput
hc_avi_multi=${data}/${NameD}.output.${name1}.LOH.hc.avinput.hg19_multianno.csv
${CONVERT2ANNOVAR3} ${hc_avi} ${hc_fpf}
${TABLEANNOVAR} ${hc_avi} ${ANNOVARData} -protocol ${protocol} -buildver hg19 -operation ${argop} -csvout -otherinfo -remove -nastring NA
hc_L_snpeff=${data}/${NameD}.output.${name1}.LOH.SnpEff.vcf
${SNPEFF} ${hc_fpf} > ${hc_L_snpeff}
done
rm -r ${tempdir}
fi
# eo VC
## CNV ----------------------------------------------------------------------------------------------------------
if [ ${task} = CNV ]; then
output="${wes}/CNV"
if [ ! -d ${output} ]; then
mkdir ${output}
fi
cat > ${wes}/CNV_config.txt <<EOI
[general]
chrFiles = ${Chromosomes}
chrLenFile = ${ChromoLength}
breakPointType = 4
breakPointThreshold = 1.2
forceGCcontentNormalization = 1
gemMappabilityFile = ${gemMappabilityFile}
intercept = 0
minCNAlength = 3
maxThreads = 12
noisyData = TRUE
outputDir = ${output}
ploidy = 2
printNA = FALSE
readCountThreshold = 50
samtools = ${SAMTOOLS}
sex = ${sex}
step = 0
window = 0
uniqueMatch = TRUE
contaminationAdjustment = TRUE
[sample]
mateFile = ${wes}/${case}_${num}_TD_output.sort.filtered.rmdup.realigned.fixed.recal.bam
inputFormat = BAM
mateOrientation = FR
[control]
mateFile = ${wes}/${case}_${num}_GD_output.sort.filtered.rmdup.realigned.fixed.recal.bam
inputFormat = BAM
mateOrientation = FR
[target]
captureRegions = ${CaptureRegions}
EOI
export PATH=${PATH}:${SAMTOOLS}
${freec}-conf ${wes}/CNV_config.txt
fi
# eo CNV
## Report -------------------------------------------------------------------------------------------------------
if [ ${task} = Report ]; then
cd ${ana}
${Rscript} ${ana}/Main.R ${case} ${num} ${4} ${5} ${mtb} ${RscriptPath} ${DatabasePath}
${Rscript} -e "library(knitr); knit('Report.Rnw')"
${soft}/pdflatex -interaction=nonstopmode Report.tex
${soft}/pdflatex -interaction=nonstopmode Report.tex
fi
# eo Report
echo "task ${task} for ${num} finished"
rm .STARTING_MARKER_${task}
exit