theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
412 stars 102 forks source link

scv.tl.velocity_graph(adata) has bug that it can't be run #1243

Closed rabbitpang closed 5 months ago

rabbitpang commented 5 months ago

I tried to run RNA velocity by following the tutorial of RNA velocity basics with following link https://scvelo.readthedocs.io/en/latest/VelocityBasics.html#

I follow the code exactly based on the link However, when at the step running scv.tl.velocity_graph(adata) there is the error : ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part. it would be great If you can fix the bug, so I can run RNA velocity. Really appreciate it, thank you very much! ...

# paste your code here, if applicable

scv.tl.velocity_graph(adata)

ValueError Traceback (most recent call last) Cell In[26], line 1 ----> 1 scv.tl.velocity_graph(adata) File ~/miniconda3/envs/MultiVelo/lib/python3.8/site-packages/scvelo/tools/velocity_graph.py:363, in velocity_graph(data, vkey, xkey, tkey, basis, n_neighbors, n_recurse_neighbors, random_neighbors_at_max, sqrt_transform, variance_stabilization, gene_subset, compute_uncertainties, approx, mode_neighbors, copy, n_jobs, backend) 359 n_jobs = get_n_jobs(n_jobs=n_jobs) 360 logg.info( 361 f"computing velocity graph (using {n_jobs}/{os.cpu_count()} cores)", r=True 362 ) --> 363 vgraph.compute_cosines(n_jobs=n_jobs, backend=backend) 365 adata.uns[f"{vkey}_graph"] = vgraph.graph 366 adata.uns[f"{vkey}_graph_neg"] = vgraph.graph_neg File ~/miniconda3/envs/MultiVelo/lib/python3.8/site-packages/scvelo/tools/velocity_graph.py:175, in VelocityGraph.compute_cosines(self, n_jobs, backend) 172 n_obs = self.X.shape[0] 174 # TODO: Use batches and vectorize calculation of dX in self._calculate_cosines --> 175 res = parallelize( 176 self._compute_cosines, 177 range(self.X.shape[0]), 178 n_jobs=n_jobs, 179 unit="cells", 180 backend=backend, 181 )() 182 uncertainties, vals, rows, cols = map(_flatten, zip(*res)) 184 vals = np.hstack(vals) File ~/miniconda3/envs/MultiVelo/lib/python3.8/site-packages/scvelo/core/_parallelize.py:138, in parallelize..wrapper(*args, **kwargs) 126 pbar, queue, thread = None, None, None 128 res = Parallel(n_jobs=n_jobs, backend=backend)( 129 delayed(callback)( 130 *((i, cs) if use_ixs else (cs,)), (...) 135 for i, cs in enumerate(collections) 136 ) --> 138 res = np.array(res) if as_array else res 139 if thread is not None: 140 thread.join() ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part. Error output ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part. ```pytb # paste the error output here, if applicable ```
Versions ```pytb # paste the ouput of scv.logging.print_versions() here ``` Running scvelo 0.2.5 (python 3.8.16) on 2024-04-29 00:13.
WeilerP commented 5 months ago

Already fixed in fixed in #1059. Please use the latest version of scvelo, and check existing and closed issues before opening a new on.