-
Notifications
You must be signed in to change notification settings - Fork 31
/
VizAlnPdf
executable file
·71 lines (63 loc) · 2.99 KB
/
VizAlnPdf
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
#!/bin/bash
#
if [ "$#" -eq 6 ]; then
# Make sure tabix is installed
hash tabix 2>/dev/null || { echo >&2 "ERROR: VizAlnPdf requires tabix. Please check that it's appropriately installed"; exit 1; }
# Make sure python is installed
hash python 2>/dev/null || { echo >&2 "ERROR: VizAlnPdf requires python. Please check that it's appropriately installed"; exit 1; }
# Make sure the required python packages are installed
python -c "from reportlab.graphics import renderPDF" 2>/dev/null || { echo >&2 "ERROR: VizAlnPdf requires the reportlab python package. Please check that it's appropriately installed"; exit 1; }
python -c "from svglib.svglib import svg2rlg" 2>/dev/null || { echo >&2 "ERROR: VizAlnPdf requires the svglib python package. 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: VizAlnPdf 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: VizAlnPdf requires the html.parser python package. Please check that it's appropriately installed"; exit 1; }
else
echo >&2 "ERROR: VizAlnPdf 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`
sample=$4
f=$5
tabix $1 $chrom:$start-$stop -h | awk -v START=$start '$2 == START || $2 == "#"' | awk -v SAMPLE=$4 '$4 == SAMPLE || $4 == "ALL"' | awk -v N=$6 'NR%N == 0 || $7 == "class=\"samplename\"" || $4 == "ALL"' | cut -f 1-4 --complement | python ${parent_path}/scripts/generate_aln_html.py | python ${parent_path}/scripts/html_alns_to_pdf.py $f
rm $f.svg
open $f.pdf 2>/dev/null || { echo >&2 "VizAlnPdf successfully generated the alignment visualization file, but failed to open it. Please open $f.pdf using a PDF viewer";}
else
cat <<usage
Usage: VizAlnPdf alns.html.gz chrom start sample out n
Generate a PDF containing every Nth alignment for a sample at an STR locus
Requires tabix and a bgzipped file with a corresponding .tbi index
Writes the results to out.pdf and opens the resulting PDF
usage
fi