@sjcrh/proteinpaint-client 2.77.0 → 2.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/dist/{2dmaf-acb8cfdd.js → 2dmaf-7dddba15.js} +1 -1
  2. package/dist/{AppHeader-315dbd3a.js → AppHeader-67cea623.js} +1 -1
  3. package/dist/{ColorScale-4b4ea8a2.js → ColorScale-7a36cc17.js} +1 -1
  4. package/dist/{DEanalysis-28ddd620.js → DEanalysis-417e1f88.js} +1 -1
  5. package/dist/{Disco-3c427131.js → Disco-30abd4cb.js} +1 -1
  6. package/dist/{Disco.UI-b071cf7a.js → Disco.UI-ea58ee03.js} +1 -1
  7. package/dist/{DragControls-7961799c.js → DragControls-a5072cfd.js} +1 -1
  8. package/dist/{DziViewer-aa5b5706.js → DziViewer-af3c5a76.js} +1 -1
  9. package/dist/FilterRxComp-cb149666.js +1 -0
  10. package/dist/FilterStateless-bdd1416d.js +1 -0
  11. package/dist/{HicApp-674a148d.js → HicApp-fe8682af.js} +1 -1
  12. package/dist/{OrbitControls-58ca2292.js → OrbitControls-0d20d46b.js} +1 -1
  13. package/dist/{WSIViewer-afe97e2e.js → WSIViewer-64e55fb8.js} +1 -1
  14. package/dist/{adSandbox-791d704e.js → adSandbox-5753745b.js} +1 -1
  15. package/dist/app-488d9fd6.js +1 -0
  16. package/dist/{app-bd9f016b.js → app-5aa892cb.js} +1 -1
  17. package/dist/app-d9433820.js +1 -0
  18. package/dist/app.js +1 -1
  19. package/dist/bam-4e0df8b6.js +1 -0
  20. package/dist/{barchart-e3dcfc5f.js → barchart-687ae584.js} +1 -1
  21. package/dist/{barchart.events-cecb7bf5.js → barchart.events-9e2c1acf.js} +1 -1
  22. package/dist/{bars.renderer-58e38632.js → bars.renderer-95f7250f.js} +1 -1
  23. package/dist/{block-944afb9f.js → block-2f22e7fd.js} +1 -1
  24. package/dist/block.lazyload-143ae987.js +1 -0
  25. package/dist/{block.legend-3dbc41a8.js → block.legend-aa831169.js} +1 -1
  26. package/dist/{block.mds-b3967ce5.js → block.mds-64d95cf9.js} +1 -1
  27. package/dist/{block.mds.cnv-6de3115e.js → block.mds.cnv-2520897d.js} +1 -1
  28. package/dist/{block.mds.expressionrank-553613e8.js → block.mds.expressionrank-582ed7bc.js} +1 -1
  29. package/dist/{block.mds.expressionstat-2c396bb9.js → block.mds.expressionstat-483c9bc9.js} +1 -1
  30. package/dist/{block.mds.geneboxplot-552fe571.js → block.mds.geneboxplot-c1276cba.js} +1 -1
  31. package/dist/{block.mds.junction-1e25c13d.js → block.mds.junction-4a132819.js} +1 -1
  32. package/dist/{block.mds.svcnv-462d762d.js → block.mds.svcnv-a532eca7.js} +1 -1
  33. package/dist/{block.mds.svcnv.share-766e4b22.js → block.mds.svcnv.share-6575b7cf.js} +1 -1
  34. package/dist/{block.mds2-6e04432d.js → block.mds2-9ce41a23.js} +1 -1
  35. package/dist/{block.svg-40b47da8.js → block.svg-adb13c76.js} +1 -1
  36. package/dist/{block.tk.aicheck-cc42cbaf.js → block.tk.aicheck-ef6b634b.js} +1 -1
  37. package/dist/{block.tk.ase-da848c5f.js → block.tk.ase-1b119031.js} +1 -1
  38. package/dist/{block.tk.bam-8053c97e.js → block.tk.bam-2aa824aa.js} +1 -1
  39. package/dist/{block.tk.bedgraphdot-79cb0faf.js → block.tk.bedgraphdot-983fe4b3.js} +1 -1
  40. package/dist/{block.tk.bigwig.ui-a8decec7.js → block.tk.bigwig.ui-fb6401ee.js} +1 -1
  41. package/dist/{block.tk.hicstraw-3d1e9d41.js → block.tk.hicstraw-c6732591.js} +1 -1
  42. package/dist/{block.tk.junction-81eae755.js → block.tk.junction-429b654c.js} +1 -1
  43. package/dist/{block.tk.junction.textmatrixui-4c45b69a.js → block.tk.junction.textmatrixui-15bd752c.js} +1 -1
  44. package/dist/{block.tk.ld-997fca31.js → block.tk.ld-fba14536.js} +1 -1
  45. package/dist/{block.tk.menu-d3e7ccbb.js → block.tk.menu-1299ae5e.js} +1 -1
  46. package/dist/{block.tk.pgv-ae1d1f59.js → block.tk.pgv-c946527f.js} +1 -1
  47. package/dist/{boxplot-fed0a86b.js → boxplot-dbf30a19.js} +1 -1
  48. package/dist/{brainImaging-b455fd0c.js → brainImaging-b2865ba3.js} +1 -1
  49. package/dist/{brush-06989a5e.js → brush-1a123226.js} +1 -1
  50. package/dist/{categorical-82722704.js → categorical-f67752ed.js} +1 -1
  51. package/dist/{condition-f68cc8d1.js → condition-dcc70001.js} +1 -1
  52. package/dist/{controls-1d99916a.js → controls-f4648f7f.js} +1 -1
  53. package/dist/controls.btns-26bb6ef1.js +1 -0
  54. package/dist/{controls.config-00ce9f0b.js → controls.config-9870bdea.js} +1 -1
  55. package/dist/{cuminc-879690b0.js → cuminc-2273cdd3.js} +1 -1
  56. package/dist/{customdata.inputui-c563c695.js → customdata.inputui-fb1b24dc.js} +1 -1
  57. package/dist/{dataDownload-087ac205.js → dataDownload-b94871d0.js} +1 -1
  58. package/dist/{databrowser.ui-9f98f6b3.js → databrowser.ui-8ace51c3.js} +1 -1
  59. package/dist/{density-e0aff1d0.js → density-e023c28f.js} +1 -1
  60. package/dist/{dictionary-fe0ea1d6.js → dictionary-321e19f9.js} +1 -1
  61. package/dist/{drag-e11d6644.js → drag-1b98e43e.js} +1 -1
  62. package/dist/{e2pca-b3250d5c.js → e2pca-00e78fdc.js} +1 -1
  63. package/dist/{ep-9ca01df0.js → ep-b0d6177c.js} +1 -1
  64. package/dist/{facet-397afad5.js → facet-26292a3d.js} +1 -1
  65. package/dist/{filter-b3d3964e.js → filter-67d51c09.js} +1 -1
  66. package/dist/{fusion.parse-e5312047.js → fusion.parse-7e3a6071.js} +1 -1
  67. package/dist/{geneExpClustering-4383ff2c.js → geneExpClustering-a2cf1bb9.js} +1 -1
  68. package/dist/{geneExpression-52678025.js → geneExpression-d1d5a7ca.js} +1 -1
  69. package/dist/{geneExpression-cfb86b5d.js → geneExpression-dc10af2c.js} +1 -1
  70. package/dist/{geneExpression-2422f66b.js → geneExpression-e4a5a2cd.js} +1 -1
  71. package/dist/{geneORA-81220ec0.js → geneORA-248baba7.js} +1 -1
  72. package/dist/{geneVariant-18f9591a.js → geneVariant-447d6af9.js} +1 -1
  73. package/dist/{geneVariant-4d22b146.js → geneVariant-7366f3d1.js} +1 -1
  74. package/dist/{genefusion.ui-e38778dd.js → genefusion.ui-e219424a.js} +1 -1
  75. package/dist/{genesearch-0587c713.js → genesearch-d8780180.js} +1 -1
  76. package/dist/{geneset-604d0529.js → geneset-1f67d4c9.js} +1 -1
  77. package/dist/genomeBrowser-52c639b4.js +1 -0
  78. package/dist/{genomeBrowser.controls-204f007e.js → genomeBrowser.controls-3a7a1c94.js} +1 -1
  79. package/dist/{groupsetting-53dfd5e5.js → groupsetting-697a1503.js} +1 -1
  80. package/dist/{gsea-a1b04406.js → gsea-d3286c53.js} +1 -1
  81. package/dist/hierCluster-00268175.js +1 -0
  82. package/dist/{html.legend-6807e9ad.js → html.legend-0abd27ff.js} +1 -1
  83. package/dist/{imagePlot-f96cdc61.js → imagePlot-f6398b6e.js} +1 -1
  84. package/dist/{lasso-845446b8.js → lasso-48317f42.js} +1 -1
  85. package/dist/launch.adhoc-98dc0421.js +1 -0
  86. package/dist/{leftlabel.sample-3a6037c2.js → leftlabel.sample-591bc38d.js} +1 -1
  87. package/dist/legacyDataset-354f1a29.js +1 -0
  88. package/dist/{log-0ea548ec.js → log-1001ca83.js} +1 -1
  89. package/dist/{lollipop-75e11e9a.js → lollipop-40c4c5cb.js} +1 -1
  90. package/dist/{maf-e4af10d7.js → maf-10526648.js} +1 -1
  91. package/dist/{maftimeline-cc2e866c.js → maftimeline-a77349ad.js} +1 -1
  92. package/dist/matrix-1190d4b3.js +1 -0
  93. package/dist/matrix-bc0ccf83.js +1 -0
  94. package/dist/{mavb-b2dd74f6.js → mavb-0d28dd97.js} +1 -1
  95. package/dist/{mds.fimo-f19840cd.js → mds.fimo-929b9e65.js} +1 -1
  96. package/dist/{mds.samplescatterplot-254f1de6.js → mds.samplescatterplot-5a4ee6b6.js} +1 -1
  97. package/dist/{mds.survivalplot-f440db10.js → mds.survivalplot-b04947ee.js} +1 -1
  98. package/dist/metaboliteIntensity-f407ad0c.js +1 -0
  99. package/dist/niceNumLabels-621ef5c3.js +1 -0
  100. package/dist/{nodrag-f6c0801c.js → nodrag-b2866dd8.js} +1 -1
  101. package/dist/{notify-da3afe99.js → notify-91f0bc5d.js} +1 -1
  102. package/dist/{numeric-1d0318e8.js → numeric-eb1d29b3.js} +1 -1
  103. package/dist/{numeric.binary-88bf9e0d.js → numeric.binary-da92d665.js} +1 -1
  104. package/dist/numeric.continuous-92d1dea8.js +1 -0
  105. package/dist/numeric.discrete-cd8f09b1.js +1 -0
  106. package/dist/{numeric.spline-b3968b77.js → numeric.spline-9a9987b6.js} +1 -1
  107. package/dist/{numeric.toggle-ab8b79be.js → numeric.toggle-8f68f077.js} +1 -1
  108. package/dist/{oncomatrix-5f4326a8.js → oncomatrix-c29e6de9.js} +1 -1
  109. package/dist/{parseData-62083461.js → parseData-3bf0ef9f.js} +1 -1
  110. package/dist/{plot.2dvaf-eccd8ef3.js → plot.2dvaf-9e59c7d1.js} +1 -1
  111. package/dist/plot.app-fc3608a9.js +1 -0
  112. package/dist/plot.barplot-122296f7.js +1 -0
  113. package/dist/{plot.boxplot-0c538ebe.js → plot.boxplot-99c5aac5.js} +1 -1
  114. package/dist/{plot.brainImaging-ee3a0272.js → plot.brainImaging-a7bb79d6.js} +1 -1
  115. package/dist/{plot.disco-c9249cbd.js → plot.disco-ccdf741c.js} +1 -1
  116. package/dist/{plot.dzi-dfd72ddf.js → plot.dzi-aafdf56b.js} +1 -1
  117. package/dist/plot.ssgq-146075f5.js +1 -0
  118. package/dist/{plot.vaf2cov-4081decd.js → plot.vaf2cov-41e13dd9.js} +1 -1
  119. package/dist/{plot.wsi-f6325d95.js → plot.wsi-2327ad63.js} +1 -1
  120. package/dist/{profileBarchart-f4da0483.js → profileBarchart-46616916.js} +1 -1
  121. package/dist/profileHome-121aaddb.js +1 -0
  122. package/dist/profilePlot-a2591a28.js +1 -0
  123. package/dist/{profilePolar-996784ad.js → profilePolar-006a56b1.js} +1 -1
  124. package/dist/{profileRadar-79299186.js → profileRadar-3320d932.js} +1 -1
  125. package/dist/{profileRadarFacility-00e31213.js → profileRadarFacility-7a9cea80.js} +1 -1
  126. package/dist/{profileSummary-df75e6ff.js → profileSummary-7a747b4e.js} +1 -1
  127. package/dist/recover-edcdde38.js +1 -0
  128. package/dist/{regression.inputs-e647b716.js → regression.inputs-d5d44e49.js} +1 -1
  129. package/dist/{regression.inputs.values.table-b283619d.js → regression.inputs.values.table-daf7bcda.js} +1 -1
  130. package/dist/regression.results-31a8884d.js +1 -0
  131. package/dist/{renderPvalueTable-0ed37e90.js → renderPvalueTable-05c29ccf.js} +1 -1
  132. package/dist/sampleScatter-f6c04130.js +1 -0
  133. package/dist/{sampleScatter.rendererThree-aa51e3c8.js → sampleScatter.rendererThree-448689c6.js} +2 -2
  134. package/dist/{sampleView-e4819da2.js → sampleView-0931e571.js} +1 -1
  135. package/dist/{samplelst-9d9ff205.js → samplelst-27115b0e.js} +1 -1
  136. package/dist/{samplematrix-3556e5c0.js → samplematrix-2bb2480b.js} +1 -1
  137. package/dist/{scatter-ff17f653.js → scatter-a8d7c2a0.js} +1 -1
  138. package/dist/select2Terms-480025f5.js +1 -0
  139. package/dist/{selectGenomeWithTklst-84f4ff79.js → selectGenomeWithTklst-71344af2.js} +1 -1
  140. package/dist/{singleCellCellType-a2ce9bfa.js → singleCellCellType-b4061c59.js} +1 -1
  141. package/dist/{singleCellGeneExpression-a2b45c7a.js → singleCellGeneExpression-547149f2.js} +1 -1
  142. package/dist/singleCellPlot-2f5ad46a.js +1 -0
  143. package/dist/{singlecell-a5b8a39b.js → singlecell-1c3bee25.js} +1 -1
  144. package/dist/{singlecell-63cb06d8.js → singlecell-281a74a6.js} +1 -1
  145. package/dist/snp-32b8cbd8.js +1 -0
  146. package/dist/{snp-6e312b4c.js → snp-6bbefa83.js} +1 -1
  147. package/dist/snplocus-84450f3d.js +1 -0
  148. package/dist/{spliceevent.a53ss.diagram-aa2df5d7.js → spliceevent.a53ss.diagram-c04f46f1.js} +1 -1
  149. package/dist/{spliceevent.exonskip.diagram-0b792984.js → spliceevent.exonskip.diagram-a514c12e.js} +1 -1
  150. package/dist/spliceevent.exonskip.getdefault-a9a45dfc.js +1 -0
  151. package/dist/{spliceevent.noeventdiagram-e6e29a6e.js → spliceevent.noeventdiagram-b1be922c.js} +1 -1
  152. package/dist/{spliceevent.phrase-5f65a5f4.js → spliceevent.phrase-57659f7c.js} +1 -1
  153. package/dist/{stattable-775a5af5.js → stattable-7fa50fd2.js} +1 -1
  154. package/dist/{style.gdc-519a42d8.js → style.gdc-6b6a2e0c.js} +1 -1
  155. package/dist/{summary-5866c75f.js → summary-54587ccf.js} +1 -1
  156. package/dist/{sunburst-f928bfd2.js → sunburst-c24faf27.js} +1 -1
  157. package/dist/{survival-405514f6.js → survival-21e6637b.js} +1 -1
  158. package/dist/survival-538cddc2.js +1 -0
  159. package/dist/{svg.download-cd895635.js → svg.download-0dd56dfd.js} +1 -1
  160. package/dist/{svg.legend-812ea603.js → svg.legend-21629769.js} +1 -1
  161. package/dist/{svgraph-037fd7b6.js → svgraph-76e34d5e.js} +1 -1
  162. package/dist/{svmr-3bd143c3.js → svmr-89b80ea2.js} +1 -1
  163. package/dist/table-10183501.js +1 -0
  164. package/dist/{table-e013d8fc.js → table-bb97b5c9.js} +1 -1
  165. package/dist/{termInfo-e16f90f2.js → termInfo-4d954045.js} +1 -1
  166. package/dist/termdb.bins-06fd21c1.js +1 -0
  167. package/dist/termsetting-c12f1c69.js +1 -0
  168. package/dist/{tk-25ae65c4.js → tk-b96367f7.js} +1 -1
  169. package/dist/{toggleButtons-2144daab.js → toggleButtons-bb9aca2f.js} +1 -1
  170. package/dist/{tp.ui-38bc5890.js → tp.ui-f01b186b.js} +1 -1
  171. package/dist/tvs.density-064e5767.js +1 -0
  172. package/dist/{tvs.geneVariant-f99fe353.js → tvs.geneVariant-3fac6bed.js} +1 -1
  173. package/dist/{tvs.numeric-d9108473.js → tvs.numeric-86aacc82.js} +1 -1
  174. package/dist/{tvs.samplelst-3b8ee998.js → tvs.samplelst-1b00d7b6.js} +1 -1
  175. package/dist/{uiUtils-57f4b1ba.js → uiUtils-5aad7e13.js} +1 -1
  176. package/dist/{variantBrowser-56ebc7e1.js → variantBrowser-2c465d02.js} +1 -1
  177. package/dist/{vcf-e43b533a.js → vcf-55bf2c83.js} +1 -1
  178. package/dist/{violin-1352dab2.js → violin-edbe9a63.js} +1 -1
  179. package/dist/violin.interactivity-57637244.js +1 -0
  180. package/dist/{violin.renderer-4273257d.js → violin.renderer-4cab7448.js} +1 -1
  181. package/dist/{violinRenderer-7f46e468.js → violinRenderer-24abe5fd.js} +1 -1
  182. package/dist/{viridis-87a8b605.js → viridis-8a8f3e12.js} +1 -1
  183. package/dist/{y-cac91178.js → y-6fe1bb7b.js} +1 -1
  184. package/dist/{zoom-001c2f01.js → zoom-6a36fb2b.js} +1 -1
  185. package/package.json +6 -5
  186. package/dist/FilterRxComp-e8de560c.js +0 -1
  187. package/dist/FilterStateless-75514d37.js +0 -1
  188. package/dist/app-3d14cbe4.js +0 -1
  189. package/dist/app-8b5b982a.js +0 -1
  190. package/dist/bam-fa90bae8.js +0 -1
  191. package/dist/block.lazyload-4c4e81ff.js +0 -1
  192. package/dist/controls.btns-237b3154.js +0 -1
  193. package/dist/genomeBrowser-9f0e8a60.js +0 -1
  194. package/dist/hierCluster-edaaacc5.js +0 -1
  195. package/dist/hierCluster.config-a84f69a3.js +0 -1
  196. package/dist/hierCluster.interactivity-dd917fd3.js +0 -1
  197. package/dist/hierCluster.renderers-4d33e96a.js +0 -1
  198. package/dist/launch.adhoc-cb00917b.js +0 -1
  199. package/dist/legacyDataset-c9bab1e6.js +0 -1
  200. package/dist/matrix-8b3341c4.js +0 -1
  201. package/dist/matrix.cells-4dd055e7.js +0 -1
  202. package/dist/matrix.cluster-7ab94fb5.js +0 -1
  203. package/dist/matrix.config-b3b56456.js +0 -1
  204. package/dist/matrix.controls-6e0e9692.js +0 -1
  205. package/dist/matrix.data-baabaf57.js +0 -1
  206. package/dist/matrix.dom-cb1f4872.js +0 -1
  207. package/dist/matrix.groups-9990aade.js +0 -1
  208. package/dist/matrix.interactivity-3f3cf44d.js +0 -1
  209. package/dist/matrix.layout-50bc2ea5.js +0 -1
  210. package/dist/matrix.legend-024e2d50.js +0 -1
  211. package/dist/matrix.renderers-1aed44e5.js +0 -1
  212. package/dist/matrix.serieses-dc18fcc2.js +0 -1
  213. package/dist/matrix.sort-89b98e83.js +0 -1
  214. package/dist/matrix.sorterUi-0ad98ef0.js +0 -1
  215. package/dist/metaboliteIntensity-4d905d93.js +0 -1
  216. package/dist/niceNumLabels-ef07b7ad.js +0 -1
  217. package/dist/numeric.continuous-d27197cf.js +0 -1
  218. package/dist/numeric.discrete-b826f33b.js +0 -1
  219. package/dist/plot.app-4dc30ebc.js +0 -1
  220. package/dist/plot.barplot-331715f6.js +0 -1
  221. package/dist/plot.ssgq-b5f68395.js +0 -1
  222. package/dist/profileHome-11b7d146.js +0 -1
  223. package/dist/profilePlot-5dd1fe71.js +0 -1
  224. package/dist/recover-4888c2a9.js +0 -1
  225. package/dist/regression.results-f61b4a25.js +0 -1
  226. package/dist/sampleScatter-b96546e9.js +0 -1
  227. package/dist/select2Terms-eb437c2a.js +0 -1
  228. package/dist/singleCellPlot-e7e57b0f.js +0 -1
  229. package/dist/snp-41aa88d1.js +0 -1
  230. package/dist/snplocus-0653ba82.js +0 -1
  231. package/dist/spliceevent.exonskip.getdefault-af1943e3.js +0 -1
  232. package/dist/survival-10dd3d28.js +0 -1
  233. package/dist/table-be2a9975.js +0 -1
  234. package/dist/termdb.bins-a60aaa77.js +0 -1
  235. package/dist/termsetting-7467350f.js +0 -1
  236. package/dist/tvs.density-060d3006.js +0 -1
  237. package/dist/violin.interactivity-2502dcd8.js +0 -1
