liana.mt.MistyData#
- class liana.mt.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[str,AnnData] |MuData Dictionary of views (
AnnData`s) or a `MuDataobject. Note that only thedata.Xattribute 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.obsmthat contains the spatial coordinates.- 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
Any Keyword arguments passed to the MuData Super class
- data
- view_names#
List of names of the different views
- spatial_key#
Key in
data.obsmcontaining the spatial coordinates.
- enforce_obs#
See parameter with the same name.
Examples
Views are
AnnData`s that share observations. The `'intra'view holds the targets to be predicted; every other view is a spatial context and must carry its own connectivities in.obsp['spatial_connectivities']:>>> import liana as li >>> adata = li.ds.generate_toy_spatial() >>> adata = adata[:, adata.var_names[:5]].copy() >>> extra = adata.copy() >>> extra.obsp["spatial_connectivities"] = li.pp.spatial_neighbors( ... extra, bandwidth=200, set_diag=True, inplace=False ... ) >>> misty = li.mt.MistyData({"intra": adata.copy(), "extra": extra})
Each extra view’s expression is multiplied by its connectivities on construction, so that a predictor is a neighbourhood value rather than the spot’s own.
liana.mt.genericMistyData()andliana.mt.lrMistyData()build the views for the two most common designs. Call the object to fit the model – seeliana.mt.MistyData.__call__().
Attributes table#
MuData axis. |
|
Change the backing mode by setting the filename to a |
|
Whether the object is a view of another |
|
Whether the object is backed on disk. |
|
Dictionary of modalities. |
|
Names of modalities (alias for |
|
Number of modalities. |
|
Total number of observations |
|
Total number of variables. |
|
Total number of variables. |
|
Annotation of observation |
|
Names of variables (alias for |
|
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 ( |
|
Unstructured annotation (ordered dictionary). |
|
Annotation of variables. |
|
Names of variables (alias for |
|
Multi-dimensional annotation of variables. |
|
Mapping of feature indices in the object to indices in individual modalities. |
|
Pairwise annotatation of variables. |
Methods table#
|
Make a copy. |
|
Returns the weighted matrix for a given set of predictors in a view. |
|
|
|
List keys of observation annotation |
Call |
|
|
Return an array of values for the requested key of length n_obs. |
List keys of observation annotation |
|
|
Copy data from the |
|
Copy data from the |
|
Copy the data from |
|
Copy the data from |
|
Transform string annotations to categoricals. |
|
Convert the object to |
|
List keys of unstructured annotation. |
|
Update both |
Update |
|
Update |
|
|
List keys of variable annotation |
Call |
|
|
Return an array of values for the requested key of length n_var. |
List keys of variable annotation |
|
|
Write the object to an HDF5 file. |
|
Write the object to an HDF5 file. |
|
Write the object to a Zarr store. |
Attributes#
- MistyData.axis#
MuData axis.
0if the modalities have shared observations1if the modalities have shared features-1if both observations and features are shared
- MistyData.filename#
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").
- MistyData.is_view#
Whether the object is a view of another
MuDataobject.
- MistyData.isbacked#
Whether the object is backed on disk.
- MistyData.mod#
Dictionary of modalities.
- MistyData.mod_names#
Names of modalities (alias for
list(mdata.mod.keys()))
- MistyData.n_mod#
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 observations.
Stores for each key a two- or higher-dimensional
ndarrayorDataFrameof lengthn_obs. Is sliced withobsbut otherwise behaves like a mapping.
- MistyData.obsmap#
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.
- MistyData.obsp#
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.
- 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.
Stores for each key a two- or higher-dimensional
ndarrayorDataFrameof lengthn_vars. Is sliced withvarbut otherwise behaves like a mapping.
- MistyData.varmap#
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.
Methods#
- MistyData.copy(filename=None)#
Make a copy.
- MistyData.get_weighted_matrix(view_name, predictors=None)#
Returns the weighted matrix for a given set of predictors in a view.
- Parameters:
- Return type:
NDArray[number] |csc_matrix|csr_matrix|csc_array|csr_array- Returns:
Weighted matrix of the requested view and predictors. If no predictors are provided, returns the variable names.
- MistyData.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.
- MistyData.obs_vector(key, layer=None)#
Return an array of values for the requested key of length n_obs.
- 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 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 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(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.
- columns
- 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 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 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(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.
- columns
- MistyData.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 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.
- columns
- MistyData.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 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.
- columns
- MistyData.strings_to_categoricals(df=None)#
Transform string annotations to categoricals.
- MistyData.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:
- MistyData.update()#
Update both
obsandvarindices of the object with the data from all the modalities.
- MistyData.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.
- MistyData.var_vector(key, layer=None)#
Return an array of values for the requested key of length n_var.
- MistyData.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().
- filename
- MistyData.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().
- filename
- MistyData.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().
- store