Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
akhst7 opened this issue Mar 5, 2024 · 7 comments · Fixed by #1233
Closed
Labels
bug Something isn't working

Comments

@akhst7
Copy link

akhst7 commented Mar 5, 2024

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
# 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, 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, 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, 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
# 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

</details>
@akhst7 akhst7 added the bug Something isn't working label Mar 5, 2024
@WeilerP
Copy link
Member

WeilerP commented Mar 5, 2024

@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
Copy link
Author

akhst7 commented Mar 6, 2024

Thanks. It worked beautifully.

@SimonE1220
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@Alvis-Jiang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants