skm_tools.translate =================== .. py:module:: skm_tools.translate .. autoapi-nested-parse:: Translate Arabidopsis (ath) networks to other species with SKM gene translation files. Functions --------- .. autoapisummary:: skm_tools.translate.load_translation_file skm_tools.translate.integrate_translation_ckn Module Contents --------------- .. py:function:: load_translation_file(species_code, translation_path=None, data_dir='.') Load a SKM gene translation file, downloading it from skm.nib.si if missing. :param species_code: SKM species code of the translation (e.g. ``"stu"`` for potato, ``"parm"`` for apricot). :type species_code: str :param translation_path: Local file (default ``/translation_ath_to_.tsv.gz``); downloaded if it doesn't exist (so it can be reused offline), gzipped if the name ends in ``.gz``. :type translation_path: str or pathlib.Path, optional :param data_dir: Folder for the default file name (default: the current folder). :type data_dir: str or pathlib.Path :returns: The translation table: the Arabidopsis genes (``ath_source``), the genes of the species (a column named after the species, e.g. ``potato``), and the evidence. All values are strings (empty: None). :rtype: pandas.DataFrame .. py:function:: integrate_translation_ckn(g, translation_df, t_target_col, g_source_attribute='TAIR', t_source_col='ath_source', method='full_replacement', edges_within_translation=True, edges_across_translation=True, keep_unmapped=True) Translate the Arabidopsis genes of CKN to another species' gene identifiers. Each node with an Arabidopsis gene identifier (`g_source_attribute`, e.g. ``TAIR``) is replaced by one node per translation of its gene; translations can be many-to-many, and all are kept. Translated node ids are ``{original}_{translation}``, so one original can have several translations. Edges of the original node are copied to every new node. Nodes without an identifier (complexes, metabolites, processes, nodes of other species) are copied as they are. Translation edges (see `edges_within_translation`, `edges_across_translation`) have ``type`` and ``interaction`` ``"homology"`` and ``directed`` False; in a directed graph, they are added in both directions. :param g: CKN with Arabidopsis gene identifiers (``species`` == ``"ath"``). :type g: networkx.Graph :param translation_df: Translation table, e.g. from :func:`load_translation_file`, with a source (Arabidopsis) and a target identifier column. :type translation_df: pandas.DataFrame :param t_target_col: Column of `translation_df` with the target species' identifiers (e.g. ``"potato"``). :type t_target_col: str :param g_source_attribute: Node attribute of `g` with the Arabidopsis identifier (default ``"TAIR"``). :type g_source_attribute: str :param t_source_col: Column of `translation_df` with the Arabidopsis identifiers (default ``"ath_source"``). :type t_source_col: str :param method: How to add the translations. Only ``"full_replacement"`` (replace the original nodes) is implemented; ``"pendant_nodes"`` (add translations as extra nodes linked to the originals) is planned. :type method: {"full_replacement"} :param edges_within_translation: Link the translations of the same original node to each other (``translation_relation`` == ``"same_translation_source"``). :type edges_within_translation: bool :param edges_across_translation: Link the nodes of different originals that translate to the same gene (``translation_relation`` == ``"same_translation_target"``). :type edges_across_translation: bool :param keep_unmapped: Keep the nodes with an identifier but without a translation (with ``translated`` False), or drop them and their edges. :type keep_unmapped: bool :returns: A new graph: a (Multi)DiGraph if `g` is directed, a (Multi)Graph otherwise; a multigraph if either kind of translation edge is added. Translated nodes get the attributes ``translation``, ``translated_from`` and ``translated``. :rtype: networkx.Graph :raises NotImplementedError: For a `method` other than ``"full_replacement"``.