1 Prepare required input data for CellChat analysis
使用cellchat进行分析时,有两种数据输入类型:一种是细胞的基因表达数据,另一种是用户分配的细胞标签。
1 gene expression data matrix:基因位于矩阵的行上,并且有对应的行名;细胞位于矩阵的列上,并且有对应的列名
2 Create a CellChat object
CellChat包的使用需要以下两种输入:
1、细胞的基因表达数据(测序结果)
2、细胞标签(用户提供,通常来源于数据库)
对于第一种基因表达数据,我们已经很熟悉了,就是一个矩阵,矩阵的行是genes,矩阵的列是cells。输入进去的数据一般是进行了初步处理的数据,即数据应为归一化数据 (normalized data): 已进行library-size归一化并用伪计数1进行log转换。如果是原始计数数据(count data),CellChat提供normalizeData
函数来进行处理,然后就可以得到归一化数据。
一、导入四种对象
1、原始数据对象:
ptm = Sys.time()
# Here we load a scRNA-seq data matrix and its associated cell meta data
# This is a combined data from two biological conditions: normal and diseases
load("/Users/suoqinjin/Library/CloudStorage/OneDrive-Personal/works/CellChat/tutorial/data_humanSkin_CellChat.rda")
data.input = data_humanSkin$data # normalized data matrix
meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data
cell.use = rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
# Subset the input data for CelChat analysis
data.input = data.input[, cell.use]
meta = meta[cell.use, ]
# meta = data.frame(labels = meta$labels[cell.use], row.names = colnames(data.input)) # manually create a dataframe consisting of the cell labels
unique(meta$labels) # check the cell labels
#> [1] Inflam. FIB FBN1+ FIB APOE+ FIB COL11A1+ FIB cDC2
#> [6] LC Inflam. DC cDC1 CD40LG+ TC Inflam. TC
#> [11] TC NKT
#> 12 Levels: APOE+ FIB FBN1+ FIB COL11A1+ FIB Inflam. FIB cDC1 cDC2 ... NKT
直接导入了.rda文件,这里面的数据是已经normalized的形式,可以直接用于cellchat分析
2、Seurat对象:
data.input <- seurat_object[["RNA"]]@data # normalized data matrix
# For Seurat version >= “5.0.0”, get the normalized data via `seurat_object[["RNA"]]$data`
labels <- Idents(seurat_object)
meta <- data.frame(labels = labels, row.names = names(labels)) # create a dataframe of the cell labels
这里展现了用非常流行的R包seurat包来分析的过程,具体展示了如何从seurat对象中提取所需的数据:
- 使用