对细胞亚群除了可以进行一些功能表型的刻画之外,借助monocle和CytoTRACE包,我们可以对细胞的分化潜能与分化轨迹进行预测,并探讨不同分化状态下细胞的表型。
第一步:导入所需的R包
library(scibet) library(Seurat) library(scater) library(scran) library(dplyr) library(Matrix) library(cowplot) library(ggplot2) library(harmony) library(monocle) library(CytoTRACE)
第二步:导入数据并创建CDS对象
cell_Subtype属性是在(三)中定义的细胞亚群
BRCA_SingleCell <- readRDS("/home/BRCA_SingleCell.RDS") allCells <- names(Idents(BRCA_SingleCell)) Idents(BRCA_SingleCell) <- "cell_Subtype" allType <- levels(Idents(BRCA_SingleCell))可能数据量太大,会导致伪时序过程中程序崩溃,因此可以选择采用下面的代码进行随机抽样
choose <- c() set.seed(123) for(i in allType){ cgCells <- allCells[(BRCA_SingleCell$cell_Subtype == i)] cg <- sample(cgCells, length(cgCells)*0.6) #这里选择总数据量的60%进行分析 choose <- c(choose, cg) } BRCA_SingleCell.random <- BRCA_SingleCell[,allCells %in% choose]构建CDS对象,用于后续分析
#提取表型信息--细胞信息 expr_matrix <- as(as.matrix(BRCA_SingleCell.random@assays$RNA@counts), 'sparseMatrix') #提取表型信息到p_data(phenotype_data)里面 p_data <- BRCA_SingleCell.random@meta.data #提取基因信息 f_data <- data.frame(data.frame(gene_short_name = row.names(BRCA_SingleCell.random), row.names = row.names(BRCA_SingleCell.random))) #expr_matrix的行数与f_data的行数相同(gene number),expr_matrix的列数与p_data的行数相同(cell number) #构建CDS对象 pd <- new('AnnotatedDataFrame', data = p_data) fd <- new('AnnotatedDataFrame', data = f_data) #将p_data和f_data从data.frame转换AnnotateDataFrame对象 monocle_cds <- newCellDataSet(expr_matrix, phenoData = pd, featureData = fd, lowerDetectionLimit = 0.5, expressionFamily = negbinomial.size())
第三步:以高可变基因作的表达趋势进行轨迹构建
monocle_cds <- estimateSizeFactors(monocle_cds) monocle_cds <- estimateDispersions(monocle_cds) monocle_cds <- detectGenes(monocle_cds, min_expr = 0.1) #在fData(cds)种添加一列num_cells_expressed print(head(fData(monocle_cds))) expressed_genes <- row.names(subset(fData(monocle_cds), num_cells_expressed >= 10)) #过滤掉在小于10个细胞种表达的基因 #输入差异或高变基因 Idents(BRCA_SingleCell.random) <- 'cell_Subtype' diff <- FindAllMarkers(BRCA_SingleCell.random,logfc.threshold = 0.5,only.pos = T,min.pct = 0.2) diff <- subset(diff,!grepl(pattern = 'RP[LS]',gene)) diff <- subset(diff,!grepl(pattern = 'MT-',gene)) head(diff) #轨迹构建基因可视化 ordergene <- row.names(diff) #选择用于排序的基因数目一般在2000左右比较合适 monocle_cds <- setOrderingFilter(monocle_cds, ordergene) #关键步骤:使用setOrderingFilter将它嵌入cds对象,后续的分析会使用这一list #然后将基因会被存储在cds@featureData@data[["use_for_ordering"]]中,可通过table(cds@featureData@data[["use_for_ordering"]])查看 plot_ordering_genes(monocle_cds) #使用反向图嵌入(DDRTree)算法对数据进行降维 monocle_cds <- reduceDimension(monocle_cds, max_components = 2, method = "DDRTree") #根据order gene的表达趋势,将细胞排序并完成轨迹构建 monocle_cds <- orderCells(monocle_cds) #使用root_state参数可以设置拟时序轴的根。如monocle_cds <- orderCells(monocle_cds, root_state = 5)
第四步:使用cytoTrace进行细胞亚群分化潜能打分
expr <- as.matrix(BRCA_SingleCell.random@assays$RNA@counts) results <- CytoTRACE(mat = expr, enableFast = F) pheno <- BRCA_SingleCell.random@meta.data$cell_Subtype pheno <- as.character(pheno) names(pheno) <- BRCA_SingleCell.random@assays$RNA@counts@Dimnames[[2]] options(repr.plot.height = 7.5, repr.plot.width = 16) plotCytoGenes(results, numOfGenes = 10) plotCytoTRAC
6158



被折叠的 条评论
为什么被折叠?



