专栏名称: 生信菜鸟团
生信菜鸟团荣誉归来,让所有想分析生物信息学数据的小伙伴找到归属,你值得拥有!
目录
相关文章推荐
生物学霸  ·  教育部官宣,7 所「新大学」来了 ·  2 天前  
BioArt  ·  Nat Commun | ... ·  2 天前  
BioArt  ·  Cell Rep | ... ·  2 天前  
生物学霸  ·  重磅!2025 中科院分区表发布,附名单 ·  3 天前  
51好读  ›  专栏  ›  生信菜鸟团

R tips:celltrek细胞共定位分析

生信菜鸟团  · 公众号  · 生物  · 2025-03-15 21:00

正文

CellTrek 是一个空间分析工具包,可以做单细胞和空间的整合分析、空间细胞共定位和空间基因表达分析。

它的共定位分析可以找到空间上距离相互靠近的细胞,并以网络图的形式呈现。

官方教程中,共定位分析需要依赖整合单细胞和空间数据之后的celltrek对象,本文则只使用空间数据进行共定位分析。同时官方提供了一个shiny程序用于展示共定位网络结构,交互性很好,但是无法导出图片,本文则使用igraph从头绘制共定位网络图。

仍以10X的xenium breast官方数据为例,下载后解压。

读取数据,构造用于celltrek共定位分析的对象

  1. # read xenium gene expression data
  2. xenium_expr  Read10X_h5("Xenium_V1_FFPE_Human_Breast_IDC/cell_feature_matrix.h5")
  3. xenium  CreateSeuratObject(
  4.     xenium_expr$`Gene Expression`,
  5.     min.cells = 10,
  6.     min.features = 10
  7.   ) %>%
  8.   RenameCells(add.cell.id = "cell")
  9. # read cell coords data
  10. # 3 column should exists to run CellTrek::scoloc analysis
  11. # coord_x, coord_y, id_new
  12. coords_xenium  arrow::read_parquet("Xenium_V1_FFPE_Human_Breast_IDC/cells.parquet")
  13. meta_coords 
  14.   coords_xenium %>%
  15.   dplyr::select(
  16.     cell_id,
  17.     coord_x = x_centroid,
  18.     coord_y = y_centroid
  19.    ) %>%
  20.   mutate(cell_id = str_c("cell", cell_id, sep = "_")) %>%
  21.   mutate(id_new = cell_id) %>%
  22.   column_to_rownames("cell_id")
  23. xenium  xenium %>% AddMetaData(meta_coords)

构造模拟的组别和细胞注释,这里只是示意,正常情况下,group是分析组别,annotation是注释好的细胞类型。

  1. set.seed(1234)
  2. xenium$group  sample(LETTERS[1:3], size = ncol(xenium), replace = TRUE)
  3. xenium$annotation  sample(str_c("Cell", LETTERS[1:10], sep = "_"), size = ncol(xenium), replace = TRUE)

展示一下此时的数据,为了提高绘图速度,只是用10%的细胞绘制空间原位图:

  1. # spatial plot
  2. xenium[[]] %>%
  3.   dplyr::slice_sample(prop = 0.1) %>%
  4.   ggplot(aes (= coord_x, y = coord_y)) +
  5.   geom_tile(aes(fill = group), height = 20, width = 20) +
  6.   coord_equal() +
  7.   ggsci::scale_fill_aaas() +
  8.   theme_void()
  9. xenium[[]] %>%
  10.   dplyr::slice_sample(prop = 0.1) %>%
  11.   ggplot(aes(= coord_x, y = coord_y)) +
  12.   geom_tile(aes(fill = annotation), height = 20, width = 20) +
  13.   coord_equal() +
  14.   ggsci::scale_fill_igv() +
  15.   theme_void()

空间共定位

  1. # run CellTrek analysis sequentially for the three groups
  2. all_data_grp_ls  xenium %>% SplitObject(split.by = "group")
  3. # run celltrek
  4. all_celltrek_ls 
  5.   all_data_grp_ls %>%
  6.   map(function(sc){ # browser()
  7.     graph_KL 
  8.       CellTrek::scoloc(
  9.         sc,
  10.         col_cell   ='annotation',
  11.         use_method ='KL',






请到「今天看啥」查看全文