FEV_KEGG.Graph.SubstanceGraphs module

class FEV_KEGG.Graph.SubstanceGraphs.Conversion[source]

Bases: object

static KeggPathway2SubstanceReactionGraph(pathway: FEV_KEGG.lib.Biopython.KEGG.KGML.KGML_pathway.Pathway, localVerbosity=1) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceReactionGraph[source]

Converts an organism’s pathway into a SubstanceReactionGraph.

Parameters:
Returns:

The substance-reaction graph calculated from pathway.

Return type:

SubstanceReactionGraph

classmethod KeggPathwaySet2SubstanceReactionGraph(pathways: Set[FEV_KEGG.lib.Biopython.KEGG.KGML.KGML_pathway.Pathway], localVerbosity=1, name=None) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceReactionGraph[source]

Combine several pathways of an organism into one SubstanceReactionGraph.

Deduplicates nodes and edges.

Parameters:
  • pathways (Set[KGML_pathway.Pathway]) –
  • localVerbosity (int, optional) – Verbosity to be used locally. Useful to silence useless log messages. See FEV_KEGG.settings.verbosity.
  • name (str, optional) – Name to use for the new graph.
Returns:

The substance-reaction graph calculated from pathways.

Return type:

SubstanceReactionGraph

static SubstanceEnzymeGraph2SubstanceEcGraph(substanceEnzymeGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceEnzymeGraph) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceEcGraph[source]

Convert a SubstanceEnzymeGraph into a SubstanceEcGraph.

Parameters:substanceEnzymeGraph (SubstanceEnzymeGraph) –
Returns:The substance-EC graph calculated from the substance-enzyme graph.
Return type:SubstanceEcGraph
static SubstanceGeneGraph2SubstanceEcGraph(substanceGeneGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph, noMultifunctional=True) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceEcGraph[source]

Convert a SubstanceGeneGraph into a SubstanceEcGraph.

Parameters:
  • substanceGeneGraph (SubstanceGeneGraph) –
  • noMultifunctional (bool, optional) – If True, does not return enzymes associated with more than one EC number.
Returns:

The substance-EC graph calculated from the substance-gene graph.

Return type:

SubstanceEcGraph

Warning

Skips the substance-enzyme step. Still parses genes from Database, this is slow and expensive!

static SubstanceGeneGraph2SubstanceEnzymeGraph(substanceGeneGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph, noMultifunctional=True) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceEnzymeGraph[source]

Convert a SubstanceGeneGraph into a SubstanceEnzymeGraph.

Each unique gene ID is mapped to the same unique enzyme, because enzymes are unique by their gene ID.

Parameters:
  • substanceGeneGraph (SubstanceGeneGraph) –
  • noMultifunctional (bool, optional) – If True, does not return enzymes associated with more than one EC number.
Returns:

The substance-enzyme graph calculated from the substance-gene graph.

Return type:

SubstanceEnzymeGraph

Warning

Parses genes from Database, this is slow and expensive!

static SubstanceReactionGraph2SubstanceGeneGraph(substanceReactionGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceReactionGraph) → FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph[source]

Convert a SubstanceReactionGraph into a SubstanceGeneGraph.

Uses pathway information embedded into the substanceReactionGraph.

Parameters:substanceReactionGraph (SubstanceReactionGraph) –
Returns:The substance-gene graph calculated from the substance-reaction graph.
Return type:SubstanceGeneGraph
class FEV_KEGG.Graph.SubstanceGraphs.SubstanceEcGraph(underlyingRawGraph: implementationGraph = None)[source]

Bases: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGraph

Directed graph with SubstanceID nodes and EcNumber edges, allowing multiple edges.

Links two FEV_KEGG.Graph.Elements.SubstanceID (compound or glycan) nodes with each FEV_KEGG.Graph.Elements.EcNumber edge, associated with an FEV_KEGG.Graph.Elements.Enzyme, associated with a FEV_KEGG.Graph.Elements.GeneID, associated with a FEV_KEGG.Graph.Elements.ReactionID they occur in.

