@jbrowse/plugin-data-management 2.3.1 → 2.3.3

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 (67) hide show
  1. package/dist/AddConnectionWidget/index.d.ts +3 -2
  2. package/dist/AddConnectionWidget/index.js +38 -4
  3. package/dist/AddConnectionWidget/index.js.map +1 -1
  4. package/dist/AddTrackWidget/index.d.ts +3 -2
  5. package/dist/AddTrackWidget/index.js +38 -4
  6. package/dist/AddTrackWidget/index.js.map +1 -1
  7. package/dist/HierarchicalTrackSelectorWidget/index.d.ts +3 -0
  8. package/dist/HierarchicalTrackSelectorWidget/index.js +36 -0
  9. package/dist/HierarchicalTrackSelectorWidget/index.js.map +1 -1
  10. package/dist/PluginStoreWidget/index.d.ts +3 -2
  11. package/dist/PluginStoreWidget/index.js +38 -4
  12. package/dist/PluginStoreWidget/index.js.map +1 -1
  13. package/dist/index.js +10 -51
  14. package/dist/index.js.map +1 -1
  15. package/dist/ucsc-trackhub/index.d.ts +3 -2
  16. package/dist/ucsc-trackhub/index.js +13 -5
  17. package/dist/ucsc-trackhub/index.js.map +1 -1
  18. package/dist/ucsc-trackhub/model.js +11 -17
  19. package/dist/ucsc-trackhub/model.js.map +1 -1
  20. package/dist/ucsc-trackhub/ucscTrackHub.d.ts +23 -5
  21. package/dist/ucsc-trackhub/ucscTrackHub.js +90 -143
  22. package/dist/ucsc-trackhub/ucscTrackHub.js.map +1 -1
  23. package/esm/AddConnectionWidget/index.d.ts +3 -2
  24. package/esm/AddConnectionWidget/index.js +15 -2
  25. package/esm/AddConnectionWidget/index.js.map +1 -1
  26. package/esm/AddTrackWidget/index.d.ts +3 -2
  27. package/esm/AddTrackWidget/index.js +15 -2
  28. package/esm/AddTrackWidget/index.js.map +1 -1
  29. package/esm/HierarchicalTrackSelectorWidget/index.d.ts +3 -0
  30. package/esm/HierarchicalTrackSelectorWidget/index.js +13 -0
  31. package/esm/HierarchicalTrackSelectorWidget/index.js.map +1 -1
  32. package/esm/PluginStoreWidget/index.d.ts +3 -2
  33. package/esm/PluginStoreWidget/index.js +15 -2
  34. package/esm/PluginStoreWidget/index.js.map +1 -1
  35. package/esm/index.js +10 -51
  36. package/esm/index.js.map +1 -1
  37. package/esm/ucsc-trackhub/index.d.ts +3 -2
  38. package/esm/ucsc-trackhub/index.js +13 -2
  39. package/esm/ucsc-trackhub/index.js.map +1 -1
  40. package/esm/ucsc-trackhub/model.js +11 -17
  41. package/esm/ucsc-trackhub/model.js.map +1 -1
  42. package/esm/ucsc-trackhub/ucscTrackHub.d.ts +23 -5
  43. package/esm/ucsc-trackhub/ucscTrackHub.js +87 -143
  44. package/esm/ucsc-trackhub/ucscTrackHub.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/AddConnectionWidget/components/{AddConnectionWidget.test.js → AddConnectionWidget.test.tsx} +17 -8
  47. package/src/AddConnectionWidget/components/__snapshots__/{AddConnectionWidget.test.js.snap → AddConnectionWidget.test.tsx.snap} +0 -0
  48. package/src/AddConnectionWidget/index.ts +17 -2
  49. package/src/AddTrackWidget/{index.test.jsx → index.test.tsx} +34 -37
  50. package/src/AddTrackWidget/index.ts +17 -2
  51. package/src/HierarchicalTrackSelectorWidget/components/HierarchicalTrackSelector.test.tsx +124 -128
  52. package/src/HierarchicalTrackSelectorWidget/components/__snapshots__/HierarchicalTrackSelector.test.tsx.snap +5 -5
  53. package/src/HierarchicalTrackSelectorWidget/index.ts +17 -0
  54. package/src/PluginStoreWidget/components/PluginStoreWidget.test.tsx +132 -0
  55. package/src/PluginStoreWidget/components/__snapshots__/{PluginStoreWidget.test.js.snap → PluginStoreWidget.test.tsx.snap} +2 -2
  56. package/src/PluginStoreWidget/index.ts +17 -2
  57. package/src/PluginStoreWidget/{model.test.js → model.test.tsx} +0 -0
  58. package/src/__snapshots__/index.test.ts.snap +9 -0
  59. package/src/index.test.ts +54 -0
  60. package/src/index.ts +10 -83
  61. package/src/ucsc-trackhub/index.ts +19 -2
  62. package/src/ucsc-trackhub/model.ts +15 -26
  63. package/src/ucsc-trackhub/ucscTrackHub.ts +326 -0
  64. package/src/PluginStoreWidget/components/PluginStoreWidget.test.js +0 -123
  65. package/src/__snapshots__/index.test.js.snap +0 -9
  66. package/src/index.test.js +0 -61
  67. package/src/ucsc-trackhub/ucscTrackHub.js +0 -442
