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

Intersect obs fails if AnnData doesn't have X #93

Closed
grst opened this issue Feb 15, 2023 · 0 comments
Closed

Intersect obs fails if AnnData doesn't have X #93

grst opened this issue Feb 15, 2023 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@grst
Copy link
Contributor

grst commented Feb 15, 2023

Describe the bug
Running muon.pp.intersect_obs on a MuData object that contains an AnnData object with X=None, it fails

To Reproduce

from anndata import AnnData
import muon as mu
from mudata import MuData
import numpy as np
import pandas as pd

md = MuData({
    "a": AnnData(None, obs=pd.DataFrame(index=["1", "2", "3"])),
    "b": AnnData(np.ones((2,2)), obs=pd.DataFrame(index=["2", "3"]))
})
mu.pp.intersect_obs(md)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/anaconda3/envs/scirpy_dev/lib/python3.9/site-packages/muon/_core/preproc.py in filter_obs(data, var, func)
    713         try:
--> 714             data._X = data.X[obs_subset, :]
    715         except TypeError:

TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/tmp/ipykernel_979716/2023157240.py in <cell line: 1>()
----> 1 mu.pp.intersect_obs(md)

~/anaconda3/envs/scirpy_dev/lib/python3.9/site-packages/muon/_core/preproc.py in intersect_obs(mdata)
    627 
    628     for mod in mdata.mod:
--> 629         filter_obs(mdata.mod[mod], common_obs)
    630 
    631     mdata.update_obs()

~/anaconda3/envs/scirpy_dev/lib/python3.9/site-packages/muon/_core/preproc.py in filter_obs(data, var, func)
    714             data._X = data.X[obs_subset, :]
    715         except TypeError:
--> 716             data._X = data.X[np.where(obs_subset)[0], :]
    717             # For some h5py versions, indexing arrays must have integer dtypes
    718             # https://github.com/h5py/h5py/issues/1847

Expected behaviour
Ignore X, intersect obs/obsm/... as usual

System
mudata master
anndata master

Additional context
AnnData objects generated by scirpy do not have a matrix in X, it only uses obs and obsm.

@grst grst added the bug Something isn't working label Feb 15, 2023
@gtca gtca closed this as completed in 580531c Feb 21, 2023
@gtca gtca added this to the v0.1.4 milestone Feb 21, 2023
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

2 participants