## ----- echo = false -----------------------------------------------------------------------------------------------------------------库(Knitr)## ----警告= f,消息= f ------------------------------------------------------------------------------------------------------------------------------------------------库(Tradeseq)图书馆(rcolorbrewer)图书馆(SingleCellexperiment)#对于可重复性调色板(brewer.pal(8,“ dark2”))数据(countmatrix,package =“ tradeseq”)counts < - as.matrix(countmatrix)rm(countmatrix)rm(Countmatrix)data(cellType,package =“ traveSeq”)###----- eval = false -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- set.seed(22)#library(monocle3)##创建一个cell_data_set对象#cds <-new_cell_data_set(counts,cell_metadata = pd,#gene_metadata)= data.frame(gene_short_name = rownames(counts),#row.names = rownames(counts)))###在data#cds <-preprocess_cds(cds,method =“ pca”)上运行umap umapredy_dimension(cds,preprocess_method =“ pca”,#reduction_method =“ umap”)###########priont coloring by Paul et al#plot_cells(cds,cds,label_groups_by_cluste)r = 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)#plot_cells = 1)请注意,要运行该代码的其余部分,应完全连接该图#CDS < - Learn_graph(cds,use_partition = false)########################(cds)[pd $ cellType ==“ multipotent祖细胞”]#CLESSEST_VERTEX <-cds@principal_graph_aux [[“ umap”] $ pr_graph_cell_proj_closest_vertex_vertex#closest_vertex#-CESSCEST_VERTEX [cell_ids,]#clessest_vertex < - as.numeric(names(whe.max(table(clessest_vertex)))))#mst <-mstal_graph(cds)$ umap#umap#root_pr_nodes <-igraph <-igraph :: v(mst)$ names $ names $ names $ names $ name[closest_vertex] # # # We compute the trajectory # cds <- order_cells(cds, root_pr_nodes = root_pr_nodes) # plot_cells(cds, color_cells_by = "pseudotime") ## ---- eval = FALSE------------------------------------------------------------ # library(magrittr) # # Get the closest vertice for every cell # y_to_cells <- principal_graph_aux(cds)$UMAP$pr_graph_cell_proj_closest_vertex %>% # as.data.frame() # y_to_cells$cells <- rownames(y_to_cells) # y_to_cells$Y <- y_to_cells$V1 # # # Get the root vertices # # It is the same node as above # root <- cds@principal_graph_aux$UMAP$root_pr_nodes # # # Get the other endpoints # endpoints <- names(which(igraph::degree(mst) == 1)) # endpoints <- endpoints[!endpoints %in% root] # # # For each endpoint # cellWeights <- lapply(endpoints, function(endpoint) { # # We find the path between the endpoint and the root # path <- igraph::shortest_paths(mst, root, endpoint)$vpath[[1]] # path <- as.character(path) # # We find the cells that map along that path # df <- y_to_cells[y_to_cells$Y %in% path, ] # df <- data.frame(weights = as.numeric(colnames(cds) %in% df$cells)) # colnames(df) <- endpoint # return(df) # }) %>% do.call(what = 'cbind', args = .) %>% # as.matrix() # rownames(cellWeights) <- colnames(cds) # pseudotime <- matrix(pseudotime(cds), ncol = ncol(cellWeights), # nrow = ncol(cds), byrow = FALSE) ## ---- eval = FALSE------------------------------------------------------------ # sce <- fitGAM(counts = counts, # pseudotime = pseudotime, # cellWeights = cellWeights) ## ----------------------------------------------------------------------------- sessionInfo()