do_RankedEnrichmentPlot: Compute a heatmap of enrichment of gene sets on the context...

View source: R/do_RankedEnrichmentPlot.R

do_RankedEnrichmentPlotR Documentation

Compute a heatmap of enrichment of gene sets on the context of a diffusion component.

Description

Compute a heatmap of enrichment of gene sets on the context of a diffusion component.

Usage

do_RankedEnrichmentPlot(
  sample,
  input_gene_list,
  assay = NULL,
  slot = NULL,
  scale.enrichment = TRUE,
  dims = 1:2,
  subsample = 2500,
  reduction = NULL,
  group.by = NULL,
  colors.use = NULL,
  raster = FALSE,
  interpolate = FALSE,
  nbin = 24,
  ctrl = 100,
  flavor = "Seurat",
  main.heatmap.size = 0.95,
  enforce_symmetry = ifelse(isTRUE(scale.enrichment), TRUE, FALSE),
  use_viridis = FALSE,
  viridis.palette = "G",
  viridis.direction = -1,
  sequential.palette = "YlGnBu",
  sequential.direction = 1,
  font.size = 14,
  font.type = "sans",
  na.value = "grey75",
  legend.width = 1,
  legend.length = 20,
  legend.framewidth = 0.5,
  legend.tickwidth = 0.5,
  legend.framecolor = "grey50",
  legend.tickcolor = "white",
  legend.type = "colorbar",
  legend.position = "bottom",
  legend.nrow = NULL,
  legend.ncol = NULL,
  legend.byrow = FALSE,
  number.breaks = 5,
  diverging.palette = "RdBu",
  diverging.direction = -1,
  axis.text.x.angle = 45,
  border.color = "black",
  return_object = FALSE,
  verbose = FALSE,
  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".

scale.enrichment

logical | Should the enrichment scores be scaled (z-scored) for better comparison in between gene sets? Setting this to TRUE should make intra- gene set comparisons easier at the cost ot not being able to compare inter- gene sets in absolute values.

dims

numeric | Vector of 2 numerics indicating the dimensions to plot out of the selected reduction. Defaults to c(1, 2) if not specified.

subsample

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

reduction

character | Reduction to use. Can be the canonical ones such as "umap", "pca", or any custom ones, such as "diffusion". If you are unsure about which reductions you have, use Seurat::Reductions(sample). Defaults to "umap" if present or to the last computed reduction if the argument is not provided.

group.by

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

colors.use

list | A named list of named vectors. The names of the list correspond to the names of the values provided to metadata and the names of the items in the named vectors correspond to the unique values of that specific metadata variable. The values are the desired colors in HEX code for the values to plot. The used are pre-defined by the package but, in order to get the most out of the plot, please provide your custom set of colors for each metadata column!

raster

logical | Whether to raster the resulting plot. This is recommendable if plotting a lot of cells.

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.

flavor

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

main.heatmap.size

numeric | A number from 0 to 1 corresponding to how big the main heatmap plot should be with regards to the rest (corresponds to the proportion in size).

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.

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.

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.

na.value

character | Color value for NA.

legend.length, legend.width

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

legend.framewidth, legend.tickwidth

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

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.

legend.type

character | Type of legend to display. One of:

  • normal: Default legend displayed by ggplot2.

  • colorbar: Redefined colorbar legend, using guide_colorbar.

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.nrow

numeric | Number of rows in the legend.

legend.ncol

numeric | Number of columns in the legend.

legend.byrow

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

number.breaks

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

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.

axis.text.x.angle

numeric | Degree to rotate the X labels. One of: 0, 45, 90.

border.color

character | Color for the border of the heatmap body.

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.

verbose

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

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 list of ggplot2 objects and a Seurat object if desired.

Examples


  # Check Suggests.
  value <- SCpubr:::check_suggests(function_name = "do_RankedEnrichmentPlot", 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])
    
    
    # This will query, for the provided components, the enrichment of the gene 
    # sets for all cells and plot them in the context of the cells reordered by 
    # the position alongside each dimensional reduction component. 
    p <- SCpubr::do_RankedEnrichmentPlot(sample = sample,
                                         input_gene_list = genes,
                                         nbin = 1,
                                         ctrl = 5,
                                         flavor = "Seurat",
                                         subsample = NA,
                                         dims = 1:2,
                                         verbose = FALSE)
    
    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.