单细胞36计之9隔岸观火---Seurat中的数据可视化方法

第九计 隔岸观火
隔着河看对岸的火。比喻对别人的危难不予援救而在一旁看热闹。此计是坐观敌人的内部恶变,不急于采取攻逼手段,顺其变,“坐山观虎斗”,最后让敌人自残自杀,时机—到而我即坐收其利,一举成功。

我们将使用2700 PBMC教程中先前计算的Seurat对象,在Seurat中演示可视化技术。您可以从SeuratData下载此数据集

SeuratData::InstallData("pbmc3k")
library(Seurat)
library(SeuratData)
library(ggplot2)
library(patchwork)
data("pbmc3k.final")
pbmc3k.final$groups <- sample(c("group1", "group2"), size = ncol(pbmc3k.final), replace = TRUE)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
pbmc3k.final
## An object of class Seurat 
## 13714 features across 2638 samples within 1 assay 
## Active assay: RNA (13714 features, 2000 variable features)
##  2 dimensional reductions calculated: pca, umap

标记特征表达的五种可视化

# Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster
RidgePlot(pbmc3k.final, features = features, ncol = 2)
image
# Violin plot - Visualize single cell expression distributions in each cluster
VlnPlot(pbmc3k.final, features = features)
image
# Feature plot - visualize feature expression in low-dimensional space
FeaturePlot(pbmc3k.final, features = features)
image
# 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(pbmc3k.final, features = features) + RotatedAxis()
image
# Single cell heatmap of feature expression
DoHeatmap(subset(pbmc3k.final, downsample = 100), features = features, size = 3)
image

的新增加 FeaturePlot

# Plot a legend to map colors to expression levels
FeaturePlot(pbmc3k.final, features = "MS4A1")
image
# Adjust the contrast in the plot
FeaturePlot(pbmc3k.final, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)
image
# Calculate feature-specific contrast levels based on quantiles of non-zero expression.
# Particularly useful when plotting multiple markers
FeaturePlot(pbmc3k.final, features = c("MS4A1", "PTPRCAP"), min.cutoff = "q10", max.cutoff = "q90")
image
# Visualize co-expression of two features simultaneously
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), blend = TRUE)
image
# Split visualization to view expression by groups (replaces FeatureHeatmap)
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), split.by = "groups")
image

更新和扩展了可视化功能

