# #——回声= FALSE ------------------------------------------------------------ 库(knitr ) ## ---- 警告= F,消息= F ---------------------------------------------------- 库(tradeSeq)图书馆(RColorBrewer)图书馆(SingleCellExperiment) #再现性调色板(布鲁尔。“Dark2”)朋友(8日)数据(countMatrix、包=“tradeSeq”)计数< - as.matrix countMatrix rm (countMatrix)数据(celltype、包= " tradeSeq ") ## ---- eval = FALSE ------------------------------------------------------------ # set.seed(22) #库(monocle3) # # # cd < -创建一个cell_data_set对象new_cell_data_set(计数,cell_metadata = pd, # gene_metadata = data.frame (gene_short_name = rownames(计数)# row.names = rownames(计数)))# # # PCA然后UMAP运行数据cd < - preprocess_cds (cd,方法= PCA) # cd <——reduce_dimension (cd, preprocess_method =“主成分分析”,# reduction_method =“UMAP”)# # #第一次显示,色素细胞类型从保罗等人# plot_cells (cd, label_groups_by_cluster = FALSE, cell_size = 1, # color_cells_by =“cellType”)# # #运行聚类方法。这对于构造图形是必要的# cds <- cluster_cells(cds, reduction_method = "UMAP") # #可视化集群# plot_cells(cds, color_cells_by = "cluster", cell_size = 1) # # #构造图形# #注意,对于其余的代码要运行,图形应该是完全连接的# cds <- learn_graph(cds,use_partition = FALSE) # # #我们找到所有靠近起点的单元格# cell_ids <- colnames(cds)[pd$cellType == "Multipotent progenitors"] # closest_vertex <- cds@principal_graph_aux[["UMAP"]]$pr_graph_cell_proj_closest_vertex # closest_vertex <- as.matrix(closest_vertex[colnames(cds),]) # closest_vertex <- closest_vertex[cell_ids,]# closest_vertex <- as.numeric(names(where .max(table(closest_vertex)))) # mst <- principal_graph(cds)$UMAP # root_pr_nodes <- igraph::V(mst)$name[closest_vertex] # # #我们计算轨迹# cds <- order_cells(cds, root_pr_nodes = root_pr_nodes) # plot_cells(cds,color_cells_by = "拟时间 ") ## ---- eval = FALSE ------------------------------------------------------------ # 库(magrittr) # #每个细胞获得最接近顶点# y_to_cells < - principal_graph_aux (cds) UMAP pr_graph_cell_proj_closest_vertex美元% > % # as.data.frame () # y_to_cells细胞< - rownames (y_to_cells) # y_to_cells Y < - y_to_cells V1 # # #美元得到根顶点# #这是上面的节点一样#根< - cds@principal_graph_aux UMAP root_pr_nodes美元# # # #其他端点Endpoints <- names(where(金格::degree(mst) == 1)) # Endpoints <- Endpoints [!端点% %根)为每个端点# # # # cellWeights < -拉普(端点函数(端点){# #我们发现端点之间的路径和根#路径< - igraph:: shortest_paths (mst,根,端点)$ vpath[[1]] #路径< - as.character(路径)# #我们沿着这条路找到地图的细胞# df < - y_to_cells [y_to_cells Y % %路径中,美元]# df < - data.frame(权重= as.numeric (colnames (cds) % % df $细胞))# colnames (df) < -端点#返回(df ) # }) %>% 做的。调用(=“cbind”什么,arg游戏 = .) %>% # as.matrix () # rownames (cellWeights) < - colnames (cds) #拟时间< -矩阵(拟时间(cds), ncol = ncol (cellWeights), # nrow = ncol (cds), byrow = FALSE ) ## ---- eval = FALSE ------------------------------------------------------------ # 南加州爱迪生公司< fitGAM(数量=计数,#拟时间=拟时间,# cellWeights = cellWeights ) ## ----------------------------------------------------------------------------- sessionInfo ()