celldancer.cdplt.PTO_Graph

celldancer.cdplt.PTO_Graph(ax, cellDancer_df, node_layout='forceatlas2', PRNG_SEED=None, force_iters=2000, use_edge_bundling=True, node_colors=None, node_sizes=5, edge_length=None, legend='off', colorbar='on')

Graph visualization of selected cells reflecting their orders in pseudotime (PseudoTimeOrdered_Graph: PTO_Graph). Embedding and pseudotime of the cells are required. Each cell makes a node and the connections between nodes are based on their separation in the embedding space and the strength of the connection is proportional to the pseudotime difference (the larger the pseudotime difference in absolute values, the weaker the connection).

Example usage:

from celldancer.plotting import graph
from matplotlib import pyplot as plt
fig, ax = plt.subplots(figsize=(10,10))
graph.PTO_Graph(ax,
    load_cellDancer,
    node_layout='forcedirected',
    use_edge_bundling=True,
    node_colors='clusters',
    edge_length=3,
    node_sizes='pseudotime',
    colorbar='on',
    legend='on')

In this example, we use a force-directed node layout algorithm (ForceAtlas2). A connection is made between any two cells within 3 (unit in the embedding). The resulted edge lengths indicate the time difference between nodes (the closer in pseudotime, the shorter the edge length). Edge bundling is applied to highlight important edges (trunks). The sizes of the nodes are proportional to the pseudotime. The nodes are colored according to their cell types (if given by the input data).

Parameters
  • cellDancer_df (pandas.DataFrame) – Dataframe of velocity estimation, cell velocity, and pseudotime results. Columns=[‘cellIndex’, ‘gene_name’, ‘unsplice’, ‘splice’, ‘unsplice_predict’, ‘splice_predict’, ‘alpha’, ‘beta’, ‘gamma’, ‘loss’, ‘cellID’, ‘clusters’, ‘embedding1’, ‘embedding2’, ‘velocity1’, ‘velocity2’, ‘pseudotime’]

  • node_layout (optional, str (default: forceatlas2)) –

    Layout for the graph. Currently only supports the forceatlas2 and embedding.

    • ’forceatlas2’ or ‘forcedirected’: treat connections as forces

    between connected nodes.

    • ’embedding’: use the embedding as positions of the nodes.

  • PRNG_SEED (optional, int, or None (default: None)) – Seed to initialize the pseudo-random number generator.

  • force_iters (optional, int (default: 2000)) – Number of passes for the force-directed layout calculation.

  • use_edge_bundling (optional, bool (default: True)) – True if bundle the edges (computational demanding). Edge bundling allows edges to curve and groups nearby ones together for better visualization of the graph structure.

  • node_colors (optional, str (default: None)) –

    The node fill colors. Possible values:

    • clusters: color according to the clusters information of the respective cells.

    • pseudotime: colors according to the pseudotime of the respective cells.

    • A single color format string.

  • edge_length (optional, float (default: None)) – The distance cutoff in the embedding between two nodes to determine whether an edge should be formed (edge is formed when r < edge_length). By default, the mean of all the cell

  • node_sizes (optional, float or numeric list-like or str (default: 5)) – The sizes of the nodes. If it is str, then the str has to be either one of those {pseudotime, index, x, y} read from the nodes dataframe.

  • legend (optional, str (default: ‘off’)) –

    • ‘off’/’on’: Exclude/include the cell type legend on the plot.

    • ’only’: Negelect the plot and only show the cell type legend.

  • colorbar (optional, str (default: ‘on’)) –

    • ‘off’/’on’: Show the colorbar in the case nodes are colored by pseudotime.

Returns

ax

Return type

matplotlib.axes.Axes