mudata.MuData — mudata documentation (original) (raw)

mudata.MuData#

class mudata.MuData(data: AnnData | Mapping[str, AnnData] | MuData | None = None, feature_types_names: dict | None = mappingproxy({'Gene Expression': 'rna', 'Peaks': 'atac', 'Antibody Capture': 'prot'}), as_view: bool = False, index: tuple[slice | Integral, slice | Integral] | slice | Integral | None = None, **kwargs)#

Bases: object

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:

__init__(data: AnnData | Mapping[str, AnnData] | MuData | None = None, feature_types_names: dict | None = mappingproxy({'Gene Expression': 'rna', 'Peaks': 'atac', 'Antibody Capture': 'prot'}), as_view: bool = False, index: tuple[slice | Integral, slice | Integral] | slice | Integral | None = None, **kwargs)#

Methods

Attributes

property axis: int#

MuData axis.

copy(filename: PathLike | None = None) → MuData#

Make a copy.

Parameters:

filename – If the object is backed, copy the object to a new file.

property filename: Path | None#

Filename of the MuData object.

Returns:

Path | None

Return type:

The path to the file if backed, None otherwise.

property isbacked: bool#

Whether the MuData object is backed.

Returns:

bool

Return type:

True if the object is backed, False otherwise.

property mod_names: list[str]#

Names of modalities (alias for list(mdata.mod.keys()))

This property is read-only.

property n_mod: int#

Number of modalities in the MuData object.

Returns:

int

Return type:

The number of modalities.

property n_obs: int#

Total number of observations

property n_var: int#

Total number of variables.

property n_vars: int#

Total number of variables.

property obs: DataFrame#

Annotation of observation

obs_keys() → list[str]#

List keys of observation annotation obs.

property obs_names: Index#

Names of variables (alias for .obs.index).

obs_names_make_unique()#

Call .obs_names_make_unique() method on each AnnData object.

If there are obs_names, which are the same for multiple modalities, append modality name to all obs_names.

obs_vector(key: str, layer: str | None = None) → ndarray#

Return an array of values for the requested key of length n_obs

property obsm: MuAxisArrays | MuAxisArraysView#

Multi-dimensional annotation of observation.

obsm_keys() → list[str]#

List keys of observation annotation obsm.

property obsmap: PairwiseArrays | PairwiseArraysView#

Mapping of observation index in the MuData to indices in individual modalities.

1-based, 0 indicates that the corresponding observation is missing in the respective modality.

property obsp: PairwiseArrays | PairwiseArraysView#

Pairwise annotatation of observations.

pull_obs(columns: list[str] | None = None, mods: list[str] | None = None, common: bool | None = None, join_common: bool | None = None, nonunique: bool | None = None, join_nonunique: bool | None = None, unique: bool | None = None, prefix_unique: bool | None = True, drop: bool = False, only_drop: bool = False)#

Copy the data from the modalities to the global .obs, existing columns to be overwritten or updated.

Parameters:

pull_var(columns: list[str] | None = None, mods: list[str] | None = None, common: bool | None = None, join_common: bool | None = None, nonunique: bool | None = None, join_nonunique: bool | None = None, unique: bool | None = None, prefix_unique: bool | None = True, drop: bool = False, only_drop: bool = False)#

Copy the data from the modalities to the global .var, existing columns to be overwritten or updated.

Parameters:

push_obs(columns: list[str] | None = None, mods: list[str] | None = None, common: bool | None = None, prefixed: bool | None = None, drop: bool = False, only_drop: bool = False)#

Copy the data from the mdata.obs to the modalities, existing columns to be overwritten.

Parameters:

push_var(columns: list[str] | None = None, mods: list[str] | None = None, common: bool | None = None, prefixed: bool | None = None, drop: bool = False, only_drop: bool = False)#

Copy the data from the mdata.var to the modalities, existing columns to be overwritten.

Parameters:

property shape: tuple[int, int]#

Shape of data, all variables and observations combined (n_obs, n_var).

strings_to_categoricals(df: DataFrame | None = None)#

Transform string columns in .var and .obs slots of MuData to categorical as well as of .var and .obs slots in each AnnData object.

This keeps it compatible with AnnData.strings_to_categoricals() method.

to_anndata(**kwargs) → AnnData#

Convert MuData to AnnData.

If mdata.axis == 0 (shared observations), concatenate modalities along axis 1 (anndata.concat(axis=1)). If mdata.axis == 1 (shared variables), concatenate datasets along axis 0 (anndata.concat(axis=0)).

See anndata.concat() documentation for more details.

Parameters:

kwargs – Keyword arguments passed to anndata.concat()

property uns: MutableMapping#

Unstructured annotation (ordered dictionary).

uns_keys() → list[str]#

List keys of unstructured annotation.

update()#

Update both .obs and .var indices of MuData with the data from all the modalities

NOTE: From v0.4, it will not pull columns from modalities by default.

update_obs()#

Update global .obs_names according to the .obs_names of all the modalities.

update_var()#

Update global .var_names according to the .var_names of all the modalities.

property var: DataFrame#

Annotation of variables.

var_keys() → list[str]#

List keys of variable annotation var.

property var_names: Index#

Names of variables (alias for .var.index)

var_names_make_unique()#

Call .var_names_make_unique() method on each AnnData object.

If there are var_names, which are the same for multiple modalities, append modality name to all var_names.

var_vector(key: str, layer: str | None = None) → ndarray#

Return an array of values for the requested key of length n_var.

property varm: MuAxisArrays | MuAxisArraysView#

Multi-dimensional annotation of variables.

varm_keys() → list[str]#

List keys of variable annotation varm.

property varmap: PairwiseArrays | PairwiseArraysView#

Mapping of feature index in the MuData to indices in individual modalities.

1-based, 0 indicates that the corresponding observation is missing in the respective modality.

property varp: PairwiseArrays | PairwiseArraysView#

Pairwise annotatation of variables.

write(filename: str | None = None, **kwargs)#

Write MuData object to an HDF5 file.

write_h5mu(filename: str | None = None, **kwargs)#

Write MuData object to an HDF5 file.

write_zarr(store: MutableMapping | str | Path, **kwargs)#

Write MuData object to a Zarr store.