'SparseCSCView' object has no attribute 'A'
kalanir opened this issue · 8 comments
When I run mv.aggregate_peaks_10x with both the demo and my own data, I get this error: 'SparseCSCView' object has no attribute 'A'
How can I get around this?
If you got this error on the demo data as well, it's probably due to some package version conflicts. Can you share the versions of scanpy, scvelo, numpy, scipy, and multivelo that you used? We can investigate further. Thanks.
Thanks for your help! These are the versions:
scanpy 1.10.2
scipy 1.14.0
scvelo 0.3.2
multivelo 0.1.3
numpy 1.26.4
When I look at just adata_atac, I get:
View of AnnData object with n_obs × n_vars = 4881 × 144437 var: 'gene_ids', 'feature_types'
Also when I look at adata_atac.X, I get:
<Compressed Sparse Column sparse matrix of dtype 'float32' with 39610080 stored elements and shape (4881, 144437)>
But when I look at adata_atac.X.A, I get:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[26], line 1
----> 1 adata_atac.X.A
AttributeError: 'SparseCSCView' object has no attribute 'A'
So I'm unsure if the intermediate data types are what they should look like as well.
Hi. I see when you print adata_atac, you got a view instead of the actual anndata object. It may be due to some subsetting in previous steps. You can try adding adata_atac = adata_atac.copy() or replacing any subset code with adata_atac = adata_atac[x, y].copy() and see if that solves the issue.
Hello! Now this is the following outputs. Using copy doesn't seem to fix things:
adata_atac = sc.read_10x_mtx(path+'/filtered_feature_bc_matrix/', var_names='gene_symbols', cache=True, gex_only=False)
adata_atac
AnnData object with n_obs × n_vars = 4881 × 176722
var: 'gene_ids', 'feature_types'
adata_atac = adata_atac[:,adata_atac.var['feature_types'] == "Peaks"].copy()
adata_atac
AnnData object with n_obs × n_vars = 4881 × 144437
var: 'gene_ids', 'feature_types'
adata_atac = mv.aggregate_peaks_10x(adata_atac,
path+'/peak_annotation.tsv',
path+'/feature_linkage.bedpe')
AttributeError Traceback (most recent call last)
Cell In[12], line 4
1 # We aggregate peaks around each gene as well as those that have high correlations with promoter peak or gene expression.
2 # Peak annotation contains the metadata for all peaks.
3 # Feature linkage contains pairs of correlated genomic features.
----> 4 adata_atac = mv.aggregate_peaks_10x(adata_atac,
5 path+'/peak_annotation.tsv',
6 path+'/feature_linkage.bedpe')
File /opt/anaconda3/envs/multivelo2/lib/python3.11/site-packages/multivelo/auxiliary.py:261, in aggregate_peaks_10x(adata_atac, peak_annot_file, linkage_file, peak_dist, min_corr, gene_body, return_dict, verbose)
258 enhancer_dict[gene].append(peak)
260 # aggregate to genes
--> 261 adata_atac_X_copy = adata_atac.X.A
262 gene_mat = np.zeros((adata_atac.shape[0], len(promoter_genes)))
263 var_names = adata_atac.var_names.to_numpy()
AttributeError: 'csc_matrix' object has no attribute 'A'
Again, this is all with the test dataset.
This seems to be related to the new Scipy version 1.14, which removed .A
from csc_matrix. See scipy/scipy#21049. I suggest reverting to scipy==1.13 if possible.
@jacobrepucci We may need to add a version cap for now.
Should be a fairly easy find-replace w/ toarray() instead of .A
Hi all! What’s your recommendation? Should I downgrade or is the plan to update the code for the newer scipy version?
Running pip install --force-reinstall -v "scipy==1.10"
and then going through the demo now works. Thank you for all your help troubleshooting this with me!