Conversation
There was a problem hiding this comment.
Code Review
This pull request updates project dependencies, including a bump to rand 0.10.0 and sassy 0.2.1, and refactors the fuzzy matching logic in FuzzyMatcher and FuzzyPatternCounter to use EncodedPatterns and FixedBitSet. These changes optimize pattern matching and improve the handling of multi-pattern logic across sequence mates. The test suite was also updated to replace the nucgen dependency with a local nucleotide generation utility. Feedback was provided regarding an incorrect API call to the rand crate in the new test utility, along with a suggestion to use SliceRandom for a more idiomatic implementation.
| fn fill_nucleotide_buffer<R: Rng>(buffer: &mut Vec<u8>, rng: &mut R, slen: usize) { | ||
| buffer.clear(); | ||
| buffer.reserve(slen); | ||
| for _ in 0..slen { | ||
| buffer.push(match rng.random_range(0..=4) { | ||
| 0 => b'A', | ||
| 1 => b'C', | ||
| 2 => b'G', | ||
| 3 => b'T', | ||
| 4 => b'N', | ||
| _ => unreachable!(), | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
The method random_range does not exist on the Rng trait in rand v0.10.0. It seems you intended to use gen_range.
This function can also be made more idiomatic and concise by using rand::seq::SliceRandom::choose to select a random nucleotide. This avoids the match statement and unreachable! panic.
You'll need to add use rand::seq::SliceRandom; to your imports.
fn fill_nucleotide_buffer<R: Rng>(buffer: &mut Vec<u8>, rng: &mut R, slen: usize) {
const NUCLEOTIDES: &[u8] = b"ACGTN";
buffer.clear();
buffer.reserve(slen);
for _ in 0..slen {
buffer.push(*NUCLEOTIDES.choose(rng).unwrap());
}
}
close #172
close #171