tomkellygenetics / leiden Goto Github PK
View Code? Open in Web Editor NEWImplementation of the Leiden algorithm called by reticulate in R. (CRAN)
Home Page: https://CRAN.R-project.org/package=leiden
License: GNU General Public License v3.0
Implementation of the Leiden algorithm called by reticulate in R. (CRAN)
Home Page: https://CRAN.R-project.org/package=leiden
License: GNU General Public License v3.0
A "max_comm_size" (default of 0, i.e, any) argument was recently added to leidenalg 0.8.2.
max_comm_size : non-negative int
Maximal total size of nodes in a community. If zero (the default), then
communities can be of any size.
It would be possible to pass this argument from R if inputs are added. This would require a (recent) version of leidenalg to be installed.
It may be possible to check whether it is supported in python to retain backwards compatibility but this would complicate things.
leidenalg <- import("leidenalg", delay_load = TRUE)
self.optimiser = leidenalg$Optimiser()
missing(self.optimiser$max_comm_size)
I am tryint to generate leiden clusters based on Seurat integrated obj, (3000, 99192) converted to a SingleCellExperiment obj. I run following lines to generate the leiden cluster:
g <- buildSNNGraph(sce, k=10, use.dimred="PCA" ,BPPARAM=MulticoreParam(40), type="jaccard")
g.am<-as_adjacency_matrix(g)
g.am
99192 x 99192 sparse Matrix of class "dgCMatrix"
partition<-leiden(g.am)
The whole process took about an hour. Is there any way to speed this process up, perhaps by incorporating a multi thread support ?
Thanks.
An implementation in the igraph C library is being developed. Once this can be called in https://github.com/igraph/r-igraph then this version can be used instead of calling https://github.com/vtraag/leidenalg in python from reticulate.
This will improve performance for igraph objects and retain compatibility with code that calls leiden in R.
Hi Tom,
I was trying to install Leiden package in Rstudio, with no success. The error message is the following:
install.packages("leiden")
There is a binary version available but the source version is later:
binary source needs_compilation
leiden 0.3.3 0.3.4 FALSE
installing the source package ‘leiden’
downloaded 1.9 MB
The downloaded source packages are in
‘/private/var/folders/z5/7f3737q13dj2k63v65qb4mqr0000gn/T/RtmpY7Ugmn/downloaded_packages’
My sessionInfo is below:
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] ps_1.4.0 fansi_0.4.1 prettyunits_1.1.1 rprojroot_1.3-2
[5] withr_2.3.0 digest_0.6.27 crayon_1.3.4 assertthat_0.2.1
[9] R6_2.5.0 backports_1.1.10 magrittr_1.5 rlang_0.4.8
[13] cli_2.1.0 fs_1.5.0 remotes_2.2.0 testthat_2.3.2
[17] callr_3.5.1 ellipsis_0.3.1 desc_1.2.0 devtools_2.3.2
[21] tools_4.0.2 glue_1.4.2 pkgload_1.1.0 compiler_4.0.2
[25] processx_3.4.4 pkgbuild_1.1.0 sessioninfo_1.1.1 memoise_1.1.0
[29] usethis_1.6.3
Could you please help me troubleshooting? Any help is highly appreciated, thanks a lot!
Weighted matrices and 'igraph' objects are supported in the 0.3.3 release but the default behaviour can differ.
Checks will be made to ensure the same results from matrix or 'igraph' inputs. Handling of weights will be detailed in the documentation (rather than referring to python leidenalg
).
It is possible to call multiplex graphs in python as detailed here: https://leidenalg.readthedocs.io/en/latest/multiplex.html
Once the bug in leidenalg 0.8.2 is addressed (vtraag/leidenalg#50) it can be supported in R.
Here is a working demo of calling it in R via reticulate on a list of python graph objects (generated by leiden.igraph).
leidenalg <- import("leidenalg", delay_load = TRUE)
leidenalg <- import("leidenalg", delay_load = TRUE)
self.optimiser = leidenalg$Optimiser()
graph_list <- r_to_py(list(graph1, graph2, graph3))
part <- leidenalg$find_partition_multiplex(graph_list, partition_type = leidenalg$CPMVertexPartition)
names(part) <- c("membership", "improv")
partition <- part$membership+1
partition
It will be possible to define a dedicated internal function (similar to "find_partitions") specifically for multiplex graphs based on this example. The question is whether to add and S3 method for "leiden.list" or make it a separate multiplex function.
R has multiple supported classes for inputs for multiplex graphs:
a list of igraph objects as demonstrated
a "Semigroup" in the "multiplex" package (basically a list of arrays)
the "network" package which supports the "network" class (which has an "is.multiplex" function)
the mully package on CRAN has a "mully" class which depends on igraph ans supports an "is.mully" function.
the "multinet" package has the "RMLNetwork" class (can be converted to igraph with as.igraph.Rcpp_RMLNetwork)
the MUNA package is only on GitHub but extends igraph objects for multiplex graphs. The ""Multiplex" class has a "layers" slot which is a list of igraph objects.
the mplex package (not maintained) has a "multiplex" class.
These can be converted by passing to the adjacency matrix, although an igraph method would be preferable..
Hi,
When I installed the package from source (download from Github), the error has occoured:
> install.packages("~/software/leiden/",repos=NULL,type="source")
Installing package into ‘/home/data/public/R/library’
(as ‘lib’ is unspecified)
* installing *source* package ‘leiden’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
sh: line 1: 14006 Aborted R_TESTS= '/home/data/R/R-4.1.0/bin/R' --no-save --no-restore --no-echo 2>&1 < '/tmp/Rtmpy9CnbD/file36a31114d884'
*** Error in `/home/data/R/R-4.1.0/bin/exec/R': free(): invalid pointer: 0x00000000040ec778 ***
======= Backtrace: =========
....
ERROR: loading failed
* removing ‘/home/data/public/R/library/leiden’
Warning in install.packages :
installation of package ‘/home/wt/software/leiden/’ had non-zero exit status
(Because the body cannot exceed 65536 characters, the full messages was attached in the file below, error.txt)
The session info was :
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS: /home/data/R/R-4.1.0/lib/libRblas.so
LAPACK: /home/data/R/R-4.1.0/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reticulate_1.24
loaded via a namespace (and not attached):
[1] MatrixGenerics_1.6.0 Biobase_2.54.0 tidyr_1.2.0
[4] pkgload_1.2.4 jsonlite_1.8.0 NeoEnrichment_0.1.0
[7] brio_1.1.3 assertthat_0.2.1 stats4_4.1.0
[10] BSgenome_1.62.0 GenomeInfoDbData_1.2.7 Rsamtools_2.10.0
[13] yaml_2.3.5 remotes_2.4.2 sessioninfo_1.2.2
[16] pillar_1.7.0 lattice_0.20-45 glue_1.6.1
[19] GenomicRanges_1.46.1 XVector_0.34.0 colorspace_2.0-3
[22] Matrix_1.4-0 XML_3.99-0.6 pkgconfig_2.0.3
[25] devtools_2.4.3 zlibbioc_1.36.0 purrr_0.3.4
[28] scales_1.1.1 processx_3.5.2 BiocParallel_1.28.3
[31] tibble_3.1.6 generics_0.1.2 IRanges_2.28.0
[34] ggplot2_3.3.5 usethis_2.1.5 ellipsis_0.3.2
[37] cachem_1.0.6 withr_2.4.3 SummarizedExperiment_1.24.0
[40] BiocGenerics_0.40.0 cli_3.2.0 magrittr_2.0.2
[43] crayon_1.5.0 memoise_2.0.1 ps_1.6.0
[46] fs_1.5.2 fansi_1.0.2 pkgbuild_1.3.1
[49] data.table_1.14.2 tools_4.1.0 prettyunits_1.1.1
[52] BiocIO_1.4.0 lifecycle_1.0.1 matrixStats_0.61.0
[55] S4Vectors_0.32.3 munsell_0.5.0 DelayedArray_0.20.0
[58] callr_3.7.0 Biostrings_2.62.0 compiler_4.1.0
[61] GenomeInfoDb_1.30.1 rlang_1.0.1 grid_4.1.0
[64] RCurl_1.98-1.6 rstudioapi_0.13 rappdirs_0.3.3
[67] rjson_0.2.21 bitops_1.0-7 testthat_3.1.2
[70] restfulr_0.0.13 gtable_0.3.0 DBI_1.1.2
[73] curl_4.3.2 R6_2.5.1 GenomicAlignments_1.30.0
[76] dplyr_1.0.8 rtracklayer_1.54.0 fastmap_1.1.0
[79] utf8_1.2.2 rprojroot_2.0.2 desc_1.4.0
[82] stringi_1.7.6 Rcpp_1.0.8 parallel_4.1.0
[85] EasyBioinfo_0.0.0.9000 png_0.1-7 vctrs_0.3.8
[88] tidyselect_1.1.2
This is possibly related to a previous issue (#20). I recently tried to use the CRAN version of leiden (0.4.3). Upon loading, I see the following:
> library(leiden)
using environment: r-reticulate
conda environment r-reticulate installed
install dependencies (yes/no)?yes
yes
using environment: r-reticulate
/path/miniconda3/envs/r-reticulate/lib/python3.8/site-packages/numba/core/types/__init__.py:108: FutureWarning: In the future `np.long` will be defined as the corresponding NumPy scalar.
long_ = _make_signed(np.long)
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
## Package Plan ##
environment location: /path/miniconda3/envs/r-reticulate/envs/r-reticulate
added / updated specs:
- python
All the dependencies are actually installed. I think part of the problem may be that reticulate::py_module_available("umap")
should be reticulate::py_module_available("umap-learn")
in leiden.R
.
When it tries to install the dependencies, it does it in a new sub-environment (notice the path in the message).
I tried to install leiden with install.packages("leiden")
command in R (Ubuntu 18.04). But I had an error showing that I don't have "pandas" (actually I have). While checking the output messages, I noticed something weird in environment location.
During installation process, some packages are installed in r-reticulate environment (/home/user/anaconda3/envs/r-reticulate).
** testing if installed package can be loaded from temporary location
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
## Package Plan ##
environment location: /home/pirlab/anaconda3/envs/r-reticulate
added / updated specs:
- python
The following NEW packages will be INSTALLED:
...
But in the final step, environment location changes:
** testing if installed package can be loaded from final location
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
## Package Plan ##
environment location: /home/user/anaconda3/envs/r-reticulate/envs/r-reticulate
added / updated specs:
- python
The following packages will be downloaded:
...
...
...
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
Error: package or namespace load failed for ‘leiden’:
.onAttach failed in attachNamespace() for 'leiden', details:
call: py_module_import(module, convert = convert)
error: ModuleNotFoundError: No module named 'pandas'
Detailed traceback:
File "/home/pirlab/R/x86_64-pc-linux-gnu-library/4.0/reticulate/python/rpytools/loader.py", line 19, in _import_hook
module = _import(
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/pirlab/R/x86_64-pc-linux-gnu-library/4.0/leiden’
Warning in install.packages :
installation of package ‘leiden’ had non-zero exit status
As seen, the path of environment location is repeated. I resolved this problem by creating r-reticulate environment and installing pandas in the env by myself.
conda env remove -n r-reticulate
conda install --name r-reticulate pandas
I would like to report this bug in installation process. Thanks...
Hi,
I've got a new computer and installed the package from scratch - unfortunately, I can't get it to run despite following the instructions.
This is the error message that I get:
conda environment r-reticulate installed
*** caught segfault ***
address 0x10, cause 'memory not mapped'
Traceback:
1: py_module_import(module, convert = convert)
2: import(module)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({ import(module) TRUE}, error = clear_error_handler(FALSE))
7: reticulate::py_module_available("umap")
8: install_python_modules()
9: eval(expr, pf)
10: eval(expr, pf)
11: withVisible(eval(expr, pf))
12: evalVis(expr)
13: capture.output(expr, file = file)
14: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
15: suppressPackageStartupMessages(capture.output(expr, file = file))
16: withCallingHandlers(expr, message = function(c) if (inherits(c, classes)) tryInvokeRestart("muffleMessage"))
17: suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file)))
18: withCallingHandlers(expr, warning = function(w) if (inherits(w, classes)) tryInvokeRestart("muffleWarning"))
19: suppressWarnings(suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file))))
20: quiet(install_python_modules())
21: doTryCatch(return(expr), name, parentenv, handler)
22: tryCatchOne(expr, names, parentenv, handlers[[1L]])
23: tryCatchList(expr, classes, parentenv, handlers)
24: tryCatch({ if (reticulate::py_available() || sum("r-reticulate" == reticulate::conda_list()$name) >= 1) { install_python_modules <- function(method = "auto", conda = "auto") { if (!is.null(reticulate::conda_binary())) { reticulate::use_python(reticulate::conda_python()) if (!("r-reticulate" %in% reticulate::conda_list()$name)) { reticulate::conda_create(envname = "r-reticulate", ) if (!reticulate::py_module_available("conda")) reticulate::conda_install(envname = "r-reticulate", packages = "conda") } suppressWarnings(suppressMessages(reticulate::use_condaenv("r-reticulate"))) if (.Platform$OS.type == "windows") { install.packages("devtools", quiet = TRUE) devtools::install_github("rstudio/reticulate", ref = "86ebb56", quiet = TRUE) if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "python-igraph"))) if (!reticulate::py_module_available("mkl")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "mkl", channel = "intel"))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "umap-learn", channel = "conda-forge"))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "leidenalg", channel = "conda-forge"))) install.packages("reticulate", quiet = TRUE) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "leidenalg"))) utils::install.packages("reticulate", quiet = TRUE) } else { if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "python-igraph"))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "umap-learn", forge = TRUE))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "leidenalg", forge = TRUE))) Sys.setenv(RETICULATE_PYTHON = reticulate::conda_python()) } } else { if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::py_install("numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::py_install("pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::py_install("python-igraph", method = method, conda = conda))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::py_install("umap-learn"))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::py_install("leidenalg", method = method, conda = conda, forge = TRUE))) Sys.setenv(RETICULATE_PYTHON = reticulate::py_config()$python) } } quiet <- function(expr, all = TRUE) { if (Sys.info()["sysname"] == "Windows") { file <- "NUL" } else { file <- "/dev/null" } if (all) { suppressWarnings(suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file)))) } else { capture.output(expr, file = file) } } quiet(install_python_modules()) }}, error = function(e) { packageStartupMessage("Unable to install python modules igraph and leidenalg") packageStartupMessage("run in terminal:") packageStartupMessage("conda install -n r-reticulate -c conda-forge vtraag python-igraph pandas umap learn")}, finally = packageStartupMessage("python modules igraph and leidenalg installed"))
25: fun(libname, pkgname)
26: doTryCatch(return(expr), name, parentenv, handler)
27: tryCatchOne(expr, names, parentenv, handlers[[1L]])
28: tryCatchList(expr, classes, parentenv, handlers)
29: tryCatch(fun(libname, pkgname), error = identity)
30: runHook(".onAttach", ns, dirname(nspath), nsname)
31: attachNamespace(ns, pos = pos, deps, exclude, include.only)
32: doTryCatch(return(expr), name, parentenv, handler)
33: tryCatchOne(expr, names, parentenv, handlers[[1L]])
34: tryCatchList(expr, classes, parentenv, handlers)
35: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
36: library(leiden)
Possible actions:
Any idea what could be the issue here? Older versions of the the package worked flawlessly for me.
There is an odd behavior that I encountered. If I try to use leiden as the first reticulate package, a duplicated conda environment ends up getting created. When I call library(leiden)
, everything seems normal.
conda environment r-reticulate installed
...
python modules igraph and leidenalg installed
Then, when I call reticulate::conda_list()
:
name
1 base
2 r-reticulate
python
1 /usr/share/miniconda/envs/r-reticulate/bin/python
2 /usr/share/miniconda/envs/r-reticulate/envs/r-reticulate/bin/python
There are actual two r-reticulate
environments detected, one inside the other and one of them is considered base
. However, they are not complete and calling reticulate::py_module_available("leidenalg")
returns FALSE
.
This is the output of conda env list
outside R:
# conda environments:
#
base * /usr/share/miniconda
r-reticulate /usr/share/miniconda/envs/r-reticulate
/usr/share/miniconda/envs/r-reticulate/envs/r-reticulate
I was able to recreate the behavior using GitHub Actions. You can check the output here (technically, there are no errors, so it's considered a successful run): https://github.com/igordot/leiden/runs/5296171878?check_suite_focus=true
If I set up r-reticulate
environment before using leiden, everything seems fine. That might be why most people wouldn't encounter it. It seems something goes wrong when the package is trying to set up the environment.
I am using Linux (Debian) and am trying to upgrade from Leiden 0.3.7 to 0.3.9 but keep getting the following error:
> install.packages("leiden")
Installing package into ‘/home/ali/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/leiden_0.3.9.tar.gz'
Content type 'application/x-gzip' length 3091497 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
* installing *source* package ‘leiden’ ...
** package ‘leiden’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** caught segfault ***
address 0x1a0, cause 'memory not mapped'
Traceback:
1: py_module_import(module, convert = convert)
2: import(module)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({ import(module) TRUE}, error = clear_error_handler(FALSE))
7: reticulate::py_module_available("umap")
8: install_python_modules()
9: eval(expr, pf)
10: eval(expr, pf)
11: withVisible(eval(expr, pf))
12: evalVis(expr)
13: capture.output(expr, file = file)
14: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
15: suppressPackageStartupMessages(capture.output(expr, file = file))
16: withCallingHandlers(expr, message = function(c) if (inherits(c, classes)) tryInvokeRestart("muffleMessage"))
17: suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file)))
18: withCallingHandlers(expr, warning = function(w) if (inherits(w, classes)) tryInvokeRestart("muffleWarning"))
19: suppressWarnings(suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file))))
20: quiet(install_python_modules())
21: doTryCatch(return(expr), name, parentenv, handler)
22: tryCatchOne(expr, names, parentenv, handlers[[1L]])
23: tryCatchList(expr, classes, parentenv, handlers)
24: tryCatch({ if (reticulate::py_available() || sum("r-reticulate" == reticulate::conda_list()$name) >= 1) { install_python_modules <- function(method = "auto", conda = "auto") { if (!is.null(reticulate::conda_binary())) { reticulate::use_python(reticulate::conda_python()) if (!("r-reticulate" %in% reticulate::conda_list()$name)) { reticulate::conda_create(envname = "r-reticulate", ) if (!reticulate::py_module_available("conda")) reticulate::conda_install(envname = "r-reticulate", packages = "conda") } suppressWarnings(suppressMessages(reticulate::use_condaenv("r-reticulate"))) if (.Platform$OS.type == "windows") { install.packages("devtools", quiet = TRUE) devtools::install_github("rstudio/reticulate", ref = "86ebb56", quiet = TRUE) if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "python-igraph"))) if (!reticulate::py_module_available("mkl")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "mkl", channel = "intel"))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "umap-learn", channel = "conda-forge"))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "leidenalg", channel = "conda-forge"))) install.packages("reticulate", quiet = TRUE) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install(envname = "r-reticulate", packages = "leidenalg"))) utils::install.packages("reticulate", quiet = TRUE) } else { if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "python-igraph"))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "umap-learn", forge = TRUE))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::conda_install("r-reticulate", "leidenalg", forge = TRUE))) Sys.setenv(RETICULATE_PYTHON = reticulate::conda_python()) } } else { if (!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::py_install("numpy"))) if (!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::py_install("pandas"))) if (!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::py_install("python-igraph", method = method, conda = conda))) if (!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::py_install("umap-learn"))) if (!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::py_install("leidenalg", method = method, conda = conda, forge = TRUE))) Sys.setenv(RETICULATE_PYTHON = reticulate::py_config()$python) } } quiet <- function(expr, all = TRUE) { if (Sys.info()["sysname"] == "Windows") { file <- "NUL" } else { file <- "/dev/null" } if (all) { suppressWarnings(suppressMessages(suppressPackageStartupMessages(capture.output(expr, file = file)))) } else { capture.output(expr, file = file) } } quiet(install_python_modules()) }}, error = function(e) { packageStartupMessage("Unable to install python modules igraph and leidenalg") packageStartupMessage("run in terminal:") packageStartupMessage("conda install -n r-reticulate -c conda-forge vtraag python-igraph pandas umap learn")}, finally = packageStartupMessage("python modules igraph and leidenalg installed"))
25: fun(libname, pkgname)
26: doTryCatch(return(expr), name, parentenv, handler)
27: tryCatchOne(expr, names, parentenv, handlers[[1L]])
28: tryCatchList(expr, classes, parentenv, handlers)
29: tryCatch(fun(libname, pkgname), error = identity)
30: runHook(".onAttach", ns, dirname(nspath), nsname)
31: attachNamespace(ns, pos = pos, deps, exclude, include.only)
32: doTryCatch(return(expr), name, parentenv, handler)
33: tryCatchOne(expr, names, parentenv, handlers[[1L]])
34: tryCatchList(expr, classes, parentenv, handlers)
35: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
36: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)
37: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
38: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE))
39: doTryCatch(return(expr), name, parentenv, handler)
40: tryCatchOne(expr, names, parentenv, handlers[[1L]])
41: tryCatchList(expr, classes, parentenv, handlers)
42: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
43: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)))
44: tools:::.test_load_package("leiden", "/home/ali/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-leiden/00new")
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault
ERROR: loading failed
* removing ‘/home/ali/R/x86_64-pc-linux-gnu-library/4.0/leiden’
* restoring previous ‘/home/ali/R/x86_64-pc-linux-gnu-library/4.0/leiden’
Warning in install.packages :
installation of package ‘leiden’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmptdXSOS/downloaded_packages’
Warning in install.packages :
converting NULL pointer to R NULL
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] nlme_3.1-152 matrixStats_0.61.0 spatstat.sparse_2.0-0 RcppAnnoy_0.0.19 RColorBrewer_1.1-2
[6] httr_1.4.2 sctransform_0.3.2 tools_4.0.4 utf8_1.2.2 R6_2.5.1
[11] irlba_2.3.3 rpart_4.1-15 KernSmooth_2.23-18 uwot_0.1.10 mgcv_1.8-34
[16] DBI_1.1.1 lazyeval_0.2.2 colorspace_2.0-2 tidyselect_1.1.1 gridExtra_2.3
[21] compiler_4.0.4 plotly_4.10.0 Seurat_4.0.5 scales_1.1.1 lmtest_0.9-38
[26] spatstat.data_2.1-0 ggridges_0.5.3 pbapply_1.5-0 goftest_1.2-3 stringr_1.4.0
[31] digest_0.6.28 spatstat.utils_2.2-0 pkgconfig_2.0.3 htmltools_0.5.2 parallelly_1.28.1
[36] fastmap_1.1.0 htmlwidgets_1.5.4 rlang_0.4.12 shiny_1.7.1 generics_0.1.1
[41] zoo_1.8-9 jsonlite_1.7.2 ica_1.0-2 dplyr_1.0.7 magrittr_2.0.1
[46] patchwork_1.1.1 Matrix_1.3-4 Rcpp_1.0.7 munsell_0.5.0 fansi_0.5.0
[51] abind_1.4-5 reticulate_1.22 lifecycle_1.0.1 yaml_2.2.1 stringi_1.7.5
[56] MASS_7.3-53.1 Rtsne_0.15 plyr_1.8.6 grid_4.0.4 parallel_4.0.4
[61] listenv_0.8.0 promises_1.2.0.1 ggrepel_0.9.1 crayon_1.4.1 miniUI_0.1.1.1
[66] deldir_1.0-6 lattice_0.20-41 cowplot_1.1.1 splines_4.0.4 tensor_1.5
[71] pillar_1.6.4 igraph_1.2.7 spatstat.geom_2.3-0 future.apply_1.8.1 reshape2_1.4.4
[76] codetools_0.2-18 leiden_0.3.7 glue_1.4.2 SeuratObject_4.0.2 data.table_1.14.2
[81] png_0.1-7 vctrs_0.3.8 httpuv_1.6.3 gtable_0.3.0 RANN_2.6.1
[86] purrr_0.3.4 spatstat.core_2.3-0 polyclip_1.10-0 tidyr_1.1.4 scattermore_0.7
[91] future_1.22.1 assertthat_0.2.1 ggplot2_3.3.5 mime_0.12 xtable_1.8-4
[96] later_1.3.0 survival_3.2-10 viridisLite_0.4.0 tibble_3.1.5 cluster_2.1.1
[101] globals_0.14.0 fitdistrplus_1.1-6 ellipsis_0.3.2 ROCR_1.0-11
Any suggestions?
I use command "install.packages('leiden') " in R to install 'leiden' package but it showed error as below.
R version is 4.1.2
Thank you so much for your help!
Is it possible to use bipartite graphs? It is supported in the python version of the package so I wonder how one could implement it in the R version.
Hi! I'm trying to install the leiden package on a Mac macOS Catalina. However, when I try to install the package, I observe the following error:
install.packages('leiden')
There is a binary version available but the source version is later:
binary source needs_compilation
leiden 0.3.6 0.3.7 FALSE
installing the source package 'leiden'
trying URL 'https://cran.rstudio.com/src/contrib/leiden_0.3.7.tar.gz'
Content type 'application/x-gzip' length 3122097 bytes (3.0 MB)
==================================================
downloaded 3.0 MB
* installing *source* package ‘leiden’ ...
** package ‘leiden’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
sh: line 1: 40574 Killed: 9 R_TESTS= '/Library/Frameworks/R.framework/Resources/bin/R' --no-save --no-restore --no-echo 2>&1 < '/var/folders/29/krs6nhk11kbgn22kgsjkqx9r0000gp/T//RtmpCLdaio/file9e6bcd34755'
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/leiden’
Warning in install.packages :
installation of package 'leiden' had non-zero exit status
Here is my sessionInfo:
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 lattice_0.20-41 prettyunits_1.1.1
[4] Rsamtools_2.6.0 Biostrings_2.58.0 assertthat_0.2.1
[7] BiocFileCache_1.14.0 R6_2.5.0 GenomeInfoDb_1.26.2
[10] stats4_4.0.3 RSQLite_2.2.3 httr_1.4.2
[13] pillar_1.4.7 zlibbioc_1.36.0 rlang_0.4.10
[16] GenomicFeatures_1.42.1 progress_1.2.2 curl_4.3
[19] rstudioapi_0.13 blob_1.2.1 S4Vectors_0.28.1
[22] Matrix_1.2-18 BiocParallel_1.24.1 stringr_1.4.0
[25] RCurl_1.98-1.2 bit_4.0.4 biomaRt_2.46.1
[28] DelayedArray_0.16.1 compiler_4.0.3 rtracklayer_1.50.0
[31] pkgconfig_2.0.3 askpass_1.1 BiocGenerics_0.36.0
[34] openssl_1.4.3 tidyselect_1.1.0 SummarizedExperiment_1.20.0
[37] tibble_3.0.5 GenomeInfoDbData_1.2.4 IRanges_2.24.1
[40] matrixStats_0.57.0 XML_3.99-0.5 crayon_1.3.4
[43] dplyr_1.0.3 dbplyr_2.0.0 GenomicAlignments_1.26.0
[46] bitops_1.0-6 rappdirs_0.3.1 grid_4.0.3
[49] lifecycle_0.2.0 DBI_1.1.1 magrittr_2.0.1
[52] stringi_1.5.3 cachem_1.0.1 XVector_0.30.0
[55] xml2_1.3.2 ellipsis_0.3.1 generics_0.1.0
[58] vctrs_0.3.6 tools_4.0.3 bit64_4.0.5
[61] Biobase_2.50.0 glue_1.4.2 purrr_0.3.4
[64] hms_1.0.0 MatrixGenerics_1.2.0 parallel_4.0.3
[67] fastmap_1.0.1 AnnotationDbi_1.52.0 GenomicRanges_1.42.0
[70] memoise_2.0.0
I'm not sure what in particular is triggering this error. I would sincerely appreciate any help you can provide! Thanks so much!
hi,
I am using leiden algorithm and I wonder how can be decide the best resolution parameter and number of iterations? Is "n_iteration" parameter in leiden function performes the iteration or shouldr we run the code multiple times?
tank you,
Elif.
Hi! I'm trying to install the leiden package on a CentOS7. However, when I try to install the package, I observe the following error:
install.packages('leiden')
Installing package into ‘/home/shiny/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://mirrors.bfsu.edu.cn/CRAN/src/contrib/leiden_0.3.9.tar.gz'
Content type 'application/octet-stream' length 3091497 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
The downloaded source packages are in
‘/tmp/RtmpcIft83/downloaded_packages’
Warning message:
In install.packages("leiden") :
installation of package ‘leiden’ had non-zero exit status
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS: /usr/local/lib64/R/lib/libRblas.so
LAPACK: /usr/local/lib64/R/lib/libRlapack.so
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
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2
Few months (Late may) back I installed Leiden R package and performed clustering on my data with the seed parameter as '123'. Yesterday I installed Leiden R package in my new system and tried to reproduce the results with the same data and also with the seed parameter as '123' (basically using the same old script as is). I am getting a different result compared to last time. I am not sure which version of the package I used few months back - I tried to reproduce my old results using the last three versions of Leiden R package (0.3.9, 0.3.8 and 0.3.7). Although the results are matching among different versions but they don't match my old results. Is there any other dependent package of Leiden I should worry about with respect to version control? Any ideas to reproduce my old results?
Hello,
Could it be possible to add support for the attribute consider_empty_community
of leidenalg.Optimiser
?
A potential use case of this attribute is to better control the maximum number of clusters discovered, see the corresponding issue #89.
Digging through the code, I think it only amounts to add the following lines in leiden::find_paritition
, after L109:
if(py_has_attr(self.optimiser, "consider_empty_community")){
py_set_attr(self.optimiser, "consider_empty_community", r_to_py(as.logical(empty_community)))
}
and add an empty_community
argument to each parent function.
Hi there, I'm attempting to install leiden
on CentOS 7.9.2009 and have encountered the following installation error. Would appreciate any assistance. Thanks!
> install.packages("leiden")
Installing package into ‘/home/an252/R-4.2.1/library’
(as ‘lib’ is unspecified)
trying URL 'https://mirrors.nics.utk.edu/cran/src/contrib/leiden_0.4.3.tar.gz'
Content type 'application/x-gzip' length 3246718 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
* installing *source* package ‘leiden’ ...
** package ‘leiden’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
sh: line 1: 15516 Segmentation fault R_TESTS= '/n/app/R/4.2.1-gcc-9.2.0/lib64/R/bin/R' --no-save --no-restore --no-echo 2>&1 < '/tmp/Rtmpz2zILL/file3c7f4ff851a1'
*** caught segfault ***
address 0x90, cause 'memory not mapped'
Traceback:
1: py_initialize(config$python, config$libpython, config$pythonhome, config$virtualenv_activate, config$version >= "3.0", interactive(), numpy_load_error)
2: (function() { Sys.setenv(PYTHONPATH = newpythonpath) on.exit(Sys.setenv(PYTHONPATH = oldpythonpath), add = TRUE) py_initialize(config$python, config$libpython, config$pythonhome, config$virtualenv_activate, config$version >= "3.0", interactive(), numpy_load_error)})()
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({ oldpythonpath <- Sys.getenv("PYTHONPATH") newpythonpath <- Sys.getenv("RETICULATE_PYTHONPATH", unset = paste(config$pythonpath, system.file("python", package = "reticulate"), sep = .Platform$path.sep)) local({ Sys.setenv(PYTHONPATH = newpythonpath) on.exit(Sys.setenv(PYTHONPATH = oldpythonpath), add = TRUE) py_initialize(config$python, config$libpython, config$pythonhome, config$virtualenv_activate, config$version >= "3.0", interactive(), numpy_load_error) })}, error = function(e) { Sys.setenv(PATH = oldpath) if (is.na(curr_session_env)) { Sys.unsetenv("R_SESSION_INITIALIZED") } else { Sys.setenv(R_SESSION_INITIALIZED = curr_session_env) } stop(e)})
7: initialize_python(required_module, use_environment)
8: ensure_python_initialized(required_module = module)
9: import(module)
10: doTryCatch(return(expr), name, parentenv, handler)
11: tryCatchOne(expr, names, parentenv, handlers[[1L]])
12: tryCatchList(expr, classes, parentenv, handlers)
13: tryCatch({ import(module) TRUE}, error = clear_error_handler(FALSE))
14: reticulate::py_module_available("pandas")
15: fun(libname, pkgname)
16: doTryCatch(return(expr), name, parentenv, handler)
17: tryCatchOne(expr, names, parentenv, handlers[[1L]])
18: tryCatchList(expr, classes, parentenv, handlers)
19: tryCatch(fun(libname, pkgname), error = identity)
20: runHook(".onAttach", ns, dirname(nspath), nsname)
21: attachNamespace(ns, pos = pos, deps, exclude, include.only)
22: doTryCatch(return(expr), name, parentenv, handler)
23: tryCatchOne(expr, names, parentenv, handlers[[1L]])
24: tryCatchList(expr, classes, parentenv, handlers)
25: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return && !quietly) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
26: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)
27: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
28: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE))
29: doTryCatch(return(expr), name, parentenv, handler)
30: tryCatchOne(expr, names, parentenv, handlers[[1L]])
31: tryCatchList(expr, classes, parentenv, handlers)
32: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call, nlines = 1L) prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
33: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)))
34: tools:::.test_load_package("leiden", "/home/an252/R-4.2.1/library/00LOCK-leiden/00new")
An irrecoverable exception occurred. R is aborting now ...
ERROR: loading failed
* removing ‘/home/an252/R-4.2.1/library/leiden’
The downloaded source packages are in
‘/tmp/Rtmp6ZFOiM/downloaded_packages’
Warning message:
In install.packages("leiden") :
installation of package ‘leiden’ had non-zero exit status
>
Hello Tom,
Thank you for the R version of this algorithm. I created some modules/communities by using this algortihm but how can I extract them to visualize in another tool, like cytoscape? R is not good at visualization, I want each module seperately.
Also, is there any source to define the "resolution_parameter" ? Is there any optimal value for this parameter?
Thanks.
Support for Bipartite graphs has been implemented: #5
Maximum community size is supported in regular and multiplexed graphs: #8
Currently the max_comm_size
parameter is passed to internal functions for bipartite graphs but does not change the results. As shown [here], this feature is supported in Python so the issue is calling it internally in R via reticulate.
Hello,
I have been having some issues installing your package for R. After I install, the following occurs:
> library(leiden)
Unable to set up conda environment r-reticulate
run in terminal:
conda init
conda create -n r-reticulate
conda environment r-reticulate installed
Unable to install python modules igraph and leidenalg
run in terminal:
conda install -n r-reticulate -c conda-forge vtraag python-igraph pandas umap learn
python modules igraph and leidenalg installed
Then, when I go to use the algorithm as follows, I get I an error:
> FindClusters(COUNTS3,method = "igraph",algorithm = 4,resolution = 1)
Error: Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).
I have tried to do pip install leidenalg
and the issue is not resolved.
What do I do?
Hi Tom,
I've used leiden on a number of clustering runs with great results! However, I'm trying to cluster ~110,000 cells from a cyTOF experiment with 36 channels and I'm receiving an error on the number of vertices;
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: no such vertex: '1e+05'
7.
stop(structure(list(message = "ValueError: no such vertex: '1e+05'",
call = py_call_impl(callable, dots$args, dots$keywords),
cppstack = NULL), class = c("Rcpp::exception", "C++Error",
"error", "condition")))
6.
py_graph$add_edges(r_to_py(edgelist))
5.
make_py_graph.igraph(object, weights = weights)
4.
make_py_graph(object, weights = weights)
3.
leiden.igraph(object, partition_type = partition_type, weights = weights,
node_sizes = node_sizes, resolution_parameter = resolution_parameter,
seed = seed, n_iterations = n_iterations, degree_as_node_size = degree_as_node_size,
laplacian = laplacian)
2.
leiden.Matrix(adjacency_matrix, resolution_parameter = clusterResolution)
1.
leiden::leiden(adjacency_matrix, resolution_parameter = clusterResolution)
I am using a standard workflow that has been successful with smaller clustering runs;
snn <- as.data.frame(t(RANN::nn2(dataToCluster, k = numNeighbours)$nn.idx))
edge_list <- tidyr::gather(snn)
edge_list <- apply(edge_list, 2, as.numeric)
graph <- igraph::graph_from_edgelist(edge_list, directed=FALSE)
adjacency_matrix <- igraph::as_adjacency_matrix(graph)
partition <- leiden::leiden(adjacency_matrix, resolution_parameter = clusterResolution)
Is there currently a limitation on the number of cells?
Here is the session info
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252
[4] LC_NUMERIC=C LC_TIME=English_Ireland.1252
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] leiden_0.3.6 MISSILe_0.1.0 colorspace_1.4-1
[4] Rtsne_0.15 uwot_0.1.8 Matrix_1.2-18
[7] ggplot2_3.3.2 phonTools_0.2-2.1 purrr_0.3.4
[10] ConsensusClusterPlus_1.52.0 FlowSOM_1.20.0 igraph_1.2.6
[13] CATALYST_1.12.2 SingleCellExperiment_1.10.1 SummarizedExperiment_1.18.2
[16] DelayedArray_0.14.1 matrixStats_0.57.0 Biobase_2.48.0
[19] GenomicRanges_1.40.0 GenomeInfoDb_1.24.2 IRanges_2.22.2
[22] S4Vectors_0.26.1 BiocGenerics_0.34.0 dplyr_1.0.2
[25] MASS_7.3-53 colorRamps_2.3 gatepoints_0.1.3
[28] flowCore_2.1.2
loaded via a namespace (and not attached):
[1] reticulate_1.18 tidyselect_1.1.0 lme4_1.1-23
[4] grid_4.0.2 BiocParallel_1.22.0 devtools_2.3.2
[7] munsell_0.5.0 codetools_0.2-16 statmod_1.4.35
[10] withr_2.3.0 batchelor_1.4.0 knitr_1.30
[13] rstudioapi_0.11 GenomeInfoDbData_1.2.3 polyclip_1.10-0
[16] pheatmap_1.0.12 flowWorkspace_4.0.6 rprojroot_1.3-2
[19] vctrs_0.3.4 generics_0.0.2 TH.data_1.0-10
[22] xfun_0.18 R6_2.4.1 ggbeeswarm_0.6.0
[25] clue_0.3-57 rsvd_1.0.3 locfit_1.5-9.4
[28] bitops_1.0-6 assertthat_0.2.1 scales_1.1.1
[31] multcomp_1.4-14 beeswarm_0.2.3 gtable_0.3.0
[34] processx_3.4.4 RProtoBufLib_2.1.0 sandwich_3.0-0
[37] rlang_0.4.8 GlobalOptions_0.1.2 splines_4.0.2
[40] hexbin_1.28.1 yaml_2.2.1 reshape2_1.4.4
[43] abind_1.4-5 backports_1.1.10 RBGL_1.64.0
[46] usethis_1.6.3 tools_4.0.2 ellipsis_0.3.1
[49] RColorBrewer_1.1-2 sessioninfo_1.1.1 ggridges_0.5.2
[52] Rcpp_1.0.5 plyr_1.8.6 base64enc_0.1-3
[55] zlibbioc_1.34.0 RCurl_1.98-1.2 prettyunits_1.1.1
[58] ps_1.4.0 GetoptLong_1.0.4 viridis_0.5.1
[61] cowplot_1.1.0 zoo_1.8-8 haven_2.3.1
[64] ggrepel_0.8.2 cluster_2.1.0 fs_1.5.0
[67] tinytex_0.26 magrittr_1.5 ncdfFlow_2.34.0
[70] data.table_1.13.0 magick_2.5.2 openxlsx_4.2.2
[73] circlize_0.4.10 RANN_2.6.1 mvtnorm_1.1-1
[76] pkgload_1.1.0 hms_0.5.3 evaluate_0.14
[79] XML_3.99-0.5 rio_0.5.16 jpeg_0.1-8.1
[82] readxl_1.3.1 gridExtra_2.3 shape_1.4.5
[85] ggcyto_1.16.0 testthat_2.3.2 compiler_4.0.2
[88] scater_1.16.2 tibble_3.0.4 KernSmooth_2.23-17
[91] crayon_1.3.4 minqa_1.2.4 htmltools_0.5.0
[94] tidyr_1.1.2 RcppParallel_5.0.2 ComplexHeatmap_2.4.3
[97] rappdirs_0.3.1 boot_1.3-25 car_3.0-10
[100] diffcyt_1.8.8 cli_2.1.0 forcats_0.5.0
[103] pkgconfig_2.0.3 foreign_0.8-80 xml2_1.3.2
[106] vipor_0.4.5 XVector_0.28.0 drc_3.0-1
[109] stringr_1.4.0 callr_3.5.1 digest_0.6.26
[112] tsne_0.1-3 graph_1.66.0 rmarkdown_2.4
[115] cellranger_1.1.0 edgeR_3.30.3 DelayedMatrixStats_1.10.1
[118] curl_4.3 gtools_3.8.2 rjson_0.2.20
[121] nloptr_1.2.2.2 lifecycle_0.2.0 nlme_3.1-148
[124] jsonlite_1.7.1 carData_3.0-4 BiocNeighbors_1.6.0
[127] desc_1.2.0 viridisLite_0.3.0 limma_3.44.3
[130] fansi_0.4.1 pillar_1.4.6 lattice_0.20-41
[133] plotrix_3.7-8 pkgbuild_1.1.0 survival_3.1-12
[136] remotes_2.2.0 glue_1.4.2 zip_2.1.1
[139] png_0.1-7 Rgraphviz_2.32.0 stringi_1.5.3
[142] nnls_1.4 BiocSingular_1.4.0 CytoML_2.0.5
[145] latticeExtra_0.6-29 memoise_1.1.0 cytolib_2.1.18
[148] irlba_2.3.3
I kept running into failed installations with:
devtools::install_github("TomKellyGenetics/leiden")
Which would crash out w/ the following error message:
* installing *source* package ‘leiden’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
Error : (converted from warning) /private/var/folders/3w/9cctnv1n61q330djgstsfl7c00019l/T/RtmpbTeXmo/R.INSTALL14881221553c2/leiden/man/leiden.Rd:37: unknown macro '\n'
ERROR: installing Rd objects failed for package ‘leiden’
I forked and removed two "\n" in man/leiden.Rd
and was then able to install from my forked repo successfully--I'm not sure if this issue is affecting anyone else?
Other graph-based methods have used the Graph Laplacian instead of the adjacency matrix. For example:
https://github.com/hayamizu-lab/treefit-r
This may be a desirable approach. A method to compute the Laplacian from an 'igraph' input and use it to compute weights. Weights could also be derived from a Laplacian matrix instead of an adjacency.
I am having this issue with Leiden running a large an adjacency matrix generated from sNN as follows;
g <- buildSNNGraph(sce, k=20, use.dimred="PCA" ,BPPARAM=MulticoreParam(30), type="jaccard")
g.am<-as_adjacency_matrix(g)
str(g.am)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:24346684] 851 1247 1353 2898 3266 3779 4053 4100 4360 4707 ...
..@ p : int [1:99193] 0 189 418 525 607 841 1034 1195 1408 1563 ...
..@ Dim : int [1:2] 99192 99192
..@ Dimnames:List of 2
.. ..$ : NULL
.. ..$ : NULL
..@ x : num [1:24346684] 1 1 1 1 1 1 1 1 1 1 ...
..@ factors : list()
partition<-leiden(g.am)
After about an hour of run, I run into a following error;
Error in r_to_py_impl(converted, convert = convert) :
Evaluation error: 351 arguments passed to .Internal(.addCondHands) which requires 5.
if I set sNN k=10, Leiden works just fine but at k=20, it fails.
Any input will be appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.