-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcdr-merge-VCF-predict.sh
executable file
·80 lines (66 loc) · 2.04 KB
/
mcdr-merge-VCF-predict.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
if [ $# -ne 2 ] ; then
echo "Error !!! Requires 2 arguments. $# argument(s) provided. Exiting ... (ERR_CODE: 1000)"
exit 1000
fi
declare vcflib_path
declare script_path
declare input_folder
declare input_count
declare output_folder
declare -a files
declare -a input_ids
script_path="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/"
source $script_path"config.sh"
input_folder=$1
output_folder=$2
source $script_path"config.sh"
if [ ! -d "$input_folder" ] ; then
echo "Error !!! Invalid 'input_folder' given. Exiting ... (ERR_CODE: 1001)"
exit 1001
fi
if [ ! -d "$output_folder" ] ; then
echo "Error !!! Invalid 'output_folder' given. Exiting ... (ERR_CODE: 1002)"
exit 1002
fi
if [ "${input_folder[@]: -1: 1}" != "/" ] ; then
input_folder="$input_folder/"
fi
if [ "${output_folder[@]: -1: 1}" != "/" ] ; then
output_folder="$output_folder/"
fi
# files=(`ls $input_folder*.vcf`)
files=(`find $input_folder -maxdepth 1 -type f -name "*.vcf"`)
for ((i=0,j=0; i<${#files[@]}; ++i)) ; do
declare temp
temp=${files[$i]##*/}
temp=${temp%%.*}
temp=${temp%_*}
if [[ ! " ${input_ids[*]} " =~ " $temp " ]]; then
input_ids[$j]=$temp
((j=j+1))
fi
# echo $j" => "$temp" => "${input_ids[j-1]}
unset temp
done
input_count=${#input_ids[@]}
if [[ $input_count -eq 0 ]] ; then
echo "Error !!! No input VCF files. Exiting ... (ERR_CODE: 1001)"
exit 1001
elif [[ $input_count -gt 1 ]] ; then
echo "Error !!! More than one input VCF files. Exiting ... (ERR_CODE: 1001)"
exit 1001
fi
echo "Running with following arguments:"
echo "script_path = $script_path"
echo "input_folder = $input_folder"
echo "Sample IDs = {"${input_ids[@]}"}"
echo "output_folder = $output_folder"
echo "vcflib_path = $vcflib_path"
echo ""
echo "Doing vcf2tsv ..."
$vcflib_path vcfbreakmulti $input_folder${input_ids[0]}".vcf" | $vcflib_path vcf2tsv -g > $output_folder${input_ids[0]}".tsv"
echo "Done vcf2tsv. Exit status $?"
echo ""
echo "Doing predictions ..."
Rscript $script_path"predict_batch.R" $script_path"data/" $output_folder${input_ids[0]}".tsv" $output_folder
echo "Done predictions"