CellTrek
是一个空间分析工具包,可以做单细胞和空间的整合分析、空间细胞共定位和空间基因表达分析。
它的共定位分析可以找到空间上距离相互靠近的细胞,并以网络图的形式呈现。
官方教程中,共定位分析需要依赖整合单细胞和空间数据之后的celltrek对象,本文则只使用空间数据进行共定位分析。同时官方提供了一个shiny程序用于展示共定位网络结构,交互性很好,但是无法导出图片,本文则使用igraph从头绘制共定位网络图。
仍以10X的xenium breast官方数据为例,下载后解压。
读取数据,构造用于celltrek共定位分析的对象
# read xenium gene expression data
xenium_expr Read10X_h5("Xenium_V1_FFPE_Human_Breast_IDC/cell_feature_matrix.h5")
xenium CreateSeuratObject(
xenium_expr$`Gene Expression`,
min.cells = 10,
min.features = 10
) %>%
RenameCells(add.cell.id = "cell")
# read cell coords data
# 3 column should exists to run CellTrek::scoloc analysis
# coord_x, coord_y, id_new
coords_xenium arrow::read_parquet("Xenium_V1_FFPE_Human_Breast_IDC/cells.parquet")
meta_coords
coords_xenium %>%
dplyr::select(
cell_id,
coord_x = x_centroid,
coord_y = y_centroid
) %>%
mutate(cell_id = str_c("cell", cell_id, sep = "_")) %>%
mutate(id_new = cell_id) %>%
column_to_rownames("cell_id")
xenium xenium %>% AddMetaData(meta_coords)
构造模拟的组别和细胞注释,这里只是示意,正常情况下,group是分析组别,annotation是注释好的细胞类型。
set.seed(1234)
xenium$group sample(LETTERS[1:3], size = ncol(xenium), replace = TRUE)
xenium$annotation sample(str_c("Cell", LETTERS[1:10], sep = "_"), size = ncol(xenium), replace = TRUE)
展示一下此时的数据,为了提高绘图速度,只是用10%的细胞绘制空间原位图:
# spatial plot
xenium[[]] %>%
dplyr::slice_sample(prop = 0.1) %>%
ggplot(aes
(x = coord_x, y = coord_y)) +
geom_tile(aes(fill = group), height = 20, width = 20) +
coord_equal() +
ggsci::scale_fill_aaas() +
theme_void()
xenium[[]] %>%
dplyr::slice_sample(prop = 0.1) %>%
ggplot(aes(x = coord_x, y = coord_y)) +
geom_tile(aes(fill = annotation), height = 20, width = 20) +
coord_equal() +
ggsci::scale_fill_igv() +
theme_void()
空间共定位
# run CellTrek analysis sequentially for the three groups
all_data_grp_ls xenium %>% SplitObject(split.by = "group")
# run celltrek
all_celltrek_ls
all_data_grp_ls %>%
map(function(sc){ # browser()
graph_KL
CellTrek::scoloc(
sc,
col_cell ='annotation',
use_method ='KL',