Files
obitools4/autodoc/docmd/pkg/obiseq/kmers.md
T
Eric Coissac 8c7017a99d ⬆️ version bump to v4.5
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5"
- Update version.txt from 4.29 → .30
(automated by Makefile)
2026-04-13 13:34:53 +02:00

21 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## BioSequence.Kmers(k int) — Semantic Description
The `Kmers` method is a generator function that yields all contiguous *k*-length subsequences (called **k-mers**) from a biological sequence (`BioSequence`).
- It operates on `[]byte` data, assuming the underlying sequence is stored as a byte slice (e.g., DNA bases `A`, `C`, `G`, `T`).
- Uses Gos new iterator protocol (`iter.Seq[[]byte]`) for memory-efficient, lazy evaluation.
- Validates input: returns an empty iterator if `k ≤ 0` or exceeds sequence length.
- Iterates linearly from index `i = 0` to `len(seq) - k`, extracting slices of length *k*.
- Each yielded value is a **non-copying slice view** (efficient, but mutable if original data changes).
- Supports early termination: the consumer can stop iteration by returning `false` from the yield callback.
- Designed for downstream tasks like sequence analysis, motif discovery, or hashing (e.g., in k-mer counting).
- Does *not* handle reverse-complement or ambiguous bases—assumes raw sequence input.
Usage example:
```go
for kmer := range seq.Kmers(3) {
fmt.Printf("%s\n", string(kmer))
}
```
This yields all 3-mers (e.g., `"ACG"`, `"CGT"`...) in order.