# HG changeset patch # User Jan Kanis # Date 1403021222 -7200 # Node ID 19c48f2ec775f63e3e5b39cff57e1b525330e991 # Parent e3dd39906eef5acf4538d6191418e0d993580763 wrap alignments if they are too long diff -r e3dd39906eef -r 19c48f2ec775 blast2html.html.jinja --- a/blast2html.html.jinja Wed Jun 04 16:28:45 2014 +0200 +++ b/blast2html.html.jinja Tue Jun 17 18:07:02 2014 +0200 @@ -603,7 +603,9 @@ -
{{hsp|alignment_pre}}
+ {% for alignment_line in hsp|alignment_pre %} +
{{alignment_line}}
+ {% endfor %} {% endfor %} diff -r e3dd39906eef -r 19c48f2ec775 blast2html.py --- a/blast2html.py Wed Jun 04 16:28:45 2014 +0200 +++ b/blast2html.py Tue Jun 17 18:07:02 2014 +0200 @@ -83,11 +83,35 @@ @filter def alignment_pre(hsp): - return ( - "Query {:>7s} {} {}\n".format(hsp['Hsp_query-from'].text, hsp.Hsp_qseq, hsp['Hsp_query-to']) + - " {:7s} {}\n".format('', hsp.Hsp_midline) + - "Subject{:>7s} {} {}".format(hsp['Hsp_hit-from'].text, hsp.Hsp_hseq, hsp['Hsp_hit-to']) - ) + step = 60 + + def split(txt): + return [txt[i:i+step] for i in range(0, len(txt), step)] + + qfrom = int(hsp['Hsp_query-from']) + qto = int(hsp['Hsp_query-to']) + hfrom = int(hsp['Hsp_hit-from']) + hto = int(hsp['Hsp_hit-to']) + qseq = hsp.Hsp_qseq.text + midline = hsp.Hsp_midline.text + hseq = hsp.Hsp_hseq.text + + offset = 0 + for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), step)): + yield ( + "Query {:>7} {} {}\n".format(qfrom+offset, qs, qfrom+len(qs)-1) + + " {:7} {}\n".format('', mid) + + "Subject{:>7} {} {}".format(hfrom+offset, hs, hfrom+len(hs)-1) + ) + + if qfrom+len(qseq)-1 != qto: + warnings.warn("Error in BlastXML input: Hsp node {} qseq length mismatch: from {} to {} length {}".format( + nodeid(hsp), qfrom, qto, len(qseq))) + if hfrom+len(hseq)-1 != hto: + warnings.warn("Error in BlastXML input: Hsp node {} hseq length mismatch: from {} to {} length {}".format( + nodeid(hsp), hfrom, hto, len(hseq))) + + @filter('len') def blastxml_len(node):