@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{p as t,bY as e,ac as n,Z as a,am as s,bZ as o,b_ as l,c as i,x as r,aa as c,a as p,q as d,a9 as f,b$ as m,j as u,ap as h,aq as g,ar as b,as as k,at as v,ak as x,z as y,ae as _,aN as w,aA as A,c0 as j,v as M,b as z,b6 as L,b7 as S,I as N,ah as U,ag as q,d as B,a8 as C,B as E,an as R,r as V,aW as I,bw as O,f as F,a7 as H,ao as P,ad as T,M as D,be as Y,bb as G}from"./app-3d14cbe4.js";import{a as X,s as J,u as Z,m as W,i as $}from"./block.mds.expressionstat-2c396bb9.js";import{s as K}from"./legacy-d3-polyfill-bdb2d792.js";import{l as Q}from"./block.legend-3dbc41a8.js";import{c as tt,d as et}from"./axis-747c801e.js";import{l as nt}from"./log-0ea548ec.js";import{v as at}from"./vcf-e43b533a.js";import{r as st,c as ot}from"./block.mds.svcnv.share-766e4b22.js";import"./partition-db811f6b.js";import"./arc-3d6751aa.js";import"./constant-426a1483.js";import"./math-2fb199c6.js";const lt="svcnv";const it="vcf";const rt="expression";async function ct(t){const{feature:n,tk:p,block:d,limitsamplebyeitherannotation:f,limitbysamplesetgroup:m}=t;const u=a({x:100,y:100,close:()=>{e(u.pane,p.config_handle);u.pane.style("display","none")}});if(f){const t=f[0];if(t){u.header.html('<span style="font-size:.8em;opacity:.5">'+p.name+"</span> "+t.value)}}else if(m){u.header.html('<span style="font-size:.8em;opacity:.5">'+p.name+"</span> "+m.name)}else{u.header.text(p.name)}const h={debugmode:d.debugmode,genome:d.genome,features:[n],hostURL:d.hostURL,limitsamplebyeitherannotation:f,limitbysamplesetgroup:m,jwt:d.jwt,holder:u.body.append("div").style("margin","20px")};if(p.iscustom){h.iscustom=1;h.querykey2tracks={};h.querykey2tracks[lt]={type:s.mdssvcnv,file:p.file,url:p.url,indexURL:p.indexURL};if(p.checkexpressionrank){h.querykey2tracks[rt]={type:s.mdsexpressionrank};for(const t in p.checkexpressionrank){h.querykey2tracks[rt][t]=p.checkexpressionrank[t]}}if(p.checkvcf){h.querykey2tracks[it]={type:s.mdsvcf};for(const t in p.checkvcf){if(t=="stringifiedObj")continue;h.querykey2tracks[it][t]=p.checkvcf[t]}}}else{h.dslabel=p.mds.label}if(window.location.search.includes("smx=3")){h.client=o;h.common=l;h.string2pos=i;h.invalidcoord=r;h.block=import("./block-944afb9f.js").then((function(t){return t.c}));const t=await c();t.dthm(h).then((t=>{t._pane=u;p.samplematrices.push(t)}))}else{import("./samplematrix-3556e5c0.js").then((t=>{const e=new t.Samplematrix(h);e._pane=u;p.samplematrices.push(e)}))}}function pt(a,s){if(!a.samplematrices||a.samplematrices.length==0)return;const o=a.tkconfigtip.d.append("table").style("margin-bottom","5px");for(const s of a.samplematrices){const l=o.append("tr");{const a=[];if(s.limitsamplebyeitherannotation){const t=s.limitsamplebyeitherannotation[0];a.push(t.value)}else if(s.limitbysamplesetgroup){a.push(s.limitbysamplesetgroup.name)}else{a.push("Any sample")}const o=s.features.length;a.push(o+" feature"+(o>1?"s":""));a.push(s.samples.length+" samples");const i=l.append("td").append("div").attr("class","sja_menuoption").style("border","solid 1px #ededed").text(a.join(", "));if(s._pane.pane.style("display")=="none"){i.style("border-color","black")}i.on("click",(()=>{if(s._pane.pane.style("display")=="none"){t(s._pane.pane);e(i,s._pane.pane);i.style("border-color","#ededed")}else{e(s._pane.pane,i);n(s._pane.pane);i.style("border-color","black")}}))}{l.append("td").attr("class","sja_menuoption").html("&times;").on("click",(()=>{l.remove();s._pane.pane.remove();for(const[t,e]of a.samplematrices.entries()){if(s.limitsamplebyeitherannotation){if(e.limitsamplebyeitherannotation){const n=s.limitsamplebyeitherannotation[0];const o=e.limitsamplebyeitherannotation[0];if(n.key==o.key&&n.value==o.value){a.samplematrices.splice(t,1);return}}}else{if(!e.limitsamplebyeitherannotation){a.samplematrices.splice(t,1);return}}}}))}}}async function dt(t,e){if(t.iscustom)return;if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","15px");const s=n.append("input").attr("size",20).attr("placeholder","Find sample");const o=n.append("div").style("margin-top","10px");s.on("keyup",p.debounce(l,300));async function l(){o.selectAll("*").remove();const n=s.property("value").trim();if(!n)return;const l={genome:e.genome.name,dslabel:t.mds.label,querykey:t.querykey,findsamplename:n};try{const n=await d("mdssvcnv",l);if(n.error)throw n.error;if(!n.result)return;for(const s of n.result){const n=o.append("div");n.append("span").text(s.name);if(s.grouplabel){n.append("span").style("margin-left","10px").style("font-size",".7em").text(s.grouplabel)}if(s.num_assay_tracks){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text(s.num_assay_tracks+" track"+(s.num_assay_tracks>1?"s":""))}if(s.disco){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text("Genome view")}if(s.mutation_signature){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text("Mutation signature")}n.attr("class","sja_menuoption").on("click",(()=>{t.tkconfigtip.hide();const n=[];Ft(n,{tk:t,block:e,sample:{samplename:s.name},samplegroup:{attributes:s.attributes}});Pt(n,{tk:t,block:e,sample:{samplename:s.name}});Ht(n,{tk:t,block:e,sample:{samplename:s.name}});Tt(n,s.name,t,e);if(s.attr&&t.sampleAttribute&&t.sampleAttribute.attributes){n.push({label:"Attributes",callback:e=>{for(const e of s.attr){const n=t.sampleAttribute.attributes[e.k];if(n)e.k=n.label}f(e,s.attr)}})}const o=a({x:100,y:100});o.header.text(s.name);m(o.body.style("padding-top","10px"),n)}))}}catch(t){u(o,err.message||err);if(err.stack)console.log(err.stack)}}}function ft(t,e,n){if(e.sampleset)return mt(t,e,n);if(e.iscustom)return;if(!t.attributes){return}const a=t=>u(e.tip2.d,t);if(!e.sampleAttribute)return a("tk.sampleAttribute missing");if(!e.sampleAttribute.attributes)return a("tk.sampleAttribute.attributes{} missing");e.tip2.d.append("div").style("margin","4px 10px").style("font-size",".7em").text(t.name);e.tip2.d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{e.tip2.clear();gt(t,e,true);e.tip2.hide();an(e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{e.tip2.clear();for(const t of e._data){gt(t,e,true)}gt(t,e,false);e.tip2.hide();an(e,n)}));{const[a,s,o]=ht(t,e);if(a);else if(o.hiddenvalues.size>0){e.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{e.tip2.hide();o.hiddenvalues.clear();an(e,n)}))}}e.tip2.d.append("div").attr("class","sja_menuoption").text("Table view").on("click",(()=>{e.tip2.hide();kt(t,e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Matrix view").on("click",(()=>{e.tip2.hide();ut(e,n,t)}));Ct(t,e,n);Gt({tk:e,block:n,samplegroup:t,holder:e.tip2.d});Xt(e,n,e.tip2.d,t)}function mt(t,e,n){e.tip2.d.append("div").style("margin","4px 10px").style("font-size",".7em").text(t.name);e.tip2.d.append("div").attr("class","sja_menuoption").text("Table view").on("click",(()=>{e.tip2.hide();kt(t,e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Matrix view").on("click",(()=>{e.tip2.hide();ut(e,n,t)}))}function ut(e,n,a){const s=n.rglst[n.startidx];const o={ismutation:1,width:60,chr:s.chr,start:s.start,stop:s.stop,cnv:{valuecutoff:e.valueCutoff,focalsizelimit:e.bplengthUpperLimit},loh:{valuecutoff:e.segmeanValueCutoff,focalsizelimit:e.lohLengthUpperLimit},itd:{},sv:{},fusion:{},snvindel:{excludeclasses:{}}};if(e.legend_mclass&&e.legend_mclass.hiddenvalues){for(const t of e.legend_mclass.hiddenvalues){if(typeof t=="string"){o.snvindel.excludeclasses[t]=1}else{if(t==h){o.cnv.hidden=1}else if(t==g){o.loh.hidden=1}else if(t==b){o.itd.hidden=1}else if(t==k){o.sv.hidden=1}else if(t==v){o.fusion.hidden=1}else{console.error("unknown hidden dt?? "+t)}}}}if(e.showinggene){o.label=e.showinggene}else{o.label=s.chr+":"+s.start+"-"+s.stop}const l={tk:e,block:n,feature:o};o.querykeylst=[];if(e.iscustom){if(e.file||e.url)o.querykeylst.push(lt);if(e.checkvcf)o.querykeylst.push(it)}else if(e.querykey){o.querykeylst.push(e.querykey);if(e.checkvcf)o.querykeylst.push(e.checkvcf.querykey)}if(e.sampleset){for(const n of e.samplematrices){if(n.limitbysamplesetgroup&&n.limitbysamplesetgroup.name==a.name){t(n._pane.pane);n.addnewfeature_update(o);return}}l.limitbysamplesetgroup={name:a.name,samples:JSON.parse(JSON.stringify(e.sampleset.find((t=>t.name==a.name)).samples))}}else if(a.attributes){const n=a.attributes[a.attributes.length-1];for(const a of e.samplematrices){if(a.limitsamplebyeitherannotation){const e=a.limitsamplebyeitherannotation[0];if(e&&e.key==n.k&&e.value==n.kvalue){t(a._pane.pane);a.addnewfeature_update(o);return}}}l.limitsamplebyeitherannotation=[{key:n.k,value:n.kvalue}]}ct(l)}function ht(t,e){if(!t.attributes)return[".attributes[] missing for group "+t.name];if(t.attributes.length==0)return[".attributes[] zero length for group "+t.name];const n=t.attributes[t.attributes.length-1];const a=e.sampleAttribute.attributes[n.k];if(!a)return['"'+n.k+'" not registered in sampleAttribute for group '+t.name];return[null,n,a]}function gt(t,e,n){const[a,s,o]=ht(t,e);if(a)return a;if(n){o.hiddenvalues.add(s.kvalue)}else{o.hiddenvalues.delete(s.kvalue)}return null}function bt(t,e){const n=e.tktip.clear().d.append("div");if(t.attributes){for(const e of t.attributes){n.append("div").html(e.kvalue+(e.fullvalue?' <span style="opacity:.5;font-size:.8em;">'+e.fullvalue+"</span>":""))}}else if(t.name){n.append("div").text(t.name)}const a=[t.samples.length+" sample"+(t.samples.length>1?"s":"")];if(t.sampletotalnum)a.push(t.sampletotalnum+" samples total, "+Math.ceil(100*t.samples.length/t.sampletotalnum)+"%");if(e.sampleset){const n=e.sampleset.find((e=>e.name==t.name));if(n){a.push(n.samples.length+" samples total, "+Math.ceil(100*t.samples.length/n.samples.length)+"%")}}e.tktip.d.append("div").style("margin-top","10px").style("color","#858585").html(a.join("<br>"));e.tktip.show(event.clientX,event.clientY)}function kt(t,e,n){const s=a({x:event.clientX+100,y:Math.max(100,event.clientY-100)});s.header.html(t.name+' <span style="font-size:.7em">'+e.name+"</span>");if(t.samples.length==1){const a=t.samples[0];const o=s.body.append("table").style("margin","10px").style("border-spacing","4px");{const t=o.append("tr");t.append("td").text("Sample").style("opacity",.5);t.append("td").text(a.samplename)}if(a.sampletype){const t=o.append("tr");t.append("td").text("Sample type").style("opacity",.5);t.append("td").text(a.sampletype)}const[l,i,r,c,p,d,f,m,u,h]=Bt(a.samplename,a.items,e);if(l.length){const s=o.append("tr");s.append("td").text("CNV").style("opacity",.5);const i=s.append("td");for(let s=0;s<l.length;s++){i.append("div").html(l[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:d[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:d[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(i.length){const s=o.append("tr");s.append("td").text("SV").style("opacity",.5);const l=s.append("td");for(let s=0;s<i.length;s++){l.append("div").html(i[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:f[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:f[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(r.length){const s=o.append("tr");s.append("td").text("LOH").style("opacity",.5);const l=s.append("td");for(let s=0;s<r.length;s++){l.append("div").html(r[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:m[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:m[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(c.length){const s=o.append("tr");s.append("td").text("ITD").style("opacity",.5);const l=s.append("td");for(let s=0;s<c.length;s++){l.append("div").html(c[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:u[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:u[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(p.length){const s=o.append("tr");s.append("td").text("SNV/indel").style("opacity",.5);const l=s.append("td");for(let s=0;s<p.length;s++){const o=h[s].sampledata.find((t=>t.sampleobj.name==a.samplename));l.append("div").html(p[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:h[s],m_sample:o,sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:h[s],sample:a,m_sample:o,samplegroup:t,tk:e,block:n})}))}}return}const o=s.body.append("table").style("border-spacing","2px").style("margin","20px");const l=t.samples.find((t=>t.sampletype));const i=o.append("tr");i.append("td").text("Sample").style("opacity",.5);if(l){i.append("td").text("Sample type").style("opacity",.5)}i.append("td").text("CNV").style("opacity",.5);i.append("td").text("SV").style("opacity",.5);i.append("td").text("LOH").style("opacity",.5);i.append("td").text("ITD").style("opacity",.5);if(e.data_vcf){i.append("td").text("SNV/indel").style("opacity",.5)}for(const[a,s]of t.samples.entries()){const i=o.append("tr");if(!(a%2)){i.style("background","#f1f1f1")}i.append("td").text(s.samplename);if(l){i.append("td").text(s.sampletype||"")}const[r,c,p,d,f,m,u,h,g,b]=Bt(s.samplename,s.items,e);{const a=i.append("td");for(let o=0;o<r.length;o++){a.append("div").html(r[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:m[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:m[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<c.length;o++){a.append("div").html(c[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:u[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:u[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<p.length;o++){a.append("div").html(p[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:h[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:h[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<d.length;o++){a.append("div").html(d[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:g[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:g[o],sample:s,samplegroup:t,tk:e,block:n})}))}}if(e.data_vcf){const a=i.append("td");for(let o=0;o<f.length;o++){const l=b[o].sampledata.find((t=>t.sampleobj.name==s.samplename));a.append("div").html(f[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:b[o],m_sample:l,sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:b[o],m_sample:l,sample:s,samplegroup:t,tk:e,block:n})}))}}}}function vt(t,e,n){if(t.items.length==1){const a=t.items[0];At({item:a,sample:a._sample,samplegroup:a._samplegroup,tk:e,block:n});return}e.tktip.clear();let a="Group";if(e.groupsamplebyattr&&e.groupsamplebyattr.attrlst){a=e.groupsamplebyattr.attrlst[e.groupsamplebyattr.attrlst.length-1].label}const s=[{k:a,v:t.name}];let o=0,l=0;for(const e of t.items){if(e.dt==k)o++;else if(e.dt==v)l++}if(o)s.push({k:"# of SV",v:o});if(l)s.push({k:"# of fusion",v:l});f(e.tktip.d,s);e.tktip.show(event.clientX,event.clientY)}function xt(t,e,n){if(t.items.length==1){const a=t.items[0];wt({item:a,sample:a._sample,samplegroup:a._samplegroup,tk:e,block:n});return}const s=a({x:event.clientX,y:event.clientY});s.header.html(t.name+' <span style="font-size:.8em">'+e.name+"</span>");const o=new Map;for(const e of t.items){if(!o.has(e.sample)){o.set(e.sample,{sv:[],fusion:[]})}if(e.dt==k){o.get(e.sample).sv.push(e)}else if(e.dt==v){o.get(e.sample).fusion.push(e)}}const l=s.body.append("table").style("border-spacing","2px").style("margin","10px");const i=l.append("tr");i.append("td").text("Sample").style("font-size",".8em").style("opacity",.5);i.append("td").text("SV").style("font-size",".8em").style("opacity",.5);i.append("td").text("RNA fusion").style("font-size",".8em").style("opacity",.5);let r=0;for(const[t,a]of o){const s=l.append("tr");if(!(r++%2)){s.style("background","#f1f1f1")}s.append("td").text(t);const o=s.append("td");for(const t of a.sv){const a=qt(t,e);o.append("div").attr("class","sja_clbtext").html(t.cytogeneticname?t.cytogeneticname+' <span style="font-size:.7em">'+a+"</span>":a).on("mouseover",(()=>{At({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(t._sample)})).on("click",(()=>{wt({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e,block:n})}))}const i=s.append("td");for(const t of a.fusion){i.append("div").attr("class","sja_clbtext").html(yn(t)+' <span style="font-size:.7em">'+qt(t,e)+"</span>").on("mouseover",(()=>{At({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(t._sample)})).on("click",(()=>{wt({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e,block:n})}))}}}function yt(t,e,n){const s=a({x:event.clientX,y:event.clientY});s.header.text(e.name);if(t.items.length==1){const a=t.items[0];s.body.append("div").style("margin","10px");if(a.dt==x){if(a.sampledata.length==1){s.pane.remove();const[t,o]=Nt({m:a,m_sample:a.sampledata[0],tk:e});a.sampledata[0];wt({item:a,m_sample:a.sampledata[0],sample:t,samplegroup:o,tk:e,block:n});return}const t=St(a,e);const o=f(s.body,t);const l=o.append("tr");l.append("td").text("Samples").style("opacity",.5).attr("colspan",2);const i=l.append("td");for(const t of a.sampledata){const[s,o]=Nt({m:a,m_sample:t,tk:e});i.append("div").text(t.sampleobj.name).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:a,m_sample:t,sample:s,samplegroup:o,tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:a,m_sample:t,sample:s,samplegroup:o,tk:e,block:n})}))}Ot(a,n,o)}else{throw"Unknown dt: "+a.dt}return}const o=s.body.append("table").style("margin-top","10px").style("border-spacing","4px");for(const a of t.items){const t=o.append("tr");t.append("td").text(a.mname).style("color",y[a.class].color).style("font-weight","bold").style("vertical-align","top");{const e=t.append("td");if(a.dt==x){e.style("opacity",".5").text(a.ref+" > "+a.alt).style("vertical-align","top")}}{const s=t.append("td");if(a.dt==x){for(const t of a.sampledata){const[o,l]=Nt({m:a,m_sample:t,tk:e});s.append("div").text(t.sampleobj.name).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:a,m_sample:t,sample:o,samplegroup:l,tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();vn(o)})).on("click",(()=>{wt({item:a,m_sample:t,sample:o,samplegroup:l,tk:e,block:n})}))}}else{console.error("unknown dt: "+a.dt)}}}}function _t(t,e,n){e.tktip.clear();if(t.items.length==1){const a=t.items[0];if(a.dt==x){if(a.sampledata.length==1){const[t,s]=Nt({m:a,m_sample:a.sampledata[0],tk:e});At({item:a,m_sample:a.sampledata[0],sample:t,samplegroup:s,tk:e,block:n});return}const t=St(a,e);t.push({k:"Samples",v:a.sampledata.length>10?a.sampledata.slice(0,6).map((t=>t.sampleobj.name)).join("<br>")+"<br><i>... and "+(a.sampledata.length-6)+" more samples</i>":a.sampledata.map((t=>t.sampleobj.name)).join("<br>")});const s=f(e.tktip.d,t);Ot(a,n,s);e.tktip.show(event.clientX,event.clientY)}else{throw"unknown dt: "+a.dt}return}e.tktip.d.append("div").style("font-size",".7em").style("margin-bottom","5px").text(t.items.length+" "+y[t.items[0].class].label+" mutations, "+t.samplecount+" samples");const a=e.tktip.d.append("table").style("border-spacing","3px");for(const e of t.items){const t=a.append("tr");t.append("td").style("color",y[e.class].color).style("font-weight","bold").text(e.mname);t.append("td").style("font-size",".7em").style("opacity",".5").text(e.ref+" > "+e.alt);const n=t.append("td").style("font-size",".7em");if(e.dt==x){n.text(e.sampledata.length==1?e.sampledata[0].sampleobj.name:"("+e.sampledata.length+" samples)")}else{n.text("unknown dt: "+e.dt)}}e.tktip.show(event.clientX,event.clientY)}async function wt(t){const e=a({x:event.clientX,y:event.clientY});e.header.text(t.tk.name);const n=[];n.push({label:"Details",callback:e=>{t.holder=e;jt(t)}});Ft(n,t);Rt(n,t);Pt(n,t);Ht(n,t);Tt(n,t.sample.samplename,t.tk,t.block);Yt(n,{tk:t.tk,block:t.block,m:t.item,sample:t.sample});Dt(n,{tk:t.tk,block:t.block,m:t.item,sample:t.sample,samplegroup:t.samplegroup});m(e.body.style("padding-top","10px"),n)}function At(t){kn(t.sample);t.holder=t.tk.tktip.clear().d;jt(t);t.tk.tktip.show(event.clientX,event.clientY)}function jt(t){const e=[];if(t.sample){e.push({k:"Sample",v:t.sample.samplename});Et(t.sample.samplename,t.tk,e)}const n=t.item;let a;if(n.dt==b){e.push({k:"ITD",v:n.chr+":"+(n.start+1)+"-"+(n.stop+1)});if(n.gene||n.isoform){const t=[];if(n.gene)t.push(n.gene);if(n.isoform)t.push(n.isoform);e.push({k:"Gene",v:t.join(", ")})}if(n.rnaduplength){e.push({k:"RNA duplicated",v:n.rnaduplength+" bp"})}if(n.aaduplength){e.push({k:"AA duplicated",v:n.aaduplength+" aa"})}a=n.mattr}else if(n.dt==h||n.dt==g){if(n.dt==g){e.push({k:"LOH seg.mean",v:n.segmean.toFixed(2)})}else{e.push({k:"CNV log2(ratio)",v:'<span style="padding:0px 4px;background:'+(n.value>0?t.tk.cnvcolor.gain.str:t.tk.cnvcolor.loss.str)+';color:white;">'+n.value.toFixed(2)+"</span>"});e.push({k:"Copy number",v:(2*Math.pow(2,n.value)).toFixed(2)})}e.push({k:"Position",v:n.chr+":"+(n.start+1)+"-"+(n.stop+1)+' <span style="font-size:.7em">'+_(n.stop-n.start)+"</span>"});a=n.mattr}else if(n.dt==k||n.dt==v){{e.push({k:n.dt==k?"SV":"RNA fusion",v:yn(n)+' <span style="font-size:.7em">'+qt(n,t.tk)+"</span>"})}if(n.clipreadA||n.clipreadB){e.push({k:"# clip reads",v:'<span style="font-size:.7em;opacity:.7">A CLIP / TOTAL</span> '+(Number.isInteger(n.clipreadA)?n.clipreadA:"?")+" / "+(Number.isInteger(n.totalreadA)?n.totalreadA:"?")+"<br>"+'<span style="font-size:.7em;opacity:.7">B CLIP / TOTAL</span> '+(Number.isInteger(n.clipreadB)?n.clipreadB:"?")+" / "+(Number.isInteger(n.totalreadB)?n.totalreadB:"?")})}a=n.mattr}else if(n.dt==x){const s=St(n,t.tk);for(const t of s)e.push(t);if(t.m_sample){a={};const s=t.tk.checkvcf?t.tk.checkvcf.format:null;for(const o in t.m_sample){if(o=="sampleobj"){continue}if(t.tk.mds&&t.tk.mds.mutation_signature){const n=t.tk.mds.mutation_signature.sets[o];if(n){const a=t.m_sample[o];const s=n.signatures[a];if(!s.nodata){const t=s?s.name:"Unknown ("+a+")";const o=s?s.color:"black";e.push({k:n.name,v:'<span style="background:'+o+'">&nbsp;&nbsp;&nbsp;</span> '+t})}continue}}if(t.tk.mutationAttribute&&t.tk.mutationAttribute.attributes){if(t.tk.mutationAttribute.attributes[o]){a[o]=t.m_sample[o];continue}}const l=s?s[o]:null;if(l){let a=l.Number=="R"||l.Number=="A";if(!a){if(o=="AD"){a=true}}if(a){const a=[];const s=[];let i;for(const e in t.m_sample[o]){if(e==n.ref)continue;a.push(e);i=t.m_sample[o][e];s.push(i)}const r=t.m_sample[o][n.ref];if(r!=undefined){a.push(n.ref);s.push(r)}let c;if(r+i>0){c=w(null,{f:i/(i+r)})}e.push({k:o,v:(c?c+" ":"")+'<span style="font-size:.8em;opacity:.5">'+a.join(" / ")+"</span> "+s.join(" / ")+(l.Description?' <span style="font-size:.7em;opacity:.5">'+l.Description+"</span>":"")});continue}}e.push({k:o,v:t.m_sample[o]})}Mt(t.tk,n,t.m_sample.sampleobj.name,e)}}else{e.push({k:"Unknown dt!!",v:n.dt})}if(a){for(const n in a){const s=t.tk.mutationAttribute?t.tk.mutationAttribute.attributes[n]:null;const o=a[n];if(s){if(s.appendto_link){if(!o){continue}e.push({k:s.label,v:o.split(",").map((t=>"<a target=_blank href="+s.appendto_link+t+">"+t+"</a>")).join(" ")});continue}if(s.values){const t=s.values[o];if(t){e.push({k:s.label,v:t.name+(t.label?' <span style="font-size:.7em;opacity:.5">'+t.label+"</span>":"")});continue}}e.push({k:s.label,v:o})}else{e.push({k:n,v:o})}}}Lt(t,e);zt(t,e);const s=f(t.holder,e);if(n.dt==x){Ot(n,t.block,s)}}function Mt(t,e,n,a){if(!t.checkrnabam)return;const s=t.checkrnabam.samples[n];if(!s)return;if(!A[e.ref]||!A[e.alt]){a.push({k:"RNA-seq",v:"RNA-seq coverage not assessed, not SNV"});return}if(!s.genes)return;let o;for(const t of s.genes){if(t.snps){const n=t.snps.find((t=>t.pos==e.pos&&t.ref==e.ref&&t.alt==e.alt));if(n){o=n;break}}}if(!o){a.push({k:"RNA-seq",v:"RNA-seq coverage not assessed, not heterozygous in DNA"});return}if(o.rnacount.nocoverage){a.push({k:"RNA-seq",v:"Not covered in RNA-seq"});return}a.push({k:"RNA-seq read count",v:w(null,{f:o.rnacount.f})+" "+'<span style="font-size:.8em;opacity:.5">'+e.alt+" / "+e.ref+"</span> "+o.rnacount.alt+" / "+o.rnacount.ref+(o.rnacount.pvalue?' <span style="font-size:.8em;opacity:.5">Binomial p</span> '+o.rnacount.pvalue:"")})}function zt(t,e){const n=t.tk;if(!n)return;if(!n.checkrnabam)return;if(!t.sample)return;const a=n.checkrnabam.samples[t.sample.samplename];if(!a)return;if(!a.genes)return;const s=[];for(const t of a.genes){const e=["<td><b>"+t.gene+"</b></td>"+'<td><span style="font-size:.8em;opacity:.5">'+n.gecfg.datatype+"</span> "+t.fpkm+"</td>"+"<td>"];if(t.estat){if(t.estat.ase_uncertain){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(t.estat.ase_biallelic){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(t.estat.ase_monoallelic){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}}e.push("</td>");s.push("<tr>"+e.join("")+"</tr>")}if(n.gecfg.fixed){for(const e of n.gecfg.fixed){if(e.sample2rnabam){const a=e.sample2rnabam[t.sample.samplename];if(a){const t=["<td><b>"+e.gene+"</b></td>"+'<td><span style="font-size:.8em;opacity:.5">'+n.gecfg.datatype+"</span> "+a.fpkm+"</td>"+"<td>"];if(a.estat){if(a.estat.ase_uncertain){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(a.estat.ase_biallelic){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(a.estat.ase_monoallelic){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}}t.push("</td>");s.push("<tr>"+t.join("")+"</tr>")}}}}if(s.length){e.push({k:"Gene expression",v:"<table>"+s.join("")+"</table>"})}}function Lt(t,e){const n=t.tk;if(!n)return;const a=t.sample;if(!a)return;if(!a.expressionrank)return;const s=[];for(const t in a.expressionrank){const e=a.expressionrank[t];const o=["<tr>"+"<td><b>"+t+"</b></td>"+'<td>&nbsp;<span style="font-size:.7em">RANK</span> '+j(e.rank)+"</td>"+'<td>&nbsp;<span style="font-size:.7em">'+n.gecfg.datatype+"</span> "+e.value+"</td>"+"<td>"];if(e.estat){if(e.estat.ase_uncertain){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(e.estat.ase_biallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(e.estat.ase_monoallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}if(e.estat.outlier){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier+';color:white">Outlier HIGH</span>')}else if(e.estat.outlier_asehigh){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier_asehigh+';color:white">ASE HIGH</span>')}}o.push("</td></tr>");s.push(o.join(""))}if(n.gecfg&&n.gecfg.fixed){for(const t of n.gecfg.fixed){if(t.sample2rank&&t.sample2rank[a.samplename]){const e=t.sample2rank[a.samplename];const o=["<tr>"+"<td><b>"+t.gene+"</b></td>"+'<td>&nbsp;<span style="font-size:.7em">RANK</span> '+j(e.rank)+"</td>"+'<td>&nbsp;<span style="font-size:.7em">'+n.gecfg.datatype+"</span> "+e.value+"</td>"+"<td>"];if(e.estat){if(e.estat.ase_uncertain){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(e.estat.ase_biallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(e.estat.ase_monoallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}if(e.estat.outlier){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier+';color:white">Outlier HIGH</span>')}else if(e.estat.outlier_asehigh){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier_asehigh+';color:white">ASE HIGH</span>')}}o.push("</td></tr>");s.push(o.join(""))}}}if(s.length){e.push({k:"Expression",v:'<table style="font-size:.9em">'+s.join("")+"</table>"})}}function St(t,e){const n=[];{const e=y[t.class];n.push({k:"Mutation",v:(t.mname?'<span style="color:'+e.color+'">'+t.mname+"</span>":"")+' <span style="font-size:.7em">'+e.label+"</span>"})}{const e=[];if(t.gene)e.push(t.gene);if(t.isoform)e.push(t.isoform);if(e.length){n.push({k:"Gene",v:e.join(" ")})}}n.push({k:"Position",v:t.chr+":"+(t.pos+1)});n.push({k:"Alleles",v:'<span style="font-size:.8em;opacity:.5">REF/ALT</span> '+t.ref+" / "+t.alt});if(e&&e.alleleAttribute&&e.alleleAttribute.attributes){for(const a in e.alleleAttribute.attributes){const s=e.alleleAttribute.attributes[a];n.push({k:s.label,v:t.altinfo?t.altinfo[a]:""})}}if(e&&e.locusAttribute&&e.locusAttribute.attributes){for(const a in e.locusAttribute.attributes){const s=e.locusAttribute.attributes[a];const o=t.info?t.info[a]:"";if(s.appendto_link){if(!o){continue}n.push({k:s.label,v:o.split(",").map((t=>"<a target=_blank href="+s.appendto_link+t+">"+t+"</a>")).join(" ")});continue}n.push({k:s.label,v:t.info?t.info[a]:""})}}return n}function Nt(t){let e;if(t.m.dt==x){if(!t.m_sample)throw"m_sample missing";e=t.m_sample.sampleobj.name}else{throw"unknown dt"}for(const n of t.tk._data){for(const t of n.samples){if(t.samplename==e){return[t,n]}}}return[-1,-1]}function Ut(t,e){if(e.legend_svchrcolor.interchrs.has(t)){return'<span style="background:'+e.legend_svchrcolor.colorfunc(t)+';font-weight:bold;padding:0px 5px;color:white">'+t+"</span>"}return t}function qt(t,e){return Ut(t.chrA,e)+":"+t.posA+(t.strandA?":"+t.strandA:"")+" &raquo; "+Ut(t.chrB,e)+":"+t.posB+(t.strandB?":"+t.strandB:"")}function Bt(t,e,n){const a=[],s=[],o=[],l=[],i=[],r=[],c=[],p=[],d=[],f=[];{const t=e.filter((t=>t.dt==k||t.dt==v));const a=Gn(t);for(const t of a){s.push('<div style="white-space:nowrap">'+yn(t)+' <span style="font-size:.7em">'+qt(t,n)+"</span>"+(t.dt==v?' <span style="font-size:.7em">(RNA fusion)</span>':"")+"</div>");c.push(t)}}for(const t of e){if(t.dt==k||t.dt==v)continue;if(t.dt==g){o.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+' <span style="font-size:.8em">'+_(t.stop-t.start)+" seg.mean: "+t.segmean+"</span>");p.push(t)}else if(t.dt==h){a.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+' <span style="font-size:.8em">'+_(t.stop-t.start)+"</span>"+' <span style="background:'+(t.value>0?n.cnvcolor.gain.str:n.cnvcolor.loss.str)+';font-size:.8em;color:white">&nbsp;'+t.value+"&nbsp;</span>"+"</div>");r.push(t)}else if(t.dt==b){l.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+(t.rnaduplength?", "+t.rnaduplength+" bp duplicated in RNA":"")+(t.aaduplength?", "+t.aaduplength+" AA duplicated":"")+"</div>");d.push(t)}else{throw"unknown dt: "+t.dt}}if(n.data_vcf){for(const e of n.data_vcf){if(e.dt==x){if(e.sampledata.find((e=>e.sampleobj.name==t))){const t=y[e.class];i.push('<div style="white-space:nowrap">'+'<span style="color:'+t.color+';font-weight:bold">'+e.mname+"</span> "+'<span style="font-size:.7em">'+t.label+"</span></div>");f.push(e)}}else{throw"unknown dt: "+e.dt}}}return[a,s,o,l,i,r,c,p,d,f]}function Ct(t,e,n){if(!e.mds||!e.mds.annotationsampleset2matrix)return;if(!t.attributes)return;const s=t.attributes.find((t=>t.k==e.mds.annotationsampleset2matrix.key));if(!s)return;const o=e.mds.annotationsampleset2matrix.groups[s.kvalue];if(!o)return;if(!o.groups)return;for(const t of o.groups){if(!t.name||!t.matrixconfig)continue;e.tip2.d.append("div").html(t.name+' <span style="font-size:.8em;opacity:.5">SUMMARY</span>').attr("class","sja_menuoption").on("click",(()=>{e.tip2.hide();const s=a({x:100,y:100});s.header.text(t.name+" summary");const o={dslabel:e.mds.label,debugmode:n.debugmode,genome:n.genome,hostURL:n.hostURL,jwt:n.jwt,holder:s.body.append("div").style("margin","20px")};for(const e in t.matrixconfig){o[e]=t.matrixconfig[e]}import("./samplematrix-3556e5c0.js").then((t=>{new t.Samplematrix(o)}))}))}}function Et(t,e,n){if(!e.sampleAttribute)return;if(!e.sampleAttribute.attributes||!e.sampleAttribute.samples)return;const a=e.sampleAttribute.samples[t];if(!a)return;for(const t in a){const s=e.sampleAttribute.attributes[t]||{};const o=a[t];if(o==undefined)continue;let l=o;if(s.values){const t=s.values[o];if(t&&t.name){l=t.name}}n.push({k:s.label||t,v:l})}}function Rt(t,e){if(!e.item)return;if(e.item.dt!=k&&e.item.dt!=v)return;t.push({label:"Fusion graph",callback:async t=>{const n=M(t);await Vt(e,t);n.remove()}})}async function Vt(t,e){const n={a:{chr:t.item.chrA,position:t.item.posA,strand:t.item.strandA},b:{chr:t.item.chrB,position:t.item.posB,strand:t.item.strandB}};const a=e.append("div");try{{a.text("Loading gene at "+n.a.chr+":"+n.a.position+" ...");const e=await It(t,n.a.chr,n.a.position);const s=e.find((t=>t.isdefault))||e[0];if(s){n.a.name=s.name;n.a.gm={isoform:s.isoform}}}{a.text("Loading gene at "+n.b.chr+":"+n.b.position+" ...");const e=await It(t,n.b.chr,n.b.position);const s=e.find((t=>t.isdefault))||e[0];if(s){n.b.name=s.name;n.b.gm={isoform:s.isoform}}}a.remove();const s={pairlst:[n],genome:t.block.genome,holder:e};import("./svgraph-037fd7b6.js").then((t=>{t.default(s)}))}catch(t){if(t.stack)console.log(t.stack);a.text("Error: "+(t.message||t))}}function It(t,e,n){return z(`isoformbycoord?genome=${t.block.genome.name}&chr=${e}&pos=${n}`).then((t=>{if(t.error)throw t.error;return t.lst}))}async function Ot(t,e,n){if(!e||!e.genome||!e.genome.hasSNP)return;const a=n.append("tr");a.append("td").attr("colspan",2).text("dbSNP").style("opacity",.4).style("padding","3px");const s=a.append("td");const o=s.append("div").text("Loading...");try{const n=await L(t.chr,[t.pos],e.genome,[t.ref,t.altstr]);if(!n||n.length==0){o.text("No match");return}o.remove();for(const t of n){const e=s.append("div");S(t,e)}}catch(t){o.text(t.message||t)}}function Ft(t,e){t.push({label:"Sample View",callback:t=>{zn({holder:t,m:e.item,sample:e.sample,samplegroup:e.samplegroup,tk:e.tk,block:e.block})}})}function Ht(t,e){if(!e.tk.mds)return;t.push({label:"Genome",callback:async t=>{const n=M(t);try{const a=await d("mdssvcnv",{genome:e.block.genome.name,dslabel:e.tk.mds.label,querykey:e.tk.mds.querykey,ifsamplehasvcf:e.sample.samplename});if(a.no)return;let s=0;for(const t in e.block.genome.majorchr){s=Math.max(s,e.block.genome.majorchr[t])}for(const n in e.block.genome.majorchr){const a=t.append("div").style("display","inline-block");const o={};if(e.tk.iscustom){}else{o.fixname=n.toUpperCase();o.mds=e.tk.mds;o.querykey=e.tk.querykey;o.singlesample={name:e.sample.samplename,waterfall:{inuse:1}};for(const t in e.tk.mds.queries[e.tk.querykey]){if(t=="bplengthUpperLimit"||t=="valueCutoff"){continue}o[t]=e.tk.mds.queries[e.tk.querykey][t]}}e.block.newblock({foldlegend:true,hide_mdsHandleHolder:1,width:Math.ceil(900*e.block.genome.majorchr[n]/s),holder:a,block:1,chr:n,start:0,stop:e.block.genome.majorchr[n],tklst:[o]})}n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Pt(t,e){if(!e.tk.mds||!e.tk.mds.singlesamplemutationjson)return;t.push({label:"Disco plot",callback:async t=>{const n=M(t);try{const a=await c();const s={genome:e.block.genome.name,dslabel:e.tk.mds.label,querykey:e.tk.querykey,getsample4disco:e.sample.samplename};const o=await d("/mdssvcnv",s);if(o.error)throw o.error;if(!o.text)throw".text missing";const l={sampleName:e.sample.samplename,data:JSON.parse(o.text)};if(e.tk.mds.mutation_signature){let t=false;for(const n in e.tk.mds.mutation_signature.sets){for(const e of l.data){if(e[n]){t=n;break}}if(t)break}if(t){const n=e.tk.mds.mutation_signature.sets[t];l.mutation_signature={key:t,name:n.name,signatures:n.signatures}}}const i=await a.dtDisco({chromosomeType:e.block.genome.name,majorchr:e.block.genome.majorchr,holderSelector:t,settings:{showControls:false,selectedSamples:[]},callbacks:{geneLabelClick:{type:"genomepaint",hostURL:e.block.hostURL,genome:e.block.genome.name,dslabel:e.tk.mds.label,sample:e.sample.samplename}}});i.main(l);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Tt(t,e,n,a){if(n.iscustom||!n.mds||!n.mds.mutation_signature)return;t.push({label:"Mutation signature",callback:async t=>{const s=M(t);try{const o=await d("mdssamplesignature",{sample:e,genome:a.genome.name,dslabel:n.mds.label});if(o.error)throw o.error;if(!o.lst)throw".lst[] missing";if(o.lst.length==0){s.text("No mutation signature for this sample.");return}for(const e of o.lst){const a=n.mds.mutation_signature.sets[e.key];const s=t.append("div").style("margin-bottom","20px");s.append("div").text(a.name);s.append("div").text(e.valuename);const o=s.append("svg");const l=14,i=16,r=250,c=20,p=2,d=6,f=5;const m=e.annotation[0].v;const u=0;const h=N().domain([u,m]).range([0,r]);let g=0;for(const t of e.annotation){o.append("text").attr("font-family",U).attr("font-size",l).text(a.signatures[t.k].name).each((function(){g=Math.max(g,this.getBBox().width)})).remove()}const b=o.append("g").attr("transform","translate("+(c+g+d)+","+(c+f+p)+")");for(const[t,n]of e.annotation.entries()){const e=b.append("g").attr("transform","translate(0,"+(i+p)*t+")");e.append("text").attr("font-family",U).attr("font-size",l).attr("x",-d).attr("text-anchor","end").attr("y",i/2).text(a.signatures[n.k].name).attr("dominant-baseline","central");e.append("rect").attr("width",Math.max(1,h(n.v))).attr("height",i).attr("shape-rendering","crispEdges").attr("fill",a.signatures[n.k].color)}q({axis:b.append("g").attr("transform","translate(0,-"+p+")").call(tt().scale(h).ticks(4)),showline:1,fontsize:l-2});o.attr("width",c+g+d+r+c).attr("height",c+f+p+(i+p)*e.annotation.length+c)}s.remove()}catch(t){s.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Dt(t,e){if(!e.tk||!e.block||!e.block.genome||!e.block.genome.fimo_motif)return;if(!e.m||e.m.dt!=x)return;t.push({label:"TF motif",callback:async t=>{const n=M(t);try{const a={genome:e.block.genome,div:t,m:{chr:e.m.chr,pos:e.m.pos+1,ref:e.m.ref,alt:e.m.alt}};if(e.tk.iscustom){if(e.tk.checkexpressionrank){a.factor_profiles=[{isgenevalue:1,name:"Gene "+e.tk.gecfg.datatype,file:e.tk.checkexpressionrank.file,url:e.tk.checkexpressionrank.url,indexURL:e.tk.checkexpressionrank.indexURL}];if(e.sample){a.factor_profiles.push({isgenevalueonesample:1,name:e.sample.samplename+" "+e.tk.gecfg.datatype,samplename:e.sample.samplename,file:e.tk.checkexpressionrank.file,url:e.tk.checkexpressionrank.url,indexURL:e.tk.checkexpressionrank.indexURL})}}}else{if(e.tk.checkexpressionrank){const t={isgenevalue:1,datatype:e.tk.checkexpressionrank.datatype,querykey:e.tk.checkexpressionrank.querykey,mdslabel:e.tk.mds.label};if(e.samplegroup){if(e.samplegroup.attributes){t.name=e.samplegroup.name+" "+e.tk.gecfg.datatype;t.samplegroup_attrlst=e.samplegroup.attributes}}if(!t.name){t.name="Gene "+e.tk.gecfg.datatype}a.factor_profiles=[t];if(e.sample){a.factor_profiles.push({isgenevalueonesample:1,name:e.sample.samplename+" "+e.tk.gecfg.datatype,samplename:e.sample.samplename,datatype:e.tk.checkexpressionrank.datatype,querykey:e.tk.checkexpressionrank.querykey,mdslabel:e.tk.mds.label})}}}const s=await import("./mds.fimo-f19840cd.js");await s.init(a);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Yt(t,e){if(!e.tk.mds||!e.tk.mds.survivalplot)return;t.push({label:"Survival",callback:async t=>{const n=M(t);try{const a=e.m;const s={mutation:1};if(a.dt==x){s.chr=a.chr;s.start=a.pos;s.stop=a.pos;s.snvindel={name:(a.gene?a.gene+" ":"")+a.mname,ref:a.ref,alt:a.alt}}else if(a.dt==h){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.cnv={focalsizelimit:e.tk.bplengthUpperLimit,valuecutoff:e.tk.valueCutoff}}else if(a.dt==g){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.loh={focalsizelimit:e.tk.lohLengthUpperLimit,valuecutoff:e.tk.segmeanValueCutoff}}else if(a.dt==k){s.chr=a._chr;s.start=a._pos;s.stop=a._pos;s.sv={}}else if(a.dt==v){s.chr=a._chr;s.start=a._pos;s.stop=a._pos;s.fusion={}}else if(a.dt==b){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.itd={}}const o={renderplot:1,samplerule:{full:{},set:s}};if(e.tk.mds.survivalplot.samplegroupattrlst&&e.sample){const t=e.tk.mds.survivalplot.samplegroupattrlst[0];const n=e.tk.sampleAttribute?e.tk.sampleAttribute.samples[e.sample.samplename]:null;if(n){const e=n[t.key];if(e){o.samplerule.full.byattr=1;o.samplerule.full.key=t.key;o.samplerule.full.value=e}}}else{}const l=await import("./mds.survivalplot-f440db10.js");await l.init({genome:e.block.genome,mds:e.tk.mds,plotlist:[o]},t,e.block.debugmode);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Gt(t){if(!t.tk.mds||!t.tk.mds.survivalplot){return}t.holder.append("div").text("Survival plot").attr("class","sja_menuoption").on("click",(()=>{t.tk.tip2.hide();t.m;const e={mutation:1};{const n=t.block.rglst;e.chr=n[t.block.startidx].chr;const a=n[t.block.startidx].start;const s=n[t.block.stopidx].stop;e.start=Math.min(a,s);e.stop=Math.max(a,s)}e.snvindel={hiddenclass:{}};{let n=false;for(const a of t.tk.legend_mclass.hiddenvalues){if(typeof a=="string"){e.snvindel.hiddenclass[a]=1;n=true}}if(!n){delete e.snvindel.hiddenclass}}if(!t.tk.legend_mclass.hiddenvalues.has(h)){e.cnv={focalsizelimit:t.tk.bplengthUpperLimit,valuecutoff:t.tk.valueCutoff}}if(!t.tk.legend_mclass.hiddenvalues.has(g)){e.loh={focalsizelimit:t.tk.lohLengthUpperLimit,valuecutoff:t.tk.segmeanValueCutoff}}if(!t.tk.legend_mclass.hiddenvalues.has(k)){e.sv={}}if(!t.tk.legend_mclass.hiddenvalues.has(v)){e.fusion={}}if(!t.tk.legend_mclass.hiddenvalues.has(b)){e.itd={}}const n={renderplot:1,samplerule:{full:{},set:e}};const s=t.samplegroup.attributes[t.samplegroup.attributes.length-1];n.samplerule.full={byattr:1,key:s.k,value:s.kvalue};const o=a({x:100,y:100});o.header.text("Survival plot");import("./mds.survivalplot-f440db10.js").then((e=>{e.init({genome:t.block.genome,mds:t.tk.mds,plotlist:[n]},o.body,t.block.debugmode)}))}))}function Xt(t,e,n,a){if(!t.mds||!t.mds.assayAvailability)return;n.append("div").text("Assay summary").attr("class","sja_menuoption").on("click",(async()=>{t.tip2.clear();const n=t.tip2.d.append("div").style("margin","10px").text("Loading...");const s={genome:e.genome.name,dslabel:t.mds.label,querykey:t.querykey,assaymap:1};if(a.attributes){const t=a.attributes[a.attributes.length-1];s.key=t.k;s.value=t.kvalue}const o=await d("mdssvcnv",s);if(o.error){n.text("Error: "+o.error);return}n.remove();Jt({data:o,par:s,div:t.tip2.d.append("div").style("margin","10px"),boxtip:t.tktip,headlabel:a.name});t.tip2.d.append("div").style("font-size",".7em").style("margin","10px").text("Drag and move a sequencing type label up/down to change order.");if(a.attributes){const e=t.tip2.d.append("div").style("margin","20px 10px 10px 10px").style("opacity",.7);for(const t of a.attributes){e.append("div").text(t.kvalue+(t.fullvalue?": "+t.fullvalue:""))}}}))}function Jt(t){const e={headlabel:t.headlabel,par:t.par,rows:[],hidetermid:new Set,svg:t.div.append("svg")};Zt(e,t.data);const n=t.div.append("div").append("div").style("display","inline");for(const a of t.data.terms){const t=n.append("div").style("display","inline-block").style("margin-right","15px").style("white-space","nowrap");const s=t.append("label");s.append("input").attr("type","checkbox").property("checked",true).on("change",(async t=>{if(t.target.checked){e.hidetermid.delete(a.id);if(e.par.termidorder&&!e.par.termidorder.includes(a.id)){e.par.termidorder.push(a.id)}}else{e.hidetermid.add(a.id)}e.par.skip_termids=[...e.hidetermid];const n=await d("mdssvcnv",e.par);Zt(e,n)}));s.append("span").text(a.name).style("padding-left","5px")}}function Zt(t,e){const n=20,a=5,s=5,o=25,l=16,i=1,r=10,c=15;t.rows=[];t.svg.selectAll("*").remove();let p=0;for(const t of e.terms){const e=t.blocks[t.blocks.length-1];p=Math.max(p,e.x+e.symbolwidth)}const f=c*p;const m=t.svg.append("g");m.append("rect").attr("width",f).attr("height",e.terms.length*(o+i)-i).attr("stroke","#858585").attr("fill","none");{let n;const a=m.append("text").attr("text-anchor","middle").attr("font-size",l-2).attr("y",-5).text((t.headlabel?t.headlabel+", ":"")+"n="+e.totalsample).each((function(){n=this.getBBox().width}));a.attr("x",f/2-(n>f?(n-f)/2:0))}let u=0;let h=0;for(const n of e.terms){const e=m.append("g").attr("transform","translate(0,"+h+")");e.append("line").attr("stroke","#858585").attr("x1",-6).attr("y1",o/2).attr("y2",o/2);const a={id:n.id,y:h,rowg:e};t.rows.push(a);a.svglabel=e.append("text").text(n.name+", n="+n.samplecount).attr("font-size",l).attr("x",-r).attr("y",o/2).attr("dominant-baseline","middle").attr("text-anchor","end").each((function(){u=Math.max(u,this.getBBox().width)})).on("mousedown",(n=>{n.preventDefault();a.moving=true;const s=B(document.body);let l=n.clientY;let i;let r=true;s.on("mousemove",(n=>{const s=n.clientY;i=s-l;const c=t.rows.findIndex((t=>t.id==a.id));if(i<0){if(c>0&&-i>=o-2){t.rows.splice(c,1);t.rows.splice(c-1,0,a);g();i=0;l=s;r=false}}else{if(c<t.rows.length-1&&i>=o-2){t.rows.splice(c,1);t.rows.splice(c+1,0,a);g();i=0;l=s;r=false}}e.attr("transform","translate(0,"+(a.y+i)+")")}));s.on("mouseup",(async()=>{s.on("mousemove",null).on("mouseup",null);delete a.moving;g();if(r)return;a.svglabel.text("Loading...");t.par.termidorder=t.rows.map((t=>t.id));t.par.skip_termids=[...t.hidetermid];const e=await d("mdssvcnv",t.par);Zt(t,e)}))}));for(const t of n.blocks){{const n=t.symbolwidth*c;const a=t.x*c;if(!t.isgap){e.append("rect").attr("fill",t.color).attr("x",a).attr("width",n).attr("height",o);e.append("text").text(t.samplecount).attr("font-size",l-2).attr("fill","white").attr("x",a+n/2).attr("y",o/2).attr("dominant-baseline","middle").attr("text-anchor","middle")}}}h+=o+i}m.attr("transform","translate("+(s+u+r)+","+n+")");t.svg.attr("width",s*2+u+r+f).attr("height",n+(o+i)*e.terms.length+a);function g(){let e=0;for(const n of t.rows){if(!n.moving)n.rowg.transition().attr("transform","translate(0,"+e+")");n.y=e;e+=o+i}}}const Wt=14;const $t=20;function Kt(t,e){const[n,a]=Q(t,e.name);e.tr_legend=n;e.td_legend=a;const s=a.append("table").style("border-spacing","5px");e.legend_table=s;e.legend_hideable=[];te(e);if(!e.nocnvlohsv){ne(e,t);ae(e);se(e)}le(e);oe(e);ie(e);if(e.alleleAttribute)re(e.alleleAttribute,e,t);if(e.locusAttribute)re(e.locusAttribute,e,t);e.legend_more_row=s.append("tr");e.legend_more_label=e.legend_more_row.append("td").style("text-align","right").append("span");e.legend_more_row.append("td")}function Qt(t,e){ce(t);pe(t,e);if(t.singlesample){de(t);return}fe(t,e)}function te(t){if(t.checkrnabam){ee(t);return}if(!t.legend_mclass)t.legend_mclass={};if(!t.legend_mclass.hiddenvalues)t.legend_mclass.hiddenvalues=new Set;t.legend_mclass.hidden=false;t.legend_mclass.row=t.legend_table.append("tr");t.legend_mclass.row.append("td").style("text-align","right").style("opacity",.5).text("Mutation");t.legend_mclass.holder=t.legend_mclass.row.append("td");t.legend_hideable.push(t.legend_mclass)}function ee(t){const e=t.legend_table.append("tr");e.append("td").style("text-align","right").style("opacity",.5).text("DNA marker usage");const n=e.append("td");{const e=n.append("div");e.append("span").html("&times;&nbsp;").style("color",t.checkrnabam.clientcolor_snpinuse).style("font-size","1.5em");e.append("span").text("Heterozygous SNP with a p-value from binomial test").style("opacity",.5)}{const e=n.append("div");e.append("span").html("&times;&nbsp;").style("color",t.checkrnabam.clientcolor_markernotinuse).style("font-size","1.5em");e.append("span").text("Marker not in use and without binomial test").style("opacity",.5)}t.checkrnabam.legend={snpusage:{row:e}}}function ne(t,e){const n=50;t.cnvcolor.cnvlegend={axistickh:4,barw:55};t.cnvcolor.cnvlegend.row=t.legend_table.append("tr");t.cnvcolor.cnvlegend.row.append("td").style("text-align","right").style("opacity",.5).text("CNV log2(ratio)");t.legend_hideable.push(t.cnvcolor.cnvlegend);const a=t.cnvcolor.cnvlegend.row.append("td").append("div").style("display","inline-block").attr("class","sja_clb").style("padding","0px").on("click",(()=>{t.tkconfigtip.clear().showunder(a.node());{const n=t.tkconfigtip.d.append("div").append("label");n.append("input").attr("type","checkbox").property("checked",!t.hide_cnvgain).on("change",(()=>{t.hide_cnvgain=!t.hide_cnvgain;an(t,e)}));n.append("span").html("&nbsp;Show copy number gain")}{const n=t.tkconfigtip.d.append("div").style("margin-top","10px").append("label");n.append("input").attr("type","checkbox").property("checked",!t.hide_cnvloss).on("change",(()=>{t.hide_cnvloss=!t.hide_cnvloss;an(t,e)}));n.append("span").html("&nbsp;Show copy number loss")}}));const s=a.append("svg").attr("width",(n+t.cnvcolor.cnvlegend.barw)*2).attr("height",Wt+t.cnvcolor.cnvlegend.axistickh+$t);t.cnvcolor.cnvlegend.svg=s;t.cnvcolor.cnvlegend.nodatadiv=a.append("div").text("no data").style("opacity",.3).style("padding-left","10px");t.cnvcolor.cnvlegend.axisg=s.append("g").attr("transform","translate("+n+","+(Wt+t.cnvcolor.cnvlegend.axistickh)+")");const o=Math.random().toString();const l=Math.random().toString();const i=s.append("defs");{const e=i.append("linearGradient").attr("id",l);t.cnvcolor.cnvlegend.loss_stop=e.append("stop").attr("offset","0%").attr("stop-color",t.cnvcolor.loss.str);e.append("stop").attr("offset","100%").attr("stop-color","white")}{const e=i.append("linearGradient").attr("id",o);e.append("stop").attr("offset","0%").attr("stop-color","white");t.cnvcolor.cnvlegend.gain_stop=e.append("stop").attr("offset","100%").attr("stop-color",t.cnvcolor.gain.str)}s.append("rect").attr("x",n).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh).attr("width",t.cnvcolor.cnvlegend.barw).attr("height",$t).attr("fill","url(#"+l+")");s.append("rect").attr("x",n+t.cnvcolor.cnvlegend.barw).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh).attr("width",t.cnvcolor.cnvlegend.barw).attr("height",$t).attr("fill","url(#"+o+")");s.append("text").attr("x",n-5).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh+$t/2).attr("font-family",U).attr("font-size",Wt).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill","black").text("Loss");s.append("text").attr("x",n+t.cnvcolor.cnvlegend.barw*2+5).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh+$t/2).attr("font-family",U).attr("font-size",Wt).attr("dominant-baseline","central").attr("fill","black").text("Gain")}function ae(t){if(t.mds&&t.mds.queries&&t.mds.queries[t.querykey]&&t.mds.queries[t.querykey].no_loh){return}const e=20;t.cnvcolor.lohlegend={axistickh:4,barw:55};t.cnvcolor.lohlegend.row=t.legend_table.append("tr");t.cnvcolor.lohlegend.row.append("td").style("text-align","right").style("opacity",.5).text("LOH seg.mean");t.legend_hideable.push(t.cnvcolor.lohlegend);const n=t.cnvcolor.lohlegend.row.append("td");const a=n.append("svg").attr("width",(e+t.cnvcolor.lohlegend.barw)*2).attr("height",Wt+t.cnvcolor.lohlegend.axistickh+$t);t.cnvcolor.lohlegend.svg=a;t.cnvcolor.lohlegend.nodatadiv=n.append("div").text("no data").style("opacity",.3).style("padding-left","10px");t.cnvcolor.lohlegend.axisg=a.append("g").attr("transform","translate("+e+","+(Wt+t.cnvcolor.lohlegend.axistickh)+")");const s=Math.random().toString();const o=a.append("defs");{const e=o.append("linearGradient").attr("id",s);e.append("stop").attr("offset","0%").attr("stop-color","white");t.cnvcolor.lohlegend.loh_stop=e.append("stop").attr("offset","100%").attr("stop-color",t.cnvcolor.loh.str)}a.append("rect").attr("x",e).attr("y",Wt+t.cnvcolor.lohlegend.axistickh).attr("width",t.cnvcolor.lohlegend.barw).attr("height",$t).attr("fill","url(#"+s+")")}function se(t){const e=t.legend_table.append("tr").style("display","none");t.legend_svchrcolor={row:e,interchrs:new Set,colorfunc:C(K),hidden:true};e.append("td").style("text-align","right").style("opacity",.5).text("SV chromosome");t.legend_svchrcolor.holder=e.append("td");t.legend_hideable.push(t.legend_svchrcolor)}function oe(t){if(t.singlesample)return;if(!t.sampleAttribute)return;for(const e in t.sampleAttribute.attributes){const n=t.sampleAttribute.attributes[e];if(!n.filter){continue}if(!n.hiddenvalues||!(n.hiddenvalues instanceof Set)){n.hiddenvalues=new Set}n.value2count=new Map;n.legendrow=t.legend_table.append("tr");n.legendcell=n.legendrow.append("td").style("text-align","right").style("opacity",.5).text(n.label);n.legendholder=n.legendrow.append("td")}}function le(t){if(!t.singlesample)return;if(!t.mds||!t.mds.mutation_signature)return;t.mutation_signature_legend={sets:{}};for(const e in t.mds.mutation_signature.sets){const n=t.legend_table.append("tr").style("display","none");n.append("td").text(t.mds.mutation_signature.sets[e].name).style("text-align","right").style("opacity",.5);const a=n.append("td");const s=a.append("table").style("border-spacing","0px").style("margin","10px");t.mutation_signature_legend.sets[e]={tr:n,td:a,table:s}}}function ie(t){if(t.singlesample)return;if(!t.mutationAttribute)return;for(const e in t.mutationAttribute.attributes){const n=t.mutationAttribute.attributes[e];if(!n.filter){continue}n.hiddenvalues=new Set;n.value2count=new Map;n.legendrow=t.legend_table.append("tr");n.legendcell=n.legendrow.append("td").style("text-align","right").style("opacity",.5).text(n.label);n.legendholder=n.legendrow.append("td")}}function re(t,e,n){for(const a in t.attributes){const s=t.attributes[a];if(!s.filter){continue}s.legendrow=e.legend_table.append("tr");s.legendcell=s.legendrow.append("td").style("text-align","right").style("opacity",.5).text(s.label);s.legendholder=s.legendrow.append("td");if(s.isnumeric){const t=s.legendholder.append("select").style("margin","0px 10px 0px 10px").on("change",(()=>{const a=t.property("value");if(a=="x"){s.disable=true}else{delete s.disable;s.keeplowerthan=a=="<"}an(e,n)}));const a=t.append("option").attr("value","<").property("text","≤");const o=t.append("option").attr("value",">").property("text","≥");const l=t.append("option").attr("value","x").property("text","X");if(s.disable){l.property("selected",1)}else if(s.keeplowerthan){a.property("selected",1)}else{o.property("selected",1)}s.legendholder.append("input").attr("type","number").style("width","50px").property("value",s.cutoffvalue).on("keyup",(t=>{if(t.key!="Enter")return;s.cutoffvalue=t.target.valueAsNumber;an(e,n)}))}else{s.hiddenvalues=new Set;s.value2count=new Map;s.legendrow=e.legend_table.append("tr");s.legendcell=s.legendrow.append("td").style("text-align","right").style("opacity",.5).text(s.label);s.legendholder=s.legendrow.append("td")}}}function ce(t){if(!t.legend_svchrcolor){return}t.legend_svchrcolor.holder.selectAll("*").remove();if(t.legend_svchrcolor.interchrs.size==0)return;t.legend_svchrcolor.row.style("display","table-row");for(const e of t.legend_svchrcolor.interchrs){const n=t.legend_svchrcolor.colorfunc(e);const a=t.legend_svchrcolor.holder.append("div").style("display","inline-block").style("margin","3px 10px 3px 0px");a.append("div").style("display","inline-block").style("border-radius","10px").style("padding","0px 10px").style("border","solid 1px "+n).style("color",n).style("font-size",".9em").text(e)}}function pe(t,e){if(!t.legend_mclass||!t.legend_mclass.holder)return;t.legend_mclass.holder.selectAll("*").remove();const n=new Map;if(t.data_vcf){for(const e of t.data_vcf){if(!n.has(e.class)){n.set(e.class,{isvcf:1,cname:e.class,count:0})}n.get(e.class).count++}}if(t.singlesample){if(t.data){for(const e of t.data){if(!n.has(e.dt)){n.set(e.dt,{dt:e.dt,count:0})}n.get(e.dt).count++}}}else if(t._data){for(const e of t._data){for(const t of e.samples){for(const e of t.items){if(!n.has(e.dt)){n.set(e.dt,{dt:e.dt,count:0})}n.get(e.dt).count++}}}}const a=[...n.values()];a.sort(((t,e)=>e.count-t.count));t.legend_mclass.total_count=a.reduce(((t,e)=>t+e.count),0);for(const e of a){let a,o,l,i="#858585";if(e.dt){a=e.dt;o=E[e.dt];if(e.dt==h)l="Copy number variation.";else if(e.dt==g)l="Loss of heterozygosity.";else if(e.dt==b){i=y[R].color;l="Internal tandem duplication."}else if(e.dt==k)l="Structural variation of DNA.";else if(e.dt==v)l="Fusion gene from RNA-seq."}else{a=e.cname;o=y[e.cname].label;i=y[e.cname].color;l=y[e.cname].desc}const r=t.legend_mclass.holder.append("div").attr("class","sja_clb").style("display","inline-block").on("click",(()=>{t.tip2.clear().d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{t.legend_mclass.hiddenvalues.add(a);s()}));t.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{for(const e of n.keys()){t.legend_mclass.hiddenvalues.add(e)}t.legend_mclass.hiddenvalues.delete(a);s()}));if(t.legend_mclass.hiddenvalues.size){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{t.legend_mclass.hiddenvalues.clear();s()}))}t.tip2.d.append("div").style("padding","10px").style("font-size",".8em").style("width","150px").text(l);t.tip2.showunder(r.node())}));r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background",i).html(e.count>1?e.count:"&nbsp;");r.append("div").style("display","inline-block").style("color",i).html("&nbsp;"+o)}for(const e of t.legend_mclass.hiddenvalues){t.legend_mclass.holder.append("div").style("display","inline-block").attr("class","sja_clb").style("text-decoration","line-through").text(Number.isInteger(e)?E[e]:y[e].label).on("click",(()=>{t.legend_mclass.hiddenvalues.delete(e);s()}))}if(t.vcfrangelimit){t.legend_mclass.holder.append("div").style("display","inline-block").text("Zoom in under "+_(t.vcfrangelimit)+" to view SNV/indel data").style("white-space","nowrap").style("margin","10px")}const s=()=>{t.tip2.hide();an(t,e)}}function de(t,e){if(!t.mds||!t.mds.mutation_signature)return;for(const e in t.mutation_signature_legend.sets){t.mutation_signature_legend.sets[e].tr.style("display","none")}if(!t.data_vcf){return}const n=new Map;for(const e of t.data_vcf){if(e.x==undefined)continue;if(!e.sampledata||!e.sampledata[0])continue;for(const a in t.mds.mutation_signature.sets){const s=e.sampledata[0][a];if(s==undefined)continue;const o=t.mds.mutation_signature.sets[a].signatures[s];if(o){if(o.nodata)continue;if(!n.has(a))n.set(a,new Map);n.get(a).set(s,1+(n.get(a).get(s)||0))}}}for(const[e,a]of n){const n=t.mutation_signature_legend.sets[e];n.tr.style("display","table-row");n.table.selectAll("*").remove();const s=[...a].sort(((t,e)=>e[1]-t[1]));for(const[a,o]of s){const s=t.mds.mutation_signature.sets[e].signatures[a];const l=n.table.append("tr");l.append("td").style("background",s.color).style("padding","0px 4px").style("color","white").style("text-align","right").html(o>1?o:"");const i=V(s.color);l.append("td").html("&nbsp;"+s.name).style("background","rgba("+i.r+","+i.g+","+i.b+",.2)").style("opacity",.6)}}}function fe(t,n){if(t.singlesample){return}const a=[];for(const s of["sampleAttribute","mutationAttribute","locusAttribute"]){if(!t[s])continue;for(const e in t[s].attributes){const n=t[s].attributes[e];if(!n.filter)continue;n.value2count.clear()}if(s=="sampleAttribute"){for(const e in t.sampleAttribute.attributes){for(const n in t.sampleAttribute.samples){ue(e,t.sampleAttribute.attributes[e],t.sampleAttribute.samples[n])}}}else{if(t._data){for(const e of t._data){for(const n of e.samples){for(const e of n.items){he(e.mattr,t,e.dt)}}}}if(t.data_vcf){for(const e of t.data_vcf){if(e.dt==x){if(e.sampledata){for(const n of e.sampledata){he(n,t,e.dt)}}if(e.info){ge(t,e)}}else{console.error("unknown dt: "+e.dt)}}}}for(const o in t[s].attributes){const l=t[s].attributes[o];if(!l.filter)continue;l.legendcell.classed("sja_hideable_legend",true).on("click",(()=>{t.tip2.hide();l.hidden=1;t.legend_more_row.style("display","table-row");e(l.legendcell,t.legend_more_label);l.legendrow.transition().delay(500).style("display","none");setTimeout((()=>{fe(t,n)}),500)}));if(l.hidden){l.legendrow.style("display","none");a.push(l);continue}if(l.value2count.size+l.hiddenvalues.size==0){l.legendrow.style("display","none");continue}l.legendrow.style("display","table-row");l.legendholder.selectAll("*").remove();const i=[...l.value2count];i.sort(((t,e)=>e[1].totalitems-t[1].totalitems));for(const[e,a]of i){const o=l.values[e]?l.values[e].name:e;const r=l.legendholder.append("div").style("display","inline-block").attr("class","sja_clb").on("click",(()=>{t.tip2.clear();if(l.hiddenvalues.has(e)){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show").on("click",(()=>{t.tip2.hide();l.hiddenvalues.delete(e);an(t,n)}))}else{t.tip2.d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{t.tip2.hide();l.hiddenvalues.add(e);an(t,n)}))}t.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{t.tip2.hide();for(const[t,e]of i){l.hiddenvalues.add(t)}l.hiddenvalues.delete(e);an(t,n)}));if(l.hiddenvalues.size){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{t.tip2.hide();l.hiddenvalues.clear();an(t,n)}))}if(l.values[e]&&l.values[e].label){t.tip2.d.append("div").text(l.values[e].label).style("opacity",.5).style("font-size",".7em").style("margin","10px")}if(a.dt2count){const e=[...a.dt2count];e.sort(((t,e)=>e[1]-t[1]));const n=t.tip2.d.append("div").style("margin","5px").style("font-size",".7em").style("opacity",.8).style("border-spacing","4px");for(const[t,a]of e){const e=n.append("tr");e.append("td").text(E[t]);e.append("td").text(a)}}t.tip2.showunder(r.node())}));const c=s=="sampleAttribute"&&t.legend_samplegroups&&t.legend_samplegroups.color(e)?t.legend_samplegroups.color(e):"#858585";r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background",c).text(a.totalitems);r.append("span").html("&nbsp;"+o)}if(l.hiddenvalues.size){for(const e of l.hiddenvalues){const a=l.values[e]&&l.values[e].name?l.values[e].name:e;l.legendholder.append("div").style("display","inline-block").attr("class","sja_clb").style("text-decoration","line-through").text(a).on("click",(()=>{l.hiddenvalues.delete(e);an(t,n)}))}}}}me(t,n,a)}function me(t,n,a){let s=0;for(const a of t.legend_hideable){a.row.select("td").classed("sja_hideable_legend",true).on("click",(()=>{t.tip2.hide();a.hidden=1;t.legend_more_row.style("display","table-row");e(a.row.select("td"),t.legend_more_label);a.row.transition().delay(500).style("display","none");setTimeout((()=>{fe(t,n)}),500)}));a.row.style("display",a.hidden?"none":"table-row");if(a.hidden){s++}}if(!a.length&&!s){t.legend_more_row.style("display","none")}else{t.legend_more_row.style("display","table-row");t.legend_more_label.selectAll("*").remove();const e=t.legend_more_label.attr("class","sja_legend_more_btn").html("MORE...").on("click",(()=>{t.tip2.clear();for(const e of t.legend_hideable){if(!e.hidden)continue;const a=t.tip2.d.append("div").attr("class","sja_menuoption").on("click",(()=>{t.tip2.hide();e.hidden=0;fe(t,n)}));if(e.hidden&&e.total_count){a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background","#858585").text(e.total_count)}a.append("span").html("&nbsp;"+e.row.node().firstChild.innerHTML)}for(const e of a){if(!e.hidden)continue;const a=[...e.value2count.values()].reduce(((t,e)=>t+e.totalitems),0);const s=t.tip2.d.append("div").attr("class","sja_menuoption").on("click",(()=>{t.tip2.hide();e.hidden=0;fe(t,n)}));s.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background","#858585").text(a);s.append("span").html("&nbsp;"+e.label)}t.tip2.showunder(e.node())}))}}function ue(t,e,n){if(!(t in n))return;if(!e.filter)return;const a=n[t];if(!e.value2count.has(a)){e.value2count.set(a,{totalitems:0})}e.value2count.get(a).totalitems++;if(!e.values){e.values={}}if(!e.values[a]){e.values[a]={name:a,label:a}}}function he(t,e,n){if(!t){return}if(!e.mutationAttribute)return;for(const a in e.mutationAttribute.attributes){const s=e.mutationAttribute.attributes[a];if(!s.filter)continue;const o=t[a];if(o==undefined){continue}if(!s.value2count.has(o)){s.value2count.set(o,{totalitems:0,dt2count:new Map})}s.value2count.get(o).totalitems++;if(!s.value2count.get(o).dt2count.has(n)){s.value2count.get(o).dt2count.set(n,0)}s.value2count.get(o).dt2count.set(n,s.value2count.get(o).dt2count.get(n)+1)}}function ge(t,e){if(!t.locusAttribute)return;for(const n in t.locusAttribute.attributes){const a=t.locusAttribute.attributes[n];if(!a.filter)continue;const s=e.info[n];if(s==undefined)continue;let o;if(Array.isArray(s)){o=s[0];if(o==".")continue}else{o=s}if(a.hiddenvalues.has(o))continue;if(!a.value2count.has(o)){a.value2count.set(o,{totalitems:0,dt2count:new Map})}a.value2count.get(o).totalitems++;if(!a.value2count.get(o).dt2count.has(e.dt)){a.value2count.get(o).dt2count.set(e.dt,0)}a.value2count.get(o).dt2count.set(e.dt,a.value2count.get(o).dt2count.get(e.dt)+1)}}function be(t,e){cn(t);const n=[];const a=[];const s=[];const o=[];const l={};let i=0,r=0,c=0;if(t.data){for(const p of t.data){if(p.dt==v||p.dt==k){const a=p.chrA+"."+p.posA+"."+p.chrB+"."+p.posB+"."+p.dt;if(!l[a]){je(p,e);if(p.x0||p.x1){l[a]=1;n.push(p);if(p.chrA!=p._chr){t.legend_svchrcolor.interchrs.add(p.chrA);t.legend_svchrcolor.colorfunc(p.chrA)}if(p.chrB!=p._chr){t.legend_svchrcolor.interchrs.add(p.chrB);t.legend_svchrcolor.colorfunc(p.chrB)}}}continue}Pn(p,t,e);if(p.x1==undefined||p.x2==undefined){console.log("unmappable: "+p.chr+" "+p.start+" "+p.stop);continue}if(p.dt==g){c=Math.max(c,p.segmean);s.push(p)}else if(p.dt==h){{if(p.value>0){i=Math.max(i,p.value)}else{r=Math.min(r,p.value)}}a.push(p)}else if(p.dt==b){o.push(p)}}if(a.length){t.cnvcolor.cnvmax=Math.max(i,-r);jn(t)}if(s.length){t.cnvcolor.segmeanmax=c;Mn(t)}}const p=_e(ke(n),t,e);t.cnv_g.attr("transform","translate(0,"+p+")");t.waterfall.axisgg.attr("transform","translate(0,"+p+")");const d=[...a,...s,...o];if(t.data_vcf){for(const e of t.data_vcf){if(e.x!=undefined){d.push(e)}}}const f=xe(d,t,e);t.height_main=t.toppad+p+f+t.bottompad;Qt(t,e)}function ke(t){const e=[];const n=8;for(let a=0;a<t.length;a++){const s=t[a];if(s.__claimed)continue;const o={x0:s.x0,x1:s.x1,_chr:s._chr,chrA:s.chrA,chrB:s.chrB,posA:s.posA,posB:s.posB,lst:[s]};for(let e=a+1;e<t.length;e++){const a=t[e];if(a.__claimed)continue;const l=a.x0==undefined||a.x1==undefined;if(s.x0!=undefined&&s.x1!=undefined){if(l)continue;if(Math.abs(a.x0-s.x0)<=n&&Math.abs(a.x1-s.x1)<=n){o.lst.push(a);a.__claimed=true}}else{if(!l)continue;const t=s.x0==undefined?s.x1:s.x0;const e=a.x0==undefined?a.x1:a.x0;if(Math.abs(t-e)<=n){o.lst.push(a);a.__claimed=true}}}e.push(o)}for(const e of t)delete e.__claimed;return e}function ve(t,e){if(e.mds&&e.mds.mutation_signature){if(t.sampledata&&t.sampledata[0]){for(const n in e.mds.mutation_signature.sets){const a=t.sampledata[0][n];if(a){return e.mds.mutation_signature.sets[n].signatures[a].color}}}}return y[t.class].color}function xe(t,e,n,a){if(t.length==0)return 0;const s=12;const o=1;let l=false;if(e.waterfall.inuse){const a=t.filter((t=>t.dt==x));if(a.length>1){if(ye(a,e,n)){l=true}}}if(!l){e.waterfall.axisg.selectAll("*").remove();e.waterfall.lab1.text("");e.waterfall.lab2.text("");e.waterfall.lab3.text("");for(const a of t){if(a.dt!=x)continue;const t=e.cnv_g.append("g");a._p={g:t};const o=ve(a,e);const l=t.append("text").attr("font-size",s).attr("font-family",U).attr("fill",o).attr("dominant-baseline","central").text(a.mname);let i;l.each((function(){i=this.getBBox().width}));const r=t.append("rect").attr("x",-s/2).attr("y",-s/2).attr("width",s).attr("height",s).attr("fill",o).attr("fill-opacity",0);let c,p;if(a.sampledata&&Xn(a.sampledata[0],e)){c=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("y1",1-s/2).attr("y2",s/2-1);p=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1)}else{c=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",1-s/2).attr("y2",s/2-1);p=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",s/2-1).attr("y2",1-s/2)}a._p.cover=t.append("rect").attr("y",-s/2).attr("width",s+en+i).attr("height",s).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{r.attr("fill-opacity",1);c.attr("stroke","white");p.attr("stroke","white");At({item:a,m_sample:a.sampledata[0],tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();r.attr("fill-opacity",0);c.attr("stroke",o);p.attr("stroke",o)}));a._p.stackw=s+5+i;if(n.width-a.x>i+en+s/2){a._p.stackx=a.x-s/2;a._p.g_x=s/2;l.attr("x",s/2+en);a._p.cover.attr("x",-s/2)}else{a._p.stackx=a.x-s/2-en-i;a._p.g_x=s/2+en+i;l.attr("x",-s/2-en).attr("text-anchor","end");a._p.cover.attr("x",-i-en-s/2)}}}t.sort(((t,e)=>{const n=t._p?t._p.stackx:Math.min(t.x1,t.x2);const a=e._p?e._p.stackx:Math.min(e.x1,e.x2);return n-a}));const i=[0];for(const e of t){if(l&&e.dt==x)continue;delete e.stack;const t=e._p?e._p.stackx:Math.min(e.x1,e.x2);const n=e._p?e._p.stackw:Math.abs(e.x1-e.x2);for(let a=0;a<i.length;a++){if(i[a]<=t){i[a]=t+n;e.stack=a;break}}if(e.stack==undefined){e.stack=i.length;i.push(t+n)}}const r=l?e.waterfall.axisheight+e.waterfall.bottompad:0;for(const n of t){if(n.dt==g||n.dt==h||n.dt==b){let t;if(n.dt==g){t="rgba("+e.cnvcolor.loh.r+","+e.cnvcolor.loh.g+","+e.cnvcolor.loh.b+","+n.segmean/e.cnvcolor.segmeanmax+")"}else if(n.dt==h){if(n.value>0){t="rgba("+e.cnvcolor.gain.r+","+e.cnvcolor.gain.g+","+e.cnvcolor.gain.b+","+n.value/e.cnvcolor.cnvmax+")"}else{t="rgba("+e.cnvcolor.loss.r+","+e.cnvcolor.loss.g+","+e.cnvcolor.loss.b+","+-n.value/e.cnvcolor.cnvmax+")"}}else if(n.dt==b){t=y[R].color}e.cnv_g.append("rect").attr("x",Math.min(n.x1,n.x2)).attr("y",r+(s+o)*n.stack).attr("width",Math.max(1,Math.abs(n.x2-n.x1))).attr("height",s).attr("fill",t).attr("shape-rendering","crispEdges").attr("stroke","none").attr("class","sja_aa_skkick").on("mouseover",(()=>{At({item:n,tk:e})})).on("mouseout",(()=>{e.tktip.hide()}));continue}if(n.dt==x&&!l){n._p.g.attr("transform","translate("+(n._p.stackx+n._p.g_x)+","+(s/2+(s+o)*n.stack)+")");continue}}return r+i.length*(s+o)-o}function ye(t,e,n){t[0].water={h:e.waterfall.axisheight};let a=0;for(let n=1;n<t.length;n++){const s=t[n];if(s.chr!=t[n-1].chr){s.water={h:e.waterfall.axisheight};continue}s.water={bpdist:s.pos-t[n-1].pos};a=Math.max(a,s.water.bpdist)}if(a<2){return false}q({axis:e.waterfall.axisg.call(et().ticks(3,".0f").scale(nt().domain([1,a]).range([e.waterfall.axisheight,0]))),color:"black",showline:1});e.waterfall.lab1.text("Log10").attr("y",e.waterfall.axisheight/2-14);e.waterfall.lab2.text("intermutation").attr("y",e.waterfall.axisheight/2);e.waterfall.lab3.text("distance").attr("y",e.waterfall.axisheight/2+14);for(let n=1;n<t.length;n++){const s=t[n];if(s.water.h){continue}if(s.water.bpdist==0){s.water.h=0}else{s.water.h=Math.log10(s.water.bpdist)*e.waterfall.axisheight/Math.log10(a)}}const s=12;for(const a of t){const t=e.cnv_g.append("g").attr("transform","translate("+a.x+","+(e.waterfall.axisheight-a.water.h)+")");const o=ve(a,e);const l=t.append("rect").attr("x",-s/2).attr("y",-s/2).attr("width",s).attr("height",s).attr("fill",o).attr("fill-opacity",0);let i,r;if(a.sampledata&&Xn(a.sampledata[0],e)){i=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("y1",1-s/2).attr("y2",s/2-1);r=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1)}else{i=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",1-s/2).attr("y2",s/2-1);r=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",s/2-1).attr("y2",1-s/2)}t.append("rect").attr("y",-s/2).attr("x",-s/2).attr("width",s).attr("height",s).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{l.attr("fill-opacity",1);i.attr("stroke","white");r.attr("stroke","white");At({item:a,m_sample:a.sampledata[0],tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();l.attr("fill-opacity",0);i.attr("stroke",o);r.attr("stroke",o)}));delete a.water}return true}function _e(t,e,n){if(t.length==0)return 0;let s;{let n=1;for(const e of t)n=Math.max(n,e.lst.length);const a=Math.pow(e.discradius,2)*Math.PI;const o=N();if(n==1){o.domain([1,1]).range([a,a])}else if(n==2){o.domain([1,2]).range([a,a*1.3])}else if(n==3){o.domain([1,3]).range([a,a*1.6])}else if(n==4){o.domain([1,4]).range([a,a*1.8])}else if(n==6){o.domain([1,6]).range([a,a*2])}else if(n==10){o.domain([1,10]).range([a,a*3])}else{o.domain([1,n]).range([a,a*4])}s=o}let o=0;for(const e of t){e.radius=Math.sqrt(s(e.lst.length)/Math.PI);o=Math.max(e.radius,o);if(e.x0!=undefined&&e.x1!=undefined){if(e.x0>e.x1){const t=e.x1;e.x1=e.x0;e.x0=t}e._x=(e.x0+e.x1)/2}else{e._x=e.x0||e.x1}e.x=e._x}const l=o*2+o*2+(t.find((t=>t.x0&&t.x1))?e.legheight:0);e.svvcf_g.attr("transform","translate(0,"+(l-0)+")");n.width+n.subpanels.reduce(((t,e)=>t+e.leftpad+e.width),0);for(const s of t){const t=s.x0&&s.x1;const o=e.legheight*(t?1:0);const l=s.lst.length==1?s.radius:s.radius*2;const i=e.svvcf_g.append("g").attr("transform","translate("+s.x+",-"+(o+l)+")");const r=s.chrA==s._chr?s.chrB:s.chrA;const c=r==s._chr?Ye:e.legend_svchrcolor.colorfunc(r);i.append("circle").attr("r",s.radius).attr("cy",-s.radius).attr("fill",c).attr("stroke","white");if(s.lst.length>1){const t=s.radius*1.5;const e=s.lst.length.toString();const n=Math.min(t/(e.length*I),t);i.append("text").text(e).attr("text-anchor","middle").attr("dominant-baseline","central").attr("fill","white").attr("y",-s.radius).attr("font-size",n).attr("font-family",U)}i.append("circle").attr("r",s.radius).attr("cy",-s.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",c).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(t=>{if(s.lst.length==1){At({item:s.lst[0],tk:e});return}Me(s.lst,e,t)})).on("mouseout",(()=>e.tktip.hide())).on("click",(t=>{if(s.lst.length==1){const o=s.lst[0];const l=a({x:t.clientX,y:t.clientY});l.header.text(o.sample);l.body.style("margin-top","10px");const[i,r]=we(o,n);if(i){const t=l.body.append("div").style("margin-bottom","5px");t.append("div").style("display","inline-block").text("Add new panel at "+i.name+":"+r).attr("class","sja_menuoption").on("click",(()=>{t.remove();Ae(i,r,n)}))}Vt({item:o,block:n},l.body.append("div"));jt({item:o,tk:e,holder:l.body.append("div")});return}ze(s.lst,e,n,t)}));if(t){i.append("line").attr("stroke",c).attr("y2",l).attr("shape-rendering","crispEdges");i.append("line").attr("stroke",c).attr("x2",(s.x1-s.x0)/2-(s.x-s._x)).attr("y1",l).attr("y2",l+o);i.append("line").attr("stroke",c).attr("x2",-(s.x1-s.x0)/2-(s.x-s._x)).attr("y1",l).attr("y2",l+o)}else{i.append("line").attr("stroke",c).attr("y2",l+o).attr("shape-rendering","crispEdges")}}return l}function we(t,e){let n;let a;if(t._chr!=t.chrA){n=t.chrA;a=t.posA}else if(t._chr!=t.chrB){n=t.chrB;a=t.posB}if(!n)return[null];const s=e.genome.chrlookup[n.toUpperCase()];if(!s){e.error("Invalid chr name: "+n);return[null]}for(const t of e.subpanels){if(t.chr==n){return[null]}}return[s,a]}function Ae(t,e,n){const a=1e4;const s={chr:t.name,start:Math.max(0,e-a),stop:Math.min(t.len,e+a),width:600,leftpad:10,leftborder:"rgba(50,50,50,.1)"};s.exonsf=s.width/(s.stop-s.start);n.init_coord_subpanel(s);n.subpanels.push(s);n.ifbusy()}function je(t,e){const n=e.seekcoord(t.chrA,t.posA);for(const a of n){if(a.ridx!=undefined){if(a.x>0&&a.x<e.width){t.x0=a.x;break}}else if(a.subpanelidx!=undefined){t.x0=a.x}}const a=e.seekcoord(t.chrB,t.posB);for(const n of a){if(n.ridx!=undefined){if(n.x>0&&n.x<e.width){t.x1=n.x;break}}else if(n.subpanelidx!=undefined){t.x1=n.x}}}function Me(t,e,n){e.tktip.clear();Le(t,e.tktip.d,e);e.tktip.show(n.clientX,n.clientY)}function ze(t,e,n,s){const o=a({x:s.clientX,y:s.clientY});Le(t,o.body,e)}function Le(t,e,n){const a=e.append("table");for(const e of t){const t=a.append("tr");t.append("td").style("font-size",".7em").text(e.dt==k?"SV":"Fusion");t.append("td").text(yn(e));t.append("td").style("font-size",".8em").html(qt(e,n))}}function Se(t,e){t.cnvrightg.selectAll("*").remove();const n=[];if(t.sampleAttribute&&t.sampleAttribute.attributes&&t.sampleAttribute.samples){for(const e in t.sampleAttribute.attributes){const a=t.sampleAttribute.attributes[e];if(!a.showintrack)continue;const s={key:e,label:a.label,min:null,max:null};for(const n of t.samplegroups){for(const a of n.samples){const n=t.sampleAttribute.samples[a.samplename];if(!n)continue;const o=n[e];if(Number.isNaN(o))continue;if(s.min==null){s.min=s.max=o}else{s.min=Math.min(s.min,o);s.max=Math.max(s.max,o)}}}n.push(s)}}const a=new Set;if(t._data){for(const e of t._data){if(!e.samples)continue;for(const t of e.samples){if(!t.expressionrank)continue;for(const e in t.expressionrank){a.add(e)}}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes){for(const t of n.genes){a.add(t.gene)}}}}const s=t.gecfg?t.gecfg.fixed:[];let o;if(t.selectedgene&&a.has(t.selectedgene)){o=t.selectedgene}else{o=[...a][0]}if(o){for(const t of s){if(o==t.gene){o=undefined;break}}}if(o){t.showinggene=o}else if(s[0]){t.showinggene=s[0].name}for(const e of t.samplegroups){for(const t of e.samples){if(t.expressionrank){for(const e in t.expressionrank){if(t.expressionrank[e].ase);}}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes&&n.genes.find((t=>t.gene==o)));}}for(const e of t.samplegroups){for(const t of e.samples){t.columnbars=[]}}let l=0;l+=Ue(o,a,t,e);for(const n of s){l+=qe(n,t,e,l)}for(const a of n){l+=Be(a,t,e,l)}if(t.gecfg&&t.gecfg.fixed_pend){const n=t.gecfg.fixed_pend.shift();if(t.gecfg.fixed_pend.length==0){delete t.gecfg.fixed_pend}Oe(n.gene,t,e)}t.rightheadw_tk=l;e.rightheadw=0;for(const t of e.tklst){e.rightheadw=Math.max(e.rightheadw,t.rightheadw_tk)}e.blocksetw();const i=0;const r=3;const c=5;const p=12;return p+p+r+c+i}function Ne(t){const{gene:e,samplename:n,value:s,tk:o,block:l}=t;const i=a({x:window.innerWidth/2,y:100});i.header.text(e+" "+o.gecfg.datatype+" from "+o.name);const r=o.gene2coord[e];if(!r){i.body.text("No coordinate for "+e);return}const c={gene:e,chr:r.chr,start:r.start,stop:r.stop,holder:i.body,block:l,genome:l.genome,sample:n?{name:n,value:s}:null,sampleset:o.sampleset};if(o.iscustom){for(const t in o.checkexpressionrank){c[t]=o.checkexpressionrank[t]}}else{const t=o.mds.queries[o.querykey].checkexpressionrank;c.dslabel=o.mds.label;c.querykey=t.querykey;c.boxplotgroupers=t.boxplotgroupers}c.color={cnvgain:o.cnvcolor.gain.str,cnvloss:o.cnvcolor.loss.str,sv:"black"};if(o.iscustom){c.svcnv={iscustom:1,file:o.file,url:o.url,indexURL:o.indexURL}}else{c.svcnv={dslabel:o.mds.label,querykey:o.querykey}}c.svcnv.valueCutoff=o.valueCutoff;c.svcnv.bplengthUpperLimit=o.bplengthUpperLimit;c.clicksample=(t,e,n)=>{const a={samplename:t.sample};let s;if(e){s={attributes:e.attributes}}const o={};for(const t in n.svcnv){o[t]=n.svcnv[t]}if(n.svcnv.iscustom){o.checkexpressionrank={file:n.file,url:n.url,indexURL:n.indexURL,datatype:n.gecfg.datatype}}else{o.mds=n.block.genome.datasets[n.svcnv.dslabel]}zn({m:{dt:h,chr:n.chr,start:n.start,stop:n.stop},sample:a,samplegroup:s,tk:o,block:n.block})};import("./block.mds.geneboxplot-552fe571.js").then((t=>{t.init(c)}))}function Ue(t,e,n,a){const s=80;const o=15;const l=0;const i=3;const r=5;const c=12;if(t){let p=0;let d=100;if(n.checkrnabam){d=0;for(const e in n.checkrnabam.samples){const a=n.checkrnabam.samples[e];if(a.genes){const e=a.genes.find((e=>e.gene==t));if(e){d=Math.max(d,e.fpkm)}}}}for(const e of n.samplegroups){let o=e.y;for(const l of e.samples){const e=n.cnvrightg.append("g").attr("transform","translate(0,"+o+")");if(l.expressionrank){const o=l.expressionrank[t];if(o!=undefined){e.append("rect").attr("fill",X(o,n.gecfg)).attr("width",s*o.rank/d).attr("height",l.height).attr("shape-rendering","crispEdges");const i=e.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",s).attr("height",l.height);if(n.isfull){l.columnbars.push(i)}i.on("mouseover",(e=>{n.tktip.clear();He(t,o,l,n.tktip.d,n);n.tktip.show(e.clientX,e.clientY);kn(l)})).on("mouseout",(()=>{n.tktip.hide();vn(l)})).on("click",(()=>{Ne({gene:t,samplename:l.samplename,value:o.value,tk:n,block:a})}))}}else if(n.checkrnabam){const o=n.checkrnabam.samples[l.samplename];if(o&&o.genes){const i=o.genes.find((e=>e.gene==t));if(i){Te(s,d,e,i,l,n,a)}}}o+=l.height+n.rowspace}}const f=n.cnvrightg.append("g").attr("transform","translate(0,-"+l+")");q({axis:f.append("g").call(tt().scale(N().domain([p,d]).range([0,s])).tickValues([0,d]).tickSize(r)),fontsize:c,showline:1});f.append("text").attr("text-anchor","middle").attr("x",s/2).attr("y",-(c+i+r+l)).attr("font-family",U).attr("font-size",c).text(t+" "+(n.checkrnabam?n.gecfg.datatype:"rank")).attr("class","sja_clbtext2").on("click",(()=>{Ce(t,e,n,a)}));return s+o}if(n.gecfg){const t=n.cnvrightg;t.append("text").attr("class","sja_clbtext2").attr("font-family",U).attr("font-size",14).text("ADD GENE").on("click",(t=>{Ie(n.tkconfigtip.clear().d,n,a);n.tkconfigtip.showunder(t.target)}));if(n.expressionrangelimit){const e=15;let a=20;t.append("text").text("Zoom in").attr("y",a).attr("font-size",12);a+=e;t.append("text").text("under").attr("y",a).attr("font-size",12);a+=e;t.append("text").text(_(n.expressionrangelimit)).attr("y",a).attr("font-size",12);a+=e;t.append("text").text("to show").attr("y",a).attr("font-size",12);a+=e;t.append("text").text("gene exp").attr("y",a).attr("font-size",12)}return s+o}return 0}function qe(t,e,n,a){if(!e.gene2coord)e.gene2coord={};e.gene2coord[t.gene]={chr:t.chr,start:t.start,stop:t.stop};const s=80;const o=15;const l=0;const i=3;const r=5;const c=12;let p=0,d=100;if(t.sample2rnabam){d=0;for(const e in t.sample2rnabam){d=Math.max(d,t.sample2rnabam[e].fpkm)}}for(const o of e.samplegroups){let l=o.y;for(const i of o.samples){const o=e.cnvrightg.append("g").attr("transform","translate("+a+","+l+")");if(t.sample2rnabam){const a=t.sample2rnabam[i.samplename];if(a){Te(s,d,o,a,i,e,n)}}else{const a=t.sample2rank[i.samplename];if(a){o.append("rect").attr("fill",X(a,e.gecfg)).attr("width",s*a.rank/d).attr("height",i.height).attr("shape-rendering","crispEdges");if(e.isfull&&a.estat){if(a.estat.outlier){o.append("circle").attr("cx",s).attr("cy",i.height/2).attr("r",i.height/2).attr("fill",e.gecfg.outlier.color_outlier)}else if(a.estat.outlier_asehigh){o.append("circle").attr("cx",s).attr("cy",i.height/2).attr("r",i.height/2).attr("fill",e.gecfg.outlier.color_outlier_asehigh)}}const l=o.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",s).attr("height",i.height);if(e.isfull){i.columnbars.push(l)}l.on("mouseover",(n=>{e.tktip.clear();const s=[{k:"Sample",v:i.samplename}];Et(i.samplename,e,s);s.push({k:t.gene+" rank",v:j(a.rank)});s.push({k:t.gene+" "+e.gecfg.datatype,v:a.value});const o=f(e.tktip.d,s);J(a,e.gecfg,o);e.tktip.show(n.clientX,n.clientY);kn(i)})).on("mouseout",(()=>{e.tktip.hide();vn(i)})).on("click",(()=>{Ne({gene:t.gene,samplename:i.samplename,value:a.value,tk:e,block:n})}))}}l+=i.height+e.rowspace}}const m=e.cnvrightg.append("g").attr("transform","translate("+a+",-"+l+")");q({axis:m.append("g").call(tt().scale(N().domain([p,d]).range([0,s])).tickValues([p,d]).tickSize(r)),fontsize:c,showline:1});m.append("text").attr("text-anchor","middle").attr("x",s/2).attr("y",-(c+i+r+l)).attr("font-family",U).attr("font-size",c).attr("fill","black").attr("class","sja_clbtext2").text(t.gene+" rank").on("click",(a=>{Ee(t,e,n);e.tkconfigtip.showunder(a.target)}));return s+o}function Be(t,e,n,a){const s=80;const o=80;const l=15;const i=0;const r=3;const c=5;const p=12;for(const n of e.samplegroups){let s=n.y;for(const l of n.samples){const n=e.cnvrightg.append("g").attr("transform","translate("+a+","+s+")");const i=e.sampleAttribute.samples[l.samplename];if(i){const a=i[t.key];if(!Number.isNaN(a)){n.append("rect").attr("x",0).attr("width",Math.max(1,o*(a-t.min)/(t.max-t.min))).attr("height",l.height).attr("fill","#858585").attr("shape-rendering","crispEdges");n.append("rect").attr("x",0).attr("width",o).attr("height",l.height).attr("fill","#858585").attr("fill-opacity",.1);const s=n.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",o).attr("height",l.height);l.columnbars.push(s);s.on("mouseover",(t=>{e.tktip.clear();const n=[{k:"Sample",v:l.samplename}];Et(l.samplename,e,n);f(e.tktip.d,n);e.tktip.show(t.clientX,t.clientY);kn(l)})).on("mouseout",(()=>{e.tktip.hide();vn(l)}))}}s+=l.height+e.rowspace}}const d=e.cnvrightg.append("g").attr("transform","translate("+a+",-"+i+")");q({axis:d.append("g").attr("transform","translate(0,0)").call(tt().scale(N().domain([t.min,t.max]).range([0,o])).ticks(3)),fontsize:p,showline:1});d.append("text").attr("x",o/2).attr("text-anchor","middle").attr("y",-(p+r+c+i)).attr("font-family",U).attr("font-size",p).text(t.label);return s+l}function Ce(t,e,n,a){n.tkconfigtip.clear();const s=n.tkconfigtip.d;Ie(s,n,a);if(e.size>1){const o=s.append("div").style("margin-bottom","15px");if(e.size>8){o.style("height","200px").style("padding","15px").style("overflow-y","scroll").style("resize","vertical")}const l=Math.random().toString();for(const s of e){const e=o.append("div");const i=Math.random().toString();const r=e.append("input").attr("type","radio").attr("id",i).attr("name",l).on("change",(()=>{n.tkconfigtip.hide();n.selectedgene=s;Se(n,a)}));if(s==t)r.attr("checked",1);e.append("label").attr("for",i).attr("class","sja_clbtext").html("&nbsp;"+s)}}De(s,t,n,a);if(n.mds){Ve(s,{gene:t,chr:n.gene2coord[t].chr,start:n.gene2coord[t].start,stop:n.gene2coord[t].stop},n,a)}Re(s,n,a);n.tkconfigtip.showunder(event.target)}function Ee(t,e,n){e.tkconfigtip.clear();De(e.tkconfigtip.d,t.gene,e,n);Ve(e.tkconfigtip.d,t,e,n);e.tkconfigtip.d.append("div").attr("class","sja_menuoption").text("Remove").on("click",(()=>{e.tkconfigtip.hide();const a=e.gecfg.fixed.findIndex((e=>e.gene==t.gene));if(a==-1){return}e.gecfg.fixed.splice(a,1);Se(e,n)}))}function Re(t,e,n){if(!e.gecfg||e.gecfg.no_ase)return;t.append("div").text("Customize ASE parameters").attr("class","sja_menuoption").on("click",(()=>{t.selectAll("*").remove();Z(t,e.gecfg,e,(()=>{e.tkconfigtip.hide();An(e);Se(e,n)}))}))}function Ve(t,e,n,s){if(!n.mds||!n.mds.survivalplot)return;t.append("div").text("Survival plot by "+e.gene+" "+n.gecfg.datatype).attr("class","sja_menuoption").on("click",(()=>{n.tkconfigtip.hide();const t=a({x:100,y:100});t.header.text("Survival plot by "+e.gene+" "+n.gecfg.datatype);const o={genome:s.genome,mds:n.mds,plotlist:[{renderplot:1,samplerule:{set:{geneexpression:1,bymedian:1,gene:e.gene,chr:e.chr,start:e.start,stop:e.stop}}}]};import("./mds.survivalplot-f440db10.js").then((e=>{e.init(o,t.body,s.debugmode)}))}))}function Ie(t,e,n){O({div:t,genome:n.genome.name,tip:e.tip2,callback:t=>{Oe(t,e,n)}})}async function Oe(t,e,n,a){e.tkconfigtip.clear();const s=e.tkconfigtip.d.append("div").text("Searching for "+t+" ...");try{const o=await z("genelookup",{body:{genome:n.genome.name,input:t,deep:1}});if(o.error)throw o.error;if(!o.gmlst)throw".gmlst[] missing";const l=o.gmlst[0];s.text("Loading "+e.gecfg.datatype+" for "+l.name+" ...");const i=await Fe(l,e,n);if(i.error)throw i.error;const r={gene:t,chr:l.chr,start:l.start,stop:l.stop};if(i.sample2rnabam){for(const t in i.sample2rnabam){W(i.sample2rnabam[t],e.gecfg)}r.sample2rnabam=i.sample2rnabam}else{if(!i.sample2rank)throw".sample2rank{} missing";for(const t in i.sample2rank){W(i.sample2rank[t],e.gecfg)}r.sample2rank=i.sample2rank}e.gecfg.fixed.push(r);e.tkconfigtip.hide();if(a){}else{Se(e,n)}}catch(t){if(t.stack)console.log(t.stack);s.text("Error: "+(t.message?t.message:t))}}function Fe(t,e,n){const a={genome:n.genome.name,getexpression4gene:{chr:t.chr,start:t.start,stop:t.stop,name:t.name}};if(e.iscustom){a.iscustom=1;const t=e.checkexpressionrank;if(t){a.checkexpressionrank={file:t.file,url:t.url,indexURL:t.indexURL}}if(e.checkvcf){a.checkvcf=e.checkvcf.stringifiedObj}if(e.checkrnabam){Ln(e,a,true)}}else{a.dslabel=e.mds.label;a.querykey=e.querykey}return d("mdssvcnv",a)}function He(t,e,n,a,s){const o=[{k:"Sample",v:n.samplename}];Et(n.samplename,s,o);if(s.checkrnabam){o.push({k:t+" "+s.gecfg.datatype,v:e.fpkm})}else{o.push({k:t+" rank",v:j(e.rank)});o.push({k:t+" "+s.gecfg.datatype,v:e.value})}const l=f(a,o);J(e,s.gecfg,l)}function Pe(t,e,n,o){const l=a({x:window.innerWidth/2,y:100});l.header.text(t.gene+" in "+e.samplename);const i=l.body.append("div").style("margin","10px 0px 20px 0px");if(n.checkrnabam&&n.checkvcf){const a=n.checkrnabam.samples[e.samplename];if(a){const l={type:s.ase,name:e.samplename+" ASE",samplename:e.samplename,rnabamfile:a.file,rnabamurl:a.url,rnabamindexURL:a.indexURL,rnabamtotalreads:a.totalreads,rnabamispairedend:a.pairedend,vcffile:n.checkvcf.file,vcfurl:n.checkvcf.url,vcfindexURL:n.checkvcf.indexURL};Ln(n,l,false);const r={style:{margin:"0px"},tklst:[l],holder:i,chr:t.chr,start:t.start,stop:t.stop};F(o.genome,r.tklst);const c=o.newblock(r);if(o.debugmode){window.bbb=c}}else{i.text("sbam missing")}}else{i.text("checkrnabam or checkvcf missing")}He(t.gene,t,e,l.body,n)}function Te(t,e,n,a,s,o,l){n.append("rect").attr("fill",X(a,o.gecfg)).attr("width",t*a.fpkm/e).attr("height",s.height).attr("shape-rendering","crispEdges");const i=n.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",t).attr("height",s.height);if(o.isfull){s.columnbars.push(i)}i.on("mouseover",(t=>{o.tktip.clear();He(a.gene,a,s,o.tktip.d,o);o.tktip.show(t.clientX,t.clientY);kn(s)})).on("mouseout",(()=>{o.tktip.hide();vn(s)})).on("click",(()=>{Pe(a,s,o,l)}))}function De(t,e,n,a){if(n.checkrnabam)return;t.append("div").text(e+" "+n.gecfg.datatype+" boxplot").attr("class","sja_menuoption").on("click",(()=>{n.tkconfigtip.hide();Ne({gene:e,tk:n,block:a})}))}const Ye="#858585";const Ge="#E8FFFF";const Xe="#222";const Je="#ED8600";const Ze=7;const We=5;const $e="#aaa";const Ke=5;const Qe="CELLLINE";const tn=0;const en=5;const nn=N().domain([1,3,5,10]).range([8,4,2,1]);function an(t,e){e.tkcloakon(t);e.block_setheight();if(t.uninitialized){qn(t,e);delete t.uninitialized}Promise.resolve().then((()=>ln(t,e))).then((()=>on(t,e))).then((()=>rn(t,e))).catch((n=>{t.height_main=50;if(n.nodata){cn(t);delete t.data_vcf;if(t.singlesample){delete t.data}else{delete t._data;delete t.samplegroups;sn(t,e)}Qt(t,e);return{error:t.name+": no data in view range"}}if(n.stack)console.error(n.stack);return{error:n.message}})).then((n=>{e.tkcloakoff(t,{error:n.error});e.block_setheight();e.setllabel()}))}function sn(t,e){const n=[];if(t.gene2coord){for(const e in t.gene2coord)n.push(e)}if(n.length==0)return;if(!t.gecfg){console.error("but .gecfg is missing");return}t.cnvrightg.attr("transform","translate(0,"+(4+t.height_main/2)+")");const a=t.cnvrightg.append("text").attr("font-size",12).attr("class","sja_clbtext2");if(n.length==1){a.text(n[0]).on("click",(a=>{const s=t.gene2coord[n[0]];Ee({gene:n[0],chr:s.chr,start:s.start,stop:s.stop},t,e);t.tkconfigtip.showunder(a.target)}));return}a.text("Select gene").on("click",(()=>{t.tkconfigtip.clear().showunder(a.node());for(const a of n){t.tkconfigtip.d.append("div").text(a).attr("class","sja_menuoption").on("click",(()=>{const n=t.gene2coord[a];Ee({gene:a,chr:n.chr,start:n.start,stop:n.stop},t,e)}))}}))}function on(t,e){if(!t.checkrnabam)return;const n=[];for(const a in t.checkrnabam.samples){const s=t.checkrnabam.samples[a];n.push(d("bamnochr",{genome:e.genome.name,file:s.file,url:s.url,indexURL:s.indexURL}).then((t=>{if(t.error)throw{message:t.error};s.nochr=t.nochr})))}return Promise.all(n)}function ln(t,e){if(!t.iscustom)return;if(t.checkvcf&&!t.checkvcf.stringifiedObj){const n=["genome="+e.genome.name];if(t.checkvcf.file){n.push("file="+t.checkvcf.file)}else{n.push("url="+t.checkvcf.url);if(t.checkvcf.indexURL)n.push("indexURL="+t.checkvcf.indexURL)}return H("vcfheader?"+n.join("&")).then((e=>{if(!e)throw{message:"server error!"};if(e.error)throw{message:e.error};const[n,a,s,o]=at(e.metastr.split("\n"));if(o)throw{message:"Error parsing VCF meta lines: "+o.join("; ")};t.checkvcf.info=n;t.checkvcf.format=a;t.checkvcf.samples=s;t.checkvcf.nochr=e.nochr;t.checkvcf.stringifiedObj=JSON.stringify(t.checkvcf)}))}}function rn(t,e){const n={genome:e.genome.name,rglst:e.tkarg_maygm(t)};if(e.subpanels.length==t.subpanels.length){for(const[t,a]of e.subpanels.entries()){n.rglst.push({chr:a.chr,start:a.start,stop:a.stop,width:a.width,exonsf:a.exonsf,subpanelidx:t})}}pn(n,t);return d("/mdssvcnv",n).then((n=>{if(n.error)throw{message:n.error};t._data_vcf=n.data_vcf;t.vcfrangelimit=n.vcfrangelimit;Yn(t,e);Dn(t,e);if(t.singlesample){if(!n.lst||n.lst.length==0){if(!t.data_vcf||t.data_vcf.length==0){throw{nodata:1}}}t.data=n.lst}else{t.gene2coord=n.gene2coord;t.expressionrangelimit=n.expressionrangelimit;if(!n.samplegroups||n.samplegroups.length==0){throw{nodata:1}}t._data=n.samplegroups;if(t.sampleAttribute){if(n.sampleannotation){t.sampleAttribute.samples=n.sampleannotation}else{t.sampleAttribute.samples={}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){delete t.checkrnabam.samples[e].genes;if(n.checkrnabam){const a=n.checkrnabam.find((t=>t.sample==e));if(a)t.checkrnabam.samples[e].genes=a.genes}}}}if(t.legend_svchrcolor){t.legend_svchrcolor.interchrs.clear();t.legend_svchrcolor.row.style("display","none")}if(t.singlesample){be(t,e)}else{dn(t,e)}return{}}))}function cn(t){if(t.singlesample){t.waterfall.axisg.selectAll("*").remove();t.waterfall.lab1.text("");t.waterfall.lab2.text("");t.waterfall.lab3.text("");t.svvcf_g.selectAll("*").remove();t.cnv_g.selectAll("*").remove();if(t.cnvcolor.cnvlegend)t.cnvcolor.cnvlegend.row.style("display","none");if(t.cnvcolor.lohlegend)t.cnvcolor.lohlegend.row.style("display","none");return}t.cnvleftg.selectAll("*").remove();t.vcfdensitylabelg.selectAll("*").remove();t.vcfdensityg.selectAll("*").remove();t.svdensitylabelg.selectAll("*").remove();t.svdensityg.selectAll("*").remove();t.cnvmidg.selectAll("*").remove();t.cnvrightg.selectAll("*").remove();t.config_handle.transition().attr("text-anchor","start").attr("x",0)}function pn(t,e){if(e.iscustom){t.iscustom=1;t.file=e.file;t.url=e.url;t.indexURL=e.indexURL;if(e.checkexpressionrank){t.checkexpressionrank={};for(const n in e.checkexpressionrank){t.checkexpressionrank[n]=e.checkexpressionrank[n]}}if(e.checkvcf){t.checkvcf=e.checkvcf.stringifiedObj}if(e.checkrnabam){Ln(e,t,true)}}else{t.dslabel=e.mds.label;t.querykey=e.querykey}if(e.getallsamples){t.getallsamples=true}if(e.sampleset)t.sampleset=e.sampleset;if(e.valueCutoff)t.valueCutoff=e.valueCutoff;if(Number.isInteger(e.bplengthUpperLimit))t.bplengthUpperLimit=e.bplengthUpperLimit;if(e.showonlycnvwithsv)t.showonlycnvwithsv=1;t.hide_cnvgain=e.hide_cnvgain;t.hide_cnvloss=e.hide_cnvloss;if(e.segmeanValueCutoff)t.segmeanValueCutoff=e.segmeanValueCutoff;if(Number.isInteger(e.lohLengthUpperLimit))t.lohLengthUpperLimit=e.lohLengthUpperLimit;if(e.singlesample){t.singlesample=e.singlesample.name}else{if(e.sampleAttribute){const n={};let a=false;for(const t in e.sampleAttribute.attributes){const s=e.sampleAttribute.attributes[t];if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}if(a){t.hiddensampleattr=n}}}if(e.mutationAttribute){const n={};let a=false;for(const t in e.mutationAttribute.attributes){const s=e.mutationAttribute.attributes[t];if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}if(a){t.hiddenmattr=n}}if(e.alleleAttribute){const n={};let a=false;for(const t in e.alleleAttribute.attributes){const s=e.alleleAttribute.attributes[t];if(s.disable)continue;if(s.isnumeric){if(Number.isFinite(s.cutoffvalue)){n[t]={cutoffvalue:s.cutoffvalue,keeplowerthan:s.keeplowerthan};a=true}}else{if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}}if(a){t.filteralleleattr=n}}if(e.locusAttribute){const n={};let a=false;for(const t in e.locusAttribute.attributes){const s=e.locusAttribute.attributes[t];if(s.disable)continue;if(s.isnumeric){if(Number.isFinite(s.cutoffvalue)){n[t]={cutoffvalue:s.cutoffvalue,keeplowerthan:s.keeplowerthan};a=true}}else{if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}}if(a){t.filterlocusattr=n}}{const n=[];for(const t of e.legend_mclass.hiddenvalues){if(Number.isInteger(t))n.push(t)}if(n.length){t.hiddendt=n}}}function dn(t,e){cn(t);let n=e.labelfontsize;if(t.versionlabel)n+=e.labelfontsize;const[a,s]=Sn(t,e);t.samplegroups=a;const o=fn(t,e);const l=un(s,t,e);const i=gn(t,e);An(t);wn(t);const r=Se(t,e);const c=o&&l?3:0;let p=Math.max(n,o+l+c,r);if(o){p+=Math.max(0,n+8-(p-l-c-o/2))}else if(l){p+=Math.max(0,n+8-(p-l/2))}if(r==0||p>r+3+e.labelfontsize){t.config_handle.transition().attr("text-anchor","start").attr("x",0)}else{t.config_handle.transition().attr("text-anchor","end").attr("x",-e.rpad)}t.cnvleftg.transition().attr("transform","translate(0,"+p+")");t.cnvmidg.transition().attr("transform","translate(0,"+p+")");t.vcfdensityg.transition().attr("transform","translate(0,"+(p-l-c)+")");t.svdensityg.transition().attr("transform","translate(0,"+p+")");t.cnvrightg.transition().attr("transform","translate(0,"+p+")");{const n="#858585";if(o&&t.data_vcf){let a=0;for(const e of t.data_vcf){if(e.x==undefined)continue;if(e.dt==x){a+=e.sampledata.length}else{console.error("unknown dt from data_vcf")}}const s=[];if(a)s.push(a+" SNV/indel"+(a>1?"s":""));t.vcfdensitylabelg.attr("transform","translate(0,"+(p-o-c-l)+")").append("text").text(s.join(", ")).attr("text-anchor","end").attr("x",e.tkleftlabel_xshift).attr("y",o/2).attr("dominant-baseline","central").attr("font-size",Math.min(e.labelfontsize,o)-1).attr("font-family",U).attr("fill",n).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)}));t.vcfdensitylabelg.append("line").attr("stroke",n).attr("y2",o).attr("shape-rendering","crispEdges");t.vcfdensitylabelg.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",-Ke).attr("y1",o/2).attr("y2",o/2);t.vcfdensitylabelg.append("line").attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("stroke-dasharray","1,3").attr("x2",e.width).attr("y1",o).attr("y2",o)}if(l){t.svdensitylabelg.attr("transform","translate(0,"+(p-l)+")").append("text").text(s.length+" SV breakpoint"+(s.length>1?"s":"")).attr("text-anchor","end").attr("x",e.tkleftlabel_xshift).attr("y",l/2).attr("dominant-baseline","central").attr("font-size",Math.min(e.labelfontsize,l)-1).attr("font-family",U).attr("fill",n).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)}));t.svdensitylabelg.append("line").attr("stroke",n).attr("y2",l).attr("shape-rendering","crispEdges");t.svdensitylabelg.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",-Ke).attr("y1",l/2).attr("y2",l/2);t.svdensitylabelg.append("line").attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("stroke-dasharray","1,3").attr("x2",e.width).attr("y1",l).attr("y2",l)}}t.height_main=t.toppad+p+i+t.bottompad;Qt(t,e)}function fn(t,e){if(t.vcfrangelimit){t.vcfdensityg.append("text").text("Zoom in under "+_(t.vcfrangelimit)+" to show SNV/indel density").attr("font-size",e.labelfontsize).attr("font-family",U);return e.labelfontsize}if(!t.isdense)return 0;if(!t.data_vcf||t.data_vcf.length==0)return 0;const n=mn(t,e);for(const t of n){if(t.lst.length==0)continue;const e=new Map;for(const n of t.lst){if(!e.has(n.class)){e.set(n.class,[])}e.get(n.class).push(n)}const n=[];for(const[t,a]of e){let e=0;for(const t of a){if(t.dt==x){e+=t.sampledata.length}else{console.error("unknown dt")}}n.push({name:y[t].label,items:a,color:y[t].color,samplecount:e})}n.sort(((t,e)=>e.samplecount-t.samplecount));t.groups=n}let a=0;for(const t of n){if(!t.groups)continue;for(const e of t.groups){a=Math.max(a,e.samplecount)}}let s=0;{const t=4;let e=0;const o=Math.pow(t,2)*Math.PI;if(a<=3){e=o*a*.9}else if(a<=10){e=o*5}else if(a<=100){e=o*7}else{e=o*10}const l=N().domain([1,a*.5+.1,a*.6+.1,a*.7+.1,a*.8+.1,a]).range([o,o+(e-o)*.8,o+(e-o)*.85,o+(e-o)*.9,o+(e-o)*.95,e]);for(const t of n){if(!t.groups)continue;for(const e of t.groups){e.radius=Math.sqrt(l(e.samplecount)/Math.PI)}const e=t.groups.reduce(((t,e)=>e.samplecount+t),0);t.offset=Math.sqrt(l(e)/Math.PI);const n=t.groups.reduce(((t,e)=>t+e.radius*2),0);s=Math.max(s,t.offset+n)}}for(const a of n){if(!a.groups)continue;const n=t.vcfdensityg.append("g").attr("transform","translate("+a.x+",0)");let s=a.offset;for(const o of a.groups){s+=o.radius;n.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill",o.color).attr("stroke","white");if(o.radius>=8){const t=o.radius*1.5;const e=o.samplecount.toString();const a=Math.min(t/(e.length*I),t);n.append("text").text(e).attr("y",-s).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-size",a).attr("font-family",U).attr("fill","white")}n.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",o.color).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(()=>{_t(o,t,e)})).on("mouseout",(()=>{t.tktip.hide()})).on("click",(()=>{yt(o,t,e)}));s+=o.radius}n.append("line").attr("y2",-a.offset).attr("stroke",a.groups[0].color)}return s}function mn(t,e){if(e.exonsf>=3){const e=new Map;for(const n of t.data_vcf){if(n.x==undefined)continue;if(!e.has(n.pos)){e.set(n.pos,{x:n.x,lst:[]})}e.get(n.pos).lst.push(n)}const n=[];for(const t of e.values()){n.push(t)}return n}const n=10;const a=[];let s=0;while(s<e.width){a.push({x1:s,x2:s+n,x:s+n/2,lst:[]});s+=n}s=e.width;for(const t of e.subpanels){s+=t.leftpad;let e=0;while(e<t.width){a.push({x1:s+e,x2:s+e+n,lst:[]});e+=n}s+=t.width}for(const e of t.data_vcf){if(e.x==undefined){continue}for(const t of a){if(t.x1<=e.x&&t.x2>=e.x){t.lst.push(e);break}}}return a}function un(t,e,n){if(!e.isdense||t.length==0)return 0;const a=hn(t,e,n);const s=[];for(const t of a){if(t.lst.length==0)continue;const e={};for(const n in t){e[n]=t[n]}e.lst=Gn(t.lst);s.push(e)}for(const t of s){const n=new Map;const a=[];for(const e of t.lst){if(e._samplegroup.name){if(!n.has(e._samplegroup.name)){n.set(e._samplegroup.name,[])}n.get(e._samplegroup.name).push(e)}else{a.push(e)}}const s=[];if(a.length){s.push({items:a,color:$e})}for(const[t,a]of n){s.push({name:t,items:a,color:e.legend_samplegroup?e.legend_samplegroup.color(t):"#aaa"})}s.sort(((t,e)=>e.items.length-t.items.length));t.groups=s}let o=0;for(const t of s){for(const e of t.groups){o=Math.max(o,e.items.length)}}let l=0;{const t=4;let e=0;const n=Math.pow(t,2)*Math.PI;if(o<=3){e=n*o*.9}else if(o<=10){e=n*5}else if(o<=100){e=n*7}else{e=n*10}const a=N().domain([1,o*.5+.1,o*.6+.1,o*.7+.1,o*.8+.1,o]).range([n,n+(e-n)*.8,n+(e-n)*.85,n+(e-n)*.9,n+(e-n)*.95,e]);for(const t of s){if(!t.groups)continue;for(const e of t.groups){e.radius=Math.sqrt(a(e.items.length)/Math.PI)}t.offset=Math.sqrt(a(t.lst.length)/Math.PI);const e=t.groups.reduce(((t,e)=>t+e.radius*2),0);l=Math.max(l,t.offset+e)}}for(const t of s){const a=e.svdensityg.append("g").attr("transform","translate("+t.x+",0)");let s=t.offset;for(const o of t.groups){s+=o.radius;a.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill",o.color).attr("stroke","white");if(o.radius>=8){const t=o.radius*1.5;const e=o.items.length.toString();const n=Math.min(t/(e.length*I),t);a.append("text").text(e).attr("y",-s).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-size",n).attr("font-family",U).attr("fill","white")}a.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",o.color).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(()=>{vt(o,e,n)})).on("mouseout",(()=>{e.tktip.hide()})).on("click",(()=>{xt(o,e,n)}));s+=o.radius}a.append("line").attr("y2",-t.offset).attr("stroke",t.groups[0].color)}return l}function hn(t,e,n){if(n.exonsf>=3){const e=new Map;for(const n of t){if(n.x==undefined)continue;if(!e.has(n._pos)){e.set(n._pos,{x:n.x,lst:[]})}e.get(n._pos).lst.push(n)}const n=[];for(const t of e.values()){n.push(t)}return n}const a=10;const s=[];let o=0;while(o<n.width){s.push({x1:o,x2:o+a,x:o+a/2,lst:[]});o+=a}o=n.width;for(const t of n.subpanels){o+=t.leftpad;let e=0;while(e<t.width){s.push({x1:o+e,x2:o+e+a,lst:[]});e+=a}o+=t.width}for(const e of t){for(const t of s){if(t.x1<=e.x&&t.x2>=e.x){t.lst.push(e);break}}}return s}function gn(t,e){{const e=[],n=[],a=[];for(const s of t.samplegroups){for(const t of s.samples){for(const s of t.items){if(s.dt==g){a.push(s.segmean);continue}if(s.dt==h){if(s.value>0)e.push(s.value);else n.push(-s.value)}}}}const s=P(e,tn);const o=-P(n,tn);t.cnvcolor.cnvmax=Math.max(s,-o);if(a.length){t.cnvcolor.segmeanmax=Math.max(...a)}else{t.cnvcolor.segmeanmax=tn}}let n;if(t.isdense){t.rowspace=0;n=4}else if(t.isfull){t.rowspace=1;n=10}const a=e.width+e.subpanels.reduce(((t,e)=>t+e.width+e.leftpad),0);xn(t,e);for(const e of t.samplegroups){e.height=t.rowspace*(e.samples.length-1)+e.samples.reduce(((t,e)=>e.height+t),0)}const s=e.labelfontsize-(t.isfull?0:1);let o=n;for(const[l,i]of t.samplegroups.entries()){let l=0;if(i.height<s){l=(s-i.height)/2}if(i.name){const n=t.legend_samplegroup?t.legend_samplegroup.color(i.name):"#0A7FA6";const a=[i.name+" ("+i.samples.length];if(i.sampletotalnum)a.push(", "+Math.ceil(100*i.samples.length/i.sampletotalnum)+"%");if(t.sampleset){const e=t.sampleset.find((t=>t.name==i.name));if(e)a.push(", "+Math.ceil(100*i.samples.length/e.samples.length)+"%")}a.push(")");t.cnvleftg.append("text").attr("font-size",s).attr("font-family",U).attr("y",o+l+i.height/2).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill",n).attr("x",e.tkleftlabel_xshift).text(a.join("")).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)})).on("mouseover",(()=>{bt(i,t)})).on("mouseout",(()=>{t.tktip.hide()})).on("click",(n=>{t.tip2.clear();ft(i,t,e);t.tip2.showunder(n.target)}));t.cnvleftg.append("line").attr("y1",o+l).attr("y2",o+l+i.height).attr("stroke",n).attr("shape-rendering","crispEdges");t.cnvleftg.append("line").attr("y1",o+l+i.height/2).attr("y2",o+l+i.height/2).attr("x2",-Ke).attr("stroke",n).attr("shape-rendering","crispEdges")}let r=o+l;i.y=r;for(const n of i.samples){if(!i.name&&n.samplename&&n.height>=Ze){n.svglabel=t.cnvleftg.append("text").text(n.samplename).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill","black").attr("x",-5).attr("y",r+n.height/2).attr("font-family",U).attr("font-size",Math.min(15,Math.max(Ze,n.height+1))).each((function(){})).on("mouseover",(()=>{kn(n)})).on("mouseout",(()=>{vn(n)}));t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,n.svglabel.node().getBBox().width)}const s=t.cnvmidg.append("g").attr("transform","translate(0,"+r+")");if(t.isfull){n.blockbg=s.append("rect").attr("width",a).attr("height",n.height).attr("fill",Je).attr("fill-opacity",0).on("mouseover",(()=>{kn(n)})).on("mouseout",(()=>{vn(n)}))}if(t.isfull&&n.sampletype==Qe){s.append("rect").attr("x",-5).attr("y",0).attr("width",5).attr("height",n.height).attr("fill","black").attr("shape-rendering","crispEdges")}for(const a of n.items){if(a.dt!=h&&a.dt!=g&&a.dt!=b)continue;let o;if(a.dt==g){if(a.segmean>=t.cnvcolor.segmeanmax){o=t.cnvcolor.loh.str}else{o="rgba("+t.cnvcolor.loh.r+","+t.cnvcolor.loh.g+","+t.cnvcolor.loh.b+","+(a.segmean/t.cnvcolor.segmeanmax).toFixed(2)+")"}}else if(a.dt==h){if(a.value>0){if(a.value>=t.cnvcolor.cnvmax){o=t.cnvcolor.gain.str}else{o="rgba("+t.cnvcolor.gain.r+","+t.cnvcolor.gain.g+","+t.cnvcolor.gain.b+","+(a.value/t.cnvcolor.cnvmax).toFixed(2)+")"}}else{if(a.value<=-t.cnvcolor.cnvmax){o=t.cnvcolor.loss.str}else{o="rgba("+t.cnvcolor.loss.r+","+t.cnvcolor.loss.g+","+t.cnvcolor.loss.b+","+(-a.value/t.cnvcolor.cnvmax).toFixed(2)+")"}}}else if(a.dt==b){o=y[R].color}s.append("rect").attr("x",Math.min(a.x1,a.x2)).attr("y",a.stack_y).attr("width",Math.max(1,Math.abs(a.x1-a.x2))).attr("height",a.stack_h).attr("shape-rendering","crispEdges").attr("stroke","none").attr("class","sja_aa_skkick").attr("fill",o).on("mouseover",(()=>{At({item:a,sample:n,samplegroup:i,tk:t})})).on("mouseout",(()=>{t.tktip.hide();vn(n)})).on("click",(()=>{wt({item:a,sample:n,samplegroup:i,tk:t,block:e})}))}for(const a of n.items){if(a.dt!=k&&a.dt!=v)continue;const o=a.chrA==a._chr?a.chrB:a.chrA;const l=o==a._chr?Ye:t.legend_svchrcolor.colorfunc(o);const r=s.append("g").attr("transform","translate("+a.x+","+n.height/2+")");const c=n.crossboxw;let p=-c/2,d=c;const f=r.append("circle").attr("r",Math.min(5,Math.max(We,1+n.height/2))).attr("fill",l).attr("fill-opacity",0).attr("stroke",l);if(a.labonleft){r.append("text").text(yn(a)).attr("text-anchor","end").attr("dominant-baseline","central").attr("font-family",U).attr("font-size",c+2).attr("fill",l).attr("x",-c/2-en);p=-c/2-en-a.labelwidth;d=c+en+a.labelwidth}else if(a.labonright){r.append("text").text(yn(a)).attr("dominant-baseline","central").attr("font-family",U).attr("font-size",c+2).attr("fill",l).attr("x",c/2+en);d=c+en+a.labelwidth}r.append("rect").attr("x",p).attr("y",-c/2).attr("width",d).attr("height",c).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{f.attr("fill-opacity",1);At({item:a,sample:n,samplegroup:i,tk:t})})).on("mouseout",(()=>{f.attr("fill-opacity",0);t.tktip.hide();vn(n)})).on("click",(()=>{wt({item:a,sample:n,samplegroup:i,tk:t,block:e})}))}if(t.isfull&&t.data_vcf){for(const a of t.data_vcf){if(a.dt!=x)continue;if(a.x==undefined)continue;if(!a.sampledata)continue;const o=n.crossboxw;const l=bn(t,a,n);for(const r of a.sampledata){if(r.sampleobj.name!=n.samplename)continue;const c=s.append("g").attr("transform","translate("+a.x+","+n.height/2+")");const p=c.append("rect").attr("x",-o/2-1).attr("y",-o/2-1).attr("width",o+2).attr("height",o+2).attr("fill",l).attr("fill-opacity",0);let d,f,m,u;if(Xn(r,t)){d=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("y1",-o/2-1).attr("y2",o/2+1);f=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2-1).attr("x2",o/2+1);m=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("y1",-o/2-1).attr("y2",o/2+1);u=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2-1).attr("x2",o/2+1)}else{d=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2).attr("x2",o/2).attr("y1",-o/2).attr("y2",o/2);f=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2).attr("x2",o/2).attr("y1",o/2).attr("y2",-o/2);m=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2).attr("x2",o/2).attr("y1",-o/2).attr("y2",o/2);u=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2).attr("x2",o/2).attr("y1",o/2).attr("y2",-o/2)}let h=-o/2,g=o;if(r.sampleobj.labonleft){c.append("text").text(a.mname).attr("text-anchor","end").attr("dominant-baseline","central").attr("font-family",U).attr("font-size",n.crossboxw+2).attr("fill",l).attr("x",-o/2-en);h=-o/2-en-r.sampleobj.labelwidth;g=o+en+r.sampleobj.labelwidth}else if(r.sampleobj.labonright){c.append("text").text(a.mname).attr("dominant-baseline","central").attr("font-family",U).attr("font-size",n.crossboxw+2).attr("fill",l).attr("x",o/2+en);g=o+en+r.sampleobj.labelwidth}c.append("rect").attr("x",h).attr("y",-o/2).attr("width",g).attr("height",o).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{p.attr("fill-opacity",1);d.attr("stroke-opacity",0);f.attr("stroke-opacity",0);m.attr("stroke","white");u.attr("stroke","white");At({item:a,m_sample:r,sample:n,samplegroup:i,tk:t,block:e})})).on("mouseout",(()=>{t.tktip.hide();p.attr("fill-opacity",0);d.attr("stroke-opacity",1);f.attr("stroke-opacity",1);m.attr("stroke",l);u.attr("stroke",l);vn(n)})).on("click",(()=>{wt({item:a,m_sample:r,sample:n,samplegroup:i,tk:t,block:e})}))}}}r+=n.height+t.rowspace}o+=i.height+l*2+n}if(!t.nocnvlohsv){if(t.cnvcolor.cnvmax==tn){t.cnvcolor.cnvlegend.svg.style("display","none");t.cnvcolor.cnvlegend.nodatadiv.style("display","block")}else{t.cnvcolor.cnvlegend.svg.style("display","block");t.cnvcolor.cnvlegend.nodatadiv.style("display","none");jn(t)}if(t.cnvcolor.segmeanmax==tn){if(t.cnvcolor.lohlegend){t.cnvcolor.lohlegend.svg.style("display","none");t.cnvcolor.lohlegend.nodatadiv.style("display","block")}}else{t.cnvcolor.lohlegend.svg.style("display","block");t.cnvcolor.lohlegend.nodatadiv.style("display","none");Mn(t)}}return o}function bn(t,e,n){if(t.checkrnabam){const a=t.checkrnabam.samples[n.samplename];if(a&&a.genes){for(const n of a.genes){if(n.snps){const a=n.snps.find((t=>t.pos==e.pos&&t.ref==e.ref&&t.alt==e.alt));if(a&&a.rnacount&&a.rnacount.pvalue!=undefined){return t.checkrnabam.clientcolor_snpinuse}}}}return t.checkrnabam.clientcolor_markernotinuse}return y[e.class].color}function kn(t){if(!t)return;if(t.svglabel)t.svglabel.attr("fill",Je);if(t.blockbg)t.blockbg.attr("fill-opacity",.1);if(t.columnbars){for(const e of t.columnbars){e.attr("fill",Je)}}}function vn(t){if(!t)return;if(t.svglabel)t.svglabel.attr("fill",Xe);if(t.blockbg)t.blockbg.attr("fill-opacity",0);if(t.columnbars){for(const e of t.columnbars){e.attr("fill",Xe)}}}function xn(t,e){if(!t.samplegroups||t.samplegroups.length==0)return;if(t.isdense){for(const e of t.samplegroups){for(const t of e.samples){t.height=1;for(const e of t.items){if(e.dt==h||e.dt==g||e.dt==b){e.stack_y=0;e.stack_h=1}}}}return}for(const e of t.samplegroups){for(const t of e.samples){for(const e of t.items){if(e.dt==k||e.dt==v){delete e.labonleft;delete e.labonright}}}}if(t.data_vcf){for(const e of t.data_vcf){if(e.sampledata){for(const t of e.sampledata){if(t.sampleobj){delete t.sampleobj.labonleft;delete t.sampleobj.labonright}}}}}const n=e.width+e.subpanels.reduce(((t,e)=>t+e.leftpad+e.width),0);for(const e of t.samplegroups){for(const a of e.samples){const e=[];for(const t of a.items){if(t.dt==h||t.dt==g||t.dt==b){if(t.x1!=undefined&&t.x2!=undefined){t._boxstart=Math.min(t.x1,t.x2);t._boxwidth=Math.abs(t.x2-t.x1);e.push(t)}}}_n(a,e);a.crossboxw=Math.min(8,a.height);const s=[];for(const e of a.items){if(e.dt==v){if(e.x==undefined)continue;const n={dt:e.dt,x:e.x,obj:e};if(t.multihidelabel_fusion);else{n.name=yn(e)}s.push(n)}else if(e.dt==k){if(e.x==undefined)continue;const n={dt:e.dt,x:e.x,obj:e};if(t.multihidelabel_sv);else{n.name=yn(e)}s.push(n)}}if(t.data_vcf){for(const e of t.data_vcf){if(e.dt!=x||e.x==undefined||!e.sampledata)continue;const n=e.sampledata.find((t=>t.sampleobj.name==a.samplename));if(n){const a={dt:e.dt,x:e.x,obj:n.sampleobj};if(t.multihidelabel_vcf);else{a.name=e.mname}s.push(a)}}}if(s.length>0){s.sort(((t,e)=>t.x-e.x));for(let e=0;e<s.length;e++){const o=s[e];if(!o.name){continue}let l;t.g.append("text").text(o.name).attr("font-size",a.crossboxw+2).attr("font-family",U).each((function(){l=this.getBBox().width})).remove();l+=a.crossboxw/2+en;let i=false,r=false;if(l>o.x){i=true}else if(l>n-o.x){r=true}for(const t of a.items){if(i&&r)break;if(t.dt==h||t.dt==g||t.dt==b){if(t.x1==undefined||t.x2==undefined)continue;const e=Math.min(t.x1,t.x2);const n=Math.max(t.x1,t.x2);if(e<o.x){if(n<o.x){if(l>o.x-n){i=true}}else{i=true;r=true}}else{if(l>e-o.x){r=true}}}}if(i&&r){continue}if(!i){for(let t=e-1;t>=0;t--){const e=s[t];if(e.x==o.x){if(e.obj.labonleft){i=true}else if(e.obj.labonright){r=true}else;}else{if(l>o.x-e.x-(e.obj.labonright?e.obj.labelwidth:0)){i=true;break}else{break}}}}if(i&&r)continue;if(!r){for(let t=e+1;t<s.length;t++){const e=s[t];if(e.x==o.x);else{if(l>e.x-o.x){r=true;break}else{break}}}}if(i&&r)continue;if(i){if(!r){o.obj.labonright=true}}else{if(r){o.obj.labonleft=true}else{o.obj.labonright=true}}if(o.obj.labonleft||o.obj.labonright){o.obj.labelwidth=l}}}}}}function yn(t){if(t.cytogeneticname)return t.cytogeneticname;return(t.geneA||t.chrA)+" > "+(t.geneB||t.chrB)}function _n(t,e){if(e.length==0){t.height=8;return}e.sort(((t,e)=>t._boxstart-e._boxstart));const n=[];for(const t of e){for(let e=0;e<n.length;e++){if(n[e]<t._boxstart){t._stacki=e;n[e]=t._boxstart+t._boxwidth;break}}if(t._stacki==undefined){t._stacki=n.length;n.push(t._boxstart+t._boxwidth)}}let a=nn(n.length);if(a<1){a=1}for(const t of e){t.stack_y=t._stacki*a;t.stack_h=a;delete t._stacki;delete t._boxstart;delete t._boxwidth}t.height=a*n.length}function wn(t){if(!t.checkrnabam)return;for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes){for(const e of n.genes){W(e,t.gecfg)}}}}function An(t){if(!t._data)return;if(!t.gecfg)return;if(t.gecfg.no_ase)return;for(const e of t._data){if(!e.samples)continue;for(const n of e.samples){if(!n.expressionrank)continue;for(const e in n.expressionrank){const a=n.expressionrank[e];W(a,t.gecfg)}}}}function jn(t){t.cnvcolor.cnvlegend.row.style("display","table-row");q({axis:t.cnvcolor.cnvlegend.axisg.call(tt().scale(N().domain([-t.cnvcolor.cnvmax,0,t.cnvcolor.cnvmax]).range([0,t.cnvcolor.cnvlegend.barw,t.cnvcolor.cnvlegend.barw*2])).tickValues([-t.cnvcolor.cnvmax,0,t.cnvcolor.cnvmax]).tickSize(t.cnvcolor.cnvlegend.axistickh))})}function Mn(t){if(!t.cnvcolor.lohlegend)return;t.cnvcolor.lohlegend.row.style("display","table-row");q({axis:t.cnvcolor.lohlegend.axisg.call(tt().scale(N().domain([0,t.cnvcolor.segmeanmax]).range([0,t.cnvcolor.lohlegend.barw])).tickValues([0,t.cnvcolor.segmeanmax]).tickSize(t.cnvcolor.lohlegend.axistickh))})}async function zn(t){const{m:e,sample:n,samplegroup:o,tk:l,block:i}=t;let r;if(t.holder){r=t.holder}else{const t=a({x:100,y:100});r=t.body}const c=r.append("div");const p={style:{margin:"0px"},tklst:[],holder:r,subpanels:[]};F(i.genome,p.tklst);if(l.checkrnabam&&l.checkvcf){const t=l.checkrnabam.samples[n.samplename];if(t){p.chr=i.rglst[0].chr;p.start=i.rglst[0].start;p.stop=i.rglst[0].stop;const e={type:s.ase,name:n.samplename+" ASE",samplename:n.samplename,rnabamfile:t.file,rnabamurl:t.url,rnabamindexURL:t.indexURL,rnabamtotalreads:t.totalreads,vcffile:l.checkvcf.file,vcfurl:l.checkvcf.url,vcfindexURL:l.checkvcf.indexURL};Ln(l,e,false);p.tklst.push(e);const a=i.newblock(p);if(i.debugmode){window.bbb=a}return}}if(l.iscustom){if(l.checkexpressionrank){const t={type:T.mdsexpressionrank,name:n.samplename+" expression rank",sample:n.samplename,iscustom:1};for(const e in l.checkexpressionrank){t[e]=l.checkexpressionrank[e]}p.tklst.push(t)}if(l.sample2assaytrack&&l.sample2assaytrack[n.samplename]){for(const t of l.sample2assaytrack[n.samplename]){p.tklst.push(t)}}}else if(l.mds&&l.mds.queries[l.querykey].checkexpressionrank){if(o){const t={type:T.mdsexpressionrank,name:n.samplename+" expression rank",dslabel:l.mds.label,querykey:l.mds.queries[l.querykey].checkexpressionrank.querykey,sample:n.samplename,attributes:o.attributes};p.tklst.push(t)}}const d={bplengthUpperLimit:0,valueCutoff:l.valueCutoff,lohLengthUpperLimit:l.lohLengthUpperLimit,segmeanValueCutoff:l.segmeanValueCutoff,singlesample:{name:n.samplename}};if(l.iscustom){d.type=T.mdssvcnv;d.file=l.file;d.url=l.url;d.indexURL=l.indexURL;d.iscustom=true;d.legend_vorigin=l.legend_vorigin}else{d.mds=l.mds;d.querykey=l.querykey;for(const t in l.mds.queries[l.querykey]){if(t=="bplengthUpperLimit"||t=="valueCutoff"){continue}d[t]=l.mds.queries[l.querykey][t]}}if(l.iscustom&&l.checkvcf){d.checkvcf=l.checkvcf}p.tklst.push(d);if(e){if(e.dt==h||e.dt==g){const t=Math.ceil((e.stop-e.start)/2);p.chr=e.chr;p.start=Math.max(0,e.start-t);p.stop=Math.min(i.genome.chrlookup[e.chr.toUpperCase()].len,e.stop+t)}else if(e.dt==k||e.dt==v){if(e.chrA==e.chrB){const t=Math.ceil(Math.abs(e.posA-e.posB)/4);p.chr=e.chrA;p.start=Math.max(0,Math.min(e.posA,e.posB)-t);p.stop=Math.min(i.genome.chrlookup[e.chrA.toUpperCase()].len,Math.max(e.posA,e.posB)+t)}else{const t=1e4;p.chr=e.chrA;p.start=Math.max(0,e.posA-t);p.stop=Math.min(i.genome.chrlookup[e.chrA.toUpperCase()].len,e.posA+t);p.subpanels.push({chr:e.chrB,start:Math.max(0,e.posB-t),stop:Math.min(i.genome.chrlookup[e.chrB.toUpperCase()].len,e.posB+t),width:600,leftpad:10,leftborder:"rgba(50,50,50,.1)"})}}}if(!p.chr){const t=i.tkarg_maygm(l)[0];if(e&&e.dt==x){const n=1e4;if(n<t.stop-t.start){p.chr=e.chr;p.start=Math.max(0,e.pos-n);p.stop=Math.min(i.genome.chrlookup[e.chr.toUpperCase()].len,e.pos+n)}}if(!p.chr){p.chr=t.chr;p.start=t.start;p.stop=t.stop}}let f;if(!l.iscustom){const t=await H("mdssvcnv",{method:"POST",body:JSON.stringify({genome:i.genome.name,dslabel:l.mds.label,querykey:l.querykey,gettrack4singlesample:n.samplename})});if(t.error)throw t.error;if(t.tracks){f=t.tracks;for(const e of t.tracks){p.tklst.push(JSON.parse(JSON.stringify(e)))}}}const m=i.newblock(p);if(e){if(e.dt==h||e.dt==g){m.addhlregion(e.chr,e.start,e.stop,Ge)}}if(f){c.style("display","inline-block").style("margin","0px 10px 20px 10px").append("div").style("margin-bottom","3px").text("Show/hide available assay tracks for "+n.samplename).style("font-size",".7em").style("opacity",.5);const t=c.append("div").style("border","solid 1px #ccc").style("border-radius","7px");for(const e of f){const n=t.append("div").style("display","inline-block").style("white-space","nowrap").style("margin","10px").style("font-size",".8em").append("label");n.append("input").attr("type","checkbox").style("margin-right","3px").property("checked",!e.hidden).on("change",(t=>{if(t.target.checked){m.turnOnTrack(e)}else{m.turnOffTrack(e)}}));n.append("span").text(e.name)}}}function Ln(t,e,n){if(!t.checkrnabam)return;e.checkrnabam={};for(const n in t.checkrnabam){if(n=="samples")continue;if(n=="legend")continue;e.checkrnabam[n]=t.checkrnabam[n]}if(n){e.checkrnabam.samples={};for(const n in t.checkrnabam.samples){const a=t.checkrnabam.samples[n];e.checkrnabam.samples[n]={file:a.file,url:a.url,indexURL:a.indexURL,nochr:a.nochr,totalreads:a.totalreads,pairedend:a.pairedend}}}}function Sn(t,e){if(!t._data){return[[],[]]}const n=[];let a=[];for(const s of t._data){const o={};for(const t in s)o[t]=s[t];o.samples=[];for(const a of s.samples){const l={};for(const t in a)l[t]=a[t];l.items=[];for(const o of a.items){if(o.dt==k||o.dt==v){Tn(o,e);if(o.x==undefined){console.log("unmappable sv: "+o._chr+" "+o._pos);continue}if(o.chrA!=o._chr){t.legend_svchrcolor.interchrs.add(o.chrA);t.legend_svchrcolor.colorfunc(o.chrA)}if(o.chrB!=o._chr){t.legend_svchrcolor.interchrs.add(o.chrB);t.legend_svchrcolor.colorfunc(o.chrB)}if(t.isdense){const t={_samplegroup:s,_sample:a};for(const e in o){t[e]=o[e]}n.push(t);continue}l.items.push(o);continue}Pn(o,t,e);if(o.x1==undefined||o.x2==undefined){console.log("unmappable stack item: ",o);continue}l.items.push(o)}if(l.items.length==0){if(t.isfull&&t.data_vcf){let e=false;for(const n of t.data_vcf){if(e)break;if(n.x==undefined)continue;if(n.dt==x){if(!n.sampledata)continue;for(const t of n.sampledata){if(t.sampleobj.name==a.samplename){e=true;break}}continue}}if(!e){if(Nn(t));else{continue}}}else{if(Nn(t));else{continue}}}o.samples.push(l)}if(o.samples.length==0)continue;a.push(o)}if(t.groupsamplebyattr){const e=t.groupsamplebyattr.sortgroupby;if(e&&e.key&&e.order){const t=[];for(const n of e.order){for(const s of a){if(!s.attributes)continue;for(const a of s.attributes){if(a.k==e.key&&a.kvalue==n){s._sorted=1;t.push(s);break}}}}for(const e of a){if(!e._sorted)t.push(e)}for(const e of t)delete e._sorted;a=t}}if(t.sampleset){const e=t.sampleset.map((t=>t.name));a.sort(((t,n)=>{if(e.indexOf(t.name)>e.indexOf(n.name))return 1;else return-1}));for(const e of t.sampleset){const t=a.find((t=>t.name==e.name));if(!t||!t.samples)continue;const n=[];for(const a of e.samples){const e=t.samples.find((t=>t.samplename==a));if(e){n.push(e)}}t.samples=n}}return[a,n]}function Nn(t){if(!t.getallsamples)return false;if(t.iscustom)return true;if(t.mds&&t.mds.allow_getallsamples)return true;return false}function Un(t,e){for(const n in t){e[n]=t[n]}if(t.attributes){e.attributes={};for(const n in t.attributes){e.attributes[n]={};for(const a in t.attributes[n]){e.attributes[n][a]=t.attributes[n][a]}}}}function qn(t,e){if(t.mds){if(t.mds.mutationAttribute){t.mutationAttribute={};Un(t.mds.mutationAttribute,t.mutationAttribute)}if(t.mds.sampleAttribute){t.sampleAttribute={};Un(t.mds.sampleAttribute,t.sampleAttribute)}if(t.mds.locusAttribute){t.locusAttribute={};Un(t.mds.locusAttribute,t.locusAttribute)}if(t.mds.alleleAttribute){t.alleleAttribute={};Un(t.mds.alleleAttribute,t.alleleAttribute)}t.nocnvlohsv=true;t.isdense=true;t.isfull=false;if(t.mds.queries){for(const e in t.mds.queries){const n=t.mds.queries[e];if(n.type==s.mdssvcnv){delete t.nocnvlohsv;if(n.isfull){t.isfull=true;t.isdense=false}}}}}else if(t.iscustom){if(!t.file&&!t.url){t.nocnvlohsv=true}}Bn(t);if(t.singlesample){t.waterfall={inuse:false,axisheight:100,bottompad:10,axisgg:t.gleft.append("g")};if(t.singlesample.waterfall){t.waterfall.inuse=t.singlesample.waterfall.inuse}t.waterfall.axisg=t.waterfall.axisgg.append("g");t.waterfall.lab1=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10);t.waterfall.lab2=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10);t.waterfall.lab3=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10)}else{t.samplematrices=[];if(t.multihidelabel_vcf==undefined){t.multihidelabel_vcf=true}if(t.multihidelabel_fusion==undefined){t.multihidelabel_fusion=true}if(t.multihidelabel_sv==undefined){t.multihidelabel_sv=true}}if(!t.singlesample&&!t.isdense&&!t.isfull){if(t.iscustom){t.isdense=false;t.isfull=true}else{t.isdense=true;t.isfull=false;if(t.showfullmode){t.isdense=false;t.isfull=true}}}t.tip2=new D({padding:"0px"});if(t.singlesample){if(!t.midpad)t.midpad=3;if(!t.stem1){t.stem1=10;t.stem2=0;t.stem3=5}if(!t.legheight)t.legheight=40;if(!t.discradius)t.discradius=8;if(!t.valueCutoff)t.valueCutoff=.2;if(!Number.isInteger(t.bplengthUpperLimit))t.bplengthUpperLimit=2e6;if(!Number.isInteger(t.lohLengthUpperLimit))t.lohLengthUpperLimit=2e6;if(!t.segmeanValueCutoff)t.segmeanValueCutoff=.1;if(t.fixname){t.name=t.fixname;t.tklabel.text(t.name);delete t.fixname}else{t.tklabel.text((t.name?t.name+", ":"")+t.singlesample.name)}t.leftLabelMaxwidth=t.tklabel.node().getBBox().width;e.setllabel();t.svvcf_g=t.glider.append("g");t.cnv_g=t.glider.append("g")}else{if(t.mds&&t.mds.version&&t.mds.version.label){t.versionlabel=e.maketklefthandle(t,e.labelfontsize).text(t.mds.version.label);if(t.mds.version.link){t.versionlabel.on("click",(()=>{window.open(t.mds.version.link)}))}}t.cnvleftg=t.gleft.append("g");t.vcfdensityg=t.glider.append("g");t.vcfdensitylabelg=t.gleft.append("g");t.svdensityg=t.glider.append("g");t.svdensitylabelg=t.gleft.append("g");t.cnvmidg=t.glider.append("g");t.cnvrightg=t.gright.append("g")}t.cnvcolor={};{const e=V(t.gaincolor);t.cnvcolor.gain={str:t.gaincolor,r:e.r,g:e.g,b:e.b};delete t.gaincolor}{const e=V(t.losscolor);t.cnvcolor.loss={str:t.losscolor,r:e.r,g:e.g,b:e.b};delete t.losscolor}{const e=V(t.lohcolor);t.cnvcolor.loh={str:t.lohcolor,r:e.r,g:e.g,b:e.b};delete t.lohcolor}if(t.iscustom){if(t.valueCutoff==undefined)t.valueCutoff=.2;if(t.bplengthUpperLimit==undefined)t.bplengthUpperLimit=2e6;if(t.segmeanValueCutoff==undefined)t.segmeanValueCutoff=.1;if(t.lohLengthUpperLimit==undefined)t.lohLengthUpperLimit=2e6}t.config_handle=e.maketkconfighandle(t).on("click",(()=>{En(t,e)}));if(t.checkrnabam){st(t.checkrnabam)}Kt(e,t);let n=false;if(t.iscustom){if(t.checkexpressionrank){n=true;if(!t.gecfg)t.gecfg={};t.gecfg.datatype=t.checkexpressionrank.datatype}else if(t.checkrnabam){n=true;if(!t.gecfg)t.gecfg={};t.gecfg.datatype="FPKM"}}else{if(t.mds.queries[t.querykey].checkexpressionrank){n=true;const e=t.mds.queries[t.mds.queries[t.querykey].checkexpressionrank.querykey];if(t.gecfg&&t.gecfg.fixed_pend){e.fixed_pend=t.gecfg.fixed_pend}t.gecfg=e}}if(n){if(!t.gecfg)t.gecfg={};if(!t.gecfg.fixed){t.gecfg.fixed=[]}if(!t.gecfg.no_ase){$(t.gecfg)}}}function Bn(t,e){const n=t.iscustom?t:t.customization;if(!n)return;if(n.singlesample){t.singlesample=n.singlesample}else if(n.sampleset){t.sampleset=n.sampleset}t.hide_cnvgain=n.hide_cnvgain;t.hide_cnvloss=n.hide_cnvloss;if(n.isfull){t.isdense=false;t.isfull=true}else if(n.isdense){t.isdense=true;t.isfull=false}if(n.sampleAttribute){if(!t.sampleAttribute)t.sampleAttribute={};if(!t.sampleAttribute.attributes)t.sampleAttribute.attributes={};for(const e in n.sampleAttribute){const a=n.sampleAttribute[e];if(!t.sampleAttribute.attributes[e]){t.sampleAttribute.attributes[e]={label:e}}const s=t.sampleAttribute.attributes[e];if(!s.hiddenvalues)s.hiddenvalues=new Set;if(a.hiddenvalues){for(const t of a.hiddenvalues)s.hiddenvalues.add(t)}}}t.legend_mclass={hiddenvalues:new Set};if(n.vcf){if(n.vcf.hiddenclass){for(const e of n.vcf.hiddenclass)t.legend_mclass.hiddenvalues.add(e)}}if(n.cnv){if(n.cnv.hidden)t.legend_mclass.hiddenvalues.add(h);if(Number.isInteger(n.cnv.upperlengthlimit))t.bplengthUpperLimit=n.cnv.upperlengthlimit}if(n.loh){if(n.loh.hidden)t.legend_mclass.hiddenvalues.add(g);if(Number.isInteger(n.loh.upperlengthlimit))t.lohLengthUpperLimit=n.loh.upperlengthlimit}if(n.fusion){if(n.fusion.hidden)t.legend_mclass.hiddenvalues.add(v)}if(n.sv){if(n.sv.hidden)t.legend_mclass.hiddenvalues.add(k)}if(n.itd){if(n.itd.hidden)t.legend_mclass.hiddenvalues.add(b)}if(n.fixedgeneexpression){if(!t.gecfg)t.gecfg={};t.gecfg.fixed_pend=n.fixedgeneexpression}}function Cn(t,e){t.tkconfigtip.hide();if(t.mode_radio_1.property("checked")){t.isdense=true;t.isfull=false}else if(t.mode_radio_2.property("checked")){t.isdense=false;t.isfull=true}if(!t._data){return}dn(t,e);e.block_setheight();e.setllabel()}function En(t,e){t.tkconfigtip.clear();pt(t);Fn(t,e);dt(t,e);Rn(t,e);Hn(t,e);In(t,e);On(t,e);ot(t,e,an);t.tkconfigtip.showunder(t.config_handle.node())}function Rn(t,e){if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","25px");if(t.sampleset){n.append("span").style("opacity",.5).style("padding-right","10px").text("Restricted to "+t.sampleset.reduce(((t,e)=>t+e.samples.length),0)+" samples");n.append("button").text("Edit").on("click",(()=>{Vn(t,e)}));n.append("button").text("Remove").on("click",(()=>{t.tkconfigtip.hide();delete t.sampleset;an(t,e)}));return}n.append("button").text("Use a sample list").on("click",(()=>{Vn(t,e)}));if(t.iscustom||t.mds&&t.mds.allow_getallsamples){n.append("button").style("margin-left","10px").text(t.getallsamples?"Only show samples with variants":"Show all samples").on("click",(()=>{t.getallsamples=!t.getallsamples;t.tkconfigtip.hide();an(t,e)}))}}function Vn(t,e){t.tkconfigtip.clear();const n=t.tkconfigtip.d.append("div");const a=n.append("textarea").attr("placeholder","One sample per row. Each row has sample and optional group name, joined by space or tab.");if(t.sampleset){const e=[];for(const n of t.sampleset){for(const t of n.samples){e.push(t+" "+n.name)}}a.property("value",e.join("\n")).style("width","250px").style("height","200px")}else{a.style("width","200px").style("height","100px")}n.append("button").text("Submit").style("display","block").on("click",(()=>{const n=a.property("value").trim().split("\n");if(n.length==0)return;const s=new Map;const o=[];for(const t of n){const[e,n]=t.split(/[\s\t]/);if(!e)continue;if(!n){o.push(e)}else{if(!s.has(n))s.set(n,[]);s.get(n).push(e)}}t.sampleset=[];for(const[e,n]of s){t.sampleset.push({name:e,samples:n})}if(o.length){const e={samples:o};if(s.size){e.name="Unnamed group"}t.sampleset.push(e)}t.tkconfigtip.hide();an(t,e)}))}function In(t,e){if(!t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","15px");if(!t.data_vcf||t.data_vcf.length<2){n.style("opacity",.5).text("No waterfall plot: not enough SNV/indels");return}const a=Math.random();n.append("input").attr("type","checkbox").attr("id",a).property("checked",t.waterfall.inuse).on("change",(n=>{t.waterfall.inuse=n.target.checked;be(t,e);e.block_setheight()}));n.append("label").attr("for",a).html("&nbsp;use Waterfall plot for SNV/indels")}function On(t,e){if(t.nocnvlohsv)return;const n=t.tkconfigtip.d;{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("CNV log2(ratio) cutoff&nbsp;");a.append("input").property("value",t.valueCutoff||0).attr("type","number").style("width","50px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseFloat(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.valueCutoff){t.valueCutoff=0;an(t,e)}return}if(t.valueCutoff){if(t.valueCutoff==a);else{t.valueCutoff=a;an(t,e)}}else{t.valueCutoff=a;an(t,e)}}));a.append("div").style("font-size",".7em").style("color","#858585").html("Only show CNV with absolute log2(ratio) no less than cutoff.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("CNV segment size limit&nbsp;");a.append("input").property("value",t.bplengthUpperLimit||0).attr("type","number").style("width","80px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseInt(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.bplengthUpperLimit){t.bplengthUpperLimit=0;an(t,e)}return}if(t.bplengthUpperLimit){if(t.bplengthUpperLimit==a);else{t.bplengthUpperLimit=a;an(t,e)}}else{t.bplengthUpperLimit=a;an(t,e)}}));a.append("span").text("bp");a.append("div").style("font-size",".7em").style("color","#858585").html("Limit the CNV segment length to show only focal events.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div");a.append("span").html("Copy number gain&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.gain.str).on("change",(n=>{t.cnvcolor.gain.str=n.target.value;const a=V(t.cnvcolor.gain.str);t.cnvcolor.gain.r=a.r;t.cnvcolor.gain.g=a.g;t.cnvcolor.gain.b=a.b;t.cnvcolor.cnvlegend.gain_stop.attr("stop-color",t.cnvcolor.gain.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}));a.append("span").html("&nbsp;&nbsp;loss&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.loss.str).on("change",(n=>{t.cnvcolor.loss.str=n.target.value;const a=V(t.cnvcolor.loss.str);t.cnvcolor.loss.r=a.r;t.cnvcolor.loss.g=a.g;t.cnvcolor.loss.b=a.b;t.cnvcolor.cnvlegend.loss_stop.attr("stop-color",t.cnvcolor.loss.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}))}if(t.cnvcolor.lohlegend){n.append("hr").style("margin","20px");{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("LOH seg.mean cutoff&nbsp;");a.append("input").property("value",t.segmeanValueCutoff||0).attr("type","number").style("width","50px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseFloat(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.segmeanValueCutoff){t.segmeanValueCutoff=0;an(t,e)}return}if(t.segmeanValueCutoff){if(t.segmeanValueCutoff==a);else{t.segmeanValueCutoff=a;an(t,e)}}else{t.segmeanValueCutoff=a;an(t,e)}}));a.append("div").style("font-size",".7em").style("color","#858585").html("Only show LOH with seg.mean no less than cutoff.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("LOH segment size limit&nbsp;");a.append("input").property("value",t.lohLengthUpperLimit||0).attr("type","number").style("width","80px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseInt(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.lohLengthUpperLimit){t.lohLengthUpperLimit=0;an(t,e)}return}if(t.lohLengthUpperLimit){if(t.lohLengthUpperLimit==a);else{t.lohLengthUpperLimit=a;an(t,e)}}else{t.lohLengthUpperLimit=a;an(t,e)}}));a.append("span").text("bp");a.append("div").style("font-size",".7em").style("color","#858585").html("Limit the LOH segment length to show only focal events.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","1px");a.append("span").html("LOH color&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.loh.str).on("change",(n=>{t.cnvcolor.loh.str=n.target.value;const a=V(t.cnvcolor.loh.str);t.cnvcolor.loh.r=a.r;t.cnvcolor.loh.g=a.g;t.cnvcolor.loh.b=a.b;t.cnvcolor.lohlegend.loh_stop.attr("stop-color",t.cnvcolor.loh.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}))}}}function Fn(t,e){if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("background","#FAF9DE").style("margin-bottom","20px").style("padding","15px");const a=Math.random().toString();const s=Math.random().toString();const o=Math.random().toString();const l=n.append("div").style("margin-bottom","5px");t.mode_radio_1=l.append("input").attr("type","radio").attr("id",a).attr("name",o).property("checked",t.isdense).on("change",(()=>{Cn(t,e)}));l.append("label").attr("for",a).attr("class","sja_clbtext").html('&nbsp;Dense <span style="font-size:.7em;color:#858585;">Showing densities of SV breakpoints and SNV/indels, over all samples</span>');const i=n.append("div");t.mode_radio_2=i.append("input").attr("type","radio").attr("id",s).attr("name",o).property("checked",t.isfull).on("change",(()=>{Cn(t,e)}));i.append("label").attr("for",s).attr("class","sja_clbtext").html('&nbsp;Expanded <span style="font-size:.7em;color:#858585;">Showing SV/SNV/indel for each sample</span>')}function Hn(t,e){if(t.singlesample)return;t.tkconfigtip.d.append("div").style("margin-bottom","5px").text("Show text labels in expanded mode").style("opacity",.5);const n=t.tkconfigtip.d.append("div").style("margin-bottom","20px");{const a=Math.random().toString();n.append("input").attr("type","checkbox").attr("id",a).property("checked",!t.multihidelabel_vcf).on("change",(()=>{t.multihidelabel_vcf=!t.multihidelabel_vcf;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;SNV/indel")}if(!t.nocnvlohsv){{const a=Math.random().toString();n.append("input").attr("type","checkbox").style("margin-left","20px").attr("id",a).property("checked",!t.multihidelabel_sv).on("change",(()=>{t.multihidelabel_sv=!t.multihidelabel_sv;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;DNA SV")}{const a=Math.random().toString();n.append("input").attr("type","checkbox").style("margin-left","20px").attr("id",a).property("checked",!t.multihidelabel_fusion).on("change",(()=>{t.multihidelabel_fusion=!t.multihidelabel_fusion;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;RNA fusion")}}}function Pn(t,e,n){const a=n.tkarg_maygm(e)[0];if(t.chr==a.chr&&Math.max(t.start,a.start)<Math.min(t.stop,a.stop)){t.x1=n.seekcoord(t.chr,Math.max(t.start,a.start))[0].x;t.x2=n.seekcoord(t.chr,Math.min(t.stop,a.stop-1))[0].x}let s=n.width;for(const e of n.subpanels){s+=e.leftpad;if(t.chr==e.chr&&Math.max(t.start,e.start)<Math.min(t.stop,e.stop)){const n=s+(Math.max(t.start,e.start)-e.start)*e.exonsf;const a=s+(Math.min(t.stop,e.stop)-e.start)*e.exonsf;if(t.x1==undefined){t.x1=n;t.x2=a}else{t.x2=a}}s+=e.width}if(t.x1!=undefined&&n.gmmode&&n.gmmode!=Y.genomic){const e=n.width+n.subpanels.reduce(((t,e)=>e.width+e.leftpad),0);if(t.x1<t.x2){if(t.x2<0||t.x1>e){t.x1=undefined;t.x2=undefined;return}if(t.x1<0){t.x1=0}if(t.x2>e){t.x2=e}}else if(t.x1>t.x2){if(t.x1<0||t.x2>e){t.x1=undefined;t.x2=undefined;return}if(t.x2<0){t.x2=0}if(t.x1>e){t.x1=e}}}}function Tn(t,e){const n=e.seekcoord(t._chr,t._pos);for(const a of n){if(a.ridx!=undefined){if(a.x>0&&a.x<e.width){t.x=a.x;break}}else if(a.subpanelidx!=undefined){t.x=a.x}}}function Dn(t,e){if(!t.data_vcf)return;for(const n of t.data_vcf){if(n.dt==x){n._chr=n.chr;n._pos=n.pos;Tn(n,e);if(n.x==undefined){console.log("snvindel unmapped: "+n.chr+":"+n.pos)}else{delete n._chr;delete n._pos}}else{console.error("may_map_vcf: unknown dt")}}}function Yn(t,e){if(!t._data_vcf||t._data_vcf.length==0){t.data_vcf=null;return}const n=t._data_vcf;t.data_vcf=[];for(const a of n){if(a.dt==x){G(a,e)}else{throw"unknown dt "+a.dt}if(!t.legend_mclass.hiddenvalues.has(a.class)){t.data_vcf.push(a)}}}function Gn(t){const e=new Map;for(const n of t){e.set(n.sample+"."+n.chrA+"."+n.posA+"."+n.strandA+"."+n.chrB+"."+n.posB+"."+n.strandB,n)}return[...e.values()]}function Xn(t,e){if(!t)return false;if(e.legend_vorigin&&e.legend_vorigin.key){const n=t[e.legend_vorigin.key];if(n){if(n.toLowerCase()==e.legend_vorigin.germline)return true}}return false}export{Je as coverbarcolor_active,Xe as coverbarcolor_silent,Gn as dedup_sv,jn as draw_colorscale_cnv,Mn as draw_colorscale_loh,zn as focus_singlesample,Ye as intrasvcolor,yn as itemname_svfusion,en as labelspace,an as loadTk,Pn as map_cnv,An as multi_expressionstatus_ase_outlier,wn as multi_rnabam_asestatus,kn as multi_sample_addhighlight,vn as multi_sample_removehighlight,Ln as rnabamtk_copyparam,cn as trackclear,Xn as vcfvariantisgermline};
1
+ import{p as t,bY as e,ac as n,Z as a,am as s,bZ as o,b_ as l,c as i,x as r,aa as c,a as p,q as d,a9 as f,b$ as m,j as u,ap as h,aq as g,ar as b,as as k,at as v,ak as x,z as y,ae as _,aN as w,aA as A,c0 as j,v as M,b as z,b6 as L,b7 as S,I as N,ah as U,ag as q,d as B,a8 as C,B as E,an as R,r as V,aW as I,bw as O,f as F,a7 as H,ao as P,ad as T,M as D,be as Y,bb as G}from"./app-488d9fd6.js";import{a as X,s as J,u as Z,m as W,i as $}from"./block.mds.expressionstat-483c9bc9.js";import{s as K}from"./legacy-d3-polyfill-bdb2d792.js";import{l as Q}from"./block.legend-aa831169.js";import{c as tt,d as et}from"./axis-747c801e.js";import{l as nt}from"./log-1001ca83.js";import{v as at}from"./vcf-55bf2c83.js";import{r as st,c as ot}from"./block.mds.svcnv.share-6575b7cf.js";import"./partition-db811f6b.js";import"./arc-3d6751aa.js";import"./constant-426a1483.js";import"./math-2fb199c6.js";const lt="svcnv";const it="vcf";const rt="expression";async function ct(t){const{feature:n,tk:p,block:d,limitsamplebyeitherannotation:f,limitbysamplesetgroup:m}=t;const u=a({x:100,y:100,close:()=>{e(u.pane,p.config_handle);u.pane.style("display","none")}});if(f){const t=f[0];if(t){u.header.html('<span style="font-size:.8em;opacity:.5">'+p.name+"</span> "+t.value)}}else if(m){u.header.html('<span style="font-size:.8em;opacity:.5">'+p.name+"</span> "+m.name)}else{u.header.text(p.name)}const h={debugmode:d.debugmode,genome:d.genome,features:[n],hostURL:d.hostURL,limitsamplebyeitherannotation:f,limitbysamplesetgroup:m,jwt:d.jwt,holder:u.body.append("div").style("margin","20px")};if(p.iscustom){h.iscustom=1;h.querykey2tracks={};h.querykey2tracks[lt]={type:s.mdssvcnv,file:p.file,url:p.url,indexURL:p.indexURL};if(p.checkexpressionrank){h.querykey2tracks[rt]={type:s.mdsexpressionrank};for(const t in p.checkexpressionrank){h.querykey2tracks[rt][t]=p.checkexpressionrank[t]}}if(p.checkvcf){h.querykey2tracks[it]={type:s.mdsvcf};for(const t in p.checkvcf){if(t=="stringifiedObj")continue;h.querykey2tracks[it][t]=p.checkvcf[t]}}}else{h.dslabel=p.mds.label}if(window.location.search.includes("smx=3")){h.client=o;h.common=l;h.string2pos=i;h.invalidcoord=r;h.block=import("./block-2f22e7fd.js").then((function(t){return t.c}));const t=await c();t.dthm(h).then((t=>{t._pane=u;p.samplematrices.push(t)}))}else{import("./samplematrix-2bb2480b.js").then((t=>{const e=new t.Samplematrix(h);e._pane=u;p.samplematrices.push(e)}))}}function pt(a,s){if(!a.samplematrices||a.samplematrices.length==0)return;const o=a.tkconfigtip.d.append("table").style("margin-bottom","5px");for(const s of a.samplematrices){const l=o.append("tr");{const a=[];if(s.limitsamplebyeitherannotation){const t=s.limitsamplebyeitherannotation[0];a.push(t.value)}else if(s.limitbysamplesetgroup){a.push(s.limitbysamplesetgroup.name)}else{a.push("Any sample")}const o=s.features.length;a.push(o+" feature"+(o>1?"s":""));a.push(s.samples.length+" samples");const i=l.append("td").append("div").attr("class","sja_menuoption").style("border","solid 1px #ededed").text(a.join(", "));if(s._pane.pane.style("display")=="none"){i.style("border-color","black")}i.on("click",(()=>{if(s._pane.pane.style("display")=="none"){t(s._pane.pane);e(i,s._pane.pane);i.style("border-color","#ededed")}else{e(s._pane.pane,i);n(s._pane.pane);i.style("border-color","black")}}))}{l.append("td").attr("class","sja_menuoption").html("&times;").on("click",(()=>{l.remove();s._pane.pane.remove();for(const[t,e]of a.samplematrices.entries()){if(s.limitsamplebyeitherannotation){if(e.limitsamplebyeitherannotation){const n=s.limitsamplebyeitherannotation[0];const o=e.limitsamplebyeitherannotation[0];if(n.key==o.key&&n.value==o.value){a.samplematrices.splice(t,1);return}}}else{if(!e.limitsamplebyeitherannotation){a.samplematrices.splice(t,1);return}}}}))}}}async function dt(t,e){if(t.iscustom)return;if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","15px");const s=n.append("input").attr("size",20).attr("placeholder","Find sample");const o=n.append("div").style("margin-top","10px");s.on("keyup",p.debounce(l,300));async function l(){o.selectAll("*").remove();const n=s.property("value").trim();if(!n)return;const l={genome:e.genome.name,dslabel:t.mds.label,querykey:t.querykey,findsamplename:n};try{const n=await d("mdssvcnv",l);if(n.error)throw n.error;if(!n.result)return;for(const s of n.result){const n=o.append("div");n.append("span").text(s.name);if(s.grouplabel){n.append("span").style("margin-left","10px").style("font-size",".7em").text(s.grouplabel)}if(s.num_assay_tracks){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text(s.num_assay_tracks+" track"+(s.num_assay_tracks>1?"s":""))}if(s.disco){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text("Genome view")}if(s.mutation_signature){n.append("span").style("font-size",".7em").style("padding","1px 5px").style("margin-left","10px").style("background","#bbb").style("color","white").style("border-radius","3px").text("Mutation signature")}n.attr("class","sja_menuoption").on("click",(()=>{t.tkconfigtip.hide();const n=[];Ft(n,{tk:t,block:e,sample:{samplename:s.name},samplegroup:{attributes:s.attributes}});Pt(n,{tk:t,block:e,sample:{samplename:s.name}});Ht(n,{tk:t,block:e,sample:{samplename:s.name}});Tt(n,s.name,t,e);if(s.attr&&t.sampleAttribute&&t.sampleAttribute.attributes){n.push({label:"Attributes",callback:e=>{for(const e of s.attr){const n=t.sampleAttribute.attributes[e.k];if(n)e.k=n.label}f(e,s.attr)}})}const o=a({x:100,y:100});o.header.text(s.name);m(o.body.style("padding-top","10px"),n)}))}}catch(t){u(o,err.message||err);if(err.stack)console.log(err.stack)}}}function ft(t,e,n){if(e.sampleset)return mt(t,e,n);if(e.iscustom)return;if(!t.attributes){return}const a=t=>u(e.tip2.d,t);if(!e.sampleAttribute)return a("tk.sampleAttribute missing");if(!e.sampleAttribute.attributes)return a("tk.sampleAttribute.attributes{} missing");e.tip2.d.append("div").style("margin","4px 10px").style("font-size",".7em").text(t.name);e.tip2.d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{e.tip2.clear();gt(t,e,true);e.tip2.hide();an(e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{e.tip2.clear();for(const t of e._data){gt(t,e,true)}gt(t,e,false);e.tip2.hide();an(e,n)}));{const[a,s,o]=ht(t,e);if(a);else if(o.hiddenvalues.size>0){e.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{e.tip2.hide();o.hiddenvalues.clear();an(e,n)}))}}e.tip2.d.append("div").attr("class","sja_menuoption").text("Table view").on("click",(()=>{e.tip2.hide();kt(t,e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Matrix view").on("click",(()=>{e.tip2.hide();ut(e,n,t)}));Ct(t,e,n);Gt({tk:e,block:n,samplegroup:t,holder:e.tip2.d});Xt(e,n,e.tip2.d,t)}function mt(t,e,n){e.tip2.d.append("div").style("margin","4px 10px").style("font-size",".7em").text(t.name);e.tip2.d.append("div").attr("class","sja_menuoption").text("Table view").on("click",(()=>{e.tip2.hide();kt(t,e,n)}));e.tip2.d.append("div").attr("class","sja_menuoption").text("Matrix view").on("click",(()=>{e.tip2.hide();ut(e,n,t)}))}function ut(e,n,a){const s=n.rglst[n.startidx];const o={ismutation:1,width:60,chr:s.chr,start:s.start,stop:s.stop,cnv:{valuecutoff:e.valueCutoff,focalsizelimit:e.bplengthUpperLimit},loh:{valuecutoff:e.segmeanValueCutoff,focalsizelimit:e.lohLengthUpperLimit},itd:{},sv:{},fusion:{},snvindel:{excludeclasses:{}}};if(e.legend_mclass&&e.legend_mclass.hiddenvalues){for(const t of e.legend_mclass.hiddenvalues){if(typeof t=="string"){o.snvindel.excludeclasses[t]=1}else{if(t==h){o.cnv.hidden=1}else if(t==g){o.loh.hidden=1}else if(t==b){o.itd.hidden=1}else if(t==k){o.sv.hidden=1}else if(t==v){o.fusion.hidden=1}else{console.error("unknown hidden dt?? "+t)}}}}if(e.showinggene){o.label=e.showinggene}else{o.label=s.chr+":"+s.start+"-"+s.stop}const l={tk:e,block:n,feature:o};o.querykeylst=[];if(e.iscustom){if(e.file||e.url)o.querykeylst.push(lt);if(e.checkvcf)o.querykeylst.push(it)}else if(e.querykey){o.querykeylst.push(e.querykey);if(e.checkvcf)o.querykeylst.push(e.checkvcf.querykey)}if(e.sampleset){for(const n of e.samplematrices){if(n.limitbysamplesetgroup&&n.limitbysamplesetgroup.name==a.name){t(n._pane.pane);n.addnewfeature_update(o);return}}l.limitbysamplesetgroup={name:a.name,samples:JSON.parse(JSON.stringify(e.sampleset.find((t=>t.name==a.name)).samples))}}else if(a.attributes){const n=a.attributes[a.attributes.length-1];for(const a of e.samplematrices){if(a.limitsamplebyeitherannotation){const e=a.limitsamplebyeitherannotation[0];if(e&&e.key==n.k&&e.value==n.kvalue){t(a._pane.pane);a.addnewfeature_update(o);return}}}l.limitsamplebyeitherannotation=[{key:n.k,value:n.kvalue}]}ct(l)}function ht(t,e){if(!t.attributes)return[".attributes[] missing for group "+t.name];if(t.attributes.length==0)return[".attributes[] zero length for group "+t.name];const n=t.attributes[t.attributes.length-1];const a=e.sampleAttribute.attributes[n.k];if(!a)return['"'+n.k+'" not registered in sampleAttribute for group '+t.name];return[null,n,a]}function gt(t,e,n){const[a,s,o]=ht(t,e);if(a)return a;if(n){o.hiddenvalues.add(s.kvalue)}else{o.hiddenvalues.delete(s.kvalue)}return null}function bt(t,e){const n=e.tktip.clear().d.append("div");if(t.attributes){for(const e of t.attributes){n.append("div").html(e.kvalue+(e.fullvalue?' <span style="opacity:.5;font-size:.8em;">'+e.fullvalue+"</span>":""))}}else if(t.name){n.append("div").text(t.name)}const a=[t.samples.length+" sample"+(t.samples.length>1?"s":"")];if(t.sampletotalnum)a.push(t.sampletotalnum+" samples total, "+Math.ceil(100*t.samples.length/t.sampletotalnum)+"%");if(e.sampleset){const n=e.sampleset.find((e=>e.name==t.name));if(n){a.push(n.samples.length+" samples total, "+Math.ceil(100*t.samples.length/n.samples.length)+"%")}}e.tktip.d.append("div").style("margin-top","10px").style("color","#858585").html(a.join("<br>"));e.tktip.show(event.clientX,event.clientY)}function kt(t,e,n){const s=a({x:event.clientX+100,y:Math.max(100,event.clientY-100)});s.header.html(t.name+' <span style="font-size:.7em">'+e.name+"</span>");if(t.samples.length==1){const a=t.samples[0];const o=s.body.append("table").style("margin","10px").style("border-spacing","4px");{const t=o.append("tr");t.append("td").text("Sample").style("opacity",.5);t.append("td").text(a.samplename)}if(a.sampletype){const t=o.append("tr");t.append("td").text("Sample type").style("opacity",.5);t.append("td").text(a.sampletype)}const[l,i,r,c,p,d,f,m,u,h]=Bt(a.samplename,a.items,e);if(l.length){const s=o.append("tr");s.append("td").text("CNV").style("opacity",.5);const i=s.append("td");for(let s=0;s<l.length;s++){i.append("div").html(l[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:d[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:d[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(i.length){const s=o.append("tr");s.append("td").text("SV").style("opacity",.5);const l=s.append("td");for(let s=0;s<i.length;s++){l.append("div").html(i[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:f[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:f[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(r.length){const s=o.append("tr");s.append("td").text("LOH").style("opacity",.5);const l=s.append("td");for(let s=0;s<r.length;s++){l.append("div").html(r[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:m[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:m[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(c.length){const s=o.append("tr");s.append("td").text("ITD").style("opacity",.5);const l=s.append("td");for(let s=0;s<c.length;s++){l.append("div").html(c[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:u[s],sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:u[s],sample:a,samplegroup:t,tk:e,block:n})}))}}if(p.length){const s=o.append("tr");s.append("td").text("SNV/indel").style("opacity",.5);const l=s.append("td");for(let s=0;s<p.length;s++){const o=h[s].sampledata.find((t=>t.sampleobj.name==a.samplename));l.append("div").html(p[s]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:h[s],m_sample:o,sample:a,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(a)})).on("click",(()=>{wt({item:h[s],sample:a,m_sample:o,samplegroup:t,tk:e,block:n})}))}}return}const o=s.body.append("table").style("border-spacing","2px").style("margin","20px");const l=t.samples.find((t=>t.sampletype));const i=o.append("tr");i.append("td").text("Sample").style("opacity",.5);if(l){i.append("td").text("Sample type").style("opacity",.5)}i.append("td").text("CNV").style("opacity",.5);i.append("td").text("SV").style("opacity",.5);i.append("td").text("LOH").style("opacity",.5);i.append("td").text("ITD").style("opacity",.5);if(e.data_vcf){i.append("td").text("SNV/indel").style("opacity",.5)}for(const[a,s]of t.samples.entries()){const i=o.append("tr");if(!(a%2)){i.style("background","#f1f1f1")}i.append("td").text(s.samplename);if(l){i.append("td").text(s.sampletype||"")}const[r,c,p,d,f,m,u,h,g,b]=Bt(s.samplename,s.items,e);{const a=i.append("td");for(let o=0;o<r.length;o++){a.append("div").html(r[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:m[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:m[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<c.length;o++){a.append("div").html(c[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:u[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:u[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<p.length;o++){a.append("div").html(p[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:h[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:h[o],sample:s,samplegroup:t,tk:e,block:n})}))}}{const a=i.append("td");for(let o=0;o<d.length;o++){a.append("div").html(d[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:g[o],sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:g[o],sample:s,samplegroup:t,tk:e,block:n})}))}}if(e.data_vcf){const a=i.append("td");for(let o=0;o<f.length;o++){const l=b[o].sampledata.find((t=>t.sampleobj.name==s.samplename));a.append("div").html(f[o]).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:b[o],m_sample:l,sample:s,samplegroup:t,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:b[o],m_sample:l,sample:s,samplegroup:t,tk:e,block:n})}))}}}}function vt(t,e,n){if(t.items.length==1){const a=t.items[0];At({item:a,sample:a._sample,samplegroup:a._samplegroup,tk:e,block:n});return}e.tktip.clear();let a="Group";if(e.groupsamplebyattr&&e.groupsamplebyattr.attrlst){a=e.groupsamplebyattr.attrlst[e.groupsamplebyattr.attrlst.length-1].label}const s=[{k:a,v:t.name}];let o=0,l=0;for(const e of t.items){if(e.dt==k)o++;else if(e.dt==v)l++}if(o)s.push({k:"# of SV",v:o});if(l)s.push({k:"# of fusion",v:l});f(e.tktip.d,s);e.tktip.show(event.clientX,event.clientY)}function xt(t,e,n){if(t.items.length==1){const a=t.items[0];wt({item:a,sample:a._sample,samplegroup:a._samplegroup,tk:e,block:n});return}const s=a({x:event.clientX,y:event.clientY});s.header.html(t.name+' <span style="font-size:.8em">'+e.name+"</span>");const o=new Map;for(const e of t.items){if(!o.has(e.sample)){o.set(e.sample,{sv:[],fusion:[]})}if(e.dt==k){o.get(e.sample).sv.push(e)}else if(e.dt==v){o.get(e.sample).fusion.push(e)}}const l=s.body.append("table").style("border-spacing","2px").style("margin","10px");const i=l.append("tr");i.append("td").text("Sample").style("font-size",".8em").style("opacity",.5);i.append("td").text("SV").style("font-size",".8em").style("opacity",.5);i.append("td").text("RNA fusion").style("font-size",".8em").style("opacity",.5);let r=0;for(const[t,a]of o){const s=l.append("tr");if(!(r++%2)){s.style("background","#f1f1f1")}s.append("td").text(t);const o=s.append("td");for(const t of a.sv){const a=qt(t,e);o.append("div").attr("class","sja_clbtext").html(t.cytogeneticname?t.cytogeneticname+' <span style="font-size:.7em">'+a+"</span>":a).on("mouseover",(()=>{At({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(t._sample)})).on("click",(()=>{wt({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e,block:n})}))}const i=s.append("td");for(const t of a.fusion){i.append("div").attr("class","sja_clbtext").html(yn(t)+' <span style="font-size:.7em">'+qt(t,e)+"</span>").on("mouseover",(()=>{At({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e})})).on("mouseout",(()=>{e.tktip.hide();vn(t._sample)})).on("click",(()=>{wt({item:t,sample:t._sample,samplegroup:t._samplegroup,tk:e,block:n})}))}}}function yt(t,e,n){const s=a({x:event.clientX,y:event.clientY});s.header.text(e.name);if(t.items.length==1){const a=t.items[0];s.body.append("div").style("margin","10px");if(a.dt==x){if(a.sampledata.length==1){s.pane.remove();const[t,o]=Nt({m:a,m_sample:a.sampledata[0],tk:e});a.sampledata[0];wt({item:a,m_sample:a.sampledata[0],sample:t,samplegroup:o,tk:e,block:n});return}const t=St(a,e);const o=f(s.body,t);const l=o.append("tr");l.append("td").text("Samples").style("opacity",.5).attr("colspan",2);const i=l.append("td");for(const t of a.sampledata){const[s,o]=Nt({m:a,m_sample:t,tk:e});i.append("div").text(t.sampleobj.name).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:a,m_sample:t,sample:s,samplegroup:o,tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();vn(s)})).on("click",(()=>{wt({item:a,m_sample:t,sample:s,samplegroup:o,tk:e,block:n})}))}Ot(a,n,o)}else{throw"Unknown dt: "+a.dt}return}const o=s.body.append("table").style("margin-top","10px").style("border-spacing","4px");for(const a of t.items){const t=o.append("tr");t.append("td").text(a.mname).style("color",y[a.class].color).style("font-weight","bold").style("vertical-align","top");{const e=t.append("td");if(a.dt==x){e.style("opacity",".5").text(a.ref+" > "+a.alt).style("vertical-align","top")}}{const s=t.append("td");if(a.dt==x){for(const t of a.sampledata){const[o,l]=Nt({m:a,m_sample:t,tk:e});s.append("div").text(t.sampleobj.name).attr("class","sja_clbtext").on("mouseover",(()=>{At({item:a,m_sample:t,sample:o,samplegroup:l,tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();vn(o)})).on("click",(()=>{wt({item:a,m_sample:t,sample:o,samplegroup:l,tk:e,block:n})}))}}else{console.error("unknown dt: "+a.dt)}}}}function _t(t,e,n){e.tktip.clear();if(t.items.length==1){const a=t.items[0];if(a.dt==x){if(a.sampledata.length==1){const[t,s]=Nt({m:a,m_sample:a.sampledata[0],tk:e});At({item:a,m_sample:a.sampledata[0],sample:t,samplegroup:s,tk:e,block:n});return}const t=St(a,e);t.push({k:"Samples",v:a.sampledata.length>10?a.sampledata.slice(0,6).map((t=>t.sampleobj.name)).join("<br>")+"<br><i>... and "+(a.sampledata.length-6)+" more samples</i>":a.sampledata.map((t=>t.sampleobj.name)).join("<br>")});const s=f(e.tktip.d,t);Ot(a,n,s);e.tktip.show(event.clientX,event.clientY)}else{throw"unknown dt: "+a.dt}return}e.tktip.d.append("div").style("font-size",".7em").style("margin-bottom","5px").text(t.items.length+" "+y[t.items[0].class].label+" mutations, "+t.samplecount+" samples");const a=e.tktip.d.append("table").style("border-spacing","3px");for(const e of t.items){const t=a.append("tr");t.append("td").style("color",y[e.class].color).style("font-weight","bold").text(e.mname);t.append("td").style("font-size",".7em").style("opacity",".5").text(e.ref+" > "+e.alt);const n=t.append("td").style("font-size",".7em");if(e.dt==x){n.text(e.sampledata.length==1?e.sampledata[0].sampleobj.name:"("+e.sampledata.length+" samples)")}else{n.text("unknown dt: "+e.dt)}}e.tktip.show(event.clientX,event.clientY)}async function wt(t){const e=a({x:event.clientX,y:event.clientY});e.header.text(t.tk.name);const n=[];n.push({label:"Details",callback:e=>{t.holder=e;jt(t)}});Ft(n,t);Rt(n,t);Pt(n,t);Ht(n,t);Tt(n,t.sample.samplename,t.tk,t.block);Yt(n,{tk:t.tk,block:t.block,m:t.item,sample:t.sample});Dt(n,{tk:t.tk,block:t.block,m:t.item,sample:t.sample,samplegroup:t.samplegroup});m(e.body.style("padding-top","10px"),n)}function At(t){kn(t.sample);t.holder=t.tk.tktip.clear().d;jt(t);t.tk.tktip.show(event.clientX,event.clientY)}function jt(t){const e=[];if(t.sample){e.push({k:"Sample",v:t.sample.samplename});Et(t.sample.samplename,t.tk,e)}const n=t.item;let a;if(n.dt==b){e.push({k:"ITD",v:n.chr+":"+(n.start+1)+"-"+(n.stop+1)});if(n.gene||n.isoform){const t=[];if(n.gene)t.push(n.gene);if(n.isoform)t.push(n.isoform);e.push({k:"Gene",v:t.join(", ")})}if(n.rnaduplength){e.push({k:"RNA duplicated",v:n.rnaduplength+" bp"})}if(n.aaduplength){e.push({k:"AA duplicated",v:n.aaduplength+" aa"})}a=n.mattr}else if(n.dt==h||n.dt==g){if(n.dt==g){e.push({k:"LOH seg.mean",v:n.segmean.toFixed(2)})}else{e.push({k:"CNV log2(ratio)",v:'<span style="padding:0px 4px;background:'+(n.value>0?t.tk.cnvcolor.gain.str:t.tk.cnvcolor.loss.str)+';color:white;">'+n.value.toFixed(2)+"</span>"});e.push({k:"Copy number",v:(2*Math.pow(2,n.value)).toFixed(2)})}e.push({k:"Position",v:n.chr+":"+(n.start+1)+"-"+(n.stop+1)+' <span style="font-size:.7em">'+_(n.stop-n.start)+"</span>"});a=n.mattr}else if(n.dt==k||n.dt==v){{e.push({k:n.dt==k?"SV":"RNA fusion",v:yn(n)+' <span style="font-size:.7em">'+qt(n,t.tk)+"</span>"})}if(n.clipreadA||n.clipreadB){e.push({k:"# clip reads",v:'<span style="font-size:.7em;opacity:.7">A CLIP / TOTAL</span> '+(Number.isInteger(n.clipreadA)?n.clipreadA:"?")+" / "+(Number.isInteger(n.totalreadA)?n.totalreadA:"?")+"<br>"+'<span style="font-size:.7em;opacity:.7">B CLIP / TOTAL</span> '+(Number.isInteger(n.clipreadB)?n.clipreadB:"?")+" / "+(Number.isInteger(n.totalreadB)?n.totalreadB:"?")})}a=n.mattr}else if(n.dt==x){const s=St(n,t.tk);for(const t of s)e.push(t);if(t.m_sample){a={};const s=t.tk.checkvcf?t.tk.checkvcf.format:null;for(const o in t.m_sample){if(o=="sampleobj"){continue}if(t.tk.mds&&t.tk.mds.mutation_signature){const n=t.tk.mds.mutation_signature.sets[o];if(n){const a=t.m_sample[o];const s=n.signatures[a];if(!s.nodata){const t=s?s.name:"Unknown ("+a+")";const o=s?s.color:"black";e.push({k:n.name,v:'<span style="background:'+o+'">&nbsp;&nbsp;&nbsp;</span> '+t})}continue}}if(t.tk.mutationAttribute&&t.tk.mutationAttribute.attributes){if(t.tk.mutationAttribute.attributes[o]){a[o]=t.m_sample[o];continue}}const l=s?s[o]:null;if(l){let a=l.Number=="R"||l.Number=="A";if(!a){if(o=="AD"){a=true}}if(a){const a=[];const s=[];let i;for(const e in t.m_sample[o]){if(e==n.ref)continue;a.push(e);i=t.m_sample[o][e];s.push(i)}const r=t.m_sample[o][n.ref];if(r!=undefined){a.push(n.ref);s.push(r)}let c;if(r+i>0){c=w(null,{f:i/(i+r)})}e.push({k:o,v:(c?c+" ":"")+'<span style="font-size:.8em;opacity:.5">'+a.join(" / ")+"</span> "+s.join(" / ")+(l.Description?' <span style="font-size:.7em;opacity:.5">'+l.Description+"</span>":"")});continue}}e.push({k:o,v:t.m_sample[o]})}Mt(t.tk,n,t.m_sample.sampleobj.name,e)}}else{e.push({k:"Unknown dt!!",v:n.dt})}if(a){for(const n in a){const s=t.tk.mutationAttribute?t.tk.mutationAttribute.attributes[n]:null;const o=a[n];if(s){if(s.appendto_link){if(!o){continue}e.push({k:s.label,v:o.split(",").map((t=>"<a target=_blank href="+s.appendto_link+t+">"+t+"</a>")).join(" ")});continue}if(s.values){const t=s.values[o];if(t){e.push({k:s.label,v:t.name+(t.label?' <span style="font-size:.7em;opacity:.5">'+t.label+"</span>":"")});continue}}e.push({k:s.label,v:o})}else{e.push({k:n,v:o})}}}Lt(t,e);zt(t,e);const s=f(t.holder,e);if(n.dt==x){Ot(n,t.block,s)}}function Mt(t,e,n,a){if(!t.checkrnabam)return;const s=t.checkrnabam.samples[n];if(!s)return;if(!A[e.ref]||!A[e.alt]){a.push({k:"RNA-seq",v:"RNA-seq coverage not assessed, not SNV"});return}if(!s.genes)return;let o;for(const t of s.genes){if(t.snps){const n=t.snps.find((t=>t.pos==e.pos&&t.ref==e.ref&&t.alt==e.alt));if(n){o=n;break}}}if(!o){a.push({k:"RNA-seq",v:"RNA-seq coverage not assessed, not heterozygous in DNA"});return}if(o.rnacount.nocoverage){a.push({k:"RNA-seq",v:"Not covered in RNA-seq"});return}a.push({k:"RNA-seq read count",v:w(null,{f:o.rnacount.f})+" "+'<span style="font-size:.8em;opacity:.5">'+e.alt+" / "+e.ref+"</span> "+o.rnacount.alt+" / "+o.rnacount.ref+(o.rnacount.pvalue?' <span style="font-size:.8em;opacity:.5">Binomial p</span> '+o.rnacount.pvalue:"")})}function zt(t,e){const n=t.tk;if(!n)return;if(!n.checkrnabam)return;if(!t.sample)return;const a=n.checkrnabam.samples[t.sample.samplename];if(!a)return;if(!a.genes)return;const s=[];for(const t of a.genes){const e=["<td><b>"+t.gene+"</b></td>"+'<td><span style="font-size:.8em;opacity:.5">'+n.gecfg.datatype+"</span> "+t.fpkm+"</td>"+"<td>"];if(t.estat){if(t.estat.ase_uncertain){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(t.estat.ase_biallelic){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(t.estat.ase_monoallelic){e.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}}e.push("</td>");s.push("<tr>"+e.join("")+"</tr>")}if(n.gecfg.fixed){for(const e of n.gecfg.fixed){if(e.sample2rnabam){const a=e.sample2rnabam[t.sample.samplename];if(a){const t=["<td><b>"+e.gene+"</b></td>"+'<td><span style="font-size:.8em;opacity:.5">'+n.gecfg.datatype+"</span> "+a.fpkm+"</td>"+"<td>"];if(a.estat){if(a.estat.ase_uncertain){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(a.estat.ase_biallelic){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(a.estat.ase_monoallelic){t.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}}t.push("</td>");s.push("<tr>"+t.join("")+"</tr>")}}}}if(s.length){e.push({k:"Gene expression",v:"<table>"+s.join("")+"</table>"})}}function Lt(t,e){const n=t.tk;if(!n)return;const a=t.sample;if(!a)return;if(!a.expressionrank)return;const s=[];for(const t in a.expressionrank){const e=a.expressionrank[t];const o=["<tr>"+"<td><b>"+t+"</b></td>"+'<td>&nbsp;<span style="font-size:.7em">RANK</span> '+j(e.rank)+"</td>"+'<td>&nbsp;<span style="font-size:.7em">'+n.gecfg.datatype+"</span> "+e.value+"</td>"+"<td>"];if(e.estat){if(e.estat.ase_uncertain){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(e.estat.ase_biallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(e.estat.ase_monoallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}if(e.estat.outlier){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier+';color:white">Outlier HIGH</span>')}else if(e.estat.outlier_asehigh){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier_asehigh+';color:white">ASE HIGH</span>')}}o.push("</td></tr>");s.push(o.join(""))}if(n.gecfg&&n.gecfg.fixed){for(const t of n.gecfg.fixed){if(t.sample2rank&&t.sample2rank[a.samplename]){const e=t.sample2rank[a.samplename];const o=["<tr>"+"<td><b>"+t.gene+"</b></td>"+'<td>&nbsp;<span style="font-size:.7em">RANK</span> '+j(e.rank)+"</td>"+'<td>&nbsp;<span style="font-size:.7em">'+n.gecfg.datatype+"</span> "+e.value+"</td>"+"<td>"];if(e.estat){if(e.estat.ase_uncertain){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_uncertain+';color:white">ASE uncertain</span>')}else if(e.estat.ase_biallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_biallelic+';color:white">Bi-allelic</span>')}else if(e.estat.ase_monoallelic){o.push('<span style="padding:0px 5px;background:'+n.gecfg.ase.color_monoallelic+';color:white">Mono-allelic</span>')}if(e.estat.outlier){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier+';color:white">Outlier HIGH</span>')}else if(e.estat.outlier_asehigh){o.push('<span style="padding:0px 5px;background:'+n.gecfg.outlier.color_outlier_asehigh+';color:white">ASE HIGH</span>')}}o.push("</td></tr>");s.push(o.join(""))}}}if(s.length){e.push({k:"Expression",v:'<table style="font-size:.9em">'+s.join("")+"</table>"})}}function St(t,e){const n=[];{const e=y[t.class];n.push({k:"Mutation",v:(t.mname?'<span style="color:'+e.color+'">'+t.mname+"</span>":"")+' <span style="font-size:.7em">'+e.label+"</span>"})}{const e=[];if(t.gene)e.push(t.gene);if(t.isoform)e.push(t.isoform);if(e.length){n.push({k:"Gene",v:e.join(" ")})}}n.push({k:"Position",v:t.chr+":"+(t.pos+1)});n.push({k:"Alleles",v:'<span style="font-size:.8em;opacity:.5">REF/ALT</span> '+t.ref+" / "+t.alt});if(e&&e.alleleAttribute&&e.alleleAttribute.attributes){for(const a in e.alleleAttribute.attributes){const s=e.alleleAttribute.attributes[a];n.push({k:s.label,v:t.altinfo?t.altinfo[a]:""})}}if(e&&e.locusAttribute&&e.locusAttribute.attributes){for(const a in e.locusAttribute.attributes){const s=e.locusAttribute.attributes[a];const o=t.info?t.info[a]:"";if(s.appendto_link){if(!o){continue}n.push({k:s.label,v:o.split(",").map((t=>"<a target=_blank href="+s.appendto_link+t+">"+t+"</a>")).join(" ")});continue}n.push({k:s.label,v:t.info?t.info[a]:""})}}return n}function Nt(t){let e;if(t.m.dt==x){if(!t.m_sample)throw"m_sample missing";e=t.m_sample.sampleobj.name}else{throw"unknown dt"}for(const n of t.tk._data){for(const t of n.samples){if(t.samplename==e){return[t,n]}}}return[-1,-1]}function Ut(t,e){if(e.legend_svchrcolor.interchrs.has(t)){return'<span style="background:'+e.legend_svchrcolor.colorfunc(t)+';font-weight:bold;padding:0px 5px;color:white">'+t+"</span>"}return t}function qt(t,e){return Ut(t.chrA,e)+":"+t.posA+(t.strandA?":"+t.strandA:"")+" &raquo; "+Ut(t.chrB,e)+":"+t.posB+(t.strandB?":"+t.strandB:"")}function Bt(t,e,n){const a=[],s=[],o=[],l=[],i=[],r=[],c=[],p=[],d=[],f=[];{const t=e.filter((t=>t.dt==k||t.dt==v));const a=Gn(t);for(const t of a){s.push('<div style="white-space:nowrap">'+yn(t)+' <span style="font-size:.7em">'+qt(t,n)+"</span>"+(t.dt==v?' <span style="font-size:.7em">(RNA fusion)</span>':"")+"</div>");c.push(t)}}for(const t of e){if(t.dt==k||t.dt==v)continue;if(t.dt==g){o.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+' <span style="font-size:.8em">'+_(t.stop-t.start)+" seg.mean: "+t.segmean+"</span>");p.push(t)}else if(t.dt==h){a.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+' <span style="font-size:.8em">'+_(t.stop-t.start)+"</span>"+' <span style="background:'+(t.value>0?n.cnvcolor.gain.str:n.cnvcolor.loss.str)+';font-size:.8em;color:white">&nbsp;'+t.value+"&nbsp;</span>"+"</div>");r.push(t)}else if(t.dt==b){l.push('<div style="white-space:nowrap">'+t.chr+":"+(t.start+1)+"-"+(t.stop+1)+(t.rnaduplength?", "+t.rnaduplength+" bp duplicated in RNA":"")+(t.aaduplength?", "+t.aaduplength+" AA duplicated":"")+"</div>");d.push(t)}else{throw"unknown dt: "+t.dt}}if(n.data_vcf){for(const e of n.data_vcf){if(e.dt==x){if(e.sampledata.find((e=>e.sampleobj.name==t))){const t=y[e.class];i.push('<div style="white-space:nowrap">'+'<span style="color:'+t.color+';font-weight:bold">'+e.mname+"</span> "+'<span style="font-size:.7em">'+t.label+"</span></div>");f.push(e)}}else{throw"unknown dt: "+e.dt}}}return[a,s,o,l,i,r,c,p,d,f]}function Ct(t,e,n){if(!e.mds||!e.mds.annotationsampleset2matrix)return;if(!t.attributes)return;const s=t.attributes.find((t=>t.k==e.mds.annotationsampleset2matrix.key));if(!s)return;const o=e.mds.annotationsampleset2matrix.groups[s.kvalue];if(!o)return;if(!o.groups)return;for(const t of o.groups){if(!t.name||!t.matrixconfig)continue;e.tip2.d.append("div").html(t.name+' <span style="font-size:.8em;opacity:.5">SUMMARY</span>').attr("class","sja_menuoption").on("click",(()=>{e.tip2.hide();const s=a({x:100,y:100});s.header.text(t.name+" summary");const o={dslabel:e.mds.label,debugmode:n.debugmode,genome:n.genome,hostURL:n.hostURL,jwt:n.jwt,holder:s.body.append("div").style("margin","20px")};for(const e in t.matrixconfig){o[e]=t.matrixconfig[e]}import("./samplematrix-2bb2480b.js").then((t=>{new t.Samplematrix(o)}))}))}}function Et(t,e,n){if(!e.sampleAttribute)return;if(!e.sampleAttribute.attributes||!e.sampleAttribute.samples)return;const a=e.sampleAttribute.samples[t];if(!a)return;for(const t in a){const s=e.sampleAttribute.attributes[t]||{};const o=a[t];if(o==undefined)continue;let l=o;if(s.values){const t=s.values[o];if(t&&t.name){l=t.name}}n.push({k:s.label||t,v:l})}}function Rt(t,e){if(!e.item)return;if(e.item.dt!=k&&e.item.dt!=v)return;t.push({label:"Fusion graph",callback:async t=>{const n=M(t);await Vt(e,t);n.remove()}})}async function Vt(t,e){const n={a:{chr:t.item.chrA,position:t.item.posA,strand:t.item.strandA},b:{chr:t.item.chrB,position:t.item.posB,strand:t.item.strandB}};const a=e.append("div");try{{a.text("Loading gene at "+n.a.chr+":"+n.a.position+" ...");const e=await It(t,n.a.chr,n.a.position);const s=e.find((t=>t.isdefault))||e[0];if(s){n.a.name=s.name;n.a.gm={isoform:s.isoform}}}{a.text("Loading gene at "+n.b.chr+":"+n.b.position+" ...");const e=await It(t,n.b.chr,n.b.position);const s=e.find((t=>t.isdefault))||e[0];if(s){n.b.name=s.name;n.b.gm={isoform:s.isoform}}}a.remove();const s={pairlst:[n],genome:t.block.genome,holder:e};import("./svgraph-76e34d5e.js").then((t=>{t.default(s)}))}catch(t){if(t.stack)console.log(t.stack);a.text("Error: "+(t.message||t))}}function It(t,e,n){return z(`isoformbycoord?genome=${t.block.genome.name}&chr=${e}&pos=${n}`).then((t=>{if(t.error)throw t.error;return t.lst}))}async function Ot(t,e,n){if(!e||!e.genome||!e.genome.hasSNP)return;const a=n.append("tr");a.append("td").attr("colspan",2).text("dbSNP").style("opacity",.4).style("padding","3px");const s=a.append("td");const o=s.append("div").text("Loading...");try{const n=await L(t.chr,[t.pos],e.genome,[t.ref,t.altstr]);if(!n||n.length==0){o.text("No match");return}o.remove();for(const t of n){const e=s.append("div");S(t,e)}}catch(t){o.text(t.message||t)}}function Ft(t,e){t.push({label:"Sample View",callback:t=>{zn({holder:t,m:e.item,sample:e.sample,samplegroup:e.samplegroup,tk:e.tk,block:e.block})}})}function Ht(t,e){if(!e.tk.mds)return;t.push({label:"Genome",callback:async t=>{const n=M(t);try{const a=await d("mdssvcnv",{genome:e.block.genome.name,dslabel:e.tk.mds.label,querykey:e.tk.mds.querykey,ifsamplehasvcf:e.sample.samplename});if(a.no)return;let s=0;for(const t in e.block.genome.majorchr){s=Math.max(s,e.block.genome.majorchr[t])}for(const n in e.block.genome.majorchr){const a=t.append("div").style("display","inline-block");const o={};if(e.tk.iscustom){}else{o.fixname=n.toUpperCase();o.mds=e.tk.mds;o.querykey=e.tk.querykey;o.singlesample={name:e.sample.samplename,waterfall:{inuse:1}};for(const t in e.tk.mds.queries[e.tk.querykey]){if(t=="bplengthUpperLimit"||t=="valueCutoff"){continue}o[t]=e.tk.mds.queries[e.tk.querykey][t]}}e.block.newblock({foldlegend:true,hide_mdsHandleHolder:1,width:Math.ceil(900*e.block.genome.majorchr[n]/s),holder:a,block:1,chr:n,start:0,stop:e.block.genome.majorchr[n],tklst:[o]})}n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Pt(t,e){if(!e.tk.mds||!e.tk.mds.singlesamplemutationjson)return;t.push({label:"Disco plot",callback:async t=>{const n=M(t);try{const a=await c();const s={genome:e.block.genome.name,dslabel:e.tk.mds.label,querykey:e.tk.querykey,getsample4disco:e.sample.samplename};const o=await d("/mdssvcnv",s);if(o.error)throw o.error;if(!o.text)throw".text missing";const l={sampleName:e.sample.samplename,data:JSON.parse(o.text)};if(e.tk.mds.mutation_signature){let t=false;for(const n in e.tk.mds.mutation_signature.sets){for(const e of l.data){if(e[n]){t=n;break}}if(t)break}if(t){const n=e.tk.mds.mutation_signature.sets[t];l.mutation_signature={key:t,name:n.name,signatures:n.signatures}}}const i=await a.dtDisco({chromosomeType:e.block.genome.name,majorchr:e.block.genome.majorchr,holderSelector:t,settings:{showControls:false,selectedSamples:[]},callbacks:{geneLabelClick:{type:"genomepaint",hostURL:e.block.hostURL,genome:e.block.genome.name,dslabel:e.tk.mds.label,sample:e.sample.samplename}}});i.main(l);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Tt(t,e,n,a){if(n.iscustom||!n.mds||!n.mds.mutation_signature)return;t.push({label:"Mutation signature",callback:async t=>{const s=M(t);try{const o=await d("mdssamplesignature",{sample:e,genome:a.genome.name,dslabel:n.mds.label});if(o.error)throw o.error;if(!o.lst)throw".lst[] missing";if(o.lst.length==0){s.text("No mutation signature for this sample.");return}for(const e of o.lst){const a=n.mds.mutation_signature.sets[e.key];const s=t.append("div").style("margin-bottom","20px");s.append("div").text(a.name);s.append("div").text(e.valuename);const o=s.append("svg");const l=14,i=16,r=250,c=20,p=2,d=6,f=5;const m=e.annotation[0].v;const u=0;const h=N().domain([u,m]).range([0,r]);let g=0;for(const t of e.annotation){o.append("text").attr("font-family",U).attr("font-size",l).text(a.signatures[t.k].name).each((function(){g=Math.max(g,this.getBBox().width)})).remove()}const b=o.append("g").attr("transform","translate("+(c+g+d)+","+(c+f+p)+")");for(const[t,n]of e.annotation.entries()){const e=b.append("g").attr("transform","translate(0,"+(i+p)*t+")");e.append("text").attr("font-family",U).attr("font-size",l).attr("x",-d).attr("text-anchor","end").attr("y",i/2).text(a.signatures[n.k].name).attr("dominant-baseline","central");e.append("rect").attr("width",Math.max(1,h(n.v))).attr("height",i).attr("shape-rendering","crispEdges").attr("fill",a.signatures[n.k].color)}q({axis:b.append("g").attr("transform","translate(0,-"+p+")").call(tt().scale(h).ticks(4)),showline:1,fontsize:l-2});o.attr("width",c+g+d+r+c).attr("height",c+f+p+(i+p)*e.annotation.length+c)}s.remove()}catch(t){s.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Dt(t,e){if(!e.tk||!e.block||!e.block.genome||!e.block.genome.fimo_motif)return;if(!e.m||e.m.dt!=x)return;t.push({label:"TF motif",callback:async t=>{const n=M(t);try{const a={genome:e.block.genome,div:t,m:{chr:e.m.chr,pos:e.m.pos+1,ref:e.m.ref,alt:e.m.alt}};if(e.tk.iscustom){if(e.tk.checkexpressionrank){a.factor_profiles=[{isgenevalue:1,name:"Gene "+e.tk.gecfg.datatype,file:e.tk.checkexpressionrank.file,url:e.tk.checkexpressionrank.url,indexURL:e.tk.checkexpressionrank.indexURL}];if(e.sample){a.factor_profiles.push({isgenevalueonesample:1,name:e.sample.samplename+" "+e.tk.gecfg.datatype,samplename:e.sample.samplename,file:e.tk.checkexpressionrank.file,url:e.tk.checkexpressionrank.url,indexURL:e.tk.checkexpressionrank.indexURL})}}}else{if(e.tk.checkexpressionrank){const t={isgenevalue:1,datatype:e.tk.checkexpressionrank.datatype,querykey:e.tk.checkexpressionrank.querykey,mdslabel:e.tk.mds.label};if(e.samplegroup){if(e.samplegroup.attributes){t.name=e.samplegroup.name+" "+e.tk.gecfg.datatype;t.samplegroup_attrlst=e.samplegroup.attributes}}if(!t.name){t.name="Gene "+e.tk.gecfg.datatype}a.factor_profiles=[t];if(e.sample){a.factor_profiles.push({isgenevalueonesample:1,name:e.sample.samplename+" "+e.tk.gecfg.datatype,samplename:e.sample.samplename,datatype:e.tk.checkexpressionrank.datatype,querykey:e.tk.checkexpressionrank.querykey,mdslabel:e.tk.mds.label})}}}const s=await import("./mds.fimo-929b9e65.js");await s.init(a);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Yt(t,e){if(!e.tk.mds||!e.tk.mds.survivalplot)return;t.push({label:"Survival",callback:async t=>{const n=M(t);try{const a=e.m;const s={mutation:1};if(a.dt==x){s.chr=a.chr;s.start=a.pos;s.stop=a.pos;s.snvindel={name:(a.gene?a.gene+" ":"")+a.mname,ref:a.ref,alt:a.alt}}else if(a.dt==h){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.cnv={focalsizelimit:e.tk.bplengthUpperLimit,valuecutoff:e.tk.valueCutoff}}else if(a.dt==g){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.loh={focalsizelimit:e.tk.lohLengthUpperLimit,valuecutoff:e.tk.segmeanValueCutoff}}else if(a.dt==k){s.chr=a._chr;s.start=a._pos;s.stop=a._pos;s.sv={}}else if(a.dt==v){s.chr=a._chr;s.start=a._pos;s.stop=a._pos;s.fusion={}}else if(a.dt==b){s.chr=a.chr;s.start=a.start;s.stop=a.stop;s.itd={}}const o={renderplot:1,samplerule:{full:{},set:s}};if(e.tk.mds.survivalplot.samplegroupattrlst&&e.sample){const t=e.tk.mds.survivalplot.samplegroupattrlst[0];const n=e.tk.sampleAttribute?e.tk.sampleAttribute.samples[e.sample.samplename]:null;if(n){const e=n[t.key];if(e){o.samplerule.full.byattr=1;o.samplerule.full.key=t.key;o.samplerule.full.value=e}}}else{}const l=await import("./mds.survivalplot-b04947ee.js");await l.init({genome:e.block.genome,mds:e.tk.mds,plotlist:[o]},t,e.block.debugmode);n.remove()}catch(t){n.text("Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}})}function Gt(t){if(!t.tk.mds||!t.tk.mds.survivalplot){return}t.holder.append("div").text("Survival plot").attr("class","sja_menuoption").on("click",(()=>{t.tk.tip2.hide();t.m;const e={mutation:1};{const n=t.block.rglst;e.chr=n[t.block.startidx].chr;const a=n[t.block.startidx].start;const s=n[t.block.stopidx].stop;e.start=Math.min(a,s);e.stop=Math.max(a,s)}e.snvindel={hiddenclass:{}};{let n=false;for(const a of t.tk.legend_mclass.hiddenvalues){if(typeof a=="string"){e.snvindel.hiddenclass[a]=1;n=true}}if(!n){delete e.snvindel.hiddenclass}}if(!t.tk.legend_mclass.hiddenvalues.has(h)){e.cnv={focalsizelimit:t.tk.bplengthUpperLimit,valuecutoff:t.tk.valueCutoff}}if(!t.tk.legend_mclass.hiddenvalues.has(g)){e.loh={focalsizelimit:t.tk.lohLengthUpperLimit,valuecutoff:t.tk.segmeanValueCutoff}}if(!t.tk.legend_mclass.hiddenvalues.has(k)){e.sv={}}if(!t.tk.legend_mclass.hiddenvalues.has(v)){e.fusion={}}if(!t.tk.legend_mclass.hiddenvalues.has(b)){e.itd={}}const n={renderplot:1,samplerule:{full:{},set:e}};const s=t.samplegroup.attributes[t.samplegroup.attributes.length-1];n.samplerule.full={byattr:1,key:s.k,value:s.kvalue};const o=a({x:100,y:100});o.header.text("Survival plot");import("./mds.survivalplot-b04947ee.js").then((e=>{e.init({genome:t.block.genome,mds:t.tk.mds,plotlist:[n]},o.body,t.block.debugmode)}))}))}function Xt(t,e,n,a){if(!t.mds||!t.mds.assayAvailability)return;n.append("div").text("Assay summary").attr("class","sja_menuoption").on("click",(async()=>{t.tip2.clear();const n=t.tip2.d.append("div").style("margin","10px").text("Loading...");const s={genome:e.genome.name,dslabel:t.mds.label,querykey:t.querykey,assaymap:1};if(a.attributes){const t=a.attributes[a.attributes.length-1];s.key=t.k;s.value=t.kvalue}const o=await d("mdssvcnv",s);if(o.error){n.text("Error: "+o.error);return}n.remove();Jt({data:o,par:s,div:t.tip2.d.append("div").style("margin","10px"),boxtip:t.tktip,headlabel:a.name});t.tip2.d.append("div").style("font-size",".7em").style("margin","10px").text("Drag and move a sequencing type label up/down to change order.");if(a.attributes){const e=t.tip2.d.append("div").style("margin","20px 10px 10px 10px").style("opacity",.7);for(const t of a.attributes){e.append("div").text(t.kvalue+(t.fullvalue?": "+t.fullvalue:""))}}}))}function Jt(t){const e={headlabel:t.headlabel,par:t.par,rows:[],hidetermid:new Set,svg:t.div.append("svg")};Zt(e,t.data);const n=t.div.append("div").append("div").style("display","inline");for(const a of t.data.terms){const t=n.append("div").style("display","inline-block").style("margin-right","15px").style("white-space","nowrap");const s=t.append("label");s.append("input").attr("type","checkbox").property("checked",true).on("change",(async t=>{if(t.target.checked){e.hidetermid.delete(a.id);if(e.par.termidorder&&!e.par.termidorder.includes(a.id)){e.par.termidorder.push(a.id)}}else{e.hidetermid.add(a.id)}e.par.skip_termids=[...e.hidetermid];const n=await d("mdssvcnv",e.par);Zt(e,n)}));s.append("span").text(a.name).style("padding-left","5px")}}function Zt(t,e){const n=20,a=5,s=5,o=25,l=16,i=1,r=10,c=15;t.rows=[];t.svg.selectAll("*").remove();let p=0;for(const t of e.terms){const e=t.blocks[t.blocks.length-1];p=Math.max(p,e.x+e.symbolwidth)}const f=c*p;const m=t.svg.append("g");m.append("rect").attr("width",f).attr("height",e.terms.length*(o+i)-i).attr("stroke","#858585").attr("fill","none");{let n;const a=m.append("text").attr("text-anchor","middle").attr("font-size",l-2).attr("y",-5).text((t.headlabel?t.headlabel+", ":"")+"n="+e.totalsample).each((function(){n=this.getBBox().width}));a.attr("x",f/2-(n>f?(n-f)/2:0))}let u=0;let h=0;for(const n of e.terms){const e=m.append("g").attr("transform","translate(0,"+h+")");e.append("line").attr("stroke","#858585").attr("x1",-6).attr("y1",o/2).attr("y2",o/2);const a={id:n.id,y:h,rowg:e};t.rows.push(a);a.svglabel=e.append("text").text(n.name+", n="+n.samplecount).attr("font-size",l).attr("x",-r).attr("y",o/2).attr("dominant-baseline","middle").attr("text-anchor","end").each((function(){u=Math.max(u,this.getBBox().width)})).on("mousedown",(n=>{n.preventDefault();a.moving=true;const s=B(document.body);let l=n.clientY;let i;let r=true;s.on("mousemove",(n=>{const s=n.clientY;i=s-l;const c=t.rows.findIndex((t=>t.id==a.id));if(i<0){if(c>0&&-i>=o-2){t.rows.splice(c,1);t.rows.splice(c-1,0,a);g();i=0;l=s;r=false}}else{if(c<t.rows.length-1&&i>=o-2){t.rows.splice(c,1);t.rows.splice(c+1,0,a);g();i=0;l=s;r=false}}e.attr("transform","translate(0,"+(a.y+i)+")")}));s.on("mouseup",(async()=>{s.on("mousemove",null).on("mouseup",null);delete a.moving;g();if(r)return;a.svglabel.text("Loading...");t.par.termidorder=t.rows.map((t=>t.id));t.par.skip_termids=[...t.hidetermid];const e=await d("mdssvcnv",t.par);Zt(t,e)}))}));for(const t of n.blocks){{const n=t.symbolwidth*c;const a=t.x*c;if(!t.isgap){e.append("rect").attr("fill",t.color).attr("x",a).attr("width",n).attr("height",o);e.append("text").text(t.samplecount).attr("font-size",l-2).attr("fill","white").attr("x",a+n/2).attr("y",o/2).attr("dominant-baseline","middle").attr("text-anchor","middle")}}}h+=o+i}m.attr("transform","translate("+(s+u+r)+","+n+")");t.svg.attr("width",s*2+u+r+f).attr("height",n+(o+i)*e.terms.length+a);function g(){let e=0;for(const n of t.rows){if(!n.moving)n.rowg.transition().attr("transform","translate(0,"+e+")");n.y=e;e+=o+i}}}const Wt=14;const $t=20;function Kt(t,e){const[n,a]=Q(t,e.name);e.tr_legend=n;e.td_legend=a;const s=a.append("table").style("border-spacing","5px");e.legend_table=s;e.legend_hideable=[];te(e);if(!e.nocnvlohsv){ne(e,t);ae(e);se(e)}le(e);oe(e);ie(e);if(e.alleleAttribute)re(e.alleleAttribute,e,t);if(e.locusAttribute)re(e.locusAttribute,e,t);e.legend_more_row=s.append("tr");e.legend_more_label=e.legend_more_row.append("td").style("text-align","right").append("span");e.legend_more_row.append("td")}function Qt(t,e){ce(t);pe(t,e);if(t.singlesample){de(t);return}fe(t,e)}function te(t){if(t.checkrnabam){ee(t);return}if(!t.legend_mclass)t.legend_mclass={};if(!t.legend_mclass.hiddenvalues)t.legend_mclass.hiddenvalues=new Set;t.legend_mclass.hidden=false;t.legend_mclass.row=t.legend_table.append("tr");t.legend_mclass.row.append("td").style("text-align","right").style("opacity",.5).text("Mutation");t.legend_mclass.holder=t.legend_mclass.row.append("td");t.legend_hideable.push(t.legend_mclass)}function ee(t){const e=t.legend_table.append("tr");e.append("td").style("text-align","right").style("opacity",.5).text("DNA marker usage");const n=e.append("td");{const e=n.append("div");e.append("span").html("&times;&nbsp;").style("color",t.checkrnabam.clientcolor_snpinuse).style("font-size","1.5em");e.append("span").text("Heterozygous SNP with a p-value from binomial test").style("opacity",.5)}{const e=n.append("div");e.append("span").html("&times;&nbsp;").style("color",t.checkrnabam.clientcolor_markernotinuse).style("font-size","1.5em");e.append("span").text("Marker not in use and without binomial test").style("opacity",.5)}t.checkrnabam.legend={snpusage:{row:e}}}function ne(t,e){const n=50;t.cnvcolor.cnvlegend={axistickh:4,barw:55};t.cnvcolor.cnvlegend.row=t.legend_table.append("tr");t.cnvcolor.cnvlegend.row.append("td").style("text-align","right").style("opacity",.5).text("CNV log2(ratio)");t.legend_hideable.push(t.cnvcolor.cnvlegend);const a=t.cnvcolor.cnvlegend.row.append("td").append("div").style("display","inline-block").attr("class","sja_clb").style("padding","0px").on("click",(()=>{t.tkconfigtip.clear().showunder(a.node());{const n=t.tkconfigtip.d.append("div").append("label");n.append("input").attr("type","checkbox").property("checked",!t.hide_cnvgain).on("change",(()=>{t.hide_cnvgain=!t.hide_cnvgain;an(t,e)}));n.append("span").html("&nbsp;Show copy number gain")}{const n=t.tkconfigtip.d.append("div").style("margin-top","10px").append("label");n.append("input").attr("type","checkbox").property("checked",!t.hide_cnvloss).on("change",(()=>{t.hide_cnvloss=!t.hide_cnvloss;an(t,e)}));n.append("span").html("&nbsp;Show copy number loss")}}));const s=a.append("svg").attr("width",(n+t.cnvcolor.cnvlegend.barw)*2).attr("height",Wt+t.cnvcolor.cnvlegend.axistickh+$t);t.cnvcolor.cnvlegend.svg=s;t.cnvcolor.cnvlegend.nodatadiv=a.append("div").text("no data").style("opacity",.3).style("padding-left","10px");t.cnvcolor.cnvlegend.axisg=s.append("g").attr("transform","translate("+n+","+(Wt+t.cnvcolor.cnvlegend.axistickh)+")");const o=Math.random().toString();const l=Math.random().toString();const i=s.append("defs");{const e=i.append("linearGradient").attr("id",l);t.cnvcolor.cnvlegend.loss_stop=e.append("stop").attr("offset","0%").attr("stop-color",t.cnvcolor.loss.str);e.append("stop").attr("offset","100%").attr("stop-color","white")}{const e=i.append("linearGradient").attr("id",o);e.append("stop").attr("offset","0%").attr("stop-color","white");t.cnvcolor.cnvlegend.gain_stop=e.append("stop").attr("offset","100%").attr("stop-color",t.cnvcolor.gain.str)}s.append("rect").attr("x",n).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh).attr("width",t.cnvcolor.cnvlegend.barw).attr("height",$t).attr("fill","url(#"+l+")");s.append("rect").attr("x",n+t.cnvcolor.cnvlegend.barw).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh).attr("width",t.cnvcolor.cnvlegend.barw).attr("height",$t).attr("fill","url(#"+o+")");s.append("text").attr("x",n-5).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh+$t/2).attr("font-family",U).attr("font-size",Wt).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill","black").text("Loss");s.append("text").attr("x",n+t.cnvcolor.cnvlegend.barw*2+5).attr("y",Wt+t.cnvcolor.cnvlegend.axistickh+$t/2).attr("font-family",U).attr("font-size",Wt).attr("dominant-baseline","central").attr("fill","black").text("Gain")}function ae(t){if(t.mds&&t.mds.queries&&t.mds.queries[t.querykey]&&t.mds.queries[t.querykey].no_loh){return}const e=20;t.cnvcolor.lohlegend={axistickh:4,barw:55};t.cnvcolor.lohlegend.row=t.legend_table.append("tr");t.cnvcolor.lohlegend.row.append("td").style("text-align","right").style("opacity",.5).text("LOH seg.mean");t.legend_hideable.push(t.cnvcolor.lohlegend);const n=t.cnvcolor.lohlegend.row.append("td");const a=n.append("svg").attr("width",(e+t.cnvcolor.lohlegend.barw)*2).attr("height",Wt+t.cnvcolor.lohlegend.axistickh+$t);t.cnvcolor.lohlegend.svg=a;t.cnvcolor.lohlegend.nodatadiv=n.append("div").text("no data").style("opacity",.3).style("padding-left","10px");t.cnvcolor.lohlegend.axisg=a.append("g").attr("transform","translate("+e+","+(Wt+t.cnvcolor.lohlegend.axistickh)+")");const s=Math.random().toString();const o=a.append("defs");{const e=o.append("linearGradient").attr("id",s);e.append("stop").attr("offset","0%").attr("stop-color","white");t.cnvcolor.lohlegend.loh_stop=e.append("stop").attr("offset","100%").attr("stop-color",t.cnvcolor.loh.str)}a.append("rect").attr("x",e).attr("y",Wt+t.cnvcolor.lohlegend.axistickh).attr("width",t.cnvcolor.lohlegend.barw).attr("height",$t).attr("fill","url(#"+s+")")}function se(t){const e=t.legend_table.append("tr").style("display","none");t.legend_svchrcolor={row:e,interchrs:new Set,colorfunc:C(K),hidden:true};e.append("td").style("text-align","right").style("opacity",.5).text("SV chromosome");t.legend_svchrcolor.holder=e.append("td");t.legend_hideable.push(t.legend_svchrcolor)}function oe(t){if(t.singlesample)return;if(!t.sampleAttribute)return;for(const e in t.sampleAttribute.attributes){const n=t.sampleAttribute.attributes[e];if(!n.filter){continue}if(!n.hiddenvalues||!(n.hiddenvalues instanceof Set)){n.hiddenvalues=new Set}n.value2count=new Map;n.legendrow=t.legend_table.append("tr");n.legendcell=n.legendrow.append("td").style("text-align","right").style("opacity",.5).text(n.label);n.legendholder=n.legendrow.append("td")}}function le(t){if(!t.singlesample)return;if(!t.mds||!t.mds.mutation_signature)return;t.mutation_signature_legend={sets:{}};for(const e in t.mds.mutation_signature.sets){const n=t.legend_table.append("tr").style("display","none");n.append("td").text(t.mds.mutation_signature.sets[e].name).style("text-align","right").style("opacity",.5);const a=n.append("td");const s=a.append("table").style("border-spacing","0px").style("margin","10px");t.mutation_signature_legend.sets[e]={tr:n,td:a,table:s}}}function ie(t){if(t.singlesample)return;if(!t.mutationAttribute)return;for(const e in t.mutationAttribute.attributes){const n=t.mutationAttribute.attributes[e];if(!n.filter){continue}n.hiddenvalues=new Set;n.value2count=new Map;n.legendrow=t.legend_table.append("tr");n.legendcell=n.legendrow.append("td").style("text-align","right").style("opacity",.5).text(n.label);n.legendholder=n.legendrow.append("td")}}function re(t,e,n){for(const a in t.attributes){const s=t.attributes[a];if(!s.filter){continue}s.legendrow=e.legend_table.append("tr");s.legendcell=s.legendrow.append("td").style("text-align","right").style("opacity",.5).text(s.label);s.legendholder=s.legendrow.append("td");if(s.isnumeric){const t=s.legendholder.append("select").style("margin","0px 10px 0px 10px").on("change",(()=>{const a=t.property("value");if(a=="x"){s.disable=true}else{delete s.disable;s.keeplowerthan=a=="<"}an(e,n)}));const a=t.append("option").attr("value","<").property("text","≤");const o=t.append("option").attr("value",">").property("text","≥");const l=t.append("option").attr("value","x").property("text","X");if(s.disable){l.property("selected",1)}else if(s.keeplowerthan){a.property("selected",1)}else{o.property("selected",1)}s.legendholder.append("input").attr("type","number").style("width","50px").property("value",s.cutoffvalue).on("keyup",(t=>{if(t.key!="Enter")return;s.cutoffvalue=t.target.valueAsNumber;an(e,n)}))}else{s.hiddenvalues=new Set;s.value2count=new Map;s.legendrow=e.legend_table.append("tr");s.legendcell=s.legendrow.append("td").style("text-align","right").style("opacity",.5).text(s.label);s.legendholder=s.legendrow.append("td")}}}function ce(t){if(!t.legend_svchrcolor){return}t.legend_svchrcolor.holder.selectAll("*").remove();if(t.legend_svchrcolor.interchrs.size==0)return;t.legend_svchrcolor.row.style("display","table-row");for(const e of t.legend_svchrcolor.interchrs){const n=t.legend_svchrcolor.colorfunc(e);const a=t.legend_svchrcolor.holder.append("div").style("display","inline-block").style("margin","3px 10px 3px 0px");a.append("div").style("display","inline-block").style("border-radius","10px").style("padding","0px 10px").style("border","solid 1px "+n).style("color",n).style("font-size",".9em").text(e)}}function pe(t,e){if(!t.legend_mclass||!t.legend_mclass.holder)return;t.legend_mclass.holder.selectAll("*").remove();const n=new Map;if(t.data_vcf){for(const e of t.data_vcf){if(!n.has(e.class)){n.set(e.class,{isvcf:1,cname:e.class,count:0})}n.get(e.class).count++}}if(t.singlesample){if(t.data){for(const e of t.data){if(!n.has(e.dt)){n.set(e.dt,{dt:e.dt,count:0})}n.get(e.dt).count++}}}else if(t._data){for(const e of t._data){for(const t of e.samples){for(const e of t.items){if(!n.has(e.dt)){n.set(e.dt,{dt:e.dt,count:0})}n.get(e.dt).count++}}}}const a=[...n.values()];a.sort(((t,e)=>e.count-t.count));t.legend_mclass.total_count=a.reduce(((t,e)=>t+e.count),0);for(const e of a){let a,o,l,i="#858585";if(e.dt){a=e.dt;o=E[e.dt];if(e.dt==h)l="Copy number variation.";else if(e.dt==g)l="Loss of heterozygosity.";else if(e.dt==b){i=y[R].color;l="Internal tandem duplication."}else if(e.dt==k)l="Structural variation of DNA.";else if(e.dt==v)l="Fusion gene from RNA-seq."}else{a=e.cname;o=y[e.cname].label;i=y[e.cname].color;l=y[e.cname].desc}const r=t.legend_mclass.holder.append("div").attr("class","sja_clb").style("display","inline-block").on("click",(()=>{t.tip2.clear().d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{t.legend_mclass.hiddenvalues.add(a);s()}));t.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{for(const e of n.keys()){t.legend_mclass.hiddenvalues.add(e)}t.legend_mclass.hiddenvalues.delete(a);s()}));if(t.legend_mclass.hiddenvalues.size){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{t.legend_mclass.hiddenvalues.clear();s()}))}t.tip2.d.append("div").style("padding","10px").style("font-size",".8em").style("width","150px").text(l);t.tip2.showunder(r.node())}));r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background",i).html(e.count>1?e.count:"&nbsp;");r.append("div").style("display","inline-block").style("color",i).html("&nbsp;"+o)}for(const e of t.legend_mclass.hiddenvalues){t.legend_mclass.holder.append("div").style("display","inline-block").attr("class","sja_clb").style("text-decoration","line-through").text(Number.isInteger(e)?E[e]:y[e].label).on("click",(()=>{t.legend_mclass.hiddenvalues.delete(e);s()}))}if(t.vcfrangelimit){t.legend_mclass.holder.append("div").style("display","inline-block").text("Zoom in under "+_(t.vcfrangelimit)+" to view SNV/indel data").style("white-space","nowrap").style("margin","10px")}const s=()=>{t.tip2.hide();an(t,e)}}function de(t,e){if(!t.mds||!t.mds.mutation_signature)return;for(const e in t.mutation_signature_legend.sets){t.mutation_signature_legend.sets[e].tr.style("display","none")}if(!t.data_vcf){return}const n=new Map;for(const e of t.data_vcf){if(e.x==undefined)continue;if(!e.sampledata||!e.sampledata[0])continue;for(const a in t.mds.mutation_signature.sets){const s=e.sampledata[0][a];if(s==undefined)continue;const o=t.mds.mutation_signature.sets[a].signatures[s];if(o){if(o.nodata)continue;if(!n.has(a))n.set(a,new Map);n.get(a).set(s,1+(n.get(a).get(s)||0))}}}for(const[e,a]of n){const n=t.mutation_signature_legend.sets[e];n.tr.style("display","table-row");n.table.selectAll("*").remove();const s=[...a].sort(((t,e)=>e[1]-t[1]));for(const[a,o]of s){const s=t.mds.mutation_signature.sets[e].signatures[a];const l=n.table.append("tr");l.append("td").style("background",s.color).style("padding","0px 4px").style("color","white").style("text-align","right").html(o>1?o:"");const i=V(s.color);l.append("td").html("&nbsp;"+s.name).style("background","rgba("+i.r+","+i.g+","+i.b+",.2)").style("opacity",.6)}}}function fe(t,n){if(t.singlesample){return}const a=[];for(const s of["sampleAttribute","mutationAttribute","locusAttribute"]){if(!t[s])continue;for(const e in t[s].attributes){const n=t[s].attributes[e];if(!n.filter)continue;n.value2count.clear()}if(s=="sampleAttribute"){for(const e in t.sampleAttribute.attributes){for(const n in t.sampleAttribute.samples){ue(e,t.sampleAttribute.attributes[e],t.sampleAttribute.samples[n])}}}else{if(t._data){for(const e of t._data){for(const n of e.samples){for(const e of n.items){he(e.mattr,t,e.dt)}}}}if(t.data_vcf){for(const e of t.data_vcf){if(e.dt==x){if(e.sampledata){for(const n of e.sampledata){he(n,t,e.dt)}}if(e.info){ge(t,e)}}else{console.error("unknown dt: "+e.dt)}}}}for(const o in t[s].attributes){const l=t[s].attributes[o];if(!l.filter)continue;l.legendcell.classed("sja_hideable_legend",true).on("click",(()=>{t.tip2.hide();l.hidden=1;t.legend_more_row.style("display","table-row");e(l.legendcell,t.legend_more_label);l.legendrow.transition().delay(500).style("display","none");setTimeout((()=>{fe(t,n)}),500)}));if(l.hidden){l.legendrow.style("display","none");a.push(l);continue}if(l.value2count.size+l.hiddenvalues.size==0){l.legendrow.style("display","none");continue}l.legendrow.style("display","table-row");l.legendholder.selectAll("*").remove();const i=[...l.value2count];i.sort(((t,e)=>e[1].totalitems-t[1].totalitems));for(const[e,a]of i){const o=l.values[e]?l.values[e].name:e;const r=l.legendholder.append("div").style("display","inline-block").attr("class","sja_clb").on("click",(()=>{t.tip2.clear();if(l.hiddenvalues.has(e)){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show").on("click",(()=>{t.tip2.hide();l.hiddenvalues.delete(e);an(t,n)}))}else{t.tip2.d.append("div").attr("class","sja_menuoption").text("Hide").on("click",(()=>{t.tip2.hide();l.hiddenvalues.add(e);an(t,n)}))}t.tip2.d.append("div").attr("class","sja_menuoption").text("Show only").on("click",(()=>{t.tip2.hide();for(const[t,e]of i){l.hiddenvalues.add(t)}l.hiddenvalues.delete(e);an(t,n)}));if(l.hiddenvalues.size){t.tip2.d.append("div").attr("class","sja_menuoption").text("Show all").on("click",(()=>{t.tip2.hide();l.hiddenvalues.clear();an(t,n)}))}if(l.values[e]&&l.values[e].label){t.tip2.d.append("div").text(l.values[e].label).style("opacity",.5).style("font-size",".7em").style("margin","10px")}if(a.dt2count){const e=[...a.dt2count];e.sort(((t,e)=>e[1]-t[1]));const n=t.tip2.d.append("div").style("margin","5px").style("font-size",".7em").style("opacity",.8).style("border-spacing","4px");for(const[t,a]of e){const e=n.append("tr");e.append("td").text(E[t]);e.append("td").text(a)}}t.tip2.showunder(r.node())}));const c=s=="sampleAttribute"&&t.legend_samplegroups&&t.legend_samplegroups.color(e)?t.legend_samplegroups.color(e):"#858585";r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background",c).text(a.totalitems);r.append("span").html("&nbsp;"+o)}if(l.hiddenvalues.size){for(const e of l.hiddenvalues){const a=l.values[e]&&l.values[e].name?l.values[e].name:e;l.legendholder.append("div").style("display","inline-block").attr("class","sja_clb").style("text-decoration","line-through").text(a).on("click",(()=>{l.hiddenvalues.delete(e);an(t,n)}))}}}}me(t,n,a)}function me(t,n,a){let s=0;for(const a of t.legend_hideable){a.row.select("td").classed("sja_hideable_legend",true).on("click",(()=>{t.tip2.hide();a.hidden=1;t.legend_more_row.style("display","table-row");e(a.row.select("td"),t.legend_more_label);a.row.transition().delay(500).style("display","none");setTimeout((()=>{fe(t,n)}),500)}));a.row.style("display",a.hidden?"none":"table-row");if(a.hidden){s++}}if(!a.length&&!s){t.legend_more_row.style("display","none")}else{t.legend_more_row.style("display","table-row");t.legend_more_label.selectAll("*").remove();const e=t.legend_more_label.attr("class","sja_legend_more_btn").html("MORE...").on("click",(()=>{t.tip2.clear();for(const e of t.legend_hideable){if(!e.hidden)continue;const a=t.tip2.d.append("div").attr("class","sja_menuoption").on("click",(()=>{t.tip2.hide();e.hidden=0;fe(t,n)}));if(e.hidden&&e.total_count){a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background","#858585").text(e.total_count)}a.append("span").html("&nbsp;"+e.row.node().firstChild.innerHTML)}for(const e of a){if(!e.hidden)continue;const a=[...e.value2count.values()].reduce(((t,e)=>t+e.totalitems),0);const s=t.tip2.d.append("div").attr("class","sja_menuoption").on("click",(()=>{t.tip2.hide();e.hidden=0;fe(t,n)}));s.append("div").style("display","inline-block").attr("class","sja_mcdot").style("background","#858585").text(a);s.append("span").html("&nbsp;"+e.label)}t.tip2.showunder(e.node())}))}}function ue(t,e,n){if(!(t in n))return;if(!e.filter)return;const a=n[t];if(!e.value2count.has(a)){e.value2count.set(a,{totalitems:0})}e.value2count.get(a).totalitems++;if(!e.values){e.values={}}if(!e.values[a]){e.values[a]={name:a,label:a}}}function he(t,e,n){if(!t){return}if(!e.mutationAttribute)return;for(const a in e.mutationAttribute.attributes){const s=e.mutationAttribute.attributes[a];if(!s.filter)continue;const o=t[a];if(o==undefined){continue}if(!s.value2count.has(o)){s.value2count.set(o,{totalitems:0,dt2count:new Map})}s.value2count.get(o).totalitems++;if(!s.value2count.get(o).dt2count.has(n)){s.value2count.get(o).dt2count.set(n,0)}s.value2count.get(o).dt2count.set(n,s.value2count.get(o).dt2count.get(n)+1)}}function ge(t,e){if(!t.locusAttribute)return;for(const n in t.locusAttribute.attributes){const a=t.locusAttribute.attributes[n];if(!a.filter)continue;const s=e.info[n];if(s==undefined)continue;let o;if(Array.isArray(s)){o=s[0];if(o==".")continue}else{o=s}if(a.hiddenvalues.has(o))continue;if(!a.value2count.has(o)){a.value2count.set(o,{totalitems:0,dt2count:new Map})}a.value2count.get(o).totalitems++;if(!a.value2count.get(o).dt2count.has(e.dt)){a.value2count.get(o).dt2count.set(e.dt,0)}a.value2count.get(o).dt2count.set(e.dt,a.value2count.get(o).dt2count.get(e.dt)+1)}}function be(t,e){cn(t);const n=[];const a=[];const s=[];const o=[];const l={};let i=0,r=0,c=0;if(t.data){for(const p of t.data){if(p.dt==v||p.dt==k){const a=p.chrA+"."+p.posA+"."+p.chrB+"."+p.posB+"."+p.dt;if(!l[a]){je(p,e);if(p.x0||p.x1){l[a]=1;n.push(p);if(p.chrA!=p._chr){t.legend_svchrcolor.interchrs.add(p.chrA);t.legend_svchrcolor.colorfunc(p.chrA)}if(p.chrB!=p._chr){t.legend_svchrcolor.interchrs.add(p.chrB);t.legend_svchrcolor.colorfunc(p.chrB)}}}continue}Pn(p,t,e);if(p.x1==undefined||p.x2==undefined){console.log("unmappable: "+p.chr+" "+p.start+" "+p.stop);continue}if(p.dt==g){c=Math.max(c,p.segmean);s.push(p)}else if(p.dt==h){{if(p.value>0){i=Math.max(i,p.value)}else{r=Math.min(r,p.value)}}a.push(p)}else if(p.dt==b){o.push(p)}}if(a.length){t.cnvcolor.cnvmax=Math.max(i,-r);jn(t)}if(s.length){t.cnvcolor.segmeanmax=c;Mn(t)}}const p=_e(ke(n),t,e);t.cnv_g.attr("transform","translate(0,"+p+")");t.waterfall.axisgg.attr("transform","translate(0,"+p+")");const d=[...a,...s,...o];if(t.data_vcf){for(const e of t.data_vcf){if(e.x!=undefined){d.push(e)}}}const f=xe(d,t,e);t.height_main=t.toppad+p+f+t.bottompad;Qt(t,e)}function ke(t){const e=[];const n=8;for(let a=0;a<t.length;a++){const s=t[a];if(s.__claimed)continue;const o={x0:s.x0,x1:s.x1,_chr:s._chr,chrA:s.chrA,chrB:s.chrB,posA:s.posA,posB:s.posB,lst:[s]};for(let e=a+1;e<t.length;e++){const a=t[e];if(a.__claimed)continue;const l=a.x0==undefined||a.x1==undefined;if(s.x0!=undefined&&s.x1!=undefined){if(l)continue;if(Math.abs(a.x0-s.x0)<=n&&Math.abs(a.x1-s.x1)<=n){o.lst.push(a);a.__claimed=true}}else{if(!l)continue;const t=s.x0==undefined?s.x1:s.x0;const e=a.x0==undefined?a.x1:a.x0;if(Math.abs(t-e)<=n){o.lst.push(a);a.__claimed=true}}}e.push(o)}for(const e of t)delete e.__claimed;return e}function ve(t,e){if(e.mds&&e.mds.mutation_signature){if(t.sampledata&&t.sampledata[0]){for(const n in e.mds.mutation_signature.sets){const a=t.sampledata[0][n];if(a){return e.mds.mutation_signature.sets[n].signatures[a].color}}}}return y[t.class].color}function xe(t,e,n,a){if(t.length==0)return 0;const s=12;const o=1;let l=false;if(e.waterfall.inuse){const a=t.filter((t=>t.dt==x));if(a.length>1){if(ye(a,e,n)){l=true}}}if(!l){e.waterfall.axisg.selectAll("*").remove();e.waterfall.lab1.text("");e.waterfall.lab2.text("");e.waterfall.lab3.text("");for(const a of t){if(a.dt!=x)continue;const t=e.cnv_g.append("g");a._p={g:t};const o=ve(a,e);const l=t.append("text").attr("font-size",s).attr("font-family",U).attr("fill",o).attr("dominant-baseline","central").text(a.mname);let i;l.each((function(){i=this.getBBox().width}));const r=t.append("rect").attr("x",-s/2).attr("y",-s/2).attr("width",s).attr("height",s).attr("fill",o).attr("fill-opacity",0);let c,p;if(a.sampledata&&Xn(a.sampledata[0],e)){c=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("y1",1-s/2).attr("y2",s/2-1);p=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1)}else{c=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",1-s/2).attr("y2",s/2-1);p=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",s/2-1).attr("y2",1-s/2)}a._p.cover=t.append("rect").attr("y",-s/2).attr("width",s+en+i).attr("height",s).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{r.attr("fill-opacity",1);c.attr("stroke","white");p.attr("stroke","white");At({item:a,m_sample:a.sampledata[0],tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();r.attr("fill-opacity",0);c.attr("stroke",o);p.attr("stroke",o)}));a._p.stackw=s+5+i;if(n.width-a.x>i+en+s/2){a._p.stackx=a.x-s/2;a._p.g_x=s/2;l.attr("x",s/2+en);a._p.cover.attr("x",-s/2)}else{a._p.stackx=a.x-s/2-en-i;a._p.g_x=s/2+en+i;l.attr("x",-s/2-en).attr("text-anchor","end");a._p.cover.attr("x",-i-en-s/2)}}}t.sort(((t,e)=>{const n=t._p?t._p.stackx:Math.min(t.x1,t.x2);const a=e._p?e._p.stackx:Math.min(e.x1,e.x2);return n-a}));const i=[0];for(const e of t){if(l&&e.dt==x)continue;delete e.stack;const t=e._p?e._p.stackx:Math.min(e.x1,e.x2);const n=e._p?e._p.stackw:Math.abs(e.x1-e.x2);for(let a=0;a<i.length;a++){if(i[a]<=t){i[a]=t+n;e.stack=a;break}}if(e.stack==undefined){e.stack=i.length;i.push(t+n)}}const r=l?e.waterfall.axisheight+e.waterfall.bottompad:0;for(const n of t){if(n.dt==g||n.dt==h||n.dt==b){let t;if(n.dt==g){t="rgba("+e.cnvcolor.loh.r+","+e.cnvcolor.loh.g+","+e.cnvcolor.loh.b+","+n.segmean/e.cnvcolor.segmeanmax+")"}else if(n.dt==h){if(n.value>0){t="rgba("+e.cnvcolor.gain.r+","+e.cnvcolor.gain.g+","+e.cnvcolor.gain.b+","+n.value/e.cnvcolor.cnvmax+")"}else{t="rgba("+e.cnvcolor.loss.r+","+e.cnvcolor.loss.g+","+e.cnvcolor.loss.b+","+-n.value/e.cnvcolor.cnvmax+")"}}else if(n.dt==b){t=y[R].color}e.cnv_g.append("rect").attr("x",Math.min(n.x1,n.x2)).attr("y",r+(s+o)*n.stack).attr("width",Math.max(1,Math.abs(n.x2-n.x1))).attr("height",s).attr("fill",t).attr("shape-rendering","crispEdges").attr("stroke","none").attr("class","sja_aa_skkick").on("mouseover",(()=>{At({item:n,tk:e})})).on("mouseout",(()=>{e.tktip.hide()}));continue}if(n.dt==x&&!l){n._p.g.attr("transform","translate("+(n._p.stackx+n._p.g_x)+","+(s/2+(s+o)*n.stack)+")");continue}}return r+i.length*(s+o)-o}function ye(t,e,n){t[0].water={h:e.waterfall.axisheight};let a=0;for(let n=1;n<t.length;n++){const s=t[n];if(s.chr!=t[n-1].chr){s.water={h:e.waterfall.axisheight};continue}s.water={bpdist:s.pos-t[n-1].pos};a=Math.max(a,s.water.bpdist)}if(a<2){return false}q({axis:e.waterfall.axisg.call(et().ticks(3,".0f").scale(nt().domain([1,a]).range([e.waterfall.axisheight,0]))),color:"black",showline:1});e.waterfall.lab1.text("Log10").attr("y",e.waterfall.axisheight/2-14);e.waterfall.lab2.text("intermutation").attr("y",e.waterfall.axisheight/2);e.waterfall.lab3.text("distance").attr("y",e.waterfall.axisheight/2+14);for(let n=1;n<t.length;n++){const s=t[n];if(s.water.h){continue}if(s.water.bpdist==0){s.water.h=0}else{s.water.h=Math.log10(s.water.bpdist)*e.waterfall.axisheight/Math.log10(a)}}const s=12;for(const a of t){const t=e.cnv_g.append("g").attr("transform","translate("+a.x+","+(e.waterfall.axisheight-a.water.h)+")");const o=ve(a,e);const l=t.append("rect").attr("x",-s/2).attr("y",-s/2).attr("width",s).attr("height",s).attr("fill",o).attr("fill-opacity",0);let i,r;if(a.sampledata&&Xn(a.sampledata[0],e)){i=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("y1",1-s/2).attr("y2",s/2-1);r=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1)}else{i=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",1-s/2).attr("y2",s/2-1);r=t.append("line").attr("stroke",o).attr("stroke-width",2).attr("x1",1-s/2).attr("x2",s/2-1).attr("y1",s/2-1).attr("y2",1-s/2)}t.append("rect").attr("y",-s/2).attr("x",-s/2).attr("width",s).attr("height",s).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{l.attr("fill-opacity",1);i.attr("stroke","white");r.attr("stroke","white");At({item:a,m_sample:a.sampledata[0],tk:e,block:n})})).on("mouseout",(()=>{e.tktip.hide();l.attr("fill-opacity",0);i.attr("stroke",o);r.attr("stroke",o)}));delete a.water}return true}function _e(t,e,n){if(t.length==0)return 0;let s;{let n=1;for(const e of t)n=Math.max(n,e.lst.length);const a=Math.pow(e.discradius,2)*Math.PI;const o=N();if(n==1){o.domain([1,1]).range([a,a])}else if(n==2){o.domain([1,2]).range([a,a*1.3])}else if(n==3){o.domain([1,3]).range([a,a*1.6])}else if(n==4){o.domain([1,4]).range([a,a*1.8])}else if(n==6){o.domain([1,6]).range([a,a*2])}else if(n==10){o.domain([1,10]).range([a,a*3])}else{o.domain([1,n]).range([a,a*4])}s=o}let o=0;for(const e of t){e.radius=Math.sqrt(s(e.lst.length)/Math.PI);o=Math.max(e.radius,o);if(e.x0!=undefined&&e.x1!=undefined){if(e.x0>e.x1){const t=e.x1;e.x1=e.x0;e.x0=t}e._x=(e.x0+e.x1)/2}else{e._x=e.x0||e.x1}e.x=e._x}const l=o*2+o*2+(t.find((t=>t.x0&&t.x1))?e.legheight:0);e.svvcf_g.attr("transform","translate(0,"+(l-0)+")");n.width+n.subpanels.reduce(((t,e)=>t+e.leftpad+e.width),0);for(const s of t){const t=s.x0&&s.x1;const o=e.legheight*(t?1:0);const l=s.lst.length==1?s.radius:s.radius*2;const i=e.svvcf_g.append("g").attr("transform","translate("+s.x+",-"+(o+l)+")");const r=s.chrA==s._chr?s.chrB:s.chrA;const c=r==s._chr?Ye:e.legend_svchrcolor.colorfunc(r);i.append("circle").attr("r",s.radius).attr("cy",-s.radius).attr("fill",c).attr("stroke","white");if(s.lst.length>1){const t=s.radius*1.5;const e=s.lst.length.toString();const n=Math.min(t/(e.length*I),t);i.append("text").text(e).attr("text-anchor","middle").attr("dominant-baseline","central").attr("fill","white").attr("y",-s.radius).attr("font-size",n).attr("font-family",U)}i.append("circle").attr("r",s.radius).attr("cy",-s.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",c).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(t=>{if(s.lst.length==1){At({item:s.lst[0],tk:e});return}Me(s.lst,e,t)})).on("mouseout",(()=>e.tktip.hide())).on("click",(t=>{if(s.lst.length==1){const o=s.lst[0];const l=a({x:t.clientX,y:t.clientY});l.header.text(o.sample);l.body.style("margin-top","10px");const[i,r]=we(o,n);if(i){const t=l.body.append("div").style("margin-bottom","5px");t.append("div").style("display","inline-block").text("Add new panel at "+i.name+":"+r).attr("class","sja_menuoption").on("click",(()=>{t.remove();Ae(i,r,n)}))}Vt({item:o,block:n},l.body.append("div"));jt({item:o,tk:e,holder:l.body.append("div")});return}ze(s.lst,e,n,t)}));if(t){i.append("line").attr("stroke",c).attr("y2",l).attr("shape-rendering","crispEdges");i.append("line").attr("stroke",c).attr("x2",(s.x1-s.x0)/2-(s.x-s._x)).attr("y1",l).attr("y2",l+o);i.append("line").attr("stroke",c).attr("x2",-(s.x1-s.x0)/2-(s.x-s._x)).attr("y1",l).attr("y2",l+o)}else{i.append("line").attr("stroke",c).attr("y2",l+o).attr("shape-rendering","crispEdges")}}return l}function we(t,e){let n;let a;if(t._chr!=t.chrA){n=t.chrA;a=t.posA}else if(t._chr!=t.chrB){n=t.chrB;a=t.posB}if(!n)return[null];const s=e.genome.chrlookup[n.toUpperCase()];if(!s){e.error("Invalid chr name: "+n);return[null]}for(const t of e.subpanels){if(t.chr==n){return[null]}}return[s,a]}function Ae(t,e,n){const a=1e4;const s={chr:t.name,start:Math.max(0,e-a),stop:Math.min(t.len,e+a),width:600,leftpad:10,leftborder:"rgba(50,50,50,.1)"};s.exonsf=s.width/(s.stop-s.start);n.init_coord_subpanel(s);n.subpanels.push(s);n.ifbusy()}function je(t,e){const n=e.seekcoord(t.chrA,t.posA);for(const a of n){if(a.ridx!=undefined){if(a.x>0&&a.x<e.width){t.x0=a.x;break}}else if(a.subpanelidx!=undefined){t.x0=a.x}}const a=e.seekcoord(t.chrB,t.posB);for(const n of a){if(n.ridx!=undefined){if(n.x>0&&n.x<e.width){t.x1=n.x;break}}else if(n.subpanelidx!=undefined){t.x1=n.x}}}function Me(t,e,n){e.tktip.clear();Le(t,e.tktip.d,e);e.tktip.show(n.clientX,n.clientY)}function ze(t,e,n,s){const o=a({x:s.clientX,y:s.clientY});Le(t,o.body,e)}function Le(t,e,n){const a=e.append("table");for(const e of t){const t=a.append("tr");t.append("td").style("font-size",".7em").text(e.dt==k?"SV":"Fusion");t.append("td").text(yn(e));t.append("td").style("font-size",".8em").html(qt(e,n))}}function Se(t,e){t.cnvrightg.selectAll("*").remove();const n=[];if(t.sampleAttribute&&t.sampleAttribute.attributes&&t.sampleAttribute.samples){for(const e in t.sampleAttribute.attributes){const a=t.sampleAttribute.attributes[e];if(!a.showintrack)continue;const s={key:e,label:a.label,min:null,max:null};for(const n of t.samplegroups){for(const a of n.samples){const n=t.sampleAttribute.samples[a.samplename];if(!n)continue;const o=n[e];if(Number.isNaN(o))continue;if(s.min==null){s.min=s.max=o}else{s.min=Math.min(s.min,o);s.max=Math.max(s.max,o)}}}n.push(s)}}const a=new Set;if(t._data){for(const e of t._data){if(!e.samples)continue;for(const t of e.samples){if(!t.expressionrank)continue;for(const e in t.expressionrank){a.add(e)}}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes){for(const t of n.genes){a.add(t.gene)}}}}const s=t.gecfg?t.gecfg.fixed:[];let o;if(t.selectedgene&&a.has(t.selectedgene)){o=t.selectedgene}else{o=[...a][0]}if(o){for(const t of s){if(o==t.gene){o=undefined;break}}}if(o){t.showinggene=o}else if(s[0]){t.showinggene=s[0].name}for(const e of t.samplegroups){for(const t of e.samples){if(t.expressionrank){for(const e in t.expressionrank){if(t.expressionrank[e].ase);}}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes&&n.genes.find((t=>t.gene==o)));}}for(const e of t.samplegroups){for(const t of e.samples){t.columnbars=[]}}let l=0;l+=Ue(o,a,t,e);for(const n of s){l+=qe(n,t,e,l)}for(const a of n){l+=Be(a,t,e,l)}if(t.gecfg&&t.gecfg.fixed_pend){const n=t.gecfg.fixed_pend.shift();if(t.gecfg.fixed_pend.length==0){delete t.gecfg.fixed_pend}Oe(n.gene,t,e)}t.rightheadw_tk=l;e.rightheadw=0;for(const t of e.tklst){e.rightheadw=Math.max(e.rightheadw,t.rightheadw_tk)}e.blocksetw();const i=0;const r=3;const c=5;const p=12;return p+p+r+c+i}function Ne(t){const{gene:e,samplename:n,value:s,tk:o,block:l}=t;const i=a({x:window.innerWidth/2,y:100});i.header.text(e+" "+o.gecfg.datatype+" from "+o.name);const r=o.gene2coord[e];if(!r){i.body.text("No coordinate for "+e);return}const c={gene:e,chr:r.chr,start:r.start,stop:r.stop,holder:i.body,block:l,genome:l.genome,sample:n?{name:n,value:s}:null,sampleset:o.sampleset};if(o.iscustom){for(const t in o.checkexpressionrank){c[t]=o.checkexpressionrank[t]}}else{const t=o.mds.queries[o.querykey].checkexpressionrank;c.dslabel=o.mds.label;c.querykey=t.querykey;c.boxplotgroupers=t.boxplotgroupers}c.color={cnvgain:o.cnvcolor.gain.str,cnvloss:o.cnvcolor.loss.str,sv:"black"};if(o.iscustom){c.svcnv={iscustom:1,file:o.file,url:o.url,indexURL:o.indexURL}}else{c.svcnv={dslabel:o.mds.label,querykey:o.querykey}}c.svcnv.valueCutoff=o.valueCutoff;c.svcnv.bplengthUpperLimit=o.bplengthUpperLimit;c.clicksample=(t,e,n)=>{const a={samplename:t.sample};let s;if(e){s={attributes:e.attributes}}const o={};for(const t in n.svcnv){o[t]=n.svcnv[t]}if(n.svcnv.iscustom){o.checkexpressionrank={file:n.file,url:n.url,indexURL:n.indexURL,datatype:n.gecfg.datatype}}else{o.mds=n.block.genome.datasets[n.svcnv.dslabel]}zn({m:{dt:h,chr:n.chr,start:n.start,stop:n.stop},sample:a,samplegroup:s,tk:o,block:n.block})};import("./block.mds.geneboxplot-c1276cba.js").then((t=>{t.init(c)}))}function Ue(t,e,n,a){const s=80;const o=15;const l=0;const i=3;const r=5;const c=12;if(t){let p=0;let d=100;if(n.checkrnabam){d=0;for(const e in n.checkrnabam.samples){const a=n.checkrnabam.samples[e];if(a.genes){const e=a.genes.find((e=>e.gene==t));if(e){d=Math.max(d,e.fpkm)}}}}for(const e of n.samplegroups){let o=e.y;for(const l of e.samples){const e=n.cnvrightg.append("g").attr("transform","translate(0,"+o+")");if(l.expressionrank){const o=l.expressionrank[t];if(o!=undefined){e.append("rect").attr("fill",X(o,n.gecfg)).attr("width",s*o.rank/d).attr("height",l.height).attr("shape-rendering","crispEdges");const i=e.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",s).attr("height",l.height);if(n.isfull){l.columnbars.push(i)}i.on("mouseover",(e=>{n.tktip.clear();He(t,o,l,n.tktip.d,n);n.tktip.show(e.clientX,e.clientY);kn(l)})).on("mouseout",(()=>{n.tktip.hide();vn(l)})).on("click",(()=>{Ne({gene:t,samplename:l.samplename,value:o.value,tk:n,block:a})}))}}else if(n.checkrnabam){const o=n.checkrnabam.samples[l.samplename];if(o&&o.genes){const i=o.genes.find((e=>e.gene==t));if(i){Te(s,d,e,i,l,n,a)}}}o+=l.height+n.rowspace}}const f=n.cnvrightg.append("g").attr("transform","translate(0,-"+l+")");q({axis:f.append("g").call(tt().scale(N().domain([p,d]).range([0,s])).tickValues([0,d]).tickSize(r)),fontsize:c,showline:1});f.append("text").attr("text-anchor","middle").attr("x",s/2).attr("y",-(c+i+r+l)).attr("font-family",U).attr("font-size",c).text(t+" "+(n.checkrnabam?n.gecfg.datatype:"rank")).attr("class","sja_clbtext2").on("click",(()=>{Ce(t,e,n,a)}));return s+o}if(n.gecfg){const t=n.cnvrightg;t.append("text").attr("class","sja_clbtext2").attr("font-family",U).attr("font-size",14).text("ADD GENE").on("click",(t=>{Ie(n.tkconfigtip.clear().d,n,a);n.tkconfigtip.showunder(t.target)}));if(n.expressionrangelimit){const e=15;let a=20;t.append("text").text("Zoom in").attr("y",a).attr("font-size",12);a+=e;t.append("text").text("under").attr("y",a).attr("font-size",12);a+=e;t.append("text").text(_(n.expressionrangelimit)).attr("y",a).attr("font-size",12);a+=e;t.append("text").text("to show").attr("y",a).attr("font-size",12);a+=e;t.append("text").text("gene exp").attr("y",a).attr("font-size",12)}return s+o}return 0}function qe(t,e,n,a){if(!e.gene2coord)e.gene2coord={};e.gene2coord[t.gene]={chr:t.chr,start:t.start,stop:t.stop};const s=80;const o=15;const l=0;const i=3;const r=5;const c=12;let p=0,d=100;if(t.sample2rnabam){d=0;for(const e in t.sample2rnabam){d=Math.max(d,t.sample2rnabam[e].fpkm)}}for(const o of e.samplegroups){let l=o.y;for(const i of o.samples){const o=e.cnvrightg.append("g").attr("transform","translate("+a+","+l+")");if(t.sample2rnabam){const a=t.sample2rnabam[i.samplename];if(a){Te(s,d,o,a,i,e,n)}}else{const a=t.sample2rank[i.samplename];if(a){o.append("rect").attr("fill",X(a,e.gecfg)).attr("width",s*a.rank/d).attr("height",i.height).attr("shape-rendering","crispEdges");if(e.isfull&&a.estat){if(a.estat.outlier){o.append("circle").attr("cx",s).attr("cy",i.height/2).attr("r",i.height/2).attr("fill",e.gecfg.outlier.color_outlier)}else if(a.estat.outlier_asehigh){o.append("circle").attr("cx",s).attr("cy",i.height/2).attr("r",i.height/2).attr("fill",e.gecfg.outlier.color_outlier_asehigh)}}const l=o.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",s).attr("height",i.height);if(e.isfull){i.columnbars.push(l)}l.on("mouseover",(n=>{e.tktip.clear();const s=[{k:"Sample",v:i.samplename}];Et(i.samplename,e,s);s.push({k:t.gene+" rank",v:j(a.rank)});s.push({k:t.gene+" "+e.gecfg.datatype,v:a.value});const o=f(e.tktip.d,s);J(a,e.gecfg,o);e.tktip.show(n.clientX,n.clientY);kn(i)})).on("mouseout",(()=>{e.tktip.hide();vn(i)})).on("click",(()=>{Ne({gene:t.gene,samplename:i.samplename,value:a.value,tk:e,block:n})}))}}l+=i.height+e.rowspace}}const m=e.cnvrightg.append("g").attr("transform","translate("+a+",-"+l+")");q({axis:m.append("g").call(tt().scale(N().domain([p,d]).range([0,s])).tickValues([p,d]).tickSize(r)),fontsize:c,showline:1});m.append("text").attr("text-anchor","middle").attr("x",s/2).attr("y",-(c+i+r+l)).attr("font-family",U).attr("font-size",c).attr("fill","black").attr("class","sja_clbtext2").text(t.gene+" rank").on("click",(a=>{Ee(t,e,n);e.tkconfigtip.showunder(a.target)}));return s+o}function Be(t,e,n,a){const s=80;const o=80;const l=15;const i=0;const r=3;const c=5;const p=12;for(const n of e.samplegroups){let s=n.y;for(const l of n.samples){const n=e.cnvrightg.append("g").attr("transform","translate("+a+","+s+")");const i=e.sampleAttribute.samples[l.samplename];if(i){const a=i[t.key];if(!Number.isNaN(a)){n.append("rect").attr("x",0).attr("width",Math.max(1,o*(a-t.min)/(t.max-t.min))).attr("height",l.height).attr("fill","#858585").attr("shape-rendering","crispEdges");n.append("rect").attr("x",0).attr("width",o).attr("height",l.height).attr("fill","#858585").attr("fill-opacity",.1);const s=n.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",o).attr("height",l.height);l.columnbars.push(s);s.on("mouseover",(t=>{e.tktip.clear();const n=[{k:"Sample",v:l.samplename}];Et(l.samplename,e,n);f(e.tktip.d,n);e.tktip.show(t.clientX,t.clientY);kn(l)})).on("mouseout",(()=>{e.tktip.hide();vn(l)}))}}s+=l.height+e.rowspace}}const d=e.cnvrightg.append("g").attr("transform","translate("+a+",-"+i+")");q({axis:d.append("g").attr("transform","translate(0,0)").call(tt().scale(N().domain([t.min,t.max]).range([0,o])).ticks(3)),fontsize:p,showline:1});d.append("text").attr("x",o/2).attr("text-anchor","middle").attr("y",-(p+r+c+i)).attr("font-family",U).attr("font-size",p).text(t.label);return s+l}function Ce(t,e,n,a){n.tkconfigtip.clear();const s=n.tkconfigtip.d;Ie(s,n,a);if(e.size>1){const o=s.append("div").style("margin-bottom","15px");if(e.size>8){o.style("height","200px").style("padding","15px").style("overflow-y","scroll").style("resize","vertical")}const l=Math.random().toString();for(const s of e){const e=o.append("div");const i=Math.random().toString();const r=e.append("input").attr("type","radio").attr("id",i).attr("name",l).on("change",(()=>{n.tkconfigtip.hide();n.selectedgene=s;Se(n,a)}));if(s==t)r.attr("checked",1);e.append("label").attr("for",i).attr("class","sja_clbtext").html("&nbsp;"+s)}}De(s,t,n,a);if(n.mds){Ve(s,{gene:t,chr:n.gene2coord[t].chr,start:n.gene2coord[t].start,stop:n.gene2coord[t].stop},n,a)}Re(s,n,a);n.tkconfigtip.showunder(event.target)}function Ee(t,e,n){e.tkconfigtip.clear();De(e.tkconfigtip.d,t.gene,e,n);Ve(e.tkconfigtip.d,t,e,n);e.tkconfigtip.d.append("div").attr("class","sja_menuoption").text("Remove").on("click",(()=>{e.tkconfigtip.hide();const a=e.gecfg.fixed.findIndex((e=>e.gene==t.gene));if(a==-1){return}e.gecfg.fixed.splice(a,1);Se(e,n)}))}function Re(t,e,n){if(!e.gecfg||e.gecfg.no_ase)return;t.append("div").text("Customize ASE parameters").attr("class","sja_menuoption").on("click",(()=>{t.selectAll("*").remove();Z(t,e.gecfg,e,(()=>{e.tkconfigtip.hide();An(e);Se(e,n)}))}))}function Ve(t,e,n,s){if(!n.mds||!n.mds.survivalplot)return;t.append("div").text("Survival plot by "+e.gene+" "+n.gecfg.datatype).attr("class","sja_menuoption").on("click",(()=>{n.tkconfigtip.hide();const t=a({x:100,y:100});t.header.text("Survival plot by "+e.gene+" "+n.gecfg.datatype);const o={genome:s.genome,mds:n.mds,plotlist:[{renderplot:1,samplerule:{set:{geneexpression:1,bymedian:1,gene:e.gene,chr:e.chr,start:e.start,stop:e.stop}}}]};import("./mds.survivalplot-b04947ee.js").then((e=>{e.init(o,t.body,s.debugmode)}))}))}function Ie(t,e,n){O({div:t,genome:n.genome.name,tip:e.tip2,callback:t=>{Oe(t,e,n)}})}async function Oe(t,e,n,a){e.tkconfigtip.clear();const s=e.tkconfigtip.d.append("div").text("Searching for "+t+" ...");try{const o=await z("genelookup",{body:{genome:n.genome.name,input:t,deep:1}});if(o.error)throw o.error;if(!o.gmlst)throw".gmlst[] missing";const l=o.gmlst[0];s.text("Loading "+e.gecfg.datatype+" for "+l.name+" ...");const i=await Fe(l,e,n);if(i.error)throw i.error;const r={gene:t,chr:l.chr,start:l.start,stop:l.stop};if(i.sample2rnabam){for(const t in i.sample2rnabam){W(i.sample2rnabam[t],e.gecfg)}r.sample2rnabam=i.sample2rnabam}else{if(!i.sample2rank)throw".sample2rank{} missing";for(const t in i.sample2rank){W(i.sample2rank[t],e.gecfg)}r.sample2rank=i.sample2rank}e.gecfg.fixed.push(r);e.tkconfigtip.hide();if(a){}else{Se(e,n)}}catch(t){if(t.stack)console.log(t.stack);s.text("Error: "+(t.message?t.message:t))}}function Fe(t,e,n){const a={genome:n.genome.name,getexpression4gene:{chr:t.chr,start:t.start,stop:t.stop,name:t.name}};if(e.iscustom){a.iscustom=1;const t=e.checkexpressionrank;if(t){a.checkexpressionrank={file:t.file,url:t.url,indexURL:t.indexURL}}if(e.checkvcf){a.checkvcf=e.checkvcf.stringifiedObj}if(e.checkrnabam){Ln(e,a,true)}}else{a.dslabel=e.mds.label;a.querykey=e.querykey}return d("mdssvcnv",a)}function He(t,e,n,a,s){const o=[{k:"Sample",v:n.samplename}];Et(n.samplename,s,o);if(s.checkrnabam){o.push({k:t+" "+s.gecfg.datatype,v:e.fpkm})}else{o.push({k:t+" rank",v:j(e.rank)});o.push({k:t+" "+s.gecfg.datatype,v:e.value})}const l=f(a,o);J(e,s.gecfg,l)}function Pe(t,e,n,o){const l=a({x:window.innerWidth/2,y:100});l.header.text(t.gene+" in "+e.samplename);const i=l.body.append("div").style("margin","10px 0px 20px 0px");if(n.checkrnabam&&n.checkvcf){const a=n.checkrnabam.samples[e.samplename];if(a){const l={type:s.ase,name:e.samplename+" ASE",samplename:e.samplename,rnabamfile:a.file,rnabamurl:a.url,rnabamindexURL:a.indexURL,rnabamtotalreads:a.totalreads,rnabamispairedend:a.pairedend,vcffile:n.checkvcf.file,vcfurl:n.checkvcf.url,vcfindexURL:n.checkvcf.indexURL};Ln(n,l,false);const r={style:{margin:"0px"},tklst:[l],holder:i,chr:t.chr,start:t.start,stop:t.stop};F(o.genome,r.tklst);const c=o.newblock(r);if(o.debugmode){window.bbb=c}}else{i.text("sbam missing")}}else{i.text("checkrnabam or checkvcf missing")}He(t.gene,t,e,l.body,n)}function Te(t,e,n,a,s,o,l){n.append("rect").attr("fill",X(a,o.gecfg)).attr("width",t*a.fpkm/e).attr("height",s.height).attr("shape-rendering","crispEdges");const i=n.append("rect").attr("fill",Xe).attr("fill-opacity",.1).attr("width",t).attr("height",s.height);if(o.isfull){s.columnbars.push(i)}i.on("mouseover",(t=>{o.tktip.clear();He(a.gene,a,s,o.tktip.d,o);o.tktip.show(t.clientX,t.clientY);kn(s)})).on("mouseout",(()=>{o.tktip.hide();vn(s)})).on("click",(()=>{Pe(a,s,o,l)}))}function De(t,e,n,a){if(n.checkrnabam)return;t.append("div").text(e+" "+n.gecfg.datatype+" boxplot").attr("class","sja_menuoption").on("click",(()=>{n.tkconfigtip.hide();Ne({gene:e,tk:n,block:a})}))}const Ye="#858585";const Ge="#E8FFFF";const Xe="#222";const Je="#ED8600";const Ze=7;const We=5;const $e="#aaa";const Ke=5;const Qe="CELLLINE";const tn=0;const en=5;const nn=N().domain([1,3,5,10]).range([8,4,2,1]);function an(t,e){e.tkcloakon(t);e.block_setheight();if(t.uninitialized){qn(t,e);delete t.uninitialized}Promise.resolve().then((()=>ln(t,e))).then((()=>on(t,e))).then((()=>rn(t,e))).catch((n=>{t.height_main=50;if(n.nodata){cn(t);delete t.data_vcf;if(t.singlesample){delete t.data}else{delete t._data;delete t.samplegroups;sn(t,e)}Qt(t,e);return{error:t.name+": no data in view range"}}if(n.stack)console.error(n.stack);return{error:n.message}})).then((n=>{e.tkcloakoff(t,{error:n.error});e.block_setheight();e.setllabel()}))}function sn(t,e){const n=[];if(t.gene2coord){for(const e in t.gene2coord)n.push(e)}if(n.length==0)return;if(!t.gecfg){console.error("but .gecfg is missing");return}t.cnvrightg.attr("transform","translate(0,"+(4+t.height_main/2)+")");const a=t.cnvrightg.append("text").attr("font-size",12).attr("class","sja_clbtext2");if(n.length==1){a.text(n[0]).on("click",(a=>{const s=t.gene2coord[n[0]];Ee({gene:n[0],chr:s.chr,start:s.start,stop:s.stop},t,e);t.tkconfigtip.showunder(a.target)}));return}a.text("Select gene").on("click",(()=>{t.tkconfigtip.clear().showunder(a.node());for(const a of n){t.tkconfigtip.d.append("div").text(a).attr("class","sja_menuoption").on("click",(()=>{const n=t.gene2coord[a];Ee({gene:a,chr:n.chr,start:n.start,stop:n.stop},t,e)}))}}))}function on(t,e){if(!t.checkrnabam)return;const n=[];for(const a in t.checkrnabam.samples){const s=t.checkrnabam.samples[a];n.push(d("bamnochr",{genome:e.genome.name,file:s.file,url:s.url,indexURL:s.indexURL}).then((t=>{if(t.error)throw{message:t.error};s.nochr=t.nochr})))}return Promise.all(n)}function ln(t,e){if(!t.iscustom)return;if(t.checkvcf&&!t.checkvcf.stringifiedObj){const n=["genome="+e.genome.name];if(t.checkvcf.file){n.push("file="+t.checkvcf.file)}else{n.push("url="+t.checkvcf.url);if(t.checkvcf.indexURL)n.push("indexURL="+t.checkvcf.indexURL)}return H("vcfheader?"+n.join("&")).then((e=>{if(!e)throw{message:"server error!"};if(e.error)throw{message:e.error};const[n,a,s,o]=at(e.metastr.split("\n"));if(o)throw{message:"Error parsing VCF meta lines: "+o.join("; ")};t.checkvcf.info=n;t.checkvcf.format=a;t.checkvcf.samples=s;t.checkvcf.nochr=e.nochr;t.checkvcf.stringifiedObj=JSON.stringify(t.checkvcf)}))}}function rn(t,e){const n={genome:e.genome.name,rglst:e.tkarg_maygm(t)};if(e.subpanels.length==t.subpanels.length){for(const[t,a]of e.subpanels.entries()){n.rglst.push({chr:a.chr,start:a.start,stop:a.stop,width:a.width,exonsf:a.exonsf,subpanelidx:t})}}pn(n,t);return d("/mdssvcnv",n).then((n=>{if(n.error)throw{message:n.error};t._data_vcf=n.data_vcf;t.vcfrangelimit=n.vcfrangelimit;Yn(t,e);Dn(t,e);if(t.singlesample){if(!n.lst||n.lst.length==0){if(!t.data_vcf||t.data_vcf.length==0){throw{nodata:1}}}t.data=n.lst}else{t.gene2coord=n.gene2coord;t.expressionrangelimit=n.expressionrangelimit;if(!n.samplegroups||n.samplegroups.length==0){throw{nodata:1}}t._data=n.samplegroups;if(t.sampleAttribute){if(n.sampleannotation){t.sampleAttribute.samples=n.sampleannotation}else{t.sampleAttribute.samples={}}}if(t.checkrnabam){for(const e in t.checkrnabam.samples){delete t.checkrnabam.samples[e].genes;if(n.checkrnabam){const a=n.checkrnabam.find((t=>t.sample==e));if(a)t.checkrnabam.samples[e].genes=a.genes}}}}if(t.legend_svchrcolor){t.legend_svchrcolor.interchrs.clear();t.legend_svchrcolor.row.style("display","none")}if(t.singlesample){be(t,e)}else{dn(t,e)}return{}}))}function cn(t){if(t.singlesample){t.waterfall.axisg.selectAll("*").remove();t.waterfall.lab1.text("");t.waterfall.lab2.text("");t.waterfall.lab3.text("");t.svvcf_g.selectAll("*").remove();t.cnv_g.selectAll("*").remove();if(t.cnvcolor.cnvlegend)t.cnvcolor.cnvlegend.row.style("display","none");if(t.cnvcolor.lohlegend)t.cnvcolor.lohlegend.row.style("display","none");return}t.cnvleftg.selectAll("*").remove();t.vcfdensitylabelg.selectAll("*").remove();t.vcfdensityg.selectAll("*").remove();t.svdensitylabelg.selectAll("*").remove();t.svdensityg.selectAll("*").remove();t.cnvmidg.selectAll("*").remove();t.cnvrightg.selectAll("*").remove();t.config_handle.transition().attr("text-anchor","start").attr("x",0)}function pn(t,e){if(e.iscustom){t.iscustom=1;t.file=e.file;t.url=e.url;t.indexURL=e.indexURL;if(e.checkexpressionrank){t.checkexpressionrank={};for(const n in e.checkexpressionrank){t.checkexpressionrank[n]=e.checkexpressionrank[n]}}if(e.checkvcf){t.checkvcf=e.checkvcf.stringifiedObj}if(e.checkrnabam){Ln(e,t,true)}}else{t.dslabel=e.mds.label;t.querykey=e.querykey}if(e.getallsamples){t.getallsamples=true}if(e.sampleset)t.sampleset=e.sampleset;if(e.valueCutoff)t.valueCutoff=e.valueCutoff;if(Number.isInteger(e.bplengthUpperLimit))t.bplengthUpperLimit=e.bplengthUpperLimit;if(e.showonlycnvwithsv)t.showonlycnvwithsv=1;t.hide_cnvgain=e.hide_cnvgain;t.hide_cnvloss=e.hide_cnvloss;if(e.segmeanValueCutoff)t.segmeanValueCutoff=e.segmeanValueCutoff;if(Number.isInteger(e.lohLengthUpperLimit))t.lohLengthUpperLimit=e.lohLengthUpperLimit;if(e.singlesample){t.singlesample=e.singlesample.name}else{if(e.sampleAttribute){const n={};let a=false;for(const t in e.sampleAttribute.attributes){const s=e.sampleAttribute.attributes[t];if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}if(a){t.hiddensampleattr=n}}}if(e.mutationAttribute){const n={};let a=false;for(const t in e.mutationAttribute.attributes){const s=e.mutationAttribute.attributes[t];if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}if(a){t.hiddenmattr=n}}if(e.alleleAttribute){const n={};let a=false;for(const t in e.alleleAttribute.attributes){const s=e.alleleAttribute.attributes[t];if(s.disable)continue;if(s.isnumeric){if(Number.isFinite(s.cutoffvalue)){n[t]={cutoffvalue:s.cutoffvalue,keeplowerthan:s.keeplowerthan};a=true}}else{if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}}if(a){t.filteralleleattr=n}}if(e.locusAttribute){const n={};let a=false;for(const t in e.locusAttribute.attributes){const s=e.locusAttribute.attributes[t];if(s.disable)continue;if(s.isnumeric){if(Number.isFinite(s.cutoffvalue)){n[t]={cutoffvalue:s.cutoffvalue,keeplowerthan:s.keeplowerthan};a=true}}else{if(s.hiddenvalues&&s.hiddenvalues.size){n[t]=[...s.hiddenvalues];a=true}}}if(a){t.filterlocusattr=n}}{const n=[];for(const t of e.legend_mclass.hiddenvalues){if(Number.isInteger(t))n.push(t)}if(n.length){t.hiddendt=n}}}function dn(t,e){cn(t);let n=e.labelfontsize;if(t.versionlabel)n+=e.labelfontsize;const[a,s]=Sn(t,e);t.samplegroups=a;const o=fn(t,e);const l=un(s,t,e);const i=gn(t,e);An(t);wn(t);const r=Se(t,e);const c=o&&l?3:0;let p=Math.max(n,o+l+c,r);if(o){p+=Math.max(0,n+8-(p-l-c-o/2))}else if(l){p+=Math.max(0,n+8-(p-l/2))}if(r==0||p>r+3+e.labelfontsize){t.config_handle.transition().attr("text-anchor","start").attr("x",0)}else{t.config_handle.transition().attr("text-anchor","end").attr("x",-e.rpad)}t.cnvleftg.transition().attr("transform","translate(0,"+p+")");t.cnvmidg.transition().attr("transform","translate(0,"+p+")");t.vcfdensityg.transition().attr("transform","translate(0,"+(p-l-c)+")");t.svdensityg.transition().attr("transform","translate(0,"+p+")");t.cnvrightg.transition().attr("transform","translate(0,"+p+")");{const n="#858585";if(o&&t.data_vcf){let a=0;for(const e of t.data_vcf){if(e.x==undefined)continue;if(e.dt==x){a+=e.sampledata.length}else{console.error("unknown dt from data_vcf")}}const s=[];if(a)s.push(a+" SNV/indel"+(a>1?"s":""));t.vcfdensitylabelg.attr("transform","translate(0,"+(p-o-c-l)+")").append("text").text(s.join(", ")).attr("text-anchor","end").attr("x",e.tkleftlabel_xshift).attr("y",o/2).attr("dominant-baseline","central").attr("font-size",Math.min(e.labelfontsize,o)-1).attr("font-family",U).attr("fill",n).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)}));t.vcfdensitylabelg.append("line").attr("stroke",n).attr("y2",o).attr("shape-rendering","crispEdges");t.vcfdensitylabelg.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",-Ke).attr("y1",o/2).attr("y2",o/2);t.vcfdensitylabelg.append("line").attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("stroke-dasharray","1,3").attr("x2",e.width).attr("y1",o).attr("y2",o)}if(l){t.svdensitylabelg.attr("transform","translate(0,"+(p-l)+")").append("text").text(s.length+" SV breakpoint"+(s.length>1?"s":"")).attr("text-anchor","end").attr("x",e.tkleftlabel_xshift).attr("y",l/2).attr("dominant-baseline","central").attr("font-size",Math.min(e.labelfontsize,l)-1).attr("font-family",U).attr("fill",n).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)}));t.svdensitylabelg.append("line").attr("stroke",n).attr("y2",l).attr("shape-rendering","crispEdges");t.svdensitylabelg.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",-Ke).attr("y1",l/2).attr("y2",l/2);t.svdensitylabelg.append("line").attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("stroke-dasharray","1,3").attr("x2",e.width).attr("y1",l).attr("y2",l)}}t.height_main=t.toppad+p+i+t.bottompad;Qt(t,e)}function fn(t,e){if(t.vcfrangelimit){t.vcfdensityg.append("text").text("Zoom in under "+_(t.vcfrangelimit)+" to show SNV/indel density").attr("font-size",e.labelfontsize).attr("font-family",U);return e.labelfontsize}if(!t.isdense)return 0;if(!t.data_vcf||t.data_vcf.length==0)return 0;const n=mn(t,e);for(const t of n){if(t.lst.length==0)continue;const e=new Map;for(const n of t.lst){if(!e.has(n.class)){e.set(n.class,[])}e.get(n.class).push(n)}const n=[];for(const[t,a]of e){let e=0;for(const t of a){if(t.dt==x){e+=t.sampledata.length}else{console.error("unknown dt")}}n.push({name:y[t].label,items:a,color:y[t].color,samplecount:e})}n.sort(((t,e)=>e.samplecount-t.samplecount));t.groups=n}let a=0;for(const t of n){if(!t.groups)continue;for(const e of t.groups){a=Math.max(a,e.samplecount)}}let s=0;{const t=4;let e=0;const o=Math.pow(t,2)*Math.PI;if(a<=3){e=o*a*.9}else if(a<=10){e=o*5}else if(a<=100){e=o*7}else{e=o*10}const l=N().domain([1,a*.5+.1,a*.6+.1,a*.7+.1,a*.8+.1,a]).range([o,o+(e-o)*.8,o+(e-o)*.85,o+(e-o)*.9,o+(e-o)*.95,e]);for(const t of n){if(!t.groups)continue;for(const e of t.groups){e.radius=Math.sqrt(l(e.samplecount)/Math.PI)}const e=t.groups.reduce(((t,e)=>e.samplecount+t),0);t.offset=Math.sqrt(l(e)/Math.PI);const n=t.groups.reduce(((t,e)=>t+e.radius*2),0);s=Math.max(s,t.offset+n)}}for(const a of n){if(!a.groups)continue;const n=t.vcfdensityg.append("g").attr("transform","translate("+a.x+",0)");let s=a.offset;for(const o of a.groups){s+=o.radius;n.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill",o.color).attr("stroke","white");if(o.radius>=8){const t=o.radius*1.5;const e=o.samplecount.toString();const a=Math.min(t/(e.length*I),t);n.append("text").text(e).attr("y",-s).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-size",a).attr("font-family",U).attr("fill","white")}n.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",o.color).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(()=>{_t(o,t,e)})).on("mouseout",(()=>{t.tktip.hide()})).on("click",(()=>{yt(o,t,e)}));s+=o.radius}n.append("line").attr("y2",-a.offset).attr("stroke",a.groups[0].color)}return s}function mn(t,e){if(e.exonsf>=3){const e=new Map;for(const n of t.data_vcf){if(n.x==undefined)continue;if(!e.has(n.pos)){e.set(n.pos,{x:n.x,lst:[]})}e.get(n.pos).lst.push(n)}const n=[];for(const t of e.values()){n.push(t)}return n}const n=10;const a=[];let s=0;while(s<e.width){a.push({x1:s,x2:s+n,x:s+n/2,lst:[]});s+=n}s=e.width;for(const t of e.subpanels){s+=t.leftpad;let e=0;while(e<t.width){a.push({x1:s+e,x2:s+e+n,lst:[]});e+=n}s+=t.width}for(const e of t.data_vcf){if(e.x==undefined){continue}for(const t of a){if(t.x1<=e.x&&t.x2>=e.x){t.lst.push(e);break}}}return a}function un(t,e,n){if(!e.isdense||t.length==0)return 0;const a=hn(t,e,n);const s=[];for(const t of a){if(t.lst.length==0)continue;const e={};for(const n in t){e[n]=t[n]}e.lst=Gn(t.lst);s.push(e)}for(const t of s){const n=new Map;const a=[];for(const e of t.lst){if(e._samplegroup.name){if(!n.has(e._samplegroup.name)){n.set(e._samplegroup.name,[])}n.get(e._samplegroup.name).push(e)}else{a.push(e)}}const s=[];if(a.length){s.push({items:a,color:$e})}for(const[t,a]of n){s.push({name:t,items:a,color:e.legend_samplegroup?e.legend_samplegroup.color(t):"#aaa"})}s.sort(((t,e)=>e.items.length-t.items.length));t.groups=s}let o=0;for(const t of s){for(const e of t.groups){o=Math.max(o,e.items.length)}}let l=0;{const t=4;let e=0;const n=Math.pow(t,2)*Math.PI;if(o<=3){e=n*o*.9}else if(o<=10){e=n*5}else if(o<=100){e=n*7}else{e=n*10}const a=N().domain([1,o*.5+.1,o*.6+.1,o*.7+.1,o*.8+.1,o]).range([n,n+(e-n)*.8,n+(e-n)*.85,n+(e-n)*.9,n+(e-n)*.95,e]);for(const t of s){if(!t.groups)continue;for(const e of t.groups){e.radius=Math.sqrt(a(e.items.length)/Math.PI)}t.offset=Math.sqrt(a(t.lst.length)/Math.PI);const e=t.groups.reduce(((t,e)=>t+e.radius*2),0);l=Math.max(l,t.offset+e)}}for(const t of s){const a=e.svdensityg.append("g").attr("transform","translate("+t.x+",0)");let s=t.offset;for(const o of t.groups){s+=o.radius;a.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill",o.color).attr("stroke","white");if(o.radius>=8){const t=o.radius*1.5;const e=o.items.length.toString();const n=Math.min(t/(e.length*I),t);a.append("text").text(e).attr("y",-s).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-size",n).attr("font-family",U).attr("fill","white")}a.append("circle").attr("cy",-s).attr("r",o.radius).attr("fill","white").attr("fill-opacity",0).attr("stroke",o.color).attr("stroke-opacity",0).attr("class","sja_aa_disckick").on("mouseover",(()=>{vt(o,e,n)})).on("mouseout",(()=>{e.tktip.hide()})).on("click",(()=>{xt(o,e,n)}));s+=o.radius}a.append("line").attr("y2",-t.offset).attr("stroke",t.groups[0].color)}return l}function hn(t,e,n){if(n.exonsf>=3){const e=new Map;for(const n of t){if(n.x==undefined)continue;if(!e.has(n._pos)){e.set(n._pos,{x:n.x,lst:[]})}e.get(n._pos).lst.push(n)}const n=[];for(const t of e.values()){n.push(t)}return n}const a=10;const s=[];let o=0;while(o<n.width){s.push({x1:o,x2:o+a,x:o+a/2,lst:[]});o+=a}o=n.width;for(const t of n.subpanels){o+=t.leftpad;let e=0;while(e<t.width){s.push({x1:o+e,x2:o+e+a,lst:[]});e+=a}o+=t.width}for(const e of t){for(const t of s){if(t.x1<=e.x&&t.x2>=e.x){t.lst.push(e);break}}}return s}function gn(t,e){{const e=[],n=[],a=[];for(const s of t.samplegroups){for(const t of s.samples){for(const s of t.items){if(s.dt==g){a.push(s.segmean);continue}if(s.dt==h){if(s.value>0)e.push(s.value);else n.push(-s.value)}}}}const s=P(e,tn);const o=-P(n,tn);t.cnvcolor.cnvmax=Math.max(s,-o);if(a.length){t.cnvcolor.segmeanmax=Math.max(...a)}else{t.cnvcolor.segmeanmax=tn}}let n;if(t.isdense){t.rowspace=0;n=4}else if(t.isfull){t.rowspace=1;n=10}const a=e.width+e.subpanels.reduce(((t,e)=>t+e.width+e.leftpad),0);xn(t,e);for(const e of t.samplegroups){e.height=t.rowspace*(e.samples.length-1)+e.samples.reduce(((t,e)=>e.height+t),0)}const s=e.labelfontsize-(t.isfull?0:1);let o=n;for(const[l,i]of t.samplegroups.entries()){let l=0;if(i.height<s){l=(s-i.height)/2}if(i.name){const n=t.legend_samplegroup?t.legend_samplegroup.color(i.name):"#0A7FA6";const a=[i.name+" ("+i.samples.length];if(i.sampletotalnum)a.push(", "+Math.ceil(100*i.samples.length/i.sampletotalnum)+"%");if(t.sampleset){const e=t.sampleset.find((t=>t.name==i.name));if(e)a.push(", "+Math.ceil(100*i.samples.length/e.samples.length)+"%")}a.push(")");t.cnvleftg.append("text").attr("font-size",s).attr("font-family",U).attr("y",o+l+i.height/2).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill",n).attr("x",e.tkleftlabel_xshift).text(a.join("")).each((function(){t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,this.getBBox().width)})).on("mouseover",(()=>{bt(i,t)})).on("mouseout",(()=>{t.tktip.hide()})).on("click",(n=>{t.tip2.clear();ft(i,t,e);t.tip2.showunder(n.target)}));t.cnvleftg.append("line").attr("y1",o+l).attr("y2",o+l+i.height).attr("stroke",n).attr("shape-rendering","crispEdges");t.cnvleftg.append("line").attr("y1",o+l+i.height/2).attr("y2",o+l+i.height/2).attr("x2",-Ke).attr("stroke",n).attr("shape-rendering","crispEdges")}let r=o+l;i.y=r;for(const n of i.samples){if(!i.name&&n.samplename&&n.height>=Ze){n.svglabel=t.cnvleftg.append("text").text(n.samplename).attr("text-anchor","end").attr("dominant-baseline","central").attr("fill","black").attr("x",-5).attr("y",r+n.height/2).attr("font-family",U).attr("font-size",Math.min(15,Math.max(Ze,n.height+1))).each((function(){})).on("mouseover",(()=>{kn(n)})).on("mouseout",(()=>{vn(n)}));t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,n.svglabel.node().getBBox().width)}const s=t.cnvmidg.append("g").attr("transform","translate(0,"+r+")");if(t.isfull){n.blockbg=s.append("rect").attr("width",a).attr("height",n.height).attr("fill",Je).attr("fill-opacity",0).on("mouseover",(()=>{kn(n)})).on("mouseout",(()=>{vn(n)}))}if(t.isfull&&n.sampletype==Qe){s.append("rect").attr("x",-5).attr("y",0).attr("width",5).attr("height",n.height).attr("fill","black").attr("shape-rendering","crispEdges")}for(const a of n.items){if(a.dt!=h&&a.dt!=g&&a.dt!=b)continue;let o;if(a.dt==g){if(a.segmean>=t.cnvcolor.segmeanmax){o=t.cnvcolor.loh.str}else{o="rgba("+t.cnvcolor.loh.r+","+t.cnvcolor.loh.g+","+t.cnvcolor.loh.b+","+(a.segmean/t.cnvcolor.segmeanmax).toFixed(2)+")"}}else if(a.dt==h){if(a.value>0){if(a.value>=t.cnvcolor.cnvmax){o=t.cnvcolor.gain.str}else{o="rgba("+t.cnvcolor.gain.r+","+t.cnvcolor.gain.g+","+t.cnvcolor.gain.b+","+(a.value/t.cnvcolor.cnvmax).toFixed(2)+")"}}else{if(a.value<=-t.cnvcolor.cnvmax){o=t.cnvcolor.loss.str}else{o="rgba("+t.cnvcolor.loss.r+","+t.cnvcolor.loss.g+","+t.cnvcolor.loss.b+","+(-a.value/t.cnvcolor.cnvmax).toFixed(2)+")"}}}else if(a.dt==b){o=y[R].color}s.append("rect").attr("x",Math.min(a.x1,a.x2)).attr("y",a.stack_y).attr("width",Math.max(1,Math.abs(a.x1-a.x2))).attr("height",a.stack_h).attr("shape-rendering","crispEdges").attr("stroke","none").attr("class","sja_aa_skkick").attr("fill",o).on("mouseover",(()=>{At({item:a,sample:n,samplegroup:i,tk:t})})).on("mouseout",(()=>{t.tktip.hide();vn(n)})).on("click",(()=>{wt({item:a,sample:n,samplegroup:i,tk:t,block:e})}))}for(const a of n.items){if(a.dt!=k&&a.dt!=v)continue;const o=a.chrA==a._chr?a.chrB:a.chrA;const l=o==a._chr?Ye:t.legend_svchrcolor.colorfunc(o);const r=s.append("g").attr("transform","translate("+a.x+","+n.height/2+")");const c=n.crossboxw;let p=-c/2,d=c;const f=r.append("circle").attr("r",Math.min(5,Math.max(We,1+n.height/2))).attr("fill",l).attr("fill-opacity",0).attr("stroke",l);if(a.labonleft){r.append("text").text(yn(a)).attr("text-anchor","end").attr("dominant-baseline","central").attr("font-family",U).attr("font-size",c+2).attr("fill",l).attr("x",-c/2-en);p=-c/2-en-a.labelwidth;d=c+en+a.labelwidth}else if(a.labonright){r.append("text").text(yn(a)).attr("dominant-baseline","central").attr("font-family",U).attr("font-size",c+2).attr("fill",l).attr("x",c/2+en);d=c+en+a.labelwidth}r.append("rect").attr("x",p).attr("y",-c/2).attr("width",d).attr("height",c).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{f.attr("fill-opacity",1);At({item:a,sample:n,samplegroup:i,tk:t})})).on("mouseout",(()=>{f.attr("fill-opacity",0);t.tktip.hide();vn(n)})).on("click",(()=>{wt({item:a,sample:n,samplegroup:i,tk:t,block:e})}))}if(t.isfull&&t.data_vcf){for(const a of t.data_vcf){if(a.dt!=x)continue;if(a.x==undefined)continue;if(!a.sampledata)continue;const o=n.crossboxw;const l=bn(t,a,n);for(const r of a.sampledata){if(r.sampleobj.name!=n.samplename)continue;const c=s.append("g").attr("transform","translate("+a.x+","+n.height/2+")");const p=c.append("rect").attr("x",-o/2-1).attr("y",-o/2-1).attr("width",o+2).attr("height",o+2).attr("fill",l).attr("fill-opacity",0);let d,f,m,u;if(Xn(r,t)){d=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("y1",-o/2-1).attr("y2",o/2+1);f=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2-1).attr("x2",o/2+1);m=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("y1",-o/2-1).attr("y2",o/2+1);u=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2-1).attr("x2",o/2+1)}else{d=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2).attr("x2",o/2).attr("y1",-o/2).attr("y2",o/2);f=c.append("line").attr("stroke","white").attr("stroke-width",3).attr("x1",-o/2).attr("x2",o/2).attr("y1",o/2).attr("y2",-o/2);m=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2).attr("x2",o/2).attr("y1",-o/2).attr("y2",o/2);u=c.append("line").attr("stroke",l).attr("stroke-width",1.5).attr("x1",-o/2).attr("x2",o/2).attr("y1",o/2).attr("y2",-o/2)}let h=-o/2,g=o;if(r.sampleobj.labonleft){c.append("text").text(a.mname).attr("text-anchor","end").attr("dominant-baseline","central").attr("font-family",U).attr("font-size",n.crossboxw+2).attr("fill",l).attr("x",-o/2-en);h=-o/2-en-r.sampleobj.labelwidth;g=o+en+r.sampleobj.labelwidth}else if(r.sampleobj.labonright){c.append("text").text(a.mname).attr("dominant-baseline","central").attr("font-family",U).attr("font-size",n.crossboxw+2).attr("fill",l).attr("x",o/2+en);g=o+en+r.sampleobj.labelwidth}c.append("rect").attr("x",h).attr("y",-o/2).attr("width",g).attr("height",o).attr("fill","white").attr("fill-opacity",0).on("mouseover",(()=>{p.attr("fill-opacity",1);d.attr("stroke-opacity",0);f.attr("stroke-opacity",0);m.attr("stroke","white");u.attr("stroke","white");At({item:a,m_sample:r,sample:n,samplegroup:i,tk:t,block:e})})).on("mouseout",(()=>{t.tktip.hide();p.attr("fill-opacity",0);d.attr("stroke-opacity",1);f.attr("stroke-opacity",1);m.attr("stroke",l);u.attr("stroke",l);vn(n)})).on("click",(()=>{wt({item:a,m_sample:r,sample:n,samplegroup:i,tk:t,block:e})}))}}}r+=n.height+t.rowspace}o+=i.height+l*2+n}if(!t.nocnvlohsv){if(t.cnvcolor.cnvmax==tn){t.cnvcolor.cnvlegend.svg.style("display","none");t.cnvcolor.cnvlegend.nodatadiv.style("display","block")}else{t.cnvcolor.cnvlegend.svg.style("display","block");t.cnvcolor.cnvlegend.nodatadiv.style("display","none");jn(t)}if(t.cnvcolor.segmeanmax==tn){if(t.cnvcolor.lohlegend){t.cnvcolor.lohlegend.svg.style("display","none");t.cnvcolor.lohlegend.nodatadiv.style("display","block")}}else{t.cnvcolor.lohlegend.svg.style("display","block");t.cnvcolor.lohlegend.nodatadiv.style("display","none");Mn(t)}}return o}function bn(t,e,n){if(t.checkrnabam){const a=t.checkrnabam.samples[n.samplename];if(a&&a.genes){for(const n of a.genes){if(n.snps){const a=n.snps.find((t=>t.pos==e.pos&&t.ref==e.ref&&t.alt==e.alt));if(a&&a.rnacount&&a.rnacount.pvalue!=undefined){return t.checkrnabam.clientcolor_snpinuse}}}}return t.checkrnabam.clientcolor_markernotinuse}return y[e.class].color}function kn(t){if(!t)return;if(t.svglabel)t.svglabel.attr("fill",Je);if(t.blockbg)t.blockbg.attr("fill-opacity",.1);if(t.columnbars){for(const e of t.columnbars){e.attr("fill",Je)}}}function vn(t){if(!t)return;if(t.svglabel)t.svglabel.attr("fill",Xe);if(t.blockbg)t.blockbg.attr("fill-opacity",0);if(t.columnbars){for(const e of t.columnbars){e.attr("fill",Xe)}}}function xn(t,e){if(!t.samplegroups||t.samplegroups.length==0)return;if(t.isdense){for(const e of t.samplegroups){for(const t of e.samples){t.height=1;for(const e of t.items){if(e.dt==h||e.dt==g||e.dt==b){e.stack_y=0;e.stack_h=1}}}}return}for(const e of t.samplegroups){for(const t of e.samples){for(const e of t.items){if(e.dt==k||e.dt==v){delete e.labonleft;delete e.labonright}}}}if(t.data_vcf){for(const e of t.data_vcf){if(e.sampledata){for(const t of e.sampledata){if(t.sampleobj){delete t.sampleobj.labonleft;delete t.sampleobj.labonright}}}}}const n=e.width+e.subpanels.reduce(((t,e)=>t+e.leftpad+e.width),0);for(const e of t.samplegroups){for(const a of e.samples){const e=[];for(const t of a.items){if(t.dt==h||t.dt==g||t.dt==b){if(t.x1!=undefined&&t.x2!=undefined){t._boxstart=Math.min(t.x1,t.x2);t._boxwidth=Math.abs(t.x2-t.x1);e.push(t)}}}_n(a,e);a.crossboxw=Math.min(8,a.height);const s=[];for(const e of a.items){if(e.dt==v){if(e.x==undefined)continue;const n={dt:e.dt,x:e.x,obj:e};if(t.multihidelabel_fusion);else{n.name=yn(e)}s.push(n)}else if(e.dt==k){if(e.x==undefined)continue;const n={dt:e.dt,x:e.x,obj:e};if(t.multihidelabel_sv);else{n.name=yn(e)}s.push(n)}}if(t.data_vcf){for(const e of t.data_vcf){if(e.dt!=x||e.x==undefined||!e.sampledata)continue;const n=e.sampledata.find((t=>t.sampleobj.name==a.samplename));if(n){const a={dt:e.dt,x:e.x,obj:n.sampleobj};if(t.multihidelabel_vcf);else{a.name=e.mname}s.push(a)}}}if(s.length>0){s.sort(((t,e)=>t.x-e.x));for(let e=0;e<s.length;e++){const o=s[e];if(!o.name){continue}let l;t.g.append("text").text(o.name).attr("font-size",a.crossboxw+2).attr("font-family",U).each((function(){l=this.getBBox().width})).remove();l+=a.crossboxw/2+en;let i=false,r=false;if(l>o.x){i=true}else if(l>n-o.x){r=true}for(const t of a.items){if(i&&r)break;if(t.dt==h||t.dt==g||t.dt==b){if(t.x1==undefined||t.x2==undefined)continue;const e=Math.min(t.x1,t.x2);const n=Math.max(t.x1,t.x2);if(e<o.x){if(n<o.x){if(l>o.x-n){i=true}}else{i=true;r=true}}else{if(l>e-o.x){r=true}}}}if(i&&r){continue}if(!i){for(let t=e-1;t>=0;t--){const e=s[t];if(e.x==o.x){if(e.obj.labonleft){i=true}else if(e.obj.labonright){r=true}else;}else{if(l>o.x-e.x-(e.obj.labonright?e.obj.labelwidth:0)){i=true;break}else{break}}}}if(i&&r)continue;if(!r){for(let t=e+1;t<s.length;t++){const e=s[t];if(e.x==o.x);else{if(l>e.x-o.x){r=true;break}else{break}}}}if(i&&r)continue;if(i){if(!r){o.obj.labonright=true}}else{if(r){o.obj.labonleft=true}else{o.obj.labonright=true}}if(o.obj.labonleft||o.obj.labonright){o.obj.labelwidth=l}}}}}}function yn(t){if(t.cytogeneticname)return t.cytogeneticname;return(t.geneA||t.chrA)+" > "+(t.geneB||t.chrB)}function _n(t,e){if(e.length==0){t.height=8;return}e.sort(((t,e)=>t._boxstart-e._boxstart));const n=[];for(const t of e){for(let e=0;e<n.length;e++){if(n[e]<t._boxstart){t._stacki=e;n[e]=t._boxstart+t._boxwidth;break}}if(t._stacki==undefined){t._stacki=n.length;n.push(t._boxstart+t._boxwidth)}}let a=nn(n.length);if(a<1){a=1}for(const t of e){t.stack_y=t._stacki*a;t.stack_h=a;delete t._stacki;delete t._boxstart;delete t._boxwidth}t.height=a*n.length}function wn(t){if(!t.checkrnabam)return;for(const e in t.checkrnabam.samples){const n=t.checkrnabam.samples[e];if(n.genes){for(const e of n.genes){W(e,t.gecfg)}}}}function An(t){if(!t._data)return;if(!t.gecfg)return;if(t.gecfg.no_ase)return;for(const e of t._data){if(!e.samples)continue;for(const n of e.samples){if(!n.expressionrank)continue;for(const e in n.expressionrank){const a=n.expressionrank[e];W(a,t.gecfg)}}}}function jn(t){t.cnvcolor.cnvlegend.row.style("display","table-row");q({axis:t.cnvcolor.cnvlegend.axisg.call(tt().scale(N().domain([-t.cnvcolor.cnvmax,0,t.cnvcolor.cnvmax]).range([0,t.cnvcolor.cnvlegend.barw,t.cnvcolor.cnvlegend.barw*2])).tickValues([-t.cnvcolor.cnvmax,0,t.cnvcolor.cnvmax]).tickSize(t.cnvcolor.cnvlegend.axistickh))})}function Mn(t){if(!t.cnvcolor.lohlegend)return;t.cnvcolor.lohlegend.row.style("display","table-row");q({axis:t.cnvcolor.lohlegend.axisg.call(tt().scale(N().domain([0,t.cnvcolor.segmeanmax]).range([0,t.cnvcolor.lohlegend.barw])).tickValues([0,t.cnvcolor.segmeanmax]).tickSize(t.cnvcolor.lohlegend.axistickh))})}async function zn(t){const{m:e,sample:n,samplegroup:o,tk:l,block:i}=t;let r;if(t.holder){r=t.holder}else{const t=a({x:100,y:100});r=t.body}const c=r.append("div");const p={style:{margin:"0px"},tklst:[],holder:r,subpanels:[]};F(i.genome,p.tklst);if(l.checkrnabam&&l.checkvcf){const t=l.checkrnabam.samples[n.samplename];if(t){p.chr=i.rglst[0].chr;p.start=i.rglst[0].start;p.stop=i.rglst[0].stop;const e={type:s.ase,name:n.samplename+" ASE",samplename:n.samplename,rnabamfile:t.file,rnabamurl:t.url,rnabamindexURL:t.indexURL,rnabamtotalreads:t.totalreads,vcffile:l.checkvcf.file,vcfurl:l.checkvcf.url,vcfindexURL:l.checkvcf.indexURL};Ln(l,e,false);p.tklst.push(e);const a=i.newblock(p);if(i.debugmode){window.bbb=a}return}}if(l.iscustom){if(l.checkexpressionrank){const t={type:T.mdsexpressionrank,name:n.samplename+" expression rank",sample:n.samplename,iscustom:1};for(const e in l.checkexpressionrank){t[e]=l.checkexpressionrank[e]}p.tklst.push(t)}if(l.sample2assaytrack&&l.sample2assaytrack[n.samplename]){for(const t of l.sample2assaytrack[n.samplename]){p.tklst.push(t)}}}else if(l.mds&&l.mds.queries[l.querykey].checkexpressionrank){if(o){const t={type:T.mdsexpressionrank,name:n.samplename+" expression rank",dslabel:l.mds.label,querykey:l.mds.queries[l.querykey].checkexpressionrank.querykey,sample:n.samplename,attributes:o.attributes};p.tklst.push(t)}}const d={bplengthUpperLimit:0,valueCutoff:l.valueCutoff,lohLengthUpperLimit:l.lohLengthUpperLimit,segmeanValueCutoff:l.segmeanValueCutoff,singlesample:{name:n.samplename}};if(l.iscustom){d.type=T.mdssvcnv;d.file=l.file;d.url=l.url;d.indexURL=l.indexURL;d.iscustom=true;d.legend_vorigin=l.legend_vorigin}else{d.mds=l.mds;d.querykey=l.querykey;for(const t in l.mds.queries[l.querykey]){if(t=="bplengthUpperLimit"||t=="valueCutoff"){continue}d[t]=l.mds.queries[l.querykey][t]}}if(l.iscustom&&l.checkvcf){d.checkvcf=l.checkvcf}p.tklst.push(d);if(e){if(e.dt==h||e.dt==g){const t=Math.ceil((e.stop-e.start)/2);p.chr=e.chr;p.start=Math.max(0,e.start-t);p.stop=Math.min(i.genome.chrlookup[e.chr.toUpperCase()].len,e.stop+t)}else if(e.dt==k||e.dt==v){if(e.chrA==e.chrB){const t=Math.ceil(Math.abs(e.posA-e.posB)/4);p.chr=e.chrA;p.start=Math.max(0,Math.min(e.posA,e.posB)-t);p.stop=Math.min(i.genome.chrlookup[e.chrA.toUpperCase()].len,Math.max(e.posA,e.posB)+t)}else{const t=1e4;p.chr=e.chrA;p.start=Math.max(0,e.posA-t);p.stop=Math.min(i.genome.chrlookup[e.chrA.toUpperCase()].len,e.posA+t);p.subpanels.push({chr:e.chrB,start:Math.max(0,e.posB-t),stop:Math.min(i.genome.chrlookup[e.chrB.toUpperCase()].len,e.posB+t),width:600,leftpad:10,leftborder:"rgba(50,50,50,.1)"})}}}if(!p.chr){const t=i.tkarg_maygm(l)[0];if(e&&e.dt==x){const n=1e4;if(n<t.stop-t.start){p.chr=e.chr;p.start=Math.max(0,e.pos-n);p.stop=Math.min(i.genome.chrlookup[e.chr.toUpperCase()].len,e.pos+n)}}if(!p.chr){p.chr=t.chr;p.start=t.start;p.stop=t.stop}}let f;if(!l.iscustom){const t=await H("mdssvcnv",{method:"POST",body:JSON.stringify({genome:i.genome.name,dslabel:l.mds.label,querykey:l.querykey,gettrack4singlesample:n.samplename})});if(t.error)throw t.error;if(t.tracks){f=t.tracks;for(const e of t.tracks){p.tklst.push(JSON.parse(JSON.stringify(e)))}}}const m=i.newblock(p);if(e){if(e.dt==h||e.dt==g){m.addhlregion(e.chr,e.start,e.stop,Ge)}}if(f){c.style("display","inline-block").style("margin","0px 10px 20px 10px").append("div").style("margin-bottom","3px").text("Show/hide available assay tracks for "+n.samplename).style("font-size",".7em").style("opacity",.5);const t=c.append("div").style("border","solid 1px #ccc").style("border-radius","7px");for(const e of f){const n=t.append("div").style("display","inline-block").style("white-space","nowrap").style("margin","10px").style("font-size",".8em").append("label");n.append("input").attr("type","checkbox").style("margin-right","3px").property("checked",!e.hidden).on("change",(t=>{if(t.target.checked){m.turnOnTrack(e)}else{m.turnOffTrack(e)}}));n.append("span").text(e.name)}}}function Ln(t,e,n){if(!t.checkrnabam)return;e.checkrnabam={};for(const n in t.checkrnabam){if(n=="samples")continue;if(n=="legend")continue;e.checkrnabam[n]=t.checkrnabam[n]}if(n){e.checkrnabam.samples={};for(const n in t.checkrnabam.samples){const a=t.checkrnabam.samples[n];e.checkrnabam.samples[n]={file:a.file,url:a.url,indexURL:a.indexURL,nochr:a.nochr,totalreads:a.totalreads,pairedend:a.pairedend}}}}function Sn(t,e){if(!t._data){return[[],[]]}const n=[];let a=[];for(const s of t._data){const o={};for(const t in s)o[t]=s[t];o.samples=[];for(const a of s.samples){const l={};for(const t in a)l[t]=a[t];l.items=[];for(const o of a.items){if(o.dt==k||o.dt==v){Tn(o,e);if(o.x==undefined){console.log("unmappable sv: "+o._chr+" "+o._pos);continue}if(o.chrA!=o._chr){t.legend_svchrcolor.interchrs.add(o.chrA);t.legend_svchrcolor.colorfunc(o.chrA)}if(o.chrB!=o._chr){t.legend_svchrcolor.interchrs.add(o.chrB);t.legend_svchrcolor.colorfunc(o.chrB)}if(t.isdense){const t={_samplegroup:s,_sample:a};for(const e in o){t[e]=o[e]}n.push(t);continue}l.items.push(o);continue}Pn(o,t,e);if(o.x1==undefined||o.x2==undefined){console.log("unmappable stack item: ",o);continue}l.items.push(o)}if(l.items.length==0){if(t.isfull&&t.data_vcf){let e=false;for(const n of t.data_vcf){if(e)break;if(n.x==undefined)continue;if(n.dt==x){if(!n.sampledata)continue;for(const t of n.sampledata){if(t.sampleobj.name==a.samplename){e=true;break}}continue}}if(!e){if(Nn(t));else{continue}}}else{if(Nn(t));else{continue}}}o.samples.push(l)}if(o.samples.length==0)continue;a.push(o)}if(t.groupsamplebyattr){const e=t.groupsamplebyattr.sortgroupby;if(e&&e.key&&e.order){const t=[];for(const n of e.order){for(const s of a){if(!s.attributes)continue;for(const a of s.attributes){if(a.k==e.key&&a.kvalue==n){s._sorted=1;t.push(s);break}}}}for(const e of a){if(!e._sorted)t.push(e)}for(const e of t)delete e._sorted;a=t}}if(t.sampleset){const e=t.sampleset.map((t=>t.name));a.sort(((t,n)=>{if(e.indexOf(t.name)>e.indexOf(n.name))return 1;else return-1}));for(const e of t.sampleset){const t=a.find((t=>t.name==e.name));if(!t||!t.samples)continue;const n=[];for(const a of e.samples){const e=t.samples.find((t=>t.samplename==a));if(e){n.push(e)}}t.samples=n}}return[a,n]}function Nn(t){if(!t.getallsamples)return false;if(t.iscustom)return true;if(t.mds&&t.mds.allow_getallsamples)return true;return false}function Un(t,e){for(const n in t){e[n]=t[n]}if(t.attributes){e.attributes={};for(const n in t.attributes){e.attributes[n]={};for(const a in t.attributes[n]){e.attributes[n][a]=t.attributes[n][a]}}}}function qn(t,e){if(t.mds){if(t.mds.mutationAttribute){t.mutationAttribute={};Un(t.mds.mutationAttribute,t.mutationAttribute)}if(t.mds.sampleAttribute){t.sampleAttribute={};Un(t.mds.sampleAttribute,t.sampleAttribute)}if(t.mds.locusAttribute){t.locusAttribute={};Un(t.mds.locusAttribute,t.locusAttribute)}if(t.mds.alleleAttribute){t.alleleAttribute={};Un(t.mds.alleleAttribute,t.alleleAttribute)}t.nocnvlohsv=true;t.isdense=true;t.isfull=false;if(t.mds.queries){for(const e in t.mds.queries){const n=t.mds.queries[e];if(n.type==s.mdssvcnv){delete t.nocnvlohsv;if(n.isfull){t.isfull=true;t.isdense=false}}}}}else if(t.iscustom){if(!t.file&&!t.url){t.nocnvlohsv=true}}Bn(t);if(t.singlesample){t.waterfall={inuse:false,axisheight:100,bottompad:10,axisgg:t.gleft.append("g")};if(t.singlesample.waterfall){t.waterfall.inuse=t.singlesample.waterfall.inuse}t.waterfall.axisg=t.waterfall.axisgg.append("g");t.waterfall.lab1=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10);t.waterfall.lab2=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10);t.waterfall.lab3=t.waterfall.axisgg.append("text").attr("font-size",13).attr("text-anchor","end").attr("x",-10)}else{t.samplematrices=[];if(t.multihidelabel_vcf==undefined){t.multihidelabel_vcf=true}if(t.multihidelabel_fusion==undefined){t.multihidelabel_fusion=true}if(t.multihidelabel_sv==undefined){t.multihidelabel_sv=true}}if(!t.singlesample&&!t.isdense&&!t.isfull){if(t.iscustom){t.isdense=false;t.isfull=true}else{t.isdense=true;t.isfull=false;if(t.showfullmode){t.isdense=false;t.isfull=true}}}t.tip2=new D({padding:"0px"});if(t.singlesample){if(!t.midpad)t.midpad=3;if(!t.stem1){t.stem1=10;t.stem2=0;t.stem3=5}if(!t.legheight)t.legheight=40;if(!t.discradius)t.discradius=8;if(!t.valueCutoff)t.valueCutoff=.2;if(!Number.isInteger(t.bplengthUpperLimit))t.bplengthUpperLimit=2e6;if(!Number.isInteger(t.lohLengthUpperLimit))t.lohLengthUpperLimit=2e6;if(!t.segmeanValueCutoff)t.segmeanValueCutoff=.1;if(t.fixname){t.name=t.fixname;t.tklabel.text(t.name);delete t.fixname}else{t.tklabel.text((t.name?t.name+", ":"")+t.singlesample.name)}t.leftLabelMaxwidth=t.tklabel.node().getBBox().width;e.setllabel();t.svvcf_g=t.glider.append("g");t.cnv_g=t.glider.append("g")}else{if(t.mds&&t.mds.version&&t.mds.version.label){t.versionlabel=e.maketklefthandle(t,e.labelfontsize).text(t.mds.version.label);if(t.mds.version.link){t.versionlabel.on("click",(()=>{window.open(t.mds.version.link)}))}}t.cnvleftg=t.gleft.append("g");t.vcfdensityg=t.glider.append("g");t.vcfdensitylabelg=t.gleft.append("g");t.svdensityg=t.glider.append("g");t.svdensitylabelg=t.gleft.append("g");t.cnvmidg=t.glider.append("g");t.cnvrightg=t.gright.append("g")}t.cnvcolor={};{const e=V(t.gaincolor);t.cnvcolor.gain={str:t.gaincolor,r:e.r,g:e.g,b:e.b};delete t.gaincolor}{const e=V(t.losscolor);t.cnvcolor.loss={str:t.losscolor,r:e.r,g:e.g,b:e.b};delete t.losscolor}{const e=V(t.lohcolor);t.cnvcolor.loh={str:t.lohcolor,r:e.r,g:e.g,b:e.b};delete t.lohcolor}if(t.iscustom){if(t.valueCutoff==undefined)t.valueCutoff=.2;if(t.bplengthUpperLimit==undefined)t.bplengthUpperLimit=2e6;if(t.segmeanValueCutoff==undefined)t.segmeanValueCutoff=.1;if(t.lohLengthUpperLimit==undefined)t.lohLengthUpperLimit=2e6}t.config_handle=e.maketkconfighandle(t).on("click",(()=>{En(t,e)}));if(t.checkrnabam){st(t.checkrnabam)}Kt(e,t);let n=false;if(t.iscustom){if(t.checkexpressionrank){n=true;if(!t.gecfg)t.gecfg={};t.gecfg.datatype=t.checkexpressionrank.datatype}else if(t.checkrnabam){n=true;if(!t.gecfg)t.gecfg={};t.gecfg.datatype="FPKM"}}else{if(t.mds.queries[t.querykey].checkexpressionrank){n=true;const e=t.mds.queries[t.mds.queries[t.querykey].checkexpressionrank.querykey];if(t.gecfg&&t.gecfg.fixed_pend){e.fixed_pend=t.gecfg.fixed_pend}t.gecfg=e}}if(n){if(!t.gecfg)t.gecfg={};if(!t.gecfg.fixed){t.gecfg.fixed=[]}if(!t.gecfg.no_ase){$(t.gecfg)}}}function Bn(t,e){const n=t.iscustom?t:t.customization;if(!n)return;if(n.singlesample){t.singlesample=n.singlesample}else if(n.sampleset){t.sampleset=n.sampleset}t.hide_cnvgain=n.hide_cnvgain;t.hide_cnvloss=n.hide_cnvloss;if(n.isfull){t.isdense=false;t.isfull=true}else if(n.isdense){t.isdense=true;t.isfull=false}if(n.sampleAttribute){if(!t.sampleAttribute)t.sampleAttribute={};if(!t.sampleAttribute.attributes)t.sampleAttribute.attributes={};for(const e in n.sampleAttribute){const a=n.sampleAttribute[e];if(!t.sampleAttribute.attributes[e]){t.sampleAttribute.attributes[e]={label:e}}const s=t.sampleAttribute.attributes[e];if(!s.hiddenvalues)s.hiddenvalues=new Set;if(a.hiddenvalues){for(const t of a.hiddenvalues)s.hiddenvalues.add(t)}}}t.legend_mclass={hiddenvalues:new Set};if(n.vcf){if(n.vcf.hiddenclass){for(const e of n.vcf.hiddenclass)t.legend_mclass.hiddenvalues.add(e)}}if(n.cnv){if(n.cnv.hidden)t.legend_mclass.hiddenvalues.add(h);if(Number.isInteger(n.cnv.upperlengthlimit))t.bplengthUpperLimit=n.cnv.upperlengthlimit}if(n.loh){if(n.loh.hidden)t.legend_mclass.hiddenvalues.add(g);if(Number.isInteger(n.loh.upperlengthlimit))t.lohLengthUpperLimit=n.loh.upperlengthlimit}if(n.fusion){if(n.fusion.hidden)t.legend_mclass.hiddenvalues.add(v)}if(n.sv){if(n.sv.hidden)t.legend_mclass.hiddenvalues.add(k)}if(n.itd){if(n.itd.hidden)t.legend_mclass.hiddenvalues.add(b)}if(n.fixedgeneexpression){if(!t.gecfg)t.gecfg={};t.gecfg.fixed_pend=n.fixedgeneexpression}}function Cn(t,e){t.tkconfigtip.hide();if(t.mode_radio_1.property("checked")){t.isdense=true;t.isfull=false}else if(t.mode_radio_2.property("checked")){t.isdense=false;t.isfull=true}if(!t._data){return}dn(t,e);e.block_setheight();e.setllabel()}function En(t,e){t.tkconfigtip.clear();pt(t);Fn(t,e);dt(t,e);Rn(t,e);Hn(t,e);In(t,e);On(t,e);ot(t,e,an);t.tkconfigtip.showunder(t.config_handle.node())}function Rn(t,e){if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","25px");if(t.sampleset){n.append("span").style("opacity",.5).style("padding-right","10px").text("Restricted to "+t.sampleset.reduce(((t,e)=>t+e.samples.length),0)+" samples");n.append("button").text("Edit").on("click",(()=>{Vn(t,e)}));n.append("button").text("Remove").on("click",(()=>{t.tkconfigtip.hide();delete t.sampleset;an(t,e)}));return}n.append("button").text("Use a sample list").on("click",(()=>{Vn(t,e)}));if(t.iscustom||t.mds&&t.mds.allow_getallsamples){n.append("button").style("margin-left","10px").text(t.getallsamples?"Only show samples with variants":"Show all samples").on("click",(()=>{t.getallsamples=!t.getallsamples;t.tkconfigtip.hide();an(t,e)}))}}function Vn(t,e){t.tkconfigtip.clear();const n=t.tkconfigtip.d.append("div");const a=n.append("textarea").attr("placeholder","One sample per row. Each row has sample and optional group name, joined by space or tab.");if(t.sampleset){const e=[];for(const n of t.sampleset){for(const t of n.samples){e.push(t+" "+n.name)}}a.property("value",e.join("\n")).style("width","250px").style("height","200px")}else{a.style("width","200px").style("height","100px")}n.append("button").text("Submit").style("display","block").on("click",(()=>{const n=a.property("value").trim().split("\n");if(n.length==0)return;const s=new Map;const o=[];for(const t of n){const[e,n]=t.split(/[\s\t]/);if(!e)continue;if(!n){o.push(e)}else{if(!s.has(n))s.set(n,[]);s.get(n).push(e)}}t.sampleset=[];for(const[e,n]of s){t.sampleset.push({name:e,samples:n})}if(o.length){const e={samples:o};if(s.size){e.name="Unnamed group"}t.sampleset.push(e)}t.tkconfigtip.hide();an(t,e)}))}function In(t,e){if(!t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("margin-bottom","15px");if(!t.data_vcf||t.data_vcf.length<2){n.style("opacity",.5).text("No waterfall plot: not enough SNV/indels");return}const a=Math.random();n.append("input").attr("type","checkbox").attr("id",a).property("checked",t.waterfall.inuse).on("change",(n=>{t.waterfall.inuse=n.target.checked;be(t,e);e.block_setheight()}));n.append("label").attr("for",a).html("&nbsp;use Waterfall plot for SNV/indels")}function On(t,e){if(t.nocnvlohsv)return;const n=t.tkconfigtip.d;{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("CNV log2(ratio) cutoff&nbsp;");a.append("input").property("value",t.valueCutoff||0).attr("type","number").style("width","50px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseFloat(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.valueCutoff){t.valueCutoff=0;an(t,e)}return}if(t.valueCutoff){if(t.valueCutoff==a);else{t.valueCutoff=a;an(t,e)}}else{t.valueCutoff=a;an(t,e)}}));a.append("div").style("font-size",".7em").style("color","#858585").html("Only show CNV with absolute log2(ratio) no less than cutoff.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("CNV segment size limit&nbsp;");a.append("input").property("value",t.bplengthUpperLimit||0).attr("type","number").style("width","80px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseInt(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.bplengthUpperLimit){t.bplengthUpperLimit=0;an(t,e)}return}if(t.bplengthUpperLimit){if(t.bplengthUpperLimit==a);else{t.bplengthUpperLimit=a;an(t,e)}}else{t.bplengthUpperLimit=a;an(t,e)}}));a.append("span").text("bp");a.append("div").style("font-size",".7em").style("color","#858585").html("Limit the CNV segment length to show only focal events.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div");a.append("span").html("Copy number gain&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.gain.str).on("change",(n=>{t.cnvcolor.gain.str=n.target.value;const a=V(t.cnvcolor.gain.str);t.cnvcolor.gain.r=a.r;t.cnvcolor.gain.g=a.g;t.cnvcolor.gain.b=a.b;t.cnvcolor.cnvlegend.gain_stop.attr("stop-color",t.cnvcolor.gain.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}));a.append("span").html("&nbsp;&nbsp;loss&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.loss.str).on("change",(n=>{t.cnvcolor.loss.str=n.target.value;const a=V(t.cnvcolor.loss.str);t.cnvcolor.loss.r=a.r;t.cnvcolor.loss.g=a.g;t.cnvcolor.loss.b=a.b;t.cnvcolor.cnvlegend.loss_stop.attr("stop-color",t.cnvcolor.loss.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}))}if(t.cnvcolor.lohlegend){n.append("hr").style("margin","20px");{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("LOH seg.mean cutoff&nbsp;");a.append("input").property("value",t.segmeanValueCutoff||0).attr("type","number").style("width","50px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseFloat(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.segmeanValueCutoff){t.segmeanValueCutoff=0;an(t,e)}return}if(t.segmeanValueCutoff){if(t.segmeanValueCutoff==a);else{t.segmeanValueCutoff=a;an(t,e)}}else{t.segmeanValueCutoff=a;an(t,e)}}));a.append("div").style("font-size",".7em").style("color","#858585").html("Only show LOH with seg.mean no less than cutoff.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","15px");a.append("span").html("LOH segment size limit&nbsp;");a.append("input").property("value",t.lohLengthUpperLimit||0).attr("type","number").style("width","80px").on("keyup",(n=>{if(n.code!="Enter"&&n.code!="NumpadEnter")return;let a=Number.parseInt(n.target.value);if(!a||a<0){a=0}if(a==0){if(t.lohLengthUpperLimit){t.lohLengthUpperLimit=0;an(t,e)}return}if(t.lohLengthUpperLimit){if(t.lohLengthUpperLimit==a);else{t.lohLengthUpperLimit=a;an(t,e)}}else{t.lohLengthUpperLimit=a;an(t,e)}}));a.append("span").text("bp");a.append("div").style("font-size",".7em").style("color","#858585").html("Limit the LOH segment length to show only focal events.<br>Set to 0 to show all. Press ENTER to update.")}{const a=n.append("div").style("margin-bottom","1px");a.append("span").html("LOH color&nbsp;");a.append("input").attr("type","color").property("value",t.cnvcolor.loh.str).on("change",(n=>{t.cnvcolor.loh.str=n.target.value;const a=V(t.cnvcolor.loh.str);t.cnvcolor.loh.r=a.r;t.cnvcolor.loh.g=a.g;t.cnvcolor.loh.b=a.b;t.cnvcolor.lohlegend.loh_stop.attr("stop-color",t.cnvcolor.loh.str);if(t.singlesample){be(t,e)}else{dn(t,e)}}))}}}function Fn(t,e){if(t.singlesample)return;const n=t.tkconfigtip.d.append("div").style("background","#FAF9DE").style("margin-bottom","20px").style("padding","15px");const a=Math.random().toString();const s=Math.random().toString();const o=Math.random().toString();const l=n.append("div").style("margin-bottom","5px");t.mode_radio_1=l.append("input").attr("type","radio").attr("id",a).attr("name",o).property("checked",t.isdense).on("change",(()=>{Cn(t,e)}));l.append("label").attr("for",a).attr("class","sja_clbtext").html('&nbsp;Dense <span style="font-size:.7em;color:#858585;">Showing densities of SV breakpoints and SNV/indels, over all samples</span>');const i=n.append("div");t.mode_radio_2=i.append("input").attr("type","radio").attr("id",s).attr("name",o).property("checked",t.isfull).on("change",(()=>{Cn(t,e)}));i.append("label").attr("for",s).attr("class","sja_clbtext").html('&nbsp;Expanded <span style="font-size:.7em;color:#858585;">Showing SV/SNV/indel for each sample</span>')}function Hn(t,e){if(t.singlesample)return;t.tkconfigtip.d.append("div").style("margin-bottom","5px").text("Show text labels in expanded mode").style("opacity",.5);const n=t.tkconfigtip.d.append("div").style("margin-bottom","20px");{const a=Math.random().toString();n.append("input").attr("type","checkbox").attr("id",a).property("checked",!t.multihidelabel_vcf).on("change",(()=>{t.multihidelabel_vcf=!t.multihidelabel_vcf;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;SNV/indel")}if(!t.nocnvlohsv){{const a=Math.random().toString();n.append("input").attr("type","checkbox").style("margin-left","20px").attr("id",a).property("checked",!t.multihidelabel_sv).on("change",(()=>{t.multihidelabel_sv=!t.multihidelabel_sv;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;DNA SV")}{const a=Math.random().toString();n.append("input").attr("type","checkbox").style("margin-left","20px").attr("id",a).property("checked",!t.multihidelabel_fusion).on("change",(()=>{t.multihidelabel_fusion=!t.multihidelabel_fusion;dn(t,e)}));n.append("label").attr("for",a).attr("class","sja_clbtext").html("&nbsp;RNA fusion")}}}function Pn(t,e,n){const a=n.tkarg_maygm(e)[0];if(t.chr==a.chr&&Math.max(t.start,a.start)<Math.min(t.stop,a.stop)){t.x1=n.seekcoord(t.chr,Math.max(t.start,a.start))[0].x;t.x2=n.seekcoord(t.chr,Math.min(t.stop,a.stop-1))[0].x}let s=n.width;for(const e of n.subpanels){s+=e.leftpad;if(t.chr==e.chr&&Math.max(t.start,e.start)<Math.min(t.stop,e.stop)){const n=s+(Math.max(t.start,e.start)-e.start)*e.exonsf;const a=s+(Math.min(t.stop,e.stop)-e.start)*e.exonsf;if(t.x1==undefined){t.x1=n;t.x2=a}else{t.x2=a}}s+=e.width}if(t.x1!=undefined&&n.gmmode&&n.gmmode!=Y.genomic){const e=n.width+n.subpanels.reduce(((t,e)=>e.width+e.leftpad),0);if(t.x1<t.x2){if(t.x2<0||t.x1>e){t.x1=undefined;t.x2=undefined;return}if(t.x1<0){t.x1=0}if(t.x2>e){t.x2=e}}else if(t.x1>t.x2){if(t.x1<0||t.x2>e){t.x1=undefined;t.x2=undefined;return}if(t.x2<0){t.x2=0}if(t.x1>e){t.x1=e}}}}function Tn(t,e){const n=e.seekcoord(t._chr,t._pos);for(const a of n){if(a.ridx!=undefined){if(a.x>0&&a.x<e.width){t.x=a.x;break}}else if(a.subpanelidx!=undefined){t.x=a.x}}}function Dn(t,e){if(!t.data_vcf)return;for(const n of t.data_vcf){if(n.dt==x){n._chr=n.chr;n._pos=n.pos;Tn(n,e);if(n.x==undefined){console.log("snvindel unmapped: "+n.chr+":"+n.pos)}else{delete n._chr;delete n._pos}}else{console.error("may_map_vcf: unknown dt")}}}function Yn(t,e){if(!t._data_vcf||t._data_vcf.length==0){t.data_vcf=null;return}const n=t._data_vcf;t.data_vcf=[];for(const a of n){if(a.dt==x){G(a,e)}else{throw"unknown dt "+a.dt}if(!t.legend_mclass.hiddenvalues.has(a.class)){t.data_vcf.push(a)}}}function Gn(t){const e=new Map;for(const n of t){e.set(n.sample+"."+n.chrA+"."+n.posA+"."+n.strandA+"."+n.chrB+"."+n.posB+"."+n.strandB,n)}return[...e.values()]}function Xn(t,e){if(!t)return false;if(e.legend_vorigin&&e.legend_vorigin.key){const n=t[e.legend_vorigin.key];if(n){if(n.toLowerCase()==e.legend_vorigin.germline)return true}}return false}export{Je as coverbarcolor_active,Xe as coverbarcolor_silent,Gn as dedup_sv,jn as draw_colorscale_cnv,Mn as draw_colorscale_loh,zn as focus_singlesample,Ye as intrasvcolor,yn as itemname_svfusion,en as labelspace,an as loadTk,Pn as map_cnv,An as multi_expressionstatus_ase_outlier,wn as multi_rnabam_asestatus,kn as multi_sample_addhighlight,vn as multi_sample_removehighlight,Ln as rnabamtk_copyparam,cn as trackclear,Xn as vcfvariantisgermline};