skm_tools.pss

PSS (Plant Stress Signalling): load the network exports, filter, simplify and rewire.

The PSS exports (reaction graph, interaction network, per-species gene networks) are made by skm-pss-export (https://github.com/NIB-SI/skm-pss-export).

The loaders record which network a graph is in g.graph["pss_network"] ("reaction_graph", "interaction_network" or "gene_network", with the species of a gene network in g.graph["species"]); the functions here use it to check that they are applied to a network they work on.

Attributes

logger

REACTION_GRAPH

INTERACTION_NETWORK

GENE_NETWORK

Functions

pss_reaction_graph_to_networkx([edge_path, node_path, ...])

pss_interaction_network_to_networkx([edge_path, ...])

pss_gene_network_to_networkx([edge_path, node_path, ...])

remove_reactions(g, reaction_ids[, remove_isolates])

Remove PSS reactions, in place.

remove_deadend_complexes(g)

Remove complexes without outgoing edges, in place.

filter_pss_nodes(g[, node_types, species, remove_isolates])

Remove PSS nodes, in place.

simplify_pss(g[, split_on_attrs, verbose])

Merge parallel edges (one per reaction) into one edge per node pair.

remove_and_rewire(g, nodes[, dry_run])

Remove nodes, connecting each of their upstream nodes to each of their downstream nodes.

remove_duplicated_binding_edges(g)

Keep one direction of each mutual binding edge, in place.

metabolite_enzymes(g)

The enzymes of the reactions that produce and that consume each metabolite.

pathway_gene_sets(g[, attribute, genes_only])

PSS pathways as node sets, e.g. for an enrichment analysis.

Module Contents

skm_tools.pss.logger
skm_tools.pss.REACTION_GRAPH = 'reaction_graph'
skm_tools.pss.INTERACTION_NETWORK = 'interaction_network'
skm_tools.pss.GENE_NETWORK = 'gene_network'
skm_tools.pss.pss_reaction_graph_to_networkx(edge_path=None, node_path=None, data_dir='.')
skm_tools.pss.pss_interaction_network_to_networkx(edge_path=None, node_path=None, data_dir='.')
skm_tools.pss.pss_gene_network_to_networkx(edge_path=None, node_path=None, species='ath', data_dir='.')
skm_tools.pss.remove_reactions(g, reaction_ids, remove_isolates=True)

Remove PSS reactions, in place.

Works on all three PSS networks: in the reaction graph, the reaction nodes are removed (with their participant edges); in the interaction network and the gene networks, the edges with these reaction_id values. Merged edges (e.g. from simplify_pss()) that also come from other reactions are kept, with only those reaction ids.

Parameters:
  • g (networkx.MultiDiGraph or networkx.DiGraph) – PSS network. Changed in place.

  • reaction_ids (str or iterable of str) – Reactions to remove (e.g. ["rx00001"]); reactions not in g are ignored.

  • remove_isolates (bool) – Also remove nodes without edges afterwards (default True); this includes nodes that had no edges before.

Returns:

Removed node -> reason ("reaction removed" for reaction nodes of the reaction graph, "isolate").

Return type:

dict

Examples

>>> import networkx as nx
>>> g = nx.MultiDiGraph()
>>> _ = g.add_edge("A", "B", key="rx1", reaction_id="rx1")
>>> _ = g.add_edge("B", "C", key="rx2", reaction_id="rx2")
>>> remove_reactions(g, "rx1")
{'A': 'isolate'}
skm_tools.pss.remove_deadend_complexes(g)

Remove complexes without outgoing edges, in place.

A complex that influences nothing (is not an input or modifier of any reaction) is a dead end in directed analyses. Repeated until no dead-end complexes are left, since removing one can leave another without outgoing edges.

In the interaction network and the gene networks, only the complexes are removed: the binding partners’ mutual edges from the same reactions are kept. In the reaction graph, the reactions producing the complexes are removed (see remove_reactions()), and then the nodes left without edges.

Parameters:

g (networkx.DiGraph or networkx.MultiDiGraph) – PSS network. Changed in place.

Returns:

Removed node -> reason ("dead-end complex"; in the reaction graph also "reaction removed" and "isolate").

Return type:

dict

skm_tools.pss.filter_pss_nodes(g, node_types=None, species=None, remove_isolates=True)

Remove PSS nodes, in place.

With species, the functional clusters without genes in the species, and the complexes they are components of, are removed with their reactions (see remove_reactions()), as in the species’ gene network: applied to the interaction network, the result has the same reactions and edges as the gene network, with clusters instead of genes. With node_types, complexes with a removed component are removed too (using the components and component_cluster_ids node attributes; components not in g are ignored).

Parameters:
  • g (networkx.Graph) – PSS network. Changed in place.

  • node_types (str or list of str, optional) – Keep only nodes of these node_type values (e.g. "PlantCoding", "Complex"; in a gene network, genes have their cluster’s class, e.g. "PlantCoding"). Not for the reaction graph, where it would leave reactions with missing participants.

  • species (str or list of str, optional) – Interaction network or reaction graph: remove the functional clusters without genes in any of these species (<species>_homologues attributes, e.g. ["stu"]), the complexes with such a cluster among their components (component_cluster_ids), and their reactions. Abstract clusters (PlantAbstract) have no genes and are kept, as metabolites. Merged edges (e.g. from simplify_pss()) are kept if they also come from other reactions. A gene network is already for one species.

  • remove_isolates (bool) – Also remove nodes without edges afterwards (default True); this includes nodes that had no edges before.

Returns:

Removed node -> reason ("species missing", "wrong node type", "complex component removed", "reaction removed" or "isolate").

Return type:

dict

Raises:

ValueError – If node_types is given for the reaction graph, species for a gene network, or a species without a <species>_homologues attribute in g (e.g. a misspelt code, or an export for some species only, which has genes instead).

skm_tools.pss.simplify_pss(g, split_on_attrs=None, verbose=False)

Merge parallel edges (one per reaction) into one edge per node pair.

Returns a new graph; g is unchanged. For the interaction network or a gene network, not the reaction graph (raises ValueError).

Each edge gets the reaction_id values of the edges merged into it, as a sorted list, and their other attributes per reaction: lists aligned with reaction_id (e.g. reaction_type, source_role, evidence_sentence, influence_sbo). Edges that aren’t merged get lists too, so each attribute has one type. Three attributes are summarised in one value instead (skm_tools.utils.merge_values()), ignoring missing values (None):

  • all values equal: that value;

  • interaction: "unknown-influence" if they differ (e.g. a positive and a negative influence; influence_sbo has the influence of each reaction);

  • directed: True if any edge is directed;

  • rank: the lowest.

For example, the edge of reactions rx1 (catalysis) and rx2 (binding/oligomerisation): reaction_id ["rx1", "rx2"], reaction_type ["catalysis", "binding/oligomerisation"]. To compare an attribute with a value, compare its elements: "catalysis" in d["reaction_type"].

Parameters:
  • g (networkx.MultiDiGraph) – PSS interaction network or gene network.

  • split_on_attrs (str or list of str, optional) – Edge attributes (e.g. ["interaction"]) that must not be merged away: parallel edges are only merged with others that have the same values for all of them. These keep their one value (not a list).

  • verbose (bool) – Log every merged edge whose summary attributes differed, with the value kept (INFO; otherwise DEBUG). A summary, with the number of merged edges per differing attribute, is always logged (INFO).

Returns:

A DiGraph, or a MultiDiGraph with split_on_attrs (as edges that differ on them stay separate). Graph attributes (e.g. pss_network) are copied.

Return type:

networkx.DiGraph or networkx.MultiDiGraph

Raises:

ValueError – If g is the reaction graph, or not a multigraph (e.g. already simplified).

skm_tools.pss.remove_and_rewire(g, nodes, dry_run=False)

Remove nodes, connecting each of their upstream nodes to each of their downstream nodes.

Changes g in place. The nodes are removed one at a time, each against the graph as rewired so far, so chains of removed nodes (A -> B -> C -> D, removing B and C) are bridged (A -> D). They are removed upstream first (in a topological order of the network, nodes on a cycle by name), whatever the order they are given in, so the result doesn’t depend on it.

Rewiring doesn’t go through the mutual edges between binding partners (partner <-> partner), in either direction, only through the complex-forming ones (partner -> complex): A -> B and B <-> D (binding) give no A -> D, but A -> B and B -> B|D give A -> B|D.

Catalysis: the catalyst -| substrate edges (the enzyme uses up its substrate) are not rewired through as they are. Removing a substrate connects the nodes upstream of it to its catalysts instead, as substrate -> catalyst (positive); and not to the product of a catalysed reaction, which it reaches through the catalyst (the substrate -> product edge of a reaction with a catalyst is not rewired through, from the substrate’s side; nor from the product’s, when the substrate is removed too, so the result doesn’t depend on the order). So removing the metabolites of a pathway connects its enzymes, in order: E1 catalysing A -> B and E2 catalysing B -> C give E1 -> E2 (through B; positive), without shortcuts past E2. A reaction without a catalyst keeps its substrate -> product route (E1 -> B, B -> C uncatalysed, C -> D by E3: E1 -> E3). The edges are recognised by their reaction_type, roles and reaction ids, per reaction: each reaction of a merged edge (e.g. from simplify_pss()) is rewired as its own.

A new edge A -> C, replacing A -> B -> C:

  • reaction_id: the reaction ids of both edges (a sorted list), and the other attributes per reaction, as in simplify_pss(): source_* attributes from A -> B (None for the reactions of B -> C only, in which A takes no part), target_* attributes from B -> C (None for those of A -> B only), and the others from the edge of the reaction;

  • note: "rewired through B" (for each reaction);

  • interaction: the sign of the chain (positive and negative: negative; two negatives: positive; anything with an unknown influence: unknown);

  • directed: True; rank: the lower.

If A -> C already exists, the new edge is merged into it, as in simplify_pss() (a reaction of both keeps the attributes of the existing edge).

Parameters:
  • g (networkx.DiGraph) – A simple directed graph, e.g. from simplify_pss(). Multigraphs are not supported.

  • nodes (node or iterable of nodes) – Nodes to remove (nodes not in g are ignored, with a warning).

  • dry_run (bool) – Don’t change g; return the edges that would be added instead.

Returns:

Removed node -> reason ("rewired", or "nothing to rewire" if no edge replaced it); with dry_run, the edges (u, v, data) that would be added or changed.

Return type:

dict or list

Raises:
skm_tools.pss.remove_duplicated_binding_edges(g)

Keep one direction of each mutual binding edge, in place.

Binding partners are linked in both directions (A -> B and B -> A, same reaction); this removes one of the two (which one is arbitrary), e.g. for a less cluttered drawing. A merged edge (e.g. from simplify_pss()) is removed only if all its reactions are bindings that the opposite edge has too. Don’t use it before directed path or neighbourhood analysis.

Parameters:

g (networkx.DiGraph or networkx.MultiDiGraph) – PSS interaction network or gene network (not the reaction graph; each parallel edge of a multigraph is considered separately). Changed in place.

Returns:

The removed edges, (u, v) or, for a multigraph, (u, v, key).

Return type:

list

skm_tools.pss.metabolite_enzymes(g)

The enzymes of the reactions that produce and that consume each metabolite.

From the catalysis reactions: a catalyst’s edge to a reaction’s product (target_role "product") and to its substrate ("substrate"), for each reaction of an edge (also of merged edges, e.g. from simplify_pss()).

Parameters:

g (networkx.MultiDiGraph or networkx.DiGraph) – PSS interaction network or gene network.

Returns:

One row per enzyme, metabolite and reaction: enzyme, metabolite, role ("producer" or "consumer"), reaction_id, metabolite_type (Metabolite or MetaboliteFamily).

Return type:

pandas.DataFrame

skm_tools.pss.pathway_gene_sets(g, attribute='all_pathways', genes_only=True)

PSS pathways as node sets, e.g. for an enrichment analysis.

Parameters:
  • g (networkx.Graph) – PSS gene network (or interaction network).

  • attribute (str) – Node attribute with the pathways (default "all_pathways"; "pathway" for the main ones).

  • genes_only (bool) – Only genes (nodes with a species; default), not metabolites or complexes.

Returns:

Pathway -> sorted list of nodes.

Return type:

dict