Teichlab / cellphonedb

MIT License
342 stars 105 forks source link

Problem with plots #289

Closed algarji closed 3 years ago

algarji commented 3 years ago

I am unexperienced in python, and I don't know how to link ggplot2 to the conda environment to perform the plots on the statistical results from cellphonedb. I already have R and ggplot2 package installed in my computer, but when I write the cellphonedb code on conda I obtain the following error: C:\Users\algar> cellphonedb plot dot_plot --pvalues-path=./out/pvalues.txt --means-path=./out/means.txt -- output-path=./out --output-name=dotplot.pdf As there is no R environment set up, some functionalities will be disabled, e.g. plot Usage: cellphonedb plot dot_plot [OPTIONS]

Can anyone help me in this step? Thanks

algarji commented 3 years ago

I think that the problem comes with rpy2 compatible versions with cellphonedb. They do not work in windows (rpy2 3.0.4 or rpy2 3.0.5). Any suggestion is appreciated.

prete commented 3 years ago

Hi @algarji this sounds similar to #286. Could you make sure you've got R_HOME and R_USER environment variables? ( to do that, on the same command-line interpreter you run cellphonedb try echo %R_HOME% and echo %R_USER% and see if they are set)

Alternatively you can try the method described here to install rpy2: https://jianghaochu.github.io/how-to-install-rpy2-in-windows-10.html

algarji commented 3 years ago

Hi @prete I decided to move to Linux on Bash as I read some other users with this problem in Windows. I successfully downloaded a compatible rpy2 version but I still have problems.

I downloaded R from source and I manually set the R_HOME and R_USER:

./configure --prefix=/usr --libdir=/usr/lib --enable-R-shlib --enable-BLAS-shlib --enable-LAPACK-shlib && make && make install
export R_HOME=/usr/lib/R/
export R_USER=/home/algarji/.local/lib/python3.6/site-packages/rpy2

When I run the dot plot code from cellphonedb I obtain the following:

/home/algarji/.local/lib/python3.6/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.cluster.k_means_ module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.cluster. Anything that cannot be imported from sklearn.cluster is now part of the private API.
  warnings.warn(message, FutureWarning)
[ ][APP][25/03/21-14:22:01][ERROR] Unexpected error
Traceback (most recent call last):
  File "/home/algarji/.local/lib/python3.6/site-packages/cellphonedb/src/api_endpoints/terminal_api/plot_terminal_api_endpoints/plot_terminal_commands.py", line 38, in dot_plot
    columns=columns)
  File "/home/algarji/.local/lib/python3.6/site-packages/cellphonedb/src/plotters/r_plotter.py", line 35, in wrapper
    from rpy2.rinterface_lib.embedded import RRuntimeError
  File "/home/algarji/.local/lib/python3.6/site-packages/rpy2/rinterface_lib/embedded.py", line 7, in <module>
    from . import openrlib
  File "/home/algarji/.local/lib/python3.6/site-packages/rpy2/rinterface_lib/openrlib.py", line 21, in <module>
    rlib = _dlopen_rlib(R_HOME)
  File "/home/algarji/.local/lib/python3.6/site-packages/rpy2/rinterface_lib/openrlib.py", line 17, in _dlopen_rlib
    rlib = ffi.dlopen(lib_path)
OSError: cannot load library '/usr/lib/R/lib/libR.so': libRblas.so: cannot open shared object file: No such file or directory

I don't understand why the system does not recognise the file libRblas.so, as I can find it using ls /usr/lib/R/lib and I explicitly enable this file in R installation. Maybe I commited some error setting the environments manually...

prete commented 3 years ago

Hi @algarji if you're on Linux now, I'd recomend you set up your environment using conda, first install miniconda3 and then:

a) create environment.yml with :

name: cpdb
dependencies:
  - python=3.8
  - pip
  - r-base
  - r-ggplot2
  - r-pheatmap
  - pip:
    - cellphonedb

b) create a conda env using the former file:

conda env create -f environment.yml

c) activate the conda environment

conda activate cpdb
algarji commented 3 years ago

@prete thanks a lot! Much more easy through miniconda.