theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
412 stars 102 forks source link

Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices' #1212

Closed akhst7 closed 5 months ago

akhst7 commented 7 months ago

Firing scv.pp.moments(adata, n_pcs=30, n_neighbors=30) runs into an error.
...

import scvelo as scv
scv.settings.verbosity = 3  
scv.settings.presenter_view = True  
scv.set_figure_params('scvelo')  
adata=scv.dataset(bonemarrow)
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)
Error output ```pytb # paste the error output here, if applicable ``` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[22], line 1 ----> 1 scv.pp.moments(adata, n_pcs=30, n_neighbors=30) File [~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/moments.py:63](http://localhost:8888/~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/moments.py#line=62), in moments(data, n_neighbors, n_pcs, mode, method, use_rep, use_highly_variable, copy) 60 normalize_per_cell(adata) 62 if n_neighbors is not None and n_neighbors > get_n_neighs(adata): ---> 63 neighbors( 64 adata, 65 n_neighbors=n_neighbors, 66 use_rep=use_rep, 67 use_highly_variable=use_highly_variable, 68 n_pcs=n_pcs, 69 method=method, 70 ) 71 verify_neighbors(adata) 73 if "spliced" not in adata.layers.keys() or "unspliced" not in adata.layers.keys(): File [~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/neighbors.py:257](http://localhost:8888/~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/neighbors.py#line=256), in neighbors(adata, n_neighbors, n_pcs, use_rep, use_highly_variable, knn, random_state, method, metric, metric_kwds, num_threads, copy) 246 neighbors = _get_hnsw_neighbors( 247 adata=adata, 248 use_rep=use_rep, (...) 254 **metric_kwds, 255 ) 256 elif method in ["umap", "gauss", "rapids"]: --> 257 neighbors = _get_scanpy_neighbors( 258 adata=adata, 259 n_neighbors=n_neighbors, 260 knn=knn, 261 n_pcs=n_pcs, 262 method=method, 263 use_rep=use_rep, 264 random_state=random_state, 265 metric=metric, 266 metric_kwds=metric_kwds, 267 ) 268 else: 269 raise ValueError( 270 f"Provided `method={method}`. Admissible values are `'umap'`, `'sklearn'`, " 271 "`'hnsw'`, `'gauss'`, and `'rapids'`." 272 ) File [~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/neighbors.py:40](http://localhost:8888/~/miniconda3/lib/python3.11/site-packages/scvelo/preprocessing/neighbors.py#line=39), in _get_scanpy_neighbors(adata, **kwargs) 38 warnings.simplefilter("ignore") 39 neighbors = Neighbors(adata) ---> 40 neighbors.compute_neighbors(write_knn_indices=True, **kwargs) 41 logg.switch_verbosity("on", module="scanpy") 43 return neighbors TypeError: Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices'
Versions ```pytb # paste the ouput of scv.logging.print_versions() here ``` scvelo==0.3.1 scanpy==1.10.0.dev219+g3ddf1ee1 anndata==0.10.5.post1 loompy==3.0.7 numpy==1.26.4 scipy==1.12.0 matplotlib==3.8.3 sklearn==1.4.1.post1 pandas==2.2.1 ERROR: XMLRPC request failed [code: -32500] RuntimeError: PyPI no longer supports 'pip search' (or XML-RPC search). Please use https://pypi.org/search (via a browser) instead. See https://warehouse.pypa.io/api-reference/xml-rpc.html#deprecated-methods for more information. ``` My system is as follows; Python 3.11.7 conda 24.1.2 'c. ,xNMM. ----------------------------- .OMMMMo OS: macOS 14.3.1 23D60 x86_64 OMMM0, Host: Mac13,2 .;loddo:' loolloddol;. Kernel: 23.3.0 cKMMMMMMMMMMNWMMMMMMMMMM0: Uptime: 1 hour, 54 mins .KMMMMMMMMMMMMMMMMMMMMMMMWd. Packages: 256 (brew) XMMMMMMMMMMMMMMMMMMMMMMMX. Shell: zsh 5.9 ;MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 3440x1440 :MMMMMMMMMMMMMMMMMMMMMMMM: DE: Aqua .MMMMMMMMMMMMMMMMMMMMMMMMX. WM: Quartz Compositor kMMMMMMMMMMMMMMMMMMMMMMMMWd. WM Theme: Blue (Light) .XMMMMMMMMMMMMMMMMMMMMMMMMMMk Terminal: iTerm2 .XMMMMMMMMMMMMMMMMMMMMMMMMK. Terminal Font: Monaco 10 kMMMMMMMMMMMMMMMMMMMMMMd CPU: Apple M1 Ultra ;KMMMMMMMWXXWMMMMMMMk. GPU: Apple M1 Ultra .cooc,. .,coo:. Memory: 3697MiB / 131072MiB ``` ```
WeilerP commented 7 months ago

@akhst7, I suggest you computer the PCA embedding and neighbor graph directly with the corresponding Scanpy functions, i.e.,

sc.pp.pca(adata)
sc.pp.neighbors(adata, n_pcs=30, n_neighbors=30)

and pass n_pcs=None, n_neighbors=None to moments. That will resolve the issue for now.

akhst7 commented 7 months ago

Thanks. It worked beautifully.

SimonE1220 commented 6 months ago

Unfortunateley same issue here: computing neighbors

TypeError Traceback (most recent call last) in <cell line: 1>() ----> 1 scv.tl.velocity(adata, mode="deterministic")

3 frames /usr/local/lib/python3.10/dist-packages/scvelo/preprocessing/neighbors.py in _get_scanpy_neighbors(adata, kwargs) 38 warnings.simplefilter("ignore") 39 neighbors = Neighbors(adata) ---> 40 neighbors.compute_neighbors(write_knn_indices=True, kwargs) 41 logg.switch_verbosity("on", module="scanpy") 42

TypeError: Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices'

BoyuJiang95 commented 5 months ago

I also encountered same error "Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices'", even I tried:

scv.pp.pca(adata) scv.pp.neighbors(adata, n_pcs=30, n_neighbors=30) scv.pp.moments(n_pcs=None, n_neighbors=None)

YuriPPAN commented 4 months ago

I also encountered same error "Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices'", even I tried:

scv.pp.pca(adata) scv.pp.neighbors(adata, n_pcs=30, n_neighbors=30) scv.pp.moments(n_pcs=None, n_neighbors=None)

Did you solve the problem? I also found the porblem, but it doesn't work.

yifanfu01 commented 3 months ago

Hi guys, @YuriPPAN , @BoyuJiang95 , do you mind that should use sc. rather than scv.? it seems shuttle from scVelo to scanpy.

Alvis-Jiang commented 3 months ago

Hi guys, @YuriPPAN , @BoyuJiang95 , do you mind that should use sc. rather than scv.? it seems shuttle from scVelo to scanpy.

Hi @yifanfu01, thank you! I uesd the sc and now scvelo works well with my data.

Best, Boyu