# dash_bioSequenceViewer Examples and Reference

see SequenceViewer in action.

## SequenceViewer

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

110

####

1
41
81
MALWMRLLPL LALLALWGPD PAAAFVNQHL CGSHLVEALY
LVCGERGFFY TPKTRREAED LQVGQVELGG GPGAGSLQPL
ALEGSLQKRG IVEQCCTSIC SLYQLENYCN
There is no mouse selection.

    app <- Dash$new()

    library(readr)
    library(dashBio)

    fasta_str = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAED
    LQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

    app$layout(htmlDiv(list(
        dashbioSequenceViewer(
            id = 'default-sequence-viewer',
            sequence = fasta_str
        ),
        htmlDiv(id = 'default-sequence-viewer-output')
    )))

    app$callback(
        output(id = "default-sequence-viewer-output", property = "children"),
        params = list(
            input(id = 'default-sequence-viewer', property = "mouseSelection")
        ),
        update_output <- function(value) {
            if ((length(value) == 0)| is.null(value[[1]])) {
                return("There is no mouse selection.")
            }
            else{
                return(sprintf("The mouse selection is %s", value$selection))
            }
        }
    )

    app$run_server()

## Customization

### Line Length And Line Numbers

Change the characters per line, and toggle the display of line numbers.

110

####

MALWMRLLPL LALLALWGPD
PAAAFVNQHL CGSHLVEALY
LVCGERGFFY TPKTRREAED
LQVGQVELGG GPGAGSLQPL
ALEGSLQKRG IVEQCCTSIC
SLYQLENYCN

    library(dashBio)

    fasta_str = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAED
    LQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

    dashbioSequenceViewer(
      id = "sequence-viewer-lines",
      sequence = fasta_str,
      showLineNumbers = FALSE,
      charsPerLine = 20
    )

### Subsequence Selection

Highlight a part of the sequence with a defined color.

110

####

1
41
81
MALWMRLLPL LALLALWGPD PAAAFVNQHL CGSHLVEALY
LVCGERGFFY TPKTRREAED LQVGQVELGG GPGAGSLQPL
ALEGSLQKRG IVEQCCTSIC SLYQLENYCN

    library(dashBio)

    fasta_str = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAED
    LQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

    dashbioSequenceViewer(
        id = "sequence-viewer-subsequence",
        sequence = fasta_str,
        selection = list(10, 20, "green")
    )

### Toolbar

Display a toolbar to change the line length from the component itself.

110

####

Char per line
1
41
81
MALWMRLLPL LALLALWGPD PAAAFVNQHL CGSHLVEALY
LVCGERGFFY TPKTRREAED LQVGQVELGG GPGAGSLQPL
ALEGSLQKRG IVEQCCTSIC SLYQLENYCN

    library(dashBio)

    fasta_str = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAED
    LQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

    dashbioSequenceViewer(
        id = "sequence-viewer-toolbar",
        sequence = fasta_str,
        toolbar = TRUE
    )

### Title And Badge

Show a title or a badge with the nucleotide or amino acid count of the protein.

#### Insulin

1
41
81
MALWMRLLPL LALLALWGPD PAAAFVNQHL CGSHLVEALY
LVCGERGFFY TPKTRREAED LQVGQVELGG GPGAGSLQPL
ALEGSLQKRG IVEQCCTSIC SLYQLENYCN

    library(dashBio)

    fasta_str = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAED
    LQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

    dashbioSequenceViewer(
        id = "sequence-viewer-title",
        sequence = fasta_str,
        title = "Insulin",
        badge = FALSE
    )

## SequenceViewer Properties

> 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` (character; optional): The ID used to identify this component in Dash callbacks.

`sequence` (character; default `'-'`): The amino acid sequence that will be displayed.

`showLineNumbers` (logical; default `TRUE`): The option of whether or not to display line numbers.

`wrapAminoAcids` (logical; 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` (numeric; default `40`): The number of amino acids that will display per line.

`toolbar` (logical; 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` (logical; default `TRUE`): The option of whether or not to include a search bar in the header. This supports regex.

`title` (character; default `''`): A string that displays at the top of the component.

`sequenceMaxHeight` (character; default `'400px'`): The maximum height of the sequence.

`badge` (logical; 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 where each item is a named list; 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 where each item is a named list with keys:

- `bgcolor` (character; optional)

- `color` (character; optional)

- `end` (numeric; optional)

- `onclick` (optional)

- `start` (numeric; optional)

- `tooltip` (character; optional)

- `underscore` (logical; optional)

`legend` (list where each item is a named list; optional): A legend corresponding to the color codes above (optionally displayed).

`legend` is a list where each item is a named list with keys:

- `color` (character; optional)

- `name` (character; optional)

- `underscore` (logical; optional)

`coverageClicked` (numeric; optional): Contains the index of the section that was clicked last in the coverage list supplied.

`mouseSelection` (named list; 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 named list with keys:

- `end` (numeric; optional)

- `selection` (character; optional)

- `start` (numeric; optional)

`subpartSelected` (list where each item is a named list; optional): A list of the subparts selected using the "search" function or the "selection" property.

`subpartSelected` is a list where each item is a named list with keys:

- `end` (numeric; optional)

- `sequence` (character; optional)

- `start` (numeric; optional)

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

`loading_state` is a named list with keys:

- `component_name` (character; optional): Holds the name of the component that is loading.

- `is_loading` (logical; optional): Determines if the component is loading or not.

- `prop_name` (character; optional): Holds which property is loading.

## Example Data

- https://github.com/plotly/datasets/blob/master/Dash_Bio/Genetic/sequence_viewer_P01308.fasta
- Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome
- Human Genome Resources at NCBI