Mercurial > repos > jankanis > blast2html
comparison blast2html.py @ 50:bfc82a8aa3c9
unicodify python sources
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Wed, 21 May 2014 18:17:03 +0200 |
parents | 4e6ac737ba17 |
children | b15a20c2372a |
comparison
equal
deleted
inserted
replaced
49:85f757f4fcd5 | 50:bfc82a8aa3c9 |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | |
3 # | |
2 # Actually runs under either python 2 or 3 | 4 # Actually runs under either python 2 or 3 |
3 | 5 |
4 # Copyright The Hyve B.V. 2014 | 6 # Copyright The Hyve B.V. 2014 |
5 # License: GPL version 3 or higher | 7 # License: GPL version 3 or higher |
8 | |
9 from __future__ import unicode_literals | |
6 | 10 |
7 import sys | 11 import sys |
8 import math | 12 import math |
9 import warnings | 13 import warnings |
10 from os import path | 14 from os import path |
167 def __init__(self, input, templatedir, templatename): | 171 def __init__(self, input, templatedir, templatename): |
168 self.input = input | 172 self.input = input |
169 self.templatename = templatename | 173 self.templatename = templatename |
170 | 174 |
171 self.blast = objectify.parse(self.input).getroot() | 175 self.blast = objectify.parse(self.input).getroot() |
172 self.loader = jinja2.FileSystemLoader(searchpath=templatedir) | 176 self.loader = jinja2.FileSystemLoader(searchpath=templatedir, encoding='utf-8') |
173 self.environment = jinja2.Environment(loader=self.loader, | 177 self.environment = jinja2.Environment(loader=self.loader, |
174 lstrip_blocks=True, trim_blocks=True, autoescape=True) | 178 lstrip_blocks=True, trim_blocks=True, autoescape=True) |
175 | 179 |
176 self._addfilters(self.environment) | 180 self._addfilters(self.environment) |
177 | 181 |
281 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page", | 285 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page", |
282 usage="{} [-i] INPUT [-o OUTPUT]".format(sys.argv[0])) | 286 usage="{} [-i] INPUT [-o OUTPUT]".format(sys.argv[0])) |
283 input_group = parser.add_mutually_exclusive_group(required=True) | 287 input_group = parser.add_mutually_exclusive_group(required=True) |
284 input_group.add_argument('positional_arg', metavar='INPUT', nargs='?', type=argparse.FileType(mode='r'), | 288 input_group.add_argument('positional_arg', metavar='INPUT', nargs='?', type=argparse.FileType(mode='r'), |
285 help='The input Blast XML file, same as -i/--input') | 289 help='The input Blast XML file, same as -i/--input') |
286 input_group.add_argument('-i', '--input', type=argparse.FileType(mode='r'), | 290 input_group.add_argument('-i', '--input', type=argparse.FileType(mode='r', encoding='utf-8'), |
287 help='The input Blast XML file') | 291 help='The input Blast XML file') |
288 parser.add_argument('-o', '--output', type=argparse.FileType(mode='w'), default=sys.stdout, | 292 parser.add_argument('-o', '--output', type=argparse.FileType(mode='w', encoding='utf-8'), default=sys.stdout, |
289 help='The output html file') | 293 help='The output html file') |
290 # We just want the file name here, so jinja can open the file | 294 # We just want the file name here, so jinja can open the file |
291 # itself. But it is easier to just use a FileType so argparse can | 295 # itself. But it is easier to just use a FileType so argparse can |
292 # handle the errors. This introduces a small race condition when | 296 # handle the errors. This introduces a small race condition when |
293 # jinja later tries to re-open the template file, but we don't | 297 # jinja later tries to re-open the template file, but we don't |
294 # care too much. | 298 # care too much. |
295 parser.add_argument('--template', type=argparse.FileType(mode='r'), default=default_template, | 299 parser.add_argument('--template', type=argparse.FileType(mode='r', encoding='utf-8'), default=default_template, |
296 help='The template file to use. Defaults to blast_html.html.jinja') | 300 help='The template file to use. Defaults to blast_html.html.jinja') |
297 | 301 |
298 args = parser.parse_args() | 302 args = parser.parse_args() |
299 if args.input == None: | 303 if args.input == None: |
300 args.input = args.positional_arg | 304 args.input = args.positional_arg |