Variables:
  • self.underlyingRawGraph (FEV_KEGG.Graph.Implementations) – The actual graph containing the data. This is dependant on the implementation.
  • self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
  • self.substanceCounts (Dict[SubstanceID, int], optional) – Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.
  • self.ecCounts (Dict[Elements.EcNumber, int], optional) – Number of precursor graphs which contained certain EcNumber edge keys still in this graph. None by default.
addEC(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, ecNumber: FEV_KEGG.Graph.Elements.EcNumber, isReversible: bool = False)[source]

Add an ecNumber between the substances substrate and product.

Parameters:
  • substrate (SubstanceID) – Automatically added, if not already in the graph.
  • product (SubstanceID) – Automatically added, if not already in the graph.
  • ecNumber (EcNumber) –
  • isReversible (bool, optional) – If True, add in both directions, swapping substrate and product.
addEcDescriptions()[source]

Downloads and adds descriptions to .description, .name, and .reaction fields of each EC edge key.

Warning

This causes many downloads and is very slow when nothing has been downloaded to cache yet!

See also

FEV_KEGG.KEGG.DataTypes.EcEnzyme()
The data type occuring in KEGG used to download the info.
ecCounts

Number of precursor graphs which contained certain GeneID edge keys still in this graph. None by default.

static fromSubstanceEnzymeGraph(substanceEnzymeGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceEnzymeGraph)[source]

Create SubstanceEcGraph from a SubstanceEnzymeGraph.

Replaces Enzymes with their EcNumber. Splits Enzymes with several EC numbers. Deduplicates Enzymes with the same EC number. See the structure of a KEGG KGML pathway description file for further insight.

Parameters:substanceEnzymeGraph (SubstanceEnzymeGraph) – The substance-enzyme graph to use for creating this graph.
Returns:A new substance-EC graph.
Return type:SubstanceEcGraph
static fromSubstanceGeneGraph(substanceGeneGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph)[source]

Create SubstanceEcGraph from a SubstanceGeneGraph.

Replaces GeneIDs with their EcNumber. Splits GeneIDs with several EC numbers. Deduplicates GeneIDs with the same EC number. See the structure of a KEGG KGML pathway description file for further insight.

Parameters:substanceGeneGraph (SubstanceGeneGraph) – The substance-gene graph to use for creating this graph.
Returns:A new substance-EC graph.
Return type:SubstanceEcGraph
getECs() → Set[FEV_KEGG.Graph.Elements.EcNumber][source]

Get all EC numbers.

Returns:Set of all EC numbers in this graph.
Return type:Set[EcNumber]
getPartialEcNumberEdges() → List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.EcNumber]][source]

Get all edges annotated with a partial EC number, i.e. containing a wildcard ‘-‘.

Returns:List of all edge tuples where its EC number is partial, i.e. has less than the full four EC levels, e.g. ‘4.1.2.-’. Even though the type list does not enforce it, this should never return duplicates.
Return type:List[Tuple[SubstanceID, SubstanceID, EcNumber]]
getPartialEcNumbers() → Set[FEV_KEGG.Graph.Elements.EcNumber][source]

Get all partial EC numbers, i.e. containing a wildcard ‘-‘.

Returns:All EC numbers in this graph with less than the full four EC levels, e.g. ‘4.1.2.-‘.
Return type:Set[EcNumber]
getUnidirectionalEcNumbers() → Set[FEV_KEGG.Graph.Elements.EcNumber][source]

Get all EC numbers which have only one direction.

Returns:Set of EC numbers which take part in an edge with only one direction. Meaning there is no edge with the opposite direction between the same substances, annotated with the same gene.
Return type:Set[EcNumber]
removeAllECsExcept(ecToKeep: Iterable[FEV_KEGG.Graph.Elements.EcNumber])[source]

