welch-lab / VeloVAE

Deep Generative Modeling of RNA Velocity
BSD 3-Clause "New" or "Revised" License
34 stars 5 forks source link

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

Open yangqianBLCU opened 3 months ago

yangqianBLCU commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago
you can try this way. https://blog.csdn.net/weixin_46128755/article/details/138460919?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522172353564416800182156066%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=172353564416800182156066&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-2-138460919-null-null.142^v100^pc_search_result_base8&utm_term=scvelo&spm=1018.2226.3001.4187 yq45646117

@. | ---- Replied Message ---- | From | Johnathan @.> | | Date | 8/8/2024 03:59 | | To | @.> | | Cc | @.>, @.***> | | Subject | Re: [welch-lab/VeloVAE] preprocessing data error :TypeError: Neighbors.compute_neighbors() got an unexpected keyword argument 'write_knn_indices' (Issue #6) |

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'])

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jjia1 commented 2 months ago

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