satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.31k stars 920 forks source link

Error running IntegrateLayers #7834

Closed ziyin96 closed 5 months ago

ziyin96 commented 1 year ago

Hi,

Appreciate all the work on v5

I followed the tutorial Integrative analysis in Seurat v5 to try different type of integration method.

Using the demo pbmcsca dataset, I succesfully achieved CCAIntegration, RPCAIntegration and FastMNNIntegration, but failed in the other two.

For HarmonyIntegration

obj <- IntegrateLayers(
  object = obj, method = HarmonyIntegration,
  orig.reduction = "pca", new.reduction = "harmony",
  verbose = FALSE
) 

I got this error:

Error: element-wise pow(): incompatible matrix dimensions: 100x9 and 9x1

For scVIIntegration:

obj <- IntegrateLayers(
  object = obj, method = scVIIntegration,
  new.reduction = "integrated.scvi",
  conda_env = "../miniconda3/envs/scvi-env", verbose = FALSE
) 

I got this error

Error in py_module_import(module, convert = convert) : 
  TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Run `reticulate::py_last_error()` for details.

> reticulate::py_last_error()

── Python Exception Message ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
    module = hook()
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 117, in _hook
    return _find_and_load(name, import_)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/python3.9/site-packages/scanpy/__init__.py", line 17, in <module>
    from . import plotting as pl
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
    module = hook()
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 117, in _hook
    return _find_and_load(name, import_)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/python3.9/site-packages/scanpy/plotting/__init__.py", line 1, in <module>
    from ._anndata import (
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
    module = hook()
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 117, in _hook
    return _find_and_load(name, import_)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/python3.9/site-packages/scanpy/plotting/_anndata.py", line 28, in <module>
    from . import _utils
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 93, in _run_hook
    module = hook()
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/R/library/reticulate/python/rpytools/loader.py", line 117, in _hook
    return _find_and_load(name, import_)
  File "/storage/chenziyin/miniconda3/envs/seurat_v5/lib/python3.9/site-packages/scanpy/plotting/_utils.py", line 36, in <module>
    class _AxesSubplot(Axes, axes.SubplotBase, ABC):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    ▆
 1. └─Seurat::IntegrateLayers(...)
 2.   └─SeuratWrappers (local) method(...)
 3.     └─reticulate::import("scanpy", convert = FALSE)
 4.       └─reticulate:::py_module_import(module, convert = convert)

Complete code I used

library(Seurat)
library(SeuratData)
library(SeuratWrappers)
library(Azimuth)
library(ggplot2)
library(patchwork)

options(future.globals.maxSize = 1e9)
options(Seurat.object.assay.version = "v5")

# InstallData("pbmcsca", force = TRUE)
obj <- LoadData("pbmcsca")
obj <- subset(obj, nFeature_RNA > 1000)
obj <- RunAzimuth(obj, reference = "pbmcref")

obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method)
obj

obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)
obj <- RunPCA(obj)

obj <- RunUMAP(obj, dims = 1:30, reduction = "pca", reduction.name = "umap.unintegrated")
p <- DimPlot(obj, reduction = "umap.unintegrated", group.by = c("Method", "predicted.celltype.l2"))
ggsave("charts.png", p, width = 14, height = 7)

obj <- IntegrateLayers(
  object = obj, method = CCAIntegration,
  orig.reduction = "pca", new.reduction = "integrated.cca",
  verbose = FALSE
)
obj <- IntegrateLayers(
  object = obj, method = RPCAIntegration,
  orig.reduction = "pca", new.reduction = "integrated.rpca",
  verbose = FALSE
)

obj <- IntegrateLayers(
  object = obj, method = HarmonyIntegration,
  orig.reduction = "pca", new.reduction = "harmony",
  verbose = FALSE
)     # Failed
obj <- IntegrateLayers(
  object = obj, method = FastMNNIntegration,
  new.reduction = "integrated.mnn",
  verbose = FALSE
)
obj <- IntegrateLayers(
  object = obj, method = scVIIntegration,
  new.reduction = "integrated.scvi",
  conda_env = "/storage/chenziyin/miniconda3/envs/seurat_v5", verbose = FALSE
)     # Failed

