jbrowse-plugin-tview 2.0.4 → 2.1.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 (73) hide show
  1. package/README.md +157 -4
  2. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.d.ts +132 -0
  3. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js +152 -0
  4. package/dist/LaunchTView/TviewGetPlanRpc/TviewGetPlan.js.map +1 -0
  5. package/dist/LaunchTView/TviewGetPlanRpc/index.d.ts +3 -0
  6. package/dist/LaunchTView/TviewGetPlanRpc/index.js +5 -0
  7. package/dist/LaunchTView/TviewGetPlanRpc/index.js.map +1 -0
  8. package/dist/LaunchTView/align.d.ts +93 -9
  9. package/dist/LaunchTView/align.js +290 -15
  10. package/dist/LaunchTView/align.js.map +1 -1
  11. package/dist/LaunchTView/alleles.d.ts +57 -0
  12. package/dist/LaunchTView/alleles.js +94 -0
  13. package/dist/LaunchTView/alleles.js.map +1 -0
  14. package/dist/LaunchTView/components/ArrayReport.d.ts +10 -0
  15. package/dist/LaunchTView/components/ArrayReport.js +59 -0
  16. package/dist/LaunchTView/components/ArrayReport.js.map +1 -0
  17. package/dist/LaunchTView/components/LaunchTViewDialog.js +74 -37
  18. package/dist/LaunchTView/components/LaunchTViewDialog.js.map +1 -1
  19. package/dist/LaunchTView/fetchTviewPlan.d.ts +20 -13
  20. package/dist/LaunchTView/fetchTviewPlan.js +27 -27
  21. package/dist/LaunchTView/fetchTviewPlan.js.map +1 -1
  22. package/dist/LaunchTView/launchView.d.ts +25 -0
  23. package/dist/LaunchTView/launchView.js +20 -0
  24. package/dist/LaunchTView/launchView.js.map +1 -0
  25. package/dist/LaunchTView/readLayout.d.ts +85 -0
  26. package/dist/LaunchTView/readLayout.js +96 -0
  27. package/dist/LaunchTView/readLayout.js.map +1 -0
  28. package/dist/LaunchTView/repeats.d.ts +68 -0
  29. package/dist/LaunchTView/repeats.js +200 -0
  30. package/dist/LaunchTView/repeats.js.map +1 -0
  31. package/dist/LaunchTView/sampleTree.d.ts +37 -0
  32. package/dist/LaunchTView/sampleTree.js +65 -0
  33. package/dist/LaunchTView/sampleTree.js.map +1 -0
  34. package/dist/LaunchTView/tview.d.ts +67 -44
  35. package/dist/LaunchTView/tview.js +190 -121
  36. package/dist/LaunchTView/tview.js.map +1 -1
  37. package/dist/LaunchTView/useTviewMsa.d.ts +13 -9
  38. package/dist/LaunchTView/useTviewMsa.js +15 -11
  39. package/dist/LaunchTView/useTviewMsa.js.map +1 -1
  40. package/dist/TViewPanel/coords.d.ts +9 -1
  41. package/dist/TViewPanel/coords.js +22 -2
  42. package/dist/TViewPanel/coords.js.map +1 -1
  43. package/dist/TViewPanel/init.d.ts +56 -0
  44. package/dist/TViewPanel/init.js +59 -0
  45. package/dist/TViewPanel/init.js.map +1 -0
  46. package/dist/TViewPanel/model.d.ts +56 -40
  47. package/dist/TViewPanel/model.js +73 -51
  48. package/dist/TViewPanel/model.js.map +1 -1
  49. package/dist/index.js +5 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/jbrowse-plugin-tview.umd.production.min.js +59 -21
  52. package/dist/jbrowse-plugin-tview.umd.production.min.js.map +4 -4
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +7 -3
  56. package/src/LaunchTView/TviewGetPlanRpc/TviewGetPlan.ts +264 -0
  57. package/src/LaunchTView/TviewGetPlanRpc/index.ts +14 -0
  58. package/src/LaunchTView/align.ts +343 -17
  59. package/src/LaunchTView/alleles.ts +132 -0
  60. package/src/LaunchTView/components/ArrayReport.tsx +64 -0
  61. package/src/LaunchTView/components/LaunchTViewDialog.tsx +122 -39
  62. package/src/LaunchTView/fetchTviewPlan.ts +42 -42
  63. package/src/LaunchTView/launchView.ts +50 -0
  64. package/src/LaunchTView/readLayout.ts +145 -0
  65. package/src/LaunchTView/repeats.ts +218 -0
  66. package/src/LaunchTView/sampleTree.ts +73 -0
  67. package/src/LaunchTView/tview.ts +259 -157
  68. package/src/LaunchTView/useTviewMsa.ts +20 -17
  69. package/src/TViewPanel/coords.ts +23 -1
  70. package/src/TViewPanel/init.ts +127 -0
  71. package/src/TViewPanel/model.ts +82 -61
  72. package/src/index.ts +5 -1
  73. package/src/version.ts +1 -1
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.0.4";
1
+ export declare const version = "2.1.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '2.0.4';
1
+ export const version = '2.1.0';
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.4",
2
+ "version": "2.1.0",
3
3
  "license": "MIT",
