Skip to content

Use non-exact matrix downsample test comparison - #129

Merged
jonathangriffiths merged 4 commits into
develfrom
downsample_logic_change
Apr 8, 2026
Merged

jonathangriffiths merged 4 commits into
develfrom
downsample_logic_change

Conversation

@jonathangriffiths

Copy link
Copy Markdown
Collaborator

scuttle commit a997286 (March 27, 2026) rewrote downsampleMatrix() to use the tatami API, replacing the scuttle::downsample_vector Bernoulli loop with Rf_rhyper() per gene per cell. The previous tests relied on both functions sharing the same RNG sequence under a fixed seed — that equivalence is now broken.

Proposed fix:

Replace the seed-coupled exact comparison with direct correctness checks on downsampleReads() output:

  • Dimensions and dimnames match the input
  • No count is negative or exceeds the original
  • Aggregate totals are exact: sum(Y) == round(prop * sum(X)) for bycol=FALSE; colSums(Y) == round(prop * colSums(X)) for bycol=TRUE (both guaranteed by no-replacement sampling)

@LTLA

LTLA commented Apr 8, 2026

Copy link
Copy Markdown
Member

Oops, forgot about the downstream implications.

A better solution would be for me to actually update scuttle::downsample_vector() to use rhyper(), which would allow everyone to be efficient while maintaining consistency.

LTLA added 3 commits April 8, 2026 16:26
Also added some more checks to ensure we don't lose integer precision.
These tests no longer make sense because the downsampling is no longer done on
a per-event basis (i.e. single UMIs or reads in each count). Rather, the new
algorithm operates on the entire count at once, for greater efficiency.

This all means that UMI and read counts are no longer interchangeable, which
means that the results from downsampleReads/Matrix are no longer directly
comparable. This is okay - the test itself was highly contrived anyway as it
only works when every UMI has a single read.
@LTLA

LTLA commented Apr 8, 2026

Copy link
Copy Markdown
Member

Just remove the affected test, there's no point changing it to test for correctness because the prior tests already do that.

Also switched to the new hypergeometric sampler for downsampleReads(), which should be more efficient. Ignore the CI failure, this requires the latest scuttle version that is yet to propagate on BioC-devel.

@jonathangriffiths

Copy link
Copy Markdown
Collaborator Author

Impressive as ever: I was just putting this up to run the tests before asking you what you thought, and here you are with the answer ready-baked.

Though as you point out I should have read beyond the affected test!

Cheers

@jonathangriffiths
jonathangriffiths merged commit f952d5d into devel Apr 8, 2026
1 check failed
@jonathangriffiths
jonathangriffiths deleted the downsample_logic_change branch April 8, 2026 07:59
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.

2 participants