I used R installed by conda

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Stream 9

Matrix products: default
BLAS/LAPACK: /storage/chenziyin/miniconda3/envs/seurat_v5/lib/libopenblasp-r0.3.24.so;  LAPACK version 3.11.0

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

time zone: Asia/Shanghai
tzcode source: system (glibc)

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

other attached packages:
 [1] patchwork_1.1.3          ggplot2_3.4.3            Azimuth_0.4.6.9004      
 [4] shinyBS_0.61.1           SeuratWrappers_0.3.19    pbmcsca.SeuratData_3.0.0
 [7] pbmcref.SeuratData_1.0.0 SeuratData_0.2.2.9001    Seurat_4.9.9.9060       
[10] SeuratObject_4.9.9.9091  sp_2.0-0                

loaded via a namespace (and not attached):
  [1] fs_1.6.3                          ProtGenerics_1.32.0              
  [3] matrixStats_1.0.0                 spatstat.sparse_3.0-2            
  [5] bitops_1.0-7                      DirichletMultinomial_1.42.0      
  [7] TFBSTools_1.38.0                  httr_1.4.7                       
  [9] RColorBrewer_1.1-3                tools_4.3.1                      
 [11] sctransform_0.4.0                 utf8_1.2.3                       
 [13] R6_2.5.1                          DT_0.29                          
 [15] lazyeval_0.2.2                    uwot_0.1.16                      
 [17] rhdf5filters_1.12.1               withr_2.5.0                      
 [19] prettyunits_1.2.0                 gridExtra_2.3                    
 [21] progressr_0.14.0                  cli_3.6.1                        
 [23] Biobase_2.60.0                    spatstat.explore_3.2-3           
 [25] fastDummies_1.7.3                 EnsDb.Hsapiens.v86_2.99.0        
 [27] shinyjs_2.1.0                     spatstat.data_3.0-1              
 [29] readr_2.1.4                       ggridges_0.5.4                   
 [31] pbapply_1.7-2                     Rsamtools_2.16.0                 
 [33] R.utils_2.12.2                    harmony_1.0                      
 [35] parallelly_1.36.0                 BSgenome_1.68.0                  
 [37] RSQLite_2.3.1                     generics_0.1.3                   
 [39] BiocIO_1.10.0                     gtools_3.9.4                     
 [41] ica_1.0-3                         spatstat.random_3.1-6            
 [43] googlesheets4_1.1.1               dplyr_1.1.3                      
 [45] GO.db_3.17.0                      Matrix_1.6-1.1                   
 [47] fansi_1.0.4                       S4Vectors_0.38.2                 
 [49] abind_1.4-5                       R.methodsS3_1.8.2                
 [51] lifecycle_1.0.3                   yaml_2.3.7                       
 [53] SummarizedExperiment_1.30.2       rhdf5_2.44.0                     
 [55] BiocFileCache_2.8.0               Rtsne_0.16                       
 [57] grid_4.3.1                        blob_1.2.4                       
 [59] promises_1.2.1                    shinydashboard_0.7.2             
 [61] crayon_1.5.2                      miniUI_0.1.1.1                   
 [63] lattice_0.21-8                    cowplot_1.1.1                    
 [65] annotate_1.78.0                   GenomicFeatures_1.52.2           
 [67] KEGGREST_1.40.0                   pillar_1.9.0                     
 [69] GenomicRanges_1.52.0              rjson_0.2.21                     
 [71] future.apply_1.11.0               codetools_0.2-19                 
 [73] fastmatch_1.1-4                   leiden_0.4.3                     
 [75] glue_1.6.2                        data.table_1.14.8                
 [77] remotes_2.4.2.1                   vctrs_0.6.3                      
 [79] png_0.1-8                         spam_2.9-1                       
 [81] cellranger_1.1.0                  gtable_0.3.4                     
 [83] poweRlaw_0.70.6                   cachem_1.0.8                     
 [85] Signac_1.11.9000                  S4Arrays_1.0.6                   
 [87] mime_0.12                         pracma_2.4.2                     
 [89] survival_3.5-7                    gargle_1.5.2                     
 [91] RcppRoll_0.3.0                    ellipsis_0.3.2                   
 [93] fitdistrplus_1.1-11               ROCR_1.0-11                      
 [95] nlme_3.1-163                      bit64_4.0.5                      
 [97] progress_1.2.2                    filelock_1.0.2                   
 [99] RcppAnnoy_0.0.21                  GenomeInfoDb_1.36.3              
