Skip to content

Commit

Permalink
also catch hashbit_info errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Apr 6, 2015
1 parent 22c8b52 commit 3881bad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2015-04-05 Michael R. Crusoe <mcrusoe@msu.edu>
2015-04-06 Michael R. Crusoe <mcrusoe@msu.edu>

* khmer/{__init__.py,_khmermodule.cc},lib/{counting,hashbits,hashtable,
subset}.cc: catch IO errors and report them.
Expand Down
15 changes: 9 additions & 6 deletions khmer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ def extract_hashbits_info(filename):
uchar_size = len(pack('B', 0))
ulonglong_size = len(pack('Q', 0))

with open(filename, 'rb') as hashbits:
version, = unpack('B', hashbits.read(1))
ht_type, = unpack('B', hashbits.read(1))
ksize, = unpack('I', hashbits.read(uint_size))
n_tables, = unpack('B', hashbits.read(uchar_size))
table_size, = unpack('Q', hashbits.read(ulonglong_size))
try:
with open(filename, 'rb') as hashbits:
version, = unpack('B', hashbits.read(1))
ht_type, = unpack('B', hashbits.read(1))
ksize, = unpack('I', hashbits.read(uint_size))
n_tables, = unpack('B', hashbits.read(uchar_size))
table_size, = unpack('Q', hashbits.read(ulonglong_size))
except:
raise ValueError("Presence table '{}' is corrupt ".format(filename))

return ksize, round(table_size, -2), n_tables, version, ht_type

Expand Down

0 comments on commit 3881bad

Please sign in to comment.