@jbrowse/plugin-legacy-jbrowse 2.6.1 → 2.6.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.
Files changed (97) hide show
  1. package/dist/GuessNCList/index.js +0 -1
  2. package/dist/JBrowse1Connection/configSchema.js +0 -1
  3. package/dist/JBrowse1Connection/index.js +0 -1
  4. package/dist/JBrowse1Connection/jb1ConfigLoad.js +0 -1
  5. package/dist/JBrowse1Connection/jb1ConfigParse.js +0 -1
  6. package/dist/JBrowse1Connection/jb1ToJb2.js +0 -1
  7. package/dist/JBrowse1Connection/model.js +0 -1
  8. package/dist/JBrowse1Connection/types.js +0 -1
  9. package/dist/JBrowse1Connection/util.js +0 -1
  10. package/dist/JBrowse1TextSearchAdapter/HttpMap.js +0 -1
  11. package/dist/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js +0 -1
  12. package/dist/JBrowse1TextSearchAdapter/configSchema.js +0 -1
  13. package/dist/JBrowse1TextSearchAdapter/index.js +0 -1
  14. package/dist/NCListAdapter/NCListAdapter.js +0 -1
  15. package/dist/NCListAdapter/NCListFeature.js +0 -1
  16. package/dist/NCListAdapter/configSchema.js +0 -1
  17. package/dist/NCListAdapter/index.js +0 -1
  18. package/dist/index.js +0 -1
  19. package/esm/GuessNCList/index.js +0 -1
  20. package/esm/JBrowse1Connection/configSchema.js +0 -1
  21. package/esm/JBrowse1Connection/index.js +0 -1
  22. package/esm/JBrowse1Connection/jb1ConfigLoad.js +0 -1
  23. package/esm/JBrowse1Connection/jb1ConfigParse.js +0 -1
  24. package/esm/JBrowse1Connection/jb1ToJb2.js +0 -1
  25. package/esm/JBrowse1Connection/model.js +0 -1
  26. package/esm/JBrowse1Connection/types.js +0 -1
  27. package/esm/JBrowse1Connection/util.js +0 -1
  28. package/esm/JBrowse1TextSearchAdapter/HttpMap.js +0 -1
  29. package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js +0 -1
  30. package/esm/JBrowse1TextSearchAdapter/configSchema.js +0 -1
  31. package/esm/JBrowse1TextSearchAdapter/index.js +0 -1
  32. package/esm/NCListAdapter/NCListAdapter.js +0 -1
  33. package/esm/NCListAdapter/NCListFeature.js +0 -1
  34. package/esm/NCListAdapter/configSchema.js +0 -1
  35. package/esm/NCListAdapter/index.js +0 -1
  36. package/esm/index.js +0 -1
  37. package/package.json +3 -4
  38. package/dist/GuessNCList/index.js.map +0 -1
  39. package/dist/JBrowse1Connection/configSchema.js.map +0 -1
  40. package/dist/JBrowse1Connection/index.js.map +0 -1
  41. package/dist/JBrowse1Connection/jb1ConfigLoad.js.map +0 -1
  42. package/dist/JBrowse1Connection/jb1ConfigParse.js.map +0 -1
  43. package/dist/JBrowse1Connection/jb1ToJb2.js.map +0 -1
  44. package/dist/JBrowse1Connection/model.js.map +0 -1
  45. package/dist/JBrowse1Connection/types.js.map +0 -1
  46. package/dist/JBrowse1Connection/util.js.map +0 -1
  47. package/dist/JBrowse1TextSearchAdapter/HttpMap.js.map +0 -1
  48. package/dist/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js.map +0 -1
  49. package/dist/JBrowse1TextSearchAdapter/configSchema.js.map +0 -1
  50. package/dist/JBrowse1TextSearchAdapter/index.js.map +0 -1
  51. package/dist/NCListAdapter/NCListAdapter.js.map +0 -1
  52. package/dist/NCListAdapter/NCListFeature.js.map +0 -1
  53. package/dist/NCListAdapter/configSchema.js.map +0 -1
  54. package/dist/NCListAdapter/index.js.map +0 -1
  55. package/dist/index.js.map +0 -1
  56. package/esm/GuessNCList/index.js.map +0 -1
  57. package/esm/JBrowse1Connection/configSchema.js.map +0 -1
  58. package/esm/JBrowse1Connection/index.js.map +0 -1
  59. package/esm/JBrowse1Connection/jb1ConfigLoad.js.map +0 -1
  60. package/esm/JBrowse1Connection/jb1ConfigParse.js.map +0 -1
  61. package/esm/JBrowse1Connection/jb1ToJb2.js.map +0 -1
  62. package/esm/JBrowse1Connection/model.js.map +0 -1
  63. package/esm/JBrowse1Connection/types.js.map +0 -1
  64. package/esm/JBrowse1Connection/util.js.map +0 -1
  65. package/esm/JBrowse1TextSearchAdapter/HttpMap.js.map +0 -1
  66. package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js.map +0 -1
  67. package/esm/JBrowse1TextSearchAdapter/configSchema.js.map +0 -1
  68. package/esm/JBrowse1TextSearchAdapter/index.js.map +0 -1
  69. package/esm/NCListAdapter/NCListAdapter.js.map +0 -1
  70. package/esm/NCListAdapter/NCListFeature.js.map +0 -1
  71. package/esm/NCListAdapter/configSchema.js.map +0 -1
  72. package/esm/NCListAdapter/index.js.map +0 -1
  73. package/esm/index.js.map +0 -1
  74. package/src/GuessNCList/index.ts +0 -27
  75. package/src/JBrowse1Connection/configSchema.ts +0 -42
  76. package/src/JBrowse1Connection/index.ts +0 -20
  77. package/src/JBrowse1Connection/jb1ConfigLoad.ts +0 -342
  78. package/src/JBrowse1Connection/jb1ConfigParse.ts +0 -423
  79. package/src/JBrowse1Connection/jb1ToJb2.ts +0 -529
  80. package/src/JBrowse1Connection/model.tsx +0 -69
  81. package/src/JBrowse1Connection/types.ts +0 -105
  82. package/src/JBrowse1Connection/util.ts +0 -149
  83. package/src/JBrowse1TextSearchAdapter/HttpMap.test.ts +0 -49
  84. package/src/JBrowse1TextSearchAdapter/HttpMap.ts +0 -100
  85. package/src/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.test.ts +0 -101
  86. package/src/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.ts +0 -100
  87. package/src/JBrowse1TextSearchAdapter/configSchema.ts +0 -44
  88. package/src/JBrowse1TextSearchAdapter/index.ts +0 -18
  89. package/src/NCListAdapter/NCListAdapter.test.ts +0 -58
  90. package/src/NCListAdapter/NCListAdapter.ts +0 -92
  91. package/src/NCListAdapter/NCListFeature.ts +0 -94
  92. package/src/NCListAdapter/__snapshots__/NCListAdapter.test.ts.snap +0 -30671
  93. package/src/NCListAdapter/configSchema.ts +0 -32
  94. package/src/NCListAdapter/index.ts +0 -16
  95. package/src/__snapshots__/index.test.ts.snap +0 -16
  96. package/src/index.test.ts +0 -35
  97. package/src/index.ts +0 -17