4
4
  "name": "jbrowse-plugin-tview",
5
5
  "repository": {
@@ -33,13 +33,16 @@
33
33
  "prepack": "pnpm build",
34
34
  "preversion": "pnpm lint && pnpm build",
35
35
  "version": "node scripts/version.mjs",
36
- "postversion": "git push --follow-tags"
36
+ "postversion": "git push --follow-tags",
37
+ "figures:repeats": "node scripts/repeat-figures.mjs",
38
+ "prefigures:repeats": "pnpm pretest:e2e",
39
+ "qc:repeats": "tsx test/liveRepeats.qc.ts"
37
40
  },
38
41
  "jbrowse-plugin": {
39
42
  "name": "TView"
40
43
  },
41
44
  "dependencies": {
42
- "react-msaview": "^5.6.1",
45
+ "@emotion/styled": "^11.14.1",
43
46
  "swr": "^2.4.2"
44
47
  },
45
48
  "devDependencies": {
@@ -67,6 +70,7 @@
67
70
  "puppeteer": "^25.3.0",
68
71
  "react": "^19.2.8",
69
72
  "react-dom": "^19.2.8",
73
+ "react-msaview": "^5.6.3",
70
74
  "rimraf": "^6.1.3",
71
75
  "tss-react": "^4.9.21",
72
76
  "typescript": "^6.0.2",
@@ -0,0 +1,264 @@
1
+ import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache'
2
+ import { RpcMethodType } from '@jbrowse/core/pluggableElementTypes'
3
+ import { renameRegionsIfNeeded } from '@jbrowse/core/util'
4
+
5
+ import { buildSampleTree } from '../sampleTree'
6
+ import { planTviewMsa, renderTviewMsa } from '../tview'
7
+
8
+ import type { AlignmentFeature } from '../readLayout'
9
+ import type PluginManager from '@jbrowse/core/PluginManager'
10
+ import type { Region } from '@jbrowse/core/util'
11
+
12
+ /** one BAM/CRAM to draw rows from, and the name its rows are grouped under */
13
+ export interface TviewSourceArgs {
14
+ adapterConfig: Record<string, unknown>
15
+ sample?: string
16
+ /**
17
+ * what this file calls the region's sequence. Filled in on the client, where
18
+ * the assembly's aliases live: two files over one assembly routinely spell it
19
+ * `4` and `chr4`, and a mismatched name fetches nothing and reports nothing.
20
+ */
21
+ refName?: string
22
+ }
23
+
24
+ export interface TviewGetPlanArgs {
25
+ sessionId: string
26
+ sources: TviewSourceArgs[]
27
+ /** the assembly's sequence adapter, when it has one */
28
+ sequenceAdapterConfig?: Record<string, unknown>
29
+ /** the sequence adapter's own spelling of the region */
30
+ sequenceRefName?: string
31
+ region: Region
32
+ /** stop before rendering an alignment bigger than this many cells */
33
+ maxCells: number
34
+ }
35
+
36
+ /** what crosses back: the alignment, and the numbers the dialog reports */
37
+ export interface TviewArrayReport {
38
+ start: number
39
+ end: number
40
+ period: number
41
+ unit: string
42
+ width: number
43
+ /** per row: copies carried, and allele length in bp */
44
+ copies: [string, number][]
45
+ lengths: [string, number][]
46
+ }
47
+
48
+ export interface TviewPlanResult {
49
+ msa: string
50
+ /** Newick grouping rows by sample; absent unless several were loaded */
51
+ tree?: string
52
+ rowCount: number
53
+ columnCount: number
54
+ cellCount: number
55
+ insertionWidths: [number, number][]
56
+ arraySpans: [number, number, number][]
57
+ region: { refName: string; start: number; end: number }
58
+ arrays: TviewArrayReport[]
59
+ subjectIndex?: number
60
+ referenceName?: string
61
+ samples: string[]
62
+ /** set when the alignment was over maxCells and `msa` is empty */
63
+ tooLarge?: boolean
64
+ }
65
+
66
+ /** the slice of a data adapter this reads, which is all of `getFeatures` */
67
+ interface FeatureSource {
68
+ getFeatures: (region: Region) => {
69
+ subscribe: (observer: {
70
+ next: (feature: AlignmentFeature) => void
71
+ error: (error: unknown) => void
72
+ complete: () => void
73
+ }) => unknown
74
+ }
75
+ }
76
+
77
+ function isFeatureSource(adapter: object): adapter is FeatureSource {
78
+ return 'getFeatures' in adapter && typeof adapter.getFeatures === 'function'
79
+ }
80
+
81
+ /**
82
+ * Drains an adapter's feature observable into an array.
83
+ *
84
+ * Hand-rolled rather than `firstValueFrom(...pipe(toArray()))` because rxjs is
85
+ * not a dependency here and `@jbrowse/core/util/rxjs` publishes only
86
+ * `ObservableCreate`. Subscribing directly needs neither.
87
+ */
88
+ async function fetchAll(
89
+ pluginManager: PluginManager,
90
+ sessionId: string,
91
+ adapterConfig: Record<string, unknown>,
92
+ region: Region,
93
+ ) {
94
+ const { dataAdapter } = await getAdapter(
95
+ pluginManager,
96
+ sessionId,
97
+ adapterConfig,
98
+ )
99
+ if (!isFeatureSource(dataAdapter)) {
100
+ throw new Error(`${adapterConfig.type as string} has no getFeatures`)
101
+ }
102
+ return new Promise<AlignmentFeature[]>((resolve, reject) => {
103
+ const ret: AlignmentFeature[] = []
104
+ dataAdapter.getFeatures(region).subscribe({
105
+ next: feature => ret.push(feature),
106
+ error: reject,
107
+ complete: () => {
108
+ resolve(ret)
109
+ },
110
+ })
111
+ })
112
+ }
113
+
114
+ /**
115
+ * Builds the whole alignment in the worker and sends back the FASTA.
116
+ *
117
+ * The work this moves is not the fetch — `CoreGetFeatures` already ran in a
118
+ * worker — but everything after it. Fetching from the client meant serializing
119
+ * every read's sequence and CIGAR across the boundary and then running the
120
+ * pairwise alignments and the string building on the main thread, where a
121
+ * region carrying a kilobase-scale array froze the UI for as long as it took.
122
+ * What comes back now is the alignment, which is smaller than the reads it was
123
+ * built from and is the only thing the view has a use for.
124
+ *
125
+ * It is also what makes several files one call: their rows are squared up
126
+ * against the same reference interval, so an array's copies are counted once,
127
+ * over rows from all of them.
128
+ */
129
+ export default class TviewGetPlan extends RpcMethodType {
130
+ name = 'TviewGetPlan'
131
+
132
+ /**
133
+ * Written against the 4.3.0 base class, which takes a bare
134
+ * `Record<string, unknown>` and has no `renameRegions` helper — that is the
135
+ * oldest host this bundle boots on, and the newer base class accepts the same
136
+ * shape.
137
+ */
138
+ async serializeArguments(
139
+ args: Record<string, unknown>,
140
+ rpcDriverClassName: string,
141
+ ) {
142
+ const typed = args as unknown as TviewGetPlanArgs
143
+ const assemblyManager =
144
+ this.pluginManager.rootModel?.session?.assemblyManager
145
+ if (!assemblyManager) {
146
+ throw new Error('no assembly manager')
147
+ }
148
+ const refNameFor = async (adapterConfig: Record<string, unknown>) => {
149
+ const { regions } = await renameRegionsIfNeeded(assemblyManager, {
150
+ sessionId: typed.sessionId,
151
+ adapterConfig,
152
+ regions: [typed.region],
153
+ })
154
+ return regions[0]!.refName
155
+ }
156
+ const sources = await Promise.all(
157
+ typed.sources.map(async source => ({
158
+ ...source,
159
+ refName: await refNameFor(source.adapterConfig),
160
+ })),
161
+ )
162
+ const sequenceRefName = typed.sequenceAdapterConfig
163
+ ? await refNameFor(typed.sequenceAdapterConfig)
164
+ : undefined
165
+
166
+ return super.serializeArguments(
167
+ { ...args, sources, sequenceRefName },
168
+ rpcDriverClassName,
169
+ )
170
+ }
171
+
172
+ async execute(args: TviewGetPlanArgs, rpcDriverClassName: string) {
173
+ const {
174
+ sessionId,
175
+ sources,
176
+ sequenceAdapterConfig,
177
+ sequenceRefName,
178
+ region,
179
+ maxCells,
180
+ } = await this.deserializeArguments(args, rpcDriverClassName)
181
+
182
+ const perSource = await Promise.all(
183
+ sources.map(source =>
184
+ fetchAll(this.pluginManager, sessionId, source.adapterConfig, {
185
+ ...region,
186
+ refName: source.refName ?? region.refName,
187
+ }),
188
+ ),
189
+ )
190
+ const features: AlignmentFeature[] = []
191
+ const sampleByIndex: (string | undefined)[] = []
192
+ for (const [i, feats] of perSource.entries()) {
193
+ for (const feature of feats) {
194
+ if (feature.get('seq')) {
195
+ features.push(feature)
196
+ sampleByIndex.push(sources[i]!.sample)
197
+ }
198
+ }
199
+ }
200
+
201
+ let sequence: string | undefined
202
+ if (sequenceAdapterConfig) {
203
+ const seqFeats = await fetchAll(
204
+ this.pluginManager,
205
+ sessionId,
206
+ sequenceAdapterConfig,
207
+ { ...region, refName: sequenceRefName ?? region.refName },
208
+ )
209
+ const seq = seqFeats[0]?.get('seq') as string | undefined
210
+ const seqStart = seqFeats[0]?.get('start') as number | undefined
211
+ // the adapter may answer with a wider block than it was asked for
212
+ const sliced =
213
+ seq !== undefined && seqStart !== undefined
214
+ ? seq.slice(region.start - seqStart, region.end - seqStart)
215
+ : undefined
216
+ // a short answer means the region runs off the end of the contig, and a
217
+ // reference row that stops early would misplace every column after it
218
+ sequence =
219
+ sliced?.length === region.end - region.start ? sliced : undefined
220
+ }
221
+
222
+ const plan = planTviewMsa({
223
+ features,
224
+ refName: region.refName,
225
+ start: region.start,
226
+ end: region.end,
227
+ sequence,
228
+ sampleOf: i => sampleByIndex[i],
229
+ })
230
+
231
+ const shared = {
232
+ rowCount: plan.reads.length,
233
+ columnCount: plan.layout.totalColumns,
234
+ cellCount: plan.cellCount,
235
+ insertionWidths: plan.insertionWidths,
236
+ arraySpans: plan.arraySpans,
237
+ region: plan.region,
238
+ arrays: plan.arrays.map(a => ({
239
+ start: a.start,
240
+ end: a.end,
241
+ period: a.period,
242
+ unit: a.unit,
243
+ width: a.width,
244
+ copies: [...a.copiesByName.entries()],
245
+ lengths: [...a.lengthByName.entries()],
246
+ })),
247
+ subjectIndex: plan.subject
248
+ ? plan.arrays.indexOf(plan.subject)
249
+ : undefined,
250
+ referenceName: plan.referenceName,
251
+ samples: plan.samples,
252
+ }
253
+
254
+ // the render is the expensive half and the only part bounded by rows x
255
+ // columns, so the size check happens before it rather than after
256
+ return plan.cellCount > maxCells
257
+ ? { ...shared, msa: '', tooLarge: true }
258
+ : {
259
+ ...shared,
260
+ msa: renderTviewMsa(plan),
261
+ tree: buildSampleTree(plan.reads),
262
+ }
263
+ }
264
+ }
@@ -0,0 +1,14 @@
1
+ import TviewGetPlan from './TviewGetPlan'
2
+
3
+ import type PluginManager from '@jbrowse/core/PluginManager'
4
+
5
+ export default function TviewGetPlanRpcF(pluginManager: PluginManager) {
6
+ pluginManager.addRpcMethod(() => new TviewGetPlan(pluginManager))
7
+ }
8
+
9
+ export type {
10
+ TviewArrayReport,
11
+ TviewGetPlanArgs,
12
+ TviewPlanResult,
13
+ TviewSourceArgs,
14
+ } from './TviewGetPlan'