-
Notifications
You must be signed in to change notification settings - Fork 31
/
VizAln
executable file
·74 lines (66 loc) · 2.68 KB
/
VizAln
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
#!/bin/bash
#
# Usage: VizAln alns.html.gz chrom start [sample]
# View alignments for an STR in a browser
# Requires tabix and a bgzipped
# file with a corresponding .tbi index
if [ "$#" -eq 3 ] || [ "$#" -eq 4 ]; then
# Make sure tabix is installed
hash tabix 2>/dev/null || { echo >&2 "ERROR: VizAln requires tabix. Please check that it's appropriately installed"; exit 1; }
# Make sure python is installed
hash python 2>/dev/null || { echo >&2 "ERROR: VizAln requires python. Please check that it's appropriately installed"; exit 1; }
# Determine whether it's python2 or python3 and make sure the required python packages are installed
version=`python -c "import sys; print(sys.version_info[0])"`
if [ $version == 2 ]
then
python -c "import HTMLParser" 2>/dev/null || { echo >&2 "ERROR: VizAln requires the HTMLParser python package. Please check that it's appropriately installed"; exit 1; }
elif [ $version == 3 ]
then
python -c "import html.parser" 2>/dev/null || { echo >&2 "ERROR: VizAln requires the html.parser python package. Please check that it's appropriately installed"; exit 1; }
else
echo >&2 "ERROR: VizAln only supports python 2 or python 3. Please check that it's appropriately installed"; exit 1;
fi
# Make sure the file exists
if [ ! -e $1 ]
then
cat <<msg
ERROR: Alignment file $1 does not exist
msg
exit 1
fi
# Make sure the file ends in .gz
if [ ! ${1: -3} == ".gz" ]
then
cat <<usage
ERROR: The alignment file must be bgzipped (and end in .gz)
usage
exit 1
fi
# Make sure the tabix index exists
if [ ! -e $1.tbi ]
then
cat<<msg
ERROR: No .tbi file for alignment file. Index using the following command:
tabix -p bed $1
msg
exit 1
fi
parent_path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
chrom=$2
start=$3
stop=`expr $start + 100`
f="/tmp/vizaln.$RANDOM.html"
if [ "$#" -eq 3 ]
then
tabix $1 $chrom:$start-$stop -h | awk -v START=$start '$2 == START || $2 == "#"' | cut -f 1-4 --complement | python ${parent_path}/scripts/generate_aln_html.py > $f
else
tabix $1 $chrom:$start-$stop -h | awk -v START=$start '$2 == START || $2 == "#"' | awk -v SAMPLE=$4 '$4 == SAMPLE || $4 == "ALL"' | cut -f 1-4 --complement | python ${parent_path}/scripts/generate_aln_html.py > $f
fi
open $f 2>/dev/null || { echo >&2 "VizAln successfully generated the alignment visualization file, but failed to open it. Please open $f using a web browser";}
else
cat <<usage
Usage: VizAln alns.html.gz chrom start [sample]
View alignments for an STR in a browser
Requires tabix and a bgzipped file with a corresponding .tbi index
usage
fi