skm_tools.annotations

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 <bin code>_<full bin name>, e.g. 26.11.3.2.1_External stimuli response.pathogen.defense mechanisms....

Functions

get_all_annotations(g[, key])

All values of a list-valued node attribute.

get_nodes_by_mapman(g, bins[, children])

Nodes annotated with any of the given MapMan bins.

mercator_gene_sets(path[, levels, min_size, max_size, ...])

MapMan gene sets from a Mercator4 result file, e.g. for an enrichment analysis.

read_plantgsea(path)

The gene sets of a PlantGSEA download, as a table.

plantgsea_gene_sets(path[, sources, min_size, max_size])

PlantGSEA gene sets, e.g. for an enrichment analysis.

Module Contents

skm_tools.annotations.get_all_annotations(g, key='mapman')

All values of a list-valued node attribute.

Parameters:
  • g (networkx.Graph)

  • key (str) – 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.

Return type:

set

skm_tools.annotations.get_nodes_by_mapman(g, bins, children=True)

Nodes annotated with any of the given MapMan bins.

Parameters:
  • g (networkx.Graph) – PSS or CKN, with list-valued mapman node attributes.

  • bins (str or list of str) – 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.

  • children (bool) – 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.

Returns:

Matching nodes.

Return type:

list

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']
skm_tools.annotations.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.

Parameters:
  • path (str or pathlib.Path) – Mercator4 result file (tab-separated, with the columns BINCODE, NAME and IDENTIFIER, values in single quotes), optionally gzipped (.gz).

  • levels (int or list of int, optional) – Bin levels to keep, e.g. [1, 2, 3] (1 is the top level). Default: all.

  • min_size (int, optional) – Keep bins with at least min_size (default 1) and at most max_size genes.

  • max_size (int, optional) – Keep bins with at least min_size (default 1) and at most max_size genes.

  • exclude_bins (list of str) – Bins to leave out, with their sub-bins. Default ("35",): MapMan4’s not assigned.

  • id_to_gene (callable, optional) – 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.

Returns:

<bin code>_<full bin name> (as in the mapman node attribute) -> sorted list of gene ids, ordered by bin code.

Return type:

dict

Examples

>>> import re
>>> sets = mercator_gene_sets(
...     "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))
skm_tools.annotations.read_plantgsea(path)

The gene sets of a PlantGSEA download, as a table.

Parameters:

path (str or pathlib.Path) – PlantGSEA “DetailInfo” file (e.g. Ara.DetailInfo_<date>.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).

Returns:

set, source, reference, description, genes (list of Arabidopsis gene ids; other identifiers in the file are left out).

Return type:

pandas.DataFrame

skm_tools.annotations.plantgsea_gene_sets(path, sources=None, min_size=1, max_size=None)

PlantGSEA gene sets, e.g. for an enrichment analysis.

Parameters:
  • path (str or pathlib.Path) – PlantGSEA “DetailInfo” file, see read_plantgsea().

  • sources (str or list of str, optional) – Keep only sets of these sources (e.g. ["GO_BP", "Literature"]). Default: all.

  • min_size (int, optional) – Keep sets with at least min_size (default 1) and at most max_size genes.

  • max_size (int, optional) – Keep sets with at least min_size (default 1) and at most max_size genes.

Returns:

Set name -> sorted list of gene ids.

Return type:

dict