monocle 2擬時序分析

monocle做擬時序分析首先要構建CDS需要3個矩陣:expr.matrix、pd、fd,其次將Seurat中的對象轉換為monocle識別的對象。然後選擇想要做擬時序依據的基因就可以了,如果已知開始和結束的細胞,將過程開始時收集的細胞與結束時收集的細胞簡單地進行比較,並找到差異表達的基因,做擬時序依據的基因,根據時間點的差異分析選擇基因通常非常有效,但是如果我們沒有時間序列數據,可以選擇離散度和表達量高的基因。

library(monocle)  packageVersion("monocle")  #monocle構建CDS需要3個矩陣:expr.matrix、pd、fd  # 將Seurat中的對象轉換為monocle識別的對象  #cds <- importCDS(GetAssayData(seurat.object))  #選擇做擬時序的亞群  Mono_tj<-subset(seurat.object, idents = c(1,2,4,6,7))    Mono_matrix<-as(as.matrix(GetAssayData(Mono_tj,slot = "counts")), 'sparseMatrix')  #構建featuredata,一般featuredata需要兩個col,一個是gene_id,一個是gene_short_name,row對應counts的rownames  feature_ann<-data.frame(gene_id=rownames(Mono_matrix),gene_short_name=rownames(Mono_matrix))  rownames(feature_ann)<-rownames(Mono_matrix)  #  Mono_fd<-new("AnnotatedDataFrame", data = feature_ann)  #  #Seurat object中的@meta.data一般會存放表型相關的資訊如cluster、sample的來源、group等,所以選擇將metadata轉換為phenodata  sample_ann<[email protected]  #rownames(sample_ann)<-colnames(Mono_matrix)    Mono_pd<-new("AnnotatedDataFrame", data =sample_ann)  #build new cell data set  Mono.cds<-newCellDataSet(Mono_matrix,phenoData =Mono_pd,featureData =Mono_fd,expressionFamily=negbinomial.size())    #查看phenodata、featuredata  head(pData(Mono.cds))  head(fData(Mono.cds))  #預處理  Mono.cds <- estimateSizeFactors(Mono.cds)  Mono.cds <- estimateDispersions(Mono.cds)  #篩選基因,這裡可以根據自己的需要篩選特定的基因  disp_table <- dispersionTable(Mono.cds)  unsup_clustering_genes <- subset(disp_table, mean_expression >= 0.1)  Mono.cds <- setOrderingFilter(Mono.cds, unsup_clustering_genes$gene_id)  #用DDRtree 進行降維分析  Mono.cds <- reduceDimension(    Mono.cds,    max_components = 2,    method = 'DDRTree')  #計算psudotime值  Mono.cds <- orderCells(Mono.cds)  head(pData(Mono.cds))    plot_cell_trajectory(Mono.cds,cell_size = 1)

image.png

plot_cell_trajectory(Mono.cds, color_by = "Pseudotime")

image.png

plot_cell_trajectory(Mono.cds, color_by = "seurat_clusters",cell_size = 1)

image.png

歡迎關注~

參考:http://cole-trapnell-lab.github.io/monocle-release/docs/