# HG changeset patch
# User Jan Kanis <jan.code@jankanis.nl>
# Date 1403094195 -7200
# Node ID 371cd585e459b63c63d97637c53a445a4215b8eb
# Parent  0ef071bba1642a21b8ca2507594326b949879a72
refactor

diff -r 0ef071bba164 -r 371cd585e459 blast2html.py
--- a/blast2html.py	Wed Jun 18 14:22:57 2014 +0200
+++ b/blast2html.py	Wed Jun 18 14:23:15 2014 +0200
@@ -84,8 +84,9 @@
 @filter
 def alignment_pre(hsp):
     """Create the preformatted alignment blocks"""
-    
-    step = 60
+
+    # line break length
+    linewidth = 60
 
     qfrom = int(hsp['Hsp_query-from'])
     qto = int(hsp['Hsp_query-to'])
@@ -93,21 +94,22 @@
     hfrom = int(hsp['Hsp_hit-from'])
     hto = int(hsp['Hsp_hit-to'])
     hframe = int(hsp['Hsp_hit-frame'])
+    
     qseq = hsp.Hsp_qseq.text
     midline = hsp.Hsp_midline.text
     hseq = hsp.Hsp_hseq.text
 
-    if not qframe in [1, -1]:
-        warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_query-frame of {}".format(nodeid(hsp), qframe))
+    if not qframe in (1, -1):
+        warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_query-frame of {}. (should be 1 or -1)".format(nodeid(hsp), qframe))
         qframe = -1 if qframe < 0 else 1
-    if not hframe in [1, -1]:
-        warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_hit-frame of {}".format(nodeid(hsp), hframe))
+    if not hframe in (1, -1):
+        warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_hit-frame of {}. (should be 1 or -1)".format(nodeid(hsp), hframe))
         hframe = -1 if hframe < 0 else 1
     
     def split(txt):
-        return [txt[i:i+step] for i in range(0, len(txt), step)]
+        return [txt[i:i+linewidth] for i in range(0, len(txt), linewidth)]
 
-    for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), step)):
+    for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), linewidth)):
         yield (
             "Query  {:>7}  {}  {}\n".format(qfrom+offset*qframe, qs, qfrom+(offset+len(qs)-1)*qframe) +
             "       {:7}  {}\n".format('', mid) +