-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathextract-snp-dists.sh
51 lines (43 loc) · 1.31 KB
/
extract-snp-dists.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
#!/bin/bash
#print the options
usage () {
echo ""
echo "This bash script extracts pair-wise SNP distance from a list using snp-dists csv output"
echo "snp-dists output in molten csv format is needed"
echo ""
echo "Usage: $0 [options] LIST snp-dists-OUTPUT.csv"
echo "Option:"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
echo ""
echo "Version 1.0"
echo "Author: Raymond Kiu Raymond.Kiu@quadram.ac.uk"
echo "";
}
version () { echo "version 1.0 (2020)";}
author () { echo "Author: Raymond Kiu Raymond.Kiu@quadram.ac.uk";}
if (($# == 0))
then
echo "No positional arguments specified"
exit 0
fi
while getopts 'hav' opt;do
case $opt in
h) usage; exit;;
a) author; exit;;
v) version; exit;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
:) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
*) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
LIST=$1
SNPDIST=$2
awk -F "," 'NR==FNR { a[$1]=$0 ; next } $1 in a { print $0 }' $LIST $SNPDIST > $1-filtered
awk -F "," 'NR==FNR { a[$1]=$0 ; next } $2 in a { print $0 }' $LIST $1-filtered > $1-COUNT
# Extract counts eliminating self comparison
awk -F "," '{ if ($1!~$2) print $1","$2","$3}' $1-COUNT
# Remove intermediary files
rm $1-filtered
rm $1-COUNT