dash_bio.OncoPrint Examples and Reference

see OncoPrint in action.

Graph

An example of a default OncoPrint component without any extra properties.

import json
import six.moves.urllib.request as urlreq
from dash_docs.utils import DatasetLoader
from six import PY3
import dash
from dash.dependencies import Input, Output
import dash_bio as dashbio
import dash_html_components as html

app = dash.Dash(__name__)

data = DatasetLoader().load(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'oncoprint_dataset3.json'
)

if PY3:
    data = data.decode('utf-8')

data = json.loads(data)

app.layout = html.Div([
    dashbio.OncoPrint(
        id='dashbio-default-oncoprint',
        data=data
    ),
    html.Div(id='default-oncoprint-output')
])

@app.callback(
    Output('default-oncoprint-output', 'children'),
    Input('dashbio-default-oncoprint', 'eventDatum')
)
def update_output(event_data):
    if event_data is None or len(event_data) == 0:
        return 'There are no event data. Hover over or click on a part \
        of the graph to generate event data.'

    event_data = json.loads(event_data)

    return [
        html.Div('{}: {}'.format(
            key,
            str(event_data[key]).replace('<br>', '\n')
        ))
        for key in event_data.keys()]

if __name__ == '__main__':
    app.run_server(debug=True)

Customization

Colors

Change the color of specific mutations, as well as the background color.

import json
import six.moves.urllib.request as urlreq
from dash_docs.utils import DatasetLoader
import dash_bio as dashbio

data = DatasetLoader().load('https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json')
data = json.loads(data)

dashbio.OncoPrint(
    data=data,
    colorscale={
        'MISSENSE': '#e763fa',
        'INFRAME': '#E763FA'
    },
    backgroundcolor='#F3F6FA'
)

Size And Spacing

Change the height and width of the component, and adjust the spacing between adjacent tracks.

import json
import six.moves.urllib.request as urlreq
from dash_docs.utils import DatasetLoader
import dash_bio as dashbio

data = DatasetLoader().load('https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json')
data = json.loads(data)

dashbio.OncoPrint(
    data=data,
    height=800,
    width=500,
    padding=0.25
)

Legend And Overview

Show or hide the legend and/or overview heatmap.

import json
import six.moves.urllib.request as urlreq
from dash_docs.utils import DatasetLoader
import dash_bio as dashbio

data = DatasetLoader().load('https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json')
data = json.loads(data)

dashbio.OncoPrint(
    data=data,
    showlegend=False,
    showoverview=False
)

OncoPrint Properties

Access this documentation in your Python terminal with:
```python

help(dash_bio.OncoPrint)
```

Our recommended IDE for writing Dash apps is Dash Enterprise’s
Data Science Workspaces,
which has typeahead support for Dash Component Properties.
Find out if your company is using
Dash Enterprise
.

id (string; optional):
The ID of this component, used to identify dash components in
callbacks. The ID needs to be unique to the component.

backgroundcolor (string; default 'rgb(190, 190, 190)'):
Default color for the tracks, in common name, hex, rgb or rgba format.
If left blank, will default to a light grey rgb(190, 190, 190).

colorscale (boolean | dict; optional):
If not None, will override the default OncoPrint colorscale. Default
OncoPrint colorscale same as CBioPortal implementation. Make your own
colrscale as a {‘mutation’: COLOR} dict. Supported mutation keys are
[‘MISSENSE, ‘INFRAME’, ‘FUSION’, ‘AMP’, ‘GAIN’, ‘HETLOSS’, ‘HMODEL’,
‘UP’, ‘DOWN’] Note that this is NOT a standard plotly colorscale.

data (list; optional):
Input data, in CBioPortal format where each list entry is a dict
consisting of ‘sample’, ‘gene’, ‘alteration’, and ‘type’.

eventDatum (dict; optional):
A Dash prop that returns data on clicking, hovering or resizing the
viewer.

height (number | string; default 500):
Height of the OncoPrint. Will disable auto-resizing of plots if set.

padding (number; default 0.05):
Adjusts the padding (as a proportion of whitespace) between two
tracks. Value is a ratio between 0 and 1. Defaults to 0.05 (i.e., 5
percent). If set to 0, plot will look like a heatmap.

range (list; default [None, None]):
Toogles whether or not to show a legend on the right side of the plot,
with mutation information.

showlegend (boolean; default True):
Toogles whether or not to show a legend on the right side of the plot,
with mutation information.

showoverview (boolean; default True):
Toogles whether or not to show a heatmap overview of the tracks.

width (number | string; optional):
Width of the OncoPrint. Will disable auto-resizing of plots if set.

Example Data