Seurat, SeuratObject and Matrix version issue

2023-11-21 04:38:22 浏览数 (3)

如果你在安装和使用Seurat (v5) and SeuratObject (v5) 过程中,出现了一些关于Matrix package的问题,可以看看本文。

我使用的是macOS, x86_64

1) SueratObject v5.0.0是基于Matrix 1.6-1 package的,所以我在CRAN官网:https://cran.r-project.org/web/packages/Matrix/index.html 下载了安装包, 官网有两个1.6-1 版本。我估计是针对macOS and windows的。 我首先下载了: Matrix 1.6-1.1.tar.gz.

While it can be successfully installed in Rstudio, we can't use library(Seurat) and library(SeuratObject).

代码语言:txt复制
library(Seurat)
library(SeuratObject)
Error: package or namespace load failed for ‘SeuratObject’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/jiajia/Library/R/x86_64/4.1/library/Matrix/libs/Matrix.so':

2) 所以我又下载了另一个1.6-1版本(Matrix_1.6-1.tar.gz)。 当我按照上述方法安装的时候,却出现·了如下报错:

代码语言:txt复制
Error: compilation failed for package ‘Matrix’ 
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(我暂时没有理会这样的报错,我当时也不知道解决的办法。)

3) 我试了一下Matrix 1.6-2版本是不是可以兼容。所以我又下载了1.6-2 version (Matrix_1.6-2.tar.gz). 我发现1.6-2版本可以正常安装。当我们library(Seurat), it shows below info:

代码语言:txt复制
library(Seurat)
‘SeuratObject’ was built with package ‘Matrix’ 1.6.1.1 but the current version is 1.6.2; it is recommended that you reinstall ‘SeuratObject’ as the ABI
for ‘Matrix’ may have changed.

因为不是error,所以我没有理会这些内容。当我继续下游代码的时候,报错出现了:

代码语言:txt复制
brain <- CreateSeuratObject(counts = brain.mat)
Error in validObject(.Object) : 
  invalid class “LogMap” object: superclass "mMatrix" not defined in the environment of the object's class.

我Google了这样的报错,提示是Matrix版本的问题。所以事情又回到了起点,还是需要安装Matrix 1.6-1.

4). 所以我得回到2)的位置,考虑一下compilation的问题

代码语言:txt复制
Error: compilation failed for package "Matrix"

通过搜索,我发现R包有时候是需要编译器的 (这里我不知道描述的是否准确,本身不涉及这个方向,如有错误,请指正),如Xcode and Fortran。 而Matrix package就需要Fortran compiler,我电脑没有安装,所以我需要安装fortran编译器。

5). 安装fortran 编译器:(link: https://cran.r-project.org/bin/macosx/tools/)

Download Fortran compiler tool: (根据自己的R版本和电脑系统,下载合适的version。在这个过程中,需要一再强调R版本和电脑系统版本。这个很重要。。。。)

代码语言:txt复制
我下载的是 gfortran-4.2.3.pkg
Install this tool by default step by step.

After installation, open /User/jiajia/.R/Makevars file and add below contents using mac terminal:

代码语言:txt复制
#CC=/Users/shaol2/homebrew/Cellar/llvm/17.0.4/bin/clang-17
#CXX=/Users/shaol2/homebrew/Cellar/llvm/17.0.4/bin/clang  
#CFLAGS=-I/Users/shaol2/homebrew/Cellar/hdf5/1.14.3/include
#CXXFLAGS=-I/Users/shaol2/homebrew/Cellar/hdf5/1.14.3/include
#LDFLAGS=-L/Users/shaol2/homebrew/Cellar/hdf5/1.14.3/lib
FC = /opt/gfortran/bin/gfortran
FLIBS = -L/opt/gfortran/lib/gcc/x86_64-apple-darwin20.0/12.2.0 -L/opt/gfortran/lib -lgfortran -lquadmath
(Content starts with # is already exist in my Makevars file. I just added FC and FLIBS)

After this step, I successfully installed Matrix package downloaded from CRAN website (1.6-1 version, it shows the name: Matrix_1.6-1.tar.gz). Also, downstream analysis is fine without any errors.

6). Tips:

代码语言:txt复制
1. restart R session sometimes when you installed new packages;
2. know your R version, computer system;
3. check package version:
Biobase::package_version("ggplot2")
4. 认真对待每一个error,试图去想办法解决。

0 人点赞