Mercurial > repos > jankanis > blast2html
comparison visualise.py @ 13:7660519f2dc9 draft
proper layout for alignments, added some links
| author | Jan Kanis <jan.code@jankanis.nl> | 
|---|---|
| date | Mon, 12 May 2014 13:55:04 +0200 | 
| parents | 2fbdf2eb27b4 | 
| children | a459c754cdb5 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 12:2fbdf2eb27b4 | 13:7660519f2dc9 | 
|---|---|
| 14 blast = objectify.parse('blast xml example1.xml').getroot() | 14 blast = objectify.parse('blast xml example1.xml').getroot() | 
| 15 loader = jinja2.FileSystemLoader(searchpath='.') | 15 loader = jinja2.FileSystemLoader(searchpath='.') | 
| 16 environment = jinja2.Environment(loader=loader, lstrip_blocks=True, trim_blocks=True, autoescape=True) | 16 environment = jinja2.Environment(loader=loader, lstrip_blocks=True, trim_blocks=True, autoescape=True) | 
| 17 | 17 | 
| 18 def filter(func_or_name): | 18 def filter(func_or_name): | 
| 19 "Decorator to register a function as filter in the current jinja environment" | |
| 19 if isinstance(func_or_name, str): | 20 if isinstance(func_or_name, str): | 
| 20 def inner(func): | 21 def inner(func): | 
| 21 environment.filters[func_or_name] = func | 22 environment.filters[func_or_name] = func | 
| 22 return func | 23 return func | 
| 23 return inner | 24 return inner | 
| 72 return hit.Hit_id.text.split('|', 2)[2] | 73 return hit.Hit_id.text.split('|', 2)[2] | 
| 73 | 74 | 
| 74 @filter | 75 @filter | 
| 75 def alignment_pre(hsp): | 76 def alignment_pre(hsp): | 
| 76 return ( | 77 return ( | 
| 77 "Query {:>7s} {} {}\n".format(hsp['Hsp_query-from'], hsp.Hsp_qseq, hsp['Hsp_query-to']) + | 78 "Query {:>7s} {} {}\n".format(hsp['Hsp_query-from'], hsp.Hsp_qseq, hsp['Hsp_query-to']) + | 
| 78 " {:7s} {}\n".format('', hsp.Hsp_midline) + | 79 " {:7s} {}\n".format('', hsp.Hsp_midline) + | 
| 79 "Subject {:>7s} {} {}".format(hsp['Hsp_hit-from'], hsp.Hsp_hseq, hsp['Hsp_hit-to'])) | 80 "Subject{:>7s} {} {}".format(hsp['Hsp_hit-from'], hsp.Hsp_hseq, hsp['Hsp_hit-to']) | 
| 81 ) | |
| 80 | 82 | 
| 81 @filter('len') | 83 @filter('len') | 
| 82 def hsplen(node): | 84 def hsplen(node): | 
| 83 return int(node['Hsp_align-len']) | 85 return int(node['Hsp_align-len']) | 
| 84 | 86 | 
| 153 cover_count = cover.count(True) | 155 cover_count = cover.count(True) | 
| 154 | 156 | 
| 155 def hsp_val(path): | 157 def hsp_val(path): | 
| 156 return (hsp[path] for hsp in hsps) | 158 return (hsp[path] for hsp in hsps) | 
| 157 | 159 | 
| 158 yield dict(title = firsttitle(hit), | 160 yield dict(hit = hit, | 
| 161 title = firsttitle(hit), | |
| 159 link_id = hit.Hit_num, | 162 link_id = hit.Hit_num, | 
| 160 maxscore = "{:.1f}".format(float(max(hsp_val('Hsp_bit-score')))), | 163 maxscore = "{:.1f}".format(float(max(hsp_val('Hsp_bit-score')))), | 
| 161 totalscore = "{:.1f}".format(float(sum(hsp_val('Hsp_bit-score')))), | 164 totalscore = "{:.1f}".format(float(sum(hsp_val('Hsp_bit-score')))), | 
| 162 cover = "{:.0%}".format(cover_count / query_length), | 165 cover = "{:.0%}".format(cover_count / query_length), | 
| 163 e_value = "{:.4g}".format(float(min(hsp_val('Hsp_evalue')))), | 166 e_value = "{:.4g}".format(float(min(hsp_val('Hsp_evalue')))), | 
| 187 queryscale=queryscale(), | 190 queryscale=queryscale(), | 
| 188 hit_info=hit_info(), | 191 hit_info=hit_info(), | 
| 189 params=params)) | 192 params=params)) | 
| 190 | 193 | 
| 191 main() | 194 main() | 
| 195 | |
| 196 # http://www.ncbi.nlm.nih.gov/nucleotide/557804451?report=genbank&log$=nuclalign&blast_rank=1&RID=PHWP1JNZ014 | |
| 197 # http://www.ncbi.nlm.nih.gov/nuccore/557804451?report=graph&rid=PHWP1JNZ014[557804451]&tracks=[key:sequence_track,name:Sequence,display_name:Sequence,id:STD1,category:Sequence,annots:Sequence,ShowLabel:true][key:gene_model_track,CDSProductFeats:false][key:alignment_track,name:other%20alignments,annots:NG%20Alignments%7CRefseq%20Alignments%7CGnomon%20Alignments%7CUnnamed,shown:false]&v=752:2685&appname=ncbiblast&link_loc=fromSubj | |
| 198 | |
| 199 # http://www.ncbi.nlm.nih.gov/nucleotide/557804451?report=genbank&log$=nucltop&blast_rank=1&RID=PHWP1JNZ014 | 
