Viz

viz.py

getPlotTraces(data, key='full', type='lines', div_factor=10010.0, horizontal=False)[source]

This function returns traces for different kinds of plots.

Parameters
  • data – Pandas DataFrame with one variable as data.index (i.e. ‘x’) and all others as columns (i.e. ‘y’).

  • type (str) – ‘lines’, ‘scaled markers’, ‘bars’.

  • div_factor (float) – relative size of the markers.

  • horizontal (bool) – bar orientation.

Returns

list of traces.

Exmaple 1:

result = getPlotTraces(data, key='full', type = 'lines', horizontal=False)

Example 2:

result = getPlotTraces(data, key='full', type = 'scaled markers', div_factor=float(10^3000), horizontal=True)
get_markdown(text, args={})[source]

Converts a given text into a Dash Markdown component. It includes a syntax for things like bold text and italics, links, inline code snippets, lists, quotes, and more. For more information visit https://dash.plot.ly/dash-core-components/markdown.

Parameters
Returns

dash Markdown component.

get_pieplot(data, identifier, args)[source]

This function plots a simple Pie plot.

Parameters
  • data – pandas DataFrame with values to plot as columns and labels as index.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • valueCol (str) – name of the column with the values to be plotted.

  • textCol (str) – name of the column containing information for the hoverinfo parameter.

  • height (str) – height of the plot.

  • width (str) – width of the plot.

Returns

Pieplot figure within the <div id=”_dash-app-content”>.

get_distplot(data, identifier, args)[source]
Parameters
  • data

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • group (str) – name of the column containing the group.

get_boxplot_grid(data, identifier, args)[source]

This function plots a boxplot in a grid based on column values.

Parameters
  • data – pandas DataFrame with columns: ‘x’ values and ‘y’ values to plot, ‘color’ and ‘facet’ (color and facet can be the same).

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • title (str) – plot title.

  • x (str) – name of column with x values.

  • y (str) – name of column with y values.

  • color (str) – name of column with colors

  • facet (str) – name of column specifying grouping

  • height (str) – plot height.

  • width (str) – plot width.

Returns

boxplot figure within the <div id=”_dash-app-content”>.

Example:

result = get_boxplot_grid(data, identifier='Boxplot', args:{"Title":"Boxplot", 'x':'sample', 'y':'identifier', 'color':'group', 'facet':'qc_class', 'axis':'cols'})
get_barplot(data, identifier, args)[source]

This function plots a simple barplot.

Parameters
  • data – pandas DataFrame with three columns: ‘name’ of the bars, ‘x’ values and ‘y’ values to plot.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • title (str) – plot title.

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • height (str) – plot height.

  • width (str) – plot width.

Returns

barplot figure within the <div id=”_dash-app-content”>.

Example:

result = get_barplot(data, identifier='barplot', args={'title':'Figure with Barplot'})
get_histogram(data, identifier, args)[source]

Basic histogram figure allows facets cols and rows

Parameters
  • data – pandas dataframe with at least values to be plotted.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (ditc) – see below.

Arguments
  • x (str) – name of the column containing values to plot in the x axis.

  • y (str) – name of the column containing values to plot in the y axis (if used).

  • color (str) – name of the column that defines how the histogram is colored (if used).

  • facet_row (str) – name of the column to be used as ‘facet’ row (if used).

  • facet_col (str) – name of the column to be used as ‘facet’ column (if used).

  • height (int) – height of the plot

  • width (int) – width of the plot

  • title (str) – plot title.

Returns

dash componenet with histogram figure

Example:

result = get_histogram(data, identifier='histogram', args={'x':'a', 'color':'group', 'facet_row':'sample', 'title':'Facet Grid Plot'})
get_facet_grid_plot(data, identifier, args)[source]

This function plots a scatterplot matrix where we can plot one variable against another to form a regular scatter plot, and we can pick a third faceting variable to form panels along the columns to segment the data even further, forming a bunch of vertical panels. For more information visit https://plot.ly/python/facet-trellis/.

Parameters
  • data – pandas dataframe with format: ‘group’, ‘name’, ‘type’, and ‘x’ and ‘y’ values to be plotted.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (ditc) – see below.

Arguments
  • x (str) – name of the column containing values to plot in the x axis.

  • y (str) – name of the column containing values to plot in the y axis.

  • group (str) – name of the column containing the group.

  • class (str) – name of the column to be used as ‘facet’ column.

  • plot_type (str) – decides the type of plot to appear in the facet grid. The options are ‘scatter’, ‘scattergl’, ‘histogram’, ‘bar’, and ‘box’.

  • title (str) – plot title.

Returns

facet grid figure within the <div id=”_dash-app-content”>.

Example:

result = get_facet_grid_plot(data, identifier='facet_grid', args={'x':'a', 'y':'b', 'group':'group', 'class':'type', 'plot_type':'bar', 'title':'Facet Grid Plot'})
get_ranking_plot(data, identifier, args)[source]

