liana.mt.df_to_lr#
- liana.mt.df_to_lr(adata, dea_df, groupby, stat_keys, resource_name='consensus', resource=None, interactions=None, groupby_pairs=None, layer=None, use_raw=False, expr_prop=0.1, min_cells=5, complex_col=None, return_all_lrs=False, source_labels=None, target_labels=None, lr_sep='^', verbose=False)#
Convert DEA results to ligand-receptor pairs.
- Parameters:
- adata
AnnData Annotated data object.
- dea_df
DataFrame DEA results. Index must match adata.var_names
- groupby
str Key to be used for grouping.
- stat_keys
list[str] List of statistics to be used for ligand-receptor pairs
- resource_name
str(default:'consensus') Name of the resource to be used for ligand-receptor inference. See
li.rs.show_resources()for available resources.- resource
DataFrame|None(default:None) A pandas dataframe with [
ligand,receptor] columns. If provided will overrule the resource requested viaresource_name- interactions
list[tuple[str,str]] |None(default:None) List of tuples with ligand-receptor pairs
[(ligand, receptor), ...]to be used for the analysis. If passed, it will overrule the resource requested viaresourceandresource_name.- groupby_pairs
DataFrame|None(default:None) A DataFrame with columns
sourceandtargetto be used to subset the possible combinations of interacting cell types. If None, all possible combinations are used.- layer
str|None(default:None) Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.
- use_raw
bool(default:False) Whether to use the
.rawattribute of adata. Defaults to False (uses.X).- expr_prop
float(default:0.1) Minimum expression proportion for the ligands and receptors (+ their subunits) in the corresponding cell identities. Set to 0 to return unfiltered results.
- min_cells
int(default:5) Minimum cells (per cell identity if grouped by
groupby) to be considered for downstream analysis.- complex_col
str|None(default:None) Column in
dea_dfto use for complex expression. Default is None. If None, will use mean expression (‘expr’) calculated per group ingroupby.- return_all_lrs
bool(default:False) Bool whether to return all ligand-receptor pairs, or only those that surpass the
expr_propthreshold. Ligand-receptor pairs that do not pass theexpr_propthreshold will be assigned to the worst score of the ones that do.Falseby default.- source_labels
list[str] |None(default:None) List of labels to use as
source, the rest are filtered out.- target_labels
list[str] |None(default:None) List of labels to use as
target, the rest are filtered out.- lr_sep
str(default:'^') Separator to use when joining ligand and receptor names into interactions.
- verbose
bool(default:False) Verbosity flag.
- adata
- Return type:
- Returns:
Returns a pd.DataFrame with joined ligand-receptor pairs and statistics.
- Raises:
ValueError – If the
groupbyvalue is not inadataordea_df, ifdea_dfindexes do not matchadata.var_namesor ifcomplex_coldoes not match one of the computed stats.AssertionError – If there’s no match when grouping-by between
adata.obsanddea_df.
Examples
dea_dfholds per-cell-type differential expression statistics, indexed by gene. It normally comes from a tool such aspydeseq2orscanpy; a stand-in is built here so the example stays offline:>>> import numpy as np >>> import pandas as pd >>> import liana as li >>> adata = li.ds.generate_toy_adata() >>> groups = adata.obs["bulk_labels"].cat.categories >>> rng = np.random.default_rng(1337) >>> dea_df = pd.DataFrame( ... {"bulk_labels": np.repeat(groups, adata.n_vars), "stat": rng.normal(size=len(groups) * adata.n_vars)}, ... index=np.tile(adata.var_names, len(groups)), ... ) >>> lr_res = li.mt.df_to_lr(adata, dea_df=dea_df, groupby="bulk_labels", stat_keys=["stat"])
Each statistic named in
stat_keysis carried over to both sides of every interaction – asligand_statandreceptor_stat– and averaged into aninteraction_statcolumn.