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

MuData.to_anndata() & AnnData.to_mudata() #14

Open
ivirshup opened this issue Jan 26, 2022 · 1 comment · May be fixed by #54
Open

MuData.to_anndata() & AnnData.to_mudata() #14

ivirshup opened this issue Jan 26, 2022 · 1 comment · May be fixed by #54
Labels
enhancement New feature or request
Milestone

Comments

@ivirshup
Copy link
Member

I'd like to propose some utility methods for converting back and forth between MuData and AnnData objects.

Implementations would look something like:

import anndata as ad
import mudata

def to_anndata(self: mudata.MuData, axis, ...) -> ad.AnnData:
    adata = ad.concat(self.mod, axis=axis, ...)
    for attr in ["obs", "obsm", "obsp", "var", "varm", "varp", "uns"]:
        getattr(adata, attr).update(getattr(self, attr))
    return adata

def to_mudata(self: ad.AnnData, axis, groupby) -> mudata.MuData:
    # self.split_by(groupby, axis=axis) -> dict[str, AnnData]
    return mudata.MuData(
        self.split_by(groupby, axis=axis)
    )

With split_by being: scverse/anndata#613

Additional needs

I think it would be good to have arguments giving some control over which features are moved to/ from shared mappings in the mudata object, as opposed to being anndata specific.

Decisions on copies vs views would be good as well.

Use cases

The main use case here is easing transition for libraries that only work with one of the types. I think it would also make it much easier to play around with which representation fits a particular use case better.

It also does a good job of advertising the connectedness of the objects, but that's very secondary.

@ivirshup ivirshup added the enhancement New feature or request label Jan 26, 2022
gtca added a commit that referenced this issue Sep 11, 2023
@gtca
Copy link
Collaborator

gtca commented Sep 11, 2023

The API should come in v0.3. As the split_by PR hasn't been merged, the to_mudata functionality might be a bit basic but should cover the main use case.

@gtca gtca linked a pull request Sep 11, 2023 that will close this issue
@gtca gtca linked a pull request Sep 11, 2023 that will close this issue
@gtca gtca added this to the v0.3.0 milestone Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants