@jbrowse/plugin-legacy-jbrowse 1.6.9 → 1.7.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 (48) hide show
  1. package/dist/JBrowse1Connection/configSchema.d.ts +2 -2
  2. package/dist/JBrowse1Connection/configSchema.js +30 -0
  3. package/dist/JBrowse1Connection/index.d.ts +2 -2
  4. package/dist/JBrowse1Connection/index.js +23 -0
  5. package/dist/JBrowse1Connection/jb1ConfigLoad.d.ts +36 -36
  6. package/dist/JBrowse1Connection/jb1ConfigLoad.js +555 -0
  7. package/dist/JBrowse1Connection/jb1ConfigParse.d.ts +11 -11
  8. package/dist/JBrowse1Connection/jb1ConfigParse.js +476 -0
  9. package/dist/JBrowse1Connection/jb1ToJb2.d.ts +47 -47
  10. package/dist/JBrowse1Connection/jb1ToJb2.js +556 -0
  11. package/dist/JBrowse1Connection/model.d.ts +15 -4
  12. package/dist/JBrowse1Connection/model.js +58 -0
  13. package/dist/JBrowse1Connection/types.d.ts +91 -91
  14. package/dist/JBrowse1Connection/types.js +5 -0
  15. package/dist/JBrowse1Connection/util.d.ts +26 -26
  16. package/dist/JBrowse1Connection/util.js +177 -0
  17. package/dist/JBrowse1TextSeachAdapter/HttpMap.d.ts +39 -39
  18. package/dist/JBrowse1TextSeachAdapter/HttpMap.js +350 -0
  19. package/dist/JBrowse1TextSeachAdapter/HttpMap.test.js +118 -0
  20. package/dist/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.d.ts +33 -33
  21. package/dist/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.js +191 -0
  22. package/dist/JBrowse1TextSeachAdapter/JBrowse1TextSearchAdapter.test.js +98 -0
  23. package/dist/JBrowse1TextSeachAdapter/configSchema.d.ts +2 -2
  24. package/dist/JBrowse1TextSeachAdapter/configSchema.js +35 -0
  25. package/dist/JBrowse1TextSeachAdapter/index.d.ts +2 -2
  26. package/dist/JBrowse1TextSeachAdapter/index.js +23 -0
  27. package/dist/NCListAdapter/NCListAdapter.d.ts +31 -31
  28. package/dist/NCListAdapter/NCListAdapter.js +237 -0
  29. package/dist/NCListAdapter/NCListAdapter.test.js +108 -0
  30. package/dist/NCListAdapter/NCListFeature.d.ts +31 -31
  31. package/dist/NCListAdapter/NCListFeature.js +142 -0
  32. package/dist/NCListAdapter/configSchema.d.ts +2 -2
  33. package/dist/NCListAdapter/configSchema.js +27 -0
  34. package/dist/NCListAdapter/index.d.ts +1 -1
  35. package/dist/NCListAdapter/index.js +15 -0
  36. package/dist/declare.d.js +1 -0
  37. package/dist/index.d.ts +6 -6
  38. package/dist/index.js +122 -6
  39. package/dist/index.test.js +44 -0
  40. package/package.json +5 -7
  41. package/src/JBrowse1Connection/jb1ConfigLoad.ts +1 -1
  42. package/dist/index.test.d.ts +0 -1
  43. package/dist/plugin-legacy-jbrowse.cjs.development.js +0 -3567
  44. package/dist/plugin-legacy-jbrowse.cjs.development.js.map +0 -1
  45. package/dist/plugin-legacy-jbrowse.cjs.production.min.js +0 -2
  46. package/dist/plugin-legacy-jbrowse.cjs.production.min.js.map +0 -1
  47. package/dist/plugin-legacy-jbrowse.esm.js +0 -3561
  48. package/dist/plugin-legacy-jbrowse.esm.js.map +0 -1
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
+
20
+ var _bufferCrc = _interopRequireDefault(require("buffer-crc32"));
21
+
22
+ /*
23
+ * Helper class allows reading names index generated in JBrowse1
24
+ * Adapted from https://github.com/GMOD/jbrowse/blob/master/src/JBrowse/Store/Hash.js
25
+ */
26
+ var HttpMap = /*#__PURE__*/function () {
27
+ function HttpMap(args) {
28
+ (0, _classCallCheck2["default"])(this, HttpMap);
29
+ (0, _defineProperty2["default"])(this, "url", void 0);
30
+ // make sure url has a trailing slash
31
+ this.url = /\/$/.test(args.url) ? args.url : "".concat(args.url, "/");
32
+ }
33
+ /**
34
+ * loads meta.json file from names directory and reads number of hash_bits used
35
+ */
36
+
37
+
38
+ (0, _createClass2["default"])(HttpMap, [{
39
+ key: "readMeta",
40
+ value: function () {
41
+ var _readMeta = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
42
+ var meta, compress, tracks, hashHexCharacters;
43
+ return _regenerator["default"].wrap(function _callee$(_context) {
44
+ while (1) {
45
+ switch (_context.prev = _context.next) {
46
+ case 0:
47
+ _context.next = 2;
48
+ return this.loadFile('meta.json');
49
+
50
+ case 2:
51
+ meta = _context.sent;
52
+ compress = meta.compress, tracks = meta.track_names;
53
+ hashHexCharacters = Math.ceil(meta.hash_bits / 4);
54
+ return _context.abrupt("return", {
55
+ hashHexCharacters: hashHexCharacters,
56
+ compress: compress,
57
+ tracks: tracks
58
+ });
59
+
60
+ case 6:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }
65
+ }, _callee, this);
66
+ }));
67
+
68
+ function readMeta() {
69
+ return _readMeta.apply(this, arguments);
70
+ }
71
+
72
+ return readMeta;
73
+ }()
74
+ }, {
75
+ key: "getHashHexCharacters",
76
+ value: function () {
77
+ var _getHashHexCharacters = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
78
+ var meta;
79
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
80
+ while (1) {
81
+ switch (_context2.prev = _context2.next) {
82
+ case 0:
83
+ _context2.next = 2;
84
+ return this.readMeta();
85
+
86
+ case 2:
87
+ meta = _context2.sent;
88
+ return _context2.abrupt("return", meta.hashHexCharacters);
89
+
90
+ case 4:
91
+ case "end":
92
+ return _context2.stop();
93
+ }
94
+ }
95
+ }, _callee2, this);
96
+ }));
97
+
98
+ function getHashHexCharacters() {
99
+ return _getHashHexCharacters.apply(this, arguments);
100
+ }
101
+
102
+ return getHashHexCharacters;
103
+ }()
104
+ }, {
105
+ key: "getCompress",
106
+ value: function () {
107
+ var _getCompress = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
108
+ var meta;
109
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
110
+ while (1) {
111
+ switch (_context3.prev = _context3.next) {
112
+ case 0:
113
+ _context3.next = 2;
114
+ return this.readMeta();
115
+
116
+ case 2:
117
+ meta = _context3.sent;
118
+ return _context3.abrupt("return", meta.compress);
119
+
120
+ case 4:
121
+ case "end":
122
+ return _context3.stop();
123
+ }
124
+ }
125
+ }, _callee3, this);
126
+ }));
127
+
128
+ function getCompress() {
129
+ return _getCompress.apply(this, arguments);
130
+ }
131
+
132
+ return getCompress;
133
+ }()
134
+ }, {
135
+ key: "getTrackNames",
136
+ value: function () {
137
+ var _getTrackNames = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
138
+ var meta;
139
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
140
+ while (1) {
141
+ switch (_context4.prev = _context4.next) {
142
+ case 0:
143
+ _context4.next = 2;
144
+ return this.readMeta();
145
+
146
+ case 2:
147
+ meta = _context4.sent;
148
+ return _context4.abrupt("return", meta.tracks);
149
+
150
+ case 4:
151
+ case "end":
152
+ return _context4.stop();
153
+ }
154
+ }
155
+ }, _callee4, this);
156
+ }));
157
+
158
+ function getTrackNames() {
159
+ return _getTrackNames.apply(this, arguments);
160
+ }
161
+
162
+ return getTrackNames;
163
+ }()
164
+ /**
165
+ * Returns contents of a bucket given a key
166
+ * @param key - string
167
+ */
168
+
169
+ }, {
170
+ key: "get",
171
+ value: function () {
172
+ var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(key) {
173
+ var bucket;
174
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
175
+ while (1) {
176
+ switch (_context5.prev = _context5.next) {
177
+ case 0:
178
+ _context5.next = 2;
179
+ return this.getBucket(key);
180
+
181
+ case 2:
182
+ bucket = _context5.sent;
183
+ return _context5.abrupt("return", bucket[key]);
184
+
185
+ case 4:
186
+ case "end":
187
+ return _context5.stop();
188
+ }
189
+ }
190
+ }, _callee5, this);
191
+ }));
192
+
193
+ function get(_x) {
194
+ return _get.apply(this, arguments);
195
+ }
196
+
197
+ return get;
198
+ }()
199
+ /**
200
+ * Returns a bucket given a key
201
+ * @param key - string
202
+ */
203
+
204
+ }, {
205
+ key: "getBucket",
206
+ value: function () {
207
+ var _getBucket = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(key) {
208
+ var bucketIdent, hexToDirPath;
209
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
210
+ while (1) {
211
+ switch (_context6.prev = _context6.next) {
212
+ case 0:
213
+ bucketIdent = this.hash(key);
214
+ _context6.next = 3;
215
+ return this.hexToDirPath(bucketIdent);
216
+
217
+ case 3:
218
+ hexToDirPath = _context6.sent;
219
+ return _context6.abrupt("return", this.loadFile(hexToDirPath));
220
+
221
+ case 5:
222
+ case "end":
223
+ return _context6.stop();
224
+ }
225
+ }
226
+ }, _callee6, this);
227
+ }));
228
+
229
+ function getBucket(_x2) {
230
+ return _getBucket.apply(this, arguments);
231
+ }
232
+
233
+ return getBucket;
234
+ }()
235
+ /**
236
+ * Loads a file using the url and provided id.
237
+ * Returns response object with contents of the file
238
+ * @param id - string
239
+ */
240
+
241
+ }, {
242
+ key: "loadFile",
243
+ value: function () {
244
+ var _loadFile = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(id) {
245
+ var response;
246
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
247
+ while (1) {
248
+ switch (_context7.prev = _context7.next) {
249
+ case 0:
250
+ _context7.next = 2;
251
+ return fetch("".concat(this.url).concat(id));
252
+
253
+ case 2:
254
+ response = _context7.sent;
255
+
256
+ if (response.ok) {
257
+ _context7.next = 5;
258
+ break;
259
+ }
260
+
261
+ throw new Error("HTTP ".concat(response.status, " ").concat(response.statusText));
262
+
263
+ case 5:
264
+ return _context7.abrupt("return", response.json());
265
+
266
+ case 6:
267
+ case "end":
268
+ return _context7.stop();
269
+ }
270
+ }
271
+ }, _callee7, this);
272
+ }));
273
+
274
+ function loadFile(_x3) {
275
+ return _loadFile.apply(this, arguments);
276
+ }
277
+
278
+ return loadFile;
279
+ }()
280
+ /**
281
+ * Returns the corresponding path of the file given a hex string
282
+ * @param hex - hex string
283
+ */
284
+
285
+ }, {
286
+ key: "hexToDirPath",
287
+ value: function () {
288
+ var _hexToDirPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(hex) {
289
+ var hashHexCharacters, compress, dirpath, i;
290
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
291
+ while (1) {
292
+ switch (_context8.prev = _context8.next) {
293
+ case 0:
294
+ _context8.next = 2;
295
+ return this.getHashHexCharacters();
296
+
297
+ case 2:
298
+ hashHexCharacters = _context8.sent;
299
+
300
+ if (!hashHexCharacters) {
301
+ _context8.next = 12;
302
+ break;
303
+ }
304
+
305
+ _context8.next = 6;
306
+ return this.getCompress();
307
+
308
+ case 6:
309
+ compress = _context8.sent;
310
+
311
+ while (hex.length < 8) {
312
+ hex = "0".concat(hex);
313
+ }
314
+
315
+ hex = hex.substr(8 - hashHexCharacters);
316
+ dirpath = [];
317
+
318
+ for (i = 0; i < hex.length; i += 3) {
319
+ dirpath.push(hex.substring(i, i + 3));
320
+ }
321
+
322
+ return _context8.abrupt("return", "".concat(dirpath.join('/'), ".json").concat(compress ? 'z' : ''));
323
+
324
+ case 12:
325
+ return _context8.abrupt("return", '');
326
+
327
+ case 13:
328
+ case "end":
329
+ return _context8.stop();
330
+ }
331
+ }
332
+ }, _callee8, this);
333
+ }));
334
+
335
+ function hexToDirPath(_x4) {
336
+ return _hexToDirPath.apply(this, arguments);
337
+ }
338
+
339
+ return hexToDirPath;
340
+ }()
341
+ }, {
342
+ key: "hash",
343
+ value: function hash(data) {
344
+ return (0, _bufferCrc["default"])(Buffer.from(data)).toString('hex').toLowerCase().replace('-', 'n');
345
+ }
346
+ }]);
347
+ return HttpMap;
348
+ }();
349
+
350
+ exports["default"] = HttpMap;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
6
+
7
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
+
9
+ var _path = _interopRequireDefault(require("path"));
10
+
11
+ var _meta = _interopRequireDefault(require("../../test_data/names/meta.json"));
12
+
13
+ var _ = _interopRequireDefault(require("../../test_data/names/0.json"));
14
+
15
+ var _f = _interopRequireDefault(require("../../test_data/names/f.json"));
16
+
17
+ var _HttpMap = _interopRequireDefault(require("./HttpMap"));
18
+
19
+ describe('test JBrowse1 hash implementation', function () {
20
+ test('read from meta', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
21
+ var mockFetch, rootTemplate, spy, hashMap;
22
+ return _regenerator["default"].wrap(function _callee$(_context) {
23
+ while (1) {
24
+ switch (_context.prev = _context.next) {
25
+ case 0:
26
+ mockFetch = function _mockFetch(url) {
27
+ var response = {};
28
+
29
+ if (url.includes('names/meta.json')) {
30
+ response = _meta["default"];
31
+ }
32
+
33
+ return Promise.resolve(new Response(JSON.stringify(response)));
34
+ };
35
+
36
+ rootTemplate = _path["default"].join(__dirname, '..', '..', '..', '..', 'test_data', 'names').replace(/\\/g, '\\\\');
37
+ spy = jest.spyOn(global, 'fetch'); // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+
39
+ spy.mockImplementation(mockFetch);
40
+ hashMap = new _HttpMap["default"]({
41
+ url: rootTemplate
42
+ });
43
+ _context.next = 7;
44
+ return hashMap.getBucket('apple');
45
+
46
+ case 7:
47
+ _context.t0 = expect;
48
+ _context.next = 10;
49
+ return hashMap.getHashHexCharacters();
50
+
51
+ case 10:
52
+ _context.t1 = _context.sent;
53
+ (0, _context.t0)(_context.t1).toBe(1);
54
+ _context.t2 = expect;
55
+ _context.next = 15;
56
+ return hashMap.getCompress();
57
+
58
+ case 15:
59
+ _context.t3 = _context.sent;
60
+ (0, _context.t2)(_context.t3).toBe(0);
61
+
62
+ case 17:
63
+ case "end":
64
+ return _context.stop();
65
+ }
66
+ }
67
+ }, _callee);
68
+ })));
69
+ test('get bucket contents', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
70
+ var mockFetch, rootTemplate, spy, hashMap;
71
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
72
+ while (1) {
73
+ switch (_context2.prev = _context2.next) {
74
+ case 0:
75
+ mockFetch = function _mockFetch2(url) {
76
+ var response = {};
77
+
78
+ if (url.includes('names/meta.json')) {
79
+ response = _meta["default"];
80
+ }
81
+
82
+ if (url.includes('names/0.json')) {
83
+ response = _["default"];
84
+ }
85
+
86
+ if (url.includes('names/f.json')) {
87
+ response = _f["default"];
88
+ }
89
+
90
+ return Promise.resolve(new Response(JSON.stringify(response)));
91
+ };
92
+
93
+ rootTemplate = _path["default"].join(__dirname, '..', '..', '..', '..', 'test_data', 'names').replace(/\\/g, '\\\\');
94
+ spy = jest.spyOn(global, 'fetch'); // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+
96
+ spy.mockImplementation(mockFetch);
97
+ hashMap = new _HttpMap["default"]({
98
+ url: rootTemplate
99
+ });
100
+ _context2.next = 7;
101
+ return hashMap.getBucket('apple');
102
+
103
+ case 7:
104
+ expect(spy).toHaveBeenLastCalledWith("".concat(rootTemplate, "/0.json"));
105
+ _context2.next = 10;
106
+ return hashMap.getBucket('apple3');
107
+
108
+ case 10:
109
+ expect(spy).toHaveBeenLastCalledWith("".concat(rootTemplate, "/f.json"));
110
+
111
+ case 11:
112
+ case "end":
113
+ return _context2.stop();
114
+ }
115
+ }
116
+ }, _callee2);
117
+ })));
118
+ });
@@ -1,33 +1,33 @@
1
- import { BaseTextSearchAdapter, BaseArgs, BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import BaseResult from '@jbrowse/core/TextSearch/BaseResults';
3
- import { Instance } from 'mobx-state-tree';
4
- import MyConfigSchema from './configSchema';
5
- import HttpMap from './HttpMap';
6
- import PluginManager from '@jbrowse/core/PluginManager';
7
- import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
8
- export interface TooManyHits {
9
- name: string;
10
- hitLimit: number;
11
- }
12
- interface SearchResults {
13
- prefix: ({
14
- name: string;
15
- } | string)[];
16
- exact: [string, number, string, string, number, number][];
17
- }
18
- export declare type NamesIndexRecord = string | Array<string | number>;
19
- export default class JBrowse1TextSearchAdapter extends BaseAdapter implements BaseTextSearchAdapter {
20
- httpMap: HttpMap;
21
- tracksNames?: string[];
22
- constructor(config: Instance<typeof MyConfigSchema>, getSubAdapter?: getSubAdapterType, pluginManager?: PluginManager);
23
- /**
24
- * Returns the contents of the file containing the query if it exists
25
- * else it returns empty
26
- * @param query - string query
27
- */
28
- loadIndexFile(query: string): Promise<Record<string, SearchResults>>;
29
- searchIndex(args: BaseArgs): Promise<BaseResult[]>;
30
- formatResults(results: SearchResults, tracks: string[], searchType?: string): BaseResult[];
31
- freeResources(): void;
32
- }
33
- export {};
1
+ import { BaseTextSearchAdapter, BaseArgs, BaseAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
+ import BaseResult from '@jbrowse/core/TextSearch/BaseResults';
3
+ import { Instance } from 'mobx-state-tree';
4
+ import MyConfigSchema from './configSchema';
5
+ import HttpMap from './HttpMap';
6
+ import PluginManager from '@jbrowse/core/PluginManager';
7
+ import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
8
+ export interface TooManyHits {
9
+ name: string;
10
+ hitLimit: number;
11
+ }
12
+ interface SearchResults {
13
+ prefix: ({
14
+ name: string;
15
+ } | string)[];
16
+ exact: [string, number, string, string, number, number][];
17
+ }
18
+ export declare type NamesIndexRecord = string | Array<string | number>;
19
+ export default class JBrowse1TextSearchAdapter extends BaseAdapter implements BaseTextSearchAdapter {
20
+ httpMap: HttpMap;
21
+ tracksNames?: string[];
22
+ constructor(config: Instance<typeof MyConfigSchema>, getSubAdapter?: getSubAdapterType, pluginManager?: PluginManager);
23
+ /**
24
+ * Returns the contents of the file containing the query if it exists
25
+ * else it returns empty
26
+ * @param query - string query
27
+ */
28
+ loadIndexFile(query: string): Promise<Record<string, SearchResults>>;
29
+ searchIndex(args: BaseArgs): Promise<BaseResult[]>;
30
+ formatResults(results: SearchResults, tracks: string[], searchType?: string): BaseResult[];
31
+ freeResources(): void;
32
+ }
33
+ export {};