5.1.3.1.4. cobramod.visualization.mapping

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 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.

5.1.3.1.4.1. Module Contents

5.1.3.1.4.1.1. Functions

get_all_values(dictionary: dict, keys: list) → set

Return a set with the all the values for a given list of keys. Elements of

child_map(mapping: list, dictionary: dict) → dict

Returns the relation parent: children as a dictionary. A key represent the

get_index(dictionary: dict, path: list, value) → int

Return index of item in a path, whose value is found.

unformatted_matrix(graph: dict) → List[list]

Returns an unformatted matrix from a graph. The matrix represent the

fill_matrix(matrix: List[list], length: int)

Fills each row of the matrix with 0 until it reaches given length

format_matrix(matrix: List[list], max_length: int) → List[list]

Formats given matrix and returns, if possible, a reduced matrix. Matrix

get_mapping(graph: dict) → List[list]

Returns a matrix for the representation of given graph.

transpose(matrix: List[list]) → List[list]

Returns a transpose matrix for given matrix.

cobramod.visualization.mapping.get_all_values(dictionary: dict, keys: list) set

Return a set with the all the values for a given list of keys. Elements of tuples will be added separately.

Parameters
  • dictionary (dict) – dictionary with keys and values

  • keys (list) – List of keys to get values

Returns

Values from given keys

Return type

Set

cobramod.visualization.mapping.child_map(mapping: list, dictionary: dict) dict

Returns the relation parent: children as a dictionary. A key represent the parent and the key their corresponding children

Parameters
  • mapping (list) – Paths from given graph

  • dictionary (dict) – Original dictionary of directed graph.

Returns

Relation of parent and children.

Return type

Dict

cobramod.visualization.mapping.get_index(dictionary: dict, path: list, value) int

Return index of item in a path, whose value is found.

Parameters
  • dictionary (dict) – Original dictionary of directed graph

  • path (list) – A list with the name of nodes to be searched.

  • value (Any) – Value to find in path

Returns

index of path.

Return type

int

Raises

Warning – If value is not found.

cobramod.visualization.mapping.unformatted_matrix(graph: dict) List[list]

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.

Parameters

graph (dict) – Dictionary with relationship between nodes. A node can have multiple edges, which should be presented as values.

Returns

List[list]: Representation of matrix

Raises

KeyError – If keys in graph are missing

cobramod.visualization.mapping.fill_matrix(matrix: List[list], length: int)

Fills each row of the matrix with 0 until it reaches given length

Parameters
  • matrix (List[list]) – Matrix to fill

  • length (int) – Desired length.

cobramod.visualization.mapping.format_matrix(matrix: List[list], max_length: int) List[list]

Formats given matrix and returns, if possible, a reduced matrix. Matrix will be filled with 0’s if needed.

Parameters
  • matrix (List[list]) – Matrix to fill

  • max_length (int) – Desired length.

cobramod.visualization.mapping.get_mapping(graph: dict) List[list]

Returns a matrix for the representation of given graph.

Parameters

graph (dict) – Dictionary with relationship between nodes. A node can have multiple edges, which should be presented as values.

Returns

List[list]: Representation of matrix

Raises

KeyError – If keys in graph are missing

cobramod.visualization.mapping.transpose(matrix: List[list]) List[list]

Returns a transpose matrix for given matrix.