- Notifications
You must be signed in to change notification settings - Fork31
Closed
Description
I want to perform multiple filtering steps on my object e.g.:
mu.pp.filter_obs(mdata, 'n_genes_by_counts', lambda x: (x >= 100))mu.pp.filter_obs(mdata, 'total_counts', lambda x: (x >= 500) & (x <= 50000)
Error message:
muon/_core/preproc.py in filter_obs(data, var, func) 733 # filter_obs() for each modality 734 for m, mod in data.mod.items():--> 735 obsmap = data.obsmap[m][obs_subset] 736 obsmap = obsmap[obsmap != 0] - 1 737 filter_obs(mod, mod.obs_names[obsmap])anndata/_core/aligned_mapping.py in __getitem__(self, key) 146 147 def __getitem__(self, key: str) -> V:--> 148 return self._data[key] 149 150 def __setitem__(self, key: str, value: V):KeyError: 'x'
Minimal working example:
import numpy as npimport muon as mux = mu.AnnData(X=np.random.normal(size=1000).reshape(-1, 100))y = mu.AnnData(X=np.random.normal(size=2000).reshape(-1, 100))md = mu.MuData({"x": x, "y": y})md['x'].obs['total_count'] = md['x'].X.sum(axis=1)md['x'].obs['min_count'] = md['x'].X.min(axis=1)md.update()# filter one of the modalities.mu.pp.filter_obs(md, 'x:min_count', lambda x: (x < -2))mu.pp.filter_obs(md, 'x:total_count', lambda x: (x >0))
If you putmd.update()
between the two filter statements it does work. But to me this is not ideal if you are filtering on lots of categories sequentially
Is this desired behaviour ot something that could be updated such that one could just one runupdate
command after sequential filters??
- OS: CentOS Linux release 7.8.2003 (Core)
- Python 3.9.5
- Versions of libraries involved
- numpy 1.20.3
- muon 0.1.1
Thanks!