scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.9k stars 597 forks source link

sc.tl.leiden, restrict_to function not properly working #2906

Open simonekats opened 7 months ago

simonekats commented 7 months ago

Please make sure these conditions are met

What happened?

Tried to run this function: sc.tl.leiden(test, resolution = 0.1, restrict_to = ('leiden', ['5']))

and instead it is subsetting cluster 5 into over 400 new subsets, even with my resolution set to 0.1. I've also tried different resolutions and none of them work, it ignores the resolution altogether. leiden

Minimal code sample

sc.tl.leiden(test, resolution = 0.1, restrict_to = ('leiden', ['5']))

Error output

No response

Versions

``` ----- anndata 0.10.3 scanpy 1.9.6 ----- PIL 10.0.1 appnope 0.1.2 asttokens NA attr 23.1.0 bottleneck 1.3.5 brotli NA celltypist 1.6.2 certifi 2023.11.17 cffi 1.16.0 chardet 4.0.0 charset_normalizer 2.0.4 cloudpickle 2.2.1 colorama 0.4.6 comm 0.1.2 cycler 0.10.0 cython_runtime NA cytoolz 0.12.2 dask 2022.7.0 dateutil 2.8.2 debugpy 1.6.7 decorator 5.1.1 decoupler 1.5.0 defusedxml 0.7.1 dill 0.3.7 docrep 0.3.2 entrypoints 0.4 exceptiongroup 1.2.0 executing 0.8.3 fsspec 2023.10.0 h5py 3.7.0 idna 3.4 igraph 0.10.8 inflect NA ipykernel 6.28.0 ipython_genutils 0.2.0 jedi 0.18.1 jinja2 3.1.3 joblib 1.3.2 jupyter_server 1.23.4 kiwisolver 1.4.4 leidenalg 0.10.1 llvmlite 0.42.0 louvain 0.8.1 lz4 4.3.2 markupsafe 2.1.3 matplotlib 3.8.0 matplotlib_inline 0.1.6 mpl_toolkits NA natsort 8.4.0 numba 0.59.0 numexpr 2.8.7 numpy 1.26.3 omnipath 1.0.8 packaging 23.1 pandas 2.1.4 parso 0.8.3 patsy 0.5.6 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA platformdirs 3.10.0 plotly 5.9.0 prompt_toolkit 3.0.43 psutil 5.9.0 ptyprocess 0.7.0 pure_eval 0.2.2 pycparser 2.21 pydantic 1.10.12 pydev_ipython NA pydevconsole NA pydevd 2.9.5 pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pygments 2.15.1 pynndescent 0.5.11 pyparsing 3.0.9 pytz 2023.3.post1 requests 2.31.0 ruamel NA scipy 1.11.4 seaborn 0.12.2 session_info 1.0.0 setuptools 65.6.3 six 1.16.0 sklearn 1.4.1.post1 snappy NA socks 1.7.1 sparse 0.14.0 sphinxcontrib NA stack_data 0.2.0 statsmodels 0.14.1 tblib 1.7.0 texttable 1.7.0 threadpoolctl 2.2.0 tlz 0.12.2 toolz 0.12.0 torch 1.12.1 tornado 6.1 tqdm 4.65.0 traitlets 5.7.1 typing_extensions NA umap 0.5.5 urllib3 1.26.18 wcwidth 0.2.5 wrapt 1.14.1 yaml 6.0.1 zipp NA zmq 25.1.2 zoneinfo NA zope NA zstandard 0.19.0 ----- IPython 8.20.0 jupyter_client 7.3.4 jupyter_core 5.5.0 jupyterlab 3.5.3 notebook 6.5.2 ----- Python 3.10.13 (main, Sep 11 2023, 08:16:02) [Clang 14.0.6 ] macOS-14.1.2-arm64-arm-64bit ----- Session information updated at 2024-03-12 14:52 ​ ```
ivirshup commented 7 months ago

Thanks for the report. I'm having trouble reproducing this behaviour locally.

Two thoughts:

  1. It looks like there's a newer version of leidenalg available, could you upgrade that?
  2. Maybe there is something about the neighborhood graph. Could you either: reproduce this with some dummy data (e.g. sc.datasets.blobs) or share the test object?