mudata icon indicating copy to clipboard operation
mudata copied to clipboard

Support for mudata.uns?

Open benemead opened this issue 2 years ago • 2 comments

Describe the bug After a read of the mudata documentation it's unclear to me if mudata supports the .uns akin to anndata. I see that each .mod (anndata) supports .uns, but when I assign a .uns directly to the mdata object, the behavior is unpredictable - specifically, any slice of the mdata object results in a loss of any mdata.uns, but otherwise I am able to interact with mdata.uns as expected.

To Reproduce

adata_dict = {'RNA':scanpy.AnnData(X=np.zeros(100,50))}
mdata = MuData(adata_dict)

test_dict = { 'test':'dict'}

mdata.uns['test_dict'] = test_dict

mdata = mdata[:50,:]

mdata.uns

Expected behaviour

returns: {} versus the expected { 'test_dict':{'test':'dict'}}

System

  • OS: macOS Ventura 13.5.1
  • Python version 3.11.4
  • Versions of libraries involved:
  • scanpy 1.9.3
  • muon 0.1.5

benemead avatar Sep 08 '23 13:09 benemead

Thanks for noticing and reporting that, @benemead! It's an easy fix, and it will be there with v0.3.

gtca avatar Sep 10 '23 01:09 gtca

Hi, I'm running in an error i think connected this issue. When trying to retreive all keys in .uns with mdata.uns_keys() I'll get the following: AttributeError: 'MuData' object has no attribute '_uns' . You can fix this in file /mudata/_core/mudata.py if you change return list(self._uns.keys()) to return list(self.uns.keys()) (line 1193). Not sure whether its intended to be that way or whether in the init self._uns (line 137) should be used instead of self.uns like the rest (self._obs, self._var, ...) . Im running mudata 0.2.3. Cheers

leuschjanphilipp avatar Mar 19 '24 17:03 leuschjanphilipp

Thanks @leuschjanphilipp and @benemead,

The fix will land in v0.3. Moreover, it now borrows DictView from anndata so it should come with improved behaviour when trying to modify .uns of a view.

gtca avatar Jul 02 '24 01:07 gtca