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

mudata.MuData#

class mudata.MuData(data: AnnData | Mapping[str, AnnData] | MuData | None = None, feature_types_names: dict | None = {'Antibody Capture': 'prot', 'Gene Expression': 'rna', 'Peaks': 'atac'}, 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.

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

Parameters:

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:

The path to the file if backed, None otherwise.

Return type:

Path | None

property isbacked_: bool_#

Whether the MuData object is backed.

Returns:

True if the object is backed, False otherwise.

Return type:

bool

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:

The number of modalities.

Return type:

int

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)

This property is read-only. To be modified, obs_names of individual modalities should be changed, and .update_obs() should be called then.

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:

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)

This property is read-only. To be modified, var_names of individual modalities should be changed, and .update_var() should be called then.

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