跟着官网学CellChat 从空间成像数据推断和分析空间信息的细胞间通信

CellChat 从空间成像数据推断和分析空间信息的细胞间通信

Suoqin Jin and Jingren Niu
2022 年 11 月 12 日
加载所需的库
第一部分:CellChat对象的数据输入&处理和初始化
加载数据
创建一个 CellChat 对象
设置配体-受体相互作用数据库
预处理细胞间通讯分析的表达数据
第二部分:细胞间通信网络的推断
计算通信概率并推断蜂窝通信网络
在信号通路水平上推断细胞间通讯
计算聚合的细胞间通信网络
第三部分:细胞间通信网络的可视化
第五部分:保存 CellChat 对象
此小插图概述了使用 CellChat 对单个空间成像数据集进行细胞间通信网络的推理、分析和可视化的步骤。我们通过将 CellChat 应用于小鼠大脑 10X visium 数据集 ( https://www.10xgenomics.com/resources/datasets/mouse-brain-serial-section-1-sagittal-anterior-1-standard ) 来展示 CellChat 在空间成像数据中的应用-1-0-0)。使用 Seurat ( https://satijalab.org/seurat/articles/spatial_vignette.html )预测斑点的生物学注释(即细胞群信息)。

CellChat 需要斑点/细胞的基因表达和空间位置数据作为用户输入,并通过将基因表达与空间距离​​以及信号配体、受体及其辅因子之间相互作用的先验知识相结合来模拟细胞间通信的概率。

在推断细胞间通信网络后,CellChat 的各种功能可用于进一步的数据探索、分析和可视化。

加载所需的库

library(CellChat)
library(patchwork)
options(stringsAsFactors = FALSE)

第一部分:CellChat对象的数据输入&处理和初始化

CellChat 需要四个用户输入:

斑点/细胞的基因表达数据:基因应该在行中,行名和细胞在列中,列名。需要将标准化数据(例如,库大小标准化,然后使用伪计数 1 进行对数转换)作为 CellChat 分析的输入。如果用户提供计数数据,我们提供一个 normalizeData函数来计算库大小,然后进行对数转换。

用户分配的单元格标签:由单元格信息组成的数据框(行是具有行名的单元格),将用于定义单元格组。

斑点/细胞的空间位置:一个数据矩阵,其中每一行给出每个细胞/斑点的空间位置/坐标。对于 10X Visium,此信息位于 tissue_positions.csv.

全分辨率图像的比例因子和光斑直径:包含全分辨率图像的比例因子和光斑直径的列表。scale.factors 必须包含一个名为 的元素spot.diameter,这是理论光斑尺寸(例如,10x Visium(spot.size = 65 微米));和另一个名为 的元素 spot,它是原始全分辨率图像中跨越理论光斑直径的像素数。对于 10X Visium,scale.factors 在文件中 scalefactors_json.json。spot是 spot.size.fullres。

加载数据

# Here we load a Seurat object of 10X Visium mouse cortex data and its associated cell meta data
load("/Users/jinsuoqin/Mirror/CellChat/tutorial/visium_mouse_cortex_annotated.RData")
library(Seurat)
#> Attaching SeuratObject
visium.brain
#> An object of class Seurat 
#> 1298 features across 1073 samples within 3 assays 
#> Active assay: SCT (648 features, 260 variable features)
#>  2 other assays present: Spatial, predictions
#>  2 dimensional reductions calculated: pca, umap
# show the image and annotated spots
SpatialDimPlot(visium.brain, label = T, label.size = 3, cols = scPalette(nlevels(visium.brain)))
#> Scale for 'fill' is already present. Adding another scale for 'fill', which
#> will replace the existing scale.

在这里插入图片描述

# Prepare input data for CelChat analysis
data.input = GetAssayData(visium.brain, slot = "data", assay = "SCT") # normalized data matrix
meta = data.frame(labels = Idents(visium.brain), row.names = names(Idents(visium.brain))) # manually create a dataframe consisting of the cell labels
unique(meta$labels) # check the cell labels
#> [1] L2/3 IT Astro   L6b     L5 IT   L6 IT   L6 CT   L4      Oligo  
#> Levels: Astro L2/3 IT L4 L5 IT L6 IT L6 CT L6b Oligo

# load spatial imaging information
# Spatial locations of spots from full (NOT high/low) resolution images are required
spatial.locs = GetTissueCoordinates(visium.brain, scale = NULL, cols = c("imagerow", "imagecol")) 
# Scale factors and spot diameters of the full resolution images 
scale.factors = jsonlite::fromJSON(txt = file.path("/Users/jinsuoqin/Mirror/CellChat/tutorial/spatial_imaging_data_visium-brain", 'scalefactors_json.json'))
scale.factors = list(spot.diameter = 65, spot = scale.factors$spot_diameter_fullres, # these two information are required
                     fiducial = scale.factors$fiducial_diameter_fullres, hires = scale.factors$tissue_hires_scalef, lowres = scale.factors$tissue_lowres_scalef # these three information are not required
)
# USER can also extract scale factors from a Seurat object, but the `spot` value here is different from the one in Seurat. Thus, USER still needs to get the `spot` value from the json file. 

###### Applying to different types of spatial imaging data ######
# `spot.diameter` is dependent on spatial imaging technologies and `spot` is dependent on specific datasets

创建一个 CellChat 对象

用户可以从数据矩阵或 Seurat 创建一个新的 CellChat 对象。如果输入是一个 Seurat 对象,默认情况下将使用对象中的元数据,并且 USER 必须提供 group.by以定义单元格组。例如,对于 Seurat 对象中的默认细胞身份,group.by = “ident”。

注意:如果用户加载以前计算的 CellChat 对象(版本 < 1.6.0),请通过以下方式更新对象 updateCellChat

cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels",
                           datatype = "spatial", coordinates = spatial.locs, scale.factors = scale.factors)
