@jbrowse/plugin-legacy-jbrowse 4.2.1 → 5.0.0-beta.1

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 (36) hide show
  1. package/esm/JBrowse1Connection/configSchema.d.ts +42 -18
  2. package/esm/JBrowse1Connection/configSchema.js +29 -3
  3. package/esm/JBrowse1Connection/get-value.d.ts +1 -10
  4. package/esm/JBrowse1Connection/get-value.js +9 -82
  5. package/esm/JBrowse1Connection/index.js +2 -2
  6. package/esm/JBrowse1Connection/jb1ConfigLoad.d.ts +9 -36
  7. package/esm/JBrowse1Connection/jb1ConfigLoad.js +72 -241
  8. package/esm/JBrowse1Connection/jb1ConfigParse.d.ts +6 -3
  9. package/esm/JBrowse1Connection/jb1ConfigParse.js +25 -250
  10. package/esm/JBrowse1Connection/jb1ToJb2.d.ts +8 -3
  11. package/esm/JBrowse1Connection/jb1ToJb2.js +124 -368
  12. package/esm/JBrowse1Connection/model.d.ts +57 -50
  13. package/esm/JBrowse1Connection/model.js +23 -9
  14. package/esm/JBrowse1Connection/set-value.d.ts +1 -0
  15. package/esm/JBrowse1Connection/set-value.js +14 -0
  16. package/esm/JBrowse1Connection/types.d.ts +4 -57
  17. package/esm/JBrowse1Connection/util.d.ts +13 -8
  18. package/esm/JBrowse1Connection/util.js +15 -80
  19. package/esm/JBrowse1TextSearchAdapter/HttpMap.d.ts +34 -7
  20. package/esm/JBrowse1TextSearchAdapter/HttpMap.js +49 -24
  21. package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.d.ts +5 -5
  22. package/esm/JBrowse1TextSearchAdapter/JBrowse1TextSearchAdapter.js +21 -22
  23. package/esm/JBrowse1TextSearchAdapter/configSchema.d.ts +42 -14
  24. package/esm/JBrowse1TextSearchAdapter/configSchema.js +31 -1
  25. package/esm/JBrowse1TextSearchAdapter/index.js +2 -2
  26. package/esm/NCListAdapter/NCListAdapter.d.ts +11 -1
  27. package/esm/NCListAdapter/NCListAdapter.js +12 -3
  28. package/esm/NCListAdapter/NCListFeature.d.ts +34 -3
  29. package/esm/NCListAdapter/NCListFeature.js +22 -8
  30. package/esm/NCListAdapter/configSchema.d.ts +35 -9
  31. package/esm/NCListAdapter/configSchema.js +26 -1
  32. package/esm/NCListAdapter/index.js +2 -2
  33. package/esm/index.js +3 -5
  34. package/package.json +9 -12
  35. package/esm/GuessNCList/index.d.ts +0 -2
  36. package/esm/GuessNCList/index.js +0 -15