@@ -1 +1 @@
1
- import{_ as t}from"./tslib.es6-c3c2d88f.js";import{M as e,D as s,ak as n,at as i,as as a,ap as o,aq as r,z as l,I as c,d as h,P as d,h as p,K as u}from"./app-3d14cbe4.js";import{d as g}from"./arc-3d6751aa.js";import{p as m,c as f}from"./constant-426a1483.js";import{s as v}from"./svg.legend-812ea603.js";import{a as A,l as x}from"./line-264f8f9e.js";import{t as M}from"./math-2fb199c6.js";import{topBarInit as R}from"./controls.btns-237b3154.js";import{configUiInit as b}from"./controls.config-00ce9f0b.js";import"./termsetting-7467350f.js";import"path";var C=Math.abs;var y=Math.cos;var w=Math.sin;var I=Math.PI;var L=I/2;var D=1e-12;var T=Array.prototype.slice;function P(t){return function(){return t}}function O(t){return t.source}function N(t){return t.target}function E(t){return t.radius}function V(t){return t.startAngle}function S(t){return t.endAngle}function z(){return 0}function B(t){var e=O,s=N,n=E,i=E,a=V,o=S,r=z,l=null;function c(){var c,h=e.apply(this,arguments),d=s.apply(this,arguments),p=r.apply(this,arguments)/2,u=T.call(arguments),g=+n.apply(this,(u[0]=h,u)),f=a.apply(this,u)-L,v=o.apply(this,u)-L,A=+i.apply(this,(u[0]=d,u)),x=a.apply(this,u)-L,M=o.apply(this,u)-L;if(!l)l=c=m();if(p>D){if(C(v-f)>p*2+D)v>f?(f+=p,v-=p):(f-=p,v+=p);else f=v=(f+v)/2;if(C(M-x)>p*2+D)M>x?(x+=p,M-=p):(x-=p,M+=p);else x=M=(x+M)/2}l.moveTo(g*y(f),g*w(f));l.arc(0,0,g,f,v);if(f!==x||v!==M){if(t){var R=+t.apply(this,arguments),b=A-R,I=(x+M)/2;l.quadraticCurveTo(0,0,b*y(x),b*w(x));l.lineTo(A*y(I),A*w(I));l.lineTo(b*y(M),b*w(M))}else{l.quadraticCurveTo(0,0,A*y(x),A*w(x));l.arc(0,0,A,x,M)}}l.quadraticCurveTo(0,0,g*y(f),g*w(f));l.closePath();if(c)return l=null,c+""||null}if(t)c.headRadius=function(e){return arguments.length?(t=typeof e==="function"?e:P(+e),c):t};c.radius=function(t){return arguments.length?(n=i=typeof t==="function"?t:P(+t),c):n};c.sourceRadius=function(t){return arguments.length?(n=typeof t==="function"?t:P(+t),c):n};c.targetRadius=function(t){return arguments.length?(i=typeof t==="function"?t:P(+t),c):i};c.startAngle=function(t){return arguments.length?(a=typeof t==="function"?t:P(+t),c):a};c.endAngle=function(t){return arguments.length?(o=typeof t==="function"?t:P(+t),c):o};c.padAngle=function(t){return arguments.length?(r=typeof t==="function"?t:P(+t),c):r};c.source=function(t){return arguments.length?(e=t,c):e};c.target=function(t){return arguments.length?(s=t,c):s};c.context=function(t){return arguments.length?(l=t==null?null:t,c):l};return c}function G(){return B()}function $(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function k(t){return t}function W(){var t=k,e=$,s=null,n=f(0),i=f(M),a=f(0);function o(o){var r,l=(o=A(o)).length,c,h,d=0,p=new Array(l),u=new Array(l),g=+n.apply(this,arguments),m=Math.min(M,Math.max(-M,i.apply(this,arguments)-g)),f,v=Math.min(Math.abs(m)/l,a.apply(this,arguments)),x=v*(m<0?-1:1),R;for(r=0;r<l;++r){if((R=u[p[r]=r]=+t(o[r],r,o))>0){d+=R}}if(e!=null)p.sort((function(t,s){return e(u[t],u[s])}));else if(s!=null)p.sort((function(t,e){return s(o[t],o[e])}));for(r=0,h=d?(m-l*x)/d:0;r<l;++r,g=f){c=p[r],R=u[c],f=g+(R>0?R*h:0)+x,u[c]={data:o[c],index:r,value:R,startAngle:g,endAngle:f,padAngle:v}}return u}o.value=function(e){return arguments.length?(t=typeof e==="function"?e:f(+e),o):t};o.sortValues=function(t){return arguments.length?(e=t,s=null,o):e};o.sort=function(t){return arguments.length?(s=t,e=null,o):s};o.startAngle=function(t){return arguments.length?(n=typeof t==="function"?t:f(+t),o):n};o.endAngle=function(t){return arguments.length?(i=typeof t==="function"?t:f(+t),o):i};o.padAngle=function(t){return arguments.length?(a=typeof t==="function"?t:f(+t),o):a};return o}class F{constructor(t,e,s){this.radius=t;this.width=e;this.color=s}render(t){const e=g();const s={startAngle:0,endAngle:Math.PI*2,innerRadius:this.radius,outerRadius:this.radius+this.width,color:this.color,text:"No label"};const n=[];n.push(s);const i=t.append("g");i.selectAll("path").data(n).enter().append("path").attr("d",(t=>e(t))).attr("fill",(t=>t.color))}}class j{static create(){const t=new e({padding:5});t.d.style("border","1px solid #FFF").style("position","absolute").style("z-index",1001);return t}}var _;(function(t){t["Intrachromosomal"]="#1B9E77";t["Interchromosomal"]="#6A3D9A"})(_||(_={}));class H{static getColor(t,e){if(t!=e){return _.Interchromosomal.valueOf()}else{return _.Intrachromosomal.valueOf()}}}class U{render(t,e){let n=0;if(e.length>0){n=e[0].target.radius;const s=new F(n,2,"#6464641A");s.render(t)}const i=G().radius(n);const a=t.selectAll(".chord").data(e);const o=j.create();a.enter().append("path").attr("class","chord").attr("d",i).attr("fill",(t=>H.getColor(t.source.positionInChromosome.chromosome,t.target.positionInChromosome.chromosome))).on("mouseover",((t,e)=>{const n=s({holder:o.d});this.createTooltip(n,e);o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()}))}createTooltip(t,e){{const[e,s]=t.addRow();e.text("Data type");s.append("span").style("margin-left","5px").text("Fusion transcript")}{const s=e.source.positionInChromosome;const n=e.target.positionInChromosome;const[i,a]=t.addRow();i.text("Position");a.append("span").style("margin-left","5px").text(` ${e.source.gene?e.source.gene:""} ${s.chromosome}:${s.position} ${e.source.strand=="+"?"forward":"reverse"} > `+` ${e.target.gene?e.target.gene:""} ${n.chromosome}:${n.position} ${e.target.strand=="+"?"forward":"reverse"} `)}}}class q{constructor(t,e){this.renders=t;this.legendRenderer=e;this.fusionRenderer=new U}render(t,e){const s=t.append("div").style("display","inline-block").style("font-family","Arial");const n=s.append("svg").attr("id","sjpp_disco_plot").attr("data-testid","sjpp_disco_plot").attr("width",e.width).attr("height",e.height+e.legendHeight);const i=n.append("g").attr("class","mainG").attr("transform",`translate(${e.settings.rings.labelLinesInnerRadius+e.settings.rings.labelsToLinesDistance+100},${e.height/2})`);for(const[t,s]of this.renders){const n=e.getElements(t);const a=e.getCollisions(t);s.render(i,n,a)}this.fusionRenderer.render(i,e.fusions);this.legendRenderer.render(i,e.legend,-1*(e.settings.rings.labelLinesInnerRadius+e.settings.rings.labelsToLinesDistance+50),e.width,e.height/2)}}class X{constructor(e){this.discoApp=e;this.downloadClickListener=t=>{const e=this.discoApp.state.settings.downloadImgName||"disco.plot";const s=document.createElement("a");document.body.appendChild(s);s.addEventListener("click",(()=>{const n=new XMLSerializer;const i=new Blob([n.serializeToString(t)],{type:"image/svg+xml"});s.download=e+".svg";s.href=URL.createObjectURL(i);document.body.removeChild(s)}),false);s.click()};this.geneClickListener=(e,s)=>t(this,void 0,void 0,(function*(){const{filter:t,filter0:n}=this.discoApp.app.getState().termfilter;const i={holder:this.discoApp.app.opts.holder,genome:this.discoApp.app.opts.state.args.genome,nobox:true,query:e,tklst:[{type:"mds3",dslabel:this.discoApp.app.opts.state.dslabel,hlaachange:s.join(","),filter0:n,filterObj:t}]};const a=yield import("./app-3d14cbe4.js").then((function(t){return t.c3}));yield a.default(i)}))}}class K{constructor(t,e,s){this.chromosomes=[];this.chromosomesOrder=[];this.keysArray=[];this.totalSizeArray=[];this.chrSizesArray=[];const n=s||e;this.settings=t;this.chromosomesOrder=[];let i=0;this.totalPadAngle=Object.keys(n).length*this.settings.padAngle;this.totalChromosomesAngle=2*Math.PI-this.totalPadAngle;for(const t in n){const e=t.slice(0,3)==="chr"?t.slice(3):t;this.chromosomesOrder.push(t);this.keysArray.push(e);this.totalSizeArray.push(i);this.chrSizesArray.push(n[t]);i+=n[t]}this.totalSize=i;let a=0;for(let t=0;t<this.keysArray.length;t++){const e=this.totalChromosomesAngle*(this.chrSizesArray[t]/i);const s=t==0?this.settings.padAngle/2:a+this.settings.padAngle;const n=t==0?this.settings.padAngle/2+e:a+this.settings.padAngle+e;const o={start:this.totalSizeArray[t],size:this.chrSizesArray[t],factor:1,startAngle:s,endAngle:n,angle:(s+n)/2,innerRadius:this.settings.chromosomeInnerRadius,outerRadius:this.settings.chromosomeInnerRadius+this.settings.chromosomeWidth,color:"#AAA",text:this.keysArray[t]};this.chromosomes.push(o);if(o.endAngle!=null){a=o.endAngle}}}}class J{constructor(t,e){this.sampleName=t;this.prioritizedGenes=e}map(t){return{dt:t.dt,mname:t.mname,mClass:t.class,gene:t.gene,chr:t.chr,ref:t.ref,alt:t.alt,position:t.pos?t.pos:t.position,poschr:t.poschr,posbins:t.posbins,poslabel:t.poslabel,sampleName:this.sampleName,ssm_id:t.ssm_id,start:t.start,stop:t.stop,value:t.value,segmean:t.segmean,isPrioritized:this.prioritizedGenes.some((e=>e==t.gene)),chrA:t.chrA,chrB:t.chrB,geneA:t.geneA,geneB:t.geneB,posA:t.posA,posB:t.posB,strandA:t.strandA,strandB:t.strandB}}}class Q{map(t,e){return this.calculatePercentileForPositivesAndNegatives(t,e)}calculatePercentileForPositivesAndNegatives(t,e){const s=t.filter((t=>t>0));const n=t.filter((t=>t<0)).map((t=>-1*t));let i=NaN;let a=NaN;if(s.length>0){i=this.calculatePercentile(s,e)}if(n.length>0){a=-1*this.calculatePercentile(n,e)}return{positive:i,negative:a}}calculatePercentile(t,e){if(t.length===0){throw new Error("Array must contain at least one element.")}const s=t.sort(((t,e)=>t-e));const n=e/100*(s.length-1);const i=Math.floor(n);const a=Math.ceil(n);const o=n-i;if(i===a){return s[i]}return s[i]+o*(s[a]-s[i])}}class Y{constructor(t,e,s,l=[]){this.labelData=[];this.nonExonicSnvData=[];this.nonExonicInnerRadius=0;this.snvRingDataMap=new Map;this.snvInnerRadius=0;this.snvData=[];this.bpx=0;this.onePxArcAngle=0;this.filteredSnvData=[];this.lohData=[];this.lohInnerRadius=0;this.cnvData=[];this.cnvInnerRadius=0;this.fusionData=[];this.fusionRadius=0;this.hasPrioritizedGenes=false;this.cnvLossMaxValue=0;this.cnvGainMaxValue=0;this.percentilePositive=0;this.percentileNegative=0;this.cnvMaxPercentileAbs=0;this.lohMaxValue=undefined;this.lohMinValue=undefined;this.snvFilter=t=>t.dt==n;this.fusionFilter=t=>t.dt==i||t.dt==a;this.cnvFilter=t=>t.dt==o;this.lohFilter=t=>t.dt==r;this.compareData=(t,e)=>{const s=this.reference.chromosomesOrder.indexOf(t.chr)-this.reference.chromosomesOrder.indexOf(e.chr);if(s!=0){return s}const n=t.pos?t.pos:t.start;const i=e.pos?e.pos:e.start;return n-i};this.settings=t;this.reference=e;this.sample=s;this.lastInnerRadious=this.settings.rings.chromosomeInnerRadius;this.gainCapped=this.settings.Disco.cnvCapping;this.lossCapped=-1*this.settings.Disco.cnvCapping;this.nonExonicFilter=e=>{if(l.length>0&&this.settings.Disco.prioritizeGeneLabelsByGeneSets){return l.includes(e.gene)&&t.rings.nonExonicFilterValues.includes(yt.snvClassLayer[e.mClass])}else{return t.rings.nonExonicFilterValues.includes(yt.snvClassLayer[e.mClass])}};this.snvRingFilter=e=>{if(l.length>0&&this.settings.Disco.prioritizeGeneLabelsByGeneSets){return l.includes(e.gene)&&t.rings.snvRingFilters.includes(yt.snvClassLayer[e.mClass])}else{return t.rings.snvRingFilters.includes(yt.snvClassLayer[e.mClass])}};this.dataObjectMapper=new J(s,l)}map(t){const e=[];t.forEach((t=>{const s=this.reference.chromosomesOrder.indexOf(t.chr);const l=this.reference.chromosomesOrder.indexOf(t.chrA);const c=this.reference.chromosomesOrder.indexOf(t.chrB);if(t.dt==n){if(s!=-1&&this.snvData.length<this.settings.snv.maxMutationCount){this.addData(t,e)}}else if(t.dt==i||t.dt==a){if(l!=-1&&c!=-1){this.addData(t,e)}}else if([o,r].includes(Number(t.dt))){this.addData(t,e)}else{throw Error("Unknown mutation type!")}}));const s=e.sort(this.compareData);if(this.settings.rings.nonExonicRingEnabled){s.forEach((t=>{this.filterNonExonicSnvData(t)}))}if(this.nonExonicSnvData.length>0){this.nonExonicInnerRadius=this.lastInnerRadious-this.settings.rings.nonExonicRingWidth;this.lastInnerRadious=this.nonExonicInnerRadius}s.forEach((t=>{this.filterSnvs(t)}));s.forEach((t=>{this.filterLohs(t)}));if(this.lohData.length>0){this.lohInnerRadius=this.lastInnerRadious-this.settings.rings.lohRingWidth;this.lastInnerRadious=this.lohInnerRadius}s.forEach((t=>{this.filterCnvs(t)}));if(this.cnvData.length>0){this.cnvInnerRadius=this.lastInnerRadious-this.settings.rings.cnvRingWidth;this.lastInnerRadious=this.cnvInnerRadius;this.cappedCnvMaxAbsValue=Math.min(this.settings.Disco.cnvCapping,Math.max(Math.abs(Y.capMaxValue(this.cnvLossMaxValue,this.gainCapped,this.lossCapped)),Math.abs(Y.capMaxValue(this.cnvGainMaxValue,this.gainCapped,this.lossCapped))));const t=(new Q).map(this.cnvData.map((t=>t.value)),this.settings.Disco.cnvPercentile);this.percentilePositive=Y.capMaxValue(t.positive,this.gainCapped,this.lossCapped);this.percentileNegative=Y.capMaxValue(t.negative,this.gainCapped,this.lossCapped);this.cnvMaxPercentileAbs=Math.min(this.settings.Disco.cnvCapping,Math.max(this.percentilePositive,Math.abs(this.percentileNegative)))}s.forEach((t=>{this.filterFusion(t)}));if(this.fusionData.length>0){this.fusionRadius=this.lastInnerRadious}const l={labelData:this.labelData,nonExonicSnvData:this.nonExonicSnvData,nonExonicInnerRadius:this.nonExonicInnerRadius,snvRingDataMap:this.snvRingDataMap,snvInnerRadius:this.snvInnerRadius,snvData:this.snvData,bpx:this.bpx,onePxArcAngle:this.onePxArcAngle,filteredSnvData:this.filteredSnvData,lohData:this.lohData,lohInnerRadius:this.lohInnerRadius,cnvData:this.cnvData,cnvInnerRadius:this.cnvInnerRadius,fusionData:this.fusionData,fusionRadius:this.fusionRadius,hasPrioritizedGenes:this.hasPrioritizedGenes,cnvGainMaxValue:this.cnvGainMaxValue,cnvLossMaxValue:this.cnvLossMaxValue,cappedCnvMaxAbsValue:this.cappedCnvMaxAbsValue,percentilePositive:this.percentilePositive,percentileNegative:this.percentileNegative,cnvMaxPercentileAbs:this.cnvMaxPercentileAbs,lohMaxValue:this.lohMaxValue,lohMinValue:this.lohMinValue};return l}addData(t,e){const s=this.dataObjectMapper.map(t);if(s.isPrioritized){this.hasPrioritizedGenes=true}e.push(s)}filterNonExonicSnvData(t){if(this.snvFilter(t)){if(this.settings.rings.nonExonicRingEnabled&&this.nonExonicFilter(t)){this.nonExonicSnvData.push(t)}}}filterSnvs(t){if(this.snvFilter(t)){this.snvData.push(t);if(this.snvRingFilter(t)){if(this.snvInnerRadius==0){this.snvInnerRadius=this.lastInnerRadious-this.settings.rings.snvRingWidth;this.lastInnerRadious=this.snvInnerRadius;this.bpx=Math.floor(this.reference.totalSize/(this.reference.totalChromosomesAngle*this.snvInnerRadius));this.onePxArcAngle=1/this.snvInnerRadius}this.filteredSnvData.push(t);this.labelData.push(t);const e=this.calculateArcAngle(t);let s=this.snvRingDataMap.get(e);if(!s){s=new Array}s.push(t);this.snvRingDataMap.set(e,s)}}}filterFusion(t){if(this.fusionFilter(t)){t.isPrioritized=true;this.fusionData.push(t);this.labelData.push(t)}}filterLohs(t){if(this.lohFilter(t)){if(this.lohMaxValue==undefined||this.lohMaxValue<t.value){this.lohMaxValue=t.segmean}if(this.lohMinValue==undefined||this.lohMinValue>t.value){this.lohMinValue=t.segmean}this.lohData.push(t)}}filterCnvs(t){if(this.cnvFilter(t)){if(this.cnvGainMaxValue==undefined||this.cnvGainMaxValue<t.value){this.cnvGainMaxValue=t.value}if(this.cnvLossMaxValue==undefined||this.cnvLossMaxValue>t.value){this.cnvLossMaxValue=t.value}this.cnvData.push(t)}}calculateArcAngle(t){const e=this.reference.chromosomes[this.reference.chromosomesOrder.findIndex((e=>t.chr==e))];const s=Math.floor(t.position/this.bpx);return e.startAngle+s*this.onePxArcAngle}static capMaxValue(t,e,s){if(t&&Math.sign(t)==1){return t>e?e:t}if(Math.sign(t)==-1){return t<s?s:t}return 0}static capMinValue(t,e=1){if(Math.sign(t)==1){return t>e?t:e}if(Math.sign(t)==-1){return t<-1*e?t:-1*e}return 1}}class Z{constructor(t,e,s,n,i,a,o,r,l){this.snvTitle=t;this.cnvTitle=e;this.lohTitle=s;this.fusionTitle=n;this.snvClassMap=i;this.cnvClassMap=a;this.cnvRenderingType=o;this.lohLegend=l;this.fusionLegend=r}legendCount(){return(this.snvClassMap.size>0?1:0)+(this.cnvClassMap.size>0?1:0)+(this.lohLegend?1:0)+(this.fusionLegend?1:0)}}class tt{constructor(t,e,s,n,i){this.source=t;this.target=e;this.genes=s;this.count=n;this.endpts=i}}class et{constructor(t,e,s,n,i,a,o,r){this.startAngle=t;this.endAngle=e;this.radius=s;this.gene=n;this.value=i;this.genes=a;this.positionInChromosome=o;this.strand=r}}class st{constructor(t,e,s){this.radius=t;this.sampleName=e;this.reference=s}map(t){const e=[];t.forEach((t=>{const s=new Set;s.add(t.geneA);s.add(t.geneB);const n=new et(this.calculateStartAngle(t.chrA,t.posA),this.calculateEndAngle(t.chrA,t.posA),this.radius,t.geneA,t.value,s,{chromosome:t.chrA,position:t.posA},t.strandA);const i=new et(this.calculateStartAngle(t.chrB,t.posB),this.calculateEndAngle(t.chrB,t.posB),this.radius,t.geneB,t.value,s,{chromosome:t.chrB,position:t.posB},t.strandB);const a=new tt(n,i,"genes",-1,"Endpoints");e.push(a)}));return e}calculateStartAngle(t,e){const s=this.reference.chromosomesOrder.indexOf(t);const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)-.01}calculateEndAngle(t,e){const s=this.reference.chromosomesOrder.indexOf(t);const n=this.reference.chromosomes[s];return.01+n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}}class nt{static provide(t){const e=Math.min(Math.max(t,0),1);const s=Math.round(e*255);return`rgb(${s}, ${s}, ${s})`}}class it{constructor(t,e){this.minValue=t;this.maxValue=e;this.colorStartValue=nt.provide(t);this.colorEndValue=nt.provide(e)}}var at;(function(t){t[t["CHROMOSOME"]=0]="CHROMOSOME";t[t["LABEL"]=1]="LABEL";t[t["NONEXONICSNV"]=2]="NONEXONICSNV";t[t["SNV"]=3]="SNV";t[t["CNV"]=4]="CNV";t[t["LOH"]=5]="LOH";t[t["FUSION"]=6]="FUSION"})(at||(at={}));class ot{constructor(t,e,s,n,i,a,o){this.settings=t;this.rings=e;this.legend=s;this.fusions=n;this.genesetName=a;this.width=1.2*(this.settings.horizontalPadding+this.settings.rings.labelLinesInnerRadius+this.settings.rings.labelsToLinesDistance);this.height=2*(this.settings.rings.labelLinesInnerRadius+this.settings.rings.labelsToLinesDistance+this.settings.verticalPadding);this.legendHeight=this.calculateLegendHeight(s);this.snvDataLength=i.snvData.length;this.filteredSnvDataLength=i.filteredSnvData.length;this.snvDataLengthAll=o;this.cnvMaxValue=i.cnvGainMaxValue;this.cnvMinValue=i.cnvLossMaxValue;this.cappedCnvMaxAbsValue=i.cappedCnvMaxAbsValue;this.negativePercentile80=i.percentileNegative;this.positivePercentile80=i.percentilePositive}getElements(t){switch(t){case at.CHROMOSOME:return this.rings.chromosomesRing?this.rings.chromosomesRing.elements:[];case at.LABEL:return this.rings.labelsRing.elementsToDisplay;case at.NONEXONICSNV:return this.rings.nonExonicArcRing?this.rings.nonExonicArcRing.elements:[];case at.SNV:return this.rings.snvArcRing?this.rings.snvArcRing.elements:[];case at.CNV:return this.rings.cnvArcRing?this.rings.cnvArcRing.elements:[];case at.LOH:return this.rings.lohArcRing?this.rings.lohArcRing.elements:[];default:throw new Error(`ringType ${t} not defined`)}}getCollisions(t){if(t==at.LABEL){return this.rings.labelsRing.collisions}else{return undefined}}calculateLegendHeight(t){const e=this.settings.legend.rowHeight;return e*t.legendCount()}}class rt{constructor(t,e,s){this.innerRadius=t;this.outerRadius=t+e;this.width=e;this.elements=s}}class lt{constructor(){const t={};for(const e in l){t[l[e].label]=l[e];t[e]=l[e]}this.mlabel=t}static getInstance(){if(!lt.instance){lt.instance=new lt}return lt.instance}}class ct{constructor(t,e,s){this.snvType=t;this.color=e;this.count=s}}class ht{constructor(t,e,s,n){this.snvClassMap=new Map;this.svnInnerRadius=t;this.svnWidth=e;this.sampleName=s;this.reference=n;this.bpx=Math.floor(this.reference.totalSize/(this.reference.totalChromosomesAngle*t));this.onePxArcAngle=1/t}map(t){const e=[];for(const s of t.keys()){const n=t.get(s);if(n){const t=n.length;for(let i=0;i<n.length;i++){const a=n[i];const o=this.snvClassMap.get(a.mClass);if(o){this.snvClassMap.set(a.mClass,this.createSnvLegend(a.mClass,++o.count))}else{this.snvClassMap.set(a.mClass,this.createSnvLegend(a.mClass,1))}const r=s;const l=s+this.onePxArcAngle;const c=lt.getInstance().mlabel?lt.getInstance().mlabel[a.mClass]:undefined;const h={startAngle:r,endAngle:l,innerRadius:this.svnInnerRadius+i*this.svnWidth/t,outerRadius:this.svnInnerRadius+(i+1)*this.svnWidth/t,color:c.color,text:a.gene,dataClass:c.label,mname:a.mname,chr:a.chr,pos:a.position,sampleName:[a.sampleName]};e.push(h)}}}return e}createSnvLegend(t,e){const s=lt.getInstance().mlabel[t];return new ct(s.label,s.color,e)}}class dt{constructor(t,e,s,n){this.text=t;this.cnvType=e;this.color=s;this.value=n}}var pt;(function(t){t[t["Loss"]=0]="Loss";t[t["Gain"]=1]="Gain";t[t["Cap"]=2]="Cap"})(pt||(pt={}));var ut;(function(t){t["heatmap"]="heatmap";t["bar"]="bar"})(ut||(ut={}));class gt{static getColor(t,e,s=0){const n=e.cnv;const i=e.Disco.cnvRenderingType==ut.heatmap?e.Disco.cnvCapping:s;const a=e.Disco.cnvRenderingType==ut.heatmap?-1*e.Disco.cnvCapping:-1*s;if(t<a){return n.cappedLossColor}else if(t>=a&&t<=0){return n.lossColor}else if(t>0&&t<=i){return n.ampColor}else{return n.cappedAmpColor}}}class mt{constructor(t,e,s,n,i,a=0,o=0,r=0,l=0,c="",h){this.cnvClassMap=new Map;this.cnvInnerRadius=t;this.cnvWidth=e;this.settings=s;this.sampleName=n;this.reference=i;this.cnvMaxValue=a;this.cnvMinValue=o;this.cnvMaxAbsValue=r;this.cnvAbsPercentile=l;this.cnvUnit=c;this.cnvRenderingType=h;this.gainCapped=Math.min(l,this.settings.Disco.cnvCapping);this.lossCapped=-1*Math.min(l,this.settings.Disco.cnvCapping);this.lossOnly=a<=0;this.gainOnly=o>=0;this.onePxArcAngle=1/this.cnvInnerRadius;const d=new dt("Max",a>0?pt.Gain:pt.Loss,this.getColor(a),a);const p=new dt("Min",o>0?pt.Gain:pt.Loss,this.getColor(o),o);const u=new dt("Capping",pt.Loss,this.getColor(o>0?o:a),this.settings.Disco.cnvCapping);this.cnvClassMap.set(pt.Gain,d);this.cnvClassMap.set(pt.Loss,p);this.cnvClassMap.set(pt.Cap,u)}map(t){const e=[];t.forEach((t=>{let s=this.calculateStartAngle(t);let n=this.calculateEndAngle(t);if(n-s<this.onePxArcAngle){const t=this.onePxArcAngle-(n-s);s=s-t/2;n=s+t/2}const i=this.calculateInnerRadius(t);const a=this.calculateOuterRadius(t);const o=this.getColor(t.value);const r={startAngle:s,endAngle:n,innerRadius:i,outerRadius:a,color:o,text:t.gene,chr:t.chr,start:t.start,stop:t.stop,value:t.value,unit:this.cnvUnit,sampleName:[this.sampleName]};e.push(r)}));return e}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.start)/s.size)}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.stop)/s.size)}getColor(t){return gt.getColor(t,this.settings,this.cnvAbsPercentile)}calculateInnerRadius(t){if(this.cnvRenderingType==ut.heatmap){return this.cnvInnerRadius}if(this.gainOnly){return this.cnvInnerRadius}if(this.lossOnly){const e=this.cnvInnerRadius+this.cnvWidth;return e+Y.capMinValue(this.cnvWidth*Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile)}const e=this.cnvInnerRadius+this.cnvWidth/2;if(Math.sign(t.value)==1){return e}if(Math.sign(t.value)==-1){return e+Y.capMinValue(Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile*(this.cnvWidth/2))}return 1}calculateOuterRadius(t){const e=this.cnvInnerRadius+this.cnvWidth;if(this.cnvRenderingType==ut.heatmap){return e}if(this.gainOnly){return this.cnvInnerRadius+Y.capMinValue(this.cnvWidth*Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile)}if(this.lossOnly){return e}const s=this.cnvInnerRadius+this.cnvWidth/2;if(Math.sign(t.value)==1){return s+Y.capMinValue(Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvMaxAbsValue*(this.cnvWidth/2))}if(Math.sign(t.value)==-1){return s}return 1}}class ft{constructor(t,e){this.points=new Array;this.points=t;this.color=e}}class vt{static createLabel(t,e,s,n,i,a,o,r,l,c,h=false,d,p,u){const g=(t+e)/2;const m=g-Math.PI/2;const f=`rotate(${g*180/Math.PI-90}) translate(${n})${g>Math.PI?"rotate(180)":""}`;const v=g>Math.PI?"end":"";const A=s;const x=n-d;const M=[];const R={x:A*Math.cos(m),y:A*Math.sin(m)};const b={x:x*Math.cos(m),y:x*Math.sin(m)};M.push(R);M.push(b);const C=new ft(M,o);const y={startAngle:t,endAngle:e,innerRadius:s,outerRadius:n,angle:g,value:i,text:a,color:o,transform:f,textAnchor:v,ccAngle:m,line:C,isPrioritized:h,start:c,stop:c,chr:l,mutationsTooltip:p?[p]:undefined,fusionTooltip:u?[u]:undefined};return y}static createMovedLabel(t,e){const s=t.startAngle+e;const n=t.endAngle+e;const i=(s+n)/2;const a=i-Math.PI/2;const o=t.innerRadius;const r=t.outerRadius-2;const l=(r-o)/3;const c=Math.cos(t.ccAngle);const h=Math.sin(t.ccAngle);const d=Math.cos(t.ccAngle+e);const p=Math.sin(t.ccAngle+e);const u=[];const g={x:o*c,y:o*h};const m={x:(o+l)*c,y:(o+l)*h};const f={x:(o+2*l)*d,y:(o+2*l)*p};const v={x:(o+3*l)*d,y:(o+3*l)*p};u.push(g);u.push(m);u.push(f);u.push(v);const A=new ft(u,t.color);const x="rotate("+(i*180/Math.PI-90)+")"+"translate("+t.outerRadius+")"+(i>Math.PI?"rotate(180)":"");const M=i>Math.PI?"end":"";const R=t.mutationsTooltip?t.mutationsTooltip[0].color:t.fusionTooltip?t.fusionTooltip[0].color:undefined;const b={startAngle:s,endAngle:n,innerRadius:t.innerRadius,outerRadius:t.outerRadius,angle:i,value:t.value,text:t.text,transform:x,textAnchor:M,ccAngle:a,color:R,line:A,isPrioritized:t.isPrioritized,start:t.start,stop:t.stop,chr:t.chr,mutationsTooltip:t.mutationsTooltip,fusionTooltip:t.fusionTooltip};return b}}class At{constructor(t,e,s,n=0){this.labelMap=new Map;this.settings=t;this.sampleName=e;this.reference=s;this.cnvMaxPercentileAbs=n}map(t,e=[]){const s=this.settings.rings.labelLinesInnerRadius;const a=s+this.settings.rings.labelsToLinesDistance;t.forEach((t=>{if(t.dt==n){const e=this.calculateStartAngle(t.chr,t.position);const n=this.calculateEndAngle(t.chr,t.position);const i=lt.getInstance().mlabel?lt.getInstance().mlabel[t.mClass]:undefined;this.addLabelOrMutation(t,t.gene,t.mname,e,n,s,a,i.color,i.label)}if(t.dt==i){const e=H.getColor(t.chrA,t.chrB);if(t.geneA){const n=this.calculateStartAngle(t.chrA,t.posA);const i=this.calculateEndAngle(t.chrA,t.posA);this.addLabelOrFusion(t,t.geneA,t.posA,n,i,s,a,e)}if(t.geneB&&t.geneA!=t.geneB){const n=this.calculateStartAngle(t.chrB,t.posB);const i=this.calculateEndAngle(t.chrB,t.posB);this.addLabelOrFusion(t,t.geneB,t.posB,n,i,s,a,e)}}}));const o=Array.from(this.labelMap.values());o.forEach((t=>{e.forEach((e=>{if(t.stop>=e.start&&e.stop>=t.start&&t.chr==e.chr){const s={value:e.value,color:gt.getColor(e.value,this.settings,this.cnvMaxPercentileAbs),chr:e.chr,start:e.start,stop:e.stop};if(t.cnvTooltip){t.cnvTooltip.push(s)}else{t.cnvTooltip=[];t.cnvTooltip.push(s)}}}))}));return Array.from(this.labelMap.values())}addLabelOrMutation(t,e,s,n,i,a,o,r,l){const c=this.labelMap.get(e);const h={mname:s,color:r,dataClass:l,chr:t.chr,position:t.position};if(!c){this.labelMap.set(e,vt.createLabel(n,i,a,o,t.value,e,r,l,t.chr,t.position,t.isPrioritized,this.settings.rings.labelsToLinesGap,h))}else{if(c.mutationsTooltip){c.start=Math.min(c.start,t.position);c.stop=Math.max(c.stop,t.position);c.mutationsTooltip.push(h)}else{c.mutationsTooltip=[];c.start=Math.min(c.start,t.position);c.stop=Math.max(c.stop,t.position);c.mutationsTooltip.push(h)}}}addLabelOrFusion(t,e,s,n,i,a,o,r){const l=this.labelMap.get(e);const c={color:r,chrA:t.chrA,chrB:t.chrB,posA:t.posA,posB:t.posB,geneA:t.geneA,geneB:t.geneB,strandA:t.strandA,strandB:t.strandB};if(!l){this.labelMap.set(e,vt.createLabel(n,i,a,o,t.value,e,r,"Fusion transcript",t.chr,t.position,t.isPrioritized,this.settings.rings.labelsToLinesGap,undefined,c))}else{if(l.fusionTooltip){l.start=Math.min(l.start,s);l.stop=Math.max(l.stop,s);l.fusionTooltip.push(c)}else{l.fusionTooltip=[];l.start=Math.min(l.start,s);l.stop=Math.max(l.stop,s);l.fusionTooltip.push(c)}}}calculateStartAngle(t,e){const s=this.reference.chromosomesOrder.findIndex((e=>e==t));const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}calculateEndAngle(t,e){const s=this.reference.chromosomesOrder.findIndex((e=>e==t));const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}}class xt extends rt{constructor(t,e,s){super(t.rings.labelLinesInnerRadius,t.rings.labelsToLinesDistance,e.sort(((t,e)=>t.startAngle<e.startAngle?-1:t.startAngle>e.startAngle?1:0)));this.elementsToDisplay=[];this.settings=t;this.hasPrioritizedGenes=s;const n=2*Math.PI*(t.rings.labelLinesInnerRadius+t.rings.labelsToLinesDistance);this.overlapAngle=this.settings.label.overlapAngleFactor*this.settings.label.fontSize/n;this.calculateCollisions()}calculateCollisions(){this.collisions=[];let t=[];t=this.elements.filter((t=>t.isPrioritized));if(this.settings.label.prioritizeGeneLabelsByGeneSets){this.elementsToDisplay=this.getLabelsWithPrioritizedGenes(t)}else if(this.hasPrioritizedGenes){const t=this.elements.filter((t=>t.isPrioritized));const e=this.getLabelsWithPrioritizedGenes(t);const s=this.elements.filter((t=>!t.isPrioritized));const n=[...s,...e].sort(((t,e)=>t.startAngle-e.startAngle));this.elementsToDisplay=this.getAllLabels(n)}else{this.elementsToDisplay=this.getLabelsWithPrioritizedGenes(this.elements)}}getLabelsWithPrioritizedGenes(t){const e=[];let s={endAngle:0};t.forEach(((t,n)=>{if(n==0){e.push(t);s=t}else{const n=s.endAngle-t.startAngle+this.overlapAngle;if(n>0&&n<this.settings.label.maxDeltaAngle){const i=vt.createMovedLabel(t,n);e===null||e===void 0?void 0:e.push(i);s=i}if(n<=0){e.push(t);s=t}}}));return e}getAllLabels(t){var e;const s=[];let n={endAngle:0};const i=t.length;let a=-1;for(let o=0;o<t.length;o++){const r=t[o];if(r.isPrioritized){s.push(r);a=o;n=r;continue}if(o==0){if(i>1){if(this.isElementOverlappingNextCancerGene(t,a,r,0)){continue}s.push(r);n=r}continue}const l=n.endAngle-r.startAngle+this.overlapAngle;if(l>0&&l<this.settings.label.maxDeltaAngle){if(o==length-1){s.push(r);continue}if(this.isElementOverlappingNextCancerGene(t,a,r,l)){continue}const i=vt.createMovedLabel(r,l);(e=this.collisions)===null||e===void 0?void 0:e.push(i);s.push(r);n=i}if(l<=0){if(this.isElementOverlappingNextCancerGene(t,a,r,0)){continue}s.push(r);n=r}}return s}isElementOverlappingNextCancerGene(t,e,s,n){const i=this.getNextLabelWithCancerGene(t,e);if(i){const t=s.endAngle+n-i.startAngle+this.overlapAngle;if(t>0){return true}}return false}getNextLabelWithCancerGene(t,e){return t.find(((t,s)=>t.isPrioritized&&s>e))}}class Mt{constructor(t,e,s,n){this.nonExonicInnerRadius=t;this.nonExonicWidht=e;this.sampleName=s;this.reference=n;this.onePxArcAngle=1/t}map(t){const e=this.nonExonicInnerRadius;const s=e+this.nonExonicWidht;const n=[];t.forEach((t=>{const i=lt.getInstance().mlabel?lt.getInstance().mlabel[t.mClass]:undefined;const a=this.calculateStartAngle(t);const o=this.calculateEndAngle(t);const r={startAngle:a,endAngle:o,innerRadius:e,outerRadius:s,color:i.color,text:t.gene,dataClass:i.label,mname:t.mname,chr:t.chr,pos:t.position,sampleName:[t.sampleName]};n.push(r)}));return n}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.position)/s.size)-this.onePxArcAngle}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return this.onePxArcAngle+s.startAngle+(s.endAngle-s.startAngle)*(Number(t.position)/s.size)}}class Rt{constructor(t,e,s,n){this.lohInnerRadius=t;this.lohWidth=e;this.sampleName=s;this.reference=n}map(t){const e=[];t.forEach((t=>{const s=this.calculateStartAngle(t);const n=this.calculateEndAngle(t);const i=this.lohInnerRadius;const a=i+this.lohWidth;const o=nt.provide(t.segmean);const r={startAngle:s,endAngle:n,innerRadius:i,outerRadius:a,color:o,text:t.gene,chr:t.chr,start:t.start,stop:t.stop,value:t.segmean};e.push(r)}));return e}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.start)/s.size)}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.stop)/s.size)}}class bt{constructor(t,e,s,n,i,a){this.labelsRing=t;this.chromosomesRing=e;this.nonExonicArcRing=s;this.snvArcRing=n;this.cnvArcRing=i;this.lohArcRing=a}}class Ct{constructor(t,e,s,n,i){this.nonExonicArcRing=undefined;this.settings=t;this.dataMapper=e;this.reference=s;this.sampleName=n;this.genesetName=i}map(t){const e=this.dataMapper.map(t);const s=new At(this.settings,this.sampleName,this.reference,e.cnvMaxPercentileAbs);const i=s.map(e.labelData,e.cnvData);const a=new xt(this.settings,i,e.hasPrioritizedGenes);const o=new rt(this.settings.rings.chromosomeInnerRadius,this.settings.rings.chromosomeWidth,this.reference.chromosomes);const r=new Mt(e.nonExonicInnerRadius,this.settings.rings.nonExonicRingWidth,this.sampleName,this.reference);const l=r.map(e.nonExonicSnvData);if(l.length>0){this.nonExonicArcRing=new rt(e.nonExonicInnerRadius,this.settings.rings.nonExonicRingWidth,l)}this.snvArcsMapper=new ht(e.snvInnerRadius,this.settings.rings.snvRingWidth,this.sampleName,this.reference);const c=this.snvArcsMapper.map(e.snvRingDataMap);if(c.length>0){this.snvArcRing=new rt(e.snvInnerRadius,this.settings.rings.snvRingWidth,c)}const h=new Rt(e.lohInnerRadius,this.settings.rings.lohRingWidth,this.sampleName,this.reference);const d=h.map(e.lohData);if(d.length>0){this.lohArcRing=new rt(e.lohInnerRadius,this.settings.rings.lohRingWidth,d)}this.cnvArcsMapper=new mt(e.cnvInnerRadius,this.settings.rings.cnvRingWidth,this.settings,this.sampleName,this.reference,e.percentilePositive,e.percentileNegative,e.cappedCnvMaxAbsValue,e.cnvMaxPercentileAbs,this.settings.cnv.unit,this.settings.Disco.cnvRenderingType);const p=this.cnvArcsMapper.map(e.cnvData);if(p.length>0){this.cnvArcRing=new rt(e.cnvInnerRadius,this.settings.rings.cnvRingWidth,p)}const u=new st(e.fusionRadius,this.sampleName,this.reference);const g=u.map(e.fusionData);let m;if(this.settings.legend.lohLegendEnabled&&e.lohMinValue&&e.lohMaxValue){m=new it(e.lohMinValue,e.lohMaxValue)}const f=new Z(this.settings.legend.snvTitle,this.settings.legend.cnvTitle,this.settings.legend.lohTitle,this.settings.legend.fusionTitle,this.snvArcsMapper?this.snvArcsMapper.snvClassMap:new Map,this.cnvArcsMapper?this.cnvArcsMapper.cnvClassMap:new Map,this.settings.Disco.cnvRenderingType,g.length>0,m);const v=new bt(a,o,this.nonExonicArcRing,this.snvArcRing,this.cnvArcRing,this.lohArcRing);return new ot(this.settings,v,f,g,e,this.genesetName,t.filter((t=>t.dt==n)).length)}}class yt{constructor(t){this.settings=t}map(t){var e,s;const n=t.args.chromosomes;const i=t.args.genome.majorchr;const a=t.args.sampleName;const o=t.args.genome;const r=((e=o===null||o===void 0?void 0:o.geneset)===null||e===void 0?void 0:e[0])?o.geneset[0].lst:[];const l=((s=o===null||o===void 0?void 0:o.geneset)===null||s===void 0?void 0:s[0])?o.geneset[0].name:"";const c=t.args.data;const h=new K(this.settings,i,n);const d=new Y(this.settings,h,a,r);return new Ct(this.settings,d,h,a,l).map(c)}}yt.snvClassLayer={M:"exonic",E:"exonic",F:"exonic",N:"exonic",S:"exonic",D:"exonic",I:"exonic",P:"exonic",L:"exonic",Utr3:"exonic",Utr5:"exonic",ProteinAltering:"exonic",mnv:"non-exonic",ITD:"non-exonic",insertion:"non-exonic",deletion:"non-exonic",Intron:"non-exonic",X:"non-exonic",noncoding:"non-exonic"};class wt{constructor(t){this.cappedCnvMaxAbsValue=t}map(t){const e=[];let s=0;if(t.snvClassMap){this.mapSnv(t,e,s++)}if(t.cnvRenderingType==ut.heatmap){this.mapCnvHeatmap(t,e,s++)}else if(t.cnvRenderingType==ut.bar){if(t.cnvClassMap){this.mapCnvBar(t,e,s++)}}if(t.lohLegend){this.mapLoh(t,e,s++)}if(t.fusionLegend){this.mapFusion(t,e,s++)}return e}mapSnv(t,e,s){const n=[];let i=0;for(const[e,s]of t.snvClassMap){n.push({termid:t.snvTitle,key:e,text:`${s.snvType} (${s.count})`,color:s.color,order:i++,border:"1px solid #ccc"})}e.push({name:t.snvTitle,order:s,items:n})}mapCnvBar(t,e,s){if(!t.cnvClassMap)return;const n=t.cnvClassMap.get(pt.Gain);const i=t.cnvClassMap.get(pt.Loss);const a=t.cnvClassMap.get(pt.Cap);if(n&&i&&a){let o=0;const r=[];if(n.value>0){r.push({termid:t.cnvTitle,key:pt.Gain,text:`Max: ${n.value}`,color:n.color,order:o++,border:"1px solid #ccc"})}if(i.value<0){r.push({termid:t.cnvTitle,key:pt.Loss,text:`Min: ${i.value}`,color:i.color,order:o++,border:"1px solid #ccc"})}r.push({termid:t.cnvTitle,key:pt.Cap,text:`Capping: ${a.value}`,color:a.color,order:o++,border:"1px solid #ccc"});e.push({name:t.cnvTitle,order:s,items:r})}}mapCnvHeatmap(t,e,s){if(!t.cnvClassMap)return;const n=t.cnvClassMap.get(pt.Gain);const i=t.cnvClassMap.get(pt.Loss);const a=t.cnvClassMap.get(pt.Cap);if(n&&i&&a){let o=0;const r=[];if(n.value>0){r.push({termid:t.cnvTitle,key:pt.Gain,text:"Copy number gain",width:100,domain:[0,1],minLabel:0,maxLabel:n.value,order:o++,isLegendItem:true,dt:4,scale:c([0,1],["white",n.color])})}if(i.value<0){r.push({termid:t.cnvTitle,key:pt.Loss,text:"Copy number loss",width:100,domain:[0,1],minLabel:0,maxLabel:i.value,order:o++,isLegendItem:true,dt:4,scale:c([0,1],["white",i.color])})}r.push({termid:t.cnvTitle,key:pt.Cap,text:`Capping: ${a.value}`,color:a.color,order:o++,border:"1px solid #ccc"});e.push({name:t.cnvTitle,order:s,items:r})}}mapLoh(t,e,s){if(!t.lohLegend)return;const n=[];n.push({termid:t.lohTitle,key:"min",text:"min",color:t.lohLegend.colorStartValue,order:0,border:"1px solid #ccc"});n.push({termid:t.lohTitle,key:"max",text:"max",color:t.lohLegend.colorEndValue,order:1,border:"1px solid #ccc"});e.push({name:t.lohTitle,order:s,items:n})}mapFusion(t,e,s){const n=[];n.push({termid:t.fusionTitle,key:_.Interchromosomal,text:"Interchromosomal",color:_.Interchromosomal.valueOf(),order:0,border:"1px solid #ccc"});n.push({termid:t.fusionTitle,key:_.Intrachromosomal,text:"Intrachromosomal",color:_.Intrachromosomal.valueOf(),order:1,border:"1px solid #ccc"});e.push({name:t.fusionTitle,order:s,items:n})}}class It{constructor(t=0,e){this.fontSize=e;this.legendJSONMapper=new wt(t)}render(t,e,s,n,i){const a=v({holder:t.append("g").attr("data-testid","sjpp_disco_plot_legend"),rectFillFxn:t=>t.color,iconStroke:"#aaa"});const o={xOffset:s};const r=this.legendJSONMapper.map(e);a(r,{settings:Object.assign({},{svgw:n,svgh:i,dimensions:o,fontsize:this.fontSize})})}}class Lt{constructor(t,e,s){this.padAngle=t;this.innerRadius=e;this.outerRadius=s}render(t,e){const s=W().padAngle(this.padAngle).value((t=>t.size)).sort(null);const n=s(e);const i=g().innerRadius(this.innerRadius).outerRadius(this.outerRadius);const a=t.append("g").attr("data-testid","sjpp_chromosomes_arc_group");a.selectAll("path").data(n).enter().append("path").attr("d",i).attr("fill","black");a.selectAll("text").data(n).enter().append("text").attr("transform",(t=>`translate(${i.centroid(t)}) rotate(${t.data.angle*180/Math.PI-90})${t.data.angle>Math.PI?"rotate(180)":""}`)).attr("dy","0.35em").attr("text-anchor","middle").text((t=>t.data.text)).style("fill","white")}}class Dt{constructor(t,e){this.animationDuration=t;this.geneClickListener=e}render(t,e,n){const i=t.append("g");const a=x().x((t=>t.x)).y((t=>t.y));const o=j.create();i.selectAll(".group").data(e).enter().append("g").attr("class","group").each(((t,e,n)=>{const i=h(n[e]);i.append("text").attr("class","chord-text").attr("dy",".35em").attr("transform",t.transform).style("text-anchor",t.textAnchor).style("font-size","12px").style("fill",t.color).style("cursor","pointer").text(t.text).on("click",(()=>{if(t.mutationsTooltip){this.geneClickListener(t.text,t.mutationsTooltip.map((t=>t.mname)))}})).on("mouseover",(e=>{const n=s({holder:o.d});this.createTooltip(n,t);o.show(e.x,e.y)})).on("mouseout",(()=>{o.clear();o.hide()}));i.append("path").attr("class","chord-tick").datum(t.line.points).style("stroke",t.color).style("fill","none").attr("d",a)}));i.selectAll(".group").each(((t,e,s)=>{const i=n?n.find((e=>e.text===t.text)):undefined;if(i){const t=h(s[e]);t.selectAll(".chord-text").datum(i).transition().duration(this.animationDuration).attr("transform",i.transform).style("text-anchor",i.textAnchor);t.selectAll(".chord-tick").datum(i.line.points).transition().duration(this.animationDuration).style("fill","none").attr("d",a)}}))}createTooltip(t,e){if(e.mutationsTooltip){const[s,n]=t.addRow();s.text("Gene");n.append("span").style("margin-left","5px").text(e.text);e.mutationsTooltip.forEach((e=>{{const[s,n]=t.addRow();s.text("Consequence");n.append("span").text(e.mname);n.append("span").style("margin-left","5px").style("color",e.color).text(e.dataClass)}{const[s,n]=t.addRow();s.text("Mutation");n.append("span").text(`${e.chr}:${e.position}`)}}))}if(e.fusionTooltip){const[s,n]=t.addRow();s.text("Data type");n.append("span").text("Fusion transcript");e.fusionTooltip.forEach((e=>{const[s,n]=t.addRow();s.text("Break points");n.append("span").text(` ${e.geneA?e.geneA:""} ${e.chrA}:${e.posA} \n\t\t\t\t\t\t${e.strandA=="+"?"forward":"reverse"} > `+`${e.geneB?e.geneB:""} ${e.chrB}:${e.posB} ${e.strandB=="+"?"forward":"reverse"} `)}))}if(e.cnvTooltip){e.cnvTooltip.forEach((e=>{const[s,n]=t.addRow();s.text("CNV");n.append("span").style("color",e.color).text(e.value).append("span").style("margin-left","5px").text(`${e.chr}:${e.start}-${e.stop}`)}))}}}function Tt(t={}){const e={downloadImgName:"disco.plot",Disco:{cnvCapping:5,isOpen:false,prioritizeGeneLabelsByGeneSets:false,showPrioritizeGeneLabelsByGeneSets:false,cnvRenderingType:ut.heatmap,cnvPercentile:80},rings:{nonExonicRingWidth:20,snvRingWidth:20,lohRingWidth:20,cnvRingWidth:30,snvRingFilters:["exonic"],chromosomeInnerRadius:190,chromosomeWidth:20,labelLinesInnerRadius:210,labelsToLinesDistance:30,labelsToLinesGap:2,nonExonicRingEnabled:true,nonExonicFilterValues:["non-exonic"]},verticalPadding:70,horizontalPadding:500,layerScaler:1,padAngle:.002,label:{fontSize:12,maxDeltaAngle:.05,animationDuration:1e3,overlapAngleFactor:5},cnv:{capping:5,ampColor:"#D6683C",lossColor:"#67a9cf",cappedAmpColor:"#8B0000",cappedLossColor:"#00008B",unit:"Unit"},snv:{maxMutationCount:1e4},legend:{snvTitle:"SNV",cnvTitle:"CNV",lohTitle:"LOH",fusionTitle:"SV",lohLegendEnabled:true,fontSize:12,rowHeight:48},menu:{padding:5}};return d(e,t)}class Pt{constructor(t){this.geneClickListener=t}render(t,e){const i=g();const a=t.append("g");const o=j.create();a.selectAll("path").data(e).enter().append("path").attr("d",(t=>i(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const i=s({holder:o.d});const a=structuredClone(e);a.dt=n;a.class=e.dataClass;a.gene=a.text;{const[t,e]=i.addRow();t.text("Consequence");e.append("span").text(a.mname);e.append("span").style("margin-left","5px").style("color",a.color).style("font-size",".8em").text(a.dataClass)}{const[t,e]=i.addRow();t.text(a.ref&&a.alt?"Mutation":"Position");e.append("span").text(`${a.chr}:${a.pos+1} ${a.ref&&a.alt?a.ref+">"+a.alt:""}`)}if(a.gene){const[t,e]=i.addRow();t.text("Gene");e.text(a.gene)}if(a.occurrence>1){const[t,e]=i.addRow();t.text("Occurrence");e.text(a.occurrence)}o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()})).on("click",((t,e)=>{this.geneClickListener(e.text,[e.mname])}))}}class Ot{constructor(t,e){this.svnWidth=t;this.geneClickListener=e}render(t,e){if(e.length>0){const s=e[0].innerRadius;const n=new F(s,this.svnWidth,"#6464641A");n.render(t)}const i=g();const a=t.append("g");const o=j.create();a.selectAll("path").data(e).enter().append("path").attr("d",(t=>i(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const i=s({holder:o.d});const a=structuredClone(e);a.dt=n;a.class=e.dataClass;a.gene=a.text;{const[t,e]=i.addRow();t.text("Consequence");e.append("span").text(a.mname);e.append("span").style("margin-left","5px").style("color",a.color).style("font-size",".8em").text(a.dataClass)}{const[t,e]=i.addRow();t.text(a.ref&&a.alt?"Mutation":"Position");e.append("span").text(`${a.chr}:${a.pos+1} ${a.ref&&a.alt?a.ref+">"+a.alt:""}`)}if(a.gene){const[t,e]=i.addRow();t.text("Gene");e.text(a.gene)}if(a.occurrence>1){const[t,e]=i.addRow();t.text("Occurrence");e.text(a.occurrence)}o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()})).on("click",((t,e)=>{this.geneClickListener(e.text,[e.mname])}))}}class Nt{render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const n=s({holder:a.d});const i=structuredClone(e);i.dt=r;i.gene=i.text;{const[t,e]=n.addRow();t.text("Data type");e.append("span").style("margin-left","5px").text("Loss of Heterozygosity")}const[o,l]=n.addRow();o.text("Position");l.append("span").text(`${e.chr}:${e.start}-${e.stop}`);a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class Et{render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const n=structuredClone(e);n.dt=o;n.samples=[{sample_id:e.sampleName}];n.gene=n.text;const i=s({holder:a.d});{const[t,e]=i.addRow();t.text("Copy number change");e.html(`<span style="background:${n.color}">&nbsp;&nbsp;</span> ${n.value}`)}{const[t,e]=i.addRow();t.text("Position");e.text(n.chr+":"+n.start+"-"+n.stop)}{const[t,e]=i.addRow();t.text("Unit");e.text(n.value)}a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class Vt{constructor(t=0,e=0){this.positivePercentile80=t;this.negativePercentile80=e}render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>c([this.negativePercentile80,0,this.positivePercentile80],[t.color,"white",t.color]).clamp(true)(t.value))).on("mouseover",((t,e)=>{const n=s({holder:a.d});const i=structuredClone(e);i.dt=o;i.samples=[{sample_id:e.sampleName}];i.gene=i.text;{const[t,e]=n.addRow();t.text("Copy number change");e.html(`<span style="background:${i.color}">&nbsp;&nbsp;</span> ${i.value}`)}{const[t,e]=n.addRow();t.text("Position");e.text(i.chr+":"+i.start+"-"+i.stop)}{const[t,e]=n.addRow();t.text("Unit");e.text(i.value)}a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class St{constructor(t){this.recreateViewModel=false;this.type="Disco";this.opts=t;this.isOpen=false;this.discoInteractions=new X(this)}init(){return t(this,void 0,void 0,(function*(){const t=this.app.getState();const e=t.plots.find((t=>t.id===this.id)).settings;this.stateViewModelMapper=new yt(e);this.viewModel=this.stateViewModelMapper.map(t);const s=this.opts.holder;const n=s.append("div").style("display","inline-block").style("vertical-align","top");const i=n.append("div");const a=n.append("div");const o=this.getConfigInputsOptions(this.viewModel);this.features=yield u({topbar:R({app:this.app,id:this.id,downloadHandler:()=>this.discoInteractions.downloadClickListener(s.select('svg[id="sjpp_disco_plot"]').node()),callback:()=>this.toggleVisibility(this.isOpen),isOpen:()=>this.isOpen,holder:i}),config:b({app:this.app,id:this.id,holder:a,isOpen:()=>this.isOpen,inputs:o})})}))}getConfigInputsOptions(t){const e=[];if(t.settings.Disco.showPrioritizeGeneLabelsByGeneSets){const s=[{boxLabel:t.genesetName,label:`Filter mutations`,type:"checkbox",chartType:"Disco",settingsKey:"prioritizeGeneLabelsByGeneSets",title:`Only show mutations for ${t.genesetName} genes`}];e.push(...s)}const s=[{label:"CNV capping",type:"number",chartType:"Disco",settingsKey:"cnvCapping",title:"Cnv capping",min:0},{boxLabel:"",label:"CNV rendering type",type:"radio",chartType:"Disco",settingsKey:"cnvRenderingType",title:"CNV rendering type",options:[{label:"Heatmap",value:ut.heatmap},{label:"Bar",value:ut.bar}]},{label:"CNV percentile",type:"number",chartType:"Disco",settingsKey:"cnvPercentile",title:"Cnv percentile",min:1,max:100}];e.push(...s);return e}main(){return t(this,void 0,void 0,(function*(){const t=this.state.settings;this.isOpen=t.Disco.isOpen;if(this.recreateViewModel){this.stateViewModelMapper=new yt(t);this.viewModel=this.stateViewModelMapper.map(this.app.getState())}this.recreateViewModel=true;if(this.viewModel){const e=this.opts.holder;e.select('div[id="sjpp_disco_plot_holder_div"]').remove();const s=e.append("div").attr("id","sjpp_disco_plot_holder_div").style("display","inline-block");const n=this.app.getState();for(const t in this.features){this.features[t].update({state:this.state,appState:n})}const i=new It(this.viewModel.cappedCnvMaxAbsValue,t.label.fontSize);const a=new q(this.getRingRenderers(t,this.viewModel,this.discoInteractions.geneClickListener),i);a.render(s,this.viewModel)}}))}getState(t){return t.plots.find((t=>t.id===this.id))}getRingRenderers(t,e,s){const n=new Lt(t.padAngle,t.rings.chromosomeInnerRadius,t.rings.chromosomeInnerRadius+t.rings.chromosomeWidth);const i=new Dt(t.label.animationDuration,s);const a=new Pt(s);const o=new Ot(t.rings.snvRingWidth,s);const r=t.Disco.cnvRenderingType===ut.heatmap?new Vt(e.positivePercentile80,e.negativePercentile80):new Et;const l=new Nt;const c=new Map;c.set(at.CHROMOSOME,n);c.set(at.LABEL,i);c.set(at.NONEXONICSNV,a);c.set(at.SNV,o);c.set(at.CNV,r);c.set(at.LOH,l);return c}toggleVisibility(t){this.app.dispatch({type:"plot_edit",id:this.opts.id,config:{settings:{Disco:{isOpen:!t}}}})}}const zt=p(St);const Bt=zt;function Gt(e){return t(this,void 0,void 0,(function*(){return{chartType:"Disco",subfolder:"disco",extension:"ts",settings:Tt(e.overrides)}}))}export{Bt as componentInit,zt as discoInit,Gt as getPlotConfig};
1
+ import{_ as t}from"./tslib.es6-c3c2d88f.js";import{M as e,D as s,ak as n,at as i,as as a,ap as o,aq as r,z as l,I as c,d as h,P as d,h as p,K as u}from"./app-488d9fd6.js";import{d as g}from"./arc-3d6751aa.js";import{p as m,c as f}from"./constant-426a1483.js";import{s as v}from"./svg.legend-21629769.js";import{a as A,l as x}from"./line-264f8f9e.js";import{t as M}from"./math-2fb199c6.js";import{topBarInit as R}from"./controls.btns-26bb6ef1.js";import{configUiInit as b}from"./controls.config-9870bdea.js";import"./termsetting-c12f1c69.js";import"path";var C=Math.abs;var y=Math.cos;var w=Math.sin;var I=Math.PI;var L=I/2;var D=1e-12;var T=Array.prototype.slice;function P(t){return function(){return t}}function O(t){return t.source}function N(t){return t.target}function E(t){return t.radius}function V(t){return t.startAngle}function S(t){return t.endAngle}function z(){return 0}function B(t){var e=O,s=N,n=E,i=E,a=V,o=S,r=z,l=null;function c(){var c,h=e.apply(this,arguments),d=s.apply(this,arguments),p=r.apply(this,arguments)/2,u=T.call(arguments),g=+n.apply(this,(u[0]=h,u)),f=a.apply(this,u)-L,v=o.apply(this,u)-L,A=+i.apply(this,(u[0]=d,u)),x=a.apply(this,u)-L,M=o.apply(this,u)-L;if(!l)l=c=m();if(p>D){if(C(v-f)>p*2+D)v>f?(f+=p,v-=p):(f-=p,v+=p);else f=v=(f+v)/2;if(C(M-x)>p*2+D)M>x?(x+=p,M-=p):(x-=p,M+=p);else x=M=(x+M)/2}l.moveTo(g*y(f),g*w(f));l.arc(0,0,g,f,v);if(f!==x||v!==M){if(t){var R=+t.apply(this,arguments),b=A-R,I=(x+M)/2;l.quadraticCurveTo(0,0,b*y(x),b*w(x));l.lineTo(A*y(I),A*w(I));l.lineTo(b*y(M),b*w(M))}else{l.quadraticCurveTo(0,0,A*y(x),A*w(x));l.arc(0,0,A,x,M)}}l.quadraticCurveTo(0,0,g*y(f),g*w(f));l.closePath();if(c)return l=null,c+""||null}if(t)c.headRadius=function(e){return arguments.length?(t=typeof e==="function"?e:P(+e),c):t};c.radius=function(t){return arguments.length?(n=i=typeof t==="function"?t:P(+t),c):n};c.sourceRadius=function(t){return arguments.length?(n=typeof t==="function"?t:P(+t),c):n};c.targetRadius=function(t){return arguments.length?(i=typeof t==="function"?t:P(+t),c):i};c.startAngle=function(t){return arguments.length?(a=typeof t==="function"?t:P(+t),c):a};c.endAngle=function(t){return arguments.length?(o=typeof t==="function"?t:P(+t),c):o};c.padAngle=function(t){return arguments.length?(r=typeof t==="function"?t:P(+t),c):r};c.source=function(t){return arguments.length?(e=t,c):e};c.target=function(t){return arguments.length?(s=t,c):s};c.context=function(t){return arguments.length?(l=t==null?null:t,c):l};return c}function G(){return B()}function $(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function k(t){return t}function W(){var t=k,e=$,s=null,n=f(0),i=f(M),a=f(0);function o(o){var r,l=(o=A(o)).length,c,h,d=0,p=new Array(l),u=new Array(l),g=+n.apply(this,arguments),m=Math.min(M,Math.max(-M,i.apply(this,arguments)-g)),f,v=Math.min(Math.abs(m)/l,a.apply(this,arguments)),x=v*(m<0?-1:1),R;for(r=0;r<l;++r){if((R=u[p[r]=r]=+t(o[r],r,o))>0){d+=R}}if(e!=null)p.sort((function(t,s){return e(u[t],u[s])}));else if(s!=null)p.sort((function(t,e){return s(o[t],o[e])}));for(r=0,h=d?(m-l*x)/d:0;r<l;++r,g=f){c=p[r],R=u[c],f=g+(R>0?R*h:0)+x,u[c]={data:o[c],index:r,value:R,startAngle:g,endAngle:f,padAngle:v}}return u}o.value=function(e){return arguments.length?(t=typeof e==="function"?e:f(+e),o):t};o.sortValues=function(t){return arguments.length?(e=t,s=null,o):e};o.sort=function(t){return arguments.length?(s=t,e=null,o):s};o.startAngle=function(t){return arguments.length?(n=typeof t==="function"?t:f(+t),o):n};o.endAngle=function(t){return arguments.length?(i=typeof t==="function"?t:f(+t),o):i};o.padAngle=function(t){return arguments.length?(a=typeof t==="function"?t:f(+t),o):a};return o}class F{constructor(t,e,s){this.radius=t;this.width=e;this.color=s}render(t){const e=g();const s={startAngle:0,endAngle:Math.PI*2,innerRadius:this.radius,outerRadius:this.radius+this.width,color:this.color,text:"No label"};const n=[];n.push(s);const i=t.append("g");i.selectAll("path").data(n).enter().append("path").attr("d",(t=>e(t))).attr("fill",(t=>t.color))}}class j{static create(){const t=new e({padding:5});t.d.style("border","1px solid #FFF").style("position","absolute").style("z-index",1001);return t}}var _;(function(t){t["Intrachromosomal"]="#1B9E77";t["Interchromosomal"]="#6A3D9A"})(_||(_={}));class H{static getColor(t,e){if(t!=e){return _.Interchromosomal.valueOf()}else{return _.Intrachromosomal.valueOf()}}}class U{render(t,e){let n=0;if(e.length>0){n=e[0].target.radius;const s=new F(n,2,"#6464641A");s.render(t)}const i=G().radius(n);const a=t.selectAll(".chord").data(e);const o=j.create();a.enter().append("path").attr("class","chord").attr("d",i).attr("fill",(t=>H.getColor(t.source.positionInChromosome.chromosome,t.target.positionInChromosome.chromosome))).on("mouseover",((t,e)=>{const n=s({holder:o.d});this.createTooltip(n,e);o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()}))}createTooltip(t,e){{const[e,s]=t.addRow();e.text("Data type");s.append("span").style("margin-left","5px").text("Fusion transcript")}{const s=e.source.positionInChromosome;const n=e.target.positionInChromosome;const[i,a]=t.addRow();i.text("Position");a.append("span").style("margin-left","5px").text(` ${e.source.gene?e.source.gene:""} ${s.chromosome}:${s.position} ${e.source.strand=="+"?"forward":"reverse"} > `+` ${e.target.gene?e.target.gene:""} ${n.chromosome}:${n.position} ${e.target.strand=="+"?"forward":"reverse"} `)}}}class q{constructor(t,e){this.renders=t;this.legendRenderer=e;this.fusionRenderer=new U}render(t,e){const s=t.append("div").style("display","inline-block").style("font-family","Arial");const n=s.append("svg").attr("id","sjpp_disco_plot").attr("data-testid","sjpp_disco_plot").attr("width",e.width).attr("height",e.height+e.legendHeight);const i=n.append("g").attr("class","mainG").attr("transform",`translate(${e.settings.rings.labelLinesInnerRadius+e.settings.rings.labelsToLinesDistance+100},${e.height/2})`);for(const[t,s]of this.renders){const n=e.getElements(t);const a=e.getCollisions(t);s.render(i,n,a)}this.fusionRenderer.render(i,e.fusions);this.legendRenderer.render(i,e.legend,-1*(e.settings.rings.labelLinesInnerRadius+e.settings.rings.labelsToLinesDistance+50),e.width,e.height/2)}}class X{constructor(e){this.discoApp=e;this.downloadClickListener=t=>{const e=this.discoApp.state.settings.downloadImgName||"disco.plot";const s=document.createElement("a");document.body.appendChild(s);s.addEventListener("click",(()=>{const n=new XMLSerializer;const i=new Blob([n.serializeToString(t)],{type:"image/svg+xml"});s.download=e+".svg";s.href=URL.createObjectURL(i);document.body.removeChild(s)}),false);s.click()};this.geneClickListener=(e,s)=>t(this,void 0,void 0,(function*(){const{filter:t,filter0:n}=this.discoApp.app.getState().termfilter;const i={holder:this.discoApp.app.opts.holder,genome:this.discoApp.app.opts.state.args.genome,nobox:true,query:e,tklst:[{type:"mds3",dslabel:this.discoApp.app.opts.state.dslabel,hlaachange:s.join(","),filter0:n,filterObj:t}]};const a=yield import("./app-488d9fd6.js").then((function(t){return t.c3}));yield a.default(i)}))}}class K{constructor(t,e,s){this.chromosomes=[];this.chromosomesOrder=[];this.keysArray=[];this.totalSizeArray=[];this.chrSizesArray=[];const n=s||e;this.settings=t;this.chromosomesOrder=[];let i=0;this.totalPadAngle=Object.keys(n).length*this.settings.padAngle;this.totalChromosomesAngle=2*Math.PI-this.totalPadAngle;for(const t in n){const e=t.slice(0,3)==="chr"?t.slice(3):t;this.chromosomesOrder.push(t);this.keysArray.push(e);this.totalSizeArray.push(i);this.chrSizesArray.push(n[t]);i+=n[t]}this.totalSize=i;let a=0;for(let t=0;t<this.keysArray.length;t++){const e=this.totalChromosomesAngle*(this.chrSizesArray[t]/i);const s=t==0?this.settings.padAngle/2:a+this.settings.padAngle;const n=t==0?this.settings.padAngle/2+e:a+this.settings.padAngle+e;const o={start:this.totalSizeArray[t],size:this.chrSizesArray[t],factor:1,startAngle:s,endAngle:n,angle:(s+n)/2,innerRadius:this.settings.chromosomeInnerRadius,outerRadius:this.settings.chromosomeInnerRadius+this.settings.chromosomeWidth,color:"#AAA",text:this.keysArray[t]};this.chromosomes.push(o);if(o.endAngle!=null){a=o.endAngle}}}}class J{constructor(t,e){this.sampleName=t;this.prioritizedGenes=e}map(t){return{dt:t.dt,mname:t.mname,mClass:t.class,gene:t.gene,chr:t.chr,ref:t.ref,alt:t.alt,position:t.pos?t.pos:t.position,poschr:t.poschr,posbins:t.posbins,poslabel:t.poslabel,sampleName:this.sampleName,ssm_id:t.ssm_id,start:t.start,stop:t.stop,value:t.value,segmean:t.segmean,isPrioritized:this.prioritizedGenes.some((e=>e==t.gene)),chrA:t.chrA,chrB:t.chrB,geneA:t.geneA,geneB:t.geneB,posA:t.posA,posB:t.posB,strandA:t.strandA,strandB:t.strandB}}}class Q{map(t,e){return this.calculatePercentileForPositivesAndNegatives(t,e)}calculatePercentileForPositivesAndNegatives(t,e){const s=t.filter((t=>t>0));const n=t.filter((t=>t<0)).map((t=>-1*t));let i=NaN;let a=NaN;if(s.length>0){i=this.calculatePercentile(s,e)}if(n.length>0){a=-1*this.calculatePercentile(n,e)}return{positive:i,negative:a}}calculatePercentile(t,e){if(t.length===0){throw new Error("Array must contain at least one element.")}const s=t.sort(((t,e)=>t-e));const n=e/100*(s.length-1);const i=Math.floor(n);const a=Math.ceil(n);const o=n-i;if(i===a){return s[i]}return s[i]+o*(s[a]-s[i])}}class Y{constructor(t,e,s,l=[]){this.labelData=[];this.nonExonicSnvData=[];this.nonExonicInnerRadius=0;this.snvRingDataMap=new Map;this.snvInnerRadius=0;this.snvData=[];this.bpx=0;this.onePxArcAngle=0;this.filteredSnvData=[];this.lohData=[];this.lohInnerRadius=0;this.cnvData=[];this.cnvInnerRadius=0;this.fusionData=[];this.fusionRadius=0;this.hasPrioritizedGenes=false;this.cnvLossMaxValue=0;this.cnvGainMaxValue=0;this.percentilePositive=0;this.percentileNegative=0;this.cnvMaxPercentileAbs=0;this.lohMaxValue=undefined;this.lohMinValue=undefined;this.snvFilter=t=>t.dt==n;this.fusionFilter=t=>t.dt==i||t.dt==a;this.cnvFilter=t=>t.dt==o;this.lohFilter=t=>t.dt==r;this.compareData=(t,e)=>{const s=this.reference.chromosomesOrder.indexOf(t.chr)-this.reference.chromosomesOrder.indexOf(e.chr);if(s!=0){return s}const n=t.pos?t.pos:t.start;const i=e.pos?e.pos:e.start;return n-i};this.settings=t;this.reference=e;this.sample=s;this.lastInnerRadious=this.settings.rings.chromosomeInnerRadius;this.gainCapped=this.settings.Disco.cnvCapping;this.lossCapped=-1*this.settings.Disco.cnvCapping;this.nonExonicFilter=e=>{if(l.length>0&&this.settings.Disco.prioritizeGeneLabelsByGeneSets){return l.includes(e.gene)&&t.rings.nonExonicFilterValues.includes(yt.snvClassLayer[e.mClass])}else{return t.rings.nonExonicFilterValues.includes(yt.snvClassLayer[e.mClass])}};this.snvRingFilter=e=>{if(l.length>0&&this.settings.Disco.prioritizeGeneLabelsByGeneSets){return l.includes(e.gene)&&t.rings.snvRingFilters.includes(yt.snvClassLayer[e.mClass])}else{return t.rings.snvRingFilters.includes(yt.snvClassLayer[e.mClass])}};this.dataObjectMapper=new J(s,l)}map(t){const e=[];t.forEach((t=>{const s=this.reference.chromosomesOrder.indexOf(t.chr);const l=this.reference.chromosomesOrder.indexOf(t.chrA);const c=this.reference.chromosomesOrder.indexOf(t.chrB);if(t.dt==n){if(s!=-1&&this.snvData.length<this.settings.snv.maxMutationCount){this.addData(t,e)}}else if(t.dt==i||t.dt==a){if(l!=-1&&c!=-1){this.addData(t,e)}}else if([o,r].includes(Number(t.dt))){this.addData(t,e)}else{throw Error("Unknown mutation type!")}}));const s=e.sort(this.compareData);if(this.settings.rings.nonExonicRingEnabled){s.forEach((t=>{this.filterNonExonicSnvData(t)}))}if(this.nonExonicSnvData.length>0){this.nonExonicInnerRadius=this.lastInnerRadious-this.settings.rings.nonExonicRingWidth;this.lastInnerRadious=this.nonExonicInnerRadius}s.forEach((t=>{this.filterSnvs(t)}));s.forEach((t=>{this.filterLohs(t)}));if(this.lohData.length>0){this.lohInnerRadius=this.lastInnerRadious-this.settings.rings.lohRingWidth;this.lastInnerRadious=this.lohInnerRadius}s.forEach((t=>{this.filterCnvs(t)}));if(this.cnvData.length>0){this.cnvInnerRadius=this.lastInnerRadious-this.settings.rings.cnvRingWidth;this.lastInnerRadious=this.cnvInnerRadius;this.cappedCnvMaxAbsValue=Math.min(this.settings.Disco.cnvCapping,Math.max(Math.abs(Y.capMaxValue(this.cnvLossMaxValue,this.gainCapped,this.lossCapped)),Math.abs(Y.capMaxValue(this.cnvGainMaxValue,this.gainCapped,this.lossCapped))));const t=(new Q).map(this.cnvData.map((t=>t.value)),this.settings.Disco.cnvPercentile);this.percentilePositive=Y.capMaxValue(t.positive,this.gainCapped,this.lossCapped);this.percentileNegative=Y.capMaxValue(t.negative,this.gainCapped,this.lossCapped);this.cnvMaxPercentileAbs=Math.min(this.settings.Disco.cnvCapping,Math.max(this.percentilePositive,Math.abs(this.percentileNegative)))}s.forEach((t=>{this.filterFusion(t)}));if(this.fusionData.length>0){this.fusionRadius=this.lastInnerRadious}const l={labelData:this.labelData,nonExonicSnvData:this.nonExonicSnvData,nonExonicInnerRadius:this.nonExonicInnerRadius,snvRingDataMap:this.snvRingDataMap,snvInnerRadius:this.snvInnerRadius,snvData:this.snvData,bpx:this.bpx,onePxArcAngle:this.onePxArcAngle,filteredSnvData:this.filteredSnvData,lohData:this.lohData,lohInnerRadius:this.lohInnerRadius,cnvData:this.cnvData,cnvInnerRadius:this.cnvInnerRadius,fusionData:this.fusionData,fusionRadius:this.fusionRadius,hasPrioritizedGenes:this.hasPrioritizedGenes,cnvGainMaxValue:this.cnvGainMaxValue,cnvLossMaxValue:this.cnvLossMaxValue,cappedCnvMaxAbsValue:this.cappedCnvMaxAbsValue,percentilePositive:this.percentilePositive,percentileNegative:this.percentileNegative,cnvMaxPercentileAbs:this.cnvMaxPercentileAbs,lohMaxValue:this.lohMaxValue,lohMinValue:this.lohMinValue};return l}addData(t,e){const s=this.dataObjectMapper.map(t);if(s.isPrioritized){this.hasPrioritizedGenes=true}e.push(s)}filterNonExonicSnvData(t){if(this.snvFilter(t)){if(this.settings.rings.nonExonicRingEnabled&&this.nonExonicFilter(t)){this.nonExonicSnvData.push(t)}}}filterSnvs(t){if(this.snvFilter(t)){this.snvData.push(t);if(this.snvRingFilter(t)){if(this.snvInnerRadius==0){this.snvInnerRadius=this.lastInnerRadious-this.settings.rings.snvRingWidth;this.lastInnerRadious=this.snvInnerRadius;this.bpx=Math.floor(this.reference.totalSize/(this.reference.totalChromosomesAngle*this.snvInnerRadius));this.onePxArcAngle=1/this.snvInnerRadius}this.filteredSnvData.push(t);this.labelData.push(t);const e=this.calculateArcAngle(t);let s=this.snvRingDataMap.get(e);if(!s){s=new Array}s.push(t);this.snvRingDataMap.set(e,s)}}}filterFusion(t){if(this.fusionFilter(t)){t.isPrioritized=true;this.fusionData.push(t);this.labelData.push(t)}}filterLohs(t){if(this.lohFilter(t)){if(this.lohMaxValue==undefined||this.lohMaxValue<t.value){this.lohMaxValue=t.segmean}if(this.lohMinValue==undefined||this.lohMinValue>t.value){this.lohMinValue=t.segmean}this.lohData.push(t)}}filterCnvs(t){if(this.cnvFilter(t)){if(this.cnvGainMaxValue==undefined||this.cnvGainMaxValue<t.value){this.cnvGainMaxValue=t.value}if(this.cnvLossMaxValue==undefined||this.cnvLossMaxValue>t.value){this.cnvLossMaxValue=t.value}this.cnvData.push(t)}}calculateArcAngle(t){const e=this.reference.chromosomes[this.reference.chromosomesOrder.findIndex((e=>t.chr==e))];const s=Math.floor(t.position/this.bpx);return e.startAngle+s*this.onePxArcAngle}static capMaxValue(t,e,s){if(t&&Math.sign(t)==1){return t>e?e:t}if(Math.sign(t)==-1){return t<s?s:t}return 0}static capMinValue(t,e=1){if(Math.sign(t)==1){return t>e?t:e}if(Math.sign(t)==-1){return t<-1*e?t:-1*e}return 1}}class Z{constructor(t,e,s,n,i,a,o,r,l){this.snvTitle=t;this.cnvTitle=e;this.lohTitle=s;this.fusionTitle=n;this.snvClassMap=i;this.cnvClassMap=a;this.cnvRenderingType=o;this.lohLegend=l;this.fusionLegend=r}legendCount(){return(this.snvClassMap.size>0?1:0)+(this.cnvClassMap.size>0?1:0)+(this.lohLegend?1:0)+(this.fusionLegend?1:0)}}class tt{constructor(t,e,s,n,i){this.source=t;this.target=e;this.genes=s;this.count=n;this.endpts=i}}class et{constructor(t,e,s,n,i,a,o,r){this.startAngle=t;this.endAngle=e;this.radius=s;this.gene=n;this.value=i;this.genes=a;this.positionInChromosome=o;this.strand=r}}class st{constructor(t,e,s){this.radius=t;this.sampleName=e;this.reference=s}map(t){const e=[];t.forEach((t=>{const s=new Set;s.add(t.geneA);s.add(t.geneB);const n=new et(this.calculateStartAngle(t.chrA,t.posA),this.calculateEndAngle(t.chrA,t.posA),this.radius,t.geneA,t.value,s,{chromosome:t.chrA,position:t.posA},t.strandA);const i=new et(this.calculateStartAngle(t.chrB,t.posB),this.calculateEndAngle(t.chrB,t.posB),this.radius,t.geneB,t.value,s,{chromosome:t.chrB,position:t.posB},t.strandB);const a=new tt(n,i,"genes",-1,"Endpoints");e.push(a)}));return e}calculateStartAngle(t,e){const s=this.reference.chromosomesOrder.indexOf(t);const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)-.01}calculateEndAngle(t,e){const s=this.reference.chromosomesOrder.indexOf(t);const n=this.reference.chromosomes[s];return.01+n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}}class nt{static provide(t){const e=Math.min(Math.max(t,0),1);const s=Math.round(e*255);return`rgb(${s}, ${s}, ${s})`}}class it{constructor(t,e){this.minValue=t;this.maxValue=e;this.colorStartValue=nt.provide(t);this.colorEndValue=nt.provide(e)}}var at;(function(t){t[t["CHROMOSOME"]=0]="CHROMOSOME";t[t["LABEL"]=1]="LABEL";t[t["NONEXONICSNV"]=2]="NONEXONICSNV";t[t["SNV"]=3]="SNV";t[t["CNV"]=4]="CNV";t[t["LOH"]=5]="LOH";t[t["FUSION"]=6]="FUSION"})(at||(at={}));class ot{constructor(t,e,s,n,i,a,o){this.settings=t;this.rings=e;this.legend=s;this.fusions=n;this.genesetName=a;this.width=1.2*(this.settings.horizontalPadding+this.settings.rings.labelLinesInnerRadius+this.settings.rings.labelsToLinesDistance);this.height=2*(this.settings.rings.labelLinesInnerRadius+this.settings.rings.labelsToLinesDistance+this.settings.verticalPadding);this.legendHeight=this.calculateLegendHeight(s);this.snvDataLength=i.snvData.length;this.filteredSnvDataLength=i.filteredSnvData.length;this.snvDataLengthAll=o;this.cnvMaxValue=i.cnvGainMaxValue;this.cnvMinValue=i.cnvLossMaxValue;this.cappedCnvMaxAbsValue=i.cappedCnvMaxAbsValue;this.negativePercentile80=i.percentileNegative;this.positivePercentile80=i.percentilePositive}getElements(t){switch(t){case at.CHROMOSOME:return this.rings.chromosomesRing?this.rings.chromosomesRing.elements:[];case at.LABEL:return this.rings.labelsRing.elementsToDisplay;case at.NONEXONICSNV:return this.rings.nonExonicArcRing?this.rings.nonExonicArcRing.elements:[];case at.SNV:return this.rings.snvArcRing?this.rings.snvArcRing.elements:[];case at.CNV:return this.rings.cnvArcRing?this.rings.cnvArcRing.elements:[];case at.LOH:return this.rings.lohArcRing?this.rings.lohArcRing.elements:[];default:throw new Error(`ringType ${t} not defined`)}}getCollisions(t){if(t==at.LABEL){return this.rings.labelsRing.collisions}else{return undefined}}calculateLegendHeight(t){const e=this.settings.legend.rowHeight;return e*t.legendCount()}}class rt{constructor(t,e,s){this.innerRadius=t;this.outerRadius=t+e;this.width=e;this.elements=s}}class lt{constructor(){const t={};for(const e in l){t[l[e].label]=l[e];t[e]=l[e]}this.mlabel=t}static getInstance(){if(!lt.instance){lt.instance=new lt}return lt.instance}}class ct{constructor(t,e,s){this.snvType=t;this.color=e;this.count=s}}class ht{constructor(t,e,s,n){this.snvClassMap=new Map;this.svnInnerRadius=t;this.svnWidth=e;this.sampleName=s;this.reference=n;this.bpx=Math.floor(this.reference.totalSize/(this.reference.totalChromosomesAngle*t));this.onePxArcAngle=1/t}map(t){const e=[];for(const s of t.keys()){const n=t.get(s);if(n){const t=n.length;for(let i=0;i<n.length;i++){const a=n[i];const o=this.snvClassMap.get(a.mClass);if(o){this.snvClassMap.set(a.mClass,this.createSnvLegend(a.mClass,++o.count))}else{this.snvClassMap.set(a.mClass,this.createSnvLegend(a.mClass,1))}const r=s;const l=s+this.onePxArcAngle;const c=lt.getInstance().mlabel?lt.getInstance().mlabel[a.mClass]:undefined;const h={startAngle:r,endAngle:l,innerRadius:this.svnInnerRadius+i*this.svnWidth/t,outerRadius:this.svnInnerRadius+(i+1)*this.svnWidth/t,color:c.color,text:a.gene,dataClass:c.label,mname:a.mname,chr:a.chr,pos:a.position,sampleName:[a.sampleName]};e.push(h)}}}return e}createSnvLegend(t,e){const s=lt.getInstance().mlabel[t];return new ct(s.label,s.color,e)}}class dt{constructor(t,e,s,n){this.text=t;this.cnvType=e;this.color=s;this.value=n}}var pt;(function(t){t[t["Loss"]=0]="Loss";t[t["Gain"]=1]="Gain";t[t["Cap"]=2]="Cap"})(pt||(pt={}));var ut;(function(t){t["heatmap"]="heatmap";t["bar"]="bar"})(ut||(ut={}));class gt{static getColor(t,e,s=0){const n=e.cnv;const i=e.Disco.cnvRenderingType==ut.heatmap?e.Disco.cnvCapping:s;const a=e.Disco.cnvRenderingType==ut.heatmap?-1*e.Disco.cnvCapping:-1*s;if(t<a){return n.cappedLossColor}else if(t>=a&&t<=0){return n.lossColor}else if(t>0&&t<=i){return n.ampColor}else{return n.cappedAmpColor}}}class mt{constructor(t,e,s,n,i,a=0,o=0,r=0,l=0,c="",h){this.cnvClassMap=new Map;this.cnvInnerRadius=t;this.cnvWidth=e;this.settings=s;this.sampleName=n;this.reference=i;this.cnvMaxValue=a;this.cnvMinValue=o;this.cnvMaxAbsValue=r;this.cnvAbsPercentile=l;this.cnvUnit=c;this.cnvRenderingType=h;this.gainCapped=Math.min(l,this.settings.Disco.cnvCapping);this.lossCapped=-1*Math.min(l,this.settings.Disco.cnvCapping);this.lossOnly=a<=0;this.gainOnly=o>=0;this.onePxArcAngle=1/this.cnvInnerRadius;const d=new dt("Max",a>0?pt.Gain:pt.Loss,this.getColor(a),a);const p=new dt("Min",o>0?pt.Gain:pt.Loss,this.getColor(o),o);const u=new dt("Capping",pt.Loss,this.getColor(o>0?o:a),this.settings.Disco.cnvCapping);this.cnvClassMap.set(pt.Gain,d);this.cnvClassMap.set(pt.Loss,p);this.cnvClassMap.set(pt.Cap,u)}map(t){const e=[];t.forEach((t=>{let s=this.calculateStartAngle(t);let n=this.calculateEndAngle(t);if(n-s<this.onePxArcAngle){const t=this.onePxArcAngle-(n-s);s=s-t/2;n=s+t/2}const i=this.calculateInnerRadius(t);const a=this.calculateOuterRadius(t);const o=this.getColor(t.value);const r={startAngle:s,endAngle:n,innerRadius:i,outerRadius:a,color:o,text:t.gene,chr:t.chr,start:t.start,stop:t.stop,value:t.value,unit:this.cnvUnit,sampleName:[this.sampleName]};e.push(r)}));return e}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.start)/s.size)}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.stop)/s.size)}getColor(t){return gt.getColor(t,this.settings,this.cnvAbsPercentile)}calculateInnerRadius(t){if(this.cnvRenderingType==ut.heatmap){return this.cnvInnerRadius}if(this.gainOnly){return this.cnvInnerRadius}if(this.lossOnly){const e=this.cnvInnerRadius+this.cnvWidth;return e+Y.capMinValue(this.cnvWidth*Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile)}const e=this.cnvInnerRadius+this.cnvWidth/2;if(Math.sign(t.value)==1){return e}if(Math.sign(t.value)==-1){return e+Y.capMinValue(Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile*(this.cnvWidth/2))}return 1}calculateOuterRadius(t){const e=this.cnvInnerRadius+this.cnvWidth;if(this.cnvRenderingType==ut.heatmap){return e}if(this.gainOnly){return this.cnvInnerRadius+Y.capMinValue(this.cnvWidth*Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvAbsPercentile)}if(this.lossOnly){return e}const s=this.cnvInnerRadius+this.cnvWidth/2;if(Math.sign(t.value)==1){return s+Y.capMinValue(Y.capMaxValue(t.value,this.gainCapped,this.lossCapped)/this.cnvMaxAbsValue*(this.cnvWidth/2))}if(Math.sign(t.value)==-1){return s}return 1}}class ft{constructor(t,e){this.points=new Array;this.points=t;this.color=e}}class vt{static createLabel(t,e,s,n,i,a,o,r,l,c,h=false,d,p,u){const g=(t+e)/2;const m=g-Math.PI/2;const f=`rotate(${g*180/Math.PI-90}) translate(${n})${g>Math.PI?"rotate(180)":""}`;const v=g>Math.PI?"end":"";const A=s;const x=n-d;const M=[];const R={x:A*Math.cos(m),y:A*Math.sin(m)};const b={x:x*Math.cos(m),y:x*Math.sin(m)};M.push(R);M.push(b);const C=new ft(M,o);const y={startAngle:t,endAngle:e,innerRadius:s,outerRadius:n,angle:g,value:i,text:a,color:o,transform:f,textAnchor:v,ccAngle:m,line:C,isPrioritized:h,start:c,stop:c,chr:l,mutationsTooltip:p?[p]:undefined,fusionTooltip:u?[u]:undefined};return y}static createMovedLabel(t,e){const s=t.startAngle+e;const n=t.endAngle+e;const i=(s+n)/2;const a=i-Math.PI/2;const o=t.innerRadius;const r=t.outerRadius-2;const l=(r-o)/3;const c=Math.cos(t.ccAngle);const h=Math.sin(t.ccAngle);const d=Math.cos(t.ccAngle+e);const p=Math.sin(t.ccAngle+e);const u=[];const g={x:o*c,y:o*h};const m={x:(o+l)*c,y:(o+l)*h};const f={x:(o+2*l)*d,y:(o+2*l)*p};const v={x:(o+3*l)*d,y:(o+3*l)*p};u.push(g);u.push(m);u.push(f);u.push(v);const A=new ft(u,t.color);const x="rotate("+(i*180/Math.PI-90)+")"+"translate("+t.outerRadius+")"+(i>Math.PI?"rotate(180)":"");const M=i>Math.PI?"end":"";const R=t.mutationsTooltip?t.mutationsTooltip[0].color:t.fusionTooltip?t.fusionTooltip[0].color:undefined;const b={startAngle:s,endAngle:n,innerRadius:t.innerRadius,outerRadius:t.outerRadius,angle:i,value:t.value,text:t.text,transform:x,textAnchor:M,ccAngle:a,color:R,line:A,isPrioritized:t.isPrioritized,start:t.start,stop:t.stop,chr:t.chr,mutationsTooltip:t.mutationsTooltip,fusionTooltip:t.fusionTooltip};return b}}class At{constructor(t,e,s,n=0){this.labelMap=new Map;this.settings=t;this.sampleName=e;this.reference=s;this.cnvMaxPercentileAbs=n}map(t,e=[]){const s=this.settings.rings.labelLinesInnerRadius;const a=s+this.settings.rings.labelsToLinesDistance;t.forEach((t=>{if(t.dt==n){const e=this.calculateStartAngle(t.chr,t.position);const n=this.calculateEndAngle(t.chr,t.position);const i=lt.getInstance().mlabel?lt.getInstance().mlabel[t.mClass]:undefined;this.addLabelOrMutation(t,t.gene,t.mname,e,n,s,a,i.color,i.label)}if(t.dt==i){const e=H.getColor(t.chrA,t.chrB);if(t.geneA){const n=this.calculateStartAngle(t.chrA,t.posA);const i=this.calculateEndAngle(t.chrA,t.posA);this.addLabelOrFusion(t,t.geneA,t.posA,n,i,s,a,e)}if(t.geneB&&t.geneA!=t.geneB){const n=this.calculateStartAngle(t.chrB,t.posB);const i=this.calculateEndAngle(t.chrB,t.posB);this.addLabelOrFusion(t,t.geneB,t.posB,n,i,s,a,e)}}}));const o=Array.from(this.labelMap.values());o.forEach((t=>{e.forEach((e=>{if(t.stop>=e.start&&e.stop>=t.start&&t.chr==e.chr){const s={value:e.value,color:gt.getColor(e.value,this.settings,this.cnvMaxPercentileAbs),chr:e.chr,start:e.start,stop:e.stop};if(t.cnvTooltip){t.cnvTooltip.push(s)}else{t.cnvTooltip=[];t.cnvTooltip.push(s)}}}))}));return Array.from(this.labelMap.values())}addLabelOrMutation(t,e,s,n,i,a,o,r,l){const c=this.labelMap.get(e);const h={mname:s,color:r,dataClass:l,chr:t.chr,position:t.position};if(!c){this.labelMap.set(e,vt.createLabel(n,i,a,o,t.value,e,r,l,t.chr,t.position,t.isPrioritized,this.settings.rings.labelsToLinesGap,h))}else{if(c.mutationsTooltip){c.start=Math.min(c.start,t.position);c.stop=Math.max(c.stop,t.position);c.mutationsTooltip.push(h)}else{c.mutationsTooltip=[];c.start=Math.min(c.start,t.position);c.stop=Math.max(c.stop,t.position);c.mutationsTooltip.push(h)}}}addLabelOrFusion(t,e,s,n,i,a,o,r){const l=this.labelMap.get(e);const c={color:r,chrA:t.chrA,chrB:t.chrB,posA:t.posA,posB:t.posB,geneA:t.geneA,geneB:t.geneB,strandA:t.strandA,strandB:t.strandB};if(!l){this.labelMap.set(e,vt.createLabel(n,i,a,o,t.value,e,r,"Fusion transcript",t.chr,t.position,t.isPrioritized,this.settings.rings.labelsToLinesGap,undefined,c))}else{if(l.fusionTooltip){l.start=Math.min(l.start,s);l.stop=Math.max(l.stop,s);l.fusionTooltip.push(c)}else{l.fusionTooltip=[];l.start=Math.min(l.start,s);l.stop=Math.max(l.stop,s);l.fusionTooltip.push(c)}}}calculateStartAngle(t,e){const s=this.reference.chromosomesOrder.findIndex((e=>e==t));const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}calculateEndAngle(t,e){const s=this.reference.chromosomesOrder.findIndex((e=>e==t));const n=this.reference.chromosomes[s];return n.startAngle+(n.endAngle-n.startAngle)*(Number(e)/n.size)}}class xt extends rt{constructor(t,e,s){super(t.rings.labelLinesInnerRadius,t.rings.labelsToLinesDistance,e.sort(((t,e)=>t.startAngle<e.startAngle?-1:t.startAngle>e.startAngle?1:0)));this.elementsToDisplay=[];this.settings=t;this.hasPrioritizedGenes=s;const n=2*Math.PI*(t.rings.labelLinesInnerRadius+t.rings.labelsToLinesDistance);this.overlapAngle=this.settings.label.overlapAngleFactor*this.settings.label.fontSize/n;this.calculateCollisions()}calculateCollisions(){this.collisions=[];let t=[];t=this.elements.filter((t=>t.isPrioritized));if(this.settings.label.prioritizeGeneLabelsByGeneSets){this.elementsToDisplay=this.getLabelsWithPrioritizedGenes(t)}else if(this.hasPrioritizedGenes){const t=this.elements.filter((t=>t.isPrioritized));const e=this.getLabelsWithPrioritizedGenes(t);const s=this.elements.filter((t=>!t.isPrioritized));const n=[...s,...e].sort(((t,e)=>t.startAngle-e.startAngle));this.elementsToDisplay=this.getAllLabels(n)}else{this.elementsToDisplay=this.getLabelsWithPrioritizedGenes(this.elements)}}getLabelsWithPrioritizedGenes(t){const e=[];let s={endAngle:0};t.forEach(((t,n)=>{if(n==0){e.push(t);s=t}else{const n=s.endAngle-t.startAngle+this.overlapAngle;if(n>0&&n<this.settings.label.maxDeltaAngle){const i=vt.createMovedLabel(t,n);e===null||e===void 0?void 0:e.push(i);s=i}if(n<=0){e.push(t);s=t}}}));return e}getAllLabels(t){var e;const s=[];let n={endAngle:0};const i=t.length;let a=-1;for(let o=0;o<t.length;o++){const r=t[o];if(r.isPrioritized){s.push(r);a=o;n=r;continue}if(o==0){if(i>1){if(this.isElementOverlappingNextCancerGene(t,a,r,0)){continue}s.push(r);n=r}continue}const l=n.endAngle-r.startAngle+this.overlapAngle;if(l>0&&l<this.settings.label.maxDeltaAngle){if(o==length-1){s.push(r);continue}if(this.isElementOverlappingNextCancerGene(t,a,r,l)){continue}const i=vt.createMovedLabel(r,l);(e=this.collisions)===null||e===void 0?void 0:e.push(i);s.push(r);n=i}if(l<=0){if(this.isElementOverlappingNextCancerGene(t,a,r,0)){continue}s.push(r);n=r}}return s}isElementOverlappingNextCancerGene(t,e,s,n){const i=this.getNextLabelWithCancerGene(t,e);if(i){const t=s.endAngle+n-i.startAngle+this.overlapAngle;if(t>0){return true}}return false}getNextLabelWithCancerGene(t,e){return t.find(((t,s)=>t.isPrioritized&&s>e))}}class Mt{constructor(t,e,s,n){this.nonExonicInnerRadius=t;this.nonExonicWidht=e;this.sampleName=s;this.reference=n;this.onePxArcAngle=1/t}map(t){const e=this.nonExonicInnerRadius;const s=e+this.nonExonicWidht;const n=[];t.forEach((t=>{const i=lt.getInstance().mlabel?lt.getInstance().mlabel[t.mClass]:undefined;const a=this.calculateStartAngle(t);const o=this.calculateEndAngle(t);const r={startAngle:a,endAngle:o,innerRadius:e,outerRadius:s,color:i.color,text:t.gene,dataClass:i.label,mname:t.mname,chr:t.chr,pos:t.position,sampleName:[t.sampleName]};n.push(r)}));return n}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.position)/s.size)-this.onePxArcAngle}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return this.onePxArcAngle+s.startAngle+(s.endAngle-s.startAngle)*(Number(t.position)/s.size)}}class Rt{constructor(t,e,s,n){this.lohInnerRadius=t;this.lohWidth=e;this.sampleName=s;this.reference=n}map(t){const e=[];t.forEach((t=>{const s=this.calculateStartAngle(t);const n=this.calculateEndAngle(t);const i=this.lohInnerRadius;const a=i+this.lohWidth;const o=nt.provide(t.segmean);const r={startAngle:s,endAngle:n,innerRadius:i,outerRadius:a,color:o,text:t.gene,chr:t.chr,start:t.start,stop:t.stop,value:t.segmean};e.push(r)}));return e}calculateStartAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.start)/s.size)}calculateEndAngle(t){const e=this.reference.chromosomesOrder.indexOf(t.chr);const s=this.reference.chromosomes[e];return s.startAngle+(s.endAngle-s.startAngle)*(Number(t.stop)/s.size)}}class bt{constructor(t,e,s,n,i,a){this.labelsRing=t;this.chromosomesRing=e;this.nonExonicArcRing=s;this.snvArcRing=n;this.cnvArcRing=i;this.lohArcRing=a}}class Ct{constructor(t,e,s,n,i){this.nonExonicArcRing=undefined;this.settings=t;this.dataMapper=e;this.reference=s;this.sampleName=n;this.genesetName=i}map(t){const e=this.dataMapper.map(t);const s=new At(this.settings,this.sampleName,this.reference,e.cnvMaxPercentileAbs);const i=s.map(e.labelData,e.cnvData);const a=new xt(this.settings,i,e.hasPrioritizedGenes);const o=new rt(this.settings.rings.chromosomeInnerRadius,this.settings.rings.chromosomeWidth,this.reference.chromosomes);const r=new Mt(e.nonExonicInnerRadius,this.settings.rings.nonExonicRingWidth,this.sampleName,this.reference);const l=r.map(e.nonExonicSnvData);if(l.length>0){this.nonExonicArcRing=new rt(e.nonExonicInnerRadius,this.settings.rings.nonExonicRingWidth,l)}this.snvArcsMapper=new ht(e.snvInnerRadius,this.settings.rings.snvRingWidth,this.sampleName,this.reference);const c=this.snvArcsMapper.map(e.snvRingDataMap);if(c.length>0){this.snvArcRing=new rt(e.snvInnerRadius,this.settings.rings.snvRingWidth,c)}const h=new Rt(e.lohInnerRadius,this.settings.rings.lohRingWidth,this.sampleName,this.reference);const d=h.map(e.lohData);if(d.length>0){this.lohArcRing=new rt(e.lohInnerRadius,this.settings.rings.lohRingWidth,d)}this.cnvArcsMapper=new mt(e.cnvInnerRadius,this.settings.rings.cnvRingWidth,this.settings,this.sampleName,this.reference,e.percentilePositive,e.percentileNegative,e.cappedCnvMaxAbsValue,e.cnvMaxPercentileAbs,this.settings.cnv.unit,this.settings.Disco.cnvRenderingType);const p=this.cnvArcsMapper.map(e.cnvData);if(p.length>0){this.cnvArcRing=new rt(e.cnvInnerRadius,this.settings.rings.cnvRingWidth,p)}const u=new st(e.fusionRadius,this.sampleName,this.reference);const g=u.map(e.fusionData);let m;if(this.settings.legend.lohLegendEnabled&&e.lohMinValue&&e.lohMaxValue){m=new it(e.lohMinValue,e.lohMaxValue)}const f=new Z(this.settings.legend.snvTitle,this.settings.legend.cnvTitle,this.settings.legend.lohTitle,this.settings.legend.fusionTitle,this.snvArcsMapper?this.snvArcsMapper.snvClassMap:new Map,this.cnvArcsMapper?this.cnvArcsMapper.cnvClassMap:new Map,this.settings.Disco.cnvRenderingType,g.length>0,m);const v=new bt(a,o,this.nonExonicArcRing,this.snvArcRing,this.cnvArcRing,this.lohArcRing);return new ot(this.settings,v,f,g,e,this.genesetName,t.filter((t=>t.dt==n)).length)}}class yt{constructor(t){this.settings=t}map(t){var e,s;const n=t.args.chromosomes;const i=t.args.genome.majorchr;const a=t.args.sampleName;const o=t.args.genome;const r=((e=o===null||o===void 0?void 0:o.geneset)===null||e===void 0?void 0:e[0])?o.geneset[0].lst:[];const l=((s=o===null||o===void 0?void 0:o.geneset)===null||s===void 0?void 0:s[0])?o.geneset[0].name:"";const c=t.args.data;const h=new K(this.settings,i,n);const d=new Y(this.settings,h,a,r);return new Ct(this.settings,d,h,a,l).map(c)}}yt.snvClassLayer={M:"exonic",E:"exonic",F:"exonic",N:"exonic",S:"exonic",D:"exonic",I:"exonic",P:"exonic",L:"exonic",Utr3:"exonic",Utr5:"exonic",ProteinAltering:"exonic",mnv:"non-exonic",ITD:"non-exonic",insertion:"non-exonic",deletion:"non-exonic",Intron:"non-exonic",X:"non-exonic",noncoding:"non-exonic"};class wt{constructor(t){this.cappedCnvMaxAbsValue=t}map(t){const e=[];let s=0;if(t.snvClassMap){this.mapSnv(t,e,s++)}if(t.cnvRenderingType==ut.heatmap){this.mapCnvHeatmap(t,e,s++)}else if(t.cnvRenderingType==ut.bar){if(t.cnvClassMap){this.mapCnvBar(t,e,s++)}}if(t.lohLegend){this.mapLoh(t,e,s++)}if(t.fusionLegend){this.mapFusion(t,e,s++)}return e}mapSnv(t,e,s){const n=[];let i=0;for(const[e,s]of t.snvClassMap){n.push({termid:t.snvTitle,key:e,text:`${s.snvType} (${s.count})`,color:s.color,order:i++,border:"1px solid #ccc"})}e.push({name:t.snvTitle,order:s,items:n})}mapCnvBar(t,e,s){if(!t.cnvClassMap)return;const n=t.cnvClassMap.get(pt.Gain);const i=t.cnvClassMap.get(pt.Loss);const a=t.cnvClassMap.get(pt.Cap);if(n&&i&&a){let o=0;const r=[];if(n.value>0){r.push({termid:t.cnvTitle,key:pt.Gain,text:`Max: ${n.value}`,color:n.color,order:o++,border:"1px solid #ccc"})}if(i.value<0){r.push({termid:t.cnvTitle,key:pt.Loss,text:`Min: ${i.value}`,color:i.color,order:o++,border:"1px solid #ccc"})}r.push({termid:t.cnvTitle,key:pt.Cap,text:`Capping: ${a.value}`,color:a.color,order:o++,border:"1px solid #ccc"});e.push({name:t.cnvTitle,order:s,items:r})}}mapCnvHeatmap(t,e,s){if(!t.cnvClassMap)return;const n=t.cnvClassMap.get(pt.Gain);const i=t.cnvClassMap.get(pt.Loss);const a=t.cnvClassMap.get(pt.Cap);if(n&&i&&a){let o=0;const r=[];if(n.value>0){r.push({termid:t.cnvTitle,key:pt.Gain,text:"Copy number gain",width:100,domain:[0,1],minLabel:0,maxLabel:n.value,order:o++,isLegendItem:true,dt:4,scale:c([0,1],["white",n.color])})}if(i.value<0){r.push({termid:t.cnvTitle,key:pt.Loss,text:"Copy number loss",width:100,domain:[0,1],minLabel:0,maxLabel:i.value,order:o++,isLegendItem:true,dt:4,scale:c([0,1],["white",i.color])})}r.push({termid:t.cnvTitle,key:pt.Cap,text:`Capping: ${a.value}`,color:a.color,order:o++,border:"1px solid #ccc"});e.push({name:t.cnvTitle,order:s,items:r})}}mapLoh(t,e,s){if(!t.lohLegend)return;const n=[];n.push({termid:t.lohTitle,key:"min",text:"min",color:t.lohLegend.colorStartValue,order:0,border:"1px solid #ccc"});n.push({termid:t.lohTitle,key:"max",text:"max",color:t.lohLegend.colorEndValue,order:1,border:"1px solid #ccc"});e.push({name:t.lohTitle,order:s,items:n})}mapFusion(t,e,s){const n=[];n.push({termid:t.fusionTitle,key:_.Interchromosomal,text:"Interchromosomal",color:_.Interchromosomal.valueOf(),order:0,border:"1px solid #ccc"});n.push({termid:t.fusionTitle,key:_.Intrachromosomal,text:"Intrachromosomal",color:_.Intrachromosomal.valueOf(),order:1,border:"1px solid #ccc"});e.push({name:t.fusionTitle,order:s,items:n})}}class It{constructor(t=0,e){this.fontSize=e;this.legendJSONMapper=new wt(t)}render(t,e,s,n,i){const a=v({holder:t.append("g").attr("data-testid","sjpp_disco_plot_legend"),rectFillFxn:t=>t.color,iconStroke:"#aaa"});const o={xOffset:s};const r=this.legendJSONMapper.map(e);a(r,{settings:Object.assign({},{svgw:n,svgh:i,dimensions:o,fontsize:this.fontSize})})}}class Lt{constructor(t,e,s){this.padAngle=t;this.innerRadius=e;this.outerRadius=s}render(t,e){const s=W().padAngle(this.padAngle).value((t=>t.size)).sort(null);const n=s(e);const i=g().innerRadius(this.innerRadius).outerRadius(this.outerRadius);const a=t.append("g").attr("data-testid","sjpp_chromosomes_arc_group");a.selectAll("path").data(n).enter().append("path").attr("d",i).attr("fill","black");a.selectAll("text").data(n).enter().append("text").attr("transform",(t=>`translate(${i.centroid(t)}) rotate(${t.data.angle*180/Math.PI-90})${t.data.angle>Math.PI?"rotate(180)":""}`)).attr("dy","0.35em").attr("text-anchor","middle").text((t=>t.data.text)).style("fill","white")}}class Dt{constructor(t,e){this.animationDuration=t;this.geneClickListener=e}render(t,e,n){const i=t.append("g");const a=x().x((t=>t.x)).y((t=>t.y));const o=j.create();i.selectAll(".group").data(e).enter().append("g").attr("class","group").each(((t,e,n)=>{const i=h(n[e]);i.append("text").attr("class","chord-text").attr("dy",".35em").attr("transform",t.transform).style("text-anchor",t.textAnchor).style("font-size","12px").style("fill",t.color).style("cursor","pointer").text(t.text).on("click",(()=>{if(t.mutationsTooltip){this.geneClickListener(t.text,t.mutationsTooltip.map((t=>t.mname)))}})).on("mouseover",(e=>{const n=s({holder:o.d});this.createTooltip(n,t);o.show(e.x,e.y)})).on("mouseout",(()=>{o.clear();o.hide()}));i.append("path").attr("class","chord-tick").datum(t.line.points).style("stroke",t.color).style("fill","none").attr("d",a)}));i.selectAll(".group").each(((t,e,s)=>{const i=n?n.find((e=>e.text===t.text)):undefined;if(i){const t=h(s[e]);t.selectAll(".chord-text").datum(i).transition().duration(this.animationDuration).attr("transform",i.transform).style("text-anchor",i.textAnchor);t.selectAll(".chord-tick").datum(i.line.points).transition().duration(this.animationDuration).style("fill","none").attr("d",a)}}))}createTooltip(t,e){if(e.mutationsTooltip){const[s,n]=t.addRow();s.text("Gene");n.append("span").style("margin-left","5px").text(e.text);e.mutationsTooltip.forEach((e=>{{const[s,n]=t.addRow();s.text("Consequence");n.append("span").text(e.mname);n.append("span").style("margin-left","5px").style("color",e.color).text(e.dataClass)}{const[s,n]=t.addRow();s.text("Mutation");n.append("span").text(`${e.chr}:${e.position}`)}}))}if(e.fusionTooltip){const[s,n]=t.addRow();s.text("Data type");n.append("span").text("Fusion transcript");e.fusionTooltip.forEach((e=>{const[s,n]=t.addRow();s.text("Break points");n.append("span").text(` ${e.geneA?e.geneA:""} ${e.chrA}:${e.posA} \n\t\t\t\t\t\t${e.strandA=="+"?"forward":"reverse"} > `+`${e.geneB?e.geneB:""} ${e.chrB}:${e.posB} ${e.strandB=="+"?"forward":"reverse"} `)}))}if(e.cnvTooltip){e.cnvTooltip.forEach((e=>{const[s,n]=t.addRow();s.text("CNV");n.append("span").style("color",e.color).text(e.value).append("span").style("margin-left","5px").text(`${e.chr}:${e.start}-${e.stop}`)}))}}}function Tt(t={}){const e={downloadImgName:"disco.plot",Disco:{cnvCapping:5,isOpen:false,prioritizeGeneLabelsByGeneSets:false,showPrioritizeGeneLabelsByGeneSets:false,cnvRenderingType:ut.heatmap,cnvPercentile:80},rings:{nonExonicRingWidth:20,snvRingWidth:20,lohRingWidth:20,cnvRingWidth:30,snvRingFilters:["exonic"],chromosomeInnerRadius:190,chromosomeWidth:20,labelLinesInnerRadius:210,labelsToLinesDistance:30,labelsToLinesGap:2,nonExonicRingEnabled:true,nonExonicFilterValues:["non-exonic"]},verticalPadding:70,horizontalPadding:500,layerScaler:1,padAngle:.002,label:{fontSize:12,maxDeltaAngle:.05,animationDuration:1e3,overlapAngleFactor:5},cnv:{capping:5,ampColor:"#D6683C",lossColor:"#67a9cf",cappedAmpColor:"#8B0000",cappedLossColor:"#00008B",unit:"Unit"},snv:{maxMutationCount:1e4},legend:{snvTitle:"SNV",cnvTitle:"CNV",lohTitle:"LOH",fusionTitle:"SV",lohLegendEnabled:true,fontSize:12,rowHeight:48},menu:{padding:5}};return d(e,t)}class Pt{constructor(t){this.geneClickListener=t}render(t,e){const i=g();const a=t.append("g");const o=j.create();a.selectAll("path").data(e).enter().append("path").attr("d",(t=>i(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const i=s({holder:o.d});const a=structuredClone(e);a.dt=n;a.class=e.dataClass;a.gene=a.text;{const[t,e]=i.addRow();t.text("Consequence");e.append("span").text(a.mname);e.append("span").style("margin-left","5px").style("color",a.color).style("font-size",".8em").text(a.dataClass)}{const[t,e]=i.addRow();t.text(a.ref&&a.alt?"Mutation":"Position");e.append("span").text(`${a.chr}:${a.pos+1} ${a.ref&&a.alt?a.ref+">"+a.alt:""}`)}if(a.gene){const[t,e]=i.addRow();t.text("Gene");e.text(a.gene)}if(a.occurrence>1){const[t,e]=i.addRow();t.text("Occurrence");e.text(a.occurrence)}o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()})).on("click",((t,e)=>{this.geneClickListener(e.text,[e.mname])}))}}class Ot{constructor(t,e){this.svnWidth=t;this.geneClickListener=e}render(t,e){if(e.length>0){const s=e[0].innerRadius;const n=new F(s,this.svnWidth,"#6464641A");n.render(t)}const i=g();const a=t.append("g");const o=j.create();a.selectAll("path").data(e).enter().append("path").attr("d",(t=>i(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const i=s({holder:o.d});const a=structuredClone(e);a.dt=n;a.class=e.dataClass;a.gene=a.text;{const[t,e]=i.addRow();t.text("Consequence");e.append("span").text(a.mname);e.append("span").style("margin-left","5px").style("color",a.color).style("font-size",".8em").text(a.dataClass)}{const[t,e]=i.addRow();t.text(a.ref&&a.alt?"Mutation":"Position");e.append("span").text(`${a.chr}:${a.pos+1} ${a.ref&&a.alt?a.ref+">"+a.alt:""}`)}if(a.gene){const[t,e]=i.addRow();t.text("Gene");e.text(a.gene)}if(a.occurrence>1){const[t,e]=i.addRow();t.text("Occurrence");e.text(a.occurrence)}o.show(t.x,t.y)})).on("mouseout",(()=>{o.clear();o.hide()})).on("click",((t,e)=>{this.geneClickListener(e.text,[e.mname])}))}}class Nt{render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const n=s({holder:a.d});const i=structuredClone(e);i.dt=r;i.gene=i.text;{const[t,e]=n.addRow();t.text("Data type");e.append("span").style("margin-left","5px").text("Loss of Heterozygosity")}const[o,l]=n.addRow();o.text("Position");l.append("span").text(`${e.chr}:${e.start}-${e.stop}`);a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class Et{render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>t.color)).on("mouseover",((t,e)=>{const n=structuredClone(e);n.dt=o;n.samples=[{sample_id:e.sampleName}];n.gene=n.text;const i=s({holder:a.d});{const[t,e]=i.addRow();t.text("Copy number change");e.html(`<span style="background:${n.color}">&nbsp;&nbsp;</span> ${n.value}`)}{const[t,e]=i.addRow();t.text("Position");e.text(n.chr+":"+n.start+"-"+n.stop)}{const[t,e]=i.addRow();t.text("Unit");e.text(n.value)}a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class Vt{constructor(t=0,e=0){this.positivePercentile80=t;this.negativePercentile80=e}render(t,e){const n=g();const i=t.append("g");const a=j.create();i.selectAll("path").data(e).enter().append("path").attr("d",(t=>n(t))).attr("fill",(t=>c([this.negativePercentile80,0,this.positivePercentile80],[t.color,"white",t.color]).clamp(true)(t.value))).on("mouseover",((t,e)=>{const n=s({holder:a.d});const i=structuredClone(e);i.dt=o;i.samples=[{sample_id:e.sampleName}];i.gene=i.text;{const[t,e]=n.addRow();t.text("Copy number change");e.html(`<span style="background:${i.color}">&nbsp;&nbsp;</span> ${i.value}`)}{const[t,e]=n.addRow();t.text("Position");e.text(i.chr+":"+i.start+"-"+i.stop)}{const[t,e]=n.addRow();t.text("Unit");e.text(i.value)}a.show(t.x,t.y)})).on("mouseout",(()=>{a.clear();a.hide()}))}}class St{constructor(t){this.recreateViewModel=false;this.type="Disco";this.opts=t;this.isOpen=false;this.discoInteractions=new X(this)}init(){return t(this,void 0,void 0,(function*(){const t=this.app.getState();const e=t.plots.find((t=>t.id===this.id)).settings;this.stateViewModelMapper=new yt(e);this.viewModel=this.stateViewModelMapper.map(t);const s=this.opts.holder;const n=s.append("div").style("display","inline-block").style("vertical-align","top");const i=n.append("div");const a=n.append("div");const o=this.getConfigInputsOptions(this.viewModel);this.features=yield u({topbar:R({app:this.app,id:this.id,downloadHandler:()=>this.discoInteractions.downloadClickListener(s.select('svg[id="sjpp_disco_plot"]').node()),callback:()=>this.toggleVisibility(this.isOpen),isOpen:()=>this.isOpen,holder:i}),config:b({app:this.app,id:this.id,holder:a,isOpen:()=>this.isOpen,inputs:o})})}))}getConfigInputsOptions(t){const e=[];if(t.settings.Disco.showPrioritizeGeneLabelsByGeneSets){const s=[{boxLabel:t.genesetName,label:`Filter mutations`,type:"checkbox",chartType:"Disco",settingsKey:"prioritizeGeneLabelsByGeneSets",title:`Only show mutations for ${t.genesetName} genes`}];e.push(...s)}const s=[{label:"CNV capping",type:"number",chartType:"Disco",settingsKey:"cnvCapping",title:"Cnv capping",min:0},{boxLabel:"",label:"CNV rendering type",type:"radio",chartType:"Disco",settingsKey:"cnvRenderingType",title:"CNV rendering type",options:[{label:"Heatmap",value:ut.heatmap},{label:"Bar",value:ut.bar}]},{label:"CNV percentile",type:"number",chartType:"Disco",settingsKey:"cnvPercentile",title:"Cnv percentile",min:1,max:100}];e.push(...s);return e}main(){return t(this,void 0,void 0,(function*(){const t=this.state.settings;this.isOpen=t.Disco.isOpen;if(this.recreateViewModel){this.stateViewModelMapper=new yt(t);this.viewModel=this.stateViewModelMapper.map(this.app.getState())}this.recreateViewModel=true;if(this.viewModel){const e=this.opts.holder;e.select('div[id="sjpp_disco_plot_holder_div"]').remove();const s=e.append("div").attr("id","sjpp_disco_plot_holder_div").style("display","inline-block");const n=this.app.getState();for(const t in this.features){this.features[t].update({state:this.state,appState:n})}const i=new It(this.viewModel.cappedCnvMaxAbsValue,t.label.fontSize);const a=new q(this.getRingRenderers(t,this.viewModel,this.discoInteractions.geneClickListener),i);a.render(s,this.viewModel)}}))}getState(t){return t.plots.find((t=>t.id===this.id))}getRingRenderers(t,e,s){const n=new Lt(t.padAngle,t.rings.chromosomeInnerRadius,t.rings.chromosomeInnerRadius+t.rings.chromosomeWidth);const i=new Dt(t.label.animationDuration,s);const a=new Pt(s);const o=new Ot(t.rings.snvRingWidth,s);const r=t.Disco.cnvRenderingType===ut.heatmap?new Vt(e.positivePercentile80,e.negativePercentile80):new Et;const l=new Nt;const c=new Map;c.set(at.CHROMOSOME,n);c.set(at.LABEL,i);c.set(at.NONEXONICSNV,a);c.set(at.SNV,o);c.set(at.CNV,r);c.set(at.LOH,l);return c}toggleVisibility(t){this.app.dispatch({type:"plot_edit",id:this.opts.id,config:{settings:{Disco:{isOpen:!t}}}})}}const zt=p(St);const Bt=zt;function Gt(e){return t(this,void 0,void 0,(function*(){return{chartType:"Disco",subfolder:"disco",extension:"ts",settings:Tt(e.overrides)}}))}export{Bt as componentInit,zt as discoInit,Gt as getPlotConfig};
@@ -1 +1 @@
1
- import{_ as t}from"./tslib.es6-c3c2d88f.js";import{m as e,a as l,b as n,c as i,f as a,e as o}from"./uiUtils-57f4b1ba.js";import{T as s}from"./toggleButtons-2144daab.js";import{y as p,aT as c}from"./app-3d14cbe4.js";import{launch as d}from"./launch.adhoc-cb00917b.js";import"./plot.app-4dc30ebc.js";import"./recover-4888c2a9.js";import"./termsetting-7467350f.js";import"path";import"./FilterRxComp-e8de560c.js";import"./table-be2a9975.js";import"./partjson.esm-b3f1fc21.js";import"./termdb.bins-a60aaa77.js";import"./FilterStateless-75514d37.js";import"./app-bd9f016b.js";import"./termInfo-e16f90f2.js";import"./genesearch-0587c713.js";import"./checkbox-96437f4d.js";import"./rehydrateFilter-12d118cb.js";function r(t,n,i){const a=t.append("div").style("margin","20px 20px 20px 40px").style("font-family","'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif").style("place-items","center left").style("overflow","hidden").classed("sjpp-app-ui",true).classed("sjpp-disco-ui",true);const o={data:[]};e(a,"Select Genome").style("font-size","1.15em").style("padding","10px 0px").style("color","#003366");m(a,n,o);e(a,"Provide Data").style("font-size","1.15em").style("padding","10px 0px 5px 0px").style("color","#003366");a.append("div").style("opacity",.75).style("padding","10px 10px 15px 20px").style("width","65vw").style("line-height","1.5em").html('<p>The plot accepts multiple data types. Input fields for each data type are available in the tabs below. Upload a file or paste data in at least one data type tab and click "Create Disco Plot". <a href="https://proteinpaint.stjude.org/ppdemo/hg38/disco/discoDemoData.tar.gz" target="Demo data">Download example files</a></p>');const s=a.append("div").style("margin-left","2vw");y(s,o);const p=a.append("div").style("display","flex").style("align-items","center").style("padding","15px 0px");h(p,o,n,a,t);l(p,o,".disco_input");if(i)window["doms"]=o;return o}function m(t,e,l){const i=t.append("div").style("margin-left","40px");const a=n(i,e).style("border","1px solid rgb(138, 177, 212)");l.genome=a.node()}function y(e,l){const n=[{label:"SNV Indel",active:true,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="snv";const t=`<ol>\n\t\t\t\t\t<li>chr</li>\n\t\t\t\t\t<li>position</li>\n\t\t\t\t\t<li>gene</li>\n\t\t\t\t\t<li>aachange</li>\n\t\t\t\t\t<li>class</li></ol>\n\t\t\t\t\t<p>Example:</p>\n<pre style="margin-left: 10px;">\nchr1\t226252135\tH3F3A\tK28M\tM\nchr2\t98765432\tTestGene\tTestMutation\tF\n</pre>`;f(n,l,t)}))},{label:"SV",active:false,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="sv";const t=`<ol>\n\t\t\t\t\t<li>chrA</li>\n\t\t\t\t\t<li>posA</li>\n\t\t\t\t\t<li>geneA (optional)</li>\n\t\t\t\t\t<li>chrB</li>\n\t\t\t\t\t<li>posB</li>\n\t\t\t\t\t<li>geneB (optional)</li>\n\t\t\t\t</ol>\n\t\t\t\t<p>Example (with genes):</p>\n<pre style="margin-left: 10px;">\nchr6\t3067605\tMDC1\tchr12\t61521661\tKMT2D\n</pre>\n\t\t\t\t<p>Example (without genes):</p>\n<pre style="margin-left: 10px;">\nchr6\t3067605\tchr12\t61521661\n</pre>`;f(n,l,t)}))},{label:"CNV",active:false,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="cnv";const t=`<ol>\n\t\t\t\t<li>chr</li>\n\t\t\t\t<li>start</li>\n\t\t\t\t<li>stop</li>\n\t\t\t\t<li>value</li>\n\t\t\t\t</ol>\n\t\t\t\t<p>Example:</p>\n<pre style="margin-left: 10px;">\nchr1\t1\t100000000\t0.5\nchr1\t100000000\t200000000\t-0.5\n</pre>`;f(n,l,t)}))}];new s({holder:e,tabs:n,tabsPosition:"vertical",linePosition:"right"}).main()}function f(t,e,l){t.contentHolder.style("border","none").style("display","block").style("padding-left","30px");b(t,e);t.contentHolder.append("div").style("padding","15px 0px 0px 10px").style("opacity",.75).text(`Provide ${t.label} data in tab delimited format with the following columns:`).append("span").html(l);delete t.callback}function b(e,l){const n=95;const i=[{label:"Select File",active:true,width:n,callback:(n,i)=>t(this,void 0,void 0,(function*(){const t=e.key;i.contentHolder.style("border","none").style("display","block");c(i.contentHolder);i.contentHolder.append("div").style("padding","0px 0px 5px 15px").style("opacity",.65).text(`Select a local file`);x(i,l,t);delete i.callback}))},{label:"Paste Data",active:false,width:n,callback:(n,i)=>t(this,void 0,void 0,(function*(){const t=e.key;i.contentHolder.style("border","none").style("display","block");c(i.contentHolder);u(i,l,t);delete i.callback}))}];new s({holder:e.contentHolder,tabs:i}).main()}function x(t,e,l){const n=t.contentHolder.append("div").style("display","inline-block");const i=a(n).classed("disco_input",true);i.on("change",(t=>{const n=t.target.files[0];const i=new FileReader;i.onload=t=>{e.data[l+"Text"]=t.target.result};i.readAsText(n,"utf8")}))}function u(e,l,n){const i=e.contentHolder.append("div").style("display","block");const a=o({div:i,cols:50}).style("border","1px solid rgb(138, 177, 212)").style("margin","0px 0px 0px 20px").classed("disco_input",true).on("keyup",(()=>t(this,void 0,void 0,(function*(){l.data[n+"Text"]=a.property("value").trim()}))))}function h(t,e,l,n,a){const o=i({div:t,text:"Create Disco Plot"});const s=t.append("div");o.style("margin-right","10px").style("font-size","16px").classed("sjpp-ui-submitBtn",true).attr("type","submit").on("click",(()=>{if(!e.data||e.data==undefined){const t=s.append("div").style("display","inline-block").style("max-width","20vw");p(t,"Please provide data");setTimeout((()=>t.remove()),2e3)}else{const t=l[e.genome.options[e.genome.selectedIndex].text];n.remove();d(e.data,t,a);v(a,l)}}))}function v(t,e){t.append("button").html("&#171; Back").on("click",(()=>{t.selectAll("*").remove();r(t,e,false)}))}export{r as init_discoplotUI};
1
+ import{_ as t}from"./tslib.es6-c3c2d88f.js";import{m as e,a as l,b as n,c as i,f as a,e as o}from"./uiUtils-5aad7e13.js";import{T as s}from"./toggleButtons-bb9aca2f.js";import{y as p,aT as d}from"./app-488d9fd6.js";import{launch as c}from"./launch.adhoc-98dc0421.js";import"./plot.app-fc3608a9.js";import"./recover-edcdde38.js";import"./termsetting-c12f1c69.js";import"path";import"./FilterRxComp-cb149666.js";import"./table-10183501.js";import"./partjson.esm-b3f1fc21.js";import"./termdb.bins-06fd21c1.js";import"./FilterStateless-bdd1416d.js";import"./app-5aa892cb.js";import"./termInfo-4d954045.js";import"./genesearch-d8780180.js";import"./checkbox-96437f4d.js";import"./rehydrateFilter-12d118cb.js";function r(t,n,i){const a=t.append("div").style("margin","20px 20px 20px 40px").style("font-family","'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif").style("place-items","center left").style("overflow","hidden").classed("sjpp-app-ui",true).classed("sjpp-disco-ui",true);const o={data:[]};e(a,"Select Genome").style("font-size","1.15em").style("padding","10px 0px").style("color","#003366");m(a,n,o);e(a,"Provide Data").style("font-size","1.15em").style("padding","10px 0px 5px 0px").style("color","#003366");a.append("div").style("opacity",.75).style("padding","10px 10px 15px 20px").style("width","65vw").style("line-height","1.5em").html('<p>The plot accepts multiple data types. Input fields for each data type are available in the tabs below. Upload a file or paste data in at least one data type tab and click "Create Disco Plot". <a href="https://proteinpaint.stjude.org/ppdemo/hg38/disco/discoDemoData.tar.gz" target="Demo data">Download example files</a></p>');const s=a.append("div").style("margin-left","2vw");y(s,o);const p=a.append("div").style("display","flex").style("align-items","center").style("padding","15px 0px");h(p,o,n,a,t);l(p,o,".disco_input");if(i)window["doms"]=o;return o}function m(t,e,l){const i=t.append("div").style("margin-left","40px");const a=n(i,e).style("border","1px solid rgb(138, 177, 212)");l.genome=a.node()}function y(e,l){const n=[{label:"SNV Indel",active:true,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="snv";const t=`<ol>\n\t\t\t\t\t<li>chr</li>\n\t\t\t\t\t<li>position</li>\n\t\t\t\t\t<li>gene</li>\n\t\t\t\t\t<li>aachange</li>\n\t\t\t\t\t<li>class</li></ol>\n\t\t\t\t\t<p>Example:</p>\n<pre style="margin-left: 10px;">\nchr1\t226252135\tH3F3A\tK28M\tM\nchr2\t98765432\tTestGene\tTestMutation\tF\n</pre>`;f(n,l,t)}))},{label:"SV",active:false,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="sv";const t=`<ol>\n\t\t\t\t\t<li>chrA</li>\n\t\t\t\t\t<li>posA</li>\n\t\t\t\t\t<li>geneA (optional)</li>\n\t\t\t\t\t<li>chrB</li>\n\t\t\t\t\t<li>posB</li>\n\t\t\t\t\t<li>geneB (optional)</li>\n\t\t\t\t</ol>\n\t\t\t\t<p>Example (with genes):</p>\n<pre style="margin-left: 10px;">\nchr6\t3067605\tMDC1\tchr12\t61521661\tKMT2D\n</pre>\n\t\t\t\t<p>Example (without genes):</p>\n<pre style="margin-left: 10px;">\nchr6\t3067605\tchr12\t61521661\n</pre>`;f(n,l,t)}))},{label:"CNV",active:false,callback:(e,n)=>t(this,void 0,void 0,(function*(){n.key="cnv";const t=`<ol>\n\t\t\t\t<li>chr</li>\n\t\t\t\t<li>start</li>\n\t\t\t\t<li>stop</li>\n\t\t\t\t<li>value</li>\n\t\t\t\t</ol>\n\t\t\t\t<p>Example:</p>\n<pre style="margin-left: 10px;">\nchr1\t1\t100000000\t0.5\nchr1\t100000000\t200000000\t-0.5\n</pre>`;f(n,l,t)}))}];new s({holder:e,tabs:n,tabsPosition:"vertical",linePosition:"right"}).main()}function f(t,e,l){t.contentHolder.style("border","none").style("display","block").style("padding-left","30px");x(t,e);t.contentHolder.append("div").style("padding","15px 0px 0px 10px").style("opacity",.75).text(`Provide ${t.label} data in tab delimited format with the following columns:`).append("span").html(l);delete t.callback}function x(e,l){const n=95;const i=[{label:"Select File",active:true,width:n,callback:(n,i)=>t(this,void 0,void 0,(function*(){const t=e.key;i.contentHolder.style("border","none").style("display","block");d(i.contentHolder);i.contentHolder.append("div").style("padding","0px 0px 5px 15px").style("opacity",.65).text(`Select a local file`);u(i,l,t);delete i.callback}))},{label:"Paste Data",active:false,width:n,callback:(n,i)=>t(this,void 0,void 0,(function*(){const t=e.key;i.contentHolder.style("border","none").style("display","block");d(i.contentHolder);b(i,l,t);delete i.callback}))}];new s({holder:e.contentHolder,tabs:i}).main()}function u(t,e,l){const n=t.contentHolder.append("div").style("display","inline-block");const i=a(n).classed("disco_input",true);i.on("change",(t=>{const n=t.target.files[0];const i=new FileReader;i.onload=t=>{e.data[l+"Text"]=t.target.result};i.readAsText(n,"utf8")}))}function b(e,l,n){const i=e.contentHolder.append("div").style("display","block");const a=o({div:i,cols:50}).style("border","1px solid rgb(138, 177, 212)").style("margin","0px 0px 0px 20px").classed("disco_input",true).on("keyup",(()=>t(this,void 0,void 0,(function*(){l.data[n+"Text"]=a.property("value").trim()}))))}function h(t,e,l,n,a){const o=i({div:t,text:"Create Disco Plot"});const s=t.append("div");o.style("margin-right","10px").style("font-size","16px").classed("sjpp-ui-submitBtn",true).attr("type","submit").on("click",(()=>{if(!e.data||e.data==undefined){const t=s.append("div").style("display","inline-block").style("max-width","20vw");p(t,"Please provide data");setTimeout((()=>t.remove()),2e3)}else{const t=l[e.genome.options[e.genome.selectedIndex].text];n.remove();c(e.data,t,a);v(a,l)}}))}function v(t,e){t.append("button").html("&#171; Back").on("click",(()=>{t.selectAll("*").remove();r(t,e,false)}))}export{r as init_discoplotUI};
@@ -1 +1 @@
1
- import{P as e,R as t,V as n,a as r,M as o,E as i}from"./sampleScatter.rendererThree-aa51e3c8.js";import"./app-3d14cbe4.js";const s=new e;const a=new t;const c=new n;const l=new r;const p=new r;const u=new r;const d=new o;class f extends i{constructor(e,t,n){super();n.style.touchAction="none";let r=null,o=null;const i=[];const f=this;function m(){n.addEventListener("pointermove",E);n.addEventListener("pointerdown",g);n.addEventListener("pointerup",j);n.addEventListener("pointerleave",j)}function v(){n.removeEventListener("pointermove",E);n.removeEventListener("pointerdown",g);n.removeEventListener("pointerup",j);n.removeEventListener("pointerleave",j);n.style.cursor=""}function h(){v()}function y(){return e}function b(){return a}function E(m){if(f.enabled===false)return;x(m);a.setFromCamera(c,t);if(r){if(a.ray.intersectPlane(s,p)){r.position.copy(p.sub(l).applyMatrix4(d))}f.dispatchEvent({type:"drag",object:r});return}if(m.pointerType==="mouse"||m.pointerType==="pen"){i.length=0;a.setFromCamera(c,t);a.intersectObjects(e,true,i);if(i.length>0){const e=i[0].object;s.setFromNormalAndCoplanarPoint(t.getWorldDirection(s.normal),u.setFromMatrixPosition(e.matrixWorld));if(o!==e&&o!==null){f.dispatchEvent({type:"hoveroff",object:o});n.style.cursor="auto";o=null}if(o!==e){f.dispatchEvent({type:"hoveron",object:e});n.style.cursor="pointer";o=e}}else{if(o!==null){f.dispatchEvent({type:"hoveroff",object:o});n.style.cursor="auto";o=null}}}}function g(o){if(f.enabled===false)return;x(o);i.length=0;a.setFromCamera(c,t);a.intersectObjects(e,true,i);if(i.length>0){r=f.transformGroup===true?e[0]:i[0].object;s.setFromNormalAndCoplanarPoint(t.getWorldDirection(s.normal),u.setFromMatrixPosition(r.matrixWorld));if(a.ray.intersectPlane(s,p)){d.copy(r.parent.matrixWorld).invert();l.copy(p).sub(u.setFromMatrixPosition(r.matrixWorld))}n.style.cursor="move";f.dispatchEvent({type:"dragstart",object:r})}}function j(){if(f.enabled===false)return;if(r){f.dispatchEvent({type:"dragend",object:r});r=null}n.style.cursor=o?"pointer":"auto"}function x(e){const t=n.getBoundingClientRect();c.x=(e.clientX-t.left)/t.width*2-1;c.y=-(e.clientY-t.top)/t.height*2+1}m();this.enabled=true;this.transformGroup=false;this.activate=m;this.deactivate=v;this.dispose=h;this.getObjects=y;this.getRaycaster=b}}export{f as DragControls};
1
+ import{P as e,R as t,V as n,a as r,M as o,E as i}from"./sampleScatter.rendererThree-448689c6.js";import"./app-488d9fd6.js";const s=new e;const a=new t;const c=new n;const l=new r;const p=new r;const u=new r;const d=new o;class f extends i{constructor(e,t,n){super();n.style.touchAction="none";let r=null,o=null;const i=[];const f=this;function m(){n.addEventListener("pointermove",E);n.addEventListener("pointerdown",g);n.addEventListener("pointerup",j);n.addEventListener("pointerleave",j)}function v(){n.removeEventListener("pointermove",E);n.removeEventListener("pointerdown",g);n.removeEventListener("pointerup",j);n.removeEventListener("pointerleave",j);n.style.cursor=""}function h(){v()}function y(){return e}function b(){return a}function E(m){if(f.enabled===false)return;x(m);a.setFromCamera(c,t);if(r){if(a.ray.intersectPlane(s,p)){r.position.copy(p.sub(l).applyMatrix4(d))}f.dispatchEvent({type:"drag",object:r});return}if(m.pointerType==="mouse"||m.pointerType==="pen"){i.length=0;a.setFromCamera(c,t);a.intersectObjects(e,true,i);if(i.length>0){const e=i[0].object;s.setFromNormalAndCoplanarPoint(t.getWorldDirection(s.normal),u.setFromMatrixPosition(e.matrixWorld));if(o!==e&&o!==null){f.dispatchEvent({type:"hoveroff",object:o});n.style.cursor="auto";o=null}if(o!==e){f.dispatchEvent({type:"hoveron",object:e});n.style.cursor="pointer";o=e}}else{if(o!==null){f.dispatchEvent({type:"hoveroff",object:o});n.style.cursor="auto";o=null}}}}function g(o){if(f.enabled===false)return;x(o);i.length=0;a.setFromCamera(c,t);a.intersectObjects(e,true,i);if(i.length>0){r=f.transformGroup===true?e[0]:i[0].object;s.setFromNormalAndCoplanarPoint(t.getWorldDirection(s.normal),u.setFromMatrixPosition(r.matrixWorld));if(a.ray.intersectPlane(s,p)){d.copy(r.parent.matrixWorld).invert();l.copy(p).sub(u.setFromMatrixPosition(r.matrixWorld))}n.style.cursor="move";f.dispatchEvent({type:"dragstart",object:r})}}function j(){if(f.enabled===false)return;if(r){f.dispatchEvent({type:"dragend",object:r});r=null}n.style.cursor=o?"pointer":"auto"}function x(e){const t=n.getBoundingClientRect();c.x=(e.clientX-t.left)/t.width*2-1;c.y=-(e.clientY-t.top)/t.height*2+1}m();this.enabled=true;this.transformGroup=false;this.activate=m;this.deactivate=v;this.dispose=h;this.getObjects=y;this.getRaycaster=b}}export{f as DragControls};
@@ -1,4 +1,4 @@
1
- import{_ as e}from"./tslib.es6-c3c2d88f.js";import{h as t}from"./app-3d14cbe4.js";import{c as i,a as n}from"./_commonjsHelpers-318dc0aa.js";var r=i((function(e){
1
+ import{_ as e}from"./tslib.es6-c3c2d88f.js";import{h as t}from"./app-488d9fd6.js";import{c as i,a as n}from"./_commonjsHelpers-318dc0aa.js";var r=i((function(e){
2
2
  //! openseadragon 4.1.1
3
3
  //! Built on 2024-04-01
4
4
  //! Git commit: v4.1.1-0-f90d9814
@@ -0,0 +1 @@
1
+ import{M as e,d as s,i,G as n,b as a,t as r,H as o,I as l,h as d}from"./app-488d9fd6.js";import{r as c}from"./table-10183501.js";import{i as f,a as p,b as m,T as u,r as h}from"./termsetting-c12f1c69.js";import{c as y}from"./partjson.esm-b3f1fc21.js";import{c as b}from"./termdb.bins-06fd21c1.js";function g(t){switch(t){case"./tvs.categorical.js":return import("./tvs.categorical-b9b37c70.js");case"./tvs.condition.js":return import("./tvs.condition-cbe198d7.js");case"./tvs.density.js":return import("./tvs.density-064e5767.js");case"./tvs.geneVariant.js":return import("./tvs.geneVariant-3fac6bed.js");case"./tvs.numeric.js":return import("./tvs.numeric-86aacc82.js");case"./tvs.samplelst.js":return import("./tvs.samplelst-1b00d7b6.js");case"./tvs.survival.js":return import("./tvs.survival-df35b85b.js");default:return new Promise((function(e,s){(typeof queueMicrotask==="function"?queueMicrotask:setTimeout)(s.bind(null,new Error("Unknown variable dynamic import: "+t)))}))}}class v{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,tip:new e({padding:"5px"})};this.durations={exit:0};w(this);this.categoryData={};this.handlerByType={};this.api={main:this.main.bind(this),showMenu:this.showMenu}}validateOpts(t){if(!t.holder)throw".holder missing";if(!t.vocabApi)throw".vocabApi missing";if(typeof t.callback!="function")throw".callback() is not a function";return t}async main(t={}){this.tvs=t.tvs;this.filter=t.filter;await this.setHandler();await this.updateUI()}async setHandler(){if(!this.tvs||!this.tvs.term)return;const t=this.tvs.term;const e=f(t)?"numeric":p(t)?"categorical":t.type;if(!this.handlerByType[e]){try{const t=await g(`./tvs.${e}.js`);this.handlerByType[e]=t.handler}catch(t){throw`error with handler='./tvs.${e}.js': ${t}`}}this.handler=this.handlerByType[e]}}const _=i(v);function w(t){t.updateUI=function(){const e=t.dom.holder;const s=e.selectAll(".tvs_pill").data([t.tvs],(t=>t?.term.id));s.exit().each(t.exitPill);s.each(t.updatePill);s.enter().append("div").attr("class","tvs_pill").style("white-space","nowrap").style("display","inline-block").transition().duration(200).each(t.enterPill)};t.enterPill=async function(){const e=s(this).style("font-size",".9em");e.append("div").attr("class","term_name_btn sja_filter_tag_btn").style("display","inline-block").style("border-radius","6px 0 0 6px").style("padding","6px 6px 3px 6px").html(t.handler.term_name_gen).style("text-transform","uppercase");e.append("div").attr("class","negate_btn").style("cursor","default").style("padding","6px 6px 3px 6px").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(t.tvs.isnot&&t.tvs.term.type!=="geneVariant"?"NOT":"IS"));t.updatePill.call(this)};t.showMenu=e=>{const s=e?e:t.dom.tip;if(t.tvs.term.type!=="geneVariant"){T(s,t.tvs,t)}t.handler.fillMenu(t,s,t.tvs)};t.updatePill=async function(){const e=s(this);const i=e.datum();const n=t.tvs.values&&t.tvs.values.length||t.tvs.ranges&&t.tvs.ranges.length||t.tvs.term.type=="samplelst";e.select(".term_name_btn").html(t.handler.term_name_gen);e.select(".negate_btn").style("display",n?"inline-block":"none").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(i.isnot&&i.term.type!=="geneVariant"?"NOT":"IS"));const a=t.handler.get_pill_label(i);if(!("grade_type"in a))a.grade_type="";const r=e.selectAll(".value_btn").data(a?[a]:[],(t=>t.txt+t.grade_type));r.exit().each(t.removeValueBtn);r.enter().append("div").attr("class","value_btn sja_filter_tag_btn").style("display",n?"inline-block":"none").style("padding","6px 6px 3px 6px").style("border-radius","0 6px 6px 0").style("font-style","italic").html((t=>t.txt)).append("div").attr("class","grade_type_btn").style("display","inline-block").style("margin","0 5px").style("font-size",".6em").style("text-transform","uppercase").html((t=>t.grade_type)).style("opacity",0).transition().duration(200).style("opacity",1)};t.exitPill=async function(e){s(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()};t.makeValueTable=function(e,s,i,n){if(i?.length==0)return e;const a=e.append("div").style("font-size","0.8rem");const r=a.append("div");const o=Math.max(...i.map((t=>t.samplecount)),0);i.forEach((t=>t.bar_width_frac=Number((1-(o-t.samplecount)/o).toFixed(4))));const l=100;const d=[];const f=[];for(const[t,e]of i.entries()){let i=e.label||e.key;if(e.samplecount)i+=" (n="+e.samplecount+")";const n=l*e.bar_width_frac;const a=`<div style='margin:1px 10px;width:${n}px;height:15px;background-color:#ddd'>`;d.push([{value:i},{html:a}]);let r=false;if(s.term.type=="categorical"||s.term.type=="survival")r=s.values.find((t=>t.key===e.key));else if(s.term.type=="float"||s.term.type=="integer")r=s.ranges.find((t=>String(t.value)===e.value.toString()));else if(s.term.type=="condition")r=s.values.find((t=>String(t.key)===String(e.key)));if(r)f.push(t)}const p=[{label:"tvs"},{label:"bar"}];const m={text:"APPLY",class:"sjpp_apply_btn sja_filter_tag_btn",callback:t=>{if(n)n(t)}};t.tableApi=c({rows:d,columns:p,div:r,maxWidth:"40vw",maxHeight:"40vh",buttons:[m],showHeader:false,striped:false,showLines:false,selectedRows:f,selectedRowStyle:{"text-decoration":s.isnot?"line-through":""}});return r};t.removeValueBtn=function(e,i){const n=s(this.parentNode);const a=n.datum();const r=t.handler.getSelectRemovePos(i,a);s(n.selectAll(".value_select")._groups[0][r]).remove();s(n.selectAll(".or_btn")._groups[0][i]).remove();s(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()}}async function j(t){const e=new v(t);e.tvs={term:t.term};e.filter=t.filter;await e.setHandler();if(e.handler.setTvsDefaults)e.handler.setTvsDefaults(e.tvs);e.handler.fillMenu(e,t.holder,e.tvs)}function T(t,e,s){const i=t.selectAll("label").data([{label:"Exclude",value:"false",checked:e.isnot!==undefined?e.isnot:false}]).enter().append("label").style("margin","0 5px");const n=i.append("input").attr("type","checkbox").attr("name","sja_filter_isnot_input").attr("value",(t=>t.value)).property("checked",(t=>t.checked)).style("vertical-align","top").style("margin-right","3px").on("change",(()=>{e.isnot=n.node().checked;if(s.tableApi){s.tableApi.update({selectedRowStyle:{"text-decoration":e.isnot?"line-through":""}})}}));i.append("span").style("margin-right","5px").style("vertical-align","top").html((t=>t.label))}function x(t,e){if(t.type==="tvs"&&t.tvs.term.id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=x(s,e);if(t)return t}}function S(t,e){if(t.$id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=S(s,e);if(t)return t}}function k(t,e){if(t.$id===e)return t;if(!t.lst)return;for(const s of t.lst){if(s.$id===e)return t;else if(s.type=="tvslst"){const t=k(s,e);if(t)return t}}}function N(t,e){if(t.tag===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=N(s,e);if(t)return t}}function C(t=[],e="",s=null){const i={type:"tvslst",in:true,join:e,lst:t};if(s!==null&&i.$id!==undefined)i.$id=s;return i}function I(t){if(!t)return C([]);const e=JSON.parse(JSON.stringify(t));const s=O(e);return s.type=="tvslst"?s:C([s])}function O(t){delete t.$id;delete t.tag;if(t.type!="tvslst")return t;const e=t.lst.filter((t=>t.type!=="tvslst"||t.lst.length>0)).map((t=>t.type!=="tvslst"||t.lst.length>1?t:t.lst[0]));e.forEach(D);if(!e.length){return C([],"",t.$id)}else if(e.length==1){if(e[0].type==="tvslst"){return O(e[0])}else{return D(e[0])}}else{t.lst=[];for(const s of e){if(s.type==="tvslst"){const e=O(s);if(e.type!=="tvslst"||e.join!=t.join||e.in!=t.in){t.lst.push(e)}else if(e.lst.length){t.lst.push(...e.lst)}}else{t.lst.push(s)}}return t}}function D(t,e=null){delete t.$id;if(typeof e=="function")e(t);if(t.type=="tvslst"){for(const s of t.lst){D(s,e)}}return t}function A(t){if(!t||t.length==0)return;let e=JSON.parse(JSON.stringify(t[0]));if(t.length==1)return e;if(e.lst.length<2){if(e.join!=="")throw'filter.join must be an empty string "" when filter.lst.length < 2';e.join="and"}else if(e.join=="or"){e={type:"tvslst",join:"and",in:true,lst:[e]}}else if(e.join!="and"){throw'filter.join must be either "and" or "or" when .lst length > 1'}for(let s=1;s<t.length;s++){const i=JSON.parse(JSON.stringify(t[s]));if(i.join=="or")e.lst.push(i);else e.lst.push(...i.lst)}if(e.lst.length==1&&e.lst[0].type=="tvs"){e.join=""}return e}let q=0;function $(t){t.initUI=async function(){if(t.opts.newBtn){t.opts.newBtn.on("click.filter",t.displayTreeNew)}else{t.dom.newBtn=t.dom.holder.append("div").attr("class","sja_new_filter_btn sja_menuoption").html(t.opts.emptyLabel).style("display","inline-block").on("click",t.displayTreeNew)}t.dom.filterContainer=t.dom.holder.append("div").attr("class","sja_filter_container");t.dom.holder.selectAll(".sja_filter_add_transformer").data(t.opts.joinWith).enter().append("div").attr("class","sja_filter_add_transformer").style("display",(e=>t.filter&&t.filter.join!=e?"inline-block":"none")).style("margin-left","10px").style("padding","5px").style("border-radius","5px").style("cursor","pointer").html((t=>"+"+t.toUpperCase())).on("click",t.displayTreeNew);t.dom.table=t.dom.controlsTip.clear().d.append("table").style("border-collapse","collapse");const e=[{action:"edit",html:["","Edit","&rsaquo;"],handler:t.editTerm},{action:"join",html:["&#10010;","","&rsaquo;"],handler:t.displayTreeMenu},{action:"switch",html:["","Switch to",""],handler:t.switchJoin},{action:"negate",html:["","Negate",""],handler:t.negateClause},{action:"remove",html:["&#10006;","Remove",""],handler:t.removeTransform}];if(t.opts.vocab){e.splice(1,0,{action:"replace",html:["","Replace","&rsaquo;"],handler:t.displayTreeMenu})}t.dom.table.selectAll("tr").data(e).enter().append("tr").attr("class","sja_menuoption").on("click",t.handleMenuOptionClick).selectAll("td").data((t=>t.html)).enter().append("td").style("padding","5px").style("border-top","solid 1px white").style("color",((t,e)=>t=="&#10006;"?"#a00":e===0?"#0a0":"#111")).style("opacity",((t,e)=>e===0?.8:1)).html((t=>t));t.dom.treeHead=t.dom.treeTip.d.append("div").attr("class","sja_tree_tip_head").style("padding","3px");t.dom.termSrcDiv=t.dom.treeTip.d.append("div").attr("class","sja_term_src_body");t.dom.treeHeadTitle=t.dom.treeHead.append("div");s("body").on("mousedown.sja_filter_"+q++,(e=>{if(["sja_filter_join_label","sja_filter_clause_negate","sja_filter_paren_open","sja_filter_paren_close"].includes(e.target.className))return;t.dom.filterContainer?.selectAll(".sja_filter_grp").style("background-color","transparent");t.removeBlankPill();this.dom.holder?.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay)}))};t.updateUI=async function(e,s){e.datum(s).style("display",!s.lst||!s.lst.length?"none":"inline-block");const i=e.selectAll(":scope > .sja_filter_grp").style("background-color","transparent").data([s],t.getId);i.exit().each(t.removeGrp);i.each(t.updateGrp);i.enter().append("div").attr("class","sja_filter_grp").style("margin","5px").each(t.addGrp);t.updatePromise(0)};t.addGrp=function(e,i){const n=this.parentNode.__data__;s(this).style("display","inline-block");s(this).append("div").attr("class","sja_filter_clause_negate").style("display",n.in?"none":"inline-block").style("color","rgb(102,0,0)").style("font-weight",500).style("cursor","pointer").html("NOT").on("click",t.displayControlsMenu);s(this).append("div").attr("class","sja_filter_paren_open").html("(").style("display","none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);const a=e.type=="tvslst"?e.lst:[e];const r=s(this).selectAll(":scope > .sja_filter_item").data(a,t.getId);r.enter().append("div").attr("class","sja_filter_item").each(t.addItem);if(t.opts.joinWith.length==1){t.dom.last_join_div=s(this).append("div").attr("class","sja_filter_last_join").style("display","inline");t.dom.last_join_label=t.dom.last_join_div.append("div").datum({action:"join",html:["&#10010;","","&rsaquo;"],handler:t.displayTreeMenu}).attr("class","sja_filter_last_join_label").style("padding","0 5px").style("display",n.lst.length?"inline":"none").style("font-weight",500).style("cursor","pointer").html("+"+t.opts.joinWith[0].toUpperCase()).on("click",t.showLastJoinBlank);s("body").on("mousedown.sja_filter_last_join",(()=>{t.dom.last_join_label.style("display","inline")}))}s(this).append("div").attr("class","sja_filter_paren_close").style("padding","0 5px").html(")").style("display","none").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);s(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||a.length<2?"none":!n.in||a.length>1&&n.tag!="filterUiRoot"?"inline-block":"none")};t.updateGrp=function(e,i){const n=this.parentNode.__data__;s(this).select(":scope > .sja_filter_clause_negate").style("display",n.in?"none":"inline-block");const a=e.type=="tvslst"?e.lst:[e];s(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||a.length<2?"none":!n.in||a.length>1&&n.tag!="filterUiRoot"?"inline-block":"none");const r=s(this).selectAll(":scope > .sja_filter_item").data(a,t.getId);r.exit().each(t.removeItem);r.each(t.updateItem);r.enter().insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_item").each(t.addItem);s(this).selectAll(":scope > .sja_filter_item").sort(((t,e)=>a.indexOf(t)-a.indexOf(e)));if(t.dom.last_join_label){t.dom.last_join_div.datum(n);this.insertBefore(t.dom.last_join_div.node(),s(this).select(":scope > .sja_filter_paren_close").node());t.dom.last_join_label.style("display","inline")}};t.removeGrp=function(e){t.numExpectedItems+=1;if(e.type=="tvslst"){for(const s of e.lst){if(s.lst)t.removeGrp(s);else{delete t.pills[s.$id]}}}else{delete t.pills[e.$id]}if(this instanceof Node){s(this).selectAll("*").on("click",null);s(this).on("click",null).remove()}t.updatePromise()};t.addItem=async function(e,i){const n=this.parentNode.__data__;if(e.type=="tvslst"){t.updateUI(s(this),e);t.addJoinLabel(this,n,e);return}t.numExpectedItems+=1;const a=s(this).style("display","inline-block").style("position","relative").style("white-space","nowrap").append("div").attr("class","sja_pill_wrapper").style("display","inline-block").style("margin",t.opts.joinWith.length>1?"":"2px").on("click",e.renderAs==="htmlSelect"?null:t.displayControlsMenu);t.addJoinLabel(this,n,e);if(e.renderAs=="htmlSelect"){const s=V(t,e);const i=a.append("select").on("change",(function(){const i=JSON.parse(JSON.stringify(t.filter));const a=S(i,n.$id);const r=n.lst.indexOf(e);if(r==-1)return;const o=+this.value;const l=JSON.parse(JSON.stringify(e));const d="keys"in s[o]?s[o].keys:[s[o].key];l.tvs.values=d.map((t=>({key:t,label:t})));a.lst[r]=l;t.refresh(i)}));const r=M(t,e);i.selectAll("option").data(s).enter().append("option").property("value",((t,e)=>e)).property("selected",((t,e)=>e==r)).html((t=>t.shortLabel?t.shortLabel:t.label?t.label:t.key))}else{const s=await _({vocabApi:t.vocabApi,holder:a,debug:t.opts.debug,getCategoriesArguments:t.opts.getCategoriesArguments,callback:s=>{const i=JSON.parse(JSON.stringify(t.filter));const a=S(i,n.$id);const r=n.lst.indexOf(e);if(r==-1)return;const o=a.lst.findIndex((t=>t.$id==e.$id));if(o==-1)a.lst[r]={$id:e.$id,type:"tvs",tvs:s};else a.lst[o].tvs=s;t.refresh(i)}});t.pills[e.$id]=s;await s.main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.updateItem=async function(e,i){const n=this.parentNode.__data__;s(this).select(":scope > .sja_filter_join_label").style("display",t.opts.joinWith.length>1&&n.lst.indexOf(e)<n.lst.length-1?"inline-block":"none").style("margin",t.opts.joinWith.length>1?"":"2px").html(n.join=="and"?"AND":"OR");if(e.type=="tvslst"){t.updateUI(s(this),e)}else if(e.renderAs==="htmlSelect"){t.numExpectedItems+=1;s(this).select("select").property("value",""+M(t,e))}else{if(!t.pills[e.$id])return;t.numExpectedItems+=1;await t.pills[e.$id].main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.removeItem=function(e){delete t.pills[e.$id];s(this).on("click",null).remove()};t.addJoinLabel=function(e,i,n){const a=i.lst.findIndex((t=>t.$id===n.$id));s(e).append("div").attr("class","sja_filter_join_label").style("display",t.opts.joinWith.length>1&&i.lst.length>1&&n&&a!=-1&&a<i.lst.length-1?"inline-block":"none").style("width","50px").style("padding","5px").style("border","none").style("border-radius","5px").style("text-align","center").style("cursor","pointer").html(i.lst.length<2?"":i.join=="and"?"AND":"OR").on("click",t.displayControlsMenu)};t.updateJoinLabel=function(e){const i=this.parentNode.parentNode.parentNode.__data__;const n=i.lst.findIndex((t=>t.$id===e.$id));s(this).style("display",t.opts.joinWith.length>1&&i.lst.length>1&&e&&n!=-1&&n<i.lst.length-1?"inline-block":"none")};t.getAddTransformerBtnDisplay=function(e){if(t.opts.joinWith.length<2){return"none"}else if(t.filter&&t.filter.lst.find((t=>t.tag==="cohortFilter"))){return t.filter.lst.length==1&&e=="and"?"inline-block":"none"}else{return t.filter&&t.filter.lst.length>0&&(t.filter.join!==e||!t.filter.in)?"inline-block":"none"}}}function V(t,e){return e.selectOptionsFrom=="selectCohort"?t.opts.termdbConfig.selectCohort.values:Array.isArray(e.tvs.term.values)?e.tvs.term.values:Object.values(e.tvs.term.values)}function M(t,e){const s=V(t,e);const i=JSON.stringify(e.tvs.values.map((t=>t.key)).sort());const n=s.findIndex((t=>t.keys?i===JSON.stringify(t.keys.sort()):t.key===i));return n}const R="#fff";function E(t){t.displayControlsMenu=function(e){e.stopPropagation();if(!t.activeData)return;const s=this.parentNode.__data__;const i=k(t.filter,s.$id);t.activeData={item:s,filter:i,elem:this};t.removeBlankPill();t.resetGrpHighlights(this,i);if(s.noEdit)t.dom.table.selectAll("tr").filter((t=>t.action=="edit")).style("display","none");t.dom.controlsTip.showunder(this)};t.resetGrpHighlights=function(e,s){const i=e.className;const n=i.includes("join")||i.includes("negate")||i.includes("paren");const a=t.dom.controlsTip.d.selectAll("tr").style("background-color","");a.filter((t=>t.action=="edit"||t.action=="replace")).style("display",n?"none":"table-row");a.filter((t=>t.action=="remove")).style("display",i.includes("_join_")&&s.lst.find((t=>t.tag=="cohortFilter"))?"none":"table-row");a.filter((t=>t.action=="join")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||i.includes("negate")||i.includes("paren")?"none":"table-row").select("td:nth-child(2)").html(n?s.join.toUpperCase():s.join=="and"?"OR":"AND");a.filter((t=>t.action=="switch")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||!i.includes("_join_")?"none":"table-row").select("td:nth-child(2)").html((t=>s.join=="and"?"Switch to OR":"Switch to AND"));t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(n){if(i.includes("join"))e.parentNode.parentNode.style.backgroundColor="#ee5";else e.parentNode.style.backgroundColor="#ee5"}};t.handleMenuOptionClick=async function(e,s){e.stopPropagation();if(s==t.activeData.menuOpt)return;t.activeData.menuOpt=s;if(t.activeData.elem.className.includes("join")&&s.action!=="join"&&s.action!="switch"){t.activeData.item=t.activeData.filter;t.activeData.filter=k(t.filter,t.activeData.item)}t.resetBlankPill(s.action);t.dom.controlsTip.d.selectAll("tr").style("background-color","");await s.handler(this,s)};t.resetBlankPill=function(e){t.removeBlankPill();t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(e!="join")return;const i=t.dom.last_join_div?t.dom.last_join_div.node():t.activeData.elem.className.includes("join_label")?t.activeData.elem.parentNode.parentNode:t.activeData.item.type=="tvs"||t.activeData.filter===t.filter?t.activeData.elem:t.activeData.elem.parentNode.parentNode;const n=t.opts.joinWith.length===1?t.opts.joinWith[0].toUpperCase():t.activeData.elem.className.includes("join_label")?t.activeData.filter.join.toUpperCase():t.activeData.btn&&typeof t.activeData.btn.__data__==="string"?t.activeData.btn.__data__.toUpperCase():t.activeData.item.type=="tvslst"?t.activeData.filter.join.toUpperCase():t.activeData.filter.join=="or"?"AND":"OR";if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){s(i).insert("div","div").attr("class","sja_filter_paren_open").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html("(")}const a=s(i).insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_blank_pill").style("display","inline-block").style("height","20px").style("overflow","visible");a.append("div").style("display","inline-block").style("width","50px").style("text-align","center").html(n);a.append("div").style("position","relative").style("top","-7px").style("display","inline-block").style("width","80px").style("height","22px").style("margin-right","5px").style("border","3px dashed #b8d3ea").style("vertical-align","top").style("background-color","#ee5");if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){s(i).append("div").attr("class","sja_filter_paren_close").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html(")")}if(i==t.dom.filterContainer.node()){t.dom.filterContainer.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display",t.opts.joinWith.length>1&&t.filter.lst.length>1?"inline-block":"none")}};t.removeBlankPill=function(){t.dom.holder?.selectAll(".sja_filter_blank_pill, .sja_pill_wrapper > .sja_filter_paren_open, .sja_pill_wrapper > .sja_filter_paren_close").remove();if(t.filter.in&&t.filter.lst.filter((t=>t.type==="tvslst")).length<1){t.dom.filterContainer?.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display","none")}};t.displayTreeNew=async function(e,s){e.stopPropagation();if(t.opts.newBtn&&this.className!=="sja_filter_add_transformer"&&t.filter.lst.length)return;t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(t.filter.lst.length>0){t.activeData={item:t.filter,filter:t.filter,elem:t.dom.filterContainer.node(),btn:this}}if(t.filter.lst.length)t.resetBlankPill("join");const i=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(i){t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");t.dom.treeTip.clear().showunder(i)}else{t.dom.treeTip.clear().showunder(this)}const n=t.activeData?t.getAdjustedRoot(t.activeData.filter.$id,s):JSON.parse(t.rawCopy);const a=await import("./app-5aa892cb.js");a.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,termfilter:{filter:n},tree:{usecase:{target:"filter"}}},tree:{disable_terms:t.activeData&&t.activeData.filter&&t.activeData.filter.lst&&s=="and"?t.activeData.filter.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):[],click_term2select_tvs(e){t.editFilterRoot(s,[{type:"tvs",tvs:e}])}}})};t.editFilterRoot=(e,s)=>{const i=JSON.parse(JSON.stringify(t.filter));if(!i.lst.length){if(s.length>1)i.join="and";i.lst.push(...s);t.refresh(i)}else if(e!="or"&&e!="and"){throw"unhandled new term(s): invalid appender join value"}else{if(!i.join)i.join=e;if(i.join==e&&i.in){if(s.length<2||i.join=="and"){i.lst.push(...s)}else{i.push({type:"tvslst",in:true,join:"and",lst:s})}t.refresh(i)}else if(e=="and"||s.length<2){delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:e,lst:[i,...s]})}else{delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:"or",lst:[i,{type:"tvslst",in:true,join:"and",lst:s}]})}}};t.displayTreeMenu=async function(e,i){s(e).style("background-color",R);t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");const n=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(n){t.dom.controlsTip.hide();t.dom.treeTip.clear().showunder(n)}else if(e.lastChild instanceof HTMLElement){t.dom.treeTip.clear().showunderoffset(e.lastChild)}else{t.dom.treeTip.clear().showunder(e)}const a=t.activeData.filter;const r=await import("./app-5aa892cb.js");r.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,header_mode:"search_only",termfilter:{filter:t.getAdjustedRoot(a.$id,a.join)},tree:{usecase:{target:"filter"}}},tree:{disable_terms:a&&a.lst&&a.join=="and"?a.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):!t.activeData.item?[]:t.activeData.item.type=="tvs"?[t.activeData.item.tvs.term.id]:t.activeData.item.lst?t.activeData.item.lst.filter((t=>t.type=="tvs")).map((t=>t.tvs.term.id)):[],click_term2select_tvs:i.action=="replace"?t.replaceTerm:!a.join||!a.lst.length||t.activeData.elem&&t.activeData.elem.className.includes("join")?t.appendTerm:t.subnestFilter}})};t.editTerm=function(e){s(e.parentNode).selectAll("tr").style("background-color",t.highlightEditRow);const i=t.dom.termSrcDiv;const n=t.activeData.item;t.dom.treeTip.clear();t.pills[n.$id].showMenu(i);t.dom.treeTip.showunderoffset(e.lastChild)};t.highlightEditRow=function(t){return t.action=="edit"?R:""};t.handleNotLabelClick=function(e,s){t.activeData={item:this.__data__};t.negateClause()};t.negateClause=function(){const e=JSON.parse(JSON.stringify(t.filter));const s=S(e,t.activeData.item.$id);if(s.type=="tvslst")s.in=!s.in;else if(s.type=="tvs"&&s.tvs?.term?.type=="geneVariant"){const t=s.tvs.values.filter((t=>t.mclassExcludeLst.length>0))[0];const e=t.mclassLst;t.mclassLst=t.mclassExcludeLst;t.mclassExcludeLst=e;s.tvs.isnot=!s.tvs.isnot}else s.tvs.isnot=!s.tvs.isnot;t.refresh(e)};t.replaceTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=S(i,t.activeData.filter.$id);const a=n.lst.findIndex((e=>e.$id===t.activeData.item.$id));if(s.length<2||n.join=="and"){n.lst.splice(a,1,...s)}else{n.lst[a]={in:!e.isnot,type:"tvslst",join:"and",lst:s}}t.refresh(i)};t.appendTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=S(i,t.activeData.filter.$id);if(s.length<2||n.join=="and"){n.lst.push(...s);if(n.join==""&&t.opts.joinWith.length===1)n.join=t.opts.joinWith[0]}else{n.lst.push({in:true,type:"tvslst",join:"and",lst:s})}t.refresh(i)};t.subnestFilter=e=>{let s;if(Array.isArray(e)){s=e}else{s=[{type:"tvs",tvs:e}]}const i=t.activeData.item;const n=t.activeData.filter;const a=JSON.parse(JSON.stringify(t.filter));const r=S(a,n.$id);const o=r.lst.findIndex((t=>t.$id===i.$id));r.lst[o]={in:true,type:"tvslst",join:n.join=="or"?"and":"or",lst:[i,...s]};t.refresh(a)};t.removeTransform=function(e,s){const i=s.action||typeof s!=="object"?t.activeData.item:S(t.filter,s.$id);const n=k(t.filter,i.$id);if(i==n){t.refresh(C([],"",i.$id));return}const a=n.lst.findIndex((t=>t.$id===i.$id));if(a==-1)return;const r=JSON.parse(JSON.stringify(t.filter));const o=S(r,n.$id);o.lst.splice(a,1);if(o.lst.length===1){const e=k(r,o.$id);if(o.lst[0].type=="tvslst"){if(e==r){o.lst[0].tag="filterUiRoot";t.refresh(o.lst[0])}else{const s=e.lst.findIndex((t=>t.$id==o.$id));if(o.lst[0].join==e.join){e.lst.splice(s,1,...o.lst[0].lst);t.refresh(r)}else{e.lst[s]=o.lst[0];t.refresh(r)}}}else{o.join="";const s=e.lst.findIndex((t=>t.$id===o.$id));e.lst[s]=o.lst[0];if(!o.in){e.lst[s].tvs.isnot=!e.lst[s].tvs.isnot;if(e==r)e.in=true}t.refresh(r)}}else{t.refresh(r)}};t.showLastJoinBlank=function(e,s){e.stopPropagation();const i=t.dom.last_join_div.node();t.dom.last_join_label.style("display","none");const n=this.parentNode.__data__;t.activeData={item:n,filter:n,elem:i};t.resetBlankPill(s.action);t.displayTreeMenu(i,s)};t.switchJoin=function(e,s){const i=JSON.parse(JSON.stringify(t.filter));const n=S(i,t.activeData.filter.$id);if(n.join<2)return;n.join=n.join=="and"?"or":"and";t.refresh(i)}}function B(t,e={}){if(t.find((t=>!Number.isFinite(t))))throw"non-numeric values found";let s;const i=new Set(t);if(i.size===1){const t=[...i][0];s={type:"custom-bin",lst:[{stop:t,stopinclusive:false,startunbounded:true,label:"<"+t},{start:t,stop:t,startinclusive:true,stopinclusive:true,label:"="+t},{start:t,startinclusive:false,stopunbounded:true,label:">"+t}]}}else{t.sort(((t,e)=>t-e));const e=t.length;const i=t[0];const n=t[e-1];const a=(n-i)/8;let r=Math.round(e*.05)-1;if(r<0)r=0;const o=t[r];const l=Math.max(i+a,o);let[d,c,f,p]=J(a,l,n,i);s={type:"regular-bin",startinclusive:true,bin_size:d,first_bin:{stop:c}};if(f)s.last_bin={start:f};if(p)s.rounding=p}if("format"in e){if(e.format==="string"){return JSON.stringify(s)}else{throw"options are not in the correct format"}}else{return s}}function J(t,e,s,i){let n,a,r,o;const l=Math.floor(Math.log10(t));if(t>=.1&&t<=2){n=Math.round(t/(1*10**l))*(1*10**l);a=Math.round(e/(1*10**l))*(1*10**l)}else{n=Math.round(t/(5*10**l))*(5*10**l);a=Math.round(e/(5*10**l))*(5*10**l);if(n===0)n=1*10**l;if(a===0)a=1*10**l;if(n===5*10**l&&a===1*10**l)a=5*10**l}if(a<i)a=a*2;const d=a+n*7;if(s>d){r=a+n*6}if(t<1){const t=Math.abs(l);n=Number(n.toFixed(t));a=Number(a.toFixed(t));if(r)r=Number(r.toFixed(t));o="."+t+"f"}if(Object.is(a,-0))a=0;return[n,a,r,o]}class P{constructor(t){this.app=t.app;this.opts=t;this.state=t.state;this.vocab=t.state.vocab;this.currAnnoData={samples:{},refs:{byTermId:{}},lastTerms:[],lastFilter:{}};this.missingCatValsByTermId={};const e=localStorage.getItem("jwtByDsRoute")||`{}`;this.jwtByDsRoute=JSON.parse(e);const s=this.vocab?.dslabel||this.state?.dslabel;this.jwtByRoute=this.jwtByDsRoute[s]||{}}async main(t=null){if(t)Object.assign(this.state,t);else this.state=structuredClone(this.app?.getState?.()||this.opts.state);if(this.state.vocab)this.vocab=this.state.vocab;const e=this.state.dslabel||this.state.vocab.dslabel;this.verifiedToken=!this.state.termdbConfig?.requiredAuth?.length||n(e,"termdb");if(e)await this.maySetVerifiedToken(e)}async maySetVerifiedToken(t){if(this.verifiedToken===true)return this.verifiedToken;let e=this.opts.getDatasetAccessToken?.();if(!e)e=this.jwtByRoute["termdb"];if(this.verifedToken&&e===this.verifiedToken)return this.verifiedToken;try{const s=this.state.termdbConfig?.requiredAuth.find((t=>t.route=="termdb"));if(!s){this.verifiedToken=true;return}if(s.type==="jwt"){if(!e){delete this.verifiedToken;return}const i={[s.headerKey]:e};const n="termdb";if(!i.authorization&&this.jwtByRoute[n])i.authorization=`Bearer ${btoa(this.jwtByRoute[n])}`;const r=await a("/jwt-status",{method:"POST",headers:i,body:{dslabel:t,route:n,embedder:location.hostname}});this.verifiedToken=r.status==="ok"&&e;if(r.error){this.tokenVerificationPayload=r;throw r.error}else{this.sessionId=s.headerKey&&r[s.headerKey]||r["x-sjppds-sessionid"]||r["x-ds-access-token"];delete this.tokenVerificationMessage;delete this.tokenVerificationPayload;if(r.jwt){if(!this.jwtByDsRoute[t]){this.jwtByDsRoute[t]={};this.jwtByRoute=this.jwtByDsRoute[t]}this.jwtByDsRoute[t][r.route]=r.jwt;localStorage.setItem("jwtByDsRoute",JSON.stringify(this.jwtByDsRoute))}}}else{throw`unsupported requiredAuth='${s.type}'`}}catch(t){this.tokenVerificationMessage=t.message||t.reason||t}}hasVerifiedToken(){return this.verifiedToken&&true}mayGetAuthHeaders(t=""){const e=this.state.termdbConfig?.requiredAuth;if(!e)return{};if(!this.verifiedToken){this.tokenVerificationMessage=`requires login for this data`;return}const s={};if(e.headerKey)s[e.headerKey]=this.verifiedToken;if(this.sessionId)s["x-sjppds-sessionid"]=this.sessionId;if(t&&this.jwtByRoute[t]){const e=this.jwtByRoute[t];s.authorization=`Bearer ${btoa(e)}`}return s}async trackDsAction({action:t,details:e}){const s={"x-sjppds-sessionid":this.sessionId};const i=this.jwtByRoute.termdb;if(i)s.authorization="Bearer "+btoa(i);await a("/authorizedActions",{method:"POST",credentials:"include",headers:s,body:Object.assign({dslabel:this.vocab.dslabel,action:t,details:e,"x-sjppds-sessionid":this.sessionId})})}getTwMinCopy(t){if(!t)return;const e={term:{},q:t.q};if(t.$id)e.$id=t.$id;if(t.term){if(m(t.term.type)){if(t.term.id)e.term.id=t.term.id;if(t.term.name)e.term.name=t.term.name;if(t.term.type)e.term.type=t.term.type;if(t.term.values)e.term.values=t.term.values;if(t.term.groupsetting)e.term.groupsetting=t.term.groupsetting}else{e.term=structuredClone(t.term);if(t.term.type=="geneVariant"){delete e.term.groupsetting}}}return e}cacheTermQ(t,e){if(!e.reuseId)throw`missing term q.reuseId for term.id='${t.id}'`;this.app.dispatch({type:"cache_termq",termId:t.id,q:e})}async uncacheTermQ(t,e){await this.app.dispatch({type:"uncache_termq",term:t,q:e})}getCustomTermQLst(t){if(t.id){const e=this.state.reuse.customTermQ.byId[t.id]||{};const s=Object.values(e).map((t=>JSON.parse(JSON.stringify(t))));for(let t=s.length+1;t<1e3;t++){const e=`Setting #${t}`;if(!s.find((t=>t.reuseId===e))){s.nextReuseId=e;break}}if(!s.nextReuseId){s.nextReuseId=btoa((+new Date).toString()).slice(10,-3)}return s}else return[]}async addCustomTerm(t){await this.app.dispatch({type:"add_customTerm",obj:t})}async deleteCustomTerm(t){await this.app.dispatch({type:"delete_customTerm",name:t})}async getCustomTerms(){if(!Array.isArray(this.state.customTerms))return[];return this.state.customTerms.map((t=>t.tw))}async addGroup(t){await this.app.dispatch({type:"add_group",obj:t})}async deleteGroup(t){await this.app.dispatch({type:"delete_group",name:t})}async getGroups(){if(!Array.isArray(this.state.groups))return[];return this.state.groups}}const F=new Set(["categorical","integer","float","condition","survival","snplst","snplocus","geneVariant","samplelst","geneExpression",u.METABOLITE_INTENSITY,u.SINGLECELL_GENE_EXPRESSION,u.SINGLECELL_CELLTYPE,u.SNP]);function L(t,e,s,i){const n=e||{};if(typeof i?.usecase?.[use.target]=="function"){return i.usecase[use.target](t,use)}const a=new Set;const r=t.child_types||[];switch(n.target){case"barchart":case"summary":if(t.type&&t.type!=="survival")a.add("plot");if(G(r,["survival"]))a.add("branch");return a;case"matrix":if(t.type)a.add("plot");if(!t.isleaf)a.add("branch");return a;case"table":if(n.detail=="term")a.add("plot");if(r.length>1)a.add("branch");return a;case"sampleScatter":if(n.detail=="numeric"){if(f(t)){a.add("plot")}if(W(r))a.add("branch")}else{if(F.has(t.type))a.add("plot");if(!t.isleaf)a.add("branch")}return a;case"profile":if(!t.isleaf){a.add("branch");const e=t.id.split("__").length;if(e>2){a.add("plot")}}return a;case"boxplot":if(t.type=="float"||t.type=="integer")a.add("plot");if(n.detail==="term2"&&W(r))a.add("branch");return a;case"cuminc":if(n.detail=="term"){if(t.type=="condition")a.add("plot");if(r.includes("condition"))a.add("branch");return a}if(n.detail==="term2"||n.detail=="term0"){if(t.type&&t.type!="condition"&&t.type!="survival")a.add("plot");if(G(r,["condition","survival"]))a.add("branch");return a}case"survival":if(n.detail=="term"){if(t.type=="survival")a.add("plot");if(r.includes("survival"))a.add("branch");return a}if(n.detail==="term2"||n.detail=="term0"){if(t.type&&t.type!="survival")a.add("plot");if(G(r,["survival"]))a.add("branch");return a}case"regression":if(n.detail=="outcome"){if(n.regressionType=="linear"){if(t.type=="float"||t.type=="integer")a.add("plot");if(W(r))a.add("branch");return a}if(n.regressionType=="logistic"){if(t.type&&t.type!="survival")a.add("plot");if(G(r,["survival"]))a.add("branch");return a}else if(n.regressionType=="cox"){if(t.type=="condition"||t.type=="survival")a.add("plot");if(r.includes("condition")||r.includes("survival"))a.add("branch");return a}}if(n.detail=="independent"){if(t.type=="float"||t.type=="integer"||t.type=="categorical"||t.type=="samplelst")a.add("plot");if(U(r,["categorical","float","integer"]))a.add("branch");return a}case"filter":const e=s?.excludedTermtypeByTarget?.filter;if(e){if(F.has(t.type)&&!e.includes(t.type))a.add("plot");if(r.find((t=>!e.includes(t))))a.add("branch");return a}default:if(F.has(t.type))a.add("plot");if(!t.isleaf)a.add("branch");return a}}function G(t,e){if(!t.length){return false}if(!e?.length){return true}if(t.some((t=>!e.includes(t)))){return true}}function W(t){return t.includes("float")||t.includes("integer")}function U(t,e){for(const s of e){if(t.includes(s))return true}}class H extends P{async getTermdbConfig(){const t=await a("termdb/config",{body:{genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname}});if(t.error)throw t.error;this.termdbConfig=t.termdbConfig||{};return this.termdbConfig}async getTermChildren(t,e){let s;const i={genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(e){i.cohortValues=e.slice().sort().join(",")}if(this.state.treeFilter){i.treeFilter=this.state.treeFilter}if(t.__tree_isroot){i.default_rootterm=1;s=await a("termdb/rootterm",{body:i},this.opts.fetchOpts)}else{i.get_children=1;i.tid=t.id;s=await a("termdb/termchildren",{body:i},this.opts.fetchOpts)}if(s.error)throw s.error;for(const t of s.lst){if(t.type=="integer"||t.type=="float"){if(t.bins.rounding)t.bins.default.rounding=t.bins.rounding;if(t.bins.label_offset&&!t.bins.default.label_offset)t.bins.default.label_offset=t.bins.label_offset}}return s}async getNestedChartSeriesData(t){const[e,s]=this.getTdbDataUrl(t);const i=this.mayGetAuthHeaders("termdb");const n=await a(e,{headers:i,body:s},this.opts.fetchOpts);if(n.error)throw n.error;if(n.charts){for(const e of n.charts){this.mayFillInMissingCatValues(t.term0,e.chartId,e.total);for(const s of e.serieses){this.mayFillInMissingCatValues(t.term,s.seriesId,s.total);for(const e of s.data){this.mayFillInMissingCatValues(t.term2,e.dataId,e.total)}}}}return n}mayFillInMissingCatValues(t,e,s){if(!e)return;if(!(t?.id in this.missingCatValsByTermId))return;const i=this.missingCatValsByTermId[t.id];if(!(e in i.values)){i.values[e]={key:e,label:e};i.samplecount[e]={samplecount:0,key:e,label:e}}i.samplecount[e].samplecount+=s}getTdbDataUrl(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname};if(t.chartType=="cuminc")e.getcuminc=1;if(t.chartType=="survival")e.getsurvival=1;for(const s of["term0","term","term2"]){const i=this.getTwMinCopy(t[s]);if(!i)continue;const n=s=="term"?"term1":s;e[n+"_$id"]=i.$id;if("id"in i.term&&(!i.term?.type||m(i.term.type))){e[n+"_id"]=i.term.id}else{e[n]=i.term}if(!i.q)throw"plot."+s+".q{} missing: "+i.term.id;e[n+"_q"]=i.q}if(t.filter){const s=I(t.filter);if(s.lst.length){e.filter=s}}if(t.filter0)e.filter0=t.filter0;if("grade"in t)e.grade=t.grade;if("minSampleSize"in t)e.minSampleSize=t.minSampleSize;if(t.term2){const s={term1:t.term.q.hiddenValues?Object.keys(t.term.q.hiddenValues).map((e=>t.term.term.values?.[e]?.label||e)):[],term2:t.term2.q.hiddenValues?Object.keys(t.term2.q.hiddenValues).map((e=>t.term2.term.values?.[e]?.label||e)):[]};e.hiddenValues=s}if(t.get)e.get=t.get;return[t.chartType?"termdb":"termdb-barsql",e]}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[i,n]of["term0","term","term2"].entries()){const a=t[n];const r=!s[n]||s[n].term?.id===a?.term?.id;if(a=="genotype")continue;if(!a){if(n=="term")throw`missing plot.term{}`;continue}if(e.refs.bins){a.bins=e.refs.bins[i];if(e.refs.q&&e.refs.q[i]){if(!a.q)a.q={};const t=e.refs.q[i];if(t!==a.q||!r){if(t.type!=a.q.type||t.mode!=a.q.mode){for(const t in a.q){if(t!="hiddenValues"||!r)delete a.q[t]}}Object.assign(a.q,t)}}}if(!a.q)a.q={}}}async getRegressionData(t){if(!m(t.outcome.term.type))throw"outcome must be dictionary term";const e=this.getTwMinCopy(t.outcome);e.id=e.term.id;e.q=JSON.parse(JSON.stringify(t.outcome.q));e.type=e.term.type;if(!e.q.mode&&t.regressionType=="linear")e.q.mode="continuous";const s=["mode","scale"];e.refGrp=e.q.mode=="continuous"?"NA":t.outcome.refGrp;if(e.q.mode=="continuous"){for(const t in e.q){if(!s.includes(t))delete e.q[t]}}const i={getregression:1,genome:this.vocab.genome,dslabel:this.vocab.dslabel,regressionType:t.regressionType,outcome:e,independent:t.independent.map((t=>{const e=this.getTwMinCopy(t);e.refGrp=t.refGrp;e.interactions=t.interactions;const i=JSON.parse(JSON.stringify(e.q));delete i.values;delete i.totalCount;if(e.q.mode=="continuous"){for(const t in i){if(!s.includes(t))delete i[t]}}return{id:e.term.id,q:i,term:e.term,type:e.term.type,refGrp:e.q.mode=="continuous"?"NA":e.refGrp,interactions:e.interactions||[],values:e.term.values}}))};const n=I(t.filter);if(n.lst.length)i.filter=n;const r=await a("termdb",{body:i},this.opts.fetchOpts);if(r.error)throw r.error;return r}async findTerm(t,e="",s=null,i=""){const n={genome:this.vocab.genome,dslabel:this.vocab.dslabel,findterm:encodeURIComponent(t),cohortStr:e};if(s)n.usecase=s;if(this.state.treeFilter)n.treeFilter=this.state.treeFilter;if(i)n.targetType=i;const r=await a("termdb",{body:n});if(r.error)throw r.error;const o=t.toUpperCase();const l={equals:[],startsWith:[],startsWord:[],includes:[]};for(const t of r.lst){const e=t.name.toUpperCase();if(e===o)l.equals.push(t);else if(e.startsWith(o))l.startsWith.push(t);else if(e.includes(" "+o))l.startsWord.push(t);else l.includes.push(t)}r.lst=[...l.equals,...l.startsWith,...l.startsWord,...l.includes];return r}async getTermInfo(t){if(!t)throw".getTermInfo: Missing term id";const e=["genome="+this.vocab.genome+"&dslabel="+this.vocab.dslabel+"&getterminfo=1&tid="+t];const s=await a("/termdb?"+e.join("&"),{},this.opts.fetchOpts);if(s.error)throw s.error;return s}async getCohortSampleCount(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,cohort:t};const s=await a("termdb/cohort/summary",{body:e},this.opts.fetchOpts);if(!s)throw"missing data";if(s.error)throw s.error;return s.count}async getFilteredSampleList(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,getsamplelist:1,filter:typeof t=="string"?t:I(t)};const s=await a("termdb",{body:e},this.opts.fetchOpts);if(!s)throw`missing data`;if(s.error)throw s.error;if(!Array.isArray(s))throw"data is not array";return s}async getFilteredSampleCount(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,getsamplecount:1,filter:typeof t=="string"?t:I(t)};const s=await a("termdb",{body:e},this.opts.fetchOpts);if(!s)throw`missing data`;if(s.error)throw s.error;return s.count}async getViolinPlotData(t,e={}){const s=this.mayGetAuthHeaders("termdb");t.tw=this.getTwMinCopy(t.tw);if(t.divideTw)t.divideTw=this.getTwMinCopy(t.divideTw);const i=Object.assign({genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname,devicePixelRatio:window.devicePixelRatio,isKDE:"isKDE"in t?t.isKDE:true,ticks:t.ticks,datasymbol:t.datasymbol||"rug",orientation:t.orientation||"horizontal",radius:t.radius||3,svgw:t.svgw||200,unit:t.unit||"abs"},t,e);if(i.filter)i.filter=I(i.filter);const n=await a("termdb/violin",{headers:s,body:i});return n}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i={getpercentile:e,tid:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(s){i.filter=I(s)}return await a("termdb/getpercentile",{body:i})}async getDescrStats(t,e,s){const i={tw:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(s)i.logScale=true;if(e){if(e.filter)i.filter=I(e.filter);if(e.filter0)i.filter0=e.filter0}return await a("/termdb/descrstats",{body:i})}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i=e||this.state.vocab?.dslabel;const n=s||this.state.vocab?.genome;if(!i)throw"getTerms: dslabel missing";if(!n)throw"getTerms: genome missing";const r={genome:n,dslabel:i,ids:t,embedder:window.location.hostname};const o=await a(`termdb/termsbyids`,{body:r});if(o.error)throw"getTerm: "+o.error;for(const t in o.terms){const e=o.terms[t];if(e.type=="categorical"&&!e.values)this.missingCatValsByTermId[e.id]=e}return o.terms}async getterm(t,e=null,s=null){if(!t)throw"getterm: termid missing";const i=await this.getTerms([t],e,s);const n=i[t];if(!n)throw"no term found for "+t;return n}graphable(t){if(!t)throw"graphable: term is missing";return L(t).has("plot")}async getCategories(t,e,s={}){const i=this.mayGetAuthHeaders();if(t.type=="snplst"||t.type=="snplocus"){const t=Object.assign({validateSnps:1,sumSamples:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel},s);if(e){t.filter=I(e)}return await a("/termdb",{headers:i,body:t})}if(t.category2samplecount){const e=[];for(const s in t.category2samplecount){e.push({key:s,label:t?.values?.[s]?.label||s,samplecount:t.category2samplecount[s]})}return{lst:e}}const n={term:t,q:s.term1_q||{}};delete s.term1_q;const o={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tw:this.getTwMinCopy(n),...s};if(e){o.filter=I(e)}try{const t=await a("termdb/categories",{headers:i,body:o});if(t.error)r(t.error);return t}catch(t){window.alert(t.message||t)}}async getNumericUncomputableCategories(t,e){const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tid:t.id};if(e){s.filter=I(e)}try{const t=await a("/termdb/numericcategories",{body:s});if(t.error)throw t.error;return t}catch(t){window.alert(t.message||t)}}async validateSnps(t){const e=["validateSnps=1","genome="+this.state.vocab.genome,"dslabel="+this.state.vocab.dslabel];if(t.text){e.push("snptext="+encodeURIComponent(t.text))}else if(t.chr){e.push("chr="+t.chr);e.push("start="+t.start);e.push("stop="+t.stop);if(t.variant_filter)e.push("variant_filter="+encodeURIComponent(JSON.stringify(t.variant_filter)))}return await a("/termdb?"+e.join("&"))}async get_variantFilter(){return await a("termdb",{body:{getvariantfilter:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getSamplesPerFilter(t){return await a("termdb",{body:{for:"getSamplesPerFilter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,filters:t.filters}})}async getAnnotatedSampleData(t,e={}){const s=this.mayGetAuthHeaders("termdb");if(!s)return;const i=I(t.filter);const n={};const r={byTermId:e.byTermId||{},bySampleId:e.bySampleId||{}};const o=[];const l=new Set;const d=t.isHierCluster?null:t.terms.filter((t=>t.term.type==="geneVariant")).map((t=>t.term.chr?`${t.term.chr}:${t.term.start}-${t.term.stop}`:t.term.name)).sort();const c=t.terms.slice();let f=0;if(t.loadingDiv)t.loadingDiv.html("Updating data ...");while(true){const e=K(c,t.termsPerRequest||1);if(e.length==0)break;const p={headers:s,credentials:"include",body:{for:"matrix",genome:this.vocab.genome,dslabel:this.vocab.dslabel,terms:e.map(this.getTwMinCopy),filter:i,embedder:window.location.hostname}};if(t.signal)p.signal=t.signal;if(t.filter0)p.body.filter0=t.filter0;if(t.isHierCluster)p.body.isHierCluster=true;if(this.vocab.dslabel=="GDC"&&e.find((t=>t.term.id&&(!t.term?.type||m(t.term.type))))&&d?.length){p.body.currentGeneNames=d}o.push(a("termdb",p,{cacheAs:"decoded"}).then((s=>{if(s.error)throw s.error;if(!s.refs.bySampleId)s.refs.bySampleId={};for(const t of e){for(const e in s.samples){const i=s.samples[e];if(!Object.keys(i).filter((t=>t!="sample")).length)continue;l.add(e);if(!(e in n)){if(!s.refs.bySampleId[e])s.refs.bySampleId[e]={};if(typeof s.refs.bySampleId[e]=="string")s.refs.bySampleId[e]={label:s.refs.bySampleId[e]};const t=s.refs.bySampleId[e];if(!t.label)t.label=e;const i={sample:e,_ref_:t};n[e]=i}if(t.$id in i)n[e][t.$id]=i[t.$id]}for(const t in s.refs.bySampleId){r.bySampleId[t]=s.refs.bySampleId[t]}r.byTermId[t.$id]=t;if(t.$id in s.refs.byTermId){r.byTermId[t.$id]=Object.assign({},r.byTermId[t.$id],s.refs.byTermId[t.$id])}}f++;if(t.loadingDiv)t.loadingDiv.html(`Updating data (${f}/${o.length}) ...`)})))}try{if(t.loadingDiv)t.loadingDiv.html(`Updating data (0/${o.length})`);await Promise.all(o);if(t.loadingDiv)t.loadingDiv.html("")}catch(t){if(typeof t=="string"){t.toLowerCase();if(t.includes("token")||t.includes("jwt")||t.includes("login")||t.includes("sign")||t.includes("auth")||t.includes("credential")){this.tokenVerificationMessage=t}}throw t}try{if(t.loadingDiv)t.loadingDiv.html(`Processing data ...`);const e=t.terms.filter((t=>m(t.term.type))).map((t=>t.$id));const s=[];if(!e.length){s.push(...Object.values(n))}else{for(const t in n){const i=n[t];for(const t in i){if(e.includes(t)){s.push(i);break}}}if(!s.length&&this.termdbConfig?.matrix?.settings?.displayDictRowWithNoValues){s.push(...Object.values(n))}}const i=new RegExp(t.sampleNameFilter||".*");const a={lst:s.filter((t=>l.has(t.sample)&&i.test(t.sample))),refs:r};a.samples=a.lst.reduce(((t,e)=>{t[e.sample]=e;return t}),{});for(const e of t.terms){z(e,a.lst,this.termdbConfig)}return a}catch(t){throw t}}async getTermTypes(t){const e={body:{for:"termTypes",genome:this.vocab.genome,dslabel:this.vocab.dslabel,ids:JSON.stringify(t)}};const s=await a("termdb",e,this.opts.fetchOpts);if(s.error)throw s.error;return s}async getLDdata(t,e){const s={getLDdata:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,ldtkname:t,m:{chr:e.chr,pos:e.pos,ref:e.ref,alt:e.alt}};return await a("termdb",{body:s})}async getScatterData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"scatter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,plotName:t.name,coordTWs:t.coordTWs.map((t=>this.getTwMinCopy(t))),filter:I(t.filter),filter0:t.filter0,embedder:window.location.hostname};if(t.colorColumn)s.colorColumn=t.colorColumn;if(t.colorTW)s.colorTW=this.getTwMinCopy(t.colorTW);if(t.shapeTW)s.shapeTW=this.getTwMinCopy(t.shapeTW);if(t.divideByTW)s.divideByTW=this.getTwMinCopy(t.divideByTW);if(t.scaleDotTW)s.scaleDotTW=this.getTwMinCopy(t.scaleDotTW);return await a("termdb",{headers:e,body:s})}async getDefaultBins(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"getDefaultBins",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tw:t.tw,embedder:window.location.hostname};const i=this.opts?.state?.termfilter;if(i){if(i.filter)s.filter=I(i.filter);if(i.filter0)s.filter0=i.filter0}return await a("termdb",{headers:e,body:s})}async setTermBins({term:t,q:e}){const s=await this.getDefaultBins({tw:{term:t,q:e}});if("error"in s)throw s.error;t.bins=s;if(e.mode=="discrete"&&!e.type){const s=e.mode;for(const t in e){if(t!="isAtomic")delete e[t]}Object.assign(e,t.bins.default);e.mode=s}}async getSingleSampleData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"singleSampleData",sampleId:t.sampleId,term_ids:t.term_ids,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const i=await a("termdb",{headers:e,body:s});const n={};if("error"in i)return i;for(const t of i){const e=JSON.parse(t.jsondata);n[t.term_id]={value:t.value,term:e}}return n}async getAllSamples(){const t=this.mayGetAuthHeaders("termdb");const e={for:"getAllSamples",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});return s}async getSamplesByName(t){const e=this.mayGetAuthHeaders("termb");const s={for:"getSamplesByName",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};if(t?.filter)s.filter=t.filter;const i=await a("termdb",{headers:e,body:s});return i}async getProfileFacilities(){const t=this.mayGetAuthHeaders("termb");const e={for:"getProfileFacilities",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});const i=[];for(const t of s)i.push(t.name);return i}async getLowessCurve(t){const e=this.mayGetAuthHeaders("termb");const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,getLowessCurve:1,coords:t.coords};return await a("termdb",{headers:e,body:s})}async getCohortsData(t){const e={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel};return await a("termdb/cohorts",{body:e})}async getMds3queryDetails(){return await a("termdb",{body:{for:"mds3queryDetails",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getMatrixByName(t){return await a("termdb",{body:{for:"matrix",getPlotDataByName:t,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getTopMutatedGenes(t){return await a("gdc/topMutatedGenes",{method:"GET",body:t})}async getTopVariablyExpressedGenes(t){return await a("termdb/topVariablyExpressedGenes",{method:"GET",body:t})}async getTopTermsByType(t){t.genome=this.state.vocab.genome;t.dslabel=this.state.vocab.dslabel;return await a("termdb/getTopTermsByType",{method:"GET",body:t})}async getSampleImages(t){const e={};e.genome=this.state.vocab.genome;e.dslabel=this.state.vocab.dslabel;e.sampleId=t;return await a("termdb/getSampleImages",{method:"GET",body:e})}async convertSampleId(t,e){const s=new Map;const i=[];for(const n of t){const t={};i.push(t);for(const i of e){if(!("to"in i))i.to=i.from;if(!i.convert){t[i.to]=n[i.from];continue}if(!s.has(i))s.set(i,{});const e=s.get(i);const a=n[i.from];if(!e[a])e[a]=[];e[a].push({obj:t,sample:n})}}const n=[];for(const[t,e]of s){const s=Object.keys(e);n.push(await a("termdb",{body:{for:"convertSampleId",inputs:s,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}}).then((i=>{for(const n of s){for(const{sample:s,obj:a}of e[n]){a[t.to]=i.mapping[n]}}})))}await Promise.all(n);return i}}function z(t,e,s){if(t.term.type!="categorical"){return}if(!("$id"in t)){return}const i={};const n={};for(const s of e){if(!s[t.$id])continue;const e=s[t.$id].key;i[e]=1+(i[e]||0);n[e]={key:e,label:e}}t.term.category2samplecount=i;if(s.alwaysRefillCategoricalTermValues||!t.term.values||Object.keys(t.term.values).length==0){t.term.values=n}}function K(t,e){const s=[];let i=0,n=t.length;while(i<n){i++;const n=t.shift();if(s.find((t=>t.term.type===n.term.type&&(("id"in t.term||"id"in n.term)&&t.term.id===n.term.id||t.term.name===n.term.name)))){t.push(n)}else{s.push(n)}if(s.length>=e)break}return s}function X(t,e,s){const i=!e?[]:e.type=="tvslst"?e.lst:[e];let n=0;for(const a of i){if(a.type=="tvslst"){if(X(t,a)){n++}}else{const e=a.tvs;let i;if(e.term.type=="geneVariant"){i=s.map((e=>t[e])).filter((t=>t))}else if(e.term.type=="integer"||e.term.type=="float"||e.term.type==u.GENE_EXPRESSION||e.term.type==u.METABOLITE_INTENSITY){i=t[e.term.id]||t[e.term.$id]?.key}else if(e.term.type=="survival"){i=t[e.term.$id]?.key}else{i=t[e.term.id]||t[e.term.$id]?.value}let r;if(e.term.type=="categorical"){if(i===undefined){if(e.isnot)r=!r;if(r)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));r=t.has(i)}else if(e.term.type=="integer"||e.term.type=="float"||e.term.type==u.GENE_EXPRESSION||e.term.type==u.METABOLITE_INTENSITY){if(i===undefined){if(e.isnot)r=!r;if(r)n++;continue}for(const t of e.ranges){if("value"in t){r=i===t.value;if(r)break}else if(i==t.name){r=true;break}else{if(e.term.values){const t=e.term.values[i.toString()];if(t&&t.uncomputable){continue}}let s,n;if(t.startunbounded){s=true}else if("start"in t){if(t.startinclusive){s=i>=t.start}else{s=i>t.start}}if(t.stopunbounded){n=true}else if("stop"in t){if(t.stopinclusive){n=i<=t.stop}else{n=i<t.stop}}r=s&&n}if(r)break}}else if(e.term.type=="condition"){const t=getPrecomputedKey(e);const s=i&&i[t];if(s){r=Array.isArray(s)?e.values.find((t=>s.includes(t.key))):e.values.find((t=>t.key==s))}}else if(e.term.type=="survival"){if(i===undefined){if(e.isnot)r=!r;if(r)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));r=t.has(i)}else if(e.term.type=="geneVariant"&&e.legendFilterType=="geneVariant_hard"){const t=e.values[0];r=i.find((e=>{for(const s of e.values){if(s.dt==t.dt&&(!s.origin||s.origin==t.origin)&&t.mclasslst.includes(s.class))return true}}))&&true}else if(e.term.type==u.SINGLECELL_GENE_EXPRESSION);else{throw"unknown term type"}if(e.isnot){r=!r}if(r)n++}if(e.join=="or"&&n)return true}if(n==i.length)return true}function Y(t,e){const s=JSON.parse(JSON.stringify(t));if(!s.term1)s.term1=s.term?s.term:{};if(!s.term1_q)s.term1_q={};if(!s.term0)s.term0={};if(!s.term0_q)s.term0_q={};if(!s.term2)s.term2={};if(!s.term2_q)s.term2_q={};if(!s.filter)s.filter={type:"tvslst",join:"",lst:[]};const i=Z(s,e);return i.tree.results}const Q=JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"_2:maxAcrossCharts":"=maxAcrossCharts()",charts:[{chartId:"@key",total:"+1","_1:maxSeriesTotal":"=maxSeriesTotal()","@done()":"=filterEmptySeries()",serieses:[{total:"+1",seriesId:"@key",max:"<&idVal.dataVal","~values":["&idVal.dataVal",0],"~sum":"+&idVal.dataVal","__:boxplot":"=boxplot()","~samples":["$sample","set"],data:[{dataId:"@key",total:"+1"},"&idVal.dataId[]"]},"&idVal.seriesId[]"]},"&idVal.chartId[]"],"~sum":"+&idVal.seriesVal","~values":["&idVal.seriesVal",0],"__:boxplot":"=boxplot()",refs:{cols:["&idVal.seriesId[]"],colgrps:["-"],rows:["&idVal.dataId[]"],rowgrps:["-"],col2name:{"&idVal.seriesId[]":{name:"@branch",grp:"-"}},row2name:{"&idVal.dataId[]":{name:"@branch",grp:"-"}},"__:useColOrder":"=useColOrder()","__:useRowOrder":"=useRowOrder()","__:bins":"=bins()","@done()":"=sortColsRows()"},"@done()":"=sortCharts()"}});function Z(t,e){const s={categorical:tt,integer:et,float:et,undefined:st};return new y({data:e,seed:`{"values": []}`,template:Q,"=":{idVal(i,n){const[a,r]=s[t.term0.type](i.data,t.term0,t.term0_q,e);const[o,l]=s[t.term1.type](i.data,t.term1,t.term1_q,e);const[d,c]=s[t.term2.type](i.data,t.term2,t.term2_q,e);return{chartId:a,chartVal:r,seriesId:o,seriesVal:l,dataId:d,dataVal:c}},prep(e){return X(e.data,t.filter)},maxSeriesTotal(t,e){let s=0;for(const t of e.self.serieses){if(t&&t.total>s){s=t.total}}return s},maxAcrossCharts(t,e){let s=0;for(const t of e.self.charts){if(t.maxSeriesTotal>s){s=t.maxSeriesTotal}}return s},boxplot(t,e){if(!e.self.values||!e.self.values.length)return;const s=e.self.values.filter((t=>t!==null&&!isNaN(t)));if(!s.length)return;s.sort(((t,e)=>t-e));const i=it(s.map((t=>({value:+t}))));i.mean=e.self.sum/s.length;let n=0;for(const t of s){n+=Math.pow(t-i.mean,2)}i.sd=Math.sqrt(n/(s.length-1));if(isNaN(i.sd))i.sd=null;return i},numSamples(t,e){return e.self.samples.size},filterEmptySeries(t){const e=t.serieses.filter((t=>t.total));t.serieses.splice(0,t.serieses.length,...e)},sortColsRows(e){if(t.term1_q.orderedLabels){const s=t.term1_q.orderedLabels;e.cols.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}if(t.term2.orderedLabels){const s=t.term2_q.orderedLabels;e.rows.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}},sortCharts(t){},useColOrder(){return t.term1_q.orderedLabels&&t.term1_q.orderedLabels.length>0},useRowOrder(){return t.term2_q.orderedLabels&&t.term2_q.orderedLabels.length>0},bins(){return[t.term0_q,t.term1_q,t.term2_q].map((t=>t.computed_bins))},q(){}}})}function tt(t,e){const s="id"in e?t[e.id]:"-";const i="id"in e&&o(t[e.id])?+t[e.id]:0;return[[s],i]}function et(t,e,s,i){if(!("id"in e)||!(e.id in t))return[[],undefined];if(!s.computed_bins){const t={};i.map((s=>{if(!o(s.data[e.id]))return;const i=+s.data[e.id];if(!("min"in t)||t.min>i)t.min=i;if(!("max"in t)||t.max<i)t.max=i}));s.computed_bins=b(s,(e=>t));s.orderedLabels=s.computed_bins.map((t=>t.label))}const n=t[e.id];if(e.values&&n in e.values&&e.values[n].uncomputable){return[[e.values[n].label],undefined]}if(o(t[e.id])){const t=[];for(const e of s.computed_bins){if(e.startunbounded){if(n<e.stop){t.push(e.label)}else if(e.stopinclusive&&n===e.stop){t.push(e.label)}}else if(e.stopunbounded){if(n>e.start){t.push(e.label)}else if(e.stopinclusive&&n===e.start){t.push(e.label)}}else if((n>e.start||n===e.start&&e.startinclusive)&&(n<e.stop||n===e.stop&&e.stopinclusive)){t.push(e.label)}if(t.length)break}return[t,n]}return[[],undefined]}function st(){return[["-"],undefined]}function it(t){const e=t.length;if(e<5){return{out:t}}const s=t[Math.floor(e/2)].value;const i=t[Math.floor(e/4)].value;const n=t[Math.floor(e*3/4)].value;const a=t[Math.floor(e*.05)].value;const r=t[Math.floor(e*.95)].value;t[Math.floor(e*.01)].value;const o=n-i;let l,d;if(o==0){l=0;d=0}else{const s=t.findIndex((t=>t.value>i-o*1.5));l=t[s==-1?0:s].value;const a=t.findIndex((t=>t.value>n+o*1.5));d=t[a==-1?e-1:Math.max(0,a-1)].value}const c=t.filter((t=>t.value<i-o*1.5||t.value>n+o*1.5));return{w1:l,w2:d,p05:a,p25:i,p50:s,p75:n,p95:r,iqr:o,out:c}}function nt(t,e){if(!e||!e.length){return{lst:Object.keys(t.term.values).map((e=>({key:e,label:t.term.values[e].label,value:e})))}}const s=new y({data:e,template:JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"&idVal.id":{samplecount:"+1",":__key":"&idVal.id",":__label":"&idVal.id",":__value":"&idVal.id"}}}),"=":{prep(e){return X(e.data,t.filter)},idVal(e,s){const[i,n]=tt(e.data,t.term);return{id:i[0],value:n}}}});return{lst:Object.values(s.tree.results)}}var at=Object.freeze({__proto__:null,getBarchartData:Y,getCategoryData:nt});function rt(t,e){t.sort(((t,e)=>t-e));const s=Math.abs(e/100*t.length-1);const i=Number.isInteger(s)?(t[s]+t[s+1])/2:t[Math.ceil(s)];return i}class ot extends P{constructor(t){super(t);this.datarows=[];if(t.state.vocab.sampleannotation){const e=t.state.vocab.sampleannotation;Object.keys(e).forEach((t=>this.datarows.push({sample:t,data:e[t]})))}}getTermdbConfig(){return{selectCohort:this.vocab.selectCohort,supportedChartTypes:[]}}getTermChildren(t,e){const s=(e||[]).slice().sort().join(",");const i=t.__tree_isroot?null:t.id;return{lst:this.vocab.terms.filter((t=>t.parent_id===i&&(!s.length||s===t.cohortValues.slice().sort.join(","))))}}async getNestedChartSeriesData(t){const e={term1:t.term?t.term.term:{},term1_q:t.term?t.term.q:undefined,term0:t.term0?t.term0.term:undefined,term0_q:t.term0?t.term0.q:undefined,term2:t.term2?t.term2.term:undefined,term2_q:t.term2?t.term2.q:undefined,filter:this.state.termfilter&&this.state.termfilter.filter};return Y(e,this.datarows)}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[s,i]of["term0","term","term2"].entries()){const n=t[i];if(n=="genotype")return;if(!n){if(i=="term")throw`missing plot.term{}`;return}if(e.refs.bins){n.bins=e.refs.bins[s];if(e.refs.q&&e.refs.q[s]){if(!n.q)n.q={};const t=e.refs.q[s];if(t!==n.q){for(const t in n.q)delete n.q[t];Object.assign(n.q,t)}}}if(!n.q)n.q={}}}async findTerm(t,e,s=null){return{lst:this.vocab.terms.filter((s=>s.name.includes(t)&&(!e||e===s.cohortValues.slice().sort.join(","))))}}async getTermInfo(e){const s=this.vocab.find((t=>t.id===e));if(!s)return undefined;return{terminfo:t.info}}async getCohortSampleCount(t){if(!t)return;const e=this.vocab.find((t=>t.id===id));if(!e||!e.cohortValues.includes(t))return;if(!e.samplecount)e.samplecount={};if(!(t in e.samplecount)){e.samplecount[t]=Object.keys(this.vocab.sampleannotation).length}return{samplecount:e.samplecount[t]}}async getCohortsData(t){return null}async getFilteredSampleCount(t){return"TBD"}async getDensityPlotData(t,e,s){if(!this.datarows||!this.datarows.length){const e=this.vocab.terms.find((e=>e.id===t));e.range&&e.range;return{minvalue:e.range&&e.range.start,maxvalue:e.range&&e.range.stop}}const i=[];const n=new Set;let a,r,d=0;let c={};for(const t of this.datarows){if(c[t.sample])continue;const e=t.s||t.data;if(e&&X(e,s)){c[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in c){if(!(t in this.vocab.sampleannotation[e]))continue;const s=this.vocab.sampleannotation[e][t];if(o(s)){const t=+s;d+=1;if(a===undefined||t<a)a=t;if(r===undefined||t>r)r=t;i.push(t);n.add(t)}}const f=this.vocab.terms.find((e=>e.id==t));const p=40;const m=f.type=="integer"&&r-a<p?r-a:f.type=="float"&&n.size<p?n:p;const u=l().domain([a,r]).range([e.plot_size.xpad,e.plot_size.width-e.plot_size.xpad]);const h=lt(u.ticks(m))(i);return{density:h,densitymax:h.reduce(((t,e,s)=>s===0||e[1]>t?e[1]:t),0),minvalue:a,maxvalue:r,samplecount:d}}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i=[];const n=[];const a={};for(const t of this.datarows){if(a[t.sample])continue;const e=t.s||t.data;if(e&&X(e,s)){a[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in a){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";n.push(s)}n.sort(((t,e)=>t-e));for(const t of e){const e=Math.abs(t/100*n.length-1);const s=Number.isInteger(e)?(n[e]+n[e+1])/2:n[Math.ceil(e)];i.push(s)}return{values:i}}async getDescrStats(t,e,s){const i=[];const n={};for(const t of this.datarows){if(n[t.sample])continue;const s=t.s||t.data;if(s&&X(s,e)){n[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in n){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";i.push(s)}i.sort(((t,e)=>t-e));const a=i.length;const r=i.reduce(((t,e)=>t+e),0);const o=r/a;const l=rt(i,25);const d=rt(i,50);const c=rt(i,75);const f=i.map((t=>(t-o)**2)).reduce(((t,e)=>t+e),0);const p=f/(i.length-1);const m=Math.sqrt(p);const u=Math.min(...i);const y=Math.max(...i);return{values:[{id:"total",label:"n",value:a},{id:"min",label:"Minimum",value:h(u,2)},{id:"p25",label:"1st quartile",value:h(l,2)},{id:"median",label:"Median",value:h(d,2)},{id:"mean",label:"Mean",value:h(o,2)},{id:"p75",label:"3rd quartile",value:h(c,2)},{id:"max",label:"Maximum",value:h(y,2)},{id:"sd",label:"Standard deviation",value:h(m,2)}]}}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i={};for(const e of t){const t=this.vocab.terms.find((t=>t.id===e));if(t)i[e]=t}return i}async getterm(t){if(!t)throw"getterm: termid missing";return this.vocab.terms.find((e=>e.id==t))}async getCategories(t,e,s=null){const i={term:t,filter:e};const n=nt(i,this.datarows);return n}getNumericUncomputableCategories(t,e){throw"to be implemented!! getNumericUncomputableCategories"}graphable(t){if(!t)throw"graphable: term is missing";return L(t).has("plot")}q_to_param(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}}function lt(t){return e=>{const s=[];for(let e=0;e<t.length;e++)s.push([t[e],0]);for(const i of e){for(let e=1;e<t.length;e++){if(i<=t[e]){s[e-1][1]++;break}}}return s}}function dt(t){if(t.vocab&&!t.state){t.state={vocab:t.vocab}}if(!t.state)throw"missing opts.state";if(!t.state.vocab){t.state.vocab=t.vocab?t.vocab:{}}const e=t.state.vocab;if(t.state.genome){e.genome=t.state.genome;delete t.state.genome}if(t.state.dslabel){e.dslabel=t.state.dslabel;delete t.state.dslabel}if(e.dslabel){return new H(t)}else if(e.terms){return new ot(t)}}function ct(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}function ft({samples:t,sample_attributes:e}){const s={__root:{id:"root",name:"root",__tree_isroot:true}};const i={};for(const n of t){const t=n.sample;if(!i[t])i[t]={};Object.assign(i[t],n.s);for(const t in n.s){if(!s[t]){const i=e[t]&&e[t].label?e[t].label:t;s[t]={id:t,name:i,parent_id:null,type:e[t].type=="float"?"float":e[t].type=="integer"?"integer":"categorical",values:{},isleaf:true}}const i=s[t];if(!("id"in i))i.id=t;if(!("parent_id"in i))i.parent_id=null;if(!("values"in i))i.values={};if(!("isleaf"in i))i.isleaf=true;if(!i.computableVals&&(i.type=="float"||i.type=="integer")){i.computableVals=[]}const a=n.s[t];if(i.type=="categorical"){i.groupsetting={disabled:true};if(!(a in i.values)){i.values[a]={key:a,label:a}}}else if(i.type=="integer"||i.type=="float"){if(a==="Not Available"&&!(a in i.values)){i.values[a]={label:a,uncomputable:true}}if(!(a in i.values)){if(!o(n.s[t]))throw`non-numeric term value='${a}' for term='${t}'`;n.s[t]=Number(n.s[t]);const e=n.s[t];i.computableVals.push(e)}}else if(i.type=="condition");else if(i.type==u.SINGLECELL_GENE_EXPRESSION);else{throw"Term type not supported:"+i.type}}}for(const t in s){const e=s[t];if((e.type=="integer"||e.type=="float")&&!e.bins){e.bins={default:B(e.computableVals)};delete e.computableVals}}return{sampleannotation:i,terms:Object.values(s)}}var pt=Object.freeze({__proto__:null,vocabInit:dt,q_to_param:ct,getVocabFromSamplesArray:ft});const mt={joinWith:["and","or"]};class ut{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,controlsTip:new e({padding:"0px",parent_menu:this.opts.holder.node()&&this.opts.holder.node().closest(".sja_menu_div")}),treeTip:new e({padding:"5px",offsetX:20,offsetY:-34,clearSelector:".sja_term_src_body"})};this.durations={exit:500};this.lastId=0;this.categoryData={};this.pills={};E(this);$(this);this.initUI();this.filter={type:"tvslst",tag:"filterUiRoot",join:"and",in:true,lst:[]};this.promises={}}validateOpts(t){const e=Object.assign({},mt,t);if(!e.holder)throw".holder missing";if(e.vocabApi){this.vocabApi=e.vocabApi}else{if(!e.vocab)throw".vocab missing";if(e.vocab.dslabel){if(!e.vocab.genome)throw"vocab.genome missing"}else{if(!e.vocab.terms)throw"vocab.terms missing"}}if(typeof e.callback!="function")throw".callback() is not a function";if(e.getVisibleRoot&&typeof e.getVisibleRoot!="function")throw".getVisibleRoot() must be a function if set as an option";if(!e.emptyLabel)e.emptyLabel="+NEW";return e}async main(t,e={}){this.promises.postRender=new Promise(((t,e)=>{this.mainResolve=t;this.mainReject=e}));this.numProcessedItems=0;this.numExpectedItems=0;this.opts=Object.assign({},this.opts,e);this.activeCohort=this.opts.activeCohort;this.rawCopy=t;this.rawFilter=JSON.parse(this.rawCopy);this.validateFilter(this.rawFilter);this.filter=N(this.rawFilter,"filterUiRoot");if(!this.filter){this.filter=this.rawFilter;this.filter.tag="filterUiRoot"}await this.resetActiveData(this.filter);this.removeBlankPill();this.dom.newBtn.style("display",this.opts.newBtn?"":this.filter.lst.length==0?"inline-block":"none");this.dom.holder.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay);this.setVocabApi();this.updateUI(this.dom.filterContainer,this.filter);return this.promises.postRender}validateFilter(t){if(!("$id"in t))t.$id=this.lastId++;else if(this.lastId<=t.$id)this.lastId=t.$id+1;if(!("type"in t))throw"missing filter.type";if(t.type!="tvs"&&t.type!="tvslst")throw"invalid filter.type";if(t.type!="tvslst")return;if(!Array.isArray(t.lst))throw"invalid or missing filter.lst[]";if(t.lst.length>1){if(t.join!="and"&&t.join!="or")throw"invalid filter.join value for lst.length > 1"}else if(t.join!==""){throw"filter.join must be an empty string when lst.length < 2"}if(!t.lst.length)t.in=true;for(const[e,s]of t.lst.entries()){this.validateFilter(s)}}resetActiveData(t){if(this.dom.controlsTip.d.style("display")=="none"){this.activeData={item:{},filter:{}}}else{this.activeData={item:S(t,this.activeData.item.$id),filter:S(t,this.activeData.filter.$id),menuOpt:this.activeData.menuOpt}}}refresh(t){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=JSON.parse(JSON.stringify(this.rawFilter));delete e.tag;t.tag="filterUiRoot";const s=k(e,this.filter.$id);if(!s||this.rawFilter.$id===this.filter.$id){this.api.main(t);this.opts.callback(t)}else{const i=s.lst.findIndex((t=>t.$id==this.filter.$id));s.lst[i]=t;this.api.main(e);this.opts.callback(t)}}getId(t){return t.$id}getFilterExcludingPill(t){const e=JSON.parse(JSON.stringify(this.rawFilter));const s=k(e,t);const i=s.lst.findIndex((e=>e.$id===t));if(i==-1)return null;s.lst.splice(i,1);return I(e)}getAdjustedRoot(t,e){const s=JSON.parse(JSON.stringify(this.rawFilter));if(e=="and")return s;const i=N(s,"cohortFilter");const n=k(s,t);if(!n){return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]}}const a=n.lst.findIndex((t=>t.$id===n.$id));if(a==-1)return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]};n.lst.splice(a,1);if(i&&!n.lst.find((t=>t===i))){return I({type:"tvslst",join:"and",lst:[i,n]})}return I(n)}setVocabApi(){if(!this.vocabApi){const t={getState:()=>{const t=JSON.parse(this.rawCopy);const e=N(t,"cohortFilter");if(e&&this.opts.termdbConfig){e.tvs.values=this.activeCohort==-1||this.activeCohort===undefined?[]:this.opts.termdbConfig.selectCohort.values[this.activeCohort].keys.map((t=>({key:t,label:t})))}return{vocab:this.opts.vocab,termfilter:{filter:t},tree:{plots:{}}}}};const e=t.getState();const s=e.vocab||{genome:e.genome,dslabel:e.dslabel};if(!this.vocabApi){this.vocabApi=dt({app:t,state:{vocab:s}})}}this.vocabApi.main()}updatePromise=function(t=1){if(!this.mainResolve)return;this.numProcessedItems+=t;if(this.numExpectedItems==this.numProcessedItems){this.mainResolve();if(this.bus)this.bus.emit("postRender");delete this.mainResolve}}}class ht extends ut{constructor(t){super(t);this.type="filter";this.initHolder()}async preApiFreeze(t){t.main=this.main.bind(this);t.getNormalRoot=()=>I(this.rawFilter)}getState(t){return{termfilter:t.termfilter,activeCohort:t.activeCohort}}async main(t=null){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=this.state&&this.state.termfilter;if(!e){this.dom.holder.style("display","none");return}this.dom.holder.style("display","inline-block");const s=JSON.stringify(t||e.filter);super.main(s,{activeCohort:this.state.activeCohort})}initHolder(){const t=this.dom.holder.attr("class","filter_div").style("position","relative").style("width","fit-content").style("margin","10px").style("margin-top","5px").style("display","table").style("border",this.opts.hideLabel?"none":"solid 1px #ddd");if(this.opts.hideLabel){this.dom.filterDiv=t.style("display","inline-block").style("padding","5px 10px")}else{t.append("span").text("Filter").style("padding","0 10px");this.dom.filterDiv=t.append("div").style("display","inline-block").style("padding","5px 10px")}}}const yt=d(ht);export{ut as F,N as a,yt as b,A as c,x as d,ft as e,k as f,I as g,X as h,L as i,at as j,pt as k,j as s,dt as v};
@@ -0,0 +1 @@
1
+ import{i as t,X as i}from"./app-488d9fd6.js";import{F as s,g as o}from"./FilterRxComp-cb149666.js";class r extends s{constructor(t){super(t);this.api={main:this.main.bind(this),getNormalRoot:()=>o(this.rawFilter),getPromise:t=>this.promises[t]};if(t.callbacks){this.events=["postInit","postRender","firstRender"];this.bus=new i(this.api,this.events,t.callbacks)}}async main(t,i={}){this.dom.controlsTip.hide();this.dom.treeTip.hide();const s="activeCohort"in i?i.activeCohort:this.activeCohort;const o=JSON.stringify(t);if(this.rawCopy==o&&JSON.stringify(this.activeCohort)==JSON.stringify(s))return;await super.main(o,i)}}const e=t(r);export{e as f};