Remove all genes which are not in ecToKeep.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:ecToKeep (Iterable[EcNumber]) – Iterable of EC numbers to keep in the graph. All other genes are removed.
removeECs(ecNumbers: Iterable[FEV_KEGG.Graph.Elements.EcNumber])[source]

Remove all occurences of certain EC numbers.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:ecNumbers (Iterable[EcNumber]) – Iterable of EC numbers to be completely removed from the graph.
removeEcEdge(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, ecNumber: FEV_KEGG.Graph.Elements.EcNumber, bothDirections: bool = False)[source]

Remove a ecNumber between substrate and product.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:
  • substrate (SubstanceID) – Not removed from the graph.
  • product (SubstanceID) – Not removed from the graph.
  • ecNumber (EcNumber) –
  • bothDirections (bool, optional) – If True, remove both directions, swapping substrate and product.
removeEcEdges(ecEdges: List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.EcNumber]])[source]

Remove all EC numbers in certain edges.

Parameters:ecEdges (List[Tuple[SubstanceID, SubstanceID, EcNumber]]) – List of tuples, each describing an edge to be removed from the graph. If an edge to be removed does not exist, the next edge will be tried, without any error message.
removePartialEcNumbers()[source]

Remove edges annotated with a partial EC number, i.e. containing a wildcard ‘-‘.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

substanceCounts

Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.

class FEV_KEGG.Graph.SubstanceGraphs.SubstanceEnzymeGraph(underlyingRawGraph: implementationGraph = None)[source]

Bases: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGraph

Directed graph with SubstanceID nodes and Enzyme edges, allowing multiple edges.

Links two FEV_KEGG.Graph.Elements.SubstanceID (compound or glycan) nodes with each FEV_KEGG.Graph.Elements.Enzyme edge, associated with a FEV_KEGG.Graph.Elements.GeneID, associated with a FEV_KEGG.Graph.Elements.ReactionID they occur in. Replaces each GeneID object with its associated Enzyme object.

Variables:
  • self.underlyingRawGraph (FEV_KEGG.Graph.Implementations) – The actual graph containing the data. This is dependant on the implementation.
  • self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
  • self.substanceCounts (Dict[SubstanceID, int], optional) – Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.
  • self.enzymeCounts (Dict[Elements.Enzyme, int], optional) – Number of precursor graphs which contained certain Enzyme edge keys still in this graph. None by default.
  • self.indexOnEC (Dict[EcNumber, Set[Enzyme]]) – Index to find all enzymes by a certain EC number.
  • self.indexOnGeneID (Dict[GeneID, Enzyme]) – Index to find an enzyme by its gene ID. An enzyme is uniquely identified by its gene ID.

Warning

Automatically parses genes from KEGG, this is slow and expensive!

