liana.multi.adata_to_views#
- liana.multi.adata_to_views(adata, groupby, sample_key, obs_keys=None, view_sep=':', keep_stats=False, verbose=False, psbulk_kwargs=None, filter_samples_kwargs=None, filter_by_expr_kwargs=None, filter_by_prop_kwargs=None)#
Converts an AnnData object to a MuData object with views that represent an aggregate for each entity in
adata.obs[groupby].- Parameters:
adata (
AnnData) – Annotated data object.groupby (
str) – Key to be used for grouping.sample_key (
str) – key inadata.obsto use for grouping by sample or context.obs_keys (
list[str] (default:None)) – Column names inadata.obsto merge with the MuData objectview_sep (
str(default:':')) – Separator to use when assigningadata.var_namesto viewskeep_stats (
bool(default:False)) – If True, keep the pseudobulk statistics inmdata.uns['psbulk_stats']. Default is False.verbose (
bool(default:False)) – Verbosity flag.psbulk_kwargs (
dict(default:None)) – Arguments to pass todc.pp.pseudobulkfor pseudobulking. Seedecouplerdocumentation for more details.filter_samples_kwargs (
dict(default:None)) – Arguments to pass todc.pp.filter_samplesfor filtering samples. Seedecouplerdocumentation for more details. If None, won’t filter.filter_by_expr_kwargs (
dict(default:None)) – Optional mapping of arguments to pass todc.pp.filter_by_exprfor gene filtering by expression. If None, won’t filter.filter_by_prop_kwargs (
dict(default:None)) – Optional mapping of arguments to pass todc.pp.filter_by_propfor gene filtering by proportion of cells that express the gene. If None, won’t filter.
- Return type:
- Returns:
Returns a MuData object with views that represent an aggregate for each entity in
adata.obs[groupby].
Examples
Each cell type becomes a view of pseudobulk profiles, with samples as the observations – the multicellular structure that MOFA is then fit on:
>>> import liana as li >>> adata = li.testing.generate_toy_adata() >>> mdata = li.mu.adata_to_views(adata, ... groupby='bulk_labels', ... sample_key='sample', ... obs_keys=['case'], ... psbulk_kwargs={'raw': True, 'skip_checks': True})
Only the views that survive the expression filters are kept, each variable is prefixed with its view, and
obs_keysare joined onto the sample-level.obs. Passfilter_by_expr_kwargsto tighten or relax those filters – they go straight todecoupler.