An example of a default SequenceViewer component without any extra properties.
import urllib.request as urlreq
from dash import Dash, dcc, html, Input, Output, callback
import dash_bio as dashbio
from dash_bio.utils import protein_reader
app = Dash()
fasta_str = urlreq.urlopen(
'https://git.io/sequence_viewer_P01308.fasta'
).read().decode('utf-8')
seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str, is_datafile=False)[0]['sequence']
app.layout = html.Div([
dashbio.SequenceViewer(
id='default-sequence-viewer',
sequence=seq
),
html.Div(id='default-sequence-viewer-output')
])
@callback(
Output('default-sequence-viewer-output', 'children'),
Input('default-sequence-viewer', 'mouseSelection')
)
def update_output(value):
if value is None or len(value) == 0:
return 'There is no mouse selection.'
return 'The mouse selection is {}.'.format(value['selection'])
if __name__ == '__main__':
app.run(debug=True)
Change the characters per line, and toggle the display of line numbers.
import urllib.request as urlreq
import dash_bio as dashbio
from dash_bio.utils import protein_reader
fasta_str = urlreq.urlopen(
'https://git.io/sequence_viewer_P01308.fasta'
).read().decode('utf-8')
seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str, is_datafile=False)[0]['sequence']
dashbio.SequenceViewer(
id='sequence-viewer-lines',
sequence=seq,
showLineNumbers=False,
charsPerLine=20
)
Highlight a part of the sequence with a defined color.
import urllib.request as urlreq
import dash_bio as dashbio
from dash_bio.utils import protein_reader
fasta_str = urlreq.urlopen(
'https://git.io/sequence_viewer_P01308.fasta'
).read().decode('utf-8')
seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str, is_datafile=False)[0]['sequence']
dashbio.SequenceViewer(
id='sequence-viewer-selection',
sequence=seq,
selection=[10, 20, 'green']
)
Display a toolbar to change the line length from the component itself.
import urllib.request as urlreq
import dash_bio as dashbio
from dash_bio.utils import protein_reader
fasta_str = urlreq.urlopen(
'https://git.io/sequence_viewer_P01308.fasta'
).read().decode('utf-8')
seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str, is_datafile=False)[0]['sequence']
dashbio.SequenceViewer(
id='sequence-viewer-toolbar',
sequence=seq,
toolbar=True
)
Show a title or a badge with the nucleotide or amino acid count of the protein.
import urllib.request as urlreq
import dash_bio as dashbio
from dash_bio.utils import protein_reader
fasta_str = urlreq.urlopen(
'https://git.io/sequence_viewer_P01308.fasta'
).read().decode('utf-8')
seq = protein_reader.read_fasta(datapath_or_datastring=fasta_str, is_datafile=False)[0]['sequence']
dashbio.SequenceViewer(
id='sequence-viewer-titlebadge',
sequence=seq,
title='Insulin',
badge=False
)
Access this documentation in your Python terminal with:
```pythonhelp(dash_bio.SequenceViewer)
```
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 used to identify this component in Dash callbacks.
sequence
(string; default '-'
):
The amino acid sequence that will be displayed.
showLineNumbers
(boolean; default True
):
The option of whether or not to display line numbers.
wrapAminoAcids
(boolean; default True
):
The option of whether or not to display the list of amino acids as
broken up into separate lines of a fixed length set by charsPerLine.
charsPerLine
(number; default 40
):
The number of amino acids that will display per line.
toolbar
(boolean; default False
):
The option of whether or not to display a toolbar at the top that
allows the user to choose the number of letters per line.
search
(boolean; default True
):
The option of whether or not to include a search bar in the header.
This supports regex.
title
(string; default ''
):
A string that displays at the top of the component.
sequenceMaxHeight
(string; default '400px'
):
The maximum height of the sequence.
badge
(boolean; default True
):
The option of whether or not to display a badge showing the amino acid
count at the top of the component beside the title.
selection
(optional):
A highlighted section of the sequence; the color of the highlight can
also be defined. Takes a list of format [min, max, color] where min is
a number that represents the starting index of the selection, max is a
number that represents the stopping index of the selection, and color
is a string that defines the highlight color. Cannot be used at the
same time as coverage.
coverage
(list of dicts; optional):
A coverage of the entire sequence; each section of the sequence can
have its own text color, background color, tooltip (on hover), and an
optional underscore. The props start and end represent the beginning
and terminating indices of the section in question. Cannot be used at
the same time as selection.
coverage
is a list of dicts with keys:
bgcolor
(string; optional)
color
(string; optional)
end
(number; optional)
onclick
(optional)
start
(number; optional)
tooltip
(string; optional)
underscore
(boolean; optional)
legend
(list of dicts; optional):
A legend corresponding to the color codes above (optionally displayed).
legend
is a list of dicts with keys:
color
(string; optional)
name
(string; optional)
underscore
(boolean; optional)
coverageClicked
(number; optional):
Contains the index of the section that was clicked last in the
coverage list supplied.
mouseSelection
(dict; optional):
Contains information about the subsequence selected by the mouse.
Start and end refer to the initial and final indices, respectively, of
the subsequence, and “selection” contains the string that is selected.
mouseSelection
is a dict with keys:
end
(number; optional)
selection
(string; optional)
start
(number; optional)
subpartSelected
(list of dicts; optional):
A list of the subparts selected using the “search” function or the
“selection” property.
subpartSelected
is a list of dicts with keys:
end
(number; optional)
sequence
(string; optional)
start
(number; optional)
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.