LouisFaure / scFates

a scalable python suite for tree inference and advanced pseudotime analysis from scRNAseq data.
https://scfates.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
47 stars 1 forks source link

error in tl.test_association, "pip3 install rpy2" not working #5

Closed Roger-GOAT closed 2 years ago

Roger-GOAT commented 2 years ago

Thank you for the wonderful software! I run scf.tl.test_association(adata) showed:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/tmp/ipykernel_235126/2079056078.py in <module>
----> 1 scf.tl.test_association(adata)

~/miniconda3/envs/scfates/lib/python3.8/site-packages/scFates/tools/test_association.py in test_association(adata, n_map, n_jobs, spline_df, fdr_cut, A_cut, st_cut, reapply_filters, plot, root, leaves, copy, layer)
    112             [type(imp) == str for imp in [Rpy2, R, rstats, rmgcv, Formula]]
    113         ).min()
--> 114         raise Exception(np.array([Rpy2, R, rstats, rmgcv, Formula])[idx])
    115 
    116     adata = adata.copy() if copy else adata

Exception: rpy2 installatio nis necessary for testing feature association to the tree.             
Please use "pip3 install rpy2" to install rpy2

However, I have "pip3 install rpy2" or "pip install rpy2" and the rpy2 had been installed. And I also install.packages('mgcv') in R.

LouisFaure commented 2 years ago

@Roger-GOAT thank you for your kind words!

Have you installed rpy2 in the same environment as scFates? From what I can read from your error message, you are running in a conda environment named scfates.

Could you run the following code right before scf.tl.test_association?

from rpy2.robjects import pandas2ri, Formula
from rpy2.robjects.packages import importr
import rpy2.rinterface

pandas2ri.activate()

Additionally if this works, could you then run the following to check whether rpy2 can access mgcv?

rmgcv = importr("mgcv")
Roger-GOAT commented 2 years ago

@LouisFaure Thank you for your reply! I try

from rpy2.robjects import pandas2ri, Formula from rpy2.robjects.packages import importr import rpy2.rinterface

pandas2ri.activate()

It showed below:

---------------------------------------------------------------------------

OSError                                   Traceback (most recent call last)
/tmp/ipykernel_2120535/643095386.py in <module>
----> 1 from rpy2.robjects import pandas2ri, Formula
      2 from rpy2.robjects.packages import importr
      3 import rpy2.rinterface
      4 
      5 pandas2ri.activate()

~/.local/lib/python3.8/site-packages/rpy2/robjects/__init__.py in <module>
     14 from functools import partial
     15 import types
---> 16 import rpy2.rinterface as rinterface
     17 import rpy2.rlike.container as rlc
     18 

~/.local/lib/python3.8/site-packages/rpy2/rinterface.py in <module>
     10 import warnings
     11 from typing import Union
---> 12 from rpy2.rinterface_lib import openrlib
     13 import rpy2.rinterface_lib._rinterface_capi as _rinterface
     14 import rpy2.rinterface_lib.embedded as embedded

~/.local/lib/python3.8/site-packages/rpy2/rinterface_lib/openrlib.py in <module>
     42     rlib = _rinterface_cffi.lib
     43 else:
---> 44     rlib = _dlopen_rlib(R_HOME)
     45 
     46 

~/.local/lib/python3.8/site-packages/rpy2/rinterface_lib/openrlib.py in _dlopen_rlib(r_home)
     35         raise ValueError('The library path cannot be None.')
     36     else:
---> 37         rlib = ffi.dlopen(lib_path)
     38     return rlib
     39 

OSError: cannot load library '/usr/local/lib/R/lib/libR.so': libRblas.so: cannot open shared object file: No such file or directory

How can I do to fix it?

LouisFaure commented 2 years ago

This error is happening as rpy2 cannot find specific shared library, depending on how R has been installed.

In my memory I would have solved this issue by specifying the path R_HOME before importing rpy2/scFates:

import os
os.environ['R_HOME'] = '/path/to/R'

I have found that using CRAN installed R usually works best, in such case path would be something like: /usr/lib/R

If that still doesn't work then I suggest you to have a look at this issue https://github.com/rpy2/rpy2/issues/675

LouisFaure commented 2 years ago

Closing this issue as it is more rpy2 R related than scFates