@jbrowse/plugin-alignments 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js +61 -90
  2. package/dist/AlignmentsFeatureDetail/AlignmentsFeatureDetail.js.map +1 -1
  3. package/dist/AlignmentsFeatureDetail/index.js +14 -16
  4. package/dist/AlignmentsFeatureDetail/index.js.map +1 -1
  5. package/dist/AlignmentsTrack/index.js +8 -8
  6. package/dist/AlignmentsTrack/index.js.map +1 -1
  7. package/dist/BamAdapter/BamAdapter.js +157 -336
  8. package/dist/BamAdapter/BamAdapter.js.map +1 -1
  9. package/dist/BamAdapter/BamSlightlyLazyFeature.js +68 -103
  10. package/dist/BamAdapter/BamSlightlyLazyFeature.js.map +1 -1
  11. package/dist/BamAdapter/MismatchParser.js +96 -162
  12. package/dist/BamAdapter/MismatchParser.js.map +1 -1
  13. package/dist/BamAdapter/configSchema.js +27 -29
  14. package/dist/BamAdapter/configSchema.js.map +1 -1
  15. package/dist/BamAdapter/index.js +9 -11
  16. package/dist/BamAdapter/index.js.map +1 -1
  17. package/dist/CramAdapter/CramAdapter.js +193 -351
  18. package/dist/CramAdapter/CramAdapter.js.map +1 -1
  19. package/dist/CramAdapter/CramSlightlyLazyFeature.js +119 -154
  20. package/dist/CramAdapter/CramSlightlyLazyFeature.js.map +1 -1
  21. package/dist/CramAdapter/CramTestAdapters.js +51 -148
  22. package/dist/CramAdapter/CramTestAdapters.js.map +1 -1
  23. package/dist/CramAdapter/configSchema.js +23 -25
  24. package/dist/CramAdapter/configSchema.js.map +1 -1
  25. package/dist/CramAdapter/index.js +9 -11
  26. package/dist/CramAdapter/index.js.map +1 -1
  27. package/dist/HtsgetBamAdapter/HtsgetBamAdapter.js +25 -87
  28. package/dist/HtsgetBamAdapter/HtsgetBamAdapter.js.map +1 -1
  29. package/dist/HtsgetBamAdapter/configSchema.js +16 -18
  30. package/dist/HtsgetBamAdapter/configSchema.js.map +1 -1
  31. package/dist/HtsgetBamAdapter/index.js +15 -19
  32. package/dist/HtsgetBamAdapter/index.js.map +1 -1
  33. package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js +14 -15
  34. package/dist/LinearAlignmentsDisplay/components/AlignmentsDisplay.js.map +1 -1
  35. package/dist/LinearAlignmentsDisplay/index.js +7 -7
  36. package/dist/LinearAlignmentsDisplay/index.js.map +1 -1
  37. package/dist/LinearAlignmentsDisplay/models/configSchema.js +5 -5
  38. package/dist/LinearAlignmentsDisplay/models/configSchema.js.map +1 -1
  39. package/dist/LinearAlignmentsDisplay/models/model.js +64 -140
  40. package/dist/LinearAlignmentsDisplay/models/model.js.map +1 -1
  41. package/dist/LinearPileupDisplay/components/ColorByModifications.js +24 -53
  42. package/dist/LinearPileupDisplay/components/ColorByModifications.js.map +1 -1
  43. package/dist/LinearPileupDisplay/components/ColorByTag.js +14 -30
  44. package/dist/LinearPileupDisplay/components/ColorByTag.js.map +1 -1
  45. package/dist/LinearPileupDisplay/components/FilterByTag.js +33 -49
  46. package/dist/LinearPileupDisplay/components/FilterByTag.js.map +1 -1
  47. package/dist/LinearPileupDisplay/components/LinearPileupDisplayBlurb.js +7 -7
  48. package/dist/LinearPileupDisplay/components/LinearPileupDisplayBlurb.js.map +1 -1
  49. package/dist/LinearPileupDisplay/components/SetFeatureHeight.js +17 -33
  50. package/dist/LinearPileupDisplay/components/SetFeatureHeight.js.map +1 -1
  51. package/dist/LinearPileupDisplay/components/SetMaxHeight.js +14 -30
  52. package/dist/LinearPileupDisplay/components/SetMaxHeight.js.map +1 -1
  53. package/dist/LinearPileupDisplay/components/SortByTag.js +14 -30
  54. package/dist/LinearPileupDisplay/components/SortByTag.js.map +1 -1
  55. package/dist/LinearPileupDisplay/configSchema.js +4 -4
  56. package/dist/LinearPileupDisplay/configSchema.js.map +1 -1
  57. package/dist/LinearPileupDisplay/index.js +7 -7
  58. package/dist/LinearPileupDisplay/index.js.map +1 -1
  59. package/dist/LinearPileupDisplay/model.d.ts +2 -2
  60. package/dist/LinearPileupDisplay/model.js +534 -644
  61. package/dist/LinearPileupDisplay/model.js.map +1 -1
  62. package/dist/LinearSNPCoverageDisplay/components/Tooltip.d.ts +1 -1
  63. package/dist/LinearSNPCoverageDisplay/components/Tooltip.js +30 -78
  64. package/dist/LinearSNPCoverageDisplay/components/Tooltip.js.map +1 -1
  65. package/dist/LinearSNPCoverageDisplay/index.js +7 -7
  66. package/dist/LinearSNPCoverageDisplay/index.js.map +1 -1
  67. package/dist/LinearSNPCoverageDisplay/models/configSchema.js +4 -4
  68. package/dist/LinearSNPCoverageDisplay/models/configSchema.js.map +1 -1
  69. package/dist/LinearSNPCoverageDisplay/models/model.d.ts +1 -1
  70. package/dist/LinearSNPCoverageDisplay/models/model.js +170 -244
  71. package/dist/LinearSNPCoverageDisplay/models/model.js.map +1 -1
  72. package/dist/NestedFrequencyTable.js +27 -40
  73. package/dist/NestedFrequencyTable.js.map +1 -1
  74. package/dist/PileupRPC/rpcMethods.js +63 -191
  75. package/dist/PileupRPC/rpcMethods.js.map +1 -1
  76. package/dist/PileupRenderer/PileupLayoutSession.js +25 -47
  77. package/dist/PileupRenderer/PileupLayoutSession.js.map +1 -1
  78. package/dist/PileupRenderer/PileupRenderer.js +395 -529
  79. package/dist/PileupRenderer/PileupRenderer.js.map +1 -1
  80. package/dist/PileupRenderer/components/PileupRendering.js +41 -68
  81. package/dist/PileupRenderer/components/PileupRendering.js.map +1 -1
  82. package/dist/PileupRenderer/configSchema.js +2 -2
  83. package/dist/PileupRenderer/configSchema.js.map +1 -1
  84. package/dist/PileupRenderer/index.js +9 -11
  85. package/dist/PileupRenderer/index.js.map +1 -1
  86. package/dist/PileupRenderer/sortUtil.js +36 -40
  87. package/dist/PileupRenderer/sortUtil.js.map +1 -1
  88. package/dist/SNPCoverageAdapter/SNPCoverageAdapter.js +229 -415
  89. package/dist/SNPCoverageAdapter/SNPCoverageAdapter.js.map +1 -1
  90. package/dist/SNPCoverageAdapter/configSchema.js +5 -9
  91. package/dist/SNPCoverageAdapter/configSchema.js.map +1 -1
  92. package/dist/SNPCoverageAdapter/index.js +17 -21
  93. package/dist/SNPCoverageAdapter/index.js.map +1 -1
  94. package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js +175 -259
  95. package/dist/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
  96. package/dist/SNPCoverageRenderer/configSchema.js +1 -1
  97. package/dist/SNPCoverageRenderer/configSchema.js.map +1 -1
  98. package/dist/SNPCoverageRenderer/index.js +10 -12
  99. package/dist/SNPCoverageRenderer/index.js.map +1 -1
  100. package/dist/index.js +40 -58
  101. package/dist/index.js.map +1 -1
  102. package/dist/shared.js +23 -78
  103. package/dist/shared.js.map +1 -1
  104. package/dist/util.js +13 -66
  105. package/dist/util.js.map +1 -1
  106. package/esm/LinearPileupDisplay/model.d.ts +2 -2
  107. package/esm/LinearSNPCoverageDisplay/models/model.d.ts +1 -1
  108. package/esm/PileupRenderer/PileupRenderer.js +0 -2
  109. package/esm/PileupRenderer/PileupRenderer.js.map +1 -1
  110. package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js +0 -1
  111. package/esm/SNPCoverageRenderer/SNPCoverageRenderer.js.map +1 -1
  112. package/package.json +2 -3
  113. package/src/AlignmentsFeatureDetail/__snapshots__/index.test.js.snap +12 -12
  114. package/src/PileupRenderer/PileupRenderer.tsx +0 -2
  115. package/src/SNPCoverageRenderer/SNPCoverageRenderer.ts +0 -1
@@ -1,30 +1,4 @@
1
1
  "use strict";
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
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
3
  if (k2 === undefined) k2 = k;
30
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -48,84 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
48
22
  __setModuleDefault(result, mod);
49
23
  return result;
50
24
  };
