skm_tools.annotations ===================== .. py:module:: skm_tools.annotations .. autoapi-nested-parse:: MapMan annotations of PSS and CKN nodes, and MapMan gene sets from Mercator files. Both networks have a ``mapman`` node attribute: a list of MapMan bins (GoMapMan 2, MapMan4), each as ``_``, e.g. ``26.11.3.2.1_External stimuli response.pathogen.defense mechanisms...``. Functions --------- .. autoapisummary:: skm_tools.annotations.get_all_annotations skm_tools.annotations.get_nodes_by_mapman skm_tools.annotations.mercator_gene_sets skm_tools.annotations.read_plantgsea skm_tools.annotations.plantgsea_gene_sets Module Contents --------------- .. py:function:: get_all_annotations(g, key='mapman') All values of a list-valued node attribute. :param g: :type g: networkx.Graph :param key: Node attribute holding a list, a single value, or None, e.g. ``"mapman"`` (default) or ``"tissue"``. A single value (e.g. a string) counts as a one-item list. :type key: str :rtype: set .. py:function:: get_nodes_by_mapman(g, bins, children=True) Nodes annotated with any of the given MapMan bins. :param g: PSS or CKN, with list-valued ``mapman`` node attributes. :type g: networkx.Graph :param bins: MapMan bin codes, e.g. ``"26.11"`` or ``["26.11", "15.5"]``; values with the bin name (``"26.11_External stimuli response.pathogen"``) work too: only the code is used. :type bins: str or list of str :param children: Also match the sub-bins of each bin (default True): ``"26.11"`` matches ``26.11``, ``26.11.3``, ``26.11.3.2.1``, ... but not ``26.110``. :type children: bool :returns: Matching nodes. :rtype: list .. rubric:: Examples >>> import networkx as nx >>> g = nx.Graph() >>> g.add_node("AT2G38470", mapman=["26.11.3.2.1_External stimuli response.pathogen..."]) >>> g.add_node("ABA", mapman=None) >>> get_nodes_by_mapman(g, "26.11") ['AT2G38470'] .. py:function:: mercator_gene_sets(path, levels=None, min_size=1, max_size=None, exclude_bins=('35', ), id_to_gene=None) MapMan gene sets from a Mercator4 result file, e.g. for an enrichment analysis. A gene counts in the bins it is annotated with and in all their parent bins: ``1.1.1`` also counts in ``1.1`` and ``1``. :param path: Mercator4 result file (tab-separated, with the columns ``BINCODE``, ``NAME`` and ``IDENTIFIER``, values in single quotes), optionally gzipped (``.gz``). :type path: str or pathlib.Path :param levels: Bin levels to keep, e.g. ``[1, 2, 3]`` (``1`` is the top level). Default: all. :type levels: int or list of int, optional :param min_size: Keep bins with at least `min_size` (default 1) and at most `max_size` genes. :type min_size: int, optional :param max_size: Keep bins with at least `min_size` (default 1) and at most `max_size` genes. :type max_size: int, optional :param exclude_bins: Bins to leave out, with their sub-bins. Default ``("35",)``: MapMan4's *not assigned*. :type exclude_bins: list of str :param id_to_gene: Converts a Mercator identifier (usually a lower-case protein or transcript id, e.g. ``"pruarm.3g005300.t1.p1_1"``) to a gene id. Default: the identifier as it is. :type id_to_gene: callable, optional :returns: ``_`` (as in the ``mapman`` node attribute) -> sorted list of gene ids, ordered by bin code. :rtype: dict .. rubric:: Examples >>> import re >>> sets = mercator_gene_sets( # doctest: +SKIP ... "parm_Mercator4v7_results.txt", levels=[1, 2, 3], min_size=5, ... id_to_gene=lambda i: re.sub(r"^pruarm\.(\d+)g(\d+)\..*", r"PruarM.\1G\2", i)) .. py:function:: read_plantgsea(path) The gene sets of a PlantGSEA download, as a table. :param path: PlantGSEA "DetailInfo" file (e.g. ``Ara.DetailInfo_.txt``): tab-separated, no header; column 1 the set name, 2 the source (e.g. ``GO_BP``, ``Literature``, ``KEGG``), 4 the reference (PubMed id), 9 the description and 11 the comma-separated genes. Latin-1 encoded; optionally gzipped (``.gz``). :type path: str or pathlib.Path :returns: ``set``, ``source``, ``reference``, ``description``, ``genes`` (list of Arabidopsis gene ids; other identifiers in the file are left out). :rtype: pandas.DataFrame .. py:function:: plantgsea_gene_sets(path, sources=None, min_size=1, max_size=None) PlantGSEA gene sets, e.g. for an enrichment analysis. :param path: PlantGSEA "DetailInfo" file, see :func:`read_plantgsea`. :type path: str or pathlib.Path :param sources: Keep only sets of these sources (e.g. ``["GO_BP", "Literature"]``). Default: all. :type sources: str or list of str, optional :param min_size: Keep sets with at least `min_size` (default 1) and at most `max_size` genes. :type min_size: int, optional :param max_size: Keep sets with at least `min_size` (default 1) and at most `max_size` genes. :type max_size: int, optional :returns: Set name -> sorted list of gene ids. :rtype: dict