ensembl.vep.render.graph package#

Graph model, layout and emitters. Domain-free: nothing here imports the rest of the package.

Submodules#

ensembl.vep.render.graph.dot module#

Rendering a graph as Graphviz DOT.

ensembl.vep.render.graph.dot.render_dot(graph)[source]#

Return a graph as a DOT digraph.

Node semantics are emitted as attributes rather than as an appearance, so a caller styling the output with their own Graphviz theme has everything the builder knew.

Return type:

str

ensembl.vep.render.graph.layout module#

Placing a layered graph on a canvas.

These graphs are small – tens of facts and rules – and already carry the layer each node belongs to, so laying them out is arithmetic rather than a general graph-drawing problem. Layers become columns, and a node’s position within its column follows declaration order.

class ensembl.vep.render.graph.layout.Layout(*, graph, placements, width, height)[source]#

Bases: object

A graph with a position for every node.

Variables:
  • graph (Graph) – The graph laid out.

  • placements (tuple[Placement, ...]) – One entry per node, in the graph’s own order.

  • width (int) – Canvas width, in pixels.

  • height (int) – Canvas height, in pixels.

graph: Graph#
height: int#
placement(identifier)[source]#

Return the placement of one node.

Raises:

KeyError – If no node has that identifier.

Return type:

Placement

placements: tuple[Placement, ...]#
width: int#
class ensembl.vep.render.graph.layout.Placement(*, node, x, y, width=170, height=34)[source]#

Bases: object

Where one node sits on the canvas.

Variables:
  • node (Node) – The node placed.

  • x (int) – Left edge, in pixels.

  • y (int) – Top edge, in pixels.

  • width (int) – Box width, in pixels.

  • height (int) – Box height, in pixels.

property centre_y: int#

Return the vertical midpoint, where an edge attaches.

height: int#
node: Node#
property right: int#

Return the right edge, where an outgoing edge leaves.

width: int#
x: int#
y: int#
ensembl.vep.render.graph.layout.layered(graph)[source]#

Lay a graph out in columns, one per layer.

Layers are taken from the nodes themselves rather than inferred, because the domain already knows the answer: a fact’s layer is its cost tier, a rule’s is its rank.

Return type:

Layout

ensembl.vep.render.graph.layout.tree(graph)[source]#

Lay a child-to-parent tree out with every parent centred on its children.

Edges must point from an operand towards its parent. The one node with no outgoing edge is the root. Leaves keep graph declaration order, making the result stable while preserving sibling order from the source expression.

Raises:

ValueError – If the graph is disconnected, cyclic, or gives a node more than one parent.

Return type:

Layout

ensembl.vep.render.graph.mermaid module#

Rendering a graph as Mermaid flowchart source.

ensembl.vep.render.graph.mermaid.render_mermaid(graph)[source]#

Return a graph as a left-to-right Mermaid flowchart.

Node state becomes a Mermaid class rather than a colour, so the diagram picks up whatever theme the surrounding document defines.

Return type:

str

ensembl.vep.render.graph.model module#

A directed graph carrying semantics, not styling.

A builder describes what a node is – its kind, which layer it belongs to, what state it ended in – and never what colour it should be. Renderers map those semantics onto an appearance, so every styling decision stays in one package and a builder needs no knowledge of the theme.

class ensembl.vep.render.graph.model.Edge(*, source, target, kind='', label='')[source]#

Bases: object

One directed connection between two nodes.

Variables:
  • source (str) – The identifier the edge leaves.

  • target (str) – The identifier the edge enters.

  • kind (str) – What the connection means, e.g. “depends”, “requires”, “subsumes”.

  • label (str) – Optional text drawn along the edge.

kind: str#
label: str#
source: str#
target: str#
class ensembl.vep.render.graph.model.Graph(*, nodes=(), edges=(), title='')[source]#

Bases: object

A set of nodes and the edges between them.

Variables:
  • nodes (tuple[Node, ...]) – The vertices, in the order a builder produced them.

  • edges (tuple[Edge, ...]) – The connections.

  • title (str) – What the graph shows.

edges: tuple[Edge, ...]#
edges_from(identifier)[source]#

Return the edges leaving one node.

Return type:

tuple[Edge, ...]

layers()[source]#

Return the distinct layer numbers present, in ascending order.

Return type:

tuple[int, ...]

node(identifier)[source]#

Return one node by its identifier.

Raises:

KeyError – If no node has that identifier.

Return type:

Node

nodes: tuple[Node, ...]#
nodes_in_layer(layer)[source]#

Return the nodes of one layer, in declaration order.

Return type:

tuple[Node, ...]

title: str#
with_hits(hits_by_identifier)[source]#

Return a copy whose nodes carry the given hit counts.

How a corpus-reach overlay is applied: the shape of the graph is unchanged, only what each node reports about how often it was reached.

Return type:

Graph

class ensembl.vep.render.graph.model.Node(*, identifier, label, kind='', layer=0, state='', hits=0, detail='')[source]#

Bases: object

One vertex.

Variables:
  • identifier (str) – Unique within a graph, and what edges refer to.

  • label (str) – The text a renderer draws.

  • kind (str) – What the node represents, e.g. “fact”, “rule”, “term”.

  • layer (int) – Which column or row the node belongs to. Layered layouts read this directly; it comes from something meaningful in the domain, such as a fact’s cost tier or a rule’s rank.

  • state (str) – How the node ended up, e.g. “computed”, “forced_false”, “fired”.

  • hits (int) – How many times the node was reached, for a corpus-reach overlay.

  • detail (str) – Optional secondary text, e.g. a value or a reason.

detail: str#
hits: int#
identifier: str#
kind: str#
label: str#
layer: int#
state: str#

ensembl.vep.render.graph.svg module#

Rendering a laid-out graph as inline SVG.

The one place node semantics become an appearance: a builder says a node was forced false, this module decides that means a dashed grey box.

ensembl.vep.render.graph.svg.STATE_COLOURS = {'cached': Colour.NEON_BLUE, 'computed': Colour.ICE_BLUE, 'emitted': Colour.BLUE, 'false': Colour.RED, 'fired': Colour.LIGHT_BLUE, 'forced_false': Colour.LIGHT_GREY, 'impact_high': Colour.DARK_PINK, 'impact_low': Colour.DUCKEGG_BLUE, 'impact_moderate': Colour.ORANGE, 'impact_modifier': Colour.LIGHT_GREY, 'operator': Colour.LIGHT_GREY, 'prefilled': Colour.DUCKEGG_BLUE, 'pruned': Colour.MEDIUM_LIGHT_GREY, 'subsumed': Colour.DUCKEGG_BLUE, 'suppressor': Colour.DARK_PINK, 'term': Colour.LIGHT_BLUE, 'true': Colour.LIGHT_BLUE, 'unreached': Colour.WHITE}#

Node state -> fill colour. A state absent from here falls back to the neutral fill.

The one place a builder’s semantics become an appearance: subsumed and suppressor are the two directions of suppression, and they are coloured apart so which way it runs is readable without following the arrowheads.

ensembl.vep.render.graph.svg.render_svg(graph, layout=None, *, links=None)[source]#

Return a graph as a standalone <svg> element.

Parameters:
  • graph (Graph) – The graph to draw.

  • layout (Layout | None, default: None) – A layout to use, or None to lay the graph out in columns.

  • links (Mapping[str, str] | None, default: None) – Optional node identifiers to link destinations.

Returns:

The SVG markup, self-contained apart from the font stack it names.

Return type:

str