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

7.1.1.4.1.6.1. Functions

get_graph_dict(graph)

Returns the mapping for the given graph. The mapping is defined as a list

get_all_values(dictionary, keys)

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

child_map(mapping, dictionary)

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

get_index(dictionary, path, value)

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

unformatted_matrix(graph)

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

fill_matrix(matrix, length)

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

format_matrix(matrix, max_length)

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

get_mapping(graph)

Returns a matrix for the representation of given graph.

transpose(matrix)

Returns a transpose matrix for given matrix.

7.1.1.4.1.6.2. Module Contents

cobramod.visualization.mapping.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.

Return type:

List

Raises:

GraphKeyError – If graph is missing a value.

Parameters:

graph (dict[str, Union[str, tuple[str]]])

cobramod.visualization.mapping.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.

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, dictionary)

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, path, value)

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)

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.

Return type:

List[list]

Returns

List[list]: Representation of matrix

Raises:

KeyError – If keys in graph are missing

Parameters:

graph (dict)

Return type:

List[list]

cobramod.visualization.mapping.fill_matrix(matrix, length)

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, max_length)

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.

Return type:

List[list]

cobramod.visualization.mapping.get_mapping(graph)

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.

Return type:

List[list]

Returns

List[list]: Representation of matrix

Raises:

KeyError – If keys in graph are missing

Parameters:

graph (dict)

Return type:

List[list]

cobramod.visualization.mapping.transpose(matrix)

Returns a transpose matrix for given matrix.

Parameters:

matrix (List[list])

Return type:

List[list]