Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scv.tl.paga #1241

Open
hvgogogo opened this issue Apr 25, 2024 · 5 comments
Open

scv.tl.paga #1241

hvgogogo opened this issue Apr 25, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@hvgogogo
Copy link

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
# paste the error output here, if applicable
Versions
# 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
@hvgogogo hvgogogo added the bug Something isn't working label Apr 25, 2024
@RongDing-NMU
Copy link

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

@hvgogogo
Copy link
Author

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
Copy link

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
Copy link

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
Copy link

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~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants