Repository navigation
Conversation
audy
marked this pull request as ready for review
November 7, 2026 00:07
kmers, canonical_kmers, bit_kmers to the Python API
audy
marked this pull request as draft
November 7, 2026 00:13
Both return lazy iterators that own a copy of the sequence, using self_cell to pair the owned buffer with the borrowing Rust iterator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
kmers(seq, k)andcanonical_kmers(seq, k)module functions, plusRecord.kmers(k)andRecord.canonical_kmers(k)methods, wrapping the existing RustKmersandCanonicalKmersiterators. They return lazy Python iterators. Each one owns a copy of the sequence, andself_cellpairs that buffer with the borrowing Rust iterator.self_cellis a new optional dependency, enabled only by thepythonandpython_testfeatures. Stubs, tests, and a CHANGELOG entry are included. b59b2a6bit_kmers(seq, k, canonical=False)andRecord.bit_kmers(k, canonical=False), wrappingBitNuclKmerto yield 2-bit packedu64k-mers (A=0, C=1, G=2, T=3) as(position, int, was_rc)tuples. 8d8ec1bNotes
canonical_kmersandbit_kmersskip windows containing non-ACGT bases. For palindromic k-mers,canonical_kmerssets the reverse-complement flag toTrueandbit_kmerssets it toFalse. Both match the Rust behavior.k == 0raisesValueError;k > 255raisesOverflowError.bit_kmersadditionally raisesValueErrorfork > 32. These are raised when the function is called, not on first iteration.Benchmark
Iterating a random 5 Mb sequence at k=31 (release builds, Apple Silicon), compared with an earlier draft that returned lists:
kmerscanonical_kmersbit_kmers(canonical=True)