51
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
- return new (P || (P = Promise))(function (resolve, reject) {
54
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
- step((generator = generator.apply(thisArg, _arguments || [])).next());
58
- });
59
- };
60
- var __generator = (this && this.__generator) || function (thisArg, body) {
61
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (_) try {
67
- 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;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- };
87
- var __read = (this && this.__read) || function (o, n) {
88
- var m = typeof Symbol === "function" && o[Symbol.iterator];
89
- if (!m) return o;
90
- var i = m.call(o), r, ar = [], e;
91
- try {
92
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
93
- }
94
- catch (error) { e = { error: error }; }
95
- finally {
96
- try {
97
- if (r && !r.done && (m = i["return"])) m.call(i);
98
- }
99
- finally { if (e) throw e.error; }
100
- }
101
- return ar;
102
- };
103
- var __values = (this && this.__values) || function(o) {
104
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
105
- if (m) return m.call(o);
106
- if (o && typeof o.length === "number") return {
107
- next: function () {
108
- if (o && i >= o.length) o = void 0;
109
- return { value: o && o[i++], done: !o };
110
- }
111
- };
112
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
113
- };
114
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
115
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
116
27
  };
117
28
  Object.defineProperty(exports, "__esModule", { value: true });
118
- var BoxRendererType_1 = __importDefault(require("@jbrowse/core/pluggableElementTypes/renderers/BoxRendererType"));
119
- var ui_1 = require("@jbrowse/core/ui");
120
- var util_1 = require("@jbrowse/core/util");
121
- var offscreenCanvasUtils_1 = require("@jbrowse/core/util/offscreenCanvasUtils");
122
- var dataAdapterCache_1 = require("@jbrowse/core/data_adapters/dataAdapterCache");
123
- var configuration_1 = require("@jbrowse/core/configuration");
29
+ const BoxRendererType_1 = __importDefault(require("@jbrowse/core/pluggableElementTypes/renderers/BoxRendererType"));
30
+ const ui_1 = require("@jbrowse/core/ui");
31
+ const util_1 = require("@jbrowse/core/util");
32
+ const offscreenCanvasUtils_1 = require("@jbrowse/core/util/offscreenCanvasUtils");
33
+ const dataAdapterCache_1 = require("@jbrowse/core/data_adapters/dataAdapterCache");
34
+ const configuration_1 = require("@jbrowse/core/configuration");
124
35
  // locals
