velocyto.RをMacにインストールする時の注意点

velocytoは、scRNA-seqデータでRNA velocity解析をするソフトウェアです。遺伝子のエキソンとイントロンに当たるリードの量から各細胞のRNA velocityを推定します。

velocytoの開発者は、pythonの実装であるvelocyto.py、Rの実装であるvelocyto.Rを提供しています。

このうち、velocyto.RをMacにインストールしようとしたところトラブルに見舞われたので、回避方法をメモします。なお、環境は macOS High Sierra Version 10.13.6、R version 3.6.0です。

エラー1: clang++のオプション

velocyto.Rはinstall_github()でインストールしますが、以下のようなエラーが出ました。

> library(devtools)
> install_github("velocyto-team/velocyto.R")
Downloading GitHub repo velocyto-team/velocyto.R@master
Your system is ready to build packages!
Skipping 1 packages not available: pcaMethods
✔  checking for file ‘/private/var/folders/q_/7mb82w5s3bs_3d6pryznm4nc0000gn/T/RtmpOJfiAm/remotes145c66cc7c245/velocyto-team-velocyto.R-d779034/DESCRIPTION’ ...
─  preparing ‘velocyto.R’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘velocyto.R_0.6.tar.gz’
  
* installing *source* package ‘velocyto.R’ ...
** using staged installation
** libs
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppArmadillo/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang: error: unsupported option '-fopenmp'
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘velocyto.R’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/velocyto.R’
Error: Failed to install 'velocyto.R' from GitHub:
 (converted from warning) installation of package ‘/var/folders/q_/7mb82w5s3bs_3d6pryznm4nc0000gn/T//RtmpOJfiAm/file145c66e0e8d4d/velocyto.R_0.6.tar.gz’ had non-zero exit status

調べてみると、Mac用のclang++でオプションがないことが原因のようでした。

(base) MacBook-Pro-6:~ haruka$ which clang++
/usr/bin/clang++
(base) MacBook-Pro-6:~ haruka$ clang++ --version
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
(base) MacBook-Pro-6:~ haruka$ clang++ --help | grep fopenmp
 -fopenmp-relocatable-target
 -fopenmp-simd           Emit OpenMP code only for SIMD-based constructs.
 -fopenmp-targets=<value>

そこで、clang++をhomebrewでインストールしました。こちらのサイトを参考にしました。

$ brew install llvm

libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.


For compilers to find libffi you may need to set:
 export LDFLAGS="-L/usr/local/opt/libffi/lib"


For pkg-config to find libffi you may need to set:
 export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"


==> llvm
To use the bundled libc++ please add the following LDFLAGS:
 LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"


llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.


If you need to have llvm first in your PATH run:
 echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile


For compilers to find llvm you may need to set:
 export LDFLAGS="-L/usr/local/opt/llvm/lib"
 export CPPFLAGS="-I/usr/local/opt/llvm/include"

このあとに、新しくHomebrewでインストールしたclang++にパスを通しました。

$ which clang++
/usr/bin/clang++
$ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ which clang++
/usr/local/opt/llvm/bin/clang++
$ clang++ --help | grep fopenmp
 -fopenmp-simd           Emit OpenMP code only for SIMD-based constructs.
 -fopenmp-targets=<value>
 -fopenmp                Parse OpenMP pragmas and generate parallel code.

エラー2:library not found for -lboost_filesystem

1つ目のエラーは消えましたが、新たなエラーが出てきます。

clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o velocyto.R.so RcppExports.o points_within.o routines.o -lboost_filesystem -lboost_system -lstdc++ -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -fopenmp -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: library not found for -lboost_filesystem

これもHomebrewでのインストールで解決します。

$ brew install boost

これで再度インストールしたらできました。

まとめ:velocyto.Rのインストール方法

$ brew install llvm
$ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
$ brew install boost
$ R
> library(devtools)
> install_github("velocyto-team/velocyto.R")


この記事が気に入ったらサポートをしてみませんか?