Skip to content

Commit

Permalink
55. Now it's failing because SBT index is saving all signatures
Browse files Browse the repository at this point in the history
(instead of only the one it was used to build the tree).
This was actually a feature (see #198) but it broke the SBT code
(it wasn't ready for that!)
  • Loading branch information
luizirber committed Aug 15, 2018
1 parent b5fdd4d commit a8809f5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions sourmash/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


sig_refs = weakref.WeakKeyDictionary()
mhs_refs = weakref.WeakKeyDictionary()


class SourmashSignature(RustObject):
Expand Down Expand Up @@ -61,6 +62,19 @@ def __str__(self):
return "SourmashSignature({})".format(md5pref)
__repr__ = __str__

def minhashes(self):
size = ffi.new("uintptr_t *")
mhs_ptr = self._methodcall(lib.signature_get_mhs, size)
size = ffi.unpack(size, 1)[0]

mhs = []
for i in range(size):
mh = MinHash._from_objptr(mhs_ptr[i], shared=True)
mhs.append(mh)
# mhs_refs[mh] = mh

return mhs

def md5sum(self):
"Calculate md5 hash of the bottom sketch, specifically."
m = hashlib.md5()
Expand Down Expand Up @@ -276,10 +290,11 @@ def load_signatures(data, ksize=None, select_moltype=None,
sig_refs[sig] = sigs

for sig in sigs:
if not ksize or ksize == sig.minhash.ksize:
if not select_moltype or \
sig.minhash.is_molecule_type(select_moltype):
yield sig
for minhash in sig.minhashes():
if not ksize or ksize == minhash.ksize:
if not select_moltype or \
minhash.is_molecule_type(select_moltype):
yield sig
except Exception as e:
error("Error in parsing signature; quitting.")
error("Exception: {}", str(e))
Expand Down

0 comments on commit a8809f5

Please sign in to comment.