theislab / zellkonverter

Conversion between scRNA-seq objects
https://theislab.github.io/zellkonverter/
Other
145 stars 27 forks source link

ModuleNotFoundError: No module named 'anndata' #38

Closed mbahin closed 3 years ago

mbahin commented 3 years ago

Hi,

I'm trying to convert a SCE object to an AnnData one in R but I get the following message:

> library(zellkonverter)
> library(anndata)
> adata <- SCE2AnnData(sce)
Error in py_module_import(module, convert = convert) : 
  ModuleNotFoundError: No module named 'anndata'

Detailed traceback: 
  File "/home/mathieu/R/x86_64-conda-linux-gnu-library/4.0/reticulate/python/rpytools/loader.py", line 24, in _import_hook
    level=level

Any clue on that problem?

Cheers, Mathieu

SessionInfo:

R version 4.0.3 (2020-10-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS/LAPACK: /opt/miniconda3/lib/libopenblasp-r0.3.12.so

locale:
[1] C

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

other attached packages:
[1] anndata_0.7.5.1     zellkonverter_1.0.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6                  XVector_0.30.0             
 [3] rappdirs_0.3.3              GenomicRanges_1.42.0       
 [5] BiocGenerics_0.36.0         zlibbioc_1.36.0            
 [7] IRanges_2.24.1              lattice_0.20-41            
 [9] R6_2.5.0                    GenomeInfoDb_1.26.2        
[11] tcltk_4.0.3                 tools_4.0.3                
[13] SummarizedExperiment_1.20.0 parallel_4.0.3             
[15] grid_4.0.3                  Biobase_2.50.0             
[17] basilisk_1.2.1              matrixStats_0.58.0         
[19] assertthat_0.2.1            Matrix_1.3-2               
[21] GenomeInfoDbData_1.2.4      BiocManager_1.30.10        
[23] S4Vectors_0.28.1            bitops_1.0-6               
[25] basilisk.utils_1.2.2        RCurl_1.98-1.2             
[27] SingleCellExperiment_1.12.0 DelayedArray_0.16.1        
[29] compiler_4.0.3              filelock_1.0.2             
[31] MatrixGenerics_1.2.1        stats4_4.0.3               
[33] jsonlite_1.7.2              reticulate_1.18
lazappi commented 3 years ago

Hi @mbahin

{zellkonverter} currently converts between an R SingleCellExperiment and a Python AnnData object, not an R AnnData object from the {anndata} package.

The error you are seeing is because the Python anndata library is not installed in your Python environment. The {reticulate} documentation has useful information for managing a Python environment for R https://rstudio.github.io/reticulate/.

Alternatively, you can use the writeH5AD() function in {zellkonverter} which will manage the environment creation process for you and give you a .h5ad file on disk. You can then read this into R using {anndata} if you want an R AnnData object.

LTLA commented 3 years ago

Might consider exporting the BasiliskEnvironment objects so people can just:

library(basilisk)
library(zellkonverter)
basiliskStart(zellkonverterEnv) # give it a nice name.

ad <- SCE2AnnData(sce)

This is technically not safe against displacement from other Python instances - one would have to wrap further code in basiliskRun() to be properly protected - but it should be good enough for ad hoc scripts written by end-users.

mbahin commented 3 years ago

Thanks for your answers. The writeH5AD() approach worked! :)

lazappi commented 3 years ago

Great! 👍🏻

Reopening as a note to think about exporting the environment objects.

lazappi commented 3 years ago

Environment now exported in devel as of v1.1.5