@jbrowse/core 2.0.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 (184) hide show
  1. package/BaseFeatureWidget/BaseFeatureDetail.d.ts +9 -3
  2. package/BaseFeatureWidget/BaseFeatureDetail.js +313 -581
  3. package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -478
  4. package/BaseFeatureWidget/index.js +88 -126
  5. package/BaseFeatureWidget/types.d.ts +1 -0
  6. package/BaseFeatureWidget/types.js +1 -4
  7. package/BaseFeatureWidget/util.js +40 -75
  8. package/CorePlugin.js +55 -94
  9. package/Plugin.js +9 -34
  10. package/PluginLoader.js +153 -422
  11. package/PluginManager.d.ts +28 -33
  12. package/PluginManager.js +377 -666
  13. package/ReExports/Attributes.js +3 -10
  14. package/ReExports/BaseCard.js +3 -10
  15. package/ReExports/DataGrid.js +5 -12
  16. package/ReExports/FeatureDetails.js +3 -10
  17. package/ReExports/index.js +6 -12
  18. package/ReExports/list.d.ts +5 -0
  19. package/ReExports/list.js +271 -7
  20. package/ReExports/material-ui-colors.js +15 -16
  21. package/ReExports/modules.d.ts +11 -20
  22. package/ReExports/modules.js +453 -798
  23. package/TextSearch/BaseResults.js +51 -123
  24. package/TextSearch/TextSearchManager.js +66 -144
  25. package/assemblyManager/assembly.js +280 -555
  26. package/assemblyManager/assemblyConfigSchema.js +47 -64
  27. package/assemblyManager/assemblyManager.js +126 -272
  28. package/assemblyManager/index.js +9 -22
  29. package/configuration/configurationSchema.js +167 -203
  30. package/configuration/configurationSlot.js +248 -326
  31. package/configuration/index.js +19 -35
  32. package/configuration/util.js +131 -173
  33. package/data_adapters/BaseAdapter.d.ts +2 -2
  34. package/data_adapters/BaseAdapter.js +132 -521
  35. package/data_adapters/CytobandAdapter.js +40 -126
  36. package/data_adapters/dataAdapterCache.js +77 -158
  37. package/package.json +4 -5
  38. package/pluggableElementTypes/AdapterType.js +24 -79
  39. package/pluggableElementTypes/AddTrackWorkflowType.d.ts +17 -0
  40. package/pluggableElementTypes/AddTrackWorkflowType.js +20 -0
  41. package/pluggableElementTypes/ConnectionType.js +22 -65
  42. package/pluggableElementTypes/DisplayType.js +35 -82
  43. package/pluggableElementTypes/InternetAccountType.js +23 -64
  44. package/pluggableElementTypes/PluggableElementBase.js +8 -20
  45. package/pluggableElementTypes/RpcMethodType.js +85 -427
  46. package/pluggableElementTypes/TextSearchAdapterType.js +16 -55
  47. package/pluggableElementTypes/TrackType.js +26 -70
  48. package/pluggableElementTypes/ViewType.js +21 -63
  49. package/pluggableElementTypes/WidgetType.js +21 -64
  50. package/pluggableElementTypes/index.d.ts +4 -3
  51. package/pluggableElementTypes/index.js +42 -125
  52. package/pluggableElementTypes/models/BaseConnectionModelFactory.js +28 -43
  53. package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
  54. package/pluggableElementTypes/models/BaseTrackModel.js +139 -199
  55. package/pluggableElementTypes/models/BaseViewModel.js +24 -40
  56. package/pluggableElementTypes/models/InternetAccountModel.js +116 -263
  57. package/pluggableElementTypes/models/baseConnectionConfig.js +14 -25
  58. package/pluggableElementTypes/models/baseInternetAccountConfig.js +29 -38
  59. package/pluggableElementTypes/models/baseTrackConfig.js +106 -133
  60. package/pluggableElementTypes/models/index.js +21 -70
  61. package/pluggableElementTypes/renderers/BoxRendererType.js +132 -291
  62. package/pluggableElementTypes/renderers/CircularChordRendererType.js +8 -38
  63. package/pluggableElementTypes/renderers/ComparativeServerSideRendererType.js +60 -192
  64. package/pluggableElementTypes/renderers/FeatureRendererType.d.ts +0 -2
  65. package/pluggableElementTypes/renderers/FeatureRendererType.js +89 -255
  66. package/pluggableElementTypes/renderers/RendererType.js +31 -105
  67. package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
  68. package/pluggableElementTypes/renderers/ServerSideRendererType.js +112 -265
  69. package/pluggableElementTypes/renderers/index.js +19 -62
  70. package/pluggableElementTypes/renderers/util/serializableFilterChain.js +27 -65
  71. package/rpc/BaseRpcDriver.js +169 -405
  72. package/rpc/MainThreadRpcDriver.js +27 -150
  73. package/rpc/RpcManager.js +58 -159
  74. package/rpc/WebWorkerRpcDriver.js +54 -171
  75. package/rpc/configSchema.js +25 -49
  76. package/rpc/coreRpcMethods.d.ts +1 -3
  77. package/rpc/coreRpcMethods.js +221 -959
  78. package/rpc/remoteAbortSignals.js +46 -70
  79. package/tsconfig.build.tsbuildinfo +1 -1
  80. package/ui/AboutDialog.js +106 -162
  81. package/ui/App.js +157 -242
  82. package/ui/AssemblySelector.js +59 -120
  83. package/ui/CascadingMenu.js +101 -196
  84. package/ui/ColorPicker.d.ts +16 -0
  85. package/ui/ColorPicker.js +97 -0
  86. package/ui/Drawer.js +28 -61
  87. package/ui/DrawerWidget.js +108 -202
  88. package/ui/DropDownMenu.js +60 -91
  89. package/ui/EditableTypography.js +87 -149
  90. package/ui/ErrorMessage.js +41 -56
  91. package/ui/FactoryResetDialog.js +24 -57
  92. package/ui/FatalErrorDialog.js +59 -91
  93. package/ui/FileSelector/FileSelector.js +123 -189
  94. package/ui/FileSelector/LocalFileChooser.js +44 -75
  95. package/ui/FileSelector/UrlChooser.js +17 -38
  96. package/ui/FileSelector/index.js +6 -12
  97. package/ui/Icons.js +45 -69
  98. package/ui/Logo.js +57 -110
  99. package/ui/Menu.js +232 -354
  100. package/ui/PrerenderedCanvas.js +63 -87
  101. package/ui/ResizeHandle.js +87 -116
  102. package/ui/ReturnToImportFormDialog.js +32 -63
  103. package/ui/SanitizedHTML.js +64 -47
  104. package/ui/Snackbar.js +74 -101
  105. package/ui/SnackbarModel.js +37 -51
  106. package/ui/Tooltip.js +49 -76
  107. package/ui/ViewContainer.js +113 -196
  108. package/ui/colors.d.ts +10 -0
  109. package/ui/colors.js +78 -0
  110. package/ui/index.js +51 -181
  111. package/ui/react-colorful.d.ts +17 -0
  112. package/ui/react-colorful.js +455 -0
  113. package/ui/theme.d.ts +23 -1
  114. package/ui/theme.js +199 -247
  115. package/util/Base1DUtils.d.ts +32 -0
  116. package/util/Base1DUtils.js +174 -0
  117. package/util/Base1DViewModel.d.ts +16 -30
  118. package/util/Base1DViewModel.js +116 -293
  119. package/util/QuickLRU.js +84 -332
  120. package/util/TimeTraveller.d.ts +19 -0
  121. package/util/TimeTraveller.js +86 -0
  122. package/util/aborting.js +49 -127
  123. package/util/analytics.js +91 -154
  124. package/util/blockTypes.js +106 -240
  125. package/util/calculateDynamicBlocks.js +98 -128
  126. package/util/calculateStaticBlocks.js +105 -125
  127. package/util/color/cssColorsLevel4.js +156 -160
  128. package/util/color/index.js +33 -55
  129. package/util/compositeMap.js +49 -333
  130. package/util/formatFastaStrings.js +9 -14
  131. package/util/idMaker.js +18 -31
  132. package/util/index.d.ts +18 -32
  133. package/util/index.js +747 -1226
  134. package/util/io/RemoteFileWithRangeCache.js +88 -257
  135. package/util/io/index.js +95 -169
  136. package/util/jexl.js +60 -115
  137. package/util/jexlStrings.js +24 -29
  138. package/util/layouts/BaseLayout.js +1 -4
  139. package/util/layouts/GranularRectLayout.js +388 -555
  140. package/util/layouts/MultiLayout.js +41 -109
  141. package/util/layouts/PrecomputedLayout.js +56 -112
  142. package/util/layouts/PrecomputedMultiLayout.js +22 -59
  143. package/util/layouts/SceneGraph.js +127 -197
  144. package/util/layouts/index.js +29 -66
  145. package/util/mst-reflection.js +55 -71
  146. package/util/offscreenCanvasPonyfill.js +66 -134
  147. package/util/offscreenCanvasUtils.d.ts +2 -7
  148. package/util/offscreenCanvasUtils.js +49 -146
  149. package/util/range.js +29 -40
  150. package/util/rxjs.js +20 -27
  151. package/util/simpleFeature.js +88 -152
  152. package/util/stats.js +91 -151
  153. package/util/tracks.js +130 -173
  154. package/util/types/index.js +110 -179
  155. package/util/types/mst.js +91 -146
  156. package/util/types/util.js +1 -4
  157. package/util/when.js +54 -101
  158. package/BaseFeatureWidget/SequenceFeatureDetails.test.js +0 -122
  159. package/BaseFeatureWidget/index.test.js +0 -69
  160. package/TextSearch/BaseResults.test.js +0 -42
  161. package/configuration/configurationSchema.test.js +0 -266
  162. package/configuration/configurationSlot.test.js +0 -69
  163. package/configuration/util.test.js +0 -39
  164. package/data_adapters/BaseAdapter.test.js +0 -200
  165. package/declare.d.js +0 -1
  166. package/pluggableElementTypes/RpcMethodType.test.js +0 -118
  167. package/pluggableElementTypes/renderers/declare.d.js +0 -1
  168. package/pluggableElementTypes/renderers/util/serializableFilterChain.test.js +0 -20
  169. package/rpc/BaseRpcDriver.test.js +0 -540
  170. package/rpc/declaration.d.js +0 -1
  171. package/ui/FatalErrorDialog.test.js +0 -82
  172. package/ui/SanitizedHTML.test.js +0 -36
  173. package/ui/theme.test.js +0 -92
  174. package/util/Base1DViewModel.test.js +0 -130
  175. package/util/calculateDynamicBlocks.test.js +0 -74
  176. package/util/calculateStaticBlocks.test.js +0 -297
  177. package/util/declare.d.js +0 -1
  178. package/util/formatFastaStrings.test.js +0 -40
  179. package/util/index.test.js +0 -213
  180. package/util/jexlStrings.test.js +0 -48
  181. package/util/layouts/GranularRectLayout.test.js +0 -99
  182. package/util/range.test.js +0 -64
  183. package/util/simpleFeature.test.js +0 -34
  184. package/util/stats.test.js +0 -172