Creates abundance multiplots (one per sample group).

Parameters
  • data – long-format pandas dataframe with group as index, ‘name’ (protein identifiers) and ‘y’ (LFQ intensities) as columns.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below

Arguments
  • group (str) – name of the column containing the group.

  • index (bool) – set to True when multi samples per group. Calculates the mean intensity for each protein in each group.

  • x_title (str) – title of plot x axis.

  • y_title (str) – title of plot y axis.

  • title (str) – plot title.

  • width (int) – plot width.

  • height (int) – plot height.

  • annotations (dict, optional) – dictionary where data points names are the keys and descriptions are the values.

Returns

multi abundance plot figure within the <div id=”_dash-app-content”>.

Example:

result = get_ranking_plot(data, identifier='ranking', args={'group':'group', 'index':'', 'x_title':'x_axis', 'y_title':'y_axis',                                     'title':'Ranking Plot', 'width':100, 'height':150, 'annotations':{'GPT~P24298': 'liver disease', 'CP~P00450': 'Wilson disease'}})
get_scatterplot_matrix(data, identifier, args)[source]

This function pltos a multi scatterplot (one for each unique element in args[‘group’]).

Parameters
  • data – pandas dataframe with four columns: ‘name’ of the data points, ‘x’ and ‘y’ values to plot, and ‘group’ they belong to.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below

Arguments
  • group (str) – name of the column containing the group.

  • title (str) – plot title.

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • height (int) – plot height.

  • width (int) – plot width.

  • annotations (dict, optional) – dictionary where data points names are the keys and descriptions are the values.

Returns

multi scatterplot figure within the <div id=”_dash-app-content”>.

Example:

result = get_scatterplot_matrix(data, identifier='scatter matrix', args={'group':'group', 'title':'Scatter Plot Matrix', 'x_title':'x_axis',                                         'y_title':'y_axis', 'height':100, 'width':100, 'annotations':{'GPT~P24298': 'liver disease', 'CP~P00450': 'Wilson disease'}})
get_simple_scatterplot(data, identifier, args)[source]

Plots a simple scatterplot with the possibility of including in-plot annotations of data points.

Parameters
  • data – long-format pandas dataframe with columns: ‘x’ (ranking position), ‘group’ (original dataframe position), ‘name’ (protein identifier), ‘y’ (LFQ intensity), ‘symbol’ (data point shape) and ‘size’ (data point size).

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • annotations (dict) – dictionary where data points names are the keys and descriptions are the values.

  • title (str) – plot title.

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • height (int) – plot height.

  • width (int) – plot width.

Returns

annotated scatterplot figure within the <div id=”_dash-app-content”>.

Example:

result = get_scatterplot_matrix(data, identifier='scatter plot', args={'annotations':{'GPT~P24298': 'liver disease', 'CP~P00450': 'Wilson disease'}',                                         'title':'Scatter Plot', 'x_title':'x_axis', 'y_title':'y_axis', 'height':100, 'width':100})
get_scatterplot(data, identifier, args)[source]

This function plots a simple Scatterplot.

Parameters
  • data – is a Pandas DataFrame with four columns: “name”, x values and y values (provided as variables) to plot.

  • identifier (str) – is the id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • title (str) – title of the figure.

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • height (int) – plot height.

  • width (int) – plot width.

Returns

scatterplot figure within the <div id=”_dash-app-content”>.

Example:

result = get_scatteplot(data, identifier='scatter plot', 'title':'Scatter Plot', 'x_title':'x_axis', 'y_title':'y_axis', 'height':100, 'width':100}))
get_volcanoplot(results, args)[source]

This function plots volcano plots for each internal dictionary in a nested dictionary.

Parameters
  • results (dict[dict]) – nested dictionary with pairwise group comparisons as keys and internal dictionaries containing ‘x’ (log2FC values), ‘y’ (-log10 p-values), ‘text’, ‘color’, ‘pvalue’ and ‘annotations’ (number of hits to be highlighted).

  • args (dict) – see below.

Arguments
  • fc (float) – fold change threshold.

  • range_x (list) – list with minimum and maximum values for x axis.

  • range_y (list) – list with minimum and maximum values for y axis.

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • colorscale (str) – string for predefined plotly colorscales or dict containing one or more of the keys listed in https://plot.ly/python/reference/#layout-colorscale.

  • showscale (bool) – determines whether or not a colorbar is displayed for a trace.

  • marker_size (int) – sets the marker size (in px).

Returns

list of volcano plot figures within the <div id=”_dash-app-content”>.

Example:

