单细胞测序技术scRNA-seq

scCustomize:自定义可视化你的单细胞数据(一)

2022-09-09  本文已影响0人  Davey1220

简介

scCustomize是一个单细胞转录组数据可视化的R包,里面集合了一些常用的数据可视化方法,可以与Seurat包进行很好的联用,支持Seurat,LIGER和SCE等常用对象的数据。

image.png

R包安装

直接使用devtools包进行安装

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

实例演示

在本教程中,我将使用来自 Marsh 等人 2020 ( bioRxiv ) 的小鼠小胶质细胞(图 1)marsh_mouse_micro和人类死后的 snRNA-seq(图 3)marsh_human_pm,以及SeuratData 包中的 pbmc3k 数据集进行实例演示。

加载示例数据

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)

数据可视化

# 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_Plotting(seurat_object = marsh_mouse_micro, dim_number = 2)
image.png
# 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
FeaturePlot(object = marsh_mouse_micro, features = "P2ry12", split.by = "orig.ident")
image.png

FeaturePlot_scCustom 解决了这个问题,并允许设置 FeaturePlots 中的列数

FeaturePlot_scCustom(seurat_object = marsh_mouse_micro, features = "P2ry12", split.by = "sample_id",
    num_columns = 4)
image.png

自定义调色板
目前,Nebulosa 包仅支持使用 viridis 调色板中的5个画板:“viridis”、“magma”、“cividis”、“inferno”和“plasma”。Plot_Density_Custom()函数将默认调色板更改为“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

绘制联合密度图
使用Plot_Density_Joint_Only()函数同时绘制多个基因的联合密度图。

Plot_Density_Joint_Only(seurat_object = marsh_mouse_micro, features = c("Fos", "Jun"))
image.png
cell_bender_example <- qread("assets/astro_nuc_seq.qs")
FeaturePlot_DualAssay(seurat_object = cell_bender_example, features = "Syt1", assay1 = "RAW", assay2 = "RNA")
image.png
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

调整垂直打印间距
根据绘制的基因数量和用户偏好,改变绘图之间的垂直间距可能会有所帮助。这可以使用plot_spacingspacing_unit参数来完成。

# 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

VlnPlot_scCustom函数提供了自定义的内置画板

VlnPlot(object = pbmc, features = "PTPRC")
VlnPlot_scCustom(seurat_object = pbmc, features = "PTPRC")
image.png
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()函数还包含其他参数,以便更好地自定义绘制点图。
包括:

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
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

基因表达模式的聚类图
默认情况下Clustered_DotPlot执行 k-means 聚类,k 值设置为 1。但是,用户可以更改此值以更好地可视化表达模式。

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

Clustered_DotPlot() 函数具有多个可选参数,用户可以根据所需的结果图修改不同可选参数。

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

在这里,我们可以根据此表达量分位数的数据范围设置最大和最小值,并更改要使用的色阶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
# 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函数设置新的默认调色板:

DimPlot(object = marsh_mouse_over)
DimPlot_scCustom(seurat_object = marsh_mouse_over)
image.png

打散重叠的点
默认情况下,Seurat 的DimPlot()函数将每个组的点都绘制在下一组之上,这会使绘图更难解释。DimPlot_scCustom默认情况下设置shuffle = TRUE,可以将重叠覆盖的点进行打散。

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()函数通过根据指定的列数实现共享轴来简化坐标轴。

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

默认情况下,当split.byDimPlot_scCustom布局一起使用时,每个绘图都会返回一个独立坐标轴,以便更轻松地可视化大量拆分。

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

还可以返回默认的 Seurat 分割图方法,同时DimPlot_scCustom通过提供split_seurat = TRUE参数。

DimPlot_scCustom(seurat_object = pbmc, split.by = "treatment", num_columns = 4, repel = TRUE, split_seurat = TRUE)
image.png
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
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_All_Samples(seurat_object = pbmc, meta_data_column = "sample_id", num_col = 3, pt.size = 0.5)
image.png

可以通过提供颜色向量而不是单个值来为每个图进行着色。

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
上一篇下一篇

猜你喜欢

热点阅读