jbrowse-plugin-tview 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +349 -69
  2. package/dist/AddHighlightModel/index.js +2 -13
  3. package/dist/AddHighlightModel/index.js.map +1 -1
  4. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.d.ts +44 -64
  5. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js +57 -81
  6. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js.map +1 -1
  7. package/dist/LaunchTView/TviewGetPlanRpc/index.d.ts +1 -1
  8. package/dist/LaunchTView/align.d.ts +18 -17
  9. package/dist/LaunchTView/align.js +198 -151
  10. package/dist/LaunchTView/align.js.map +1 -1
  11. package/dist/LaunchTView/alleles.d.ts +14 -0
  12. package/dist/LaunchTView/alleles.js +51 -3
  13. package/dist/LaunchTView/alleles.js.map +1 -1
  14. package/dist/LaunchTView/fetchTviewPlan.d.ts +5 -37
  15. package/dist/LaunchTView/fetchTviewPlan.js +7 -28
  16. package/dist/LaunchTView/fetchTviewPlan.js.map +1 -1
  17. package/dist/LaunchTView/index.js +45 -16
  18. package/dist/LaunchTView/index.js.map +1 -1
  19. package/dist/LaunchTView/launch.d.ts +50 -0
  20. package/dist/LaunchTView/launch.js +48 -0
  21. package/dist/LaunchTView/launch.js.map +1 -0
  22. package/dist/LaunchTView/launchView.d.ts +3 -8
  23. package/dist/LaunchTView/launchView.js +18 -12
  24. package/dist/LaunchTView/launchView.js.map +1 -1
  25. package/dist/LaunchTView/modifications.d.ts +64 -0
  26. package/dist/LaunchTView/modifications.js +131 -0
  27. package/dist/LaunchTView/modifications.js.map +1 -0
  28. package/dist/LaunchTView/readLayout.d.ts +35 -39
  29. package/dist/LaunchTView/readLayout.js +44 -24
  30. package/dist/LaunchTView/readLayout.js.map +1 -1
  31. package/dist/LaunchTView/repeatStats.d.ts +1 -1
  32. package/dist/LaunchTView/repeatStats.js +6 -6
  33. package/dist/LaunchTView/repeatStats.js.map +1 -1
  34. package/dist/LaunchTView/repeats.js +6 -4
  35. package/dist/LaunchTView/repeats.js.map +1 -1
  36. package/dist/LaunchTView/tview.d.ts +47 -24
  37. package/dist/LaunchTView/tview.js +188 -99
  38. package/dist/LaunchTView/tview.js.map +1 -1
  39. package/dist/TViewPanel/components/TViewPanel.js +9 -4
  40. package/dist/TViewPanel/components/TViewPanel.js.map +1 -1
  41. package/dist/TViewPanel/genome.d.ts +11 -0
  42. package/dist/TViewPanel/genome.js +32 -0
  43. package/dist/TViewPanel/genome.js.map +1 -0
  44. package/dist/TViewPanel/init.d.ts +38 -19
  45. package/dist/TViewPanel/init.js +66 -39
  46. package/dist/TViewPanel/init.js.map +1 -1
  47. package/dist/TViewPanel/initMenu.d.ts +28 -0
  48. package/dist/TViewPanel/initMenu.js +79 -0
  49. package/dist/TViewPanel/initMenu.js.map +1 -0
  50. package/dist/TViewPanel/model.d.ts +1178 -383
  51. package/dist/TViewPanel/model.js +298 -87
  52. package/dist/TViewPanel/model.js.map +1 -1
  53. package/dist/TViewPanel/modifications.d.ts +25 -0
  54. package/dist/TViewPanel/modifications.js +89 -0
  55. package/dist/TViewPanel/modifications.js.map +1 -0
  56. package/dist/index.d.ts +0 -1
  57. package/dist/index.js +0 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/jbrowse-plugin-tview.umd.production.min.js +125 -89
  60. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
  61. package/dist/version.d.ts +1 -1
  62. package/dist/version.js +1 -1
  63. package/package.json +21 -18
  64. package/src/AddHighlightModel/index.tsx +8 -14
  65. package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +119 -157
  66. package/src/LaunchTView/TviewGetPlanRpc/index.ts +0 -1
  67. package/src/LaunchTView/align.ts +233 -177
  68. package/src/LaunchTView/alleles.ts +70 -4
  69. package/src/LaunchTView/fetchTviewPlan.ts +11 -54
  70. package/src/LaunchTView/index.ts +74 -16
  71. package/src/LaunchTView/launch.ts +98 -0
  72. package/src/LaunchTView/launchView.ts +28 -20
  73. package/src/LaunchTView/modifications.ts +200 -0
  74. package/src/LaunchTView/readLayout.ts +65 -41
  75. package/src/LaunchTView/repeatStats.ts +7 -7
  76. package/src/LaunchTView/repeats.ts +6 -4
  77. package/src/LaunchTView/tview.ts +228 -112
  78. package/src/TViewPanel/components/TViewPanel.tsx +33 -4
  79. package/src/TViewPanel/genome.ts +41 -0
  80. package/src/TViewPanel/init.ts +104 -51
  81. package/src/TViewPanel/initMenu.ts +126 -0
  82. package/src/TViewPanel/model.ts +350 -97
  83. package/src/TViewPanel/modifications.ts +127 -0
  84. package/src/index.ts +0 -2
  85. package/src/version.ts +1 -1
  86. package/dist/AddHighlightModel/GenomeMouseoverHighlight.d.ts +0 -6
  87. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js +0 -23
  88. package/dist/AddHighlightModel/GenomeMouseoverHighlight.js.map +0 -1
  89. package/dist/AddHighlightModel/HighlightComponents.d.ts +0 -7
  90. package/dist/AddHighlightModel/HighlightComponents.js +0 -11
  91. package/dist/AddHighlightModel/HighlightComponents.js.map +0 -1
  92. package/dist/LaunchTView/components/ArrayReport.d.ts +0 -10
  93. package/dist/LaunchTView/components/ArrayReport.js +0 -59
  94. package/dist/LaunchTView/components/ArrayReport.js.map +0 -1
  95. package/dist/LaunchTView/components/LaunchTViewDialog.d.ts +0 -6
  96. package/dist/LaunchTView/components/LaunchTViewDialog.js +0 -124
  97. package/dist/LaunchTView/components/LaunchTViewDialog.js.map +0 -1
  98. package/dist/LaunchTView/sampleTree.d.ts +0 -37
  99. package/dist/LaunchTView/sampleTree.js +0 -65
  100. package/dist/LaunchTView/sampleTree.js.map +0 -1
  101. package/dist/LaunchTView/useTviewMsa.d.ts +0 -18
  102. package/dist/LaunchTView/useTviewMsa.js +0 -24
  103. package/dist/LaunchTView/useTviewMsa.js.map +0 -1
  104. package/dist/TViewPanel/coords.d.ts +0 -25
  105. package/dist/TViewPanel/coords.js +0 -56
  106. package/dist/TViewPanel/coords.js.map +0 -1
  107. package/src/AddHighlightModel/GenomeMouseoverHighlight.tsx +0 -46
  108. package/src/AddHighlightModel/HighlightComponents.tsx +0 -25
  109. package/src/LaunchTView/components/ArrayReport.tsx +0 -64
  110. package/src/LaunchTView/components/LaunchTViewDialog.tsx +0 -212
  111. package/src/LaunchTView/sampleTree.ts +0 -73
  112. package/src/LaunchTView/useTviewMsa.ts +0 -39
  113. package/src/TViewPanel/coords.ts +0 -65
