FEV_KEGG.Drawing.Export module

FEV_KEGG.Drawing.Export.COLOUR_NAME = 'colour'

Name of the attribute of the graph to be used for storing the colour.

class FEV_KEGG.Drawing.Export.Colour[source]

Bases: enum.Enum

An enumeration.

BLUE = '#4444FF'
GREEN = '#55FF55'
PINK = '#FF66FF'
RED = '#FF5555'
TURQUOISE = '#55FFFF'
YELLOW = '#FFFF55'
FEV_KEGG.Drawing.Export.DESCRIPTION_NAME = 'custom_description'

Name of the attribute of the graph to be used for storing the description.

FEV_KEGG.Drawing.Export.ID_NAME = 'custom_id'

Name of the attribute of the graph to be used for storing the id.

FEV_KEGG.Drawing.Export.LABEL_NAME = 'custom_label'

Name of the attribute of the graph to be used for storing the label.

FEV_KEGG.Drawing.Export.MAJORITY_NAME = 'custom_majority'

Name of the attribute of the graph to be used for storing the majority percentage.

FEV_KEGG.Drawing.Export.REACTION_NAME = 'custom_reaction'

Name of the attribute of the graph to be used for storing the reaction.

FEV_KEGG.Drawing.Export.URL_NAME = 'URL'

Name of the attribute of the graph to be used for storing the URL.

FEV_KEGG.Drawing.Export.addColourAttribute(graph: FEV_KEGG.Graph.Models.CommonGraphApi, colour: FEV_KEGG.Drawing.Export.Colour, nodes=False, edges=False)[source]

Adds the “colour” attribute to selected nodes/edges.

If both, nodes and edges are False, nothing is coloured. Adds an attribute to nodes and edges called “colour” (see module variable COLOUR_NAME) containing the string of a hex value of a colour in RGB, see Colour.

Parameters:
  • graph (Models.CommonGraphApi) – A graph object.
  • colour (Colour) – Colour to use.
  • nodes (Iterable[NodeView] or bool, optional) – Nodes to be coloured, i.e. annotated with the “colour” attribute containing colour. If True, all nodes are coloured.
  • edges (Iterable[EdgeView] or bool, optional) – Edges to be coloured, i.e. annotated with the “colour” attribute containing colour. If True, all edges are coloured.

Warning

Any operation on the resulting graph, e.g. FEV_KEGG.Graph.Models.CommonGraphApi.intersection(), removes the colouring. It actually removes all attributes.

FEV_KEGG.Drawing.Export.addDescriptionAttribute(nxGraph: networkx.classes.multigraph.MultiGraph)[source]

Adds the “custom_description” attribute to each node and edge.

Add an attribute to nodes and edges called “custom_description” (see module variable DESCRIPTION_NAME) containing the node’s or edge’s .description field, if there is any.

Parameters:nxGraph (networkx.classes.MultiGraph) – A NetworkX graph object.
FEV_KEGG.Drawing.Export.addIdAttribute(nxGraph: networkx.classes.multigraph.MultiGraph)[source]

Adds the “custom_id” attribute to each node and edge.

Add an attribute to nodes and edges called “custom_id” (see module variable ID_NAME) containing the string of the node’s id, or the edge’s key’s id, repectively.

Parameters:nxGraph (networkx.classes.MultiGraph) – A NetworkX graph object.
FEV_KEGG.Drawing.Export.addLabelAttribute(nxGraph: networkx.classes.multigraph.MultiGraph)[source]

Adds the “custom_label” attribute to each node and edge.

Add an attribute to nodes and edges called “custom_label” (see module variable LABEL_NAME) containing the string of the node’s label, or the edge’s key’s label, repectively. A label is defined as either the .name field, or if that is None, the id. This is especially useful if the tool you import this file into does not regularly read the XML’s id parameter. For example, Cytoscape does not for edges.

Parameters:nxGraph (networkx.classes.MultiGraph) – A NetworkX graph object.
FEV_KEGG.Drawing.Export.addMajorityAttribute(graph: FEV_KEGG.Graph.Models.CommonGraphApi, totalNumberOfOrganisms: int)[source]

Adds the “custom_majority” attribute to each node and edge.

Add an attribute to nodes and edges called “custom_majority” (see module variable MAJORITY_NAME). It contains each node’s or edge’s majority percentage, if the graph contains counts (graph.nodeCounts or graph.edgeCounts, see FEV_KEGG.Graph.Models.CommonGraphApi). For example, say edge A were to occur in 52 of all organisms used to create the graph, then `graph.edgeCounts[A] == 52`. Now we have also `totalNumberOfOrganisms == 76`. Then, we will write `ceil(52/76*100) = 68` into the “custom_majority” attribute.

Parameters:
  • graph (Models.CommonGraphApi) – A graph object.
  • totalNumberOfOrganisms (int) – Total number of organisms which were involved in creating the graph. This is used to calculate the percentage of counts. 100% == totalNumberOfOrganisms.
FEV_KEGG.Drawing.Export.addReactionAttribute(nxGraph: networkx.classes.multigraph.MultiGraph)[source]

Adds the “custom_reaction” attribute to each edge.

Add an attribute to edges called “custom_reaction” (see module variable REACTION_NAME) containing the edge’s .reaction field, if there is any.

Parameters:nxGraph (networkx.classes.MultiGraph) – A NetworkX graph object.
FEV_KEGG.Drawing.Export.addUrlAttribute(nxGraph: networkx.classes.multigraph.MultiGraph)[source]

Adds the “URL” attribute to each edge.

Add an attribute to edges called “URL” (see module variable URL_NAME) containing the edge’s or node’s URL to KEGG.

Parameters:nxGraph (networkx.classes.MultiGraph) – A NetworkX graph object.
FEV_KEGG.Drawing.Export.forCytoscape(graph: FEV_KEGG.Graph.Models.CommonGraphApi, file, inCacheFolder=False, addDescriptions=True, totalNumberOfOrganisms: int = None)[source]

Export graph to file in GraphML format, including some tweaks for Cytoscape.

Parameters:
  • graph (Models.CommonGraphApi) – The graph to be exported.
  • file (str) – Path and name of the exported file. See inCacheFolder.
  • inCacheFolder (bool, optional) – If True, interpret file relative to the cache folder. See FEV_KEGG.settings.cachePath. If False, interpret file relative to the current working directory.
  • addDescriptions (bool, optional) – If True, downloads additional descriptions for substance
  • totalNumberOfOrganisms (int, optional) – Total number of organisms which were involved in creating the graph. This is used to calculate the percentage of counts. 100% == totalNumberOfOrganisms. If None, no majority attribute is added. Only relevant if graph has counts, which it usually does not. See addMajorityAttribute() for more info.
Raises:

NotImplementedError – If graph is not of a NetworkX type.

Warning

Adding extra descriptions, when addDescriptions == True (default!) is a lengthy process and can take some minutes.

FEV_KEGG.Drawing.Export.toGML(graph: FEV_KEGG.Graph.Models.CommonGraphApi, file, inCacheFolder=False)[source]

Export graph to file in GML format.

Each of the graph element’s attributes is translated into a column.

Parameters:
  • graph (Models.CommonGraphApi) – The graph to be exported.
  • file (str) – Path and name of the exported file. See inCacheFolder.
  • inCacheFolder (bool, optional) – If True, interpret file relative to the cache folder. See FEV_KEGG.settings.cachePath. If False, interpret file relative to the current working directory.
Raises:

NotImplementedError – If graph is not of a NetworkX type.

FEV_KEGG.Drawing.Export.toGraphML(graph: FEV_KEGG.Graph.Models.CommonGraphApi, file, inCacheFolder=False)[source]

Export graph to file in GraphML format.

Each of the graph element’s attributes is translated into a column.

Parameters:
  • graph (Models.CommonGraphApi) – The graph to be exported.
  • file (str) – Path and name of the exported file. See inCacheFolder.
  • inCacheFolder (bool, optional) – If True, interpret file relative to the cache folder. See FEV_KEGG.settings.cachePath. If False, interpret file relative to the current working directory.
Raises:

NotImplementedError – If graph is not of a NetworkX type.