fluopy.network

Represent states and transitions as graph.

Functions

construct_state_graphs(→ list[networkx.MultiDiGraph])

Constructs graphs of states (nodes) and their transitions (edges). Each fluorophore

construct_transition_graph(→ networkx.MultiDiGraph)

Constructs a graph of transitions (nodes) and their involved states (edges).

check_graph_suitable(→ tuple[bool, list[Any]])

Checks whether a Markov chain is suitable for an approximation of its development

determine_node_order(→ collections.abc.Generator[Any, ...)

Determine the order of nodes of a graph such that each node that leads to another

plot_graph(→ matplotlib.axes.Axes)

Plot graph.

draw_networkx_curved_edge_labels(→ matplotlib.axes.Axes)

Draws labels to curved edges.

Module Contents

fluopy.network.construct_state_graphs(transition_df: pandas.DataFrame) list[networkx.MultiDiGraph][source]

Constructs graphs of states (nodes) and their transitions (edges). Each fluorophore or fluorophore combination gets a separate graph.

Parameters:

transition_df – Dataframe of all given transitions with non-zero rate containing their id as second level index and their other attributes as columns. Name of fluorophores as first level index.

Returns:

graphs – Contains objects of type nx.MultiDiGraph.

Return type:

list[nx.MultiDiGraph]

fluopy.network.construct_transition_graph(transition_df: pandas.DataFrame) networkx.MultiDiGraph[source]

Constructs a graph of transitions (nodes) and their involved states (edges).

Parameters:

transition_df – Dataframe of all given transitions with non-zero rate containing their id as second level index and their other attributes as columns. Name of fluorophores as first level index.

Returns:

G – Markov chain representation by nodes and edges.

Return type:

nx.MultiDiGraph

fluopy.network.check_graph_suitable(G: networkx.MultiDiGraph, starting_node: int) tuple[bool, list[Any]][source]

Checks whether a Markov chain is suitable for an approximation of its development in time. This means being acyclic (except cycles that include the starting node).

Parameters:
  • G – Markov Chain representation by nodes and edges.

  • starting_node – Numeric value representing the starting node (i.e., state).

Returns:

  • graph_suited (bool) – Whether the graph is suited for the algorithms.

  • cycles (list) – Contains each simple cycle of G.

fluopy.network.determine_node_order(G: networkx.MultiDiGraph, starting_node: int) collections.abc.Generator[Any, None, None][source]

Determine the order of nodes of a graph such that each node that leads to another node has been visited before the other node. Requires the graph to be a DAG (directed acyclic graph). If the starting node is part of each cycle, it can be removed to convert the graph to DAG.

Parameters:
  • G – Markov Chain representation by nodes and edges.

  • starting_node – Numeric value representing the starting node (i.e., state).

Returns:

node_order – Yields the topological sort of the graph.

Return type:

generator

fluopy.network.plot_graph(G: networkx.MultiDiGraph, graph_type: str = 'shell', colors: collections.abc.Sequence[str] = None, scale: float = 1, ax: matplotlib.axes.Axes | None = None) matplotlib.axes.Axes[source]

Plot graph. Adapted from https://stackoverflow.com/questions/22785849/drawing-multiple-edges- between-two-nodes-with-networkx.

Parameters:
  • G – Markov Chain representation by nodes and edges.

  • graph_type – Specifies network layout. One of ‘shell’, ‘circular’, ‘planar’ or ‘kamada’.

  • colors – Contains two colors as Hex values of type str.

  • scale – Factor to scale the figure.

  • ax (mpl.Axes) – The axes on which to show the image

Returns:

Axes object with the plot.

Return type:

mpl.Axes

fluopy.network.draw_networkx_curved_edge_labels(G: networkx.Graph, pos: dict[Any, Any], ax: matplotlib.axes.Axes | None = None, edge_labels: dict[Any, Any] = None, rad: float = 0) matplotlib.axes.Axes[source]

Draws labels to curved edges. Adapted from https://stackoverflow.com/questions/22785849/drawing-multiple-edges- between-two-nodes-with-networkx.

Parameters:
  • G – A networkx graph.

  • pos – Nodes as keys and positions as values.

  • ax – Axis to plot on.

  • edge_labels – Edges (tuples) as keys and labels as values.

  • rad – Rounding radius of curved edge.

Returns:

ax

Return type:

mpl.Axes