Updated: 2024/03/25 15:51
Seurat.utils Is a collection of utility functions for Seurat single cell analysis.
Functions allow 3D plotting, visualisation of statistics & QC,
the automation / multiplexing of plotting, interaction with the Seurat object, etc.
Some functionalities require functions from CodeAndRoll and MarkdownReports libraries.> For details, please use the help()
function, or browse the source code.
PlotFilters()
Plot filtering threshold and distributions, using four panels to highlight the relation between Gene- and UMI-count, ribosomal- and mitochondrial-content.
PlotFilters(ls.Seurat)
scCalcPCAVarExplained()
This function calculates the percentage of variation each principal component (PC)
data("combined.obj") # Example Seurat object var_explained <- scCalcPCAVarExplained(combined.obj) print(var_explained)
scPlotPCAvarExplained()
This function plots the percentage of variation explained by each principal
data("combined.obj") # Example Seurat object scPlotPCAvarExplained(combined.obj, use.MarkdownReports = TRUE)
PercentInTranscriptome()
This function computes and visualizes gene expression levels as a fraction of total
combined.obj <- PercentInTranscriptome(combined.obj)
geneExpressionLevelPlots()
This function generates a histogram to visualize the expression level distribution
No examples found.
PrctCellExpringGene()
Calculates the proportion of cells expressing one or more specified genes.
PrctCellExpringGene(genes = c("Gene1", "Gene2"), obj = seurat_object)
ww.calc_helper()
Computes the proportion of cells expressing a specific gene within a Seurat object.
ww.calc_helper(obj = seurat_object, genes = "Gene1")
get.clustercomposition()
Analyzes and visualizes the composition of clusters in a Seurat object, indicating
get.clustercomposition()
scBarplot.CellFractions()
This function generates a bar plot of cell fractions per cluster from a Seurat object.
scBarplot.CellFractions(obj = combined.obj, group.by = "integrated_snn_res.0.1", fill.by = "Phase", downsample = TRUE) scBarplot.CellFractions(obj = combined.obj, group.by = "integrated_snn_res.0.1", fill.by = "Phase", downsample = FALSE)
scBarplot.CellsPerCluster()
Visualizes the fraction of cells within each cluster through a barplot.
scBarplot.CellsPerCluster() scBarplot.CellsPerCluster(sort = TRUE)
scBarplot.CellsPerObject()
Visualizes the number of cells in each Seurat object within a list, showing the
No examples found.
plotClustSizeDistr()
Generates a bar plot or histogram to visualize the size distribution of clusters
plotClustSizeDistr()
scBarplot.FractionAboveThr()
Generates a bar plot depicting the percentage of cells within each cluster that
scBarplot.FractionAboveThr(id.col = "cl.names.top.gene.res.0.3", value.col = "percent.ribo", thrX = 0.3)
scBarplot.FractionBelowThr()
Generates a bar plot to visualize the percentage of cells within each cluster that
scBarplot.FractionBelowThr(id.col = "cl.names.top.gene.res.0.3", value.col = "percent.ribo", thrX = 0.01)
scBarplotStackedMetaCateg_List()
Creates and saves a stacked barplot for a specified metadata category
No examples found.
gg_color_hue()
Generates a vector of colors that emulates the default color palette used by ggplot2.
# Generate a palette of 5 colors print(gg_color_hue(5))
getDiscretePalette()
Safe wrapper around Seurat's DiscretePalette(), which returns NA's if too many
getDiscretePalette()
getDiscretePaletteObj()
Generates a discrete color palette for visualizing clusters in a Seurat object,
ident.used <- "resolution_1" obj <- YourSeuratObject colors <- getDiscretePaletteObj(ident.used = ident.used, obj = obj) print(colors)
DiscretePaletteSafe()
Generates a discrete color palette, ensuring no NA values are included, suitable
colors <- DiscretePaletteSafe(n = 10) print(colors)
getClusterColors()
Regenerate and optionally displays the color scheme associated with the clusters
getClusterColors(obj = combined.obj, ident = GetClusteringRuns(combined.obj)[1])
SeuratColorVector()
Extracts and optionally displays the color scheme assigned to cluster identities
# Display colors for the active identity SeuratColorVector() # Retrieve and plot colors for a specified clustering identity SeuratColorVector(ident = "RNA_snn_res.1", plot.colors = TRUE)
plotAndSaveHeatmaps()
Generates and saves heatmap visualizations for each metric in the results obtained
# Assuming `results` is the output from `calculateAverageMetaData`: plotAndSaveHeatmaps(results, path = "path/to/save/heatmaps", file.prefix = "myData_")
qFeatureScatter()
Generates a scatter plot comparing two features (genes or metrics) from a Seurat
# Generate and display a scatter plot for features TOP2A and ID2 qFeatureScatter(feature1 = "TOP2A", feature2 = "ID2", obj = yourSeuratObject)
qSeuViolin()
Generates a violin plot for a specified feature in a Seurat object,
# Assuming `seurat_obj` is a valid Seurat object qSeuViolin(object = seurat_obj, features = "nFeature_RNA")
plotGeneExpHist()
Creates and optionally saves a histogram showing expression levels of specified genes
plotGeneExpHist(obj = yourSeuratObject, genes = c("GeneA", "GeneB"))
qUMAP()
Generates a UMAP visualization for a specific feature from a Seurat object, and
qUMAP(feature = "nFeature_RNA", obj = yourSeuratObject) qUMAP(feature = "TOP2A", obj = yourSeuratObject, PNG = FALSE, save.plot = TRUE)
clUMAP()
Generates a UMAP visualization based on clustering results from a Seurat object,
clUMAP(ident = "integrated_snn_res.0.5", obj = yourSeuratObj) clUMAP(ident = "integrated_snn_res.0.5", obj = yourSeuratObj, cols = RColorBrewer::brewer.pal(8, "Dark2"))
umapHiLightSel()
Generates a UMAP plot from a Seurat object with specified clusters highlighted.
umapHiLightSel(obj = combined.obj, COI = c("0", "1"), res.cl = "resolution_0.8")
DimPlot.ClusterNames()
Plot UMAP with Cluster names.
DimPlot.ClusterNames()
multiFeaturePlot.A4()
Save multiple FeaturePlots, as jpeg, on A4 for each gene, which are stored as a list of gene names.
No examples found.
multiSingleClusterHighlightPlots.A4()
This function generates and saves cluster highlight plots for both single and multiple
multiSingleClusterHighlightPlots.A4(ident = "cluster_id", obj = yourSeuratObject)
multiSeuratHeatmap.A4()
Save multiple FeatureHeatmaps from a list of genes on A4 jpeg.
No examples found.
multi_clUMAP.A4()
Generates and saves multiple UMAP plots for clustering results, adjusting the
multi_clUMAP.A4(idents = c("S1", "S2"), obj = YourSeuratObject)
qClusteringUMAPS()
Generates and arranges UMAP plots for up to four specified clustering resolutions
qClusteringUMAPS()
plotQUMAPsInAFolder()
This function plots qUMAPs for a specified set of genes, storing the results in a
plotQUMAPsInAFolder( genes = c("Gene1", "Gene2"), obj = combined.obj, foldername = "MyGenePlots", intersectionAssay = "RNA", plot.reduction = "umap" )
PlotTopGenesPerCluster()
Visualizes the top N differentially expressed (DE) genes for each cluster within a
PlotTopGenesPerCluster(obj = combined.obj, cl_res = 0.5, nrGenes = 10)
qQC.plots.BrainOrg()
Generates and arranges UMAP plots for specified QC features
qQC.plots.BrainOrg()
qMarkerCheck.BrainOrg()
Generates plots for a predefined or custom set of gene markers within brain organoids,
qMarkerCheck.BrainOrg(combined.obj) qMarkerCheck.BrainOrg(combined.obj, custom.genes = c("Gene1", "Gene2"))
PlotTopGenes()
This function plots the highest expressed genes on UMAPs, saving the plots in a
PlotTopGenes()
FlipReductionCoordinates()
Flips dimensionality reduction coordinates (such as UMAP or tSNE) vertically or
# Before flipping UMAP coordinates clUMAP() # Flip UMAP coordinates and visualize again combined.obj <- FlipReductionCoordinates(combined.obj) clUMAP()
AutoNumber.by.UMAP()
Automatically renumbers clusters based on their position along a specified dimension
combined.obj <- AutoNumber.by.UMAP( obj = combined.obj, dim = 1, reduction = "umap", res = "integrated_snn_res.0.5" ) DimPlot.ClusterNames(combined.obj, ident = "integrated_snn_res.0.5.ordered")
.adjustLayout()
Adjusts layout dimensions and properties based on the specified layout type.
env <- new.env() .adjustLayout("tall", 1, 8.27, 11.69, env) print(env$w) # Should print the width based on "tall" layout scaling.
save2plots.A4()
Arranges and saves two UMAP plots (or any plots) side-by-side or one above
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() p2 <- ggplot(iris, aes(Petal.Length, Petal.Width, color = Species)) + geom_point() save2plots.A4(plot_list = list(p1, p2))
save4plots.A4()
Arranges and saves four plots (e.g. UMAPs) onto a single A4 page, allowing for a
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() p2 <- ggplot(mtcars, aes(mpg, disp, color = as.factor(cyl))) + geom_point() p3 <- ggplot(mpg, aes(displ, hwy, color = class)) + geom_point() p4 <- ggplot(diamonds, aes(carat, price, color = cut)) + geom_point() save4plots.A4(plot_list = list(p1, p2, p3, p4))
qqSaveGridA4()
Saves a grid of 2 or 4 ggplot objects onto an A4 page.
qqSaveGridA4(plotlist = pl, plots = 1:2, fname = "Fractions.per.Cl.png") qqSaveGridA4(plotlist = pl, plots = 1:4, fname = "Fractions.per.Cl.4.png")
ww.check.if.3D.reduction.exist()
ww.check.if.3D.reduction.exist in backup slot #
No examples found.
ww.check.quantile.cutoff.and.clip.outliers()
Checks a specified quantile cutoff and clips outliers from an expression vector,
expr.vec <- c(...) quantileCutoff <- 0.99 min.cells.expressing <- 10 ww.check.quantile.cutoff.and.clip.outliers(expr.vec, quantileCutoff, min.cells.expressing)
plot3D.umap.gene()
Plot a 3D umap with gene expression. Uses plotly. Based on github.com/Dragonmasterx87.
plot3D.umap.gene(obj = combined.obj, gene = "DDIT4", quantileCutoff = .95) plot3D.umap.gene(obj = combined.obj, gene = "percent.mito", quantileCutoff = .95) # for continous meta variables plot3D.umap.gene(obj = combined.obj, gene = "nFeature_RNA", quantileCutoff = .95) # for continous meta variables
plot3D.umap()
Plot a 3D umap based on one of the metadata columns. Uses plotly. Based on github.com/Dragonmasterx87.
plot3D.umap(combined.obj, category = "Phase")
SavePlotlyAsHtml()
Save a Plotly 3D scatterplot as an HTML file.
No examples found.
BackupReduction()
Stores a backup of specified dimensionality reduction data (e.g., UMAP, tSNE, PCA)
obj <- BackupReduction(obj = obj, dim = 2, reduction = "umap")
SetupReductionsNtoKdimensions()
Executes specified dimensionality reduction (UMAP, tSNE, or PCA) over a range of dimensions
combined.obj <- SetupReductionsNtoKdimensions( obj = combined.obj, nPCs = 10, dimensions = 2:3, reduction = "umap" )
RecallReduction()
Restores dimensionality reduction data (e.g., UMAP, tSNE, PCA) from a backup
combined.obj <- RecallReduction(obj = combined.obj, dim = 2, reduction = "umap") qUMAP() combined.obj <- RecallReduction(obj = combined.obj, dim = 3, reduction = "umap") qUMAP()
Annotate4Plotly3D()
Create annotation labels for 3D plots. Source https://plot.ly/r/text-and-annotations/#3d-annotations.
No examples found.
Plot3D.ListOfGenes()
Plot and save list of 3D UMAP or tSNE plots using plotly.
CellTypeMarkers <- c("PGK1", "CTIP2" = "BCL11B", "FEZF2", "EOMES", "DLX6-AS1", "HOPX", "DDIT4", "TOP2A", "PTGDS", "EDNRB", "EGFR", "SCGN", "NR2F2", "EMX2", "GAD2", "DLX2", "SATB2") Plot3D.ListOfGenes(obj = combined.obj, ListOfGenes = CellTypeMarkers)
Plot3D.ListOfCategories()
This function plots and saves a list of 3D UMAP or tSNE plots using plotly.
categ3Dplots <- c("v.project", "experiment", "Phase", "integrated_snn_res.0.7", "Area", "Individual", "Type") Plot3D.ListOfCategories(obj = combined.obj, ListOfCategories = categ3Dplots)
panelCorPearson()
This function displays the correlation coefficient and significance level within
pairs(mtcars[, 1:4], panel = panelCorPearson)
suPlotVariableFeatures()
Generates a Variable Feature Plot for a specified Seurat object, labels points with
suPlotVariableFeatures(combined.obj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.