FEV_KEGG.Graph.Models module¶
-
class
FEV_KEGG.Graph.Models.CommonGraphApi(underlyingRawGraph=None)[source]¶ Bases:
objectRepresents any type of graph.
The library to implement graphs is chosen here.
Parameters: underlyingRawGraph (
implementationLib, optional) – 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 chosen inimplementationLib. - self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
- self.nodeCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementnodes still in this graph. None by default. - self.edgeCounts (Dict[Tuple[Element, Element, Element], int], optional) – Number of precursor graphs which contained a certain edge (a Tuple of three
Element) still in this graph. None by default. - self.edgeElementCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementedge keys still in this graph. None by default.
-
__eq__(other: object)[source]¶ Determine equality of two graphs.
Parameters: other (object) – The object to compare this graph with. Returns: Both graphs are considered equal, if they have identical memory addresses OR (the same class AND the same number of nodes and edges AND they are ismorphic). WARNING: isomorphism check is NP-hard! Return type: bool Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
__ne__(other: object)[source]¶ Determine non-equality of two graphs.
This simply negates
__eq__().Parameters: other (object) – The object to compare this graph with. Returns: Both graphs are considered inequal, if they do not have identical memory addresses NOR (the same class AND the same number of nodes and edges AND they are ismorphic). WARNING: isomorphism check is NP-hard! Return type: bool Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
addEdge(node1: FEV_KEGG.Graph.Elements.Element, node2: FEV_KEGG.Graph.Elements.Element, key: FEV_KEGG.Graph.Elements.Element, isReversible: bool = False)[source]¶ Add an edge to the graph.
Parameters: - node1 (Element) – Node from which the newly created edge starts. Is added to the graph, if not already present.
- node2 (Element) – Node at which the newly created edge ends. Is added to the graph, if not already present.
- key (Element) – Edge key element annotating the newly created edge.
- isReversible (bool, optional) – If True, both directions are added, swapping node1 and node2. If the graph is undirected, this option is ignored.
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
addEdges(edges: Iterable[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]])[source]¶ Add edges to the graph.
Parameters: edges (Iterable[Tuple[Element, Element, Element]]) – Iterable of edge tuples, defined as (node1, node2, edge key). If the nodes do not already exist, they are silently added. If the graph is directed, the order of node1 and node2 counts as direction. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
addNode(node: FEV_KEGG.Graph.Elements.Element)[source]¶ Add a node to the graph.
Parameters: node (Element) – Node to add to the graph, if not already present. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
addNodes(nodes: Iterable[FEV_KEGG.Graph.Elements.Element])[source]¶ Add nodes to the graph.
Parameters: nodes (Iterable[Element]) – Iterable of elements to be added as nodes. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
classmethod
composeAll(graphs: Iterable[CommonGraphApi], name: str = None, pathwaySet=None) → FEV_KEGG.Graph.Models.CommonGraphApi[source]¶ Simple UNION of node and edge lists.
A node is defined by its hash(). An edge is defined by Tuple[node1, node2, hash(edge key)], while the order of node1 and node2 encodes the direction, if the graph is directed. This is similar to
union(), but aims at a special use case. You will most likely want to useunion().Parameters: - graphs (Iterable[CommonGraphApi]) – Iterable of graphs to be composed.
- name (str, optional) – Name of the new graph.
- pathwaySet (Set[KGML_pathway.Pathway], optional) – Set of pathways this graph was derived from. Especially useful for e.g.
FEV_KEGG.Graph.SubstanceGraphs.Conversion.SubstanceReactionGraph2SubstanceGeneGraph().
Returns: Composition of all graphs by simple union operation. Includes pathwaySet, if given.
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
copy(underlyingRawGraph=None) → FEV_KEGG.Graph.Models.CommonGraphApi[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
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: CommonGraphApi
-
difference(subtrahend: Graph to be subtracted, subtractNodes=False, updateName=False) → CommonGraphApi[source]¶ Difference between this graph and subtrahend graph, i.e.
self - subtrahend.You may want to
removeIsolatedNodes()afterwards, to remove nodes that now have no edge.Parameters: - subtrahend (CommonGraphApi) – The graph to be subtracted.
- subtractNodes (bool, optional) – If True, also remove all nodes present in subtrahend from this graph. WARNING: This may remove edges that only exist in this graph, because they are removed with their associated node!
- updateName (bool, optional) – If True, update this graph’s name.
Returns: A copy of this graph, containing all nodes which are present in this graph and all edges present in this graph, but which are not present in subtrahend.
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getComponents() → Generator[Set[T], None, None][source]¶ Get all isolated components.
For a directed graph, this considers weakly connected components, too. This means that there do not have to be edges in both directions to be counted as a component. Even an edge in only one direction counts as connecting a component.
Returns: Generator of any isolated component of the graph. Each represented by a set of their nodes, each represented by an Element. Return type: Generator[Set[Element]] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getEdgeKeys() → Set[FEV_KEGG.Graph.Elements.Element][source]¶ Get edge key elements of all edges.
Returns: Set of all edge’s key elements, extracted from edge tuples of (node1, node2, edge key). Element objects which are the edge key of multiple edges are only returned once in the set. Return type: Set[Element] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getEdges(fromNode: FEV_KEGG.Graph.Elements.Element = None, toNode: FEV_KEGG.Graph.Elements.Element = None) → Set[Tuple][source]¶ Get all edges, optionally directly between two nodes.
Parameters: Returns: A set-like object of all edges, defined by Tuples of (node1, node2, edge key). This is not a copy, but the original internal list. Do not change while iterating! Make a copy instead: copy = list(getEdges()) Only returns outgoing edges, so that no edge is reported twice. If fromNode and toNode are specified, returns only edges directly between these nodes. If there are none, returns an empty set. Does not report whole paths, only single edges!
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getEdgesForKey() → Dict[FEV_KEGG.Graph.Elements.Element, List[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]]][source]¶ Get all edges, sorted by their key element.
Returns: A dict of all key elements pointing to a list of their edge tuples. Return type: Dict[Element, List[Tuple[Element, Element, Element]]] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getEdgesFromKey(key: FEV_KEGG.Graph.Elements.Element) → List[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]][source]¶ Get all edges with a certain key element.
Parameters: key (Element) – The key element of the edges to be returned. Returns: A set of all edges, defined by Tuples of (node1, node2, edge key), where edge key == key. This is a copy of the original internal list. Only returns outgoing edges, so that no edge is reported twice. Return type: Set[Tuple[Element, Element, Element]] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getIsolatedNodes() → Iterable[FEV_KEGG.Graph.Elements.Element][source]¶ Get all nodes without any edge to another node.
Returns: Iterable of nodes without any edge to another node. Even though the type does not enforce it, this should never return duplicates. Return type: Iterable[Element] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getLargestComponent() → FEV_KEGG.Graph.Models.CommonGraphApi[source]¶ Get the largest component.
Returns: Copy of this graph, reduced to the largest component. Return type: CommonGraphApi Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getLargestComponentNodes() → Set[FEV_KEGG.Graph.Elements.Element][source]¶ Get nodes of the largest component.
Returns: Set of all nodes, represented by an Element, of the largest component. Return type: Set[Element] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getNodes() → Set[FEV_KEGG.Graph.Elements.Element][source]¶ Get all nodes.
Returns: A set-like object of all nodes. Even though the type list does not enforce it, this should never return duplicates. Return type: Set[Element] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
getPaths(fromNode: FEV_KEGG.Graph.Elements.Element, toNode: FEV_KEGG.Graph.Elements.Element) → Set[FEV_KEGG.Graph.Models.Path][source]¶ Get all simple paths between two nodes.
Simple paths are loop-free. If one of the two nodes is None, searches for all paths starting/ending in the the one node given.
Parameters: Returns: Set of all paths between fromNode and toNode. If fromNode or toNode does not exist, or there is no path, returns an empty list.
Return type: Set[Path]
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.ValueError– If both fromNode and toNode are given as None.
-
getShortestPaths(fromNode: FEV_KEGG.Graph.Elements.Element, toNode: FEV_KEGG.Graph.Elements.Element) → Set[FEV_KEGG.Graph.Models.Path][source]¶ Get all shortest paths between two nodes.
Parameters: - fromNode (Element) – Where to start searching for shortest paths. If None, searches for all shortest paths ending in toNode, which are obviously all of length 1.
- toNode (Element) – Where to stop searching. If None, searches for all shortest paths starting in fromNode, which are obviously all of length 1.
Returns: Set of all shortest paths between fromNode and toNode. If fromNode or toNode does not exist, or there is no path, returns an empty list.
Return type: Set[Path]
Note
If one of the two nodes is None, determine if there is any path starting/ending in the one node given. If this is the case, the shortest paths are obviously always of length 1.
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.ValueError– If both fromNode and toNode are given as None.
-
getSubgraph(byNodes: Iterable[FEV_KEGG.Graph.Elements.Element] = None, byEdges: Iterable[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]] = None) → FEV_KEGG.Graph.Models.CommonGraphApi[source]¶ Get sub-graph defined by nodes or edges.
If both are passed, only nodes are used. If nothing is passed, None is returned.
Parameters: - byNodes (Iterable[Element], optional) – Iterable of nodes defining the sub-graph. All edges between these nodes are conserved.
- byEdges (Iterable[Tuple[Element, Element, Element]], optional) – Iterable of edges defining the sub-graph, each defined as (node1, node2, edge key). All nodes involved with these edges, i.e. all node1’s and node2’s are preserved.
Returns: Copy of the sub-graph specified by either nodes or edges.
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
implementationLib¶
-
intersection(withGraph: Graph to be intersected with, allows list of graphs, addCount=False, updateName=False) → CommonGraphApi[source]¶ Intersection of this graph and the graph(s) in withGraph.
You may want to
removeIsolatedNodes()afterwards, to remove nodes that now have no edge.Parameters: - withGraph (CommonGraphApi or Iterable[CommonGraphApi]) – The graph(s) this graph is to be intersected with.
- addCount (bool, optional) –
If True, the returned graph contains extra dicts:
- graph.nodeCounts[node] = number of graphs which contained this node
- graph.edgeCounts[(node, node, element)] = number of graphs which contained this edge
- graph.edgeElementCounts[element] = number of graphs which contained this element
- updateName (bool, optional) – If True, update this graph’s name.
Returns: A copy of this graph, containing nodes and edges present in both this graph and the other graph(s).
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
majorityIntersection(withGraph: Graph to be majority-intersected with, allows list of graphs, majorityPercentage=51, addCount=False, updateName=False) → CommonGraphApi[source]¶ Majority-Intersection of this graph and the graph(s) in withGraph.
You may want to
removeIsolatedNodes()afterwards, to remove nodes that now have no edge.Parameters: - withGraph (CommonGraphApi or Iterable[CommonGraphApi]) – The graph(s) this graph is to be intersected with.
- majorityPercentage (float, optional) – The majority percentage means ‘at least x%’ and is rounded up. For example 90% of 11 organisms (including the organism this method is called on) would be ceiling(9,9) = 10 organisms.
If the rounded majority total effectively equated to 100% of all graphs, regular
intersection()is called instead. If only one graph is passed in withGraph AND the rounded majority total effectively equates 1, regularunion()is called instead. - addCount (bool, optional) –
If True, the returned graph contains extra dicts:
- graph.nodeCounts[node] = number of graphs which contained this node
- graph.edgeCounts[(node, node, element)] = number of graphs which contained this edge
- graph.edgeElementCounts[element] = number of graphs which contained this element
- updateName (bool, optional) – If True, update this graph’s name.
Returns: A copy of this graph, containing all nodes and edges present in the majority of this graph and the other graph(s).
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
name¶ Custom name of the graph.
This is often set in calcuations, but not used for any calculations.
Returns: Custom name of the graph. Return type: str
-
removeEdge(node1: FEV_KEGG.Graph.Elements.Element, node2: FEV_KEGG.Graph.Elements.Element, key: FEV_KEGG.Graph.Elements.Element, bothDirections: bool = False)[source]¶ Remove an edge from the graph.
You may want to
removeIsolatedNodes()afterwards, to remove nodes that now have no edge.Parameters: - node1 (Element) – Node from which the edge to be removed starts. Is not removed itself.
- node2 (Element) – Node at which the edge to be removed ends. Is not removed itself.
- key (Element) – Edge key element annotating the edge to be removed.
- bothDirections (bool, optional) – If True, both directions are removed, swapping node1 and node2. If the graph is undirected, this option is ignored.
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
removeEdges(edges: Iterable[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]])[source]¶ Remove certain edges.
Parameters: edges (Iterable[Tuple[Element, Element, Element]]) – Iterable of edge tuples for edges to be removed, defined as (node1, node2, edge key). If an edge to be removed does not exist, the next edge will be tried, without any error message. If the graph is directed, the order of node1 and node2 counts as direction. The edge of opposing direction is not removed. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
removeEdgesByElements(elements: Iterable[FEV_KEGG.Graph.Elements.Element])[source]¶ Removes all edges associated with each of the
Elementin elements.Parameters: elements (Iterable[Element]) – Iterable of edge keys. Every edge keyed with an edge key equal (by __eq__) to any of these elements is removed. Direction of the graph does not affect removal. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
removeIsolatedNodes()[source]¶ Remove all nodes without any edge to another node.
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
removeNodes(nodes: Iterable[FEV_KEGG.Graph.Elements.Element])[source]¶ Remove all nodes.
Parameters: nodes (Iterable[Element]) – Iterable of elements representing nodes to be removed. Any edges involving these nodes are removed as well! Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
removeSmallComponents(upToNumberOfNodes: int)[source]¶ Remove every isolated component of the graph with a total count of nodes <= upToNumberOfNodes.
For a directed graph, this considers weakly connected components, too. This means that there do not have to be edges in both directions to be counted as a component. Even an edge in only one direction counts as connecting a component.
Parameters: upToNumberOfNodes (int) – Maximum number of nodes a component has to connect to be completely removed. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
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]¶ Replaces a certain edge key element, if the edge is present, with another element.
Silently ignores non-existing edge, especially never adds the new edge. Treats both directions independently.
Parameters: - edge (Tuple[Element, Element, Element]) – Tuple representing the edge which key element is to be replaced.
- newElement (Element) – The element to replace the edge’s former key element.
- bothDirections (bool, optional) – If True, automatically replace the edge key element of both directions. If the other direction does not exist, nothing happens.
Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
replaceNode(oldNode: FEV_KEGG.Graph.Elements.Element, newNode: FEV_KEGG.Graph.Elements.Element)[source]¶ Replaces a certain node, if present, with another node.
Silently ignores non-existing nodes.
Parameters: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
replaceNodes(oldToNew: Dict[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element])[source]¶ Replaces certain nodes, if present, with another node each.
Silently ignores non-existing nodes.
Parameters: oldToNew (Dict[Element, Element]) – Node to be replaced pointing to the node to replace it. Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
-
union(withGraph: Graph to be unified with, allows list of graphs, addCount=False, updateName=False) → CommonGraphApi[source]¶ Union of this graph and the graph(s) in withGraph.
Parameters: - withGraph (CommonGraphApi or Iterable[CommonGraphApi]) – The graph(s) this graph is to be unified with.
- addCount (bool, optional) –
If True, the returned graph contains extra dicts:
- graph.nodeCounts[node] = number of graphs which contained this node
- graph.edgeCounts[(node, node, element)] = number of graphs which contained this edge
- graph.edgeElementCounts[element] = number of graphs which contained this element
- updateName (bool, optional) – If True, update this graph’s name.
Returns: A copy of this graph, containing all nodes and all edges present in any of this graph or the other graph(s).
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationLib.
- self.underlyingRawGraph (
-
class
FEV_KEGG.Graph.Models.DirectedMultiGraph(underlyingRawGraph: implementationGraph = None)[source]¶ Bases:
FEV_KEGG.Graph.Models.CommonGraphApiRepresents a directed multigraph.
Parameters: underlyingRawGraph (
implementationGraph, optional) – 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 chosen inimplementationLib. - self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
- self.nodeCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementnodes still in this graph. None by default. - self.edgeCounts (Dict[Tuple[Element, Element, Element], int], optional) – Number of precursor graphs which contained a certain edge (a Tuple of three
Element) still in this graph. None by default. - self.edgeElementCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementedge keys still in this graph. None by default.
-
getUnidirectionalEdges() → Set[Tuple[FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element, FEV_KEGG.Graph.Elements.Element]][source]¶ Get all edges which are unidirectional only.
Returns: Set of all edge tuples (node1, node2, edge key) that have only one direction, i.e. there is no other edge tuple in reverse direction (node2, node1, edge key). Return type: Set[Tuple[Element, Element, Element]] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
getUnidirectionalEdgesElements() → Set[FEV_KEGG.Graph.Elements.Element][source]¶ Get the edge key elements of all edges which are unidirectional only.
Returns: Set of all edge key elements of edges returned by getUnidirectionalEdges().Return type: Set[Element] Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
implementationGraph¶ alias of
FEV_KEGG.Graph.Implementations.NetworkX.MultiDiGraph
-
toUndirectedGraph(keepUnidirectionalEdges=False) → FEV_KEGG.Graph.Models.UndirectedMultiGraph[source]¶ Create undirected graph from this directed graph.
Parameters: keepUnidirectionalEdges (bool, optional) – If True, treat unidirectional edges in directedMultiGraph as undirected edges, thus keep them for this graph. If False (default), undirected edges are only created if there are edges for both directions in directedMultiGraph. Returns: Undirected graph converted from this directed graph. Return type: UndirectedMultiGraph Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
- self.underlyingRawGraph (
-
class
FEV_KEGG.Graph.Models.MarkedPath(path: FEV_KEGG.Graph.Models.Path, specialKeys: Set[FEV_KEGG.Graph.Elements.Element] = None, specialNodes: Set[FEV_KEGG.Graph.Elements.Element] = None)[source]¶ Bases:
FEV_KEGG.Graph.Models.PathImmutable linear
Path, including markings for special edges/nodes.Parameters: Variables: - self.specialKeys (Set[Element]) – Set of edge keys of the path which have been marked as special. None if specialKeys == None, empty if no special edges found. Special edges with parallel edges are also listed here.
- self.parallelSpecialKeys (Dict[Element, int]) – If there are multiple edges between two nodes, and one of them is marked as special, this special edge is one of x edges between those nodes. This dictionary contains the special edge pointing to its x. Special edges without parallel edges are not listed here. None if specialKeys == None, empty if no special edges with parallel edges found.
- self.specialNodes (Set[Element]) – Set of nodes of the path which have been marked as special. None if specialNodes == None, empty if no special nodes found.
Raises: ValueError– If both specialKeys and specialNodes are None.-
hasSpecialKey¶ Whether this marked path has a special edge.
Returns: Return type: bool
-
hasSpecialNode¶ Whether this marked path has a special node.
Returns: Return type: bool
-
class
FEV_KEGG.Graph.Models.MutablePath(node1: FEV_KEGG.Graph.Elements.Element, edge1: FEV_KEGG.Graph.Elements.Element, node2: FEV_KEGG.Graph.Elements.Element)[source]¶ Bases:
objectMutable directed path of nodes connected by multiple edges.
The path can be elongated after creation. Cycles or loops are not forbidden, you should stay aware of them.
Parameters: Variables: - self.nodes (List[Element]) – List of nodes in order of appearance in the path.
- self.edges (List[Element or FrozenSet[Element]]) – List of multi-edges in order of appearance in the path. A multi-edge may be just a single edge, or a set of parallel edges.
- self.edgesExpanded (Set[Element]) – Set of all edges in the path in arbitrary order. This is calculated by expanding all multi-edges in self.edges into a single set.
- self.path (List[Element or FrozenSet[Element]]) – List of nodes and multi-edges, alternating in order of appearance in the path. A multi-edge may be just a single edge, or a set of parallel edges.
Raises: ValueError– If edge1 is an emptyIterable.TypeError– If you try to use a mutable path in a set.
Warning
A path must be made immutable to be able to use it in a set! See
Path. Otherwise, a TypeError will be raised at some point.-
edges¶
-
edgesExpanded¶
-
elongate(nextEdge: FEV_KEGG.Graph.Elements.Element, nextNode: FEV_KEGG.Graph.Elements.Element)[source]¶ Elongates the path by another (multiple) edge and node.
Parameters: Raises: ValueError– If nextEdge is an emptyIterable.
-
nodes¶
-
class
FEV_KEGG.Graph.Models.Path(mutablePath: FEV_KEGG.Graph.Models.MutablePath)[source]¶ Bases:
objectDirected path of nodes connected by multiple edges, immutable.
The path can not be changed after creation. Cycles or loops are not forbidden, you should stay aware of them.
Parameters: mutablePath (MutablePath) – The path to be made immutable.
Variables: - self.nodes (Tuple[Element]) – List of nodes in order of appearance in the path.
- self.edges (Tuple[Element or FrozenSet[Element]]) – List of multi-edges in order of appearance in the path. A multi-edge may be just a single edge, or a set of parallel edges.
- self.edgesExpanded (FrozenSet[Element]) – Set of all edges in the path in arbitrary order. This is calculated by expanding all multi-edges in self.edges into a single set.
- self.path (Tuple[Element or FrozenSet[Element]]) – List of nodes and multi-edges, alternating in order of appearance in the path. A multi-edge may be just a single edge, or a set of parallel edges.
Raises: ValueError– If edge1 is an emptyIterable.TypeError– If you try to use a mutable path in a set.
Warning
A path must be made immutable to be able to use it in a set! See
Path. Otherwise, a TypeError will be raised at some point.-
edges¶
-
edgesExpanded¶
-
nodes¶
-
class
FEV_KEGG.Graph.Models.UndirectedMultiGraph(underlyingRawGraph: implementationGraph = None)[source]¶ Bases:
FEV_KEGG.Graph.Models.CommonGraphApiRepresents an undirected multi graph.
Parameters: underlyingRawGraph (
implementationGraph, optional) – 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 chosen inimplementationLib. - self.name (str) – Custom name of the graph. This is often set, but not necessary in any calculations.
- self.nodeCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementnodes still in this graph. None by default. - self.edgeCounts (Dict[Tuple[Element, Element, Element], int], optional) – Number of precursor graphs which contained a certain edge (a Tuple of three
Element) still in this graph. None by default. - self.edgeElementCounts (Dict[Element, int], optional) – Number of precursor graphs which contained certain
Elementedge keys still in this graph. None by default.
-
classmethod
fromDirectedMultiGraph(directedMultiGraph: FEV_KEGG.Graph.Models.DirectedMultiGraph, keepUnidirectionalEdges=False)[source]¶ Create undirected graph from a directed graph.
Parameters: - directedMultiGraph (DirectedMultiGraph) – Directed graph to use for conversion.
- keepUnidirectionalEdges (bool, optional) – If True, treat unidirectional edges in directedMultiGraph as undirected edges, thus keep them for this graph. If False (default), undirected edges are only created if there are edges for both directions in directedMultiGraph.
Returns: Undirected graph converted from directedMultiGraph.
Return type: Raises: NotImplementedError– If this function has not been adapted to the chosen graph implementation, yet. SeeimplementationGraph.
-
implementationGraph¶
- self.underlyingRawGraph (