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))