addEdge(node1: FEV_KEGG.Graph.Elements.Element, node2: FEV_KEGG.Graph.Elements.Element, key: FEV_KEGG.Graph.Elements.Element, isReversible: bool = False)[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

addEdges(edges: List[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]])[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

addEnzyme(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, enzyme: FEV_KEGG.Graph.Elements.Enzyme, isReversible: bool = False)[source]

Add an enzyme between the substances substrate and product.

Automatically updates indices.

Parameters:
  • substrate (SubstanceID) – Automatically added, if not already in the graph.
  • product (SubstanceID) – Automatically added, if not already in the graph.
  • enzyme (Enzyme) –
  • isReversible (bool, optional) – If True, add in both directions, swapping substrate and product.
copy(underlyingRawGraph=None)[source]

Shallow copy of the whole graph.

However, some attributes are explicitly copied (although each attribute might in itself be shallowly copied):

  • .underlyingRawGraph
  • .name
  • .nodeCounts
  • .edgeCounts
  • .edgeElementCounts
  • .indexOnEC
  • .indexOnGeneID
Parameters:underlyingRawGraph (FEV_KEGG.Graph.Implementations, optional) – If given, does not copy the underlying raw graph, but uses this one.
Returns:Shallow copy of the whole graph.
Return type:SubstanceReactionGraph
enzymeCounts

Number of precursor graphs which contained certain Enzyme edge keys still in this graph. None by default.

static fromSubstanceGeneGraph(substanceGeneGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph)[source]

Create SubstanceEnzymeGraph from a SubstanceGeneGraph.

Replaces reactions with their associated genes. Splits reactions associated with several genes. Deduplicates reactions associated with the same gene. See the structure of a KEGG KGML pathway description file for further insight.

Parameters:substanceGeneGraph (SubstanceGeneGraph) – The substance-gene graph to use for creating this graph. Apart from the graph structure itself, downloads from KEGG GENE are needed!
Returns:A new substance-enzyme graph.
Return type:SubstanceEnzymeGraph

Warning

Automatically parses genes from KEGG, this is slow and expensive!

getEnzymeForGeneID(geneID: FEV_KEGG.Graph.Elements.GeneID) → FEV_KEGG.Graph.Elements.Enzyme[source]

Get the enzyme uniquely identified with geneID.

Parameters:geneID (GeneID) – The gene encoding the enzyme.
Returns:The enzyme in this graph identified by the given geneID. If there is no such geneID, returns None.
Return type:Enzyme
getEnzymes() → Set[FEV_KEGG.Graph.Elements.Enzyme][source]

Get all enzymes.

Returns:Set of all enzymes in this graph.
Return type:Set[Enzyme]
getEnzymesForEcNumber(ecNumber: FEV_KEGG.Graph.Elements.EcNumber) → Set[FEV_KEGG.Graph.Elements.Enzyme][source]

Get enzymes associated with a certain EC number.

Parameters:ecNumber (EcNumber) –
Returns:Set of enzymes associated with the EC number in the ecNumber parameter. If there is no such EC number, returns an empty set.
Return type:Set[Enzyme]
getGeneIDsForEcNumber(ecNumber: FEV_KEGG.Graph.Elements.EcNumber) → Set[FEV_KEGG.Graph.Elements.GeneID][source]

Get genes associated with a certain EC number.

Parameters:ecNumber (EcNumber) –
Returns:Set of genes associated with the EC number in the ecNumber parameter. If there is no such EC number, returns an empty set.
Return type:Set[GeneID]
getMultifunctionalEnzymeEdges() → List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.Enzyme]][source]

Get all edges annotated with an enzyme associated with more than one EC number.

Returns:List of all edge tuples where its enzyme is associated with more than one EC number.
Return type:List[Tuple[SubstanceID, SubstanceID, Enzyme]]
getMultifunctionalEnzymes() → Set[FEV_KEGG.Graph.Elements.Enzyme][source]

Get all enzymes which are associated with more than one EC number.

Returns:Set of enzymes associated with more than one EC number.
Return type:Set[Enzyme]
getUnidirectionalEnzymes() → Set[FEV_KEGG.Graph.Elements.Enzyme][source]

Get all enzymes which have only one direction.

Returns:Set of enzymes which take part in an edge with only one direction. Meaning there is no edge with the opposite direction between the same substances, annotated with the same enzyme.
Return type:Set[Enzyme]
keepEnzymesByEC(ecNumbers: Iterable[FEV_KEGG.Graph.Elements.EcNumber])[source]

Remove all enzymes from the graph, except the ones associated with the passed EC numbers.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:ecNumbers (Iterable[EcNumber]) –
removeAllEnzymesExcept(enzymesToKeep: Iterable[FEV_KEGG.Graph.Elements.Enzyme])[source]

Remove all enzymes which are not in enzymesToKeep.

