broadinstitute / infercnv

Inferring CNV from Single-Cell RNA-Seq
Other
558 stars 166 forks source link

Error with python #359

Closed Sa753 closed 2 years ago

Sa753 commented 3 years ago

Dear team,

I am getting the following error twice after running for 5h at step15

INFO [2021-09-07 07:41:08] define_signif_tumor_subclusters(p_val=0.1 INFO [2021-09-07 07:41:08] define_signif_tumor_subclusters(), tumor: 6 Error in py_module_import(module, convert = convert) : ImportError: No module named leidenalg

and the other time STEP 15: computing tumor subclusters via leiden

INFO [2021-09-07 01:16:19] define_signif_tumor_subclusters(p_val=0.1 INFO [2021-09-07 01:16:19] define_signif_tumor_subclusters(), tumor: 6 Error: Python module igraph was not found.

Detected Python configuration:

python: /usr/bin/python libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7 version: 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy numpy_version: 1.8.0 numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy

python versions found: /Users/opt/anaconda3/envs/r-reticulate/bin/python /usr/bin/python /Users/opt/anaconda3/envs/anaconda3/bin/python /Users/opt/anaconda3/envs/Python3/bin/python /Users/cpdb-venv/bin/python

I have all those modules installed . I run the functions before and worked well, the error appeared when I added analysis_mode = 'subclusters' . Also, I don't know why is it picking up python 2.7 and I have python 3.8 installed. I have igraph version 0.7.1 python-igraph version 0.7.1 leidenlag version 0.7.0

installed via anaconda 3.

Also, is there any suggestions to make the run time any shorter?. I am unable to complete the run for 22K cells

Thanks

Sa753 commented 3 years ago

library(leiden) Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

All requested packages already installed.

Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

All requested packages already installed.

Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

All requested packages already installed.

Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

All requested packages already installed.

**pythonmodules igraph and leidenalg installed

perform infercnv operations to reveal cnv signal

infercnv_obj_m = infercnv::run(infercnv_obj_m,

  • cutoff=0.1, # use 1 for smart-seq, 0.1 for 10x-genomics
  • out_dir="output_dir_h5", # dir is auto-created for storing outputs
  • cluster_by_groups=T, diagnostics=TRUE, # cluster
  • denoise=T, HMM = T, analysis_mode = 'subclusters' , num_ref_groups = 1, num_threads = 20) INFO [2021-09-07 11:18:23] ::process_data:Start INFO [2021-09-07 11:18:23] Checking for saved results. INFO [2021-09-07 11:18:23] Trying to reload from step 14 INFO [2021-09-07 11:18:26] Using backup from step 14 INFO [2021-09-07 11:18:26]
STEP 1: incoming data

INFO [2021-09-07 11:18:26]

STEP 02: Removing lowly expressed genes

INFO [2021-09-07 11:18:26]

STEP 03: normalization by sequencing depth

INFO [2021-09-07 11:18:26]

STEP 04: log transformation of data

INFO [2021-09-07 11:18:26]

STEP 06: splitting reference data into 1 clusters

INFO [2021-09-07 11:18:26]

STEP 08: removing average of reference data (before smoothing)

INFO [2021-09-07 11:18:26]

STEP 09: apply max centered expression threshold: 3

INFO [2021-09-07 11:18:26]

STEP 10: Smoothing data per cell by chromosome

INFO [2021-09-07 11:18:26]

STEP 11: re-centering data across chromosome after smoothing

INFO [2021-09-07 11:18:26]

STEP 12: removing average of reference data (after smoothing)

INFO [2021-09-07 11:18:26]

STEP 14: invert log2(FC) to FC

INFO [2021-09-07 11:18:26]

STEP 15: computing tumor subclusters via leiden

INFO [2021-09-07 11:18:26] define_signif_tumor_subclusters(p_val=0.1 INFO [2021-09-07 11:18:26] define_signif_tumor_subclusters(), tumor: 44 Error in py_module_import(module, convert = convert) : ImportError: No module named leidenalg

GeorgescuC commented 3 years ago

Hi @Sa753 ,

By default, R tries to make its own (ana)conda environment, in your case in /Users/opt/anaconda3/envs/r-reticulate/bin/python, but the error messages indicate that this environment is not the one currently being used, but rather /usr/bin/python is used. If this is the first time you have used a package that requires python in R, the first thing to attempt is to restart your R/Rstudio session so that the newly created anaconda environment can automatically be loaded and used.

If that does not work, you can run

library(reticulate)
py_config()

to check which environment is loaded.

If the correct anaconda environment is loaded and packages are still missing, you can try installing them through R with: reticulate::conda_install("r-reticulate", "leidenalg", channel = "vtraag")

Or in a terminal:

conda activate /Users/opt/anaconda3/envs/r-reticulate/bin/python
conda pip install igraph leidenalg
conda deactivate

If the correct anaconda environment is not loaded, reticulate::use_condaenv("r-reticulate") should make R use it.

Regards, Christophe.

Sa753 commented 3 years ago

Hi Christophe,

Unfortunately I am still getting the same errors inspite of the packages being installed as shown below

reticulate::conda_install("r-reticulate", "leidenalg", channel = "vtraag") Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

All requested packages already installed.

then I run infercnsv::run() and I get

STEP 15: computing tumor subclusters via leiden

INFO [2021-09-16 19:45:58] define_signif_tumor_subclusters(p_val=0.1 INFO [2021-09-16 19:45:58] define_signif_tumor_subclusters(), tumor: 44 Error in py_module_import(module, convert = convert) : ImportError: No module named leidenalg

GeorgescuC commented 3 years ago

Hi @Sa753 ,

Does reticulate::py_config() return that you are using the same version of Python where you know the packages are installed? You can make an .Rprofile file where you start R from that contains Sys.setenv(RETICULATE_PYTHON = "/Users/opt/anaconda3/envs/r-reticulate/bin/python"), or run "export RETICULATE_PYTHON=/Users/opt/anaconda3/envs/r-reticulate/bin/python" in your terminal, then restart R in either case.

Alternatively, if this issue with R reticulate finding the proper python env persists, I updated the docker image to the latest commit, so you can try using that instead.

Regards, Christophe.

Sa753 commented 2 years ago

it worked with Miniconda but not anaconda and I don't know the reason