
Find marker genes for cell types
find_markers.RdDiscovers marker genes for each cell type (cluster) in an expression
matrix or Seurat object, and returns them in the hitype marker database
format so the result can be passed directly to gs_prepare(). Three
backends are available: the dependency-light fold-change method
(default), Seurat's FindAllMarkers, and presto's Wilcoxon rank-sum
test. For method = "fc", the input expression matrix is expected to
be log-normalized.
Arguments
- exprs
A genes x cells expression matrix (plain matrix or dgCMatrix/dgTMatrix) or a Seurat object. For
method = "fc", the input is expected to be log-normalized.- clusters
A named vector of cluster ids (names = cells) or a factor. If
exprsis a Seurat object, defaults toSeurat::Idents(exprs).- method
The marker-finding method. One of:
- "fc"
Fold-change based (default). No extra dependencies. Ranks genes by
log2fc * (pct_in - pct_out).- "seurat"
Seurat's
FindAllMarkers. Requires a Seurat object.- "presto"
presto's Wilcoxon rank-sum test (
wilcoxauc). Requires the presto package.
- top
Number of markers to return per cell type: a single number applied to both positive and negative markers, or a length-2 vector
c(n_positive, n_negative)budgeting each direction separately (defaultc(10, 10)). The negative budget is only used whenpos_only = FALSE.- min_log2fc
Minimum log2 fold change for a gene to be kept as a marker (when
pos_only = TRUE).- min_pct
Minimum fraction of cells in the cell type expressing the gene.
- against
Restrict the reference group a cell type is compared against (by default one-vs-rest, i.e. all other cells). One of:
NULLOne-vs-rest (default).
- a character vector of cell types
Only the cells of those types form the reference group:
pct_out,log2fcand the score are computed against them instead of all the other cells, which recovers sibling-specific markers shared with the rest of the cells. A type listed inagainstcannot use its own cells as the reference, so they are excluded from its reference group; if no other listed type remains, no markers are returned for it."nearest"For each cell type, the single most similar other type is used as its reference group. Similarity is the Pearson correlation between the mean expression profiles of the two types (computed once per call over the input matrix), and the resolved type is then used exactly like an explicit
againstentry.
An error is raised if
againstnames a cell type not present in the data (available types are listed) or if it names the only cell type in the data (a type cannot be compared against itself). Negative markers (pos_only = FALSE) are extracted as before as genes low in the type vs the rest of the cells, but whenagainstis set they must ALSO satisfylog2fc <= -min_log2fcagainst the reference group, so that sibling-specific negative markers are found. Formethod = "seurat",againstis implemented with per-type two-groupSeurat::FindMarkers(ident.1 = type, ident.2 = against)calls ("nearest"is resolved to the per-type reference types first);method = "presto"does not supportagainstand raises an error.- max_pct_out
Drop positive-marker candidates expressed in more than this fraction of ALL other cells (the one-vs-rest
pct_out, computed over all cells not of the type even whenagainstis set), guarding against pan-lineage genes up-regulated in most other cell types. Negative markers are not subject to this guard. A single aggregated warning reports the number of dropped candidates per cell type. Default0.75.- pos_only
Only keep genes that are higher in the cell type than in the rest of the cells (positive markers). If
FALSE, all genes passingmin_pctare considered, ranked by score.- level
The hierarchy level to write into the output data frame.
- format
The format of the output data frame. One of
"universal"(default) or"db"(the hitype/ScType wide format).
Value
A data frame in the universal marker format (default) with
columns cell_type, gene, direction and level, or in the hitype
db format (format = "db") with columns cellName,
geneSymbolmore1, geneSymbolmore2 and level. Both are directly
consumable by gs_prepare().
Examples
set.seed(1)
ngenes <- 40
ncells <- 60
exprs <- matrix(runif(ngenes * ncells, 0, 0.2), ngenes, ncells)
rownames(exprs) <- paste0("gene", seq_len(ngenes))
colnames(exprs) <- paste0("cell", seq_len(ncells))
clusters <- setNames(
rep(c("Tcell", "Bcell", "Monocyte"), each = 20),
colnames(exprs)
)
markers <- find_markers(exprs, clusters, method = "fc", top = 5)
#> Warning: Dropped 16 positive-marker candidate(s) expressed in more than 75% of other cells (max_pct_out): Tcell: 9, Bcell: 4, Monocyte: 3
head(markers)
#> NULL