GATK's Pipeline for calling variants with wgs data

#!/bin/bash

PICARD=/home/lq/storage/call_variants/softwares/picard.jar

gatk=/home/lq/storage/call_variants/softwares/gatk_noDownSample/GenomeAnalysisTK.jar

db=/home/lq/software/data/known_database

reference_file=/home/lq/software/data/reference_sequence/hs37d5.fasta

tmp_dir=/home/lq/Storage/erdai/tmp

result_path=/home/lq/Storage/erdai


##################################################################################################

#############################################      QC    #######################################

##################################################################################################

echo  "#######################################    QC    #######################################"

in_dir=/home/lq/Storage

out_dir=${result_path}/quality_control

fastqc -t 32 ${in_dir}/HAP1_264_DHG15556-S_1.fq.gz ${in_dir}/HAP1_264_DHG15556-S_2.fq.gz --outdir=${out_dir}


### If necessary:

##################################################################################################

#############################################    Cutadapt     #######################################

##################################################################################################

echo  "#######################################    Cutadapt    #######################################"

out_dir=${result_path}/1_cutadapt_output

cutadapt -q 5 -o ${out_dir}/1_cutadapt.fastq.gz ${in_dir}/HAP1_264_DHG15556-S_1.fq.gz

cutadapt -q 5 -o ${out_dir}/2_cutadapt.fastq.gz ${in_dir}/HAP1_264_DHG15556-S_2.fq.gz

##################################################################################################

#############################################      BWA    #######################################

##################################################################################################

echo  "#######################################    BWA    #######################################"

in_dir=${out_dir}

out_dir=${result_path}/2_bwa_output

if [ ! -e ${out_dir}/cutadapt_bwa.sam ]; then

        bwa mem -M -P -t 32 -R '@RG\tID:normal\tSM:normal\tLB:normalLib\tPU:runname\tCN:GenePlus\tPL:illumina' $reference_file ${in_dir}/HAP1_264_DHG15556-S_1.fq.gz ${in_dir}/HAP1_264_DHG15556-S_2.fq.gz > ${out_dir}/cutadapt_bwa.sam

fi

####################################################################################################

#####################################  Samtools: Compress SAM to BAM  #############################

####################################################################################################

echo  "###########################  Use SAMTOOLS to compress SAM to BAM  ###########################"

in_dir=${out_dir}

out_dir=${result_path}/3_samtools_output

if [ ! -e ${out_dir}/cutadapt_bwa.bam ]; then

        time samtools view -@ 32 -bS ${in_dir}/cutadapt_bwa.sam > ${out_dir}/cutadapt_bwa.bam

fi

###################################################################################################

###########################################  Samtools: Sort  #####################################

###################################################################################################

echo  "##################################  Use SAMTOOLS to sort  ###################################"

if [ ! -e ${out_dir}/cutadapt_bwa_sort.bam ]; then

        time samtools sort -@ 32 -m 1536M ${out_dir}/cutadapt_bwa.bam -o ${out_dir}/cutadapt_bwa_sort.bam

fi

###################################################################################################

###########################################  Samtools: index  ####################################

###################################################################################################

echo  "##################################  Use SAMTOOLS to index  ##################################"

if [ ! -e ${out_dir}/cutadapt_bwa_sort.bam.bai ]; then

        time samtools index ${out_dir}/cutadapt_bwa_sort.bam ${out_dir}/cutadapt_bwa_sort.bam.bai

fi

###################################################################################################

#####################################  Picard: MarkDuplicates  ####################################

###################################################################################################

echo  "#############################  Use Picard to Markduplicates  ################################"

in_dir=${out_dir}

out_dir=${result_path}/4_picard_output

if [ ! -e ${out_dir}/cutadapt_bwa_sort_markdup.bam ]; then

        time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Xms8g  -Xmx16g  \

                -Djava.io.tmpdir=${tmp_dir} -jar $PICARD MarkDuplicates \

                I=${in_dir}/cutadapt_bwa_sort.bam O=${out_dir}/cutadapt_bwa_sort_markdup.bam  \

                METRICS_FILE=${out_dir}/cutadapt_bwa_sort_markdup.bam.metrics ASO=coordinate \ 

                OPTICAL_DUPLICATE_PIXEL_DISTANCE=100 VALIDATION_STRINGENCY=SILENT