#> [1] "Create a CellChat object from a data matrix"
#> Create a CellChat object from spatial imaging data... 
#> Set cell identities for the new CellChat object 
#> The cell groups used for CellChat analysis are  Astro L2/3 IT L4 L5 IT L6 IT L6 CT L6b Oligo
cellchat
#> An object of class CellChat created from a single dataset 
#>  648 genes.
#>  1073 cells. 
#> CellChat analysis of spatial data! The input spatial locations are 
#>                    imagerow imagecol
#> AAACAGAGCGACTCCT-1     3164     7950
#> AAACCGGGTAGGTACC-1     6517     3407
#> AAACCGTTCGTCCAGG-1     7715     4371
#> AAACTCGTGATATAAG-1     4242     9258
#> AAAGGGATGTAGCAAG-1     4362     5747
#> AAATAACCATACGGGA-1     3164     7537

设置配体-受体相互作用数据库

我们的数据库 CellChatDB 是一个人工管理的数据库,包含文献支持的人类和小鼠配体-受体相互作用。小鼠中的 CellChatDB 包含 2,021 个经过验证的分子相互作用,包括 60% 的分泌自分泌/旁分泌信号相互作用、21% 的细胞外基质 (ECM)-受体相互作用和 19% 的细胞-细胞接触相互作用。CellChatDB 在人类中包含 1,939 个经过验证的分子相互作用,包括 61.8% 的旁分泌/自分泌信号相互作用、21.7% 的细胞外基质 (ECM)-受体相互作用和 16.5% 的细胞-细胞接触相互作用。

用户可以通过添加自己精选的配体-受体对来更新 CellChatDB。请查看我们的教程了解如何操作。

CellChatDB <- CellChatDB.mouse # use CellChatDB.human if running on human data

# use a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling
# use all CellChatDB for cell-cell communication analysis
# CellChatDB.use <- CellChatDB # simply use the default CellChatDB

# set the used database in the object
cellchat@DB <- CellChatDB.use

