do_SCEnrichmentHeatmap: Perform a single-cell-based heatmap showing the enrichment in...

View source: R/do_SCEnrichmentHeatmap.R

do_SCEnrichmentHeatmapR Documentation

Perform a single-cell-based heatmap showing the enrichment in a list of gene sets.

Description

This function is heavily inspired by DoHeatmap.

Usage

do_SCEnrichmentHeatmap(
  sample,
  input_gene_list,
  assay = NULL,
  slot = NULL,
  group.by = NULL,
  features.order = NULL,
  metadata = NULL,
  metadata.colors = NULL,
  subsample = NA,
  cluster = TRUE,
  flavor = "Seurat",
  return_object = FALSE,
  ncores = 1,
  storeRanks = TRUE,
  interpolate = FALSE,
  nbin = 24,
  ctrl = 100,
  xlab = "Cells",
  ylab = "Genes",
  font.size = 14,
  font.type = "sans",
  plot.title = NULL,
  plot.subtitle = NULL,
  plot.caption = NULL,
  legend.position = "bottom",
  legend.title = NULL,
  legend.type = "colorbar",
  legend.framewidth = 0.5,
  legend.tickwidth = 0.5,
  legend.length = 20,
  legend.width = 1,
  legend.framecolor = "grey50",
  legend.tickcolor = "white",
  strip.text.color = "black",
  strip.text.angle = 0,
  strip.spacing = 10,
  legend.ncol = NULL,
  legend.nrow = NULL,
  legend.byrow = FALSE,
  min.cutoff = NA,
  max.cutoff = NA,
  number.breaks = 5,
  main.heatmap.size = 0.95,
  enforce_symmetry = FALSE,
  use_viridis = FALSE,
  viridis.palette = "G",
  viridis.direction = -1,
  na.value = "grey75",
  diverging.palette = "RdBu",
  diverging.direction = -1,
  sequential.palette = "YlGnBu",
  sequential.direction = 1,
  proportional.size = TRUE,
  verbose = FALSE,
  border.color = "black",
  plot.title.face = "bold",
  plot.subtitle.face = "plain",
  plot.caption.face = "italic",
  axis.title.face = "bold",
  axis.text.face = "plain",
  legend.title.face = "bold",
  legend.text.face = "plain"
)

Arguments

sample

Seurat | A Seurat object, generated by CreateSeuratObject.

input_gene_list

named_list | Named list of lists of genes to be used as input.

assay

character | Assay to use. Defaults to the current assay.

slot

character | Data slot to use. Only one of: counts, data, scale.data. Defaults to "data".

group.by

character | Metadata variable to group the output by. Has to be a character of factor column.

features.order

character | Should the gene sets be ordered in a specific way? Provide it as a vector of characters with the same names as the names of the gene sets.

metadata

character | Categorical metadata variables to plot alongside the main heatmap.

metadata.colors

named_list | Named list of valid colors for each of the variables defined in metadata.

subsample

numeric | Number of cells to subset for the analysis. NA will use all. Cells are selected at random.

cluster

logical | Whether to perform clustering of rows and columns.

flavor

character | One of: Seurat, UCell. Compute the enrichment scores using AddModuleScore or AddModuleScore_UCell.

return_object

logical | Returns the Seurat object with the modifications performed in the function. Nomally, this contains a new assay with the data that can then be used for any other visualization desired.

ncores

numeric | Number of cores used to run UCell scoring.

storeRanks

logical | Whether to store the ranks for faster UCell scoring computations. Might require large amounts of RAM.

interpolate

logical | Smoothes the output heatmap, saving space on disk when saving the image. However, the image is not as crisp.

nbin

numeric | Number of bins to use in AddModuleScore.

ctrl

numeric | Number of genes in the control set to use in AddModuleScore.

xlab, ylab

character | Titles for the X and Y axis.

font.size

numeric | Overall font size of the plot. All plot elements will have a size relationship with this font size.

font.type

character | Base font family for the plot. One of:

  • mono: Mono spaced font.

  • serif: Serif font family.

  • sans: Default font family.

plot.title, plot.subtitle, plot.caption