fi

###################################################################################################

###########################################  Samtools: index  ####################################

###################################################################################################

echo  "##################################  Use SAMTOOLS to index  ##################################"

if [ ! -e ${out_dir}/cutadapt_bwa_sort_markdup.bam.bai ]; then

        time samtools index ${out_dir}/cutadapt_bwa_sort_markdup.bam ${out_dir}/cutadapt_bwa_sort_markdup.bam.bai

fi

####################################################################################################

###########################################  Local Realignment  ####################################

####################################################################################################

echo  "####################################  Local Realignment  ####################################"

in_dir=${out_dir}

out_dir=${result_path}/5_realign_output

if [ ! -e ${out_dir}/cutadapt_bwa_sort_markdup_realign.bam ]; then

        time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Xms32g -Xmx120g  \

                -Djava.io.tmpdir=${tmp_dir}  -jar $gatk -T RealignerTargetCreator  \

                -I ${in_dir}/cutadapt_bwa_sort_markdup.bam \

                -o ${out_dir}/coRealign.intervals \

                -known Mills_and_1000G_gold_standard.indels.b37.vcf \

                -R ${reference_file} \

                -nt 32


        time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Xms32g -Xmx120g  \

                -Djava.io.tmpdir=${tmp_dir} -jar $gatk -T IndelRealigner \

                -I ${in_dir}/cutadapt_bwa_sort_markdup.bam \

                -targetIntervals ${out_dir}/coRealign.intervals \

                -known Mills_and_1000G_gold_standard.indels.b37.vcf.gz  \

                -R ${reference_file}  \

                -o ${out_dir}/cutadapt_bwa_sort_markdup_realign.bam \

                -nt 32

fi

####################################################################################################

###############################################  BQSR  #############################################

####################################################################################################

echo  "########################################  BQSR  #############################################"

in_dir=${out_dir}

out_dir=${result_path}/6_bqsr_output

if [ ! -e ${out_dir}/cutadapt_bwa_sort_markdup_realign_recal.bam ]; then

        time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Xms30g -Xmx30g \

                -Djava.io.tmpdir=${tmp_dir}  -jar $gatk  -T BaseRecalibrator  \

                -I ${in_dir}/cutadapt_bwa_sort_markdup_realign.bam  \

                -o ${out_dir}/cutadapt_bwa_sort_markdup_realign.grp \

                -R ${reference_file}  \

                -knownSites Mills_and_1000G_gold_standard.indels.b37.vcf \

                -knownSites dbsnp_138.b37.vcf \

                -knownSites b37_cosmic_v73_061615.vcf \

                -nct 32

        time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -XX:+UseParallelOldGC -Xms30g -Xmx30g  \

                -Djava.io.tmpdir=${tmp_dir}  -jar $gatk -T PrintReads  \

                -I ${in_dir}/cutadapt_bwa_sort_markdup_realign.bam  \

                -BQSR ${out_dir}/cutadapt_bwa_sort_markdup_realign.grp  \

                -o ${out_dir}/cutadapt_bwa_sort_markdup_realign_recal.bam  \

                -R ${reference_file}  \

                -nct 32

fi

####################################################################################################

############################################  GATK: HaplotypeCaller  ####################################

###################################################################################

echo  "##################################  Use GATK HaplotypeCaller ##################################"

in_dir=${out_dir}

out_dir=${result_path}/7_haplotypeCaller_output

time java -d64 -server -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Djava.io.tmpdir=${tmp_dir}  \

    -jar $gatk  -T HaplotypeCaller  \

    -nct 32 \

    -R ${reference_file} \

    -ploidy 1 \

    -I ${in_dir}/cutadapt_bwa_sort_markdup_realign_recal.bam \

    --dbsnp dbsnp_138.b37.vcf \

    -o ${out_dir}/cutadapt_bwa_sort_markdup_realign_recal.raw.snps.indels.vcf

####################################################################################################

#######################################VQSR: Build the SNP recalibration model############################

####################################################################################################

