# HG changeset patch # User Jan Kanis # Date 1403106632 -7200 # Node ID 4d2c25baf5a3aff771f3b7c9212306b1bb95d892 # Parent 03e044b5bcc2acb5a0a82951d2d77aa39b92f511 Fix rounding errors diff -r 03e044b5bcc2 -r 4d2c25baf5a3 blast2html.html.jinja --- a/blast2html.html.jinja Wed Jun 18 16:58:25 2014 +0200 +++ b/blast2html.html.jinja Wed Jun 18 17:50:32 2014 +0200 @@ -597,9 +597,9 @@ {{hsp['Hsp_bit-score']|fmt('.1f')}} bits({{hsp.Hsp_score}}) {{hsp.Hsp_evalue|fmt('.1f')}} {{ hsp.Hsp_identity }}/{{ hsp|len }}({{ - (hsp.Hsp_identity/hsp|len) |fmt('.0%') }}) + ((hsp.Hsp_identity|float)/hsp|len) | fmt('.0%') }}) {{ hsp.Hsp_gaps }}/{{ hsp|len - }}({{ (hsp.Hsp_gaps / hsp|len) | fmt('.0%') }}) + }}({{ ((hsp.Hsp_gaps|float) / hsp|len) | fmt('.0%') }}) {{ hsp['Hsp_query-frame']|asframe }}/{{ hsp['Hsp_hit-frame']|asframe }} diff -r 03e044b5bcc2 -r 4d2c25baf5a3 blast2html.py --- a/blast2html.py Wed Jun 18 16:58:25 2014 +0200 +++ b/blast2html.py Wed Jun 18 17:50:32 2014 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Actually this program works with both python 2 and 3 +# Actually this program works with both python 2 and 3, tested against python 2.6 # Copyright The Hyve B.V. 2014 # License: GPL version 3 or (at your option) any higher version @@ -12,6 +12,7 @@ import math import warnings import six, codecs +from six.moves import builtins from os import path from itertools import repeat import argparse @@ -20,7 +21,7 @@ -_filters = dict() +_filters = dict(int='int', float='float') def filter(func_or_name): "Decorator to register a function as filter in the current jinja environment" if isinstance(func_or_name, six.string_types): @@ -241,7 +242,10 @@ try: environment.filters[filtername] = getattr(self, funcname) except AttributeError: - environment.filters[filtername] = globals()[funcname] + try: + environment.filters[filtername] = globals()[funcname] + except KeyError: + environment.filters[filtername] = getattr(builtins, funcname) def render(self, output): template = self.environment.get_template(self.templatename) @@ -256,8 +260,6 @@ result = template.render(blast=self.blast, iterations=self.blast.BlastOutput_iterations.Iteration, colors=self.colors, - # match_colors=self.match_colors(), - # hit_info=self.hit_info(), genelink=genelink, params=params) if six.PY2: @@ -327,13 +329,14 @@ return (float(hsp[path]) for hsp in hsps) yield dict(hit = hit, - title = firsttitle(hit), + title = firsttitle(hit), maxscore = "{0:.1f}".format(max(hsp_val('Hsp_bit-score'))), totalscore = "{0:.1f}".format(sum(hsp_val('Hsp_bit-score'))), cover = "{0:.0%}".format(cover_count / query_length), e_value = "{0:.4g}".format(min(hsp_val('Hsp_evalue'))), # FIXME: is this the correct formula vv? - ident = "{0:.0%}".format(float(min(hsp.Hsp_identity / blastxml_len(hsp) for hsp in hsps))), + # float(...) because non-rounding division doesn't work with lxml elements in python 2.6 + ident = "{0:.0%}".format(float(min(float(hsp.Hsp_identity) / blastxml_len(hsp) for hsp in hsps))), accession = hit.Hit_accession)