scverse / mudata

Multimodal Data (.h5mu) implementation for Python
https://mudata.rtfd.io
BSD 3-Clause "New" or "Revised" License
75 stars 17 forks source link

Support for mudata.uns? #52

Closed benemead closed 3 months ago

benemead commented 1 year ago

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

gtca commented 1 year ago

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

leuschjanphilipp commented 6 months ago

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

gtca commented 3 months ago

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.