mudata.MuData#
- class mudata.MuData(data=None, feature_types_names=mappingproxy({'Gene Expression': 'rna', 'Peaks': 'atac', 'Antibody Capture': 'prot'}), as_view=False, index=None, **kwargs)#
Multimodal data object
MuData represents modalities as collections of AnnData objects as well as includes multimodal annotations such as embeddings and neighbours graphs learned jointly on multiple modalities and generalised sample and feature metadata tables.
- Parameters:
data (
AnnData|Mapping[str,AnnData] |MuData|None(default:None)) – AnnData object or dictionary with AnnData objects as values. If a dictionary is passed, the keys will be used as modality names. If None, creates an empty MuData object.feature_types_names (
Mapping[str,str] |None(default:mappingproxy({'Gene Expression': 'rna', 'Peaks': 'atac', 'Antibody Capture': 'prot'}))) – Dictionary to map feature types encoded in data.var[“feature_types”] to modality names. Only relevant when data is an AnnData object. Default: {“Gene Expression”: “rna”, “Peaks”: “atac”, “Antibody Capture”: “prot”}as_view (
bool(default:False)) – Create a view of the MuData object.index (
tuple[slice|int,slice|int] |slice|int|None(default:None)) – Index to slice the MuData object when creating the view.**kwargs – Additional arguments to create a MuData object.
Attributes table#
MuData axis.
Change the backing mode by setting the filename to a
.h5mufile.Whether the object is a view of another
MuDataobject.Whether the object is backed on disk.
Dictionary of modalities.
Names of modalities (alias for
list(mdata.mod.keys()))Number of modalities.
Total number of observations
Total number of variables.
Total number of variables.
Annotation of observation
Names of variables (alias for
.obs.index).Multi-dimensional annotation of observations.
Mapping of observation indices in the object to indices in individual modalities.
Pairwise annotatation of observations.
Shape of data, all variables and observations combined (
n_obs,n_vars).Unstructured annotation (ordered dictionary).
Annotation of variables.
Names of variables (alias for
.var.index)Multi-dimensional annotation of variables.
Mapping of feature indices in the object to indices in individual modalities.
Pairwise annotatation of variables.
Methods table#
copy([filename])Make a copy.
obs_keys()List keys of observation annotation
obs.Call
AnnData.obs_names_make_uniqueon each modality.obs_vector(key[, layer])Return an array of values for the requested key of length n_obs.
List keys of observation annotation
obsm.pull_obs([columns, mods, common, ...])pull_var([columns, mods, common, ...])push_obs([columns, mods, common, prefixed, ...])push_var([columns, mods, common, prefixed, ...])strings_to_categoricals([df])Transform string annotations to categoricals.
to_anndata(**kwargs)Convert the object to
AnnData.uns_keys()List keys of unstructured annotation.
update()Update both
obsandvarindices of the object with the data from all the modalities.Update
obsindices of the object with the data from all the modalities.Update
varindices of the object with the data from all the modalities.var_keys()List keys of variable annotation
var.Call
AnnData.var_names_make_uniqueon each modality.var_vector(key[, layer])Return an array of values for the requested key of length n_var.
List keys of variable annotation
varm.write([filename])Write the object to an HDF5 file.
write_h5mu([filename])Write the object to an HDF5 file.
write_zarr(store, **kwargs)Write the object to a Zarr store.
Attributes#
- property axis: Literal[-1, 0, 1]#
MuData axis.
0if the modalities have shared observations1if the modalities have shared features-1if both observations and features are shared
- property filename: Path | None#
Change the backing mode by setting the filename to a
.h5mufile.Setting the filename writes the stored data to disk.
Setting the filename when the filename was previously another name moves the backing file from the previous file to the new file. If you want to copy the previous file, use
copy(filename="new_filename").
- property obsm: MutableMapping[str]#
Multi-dimensional annotation of observations.
Stores for each key a two- or higher-dimensional
ndarrayorDataFrameof lengthn_obs. Is sliced withobsbut otherwise behaves like a mapping.
- property obsmap: Mapping[str]#
Mapping of observation indices in the object to indices in individual modalities.
Contains an entry for each modality. Each entry is an
ndarraywith shape(n_obs, 1). Each element in the array contains the numerical index of the observation in the respective modality corresponding to theMuDataobservation in that position. The index is 1-based, 0 indicates that the observation is missing in the modality.
- property obsp: MutableMapping[str]#
Pairwise annotatation of observations.
Stores for each key a two- or higher-dimensional
ndarraywhose first two dimensions are of liengthn_obs. Is sliced withobsbut otherwise behaves like a mapping.
- property shape: tuple[int, int]#
Shape of data, all variables and observations combined (
n_obs,n_vars).
- property uns: MutableMapping#
Unstructured annotation (ordered dictionary).
- property varm: MutableMapping[str]#
Multi-dimensional annotation of variables.
Stores for each key a two- or higher-dimensional
ndarrayorDataFrameof lengthn_vars. Is sliced withvarbut otherwise behaves like a mapping.
- property varmap: Mapping[str]#
Mapping of feature indices in the object to indices in individual modalities.
Contains an entry for each modality. Each entry is an
ndarraywith shape(n_obs, 1). Each element in the array contains the numerical index of the feature in the respective modality corresponding to theMuDatafeature in that position. The index is 1-based, 0 indicates that the feature is missing in the modality.
- property varp: MutableMapping[str]#
Pairwise annotatation of variables.
Stores for each key a two- or higher-dimensional
ndarraywhose first two dimensions are of liengthn_obs. Is sliced withobsbut otherwise behaves like a mapping.
Methods#
- copy(filename=None)#
Make a copy.
- obs_names_make_unique()#
Call
AnnData.obs_names_make_uniqueon each modality.If there are
obs_nameswhich are the same for multiple modalities, append the modality name to all obs_names.
- obs_vector(key, layer=None)#
Return an array of values for the requested key of length n_obs.
- pull_obs(columns=None, mods=None, common=None, join_common=None, nonunique=None, join_nonunique=None, unique=None, prefix_unique=True, drop=False, only_drop=False)#
Copy data from the
obsof the modalities to the globalobsExisting columns to be overwritten or updated.
- Parameters:
columns (
list[str] |None(default:None)) – List of columns to pull from the modalities’ .obs tablescommon (
bool|None(default:None)) – If True, pull common columns. Common columns do not have modality prefixes. Pull from all modalities. Cannot be used with columns. True by default.mods (
list[str] |None(default:None)) – List of modalities to pull from.join_common (
bool|None(default:None)) – If True, attempt to join common columns. Common columns are present in all modalities. True for MuData wth axis=1 (shared var). False for MuData with axis=0 and axis=-1. Cannot be used with mods, or for shared attr.nonunique (
bool|None(default:None)) – If True, pull columns that have a modality prefix such that there are multiple columns with the same name and different prefix. Cannot be used with columns or mods. True by default.join_nonunique (
bool|None(default:None)) – If True, attempt to join non-unique columns. Intended usage is the same as for join_common. Cannot be used with mods, or for shared attr. False by default.unique (
bool|None(default:None)) – If True, pull columns that have a modality prefix such that there is no other column with the same name and a different modality prefix. Cannot be used with columns or mods. True by default.prefix_unique (
bool(default:True)) – If True, prefix unique column names with modname (default). No prefix when False.drop (
bool(default:False)) – If True, drop the columns from the modalities after pulling.only_drop (
bool(default:False)) – If True, drop the columns but do not actually pull them. Forces drop=True.
- pull_var(columns=None, mods=None, common=None, join_common=None, nonunique=None, join_nonunique=None, unique=None, prefix_unique=True, drop=False, only_drop=False)#
Copy data from the
varof the modalities to the globalvarExisting columns to be overwritten or updated.
- Parameters:
columns (
list[str] |None(default:None)) – List of columns to pull from the modalities’ .var tablescommon (
bool|None(default:None)) – If True, pull common columns. Common columns do not have modality prefixes. Pull from all modalities. Cannot be used with columns. True by default.mods (
list[str] |None(default:None)) – List of modalities to pull from.join_common (
bool|None(default:None)) – If True, attempt to join common columns. Common columns are present in all modalities. True for MuData with axis=0 (shared obs). False for MuData with axis=1 and axis=-1. Cannot be used with mods, or for shared attr.nonunique (
bool|None(default:None)) – If True, pull columns that have a modality prefix such that there are multiple columns with the same name and different prefix. Cannot be used with columns or mods. True by default.join_nonunique (
bool|None(default:None)) – If True, attempt to join non-unique columns. Intended usage is the same as for join_common. Cannot be used with mods, or for shared attr. False by default.unique (
bool|None(default:None)) – If True, pull columns that have a modality prefix such that there is no other column with the same name and a different modality prefix. Cannot be used with columns or mods. True by default.prefix_unique (
bool(default:True)) – If True, prefix unique column names with modname (default). No prefix when False.drop (
bool(default:False)) – If True, drop the columns from the modalities after pulling.only_drop (
bool(default:False)) – If True, drop the columns but do not actually pull them. Forces drop=True.
- push_obs(columns=None, mods=None, common=None, prefixed=None, drop=False, only_drop=False)#
Copy the data from
obsto theobsof the modalities.Existing columns to be overwritten.
- Parameters:
columns (
list[str] |None(default:None)) – List of columns to pushmods (
list[str] |None(default:None)) – List of modalities to push tocommon (
bool|None(default:None)) – If True, push common columns. Common columns do not have modality prefixes. Push to each modality unless all values for a modality are null. Cannot be used with columns. True by default.prefixed (
bool|None(default:None)) – If True, push columns that have a modality prefix. which are prefixed by modality names. Only push to the respective modality names. Cannot be used with columns. True by default.drop (
bool(default:False)) – If True, drop the columns from the global .obs after pushing. False by default.only_drop (
bool(default:False)) – If True, drop the columns but do not actually pull them. Forces drop=True. False by default.
- push_var(columns=None, mods=None, common=None, prefixed=None, drop=False, only_drop=False)#
Copy the data from
varto thevarof the modalities.Existing columns to be overwritten.
- Parameters:
columns (
list[str] |None(default:None)) – List of columns to pushmods (
list[str] |None(default:None)) – List of modalities to push tocommon (
bool|None(default:None)) – If True, push common columns. Common columns do not have modality prefixes. Push to each modality unless all values for a modality are null. Cannot be used with columns. True by default.prefixed (
bool|None(default:None)) – If True, push columns that have a modality prefix. which are prefixed by modality names. Only push to the respective modality names. Cannot be used with columns. True by default.drop (
bool(default:False)) – If True, drop the columns from the global .var after pushing. False by default.only_drop (
bool(default:False)) – If True, drop the columns but do not actually pull them. Forces drop=True. False by default.
- strings_to_categoricals(df=None)#
Transform string annotations to categoricals.
- to_anndata(**kwargs)#
Convert the object to
AnnData.If
axisis0(shared observations), concatenate modalities along axis 1 (anndata.concat(axis=1)).If
axisis1(shared features), concatenate datasets along axis 0 (anndata.concat(axis=0)).See
anndata.concat()documentation for more details.- Parameters:
**kwargs – Keyword arguments passed to
anndata.concat()- Return type:
- update()#
Update both
obsandvarindices of the object with the data from all the modalities.Note
From v0.4, it will not pull columns from modalities by default.
- update_obs()#
Update
obsindices of the object with the data from all the modalities.Note
From v0.4, it will not pull columns from modalities by default.
- update_var()#
Update
varindices of the object with the data from all the modalities.Note
From v0.4, it will not pull columns from modalities by default.
- var_names_make_unique()#
Call
AnnData.var_names_make_uniqueon each modality.If there are
obs_nameswhich are the same for multiple modalities, append the modality name to all obs_names.
- var_vector(key, layer=None)#
Return an array of values for the requested key of length n_var.
- write(filename=None, **kwargs)#
Write the object to an HDF5 file.
- Parameters:
filename (
str|PathLike|None(default:None)) – Path of the.h5mufile to write to. Defaults to the backing file.**kwargs – Additional arguments to
write_h5mu().
- write_h5mu(filename=None, **kwargs)#
Write the object to an HDF5 file.
- Parameters:
filename (
str|PathLike|None(default:None)) – Path of the.h5mufile to write to. Defaults to the backing file.**kwargs – Additional arguments to
write_h5mu().
- write_zarr(store, **kwargs)#
Write the object to a Zarr store.
- Parameters:
store (
MutableMapping|str|PathLike|Store) – The filename or a Zarr store.**kwargs – Additional arguments to
write_zarr().