Skip sample-wise normalization for < 20 gene sets (single gene set returns a constant) - #15
Merged
Conversation
zitoa
approved these changes
Aug 10, 2026
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.
Problem
Scoring a single gene set returns the exact same value for every sample.
No error, no warning.
Cause
plaid()subtracts a per-sample baseline computed across gene sets:score_ij - baseline_j + mean(baseline). With one gene set the baseline ofsample j is the score itself, so this reduces to
mean(baseline), a constant.The
nrow(gsetX) < 20branch swaps the median for the column mean, but the twohave the same algebraic form, and for N = 1 the mean of one value equals the
median of one value — so the branch does not help. At N = 2 the variance is
exactly halved and the two rows become perfectly anticorrelated.
Fix
Skip the normalization below 20 gene sets. The existing comment on that branch
(
## for few genesets, median-norm is not good) already identifies the problem;this follows it through to the degenerate case, where the only correct amount of
normalization is none.
This also fixes
replaid.ssgsea,replaid.ucell,replaid.aucellandreplaid.gsva, which all normalize unconditionally and inherit the samebehaviour (
replaid.singandreplaid.scsealready passnormalize = FALSE).Compatibility
With >= 20 gene sets the output is bit-for-bit unchanged (checked on 50 hallmark
sets and on a 51-set collection: max absolute difference 0).