Skip to content

Commit

Permalink
Fix containment calculation for nodegraphs (#1862)
Browse files Browse the repository at this point in the history
* fix containment calculation for nodegraphs
* add a containment test
  • Loading branch information
luizirber committed Mar 5, 2022
1 parent efebe8a commit 4defa47
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/core/src/sketch/nodegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Nodegraph {
.zip(&other.bs)
.map(|(bs, bs_other)| bs.intersection(bs_other).count())
.sum();
let size: usize = self.bs.iter().map(|bs| bs.len()).sum();
let size: usize = self.bs.iter().map(|bs| bs.count_ones(..)).sum();
result as f64 / size as f64
}
}
Expand Down Expand Up @@ -435,6 +435,24 @@ mod test {
assert_eq!(ng.unique_kmers(), 1);
}

#[test]
fn containment() {
let mut ng1: Nodegraph = Nodegraph::new(&[31], 3);
let mut ng2: Nodegraph = Nodegraph::new(&[31], 3);

(0..20).for_each(|i| {
if i % 2 == 0 {
ng1.count(i);
};
ng2.count(i);
});

assert_eq!(ng1.containment(&ng2), 1.0);
assert_eq!(ng1.similarity(&ng2), 0.5);
assert_eq!(ng1.unique_kmers(), 10);
assert_eq!(ng2.unique_kmers(), 20);
}

#[test]
fn load_save_nodegraph() {
let mut datadir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down

0 comments on commit 4defa47

Please sign in to comment.