Skip to contents

Extends FastDotPlot() with an optional enrichment annotation panel aligned above the dot plot columns. When RunEnrichR = TRUE, the top TopN_Enrich significant terms from the specified EnrichR database are displayed as a text header above each gene-cluster panel.

Usage

FastDotPlot2(
  seurat_object,
  assay = "RNA",
  features = NULL,
  pattern = NULL,
  group.by = "seurat_clusters",
  split.by = NULL,
  ClusterGroups = FALSE,
  ClusterGenes = TRUE,
  k_genes = 1,
  min.pct.exp = 15,
  col.min = 0,
  col.max = 2.5,
  scale.min = 5,
  scale.max = 100,
  dot.scale = 6,
  RunEnrichR = TRUE,
  EnrichR_DB = "CellMarker_2024",
  TopN_Enrich = 3,
  output_dir = NULL,
  file_name = NULL
)

Arguments

seurat_object

A Seurat object.

assay

Character. Assay to use. Default "RNA".

features

Character vector of gene names, or NULL if using pattern.

pattern

Character regex. All matching genes in rownames(seurat_object) are used. Ignored if features is provided.

group.by

Character. Metadata column for y-axis. Default "GlobalAssignment".

split.by

Character or NULL. Metadata column for row facets.

ClusterGroups

Logical. Cluster y-axis groups? Default FALSE.

ClusterGenes

Logical. Cluster genes on x-axis? Default TRUE.

k_genes

Integer. Number of gene clusters (panels) to cut the dendrogram into. 1 = no cutting (single panel). Default 1.

min.pct.exp

Numeric. Minimum percent expression threshold. Default 15.

col.min, col.max

Numeric. Color clamp limits. Defaults 0, 2.5.

scale.min, scale.max

Numeric. Size clamp limits. Defaults 5, 100.

dot.scale

Numeric. Max dot radius. Default 6.

RunEnrichR

Logical. Run EnrichR enrichment? Default TRUE.

EnrichR_DB

Character. EnrichR database name. Default "CellMarker_2024".

TopN_Enrich

Integer. Number of top terms to show per pattern. Default 3.

output_dir

Character or NULL. Directory to save a PDF. NULL (default) returns the plot without saving. When NULL, the function walks up to the output_dir stored by PrepObject, unless AutoSavePlots = FALSE was set there.

file_name

Character or NULL. Base name (no extension) for the saved PDF. NULL (default) auto-generates a name that includes the gene pattern (when used) followed by group.by and split.by, e.g. <pattern>_<group.by>_<split.by>_FastDotPlot, so different groupings and splits never overwrite each other.

Value

A named list:

plot

The combined (enrichment + dot plot) or standalone dot plot.

dotplot

The standalone dot plot ggplot2 object.

enrich_plot

The enrichment header ggplot2 object, or NULL.

patterns

Named list mapping each pattern label to its gene vector.

filtered_genes

Data frame with columns features.plot and Gene_Cluster for every gene that passed min.pct.exp.

enrich_table

Raw EnrichR results data frame, or NULL.

Details

Bug fixes vs. original script:

  • Gene-cluster strip labels are shown even when enrichment is disabled or fails (they were previously always hidden).

  • The filtered gene list and per-pattern gene assignments are always returned in the output list regardless of enrichment status.