前言
在ktplots包系列的前一期推文:ktplots(一):绘制个性化气泡图中,Immugent介绍了如何通过ktplots包美化气泡图。其中介绍的一个主要内容就是在展示感兴趣的细胞之间的互作信号,其实还有很多其它类型的图来展示感兴趣的细胞之间的互作方式,今天Immugent就来介绍其它几种常见的作图方式。
废话不多说,下面开始展示。。。
代码流程
首先就是导入数据,为了方便大家复现,Immugent专门使用包内置的数据。
data(kidneyimmune)
annotation <- paste0(kidneyimmune$Experiment, '_', kidneyimmune$celltype)
# one you have set that up correctly, you can then read in the files.
naive_means <- read.delim("naive_out/means.txt", check.names = FALSE)
naive_pvals <- read.delim("naive_out/pvalues.txt", check.names = FALSE)
naive_decon <- read.delim("naive_out/deconvoluted.txt", check.names = FALSE)
treated_means <- read.delim("treated_out/means.txt", check.names = FALSE)
treated_pvals <- read.delim("treated_out/pvalues.txt", check.names = FALSE)
treated_decon <- read.delim("treated_out/deconvoluted.txt", check.names = FALSE)
means <- combine_cpdb(naive_means, treated_means)
pvals <- combine_cpdb(naive_pvals, treated_pvals)
decon <- combine_cpdb(naive_decon, treated_decon)
library(ktplots)
data(kidneyimmune)
data(cpdb_output2)
p <- plot_cpdb2(cell_type1 = 'B cell', cell_type2 = 'CD4T cell',
scdata = kidneyimmune,
idents = 'celltype', # column name where the cell ids are located in the metadata
means = means2,
pvals = pvals2,
deconvoluted = decon2, # new options from here on specific to plot_cpdb2
desiredInteractions = list(
c('CD4T cell', 'B cell'),
c('B cell', 'CD4T cell')),
interaction_grouping = interaction_annotation,
edge_group_colors = c(
"Activating" = "#e15759",
"Chemotaxis" = "#59a14f",
"Inhibitory" = "#4e79a7",
"Intracellular trafficking" = "#9c755f",
"DC_development" = "#B07aa1",
"Unknown" = "#e7e7e7"
),
node_group_colors = c(
"CD4T cell" = "red",
"B cell" = "blue"),
keep_significant_only = TRUE,
standard_scale = TRUE,
remove_self = TRUE
)
p
image.png
Formatting data from anndata formatted file
# code example but not using the example datasets
library(SingleCellExperiment)
library(reticulate)
library(ktplots)
ad=import('anndata')
adata = ad$read_h5ad('rna.h5ad')
counts <- Matrix::t(adata$X)
row.names(counts) <- row.names(adata$var)
colnames(counts) <- row.names(adata$obs)
sce <- SingleCellExperiment(list(counts = counts), colData = adata$obs, rowData = adata$var)
means <- read.delim('out/means.txt', check.names = FALSE)
pvalues <- read.delim('out/pvalues.txt', check.names = FALSE)
deconvoluted <- read.delim('out/deconvoluted.txt', check.names = FALSE)
interaction_grouping <- read.delim('interactions_groups.txt')
# > head(interaction_grouping)
# interaction role
# 1 ALOX5_ALOX5AP Activating
# 2 ANXA1_FPR1 Inhibitory
# 3 BTLA_TNFRSF14 Inhibitory
# 4 CCL5_CCR5 Chemotaxis
# 5 CD2_CD58 Activating
# 6 CD28_CD86 Activating
test <- plot_cpdb2(cell_type1 = "CD4_Tem|CD4_Tcm|CD4_Treg", # same usage style as plot_cpdb
cell_type2 = "cDC",
idents = 'fine_clustering',
split.by = 'treatment_group_1',
scdata = sce,
means = means,
pvals = pvalues,
deconvoluted = deconvoluted, # new options from here on specific to plot_cpdb2
gene_symbol_mapping = 'index', # column name in rowData holding the actual gene symbols if the row names is ENSG Ids. Might be a bit buggy
desiredInteractions = list(c('CD4_Tcm', 'cDC1'), c('CD4_Tcm', 'cDC2'), c('CD4_Tem', 'cDC1'), c('CD4_Tem', 'cDC2 '), c('CD4_Treg', 'cDC1'), c('CD4_Treg', 'cDC2')),
interaction_grouping = interaction_grouping,
edge_group_colors = c("Activating" = "#e15759", "Chemotaxis" = "#59a14f", "Inhibitory" = "#4e79a7", " Intracellular trafficking" = "#9c755f", "DC_development" = "#B07aa1"),
node_group_colors = c("CD4_Tcm" = "#86bc86", "CD4_Tem" = "#79706e", "CD4_Treg" = "#ff7f0e", "cDC1" = "#bcbd22" ,"cDC2" = "#17becf"),
keep_significant_only = TRUE,
standard_scale = TRUE,
remove_self = TRUE)
image.png
library(ktplots)
data(kidneyimmune)
data(cpdb_output2)
p <- plot_cpdb3(cell_type1 = 'B cell', cell_type2 = 'CD4T cell|MNPd',
scdata = kidneyimmune,
idents = 'celltype', # column name where the cell ids are located in the metadata
means = means2,
pvals = pvals2,
deconvoluted = decon2, # new options from here on specific to plot_cpdb3
keep_significant_only = TRUE,
standard_scale = TRUE,
remove_self = TRUE
)
p
image.png
Usage is similar to plot_cpdb3 but with additional required interaction option. Additional kwargs are passed to plot_cpdb.
library(ktplots)
data(kidneyimmune)
data(cpdb_output2)
p <- plot_cpdb4(
interaction = 'CLEC2D-KLRB1',
cell_type1 = 'NK', cell_type2 = 'Mast',
scdata = kidneyimmune,
idents = 'celltype',
means = means2,
pvals = pvals2,
deconvoluted = decon2,
keep_significant_only = TRUE,
standard_scale = TRUE,
)
p
image.png
or specify more than 1 interactions + only show specific cell-type type interactions!
plot_cpdb4(
interaction = c('CLEC2D-KLRB1', 'CD40-CD40LG'),
cell_type1 = 'NK|B', cell_type2 = 'Mast|CD4T',
scdata = kidneyimmune,
idents = 'celltype',
means = means2,
pvals = pvals2,
deconvoluted = decon2,
desiredInteractions = list(
c('NK cell', 'Mast cell'),
c('NK cell', 'NKT cell'),
c('NKT cell', 'Mast cell'),
c('B cell', 'CD4T cell')),
keep_significant_only = TRUE
)
image.png
说在最后
想必跟着代码复现过上面那些图的小伙伴都会觉得,原来自己也能亲自做出之前只在高分文章中见到的图。有一说一,ktplots包做出的图无论是从配色上还是构图上,都没有太多可挑剔的。其实这只是展示ktplots包的一部分功能,其还可以通过调整很多参数做到更个性化的作图/美图,感兴趣的小伙伴可以通过自行探索每一个参数,从而更有利于满足自己以后在绘图中的需要。
好啦,今天的分享到这里就结束啦,我们下期再会~~
网友评论