@jbrowse/plugin-gff3 1.7.11 → 2.0.0

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 (38) hide show
  1. package/dist/Gff3Adapter/Gff3Adapter.js +284 -390
  2. package/dist/Gff3Adapter/Gff3Adapter.js.map +1 -0
  3. package/dist/Gff3Adapter/configSchema.js +9 -21
  4. package/dist/Gff3Adapter/configSchema.js.map +1 -0
  5. package/dist/Gff3Adapter/index.js +8 -14
  6. package/dist/Gff3Adapter/index.js.map +1 -0
  7. package/dist/Gff3TabixAdapter/Gff3TabixAdapter.js +305 -386
  8. package/dist/Gff3TabixAdapter/Gff3TabixAdapter.js.map +1 -0
  9. package/dist/Gff3TabixAdapter/configSchema.js +27 -40
  10. package/dist/Gff3TabixAdapter/configSchema.js.map +1 -0
  11. package/dist/Gff3TabixAdapter/index.js +8 -14
  12. package/dist/Gff3TabixAdapter/index.js.map +1 -0
  13. package/dist/index.js +109 -130
  14. package/dist/index.js.map +1 -0
  15. package/esm/Gff3Adapter/Gff3Adapter.d.ts +17 -0
  16. package/esm/Gff3Adapter/Gff3Adapter.js +146 -0
  17. package/esm/Gff3Adapter/Gff3Adapter.js.map +1 -0
  18. package/esm/Gff3Adapter/configSchema.d.ts +2 -0
  19. package/esm/Gff3Adapter/configSchema.js +8 -0
  20. package/esm/Gff3Adapter/configSchema.js.map +1 -0
  21. package/esm/Gff3Adapter/index.d.ts +1 -0
  22. package/esm/Gff3Adapter/index.js +2 -0
  23. package/esm/Gff3Adapter/index.js.map +1 -0
  24. package/esm/Gff3TabixAdapter/Gff3TabixAdapter.d.ts +20 -0
  25. package/esm/Gff3TabixAdapter/Gff3TabixAdapter.js +186 -0
  26. package/esm/Gff3TabixAdapter/Gff3TabixAdapter.js.map +1 -0
  27. package/esm/Gff3TabixAdapter/configSchema.d.ts +2 -0
  28. package/esm/Gff3TabixAdapter/configSchema.js +27 -0
  29. package/esm/Gff3TabixAdapter/configSchema.js.map +1 -0
  30. package/esm/Gff3TabixAdapter/index.d.ts +1 -0
  31. package/esm/Gff3TabixAdapter/index.js +2 -0
  32. package/esm/Gff3TabixAdapter/index.js.map +1 -0
  33. package/esm/index.d.ts +6 -0
  34. package/esm/index.js +62 -0
  35. package/esm/index.js.map +1 -0
  36. package/package.json +17 -9
  37. package/dist/Gff3Adapter/Gff3Adapter.test.js +0 -71
  38. package/dist/Gff3TabixAdapter/Gff3TabixAdapter.test.js +0 -74
@@ -1,395 +1,314 @@
1
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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
-
18
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
-
20
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
21
-
22
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
23
-
24
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
25
-
26
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
27
-
28
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
29
-
30
- var _BaseAdapter = require("@jbrowse/core/data_adapters/BaseAdapter");
31
-
32
- var _range = require("@jbrowse/core/util/range");
33
-
34
- var _io = require("@jbrowse/core/util/io");
35
-
36
- var _rxjs = require("@jbrowse/core/util/rxjs");
37
-
38
- var _simpleFeature = _interopRequireDefault(require("@jbrowse/core/util/simpleFeature"));
39
-
40
- var _tabix = require("@gmod/tabix");
41
-
42
- var _gff = _interopRequireDefault(require("@gmod/gff"));
43
-
44
- var _configuration = require("@jbrowse/core/configuration");
45
-
46
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
47
-
48
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
49
-
50
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
51
-
52
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
53
-
54
- var _default = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
55
- (0, _inherits2.default)(_default, _BaseFeatureDataAdapt);
56
-
57
- var _super = _createSuper(_default);
58
-
59
- function _default(config, getSubAdapter, pluginManager) {
60
- var _this;
61
-
62
- (0, _classCallCheck2.default)(this, _default);
63
- _this = _super.call(this, config, getSubAdapter, pluginManager);
64
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gff", void 0);
65
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "dontRedispatch", void 0);
66
- var gffGzLocation = (0, _configuration.readConfObject)(config, 'gffGzLocation');
67
- var indexType = (0, _configuration.readConfObject)(config, ['index', 'indexType']);
68
- var location = (0, _configuration.readConfObject)(config, ['index', 'location']);
69
- var dontRedispatch = (0, _configuration.readConfObject)(config, 'dontRedispatch');
70
- _this.dontRedispatch = dontRedispatch || ['chromosome', 'contig', 'region'];
71
- _this.gff = new _tabix.TabixIndexedFile({
72
- filehandle: (0, _io.openLocation)(gffGzLocation, _this.pluginManager),
73
- csiFilehandle: indexType === 'CSI' ? (0, _io.openLocation)(location, _this.pluginManager) : undefined,
74
- tbiFilehandle: indexType !== 'CSI' ? (0, _io.openLocation)(location, _this.pluginManager) : undefined,
75
- chunkCacheSize: 50 * Math.pow(2, 20),
76
- renameRefSeqs: function renameRefSeqs(n) {
77
- return n;
78
- }
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
79
35
  });
