mudata.concat#
- mudata.concat(mdatas, *, join='inner', merge=None, uns_merge=None, label=None, keys=None, index_unique=None, fill_value=None, pairwise=False)#
Concatenates MuData objects.
All mdatas should have the same
axis0or1, which defines concatenation axis:concatenate along obs when obs are shared in each mdata (multimodal),
concatenate along vars when vars are shared in each mdata (multi-dataset).
The intersection of modalities is taken. Nested
MuDataobjects cannot be concatenated.This implementation follows anndata.concat() original implementation. The arguments are propagated to anndata.concat() for concatenating modalities. See anndata.concat() documentation for more details.
- Parameters:
mdatas (
Collection[AnnData] |Mapping[str,AnnData]) – The objects to be concatenated. If aMappingis passed, keys are used for thekeysargument and values are concatenated.join (
Literal['inner','outer'] (default:'inner')) – How to align values when concatenating. If “outer”, the union of the other axis is taken. If “inner”, the intersection.merge (
Literal['same','unique','first','only'] |Callable|None(default:None)) –How elements not aligned to the axis being concatenated along are selected. Currently implemented strategies include:
None: No elements are kept."same": Elements that are the same in each of the objects."unique": Elements for which there is only one possible value."first": The first element seen at each from each position."only": Elements that show up in only one of the objects.
uns_merge (
Literal['same','unique','first','only'] |Callable|None(default:None)) – How the elements ofunsare selected. Uses the same set of strategies as themergeargument, except applied recursively.label (
str|None(default:None)) – Column in axis annotation (i.e.obsorvar) to place batch information in. IfNone, no column is added.keys (
Collection|None(default:None)) – Names for each object being added. These values are used for column values forlabelor appended to the index ifindex_uniqueis notNone. Defaults to incrementing integer labels.index_unique (
str|None(default:None)) – Whether to make the index unique by using the keys. If provided, this is the delimiter between “{orig_idx}{index_unique}{key}”. WhenNone, the original indices are kept.fill_value (
Any|None(default:None)) – Whenjoin="outer", this is the value that will be used to fill the introduced indices. By default, sparse arrays are padded with zeros, while dense arrays and DataFrames are padded with missing values.pairwise (
bool(default:False)) – Whether pairwise elements along the concatenated dimension should be included. This is False by default, since the resulting arrays are often not meaningful.
- Return type:
Examples
Preparing example objects
>>> import mudata as md, anndata as ad, pandas as pd, numpy as np >>> from scipy import sparse >>> a = ad.AnnData( ... X=sparse.csr_matrix(np.array([[0, 1], [2, 3]])), ... obs=pd.DataFrame({"group": ["a", "b"]}, index=["s1", "s2"]), ... var=pd.DataFrame(index=["var1", "var2"]), ... varm={"ones": np.ones((2, 5)), "rand": np.random.randn(2, 3), "zeros": np.zeros((2, 5))}, ... uns={"a": 1, "b": 2, "c": {"c.a": 3, "c.b": 4}}, ... ) >>> b = ad.AnnData( ... X=sparse.csr_matrix(np.array([[4, 5, 6], [7, 8, 9]])), ... obs=pd.DataFrame({"group": ["b", "c"], "measure": [1.2, 4.3]}, index=["s3", "s4"]), ... var=pd.DataFrame(index=["var1", "var2", "var3"]), ... varm={"ones": np.ones((3, 5)), "rand": np.random.randn(3, 5)}, ... uns={"a": 1, "b": 3, "c": {"c.b": 4}}, ... ) >>> c = ad.AnnData( ... X=sparse.csr_matrix(np.array([[10, 11], [12, 13]])), ... obs=pd.DataFrame({"group": ["a", "b"]}, index=["s1", "s2"]), ... var=pd.DataFrame(index=["var3", "var4"]), ... uns={"a": 1, "b": 4, "c": {"c.a": 3, "c.b": 4, "c.c": 5}}, ... ) >>> m = md.MuData({"a": a, "b": b, "c": c})