character | Title, subtitle or caption to use in the plot.

legend.position

character | Position of the legend in the plot. One of:

  • top: Top of the figure.

  • bottom: Bottom of the figure.

  • left: Left of the figure.

  • right: Right of the figure.

  • none: No legend is displayed.

legend.title

character | Title for the legend.

legend.type

character | Type of legend to display. One of:

  • normal: Default legend displayed by ggplot2.

  • colorbar: Redefined colorbar legend, using guide_colorbar.

legend.framewidth, legend.tickwidth

numeric | Width of the lines of the box in the legend.

legend.length, legend.width

numeric | Length and width of the legend. Will adjust automatically depending on legend side.

legend.framecolor

character | Color of the lines of the box in the legend.

legend.tickcolor

character | Color of the ticks of the box in the legend.

strip.text.color

character | Color of the strip text.

strip.text.angle

numeric | Rotation of the strip text (angles).

strip.spacing

numeric | Controls the size between the different facets.

legend.ncol

numeric | Number of columns in the legend.

legend.nrow

numeric | Number of rows in the legend.

legend.byrow

logical | Whether the legend is filled by row or not.

min.cutoff, max.cutoff

numeric | Set the min/max ends of the color scale. Any cell/group with a value lower than min.cutoff will turn into min.cutoff and any cell with a value higher than max.cutoff will turn into max.cutoff. In FeaturePlots, provide as many values as features. Use NAs to skip a feature.

number.breaks

numeric | Controls the number of breaks in continuous color scales of ggplot2-based plots.

main.heatmap.size

numeric | Controls the size of the main heatmap (proportion-wise, defaults to 0.95).

enforce_symmetry

logical | Return a symmetrical plot axes-wise or continuous color scale-wise, when applicable.

use_viridis

logical | Whether to use viridis color scales.

viridis.palette

character | A capital letter from A to H or the scale name as in scale_fill_viridis.

viridis.direction

numeric | Either 1 or -1. Controls how the gradient of viridis scale is formed.

na.value

character | Color value for NA.

diverging.palette

character | Type of symmetrical color palette to use. Out of the diverging palettes defined in brewer.pal.

diverging.direction

numeric | Either 1 or -1. Direction of the divering palette. This basically flips the two ends.

sequential.palette

character | Type of sequential color palette to use. Out of the sequential palettes defined in brewer.pal.

sequential.direction

numeric | Direction of the sequential color scale. Either 1 or -1.

proportional.size

logical | Whether the groups should take the same space in the plot or not.

verbose

logical | Whether to show extra comments, warnings,etc.

border.color

character | Color for the border of the heatmap body.

plot.title.face, plot.subtitle.face, plot.caption.face, axis.title.face, axis.text.face, legend.title.face, legend.text.face

character | Controls the style of the font for the corresponding theme element. One of:

  • plain: For normal text.

  • italic: For text in itallic.

  • bold: For text in bold.

  • bold.italic: For text both in itallic and bold.

Value

A ggplot2 object.

Examples


  # Check Suggests.
  value <- SCpubr:::check_suggests(function_name = "do_SCEnrichmentHeatmap", passive = TRUE)
  
  if (isTRUE(value)){
    # Consult the full documentation in https://enblacar.github.io/SCpubr-book/
    
    # Define your Seurat object.
    sample <- readRDS(system.file("extdata/seurat_dataset_example.rds", package = "SCpubr"))
    
    # Genes have to be unique.
    genes <- list("A" = rownames(sample)[1:5],
                  "B" = rownames(sample)[6:10],
                  "C" = rownames(sample)[11:15])
    
    p <- SCpubr::do_SCEnrichmentHeatmap(sample = sample,
                                        input_gene_list = genes,
                                        nbin = 1,
                                        ctrl = 5,
                                        flavor = "Seurat",
                                        subsample = NA)
    p
    
  } else if (base::isFALSE(value)){
    message("This function can not be used without its suggested packages.")
    message("Check out which ones are needed using `SCpubr::state_dependencies()`.")
  }


enblacar/SCpubr documentation built on Aug. 25, 2024, 9:45 p.m.