# AlignmentsColor

Auto-generated from the config schema in the source. See the [config guide](https://jbrowse.org/jb2/docs/config_guide) for concepts. Provided by the `alignments` plugin. [View source](https://github.com/GMOD/jbrowse-components/blob/main/plugins/alignments/src/LinearAlignmentsDisplay/alignmentsColorConfigSchema.ts).

The alignments displays' `encoding.color`: one color for every read in
`value`, or a field of each read. A preset field, listed below, colors by
its levels or bins, `tags.XX` reads a SAM tag, and any other name reads
the read as a facet over it does: `mateAssembly`, a feature attribute, a
dotted path into one or a `jexl:` expression. A string is the field.
Unlike a feature track, which deals colors in the order values appear, a
tag or attribute with no `scale.domain`, `range` or `unknown` colors each
value by its text alone, so the value keeps its color in every region and
session.
`split`, `spliced`, `pairing`, `svKind` and `svSignal` color nothing:
reads keep their arcs' colors. A facet sections them by the first four, and
the `svSignal` filter keeps or hides SV evidence.
The per-base layer over the reads is `pileup.bases`.

## Example usage

```js
{ type: 'LinearAlignmentsDisplay', encoding: { color: 'strand' } }
```

```js
{
  type: 'LinearAlignmentsDisplay',
  encoding: {
    color: {
      field: 'tags.HP',
      scale: {
        domain: ['1', '2'],
        range: ['#d95f02', '#1b9e77'],
        names: ['Maternal', 'Paternal'],
        invalid: '#cccccc',
      },
    },
  },
}
```

```js
{
  type: 'LinearAlignmentsDisplay',
  encoding: {
    color: { field: 'tags.NM', scale: { type: 'linear', scheme: 'viridis' } },
  },
}
```

```js
{
  type: 'LinearAlignmentsDisplay',
  normalInsertSize: { min: 150, max: 600 },
  encoding: {
    color: {
      field: 'insertSizeAndOrientation',
      scale: { domain: ['RR'], range: ['#d95f02'] },
    },
  },
}
```

## Related links

- **Extended by:** [LGVSyntenyColor](../lgvsyntenycolor)

## Preset fields

A `field` named here paints through its own scale while `scale.type` is unset, and `range` and `names` index its levels in order while `domain` is unwritten. Any other field is ordinal.

| Field | Scale | Levels | Names | Other defaults |
| --- | --- | --- | --- | --- |
| `strand` | ordinal | `1`, `-1` |  |  |
| `mapq` | threshold | `1`, `10`, `30` | MAPQ 0 (multi-mapping), MAPQ 1-9 (low), MAPQ 10-29, MAPQ 30+ (high confidence) | `scheme: cividis`; key "Mapping quality" |
| `firstOfPairStrand` | ordinal | `1`, `-1` |  |  |
| `insertSizeAndOrientation` | ordinal | `short`, `normal`, `long`, `RL`, `RR`, `LL`, `mateUnmapped`, `interchrom`, `splitInverted`, `splitSameStrand`, `unpairedSplitInverted`, `unpairedSplitSameStrand` |  |  |
| `mateRefName` | ordinal |  |  |  |

## Config slots

A setting written to it replaces it whole: a member left out returns to its default. Slot types (`fileLocation`, `frozen`, ...) are explained in the [config slot types reference](https://jbrowse.org/jb2/docs/config_guides/slot_types). Slots a base configuration contributes are listed here too, so this table is the whole surface.

| Slot | Description |
| --- | --- |
| **value**<br>[`maybeColor`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | The fill of every read while no field paints. Arcs and pair orientations keep the theme's colors. Unset, the theme's read color. |
| **scale**<br>[AlignmentsColorScale sub-schema](#slot-scaleinvalid) | How the field's values map to colors, Vega-Lite's scale object. |
| **scale.invalid**<br>[`maybeColor`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | The fill of a read with no value under the field, Vega-Lite's word for a missing value's output: no tag, no attribute, or no mate under `mateRefName`. A `''` in `domain` colors it by its `range` entry instead. |
| **scale.unknown**<br>[`maybeColor`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | The fill of a read whose tag, attribute, mate reference or MAPQ an ordinal `domain` leaves out, d3's `ordinal.unknown`: `unknown: "#999"` beside `domain: ["1", "2"]` on `tags.HP` paints every other haplotype grey, and the key lists them as one row, Other. A field with fixed levels, such as strand, has no value outside them. |
| **scale.names**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>[]</code> | Names for each level or value `range` colors, in the same order, in the key, the hovers and the arc key: `names: ["Maternal", "Paternal"]` beside `domain: ["1", "2"]` on `tags.HP`. |
| **legend**<br>[AlignmentsColorLegend sub-schema](#slot-legendtitle) | The key this channel draws. |
| **field**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | field to color each read by: a preset field by its levels or bins; tags.XX reads a SAM tag; any other name reads as a facet over it does: mateAssembly, a feature attribute, a dotted path or a jexl: expression; split, spliced, pairing, svKind and svSignal color nothing: a facet sections by the first four and the svSignal filter keeps or hides SV evidence |
| **scale.type**<br>[`maybeStringEnum`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) (ordinal, linear, threshold) | ordinal a range color per value; linear a ramp over mapq or a numeric tag or attribute between domainMin and domainMax; threshold the bins domain cuts; unset, threshold over mapq and ordinal over any other field |
| **scale.domain**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>[]</code> | for an ordinal scale, the values that take the range first, in order: a preset field's levels, insertSizeAndOrientation's short, normal, long and RL among them, '' a read with no value, a MAPQ, 255 for unavailable, or a tag's values; for a threshold scale, the cut points; the display's normalInsertSize sets the insert sizes between short and long |
| **scale.range**<br>[`colorArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#colorarray) = <code>[]</code> | CSS colors an ordinal scale hands its domain in order, or with no domain a preset field's levels in their preset order, a threshold scale its bins, or a linear scale's stops, evenly spaced; a level left out keeps its default; empty uses the field's default colors, cividis over mapq's bins, the tag palette or viridis |
| **scale.scheme**<br>[`maybeStringEnum`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) (viridis, magma, inferno, cividis, juicebox, fall, reds, blues, redblue, purpleorange, redgreyblue, redyellowblue) | a named ramp: a ramp scale colors along it; a threshold scale that writes cuts gives each interval one color from end to end; an ordinal scale that lists a domain gives each value one color; range's colors, where it lists any, win over it |
| **scale.reverse**<br>[`maybeBoolean`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | turns the ramp round, so its last color paints the bottom of a ramp's domain or a threshold's lowest interval; unset follows the field's preset, else runs as written |
| **scale.domainMid**<br>[`maybeNumber`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | the value the ramp's middle stop sits at, so a diverging ramp centres somewhere other than the middle of the domain, both sides on one scale: the farther end of the domain reaches its end color and equal distances from the middle take equal colors; unset, the stops are evenly spaced across it |
| **scale.domainMin**<br>[`maybeNumber`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | the bottom of a ramp's domain; unset follows the loaded values |
| **scale.domainMax**<br>[`maybeNumber`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | the top of a ramp's domain; unset follows the loaded values |
| **scale.domainQuantile**<br>[`number`](https://jbrowse.org/jb2/docs/config_guides/slot_types#number) = <code>1</code> | the quantile an open end of a ramp follows over the loaded values: 1 their extremes, 0.99 clips the outermost 1% at each end, each sign measured on its own; a y scale fences at twice that span with fenceQuantile instead<br>_advanced_ |
| **legend.title**<br>[`maybeString`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | key title; unset keeps the display's own heading, "" draws none |
| **legend.descending**<br>[`maybeBoolean`](https://jbrowse.org/jb2/docs/config_guides/slot_types#the-maybe-types) | threshold key lists the highest interval first; unset follows the field's preset, else the lowest first |