预处理细胞间通讯分析的表达数据

为了推断特定于细胞状态的通讯,我们在一个细胞群中识别出过表达的配体或受体,然后在配体或受体过表达时识别过表达的配体-受体相互作用。

我们还提供了将基因表达数据投射到蛋白质-蛋白质相互作用 (PPI) 网络上的功能。具体来说,扩散过程用于根据在高置信度实验验证的蛋白质-蛋白质网络中定义的邻居基因的表达值来平滑基因的表达值。此功能在分析具有浅测序深度的单细胞数据时非常有用,因为投影减少了信号基因的丢失效应,特别是对于配体/受体亚基的可能零表达。人们可能会担心这种扩散过程可能引入的人工制品,但是,它只会引入非常微弱的通信。USERS 也可以跳过这一步,raw.use = TRUE在函数中设置computeCommunProb()。

# subset the expression data of signaling genes for saving computation cost
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
future::plan("multiprocess", workers = 4) # do parallel
#> Warning: Strategy 'multiprocess' is deprecated in future (>= 1.20.0). Instead,
#> explicitly specify either 'multisession' or 'multicore'. In the current R
#> session, 'multiprocess' equals 'multisession'.
#> Warning in supportsMulticoreAndRStudio(...): [ONE-TIME WARNING] Forked
#> processing ('multicore') is not supported when running R from RStudio
#> because it is considered unstable. For more details, how to control forked
#> processing or not, and how to silence this warning in future R sessions, see ?
#> parallelly::supportsMulticore
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
 
# project gene expression data onto PPI (Optional: when running it, USER should set `raw.use = FALSE` in the function `computeCommunProb()` in order to use the projected data)
# cellchat <- projectData(cellchat, PPI.mouse)

第二部分:细胞间通信网络的推断

CellChat 通过为每个交互分配一个概率值并执行排列测试来推断具有生物学意义的细胞间通讯。CellChat 通过将基因表达与空间位置以及使用质量作用定律的信号配体、受体及其辅因子之间相互作用的先前已知知识相结合来模拟细胞间通信的可能性。

推断的配体-受体对的数量显然取决于 计算每个细胞群的平均基因表达的方法。由于当前空间成像技术的灵敏度较低,我们建议使用 10%truncated mean来计算平均基因表达。默认的“trimean”方法产生较少的交互,并且可能会错过低表达的信号。在 中computeCommunProb,我们提供了使用不同方法计算平均基因表达的选项。值得注意的是,“trimean”接近 25% 的截断平均值,这意味着如果一组中表达细胞的百分比小于 25%,则平均基因表达为零。要使用 10% 截断均值,用户可以设置 type = "truncatedMean"和trim = 0.1。功能computeAveExpr可以帮助检查感兴趣的信号基因的平均表达,例如, computeAveExpr(cellchat, features = c(“CXCL12”,“CXCR4”), type = “truncatedMean”, trim = 0.1)。

计算通信概率并推断蜂窝通信网络

要快速检查推理结果,用户可以 nboot = 20在 中设置computeCommunProb。那么“pvalue < 0.05”意味着没有一个排列结果大于观察到的通信概率。

如果未预测所研究生物过程中众所周知的信号通路,用户可以尝试truncatedMean使用较低的值trim来更改计算每个细胞组的平均基因表达的方法。

scale.distance 用户在处理来自其他空间成像技术的数据时可能需要调整参数。请通过详细查看文档 ?computeCommunProb。

cellchat <- computeCommunProb(cellchat, type = "truncatedMean", trim = 0.1, 
                               distance.use = TRUE, interaction.length = 200, scale.distance = 0.01)
#> truncatedMean is used for calculating the average gene expression per cell group. 
#> [1] ">>> Run CellChat on spatial imaging data using distances as constraints <<< [2022-11-12 07:49:23]"
#> The suggested minimum value of scaled distances is in [1,2], and the calculated value here is  1.30553 
#> [1] ">>> CellChat inference is done. Parameter values are stored in `object@options$parameter` <<< [2022-11-12 08:10:42]"

