單細(xì)胞轉(zhuǎn)錄組 數(shù)據(jù)分析||Seurat新版教程:New data visualization methods in v3.0

編者按:本文介紹了新版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"    

隨機(jī)選的啊
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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末琳状,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子盒齿,更是在濱河造成了極大的恐慌念逞,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,013評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件边翁,死亡現(xiàn)場(chǎng)離奇詭異翎承,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)符匾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,205評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門叨咖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事甸各《庀停” “怎么了?”我有些...
    開封第一講書人閱讀 152,370評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵趣倾,是天一觀的道長(zhǎng)聘惦。 經(jīng)常有香客問(wèn)我,道長(zhǎng)儒恋,這世上最難降的妖魔是什么善绎? 我笑而不...
    開封第一講書人閱讀 55,168評(píng)論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮诫尽,結(jié)果婚禮上禀酱,老公的妹妹穿的比我還像新娘。我一直安慰自己箱锐,他們只是感情好比勉,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,153評(píng)論 5 371
  • 文/花漫 我一把揭開白布劳较。 她就那樣靜靜地躺著驹止,像睡著了一般。 火紅的嫁衣襯著肌膚如雪观蜗。 梳的紋絲不亂的頭發(fā)上臊恋,一...
    開封第一講書人閱讀 48,954評(píng)論 1 283
  • 那天,我揣著相機(jī)與錄音墓捻,去河邊找鬼抖仅。 笑死,一個(gè)胖子當(dāng)著我的面吹牛砖第,可吹牛的內(nèi)容都是我干的撤卢。 我是一名探鬼主播,決...
    沈念sama閱讀 38,271評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼梧兼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼放吩!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起羽杰,我...
    開封第一講書人閱讀 36,916評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤渡紫,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后考赛,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體惕澎,經(jīng)...
    沈念sama閱讀 43,382評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,877評(píng)論 2 323
  • 正文 我和宋清朗相戀三年颜骤,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了唧喉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 37,989評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖欣喧,靈堂內(nèi)的尸體忽然破棺而出腌零,到底是詐尸還是另有隱情,我是刑警寧澤唆阿,帶...
    沈念sama閱讀 33,624評(píng)論 4 322
  • 正文 年R本政府宣布益涧,位于F島的核電站,受9級(jí)特大地震影響驯鳖,放射性物質(zhì)發(fā)生泄漏闲询。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,209評(píng)論 3 307
  • 文/蒙蒙 一浅辙、第九天 我趴在偏房一處隱蔽的房頂上張望扭弧。 院中可真熱鬧,春花似錦记舆、人聲如沸鸽捻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,199評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)御蒲。三九已至,卻和暖如春诊赊,著一層夾襖步出監(jiān)牢的瞬間厚满,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,418評(píng)論 1 260
  • 我被黑心中介騙來(lái)泰國(guó)打工碧磅, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留碘箍,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,401評(píng)論 2 352
  • 正文 我出身青樓鲸郊,卻偏偏與公主長(zhǎng)得像丰榴,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子秆撮,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,700評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容