plot — plotting

Plotting functions for accuracy summaries, networks, and simulations.

bobaT.plot.plot_sklearn_summ_stats(summary_stats, VAL_DIR, fname='')[source]
bobaT.plot.plot_sklearn_metrics(VAL_DIR, show=False, save=True)[source]
bobaT.plot.plot_roc(fprs, tprs, area, node, save=False, save_dir=None, show_plot=True)[source]
bobaT.plot.plot_aucs(VAL_DIR, save=False, show_plot=True)[source]
bobaT.plot.plot_validation_avgs(fpr_all, tpr_all, num_nodes, area_all, save=False, save_dir=None, show_plot=False, vertex_dict=None, graph=None, remove_sources=False)[source]
bobaT.plot.parent_heatmap(data, regulators_dict, gene)[source]
bobaT.plot.plot_accuracy(data, node, regulators_dict, rules, data_t1=None, plot_clusters=False, clusters=None, save=True, save_dir=None, show_plot=False, save_df=True, customPalette=[(0.4, 0.7607843137254902, 0.6470588235294118), (0.9882352941176471, 0.5529411764705883, 0.3843137254901961), (0.5529411764705883, 0.6274509803921569, 0.796078431372549), (0.9058823529411765, 0.5411764705882353, 0.7647058823529411), (0.6509803921568628, 0.8470588235294118, 0.32941176470588235), (1.0, 0.8509803921568627, 0.1843137254901961), (0.8980392156862745, 0.7686274509803922, 0.5803921568627451), (0.7019607843137254, 0.7019607843137254, 0.7019607843137254)])[source]
bobaT.plot.plot_attractors(fname, save_dir='', sep=',')[source]
bobaT.plot.plot_attractors_clustermap(fname, save_dir=None, sep=',', save=True)[source]
bobaT.plot.make_jaccard_heatmap(fname, cmap='viridis', set_color={}, clustered=True, figsize=(10, 10), save=False, save_dir=None)[source]

Function to make heatmap of jaccard distance between attractors from dataframe

Parameters:
  • fname (str) – File name for filtered attractors csv.

  • cmap (str, optional) – color map, defaults to ‘viridis’

  • set_color (dict, optional) – Optional dictionary to include specific color arguments; for example, {“Generalist”: “lightgrey”}, defaults to dict()

  • clustered (bool, optional) – Whether to cluster the rows and colors or leave in the original order without dendrograms, defaults to True

  • figsize (tuple, optional) – Figure size, defaults to (10,10)

  • save (bool, optional) – Whether to save the figure or show, defaults to False

  • save_dir (str, optional) – Directory to save figure, defaults to None

bobaT.plot.plot_rule(gene, rule, regulators, sample_weights, data, save_dir='rules', save=False, show_plot=True, hlines=None)[source]
bobaT.plot.plot_histograms(n_steps_0, n_steps_1, expt_label, bins=20, fname=None, ax=None)[source]

Plot histograms for random walks compared to perturbations. This function is an internal function called by rw.random_walks() and should be used with caution.

