pub struct MerDna { /* private fields */ }Expand description
A DNA k-mer stored as 2-bit packed encoding in u64 words.
This matches the Jellyfish MerDNA representation:
- Each base is 2 bits: A=0, C=1, G=2, T=3
- Bases are packed from LSB to MSB within each word
- Words are ordered from least significant to most significant
§Examples
use jellyfish_reader::MerDna;
let mer: MerDna = "ACGT".parse().unwrap();
assert_eq!(mer.to_string(), "ACGT");
assert_eq!(mer.k(), 4);
let rc = mer.get_reverse_complement();
assert_eq!(rc.to_string(), "ACGT"); // ACGT is its own reverse complementImplementations§
Source§impl MerDna
impl MerDna
Sourcepub fn from_words(words: Vec<u64>, k: usize) -> Self
pub fn from_words(words: Vec<u64>, k: usize) -> Self
Create a MerDna from raw word data and k-mer length.
The words should contain 2-bit packed bases matching Jellyfish’s encoding.
Sourcepub fn from_bytes(bytes: &[u8], k: usize) -> Self
pub fn from_bytes(bytes: &[u8], k: usize) -> Self
Create a MerDna by reading packed bytes (as stored in Jellyfish binary files).
Bytes are read in order and packed into u64 words in little-endian byte order.
Sourcepub fn set_base(&mut self, i: usize, base_code: u8)
pub fn set_base(&mut self, i: usize, base_code: u8)
Set the base at position i (0-indexed from the right/LSB end).
§Panics
Panics if i >= k or if base_code is not in 0..4.
Sourcepub fn shift_left(&mut self, base: u8) -> Option<u8>
pub fn shift_left(&mut self, base: u8) -> Option<u8>
Shift the k-mer left by one position, inserting base at the right end.
Returns the base character that was shifted out from the left end.
Sourcepub fn shift_right(&mut self, base: u8) -> Option<u8>
pub fn shift_right(&mut self, base: u8) -> Option<u8>
Shift the k-mer right by one position, inserting base at the left end.
Returns the base character that was shifted out from the right end.
Sourcepub fn get_reverse_complement(&self) -> MerDna
pub fn get_reverse_complement(&self) -> MerDna
Compute the reverse complement of this k-mer.
Sourcepub fn reverse_complement(&mut self)
pub fn reverse_complement(&mut self)
Modify this k-mer in place to its reverse complement.
Sourcepub fn get_canonical(&self) -> MerDna
pub fn get_canonical(&self) -> MerDna
Get the canonical form (lexicographically smaller of self and reverse complement).
Sourcepub fn canonicalize(&mut self)
pub fn canonicalize(&mut self)
Modify this k-mer in place to its canonical form.
Sourcepub fn is_homopolymer(&self) -> bool
pub fn is_homopolymer(&self) -> bool
Check if this k-mer is a homopolymer (all same base).