Python rpy2 加载 edgeR R 包时出错,但它已安装并在 R 中运行

Python rpy2 error loading edgeR R-package, but it is installed and working in R

我在 Python 中使用 rpy2 加载 R 包 edgeR 时遇到问题。

当我运行:

import rpy2.robjects as robjects

robjects.r('''
    library(edgeR)
''')

我收到以下错误:

/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/functions.py:106: UserWarning: Loading required package: limma

  res = super(Function, self).__call__(*new_args, **new_kwargs)
/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/functions.py:106: UserWarning: Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/data/scratch/user/source/anaconda/lib/R/library/edgeR/libs/edgeR.so':
  /data/scratch/user/source/anaconda/lib/R/library/edgeR/libs/edgeR.so: undefined symbol: _ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev

  res = super(Function, self).__call__(*new_args, **new_kwargs)
/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/functions.py:106: UserWarning: Error: package or namespace load failed for ‘edgeR’

  res = super(Function, self).__call__(*new_args, **new_kwargs)
Traceback (most recent call last):
  File "differential_expression.py", line 221, in <module>
    diff_expr_object.run_edgeR()
  File "differential_expression.py", line 127, in run_edgeR
    probs = call_edger(data, groups, sizes, genes)
  File "differential_expression.py", line 64, in call_edger
    ''')
  File "/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 321, in __call__
    res = self.eval(p)
  File "/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 178, in __call__
    return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
  File "/home/user/.local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 106, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error: package or namespace load failed for ‘edgeR’

主要问题是:

rpy2.rinterface.RRuntimeError: Error: package or namespace load failed for ‘edgeR’

但是,当我运行以下内容时:

R
> library(edgeR)
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.5 (Final)

locale:
 [1] LC_CTYPE=en_ZA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_ZA.UTF-8        LC_COLLATE=en_ZA.UTF-8    
 [5] LC_MONETARY=en_ZA.UTF-8    LC_MESSAGES=en_ZA.UTF-8   
 [7] LC_PAPER=en_ZA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_ZA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] edgeR_3.12.0 limma_3.26.9
> 

我可以看到 edgeR 已成功安装并且 运行ning 在 R 中。为什么它不能在 Python 中工作?我试图从 rpy2 加载其他包,例如library(tools) 效果很好。

错误是:

UserWarning: Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/data/scratch/user/source/anaconda/lib/R/library/edgeR/libs/edgeR.so':
 /data/scratch/user/source/anaconda/lib/R/library/edgeR/libs/edgeR.so: undefined symbol: _ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev

无法加载 edgeR 的 C 库。您是否了解如何安装 R 和 edgeR 的详细信息? (我可以看到涉及anaconda)。

找到解决方案...

由于我使用的 Rr-base 版本是使用 conda 安装的,因此通过相同的渠道安装 edgeR 可以修复错误。

简单运行:

conda install --channel https://conda.anaconda.org/bioconda bioconductor-edger