前言
在ktplots包系列的前一期推文:ktplots(一):繪制個性化氣泡圖中,Immugent介紹了如何通過ktplots包美化氣泡圖扫夜。其中介紹的一個主要內(nèi)容就是在展示感興趣的細胞之間的互作信號定续,其實還有很多其它類型的圖來展示感興趣的細胞之間的互作方式,今天Immugent就來介紹其它幾種常見的作圖方式首繁。
廢話不多說,下面開始展示。。陶衅。
代碼流程
首先就是導入數(shù)據(jù),為了方便大家復現(xiàn)直晨,Immugent專門使用包內(nèi)置的數(shù)據(jù)搀军。
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
說在最后
想必跟著代碼復現(xiàn)過上面那些圖的小伙伴都會覺得膨俐,原來自己也能親自做出之前只在高分文章中見到的圖。有一說一罩句,ktplots包做出的圖無論是從配色上還是構(gòu)圖上焚刺,都沒有太多可挑剔的。其實這只是展示ktplots包的一部分功能门烂,其還可以通過調(diào)整很多參數(shù)做到更個性化的作圖/美圖乳愉,感興趣的小伙伴可以通過自行探索每一個參數(shù),從而更有利于滿足自己以后在繪圖中的需要屯远。
好啦蔓姚,今天的分享到這里就結(jié)束啦,我們下期再會~~