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

Fix skani shuffle #39

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions src/clusterer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,30 @@ mod tests {
}
assert_eq!(vec![vec![0, 1, 3], vec![2]], clusters)
}

#[test]
fn test_skani_skani_two_preclusters() {
init();
let mut clusters = cluster(
&[
"tests/data/abisko4/73.20120800_S1X.13.fna",
"tests/data/abisko4/73.20120600_S2D.19.fna",
"tests/data/abisko4/73.20120700_S3X.12.fna",
"tests/data/abisko4/73.20110800_S2D.13.fna",
"tests/data/antonio_mags/BE_RX_R2_MAG52.fna",
],
&crate::skani::SkaniPreclusterer {
threshold: 90.0,
min_aligned_threshold: 0.2,
},
&crate::skani::SkaniClusterer {
threshold: 99.0,
min_aligned_threshold: 0.2,
},
);
for cluster in clusters.iter_mut() {
cluster.sort_unstable();
}
assert_eq!(vec![vec![4], vec![0, 1, 3], vec![2]], clusters)
}
}
15 changes: 14 additions & 1 deletion src/skani.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn precluster_skani(
.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>();
// Note that sketches is now shuffled!
let sketches = &file_io::fastx_to_sketches(&fasta_strings, &sketch_params, true);

// Right now implemented by parallel collection into a queue, and then
Expand Down Expand Up @@ -73,9 +74,21 @@ fn precluster_skani(
let map_params = chain::map_params_from_sketch(ref_sketch, false, &command_params);
let ani_result = chain::chain_seeds(ref_sketch, &sketches[j], map_params);
let ani = ani_result.ani * 100.;
let ref_name = ref_sketch.file_name.clone();
let query_name = sketches[j].file_name.clone();

debug!("Pushing ANI result for {} and {}", ref_name, query_name);
let ref_index = genome_fasta_paths
.iter()
.position(|&r| r == ref_name)
.unwrap();
let query_index = genome_fasta_paths
.iter()
.position(|&r| r == query_name)
.unwrap();
if ani >= threshold {
queue
.push((i, j, ani))
.push((ref_index, query_index, ani))
.expect("Failed to push to queue during preclustering");
}
}
Expand Down
Loading