Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Fix containment calculation for nodegraphs #1862

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

Comment on lines +438 to +455
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there you go @ctb

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