Seurat: Leidenalg error

Created on 16 Jan 2020  ยท  8Comments  ยท  Source: satijalab/seurat

Hi,

I am encountering this error when I try Leidenalg. Does anyone knows what is going on?

 seu <- FindClusters(seu, algorithm = 4, random.seed = 256, resolution = 0.5)
Error in leidenalg$find_partition(snn_graph, leidenalg$RBConfigurationVertexPartition,  : 
  attempt to apply non-function
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

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

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

other attached packages:
 [1] reticulate_1.14     scales_1.1.0        RColorBrewer_1.1-2  slingshot_1.2.0     Biobase_2.44.0      BiocGenerics_0.30.0 princurve_2.1.4     dplyr_0.8.3         plyr_1.8.5          Seurat_3.1.2       

loaded via a namespace (and not attached):
  [1] R.utils_2.9.2               tidyselect_0.2.5            RSQLite_2.2.0               AnnotationDbi_1.46.1        htmlwidgets_1.5.1           grid_3.6.2                  BiocParallel_1.18.1        
  [8] Rtsne_0.15                  RNeXML_2.4.0                munsell_0.5.0               codetools_0.2-16            mutoss_0.1-12               ica_1.0-2                   miniUI_0.1.1.1             
 [15] future_1.15.1               withr_2.1.2                 colorspace_1.4-1            knitr_1.26                  uuid_0.1-2                  pspline_1.0-18              zinbwave_1.6.0             
 [22] rstudioapi_0.10             stats4_3.6.2                SingleCellExperiment_1.6.0  ROCR_1.0-7                  ggsignif_0.6.0              gbRd_0.4-11                 listenv_0.8.0              
 [29] NMF_0.21.0                  Rdpack_0.11-1               labeling_0.3                GenomeInfoDbData_1.2.1      mnormt_1.5-5                bit64_0.9-7                 farver_2.0.1               
 [36] pheatmap_1.0.12             rhdf5_2.28.1                vctrs_0.2.1                 TH.data_1.0-10              xfun_0.12                   R6_2.4.1                    doParallel_1.0.15          
 [43] GenomeInfoDb_1.20.0         rsvd_1.0.2                  locfit_1.5-9.1              manipulateWidget_0.10.0     bitops_1.0-6                DelayedArray_0.10.0         assertthat_0.2.1           
 [50] promises_1.1.0              SDMTools_1.1-221.2          multcomp_1.4-12             gtable_0.3.0                phylobase_0.8.6             npsurv_0.4-0                globals_0.12.5             
 [57] sandwich_2.5-1              rlang_0.4.2                 genefilter_1.66.0           zeallot_0.1.0               splines_3.6.2               lazyeval_0.2.2              rgl_0.100.30               
 [64] BiocManager_1.30.10         yaml_2.2.0                  reshape2_1.4.3              crosstalk_1.0.0             backports_1.1.5             httpuv_1.5.2                tools_3.6.2                
 [71] gridBase_0.4-7              ggplot2_3.2.1               gplots_3.0.1.2              stabledist_0.7-1            ggridges_0.5.2              TFisher_0.2.0               Rcpp_1.0.3                 
 [78] base64enc_0.1-3             progress_1.2.2              zlibbioc_1.30.0             purrr_0.3.3                 RCurl_1.95-4.12             prettyunits_1.1.0           ggpubr_0.2.4               
 [85] pbapply_1.4-2               cowplot_1.0.0               S4Vectors_0.22.1            zoo_1.8-7                   SummarizedExperiment_1.14.1 ggrepel_0.8.1               cluster_2.1.0              
 [92] magrittr_1.5                data.table_1.12.8           RSpectra_0.16-0             lmtest_0.9-37               RANN_2.6.1                  mvtnorm_1.0-12              fitdistrplus_1.0-14        
 [99] matrixStats_0.55.0          gsl_2.1-6                   mime_0.8                    hms_0.5.3                   lsei_1.2-0                  evaluate_0.14               xtable_1.8-4               
[106] XML_3.98-1.20               readxl_1.3.1                shape_1.4.4                 IRanges_2.18.3              gridExtra_2.3               compiler_3.6.2              tibble_2.1.3               
[113] KernSmooth_2.23-16          crayon_1.3.4                R.oo_1.23.0                 htmltools_0.4.0             later_1.0.0                 pcaPP_1.9-73                tidyr_1.0.0                
[120] RcppParallel_4.4.4          DBI_1.1.0                   howmany_0.3-1               MASS_7.3-51.5               rappdirs_0.3.1              Matrix_1.2-18               ade4_1.7-13                
[127] readr_1.3.1                 R.methodsS3_1.7.1           gdata_2.18.0                metap_1.2                   igraph_1.2.4.2              GenomicRanges_1.36.1        pkgconfig_2.0.3            
[134] rncl_0.8.3                  sn_1.5-4                    registry_0.5-1              numDeriv_2016.8-1.1         locfdr_1.1-8                plotly_4.9.1                xml2_1.2.2                 
[141] foreach_1.4.7               annotate_1.62.0             rngtools_1.4                webshot_0.5.2               pkgmaker_0.27               multtest_2.40.0             XVector_0.24.0             
[148] bibtex_0.4.2.2              stringr_1.4.0               digest_0.6.23               sctransform_0.2.1           RcppAnnoy_0.0.14            tsne_0.1-3                  copula_0.999-19.1          
[155] ADGofTest_0.3               softImpute_1.4              rmarkdown_2.0               cellranger_1.1.0            leiden_0.3.1                edgeR_3.26.8                uwot_0.1.5                 
[162] kernlab_0.9-29              shiny_1.4.0                 gtools_3.8.1                lifecycle_0.1.0             nlme_3.1-143                jsonlite_1.6                Rhdf5lib_1.6.3             
[169] clusterExperiment_2.4.4     viridisLite_0.3.0           limma_3.40.6                pillar_1.4.3                lattice_0.20-38             fastmap_1.0.1               httr_1.4.1                 
[176] plotrix_3.7-7               survival_3.1-8              glue_1.3.1                  png_0.1-7                   iterators_1.0.12            glmnet_3.0-2                bit_1.1-15.1               
[183] HDF5Array_1.12.3            stringi_1.4.5               blob_1.2.0                  memoise_1.1.0               caTools_1.17.1.4            irlba_2.3.3                 future.apply_1.4.0         
[190] ape_5.3 
more-information-needed

Most helpful comment

Hi guys,

Not sure if this is the most correct way but this is how I got around the error. After running FindNeighbors I use the code below. I adapted it from here: https://cran.r-project.org/web/packages/leiden/vignettes/run_leiden.html

`#Install R accessible leidenalg and igraph
reticulate::py_install(packages ='leidenalg')

reticulate::py_install(packages ='igraph')

Install the R package for using leiden

devtools::install_github("TomKellyGenetics/leiden")

library(leiden)

use leiden on your adjacency matrix in the seurat object

Cluster_assignment <- leiden(x.combined@graphs$integrated_snn)

Add the cluster assignments as a column of metadata

x.[email protected]$Leiden_assigned_clusters <- Cluster_assignment`

Hope it helps!
-Chris

All 8 comments

Hi Saeed,

What version of Leiden do you have installed? You can find out with

import leidenalg
leidenalg.__version__

in Python or

pip freeze | grep leiden

in the shell

Hi Paul,

I could not make conda install -c vtraag leidenalg work. It returned as follows. Hence I used pip install leidenalg. It said it installed. However, when I use pip freeze I don't see it in the list. But when I use py_config() from reticulate in rstudio I see that it is getting installed somewhere outside. Honestly, do not know how to work around this. I know this must be an outside topic for 'Seurat' now. Will be great if you can suggest something though.

Not at all an expert with shell or python

Thanks

(base) u0119129@gbw-d-l0099:~$ conda install -c vtraag leidenalg
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \ 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
Examining certifi:  23%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–                  | 5/22 [00:00<00:00, 148.98it/s]
Comparing specs that have this dependency:   0%|          | 0/2 [00:00<?, ?it/s]
Finding short/ t conflict path for certifi[version='>=2016.9.26']:   0%| | 0/4 [Finding shortest conflict path for certifi:  25%|โ–Ž| 1/4 [00:00<00:00, 15.55it/s]Finding shortest conflict path for ca-certificates:  50%|โ–Œ| 2/4 [00:00<00:00, 15Finding shortest co- lict path for ca-certificates:  75%|โ–Š| 3/4 [00:00<00:00, 23Finding shortest conflict path for certifi[version='>=2016.09']:  75%|โ–Š| 3/4 [00Comparing specs that have this dependency:  50%|โ–ˆ | 1/2 [00:00<00:00,  4.81it/s]Finding shortest conflict path for certifi[version='>=2016.9.26']:   0%| | 0/3 [Finding shortest conflict path for ca-certificates:  33%|โ–Ž| 1/3 [00:00<00:00, 36Examining python:  59%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Š          | 13/22 [00:00<00:00, 23.17it/s]Comparing specs that have this dependency:   0%|          | 0/2 [00:00<?, ?it/s]Finding shortest conflict path for python[version='>=3.6,<3.7.0a0']:   0%| | 0/3Finding shortest conflict path for python=3.7:  33%|โ–Ž| 1/3 [00:00<00:00, 12157.4Finding shortest conflict path for python-igraph[version='>=0.7.1.0']:  67%|โ–‹| 2                                                                                Finding shortest conflict path for python[version='>=3.7,<3.8.0a0']:   0%| | 0/2failed                                                                                                                                                          UnsatisfiableError: The following specifications were found to be incompatible with each other:



Package certifi conflicts for:
leidenalg -> python[version='>=3.6,<3.7.0a0'] -> pip -> setuptools -> certifi[version='>=2016.09|>=2016.9.26']
python=3.7 -> pip -> setuptools -> certifi[version='>=2016.09|>=2016.9.26']
Package ca-certificates conflicts for:
python=3.7 -> openssl[version='>=1.1.1c,<1.1.2a'] -> ca-certificates
leidenalg -> python[version='>=3.6,<3.7.0a0'] -> openssl[version='>=1.0.2o,<1.0.3a'] -> ca-certificates
Package wheel conflicts for:
python=3.7 -> pip -> wheel
leidenalg -> python[version='>=3.6,<3.7.0a0'] -> pip -> wheel
Package pip conflicts for:
python=3.7 -> pip
leidenalg -> python[version='>=3.6,<3.7.0a0'] -> pip
Package setuptools conflicts for:
python=3.7 -> pip -> setuptools
leidenalg -> python[version='>=3.6,<3.7.0a0'] -> pip -> setuptools
Package python conflicts for:
python=3.7
Package python-igraph conflicts for:
leidenalg -> python-igraph[version='>=0.7.1.0']

py_config()
python:         /usr/bin/python
libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome:     //usr://usr
version:        2.7.15+ (default, Oct  7 2019, 17:39:04)  [GCC 7.4.0]
numpy:          /usr/local/lib/python2.7/dist-packages/numpy
numpy_version:  1.16.5
leidenalg:      /usr/local/lib/python2.7/dist-packages/leidenalg

python versions found: 
 /usr/bin/python3
 /usr/bin/python
 /home/luna.kuleuven.be/u0119129/anaconda3/bin/python

First, we strongly recommend not using Conda as it causes issue after issue after issue, especially with R/Python interoperability. Second, it seems that you have leidenalg installed under your system's Python 2 installation. Launch that with python (or /usr/bin/python if Conda decided to hijack your system's Python) and run the Python code I posted above to get version information.

Hi guys,

Not sure if this is the most correct way but this is how I got around the error. After running FindNeighbors I use the code below. I adapted it from here: https://cran.r-project.org/web/packages/leiden/vignettes/run_leiden.html

`#Install R accessible leidenalg and igraph
reticulate::py_install(packages ='leidenalg')

reticulate::py_install(packages ='igraph')

Install the R package for using leiden

devtools::install_github("TomKellyGenetics/leiden")

library(leiden)

use leiden on your adjacency matrix in the seurat object

Cluster_assignment <- leiden(x.combined@graphs$integrated_snn)

Add the cluster assignments as a column of metadata

x.[email protected]$Leiden_assigned_clusters <- Cluster_assignment`

Hope it helps!
-Chris

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Hi @mojaveazure, @cstill1992,

I am having this same issue. Was there a proper fix for this in the end? I have v0.8.1 of leidenalg and am getting the following error when I run either:
sample <- FindClusters(object = sample, resolution = 0.3, verbose = FALSE, algorithm = 4)
or
Cluster_assignment <- leiden(sample@graphs$SCT_snn)

Error in leidenalg$find_partition(snn_graph, leidenalg$RBConfigurationVertexPartition, :
attempt to apply non-function

Best wishes,
Lucy

@lc822 Hi, I remembered doing the following steps and solved the problem:

  1. In terminal, activate r-reticulate environment and un-install igraph, then go to rstudio and reinstall igraph through reticulate
  2. In terminal r-reticulate environment, pip install leiden-alg

Thanks, I managed to get it working in the end - can't remember how!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RuiyangLiu94 picture RuiyangLiu94  ยท  3Comments

GHAStVHenry picture GHAStVHenry  ยท  3Comments

htc502 picture htc502  ยท  3Comments

camilliano picture camilliano  ยท  3Comments

milanmlft picture milanmlft  ยท  3Comments