echo  "########################VQSR: Build the SNP recalibration model######################################"

in_dir=${out_dir}

out_dir=${result_path}/8_vqsr_output

java -jar GenomeAnalysisTK.jar \

    -T  VariantRecalibrator \

    -R  ${reference_file} \

    -nt  20 \

    -input  ${in_dir}/cutadapt_bwa_sort_markdup_realign_recal.raw.snps.indels.vcf \

    -resource:hapmap,known=false,training=true,truth=true,prior=15.0  hapmap_3.3.b37.vcf \

    -resource:omni,known=false,training=true,truth=true,prior=12.0  1000G_omni2.5.b37.vcf \

    -resource:1000G,known=false,training=true,truth=false,prior=10.0  1000G_phase1.snps.high_confidence.b37.vcf \

    -resource:dbsnp,known=true,training=false,truth=false,prior=2.0  dbsnp_138.b37.vcf \

    -an QD \

    -an MQ \

    -an MQRankSum \

    -an ReadPosRankSum \

    -an FS \

    -an SOR \

    -an DP \

    -mode SNP \

    -tranche 100.0 -tranche 99.9 -tranche 99.0 -tranche 90.0 \

    -recalFile  ${out_dir}/recalibrate_SNP.recal \

    -tranchesFile  ${out_dir}/recalibrate_SNP.tranches \

    -rscriptFile  ${out_dir}/recalibrate_SNP_plots.R

####################################################################################################

######################### Apply the desired level of recalibration to SNPs in the call set#######################

####################################################################################################

echo  "################### Apply the desired level of recalibration to SNPs in the call set########################"

java -jar GenomeAnalysisTK.jar \

    -T ApplyRecalibration \

    -ef \

    -nt 20 \

    -R ${reference_file} \

    -input ${in_dir}/cutadapt_bwa_sort_markdup_realign_recal.raw.snps.indels.vcf \

    -mode SNP \

    --ts_filter_level 99.0 \

    -recalFile  ${out_dir}/recalibrate_SNP.recal \

    -tranchesFile  ${out_dir}/recalibrate_SNP.tranches \

    -o ${out_dir}/exfilter_recalibrated_snps_raw_indels.vcf

####################################################################################################

#######################################VQSR: Build the INDEL recalibration model############################

####################################################################################################

echo  "########################VQSR: Build the INDEL recalibration model######################################"

java -jar GenomeAnalysisTK.jar \

    -T VariantRecalibrator \

    -nt 20 \

    -R  ${reference_file} \

    -input  ${out_dir}/exfilter_recalibrated_snps_raw_indels.vcf \

    -resource:mills,known=false,training=true,truth=true,prior=12.0  Mills_and_1000G_gold_standard.indels.b37.vcf \

    -resource:dbsnp,known=true,training=false,truth=false,prior=2.0  dbsnp_138.b37.vcf \

    -an QD \

    -an DP \

    -an FS \

    -an SOR \

    -an MQRankSum \

    -an ReadPosRankSum \

    -mode INDEL \

    -tranche 100.0 -tranche 99.9 -tranche 99.0 -tranche 90.0 \

    --maxGaussians 4 \

    -recalFile  ${out_dir}/recalibrate_INDEL.recal \

    -tranchesFile ${out_dir}/recalibrate_INDEL.tranches \

    -rscriptFile ${out_dir}/recalibrate_INDEL_plots.R

####################################################################################################

######################### Apply the desired level of recalibration to INDELs in the call set#######################

####################################################################################################

echo  "################### Apply the desired level of recalibration to INDELs in the call set########################"

java -jar GenomeAnalysisTK.jar \

    -T ApplyRecalibration \

    -ef \

    -nt 20 \

    -R  ${reference_file} \

    -input  ${out_dir}/exfilter_recalibrated_snps_raw_indels.vcf \

    -mode INDEL \

    --ts_filter_level 99.0 \

    -recalFile  ${out_dir}/recalibrate_INDEL.recal \

    -tranchesFile ${out_dir}/recalibrate_INDEL.tranches \

    -o ${out_dir}/exfilter_recalibrated_variants.vcf

你可能感兴趣的:(GATK's Pipeline for calling variants with wgs data)