dash_bio.AlignmentChart Examples and Reference

see AlignmentChart in action.

AlignmentChart

An example of a default AlignmentChart component without any extra properties

import dash_bio as dashbio
from dash import Dash, html, Input, Output, callback
import urllib.request as urlreq


app = Dash()


data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

app.layout = html.Div([
    dashbio.AlignmentChart(
        id='my-default-alignment-viewer',
        data=data,
        height=900,
        tilewidth=30,
    ),
    html.Div(id='default-alignment-viewer-output')
])

@callback(
    Output('default-alignment-viewer-output', 'children'),
    Input('my-default-alignment-viewer', 'eventDatum')
)
def update_output(value):
    if value is None:
        return 'No data.'
    return str(value)

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

Customization

Color Scales

Change the colors used for the heatmap.

import dash_bio as dashbio
import urllib.request as urlreq



data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')


dashbio.AlignmentChart(
    data=data,
    colorscale='hydro',
    conservationcolorscale='blackbody',
    height=900,
    tilewidth=30,
)

Show/Hide Barplots

Enable or disable the secondary bar plots for gaps and conservation.

import urllib.request as urlreq
import dash_bio as dashbio



data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

dashbio.AlignmentChart(
    data=data,
    showconservation=False,
    showgap=False,
    height=700,
    tilewidth=30,
)

Tile Size

Change the height and/or width of the tiles.

import urllib.request as urlreq
import dash_bio as dashbio



data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

dashbio.AlignmentChart(
    data=data,
    tilewidth=50,
    height=900,
)

Consensus Sequence

Toggle the display of the consensus sequence at the bottom of the heatmap.

import dash_bio as dashbio
import urllib.request as urlreq



data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

dashbio.AlignmentChart(
    data=data,
    showconsensus=False,
    height=900,
    tilewidth=30,
)

Event

Event Datum

Show data on clicking or hovering the Alignment Chart.

Hover or click on data to see it here.

from dash import Dash, html, Input, Output, callback
import dash_bio as dashbio
import urllib.request as urlreq


import json

app = Dash()



data = urlreq.urlopen(
    'https://git.io/alignment_viewer_p53.fasta'
).read().decode('utf-8')

app.layout = html.Div([
    dashbio.AlignmentChart(
        id='alignment-viewer-eventDatum-usage',
        data=data,
        height=900,
        tilewidth=30,
    ),
    html.P('Hover or click on data to see it here.'),
    html.Div(id='alignment-viewer-eventDatum-usage-output')
])

@callback(
    Output('alignment-viewer-eventDatum-usage-output', 'children'),
    Input('alignment-viewer-eventDatum-usage', 'eventDatum')
)
def update_output(value):
    if value is None:
        return 'No data.'

    value = json.loads(value)

    if len(value.keys()) == 0:
        return 'No event data to display.'

    return [
        html.Div('- {}: {}'.format(key, value[key]))
        for key in value.keys()
    ]

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

AlignmentChart Properties

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

