# Highlights

A highlight is a translucent band over a genomic region. Every linear genome
view (LGV) and dotplot showing the region's assembly draws it, and the session
saves it, so a shared link contains it. The highlight list, opened from **Tools
→ Highlights** or **Highlights → Open highlight list** in an LGV's menu, holds
every highlight with a link back to it.

<Figure caption="Three labeled highlights over the beta-globin cluster, each band its own color." src="/img/highlights_beta_globin.png"/>

Session spec, on config <https://jbrowse.org/code/jb2/main/test_data/config_demo.json>:

```json
{
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr11:5,208,000-5,300,000",
      "tracks": [
        {
          "trackId": "mane_hg38",
          "height": 80
        },
        {
          "trackId": "encodeCcreCombined",
          "height": 50,
          "labels": {
            "name": {
              "show": false
            }
          }
        },
        {
          "trackId": "hg38.100way.phyloP100way",
          "height": 100
        }
      ],
      "highlight": [
        {
          "refName": "chr11",
          "start": 5225000,
          "end": 5234600,
          "color": "rgba(214, 39, 40, 0.18)",
          "label": "adult: HBB, HBD"
        },
        {
          "refName": "chr11",
          "start": 5248000,
          "end": 5255000,
          "color": "rgba(31, 119, 180, 0.18)",
          "label": "fetal: HBG1, HBG2"
        },
        {
          "refName": "chr11",
          "start": 5275500,
          "end": 5292000,
          "color": "rgba(44, 160, 44, 0.18)",
          "label": "LCR"
        }
      ]
    }
  ]
}
```

## Making a highlight

- Drag across the scalebar at the top of an LGV and pick **Highlight region**.
- On a dotplot, drag a rectangle and pick **Highlight region**: the horizontal
  span bands the horizontal axis and the vertical span the vertical one.
- Press `Ctrl`/`Cmd` + `Shift` + `D` to highlight the region in view.
- Import a BED or TSV file from the highlight list's menu.
- Pass them in a URL, a session or code, [below](#setting-highlights-in-code).

<Figure caption="Drag across the top of an LGV and pick 'Highlight region.'" src="/img/highlight_list_create.png"/>

Session spec, on config <https://jbrowse.org/code/jb2/main/test_data/config_demo.json>:

```json
{
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg19",
      "loc": "chr10:89,613,000-89,740,000",
      "tracks": [
        "ncbi_gff_hg19"
      ]
    }
  ]
}
```

<Video src="/media/ui/highlight_region.mp4" caption="A span highlighted from the scalebar, named in the highlight list, and returned to from the list's link." />

Open the session this video starts in: <https://jbrowse.org/code/jb2/main/?config=test_data%2Fconfig_demo.json&session=spec-%7B%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg19%22%2C%22loc%22%3A%22chr10%3A89%2C613%2C000-89%2C740%2C000%22%2C%22tracks%22%3A%5B%22ncbi_gff_hg19%22%5D%7D%5D%7D&sessionName=Screenshot>

## The highlight list

- The link in the Location column navigates the focused LGV on that assembly, or
  opens one, zoomed out a little for context. `Ctrl`/`Cmd` + `Shift` + `M`
  navigates to the newest highlight.
- Click a Label cell and type to name a highlight. **Show… → Show highlight
  labels** in an LGV's menu shows or hides the names on the bands in every view.
- The Color column sets a band's color. Tick rows to recolor or delete several
  at once.

<Figure caption="A label typed into the highlight list names the band on the LGV." src="/img/highlight_list_edit_label.png"/>

Session spec, on config <https://jbrowse.org/code/jb2/main/test_data/config_demo.json>:

```json
{
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg19",
      "loc": "chr1:1-20,000",
      "tracks": [
        "ncbi_gff_hg19"
      ]
    }
  ]
}
```

## Showing, hiding and removing

**Show highlights** hides or shows the bands in every view at once. An LGV has
it under **Show…**, a dotplot has it at the top of its menu, and the list has it
in its menu. Making or recoloring a highlight shows them again.

A band's chip menu has **Dismiss highlight**. In the list, tick rows and press
the delete icon.

## Export and import

Export writes the ticked highlights, or all of them, as BED (one file per
assembly, 0-based starts) or TSV (one file with `assembly_name` and `color`
columns, 1-based starts). Only TSV keeps colors. Import reads either and adds to
the list; a BED file takes the assembly picked in the dialog.

## Setting highlights in code

Each form below takes a locstring or an object; an object adds `color` (used
as-is, alpha included) and `label`, and an entry without `assemblyName` takes
the view's assembly.

**In a URL**, [`&highlight=`](https://jbrowse.org/jb2/docs/urlparams#highlight) beside `&assembly=` and
`&loc=`, several separated by spaces (`%20`):
[live link](https://jbrowse.org/code/jb2/main/?config=test_data/volvox/config.json&assembly=volvox&loc=ctgA:1-20000&highlight=ctgA:5000-8000%20ctgA:12000-13000).

```text
&assembly=volvox&loc=ctgA:1-20000&highlight=ctgA:5000-8000
&highlight={"refName":"ctgA","start":5000,"end":8000,"color":"rgba(240,128,128,0.3)","label":"my region"}
```

**In a session spec or `defaultSession`**, as `highlight` on a view. The dotplot
takes the same key ([dotplot highlights](https://jbrowse.org/jb2/docs/urlparams#dotplot-highlights)):

```json
{
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "volvox",
      "loc": "ctgA:1-20000",
      "highlight": ["ctgA:5000-8000"]
    }
  ]
}
```

**In a saved session**, the session's `highlights` list, where each entry names
its assembly:

```json
"highlights": [
  { "assemblyName": "volvox", "refName": "ctgA", "start": 5000, "end": 8000, "label": "my region" }
]
```

**In an embedded LGV or from a plugin**, `highlight` in `createViewState` at
launch ([Embedded components](https://jbrowse.org/jb2/docs/embedded_components)); after that, `session.addHighlight` takes
an object like the one above, `session.setHighlights` replaces the list (`[]`
clears it), and `removeHighlight` and `updateHighlight` take an entry of
`session.highlights`. A view's `highlights` lists the ones on the assemblies the
view displays. The [BaseSessionModel reference](https://jbrowse.org/jb2/docs/models/basesessionmodel)
has the rest.

