Skip to content

Commit

Permalink
Hack for Bio.SearchIO blast-xml encoding
Browse files Browse the repository at this point in the history
BLAST XML files do not specify its encoding, which may be problematic in some
Python versions. This commit forces a 'utf-8' encoding for all BLAST XML files
opened through Bio.SearchIO.
  • Loading branch information
bow authored and peterjc committed Nov 30, 2012
1 parent 820677c commit 06cb6da
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Bio/SearchIO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,15 @@ def parse(handle, format=None, **kwargs):
# get the iterator object and do error checking
iterator = get_processor(format, _ITERATOR_MAP)

# HACK: force BLAST xml files to be opened using utf-8 encoding
# BLAST XML files do not specify this, which may lead to problems
# in some python versions
handle_kwargs = {}
if format == 'blast-xml':
handle_kwargs['encoding'] = 'utf-8'

# and start iterating
with as_handle(handle, 'rU') as source_file:
with as_handle(handle, 'rU', **handle_kwargs) as source_file:
generator = iterator(source_file, **kwargs)

for qresult in generator:
Expand Down

0 comments on commit 06cb6da

Please sign in to comment.