80
- return _this;
81
- }
82
-
83
- (0, _createClass2.default)(_default, [{
84
- key: "getRefNames",
85
- value: function () {
86
- var _getRefNames = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
87
- var opts,
88
- _args = arguments;
89
- return _regenerator.default.wrap(function _callee$(_context) {
90
- while (1) {
91
- switch (_context.prev = _context.next) {
92
- case 0:
93
- opts = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
94
- return _context.abrupt("return", this.gff.getReferenceSequenceNames(opts));
95
-
96
- case 2:
97
- case "end":
98
- return _context.stop();
99
- }
100
- }
101
- }, _callee, this);
102
- }));
103
-
104
- function getRefNames() {
105
- return _getRefNames.apply(this, arguments);
106
- }
107
-
108
- return getRefNames;
109
- }()
110
- }, {
111
- key: "getHeader",
112
- value: function () {
113
- var _getHeader = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
114
- return _regenerator.default.wrap(function _callee2$(_context2) {
115
- while (1) {
116
- switch (_context2.prev = _context2.next) {
117
- case 0:
118
- return _context2.abrupt("return", this.gff.getHeader());
119
-
120
- case 1:
121
- case "end":
122
- return _context2.stop();
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
123
58
  }
124
- }
125
- }, _callee2, this);
126
- }));
127
-
128
- function getHeader() {
129
- return _getHeader.apply(this, arguments);
130
- }
131
-
132
- return getHeader;
133
- }()
134
- }, {
135
- key: "getFeatures",
136
- value: function getFeatures(query) {
137
- var _this2 = this;
138
-
139
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
140
- return (0, _rxjs.ObservableCreate)( /*#__PURE__*/function () {
141
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(observer) {
142
- var metadata;
143
- return _regenerator.default.wrap(function _callee3$(_context3) {
144
- while (1) {
145
- switch (_context3.prev = _context3.next) {
146
- case 0:
147
- _context3.next = 2;
148
- return _this2.gff.getMetadata();
149
-
150
- case 2:
151
- metadata = _context3.sent;
152
-
153
- _this2.getFeaturesHelper(query, opts, metadata, observer, true);
154
-
155
- case 4:
156
- case "end":
157
- return _context3.stop();
158
- }
159
- }
160
- }, _callee3);
161
- }));
162
-
163
- return function (_x) {
164
- return _ref.apply(this, arguments);
165
- };
166
- }(), opts.signal);
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
167
62
  }