@@ -1,423 +0,0 @@
1
- /* eslint no-cond-assign: ["error", "except-parens"] */
2
- import getValue from 'get-value'
3
- import setValue from 'set-value'
4
- import { objectHash } from '@jbrowse/core/util'
5
- import { isSource, isTrack } from './util'
6
- import { Config, Track, Source, Store, Names } from './types'
7
-
8
- export function parseJB1Json(config: Config | string, url: string): Config {
9
- if (typeof config === 'string') {
10
- let parsedConf
11
- try {
12
- parsedConf = JSON.parse(config)
13
- } catch (error) {
14
- throw new Error(`${error} when parsing configuration.`)
15
- }
16
- return regularizeConf(parsedConf, url)
17
- }
18
- return regularizeConf(config, url)
19
- }
20
-
21
- export function parseJB1Conf(config: string, url: string): Config {
22
- let parsedConf
23
- try {
24
- parsedConf = parse(config, url)
25
- } catch (error) {
26
- throw new Error(`${error} when parsing configuration.`)
27
- }
28
- return regularizeConf(parsedConf, url)
29
- }
30
-
31
- function isAlwaysArray(varName: string): boolean {
32
- if (varName === 'include') {
33
- return true
34
- }
35
- return false
36
- }
37
-
38
- function parse(text: string, url: string): Config {
39
- let section: string[] = []
40
- let keyPath: string[] | undefined
41
- let operation: string
42
- let value: string | undefined
43
- const data: Config = { tracks: {} }
44
- let lineNumber: number
45
-
46
- function recordVal(): void {
47
- if (value !== undefined) {
48
- let parsedValue:
49
- | string
50
- | number
51
- | boolean
52
- | string[]
53
- | number[]
54
- | boolean[]
55
- try {
56
- // parse json
57
- const match = value.match(/^json:(.+)/i)
58
- if (match) {
59
- parsedValue = JSON.parse(match[1])
60
- }
61
- // parse numbers if it looks numeric
62
- else if (/^[+-]?[\d.,]+([eE][-+]?\d+)?$/.test(value)) {
63
- parsedValue = parseFloat(value.replaceAll(',', ''))
64
- } else {
65
- parsedValue = value
66
- }
67
-
68
- if (!keyPath) {
69
- throw new Error(`Error parsing in section ${section.join(' - ')}`)
70
- }
71
- const path = [...section, ...keyPath].join('.')
72
- if (operation === '+=') {
73
- let existing = getValue(data, path)
74
- if (existing) {
75
- if (!Array.isArray(existing)) {
76
- existing = [existing]
77
- }
78
- } else {
79
- existing = []
80
- }
81
-
82
- existing.push(parsedValue)
83
- parsedValue = existing
84
- }
85
- if (parsedValue === 'true') {
86
- parsedValue = true
87
- }
88
- if (parsedValue === 'false') {
89
- parsedValue = false
90
- }
91
- setValue(data, path, parsedValue)
92
- } catch (e) {
93
- throw new Error(
94
- `syntax error${url ? ` in ${url}` : ''}${
95
- lineNumber ? ` at line ${lineNumber - 1}` : ''
96
- }`,
97
- )
98
- }
99
- }
100
- }
101
-
102
- text.split(/\n|\r\n|\r/).forEach((textLine, i): void => {
103
- lineNumber = i + 1
104
- const line = textLine.replace(/^\s*#.+/, '')
105
-
106
- // new section
107
- let match: RegExpMatchArray | null
108
- if ((match = line.match(/^\s*\[([^\]]+)/))) {
109
- // new section
110
- recordVal()
111
- keyPath = undefined
112
- value = undefined
113
- section = match[1].trim().split(/\s*\.\s*/)
114
- if (section.length === 1 && section[0].toLowerCase() === 'general') {
115
- section = []
116
- }
117
- }
118
- // new value
119
- else if (
120
- (match = line.match(
121
- value === undefined ? /^([^+=]+)(\+?=)(.*)/ : /^(\S[^+=]+)(\+?=)(.*)/,
122
- ))
123
- ) {
124
- recordVal()
125
- keyPath = match[1].trim().split(/\s*\.\s*/)
126
- ;[, , operation] = match
127
- if (isAlwaysArray([...section, ...keyPath].join('.'))) {
128
- operation = '+='
129
- }
130
- value = match[3].trim()
131
- }
132
- // add to existing array value
133
- else if (
134
- keyPath !== undefined &&
135
- (match = line.match(/^\s{0,4}\+\s*(.+)/))
136
- ) {
137
- recordVal()
138
- operation = '+='
139
- value = match[1].trim()
140
- }
141
- // add to existing value
142
- else if (value !== undefined && (match = line.match(/^\s+(\S.*)/))) {
143
- value += value.length ? ` ${match[1].trim()}` : match[1].trim()
144
- }
145
- // done with last value
146
- else {
147
- recordVal()
148
- keyPath = undefined
149
- value = undefined
150
- }
151
- })
152
-
153
- recordVal()
154
-
155
- return data
156
- }
157
-
158
- /**
159
- * Applies defaults and any other necessary tweaks to the loaded configuration.
160
- * @param conf - the object containing the configuration, which it modifies
161
- * in-place
162
- * @param url - URL of the config file
163
- * @returns the same object it was passed
164
- */
165
- export function regularizeConf(conf: Config, url: string): Config {
166
- // if tracks is not an array, convert it to one
167
- if (conf.tracks && !Array.isArray(conf.tracks)) {
168
- // if it's a single track config, wrap it in an arrayref
169
- if (isTrack(conf.tracks)) {
170
- conf.tracks = [conf.tracks]
171
- }
172
- // otherwise, coerce it to an array
173
- else {
174
- const tracks: Track[] = []
175
- for (const label of Object.keys(conf.tracks)) {
176
- const track = conf.tracks[label]
177
- if (isTrack(track)) {
178
- tracks.push(track)
179
- } else {
180
- tracks.push({ label, ...track })
181
- }
182
- }
183
- conf.tracks = tracks
184
- }
185
- }
186
-
187
- // regularize trackMetadata.sources
188
- const meta = conf.trackMetadata
189
- if (meta && meta.sources) {
190
- // if it's a single source config, wrap it in an arrayref
191
- if (typeof meta.sources === 'string') {
192
- meta.sources = [meta.sources]
193
- }
194
- if (isSource(meta.sources)) {
195
- meta.sources = [meta.sources]
196
- }
197
-
198
- if (!Array.isArray(meta.sources)) {
199
- const sources: Source[] = []
200
- for (const name of Object.keys(meta.sources)) {
201
- const source = meta.sources[name]
202
- if (!('name' in source)) {
203
- source.name = name
204
- }
205
- sources.push(source)
206
- }
207
- meta.sources = sources
208
- }
209
-
210
- // coerce any string source defs to be URLs, and try to detect their types
211
- meta.sources = meta.sources.map((sourceDef: string | Source): Source => {
212
- if (typeof sourceDef === 'string') {
213
- const newSourceDef: Source = { url: sourceDef }
214
- const typeMatch = sourceDef.match(/\.(\w+)$/)
215
- if (typeMatch) {
216
- newSourceDef.type = typeMatch[1].toLowerCase()
217
- }
218
- return newSourceDef
219
- }
220
- return sourceDef
221
- })
222
- }
223
-
224
- conf.sourceUrl = conf.sourceUrl || url
225
- if (conf.sourceUrl.startsWith('/')) {
226
- conf.sourceUrl = new URL(conf.sourceUrl, window.location.href).href
227
- }
228
- conf.baseUrl = conf.baseUrl || new URL('.', conf.sourceUrl).href
229
- if (conf.baseUrl.length && !conf.baseUrl.endsWith('/')) {
230
- conf.baseUrl += '/'
231
- }
232
-
233
- if (conf.sourceUrl) {
234
- // set a default baseUrl in each of the track and store confs, and the names
235
- // conf, if needed
236
- const addBase: (Track | Store | Names)[] = []
237
- if (conf.tracks) {
238
- addBase.push(...conf.tracks)
239
- }
240
- if (conf.stores) {
241
- addBase.push(...Object.values(conf.stores))
242
- }
243
- if (conf.names) {
244
- addBase.push(conf.names)
245
- }
246
-
247
- addBase.forEach((t): void => {
248
- if (!t.baseUrl) {
249
- t.baseUrl = conf.baseUrl || '/'
250
- }
251
- })
252
-
253
- // resolve the refSeqs and nameUrl if present
254
- if (conf.refSeqs && typeof conf.refSeqs === 'string') {
255
- conf.refSeqs = new URL(conf.refSeqs, conf.sourceUrl).href
256
- }
257
- if (conf.nameUrl) {
258
- conf.nameUrl = new URL(conf.nameUrl, conf.sourceUrl).href
259
- }
260
- }
261
-
262
- conf.stores = conf.stores || {}
263
- ;(conf.tracks || []).forEach((trackConfig: Track): void => {
264
- // if there is a `config` subpart, just copy its keys in to the top-level
265
- // config
266
- if (trackConfig.config) {
267
- const c = trackConfig.config
268
- delete trackConfig.config
269
- trackConfig = { ...c, ...trackConfig }
270
- }
271
-
272
- // skip if it's a new-style track def
273
- if (trackConfig.store) {
274
- return
275
- }
276
-
277
- let trackClassName: string
278
- if (trackConfig.type === 'FeatureTrack') {
279
- trackClassName = 'JBrowse/View/Track/HTMLFeatures'
280
- } else if (trackConfig.type === 'ImageTrack') {
281
- trackClassName = 'JBrowse/View/Track/FixedImage'
282
- } else if (trackConfig.type === 'ImageTrack.Wiggle') {
283
- trackClassName = 'JBrowse/View/Track/FixedImage/Wiggle'
284
- } else if (trackConfig.type === 'SequenceTrack') {
285
- trackClassName = 'JBrowse/View/Track/Sequence'
286
- } else {
287
- trackClassName = regularizeClass('JBrowse/View/Track', trackConfig.type)
288
- }
289
-
290
- trackConfig.type = trackClassName
291
-
292
- synthesizeTrackStoreConfig(conf, trackConfig)
293
-
294
- if (trackConfig.histograms) {
295
- if (!trackConfig.histograms.baseUrl) {
296
- trackConfig.histograms.baseUrl = trackConfig.baseUrl
297
- }
298
- synthesizeTrackStoreConfig(conf, trackConfig.histograms)
299
- }
300
- })
301
-
302
- return conf
303
- }
304
-
305
- /**
306
- * prefix class name with `root` if it contains no slashes
307
- * @param root - Prefix root
308
- * @param className - class name
309
- */
310
- function regularizeClass(root: string, className: string | undefined): string {
311
- if (!className) {
312
- return ''
313
- }
314
- if (!className.includes('/')) {
315
- className = `${root}/${className}`
316
- }
317
- className = className.replace(/^\//, '')
318
- return className
319
- }
320
-
321
- function guessStoreClass(
322
- trackConfig: Track | undefined,
323
- urlTemplate: string,
324
- ): string {
325
- if (!trackConfig) {
326
- return ''
327
- }
328
- if (trackConfig.type && trackConfig.type.includes('/FixedImage')) {
329
- return `JBrowse/Store/TiledImage/Fixed${
330
- trackConfig.backendVersion === 0 ? '_v0' : ''
331
- }`
332
- }
333
- if (/\.jsonz?$/i.test(urlTemplate)) {
334
- return `JBrowse/Store/SeqFeature/NCList${
335
- trackConfig.backendVersion === 0 ? '_v0' : ''
336
- }`
337
- }
338
- if (/\.bam$/i.test(urlTemplate)) {
339
- return 'JBrowse/Store/SeqFeature/BAM'
340
- }
341
- if (/\.cram$/i.test(urlTemplate)) {
342
- return 'JBrowse/Store/SeqFeature/CRAM'
343
- }
344
- if (/\.gff3?$/i.test(urlTemplate)) {
345
- return 'JBrowse/Store/SeqFeature/GFF3'
346
- }
347
- if (/\.bed$/i.test(urlTemplate)) {
348
- return 'JBrowse/Store/SeqFeature/BED'
349
- }
350
- if (/\.vcf.b?gz$/i.test(urlTemplate)) {
351
- return 'JBrowse/Store/SeqFeature/VCFTabix'
352
- }
353
- if (/\.gff3?.b?gz$/i.test(urlTemplate)) {
354
- return 'JBrowse/Store/SeqFeature/GFF3Tabix'
355
- }
356
- if (/\.bed.b?gz$/i.test(urlTemplate)) {
357
- return 'JBrowse/Store/SeqFeature/BEDTabix'
358
- }
359
- if (/\.(bw|bigwig)$/i.test(urlTemplate)) {
360
- return 'JBrowse/Store/SeqFeature/BigWig'
361
- }
362
- if (/\.(bb|bigbed)$/i.test(urlTemplate)) {
363
- return 'JBrowse/Store/SeqFeature/BigBed'
364
- }
365
- if (/\.(fa|fasta)$/i.test(urlTemplate)) {
366
- return 'JBrowse/Store/SeqFeature/IndexedFasta'
367
- }
368
- if (/\.(fa|fasta)\.b?gz$/i.test(urlTemplate)) {
369
- return 'JBrowse/Store/SeqFeature/BgzipIndexedFasta'
370
- }
371
- if (/\.2bit$/i.test(urlTemplate)) {
372
- return 'JBrowse/Store/SeqFeature/TwoBit'
373
- }
374
- if (trackConfig.type && trackConfig.type.endsWith('/Sequence')) {
375
- return 'JBrowse/Store/Sequence/StaticChunked'
376
- }
377
- return ''
378
- }
379
-
380
- function synthesizeTrackStoreConfig(
381
- mainConf: Config,
382
- trackConfig: Track,
383
- ): void {
384
- // figure out what data store class to use with the track, applying some
385
- // defaults if it is not explicit in the configuration
386
- const { urlTemplate = '' } = trackConfig
387
-
388
- const storeClass = trackConfig.storeClass
389
- ? regularizeClass('JBrowse/Store', trackConfig.storeClass)
390
- : guessStoreClass(trackConfig, urlTemplate)
391
-
392
- if (!storeClass) {
393
- console.warn(
394
- `Unable to determine an appropriate data store to use with track '${trackConfig.label}', please explicitly specify a storeClass in the configuration.`,
395
- )
396
- return
397
- }
398
-
399
- // synthesize a separate store conf
400
- const storeConf: Store = { ...trackConfig, type: storeClass }
401
-
402
- // if this is the first sequence store we see, and we have no refseqs store
403
- // defined explicitly, make this the refseqs store.
404
- storeConf.name =
405
- (storeClass === 'JBrowse/Store/Sequence/StaticChunked' ||
406
- storeClass === 'JBrowse/Store/Sequence/IndexedFasta' ||
407
- storeClass === 'JBrowse/Store/SeqFeature/IndexedFasta' ||
408
- storeClass === 'JBrowse/Store/SeqFeature/BgzipIndexedFasta' ||
409
- storeClass === 'JBrowse/Store/SeqFeature/TwoBit' ||
410
- storeClass === 'JBrowse/Store/Sequence/TwoBit' ||
411
- trackConfig.useAsRefSeqStore) &&
412
- !(mainConf.stores && mainConf.stores.refseqs)
413
- ? 'refseqs'
414
- : `store${objectHash(storeConf)}`
415
- // record it
416
- if (!mainConf.stores) {
417
- mainConf.stores = {}
418
- }
419
- mainConf.stores[storeConf.name] = storeConf
420
-
421
- // connect it to the track conf
422
- trackConfig.store = storeConf.name
423
- }