Scanpy: regress_out failed in the pbmc3k tutorial

Created on 26 Jan 2020  路  5Comments  路  Source: theislab/scanpy

AxisError was encountered while executing the regress_out function following the pbmc3k tutorial
...

sc.pp.regress_out(adata, ['n_counts', 'percent_mito'])
regressing out ['n_counts', 'percent_mito']
    sparse input is densified and may lead to high memory use
---------------------------------------------------------------------------
AxisError                                 Traceback (most recent call last)
<ipython-input-55-c0d016811ded> in <module>
----> 1 sc.pp.regress_out(adata, ['n_counts', 'percent_mito'])

~/anaconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/preprocessing/_simple.py in regress_out(adata, keys, n_jobs, copy)
    817     # split the adata.X matrix by columns in chunks of size n_chunk
    818     # (the last chunk could be of smaller size than the others)
--> 819     chunk_list = np.array_split(adata.X, n_chunks, axis=1)
    820     if variable_is_categorical:
    821         regressors_chunk = np.array_split(regressors, n_chunks, axis=1)

<__array_function__ internals> in array_split(*args, **kwargs)

~/anaconda3/envs/scanpy/lib/python3.6/site-packages/numpy/lib/shape_base.py in array_split(ary, indices_or_sections, axis)
    782 
    783     sub_arys = []
--> 784     sary = _nx.swapaxes(ary, axis, 0)
    785     for i in range(Nsections):
    786         st = div_points[i]

<__array_function__ internals> in swapaxes(*args, **kwargs)

~/anaconda3/envs/scanpy/lib/python3.6/site-packages/numpy/core/fromnumeric.py in swapaxes(a, axis1, axis2)
    595 
    596     """
--> 597     return _wrapfunc(a, 'swapaxes', axis1, axis2)
    598 
    599 

~/anaconda3/envs/scanpy/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     56     bound = getattr(obj, method, None)
     57     if bound is None:
---> 58         return _wrapit(obj, method, *args, **kwds)
     59 
     60     try:

~/anaconda3/envs/scanpy/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     45     except AttributeError:
     46         wrap = None
---> 47     result = getattr(asarray(obj), method)(*args, **kwds)
     48     if wrap:
     49         if not isinstance(result, mu.ndarray):

AxisError: axis1: axis 1 is out of bounds for array of dimension 0

Versions:

scanpy==1.4.5.post3 anndata==0.7.1 umap==0.3.10 numpy==1.18.1 scipy==1.4.1 pandas==0.25.3 scikit-learn==0.22.1 statsmodels==0.11.0 python-igraph==0.7.1 louvain==0.6.1

bug

Most helpful comment

It looks like this is connected to the way anndata objects are sliced. An explicit adata = adata.copy() before calling sc.pp.regress_out() solves the problem.

All 5 comments

I had the exact same issue and error message at that step in the tutorial. I installed scanpy using pip, because installing with conda was not working.

I had the exact same issue and error message at that step in the tutorial. I installed scanpy using pip, because installing with conda was not working.

Same here. I assume there is some issue with the implementation of the setter of adata.X, which prevents adata.X = adata.X.toarray() from updating X to its densified version.

It looks like this is connected to the way anndata objects are sliced. An explicit adata = adata.copy() before calling sc.pp.regress_out() solves the problem.

It looks like this is connected to the way anndata objects are sliced. An explicit adata = adata.copy() before calling sc.pp.regress_out() solves the problem.

Thank you!

Fixed in #1014 (scanpy 1.4.5.1)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

falexwolf picture falexwolf  路  4Comments

wangjiawen2013 picture wangjiawen2013  路  5Comments

picciama picture picciama  路  4Comments

gokceneraslan picture gokceneraslan  路  4Comments

wflynny picture wflynny  路  6Comments