125
- var MismatchParser_1 = require("../BamAdapter/MismatchParser");
126
- var sortUtil_1 = require("./sortUtil");
127
- var util_2 = require("../util");
128
- var PileupLayoutSession_1 = require("./PileupLayoutSession");
36
+ const MismatchParser_1 = require("../BamAdapter/MismatchParser");
37
+ const sortUtil_1 = require("./sortUtil");
38
+ const util_2 = require("../util");
39
+ const PileupLayoutSession_1 = require("./PileupLayoutSession");
129
40
  function fillRect(ctx, l, t, w, h, cw, color) {
130
41
  if (l + w < 0 || l > cw) {
131
42
  return;
@@ -138,8 +49,7 @@ function fillRect(ctx, l, t, w, h, cw, color) {
138
49
  }
139
50
  }
140
51
  function getColorBaseMap(theme) {
141
- // @ts-ignore
142
- var bases = theme.palette.bases;
52
+ const { bases } = theme.palette;
143
53
  return {
144
54
  A: bases.A.main,
145
55
  C: bases.C.main,
@@ -149,15 +59,12 @@ function getColorBaseMap(theme) {
149
59
  };
150
60
  }
151
61
  function getContrastBaseMap(theme) {
152
- return Object.fromEntries(Object.entries(getColorBaseMap(theme)).map(function (_a) {
153
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
154
- return [
155
- key,
156
- theme.palette.getContrastText(value),
157
- ];
158
- }));
62
+ return Object.fromEntries(Object.entries(getColorBaseMap(theme)).map(([key, value]) => [
63
+ key,
64
+ theme.palette.getContrastText(value),
65
+ ]));
159
66
  }
160
- var alignmentColoring = {
67
+ const alignmentColoring = {
161
68
  color_fwd_strand_not_proper: '#ECC8C8',
162
69
  color_rev_strand_not_proper: '#BEBED8',
163
70
  color_fwd_strand: '#EC8B8B',
@@ -181,31 +88,28 @@ function shouldDrawSNPsMuted(type) {
181
88
  function shouldDrawIndels(type) {
182
89
  return true;
183
90
  }
184
- var PileupRenderer = /** @class */ (function (_super) {
185
- __extends(PileupRenderer, _super);
186
- function PileupRenderer() {
187
- var _this = _super !== null && _super.apply(this, arguments) || this;
188
- _this.supportsSVG = true;
189
- return _this;
91
+ class PileupRenderer extends BoxRendererType_1.default {
92
+ constructor() {
93
+ super(...arguments);
94
+ this.supportsSVG = true;
190
95
  }
191
96
  // get width and height of chars the height is an approximation: width
192
97
  // letter M is approximately the height
193
- PileupRenderer.prototype.getCharWidthHeight = function (ctx) {
194
- var charWidth = (0, util_1.measureText)('A');
195
- var charHeight = (0, util_1.measureText)('M') - 2;
196
- return { charWidth: charWidth, charHeight: charHeight };
197
- };
198
- PileupRenderer.prototype.layoutFeature = function (_a) {
199
- var feature = _a.feature, layout = _a.layout, bpPerPx = _a.bpPerPx, region = _a.region, showSoftClip = _a.showSoftClip, heightPx = _a.heightPx, displayMode = _a.displayMode;
200
- var expansionBefore = 0;
201
- var expansionAfter = 0;
98
+ getCharWidthHeight(ctx) {
99
+ const charWidth = (0, util_1.measureText)('A');
100
+ const charHeight = (0, util_1.measureText)('M') - 2;
101
+ return { charWidth, charHeight };
102
+ }
103
+ layoutFeature({ feature, layout, bpPerPx, region, showSoftClip, heightPx, displayMode, }) {
104
+ let expansionBefore = 0;
105
+ let expansionAfter = 0;
202
106
  // Expand the start and end of feature when softclipping enabled
203
107
  if (showSoftClip) {
204
- var mismatches = feature.get('mismatches');
205
- var seq = feature.get('seq');
108
+ const mismatches = feature.get('mismatches');
109
+ const seq = feature.get('seq');
206
110
  if (seq) {
207
- for (var i = 0; i < mismatches.length; i += 1) {
208
- var _b = mismatches[i], type = _b.type, start = _b.start, _c = _b.cliplen, cliplen = _c === void 0 ? 0 : _c;
111
+ for (let i = 0; i < mismatches.length; i += 1) {
112
+ const { type, start, cliplen = 0 } = mismatches[i];
209
113
  if (type === 'softclip') {
210
114
  start === 0
211
115
  ? (expansionBefore = cliplen)
@@ -214,64 +118,69 @@ var PileupRenderer = /** @class */ (function (_super) {
214
118
  }
215
119
  }
216
120
  }
217
- var _d = __read((0, util_1.bpSpanPx)(feature.get('start') - expansionBefore, feature.get('end') + expansionAfter, region, bpPerPx), 2), leftPx = _d[0], rightPx = _d[1];
121
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(feature.get('start') - expansionBefore, feature.get('end') + expansionAfter, region, bpPerPx);
218
122
  if (displayMode === 'compact') {
219
123
  heightPx /= 3;
220
124
  }
221
125
  if (feature.get('refName') !== region.refName) {
222
- throw new Error("feature ".concat(feature.id(), " is not on the current region's reference sequence ").concat(region.refName));
126
+ throw new Error(`feature ${feature.id()} is not on the current region's reference sequence ${region.refName}`);
223
127
  }
224
- var topPx = layout.addRect(feature.id(), feature.get('start') - expansionBefore, feature.get('end') + expansionAfter, heightPx, feature);
128
+ const topPx = layout.addRect(feature.id(), feature.get('start') - expansionBefore, feature.get('end') + expansionAfter, heightPx, feature);
225
129
  if (topPx === null) {
226
130
  return null;
227
131
  }
228
132
  return {
229
- feature: feature,
230
- leftPx: leftPx,
231
- rightPx: rightPx,
133
+ feature,
134
+ leftPx,
135
+ rightPx,
232
136
  topPx: displayMode === 'collapse' ? 0 : topPx,
233
- heightPx: heightPx,
137
+ heightPx,
234
138
  };
235
- };
139
+ }
236
140
  // expands region for clipping to use. possible improvement: use average read
237
141
  // size to set the heuristic maxClippingSize expansion (e.g. short reads
238
142
  // don't have to expand a softclipping size a lot, but long reads might)
239
- PileupRenderer.prototype.getExpandedRegion = function (region, renderArgs) {
240
- var config = renderArgs.config, showSoftClip = renderArgs.showSoftClip;
241
- var maxClippingSize = (0, configuration_1.readConfObject)(config, 'maxClippingSize');
242
- var start = region.start, end = region.end;
243
- var len = end - start;
244
- var bpExpansion = Math.max(len, showSoftClip ? Math.round(maxClippingSize) : 0);
245
- return __assign(__assign({}, region), { start: Math.floor(Math.max(start - bpExpansion, 0)), end: Math.ceil(end + bpExpansion) });
246
- };
247
- PileupRenderer.prototype.colorByOrientation = function (feature, config) {
143
+ getExpandedRegion(region, renderArgs) {
144
+ const { config, showSoftClip } = renderArgs;
145
+ const maxClippingSize = (0, configuration_1.readConfObject)(config, 'maxClippingSize');
146
+ const { start, end } = region;
147
+ const len = end - start;
148
+ const bpExpansion = Math.max(len, showSoftClip ? Math.round(maxClippingSize) : 0);
149
+ return {
150
+ // xref https://github.com/mobxjs/mobx-state-tree/issues/1524 for Omit
151
+ ...region,
152
+ start: Math.floor(Math.max(start - bpExpansion, 0)),
153
+ end: Math.ceil(end + bpExpansion),
154
+ };
155
+ }
156
+ colorByOrientation(feature, config) {
248
157
  return alignmentColoring[this.getOrientation(feature, config) || 'color_nostrand'];
249
- };
250
- PileupRenderer.prototype.getOrientation = function (feature, config) {
251
- var orientationType = (0, configuration_1.readConfObject)(config, 'orientationType');
252
- var type = util_2.orientationTypes[orientationType];
253
- var orientation = type[feature.get('pair_orientation')];
254
- var map = {
158
+ }
159
+ getOrientation(feature, config) {
160
+ const orientationType = (0, configuration_1.readConfObject)(config, 'orientationType');
161
+ const type = util_2.orientationTypes[orientationType];
162
+ const orientation = type[feature.get('pair_orientation')];
163
+ const map = {
255
164
  LR: 'color_pair_lr',
256
165
  RR: 'color_pair_rr',
257
166
  RL: 'color_pair_rl',
258
167
  LL: 'color_pair_ll',
259
168
  };
260
169
  return map[orientation];
261
- };
262
- PileupRenderer.prototype.colorByInsertSize = function (feature, _config) {
170
+ }
171
+ colorByInsertSize(feature, _config) {
263
172
  return feature.get('is_paired') &&
264
173
  feature.get('seq_id') !== feature.get('next_seq_id')
265
174
  ? '#555'
266
- : "hsl(".concat(Math.abs(feature.get('template_length')) / 10, ",50%,50%)");
267
- };
268
- PileupRenderer.prototype.colorByStranded = function (feature, _config) {
269
- var flags = feature.get('flags');
270
- var strand = feature.get('strand');
175
+ : `hsl(${Math.abs(feature.get('template_length')) / 10},50%,50%)`;
176
+ }
177
+ colorByStranded(feature, _config) {
178
+ const flags = feature.get('flags');
179
+ const strand = feature.get('strand');
271
180
  // is paired
272
181
  if (flags & 1) {
273
- var revflag = flags & 64;
274
- var flipper = revflag ? -1 : 1;
182
+ const revflag = flags & 64;
183
+ const flipper = revflag ? -1 : 1;
275
184
  // proper pairing
276
185
  if (flags & 2) {
277
186
  return strand * flipper === 1 ? 'color_rev_strand' : 'color_fwd_strand';
@@ -290,20 +199,19 @@ var PileupRenderer = /** @class */ (function (_super) {
290
199
  return strand === 1 ? 'color_fwd_diff_chr' : 'color_rev_diff_chr';
291
200
  }
292
201
  return strand === 1 ? 'color_fwd_strand' : 'color_rev_strand';
293
- };
294
- PileupRenderer.prototype.colorByPerBaseLettering = function (_a) {
295
- var ctx = _a.ctx, feat = _a.feat, region = _a.region, bpPerPx = _a.bpPerPx, colorForBase = _a.colorForBase, contrastForBase = _a.contrastForBase, charWidth = _a.charWidth, charHeight = _a.charHeight, canvasWidth = _a.canvasWidth;
296
- var heightLim = charHeight - 2;
297
- var feature = feat.feature, topPx = feat.topPx, heightPx = feat.heightPx;
298
- var seq = feature.get('seq');
299
- var cigarOps = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
300
- var w = 1 / bpPerPx;
301
- var start = feature.get('start');
302
- var soffset = 0; // sequence offset
303
- var roffset = 0; // reference offset
304
- for (var i = 0; i < cigarOps.length; i += 2) {
305
- var len = +cigarOps[i];
306
- var op = cigarOps[i + 1];
202
+ }
203
+ colorByPerBaseLettering({ ctx, feat, region, bpPerPx, colorForBase, contrastForBase, charWidth, charHeight, canvasWidth, }) {
204
+ const heightLim = charHeight - 2;
205
+ const { feature, topPx, heightPx } = feat;
206
+ const seq = feature.get('seq');
207
+ const cigarOps = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
208
+ const w = 1 / bpPerPx;
209
+ const start = feature.get('start');
210
+ let soffset = 0; // sequence offset
211
+ let roffset = 0; // reference offset
212
+ for (let i = 0; i < cigarOps.length; i += 2) {
213
+ const len = +cigarOps[i];
214
+ const op = cigarOps[i + 1];
307
215
  if (op === 'S' || op === 'I') {
308
216
  soffset += len;
309
217
  }
@@ -311,10 +219,10 @@ var PileupRenderer = /** @class */ (function (_super) {
311
219
  roffset += len;
312
220
  }
313
221
  else if (op === 'M' || op === 'X' || op === '=') {
314
- for (var m = 0; m < len; m++) {
315
- var letter = seq[soffset + m];
316
- var r = start + roffset + m;
317
- var _b = __read((0, util_1.bpSpanPx)(r, r + 1, region, bpPerPx), 1), leftPx = _b[0];
222
+ for (let m = 0; m < len; m++) {
223
+ const letter = seq[soffset + m];
224
+ const r = start + roffset + m;
225
+ const [leftPx] = (0, util_1.bpSpanPx)(r, r + 1, region, bpPerPx);
318
226
  fillRect(ctx, leftPx, topPx, w + 0.5, heightPx, canvasWidth, colorForBase[letter]);
319
227
  if (w >= charWidth && heightPx >= heightLim) {
320
228
  // normal SNP coloring
@@ -326,20 +234,19 @@ var PileupRenderer = /** @class */ (function (_super) {
326
234
  roffset += len;
327
235
  }
328
236
  }
329
- };
330
- PileupRenderer.prototype.colorByPerBaseQuality = function (_a) {
331
- var ctx = _a.ctx, feat = _a.feat, region = _a.region, bpPerPx = _a.bpPerPx, canvasWidth = _a.canvasWidth;
332
- var feature = feat.feature, topPx = feat.topPx, heightPx = feat.heightPx;
333
- var qual = feature.get('qual') || '';
334
- var scores = qual.split(' ').map(function (val) { return +val; });
335
- var cigarOps = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
336
- var width = 1 / bpPerPx;
337
- var start = feature.get('start');
338
- var soffset = 0; // sequence offset
339
- var roffset = 0; // reference offset
340
- for (var i = 0; i < cigarOps.length; i += 2) {
341
- var len = +cigarOps[i];
342
- var op = cigarOps[i + 1];
237
+ }
238
+ colorByPerBaseQuality({ ctx, feat, region, bpPerPx, canvasWidth, }) {
239
+ const { feature, topPx, heightPx } = feat;
240
+ const qual = feature.get('qual') || '';
241
+ const scores = qual.split(' ').map(val => +val);
242
+ const cigarOps = (0, MismatchParser_1.parseCigar)(feature.get('CIGAR'));
243
+ const width = 1 / bpPerPx;
244
+ const start = feature.get('start');
245
+ let soffset = 0; // sequence offset
246
+ let roffset = 0; // reference offset
247
+ for (let i = 0; i < cigarOps.length; i += 2) {
248
+ const len = +cigarOps[i];
249
+ const op = cigarOps[i + 1];
343
250
  if (op === 'S' || op === 'I') {
344
251
  soffset += len;
345
252
  }
@@ -347,16 +254,16 @@ var PileupRenderer = /** @class */ (function (_super) {
347
254
  roffset += len;
348
255
  }
349
256
  else if (op === 'M' || op === 'X' || op === '=') {
350
- for (var m = 0; m < len; m++) {
351
- var score = scores[soffset + m];
352
- var _b = __read((0, util_1.bpSpanPx)(start + roffset + m, start + roffset + m + 1, region, bpPerPx), 1), leftPx = _b[0];
353
- fillRect(ctx, leftPx, topPx, width + 0.5, heightPx, canvasWidth, "hsl(".concat(score === 255 ? 150 : score * 1.5, ",55%,50%)"));
257
+ for (let m = 0; m < len; m++) {
258
+ const score = scores[soffset + m];
259
+ const [leftPx] = (0, util_1.bpSpanPx)(start + roffset + m, start + roffset + m + 1, region, bpPerPx);
260
+ fillRect(ctx, leftPx, topPx, width + 0.5, heightPx, canvasWidth, `hsl(${score === 255 ? 150 : score * 1.5},55%,50%)`);
354
261
  }
355
262
  soffset += len;
356
263
  roffset += len;
357
264
  }
358
265
  }
359
- };
266
+ }
360
267
  // ML stores probabilities as array of numerics and MP is scaled phred scores
361
268
  // https://github.com/samtools/hts-specs/pull/418/files#diff-e765c6479316309f56b636f88189cdde8c40b854c7bdcce9ee7fe87a4e76febcR596
362
269
  //
@@ -366,109 +273,85 @@ var PileupRenderer = /** @class */ (function (_super) {
366
273
  // has very high likelihood basecalls at that point, we really only care
367
274
  // about low qual calls <20 approx
368
275
  //
369
- PileupRenderer.prototype.colorByModifications = function (_a) {
370
- var e_1, _b;
371
- var ctx = _a.ctx, feat = _a.feat, region = _a.region, bpPerPx = _a.bpPerPx, renderArgs = _a.renderArgs, canvasWidth = _a.canvasWidth;
372
- var feature = feat.feature, topPx = feat.topPx, heightPx = feat.heightPx;
373
- var Color = renderArgs.Color, _c = renderArgs.modificationTagMap, modificationTagMap = _c === void 0 ? {} : _c;
374
- var mm = (0, util_2.getTagAlt)(feature, 'MM', 'Mm') || '';
375
- var ml = (0, util_2.getTagAlt)(feature, 'ML', 'Ml') || [];
376
- var probabilities = ml
377
- ? (typeof ml === 'string' ? ml.split(',').map(function (e) { return +e; }) : ml).map(function (e) { return e / 255; })
276
+ colorByModifications({ ctx, feat, region, bpPerPx, renderArgs, canvasWidth, }) {
277
+ const { feature, topPx, heightPx } = feat;
278
+ const { Color, modificationTagMap = {} } = renderArgs;
279
+ const mm = (0, util_2.getTagAlt)(feature, 'MM', 'Mm') || '';
280
+ const ml = (0, util_2.getTagAlt)(feature, 'ML', 'Ml') || [];
281
+ const probabilities = ml
282
+ ? (typeof ml === 'string' ? ml.split(',').map(e => +e) : ml).map(e => e / 255)
378
283
  : (0, util_2.getTagAlt)(feature, 'MP', 'Mp')
379
284
  .split('')
380
- .map(function (s) { return s.charCodeAt(0) - 33; })
381
- .map(function (elt) { return Math.min(1, elt / 50); });
382
- var cigar = feature.get('CIGAR');
383
- var start = feature.get('start');
384
- var seq = feature.get('seq');
385
- var strand = feature.get('strand');
386
- var cigarOps = (0, MismatchParser_1.parseCigar)(cigar);
387
- var modifications = (0, MismatchParser_1.getModificationPositions)(mm, seq, strand);
285
+ .map(s => s.charCodeAt(0) - 33)
286
+ .map(elt => Math.min(1, elt / 50));
287
+ const cigar = feature.get('CIGAR');
288
+ const start = feature.get('start');
289
+ const seq = feature.get('seq');
290
+ const strand = feature.get('strand');
291
+ const cigarOps = (0, MismatchParser_1.parseCigar)(cigar);
292
+ const modifications = (0, MismatchParser_1.getModificationPositions)(mm, seq, strand);
388
293
  // probIndex applies across multiple modifications e.g.
389
- var probIndex = 0;
390
- for (var i = 0; i < modifications.length; i++) {
391
- var _d = modifications[i], type = _d.type, positions = _d.positions;
392
- var col = modificationTagMap[type] || 'black';
294
+ let probIndex = 0;
295
+ for (let i = 0; i < modifications.length; i++) {
296
+ const { type, positions } = modifications[i];
297
+ const col = modificationTagMap[type] || 'black';
393
298
  // @ts-ignore
394
- var base = Color(col);
395
- try {
396
- for (var _e = (e_1 = void 0, __values((0, MismatchParser_1.getNextRefPos)(cigarOps, positions))), _f = _e.next(); !_f.done; _f = _e.next()) {
397
- var readPos = _f.value;
398
- var r = start + readPos;
399
- var _g = __read((0, util_1.bpSpanPx)(r, r + 1, region, bpPerPx), 2), leftPx = _g[0], rightPx = _g[1];
400
- // give it a little boost of 0.1 to not make them fully
401
- // invisible to avoid confusion
402
- var prob = probabilities[probIndex];
403
- fillRect(ctx, leftPx, topPx, rightPx - leftPx + 0.5, heightPx, canvasWidth, prob && prob !== 1
404
- ? base
405
- .alpha(prob + 0.1)
406
- .hsl()
407
- .string()
408
- : col);
409
- probIndex++;
410
- }
411
- }
412
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
413
- finally {
414
- try {
415
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
416
- }
417
- finally { if (e_1) throw e_1.error; }
299
+ const base = Color(col);
300
+ for (const readPos of (0, MismatchParser_1.getNextRefPos)(cigarOps, positions)) {
301
+ const r = start + readPos;
302
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(r, r + 1, region, bpPerPx);
303
+ // give it a little boost of 0.1 to not make them fully
304
+ // invisible to avoid confusion
305
+ const prob = probabilities[probIndex];
306
+ fillRect(ctx, leftPx, topPx, rightPx - leftPx + 0.5, heightPx, canvasWidth, prob && prob !== 1
307
+ ? base
308
+ .alpha(prob + 0.1)
309
+ .hsl()
310
+ .string()
311
+ : col);
312
+ probIndex++;
418
313
  }
419
314
  }
420
- };
315
+ }
421
316
  // Color by methylation is slightly modified version of color by
422
317
  // modifications that focuses on CpG sites, with non-methylated CpG colored
423
318
  // blue
424
- PileupRenderer.prototype.colorByMethylation = function (_a) {
425
- var e_2, _b;
426
- var ctx = _a.ctx, feat = _a.feat, region = _a.region, bpPerPx = _a.bpPerPx, renderArgs = _a.renderArgs, canvasWidth = _a.canvasWidth;
427
- var regionSequence = renderArgs.regionSequence;
428
- var feature = feat.feature, topPx = feat.topPx, heightPx = feat.heightPx;
429
- var mm = (0, util_2.getTagAlt)(feature, 'MM', 'Mm') || '';
319
+ colorByMethylation({ ctx, feat, region, bpPerPx, renderArgs, canvasWidth, }) {
320
+ const { regionSequence } = renderArgs;
321
+ const { feature, topPx, heightPx } = feat;
322
+ const mm = (0, util_2.getTagAlt)(feature, 'MM', 'Mm') || '';
430
323
  if (!regionSequence) {
431
324
  throw new Error('region sequence required for methylation');
432
325
  }
433
- var cigar = feature.get('CIGAR');
434
- var fstart = feature.get('start');
435
- var fend = feature.get('end');
436
- var seq = feature.get('seq');
437
- var strand = feature.get('strand');
438
- var cigarOps = (0, MismatchParser_1.parseCigar)(cigar);
439
- var methBins = new Array(region.end - region.start).fill(0);
440
- var modifications = (0, MismatchParser_1.getModificationPositions)(mm, seq, strand);
441
- for (var i = 0; i < modifications.length; i++) {
442
- var _c = modifications[i], type = _c.type, positions = _c.positions;
326
+ const cigar = feature.get('CIGAR');
327
+ const fstart = feature.get('start');
328
+ const fend = feature.get('end');
329
+ const seq = feature.get('seq');
330
+ const strand = feature.get('strand');
331
+ const cigarOps = (0, MismatchParser_1.parseCigar)(cigar);
332
+ const methBins = new Array(region.end - region.start).fill(0);
333
+ const modifications = (0, MismatchParser_1.getModificationPositions)(mm, seq, strand);
334
+ for (let i = 0; i < modifications.length; i++) {
335
+ const { type, positions } = modifications[i];
443
336
  if (type === 'm' && positions) {
444
- try {
445
- for (var _d = (e_2 = void 0, __values((0, MismatchParser_1.getNextRefPos)(cigarOps, positions))), _e = _d.next(); !_e.done; _e = _d.next()) {
446
- var pos = _e.value;
447
- var epos = pos + fstart - region.start;
448
- if (epos >= 0 && epos < methBins.length) {
449
- methBins[epos] = 1;
450
- }
451
- }
452
- }
453
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
454
- finally {
455
- try {
456
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
337
+ for (const pos of (0, MismatchParser_1.getNextRefPos)(cigarOps, positions)) {
338
+ const epos = pos + fstart - region.start;
339
+ if (epos >= 0 && epos < methBins.length) {
340
+ methBins[epos] = 1;
457
341
  }
458
- finally { if (e_2) throw e_2.error; }
459
342
  }
460
343
  }
461
344
  }
462
- for (var j = fstart; j < fend; j++) {
463
- var i = j - region.start;
345
+ for (let j = fstart; j < fend; j++) {
346
+ const i = j - region.start;
464
347
  if (i >= 0 && i < methBins.length) {
465
- var l1 = regionSequence[i].toLowerCase();
466
- var l2 = regionSequence[i + 1].toLowerCase();
348
+ const l1 = regionSequence[i].toLowerCase();
349
+ const l2 = regionSequence[i + 1].toLowerCase();
467
350
  // if we are zoomed out, display just a block over the cpg
468
351
  if (bpPerPx > 2) {
469
352
  if (l1 === 'c' && l2 === 'g') {
470
- var s = region.start + i;
471
- var _f = __read((0, util_1.bpSpanPx)(s, s + 2, region, bpPerPx), 2), leftPx = _f[0], rightPx = _f[1];
353
+ const s = region.start + i;
354
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(s, s + 2, region, bpPerPx);
472
355
  fillRect(ctx, leftPx, topPx, rightPx - leftPx + 0.5, heightPx, canvasWidth, methBins[i] || methBins[i + 1] ? 'red' : 'blue');
473
356
  }
474
357
  }
@@ -476,23 +359,23 @@ var PileupRenderer = /** @class */ (function (_super) {
476
359
  else {
477
360
  // color
478
361
  if (l1 === 'c' && l2 === 'g') {
479
- var s = region.start + i;
480
- var _g = __read((0, util_1.bpSpanPx)(s, s + 1, region, bpPerPx), 2), leftPx = _g[0], rightPx = _g[1];
362
+ const s = region.start + i;
363
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(s, s + 1, region, bpPerPx);
481
364
  fillRect(ctx, leftPx, topPx, rightPx - leftPx + 0.5, heightPx, canvasWidth, methBins[i] ? 'red' : 'blue');
482
- var _h = __read((0, util_1.bpSpanPx)(s + 1, s + 2, region, bpPerPx), 2), leftPx2 = _h[0], rightPx2 = _h[1];
365
+ const [leftPx2, rightPx2] = (0, util_1.bpSpanPx)(s + 1, s + 2, region, bpPerPx);
483
366
  fillRect(ctx, leftPx2, topPx, rightPx2 - leftPx2 + 0.5, heightPx, canvasWidth, methBins[i + 1] ? 'red' : 'blue');
484
367
  }
485
368
  }
486
369
  }
487
370
  }
488
- };
489
- PileupRenderer.prototype.drawRect = function (ctx, feat, props) {
490
- var regions = props.regions, bpPerPx = props.bpPerPx;
491
- var heightPx = feat.heightPx, topPx = feat.topPx, feature = feat.feature;
492
- var _a = __read(regions, 1), region = _a[0];
493
- var _b = __read((0, util_1.bpSpanPx)(feature.get('start'), feature.get('end'), region, bpPerPx), 2), leftPx = _b[0], rightPx = _b[1];
494
- var flip = region.reversed ? -1 : 1;
495
- var strand = feature.get('strand') * flip;
371
+ }
372
+ drawRect(ctx, feat, props) {
373
+ const { regions, bpPerPx } = props;
374
+ const { heightPx, topPx, feature } = feat;
375
+ const [region] = regions;
376
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(feature.get('start'), feature.get('end'), region, bpPerPx);
377
+ const flip = region.reversed ? -1 : 1;
378
+ const strand = feature.get('strand') * flip;
496
379
  if (bpPerPx < 10) {
497
380
  if (strand === -1) {
498
381
  ctx.beginPath();
@@ -518,13 +401,12 @@ var PileupRenderer = /** @class */ (function (_super) {
518
401
  else {
519
402
  ctx.fillRect(leftPx, topPx, rightPx - leftPx, heightPx);
520
403
  }
521
- };
522
- PileupRenderer.prototype.drawAlignmentRect = function (_a) {
523
- var ctx = _a.ctx, feat = _a.feat, renderArgs = _a.renderArgs, colorForBase = _a.colorForBase, contrastForBase = _a.contrastForBase, charWidth = _a.charWidth, charHeight = _a.charHeight, defaultColor = _a.defaultColor, canvasWidth = _a.canvasWidth;
524
- var config = renderArgs.config, bpPerPx = renderArgs.bpPerPx, regions = renderArgs.regions, colorBy = renderArgs.colorBy, _b = renderArgs.colorTagMap, colorTagMap = _b === void 0 ? {} : _b;
525
- var _c = colorBy || {}, _d = _c.tag, tag = _d === void 0 ? '' : _d, _e = _c.type, colorType = _e === void 0 ? '' : _e;
526
- var feature = feat.feature;
527
- var region = regions[0];
404
+ }
405
+ drawAlignmentRect({ ctx, feat, renderArgs, colorForBase, contrastForBase, charWidth, charHeight, defaultColor, canvasWidth, }) {
406
+ const { config, bpPerPx, regions, colorBy, colorTagMap = {} } = renderArgs;
407
+ const { tag = '', type: colorType = '' } = colorBy || {};
408
+ const { feature } = feat;
409
+ const region = regions[0];
528
410
  // first pass for simple color changes that change the color of the
529
411
  // alignment
530
412
  switch (colorType) {
@@ -535,7 +417,7 @@ var PileupRenderer = /** @class */ (function (_super) {
535
417
  ctx.fillStyle = feature.get('strand') === -1 ? '#8F8FD8' : '#EC8B8B';
536
418
  break;
537
419
  case 'mappingQuality':
538
- ctx.fillStyle = "hsl(".concat(feature.get('mq'), ",50%,50%)");
420
+ ctx.fillStyle = `hsl(${feature.get('mq')},50%,50%)`;
539
421
  break;
540
422
  case 'pairOrientation':
541
423
  ctx.fillStyle = this.colorByOrientation(feature, config);
@@ -545,11 +427,11 @@ var PileupRenderer = /** @class */ (function (_super) {
545
427
  break;
546
428
  case 'xs':
547
429
  case 'tag': {
548
- var tags = feature.get('tags');
549
- var val = tags ? tags[tag] : feature.get(tag);
430
+ const tags = feature.get('tags');
431
+ const val = tags ? tags[tag] : feature.get(tag);
550
432
  // special for for XS/TS tag
551
433
  if (tag === 'XS' || tag === 'TS') {
552
- var map = {
434
+ const map = {
553
435
  '-': 'color_rev_strand',
554
436
  '+': 'color_fwd_strand',
555
437
  };
@@ -557,7 +439,7 @@ var PileupRenderer = /** @class */ (function (_super) {
557
439
  }
558
440
  // lower case 'ts' from minimap2 is flipped from xs
559
441
  if (tag === 'ts') {
560
- var map = {
442
+ const map = {
561
443
  '-': feature.get('strand') === -1
562
444
  ? 'color_fwd_strand'
563
445
  : 'color_rev_strand',
@@ -570,7 +452,7 @@ var PileupRenderer = /** @class */ (function (_super) {
570
452
  // tag is not one of the autofilled tags, has color-value pairs from
571
453
  // fetchValues
572
454
  else {
573
- var foundValue = colorTagMap[val];
455
+ const foundValue = colorTagMap[val];
574
456
  ctx.fillStyle = foundValue || alignmentColoring['color_nostrand'];
575
457
  }
576
458
  break;
@@ -596,7 +478,7 @@ var PileupRenderer = /** @class */ (function (_super) {
596
478
  ctx.fillStyle = '#c8c8c8';
597
479
  }
598
480
  else {
599
- ctx.fillStyle = (0, configuration_1.readConfObject)(config, 'color', { feature: feature });
481
+ ctx.fillStyle = (0, configuration_1.readConfObject)(config, 'color', { feature });
600
482
  }
601
483
  break;
602
484
  }
@@ -606,75 +488,74 @@ var PileupRenderer = /** @class */ (function (_super) {
606
488
  switch (colorType) {
607
489
  case 'perBaseQuality':
608
490
  this.colorByPerBaseQuality({
609
- ctx: ctx,
610
- feat: feat,
611
- region: region,
612
- bpPerPx: bpPerPx,
613
- canvasWidth: canvasWidth,
491
+ ctx,
492
+ feat,
493
+ region,
494
+ bpPerPx,
495
+ canvasWidth,
614
496
  });
615
497
  break;
616
498
  case 'perBaseLettering':
617
499
  this.colorByPerBaseLettering({
618
- ctx: ctx,
619
- feat: feat,
620
- region: region,
621
- bpPerPx: bpPerPx,
622
- colorForBase: colorForBase,
623
- contrastForBase: contrastForBase,
624
- charWidth: charWidth,
625
- charHeight: charHeight,
626
- canvasWidth: canvasWidth,
500
+ ctx,
501
+ feat,
502
+ region,
503
+ bpPerPx,
504
+ colorForBase,
505
+ contrastForBase,
506
+ charWidth,
507
+ charHeight,
508
+ canvasWidth,
627
509
  });
628
510
  break;
629
511
  case 'modifications':
630
512
  this.colorByModifications({
631
- ctx: ctx,
632
- feat: feat,
633
- region: region,
634
- bpPerPx: bpPerPx,
635
- renderArgs: renderArgs,
636
- canvasWidth: canvasWidth,
513
+ ctx,
514
+ feat,
515
+ region,
516
+ bpPerPx,
517
+ renderArgs,
518
+ canvasWidth,
637
519
  });
638
520
  break;
639
521
  case 'methylation':
640
522
  this.colorByMethylation({
641
- ctx: ctx,
642
- feat: feat,
643
- region: region,
644
- bpPerPx: bpPerPx,
645
- renderArgs: renderArgs,
646
- canvasWidth: canvasWidth,
523
+ ctx,
524
+ feat,
525
+ region,
526
+ bpPerPx,
527
+ renderArgs,
528
+ canvasWidth,
647
529
  });
648
530
  break;
649
531
  }
650
- };
651
- PileupRenderer.prototype.drawMismatches = function (_a) {
652
- var ctx = _a.ctx, feat = _a.feat, renderArgs = _a.renderArgs, minSubfeatureWidth = _a.minSubfeatureWidth, largeInsertionIndicatorScale = _a.largeInsertionIndicatorScale, mismatchAlpha = _a.mismatchAlpha, charWidth = _a.charWidth, charHeight = _a.charHeight, colorForBase = _a.colorForBase, contrastForBase = _a.contrastForBase, canvasWidth = _a.canvasWidth, drawSNPsMuted = _a.drawSNPsMuted, _b = _a.drawIndels, drawIndels = _b === void 0 ? true : _b;
653
- var Color = renderArgs.Color, bpPerPx = renderArgs.bpPerPx, regions = renderArgs.regions;
654
- var heightPx = feat.heightPx, topPx = feat.topPx, feature = feat.feature;
655
- var _c = __read(regions, 1), region = _c[0];
656
- var start = feature.get('start');
657
- var pxPerBp = Math.min(1 / bpPerPx, 2);
658
- var w = Math.max(minSubfeatureWidth, pxPerBp);
659
- var mismatches = feature.get('mismatches');
660
- var heightLim = charHeight - 2;
532
+ }
533
+ drawMismatches({ ctx, feat, renderArgs, minSubfeatureWidth, largeInsertionIndicatorScale, mismatchAlpha, charWidth, charHeight, colorForBase, contrastForBase, canvasWidth, drawSNPsMuted, drawIndels = true, }) {
534
+ const { Color, bpPerPx, regions } = renderArgs;
535
+ const { heightPx, topPx, feature } = feat;
536
+ const [region] = regions;
537
+ const start = feature.get('start');
538
+ const pxPerBp = Math.min(1 / bpPerPx, 2);
539
+ const w = Math.max(minSubfeatureWidth, pxPerBp);
540
+ const mismatches = feature.get('mismatches');
541
+ const heightLim = charHeight - 2;
661
542
  // extraHorizontallyFlippedOffset is used to draw interbase items, which
662
543
  // are located to the left when forward and right when reversed
663
- var extraHorizontallyFlippedOffset = region.reversed
544
+ const extraHorizontallyFlippedOffset = region.reversed
664
545
  ? 1 / bpPerPx + 1
665
546
  : -1;
666
547
  // two pass rendering: first pass, draw all the mismatches except wide
667
548
  // insertion markers
668
- for (var i = 0; i < mismatches.length; i += 1) {
669
- var mismatch = mismatches[i];
670
- var mstart = start + mismatch.start;
671
- var mlen = mismatch.length;
672
- var mbase = mismatch.base;
673
- var _d = __read((0, util_1.bpSpanPx)(mstart, mstart + mlen, region, bpPerPx), 2), leftPx = _d[0], rightPx = _d[1];
674
- var widthPx = Math.max(minSubfeatureWidth, Math.abs(leftPx - rightPx));
549
+ for (let i = 0; i < mismatches.length; i += 1) {
550
+ const mismatch = mismatches[i];
551
+ const mstart = start + mismatch.start;
552
+ const mlen = mismatch.length;
553
+ const mbase = mismatch.base;
554
+ const [leftPx, rightPx] = (0, util_1.bpSpanPx)(mstart, mstart + mlen, region, bpPerPx);
555
+ const widthPx = Math.max(minSubfeatureWidth, Math.abs(leftPx - rightPx));
675
556
  if (mismatch.type === 'mismatch') {
676
557
  if (!drawSNPsMuted) {
677
- var baseColor = colorForBase[mismatch.base] || '#888';
558
+ const baseColor = colorForBase[mismatch.base] || '#888';
678
559
  fillRect(ctx, leftPx, topPx, widthPx, heightPx, canvasWidth, !mismatchAlpha
679
560
  ? baseColor
680
561
  : mismatch.qual !== undefined
@@ -687,7 +568,7 @@ var PileupRenderer = /** @class */ (function (_super) {
687
568
  }
688
569
  if (widthPx >= charWidth && heightPx >= heightLim) {
689
570
  // normal SNP coloring
690
- var contrastColor = drawSNPsMuted
571
+ const contrastColor = drawSNPsMuted
691
572
  ? 'black'
692
573
  : contrastForBase[mismatch.base] || 'black';
693
574
  ctx.fillStyle = !mismatchAlpha
@@ -704,8 +585,8 @@ var PileupRenderer = /** @class */ (function (_super) {
704
585
  }
705
586
  else if (mismatch.type === 'deletion' && drawIndels) {
706
587
  fillRect(ctx, leftPx, topPx, widthPx, heightPx, canvasWidth, colorForBase.deletion);
707
- var txt = "".concat(mismatch.length);
708
- var rwidth = (0, util_1.measureText)(txt, 10);
588
+ const txt = `${mismatch.length}`;
589
+ const rwidth = (0, util_1.measureText)(txt, 10);
709
590
  if (widthPx >= rwidth && heightPx >= heightLim) {
710
591
  ctx.fillStyle = contrastForBase.deletion;
711
592
  ctx.fillText(txt, (leftPx + rightPx) / 2 - rwidth / 2, topPx + heightPx);
@@ -713,25 +594,25 @@ var PileupRenderer = /** @class */ (function (_super) {
713
594
  }
714
595
  else if (mismatch.type === 'insertion' && drawIndels) {
715
596
  ctx.fillStyle = 'purple';
716
- var pos = leftPx + extraHorizontallyFlippedOffset;
717
- var len = +mismatch.base || mismatch.length;
718
- var insW = Math.max(minSubfeatureWidth / 2, Math.min(1.2, 1 / bpPerPx));
597
+ const pos = leftPx + extraHorizontallyFlippedOffset;
598
+ const len = +mismatch.base || mismatch.length;
599
+ const insW = Math.max(minSubfeatureWidth / 2, Math.min(1.2, 1 / bpPerPx));
719
600
  if (len < 10) {
720
601
  fillRect(ctx, pos, topPx, insW, heightPx, canvasWidth, 'purple');
721
602
  if (1 / bpPerPx >= charWidth && heightPx >= heightLim) {
722
603
  fillRect(ctx, pos - insW, topPx, insW * 3, 1, canvasWidth);
723
604
  fillRect(ctx, pos - insW, topPx + heightPx - 1, insW * 3, 1, canvasWidth);
724
- ctx.fillText("(".concat(mismatch.base, ")"), pos + 3, topPx + heightPx);
605
+ ctx.fillText(`(${mismatch.base})`, pos + 3, topPx + heightPx);
725
606
  }
726
607
  }
727
608
  }
728
609
  else if (mismatch.type === 'hardclip' || mismatch.type === 'softclip') {
729
- var pos = leftPx + extraHorizontallyFlippedOffset;
610
+ const pos = leftPx + extraHorizontallyFlippedOffset;
730
611
  fillRect(ctx, pos, topPx, w, heightPx, canvasWidth, mismatch.type === 'hardclip' ? 'red' : 'blue');
731
612
  if (1 / bpPerPx >= charWidth && heightPx >= heightLim) {
732
613
  fillRect(ctx, pos - w, topPx, w * 3, 1, canvasWidth);
733
614
  fillRect(ctx, pos - w, topPx + heightPx - 1, w * 3, 1, canvasWidth);
734
- ctx.fillText("(".concat(mismatch.base, ")"), pos + 3, topPx + heightPx);
615
+ ctx.fillText(`(${mismatch.base})`, pos + 3, topPx + heightPx);
735
616
  }
736
617
  }
737
618
  else if (mismatch.type === 'skip') {
@@ -740,7 +621,7 @@ var PileupRenderer = /** @class */ (function (_super) {
740
621
  // also affected firefox ref #1236 #2750
741
622
  if (leftPx + widthPx > 0) {
742
623
  // make small exons more visible when zoomed far out
743
- var adjustPx = widthPx - (bpPerPx > 10 ? 1.5 : 0);
624
+ const adjustPx = widthPx - (bpPerPx > 10 ? 1.5 : 0);
744
625
  ctx.clearRect(leftPx, topPx, adjustPx, heightPx);
745
626
  fillRect(ctx, Math.max(0, leftPx), topPx + heightPx / 2 - 1, adjustPx + (leftPx < 0 ? leftPx : 0), 2, canvasWidth, '#333');
746
627
  }
@@ -748,44 +629,42 @@ var PileupRenderer = /** @class */ (function (_super) {
748
629
  }
749
630
  // second pass, draw wide insertion markers on top
750
631
  if (drawIndels) {
751
- for (var i = 0; i < mismatches.length; i += 1) {
752
- var mismatch = mismatches[i];
753
- var mstart = start + mismatch.start;
754
- var mlen = mismatch.length;
755
- var _e = __read((0, util_1.bpSpanPx)(mstart, mstart + mlen, region, bpPerPx), 1), leftPx = _e[0];
756
- var len = +mismatch.base || mismatch.length;
757
- var txt = "".concat(len);
632
+ for (let i = 0; i < mismatches.length; i += 1) {
633
+ const mismatch = mismatches[i];
634
+ const mstart = start + mismatch.start;
635
+ const mlen = mismatch.length;
636
+ const [leftPx] = (0, util_1.bpSpanPx)(mstart, mstart + mlen, region, bpPerPx);
637
+ const len = +mismatch.base || mismatch.length;
638
+ const txt = `${len}`;
758
639
  if (mismatch.type === 'insertion' && len >= 10) {
759
640
  if (bpPerPx > largeInsertionIndicatorScale) {
760
641
  fillRect(ctx, leftPx - 1, topPx, 2, heightPx, canvasWidth, 'purple');
761
642
  }
762
643
  else if (heightPx > charHeight) {
763
- var rwidth = (0, util_1.measureText)(txt);
764
- var padding = 5;
644
+ const rwidth = (0, util_1.measureText)(txt);
645
+ const padding = 5;
765
646
  fillRect(ctx, leftPx - rwidth / 2 - padding, topPx, rwidth + 2 * padding, heightPx, canvasWidth, 'purple');
766
647
  ctx.fillStyle = 'white';
767
648
  ctx.fillText(txt, leftPx - rwidth / 2, topPx + heightPx);
768
649
  }
769
650
  else {
770
- var padding = 2;
651
+ const padding = 2;
771
652
  fillRect(ctx, leftPx - padding, topPx, 2 * padding, heightPx, canvasWidth, 'purple');
772
653
  }
773
654
  }
774
655
  }
775
656
  }
776
- };
777
- PileupRenderer.prototype.drawSoftClipping = function (_a) {
778
- var ctx = _a.ctx, feat = _a.feat, renderArgs = _a.renderArgs, config = _a.config, theme = _a.theme, canvasWidth = _a.canvasWidth;
779
- var feature = feat.feature, topPx = feat.topPx, heightPx = feat.heightPx;
780
- var regions = renderArgs.regions, bpPerPx = renderArgs.bpPerPx;
781
- var _b = __read(regions, 1), region = _b[0];
782
- var minFeatWidth = (0, configuration_1.readConfObject)(config, 'minSubfeatureWidth');
783
- var mismatches = feature.get('mismatches');
784
- var seq = feature.get('seq');
785
- var _c = this.getCharWidthHeight(ctx), charWidth = _c.charWidth, charHeight = _c.charHeight;
786
- // @ts-ignore
787
- var bases = theme.palette.bases;
788
- var colorForBase = {
657
+ }
658
+ drawSoftClipping({ ctx, feat, renderArgs, config, theme, canvasWidth, }) {
659
+ const { feature, topPx, heightPx } = feat;
660
+ const { regions, bpPerPx } = renderArgs;
661
+ const [region] = regions;
662
+ const minFeatWidth = (0, configuration_1.readConfObject)(config, 'minSubfeatureWidth');
663
+ const mismatches = feature.get('mismatches');
664
+ const seq = feature.get('seq');
665
+ const { charWidth, charHeight } = this.getCharWidthHeight(ctx);
666
+ const { bases } = theme.palette;
667
+ const colorForBase = {
789
668
  A: bases.A.main,
790
669
  C: bases.C.main,
791
670
  G: bases.G.main,
@@ -795,23 +674,23 @@ var PileupRenderer = /** @class */ (function (_super) {
795
674
  // Display all bases softclipped off in lightened colors
796
675
  if (seq) {
797
676
  mismatches
798
- .filter(function (mismatch) { return mismatch.type === 'softclip'; })
799
- .forEach(function (mismatch) {
800
- var softClipLength = mismatch.cliplen || 0;
801
- var s = feature.get('start');
802
- var softClipStart = mismatch.start === 0 ? s - softClipLength : s + mismatch.start;
803
- for (var k = 0; k < softClipLength; k += 1) {
804
- var base = seq.charAt(k + mismatch.start);
677
+ .filter(mismatch => mismatch.type === 'softclip')
678
+ .forEach(mismatch => {
679
+ const softClipLength = mismatch.cliplen || 0;
680
+ const s = feature.get('start');
681
+ const softClipStart = mismatch.start === 0 ? s - softClipLength : s + mismatch.start;
682
+ for (let k = 0; k < softClipLength; k += 1) {
683
+ const base = seq.charAt(k + mismatch.start);
805
684
  // If softclip length+start is longer than sequence, no need to
806
685
  // continue showing base
807
686
  if (!base) {
808
687
  return;
809
688
  }
810
- var _a = __read((0, util_1.bpSpanPx)(softClipStart + k, softClipStart + k + 1, region, bpPerPx), 2), softClipLeftPx = _a[0], softClipRightPx = _a[1];
811
- var softClipWidthPx = Math.max(minFeatWidth, Math.abs(softClipLeftPx - softClipRightPx));
689
+ const [softClipLeftPx, softClipRightPx] = (0, util_1.bpSpanPx)(softClipStart + k, softClipStart + k + 1, region, bpPerPx);
690
+ const softClipWidthPx = Math.max(minFeatWidth, Math.abs(softClipLeftPx - softClipRightPx));
812
691
  // Black accounts for IUPAC ambiguity code bases such as N that
813
692
  // show in soft clipping
814
- var baseColor = colorForBase[base] || '#000000';
693
+ const baseColor = colorForBase[base] || '#000000';
815
694
  ctx.fillStyle = baseColor;
816
695
  fillRect(ctx, softClipLeftPx, topPx, softClipWidthPx, heightPx, canvasWidth);
817
696
  if (softClipWidthPx >= charWidth && heightPx >= charHeight - 5) {
@@ -821,171 +700,158 @@ var PileupRenderer = /** @class */ (function (_super) {
821
700
  }
822
701
  });
823
702
  }
824
- };
825
- PileupRenderer.prototype.makeImageData = function (_a) {
826
- var ctx = _a.ctx, layoutRecords = _a.layoutRecords, canvasWidth = _a.canvasWidth, renderArgs = _a.renderArgs;
827
- var layout = renderArgs.layout, config = renderArgs.config, showSoftClip = renderArgs.showSoftClip, colorBy = renderArgs.colorBy, configTheme = renderArgs.theme;
828
- var mismatchAlpha = (0, configuration_1.readConfObject)(config, 'mismatchAlpha');
829
- var minSubfeatureWidth = (0, configuration_1.readConfObject)(config, 'minSubfeatureWidth');
830
- var largeInsertionIndicatorScale = (0, configuration_1.readConfObject)(config, 'largeInsertionIndicatorScale');
831
- var defaultColor = (0, configuration_1.readConfObject)(config, 'color') === '#f0f';
832
- var theme = (0, ui_1.createJBrowseTheme)(configTheme);
833
- var colorForBase = getColorBaseMap(theme);
834
- var contrastForBase = getContrastBaseMap(theme);
703
+ }
704
+ makeImageData({ ctx, layoutRecords, canvasWidth, renderArgs, }) {
705
+ const { layout, config, showSoftClip, colorBy, theme: configTheme, } = renderArgs;
706
+ const mismatchAlpha = (0, configuration_1.readConfObject)(config, 'mismatchAlpha');
707
+ const minSubfeatureWidth = (0, configuration_1.readConfObject)(config, 'minSubfeatureWidth');
708
+ const largeInsertionIndicatorScale = (0, configuration_1.readConfObject)(config, 'largeInsertionIndicatorScale');
709
+ const defaultColor = (0, configuration_1.readConfObject)(config, 'color') === '#f0f';
710
+ const theme = (0, ui_1.createJBrowseTheme)(configTheme);
711
+ const colorForBase = getColorBaseMap(theme);
712
+ const contrastForBase = getContrastBaseMap(theme);
835
713
  if (!layout) {
836
- throw new Error("layout required");
714
+ throw new Error(`layout required`);
837
715
  }
838
716
  if (!layout.addRect) {
839
717
  throw new Error('invalid layout object');
840
718
  }
841
719
  ctx.font = 'bold 10px Courier New,monospace';
842
- var _b = this.getCharWidthHeight(ctx), charWidth = _b.charWidth, charHeight = _b.charHeight;
843
- var drawSNPsMuted = shouldDrawSNPsMuted(colorBy === null || colorBy === void 0 ? void 0 : colorBy.type);
844
- var drawIndels = shouldDrawIndels(colorBy === null || colorBy === void 0 ? void 0 : colorBy.type);
845
- for (var i = 0; i < layoutRecords.length; i++) {
846
- var feat = layoutRecords[i];
720
+ const { charWidth, charHeight } = this.getCharWidthHeight(ctx);
721
+ const drawSNPsMuted = shouldDrawSNPsMuted(colorBy === null || colorBy === void 0 ? void 0 : colorBy.type);
722
+ const drawIndels = shouldDrawIndels(colorBy === null || colorBy === void 0 ? void 0 : colorBy.type);
723
+ for (let i = 0; i < layoutRecords.length; i++) {
724
+ const feat = layoutRecords[i];
847
725
  if (feat === null) {
848
726
  continue;
849
727
  }
850
728
  this.drawAlignmentRect({
851
- ctx: ctx,
852
- feat: feat,
853
- renderArgs: renderArgs,
854
- defaultColor: defaultColor,
855
- colorForBase: colorForBase,
856
- contrastForBase: contrastForBase,
857
- charWidth: charWidth,
858
- charHeight: charHeight,
859
- canvasWidth: canvasWidth,
729
+ ctx,
730
+ feat,
731
+ renderArgs,
732
+ defaultColor,
733
+ colorForBase,
734
+ contrastForBase,
735
+ charWidth,
736
+ charHeight,
737
+ canvasWidth,
860
738
  });
861
739
  this.drawMismatches({
862
- ctx: ctx,
863
- feat: feat,
864
- renderArgs: renderArgs,
865
- mismatchAlpha: mismatchAlpha,
866
- drawSNPsMuted: drawSNPsMuted,
867
- drawIndels: drawIndels,
868
- largeInsertionIndicatorScale: largeInsertionIndicatorScale,
869
- minSubfeatureWidth: minSubfeatureWidth,
870
- charWidth: charWidth,
871
- charHeight: charHeight,
872
- colorForBase: colorForBase,
873
- contrastForBase: contrastForBase,
874
- canvasWidth: canvasWidth,
740
+ ctx,
741
+ feat,
742
+ renderArgs,
743
+ mismatchAlpha,
744
+ drawSNPsMuted,
745
+ drawIndels,
746
+ largeInsertionIndicatorScale,
747
+ minSubfeatureWidth,
748
+ charWidth,
749
+ charHeight,
750
+ colorForBase,
751
+ contrastForBase,
752
+ canvasWidth,
875
753
  });
876
754
  if (showSoftClip) {
877
755
  this.drawSoftClipping({
878
- ctx: ctx,
879
- feat: feat,
880
- renderArgs: renderArgs,
881
- config: config,
882
- theme: theme,
883
- canvasWidth: canvasWidth,
756
+ ctx,
757
+ feat,
758
+ renderArgs,
759
+ config,
760
+ theme,
761
+ canvasWidth,
884
762
  });
885
763
  }
886
764
  }
887
- };
765
+ }
888
766
  // we perform a full layout before render as a separate method because the
889
767
  // layout determines the height of the canvas that we use to render
890
- PileupRenderer.prototype.layoutFeats = function (props) {
891
- var _this = this;
892
- var layout = props.layout, features = props.features, sortedBy = props.sortedBy, config = props.config, bpPerPx = props.bpPerPx, showSoftClip = props.showSoftClip, regions = props.regions;
893
- var _a = __read(regions, 1), region = _a[0];
768
+ layoutFeats(props) {
769
+ const { layout, features, sortedBy, config, bpPerPx, showSoftClip, regions, } = props;
770
+ const [region] = regions;
894
771
  if (!layout) {
895
- throw new Error("layout required");
772
+ throw new Error(`layout required`);
896
773
  }
897
774
  if (!layout.addRect) {
898
775
  throw new Error('invalid layout object');
899
776
  }
900
- var featureMap = (sortedBy === null || sortedBy === void 0 ? void 0 : sortedBy.type) && region.start === sortedBy.pos
777
+ const featureMap = (sortedBy === null || sortedBy === void 0 ? void 0 : sortedBy.type) && region.start === sortedBy.pos
901
778
  ? (0, sortUtil_1.sortFeature)(features, sortedBy)
902
779
  : features;
903
- var heightPx = (0, configuration_1.readConfObject)(config, 'height');
904
- var displayMode = (0, configuration_1.readConfObject)(config, 'displayMode');
905
- return (0, util_1.iterMap)(featureMap.values(), function (feature) {
906
- return _this.layoutFeature({
907
- feature: feature,
908
- layout: layout,
909
- bpPerPx: bpPerPx,
910
- region: region,
911
- showSoftClip: showSoftClip,
912
- heightPx: heightPx,
913
- displayMode: displayMode,
914
- });
915
- }, featureMap.size);
916
- };
917
- PileupRenderer.prototype.fetchSequence = function (renderProps) {
918
- return __awaiter(this, void 0, void 0, function () {
919
- var sessionId, regions, adapterConfig, sequenceAdapter, dataAdapter, _a, region;
920
- return __generator(this, function (_b) {
921
- switch (_b.label) {
922
- case 0:
923
- sessionId = renderProps.sessionId, regions = renderProps.regions, adapterConfig = renderProps.adapterConfig;
924
- sequenceAdapter = adapterConfig.sequenceAdapter;
925
- if (!sequenceAdapter) {
926
- return [2 /*return*/, undefined];
927
- }
928
- return [4 /*yield*/, (0, dataAdapterCache_1.getAdapter)(this.pluginManager, sessionId, sequenceAdapter)];
929
- case 1:
930
- dataAdapter = (_b.sent()).dataAdapter;
931
- _a = __read(regions, 1), region = _a[0];
932
- return [2 /*return*/, (0, util_2.fetchSequence)(region, dataAdapter)];
933
- }
934
- });
935
- });
936
- };
937
- PileupRenderer.prototype.render = function (renderProps) {
780
+ const heightPx = (0, configuration_1.readConfObject)(config, 'height');
781
+ const displayMode = (0, configuration_1.readConfObject)(config, 'displayMode');
782
+ return (0, util_1.iterMap)(featureMap.values(), feature => this.layoutFeature({
783
+ feature,
784
+ layout,
785
+ bpPerPx,
786
+ region,
787
+ showSoftClip,
788
+ heightPx,
789
+ displayMode,
790
+ }), featureMap.size);
791
+ }
792
+ async fetchSequence(renderProps) {
793
+ const { sessionId, regions, adapterConfig } = renderProps;
794
+ const { sequenceAdapter } = adapterConfig;
795
+ if (!sequenceAdapter) {
796
+ return undefined;
797
+ }
798
+ const { dataAdapter } = await (0, dataAdapterCache_1.getAdapter)(this.pluginManager, sessionId, sequenceAdapter);
799
+ const [region] = regions;
800
+ return (0, util_2.fetchSequence)(region, dataAdapter);
801
+ }
802
+ async render(renderProps) {
938
803
  var _a;
939
- return __awaiter(this, void 0, void 0, function () {
940
- var features, layout, regions, bpPerPx, layoutRecords, _b, region, regionSequence, _c, end, start, width, height, Color, res, results;
941
- var _this = this;
942
- return __generator(this, function (_d) {
943
- switch (_d.label) {
944
- case 0: return [4 /*yield*/, this.getFeatures(renderProps)];
945
- case 1:
946
- features = _d.sent();
947
- layout = this.createLayoutInWorker(renderProps);
948
- regions = renderProps.regions, bpPerPx = renderProps.bpPerPx;
949
- layoutRecords = this.layoutFeats(__assign(__assign({}, renderProps), { features: features, layout: layout }));
950
- _b = __read(regions, 1), region = _b[0];
951
- if (!(features.size && (0, util_2.shouldFetchReferenceSequence)((_a = renderProps.colorBy) === null || _a === void 0 ? void 0 : _a.type))) return [3 /*break*/, 3];
952
- return [4 /*yield*/, this.fetchSequence(renderProps)];
953
- case 2:
954
- _c = _d.sent();
955
- return [3 /*break*/, 4];
956
- case 3:
957
- _c = undefined;
958
- _d.label = 4;
959
- case 4:
960
- regionSequence = _c;
961
- end = region.end, start = region.start;
962
- width = (end - start) / bpPerPx;
963
- height = Math.max(layout.getTotalHeight(), 1);
964
- return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('color')); }).then(function (f) { return f.default; })];
965
- case 5:
966
- Color = _d.sent();
967
- return [4 /*yield*/, (0, offscreenCanvasUtils_1.renderToAbstractCanvas)(width, height, renderProps, function (ctx) {
968
- return _this.makeImageData({
969
- ctx: ctx,
970
- layoutRecords: layoutRecords,
971
- canvasWidth: width,
972
- renderArgs: __assign(__assign({}, renderProps), { layout: layout, features: features, regionSequence: regionSequence, Color: Color }),
973
- });
974
- })];
975
- case 6:
976
- res = _d.sent();
977
- return [4 /*yield*/, _super.prototype.render.call(this, __assign(__assign(__assign({}, renderProps), res), { features: features, layout: layout, height: height, width: width }))];
978
- case 7:
979
- results = _d.sent();
980
- return [2 /*return*/, __assign(__assign(__assign({}, results), res), { features: new Map(), layout: layout, height: height, width: width, maxHeightReached: layout.maxHeightReached })];
981
- }
982
- });
804
+ const features = await this.getFeatures(renderProps);
805
+ const layout = this.createLayoutInWorker(renderProps);
806
+ const { regions, bpPerPx } = renderProps;
807
+ const layoutRecords = this.layoutFeats({
808
+ ...renderProps,
809
+ features,
810
+ layout,
983
811
  });
984
- };
985
- PileupRenderer.prototype.createSession = function (args) {
812
+ const [region] = regions;
813
+ // only need reference sequence if there are features and only for some
814
+ // cases
815
+ const regionSequence = features.size && (0, util_2.shouldFetchReferenceSequence)((_a = renderProps.colorBy) === null || _a === void 0 ? void 0 : _a.type)
816
+ ? await this.fetchSequence(renderProps)
817
+ : undefined;
818
+ const { end, start } = region;
819
+ const width = (end - start) / bpPerPx;
820
+ const height = Math.max(layout.getTotalHeight(), 1);
821
+ const Color = await Promise.resolve().then(() => __importStar(require('color'))).then(f => f.default);
822
+ const res = await (0, offscreenCanvasUtils_1.renderToAbstractCanvas)(width, height, renderProps, ctx => this.makeImageData({
823
+ ctx,
824
+ layoutRecords,
825
+ canvasWidth: width,
826
+ renderArgs: {
827
+ ...renderProps,
828
+ layout,
829
+ features,
830
+ regionSequence,
831
+ Color,
832
+ },
833
+ }));
834
+ const results = await super.render({
835
+ ...renderProps,
836
+ ...res,
837
+ features,
838
+ layout,
839
+ height,
840
+ width,
841
+ });
842
+ return {
843
+ ...results,
844
+ ...res,
845
+ features: new Map(),
846
+ layout,
847
+ height,
848
+ width,
849
+ maxHeightReached: layout.maxHeightReached,
850
+ };
851
+ }
852
+ createSession(args) {
986
853
  return new PileupLayoutSession_1.PileupLayoutSession(args);
987
- };
988
- return PileupRenderer;
989
- }(BoxRendererType_1.default));
854
+ }
855
+ }
990
856
  exports.default = PileupRenderer;
991
857
  //# sourceMappingURL=PileupRenderer.js.map