liana.resource.translate_column

liana.resource.translate_column#

liana.resource.translate_column(resource, map_df, column, replace=True, one_to_many=1)#

Generate orthologs for a given column in a DataFrame.

Parameters:
  • resource (DataFrame) – Input DataFrame.

  • map_df (DataFrame) – DataFrame with orthology mappings, where the first column is the source and the second column is the target for mapping.

  • column (str) – Column name to translate.

  • replace (bool (default: True)) – Whether to replace the original column with the translated values. Default is True. If False, it will create a new column with the prefix orthology_.

  • one_to_many (int (default: 1)) – Maximum number of orthologs allowed per gene. Default is 1.

  • Details

  • -------

  • DataFrame. (This function generates orthologs for a given column in a)

  • orthologs. (It handles complex names by splitting them into subunits and generating all possible combinations of)

  • ("_"). (It assumes that subunits are separated by an underscore)

Return type:

DataFrame

Returns:

Resulting DataFrame with translated column.

Raises:

ValueError – If the mapping_df does not contain ‘source’ and ‘target’ columns or one_to_many is not an integer

Examples

map_df maps human symbols (source) to the target organism (target). liana.resource.get_hcop_orthologs() builds one; it is written out here to keep the example offline:

>>> import pandas as pd
>>> import liana as li
>>> resource = li.rs.select_resource('consensus').head(3)
>>> map_df = pd.DataFrame({'source': ['LGALS9', 'PTPRC', 'MET', 'CD44'],
...                        'target': ['Lgals9', 'Ptprc', 'Met', 'Cd44']})
>>> li.rs.translate_column(resource, map_df, column='ligand')
   ligand receptor
0  Lgals9    PTPRC
1  Lgals9      MET
2  Lgals9     CD44

With replace=False the translation is added as an orthology_ligand column instead of overwriting ligand. Use liana.resource.translate_resource() to do both sides at once.