cobramod.core.graph =================== .. py:module:: cobramod.core.graph .. autoapi-nested-parse:: Module for graph algorithm This module creates the needed functions to find out the reaction order from a pathway. The vertex represents the reactions and the edges symbolize the order of the reactions. I.e. the relationship between reactions. The main function of this module: build_graph: From given dictionary with Parent-reaction:children-reaction, return the corresponding non-cyclic directed graph. Exceptions ---------- .. autoapisummary:: cobramod.core.graph.GraphKeyError Functions --------- .. autoapisummary:: cobramod.core.graph.find_missing cobramod.core.graph.find_cycle cobramod.core.graph.return_cycles cobramod.core.graph.cut_cycle cobramod.core.graph.cut_parents cobramod.core.graph.back cobramod.core.graph.verify_paths cobramod.core.graph.get_paths cobramod.core.graph.get_mapping cobramod.core.graph.get_graph_dict cobramod.core.graph.filter_graph cobramod.core.graph.build_lineal_graph Module Contents --------------- .. py:exception:: GraphKeyError Bases: :py:obj:`Exception` Simple Error that should be raised when a value is missing as key in a graph .. py:function:: find_missing(graph) Checks whether the given graph is missing a key. :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict :raises KeyError: If keys are missing .. py:function:: find_cycle(graph, key, visited) .. py:function:: return_cycles(graph) Returns a nested list of cyclic paths. These paths might repeat. If the graph does not contain a cycle, the list is empty. :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict :returns: Nested list with cyclic paths or an empty list if the graph does not contain a cycle. :rtype: List .. py:function:: cut_cycle(graph, key) Changes value of the key to None in a given dictionary. It will raise an error if the value is a tuple. .. py:function:: cut_parents(graph) Checks if multiple parents shared a common child. If so, the graph will replace the values of these parents to a None and leave one of the parents normal. :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict .. py:function:: back(graph, value, path, stop_list = []) Returns a list with a linear path. The function creates a sequence from the graph dictionary until the given value is found in the sequence or in the given stop_list. The function does not work with graphs that contain some kind of cycle and will raise a recursion error. :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict :param value: The value to be searched.. :type value: str :param path: The already-visited path. :type path: list :param stop_list: Elements that trigger the function to stop, if found. :type stop_list: list :returns: A list with the path that ends with the specified value or with an element of the stop_list. :rtype: List :raises RecursionError: If an element is visited more than once due to a cycle. .. py:function:: verify_paths(paths, graph) Returns the missing keys that are not present in the given paths list. :param paths: Paths of the given graph. :type paths: list :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict :returns: Either the missing nodes or an empty set. :rtype: set .. py:function:: get_paths(graph, stop_list) Returns a list with the longest paths in a graph. This only works with lineal directed paths. :param graph: Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. :type graph: dict :returns: Paths from given graph :rtype: List :raises RecursionError: if the graph is not lineal .. py:function:: get_mapping(graph, stop_list, new) Gets the mapping for given graph. The mapping defines the longest paths for the graph without including the previous longest path. The function modifies given graph. :param graph: graph (dict): Dictionary representing the relationships between nodes. A node can have several edges, which should be represented in the form of values. This will be modified. :type graph: dict :param stop_list: Elements that cause the function to stop when found. :type stop_list: list :param new: List with new mapping. Must be empty when called for the first time. :type new: list :returns: A list with the new mapping. Longest path for each recursion and rest. :rtype: List .. py:function:: get_graph_dict(graph) Returns the mapping for the given graph. The mapping is defined as a list with a "core" path and its branches. Cyclic graphs will be cut to create a lineal direct graph .. note:: If the first element of a branch is not in the "core", then it is in one of the branches. :returns: Mapping of the graph. :rtype: List :raises GraphKeyError: If graph is missing a value. .. py:function:: filter_graph(graph, avoid_list) Returns a new graph, where items are removed if found in given avoid list. .. py:function:: build_lineal_graph(sequence) Creates a returns a simple lineal directed graph from given sequence