comparison blast2html.py @ 27:4e6ac737ba17

improve the galaxy html stripping warning; make sure the tool can find the template from within galaxy
author Jan Kanis <jan.code@jankanis.nl>
date Thu, 15 May 2014 16:46:09 +0200
parents c8347745bbad
children bfc82a8aa3c9
comparison
equal deleted inserted replaced
26:eee23a36c582 27:4e6ac737ba17
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 # Actually runs under either python 2 or 3
2 3
3 # Copyright The Hyve B.V. 2014 4 # Copyright The Hyve B.V. 2014
4 # License: GPL version 3 or higher 5 # License: GPL version 3 or higher
5 6
6 import sys 7 import sys
271 e_value = "{:.4g}".format(min(hsp_val('Hsp_evalue'))), 272 e_value = "{:.4g}".format(min(hsp_val('Hsp_evalue'))),
272 # FIXME: is this the correct formula vv? 273 # FIXME: is this the correct formula vv?
273 ident = "{:.0%}".format(float(min(hsp.Hsp_identity / blastxml_len(hsp) for hsp in hsps))), 274 ident = "{:.0%}".format(float(min(hsp.Hsp_identity / blastxml_len(hsp) for hsp in hsps))),
274 accession = hit.Hit_accession) 275 accession = hit.Hit_accession)
275 276
277
276 def main(): 278 def main():
277 279 default_template = path.join(path.dirname(__file__), 'blast2html.html.jinja')
280
278 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page", 281 parser = argparse.ArgumentParser(description="Convert a BLAST XML result into a nicely readable html page",
279 usage="{} [-i] INPUT [-o OUTPUT]".format(sys.argv[0])) 282 usage="{} [-i] INPUT [-o OUTPUT]".format(sys.argv[0]))
280 input_group = parser.add_mutually_exclusive_group(required=True) 283 input_group = parser.add_mutually_exclusive_group(required=True)
281 input_group.add_argument('positional_arg', metavar='INPUT', nargs='?', type=argparse.FileType(mode='r'), 284 input_group.add_argument('positional_arg', metavar='INPUT', nargs='?', type=argparse.FileType(mode='r'),
282 help='The input Blast XML file, same as -i/--input') 285 help='The input Blast XML file, same as -i/--input')
287 # We just want the file name here, so jinja can open the file 290 # We just want the file name here, so jinja can open the file
288 # itself. But it is easier to just use a FileType so argparse can 291 # itself. But it is easier to just use a FileType so argparse can
289 # handle the errors. This introduces a small race condition when 292 # handle the errors. This introduces a small race condition when
290 # jinja later tries to re-open the template file, but we don't 293 # jinja later tries to re-open the template file, but we don't
291 # care too much. 294 # care too much.
292 parser.add_argument('--template', type=argparse.FileType(mode='r'), default='blast2html.html.jinja', 295 parser.add_argument('--template', type=argparse.FileType(mode='r'), default=default_template,
293 help='The template file to use. Defaults to blast_html.html.jinja') 296 help='The template file to use. Defaults to blast_html.html.jinja')
294 297
295 args = parser.parse_args() 298 args = parser.parse_args()
296 if args.input == None: 299 if args.input == None:
297 args.input = args.positional_arg 300 args.input = args.positional_arg