strobemers/
lib.rs

1#![crate_name = "strobemers"]
2//! Strobemers is a crate to generate strobemers. It aims to provide a toolkit for reproducing existing strobemer implementations while allowing individual components to be easily swapped out (e.g. hash function, window generator, or strobe selector).
3
4//! Here is a simple example:
5//!```
6//! use strobemers::StrobemerBuilder;
7//! let reference = b"ACGCGTACGAATCACGCCGGGTGTGTGTGATCG";
8//! let n: usize = 2;
9//! let k: usize = 15;
10//! let w_min: usize = 16;
11//! let w_max: usize = 30;
12//!
13//! let mut randstrobe_iter = StrobemerBuilder::new()
14//!     .reference(reference)
15//!     .n(n)
16//!     .k(k)
17//!     .w_min(w_min)
18//!     .build()
19//!     .unwrap();
20//! for strobe in randstrobe_iter {
21//!     println!("randstrobe start positions: {:?}", strobe);
22//! }
23//!```
24//!
25//!You can also begin with a specific implementation (consisting of hasher, window, and
26//!strobe selector) and swap individual components out with your own. For example using a
27//!provided randstrobe implementation with a custom hash function:
28//!```
29//! use strobemers::StrobemerBuilder;
30//! use strobemers::implementations::{RandstrobeSahlin2021, StrobeHasher};
31//! use wyhash::wyhash;
32//! let reference = b"ACGCGTACGAATCACGCCGGGTGTGTGTGATCG";
33//! let n: usize = 2;
34//! let k: usize = 15;
35//! let w_min: usize = 16;
36//! let w_max: usize = 30;
37//!
38//! struct WyHasher;
39//! impl StrobeHasher for WyHasher {
40//!     fn hash(&self, input: &[u8], k: usize) -> Vec<u64> {
41//!         let mut input_hashes = Vec::new();
42//!         for i in 0..input.len() - k {
43//!             input_hashes.push(wyhash(&input[i..i + k], 42));
44//!         }
45//!         input_hashes
46//!     }
47//! }
48//!
49//! let mut randstrobe_iter = StrobemerBuilder::from_implementation(RandstrobeSahlin2021)
50//!     .reference(reference)
51//!     .n(n)
52//!     .k(k)
53//!     .w_min(w_min)
54//!     .hasher(Box::new(WyHasher))
55//!     .build()
56//!     .unwrap();
57//! for strobe in randstrobe_iter {
58//!     println!("randstrobe start positions: {:?}", strobe);
59//! }
60//!```
61
62#[doc = include_str!("../README.md")]
63#[cfg(doctest)]
64pub struct ReadmeDoctests;
65
66pub mod implementations;
67pub mod strobemer;
68use thiserror::Error;
69
70#[derive(Error, Debug)]
71pub enum StrobemerError {
72    /// Error thrown when unsupported strobemer order is requested
73    #[error("Strobemer order is unsupported")]
74    UnsupportedOrder,
75}
76
77pub use strobemer::StrobemerBuilder;