與其他單細胞分析工具包的接口
- 從Seurat或SingleCellExperiment對象創(chuàng)建CellChat對象
- 根據(jù)從Seurat和Scanpy工具中提取的數(shù)據(jù)矩陣創(chuàng)建CellChat對象
從Seurat或SingleCellExperiment對象創(chuàng)建CellChat對象
從CellChat版本0.5.0開始,USERS可以從Seurat或SingleCellExperiment對象創(chuàng)建新的CellChat對象毫痕。桅滋。如果輸入是Seurat或SingleCellExperiment對象沐兰,則默認情況下將使用該對象中的元數(shù)據(jù)趋翻,并且USER必須提供group.by
以定義單元格組芹壕。例如窟绷,group.by =“ ident”用于Seurat對象中的默認單元格標識锯玛。
請通過查閱文檔中的示例以createCellChat
獲取詳細信息help(createCellChat)
。
注意:如果用戶加載先前計算的CellChat對象(版本<0.5.0)兼蜈,請通過 updateCellChat
在單單元格對象之間轉(zhuǎn)換(Seurat攘残,SingleCellExperiment和andata對象)
有幾種出色的工具可在Seurat對象,SingleCellExperiment對象和andata對象之間進行轉(zhuǎn)換为狸。這是兩個示例:一個是Satija Lab的Seurat R軟件包肯腕,另一個是Theis Lab的zellkonverter R軟件包。
根據(jù)從Seurat和Scanpy工具中提取的數(shù)據(jù)矩陣創(chuàng)建CellChat對象
下面我們展示了如何從其他現(xiàn)有的單細胞分析工具包(包括Seurat和Scanpy)中將CellChat輸入文件提取為數(shù)據(jù)矩陣钥平。
CellChat中需要的數(shù)據(jù)輸入
CellChat需要兩個用戶輸入:一個是細胞的基因表達數(shù)據(jù)实撒,另一個是用戶分配的細胞標簽(即基于標簽的模式)或單細胞數(shù)據(jù)的低維表示形式(即無標簽)模式)姊途。對于后者,CellChat通過基于低維空間或偽時間軌跡空間中的單元格距離構(gòu)建共享的鄰居圖來自動對單元格進行分組知态。
資料格式
對于基因表達數(shù)據(jù)矩陣捷兰,基因應(yīng)在具有行名的行中以及單元格在具有名的列中。需要進行歸一化的數(shù)據(jù)作為CellChat分析的輸入负敏,例如贡茅,庫大小歸一化,然后以偽計數(shù)1進行對數(shù)轉(zhuǎn)換其做。如果用戶提供了計數(shù)數(shù)據(jù)顶考,我們將提供一個normalizeData
函數(shù)來計算庫大小。
對于單元組信息妖泄,需要具有行名的數(shù)據(jù)框作為CellChat的輸入驹沿。
從Seurat V3對象中提取CellChat輸入文件
可以從Seurat對象獲得歸一化的計數(shù)數(shù)據(jù)和細胞組信息,方法是:
data.input <- GetAssayData(seurat_object, assay = "RNA", slot = "data") # normalized data matrix
labels <- Idents(seurat_object)
meta <- data.frame(group = labels, row.names = names(labels)) # create a dataframe of the cell labels
從Seurat V2對象中提取CellChat輸入文件
可以從Seurat對象獲得歸一化的計數(shù)數(shù)據(jù)和細胞組信息蹈胡,方法是:
data.input <- seurat_object@data # normalized data matrix
labels <- seurat_object@idents
meta <- data.frame(group = labels, row.names = names(labels)) # create a dataframe of the cell labels
從Scanpy對象中提取CellChat輸入文件
anndata提供了一個python類渊季,可用于存儲單單元格數(shù)據(jù)。此數(shù)據(jù)格式還用于在scanpy軟件包中進行存儲罚渐。我們首先使用reticulate包將數(shù)據(jù)讀入R中却汉,以導(dǎo)入andata模塊。
library(reticulate)
ad <- import("anndata", convert = FALSE)
ad_object <- ad$read_h5ad("scanpy_object.h5ad")
# access normalized data matrix
data.input <- t(py_to_r(ad_object$X))
rownames(data.input) <- rownames(py_to_r(ad_object$var))
colnames(data.input) <- rownames(py_to_r(ad_object$obs))
# access meta data
meta.data <- py_to_r(ad_object$obs)
meta <- meta.data
提取所需的CellChat輸入文件后荷并,然后創(chuàng)建一個CellChat對象并開始分析合砂。
使用數(shù)據(jù)矩陣作為輸入創(chuàng)建一個CellChat對象
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
將單元格信息添加到對象的元插槽中
如果在創(chuàng)建CellChat對象時未添加單元格mata信息,則USERS也可以稍后使用添加該信息addMeta
源织,并使用設(shè)置默認單元格標識setIdent
既穆。
cellchat <- addMeta(cellchat, meta = meta, meta.name = "labels")
cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity
levels(cellchat@idents) # show factor levels of the cell labels