liana.resource.generate_lr_geneset#
- liana.resource.generate_lr_geneset(resource, net, ligand_key='ligand', receptor_key='receptor', lr_sep='^', source='source', target='target', weight='weight')#
Generate a ligand-receptor gene set from a resource and a network.
Specifically, it works with weighted bipartite networks, where the weight represents the importance of the genes to a given geneset. The function will assign a weight to each ligand-receptor interaction, based on the mean. It does so by first assigning a weight to each ligand-receptor subunit, checking for sign coherence and completeness of the ligand-receptor complex.
- Parameters:
resource (
DataFrame) – A pandas dataframe with [ligand,receptor] columns.net (
DataFrame) – Prior knowledge network in bipartite or decoupler format.ligand – Name of the ligand column in the resource
receptor – Name of the receptor column in the resource
lr_sep (
str(default:'^')) – Separator to use when joining ligand and receptor names into interactions.source (
str(default:'source')) – Name of the source column in the network.weight (
str(default:'weight')) – Name of the weight column in the network. If None, all weights are set to 1.
- Return type:
DataFrame- Returns:
Returns ligand-receptor geneset resource as a pandas.DataFrame with the following columns: - interaction: ligand-receptor interaction - weight: mean weight of the interaction - source: source of the interaction
Examples
netis a bipartite gene set (e.g. pathways, transcription-factor regulons) in decoupler format. Only ligand-receptor pairs whose both partners are in the same gene set, with coherent signs, are kept:>>> import pandas as pd >>> import liana as li >>> resource = li.rs.select_resource('consensus') >>> net = pd.DataFrame({'source': ['pathA', 'pathA', 'pathB', 'pathB'], ... 'target': ['LGALS9', 'PTPRC', 'THY1', 'ITGB2'], ... 'weight': [1.0, 1.0, -1.0, -1.0]}) >>> geneset = li.rs.generate_lr_geneset(resource, net) >>> geneset source interaction weight 0 pathA LGALS9^PTPRC 1.0 1 pathB ITGB2^THY1 -1.0
The result can then be handed to an enrichment method (e.g.
decoupler) with the interaction names as features.