@@ -1,37 +1,25 @@
1
- import { objectHash } from '@jbrowse/core/util';
2
- import setValue from 'set-value';
3
- import getValue from "./get-value.js";
4
- import { isSource, isTrack } from "./util.js";
5
- export function parseJB1Json(config, url) {
6
- if (typeof config === 'string') {
7
- let parsedConf;
1
+ /* eslint no-cond-assign: ["error", "except-parens"] */
2
+ import getValue from './get-value.js';
3
+ import setValue from './set-value.js';
4
+ /**
5
+ * Parse a JBrowse 1 config file. A `trackList.json` is JSON; a `tracks.conf`
6
+ * is JBrowse 1's own INI-like format, whose `[section.subsection]` headers and
7
+ * `key.subkey = value` lines both address a dotted path.
8
+ */
9
+ export function parseJb1(text, url = '') {
10
+ if (text.trimStart().startsWith('{')) {
8
11
  try {
9
- parsedConf = JSON.parse(config);
12
+ return JSON.parse(text);
10
13
  }
11
14
  catch (error) {
12
- throw new Error(`${error} when parsing configuration.`);
15
+ throw new Error(`${error} when parsing ${url || 'configuration'}`, {
16
+ cause: error,
17
+ });
13
18
  }
14
- return regularizeConf(parsedConf, url);
15
19
  }
16
- return regularizeConf(config, url);
20
+ return parseConf(text, url);
17
21
  }
18
- export function parseJB1Conf(config, url) {
19
- let parsedConf;
20
- try {
21
- parsedConf = parse(config, url);
22
- }
23
- catch (error) {
24
- throw new Error(`${error} when parsing configuration.`);
25
- }
26
- return regularizeConf(parsedConf, url);
27
- }
28
- function isAlwaysArray(varName) {
29
- if (varName === 'include') {
30
- return true;
31
- }
32
- return false;
33
- }
34
- function parse(text, url) {
22
+ function parseConf(text, url) {
35
23
  let section = [];
36
24
  let keyPath;
37
25
  let operation;
@@ -57,15 +45,12 @@ function parse(text, url) {
57
45
  }
58
46
  const path = [...section, ...keyPath].join('.');
59
47
  if (operation === '+=') {
60
- let existing = getValue(data, path);
61
- if (existing) {
62
- if (!Array.isArray(existing)) {
63
- existing = [existing];
64
- }
65
- }
66
- else {
67
- existing = [];
68
- }
48
+ const prev = getValue(data, path);
49
+ const existing = Array.isArray(prev)
50
+ ? prev
51
+ : prev
52
+ ? [prev]
53
+ : [];
69
54
  existing.push(parsedValue);
70
55
  parsedValue = existing;
71
56
  }
@@ -78,7 +63,7 @@ function parse(text, url) {
78
63
  setValue(data, path, parsedValue);
79
64
  }
80
65
  catch (e) {
81
- throw new Error(`syntax error${url ? ` in ${url}` : ''}${lineNumber ? ` at line ${lineNumber - 1}` : ''}`);
66
+ throw new Error(`syntax error${url ? ` in ${url}` : ''}${lineNumber ? ` at line ${lineNumber - 1}` : ''}`, { cause: e });
82
67
  }
83
68
  }
84
69
  }
@@ -98,8 +83,8 @@ function parse(text, url) {
98
83
  else if ((match = line.match(value === undefined ? /^([^+=]+)(\+?=)(.*)/ : /^(\S[^+=]+)(\+?=)(.*)/))) {
99
84
  recordVal();
100
85
  keyPath = match[1].trim().split(/\s*\.\s*/);
101
- [, , operation] = match;
102
- if (isAlwaysArray([...section, ...keyPath].join('.'))) {
86
+ operation = match[2];
87
+ if ([...section, ...keyPath].join('.') === 'include') {
103
88
  operation = '+=';
104
89
  }
105
90
  value = match[3].trim();
@@ -123,213 +108,3 @@ function parse(text, url) {
123
108
  recordVal();
124
109
  return data;
125
110
  }
126
- export function regularizeConf(conf, url) {
127
- if (conf.tracks && !Array.isArray(conf.tracks)) {
128
- if (isTrack(conf.tracks)) {
129
- conf.tracks = [conf.tracks];
130
- }
131
- else {
132
- const tracks = [];
133
- for (const label of Object.keys(conf.tracks)) {
134
- const track = conf.tracks[label];
135
- if (isTrack(track)) {
136
- tracks.push(track);
137
- }
138
- else {
139
- tracks.push({ label, ...track });
140
- }
141
- }
142
- conf.tracks = tracks;
143
- }
144
- }
145
- const meta = conf.trackMetadata;
146
- if (meta?.sources) {
147
- if (typeof meta.sources === 'string') {
148
- meta.sources = [meta.sources];
149
- }
150
- if (isSource(meta.sources)) {
151
- meta.sources = [meta.sources];
152
- }
153
- if (!Array.isArray(meta.sources)) {
154
- const sources = [];
155
- for (const name of Object.keys(meta.sources)) {
156
- const source = meta.sources[name];
157
- if (!('name' in source)) {
158
- source.name = name;
159
- }
160
- sources.push(source);
161
- }
162
- meta.sources = sources;
163
- }
164
- meta.sources = meta.sources.map((sourceDef) => {
165
- if (typeof sourceDef === 'string') {
166
- const newSourceDef = { url: sourceDef };
167
- const typeMatch = /\.(\w+)$/.exec(sourceDef);
168
- if (typeMatch) {
169
- newSourceDef.type = typeMatch[1].toLowerCase();
170
- }
171
- return newSourceDef;
172
- }
173
- return sourceDef;
174
- });
175
- }
176
- conf.sourceUrl = conf.sourceUrl || url;
177
- if (conf.sourceUrl.startsWith('/')) {
178
- conf.sourceUrl = new URL(conf.sourceUrl, window.location.href).href;
179
- }
180
- conf.baseUrl = conf.baseUrl || new URL('.', conf.sourceUrl).href;
181
- if (conf.baseUrl.length && !conf.baseUrl.endsWith('/')) {
182
- conf.baseUrl += '/';
183
- }
184
- if (conf.sourceUrl) {
185
- const addBase = [];
186
- if (conf.tracks) {
187
- for (const track of conf.tracks) {
188
- addBase.push(track);
189
- }
190
- }
191
- if (conf.stores) {
192
- for (const store of Object.values(conf.stores)) {
193
- addBase.push(store);
194
- }
195
- }
196
- if (conf.names) {
197
- addBase.push(conf.names);
198
- }
199
- for (const t of addBase) {
200
- if (!t.baseUrl) {
201
- t.baseUrl = conf.baseUrl || '/';
202
- }
203
- }
204
- if (conf.refSeqs && typeof conf.refSeqs === 'string') {
205
- conf.refSeqs = new URL(conf.refSeqs, conf.sourceUrl).href;
206
- }
207
- if (conf.nameUrl) {
208
- conf.nameUrl = new URL(conf.nameUrl, conf.sourceUrl).href;
209
- }
210
- }
211
- conf.stores = conf.stores || {};
212
- for (let trackConfig of conf.tracks || []) {
213
- if (trackConfig.config) {
214
- const c = trackConfig.config;
215
- trackConfig.config = undefined;
216
- trackConfig = { ...c, ...trackConfig };
217
- }
218
- if (trackConfig.store) {
219
- continue;
220
- }
221
- let trackClassName;
222
- if (trackConfig.type === 'FeatureTrack') {
223
- trackClassName = 'JBrowse/View/Track/HTMLFeatures';
224
- }
225
- else if (trackConfig.type === 'ImageTrack') {
226
- trackClassName = 'JBrowse/View/Track/FixedImage';
227
- }
228
- else if (trackConfig.type === 'ImageTrack.Wiggle') {
229
- trackClassName = 'JBrowse/View/Track/FixedImage/Wiggle';
230
- }
231
- else if (trackConfig.type === 'SequenceTrack') {
232
- trackClassName = 'JBrowse/View/Track/Sequence';
233
- }
234
- else {
235
- trackClassName = regularizeClass('JBrowse/View/Track', trackConfig.type);
236
- }
237
- trackConfig.type = trackClassName;
238
- synthesizeTrackStoreConfig(conf, trackConfig);
239
- if (trackConfig.histograms) {
240
- if (!trackConfig.histograms.baseUrl) {
241
- trackConfig.histograms.baseUrl = trackConfig.baseUrl;
242
- }
243
- synthesizeTrackStoreConfig(conf, trackConfig.histograms);
244
- }
245
- }
246
- return conf;
247
- }
248
- function regularizeClass(root, className) {
249
- if (!className) {
250
- return '';
251
- }
252
- if (!className.includes('/')) {
253
- className = `${root}/${className}`;
254
- }
255
- className = className.replace(/^\//, '');
256
- return className;
257
- }
258
- function guessStoreClass(trackConfig, urlTemplate) {
259
- if (!trackConfig) {
260
- return '';
261
- }
262
- if (trackConfig.type?.includes('/FixedImage')) {
263
- return `JBrowse/Store/TiledImage/Fixed${trackConfig.backendVersion === 0 ? '_v0' : ''}`;
264
- }
265
- if (/\.jsonz?$/i.test(urlTemplate)) {
266
- return `JBrowse/Store/SeqFeature/NCList${trackConfig.backendVersion === 0 ? '_v0' : ''}`;
267
- }
268
- if (/\.bam$/i.test(urlTemplate)) {
269
- return 'JBrowse/Store/SeqFeature/BAM';
270
- }
271
- if (/\.cram$/i.test(urlTemplate)) {
272
- return 'JBrowse/Store/SeqFeature/CRAM';
273
- }
274
- if (/\.gff3?$/i.test(urlTemplate)) {
275
- return 'JBrowse/Store/SeqFeature/GFF3';
276
- }
277
- if (/\.bed$/i.test(urlTemplate)) {
278
- return 'JBrowse/Store/SeqFeature/BED';
279
- }
280
- if (/\.vcf.b?gz$/i.test(urlTemplate)) {
281
- return 'JBrowse/Store/SeqFeature/VCFTabix';
282
- }
283
- if (/\.gff3?.b?gz$/i.test(urlTemplate)) {
284
- return 'JBrowse/Store/SeqFeature/GFF3Tabix';
285
- }
286
- if (/\.bed.b?gz$/i.test(urlTemplate)) {
287
- return 'JBrowse/Store/SeqFeature/BEDTabix';
288
- }
289
- if (/\.(bw|bigwig)$/i.test(urlTemplate)) {
290
- return 'JBrowse/Store/SeqFeature/BigWig';
291
- }
292
- if (/\.(bb|bigbed)$/i.test(urlTemplate)) {
293
- return 'JBrowse/Store/SeqFeature/BigBed';
294
- }
295
- if (/\.(fa|fasta)$/i.test(urlTemplate)) {
296
- return 'JBrowse/Store/SeqFeature/IndexedFasta';
297
- }
298
- if (/\.(fa|fasta)\.b?gz$/i.test(urlTemplate)) {
299
- return 'JBrowse/Store/SeqFeature/BgzipIndexedFasta';
300
- }
301
- if (/\.2bit$/i.test(urlTemplate)) {
302
- return 'JBrowse/Store/SeqFeature/TwoBit';
303
- }
304
- if (trackConfig.type?.endsWith('/Sequence')) {
305
- return 'JBrowse/Store/Sequence/StaticChunked';
306
- }
307
- return '';
308
- }
309
- function synthesizeTrackStoreConfig(mainConf, trackConfig) {
310
- const { urlTemplate = '' } = trackConfig;
311
- const storeClass = trackConfig.storeClass
312
- ? regularizeClass('JBrowse/Store', trackConfig.storeClass)
313
- : guessStoreClass(trackConfig, urlTemplate);
314
- if (!storeClass) {
315
- console.warn(`Unable to determine an appropriate data store to use with track '${trackConfig.label}', please explicitly specify a storeClass in the configuration.`);
316
- return;
317
- }
318
- const storeConf = { ...trackConfig, type: storeClass };
319
- storeConf.name =
320
- (storeClass === 'JBrowse/Store/Sequence/StaticChunked' ||
321
- storeClass === 'JBrowse/Store/Sequence/IndexedFasta' ||
322
- storeClass === 'JBrowse/Store/SeqFeature/IndexedFasta' ||
323
- storeClass === 'JBrowse/Store/SeqFeature/BgzipIndexedFasta' ||
324
- storeClass === 'JBrowse/Store/SeqFeature/TwoBit' ||
325
- storeClass === 'JBrowse/Store/Sequence/TwoBit' ||
326
- trackConfig.useAsRefSeqStore) &&
327
- !mainConf.stores?.refseqs
328
- ? 'refseqs'
329
- : `store${objectHash(storeConf)}`;
330
- if (!mainConf.stores) {
331
- mainConf.stores = {};
332
- }
333
- mainConf.stores[storeConf.name] = storeConf;
334
- trackConfig.store = storeConf.name;
335
- }
@@ -1,4 +1,4 @@
1
- import type { RefSeqs, Track } from './types.ts';
1
+ import type { Track } from './types.ts';
2
2
  interface Jb2Track {
3
3
  trackId: string;
4
4
  name: string;
@@ -6,9 +6,14 @@ interface Jb2Track {
6
6
  category?: string[];
7
7
  adapter?: Jb2Adapter;
8
8
  type?: string;
9
- defaultRendering?: string;
9
+ displays?: {
10
+ type: string;
11
+ displayId: string;
12
+ defaultRendering: string;
13
+ }[];
10
14
  }
11
15
  interface Jb2Adapter {
16
+ [key: string]: unknown;
12
17
  type: string;
13
18
  features?: Jb2Feature[];
14
19
  bamLocation?: Jb2Location;
@@ -24,6 +29,7 @@ interface Jb2Adapter {
24
29
  gffLocation?: Jb2Location;
25
30
  gffGzLocation?: Jb2Location;
26
31
  gtfLocation?: Jb2Location;
32
+ bedLocation?: Jb2Location;
27
33
  bedGzLocation?: Jb2Location;
28
34
  index?: {
29
35
  location: Jb2Location;
@@ -44,5 +50,4 @@ interface Jb2Location {
44
50
  locationType?: string;
45
51
  }
46
52
  export declare function convertTrackConfig(jb1TrackConfig: Track, dataRoot: string): Jb2Track;
47
- export declare function createRefSeqsAdapter(refSeqs: string | RefSeqs): Promise<Jb2Adapter>;
48
53
  export {};