scCustomize:自定義可視化你的單細(xì)胞數(shù)據(jù)(一)

簡介

scCustomize是一個單細(xì)胞轉(zhuǎn)錄組數(shù)據(jù)可視化的R包,里面集合了一些常用的數(shù)據(jù)可視化方法,可以與Seurat包進(jìn)行很好的聯(lián)用,支持Seurat,LIGER和SCE等常用對象的數(shù)據(jù)。

image.png

R包安裝

直接使用devtools包進(jìn)行安裝

devtools::install_github(repo = "samuel-marsh/scCustomize")
remotes::install_github(repo = "samuel-marsh/scCustomize")

實例演示

在本教程中,我將使用來自 Marsh 等人 2020 ( bioRxiv ) 的小鼠小膠質(zhì)細(xì)胞(圖 1)marsh_mouse_micro和人類死后的 snRNA-seq(圖 3)marsh_human_pm,以及SeuratData 包中的 pbmc3k 數(shù)據(jù)集進(jìn)行實例演示。

加載示例數(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ù)。
# 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)
image.png
  • 繪制PC主成分熱圖
    為了便于評估 PCA 降維結(jié)果,scCustomize 包提供了PC_Plotting()函數(shù)繪制 PC主成分熱圖和特征基因加載圖。
PC_Plotting(seurat_object = marsh_mouse_micro, dim_number = 2)
image.png
  • FeaturePlot
    默認(rèn)Seurat包的Seurat::FeaturePlot()函數(shù)的繪圖效果也很不錯,在這里我們可以通過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)
image.png
# 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)
image.png
  • Split Feature Plots
    Seurat::FeaturePlot()函數(shù)在按object@meta.data 中的變量進(jìn)行拆分繪圖時不再可以指定輸出的列數(shù),這使得可視化具有很多變量的對象變得困難,圖形經(jīng)常擠到一起。
FeaturePlot(object = marsh_mouse_micro, features = "P2ry12", split.by = "orig.ident")
image.png

FeaturePlot_scCustom 解決了這個問題,并允許設(shè)置 FeaturePlots 中的列數(shù)

FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "P2ry12", split.by = "sample_id",
    num_columns = 4)
image.png
  • Density Plots
    Nebulosa包為通過密度圖繪制基因表達(dá)提供了非常棒的功能。scCustomize 包提供了兩個函數(shù)來擴(kuò)展這些圖的功能并便于繪制“聯(lián)合”密度圖。

自定義調(diào)色板
目前,Nebulosa 包僅支持使用 viridis 調(diào)色板中的5個畫板:“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())
image.png

繪制聯(lián)合密度圖
使用Plot_Density_Joint_Only()函數(shù)同時繪制多個基因的聯(lián)合密度圖。

Plot_Density_Joint_Only(seurat_object = marsh_mouse_micro, features = c("Fos", "Jun"))
image.png
  • Dual Assay Plotting
    當(dāng)對象中同時含有多個assay的數(shù)據(jù),我們可以使用FeaturePlot_DualAssay()函數(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")
image.png
  • 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)
image.png

繪制分割堆疊小提琴圖

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")
image.png

調(diào)整垂直打印間距
根據(jù)繪制的基因數(shù)量和用戶偏好,改變繪圖之間的垂直間距可能會有所幫助。這可以使用plot_spacingspacing_unit參數(shù)來完成。

# 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)
image.png
  • 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")
image.png
  • 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)
image.png

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)
image.png
  • Clustered DotPlots
    scCustomize 包還提供了一個單獨(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)
image.png

基因表達(dá)模式的聚類圖
默認(rèn)情況下Clustered_DotPlot執(zhí)行 k-means 聚類,k 值設(shè)置為 1。但是,用戶可以更改此值以更好地可視化表達(dá)模式。

Clustered_DotPlot(seurat_object = pbmc, features = top5_markers, k = 9)
image.png

Clustered_DotPlot() 函數(shù)具有多個可選參數(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)識(列)的顏色。
  • x_lab_rotate 邏輯或整數(shù)。默認(rèn)值為 TRUE(45 度列標(biāo)簽旋轉(zhuǎn))。FALSE(0 度旋轉(zhuǎn))。自定義文本旋轉(zhuǎn)值的整數(shù)。
  • row_label_size 更改行文本(基因符號)的大小。
  • 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())
image.png
  • Split_FeatureScatter()
    這是添加Seurat::FeatureScatter()函數(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)
image.png
  • DimPlot_scCustom()
    scCustomize 包的DimPlot_scCustom()函數(shù)提供了一些新的自定義功能。

新的默認(rèn)調(diào)色板
DimPlot_scCustom函數(shù)設(shè)置新的默認(rèn)調(diào)色板:

  • 如果少于或等于 36 個組,則將使用“多色”調(diào)色板。
  • 如果超過 36 個組,“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)
image.png

打散重疊的點(diǎn)
默認(rèn)情況下,Seurat 的DimPlot()函數(shù)將每個組的點(diǎn)都繪制在下一組之上,這會使繪圖更難解釋。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")
image.png

拆分DimPlot
繪制拆分圖時,Seurat::DimPlot()函數(shù)通過根據(jù)指定的列數(shù)實現(xiàn)共享軸來簡化坐標(biāo)軸。

DimPlot(object = pbmc, split.by = "treatment")
DimPlot(object = pbmc, split.by = "sample_id", ncol = 4)
image.png

默認(rèn)情況下,當(dāng)split.byDimPlot_scCustom布局一起使用時,每個繪圖都會返回一個獨(dú)立坐標(biāo)軸,以便更輕松地可視化大量拆分。

DimPlot_scCustom(seurat_object = pbmc, split.by = "treatment", num_columns = 4, repel = TRUE)
image.png

還可以返回默認(rèn)的 Seurat 分割圖方法,同時DimPlot_scCustom通過提供split_seurat = TRUE參數(shù)。

DimPlot_scCustom(seurat_object = pbmc, split.by = "treatment", num_columns = 4, repel = TRUE, split_seurat = TRUE)
image.png
  • Highlight Cluster(s)
    scCustomize 包提供了Cluster_Highlight_Plot()函數(shù),可以突出顯示一個或多個選定細(xì)胞群與其余細(xì)胞的分布,以突出顯示它們在圖上的位置。
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")
image.png
  • Highlight Meta Data
    scCustomize 包還提供了一個類似的函數(shù)Meta_Highlight_Plot(),可以允許我們快速突出顯示任何有效的metadata元數(shù)據(jù)信息。其中,元數(shù)據(jù)變量必須是“factor”, “character”, or “l(fā)ogical”類型,可以使用as.characteras.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")
image.png
  • DimPlot Layout Plots
    使用DimPlot_All_Samples函數(shù)對指定變量進(jìn)行拆分繪圖。
DimPlot_All_Samples(seurat_object = pbmc, meta_data_column = "sample_id", num_col = 3, pt.size = 0.5)
image.png

可以通過提供顏色向量而不是單個值來為每個圖進(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"))
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容