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

preprocessing data error :TypeError: Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices' #6

Open
yangqianBLCU opened this issue Jul 18, 2024 · 5 comments

Comments

@yangqianBLCU
Copy link

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

TypeError Traceback (most recent call last)
Cell In[70], line 2
1 n_gene = 2000
----> 2 vv.preprocess(adata_c, n_gene,compute_umap=True,perform_clustering=True)

File ~/miniconda3/envs/VeloVAE/lib/python3.10/site-packages/velovae/preprocessing.py:340, in preprocess(adata, n_gene, cluster_key, tkey, selection_method, min_count_per_cell, min_genes_expressed, min_shared_counts, min_shared_cells, min_counts_s, min_cells_s, max_counts_s, max_cells_s, min_counts_u, min_cells_u, max_counts_u, max_cells_u, npc, n_neighbors, genes_retain, perform_clustering, resolution, compute_umap, umap_min_dist, keep_raw, **kwargs)
327 filter_genes(adata,
328 min_counts=min_counts_s,
329 min_cells=min_cells_s,
(...)
335 max_cells_u=max_cells_u,
336 retain_genes=genes_retain)
338 # 2. KNN Averaging
339 # remove_duplicate_cells(adata)
--> 340 moments(adata, n_pcs=npc, n_neighbors=n_neighbors)
342 if keep_raw:
343 print("Keep raw unspliced/spliced count data.")

File ~/miniconda3/envs/VeloVAE/lib/python3.10/site-packages/velovae/scvelo_preprocessing/moments.py:66, in moments(data, n_neighbors, n_pcs, mode, method, use_rep, copy)
64 use_rep = "X_pca"
65 print(f"Computing the KNN graph based on {use_rep}")
---> 66 neighbors(
67 adata, n_neighbors=n_neighbors, use_rep=use_rep, n_pcs=n_pcs, method=method
68 )
...
161 )
162 logg.switch_verbosity("on", module="scanpy")
164 adata.uns["neighbors"] = {}

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

@g-yichen
Copy link
Collaborator

Hi,

This is due to a mismatch of update in scanpy and scvelo. It has been fixed in a new version (see this github page). The preprocessing function in our package is adapted from scVelo for convenience. You can directly use scVelo to preprocess the data and train the model without any problem.

Meanwhile, we will fix this issue as soon as possible. My apologies for the inconvenience!

Thank you!

@yangqianBLCU
Copy link
Author

I have solve the error "write_knn_indices", and only trian VeloVAE. Then i will run Post-Training Analysis Compute the Metrics and Plot the Genes, cluster_edges = [('Ngn3 low EP', 'Ngn3 high EP'),
('Ngn3 high EP', 'Pre-endocrine'),
('Pre-endocrine', 'Delta'),
('Pre-endocrine', 'Beta'),
('Pre-endocrine', 'Epsilon'),
('Pre-endocrine', 'Alpha')]
methods = ['VeloVAE']
keys = ['vae']
grid_size = (1,2)
res, res_type = vv.post_analysis(adata,
'continuous',
methods,
keys,
compute_metrics=True,
raw_count=False,
grid_size=(1,2),
figure_path=figure_path,
cluster_edges=cluster_edges)
error happen:
KeyError Traceback (most recent call last)
Cell In[42], line 10
8 keys = ['vae']
9 grid_size = (1,2)
---> 10 res, res_type = vv.post_analysis(adata,
11 'continuous',
12 methods,
13 keys,
14 compute_metrics=True,
15 raw_count=False,
16 grid_size=(1,2),
17 figure_path=figure_path,
18 cluster_edges=cluster_edges)

File ~/miniconda3/envs/VeloVAE/lib/python3.10/site-packages/velovae/analysis/evaluation.py:455, in post_analysis(adata, test_id, methods, keys, gene_key, compute_metrics, raw_count, genes, plot_type, cluster_key, cluster_edges, nplot, frac, embed, grid_size, sparsity_correction, figure_path, save, **kwargs)
453 for i, method in enumerate(methods):
454 if compute_metrics:
--> 455 stats_i, stats_type_i = get_metric(adata,
456 method,
457 keys[i],
458 vkeys[i],
459 cluster_key,
460 gene_key,
461 cluster_edges,
...
-> 1621 nbs = adata.uns['neighbors']['indices']
1623 velocities = adata.layers[vkey]
1624 nan_mask = ~np.isnan(velocities[0]) if gene_mask is None else gene_mask

KeyError: 'indices'

@jjia1
Copy link
Contributor

jjia1 commented Aug 7, 2024

I'm also getting the adata.uns['neighbors']['indices'] error. my scanpy object doesn't have indices in the keys.

adata.uns['neighbors'].keys()

> dict_keys(['connectivities_key', 'distances_key', 'params'])

@yangqianBLCU
Copy link
Author

yangqianBLCU commented Aug 13, 2024 via email

@jjia1
Copy link
Contributor

jjia1 commented Aug 15, 2024

@g-yichen bump could you check my PR? I think I fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants