Skip to content

Commit 314c9e6

Browse files
committed
Fix Clippy errors
[squashme] more clippy fixes
1 parent 265dbac commit 314c9e6

File tree

9 files changed

+46
-59
lines changed

9 files changed

+46
-59
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub fn update_sketch_params(
413413
if let Some(new_scale_num) = new_scale {
414414
if matches.occurrences_of("scale") == 0 {
415415
*scale = new_scale_num;
416-
} else if (*scale - new_scale_num).abs() < std::f64::EPSILON {
416+
} else if (*scale - new_scale_num).abs() < f64::EPSILON {
417417
// TODO: maybe this should have a slightly larger delta?
418418
bail!(
419419
"Specified scale {} does not match {} from sketch {}",

lib/src/distance.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn raw_distance(
9797
// at this point we've exhausted one of the two sketches, but we may have
9898
// more counts in the other to compare if these were scaled sketches
9999
if scale > 0. {
100-
let max_hash = u64::max_value() / scale.recip() as u64;
100+
let max_hash = u64::MAX / scale.recip() as u64;
101101
while query_hashes
102102
.get(i)
103103
.map(|kmer_count| kmer_count.hash < max_hash)
@@ -125,6 +125,37 @@ pub fn raw_distance(
125125
(containment, jaccard, common, total)
126126
}
127127

128+
/// This computes set statistics from one set of hashes to another.
129+
///
130+
/// Every hash in the reference set is considered while only those hashes in the
131+
/// query set that are in the same range as the reference set are compared. This
132+
/// should be a more accurate representation of the query set's containment in
133+
/// the reference set because we consider all of the reference set. In
134+
/// practice, there may be issues especially if the query is sketched to a
135+
/// different effective scale than the reference.
136+
pub fn old_distance(query_sketch: &[KmerCount], ref_sketch: &[KmerCount]) -> (f64, f64, u64, u64) {
137+
let mut i: usize = 0;
138+
let mut common: u64 = 0;
139+
let mut total: u64 = 0;
140+
141+
for ref_hash in ref_sketch {
142+
while (query_sketch[i].hash < ref_hash.hash) && (i < query_sketch.len() - 1) {
143+
i += 1;
144+
}
145+
146+
if query_sketch[i].hash == ref_hash.hash {
147+
common += 1;
148+
}
149+
150+
total += 1;
151+
}
152+
153+
// Numerator is A-intersect-B, |A| is the denominator, we enforce |A| == |B|
154+
let containment: f64 = common as f64 / total as f64;
155+
let jaccard: f64 = common as f64 / (common + 2 * (total - common)) as f64;
156+
(containment, jaccard, common, total)
157+
}
158+
128159
#[cfg(test)]
129160
mod tests {
130161
use super::*;
@@ -306,37 +337,6 @@ mod tests {
306337
}
307338
}
308339

309-
/// This computes set statistics from one set of hashes to another.
310-
///
311-
/// Every hash in the reference set is considered while only those hashes in the
312-
/// query set that are in the same range as the reference set are compared. This
313-
/// should be a more accurate representation of the query set's containment in
314-
/// the reference set because we consider all of the reference set. In
315-
/// practice, there may be issues especially if the query is sketched to a
316-
/// different effective scale than the reference.
317-
pub fn old_distance(query_sketch: &[KmerCount], ref_sketch: &[KmerCount]) -> (f64, f64, u64, u64) {
318-
let mut i: usize = 0;
319-
let mut common: u64 = 0;
320-
let mut total: u64 = 0;
321-
322-
for ref_hash in ref_sketch {
323-
while (query_sketch[i].hash < ref_hash.hash) && (i < query_sketch.len() - 1) {
324-
i += 1;
325-
}
326-
327-
if query_sketch[i].hash == ref_hash.hash {
328-
common += 1;
329-
}
330-
331-
total += 1;
332-
}
333-
334-
// Numerator is A-intersect-B, |A| is the denominator, we enforce |A| == |B|
335-
let containment: f64 = common as f64 / total as f64;
336-
let jaccard: f64 = common as f64 / (common + 2 * (total - common)) as f64;
337-
(containment, jaccard, common, total)
338-
}
339-
340340
// TODO: add another method like this to allow 0's in ref sketch for hashes present in sketches?
341341
// TODO: maybe we want to do NNLS on these matrices in Rust? for example code, see:
342342
// https://github.com/igmanthony/fnnls/blob/master/src/fnnls.rs

lib/src/filtering.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ impl FilterParams {
3131
Some(u32::max(l, sketch.filter_params.abun_filter.0.unwrap_or(0))),
3232
Some(u32::min(
3333
h,
34-
sketch
35-
.filter_params
36-
.abun_filter
37-
.1
38-
.unwrap_or(u32::max_value()),
34+
sketch.filter_params.abun_filter.1.unwrap_or(u32::MAX),
3935
)),
4036
),
4137
(Some(l), None) => (
@@ -46,11 +42,7 @@ impl FilterParams {
4642
None,
4743
Some(u32::min(
4844
h,
49-
sketch
50-
.filter_params
51-
.abun_filter
52-
.1
53-
.unwrap_or(u32::max_value()),
45+
sketch.filter_params.abun_filter.1.unwrap_or(u32::MAX),
5446
)),
5547
),
5648
(None, None) => (None, None),
@@ -341,7 +333,7 @@ pub fn filter_abundance(
341333
) -> Vec<KmerCount> {
342334
let mut filtered = Vec::new();
343335
let lo_threshold = low.unwrap_or(0u32);
344-
let hi_threshold = high.unwrap_or(u32::max_value());
336+
let hi_threshold = high.unwrap_or(u32::MAX);
345337
for kmer in sketch {
346338
if lo_threshold <= kmer.count && kmer.count <= hi_threshold {
347339
filtered.push(kmer.clone());

lib/src/serialization/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'de> Deserialize<'de> for QuotedU64 {
247247
{
248248
struct QuotedU64Visitor;
249249

250-
impl<'de> Visitor<'de> for QuotedU64Visitor {
250+
impl Visitor<'_> for QuotedU64Visitor {
251251
type Value = QuotedU64;
252252

253253
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

lib/src/serialization/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,8 @@ pub fn write_finch_file(file: &mut dyn Write, sketches: &[Sketch]) -> FinchResul
151151
let mut cap_filter_params = cap_sketch.reborrow().init_filter_params();
152152
cap_filter_params.set_filtered(sketch.filter_params.filter_on.unwrap_or(false));
153153
cap_filter_params.set_low_abun_filter(sketch.filter_params.abun_filter.0.unwrap_or(0));
154-
cap_filter_params.set_high_abun_filter(
155-
sketch
156-
.filter_params
157-
.abun_filter
158-
.1
159-
.unwrap_or(::std::u32::MAX),
160-
);
154+
cap_filter_params
155+
.set_high_abun_filter(sketch.filter_params.abun_filter.1.unwrap_or(u32::MAX));
161156
cap_filter_params.set_err_filter(sketch.filter_params.err_filter);
162157
cap_filter_params.set_strand_filter(sketch.filter_params.strand_filter);
163158

lib/src/sketch_schemes/mash.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::{BinaryHeap, HashMap};
22
use std::hash::BuildHasherDefault;
3-
use std::usize;
43

54
use needletail::Sequence;
65

lib/src/sketch_schemes/scaled.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::{BinaryHeap, HashMap};
22
use std::hash::BuildHasherDefault;
3-
use std::usize;
43

54
use needletail::Sequence;
65

@@ -29,7 +28,7 @@ impl ScaledSketcher {
2928
total_kmers: 0,
3029
total_bases: 0,
3130
size,
32-
max_hash: u64::max_value() / iscale,
31+
max_hash: u64::MAX / iscale,
3332
seed,
3433
}
3534
}

lib/src/statistics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ pub fn cardinality(sketch: &[KmerCount]) -> Result<u64, &'static str> {
1616
if sketch.is_empty() {
1717
return Ok(0u64);
1818
}
19-
Ok(((sketch.len() - 1) as f32
20-
/ (sketch.last().unwrap().hash as f32 / usize::max_value() as f32)) as u64)
19+
Ok(
20+
((sketch.len() - 1) as f32 / (sketch.last().unwrap().hash as f32 / usize::MAX as f32))
21+
as u64,
22+
)
2123
}
2224

2325
/// Generates a Vec of numbers of kmers for each coverage level

0 commit comments

Comments
 (0)