@jbrowse/plugin-alignments 1.5.8 → 1.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.
@@ -157,14 +157,14 @@ function _inherits(subClass, superClass) {
157
157
  throw new TypeError("Super expression must either be null or a function");
158
158
  }
159
159
 
160
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
161
+ constructor: {
162
+ value: subClass,
163
+ writable: true,
164
+ configurable: true
165
+ }
166
+ });
160
167
  Object.defineProperty(subClass, "prototype", {
161
- value: Object.create(superClass && superClass.prototype, {
162
- constructor: {
163
- value: subClass,
164
- writable: true,
165
- configurable: true
166
- }
167
- }),
168
168
  writable: false
169
169
  });
170
170
  if (superClass) _setPrototypeOf(subClass, superClass);
@@ -1604,9 +1604,12 @@ var MismatchParser = {
1604
1604
  };
1605
1605
 
1606
1606
  var configSchemaF = (function (pluginManager) {
1607
- var types = pluginManager.lib['mobx-state-tree'].types;
1608
- return types.late(function () {
1607
+ return mobxStateTree.types.late(function () {
1609
1608
  return configuration.ConfigurationSchema('CramAdapter', {
1609
+ fetchSizeLimit: {
1610
+ type: 'number',
1611
+ defaultValue: 3000000
1612
+ },
1610
1613
  cramLocation: {
1611
1614
  type: 'fileLocation',
1612
1615
  defaultValue: {
@@ -1671,7 +1674,7 @@ var configSchema = /*#__PURE__*/mobxStateTree.types.late(function () {
1671
1674
  },
1672
1675
  fetchSizeLimit: {
1673
1676
  type: 'number',
1674
- defaultValue: 500000000
1677
+ defaultValue: 5000000
1675
1678
  },
1676
1679
  sequenceAdapter: {
1677
1680
  type: 'frozen',
@@ -1993,28 +1996,24 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
1993
1996
  }(), opts.signal);
1994
1997
  }
1995
1998
  }, {
1996
- key: "getRefNames",
1999
+ key: "estimateRegionsStats",
1997
2000
  value: function () {
1998
- var _getRefNames = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1999
- var opts,
2000
- _yield$this$configure,
2001
- subadapter,
2002
- _args3 = arguments;
2001
+ var _estimateRegionsStats = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(regions, opts) {
2002
+ var _yield$this$configure, subadapter;
2003
2003
 
2004
2004
  return runtime_1.wrap(function _callee3$(_context3) {
2005
2005
  while (1) {
2006
2006
  switch (_context3.prev = _context3.next) {
2007
2007
  case 0:
2008
- opts = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
2009
- _context3.next = 3;
2008
+ _context3.next = 2;
2010
2009
  return this.configure();
2011
2010
 
2012
- case 3:
2011
+ case 2:
2013
2012
  _yield$this$configure = _context3.sent;
2014
2013
  subadapter = _yield$this$configure.subadapter;
2015
- return _context3.abrupt("return", subadapter.getRefNames(opts));
2014
+ return _context3.abrupt("return", subadapter.estimateRegionsStats(regions, opts));
2016
2015
 
2017
- case 6:
2016
+ case 5:
2018
2017
  case "end":
2019
2018
  return _context3.stop();
2020
2019
  }
@@ -2022,6 +2021,42 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
2022
2021
  }, _callee3, this);
2023
2022
  }));
2024
2023
 
2024
+ function estimateRegionsStats(_x2, _x3) {
2025
+ return _estimateRegionsStats.apply(this, arguments);
2026
+ }
2027
+
2028
+ return estimateRegionsStats;
2029
+ }()
2030
+ }, {
2031
+ key: "getRefNames",
2032
+ value: function () {
2033
+ var _getRefNames = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
2034
+ var opts,
2035
+ _yield$this$configure2,
2036
+ subadapter,
2037
+ _args4 = arguments;
2038
+
2039
+ return runtime_1.wrap(function _callee4$(_context4) {
2040
+ while (1) {
2041
+ switch (_context4.prev = _context4.next) {
2042
+ case 0:
2043
+ opts = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
2044
+ _context4.next = 3;
2045
+ return this.configure();
2046
+
2047
+ case 3:
2048
+ _yield$this$configure2 = _context4.sent;
2049
+ subadapter = _yield$this$configure2.subadapter;
2050
+ return _context4.abrupt("return", subadapter.getRefNames(opts));
2051
+
2052
+ case 6:
2053
+ case "end":
2054
+ return _context4.stop();
2055
+ }
2056
+ }
2057
+ }, _callee4, this);
2058
+ }));
2059
+
2025
2060
  function getRefNames() {
2026
2061
  return _getRefNames.apply(this, arguments);
2027
2062
  }
@@ -2045,20 +2080,20 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
2045
2080
  }, {
2046
2081
  key: "generateCoverageBins",
2047
2082
  value: function () {
2048
- var _generateCoverageBins = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(features, region, opts) {
2049
- var colorBy, _yield$this$configure2, sequenceAdapter, originalRefName, refName, start, end, binMax, skipmap, initBins, regionSeq, _yield$sequenceAdapte, _yield$sequenceAdapte2, feat, bins;
2083
+ var _generateCoverageBins = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(features, region, opts) {
2084
+ var colorBy, _yield$this$configure3, sequenceAdapter, originalRefName, refName, start, end, binMax, skipmap, initBins, regionSeq, _yield$sequenceAdapte, _yield$sequenceAdapte2, feat, bins;
2050
2085
 
2051
- return runtime_1.wrap(function _callee4$(_context4) {
2086
+ return runtime_1.wrap(function _callee5$(_context5) {
2052
2087
  while (1) {
2053
- switch (_context4.prev = _context4.next) {
2088
+ switch (_context5.prev = _context5.next) {
2054
2089
  case 0:
2055
2090
  colorBy = opts.colorBy;
2056
- _context4.next = 3;
2091
+ _context5.next = 3;
2057
2092
  return this.configure();
2058
2093
 
2059
2094
  case 3:
2060
- _yield$this$configure2 = _context4.sent;
2061
- sequenceAdapter = _yield$this$configure2.sequenceAdapter;
2095
+ _yield$this$configure3 = _context5.sent;
2096
+ sequenceAdapter = _yield$this$configure3.sequenceAdapter;
2062
2097
  originalRefName = region.originalRefName, refName = region.refName, start = region.start, end = region.end;
2063
2098
  binMax = Math.ceil(region.end - region.start);
2064
2099
  skipmap = {};
@@ -2076,11 +2111,11 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
2076
2111
  }); // request an extra +1 on the end to get CpG crossing region boundary
2077
2112
 
2078
2113
  if (!sequenceAdapter) {
2079
- _context4.next = 16;
2114
+ _context5.next = 16;
2080
2115
  break;
2081
2116
  }
2082
2117
 
2083
- _context4.next = 12;
2118
+ _context5.next = 12;
2084
2119
  return sequenceAdapter.getFeatures({
2085
2120
  refName: originalRefName || refName,
2086
2121
  start: start,
@@ -2089,13 +2124,13 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
2089
2124
  }).pipe(operators.toArray()).toPromise();
2090
2125
 
2091
2126
  case 12:
2092
- _yield$sequenceAdapte = _context4.sent;
2127
+ _yield$sequenceAdapte = _context5.sent;
2093
2128
  _yield$sequenceAdapte2 = _slicedToArray(_yield$sequenceAdapte, 1);
2094
2129
  feat = _yield$sequenceAdapte2[0];
2095
2130
  regionSeq = feat === null || feat === void 0 ? void 0 : feat.get('seq');
2096
2131
 
2097
2132
  case 16:
2098
- _context4.next = 18;
2133
+ _context5.next = 18;
2099
2134
  return features.pipe(operators.reduce(function (bins, feature) {
2100
2135
  var cigar = feature.get('CIGAR');
2101
2136
  var fstart = feature.get('start');
@@ -2286,21 +2321,21 @@ var SNPCoverageAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
2286
2321
  }, initBins)).toPromise();
2287
2322
 
2288
2323
  case 18:
2289
- bins = _context4.sent;
2290
- return _context4.abrupt("return", {
2324
+ bins = _context5.sent;
2325
+ return _context5.abrupt("return", {
2291
2326
  bins: bins,
2292
2327
  skipmap: skipmap
2293
2328
  });
2294
2329
 
2295
2330
  case 20:
2296
2331
  case "end":
2297
- return _context4.stop();
2332
+ return _context5.stop();
2298
2333
  }
2299
2334
  }
2300
- }, _callee4, this);
2335
+ }, _callee5, this);
2301
2336
  }));
2302
2337
 
2303
- function generateCoverageBins(_x2, _x3, _x4) {
2338
+ function generateCoverageBins(_x4, _x5, _x6) {
2304
2339
  return _generateCoverageBins.apply(this, arguments);
2305
2340
  }
2306
2341
 
@@ -3395,10 +3430,12 @@ var PileupRenderer = /*#__PURE__*/function (_BoxRendererType) {
3395
3430
  var _baseColor = colorForBase.deletion;
3396
3431
  ctx.fillStyle = _baseColor;
3397
3432
  ctx.fillRect(leftPx, topPx, widthPx, heightPx);
3433
+ var txt = "".concat(mismatch.length);
3434
+ var rect = ctx.measureText(txt);
3398
3435
 
3399
- if (widthPx >= charWidth && heightPx >= heightLim) {
3436
+ if (widthPx >= rect.width && heightPx >= heightLim) {
3400
3437
  ctx.fillStyle = theme.palette.getContrastText(_baseColor);
3401
- ctx.fillText(mbase, leftPx + (widthPx - charWidth) / 2 + 1, topPx + heightPx);
3438
+ ctx.fillText(txt, leftPx + (rightPx - leftPx) / 2 - rect.width / 2, topPx + heightPx);
3402
3439
  }
3403
3440
  } else if (mismatch.type === 'insertion' && drawIndels) {
3404
3441
  ctx.fillStyle = 'purple';
@@ -3458,19 +3495,20 @@ var PileupRenderer = /*#__PURE__*/function (_BoxRendererType) {
3458
3495
 
3459
3496
  var _len = +_mismatch.base || _mismatch.length;
3460
3497
 
3461
- var txt = "".concat(_len);
3498
+ var _txt = "".concat(_len);
3462
3499
 
3463
3500
  if (_mismatch.type === 'insertion' && _len >= 10) {
3464
3501
  if (bpPerPx > largeInsertionIndicatorScale) {
3465
3502
  ctx.fillStyle = 'purple';
3466
3503
  ctx.fillRect(_leftPx2 - 1, topPx, 2, heightPx);
3467
3504
  } else if (heightPx > charHeight) {
3468
- var rect = ctx.measureText(txt);
3505
+ var _rect = ctx.measureText(_txt);
3506
+
3469
3507
  var padding = 5;
3470
3508
  ctx.fillStyle = 'purple';
3471
- ctx.fillRect(_leftPx2 - rect.width / 2 - padding, topPx, rect.width + 2 * padding, heightPx);
3509
+ ctx.fillRect(_leftPx2 - _rect.width / 2 - padding, topPx, _rect.width + 2 * padding, heightPx);
3472
3510
  ctx.fillStyle = 'white';
3473
- ctx.fillText(txt, _leftPx2 - rect.width / 2, topPx + heightPx);
3511
+ ctx.fillText(_txt, _leftPx2 - _rect.width / 2, topPx + heightPx);
3474
3512
  } else {
3475
3513
  var _padding = 2;
3476
3514
  ctx.fillStyle = 'purple';
@@ -4096,7 +4134,8 @@ var stateModelFactory = function stateModelFactory(pluginManager, configSchema)
4096
4134
  configuration: configuration.ConfigurationReference(configSchema),
4097
4135
  height: 250,
4098
4136
  showCoverage: true,
4099
- showPileup: true
4137
+ showPileup: true,
4138
+ userFeatureScreenDensity: mobxStateTree.types.maybe(mobxStateTree.types.number)
4100
4139
  }))["volatile"](function () {
4101
4140
  return {
4102
4141
  scrollTop: 0
@@ -4189,9 +4228,9 @@ var stateModelFactory = function stateModelFactory(pluginManager, configSchema)
4189
4228
  height: self.snpCovHeight
4190
4229
  };
4191
4230
  },
4192
- setUserBpPerPxLimit: function setUserBpPerPxLimit(limit) {
4193
- self.PileupDisplay.setUserBpPerPxLimit(limit);
4194
- self.SNPCoverageDisplay.setUserBpPerPxLimit(limit);
4231
+ setUserFeatureScreenDensity: function setUserFeatureScreenDensity(limit) {
4232
+ self.PileupDisplay.setUserFeatureScreenDensity(limit);
4233
+ self.SNPCoverageDisplay.setUserFeatureScreenDensity(limit);
4195
4234
  },
4196
4235
  setPileupDisplay: function setPileupDisplay(displayConfig) {
4197
4236
  self.PileupDisplay = {
@@ -4382,11 +4421,6 @@ function SNPCoverageConfigFactory(pluginManager) {
4382
4421
  description: 'draw upside down',
4383
4422
  defaultValue: false
4384
4423
  },
4385
- maxDisplayedBpPerPx: {
4386
- type: 'number',
4387
- description: 'maximum bpPerPx that is displayed in the view',
4388
- defaultValue: 100
4389
- },
4390
4424
  headroom: {
4391
4425
  type: 'number',
4392
4426
  description: 'round the upper value of the domain scale to the nearest N',
@@ -4593,8 +4627,9 @@ var stateModelFactory$1 = function stateModelFactory(pluginManager, configSchema
4593
4627
  },
4594
4628
 
4595
4629
  renderProps: function renderProps() {
4596
- return _objectSpread2(_objectSpread2({}, superRenderProps()), {}, {
4597
- notReady: !self.ready || !this.modificationsReady,
4630
+ var superProps = superRenderProps();
4631
+ return _objectSpread2(_objectSpread2({}, superProps), {}, {
4632
+ notReady: superProps.notReady || !this.modificationsReady,
4598
4633
  filters: self.filters,
4599
4634
  modificationTagMap: JSON.parse(JSON.stringify(self.modificationTagMap)),
4600
4635
  // must use getSnapshot because otherwise changes to e.g. just the
@@ -4773,10 +4808,10 @@ function PileupConfigFactory(pluginManager) {
4773
4808
  SvgFeatureRenderer: SvgFeatureRendererConfigSchema
4774
4809
  }),
4775
4810
  renderer: '',
4776
- maxDisplayedBpPerPx: {
4811
+ maxFeatureScreenDensity: {
4777
4812
  type: 'number',
4778
- description: 'maximum bpPerPx that is displayed in the view',
4779
- defaultValue: 100
4813
+ description: 'maximum features per pixel that is displayed in the view',
4814
+ defaultValue: 5
4780
4815
  },
4781
4816
  colorScheme: {
4782
4817
  type: 'stringEnum',
@@ -4863,17 +4898,13 @@ var stateModelFactory$2 = function stateModelFactory(configSchema) {
4863
4898
  return {
4864
4899
  colorTagMap: mobx.observable.map({}),
4865
4900
  modificationTagMap: mobx.observable.map({}),
4866
- ready: false,
4867
- currBpPerPx: 0
4901
+ ready: false
4868
4902
  };
4869
4903
  }).actions(function (self) {
4870
4904
  return {
4871
4905
  setReady: function setReady(flag) {
4872
4906
  self.ready = flag;
4873
4907
  },
4874
- setCurrBpPerPx: function setCurrBpPerPx(n) {
4875
- self.currBpPerPx = n;
4876
- },
4877
4908
  setMaxHeight: function setMaxHeight(n) {
4878
4909
  self.trackMaxHeight = n;
4879
4910
  },
@@ -5176,14 +5207,14 @@ var stateModelFactory$2 = function stateModelFactory(configSchema) {
5176
5207
 
5177
5208
  renderProps: function renderProps() {
5178
5209
  var view = util.getContainingView(self);
5179
- var ready = self.ready,
5180
- colorTagMap = self.colorTagMap,
5210
+ var colorTagMap = self.colorTagMap,
5181
5211
  modificationTagMap = self.modificationTagMap,
5182
5212
  sortedBy = self.sortedBy,
5183
5213
  colorBy = self.colorBy,
5184
5214
  rpcDriverName = self.rpcDriverName;
5185
- return _objectSpread2(_objectSpread2({}, superRenderProps()), {}, {
5186
- notReady: !ready || sortedBy && self.currBpPerPx !== view.bpPerPx,
5215
+ var superProps = superRenderProps();
5216
+ return _objectSpread2(_objectSpread2({}, superProps), {}, {
5217
+ notReady: superProps.notReady || !self.ready || sortedBy && self.currBpPerPx !== view.bpPerPx,
5187
5218
  rpcDriverName: rpcDriverName,
5188
5219
  displayModel: self,
5189
5220
  sortedBy: sortedBy,
@@ -5676,13 +5707,16 @@ var AlignmentsPlugin = /*#__PURE__*/function (_Plugin) {
5676
5707
  var regexGuess = /\.cram$/i;
5677
5708
  var adapterName = 'CramAdapter';
5678
5709
  var fileName = tracks.getFileName(file);
5710
+ var obj = {
5711
+ type: adapterName,
5712
+ cramLocation: file,
5713
+ craiLocation: index || tracks.makeIndex(file, '.crai')
5714
+ };
5679
5715
 
5680
- if (regexGuess.test(fileName) || adapterHint === adapterName) {
5681
- return {
5682
- type: adapterName,
5683
- cramLocation: file,
5684
- craiLocation: index || tracks.makeIndex(file, '.crai')
5685
- };
5716
+ if (regexGuess.test(fileName) && !adapterHint) {
5717
+ return obj;
5718
+ } else if (adapterHint === adapterName) {
5719
+ return obj;
5686
5720
  }
5687
5721
 
5688
5722
  return adapterGuesser(file, index, adapterHint);
@@ -5694,16 +5728,19 @@ var AlignmentsPlugin = /*#__PURE__*/function (_Plugin) {
5694
5728
  var adapterName = 'BamAdapter';
5695
5729
  var fileName = tracks.getFileName(file);
5696
5730
  var indexName = index && tracks.getFileName(index);
5731
+ var obj = {
5732
+ type: adapterName,
5733
+ bamLocation: file,
5734
+ index: {
5735
+ location: index || tracks.makeIndex(file, '.bai'),
5736
+ indexType: tracks.makeIndexType(indexName, 'CSI', 'BAI')
5737
+ }
5738
+ };
5697
5739
 
5698
- if (regexGuess.test(fileName) || adapterHint === adapterName) {
5699
- return {
5700
- type: adapterName,
5701
- bamLocation: file,
5702
- index: {
5703
- location: index || tracks.makeIndex(file, '.bai'),
5704
- indexType: tracks.makeIndexType(indexName, 'CSI', 'BAI')
5705
- }
5706
- };
5740
+ if (regexGuess.test(fileName) && !adapterHint) {
5741
+ return obj;
5742
+ } else if (adapterHint === adapterName) {
5743
+ return obj;
5707
5744
  }
5708
5745
 
5709
5746
  return adapterGuesser(file, index, adapterHint);
@@ -6174,7 +6211,7 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6174
6211
  key: "configure",
6175
6212
  value: function () {
6176
6213
  var _configure = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
6177
- var cramLocation, craiLocation, sequenceAdapterType, _yield$this$getSubAda, dataAdapter;
6214
+ var cramLocation, craiLocation, cram$1, sequenceAdapterType, seqConf, _yield$this$getSubAda, sequenceAdapter;
6178
6215
 
6179
6216
  return runtime_1.wrap(function _callee$(_context) {
6180
6217
  while (1) {
@@ -6199,14 +6236,15 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6199
6236
  throw new Error('missing craiLocation argument');
6200
6237
 
6201
6238
  case 6:
6202
- this.cram = new cram.IndexedCramFile({
6239
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6240
+ cram$1 = new cram.IndexedCramFile({
6203
6241
  cramFilehandle: io.openLocation(cramLocation, this.pluginManager),
6204
6242
  index: new cram.CraiIndex({
6205
6243
  filehandle: io.openLocation(craiLocation, this.pluginManager)
6206
6244
  }),
6207
6245
  seqFetch: this.seqFetch.bind(this),
6208
6246
  checkSequenceMD5: false,
6209
- fetchSizeLimit: this.config.fetchSizeLimit || 600000000
6247
+ fetchSizeLimit: 200000000
6210
6248
  }); // instantiate the sequence adapter
6211
6249
 
6212
6250
  sequenceAdapterType = configuration.readConfObject(this.config, ['sequenceAdapter', 'type']);
@@ -6219,31 +6257,28 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6219
6257
  throw new Error('Error getting subadapter');
6220
6258
 
6221
6259
  case 10:
6222
- _context.next = 12;
6223
- return this.getSubAdapter(configuration.readConfObject(this.config, 'sequenceAdapter'));
6260
+ seqConf = configuration.readConfObject(this.config, 'sequenceAdapter');
6261
+ _context.next = 13;
6262
+ return this.getSubAdapter(seqConf);
6224
6263
 
6225
- case 12:
6264
+ case 13:
6226
6265
  _yield$this$getSubAda = _context.sent;
6227
- dataAdapter = _yield$this$getSubAda.dataAdapter;
6266
+ sequenceAdapter = _yield$this$getSubAda.dataAdapter;
6228
6267
 
6229
- if (!(dataAdapter instanceof BaseAdapter.BaseFeatureDataAdapter)) {
6230
- _context.next = 18;
6268
+ if (sequenceAdapter instanceof BaseAdapter.BaseFeatureDataAdapter) {
6269
+ _context.next = 17;
6231
6270
  break;
6232
6271
  }
6233
6272
 
6234
- this.sequenceAdapter = dataAdapter;
6235
- _context.next = 19;
6236
- break;
6237
-
6238
- case 18:
6239
6273
  throw new Error("CRAM feature adapters cannot use sequence adapters of type '".concat(sequenceAdapterType, "'"));
6240
6274
 
6241
- case 19:
6275
+ case 17:
6242
6276
  return _context.abrupt("return", {
6243
- sequenceAdapter: this.sequenceAdapter
6277
+ cram: cram$1,
6278
+ sequenceAdapter: sequenceAdapter
6244
6279
  });
6245
6280
 
6246
- case 20:
6281
+ case 18:
6247
6282
  case "end":
6248
6283
  return _context.stop();
6249
6284
  }
@@ -6261,6 +6296,8 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6261
6296
  key: "getHeader",
6262
6297
  value: function () {
6263
6298
  var _getHeader = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(opts) {
6299
+ var _yield$this$configure, cram;
6300
+
6264
6301
  return runtime_1.wrap(function _callee2$(_context2) {
6265
6302
  while (1) {
6266
6303
  switch (_context2.prev = _context2.next) {
@@ -6269,9 +6306,11 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6269
6306
  return this.configure();
6270
6307
 
6271
6308
  case 2:
6272
- return _context2.abrupt("return", this.cram.cram.getHeaderText(opts));
6309
+ _yield$this$configure = _context2.sent;
6310
+ cram = _yield$this$configure.cram;
6311
+ return _context2.abrupt("return", cram.cram.getHeaderText(opts));
6273
6312
 
6274
- case 3:
6313
+ case 5:
6275
6314
  case "end":
6276
6315
  return _context2.stop();
6277
6316
  }
@@ -6289,69 +6328,63 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6289
6328
  key: "seqFetch",
6290
6329
  value: function () {
6291
6330
  var _seqFetch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(seqId, start, end) {
6292
- var refSeqStore, refName, features, seqChunks, trimmed, sequence;
6331
+ var _yield$this$configure2, sequenceAdapter, refName, seqChunks, sequence;
6332
+
6293
6333
  return runtime_1.wrap(function _callee3$(_context3) {
6294
6334
  while (1) {
6295
6335
  switch (_context3.prev = _context3.next) {
6296
6336
  case 0:
6297
6337
  start -= 1; // convert from 1-based closed to interbase
6298
6338
 
6299
- refSeqStore = this.sequenceAdapter;
6300
-
6301
- if (refSeqStore) {
6302
- _context3.next = 4;
6303
- break;
6304
- }
6305
-
6306
- return _context3.abrupt("return", undefined);
6339
+ _context3.next = 3;
6340
+ return this.configure();
6307
6341
 
6308
- case 4:
6342
+ case 3:
6343
+ _yield$this$configure2 = _context3.sent;
6344
+ sequenceAdapter = _yield$this$configure2.sequenceAdapter;
6309
6345
  refName = this.refIdToOriginalName(seqId) || this.refIdToName(seqId);
6310
6346
 
6311
6347
  if (refName) {
6312
- _context3.next = 7;
6348
+ _context3.next = 8;
6313
6349
  break;
6314
6350
  }
6315
6351
 
6316
6352
  return _context3.abrupt("return", undefined);
6317
6353
 
6318
- case 7:
6319
- features = refSeqStore.getFeatures({
6354
+ case 8:
6355
+ _context3.next = 10;
6356
+ return sequenceAdapter.getFeatures({
6320
6357
  refName: refName,
6321
6358
  start: start,
6322
6359
  end: end,
6323
6360
  assemblyName: ''
6324
- }, {});
6325
- _context3.next = 10;
6326
- return features.pipe(operators.toArray()).toPromise();
6361
+ }).pipe(operators.toArray()).toPromise();
6327
6362
 
6328
6363
  case 10:
6329
6364
  seqChunks = _context3.sent;
6330
- trimmed = [];
6331
- seqChunks.sort(function (a, b) {
6365
+ sequence = seqChunks.sort(function (a, b) {
6332
6366
  return a.get('start') - b.get('start');
6333
- }).forEach(function (chunk) {
6367
+ }).map(function (chunk) {
6334
6368
  var chunkStart = chunk.get('start');
6335
6369
  var chunkEnd = chunk.get('end');
6336
6370
  var trimStart = Math.max(start - chunkStart, 0);
6337
6371
  var trimEnd = Math.min(end - chunkStart, chunkEnd - chunkStart);
6338
6372
  var trimLength = trimEnd - trimStart;
6339
6373
  var chunkSeq = chunk.get('seq') || chunk.get('residues');
6340
- trimmed.push(chunkSeq.substr(trimStart, trimLength));
6341
- });
6342
- sequence = trimmed.join('');
6374
+ return chunkSeq.substr(trimStart, trimLength);
6375
+ }).join('');
6343
6376
 
6344
6377
  if (!(sequence.length !== end - start)) {
6345
- _context3.next = 16;
6378
+ _context3.next = 14;
6346
6379
  break;
6347
6380
  }
6348
6381
 
6349
6382
  throw new Error("sequence fetch failed: fetching ".concat(refName, ":").concat((start - 1).toLocaleString(), "-").concat(end.toLocaleString(), " returned ").concat(sequence.length.toLocaleString(), " bases, but should have returned ").concat((end - start).toLocaleString()));
6350
6383
 
6351
- case 16:
6384
+ case 14:
6352
6385
  return _context3.abrupt("return", sequence);
6353
6386
 
6354
- case 17:
6387
+ case 15:
6355
6388
  case "end":
6356
6389
  return _context3.stop();
6357
6390
  }
@@ -6365,77 +6398,91 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6365
6398
 
6366
6399
  return seqFetch;
6367
6400
  }()
6401
+ }, {
6402
+ key: "setupPre",
6403
+ value: function () {
6404
+ var _setupPre = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
6405
+ var _ref, _ref$statusCallback, statusCallback, configured, cram, samHeader, idToName, nameToId, readGroups, data;
6406
+
6407
+ return runtime_1.wrap(function _callee4$(_context4) {
6408
+ while (1) {
6409
+ switch (_context4.prev = _context4.next) {
6410
+ case 0:
6411
+ _ref = opts || {}, _ref$statusCallback = _ref.statusCallback, statusCallback = _ref$statusCallback === void 0 ? function () {} : _ref$statusCallback;
6412
+ _context4.next = 3;
6413
+ return this.configure();
6414
+
6415
+ case 3:
6416
+ configured = _context4.sent;
6417
+ statusCallback('Downloading index');
6418
+ cram = configured.cram;
6419
+ _context4.next = 8;
6420
+ return cram.cram.getSamHeader(opts === null || opts === void 0 ? void 0 : opts.signal);
6421
+
6422
+ case 8:
6423
+ samHeader = _context4.sent;
6424
+ // use the @SQ lines in the header to figure out the
6425
+ // mapping between ref ID numbers and names
6426
+ idToName = [];
6427
+ nameToId = {};
6428
+ samHeader.filter(function (l) {
6429
+ return l.tag === 'SQ';
6430
+ }).forEach(function (sqLine, refId) {
6431
+ sqLine.data.forEach(function (item) {
6432
+ if (item.tag === 'SN') {
6433
+ // this is the ref name
6434
+ var refName = item.value;
6435
+ nameToId[refName] = refId;
6436
+ idToName[refId] = refName;
6437
+ }
6438
+ });
6439
+ });
6440
+ readGroups = samHeader.filter(function (l) {
6441
+ return l.tag === 'RG';
6442
+ }).map(function (rgLine) {
6443
+ var _rgLine$data$find;
6444
+
6445
+ return (_rgLine$data$find = rgLine.data.find(function (item) {
6446
+ return item.tag === 'ID';
6447
+ })) === null || _rgLine$data$find === void 0 ? void 0 : _rgLine$data$find.value;
6448
+ });
6449
+ data = {
6450
+ idToName: idToName,
6451
+ nameToId: nameToId,
6452
+ readGroups: readGroups
6453
+ };
6454
+ statusCallback('');
6455
+ this.samHeader = data;
6456
+ return _context4.abrupt("return", _objectSpread2({
6457
+ samHeader: data
6458
+ }, configured));
6459
+
6460
+ case 17:
6461
+ case "end":
6462
+ return _context4.stop();
6463
+ }
6464
+ }
6465
+ }, _callee4, this);
6466
+ }));
6467
+
6468
+ function setupPre(_x5) {
6469
+ return _setupPre.apply(this, arguments);
6470
+ }
6471
+
6472
+ return setupPre;
6473
+ }()
6368
6474
  }, {
6369
6475
  key: "setup",
6370
6476
  value: function () {
6371
6477
  var _setup = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(opts) {
6372
6478
  var _this2 = this;
6373
6479
 
6374
- var _ref, _ref$statusCallback, statusCallback;
6375
-
6376
6480
  return runtime_1.wrap(function _callee5$(_context5) {
6377
6481
  while (1) {
6378
6482
  switch (_context5.prev = _context5.next) {
6379
6483
  case 0:
6380
- _ref = opts || {}, _ref$statusCallback = _ref.statusCallback, statusCallback = _ref$statusCallback === void 0 ? function () {} : _ref$statusCallback;
6381
-
6382
6484
  if (!this.setupP) {
6383
- this.setupP = this.configure().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
6384
- var samHeader, idToName, nameToId, readGroups;
6385
- return runtime_1.wrap(function _callee4$(_context4) {
6386
- while (1) {
6387
- switch (_context4.prev = _context4.next) {
6388
- case 0:
6389
- statusCallback('Downloading index');
6390
- _context4.next = 3;
6391
- return _this2.cram.cram.getSamHeader(opts === null || opts === void 0 ? void 0 : opts.signal);
6392
-
6393
- case 3:
6394
- samHeader = _context4.sent;
6395
- // use the @SQ lines in the header to figure out the
6396
- // mapping between ref ID numbers and names
6397
- idToName = [];
6398
- nameToId = {};
6399
- samHeader.filter(function (l) {
6400
- return l.tag === 'SQ';
6401
- }).forEach(function (sqLine, refId) {
6402
- sqLine.data.forEach(function (item) {
6403
- if (item.tag === 'SN') {
6404
- // this is the ref name
6405
- var refName = item.value;
6406
- nameToId[refName] = refId;
6407
- idToName[refId] = refName;
6408
- }
6409
- });
6410
- });
6411
- readGroups = samHeader.filter(function (l) {
6412
- return l.tag === 'RG';
6413
- }).map(function (rgLine) {
6414
- var _rgLine$data$find;
6415
-
6416
- return (_rgLine$data$find = rgLine.data.find(function (item) {
6417
- return item.tag === 'ID';
6418
- })) === null || _rgLine$data$find === void 0 ? void 0 : _rgLine$data$find.value;
6419
- });
6420
-
6421
- if (idToName.length) {
6422
- _this2.samHeader = {
6423
- idToName: idToName,
6424
- nameToId: nameToId,
6425
- readGroups: readGroups
6426
- };
6427
- }
6428
-
6429
- statusCallback('');
6430
- return _context4.abrupt("return", _this2.samHeader);
6431
-
6432
- case 11:
6433
- case "end":
6434
- return _context4.stop();
6435
- }
6436
- }
6437
- }, _callee4);
6438
- })))["catch"](function (e) {
6485
+ this.setupP = this.setupPre(opts)["catch"](function (e) {
6439
6486
  _this2.setupP = undefined;
6440
6487
  throw e;
6441
6488
  });
@@ -6443,7 +6490,7 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6443
6490
 
6444
6491
  return _context5.abrupt("return", this.setupP);
6445
6492
 
6446
- case 3:
6493
+ case 2:
6447
6494
  case "end":
6448
6495
  return _context5.stop();
6449
6496
  }
@@ -6451,7 +6498,7 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6451
6498
  }, _callee5, this);
6452
6499
  }));
6453
6500
 
6454
- function setup(_x5) {
6501
+ function setup(_x6) {
6455
6502
  return _setup.apply(this, arguments);
6456
6503
  }
6457
6504
 
@@ -6461,6 +6508,8 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6461
6508
  key: "getRefNames",
6462
6509
  value: function () {
6463
6510
  var _getRefNames = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
6511
+ var _yield$this$setup, samHeader;
6512
+
6464
6513
  return runtime_1.wrap(function _callee6$(_context6) {
6465
6514
  while (1) {
6466
6515
  switch (_context6.prev = _context6.next) {
@@ -6469,23 +6518,18 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6469
6518
  return this.setup(opts);
6470
6519
 
6471
6520
  case 2:
6472
- if (!this.samHeader.idToName) {
6473
- _context6.next = 4;
6474
- break;
6475
- }
6476
-
6477
- return _context6.abrupt("return", this.samHeader.idToName);
6521
+ _yield$this$setup = _context6.sent;
6522
+ samHeader = _yield$this$setup.samHeader;
6478
6523
 
6479
- case 4:
6480
- if (!this.sequenceAdapter) {
6524
+ if (samHeader.idToName) {
6481
6525
  _context6.next = 6;
6482
6526
  break;
6483
6527
  }
6484
6528
 
6485
- return _context6.abrupt("return", this.sequenceAdapter.getRefNames());
6529
+ throw new Error('CRAM file has no header lines');
6486
6530
 
6487
6531
  case 6:
6488
- throw new Error('unable to get refnames');
6532
+ return _context6.abrupt("return", samHeader.idToName);
6489
6533
 
6490
6534
  case 7:
6491
6535
  case "end":
@@ -6495,7 +6539,7 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6495
6539
  }, _callee6, this);
6496
6540
  }));
6497
6541
 
6498
- function getRefNames(_x6) {
6542
+ function getRefNames(_x7) {
6499
6543
  return _getRefNames.apply(this, arguments);
6500
6544
  }
6501
6545
 
@@ -6541,18 +6585,19 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6541
6585
  value: function getFeatures(region, opts) {
6542
6586
  var _this3 = this;
6543
6587
 
6544
- var _ref3 = opts || {},
6545
- signal = _ref3.signal,
6546
- _ref3$statusCallback = _ref3.statusCallback,
6547
- statusCallback = _ref3$statusCallback === void 0 ? function () {} : _ref3$statusCallback;
6588
+ var _ref2 = opts || {},
6589
+ signal = _ref2.signal,
6590
+ _ref2$statusCallback = _ref2.statusCallback,
6591
+ statusCallback = _ref2$statusCallback === void 0 ? function () {} : _ref2$statusCallback;
6548
6592
 
6549
6593
  var refName = region.refName,
6550
6594
  start = region.start,
6551
6595
  end = region.end,
6552
6596
  originalRefName = region.originalRefName;
6553
6597
  return rxjs.ObservableCreate( /*#__PURE__*/function () {
6554
- var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(observer) {
6555
- var refId, records;
6598
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(observer) {
6599
+ var _yield$_this3$setup, cram, sequenceAdapter, refId, records;
6600
+
6556
6601
  return runtime_1.wrap(function _callee7$(_context7) {
6557
6602
  while (1) {
6558
6603
  switch (_context7.prev = _context7.next) {
@@ -6561,22 +6606,27 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6561
6606
  return _this3.setup(opts);
6562
6607
 
6563
6608
  case 2:
6564
- if (!(_this3.sequenceAdapter && !_this3.seqIdToRefName)) {
6565
- _context7.next = 6;
6609
+ _yield$_this3$setup = _context7.sent;
6610
+ cram = _yield$_this3$setup.cram;
6611
+ sequenceAdapter = _yield$_this3$setup.sequenceAdapter;
6612
+ statusCallback('Downloading alignments');
6613
+
6614
+ if (_this3.seqIdToRefName) {
6615
+ _context7.next = 10;
6566
6616
  break;
6567
6617
  }
6568
6618
 
6569
- _context7.next = 5;
6570
- return _this3.sequenceAdapter.getRefNames(opts);
6619
+ _context7.next = 9;
6620
+ return sequenceAdapter.getRefNames(opts);
6571
6621
 
6572
- case 5:
6622
+ case 9:
6573
6623
  _this3.seqIdToRefName = _context7.sent;
6574
6624
 
6575
- case 6:
6625
+ case 10:
6576
6626
  refId = _this3.refNameToId(refName);
6577
6627
 
6578
6628
  if (!(refId !== undefined)) {
6579
- _context7.next = 15;
6629
+ _context7.next = 20;
6580
6630
  break;
6581
6631
  }
6582
6632
 
@@ -6584,23 +6634,27 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6584
6634
  _this3.seqIdToOriginalRefName[refId] = originalRefName;
6585
6635
  }
6586
6636
 
6587
- statusCallback('Downloading alignments');
6588
- _context7.next = 12;
6589
- return _this3.cram.getRecordsForRange(refId, start, end, opts);
6637
+ _context7.next = 15;
6638
+ return cram.getRecordsForRange(refId, start, end, opts);
6590
6639
 
6591
- case 12:
6640
+ case 15:
6592
6641
  records = _context7.sent;
6593
6642
  util.checkAbortSignal(signal); // eslint-disable-next-line @typescript-eslint/no-explicit-any
6594
6643
 
6595
6644
  records.forEach(function (record) {
6596
6645
  observer.next(_this3.cramRecordToFeature(record));
6597
6646
  });
6647
+ _context7.next = 21;
6648
+ break;
6598
6649
 
6599
- case 15:
6650
+ case 20:
6651
+ console.warn('Unknown refName', refName);
6652
+
6653
+ case 21:
6600
6654
  statusCallback('');
6601
6655
  observer.complete();
6602
6656
 
6603
- case 17:
6657
+ case 23:
6604
6658
  case "end":
6605
6659
  return _context7.stop();
6606
6660
  }
@@ -6608,8 +6662,8 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6608
6662
  }, _callee7);
6609
6663
  }));
6610
6664
 
6611
- return function (_x7) {
6612
- return _ref4.apply(this, arguments);
6665
+ return function (_x8) {
6666
+ return _ref3.apply(this, arguments);
6613
6667
  };
6614
6668
  }(), signal);
6615
6669
  }
@@ -6617,13 +6671,102 @@ var CramAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6617
6671
  key: "freeResources",
6618
6672
  value: function
6619
6673
  /* { region } */
6620
- freeResources() {} // eslint-disable-next-line @typescript-eslint/no-explicit-any
6621
-
6674
+ freeResources() {}
6622
6675
  }, {
6623
6676
  key: "cramRecordToFeature",
6624
6677
  value: function cramRecordToFeature(record) {
6625
6678
  return new CramSlightlyLazyFeature(record, this);
6626
- }
6679
+ } // we return the configured fetchSizeLimit, and the bytes for the region
6680
+
6681
+ }, {
6682
+ key: "estimateRegionsStats",
6683
+ value: function () {
6684
+ var _estimateRegionsStats = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(regions, opts) {
6685
+ var bytes, fetchSizeLimit;
6686
+ return runtime_1.wrap(function _callee8$(_context8) {
6687
+ while (1) {
6688
+ switch (_context8.prev = _context8.next) {
6689
+ case 0:
6690
+ _context8.next = 2;
6691
+ return this.bytesForRegions(regions, opts);
6692
+
6693
+ case 2:
6694
+ bytes = _context8.sent;
6695
+ fetchSizeLimit = configuration.readConfObject(this.config, 'fetchSizeLimit');
6696
+ return _context8.abrupt("return", {
6697
+ bytes: bytes,
6698
+ fetchSizeLimit: fetchSizeLimit
6699
+ });
6700
+
6701
+ case 5:
6702
+ case "end":
6703
+ return _context8.stop();
6704
+ }
6705
+ }
6706
+ }, _callee8, this);
6707
+ }));
6708
+
6709
+ function estimateRegionsStats(_x9, _x10) {
6710
+ return _estimateRegionsStats.apply(this, arguments);
6711
+ }
6712
+
6713
+ return estimateRegionsStats;
6714
+ }()
6715
+ /**
6716
+ * get the approximate number of bytes queried from the file for the given
6717
+ * query regions
6718
+ * @param regions - list of query regions
6719
+ */
6720
+
6721
+ }, {
6722
+ key: "bytesForRegions",
6723
+ value: function () {
6724
+ var _bytesForRegions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(regions, _opts) {
6725
+ var _this4 = this;
6726
+
6727
+ var _yield$this$configure3, cram, blockResults;
6728
+
6729
+ return runtime_1.wrap(function _callee9$(_context9) {
6730
+ while (1) {
6731
+ switch (_context9.prev = _context9.next) {
6732
+ case 0:
6733
+ _context9.next = 2;
6734
+ return this.configure();
6735
+
6736
+ case 2:
6737
+ _yield$this$configure3 = _context9.sent;
6738
+ cram = _yield$this$configure3.cram;
6739
+ _context9.next = 6;
6740
+ return Promise.all(regions.map(function (region) {
6741
+ var refName = region.refName,
6742
+ start = region.start,
6743
+ end = region.end;
6744
+
6745
+ var chrId = _this4.refNameToId(refName);
6746
+
6747
+ return cram.index.getEntriesForRange(chrId, start, end);
6748
+ }));
6749
+
6750
+ case 6:
6751
+ blockResults = _context9.sent;
6752
+ return _context9.abrupt("return", blockResults.flat().reduce(function (a, b) {
6753
+ return a + b.sliceBytes;
6754
+ }, 0));
6755
+
6756
+ case 8:
6757
+ case "end":
6758
+ return _context9.stop();
6759
+ }
6760
+ }
6761
+ }, _callee9, this);
6762
+ }));
6763
+
6764
+ function bytesForRegions(_x11, _x12) {
6765
+ return _bytesForRegions.apply(this, arguments);
6766
+ }
6767
+
6768
+ return bytesForRegions;
6769
+ }()
6627
6770
  }]);
6628
6771
 
6629
6772
  return CramAdapter;
@@ -6661,7 +6804,6 @@ var BamSlightlyLazyFeature = /*#__PURE__*/function () {
6661
6804
  }, {
6662
6805
  key: "_get_flags",
6663
6806
  value: function _get_flags() {
6664
- // @ts-ignore
6665
6807
  return this.record.flags;
6666
6808
  }
6667
6809
  }, {
@@ -6669,12 +6811,6 @@ var BamSlightlyLazyFeature = /*#__PURE__*/function () {
6669
6811
  value: function _get_strand() {
6670
6812
  return this.record.isReverseComplemented() ? -1 : 1;
6671
6813
  }
6672
- }, {
6673
- key: "_get_read_group_id",
6674
- value: function _get_read_group_id() {
6675
- // @ts-ignore
6676
- return this.record.readGroupId;
6677
- }
6678
6814
  }, {
6679
6815
  key: "_get_pair_orientation",
6680
6816
  value: function _get_pair_orientation() {
@@ -6699,7 +6835,9 @@ var BamSlightlyLazyFeature = /*#__PURE__*/function () {
6699
6835
  }, {
6700
6836
  key: "_get_next_segment_position",
6701
6837
  value: function _get_next_segment_position() {
6702
- return this.record.isPaired() ? "".concat(this.adapter.refIdToName(this.record._next_refid()), ":").concat(this.record._next_pos() + 1) : undefined;
6838
+ var record = this.record,
6839
+ adapter = this.adapter;
6840
+ return record.isPaired() ? "".concat(adapter.refIdToName(record._next_refid()), ":").concat(record._next_pos() + 1) : undefined;
6703
6841
  }
6704
6842
  }, {
6705
6843
  key: "_get_seq",
@@ -6871,7 +7009,7 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6871
7009
  // configure method allows derived classes to override this behavior
6872
7010
  function () {
6873
7011
  var _configure = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
6874
- var bamLocation, location, indexType, chunkSizeLimit, fetchSizeLimit, bam$1, adapterConfig;
7012
+ var bamLocation, location, indexType, chunkSizeLimit, bam$1, adapterConfig;
6875
7013
  return runtime_1.wrap(function _callee$(_context) {
6876
7014
  while (1) {
6877
7015
  switch (_context.prev = _context.next) {
@@ -6881,13 +7019,12 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6881
7019
  location = configuration.readConfObject(this.config, ['index', 'location']);
6882
7020
  indexType = configuration.readConfObject(this.config, ['index', 'indexType']);
6883
7021
  chunkSizeLimit = configuration.readConfObject(this.config, 'chunkSizeLimit');
6884
- fetchSizeLimit = configuration.readConfObject(this.config, 'fetchSizeLimit');
6885
7022
  bam$1 = new bam.BamFile({
6886
7023
  bamFilehandle: io.openLocation(bamLocation, this.pluginManager),
6887
7024
  csiFilehandle: indexType === 'CSI' ? io.openLocation(location, this.pluginManager) : undefined,
6888
7025
  baiFilehandle: indexType !== 'CSI' ? io.openLocation(location, this.pluginManager) : undefined,
6889
7026
  chunkSizeLimit: chunkSizeLimit,
6890
- fetchSizeLimit: fetchSizeLimit
7027
+ fetchSizeLimit: 100000000
6891
7028
  });
6892
7029
  adapterConfig = configuration.readConfObject(this.config, 'sequenceAdapter');
6893
7030
 
@@ -6955,87 +7092,109 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
6955
7092
  return getHeader;
6956
7093
  }()
6957
7094
  }, {
6958
- key: "setup",
7095
+ key: "setupPre",
6959
7096
  value: function () {
6960
- var _setup = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
6961
- var _this = this;
6962
-
6963
- var _ref2, _ref2$statusCallback, statusCallback;
7097
+ var _setupPre = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
7098
+ var _ref2, _ref2$statusCallback, statusCallback, _yield$this$configure2, bam;
6964
7099
 
6965
7100
  return runtime_1.wrap(function _callee4$(_context4) {
6966
7101
  while (1) {
6967
7102
  switch (_context4.prev = _context4.next) {
6968
7103
  case 0:
6969
- // note that derived classes may not provide a BAM directly so this is
6970
- // conditional
6971
7104
  _ref2 = opts || {}, _ref2$statusCallback = _ref2.statusCallback, statusCallback = _ref2$statusCallback === void 0 ? function () {} : _ref2$statusCallback;
7105
+ _context4.next = 3;
7106
+ return this.configure();
6972
7107
 
6973
- if (!this.setupP) {
6974
- this.setupP = this.configure().then( /*#__PURE__*/function () {
6975
- var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref3) {
6976
- var bam, samHeader, idToName, nameToId;
6977
- return runtime_1.wrap(function _callee3$(_context3) {
6978
- while (1) {
6979
- switch (_context3.prev = _context3.next) {
6980
- case 0:
6981
- bam = _ref3.bam;
6982
- statusCallback('Downloading index');
6983
- _context3.next = 4;
6984
- return bam.getHeader(opts);
6985
-
6986
- case 4:
6987
- samHeader = _context3.sent;
6988
- // use the @SQ lines in the header to figure out the
6989
- // mapping between ref ref ID numbers and names
6990
- idToName = [];
6991
- nameToId = {};
6992
- samHeader.filter(function (l) {
6993
- return l.tag === 'SQ';
6994
- }).forEach(function (sqLine, refId) {
6995
- sqLine.data.forEach(function (item) {
6996
- if (item.tag === 'SN') {
6997
- // this is the ref name
6998
- var refName = item.value;
6999
- nameToId[refName] = refId;
7000
- idToName[refId] = refName;
7001
- }
7002
- });
7003
- });
7004
- statusCallback('');
7005
- _this.samHeader = {
7006
- idToName: idToName,
7007
- nameToId: nameToId
7008
- };
7009
- return _context3.abrupt("return", _this.samHeader);
7010
-
7011
- case 11:
7012
- case "end":
7013
- return _context3.stop();
7014
- }
7015
- }
7016
- }, _callee3);
7017
- }));
7108
+ case 3:
7109
+ _yield$this$configure2 = _context4.sent;
7110
+ bam = _yield$this$configure2.bam;
7111
+ _context4.next = 7;
7112
+ return util.updateStatus('Downloading index', statusCallback, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
7113
+ var samHeader, idToName, nameToId;
7114
+ return runtime_1.wrap(function _callee3$(_context3) {
7115
+ while (1) {
7116
+ switch (_context3.prev = _context3.next) {
7117
+ case 0:
7118
+ _context3.next = 2;
7119
+ return bam.getHeader(opts);
7120
+
7121
+ case 2:
7122
+ samHeader = _context3.sent;
7123
+ // use the @SQ lines in the header to figure out the
7124
+ // mapping between ref ref ID numbers and names
7125
+ idToName = [];
7126
+ nameToId = {};
7127
+ samHeader.filter(function (l) {
7128
+ return l.tag === 'SQ';
7129
+ }).forEach(function (sqLine, refId) {
7130
+ sqLine.data.forEach(function (item) {
7131
+ if (item.tag === 'SN') {
7132
+ // this is the ref name
7133
+ var refName = item.value;
7134
+ nameToId[refName] = refId;
7135
+ idToName[refId] = refName;
7136
+ }
7137
+ });
7138
+ });
7139
+ return _context3.abrupt("return", {
7140
+ idToName: idToName,
7141
+ nameToId: nameToId
7142
+ });
7143
+
7144
+ case 7:
7145
+ case "end":
7146
+ return _context3.stop();
7147
+ }
7148
+ }
7149
+ }, _callee3);
7150
+ })));
7018
7151
 
7019
- return function (_x3) {
7020
- return _ref4.apply(this, arguments);
7021
- };
7022
- }())["catch"](function (e) {
7152
+ case 7:
7153
+ this.samHeader = _context4.sent;
7154
+ return _context4.abrupt("return", this.samHeader);
7155
+
7156
+ case 9:
7157
+ case "end":
7158
+ return _context4.stop();
7159
+ }
7160
+ }
7161
+ }, _callee4, this);
7162
+ }));
7163
+
7164
+ function setupPre(_x2) {
7165
+ return _setupPre.apply(this, arguments);
7166
+ }
7167
+
7168
+ return setupPre;
7169
+ }()
7170
+ }, {
7171
+ key: "setup",
7172
+ value: function () {
7173
+ var _setup = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(opts) {
7174
+ var _this = this;
7175
+
7176
+ return runtime_1.wrap(function _callee5$(_context5) {
7177
+ while (1) {
7178
+ switch (_context5.prev = _context5.next) {
7179
+ case 0:
7180
+ if (!this.setupP) {
7181
+ this.setupP = this.setupPre(opts)["catch"](function (e) {
7023
7182
  _this.setupP = undefined;
7024
7183
  throw e;
7025
7184
  });
7026
7185
  }
7027
7186
 
7028
- return _context4.abrupt("return", this.setupP);
7187
+ return _context5.abrupt("return", this.setupP);
7029
7188
 
7030
- case 3:
7189
+ case 2:
7031
7190
  case "end":
7032
- return _context4.stop();
7191
+ return _context5.stop();
7033
7192
  }
7034
7193
  }
7035
- }, _callee4, this);
7194
+ }, _callee5, this);
7036
7195
  }));
7037
7196
 
7038
- function setup(_x2) {
7197
+ function setup(_x3) {
7039
7198
  return _setup.apply(this, arguments);
7040
7199
  }
7041
7200
 
@@ -7044,27 +7203,27 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7044
7203
  }, {
7045
7204
  key: "getRefNames",
7046
7205
  value: function () {
7047
- var _getRefNames = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(opts) {
7206
+ var _getRefNames = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
7048
7207
  var _yield$this$setup, idToName;
7049
7208
 
7050
- return runtime_1.wrap(function _callee5$(_context5) {
7209
+ return runtime_1.wrap(function _callee6$(_context6) {
7051
7210
  while (1) {
7052
- switch (_context5.prev = _context5.next) {
7211
+ switch (_context6.prev = _context6.next) {
7053
7212
  case 0:
7054
- _context5.next = 2;
7213
+ _context6.next = 2;
7055
7214
  return this.setup(opts);
7056
7215
 
7057
7216
  case 2:
7058
- _yield$this$setup = _context5.sent;
7217
+ _yield$this$setup = _context6.sent;
7059
7218
  idToName = _yield$this$setup.idToName;
7060
- return _context5.abrupt("return", idToName);
7219
+ return _context6.abrupt("return", idToName);
7061
7220
 
7062
7221
  case 5:
7063
7222
  case "end":
7064
- return _context5.stop();
7223
+ return _context6.stop();
7065
7224
  }
7066
7225
  }
7067
- }, _callee5, this);
7226
+ }, _callee6, this);
7068
7227
  }));
7069
7228
 
7070
7229
  function getRefNames(_x4) {
@@ -7076,35 +7235,35 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7076
7235
  }, {
7077
7236
  key: "seqFetch",
7078
7237
  value: function () {
7079
- var _seqFetch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(refName, start, end) {
7080
- var _yield$this$configure2, sequenceAdapter, refSeqStore, features, seqChunks, trimmed, sequence;
7238
+ var _seqFetch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(refName, start, end) {
7239
+ var _yield$this$configure3, sequenceAdapter, refSeqStore, features, seqChunks, trimmed, sequence;
7081
7240
 
7082
- return runtime_1.wrap(function _callee6$(_context6) {
7241
+ return runtime_1.wrap(function _callee7$(_context7) {
7083
7242
  while (1) {
7084
- switch (_context6.prev = _context6.next) {
7243
+ switch (_context7.prev = _context7.next) {
7085
7244
  case 0:
7086
- _context6.next = 2;
7245
+ _context7.next = 2;
7087
7246
  return this.configure();
7088
7247
 
7089
7248
  case 2:
7090
- _yield$this$configure2 = _context6.sent;
7091
- sequenceAdapter = _yield$this$configure2.sequenceAdapter;
7249
+ _yield$this$configure3 = _context7.sent;
7250
+ sequenceAdapter = _yield$this$configure3.sequenceAdapter;
7092
7251
  refSeqStore = sequenceAdapter;
7093
7252
 
7094
7253
  if (refSeqStore) {
7095
- _context6.next = 7;
7254
+ _context7.next = 7;
7096
7255
  break;
7097
7256
  }
7098
7257
 
7099
- return _context6.abrupt("return", undefined);
7258
+ return _context7.abrupt("return", undefined);
7100
7259
 
7101
7260
  case 7:
7102
7261
  if (refName) {
7103
- _context6.next = 9;
7262
+ _context7.next = 9;
7104
7263
  break;
7105
7264
  }
7106
7265
 
7107
- return _context6.abrupt("return", undefined);
7266
+ return _context7.abrupt("return", undefined);
7108
7267
 
7109
7268
  case 9:
7110
7269
  features = refSeqStore.getFeatures({
@@ -7113,11 +7272,11 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7113
7272
  end: end,
7114
7273
  assemblyName: ''
7115
7274
  });
7116
- _context6.next = 12;
7275
+ _context7.next = 12;
7117
7276
  return features.pipe(operators.toArray()).toPromise();
7118
7277
 
7119
7278
  case 12:
7120
- seqChunks = _context6.sent;
7279
+ seqChunks = _context7.sent;
7121
7280
  trimmed = [];
7122
7281
  seqChunks.sort(function (a, b) {
7123
7282
  return a.get('start') - b.get('start');
@@ -7133,21 +7292,21 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7133
7292
  sequence = trimmed.join('');
7134
7293
 
7135
7294
  if (!(sequence.length !== end - start)) {
7136
- _context6.next = 18;
7295
+ _context7.next = 18;
7137
7296
  break;
7138
7297
  }
7139
7298
 
7140
7299
  throw new Error("sequence fetch failed: fetching ".concat(refName, ":").concat((start - 1).toLocaleString(), "-").concat(end.toLocaleString(), " returned ").concat(sequence.length.toLocaleString(), " bases, but should have returned ").concat((end - start).toLocaleString()));
7141
7300
 
7142
7301
  case 18:
7143
- return _context6.abrupt("return", sequence);
7302
+ return _context7.abrupt("return", sequence);
7144
7303
 
7145
7304
  case 19:
7146
7305
  case "end":
7147
- return _context6.stop();
7306
+ return _context7.stop();
7148
7307
  }
7149
7308
  }
7150
- }, _callee6, this);
7309
+ }, _callee7, this);
7151
7310
  }));
7152
7311
 
7153
7312
  function seqFetch(_x5, _x6, _x7) {
@@ -7166,44 +7325,44 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7166
7325
  end = region.end,
7167
7326
  originalRefName = region.originalRefName;
7168
7327
 
7169
- var _ref5 = opts || {},
7170
- signal = _ref5.signal,
7171
- _ref5$statusCallback = _ref5.statusCallback,
7172
- statusCallback = _ref5$statusCallback === void 0 ? function () {} : _ref5$statusCallback;
7328
+ var _ref4 = opts || {},
7329
+ signal = _ref4.signal,
7330
+ _ref4$statusCallback = _ref4.statusCallback,
7331
+ statusCallback = _ref4$statusCallback === void 0 ? function () {} : _ref4$statusCallback;
7173
7332
 
7174
7333
  return rxjs.ObservableCreate( /*#__PURE__*/function () {
7175
- var _ref6 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(observer) {
7334
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(observer) {
7176
7335
  var _yield$_this2$configu, bam, records, _iterator, _step, record, ref;
7177
7336
 
7178
- return runtime_1.wrap(function _callee7$(_context7) {
7337
+ return runtime_1.wrap(function _callee8$(_context8) {
7179
7338
  while (1) {
7180
- switch (_context7.prev = _context7.next) {
7339
+ switch (_context8.prev = _context8.next) {
7181
7340
  case 0:
7182
- _context7.next = 2;
7341
+ _context8.next = 2;
7183
7342
  return _this2.configure();
7184
7343
 
7185
7344
  case 2:
7186
- _yield$_this2$configu = _context7.sent;
7345
+ _yield$_this2$configu = _context8.sent;
7187
7346
  bam = _yield$_this2$configu.bam;
7188
- _context7.next = 6;
7347
+ _context8.next = 6;
7189
7348
  return _this2.setup(opts);
7190
7349
 
7191
7350
  case 6:
7192
7351
  statusCallback('Downloading alignments');
7193
- _context7.next = 9;
7352
+ _context8.next = 9;
7194
7353
  return bam.getRecordsForRange(refName, start, end, opts);
7195
7354
 
7196
7355
  case 9:
7197
- records = _context7.sent;
7356
+ records = _context8.sent;
7198
7357
  util.checkAbortSignal(signal);
7199
7358
  _iterator = _createForOfIteratorHelper(records);
7200
- _context7.prev = 12;
7359
+ _context8.prev = 12;
7201
7360
 
7202
7361
  _iterator.s();
7203
7362
 
7204
7363
  case 14:
7205
7364
  if ((_step = _iterator.n()).done) {
7206
- _context7.next = 24;
7365
+ _context8.next = 24;
7207
7366
  break;
7208
7367
  }
7209
7368
 
@@ -7211,39 +7370,39 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7211
7370
  ref = void 0;
7212
7371
 
7213
7372
  if (record.get('md')) {
7214
- _context7.next = 21;
7373
+ _context8.next = 21;
7215
7374
  break;
7216
7375
  }
7217
7376
 
7218
- _context7.next = 20;
7377
+ _context8.next = 20;
7219
7378
  return _this2.seqFetch(originalRefName || refName, record.get('start'), record.get('end'));
7220
7379
 
7221
7380
  case 20:
7222
- ref = _context7.sent;
7381
+ ref = _context8.sent;
7223
7382
 
7224
7383
  case 21:
7225
7384
  observer.next(new BamSlightlyLazyFeature(record, _this2, ref));
7226
7385
 
7227
7386
  case 22:
7228
- _context7.next = 14;
7387
+ _context8.next = 14;
7229
7388
  break;
7230
7389
 
7231
7390
  case 24:
7232
- _context7.next = 29;
7391
+ _context8.next = 29;
7233
7392
  break;
7234
7393
 
7235
7394
  case 26:
7236
- _context7.prev = 26;
7237
- _context7.t0 = _context7["catch"](12);
7395
+ _context8.prev = 26;
7396
+ _context8.t0 = _context8["catch"](12);
7238
7397
 
7239
- _iterator.e(_context7.t0);
7398
+ _iterator.e(_context8.t0);
7240
7399
 
7241
7400
  case 29:
7242
- _context7.prev = 29;
7401
+ _context8.prev = 29;
7243
7402
 
7244
7403
  _iterator.f();
7245
7404
 
7246
- return _context7.finish(29);
7405
+ return _context8.finish(29);
7247
7406
 
7248
7407
  case 32:
7249
7408
  statusCallback('');
@@ -7251,17 +7410,69 @@ var BamAdapter = /*#__PURE__*/function (_BaseFeatureDataAdapt) {
7251
7410
 
7252
7411
  case 34:
7253
7412
  case "end":
7254
- return _context7.stop();
7413
+ return _context8.stop();
7255
7414
  }
7256
7415
  }
7257
- }, _callee7, null, [[12, 26, 29, 32]]);
7416
+ }, _callee8, null, [[12, 26, 29, 32]]);
7258
7417
  }));
7259
7418
 
7260
7419
  return function (_x8) {
7261
- return _ref6.apply(this, arguments);
7420
+ return _ref5.apply(this, arguments);
7262
7421
  };
7263
7422
  }(), signal);
7264
7423
  }
7424
+ }, {
7425
+ key: "estimateRegionsStats",
7426
+ value: function () {
7427
+ var _estimateRegionsStats = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(regions, opts) {
7428
+ var _yield$this$configure4, bam, index, bytes, fetchSizeLimit;
7429
+
7430
+ return runtime_1.wrap(function _callee9$(_context9) {
7431
+ while (1) {
7432
+ switch (_context9.prev = _context9.next) {
7433
+ case 0:
7434
+ _context9.next = 2;
7435
+ return this.configure();
7436
+
7437
+ case 2:
7438
+ _yield$this$configure4 = _context9.sent;
7439
+ bam = _yield$this$configure4.bam;
7440
+ // @ts-ignore
7441
+ index = bam.index; // this is a method to avoid calling on htsget adapters
7442
+
7443
+ if (!(index.filehandle !== '?')) {
7444
+ _context9.next = 13;
7445
+ break;
7446
+ }
7447
+
7448
+ _context9.next = 8;
7449
+ return util.bytesForRegions(regions, index);
7450
+
7451
+ case 8:
7452
+ bytes = _context9.sent;
7453
+ fetchSizeLimit = configuration.readConfObject(this.config, 'fetchSizeLimit');
7454
+ return _context9.abrupt("return", {
7455
+ bytes: bytes,
7456
+ fetchSizeLimit: fetchSizeLimit
7457
+ });
7458
+
7459
+ case 13:
7460
+ return _context9.abrupt("return", _get(_getPrototypeOf(BamAdapter.prototype), "estimateRegionsStats", this).call(this, regions, opts));
7461
+
7462
+ case 14:
7463
+ case "end":
7464
+ return _context9.stop();
7465
+ }
7466
+ }
7467
+ }, _callee9, this);
7468
+ }));
7469
+
7470
+ function estimateRegionsStats(_x9, _x10) {
7471
+ return _estimateRegionsStats.apply(this, arguments);
7472
+ }
7473
+
7474
+ return estimateRegionsStats;
7475
+ }()
7265
7476
  }, {
7266
7477
  key: "freeResources",
7267
7478
  value: function