Leidenalg clustering error in Trajectory inference tutorial

I am trying to replicate this tutorial on trajectory inference. I have followed every step up until clustering, where I try to use sc.tl.leiden(adata) to cluster, but keep having the following error:

BaseException Traceback (most recent call last)
Cell In [15], line 1
----> 1 sc.tl.leiden(adata)

File ~/miniconda3/envs/py39/lib/python3.9/site-packages/scanpy/tools/_leiden.py:144, 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)

File ~/miniconda3/envs/py39/lib/python3.9/site-packages/leidenalg/functions.py:81, in find_partition(graph, partition_type, initial_membership, weights, n_iterations, max_comm_size, seed, **kwargs)
79 if not weights is None:
80 kwargs[‘weights’] = weights
—> 81 partition = partition_type(graph,
82 initial_membership=initial_membership,
83 **kwargs)
84 optimiser = Optimiser()
86 optimiser.max_comm_size = max_comm_size

File ~/miniconda3/envs/py39/lib/python3.9/site-packages/leidenalg/VertexPartition.py:855, in RBConfigurationVertexPartition.init(self, graph, initial_membership, weights, node_sizes, resolution_parameter)
851 else:
852 # Make sure it is a list
853 node_sizes = list(node_sizes)
→ 855 self._partition = _c_leiden._new_RBConfigurationVertexPartition(pygraph_t,
856 initial_membership, weights, node_sizes, resolution_parameter)
857 self._update_internal_membership()

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

Does anyone know why this doesn’t work? I assumed weight and edges would be taken from adata.obsp[‘connectivities’], the default storage output of sc.pp.neighbors adjacency graph.

1 Like

On Python 3.7 and a clean conda install from 2 days ago sc.tl.leiden throws the same error.

I had the same issue, would you be able to make an issue at scanpy? I noticed installing leidenalg with pip fixes the issue.

1 Like

Installing with pip didn’t work for me. Can you give more details on your setup?