[101] irlba_2.3.5.1                     KernSmooth_2.23-22               
[103] SeuratDisk_0.0.0.9020             colorspace_2.1-0                 
[105] seqLogo_1.66.0                    BiocGenerics_0.46.0              
[107] DBI_1.1.3                         tidyselect_1.2.0                 
[109] bit_4.0.5                         compiler_4.3.1                   
[111] curl_5.0.2                        hdf5r_1.3.8                      
[113] xml2_1.3.5                        DelayedArray_0.26.7              
[115] plotly_4.10.2                     rtracklayer_1.60.1               
[117] scales_1.2.1                      caTools_1.18.2                   
[119] lmtest_0.9-40                     rappdirs_0.3.3                   
[121] stringr_1.5.0                     digest_0.6.33                    
[123] goftest_1.2-3                     presto_1.0.0                     
[125] spatstat.utils_3.0-3              XVector_0.40.0                   
[127] htmltools_0.5.6                   pkgconfig_2.0.3                  
[129] MatrixGenerics_1.12.3             dbplyr_2.3.3                     
[131] fastmap_1.1.1                     ensembldb_2.24.1                 
[133] rlang_1.1.1                       htmlwidgets_1.6.2                
[135] shiny_1.7.5                       zoo_1.8-12                       
[137] jsonlite_1.8.7                    BiocParallel_1.34.2              
[139] R.oo_1.25.0                       RCurl_1.98-1.12                  
[141] magrittr_2.0.3                    GenomeInfoDbData_1.2.10          
[143] dotCall64_1.0-2                   Rhdf5lib_1.22.1                  
[145] munsell_0.5.0                     Rcpp_1.0.11                      
[147] reticulate_1.32.0                 stringi_1.7.12                   
[149] zlibbioc_1.46.0                   MASS_7.3-60                      
[151] plyr_1.8.8                        parallel_4.3.1                   
[153] listenv_0.9.0                     ggrepel_0.9.3                    
[155] deldir_1.0-9                      CNEr_1.36.0                      
[157] Biostrings_2.68.1                 splines_4.3.1                    
[159] tensor_1.5                        hms_1.1.3                        
[161] BSgenome.Hsapiens.UCSC.hg38_1.4.5 igraph_1.5.1                     
[163] spatstat.geom_3.2-5               RcppHNSW_0.5.0                   
[165] reshape2_1.4.4                    biomaRt_2.56.1                   
[167] stats4_4.3.1                      TFMPvalue_0.0.9                  
[169] XML_3.99-0.14                     BiocManager_1.30.22              
[171] JASPAR2020_0.99.10                tzdb_0.4.0                       
[173] httpuv_1.6.11                     RANN_2.6.1                       
[175] tidyr_1.3.0                       purrr_1.0.2                      
[177] polyclip_1.10-4                   future_1.33.0                    
[179] scattermore_1.2                   rsvd_1.0.5                       
[181] xtable_1.8-4                      restfulr_0.0.15                  
[183] AnnotationFilter_1.24.0           RSpectra_0.16-1                  
[185] later_1.3.1                       googledrive_2.1.1                
[187] viridisLite_0.4.2                 tibble_3.2.1                     
[189] memoise_2.0.1                     AnnotationDbi_1.62.2             
[191] GenomicAlignments_1.36.0          IRanges_2.34.1                   
[193] cluster_2.1.4                     globals_0.16.2   
saphir746 commented 1 year ago

I too would like to know the answer to this

MariahHoffman commented 8 months ago

This error may be due to a dependency issue with scanpy (see https://github.com/scverse/scanpy/issues/2411#issuecomment-1429887964). I found that downgrading to matplotlib=3.6.3 in the scvi conda environment removed the error.

mhkowalski commented 5 months ago

Hi,

Thanks for your report. It seems like the scvi conda environment isn't set up correctly, as @MariahHoffman mentioned. Please open a new issue if you've tried this fix and are still encountering problems.