Skip to content

Commit 53cfe23

Browse files
committed
Updated to ANI
1 parent e39bc24 commit 53cfe23

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/distances/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::sketch::multisketch::MultiSketch;
1414
pub mod distance_matrix;
1515
use self::distance_matrix::*;
1616
mod jaccard;
17+
pub use self::jaccard::ani_pois;
1718
use self::jaccard::*;
1819

1920
/// Chunk size in parallel distance calculations

src/io.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ pub fn read_completeness_file(
260260
.filter_map(|line| {
261261
if let Some((genome_id, completeness_str)) = line.split_once('\t') {
262262
if let Ok(completeness) = completeness_str.parse::<f64>() {
263-
sketches.get_sample_index(genome_id).map(|index| (index, completeness))
263+
sketches
264+
.get_sample_index(genome_id)
265+
.map(|index| (index, completeness))
264266
} else {
265267
None
266268
}

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ use crate::sketch::sketch_datafile::SketchArrayReader;
179179
use crate::sketch::{num_bins, sketch_files};
180180

181181
pub mod inverted;
182+
#[cfg(target_family = "wasm")]
183+
use crate::distances::ani_pois;
182184
use crate::inverted::Inverted;
183185

184186
pub mod distances;
@@ -1054,7 +1056,7 @@ impl SketchlibData {
10541056
}
10551057

10561058
/// Mapping function.
1057-
pub fn get_probs(&self, nouts: usize) -> String {
1059+
pub fn get_ani(&self, nouts: usize) -> String {
10581060
if self.out_probs.is_empty() {
10591061
panic!("No probabilities calculated!");
10601062
}
@@ -1068,13 +1070,13 @@ impl SketchlibData {
10681070

10691071
let selected = select_ranked_matches(&self.out_probs, nouts);
10701072

1071-
results["probs"] = json::JsonValue::Array(
1073+
results["ani"] = json::JsonValue::Array(
10721074
selected
10731075
.iter()
10741076
.map(|x| {
10751077
let matches = x.0 as f64;
1076-
let similarity = matches / ((2 * self.index.sketch_size()) as f64 - matches);
1077-
json::JsonValue::Number(similarity.into())
1078+
let jaccard = matches / ((2 * self.index.sketch_size()) as f64 - matches);
1079+
json::JsonValue::Number(ani_pois(jaccard, self.index.kmer() as f64).into())
10781080
})
10791081
.collect(),
10801082
);
@@ -1147,7 +1149,7 @@ mod wasm_result_ranking_tests {
11471149
}
11481150

11491151
#[test]
1150-
fn get_probs_three_excludes_internal_rank_three() {
1152+
fn get_ani_three_excludes_internal_rank_three() {
11511153
let matches = vec![(10, 0), (9, 1), (8, 2), (7, 3)];
11521154
assert!(!select_ranked_matches(&matches, 3).contains(&(7, 3, 3)));
11531155
}

0 commit comments

Comments
 (0)