run_FeBY2_prep_L2.sh.bak 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env bash
  2. ##Author: guochangquan
  3. ##Copyright 20210929
  4. ##company: NuProbe
  5. set -e
  6. function usage() {
  7. echo "Usage: $0 [ -s <sample> ] [ -i <fq_dir> ] [ -o <analysis_dir> ] [ -x <script_dir> ] [ -c <FeBY2_CNV_outdir> ]"
  8. echo "-s sample name"
  9. echo "-i input fastq dir"
  10. echo "-x script_dir"
  11. echo "-o analysis_dir"
  12. echo "-c FeBY2 CNV outdir"
  13. }
  14. if [ $# -eq 0 ]
  15. then
  16. usage
  17. exit
  18. fi
  19. while getopts ":s:c:x:o:i:h" opt; do
  20. case $opt in
  21. i)
  22. fq_dir=$OPTARG
  23. ;;
  24. o)
  25. out_dir=$OPTARG
  26. ;;
  27. s)
  28. sample=$OPTARG
  29. ;;
  30. c)
  31. cnv_dir=$OPTARG
  32. ;;
  33. x)
  34. feby2_script=$OPTARG
  35. ;;
  36. h)
  37. usage
  38. exit
  39. ;;
  40. \?)
  41. echo "Invalid option: -$OPTARG" > /dev/stderr
  42. usage
  43. exit
  44. ;;
  45. esac
  46. done
  47. echo "Input FASTQ dir:" $fq_dir
  48. echo "Output BAM dir:" $out_dir
  49. echo "Sample Name:" $sample
  50. echo "CNV Analysis dir:" $cnv_dir
  51. echo $feby2_script
  52. . $feby2_script/conf/feby2.cfg
  53. ### FASTQ TRIM and Mapping
  54. test -d $out_dir/${sample} || mkdir ${outdir}/${sample}
  55. cd $out_dir/${sample}
  56. $fastp -i ${fq_dir}/${sample}/${sample}_combined_R1.fastq.gz -I ${fq_dir}/${sample}/${sample}_combined_R2.fastq.gz -o ${sample}_1.fq.gz -O ${sample}_2.fq.gz -c --length_required 50 -q 20 -j ${sample}.fastp.json -h ${sample}.fastp.html
  57. $speedseq_dir/speedseq align -o ${sample} -M 20 -t 8 -R "@RG\tID:${sample}\tSM:${sample}\tLB:${sample}\tPL:ILLUMINA" $ref ${sample}_1.fq.gz ${sample}_2.fq.gz && rm ${sample}_1.fq.gz ${sample}_2.fq.gz
  58. ### SNV/INDEL CAll and annotation
  59. $gatk4 --java-options "-Xmx10g" HaplotypeCaller -R $ref -I ${sample}.bam -ip 20 -L $target_call -O ${sample}.gatk.vcf.gz
  60. /cgdata/CGTools/CGTools/wrapper/S14-annovar-snv-annotation.sh -w . -s ${sample}.gatk -v ${sample}.gatk.vcf.gz
  61. perl $exe_dir/snp_stat.pl $sample.gatk.hg19_multianno.txt
  62. python /cgdata/CGTools/CGTools/tools/T07-var-filter.py -i $sample.gatk.hg19_multianno.txt -o $sample.gatk.hg19_multianno.xlsx
  63. ### QC
  64. test -d conest/ || mkdir conest/
  65. $qualimap_dir/qualimap bamqc -bam ${sample}.bam -c --java-mem-size=20G -sd -gff ${target}
  66. $verify --vcf $bia_snp --bam ${sample}.bam --out conest/${sample}.verify --verbose --ignoreRG &
  67. $gatk4 CollectHsMetrics -I ${sample}.bam -BI $interval -TI $interval -O ${sample}_hs_metrics.txt -R $ref --COVERAGE_CAP 6000 -MQ 0 --CLIP_OVERLAPPING_READS false &
  68. $gatk4 GetPileupSummaries -I ${sample}.bam -L $target -V $bia_snp -max-af 0.99 -min-af 0.01 -O conest/${sample}.ps.tab
  69. $gatk4 CalculateContamination -I conest/${sample}.ps.tab -O conest/${sample}.contEST.tab
  70. wait
  71. ### yesuan
  72. $gatk4 HaplotypeCaller -R $ref -I ${sample}.bam --genotyping-mode GENOTYPE_GIVEN_ALLELES -L $ye_target --alleles $ye_site -O ${sample}.ye.vcf
  73. bcftools norm -m-both -o ${sample}.step1.vcf ${sample}.ye.vcf
  74. bcftools norm -f $ref -o ${sample}.step2.vcf ${sample}.step1.vcf
  75. $gatk4 VariantsToTable -V ${sample}.step2.vcf -O ${sample}.ye.norm.tab -F CHROM -F POS -F TYPE -GF GT -GF GQ -GF AD -F REF -F ALT --show-filtered && rm ${sample}.step2.vcf ${sample}.step1.vcf
  76. perl $ye_home/prep_FeBY2_plus.pl ${sample} FeBY2 $ye_ref
  77. ### prepare for CNV
  78. bamf=$out_dir/$sample/$sample.bam
  79. cd $cnv_dir
  80. samtools view -f 2 -F 1024 -F 2048 -hub $bamf \
  81. | samtools sort -n -l 0 -m 20G - |bamToBed -bedpe \
  82. | awk '$1!~/M/ && $1==$4 && $2!=-1 && $6-$2>0 && $6-$2<1000{print $1"\t"$2"\t"$6"\t"$7}' \
  83. | intersectBed -a - -b $cnv_target -loj -wb \
  84. | perl $feby2_script/script/get_GCcor2cov.pl $sample $ref $target_GCref $cnv_target b37 > $sample.gc.xls
  85. test -s $sample_?_QC_plot.pdf || Rscript $feby2_script/script/MBY2_CNV_stat.r $sample
  86. samtools view -hb -L $target $bamf > ${sample}.target.bam && samtools index ${sample}.target.bam && samtools idxstats ${sample}.target.bam > ${sample}.idxstats && rm ${sample}.target.bam*