編者按:本文介紹了新版Seurat在數(shù)據(jù)可視化方面的新功能射沟。主要是進(jìn)一步加強(qiáng)與ggplot2語(yǔ)法的兼容性,支持交互操作拓售。
seurat visualization
我們將使用之前在2700 PBMC教程中計(jì)算的Seurat對(duì)象演示Seurat中的可視化技術(shù)。你可以在這里下載here
ibrary(Seurat)
library(ggplot2)
pbmc <- readRDS(file = "D:\\Users\\Administrator\\Desktop\\Novo周運(yùn)來(lái)\\SingleCell\\scrna_tools/pbmc3k_final.rds")
pbmc$groups <- sample(c("group1", "group2"), size = ncol(pbmc), replace = TRUE)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
pbmc
An object of class Seurat
13714 features across 2638 samples within 1 assay
Active assay: RNA (13714 features)
3 dimensional reductions calculated: pca, umap, tsne
five-visualizations-of-marker-feature-expression
# Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster
RidgePlot(pbmc, features = features, ncol = 2)
# Violin plot - Visualize single cell expression distributions in each cluster
VlnPlot(pbmc, features = features)
# Feature plot - visualize feature expression in low-dimensional space
FeaturePlot(pbmc, features = features)
# Dot plots - the size of the dot corresponds to the percentage of cells expressing the feature
# in each cluster. The color represents the average expression level
DotPlot(pbmc, features = features) + RotatedAxis()
# Single cell heatmap of feature expression
DoHeatmap(subset(pbmc, downsample = 100), features = features, size = 3)
new-additions-to-featureplot
# Plot a legend to map colors to expression levels
FeaturePlot(pbmc, features = "MS4A1")
# Adjust the contrast in the plot
FeaturePlot(pbmc, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)
# Calculate feature-specific contrast levels based on quantiles of non-zero expression.
# Particularly useful when plotting multiple markers
FeaturePlot(pbmc, features = c("MS4A1", "PTPRCAP"), min.cutoff = "q10", max.cutoff = "q90")
# Visualize co-expression of two features simultaneously
FeaturePlot(pbmc, features = c("MS4A1", "CD79A"), blend = TRUE)
# Split visualization to view expression by groups (replaces FeatureHeatmap)
FeaturePlot(pbmc, features = c("MS4A1", "CD79A"), split.by = "groups")
updated-and-expanded-visualization-functions
除了對(duì)FeaturePlot進(jìn)行更改外,還更新和擴(kuò)展了其他幾個(gè)繪圖函數(shù)华临,添加了一些新特性,并取代了現(xiàn)在不推薦的函數(shù).
# Violin plots can also be split on some variable. Simply add the splitting variable to object
# metadata and pass it to the split.by argument
VlnPlot(pbmc, features = "percent.mt", split.by = "groups")
# SplitDotPlotGG has been replaced with the `split.by` parameter for DotPlot
DotPlot(pbmc, features = features, split.by = "groups") + RotatedAxis()
# DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either 'umap', 'tsne', or
# 'pca' by default, in that order
DimPlot(pbmc)
pbmc.no.umap <- pbmc
pbmc.no.umap[["umap"]] <- NULL
DimPlot(pbmc.no.umap) + RotatedAxis()
# DoHeatmap now shows a grouping bar, splitting the heatmap into groups or clusters. This can be
# changed with the `group.by` parameter
DoHeatmap(pbmc, features = VariableFeatures(pbmc)[1:100], cells = 1:500, size = 4, angle = 90) +
NoLegend()
applying-themes-to-plots
在Seurat v3.0中端考,所有繪圖函數(shù)默認(rèn)情況下都返回基于ggplot2的繪圖對(duì)象雅潭,允許我們像其他基于ggplot2的繪圖對(duì)象一樣輕松地再次操作繪圖揭厚。
baseplot <- DimPlot(pbmc, reduction = "umap")
# Add custom labels and titles
baseplot + labs(title = "Clustering of 2,700 PBMCs")
# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin with
# devtools::install_github('sjessa/ggmin')
baseplot + ggmin::theme_powerpoint()
# Seurat also provides several built-in themes, such as DarkTheme; for more details see
# ?SeuratTheme
baseplot + DarkTheme()
# Chain themes together
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()
interactive-plotting-features
Seurat利用R的plot繪圖庫(kù)來(lái)創(chuàng)建交互式繪圖。這個(gè)交互式繪圖功能適用于任何基于ggplot2的散點(diǎn)圖(需要一個(gè)geom_point層)扶供。要使用它筛圆,只需制作一個(gè)基于ggplot2的散點(diǎn)圖(例如DimPlot或FeaturePlot),并將生成的圖傳遞給HoverLocator.
# Include additional data to display alongside cell names by passing in a data frame of
# information Works well when using FetchData
plot <- FeaturePlot(pbmc, features = "MS4A1")
HoverLocator(plot = plot, information = FetchData(pbmc, vars = c("ident", "PC_1", "nFeature_RNA")))
Warning messages:
1: In if (is.na(col)) { :
the condition has length > 1 and only the first element will be used
2: In if (is.na(col)) { :
the condition has length > 1 and only the first element will be used
3: `error_y.color` does not currently support multiple values.
4: `error_x.color` does not currently support multiple values.
5: `line.color` does not currently support multiple values.
6: The titlefont attribute is deprecated. Use title = list(font = ...) instead.
更多細(xì)節(jié)等你探索椿浓,交互式Seurat!
Seurat提供的另一個(gè)交互特性是能夠手動(dòng)選擇細(xì)胞以進(jìn)行進(jìn)一步的研究太援。我們發(fā)現(xiàn),對(duì)于那些并不總是使用無(wú)偏聚類進(jìn)行分離的小集群來(lái)說(shuō)扳碍,這一點(diǎn)特別有用提岔,但是它們看起來(lái)非常不同。現(xiàn)在笋敞,您可以通過(guò)創(chuàng)建一個(gè)基于ggplot2的散點(diǎn)圖(例如使用DimPlot或FeaturePlot碱蒙,并將返回的圖傳遞給CellSelector)來(lái)選擇這些細(xì)胞。CellSelector將返回一個(gè)向量夯巷,其中包含所選點(diǎn)的名稱赛惩,這樣您就可以將它們?cè)O(shè)置為一個(gè)新的標(biāo)識(shí)類進(jìn)行 differential expression。
例如趁餐,讓我們假設(shè)樹突狀細(xì)胞(DCs)已經(jīng)在集群中與單核細(xì)胞(monocytes)合并喷兼,但是我們想根據(jù)它們?cè)趖SNE圖中的位置了解它們的獨(dú)特之處。
pbmc <- RenameIdents(pbmc, DC = "CD14+ Mono")
plot <- DimPlot(pbmc, reduction = "umap")
select.cells <- CellSelector(plot = plot)
給出一行小提示:
Click around the cluster of points you wish to select
ie. select the vertecies of a shape around the cluster you
are interested in. Press <Esc> when finished (right click for R-terminal users)
然后我們可以使用SetIdent將這些細(xì)胞轉(zhuǎn)變成它們自己的小簇后雷。
> head(select.cells)
[1] "AAGCCATGAACTGC" "ACGTCGCTCCTGAA" "ACTTAAGATTACTC"
[4] "ACTTCAACAAGCAA" "AGCACTGATGCTTT" "CACCGGGACTTCTA"
Idents(pbmc, cells = select.cells) <- "NewCells"
# Now, we find markers that are specific to the new cells, and find clear DC markers
newcells.markers <- FindMarkers(pbmc, ident.1 = "NewCells", ident.2 = "CD14+ Mono", min.diff.pct = 0.3,
only.pos = TRUE)
head(newcells.markers)
p_val avg_logFC pct.1 pct.2 p_val_adj
HLA-DQA2 6.579989e-24 1.635741 0.619 0.045 9.023796e-20
SPECC1 1.928970e-21 0.547701 0.333 0.009 2.645390e-17
FCER1A 3.069126e-21 2.062739 0.524 0.036 4.208999e-17
HLA-DQB1 1.476429e-20 1.823891 0.905 0.142 2.024774e-16
HLA-DRB5 3.013802e-20 1.994758 0.810 0.112 4.133129e-16
HLA-DMA 6.237886e-20 1.363932 0.762 0.092 8.554637e-16
除了返回一個(gè)向量的細(xì)胞名稱,CellSelector也可以選擇的細(xì)胞和分配一個(gè)新的身份,返回一個(gè)修對(duì)象與身份已經(jīng)設(shè)置類褒搔。這樣做是通過(guò)修對(duì)象用來(lái)制造陰謀CellSelector,以及身份類。例如喷面,我們將選擇與之前相同的單元格集合星瘾,并將它們的標(biāo)識(shí)類設(shè)置為" selected "
pbmc <- CellSelector(plot = plot, object = pbmc, ident = "selected")
levels(pbmc)
[1] "selected" "NewCells" "CD14+ Mono" "Naive CD4 T"
[5] "Memory CD4 T" "B" "CD8 T" "FCGR3A+ Mono"
[9] "NK" "Platelet"
plotting-accessories
除了向繪圖添加交互功能之外,Seurat還提供了用于操作和組合繪圖的新輔助功能惧辈。
# LabelClusters and LabelPoints will label clusters (a coloring variable) or individual points
# on a ggplot2-based scatter plot
plot <- DimPlot(pbmc, reduction = "pca") + NoLegend()
LabelClusters(plot = plot, id = "ident")
# Both functions support `repel`, which will intelligently stagger labels and draw connecting
# lines from the labels to the points or clusters
LabelPoints(plot = plot, points = TopCells(object = pbmc[["pca"]]), repel = TRUE)
# Plotting multiple plots at once is easy with CombinePlots
plot1 <- DimPlot(pbmc)
plot2 <- FeatureScatter(pbmc, feature1 = "LYZ", feature2 = "CCL5")
# CombinePlots takes a list of ggplot2-based plots
CombinePlots(plots = list(plot1, plot2))
# CombinePlots can also easily remove the legend from the plots by passing `legend = 'none'`;
# legends can also be combined with `legend = 'right'`
CombinePlots(plots = list(plot1, plot2), legend = "none")
# CombinePlots used cowplot:plot_grid under the hood, and will pass on additional arguments to
# cowplot::plot_grid