# MarkTransform

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 `marks` plugin. [View source](https://github.com/GMOD/jbrowse-components/blob/main/plugins/marks/src/LinearMarkDisplay/markTransformConfigSchema.ts).

One step of a `transform` list, which runs over the region's features in
order, each step reading what the one before it produced. The list follows
Vega's typed transform steps: a step names its `type`, which picks the
schema it takes (ADR-150), and a key belonging to another step is refused
at load.

`filter` keeps the features an expression admits; `formula` writes an
expression's value into a field; `bin` snaps each feature to a
genome-aligned bin, or with `fields` cuts it into a piece per bin it
overlaps; `aggregate` folds each group into one feature with
its summaries; `window` writes each feature with summaries over the
features of its group around it in start order, a moving average over a
fixed number of features; `coverage` replaces the
features with runs of how many
overlap each stretch; `flatten` fans out an array or a record field;
`cells` replaces each aligned row with its runs of match, mismatch and gap
against the reference it was fanned out of and an interbase insertion per
run of reference gaps, with `state`, `base`, `match` and `length` written;
`pileup` writes
each feature's row in a greedy first-fit packing; `mate` yields one
feature per other end a record states, the `mate` a paired adapter fills
in (BEDPE, STAR-Fusion), each VCF `ALT` naming a locus, or a paired read's
`next_ref` and `next_pos`, with `mate.refName`, `mate.start`, `mate.end`
and `mate.mateDirection`, the record's `mateDirection`, the `alt` it
came from and `svType` written, a record with no other end dropped and a
pair of ends yielding one feature.

## Example usage

Count features per bin that follows the zoom:

```js
transform: [
  { type: 'bin', step: 'auto' },
  { type: 'aggregate', ops: [{ op: 'count' }] },
]
```

A moving average of each file's `score` over 101 sites, weighted by read
depth. `groupby` keeps each file's average to its own sites; the `color`
field splits the line into one series per file:

```js
{
  mark: 'line',
  transform: [
    {
      type: 'window',
      groupby: ['source'],
      frame: [-50, 50],
      ops: [{ op: 'mean', field: 'score', weight: 'n_valid_cov', as: 'meth' }],
    },
  ],
  encoding: { y: 'meth', color: { field: 'source' } },
}
```

The fraction of aligned bases matching the reference per bin, no reference
`N` counted, behind a
`cells` step, each run weighted by the bases it puts in the bin:

```js
transform: [
  { type: 'bin', step: 'auto', fields: ['start', 'end'] },
  {
    type: 'aggregate',
    ops: [{ op: 'mean', field: 'match', weight: 'overlap', as: 'identity' }],
  },
]
```

## Config slots

A MarkTransform is one of the types its rows begin with, named by its `type`, and takes only that type's rows: `filter.expr` is written `{ "type": "filter", "expr": ... }`, and a key belonging to another type is refused where the config is read. 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 |
| --- | --- |
| **filter.expr**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | A jexl callback over `feature`, written with its `jexl:` prefix. The features it admits are kept and the rest dropped before the steps behind it run.<br>_callback args:_ `feature` |
| **formula.expr**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | A jexl callback over `feature`, written with its `jexl:` prefix, whose value is written into `as`.<br>_callback args:_ `feature` |
| **formula.as**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'value'</code> | The field the value is written to. |
| **bin.step**<br>[`number`](https://jbrowse.org/jb2/docs/config_guides/slot_types#number) or <code>'auto'</code> = <code>10000</code> | The bin width in bp, aligned to the genome, or `"auto"` for a width that follows the view's zoom — the target of four pixels per bin, snapped up to the next 1/2/5 rung, resolved before the fetch and keyed into it. |
| **bin.field**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'start'</code> | The field placing a feature in a bin: a name, or a dotted path into a structured field (`INFO.END`). A `formula` step in front computes one. |
| **bin.fields**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>[]</code> | An interval's start and end fields, in place of `field`: each feature is cut at the bin edges into one piece per bin it overlaps, and each piece writes `overlap`, the bases of the interval inside its bin, which an `aggregate` op's `weight` reads for a mean per base. Empty bins by `field`. |
| **bin.as**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>['start', 'end']</code> | The two fields the bin's edges are written to. An `aggregate` behind the bin that names no `groupby` groups by these. |
| **aggregate.ops.op**<br>[`stringEnum`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringenum) (count, sum, mean, min, max) = <code>'count'</code> | `count` needs no field; `sum`, `mean`, `min` and `max` read one. |
| **aggregate.ops.field**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | The feature field the op reads, for every op but `count`. |
| **aggregate.ops.weight**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | A field each feature counts by: `count` sums it, `sum` sums the value times it, and `mean` divides that by its sum. `overlap` behind a `bin` over `fields` weights a mean by bases. `min` and `max` read none. Empty counts every feature once. |
| **aggregate.ops.as**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | The output field. When empty, it is `count`, or `<op>_<field>`. |
| **aggregate.groupby**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>[]</code> | The fields whose distinct value sets make the groups. Empty takes the edges the last `bin` before it wrote, in this mark's `transform`, the facet's or the display's, so binning and counting needs no restatement; with none there it folds the whole region into one feature. |
| **aggregate.ops**<br>[list of MarkAggregateOp entries](#slot-aggregateopsop) | The summaries computed for each group. |
| **window.groupby**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>[]</code> | The fields whose distinct value sets make the groups a frame stays inside, within a facet's section. When empty, each section is one group. |
| **window.frame**<br>[`frozen`](https://jbrowse.org/jb2/docs/config_guides/slot_types#frozen) = <code>[-10, 10]</code> | The rows before and after each row that its summaries read, in its group's start order: `[-10, 10]` reads 21 rows, whatever bases they span, and `null` runs to the group's end, so `[null, 0]` is a running total. |
| **window.ops**<br>[list of MarkAggregateOp entries](#slot-aggregateopsop) | The summaries each row is written with, named as an `aggregate`'s are. |
| **coverage.as**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'coverage'</code> | The field each run's depth is written to. |
| **flatten.field**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'subfeatures'</code> | The field fanned out, one feature per element of an array or per entry of a record keyed by name: a name or a dotted path. An element that is a feature, such as a BED12 block or a transcript's exon, hovers and opens as the feature it came from, in every mark; a record or a plain value is a row of its own. |
| **flatten.index**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | The field each element's position in its array is written to. Empty writes none. |
| **flatten.key**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>''</code> | The field each entry's key is written to where the field is a record: the sample of a VCF `samples` entry, the species of a MAF block's `alignments` entry. Empty writes none. |
| **flatten.keepEmpty**<br>[`boolean`](https://jbrowse.org/jb2/docs/config_guides/slot_types#boolean) = <code>false</code> | Keep a feature whose field holds nothing, which is otherwise dropped. |
| **cells.field**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'seq'</code> | The field holding each row's aligned text, gaps as `-`; the reference's is the same field on the feature the row was fanned out of. |
| **pileup.as**<br>[`string`](https://jbrowse.org/jb2/docs/config_guides/slot_types#string) = <code>'row'</code> | The field each feature's row is written to, which a `rect` encoding `row` then reads. |
| **pileup.fields**<br>[`stringArray`](https://jbrowse.org/jb2/docs/config_guides/slot_types#stringarray) = <code>['start', 'end']</code> | The two fields giving the interval it packs. |
| **pileup.padding**<br>[`number`](https://jbrowse.org/jb2/docs/config_guides/slot_types#number) = <code>0</code> | bp of clearance kept between two features sharing a row, so a pileup does not butt its reads together. |

