Mercurial > repos > jankanis > blast2html
comparison blast2html.py @ 67:19c48f2ec775
wrap alignments if they are too long
| author | Jan Kanis <jan.code@jankanis.nl> |
|---|---|
| date | Tue, 17 Jun 2014 18:07:02 +0200 |
| parents | 4217bb9cf1d3 |
| children | fa8a93bdefd7 |
comparison
equal
deleted
inserted
replaced
| 66:e3dd39906eef | 67:19c48f2ec775 |
|---|---|
| 81 return hitid | 81 return hitid |
| 82 | 82 |
| 83 | 83 |
| 84 @filter | 84 @filter |
| 85 def alignment_pre(hsp): | 85 def alignment_pre(hsp): |
| 86 return ( | 86 step = 60 |
| 87 "Query {:>7s} {} {}\n".format(hsp['Hsp_query-from'].text, hsp.Hsp_qseq, hsp['Hsp_query-to']) + | 87 |
| 88 " {:7s} {}\n".format('', hsp.Hsp_midline) + | 88 def split(txt): |
| 89 "Subject{:>7s} {} {}".format(hsp['Hsp_hit-from'].text, hsp.Hsp_hseq, hsp['Hsp_hit-to']) | 89 return [txt[i:i+step] for i in range(0, len(txt), step)] |
| 90 ) | 90 |
| 91 qfrom = int(hsp['Hsp_query-from']) | |
| 92 qto = int(hsp['Hsp_query-to']) | |
| 93 hfrom = int(hsp['Hsp_hit-from']) | |
| 94 hto = int(hsp['Hsp_hit-to']) | |
| 95 qseq = hsp.Hsp_qseq.text | |
| 96 midline = hsp.Hsp_midline.text | |
| 97 hseq = hsp.Hsp_hseq.text | |
| 98 | |
| 99 offset = 0 | |
| 100 for qs, mid, hs, offset in zip(split(qseq), split(midline), split(hseq), range(0, len(qseq), step)): | |
| 101 yield ( | |
| 102 "Query {:>7} {} {}\n".format(qfrom+offset, qs, qfrom+len(qs)-1) + | |
| 103 " {:7} {}\n".format('', mid) + | |
| 104 "Subject{:>7} {} {}".format(hfrom+offset, hs, hfrom+len(hs)-1) | |
| 105 ) | |
| 106 | |
| 107 if qfrom+len(qseq)-1 != qto: | |
| 108 warnings.warn("Error in BlastXML input: Hsp node {} qseq length mismatch: from {} to {} length {}".format( | |
| 109 nodeid(hsp), qfrom, qto, len(qseq))) | |
| 110 if hfrom+len(hseq)-1 != hto: | |
| 111 warnings.warn("Error in BlastXML input: Hsp node {} hseq length mismatch: from {} to {} length {}".format( | |
| 112 nodeid(hsp), hfrom, hto, len(hseq))) | |
| 113 | |
| 114 | |
| 91 | 115 |
| 92 @filter('len') | 116 @filter('len') |
| 93 def blastxml_len(node): | 117 def blastxml_len(node): |
| 94 if node.tag == 'Hsp': | 118 if node.tag == 'Hsp': |
| 95 return int(node['Hsp_align-len']) | 119 return int(node['Hsp_align-len']) |
