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

CellChat AttributeError: 'SparseCSRView' object has no attribute 'A' #135

Open
AmyOlex opened this issue Aug 16, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@AmyOlex
Copy link

AmyOlex commented Aug 16, 2024

Describe the bug
I am trying to run CellChat and I am getting a AttributeError: 'SparseCSRView' object has no attribute 'A'.

To Reproduce
Here is the code to call the method. The "adata" is a Seurat object with the Data slot (log normalized) converted to an h5ad file using R and imported as an anndata formatted object in Python using the read_h5ad method. I was able to get CellPhoneDB method to run fine.

cellchat(adata,
use_raw=False,
groupby='cell_type',
# NOTE by default the resource uses HUMAN gene symbols
resource_name='consensus',
expr_prop=0.25,
verbose=True, key_added='cellchat_res')

Screenshots
No screen shot, but here is the traceback:

AttributeError Traceback (most recent call last)
Cell In[23], line 2
1 # run cellchat
----> 2 cellchat(adata,
3 use_raw=False,
4 groupby='cell_type',
5 # NOTE by default the resource uses HUMAN gene symbols
6 resource_name='consensus',
7 expr_prop=0.25,
8 verbose=True, key_added='cellchat_res')

File ~/anaconda3/envs/env_liana_p311/lib/python3.11/site-packages/liana/method/sc/_Method.py:244, in Method.call(self, adata, groupby, resource_name, expr_prop, min_cells, groupby_pairs, base, supp_columns, return_all_lrs, key_added, use_raw, layer, de_method, n_perms, seed, n_jobs, resource, interactions, mdata_kwargs, inplace, verbose)
241 if supp_columns is None:
242 supp_columns = []
--> 244 liana_res = liana_pipe(adata=adata,
245 groupby=groupby,
246 resource_name=resource_name,
247 resource=resource,
248 interactions=interactions,
249 expr_prop=expr_prop,
250 min_cells=min_cells,
251 supp_columns=supp_columns,
252 return_all_lrs=return_all_lrs,
253 groupby_pairs=groupby_pairs,
254 base=base,
255 de_method=de_method,
256 verbose=verbose,
257 _score=self._method,
258 n_perms=n_perms,
259 seed=seed,
260 n_jobs=n_jobs,
261 use_raw=use_raw,
262 layer=layer,
263 mdata_kwargs=mdata_kwargs
264 )
265 if inplace:
266 adata.uns[key_added] = liana_res

File ~/anaconda3/envs/env_liana_p311/lib/python3.11/site-packages/liana/method/sc/_liana_pipe.py:171, in liana_pipe(adata, groupby, resource_name, resource, interactions, groupby_pairs, expr_prop, min_cells, base, de_method, n_perms, seed, verbose, use_raw, n_jobs, layer, supp_columns, return_all_lrs, _score, _methods, _consensus_opts, _aggregate_method, mdata_kwargs)
167 print(f"Generating ligand-receptor stats for {adata.shape[0]} samples "
168 f"and {adata.shape[1]} features")
170 # Get lr results
--> 171 lr_res = _get_lr(adata=adata,
172 resource=resource,
173 groupby_pairs=groupby_pairs,
174 mat_mean=mat_mean,
175 mat_max=mat_max,
176 relevant_cols=_key_cols + _add_cols + _complex_cols,
177 de_method=de_method,
178 base=base,
179 verbose=verbose
180 )
182 # Ligand and receptor score based on unfiltered cluster mean and cluster std. Handles protein complexes
183 if (M.ligand_cdf in _add_cols) or (M.receptor_cdf in _add_cols):

File ~/anaconda3/envs/env_liana_p311/lib/python3.11/site-packages/liana/method/sc/_liana_pipe.py:308, in _get_lr(adata, resource, groupby_pairs, relevant_cols, mat_mean, mat_max, de_method, base, verbose)
306 dedict[label]['logfc'] = _calc_log2fc(adata, label)
307 if isinstance(mat_max, np.float32): # cellchat flag
--> 308 dedict[label]['trimean'] = _trimean(temp.X / mat_max)
310 pairs = (pd.DataFrame(np.array(np.meshgrid(labels, labels))
311 .reshape(2, np.size(labels) * np.size(labels)).T)
312 .rename(columns={0: P.source, 1: P.target}))
314 if groupby_pairs is not None:

File ~/anaconda3/envs/env_liana_p311/lib/python3.11/site-packages/liana/method/sc/_liana_pipe.py:463, in _trimean(a, axis)
462 def _trimean(a, axis=0):
--> 463 quantiles = np.quantile(a.A, q=[0.25, 0.75], axis=axis)
464 median = np.median(a.A, axis=axis)
465 return (quantiles[0] + 2 * median + quantiles[1]) / 4

AttributeError: 'SparseCSRView' object has no attribute 'A'

Thank you for any assistance!

@AmyOlex AmyOlex added bug Something isn't working help wanted Extra attention is needed labels Aug 16, 2024
@dbdimitrov
Copy link
Collaborator

Hi @AmyOlex,

This appears to be related to a scipy version. I will address in the following update but in the meantime, downgrading scipy to e.g. 1.10.1 will resolve it.

Daniel

@Zach-Sten
Copy link

downgrading scipy to 1.13.1 also fixes this if for some reason others need a more recent version of scipy.

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

No branches or pull requests

3 participants