Mercurial > repos > jankanis > blast2html
annotate blast2html.py @ 95:4378d11f0ed7
implement configurable gene bank links
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Mon, 30 Jun 2014 16:49:45 +0200 |
parents | 9fb1a7d67317 |
children | 02b795b784e1 |
rev | line source |
---|---|
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
50 | 2 # -*- coding: utf-8 -*- |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
3 |
75 | 4 # Actually this program works with both python 2 and 3, tested against python 2.6 |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
5 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
6 # Copyright The Hyve B.V. 2014 |
72 | 7 # License: GPL version 3 or (at your option) any higher version |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
8 |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
9 from __future__ import unicode_literals, division |
50 | 10 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
11 import sys |
7
9e7927673089
intermediate commit before converting some tables to divs
Jan Kanis <jan.code@jankanis.nl>
parents:
5
diff
changeset
|
12 import math |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
13 import warnings |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
14 import six, codecs |
75 | 15 from six.moves import builtins |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
16 from os import path |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
17 from itertools import repeat |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
18 from collections import defaultdict |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
19 import argparse |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
20 from lxml import objectify |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
21 import jinja2 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
22 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
23 builtin_str = str |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
24 str = six.text_type |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
25 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
26 |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
27 |
76
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
28 _filters = dict(float='float') |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
29 def filter(func_or_name): |
11
7660519f2dc9
proper layout for alignments, added some links
Jan Kanis <jan.code@jankanis.nl>
parents:
10
diff
changeset
|
30 "Decorator to register a function as filter in the current jinja environment" |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
31 if isinstance(func_or_name, six.string_types): |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
32 def inner(func): |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
33 _filters[func_or_name] = func.__name__ |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
34 return func |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
35 return inner |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
36 else: |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
37 _filters[func_or_name.__name__] = func_or_name.__name__ |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
38 return func_or_name |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
39 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
40 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
41 def color_idx(length): |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
42 if length < 40: |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
43 return 0 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
44 elif length < 50: |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
45 return 1 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
46 elif length < 80: |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
47 return 2 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
48 elif length < 200: |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
49 return 3 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
50 return 4 |
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
51 |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
52 @filter |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
53 def fmt(val, fmt): |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
54 return format(float(val), fmt) |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
55 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
56 @filter |
76
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
57 def numfmt(val): |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
58 """Format numbers in decimal notation, but without excessive trailing 0's. |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
59 Default python float formatting will use scientific notation for some values, |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
60 or append trailing zeros with the 'f' format type, and the number of digits differs |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
61 between python 2 and 3.""" |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
62 fpart, ipart = math.modf(val) |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
63 if fpart == 0: |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
64 return str(int(val)) |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
65 # round to 10 to get identical representations in python 2 and 3 |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
66 s = format(round(val, 10), '.10f').rstrip('0') |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
67 if s[-1] == '.': |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
68 s += '0' |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
69 return s |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
70 |
7d0d46168fd5
Format all numbers in a predictable way
Jan Kanis <jan.code@jankanis.nl>
parents:
75
diff
changeset
|
71 @filter |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
72 def firsttitle(hit): |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
73 return hit.Hit_def.text.split('>')[0] |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
74 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
75 @filter |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
76 def othertitles(hit): |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
77 """Split a hit.Hit_def that contains multiple titles up, splitting out the hit ids from the titles.""" |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
78 id_titles = hit.Hit_def.text.split('>') |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
79 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
80 titles = [] |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
81 for t in id_titles[1:]: |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
82 id, title = t.split(' ', 1) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
83 titles.append(argparse.Namespace(Hit_id = id, |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
84 Hit_def = title, |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
85 Hit_accession = '', |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
86 getroottree = hit.getroottree)) |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
87 return titles |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
88 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
89 @filter |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
90 def hitid(hit): |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
91 return str(hit.Hit_id) |
24
c8347745bbad
use Iteration_message tag; also work with unexpected Hit_id values
Jan Kanis <jan.code@jankanis.nl>
parents:
23
diff
changeset
|
92 |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
93 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
94 @filter |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
95 def alignment_pre(hsp): |
68
fa8a93bdefd7
fix bug in calculations of alignment end
Jan Kanis <jan.code@jankanis.nl>
parents:
67
diff
changeset
|
96 """Create the preformatted alignment blocks""" |
71 | 97 |
98 # line break length | |
99 linewidth = 60 | |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
100 |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
101 qfrom = int(hsp['Hsp_query-from']) |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
102 qto = int(hsp['Hsp_query-to']) |
69 | 103 qframe = int(hsp['Hsp_query-frame']) |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
104 hfrom = int(hsp['Hsp_hit-from']) |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
105 hto = int(hsp['Hsp_hit-to']) |
69 | 106 hframe = int(hsp['Hsp_hit-frame']) |
71 | 107 |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
108 qseq = hsp.Hsp_qseq.text |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
109 midline = hsp.Hsp_midline.text |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
110 hseq = hsp.Hsp_hseq.text |
69 | 111 |
71 | 112 if not qframe in (1, -1): |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
113 warnings.warn("Error in BlastXML input: Hsp node {0} has a Hsp_query-frame of {1}. (should be 1 or -1)".format(nodeid(hsp), qframe)) |
69 | 114 qframe = -1 if qframe < 0 else 1 |
71 | 115 if not hframe in (1, -1): |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
116 warnings.warn("Error in BlastXML input: Hsp node {0} has a Hsp_hit-frame of {1}. (should be 1 or -1)".format(nodeid(hsp), hframe)) |
69 | 117 hframe = -1 if hframe < 0 else 1 |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
118 |
69 | 119 def split(txt): |
71 | 120 return [txt[i:i+linewidth] for i in range(0, len(txt), linewidth)] |
69 | 121 |
71 | 122 for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), linewidth)): |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
123 yield ( |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
124 "Query {0:>7} {1} {2}\n".format(qfrom+offset*qframe, qs, qfrom+(offset+len(qs)-1)*qframe) + |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
125 " {0:7} {1}\n".format('', mid) + |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
126 "Subject{0:>7} {1} {2}".format(hfrom+offset*hframe, hs, hfrom+(offset+len(hs)-1)*hframe) |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
127 ) |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
128 |
69 | 129 if qfrom+(len(qseq)-1)*qframe != qto: |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
130 warnings.warn("Error in BlastXML input: Hsp node {0} qseq length mismatch: from {1} to {2} length {3}".format( |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
131 nodeid(hsp), qfrom, qto, len(qseq))) |
69 | 132 if hfrom+(len(hseq)-1)*hframe != hto: |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
133 warnings.warn("Error in BlastXML input: Hsp node {0} hseq length mismatch: from {1} to {2} length {3}".format( |
67
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
134 nodeid(hsp), hfrom, hto, len(hseq))) |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
135 |
19c48f2ec775
wrap alignments if they are too long
Jan Kanis <jan.code@jankanis.nl>
parents:
53
diff
changeset
|
136 |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
137 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
138 @filter('len') |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
139 def blastxml_len(node): |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
140 if node.tag == 'Hsp': |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
141 return int(node['Hsp_align-len']) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
142 elif node.tag == 'Iteration': |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
143 return int(node['Iteration_query-len']) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
144 raise Exception("Unknown XML node type: "+node.tag) |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
145 |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
146 @filter |
53
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
147 def nodeid(node): |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
148 id = [] |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
149 if node.tag == 'Hsp': |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
150 id.insert(0, node.Hsp_num.text) |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
151 node = node.getparent().getparent() |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
152 assert node.tag == 'Hit' |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
153 if node.tag == 'Hit': |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
154 id.insert(0, node.Hit_num.text) |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
155 node = node.getparent().getparent() |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
156 assert node.tag == 'Iteration' |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
157 if node.tag == 'Iteration': |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
158 id.insert(0, node['Iteration_iter-num'].text) |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
159 return '-'.join(id) |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
160 raise ValueError("The nodeid filter can only be applied to Hsp, Hit or Iteration nodes in a BlastXML document") |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
161 |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
162 |
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
163 @filter |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
164 def asframe(frame): |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
165 if frame == 1: |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
166 return 'Plus' |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
167 elif frame == -1: |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
168 return 'Minus' |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
169 raise Exception("frame should be either +1 or -1") |
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
170 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
171 # def genelink(hit, type='genbank', hsp=None): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
172 # if not isinstance(hit, six.string_types): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
173 # hit = hitid(hit) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
174 # link = "http://www.ncbi.nlm.nih.gov/nucleotide/{0}?report={1}&log$=nuclalign".format(hit, type) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
175 # if hsp != None: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
176 # link += "&from={0}&to={1}".format(hsp['Hsp_hit-from'], hsp['Hsp_hit-to']) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
177 # return link |
16 | 178 |
179 | |
180 # javascript escape filter based on Django's, from https://github.com/dsissitka/khan-website/blob/master/templatefilters.py#L112-139 | |
181 # I've removed the html escapes, since html escaping is already being performed by the template engine. | |
7
9e7927673089
intermediate commit before converting some tables to divs
Jan Kanis <jan.code@jankanis.nl>
parents:
5
diff
changeset
|
182 |
74
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
183 # The r'\u0027' syntax doesn't work the way we need to in python 2.6 with unicode_literals |
16 | 184 _base_js_escapes = ( |
74
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
185 ('\\', '\\u005C'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
186 ('\'', '\\u0027'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
187 ('"', '\\u0022'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
188 # ('>', '\\u003E'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
189 # ('<', '\\u003C'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
190 # ('&', '\\u0026'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
191 # ('=', '\\u003D'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
192 # ('-', '\\u002D'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
193 # (';', '\\u003B'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
194 (u'\u2028', '\\u2028'), |
03e044b5bcc2
fix escaping of javascript literals
Jan Kanis <jan.code@jankanis.nl>
parents:
73
diff
changeset
|
195 (u'\u2029', '\\u2029') |
16 | 196 ) |
197 | |
198 # Escape every ASCII character with a value less than 32. This is | |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
199 # needed a.o. to prevent html parsers from jumping out of javascript |
16 | 200 # parsing mode. |
201 _js_escapes = (_base_js_escapes + | |
202 tuple(('%c' % z, '\\u%04X' % z) for z in range(32))) | |
203 | |
204 @filter | |
205 def js_string_escape(value): | |
72 | 206 """ |
207 Javascript string literal escape. Note that this only escapes data | |
208 for embedding within javascript string literals, not in general | |
209 javascript snippets. | |
210 """ | |
16 | 211 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
212 value = str(value) |
16 | 213 |
214 for bad, good in _js_escapes: | |
215 value = value.replace(bad, good) | |
216 | |
217 return value | |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
218 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
219 @filter |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
220 def hits(result): |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
221 # sort hits by longest hotspot first |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
222 return sorted(result.Iteration_hits.findall('Hit'), |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
223 key=lambda h: max(blastxml_len(hsp) for hsp in h.Hit_hsps.Hsp), |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
224 reverse=True) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
225 |
7
9e7927673089
intermediate commit before converting some tables to divs
Jan Kanis <jan.code@jankanis.nl>
parents:
5
diff
changeset
|
226 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
227 |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
228 class BlastVisualize: |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
229 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
230 colors = ('black', 'blue', 'green', 'magenta', 'red') |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
231 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
232 max_scale_labels = 10 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
233 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
234 def __init__(self, input, templatedir, templatename, genelinks={}): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
235 self.input = input |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
236 self.templatename = templatename |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
237 self.genelinks = genelinks |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
238 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
239 self.blast = objectify.parse(self.input).getroot() |
79
9fb1a7d67317
remove unneeded encoding parameter
Jan Kanis <jan.code@jankanis.nl>
parents:
78
diff
changeset
|
240 self.loader = jinja2.FileSystemLoader(searchpath=templatedir) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
241 self.environment = jinja2.Environment(loader=self.loader, |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
242 lstrip_blocks=True, trim_blocks=True, autoescape=True) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
243 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
244 self._addfilters(self.environment) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
245 |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
246 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
247 def _addfilters(self, environment): |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
248 for filtername, funcname in _filters.items(): |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
249 try: |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
250 environment.filters[filtername] = getattr(self, funcname) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
251 except AttributeError: |
75 | 252 try: |
253 environment.filters[filtername] = globals()[funcname] | |
254 except KeyError: | |
255 environment.filters[filtername] = getattr(builtins, funcname) | |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
256 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
257 def render(self, output): |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
258 template = self.environment.get_template(self.templatename) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
259 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
260 params = (('Query ID', self.blast["BlastOutput_query-ID"]), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
261 ('Query definition', self.blast["BlastOutput_query-def"]), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
262 ('Query length', self.blast["BlastOutput_query-len"]), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
263 ('Program', self.blast.BlastOutput_version), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
264 ('Database', self.blast.BlastOutput_db), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
265 ) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
266 |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
267 result = template.render(blast=self.blast, |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
268 iterations=self.blast.BlastOutput_iterations.Iteration, |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
269 colors=self.colors, |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
270 params=params) |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
271 if six.PY2: |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
272 result = result.encode('utf-8') |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
273 output.write(result) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
274 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
275 @filter |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
276 def match_colors(self, result): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
277 """ |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
278 An iterator that yields lists of length-color pairs. |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
279 """ |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
280 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
281 query_length = blastxml_len(result) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
282 |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
283 percent_multiplier = 100 / query_length |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
284 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
285 for hit in hits(result): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
286 # sort hotspots from short to long, so we can overwrite index colors of |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
287 # short matches with those of long ones. |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
288 hotspots = sorted(hit.Hit_hsps.Hsp, key=lambda hsp: blastxml_len(hsp)) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
289 table = bytearray([255]) * query_length |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
290 for hsp in hotspots: |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
291 frm = hsp['Hsp_query-from'] - 1 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
292 to = int(hsp['Hsp_query-to']) |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
293 table[frm:to] = repeat(color_idx(blastxml_len(hsp)), to - frm) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
294 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
295 matches = [] |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
296 last = table[0] |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
297 count = 0 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
298 for i in range(query_length): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
299 if table[i] == last: |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
300 count += 1 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
301 continue |
16 | 302 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'transparent')) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
303 last = table[i] |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
304 count = 1 |
16 | 305 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'transparent')) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
306 |
53
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
307 yield dict(colors=matches, hit=hit, defline=firsttitle(hit)) |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
308 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
309 @filter |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
310 def queryscale(self, result): |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
311 query_length = blastxml_len(result) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
312 skip = math.ceil(query_length / self.max_scale_labels) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
313 percent_multiplier = 100 / query_length |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
314 for i in range(1, query_length+1): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
315 if i % skip == 0: |
23 | 316 yield dict(label = i, width = skip * percent_multiplier) |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
317 if query_length % skip != 0: |
20
53cd304c5f26
Add index for multiple results; fix layout of query ruler for edge case
Jan Kanis <jan.code@jankanis.nl>
parents:
19
diff
changeset
|
318 yield dict(label = query_length, |
23 | 319 width = (query_length % skip) * percent_multiplier) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
320 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
321 @filter |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
322 def hit_info(self, result): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
323 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
324 query_length = blastxml_len(result) |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
325 |
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
326 for hit in hits(result): |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
327 hsps = hit.Hit_hsps.Hsp |
7
9e7927673089
intermediate commit before converting some tables to divs
Jan Kanis <jan.code@jankanis.nl>
parents:
5
diff
changeset
|
328 |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
329 cover = [False] * query_length |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
330 for hsp in hsps: |
19
67ddcb807b7d
make it work with multiple queries
Jan Kanis <jan.code@jankanis.nl>
parents:
18
diff
changeset
|
331 cover[hsp['Hsp_query-from']-1 : int(hsp['Hsp_query-to'])] = repeat(True, blastxml_len(hsp)) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
332 cover_count = cover.count(True) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
333 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
334 def hsp_val(path): |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
335 return (float(hsp[path]) for hsp in hsps) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
336 |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
337 yield dict(hit = hit, |
75 | 338 title = firsttitle(hit), |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
339 maxscore = "{0:.1f}".format(max(hsp_val('Hsp_bit-score'))), |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
340 totalscore = "{0:.1f}".format(sum(hsp_val('Hsp_bit-score'))), |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
341 cover = "{0:.0%}".format(cover_count / query_length), |
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
342 e_value = "{0:.4g}".format(min(hsp_val('Hsp_evalue'))), |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
343 # FIXME: is this the correct formula vv? |
78 | 344 # float(...) because non-flooring division doesn't work with lxml elements in python 2.6 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
345 ident = "{0:.0%}".format(float(min(float(hsp.Hsp_identity) / blastxml_len(hsp) for hsp in hsps)))) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
346 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
347 @filter |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
348 def genelink(self, hit, text=None, clas=None, display_nolink=True): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
349 if text is None: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
350 text = hitid(hit) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
351 db = hit.getroottree().getroot().BlastOutput_db |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
352 if isinstance(self.genelinks, six.string_types): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
353 template = self.genelinks |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
354 else: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
355 template = self.genelinks.get(db) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
356 if template is None: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
357 return text if display_nolink else '' |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
358 args = dict(id=hitid(hit).split('|'), |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
359 fullid=hitid(hit), |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
360 defline=str(hit.Hit_def).split('|'), |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
361 fulldefline=str(hit.Hit_def), |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
362 accession=str(hit.Hit_accession)) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
363 try: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
364 link = template.format(**args) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
365 except Exception as e: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
366 warnings.warn('Error in formatting gene bank link {} with {}: {}'.format(template, args, e)) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
367 return text if display_nolink else '' |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
368 classattr = 'class="{}" '.format(jinja2.escape(clas)) if clas is not None else '' |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
369 return jinja2.Markup("<a {}href=\"{}\">{}</a>".format(classattr, jinja2.escape(link), jinja2.escape(text))) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
370 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
371 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
372 def read_genelinks(dir): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
373 links = {} |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
374 for f in ('blastdb.loc', 'blastdb_p.loc', 'blastdb_d.loc'): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
375 try: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
376 f = open(path.join(dir, f)) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
377 for l in f.readlines(): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
378 if l.strip().startswith('#'): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
379 continue |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
380 line = l.split('\t') |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
381 try: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
382 links[line[2]] = line[3] |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
383 except IndexError: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
384 continue |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
385 f.close() |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
386 except OSError: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
387 continue |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
388 if not links: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
389 warnings.warn("No gene bank link templates found") |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
390 return links |
10
2fbdf2eb27b4
All data is displayed now, still some formatting to do
Jan Kanis <jan.code@jankanis.nl>
parents:
7
diff
changeset
|
391 |
27
4e6ac737ba17
improve the galaxy html stripping warning; make sure the tool can find the template from within galaxy
Jan Kanis <jan.code@jankanis.nl>
parents:
24
diff
changeset
|
392 |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
393 def main(): |
27
4e6ac737ba17
improve the galaxy html stripping warning; make sure the tool can find the template from within galaxy
Jan Kanis <jan.code@jankanis.nl>
parents:
24
diff
changeset
|
394 default_template = path.join(path.dirname(__file__), 'blast2html.html.jinja') |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
395 |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
396 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page", |
73
67b1a319c6dc
First go at 2.6 compatibility
Jan Kanis <jan.code@jankanis.nl>
parents:
72
diff
changeset
|
397 usage="{0} [-i] INPUT [-o OUTPUT]".format(sys.argv[0])) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
398 input_group = parser.add_mutually_exclusive_group(required=True) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
399 input_group.add_argument('positional_arg', metavar='INPUT', nargs='?', type=argparse.FileType(mode='r'), |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
400 help='The input Blast XML file, same as -i/--input') |
53
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
401 input_group.add_argument('-i', '--input', type=argparse.FileType(mode='r'), |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
402 help='The input Blast XML file') |
53
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
403 parser.add_argument('-o', '--output', type=argparse.FileType(mode='w'), default=sys.stdout, |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
404 help='The output html file') |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
405 # We just want the file name here, so jinja can open the file |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
406 # itself. But it is easier to just use a FileType so argparse can |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
407 # handle the errors. This introduces a small race condition when |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
408 # jinja later tries to re-open the template file, but we don't |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
409 # care too much. |
53
4217bb9cf1d3
depend on python 3; fix internal links with multiple iterations
Jan Kanis <jan.code@jankanis.nl>
parents:
51
diff
changeset
|
410 parser.add_argument('--template', type=argparse.FileType(mode='r'), default=default_template, |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
411 help='The template file to use. Defaults to blast_html.html.jinja') |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
412 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
413 dblink_group = parser.add_mutually_exclusive_group() |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
414 dblink_group.add_argument('--genelink-template', default='http://www.ncbi.nlm.nih.gov/nucleotide/{accession}?report=genbank&log$=nuclalign', |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
415 help="""A link template to link hits to a gene bank webpage. The template string is a |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
416 Python format string. It can contain the following replacement elements: {id[N]}, {fullid}, |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
417 {defline[N]}, {fulldefline}, {accession}, where N is a number. id[N] and defline[N] will be |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
418 replaced by the Nth element of the id or defline, where '|' is the field separator. |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
419 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
420 The default is 'http://www.ncbi.nlm.nih.gov/nucleotide/{accession}?report=genbank&log$=nuclalign', |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
421 which is a link to the NCBI nucleotide database.""") |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
422 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
423 dblink_group.add_argument('--db-config-dir', |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
424 help="""The directory where databases are configured in blastdb*.loc files. These files |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
425 are consulted for creating a gene bank link. The files should be tab-separated tables (with lines |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
426 starting with '#' ignored), where the third field of a line should be a database path and the fourth |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
427 a genebank link template conforming to the --genelink-template option syntax. |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
428 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
429 This option is incompatible with --genelink-template.""") |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
430 |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
431 args = parser.parse_args() |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
432 if args.input == None: |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
433 args.input = args.positional_arg |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
434 if args.input == None: |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
435 parser.error('no input specified') |
5
1df2bfce5c24
first features are working, partial match table
Jan Kanis <jan.code@jankanis.nl>
parents:
diff
changeset
|
436 |
18
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
437 templatedir, templatename = path.split(args.template.name) |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
438 args.template.close() |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
439 if not templatedir: |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
440 templatedir = '.' |
4434ffab721a
add a parameter for the template
Jan Kanis <jan.code@jankanis.nl>
parents:
16
diff
changeset
|
441 |
95
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
442 if args.db_config_dir is None: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
443 genelinks = args.genelink_template |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
444 elif not path.isdir(args.db_config_dir): |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
445 parser.error('db-config-dir does not exist or is not a directory') |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
446 else: |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
447 genelinks = read_genelinks(args.db_config_dir) |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
448 |
4378d11f0ed7
implement configurable gene bank links
Jan Kanis <jan.code@jankanis.nl>
parents:
79
diff
changeset
|
449 b = BlastVisualize(args.input, templatedir, templatename, genelinks) |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
450 b.render(args.output) |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
451 |
11
7660519f2dc9
proper layout for alignments, added some links
Jan Kanis <jan.code@jankanis.nl>
parents:
10
diff
changeset
|
452 |
12
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
453 if __name__ == '__main__': |
a459c754cdb5
add links, refactor, proper commandline arguments
Jan Kanis <jan.code@jankanis.nl>
parents:
11
diff
changeset
|
454 main() |
11
7660519f2dc9
proper layout for alignments, added some links
Jan Kanis <jan.code@jankanis.nl>
parents:
10
diff
changeset
|
455 |