@datagrok/proteomics 1.0.1 → 1.2.1

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 (116) hide show
  1. package/CHANGELOG.md +52 -3
  2. package/CLAUDE.md +178 -0
  3. package/README.md +195 -3
  4. package/detectors.js +152 -9
  5. package/dist/package-test.js +1 -1744
  6. package/dist/package-test.js.map +1 -1
  7. package/dist/package.js +1 -146
  8. package/dist/package.js.map +1 -1
  9. package/docs/personas-and-capabilities.md +165 -0
  10. package/files/demo/README.md +264 -0
  11. package/files/demo/cptac-spike-in.txt +1571 -0
  12. package/files/demo/enrichment-demo.csv +120 -0
  13. package/files/demo/fragpipe-smoke-test.tsv +11 -0
  14. package/files/demo/proteinGroups.txt +28 -0
  15. package/files/demo/spectronaut-hye-candidates.tsv +94 -0
  16. package/files/demo/spectronaut-hye-demo.tsv +8761 -0
  17. package/files/demo/spectronaut-hye-mix.tsv +8761 -0
  18. package/files/demo/spectronaut-hye-precursor-golden.json +938 -0
  19. package/files/demo/spectronaut-hye-precursor-golden.tsv +235 -0
  20. package/files/demo/spectronaut-hye-precursor.tsv +493 -0
  21. package/images/enrichment-crosslink.png +0 -0
  22. package/images/enrichment-term-selected.png +0 -0
  23. package/images/hero.png +0 -0
  24. package/images/pipeline.svg +80 -0
  25. package/package.json +88 -63
  26. package/scripts/deqms_de.R +60 -0
  27. package/scripts/limma_de.R +42 -0
  28. package/scripts/vsn_normalize.R +19 -0
  29. package/src/analysis/differential-expression.ts +450 -0
  30. package/src/analysis/enrichment-export.ts +101 -0
  31. package/src/analysis/enrichment.ts +602 -0
  32. package/src/analysis/experiment-setup.ts +199 -0
  33. package/src/analysis/imputation.ts +407 -0
  34. package/src/analysis/log2-scale.ts +139 -0
  35. package/src/analysis/normalization.ts +255 -0
  36. package/src/analysis/pca.ts +254 -0
  37. package/src/analysis/spc-storage.ts +515 -0
  38. package/src/analysis/spc.ts +544 -0
  39. package/src/analysis/subcellular-location.ts +431 -0
  40. package/src/demo/enrichment-demo.ts +94 -0
  41. package/src/demo/proteomics-demo.ts +123 -0
  42. package/src/global.d.ts +15 -0
  43. package/src/menu.ts +133 -0
  44. package/src/package-api.ts +136 -14
  45. package/src/package-test.ts +45 -20
  46. package/src/package.g.ts +161 -0
  47. package/src/package.ts +1029 -17
  48. package/src/panels/protein-focus.ts +63 -0
  49. package/src/panels/published-analysis-panel.ts +151 -0
  50. package/src/panels/uniprot-panel.ts +349 -0
  51. package/src/parsers/fragpipe-parser.ts +200 -0
  52. package/src/parsers/generic-parser.ts +197 -0
  53. package/src/parsers/maxquant-parser.ts +162 -0
  54. package/src/parsers/shared-utils.ts +163 -0
  55. package/src/parsers/spectronaut-candidates-parser.ts +307 -0
  56. package/src/parsers/spectronaut-parser.ts +604 -0
  57. package/src/publishing/assert-published-shape.ts +260 -0
  58. package/src/publishing/post-open-recovery.ts +104 -0
  59. package/src/publishing/publish-project.ts +515 -0
  60. package/src/publishing/publish-settings.ts +59 -0
  61. package/src/publishing/publish-state.ts +316 -0
  62. package/src/publishing/share-dialog.ts +171 -0
  63. package/src/publishing/trim-dataframe.ts +247 -0
  64. package/src/tests/analysis.ts +658 -0
  65. package/src/tests/enrichment-export.ts +61 -0
  66. package/src/tests/enrichment-visualization.ts +340 -0
  67. package/src/tests/enrichment.ts +224 -0
  68. package/src/tests/fragpipe-e2e.ts +74 -0
  69. package/src/tests/fragpipe-parser.ts +147 -0
  70. package/src/tests/gene-label-resolver.ts +387 -0
  71. package/src/tests/generic-parser.ts +152 -0
  72. package/src/tests/group-mean-correlation.ts +139 -0
  73. package/src/tests/log2-scale.ts +93 -0
  74. package/src/tests/organisms.ts +56 -0
  75. package/src/tests/parsers.ts +182 -0
  76. package/src/tests/publish-roundtrip.ts +584 -0
  77. package/src/tests/publish-spike.ts +377 -0
  78. package/src/tests/qc-dashboard.ts +210 -0
  79. package/src/tests/smart-pathway-filter.ts +193 -0
  80. package/src/tests/spc-formula-lines-spike.ts +129 -0
  81. package/src/tests/spc.ts +640 -0
  82. package/src/tests/spectronaut-candidates-e2e.ts +140 -0
  83. package/src/tests/spectronaut-candidates-parser.ts +398 -0
  84. package/src/tests/spectronaut-parser.ts +668 -0
  85. package/src/tests/subcellular-location.ts +361 -0
  86. package/src/tests/uniprot-panel.ts +202 -0
  87. package/src/tests/volcano.ts +603 -0
  88. package/src/utils/column-detection.ts +28 -0
  89. package/src/utils/gene-label-resolver.ts +443 -0
  90. package/src/utils/organisms.ts +82 -0
  91. package/src/utils/proteomics-types.ts +30 -0
  92. package/src/viewers/enrichment-viewers.ts +274 -0
  93. package/src/viewers/group-mean-correlation.ts +218 -0
  94. package/src/viewers/heatmap.ts +168 -0
  95. package/src/viewers/pca-plot.ts +169 -0
  96. package/src/viewers/qc-computations.ts +266 -0
  97. package/src/viewers/qc-dashboard.ts +176 -0
  98. package/src/viewers/spc-dashboard.ts +755 -0
  99. package/src/viewers/volcano.ts +690 -0
  100. package/test-console-output-1.log +2073 -0
  101. package/test-record-1.mp4 +0 -0
  102. package/tools/derive-precursor-golden-sidecar.mjs +81 -0
  103. package/tools/generate-enrichment-fixture.sh +160 -0
  104. package/tools/generate-spectronaut-candidates-fixture.mjs +212 -0
  105. package/tools/generate-spectronaut-precursor-fixture.mjs +128 -0
  106. package/tools/spectronaut-aggregate.sh +46 -0
  107. package/tools/spectronaut-aggregate.sql +80 -0
  108. package/tsconfig.json +18 -71
  109. package/webpack.config.js +86 -45
  110. package/.eslintignore +0 -1
  111. package/.eslintrc.json +0 -56
  112. package/LICENSE +0 -674
  113. package/package.png +0 -0
  114. package/scripts/number_antibody.py +0 -190
  115. package/scripts/number_antibody_abnumber.py +0 -177
  116. package/scripts/number_antibody_anarci.py +0 -200
package/dist/package.js CHANGED
@@ -1,147 +1,2 @@
1
- var proteomics;
2
- /******/ (() => { // webpackBootstrap
3
- /******/ "use strict";
4
- /******/ var __webpack_modules__ = ({
5
-
6
- /***/ "./src/package.g.ts"
7
- /*!**************************!*\
8
- !*** ./src/package.g.ts ***!
9
- \**************************/
10
- (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
11
-
12
- __webpack_require__.r(__webpack_exports__);
13
-
14
-
15
-
16
- /***/ },
17
-
18
- /***/ "datagrok-api/dg"
19
- /*!*********************!*\
20
- !*** external "DG" ***!
21
- \*********************/
22
- (module) {
23
-
24
- module.exports = DG;
25
-
26
- /***/ },
27
-
28
- /***/ "datagrok-api/grok"
29
- /*!***********************!*\
30
- !*** external "grok" ***!
31
- \***********************/
32
- (module) {
33
-
34
- module.exports = grok;
35
-
36
- /***/ }
37
-
38
- /******/ });
39
- /************************************************************************/
40
- /******/ // The module cache
41
- /******/ var __webpack_module_cache__ = {};
42
- /******/
43
- /******/ // The require function
44
- /******/ function __webpack_require__(moduleId) {
45
- /******/ // Check if module is in cache
46
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
47
- /******/ if (cachedModule !== undefined) {
48
- /******/ return cachedModule.exports;
49
- /******/ }
50
- /******/ // Create a new module (and put it into the cache)
51
- /******/ var module = __webpack_module_cache__[moduleId] = {
52
- /******/ // no module.id needed
53
- /******/ // no module.loaded needed
54
- /******/ exports: {}
55
- /******/ };
56
- /******/
57
- /******/ // Execute the module function
58
- /******/ if (!(moduleId in __webpack_modules__)) {
59
- /******/ delete __webpack_module_cache__[moduleId];
60
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
61
- /******/ e.code = 'MODULE_NOT_FOUND';
62
- /******/ throw e;
63
- /******/ }
64
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
65
- /******/
66
- /******/ // Return the exports of the module
67
- /******/ return module.exports;
68
- /******/ }
69
- /******/
70
- /************************************************************************/
71
- /******/ /* webpack/runtime/compat get default export */
72
- /******/ (() => {
73
- /******/ // getDefaultExport function for compatibility with non-harmony modules
74
- /******/ __webpack_require__.n = (module) => {
75
- /******/ var getter = module && module.__esModule ?
76
- /******/ () => (module['default']) :
77
- /******/ () => (module);
78
- /******/ __webpack_require__.d(getter, { a: getter });
79
- /******/ return getter;
80
- /******/ };
81
- /******/ })();
82
- /******/
83
- /******/ /* webpack/runtime/define property getters */
84
- /******/ (() => {
85
- /******/ // define getter functions for harmony exports
86
- /******/ __webpack_require__.d = (exports, definition) => {
87
- /******/ for(var key in definition) {
88
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
89
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
90
- /******/ }
91
- /******/ }
92
- /******/ };
93
- /******/ })();
94
- /******/
95
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
96
- /******/ (() => {
97
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
98
- /******/ })();
99
- /******/
100
- /******/ /* webpack/runtime/make namespace object */
101
- /******/ (() => {
102
- /******/ // define __esModule on exports
103
- /******/ __webpack_require__.r = (exports) => {
104
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
105
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
106
- /******/ }
107
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
108
- /******/ };
109
- /******/ })();
110
- /******/
111
- /************************************************************************/
112
- var __webpack_exports__ = {};
113
- // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
114
- (() => {
115
- /*!************************!*\
116
- !*** ./src/package.ts ***!
117
- \************************/
118
- __webpack_require__.r(__webpack_exports__);
119
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
120
- /* harmony export */ PackageFunctions: () => (/* binding */ PackageFunctions),
121
- /* harmony export */ _package: () => (/* binding */ _package),
122
- /* harmony export */ info: () => (/* binding */ info)
123
- /* harmony export */ });
124
- /* harmony import */ var datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! datagrok-api/grok */ "datagrok-api/grok");
125
- /* harmony import */ var datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__);
126
- /* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! datagrok-api/dg */ "datagrok-api/dg");
127
- /* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__);
128
- /* harmony import */ var _package_g__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./package.g */ "./src/package.g.ts");
129
- /* eslint-disable max-len */
130
- /* Do not change these import lines to match external modules in webpack configuration */
131
-
132
-
133
-
134
- const _package = new datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__.Package();
135
- //name: info
136
- function info() {
137
- datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.info(_package.webRoot);
138
- }
139
- class PackageFunctions {
140
- }
141
-
142
- })();
143
-
144
- proteomics = __webpack_exports__;
145
- /******/ })()
146
- ;
1
+ var proteomics;(()=>{var e={749(e,t,n){"use strict";n.d(t,{bk:()=>a,cb:()=>i}),n(982),DG.DataFrame.fromCsv('countries,fasta,smiles,molregno,LON,Zip Code,Street Address Line 1,ImageUrl,user_id,error_message,xray,flag,magnitude,CS-id,pdb_id,accel_a,time_offset,chart,fit,Questions,empty_number,empty_string\nBelgium,MSNFHNEHVMQFYRNNLKTKGVFGRQ,CC(C(=O)OCCCc1cccnc1)c2cccc(c2)C(=O)c3ccccc3,1480014,36.276729583740234,995042300,14016 ROUTE 31W,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,1,1,1QBS,1,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[2.497360340644872, 1.7058694986686864, 5.278052678195135, 0.16000320889028383],""points"":[{""x"":0.10000000149011612,""y"":2.374499797821045},{""x"":0.6000000238418579,""y"":2.6242473125457764},{""x"":1.100000023841858,""y"":2.367267608642578},{""x"":1.600000023841858,""y"":2.6723148822784424},{""x"":2.0999999046325684,""y"":2.6537344455718994},{""x"":2.5999999046325684,""y"":2.3651671409606934},{""x"":3.0999999046325684,""y"":2.5654284954071045},{""x"":3.5999999046325684,""y"":2.4160959720611572},{""x"":4.099999904632568,""y"":2.286726713180542},{""x"":4.599999904632568,""y"":2.5100042819976807},{""x"":5.099999904632568,""y"":1.6676985025405884},{""x"":5.599999904632568,""y"":0.680136501789093},{""x"":6.099999904632568,""y"":0.3391543924808502},{""x"":6.599999904632568,""y"":0.09038983285427094},{""x"":7.099999904632568,""y"":0.19802775979042053}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[7.525235855508179, 1.3186911876809984, 5.335672608564294, 0.7860743343958098],""points"":[{""x"":0.10000000149011612,""y"":7.988070487976074},{""x"":0.6000000238418579,""y"":7.018453121185303},{""x"":1.100000023841858,""y"":8.115279197692871},{""x"":1.600000023841858,""y"":7.486658096313477},{""x"":2.0999999046325684,""y"":7.396438121795654},{""x"":2.5999999046325684,""y"":7.477052211761475},{""x"":3.0999999046325684,""y"":6.913095474243164},{""x"":3.5999999046325684,""y"":8.01385498046875},{""x"":4.099999904632568,""y"":6.985900402069092},{""x"":4.599999904632568,""y"":6.970335960388184},{""x"":5.099999904632568,""y"":5.448817253112793},{""x"":5.599999904632568,""y"":2.5534818172454834},{""x"":6.099999904632568,""y"":1.893947958946228},{""x"":6.599999904632568,""y"":0.6340042352676392},{""x"":7.099999904632568,""y"":0.8403874039649963}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,100,abc\nBurundi,MDYKETLLMPKTDFPMRGGLPNKEPQIQEKW,COc1ccc2cc(ccc2c1)C(C)C(=O)Oc3ccc(C)cc3OC,1480015,36.276729583740234,995073444,80 STATE HIGHWAY 310,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,2,2,1ZP8,2,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[4.431460753103398, 2.1691498799246745, 5.266445597102774, 0.7825762827017926],""points"":[{""x"":0.10000000149011612,""y"":4.751083850860596},{""x"":0.6000000238418579,""y"":4.203000068664551},{""x"":1.100000023841858,""y"":4.415858745574951},{""x"":1.600000023841858,""y"":4.68414306640625},{""x"":2.0999999046325684,""y"":4.198400974273682},{""x"":2.5999999046325684,""y"":4.179222106933594},{""x"":3.0999999046325684,""y"":4.638473987579346},{""x"":3.5999999046325684,""y"":4.708553314208984},{""x"":4.099999904632568,""y"":4.291589260101318},{""x"":4.599999904632568,""y"":4.038082599639893},{""x"":5.099999904632568,""y"":3.4349939823150635},{""x"":5.599999904632568,""y"":1.2194708585739136},{""x"":6.099999904632568,""y"":1.1920831203460693},{""x"":6.599999904632568,""y"":0.5352635979652405},{""x"":7.099999904632568,""y"":0.3346920311450958}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[2.339458017970126, -1.0734184310171178, 4.746332950550934, 0.2482416857595658],""points"":[{""x"":0.10000000149011612,""y"":0.2139337658882141},{""x"":0.6000000238418579,""y"":0.4269562065601349},{""x"":1.100000023841858,""y"":0.2441573292016983},{""x"":1.600000023841858,""y"":0.146635964512825},{""x"":2.0999999046325684,""y"":0.08818462491035461},{""x"":2.5999999046325684,""y"":0.2560656666755676},{""x"":3.0999999046325684,""y"":0.42434045672416687},{""x"":3.5999999046325684,""y"":0.37111231684684753},{""x"":4.099999904632568,""y"":0.5581737160682678},{""x"":4.599999904632568,""y"":1.183590054512024},{""x"":5.099999904632568,""y"":1.5629843473434448},{""x"":5.599999904632568,""y"":2.3211288452148438},{""x"":6.099999904632568,""y"":2.229961633682251},{""x"":6.599999904632568,""y"":2.2560226917266846},{""x"":7.099999904632568,""y"":2.2142398357391357}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nCameroon,MIEVFLFGIVLGLIPITLAGLFVTAYLQYRRGDQLDL,COc1ccc2cc(ccc2c1)C(C)C(=O)OCCCc3cccnc3,1480016,36.26095962524414,995153596,30-56 WHITESTONE EXPY,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,3,3,2BDJ,3,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[4.6760652578642325, 0.9046956320756703, 5.651408971856738, 0.07738846012184185],""points"":[{""x"":0.10000000149011612,""y"":4.32425594329834},{""x"":0.6000000238418579,""y"":4.668442249298096},{""x"":1.100000023841858,""y"":4.379785060882568},{""x"":1.600000023841858,""y"":5.0345139503479},{""x"":2.0999999046325684,""y"":4.878653526306152},{""x"":2.5999999046325684,""y"":4.3451313972473145},{""x"":3.0999999046325684,""y"":4.336992263793945},{""x"":3.5999999046325684,""y"":5.037430286407471},{""x"":4.099999904632568,""y"":5.0092692375183105},{""x"":4.599999904632568,""y"":4.151902675628662},{""x"":5.099999904632568,""y"":3.4066951274871826},{""x"":5.599999904632568,""y"":2.3732759952545166},{""x"":6.099999904632568,""y"":1.673728108406067},{""x"":6.599999904632568,""y"":0.48574790358543396},{""x"":7.099999904632568,""y"":0.2783052325248718}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[2.938395863010111, -1.4658480661392117, 5.462702751996584, 0.3473139023615039],""points"":[{""x"":0.10000000149011612,""y"":0.4941710829734802},{""x"":0.6000000238418579,""y"":0.15323974192142487},{""x"":1.100000023841858,""y"":0.46373432874679565},{""x"":1.600000023841858,""y"":0.3370431363582611},{""x"":2.0999999046325684,""y"":0.5179030299186707},{""x"":2.5999999046325684,""y"":0.27899765968322754},{""x"":3.0999999046325684,""y"":0.22075064480304718},{""x"":3.5999999046325684,""y"":0.5789918899536133},{""x"":4.099999904632568,""y"":0.21169911324977875},{""x"":4.599999904632568,""y"":0.27857646346092224},{""x"":5.099999904632568,""y"":1.0906332731246948},{""x"":5.599999904632568,""y"":1.8520300388336182},{""x"":6.099999904632568,""y"":2.7177059650421143},{""x"":6.599999904632568,""y"":2.8680918216705322},{""x"":7.099999904632568,""y"":3.2413077354431152}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nCanada,MMELVLKTIIGPIVVGVVLRIVDKWLNKDK,CC(C(=O)NCCS)c1cccc(c1)C(=O)c2ccccc2,1480017,36.26095962524414,99515,30-56 WHITESTONE EXPY,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,4,4,1IAN,4,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[0.8597390975430008, 1.0957625732481946, 5.260537067987958, 0.07974187998177736],""points"":[{""x"":0.10000000149011612,""y"":0.8190152645111084},{""x"":0.6000000238418579,""y"":0.8421689867973328},{""x"":1.100000023841858,""y"":0.8740922212600708},{""x"":1.600000023841858,""y"":0.8924275040626526},{""x"":2.0999999046325684,""y"":0.8249067664146423},{""x"":2.5999999046325684,""y"":0.9327669143676758},{""x"":3.0999999046325684,""y"":0.8522974252700806},{""x"":3.5999999046325684,""y"":0.8174492716789246},{""x"":4.099999904632568,""y"":0.8394647240638733},{""x"":4.599999904632568,""y"":0.7139387726783752},{""x"":5.099999904632568,""y"":0.5561167597770691},{""x"":5.599999904632568,""y"":0.3276226818561554},{""x"":6.099999904632568,""y"":0.12479474395513535},{""x"":6.599999904632568,""y"":0.13006797432899475},{""x"":7.099999904632568,""y"":0.059702079743146896}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[5.760930219582546, 1.6591793293833013, 4.667155929720851, 0.7858109544121652],""points"":[{""x"":0.10000000149011612,""y"":6.156993389129639},{""x"":0.6000000238418579,""y"":5.236701965332031},{""x"":1.100000023841858,""y"":6.010560512542725},{""x"":1.600000023841858,""y"":5.495512962341309},{""x"":2.0999999046325684,""y"":6.087770462036133},{""x"":2.5999999046325684,""y"":5.79986572265625},{""x"":3.0999999046325684,""y"":5.597546577453613},{""x"":3.5999999046325684,""y"":5.520902156829834},{""x"":4.099999904632568,""y"":5.360654354095459},{""x"":4.599999904632568,""y"":3.5539746284484863},{""x"":5.099999904632568,""y"":1.577236294746399},{""x"":5.599999904632568,""y"":1.0001264810562134},{""x"":6.099999904632568,""y"":0.9305797815322876},{""x"":6.599999904632568,""y"":0.6033638715744019},{""x"":7.099999904632568,""y"":0.4203685522079468}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nColombia,MDRTDEVSNHTHDKPTLTWFEEIFEEYHSPFHN,FC(F)(F)c1ccc(OC2CCNCC2)cc1,1480029,36.3309440612793,995152050,1 COURT HOUSE SQUARE,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,5,5,4UJ1,5,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[6.4995088314153655, 2.4270351004539914, 5.178659535348579, 0.625653346241577],""points"":[{""x"":0.10000000149011612,""y"":6.496231555938721},{""x"":0.6000000238418579,""y"":6.42543363571167},{""x"":1.100000023841858,""y"":7.040063858032227},{""x"":1.600000023841858,""y"":6.1115403175354},{""x"":2.0999999046325684,""y"":6.680728435516357},{""x"":2.5999999046325684,""y"":6.406774520874023},{""x"":3.0999999046325684,""y"":6.611269474029541},{""x"":3.5999999046325684,""y"":5.889094352722168},{""x"":4.099999904632568,""y"":6.75344705581665},{""x"":4.599999904632568,""y"":6.361435890197754},{""x"":5.099999904632568,""y"":4.1666975021362305},{""x"":5.599999904632568,""y"":1.172118902206421},{""x"":6.099999904632568,""y"":0.801048994064331},{""x"":6.599999904632568,""y"":0.4640021026134491},{""x"":7.099999904632568,""y"":0.0010357667924836278}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[1.4734381347446401, 1.1649805188074196, 4.82958608866421, 0.09500545496710007],""points"":[{""x"":0.10000000149011612,""y"":1.5279096364974976},{""x"":0.6000000238418579,""y"":1.3559974431991577},{""x"":1.100000023841858,""y"":1.5246378183364868},{""x"":1.600000023841858,""y"":1.5567657947540283},{""x"":2.0999999046325684,""y"":1.4114240407943726},{""x"":2.5999999046325684,""y"":1.4045010805130005},{""x"":3.0999999046325684,""y"":1.4769829511642456},{""x"":3.5999999046325684,""y"":1.4875500202178955},{""x"":4.099999904632568,""y"":1.2991987466812134},{""x"":4.599999904632568,""y"":0.922961413860321},{""x"":5.099999904632568,""y"":0.6520044803619385},{""x"":5.599999904632568,""y"":0.15350978076457977},{""x"":6.099999904632568,""y"":0.1078903079032898},{""x"":6.599999904632568,""y"":0.17276449501514435},{""x"":7.099999904632568,""y"":0.14066608250141144}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nCosta Rica,MKSTKEEIQTIKTLLKDSRTAKYHKRLQIVL,CC(C)Cc1ccc(cc1)C(C)C(=O)N2CCCC2C(=O)OCCCc3ccccc3,1480018,36.3309440612793,995084218,4041 SOUTHWESTERN BLVD,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,6,6,2BPW,6,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[2.4833641843311227, -1.8945978742090062, 4.671127708092568, 0.24159861311815153],""points"":[{""x"":0.10000000149011612,""y"":0.0969524160027504},{""x"":0.6000000238418579,""y"":0.028483040630817413},{""x"":1.100000023841858,""y"":0.22087176144123077},{""x"":1.600000023841858,""y"":0.0068915546871721745},{""x"":2.0999999046325684,""y"":0.4305879771709442},{""x"":2.5999999046325684,""y"":0.44774115085601807},{""x"":3.0999999046325684,""y"":0.45346319675445557},{""x"":3.5999999046325684,""y"":0.2370593100786209},{""x"":4.099999904632568,""y"":0.4657953977584839},{""x"":4.599999904632568,""y"":1.155200719833374},{""x"":5.099999904632568,""y"":2.2294070720672607},{""x"":5.599999904632568,""y"":2.4311530590057373},{""x"":6.099999904632568,""y"":2.33846116065979},{""x"":6.599999904632568,""y"":2.608201026916504},{""x"":7.099999904632568,""y"":2.8136143684387207}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[5.224573521642033, 1.4454033924198528, 5.6014197746076535, 0.2823216054197577],""points"":[{""x"":0.10000000149011612,""y"":4.95027494430542},{""x"":0.6000000238418579,""y"":5.1754679679870605},{""x"":1.100000023841858,""y"":5.276752948760986},{""x"":1.600000023841858,""y"":5.589294910430908},{""x"":2.0999999046325684,""y"":5.616994857788086},{""x"":2.5999999046325684,""y"":5.120813846588135},{""x"":3.0999999046325684,""y"":5.340766906738281},{""x"":3.5999999046325684,""y"":4.876471042633057},{""x"":4.099999904632568,""y"":4.94999361038208},{""x"":4.599999904632568,""y"":5.162564754486084},{""x"":5.099999904632568,""y"":4.399557590484619},{""x"":5.599999904632568,""y"":2.7977969646453857},{""x"":6.099999904632568,""y"":1.0229872465133667},{""x"":6.599999904632568,""y"":0.48275601863861084},{""x"":7.099999904632568,""y"":0.10408931970596313}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nCuba,MHAILRYFIRRLFYHIFYKIYSLISKKHQSLPSDVRQF,COc1ccc2c(c1)c(CC(=O)N3CCCC3C(=O)Oc4ccc(C)cc4OC)c(C)n2C(=O)c5ccc(Cl)cc5,1480019,36.33115768432617,995081928,1227 US HIGHWAY 11,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,7,7,1QBS,7,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[3.320838679713925, -1.2421619987316728, 4.831325425225256, 0.3236011098403072],""points"":[{""x"":0.10000000149011612,""y"":0.3727470338344574},{""x"":0.6000000238418579,""y"":0.12365014106035233},{""x"":1.100000023841858,""y"":0.48422467708587646},{""x"":1.600000023841858,""y"":0.2264465093612671},{""x"":2.0999999046325684,""y"":0.16821794211864471},{""x"":2.5999999046325684,""y"":0.3879014551639557},{""x"":3.0999999046325684,""y"":0.5470244884490967},{""x"":3.5999999046325684,""y"":0.3419053554534912},{""x"":4.099999904632568,""y"":0.7655120491981506},{""x"":4.599999904632568,""y"":1.2346516847610474},{""x"":5.099999904632568,""y"":2.453336715698242},{""x"":5.599999904632568,""y"":2.9565491676330566},{""x"":6.099999904632568,""y"":3.335299491882324},{""x"":6.599999904632568,""y"":3.240290880203247},{""x"":7.099999904632568,""y"":3.1107218265533447}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[3.6401853521511094, 1.26211588875013, 5.399028074402744, 0.5089580830068091],""points"":[{""x"":0.10000000149011612,""y"":3.8585598468780518},{""x"":0.6000000238418579,""y"":3.6077206134796143},{""x"":1.100000023841858,""y"":3.855252265930176},{""x"":1.600000023841858,""y"":3.619039297103882},{""x"":2.0999999046325684,""y"":3.839388370513916},{""x"":2.5999999046325684,""y"":3.335283041000366},{""x"":3.0999999046325684,""y"":3.571141481399536},{""x"":3.5999999046325684,""y"":3.4155046939849854},{""x"":4.099999904632568,""y"":3.7316646575927734},{""x"":4.599999904632568,""y"":3.0680155754089355},{""x"":5.099999904632568,""y"":2.891066551208496},{""x"":5.599999904632568,""y"":1.6022753715515137},{""x"":6.099999904632568,""y"":0.7652576565742493},{""x"":6.599999904632568,""y"":0.6875326037406921},{""x"":7.099999904632568,""y"":0.5828871726989746}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nItaly,MSNFHNEHVMQFYRNNLKTKGVFGRQ,CC(C)Cc1ccc(cc1)C(C)C(=O)N2CCCC2C(=O)OCCO[N+](=O)[O-],1480020,36.33115768432617,99502,"168-46 91ST AVE., 2ND FLR",https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,8,8,1ZP8,8,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[2.293592105923809, 1.3781586549141835, 5.1025898038676605, 0.03493851245291291],""points"":[{""x"":0.10000000149011612,""y"":2.1287283897399902},{""x"":0.6000000238418579,""y"":2.267972230911255},{""x"":1.100000023841858,""y"":2.398442506790161},{""x"":1.600000023841858,""y"":2.5130622386932373},{""x"":2.0999999046325684,""y"":2.3255116939544678},{""x"":2.5999999046325684,""y"":2.127340793609619},{""x"":3.0999999046325684,""y"":2.47259783744812},{""x"":3.5999999046325684,""y"":2.131181478500366},{""x"":4.099999904632568,""y"":2.090421438217163},{""x"":4.599999904632568,""y"":2.02299165725708},{""x"":5.099999904632568,""y"":1.1105059385299683},{""x"":5.599999904632568,""y"":0.4494485855102539},{""x"":6.099999904632568,""y"":0.1375635862350464},{""x"":6.599999904632568,""y"":0.036351121962070465},{""x"":7.099999904632568,""y"":0.1619771122932434}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[5.953125499439879, 1.2528620255306528, 5.187637440149802, 0.3110348753260886],""points"":[{""x"":0.10000000149011612,""y"":5.6585283279418945},{""x"":0.6000000238418579,""y"":5.911152362823486},{""x"":1.100000023841858,""y"":5.924920082092285},{""x"":1.600000023841858,""y"":5.8469438552856445},{""x"":2.0999999046325684,""y"":5.929472923278809},{""x"":2.5999999046325684,""y"":6.190037727355957},{""x"":3.0999999046325684,""y"":6.236179828643799},{""x"":3.5999999046325684,""y"":6.141019344329834},{""x"":4.099999904632568,""y"":5.295210838317871},{""x"":4.599999904632568,""y"":5.265801906585693},{""x"":5.099999904632568,""y"":3.3722851276397705},{""x"":5.599999904632568,""y"":1.8299226760864258},{""x"":6.099999904632568,""y"":0.32690900564193726},{""x"":6.599999904632568,""y"":0.6274543404579163},{""x"":7.099999904632568,""y"":0.8441857099533081}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nRwanda,MPNSEPASLLELFNSIATQGELVRSLKAGNASK,CC(C)Cc1ccc(cc1)C(C)C(=O)N2CCCC2C(=O)OCCO,1480021,36.33137130737305,995037247,"168-46 91ST AVE., 2ND FLR",https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,9,9,2BDJ,9,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[3.8209972202654474, 1.3779216716448506, 5.299882228439686, 0.06040645519069608],""points"":[{""x"":0.10000000149011612,""y"":3.7821109294891357},{""x"":0.6000000238418579,""y"":3.542433023452759},{""x"":1.100000023841858,""y"":3.7008674144744873},{""x"":1.600000023841858,""y"":3.717301607131958},{""x"":2.0999999046325684,""y"":4.024452209472656},{""x"":2.5999999046325684,""y"":4.013899326324463},{""x"":3.0999999046325684,""y"":3.945094347000122},{""x"":3.5999999046325684,""y"":3.866621971130371},{""x"":4.099999904632568,""y"":3.7461626529693604},{""x"":4.599999904632568,""y"":3.3454740047454834},{""x"":5.099999904632568,""y"":2.61944317817688},{""x"":5.599999904632568,""y"":0.999405026435852},{""x"":6.099999904632568,""y"":0.46259793639183044},{""x"":6.599999904632568,""y"":0.054134611040353775},{""x"":7.099999904632568,""y"":0.05711187422275543}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[5.6318079657726035, 1.8495493770000595, 5.391793312471116, 0.17060707587348442],""points"":[{""x"":0.10000000149011612,""y"":5.458079814910889},{""x"":0.6000000238418579,""y"":5.554427146911621},{""x"":1.100000023841858,""y"":5.799983024597168},{""x"":1.600000023841858,""y"":5.364140033721924},{""x"":2.0999999046325684,""y"":5.864485740661621},{""x"":2.5999999046325684,""y"":5.4509806632995605},{""x"":3.0999999046325684,""y"":5.702574729919434},{""x"":3.5999999046325684,""y"":5.7314534187316895},{""x"":4.099999904632568,""y"":5.5123443603515625},{""x"":4.599999904632568,""y"":5.724395751953125},{""x"":5.099999904632568,""y"":4.354506969451904},{""x"":5.599999904632568,""y"":1.7307666540145874},{""x"":6.099999904632568,""y"":0.6305936574935913},{""x"":6.599999904632568,""y"":0.035183437168598175},{""x"":7.099999904632568,""y"":0.7575169205665588}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\nSwitzerland,IRVVGRYLIEVWKAAGMDMDKVLFLWSSDEI,CN1CCC(CC1)Oc2ccc(cc2)C(F)(F)F,1480028,36.33137130737305,99504,92-11 179TH PLACE,https://datagrok.ai/img/slides/access-db-connect.png,id,ErrorMessage,"COMPND \nATOM \nEND",flag,9,10,1IAN,10,1.23,<chart></chart>,"{""series"":[{""name"":""Run:2023-08-08"",""fitFunction"":""sigmoid"",""fitLineColor"":""#1f77b4"",""pointColor"":""#1f77b4"",""showPoints"":""points"",""parameters"":[1.1190255865097471, 2.3163895161544437, 5.4968866182279195, 0.2035204047289052],""points"":[{""x"":0.10000000149011612,""y"":1.1057683229446411},{""x"":0.6000000238418579,""y"":1.1019697189331055},{""x"":1.100000023841858,""y"":1.0818607807159424},{""x"":1.600000023841858,""y"":1.062997817993164},{""x"":2.0999999046325684,""y"":1.046447515487671},{""x"":2.5999999046325684,""y"":1.1217249631881714},{""x"":3.0999999046325684,""y"":1.2166996002197266},{""x"":3.5999999046325684,""y"":1.215477705001831},{""x"":4.099999904632568,""y"":1.0581893920898438},{""x"":4.599999904632568,""y"":1.1747995615005493},{""x"":5.099999904632568,""y"":1.0181127786636353},{""x"":5.599999904632568,""y"":0.5344523191452026},{""x"":6.099999904632568,""y"":0.2569526433944702},{""x"":6.599999904632568,""y"":0.1912207305431366},{""x"":7.099999904632568,""y"":0.15060538053512573}]},{""name"":""Run:2023-08-08"",""fitLineColor"":""#ffbb78"",""pointColor"":""#ffbb78"",""showPoints"":""points"",""parameters"":[3.1038581025805785, 2.0032224204185245, 5.087602825989163, 0.13277988512492753],""points"":[{""x"":0.10000000149011612,""y"":3.0498509407043457},{""x"":0.6000000238418579,""y"":2.805217742919922},{""x"":1.100000023841858,""y"":3.3415253162384033},{""x"":1.600000023841858,""y"":3.0549843311309814},{""x"":2.0999999046325684,""y"":3.250074863433838},{""x"":2.5999999046325684,""y"":3.0432586669921875},{""x"":3.0999999046325684,""y"":3.265852451324463},{""x"":3.5999999046325684,""y"":2.9475724697113037},{""x"":4.099999904632568,""y"":3.1929898262023926},{""x"":4.599999904632568,""y"":2.7460060119628906},{""x"":5.099999904632568,""y"":1.6175861358642578},{""x"":5.599999904632568,""y"":0.3006608486175537},{""x"":6.099999904632568,""y"":0.3444803059101105},{""x"":6.599999904632568,""y"":0.015537971630692482},{""x"":7.099999904632568,""y"":0.5527358055114746}]}],""chartOptions"":{""xAxisName"":""Conc."",""yAxisName"":""Activity"",""title"":""Dose-Response curves""}}",text,,\n,,,,,,,,,,,,,,,,,,,,,').columns.add(DG.Column.fromList(DG.TYPE.BYTE_ARRAY,"BinaryImage",Array.from(new Uint8Array(11))));var r,o=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}l((r=r.apply(e,t||[])).next())})};function i(e){return o(this,void 0,void 0,function*(){yield new Promise(t=>setTimeout(t,e))})}function a(e,t="Timeout exceeded",n=500,r=50){return o(this,void 0,void 0,function*(){return new Promise((o,i)=>{setTimeout(()=>{clearInterval(a),i(new Error(t))},n);const a=setInterval(()=>{e()&&(clearInterval(a),o(null))},r)})})}console.log.bind(console),console.info.bind(console),console.warn.bind(console),console.error.bind(console),function(e){e.notNull=function(e,t){if(null==e)throw new Error(`${t??"Value"} not defined`)}}(r||(r={})),DG.DataFrame.fromColumns([DG.Column.fromStrings("col",["val1","val2","val3"])])},353(e){e.exports=function(){"use strict";var e=6e4,t=36e5,n="millisecond",r="second",o="minute",i="hour",a="day",s="week",l="month",c="quarter",u="year",f="date",p="Invalid Date",d=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,m=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},g=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},y={s:g,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),o=n%60;return(t<=0?"+":"-")+g(r,2,"0")+":"+g(o,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),o=t.clone().add(r,l),i=n-o<0,a=t.clone().add(r+(i?-1:1),l);return+(-(r+(n-o)/(i?o-a:a-o))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:u,w:s,d:a,D:f,h:i,m:o,s:r,ms:n,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},w="en",v={};v[w]=h;var b="$isDayjsObject",_=function(e){return e instanceof S||!(!e||!e[b])},x=function e(t,n,r){var o;if(!t)return w;if("string"==typeof t){var i=t.toLowerCase();v[i]&&(o=i),n&&(v[i]=n,o=i);var a=t.split("-");if(!o&&a.length>1)return e(a[0])}else{var s=t.name;v[s]=t,o=s}return!r&&o&&(w=o),o||!r&&w},N=function(e,t){if(_(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new S(n)},C=y;C.l=x,C.i=_,C.w=function(e,t){return N(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var S=function(){function h(e){this.$L=x(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[b]=!0}var g=h.prototype;return g.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(C.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(d);if(r){var o=r[2]-1||0,i=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(t)}(e),this.init()},g.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},g.$utils=function(){return C},g.isValid=function(){return!(this.$d.toString()===p)},g.isSame=function(e,t){var n=N(e);return this.startOf(t)<=n&&n<=this.endOf(t)},g.isAfter=function(e,t){return N(e)<this.startOf(t)},g.isBefore=function(e,t){return this.endOf(t)<N(e)},g.$g=function(e,t,n){return C.u(e)?this[t]:this.set(n,e)},g.unix=function(){return Math.floor(this.valueOf()/1e3)},g.valueOf=function(){return this.$d.getTime()},g.startOf=function(e,t){var n=this,c=!!C.u(t)||t,p=C.p(e),d=function(e,t){var r=C.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return c?r:r.endOf(a)},m=function(e,t){return C.w(n.toDate()[e].apply(n.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},h=this.$W,g=this.$M,y=this.$D,w="set"+(this.$u?"UTC":"");switch(p){case u:return c?d(1,0):d(31,11);case l:return c?d(1,g):d(0,g+1);case s:var v=this.$locale().weekStart||0,b=(h<v?h+7:h)-v;return d(c?y-b:y+(6-b),g);case a:case f:return m(w+"Hours",0);case i:return m(w+"Minutes",1);case o:return m(w+"Seconds",2);case r:return m(w+"Milliseconds",3);default:return this.clone()}},g.endOf=function(e){return this.startOf(e,!1)},g.$set=function(e,t){var s,c=C.p(e),p="set"+(this.$u?"UTC":""),d=(s={},s[a]=p+"Date",s[f]=p+"Date",s[l]=p+"Month",s[u]=p+"FullYear",s[i]=p+"Hours",s[o]=p+"Minutes",s[r]=p+"Seconds",s[n]=p+"Milliseconds",s)[c],m=c===a?this.$D+(t-this.$W):t;if(c===l||c===u){var h=this.clone().set(f,1);h.$d[d](m),h.init(),this.$d=h.set(f,Math.min(this.$D,h.daysInMonth())).$d}else d&&this.$d[d](m);return this.init(),this},g.set=function(e,t){return this.clone().$set(e,t)},g.get=function(e){return this[C.p(e)]()},g.add=function(n,c){var f,p=this;n=Number(n);var d=C.p(c),m=function(e){var t=N(p);return C.w(t.date(t.date()+Math.round(e*n)),p)};if(d===l)return this.set(l,this.$M+n);if(d===u)return this.set(u,this.$y+n);if(d===a)return m(1);if(d===s)return m(7);var h=(f={},f[o]=e,f[i]=t,f[r]=1e3,f)[d]||1,g=this.$d.getTime()+n*h;return C.w(g,this)},g.subtract=function(e,t){return this.add(-1*e,t)},g.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||p;var r=e||"YYYY-MM-DDTHH:mm:ssZ",o=C.z(this),i=this.$H,a=this.$m,s=this.$M,l=n.weekdays,c=n.months,u=n.meridiem,f=function(e,n,o,i){return e&&(e[n]||e(t,r))||o[n].slice(0,i)},d=function(e){return C.s(i%12||12,e,"0")},h=u||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(m,function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return C.s(t.$y,4,"0");case"M":return s+1;case"MM":return C.s(s+1,2,"0");case"MMM":return f(n.monthsShort,s,c,3);case"MMMM":return f(c,s);case"D":return t.$D;case"DD":return C.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return f(n.weekdaysMin,t.$W,l,2);case"ddd":return f(n.weekdaysShort,t.$W,l,3);case"dddd":return l[t.$W];case"H":return String(i);case"HH":return C.s(i,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return h(i,a,!0);case"A":return h(i,a,!1);case"m":return String(a);case"mm":return C.s(a,2,"0");case"s":return String(t.$s);case"ss":return C.s(t.$s,2,"0");case"SSS":return C.s(t.$ms,3,"0");case"Z":return o}return null}(e)||o.replace(":","")})},g.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},g.diff=function(n,f,p){var d,m=this,h=C.p(f),g=N(n),y=(g.utcOffset()-this.utcOffset())*e,w=this-g,v=function(){return C.m(m,g)};switch(h){case u:d=v()/12;break;case l:d=v();break;case c:d=v()/3;break;case s:d=(w-y)/6048e5;break;case a:d=(w-y)/864e5;break;case i:d=w/t;break;case o:d=w/e;break;case r:d=w/1e3;break;default:d=w}return p?d:C.a(d)},g.daysInMonth=function(){return this.endOf(l).$D},g.$locale=function(){return v[this.$L]},g.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=x(e,t,!0);return r&&(n.$L=r),n},g.clone=function(){return C.w(this.$d,this)},g.toDate=function(){return new Date(this.valueOf())},g.toJSON=function(){return this.isValid()?this.toISOString():null},g.toISOString=function(){return this.$d.toISOString()},g.toString=function(){return this.$d.toUTCString()},h}(),T=S.prototype;return N.prototype=T,[["$ms",n],["$s",r],["$m",o],["$H",i],["$W",a],["$M",l],["$y",u],["$D",f]].forEach(function(e){T[e[1]]=function(t){return this.$g(t,e[0],e[1])}}),N.extend=function(e,t){return e.$i||(e(t,S,N),e.$i=!0),N},N.locale=x,N.isDayjs=_,N.unix=function(e){return N(1e3*e)},N.en=v[w],N.Ls=v,N.p={},N}()},982(e,t,n){var r;!function(){var t={};!function(e){"use strict";e.__esModule=!0,e.digestLength=32,e.blockSize=64;var t=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function n(e,n,r,o,i){for(var a,s,l,c,u,f,p,d,m,h,g,y,w;i>=64;){for(a=n[0],s=n[1],l=n[2],c=n[3],u=n[4],f=n[5],p=n[6],d=n[7],h=0;h<16;h++)g=o+4*h,e[h]=(255&r[g])<<24|(255&r[g+1])<<16|(255&r[g+2])<<8|255&r[g+3];for(h=16;h<64;h++)y=((m=e[h-2])>>>17|m<<15)^(m>>>19|m<<13)^m>>>10,w=((m=e[h-15])>>>7|m<<25)^(m>>>18|m<<14)^m>>>3,e[h]=(y+e[h-7]|0)+(w+e[h-16]|0);for(h=0;h<64;h++)y=(((u>>>6|u<<26)^(u>>>11|u<<21)^(u>>>25|u<<7))+(u&f^~u&p)|0)+(d+(t[h]+e[h]|0)|0)|0,w=((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+(a&s^a&l^s&l)|0,d=p,p=f,f=u,u=c+y|0,c=l,l=s,s=a,a=y+w|0;n[0]+=a,n[1]+=s,n[2]+=l,n[3]+=c,n[4]+=u,n[5]+=f,n[6]+=p,n[7]+=d,o+=64,i-=64}return o}var r=function(){function t(){this.digestLength=e.digestLength,this.blockSize=e.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return t.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},t.prototype.clean=function(){for(var e=0;e<this.buffer.length;e++)this.buffer[e]=0;for(e=0;e<this.temp.length;e++)this.temp[e]=0;this.reset()},t.prototype.update=function(e,t){if(void 0===t&&(t=e.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var r=0;if(this.bytesHashed+=t,this.bufferLength>0){for(;this.bufferLength<64&&t>0;)this.buffer[this.bufferLength++]=e[r++],t--;64===this.bufferLength&&(n(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(t>=64&&(r=n(this.temp,this.state,e,r,t),t%=64);t>0;)this.buffer[this.bufferLength++]=e[r++],t--;return this},t.prototype.finish=function(e){if(!this.finished){var t=this.bytesHashed,r=this.bufferLength,o=t/536870912|0,i=t<<3,a=t%64<56?64:128;this.buffer[r]=128;for(var s=r+1;s<a-8;s++)this.buffer[s]=0;this.buffer[a-8]=o>>>24&255,this.buffer[a-7]=o>>>16&255,this.buffer[a-6]=o>>>8&255,this.buffer[a-5]=o>>>0&255,this.buffer[a-4]=i>>>24&255,this.buffer[a-3]=i>>>16&255,this.buffer[a-2]=i>>>8&255,this.buffer[a-1]=i>>>0&255,n(this.temp,this.state,this.buffer,0,a),this.finished=!0}for(s=0;s<8;s++)e[4*s+0]=this.state[s]>>>24&255,e[4*s+1]=this.state[s]>>>16&255,e[4*s+2]=this.state[s]>>>8&255,e[4*s+3]=this.state[s]>>>0&255;return this},t.prototype.digest=function(){var e=new Uint8Array(this.digestLength);return this.finish(e),e},t.prototype._saveState=function(e){for(var t=0;t<this.state.length;t++)e[t]=this.state[t]},t.prototype._restoreState=function(e,t){for(var n=0;n<this.state.length;n++)this.state[n]=e[n];this.bytesHashed=t,this.finished=!1,this.bufferLength=0},t}();e.Hash=r;var o=function(){function e(e){this.inner=new r,this.outer=new r,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var t=new Uint8Array(this.blockSize);if(e.length>this.blockSize)(new r).update(e).finish(t).clean();else for(var n=0;n<e.length;n++)t[n]=e[n];for(n=0;n<t.length;n++)t[n]^=54;for(this.inner.update(t),n=0;n<t.length;n++)t[n]^=106;for(this.outer.update(t),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate),n=0;n<t.length;n++)t[n]=0}return e.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},e.prototype.clean=function(){for(var e=0;e<this.istate.length;e++)this.ostate[e]=this.istate[e]=0;this.inner.clean(),this.outer.clean()},e.prototype.update=function(e){return this.inner.update(e),this},e.prototype.finish=function(e){return this.outer.finished?this.outer.finish(e):(this.inner.finish(e),this.outer.update(e,this.digestLength).finish(e)),this},e.prototype.digest=function(){var e=new Uint8Array(this.digestLength);return this.finish(e),e},e}();function i(e){var t=(new r).update(e),n=t.digest();return t.clean(),n}function a(e,t){var n=new o(e).update(t),r=n.digest();return n.clean(),r}function s(e,t,n,r){var o=r[0];if(0===o)throw new Error("hkdf: cannot expand more");t.reset(),o>1&&t.update(e),n&&t.update(n),t.update(r),t.finish(e),r[0]++}e.HMAC=o,e.hash=i,e.default=i,e.hmac=a;var l=new Uint8Array(e.digestLength);e.hkdf=function(e,t,n,r){void 0===t&&(t=l),void 0===r&&(r=32);for(var i=new Uint8Array([1]),c=a(t,e),u=new o(c),f=new Uint8Array(u.digestLength),p=f.length,d=new Uint8Array(r),m=0;m<r;m++)p===f.length&&(s(f,u,n,i),p=0),d[m]=f[p++];return u.clean(),f.fill(0),i.fill(0),d},e.pbkdf2=function(e,t,n,r){for(var i=new o(e),a=i.digestLength,s=new Uint8Array(4),l=new Uint8Array(a),c=new Uint8Array(a),u=new Uint8Array(r),f=0;f*a<r;f++){var p=f+1;s[0]=p>>>24&255,s[1]=p>>>16&255,s[2]=p>>>8&255,s[3]=p>>>0&255,i.reset(),i.update(t),i.update(s),i.finish(c);for(var d=0;d<a;d++)l[d]=c[d];for(d=2;d<=n;d++){i.reset(),i.update(c).finish(c);for(var m=0;m<a;m++)l[m]^=c[m]}for(d=0;d<a&&f*a+d<r;d++)u[f*a+d]=l[d]}for(f=0;f<a;f++)l[f]=c[f]=0;for(f=0;f<4;f++)s[f]=0;return i.clean(),u}}(t);var o=t.default;for(var i in t)o[i]=t[i];"object"==typeof e.exports?e.exports=o:void 0===(r=function(){return o}.call(t,n,t,e))||(e.exports=r)}()},572(e){var t;e.exports=(t=function(e,t){var n=Array.prototype.concat,r=Array.prototype.slice,o=Object.prototype.toString;function i(t,n){var r=t>n?t:n;return e.pow(10,17-~~(e.log(r>0?r:-r)*e.LOG10E))}var a=Array.isArray||function(e){return"[object Array]"===o.call(e)};function s(e){return"[object Function]"===o.call(e)}function l(e){return"number"==typeof e&&e-e===0}function c(){return new c._init(arguments)}function u(){return 0}function f(){return 1}function p(e,t){return e===t?1:0}c.fn=c.prototype,c._init=function(e){if(a(e[0]))if(a(e[0][0])){s(e[1])&&(e[0]=c.map(e[0],e[1]));for(var t=0;t<e[0].length;t++)this[t]=e[0][t];this.length=e[0].length}else this[0]=s(e[1])?c.map(e[0],e[1]):e[0],this.length=1;else if(l(e[0]))this[0]=c.seq.apply(null,e),this.length=1;else{if(e[0]instanceof c)return c(e[0].toArray());this[0]=[],this.length=1}return this},c._init.prototype=c.prototype,c._init.constructor=c,c.utils={calcRdx:i,isArray:a,isFunction:s,isNumber:l,toVector:function(e){return n.apply([],e)}},c._random_fn=e.random,c.setRandom=function(e){if("function"!=typeof e)throw new TypeError("fn is not a function");c._random_fn=e},c.extend=function(e){var t,n;if(1===arguments.length){for(n in e)c[n]=e[n];return this}for(t=1;t<arguments.length;t++)for(n in arguments[t])e[n]=arguments[t][n];return e},c.rows=function(e){return e.length||1},c.cols=function(e){return e[0].length||1},c.dimensions=function(e){return{rows:c.rows(e),cols:c.cols(e)}},c.row=function(e,t){return a(t)?t.map(function(t){return c.row(e,t)}):e[t]},c.rowa=function(e,t){return c.row(e,t)},c.col=function(e,t){if(a(t)){var n=c.arange(e.length).map(function(){return new Array(t.length)});return t.forEach(function(t,r){c.arange(e.length).forEach(function(o){n[o][r]=e[o][t]})}),n}for(var r=new Array(e.length),o=0;o<e.length;o++)r[o]=[e[o][t]];return r},c.cola=function(e,t){return c.col(e,t).map(function(e){return e[0]})},c.diag=function(e){for(var t=c.rows(e),n=new Array(t),r=0;r<t;r++)n[r]=[e[r][r]];return n},c.antidiag=function(e){for(var t=c.rows(e)-1,n=new Array(t),r=0;t>=0;t--,r++)n[r]=[e[r][t]];return n},c.transpose=function(e){var t,n,r,o,i,s=[];for(a(e[0])||(e=[e]),n=e.length,r=e[0].length,i=0;i<r;i++){for(t=new Array(n),o=0;o<n;o++)t[o]=e[o][i];s.push(t)}return 1===s.length?s[0]:s},c.map=function(e,t,n){var r,o,i,s,l;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,s=n?e:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),l=0;l<i;l++)s[r][l]=t(e[r][l],r,l);return 1===s.length?s[0]:s},c.cumreduce=function(e,t,n){var r,o,i,s,l;for(a(e[0])||(e=[e]),o=e.length,i=e[0].length,s=n?e:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),i>0&&(s[r][0]=e[r][0]),l=1;l<i;l++)s[r][l]=t(s[r][l-1],e[r][l]);return 1===s.length?s[0]:s},c.alter=function(e,t){return c.map(e,t,!0)},c.create=function(e,t,n){var r,o,i=new Array(e);for(s(t)&&(n=t,t=e),r=0;r<e;r++)for(i[r]=new Array(t),o=0;o<t;o++)i[r][o]=n(r,o);return i},c.zeros=function(e,t){return l(t)||(t=e),c.create(e,t,u)},c.ones=function(e,t){return l(t)||(t=e),c.create(e,t,f)},c.rand=function(e,t){return l(t)||(t=e),c.create(e,t,c._random_fn)},c.identity=function(e,t){return l(t)||(t=e),c.create(e,t,p)},c.symmetric=function(e){var t,n,r=e.length;if(e.length!==e[0].length)return!1;for(t=0;t<r;t++)for(n=0;n<r;n++)if(e[n][t]!==e[t][n])return!1;return!0},c.clear=function(e){return c.alter(e,u)},c.seq=function(e,t,n,r){s(r)||(r=!1);var o,a=[],l=i(e,t),c=(t*l-e*l)/((n-1)*l),u=e;for(o=0;u<=t&&o<n;u=(e*l+c*l*++o)/l)a.push(r?r(u,o):u);return a},c.arange=function(e,n,r){var o,i=[];if(r=r||1,n===t&&(n=e,e=0),e===n||0===r)return[];if(e<n&&r<0)return[];if(e>n&&r>0)return[];if(r>0)for(o=e;o<n;o+=r)i.push(o);else for(o=e;o>n;o+=r)i.push(o);return i},c.slice=function(){function e(e,n,r,o){var i,a=[],s=e.length;if(n===t&&r===t&&o===t)return c.copy(e);if(o=o||1,(n=(n=n||0)>=0?n:s+n)===(r=(r=r||e.length)>=0?r:s+r)||0===o)return[];if(n<r&&o<0)return[];if(n>r&&o>0)return[];if(o>0)for(i=n;i<r;i+=o)a.push(e[i]);else for(i=n;i>r;i+=o)a.push(e[i]);return a}return function(t,n){var r,o;return l((n=n||{}).row)?l(n.col)?t[n.row][n.col]:e(c.rowa(t,n.row),(r=n.col||{}).start,r.end,r.step):l(n.col)?e(c.cola(t,n.col),(o=n.row||{}).start,o.end,o.step):(o=n.row||{},r=n.col||{},e(t,o.start,o.end,o.step).map(function(t){return e(t,r.start,r.end,r.step)}))}}(),c.sliceAssign=function(n,r,o){var i,a;if(l(r.row)){if(l(r.col))return n[r.row][r.col]=o;r.col=r.col||{},r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,i=c.arange(r.col.start,e.min(n.length,r.col.end),r.col.step);var s=r.row;return i.forEach(function(e,t){n[s][e]=o[t]}),n}if(l(r.col)){r.row=r.row||{},r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,a=c.arange(r.row.start,e.min(n[0].length,r.row.end),r.row.step);var u=r.col;return a.forEach(function(e,t){n[e][u]=o[t]}),n}return o[0].length===t&&(o=[o]),r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,a=c.arange(r.row.start,e.min(n.length,r.row.end),r.row.step),i=c.arange(r.col.start,e.min(n[0].length,r.col.end),r.col.step),a.forEach(function(e,t){i.forEach(function(r,i){n[e][r]=o[t][i]})}),n},c.diagonal=function(e){var t=c.zeros(e.length,e.length);return e.forEach(function(e,n){t[n][n]=e}),t},c.copy=function(e){return e.map(function(e){return l(e)?e:e.map(function(e){return e})})};var d=c.prototype;return d.length=0,d.push=Array.prototype.push,d.sort=Array.prototype.sort,d.splice=Array.prototype.splice,d.slice=Array.prototype.slice,d.toArray=function(){return this.length>1?r.call(this):r.call(this)[0]},d.map=function(e,t){return c(c.map(this,e,t))},d.cumreduce=function(e,t){return c(c.cumreduce(this,e,t))},d.alter=function(e){return c.alter(this,e),this},function(e){for(var t=0;t<e.length;t++)(function(e){d[e]=function(t){var n,r=this;return t?(setTimeout(function(){t.call(r,d[e].call(r))}),this):(n=c[e](this),a(n)?c(n):n)}})(e[t])}("transpose clear symmetric rows cols dimensions diag antidiag".split(" ")),function(e){for(var t=0;t<e.length;t++)(function(e){d[e]=function(t,n){var r=this;return n?(setTimeout(function(){n.call(r,d[e].call(r,t))}),this):c(c[e](this,t))}})(e[t])}("row col".split(" ")),function(e){for(var t=0;t<e.length;t++)(function(e){d[e]=function(){return c(c[e].apply(null,arguments))}})(e[t])}("create zeros ones rand identity".split(" ")),c}(Math),function(e,t){var n=e.utils.isFunction;function r(e,t){return e-t}function o(e,n,r){return t.max(n,t.min(e,r))}e.sum=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.sumsqrd=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n]*e[n];return t},e.sumsqerr=function(t){for(var n,r=e.mean(t),o=0,i=t.length;--i>=0;)o+=(n=t[i]-r)*n;return o},e.sumrow=function(e){for(var t=0,n=e.length;--n>=0;)t+=e[n];return t},e.product=function(e){for(var t=1,n=e.length;--n>=0;)t*=e[n];return t},e.min=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]<t&&(t=e[n]);return t},e.max=function(e){for(var t=e[0],n=0;++n<e.length;)e[n]>t&&(t=e[n]);return t},e.unique=function(e){for(var t={},n=[],r=0;r<e.length;r++)t[e[r]]||(t[e[r]]=!0,n.push(e[r]));return n},e.mean=function(t){return e.sum(t)/t.length},e.meansqerr=function(t){return e.sumsqerr(t)/t.length},e.geomean=function(n){var r=n.map(t.log),o=e.mean(r);return t.exp(o)},e.median=function(e){var t=e.length,n=e.slice().sort(r);return 1&t?n[t/2|0]:(n[t/2-1]+n[t/2])/2},e.cumsum=function(t){return e.cumreduce(t,function(e,t){return e+t})},e.cumprod=function(t){return e.cumreduce(t,function(e,t){return e*t})},e.diff=function(e){var t,n=[],r=e.length;for(t=1;t<r;t++)n.push(e[t]-e[t-1]);return n},e.rank=function(e){var t,n=[],o={};for(t=0;t<e.length;t++)o[l=e[t]]?o[l]++:(o[l]=1,n.push(l));var i=n.sort(r),a={},s=1;for(t=0;t<i.length;t++){var l,c=o[l=i[t]],u=(s+(s+c-1))/2;a[l]=u,s+=c}return e.map(function(e){return a[e]})},e.mode=function(e){var t,n=e.length,o=e.slice().sort(r),i=1,a=0,s=0,l=[];for(t=0;t<n;t++)o[t]===o[t+1]?i++:(i>a?(l=[o[t]],a=i,s=0):i===a&&(l.push(o[t]),s++),i=1);return 0===s?l[0]:l},e.range=function(t){return e.max(t)-e.min(t)},e.variance=function(t,n){return e.sumsqerr(t)/(t.length-(n?1:0))},e.pooledvariance=function(t){return t.reduce(function(t,n){return t+e.sumsqerr(n)},0)/(t.reduce(function(e,t){return e+t.length},0)-t.length)},e.deviation=function(t){for(var n=e.mean(t),r=t.length,o=new Array(r),i=0;i<r;i++)o[i]=t[i]-n;return o},e.stdev=function(n,r){return t.sqrt(e.variance(n,r))},e.pooledstdev=function(n){return t.sqrt(e.pooledvariance(n))},e.meandev=function(n){for(var r=e.mean(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.mean(o)},e.meddev=function(n){for(var r=e.median(n),o=[],i=n.length-1;i>=0;i--)o.push(t.abs(n[i]-r));return e.median(o)},e.coeffvar=function(t){return e.stdev(t)/e.mean(t)},e.quartiles=function(e){var n=e.length,o=e.slice().sort(r);return[o[t.round(n/4)-1],o[t.round(n/2)-1],o[t.round(3*n/4)-1]]},e.quantiles=function(e,n,i,a){var s,l,c,u,f,p=e.slice().sort(r),d=[n.length],m=e.length;for(void 0===i&&(i=3/8),void 0===a&&(a=3/8),s=0;s<n.length;s++)c=m*(l=n[s])+(i+l*(1-i-a)),u=t.floor(o(c,1,m-1)),f=o(c-u,0,1),d[s]=(1-f)*p[u-1]+f*p[u];return d},e.percentile=function(e,t,n){var o=e.slice().sort(r),i=t*(o.length+(n?1:-1))+(n?0:1),a=parseInt(i),s=i-a;return a+1<o.length?o[a-1]+s*(o[a]-o[a-1]):o[a-1]},e.percentileOfScore=function(e,t,n){var r,o,i=0,a=e.length,s=!1;for("strict"===n&&(s=!0),o=0;o<a;o++)r=e[o],(s&&r<t||!s&&r<=t)&&i++;return i/a},e.histogram=function(n,r){r=r||4;var o,i=e.min(n),a=(e.max(n)-i)/r,s=n.length,l=[];for(o=0;o<r;o++)l[o]=0;for(o=0;o<s;o++)l[t.min(t.floor((n[o]-i)/a),r-1)]+=1;return l},e.covariance=function(t,n){var r,o=e.mean(t),i=e.mean(n),a=t.length,s=new Array(a);for(r=0;r<a;r++)s[r]=(t[r]-o)*(n[r]-i);return e.sum(s)/(a-1)},e.corrcoeff=function(t,n){return e.covariance(t,n)/e.stdev(t,1)/e.stdev(n,1)},e.spearmancoeff=function(t,n){return t=e.rank(t),n=e.rank(n),e.corrcoeff(t,n)},e.stanMoment=function(n,r){for(var o=e.mean(n),i=e.stdev(n),a=n.length,s=0,l=0;l<a;l++)s+=t.pow((n[l]-o)/i,r);return s/n.length},e.skewness=function(t){return e.stanMoment(t,3)},e.kurtosis=function(t){return e.stanMoment(t,4)-3};var i=e.prototype;!function(t){for(var r=0;r<t.length;r++)(function(t){i[t]=function(r,o){var a=[],s=0,l=this;if(n(r)&&(o=r,r=!1),o)return setTimeout(function(){o.call(l,i[t].call(l,r))}),this;if(this.length>1){for(l=!0===r?this:this.transpose();s<l.length;s++)a[s]=e[t](l[s]);return a}return e[t](this[0],r)}})(t[r])}("cumsum cumprod".split(" ")),function(t){for(var r=0;r<t.length;r++)(function(t){i[t]=function(r,o){var a=[],s=0,l=this;if(n(r)&&(o=r,r=!1),o)return setTimeout(function(){o.call(l,i[t].call(l,r))}),this;if(this.length>1){for("sumrow"!==t&&(l=!0===r?this:this.transpose());s<l.length;s++)a[s]=e[t](l[s]);return!0===r?e[t](e.utils.toVector(a)):a}return e[t](this[0],r)}})(t[r])}("sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr geomean median diff rank mode range variance deviation stdev meandev meddev coeffvar quartiles histogram skewness kurtosis".split(" ")),function(t){for(var r=0;r<t.length;r++)(function(t){i[t]=function(){var r,o=[],a=0,s=this,l=Array.prototype.slice.call(arguments);if(n(l[l.length-1])){r=l[l.length-1];var c=l.slice(0,l.length-1);return setTimeout(function(){r.call(s,i[t].apply(s,c))}),this}r=void 0;var u=function(n){return e[t].apply(s,[n].concat(l))};if(this.length>1){for(s=s.transpose();a<s.length;a++)o[a]=u(s[a]);return o}return u(this[0])}})(t[r])}("quantiles percentileOfScore".split(" "))}(t,Math),function(e,t){e.gammaln=function(e){var n,r,o,i=0,a=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],s=1.000000000190015;for(o=(r=n=e)+5.5,o-=(n+.5)*t.log(o);i<6;i++)s+=a[i]/++r;return t.log(2.5066282746310007*s/n)-o},e.loggam=function(e){var n,r,o,i,a,s,l,c=[.08333333333333333,-.002777777777777778,.0007936507936507937,-.0005952380952380952,.0008417508417508418,-.001917526917526918,.00641025641025641,-.02955065359477124,.1796443723688307,-1.3924322169059];if(n=e,l=0,1==e||2==e)return 0;for(e<=7&&(n=e+(l=t.floor(7-e))),r=1/(n*n),o=2*t.PI,a=c[9],s=8;s>=0;s--)a*=r,a+=c[s];if(i=a/n+.5*t.log(o)+(n-.5)*t.log(n)-n,e<=7)for(s=1;s<=l;s++)i-=t.log(n-1),n-=1;return i},e.gammafn=function(e){var n,r,o,i,a=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],s=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],l=!1,c=0,u=0,f=0,p=e;if(e>171.6243769536076)return 1/0;if(p<=0){if(!(i=p%1+36e-17))return 1/0;l=(1&p?-1:1)*t.PI/t.sin(t.PI*i),p=1-p}for(o=p,r=p<1?p++:(p-=c=(0|p)-1)-1,n=0;n<8;++n)f=(f+a[n])*r,u=u*r+s[n];if(i=f/u+1,o<p)i/=o;else if(o>p)for(n=0;n<c;++n)i*=p,p++;return l&&(i=l/i),i},e.gammap=function(t,n){return e.lowRegGamma(t,n)*e.gammafn(t)},e.lowRegGamma=function(n,r){var o,i=e.gammaln(n),a=n,s=1/n,l=s,c=r+1-n,u=1/1e-30,f=1/c,p=f,d=1,m=-~(8.5*t.log(n>=1?n:1/n)+.4*n+17);if(r<0||n<=0)return NaN;if(r<n+1){for(;d<=m;d++)s+=l*=r/++a;return s*t.exp(-r+n*t.log(r)-i)}for(;d<=m;d++)p*=(f=1/(f=(o=-d*(d-n))*f+(c+=2)))*(u=c+o/u);return 1-p*t.exp(-r+n*t.log(r)-i)},e.factorialln=function(t){return t<0?NaN:e.gammaln(t+1)},e.factorial=function(t){return t<0?NaN:e.gammafn(t+1)},e.combination=function(n,r){return n>170||r>170?t.exp(e.combinationln(n,r)):e.factorial(n)/e.factorial(r)/e.factorial(n-r)},e.combinationln=function(t,n){return e.factorialln(t)-e.factorialln(n)-e.factorialln(t-n)},e.permutation=function(t,n){return e.factorial(t)/e.factorial(t-n)},e.betafn=function(n,r){if(!(n<=0||r<=0))return n+r>170?t.exp(e.betaln(n,r)):e.gammafn(n)*e.gammafn(r)/e.gammafn(n+r)},e.betaln=function(t,n){return e.gammaln(t)+e.gammaln(n)-e.gammaln(t+n)},e.betacf=function(e,n,r){var o,i,a,s,l=1e-30,c=1,u=n+r,f=n+1,p=n-1,d=1,m=1-u*e/f;for(t.abs(m)<l&&(m=l),s=m=1/m;c<=100&&(m=1+(i=c*(r-c)*e/((p+(o=2*c))*(n+o)))*m,t.abs(m)<l&&(m=l),d=1+i/d,t.abs(d)<l&&(d=l),s*=(m=1/m)*d,m=1+(i=-(n+c)*(u+c)*e/((n+o)*(f+o)))*m,t.abs(m)<l&&(m=l),d=1+i/d,t.abs(d)<l&&(d=l),s*=a=(m=1/m)*d,!(t.abs(a-1)<3e-7));c++);return s},e.gammapinv=function(n,r){var o,i,a,s,l,c,u=0,f=r-1,p=e.gammaln(r);if(n>=1)return t.max(100,r+100*t.sqrt(r));if(n<=0)return 0;for(r>1?(l=t.log(f),c=t.exp(f*(l-1)-p),s=n<.5?n:1-n,o=(2.30753+.27061*(i=t.sqrt(-2*t.log(s))))/(1+i*(.99229+.04481*i))-i,n<.5&&(o=-o),o=t.max(.001,r*t.pow(1-1/(9*r)-o/(3*t.sqrt(r)),3))):o=n<(i=1-r*(.253+.12*r))?t.pow(n/i,1/r):1-t.log(1-(n-i)/(1-i));u<12;u++){if(o<=0)return 0;if((o-=i=(a=(e.lowRegGamma(r,o)-n)/(i=r>1?c*t.exp(-(o-f)+f*(t.log(o)-l)):t.exp(-o+f*t.log(o)-p)))/(1-.5*t.min(1,a*((r-1)/o-1))))<=0&&(o=.5*(o+i)),t.abs(i)<1e-8*o)break}return o},e.erf=function(e){var n,r,o,i,a=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],s=a.length-1,l=!1,c=0,u=0;for(e<0&&(e=-e,l=!0),r=4*(n=2/(2+e))-2;s>0;s--)o=c,c=r*c-u+a[s],u=o;return i=n*t.exp(-e*e+.5*(a[0]+r*c)-u),l?i-1:1-i},e.erfc=function(t){return 1-e.erf(t)},e.erfcinv=function(n){var r,o,i,a,s=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,r=-.70711*((2.30753+.27061*(i=t.sqrt(-2*t.log(a/2))))/(1+i*(.99229+.04481*i))-i);s<2;s++)r+=(o=e.erfc(r)-a)/(1.1283791670955126*t.exp(-r*r)-r*o);return n<1?r:-r},e.ibetainv=function(n,r,o){var i,a,s,l,c,u,f,p,d,m,h=r-1,g=o-1,y=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&o>=1?(s=n<.5?n:1-n,u=(2.30753+.27061*(l=t.sqrt(-2*t.log(s))))/(1+l*(.99229+.04481*l))-l,n<.5&&(u=-u),f=(u*u-3)/6,p=2/(1/(2*r-1)+1/(2*o-1)),d=u*t.sqrt(f+p)/p-(1/(2*o-1)-1/(2*r-1))*(f+5/6-2/(3*p)),u=r/(r+o*t.exp(2*d))):(i=t.log(r/(r+o)),a=t.log(o/(r+o)),u=n<(l=t.exp(r*i)/r)/(d=l+(c=t.exp(o*a)/o))?t.pow(r*d*n,1/r):1-t.pow(o*d*(1-n),1/o)),m=-e.gammaln(r)-e.gammaln(o)+e.gammaln(r+o);y<10;y++){if(0===u||1===u)return u;if((u-=l=(c=(e.ibeta(u,r,o)-n)/(l=t.exp(h*t.log(u)+g*t.log(1-u)+m)))/(1-.5*t.min(1,c*(h/u-g/(1-u)))))<=0&&(u=.5*(u+l)),u>=1&&(u=.5*(u+l+1)),t.abs(l)<1e-8*u&&y>0)break}return u},e.ibeta=function(n,r,o){var i=0===n||1===n?0:t.exp(e.gammaln(r+o)-e.gammaln(r)-e.gammaln(o)+r*t.log(n)+o*t.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+o+2)?i*e.betacf(n,r,o)/r:1-i*e.betacf(1-n,o,r)/o)},e.randn=function(n,r){var o,i,a,s,l;if(r||(r=n),n)return e.create(n,r,function(){return e.randn()});do{o=e._random_fn(),i=1.7156*(e._random_fn()-.5),l=(a=o-.449871)*a+(s=t.abs(i)+.386595)*(.196*s-.25472*a)}while(l>.27597&&(l>.27846||i*i>-4*t.log(o)*o*o));return i/o},e.randg=function(n,r,o){var i,a,s,l,c,u,f=n;if(o||(o=r),n||(n=1),r)return(u=e.zeros(r,o)).alter(function(){return e.randg(n)}),u;n<1&&(n+=1),i=n-1/3,a=1/t.sqrt(9*i);do{do{l=1+a*(c=e.randn())}while(l<=0);l*=l*l,s=e._random_fn()}while(s>1-.331*t.pow(c,4)&&t.log(s)>.5*c*c+i*(1-l+t.log(l)));if(n==f)return i*l;do{s=e._random_fn()}while(0===s);return t.pow(s,1/f)*i*l},function(t){for(var n=0;n<t.length;n++)(function(t){e.fn[t]=function(){return e(e.map(this,function(n){return e[t](n)}))}})(t[n])}("gammaln gammafn factorial factorialln".split(" ")),function(t){for(var n=0;n<t.length;n++)(function(t){e.fn[t]=function(){return e(e[t].apply(null,arguments))}})(t[n])}("randn".split(" "))}(t,Math),function(e,t){function n(e,n,r,o){for(var i,a=0,s=1,l=1,c=1,u=0,f=0;t.abs((l-f)/l)>o;)f=l,s=c+(i=-(n+u)*(n+r+u)*e/(n+2*u)/(n+2*u+1))*s,l=(a=l+i*a)+(i=(u+=1)*(r-u)*e/(n+2*u-1)/(n+2*u))*l,a/=c=s+i*c,s/=c,l/=c,c=1;return l/n}function r(n,r,o){var i=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],a=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],s=.5*n;if(s>=8)return 1;var l,c=2*e.normal.cdf(s,0,1,1,0)-1;c=c>=t.exp(-50/o)?t.pow(c,o):0;for(var u=s,f=(8-s)/(l=n>3?2:3),p=u+f,d=0,m=o-1,h=1;h<=l;h++){for(var g=0,y=.5*(p+u),w=.5*(p-u),v=1;v<=12;v++){var b,_=y+w*(6<v?i[(b=12-v+1)-1]:-i[(b=v)-1]),x=_*_;if(x>60)break;var N=2*e.normal.cdf(_,0,1,1,0)*.5-2*e.normal.cdf(_,n,1,1,0)*.5;N>=t.exp(-30/m)&&(g+=N=a[b-1]*t.exp(-.5*x)*t.pow(N,m))}d+=g*=2*w*o/t.sqrt(2*t.PI),u=p,p+=f}return(c+=d)<=t.exp(-30/r)?0:(c=t.pow(c,r))>=1?1:c}!function(t){for(var n=0;n<t.length;n++)(function(t){e[t]=function e(t,n,r){return this instanceof e?(this._a=t,this._b=n,this._c=r,this):new e(t,n,r)},e.fn[t]=function(n,r,o){var i=e[t](n,r,o);return i.data=this,i},e[t].prototype.sample=function(n){var r=this._a,o=this._b,i=this._c;return n?e.alter(n,function(){return e[t].sample(r,o,i)}):e[t].sample(r,o,i)},function(n){for(var r=0;r<n.length;r++)(function(n){e[t].prototype[n]=function(r){var o=this._a,i=this._b,a=this._c;return r||0===r||(r=this.data),"number"!=typeof r?e.fn.map.call(r,function(r){return e[t][n](r,o,i,a)}):e[t][n](r,o,i,a)}})(n[r])}("pdf cdf inv".split(" ")),function(n){for(var r=0;r<n.length;r++)(function(n){e[t].prototype[n]=function(){return e[t][n](this._a,this._b,this._c)}})(n[r])}("mean median mode variance".split(" "))})(t[n])}("beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy laplace lognormal noncentralt normal pareto studentt weibull uniform binomial negbin hypgeom poisson triangular tukey arcsine".split(" ")),e.extend(e.beta,{pdf:function(n,r,o){return n>1||n<0?0:1==r&&1==o?1:r<512&&o<512?t.pow(n,r-1)*t.pow(1-n,o-1)/e.betafn(r,o):t.exp((r-1)*t.log(n)+(o-1)*t.log(1-n)-e.betaln(r,o))},cdf:function(t,n,r){return t>1||t<0?1*(t>1):e.ibeta(t,n,r)},inv:function(t,n,r){return e.ibetainv(t,n,r)},mean:function(e,t){return e/(e+t)},median:function(t,n){return e.ibetainv(.5,t,n)},mode:function(e,t){return(e-1)/(e+t-2)},sample:function(t,n){var r=e.randg(t);return r/(r+e.randg(n))},variance:function(e,n){return e*n/(t.pow(e+n,2)*(e+n+1))}}),e.extend(e.centralF,{pdf:function(n,r,o){var i;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/e.betafn(r/2,o/2)*t.pow(r/o,r/2)*t.pow(n,r/2-1)*t.pow(1+r/o*n,-(r+o)/2):(i=r*n/(o+n*r),r*(o/(o+n*r))/2*e.binomial.pdf((r-2)/2,(r+o-2)/2,i))},cdf:function(t,n,r){return t<0?0:e.ibeta(n*t/(n*t+r),n/2,r/2)},inv:function(t,n,r){return r/(n*(1/e.ibetainv(t,n/2,r/2)-1))},mean:function(e,t){return t>2?t/(t-2):void 0},mode:function(e,t){return e>2?t*(e-2)/(e*(t+2)):void 0},sample:function(t,n){return 2*e.randg(t/2)/t/(2*e.randg(n/2)/n)},variance:function(e,t){if(!(t<=4))return 2*t*t*(e+t-2)/(e*(t-2)*(t-2)*(t-4))}}),e.extend(e.cauchy,{pdf:function(e,n,r){return r<0?0:r/(t.pow(e-n,2)+t.pow(r,2))/t.PI},cdf:function(e,n,r){return t.atan((e-n)/r)/t.PI+.5},inv:function(e,n,r){return n+r*t.tan(t.PI*(e-.5))},median:function(e){return e},mode:function(e){return e},sample:function(n,r){return e.randn()*t.sqrt(1/(2*e.randg(.5)))*r+n}}),e.extend(e.chisquare,{pdf:function(n,r){return n<0?0:0===n&&2===r?.5:t.exp((r/2-1)*t.log(n)-n/2-r/2*t.log(2)-e.gammaln(r/2))},cdf:function(t,n){return t<0?0:e.lowRegGamma(n/2,t/2)},inv:function(t,n){return 2*e.gammapinv(t,.5*n)},mean:function(e){return e},median:function(e){return e*t.pow(1-2/(9*e),3)},mode:function(e){return e-2>0?e-2:0},sample:function(t){return 2*e.randg(t/2)},variance:function(e){return 2*e}}),e.extend(e.exponential,{pdf:function(e,n){return e<0?0:n*t.exp(-n*e)},cdf:function(e,n){return e<0?0:1-t.exp(-n*e)},inv:function(e,n){return-t.log(1-e)/n},mean:function(e){return 1/e},median:function(e){return 1/e*t.log(2)},mode:function(){return 0},sample:function(n){return-1/n*t.log(e._random_fn())},variance:function(e){return t.pow(e,-2)}}),e.extend(e.gamma,{pdf:function(n,r,o){return n<0?0:0===n&&1===r?1/o:t.exp((r-1)*t.log(n)-n/o-e.gammaln(r)-r*t.log(o))},cdf:function(t,n,r){return t<0?0:e.lowRegGamma(n,t/r)},inv:function(t,n,r){return e.gammapinv(t,n)*r},mean:function(e,t){return e*t},mode:function(e,t){if(e>1)return(e-1)*t},sample:function(t,n){return e.randg(t)*n},variance:function(e,t){return e*t*t}}),e.extend(e.invgamma,{pdf:function(n,r,o){return n<=0?0:t.exp(-(r+1)*t.log(n)-o/n-e.gammaln(r)+r*t.log(o))},cdf:function(t,n,r){return t<=0?0:1-e.lowRegGamma(n,r/t)},inv:function(t,n,r){return r/e.gammapinv(1-t,n)},mean:function(e,t){return e>1?t/(e-1):void 0},mode:function(e,t){return t/(e+1)},sample:function(t,n){return n/e.randg(t)},variance:function(e,t){if(!(e<=2))return t*t/((e-1)*(e-1)*(e-2))}}),e.extend(e.kumaraswamy,{pdf:function(e,n,r){return 0===e&&1===n?r:1===e&&1===r?n:t.exp(t.log(n)+t.log(r)+(n-1)*t.log(e)+(r-1)*t.log(1-t.pow(e,n)))},cdf:function(e,n,r){return e<0?0:e>1?1:1-t.pow(1-t.pow(e,n),r)},inv:function(e,n,r){return t.pow(1-t.pow(1-e,1/r),1/n)},mean:function(t,n){return n*e.gammafn(1+1/t)*e.gammafn(n)/e.gammafn(1+1/t+n)},median:function(e,n){return t.pow(1-t.pow(2,-1/n),1/e)},mode:function(e,n){if(e>=1&&n>=1&&1!==e&&1!==n)return t.pow((e-1)/(e*n-1),1/e)},variance:function(){throw new Error("variance not yet implemented")}}),e.extend(e.lognormal,{pdf:function(e,n,r){return e<=0?0:t.exp(-t.log(e)-.5*t.log(2*t.PI)-t.log(r)-t.pow(t.log(e)-n,2)/(2*r*r))},cdf:function(n,r,o){return n<0?0:.5+.5*e.erf((t.log(n)-r)/t.sqrt(2*o*o))},inv:function(n,r,o){return t.exp(-1.4142135623730951*o*e.erfcinv(2*n)+r)},mean:function(e,n){return t.exp(e+n*n/2)},median:function(e){return t.exp(e)},mode:function(e,n){return t.exp(e-n*n)},sample:function(n,r){return t.exp(e.randn()*r+n)},variance:function(e,n){return(t.exp(n*n)-1)*t.exp(2*e+n*n)}}),e.extend(e.noncentralt,{pdf:function(n,r,o){return t.abs(o)<1e-14?e.studentt.pdf(n,r):t.abs(n)<1e-14?t.exp(e.gammaln((r+1)/2)-o*o/2-.5*t.log(t.PI*r)-e.gammaln(r/2)):r/n*(e.noncentralt.cdf(n*t.sqrt(1+2/r),r+2,o)-e.noncentralt.cdf(n,r,o))},cdf:function(n,r,o){var i=1e-14;if(t.abs(o)<i)return e.studentt.cdf(n,r);var a=!1;n<0&&(a=!0,o=-o);for(var s=e.normal.cdf(-o,0,1),l=i+1,c=l,u=n*n/(n*n+r),f=0,p=t.exp(-o*o/2),d=t.exp(-o*o/2-.5*t.log(2)-e.gammaln(1.5))*o;f<200||c>i||l>i;)c=l,f>0&&(p*=o*o/(2*f),d*=o*o/(2*(f+.5))),s+=.5*(l=p*e.beta.cdf(u,f+.5,r/2)+d*e.beta.cdf(u,f+1,r/2)),f++;return a?1-s:s}}),e.extend(e.normal,{pdf:function(e,n,r){return t.exp(-.5*t.log(2*t.PI)-t.log(r)-t.pow(e-n,2)/(2*r*r))},cdf:function(n,r,o){return.5*(1+e.erf((n-r)/t.sqrt(2*o*o)))},inv:function(t,n,r){return-1.4142135623730951*r*e.erfcinv(2*t)+n},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},sample:function(t,n){return e.randn()*n+t},variance:function(e,t){return t*t}}),e.extend(e.pareto,{pdf:function(e,n,r){return e<n?0:r*t.pow(n,r)/t.pow(e,r+1)},cdf:function(e,n,r){return e<n?0:1-t.pow(n/e,r)},inv:function(e,n,r){return n/t.pow(1-e,1/r)},mean:function(e,n){if(!(n<=1))return n*t.pow(e,n)/(n-1)},median:function(e,n){return e*(n*t.SQRT2)},mode:function(e){return e},variance:function(e,n){if(!(n<=2))return e*e*n/(t.pow(n-1,2)*(n-2))}}),e.extend(e.studentt,{pdf:function(n,r){return r=r>1e100?1e100:r,1/(t.sqrt(r)*e.betafn(.5,r/2))*t.pow(1+n*n/r,-(r+1)/2)},cdf:function(n,r){var o=r/2;return e.ibeta((n+t.sqrt(n*n+r))/(2*t.sqrt(n*n+r)),o,o)},inv:function(n,r){var o=e.ibetainv(2*t.min(n,1-n),.5*r,.5);return o=t.sqrt(r*(1-o)/o),n>.5?o:-o},mean:function(e){return e>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(n){return e.randn()*t.sqrt(n/(2*e.randg(n/2)))},variance:function(e){return e>2?e/(e-2):e>1?1/0:void 0}}),e.extend(e.weibull,{pdf:function(e,n,r){return e<0||n<0||r<0?0:r/n*t.pow(e/n,r-1)*t.exp(-t.pow(e/n,r))},cdf:function(e,n,r){return e<0?0:1-t.exp(-t.pow(e/n,r))},inv:function(e,n,r){return n*t.pow(-t.log(1-e),1/r)},mean:function(t,n){return t*e.gammafn(1+1/n)},median:function(e,n){return e*t.pow(t.log(2),1/n)},mode:function(e,n){return n<=1?0:e*t.pow((n-1)/n,1/n)},sample:function(n,r){return n*t.pow(-t.log(e._random_fn()),1/r)},variance:function(n,r){return n*n*e.gammafn(1+2/r)-t.pow(e.weibull.mean(n,r),2)}}),e.extend(e.uniform,{pdf:function(e,t,n){return e<t||e>n?0:1/(n-t)},cdf:function(e,t,n){return e<t?0:e<n?(e-t)/(n-t):1},inv:function(e,t,n){return t+e*(n-t)},mean:function(e,t){return.5*(e+t)},median:function(t,n){return e.mean(t,n)},mode:function(){throw new Error("mode is not yet implemented")},sample:function(t,n){return t/2+n/2+(n/2-t/2)*(2*e._random_fn()-1)},variance:function(e,n){return t.pow(n-e,2)/12}}),e.extend(e.binomial,{pdf:function(n,r,o){return 0===o||1===o?r*o===n?1:0:e.combination(r,n)*t.pow(o,n)*t.pow(1-o,r-n)},cdf:function(r,o,i){var a,s=1e-10;if(r<0)return 0;if(r>=o)return 1;if(i<0||i>1||o<=0)return NaN;var l=i,c=(r=t.floor(r))+1,u=o-r,f=c+u,p=t.exp(e.gammaln(f)-e.gammaln(u)-e.gammaln(c)+c*t.log(l)+u*t.log(1-l));return a=l<(c+1)/(f+2)?p*n(l,c,u,s):1-p*n(1-l,u,c,s),t.round(1/s*(1-a))/(1/s)}}),e.extend(e.negbin,{pdf:function(n,r,o){return n===n>>>0&&(n<0?0:e.combination(n+r-1,r-1)*t.pow(1-o,n)*t.pow(o,r))},cdf:function(t,n,r){var o=0,i=0;if(t<0)return 0;for(;i<=t;i++)o+=e.negbin.pdf(i,n,r);return o}}),e.extend(e.hypgeom,{pdf:function(n,r,o,i){if(n!=n|0)return!1;if(n<0||n<o-(r-i))return 0;if(n>i||n>o)return 0;if(2*o>r)return 2*i>r?e.hypgeom.pdf(r-o-i+n,r,r-o,r-i):e.hypgeom.pdf(i-n,r,r-o,i);if(2*i>r)return e.hypgeom.pdf(o-n,r,o,r-i);if(o<i)return e.hypgeom.pdf(n,r,i,o);for(var a=1,s=0,l=0;l<n;l++){for(;a>1&&s<i;)a*=1-o/(r-s),s++;a*=(i-l)*(o-l)/((l+1)*(r-o-i+l+1))}for(;s<i;s++)a*=1-o/(r-s);return t.min(1,t.max(0,a))},cdf:function(n,r,o,i){if(n<0||n<o-(r-i))return 0;if(n>=i||n>=o)return 1;if(2*o>r)return 2*i>r?e.hypgeom.cdf(r-o-i+n,r,r-o,r-i):1-e.hypgeom.cdf(i-n-1,r,r-o,i);if(2*i>r)return 1-e.hypgeom.cdf(o-n-1,r,o,r-i);if(o<i)return e.hypgeom.cdf(n,r,i,o);for(var a=1,s=1,l=0,c=0;c<n;c++){for(;a>1&&l<i;){var u=1-o/(r-l);s*=u,a*=u,l++}a+=s*=(i-c)*(o-c)/((c+1)*(r-o-i+c+1))}for(;l<i;l++)a*=1-o/(r-l);return t.min(1,t.max(0,a))}}),e.extend(e.poisson,{pdf:function(n,r){return r<0||n%1!=0||n<0?0:t.pow(r,n)*t.exp(-r)/e.factorial(n)},cdf:function(t,n){var r=[],o=0;if(t<0)return 0;for(;o<=t;o++)r.push(e.poisson.pdf(o,n));return e.sum(r)},mean:function(e){return e},variance:function(e){return e},sampleSmall:function(n){var r=1,o=0,i=t.exp(-n);do{o++,r*=e._random_fn()}while(r>i);return o-1},sampleLarge:function(n){var r,o,i,a,s,l,c,u,f,p,d=n;for(a=t.sqrt(d),s=t.log(d),l=.02483*(c=.931+2.53*a)-.059,u=1.1239+1.1328/(c-3.4),f=.9277-3.6224/(c-2);;){if(o=t.random()-.5,i=t.random(),p=.5-t.abs(o),r=t.floor((2*l/p+c)*o+d+.43),p>=.07&&i<=f)return r;if(!(r<0||p<.013&&i>p)&&t.log(i)+t.log(u)-t.log(l/(p*p)+c)<=r*s-d-e.loggam(r+1))return r}},sample:function(e){return e<10?this.sampleSmall(e):this.sampleLarge(e)}}),e.extend(e.triangular,{pdf:function(e,t,n,r){return n<=t||r<t||r>n?NaN:e<t||e>n?0:e<r?2*(e-t)/((n-t)*(r-t)):e===r?2/(n-t):2*(n-e)/((n-t)*(n-r))},cdf:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=n?0:e>=r?1:e<=o?t.pow(e-n,2)/((r-n)*(o-n)):1-t.pow(r-e,2)/((r-n)*(r-o))},inv:function(e,n,r,o){return r<=n||o<n||o>r?NaN:e<=(o-n)/(r-n)?n+(r-n)*t.sqrt(e*((o-n)/(r-n))):n+(r-n)*(1-t.sqrt((1-e)*(1-(o-n)/(r-n))))},mean:function(e,t,n){return(e+t+n)/3},median:function(e,n,r){return r<=(e+n)/2?n-t.sqrt((n-e)*(n-r))/t.sqrt(2):r>(e+n)/2?e+t.sqrt((n-e)*(r-e))/t.sqrt(2):void 0},mode:function(e,t,n){return n},sample:function(n,r,o){var i=e._random_fn();return i<(o-n)/(r-n)?n+t.sqrt(i*(r-n)*(o-n)):r-t.sqrt((1-i)*(r-n)*(r-o))},variance:function(e,t,n){return(e*e+t*t+n*n-e*t-e*n-t*n)/18}}),e.extend(e.arcsine,{pdf:function(e,n,r){return r<=n?NaN:e<=n||e>=r?0:2/t.PI*t.pow(t.pow(r-n,2)-t.pow(2*e-n-r,2),-.5)},cdf:function(e,n,r){return e<n?0:e<r?2/t.PI*t.asin(t.sqrt((e-n)/(r-n))):1},inv:function(e,n,r){return n+(.5-.5*t.cos(t.PI*e))*(r-n)},mean:function(e,t){return t<=e?NaN:(e+t)/2},median:function(e,t){return t<=e?NaN:(e+t)/2},mode:function(){throw new Error("mode is not yet implemented")},sample:function(n,r){return(n+r)/2+(r-n)/2*t.sin(2*t.PI*e.uniform.sample(0,1))},variance:function(e,n){return n<=e?NaN:t.pow(n-e,2)/8}}),e.extend(e.laplace,{pdf:function(e,n,r){return r<=0?0:t.exp(-t.abs(e-n)/r)/(2*r)},cdf:function(e,n,r){return r<=0?0:e<n?.5*t.exp((e-n)/r):1-.5*t.exp(-(e-n)/r)},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},variance:function(e,t){return 2*t*t},sample:function(n,r){var o,i=e._random_fn()-.5;return n-r*((o=i)/t.abs(o))*t.log(1-2*t.abs(i))}}),e.extend(e.tukey,{cdf:function(n,o,i){var a=o,s=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],l=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(i<2||a<2)return NaN;if(!Number.isFinite(n))return 1;if(i>25e3)return r(n,1,a);var c,u=.5*i,f=u*t.log(i)-i*t.log(2)-e.gammaln(u),p=u-1,d=.25*i;c=i<=100?1:i<=800?.5:i<=5e3?.25:.125,f+=t.log(c);for(var m=0,h=1;h<=50;h++){for(var g=0,y=(2*h-1)*c,w=1;w<=16;w++){var v,b;8<w?(v=w-8-1,b=f+p*t.log(y+s[v]*c)-(s[v]*c+y)*d):(v=w-1,b=f+p*t.log(y-s[v]*c)+(s[v]*c-y)*d),b>=-30&&(g+=r(8<w?n*t.sqrt(.5*(s[v]*c+y)):n*t.sqrt(.5*(-s[v]*c+y)),1,a)*l[v]*t.exp(b))}if(h*c>=1&&g<=1e-14)break;m+=g}if(g>1e-14)throw new Error("tukey.cdf failed to converge");return m>1&&(m=1),m},inv:function(n,r,o){if(o<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var i,a=function(e,n,r){var o=.5-.5*e,i=t.sqrt(t.log(1/(o*o))),a=i+((((-453642210148e-16*i-.204231210125)*i-.342242088547)*i-1)*i+.322232421088)/((((.0038560700634*i+.10353775285)*i+.531103462366)*i+.588581570495)*i+.099348462606);r<120&&(a+=(a*a*a+a)/r/4);var s=.8832-.2368*a;return r<120&&(s+=-1.214/r+1.208*a/r),a*(s*t.log(n-1)+1.4142)}(n,r,o),s=e.tukey.cdf(a,r,o)-n;i=s>0?t.max(0,a-1):a+1;for(var l,c=e.tukey.cdf(i,r,o)-n,u=1;u<50;u++)if(l=i-c*(i-a)/(c-s),s=c,a=i,l<0&&(l=0,c=-n),c=e.tukey.cdf(l,r,o)-n,i=l,t.abs(i-a)<1e-4)return l;throw new Error("tukey.inv failed to converge")}})}(t,Math),function(e,t){var n,r,o=Array.prototype.push,i=e.utils.isArray;function a(t){return i(t)||t instanceof e}e.extend({add:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,function(e,t,r){return e+n[t][r]})):e.map(t,function(e){return e+n})},subtract:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.map(t,function(e,t,r){return e-n[t][r]||0})):e.map(t,function(e){return e-n})},divide:function(t,n){return a(n)?(a(n[0])||(n=[n]),e.multiply(t,e.inv(n))):e.map(t,function(e){return e/n})},multiply:function(t,n){var r,o,i,s,l,c,u,f;if(void 0===t.length&&void 0===n.length)return t*n;if(l=t.length,c=t[0].length,u=e.zeros(l,i=a(n)?n[0].length:c),f=0,a(n)){for(;f<i;f++)for(r=0;r<l;r++){for(s=0,o=0;o<c;o++)s+=t[r][o]*n[o][f];u[r][f]=s}return 1===l&&1===f?u[0][0]:u}return e.map(t,function(e){return e*n})},outer:function(t,n){return e.multiply(t.map(function(e){return[e]}),[n])},dot:function(t,n){a(t[0])||(t=[t]),a(n[0])||(n=[n]);for(var r,o,i=1===t[0].length&&1!==t.length?e.transpose(t):t,s=1===n[0].length&&1!==n.length?e.transpose(n):n,l=[],c=0,u=i.length,f=i[0].length;c<u;c++){for(l[c]=[],r=0,o=0;o<f;o++)r+=i[c][o]*s[c][o];l[c]=r}return 1===l.length?l[0]:l},pow:function(n,r){return e.map(n,function(e){return t.pow(e,r)})},exp:function(n){return e.map(n,function(e){return t.exp(e)})},log:function(n){return e.map(n,function(e){return t.log(e)})},abs:function(n){return e.map(n,function(e){return t.abs(e)})},norm:function(e,n){var r=0,o=0;for(isNaN(n)&&(n=2),a(e[0])&&(e=e[0]);o<e.length;o++)r+=t.pow(t.abs(e[o]),n);return t.pow(r,1/n)},angle:function(n,r){return t.acos(e.dot(n,r)/(e.norm(n)*e.norm(r)))},aug:function(e,t){var n,r=[];for(n=0;n<e.length;n++)r.push(e[n].slice());for(n=0;n<r.length;n++)o.apply(r[n],t[n]);return r},inv:function(t){for(var n,r=t.length,o=t[0].length,i=e.identity(r,o),a=e.gauss_jordan(t,i),s=[],l=0;l<r;l++)for(s[l]=[],n=o;n<a[0].length;n++)s[l][n-o]=a[l][n];return s},det:function e(t){if(2===t.length)return t[0][0]*t[1][1]-t[0][1]*t[1][0];for(var n=0,r=0;r<t.length;r++){for(var o=[],i=1;i<t.length;i++){o[i-1]=[];for(var a=0;a<t.length;a++)a<r?o[i-1][a]=t[i][a]:a>r&&(o[i-1][a-1]=t[i][a])}var s=r%2?-1:1;n+=e(o)*t[0][r]*s}return n},gauss_elimination:function(n,r){var o,i,a,s,l=0,c=0,u=n.length,f=n[0].length,p=1,d=0,m=[];for(o=(n=e.aug(n,r))[0].length,l=0;l<u;l++){for(i=n[l][l],c=l,s=l+1;s<f;s++)i<t.abs(n[s][l])&&(i=n[s][l],c=s);if(c!=l)for(s=0;s<o;s++)a=n[l][s],n[l][s]=n[c][s],n[c][s]=a;for(c=l+1;c<u;c++)for(p=n[c][l]/n[l][l],s=l;s<o;s++)n[c][s]=n[c][s]-p*n[l][s]}for(l=u-1;l>=0;l--){for(d=0,c=l+1;c<=u-1;c++)d+=m[c]*n[l][c];m[l]=(n[l][o-1]-d)/n[l][l]}return m},gauss_jordan:function(n,r){var o,i,a,s=e.aug(n,r),l=s.length,c=s[0].length,u=0;for(i=0;i<l;i++){var f=i;for(a=i+1;a<l;a++)t.abs(s[a][i])>t.abs(s[f][i])&&(f=a);var p=s[i];for(s[i]=s[f],s[f]=p,a=i+1;a<l;a++)for(u=s[a][i]/s[i][i],o=i;o<c;o++)s[a][o]-=s[i][o]*u}for(i=l-1;i>=0;i--){for(u=s[i][i],a=0;a<i;a++)for(o=c-1;o>i-1;o--)s[a][o]-=s[i][o]*s[a][i]/u;for(s[i][i]/=u,o=l;o<c;o++)s[i][o]/=u}return s},triaUpSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map(function(e){return e[0]}),a=!0),e.arange(o-1,-1,-1).forEach(function(a){r=e.arange(a+1,o).map(function(e){return i[e]*t[a][e]}),i[a]=(n[a]-e.sum(r))/t[a][a]}),a?i.map(function(e){return[e]}):i},triaLowSolve:function(t,n){var r,o=t[0].length,i=e.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map(function(e){return e[0]}),a=!0),e.arange(o).forEach(function(o){r=e.arange(o).map(function(e){return t[o][e]*i[e]}),i[o]=(n[o]-e.sum(r))/t[o][o]}),a?i.map(function(e){return[e]}):i},lu:function(t){var n,r=t.length,o=e.identity(r),i=e.zeros(t.length,t[0].length);return e.arange(r).forEach(function(e){i[0][e]=t[0][e]}),e.arange(1,r).forEach(function(a){e.arange(a).forEach(function(r){n=e.arange(r).map(function(e){return o[a][e]*i[e][r]}),o[a][r]=(t[a][r]-e.sum(n))/i[r][r]}),e.arange(a,r).forEach(function(r){n=e.arange(a).map(function(e){return o[a][e]*i[e][r]}),i[a][r]=t[n.length][r]-e.sum(n)})}),[o,i]},cholesky:function(n){var r,o=n.length,i=e.zeros(n.length,n[0].length);return e.arange(o).forEach(function(a){r=e.arange(a).map(function(e){return t.pow(i[a][e],2)}),i[a][a]=t.sqrt(n[a][a]-e.sum(r)),e.arange(a+1,o).forEach(function(t){r=e.arange(a).map(function(e){return i[a][e]*i[t][e]}),i[t][a]=(n[a][t]-e.sum(r))/i[a][a]})}),i},gauss_jacobi:function(n,r,o,i){for(var a,s,l,c,u=0,f=0,p=n.length,d=[],m=[],h=[];u<p;u++)for(d[u]=[],m[u]=[],h[u]=[],f=0;f<p;f++)u>f?(d[u][f]=n[u][f],m[u][f]=h[u][f]=0):u<f?(m[u][f]=n[u][f],d[u][f]=h[u][f]=0):(h[u][f]=n[u][f],d[u][f]=m[u][f]=0);for(l=e.multiply(e.multiply(e.inv(h),e.add(d,m)),-1),s=e.multiply(e.inv(h),r),a=o,c=e.add(e.multiply(l,o),s),u=2;t.abs(e.norm(e.subtract(c,a)))>i;)a=c,c=e.add(e.multiply(l,a),s),u++;return c},gauss_seidel:function(n,r,o,i){for(var a,s,l,c,u,f=0,p=n.length,d=[],m=[],h=[];f<p;f++)for(d[f]=[],m[f]=[],h[f]=[],a=0;a<p;a++)f>a?(d[f][a]=n[f][a],m[f][a]=h[f][a]=0):f<a?(m[f][a]=n[f][a],d[f][a]=h[f][a]=0):(h[f][a]=n[f][a],d[f][a]=m[f][a]=0);for(c=e.multiply(e.multiply(e.inv(e.add(h,d)),m),-1),l=e.multiply(e.inv(e.add(h,d)),r),s=o,u=e.add(e.multiply(c,o),l),f=2;t.abs(e.norm(e.subtract(u,s)))>i;)s=u,u=e.add(e.multiply(c,s),l),f+=1;return u},SOR:function(n,r,o,i,a){for(var s,l,c,u,f,p=0,d=n.length,m=[],h=[],g=[];p<d;p++)for(m[p]=[],h[p]=[],g[p]=[],s=0;s<d;s++)p>s?(m[p][s]=n[p][s],h[p][s]=g[p][s]=0):p<s?(h[p][s]=n[p][s],m[p][s]=g[p][s]=0):(g[p][s]=n[p][s],m[p][s]=h[p][s]=0);for(u=e.multiply(e.inv(e.add(g,e.multiply(m,a))),e.subtract(e.multiply(g,1-a),e.multiply(h,a))),c=e.multiply(e.multiply(e.inv(e.add(g,e.multiply(m,a))),r),a),l=o,f=e.add(e.multiply(u,o),c),p=2;t.abs(e.norm(e.subtract(f,l)))>i;)l=f,f=e.add(e.multiply(u,l),c),p++;return f},householder:function(n){for(var r,o,i,a,s=n.length,l=n[0].length,c=0,u=[],f=[];c<s-1;c++){for(r=0,a=c+1;a<l;a++)r+=n[a][c]*n[a][c];for(r=(n[c+1][c]>0?-1:1)*t.sqrt(r),o=t.sqrt((r*r-n[c+1][c]*r)/2),(u=e.zeros(s,1))[c+1][0]=(n[c+1][c]-r)/(2*o),i=c+2;i<s;i++)u[i][0]=n[i][c]/(2*o);f=e.subtract(e.identity(s,l),e.multiply(e.multiply(u,e.transpose(u)),2)),n=e.multiply(f,e.multiply(n,f))}return n},QR:(n=e.sum,r=e.arange,function(o){var i,a,s,l=o.length,c=o[0].length,u=e.zeros(c,c);for(o=e.copy(o),a=0;a<c;a++){for(u[a][a]=t.sqrt(n(r(l).map(function(e){return o[e][a]*o[e][a]}))),i=0;i<l;i++)o[i][a]=o[i][a]/u[a][a];for(s=a+1;s<c;s++)for(u[a][s]=n(r(l).map(function(e){return o[e][a]*o[e][s]})),i=0;i<l;i++)o[i][s]=o[i][s]-o[i][a]*u[a][s]}return[o,u]}),lstsq:function(t,n){var r=!1;void 0===n[0].length&&(n=n.map(function(e){return[e]}),r=!0);var o=e.QR(t),i=o[0],a=o[1],s=t[0].length,l=e.slice(i,{col:{end:s}}),c=function(t){var n=(t=e.copy(t)).length,r=e.identity(n);return e.arange(n-1,-1,-1).forEach(function(n){e.sliceAssign(r,{row:n},e.divide(e.slice(r,{row:n}),t[n][n])),e.sliceAssign(t,{row:n},e.divide(e.slice(t,{row:n}),t[n][n])),e.arange(n).forEach(function(o){var i=e.multiply(t[o][n],-1),a=e.slice(t,{row:o}),s=e.multiply(e.slice(t,{row:n}),i);e.sliceAssign(t,{row:o},e.add(a,s));var l=e.slice(r,{row:o}),c=e.multiply(e.slice(r,{row:n}),i);e.sliceAssign(r,{row:o},e.add(l,c))})}),r}(e.slice(a,{row:{end:s}})),u=e.transpose(l);void 0===u[0].length&&(u=[u]);var f=e.multiply(e.multiply(c,u),n);return void 0===f.length&&(f=[[f]]),r?f.map(function(e){return e[0]}):f},jacobi:function(n){for(var r,o,i,a,s,l,c,u=1,f=n.length,p=e.identity(f,f),d=[];1===u;){for(s=n[0][1],i=0,a=1,r=0;r<f;r++)for(o=0;o<f;o++)r!=o&&s<t.abs(n[r][o])&&(s=t.abs(n[r][o]),i=r,a=o);for(l=n[i][i]===n[a][a]?n[i][a]>0?t.PI/4:-t.PI/4:t.atan(2*n[i][a]/(n[i][i]-n[a][a]))/2,(c=e.identity(f,f))[i][i]=t.cos(l),c[i][a]=-t.sin(l),c[a][i]=t.sin(l),c[a][a]=t.cos(l),p=e.multiply(p,c),n=e.multiply(e.multiply(e.inv(c),n),c),u=0,r=1;r<f;r++)for(o=1;o<f;o++)r!=o&&t.abs(n[r][o])>.001&&(u=1)}for(r=0;r<f;r++)d.push(n[r][r]);return[p,d]},rungekutta:function(e,t,n,r,o,i){var a,s,l;if(2===i)for(;r<=n;)o+=((a=t*e(r,o))+(s=t*e(r+t,o+a)))/2,r+=t;if(4===i)for(;r<=n;)o+=((a=t*e(r,o))+2*(s=t*e(r+t/2,o+a/2))+2*(l=t*e(r+t/2,o+s/2))+t*e(r+t,o+l))/6,r+=t;return o},romberg:function(e,n,r,o){for(var i,a,s,l,c,u=0,f=(r-n)/2,p=[],d=[],m=[];u<o/2;){for(c=e(n),s=n,l=0;s<=r;s+=f,l++)p[l]=s;for(i=p.length,s=1;s<i-1;s++)c+=(s%2!=0?4:2)*e(p[s]);c=f/3*(c+e(r)),m[u]=c,f/=2,u++}for(a=m.length,i=1;1!==a;){for(s=0;s<a-1;s++)d[s]=(t.pow(4,i)*m[s+1]-m[s])/(t.pow(4,i)-1);a=d.length,m=d,d=[],i++}return m},richardson:function(e,n,r,o){function i(e,t){for(var n,r=0,o=e.length;r<o;r++)e[r]===t&&(n=r);return n}for(var a,s,l,c,u,f=t.abs(r-e[i(e,r)+1]),p=0,d=[],m=[];o>=f;)a=i(e,r+o),s=i(e,r),d[p]=(n[a]-2*n[s]+n[2*s-a])/(o*o),o/=2,p++;for(c=d.length,l=1;1!=c;){for(u=0;u<c-1;u++)m[u]=(t.pow(4,l)*d[u+1]-d[u])/(t.pow(4,l)-1);c=m.length,d=m,m=[],l++}return d},simpson:function(e,t,n,r){for(var o,i=(n-t)/r,a=e(t),s=[],l=t,c=0,u=1;l<=n;l+=i,c++)s[c]=l;for(o=s.length;u<o-1;u++)a+=(u%2!=0?4:2)*e(s[u]);return i/3*(a+e(n))},hermite:function(e,t,n,r){for(var o,i=e.length,a=0,s=0,l=[],c=[],u=[],f=[];s<i;s++){for(l[s]=1,o=0;o<i;o++)s!=o&&(l[s]*=(r-e[o])/(e[s]-e[o]));for(c[s]=0,o=0;o<i;o++)s!=o&&(c[s]+=1/(e[s]-e[o]));u[s]=(1-2*(r-e[s])*c[s])*(l[s]*l[s]),f[s]=(r-e[s])*(l[s]*l[s]),a+=u[s]*t[s]+f[s]*n[s]}return a},lagrange:function(e,t,n){for(var r,o,i=0,a=0,s=e.length;a<s;a++){for(o=t[a],r=0;r<s;r++)a!=r&&(o*=(n-e[r])/(e[a]-e[r]));i+=o}return i},cubic_spline:function(t,n,r){for(var o,i,a=t.length,s=0,l=[],c=[],u=[],f=[],p=[],d=[];s<a-1;s++)f[s]=t[s+1]-t[s];for(u[0]=0,s=1;s<a-1;s++)u[s]=3/f[s]*(n[s+1]-n[s])-3/f[s-1]*(n[s]-n[s-1]);for(s=1;s<a-1;s++)l[s]=[],c[s]=[],l[s][s-1]=f[s-1],l[s][s]=2*(f[s-1]+f[s]),l[s][s+1]=f[s],c[s][0]=u[s];for(i=e.multiply(e.inv(l),c),o=0;o<a-1;o++)p[o]=(n[o+1]-n[o])/f[o]-f[o]*(i[o+1][0]+2*i[o][0])/3,d[o]=(i[o+1][0]-i[o][0])/(3*f[o]);for(o=0;o<a&&!(t[o]>r);o++);return n[o-=1]+(r-t[o])*p[o]+e.sq(r-t[o])*i[o]+(r-t[o])*e.sq(r-t[o])*d[o]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(t){var n,r,o,i,a,s=t.length,l=t[0].length,c=0,u=[],f=[],p=[],d=[],m=[],h=[],g=[];for(c=0;c<s;c++)u[c]=e.sum(t[c])/l;for(c=0;c<l;c++)for(m[c]=[],n=0;n<s;n++)m[c][n]=t[n][c]-u[n];for(m=e.transpose(m),c=0;c<s;c++)for(h[c]=[],n=0;n<s;n++)h[c][n]=e.dot([m[c]],[m[n]])/(l-1);for(a=(o=e.jacobi(h))[0],f=o[1],g=e.transpose(a),c=0;c<f.length;c++)for(n=c;n<f.length;n++)f[c]<f[n]&&(r=f[c],f[c]=f[n],f[n]=r,p=g[c],g[c]=g[n],g[n]=p);for(i=e.transpose(m),c=0;c<s;c++)for(d[c]=[],n=0;n<i.length;n++)d[c][n]=e.dot([g[c]],[i[n]]);return[t,f,g,d]}}),function(t){for(var n=0;n<t.length;n++)(function(t){e.fn[t]=function(n,r){var o=this;return r?(setTimeout(function(){r.call(o,e.fn[t].call(o,n))},15),this):"number"==typeof e[t](this,n)?e[t](this,n):e(e[t](this,n))}})(t[n])}("add divide multiply subtract dot pow exp log abs norm angle".split(" "))}(t,Math),function(e,t){var n=[].slice,r=e.utils.isNumber,o=e.utils.isArray;function i(e,n,r,o){if(e>1||r>1||e<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var i=(e*n+r*o)/(n+o);return(e-r)/t.sqrt(i*(1-i)*(1/n+1/o))}e.extend({zscore:function(){var t=n.call(arguments);return r(t[1])?(t[0]-t[1])/t[2]:(t[0]-e.mean(t[1]))/e.stdev(t[1],t[2])},ztest:function(){var r,i=n.call(arguments);return o(i[1])?(r=e.zscore(i[0],i[1],i[3]),1===i[2]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):i.length>2?(r=e.zscore(i[0],i[1],i[2]),1===i[3]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1)):(r=i[0],1===i[1]?e.normal.cdf(-t.abs(r),0,1):2*e.normal.cdf(-t.abs(r),0,1))}}),e.extend(e.fn,{zscore:function(e,t){return(e-this.mean())/this.stdev(t)},ztest:function(n,r,o){var i=t.abs(this.zscore(n,o));return 1===r?e.normal.cdf(-i,0,1):2*e.normal.cdf(-i,0,1)}}),e.extend({tscore:function(){var r=n.call(arguments);return 4===r.length?(r[0]-r[1])/(r[2]/t.sqrt(r[3])):(r[0]-e.mean(r[1]))/(e.stdev(r[1],!0)/t.sqrt(r[1].length))},ttest:function(){var o,i=n.call(arguments);return 5===i.length?(o=t.abs(e.tscore(i[0],i[1],i[2],i[3])),1===i[4]?e.studentt.cdf(-o,i[3]-1):2*e.studentt.cdf(-o,i[3]-1)):r(i[1])?(o=t.abs(i[0]),1==i[2]?e.studentt.cdf(-o,i[1]-1):2*e.studentt.cdf(-o,i[1]-1)):(o=t.abs(e.tscore(i[0],i[1])),1==i[2]?e.studentt.cdf(-o,i[1].length-1):2*e.studentt.cdf(-o,i[1].length-1))}}),e.extend(e.fn,{tscore:function(e){return(e-this.mean())/(this.stdev(!0)/t.sqrt(this.cols()))},ttest:function(n,r){return 1===r?1-e.studentt.cdf(t.abs(this.tscore(n)),this.cols()-1):2*e.studentt.cdf(-t.abs(this.tscore(n)),this.cols()-1)}}),e.extend({anovafscore:function(){var r,o,i,a,s,l,c,u,f=n.call(arguments);if(1===f.length){for(s=new Array(f[0].length),c=0;c<f[0].length;c++)s[c]=f[0][c];f=s}for(o=new Array,c=0;c<f.length;c++)o=o.concat(f[c]);for(i=e.mean(o),r=0,c=0;c<f.length;c++)r+=f[c].length*t.pow(e.mean(f[c])-i,2);for(r/=f.length-1,l=0,c=0;c<f.length;c++)for(a=e.mean(f[c]),u=0;u<f[c].length;u++)l+=t.pow(f[c][u]-a,2);return r/(l/(o.length-f.length))},anovaftest:function(){var t,o,i,a,s=n.call(arguments);if(r(s[0]))return 1-e.centralF.cdf(s[0],s[1],s[2]);var l=e.anovafscore(s);for(t=s.length-1,i=0,a=0;a<s.length;a++)i+=s[a].length;return o=i-t-1,1-e.centralF.cdf(l,t,o)},ftest:function(t,n,r){return 1-e.centralF.cdf(t,n,r)}}),e.extend(e.fn,{anovafscore:function(){return e.anovafscore(this.toArray())},anovaftes:function(){var t,n=0;for(t=0;t<this.length;t++)n+=this[t].length;return e.ftest(this.anovafscore(),this.length-1,n-this.length)}}),e.extend({qscore:function(){var o,i,a,s,l,c=n.call(arguments);return r(c[0])?(o=c[0],i=c[1],a=c[2],s=c[3],l=c[4]):(o=e.mean(c[0]),i=e.mean(c[1]),a=c[0].length,s=c[1].length,l=c[2]),t.abs(o-i)/(l*t.sqrt((1/a+1/s)/2))},qtest:function(){var t,r=n.call(arguments);3===r.length?(t=r[0],r=r.slice(1)):7===r.length?(t=e.qscore(r[0],r[1],r[2],r[3],r[4]),r=r.slice(5)):(t=e.qscore(r[0],r[1],r[2]),r=r.slice(3));var o=r[0],i=r[1];return 1-e.tukey.cdf(t,i,o-i)},tukeyhsd:function(t){for(var n=e.pooledstdev(t),r=t.map(function(t){return e.mean(t)}),o=t.reduce(function(e,t){return e+t.length},0),i=[],a=0;a<t.length;++a)for(var s=a+1;s<t.length;++s){var l=e.qtest(r[a],r[s],t[a].length,t[s].length,n,o,t.length);i.push([[a,s],l])}return i}}),e.extend({normalci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.normal.inv(o[1]/2,0,1)*o[2]/t.sqrt(o[3])):t.abs(e.normal.inv(o[1]/2,0,1)*e.stdev(o[2])/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},tci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?t.abs(e.studentt.inv(o[1]/2,o[3]-1)*o[2]/t.sqrt(o[3])):t.abs(e.studentt.inv(o[1]/2,o[2].length-1)*e.stdev(o[2],!0)/t.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},significant:function(e,t){return e<t}}),e.extend(e.fn,{normalci:function(t,n){return e.normalci(t,n,this.toArray())},tci:function(t,n){return e.tci(t,n,this.toArray())}}),e.extend(e.fn,{oneSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,1)},twoSidedDifferenceOfProportions:function(t,n,r,o){var a=i(t,n,r,o);return e.ztest(a,2)}})}(t,Math),t.models=function(){function e(e,n){var r=e.length,o=n[0].length-1,i=r-o-1,a=t.lstsq(n,e),s=t.multiply(n,a.map(function(e){return[e]})).map(function(e){return e[0]}),l=t.subtract(e,s),c=t.mean(e),u=t.sum(s.map(function(e){return Math.pow(e-c,2)})),f=t.sum(e.map(function(e,t){return Math.pow(e-s[t],2)})),p=u+f;return{exog:n,endog:e,nobs:r,df_model:o,df_resid:i,coef:a,predict:s,resid:l,ybar:c,SST:p,SSE:u,SSR:f,R2:u/p}}function n(n){var r,o,i=(r=n.exog,o=r[0].length,t.arange(o).map(function(n){var i=t.arange(o).filter(function(e){return e!==n});return e(t.col(r,n).map(function(e){return e[0]}),t.col(r,i))})),a=Math.sqrt(n.SSR/n.df_resid),s=i.map(function(e){var t=e.SST,n=e.R2;return a/Math.sqrt(t*(1-n))}),l=n.coef.map(function(e,t){return(e-0)/s[t]}),c=l.map(function(e){var r=t.studentt.cdf(e,n.df_resid);return 2*(r>.5?1-r:r)}),u=t.studentt.inv(.975,n.df_resid),f=n.coef.map(function(e,t){var n=u*s[t];return[e-n,e+n]});return{se:s,t:l,p:c,sigmaHat:a,interval95:f}}return{ols:function(r,o){var i=e(r,o),a=n(i),s=function(e){var n,r,o,i=e.R2/e.df_model/((1-e.R2)/e.df_resid);return{F_statistic:i,pvalue:1-(n=i,r=e.df_model,o=e.df_resid,t.beta.cdf(n/(o/r+n),r/2,o/2))}}(i),l=1-(1-i.R2)*((i.nobs-1)/i.df_resid);return i.t=a,i.f=s,i.adjust_R2=l,i}}}(),t.extend({buildxmatrix:function(){for(var e=new Array(arguments.length),n=0;n<arguments.length;n++){e[n]=[1].concat(arguments[n])}return t(e)},builddxmatrix:function(){for(var e=new Array(arguments[0].length),n=0;n<arguments[0].length;n++){e[n]=[1].concat(arguments[0][n])}return t(e)},buildjxmatrix:function(e){for(var n=new Array(e.length),r=0;r<e.length;r++)n[r]=e[r];return t.builddxmatrix(n)},buildymatrix:function(e){return t(e).transpose()},buildjymatrix:function(e){return e.transpose()},matrixmult:function(e,n){var r,o,i,a,s;if(e.cols()==n.rows()){if(n.rows()>1){for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<e.cols();i++)s+=e.toArray()[r][i]*n.toArray()[i][o];a[r][o]=s}return t(a)}for(a=[],r=0;r<e.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<e.cols();i++)s+=e.toArray()[r][i]*n.toArray()[o];a[r][o]=s}return t(a)}},regress:function(e,n){var r=t.xtranspxinv(e),o=e.transpose(),i=t.matrixmult(t(r),o);return t.matrixmult(i,n)},regresst:function(e,n,r){var o=t.regress(e,n),i={anova:{}},a=t.jMatYBar(e,o);i.yBar=a;var s=n.mean();i.anova.residuals=t.residuals(n,a),i.anova.ssr=t.ssr(a,s),i.anova.msr=i.anova.ssr/(e[0].length-1),i.anova.sse=t.sse(n,a),i.anova.mse=i.anova.sse/(n.length-(e[0].length-1)-1),i.anova.sst=t.sst(n,s),i.anova.mst=i.anova.sst/(n.length-1),i.anova.r2=1-i.anova.sse/i.anova.sst,i.anova.r2<0&&(i.anova.r2=0),i.anova.fratio=i.anova.msr/i.anova.mse,i.anova.pvalue=t.anovaftest(i.anova.fratio,e[0].length-1,n.length-(e[0].length-1)-1),i.anova.rmse=Math.sqrt(i.anova.mse),i.anova.r2adj=1-i.anova.mse/i.anova.mst,i.anova.r2adj<0&&(i.anova.r2adj=0),i.stats=new Array(e[0].length);for(var l,c,u,f=t.xtranspxinv(e),p=0;p<o.length;p++)l=Math.sqrt(i.anova.mse*Math.abs(f[p][p])),c=Math.abs(o[p]/l),u=t.ttest(c,n.length-e[0].length-1,r),i.stats[p]=[o[p],l,c,u];return i.regress=o,i},xtranspx:function(e){return t.matrixmult(e.transpose(),e)},xtranspxinv:function(e){var n=t.matrixmult(e.transpose(),e);return t.inv(n)},jMatYBar:function(e,n){var r=t.matrixmult(e,n);return new t(r)},residuals:function(e,n){return t.matrixsubtract(e,n)},ssr:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},sse:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t[r],2);return n},sst:function(e,t){for(var n=0,r=0;r<e.length;r++)n+=Math.pow(e[r]-t,2);return n},matrixsubtract:function(e,n){for(var r=new Array(e.length),o=0;o<e.length;o++){r[o]=new Array(e[o].length);for(var i=0;i<e[o].length;i++)r[o][i]=e[o][i]-n[o][i]}return t(r)}}),t.jStat=t,t)},829(e,t,n){"use strict";n.d(t,{RJ:()=>p,ps:()=>h,B9:()=>v});var r,o=n(328),i=n(389),a=n(82),s=n(572);function l(e,t,n=!1,r=!1){if(e.length<=1||t.length<=1)throw new Error(`StatisticsError: Wrong sample size; expected at least 2, got ${Math.min(e.length,t.length)})`);const o=s.mean(e),i=s.mean(t),a=s.variance(e),l=s.variance(t),c=e.length,u=t.length;let f,p,d;if(n){const e=a/c,t=l/u,n=(o-i)/Math.sqrt(e+t);p=s.normal.pdf(n,0,1),f=1-p,d=2*(p<f?p:f)}else if(r){const e=c+u-2,t=(a*(c-1)+l*(u-1))/e,n=Math.sqrt(c*u/(c+u))*(o-i)/t;f=1-s.studentt.cdf(n,e),p=s.studentt.cdf(n,e),d=2*(p<f?p:f)}else{const e=a/c,t=l/u,n=(o-i)/Math.sqrt(e+t),r=Math.pow(e+t,2)/(Math.pow(e,2)/(c-1)+Math.pow(t,2)/(u-1));p=s.studentt.cdf(n,r),f=1-p,d=2*(p<f?p:f)}return{"p-value":d,"Mean difference":o-i,"p-value more":f,"p-value less":p}}!function(e){e.indexesOf=function(e,t){const n=[];for(let r=0;r<e.length;r++)t(e[r])&&n.push(r);return n},e.genRange=function(e,t,n=!1){const r=t-e+(n?0:1),o=new Int32Array(r);for(let t=0;t<r;++t)o[t]=e+t;return o},e.argSort=function(e,t=!1){const n=t?(e,t)=>t[0]-e[0]:(e,t)=>e[0]-t[0];return e.map((e,t)=>[e,t]).sort(n).map(e=>e[1])}}(r||(r={}));const c={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,min:(e,t)=>e<t?e:t,max:(e,t)=>e>t?e:t};var u=n(641),f=n(252);function p(e,t){return"true"===e.getTag("proteomics.de_complete")||(o.shell.warning(t),!1)}function d(e,t,n){const r=[];for(const o of t){const t=e.columns.byName(o);t&&!t.isNone(n)&&r.push(t.get(n))}return r}function m(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t/e.length}function h(e,t,n,o,i,s=u.M5,f=u.Dx){const p=e.rowCount,h=new Float32Array(p),g=new Float32Array(p),y=new Float32Array(p);h.fill(a.FLOAT_NULL),g.fill(a.FLOAT_NULL),y.fill(a.FLOAT_NULL);const w=[],v=[];for(let r=0;r<p;r++){const o=d(e,t,r),i=d(e,n,r);if(o.length<2||i.length<2)continue;h[r]=m(i)-m(o);const a=l(o,i)["p-value"];g[r]=a,w.push(r),v.push(a)}if(v.length>0){const[,e]=function(e,t=.05,n="n",o=!1){const i=e.length;let a,s,l=0;var u,f;o?(s=new Int32Array(i).fill(0).map((e,t)=>t),a=e):(s=function(e){const t=Array.from(e);return Int32Array.from(r.argSort(t))}(e),u=s,f=e,a=Float32Array.from(f).map((e,t)=>f[u[t]]));let p=function(e){const t=e.length;return Float32Array.from(e).map((e,n)=>(n+1)/t)}(a);if(["n","negcorr"].includes(n))l=function(e){let t=0;for(let n=0;n<e;++n)t+=1/(n+1);return t}(i),p=function(e,t,n="*"){return Float32Array.from(e).map((e,r)=>c[n](e,t))}(p,l,"/");else if(!["i","indep","p","poscorr"].includes(n))throw new Error("only indep and negcorr implemented");const d=new Array(i).fill(!1);let m=-1;for(let e=0;e<i;++e)a[e]<=p[e]*t&&(m=e);if(m>=0)for(let e=0;e<m;++e)d[e]=!0;let h=function(e,t,n="*"){return Float32Array.from(e).map((e,r)=>c[n](e,t[r]))}(a,p,"/");h=function(e){const t=e.length,n=Float32Array.from(e);for(let r=0;r<t;++r)n[r]=e.slice(0,r+1).reduce((e,t,n,r)=>c.min(e,t));return n}(h.reverse()).reverse();for(let e=0;e<i;++e)h[e]>1&&(h[e]=1);if(!o){const e=function(e,t){const n=Float32Array.from(e);for(let r=0;r<t.length;++r)n[t[r]]=e[r];return n}(h,s),t=function(e,t){const n=Array.from(e);for(let r=0;r<t.length;++r)n[t[r]]=e[r];return n}(d,s);return[t,e]}return[d,h]}(new Float32Array(v),f,"i");for(let t=0;t<w.length;t++)y[w[t]]=e[t]}const b=e.columns.addNewFloat("log2FC"),_=e.columns.addNewFloat("p-value"),x=e.columns.addNewFloat("adj.p-value");b.init(e=>h[e]),_.init(e=>g[e]),x.init(e=>y[e]),e.columns.addNewBool("significant").init(e=>{const t=y[e],n=h[e];return t!==a.FLOAT_NULL&&n!==a.FLOAT_NULL&&Math.abs(n)>=s&&t<=f}),b.semType=u.iu.LOG2FC,_.semType=u.iu.P_VALUE,x.semType=u.iu.P_VALUE,e.setTag("proteomics.de_complete","true"),e.fireValuesChanged();const N=w.length;return{tested:N,untestable:e.rowCount-N}}function g(e,t,n){const r=[...t,...n],o=[];for(let t=0;t<r.length;t++){const n=e.columns.byName(r[t]).getRawData(),i=new Float32Array(n.length);i.set(n),o.push(a.Column.fromFloat32Array(`s${t+1}`,i))}return a.DataFrame.fromColumns(o)}function y(e,t){const n=e.rowCount,r=t.rowCount,o=t.columns.byName("log2FC").getRawData(),i=t.columns.byName("p.value").getRawData(),s=t.columns.byName("adj.p.value").getRawData(),l=t.columns.byName("significant"),c=t.col("row"),f=new Int32Array(r);if(c){const e=c.getRawData();for(let t=0;t<r;t++)f[t]=(0|e[t])-1}else for(let e=0;e<r;e++)f[e]=e;const p=new Float32Array(n);p.fill(a.FLOAT_NULL);const d=new Float32Array(n);d.fill(a.FLOAT_NULL);const m=new Float32Array(n);m.fill(a.FLOAT_NULL);const h=new Uint8Array(n);let g=0;for(let e=0;e<r;e++){const t=f[e];if(t<0||t>=n)continue;p[t]=o[e],d[t]=i[e],m[t]=s[e];const r=l.get(e);!0!==r&&1!==r&&"1"!==r&&"TRUE"!==r||(h[t]=1,g++)}const y=a.Column.fromFloat32Array("log2FC",p),w=a.Column.fromFloat32Array("p-value",d),v=a.Column.fromFloat32Array("adj.p-value",m);return e.columns.addNewBool("significant").init(e=>1===h[e]),y.semType=u.iu.LOG2FC,w.semType=u.iu.P_VALUE,v.semType=u.iu.P_VALUE,e.columns.add(y),e.columns.add(w),e.columns.add(v),g}async function w(e,t,n,r,i){const a=g(e,t,n),s=y(e,await o.functions.call("Proteomics:LimmaDE",{exprDf:a,nGroup1:t.length,fcThreshold:r,pThreshold:i}));return e.setTag("proteomics.de_complete","true"),e.fireValuesChanged(),s}function v(e,t){const n=(0,f.f)(e);if(!n)return void o.shell.warning("Please annotate experimental groups first (Proteomics | Annotate Experiment)");if("true"===e.getTag("proteomics.de_complete"))return void o.shell.warning("Differential expression already performed");const r=n.group1,s=n.group2,l=i.divText(`Group 1: ${r.name} (${r.columns.length} samples), Group 2: ${s.name} (${s.columns.length} samples)`),c=[`${s.name} vs ${r.name}`,`${r.name} vs ${s.name}`],p=i.input.choice("Comparison",{value:(d=r.name,m=s.name,`${d} vs ${m}`),items:c,nullable:!1});var d,m;const v=i.div();v.style.cssText="font-style:italic; color:#888; font-size:12px; margin-bottom:8px;";const b=()=>{const e=p.value===c[1],t=e?r.name:s.name,n=e?s.name:r.name;v.textContent=`Positive log2FC = higher in ${t}, Negative log2FC = higher in ${n}`};p.onChanged.subscribe(b),b();const _=i.input.choice("Method",{value:"limma",items:["limma","DEqMS","t-test"],nullable:!1});_.setTooltip("limma: moderated t-test; DEqMS: peptide-count-weighted variance; t-test: client-side Welch's t-test");const x=e.columns.toList().find(e=>"Unique peptides"===e.name||"Peptides"===e.name)??void 0,N=i.input.column("Peptide count column",{table:e,value:x,filter:e=>e.type===a.COLUMN_TYPE.INT||e.type===a.COLUMN_TYPE.FLOAT,nullable:!1});N.setTooltip("Column with peptide/spectra counts per protein");const C=N.root;C.style.display="none",_.onChanged.subscribe(()=>{C.style.display="DEqMS"===_.value?"":"none"});const S=i.input.float("|log2FC| threshold",{value:u.M5});S.setTooltip("Minimum absolute fold change for significance");const T=i.input.float("Adj. p-value threshold",{value:u.Dx});T.setTooltip("Maximum adjusted p-value for significance"),i.dialog("Differential Expression").add(l).add(p).add(v).add(_).add(N).add(S).add(T).onOK(async()=>{const n=S.value??u.M5,i=T.value??u.Dx,l=_.value,f=p.value===c[1],d=f?r.columns:s.columns,m=f?s.columns:r.columns,v=(f?r.name:s.name,f?s.name:r.name,a.TaskBarProgressIndicator.create(`Running ${l} analysis...`));try{if("t-test"===l){const t=h(e,m,d,0,0,n,i);e.setTag("proteomics.de_method","t-test"),o.shell.info(`DE complete (t-test): ${t.tested} proteins tested, ${t.untestable} untestable`)}else if("DEqMS"===l){const t=N.value;if(!t)return void o.shell.error("Please select a peptide count column for DEqMS");try{const r=await async function(e,t,n,r,i,s){const l=g(e,t,n),c=a.DataFrame.create(e.rowCount),u=c.columns.addNewInt("count");for(let t=0;t<e.rowCount;t++)u.set(t,r.isNone(t)?1:Math.round(r.get(t)));const f=y(e,await o.functions.call("Proteomics:DeqmsDE",{exprDf:l,nGroup1:t.length,peptideDf:c,fcThreshold:i,pThreshold:s}));return e.setTag("proteomics.de_complete","true"),e.setTag("proteomics.de_method","deqms"),e.fireValuesChanged(),f}(e,m,d,t,n,i);e.setTag("proteomics.de_method","deqms"),o.shell.info(`DE complete (DEqMS): ${r} significant proteins`)}catch(t){console.warn("DEqMS failed, trying limma:",t),v.update(50,"DEqMS unavailable, trying limma..."),o.shell.warning("DEqMS unavailable, trying limma...");try{const t=await w(e,m,d,n,i);e.setTag("proteomics.de_method","limma"),o.shell.info(`DE complete (limma fallback): ${t} significant proteins`)}catch(t){console.warn("Limma DE also failed, using client-side fallback:",t),v.update(75,"Server-side DE unavailable, using client-side t-test..."),o.shell.warning("R environment unavailable — using client-side t-test");const r=h(e,m,d,0,0,n,i);e.setTag("proteomics.de_method","t-test"),o.shell.info(`DE complete (t-test): ${r.tested} proteins tested, ${r.untestable} untestable`)}}}else try{const t=await w(e,m,d,n,i);e.setTag("proteomics.de_method","limma"),o.shell.info(`DE complete (limma): ${t} significant proteins`)}catch(t){v.update(50,"Limma unavailable, using client-side t-test..."),o.shell.warning("R environment unavailable — using client-side t-test"),console.warn("Limma DE failed, using client-side fallback:",t);const r=h(e,m,d,0,0,n,i);e.setTag("proteomics.de_method","t-test"),o.shell.info(`DE complete (t-test): ${r.tested} proteins tested, ${r.untestable} untestable`)}}finally{v.close()}t&&t()}).show()}},989(e,t,n){"use strict";n.d(t,{N:()=>c});var r=n(328),o=n(389),i=n(82),a=n(304),s=n(641),l=n(230);function c(e){const t=(0,a.I)(e);if(!t.log2fc||!t.pValue)return void r.shell.warning("No log2FC or p-value columns found. Run Differential Expression first.");const n=o.input.float("|log2FC| threshold",{value:s.M5});n.setTooltip("Minimum absolute fold change for a gene to count as up/down.");const c=o.input.float("Adj. p-value threshold",{value:s.Dx});c.setTooltip("Maximum adjusted p-value for a gene to count as up/down.");const u=o.divText(""),f=()=>{const r=(0,l.bM)(e,n.value??s.M5,c.value??s.Dx,t.log2fc,t.pValue);u.textContent=`${r.significant} of ${r.total.toLocaleString()} proteins significant`};f(),n.onChanged.subscribe(f),c.onChanged.subscribe(f),o.dialog("Export Enrichment Inputs").add(u).add(n).add(c).onOK(()=>{const t=n.value??s.M5,o=c.value??s.Dx,{csv:u,counts:f}=function(e,t,n){const r=(0,a.I)(e);if(!r.log2fc||!r.pValue)throw new Error("No log2FC or adjusted p-value columns found. Run Differential Expression first.");const o=r.geneName??r.proteinId;if(!o)throw new Error("No gene-name or protein-ID column found to export.");const i=new Map;for(let t=0;t<e.rowCount;t++){const e=o.get(t);e&&i.set(t,String(e))}const s=r.log2fc.getRawData(),c=r.pValue.getRawData(),{upGenes:u,downGenes:f,background:p}=(0,l.Bx)(i,s,c,t,n),d=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,'""')}"`:e,m=["gene,list"];for(const e of u)m.push(`${d(e)},up`);for(const e of f)m.push(`${d(e)},down`);for(const e of p)m.push(`${d(e)},background`);return{csv:m.join("\n"),counts:{up:u.length,down:f.length,background:p.length}}}(e,t,o),p=e.name?`${e.name} — enrichment inputs`:"enrichment inputs";i.Utils.download(`${p}.csv`,u,"text/csv"),r.shell.info(`Exported ${f.up} up, ${f.down} down, ${f.background} background genes.`)}).show()}},230(e,t,n){"use strict";n.d(t,{Bx:()=>b,D9:()=>x,bM:()=>_,pG:()=>N});var r=n(328),o=n(389),i=n(82),a=n(498),s=n(304),l=n(641),c=n(897),u=n(829),f=n(252),p=n(935);const d="https://biit.cs.ut.ee/gprofiler";async function m(e,t,n=3e4){const o=r.dapi.fetchProxy(e,t),i=new Promise((e,t)=>setTimeout(()=>t(new Error("g:Profiler API request timed out. The service may be temporarily unavailable.")),n)),a=await Promise.race([o,i]);if(!a.ok)throw new Error(`g:Profiler API returned status ${a.status}`);return a}async function h(e,t,n,r,o=l.Dx){const i=await m(`${d}/api/gost/profile/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({organism:n,query:e,sources:r,user_threshold:o,significance_threshold_method:"fdr",domain_scope:"custom",background:t,all_results:!0,ordered:!1,no_evidences:!1,combined:!1,measure_underrepresentation:!1,no_iea:!1,numeric_ns:"",output:"json"})}),a=await i.json();return a.result?Array.isArray(a.result)&&a.result.length>0&&a.result[0]?.result?a.result[0].result:Array.isArray(a.result)?a.result:[]:[]}const g=["localization","cellular component organization","transport","cellular process","biological process","metabolic process"],y=["actin","vesicle","endocytosis","cytoskeleton"];function w(e,t=15){if(0===e.length)return{kept:[],stats:{total:0,kept:0,droppedParents:0,cappedAtN:t}};const n=e.filter(e=>"GO:BP"===e.source),r=e.filter(e=>"GO:BP"!==e.source);let o=0;const i=[];if(n.length>0){const e=[...n].sort((e,t)=>e.p_value-t.p_value);for(const n of e){const e=(n.name??"").toLowerCase();if(g.some(t=>e.includes(t))&&i.some(e=>y.some(t=>(e.name??"").toLowerCase().includes(t))))o++;else if(i.push(n),i.length>=t)break}}const a=[...r].sort((e,t)=>e.p_value-t.p_value).slice(0,t),s=[...i,...a].sort((e,t)=>e.p_value-t.p_value);return{kept:s,stats:{total:e.length,kept:s.length,droppedParents:o,cappedAtN:t}}}function v(e,t,n=l.Dx,r){const o=e.length,a=i.DataFrame.create(o);a.name="Enrichment Results";const s=e.map(e=>{if(!e.intersections)return"";const n=[],r=Math.min(t.length,e.intersections.length);for(let o=0;o<r;o++)e.intersections[o]&&e.intersections[o].length>0&&n.push(t[o]);return n.join(", ")}),c=a.columns.addNewString("Source"),u=a.columns.addNewString("Term ID"),f=a.columns.addNewString("Term Name"),p=a.columns.addNewFloat("FDR"),d=a.columns.addNewInt("Gene Count"),m=a.columns.addNewFloat("Gene Ratio"),h=a.columns.addNewString("Intersection");c.init(t=>e[t].source),u.init(t=>e[t].native),f.init(t=>e[t].name),p.init(t=>e[t].p_value),d.init(t=>e[t].intersection_size),m.init(t=>e[t].precision),h.init(e=>s[e]);const g=p.getRawData();return a.columns.addNewBool("Significant").init(e=>g[e]!==i.FLOAT_NULL&&g[e]<=n),r&&a.columns.addNewString("Direction").init(()=>r),p.setTag("color-coding-type","Linear"),p.setTag("color-coding-linear",'{"0":"#2ecc71","0.05":"#f39c12","1":"#e74c3c"}'),a.setTag("proteomics.enrichment","true"),a}function b(e,t,n,r,o){const a=new Set,s=new Set,l=new Set;for(const[c,u]of e){l.add(u);const e=t[c],f=n[c];e!==i.FLOAT_NULL&&f!==i.FLOAT_NULL&&f<=o&&Math.abs(e)>=r&&(e>0?a.add(u):e<0&&s.add(u))}return{upGenes:[...a],downGenes:[...s],background:[...l]}}function _(e,t,n,r,o){const a=e.rowCount,s=r.getRawData(),l=o.getRawData();let c=0;for(let e=0;e<a;e++){const r=s[e],o=l[e];r!==i.FLOAT_NULL&&o!==i.FLOAT_NULL&&Math.abs(r)>=t&&o<=n&&c++}return{significant:c,total:a}}async function x(e,t,n,r,o,i=!0,c=15){const u=(0,s.I)(e);if(!u.proteinId)throw new Error("No protein ID column found");if(!u.log2fc||!u.pValue)throw new Error("No log2FC or adjusted p-value columns found. Run Differential Expression first.");let f,p=0,g=0,y=0;if(u.geneName){f=new Map;const t=u.geneName;for(let n=0;n<e.rowCount;n++){const e=t.get(n);e&&f.set(n,e)}p=f.size,g=e.rowCount,y=g-p}else{const t=new Map;for(let n=0;n<e.rowCount;n++){const e=u.proteinId.get(n),r=(0,a.S6)(e);r&&(t.has(r)||t.set(r,[]),t.get(r).push(n))}const n=[...t.keys()],o=await async function(e,t="hsapiens"){const n=await m(`${d}/api/convert/convert/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({organism:t,query:e,target:"ENSG",numeric_ns:"",output:"json"})});return(await n.json()).result??[]}(n,r),i=new Map;for(const e of o)e.incoming&&e.name&&"N/A"!==e.name&&!i.has(e.incoming)&&i.set(e.incoming,e.name);f=new Map;for(const[e,n]of t){const t=i.get(e);if(t)for(const e of n)f.set(e,t)}const s=new Array(e.rowCount).fill("");for(const[e,t]of f)s[e]=t;const c=e.columns.addNewString("Gene Symbol (mapped)");c.semType=l.iu.GENE_SYMBOL,c.init(e=>s[e]),p=i.size,g=n.length,y=g-p}const _=u.log2fc.getRawData(),x=u.pValue.getRawData(),{upGenes:N,downGenes:C,background:S}=b(f,_,x,t,n);if(0===N.length&&0===C.length)throw new Error("No significant proteins found with the given thresholds");const T=[];let E=null,P=null;if(N.length>0){let e=await h(N,S,r,o,n);if(i){const t=w(e,c);e=t.kept,E=t.stats}T.push(v(e,N,n,"Up"))}if(C.length>0){let e=await h(C,S,r,o,n);if(i){const t=w(e,c);e=t.kept,P=t.stats}T.push(v(e,C,n,"Down"))}let D=T[0];for(let e=1;e<T.length;e++)D=D.append(T[e]);D.name=e.name?`${e.name} — Enrichment`:"Enrichment Results",D.setTag("proteomics.enrichment","true");const L=D.col("FDR");if(L&&(L.setTag("color-coding-type","Linear"),L.setTag("color-coding-linear",'{"0":"#2ecc71","0.05":"#f39c12","1":"#e74c3c"}')),i){const e=(E?.total??0)+(P?.total??0),t=(E?.kept??0)+(P?.kept??0),n=(E?.droppedParents??0)+(P?.droppedParents??0);t<e&&(D.setTag("proteomics.enrichment_smart_filtered","true"),D.setTag("proteomics.enrichment_smart_filtered_kept",String(t)),D.setTag("proteomics.enrichment_smart_filtered_total",String(e)),D.setTag("proteomics.enrichment_smart_filtered_dropped_parents",String(n)),D.setTag("proteomics.enrichment_smart_filtered_cap",String(c)))}return{enrichmentDf:D,mapped:p,total:g,unmapped:y}}function N(e){if(!(0,u.RJ)(e,"Run Differential Expression first"))return;const t=(0,s.I)(e);if(!t.log2fc||!t.pValue)return void r.shell.warning("No log2FC or p-value columns found");const n=o.input.float("|log2FC| threshold",{value:l.M5});n.setTooltip("Minimum absolute fold change for significance");const a=o.input.float("Adj. p-value threshold",{value:l.Dx});a.setTooltip("Maximum adjusted p-value for significance");const d=(0,p.X3)((0,f.Di)(e)??(0,p.Vr)(e)),m=o.input.choice("Organism",{value:d??"Homo sapiens (Human)",items:p.Ae.map(e=>e.display),nullable:!1}),h=o.input.bool("GO: Biological Process",{value:!0}),g=o.input.bool("GO: Molecular Function",{value:!0}),y=o.input.bool("GO: Cellular Component",{value:!0}),w=o.input.bool("KEGG Pathways",{value:!0}),v=o.input.bool("Reactome Pathways",{value:!0}),b=o.input.bool("WikiPathways",{value:!0}),N=o.input.bool("Apply smart pathway filter",{value:!0});N.setTooltip("Drops generic GO parent terms when more specific child terms are present; caps each source at top-N by FDR. Recommended for cleaner results; uncheck for raw g:Profiler output.");const C=o.input.int("Max terms per source",{value:15,min:1});C.setTooltip("Upper bound on terms kept per enrichment source (top-N by FDR). Applies only when the smart pathway filter is on.");const S=()=>C.enabled=N.value??!0;N.onChanged.subscribe(S),S();const T=o.divText(""),E=()=>{const r=n.value??l.M5,o=a.value??l.Dx,i=_(e,r,o,t.log2fc,t.pValue),s=i.total.toLocaleString();T.textContent=`${i.significant} of ${s} proteins are significant with these thresholds`};E(),n.onChanged.subscribe(E),a.onChanged.subscribe(E),o.dialog("Enrichment Analysis").add(T).add(n).add(a).add(m).add(h).add(g).add(y).add(w).add(v).add(b).add(N).add(C).onOK(async()=>{const t=i.TaskBarProgressIndicator.create("Running enrichment analysis...");try{const t=n.value??l.M5,o=a.value??l.Dx,i=m.value,s=p.Ae.find(e=>e.display===i),u=s?.code??"hsapiens";(0,f.Np)(e,u);const d=[];if(h.value&&d.push("GO:BP"),g.value&&d.push("GO:MF"),y.value&&d.push("GO:CC"),w.value&&d.push("KEGG"),v.value&&d.push("REAC"),b.value&&d.push("WP"),0===d.length)return void r.shell.warning("Please select at least one enrichment source");const _=await x(e,t,o,u,d,N.value??!0,C.value??15),S=_.total>0?(_.mapped/_.total*100).toFixed(1):"0.0";r.shell.info(`${_.mapped}/${_.total} proteins mapped (${S}%). ${_.unmapped} unmapped.`),(0,c.q6)(_.enrichmentDf,e)}catch(e){r.shell.error(`Enrichment analysis failed: ${e.message}`)}finally{t.close()}}).show()}},252(e,t,n){"use strict";n.d(t,{$Y:()=>u,Di:()=>d,Np:()=>p,XX:()=>m,f:()=>f});var r=n(328),o=n(389),i=n(353),a=n.n(i),s=n(641),l=n(655),c=n(935);function u(e,t){e.setTag("proteomics.groups",JSON.stringify(t))}function f(e){const t=e.getTag("proteomics.groups");if(!t)return null;try{return JSON.parse(t)}catch{return null}}function p(e,t){e.setTag("proteomics.organism",t)}function d(e){return e.getTag("proteomics.organism")||void 0}function m(e){const t=e.columns.toList().filter(e=>e.semType===s.iu.INTENSITY&&e.name.startsWith("log2(")).map(e=>e.name),n=function(e,t){const n=function(e){const t=(0,l.getRunMeta)(e);if(t)return t;const n=e.getTag("proteomics.spc_run_meta_seed");if(n)try{return JSON.parse(n)}catch{return}}(e),r=f(e);if(!r)return{group1Name:"Control",group1Cols:[],group2Name:"Treatment",group2Cols:[],instrumentId:n?.instrument_id,acquisitionDatetime:n?.acquisition_datetime};const o=new Set(t),i=t=>t.filter(e=>o.has(e)).map(t=>e.col(t)).filter(e=>null!==e);return{group1Name:r.group1.name||"Control",group1Cols:i(r.group1.columns),group2Name:r.group2.name||"Treatment",group2Cols:i(r.group2.columns),instrumentId:n?.instrument_id,acquisitionDatetime:n?.acquisition_datetime}}(e,t),i=o.input.string("Group 1 Name",{value:n.group1Name}),m=o.input.columns("Group 1",{table:e,available:t,value:n.group1Cols}),h=o.input.string("Group 2 Name",{value:n.group2Name}),g=o.input.columns("Group 2",{table:e,available:t,value:n.group2Cols}),y=o.input.string("Instrument",{value:n.instrumentId??"",tooltipText:"Free-text identifier for the instrument that ran this analysis (e.g. QExactive-01). Used to group runs in the SPC dashboard."}),w=o.input.date("Acquisition datetime",{value:n.acquisitionDatetime?a()(n.acquisitionDatetime):null,tooltipText:"When the samples were acquired on the instrument. Used to order runs on the SPC trend chart — not the file-import time."}),v=o.input.choice("Organism",{value:(0,c.X3)(d(e)??(0,c.Vr)(e))??"Homo sapiens (Human)",items:c.Ae.map(e=>e.display),nullable:!1,tooltipText:"Species for enrichment (g:Profiler) and UniProt subcellular-location lookup. Auto-detected from the data when available."});o.dialog("Annotate Experiment").add(i).add(m).add(h).add(g).add(v).add(y).add(w).onOK(()=>{const t=m.value??[],n=g.value??[];if(0===t.length||0===n.length)return void r.shell.warning("Select at least one column per group");const o={group1:{name:i.value,columns:t.map(e=>e.name)},group2:{name:h.value,columns:n.map(e=>e.name)}},a=(y.value??"").trim(),s=w.value,f=s&&"function"==typeof s.toISOString||s instanceof Date?s.toISOString():"";!function(e,t){u(e,{group1:t.group1,group2:t.group2}),t.organism&&p(e,t.organism),t.runMeta&&(0,l.setRunMeta)(e,t.runMeta)}(e,{group1:o.group1,group2:o.group2,organism:(0,c.$S)(v.value??void 0),runMeta:a.length>0||f.length>0?{instrument_id:a,acquisition_datetime:f}:void 0}),r.shell.info(`Groups assigned: ${t.length} + ${n.length} samples`)}).show()}},47(e,t,n){"use strict";n.d(t,{Mx:()=>c,UN:()=>u});var r=n(328),o=n(389),i=n(82),a=n(641),s=n(252);function l(e,t){const n=Math.random(),r=Math.random();return e+t*(Math.sqrt(-2*Math.log(n))*Math.cos(2*Math.PI*r))}function c(e,t,n=10){const r=t.map(t=>e.col(t)).filter(e=>null!=e&&e.type===i.COLUMN_TYPE.FLOAT);if(0===r.length)return 0;const o=r.map(e=>e.getRawData()),a=e.rowCount,s=r.length,l=[],c=[];for(let e=0;e<a;e++){const t=new Float64Array(s),n=[];for(let o=0;o<s;o++){const i=r[o].isNone(e);n.push(i),t[o]=i?0:r[o].get(e)}l.push(t),c.push(n)}const u=new Float64Array(s);for(let e=0;e<s;e++){let t=0,n=0;for(let r=0;r<a;r++)c[r][e]||(t+=l[r][e],n++);u[e]=n>0?t/n:NaN}const f=[];for(let e=0;e<a;e++)c[e].some(e=>e)&&f.push(e);const p=i.TaskBarProgressIndicator.create("kNN imputation...");let d=0;try{for(let e=0;e<f.length;e++){const t=f[e];if(p.update(Math.round(e/f.length*100),`Row ${e+1}/${f.length}`),!c[t].some(e=>!e)){for(let e=0;e<s;e++)c[t][e]&&isFinite(u[e])&&(o[e][t]=u[e],d++);continue}const r=[];for(let e=0;e<a;e++){if(e===t)continue;let n=0,o=0;for(let r=0;r<s;r++)if(!c[t][r]&&!c[e][r]){const i=l[t][r]-l[e][r];n+=i*i,o++}o>0&&r.push({row:e,dist:Math.sqrt(n/o)})}r.sort((e,t)=>e.dist-t.dist);const i=r.slice(0,n);for(let e=0;e<s;e++){if(!c[t][e])continue;let n=0,r=0;for(const t of i)c[t.row][e]||(n+=l[t.row][e],r++);const a=r>0?n/r:u[e];isFinite(a)&&(o[e][t]=a,d++)}}}finally{p.close()}return e.fireValuesChanged(),e.setTag("proteomics.imputed","true"),d}function u(e){if("true"===e.getTag("proteomics.imputed"))return void r.shell.warning("Missing values already imputed");const t=e.columns.toList().filter(e=>e.semType===a.iu.INTENSITY&&e.name.startsWith("log2(")).map(e=>e.name),n=t.map(t=>e.col(t)),u=o.input.choice("Method",{value:"MinProb",items:["MinProb","kNN","Zero","Mean","Median"],nullable:!1}),f=o.input.columns("Intensity columns",{table:e,available:t,value:n}),p=o.input.float("Downshift",{value:1.8});p.setTooltip("Standard deviations to shift left from mean (Perseus default: 1.8)");const d=o.input.float("Width",{value:.3});d.setTooltip("Fraction of standard deviation for imputation distribution (Perseus default: 0.3)");const m=o.div([p.root,d.root]),h=o.input.int("k (neighbors)",{value:10}),g=o.div([h.root]);g.style.display="none",u.onChanged.subscribe(()=>{const e=u.value;m.style.display="MinProb"===e?"":"none",g.style.display="kNN"===e?"":"none"});const y=o.input.int("Min valid values per group",{value:2}),w=o.divText("");w.style.cssText="font-size:12px; color:#888; margin-bottom:8px;";const v=()=>{const t=y.value??0,n=(0,s.f)(e);if(0===t||!n)return void(w.textContent=`Will keep all ${e.rowCount} proteins`);const r=n.group1.columns.map(t=>e.col(t)).filter(e=>null!=e),o=n.group2.columns.map(t=>e.col(t)).filter(e=>null!=e);let i=0;for(let n=0;n<e.rowCount;n++){let e=0;for(const t of r)t.isNone(n)||e++;let a=0;for(const e of o)e.isNone(n)||a++;(e>=t||a>=t)&&i++}const a=e.rowCount-i;w.textContent=`Will keep ${i}/${e.rowCount} proteins (${a} removed)`};y.onChanged.subscribe(v),v(),o.dialog("Impute Missing Values").add(u).add(f).add(m).add(g).add(y).add(w).onOK(()=>{const t=f.value.map(e=>e.name),n=u.value,o=y.value??0,a=(0,s.f)(e);if(o>0&&a){const t=a.group1.columns.map(t=>e.col(t)).filter(e=>null!=e),n=a.group2.columns.map(t=>e.col(t)).filter(e=>null!=e),s=i.BitSet.create(e.rowCount);for(let r=0;r<e.rowCount;r++){let e=0;for(const n of t)n.isNone(r)||e++;let i=0;for(const e of n)e.isNone(r)||i++;e<o&&i<o&&s.set(r,!0)}const l=s.trueCount;l>0&&(e.rows.removeWhere(e=>s.get(e.idx)),r.shell.info(`Filtered: removed ${l} proteins below threshold`))}let m=0;try{switch(n){case"MinProb":m=function(e,t,n=1.8,r=.3){let o=0;for(const a of t){const t=e.col(a);if(!t)continue;if(t.type!==i.COLUMN_TYPE.FLOAT)continue;const s=t.stats.avg,c=t.stats.stdev;if(isNaN(s)||isNaN(c)||0===c)continue;const u=s-n*c,f=r*c,p=t.getRawData();for(let t=0;t<e.rowCount;t++)p[t]===i.FLOAT_NULL&&(p[t]=l(u,f),o++)}return e.fireValuesChanged(),e.setTag("proteomics.imputed","true"),o}(e,t,p.value,d.value);break;case"kNN":m=c(e,t,h.value);break;case"Zero":m=function(e,t){let n=0;for(const r of t){const t=e.col(r);if(!t||t.type!==i.COLUMN_TYPE.FLOAT)continue;const o=t.getRawData();for(let t=0;t<e.rowCount;t++)o[t]===i.FLOAT_NULL&&(o[t]=0,n++)}return e.fireValuesChanged(),e.setTag("proteomics.imputed","true"),n}(e,t);break;case"Mean":m=function(e,t){let n=0;for(const r of t){const t=e.col(r);if(!t||t.type!==i.COLUMN_TYPE.FLOAT)continue;const o=t.stats.avg;if(isNaN(o))continue;const a=t.getRawData();for(let t=0;t<e.rowCount;t++)a[t]===i.FLOAT_NULL&&(a[t]=o,n++)}return e.fireValuesChanged(),e.setTag("proteomics.imputed","true"),n}(e,t);break;case"Median":m=function(e,t){let n=0;for(const r of t){const t=e.col(r);if(!t||t.type!==i.COLUMN_TYPE.FLOAT)continue;const o=t.stats.med;if(isNaN(o))continue;const a=t.getRawData();for(let t=0;t<e.rowCount;t++)a[t]===i.FLOAT_NULL&&(a[t]=o,n++)}return e.fireValuesChanged(),e.setTag("proteomics.imputed","true"),n}(e,t)}}catch(e){return void r.shell.error(`Imputation failed: ${e?.message??e}. Valid-values filter was already applied; data remains filtered but un-imputed.`)}r.shell.info(`Imputed ${m} missing values across ${t.length} columns (${n})`)}).show()}},871(e,t,n){"use strict";n.d(t,{Kb:()=>c});var r=n(328),o=n(389),i=n(641),a=n(954);function s(e){return e.columns.toList().filter(e=>e.semType===i.iu.INTENSITY&&!e.name.startsWith("log2(")).map(e=>e.name)}function l(e,t){for(const n of t){const t=e.col(n),r=e.col(`log2(${n})`);if(t&&r)for(let n=0;n<e.rowCount;n++){if(t.isNone(n)||r.isNone(n))continue;const e=Number(t.get(n)),o=Number(r.get(n));if(e>0&&Number.isFinite(o)){if(Math.abs(o-Math.log2(e))<1e-4)return"transform";if(Math.abs(o-e)<1e-4)return"copy"}}}return"unknown"}function c(e){const t=s(e);if(0===t.length)return void r.shell.warning("No intensity columns found — nothing to rescale.");const n=l(e,t),i=(0,a.eY)(e,t),c=o.input.bool("Data is already log2-transformed",{value:"copy"===n,tooltipText:"On: intensities are used as-is. Off: a log2 transform is applied. Flip this if fold changes look wildly off — the import heuristic can misread small-magnitude raw intensities as already-log2."}),u=o.divText(`Auto-detection: ${i.message}.`+("unknown"!==n?` Currently applied: ${"copy"===n?"used as-is (no transform)":"log2-transformed"}.`:""));u.style.cssText="font-style:italic;color:#888;margin:4px 0;font-size:12px;max-width:420px;";const f=["proteomics.normalized","proteomics.imputed","proteomics.de_complete"].some(t=>"true"===e.getTag(t)),p=o.divText("Normalize / Impute / Differential Expression have already run. Changing the scale resets those steps — re-run them from Analyze.");p.style.cssText="color:#b26a00;margin:4px 0;font-size:12px;max-width:420px;",p.style.display=f?"":"none",o.dialog("Set Log2 Scale").add(c).add(u).add(p).onOK(()=>{const t=function(e,t){const n=s(e);if(0===n.length)return!1;if(l(e,n)===(t?"copy":"transform"))return!1;for(const t of n){const n=`log2(${t})`;e.col(n)&&e.columns.remove(n)}t?(0,a.l3)(e,n):(0,a.Kh)(e,n);for(const t of["proteomics.normalized","proteomics.imputed","proteomics.de_complete","proteomics.de_method"])e.setTag(t,"");return!0}(e,c.value);t?r.shell.info(c.value?"Intensities are now used as-is (no log2 transform). Re-run analysis steps.":"Intensities are now log2-transformed. Re-run analysis steps."):r.shell.info("Scale unchanged.")}).show()}},350(e,t,n){"use strict";n.d(t,{v5:()=>u});var r=n(328),o=n(389),i=n(82),a=n(641),s=n(715);function l(e,t){for(const n of t){const t=e.col(n);if(!t)continue;if(t.type!==i.COLUMN_TYPE.FLOAT){console.warn(`medianNormalize: skipping non-float column "${n}" (type=${t.type})`);continue}const r=t.stats.med;if(isNaN(r))continue;const o=t.getRawData();for(let e=0;e<o.length;e++)t.isNone(e)||(o[e]-=r)}e.fireValuesChanged(),e.setTag("proteomics.normalized","true")}function c(e,t){if(t.length<2)return;const n=t.map(t=>e.col(t)).filter(e=>null!=e&&e.type===i.COLUMN_TYPE.FLOAT);if(n.length<2)return;const r=e.rowCount,o=[];for(const e of n){const t=e.getRawData(),n=[];for(let t=0;t<r;t++)e.isNone(t)||n.push(t);n.sort((e,n)=>t[e]-t[n]),o.push({indices:n,raw:t})}const a=Math.max(...o.map(e=>e.indices.length));if(0===a)return;const s=new Float64Array(a);for(let e=0;e<a;e++){let t=0,n=0;for(const r of o){if(0===r.indices.length)continue;const o=e/(a-1)*(r.indices.length-1),i=Math.floor(o),s=Math.min(Math.ceil(o),r.indices.length-1),l=o-i;t+=(1-l)*r.raw[r.indices[i]]+l*r.raw[r.indices[s]],n++}s[e]=t/n}for(const e of o){const t=e.indices.length;if(0!==t)for(let n=0;n<t;n++){const r=1===a?0:n/(t-1)*(a-1),o=Math.floor(r),i=Math.min(Math.ceil(r),a-1),l=r-o,c=(1-l)*s[o]+l*s[i];e.raw[e.indices[n]]=c}}e.fireValuesChanged(),e.setTag("proteomics.normalized","true")}function u(e){if("true"===e.getTag("proteomics.normalized"))return void r.shell.warning("Data already normalized");const t=e.columns.toList().filter(e=>e.semType===a.iu.INTENSITY&&e.name.startsWith("log2(")).map(e=>e.name),n=t.map(t=>e.col(t)),u=o.div([],{style:{background:"#FFF3CD",border:"1px solid #FFEEBA",color:"#856404",padding:"8px",margin:"4px 0",borderRadius:"4px",display:"true"===e.getTag("proteomics.preNormalized")?"":"none"}});u.textContent="This data may be pre-normalized (Spectronaut). Additional normalization may distort results.";const f=o.input.choice("Method",{value:"Median Centering",items:["Median Centering","Quantile","VSN"],nullable:!1}),p=o.input.columns("Intensity columns",{table:e,available:t,value:n}),d=o.div([],{style:{width:"100%",height:"250px",border:"1px solid #ddd",marginTop:"8px"}});function m(){d.innerHTML="";const t=p.value.map(e=>e.name);if(0===t.length)return;const n=e.clone(null,t),r=f.value;"Median Centering"===r?l(n,t):"Quantile"===r&&c(n,t);const o=(0,s.j4)(n,t),a=i.Viewer.boxPlot(o,{valueColumnName:"Intensity",categoryColumnName:"Sample"});a.root.style.width="100%",a.root.style.height="220px",d.appendChild(a.root)}f.onChanged.subscribe(()=>m()),p.onChanged.subscribe(()=>m()),m(),o.dialog("Normalize").add(u).add(f).add(p).add(d).onOK(async()=>{const t=p.value.map(e=>e.name),n=f.value;"Median Centering"===n?l(e,t):"Quantile"===n?c(e,t):"VSN"===n&&await async function(e,t){try{const n=[],o=[];for(const r of t)if(r.startsWith("log2(")&&r.endsWith(")")){const t=r.slice(5,-1);e.col(t)&&(n.push(t),o.push(r))}if(0===n.length)return t.length<2?void r.shell.warning("Cannot normalize — VSN needs raw intensity columns and quantile fallback needs at least 2 columns"):(r.shell.warning("No raw intensity columns found for VSN — using quantile normalization"),void c(e,t));const a=i.DataFrame.create(e.rowCount);for(let t=0;t<n.length;t++){const r=e.col(n[t]).getRawData();a.columns.addNewFloat(`s${t+1}`).init(e=>r[e])}const s=await r.functions.call("Proteomics:VsnNormalize",{exprDf:a});for(let t=0;t<o.length;t++){const n=e.col(o[t]),r=s.col(`s${t+1}`),a=n.getRawData(),l=r.getRawData();for(let t=0;t<e.rowCount;t++)l[t]!==i.FLOAT_NULL&&(a[t]=l[t])}e.fireValuesChanged(),e.setTag("proteomics.normalized","true")}catch(n){if(console.warn("VSN normalization failed, using quantile fallback:",n),t.length<2)return void r.shell.warning("VSN failed and quantile fallback needs at least 2 columns — data left unnormalized");r.shell.warning("R environment unavailable — using quantile normalization"),c(e,t)}}(e,t),r.shell.info(`Normalized ${t.length} columns (${n})`)}).show()}},883(e,t,n){"use strict";n.d(t,{$G:()=>T,OI:()=>S,loadBaseline:()=>v,loadRuns:()=>w,oF:()=>x,saveBaseline:()=>b,upsertRun:()=>y});var r=n(328),o=n(82);const i=["run_id","instrument_id","acquisition_datetime","run_label","median_intensity","missing_pct","control_corr","protein_count","status","rules_tripped","source_project_id","source_df_name","computed_at"],a="spc.runs.schema_version";function s(e){return e&&e.root?e.root:"System:AppData/Proteomics/spc"}function l(e){return`${s(e)}/runs.csv`}function c(e){return`${s(e)}/runs-meta.json`}function u(e,t){return`${s(t)}/baseline-${function(e){if(null==e)return"unnamed";let t=String(e).replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-{2,}/g,"-").replace(/^[-.]+|[-.]+$/g,"").slice(0,64).replace(/[-.]+$/g,"");return 0===t.length&&(t="unnamed"),t}(e)}.json`}function f(e){return e.indexOf(",")<0&&e.indexOf('"')<0&&e.indexOf("\n")<0?e:'"'+e.replace(/"/g,'""')+'"'}function p(e){const t=[];let n=0;for(;n<e.length;)if('"'===e[n]){n++;let r="";for(;n<e.length;)if('"'===e[n]){if('"'!==e[n+1]){n++;break}r+='"',n+=2}else r+=e[n],n++;t.push(r),","===e[n]&&n++}else{let r="";for(;n<e.length&&","!==e[n];)r+=e[n],n++;t.push(r),","===e[n]&&n++}return t}function d(e){return[e.run_id,e.instrument_id,e.acquisition_datetime,e.run_label,String(e.median_intensity),String(e.missing_pct),String(e.control_corr),String(e.protein_count),e.status,JSON.stringify(e.rules_tripped),null==e.source_project_id?"":e.source_project_id,e.source_df_name,e.computed_at].map(f).join(",")}function m(e){const t=t=>e[(e=>i.indexOf(e))(t)]??"";let n=[];try{const e=t("rules_tripped");e&&(n=JSON.parse(e))}catch{}const r=t("source_project_id");return{run_id:t("run_id"),instrument_id:t("instrument_id"),acquisition_datetime:t("acquisition_datetime"),run_label:t("run_label"),median_intensity:Number(t("median_intensity")),missing_pct:Number(t("missing_pct")),control_corr:Number(t("control_corr")),protein_count:Number(t("protein_count")),status:t("status"),rules_tripped:n,source_project_id:0===r.length?null:r,source_df_name:t("source_df_name"),computed_at:t("computed_at")}}async function h(e){const t=l(e);if(!await r.dapi.files.exists(t))return[];const n=function(e){const t=[],n=e.split("\n").filter(e=>e.length>0);for(const e of n)t.push(p(e));return t}(await r.dapi.files.readAsText(t));return n.length<=1?[]:n.slice(1).map(m)}async function g(e){const t=c(e);if(!await r.dapi.files.exists(t))return{};try{return JSON.parse(await r.dapi.files.readAsText(t))}catch(e){return console.warn(`[spc-storage] failed to parse ${t}: ${e}`),{}}}async function y(e,t){const n=await h(t),o=n.findIndex(t=>t.instrument_id===e.instrument_id&&t.acquisition_datetime===e.acquisition_datetime);let s;o>=0?(s={...n[o],...e,run_id:n[o].run_id,rules_tripped:e.rules_tripped,source_project_id:e.source_project_id},n[o]=s):(s={run_id:e.run_id??("undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"r-"+Math.random().toString(16).slice(2)+"-"+Date.now().toString(16)),instrument_id:e.instrument_id,acquisition_datetime:e.acquisition_datetime,run_label:e.run_label,median_intensity:e.median_intensity,missing_pct:e.missing_pct,control_corr:e.control_corr,protein_count:e.protein_count,status:e.status,rules_tripped:e.rules_tripped,source_project_id:e.source_project_id,source_df_name:e.source_df_name,computed_at:e.computed_at},n.push(s)),await r.dapi.files.writeAsText(l(t),function(e){const t=[i.map(f).join(",")];for(const n of e)t.push(d(n));return t.join("\n")+"\n"}(n));const u=await async function(e){return(await g(e))[a]??null}(t);return"1"!==u&&await async function(e,t){const n=await g(t);n[a]=e,await async function(e,t){await r.dapi.files.writeAsText(c(t),JSON.stringify(e,null,2))}(n,t)}("1",t),s}async function w(e,t){const n=await h(t),r=e?n.filter(t=>t.instrument_id===e):n;return r.sort((e,t)=>e.acquisition_datetime.localeCompare(t.acquisition_datetime)),r}async function v(e,t){const n=u(e,t);if(!await r.dapi.files.exists(n))return null;try{return JSON.parse(await r.dapi.files.readAsText(n))}catch(e){return console.warn(`[spc-storage] failed to parse baseline at ${n}: ${e}`),null}}async function b(e,t,n){await r.dapi.files.writeAsText(u(e,n),JSON.stringify(t,null,2))}function _(e){const t=e.length;if(0===t)return{mean:NaN,sd:NaN};let n=0;for(const t of e)n+=t;const r=n/t;let o=0;for(const t of e){const e=t-r;o+=e*e}return{mean:r,sd:t>1?Math.sqrt(o/(t-1)):0}}function x(e,t=2){const n=e.slice(),r=[],o=[];if(n.length<3)return{retained_run_ids:n.map(e=>e.run_id),excluded_run_ids:[],iteration_trace:[]};for(let e=1;e<=t;e++){const t=n.map(e=>e.value).filter(e=>Number.isFinite(e)),{mean:i,sd:a}=_(t);if(!Number.isFinite(a)||0===a)break;const s=[];for(let e=n.length-1;e>=0;e--){const t=n[e].value;if(!Number.isFinite(t))continue;const o=(t-i)/a;Math.abs(o)>3&&(s.push(n[e]),r.push(n[e]),n.splice(e,1))}if(0===s.length)break;o.push({iter:e,dropped:s.map(e=>e.run_id)})}return{retained_run_ids:n.map(e=>e.run_id),excluded_run_ids:r.map(e=>e.run_id),iteration_trace:o}}const N=["median_intensity","missing_pct","control_corr","protein_count"];function C(e){const t=e.filter(e=>Number.isFinite(e));if(t.length<2)return{mean:NaN,sd:NaN};const{mean:n,sd:r}=_(t);return{mean:n,sd:r}}function S(e){const t={};for(const n of N)t[n]=C(e.map(e=>e[n]));return t}function T(e){const t=t=>e.map(t),n=[o.Column.fromStrings("run_id",t(e=>e.run_id)),o.Column.fromStrings("instrument_id",t(e=>e.instrument_id)),o.Column.fromList(o.COLUMN_TYPE.DATE_TIME,"acquisition_datetime",t(e=>Date.parse(e.acquisition_datetime))),o.Column.fromStrings("run_label",t(e=>e.run_label)),o.Column.fromFloat32Array("median_intensity",new Float32Array(t(e=>e.median_intensity))),o.Column.fromFloat32Array("missing_pct",new Float32Array(t(e=>e.missing_pct))),o.Column.fromFloat32Array("control_corr",new Float32Array(t(e=>e.control_corr))),o.Column.fromFloat32Array("protein_count",new Float32Array(t(e=>e.protein_count))),o.Column.fromStrings("status",t(e=>e.status)),o.Column.fromStrings("rules_tripped",t(e=>JSON.stringify(e.rules_tripped))),o.Column.fromStrings("source_project_id",t(e=>e.source_project_id??"")),o.Column.fromStrings("source_df_name",t(e=>e.source_df_name)),o.Column.fromStrings("computed_at",t(e=>e.computed_at))];return o.DataFrame.fromColumns(n)}},655(e,t,n){"use strict";n.d(t,{Mj:()=>r,classifyStatus:()=>h,computeSpcMetrics:()=>c,getRunMeta:()=>i,kY:()=>u,setRunMeta:()=>o,setSpcStatus:()=>g,uV:()=>m});const r=3.267;function o(e,t){e.setTag("proteomics.spc_run_meta",JSON.stringify(t))}function i(e){const t=e.getTag("proteomics.spc_run_meta");if(!t)return null;try{return JSON.parse(t)}catch{return null}}function a(e,t){if(e.isNone(t))return!0;const n=e.get(t);return!("number"!=typeof n||!Number.isNaN(n))}function s(e,t){const n=e.length;if(n<3)return NaN;let r=0,o=0;for(let i=0;i<n;i++)r+=e[i],o+=t[i];const i=r/n,a=o/n;let s=0,l=0,c=0;for(let r=0;r<n;r++){const n=e[r]-i,o=t[r]-a;s+=n*o,l+=n*n,c+=o*o}const u=Math.sqrt(l*c);return 0===u?NaN:s/u}function l(e,t){const n=[];for(const r of t){const t=e.col(r);null!==t&&n.push(t)}return n}function c(e,t,n){const r=l(e,t.group1.columns),o=l(e,t.group2.columns),i=r.concat(o),c=t.group1.columns.length+t.group2.columns.length,u=[],f=e.rowCount;let p=0,d=0,m=0;for(let e=0;e<f;e++){let t=!1;for(const n of i)d++,a(n,e)?p++:(u.push(n.get(e)),t=!0);t&&m++}const h=function(e){if(0===e.length)return NaN;const t=e.slice().sort((e,t)=>e-t),n=t.length,r=Math.floor(n/2);return n%2==0?(t[r-1]+t[r])/2:t[r]}(u),g=0===d?NaN:p/d*100;let y=NaN;if(r.length>=2){let e=0,t=0;for(let n=0;n<r.length;n++)for(let o=n+1;o<r.length;o++){const i=r[n],l=r[o],c=[],u=[];for(let e=0;e<f;e++)a(i,e)||a(l,e)||(c.push(i.get(e)),u.push(l.get(e)));const p=s(c,u);Number.isNaN(p)||(e+=p,t++)}y=0===t?NaN:e/t}return{median_intensity:h,missing_pct:g,control_corr:y,protein_count:m,sample_count:c,computed_at:(new Date).toISOString()}}function u(){const e={nelson_1:!0,nelson_2:!1,nelson_3:!1,nelson_4:!1,nelson_5:!0,nelson_6:!1,nelson_7:!1,nelson_8:!1};return{median_intensity:{...e},missing_pct:{...e},control_corr:{...e},protein_count:{...e}}}const f={nelson_1:function(e){const t=e.z.length-1;return Math.abs(e.z[t])>3},nelson_2:function(e){if(e.series.length<9)return!1;const t=e.series.slice(-9),n=t.every(t=>t>e.mean),r=t.every(t=>t<e.mean);return n||r},nelson_3:function(e){if(e.series.length<6)return!1;const t=e.series.slice(-6);let n=!0,r=!0;for(let e=1;e<6;e++)t[e]>t[e-1]||(n=!1),t[e]<t[e-1]||(r=!1);return n||r},nelson_4:function(e){if(e.series.length<14)return!1;const t=e.series.slice(-14).map(t=>t>e.mean?1:t<e.mean?-1:0);for(let e=1;e<t.length;e++){if(0===t[e]||0===t[e-1])return!1;if(t[e]===t[e-1])return!1}return!0},nelson_5:function(e){if(e.z.length<3){const t=e.z;if(t.length<2)return!1;const n=t.filter(e=>e>2).length,r=t.filter(e=>e<-2).length;return n>=2||r>=2}const t=e.z.slice(-3),n=t.filter(e=>e>2).length,r=t.filter(e=>e<-2).length;return n>=2||r>=2},nelson_6:function(e){if(e.z.length<5)return!1;const t=e.z.slice(-5),n=t.filter(e=>e>1).length,r=t.filter(e=>e<-1).length;return n>=4||r>=4},nelson_7:function(e){return!(e.z.length<15)&&e.z.slice(-15).every(e=>Math.abs(e)<1)},nelson_8:function(e){return!(e.z.length<8)&&e.z.slice(-8).every(e=>Math.abs(e)>1)}},p=["nelson_1","nelson_2","nelson_3","nelson_4","nelson_5","nelson_6","nelson_7","nelson_8"];function d(e,t,n,r,o){if(0===e.length||!Number.isFinite(n)||0===n)return{status:"pass",rulesTripped:[]};const i=e.map(e=>(e-t)/n),a={series:e,z:i,mean:t,sd:n},s=[];for(const e of p)r[e]&&f[e](a)&&s.push(o?`${e}@${o}`:e);return{status:h(s),rulesTripped:s}}function m(e,t,n,r){const o=[],i=["median_intensity","missing_pct","control_corr","protein_count"];for(const a of i){const i=e[a];if(!Number.isFinite(i))continue;const s=d(t[a].concat([i]),n[a].mean,n[a].sd,r[a],a);for(const e of s.rulesTripped)o.push(e)}return{status:h(o),rulesTripped:o}}function h(e){if(0===e.length)return"pass";for(const t of e)if(t.startsWith("nelson_1@")||"nelson_1"===t)return"out_of_control";return"flagged"}function g(e,t,n){e.setTag("proteomics.spc_metrics",JSON.stringify(t)),e.setTag("proteomics.spc_status",n.status),e.setTag("proteomics.spc_rules_tripped",JSON.stringify(n.rulesTripped));const r=function(e,t){return e.columns.contains(t)&&e.columns.remove(t),e.columns.addNewString(t)}(e,"~spc_metrics_meta"),o=JSON.stringify({metrics:t,status:n.status,rulesTripped:n.rulesTripped});0!==e.rowCount&&r.set(0,o)}},623(e,t,n){"use strict";n.d(t,{Jn:()=>i,Kf:()=>w,Pd:()=>h,er:()=>u,n0:()=>g});var r=n(328);const o={Nucleus:["nucleus","nuclear","nucleoplasm","chromatin","nucleolus","nuclear envelope","nuclear membrane","nuclear pore","nuclear speck","cajal body","nuclear body"],Cytoplasm:["cytoplasm","cytosol","cytoplasmic","cytoskeleton","microtubule","actin","intermediate filament","sarcomere","myofibril","z disc","z disk","spindle","centriole","centrosome","cilium","flagellum","stress fiber"],Mitochondria:["mitochondria","mitochondrial","mitochondrion","mitochondrial matrix","mitochondrial membrane","mitochondrial inner membrane","mitochondrial outer membrane","mitochondrial intermembrane space"],ER:["endoplasmic reticulum","sarcoplasmic reticulum","rough endoplasmic reticulum","smooth endoplasmic reticulum","er-golgi intermediate compartment","ergic"],Golgi:["golgi","trans-golgi","golgi apparatus","golgi membrane","cis-golgi","trans-golgi network","tgn"],"Plasma Membrane":["plasma membrane","cell membrane","cell surface","tight junction","gap junction","adherens junction","desmosome","focal adhesion","cell junction","synapse","postsynaptic","presynaptic","neuromuscular junction"],Lysosome:["lysosome","lysosomal","vacuole","lysosomal membrane","autophagosome","phagosome"],Peroxisome:["peroxisome","peroxisomal","glyoxysome"],Ribosome:["ribosome","ribosomal","ribosomal protein","polysome"],Extracellular:["extracellular","secreted","extracellular space","extracellular matrix","basement membrane","basal lamina","collagen","ecm"],Vesicles:["vesicle","endosome","transport vesicle","secretory vesicle","early endosome","late endosome","recycling endosome","clathrin-coated vesicle","coated vesicle"]},i={Nucleus:4278190080|parseInt("FF6B6B",16),Cytoplasm:4278190080|parseInt("ECDC44",16),Mitochondria:4278190080|parseInt("45B7D1",16),ER:4278190080|parseInt("96CEB4",16),Golgi:4278190080|parseInt("FAAFFE",16),"Plasma Membrane":4278190080|parseInt("DDA0DD",16),Lysosome:4278190080|parseInt("F39C12",16),Peroxisome:4278190080|parseInt("E17055",16),Ribosome:4278190080|parseInt("A29BFE",16),Extracellular:4278190080|parseInt("FD79A8",16),Vesicles:4278190080|parseInt("FDCB6E",16),Unknown:4278190080|parseInt("CCCCCC",16)};function a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e){if(!e)return null;const t=e.toLowerCase();let n=null,r=1/0;for(const e of Object.keys(o))for(const i of o[e]){const o=new RegExp("\\b"+a(i)+"\\b","i").exec(t);o&&o.index<r&&(r=o.index,n=e)}return n}function l(e,t){const n=t??"";let r=s(e??"");return r||(r=s(n),r||"Unknown")}const c={hsapiens:9606,mmusculus:10090,rnorvegicus:10116,scerevisiae:4932,ecoli:562,drerio:7955,dmelanogaster:7227,athaliana:3702,celegans:6239},u="proteomics-subcell-loc",f="13-04-1",p="__schema_v",d=new Set([...Object.keys(o),"Unknown"]);function m(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function h(e,t,n){const r=new Array(e.length);let o=0;const i=Math.min(Math.max(1,t),e.length||1),a=[];for(let t=0;t<i;t++)a.push((async()=>{for(;;){const t=o++;if(t>=e.length)return;r[t]=await n(e[t],t)}})());return await Promise.all(a),r}async function g(e,t,n){const o=[...new Set(e.filter(e=>e&&e.length>0))],i=await async function(){try{const e=await r.dapi.userDataStorage.get(u)??{};return e[p]!==f?{[p]:f}:e}catch{return{[p]:f}}}(),a=new Map,s=[];for(const e of o){const t=i[e];void 0!==t&&d.has(t)?a.set(e,t):s.push(e)}const g=new Map,y={},w=function(e){const t=e?c[e]:void 0;return t?` AND (taxonomy_id:${t})`:""}(t),v=async()=>{if(0!==Object.keys(y).length)try{await r.dapi.userDataStorage.put(u,{...i,...y,[p]:f})}catch(e){console.warn(`Subcellular-location cache write failed: ${e?.message??e}`)}},b=setInterval(()=>{v().catch(()=>{})},5e3);try{const e=m(s,100),t=e.length;let i=0;await h(e,6,async e=>{const o=e.map(e=>`accession:${e}`).join(" OR "),s=`https://rest.uniprot.org/uniprotkb/stream?query=(${encodeURIComponent(o)})&fields=accession,cc_subcellular_location,go_c,reviewed,gene_primary&format=tsv`;try{const e=await r.dapi.fetchProxy(s);if(!e.ok)return void console.warn(`UniProt stream returned status ${e.status}; continuing`);const{locByAcc:t,geneByAcc:n}=function(e){const t=new Map,n=new Map,r=new Map,o=e.trim().split("\n");for(let e=1;e<o.length;e++){const i=o[e];if(!i)continue;const a=i.split("\t"),s=(a[0]??"").trim();if(!s)continue;const c=a[1]??"",u=a[2]??"",f="reviewed"===(a[3]??"").toLowerCase(),p=(a[4]??"").trim(),d=l(c,u);t.has(s)?f&&"Unknown"!==d?(t.set(s,d),r.set(s,!0)):"Unknown"===t.get(s)&&"Unknown"!==d&&(t.set(s,d),r.set(s,f)):(t.set(s,d),r.set(s,f)),!p||n.has(s)&&!f||n.set(s,p)}return{locByAcc:t,geneByAcc:n,reviewedByAcc:r}}(await e.text());for(const[e,n]of t)a.set(e,n),y[e]=n;for(const[e,t]of n)g.set(e,t)}catch(e){console.warn(`UniProt stream batch failed: ${e?.message??e}; continuing`)}i++,n?.(i,t,"fetch-acc")});const c=new Map;for(const e of s){const t=a.get(e)??"Unknown",n=g.get(e);"Unknown"===t&&n&&(c.has(n)||c.set(n,[]),c.get(n).push(e))}const u=m([...c.keys()],20),f=u.length;let p=0;await h(u,6,async e=>{const t=e.map(e=>`gene_exact:${e}`).join(" OR "),o=`https://rest.uniprot.org/uniprotkb/stream?query=(${encodeURIComponent(t)}) AND (reviewed:true)${encodeURIComponent(w)}&fields=accession,gene_primary,cc_subcellular_location,go_c&format=tsv`;try{const e=await r.dapi.fetchProxy(o);if(!e.ok)return void console.warn(`UniProt gene fallback returned status ${e.status}; continuing`);const t=(await e.text()).trim().split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t"),r=(n[1]??"").trim(),o=l(n[2]??"",n[3]??"");if(r&&"Unknown"!==o)for(const e of c.get(r)??[])a.set(e,o),y[e]=o}}catch(e){console.warn(`UniProt gene fallback batch failed: ${e?.message??e}; continuing`)}p++,n?.(p,f,"fetch-gene")});for(const e of o)a.has(e)||a.set(e,"Unknown"),void 0===y[e]&&(y[e]=a.get(e))}finally{clearInterval(b),await v()}const _=new Map;for(const e of o)_.set(e,a.get(e)??"Unknown");return _}const y=new Map;async function w(e){if(y.has(e))return y.get(e)??null;const t=`https://rest.uniprot.org/uniprotkb/${encodeURIComponent(e)}.json?fields=accession,protein_name,gene_names,organism_name,cc_function,go`;try{const n=await r.dapi.fetchProxy(t);if(!n.ok)return console.warn(`UniProt fetch for ${e} returned status ${n.status}`),y.set(e,null),null;const o=await n.json();return y.set(e,o),o}catch(t){return console.warn(`UniProt fetch for ${e} failed:`,t?.message??t),null}}},110(e,t,n){"use strict";n.r(t),n.d(t,{PackageFunctions:()=>Oe,_package:()=>Te,annotateExperiment:()=>te,buildProteomicsTopMenu:()=>K,computeSpcStatus:()=>ae,differentialExpression:()=>ie,dockComparisonFilterIfMultiContrast:()=>Me,enrichmentAnalysis:()=>me,enrichmentCharts:()=>ge,exportEnrichmentInputs:()=>he,importFragPipe:()=>X,importGenericMatrix:()=>ee,importMaxQuant:()=>Z,importSpectronaut:()=>J,importSpectronautCandidates:()=>Q,imputeMissingValues:()=>oe,initProteomics:()=>W,normalizeProteomics:()=>re,openCandidatesAnalysisView:()=>Ie,proteomicsDemo:()=>ye,proteomicsEnrichmentDemo:()=>we,publishedAnalysisPanelWidget:()=>_e,recoverPublishedProjectsOnStartup:()=>xe,setLog2Scale:()=>ne,shareAnalysisForReview:()=>be,showAllVisualizations:()=>de,showGroupMeanCorrelation:()=>ue,showHeatmap:()=>le,showPcaPlot:()=>ce,showQcDashboard:()=>fe,showSpcDashboard:()=>pe,showVolcanoPlot:()=>se,sniffIsPrecursor:()=>De,uniprotPanelWidget:()=>ve});var r=n(328),o=n(389),i=n(82),a=n(713),s=n(312),l=n(53),c=n(86),u=n(119),f=n(641),p=n(304);const d=["primary protein id","pg.proteingroups","protein id","uniprot","accession"];function m(e,t=0){if(0===e.rowCount||t<0||t>=e.rowCount)return;const n=(0,p.k)(e,f.iu.PROTEIN_ID,d);n&&(e.currentCell=e.cell(t,n.name),r.shell.windows.showContextPanel=!0,async function(){const e=["Proteomics","UniProt"];for(let t=0;t<12;t++){await new Promise(e=>setTimeout(e,250));try{const t=document.querySelector('[d4-title="semantic meta.Proteomics-ProteinId"]');if(!t)continue;let n=!0;for(const r of e){const e=Array.from(t.querySelectorAll(".d4-accordion-pane-header")).find(e=>e.textContent?.trim()===r);e?e.classList.contains("expanded")||(e.click(),n=!1):n=!1}if(n)return}catch{}}}())}var h=n(954),g=n(117);function y(){i.Utils.openFile({accept:".csv,.tsv,.txt",open:e=>{const t=new FileReader;t.onload=()=>{try{const n=t.result,a=(0,h.T6)(n);!function(e,t){const n=(0,h.q2)(e),a=(0,h.YL)(e),s=(0,h.WI)(e),l=o.input.column("Protein ID",{table:e,filter:e=>e.type===i.COLUMN_TYPE.STRING,value:n??void 0}),c=o.input.column("Gene Name (optional)",{table:e,filter:e=>e.type===i.COLUMN_TYPE.STRING,value:a??void 0,nullable:!0}),u=e.columns.toList().filter(e=>e.type===i.COLUMN_TYPE.FLOAT||e.type===i.COLUMN_TYPE.INT||e.type===i.COLUMN_TYPE.BIG_INT).map(e=>e.name),p=o.input.columns("Intensity Columns",{table:e,available:u,value:s.map(t=>e.col(t)).filter(e=>null!=e)}),d=(0,h.eY)(e,s),y=o.input.bool("Log2 Transform",{value:!d.isLog2}),w=o.divText(d.message);w.style.cssText="font-style:italic;color:#888;margin-bottom:8px;font-size:12px;";const v=document.createElement("div");function b(){const t=[],n=l.value;n&&t.push(n.name);const r=c.value;r&&t.push(r.name);const a=(p.value??[]).map(e=>e.name);if(t.push(...a),0!==t.length)try{const n=i.BitSet.create(e.rowCount,e=>e<5),r=e.clone(n,t),a=i.Viewer.grid(r);v.innerHTML="";const s=o.divText(`Preview: ${t.length} columns, 5 rows`);s.style.cssText="font-size:11px;color:#888;padding:2px 4px;",a.root.style.cssText="width:100%;height:180px;",v.appendChild(s),v.appendChild(a.root)}catch{v.innerHTML='<div style="padding:8px;color:#888">Unable to generate preview</div>'}else v.innerHTML='<div style="padding:8px;color:#888">Select columns to preview</div>'}v.style.cssText="border:1px solid #ddd;margin-top:8px;width:100%;",l.onChanged.subscribe(()=>b()),c.onChanged.subscribe(()=>b()),p.onChanged.subscribe(()=>{(function(){const t=(p.value??[]).map(e=>e.name);if(0===t.length)return void(w.textContent="Select intensity columns");const n=(0,h.eY)(e,t);w.textContent=n.message,y.value=!n.isLog2})(),b()}),b(),o.dialog("Import Generic Matrix").add(l).add(c).add(p).add(y).add(o.div([w])).add(v).onOK(async()=>{const n=l.value;if(!n)return void r.shell.warning("Please select a Protein ID column");const o=(p.value??[]).map(e=>e.name);if(0===o.length)return void r.shell.warning("Please select at least one intensity column");n.semType=f.iu.PROTEIN_ID;const i=c.value;i&&(i.semType=f.iu.GENE_SYMBOL),y.value?(0,h.Kh)(e,o):(0,h.l3)(e,o),(0,h.wK)(e,n.name,"Primary Protein ID",f.iu.PROTEIN_ID),i&&(0,h.wK)(e,i.name,"Primary Gene Name",f.iu.GENE_SYMBOL),e.setTag("proteomics.source","generic"),await(0,g.rv)(e),e.name=t.replace(/\.[^.]+$/,""),r.shell.addTableView(e),r.shell.info(`Imported ${e.rowCount} proteins from ${t}`),m(e)}).show()}(i.DataFrame.fromCsv(n,{delimiter:a}),e.name)}catch(e){r.shell.error("Failed to parse file: "+e.message)}},t.readAsText(e)}})}var w=n(252),v=n(935),b=n(655),_=n(883),x=n(350),N=n(871),C=n(989),S=n(47),T=n(829),E=n(70),P=n(623);async function D(e,t){const n=t?.topN??50,r=t?.labelCol??"Gene Name";if("true"!==e.getTag("proteomics.de_complete"))throw new Error("Differential expression must be run first");const o=(0,w.f)(e);if(!o)throw new Error("Experimental groups must be annotated first");const a=e.col("adj.p-value");if(!a)throw new Error("adj.p-value column not found");const s=[];for(let t=0;t<e.rowCount;t++)a.isNone(t)||s.push({idx:t,pVal:a.get(t)});s.sort((e,t)=>e.pVal-t.pVal);const l=new Set;for(let e=0;e<Math.min(n,s.length);e++)l.add(s[e].idx);const c=i.BitSet.create(e.rowCount);for(const e of l)c.set(e,!0);const u=e.clone(c),d=[...o.group1.columns,...o.group2.columns],m=[];for(const t of d){const n=`_zscore_${t}`;m.push(n);const r=e.col(t);if(!r)continue;const o=r.getRawData();let a=0,s=0,l=0;for(let t=0;t<e.rowCount;t++){const e=o[t];e!==i.FLOAT_NULL&&(a+=e,s+=e*e,l++)}const c=l>0?a/l:0,f=l>1?(s-a*a/l)/(l-1):0,p=Math.sqrt(f),d=u.col(t);if(!d)continue;const h=d.getRawData();u.columns.addNewFloat(n).init(e=>{return h[e]===i.FLOAT_NULL?i.FLOAT_NULL:(t=h[e],(n=p)>0?(t-c)/n:0);var t,n})}const h=u.plot.grid();for(let e=0;e<h.columns.length;e++){const t=h.columns.byIndex(e);t&&(t.visible=!1)}const g=(0,p.k)(u,f.iu.GENE_SYMBOL,[r.toLowerCase(),"gene symbol"])??(0,p.k)(u,f.iu.PROTEIN_ID,["protein id","majority protein id","accession"]);if(g){const e=h.columns.byName(g.name);e&&(e.visible=!0)}const y=o.group1.columns.map(e=>`_zscore_${e}`),v=o.group2.columns.map(e=>`_zscore_${e}`);for(const e of[...y,...v]){const t=h.columns.byName(e);t&&(t.visible=!0)}let b=!1;const _=i.TaskBarProgressIndicator.create("Calculating distance matrix...");try{const e=i.Func.find({package:"Dendrogram",name:"hierarchicalClustering"})[0];if(!e)throw new Error("Dendrogram package not installed (hierarchicalClustering not found)");if(4!==e.inputs.length)throw new Error(`Dendrogram.hierarchicalClustering signature changed (expected 4 inputs, got ${e.inputs.length})`);await e.apply({df:h,colNameList:m,distance:"euclidean",linkage:"complete"}),b=!0}catch(e){console.warn(`Dendrogram clustering unavailable, falling back to significance-based row ordering: ${e?.message??e}`)}finally{_.close()}if(!b){const e=u.col("adj.p-value")?"adj.p-value":u.col("adj.p.value")?"adj.p.value":null;e&&h.sort([e])}return h.props.isHeatmap=!0,h.props.isGrid=!1,t?.title&&h.setOptions({title:t.title}),h}const L=["#2196F3","#FF5722"];function A(e,t,n=64){const r=e.length;if(r<3)return null;let o=0,i=0;for(let n=0;n<r;n++)o+=e[n],i+=t[n];o/=r,i/=r;let a=0,s=0,l=0;for(let n=0;n<r;n++){const r=e[n]-o,c=t[n]-i;a+=r*r,s+=r*c,l+=c*c}a/=r-1,s/=r-1,l/=r-1;const c=a+l,u=a*l-s*s,f=Math.sqrt(Math.max(c*c/4-u,0)),p=c/2+f,d=c/2-f;if(p<=0||d<=0)return null;let m;m=Math.abs(s)>1e-12?Math.atan2(p-a,s):a>=l?0:Math.PI/2;const h=Math.sqrt(5.991*p),g=Math.sqrt(5.991*d),y=[],w=Math.cos(m),v=Math.sin(m);for(let e=0;e<n;e++){const t=2*Math.PI*e/n,r=h*Math.cos(t),a=g*Math.sin(t),s=o+w*r-v*a,l=i+v*r+w*a;y.push([s,l])}return y}function M(e,t,n,r){const{pcaDf:o,varianceExplained:a}=function(e,t,n,r=2){const o=t.length,a=e.rowCount,s=[],l=new Array(a).fill(0),c=new Array(a).fill(0);for(const n of t){const t=e.col(n);if(t)for(let e=0;e<a;e++)t.isNone(e)||(l[e]+=t.get(e),c[e]++)}for(let e=0;e<a;e++)l[e]=c[e]>0?l[e]/c[e]:0;for(const n of t){const t=e.col(n),r=new Array(a);for(let e=0;e<a;e++)!t||t.isNone(e)?r[e]=l[e]:r[e]=t.get(e);s.push(r)}const u=new Array(a).fill(0);for(let e=0;e<a;e++){for(let t=0;t<o;t++)u[e]+=s[t][e];u[e]/=o}for(let e=0;e<o;e++)for(let t=0;t<a;t++)s[e][t]-=u[t];const f=function(e,t,n){const r=[];for(let o=0;o<n;o++){const n=new Array(t);for(let r=0;r<t;r++)n[r]=e[r][o];r.push(n)}return r}(s,o,a),p=function(e,t,n,r,o){const i=[];for(let a=0;a<n;a++){const n=new Array(o).fill(0);for(let i=0;i<r;i++){const r=e[a][i];for(let e=0;e<o;e++)n[e]+=r*t[i][e]}i.push(n)}return i}(s,f,o,a,o),d=a>1?a-1:1;for(let e=0;e<o;e++)for(let t=0;t<o;t++)p[e][t]/=d;const{eigenvalues:m,eigenvectors:h}=function(e,t){const n=e.map(e=>[...e]),r=[];for(let e=0;e<t;e++){const n=new Array(t).fill(0);n[e]=1,r.push(n)}let o=!1;for(let e=0;e<100;e++){let e=0,i=0,a=1;for(let r=0;r<t;r++)for(let o=r+1;o<t;o++)Math.abs(n[r][o])>e&&(e=Math.abs(n[r][o]),i=r,a=o);if(e<1e-10){o=!0;break}const s=(n[a][a]-n[i][i])/(2*n[i][a]),l=Math.sign(s)/(Math.abs(s)+Math.sqrt(s*s+1)),c=1/Math.sqrt(l*l+1),u=l*c,f=n[i][i],p=n[a][a],d=n[i][a];n[i][i]=c*c*f-2*u*c*d+u*u*p,n[a][a]=u*u*f+2*u*c*d+c*c*p,n[i][a]=0,n[a][i]=0;for(let e=0;e<t;e++)if(e!==i&&e!==a){const t=n[e][i],r=n[e][a];n[e][i]=c*t-u*r,n[i][e]=n[e][i],n[e][a]=u*t+c*r,n[a][e]=n[e][a]}for(let e=0;e<t;e++){const t=r[e][i],n=r[e][a];r[e][i]=c*t-u*n,r[e][a]=u*t+c*n}}o||console.warn(`PCA Jacobi did not converge in 100 iterations (n=${t}); results may be approximate`);const i=new Array(t);for(let e=0;e<t;e++)i[e]=n[e][e];const a=Array.from({length:t},(e,t)=>t);a.sort((e,t)=>i[t]-i[e]);const s=a.map(e=>i[e]),l=[];for(let e=0;e<t;e++){const n=new Array(t);for(let o=0;o<t;o++)n[o]=r[e][a[o]];l.push(n)}return{eigenvalues:s,eigenvectors:l}}(p,o),g=[];for(let e=0;e<o;e++){const t=[];for(let n=0;n<Math.min(r,o);n++){const r=m[n]>0?Math.sqrt(m[n]):0;t.push(h[e][n]*r)}g.push(t)}const y=m.reduce((e,t)=>e+Math.max(t,0),0),w=[];for(let e=0;e<Math.min(r,o);e++){const t=y>0?Math.max(m[e],0)/y*100:0;w.push(Math.round(10*t)/10)}const v=w.length>0&&isFinite(w[0])?w[0]:0,b=o>=2?`PC1 (${v}%)`:"PC1",_=w.length>=2&&isFinite(w[1])?w[1]:0,x=r>=2&&w.length>=2&&o>=2?`PC2 (${_}%)`:"PC2",N=[i.Column.fromStrings("SampleName",t),i.Column.fromFloat32Array(b,new Float32Array(g.map(e=>e[0])))];if(r>=2){const e=i.Column.fromFloat32Array(x,new Float32Array(g.map(e=>e.length>1?e[1]:0)));N.push(e)}const C=t.map(e=>n.group1.columns.includes(e)?n.group1.name:n.group2.columns.includes(e)?n.group2.name:"Unknown"),S=i.Column.fromStrings("Group",C);N.push(S);const T=i.DataFrame.fromColumns(N);return T.name="PCA",{pcaDf:T,varianceExplained:w}}(e,t,n),s=o.columns.toList().find(e=>e.name.startsWith("PC1"))?.name,l=o.columns.toList().find(e=>e.name.startsWith("PC2"))?.name;if(!s||!l)throw new Error("PCA did not produce PC1/PC2 columns — too few samples?");const c=o.plot.scatter({x:s,y:l,color:"Group"});c.props.labelColumnNames=["SampleName"],c.props.displayLabels="Always";try{const e=o.col(s),t=o.col(l),r=o.col("Group"),i=[n.group1.name,n.group2.name];for(let n=0;n<i.length;n++){const a=i[n],u=[],f=[];for(let n=0;n<o.rowCount;n++)r.get(n)===a&&(u.push(e.get(n)),f.push(t.get(n)));const p=A(u,f);if(p){const e=L[n%L.length],t={type:"area",area:p,fillColor:e,opacity:.15,outlineColor:e,outlineWidth:1,x:s,y:l};c.meta.annotationRegions?.add(t)}}}catch(e){console.warn("PCA: could not add confidence ellipses:",e?.message??e)}return r&&c.setOptions({title:r}),{viewer:c,pcaDf:o}}var I=n(715);const O=["M","A","MA_trend","CV_group1","meanInt_group1","CV_group2","meanInt_group2"];function F(e){const t=i.TaskBarProgressIndicator.create("Creating QC dashboard...");try{const t=(0,w.f)(e);if(!t)return void r.shell.warning("Annotate experimental groups first (Proteomics | Annotate Experiment)");for(const t of O)e.columns.contains(t)&&e.columns.remove(t);const n=(0,I.Hc)(e);if(0===n.length)return void r.shell.warning("No log2 intensity columns found");(0,I.iQ)(e,t),(0,I.Pq)(e),(0,I.JZ)(e,t.group1.columns,"CV_group1","meanInt_group1"),(0,I.JZ)(e,t.group2.columns,"CV_group2","meanInt_group2");const o=r.shell.tv;if(!o)return void r.shell.warning("No table view open");const a={xColumnName:"A",yColumnName:"M",title:"MA Plot",markerDefaultSize:2};if("true"===e.getTag("proteomics.de_complete"))try{const t=(0,E.EO)(e,f.M5,f.Dx);a.colorColumnName=t}catch(e){}const s=o.addViewer(i.VIEWER.SCATTER_PLOT,a),l="${M} = 0";e.meta.formulaLines.items=e.meta.formulaLines.items.filter(e=>e.formula!==l),e.meta.formulaLines.addLine({formula:l,color:"#888888",width:1,visible:!0});const c=o.addViewer(i.VIEWER.SCATTER_PLOT,{xColumnName:"A",yColumnName:"MA_trend",title:"MA Trend",markerDefaultSize:1}),u=o.addViewer(i.VIEWER.SCATTER_PLOT,{xColumnName:"meanInt_group1",yColumnName:"CV_group1",title:"CV Plot",markerDefaultSize:2}),p=o.addViewer(i.VIEWER.CORR_PLOT,{xColumnNames:n,yColumnNames:n,title:"Sample Correlation"}),d=(0,I.ho)(e,n),m=i.Viewer.grid(d);m.props.allowColSelection=!1;const h=(0,I.rA)(e,n,t),g=i.Viewer.barChart(h,{splitColumnName:"Sample",valueColumnName:"MissingPct",stackColumnName:"Group"}),y=(0,I.j4)(e,n),v=i.Viewer.boxPlot(y,{valueColumnName:"Intensity",categoryColumnName:"Sample"}),b=o.dockManager,_=b.dock(s,i.DOCK_TYPE.RIGHT,null,"MA Plot",.75);b.dock(c,i.DOCK_TYPE.FILL,_,"MA Trend"),b.dock(u,i.DOCK_TYPE.FILL,_,"CV Plot");const x=b.dock(p,i.DOCK_TYPE.DOWN,_,"Sample Correlation",.5);b.dock(v,i.DOCK_TYPE.FILL,x,"Intensity Distributions"),b.dock(g,i.DOCK_TYPE.FILL,x,"Missing % per Sample"),b.dock(m,i.DOCK_TYPE.FILL,x,"Missing Values");const N=e=>{try{const t=b.findNode(e.root);t?.parent&&t.parent.container.setActiveChild(t.container)}catch{}};N(s),N(p)}finally{t.close()}}var $=n(589),R=n(644),k=n(498),U=n(771);function B(e){if(null==e)return"unknown date";try{if(e instanceof Date)return Number.isNaN(e.getTime())?"unknown date":e.toISOString().slice(0,10);const t=new Date(e);return Number.isNaN(t.getTime())?"unknown date":t.toISOString().slice(0,10)}catch{return"unknown date"}}function V(e,t){const n=o.divText(e);n.style.fontWeight="600",n.style.fontSize="12px",n.style.color="#666";const r=o.divText(t);r.style.marginBottom="8px";const i=o.div([n,r]);return i.style.marginBottom="6px",i}var G=n(807),H=n(637);var j=n(649),q=n(230),Y=n(897);const z=["Import","Annotate Experiment...","Analyze","Visualize","Share"];async function W(){await Oe.initProteomics()}async function K(){await Oe.buildProteomicsTopMenu()}async function Q(){await Oe.importSpectronautCandidates()}async function J(){await Oe.importSpectronaut()}async function Z(){await Oe.importMaxQuant()}async function X(){await Oe.importFragPipe()}async function ee(){await Oe.importGenericMatrix()}async function te(){await Oe.annotateExperiment()}async function ne(){await Oe.setLog2Scale()}async function re(){await Oe.normalizeProteomics()}async function oe(){await Oe.imputeMissingValues()}async function ie(){await Oe.differentialExpression()}async function ae(){await Oe.computeSpcStatus()}async function se(){await Oe.showVolcanoPlot()}async function le(){await Oe.showHeatmap()}async function ce(){await Oe.showPcaPlot()}async function ue(){await Oe.showGroupMeanCorrelation()}async function fe(){await Oe.showQcDashboard()}async function pe(){await Oe.showSpcDashboard()}async function de(){await Oe.showAllVisualizations()}async function me(){await Oe.enrichmentAnalysis()}async function he(){await Oe.exportEnrichmentInputs()}async function ge(){await Oe.enrichmentCharts()}async function ye(){await Oe.proteomicsDemo()}async function we(){await Oe.proteomicsEnrichmentDemo()}function ve(e){return Oe.uniprotPanelWidget(e)}async function be(){await Oe.shareAnalysisForReview()}function _e(e){return Oe.publishedAnalysisPanelWidget(e)}async function xe(){await Oe.recoverPublishedProjectsOnStartup()}var Ne=function(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a},Ce=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Se=function(e,t){return function(n,r){t(n,r,e)}};const Te=new i.Package;function Ee(e,t){return"spectronaut-candidates"!==e.getTag("proteomics.source")||(r.shell.warning(`${t} needs per-sample intensities, but this table is a Spectronaut Candidates report (one row per protein per comparison — pre-computed DE only). Import the matching Spectronaut Report (Proteomics | Import | Spectronaut Report) to enable per-sample analyses, or stick to Volcano / Enrichment / UniProt panel on this one.`),!1)}r.decorators||(r.decorators={}),["func","init","param","panel","editor","demo","app","appTreeBrowser","fileHandler","fileExporter","model","viewer","filter","cellRenderer","autostart","dashboard","folderViewer","semTypeDetector","packageSettingsEditor","functionAnalysis","converter","fileViewer","treeBrowser","polyfill"].forEach(e=>{r.decorators[e]||(r.decorators[e]=function(e){return function(e,t,n){}})});const Pe=["EG.ModifiedPeptide","FG.Charge","PEP.StrippedSequence"];async function De(e){const t=e.stream().pipeThrough(new TextDecoderStream("utf-8")).getReader();try{let e="";const n=1048576;for(;e.indexOf("\n")<0&&e.length<n;){const{value:n,done:r}=await t.read();if(r)break;e+=n}const r=e.indexOf("\n");let o=r>=0?e.slice(0,r):e;return o.endsWith("\r")&&(o=o.slice(0,-1)),Pe.some(e=>o.includes(e))}finally{await t.cancel()}}let Le=[];function Ae(e){if((0,w.Di)(e))return;const t=(0,v.Vr)(e);t&&(0,w.Np)(e,t)}function Me(e,t){const n=c.g.reduce((e,n)=>e??t.col(n),null);if(!n)return!1;const r=new Set;for(let e=0;e<t.rowCount;e++){const t=n.get(e);"string"==typeof t&&t.length>0&&r.add(t)}if(r.size<=1)return!1;const o=(0,p.k)(t,f.iu.DISPLAY_NAME,["display name"]),s=(0,p.k)(t,f.iu.SOURCE_ID,["source id"]),l=(0,p.k)(t,f.iu.PROTEIN_ID,["primary protein id","protein id","uniprot","accession"]),u=[n.name];o&&u.push(o.name),s&&u.push(s.name),!o&&l&&u.push(l.name);const d=i.Viewer.filters(t,{columnNames:u,showBoolCombinedFilter:!1,showHeader:!0,showSearchBox:!0});e.dockManager.dock(d,i.DOCK_TYPE.RIGHT,null,"Filters",.3);for(const e of Le)e.unsubscribe();Le=[];const m=i.BitSet.create(t.rowCount);m.copyFrom(t.filter);let h=!1;return Le.push(t.onFilterChanged.pipe((0,a.debounceTime)(100)).subscribe(()=>{if(h)return;const n=[];for(let e=0;e<t.rowCount;e++)t.filter.get(e)&&n.push(e);if(n.length===t.rowCount)return void m.copyFrom(t.filter);h=!0;try{t.filter.copyFrom(m)}finally{h=!1}t.selection.setAll(!1,!1);for(const e of n)t.selection.set(e,!0,!1);t.selection.fireChanged();const r=(()=>{for(const t of e.viewers)if(t.type===i.VIEWER.SCATTER_PLOT&&"negLog10P"===t.props.yColumnName)return t;return null})();r&&(0,E.XC)(t,r,(0,E.m2)(t),n)})),!0}function Ie(e){const t=r.shell.addTableView(e);r.shell.info(`Imported ${e.rowCount} candidates from Spectronaut`);try{t.addViewer((0,E.gO)(e))}catch(e){r.shell.warning(`Imported, but could not auto-open the volcano: ${e?.message??e}. Open it via Proteomics | Visualize | Volcano Plot.`)}return Me(t,e),m(e),t}class Oe{static async initProteomics(){}static async buildProteomicsTopMenu(){const e={importSpectronautCandidates:()=>Oe.importSpectronautCandidates(),importSpectronaut:()=>Oe.importSpectronaut(),importMaxQuant:()=>Oe.importMaxQuant(),importFragPipe:()=>Oe.importFragPipe(),importGenericMatrix:()=>Oe.importGenericMatrix(),annotateExperiment:()=>Oe.annotateExperiment(),setLog2Scale:()=>Oe.setLog2Scale(),normalize:()=>Oe.normalizeProteomics(),impute:()=>Oe.imputeMissingValues(),differentialExpression:()=>Oe.differentialExpression(),enrichmentAnalysis:()=>Oe.enrichmentAnalysis(),exportEnrichmentInputs:()=>Oe.exportEnrichmentInputs(),computeSpcStatus:()=>Oe.computeSpcStatus(),showVolcanoPlot:()=>Oe.showVolcanoPlot(),showHeatmap:()=>Oe.showHeatmap(),showPcaPlot:()=>Oe.showPcaPlot(),showGroupMeanCorrelation:()=>Oe.showGroupMeanCorrelation(),showQcDashboard:()=>Oe.showQcDashboard(),showSpcDashboard:()=>Oe.showSpcDashboard(),enrichmentCharts:()=>Oe.enrichmentCharts(),showAllVisualizations:()=>Oe.showAllVisualizations(),shareAnalysisForReview:()=>Oe.shareAnalysisForReview()},t=new WeakSet,n=n=>{n?.type!==i.VIEW_TYPE.TABLE_VIEW||t.has(n)||setTimeout(()=>{if(!t.has(n))try{(function(e,t){if(!(n=e.dataFrame)||!n.getTag("proteomics.source"))return!1;var n;const r=e.ribbonMenu.group("Proteomics");for(const e of z)try{r.remove(e)}catch{}const o={isEnabled:()=>function(e){return e&&"spectronaut-candidates"===e.getTag("proteomics.source")?"Not applicable to a Spectronaut Candidates file — it already carries computed differential expression and has no per-sample intensities. Use Volcano Plot, Enrichment Analysis or the UniProt panel, or import the matching Spectronaut Report for sample-level analyses.":null}(e.dataFrame)},i=r.group("Import");i.item("Spectronaut Candidates...",t.importSpectronautCandidates),i.item("Spectronaut Report...",t.importSpectronaut),i.item("MaxQuant...",t.importMaxQuant),i.item("FragPipe...",t.importFragPipe),i.item("Generic Matrix...",t.importGenericMatrix),r.item("Annotate Experiment...",t.annotateExperiment,null,o);const a=r.group("Analyze");a.item("Set Log2 Scale...",t.setLog2Scale,null,o),a.item("Normalize...",t.normalize,null,o),a.item("Impute Missing Values...",t.impute,null,o),a.item("Differential Expression...",t.differentialExpression,null,o),a.item("Enrichment Analysis...",t.enrichmentAnalysis),a.item("Export Enrichment Inputs...",t.exportEnrichmentInputs),a.item("Compute SPC Status",t.computeSpcStatus,null,o);const s=r.group("Visualize");return s.item("Volcano Plot...",t.showVolcanoPlot),s.item("Heatmap...",t.showHeatmap,null,o),s.item("PCA...",t.showPcaPlot,null,o),s.item("Group-Mean Correlation...",t.showGroupMeanCorrelation,null,o),s.item("QC Dashboard...",t.showQcDashboard,null,o),s.item("SPC Dashboard...",t.showSpcDashboard),s.item("Enrichment Charts...",t.enrichmentCharts),s.item("Show All Visualizations...",t.showAllVisualizations,null,o),r.group("Share").item("Share Analysis for Review...",t.shareAnalysisForReview),!0})(n,e)&&t.add(n)}catch{}},50)};try{for(const e of r.shell.views)n(e)}catch{}r.events.onViewAdded.subscribe(n),r.events.onCurrentViewChanged.subscribe(()=>n(r.shell.v))}static async importSpectronautCandidates(){i.Utils.openFile({accept:".tsv,.txt,.csv",open:async e=>{try{const t=await e.text(),n=await(0,c.R)(t);n.name=e.name.replace(/\.[^.]+$/,""),Ae(n),Ie(n)}catch(e){r.shell.error(`Failed to import Spectronaut Candidates file: ${e?.message??e}`)}}})}static async importSpectronaut(){i.Utils.openFile({accept:".tsv,.txt,.csv",open:async e=>{try{const t=await De(e)?await(0,l.A)(e):await(0,l.parseSpectronautText)(await e.text());t.name=e.name.replace(/\.[^.]+$/,""),Ae(t),r.shell.addTableView(t),r.shell.info(`Imported ${t.rowCount} protein groups from Spectronaut`),m(t)}catch(e){r.shell.error(`Failed to import Spectronaut file: ${e?.message??e}`),r.shell.warning("If this is a very large precursor-level Spectronaut report that fails to stream in-browser, pre-aggregate it to the importable protein-group shape with the bundled duckdb fallback: tools/spectronaut-aggregate.sh <input.tsv>, then re-import the resulting file. See files/demo/README.md for usage.")}}})}static async importMaxQuant(){i.Utils.openFile({accept:".txt,.tsv",open:async e=>{try{const t=await e.text(),n=await(0,s.E)(t);n.name=e.name.replace(/\.[^.]+$/,""),Ae(n),r.shell.addTableView(n),r.shell.info(`Imported ${n.rowCount} protein groups`),m(n)}catch(e){r.shell.error(`Failed to import MaxQuant file: ${e?.message??e}`)}}})}static async importFragPipe(){i.Utils.openFile({accept:".tsv,.txt",open:async e=>{try{const t=await e.text(),n=await(0,u.p)(t);n.name=e.name.replace(/\.[^.]+$/,""),Ae(n),r.shell.addTableView(n),r.shell.info(`Imported ${n.rowCount} protein groups from FragPipe`),m(n)}catch(e){r.shell.error(`Failed to import FragPipe file: ${e?.message??e}`)}}})}static async importGenericMatrix(){y()}static async annotateExperiment(){const e=r.shell.tv?.dataFrame;e?Ee(e,"Annotate Experiment")&&(0,w.XX)(e):r.shell.warning("No table open")}static async setLog2Scale(){const e=r.shell.tv?.dataFrame;e?Ee(e,"Set Log2 Scale")&&(0,N.Kb)(e):r.shell.warning("No table open")}static async normalizeProteomics(){const e=r.shell.tv?.dataFrame;e?Ee(e,"Normalize")&&(0,x.v5)(e):r.shell.warning("No table open")}static async imputeMissingValues(){const e=r.shell.tv?.dataFrame;e?Ee(e,"Impute Missing Values")&&(0,S.UN)(e):r.shell.warning("No table open")}static async differentialExpression(){const e=r.shell.tv,t=e?.dataFrame;e&&t?Ee(t,"Differential Expression")&&(0,T.B9)(t,()=>{const n=(0,E.gO)(t);e.addViewer(n)}):r.shell.warning("No table open")}static async computeSpcStatus(){const e=r.shell.tv,t=e?.dataFrame;if(!e||!t)return void r.shell.warning("Open an analyzed file first, then run Compute SPC Status.");if("spectronaut-candidates"===t.getTag("proteomics.source"))return void r.shell.warning("SPC requires per-sample intensities. Re-import this analysis from the Spectronaut PG report (not the Candidates report) to compute SPC.");const n=(0,b.getRunMeta)(t);if(!n||!n.instrument_id||!n.acquisition_datetime)return void r.shell.warning("Open Annotate Experiment to set instrument + acquisition datetime.");const o=(0,w.f)(t);if(!o)return void r.shell.warning("Annotate experimental groups first (Proteomics → Annotate Experiment) — SPC needs Group 1 to compute control-replicate correlation.");o.group1.columns.length<2&&r.shell.info("Group 1 has fewer than 2 samples — control-replicate correlation can't be computed. The other three metrics will still be recorded.");const a=i.TaskBarProgressIndicator.create("Computing SPC status...");try{const e=(0,b.computeSpcMetrics)(t,o,n),i=await(0,_.loadBaseline)(n.instrument_id),a=await(0,_.loadRuns)(n.instrument_id),s=a.find(e=>e.acquisition_datetime===n.acquisition_datetime),l=s?.status??null;let c;if(null===i)c={status:"pass",rulesTripped:[]},r.shell.info(`No baseline locked for ${n.instrument_id} yet — recorded as pass. Define a baseline once at least 4 runs have been computed.`);else{const t={median_intensity:a.map(e=>e.median_intensity),missing_pct:a.map(e=>e.missing_pct),control_corr:a.map(e=>e.control_corr),protein_count:a.map(e=>e.protein_count)};c=(0,b.uV)(e,t,i.metrics,i.rules_enabled??(0,b.kY)())}(0,b.setSpcStatus)(t,e,c);const u={instrument_id:n.instrument_id,acquisition_datetime:n.acquisition_datetime,run_label:t.name,median_intensity:e.median_intensity,missing_pct:e.missing_pct,control_corr:e.control_corr,protein_count:e.protein_count,status:c.status,rules_tripped:c.rulesTripped,source_project_id:null,source_df_name:t.name,computed_at:e.computed_at};await(0,_.upsertRun)(u),null!==l?r.shell.info(`Updated SPC for ${t.name} (previous status: ${l}).`):"pass"===c.status?r.shell.info(`SPC computed: ${t.name} — status: pass.`):"flagged"===c.status?r.shell.info(`SPC computed: ${t.name} — flagged on ${c.rulesTripped.length} rule(s): ${c.rulesTripped.join(", ")}.`):r.shell.info(`SPC computed: ${t.name} — OUT OF CONTROL on ${c.rulesTripped.length} rule(s): ${c.rulesTripped.join(", ")}.`)}finally{a.close()}}static async showVolcanoPlot(){const e=r.shell.tv,t=e?.dataFrame;e&&t?(0,T.RJ)(t,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)")&&await Oe.volcanoOptions():r.shell.warning("No table open")}static async volcanoOptions(e){const t=r.shell.tv,n=t?.dataFrame;if(!t||!n)return void r.shell.warning("No table open");if(!(0,T.RJ)(n,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)"))return;let a=e;if(!a)for(const e of t.viewers)if(e.type===i.VIEWER.SCATTER_PLOT&&"negLog10P"===e.props.yColumnName){a=e;break}const s=a?(0,E.ur)(n,a):{metric:"adj.p-value",colorDim:"significance"},l=null!=n.col("p-value"),c=l?s.metric:"adj.p-value",u=o.input.choice("Significance metric",{value:c,items:l?["adj.p-value","p-value"]:["adj.p-value"],nullable:!1});u.setTooltip(l?"Y axis, classification and threshold line all switch together":"p-value column not present — only adj.p-value is available");const p=o.input.choice("Color by",{value:s.colorDim,items:["significance","location"],nullable:!1});p.setTooltip("significance = Enriched in g1 / Enriched in g2 / Not significant; location = UniProt subcellular location");const d=o.input.int("Label top N points",{value:(0,E.m2)(n),min:0});d.setTooltip("How many of the most significant proteins get name labels. 0 = none. Labels no longer touch your row selection.");const m=(0,E.GE)(n),h=o.input.float("X-axis max (|log2FC|)",{value:m.xMax??void 0,min:0,nullable:!0});h.setTooltip("Pin the X axis to ±this |log2FC|. Leave empty to auto-scale. Set the same value on two volcanoes to compare them side-by-side.");const g=o.input.float("Y-axis max (−log10 p)",{value:m.yMax??void 0,min:0,nullable:!0});g.setTooltip("Pin the Y axis to 0…this −log10(p). Leave empty to auto-scale. Set the same value on two volcanoes to compare them side-by-side."),o.dialog("Volcano Options").add(u).add(p).add(d).add(h).add(g).onOK(async()=>{const e=u.value??"adj.p-value",o="location"===p.value?"location":"significance";if((0,E.S6)(n,h.value??null,g.value??null),a||(a=(0,E.gO)(n,{topNLabels:0}),t.addViewer(a)),"location"===o&&!n.col(E.fQ)){const e=await r.dapi.userDataStorage.get(P.er).catch(()=>null);0===(e?Object.keys(e).filter(e=>"__schema_v"!==e).length:0)?r.shell.info("Fetching subcellular locations from UniProt — may take a minute or two on first use without cache; subsequent toggles use the cache."):r.shell.info("Resolving subcellular locations from cache.")}const s="location"===o?"Classifying subcellular locations…":"Updating volcano…",l=i.TaskBarProgressIndicator.create(s),c="location"===o;c&&(0,E.DI)(a,s);const m=(e,t,n)=>{const r="fetch-acc"===n?"Fetching subcellular locations":"fetch-gene"===n?"Resolving by gene name":"init-column"===n||"location"===o?"Classifying subcellular locations":"Updating volcano",i=t>0?Math.round(e/t*100):0;if(l.update(i,`${r}: ${e}/${t}`),c){const n=t>1?`${e}/${t} (${i}%)`:"";(0,E.Bb)(a,r,n)}};try{await(0,E.nj)(n,a,e,o,f.M5,f.Dx,m),(0,E.XC)(n,a,d.value??(0,E.m2)(n))}catch(e){r.shell.error(`Volcano update failed: ${e?.message??e}`)}finally{l.close(),c&&a&&(0,E.kX)(a)}}).show()}static async showHeatmap(){const e=r.shell.tv,t=e?.dataFrame;if(!e||!t)return void r.shell.warning("No table open");if(!Ee(t,"Heatmap"))return;if(!(0,T.RJ)(t,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)"))return;const n=o.input.int("Top N proteins",{value:50,min:1});n.setTooltip("How many of the most significant proteins (by adj. p-value) to show."),o.dialog("Heatmap Options").add(n).onOK(async()=>{const r=n.value??50,o=i.TaskBarProgressIndicator.create("Creating heatmap...");try{const n=await D(t,{topN:r,title:`Heatmap: Top ${r} DE Proteins`});e.addViewer(n)}finally{o.close()}}).show()}static async showPcaPlot(){const e=r.shell.tv,t=e?.dataFrame;if(!e||!t)return void r.shell.warning("No table open");if(!Ee(t,"PCA"))return;const n=(0,w.f)(t);if(!n)return void r.shell.warning("Annotate experimental groups first (Proteomics | Annotate Experiment)");const o=[...n.group1.columns,...n.group2.columns],{viewer:i,pcaDf:a}=M(t,o,n,"PCA: All Groups");a.name=`PCA: ${t.name}`,r.shell.addTableView(a).addViewer(i)}static async showGroupMeanCorrelation(){const e=r.shell.tv,t=e?.dataFrame;if(!e||!t)return void r.shell.warning("No table open");if(!(0,T.RJ)(t,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)"))return;if(!(0,w.f)(t))return void r.shell.warning("Annotate experimental groups first (Proteomics | Annotate Experiment)");const n=(0,R.Z7)(t);e.addViewer(n)}static async showQcDashboard(){const e=r.shell.tv,t=e?.dataFrame;e&&t?Ee(t,"QC Dashboard")&&F(t):r.shell.warning("No table open")}static async showSpcDashboard(){await(0,$.r9)()}static async showAllVisualizations(){const e=r.shell.tv,t=e?.dataFrame;if(!e||!t)return void r.shell.warning("No table open");if(!Ee(t,"Show All Visualizations"))return;if(!(0,T.RJ)(t,"Run Differential Expression first"))return;const n=(0,w.f)(t),o=(0,E.gO)(t);e.addViewer(o);const a=i.TaskBarProgressIndicator.create("Creating heatmap...");try{const n=await D(t,{title:"Heatmap: Top 50 DE Proteins"});e.addViewer(n)}finally{a.close()}if(n){const e=[...n.group1.columns,...n.group2.columns],{viewer:o,pcaDf:i}=M(t,e,n,"PCA: All Groups");i.name=`PCA: ${t.name}`,r.shell.addTableView(i).addViewer(o)}}static async enrichmentAnalysis(){const e=r.shell.tv?.dataFrame;e?(0,q.pG)(e):r.shell.warning("No table open")}static async exportEnrichmentInputs(){const e=r.shell.tv?.dataFrame;e?(0,T.RJ)(e,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)")&&(0,C.N)(e):r.shell.warning("No table open")}static async enrichmentCharts(){const e=r.shell.tv,t=e?.dataFrame;if(!t)return void r.shell.warning("No table open");if("true"!==t.getTag("proteomics.enrichment"))return void r.shell.warning("Run Enrichment Analysis first (Proteomics | Enrichment Analysis)");const n=r.shell.tables.filter(e=>"true"===e.getTag("proteomics.de_complete"));if(0===n.length)return r.shell.warning("No protein table with DE results found. Enrichment charts will open without volcano linking."),void(0,Y.q6)(t,t);n.length>1&&r.shell.warning(`Multiple protein tables with DE results found; linking enrichment to "${n[0].name}"`),(0,Y.q6)(t,n[0])}static async proteomicsDemo(){await async function(){const e=i.TaskBarProgressIndicator.create("Loading proteomics demo…");try{e.update(5,"Importing HYE benchmark (Spectronaut DIA)…");const t=await Te.files.readAsText("demo/spectronaut-hye-demo.tsv"),n=await(0,l.parseSpectronautText)(t);n.name="HYE benchmark";const o=r.shell.addTableView(n),a=(0,w.f)(n);if(!a)return void r.shell.warning("Demo: expected two auto-annotated conditions — opened the table without running differential expression.");const s=[...a.group1.columns,...a.group2.columns];e.update(40,"Imputing missing values (KNN)…"),(0,S.Mx)(n,s),n.setTag("proteomics.imputed","true"),e.update(60,"Differential expression (t-test)…"),(0,T.ps)(n,a.group1.columns,a.group2.columns,a.group1.name,a.group2.name),n.setTag("proteomics.de_method","t-test"),e.update(78,"Building volcano and heatmap…");const c=(0,E.gO)(n);o.dockManager.dock(c,i.DOCK_TYPE.RIGHT,null,"Volcano",.5);const u=await D(n,{title:"Heatmap: Top 50 DE Proteins"});o.dockManager.dock(u,i.DOCK_TYPE.DOWN,null,"Heatmap",.45),e.update(90,"Building QC dashboard tab…"),r.shell.addTableView(n).name="HYE benchmark — QC",F(n),r.shell.v=o,m(n,function(e){const t=e.col("adj.p-value"),n=e.col("significant");if(!t)return 0;let r=-1,o=1/0;for(let i=0;i<e.rowCount;i++){if(n&&!n.get(i))continue;if(t.isNone(i))continue;const e=t.get(i);e<o&&(o=e,r=i)}return r<0?0:r}(n)),e.update(100,"Done"),r.shell.info("Proteomics demo: HYE benchmark analyzed end to end (import → impute → differential expression). Yeast and E. coli proteins shift abundance between the two conditions, so the volcano separates the genuinely differential proteins from the constant human background. QC charts are on the second tab; the top hit is selected for its UniProt panel.")}finally{e.close()}}()}static async proteomicsEnrichmentDemo(){await async function(){const e=i.TaskBarProgressIndicator.create("Loading enrichment demo…");try{e.update(10,"Loading human DE result…");const t=await Te.files.readAsText("demo/enrichment-demo.csv"),n=i.DataFrame.fromCsv(t);n.name="Treatment vs Control (human)";const o=(e,t)=>{const r=n.col(e);r&&(r.semType=t)};o("Protein ID",f.iu.PROTEIN_ID),o("Gene",f.iu.GENE_SYMBOL),o("log2FC",f.iu.LOG2FC),o("p-value",f.iu.P_VALUE),o("adj.p-value",f.iu.P_VALUE),n.setTag("proteomics.source","generic"),n.setTag("proteomics.de_method","precomputed"),n.setTag("proteomics.de_complete","true"),(0,w.$Y)(n,{group1:{name:"Treatment",columns:[]},group2:{name:"Control",columns:[]}});const a=r.shell.addTableView(n),s=(0,E.gO)(n);a.dockManager.dock(s,i.DOCK_TYPE.RIGHT,null,"Volcano",.5),m(n,0),e.update(45,"Running g:Profiler enrichment (GO / KEGG / Reactome)…");try{const{enrichmentDf:t,mapped:o,total:i}=await(0,q.D9)(n,f.M5,f.Dx,"hsapiens",["GO:BP","GO:MF","GO:CC","KEGG","REAC","WP"],!0);e.update(90,"Opening enrichment charts…"),(0,Y.q6)(t,n).name=`${n.name} — Enrichment`,r.shell.v=a,r.shell.info(`Enrichment demo: ${t.rowCount} over-represented terms across ${o}/${i} genes. Up-regulated proteins are enriched for cell-cycle / mitosis; down-regulated for oxidative phosphorylation. Select a term row to highlight its proteins on the volcano.`)}catch(e){r.shell.warning(`Enrichment demo: g:Profiler enrichment could not run (${e?.message??e}). The DE table and volcano are open — retry via Proteomics | Enrichment Analysis once the service is reachable.`)}e.update(100,"Done")}finally{e.close()}}()}static uniprotPanelWidget(e){return(0,k.ku)(e)}static async shareAnalysisForReview(){const e=r.shell.tv;let t=e?.dataFrame;if(t){if("true"!==t.getTag("proteomics.de_complete")){const e=r.shell.tables.filter(e=>"true"===e.getTag("proteomics.de_complete"));if(0===e.length)return void(0,T.RJ)(t,"Run Differential Expression first (Proteomics | Analyze | Differential Expression)");e.length>1&&r.shell.warning(`Multiple analyzed tables open; sharing "${e[0].name}".`),t=e[0]}await async function(e){if("true"!==e.getTag(U.$y))return void r.shell.warning("Run Differential Expression first.");const t=await r.dapi.groups.list(),n=i.Group.defaultGroupsIds?.["All users"],a=(t??[]).filter(e=>!(null==e||e.hidden||e.personal||n&&e.id===n));if(0===a.length)return void r.shell.warning("No teams available to share with. Ask an admin to create a reviewer team.");const s=new Map;for(const e of a){const t=e.friendlyName??e.name??"";t&&!s.has(t)&&s.set(t,e)}const l=Array.from(s.keys()),c=o.input.string("Target",{value:""});c.setTooltip("Free text — your team's name for this target (e.g., MYH7-DMD, muscle-atrophy panel)");const u=o.input.choice("Share with team",{value:l[0],items:l,nullable:!1}),f=o.input.textArea?o.input.textArea("Note for reviewers",{value:""}):o.input.string("Note for reviewers",{value:""}),p=o.input.bool("Verify published dashboard",{value:(0,H.Cb)()});p.setTooltip("Re-open the shared dashboard after publishing to confirm it survives a reload. On = safer (recommended for client deliverables); off = faster share.");const d=o.div();d.style.cssText="background:#fff3cd; padding:8px; border-radius:4px; margin-bottom:8px; display:none;";const m=o.div();m.style.cssText="background:#f0f0f0; padding:8px; border-radius:4px; margin:8px 0; font-family: monospace; font-size:11px;";let h=null;const g=async()=>{const e=(c.value??"").trim(),t=u.value,n=t?s.get(t)??null:null,r=e?(0,U.fz)(e):"<no-target>",i=(new Date).toISOString().slice(0,10);if(e&&n)try{h=await(0,U.T7)(e,n)}catch{h=null}else h=null;const a=(e=>{if(!e)return 0;const t=/-v(\d+)-/.exec(e);if(!t)return 0;const n=parseInt(t[1],10);return Number.isFinite(n)?n:0})(h?h.name:null),l=a>0?a+1:1;h?(d.textContent=`⚠ This will share as v${l} and supersede "${h.name}". The previous version stays available for reference.`,d.style.display="block"):d.style.display="none";const f=`${(0,H.sK)()}-${r}-v${l}-${i}`,p=n?n.friendlyName??n.name??"<unnamed team>":"<pick a team>",g=h?`Will supersede "${h.name}" (v${l})`:"New share";m.innerHTML="",m.appendChild(o.divText(`Project: ${f}`)),m.appendChild(o.divText(`Will be visible to: ${p}`)),m.appendChild(o.divText(`Status: ${g}`)),m.appendChild(o.divText(`Date: ${i}`))};c.onChanged.subscribe(()=>{g()}),u.onChanged.subscribe(()=>{g()}),await g(),o.dialog("Share Analysis for Review").add(c).add(u).add(f).add(p).add(d).add(m).onOK(async()=>{const t=(c.value??"").trim();if(!t)return void r.shell.warning("Target is required.");const n=u.value?s.get(u.value):null;if(!n)return void r.shell.warning("Pick a team to share with.");const o={target:t,reviewerGroup:n,note:f.value??"",priorVersion:h,verify:p.value??!0};try{const t=await(0,G.M)(e,o),i=n.friendlyName??n.name??"(unnamed team)";r.shell.info(`Shared as ${t.name} with team ${i}.`)}catch(e){r.shell.error(`Share failed: ${e?.message??String(e)}`)}}).show()}(t)}else r.shell.warning("No table open")}static publishedAnalysisPanelWidget(e){return function(e){const t=(0,k.xh)(e);if(null==t)return new i.Widget(o.div());if(!(0,U.HF)(t))return new i.Widget(o.div());const n=(0,U.M4)(t);if(null==n)return new i.Widget(o.divText("Shared analysis metadata unavailable. Ask the sharer to re-share."));const a=o.div();if(a.style.padding="8px 4px",null!=n.supersededBy&&""!==n.supersededBy){const e=o.link("Newer version available — open it",async()=>{try{const e=await r.dapi.projects.find(n.supersededBy);await e.open()}catch(e){r.shell.warning(`Could not open the newer version: ${e?.message??e}`)}}),t=o.div([e]);t.style.padding="8px",t.style.marginBottom="10px",t.style.backgroundColor="#fff8dc",t.style.borderRadius="4px",a.appendChild(t)}a.appendChild(o.h2("Shared analysis details"));const s=(0,w.f)(t),l=null!=s?`${s.group2.name} vs ${s.group1.name}`:"unavailable",c=Number.isFinite(n.fcThreshold)?Math.pow(2,n.fcThreshold):NaN,u=Number.isFinite(n.fcThreshold)?`log2(${n.fcThreshold}) (${Number.isFinite(c)?c.toFixed(2):"NaN"}-fold)`:"(unknown)",f=Number.isFinite(n.pThreshold)?`${n.pThreshold} (FDR-adjusted)`:"(unknown)";a.appendChild(V("Target",n.target||"(unknown)")),a.appendChild(V("Shared",B(n.publishedAt))),a.appendChild(V("Shared by",n.publishedBy||"(unknown)")),a.appendChild(V("Method",function(e){switch(e){case"limma":return"limma — moderated t-test";case"deqms":return"DEqMS — peptide-count-aware moderated t-test";case"t-test":return"Welch t-test";case"spectronaut":return"Spectronaut Candidates (pre-computed DE)";default:return e||"(unknown method)"}}(n.deMethod))),a.appendChild(V("Comparison",l)),a.appendChild(V("Fold-change cutoff",u)),a.appendChild(V("p-value cutoff",f));const p=function(e,t){if(null!=t.publishedByEmail&&""!==t.publishedByEmail)return t.publishedByEmail;try{const t=e.col(U.MD.PUBLISHED_BY_EMAIL);if(null!=t){const e=t.get(0);if(null!=e&&""!==e)return String(e)}}catch{}try{const t=e.getTag(U.L6.PUBLISHED_BY_EMAIL);if(t)return t}catch{}return null}(t,n);if(null!=p){const e=t.name||"shared analysis",r=(0,U.Kj)({sharerEmail:p,sharerName:n.publishedBy||"colleague",projectName:e,publishedDateStr:B(n.publishedAt)}),i=o.link("Request re-run with different parameters",r);i.href=r;const s=o.div([i]);s.style.marginTop="12px",a.appendChild(s)}return new i.Widget(a)}(e)}static async recoverPublishedProjectsOnStartup(){const e=r.events.onProjectOpened??r.events.onCurrentProjectChanged??null;if(e&&"function"==typeof e.subscribe)e.subscribe(()=>{(async()=>{await new Promise(e=>setTimeout(e,200));const e=r.shell.tables;if(Array.isArray(e))for(const t of e)if((0,U.HF)(t))try{await(0,j.I)(t)}catch(e){r.shell.warning(`Could not auto-recover shared analysis on open: ${e?.message??e}`)}})()});else{const e=r.events.onViewAdded;e&&"function"==typeof e.subscribe&&e.subscribe(e=>{if(e instanceof i.TableView){const t=e.dataFrame;t&&(0,U.HF)(t)&&(0,j.I)(t).catch(e=>{r.shell.warning(`Could not auto-recover shared analysis on open: ${e?.message??e}`)})}})}}}Ne([r.decorators.init({tags:["init"]}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"initProteomics",null),Ne([r.decorators.func({tags:["autostart"],meta:{autostartImmediate:"true"}}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"buildProteomicsTopMenu",null),Ne([r.decorators.func({"top-menu":"Proteomics | Import | Spectronaut Candidates..."}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"importSpectronautCandidates",null),Ne([r.decorators.func({"top-menu":"Proteomics | Import | Spectronaut Report..."}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"importSpectronaut",null),Ne([r.decorators.func({"top-menu":"Proteomics | Import | MaxQuant..."}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"importMaxQuant",null),Ne([r.decorators.func({"top-menu":"Proteomics | Import | FragPipe..."}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"importFragPipe",null),Ne([r.decorators.func({"top-menu":"Proteomics | Import | Generic Matrix..."}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"importGenericMatrix",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"annotateExperiment",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"setLog2Scale",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"normalizeProteomics",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"imputeMissingValues",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"differentialExpression",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"computeSpcStatus",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showVolcanoPlot",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showHeatmap",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showPcaPlot",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showGroupMeanCorrelation",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showQcDashboard",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showSpcDashboard",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"showAllVisualizations",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"enrichmentAnalysis",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"exportEnrichmentInputs",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"enrichmentCharts",null),Ne([r.decorators.func({name:"Proteomics Demo",description:"End-to-end proteomics differential-expression analysis on the HYE benchmark: import → impute → differential expression → volcano + heatmap, with a QC dashboard tab and the top hit pre-selected for its UniProt panel",meta:{demoPath:"Proteomics | Differential Expression",isDemoDashboard:"true"}}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"proteomicsDemo",null),Ne([r.decorators.func({name:"Proteomics Enrichment Demo",description:"Pathway enrichment (g:Profiler GO / KEGG / Reactome / WikiPathways) on a human differential-expression result — cell-cycle up, oxidative-phosphorylation down — with the enrichment charts cross-linked to the volcano",meta:{demoPath:"Proteomics | Enrichment Analysis",isDemoDashboard:"true"}}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"proteomicsEnrichmentDemo",null),Ne([r.decorators.panel({name:"Proteomics | UniProt",description:"UniProt protein details",meta:{role:"widgets"}}),Se(0,r.decorators.param({options:{semType:"Proteomics-ProteinId"}})),Ce("design:type",Function),Ce("design:paramtypes",[String]),Ce("design:returntype",i.Widget)],Oe,"uniprotPanelWidget",null),Ne([r.decorators.func(),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"shareAnalysisForReview",null),Ne([r.decorators.panel({name:"Proteomics | Shared Analysis",description:"Audit context for a shared analysis snapshot",meta:{role:"widgets"}}),Se(0,r.decorators.param({options:{semType:"Proteomics-ProteinId"}})),Ce("design:type",Function),Ce("design:paramtypes",[String]),Ce("design:returntype",i.Widget)],Oe,"publishedAnalysisPanelWidget",null),Ne([r.decorators.func({tags:["autostart"],meta:{autostartImmediate:"true"}}),Ce("design:type",Function),Ce("design:paramtypes",[]),Ce("design:returntype",Promise)],Oe,"recoverPublishedProjectsOnStartup",null)},498(e,t,n){"use strict";n.d(t,{S6:()=>u,ku:()=>p,xh:()=>f});var r=n(328),o=n(389),i=n(82),a=n(623),s=n(252),l=n(304),c=n(641);function u(e){if(!e||!e.trim())return null;const t=e.split(";")[0].trim();if(!t)return null;const n=t.match(/^(?:sp|tr)\|([A-Za-z0-9_-]+)\|/);if(n)return n[1];const r=t.match(/^([A-Za-z0-9]+?)ups\|/i);if(r)return r[1];if(t.includes("|"))return t.split("|")[0].trim();const o=t.match(/^([A-Za-z0-9_-]+)$/);return o?o[1].replace(/ups$/i,""):null}function f(e){if(!e)return null;const t=[];for(const n of r.shell.tables){if(!(0,s.f)(n))continue;const r=(0,l.k)(n,c.iu.PROTEIN_ID,["primary protein id","protein id","uniprot","accession"]);if(r)for(let o=0;o<n.rowCount;o++){const i=r.get(o);if(i&&u(i)===e){t.push(n);break}}}if(0===t.length)return null;const n=r.shell.tv?.dataFrame??null;return n&&t.includes(n)?n:t[0]}function p(e){const t=u(e);return t?new i.Widget(o.wait(async()=>{const e=await async function(e){return await(0,a.Kf)(e)}(t);return e?function(e,t){const n=document.createElement("div"),r=o.link(`UniProt: ${t}`,`https://www.uniprot.org/uniprot/${t}`,"Open full UniProt entry");r.style.fontWeight="bold",r.style.display="block",r.style.marginBottom="8px",n.appendChild(r);const a=function(e){return e.proteinDescription?.recommendedName?.fullName?.value??e.proteinDescription?.submissionNames?.[0]?.fullName?.value??"Unknown"}(e),p=e.genes?.[0]?.geneName?.value??"Unknown",d=e.organism?.scientificName??"Unknown",m=e.comments?.find(e=>"FUNCTION"===e.commentType);let h=m?.texts?.[0]?.value??"";h.length>200&&(h=h.substring(0,200)+"...");const g={Protein:a,Gene:p,Organism:d};h&&(g.Function=h),n.appendChild(o.tableFromMap(g));const y=function(e){const t=[],n=[],r=[];for(const o of e.uniProtKBCrossReferences??[]){if("GO"!==o.database)continue;const e=o.properties?.find(e=>"GoTerm"===e.key)?.value??"";e.startsWith("F:")?t.push(e.substring(2)):e.startsWith("P:")?n.push(e.substring(2)):e.startsWith("C:")&&r.push(e.substring(2))}return{mf:t,bp:n,cc:r}}(e),w=[{label:"Molecular Function",terms:y.mf},{label:"Biological Process",terms:y.bp},{label:"Cellular Component",terms:y.cc}];if(w.some(e=>e.terms.length>0)){const e=o.divText("GO Terms");e.style.fontWeight="bold",e.style.marginTop="8px",e.style.marginBottom="4px",n.appendChild(e);for(const e of w){if(0===e.terms.length)continue;const t=o.divText(e.label);t.style.fontWeight="bold",t.style.fontSize="0.9em",t.style.marginTop="4px",n.appendChild(t);const r=e.terms.slice(0,5).join(", "),i=o.divText(r);i.style.fontSize="0.85em",i.style.marginLeft="8px",n.appendChild(i)}}const v=f(t);if(v){const e=o.divText("Per-Group Quantities");e.style.fontWeight="bold",e.style.marginTop="8px",e.style.marginBottom="4px",n.appendChild(e);const r=function(e,t){const n=(0,s.f)(e);if(!n)return null;const r=(0,l.k)(e,c.iu.PROTEIN_ID,["primary protein id","protein id","uniprot","accession"]);if(!r)return null;let a=-1;for(let n=0;n<e.rowCount;n++){const e=r.get(n);if(e&&u(e)===t){a=n;break}}if(a<0)return null;const f=[n.group1,n.group2].map(t=>{const n=t.columns.map(t=>e.col(t)).filter(e=>null!=e).map(e=>e.isNone(a)?NaN:e.get(a)).filter(e=>"number"==typeof e&&!isNaN(e)&&e!==i.FLOAT_NULL),r=n.length;if(0===r)return{name:t.name,mean:NaN,sd:NaN,n:0};const o=n.reduce((e,t)=>e+t,0)/r,s=r>1?n.reduce((e,t)=>e+(t-o)**2,0)/(r-1):0;return{name:t.name,mean:o,sd:Math.sqrt(s),n:r}});if(f.every(e=>0===e.n))return o.divText("No per-group quantities available for this protein");const p=Math.max(...f.map(e=>isNaN(e.mean)?0:e.mean+(isNaN(e.sd)?0:e.sd))),d=p>0?p:1,m=e=>96-e/d*72,h=e=>"#"+(16777215&e).toString(16).padStart(6,"0").toUpperCase(),g=[h(c.PL.enrichedG1),h(c.PL.enrichedG2)],y="http://www.w3.org/2000/svg",w=document.createElementNS(y,"svg");w.setAttribute("width",String(200)),w.setAttribute("height",String(120)),f.forEach((e,t)=>{const n=24+40*t;if(0===e.n)return;const r=m(e.mean),o=document.createElementNS(y,"rect");if(o.setAttribute("x",String(n)),o.setAttribute("y",String(r)),o.setAttribute("width",String(24)),o.setAttribute("height",String(Math.max(0,96-r))),o.setAttribute("fill",g[t]??h(c.PL.notSig)),w.appendChild(o),e.n>1&&!isNaN(e.sd)){const t=n+12,r=m(e.mean+e.sd),o=m(e.mean-e.sd),i=document.createElementNS(y,"line");i.setAttribute("x1",String(t)),i.setAttribute("x2",String(t)),i.setAttribute("y1",String(r)),i.setAttribute("y2",String(o)),i.setAttribute("stroke","#333"),i.setAttribute("stroke-width","1"),w.appendChild(i)}const i=document.createElementNS(y,"text");i.setAttribute("x",String(n+12)),i.setAttribute("y",String(116)),i.setAttribute("text-anchor","middle"),i.setAttribute("font-size","10"),i.textContent=`${e.name} (n=${e.n})`,w.appendChild(i)});const v=o.divV([w]);return f.forEach(e=>{if(e.n>0){const t=o.divText(`${e.name}: mean=${e.mean.toFixed(2)} SD=${e.sd.toFixed(2)}`);t.style.fontSize="0.85em",v.appendChild(t)}}),v}(v,t);n.appendChild(r??o.divText("No per-group quantities available for this protein"))}return n}(e,t):o.divText(`Unable to fetch UniProt data for ${t}`)})):new i.Widget(o.divText("No valid UniProt accession found"))}},119(e,t,n){"use strict";n.d(t,{p:()=>m});var r=n(82),o=n(641),i=n(954),a=n(117);const s=[" MaxLFQ Intensity"," Intensity"," Razor Intensity"],l=["Protein ID","Protein"],c=["Gene","Gene Names","Gene Symbol"],u=["contam_","rev_","CON__","REV__"];function f(e,t){for(const n of t){const t=e.col(n);if(t)return t}return null}function p(e){const t=e.toLowerCase();for(const e of s)if(t.endsWith(e.toLowerCase())&&t.length>e.length)return e.toLowerCase();return null}function d(e,t,n,r){const o=f(e,t);o&&(0,i.wK)(e,o.name,n,r)}async function m(e){const t=function(e){const t=e.indexOf("\n"),n=(t>=0?e.substring(0,t):e).replace(/\r$/,"").split("\t"),r=[];for(const e of n)p(e)&&r.push({name:e,type:"double"});return r}(e),n=r.DataFrame.fromCsv(e,{delimiter:"\t",columnImportOptions:t});n.filter.init(e=>!0),function(e){const t=["Protein ID","Protein"],n=[];for(const r of t){const t=e.col(r);t&&n.push(t)}if(0!==n.length)for(let t=0;t<e.rowCount;t++)for(const r of n){const n=r.get(t);if("string"!=typeof n)continue;let o=!1;for(const e of u)if(n.startsWith(e)){o=!0;break}if(o){e.filter.set(t,!1,!1);break}}}(n),n.filter.fireChanged();const s=n.clone(n.filter),m=function(e){const t=new Map;for(const n of e.columns.names()){const o=e.col(n);if(!o)continue;if(o.type!==r.COLUMN_TYPE.FLOAT&&o.type!==r.COLUMN_TYPE.INT&&o.type!==r.COLUMN_TYPE.BIG_INT)continue;const i=n.toLowerCase();let a=null,s=null;i.endsWith(" maxlfq intensity")?(a=n.substring(0,n.length-17),s="maxLfq"):i.endsWith(" razor intensity")?(a=n.substring(0,n.length-16),s="razor"):i.endsWith(" intensity")&&(a=n.substring(0,n.length-10),s="intensity"),a&&s&&(t.has(a)||t.set(a,{}),t.get(a)[s]=n)}const n=[];for(const e of t.values())e.maxLfq?n.push(e.maxLfq):e.intensity?n.push(e.intensity):e.razor&&n.push(e.razor);return n}(s);return function(e,t){const n=f(e,l);n&&(n.semType=o.iu.PROTEIN_ID);const r=f(e,c);r&&(r.semType=o.iu.GENE_SYMBOL);for(const n of t){const t=e.col(n);t&&(t.semType=o.iu.INTENSITY)}}(s,m),d(s,l,"Primary Protein ID",o.iu.PROTEIN_ID),d(s,c,"Primary Gene Name",o.iu.GENE_SYMBOL),(0,i.Kh)(s,m),s.setTag("proteomics.source","fragpipe"),await(0,a.rv)(s),s}},312(e,t,n){"use strict";n.d(t,{E:()=>g});var r=n(82),o=n(641),i=n(954),a=n(117);const s=["lfq intensity","ibaq","reporter intensity","intensity"],l=["Potential contaminant","Potential.contaminant"],c=["Reverse"],u=["Only identified by site","Only.identified.by.site"],f=["Protein IDs","Majority protein IDs"],p=["Gene names","Gene name"];function d(e,t){for(const n of t){const t=e.col(n);if(t)return t}return null}function m(e,t){const n=d(e,t);if(n)for(let t=0;t<e.rowCount;t++)"+"===n.get(t)&&e.filter.set(t,!1,!1)}function h(e,t,n,r){const o=d(e,t);o&&(0,i.wK)(e,o.name,n,r)}async function g(e){const t=function(e){const t=e.indexOf("\n"),n=(t>=0?e.substring(0,t):e).replace(/\r$/,"").split("\t"),r=[];for(const e of n){const t=e.toLowerCase();for(const n of s)if(t.startsWith(n)){r.push({name:e,type:"double"});break}}return r}(e),n=r.DataFrame.fromCsv(e,{delimiter:"\t",columnImportOptions:t});n.filter.init(e=>!0),m(n,l),m(n,c),m(n,u),function(e){const t=[];for(const n of f){const r=e.col(n);r&&t.push(r)}if(0!==t.length)for(let n=0;n<e.rowCount;n++)for(const r of t){const t=r.get(n);if("string"==typeof t&&(t.startsWith("CON__")||t.startsWith("REV__"))){e.filter.set(n,!1,!1);break}}}(n),n.filter.fireChanged();const g=n.clone(n.filter);return function(e){const t=d(e,f);t&&(t.semType=o.iu.PROTEIN_ID);const n=d(e,p);n&&(n.semType=o.iu.GENE_SYMBOL)}(g),h(g,f,"Primary Protein ID",o.iu.PROTEIN_ID),h(g,p,"Primary Gene Name",o.iu.GENE_SYMBOL),function(e){const t=[];for(const n of e.columns.names()){const o=e.col(n);if(!o)continue;if(o.type!==r.COLUMN_TYPE.FLOAT&&o.type!==r.COLUMN_TYPE.INT)continue;const i=n.toLowerCase();for(const e of s)if(i.startsWith(e)){t.push(n);break}}(0,i.Kh)(e,t)}(g),g.setTag("proteomics.source","maxquant"),await(0,a.rv)(g),g}},954(e,t,n){"use strict";n.d(t,{Kh:()=>i,T6:()=>c,WI:()=>p,YL:()=>f,eY:()=>l,l3:()=>a,q2:()=>u,wK:()=>s});var r=n(82),o=n(641);function i(e,t){let n=0;for(const i of t){const t=e.col(i);if(!t)continue;t.semType=o.iu.INTENSITY;const a=`log2(${i})`,s=e.columns.addNewFloat(a);s.init(e=>{if(t.isNone(e))return r.FLOAT_NULL;const o=Number(t.get(e));return isNaN(o)?(n++,r.FLOAT_NULL):o>0?Math.log2(o):r.FLOAT_NULL}),s.semType=o.iu.INTENSITY}n>0&&console.warn(`log2TransformColumns: ${n} non-numeric value(s) dropped to null`)}function a(e,t){for(const n of t){const t=e.col(n);if(!t)continue;t.semType=o.iu.INTENSITY;const i=`log2(${n})`,a=e.columns.addNewFloat(i);a.init(e=>t.isNone(e)?r.FLOAT_NULL:Number(t.get(e))),a.semType=o.iu.INTENSITY}}function s(e,t,n,r){const o=e.col(t);if(!o)return;let i=!1;for(let t=0;t<e.rowCount&&!i;t++){const e=o.get(t);"string"==typeof e&&e.includes(";")&&(i=!0)}if(!i)return;const a=e.columns.addNewString(n);a.init(e=>{const t=o.get(e);if("string"!=typeof t||0===t.length)return null;const n=t.indexOf(";");return n>=0?t.substring(0,n):t}),a.semType=r}function l(e,t){let n=0,o=0,i=0;for(const a of t){const t=e.col(a);if(t&&(t.type===r.COLUMN_TYPE.FLOAT||t.type===r.COLUMN_TYPE.INT||t.type===r.COLUMN_TYPE.BIG_INT)){for(let r=0;r<e.rowCount&&i<200;r++){if(t.isNone(r))continue;const e=Number(t.get(r));e>=0&&e<=30?(n++,i++):e>=1e3&&(o++,i++)}if(i>=200)break}}return 0===i?{isLog2:!1,message:"No intensity values found"}:o/i>.5?{isLog2:!1,message:"Data appears to be raw intensities"}:n/i>.8?{isLog2:!0,message:"Data appears to be already log2-transformed"}:{isLog2:!1,message:"Could not determine data scale"}}function c(e){const t=e.indexOf("\n"),n=t>=0?e.substring(0,t):e;return(n.match(/\t/g)||[]).length>(n.match(/,/g)||[]).length?"\t":","}function u(e){const t=["protein","accession","uniprot"];for(const n of e.columns.toList()){if(n.type!==r.COLUMN_TYPE.STRING)continue;const e=n.name.toLowerCase();for(const r of t)if(e.includes(r))return n}return null}function f(e){const t=["gene","symbol","gene_name","genename"];for(const n of e.columns.toList()){if(n.type!==r.COLUMN_TYPE.STRING)continue;const e=n.name.toLowerCase();for(const r of t)if(e.includes(r))return n}return null}function p(e){const t=["intensity","lfq","ibaq","tmt","reporter","abundance"],n=[];for(const o of e.columns.toList()){if(o.type!==r.COLUMN_TYPE.FLOAT&&o.type!==r.COLUMN_TYPE.INT&&o.type!==r.COLUMN_TYPE.BIG_INT)continue;const e=o.name.toLowerCase();for(const r of t)if(e.includes(r)){n.push(o.name);break}}return n}},86(e,t,n){"use strict";n.d(t,{R:()=>_,g:()=>d});var r=n(82),o=n(641),i=n(954),a=n(117),s=n(252);const l=["PG.ProteinGroups","ProteinGroups","Protein Groups"],c=["PG.Genes","Genes","Gene Names"],u=["AVG Log2 Ratio","Log2 Ratio","AVG Log2 Fold Change"],f=["Qvalue","Q-Value","Q.Value","AdjustedPValue","Adjusted P-Value"],p=["Pvalue","PValue","P-Value","P.Value"],d=["Comparison (group1/group2)","Comparison"],m=["AVG Group Quantity Numerator"],h=["AVG Group Quantity Denominator"],g=["Condition Numerator"],y=["Condition Denominator"],w=["contam_","rev_","CON__","REV__"];function v(e,t){for(const n of t){const t=e.col(n);if(t)return t}return null}function b(e,t,n){if(t.name===n)return;const r=e.col(n);r&&r!==t||(t.name=n)}async function _(e){const t=(0,i.T6)(e),n=r.DataFrame.fromCsv(e,{delimiter:t}),_=v(n,l);if(!_)throw new Error(`Spectronaut Candidates: missing protein-group column (expected one of ${l.join(", ")})`);if(!v(n,u))throw new Error(`Spectronaut Candidates: missing log2 ratio column (expected one of ${u.join(", ")})`);if(!v(n,f))throw new Error(`Spectronaut Candidates: missing q-value column (expected one of ${f.join(", ")})`);n.filter.init(e=>!0),function(e,t){const n=e.col(t);if(n)for(let t=0;t<e.rowCount;t++){const r=n.get(t);if("string"==typeof r)for(const n of w)if(r.startsWith(n)){e.filter.set(t,!1,!1);break}}}(n,_.name),n.filter.fireChanged();const N=n.clone(n.filter),C=v(N,l),S=v(N,u),T=v(N,f),E=v(N,c),P=v(N,p);b(N,S,"log2FC"),b(N,T,"adj.p-value"),P&&b(N,P,"p-value"),C.semType=o.iu.PROTEIN_ID,E&&(E.semType=o.iu.GENE_SYMBOL),N.col("log2FC").semType=o.iu.LOG2FC,N.col("adj.p-value").semType=o.iu.P_VALUE,N.col("p-value")&&(N.col("p-value").semType=o.iu.P_VALUE),(0,i.wK)(N,C.name,"Primary Protein ID",o.iu.PROTEIN_ID),E&&(0,i.wK)(N,E.name,"Primary Gene Name",o.iu.GENE_SYMBOL),function(e){const t=v(e,d);if(!t)return;const n=e.rowCount;let o=null,i="",a="";for(let e=0;e<n;e++){const n=t.get(e);if("string"==typeof n&&n.includes(" / ")){const e=n.split(" / ");if(2===e.length&&e[0]&&e[1]){o=n,i=e[0],a=e[1];break}}}if(null===o)return;const s=`${a} / ${i}`,l=new Uint8Array(n);let c=!1;for(let e=0;e<n;e++)t.get(e)===s&&(l[e]=1,c=!0);if(!c)return;const u=e.col("log2FC"),f=u.getRawData(),p=new Array(n);for(let e=0;e<n;e++){const t=f[e];p[e]=t===r.FLOAT_NULL?r.FLOAT_NULL:l[e]?-t:t}u.init(e=>p[e]);const w=v(e,m),b=v(e,h);if(w&&b){const e=w.getRawData(),t=b.getRawData(),r=new Array(n),o=new Array(n);for(let i=0;i<n;i++){const n=e[i],a=t[i];r[i]=l[i]?a:n,o[i]=l[i]?n:a}w.init(e=>r[e]),b.init(e=>o[e])}const _=new Array(n);for(let e=0;e<n;e++)_[e]=l[e]?o:t.get(e);t.init(e=>_[e]);const x=v(e,g),N=v(e,y);if(x&&N){const e=new Array(n),t=new Array(n);for(let r=0;r<n;r++)e[r]=l[r]?i:x.get(r),t[r]=l[r]?a:N.get(r);x.init(t=>e[t]),N.init(e=>t[e])}}(N);const D=N.columns.addNewBool("significant"),L=N.col("log2FC").getRawData(),A=N.col("adj.p-value").getRawData();D.init(e=>{const t=L[e],n=A[e];return t!==r.FLOAT_NULL&&n!==r.FLOAT_NULL&&Math.abs(t)>=o.M5&&n<=o.Dx}),N.setTag("proteomics.source","spectronaut-candidates"),N.setTag("proteomics.de_complete","true"),N.setTag("proteomics.de_method","spectronaut");let M=x(v(N,g)),I=x(v(N,y));if(!M||!I){const e=x(v(N,d));if(e&&e.includes("/")){const[t,n]=e.split("/").map(e=>e.trim());M=M??(t||null),I=I??(n||null)}}return M&&I&&(0,s.$Y)(N,{group1:{name:M,columns:[]},group2:{name:I,columns:[]}}),await(0,a.rv)(N),N}function x(e){if(!e)return null;for(let t=0;t<e.length;t++){const n=e.get(t);if(null!=n&&String(n).trim().length>0)return String(n).trim()}return null}},53(e,t,n){"use strict";n.d(t,{A:()=>m,parseSpectronautText:()=>h});var r=n(328),o=n(82),i=n(641),a=n(954),s=n(252),l=n(117);const c=["R.Condition","R.Replicate","PG.ProteinGroups"],u=["PG.IBAQ","PG.Quantity"];function f(e){if(!e||0===e.trim().length)return null;const t=Date.parse(e);return Number.isNaN(t)?null:t}async function p(e){const t=function(e){const t=Array.from(e.proteinMap.keys()),n=t.length,r=o.Column.fromStrings("PG.ProteinGroups",t);r.semType=i.iu.PROTEIN_ID;const a=[r];if(e.organisms.size>0){const n=t.map(t=>e.organisms.get(t)??""),r=o.Column.fromStrings("PG.Organisms",n);a.push(r)}for(const r of e.sampleKeys){const s=new Float32Array(n);for(let i=0;i<n;i++){const n=e.proteinMap.get(t[i]);s[i]=n.has(r)?n.get(r):o.FLOAT_NULL}const l=o.Column.fromFloat32Array(r,s);l.semType=i.iu.INTENSITY,e.sampleFileNames.has(r)&&l.setTag("spectronaut.fileName",e.sampleFileNames.get(r)),a.push(l)}return o.DataFrame.fromColumns(a)}(e);(0,a.wK)(t,"PG.ProteinGroups","Primary Protein ID",i.iu.PROTEIN_ID);const n=e.sampleKeys;return(0,a.eY)(t,n).isLog2?(0,a.l3)(t,n):(0,a.Kh)(t,n),t.setTag("proteomics.preNormalized","true"),t.setTag("proteomics.source","spectronaut"),function(e,t){const n=new Map;for(const e of t){const t=e.lastIndexOf("_"),r=e.substring(0,t);n.has(r)||n.set(r,[]),n.get(r).push(`log2(${e})`)}const r=Array.from(n.keys());2===r.length&&(0,s.$Y)(e,{group1:{name:r[0],columns:n.get(r[0])},group2:{name:r[1],columns:n.get(r[1])}})}(t,e.sampleKeys),await(0,l.rv)(t),t}function d(e){if(null==e)return null;const t=e.trim();if(""===t||"NaN"===t||"NA"===t)return null;const n=Number(t);return Number.isFinite(n)?n:null}async function m(e,t=.01){const n=o.TaskBarProgressIndicator.create("Streaming Spectronaut report...");try{const o=e.stream().pipeThrough(new TextDecoderStream("utf-8")).getReader(),i=new Map;let a="",s=!1,l=new Map,m=-1,h=-1,y=-1,w=-1,v=-1,b=-1,_=-1,x=-1,N=-1,C=0,S=null,T=null,E=null,P=0,D=0,L=0,A=0,M=performance.now();const I=Math.max(1,e.size),O=e=>{if(e.length<C)return"malformed";const n=e[m];if(!n)return"filtered";if(n.startsWith("CON__")||n.startsWith("REV__"))return"filtered";const r=w>=0?d(e[w]):null;if(null!==r&&r>t)return"filtered";const o=d(e[v]);if(null===o&&null===r)return"filtered";const a=e[h]??"",s=e[y]??"",l=n+""+a+""+s;let c=i.get(l);if(void 0===c&&(c={protein:n,condition:a,replicate:s,maxQuantity:-1/0,minQvalue:1/0,fileName:null,organism:null},i.set(l,c)),null!==o&&o>c.maxQuantity&&(c.maxQuantity=o),null!==r&&r<c.minQvalue&&(c.minQvalue=r),null===c.fileName&&b>=0){const t=e[b];t&&(c.fileName=t)}if(null===c.organism&&_>=0){const t=e[_];t&&(c.organism=t)}if(x>=0){const t=e[x];if(t){const e=f(t);null!==e&&(null===S||e<S)&&(S=e,T=new Date(e).toISOString())}}if(N>=0&&null===E){const t=e[N];t&&t.trim().length>0&&(E=t)}return"kept"},F=e=>{const t=e.split("\t");l=new Map;for(let e=0;e<t.length;e++)l.set(t[e],e);for(const e of c)if(!l.has(e))throw new Error(`Missing required Spectronaut column: ${e}`);const n=u.find(e=>l.has(e));if(!n)throw new Error(`Missing protein-group quantity column (expected one of ${u.join(", ")})`);m=l.get("PG.ProteinGroups"),h=l.get("R.Condition"),y=l.get("R.Replicate"),v=l.get(n),w=l.has("EG.Qvalue")?l.get("EG.Qvalue"):-1,b=l.has("R.FileName")?l.get("R.FileName"):-1,_=l.has("PG.Organisms")?l.get("PG.Organisms"):-1,x=l.has("R.RunDate")?l.get("R.RunDate"):-1,N=l.has("R.InstrumentMethod")?l.get("R.InstrumentMethod"):-1,C=Math.max(m,h,y,v,w,b,_,x,N)+1,s=!0};for(;;){const{value:e,done:t}=await o.read();if(t)break;let r;for(P+=e.length,a+=e;(r=a.indexOf("\n"))>=0;){let e=a.slice(0,r);if(a=a.slice(r+1),e.endsWith("\r")&&(e=e.slice(0,-1)),s){if(0!==e.length)switch(O(e.split("\t"))){case"kept":D++;break;case"malformed":L++;break;case"filtered":A++}}else{if(0===e.length)continue;F(e)}}if(performance.now()-M>=16){const e=Math.min(99,P/I*100),t=L>0?`${D} rows (${L} malformed skipped)`:`${D} rows`;n.update(e,t),await new Promise(e=>setTimeout(e,0)),M=performance.now()}}if(a.length>0){let e=a;if(e.endsWith("\r")&&(e=e.slice(0,-1)),e.length>0)if(s)switch(O(e.split("\t"))){case"kept":D++;break;case"malformed":L++;break;case"filtered":A++}else F(e)}if(!s)throw new Error("Missing required Spectronaut column: R.Condition");L>0&&r.shell.info(`Spectronaut import: skipped ${L} malformed line(s)`);const $=function(e){const t=new Map,n=new Set,r=new Map,o=new Map;for(const i of e.values()){if(!Number.isFinite(i.maxQuantity))continue;const e=`${i.condition}_${i.replicate}`;n.add(e),t.has(i.protein)||t.set(i.protein,new Map),t.get(i.protein).set(e,i.maxQuantity),null===i.fileName||r.has(e)||r.set(e,i.fileName),null===i.organism||o.has(i.protein)||o.set(i.protein,i.organism)}return{proteinMap:t,sampleKeys:Array.from(n).sort(),sampleFileNames:r,organisms:o}}(i);$.earliestRunDate=T,$.firstInstrumentMethod=E;const R=await p($);return g(R,$),R}finally{n.close()}}async function h(e,t=.01){const n=o.DataFrame.fromCsv(e,{delimiter:"\t"});for(const e of c)if(!n.col(e))throw new Error(`Missing required Spectronaut column: ${e}`);const r=u.find(e=>null!==n.col(e));if(!r)throw new Error(`Missing protein-group quantity column (expected one of ${u.join(", ")})`);const i=function(e,t,n){const r=e.col("R.Condition"),o=e.col("R.Replicate"),i=e.col("PG.ProteinGroups"),a=e.col(t),s=e.col("EG.Qvalue"),l=e.col("R.FileName"),c=e.col("PG.Organisms"),u=e.col("R.RunDate"),p=e.col("R.InstrumentMethod"),d=new Map,m=new Set,h=new Map,g=new Map;let y=null,w=null,v=null;for(let t=0;t<e.rowCount;t++){if(s)if(s.isNone(t));else{const e=s.get(t),r=Number(e);if(!isNaN(r)&&r>n)continue}const e=i.get(t);if(!e)continue;if(e.startsWith("CON__")||e.startsWith("REV__"))continue;const b=`${String(r.get(t))}_${String(o.get(t))}`;if(m.add(b),d.has(e)||d.set(e,new Map),d.get(e).has(b)||a.isNone(t)||d.get(e).set(b,Number(a.get(t))),!l||h.has(b)||l.isNone(t)||h.set(b,l.get(t)),!c||g.has(e)||c.isNone(t)||g.set(e,c.get(t)),u&&!u.isNone(t)){const e=f(String(u.get(t)));null!==e&&(null===y||e<y)&&(y=e,w=new Date(e).toISOString())}if(p&&null===v&&!p.isNone(t)){const e=String(p.get(t));e.trim().length>0&&(v=e)}}return{proteinMap:d,sampleKeys:Array.from(m).sort(),sampleFileNames:h,organisms:g,earliestRunDate:w,firstInstrumentMethod:v}}(n,r,t),a=await p(i);return g(a,i),a}function g(e,t){const n=null!=t.earliestRunDate,r=null!=t.firstInstrumentMethod;(n||r)&&e.setTag("proteomics.spc_run_meta_seed",JSON.stringify({instrument_id:t.firstInstrumentMethod??"",acquisition_datetime:t.earliestRunDate??""}))}},691(e,t,n){"use strict";n.d(t,{F:()=>u,Y:()=>c});var r=n(328),o=n(82),i=n(749),a=n(641),s=n(304),l=n(771);const c="FORMULA_LINE_MISSING:";async function u(e,t){const n=e.id;r.shell.closeAll(),await(0,i.cb)(100);const u=await r.dapi.projects.find(n);await u.open(),await(0,i.bk)(()=>!!r.shell.tv&&!!r.shell.tv.dataFrame,"assertPublishedShape: TableView never materialized after project.open()",5e3);const f=r.shell.tv.dataFrame;if(f.name!==t.expectedName)throw new Error(`assertPublishedShape: df.name: got "${f.name}", expected "${t.expectedName}"`);if(u.name!==t.expectedProjectName)throw new Error(`assertPublishedShape: project.name: got "${u.name}", expected "${t.expectedProjectName}"`);for(const e of t.expectedAllowlist)if(!f.col(e))throw new Error(`assertPublishedShape: allowlist column missing on reopen: "${e}"`);const p=f.columns.toList().map(e=>e.name).filter(e=>!e.startsWith("_meta_")&&!e.startsWith("~"));if(p.length!==t.expectedAllowlist.length){const e=p.filter(e=>!t.expectedAllowlist.includes(e)),n=t.expectedAllowlist.filter(e=>!p.includes(e));throw new Error(`assertPublishedShape: visible column count: got ${p.length}, expected ${t.expectedAllowlist.length}. Unexpected: [${e.join(", ")}]. Missing: [${n.join(", ")}].`)}const d=(0,s.k)(f,a.iu.PROTEIN_ID,["protein id","majority protein id","accession"]);if(null==d)throw new Error("assertPublishedShape: protein-id column not found via findColumn");if(d.semType!==a.iu.PROTEIN_ID)throw new Error(`assertPublishedShape: protein-id semType: got "${d.semType??"null"}", expected "${a.iu.PROTEIN_ID}". Detectors may not have re-fired on reopen — re-assign in trim-dataframe.ts Step E.`);const m=(0,l.M4)(f);if(null==m)throw new Error("assertPublishedShape: getPublishedMetadata returned null — published flag not set or all critical fields unreadable");const h=t.expectedMeta,g=(e,t)=>!(Math.abs(e-t)>1e-9);if(m.target!==h.target)throw new Error(`assertPublishedShape: meta.target: got "${m.target}", expected "${h.target}"`);if(m.deMethod!==h.deMethod)throw new Error(`assertPublishedShape: meta.deMethod: got "${m.deMethod}", expected "${h.deMethod}"`);if(!g(m.fcThreshold,h.fcThreshold))throw new Error(`assertPublishedShape: meta.fcThreshold: got ${m.fcThreshold}, expected ${h.fcThreshold}`);if(!g(m.pThreshold,h.pThreshold))throw new Error(`assertPublishedShape: meta.pThreshold: got ${m.pThreshold}, expected ${h.pThreshold}`);if(m.version!==h.version)throw new Error(`assertPublishedShape: meta.version: got ${m.version}, expected ${h.version}`);if(m.publishId!==h.publishId)throw new Error(`assertPublishedShape: meta.publishId: got "${m.publishId}", expected "${h.publishId}"`);if(m.includesEnrichment!==h.includesEnrichment)throw new Error(`assertPublishedShape: meta.includesEnrichment: got ${m.includesEnrichment}, expected ${h.includesEnrichment}`);if(m.publishedBy!==h.publishedBy)throw new Error(`assertPublishedShape: meta.publishedBy: got "${m.publishedBy}", expected "${h.publishedBy}"`);for(const e of Object.keys(l.MD)){const t=l.MD[e];if(!f.col(t))throw new Error(`assertPublishedShape: metadata column missing: "${t}"`)}let y=null;if(t.expectVolcano)try{await(0,i.bk)(()=>{const e=r.shell.tv;if(!e)return!1;for(const t of e.viewers)if(t.type===o.VIEWER.SCATTER_PLOT)return y=t,!0;return!1},"assertPublishedShape: volcano scatter plot not present on reopen — consider post-open recomputeVolcano in publish-project.ts",5e3)}catch(e){throw new Error(`assertPublishedShape: volcano viewer assertion failed: ${e?.message??e}`)}if(t.expectVolcano&&t.expectFormulaLines&&null!=y){const e=String(h.fcThreshold),t=String(h.pThreshold),n=String(-Math.log10(h.pThreshold)),r=[];try{const e=f.meta?.formulaLines?.items??[];Array.isArray(e)&&r.push(...e)}catch{}try{const e=y.getOptions?.(),t=e?.look?.formulaLines,n="string"==typeof t?JSON.parse(t):t;Array.isArray(n)&&r.push(...n)}catch{}try{const e=y?.props?.formulaLines,t="string"==typeof e?JSON.parse(e):e;Array.isArray(t)&&r.push(...t)}catch{}const o=r.map(e=>"string"==typeof e?.formula?e.formula:"").filter(e=>e.length>0),i=o.some(t=>t.includes(e)||t.includes(`-${e}`)),a=o.some(e=>e.includes(n)||e.includes(t));if(!i||!a)throw new Error(`${c} volcano reopened without formula lines for FC=${h.fcThreshold} and/or p=${h.pThreshold}. The look/filter config was stripped by the serializer (Phase 13 e527d07ba1 evidence). Plan 04 step 8 catch should invoke the post-open recovery hook from tags ${l.L6.PUBLISHED_FC_THRESHOLD} / ${l.L6.PUBLISHED_P_THRESHOLD} and re-run this assertion once.`)}if(t.expectEnrichment){const e=r.shell.tables;if(!Array.isArray(e)||e.length<2)throw new Error(`assertPublishedShape: expectEnrichment=true but grok.shell.tables has ${e?.length??0} DataFrames (need ≥ 2)`);if(!e.find(e=>{try{const t=e.col(l.MD.PUBLISHED_INCLUDES_ENRICHMENT);return null!=t&&"true"===String(t.get(0))}catch{return!1}}))throw new Error("assertPublishedShape: protein DF (with _meta_published_includes_enrichment=true) not found among reopened tables");if(!e.find(e=>"true"===e.getTag("proteomics.enrichment")))throw new Error("assertPublishedShape: enrichment DF (proteomics.enrichment=true tag) not found among reopened tables")}const w=u.options??{};if(null!=h.supersedes){const e=w[l.L6.SUPERSEDES];if(e!==h.supersedes)throw new Error(`assertPublishedShape: project.options['${l.L6.SUPERSEDES}']: got "${e??"null"}", expected "${h.supersedes}"`)}if(null!=h.supersededBy){const e=w[l.L6.SUPERSEDED_BY];if(e!==h.supersededBy)throw new Error(`assertPublishedShape: project.options['${l.L6.SUPERSEDED_BY}']: got "${e??"null"}", expected "${h.supersededBy}"`)}}},649(e,t,n){"use strict";n.d(t,{I:()=>c});var r=n(328),o=n(82),i=n(771),a=n(807),s=n(897);const l="proteomics.enrichment_wired";async function c(e){if(!(0,i.HF)(e))return;const t=function(e){try{const t=r.shell.tableViews;if(Array.isArray(t)){const n=t.find(t=>t?.dataFrame===e);if(n)return n}}catch{}try{const t=r.shell.tv;if(t&&t.dataFrame===e)return t}catch{}return null}(e);if(t){const n=Array.from(t.viewers).find(e=>e.type===o.VIEWER.SCATTER_PLOT);if(n){const t=e.getTag(i.L6.PUBLISHED_FC_THRESHOLD),r=e.getTag(i.L6.PUBLISHED_P_THRESHOLD);if(t&&r){const o=parseFloat(t),i=parseFloat(r);if(Number.isFinite(o)&&Number.isFinite(i)&&!function(e,t){try{const t=e.meta?.formulaLines?.items??[];if(Array.isArray(t)&&t.length>0)return!0}catch{}try{const e=t.getOptions?.(),n=e?.look?.formulaLines;if("string"==typeof n&&""!==n&&"[]"!==n)return!0;if(Array.isArray(n)&&n.length>0)return!0}catch{}return!1}(e,n))try{(0,a.u)(n,o,i)}catch{}}}}const n=function(e){try{const t=r.shell.tables;return Array.isArray(t)?t.find(t=>t!==e&&"true"===t?.getTag?.("proteomics.enrichment")&&"true"===t?.getTag?.(i.L6.PUBLISHED))??null:null}catch{return null}}(e);if(n&&"true"!==n.getTag(l))try{(0,s.aB)(n,e),n.setTag(l,"true")}catch{}}},807(e,t,n){"use strict";n.d(t,{u:()=>m,M:()=>h});var r=n(328),o=n(82),i=n(749),a=n(771),s=n(641),l=n(304);function c(e,t){let n,r;switch(e.columns.contains(t.name)&&e.columns.remove(t.name),t.type){case"datetime":n=e.columns.addNewDateTime(t.name);break;case"float":n=e.columns.addNewFloat(t.name);break;case"int":n=e.columns.addNewInt(t.name);break;default:n=e.columns.addNewString(t.name)}if(null==t.value){if(!t.emptyForNull)return;r="string"===t.type?"":0}else r=t.value instanceof Date?t.value:"boolean"==typeof t.value?t.value?"true":"false":"string"===t.type?String(t.value):t.value;n.init(()=>r),n.setTag(".hidden","true")}var u=n(691),f=n(70),p=n(897),d=n(637);function m(e,t,n){const r=e.dataFrame;if(!r)return;let o=null;try{const t=e.getOptions?.();o=t?.look?.yColumnName??null}catch{}if(!o)try{o=e.props?.yColumnName??null}catch{}if(!o)return;const i=`\${${o}}`,a="${log2FC}",s=-Math.log10(n),l=r.meta,c=l?.formulaLines;if(c){try{const e=Array.isArray(c.items)?c.items:[];c.items=e.filter(e=>{const t=e?.formula??"";return!("string"==typeof t&&(t.startsWith(i)||t.startsWith(a)))})}catch{}try{c.addLine({formula:`${i} = ${s}`,color:"#888888",width:1,visible:!0}),c.addLine({formula:`${a} = ${t}`,color:"#888888",width:1,visible:!0}),c.addLine({formula:`${a} = ${-t}`,color:"#888888",width:1,visible:!0})}catch{}try{e.props.showViewerFormulaLines=!0}catch{}}}async function h(e,t){const n=o.TaskBarProgressIndicator.create("Publishing snapshot...");try{n.description="Preparing metadata...";const h=r.shell.user?.friendlyName??"",g=r.shell.user?.email??null,y=e.getTag("proteomics.de_method")??"t-test";let w=s.M5,v=s.Dx;try{const e=t;"number"==typeof e.fcThreshold&&Number.isFinite(e.fcThreshold)&&(w=e.fcThreshold),"number"==typeof e.pThreshold&&Number.isFinite(e.pThreshold)&&(v=e.pThreshold)}catch{}const b=(0,a.fz)(t.target),_=function(e){if(!e)return 0;const t=/-v(\d+)-/.exec(e);if(!t)return 0;const n=parseInt(t[1],10);return Number.isFinite(n)?n:0}(t.priorVersion?.name),x=_>0?_+1:1,N=function(){try{const e=globalThis?.crypto;if(e&&"function"==typeof e.randomUUID)return e.randomUUID()}catch{}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}(),C=new Date,S=C.toISOString().slice(0,10),T=(()=>{const e=r.shell.tables;return Array.isArray(e)?e.find(e=>"true"===e.getTag("proteomics.enrichment"))??null:null})(),E={target:t.target,publishedAt:C,publishedBy:h,publishedByEmail:g,deMethod:y,fcThreshold:w,pThreshold:v,version:x,publishId:N,includesEnrichment:!!T,supersedes:t.priorVersion?.id??null,supersededBy:null};n.description="Trimming snapshot...";const P=function(e,t){const n=(0,l.I)(e),r=n.proteinId,o=n.geneName,i=n.log2fc,u=(0,l.k)(e,"",["adj.p-value","adj.p","fdr","q-value"]),f=e.columns.toList().find(e=>{const t=e.name.toLowerCase();return("p-value"===t||"pvalue"===t)&&e.name!==(u?.name??"")})??null,p=(0,l.k)(e,"",["significant","sig"]),d=(0,l.k)(e,"",["direction","regulation","up_down"]),m=[["Protein ID",r],["log2FC",i],["p-value",f],["adj.p-value",u],["significant",p]];for(const[e,t]of m)if(null==t)throw new Error(`Cannot publish: missing required column [${e}]. Run Differential Expression to completion before publishing.`);const h=Array.from(new Set([r.name,o?.name,i.name,f.name,u.name,p.name,d?.name].filter(e=>"string"==typeof e&&e.length>0))),g=e.clone(null,h),y=["proteomics.source","proteomics.de_method","proteomics.groups","proteomics.de_complete"];for(const t of y){const n=e.getTag(t);null!=n&&""!==n&&g.setTag(t,n)}(0,a.W7)(g,t);const w=t.publishedAt instanceof Date?t.publishedAt.toISOString().slice(0,10):new Date(String(t.publishedAt)).toISOString().slice(0,10);g.name=`${e.name||"analysis"}_published_${w}`;const v=[[r,s.iu.PROTEIN_ID],[o,s.iu.GENE_SYMBOL],[i,s.iu.LOG2FC],[f,s.iu.P_VALUE]];for(const[e,t]of v){if(null==e)continue;const n=g.col(e.name);null!=n&&(n.semType=t)}const b=t.includesEnrichment?"true":"false",_=[{name:a.MD.PUBLISHED,value:"true",type:"string"},{name:a.MD.PUBLISHED_AT,value:t.publishedAt,type:"datetime"},{name:a.MD.PUBLISHED_BY,value:t.publishedBy,type:"string"},{name:a.MD.PUBLISHED_BY_EMAIL,value:t.publishedByEmail??"",type:"string",emptyForNull:!0},{name:a.MD.PUBLISHED_TARGET,value:t.target,type:"string"},{name:a.MD.PUBLISHED_DE_METHOD,value:t.deMethod,type:"string"},{name:a.MD.PUBLISHED_FC_THRESHOLD,value:String(t.fcThreshold),type:"string"},{name:a.MD.PUBLISHED_P_THRESHOLD,value:String(t.pThreshold),type:"string"},{name:a.MD.PUBLISHED_VERSION,value:String(t.version),type:"string"},{name:a.MD.PUBLISHED_ID,value:t.publishId,type:"string"},{name:a.MD.PUBLISHED_INCLUDES_ENRICHMENT,value:b,type:"string"},{name:a.MD.SUPERSEDES,value:t.supersedes??"",type:"string",emptyForNull:!0},{name:a.MD.SUPERSEDED_BY,value:t.supersededBy??"",type:"string",emptyForNull:!0}];for(const e of _)c(g,e);return g}(e,E),D=P.name;let L=null;T&&(n.description="Trimming enrichment...",L=function(e,t){const n=(0,l.k)(e,"",["term name","term","pathway"]),r=(0,l.k)(e,"",["source"]),o=(0,l.k)(e,"",["fdr","adj.p-value","adj.p","q-value","p-value","pvalue"]),i=(0,l.k)(e,"",["intersection","genes"]),s=(0,l.k)(e,"",["direction","regulation"]),u=(0,l.k)(e,"",["gene ratio"]),f=(0,l.k)(e,"",["gene count"]),p=[["Term Name",n],["Source",r],["significance (FDR / adj.p-value)",o],["Intersection",i]];for(const[e,t]of p)if(null==t)throw new Error(`Cannot publish enrichment: missing required column [${e}]. Re-run enrichment before publishing.`);const d=[n.name,r.name,o.name,i.name,s?.name,u?.name,f?.name].filter(e=>"string"==typeof e&&e.length>0),m=e.clone(null,d);m.setTag("proteomics.enrichment","true");const h=t.publishedAt instanceof Date?t.publishedAt.toISOString().slice(0,10):new Date(String(t.publishedAt)).toISOString().slice(0,10);return m.name=`enrichment_published_${h}`,c(m,{name:a.MD.PUBLISHED_ID,value:t.publishId,type:"string"}),c(m,{name:a.MD.PUBLISHED_INCLUDES_ENRICHMENT,value:"true",type:"string"}),m.setTag(a.L6.PUBLISHED,"true"),m.setTag(a.L6.PUBLISHED_ID,t.publishId),m.setTag(a.L6.PUBLISHED_INCLUDES_ENRICHMENT,"true"),m}(T,E)),n.description="Ensuring umbrella Space...";const A=t.umbrellaName??(0,d.ck)(),M=r.dapi;let I=null;try{I=await M.spaces.createRootSpace(A)}catch(e){const t=String(e?.message??e??"");if(!/already exists|exists/i.test(t))throw e;try{I=(await M.spaces.list()??[]).find(e=>e?.name===A||e?.friendlyName===A)??null}catch{}if(!I)throw new Error(`Umbrella Space '${A}' exists on the server but could not be resolved by name from spaces.list() (msg: ${t}). Ask an admin to inspect the conflicting Space.`)}const O=M.spaces.id(I.id);n.description="Ensuring per-target Space...";const F=`${(0,d.sK)()}-${b}`;let $=null;const R=async()=>{try{return(await O.children.filter("Project",!1).list()??[]).find(e=>e?.friendlyName===F||e?.name===F)??null}catch{return null}};try{await O.subspaceExists(F)&&($=await R())}catch{}if(!$)try{$=await O.addSubspace(F)}catch(e){const t=String(e?.message??e??"");if(!/already exists|exists/i.test(t))throw e;if($=await R(),!$)throw new Error(`Per-target child Space '${F}' exists but could not be resolved via umbrella children.list() (msg: ${t}).`)}const k=M.spaces.id($.id);n.description="Saving Project...";const U=o.Project.create(),B=`${(0,d.sK)()}-${b}-v${x}-${S}`;U.name=B,U.friendlyName=`${(0,d.sK)().replace(/-/g," ")} ${t.target} v${x} ${S}`;try{U.options[a.L6.PUBLISHED_ID]=N}catch{}if(null!=t.priorVersion)try{U.options[a.L6.SUPERSEDES]=t.priorVersion.id}catch{}U.addChild(P.getTableInfo()),L&&U.addChild(L.getTableInfo()),n.description="Re-rendering volcano on trimmed snapshot...";const V=r.shell.addTableView(P);await(0,i.cb)(100);const G=(0,f.gO)(P,{fcThreshold:w,pThreshold:v});V.addViewer(G),m(G,w,v),await(0,i.cb)(100);const H=V.getInfo();U.addChild(H);let j=null;if(L){n.description="Re-rendering enrichment charts...";const e=r.shell.addTableView(L);await(0,i.cb)(100),(0,p.YS)(e,L),await(0,i.cb)(100),j=e.getInfo(),U.addChild(j),r.shell.v=V}await r.dapi.tables.uploadDataFrame(P),await r.dapi.tables.save(P.getTableInfo()),L&&(await r.dapi.tables.uploadDataFrame(L),await r.dapi.tables.save(L.getTableInfo())),await r.dapi.views.save(H),j&&await r.dapi.views.save(j),await r.dapi.projects.save(U);try{await k.addEntity(U.id)}catch(e){r.shell.warning(`Could not move Project into child Space "${F}": ${e?.message??e}. Continuing — reviewer view grant is applied directly to the Project.`)}n.description="Granting reviewer view-only access...";try{await r.dapi.permissions.grant(U,t.reviewerGroup,!1)}catch(e){try{await r.dapi.projects.delete(U)}catch(e){r.shell.error(`Manual cleanup required: project id ${U.id} could not be deleted: ${e?.message??e}`)}throw new Error(`Reviewer group view grant failed: ${e?.message??e}`)}n.description="Verifying view-only access...";const q=t.reviewerGroup?.id,Y=e=>null!=e&&("string"==typeof e?e===q:null!=e?.id&&e.id===q),z=await r.dapi.permissions.get(U);let W=null,K=null;try{$&&(W=await r.dapi.permissions.get($))}catch{}try{I&&(K=await r.dapi.permissions.get(I))}catch{}const Q=e=>{for(const t of[z,W,K]){const n=t?.[e];if(Array.isArray(n)&&n.some(Y))return!0}return!1},J=Q("view"),Z=Q("edit"),X=Q("share"),ee=Q("delete");if(!J||Z||X||ee){try{await r.dapi.projects.delete(U)}catch(e){r.shell.error(`Manual cleanup required: project id ${U.id} could not be deleted: ${e?.message??e}`)}throw new Error("Reviewer group already has elevated access via Space inheritance — publish aborted; ask an admin to scope the umbrella Space's permissions")}if(t.verify??(0,d.Cb)()){n.description="Verifying round-trip survival...";const e={expectedName:D,expectedProjectName:B,expectedAllowlist:P.columns.toList().map(e=>e.name).filter(e=>!e.startsWith("_meta_")&&!e.startsWith("~")),expectedMeta:{...E},expectVolcano:!0,expectEnrichment:!!L,expectFormulaLines:!0};let t=!1;for(;;)try{await(0,u.F)(U,e);break}catch(e){const n=String(e?.message??e??"");if(!t&&n.startsWith(u.Y)){t=!0;const e=r.shell.tv,n=e?Array.from(e.viewers).find(e=>e.type===o.VIEWER.SCATTER_PLOT):null;if(n&&e){const t=e.dataFrame,o=parseFloat(t.getTag(a.L6.PUBLISHED_FC_THRESHOLD)??String(w)),s=parseFloat(t.getTag(a.L6.PUBLISHED_P_THRESHOLD)??String(v));m(n,Number.isFinite(o)?o:w,Number.isFinite(s)?s:v);try{await r.dapi.views.save(e.getInfo())}catch{}await(0,i.cb)(100);continue}}try{await r.dapi.projects.delete(U)}catch(e){r.shell.error(`Manual cleanup required: project id ${U.id} could not be deleted: ${e?.message??e}`)}throw new Error(`Round-trip shape verification failed: ${e?.message??e}`)}}if(null!=t.priorVersion){n.description="Updating supersede chain...";const e=t.priorVersion.id;try{const t=await r.dapi.projects.find(e);t.options[a.L6.SUPERSEDED_BY]=U.id,await r.dapi.projects.save(t)}catch(e){r.shell.warning(`Supersede pointer on prior version's options failed: ${e?.message??e} (DataFrame-tag dual-write path below provides fallback).`)}try{r.shell.closeAll(),await(0,i.cb)(100);const t=await r.dapi.projects.find(e);await t.open(),await(0,i.bk)(()=>!!r.shell.tv&&!!r.shell.tv.dataFrame,"supersede stamp: prior project DF did not materialize",5e3);const n=r.shell.tv.dataFrame;n.setTag(a.L6.SUPERSEDED_BY,U.id);const o=n.col(a.MD.SUPERSEDED_BY);if(o)try{o.set(0,U.id)}catch{}await r.dapi.tables.uploadDataFrame(n),await r.dapi.tables.save(n.getTableInfo())}catch(e){r.shell.warning(`Supersede tag could not be stamped on prior version DF: ${e?.message??e} (Project.options pointer was still written — Plan 06 panel falls back to that path)`)}try{U.options[a.L6.SUPERSEDES]=e}catch{}try{await r.dapi.projects.save(U)}catch(e){r.shell.warning(`Could not write supersedes pointer on new project options: ${e?.message??e}`)}}n.description="Restoring your analysis...";try{if(r.shell.closeAll(),await(0,i.cb)(100),T)try{(0,p.q6)(T,e)}catch{}const t=r.shell.addTableView(e);try{t.addViewer((0,f.gO)(e))}catch{}}catch{}return n.description="Done.",U}finally{n.close()}}},637(e,t,n){"use strict";n.d(t,{Cb:()=>s,ck:()=>i,sK:()=>a});var r=n(110);function o(e,t){try{const t=r._package?.settings?.[e];if("string"==typeof t&&t.trim().length>0)return t.trim()}catch{}return t}function i(){return o("reviewSpaceName","Proteomics-Reviews")}function a(){return o("reviewNamePrefix","Proteomics-Review")}function s(){try{const e=r._package?.settings?.verifyPublishedDashboard;if(!1===e||"false"===e)return!1;if(!0===e||"true"===e)return!0}catch{}return!0}},771(e,t,n){"use strict";n.d(t,{$y:()=>i,HF:()=>l,Kj:()=>d,L6:()=>a,M4:()=>c,MD:()=>s,T7:()=>p,W7:()=>u,fz:()=>f});var r=n(328),o=n(637);const i="proteomics.de_complete",a={PUBLISHED:"proteomics.published",PUBLISHED_AT:"proteomics.published_at",PUBLISHED_BY:"proteomics.published_by",PUBLISHED_BY_EMAIL:"proteomics.published_by_email",PUBLISHED_TARGET:"proteomics.published_target",PUBLISHED_DE_METHOD:"proteomics.published_de_method",PUBLISHED_FC_THRESHOLD:"proteomics.published_fc_threshold",PUBLISHED_P_THRESHOLD:"proteomics.published_p_threshold",PUBLISHED_VERSION:"proteomics.published_version",PUBLISHED_ID:"proteomics.published_id",PUBLISHED_INCLUDES_ENRICHMENT:"proteomics.published_includes_enrichment",SUPERSEDED_BY:"proteomics.superseded_by",SUPERSEDES:"proteomics.supersedes"},s={PUBLISHED:"_meta_published",PUBLISHED_AT:"_meta_published_at",PUBLISHED_BY:"_meta_published_by",PUBLISHED_BY_EMAIL:"_meta_published_by_email",PUBLISHED_TARGET:"_meta_published_target",PUBLISHED_DE_METHOD:"_meta_published_de_method",PUBLISHED_FC_THRESHOLD:"_meta_published_fc_threshold",PUBLISHED_P_THRESHOLD:"_meta_published_p_threshold",PUBLISHED_VERSION:"_meta_published_version",PUBLISHED_ID:"_meta_published_id",PUBLISHED_INCLUDES_ENRICHMENT:"_meta_published_includes_enrichment",SUPERSEDED_BY:"_meta_superseded_by",SUPERSEDES:"_meta_supersedes"};function l(e){return"true"===e.getTag(a.PUBLISHED)}function c(e){if(!l(e))return null;const t=(t,n)=>{try{const n=e.col(s[t]);if(null!=n){const e=n.get(0);if(null!=e&&""!==e)return String(e)}}catch{}try{return e.getTag(a[n])??null}catch{return null}},n=(e,n)=>{const r=t(e,n);if(null==r)return NaN;const o=parseFloat(r);return Number.isFinite(o)?o:NaN},r=t("PUBLISHED_TARGET","PUBLISHED_TARGET"),o=t("PUBLISHED_ID","PUBLISHED_ID");if(null==r||null==o)return null;const i=(()=>{try{const t=e.col(s.PUBLISHED_AT);if(null!=t){const e=t.get(0);if(e instanceof Date)return e;if("string"==typeof e&&e)return new Date(e);if("number"==typeof e)return new Date(e)}}catch{}try{const t=e.getTag(a.PUBLISHED_AT);if(t)return new Date(t)}catch{}return null})(),c=t("PUBLISHED_VERSION","PUBLISHED_VERSION"),u=null!=c?parseInt(c,10):NaN;return{target:r,publishedAt:i??new Date(NaN),publishedBy:t("PUBLISHED_BY","PUBLISHED_BY")??"",publishedByEmail:t("PUBLISHED_BY_EMAIL","PUBLISHED_BY_EMAIL"),deMethod:t("PUBLISHED_DE_METHOD","PUBLISHED_DE_METHOD")??"",fcThreshold:n("PUBLISHED_FC_THRESHOLD","PUBLISHED_FC_THRESHOLD"),pThreshold:n("PUBLISHED_P_THRESHOLD","PUBLISHED_P_THRESHOLD"),version:Number.isFinite(u)?u:1,publishId:o,includesEnrichment:"true"===t("PUBLISHED_INCLUDES_ENRICHMENT","PUBLISHED_INCLUDES_ENRICHMENT"),supersedes:t("SUPERSEDES","SUPERSEDES"),supersededBy:t("SUPERSEDED_BY","SUPERSEDED_BY")}}function u(e,t){e.setTag(a.PUBLISHED,"true"),e.setTag(a.PUBLISHED_AT,t.publishedAt instanceof Date?t.publishedAt.toISOString():String(t.publishedAt)),e.setTag(a.PUBLISHED_BY,t.publishedBy),null!=t.publishedByEmail&&e.setTag(a.PUBLISHED_BY_EMAIL,t.publishedByEmail),e.setTag(a.PUBLISHED_TARGET,t.target),e.setTag(a.PUBLISHED_DE_METHOD,t.deMethod),e.setTag(a.PUBLISHED_FC_THRESHOLD,String(t.fcThreshold)),e.setTag(a.PUBLISHED_P_THRESHOLD,String(t.pThreshold)),e.setTag(a.PUBLISHED_VERSION,String(t.version)),e.setTag(a.PUBLISHED_ID,t.publishId),e.setTag(a.PUBLISHED_INCLUDES_ENRICHMENT,t.includesEnrichment?"true":"false"),null!=t.supersedes&&e.setTag(a.SUPERSEDES,t.supersedes),null!=t.supersededBy&&e.setTag(a.SUPERSEDED_BY,t.supersededBy)}function f(e){if(null==e)return"unnamed";let t=String(e).replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-{2,}/g,"-").replace(/^[-.]+|[-.]+$/g,"").slice(0,64).replace(/[-.]+$/g,"");return 0===t.length&&(t="unnamed"),t}async function p(e,t){const n=f(e),i=`${(0,o.sK)()}-${n}-v`,a=/-v(\d+)-/,s=e=>{let t=null,n=-1;for(const r of e){const e=r?.name??"",o=a.exec(e);if(!o)continue;const i=parseInt(o[1],10);Number.isFinite(i)&&i>n&&(n=i,t=r)}return t};try{const e=`${i}%`,t=await r.dapi.projects.filter(`name like "${e}"`).list();if(Array.isArray(t)&&t.length>0)return s(t)}catch{}try{const e=await r.dapi.projects.list(),t=(Array.isArray(e)?e:[]).filter(e=>(e?.name??"").startsWith(i));if(t.length>0)return s(t)}catch{}return null}function d(e){const t=`Re-run request: ${e.projectName}`,n=`Hi ${e.sharerName}, could you re-run with [different parameters]? Looking at ${e.projectName} (shared ${e.publishedDateStr}).`;return`mailto:${e.sharerEmail?encodeURIComponent(e.sharerEmail):""}?subject=${encodeURIComponent(t)}&body=${encodeURIComponent(n)}`}},304(e,t,n){"use strict";n.d(t,{I:()=>i,k:()=>o});var r=n(641);function o(e,t,n){const r=e.columns.toList().find(e=>e.semType===t);if(r)return r;for(const t of n){const n=t.toLowerCase(),r=e.columns.toList().find(e=>e.name.toLowerCase().includes(n));if(r)return r}return null}function i(e){return{proteinId:o(e,r.iu.PROTEIN_ID,["protein id","majority protein id","accession","uniprot"]),geneName:o(e,r.iu.GENE_SYMBOL,["gene name","gene symbol"]),log2fc:o(e,r.iu.LOG2FC,["log2fc","log2 fold","logfc"]),pValue:o(e,r.iu.P_VALUE,["p-value","pvalue","adj.p","fdr","q-value"])}}},117(e,t,n){"use strict";n.d(t,{rv:()=>g});var r=n(328),o=n(304),i=n(641),a=n(623);const s="proteomics-gene-labels",l="14-r1-1",c="__schema_v",u=["ENSRNOG","ENSMUSG","LOC","ENSG","ENSDARG","ENSRNO","MGP_","RGD","AABR"];function f(e){return e.startsWith("ENS")||e.startsWith("MGP_")}function p(e){for(const t of u)if(e.startsWith(t))return!0;return!1}function d(e){if(null==e||""===e)return null;let t=String(e);t=t.split("[")[0].trim(),t=t.replace(/^Predicted to enable\s+/i,""),t=t.replace(/^Predicted to be involved in\s+/i,""),t=t.replace(/^Predicted to be located in\s+/i,""),t=t.replace(/^Predicted to be part of\s+/i,""),t=t.replace(/^Predicted to be\s+/i,""),t=t.replace(/^Predicted to\s+/i,"");const n=t.split(".");return n.length>0&&(t=n[0].trim()),t=t.replace(/_RAT$/i,""),t=t.replace(/_MOUSE$/i,""),t=t.replace(/_HUMAN$/i,""),t.length>0&&t[0]===t[0].toLowerCase()&&t[0]!==t[0].toUpperCase()&&(t=t[0].toUpperCase()+t.slice(1)),t.length>60&&(t=t.slice(0,57)+"..."),""===t||t.length<3||t.toLowerCase().includes("uncharacterized")?null:t}function m(e,t,n){return e+(t?"*":"")+(n?"†":"")}function h(e,t){if(!t)return null;const n=[t.external_name,t.display_name,t.description?t.description.split("[")[0].trim():void 0];for(const t of n)if(t&&t!==e&&!p(t))return t;return null}async function g(e,t){const n=(0,o.k)(e,i.iu.GENE_SYMBOL,["gene name","gene names","gene symbol"]),u=e.rowCount,g=new Array(u).fill(""),y=new Array(u).fill("");if(null!=n)for(let e=0;e<u;e++){const t=n.get(e),r=null==t?"":String(t);g[e]=r}const w=(0,o.k)(e,i.iu.PROTEIN_ID,["protein ids","primary protein id","protein id","majority protein ids","accession","uniprot"]),v=[],b=(e,t,n)=>{if(!t)return!1;const r=t.includes("*"),o=t.replace(/[*†]/g,"");return!!p(o)&&(v.push({row:e,clean:o,hadAsterisk:r,source:n}),!0)};for(let e=0;e<u;e++){const t=null!=n?n.get(e):null;if(!b(e,null==t?"":String(t),"gene")&&null!=w){const t=w.get(e);b(e,null==t?"":String(t).split(";")[0],"protein")}}for(const t of["Display Name","Source ID"])null!=e.col(t)&&e.columns.remove(t);if(0===v.length){const t=e.columns.addNewString("Display Name");t.init(e=>g[e]),t.semType=i.iu.DISPLAY_NAME;const n=e.columns.addNewString("Source ID");return n.init(e=>y[e]),void(n.semType=i.iu.SOURCE_ID)}const _=[...new Set(v.map(e=>e.clean))].filter(e=>f(e)),x=await async function(){try{const e=await r.dapi.userDataStorage.get(s)??{};return e[c]!==l?{[c]:l}:e}catch{return{[c]:l}}}(),N={},C=new Map;for(const e of _){const t=x[e];t&&"object"==typeof t&&C.set(e,t)}const S=_.filter(e=>!C.has(e));let T=!1;if(S.length>0){const e=function(e){const t=[];for(let n=0;n<e.length;n+=1e3)t.push(e.slice(n,n+1e3));return t}(S),n=e.length;let o=0;try{await(0,a.Pd)(e,6,async e=>{const i=await async function(e){const t=new Map;if(0===e.length)return t;const n=async()=>r.dapi.fetchProxy("https://rest.ensembl.org/lookup/id",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({ids:e})});let o,i;try{o=await n()}catch(e){return console.warn(`Ensembl lookup/id batch failed (network): ${e?.message??e}`),t}if(429===o.status){const e=parseFloat(o.headers.get("Retry-After")??"1"),r=Math.min(3e4,Math.max(0,1e3*e));await new Promise(e=>setTimeout(e,r));try{o=await n()}catch(e){return console.warn(`Ensembl lookup/id retry failed: ${e?.message??e}`),t}}if(!o.ok)return console.warn(`Ensembl lookup/id returned status ${o.status}; continuing`),t;try{i=await o.json()}catch(e){return console.warn(`Ensembl lookup/id JSON parse failed: ${e?.message??e}`),t}if(i&&"object"==typeof i)for(const[e,n]of Object.entries(i))if(n&&"object"==typeof n){const r=n,o={};"string"==typeof r.display_name&&(o.display_name=r.display_name),"string"==typeof r.external_name&&(o.external_name=r.external_name),"string"==typeof r.description&&(o.description=r.description),"string"==typeof r.species&&(o.species=r.species),"string"==typeof r.biotype&&(o.biotype=r.biotype),"string"==typeof r.object_type&&(o.object_type=r.object_type),t.set(e,o)}return t}(e);for(const[e,t]of i)C.set(e,t),N[e]=t;for(const t of e)i.has(t)||(T=!0);o++,t?.(o,n,"lookup")})}finally{await async function(e,t){try{await r.dapi.userDataStorage.put(s,{...e,...t,[c]:l})}catch(e){console.warn(`Gene-label cache write failed: ${e?.message??e}`)}}(x,N)}}const E=e.col("Protein Descriptions")??e.col("Protein names")??e.col("Description")??e.col("protein_descriptions");for(const e of v){const t=C.get(e.clean);let n=h(e.clean,t);if(null==n&&null!=t){const r=d(t.description??null);null==r||r===e.clean||p(r)||(n=r)}if(null==n&&null!=E){const t=E.get(e.row),r=d(null==t?null:String(t));null!=r&&r!==e.clean&&!p(r)&&r.length>3&&(n=r)}const r=m(n??e.clean,e.hadAsterisk,!0);g[e.row]=r,y[e.row]=e.clean}t?.(v.length,v.length,"apply");const P=new Map,D=new Map;for(let e=0;e<u;e++){const t=g[e],n=y[e];t&&n&&(P.has(t)||P.set(t,new Set),P.get(t).add(n),D.has(t)||D.set(t,[]),D.get(t).push(e))}let L=0;for(const[e,t]of P)if(!(t.size<=1))for(const t of D.get(e)??[]){const n=y[t];n&&(g[t]=`${e} (${n})`,L++)}if(L>0&&r.shell.warning(`${L} duplicate gene names disambiguated with source IDs.`),T){const e=v.filter(e=>f(e.clean)&&!C.has(e.clean)).length;r.shell.warning(`Ensembl gene-label resolution unavailable. Showing raw IDs (${e} unresolved). Re-import to retry.`)}const A=e.columns.addNewString("Display Name");A.init(e=>g[e]),A.semType=i.iu.DISPLAY_NAME;const M=e.columns.addNewString("Source ID");M.init(e=>y[e]),M.semType=i.iu.SOURCE_ID}},935(e,t,n){"use strict";n.d(t,{$S:()=>a,Ae:()=>r,Vr:()=>c,X3:()=>i});const r=[{display:"Homo sapiens (Human)",code:"hsapiens"},{display:"Mus musculus (Mouse)",code:"mmusculus"},{display:"Rattus norvegicus (Rat)",code:"rnorvegicus"},{display:"Saccharomyces cerevisiae (Yeast)",code:"scerevisiae"},{display:"Escherichia coli (K12)",code:"ecoli"},{display:"Danio rerio (Zebrafish)",code:"drerio"},{display:"Drosophila melanogaster (Fruit fly)",code:"dmelanogaster"},{display:"Arabidopsis thaliana",code:"athaliana"},{display:"Caenorhabditis elegans",code:"celegans"}],o=r.map(e=>({scientific:e.display.split("(")[0].trim().toLowerCase(),code:e.code}));function i(e){return r.find(t=>t.code===e)?.display}function a(e){return r.find(t=>t.display===e)?.code}function s(e){if(!e)return;const t=e.toLowerCase();for(const{scientific:e,code:n}of o)if(t.includes(e))return n}const l=["pg.organisms","organism","organisms","species"];function c(e){const t=function(e){for(const t of e.columns.toList()){const e=t.name.toLowerCase();if(l.some(t=>e===t||e.includes(t)))return t}return null}(e);if(!t)return;const n=new Set;for(let e=0;e<t.length;e++){if(t.isNone(e))continue;const r=s(t.get(e));if(r&&n.add(r),n.size>1)return}return 1===n.size?[...n][0]:void 0}},641(e,t,n){"use strict";n.d(t,{Dx:()=>i,M5:()=>o,PL:()=>a,iu:()=>r});const r={PROTEIN_ID:"Proteomics-ProteinId",GENE_SYMBOL:"Proteomics-GeneSymbol",LOG2FC:"Proteomics-Log2FC",P_VALUE:"Proteomics-PValue",INTENSITY:"Proteomics-Intensity",SUBCELLULAR_LOCATION:"Proteomics-SubcellularLocation",DISPLAY_NAME:"Proteomics-DisplayName",SOURCE_ID:"Proteomics-SourceId",NUMERATOR_MEAN:"Proteomics-NumeratorMean",DENOMINATOR_MEAN:"Proteomics-DenominatorMean"},o=1,i=.05,a={enrichedG1:4294902015,enrichedG2:4278255615,notSig:4289374890}},897(e,t,n){"use strict";n.d(t,{YS:()=>w,aB:()=>h,q6:()=>y});var r=n(328),o=n(389),i=n(82),a=n(858),s=n(304),l=n(641);let c=[];const u="negLog10FDR",f="~enrichChartTop";function p(e){const t=[`\${${f}}`];return e&&t.push(`\${Direction} == "${e}"`),t.join(" and ")}function d(e,t){return i.Viewer.scatterPlot(e,{x:"Gene Ratio",y:"Term Name",sizeColumnName:"Gene Count",colorColumnName:u,markerMinSize:5,markerMaxSize:25,filter:p(t),title:t?`Enrichment — ${t}`:"Enrichment Dot Plot"})}function m(e,t){return i.Viewer.barChart(e,{splitColumnName:"Term Name",valueColumnName:u,valueAggrType:"avg",barSortType:"by value",barSortOrder:"desc",orientation:"Horizontal",filter:p(t),title:t?`Top Enriched — ${t}`:"Top Enriched Terms"})}function h(e,t){const n=(0,s.k)(t,l.iu.GENE_SYMBOL,["gene name","gene symbol"]);if(!n)return a.Subscription.EMPTY;const r=new Map;for(let e=0;e<t.rowCount;e++)if(!n.isNone(e)){const t=n.get(e).trim();r.has(t)||r.set(t,[]),r.get(t).push(e)}return e.onCurrentRowChanged.subscribe(()=>{const n=e.currentRowIdx;if(n<0)return;const o=e.col("Intersection");if(!o)return;const i=o.get(n);if(!i)return;const a=i.split(",").map(e=>e.trim()).filter(Boolean);t.selection.setAll(!1,!1);for(const e of a){const n=r.get(e);if(n)for(const e of n)t.selection.set(e,!0,!1)}t.selection.fireChanged()})}function g(e,t){const n=e.col("Direction");if(!n)return!1;for(let r=0;r<e.rowCount;r++)if(n.get(r)===t)return!0;return!1}function y(e,t){for(const e of c)e.unsubscribe();let n;c=[];for(const t of r.shell.tableViews)if(t.dataFrame?.dart===e.dart){n=t;break}const a=n??r.shell.addTableView(e);r.shell.v=a;const s=a;if("true"===e.getTag("proteomics.enrichment_smart_filtered")){const t=e.getTag("proteomics.enrichment_smart_filtered_kept")??"?",n=e.getTag("proteomics.enrichment_smart_filtered_total")??"?",r=e.getTag("proteomics.enrichment_smart_filtered_dropped_parents")??"?",s=e.getTag("proteomics.enrichment_smart_filtered_cap")??"15",l=o.divText(`Smart pathway filter active: showing ${t} of ${n} terms (dropped ${r} generic parents, capped at ${s} per source). Re-run with the filter off to see all.`);l.dataset.smartFilterBanner="true",a.dockManager.dock(l,i.DOCK_TYPE.TOP,null,"Smart Filter Info",.1)}return w(s,e),c.push(h(e,t)),a}function w(e,t){if(function(e,t=15){const n=e.col("FDR");if(!n)return;const r=-Math.log10(Number.MIN_VALUE),o=n.getRawData();e.columns.contains(u)&&e.columns.remove(u);const i=e.columns.addNewFloat(u);i.init(e=>o[e]>0?-Math.log10(o[e]):r),i.setTag(".hidden","true");const a=e.col("Direction"),s=new Map;for(let t=0;t<e.rowCount;t++){if(n.isNone(t))continue;const e=a?String(a.get(t)):"";s.has(e)||s.set(e,[]),s.get(e).push({idx:t,fdr:n.get(t)})}const l=new Array(e.rowCount).fill(!1);for(const e of s.values()){e.sort((e,t)=>e.fdr-t.fdr);for(let n=0;n<Math.min(t,e.length);n++)l[e[n].idx]=!0}e.columns.contains(f)&&e.columns.remove(f),e.columns.addNewBool(f).init(e=>l[e])}(t),g(t,"Up")&&g(t,"Down")){const n=e.dockManager.dock(d(t,"Up"),i.DOCK_TYPE.RIGHT,null,"Up — Dot Plot",.6),r=e.dockManager.dock(d(t,"Down"),i.DOCK_TYPE.RIGHT,n,"Down — Dot Plot",.5);return e.dockManager.dock(m(t,"Up"),i.DOCK_TYPE.DOWN,n,"Up — Bar Chart",.5),void e.dockManager.dock(m(t,"Down"),i.DOCK_TYPE.DOWN,r,"Down — Bar Chart",.5)}const n=e.dockManager.dock(d(t),i.DOCK_TYPE.RIGHT,null,"Dot Plot",.5);e.dockManager.dock(m(t),i.DOCK_TYPE.DOWN,n,"Bar Chart",.5)}},644(e,t,n){"use strict";n.d(t,{Z7:()=>h});var r=n(82),o=n(304),i=n(641),a=n(252);const s="Numerator Mean",l="Denominator Mean",c=`\${${s}} = \${${l}}`;function u(e,t){return e.columns.contains(t)&&e.columns.remove(t),e.columns.addNewFloat(t)}function f(e,t){let n=0,r=0;for(const o of e)o.isNone(t)||(n+=o.get(t),r++);return r>0?n/r:NaN}function p(e,t){let n=0,o=0,i=0;for(let a=0;a<e.length;a++){const s=e[a],l=t[a];Number.isFinite(s)&&Number.isFinite(l)&&s!==r.FLOAT_NULL&&l!==r.FLOAT_NULL&&(o+=s,i+=l,n++)}if(0===n)return NaN;const a=o/n,s=i/n;let l=0,c=0,u=0;for(let n=0;n<e.length;n++){const o=e[n],i=t[n];if(!Number.isFinite(o)||!Number.isFinite(i)||o===r.FLOAT_NULL||i===r.FLOAT_NULL)continue;const f=o-a,p=i-s;l+=f*p,c+=f*f,u+=p*p}const f=Math.sqrt(c*u);return 0===f?NaN:l/f}function d(e){const t=e.map((e,t)=>({v:e,i:t}));t.sort((e,t)=>e.v-t.v);const n=new Array(e.length);let r=0;for(;r<t.length;){let e=r;for(;e+1<t.length&&t[e+1].v===t[r].v;)e++;const o=(r+e)/2+1;for(let i=r;i<=e;i++)n[t[i].i]=o;r=e+1}return n}function m(e,t){return p(d(e),d(t))}function h(e,t){const n=(0,a.f)(e);if(!n)throw new Error("Annotate experimental groups first (Proteomics | Annotate Experiment)");!function(e,t){const n=t.group1.columns.map(t=>e.col(t)).filter(e=>null!=e),o=t.group2.columns.map(t=>e.col(t)).filter(e=>null!=e),a=e.rowCount,c=new Float32Array(a),p=new Float32Array(a);for(let e=0;e<a;e++){const t=f(n,e),i=f(o,e);c[e]=isNaN(t)?r.FLOAT_NULL:t,p[e]=isNaN(i)?r.FLOAT_NULL:i}const d=u(e,s);d.init(e=>c[e]),d.semType=i.iu.NUMERATOR_MEAN;const m=u(e,l);m.init(e=>p[e]),m.semType=i.iu.DENOMINATOR_MEAN}(e,n);const d=e.plot.scatter({x:s,y:l,color:"direction"}),h=(0,o.k)(e,i.iu.DISPLAY_NAME,["display name"])??(0,o.k)(e,i.iu.GENE_SYMBOL,["gene name","gene symbol"]);h&&(d.props.labelColumnNames=[h.name],d.props.showLabelsFor="MouseOverRow"),e.meta.formulaLines.items=e.meta.formulaLines.items.filter(e=>{const t=e.formula??"";return!("string"==typeof t&&t.includes(s)&&t.includes(l))}),e.meta.formulaLines.addLine({formula:c,color:"#888888",width:1,visible:!0}),d.props.showViewerFormulaLines=!0;const{r:g,rho:y}=function(e,t,n){const o=e.col(t),i=e.col(n);if(!o||!i)return{r:NaN,rho:NaN};const a=o.getRawData(),s=i.getRawData(),l=[],c=[];for(let t=0;t<e.rowCount;t++){if(!e.filter.get(t))continue;const n=a[t],o=s[t];n!==r.FLOAT_NULL&&o!==r.FLOAT_NULL&&Number.isFinite(n)&&Number.isFinite(o)&&(l.push(n),c.push(o))}return{r:p(l,c),rho:m(l,c)}}(e,s,l),w=t?.title??"Group-Mean Correlation",v=Number.isFinite(g)?g.toFixed(2):"NA",b=Number.isFinite(y)?y.toFixed(2):"NA";return d.setOptions({title:`${w} — r=${v} (Pearson), ρ=${b} (Spearman)`,xColumnLabel:`${n.group1.name} mean (log2 intensity)`,yColumnLabel:`${n.group2.name} mean (log2 intensity)`}),d}},715(e,t,n){"use strict";n.d(t,{Hc:()=>a,JZ:()=>f,Pq:()=>u,ho:()=>p,iQ:()=>c,j4:()=>d,rA:()=>m});var r=n(82),o=n(641),i=n(304);function a(e){return e.columns.toList().filter(e=>e.semType===o.iu.INTENSITY&&e.name.startsWith("log2(")).map(e=>e.name)}function s(e,t){let n=0,r=0;for(const o of e)o.isNone(t)||(n+=o.get(t),r++);return r>0?n/r:NaN}function l(e,t){return e.columns.contains(t)&&e.columns.remove(t),e.columns.addNewFloat(t)}function c(e,t){const n=t.group1.columns.map(t=>e.col(t)),o=t.group2.columns.map(t=>e.col(t)),i=e.rowCount,a=new Float32Array(i),c=new Float32Array(i);for(let e=0;e<i;e++){const t=s(n,e),i=s(o,e);isNaN(t)||isNaN(i)?(a[e]=r.FLOAT_NULL,c[e]=r.FLOAT_NULL):(a[e]=i-t,c[e]=(t+i)/2)}l(e,"M").init(e=>a[e]),l(e,"A").init(e=>c[e])}function u(e,t=.1){const n=e.col("A"),o=e.col("M");if(!n||!o)return void l(e,"MA_trend");const i=n.getRawData(),a=o.getRawData(),s=[];for(let t=0;t<e.rowCount;t++)i[t]!==r.FLOAT_NULL&&a[t]!==r.FLOAT_NULL&&s.push({idx:t,a:i[t],m:a[t]});const c=new Float32Array(e.rowCount);if(c.fill(r.FLOAT_NULL),s.length<3)return void l(e,"MA_trend").init(e=>c[e]);s.sort((e,t)=>e.a-t.a);const u=Math.max(Math.round(s.length*t/2),5);for(let e=0;e<s.length;e++){const t=Math.max(0,e-u),n=Math.min(s.length-1,e+u);let r=0,o=0;for(let e=t;e<=n;e++)r+=s[e].m,o++;c[s[e].idx]=r/o}l(e,"MA_trend").init(e=>c[e])}function f(e,t,n,o){const i=t.map(t=>e.col(t)).filter(e=>null!=e&&e.type===r.COLUMN_TYPE.FLOAT).map(e=>e.getRawData()),a=e.rowCount,s=new Float32Array(a),c=new Float32Array(a);for(let e=0;e<a;e++){let t=0,n=0,o=0;for(const a of i){const i=a[e];if(i!==r.FLOAT_NULL){const e=Math.pow(2,i);t++;const r=e-n;n+=r/t,o+=r*(e-n)}}if(t<1)s[e]=r.FLOAT_NULL,c[e]=r.FLOAT_NULL;else if(t<2)s[e]=r.FLOAT_NULL,c[e]=n;else{const i=o/(t-1),a=Math.sqrt(Math.max(0,i));s[e]=n>0?a/n:r.FLOAT_NULL,c[e]=n}}l(e,n).init(e=>s[e]),l(e,o).init(e=>c[e])}function p(e,t){const n=[],a=(0,i.k)(e,o.iu.PROTEIN_ID,["protein id","accession"]);a&&n.push(a.clone());for(const o of t){const t=e.col(o),i=t.type===r.COLUMN_TYPE.FLOAT?t.getRawData():null,a=new Int32Array(e.rowCount);if(i)for(let t=0;t<e.rowCount;t++)a[t]=i[t]===r.FLOAT_NULL?0:1;else for(let n=0;n<e.rowCount;n++)a[n]=t.isNone(n)?0:1;n.push(r.Column.fromInt32Array(o,a))}const s=r.DataFrame.fromColumns(n);return s.name="Missing Values",s}function d(e,t){const n=(0,i.k)(e,o.iu.PROTEIN_ID,["protein id","accession"]),a=[],s=[],l=[];for(let r=0;r<e.rowCount;r++){const o=n?n.get(r)??String(r):String(r);for(const n of t){const t=e.col(n);t.isNone(r)||(a.push(o),s.push(n),l.push(t.get(r)))}}const c=r.DataFrame.fromColumns([r.Column.fromStrings("ProteinId",a),r.Column.fromStrings("Sample",s),r.Column.fromFloat32Array("Intensity",new Float32Array(l))]);return c.name="Intensity Distributions",c}function m(e,t,n){const o=[],i=[],a=[],s=new Set(n.group1.columns),l=new Set(n.group2.columns);for(const r of t){const t=e.col(r);let c=0;for(let n=0;n<e.rowCount;n++)t.isNone(n)&&c++;o.push(r),i.push(c/e.rowCount*100),s.has(r)?a.push(n.group1.name):l.has(r)?a.push(n.group2.name):a.push("Other")}const c=r.DataFrame.fromColumns([r.Column.fromStrings("Sample",o),r.Column.fromFloat32Array("MissingPct",new Float32Array(i)),r.Column.fromStrings("Group",a)]);return c.name="Missing Values per Sample",c}},589(e,t,n){"use strict";n.d(t,{r9:()=>v});var r=n(328),o=n(389),i=n(82),a=n(655),s=n(883);const l=["median_intensity","missing_pct","control_corr","protein_count"],c={median_intensity:"Median log2 intensity",missing_pct:"Missing %",control_corr:"Control replicate correlation",protein_count:"Protein count"},u="#888888",f="#666666",p="spc.last_picked_instrument",d={rule_1_only:"Expected false-alarm rate at this rule set: ~0.27%. (Rule 1 only — a point beyond 3σ.)",rules_1_5:"Expected false-alarm rate at this rule set: ~0.4%. (Rules 1 + 5 — a single point beyond 3σ, or 2 of 3 beyond 2σ.)",rules_1_5_2:"Enabling rules 1+5+2 raises the expected false-alarm rate to ~1.1%.",rules_all_8:"Expected false-alarm rate at this rule set: ~2.65%. Enabling all 8 rules will flag roughly 1 in 38 normal-operation runs.",rules_other:"More rules enabled → higher false-alarm rate. The Nelson 1+5 default is calibrated for ~0.4%."};function m(e){const t=e.median_intensity,n=Object.entries(t).filter(([e,t])=>t).map(([e])=>e).sort();return 1===n.length&&"nelson_1"===n[0]?"rule_1_only":2===n.length&&"nelson_1"===n[0]&&"nelson_5"===n[1]?"rules_1_5":3===n.length&&n.includes("nelson_1")&&n.includes("nelson_5")&&n.includes("nelson_2")?"rules_1_5_2":8===n.length?"rules_all_8":"rules_other"}function h(e,t,n){const r=i.Viewer.lineChart(e,{xColumnName:"acquisition_datetime",yColumnNames:[n],title:c[n]});if(t){const e=function(e,t){if(!e)return{ucl:NaN,cl:NaN,lcl:NaN};const n=e.metrics[t];return n&&Number.isFinite(n.mean)&&Number.isFinite(n.sd)?{ucl:n.mean+3*n.sd,cl:n.mean,lcl:n.mean-3*n.sd}:{ucl:NaN,cl:NaN,lcl:NaN}}(t,n);if(Number.isFinite(e.cl)){const t=r?.meta?.formulaLines;if(t&&"function"==typeof t.addLine)try{t.addLine({formula:`\${${n}} = ${e.ucl}`,color:f,width:1,style:"dashed",visible:!0,title:"UCL"}),t.addLine({formula:`\${${n}} = ${e.cl}`,color:u,width:1,style:"solid",visible:!0,title:"CL"}),t.addLine({formula:`\${${n}} = ${e.lcl}`,color:f,width:1,style:"dashed",visible:!0,title:"LCL"})}catch(e){}}}const o=`MR_${n}`,s=i.Viewer.lineChart(e,{xColumnName:"acquisition_datetime",yColumnNames:[o],title:`MR ${c[n]}`});if(t&&e.col(o)){const t=e.col(o);let n=0,r=0;for(let o=0;o<e.rowCount;o++){if(t.isNone(o))continue;const e=Number(t.get(o));Number.isFinite(e)&&(n+=e,r++)}if(r>0){const e=n/r,t=a.Mj*e,i=s?.meta?.formulaLines;if(i&&"function"==typeof i.addLine)try{i.addLine({formula:`\${${o}} = ${t}`,color:f,width:1,style:"dashed",visible:!0,title:"MR UCL"}),i.addLine({formula:`\${${o}} = ${e}`,color:u,width:1,style:"solid",visible:!0,title:"MR CL"})}catch(e){}}}return{iChart:r,mrChart:s}}function g(e){switch(e){case"nelson_1":return"Nelson rule 1: a single point beyond 3σ from the centerline.";case"nelson_2":return"Nelson rule 2: 9 consecutive points on the same side of the centerline.";case"nelson_3":return"Nelson rule 3: 6 consecutive points all trending up, or all trending down.";case"nelson_4":return"Nelson rule 4: 14 consecutive points alternating above and below the centerline.";case"nelson_5":return"Nelson rule 5: 2 out of 3 consecutive points beyond 2σ on the same side.";case"nelson_6":return"Nelson rule 6: 4 out of 5 consecutive points beyond 1σ on the same side.";case"nelson_7":return"Nelson rule 7: 15 consecutive points within 1σ of the centerline (unusually stable).";case"nelson_8":return"Nelson rule 8: 8 consecutive points more than 1σ from the centerline on either side."}}function y(e,t){const n=e.rowCount;if(0===n)return;const r={median_intensity:e.col("median_intensity"),missing_pct:e.col("missing_pct"),control_corr:e.col("control_corr"),protein_count:e.col("protein_count")},o=e.col("status"),i=e.col("rules_tripped");if(o&&i){for(let e=0;e<n;e++){const n={median_intensity:Number(r.median_intensity?.get(e)),missing_pct:Number(r.missing_pct?.get(e)),control_corr:Number(r.control_corr?.get(e)),protein_count:Number(r.protein_count?.get(e)),sample_count:0,computed_at:""},s={median_intensity:[],missing_pct:[],control_corr:[],protein_count:[]};for(let t=0;t<e;t++)s.median_intensity.push(Number(r.median_intensity?.get(t))),s.missing_pct.push(Number(r.missing_pct?.get(t))),s.control_corr.push(Number(r.control_corr?.get(t))),s.protein_count.push(Number(r.protein_count?.get(t)));const l=(0,a.uV)(n,s,t.metrics,t.rules_enabled);o.set(e,l.status),i.set(e,JSON.stringify(l.rulesTripped))}a.classifyStatus}}function w(e,t,n,i){const u=!!i,f=u?`Rebuild baseline for ${e}`:`Lock baseline for ${e}`,p=t.slice().sort((e,t)=>e.acquisition_datetime.localeCompare(t.acquisition_datetime)),h=new Set;if(u)for(const e of i.included_run_ids)h.add(e);else{const e=Math.min(7,p.length);for(let t=0;t<e;t++)h.add(p[t].run_id)}const y=[],w=o.divV([]);w.style.maxHeight="300px",w.style.overflowY="auto";for(const e of p){const t=o.input.bool("",{value:h.has(e.run_id)});y.push({run:e,input:t}),w.appendChild(o.divH([t.root,o.divText(e.acquisition_datetime.slice(0,10)),o.divText(e.run_label)]))}const v=o.input.bool("Iterate 3σ outlier removal (recommended)",{value:!u||i.iteration_trace.length>0,tooltipText:"When on, runs more than 3 standard deviations from the baseline mean are dropped from the baseline. Capped at 2 passes."}),b=i?.rules_enabled??(0,a.kY)(),_=["nelson_1","nelson_2","nelson_3","nelson_4","nelson_5","nelson_6","nelson_7","nelson_8"],x={median_intensity:{},missing_pct:{},control_corr:{},protein_count:{}},N=[o.divH([o.divText(""),..._.map(e=>o.divText(e.replace("nelson_","R")))])],C=o.divText(d[m(b)]);for(const e of l){const t=[o.divText(c[e])];for(const n of _){const r=o.input.bool("",{value:b[e][n],tooltipText:g(n)});r.onChanged.subscribe(()=>{const e=S();C.textContent=d[m(e)]}),x[e][n]=r,t.push(r.root)}N.push(o.divH(t))}function S(){const e={};for(const t of l){e[t]={};for(const n of _)e[t][n]=!!x[t][n].value}return e}const T=[];u?T.push(o.divText(`This replaces the locked baseline from ${i.locked_at}. The previous baseline is not kept.`)):T.push(o.divText("Pick the runs that represent normal operation:")),T.push(w),T.push(v.root),T.push(o.h2("Nelson rules")),T.push(o.divV(N)),T.push(C);const E=o.dialog(f);for(const e of T)E.add(e);E.onOK(async()=>{const t=y.filter(e=>!0===e.input.value).map(e=>e.run);if(t.length<3)return void r.shell.warning("At least 3 runs must remain after outlier removal — too few to compute a baseline.");const o=new Set,i=[];if(v.value)for(const e of l){const n=t.map(t=>({run_id:t.run_id,value:t[e]})),r=(0,s.oF)(n,2);for(const e of r.excluded_run_ids)o.add(e);for(const e of r.iteration_trace)i.push(e)}const a=t.filter(e=>!o.has(e.run_id));if(a.length<3)return void r.shell.warning("At least 3 runs must remain after outlier removal — too few to compute a baseline.");const c=(0,s.OI)(a),f={instrument_id:e,locked_at:(new Date).toISOString(),included_run_ids:a.map(e=>e.run_id),excluded_run_ids:Array.from(o),iteration_trace:i,metrics:c,rules_enabled:S()};await n(f),u?r.shell.info(`Baseline rebuilt for ${e}: ${a.length} runs included, ${o.size} excluded. Previous baseline replaced.`):r.shell.info(`Baseline locked for ${e}: ${a.length} runs included, ${o.size} excluded.`)}),E.show()}async function v(){const e=await(0,s.loadRuns)();if(0===e.length)return void r.shell.warning("No SPC runs recorded yet. Open an analyzed file, then run Analyze → Compute SPC Status. The dashboard turns on once at least 4 runs have been computed.");const t=Array.from(new Set(e.map(e=>e.instrument_id))),n=await r.dapi.userDataStorage.get(p),u=n&&n.instrument_id||t[0],f=new Map;for(const e of t)f.set(e,await(0,s.loadBaseline)(e));const v=t.map(e=>f.get(e)?`${e} (baseline locked)`:`${e} (no baseline)`),b=new Map;for(let e=0;e<t.length;e++)b.set(v[e],t[e]);const _=v[t.indexOf(u)]??v[0],x=o.input.choice("Instrument",{value:_,items:v,nullable:!1,tooltipText:"Switches the trend charts and baseline to a different instrument. Only instruments with computed SPC runs are listed."});o.dialog("SPC Dashboard").add(x).onOK(async()=>{const e=b.get(String(x.value))??t[0];await r.dapi.userDataStorage.put(p,{instrument_id:e}),await async function(e){const t=await(0,s.loadRuns)(e);let n;n=0===t.length?i.DataFrame.create(0):(0,s.$G)(t),n.name=`SPC — ${e}`,function(e){for(const t of l){const n=e.col(t);if(!n)continue;const r=`MR_${t}`;e.columns.contains(r)&&e.columns.remove(r);const o=e.columns.addNewFloat(r),i=e.rowCount;let a=null;for(let e=0;e<i;e++){if(0===e){o.set(e,null),a=null;continue}if(n.isNone(e)||n.isNone(e-1)){o.set(e,null);continue}const t=Number(n.get(e)),r=Number(n.get(e-1));Number.isFinite(t)&&Number.isFinite(r)?(o.set(e,Math.abs(t-r)),a=t):o.set(e,null)}}}(n);const u=r.shell.addTableView(n);let f=await(0,s.loadBaseline)(e);const p=()=>{for(const e of l){const{iChart:t,mrChart:r}=h(n,f,e);u.dockManager.dock(t,i.DOCK_TYPE.RIGHT,null,`I-chart ${c[e]}`,.5),u.dockManager.dock(r,i.DOCK_TYPE.DOWN,null,`MR-chart ${c[e]}`,.5)}const t=function(e,t){if(e.rowCount<4)return null;const n=e.col("rules_tripped");if(!n)return null;const r=e.rowCount,o=[];for(let e=0;e<r;e++){const t=String(n.get(e)??"");let r=[];if(t.length>0)try{r=JSON.parse(t)}catch{r=[]}o.push({rules_tripped:r})}const a=function(e){const t=new Map;for(const n of e){const e=Array.isArray(n.rules_tripped)?n.rules_tripped:[];for(const n of e){const e=t.get(n)??0;t.set(n,e+1)}}const n=[];for(const[e,r]of t.entries()){const t=e.indexOf("@");t<0?n.push({rule:e,metric:"",count:r}):n.push({rule:e.slice(0,t),metric:e.slice(t+1),count:r})}return n.sort((e,t)=>t.count-e.count),n}(o);if(0===a.length)return null;const s=i.Column.fromStrings("rule_metric",a.map(e=>e.metric?`${e.rule}@${e.metric}`:e.rule)),l=new Int32Array(a.map(e=>e.count)),c=new Int32Array(a.map(()=>r)),u=new Float32Array(a.map(e=>e.count/r*100)),f=i.DataFrame.fromColumns([s,i.Column.fromInt32Array("trip_count",l),i.Column.fromInt32Array("total_runs",c),i.Column.fromFloat32Array("pct",u)]),p=i.Viewer.barChart(f,{splitColumnName:"rule_metric",valueColumnName:"trip_count",title:`Which rules trip most often — ${t}`});try{p.props.xLabel="(rule, metric)",p.props.yLabel="Times tripped"}catch(e){}return p}(n,e);if(null!==t)u.dockManager.dock(t,i.DOCK_TYPE.DOWN,null,"Pareto",.3);else{const e=o.divV([o.divText("Pareto chart appears once 4 or more runs have been recorded for this instrument.")]);u.dockManager.dock(e,i.DOCK_TYPE.DOWN,null,"Pareto",.3)}},v=function(e,t,n,r){const i=o.h2(`Instrument: ${e}`);let s;s=t?o.divV([o.divText(`Baseline locked: ${t.locked_at}`),o.divText(`${t.included_run_ids.length} runs included · ${t.excluded_run_ids.length} runs excluded (3σ outlier).`),o.button("Rebuild baseline...",n)]):o.divV([o.divText("No baseline locked yet. The dashboard turns on once a baseline exists.")]);const u=["nelson_1","nelson_2","nelson_3","nelson_4","nelson_5","nelson_6","nelson_7","nelson_8"],f=t?.rules_enabled??(0,a.kY)(),p=o.divText(d[m(f)]),h=[];h.push(o.divH([o.divText(""),...u.map(e=>o.divText(e.replace("nelson_","R")))]));for(const e of l){const t=[o.divText(c[e])];for(const n of u){const i=o.input.bool("",{value:f[e][n],tooltipText:g(n)});i.onChanged.subscribe(async t=>{await r(e,n,!!t)}),t.push(i.root)}h.push(o.divH(t))}return{el:o.divV([i,s,o.h2("Nelson rules"),o.divV(h),p]),setDisclosure:e=>{p.textContent=e}}}(e,f,()=>{w(e,t,async t=>{await(0,s.saveBaseline)(e,t),f=t,y(n,t),p()},f??void 0)},async(t,r,o)=>{f&&(f.rules_enabled[t][r]=o,await(0,s.saveBaseline)(e,f),y(n,f))});if(u.dockManager.dock(v.el,i.DOCK_TYPE.LEFT,null,"SPC Controls",.25),null===f){const r=o.divV([o.h2(`No baseline locked for ${e}.`),o.divText("Pick the runs that represent normal operation, then click Lock baseline. The dashboard turns on once a baseline exists."),o.button("Define baseline...",()=>{w(e,t,async t=>{await(0,s.saveBaseline)(e,t),f=t,y(n,t),p()})})]);u.dockManager.dock(r,i.DOCK_TYPE.RIGHT,null,"Baseline",.75)}else p();!function(e,t){e.dataFrame.onCurrentRowChanged.subscribe(async()=>{const e=t.currentRowIdx;if(e<0)return;const n=String(t.col("status")?.get(e)??"");if("flagged"!==n&&"out_of_control"!==n)return;const o=t.col("source_project_id")?.get(e),i=null==o||""===o?null:String(o),a=await async function(e,t){if(null==e.source_project_id)return{kind:"toast",message:`Source for '${e.run_label}' is not currently available. Open the run's analyzed file and re-run Compute SPC Status.`};const n=await t.projectsFind(e.source_project_id);return n?(await n.open(),{kind:"opened",id:e.source_project_id}):{kind:"toast",message:`Source for '${e.run_label}' is not currently available. Open the run's analyzed file and re-run Compute SPC Status.`}}({run_id:String(t.col("run_id")?.get(e)??""),run_label:String(t.col("run_label")?.get(e)??""),source_project_id:i},{projectsFind:async e=>{const t=await r.dapi.projects.find(e);return t?{open:()=>t.open()}:null}});"toast"===a.kind&&r.shell.warning(a.message)})}(u,n)}(e)}).show()}},70(e,t,n){"use strict";n.d(t,{Bb:()=>E,DI:()=>T,EO:()=>b,GE:()=>I,S6:()=>O,XC:()=>R,fQ:()=>m,gO:()=>k,kX:()=>P,m2:()=>$,nj:()=>U,ur:()=>C});var r=n(82),o=n(389),i=n(713),a=n(304),s=n(641),l=n(498),c=n(252),u=n(623);const f=-Math.log10(Number.MIN_VALUE),p="negLog10P",d="direction",m="Subcellular Location",h="proteomics.volcano_metric";let g=[];const y="proteomics-volcano";function w(e,t){if("p-value"===t){const t=e.col("p-value");if(t)return t}const n=e.col("adj.p-value");if(!n)throw new Error("adj.p-value column not found");return n}function v(e,t="adj.p-value"){const n=w(e,t);return(e.col(p)??e.columns.addNewFloat(p)).init(e=>{if(n.isNone(e))return r.FLOAT_NULL;const t=n.get(e);return t>0?-Math.log10(t):f}),p}function b(e,t,n,r="adj.p-value"){const o=e.col("log2FC");if(!o)throw new Error("log2FC column not found");const i=w(e,r),a=(0,c.f)(e),l=a?`Enriched in ${a.group1.name}`:"Enriched in group1",u=a?`Enriched in ${a.group2.name}`:"Enriched in group2",f="Not significant",p=e.rowCount,m=new Array(p);for(let e=0;e<p;e++){if(o.isNone(e)||i.isNone(e)){m[e]=f;continue}const r=o.get(e),a=i.get(e);m[e]=a<=n&&r>t?l:a<=n&&r<-t?u:f}const h=e.col(d)??e.columns.addNewString(d);return h.init(e=>m[e]),h.meta.colors.setCategorical({[l]:s.PL.enrichedG1,[u]:s.PL.enrichedG2,[f]:s.PL.notSig}),d}const _="proteomics.location_acc_hash";function x(e,t,n,r){const o=-Math.log10(r),i=`\${${t}}`,a="${log2FC}";e.meta.formulaLines.items=e.meta.formulaLines.items.filter(e=>{const t=e.formula??"";return!("string"==typeof t&&(t.startsWith(i)||t.startsWith(a)))}),e.meta.formulaLines.addLine({formula:`${i} = ${o}`,color:"#888888",width:1,visible:!0}),e.meta.formulaLines.addLine({formula:`${a} = ${n}`,color:"#888888",width:1,visible:!0}),e.meta.formulaLines.addLine({formula:`${a} = ${-n}`,color:"#888888",width:1,visible:!0})}function N(e){return"p-value"===e?"-Log10(p-value)":"-Log10(Q-value)"}function C(e,t){const n=t.getOptions(),r=(n?.look??{}).colorColumnName===m?"location":"significance";return{metric:e.getTag(h)??"adj.p-value",colorDim:r}}function S(e,t){const n=e.root.querySelector("[data-volcano-axis-y]");if(n){const e=t.getTag(h);n.textContent=N(e)}}function T(e,t){P(e);const n=e.root;n.style.position=n.style.position||"relative";const r=o.divV([]);r.dataset.volcanoBusy="true",Object.assign(r.style,{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",padding:"12px 20px",background:"rgba(255,255,255,0.95)",border:"1px solid #ccc",borderRadius:"6px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)",fontSize:"0.95em",textAlign:"center",pointerEvents:"none",zIndex:"6",maxWidth:"320px"});const i=o.divText(t);i.style.fontWeight="bold",i.style.marginBottom="4px";const a=o.divText("");a.style.fontSize="0.85em",a.style.color="#666",r.appendChild(i),r.appendChild(a),n.appendChild(r)}function E(e,t,n){const r=e.root.querySelector("[data-volcano-busy]");if(!r)return;const[o,i]=Array.from(r.children);o&&(o.textContent=t),i&&(i.textContent=n??"")}function P(e){e.root.querySelectorAll("[data-volcano-busy]").forEach(e=>e.remove())}const D="~Volcano label",L="proteomics.volcano_top_n",A="proteomics.volcano_x_max",M="proteomics.volcano_y_max";function I(e){const t=t=>{const n=parseFloat(e.getTag(t)??"");return Number.isFinite(n)&&n>0?n:null};return{xMax:t(A),yMax:t(M)}}function O(e,t,n){const r=(t,n)=>e.setTag(t,null!=n&&Number.isFinite(n)&&n>0?String(n):"");r(A,t),r(M,n)}function F(e,t){const{xMax:n,yMax:r}=I(t);if(null!=n)e.props.xMin=-n,e.props.xMax=n;else{const n=t.col("log2FC");if(null!=n&&Number.isFinite(n.min)&&Number.isFinite(n.max)){const t=Math.max(.05*(n.max-n.min),1e-6);e.props.xMin=n.min-t,e.props.xMax=n.max+t}}if(null!=r)e.props.yMin=0,e.props.yMax=r;else{const n=t.col(p);null!=n&&Number.isFinite(n.max)&&(e.props.yMin=0,e.props.yMax=1.05*n.max+1e-6)}}function $(e){const t=parseInt(e.getTag(L)??"",10);return Number.isFinite(t)&&t>=0?t:15}function R(e,t,n=15,o){e.setTag(L,String(n));const i=function(e){return(0,a.k)(e,s.iu.DISPLAY_NAME,["display name"])??(0,a.k)(e,s.iu.GENE_SYMBOL,["gene name","gene symbol"])}(e);if(!i)return;const l=e.col(D)??e.columns.addNewString(D),c=new Set(function(e,t){if(t<=0)return[];const n=e.col(p),o=e.col("log2FC");if(!n||!o)return[];const i=n.getRawData(),a=o.getRawData(),s=[];for(let t=0;t<e.rowCount;t++)e.filter.get(t)&&i[t]!==r.FLOAT_NULL&&a[t]!==r.FLOAT_NULL&&s.push(t);return s.sort((e,t)=>{const n=i[t]-i[e];return 0!==n?n:Math.abs(a[t])-Math.abs(a[e])}),s.slice(0,t)}(e,n));if(o)for(const e of o)c.add(e);l.init(e=>c.has(e)?String(i.get(e)??""):""),t.props.labelColumnNames=[D],t.props.showLabelsFor="All"}function k(e,t){const n=t?.fcThreshold??s.M5,r=t?.pThreshold??s.Dx;!function(){for(const e of g)e.unsubscribe();g=[]}();const a=e.getTag(h)??"adj.p-value";e.setTag(h,a);const l=v(e,a),u=b(e,n,r,a),f=e.plot.scatter({x:"log2FC",y:l,color:u});x(e,l,n,r),f.props.showViewerFormulaLines=!0,function(){const e="proteomics-volcano-styles";if(document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`.${y} .d4-column-selector.d4-vertical,.${y} .d4-column-selector.d4-bottom-center{display:none !important;}`,document.head.appendChild(t)}(),f.root.classList.add(y);const p=t?.title??function(e){const t=(0,c.f)(e);return t?`Volcano Plot: ${t.group1.name} vs ${t.group2.name}`:"Volcano Plot"}(e);return f.setOptions({title:p}),function(e,t){const n=e.root;n.style.position=n.style.position||"relative";const r=o.divText("Log2 Fold Change");r.dataset.volcanoAxisX="true",Object.assign(r.style,{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",fontSize:"0.85em",pointerEvents:"none",background:"rgba(255,255,255,0.7)",padding:"0 4px",zIndex:"4"}),n.appendChild(r);const a=t.getTag(h),s=o.divText(N(a));s.dataset.volcanoAxisY="true",Object.assign(s.style,{position:"absolute",left:"4px",top:"50%",transform:"translateY(-50%) rotate(-90deg)",transformOrigin:"left center",fontSize:"0.85em",pointerEvents:"none",background:"rgba(255,255,255,0.7)",padding:"0 4px",zIndex:"4"}),n.appendChild(s),g.push(e.onPropertyValueChanged.pipe((0,i.debounceTime)(50)).subscribe(()=>S(e,t)))}(f,e),function(e,t){const n=e.root;n.style.position=n.style.position||"relative";const r=o.divV([]);r.dataset.volcanoCounter="true",Object.assign(r.style,{position:"absolute",bottom:"8px",right:"8px",padding:"8px 16px",background:"rgba(255,255,255,0.85)",borderRadius:"4px",fontSize:"0.9em",pointerEvents:"none",zIndex:"5"}),n.appendChild(r);const a=()=>{const n=t.filter.trueCount,i=e.props.colorColumnName,a=i?t.col(i):null,s=new Map;let l=!1;if(a&&(i===d||i===m)){l=!0;for(const e of a.categories)s.set(e,0);for(let e=0;e<t.rowCount;e++){if(!t.filter.get(e))continue;if(a.isNone(e))continue;const n=a.get(e);s.set(n,(s.get(n)??0)+1)}}r.replaceChildren();const c=o.divText("Visible Proteins");if(c.style.fontWeight="bold",r.appendChild(c),r.appendChild(o.divText(`Total: ${n.toLocaleString()}`)),l)for(const[e,t]of s)r.appendChild(o.divText(`${e}: ${t.toLocaleString()}`))};a(),g.push(t.onFilterChanged.pipe((0,i.debounceTime)(50)).subscribe(a),t.onSelectionChanged.pipe((0,i.debounceTime)(50)).subscribe(a),e.onPropertyValueChanged.pipe((0,i.debounceTime)(50)).subscribe(a))}(f,e),F(f,e),R(e,f,t?.topNLabels??15),f}async function U(e,t,n,r,o=s.M5,i=s.Dx,f){e.setTag(h,n);const p=v(e,n),d=b(e,o,i,n);x(e,p,o,i),t.props.xColumnName="log2FC",t.props.yColumnName=p,t.props.colorColumnName="location"===r?await async function(e,t){const n=(0,a.k)(e,s.iu.PROTEIN_ID,["primary protein id","protein id","protein ids","accession","uniprot"])??e.col("Primary Protein ID")??e.col("Protein ID"),r=e.rowCount,o=new Array(r).fill(null),i=new Set;if(n)for(let e=0;e<r;e++){const t=n.get(e),r=t?(0,l.S6)(t):null;o[e]=r,r&&i.add(r)}const f=function(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(16).padStart(8,"0")}([...i].sort().join("|")),p=e.col(m);if(p&&p.getTag(_)===f)return t?.(1,1,"init-column"),m;const d=await(0,u.n0)([...i],(0,c.Di)(e),t),h=new Array(r);for(let e=0;e<r;e++){const t=o[e];h[e]=t&&d.get(t)||"Unknown"}const g=p??e.columns.addNewString(m);return g.init(e=>h[e]),g.meta.colors.setCategorical(u.Jn),g.semType=s.iu.SUBCELLULAR_LOCATION,g.setTag(_,f),t?.(1,1,"init-column"),m}(e,f):d,S(t,e),F(t,e)}},82(e){"use strict";e.exports=DG},328(e){"use strict";e.exports=grok},858(e){"use strict";e.exports=rxjs},713(e){"use strict";e.exports=rxjs.operators},389(e){"use strict";e.exports=ui}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r=n(110);proteomics=r})();
147
2
  //# sourceMappingURL=package.js.map