168
- }, {
169
- key: "getFeaturesHelper",
170
- value: function () {
171
- var _getFeaturesHelper = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(query) {
172
- var _this3 = this;
173
-
174
- var opts,
175
- metadata,
176
- observer,
177
- allowRedispatch,
178
- originalQuery,
179
- lines,
180
- minStart,
181
- maxEnd,
182
- gff3,
183
- features,
184
- _args4 = arguments;
185
- return _regenerator.default.wrap(function _callee4$(_context4) {
186
- while (1) {
187
- switch (_context4.prev = _context4.next) {
188
- case 0:
189
- opts = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
190
- metadata = _args4.length > 2 ? _args4[2] : undefined;
191
- observer = _args4.length > 3 ? _args4[3] : undefined;
192
- allowRedispatch = _args4.length > 4 ? _args4[4] : undefined;
193
- originalQuery = _args4.length > 5 && _args4[5] !== undefined ? _args4[5] : query;
194
- _context4.prev = 5;
195
- lines = [];
196
- _context4.next = 9;
197
- return this.gff.getLines(query.refName, query.start, query.end, function (line, fileOffset) {
198
- lines.push(_this3.parseLine(metadata.columnNumbers, line, fileOffset));
199
- });
200
-
201
- case 9:
202
- if (!(allowRedispatch && lines.length)) {
203
- _context4.next = 16;
204
- break;
205
- }
206
-
207
- minStart = Infinity;
208
- maxEnd = -Infinity;
209
- lines.forEach(function (line) {
210
- var featureType = line.fields[2]; // only expand redispatch range if feature is not a "dontRedispatch" type
211
- // skips large regions like chromosome,region
212
-
213
- if (!_this3.dontRedispatch.includes(featureType)) {
214
- var start = line.start - 1; // gff is 1-based
215
-
216
- if (start < minStart) {
217
- minStart = start;
218
- }
219
-
220
- if (line.end > maxEnd) {
221
- maxEnd = line.end;
222
- }
223
- }
224
- });
225
-
226
- if (!(maxEnd > query.end || minStart < query.start)) {
227
- _context4.next = 16;
228
- break;
229
- }
230
-
231
- // make a new feature callback to only return top-level features
232
- // in the original query range
233
- this.getFeaturesHelper(_objectSpread(_objectSpread({}, query), {}, {
234
- start: minStart,
235
- end: maxEnd
236
- }), opts, metadata, observer, false, query);
237
- return _context4.abrupt("return");
238
-
239
- case 16:
240
- gff3 = lines.map(function (lineRecord) {
241
- if (lineRecord.fields[8] && lineRecord.fields[8] !== '.') {
242
- if (!lineRecord.fields[8].includes('_lineHash')) {
243
- lineRecord.fields[8] += ";_lineHash=".concat(lineRecord.lineHash);
244
- }
245
- } else {
246
- lineRecord.fields[8] = "_lineHash=".concat(lineRecord.lineHash);
247
- }
248
-
249
- return lineRecord.fields.join('\t');
250
- }).join('\n');
251
- features = _gff.default.parseStringSync(gff3, {
252
- parseFeatures: true,
253
- parseComments: false,
254
- parseDirectives: false,
255
- parseSequences: false
256
- });
257
- features.forEach(function (featureLocs) {
258
- return _this3.formatFeatures(featureLocs).forEach(function (f) {
259
- if ((0, _range.doesIntersect2)(f.get('start'), f.get('end'), originalQuery.start, originalQuery.end)) {
260
- observer.next(f);
261
- }
262
- });
263
- });
264
- observer.complete();
265
- _context4.next = 25;
266
- break;
267
-
268
- case 22:
269
- _context4.prev = 22;
270
- _context4.t0 = _context4["catch"](5);
271
- observer.error(_context4.t0);
272
-
273
- case 25:
274
- case "end":
275
- return _context4.stop();
276
- }
277
- }
278
- }, _callee4, this, [[5, 22]]);
279
- }));
280
-
281
- function getFeaturesHelper(_x2) {
282
- return _getFeaturesHelper.apply(this, arguments);
283
- }
284
-
285
- return getFeaturesHelper;
286
- }()
287
- }, {
288
- key: "parseLine",
289
- value: function parseLine(columnNumbers, line, fileOffset) {
290
- var fields = line.split('\t'); // note: index column numbers are 1-based
291
-
292
- return {
293
- start: +fields[columnNumbers.start - 1],
294
- end: +fields[columnNumbers.end - 1],
295
- lineHash: fileOffset,
296
- fields: fields
297
- };
63
+ };
64
+ var __read = (this && this.__read) || function (o, n) {
65
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
66
+ if (!m) return o;
67
+ var i = m.call(o), r, ar = [], e;
68
+ try {
69
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
298
70
  }
299
- }, {
300
- key: "formatFeatures",
301
- value: function formatFeatures(featureLocs) {
302
- var _this4 = this;
303
-
304
- return featureLocs.map(function (featureLoc) {
305
- return new _simpleFeature.default({
306
- data: _this4.featureData(featureLoc),
307
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
308
- id: "".concat(_this4.id, "-offset-").concat(featureLoc.attributes._lineHash[0])
71
+ catch (error) { e = { error: error }; }
72
+ finally {
73
+ try {
74
+ if (r && !r.done && (m = i["return"])) m.call(i);
75
+ }
76
+ finally { if (e) throw e.error; }
77
+ }
78
+ return ar;
79
+ };
80
+ var __importDefault = (this && this.__importDefault) || function (mod) {
81
+ return (mod && mod.__esModule) ? mod : { "default": mod };
82
+ };
83
+ Object.defineProperty(exports, "__esModule", { value: true });
84
+ /* eslint-disable no-underscore-dangle */
85
+ var BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
86
+ var range_1 = require("@jbrowse/core/util/range");
87
+ var io_1 = require("@jbrowse/core/util/io");
88
+ var rxjs_1 = require("@jbrowse/core/util/rxjs");
89
+ var simpleFeature_1 = __importDefault(require("@jbrowse/core/util/simpleFeature"));
90
+ var tabix_1 = require("@gmod/tabix");
91
+ var gff_1 = __importDefault(require("@gmod/gff"));
92
+ var configuration_1 = require("@jbrowse/core/configuration");
93
+ var default_1 = /** @class */ (function (_super) {
94
+ __extends(default_1, _super);
95
+ function default_1(config, getSubAdapter, pluginManager) {
96
+ var _this = _super.call(this, config, getSubAdapter, pluginManager) || this;
97
+ var gffGzLocation = (0, configuration_1.readConfObject)(config, 'gffGzLocation');
98
+ var indexType = (0, configuration_1.readConfObject)(config, ['index', 'indexType']);
99
+ var location = (0, configuration_1.readConfObject)(config, ['index', 'location']);
100
+ var dontRedispatch = (0, configuration_1.readConfObject)(config, 'dontRedispatch');
101
+ _this.dontRedispatch = dontRedispatch || ['chromosome', 'contig', 'region'];
102
+ _this.gff = new tabix_1.TabixIndexedFile({
103
+ filehandle: (0, io_1.openLocation)(gffGzLocation, _this.pluginManager),
104
+ csiFilehandle: indexType === 'CSI'
105
+ ? (0, io_1.openLocation)(location, _this.pluginManager)
106
+ : undefined,
107
+ tbiFilehandle: indexType !== 'CSI'
108
+ ? (0, io_1.openLocation)(location, _this.pluginManager)
109
+ : undefined,
110
+ chunkCacheSize: 50 * Math.pow(2, 20),
111
+ renameRefSeqs: function (n) { return n; },
309
112
  });
310
- });
113
+ return _this;
311
114
  }
312
- }, {
313
- key: "featureData",
314
- value: function featureData(data) {
315
- var _this5 = this;
316
-
317
- var f = _objectSpread({}, data);
318
-
319
- f.start -= 1; // convert to interbase
320
-
321
- if (data.strand === '+') {
322
- f.strand = 1;
323
- } else if (data.strand === '-') {
324
- f.strand = -1;
325
- } else if (data.strand === '.') {
326
- f.strand = 0;
327
- } else {
328
- f.strand = undefined;
329
- }
330
-
331
- f.phase = Number(data.phase);
332
- f.refName = data.seq_id;
333
-
334
- if (data.score === null) {
335
- delete f.score;
336
- }
337
-
338
- if (data.phase === null) {
339
- delete f.score;
340
- }
341
-
342
- var defaultFields = ['start', 'end', 'seq_id', 'score', 'type', 'source', 'phase', 'strand'];
343
- var dataAttributes = data.attributes || {};
344
- Object.keys(dataAttributes).forEach(function (a) {
345
- var b = a.toLowerCase();
346
-
347
- if (defaultFields.includes(b)) {
348
- // add "suffix" to tag name if it already exists
349
- // reproduces behavior of NCList
350
- b += '2';
115
+ default_1.prototype.getRefNames = function (opts) {
116
+ if (opts === void 0) { opts = {}; }
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ return [2 /*return*/, this.gff.getReferenceSequenceNames(opts)];
120
+ });
121
+ });
122
+ };
123
+ default_1.prototype.getHeader = function () {
124
+ return __awaiter(this, void 0, void 0, function () {
125
+ return __generator(this, function (_a) {
126
+ return [2 /*return*/, this.gff.getHeader()];
127
+ });
128
+ });
129
+ };
130
+ default_1.prototype.getFeatures = function (query, opts) {
131
+ var _this = this;
132
+ if (opts === void 0) { opts = {}; }
133
+ return (0, rxjs_1.ObservableCreate)(function (observer) { return __awaiter(_this, void 0, void 0, function () {
134
+ var metadata;
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
137
+ case 0: return [4 /*yield*/, this.gff.getMetadata()];
138
+ case 1:
139
+ metadata = _a.sent();
140
+ this.getFeaturesHelper(query, opts, metadata, observer, true);
141
+ return [2 /*return*/];
142
+ }
143
+ });
144
+ }); }, opts.signal);
145
+ };
146
+ default_1.prototype.getFeaturesHelper = function (query, opts, metadata, observer, allowRedispatch, originalQuery) {
147
+ if (opts === void 0) { opts = {}; }
148
+ if (originalQuery === void 0) { originalQuery = query; }
149
+ return __awaiter(this, void 0, void 0, function () {
150
+ var lines_1, minStart_1, maxEnd_1, gff3, features, e_1;
151
+ var _this = this;
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0:
155
+ _a.trys.push([0, 2, , 3]);
156
+ lines_1 = [];
157
+ return [4 /*yield*/, this.gff.getLines(query.refName, query.start, query.end, function (line, fileOffset) {
158
+ lines_1.push(_this.parseLine(metadata.columnNumbers, line, fileOffset));
159
+ })];
160
+ case 1:
161
+ _a.sent();
162
+ if (allowRedispatch && lines_1.length) {
163
+ minStart_1 = Infinity;
164
+ maxEnd_1 = -Infinity;
165
+ lines_1.forEach(function (line) {
166
+ var featureType = line.fields[2];
167
+ // only expand redispatch range if feature is not a "dontRedispatch" type
168
+ // skips large regions like chromosome,region
169
+ if (!_this.dontRedispatch.includes(featureType)) {
170
+ var start = line.start - 1; // gff is 1-based
171
+ if (start < minStart_1) {
172
+ minStart_1 = start;
173
+ }
174
+ if (line.end > maxEnd_1) {
175
+ maxEnd_1 = line.end;
176
+ }
177
+ }
178
+ });
179
+ if (maxEnd_1 > query.end || minStart_1 < query.start) {
180
+ // make a new feature callback to only return top-level features
181
+ // in the original query range
182
+ this.getFeaturesHelper(__assign(__assign({}, query), { start: minStart_1, end: maxEnd_1 }), opts, metadata, observer, false, query);
183
+ return [2 /*return*/];
184
+ }
185
+ }
186
+ gff3 = lines_1
187
+ .map(function (lineRecord) {
188
+ if (lineRecord.fields[8] && lineRecord.fields[8] !== '.') {
189
+ if (!lineRecord.fields[8].includes('_lineHash')) {
190
+ lineRecord.fields[8] += ";_lineHash=".concat(lineRecord.lineHash);
191
+ }
192
+ }
193
+ else {
194
+ lineRecord.fields[8] = "_lineHash=".concat(lineRecord.lineHash);
195
+ }
196
+ return lineRecord.fields.join('\t');
197
+ })
198
+ .join('\n');
199
+ features = gff_1.default.parseStringSync(gff3, {
200
+ parseFeatures: true,
201
+ parseComments: false,
202
+ parseDirectives: false,
203
+ parseSequences: false,
204
+ });
205
+ features.forEach(function (featureLocs) {
206
+ return _this.formatFeatures(featureLocs).forEach(function (f) {
207
+ if ((0, range_1.doesIntersect2)(f.get('start'), f.get('end'), originalQuery.start, originalQuery.end)) {
208
+ observer.next(f);
209
+ }
210
+ });
211
+ });
212
+ observer.complete();
213
+ return [3 /*break*/, 3];
214
+ case 2:
215
+ e_1 = _a.sent();
216
+ observer.error(e_1);
217
+ return [3 /*break*/, 3];
218
+ case 3: return [2 /*return*/];
219
+ }
220
+ });
221
+ });
222
+ };
223
+ default_1.prototype.parseLine = function (columnNumbers, line, fileOffset) {
224
+ var fields = line.split('\t');
225
+ // note: index column numbers are 1-based
226
+ return {
227
+ start: +fields[columnNumbers.start - 1],
228
+ end: +fields[columnNumbers.end - 1],
229
+ lineHash: fileOffset,
230
+ fields: fields,
231
+ };
232
+ };
233
+ default_1.prototype.formatFeatures = function (featureLocs) {
234
+ var _this = this;
235
+ return featureLocs.map(function (featureLoc) {
236
+ return new simpleFeature_1.default({
237
+ data: _this.featureData(featureLoc),
238
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
+ id: "".concat(_this.id, "-offset-").concat(featureLoc.attributes._lineHash[0]),
240
+ });
241
+ });
242
+ };
243
+ default_1.prototype.featureData = function (data) {
244
+ var _this = this;
245
+ var f = __assign({}, data);
246
+ f.start -= 1; // convert to interbase
247
+ if (data.strand === '+') {
248
+ f.strand = 1;
351
249
  }
352
-
353
- if (dataAttributes[a] !== null) {
354
- var attr = dataAttributes[a];
355
-
356
- if (Array.isArray(attr) && attr.length === 1) {
357
- ;
358
- var _attr = attr;
359
-
360
- var _attr2 = (0, _slicedToArray2.default)(_attr, 1);
361
-
362
- attr = _attr2[0];
363
- }
364
-
365
- f[b] = attr;
250
+ else if (data.strand === '-') {
251
+ f.strand = -1;
366
252
  }
367
- });
368
- f.refName = f.seq_id; // the SimpleFeature constructor takes care of recursively inflating subfeatures
369
-
370
- if (data.child_features && data.child_features.length) {
371
- f.subfeatures = data.child_features.map(function (childLocs) {
372
- return childLocs.map(function (childLoc) {
373
- return _this5.featureData(childLoc);
374
- });
375
- }).flat();
376
- }
377
-
378
- delete f.child_features;
379
- delete f.data;
380
- delete f.derived_features;
381
- delete f._linehash;
382
- delete f.attributes;
383
- delete f.seq_id;
384
- return f;
385
- }
386
- }, {
387
- key: "freeResources",
388
- value: function
389
- /* { region } */
390
- freeResources() {}
391
- }]);
392
- return _default;
393
- }(_BaseAdapter.BaseFeatureDataAdapter);
394
-
395
- exports.default = _default;
253
+ else if (data.strand === '.') {
254
+ f.strand = 0;
255
+ }
256
+ else {
257
+ f.strand = undefined;
258
+ }
259
+ f.phase = Number(data.phase);
260
+ f.refName = data.seq_id;
261
+ if (data.score === null) {
262
+ delete f.score;
263
+ }
264
+ if (data.phase === null) {
265
+ delete f.score;
266
+ }
267
+ var defaultFields = [
268
+ 'start',
269
+ 'end',
270
+ 'seq_id',
271
+ 'score',
272
+ 'type',
273
+ 'source',
274
+ 'phase',
275
+ 'strand',
276
+ ];
277
+ var dataAttributes = data.attributes || {};
278
+ Object.keys(dataAttributes).forEach(function (a) {
279
+ var _a, _b;
280
+ var b = a.toLowerCase();
281
+ if (defaultFields.includes(b)) {
282
+ // add "suffix" to tag name if it already exists
283
+ // reproduces behavior of NCList
284
+ b += '2';
285
+ }
286
+ if (dataAttributes[a] !== null) {
287
+ var attr = dataAttributes[a];
288
+ if (Array.isArray(attr) && attr.length === 1) {
289
+ ;
290
+ _a = attr, _b = __read(_a, 1), attr = _b[0];
291
+ }
292
+ f[b] = attr;
293
+ }
294
+ });
295
+ f.refName = f.seq_id;
296
+ // the SimpleFeature constructor takes care of recursively inflating subfeatures
297
+ if (data.child_features && data.child_features.length) {
298
+ f.subfeatures = data.child_features
299
+ .map(function (childLocs) { return childLocs.map(function (childLoc) { return _this.featureData(childLoc); }); })
300
+ .flat();
301
+ }
302
+ delete f.child_features;
303
+ delete f.data;
304
+ delete f.derived_features;
305
+ delete f._linehash;
306
+ delete f.attributes;
307
+ delete f.seq_id;
308
+ return f;
309
+ };
310
+ default_1.prototype.freeResources = function ( /* { region } */) { };
311
+ return default_1;
312
+ }(BaseAdapter_1.BaseFeatureDataAdapter));
313
+ exports.default = default_1;
314
+ //# sourceMappingURL=Gff3TabixAdapter.js.map