From a8809f554da4e62805a43718c2a87c35994c98a3 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Wed, 15 Aug 2018 16:43:43 -0700 Subject: [PATCH] 55. Now it's failing because SBT index is saving all signatures (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!) --- sourmash/signature.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/sourmash/signature.py b/sourmash/signature.py index 2da8561201..4187b86dc9 100644 --- a/sourmash/signature.py +++ b/sourmash/signature.py @@ -22,6 +22,7 @@ sig_refs = weakref.WeakKeyDictionary() +mhs_refs = weakref.WeakKeyDictionary() class SourmashSignature(RustObject): @@ -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() @@ -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))