@@ -1,185 +1,121 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- exports.isFeature = isFeature;
10
-
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
-
13
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
-
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
18
-
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
-
21
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
22
-
23
- /**
24
- * Abstract feature object
25
- */
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFeature = void 0;
26
4
  function isFeature(thing) {
27
- return (0, _typeof2.default)(thing) === 'object' && thing !== null && typeof thing.get === 'function' && typeof thing.id === 'function';
5
+ return (typeof thing === 'object' &&
6
+ thing !== null &&
7
+ typeof thing.get === 'function' &&
8
+ typeof thing.id === 'function');
28
9
  }
29
-
10
+ exports.isFeature = isFeature;
30
11
  function isSimpleFeatureSerialized(args) {
31
- return 'uniqueId' in args && (0, _typeof2.default)(args.data) !== 'object';
12
+ return 'uniqueId' in args && typeof args.data !== 'object';
32
13
  }
33
14
  /**
34
15
  * Simple implementation of a feature object.
35
16
  */
36
-
37
-
38
- var SimpleFeature = /*#__PURE__*/function () {
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
-
41
- /**
42
- * @param args - SimpleFeature args
43
- *
44
- * Note: args.data.subfeatures can be an array of these same args,
45
- * which will be inflated to more instances of this class.
46
- */
47
- function SimpleFeature(args) {
48
- var _this = this;
49
-
50
- (0, _classCallCheck2.default)(this, SimpleFeature);
51
- (0, _defineProperty2.default)(this, "data", void 0);
52
- (0, _defineProperty2.default)(this, "subfeatures", void 0);
53
- (0, _defineProperty2.default)(this, "parentHandle", void 0);
54
- (0, _defineProperty2.default)(this, "uniqueId", void 0);
55
-
56
- if (isSimpleFeatureSerialized(args)) {
57
- this.data = args;
58
- } else {
59
- this.data = args.data || {}; // load handle from args.parent (not args.data.parent)
60
- // this reason is because if args is an object, it likely isn't properly loaded with
61
- // parent as a Feature reference (probably a raw parent ID or something instead)
62
-
63
- this.parentHandle = args.parent;
64
- } // the feature id comes from
65
- // args.id, args.data.uniqueId, or args.uniqueId due to this initialization
66
-
67
-
68
- var id = isSimpleFeatureSerialized(args) ? args.uniqueId : args.id;
69
-
70
- if (id === undefined || id === null) {
71
- throw new Error('SimpleFeature requires a unique `id` or `data.uniqueId` attribute');
72
- }
73
-
74
- this.uniqueId = String(id);
75
-
76
- if (!(this.data.aliases || this.data.end - this.data.start >= 0)) {
77
- throw new Error("invalid feature data, end less than start. end: ".concat(this.data.end, " start: ").concat(this.data.start));
78
- }
79
-
80
- if (this.data.subfeatures) {
81
- var _this$data$subfeature;
82
-
83
- this.subfeatures = (_this$data$subfeature = this.data.subfeatures) === null || _this$data$subfeature === void 0 ? void 0 : _this$data$subfeature.map( // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- function (f, i) {
85
- return typeof f.get !== 'function' ? new SimpleFeature({
86
- id: f.uniqueId || "".concat(id, "-").concat(i),
87
- data: _objectSpread({
88
- strand: _this.data.strand
89
- }, f),
90
- parent: _this
91
- }) : f;
92
- });
17
+ class SimpleFeature {
18
+ /**
19
+ * @param args - SimpleFeature args
20
+ *
21
+ * Note: args.data.subfeatures can be an array of these same args,
22
+ * which will be inflated to more instances of this class.
23
+ */
24
+ constructor(args) {
25
+ var _a;
26
+ if (isSimpleFeatureSerialized(args)) {
27
+ this.data = args;
28
+ }
29
+ else {
30
+ this.data = args.data || {};
31
+ // load handle from args.parent (not args.data.parent)
32
+ // this reason is because if args is an object, it likely isn't properly loaded with
33
+ // parent as a Feature reference (probably a raw parent ID or something instead)
34
+ this.parentHandle = args.parent;
35
+ }
36
+ // the feature id comes from
37
+ // args.id, args.data.uniqueId, or args.uniqueId due to this initialization
38
+ const id = isSimpleFeatureSerialized(args) ? args.uniqueId : args.id;
39
+ if (id === undefined || id === null) {
40
+ throw new Error('SimpleFeature requires a unique `id` or `data.uniqueId` attribute');
41
+ }
42
+ this.uniqueId = String(id);
43
+ if (!(this.data.aliases || this.data.end - this.data.start >= 0)) {
44
+ throw new Error(`invalid feature data, end less than start. end: ${this.data.end} start: ${this.data.start}`);
45
+ }
46
+ if (this.data.subfeatures) {
47
+ this.subfeatures = (_a = this.data.subfeatures) === null || _a === void 0 ? void 0 : _a.map(
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ (f, i) => typeof f.get !== 'function'
50
+ ? new SimpleFeature({
51
+ id: f.uniqueId || `${id}-${i}`,
52
+ data: {
53
+ strand: this.data.strand,
54
+ ...f,
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ },
57
+ parent: this,
58
+ })
59
+ : f);
60
+ }
93
61
  }
94
- }
95
- /**
96
- * Get a piece of data about the feature. All features must have
97
- * 'start' and 'end', but everything else is optional.
98
- */
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
-
101
-
102
- (0, _createClass2.default)(SimpleFeature, [{
103
- key: "get",
104
- value: function get(name) {
105
- return name === 'subfeatures' ? this.subfeatures : name === 'parent' ? this.parent() : this.data[name];
62
+ /**
63
+ * Get a piece of data about the feature. All features must have
64
+ * 'start' and 'end', but everything else is optional.
65
+ */
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ get(name) {
68
+ return name === 'subfeatures'
69
+ ? this.subfeatures
70
+ : name === 'parent'
71
+ ? this.parent()
72
+ : this.data[name];
106
73
  }
107
74
  /**
108
75
  * Set an item of data.
109
76
  */
110
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
-
112
- }, {
113
- key: "set",
114
- value: function set(name, val) {
115
- this.data[name] = val;
78
+ set(name, val) {
79
+ this.data[name] = val;
116
80
  }
117
81
  /**
118
82
  * Get an array listing which data keys are present in this feature.
119
83
  */
120
-
121
- }, {
122
- key: "tags",
123
- value: function tags() {
124
- return Object.keys(this.data);
84
+ tags() {
85
+ return Object.keys(this.data);
125
86
  }
126
87
  /**
127
88
  * Get the unique ID of this feature.
128
89
  */
129
-
130
- }, {
131
- key: "id",
132
- value: function id() {
133
- return this.uniqueId;
90
+ id() {
91
+ return this.uniqueId;
134
92
  }
135
93
  /**
136
94
  * Get this feature's parent feature, or undefined if none.
137
95
  */
138
-
139
- }, {
140
- key: "parent",
141
- value: function parent() {
142
- return this.parentHandle;
96
+ parent() {
97
+ return this.parentHandle;
143
98
  }
144
99
  /**
145
100
  * Get an array of child features, or undefined if none.
146
101
  */
147
-
148
- }, {
149
- key: "children",
150
- value: function children() {
151
- return this.get('subfeatures');
102
+ children() {
103
+ return this.get('subfeatures');
152
104
  }
153
- }, {
154
- key: "toJSON",
155
- value: function toJSON() {
156
- var d = _objectSpread(_objectSpread({}, this.data), {}, {
157
- uniqueId: this.id()
158
- });
159
-
160
- var p = this.parent();
161
-
162
- if (p) {
163
- d.parentId = p.id();
164
- }
165
-
166
- var c = this.children();
167
-
168
- if (c) {
169
- d.subfeatures = c.map(function (child) {
170
- return child.toJSON();
171
- });
172
- }
173
-
174
- return d;
105
+ toJSON() {
106
+ const d = { ...this.data, uniqueId: this.id() };
107
+ const p = this.parent();
108
+ if (p) {
109
+ d.parentId = p.id();
110
+ }
111
+ const c = this.children();
112
+ if (c) {
113
+ d.subfeatures = c.map(child => child.toJSON());
114
+ }
115
+ return d;
175
116
  }
176
- }], [{
177
- key: "fromJSON",
178
- value: function fromJSON(json) {
179
- return new SimpleFeature(_objectSpread({}, json));
117
+ static fromJSON(json) {
118
+ return new SimpleFeature({ ...json });
180
119
  }
181
- }]);
182
- return SimpleFeature;
183
- }();
184
-
185
- exports.default = SimpleFeature;
120
+ }
121
+ exports.default = SimpleFeature;
package/util/stats.js CHANGED
@@ -1,28 +1,7 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.blankStats = blankStats;
9
- exports.calcPerBaseStats = calcPerBaseStats;
10
- exports.calcStdFromSums = calcStdFromSums;
11
- exports.rectifyStats = rectifyStats;
12
- exports.scoresToStats = scoresToStats;
13
-
14
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
15
-
16
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
17
-
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
- var _operators = require("rxjs/operators");
21
-
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blankStats = exports.scoresToStats = exports.calcPerBaseStats = exports.rectifyStats = exports.calcStdFromSums = void 0;
4
+ const operators_1 = require("rxjs/operators");
26
5
  /*
27
6
  * calculate standard deviation using the 'shortcut method' that accepts
28
7
  * the sum and the sum squares of the elements
@@ -33,155 +12,116 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
33
12
  * @param population - boolean: use population instead of sample correction
34
13
  * @return the estimated std deviation
35
14
  */
36
- function calcStdFromSums(sum, sumSquares, n) {
37
- var population = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
38
-
39
- if (n === 0) {
40
- return 0;
41
- }
42
-
43
- var variance;
44
-
45
- if (population) {
46
- variance = sumSquares / n - sum * sum / (n * n);
47
- } else {
48
- // sample correction is n-1
49
- variance = sumSquares - sum * sum / n;
50
-
51
- if (n > 1) {
52
- variance /= n - 1;
15
+ function calcStdFromSums(sum, sumSquares, n, population = false) {
16
+ if (n === 0) {
17
+ return 0;
18
+ }
19
+ let variance;
20
+ if (population) {
21
+ variance = sumSquares / n - (sum * sum) / (n * n);
53
22
  }
54
- }
55
-
56
- return variance < 0 ? 0 : Math.sqrt(variance);
23
+ else {
24
+ // sample correction is n-1
25
+ variance = sumSquares - (sum * sum) / n;
26
+ if (n > 1) {
27
+ variance /= n - 1;
28
+ }
29
+ }
30
+ return variance < 0 ? 0 : Math.sqrt(variance);
57
31
  }
32
+ exports.calcStdFromSums = calcStdFromSums;
58
33
  /*
59
34
  * @param stats - a summary stats object with scoreSum, featureCount, scoreSumSquares, and basesCovered
60
35
  * @return - a summary stats object with scoreMean, scoreStdDev, and featureDensity added
61
36
  */
62
-
63
-
64
37
  function rectifyStats(s) {
65
- return _objectSpread(_objectSpread({}, s), {}, {
66
- scoreMean: (s.scoreSum || 0) / (s.featureCount || s.basesCovered || 1),
67
- scoreStdDev: calcStdFromSums(s.scoreSum, s.scoreSumSquares, s.featureCount || s.basesCovered),
68
- featureDensity: (s.featureCount || 1) / s.basesCovered
69
- });
38
+ return {
39
+ ...s,
40
+ scoreMean: (s.scoreSum || 0) / (s.featureCount || s.basesCovered || 1),
41
+ scoreStdDev: calcStdFromSums(s.scoreSum, s.scoreSumSquares, s.featureCount || s.basesCovered),
42
+ featureDensity: (s.featureCount || 1) / s.basesCovered,
43
+ };
70
44
  }
45
+ exports.rectifyStats = rectifyStats;
71
46
  /*
72
47
  * calculates per-base scores for variable width features over a region
73
48
  * @param region - object contains start, end
74
49
  * @param features - list of features with start, end, score
75
50
  * @return array of numeric scores
76
51
  */
77
-
78
-
79
52
  function calcPerBaseStats(region, features) {
80
- var start = region.start,
81
- end = region.end;
82
- var scores = [];
83
- var feats = features.sort(function (a, b) {
84
- return a.get('start') - b.get('start');
85
- });
86
- var pos = start;
87
- var currentFeat = 0;
88
- var i = 0;
89
-
90
- while (pos < end) {
91
- while (currentFeat < feats.length && pos >= feats[currentFeat].get('end')) {
92
- currentFeat += 1;
93
- }
94
-
95
- var f = feats[currentFeat];
96
-
97
- if (!f) {
98
- scores[i] = 0;
99
- } else if (pos >= f.get('start') && pos < f.get('end')) {
100
- scores[i] = f.get('score');
101
- } else {
102
- scores[i] = 0;
53
+ const { start, end } = region;
54
+ const scores = [];
55
+ const feats = features.sort((a, b) => a.get('start') - b.get('start'));
56
+ let pos = start;
57
+ let currentFeat = 0;
58
+ let i = 0;
59
+ while (pos < end) {
60
+ while (currentFeat < feats.length && pos >= feats[currentFeat].get('end')) {
61
+ currentFeat += 1;
62
+ }
63
+ const f = feats[currentFeat];
64
+ if (!f) {
65
+ scores[i] = 0;
66
+ }
67
+ else if (pos >= f.get('start') && pos < f.get('end')) {
68
+ scores[i] = f.get('score');
69
+ }
70
+ else {
71
+ scores[i] = 0;
72
+ }
73
+ i += 1;
74
+ pos += 1;
103
75
  }
104
-
105
- i += 1;
106
- pos += 1;
107
- }
108
-
109
- return scores;
76
+ return scores;
110
77
  }
78
+ exports.calcPerBaseStats = calcPerBaseStats;
111
79
  /*
112
80
  * transform a list of scores to summary statistics
113
81
  * @param region - object with start, end
114
82
  * @param feats - array of features which are possibly summary features
115
83
  * @return - object with scoreMax, scoreMin, scoreSum, scoreSumSquares, etc
116
84
  */
117
-
118
-
119
- function scoresToStats(_x, _x2) {
120
- return _scoresToStats.apply(this, arguments);
85
+ async function scoresToStats(region, features) {
86
+ const { start, end } = region;
87
+ const { scoreMin, scoreMax, scoreSum, scoreSumSquares, featureCount } = await features
88
+ .pipe((0, operators_1.reduce)((seed, f) => {
89
+ const score = f.get('score');
90
+ seed.scoreMax = Math.max(seed.scoreMax, f.get('summary') ? f.get('maxScore') : score);
91
+ seed.scoreMin = Math.min(seed.scoreMin, f.get('summary') ? f.get('minScore') : score);
92
+ seed.scoreSum += score;
93
+ seed.scoreSumSquares += score * score;
94
+ seed.featureCount += 1;
95
+ return seed;
96
+ }, {
97
+ scoreMin: Number.MAX_VALUE,
98
+ scoreMax: Number.MIN_VALUE,
99
+ scoreSum: 0,
100
+ scoreSumSquares: 0,
101
+ featureCount: 0,
102
+ }))
103
+ .toPromise();
104
+ return rectifyStats({
105
+ scoreMax,
106
+ scoreMin,
107
+ scoreSum,
108
+ scoreSumSquares,
109
+ featureCount,
110
+ basesCovered: end - start + 1,
111
+ });
121
112
  }
122
-
123
- function _scoresToStats() {
124
- _scoresToStats = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(region, features) {
125
- var start, end, _yield$features$pipe$, scoreMin, scoreMax, scoreSum, scoreSumSquares, featureCount;
126
-
127
- return _regenerator.default.wrap(function _callee$(_context) {
128
- while (1) {
129
- switch (_context.prev = _context.next) {
130
- case 0:
131
- start = region.start, end = region.end;
132
- _context.next = 3;
133
- return features.pipe((0, _operators.reduce)(function (seed, f) {
134
- var score = f.get('score');
135
- seed.scoreMax = Math.max(seed.scoreMax, f.get('summary') ? f.get('maxScore') : score);
136
- seed.scoreMin = Math.min(seed.scoreMin, f.get('summary') ? f.get('minScore') : score);
137
- seed.scoreSum += score;
138
- seed.scoreSumSquares += score * score;
139
- seed.featureCount += 1;
140
- return seed;
141
- }, {
142
- scoreMin: Number.MAX_VALUE,
143
- scoreMax: Number.MIN_VALUE,
144
- scoreSum: 0,
145
- scoreSumSquares: 0,
146
- featureCount: 0
147
- })).toPromise();
148
-
149
- case 3:
150
- _yield$features$pipe$ = _context.sent;
151
- scoreMin = _yield$features$pipe$.scoreMin;
152
- scoreMax = _yield$features$pipe$.scoreMax;
153
- scoreSum = _yield$features$pipe$.scoreSum;
154
- scoreSumSquares = _yield$features$pipe$.scoreSumSquares;
155
- featureCount = _yield$features$pipe$.featureCount;
156
- return _context.abrupt("return", rectifyStats({
157
- scoreMax: scoreMax,
158
- scoreMin: scoreMin,
159
- scoreSum: scoreSum,
160
- scoreSumSquares: scoreSumSquares,
161
- featureCount: featureCount,
162
- basesCovered: end - start + 1
163
- }));
164
-
165
- case 10:
166
- case "end":
167
- return _context.stop();
168
- }
169
- }
170
- }, _callee);
171
- }));
172
- return _scoresToStats.apply(this, arguments);
173
- }
174
-
113
+ exports.scoresToStats = scoresToStats;
175
114
  function blankStats() {
176
- return {
177
- scoreMin: 0,
178
- scoreMax: 0,
179
- scoreMean: 0,
180
- scoreStdDev: 0,
181
- scoreSum: 0,
182
- scoreSumSquares: 0,
183
- featureCount: 0,
184
- featureDensity: 0,
185
- basesCovered: 0
186
- };
187
- }
115
+ return {
116
+ scoreMin: 0,
117
+ scoreMax: 0,
118
+ scoreMean: 0,
119
+ scoreStdDev: 0,
120
+ scoreSum: 0,
121
+ scoreSumSquares: 0,
122
+ featureCount: 0,
123
+ featureDensity: 0,
124
+ basesCovered: 0,
125
+ };
126
+ }
127
+ exports.blankStats = blankStats;