cobramod.visualization.mapping ============================== .. py:module:: cobramod.visualization.mapping .. autoapi-nested-parse:: Mapping of graph This modules handles the mapping of a directed graph into a matrix that can be used in Escher. The main function is :func:`cobramod.visualization.mapping.get_mapping`, which checks if the graph is lineal and creates the representation in a matrix. In case of cyclic path, it will cut it. Functions --------- .. autoapisummary:: cobramod.visualization.mapping.get_graph_dict cobramod.visualization.mapping.get_all_values cobramod.visualization.mapping.child_map cobramod.visualization.mapping.get_index cobramod.visualization.mapping.unformatted_matrix cobramod.visualization.mapping.fill_matrix cobramod.visualization.mapping.format_matrix cobramod.visualization.mapping.get_mapping cobramod.visualization.mapping.transpose Module Contents --------------- .. 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:: get_all_values(dictionary, keys) Return a set with the all the values for a given list of keys. Elements of tuples will be added separately. :param dictionary: dictionary with keys and values :type dictionary: dict :param keys: List of keys to get values :type keys: list :returns: Values from given keys :rtype: Set .. py:function:: child_map(mapping, dictionary) Returns the relation parent: children as a dictionary. A key represent the parent and the key their corresponding children :param mapping: Paths from given graph :type mapping: list :param dictionary: Original dictionary of directed graph. :type dictionary: dict :returns: Relation of parent and children. :rtype: Dict .. py:function:: get_index(dictionary, path, value) Return index of item in a path, whose value is found. :param dictionary: Original dictionary of directed graph :type dictionary: dict :param path: A list with the name of nodes to be searched. :type path: list :param value: Value to find in path :type value: Any :returns: index of path. :rtype: int :raises Warning: If value is not found. .. py:function:: unformatted_matrix(graph) Returns an unformatted matrix from a graph. The matrix represent the locations of the nodes and their relationships. Graph will be cut if cyclic. Unrelated nodes will be appended separately at the end. The matrix have 0 in empty positions. :param graph: Dictionary with relationship between nodes. A node can have multiple edges, which should be presented as values. :type graph: dict Returns List[list]: Representation of matrix :raises KeyError: If keys in graph are missing .. py:function:: fill_matrix(matrix, length) Fills each row of the matrix with 0 until it reaches given length :param matrix: Matrix to fill :type matrix: List[list] :param length: Desired length. :type length: int .. py:function:: format_matrix(matrix, max_length) Formats given matrix and returns, if possible, a reduced matrix. Matrix will be filled with 0's if needed. :param matrix: Matrix to fill :type matrix: List[list] :param max_length: Desired length. :type max_length: int .. py:function:: get_mapping(graph) Returns a matrix for the representation of given graph. :param graph: Dictionary with relationship between nodes. A node can have multiple edges, which should be presented as values. :type graph: dict Returns List[list]: Representation of matrix :raises KeyError: If keys in graph are missing .. py:function:: transpose(matrix) Returns a transpose matrix for given matrix.