
Correlate one gene against all others within each cell type
CorrelateGene.RdComputes Spearman (or Pearson) correlation between a gene of interest (GOI) and every other gene, separately within each cell type. Three resolution levels are supported:
Arguments
- seurat_object
A Seurat object.
- gene
Character. The gene of interest (GOI).
- group.by
Character. Cell-type identity column.
- level
Character.
"sc"(default),"pseudobulk", or"group".- compare.by
Character or
NULL. Optional metadata column whose levels define independent comparison groups (e.g."Sex","Diagnosis"). When supplied, correlation is computed separately within each level so you can ask which genes are correlated with GOI in group A but not group B.- sample.by
Character. Donor/sample ID. Required for
"pseudobulk".- condition.by
Character. Condition column. Required for
"group".- assay
Character or
NULL. Assay to use.- layer
Character. Layer/slot for SC and group levels. Default
"data".- method
Character.
"spearman"(default) or"pearson".- expressed_only
Logical. SC level: restrict to GOI > 0 cells? Default
TRUE.- min_pct
Numeric. SC level: minimum % of (GOI-expressing) cells that must express a tested gene. Default
10.- min_cells
Integer. SC level: minimum cells per cell type. Default
20.- min_donors
Integer. Pseudobulk level: minimum donors. Default
5.- min_groups
Integer. Group level: minimum groups. Default
3.
Value
A data frame: gene, cell_type, r, p, padj, n, goi,
level, method, and (when compare.by is set) compare_group.
Sorted by cell type then descending |r|.
Details
"sc": cell level. Restricts to cells where GOI > 0 (expressed_only = TRUE) by default to avoid co-absence artifacts from dropout. Exploratory; validate hits at pseudobulk level."pseudobulk": donor level. Aggregates raw counts per donor x cell type, converts to edgeR log-CPM, then runs Spearman across donors. Statistically most valid."group": averages log-normalized expression within eachcondition.by x cell_typecombination, then correlates across groups.
When compare.by is supplied, the analysis is run separately within each
level of that variable (e.g. compare.by = "Sex" produces independent
correlation tables for males and females). Results gain a compare_group
column and PlotCorrelation() will lay the groups out side by side.