Repository navigation
Release 4.0.3: --primary_skani_min_af_both for plasmids (issue #311) - #312
Merged
Merged
Conversation
A primary-clustering edge only needed --primary_skani_min_af in one direction. A small plasmid that is mostly a shared transposon or resistance cassette aligns ~100% to every larger plasmid carrying it, so a few of them chain thousands of unrelated plasmids into one primary cluster, and secondary clustering then builds every pairwise comparison in it (741M Ndb rows and 350 GB for 27k Acinetobacter plasmids). The new flag requires the aligned fraction in both directions. Secondary clustering only groups pairs that align in both directions anyway, so with --primary_skani_min_af <= 100 x --cov_thresh and -pa <= -sa this splits primary clusters without changing the final clusters. On simulated plasmids sharing a transposon it turned 1 primary cluster into 9, with identical final clusters and winners and 9x fewer Ndb rows. It is opt-in, since the either-direction 15% default was tuned to reproduce the MASH partition on UHGG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013UpcPFwkh6QMusnD6ApThL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
--primary_skani_min_af_bothflag that stops plasmid datasets from collapsing into one giant primary cluster (#311). Also bumps the version to 4.0.3, which publishes to PyPI automatically on merge.The problem. A pair becomes a primary-clustering edge if its aligned fraction passes
--primary_skani_min_afin either direction. Plasmids share mobile elements, and a small plasmid that is mostly a transposon or resistance cassette aligns ~100% to every larger plasmid carrying it. Under single linkage, a few of those plasmids chain thousands of unrelated plasmids together.In #311, 27,237 Acinetobacter plasmids ended up in 1 primary cluster. Secondary clustering then built every pair in it: 741,854,169 = 27,237² Ndb rows. That step is single-threaded and was still running after 22 h at 350 GB of RAM.
The fix.
--primary_skani_min_af_bothrequires the aligned fraction in both directions. This doesn't change the final clusters, as long as--primary_skani_min_af≤ 100 ×--cov_threshand-pa≤-sa:--cov_thresh, then averages the two directions.-saand aligns in both directions.The flag is opt-in because the either-direction 15% default was tuned to reproduce the Mash partition on UHGG.
Changes
drep/d_cluster/union_find.py:cluster_edges(..., cov_both=False), plus a vectorized_reverse_coveragethat looks up the other direction's aligned fraction. A pair with only one direction present fails the both-directions check.drep/d_cluster/compare_utils.py: passes the flag through, and the log line says "in both directions".drep/argumentParser.py: adds the--primary_skani_min_af_bothflag.docs/module_descriptions.rstgets the new flag in both-hdumps.docs/choosing_parameters.rstgets a plasmid paragraph in the non-bacterial section.CHANGELOG.md: 4.0.3 entry. It also records that releases now publish automatically and that 4.0.1 never reached PyPI.drep/VERSION: 4.0.3.Testing
test_cov_both_stops_small_genomes_chaining_clusters. A small "transposon" plasmid chains two families into one cluster by default, but not withcov_both. A pair with only one direction present is not an edge.--primary_skani_min_af_both-pa 0.98 --primary_skani_min_af 50 --primary_skani_min_af_both-pa 0.98 --primary_skani_min_af 50without the new flagtests/tests: 85 passed, 12 skipped, 4 failed, all for reasons unrelated to this change:test_goANI,test_goANI2andtest_dereplicate_3need nsimscan, which isn't installed locally.test_drep_scaffold_levelfails the same way on master locally.🤖 Generated with Claude Code
https://claude.ai/code/session_013UpcPFwkh6QMusnD6ApThL
Generated by Claude Code