tomodrgn.commands.graph_traversal.LatentGraph#

class LatentGraph(edges: list[tuple[int, int, float]])[source]#

Bases: object

Class for describing connected latent embeddings as a graph based on proximity in latent space.

Methods

construct_from_array

Constructor method to create a graph of connected latent embeddings from an array of all latent embeddings.

find_path_dijkstra

Standard implementation of Dijkstra's algorithm to find the shortest path through a weighted graph.

plot_graph

Plot a 2-D graph of the data underlying the LatentGraph object.

plot_path

Plot a 2-D graph of the data underlying the LatentGraph object, superimposed by a series of connected paths.

classmethod construct_from_array(data: ndarray, max_neighbors: int, avg_neighbors: int)[source]#

Constructor method to create a graph of connected latent embeddings from an array of all latent embeddings.

Parameters:
  • data – array of latent embeddings, shape (nptcls, zdim)

  • max_neighbors – maximum number of neighbors to initially calculate distances for from each latent embedding

  • avg_neighbors – used to set a cutoff distance defining connected neighbors such that each embedding will have this many connected neighbors on average

Returns:

LatentGraph instance

find_path_dijkstra(src: int, dest: int) tuple[list[int], float] | tuple[None, None][source]#

Standard implementation of Dijkstra’s algorithm to find the shortest path through a weighted graph. Earliest reference I can find for this code is: theannielin/drkung143

Parameters:
  • src – index of starting node

  • dest – index of ending node

Returns:

list of node indices connecting src and dest nodes and total distance of that path, or (None, None) if no path can be found

plot_graph(data: ndarray) tuple[Figure, Axes][source]#

Plot a 2-D graph of the data underlying the LatentGraph object. Scatter plot all points; draw line segments between connected graph components.

Parameters:

data – data array from which this graph object was created, shape (nptcls, zdim)

Returns:

the created graph figure and its contained axis

plot_path(data: ndarray, anchor_inds: list[int], path_inds: list[int]) tuple[Figure, Axes][source]#

Plot a 2-D graph of the data underlying the LatentGraph object, superimposed by a series of connected paths. The connected paths are drawn as red line segments. Data (particle) indices along path are annotated, with anchor points defining path search input marked in bold.

Parameters:
  • data – data array from which this graph object was created, shape (nptcls, zdim)

  • anchor_inds – list of node indices used as anchors to define start and end of each searched path segment

  • path_inds – list of node indices defining each minimum-distance path, in order of input anchor indices

Returns:

the created graph figure and its contained axis