This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Leiden algorithm not working R studio scRNAseq

Hi,

I would like to use the Leiden algorithm on my scRNAseq to identify the clusters but I cannot run the algorithm. If I use the default one I have no problem. I tried :

 FindClusters(immune.combined, resolution = 0.3, algorithm = 4)

but it gives me this error:

Error: Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).


In addition: Warning message:
In system2(command = python, args = shQuote(script), stdout = TRUE,  :
  running command ''/Users/camilla/.virtualenvs/r-reticulate/bin/python' '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/config/config.py' 2>/dev/null' had status 1

I have reticulate package but when I try to install leidenAlg it install it in a folder I have never seen

The downloaded binary packages are in
    /var/folders/w2/826prqh14cq_pjljhh87q2lh0000gq/T//RtmpkPBi5K/downloaded_packages

and when I try to load it :

library(reticulate)
library('leidenAlg')
library(Matrix)

it gives me this error:

Loading required package: Matrix
Error in value[[3L]](cond) : 
  Package ‘Matrix’ version 1.5.4.1 cannot be unloaded:
 Error in unloadNamespace(package) : namespace ‘Matrix’ is imported by ‘SummarizedExperiment’, ‘SeuratObject’, ‘uwot’, ‘S4Arrays’, ‘spatstat.data’, ‘survival’, ‘spatstat.explore’, ‘DelayedArray’, ‘leiden’, ‘TFisher’, ‘irlba’, ‘reticulate’, ‘spatstat.sparse’, ‘sctransform’, ‘Seurat’ so cannot be unloaded

Why it gives me so many errors? How can I solve it? How can I install pip install leidenalg on R studio?

Thank you

Camilla

scrnaseq r leidenalg reticulate

1 answer

library(reticulate)
py_install("leidenalg")
leidenalg<- import("leidenalg")

See the reticulate docs for more info.

thank you! but now it gives me this error :

note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for leidenalg
Failed to build leidenalg
ERROR: Could not build wheels for leidenalg, which is required to install pyproject.toml-based projects
Error: Error installing package(s): "'leidenalg'"
In addition: Warning message:
In system2(command = python, args = shQuote(script), stdout = TRUE,  :
  running command ''/Users/camilla/.virtualenvs/r-reticulate/bin/python' '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/config/config.py' 2>/dev/null' had status 1

Maybe a compiler error, impossible to know without more info. Make sure gcc and g++ are installed on your system.

I'd probably just make a new environment and install it with conda. Read more here. leidenalg is available via conda in conda-forge.

Log in to answer this question.