compact_genome/interface/
k_mer.rs

1//! K-mers are sequences of length k.
2
3use crate::interface::alphabet::Alphabet;
4use crate::interface::sequence::{GenomeSequence, GenomeSequenceMut, OwnedGenomeSequence};
5
6/// A sequence of fixed length k.
7/// Fixing the length allows for more efficient representations, such as arrays.
8pub trait Kmer<
9    const K: usize,
10    AlphabetType: Alphabet,
11    GenomeSubsequence: GenomeSequence<AlphabetType, GenomeSubsequence> + ?Sized,
12>: GenomeSequence<AlphabetType, GenomeSubsequence>
13{
14    /// The length of sequences of this type.
15    fn k() -> usize {
16        K
17    }
18}
19
20/// An owned k-mer.
21pub trait OwnedKmer<
22    const K: usize,
23    AlphabetType: Alphabet,
24    GenomeSubsequence: GenomeSequence<AlphabetType, GenomeSubsequence> + ?Sized,
25>: OwnedGenomeSequence<AlphabetType, GenomeSubsequence>
26{
27    /// Get the successor of this k-mer with the specified character.
28    ///
29    /// This works by shifting the k-mer to the left and adding the character at the end.
30    fn successor(&self, successor: AlphabetType::CharacterType) -> Self;
31}
32
33/// A k-mer whose characters can be mutated.
34pub trait KmerMut<
35    AlphabetType: Alphabet,
36    GenomeSubsequenceMut: GenomeSequenceMut<AlphabetType, GenomeSubsequenceMut> + ?Sized,
37>: GenomeSequenceMut<AlphabetType, GenomeSubsequenceMut>
38{
39}