# Filter out the cell-cell communication if there are only few number of cells in certain cell groups
cellchat <- filterCommunication(cellchat, min.cells = 10)

在信号通路水平上推断细胞间通讯

CellChat 通过汇总与每个信号通路相关的所有配体-受体相互作用的通信概率,计算信号通路水平上的通信概率。

注意:每个配体-受体对和每个信号通路的推断细胞间通信网络分别存储在插槽“net”和“netP”中。

cellchat <- computeCommunProbPathway(cellchat)

计算聚合的细胞间通信网络

我们可以通过计算链路数或汇总通信概率来计算聚合的细胞间通信网络。sources.useUSER 还可以通过设置和 来 计算小区组子集之间的聚合网络targets.use。

cellchat <- aggregateNet(cellchat)

我们还可以可视化聚合的细胞间通信网络。例如,使用圆形图显示任意两个单元格组之间的交互次数或总交互强度(权重)。

groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd=TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = rowSums(cellchat@net$count), weight.scale = T, label.edge= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = rowSums(cellchat@net$weight), weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")

在这里插入图片描述

第三部分:细胞间通信网络的可视化

在推断细胞间通信网络后,CellChat 为进一步的数据探索、分析和可视化提供了各种功能。这里我们只展示circle plot和新的spatial plot。

不同级别的细胞间通信可视化:可以使用 可视化信号通路的推断通信网络netVisual_aggregate,并使用 可视化与该信号通路相关的各个 LR 对的推断通信网络netVisual_individual。

这里我们以一个信号通路的输入为例。可以访问显示重要通信的所有信号通路 cellchat@netP$pathways。

pathways.show <- c("CXCL") 
# Circle plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle")

在这里插入图片描述

# Spatial plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "spatial", edge.width.max = 2, vertex.size.max = 1, alpha.image = 0.2, vertex.label.cex = 3.5)

在这里插入图片描述
计算并可视化网络中心性分数:

# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
par(mfrow=c(1,1))
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)

在这里插入图片描述

# USER can visualize this information on the spatial imaging, e.g., bigger circle indicates larger incoming signaling
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "spatial", edge.width.max = 2, alpha.image = 0.2, vertex.weight = "incoming", vertex.size.max = 3, vertex.label.cex = 3.5)

在这里插入图片描述
注意:根据空间成像数据推断细胞间通信网络,CellChat 的各种功能可用于进一步的数据探索、分析和可视化。请检查名为的基本教程中的其他功能 CellChat-vignette.html

第五部分:保存 CellChat 对象