help(dash_bio.AlignmentChart)
```

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 across all of the components in
an app.

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

data (string; optional):
Input data, either in FASTA or Clustal format.

extension (string; default 'fasta'):
Format type of the input data, either in FASTA or Clustal.

colorscale (string | dict; default 'clustal2'):
Colorscale in ‘buried’, ‘cinema’, ‘clustal’, ‘clustal2’, ‘helix’,
‘hydrophobicity’ ‘lesk’, ‘mae’, ‘nucleotide’, ‘purine’, ‘strand’,
‘taylor’, ‘turn’, ‘zappo’, or your own colorscale as a {‘nucleotide’:
COLOR} dict. Note that this is NOT a standard plotly colorscale.

opacity (number | string; optional):
Opacity of the main plot as a value between 0 and 1.

textcolor (string; optional):
Color of the nucleotide labels, in common name, hex, rgb or rgba
format. If left blank, handled by the colorscale automatically.

textsize (number | string; default 10):
Size of the nucleotide labels, as a number.

showlabel (boolean; default True):
Toggles displaying sequence labels at left of alignment.

showid (boolean; default True):
Toggles displaying sequence IDs at left of alignment.

showconservation (boolean; default True):
Enables the display of conservation secondary barplot where the most
conserved nucleotides or amino acids get greater bars.

conservationcolor (string; optional):
Color of the conservation secondary barplot, in common name, hex, rgb
or rgba format.

conservationcolorscale (string | list; default 'Viridis'):
Colorscale of the conservation barplot, in Plotly colorscales (e.g.
‘Viridis’) or as custom Plotly colorscale under a list format. Note
that this conservationcolorscale argument does NOT follow the same
format as the colorscale argument.

conservationopacity (number | string; optional):
Opacity of the conservation secondary barplot as a value between 0 and
1.

conservationmethod (a value equal to: ‘conservation’ or ‘entropy’; default 'entropy'):
Whether to use most conserved ratio (MLE) ‘conservation’ or normalized
entropy ‘entropy’ to determine conservation, which is a value between
0 and 1 where 1 is most conserved.

correctgap (boolean; default True):
Whether to normalize the conservation barchart By multiplying it
elementwise with the gap barchart, as to lower the conservation values
across sequences regions with many gaps.

showgap (boolean; default True):
Enables the display of gap secondary barplot where the sequence
regions with the fewest gaps get the greatest bars.

gapcolor (string; default 'grey'):
Color of the gap secondary barplot, in common name, hex, rgb or rgba
format.

gapcolorscale (string | list; optional):
Colorscale of the gap barplot, in Plotly colorscales (e.g. ‘Viridis’)
or as custom Plotly colorscale under a list format. Note that this
conservationcolorscale argument does NOT follow the same format as the
colorscale argument.

gapopacity (number | string; optional):
Opacity of the gap secondary barplot as a value between 0 and 1.

groupbars (boolean; default False):
If both conservation and gap are enabled, toggles whether to group
bars or to stack them as separate subplots. No effect if not both gap
and conservation are shown.

showconsensus (boolean; default True):
Displays toggling the consensus sequence, where each nucleotide in the
consensus sequence is the argmax of its distribution at a set
nucleotide.

tilewidth (number; default 16):
Sets how many pixels each nucleotide/amino acid on the Alignment Chart
takes up horizontally. The total number of tiles (numtiles) seen
horizontally is automatically determined by rounding the Viewer width
divided by the tile width. the Viewwer width divided by the tile
witdth.

tileheight (number; default 16):
Sets how many pixels each nucleotide/amino acid on the Alignment Chart
takes up vertically. If enabled, set height dynamically.

overview (a value equal to: ‘heatmap’, ‘slider’ or ‘none’; default 'heatmap'):
Toggles whether the overview should be a heatmap, a slider, or none.

numtiles (number; optional):
Sets how many tiles to display across horitontally. If enabled,
overrides tilewidth and sets the amount of tiles directly based off
that value.

scrollskip (number; default 10):
If overview is set to ‘scroll’, determines how many tiles to skip with
each slider movement. Has no effect if scroll is not enabled (such as
with overview or none).

tickstart (number | string; default 1):
Determines where to start annotating the first tile. If let blank will
be automatically determined by Plotly. Equivalent to Plotly’s tick0
property. Does not function if overview mode ‘slider’ is applied.
(Current bug).

ticksteps (number | string; default 6):
Determines at what interval to keep annotating the tiles. If left
blank will be automatially determined by Plotly. Equivalent to
Plotly’s dtick property. Does not function if overview mode ‘slider’
is applied. (Current bug).

width (number | string; optional):
Width of the Viewer. Property takes precedence over tileswidth and
numtiles if either of them is set.

height (number | string; optional):
Width of the Viewer. Property takes precedence over tilesheight if
both are set.

sequenceIds (list; optional):
Sequences ids to display.

loading_state (dict; optional):
Object that holds the loading state object coming from dash-renderer.

loading_state is a dict with keys:

  • component_name (string; optional):
    Holds the name of the component that is loading.

  • is_loading (boolean; optional):
    Determines if the component is loading or not.

  • prop_name (string; optional):
    Holds which property is loading.

Example Data