Skip to content

finer control on the "outer, inner" join behavior of sc.concat #591

Description

@zhangguy

Hi,

When we join two adata objects, usually we want to do inner join on the genes and outer join on the meta data (adata.obs). I understand that there is an option in sc.concat to control the behavior of joining, but it assigns the same behavior to the genes and adata.obs. Is it possible to add an option to control the behavior separately? Thanks!

Activity

  1. ivirshup commented on Jul 15, 2021

    @ivirshup
    Member

    I think this is a good idea, which has also come up here #416 (review).

    I think the main question is API. I some thoughts on this, but am not completley happy with any. I would note that xr.concat (which I heavily borrowed concepts from for this function) doesn't have a clear analog here. Though perhaps this is more like passing a list to data_vars or coords?

    I'll give a few of my thoughts, but would like to hear others and get feedback

    Specify kind of join per attribute/ element via dict

    ad.concat(adatas, join={"obs": "outer", "var_names": "inner", "obsm": {"pca": "inner"})

    But what's the behaviour for unspecified elements? E.g. What does this result in for other elements of obsm? It would be great if it was a simple consistent rule.

    This is a bit like passing a dict for fill_value to xr.concat (which we could also do, and would be a nice symmetry for the arguments).

    Example of xr.concat with fill_value
    import xarray as xr, numpy as np
    
    da = xr.DataArray(
        np.arange(6).reshape(2, 3), [("x", ["a", "b"]), ("y", [10, 20, 30])]
    )
    ds = xr.Dataset({"foo": da, "bar": da})
    
    (
        xr.concat(
            [ds.sel(x="a"), ds.sel(x="b", y=[10, 30])],
            dim="x",
            join="outer",
            fill_value={"foo": np.inf, "bar": 42}
        )
        .sel(x="b", y=20)
        .data_vars
    )
    Data variables:
        foo      float64 inf
        bar      int64 42
    

    Maybe we could also explicitly provide a list of elements to keep?

    ad.concat(adatas, join="outer", keep_elems={"obs": list_of_column_names})

    Simple option

    A simple option which would be quick to implement would be a join_elements argument, which defaults the value of join, but if passed allows you to override how elements in obs, obsm (/ var, varm) are joined. So:

    ad.concat(adatas, join="outer", join_elements="inner")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions