Skip to content

Traversal and structure

The traversal methods (neighbors, in_neighbors, out_neighbors, successors, predecessors) are methods of the graph: anet.neighbors('EGFR'). The functions in annnet.algorithms answer questions about the directed edges of a graph.

annnet.algorithms.traversal.Traversal

Local neighborhood traversal over the incidence-backed graph.

Every method here delegates to the structural query facade of the core, which owns the traversal itself. The facade answers a binary edge from the adjacency index in time proportional to the degree, and it answers a hyperedge from a list it caches against the structural clock. A graph with no hyperedge therefore never pays a full edge scan.

Functions

neighbors
neighbors(entity_id)

Return adjacent entities for a node or an edge-entity.

Parameters:

Name Type Description Default
entity_id str

Entity identifier.

required

Returns:

Type Description
list[str]

Neighbor identifiers reachable through incident edges.

out_neighbors
out_neighbors(node_id)

Return outward neighbors of a node.

Parameters:

Name Type Description Default
node_id str

Node identifier.

required

Returns:

Type Description
list[str]

Neighbor identifiers reachable via outgoing or undirected edges.

successors
successors(node_id)

Alias for :meth:out_neighbors.

Parameters:

Name Type Description Default
node_id str

Node identifier.

required

Returns:

Type Description
list[str]

Successor identifiers.

in_neighbors
in_neighbors(node_id)

Return inward neighbors of a node.

Parameters:

Name Type Description Default
node_id str

Node identifier.

required

Returns:

Type Description
list[str]

Neighbor identifiers reachable via incoming or undirected edges.

predecessors
predecessors(node_id)

Alias for :meth:in_neighbors.

Parameters:

Name Type Description Default
node_id str

Node identifier.

required

Returns:

Type Description
list[str]

Predecessor identifiers.

Structure

annnet.algorithms.structure.directed_pairs

directed_pairs(graph)

Yield (source_id, target_id) for every directed binary edge.

An undirected edge has two sides in storage order and no direction, so it is left out. A hyperedge has no single source and no single target, so it is left out too, as are edges incident to edge entities. Ids are bare node ids, whatever layer the node sits in.

annnet.algorithms.structure.sources

sources(graph)

The nodes a directed binary edge starts from.

annnet.algorithms.structure.targets

targets(graph)

The nodes a directed binary edge ends at.

annnet.algorithms.structure.directed_cycle

directed_cycle(graph)

One directed cycle, as the nodes along it, or None when there is none.

Depth-first over the directed binary edges, stopping at the first cycle found. The list starts and ends on the same node, so a self-loop comes back as [node, node]. Which cycle is found when there are several is not promised.