除了对的更改外[FeaturePlot()](https://satijalab.org/seurat/reference/FeaturePlot.html),还更新和扩展了其他一些绘图功能,增加了新功能,并取代了现在不推荐使用的功能

# 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(pbmc3k.final, features = "percent.mt", split.by = "groups")
image
# SplitDotPlotGG has been replaced with the `split.by` parameter for DotPlot
DotPlot(pbmc3k.final, features = features, split.by = "groups") + RotatedAxis()
image
# DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either 'umap', 'tsne', or
# 'pca' by default, in that order
DimPlot(pbmc3k.final)
image
pbmc3k.final.no.umap <- pbmc3k.final
pbmc3k.final.no.umap[["umap"]] <- NULL
DimPlot(pbmc3k.final.no.umap) + RotatedAxis()
image
# DoHeatmap now shows a grouping bar, splitting the heatmap into groups or clusters. This can be
# changed with the `group.by` parameter
DoHeatmap(pbmc3k.final, features = VariableFeatures(pbmc3k.final)[1:100], cells = 1:500, size = 4, 
    angle = 90) + NoLegend()
image

将主题应用于情节

使用Seurat,所有绘图功能默认情况下都会返回基于ggplot2的绘图,从而使您可以像捕获其他基于ggplot2的绘图一样轻松地捕获和操作绘图。

baseplot <- DimPlot(pbmc3k.final, reduction = "umap")
# Add custom labels and titles
baseplot + labs(title = "Clustering of 2,700 PBMCs")
image
# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin with
# remotes::install_github('sjessa/ggmin')
baseplot + ggmin::theme_powerpoint()
image
# Seurat also provides several built-in themes, such as DarkTheme; for more details see
# ?SeuratTheme
baseplot + DarkTheme()
image
# Chain themes together
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()
image

交互式绘图功能

Seurat利用R的绘图库创建交互式绘图。此交互式绘图功能可用于任何基于ggplot2的散点图(需要一个geom_point图层)。要使用,只需制作一个基于ggplot2的散点图(例如[DimPlot()](https://satijalab.org/seurat/reference/DimPlot.html)[FeaturePlot()](https://satijalab.org/seurat/reference/FeaturePlot.html)),然后将生成的图传递到[HoverLocator()](https://satijalab.org/seurat/reference/HoverLocator.html)

# Include additional data to display alongside cell names by passing in a data frame of
# information Works well when using FetchData
plot <- FeaturePlot(pbmc3k.final, features = "MS4A1")
HoverLocator(plot = plot, information = FetchData(pbmc3k.final, vars = c("ident", "PC_1", "nFeature_RNA")))

<svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="864" height="672" style="background: white;"><g class="cartesianlayer"><g class="subplot xy"><g class="xaxislayer-above"><g class="xtick"><text text-anchor="middle" x="0" y="645.4" data-unformatted="−10" data-math="N" transform="translate(70.05,0)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">−10</text></g><g class="xtick"><text text-anchor="middle" x="0" y="645.4" data-unformatted="−5" data-math="N" transform="translate(232.01,0)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">−5</text></g><g class="xtick"><text text-anchor="middle" x="0" y="645.4" data-unformatted="0" data-math="N" transform="translate(393.97,0)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">0</text></g><g class="xtick"><text text-anchor="middle" x="0" y="645.4" data-unformatted="5" data-math="N" transform="translate(555.9300000000001,0)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">5</text></g><g class="xtick"><text text-anchor="middle" x="0" y="645.4" data-unformatted="10" data-math="N" transform="translate(717.88,0)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">10</text></g></g><g class="yaxislayer-above"><g class="ytick"><text text-anchor="end" x="56.6" y="4.199999999999999" data-unformatted="−5" data-math="N" transform="translate(0,508.52)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">−5</text></g><g class="ytick"><text text-anchor="end" x="56.6" y="4.199999999999999" data-unformatted="0" data-math="N" transform="translate(0,385.56)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">0</text></g><g class="ytick"><text text-anchor="end" x="56.6" y="4.199999999999999" data-unformatted="5" data-math="N" transform="translate(0,262.61)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">5</text></g><g class="ytick"><text text-anchor="end" x="56.6" y="4.199999999999999" data-unformatted="10" data-math="N" transform="translate(0,139.66)" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;">10</text></g></g></g></g></svg><svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="864" height="672"><g class="infolayer"><g class="g-gtitle"><text class="gtitle" x="432" y="12.5" text-anchor="middle" dy="0em" data-unformatted="MS4A1" data-math="N" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 17px; fill: rgb(0, 0, 0); opacity: 1; font-weight: normal; white-space: pre;">MS4A1</text></g><g class="g-xtitle" transform="translate(0,-13)"><text class="xtitle" x="457" y="682" text-anchor="middle" data-unformatted="UMAP_1" data-math="N" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 14px; fill: rgb(68, 68, 68); opacity: 1; font-weight: normal; white-space: pre;">UMAP_1</text></g><g class="g-ytitle"><text class="ytitle" transform="rotate(-90,22,327.5)" x="22" y="327.5" text-anchor="middle" data-unformatted="UMAP_2" data-math="N" style="font-family: "Open Sans", verdana, arial, sans-serif; font-size: 14px; fill: rgb(68, 68, 68); opacity: 1; font-weight: normal; white-space: pre;">UMAP_2</text></g></g></svg>

Seurat提供的另一个交互式功能是能够手动选择单元以进行进一步研究。我们发现,这对于不总是使用无偏聚类进行分离但看起来非常不同的小型聚类特别有用。现在,您可以通过创建一个基于GGPLOT2-散点图(如选择带这些细胞[DimPlot()](https://satijalab.org/seurat/reference/DimPlot.html)[FeaturePlot()](https://satijalab.org/seurat/reference/FeaturePlot.html),并通过返回的情节[CellSelector()](https://satijalab.org/seurat/reference/CellSelector.html)[CellSelector()](https://satijalab.org/seurat/reference/CellSelector.html)将返回与点的选定名称的载体,这样你就可以将其设置为一个新的身份分类并执行差分表达式。

例如,让我们假设DC在集群中已经与单核细胞融合,但是我们希望根据它们在tSNE图中的位置来了解它们的独特之处。

pbmc3k.final <- RenameIdents(pbmc3k.final, DC = "CD14+ Mono")
plot <- DimPlot(pbmc3k.final, reduction = "umap")
select.cells <- CellSelector(plot = plot)
image

然后,我们可以更改这些单元格的标识,以将其转变为自己的微型集群。

head(select.cells)
## [1] "AAGATTACCGCCTT" "AAGCCATGAACTGC" "AATTACGAATTCCT" "ACCCGTTGCTTCTA"
## [5] "ACGAGGGACAGGAG" "ACGTGATGCCATGA"
Idents(pbmc3k.final, cells = select.cells) <- "NewCells"

# Now, we find markers that are specific to the new cells, and find clear DC markers
newcells.markers <- FindMarkers(pbmc3k.final, ident.1 = "NewCells", ident.2 = "CD14+ Mono", min.diff.pct = 0.3, 
    only.pos = TRUE)
head(newcells.markers)
##                 p_val avg_log2FC pct.1 pct.2    p_val_adj
## FCER1A   3.239004e-69  3.7008561 0.800 0.017 4.441970e-65
## SERPINF1 7.761413e-36  1.5737896 0.457 0.013 1.064400e-31
## HLA-DQB2 1.721094e-34  0.9685974 0.429 0.010 2.360309e-30
## CD1C     2.304106e-33  1.7785158 0.514 0.025 3.159851e-29
## ENHO     5.099765e-32  1.3734708 0.400 0.010 6.993818e-28
## ITM2C    4.299994e-29  1.5590007 0.371 0.010 5.897012e-25

<details style="box-sizing: border-box; display: block;"><summary style="box-sizing: border-box; display: list-item;">使用CellSelector自动分配小区标识</summary></details>

绘图配件

除了新功能之外,Seurat还为绘图增加了交互功能,还提供了新的附件功能来处理和合并绘图。

# LabelClusters and LabelPoints will label clusters (a coloring variable) or individual points
# on a ggplot2-based scatter plot
plot <- DimPlot(pbmc3k.final, reduction = "pca") + NoLegend()
LabelClusters(plot = plot, id = "ident")
image
# 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 = pbmc3k.final[["pca"]]), repel = TRUE)
image

以前使用该CombinePlot()功能可以绘制多个图。我们不赞成使用此功能,而建议使用拼凑系统。下面是一个简短的演示,但是请访问此处的补丁程序包网站以获取更多详细信息和示例。

plot1 <- DimPlot(pbmc3k.final)
plot2 <- FeatureScatter(pbmc3k.final, feature1 = "LYZ", feature2 = "CCL5")
# Combine two plots
plot1 + plot2
image
# Remove the legend from all plots
(plot1 + plot2) & NoLegend()
image.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容