Normalise the simulated data the same way as the real data - #18
Merged
Conversation
8 tasks
rcannood
force-pushed
the
fix/metric-normalisation
branch
from
July 28, 2026 12:24
76a5826 to
7471a5a
Compare
rcannood
force-pushed
the
fix/metric-normalisation
branch
from
July 28, 2026 12:31
7471a5a to
8d12522
Compare
`downstream` built the simulated `logcounts` with `log1p(counts)`, but read the real dataset's stored `logcounts` layer for the other side of the comparison. That layer is `log2(counts / sizeFactor + 1)` -- verified exactly against the shipped dataset -- so the two sides differed by a whole transform and Moran's I partly measured that rather than the data. Both sides now go through a shared `compute_logcounts()`, which reproduces the stored layer to 9e-16, so the real side is unchanged and only the simulated side moves. On the positive control, where the simulated data is the real data, crosscor_cosine and crosscor_mantel go from 0.95 to exactly 1.
rcannood
force-pushed
the
fix/metric-normalisation
branch
from
July 28, 2026 12:32
8d12522 to
db076bb
Compare
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.
Describe your changes
downstreambuilt the simulatedlogcountswithlog1p(counts), but read the real dataset's storedlogcountslayer for the other side of the comparison.generate_moransI()then compared the two, so the metric partly measured the difference in transform rather than the difference in the data.The stored layer turns out to be exactly
log2(counts / sizeFactor + 1), andsizeFactoris exactly the library size factor -- which is precisely whatscater::logNormCounts()computes. Checked against the shipped test dataset:So both sides now go through a shared
compute_logcounts(). It reproduces the stored layer to 9e-16, meaning the real side does not move at all -- only the simulated side changes, fromlog1pto the same normalisation the real data already had.On the positive control, whose "simulated" dataset is the real dataset and which should therefore score exactly 1:
Changes published numbers for
crosscor_cosineandcrosscor_mantel.A correction to what I said earlier
An earlier version of this PR also routed
ks_statistic_sc_featuresthrough the helper, and claimed the same problem applied there. It does not. That component was already computingscater::logNormCounts()for its simulated side, which is bit-identical tocompute_logcounts():So I have dropped that hunk -- it was a no-op.
That leaves its positive-control deviations (
ks_statistic_L_stats-1.246,_nn_correlation-1.463,_morans_I0.345, all of which should be 0) unexplained by normalisation. The likelier cause is that it takes the real cell type proportions from the precomputedobsm[["celltype_proportions"]]but recomputes the simulated ones withCARD_processing(), so the two sides come from different code paths. I'd rather look into that properly than fold a guess into this PR.Checklist before requesting a review
I have performed a self-review of my code
Check the correct box. Does this PR contain:
Proposed changes are described in the CHANGELOG.md
CI Tests succeed and look good!