Skip to content

Fix distance with multiple samples and ambigous bases - #98

Merged
johnlees merged 6 commits into
masterfrom
distance-ambig
Jul 24, 2025
Merged

johnlees merged 6 commits into
masterfrom
distance-ambig

Conversation

@johnlees

Copy link
Copy Markdown
Member

Fixes an issue where distances can be reported differently with >2 samples

  • Simplify distance filtering by doing it in the distance function for each pair, rather than the entire alignment
  • Make ambiguous base consideration its own path, can be very simple if just checking mismatches

Also:

  • Make use of threads clearer in some subcommands
  • update clippy linting in ska lo

Closes #97

johnlees added 4 commits July 23, 2025 09:10
Move to the distance function itself
Fixes ambiguous bases still being included in multi-sample comparisons
@johnlees
johnlees requested a review from rderelle July 23, 2025 09:26
@johnlees

Copy link
Copy Markdown
Member Author

@rderelle Could you try this code on your test case?

@codecov

codecov Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 90.76923% with 6 lines in your changes missing coverage. Please review.

Project coverage is 94.90%. Comparing base (9483f03) to head (ec2df9a).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/lib.rs 57.14% 3 Missing ⚠️
src/skalo/positioning.rs 0.00% 1 Missing ⚠️
src/skalo/process_variants.rs 0.00% 1 Missing ⚠️
src/skalo/utils.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
+ Coverage   94.41%   94.90%   +0.49%     
==========================================
  Files          25       25              
  Lines        4098     3630     -468     
==========================================
- Hits         3869     3445     -424     
+ Misses        229      185      -44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rderelle

rderelle commented Jul 23, 2025 •

Copy link
Copy Markdown
Collaborator

@johnlees Distances working well: I'm getting stable distances between A and B in all conditions (2 isolates and m=0; 2 isolates and m=0.9; 56 isolates and m=0; 56 isolates and m=0.9).
In a few cases, distances differ by 1 SNP between m=0 and m=0.9 which is expected as some split k-mers are ignored at 0.9.

-> no need to change min-freq threshold value (only the doc '0.9' -> '0')

@rderelle

Copy link
Copy Markdown
Collaborator

There might be an issue with Mismatches though: the values I get do not make sense to me. If the number of SNP is constant, we should get higher proportion of mismatches at m=0.9 compared to m=0. However, I'm observing the opposite:

with m=0:
ERR2884613 ERR2884716 4.00 0.01784
with m=0.9:
ERR2884613 ERR2884716 4.00 0.00000

@johnlees

Copy link
Copy Markdown
Member Author

Mismatches I interpret as an estimate of the proportion of the genome that's alignable/been aligned. This could include the k-mers filtered out by min-freq if you interpret these all as unalignable; or you could exclude them (the current behaviour) if you interpret them as low quality data that shouldn't contribute to this estimate.

I was actually unsure whether to keep min-freq when changing this as it is based on the whole population, when it's probably more intuitive to work just on the pairwise comparisons. I preferred the default of zero because I thought that including distances from a highly variable region between a pair of samples makes the most sense – it's really more in the whole population alignment that min-freq is useful for removing columns that only a few samples have.

So I'm not really sure what's right or expected here. I can see in your example that feels a bit unintuitive, but if you consider the min-freq filter as only considering the high quality/constant areas of the genome then in those areas there are no mismatches.

It almost feels like separating out these two terms might be best, and indeed if you run with -v you get a report of the number filtered by min-freq.

But I could also easily change this so the min-freq filtered k-mers contribute to mismatches.

What do you think?

@rderelle

rderelle commented Jul 23, 2025 •

Copy link
Copy Markdown
Collaborator

@johnlees I thought Mismatches corresponded to the ratio of SNPs divided by shared kmers but, looking closely at the code, your definition is the correct one (proportion of non-aligned genome). Then the values observed at m=0 and m=0.9 are the expected ones (most non-aligned split-kmers are discarded at m=0.9 leading to Mismatches = 0). No bug, my mistake.

That said, the metric makes a little less sense when filtering is applied because the set of considered split k-mers does not represent the whole genome anymore, so good news we are keeping m=0. :)

Up to you, but I would keep Mismatches as it is as I do not have any strong alternative preference.

@rderelle rderelle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

all good to me.

@johnlees

Copy link
Copy Markdown
Member Author

Thanks for your input! I might make a little addition to the docs about the interpretation of mismatches and otherwise leave as-is

@johnlees
johnlees merged commit c8d5834 into master Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with ska distance for large data sets

2 participants