ys-zong / conST

conST: an interpretable multi-modal contrastive learning framework for spatial transcriptomics
MIT License
22 stars 4 forks source link

leidenalg issue #3

Closed nikhilmehta16 closed 1 year ago

nikhilmehta16 commented 1 year ago

Hey,

I was trying to run your code on my local but leidenalg keeps giving this error: BaseException: Could not construct partition: Weight vector not the same size as the number of edges. I have tried using every version of leidenalg from 0.7.0 to 0.9.0. Do you happen to know any work around.

Complete Error Message: `BaseException Traceback (most recent call last) /tmp/ipykernel_58748/2566975975.py in 35 sc.pp.neighbors(adata_conST, n_neighbors=params.eval_graph_n) 36 ---> 37 eval_resolution = res_search_fixed_clus(adata_conST, n_clusters) 38 print(eval_resolution) 39 cluster_key = "conST_leiden"

/media/nikhilmehta/New Volume/01IITK/Sem 7/CS690/conST/src/utils_func.py in res_search_fixed_clus(adata, fixed_clus_count, increment) 36 ''' 37 for res in sorted(list(np.arange(0.01, 2.5, increment)), reverse=True): ---> 38 sc.tl.leiden(adata, random_state=0, resolution=res) 39 count_unique_leiden = len(pd.DataFrame(adata.obs['leiden']).leiden.unique()) 40 if count_unique_leiden == fixed_clus_count:

~/anaconda3/envs/cs690/lib/python3.7/site-packages/scanpy/tools/_leiden.py in leiden(adata, resolution, restrict_to, random_state, key_added, adjacency, directed, use_weights, n_iterations, partition_type, neighbors_key, obsp, copy, partition_kwargs) 142 partition_kwargs['resolution_parameter'] = resolution 143 # clustering proper --> 144 part = leidenalg.find_partition(g, partition_type, partition_kwargs) 145 # store output into adata.obs 146 groups = np.array(part.membership)

~/anaconda3/envs/cs690/lib/python3.7/site-packages/leidenalg/functions.py in find_partition(graph, partition_type, initial_membership, weights, n_iterations, max_comm_size, seed, **kwargs) 81 kwargs['weights'] = weights ... --> 856 singleton partition. 857 858 weights : list of double, or edge attribute

BaseException: Could not construct partition: Weight vector not the same size as the number of edges.`

ys-zong commented 1 year ago

I haven't met this error before. My leidenalg version is 0.8.7.

It seems to me that the error might be from the input data as it says Weight vector not the same size as the number of edges. I wonder what data are you using and can you double-check if the input adata is correct?

nikhilmehta16 commented 1 year ago

First I tried to run your code as it was without making any changes and received this error, next I retrained the model on slice 151507 from the spatialLIBD data set as provided in the Google Drive Link in Readme.md. But still facing with the same error.

ys-zong commented 1 year ago

can you post a link to your adata so that I can check what's going wrong?

nikhilmehta16 commented 1 year ago

@ys-zong I checked the weights of data and found to be equal. When I dig deeper, this issue seems to be related to compatibility of leidenalg and python i-graph, As mentioned scverse/scanpy#2339 on scanpy issues. I tried all the solutions in the comments but was of no success. Could you please provide which exact versions of python-igraph / igraph you were using. Thanks

ys-zong commented 1 year ago

I'm using pythton-igraph 0.9.6

nikhilmehta16 commented 1 year ago

Using leidenalg=0.8.7 an pythton-igraph=0.9.6 finally fixed the issue. I tried various combinations of versions but nothing worked. Also, no solution on scverse/scanpy#2339 was of use.

It would be greate if you can mention this requirement in readme file. Thanks @ys-zong

szhorvat commented 1 year ago

If you use the latest version of both (leidenalg 0.9.0 and igraph 0.10.2), things should work fine. If you see an incompatibility between these specific versions, you should probably report it to leidenalg.