saveRDS(cellchat, file = "cellchat_visium_mouse_cortex.rds")
sessionInfo()
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] SeuratObject_4.0.4  Seurat_4.0.6        patchwork_1.1.1    
#> [4] CellChat_1.6.0      Biobase_2.54.0      BiocGenerics_0.40.0
#> [7] ggplot2_3.3.5       igraph_1.3.4        dplyr_1.0.7        
#> 
#> loaded via a namespace (and not attached):
#>   [1] backports_1.4.1       circlize_0.4.13       systemfonts_1.0.2    
#>   [4] NMF_0.23.0            plyr_1.8.6            lazyeval_0.2.2       
#>   [7] splines_4.1.2         BiocParallel_1.28.3   listenv_0.8.0        
#>  [10] scattermore_0.7       ggnetwork_0.5.10      gridBase_0.4-7       
#>  [13] digest_0.6.29         foreach_1.5.1         htmltools_0.5.2      
#>  [16] magick_2.7.3          ggalluvial_0.12.3     fansi_0.5.0          
#>  [19] magrittr_2.0.1        tensor_1.5            cluster_2.1.2        
#>  [22] doParallel_1.0.16     ROCR_1.0-11           sna_2.6              
#>  [25] ComplexHeatmap_2.10.0 globals_0.14.0        matrixStats_0.61.0   
#>  [28] svglite_2.0.0         spatstat.sparse_2.1-0 colorspace_2.0-2     
#>  [31] ggrepel_0.9.1         xfun_0.33             crayon_1.4.2         
#>  [34] jsonlite_1.7.2        spatstat.data_2.1-2   survival_3.2-13      
#>  [37] zoo_1.8-9             iterators_1.0.13      glue_1.6.0           
#>  [40] polyclip_1.10-0       registry_0.5-1        gtable_0.3.0         
#>  [43] leiden_0.3.9          GetoptLong_1.0.5      car_3.0-12           
#>  [46] future.apply_1.8.1    shape_1.4.6           abind_1.4-5          
#>  [49] scales_1.1.1          DBI_1.1.2             rngtools_1.5.2       
#>  [52] rstatix_0.7.0         miniUI_0.1.1.1        Rcpp_1.0.7           
#>  [55] viridisLite_0.4.0     xtable_1.8-4          clue_0.3-60          
#>  [58] spatstat.core_2.3-2   reticulate_1.22       stats4_4.1.2         
#>  [61] htmlwidgets_1.5.4     httr_1.4.2            FNN_1.1.3            
#>  [64] RColorBrewer_1.1-2    ellipsis_0.3.2        ica_1.0-2            
#>  [67] farver_2.1.0          pkgconfig_2.0.3       uwot_0.1.11          
#>  [70] deldir_1.0-6          sass_0.4.0            utf8_1.2.2           
#>  [73] labeling_0.4.2        later_1.3.0           tidyselect_1.1.1     
#>  [76] rlang_0.4.12          reshape2_1.4.4        munsell_0.5.0        
#>  [79] tools_4.1.2           generics_0.1.1        statnet.common_4.5.0 
#>  [82] broom_0.7.10          ggridges_0.5.3        evaluate_0.17        
#>  [85] stringr_1.4.0         fastmap_1.1.0         goftest_1.2-3        
#>  [88] yaml_2.2.1            knitr_1.40            fitdistrplus_1.1-6   
#>  [91] purrr_0.3.4           RANN_2.6.1            nlme_3.1-153         
#>  [94] pbapply_1.5-0         future_1.23.0         mime_0.12            
#>  [97] compiler_4.1.2        plotly_4.10.0         png_0.1-7            
#> [100] ggsignif_0.6.3        spatstat.utils_2.3-0  tibble_3.1.6         
#> [103] bslib_0.3.1           stringi_1.7.6         highr_0.9            
#> [106] RSpectra_0.16-0       lattice_0.20-45       Matrix_1.3-4         
#> [109] vctrs_0.3.8           pillar_1.6.4          lifecycle_1.0.1      
#> [112] spatstat.geom_2.3-1   lmtest_0.9-39         jquerylib_0.1.4      
#> [115] GlobalOptions_0.1.2   RcppAnnoy_0.0.19      BiocNeighbors_1.12.0 
#> [118] data.table_1.14.2     cowplot_1.1.1         irlba_2.3.5          
#> [121] httpuv_1.6.4          R6_2.5.1              promises_1.2.0.1     
#> [124] network_1.17.1        gridExtra_2.3         KernSmooth_2.23-20   
#> [127] IRanges_2.28.0        parallelly_1.30.0     codetools_0.2-18     
#> [130] MASS_7.3-54           assertthat_0.2.1      pkgmaker_0.32.2      
#> [133] rjson_0.2.20          withr_2.4.3           sctransform_0.3.2    
#> [136] S4Vectors_0.32.3      mgcv_1.8-38           parallel_4.1.2       
#> [139] rpart_4.1-15          grid_4.1.2            tidyr_1.1.4          
#> [142] coda_0.19-4           rmarkdown_2.17        carData_3.0-4        
#> [145] Rtsne_0.15            ggpubr_0.4.0          shiny_1.7.1
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值