Use NetworkX python package to visualise the graphs and the solutions#

To use one of the described component here, you have to import them from khloraascaf_utils.to_networkx.

Constants#

Graph relation type#

RELATION_ATTR = 'relation'#

Relation attribute name on edges.

Its value can be EDGE_ATTRVAL, INVF_ATTRVAL or DIRF_ATTRVAL.

EDGE_ATTRVAL = 'edge'#

Property that assumes the edge is an edge in MDCG.

INVF_ATTRVAL = 'inverted_fragment'#

Property that assumes the edge is an inverted fragment in MDCG.

DIRF_ATTRVAL = 'direct_fragment'#

Property that assumes the edge is a direct fragment in MDCG.

For the solutions#

SOLUTION_PATH_PREFIX_ATTR = 'solution_path'#

Prefix to write the solution path on the edges.

SOLUTION_INVF_PREFIX_ATTR = 'solution_invf'#

Prefix to write the solution inverted fragments.

SOLUTION_DIRF_PREFIX_ATTR = 'solution_dirf'#

Prefix to write the solution direct fragments.

For file extension#

GRAPHML_EXT = 'graphml'#

GraphML file extension.

Functions#

Main function#

mdcg_to_nxdigraph(mdcg, id_container)#

Format mdcg graph to a networkx digraph.

Parameters:
  • mdcg (MDCGraph) – Multiplied doubled contig graph

  • id_container (MDCGraphIDContainer) – Identifiers container

Returns:

NetworkX graph

Return type:

DiGraph

format_occorc_to_nxnode(occorc)#

Format to a string a multiplied oriented contig.

Parameters:

occorc (OccOrCT) – Multiplied oriented contig

Returns:

NetworkX digraph node’s identifier

Return type:

str

To add different solutions’ attributes#

add_solution_path_in_nxdigraph(nxgraph, vertex_path, attribute_suffix)#

Add the solutions’ path to the networkx graph.

Parameters:
  • nxgraph (DiGraph) – NetworkX mdcg graph

  • vertex_path (iterable of OccOrCT) – Vertex path

  • attribute_suffix (str) – Suffix for the attribute name

add_solution_invf_in_nxdigraph(nxgraph, sol_invf, attribute_suffix)#

Add the solutions’ inverted fragments to the networkx graph.

Parameters:
  • nxgraph (DiGraph) – NetworkX mdcg graph

  • sol_invf (iterable of InvFT) – Solution’s inverted fragments list

  • attribute_suffix (str) – Suffix for the attribute name

add_solution_dirf_in_nxdigraph(nxgraph, sol_dirf, attribute_suffix)#

Add the solutions’ direct fragments to the networkx graph.

Parameters:
  • nxgraph (DiGraph) – NetworkX mdcg graph

  • sol_dirf (iterable of DirFT) – Solution’s direct fragments list

  • attribute_suffix (str) – Suffix for the attribute name

To format the attribute keys according to the instance’s name#

solution_path_attr(attribute_suffix)#

Format the attribute name for the solution’s path.

Parameters:

attribute_suffix (str) – Suffix for the attribute name

Returns:

Formatted string attribute name

Return type:

str

solution_invf_attr(attribute_suffix)#

Format the attribute name for the solution’s inverted fragments.

Parameters:

attribute_suffix (str) – Suffix for the attribute name

Returns:

Formatted string attribute name

Return type:

str

solution_dirf_attr(attribute_suffix)#

Format the attribute name for the solution’s direct fragments.

Parameters:

attribute_suffix (str) – Suffix for the attribute name

Returns:

Formatted string attribute name

Return type:

str