-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnp_alignment.sh
executable file
·119 lines (110 loc) · 2.69 KB
/
snp_alignment.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
#!/bin/bash
scriptName=snp_alignment
version="v0.1"
jar_dir="$HOME/Applications/xxx"
jar_name="GenotypeHarmonizer"
############################################################
# The help function #
############################################################
help()
{
echo "Member of script series for automatizing workflow for GWAS prephasing and imputation."
echo " Step 1: Alignment of the SNPs."
echo
echo "Syntax: snp_alignment -h|[p]|[n]|i|r|v|V"
echo "options:"
echo "h Print this Help."
echo "p Specify path to the jar file."
echo " Default value: ~/Applications/xxx"
echo "n Specify name of the jar file."
echo " Default value: GenotypeHarmonizer"
echo "i Path to input study gwas files, PLINK file prefix only."
echo "r Path to reference, PLINK file prefix only."
echo "v Verbose mode."
echo "V Print software version and exit."
echo
}
check_if_dir ()
{
if [ ! -d "$1" ]
then
echo "Specified directory $1 doesn't exist."
exit
fi
}
check_if_file ()
{
if [ ! -f "$1" ]
then
echo "Specified file $1 doesn't exist."
exit
fi
}
############################################################
# Main function #
############################################################
# Get options
optstr="hp:n:i:r:vV"
while getopts ${optstr} option; do
case $option in
h | \?) # display Help
help
exit
;;
p) # set *.jar path
check_if_dir ${OPTARG}
jar_dir=${OPTARG}
# if [ ! -d "${jar_dir}" ]
# then
# echo "Specified directory for the .jar file doesn't exist."
# exit
# fi
# check trailing slash
if [ ! "${jar_dir: -1}" = "/" ]
then
jar_dir="${jar_dir}/"
fi
;;
n) # set *.jar name
check_if_file ${OPTARG}
jar_name=${OPTARG}
# full_file_name=$(basename "$OPTARG")
# file_dir=$(dirname "$OPTARG")
# file_dir="${file_dir}/"
# out_dir="${file_dir}"
;;
i) # get path to input files
check_if_dir ${OPTARG}
input_dir=${OPTARG}
# check trailing slash
if [ ! "${input_dir: -1}" = "/" ]
then
input_dir="${input_dir}/"
fi
;;
r) # get path to reference files
check_if_dir ${OPTARG}
ref_dir=${OPTARG}
# check trailing slash
if [ ! "${ref_dir: -1}" = "/" ]
then
ref_dir="${ref_dir}/"
fi
;;
v) # turn on verbose
verbose=1
;;
V) # print software version
echo "$scriptName $version"
exit
esac
done
# mkdir alignment
java -Xmx40g -jar ${jar_dir}${jar_name}.jar \
--inputType PLINK_BED \
--input ${input_dir} \ # PLINK file prefix only
--update-id \
--outputType PLINK_BED \
--output alignment/all_chrs \
--refType PLINK_BED \
--ref ${ref_dir} # PLINK file prefix only