Mercurial > repos > jankanis > blast2html
comparison blast2html.py @ 99:8f02008a5f20
look at all blast*.loc files; python2.6 compat fix
author | Jan Kanis <jan.code@jankanis.nl> |
---|---|
date | Tue, 01 Jul 2014 16:00:29 +0200 |
parents | e780606b7c25 |
children | 5bfaa3ee1f27 |
comparison
equal
deleted
inserted
replaced
98:e780606b7c25 | 99:8f02008a5f20 |
---|---|
14 import six, codecs | 14 import six, codecs |
15 from six.moves import builtins | 15 from six.moves import builtins |
16 from os import path | 16 from os import path |
17 from itertools import repeat | 17 from itertools import repeat |
18 from collections import defaultdict | 18 from collections import defaultdict |
19 import glob | |
19 import argparse | 20 import argparse |
20 from lxml import objectify | 21 from lxml import objectify |
21 import jinja2 | 22 import jinja2 |
22 | 23 |
23 builtin_str = str | 24 builtin_str = str |
372 link = template.format(**args) | 373 link = template.format(**args) |
373 except Exception as e: | 374 except Exception as e: |
374 warnings.warn('Error in formatting gene bank link {} with {}: {}'.format(template, args, e)) | 375 warnings.warn('Error in formatting gene bank link {} with {}: {}'.format(template, args, e)) |
375 return text if display_nolink else '' | 376 return text if display_nolink else '' |
376 | 377 |
377 classattr = 'class="{}" '.format(jinja2.escape(clas)) if clas is not None else '' | 378 classattr = 'class="{0}" '.format(jinja2.escape(clas)) if clas is not None else '' |
378 return jinja2.Markup("<a {}href=\"{}\">{}</a>".format(classattr, jinja2.escape(link), jinja2.escape(text))) | 379 return jinja2.Markup("<a {0}href=\"{1}\">{2}</a>".format(classattr, jinja2.escape(link), jinja2.escape(text))) |
379 | 380 |
380 | 381 |
381 def read_genelinks(dir): | 382 def read_genelinks(dir): |
382 links = {} | 383 links = {} |
383 for f in ('blastdb.loc', 'blastdb_p.loc', 'blastdb_d.loc'): | 384 # blastdb.loc, blastdb_p.loc, blastdb_d.loc, etc. |
385 # sort reversed, so blastdb.loc will take precedence | |
386 for f in sorted(glob.glob(path.join(dir, 'blastdb*.loc')), reverse=True): | |
384 try: | 387 try: |
385 f = open(path.join(dir, f)) | 388 f = open(path.join(dir, f)) |
386 for l in f.readlines(): | 389 for l in f.readlines(): |
387 if l.strip().startswith('#'): | 390 if l.strip().startswith('#'): |
388 continue | 391 continue |