result = get_volcanoplot(results, args={'fc':2.0, 'range_x':[0, 1], 'range_y':[-1, 1], 'x_title':'x_axis', 'y_title':'y_title', 'colorscale':'Blues',                                 'showscale':True, 'marker_size':7})
run_volcano(data, identifier, args={'alpha': 0.05, 'colorscale': 'Blues', 'fc': 2, 'marker_size': 8, 'num_annotations': 10, 'showscale': False, 'x_title': 'log2FC', 'y_title': '-log10(pvalue)'})[source]

This function parsers the regulation data from statistical tests and creates volcano plots for all distinct group comparisons. Significant hits with lowest adjusted p-values are highlighed.

Parameters
  • data – pandas dataframe with format: ‘identifier’, ‘group1’, ‘group2’, ‘mean(group1’, ‘mean(group2)’, ‘log2FC’, ‘std_error’, ‘tail’, ‘t-statistics’, ‘padj_THSD’, ‘effsize’, ‘efftype’, ‘FC’, ‘rejected’, ‘F-statistics’, ‘pvalue’, ‘padj’, ‘correction’, ‘-log10 pvalue’ and ‘Method’.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • alpha (float) – adjusted p-value threshold for significant hits.

  • fc (float) – fold change threshold.

  • colorscale (str or dict) – name of predefined plotly colorscale or dictionary containing one or more of the keys listed in https://plot.ly/python/reference/#layout-colorscale.

  • showscale (bool) – determines whether or not a colorbar is displayed for a trace.

  • marker_size (int) – sets the marker size (in px).

  • x_title (str) – plot x axis title.

  • y_title (str) – plot y axis title.

  • num_annotations (int) – number of hits to be highlighted (if num_annotations = 10, highlights 10 hits with lowest adjusted p-value).

Returns

list of volcano plot figures within the <div id=”_dash-app-content”>.

Example:

result = run_volcano(data, identifier='volvano data', args={'alpha':0.05, 'fc':2.0, 'colorscale':'Blues', 'showscale':False, 'marker_size':6, 'x_title':'log2FC',                             'y_title':'-log10(pvalue)', 'num_annotations':10})
get_heatmapplot(data, identifier, args)[source]

This function plots a simple Heatmap.

Parameters
  • data – is a Pandas DataFrame with the shape of the heatmap where index corresponds to rows and column names corresponds to columns, values in the heatmap corresponds to the row values.

  • identifier (str) – is the id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • format (str) – defines the format of the input dataframe.

  • source (str) – name of the column containing the source.

  • target (str) – name of the column containing the target.

  • values (str) – name of the column containing the values to be plotted.

  • title (str) – title of the figure.

Returns

heatmap figure within the <div id=”_dash-app-content”>.

Example:

result = get_heatmapplot(data, identifier='heatmap', args={'format':'edgelist', 'source':'node1', 'target':'node2', 'values':'score', 'title':'Heatmap Plot'})
get_complex_heatmapplot(data, identifier, args)[source]
get_notebook_network_pyvis(graph, args={})[source]

This function converts a Networkx graph into a PyVis graph supporting Jupyter notebook embedding.

Parameters
  • graph (graph) – networkX graph.

  • args (dict) – see below.

Arguments
  • height (int) – network canvas height.

  • width (int) – network canvas width.

Returns

PyVis graph.

Example:

result = get_notebook_network_pyvis(graph, args={'height':100, 'width':100})
get_notebook_network_web(graph, args)[source]

This function converts a networkX graph into a webweb interactive network in a browser.

Parameters

graph (graph) – networkX graph.

Returns

web network.

network_to_tables(graph)[source]

Creates the graph edge list and node list and returns them as separate Pandas DataFrames.

Parameters

graph – networkX graph used to construct the Pandas DataFrame.

Returns

two Pandas DataFrames.

generate_configuration_tree(report_pipeline, dataset_type)[source]

This function retrieves the analysis pipeline from a dataset .yml file and creates a Cytoscape network, organized hierarchically.

Parameters
  • report_pipeline (dict) – dictionary with dataset type analysis and visualization pipeline (conversion of .yml files to python dictionary).

  • dataset_type (str) – type of dataset (‘clinical’, ‘proteomics’, ‘DNAseq’, ‘RNAseq’, ‘multiomics’).

Returns

new Dash div with title and Cytoscape network, summarizing analysis pipeline.

get_network(data, identifier, args)[source]

This function filters an input dataframe based on a threshold score and builds a cytoscape network. For more information on ‘node_size’ parameter, visit https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.centrality.betweenness_centrality.html and https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.centrality.eigenvector_centrality_numpy.html.

Parameters
  • data – long-format pandas dataframe with at least three columns: source node, target node and value (e.g. weight, score).

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • source (str) – name of the column containing the source.

  • target (str) – name of the column containing the target.

  • cutoff (float) – value threshold for network building.

  • cutoff_abs (bool) – if True will take both positive and negative sides of the cutoff value.

  • values (str) – name of the column containing the values to be plotted.

  • node_size (str) – method used to determine node radius (‘betweenness’, ‘ev_centrality’, ‘degree’).

  • title (str) – plot title.

  • color_weight (bool) – if True, edges in network are colored red if score > 0 and blue if score < 0.

Returns

dictionary with the network in multiple formats: jupyetr-notebook compatible, web brower compatibles, data table, and json.

Example:

result = get_network(data, identifier='network', args={'source':'node1', 'target':'node2', 'cutoff':0.5, 'cutoff_abs':True, 'values':'weight',                             'node_size':'degree', 'title':'Network Figure', 'color_weight': True})
get_network_style(node_colors, color_edges)[source]

This function uses a dictionary of nodes and colors and creates a stylesheet and layout for a network.

Parameters
  • node_colors (dict) – dictionary with node names as keys and colors as values.

  • color_edges (bool) – if True, add edge coloring to stylesheet (red for positive width, blue for negative).

Returns

stylesheet (list of dictionaries specifying the style for a group of elements, a class of elements, or a single element) and layout (dictionary specifying how the nodes should be positioned on the canvas).

visualize_notebook_network(network, notebook_type='jupyter', layout={'height': '700px', 'width': '100%'})[source]

This function returns a Cytoscape network visualization for Jupyter notebooks

Parameters
  • network (tuple) – tuple with two dictionaries: network data and stylesheet (see get_network(data, identifier, args)).

  • notebook_type (str) – the type of notebook where the network will be visualized (currently only jupyter notebook is supported)

  • layout (dict) – specific layout properties (see https://dash.plot.ly/cytoscape/layout)

Returns

cyjupyter.cytoscape.Cytoscape object

Example:

net = get_network(clincorr.dropna(), identifier='corr', args={'source':'node1', 'target':'node2',
                                                    'cutoff':0, 'cutoff_abs':True,
                                                    'values':'weight','node_size':'degree',
                                                    'title':'Network Figure', 'color_weight': True})
visualize_notebook_network(net['notebook'], notebook_type='jupyter', layout={'width':'100%', 'height':'700px'})
visualize_notebook_path(path, notebook_type='jupyter')[source]

This function returns a Cytoscape network visualization for Jupyter notebooks

Parameters
  • object (path) – dash_html_components object with the cytoscape network (returned by get_cytoscape_network())

  • notebook_type (str) – the type of notebook where the network will be visualized (currently only jupyter notebook is supported)

  • layout (dict) – specific layout properties (see https://dash.plot.ly/cytoscape/layout)

Returns

cyjupyter.cytoscape.Cytoscape object

Example:

net = get_cytoscape_network(G, identifier='corr', args={'title':'Cytoscape path',
                                                    'stylesheet':stylesheet,
                                                    'layout': layout})
visualize_notebook_path(net, notebook_type='jupyter')
get_pca_plot(data, identifier, args)[source]

This function creates a pca plot with scores and top “args[‘loadings’]” loadings.

Parameters
  • data (tuple) – tuple with two pandas dataframes: scores and loadings.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below

Arguments
  • loadings (int) – number of features with highest loading values to be displayed in the pca plot

  • title (str) – title of the figure

  • x_title (str) – plot x axis title

  • y_title (str) – plot y axis title

  • height (int) – plot height

  • width (int) – plot width

Returns

PCA figure within the <div id=”_dash-app-content”>.

Example:

result = get_pca_plot(data, identifier='pca', args={'loadings':15, 'title':'PCA Plot', 'x_title':'PC1', 'y_title':'PC2', 'height':100, 'width':100})
get_sankey_plot(data, identifier, args={'font': 12, 'height': 800, 'orientation': 'h', 'source': 'source', 'source_colors': 'source_colors', 'target': 'target', 'target_colors': 'target_colors', 'title': 'Sankey plot', 'valueformat': '.0f', 'weight': 'weight', 'width': 800})[source]

This function generates a Sankey plot in Plotly.

Parameters
  • data – Pandas DataFrame with the format: source target weight.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below

Arguments
  • source (str) – name of the column containing the source

  • target (str) – name of the column containing the target

  • weight (str) – name of the column containing the weight

  • source_colors (str) – name of the column in data that contains the colors of each source item

  • target_colors (str) – name of the column in data that contains the colors of each target item

  • title (str) – plot title

  • orientation (str) – whether to plot horizontal (‘h’) or vertical (‘v’)

  • valueformat (str) – how to show the value (‘.0f’)

  • width (int) – plot width

  • height (int) – plot height

  • font (int) – font size

Returns

dcc.Graph

Example:

result = get_sankey_plot(data, identifier='sankeyplot', args={'source':'source', 'target':'target', 'weight':'weight','source_colors':'source_colors',                                 'target_colors':'target_colors', 'orientation': 'h', 'valueformat': '.0f', 'width':800, 'height':800, 'font':12, 'title':'Sankey plot'})
get_table(data, identifier, args)[source]

This function converts a pandas dataframe into an interactive table for viewing, editing and exploring large datasets. For more information visit https://dash.plot.ly/datatable.

Parameters
  • data – pandas dataframe.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • title (str) – table title.

  • subset – selects columns from dataframe to be used. If None, the entire dataframe is used.

Returns

new Dash div containing title and interactive table.

Example:

result = get_table(data, identifier='table', title='Table Figure', subset = None)
get_multi_table(data, identifier, title)[source]
get_violinplot(data, identifier, args)[source]

This function creates a violin plot for all columns in the input dataframe.

Parameters
  • data – pandas dataframe with samples as rows and dependent variables as columns.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below

Arguments
  • drop_cols (list) – column labels to be dropped from the dataframe.

  • group (str) – name of the column containing the group.

Returns

list of violion plots within the <div id=”_dash-app-content”>.

Example:

result = get_violinplot(data, identifier='violinplot, args={'drop_cols':['sample', 'subject'], 'group':'group'})
create_violinplot(df, variable, group_col='group')[source]

This function creates traces for a simple violin plot.

Parameters
  • df – pandas dataframe with samples as rows and dependent variables as columns.

  • variable ((str)) – name of the column with the dependent variable.

Pram (str) group_col

name of the column containing the group.

Returns

list of traces to be used as data for plotly figure.

Example:

result = create_violinplot(df, 'prptein a', group_col='group')
get_clustergrammer_plot(data, identifier, args)[source]

This function takes a pandas dataframe, calculates clustering, and generates the visualization json. For more information visit https://github.com/MaayanLab/clustergrammer-py.

Parameters
  • data – long-format pandas dataframe with columns ‘node1’ (source), ‘node2’ (target) and ‘weight’

  • identifier (str) – id used to identify the div where the figure will be generated

  • args (dict) – see below

Arguments
  • format (str) – defines if dataframe needs to be converted from ‘edgelist’ to matrix

  • title (str) – plot title

Returns

Dash Div with heatmap plot from Clustergrammer web-based tool

get_parallel_plot(data, identifier, args)[source]

This function creates a parallel coordinates plot, with sample groups as the different dimensions.

Parameters
  • data – pandas dataframe with groups as rows and dependent variables as columns.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • group (str) – name of the column containing the groups.

  • zscore (bool) – if True, calculates the z score of each values in the row, relative to the row mean and standard deviation.

  • color (str) – line color.

  • title (str) – plot title.

Returns

parallel plot figure within <div id=”_dash-app-content”> .

Example:

result = get_parallel_plot(data, identifier='parallel plot', args={'group':'group', 'zscore':True, 'color':'blue', 'title':'Parallel Plot'})
get_WGCNAPlots(data, identifier)[source]

Takes data from runWGCNA function and builds WGCNA plots.

Parameters
  • data – tuple with multiple pandas dataframes.

  • identifier (str) – is the id used to identify the div where the figure will be generated.

Returns

list of dcc.Graph.

getMapperFigure(data, identifier, title)[source]

This function uses the KeplerMapper python package to visualize high-dimensional data and generate a FigureWidget that can be shown or editted. This method is suitable for use in Jupyter notebooks. For more information visit https://kepler-mapper.scikit-tda.org/reference/stubs/kmapper.plotlyviz.plotlyviz.html.

Parameters
  • data – dictionary. Simplicial complex output from the KeplerMapper map method.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • title (str) – plot title.

Returns

plotly FigureWidget within <div id=”_dash-app-content”> .

get_2_venn_diagram(data, identifier, cond1, cond2, args)[source]

This function extracts the exlusive features in cond1 and cond2 and their common features, and build a two-circle venn diagram.

Parameters
  • data – pandas dataframe with features as rows and group identifiers as columns.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • cond1 (str) – identifier of first group.

  • cond2 (str) – identifier of second group.

  • args (dict) – see below.

Arguments
  • colors (dict) – dictionary with cond1 and cond2 as keys, and color codes as values.

  • title (str) – plot title.

Returns

two-circle venn diagram figure within <div id=”_dash-app-content”>.

Example:

result = get_2_venn_diagram(data, identifier='venn2', cond1='group1', cond2='group2', args={'color':{'group1':'blue', 'group2':'red'},                                     'title':'Two-circle Venn diagram'})
plot_2_venn_diagram(cond1, cond2, unique1, unique2, intersection, identifier, args)[source]

This function creates a simple non area-weighted two-circle venn diagram.

Parameters
  • cond1 (str) – label of the first circle.

  • cond2 (str) – label of the second circle.

  • unique1 (int) – number of features exclusive to cond1.

  • unique2 (int) – number of features exclusive to cond2.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Parm int intersection

number of features common to cond1 and cond2.

Arguments
  • colors (dict) – dictionary with cond1 and cond2 as keys, and color codes as values.

  • title (str) – plot title.

Returns

two-circle venn diagram figure within <div id=”_dash-app-content”>.

Example:

result = plot_2_venn_diagram(cond1='group1', cond2='group2', unique1=10, unique2=15, intersection=8, identifier='vennplot',                                     args={'color':{'group1':'blue', 'group2':'red'}, 'title':'Two-circle Venn diagram'})
get_wordcloud(data, identifier, args={'height': 700, 'margin': 1, 'max_font_size': 100, 'max_words': 400, 'stopwords': [], 'width': 700})[source]

This function generates a Wordcloud based on the natural text in a pandas dataframe column.

Parameters
  • data – pandas dataframe with columns: ‘PMID’, ‘abstract’, ‘authors’, ‘date’, ‘journal’, ‘keywords’, ‘title’, ‘url’, ‘Proteins’, ‘Diseases’.

  • identifier (str) – id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • text_col (str) – name of column containing the natural text used to generate the wordcloud.

  • stopwords (list) – list of words that will be eliminated.

  • max_words (int) – maximum number of words.

  • max_font_size (int) – maximum font size for the largest word.

  • margin (int) – plot margin size.

  • width (int) – width of the plot.

  • height (int) – height of the plot.

  • title (str) – plot title.

Returns

wordcloud figure within <div id=”_dash-app-content”>.

Example:

result = get_wordcloud(data, identifier='wordcloud', args={'stopwords':['BACKGROUND','CONCLUSION','RESULT','METHOD','CONCLUSIONS','RESULTS','METHODS'],                                 'max_words': 400, 'max_font_size': 100, 'width':700, 'height':700, 'margin': 1})
get_cytoscape_network(net, identifier, args)[source]

This function creates a Cytoscpae network in dash. For more information visit https://dash.plot.ly/cytoscape.

Parameters
  • net (dict) – dictionary in which each element (key) is defined by a dictionary with ‘id’ and ‘label’ (if it is a node) or ‘source’, ‘target’ and ‘label’ (if it is an edge).

  • identifier (str) – is the id used to identify the div where the figure will be generated.

  • args (dict) – see below.

Arguments
  • title (str) – title of the figure.

  • stylesheet (list[dict]) – specifies the style for a group of elements, a class of elements, or a single element (accepts two keys ‘selector’ and ‘style’).

  • layout (dict) – specifies how the nodes should be positioned on the screen.

Returns

network figure within <div id=”_dash-app-content”>.

save_DASH_plot(plot, name, plot_format='svg', directory='.')[source]

This function saves a plotly figure to a specified directory, in a determined format.

Parameters
  • plot – plotly figure (dictionary with data and layout)

  • name (str) – name of the figure

  • plot_format (str) – suffix of the saved file (‘svg’, ‘pdf’, ‘png’, ‘jpeg’, ‘jpg’)

  • directory (str) – folder where figure is to be saved

Returns

figure saved in directory

Example:

result = save_DASH_plot(plot, name='Plot example', plot_format='svg', directory='/data/plots')
mpl_to_plotly(fig, ci=True, legend=True)[source]
get_km_plot(data, identifier, args)[source]
get_polar_plot(df, identifier, args)[source]

This function creates a Polar plot with data aggregated for a given group.

Parameters
  • df (dataframe) – dataframe with the data to plot

  • identifier (str) – identifier to be used in the app

  • args (dict) – dictionary containing the arguments needed to plot the figure (value_col (value to aggregate), group_col (group by), color_col (color by))

Returns

Dash Graph

Example::

figure = get_polar_plot(df, identifier=’polar’, args={‘value_col’:’intensity’, ‘group_col’:’modifier’, ‘color_col’:’group’})

wgcnaFigures.py

get_module_color_annotation(map_list, col_annotation=False, row_annotation=False, bygene=False, module_colors=[], dendrogram=[])[source]

This function takes a list of values, converts them into colors, and creates a new plotly object to be used as an annotation. Options module_colors and dendrogram only apply when map_list is a list of experimental features used in module eigenegenes calculation.

Parameters
  • map_list (list) – dendrogram leaf labels.

  • col_annotation (bool) – if True, adds color annotations as a row.

  • row_annotation (bool) – if True, adds color annotations as a column.

  • bygene (bool) – determines wether annotation colors have to be reordered to match dendrogram leaf labels.

  • module_colors (list) – dendrogram leaf module color.

  • dendrogram (dict) – dendrogram represented as a plotly object figure.

Returns

Plotly object figure.

Note

map_list and module_colors must have the same length.

get_heatmap(df, colorscale=None, color_missing=True)[source]

This function plots a simple Plotly heatmap.

Parameters
  • df – pandas dataframe containing experimental data, with samples/subjects as rows and features as columns.

  • colorscale (list[list]) – heatmap colorscale (e.g. [[0,’#67a9cf’],[0.5,’#f7f7f7’],[1,’#ef8a62’]]). If colorscale is not defined, will take [[0, ‘rgb(255,255,255)’], [1, ‘rgb(255,51,0)’]] as default.

  • color_missing (bool) – if set to True, plots missing values as grey in the heatmap.

Returns

Plotly object figure.

plot_labeled_heatmap(df, textmatrix, title, colorscale=[[0, 'rgb(0,255,0)'], [0.5, 'rgb(255,255,255)'], [1, 'rgb(255,0,0)']], width=1200, height=800, row_annotation=False, col_annotation=False)[source]

This function plots a simple Plotly heatmap with column and/or row annotations and heatmap annotations.

Parameters
  • df – pandas dataframe containing data to be plotted in the heatmap.

  • textmatrix – pandas dataframe with heatmap annotations as values.

  • title (str) – the title of the figure.

  • colorscale (list[list]) – heatmap colorscale (e.g. [[0,’rgb(0,255,0)’],[0.5,’rgb(255,255,255)’],[1,’rgb(255,0,0)’]])

  • width (int) – the width of the figure.

  • height (int) – the height of the figure.

  • row_annotation (bool) – if True, adds a color-coded column at the left of the heatmap.

  • col_annotation (bool) – if True, adds a color-coded row at the bottom of the heatmap.

Returns

Plotly object figure.

plot_dendrogram_guidelines(Z_tree, dendrogram)[source]

This function takes a dendrogram tree dictionary and its plotly object and creates shapes to be plotted as vertical dashed lines in the dendrogram.

Parameters
  • Z_tree (dict) – dictionary of data structures computed to render the dendrogram. Keys: ‘icoords’, ‘dcoords’, ‘ivl’ and ‘leaves’.

  • dendrogram – dendrogram represented as a plotly object figure.

Returns

List of dictionaries.

plot_intramodular_correlation(MM, FS, feature_module_df, title, width=1000, height=800)[source]

This function uses the Feature significance and Module Membership measures, and plots a multi-scatter plot of all modules against all clinical traits.

Parameters
  • MM – pandas dataframe with module membership data

  • FS – pandas dataframe with feature significance data

  • feature_module_df – pandas DataFrame of experimental features and module colors (use mode=’dataframe’ in get_FeaturesPerModule)

  • title (str) – plot title

  • width (int) – plot width

  • height (int) – plot height

Returns

Plotly object figure.

Example:

plot = plot_intramodular_correlation(MM, FS, feature_module_df, title='Plot', width=1000, height=800):

Note

There is a limit in the number of subplots one can make in Plotly. This function limits the number of modules shown to 5.

plot_complex_dendrogram(dendro_df, subplot_df, title, dendro_labels=[], distfun='euclidean', linkagefun='average', hang=0.04, subplot='module colors', subplot_colorscale=[], color_missingvals=True, row_annotation=False, col_annotation=False, width=1000, height=800)[source]

This function plots a dendrogram with a subplot below that can be a heatmap (annotated or not) or module colors.

Parameters
  • dendro_df – pandas dataframe containing data used to generate dendrogram, columns will result in dendrogram leaves.

  • subplot_df – pandas dataframe containing data used to generate plot below dendrogram.

  • title (str) – the title of the figure.

  • dendro_labels (list) – list of strings for dendrogram leaf nodes labels.

  • distfun (str) – distance measure to be used (‘euclidean‘, ‘maximum‘, ‘manhattan‘, ‘canberra‘, ‘binary‘, ‘minkowski‘ or ‘jaccard‘).

  • linkagefun (str) – hierarchical/agglomeration method to be used (‘single‘, ‘complete‘, ‘average‘, ‘weighted‘, ‘centroid‘, ‘median‘ or ‘ward‘).

  • hang (float) – height at which the dendrogram leaves should be placed.

  • subplot (str) – type of plot to be shown below the dendrogram (´module colors´ or ´heatmap´).

  • subplot_colorscale (list) – colorscale to be used in the subplot.

  • color_missingvals (bool) – if set to True, plots missing values as grey in the heatmap.

  • row_annotation (bool) – if True, adds a color-coded column at the left of the heatmap.

  • col_annotation (bool) – if True, adds a color-coded row at the bottom of the heatmap.

  • width (int) – the width of the figure.

  • height (int) – the height of the figure.

Returns

Plotly object figure.

Dendrogram.py

plot_dendrogram(Z_dendrogram, cutoff_line=True, value=15, orientation='bottom', hang=30, hide_labels=False, labels=None, colorscale=None, hovertext=None, color_threshold=None)[source]

Modified version of Plotly _dendrogram.py that returns a dendrogram Plotly figure object with cutoff line.

Parameters
  • Z_dendrogram (ndarray) – Matrix of observations as array of arrays

  • cutoff_line (boolean) – plot distance cutoff line

  • value (float or int) – dendrogram distance for cutoff line

  • orientation (str) – ‘top’, ‘right’, ‘bottom’, or ‘left’

  • hang (float) – dendrogram distance of leaf lines

  • hide_labels (boolean) – show leaf labels

  • labels (list) – List of axis category labels(observation labels)

  • colorscale (list) – Optional colorscale for dendrogram tree

  • hovertext (list[list]) – List of hovertext for constituent traces of dendrogram clusters

  • color_threshold (double) – Value at which the separation of clusters will be made

Returns

Plotly figure object

Example:

figure = plot_dendrogram(dendro_tree, hang=0.9, cutoff_line=False)
class Dendrogram(Z_dendrogram, orientation='bottom', hang=1, hide_labels=False, labels=None, colorscale=None, hovertext=None, color_threshold=None, width=numpy.inf, height=numpy.inf, xaxis='xaxis', yaxis='yaxis')[source]

Bases: object

Refer to plot_dendrogram() for docstring.

get_color_dict(colorscale)[source]

Returns colorscale used for dendrogram tree clusters.

Parameters

colorscale (list) – colors to use for the plot in rgb format

Return (dict)

default colors mapped to the user colorscale

set_axis_layout(axis_key, hide_labels)[source]

Sets and returns default axis object for dendrogram figure.

Parameters

axis_key (str) – E.g., ‘xaxis’, ‘xaxis1’, ‘yaxis’, yaxis1’, etc.

Return (dict)

An axis_key dictionary with set parameters.

set_figure_layout(width, height, hide_labels)[source]

Sets and returns default layout object for dendrogram figure.

Parameters
  • width (int) – plot width

  • height (int) – plot height

  • hide_labels (boolean) – show leaf labels

Returns

Plotly layout

get_dendrogram_traces(Z_dendrogram, hang, colorscale, hovertext, color_threshold)[source]

Calculates all the elements needed for plotting a dendrogram.

Parameters
  • Z_dendrogram (ndarray) – Matrix of observations as array of arrays

  • hang (float) – dendrogram distance of leaf lines

  • colorscale (list) – Color scale for dendrogram tree clusters

  • hovertext (list) – List of hovertext for constituent traces of dendrogram

Return (tuple)

Contains all the traces in the following order:

  1. trace_list: List of Plotly trace objects for dendrogram tree

  2. icoord: All X points of the dendrogram tree as array of arrays with length 4

  3. dcoord: All Y points of the dendrogram tree as array of arrays with length 4

  4. ordered_labels: leaf labels in the order they are going to appear on the plot

  5. Z_dendrogram[‘leaves’]: left-to-right traversal of the leaves

color_list.py

Code for handling color names and RGB codes.

This module is part of Swampy, and used in Think Python and Think Complexity, by Allen Downey.

http://greenteapress.com

Copyright 2013 Allen B. Downey. Distributed under the GNU General Public License at gnu.org/licenses/gpl.html.

make_color_dict(colors='\n141 211 199\t\tturquoise\n31 120 180\t\tblue\n139 69 19\t\tsaddlebrown\n177 89 40\t\tbrown\n51 160 44\t\tgreen\n255 237 111\t\tyellow\n173 255 47\t\tgreenyellow\n255 0 0\t\tred\n255 255 255\t\twhite\n0 0 0\t\tblack\n255 192 203\t\tpink\n255 0 255\t\tmagenta\n160 32 240\t\tpurple\n210 180 140\t\ttan\n250 128 114\t\tsalmon\n166 206 227\t\tcyan\n25 25 112\t\tmidnightblue\n224 255 255\t\tlightcyan\n153 153 153 \t\tgrey60\n144 238 144\t\tlightgreen\n255 255 224\t\tlightyellow\n65 105 225\t\troyalblue\n139 0 0\t\tdarkred\n0 100 0\t\tdarkgreen\n0 206 209\t\tdarkturquoise\n169 169 169\t\tdarkgrey\n255 165 0\t\torange\n255 140 0\t\tdarkorange\n135 206 235\t\tskyblue\n70 130 180\t\tsteelblue\n175 238 238\t\tpaleturquoise\n238 130 238\t\tviolet\n85 107 47\t\tdarkolivegreen\n139 0 139\t\tdarkmagenta\n190 190 190\t\tgray\n190 190 190\t\tgrey\n')[source]

Returns a dictionary that maps color names to RGB strings.

The format of RGB strings is ‘#RRGGBB’.

read_colors()[source]

Returns color information in two data structures.

The format of RGB strings is ‘#RRGGBB’.

color_dict: map from color name to RGB string rgbs: list of (rgb, names) pairs, where rgb is an RGB code and names is a sorted list of color names

invert_dict(d)[source]

Returns a dictionary that maps from values to lists of keys.

d: dict

returns: dict