Genome-wide association studies (GWAS) find thousands of variants linked to diseases and complex traits, but they do not say in which cells these variants act. scDRS (single-cell disease-relevance score; Zhang, Hou et al., Nature Genetics 2022) answers that question at the level of individual cells. It takes a disease gene set, the top genes of a gene-level GWAS analysis such as MAGMA, and scores every cell of a single-cell RNA-seq data set for excess expression of these genes. The comparison is not with zero but with many random control gene sets that match the disease genes in mean expression and variance, so the score is not driven by how much a cell expresses in general. The result is:
RscDRS is a native R implementation of scDRS for
SingleCellExperiment
objects. It does not call Python. Each function is tested against the
original Python package (scdrs 1.0.4, https://github.com/martinjzhang/scDRS). The R functions
follow the Python ones and the scdrs command line tool:
| Step | R | Python |
|---|---|---|
| gene sets | scdrsReadGeneSets(),
scdrsMungeGeneSets() |
util.load_gs,
scdrs munge-gs |
| normalization | scdrsNormalize() |
util.load_h5ad |
| preprocessing | scdrsPreprocess() |
pp.preprocess |
| scoring | scdrsScoreCells(),
scdrsComputeScore() |
score_cell,
scdrs compute-score |
| cell-cell graph | scdrsBuildGraph() |
sc.pp.pca +
sc.pp.neighbors |
| group analysis | scdrsTestGroups() |
downstream_group_analysis |
| correlation, genes | scdrsTestCorrelation(),
scdrsRankGenes() |
downstream_corr_analysis,
downstream_gene_analysis |
| all downstream | scdrsPerformDownstream() |
scdrs perform-downstream |
The package ships the toy data of the original scDRS: 2,500 mouse
genes and 30 cells from Tabula Muris Senis. In this simulation, 10 cells
(causal_cell) overexpress the disease genes and 20 cells
(non_causal_cell) do not. The assay logcounts
holds size-factor normalized, natural-log log1p data, which
is what scDRS expects. For raw counts, scdrsNormalize()
does the same filtering and normalization as
scdrs compute-score. Do not use
scuttle::logNormCounts(), which uses log2 and centred size
factors.
sce <- scdrsLoadToyData()
sce
#> class: SingleCellExperiment
#> dim: 2500 30
#> metadata(0):
#> assays(1): logcounts
#> rownames(2500): Pip4k2a Chd7 ... Smc2 Cops4
#> rowData names(1): label
#> colnames(30): N1.MAA000586.3_8_M.1.1-1-1 F10.D041911.3_8_M.1.1-1-1 ...
#> F12_B000808_B008541_S132.mm10-plus-6-0 J10_B003899_S130.mus-7-0-1
#> colData names(5): label cell_type causal_variable non_causal_variable
#> covariate
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
table(sce$cell_type)
#>
#> causal_cell non_causal_cell
#> 10 20
head(colData(sce)[, c("cell_type", "causal_variable", "covariate")])
#> DataFrame with 6 rows and 3 columns
#> cell_type causal_variable covariate
#> <character> <numeric> <integer>
#> N1.MAA000586.3_8_M.1.1-1-1 causal_cell 10.131912 10
#> F10.D041911.3_8_M.1.1-1-1 causal_cell 8.019434 10
#> A17_B002755_B007347_S17.mm10-plus-7-0 causal_cell 10.768771 10
#> C22_B003856_S298_L004.mus-2-0-1 causal_cell 9.578672 10
#> G12.B002765.3_38_F.1.1-1-1 causal_cell 9.530689 10
#> H5.B003278.3_38_F.1.1-1-1 causal_cell 0.875696 10colData also holds a covariate to regress out
(covariate) and two cell-level variables, one of them
related to the disease (causal_variable) and one not
(non_causal_variable).
Gene sets come in the scDRS .gs format: a tab-separated
file with columns TRAIT and GENESET, where a
gene set is a comma-separated list of genes (g1,g2) or of
genes with weights (g1:w1,g2:w2).
scdrsReadGeneSets() returns a named list with one named
numeric vector of weights per trait. Human gene sets, the usual output
of a GWAS, can be mapped to mouse genes with the homolog table shipped
with scDRS:
gsMouse <- scdrsReadGeneSets(system.file("extdata", "toydata_mouse.gs",
package = "RscDRS"))
gsHuman <- scdrsReadGeneSets(system.file("extdata", "toydata_human.gs",
package = "RscDRS"), srcSpecies = "human", dstSpecies = "mouse",
intersect = rownames(sce))
lengths(gsMouse)
#> toydata_gs_mouse
#> 250
lengths(gsHuman)
#> toydata_gs_human
#> 250
head(gsMouse$toydata_gs_mouse)
#> Mrps33 Cyp4f13 Kazald1 Uqcrq Mblac2 Zfp180
#> 1 1 1 1 1 1To make gene sets from gene-level GWAS results (e.g. MAGMA p-values
for many traits), use scdrsMungeGeneSets(). By default it
keeps the 1,000 genes with the smallest p-values and weights them by
their z-scores:
scdrsPreprocess() regresses covariates out of the
expression data, adding back each gene’s mean. It then computes the gene
statistics that scDRS uses to choose control genes: mean, variance,
technical variance and mean-variance bins. The covariates here are one
colData column. A constant term is added automatically.
With a sparse assay the correction is done implicitly and the data stays
sparse. The input assay is never changed. The gene statistics go to
rowData, prefixed scdrs_.
sce <- scdrsPreprocess(sce, cov = "covariate")
#> Too few genes for 20*20 bins, setting nMeanBin = nVarBin = 15
rowData(sce)[1:3, c("scdrs_mean", "scdrs_var", "scdrs_var_tech",
"scdrs_mean_var")]
#> DataFrame with 3 rows and 4 columns
#> scdrs_mean scdrs_var scdrs_var_tech scdrs_mean_var
#> <numeric> <numeric> <numeric> <character>
#> Pip4k2a 4.64725 0.4537622 0.176877 11.11
#> Chd7 4.46020 0.0847056 0.142655 5.3
#> Atp6v0c 4.69168 0.1107835 0.744193 11.0The control genes are matched to the disease genes within these bins. The figure shows the gene means and variances, with the disease genes highlighted:
rd <- as.data.frame(rowData(sce)[, c("scdrs_mean", "scdrs_var")])
rd$set <- ifelse(rownames(rd) %in% names(gsMouse$toydata_gs_mouse),
"disease gene", "other gene")
rd <- rd[order(rd$set == "disease gene"), ]
ggplot(rd, aes(scdrs_mean, scdrs_var, colour = set)) +
geom_point(size = 1.8, alpha = 0.8) +
scale_colour_manual(values = c(`disease gene` = "#257de0",
`other gene` = "#c8c8c8"), name = NULL) +
labs(x = "Mean log expression", y = "Variance") +
theme_minimal(base_size = 14) +
theme(panel.grid.minor = element_blank(), legend.position = "top")Mean and variance of the 2,500 genes after covariate correction. The 250 disease genes (blue) span the whole range, so their control genes come from all over it.
scdrsScoreCells() scores one gene set. Control gene sets
are drawn at random with R’s random number generator, so call
set.seed() first for reproducible results.
nCtrl = 1000 is the scDRS default. The normalized control
scores are needed for the downstream analyses, so we keep them.
set.seed(2022)
res <- scdrsScoreCells(sce, gsMouse$toydata_gs_mouse, nCtrl = 1000,
returnCtrlNormScore = TRUE)
res[1:4, c("raw_score", "norm_score", "pval", "zscore")]
#> DataFrame with 4 rows and 4 columns
#> raw_score norm_score pval
#> <numeric> <numeric> <numeric>
#> N1.MAA000586.3_8_M.1.1-1-1 4.74457 4.88991 3.33322e-05
#> F10.D041911.3_8_M.1.1-1-1 4.74265 4.56948 6.66644e-05
#> A17_B002755_B007347_S17.mm10-plus-7-0 4.63811 4.25031 6.66644e-05
#> C22_B003856_S298_L004.mus-2-0-1 4.68241 5.44646 3.33322e-05
#> zscore
#> <numeric>
#> N1.MAA000586.3_8_M.1.1-1-1 3.98789
#> F10.D041911.3_8_M.1.1-1-1 3.82023
#> A17_B002755_B007347_S17.mm10-plus-7-0 3.82023
#> C22_B003856_S298_L004.mus-2-0-1 3.98789
dim(res$ctrl_norm_score)
#> [1] 30 1000The result is a DataFrame with one row per cell.
norm_score is the normalized disease score.
pval is the cell-level p-value: the fraction of all control
scores, pooled over all cells, that are at least as high. The results
can be added to colData:
sce$scdrs_norm_score <- res$norm_score
sce$scdrs_fdr <- p.adjust(res$pval, method = "BH")
table(cell_type = sce$cell_type, FDR_below_0.1 = sce$scdrs_fdr < 0.1)
#> FDR_below_0.1
#> cell_type FALSE TRUE
#> causal_cell 5 5
#> non_causal_cell 20 0The causal cells have clearly higher scores. Each control gene set gives one normalized control score per cell, and the grey band shows where most of them fall:
df <- data.frame(cell_type = sce$cell_type, score = res$norm_score,
significant = sce$scdrs_fdr < 0.1)
band <- quantile(res$ctrl_norm_score, c(0.025, 0.975))
ggplot(df, aes(cell_type, score, colour = cell_type)) +
annotate("rect", xmin = -Inf, xmax = Inf, ymin = band[1],
ymax = band[2], fill = "grey92") +
geom_hline(yintercept = 0, colour = "grey70", linewidth = 0.3) +
geom_point(aes(shape = significant), size = 3.4,
position = position_jitter(width = 0.12, seed = 1)) +
scale_colour_manual(values = c(causal_cell = "#257de0",
non_causal_cell = "#f47230"), guide = "none") +
scale_shape_manual(values = c(`TRUE` = 16, `FALSE` = 1),
labels = c(`TRUE` = "FDR < 0.1", `FALSE` = "not significant"),
name = NULL) +
labs(x = NULL, y = "Normalized disease score") +
theme_minimal(base_size = 14) +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(), legend.position = "top")Normalized disease score of each cell (points) by cell type. The grey band holds 95% of the normalized control scores of all cells. Filled points are significant at FDR < 0.1.
Several gene sets are scored in one call with
scdrsComputeScore(), the counterpart of
scdrs compute-score. It preprocesses the data if needed,
skips gene sets with fewer than 10 genes in the data, and returns a list
of score tables. scdrsWriteScores() writes them as the
.score.gz and .full_score.gz files of the
Python tool, and scdrsReadScores() reads files written by
either tool.
set.seed(2022)
allScores <- scdrsComputeScore(sce, c(gsMouse, gsHuman), nCtrl = 1000)
#> Trait=toydata_gs_mouse, n_gene=250: 5/30 FDR<0.1 cells, 5/30 FDR<0.2 cells
#> Trait=toydata_gs_human, n_gene=250: 5/30 FDR<0.1 cells, 5/30 FDR<0.2 cells
names(allScores)
#> [1] "toydata_gs_mouse" "toydata_gs_human"The heterogeneity test needs a cell-cell neighbour graph.
scdrsBuildGraph() builds it as
scdrs perform-downstream does with scanpy: a PCA with 20
components, the 15 nearest neighbours of each cell, and UMAP
connectivities as edge weights. The graph is stored in
colPair(sce). Any other graph, e.g. from bluster,
can be used instead.
scdrsTestGroups() then tests each group of cells for
association with the disease (assoc_*), comparing the 95%
quantile of the group’s scores with the same quantile of each control
score. It also tests heterogeneity within the group
(hetero_*, Geary’s C), and counts the cells below several
FDR levels.
grp <- scdrsTestGroups(sce, res, groupCols = "cell_type")
grp$cell_type[, c("n_cell", "assoc_mcp", "assoc_mcz", "hetero_mcp",
"n_fdr_0.1")]
#> DataFrame with 2 rows and 5 columns
#> n_cell assoc_mcp assoc_mcz hetero_mcp n_fdr_0.1
#> <numeric> <numeric> <numeric> <numeric> <numeric>
#> causal_cell 10 0.000999001 8.86523 0.177822 5
#> non_causal_cell 20 0.898101898 -1.19375 0.744256 0gdf <- as.data.frame(grp$cell_type)
gdf$cell_type <- rownames(gdf)
gdf$label <- sprintf("p = %.3g", gdf$assoc_mcp)
ggplot(gdf, aes(assoc_mcz, cell_type, colour = cell_type)) +
geom_vline(xintercept = 0, colour = "grey70", linewidth = 0.3) +
geom_vline(xintercept = 1.96, colour = "grey60", linewidth = 0.3,
linetype = "dashed") +
geom_segment(aes(x = 0, xend = assoc_mcz, yend = cell_type),
linewidth = 1) +
geom_point(size = 4) +
geom_text(aes(label = label, hjust = ifelse(assoc_mcz < 0, 1.25,
-0.25)), colour = "grey25", size = 4.2) +
expand_limits(x = range(c(gdf$assoc_mcz, 0)) + c(-2.5, 2.5)) +
scale_colour_manual(values = c(causal_cell = "#257de0",
non_causal_cell = "#f47230"), guide = "none") +
labs(x = "Association z-score (assoc_mcz)", y = NULL) +
theme_minimal(base_size = 14) +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank())Group-level association z-scores. Only the causal cells are associated with the disease; the dashed line marks z = 1.96.
None of the groups shows significant heterogeneity here, as expected: all the disease cells of the simulation are alike.
scdrsTestCorrelation() tests whether the disease score
correlates with continuous cell-level variables more than the control
scores do:
scdrsTestCorrelation(sce, res, c("causal_variable", "non_causal_variable"))
#> DataFrame with 2 rows and 3 columns
#> n_ctrl corr_mcp corr_mcz
#> <numeric> <numeric> <numeric>
#> causal_variable 1000 0.000999001 3.991476
#> non_causal_variable 1000 0.376623377 0.350912scdrsRankGenes() ranks genes by the correlation of their
expression with the disease score, a way to prioritize genes:
head(scdrsRankGenes(sce, res), 5)
#> DataFrame with 5 rows and 2 columns
#> CORR RANK
#> <numeric> <integer>
#> Tm4sf1 0.189274 1
#> Krt14 0.178838 2
#> Cd9 0.178055 3
#> Serping1 0.172495 4
#> Igfbp7 0.167098 5scdrsPerformDownstream() runs all three analyses, for
one score table or a list of them, like
scdrs perform-downstream:
out <- scdrsPerformDownstream(sce, allScores, groupCols = "cell_type",
varCols = "causal_variable")
out$toydata_gs_human$group$cell_type[, c("assoc_mcp", "hetero_mcp")]
#> DataFrame with 2 rows and 2 columns
#> assoc_mcp hetero_mcp
#> <numeric> <numeric>
#> causal_cell 0.000999001 0.197802
#> non_causal_cell 0.933066933 0.738262The scores can be shown on a UMAP of the cells, computed with uwot from the
PCA that scdrsBuildGraph() stored. UMAP is random, so we
set a seed; with only 30 cells we use few neighbours and wide spacing.
The three clusters are the three values of the simulated covariate (the
PCA is of the uncorrected data), not cell types:
set.seed(1)
reducedDim(sce, "UMAP") <- uwot::umap(reducedDim(sce, "scdrs_pca"),
n_neighbors = 5, min_dist = 1)um <- as.data.frame(reducedDim(sce, "UMAP"))
colnames(um) <- c("UMAP1", "UMAP2")
um$score <- sce$scdrs_norm_score
um$significant <- sce$scdrs_fdr < 0.1
ggplot(um, aes(UMAP1, UMAP2)) +
geom_point(data = um[um$significant, ], size = 6, shape = 21,
colour = "grey20", stroke = 0.6) +
geom_point(aes(colour = score), size = 4) +
scale_colour_gradient(low = "#cce3fd", high = "#0e3d7e",
name = "Normalized\nscore") +
theme_minimal(base_size = 14) +
theme(panel.grid.minor = element_blank())UMAP of the cells, coloured by normalized disease score for the mouse gene set; circled cells are significant at FDR < 0.1.
The package includes the Python scDRS results for the same analysis
(toydata_mouse_python_scores.csv.gz: scdrs 1.0.4,
preprocess with the covariates, score_cell
with 1,000 control gene sets; see inst/scripts/python/).
Because the two packages draw their control gene sets with different
random number generators, the scores differ by Monte Carlo noise
only:
py <- read.csv(system.file("extdata", "toydata_mouse_python_scores.csv.gz",
package = "RscDRS"), row.names = 1)[colnames(sce), ]
cor(res$norm_score, py$norm_score)
#> [1] 0.999403
table(R = sce$scdrs_fdr < 0.1,
Python = p.adjust(py$pval, method = "BH") < 0.1)
#> Python
#> R FALSE TRUE
#> FALSE 25 0
#> TRUE 0 5both <- data.frame(R = res$norm_score, Python = py$norm_score,
cell_type = sce$cell_type)
ggplot(both, aes(Python, R)) +
geom_abline(slope = 1, intercept = 0, colour = "grey60",
linetype = "dashed") +
geom_point(aes(colour = cell_type), size = 3.4) +
scale_colour_manual(values = c("#257de0", "#f47230"),
name = "Cell type") +
coord_equal() +
labs(x = "Python scDRS", y = "RscDRS") +
theme_minimal(base_size = 14) +
theme(panel.grid.minor = element_blank(), legend.position = "bottom")Normalized disease score of each cell computed by RscDRS and by the Python scDRS; the dashed line is y = x.
side <- rbind(
data.frame(um[, c("UMAP1", "UMAP2")], score = both$R,
package = "RscDRS"),
data.frame(um[, c("UMAP1", "UMAP2")], score = both$Python,
package = "Python scDRS"))
side$package <- factor(side$package, c("RscDRS", "Python scDRS"))
ggplot(side, aes(UMAP1, UMAP2, colour = score)) +
geom_point(size = 3.6) +
facet_wrap(~package) +
scale_colour_gradient(low = "#cce3fd", high = "#0e3d7e",
name = "Normalized\nscore") +
theme_minimal(base_size = 14) +
theme(panel.grid.minor = element_blank(),
strip.text = element_text(face = "bold", size = 14))The same scores on the UMAP of the cells: RscDRS (left) and the Python scDRS (right), on one colour scale.
controlSets), R reproduces Python’s results to float32
precision. There is no seed argument: use
set.seed().scdrsBuildGraph()
computes the PCA with BiocSingular
and the exact nearest neighbours with BiocNeighbors,
then scanpy’s UMAP connectivities. On the toy data the graph equals
scanpy’s to 1e-4. On large data the PCA and neighbour search can differ
slightly, and so can hetero_*.rowData,
colData, reducedDim and metadata
with the prefix scdrs_. Scores are returned as
DataFrames with control scores as matrix columns.score_cell_vision and score_cell_scanpy of the
benchmarks in the paper, archived functions, and the plotting helpers.
The figures above are made with ggplot2.If you use RscDRS, please cite the original scDRS paper:
Zhang MJ, Hou K, Dey KK, Sakaue S, Jagadeesh KA, Weinand K, Taychameekiatchai A, Rao P, Pisco AO, Zou J, Wang B, Gandal M, Raychaudhuri S, Pasaniuc B, Price AL (2022). Polygenic enrichment distinguishes disease associations of individual cells in single-cell RNA-seq data. Nature Genetics 54, 1572-1580. doi:10.1038/s41588-022-01167-z
citation("RscDRS")
#> To cite package 'RscDRS' in publications use:
#>
#> Zhang MJ, Hou K, Dey KK, et al. (2022). Polygenic enrichment
#> distinguishes disease associations of individual cells in single-cell
#> RNA-seq data. Nature Genetics 54, 1572-1580.
#> doi:10.1038/s41588-022-01167-z
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Article{,
#> title = {Polygenic enrichment distinguishes disease associations of individual cells in single-cell RNA-seq data},
#> author = {Martin Jinye Zhang and Kangcheng Hou and Kushal K. Dey and Saori Sakaue and Karthik A. Jagadeesh and Kathryn Weinand and Aris Taychameekiatchai and Poorvi Rao and Angela Oliveira Pisco and James Zou and Bruce Wang and Michael Gandal and Soumya Raychaudhuri and Bogdan Pasaniuc and Alkes L. Price},
#> journal = {Nature Genetics},
#> year = {2022},
#> volume = {54},
#> pages = {1572--1580},
#> doi = {10.1038/s41588-022-01167-z},
#> }sessionInfo()
#> R version 4.6.2 (2026-10-29)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] ggplot2_4.0.4 RscDRS_0.99.0
#> [3] SingleCellExperiment_1.35.2 SummarizedExperiment_1.45.0
#> [5] Biobase_2.73.2 GenomicRanges_1.67.0
#> [7] Seqinfo_1.5.0 IRanges_2.47.5
#> [9] S4Vectors_0.53.0 BiocGenerics_0.59.13
#> [11] generics_0.1.4 MatrixGenerics_1.27.0
#> [13] matrixStats_1.5.0 BiocStyle_2.41.0
#>
#> loaded via a namespace (and not attached):
#> [1] sass_0.5.0 SparseArray_1.15.0 lattice_0.23-1
#> [4] digest_0.6.39 evaluate_1.0.5 grid_4.6.2
#> [7] RColorBrewer_1.1-3 fastmap_1.2.0 jsonlite_2.0.0
#> [10] Matrix_1.7-6 BiocManager_1.30.27 scales_1.4.0
#> [13] codetools_0.2-20 jquerylib_0.1.4 abind_1.4-8
#> [16] cli_3.6.6 rlang_1.3.0 XVector_0.53.0
#> [19] BiocNeighbors_2.9.0 uwot_0.2.5 withr_3.0.3
#> [22] cachem_1.1.0 DelayedArray_0.39.8 yaml_2.3.12
#> [25] FNN_1.1.4.1 otel_0.3.0 S4Arrays_1.15.0
#> [28] beachmat_2.29.3 parallel_4.6.2 tools_4.6.2
#> [31] BiocParallel_1.47.0 rsvd_2.0.0 buildtools_1.0.0
#> [34] vctrs_0.7.3 R6_2.6.1 lifecycle_1.0.5
#> [37] BiocSingular_1.31.0 irlba_2.4.1 ScaledMatrix_1.21.0
#> [40] bslib_0.12.0 gtable_0.3.6 Rcpp_1.1.2
#> [43] glue_1.8.1 xfun_0.62 sys_3.4.3
#> [46] knitr_1.52 farver_2.1.2 htmltools_0.5.9
#> [49] labeling_0.4.3 rmarkdown_2.32 maketools_1.3.2
#> [52] compiler_4.6.2 S7_1.0.0