OncoPrint Examples and Reference


Default OncoPrint

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

import json
import six.moves.urllib.request as urlreq
from six import PY3

import dash
import dash_bio as dashbio
import dash_html_components as html


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

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

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

data = json.loads(data)

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


@app.callback(
    dash.dependencies.Output('oncoprint-output', 'children'),
    [dash.dependencies.Input('my-dashbio-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)

Colors

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

import json
import six.moves.urllib.request as urlreq

import dash_bio as dashbio


data = urlreq.urlopen("https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json").read()
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

import dash_bio as dashbio


data = urlreq.urlopen("https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json").read()
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

import dash_bio as dashbio


data = urlreq.urlopen("https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/oncoprint_dataset3.json").read()
data = json.loads(data)

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

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

help(dash_bio.OncoPrint)
```

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 null, 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 [null, null]): .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.