-
Notifications
You must be signed in to change notification settings - Fork 1
/
beagle4-imputation.sh
executable file
·87 lines (76 loc) · 2.16 KB
/
beagle4-imputation.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
#!/usr/bin/env bash
# trace date
PS4='+ $(date "+%x %T %Z")\011 '
# terminate the script immediately if there is a error
set -e
# programs
bcftools=bcftools
beagle4=/maps/projects/seqafrica/people/rlk420/bos/imputation/beagle.27Jan18.7e1.jar
runBeagle4() {
VCF=$1
OUT=$2
MAF=$3
echo "start running beagle v4.1 by chr"
# chrs=$(bcftools index -s $VCF | cut -f1 | tail -n+$1 | head -n $2)
chrs=$(${bcftools} index -s $VCF | cut -f1) # may change chr name patterns to your own
for chrom in $chrs; do
{
# convert PL tag to GL in beagle format
indir=$OUT/gl
mkdir -p $indir
bname=$indir/$(basename $VCF).$chrom
input=${bname}.vcf.gz
if [ ! -s $input ];then
${bcftools} view -r $chrom -q $MAF:minor -Oz -o $input $VCF
fi
# run imputation
outdir=$OUT/imputed
mkdir -p $outdir
outpre=$outdir/$(basename $bname)
out=$outpre.vcf.gz
# the output of beagle3 is [output prefix].[input].[ext]
if [ ! -s $out ];then
java -Xss5m -Xmx60g -Djava.io.tmpdir=$outdir -jar $beagle4 gl=$input chrom=$chrom out=$outpre nthreads=6
fi
} &
done
wait
echo "beagle4 imputation done"
echo "start concating files"
}
showhelp() {
# `cat << EOF` This means that cat should stop reading when EOF is detected
cat <<EOF
Usage: beagle4-imputation.sh [options]
Pipeline of genotype refinement for median depth sequencing data using beagle4.1
-h, Display help
-i, Input VCF/BCF file
-o, Output folder
-f, MAF filters before imputation
EOF
exit 1
}
while getopts ":h:i:f:o:" OPT; do
case "${OPT}" in
h)
showhelp
;;
i)
VCF=${OPTARG}
;;
o)
OUT=${OPTARG}
;;
f)
MAF=${OPTARG}
;;
*)
showhelp
;;
esac
done
shift $((OPTIND - 1))
if [ -z "${VCF}" ] || [ -z "${OUT}" ] || [ -z "${MAF}" ]; then
showhelp
fi
runBeagle4 $VCF $OUT $MAF && echo "runBeagle4 done"