Mercurial > repos > jankanis > blast2html2
comparison blast_html.py @ 16:db7e4ee3be03
fix validation, reindent
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Tue, 13 May 2014 12:22:35 +0200 |
parents | 648b3b7437da |
children | 4434ffab721a |
comparison
equal
deleted
inserted
replaced
15:648b3b7437da | 16:db7e4ee3be03 |
---|---|
92 if not isinstance(hit, str): | 92 if not isinstance(hit, str): |
93 hit = hitid(hit) | 93 hit = hitid(hit) |
94 link = "http://www.ncbi.nlm.nih.gov/nucleotide/{}?report={}&log$=nuclalign".format(hit, type) | 94 link = "http://www.ncbi.nlm.nih.gov/nucleotide/{}?report={}&log$=nuclalign".format(hit, type) |
95 if hsp != None: | 95 if hsp != None: |
96 link += "&from={}&to={}".format(hsp['Hsp_hit-from'], hsp['Hsp_hit-to']) | 96 link += "&from={}&to={}".format(hsp['Hsp_hit-from'], hsp['Hsp_hit-to']) |
97 return jinja2.Markup(link) | 97 return link |
98 | 98 |
99 | |
100 # javascript escape filter based on Django's, from https://github.com/dsissitka/khan-website/blob/master/templatefilters.py#L112-139 | |
101 # I've removed the html escapes, since html escaping is already being performed by the template engine. | |
102 | |
103 _base_js_escapes = ( | |
104 ('\\', r'\u005C'), | |
105 ('\'', r'\u0027'), | |
106 ('"', r'\u0022'), | |
107 # ('>', r'\u003E'), | |
108 # ('<', r'\u003C'), | |
109 # ('&', r'\u0026'), | |
110 # ('=', r'\u003D'), | |
111 # ('-', r'\u002D'), | |
112 # (';', r'\u003B'), | |
113 # (u'\u2028', r'\u2028'), | |
114 # (u'\u2029', r'\u2029') | |
115 ) | |
116 | |
117 # Escape every ASCII character with a value less than 32. This is | |
118 # needed a.o. to prevent parsers from jumping out of javascript | |
119 # parsing mode. | |
120 _js_escapes = (_base_js_escapes + | |
121 tuple(('%c' % z, '\\u%04X' % z) for z in range(32))) | |
122 | |
123 @filter | |
124 def js_string_escape(value): | |
125 """Escape javascript string literal escapes. Note that this only works | |
126 within javascript string literals, not in general javascript | |
127 snippets.""" | |
128 | |
129 value = str(value) | |
130 | |
131 for bad, good in _js_escapes: | |
132 value = value.replace(bad, good) | |
133 | |
134 return value | |
99 | 135 |
100 | 136 |
101 | 137 |
102 class BlastVisualize: | 138 class BlastVisualize: |
103 | 139 |
173 count = 0 | 209 count = 0 |
174 for i in range(self.query_length): | 210 for i in range(self.query_length): |
175 if table[i] == last: | 211 if table[i] == last: |
176 count += 1 | 212 count += 1 |
177 continue | 213 continue |
178 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'none')) | 214 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'transparent')) |
179 last = table[i] | 215 last = table[i] |
180 count = 1 | 216 count = 1 |
181 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'none')) | 217 matches.append((count * percent_multiplier, self.colors[last] if last != 255 else 'transparent')) |
182 | 218 |
183 yield dict(colors=matches, link="#hit"+hit.Hit_num.text, defline=firsttitle(hit)) | 219 yield dict(colors=matches, link="#hit"+hit.Hit_num.text, defline=firsttitle(hit)) |
184 | 220 |
185 | 221 |
186 def queryscale(self): | 222 def queryscale(self): |