单细胞轨迹分析-monocle包的使用

时间:2025-02-09 12:22:56

探序基因肿瘤研究院 整理

安装:

monocle源码下载:/packages/release/bioc/html/

R版本,4.2.0

BiocManager::install("monocle")

不过在安装过程中还是报错了:

Warning: 无法在/packages/3.15/bioc/src/contrib中读写索引:

  无法打开URL'/packages/3.15/bioc/src/contrib/PACKAGES'

Bioconductor version 3.15 (BiocManager 1.30.18), R 4.2.0 (2022-04-22)

Installing package(s) 'monocle'

Warning: 没有'‘qlcMatrix’'这种相依关系

还安装相依关系‘RBGL’, ‘HSMMSingleCell’, ‘biocViews’

于是单独安装RBGL:

BiocManager::install("RBGL")

下载程序包‘RBGL’时出了问题

Installation paths not writeable, unable to update packages

  path: /usr/local/lib64/R/library

然后:

> BiocManager::install("RBGL")

Warning: 无法在貯藏處/packages/3.15/bioc/src/contrib中读写索引:

  无法打开URL'/packages/3.15/bioc/src/contrib/PACKAGES'

Bioconductor version 3.15 (BiocManager 1.30.18), R 4.2.0 (2022-04-22)

Installing package(s) 'RBGL'

还安装相依关系‘graph’

试开URL’/packages/3.15/bioc/src/contrib/graph_1.74.'

发现下载速度慢,于是到/packages/release/bioc/html/下载,再:

R CMD INSTALL graph_1.80.,安装成功。RBGL同样下载,再安装

R CMD INSTALL RBGL_1.78.,安装成功。

其他依赖的包都能装好,就差qlcMatrix,找到线索:/web/packages/qlcMatrix/,提示:

Package ‘qlcMatrix’ was removed from the CRAN repository.

Formerly available versions can be obtained from thearchive.

Archived on 2023-11-29 as issues were not corrected in time.

下载了qlcMatrix_0.9.。最后R CMD INSTALL monocle_2.30.

根据网上报道,安装monocle经常有错,比如R版本太高。

使用:

重要:构建CDS对象,所需要的3个输入文件:表达矩阵信息、基因信息和表型信息。

注意:Seurat为将基因表达矩阵,使用了Seurat包处理成的Seurat结构的一个变量

Mat <- Seurat@assays$RNA@counts

  p_data <- Seurat@

  p_data$celltype <- Seurat@

  f_data <- (gene_short_name = (Mat), = (Mat))

#注意,表达矩阵Mat的细胞名字和数量要和p_data一致。表达矩阵Mat的基因名字和数量要和f_data一致。

  pd <- new('AnnotatedDataFrame', data = p_data)

  fd <- new('AnnotatedDataFrame', data = f_data)

  cds <- newCellDataSet(Mat,phenoData = pd,featureData = fd,lowerDetectionLimit = 0.5,expressionFamily = ())

  cds <- estimateSizeFactors(cds)

  cds <- estimateDispersions(cds)

  express_genes <- VariableFeatures(Seurat)

  cds<- setOrderingFilter(cds, express_genes)

  cds <- reduceDimension(cds,max_components = 2,method = 'DDRTree')

  cds <- orderCells(cds)

画图:

plot_cell_trajectory(cds,color_by="Pseudotime",size=1,show_backbone=TRUE)

其他更多的图,可以参照-【单细胞轨迹分析】monocle2

相关报错:

> cds <- orderCells(cds)

Warning messages:

1: In (dp_mst, root = root_cell, neimode = "all", unreachable = FALSE,  :

  Argument `neimode' is deprecated; use `mode' instead

2: In (dp_mst, root = root_cell, neimode = "all", unreachable = FALSE,  :

  Argument `neimode' is deprecated; use `mode' instead

参考:

简书-【单细胞轨迹分析】monocle2