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:
- data – 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 – 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 – Create a view of the MuData object.
- index – Index to slice the MuData object when creating the view.
- **kwargs – Additional arguments to create a MuData object.
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:
- columns – List of columns to pull from the modalities’ .obs tables
- common – 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 of modalities to pull from.
- join_common – 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 – 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 – 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 – 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 – If True, prefix unique column names with modname (default). No prefix when False.
- drop – If True, drop the columns from the modalities after pulling.
- only_drop – If True, drop the columns but do not actually pull them. Forces drop=True.
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:
- columns – List of columns to pull from the modalities’ .var tables
- common – 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 of modalities to pull from.
- join_common – 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 – 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 – 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 – 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 – If True, prefix unique column names with modname (default). No prefix when False.
- drop – If True, drop the columns from the modalities after pulling.
- only_drop – If True, drop the columns but do not actually pull them. Forces drop=True.
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:
- columns – List of columns to push
- mods – List of modalities to push to
- common – 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 – 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 – If True, drop the columns from the global .obs after pushing. False by default.
- only_drop – If True, drop the columns but do not actually pull them. Forces drop=True. False by default.
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:
- columns – List of columns to push
- mods – List of modalities to push to
- common – 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 – 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 – If True, drop the columns from the global .var after pushing. False by default.
- only_drop – If True, drop the columns but do not actually pull them. Forces drop=True. False by default.
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:
- data (MuData) – MuData object to convert to AnnData
- kwargs (dict) – 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)
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