Automatically updates indices. You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:enzymesToKeep (Iterable[Enzyme]) – Iterable of enzymes to keep in the graph. All other enzymes are removed.
removeEdge(node1: FEV_KEGG.Graph.Elements.Element, node2: FEV_KEGG.Graph.Elements.Element, key: FEV_KEGG.Graph.Elements.Element, bothDirections: bool = False)[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

removeEdges(edges: List[Tuple])[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

removeEdgesByElements(elements: Iterable[FEV_KEGG.Graph.Elements.Element])[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

removeEnzymeEdge(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, enzyme: FEV_KEGG.Graph.Elements.Enzyme, bothDirections: bool = False)[source]

Remove an enzyme between substrate and product.

Automatically updates indices. You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:
  • substrate (SubstanceID) – Not removed from the graph.
  • product (SubstanceID) – Not removed from the graph.
  • enzyme (Enzyme) –
  • bothDirections (bool, optional) – If True, remove both directions, swapping substrate and product.
removeEnzymeEdges(enzymeEdges: List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.Enzyme]])[source]

Remove all enzymes in certain edges.

Automatically updates indices.

Parameters:enzymeEdges (List[Tuple[SubstanceID, SubstanceID, Enzyme]]) – List of tuples, each describing an edge to be removed from the graph. If an edge to be removed does not exist, the next edge will be tried, without any error message.
removeEnzymes(enzymes: Iterable[FEV_KEGG.Graph.Elements.Enzyme])[source]

Remove all occurences of certain enzymes.

Automatically updates indices. You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:enzymes (Iterable[Enzyme]) – Iterable of enzymes to be completely removed from the graph.
removeEnzymesByEC(ecNumbers: Iterable[FEV_KEGG.Graph.Elements.EcNumber], keepInstead=False)[source]

Remove all enzymes associated with the passed EC numbers.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:
  • ecNumbers (Iterable[EcNumber]) –
  • keepInstead (bool, optional) – If True, remove all enzymes except the ones associated with the passed EC numbers.
removeMultifunctionalEnzymes()[source]

Remove enzymes associated with more than one EC number.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

replaceEdgeElement(edge: Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element], newElement: FEV_KEGG.Graph.Elements.Element, bothDirections: bool = False)[source]

Automatically updates the indices. See FEV_KEGG.Graph.Models.DirectedMultiGraph for the original function.

substanceCounts

Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.

class FEV_KEGG.Graph.SubstanceGraphs.SubstanceGeneGraph(underlyingRawGraph: implementationGraph = None)[source]

Bases: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGraph

Directed graph with SubstanceID nodes and GeneID edges, allowing multiple edges.

Links two FEV_KEGG.Graph.Elements.SubstanceID (compound or glycan) nodes with each FEV_KEGG.Graph.Elements.GeneID edge, associated with a FEV_KEGG.Graph.Elements.ReactionID they occur in.

Variables:
  • self.underlyingRawGraph (FEV_KEGG.Graph.Implementations) – The actual graph containing the data. This is dependant on the implementation.
  • self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
  • self.substanceCounts (Dict[SubstanceID, int], optional) – Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.
  • self.geneCounts (Dict[Elements.GeneID, int], optional) – Number of precursor graphs which contained certain GeneID edge keys still in this graph. None by default.
addGene(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, geneID: FEV_KEGG.Graph.Elements.GeneID, isReversible: bool = False)[source]

Add an geneID between the substances substrate and product.

Parameters:
  • substrate (SubstanceID) – Automatically added, if not already in the graph.
  • product (SubstanceID) – Automatically added, if not already in the graph.
  • geneID (GeneID) –
  • isReversible (bool, optional) – If True, add in both directions, swapping substrate and product.
static fromSubstanceReactionGraph(substanceReactionGraph: FEV_KEGG.Graph.SubstanceGraphs.SubstanceReactionGraph)[source]

Create SubstanceGeneGraph from a SubstanceReactionGraph.

Replaces reactions with their associated genes. Splits reactions associated with several genes. Deduplicates reactions associated with the same gene. See the structure of a KEGG KGML pathway description file for further insight.

