Mercurial > repos > jankanis > blast2html
comparison blast2html.py @ 69:0c4ac210068b
handle reverse matches
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Wed, 18 Jun 2014 14:12:00 +0200 |
parents | fa8a93bdefd7 |
children | 371cd585e459 |
comparison
equal
deleted
inserted
replaced
68:fa8a93bdefd7 | 69:0c4ac210068b |
---|---|
85 def alignment_pre(hsp): | 85 def alignment_pre(hsp): |
86 """Create the preformatted alignment blocks""" | 86 """Create the preformatted alignment blocks""" |
87 | 87 |
88 step = 60 | 88 step = 60 |
89 | 89 |
90 def split(txt): | |
91 return [txt[i:i+step] for i in range(0, len(txt), step)] | |
92 | |
93 qfrom = int(hsp['Hsp_query-from']) | 90 qfrom = int(hsp['Hsp_query-from']) |
94 qto = int(hsp['Hsp_query-to']) | 91 qto = int(hsp['Hsp_query-to']) |
92 qframe = int(hsp['Hsp_query-frame']) | |
95 hfrom = int(hsp['Hsp_hit-from']) | 93 hfrom = int(hsp['Hsp_hit-from']) |
96 hto = int(hsp['Hsp_hit-to']) | 94 hto = int(hsp['Hsp_hit-to']) |
95 hframe = int(hsp['Hsp_hit-frame']) | |
97 qseq = hsp.Hsp_qseq.text | 96 qseq = hsp.Hsp_qseq.text |
98 midline = hsp.Hsp_midline.text | 97 midline = hsp.Hsp_midline.text |
99 hseq = hsp.Hsp_hseq.text | 98 hseq = hsp.Hsp_hseq.text |
100 | 99 |
101 offset = 0 | 100 if not qframe in [1, -1]: |
101 warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_query-frame of {}".format(nodeid(hsp), qframe)) | |
102 qframe = -1 if qframe < 0 else 1 | |
103 if not hframe in [1, -1]: | |
104 warnings.warn("Error in BlastXML input: Hsp node {} has a Hsp_hit-frame of {}".format(nodeid(hsp), hframe)) | |
105 hframe = -1 if hframe < 0 else 1 | |
106 | |
107 def split(txt): | |
108 return [txt[i:i+step] for i in range(0, len(txt), step)] | |
109 | |
102 for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), step)): | 110 for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), step)): |
103 yield ( | 111 yield ( |
104 "Query {:>7} {} {}\n".format(qfrom+offset, qs, qfrom+offset+len(qs)-1) + | 112 "Query {:>7} {} {}\n".format(qfrom+offset*qframe, qs, qfrom+(offset+len(qs)-1)*qframe) + |
105 " {:7} {}\n".format('', mid) + | 113 " {:7} {}\n".format('', mid) + |
106 "Subject{:>7} {} {}".format(hfrom+offset, hs, hfrom+offset+len(hs)-1) | 114 "Subject{:>7} {} {}".format(hfrom+offset*hframe, hs, hfrom+(offset+len(hs)-1)*hframe) |
107 ) | 115 ) |
108 | 116 |
109 if qfrom+len(qseq)-1 != qto: | 117 if qfrom+(len(qseq)-1)*qframe != qto: |
110 warnings.warn("Error in BlastXML input: Hsp node {} qseq length mismatch: from {} to {} length {}".format( | 118 warnings.warn("Error in BlastXML input: Hsp node {} qseq length mismatch: from {} to {} length {}".format( |
111 nodeid(hsp), qfrom, qto, len(qseq))) | 119 nodeid(hsp), qfrom, qto, len(qseq))) |
112 if hfrom+len(hseq)-1 != hto: | 120 if hfrom+(len(hseq)-1)*hframe != hto: |
113 warnings.warn("Error in BlastXML input: Hsp node {} hseq length mismatch: from {} to {} length {}".format( | 121 warnings.warn("Error in BlastXML input: Hsp node {} hseq length mismatch: from {} to {} length {}".format( |
114 nodeid(hsp), hfrom, hto, len(hseq))) | 122 nodeid(hsp), hfrom, hto, len(hseq))) |
115 | 123 |
116 | 124 |
117 | 125 |