Add diffexp and diffadb projections to plot_features (#26)#27
Merged
Conversation
Allow plot_features() to visualize differential expression and differential pathway activity as projection types, as requested in #26. - plot_features() gains projection = "diffexp" (per-cell differential expression for selected genes, with optional include_O) and "diffadb" (per-cell differential pathway activity for selected pathways), both driven by a user `contrast`. The diffexp path evaluates only the selected gene rows and never materialises the full J x N matrix. - New getDiffADB_cpp kernel and model$diffADB(contrast) method. diffADB is the exact differential of ADB (i.e. ADB(Z + dQ) - ADB(Z)): it applies the same solve_A shrinkage operator, so it stays on the same scale as model$projections$ADB. - Coerce prior matrices to dense double before mapping into Eigen so an integer or sparse C prior (e.g. a 0/1 membership matrix) is handled. - Tests: API and edge-case coverage plus numerical math-invariant checks (solve_A identity, diffADB == differential of ADB, contrast linearity, plot-value correctness). Full testthat suite: 134 passing.
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
Implements the feature requested in #26: visualize differential expression (and, symmetrically, differential pathway activity) with
plot_features()by exposing them as projection types.plot_features()gains two newprojectionvalues, both driven by a usercontrast:projection = "diffexp"— per-cell differential expression for selected genes (optionalinclude_O = TRUEto add the global offset effect). The efficient path evaluates only the selected gene rows and never materialises the fullJ x Nmatrix.projection = "diffadb"— per-cell differential pathway activity for selected pathways (requires a gene-level priorC).Also adds the public accessor
model$diffADB(contrast)(returnsnum_pathways x N).Design
Every GEDI projection has the form
Loadings · DB:ZDBusesZ,ADBusesC.rotation·A, anddiffExpuses the differential gene loadingsdiffQ_Z = [Rk·(H.rotation·contrast)].diffadbis the missing symmetric member.Because
solve_A()fitsAlinearly fromZ(A = (CᵀC + λI)⁻¹ CᵀZ,λ = 1/S_A),ADBis a fixed linear map of the gene loadings.diffADBis therefore defined as the exact differential ofADB:It applies the same
solve_Ashrinkage operator, somodel$diffADB()stays on the same scale asmodel$projections$ADB(rather than being off by1 + 1/S_A).Changes
getDiffADB_cppkernel (src/gedi_differential.cpp);compute_diffADBwrapper andmodel$diffADB()method;plot_features()wiring fordiffexp/diffadb.C(e.g. a 0/1 membership matrix) is handled.NEWS.mdentry; regeneratedman/,RcppExports.Testing
testthat: 134/134 pass, 0 fail/warn/skip, no regressions. Includes numerical math-invariant checks:solve_Aidentity,diffADB == ADB(Z+ΔQ) − ADB(Z), a shrinkage-scale regression guard, contrast linearity, and plot-value correctness (efficient path == full matrix).R CMD check: 0 errors, 0 warnings, 3 NOTES — all pre-existing/environmental (uninstalled optionalglmnet, cluster clock,-marchcompile flag); none introduced by this PR.