Parameters:substanceReactionGraph (SubstanceReactionGraph) – The substance-reaction graph to use for creating this graph. Apart from the graph structure itself, its attribute SubstanceReactionGraph.pathwaySet is needed!
Returns:A new substance-gene graph.
Return type:SubstanceGeneGraph
geneCounts

Number of precursor graphs which contained certain GeneID edge keys still in this graph. None by default.

getGenes() → Set[FEV_KEGG.Graph.Elements.GeneID][source]

Get all genes.

Returns:Set of all genes in this graph.
Return type:Set[GeneID]
getMultifunctionalGeneEdges() → List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.GeneID]][source]

Get all edges annotated with a gene associated with more than one EC number.

Returns:List of all edge tuples where its gene, represented by a GeneID, is associated with more than one EC number.
Return type:List[Tuple[SubstanceID, SubstanceID, GeneID]]

Warning

Parses Database, this is slow and expensive!

getMultifunctionalGenes() → Set[FEV_KEGG.Graph.Elements.GeneID][source]

Get all genes which are associated with more than one EC number.

Returns:Set of genes associated with more than one EC number.
Return type:Set[GeneID]

Warning

Parses Database, this is slow and expensive!

getUnidirectionalGenes() → Set[FEV_KEGG.Graph.Elements.GeneID][source]

Get all genes which have only one direction.

Returns:Set of genes which take part in an edge with only one direction. Meaning there is no edge with the opposite direction between the same substances, annotated with the same gene.
Return type:Set[GeneID]
removeAllGenesExcept(genesToKeep: Iterable[FEV_KEGG.Graph.Elements.GeneID])[source]

Remove all genes which are not in genesToKeep.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:genesToKeep (Iterable[GeneID]) – Iterable of genes to keep in the graph. All other genes are removed.
removeGeneEdge(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, gene: FEV_KEGG.Graph.Elements.GeneID, bothDirections: bool = False)[source]

Remove a gene between substrate and product.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:
  • substrate (SubstanceID) – Not removed from the graph.
  • product (SubstanceID) – Not removed from the graph.
  • gene (GeneID) –
  • bothDirections (bool, optional) – If True, remove both directions, swapping substrate and product.
removeGeneEdges(geneEdges: List[Tuple[FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.SubstanceID, FEV_KEGG.Graph.Elements.GeneID]])[source]

Remove all genes in certain edges.

Parameters:geneEdges (List[Tuple[SubstanceID, SubstanceID, GeneID]]) – List of tuples, each describing an edge to be removed from the graph. If an edge to be removed does not exist, the next edge will be tried, without any error message.
removeGenes(geneIDs: Iterable[FEV_KEGG.Graph.Elements.GeneID])[source]

Remove all occurences of certain genes.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Parameters:geneIDs (Iterable[GeneID]) – Iterable of genes to be completely removed from the graph.
removeMultifunctionalGenes()[source]

Remove genes associated with more than one EC number.

You may want to removeIsolatedNodes() afterwards, to remove nodes that now have no edge.

Warning

Parses Database, this is slow and expensive!

substanceCounts

Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.

class FEV_KEGG.Graph.SubstanceGraphs.SubstanceGraph(underlyingRawGraph=None)[source]

Bases: FEV_KEGG.Graph.Models.DirectedMultiGraph

Directed graph with SubstanceID nodes.

Parameters:underlyingRawGraph (FEV_KEGG.Graph.Implementations) – If not None, copies underlyingRawGraph and stores it for this object.
Variables:self.underlyingRawGraph (FEV_KEGG.Graph.Implementations) – The actual graph containing the data. This is dependant on the implementation.
addSubstanceDescriptions()[source]

Downloads and adds description to .description and .name field of each substance node.

Warning

This causes many downloads and is very slow when nothing has been downloaded to cache yet!

See also

FEV_KEGG.KEGG.DataTypes.Substance()
The data type occuring in KEGG used to download the info.
class FEV_KEGG.Graph.SubstanceGraphs.SubstanceReactionGraph(underlyingRawGraph=None, pathwaySet=None)[source]

