@jbrowse/plugin-data-management 2.3.1 → 2.3.2

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.
@@ -1,442 +0,0 @@
1
- import { objectHash } from '@jbrowse/core/util'
2
- import { openLocation } from '@jbrowse/core/util/io'
3
- import {
4
- generateUnsupportedTrackConf,
5
- generateUnknownTrackConf,
6
- } from '@jbrowse/core/util/tracks'
7
- import ucscAssemblies from './ucscAssemblies'
8
-
9
- export { ucscAssemblies }
10
-
11
- export async function fetchHubFile(hubFileLocation) {
12
- try {
13
- const hubFileText = await openLocation(hubFileLocation).readFile('utf8')
14
- const { HubFile } = await import('@gmod/ucsc-hub')
15
- return new HubFile(hubFileText)
16
- } catch (error) {
17
- throw new Error(`Not a valid hub.txt file, got error: '${error}'`)
18
- }
19
- }
20
-
21
- export async function fetchGenomesFile(genomesFileLocation) {
22
- const genomesFileText = await openLocation(genomesFileLocation).readFile(
23
- 'utf8',
24
- )
25
- const { GenomesFile } = await import('@gmod/ucsc-hub')
26
- return new GenomesFile(genomesFileText)
27
- }
28
-
29
- export async function fetchTrackDbFile(trackDbFileLocation) {
30
- const text = await openLocation(trackDbFileLocation).readFile('utf8')
31
- const { TrackDbFile } = await import('@gmod/ucsc-hub')
32
- return new TrackDbFile(text)
33
- }
34
-
35
- export function generateTracks(
36
- trackDb,
37
- trackDbFileLocation,
38
- assemblyName,
39
- sequenceAdapter,
40
- ) {
41
- const tracks = []
42
-
43
- trackDb.forEach((track, trackName) => {
44
- const trackKeys = Array.from(track.keys())
45
- const parentTrackKeys = [
46
- 'superTrack',
47
- 'compositeTrack',
48
- 'container',
49
- 'view',
50
- ]
51
- if (trackKeys.some(key => parentTrackKeys.includes(key))) {
52
- return
53
- }
54
- const parentTracks = []
55
- let currentTrackName = trackName
56
- do {
57
- currentTrackName = trackDb.get(currentTrackName).get('parent')
58
- if (currentTrackName) {
59
- ;[currentTrackName] = currentTrackName.split(' ')
60
- parentTracks.push(trackDb.get(currentTrackName))
61
- }
62
- } while (currentTrackName)
63
- parentTracks.reverse()
64
- const categories = parentTracks.map(parentTrack =>
65
- parentTrack.get('shortLabel'),
66
- )
67
- const res = makeTrackConfig(
68
- track,
69
- categories,
70
- trackDbFileLocation,
71
- trackDb,
72
- sequenceAdapter,
73
- )
74
- res.trackId = `ucsc-trackhub-${objectHash(res)}`
75
- res.assemblyNames = [assemblyName]
76
- tracks.push(res)
77
- })
78
-
79
- return tracks
80
- }
81
-
82
- function makeTrackConfig(
83
- track,
84
- categories,
85
- trackDbFileLocation,
86
- trackDb,
87
- sequenceAdapter,
88
- ) {
89
- let trackType = track.get('type')
90
- if (!trackType) {
91
- trackType = trackDb.get(track.get('parent')).get('type')
92
- }
93
- let baseTrackType = trackType.split(' ')[0]
94
- if (
95
- baseTrackType === 'bam' &&
96
- track.get('bigDataUrl').toLowerCase().endsWith('cram')
97
- ) {
98
- baseTrackType = 'cram'
99
- }
100
- let bigDataLocation
101
- if (trackDbFileLocation.uri) {
102
- bigDataLocation = {
103
- uri: new URL(track.get('bigDataUrl'), trackDbFileLocation.uri).href,
104
- locationType: 'UriLocation',
105
- }
106
- } else {
107
- bigDataLocation = {
108
- localPath: track.get('bigDataUrl'),
109
- locationType: 'LocalPathLocation',
110
- }
111
- }
112
- let bigDataIndexLocation
113
-
114
- switch (baseTrackType) {
115
- case 'bam':
116
- if (trackDbFileLocation.uri) {
117
- bigDataIndexLocation = track.get('bigDataIndex')
118
- ? {
119
- uri: new URL(track.get('bigDataIndex'), trackDbFileLocation.uri)
120
- .href,
121
- locationType: 'UriLocation',
122
- }
123
- : {
124
- uri: new URL(
125
- `${track.get('bigDataUrl')}.bai`,
126
- trackDbFileLocation.uri,
127
- ).href,
128
- locationType: 'UriLocation',
129
- }
130
- } else {
131
- bigDataIndexLocation = track.get('bigDataIndex')
132
- ? {
133
- localPath: track.get('bigDataIndex'),
134
- locationType: 'LocalPathLocation',
135
- }
136
- : {
137
- localPath: `${track.get('bigDataUrl')}.bai`,
138
- locationType: 'LocalPathLocation',
139
- }
140
- }
141
- return {
142
- type: 'AlignmentsTrack',
143
- name: track.get('shortLabel'),
144
- description: track.get('longLabel'),
145
- category: categories,
146
- adapter: {
147
- type: 'BamAdapter',
148
- bamLocation: bigDataLocation,
149
- index: {
150
- location: bigDataIndexLocation,
151
- },
152
- },
153
- }
154
- case 'bed':
155
- return generateUnsupportedTrackConf(
156
- track.get('shortLabel'),
157
- baseTrackType,
158
- categories,
159
- )
160
- case 'bed5FloatScore':
161
- return generateUnsupportedTrackConf(
162
- track.get('shortLabel'),
163
- baseTrackType,
164
- categories,
165
- )
166
- case 'bedGraph':
167
- return generateUnsupportedTrackConf(
168
- track.get('shortLabel'),
169
- baseTrackType,
170
- categories,
171
- )
172
- case 'bedRnaElements':
173
- return generateUnsupportedTrackConf(
174
- track.get('shortLabel'),
175
- baseTrackType,
176
- categories,
177
- )
178
- case 'bigBarChart':
179
- return {
180
- type: 'FeatureTrack',
181
- name: track.get('shortLabel'),
182
- description: track.get('longLabel'),
183
- category: categories,
184
- adapter: {
185
- type: 'BigBedAdapter',
186
- bigBedLocation: bigDataLocation,
187
- },
188
- renderer: {
189
- type: 'SvgFeatureRenderer',
190
- },
191
- }
192
- case 'bigBed':
193
- return {
194
- type: 'FeatureTrack',
195
- name: track.get('shortLabel'),
196
- description: track.get('longLabel'),
197
- category: categories,
198
- adapter: {
199
- type: 'BigBedAdapter',
200
- bigBedLocation: bigDataLocation,
201
- },
202
- }
203
- case 'bigGenePred':
204
- return {
205
- type: 'FeatureTrack',
206
- name: track.get('shortLabel'),
207
- description: track.get('longLabel'),
208
- category: categories,
209
- adapter: {
210
- type: 'BigBedAdapter',
211
- bigBedLocation: bigDataLocation,
212
- },
213
- }
214
- case 'bigChain':
215
- return {
216
- type: 'FeatureTrack',
217
- name: track.get('shortLabel'),
218
- description: track.get('longLabel'),
219
- category: categories,
220
- adapter: {
221
- type: 'BigBedAdapter',
222
- bigBedLocation: bigDataLocation,
223
- },
224
- renderer: {
225
- type: 'SvgFeatureRenderer',
226
- },
227
- }
228
- case 'bigInteract':
229
- return {
230
- type: 'FeatureTrack',
231
- name: track.get('shortLabel'),
232
- description: track.get('longLabel'),
233
- category: categories,
234
- adapter: {
235
- type: 'BigBedAdapter',
236
- bigBedLocation: bigDataLocation,
237
- },
238
- renderer: {
239
- type: 'SvgFeatureRenderer',
240
- },
241
- }
242
- case 'bigMaf':
243
- return {
244
- type: 'FeatureTrack',
245
- name: track.get('shortLabel'),
246
- description: track.get('longLabel'),
247
- category: categories,
248
- adapter: {
249
- type: 'BigBedAdapter',
250
- bigBedLocation: bigDataLocation,
251
- },
252
- renderer: {
253
- type: 'SvgFeatureRenderer',
254
- },
255
- }
256
- case 'bigPsl':
257
- return {
258
- type: 'FeatureTrack',
259
- name: track.get('shortLabel'),
260
- description: track.get('longLabel'),
261
- category: categories,
262
- adapter: {
263
- type: 'BigBedAdapter',
264
- bigBedLocation: bigDataLocation,
265
- },
266
- renderer: {
267
- type: 'SvgFeatureRenderer',
268
- },
269
- }
270
- case 'bigWig':
271
- return {
272
- type: 'QuantitativeTrack',
273
- name: track.get('shortLabel'),
274
- description: track.get('longLabel'),
275
- category: categories,
276
- adapter: {
277
- type: 'BigWigAdapter',
278
- bigWigLocation: bigDataLocation,
279
- },
280
- }
281
- case 'broadPeak':
282
- return generateUnsupportedTrackConf(
283
- track.get('shortLabel'),
284
- baseTrackType,
285
- categories,
286
- )
287
- case 'coloredExon':
288
- return generateUnsupportedTrackConf(
289
- track.get('shortLabel'),
290
- baseTrackType,
291
- categories,
292
- )
293
- case 'cram':
294
- if (trackDbFileLocation.uri) {
295
- bigDataIndexLocation = track.get('bigDataIndex')
296
- ? {
297
- uri: new URL(track.get('bigDataIndex'), trackDbFileLocation.uri)
298
- .href,
299
- locationType: 'UriLocation',
300
- }
301
- : {
302
- uri: new URL(
303
- `${track.get('bigDataUrl')}.crai`,
304
- trackDbFileLocation.uri,
305
- ).href,
306
- locationType: 'UriLocation',
307
- }
308
- } else {
309
- bigDataIndexLocation = track.get('bigDataIndex')
310
- ? {
311
- localPath: track.get('bigDataIndex'),
312
- locationType: 'LocalPathLocation',
313
- }
314
- : {
315
- localPath: `${track.get('bigDataUrl')}.crai`,
316
- locationType: 'LocalPathLocation',
317
- }
318
- }
319
- return {
320
- type: 'AlignmentsTrack',
321
- name: track.get('shortLabel'),
322
- description: track.get('longLabel'),
323
- category: categories,
324
- adapter: {
325
- type: 'CramAdapter',
326
- cramLocation: bigDataLocation,
327
- craiLocation: bigDataIndexLocation,
328
- sequenceAdapter,
329
- },
330
- }
331
- case 'gvf':
332
- return generateUnsupportedTrackConf(
333
- track.get('shortLabel'),
334
- baseTrackType,
335
- categories,
336
- )
337
- case 'ld2':
338
- return generateUnsupportedTrackConf(
339
- track.get('shortLabel'),
340
- baseTrackType,
341
- categories,
342
- )
343
- case 'narrowPeak':
344
- return generateUnsupportedTrackConf(
345
- track.get('shortLabel'),
346
- baseTrackType,
347
- categories,
348
- )
349
- case 'bigNarrowPeak':
350
- return {
351
- type: 'FeatureTrack',
352
- name: track.get('shortLabel'),
353
- description: track.get('longLabel'),
354
- category: categories,
355
- adapter: {
356
- type: 'BigBedAdapter',
357
- bigBedLocation: bigDataLocation,
358
- },
359
- }
360
- case 'peptideMapping':
361
- return generateUnsupportedTrackConf(
362
- track.get('shortLabel'),
363
- baseTrackType,
364
- categories,
365
- )
366
- case 'vcfTabix':
367
- if (trackDbFileLocation.uri) {
368
- bigDataIndexLocation = track.get('bigDataIndex')
369
- ? {
370
- uri: new URL(track.get('bigDataIndex'), trackDbFileLocation.uri)
371
- .href,
372
- locationType: 'UriLocation',
373
- }
374
- : {
375
- uri: new URL(
376
- `${track.get('bigDataUrl')}.tbi`,
377
- trackDbFileLocation.uri,
378
- ).href,
379
- locationType: 'UriLocation',
380
- }
381
- } else {
382
- bigDataIndexLocation = track.get('bigDataIndex')
383
- ? {
384
- localPath: track.get('bigDataIndex'),
385
- locationType: 'LocalPathLocation',
386
- }
387
- : {
388
- localPath: `${track.get('bigDataUrl')}.tbi`,
389
- locationType: 'LocalPathLocation',
390
- }
391
- }
392
- return {
393
- type: 'VariantTrack',
394
- name: track.get('shortLabel'),
395
- description: track.get('longLabel'),
396
- category: categories,
397
- adapter: {
398
- type: 'VcfTabixAdapter',
399
- vcfGzLocation: bigDataLocation,
400
- index: {
401
- location: bigDataIndexLocation,
402
- },
403
- },
404
- }
405
- case 'wig':
406
- return generateUnsupportedTrackConf(
407
- track.get('shortLabel'),
408
- baseTrackType,
409
- categories,
410
- )
411
- case 'wigMaf':
412
- return generateUnsupportedTrackConf(
413
- track.get('shortLabel'),
414
- baseTrackType,
415
- categories,
416
- )
417
- case 'hic':
418
- return {
419
- type: 'HicTrack',
420
- name: track.get('shortLabel'),
421
- description: track.get('longLabel'),
422
- category: categories,
423
- adapter: {
424
- type: 'HicAdapter',
425
- hicLocation: bigDataLocation,
426
- },
427
- }
428
- case 'halSnake':
429
- return generateUnsupportedTrackConf(
430
- track.get('shortLabel'),
431
- baseTrackType,
432
- categories,
433
- )
434
-
435
- default:
436
- return generateUnknownTrackConf(
437
- track.get('shortLabel'),
438
- baseTrackType,
439
- categories,
440
- )
441
- }
442
- }