@@ -0,0 +1,326 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { RaStanza, TrackDbFile } from '@gmod/ucsc-hub'
3
+ import { FileLocation, isUriLocation, objectHash } from '@jbrowse/core/util'
4
+ import { openLocation } from '@jbrowse/core/util/io'
5
+ import {
6
+ generateUnsupportedTrackConf,
7
+ generateUnknownTrackConf,
8
+ } from '@jbrowse/core/util/tracks'
9
+ import ucscAssemblies from './ucscAssemblies'
10
+
11
+ export { ucscAssemblies }
12
+
13
+ export async function fetchHubFile(hubLocation: FileLocation) {
14
+ try {
15
+ const hubFileText = await openLocation(hubLocation).readFile('utf8')
16
+ const { HubFile } = await import('@gmod/ucsc-hub')
17
+ return new HubFile(hubFileText)
18
+ } catch (error) {
19
+ throw new Error(`Not a valid hub.txt file, got error: '${error}'`)
20
+ }
21
+ }
22
+
23
+ export async function fetchGenomesFile(genomesLoc: FileLocation) {
24
+ const genomesFileText = await openLocation(genomesLoc).readFile('utf8')
25
+ const { GenomesFile } = await import('@gmod/ucsc-hub')
26
+ return new GenomesFile(genomesFileText)
27
+ }
28
+
29
+ export async function fetchTrackDbFile(trackDbLoc: FileLocation) {
30
+ const text = await openLocation(trackDbLoc).readFile('utf8')
31
+ const { TrackDbFile } = await import('@gmod/ucsc-hub')
32
+ return new TrackDbFile(text)
33
+ }
34
+
35
+ export function makeLoc(first: string, base: { uri: string }) {
36
+ return {
37
+ uri: new URL(first, base.uri).href,
38
+ locationType: 'UriLocation',
39
+ }
40
+ }
41
+
42
+ export function makeLocAlt(first: string, alt: string, base: { uri: string }) {
43
+ return first ? makeLoc(first, base) : makeLoc(alt, base)
44
+ }
45
+
46
+ export function makeLoc2(first: string, alt?: string) {
47
+ return first
48
+ ? {
49
+ uri: first,
50
+ locationType: 'LocalPath',
51
+ }
52
+ : {
53
+ uri: alt,
54
+ locationType: 'UriLocation',
55
+ }
56
+ }
57
+
58
+ export function generateTracks(
59
+ trackDb: TrackDbFile,
60
+ trackDbLoc: FileLocation,
61
+ assemblyName: string,
62
+ sequenceAdapter: any,
63
+ ) {
64
+ const tracks: any = []
65
+
66
+ trackDb.forEach((track, trackName) => {
67
+ const trackKeys = Array.from(track.keys()) as string[]
68
+ const parentTrackKeys = [
69
+ 'superTrack',
70
+ 'compositeTrack',
71
+ 'container',
72
+ 'view',
73
+ ]
74
+ if (trackKeys.some(key => parentTrackKeys.includes(key))) {
75
+ return
76
+ }
77
+ const parentTracks = []
78
+ let currentTrackName = trackName
79
+ do {
80
+ currentTrackName = trackDb.get(currentTrackName)?.get('parent') || ''
81
+ if (currentTrackName) {
82
+ ;[currentTrackName] = currentTrackName.split(' ')
83
+ parentTracks.push(trackDb.get(currentTrackName))
84
+ }
85
+ } while (currentTrackName)
86
+ parentTracks.reverse()
87
+ const categories = parentTracks
88
+ .map(p => p?.get('shortLabel'))
89
+ .filter((f): f is string => !!f)
90
+ const res = makeTrackConfig(
91
+ track,
92
+ categories,
93
+ trackDbLoc,
94
+ trackDb,
95
+ sequenceAdapter,
96
+ )
97
+ tracks.push({
98
+ ...res,
99
+ trackId: `ucsc-trackhub-${objectHash(res)}`,
100
+ assemblyNames: [assemblyName],
101
+ })
102
+ })
103
+
104
+ return tracks
105
+ }
106
+
107
+ function makeTrackConfig(
108
+ track: RaStanza,
109
+ categories: string[],
110
+ trackDbLoc: FileLocation,
111
+ trackDb: TrackDbFile,
112
+ sequenceAdapter: any,
113
+ ) {
114
+ let trackType = track.get('type')
115
+ const name = track.get('shortLabel') || ''
116
+ const bigDataUrl = track.get('bigDataUrl') || ''
117
+ const bigDataIdx = track.get('bigDataIndex') || ''
118
+ const isUri = isUriLocation(trackDbLoc)
119
+ if (!trackType) {
120
+ trackType = trackDb.get(track.get('parent') || '')?.get('type')
121
+ }
122
+ let baseTrackType = trackType?.split(' ')[0] || ''
123
+ if (baseTrackType === 'bam' && bigDataUrl.toLowerCase().endsWith('cram')) {
124
+ baseTrackType = 'cram'
125
+ }
126
+ const bigDataLocation = isUri
127
+ ? makeLoc(bigDataUrl, trackDbLoc)
128
+ : makeLoc2(bigDataUrl)
129
+
130
+ switch (baseTrackType) {
131
+ case 'bam':
132
+ return {
133
+ type: 'AlignmentsTrack',
134
+ name: track.get('shortLabel'),
135
+ description: track.get('longLabel'),
136
+ category: categories,
137
+ adapter: {
138
+ type: 'BamAdapter',
139
+ bamLocation: bigDataLocation,
140
+ index: {
141
+ location: isUri
142
+ ? makeLocAlt(bigDataIdx, bigDataUrl + '.bai', trackDbLoc)
143
+ : makeLoc2(bigDataIdx, bigDataUrl + '.bai'),
144
+ },
145
+ },
146
+ }
147
+
148
+ case 'bigBarChart':
149
+ return {
150
+ type: 'FeatureTrack',
151
+ name,
152
+ description: track.get('longLabel'),
153
+ category: categories,
154
+ adapter: {
155
+ type: 'BigBedAdapter',
156
+ bigBedLocation: bigDataLocation,
157
+ },
158
+ renderer: {
159
+ type: 'SvgFeatureRenderer',
160
+ },
161
+ }
162
+ case 'bigBed':
163
+ return {
164
+ type: 'FeatureTrack',
165
+ name,
166
+ description: track.get('longLabel'),
167
+ category: categories,
168
+ adapter: {
169
+ type: 'BigBedAdapter',
170
+ bigBedLocation: bigDataLocation,
171
+ },
172
+ }
173
+ case 'bigGenePred':
174
+ return {
175
+ type: 'FeatureTrack',
176
+ name,
177
+ description: track.get('longLabel'),
178
+ category: categories,
179
+ adapter: {
180
+ type: 'BigBedAdapter',
181
+ bigBedLocation: bigDataLocation,
182
+ },
183
+ }
184
+ case 'bigChain':
185
+ return {
186
+ type: 'FeatureTrack',
187
+ name,
188
+ description: track.get('longLabel'),
189
+ category: categories,
190
+ adapter: {
191
+ type: 'BigBedAdapter',
192
+ bigBedLocation: bigDataLocation,
193
+ },
194
+ renderer: {
195
+ type: 'SvgFeatureRenderer',
196
+ },
197
+ }
198
+ case 'bigInteract':
199
+ return {
200
+ type: 'FeatureTrack',
201
+ name,
202
+ description: track.get('longLabel'),
203
+ category: categories,
204
+ adapter: {
205
+ type: 'BigBedAdapter',
206
+ bigBedLocation: bigDataLocation,
207
+ },
208
+ renderer: {
209
+ type: 'SvgFeatureRenderer',
210
+ },
211
+ }
212
+ case 'bigMaf':
213
+ return {
214
+ type: 'FeatureTrack',
215
+ name,
216
+ description: track.get('longLabel'),
217
+ category: categories,
218
+ adapter: {
219
+ type: 'BigBedAdapter',
220
+ bigBedLocation: bigDataLocation,
221
+ },
222
+ renderer: {
223
+ type: 'SvgFeatureRenderer',
224
+ },
225
+ }
226
+ case 'bigPsl':
227
+ return {
228
+ type: 'FeatureTrack',
229
+ name,
230
+ description: track.get('longLabel'),
231
+ category: categories,
232
+ adapter: {
233
+ type: 'BigBedAdapter',
234
+ bigBedLocation: bigDataLocation,
235
+ },
236
+ renderer: {
237
+ type: 'SvgFeatureRenderer',
238
+ },
239
+ }
240
+ case 'bigWig':
241
+ return {
242
+ type: 'QuantitativeTrack',
243
+ name,
244
+ description: track.get('longLabel'),
245
+ category: categories,
246
+ adapter: {
247
+ type: 'BigWigAdapter',
248
+ bigWigLocation: bigDataLocation,
249
+ },
250
+ }
251
+
252
+ case 'cram':
253
+ return {
254
+ type: 'AlignmentsTrack',
255
+ name,
256
+ description: track.get('longLabel'),
257
+ category: categories,
258
+ adapter: {
259
+ type: 'CramAdapter',
260
+ cramLocation: bigDataLocation,
261
+ craiLocation: isUri
262
+ ? makeLocAlt(bigDataIdx, bigDataUrl + '.crai', trackDbLoc)
263
+ : makeLoc2(bigDataIdx, bigDataUrl + '.crai'),
264
+ sequenceAdapter,
265
+ },
266
+ }
267
+
268
+ case 'bigNarrowPeak':
269
+ return {
270
+ type: 'FeatureTrack',
271
+ name,
272
+ description: track.get('longLabel'),
273
+ category: categories,
274
+ adapter: {
275
+ type: 'BigBedAdapter',
276
+ bigBedLocation: bigDataLocation,
277
+ },
278
+ }
279
+ case 'peptideMapping':
280
+ return generateUnsupportedTrackConf(name, baseTrackType, categories)
281
+ case 'vcfTabix':
282
+ return {
283
+ type: 'VariantTrack',
284
+ name,
285
+ description: track.get('longLabel'),
286
+ category: categories,
287
+ adapter: {
288
+ type: 'VcfTabixAdapter',
289
+ vcfGzLocation: bigDataLocation,
290
+ index: {
291
+ location: isUri
292
+ ? makeLocAlt(bigDataIdx, bigDataUrl + '.tbi', trackDbLoc)
293
+ : makeLoc2(bigDataIdx, bigDataUrl + '.tbi'),
294
+ },
295
+ },
296
+ }
297
+
298
+ case 'hic':
299
+ return {
300
+ type: 'HicTrack',
301
+ name,
302
+ description: track.get('longLabel'),
303
+ category: categories,
304
+ adapter: {
305
+ type: 'HicAdapter',
306
+ hicLocation: bigDataLocation,
307
+ },
308
+ }
309
+
310
+ // unsupported types
311
+ // case 'gvf':
312
+ // case 'ld2':
313
+ // case 'narrowPeak':
314
+ // case 'wig':
315
+ // case 'wigMaf':
316
+ // case 'halSnake':
317
+ // case 'bed':
318
+ // case 'bed5FloatScore':
319
+ // case 'bedGraph':
320
+ // case 'bedRnaElements':
321
+ // case 'broadPeak':
322
+ // case 'coloredExon':
323
+ default:
324
+ return generateUnknownTrackConf(name, baseTrackType, categories)
325
+ }
326
+ }
@@ -1,123 +0,0 @@
1
- import React from 'react'
2
- import { getSnapshot, getParent } from 'mobx-state-tree'
3
- import { ThemeProvider } from '@mui/material/styles'
4
- import { render, cleanup, fireEvent, waitFor } from '@testing-library/react'
5
- import { createJBrowseTheme } from '@jbrowse/core/ui'
6
- import { createTestSession } from '@jbrowse/web/src/rootModel'
7
-
8
- import PluginStoreWidget from './PluginStoreWidget'
9
- jest.mock('@jbrowse/web/src/makeWorkerInstance', () => () => {})
10
-
11
- const plugins = {
12
- plugins: [
13
- {
14
- name: 'MsaView',
15
- authors: ['Colin Diesh'],
16
- description: 'multiple sequence alignment browser plugin for JBrowse 2',
17
- location: 'https://github.com/GMOD/jbrowse-plugin-msaview',
18
- url: 'https://unpkg.com/jbrowse-plugin-msaview/dist/jbrowse-plugin-msaview.umd.production.min.js',
19
- license: 'Apache License 2.0',
20
- image:
21
- 'https://raw.githubusercontent.com/GMOD/jbrowse-plugin-list/main/img/msaview-screenshot-fs8.png',
22
- },
23
- ],
24
- }
25
-
26
- describe('<PluginStoreWidget />', () => {
27
- let session
28
- let model
29
-
30
- beforeEach(() => {
31
- session = createTestSession()
32
- model = session.addWidget('PluginStoreWidget', 'pluginStoreWidget')
33
- const { location } = window
34
- delete window.location
35
- window.location = {
36
- ...location,
37
- reload: jest.fn(),
38
- }
39
- fetch.resetMocks()
40
- fetch.mockResponse(JSON.stringify(plugins))
41
- })
42
-
43
- afterEach(cleanup)
44
-
45
- it('renders with the available plugins', async () => {
46
- const { container, findByText } = render(
47
- <ThemeProvider theme={createJBrowseTheme()}>
48
- <PluginStoreWidget model={model} />
49
- </ThemeProvider>,
50
- )
51
- await findByText('multiple sequence alignment browser plugin for JBrowse 2')
52
- expect(container.firstChild).toMatchSnapshot()
53
- })
54
-
55
- it('Installs a session plugin', async () => {
56
- const { findByText } = render(
57
- <ThemeProvider theme={createJBrowseTheme()}>
58
- <PluginStoreWidget model={model} />
59
- </ThemeProvider>,
60
- )
61
- await findByText('multiple sequence alignment browser plugin for JBrowse 2')
62
- fireEvent.click(await findByText('Install'))
63
- await waitFor(() => {
64
- expect(window.location.reload).toHaveBeenCalled()
65
- })
66
- expect(getSnapshot(session.sessionPlugins)[0]).toEqual(plugins.plugins[0])
67
- })
68
-
69
- it('plugin store admin - adds a custom plugin correctly', async () => {
70
- session = createTestSession({}, true)
71
- model = session.addWidget('PluginStoreWidget', 'pluginStoreWidget')
72
- const { findByText, getByText, getByLabelText } = render(
73
- <ThemeProvider theme={createJBrowseTheme()}>
74
- <PluginStoreWidget model={model} />
75
- </ThemeProvider>,
76
- )
77
- await findByText('multiple sequence alignment browser plugin for JBrowse 2')
78
- fireEvent.click(getByText('Add custom plugin'))
79
- fireEvent.change(getByLabelText('Plugin URL'), {
80
- target: {
81
- value:
82
- 'https://unpkg.com/jbrowse-plugin-msaview/dist/jbrowse-plugin-msaview.esm.js',
83
- },
84
- })
85
- fireEvent.change(getByLabelText('Plugin name'), {
86
- target: {
87
- value: 'MsaView',
88
- },
89
- })
90
- fireEvent.click(getByText('Submit'))
91
-
92
- await waitFor(() => {
93
- expect(window.location.reload).toHaveBeenCalled()
94
- })
95
-
96
- expect(getSnapshot(getParent(session)).jbrowse.plugins).toEqual([
97
- {
98
- name: 'MsaView',
99
- umdUrl:
100
- 'https://unpkg.com/jbrowse-plugin-msaview/dist/jbrowse-plugin-msaview.esm.js',
101
- },
102
- ])
103
- })
104
-
105
- it('plugin store admin - removes a custom plugin correctly', async () => {
106
- session = createTestSession({}, true)
107
- model = session.addWidget('PluginStoreWidget', 'pluginStoreWidget')
108
- const rootModel = getParent(session)
109
- const { jbrowse } = rootModel
110
- jbrowse.addPlugin(plugins.plugins[0])
111
- const { findByText, getByText, getByTestId } = render(
112
- <ThemeProvider theme={createJBrowseTheme()}>
113
- <PluginStoreWidget model={model} />
114
- </ThemeProvider>,
115
- )
116
- await findByText('multiple sequence alignment browser plugin for JBrowse 2')
117
- fireEvent.click(getByTestId('removePlugin-SVGPlugin'))
118
- fireEvent.click(getByText('Confirm'))
119
- await waitFor(() => {
120
- expect(window.location.reload).toHaveBeenCalled()
121
- })
122
- })
123
- })
@@ -1,9 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Data management adds config editor widget 1`] = `{}`;
4
-
5
- exports[`Data management adds connection add widget 1`] = `{}`;
6
-
7
- exports[`Data management adds hierarchical track selector 1`] = `{}`;
8
-
9
- exports[`Data management adds track add widget 1`] = `{}`;
package/src/index.test.js DELETED
@@ -1,61 +0,0 @@
1
- import PluginManager from '@jbrowse/core/PluginManager'
2
- import Config from '@jbrowse/plugin-config'
3
- import { getSnapshot } from 'mobx-state-tree'
4
- import ThisPlugin from '.'
5
-
6
- describe('Data management', () => {
7
- let pluginManager
8
-
9
- beforeAll(() => {
10
- const originalConsoleWarn = console.warn
11
- console.warn = jest.fn()
12
- pluginManager = new PluginManager([new ThisPlugin(), new Config()])
13
- pluginManager.createPluggableElements()
14
- pluginManager.configure()
15
- console.warn = originalConsoleWarn
16
- })
17
-
18
- it("won't add if already added", () => {
19
- expect(() => pluginManager.addPlugin(new ThisPlugin())).toThrow(
20
- /JBrowse already configured, cannot add plugins/,
21
- )
22
- })
23
-
24
- it('adds track add widget', () => {
25
- const AddTrackWidget = pluginManager.getWidgetType('AddTrackWidget')
26
- const config = AddTrackWidget.configSchema.create({
27
- type: 'AddTrackWidget',
28
- })
29
- expect(getSnapshot(config)).toMatchSnapshot()
30
- })
31
-
32
- it('adds config editor widget', () => {
33
- const ConfigurationEditorWidget = pluginManager.getWidgetType(
34
- 'ConfigurationEditorWidget',
35
- )
36
- const config = ConfigurationEditorWidget.configSchema.create({
37
- type: 'ConfigurationEditorWidget',
38
- })
39
- expect(getSnapshot(config)).toMatchSnapshot()
40
- })
41
-
42
- it('adds connection add widget', () => {
43
- const AddConnectionWidget = pluginManager.getWidgetType(
44
- 'AddConnectionWidget',
45
- )
46
- const config = AddConnectionWidget.configSchema.create({
47
- type: 'AddConnectionWidget',
48
- })
49
- expect(getSnapshot(config)).toMatchSnapshot()
50
- })
51
-
52
- it('adds hierarchical track selector', () => {
53
- const HierarchicalTrackSelectorWidget = pluginManager.getWidgetType(
54
- 'HierarchicalTrackSelectorWidget',
55
- )
56
- const config = HierarchicalTrackSelectorWidget.configSchema.create({
57
- type: 'HierarchicalTrackSelectorWidget',
58
- })
59
- expect(getSnapshot(config)).toMatchSnapshot()
60
- })
61
- })