Bases: FEV_KEGG.Graph.SubstanceGraphs.SubstanceGraph

Directed graph with SubstanceID nodes and ReactionID edges, allowing multiple edges.

Links two FEV_KEGG.Graph.Elements.SubstanceID (compound or glycan) nodes with each FEV_KEGG.Graph.Elements.ReactionID edge they occur in. Substances have to occur on different sides of the reaction, one being a substrate, the other being a product. Reversible reactions will get two edges with swapped roles of substrate/product. There may be other substrates/products in the same reaction, they will be linked with another edge.

For example A1 + A2 -> B1 + B2 will yield four edges: (A1, B1); (A1, B2); (A2, B1); (A2, B2). Making this reaction reversible would yield eight edges, because each tuple will be swapped to form the other direction.

Parameters:
Variables:
  • self.underlyingRawGraph (FEV_KEGG.Graph.Implementations) – The actual graph containing the data. This is dependant on the implementation.
  • self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
  • self.pathwaySet (Set[KGML_pathway.Pathway]) – Set of pathways this graph was derived from. Especially useful for e.g. Conversion.SubstanceReactionGraph2SubstanceGeneGraph().
  • self.substanceCounts (Dict[SubstanceID, int], optional) – Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.
  • self.reactionCounts (Dict[Elements.ReactionID, int], optional) – Number of precursor graphs which contained certain ReactionID edge keys still in this graph. None by default.
addReaction(substrate: FEV_KEGG.Graph.Elements.SubstanceID, product: FEV_KEGG.Graph.Elements.SubstanceID, reaction: FEV_KEGG.Graph.Elements.ReactionID, isReversible: bool = False)[source]

Add a reaction edge between substrate and product.

Parameters:
  • substrate (SubstanceID) – Substance from which the reaction edge starts. Automatically added, if not already in the graph.
  • product (SubstanceID) – Substance where the reaction edge ends. Automatically added, if not already in the graph.
  • reaction (Elements.ReactionID) – Reaction with which the new edge is to be annotated, as its edge key.
  • isReversible (bool, optional) – If True, add reaction in both directions.
copy(underlyingRawGraph=None)[source]

Shallow copy of the whole graph.

However, some attributes are explicitly copied (although each attribute might in itself be shallowly copied):

  • .underlyingRawGraph
  • .name
  • .nodeCounts
  • .edgeCounts
  • .edgeElementCounts
  • .pathwaySet
Parameters:underlyingRawGraph (FEV_KEGG.Graph.Implementations, optional) – If given, does not copy the underlying raw graph, but uses this one.
Returns:Shallow copy of the whole graph.
Return type:SubstanceReactionGraph
static fromPathway(pathway: Set[FEV_KEGG.lib.Biopython.KEGG.KGML.KGML_pathway.Pathway])[source]

Create SubstanceReactionGraph from certain pathways.

Parameters:pathway (Set[KGML_pathway.Pathway] or KGML_pathway.Pathway) – Pathway(s) to use for creating the graph.
Returns:A new substance-reaction graph.
Return type:SubstanceReactionGraph
getReactions() → Set[FEV_KEGG.Graph.Elements.ReactionID][source]

Get all reactions.

Returns:Set of all reaction edge keys in this graph.
Return type:Set[Elements.ReactionID]
getUnidirectionalReactions() → Set[FEV_KEGG.Graph.Elements.ReactionID][source]

Get the reactions of all edges which are unidirectional only.

Returns:Set of all reactions which are edge keys of edges that have only one direction, i.e. there is no other edge in reverse direction with the same reaction edge key.
Return type:Set[Elements.ReactionID]
reactionCounts

Number of precursor graphs which contained certain ReactionID edge keys still in this graph. None by default.

substanceCounts

Number of precursor graphs which contained certain SubstanceID nodes still in this graph. None by default.