@@ -1,64 +0,0 @@
1
- import React from 'react'
2
-
3
- import { Typography } from '@mui/material'
4
-
5
- import type { TviewPlanResult } from '../TviewGetPlanRpc'
6
-
7
- /** allele lengths seen, commonest first, as `63bp x12` */
8
- function alleleTally(lengths: [string, number][]) {
9
- const counts = new Map<number, number>()
10
- for (const [, length] of lengths) {
11
- counts.set(length, (counts.get(length) ?? 0) + 1)
12
- }
13
- return [...counts]
14
- .sort((a, b) => b[1] - a[1] || a[0] - b[0])
15
- .map(([length, n]) => `${length}bp x${n}`)
16
- }
17
-
18
- /**
19
- * What the reads say about the arrays before the view is opened, since the
20
- * number is often the whole reason for opening it and a picture of 400 columns
21
- * is a slow way to read one off.
22
- */
23
- export default function ArrayReport({ data }: { data: TviewPlanResult }) {
24
- const { arrays, subjectIndex, region } = data
25
- const subject = subjectIndex === undefined ? undefined : arrays[subjectIndex]
26
- if (!subject) {
27
- return arrays.length ? null : (
28
- <Typography variant="body2">
29
- No tandem array in the reference here, so the reads are laid out base by
30
- base.
31
- </Typography>
32
- )
33
- }
34
- const copies = subject.copies
35
- return (
36
- <>
37
- <Typography variant="subtitle2">
38
- Tandem array at {region.refName}:{subject.start.toLocaleString('en-US')}
39
- -{subject.end.toLocaleString('en-US')}, {subject.period}bp unit{' '}
40
- {subject.unit}
41
- </Typography>
42
- <Typography variant="body2">
43
- {copies.length} of {data.rowCount} rows span it end to end and carry{' '}
44
- {Math.min(...copies.map(c => c[1]))}&ndash;
45
- {Math.max(...copies.map(c => c[1]))} copies. Allele lengths:{' '}
46
- {alleleTally(subject.lengths).join(', ')}.
47
- </Typography>
48
- <Typography variant="body2">
49
- Each copy gets its own block of columns, so one divergent copy shows up
50
- as a column rather than shifting every copy after it. Blocks are array
51
- order, not homology: copies are counted from the left edge, and arrays
52
- expand and contract anywhere inside themselves, so the 9th copy of one
53
- row need not be the 9th of another. Read down a row, not across two.
54
- </Typography>
55
- {arrays.length > 1 ? (
56
- <Typography variant="body2">
57
- {arrays.length - 1} shorter{' '}
58
- {arrays.length === 2 ? 'array is' : 'arrays are'} also laid out per
59
- copy; rows are ordered by this one.
60
- </Typography>
61
- ) : null}
62
- </>
63
- )
64
- }
@@ -1,212 +0,0 @@
1
- import React, { useState } from 'react'
2
-
3
- import { getConf } from '@jbrowse/core/configuration'
4
- import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
5
- import {
6
- assembleLocString,
7
- getContainingView,
8
- getSession,
9
- } from '@jbrowse/core/util'
10
- import {
11
- Button,
12
- Checkbox,
13
- DialogActions,
14
- DialogContent,
15
- FormControlLabel,
16
- Typography,
17
- } from '@mui/material'
18
-
19
- import ArrayReport from './ArrayReport'
20
- import { MAX_BP } from '../limits'
21
- import { useTviewMsa } from '../useTviewMsa'
22
-
23
- import type { TviewInit } from '../../TViewPanel/init'
24
- import type { AbstractTrackModel } from '@jbrowse/core/util'
25
- import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
26
-
27
- // how much of the alignment the default column width aims to put on screen
28
- const FIT_WIDTH_PX = 3000
29
-
30
- function trackLabel(track: AbstractTrackModel) {
31
- return (
32
- (getConf(track, 'name') as string) || (getConf(track, 'trackId') as string)
33
- )
34
- }
35
-
36
- /** every alignments track open in the same view, the launching one first */
37
- function peerTracks(view: LinearGenomeViewModel, model: AbstractTrackModel) {
38
- const alignments = view.tracks.filter(track =>
39
- track.displays.some(
40
- (display: { type: string }) => display.type === 'LinearAlignmentsDisplay',
41
- ),
42
- ) as AbstractTrackModel[]
43
- return [model, ...alignments.filter(t => t.id !== model.id)]
44
- }
45
-
46
- export default function LaunchTViewDialog({
47
- handleClose,
48
- model,
49
- }: {
50
- handleClose: () => void
51
- model: AbstractTrackModel
52
- }) {
53
- const view = getContainingView(model) as LinearGenomeViewModel
54
- const session = getSession(model)
55
- const block = view.dynamicBlocks.contentBlocks[0]
56
- const region = block
57
- ? {
58
- assemblyName: block.assemblyName,
59
- refName: block.refName,
60
- start: Math.floor(block.start),
61
- end: Math.ceil(block.end),
62
- }
63
- : undefined
64
- const width = region ? region.end - region.start : 0
65
- const tooWide = width > MAX_BP
66
-
67
- const candidates = peerTracks(view, model)
68
- // the launching track is always in; the others are opt-in, because pulling
69
- // every open pileup into one alignment is a much bigger fetch than the menu
70
- // item that got here suggests
71
- const [extra, setExtra] = useState<string[]>([])
72
- const chosen = candidates.filter(
73
- t => t.id === model.id || extra.includes(t.id),
74
- )
75
-
76
- // The dialog's whole output. Everything below either previews what this
77
- // resolves to or hands it to a view, so what the button opens is the same
78
- // blob a session could have been authored with.
79
- const init: TviewInit | undefined = region
80
- ? {
81
- assembly: region.assemblyName,
82
- loc: assembleLocString(region),
83
- tracks: chosen.map(t => ({
84
- trackId: getConf(t, 'trackId') as string,
85
- sample: trackLabel(t),
86
- })),
87
- }
88
- : undefined
89
-
90
- const { data, error, isLoading } = useTviewMsa({
91
- session,
92
- init: tooWide ? undefined : init,
93
- })
94
-
95
- // 10 is comfortable for an ordinary pileup, but an unrolled tandem array runs
96
- // to hundreds of columns and at 10 almost none of it is on screen at once.
97
- // Fits the alignment to roughly two screen-widths; a no-op for the narrow
98
- // regions that already fitted.
99
- const totalColumns = data?.columnCount ?? 0
100
- const colWidth = totalColumns
101
- ? Math.max(1, Math.min(10, Math.floor(FIT_WIDTH_PX / totalColumns)))
102
- : 10
103
-
104
- return (
105
- <Dialog
106
- maxWidth="xl"
107
- title="Launch tview"
108
- onClose={() => {
109
- handleClose()
110
- }}
111
- open
112
- >
113
- <DialogContent>
114
- <Typography>
115
- Create a view similar to "samtools tview" for the reads in the current
116
- region: {init?.loc ?? 'Unknown'}
117
- </Typography>
118
- {candidates.length > 1 ? (
119
- <div>
120
- <Typography variant="subtitle2">
121
- Include reads from other alignment tracks in this view
122
- </Typography>
123
- {candidates.slice(1).map(track => (
124
- <FormControlLabel
125
- key={track.id}
126
- control={
127
- <Checkbox
128
- checked={extra.includes(track.id)}
129
- onChange={event => {
130
- setExtra(
131
- event.target.checked
132
- ? [...extra, track.id]
133
- : extra.filter(id => id !== track.id),
134
- )
135
- }}
136
- />
137
- }
138
- label={trackLabel(track)}
139
- />
140
- ))}
141
- </div>
142
- ) : null}
143
- {tooWide ? (
144
- <Typography>
145
- Region is {width.toLocaleString('en-US')}bp, wider than the{' '}
146
- {MAX_BP.toLocaleString('en-US')}bp limit. Zoom in and try again.
147
- </Typography>
148
- ) : error ? (
149
- <ErrorMessage error={error} />
150
- ) : isLoading ? (
151
- <Typography>Loading...</Typography>
152
- ) : data?.tooLarge ? (
153
- <Typography>
154
- {data.rowCount.toLocaleString('en-US')} rows over{' '}
155
- {data.columnCount.toLocaleString('en-US')} columns is{' '}
156
- {data.cellCount.toLocaleString('en-US')} cells, which is too large
157
- to render. Zoom in and try again.
158
- </Typography>
159
- ) : data ? (
160
- <>
161
- <Typography>
162
- {data.rowCount} rows
163
- {data.referenceName
164
- ? ' (the reference plus every read with sequence)'
165
- : ' of reads with sequence data'}
166
- {data.samples.length > 1
167
- ? `, from ${data.samples.length} tracks`
168
- : ''}
169
- </Typography>
170
- <ArrayReport data={data} />
171
- </>
172
- ) : (
173
- <Typography>No region is currently visible.</Typography>
174
- )}
175
- </DialogContent>
176
- <DialogActions>
177
- <Button
178
- variant="contained"
179
- color="primary"
180
- disabled={!data?.msa || !init}
181
- onClick={() => {
182
- if (init) {
183
- session.addView('TView', {
184
- type: 'TView',
185
- displayName: init.loc,
186
- init,
187
- colWidth,
188
- rowHeight: 12,
189
- labelsAlignRight: true,
190
- colorSchemeName: 'jbrowse_dna',
191
- drawTree: init.tracks.length > 1,
192
- connectedViewId: view.id,
193
- })
194
- }
195
- handleClose()
196
- }}
197
- >
198
- Submit
199
- </Button>
200
- <Button
201
- variant="contained"
202
- color="secondary"
203
- onClick={() => {
204
- handleClose()
205
- }}
206
- >
207
- Cancel
208
- </Button>
209
- </DialogActions>
210
- </Dialog>
211
- )
212
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * A Newick tree whose only job is to group rows.
3
- *
4
- * With one file the rows are a pileup and their order is the whole structure.
5
- * With several, the rows of two samples interleave into a list nothing separates
6
- * — and react-msaview already draws a tree, collapses its clades and can show
7
- * one branch alone, all of it keyed off a Newick string it is currently never
8
- * given. Handing it one grouped by sample turns those controls on for free: a
9
- * clade per sample, collapsible, and the allele ladder inside each.
10
- *
11
- * The tree is a grouping, not a phylogeny. Branch lengths are all 1 and say
12
- * nothing; the topology is the sample the row came from, and the leaf order
13
- * inside a clade is the copy-number order the rows were already in.
14
- */
15
-
16
- /**
17
- * Newick reserves these, and a name is not quoted when it goes in.
18
- *
19
- * **Applied where the row name is built, not here.** react-msaview joins a tree
20
- * leaf to an alignment row by name, so sanitizing on the way into the Newick
21
- * and leaving the FASTA defline alone matches nothing: every row whose name
22
- * needed fixing renders blank, with its label still in the tree, which looks
23
- * like a rendering bug rather than a naming one. A track named `HG004 (mother)`
24
- * is enough to trigger it.
25
- */
26
- export function newickSafe(name: string) {
27
- return name.replaceAll(/[(),:;[\]'\s]+/g, '_').replace(/_+$/, '')
28
- }
29
-
30
- export interface TreeRow {
31
- name: string
32
- /** what the defline says, when that is not just the name */
33
- label?: string
34
- sample?: string
35
- }
36
-
37
- /**
38
- * Groups rows by sample, keeping the order they arrive in both for the clades
39
- * and inside them. Returns undefined when there is nothing to group — one
40
- * sample, or none — since a tree of one clade is a line drawn beside a list.
41
- */
42
- export function buildSampleTree(rows: TreeRow[]) {
43
- const bySample = new Map<string, string[]>()
44
- const ungrouped: string[] = []
45
- for (const row of rows) {
46
- // the leaf is the row's *defline*, already Newick-safe from getReadNames.
47
- // The tree must not rewrite it, and must not use the identity where the
48
- // defline carries a label — react-msaview joins the two by string, and a
49
- // leaf naming no row leaves that row blank with its label still drawn
50
- const leaf = row.label ?? row.name
51
- if (row.sample === undefined) {
52
- ungrouped.push(leaf)
53
- } else {
54
- const group = bySample.get(row.sample)
55
- if (group) {
56
- group.push(leaf)
57
- } else {
58
- bySample.set(row.sample, [leaf])
59
- }
60
- }
61
- }
62
- if (bySample.size < 2) {
63
- return undefined
64
- }
65
- const clades = [
66
- // the reference has no sample and belongs above all of them
67
- ...ungrouped.map(name => `${name}:1`),
68
- ...[...bySample].map(
69
- ([sample, names]) => `(${names.map(n => `${n}:1`).join(',')})${sample}:1`,
70
- ),
71
- ]
72
- return `(${clades.join(',')});`
73
- }
@@ -1,39 +0,0 @@
1
- import useSWR from 'swr'
2
-
3
- import { fetchTviewPlan } from './fetchTviewPlan'
4
- import { initRegion, initSources } from '../TViewPanel/init'
5
-
6
- import type { TviewInit } from '../TViewPanel/init'
7
- import type { AbstractSessionModel } from '@jbrowse/core/util'
8
-
9
- const staticSwrConfig = {
10
- revalidateOnFocus: false,
11
- revalidateOnReconnect: false,
12
- revalidateIfStale: false,
13
- shouldRetryOnError: false,
14
- }
15
-
16
- /**
17
- * A preview of what a `TviewInit` resolves to, for the dialog to report before
18
- * the view is opened.
19
- *
20
- * Resolved through the same two functions the view itself uses, so what the
21
- * dialog states and what the view then builds cannot disagree.
22
- */
23
- export function useTviewMsa({
24
- session,
25
- init,
26
- }: {
27
- session: AbstractSessionModel
28
- init?: TviewInit
29
- }) {
30
- const region = init ? initRegion(session, init) : undefined
31
- const sources = init ? initSources(session, init) : undefined
32
- return useSWR(
33
- region && sources
34
- ? { tag: 'tview', loc: init!.loc, tracks: init!.tracks, region, sources }
35
- : null,
36
- ({ region, sources }) => fetchTviewPlan({ session, sources, region }),
37
- staticSwrConfig,
38
- )
39
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * Inverse of the column layout built by buildTviewMsa: the alignment emits each
3
- * reference position's insertion columns followed by its reference column, so a
4
- * flat column -> reference position array recovers the mapping.
5
- *
6
- * An array block is the exception. Its columns are copies rather than positions,
7
- * and a copy is not at any one reference base — the whole point of the block is
8
- * that reads disagree about where the bases are. Its columns therefore ramp
9
- * evenly across the interval the array covers, which is right at the two edges
10
- * and an interpolation in between; hovering a copy lands in the array, which is
11
- * the honest answer.
12
- */
13
- export function buildColumnToRefPos({
14
- start,
15
- end,
16
- insertionWidths,
17
- arraySpans = [],
18
- }: {
19
- start: number
20
- end: number
21
- insertionWidths: [number, number][]
22
- arraySpans?: [number, number, number][]
23
- }) {
24
- const widths = new Map(insertionWidths)
25
- const arrayAt = new Map(arraySpans.map(([s, e, w]) => [s, { end: e, w }]))
26
- const ret: number[] = []
27
- let pos = start
28
- while (pos < end) {
29
- const array = arrayAt.get(pos)
30
- if (array) {
31
- const stop = Math.min(array.end, end)
32
- const span = stop - pos
33
- for (let i = 0; i < array.w; i++) {
34
- ret.push(pos + Math.min(span - 1, Math.floor((i * span) / array.w)))
35
- }
36
- pos = stop
37
- continue
38
- }
39
- const width = widths.get(pos) ?? 0
40
- for (let i = 0; i < width; i++) {
41
- ret.push(pos)
42
- }
43
- ret.push(pos)
44
- pos++
45
- }
46
- return ret
47
- }
48
-
49
- /**
50
- * react-msaview drops all-gap columns from the rendering when hideGaps is
51
- * effective (a row is collapsed, or allowedGappyness < 100), so the column
52
- * index its mouse handlers report counts only visible columns. Expand it back
53
- * to an index into the full alignment. `blanks` is ascending.
54
- */
55
- export function renderedColToMsaCol(blanks: number[], col: number) {
56
- let ret = col
57
- for (const blank of blanks) {
58
- if (blank <= ret) {
59
- ret++
60
- } else {
61
- break
62
- }
63
- }
64
- return ret
65
- }