@jbrowse/wiggle-core
Auto-generated from exported functions tagged #api in the source. See
imports and re-exports for how to
import these from a plugin.
autoscaleDomainFromSpans
The domain the visible instances autoscale to: at a quantile of 1 their
extremes, stats; below it those extremes fenced by quantileExtent's
ends (fenceOutliers), the bottom read off the lows and the top off the
highs less the zeros where any is positive, so whiskers open to their
spread, a sparse window's empty bins lower no top, and a window of nothing
above 0 keeps the top it has.
import { autoscaleDomainFromSpans } from '@jbrowse/wiggle-core'
function autoscaleDomainFromSpans(opts: {
stats: ScoreStats
quantile: number
zero: boolean
spans: ScoreSpan[]
}): [number, number]getEffectiveScores
The per-feature array a summary field names: minScore and maxScore the
bins' stored extremes, anything else score, the bins' mean.
import { getEffectiveScores } from '@jbrowse/wiggle-core'
function getEffectiveScores(
data: {
featureScores: Float32Array
featureMinScores: Float32Array
featureMaxScores: Float32Array
},
field: 'maxScore' | 'minScore' | 'score',
): Float32Array<ArrayBufferLike>getNiceDomain
Rounds a domain to "nice" endpoints. zero reaches a linear or symlog
domain to 0 (encoding.y.scale.zero, ADR-182); a log domain has no 0, so a min at
or below it floors to a positive value and a positive min stays where the
data put it. An end given an explicit bounds value keeps that value
exactly — only an autoscaled end is rounded. A log scale's floor still
takes precedence over a bound it cannot hold, and the log-floor rule
reports that.
The result never descends and never collapses: a bound that would put min
above max widens the other end instead, and one value in view widens
away from itself, so no consumer has to guess what a backwards or a flat
domain means.
import { getNiceDomain } from '@jbrowse/wiggle-core'
function getNiceDomain(opts: {
scaleType: ScaleType
domain: readonly [number, number]
bounds: readonly [number | undefined, number | undefined]
zero: boolean
}): [number, number]getNiceScale
Returns a niced {min, max} domain for a maximum score value.
Uses log base-2 when useLogScale is true (domain is clamped to [1, max]).
import { getNiceScale } from '@jbrowse/wiggle-core'
function getNiceScale(
maxScore: number,
useLogScale?: boolean,
): { min: number; max: number }getScale
Builds a d3 scale (linear/log/symlog) from a ScaleOpts, nicing the domain
unless nice: false is set because the domain is already the one being
drawn with.
import { getScale } from '@jbrowse/wiggle-core'
function getScale(opts: ScaleOpts): ScaleregisterScoreAxisWidget
Registers the drawer widget the quantitative tracks' "Y axis..." row opens. The wiggle plugin calls it once; alignments and the mark display open it by name.
import { registerScoreAxisWidget } from '@jbrowse/wiggle-core/scoreAxisWidget'
function registerScoreAxisWidget(pluginManager: PluginManager): voidresolveSymlogConstant
The symlog constant actually used for a domain. 0 (the config default)
means "pick one from the domain": a thousandth of its largest magnitude, so
the log-ish part of the curve covers the top three decades of whatever the
track holds and the linear knee sits below the data rather than through it.
The alternative — d3's default of 1 — is log(x + 1), which is fine for read
depth and useless for anything living below 1, because the entire domain then
falls in the linear part of the curve. A p-value track configured that way is
just a linear track wearing a log label, which is the reason this is resolved
rather than hard-coded.
import { resolveSymlogConstant } from '@jbrowse/wiggle-core'
function resolveSymlogConstant(
min: number,
max: number,
configured: number,
): numberscoreRuleMarks
Screen y for each rule that falls inside the plotted domain, dropping the rest.
Out-of-domain is a real case rather than a guard: the domain is whatever autoscale resolved for the visible data, so panning to a quiet stretch can put a rule above everything on screen, and a rule pinned to the top edge there reads as "the whole view is over the line".
normalize is the display's OWN score normalizer — the same one the renderer
draws with. It is a parameter rather than a linear interpolation of the domain
because the axis need not be linear: on a log or symlog track, placing a rule
at (value - min) / (max - min) puts the line somewhere the data it is meant
to be read against is not.
box is likewise the caller's own — hand it the same {yTop, yBottom} the
display's ticks were built with (a YScaleTicks satisfies it). A box
recomputed here would place rules off the ticks of any band that lays its
axis out differently, and the alignments coverage band does. A box carrying
its own valueToY places the rules by that instead of normalize: the read
cloud's ladder, whose band flips when it hangs down.
import { scoreRuleMarks } from '@jbrowse/wiggle-core'
function scoreRuleMarks(opts: {
rules: readonly ValueScaleRule[]
domain: [number, number] | undefined
box: Pick<YScaleTicks, 'valueToY' | 'yBottom' | 'yTop'>
normalize: (score: number) => number
}): ScoreRuleMark[]ScoreSpan
One block's worth of values to fold into a domain, whatever packed them: a
wiggle source's interleaved featurePositions and its summary arrays, or a
mark layer's separate x/x2 and its one y lane. starts[i * stride] and
ends[i * stride + endOffset] give instance i's span, and low and high
the two ends of its value, one array where the packer ships a single scalar.
import type { ScoreSpan } from '@jbrowse/wiggle-core'
interface ScoreSpan {
count: number
starts: Uint32Array
ends: Uint32Array
stride: number
endOffset: number
low: Float32Array
high: Float32Array
visStart?: number
visEnd?: number
sortedBins: boolean
row?: Uint32Array
drawnKeys?: Uint8Array
}ungroupedAutoscaleViews
What a static host answers ScoreAxisMixin for its group: none, whatever
scale.share names, since it stands in no view and has no peers to union
with, so its axis autoscales over its own range alone.
import { ungroupedAutoscaleViews } from '@jbrowse/wiggle-core'
function ungroupedAutoscaleViews(): {
readonly autoscaleGroup: string | undefined
}visibleStats
The stats of what the settled blocks show, walked once so a display can
read both its autoscaled range and the values in view off one getter.
undefined while there is nothing to scale against — no data, a hidden
band, or a view that has not initialized.
import { visibleStats } from '@jbrowse/wiggle-core'
function visibleStats<Payload, Item, Stats>(
opts: VisibleStatsSpec<Payload, Item, Stats>,
): VisibleStats<Item, Stats> | undefinedwidenRangeToRules
Widens an autoscaled range so every configured rule stays on the axis.
Without this a rule is dropped from the plot in the views where it is most
useful. Autoscale follows the visible data, so over a homozygous deletion a
coverage domain collapses to about [0, 1] and a rule at the diploid depth
falls outside it, though the rule's position above the data is what the reader needs to see
in that view, and a dropped rule leaves no visible trace.
Applied to the raw range, before getNiceDomain takes the y scale's
domain bounds. Those still win: a rule outside an explicitly bounded axis
is one the config asked not to be shown, and it drops as before.
import { widenRangeToRules } from '@jbrowse/wiggle-core'
function widenRangeToRules(
range: [number, number],
ruleValues: readonly number[],
): [number, number]Related links
- Developer guide: Dependencies and re-exports