Parameters:
  • n_steps_0 (list of integers) – list of lengths of random walks without perturbation (from rw.random_walks())

  • n_steps_1 (list of integers) – list of lengths of random walks with perturbation (from rw.random_walks())

  • expt_label (string) – name of perturbation (in rw.random_walks(), this is assigned to “{node}_activate” or “{node}_knockdown”

  • bins (int, optional) – number of bins for histogram plot, defaults to 20

  • fname (string or None, optional) – name of file to save histogram plot, defaults to None

  • ax (Matplotlib Axes object, optional) – if plotting on an axis that already exists, defaults to None

Returns:

list of control average, perturbation average, and destabilization score

Return type:

list of floats

bobaT.plot.plot_destabilization_scores(attractor_dict, perturbations_dir, show=False, save=True, clustered=True, act_kd_together=False, save_dir='clustered_perturb_plots')[source]
bobaT.plot.plot_perturb_gene_dictionary(p_dict, full, perturbations_dir, show=False, save=True, ncols=5, fname='', palette={'activate': 'green', 'knockdown': 'orange'})[source]
bobaT.plot.plot_stability(attractor_dict, walks_dir, palette=[(0.12156862745098039, 0.4666666666666667, 0.7058823529411765), (0.6823529411764706, 0.7803921568627451, 0.9098039215686274), (1.0, 0.4980392156862745, 0.054901960784313725), (1.0, 0.7333333333333333, 0.47058823529411764), (0.17254901960784313, 0.6274509803921569, 0.17254901960784313), (0.596078431372549, 0.8745098039215686, 0.5411764705882353), (0.8392156862745098, 0.15294117647058825, 0.1568627450980392), (1.0, 0.596078431372549, 0.5882352941176471), (0.5803921568627451, 0.403921568627451, 0.7411764705882353), (0.7725490196078432, 0.6901960784313725, 0.8352941176470589), (0.5490196078431373, 0.33725490196078434, 0.29411764705882354), (0.7686274509803922, 0.611764705882353, 0.5803921568627451), (0.8901960784313725, 0.4666666666666667, 0.7607843137254902), (0.9686274509803922, 0.7137254901960784, 0.8235294117647058), (0.4980392156862745, 0.4980392156862745, 0.4980392156862745), (0.7803921568627451, 0.7803921568627451, 0.7803921568627451), (0.7372549019607844, 0.7411764705882353, 0.13333333333333333), (0.8588235294117647, 0.8588235294117647, 0.5529411764705883), (0.09019607843137255, 0.7450980392156863, 0.8117647058823529), (0.6196078431372549, 0.8549019607843137, 0.8980392156862745)], rescaled=True, show=False, save=True, err_style='bars')[source]
bobaT.plot.plot_random_walks(walk_path, starting_attractors, ATTRACTOR_DIR, nodes, perturb=None, num_walks=20, binarized_data=None, save_as='', show_lineplots=True, fit_to_data=True, plot_vs=False, show=False, reduction='pca', set_colors=None)[source]

Visualization of random walks with and without perturbations

Parameters:
  • walk_path – file path to the walks folder for plotting (usually long_walks subfolder)

  • starting_attractors – name of the attractors to start the walk from (key in attractor_dict)

  • perturb – name of perturbation to plot (suffix of walk results csv files)

  • ATTRACTOR_DIR – file path to the attractors folder

  • nodes – list of nodes in the network

  • num_walks – number of walks to plot with lines and kde plot

  • binarized_data – if fit_to_data is True, this is the binarized data as a dictionary

  • save_as – suffix on plot file name

  • show_lineplots – if true, plot the lineplots of the walks

  • fit_to_data – if true, fit the pca to the data instead of only the attractors

  • plot_vs – if true, plot both the unperturbed and perturbed plot side by side. Note that perturb must be specified.

  • show – if true, show the plot

  • reduction – dimensionality reduction method to use. Options are ‘pca’ and ‘umap’

  • set_colors – dictionary of colors to use for each attractor type (key in attractor_dict); otherwise default seaborn palette is used. Can specify single attractor-color mapping to override default palette for that attractor, for example, {‘Generalist’: ‘grey’}

Returns:

bobaT.plot.pca_plot_paths(att_list, phenotypes, phenotype_color, radius, start_idx, num_paths=100, pca_path_reduce=False, walk_to_basin=False)[source]

DO NOT USE. STILL UNDER DEVELOPMENT. Use plot_random_walks instead.

Parameters:
  • att_list (_type_) – _description_

  • phenotypes (_type_) – _description_

  • phenotype_color (_type_) – _description_

  • radius (_type_) – _description_

  • start_idx (_type_) – _description_

  • num_paths (int, optional) – _description_, defaults to 100

  • pca_path_reduce (bool, optional) – _description_, defaults to False

  • walk_to_basin (bool, optional) – _description_, defaults to False

bobaT.plot.plot_all_random_walks(walk_path, starting_attractors, ATTRACTOR_DIR, nodes, perturb=None, num_walks=20, binarized_data=None, save_as='', fit_to_data=True, show=False, reduction='pca', set_colors={'Generalist': 'grey'})[source]

Visualization of random walks with and without perturbations

Parameters:
  • walk_path – file path to the walks folder for plotting (usually long_walks subfolder)

  • starting_attractors – name of the attractors to start the walk from (key in attractor_dict)

  • perturb – name of perturbation to plot (suffix of walk results csv files)

  • ATTRACTOR_DIR – file path to the attractors folder

  • num_walks – number of walks to plot with lines and kde plot

  • binarized_data – if fit_to_data is True, this is the binarized data

  • save_as – suffix on plot file name

  • fit_to_data – if true, fit the pca to the data instead of only the attractors

  • show – if true, show the plot

  • reduction – dimensionality reduction method to use. Options are ‘pca’ and ‘umap’

  • set_colors – dictionary of colors to use for each attractor type (key in attractor_dict); otherwise default seaborn palette is used. Can specify single attractor-color mapping to override default palette for that attractor

Returns:

bobaT.plot.check_middle_stop(start_idx, basin, check_stops, radius=2)[source]

DO NOT USE. STILL UNDER DEVELOPMENT.

Parameters:
  • start_idx (_type_) – _description_

  • basin (_type_) – _description_

  • check_stops (_type_) – _description_

  • radius (int, optional) – _description_, defaults to 2

Returns:

_description_

Return type:

_type_

bobaT.plot.draw_grn(G, gene2vertex, rules, regulators_dict, fname, gene2group=None, gene2color=None, type='', B_min=5, save_edge_weights=True, edge_weights_fname='edge_weights.csv')[source]

Plot the network and optionally save to pdf

Parameters:
  • G (graph-tool graph object) – Graph to plot, such as the graph outputted by load.load_network()

  • gene2vertex (dict) – Vertex dictionary assigning node names to vertices in network, such as the vertex_dict outputted by load.load_network()

  • rules (rules describing the Boolean tree for each node in network, such as the rules outputted by tl.get_rules()) – _description_

  • regulators_dict (dict) – dictionary of the form {node_A:[parents_of_A], node_B:[parents_of_B],…}

  • fname (str) – File path to save network plot

  • gene2group (dict, optional) – Dictionary of the form {node[str]:group[int]} used to group nodes by color, defaults to None

  • gene2color (dict, optional) – Dictionary of the form {node[str]:color[vector<float>]} used to group nodes by color (in normalized RGBA format), defaults to None

  • type (str, optional) – network plot type, either “circle” or “”, defaults to “”

  • B_min (int, optional) – if type ==’circle’, B_min is argument of minimize_nested_blockmodel_dl for arranging nodes, defaults to 5

  • save_edge_weights (bool, optional) – Whether to save the edge weights DataFrame to a csv, defaults to True

  • edge_weights_fname (str, optional) – If save_edge_weights == True, file name for saving edge weights DataFrame, defaults to “edge_weights.csv”

Returns:

Graph with additional edge properties, edge_weight_df, edge_binary_df

Return type:

[graph-tool graph object, Pandas DataFrame, Pandas DataFrame]

bobaT.plot.plot_subgraph(keep_nodes, network_file, nodes, edge_weights, keep_parents=True, keep_children=True, save_dir='', arrows='straight', show=False, save=True, off_node_arrows_gray=True, weight=3)[source]

Plot a subgraph of the network centered on given nodes

Parameters:
  • keep_nodes (list of str) – list of nodes to keep centered in network; parent and child nodes will also be kept

  • network_file (str) – file path for full network

  • nodes (list of str) – list of all nodes in network

  • edge_weights (Pandas DataFrame) – DataFrame of edge weights to color and weight edges in subgraph with rows = child nodes and cols = parent nodes for each interaction. This is generated by draw_grn or can be replaced by signed_strengths from fitted rules.

  • keep_parents (bool, optional) – Whether to keep parent nodes of keep_nodes, defaults to True

  • keep_children (bool, optional) – Whether to keep child nodes of keep_nodes, defaults to True

  • save_dir (str, optional) – path to save plot of subgraph, defaults to “”

  • arrows (str, optional) – Option for arrow style in {‘curved’, ‘straight’}, defaults to “straight”

  • show (bool, optional) – Whether to show plots, defaults to False

  • save (bool, optional) – Whether to save plots to file {save_dir}/subnetwork{keep_nodes}_{arrows}.pdf, defaults to True

  • off_node_arrows_gray (bool, optional) – Whether the arrows between nodes that do not include the central nodes should be colored (by edge type) or grey, defaults to True

  • weight (int, optional) – Weight multiplier for edges in plot, defaults to 3