簡(jiǎn)介
scCustomize
是一個(gè)單細(xì)胞轉(zhuǎn)錄組數(shù)據(jù)可視化的R包,里面集合了一些常用的數(shù)據(jù)可視化方法哥攘,可以與Seurat包進(jìn)行很好的聯(lián)用,支持Seurat,LIGER和SCE等常用對(duì)象的數(shù)據(jù)椎眯。
R包安裝
直接使用devtools包進(jìn)行安裝
devtools::install_github(repo = "samuel-marsh/scCustomize")
remotes::install_github(repo = "samuel-marsh/scCustomize")
實(shí)例演示
在本教程中,我將使用來(lái)自 Marsh 等人 2020 ( bioRxiv ) 的小鼠小膠質(zhì)細(xì)胞(圖 1)marsh_mouse_micro
和人類死后的 snRNA-seq(圖 3)marsh_human_pm
胳岂,以及SeuratData 包中的 pbmc3k 數(shù)據(jù)集進(jìn)行實(shí)例演示盅视。
加載示例數(shù)據(jù)
library(tidyverse)
library(patchwork)
library(viridis)
library(Seurat)
library(scCustomize)
library(qs)
# Load bioRxiv datasets
marsh_mouse_micro <- qread(file = "assets/marsh_2020_micro.qs")
marsh_human_pm <- qread(file = "assets/marsh_human_pm.qs")
# Load pbmc dataset
pbmc <- pbmc3k.SeuratData::pbmc3k.final
# add metadata
pbmc$sample_id <- sample(c("sample1", "sample2", "sample3", "sample4", "sample5", "sample6"), size = ncol(pbmc),
replace = TRUE)
pbmc$treatment <- sample(c("Treatment1", "Treatment", "Treatment3", "Treatment4"), size = ncol(pbmc),
replace = TRUE)
數(shù)據(jù)可視化
- 繪制高變異基因
scCustomize 包可以使用VariableFeaturePlot_scCustom()
函數(shù)繪制高度可變基因,同時(shí)提供了多個(gè)可用于自定義可視化的附加參數(shù)旦万。
# Default scCustomize plot
VariableFeaturePlot_scCustom(seurat_object = marsh_mouse_micro, num_features = 20)
# Can remove labels if not desired
VariableFeaturePlot_scCustom(seurat_object = marsh_mouse_micro, num_features = 20, label = FALSE)
# Repel labels
VariableFeaturePlot_scCustom(seurat_object = marsh_mouse_micro, num_features = 20, repel = TRUE)
# Change the scale of y-axis from linear to log10
VariableFeaturePlot_scCustom(seurat_object = marsh_mouse_micro, num_features = 20, repel = TRUE,
y_axis_log = TRUE)
- 繪制PC主成分熱圖
為了便于評(píng)估 PCA 降維結(jié)果闹击,scCustomize 包提供了PC_Plotting()
函數(shù)繪制 PC主成分熱圖和特征基因加載圖。
PC_Plotting(seurat_object = marsh_mouse_micro, dim_number = 2)
- FeaturePlot
默認(rèn)Seurat包的Seurat::FeaturePlot()
函數(shù)的繪圖效果也很不錯(cuò)成艘,在這里我們可以通過(guò)scCustomize包的FeaturePlot_scCustom()
函數(shù)默認(rèn)設(shè)置的幾種方式進(jìn)行功能的增強(qiáng)赏半。默認(rèn)情況下,F(xiàn)eaturePlot_scCustom函數(shù)的參數(shù)order = TRUE是默認(rèn)值淆两,可以將高表達(dá)的細(xì)胞繪制在頂部断箫。
# Set color palette
pal <- viridis(n = 10, option = "C", direction = -1)
# Create Plots
FeaturePlot(object = marsh_mouse_micro, features = "Jun")
FeaturePlot(object = marsh_mouse_micro, features = "Jun", order = T)
FeaturePlot(object = marsh_mouse_micro, features = "Jun", cols = pal, order = T)
# Set color palette
pal <- viridis(n = 10, option = "D")
# Create Plots
FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "Jun", order = F)
FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "Jun")
FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "Jun", colors_use = pal)
- Split Feature Plots
Seurat::FeaturePlot()
函數(shù)在按object@meta.data 中的變量進(jìn)行拆分繪圖時(shí)不再可以指定輸出的列數(shù),這使得可視化具有很多變量的對(duì)象變得困難秋冰,圖形經(jīng)常擠到一起仲义。
FeaturePlot(object = marsh_mouse_micro, features = "P2ry12", split.by = "orig.ident")
FeaturePlot_scCustom 解決了這個(gè)問(wèn)題,并允許設(shè)置 FeaturePlots 中的列數(shù)
FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "P2ry12", split.by = "sample_id",
num_columns = 4)
- Density Plots
Nebulosa包為通過(guò)密度圖繪制基因表達(dá)提供了非常棒的功能剑勾。scCustomize 包提供了兩個(gè)函數(shù)來(lái)擴(kuò)展這些圖的功能并便于繪制“聯(lián)合”密度圖埃撵。
自定義調(diào)色板
目前,Nebulosa 包僅支持使用 viridis 調(diào)色板中的5個(gè)畫板:“viridis”虽另、“magma”暂刘、“cividis”、“inferno”和“plasma”捂刺。Plot_Density_Custom()
函數(shù)將默認(rèn)調(diào)色板更改為“magma”谣拣,還允許使用任何自定義漸變畫板。
Plot_Density_Custom(seurat_object = marsh_mouse_micro, features = "Fos")
Plot_Density_Custom(seurat_object = marsh_mouse_micro, features = "Fos", custom_palette = PurpleAndYellow())
繪制聯(lián)合密度圖
使用Plot_Density_Joint_Only()
函數(shù)同時(shí)繪制多個(gè)基因的聯(lián)合密度圖族展。
Plot_Density_Joint_Only(seurat_object = marsh_mouse_micro, features = c("Fos", "Jun"))
- Dual Assay Plotting
當(dāng)對(duì)象中同時(shí)含有多個(gè)assay的數(shù)據(jù)森缠,我們可以使用FeaturePlot_DualAssay()
函數(shù)同時(shí)繪制不同assay中的數(shù)據(jù)。
cell_bender_example <- qread("assets/astro_nuc_seq.qs")
FeaturePlot_DualAssay(seurat_object = cell_bender_example, features = "Syt1", assay1 = "RAW", assay2 = "RNA")
- Stacked Violin Plots
與Seurat包的Seurat::VlnPlot()
函數(shù)相比仪缸,scCustomize 包提供了更美觀的堆疊小提琴圖繪制函數(shù)Stacked_VlnPlot()
贵涵。
gene_list_plot <- c("SLC17A7", "GAD2", "AQP4", "MYT1", "COL1A2", "CLDN5", "OPALIN", "CX3CR1", "CD3E")
human_colors_list <- c("dodgerblue", "navy", "forestgreen", "darkorange2", "darkorchid3", "orchid",
"orange", "gold", "gray")
# Create Plots
Stacked_VlnPlot(seurat_object = marsh_human_pm, features = gene_list_plot, x_lab_rotate = TRUE,
colors_use = human_colors_list)
繪制分割堆疊小提琴圖
sample_colors <- c("dodgerblue", "forestgreen", "firebrick1")
# Create Plots
Stacked_VlnPlot(seurat_object = marsh_human_pm, features = gene_list_plot, x_lab_rotate = TRUE,
colors_use = sample_colors, split.by = "orig.ident")
調(diào)整垂直打印間距
根據(jù)繪制的基因數(shù)量和用戶偏好,改變繪圖之間的垂直間距可能會(huì)有所幫助。這可以使用plot_spacing
和spacing_unit
參數(shù)來(lái)完成独悴。
# Default plot spacing (plot_spacing = 0.15 and spacing_unit = 'cm')
Stacked_VlnPlot(seurat_object = pbmc, features = c("CD3E", "CD14", "MS4A1", "FCER1A", "PPBP"), x_lab_rotate = TRUE)
# Double the space between plots
Stacked_VlnPlot(seurat_object = pbmc, features = c("CD3E", "CD14", "MS4A1", "FCER1A", "PPBP"), x_lab_rotate = TRUE,
plot_spacing = 0.3)
- Custom VlnPlots
除了Stacked_VlnPlot函數(shù)例书,scCustomize包也提供了VlnPlot_scCustom()
函數(shù)進(jìn)行自定義可視化小提琴圖。
VlnPlot_scCustom函數(shù)提供了自定義的內(nèi)置畫板
VlnPlot(object = pbmc, features = "PTPRC")
VlnPlot_scCustom(seurat_object = pbmc, features = "PTPRC")
- Custom DotPlots
scCustomize包的DotPlot_scCustom()
函數(shù)允許使用自定義漸變畫板進(jìn)行繪圖刻炒。
micro_genes <- c("P2ry12", "Fcrls", "Trem2", "Tmem119", "Cx3cr1", "Hexb", "Tgfbr1", "Sparc", "P2ry13",
"Olfml3", "Adgrg1", "C1qa", "C1qb", "C1qc", "Csf1r", "Fcgr3", "Ly86", "Laptm5")
DotPlot(object = marsh_mouse_micro, features = micro_genes[1:6], cols = viridis_plasma_dark_high)
DotPlot_scCustom(seurat_object = marsh_mouse_micro, features = micro_genes[1:6], colors_use = viridis_plasma_dark_high)
DotPlot_scCustom()
函數(shù)還包含其他參數(shù)决采,以便更好地自定義繪制點(diǎn)圖。
包括:
-
x_lab_rotate
旋轉(zhuǎn) x 軸文本坟奥, 默認(rèn)值為 FALSE树瞭。 -
y_lab_rotate
旋轉(zhuǎn) y 軸文本, 默認(rèn)值為 FALSE爱谁。 -
flip_axes
翻轉(zhuǎn)坐標(biāo)軸晒喷,默認(rèn)為FALSE。 -
remove_axis_titles
刪除 x 軸和 y 軸標(biāo)簽访敌。默認(rèn)為TRUE
DotPlot_scCustom(seurat_object = marsh_mouse_micro, features = micro_genes[1:6], x_lab_rotate = TRUE)
DotPlot_scCustom(seurat_object = marsh_mouse_micro, features = micro_genes[1:6], y_lab_rotate = TRUE)
DotPlot_scCustom(seurat_object = marsh_mouse_micro, features = micro_genes[1:6], flip_axes = T,
x_lab_rotate = TRUE)
DotPlot_scCustom(seurat_object = marsh_mouse_micro, features = micro_genes[1:6], flip_axes = T,
remove_axis_titles = FALSE)
- Clustered DotPlots
scCustomize 包還提供了一個(gè)單獨(dú)的函數(shù)Clustered_DotPlot()
凉敲,可以繪制基因和樣本的聚類點(diǎn)圖。
all_markers <- FindAllMarkers(object = pbmc)
top5_markers <- Extract_Top_Markers(marker_dataframe = all_markers, num_genes = 5, named_vector = FALSE,
make_unique = TRUE)
Clustered_DotPlot(seurat_object = pbmc, features = top5_markers)
基因表達(dá)模式的聚類圖
默認(rèn)情況下Clustered_DotPlot
執(zhí)行 k-means 聚類寺旺,k 值設(shè)置為 1爷抓。但是,用戶可以更改此值以更好地可視化表達(dá)模式阻塑。
Clustered_DotPlot(seurat_object = pbmc, features = top5_markers, k = 9)
Clustered_DotPlot()
函數(shù)具有多個(gè)可選參數(shù)蓝撇,用戶可以根據(jù)所需的結(jié)果圖修改不同可選參數(shù)。
- colors_use_exp 提供自定義色標(biāo)
- exp_color_min/exp_color_max 可用于設(shè)置基因表達(dá)量刻度上的最小值和最大值陈莽。
- print_exp_quantiles 可以設(shè)置為 TRUE 以打印基因表達(dá)量分位數(shù)以幫助設(shè)置 new exp_color_min/exp_color_max渤昌。
- exp_color_middle 可用于更改用于色標(biāo)中間的值。
- colors_use_idents 用于繪制的標(biāo)識(shí)(列)的顏色走搁。
- x_lab_rotate 邏輯或整數(shù)独柑。默認(rèn)值為 TRUE(45 度列標(biāo)簽旋轉(zhuǎn))。FALSE(0 度旋轉(zhuǎn))朱盐。自定義文本旋轉(zhuǎn)值的整數(shù)群嗤。
- row_label_size 更改行文本(基因符號(hào))的大小。
- raster 是否柵格化繪圖(更快和更小的文件大斜铡)。默認(rèn)為FALSE骇径。
Clustered_DotPlot(seurat_object = pbmc, features = top5_markers, k = 7, print_exp_quantiles = T)
#Quantiles of gene expression data are:
# 10% 50% 90% 99%
#-0.6555988 -0.3595223 1.7742718 2.6666597
在這里躯肌,我們可以根據(jù)此表達(dá)量分位數(shù)的數(shù)據(jù)范圍設(shè)置最大和最小值,并更改要使用的色階Seurat::PurpleAndYellow()
Clustered_DotPlot(seurat_object = pbmc, features = top5_markers, k = 7, exp_color_min = -1, exp_color_max = 2,
colors_use_exp = PurpleAndYellow())
- Split_FeatureScatter()
這是添加Seurat::FeatureScatter()
函數(shù)缺少的功能破衔,在比較兩個(gè)基因/特征或比較模塊得分時(shí)清女,使用Split_FeatureScatter函數(shù)進(jìn)行分割繪圖可能非常有用。
# Create Plots
Split_FeatureScatter(seurat_object = marsh_mouse_micro, feature1 = "exAM_Score1", feature2 = "Microglia_Score1",
colors_use = mouse_colors, split.by = "Transcription_Method", group.by = "ident", num_columns = 2,
pt.size = 1)
- DimPlot_scCustom()
scCustomize 包的DimPlot_scCustom()
函數(shù)提供了一些新的自定義功能晰筛。
新的默認(rèn)調(diào)色板
DimPlot_scCustom
函數(shù)設(shè)置新的默認(rèn)調(diào)色板:
- 如果少于或等于 36 個(gè)組嫡丙,則將使用“多色”調(diào)色板拴袭。
- 如果超過(guò) 36 個(gè)組,“varibow”調(diào)色板將與
shuffle_pal = TRUE
. - 如果用戶想使用 ggplot2 色調(diào)調(diào)色板然后設(shè)置參數(shù)
ggplot_default_colors = TRUE
曙博。
DimPlot(object = marsh_mouse_over)
DimPlot_scCustom(seurat_object = marsh_mouse_over)
打散重疊的點(diǎn)
默認(rèn)情況下拥刻,Seurat 的DimPlot()
函數(shù)將每個(gè)組的點(diǎn)都繪制在下一組之上,這會(huì)使繪圖更難解釋父泳。DimPlot_scCustom
默認(rèn)情況下設(shè)置shuffle = TRUE
般哼,可以將重疊覆蓋的點(diǎn)進(jìn)行打散。
DimPlot(object = marsh_human_pm, group.by = "sample_id")
DimPlot_scCustom(seurat_object = marsh_human_pm, group.by = "sample_id")
拆分DimPlot
繪制拆分圖時(shí)惠窄,Seurat::DimPlot()
函數(shù)通過(guò)根據(jù)指定的列數(shù)實(shí)現(xiàn)共享軸來(lái)簡(jiǎn)化坐標(biāo)軸蒸眠。
DimPlot(object = pbmc, split.by = "treatment")
DimPlot(object = pbmc, split.by = "sample_id", ncol = 4)
默認(rèn)情況下,當(dāng)split.by
與DimPlot_scCustom
布局一起使用時(shí)杆融,每個(gè)繪圖都會(huì)返回一個(gè)獨(dú)立坐標(biāo)軸楞卡,以便更輕松地可視化大量拆分。
DimPlot_scCustom(seurat_object = pbmc, split.by = "treatment", num_columns = 4, repel = TRUE)
還可以返回默認(rèn)的 Seurat 分割圖方法脾歇,同時(shí)DimPlot_scCustom
通過(guò)提供split_seurat = TRUE
參數(shù)蒋腮。
DimPlot_scCustom(seurat_object = pbmc, split.by = "treatment", num_columns = 4, repel = TRUE, split_seurat = TRUE)
- Highlight Cluster(s)
scCustomize 包提供了Cluster_Highlight_Plot()
函數(shù),可以突出顯示一個(gè)或多個(gè)選定細(xì)胞群與其余細(xì)胞的分布介劫,以突出顯示它們?cè)趫D上的位置徽惋。
Cluster_Highlight_Plot(seurat_object = marsh_mouse_over, cluster_name = "7", highlight_color = "navy",
background_color = "lightgray")
Cluster_Highlight_Plot(seurat_object = marsh_mouse_over, cluster_name = "8", highlight_color = "forestgreen",
background_color = "lightgray")
- Highlight Meta Data
scCustomize 包還提供了一個(gè)類似的函數(shù)Meta_Highlight_Plot()
,可以允許我們快速突出顯示任何有效的metadata元數(shù)據(jù)信息座韵。其中险绘,元數(shù)據(jù)變量必須是“factor”, “character”, or “l(fā)ogical”類型,可以使用as.character
或as.factor
函數(shù)將其他類型數(shù)據(jù)進(jìn)行轉(zhuǎn)換誉碴。
Meta_Highlight_Plot(seurat_object = marsh_mouse_micro, meta_data_column = "Transcription_Method",
meta_data_highlight = "ENZYMATIC_NONE", highlight_color = "firebrick", background_color = "lightgray")
- DimPlot Layout Plots
使用DimPlot_All_Samples函數(shù)對(duì)指定變量進(jìn)行拆分繪圖宦棺。
DimPlot_All_Samples(seurat_object = pbmc, meta_data_column = "sample_id", num_col = 3, pt.size = 0.5)
可以通過(guò)提供顏色向量而不是單個(gè)值來(lái)為每個(gè)圖進(jìn)行著色。
DimPlot_All_Samples(seurat_object = marsh_mouse_micro, meta_data_column = "Transcription", num_col = 2,
pt.size = 0.5, color = c("firebrick3", "dodgerblue3"))