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.paga #1241

Open hvgogogo opened 5 months ago

hvgogogo commented 5 months ago

Hi team, I used the example data to run the scv.tl.page step and encounts the following error. I guess it's the imcompelity with paga.compute_transitions() funtion? many thanks ...

# paste your code here, if applicable
# this is needed due to a current bug - bugfix is coming soon.
data.uns['neighbors']['distances'] = data.obsp['distances']
data.uns['neighbors']['connectivities'] = data.obsp['connectivities']

scv.tl.paga(data, groups='clusters')
df = scv.get_df(adata, 'paga/transitions_confidence', precision=2).T
df.style.background_gradient(cmap='Blues').format('{:.2g}')
running PAGA using priors: ['velocity_pseudotime'] --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[327], line 5 2 data.uns['neighbors']['distances'] = data.obsp['distances'] 3 data.uns['neighbors']['connectivities'] = data.obsp['connectivities'] ----> 5 scv.tl.paga(data, groups='clusters') 6 df = scv.get_df(adata, 'paga/transitions_confidence', precision=2).T 7 df.style.background_gradient(cmap='Blues').format('{:.2g}') File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scvelo/tools/paga.py:288, in paga(adata, groups, vkey, use_time_prior, root_key, end_key, threshold_root_end_prior, minimum_spanning_tree, copy) 285 adata.uns["paga"]["connectivities_tree"] = paga.connectivities_tree 286 adata.uns[f"{groups}_sizes"] = np.array(paga.ns) --> 288 paga.compute_transitions() 289 adata.uns["paga"]["transitions_confidence"] = paga.transitions_confidence 290 adata.uns["paga"]["threshold"] = paga.threshold File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scvelo/tools/paga.py:142, in PAGA_tree.compute_transitions(self) 140 vc = igraph.VertexClustering(g, membership=membership) 141 cg_full = vc.cluster_graph(combine_edges="sum") --> 142 transitions = get_sparse_from_igraph(cg_full, weight_attr="weight") 143 transitions = transitions - transitions.T 144 transitions_conf = transitions.copy() File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scvelo/tools/paga.py:51, in get_sparse_from_igraph(graph, weight_attr) 49 shape = (shape, shape) 50 if len(edges) > 0: ---> 51 return csr_matrix((weights, zip(*edges)), shape=shape) 52 else: 53 return csr_matrix(shape) File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scipy/sparse/_compressed.py:55, in _cs_matrix.__init__(self, arg1, shape, dtype, copy) 52 else: 53 if len(arg1) == 2: 54 # (data, ij) format ---> 55 coo = self._coo_container(arg1, shape=shape, dtype=dtype) 56 arrays = coo._coo_to_compressed(self._swap) 57 self.indptr, self.indices, self.data, self._shape = arrays File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scipy/sparse/_coo.py:99, in _coo_base.__init__(self, arg1, shape, dtype, copy) 96 if dtype is not None: 97 self.data = self.data.astype(dtype, copy=False) ---> 99 self._check() File ~/anaconda3/envs/localpy/lib/python3.9/site-packages/scipy/sparse/_coo.py:188, in _coo_base._check(self) 186 """ Checks data structure for consistency """ 187 if self.ndim != len(self.coords): --> 188 raise ValueError('mismatching number of index arrays for shape; ' 189 f'got {len(self.coords)}, expected {self.ndim}') 191 # index arrays should have integer data types 192 for i, idx in enumerate(self.coords): ValueError: mismatching number of index arrays for shape; got 0, expected 2 Error output ```pytb # paste the error output here, if applicable ```
Versions ```pytb # paste the ouput of scv.logging.print_versions() here scvelo==0.3.2 scanpy==1.10.1 anndata==0.10.7 loompy==3.0.7 numpy==1.26.4 scipy==1.13.0 matplotlib==3.8.4 sklearn==1.4.2 pandas==2.2.2 ```
RongDing-NMU commented 5 months ago

Hello, I met the same problem. o(╥﹏╥)o

hvgogogo commented 5 months ago

Hello, I met the same problem. o(╥﹏╥)o

after screening the codes, i find that the problem arised from function: get_sparse_from_igraph()

it works if you modify the codes from: if len(edges) > 0: return csr_matrix((weights, zip(edges)), shape=shape) to: rows, cols = zip(edges) if len(edges) > 0: return csr_matrix((weights, (rows, cols)), shape=shape)

😃

RongDing-NMU commented 5 months ago

Hello, I met the same problem. o(╥﹏╥)o

after screening the codes, i find that the problem arised from function: get_sparse_from_igraph()

it works if you modify the codes from: if len(edges) > 0: return csr_matrix((weights, zip(edges)), shape=shape) to: rows, cols = zip(edges) if len(edges) > 0: return csr_matrix((weights, (rows, cols)), shape=shape)

😃

I install scipy==1.11.4 to avoid the self._check() error, and solve this problem.

yinan-wan0 commented 4 months ago

I am having the same problem. Installing scipy==1.11.4 got rid of this problem but I got another error instead when running scv.tl.paga: TypeError: sparse array length is ambiguous; use getnnz() or shape[0]

SunYong0821 commented 3 weeks ago

Hello, I met the same problem. o(╥﹏╥)o

after screening the codes, i find that the problem arised from function: get_sparse_from_igraph()

it works if you modify the codes from: if len(edges) > 0: return csr_matrix((weights, zip(edges)), shape=shape) to: rows, cols = zip(edges) if len(edges) > 0: return csr_matrix((weights, (rows, cols)), shape=shape)

😃

it worked!~~~ thx~