liana.method.MistyData#

class liana.method.MistyData(data, obs=None, spatial_key='spatial', enforce_obs=True, **kwargs)#

MistyData Class used to construct multi-view objects.

Construct a MistyData object from a dictionary of views (anndatas).

Parameters:
  • data (dict | MuData) – Dictionary of views (AnnData`s) or a `MuData object. Note that only the data.X attribute is used. An intra-view called “intra” is required.

  • obs (DataFrame | None (default: None)) – DataFrame of observations. If None, the obs of the intra-view is used.

  • spatial_key (str (default: 'spatial')) – Key in adata.obsm that contains the spatial coordinates. Default is 'spatial'.

  • enforce_obs (bool (default: True)) – If True, the number of observations in each extra-view must match the intra-view. Then the connectivities are stored in the .obsp attribute, while the weighted matrix is stored in .layers[‘weighted’]. If False, the connectivities are stored in the .obsm attribute, while the weighted matrix is transposed and stored in .varm[‘weighted’].

  • **kwargs – Keyword arguments passed to the MuData Super class

view_names#

List of names of the different views

spatial_key#

Key in data.obsm containing the spatial coordinates.

enforce_obs#

See parameter with the same name.

obs#

See parameter with the same name.

Attributes table#

axis

MuData axis

filename

Filename of the MuData object.

isbacked

Whether the MuData object is backed.

mod_names

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

n_mod

Number of modalities in the MuData object.

n_obs

Total number of observations

n_var

Total number of variables

n_vars

Total number of variables

obs

Annotation of observation

obs_names

Names of variables (alias for .obs.index)

obsm

Multi-dimensional annotation of observation

obsmap

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

obsp

Pairwise annotatation of observations

shape

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

uns

Unstructured annotation (ordered dictionary).

var

Annotation of variables

var_names

Names of variables (alias for .var.index)

varm

Multi-dimensional annotation of variables

varmap

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

varp

Pairwise annotatation of variables

Methods table#

copy([filename])

Make a copy.

get_weighted_matrix(view_name[, predictors])

Returns the weighted matrix for a given set of predictors in a view.

getdoc()

obs_keys()

List keys of observation annotation obs.

obs_names_make_unique()

Call .obs_names_make_unique() method on each AnnData object.

obs_vector(key[, layer])

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

obsm_keys()

List keys of observation annotation obsm.

pull_obs([columns, mods, common, ...])

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

pull_var([columns, mods, common, ...])

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

push_obs([columns, mods, common, prefixed, ...])

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

push_var([columns, mods, common, prefixed, ...])

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

strings_to_categoricals([df])

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

to_anndata(**kwargs)

Convert MuData to AnnData

uns_keys()

List keys of unstructured annotation.

update()

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

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.

var_keys()

List keys of variable annotation var.

var_names_make_unique()

Call .var_names_make_unique() method on each AnnData object.

var_vector(key[, layer])

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

varm_keys()

List keys of variable annotation varm.

write([filename])

Write MuData object to an HDF5 file

write_h5mu([filename])

Write MuData object to an HDF5 file

write_zarr(store, **kwargs)

Write MuData object to a Zarr store

Attributes#

MistyData.axis#

MuData axis

MistyData.filename#

Filename of the MuData object.

Returns:

Path | None: The path to the file if backed, None otherwise.

MistyData.isbacked#

Whether the MuData object is backed.

Returns:

bool: True if the object is backed, False otherwise.

MistyData.mod_names#

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

This property is read-only.

MistyData.n_mod#

Number of modalities in the MuData object.

Returns:

int: The number of modalities.

MistyData.n_obs#

Total number of observations

MistyData.n_var#

Total number of variables

MistyData.n_vars#

Total number of variables

MistyData.obs#

Annotation of observation

MistyData.obs_names#

Names of variables (alias for .obs.index)

MistyData.obsm#

Multi-dimensional annotation of observation

MistyData.obsmap#

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.

MistyData.obsp#

Pairwise annotatation of observations

MistyData.shape#

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

MistyData.uns#

Unstructured annotation (ordered dictionary).

MistyData.var#

Annotation of variables

MistyData.var_names#

Names of variables (alias for .var.index)

MistyData.varm#

Multi-dimensional annotation of variables

MistyData.varmap#

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.

MistyData.varp#

Pairwise annotatation of variables

Methods#

MistyData.copy(filename=None)#

Make a copy.

Parameters:

filename (PathLike | None (default: None)) – If the object is backed, copy the object to a new file.

Return type:

MuData

MistyData.get_weighted_matrix(view_name, predictors=None)#

Returns the weighted matrix for a given set of predictors in a view.

Parameters:
  • view_name (str) – Name of the view of interest.

  • predictors (list[str] (default: None)) – List of predictors from which to retrieve the weights.

Return type:

Index | ndarray

Returns:

Weighted matrix of the requested view and predictors. If no predictors are provided, returns the variable names.

MistyData.getdoc() str | None#
MistyData.obs_keys()#

List keys of observation annotation obs.

Return type:

list[str]

MistyData.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.

MistyData.obs_vector(key, layer=None)#

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

Return type:

ndarray

MistyData.obsm_keys()#

List keys of observation annotation obsm.

Return type:

list[str]

MistyData.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 the data from the modalities to the global .obs, existing columns to be overwritten or updated

Parameters:
  • columns (list[str] | None (default: None)) – List of columns to pull from the modalities’ .obs tables

  • common (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 | None (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.

MistyData.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 the data from the modalities to the global .var, existing columns to be overwritten or updated

Parameters:
  • columns (list[str] | None (default: None)) – List of columns to pull from the modalities’ .var tables

  • common (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 | None (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.

MistyData.push_obs(columns=None, mods=None, common=None, prefixed=None, drop=False, only_drop=False)#

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

Parameters:
  • columns (list[str] | None (default: None)) – List of columns to push

  • mods (list[str] | None (default: None)) – List of modalities to push to

  • common (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.

MistyData.push_var(columns=None, mods=None, common=None, prefixed=None, drop=False, only_drop=False)#

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

Parameters:
  • columns (list[str] | None (default: None)) – List of columns to push

  • mods (list[str] | None (default: None)) – List of modalities to push to

  • common (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.

MistyData.strings_to_categoricals(df=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.

MistyData.to_anndata(**kwargs)#

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()

Return type:

AnnData

MistyData.uns_keys()#

List keys of unstructured annotation.

Return type:

list[str]

MistyData.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.

MistyData.update_obs()#

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

MistyData.update_var()#

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

MistyData.var_keys()#

List keys of variable annotation var.

Return type:

list[str]

MistyData.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.

MistyData.var_vector(key, layer=None)#

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

Return type:

ndarray

MistyData.varm_keys()#

List keys of variable annotation varm.

Return type:

list[str]

MistyData.write(filename=None, **kwargs)#

Write MuData object to an HDF5 file

MistyData.write_h5mu(filename=None, **kwargs)#

Write MuData object to an HDF5 file

MistyData.write_zarr(store, **kwargs)#

Write MuData object to a Zarr store