@sjcrh/proteinpaint-client 2.76.0 → 2.76.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/dist/{2dmaf-74b99126.js → 2dmaf-593951c7.js} +1 -1
  2. package/dist/{AppHeader-cecb39c2.js → AppHeader-29b88e14.js} +1 -1
  3. package/dist/{ColorScale-21cab8d2.js → ColorScale-3d3c42dc.js} +1 -1
  4. package/dist/{DEanalysis-95bad59a.js → DEanalysis-f81e0f19.js} +1 -1
  5. package/dist/{Disco-a6e921a0.js → Disco-db386f7a.js} +1 -1
  6. package/dist/{Disco.UI-9ad999ed.js → Disco.UI-8ed9cb39.js} +1 -1
  7. package/dist/{DragControls-e3b6a937.js → DragControls-d6250d18.js} +1 -1
  8. package/dist/{DziViewer-354a790d.js → DziViewer-9352e224.js} +1 -1
  9. package/dist/{FilterRxComp-701a1480.js → FilterRxComp-0f35b322.js} +1 -1
  10. package/dist/{FilterStateless-54c0b763.js → FilterStateless-b1c6ee04.js} +1 -1
  11. package/dist/{HicApp-d5a946bf.js → HicApp-14b94b20.js} +1 -1
  12. package/dist/{OrbitControls-694652cd.js → OrbitControls-45f56ed4.js} +1 -1
  13. package/dist/{WSIViewer-dc7f8eb0.js → WSIViewer-80f60272.js} +1 -1
  14. package/dist/{adSandbox-f438e388.js → adSandbox-94424b88.js} +1 -1
  15. package/dist/app-2cd97738.js +1 -0
  16. package/dist/{app-3320ab6f.js → app-686b9547.js} +1 -1
  17. package/dist/app-f031940d.js +1 -0
  18. package/dist/app.js +1 -1
  19. package/dist/{bam-431875ef.js → bam-6631640f.js} +1 -1
  20. package/dist/barchart-3c5d734c.js +1 -0
  21. package/dist/{barchart.events-da29c90d.js → barchart.events-df44e666.js} +1 -1
  22. package/dist/{bars.renderer-dcfdd59b.js → bars.renderer-b232d882.js} +1 -1
  23. package/dist/{block-6aedd569.js → block-4134e823.js} +1 -1
  24. package/dist/block.lazyload-eda77d9b.js +1 -0
  25. package/dist/{block.legend-d3f61ef7.js → block.legend-d2b7f1cb.js} +1 -1
  26. package/dist/{block.mds-3ad17dfa.js → block.mds-ebe7b58d.js} +1 -1
  27. package/dist/{block.mds.cnv-857ba868.js → block.mds.cnv-99f0a414.js} +1 -1
  28. package/dist/{block.mds.expressionrank-7e3b208c.js → block.mds.expressionrank-96bf864b.js} +1 -1
  29. package/dist/{block.mds.expressionstat-f2d31c86.js → block.mds.expressionstat-dcab3fd1.js} +1 -1
  30. package/dist/{block.mds.geneboxplot-f0fbaf12.js → block.mds.geneboxplot-e5b2a4ce.js} +1 -1
  31. package/dist/{block.mds.junction-7f87f48f.js → block.mds.junction-534eef9b.js} +1 -1
  32. package/dist/{block.mds.svcnv-ac035c12.js → block.mds.svcnv-de6a3c7d.js} +1 -1
  33. package/dist/{block.mds.svcnv.share-886d9479.js → block.mds.svcnv.share-2c2c16db.js} +1 -1
  34. package/dist/{block.mds2-7852c1ee.js → block.mds2-373fcb4d.js} +1 -1
  35. package/dist/{block.svg-9b916fa6.js → block.svg-be5d741d.js} +1 -1
  36. package/dist/{block.tk.aicheck-6770e333.js → block.tk.aicheck-f2da5e81.js} +1 -1
  37. package/dist/{block.tk.ase-ee807e59.js → block.tk.ase-ef848944.js} +1 -1
  38. package/dist/{block.tk.bam-00fba6e8.js → block.tk.bam-11fcba17.js} +1 -1
  39. package/dist/{block.tk.bedgraphdot-7fda78e9.js → block.tk.bedgraphdot-a81b0709.js} +1 -1
  40. package/dist/{block.tk.bigwig.ui-cc1a42f3.js → block.tk.bigwig.ui-f8e5ba71.js} +1 -1
  41. package/dist/{block.tk.hicstraw-526470e3.js → block.tk.hicstraw-e7072b25.js} +1 -1
  42. package/dist/{block.tk.junction-b43a4cda.js → block.tk.junction-1c9a7854.js} +1 -1
  43. package/dist/{block.tk.junction.textmatrixui-a60ed78a.js → block.tk.junction.textmatrixui-ffecbb16.js} +1 -1
  44. package/dist/{block.tk.ld-d15bde41.js → block.tk.ld-274c3a82.js} +1 -1
  45. package/dist/{block.tk.menu-3aeb93c6.js → block.tk.menu-e970cd4a.js} +1 -1
  46. package/dist/{block.tk.pgv-9af2bd64.js → block.tk.pgv-f4d4dbf7.js} +1 -1
  47. package/dist/{boxplot-e17a17b7.js → boxplot-44d3b48f.js} +1 -1
  48. package/dist/{brainImaging-bf2ceee9.js → brainImaging-2eaa419d.js} +1 -1
  49. package/dist/{brush-aa175142.js → brush-bb4ae2fb.js} +1 -1
  50. package/dist/{categorical-a52014a1.js → categorical-db9b0175.js} +1 -1
  51. package/dist/{condition-c646e357.js → condition-4e788f7d.js} +1 -1
  52. package/dist/{controls-287e6efa.js → controls-3c1691d7.js} +1 -1
  53. package/dist/{controls.btns-79b805dd.js → controls.btns-5b1240c8.js} +1 -1
  54. package/dist/controls.config-81cd5749.js +1 -0
  55. package/dist/cuminc-c4db28f0.js +1 -0
  56. package/dist/{customdata.inputui-dc49d94b.js → customdata.inputui-f9234d1f.js} +1 -1
  57. package/dist/{dataDownload-3a3d4f33.js → dataDownload-a4dfa2d0.js} +1 -1
  58. package/dist/{databrowser.ui-d8d3f8fd.js → databrowser.ui-a64bab0c.js} +1 -1
  59. package/dist/{density-a82a8b1c.js → density-69a732f6.js} +1 -1
  60. package/dist/{dictionary-c5a19d90.js → dictionary-e2232e84.js} +1 -1
  61. package/dist/{drag-7b30ba17.js → drag-d8daa62f.js} +1 -1
  62. package/dist/{e2pca-82765817.js → e2pca-f9324654.js} +1 -1
  63. package/dist/{ep-d017ec2f.js → ep-a5c1ee3a.js} +1 -1
  64. package/dist/{facet-a9b44ef3.js → facet-98971c68.js} +1 -1
  65. package/dist/{fusion.parse-d40d0b9d.js → fusion.parse-466ded6d.js} +1 -1
  66. package/dist/{geneExpClustering-34c3f518.js → geneExpClustering-66c05fb1.js} +1 -1
  67. package/dist/{geneExpression-0d1b7244.js → geneExpression-5685eae2.js} +1 -1
  68. package/dist/{geneExpression-589f485b.js → geneExpression-b5d0261f.js} +1 -1
  69. package/dist/{geneExpression-7d14983f.js → geneExpression-ff46a389.js} +1 -1
  70. package/dist/{geneORA-903a780f.js → geneORA-f1a90d02.js} +1 -1
  71. package/dist/{geneVariant-92c4e870.js → geneVariant-1cf17b3b.js} +1 -1
  72. package/dist/{geneVariant-89601b34.js → geneVariant-d0b9e1cb.js} +1 -1
  73. package/dist/{genefusion.ui-7e22e811.js → genefusion.ui-89a727ea.js} +1 -1
  74. package/dist/{genesearch-a4e19f0d.js → genesearch-41cb55ce.js} +1 -1
  75. package/dist/{geneset-108a39d2.js → geneset-b63496eb.js} +1 -1
  76. package/dist/{genomeBrowser-12f86a36.js → genomeBrowser-ec8fbddc.js} +1 -1
  77. package/dist/{genomeBrowser.controls-d5067811.js → genomeBrowser.controls-2dcaf4f5.js} +1 -1
  78. package/dist/{groupsetting-b4416a96.js → groupsetting-3fef59f9.js} +1 -1
  79. package/dist/{gsea-543dab25.js → gsea-3075c82c.js} +1 -1
  80. package/dist/{hierCluster-26e14090.js → hierCluster-33a828a1.js} +1 -1
  81. package/dist/hierCluster.config-fa799d06.js +1 -0
  82. package/dist/{hierCluster.interactivity-e56f6542.js → hierCluster.interactivity-6d453881.js} +1 -1
  83. package/dist/{hierCluster.renderers-74a64cf5.js → hierCluster.renderers-6279d7fb.js} +1 -1
  84. package/dist/{html.legend-a3f4ebfe.js → html.legend-fac5cb07.js} +1 -1
  85. package/dist/{imagePlot-b9eae4ae.js → imagePlot-38254245.js} +1 -1
  86. package/dist/{lasso-f767f634.js → lasso-e8b9500e.js} +1 -1
  87. package/dist/{launch.adhoc-abca6af3.js → launch.adhoc-2799109b.js} +1 -1
  88. package/dist/{leftlabel.sample-24c2388d.js → leftlabel.sample-afcdcefd.js} +1 -1
  89. package/dist/{legacyDataset-e0e201ab.js → legacyDataset-3b08c91a.js} +1 -1
  90. package/dist/{log-99af3443.js → log-4d84c357.js} +1 -1
  91. package/dist/{lollipop-806f8fa4.js → lollipop-64c5cdfc.js} +1 -1
  92. package/dist/{maf-b06579e4.js → maf-fd4ffbd0.js} +1 -1
  93. package/dist/{maftimeline-4840a380.js → maftimeline-3e892da7.js} +1 -1
  94. package/dist/{matrix-00bb50ff.js → matrix-e371888a.js} +1 -1
  95. package/dist/{matrix.cells-914dd0c6.js → matrix.cells-eb4110a7.js} +1 -1
  96. package/dist/{matrix.cluster-783ceab0.js → matrix.cluster-0df274ed.js} +1 -1
  97. package/dist/{matrix.config-6ce74dfe.js → matrix.config-3ef822b9.js} +1 -1
  98. package/dist/{matrix.controls-7b2a6f95.js → matrix.controls-42bb2063.js} +1 -1
  99. package/dist/{matrix.data-dac4f1b7.js → matrix.data-27b8e3a9.js} +1 -1
  100. package/dist/{matrix.dom-4e10bbe9.js → matrix.dom-1bbe1f39.js} +1 -1
  101. package/dist/{matrix.groups-b9fca14a.js → matrix.groups-67606700.js} +1 -1
  102. package/dist/{matrix.interactivity-84169b43.js → matrix.interactivity-cdcc56c9.js} +1 -1
  103. package/dist/{matrix.layout-dd5a44fd.js → matrix.layout-857cd336.js} +1 -1
  104. package/dist/{matrix.legend-ac6d45e6.js → matrix.legend-09f6dc57.js} +1 -1
  105. package/dist/{matrix.renderers-78010275.js → matrix.renderers-d392fb69.js} +1 -1
  106. package/dist/{matrix.serieses-9b4fd744.js → matrix.serieses-b03b62aa.js} +1 -1
  107. package/dist/{matrix.sort-014d798d.js → matrix.sort-9440c86a.js} +1 -1
  108. package/dist/{matrix.sorterUi-9bf7e6f9.js → matrix.sorterUi-2c5eb35f.js} +1 -1
  109. package/dist/{mavb-c6be46fc.js → mavb-9d86df89.js} +1 -1
  110. package/dist/{mds.fimo-bff6a1ed.js → mds.fimo-bffccb9f.js} +1 -1
  111. package/dist/{mds.samplescatterplot-9a02b9fb.js → mds.samplescatterplot-b3908cc7.js} +1 -1
  112. package/dist/{mds.survivalplot-055549f4.js → mds.survivalplot-9ad7dabc.js} +1 -1
  113. package/dist/{metaboliteIntensity-fac92f8b.js → metaboliteIntensity-ec3176f4.js} +1 -1
  114. package/dist/niceNumLabels-5f45218a.js +1 -0
  115. package/dist/{nodrag-16ad4b03.js → nodrag-ab7d5a9f.js} +1 -1
  116. package/dist/{notify-224cccbd.js → notify-59f61230.js} +1 -1
  117. package/dist/{numeric-b0b17185.js → numeric-4853b665.js} +1 -1
  118. package/dist/{numeric.binary-1f9e93f2.js → numeric.binary-1dd9a2b4.js} +1 -1
  119. package/dist/{numeric.continuous-ebcd0567.js → numeric.continuous-ed132eea.js} +1 -1
  120. package/dist/{numeric.discrete-7b97044a.js → numeric.discrete-d780d076.js} +1 -1
  121. package/dist/{numeric.spline-1be88f3d.js → numeric.spline-abe07708.js} +1 -1
  122. package/dist/{numeric.toggle-7fa2a770.js → numeric.toggle-647423dd.js} +1 -1
  123. package/dist/oncomatrix-7ac995a2.js +1 -0
  124. package/dist/{parseData-21fe9822.js → parseData-567f3d70.js} +1 -1
  125. package/dist/{plot.2dvaf-18a35e4b.js → plot.2dvaf-4016e75e.js} +1 -1
  126. package/dist/plot.app-d6fe76e2.js +1 -0
  127. package/dist/plot.barplot-d2fc5020.js +1 -0
  128. package/dist/{plot.boxplot-fe3046c6.js → plot.boxplot-76229491.js} +1 -1
  129. package/dist/{plot.brainImaging-2ceb6023.js → plot.brainImaging-39b80a1c.js} +1 -1
  130. package/dist/{plot.disco-6011f87f.js → plot.disco-9a544f9a.js} +1 -1
  131. package/dist/{plot.dzi-6728a7c8.js → plot.dzi-f1658ebf.js} +1 -1
  132. package/dist/{plot.ssgq-5581dc56.js → plot.ssgq-aeb2dabc.js} +1 -1
  133. package/dist/{plot.vaf2cov-b2284c64.js → plot.vaf2cov-ba8332ed.js} +1 -1
  134. package/dist/{plot.wsi-9a9d4034.js → plot.wsi-2d802557.js} +1 -1
  135. package/dist/{profileBarchart-0476f1f8.js → profileBarchart-72adc533.js} +1 -1
  136. package/dist/{profileHome-32eb9b50.js → profileHome-37fd52e5.js} +1 -1
  137. package/dist/{profilePlot-c7e099e8.js → profilePlot-0b897a05.js} +1 -1
  138. package/dist/profilePolar-a7248d48.js +1 -0
  139. package/dist/profileRadar-1ba5d8fd.js +1 -0
  140. package/dist/profileRadarFacility-452e76ef.js +1 -0
  141. package/dist/{profileSummary-b114204f.js → profileSummary-7f0eacf0.js} +1 -1
  142. package/dist/{recover-49e09de0.js → recover-74f2e965.js} +1 -1
  143. package/dist/{regression.inputs-a761f40d.js → regression.inputs-ff00f74e.js} +1 -1
  144. package/dist/{regression.inputs.values.table-5929d25a.js → regression.inputs.values.table-1753d56b.js} +1 -1
  145. package/dist/{regression.results-69bc42d0.js → regression.results-6f85a5dc.js} +1 -1
  146. package/dist/{renderPvalueTable-dc5d15f2.js → renderPvalueTable-17558d6a.js} +1 -1
  147. package/dist/{sampleScatter-2d0ed680.js → sampleScatter-97917406.js} +1 -1
  148. package/dist/{sampleScatter.rendererThree-0b12ac61.js → sampleScatter.rendererThree-4649d1ec.js} +2 -2
  149. package/dist/{sampleView-484ab133.js → sampleView-f86dc5ea.js} +1 -1
  150. package/dist/{samplelst-689796e6.js → samplelst-4a5512df.js} +1 -1
  151. package/dist/{samplematrix-2b137a05.js → samplematrix-1192e5e2.js} +1 -1
  152. package/dist/{scatter-205e013f.js → scatter-cc1b0d07.js} +1 -1
  153. package/dist/{select2Terms-b21e184a.js → select2Terms-d4f6ed9e.js} +1 -1
  154. package/dist/{selectGenomeWithTklst-466995b4.js → selectGenomeWithTklst-b5cfd153.js} +1 -1
  155. package/dist/{singleCellCellType-5db730bb.js → singleCellCellType-d8c58253.js} +1 -1
  156. package/dist/{singleCellGeneExpression-7147a2d0.js → singleCellGeneExpression-b7209531.js} +1 -1
  157. package/dist/{singleCellPlot-73b2738f.js → singleCellPlot-e6f83b2a.js} +1 -1
  158. package/dist/{singlecell-bca774ed.js → singlecell-321dd973.js} +1 -1
  159. package/dist/{singlecell-24409b72.js → singlecell-879235b3.js} +1 -1
  160. package/dist/snp-541ec14d.js +1 -0
  161. package/dist/{snp-a8388ce4.js → snp-b046b7e6.js} +1 -1
  162. package/dist/snplocus-61ff1c10.js +1 -0
  163. package/dist/{spliceevent.a53ss.diagram-e2eab72b.js → spliceevent.a53ss.diagram-1a84db58.js} +1 -1
  164. package/dist/{spliceevent.exonskip.diagram-4d5df3a1.js → spliceevent.exonskip.diagram-da10648b.js} +1 -1
  165. package/dist/{spliceevent.exonskip.getdefault-a94aad6e.js → spliceevent.exonskip.getdefault-8028e522.js} +1 -1
  166. package/dist/{spliceevent.noeventdiagram-ea97b0fb.js → spliceevent.noeventdiagram-1d6d790d.js} +1 -1
  167. package/dist/{spliceevent.phrase-c5832470.js → spliceevent.phrase-2ca0ce59.js} +1 -1
  168. package/dist/{stattable-7c5ecc2f.js → stattable-c5f12d9c.js} +1 -1
  169. package/dist/{style.gdc-131f3c77.js → style.gdc-5b7d90c6.js} +1 -1
  170. package/dist/summary-0624f5e6.js +1 -0
  171. package/dist/{sunburst-533902a7.js → sunburst-30295714.js} +1 -1
  172. package/dist/{survival-e16e068f.js → survival-816e055a.js} +1 -1
  173. package/dist/{survival-92250664.js → survival-fcc7719f.js} +1 -1
  174. package/dist/{svg.download-35926549.js → svg.download-e89a7369.js} +1 -1
  175. package/dist/{svg.legend-8d490df2.js → svg.legend-c93f2980.js} +1 -1
  176. package/dist/{svgraph-6fac8cbc.js → svgraph-6ab3011b.js} +1 -1
  177. package/dist/{svmr-d07ff695.js → svmr-3ad3d600.js} +1 -1
  178. package/dist/{table-ad744310.js → table-4d3a771e.js} +1 -1
  179. package/dist/{table-29d5a973.js → table-f50a9344.js} +1 -1
  180. package/dist/{termInfo-bf99a37e.js → termInfo-d0a9e65f.js} +1 -1
  181. package/dist/{termdb.bins-8b656cc3.js → termdb.bins-01e8cce6.js} +1 -1
  182. package/dist/{termsetting-33ea66f1.js → termsetting-ad8c4f3a.js} +1 -1
  183. package/dist/{tk-071a7550.js → tk-e74c9beb.js} +1 -1
  184. package/dist/{toggleButtons-dbdbad01.js → toggleButtons-04c5ad7c.js} +1 -1
  185. package/dist/{tp.ui-9c2e9fc5.js → tp.ui-7b24f0ef.js} +1 -1
  186. package/dist/{tvs.density-f6128793.js → tvs.density-b2790080.js} +1 -1
  187. package/dist/{tvs.geneVariant-ca4bdbb1.js → tvs.geneVariant-418ed4ff.js} +1 -1
  188. package/dist/{tvs.numeric-0260a825.js → tvs.numeric-de14101f.js} +1 -1
  189. package/dist/{tvs.samplelst-cb71b3bf.js → tvs.samplelst-15bb62f1.js} +1 -1
  190. package/dist/{uiUtils-f1bd2bcc.js → uiUtils-ff2d4a6a.js} +1 -1
  191. package/dist/{variantBrowser-7c540224.js → variantBrowser-261373bf.js} +1 -1
  192. package/dist/{vcf-5cc55588.js → vcf-145bf5dd.js} +1 -1
  193. package/dist/violin-e647aac9.js +1 -0
  194. package/dist/{violin.interactivity-4da6d7a9.js → violin.interactivity-30a239fe.js} +1 -1
  195. package/dist/{violin.renderer-ce024265.js → violin.renderer-e29d2700.js} +1 -1
  196. package/dist/{violinRenderer-f7c96a60.js → violinRenderer-08b3b58c.js} +1 -1
  197. package/dist/{viridis-01ab20c5.js → viridis-d86ad99b.js} +1 -1
  198. package/dist/{y-67939f83.js → y-06b0d47c.js} +1 -1
  199. package/dist/{zoom-25dce8b9.js → zoom-d6ef6f3f.js} +1 -1
  200. package/package.json +1 -1
  201. package/dist/app-649f8357.js +0 -1
  202. package/dist/app-b369b169.js +0 -1
  203. package/dist/barchart-8277ed43.js +0 -1
  204. package/dist/block.lazyload-87b12654.js +0 -1
  205. package/dist/controls.config-28d6d6a8.js +0 -1
  206. package/dist/cuminc-9e275854.js +0 -1
  207. package/dist/hierCluster.config-98e82dff.js +0 -1
  208. package/dist/niceNumLabels-238aabce.js +0 -1
  209. package/dist/oncomatrix-351af2a0.js +0 -1
  210. package/dist/plot.app-30c4b8e5.js +0 -1
  211. package/dist/plot.barplot-7c4865a2.js +0 -1
  212. package/dist/profilePolar-6b981e63.js +0 -1
  213. package/dist/profileRadar-bca1cc03.js +0 -1
  214. package/dist/profileRadarFacility-bbb1ecd8.js +0 -1
  215. package/dist/snp-37d06246.js +0 -1
  216. package/dist/snplocus-7a1ea8c9.js +0 -1
  217. package/dist/summary-5ec455d3.js +0 -1
  218. package/dist/violin-2ba509eb.js +0 -1
@@ -1 +1 @@
1
- import{Z as t,B as e,ap as s,aP as o,aQ as a,aR as n,ar as r,at as i,as as l,ak as c,z as f,a9 as d,p,ac as u,b6 as m,b7 as h,aN as g,q as b,b8 as y,j as x,b9 as k,ba as v,a7 as w,aG as _,bb as j,a8 as M,af as A,aM as z,aL as N,r as P,aW as S,d as C,aF as F,I as R,ah as I,W as B,ag as q,ad as D,O as L,aJ as E,bc as U,bd as G,be as V,bf as O,ae as T,M as H}from"./app-b369b169.js";import{v as X,a as Y}from"./vcf-5cc55588.js";import{p as J}from"./partition-db811f6b.js";import{d as Q}from"./arc-3d6751aa.js";import{b as W}from"./axis-747c801e.js";import{s as Z}from"./legacy-d3-polyfill-bdb2d792.js";const K="__";function $(f){const{mlst:d,tk:p,block:u}=f;if(!d||d.length==0)return;let m;if(f.pane){const e=t({x:f.x,y:f.y});e.header.html(tt(d));m=e.body}else{m=f.holder}if(!m){console.error("no holder provided for showing table");return}const h=new Map;for(const t of d){if(!h.has(t.dt)){h.set(t.dt,[])}h.get(t.dt).push(t)}delete p.__singlevariant_table;for(const[t,f]of h){const d=m.append("div").style("margin","10px");if(h.size>1){d.append("p").text(e[t]).style("color","#858585")}switch(t){case c:et(f,d,p,u);break;case l:case i:ct(f,d,p,u);break;case r:dt(f,d,p,u.genome);break;case n:case a:ut(f,d,p,u.genome);break;case o:pt(f,d,p,u.genome);break;case s:d.append("p").text("cnv not supported yet");break;default:d.append("p").text("unknown dt: "+t)}}Ft(d,m,p,u)}function tt(t){if(t.length==1){const e=t[0];const d=f[e.class];if(e.dt==c){return'<span style="font-weight:bold;color:'+d.color+'">'+(e.mname?e.mname:e.pos?e.chr+":"+(e.pos+1):"")+'</span> <span style="font-size:80%">'+d.label+"</span>"}if(e.dt==l||e.dt==i){const t=[];for(let s=0;s<e.pairlst.length;s++){if(s==0)t.push(e.pairlst[s].a.name?e.pairlst[s].a.name:e.pairlst[s].a.chr);t.push(e.pairlst[s].b.name?e.pairlst[s].b.name:e.pairlst[s].b.chr)}return t.join(" - ")+'&nbsp;&nbsp;<span style="font-size:80%">'+d.label+"</span>"}if(e.dt==n||e.dt==a||e.dt==r||e.dt==o||e.dt==s){return'<span style="font-size:80%">'+d.label+"</span>"}return"unknown dt "+e.dt}const d=new Set;for(const e of t){d.add(e.dt)}if(d.size==1){const s=[...d][0];return t.length+" "+e[s]}return t.length+" mutations"}function et(e,s,o,a){if(o.ds&&o.ds.id2vcf){if(e.length==1){const t=o.ds.id2vcf[e[0].vcfid];if(!t){s.append("p").text("No vcf config file (id: "+e[0].vcfid+")");return}at(e[0],t,s,o,a);return}for(const n of e){const e=o.ds.id2vcf[n.vcfid];if(!e){s.append("p").text("No vcf config file (id: "+n.vcfid+")");continue}const r=s.append("div").attr("class","sja_menuoption").on("click",(s=>{const r=t({x:s.clientX+100,y:Math.max(100,s.clientY-100)});at(n,e,r.body,o,a)}));if(n.mname){r.append("span").html(n.mname+'\t<span style="font-size:80%;color:#858585">'+f[n.class].label+"</span>")}else if(n.csq){r.append("span").html(n.csq[0]._mname+'\t<span style="font-size:80%;color:#858585">'+n.csq[0].Consequence+"</span>")}r.append("span").html("&nbsp;&nbsp;"+n.chr+":"+(n.pos+1)+' <span style="font-size:70%">REF</span> '+n.ref+' <span style="font-size:70%">ALT</span> '+n.alt)}return}const n=a.genome.hasSNP;const r={chr:null,bprange:[],holder:null,says:null};const i={set:new Map,butholder:null};for(const t of e){if(n&&t.chr&&t.pos){r.chr=t.chr;let e=true;for(const s of r.bprange){if(s.start<=t.pos&&s.stop>=t.pos){e=false;break}}if(e){r.bprange.push({start:t.pos,stop:t.pos+1})}}}if(!o.snvindelattr){mt(o,e)}if(a.variantPageCall_snv){i.butholder=s.append("div").style("margin","10px")}if(e.length==1){const t=e[0];r.alleleLst=[t.ref,t.alt];if(a.variantPageCall_snv){if(t.chr!=undefined&&t.pos!=undefined&&t.ref!=undefined&&t.alt!=undefined){i.set.set(t.chr+K+t.pos+K+t.ref+K+t.alt,{mname:t.mname,class:t.class})}}const l=[];for(const e of o.snvindelattr){if(e.lst){const s=[];for(const o of e.lst){if(o.ismaf){const e=o.get(t);s.push({k:o.label,v:e?Number.isFinite(e.f)?'<span style="color:'+o.fill+'">'+(e.f*100).toFixed(0)+"% ("+e.v1+"/"+e.v2+")</span>":"n/a":""})}else{s.push({k:o.label,v:o.get(t)})}}if(s.length){l.push({k:e.label,kvlst:s})}}else if(e.ismaf){const s=e.get(t);l.push({k:e.label,v:s?Number.isFinite(s.f)?'<span style="color:'+e.fill+'">'+(s.f*100).toFixed(0)+"% ("+s.v1+"/"+s.v2+")</span>":"n/a":""})}else{let s=e.get(t);if(e.hover){const o=e.hover(t);if(o){s+=' <span style="color:#aaa;font-size:80%">'+o+"</span>"}}l.push({k:e.label,v:s})}}const c=d(s,l);if(n){const t=c.append("tr");t.append("td").attr("colspan",2).style("color","#9e9e9e").text("dbSNP");r.says=t.append("td").text("loading...")}const f=s.append("div").style("margin-top","10px");if(o.eplst){for(const t of o.eplst){lt(t,f,e)}}if(o.ds&&o.ds.snvindel_legend){f.append("button").text("Legend").on("click",(()=>{if(t.style("display")=="none"){p(t)}else{u(t)}}));const t=f.append("div").style("display","none").style("margin","10px").style("width","400px").html(o.ds.snvindel_legend)}}else{if(a.variantPageCall_snv){for(const t of e){if(t.chr!=undefined&&t.pos!=undefined&&t.ref!=undefined&&t.alt!=undefined){i.set.set(t.chr+K+t.pos+K+t.ref+K+t.alt,{mname:t.mname,class:t.class})}}}const t=s.append("table").style("border-spacing","3px").style("border-collapse","separate").style("margin","0px 7px 7px 0px").style("font-size","90%").style("color","black").style("background-color","white");st(e,t,o.snvindelattr,o);const l=s.append("div").style("margin","10px 5px");let c,f,d;l.append("button").text("Table columns").on("click",(function(){if(c.style("display")=="block"){this.style.color="black";u(c)}else{this.style.color="red";p(c)}}));if(n&&r.bprange.length){r.button=l.append("button").text("loading...").on("click",(function(){if(f.style("display")=="block"){this.style.color="black";u(f)}else{this.style.color="red";p(f)}}))}if(o.eplst){for(const t of o.eplst){lt(t,l,e)}}if(o.ds&&o.ds.snvindel_legend){l.append("button").text("Legend").on("click",(function(){if(d.style("display")=="block"){this.style.color="black";u(d)}else{this.style.color="red";p(d)}}))}c=s.append("div").style("margin","10px").style("display","none");for(const s of o.snvindelattr){const a=Math.random();const n=c.append("input").attr("type","checkbox").attr("id",a);if(!s.hide)n.attr("checked",true);n.on("change",(()=>{s.hide=!n.node().checked;st(e,t,o.snvindelattr,o)}));c.append("label").attr("for",a).text(s.label);c.append("br")}if(n){f=s.append("div").style("margin","10px").style("display","none");r.holder=f;r.says=f}if(o.ds&&o.ds.snvindel_legend){d=s.append("div").style("display","none").style("width","300px").html(o.ds.snvindel_legend)}}if(n&&r.bprange.length){m(r.chr,r.bprange,a.genome,r.alleleLst).then((t=>{if(!t||t.length==0)throw{message:"no SNP"};r.says.text("");if(r.button){r.button.text(t.length+" SNP"+(t.length>1?"s":""))}for(const e of t){const t=r.says.append("div");h(e,t)}})).catch((t=>{r.says.text(t.message);if(r.button){r.button.attr("disabled",true)}if(t.stack)console.log(t.stack)}))}if(a.variantPageCall_snv){const t=[];for(const[e,s]of i.set){const o=e.split(K);t.push({chr:o[0],position:Number.parseInt(o[1])+1,refallele:o[2],altallele:o[3],class:s.class,aachange:s.mname})}if(t.length==1){const e=t[0];e.container=i.butholder;a.variantPageCall_snv(e)}else if(t.length>1){i.butholder.append("div").classed("sja_variantpagesnv",true).text("Variant Page").on("click",(e=>{const s=o.tktip.clear().showunder(e.target).d.append("table");for(const e of t){const t=s.append("tr");t.append("td").text(e.aachange);t.append("td").text(f[e.class].label).style("font-size",".7em").style("color",f[e.class].color);t.append("td").text(e.chr+":"+e.position+" "+e.refallele+">"+e.altallele).attr("font-size",".7em");e.container=t.append("td");a.variantPageCall_snv(e)}}))}}}function st(t,e,s,o,a){e.selectAll("*").remove();let n=null;for(const t of s){if(t.lst){for(const e of t.lst){if(e.sort)n=e}}else if(t.sort)n=t}if(n){t.sort(((t,e)=>{const s=n.get(t);const o=n.get(e);if(n.ismaf){if(s==undefined){if(o==undefined)return 0;return 1}else{if(o==undefined)return-1;return n.descend?o.f-s.f:s.f-o.f}}if(s==undefined||s===""){if(o==undefined||o==="")return 0;return 1}if(o==undefined||o==="")return-1;if(typeof s=="string"){if(s<o)return n.descend?1:-1;if(s>o)return n.descend?-1:1}if(typeof s=="number")return n.descend?o-s:s-o;return 0}))}const r=e.append("tr");const i=e.append("tr");r.append("td").attr("rowspan",2);for(const n of s){if(n.hide)continue;if(n.lst){r.append("td").attr("colspan",n.lst.length).style("color","#aaa").style("border-bottom","solid 1px #ccc").style("text-align","center").html(n.label);for(const r of n.lst){i.append("td").attr("class","sja_clbtext").html(r.label+(r.sort?r.descend?" &#9660;":" &#9650;":"")).on("click",(()=>{if(r.sort){r.descend=!r.descend}for(const t of s){if(t.lst){for(const e of t.lst)e.sort=false}else{t.sort=false}}r.sort=true;st(t,e,s,o,a)}))}}else{r.append("td").attr("rowspan",2).attr("class","sja_clbtext").html(n.label+(n.sort?n.descend?" &#9660;":" &#9650;":"")).on("click",(()=>{if(n.sort){n.descend=!n.descend}for(const t of s){if(t.lst){for(const e of t.lst)e.sort=false}else{t.sort=false}}n.sort=true;st(t,e,s,o,a)}))}}const l=t.length>1e3?900:t.length;for(let n=0;n<l;n++){const r=t[n];const i=e.append("tr").attr("class","sja_tr");if(a){i.on("click",(()=>a(r)))}if(o.eplst){i.on("mouseover",((t,e)=>{for(const t of o.eplst)t.may_hl([r],true)})).on("mouseout",((t,e)=>{for(const t of o.eplst)t.may_hl([r],false)}))}i.append("td").style("font-size",".8em").text(n+1);for(const t of s){if(t.hide)continue;if(t.lst){for(const e of t.lst){const t=i.append("td");if(e.ismaf){const s=e.get(r);if(s&&typeof s=="object"){if(s.v2==0){t.text("0/0");t.attr("aria-label","No coverage")}else{g(t,s,e)}}}else{t.html(e.get(r))}}}else{const e=i.append("td");if(t.hover){const s=t.hover(r);if(s!=undefined){e.attr("aria-label",s)}}if(t.tablecellwidth){e.style("width",t.tablecellwidth).style("word-break","break-all")}if(t.ismaf){const s=t.get(r);if(s){if(s.v2==0){e.text("0/0");e.attr("aria-label","No coverage")}else{g(e,s,t)}}}else{e.html(t.get(r))}}}}}function ot(t){return'<span style="font-size:70%;color:#858585">'+t+"</span>"}function at(t,e,s,o,a){if(!e){s.append("p").text("vcfobj config object missing");return}const n=s.append("div").style("margin-top","10px");n.append("span").text(t.type).style("padding-right","10px");n.append("span").text(t.chr+":"+(t.pos+1)).style("padding-right","10px");if(t.dt==c){n.append("span").style("padding-right","10px").html(ot("REF")+" "+t.ref+" "+ot("ALT")+" "+t.alt);if(a.variantPageCall_snv){const e={chr:t.chr,position:t.pos+1,refallele:t.ref,altallele:t.alt,container:n.append("span").style("padding-left","20px")};a.variantPageCall_snv(e)}if(o.button4variant){zt(n,t,o.button4variant)}if(o.url4variant){At(n,t,o.url4variant)}}if(e.info&&e.info.CSQ&&e.info.CSQ.csqheader&&t.csq){vt(t.csq,n,o,e.info.CSQ.csqheader)}if(e.info&&e.info.ANN&&e.info.ANN.annheader&&t.ann){wt(t.ann,n,o,e.info.ANN.annheader)}if(o.variant2img){_t(t,n,s.append("div"),o)}const r=s.append("div");if(Pt(t,o,r)){r.style("margin-top","10px")}else if(t.sampledata){const e=r.append("div");Promise.resolve().then((()=>{if(t.sampledata.length==0&&o.ds.vcfcohorttrack){e.text("Loading ...");return Mt(t,o,a).then((e=>{if(!e){return}t.sampledata=e.sampledata;return}))}return})).then((()=>{e.remove();if(t.sampledata.length==0){return}if(t.sampledata.length==1){St(t,o,r);return}if(Nt(t,o,r)){r.style("margin-top","10px")}else if(jt(t,o,r)){r.style("margin-top","10px")}else if(Pt(t,o,r)){r.style("margin-top","10px")}else{kt(t,n,o)}})).catch((t=>{e.text(t)}))}if(e.infopipejoin){const o=[];if(t.altinfo){for(const s of e.infopipejoin){const e=t.altinfo[s.key];if(e){if(Array.isArray(e)){o.push(e)}else{o.push(e.split(/[,|]/))}}else{o.push([])}}}if(o.length){const t=s.append("div");for(let s=0;s<o[0].length;s++){const a=[];for(let t=0;t<e.infopipejoin.length;t++){const n=e.infopipejoin[t];a.push({k:n.label,v:n.values?n.values[o[t][s]]:o[t][s]})}d(t,a).style("display","inline-block").style("border","solid 1px black").style("margin","20px")}}}nt(t,s,o);rt(t,s,o);const i={};const l={};if(o.vcfinfofilter){for(const t of o.vcfinfofilter.lst){if(t.categories){if(t.altalleleinfo){i[t.altalleleinfo.key]=t.categories}else if(t.locusinfo){l[t.locusinfo.key]=t.categories}}}}{const o=[];for(const s in t.altinfo){const a=Array.isArray(t.altinfo[s])?t.altinfo[s]:[t.altinfo[s]];let n;if(i[s]){n=a.map((t=>{const e=i[s][t];if(e){return'<span style="padding:1px 3px;background:'+e.color+";color:"+(e.textcolor||"black")+';">'+t+"</span>"}return t}))}else{n=a}o.push({k:s,v:n.join(", ")+(e.info&&e.info[s]?' <span style="font-size:70%;color:#858585">'+e.info[s].Description+"</span>":"")})}if(o.length){s.append("h3").text("Alternative allele:");d(s,o)}}{const a=[];for(const s in t.info){if(o.info2table&&o.info2table[s]){continue}const n=Array.isArray(t.info[s])?t.info[s]:[t.info[s]];let r;if(l[s]){r=n.map((t=>{const e=l[s][t];if(e){return'<span style="padding:1px 3px;background:'+e.color+";color:"+(e.textcolor||"black")+';">'+t+"</span>"}return t}))}else{r=n}a.push({k:s,v:r.join(", ")+(e.info&&e.info[s]?' <span style="font-size:70%;color:#858585">'+e.info[s].Description+"</span>":"")})}if(a.length){s.append("h3").text("This locus:");d(s,a)}}}function nt(t,e,s){if(!s.info2singletable)return;for(const o in s.info2singletable){const a=s.info2singletable[o];const n=t.info[o];if(!n||!n[0])continue;const r=[];const i=n[0].split(a.col_separator);for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;r.push({k:a.fields[t].name,v:it(a,i,t)})}d(e,r)}}function rt(t,e,s){if(!s.info2table)return;for(const o in s.info2table){const a=s.info2table[o];const n=t.info[o];if(!n)continue;if(a.separate_tables){const t=JSON.parse(JSON.stringify(a.separate_tables));t.forEach((t=>t.rows=[]));for(const e of n){const s=e.split(a.col_separator);const o=new Map;for(let t=0;t<a.fields.length;t++){o.set(a.fields[t].name,s[t])}for(const e of t){if(e.groupers.reduce(((t,e)=>o.get(e.field)==e.value?t:false),true)){e.rows.push(o)}}}for(const s of t){if(s.rows.length==0)continue;e.append("h3").html(s.headhtml);const t=e.append("table").style("border-spacing","2px").style("border-collapse","separate").style("font-size","90%");const o=t.append("tr");for(const t of a.fields){if(t.hide)continue;o.append("td").text(t.name)}for(const e of s.rows){const s=t.append("tr").attr("class","sja_tr");const o=a.fields.map((t=>e.get(t.name)));for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;const e=s.append("td");e.html(it(a,o,t))}}}continue}const r=e.append("table").style("border-spacing","2px").style("border-collapse","separate").style("font-size","90%");const i=r.append("tr");for(const t of a.fields){if(t.hide)continue;i.append("td").text(t.name)}for(const t of n){const e=r.append("tr").attr("class","sja_tr");const s=t.split(a.col_separator);for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;const o=e.append("td");o.html(it(a,s,t))}}}}function it(t,e,s){const o=t.fields[s];if(o.hide)return;let a=e[s];if(a==undefined)return;if(o.eval){a=(0,eval)('"'+a+'"')}if(o.isurl)return"<a href="+a+" target=_blank>"+a+"</a>";if(o.appendUrl){if(o.separator){return a.split(o.separator).map((t=>"<a href="+o.appendUrl+t+" target=_blank>"+t+"</a>")).join(", ")}return"<a href="+o.appendUrl+a+" target=_blank>"+a+"</a>"}if(o.insert2url){return"<a href="+o.insert2url.left+a+o.insert2url.right+" target=_blank>"+a+"</a>"}if(o.ampersand2br)return a.replace(/&/g,"<br>");if(o.urlMatchLst){const t=a.toLowerCase();const e=t.split(o.urlMatchLst.separator)[o.urlMatchLst.idIndex];if(e){for(const s of o.urlMatchLst.types){if(t.indexOf(s.type)!=-1){if(s.appendUrl){return'<span style="font-size:.7em">'+s.type.toUpperCase()+"</span> <a href="+s.appendUrl+e+" target=_blank>"+e+"</a>"}}}}}return a}function lt(t,e,s){let o=true;for(const e of s){if(e[t.p.sampletype]in t.sampletype2value){o=false;break}}if(o){return}let a=false;e.append("button").text("Highlight in "+t.p.name).on("click",(()=>{a=!a;t.may_hl(s,a)}))}function ct(t,e,s,o){const a=e.append("div").style("margin-bottom","10px");ft(t[0].pairlst,o,a);if(!s.svattr){yt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.svattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const n=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const r=n.append("tr");for(const t of s.svattr){r.append("td").text(t.label)}st(t,n,s.svattr,s,(t=>{a.selectAll("*").remove();ft(t.pairlst,o,a)}));if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function ft(t,e,s){for(const e of t){if(e.a.isoform){e.a.gm={isoform:e.a.isoform}}if(e.b.isoform){e.b.gm={isoform:e.b.isoform}}}const o={jwt:e.jwt,hostURL:e.hostURL,pairlst:t,genome:e.genome,holder:s};import("./svgraph-6fac8cbc.js").then((t=>{t.default(o)}))}function dt(t,e,s,o){if(!s.itdattr){bt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.itdattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.itdattr){n.append("td").text(t.label)}st(t,a,s.itdattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function pt(t,e,s,o){if(!s.delattr){gt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.delattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.delattr){n.append("td").text(t.label)}st(t,a,s.delattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function ut(t,e,s,o){if(!s.truncattr){ht(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.truncattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.truncattr){n.append("td").text(t.label)}st(t,a,s.truncattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function mt(t,e){t.snvindelattr=[];if(t.ds&&t.ds.snvindel_attributes){for(const e of t.ds.snvindel_attributes){t.snvindelattr.push(e)}}else{const s=new Set(["pos","aapos","rnapos","dt","vcfid","isrim1","isrim2","alt","__x"]);if(t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k)}}const o=[];for(const t in e[0]){if(s.has(t))continue;switch(t){case"chr":o.push({label:"Genome pos.",get:t=>t.chr+":"+(t.pos+1)});break;case"class":o.push({label:"Class",get:t=>f[t.class].label});break;case"mname":o.push({label:"Mutation",get:t=>t.mname});break;case"ref":o.push({label:"Allele",lst:[{label:"Ref",get:t=>t.ref},{label:"Alt",get:t=>t.alt}]});break;case"pmid":o.push(xt());break;case"maf_tumor":o.push({get:t=>t.maf_tumor,ismaf:true,width:40,height:12,label:"Tumor MAF",fill:"#ff4d4d",fillbg:"#ffcccc"});break;case"maf_normal":o.push({get:t=>t.maf_normal,ismaf:true,width:40,height:12,label:"Germline MAF",fill:"#4d4dff",fillbg:"#ccccff"});break;default:o.push({label:t,get:e=>e[t]})}}t.snvindelattr=o}if(t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){t.snvindelattr.push({label:e.label||e.k,hide:e.hide,get:t=>{if(t[e.k])return t[e.k]+(e.full?t[e.full]?' <span style="font-size:.8em;color:#858585">'+t[e.full]+"</span>":"":"");return""}})}}if(t.eplst){for(const e of t.eplst){if(!e.p){console.error("no config object for epaint");continue}if(e.p.maf){t.snvindelattr.push({label:e.p.name,lst:[{label:e.p.datatype,get:t=>{const s=t[e.p.sampletype];if(!s)return"";return e.sampletype2value[s]}},{label:e.p.maf.label,width:40,height:12,fill:e.p.hlcolor,fillbg:e.p.hlcolor2,get:e.p.maf.get,readcountcredible:e.p.maf.readcountcredible,ismaf:true}]})}else{t.snvindelattr.push({label:e.p.name+" "+e.p.datatype,get:t=>{const s=t[e.p.sampletype];if(!s)return"";return e.sampletype2value[s]}})}}}}function ht(t,e){const s=new Set(["__x","mname","gene","strand","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","partner"]);t.truncattr=[];for(const o of e){if(o.sample){t.truncattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.truncattr.push({label:"Position",get:t=>t.chr+":"+t.pos});const o=new Set;for(const t of e){o.add(t.dt)}if(o.size>1){t.truncattr.push({label:"Truncated",get:t=>t.dt==n?"N-term":"C-term"})}for(const o of e){if(o.pmid){t.truncattr.push(xt());s.add("pmid");break}}for(const s of e){if(s.partner){t.truncattr.push({get:t=>{const e=[];for(const s in t.partner){e.push(s+": "+t.partner[s])}return e.join("&nbsp;&nbsp;")},label:"Translocation"});break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.truncattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.truncattr.push({label:o,get:t=>t[o]})}}function gt(t,e){const s=new Set(["__x","mname","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","rnadellength","a","b"]);t.delattr=[];for(const o of e){if(o.sample){t.delattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.delattr.push({label:"Position",get:t=>t.chr+":"+t.pos});t.delattr.push({label:"Del. length",get:t=>t.rnadellength+" bp"});for(const o of e){if(o.pmid){t.delattr.push(xt());s.add("pmid");break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.delattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.delattr.push({label:o,get:t=>t[o]})}}function bt(t,e){const s=new Set(["__x","mname","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","rnaduplength","a","b"]);t.itdattr=[];for(const o of e){if(o.sample){t.itdattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.itdattr.push({label:"Position",get:t=>t.chr+":"+t.pos});t.itdattr.push({label:"Dup. length",get:t=>t.rnaduplength+" bp"});for(const o of e){if(o.pmid){t.itdattr.push(xt());s.add("pmid");break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.itdattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.itdattr.push({label:o,get:t=>t[o]})}}function yt(t,e){const s=new Set(["__x","mname","aapos","chr","class","dt","inframe","origin","pos","rnapos","strand","useNterm","pairlst"]);t.svattr=[];for(const o of e){if(o.sample){t.svattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.svattr.push({label:"Genomic breakpoint",get:t=>{if(!t.pairlst)return"no pairlst";const e=t.pairlst.map((t=>(t.a.name?"<strong>"+t.a.name+"</strong> ":"")+(t.a.chr?'<span style="color:#858585">'+t.a.chr+":"+(t.a.position+1)+" "+(t.a.strand=="+"?"forward":"reverse")+"</span> &#10140; ":"")+(t.b.name?"<strong>"+t.b.name+"</strong> ":"")+(t.b.chr?'<span style="color:#858585">'+t.b.chr+":"+(t.b.position+1)+" "+(t.b.strand=="+"?"forward":"reverse")+"</span>":"")));return e.join("<br>")}});for(const s of e){if(s.pairlst[0].a.rnaposition!=undefined){t.svattr.push({label:"RNA breakpoint",get:t=>{if(!t.pairlst)return"no pairlst";const e=t.pairlst.map((t=>(t.a.name?"<strong>"+t.a.name+"</strong> ":"")+'<span style="color:#858585">r.'+(t.a.rnaposition+1)+"</span> &#10140; "+(t.b.name?"<strong>"+t.b.name+"</strong> ":"")+'<span style="color:#858585">r.'+(t.b.rnaposition+1)+"</span>"));return e.join("<br>")}});break}}for(const o of e){if(o.pmid){t.svattr.push(xt());s.add("pmid");break}}let o=false;for(const s of e){if(o)break;for(const e of s.pairlst){if(e.translocationname){t.svattr.push({get:t=>t.pairlst.map((t=>t.translocationname?t.translocationname:"")).join("_"),label:"Translocation name"});o=true;break}}}if(e[0].pairlst[0].a.ratio!=undefined){t.svattr.push({label:"Chimeric reads ratio",get:t=>{const e=[];const s=40,o=12,a="#FF850A",n="#FFCF9E";for(const r of t.pairlst){e.push((r.a.name?r.a.name:r.a.chr)+" <svg width="+s+" height="+o+"><g><title>"+r.a.ratio+"</title><rect width="+s+" height="+o+' fill="'+n+'"></rect>'+"<rect width="+s*r.a.ratio+" height="+o+' fill="'+a+'"></rect>'+"</g></svg>"+"&nbsp;&nbsp;"+(r.b.name?r.b.name:r.b.chr)+" <svg width="+s+" height="+o+"><g><title>"+r.b.ratio+"</title><rect width="+s+" height="+o+' fill="'+n+'"></rect>'+"<rect width="+s*r.b.ratio+" height="+o+' fill="'+a+'"></rect>'+"</g></svg>")}return e.join("<br>")}})}t.svattr.push({label:"Frame",get:t=>{function e(t){if(t==0)return'<span style="white-space:nowrap;background-color:'+k+';font-size:80%;color:white;padding:1px 3px">OUT of frame</span>';if(t==1)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span>';if(t==2)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span> <span style="font-size:80%;color:#858585">promoter fusion</span>';if(t==3)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span> <span style="font-size:80%;color:#858585">alternative promoter</span>';return"err ("+t+")"}const s=[];for(const e of t.pairlst){if(e.frame!=undefined){s.push({frame:e.frame,a:e.a.name?e.a.name:e.a.chr,b:e.b.name?e.b.name:e.b.chr})}}if(s.length==1)return e(s[0].frame);return s.map((t=>t.a+"-"+t.b+": "+e(t.frame))).join("<br>")}});if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.svattr.push({label:e.label||e.k,hide:e.hide,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.svattr.push({label:o,get:t=>t[o]})}}function xt(t){return{get:t=>{if(!t.pmid){return""}if(typeof t.pmid=="number"){return"<a target=_blank href=https://pubmed.ncbi.nlm.nih.gov/"+t.pmid+">"+t.pmid+"</a>"}const e=t.pmid.split(",");const s=[];for(const t of e){if(t=="")continue;const e=Number.parseInt(t);if(Number.isNaN(e)){s.push(t)}else{s.push("<a target=_blank href=https://pubmed.ncbi.nlm.nih.gov/"+t+">"+t+"</a>")}}return s.join(" ")},label:"PubMed"}}function kt(t,e,s){let o=t.sampledata;if(s.ds&&s.ds.cohort&&s.ds.cohort.annotation&&s.ds.cohort.key4annotation&&s.ds.cohort.sampleattribute&&s.ds.cohort.sampleattribute.runtimelst){o=[];for(const e of t.sampledata){const t=e.sampleobj[s.ds.cohort.key4annotation];if(!t)continue;const a=s.ds.cohort.annotation[t];if(a){let t=false;for(const e of s.ds.cohort.sampleattribute.runtimelst){if(e.key&&e.key.k&&e.key.hiddenvalues&&e.key.hiddenvalues.size){const s=a[e.key.k];if(e.key.hiddenvalues.has(s)){t=true;break}}}if(t)continue}o.push(e)}}e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text(o.length+" sample"+(o.length>1?"s":"")).on("click",(t=>{s.tktip.showunder(t.target).clear();const e=s.tktip.d.append("table");const a=e.append("tr").style("font-size",".8em").style("color","#858585");a.append("td").text("Name");a.append("td").text("Genotype");let n=false;if(o[0].DP!=undefined){a.append("td").text("Read depth");n=true}let r=false;if(o[0].allele2readcount){a.append("td").text("Allele read count");r=true}for(const t of o){const s=e.append("tr");s.append("td").text(t.sampleobj.name);s.append("td").style("padding-left","10px").text(t.genotype);if(n){s.append("td").style("padding-left","10px").text(t.DP||"")}if(r){const e=[];for(const s in t.allele2readcount){e.push(s+":"+t.allele2readcount[s])}s.append("td").style("padding-left","10px").text(e.join(", "))}}}))}function vt(t,e,s,o){e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("VEP annotation").on("click",(e=>{s.tktip.clear();s.tktip.showunder(e.target);for(const e of t){let t=false;let a;{const t=[];if(e.HGVSp){t.push('<span style="font-size:.7em;color:#858585">HGVSp</span> '+e.HGVSp)}else if(e.HGVSc){t.push('<span style="font-size:.7em;color:#858585">HGVSc</span> '+e.HGVSc)}else{t.push("no_HGVS")}if(e.Consequence){t.push('<span style="font-size:.7em;color:#858585">CONSEQUENCE</span> '+e.Consequence)}else{t.push("no_consequence")}a=t.join(" ")}const n=s.tktip.d.append("div").attr("class","sja_menuoption").style("margin","5px").html(a).on("click",(()=>{if(t){t=false;n.html(a)}else{t=true;n.text("");const s=[];for(const t of o){const o=e[t.name];if(o){s.push({k:t.name,v:o})}}d(n,s)}}))}}))}function wt(t,e,s,o){e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("Annotation").on("click",(e=>{s.tktip.clear();s.tktip.showunder(e.target);for(const e of t){let t=false;let a;{const t=[];if(e["HGVS.p"]){t.push('<span style="font-size:.7em;color:#858585">HGVS.p</span> '+e["HGVS.p"])}else if(e["HGVS.c"]){t.push('<span style="font-size:.7em;color:#858585">HGVS.c</span> '+e["HGVS.c"])}else{t.push("no_HGVS")}if(e.Annotation){t.push('<span style="font-size:.7em;color:#858585">Annotation</span> '+e.Annotation)}else{t.push("no_annotation")}a=t.join(" ")}const n=s.tktip.d.append("div").attr("class","sja_menuoption").style("margin","5px").html(a).on("click",(()=>{if(t){t=false;n.html(a)}else{t=true;n.text("");const s=[];for(const t of o){const o=e[t.name];if(o){s.push({k:t.name,v:o})}}d(n,s)}}))}}))}function _t(t,e,s,o,a){let n=false;e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("Image").on("click",(async()=>{if(n)return;n=true;const e=s.append("div").style("margin","20px").text("Loading...");try{const a=await b("img",{file:[o.variant2img.path,t.chr+"."+(t.pos+1)+"."+t.ref+"."+t.alt+"."+o.variant2img.ext].join("/")});if(a.error)throw a.error;e.remove();s.append("img").attr("src",a.src).style("width",a.size.width+"px").style("height",a.size.height+"px")}catch(t){e.text("Error loading image")}}))}function jt(t,e,s){if(!e.ds.vaf2coverageplot){return false}if(!t.sampledata){return false}const o=[];const a={};const n=new Map;let r=0;for(const s of t.sampledata){if(!s.allele2readcount){r++;continue}if(s.DP==undefined){s.DP=0;for(const t in s.allele2readcount){s.DP+=s.allele2readcount[t]}}const i=s.allele2readcount[t.alt]||0;if(i>s.DP){console.log("alt coverage > DP: "+i+" "+s.DP);continue}const l={sampleobj:{},mut:i,total:s.DP,maf:s.DP==0?0:i/s.DP,genotype:s.genotype};if(s.sampleobj){if(e.ds.cohort&&e.ds.cohort.annotation&&e.ds.cohort.key4annotation){const t=s.sampleobj[e.ds.cohort.key4annotation];if(t){const s=e.ds.cohort.annotation[t];if(s){if(e.ds.cohort.levels){for(const t of e.ds.cohort.levels){if(!s[t.k])continue;l.sampleobj[t.label||t.k]=s[t.k]+(t.full&&s[t.full]?' <span style="font-size:.8em;color:#858585">'+s[t.full]+"</span>":"")}l.sampleobj[e.ds.cohort.key4annotation]=t}else{for(const t in s){l.sampleobj[t]=s[t]}}}}}else{for(const t in s.sampleobj){l.sampleobj[t]=s.sampleobj[t]}}}if(e.ds.vaf2coverageplot.categorykey&&e.ds.vaf2coverageplot.categories){const t=l.sampleobj[e.ds.vaf2coverageplot.categorykey];if(t&&e.ds.vaf2coverageplot.categories[t]){l.color=e.ds.vaf2coverageplot.categories[t].color;if(!n.has(t)){n.set(t,0)}n.set(t,n.get(t)+1);delete l.sampleobj[e.ds.vaf2coverageplot.categorykey];l.sampleobj[e.ds.vaf2coverageplot.categorylabel]=t}}if(e.ds.vaf2coverageplot.samplegroupkey){if(l.sampleobj&&l.sampleobj[e.ds.vaf2coverageplot.samplegroupkey]){const t=l.sampleobj[e.ds.vaf2coverageplot.samplegroupkey];if(!a[t]){a[t]=[]}a[t].push(l)}else{o.push(l)}}else{o.push(l)}}if(r){console.log("skipped "+r+" items")}const i=[];if(o.length){i.push({name:"no "+(e.ds.vaf2coverageplot.samplegroupkey||"sampletype"),lst:o})}for(const t in a){i.push({name:t,lst:a[t]})}if(i.length==0){return false}if(n.size>0){const t=s.append("div").style("margin","20px 20px 0px 20px");for(const[s,o]of n){const o=e.ds.vaf2coverageplot.categories[s];const a=t.append("div").style("margin-bottom","3px");a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("margin-right","5px").style("background-color",o.color).html("&nbsp;&nbsp;");a.append("span").style("color",o.color).text(o.label||s)}}const l=s.append("div").style("margin-bottom","10px");import("./plot.vaf2cov-b2284c64.js").then((t=>{const s={};for(const o of i){let a=l.append("div").style("display","inline-block").style("vertical-align","top");if(i.length>1){a.style("margin-right","30px").append("div").style("margin-top","10px").style("padding","3px 10px").style("background-color","#aaa").style("color","white").style("display","inline-block").style("font-size",".8em").style("font-weight","bold").text(o.name.toUpperCase());a=a.append("div").style("border","solid 1px #aaa")}const n={holder:a,data:o.lst,name:o.name,tip:e.tktip,automax:true,mouseover:t=>{if(!t.sampleobj)return;for(const e in s){if(e==o.name)continue;s[e].filter((e=>e.sampleobj.patient==t.sampleobj.patient)).each((t=>{t.crosshair1.attr("transform","scale(2.5)");t.crosshair2.attr("transform","scale(2.5)")}))}},mouseout:t=>{if(!t.sampleobj)return;for(const e in s){if(e==o.name)continue;s[e].filter((e=>e.sampleobj.patient==t.sampleobj.patient)).each((t=>{t.crosshair1.attr("transform","scale(1)");t.crosshair2.attr("transform","scale(1)")}))}}};s[o.name]=t.default(n)}}));return true}function Mt(t,e,s){const o=e.ds.vcfcohorttrack;return Promise.resolve().then((()=>{if(o.info){return null}const t={jwt:s.jwt,file:o.file,url:o.url,indexURL:o.indexURL,header:1};return fetch(new Request(s.hostURL+"/vcf",{method:"POST",body:JSON.stringify(t)})).then((t=>t.json()))})).then((t=>{if(t==null)return;if(!t.metastr)throw{message:"no meta lines for the cohort vcf file "};if(!t.chrstr)throw{message:"no chromosome names found for the cohort vcf file"};const[e,a,n,r]=X(t.metastr.split("\n"));if(r)throw{message:"vcf meta error for the cohort vcf file: "+r.join("; ")};o.info=e;o.format=a;if(o.samplenamemap){o.samples=n.map(o.samplenamemap)}else{o.samples=n}o.nochr=y(s.genome,t.chrstr.split("\n"));return})).then((()=>{const e={jwt:s.jwt,file:o.file,url:o.url,indexURL:o.indexURL,rglst:[{chr:o.nochr?t.chr.replace("chr",""):t.chr,start:t.pos+1,stop:t.pos+1}]};return fetch(new Request(s.hostURL+"/vcf",{method:"POST",body:JSON.stringify(e)})).then((t=>t.json())).then((e=>{if(e.error)throw{message:"Error querying vcf file: "+e.error};const s=e.linestr?e.linestr.trim().split("\n"):[];for(const e of s){const[s,a,n]=Y(e,o);for(const e of a){if(e.pos==t.pos&&e.ref==t.ref&&e.alt==t.alt){return e}}}return null}))}))}function At(t,e,s){for(const o of s){if(!o.makeurl)continue;const s=o.makeurl(e);if(!s){continue}t.append("a").attr("href",s).attr("target","_blank").text(o.makelabel?o.makelabel(e):o.label||"link").style("margin-right","10px")}}function zt(t,e,s){s.forEach((s=>{if(!s.makebutton)return;const o=t.append("div").style("display","inline-block").style("margin","0px 10px 2px 3px");s.makebutton(e,o.node())}))}function Nt(t,e,s){const o=e.ds.germline2dvafplot;if(!o)return false;const a=o.individualkey;const n=new Map;let r=0;for(const e of t.sampledata){if(e.DP==undefined||!e.allele2readcount){r++;continue}const s=e.allele2readcount[t.alt]||0;if(s>e.DP){console.log("alt coverage > DP: "+s+" "+e.DP);continue}const i=e.sampleobj[a];if(!i){continue}const l=e.sampleobj[o.sampletypekey];if(!l){continue}if(!n.has(i)){const t={sampletypes:{}};for(const s in e.sampleobj){t[s]=e.sampleobj[s]}n.set(i,t)}n.get(i).sampletypes[l]={total:e.DP,vaf:e.DP==0?0:s/e.DP}}if(r){console.log(r+" samples has no valid DP/allele2readcount")}const i=[];for(const[t,e]of n){if(!e.sampletypes[o.xsampletype]){continue}if(e.sampletypes[o.yleftsampletype]){const t={};for(const s in e){t[s]=e[s]}t.sampletypes={};t.sampletypes[o.xsampletype]=e.sampletypes[o.xsampletype];t.sampletypes[o.yleftsampletype]=e.sampletypes[o.yleftsampletype];i.push(t)}if(o.yrightsampletype&&e.sampletypes[o.yrightsampletype]){const t={};for(const s in e){t[s]=e[s]}t.sampletypes={};t.sampletypes[o.xsampletype]=e.sampletypes[o.xsampletype];t.sampletypes[o.yrightsampletype]=e.sampletypes[o.yrightsampletype];i.push(t)}}if(i.length){const t=s.append("div").style("display","inline-block");import("./plot.2dvaf-18a35e4b.js").then((e=>{e.default(i,o,t)}));return true}return false}function Pt(t,e,s){const o=e.ds.genotype2boxplot;if(!o)return false;if(o.boxplotvaluekey){const e=t.info[o.boxplotvaluekey];if(!e)return false;const a=e.split("|");const n=[];for(const t of a){const e=t.split("/");const s=Number.parseFloat(e[1]);const o=Number.parseFloat(e[2]);const a=Number.parseFloat(e[3]);const r=Number.parseFloat(e[4]);const i=Number.parseFloat(e[5]);if(Number.isNaN(s)||Number.isNaN(o)||Number.isNaN(a)||Number.isNaN(r)||Number.isNaN(i)){continue}n.push({label:e[0],color:"#4F8F38",minvalue:s,maxvalue:i,percentile:{p05:s,p25:o,p50:a,p75:r,p95:i}})}const r=s.append("div").style("display","inline-block");import("./plot.boxplot-fe3046c6.js").then((t=>{const e=t.default({holder:r,axislabel:o.axislabel,list:n});if(e){x(r,"Boxplot: "+e)}}));return true}if(!e.ds.cohort||!e.ds.cohort.annotation||!e.ds.cohort.key4annotation){console.log("genotype2boxplot but ds.cohort is incomplete");return false}const a=new Map;t.sampledata.forEach((t=>{if(!t.genotype)return;const s=t.sampleobj[e.ds.cohort.key4annotation];if(!s)return;const n=e.ds.cohort.annotation[s];if(!n)return;const r=n[o.sampleannotationkey];if(!Number.isFinite(r))return;if(!a.has(t.genotype)){a.set(t.genotype,[])}a.get(t.genotype).push({value:r,key:s})}));if(a.size==0){return false}const n=[];for(const[t,e]of a){n.push({label:t,color:"#4F8F38",samples:e})}const r=s.append("div").style("display","inline-block");import("./plot.boxplot-fe3046c6.js").then((t=>{const e=t.default({holder:r,axislabel:o.axislabel,list:n});if(e){x(r,"Boxplot: "+e)}}));return true}function St(t,e,s){const o=t.sampledata[0];const a=[];if(o.genotype){a.push({k:"genotype",v:o.genotype})}if(o.DP!=undefined){a.push({k:"total reads",v:o.DP})}if(o.allele2readcount&&o.allele2readcount[t.alt]!=undefined){a.push({k:"alt reads",v:o.allele2readcount[t.alt]})}else{Ct(a,t,e)}if(o.sampleobj){if(e.ds.cohort&&e.ds.cohort.annotation&&e.ds.cohort.key4annotation){const t=o.sampleobj[e.ds.cohort.key4annotation];if(t){a.push({k:e.ds.cohort.key4annotation,v:t});const s=e.ds.cohort.annotation[t];if(s){if(e.ds.cohort.levels){for(const t of e.ds.cohort.levels){if(!s[t.k])continue;a.push({k:t.label||t.k,v:s[t.k]+(t.full&&s[t.full]?' <span style="font-size:.8em;color:#858585">'+s[t.full]+"</span>":"")})}}else{for(const t in s){if(t=="color")continue;a.push({k:t,v:s[t]})}}}}}else if(o.sampleobj.name){a.push({k:"name",v:o.sampleobj.name})}}d(s,a)}function Ct(t,e,s){let o;if(e.vcfid&&s.ds&&s.ds.id2vcf)o=s.ds.id2vcf[e.vcfid];if(!o)return;if(!o.format)return;const a=e.sampledata[0];for(const s in o.format){const n=o.format[s];if(!(s in a))continue;let r=n.Number=="R"||n.Number=="A";if(!r){if(s=="AD"){r=true}}if(r){const o=[];const r=[];let i;for(const t in a[s]){if(t==e.ref)continue;o.push(t);i=a[s][t];r.push(i)}const l=a[s][e.ref];if(l!=undefined){o.push(e.ref);r.push(l)}let c;if(l+i>0){c=g(null,{f:i/(i+l)})}t.push({k:s,v:(c?c+" ":"")+'<span style="font-size:.8em;opacity:.5">'+o.join(" / ")+"</span> "+r.join(" / ")+(n.Description?' <span style="font-size:.7em;opacity:.5">'+n.Description+"</span>":"")})}else{t.push({k:s,v:a[s]})}}}function Ft(t,e,s,o){if(!o.samplecart||!s.ds||!s.ds.sampleselectable)return;const a=new Set;for(const e of t){if(e.sample){a.add(e.sample)}}if(a.size==0){return}const n=new Set;for(const e of t){const t=f[e.class].label;let s;if(e.dt==i||e.dt==l){if(e.mname){if(e.useNterm){s=(o.usegm?o.usegm.name+"-":"")+e.mname+" "+t}else{s=e.mname+(o.usegm?"-"+o.usegm.name:"")+" "+t}}else{s=(o.usegm?o.usegm.name:"")+" "+t}}else{s=(e.mname?e.mname+" ":"")+t+(o.usegm?" in "+o.usegm.name:"")}n.add(s)}if(n.size==1){"having "+[...n][0]}else{"having mutations"+(o.usegm?" in "+o.usegm.name:"")}o.samplecart.setBtns({samplelst:[...a],id:n.size?[...n][0]:o.usegm?o.usegm.name:"",basket:"Gene Mutation",container:e.append("div").style("margin-left","10px").append("div")})}function Rt(t,e){let s=null;for(const t in e.ds.id2vcf){s=e.ds.id2vcf[t]}if(!s){t.tkcloakoff(e,{error:"no vcf config found"});return}Promise.resolve().then((()=>{if(!s.headernotloaded)return;delete s.headernotloaded;const o=["genome="+t.genome.name];if(s.file){o.push("file="+s.file)}else{o.push("url="+s.url);if(s.indexURL)o.push("indexURL="+s.indexURL)}return w("vcfheader?"+o.join("&")).then((t=>{if(t.error)throw{message:t.error};if(!t.metastr)throw{message:"no meta lines for vcf file "+e.name};const[o,a,n,r]=X(t.metastr.split("\n"));if(r)throw{error:"vcf meta error for file "+e.name+": "+r.join("; ")};s.info=o;s.format=a;if(s.samplenamemap){s.samples=n.map(s.samplenamemap)}else{s.samples=n}s.nochr=t.nochr}))})).then((()=>{const o={file:s.file,url:s.url,indexURL:s.indexURL,rglst:t.tkarg_maygm(e)};if(s.nochr){for(const t of o.rglst){t.chr=t.chr.replace("chr","")}}return w("vcf",{method:"POST",body:JSON.stringify(o)}).then((o=>{if(o.error)throw{message:o.error};const a=o.linestr?o.linestr.trim().split("\n"):[];ce([{vcfid:s.vcfid,lines:a}],t,e);return}))})).catch((t=>{if(t.stack)console.log(t.stack);return t.message})).then((s=>{t.tkcloakoff(e,{error:s})}))}function It(t,e,s){const o=e.ds.id2vcf[t.vcfid];if(!o){s.error("vcf not found by id: "+t.vcfid);return}if(!t.lines){s.error("no vcf lines from vcf file "+t.vcfid);return}const a=[];for(const n of t.lines){const[r,i,l]=Y(n,o);if(r){a.push(r)}if(!i){continue}for(const o of i){if(o.alt=="NON_REF"){continue}if(e.ds.discardsymbolicallele&&o.issymbolicallele){continue}if(s.usegm){const t=_(o.pos,s.usegm);o.rnapos=t.rnapos;o.aapos=t.aapos}o.vcfid=t.vcfid;j(o,s);e.mlst.push(o)}}if(!e.dstk_novcferror&&a.length){s.error(a[0]+(a.length==1?"":" and "+(a.length-1)+" more errors with the VCF track"))}}function Bt(t,e,s){if(!s.cohort){console.error("arg.cohort missing");return}if(!s.cohort.levels){console.error("arg.cohort.levels missing");return}if(!s.cohort.key2color&&!s.cohort.suncolor){s.cohort.suncolor=M(A)}let o;if(!s.cohort.annotation){o=s.mlst}else{if(!s.cohort.key4annotation){console.error("arg.cohort.key4annotation missing");return}o=[];if(s.mlst[0].sampledata){for(const t of s.mlst){if(!t.sampledata){continue}for(const e of t.sampledata){const t=e.sampleobj[s.cohort.key4annotation];if(!t){continue}const a=s.cohort.annotation[t];if(!a){continue}const n={k4a:t};for(const t of s.cohort.levels){n[t.k]=a[t.k];if(t.full){n[t.full]=a[t.full]}}o.push(n)}}}else{for(const t of s.mlst){const e=t[s.cohort.key4annotation];if(!e){continue}const a=s.cohort.annotation[e];if(!a){continue}const n={k4a:e};for(const t of s.cohort.levels){n[t.k]=a[t.k];if(t.full){n[t.full]=a[t.full]}}o.push(n)}}if(o.length==0){if(s.m2detail){$({mlst:[s.m2detail],pane:true,x:s.cx,y:s.cy,tk:t,block:e})}else{$({mlst:s.mlst,pane:true,x:s.cx,y:s.cy,tk:t,block:e})}return}}let a=s.cx,n=s.cy,r=500,i=250;const l=t.glider.append("g").attr("transform","translate("+a+","+n+")");const c=t.pica;const f=l.append("g");const d=l.append("g");const p={g:l,eye:f,ring:d,pica:c,busy:false};let u=Math.log(o.length)*24;if(u>t.height*.42){u=t.height*.42}else if(u<t.height*.2){u=t.height*.2}let m=a,h=n;if(a-u<0){m=u}else if(a+u>e.width){m=e.width-u}if(n-u<0){h=u}else if(n+u>t.height){h=t.height-u}if(m!=a||h!=n){l.transition().delay(r+i).attr("transform","translate("+m+","+h+")");a=m;n=h}const g=z(o,s.cohort.levels);const b=N()(g);b.sum((t=>t.value));b.sort(((t,e)=>e.value-t.value));J().size([1,Math.pow(u,2)])(b);f.append("circle").attr("r",u).attr("fill","white").attr("fill-opacity",0);let y;const x=Q().startAngle((t=>Math.PI*2*t.x0)).endAngle((t=>Math.PI*2*t.x1)).innerRadius((t=>{if(!t.parent){y=Math.sqrt(t.y1)-u/15;return y}return Math.sqrt(t.y0)})).outerRadius((t=>{t.outradius=Math.sqrt(t.y1);return t.outradius}));d.selectAll().data(b.descendants()).enter().append("path").attr("d",x).attr("stroke","white").attr("fill",(t=>{if(!t.parent){return"white"}let e;if(t.children){e=t.id}else{if(!t.parent.parent){e=t.id}else{e=t.parent.id}}let o;if(s.cohort.key2color){o=s.cohort.key2color[e];if(!o){console.log(e);o="#858585"}}else{o=s.cohort.suncolor(e)}t._color=o;return o})).on("mouseover",((o,r)=>{if(!r.parent)return;if(p.busy)return;o.target.setAttribute("fill",P(r._color).darker(.5).toString());Dt(r,c,s,a,n,t,e)})).on("mouseout",((t,e)=>{c.g.selectAll("*").remove();if(!e.parent)return;t.target.setAttribute("fill",e._color)})).on("click",((o,a)=>{if(s.noclickring){return}if(!a.parent){return}if(s.cohort.annotation){if(a.data.lst.length==1){Lt(a.data.lst[0].k4a,s.cohort.annotation[a.data.lst[0].k4a],o.clientX,o.clientY);return}Et(a.data.lst,s.cohort,o.clientX,o.clientY);return}$({mlst:a.data.lst,x:o.clientX,y:o.clientY,tk:t,block:e,pane:true})}));const k=y*2;d.attr("transform","scale(.3,.3)").attr("fill-opacity",0).transition().duration(r).attr("transform","scale(1,1)").attr("fill-opacity",1).on("end",(()=>{f.shutter=f.append("rect").attr("x",-y).attr("y",-y).attr("width",y*2).attr("height",0).attr("fill","#ededed").on("click",(()=>qt(p)));f.shutter.transition().duration(i).attr("height",y*2).on("end",(()=>{f.fore=f.append("g");const r=Math.min(k/(s.label.length*S),y*.6);f.fore.append("text").text(s.label).attr("text-anchor","middle").attr("dominant-baseline","central").attr("fill","#858585").attr("font-weight","bold").attr("font-family","Arial").attr("font-size",r);const i=Math.min(18,Math.min(y*.7/(o.length.toString().length*S),(y-r/2)*.7));f.fore.append("text").text(o.length).attr("text-anchor","middle").attr("fill","#858585").attr("y",-r/2-2).attr("font-family","Arial").attr("font-size",i);f.append("rect").attr("x",-y).attr("y",-y).attr("width",y*2).attr("height",y*2).attr("fill","black").attr("fill-opacity",0).on("click",(()=>{if(p.busy)return;qt(p)})).on("mousedown",(t=>{t.preventDefault();t.stopPropagation();let e=a,s=n,o=t.clientX,r=t.clientY,i=C(document.body);i.on("mousemove",(t=>{p.busy=true;a=e+t.clientX-o;n=s+t.clientY-r;l.attr("transform","translate("+a+","+n+")")})).on("mouseup",(()=>{setTimeout((()=>p.busy=false),10);i.on("mousemove",null).on("mouseup",null)}))}));p.listbutt=f.append("g").attr("transform","translate(0,"+r/2+")");const c=p.listbutt.append("rect").attr("x",-k/2).attr("width",k).attr("height",y-r/2).attr("fill","#d9d9d9");const d=p.listbutt.append("text").text(s.m2detail?"Show":"List").attr("y",(y-r/2)/2).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-family","Arial").attr("fill","#858585").attr("font-size",Math.min(18,i));p.listbutt.append("rect").attr("x",-k/2).attr("width",k).attr("height",y-r/2).attr("fill-opacity",0).on("mouseover",(()=>{c.attr("fill","#bababa");d.attr("fill","white")})).on("mouseout",(()=>{c.attr("fill","#d9d9d9");d.attr("fill","#858585")})).on("click",(o=>{if(s.m2detail){qt(p);$({mlst:[s.m2detail],pane:true,x:o.clientX-u,y:o.clientY-u*2,tk:t,block:e});return}const a=o.target.getBoundingClientRect();qt(p);setTimeout((()=>$({mlst:s.mlst,x:a.left,y:a.top,tk:t,block:e,pane:true})),500)}))}))}))}function qt(t){t.busy=true;if(t.eye.fore){t.eye.fore.remove()}if(t.listbutt){t.listbutt.remove()}if(t.eye.shutter){t.eye.shutter.transition().attr("height",0).on("end",(()=>{t.ring.transition().attr("transform","scale(.5,.5)").attr("fill-opacity",0).on("end",(()=>{t.g.remove();t.pica.g.selectAll("*").remove()}))}))}else{t.ring.transition().attr("transform","scale(.5,.5)").attr("fill-opacity",0).on("end",(()=>{t.g.remove();t.pica.g.selectAll("*").remove()}))}t.pica.g.selectAll("*").remove()}function Dt(t,e,s,o,a,n,r){const i=s.cohort;const l=13;const c=10;const f=1;let d=(t.x0+t.x1)/2;if(d>=.375&&d<=.625){const e=n.yoff+a+t.outradius;const s=Number.parseFloat(r.svg.attr("height"));l+f+l+(i&&i.root?f+c+5:0);if(e>=s-30){if(d<=.5){d=Math.max(.25,t.x0)}else{d=Math.min(.75,t.x1)}}}e.g.selectAll("*").remove();const p=o+(t.outradius+5)*Math.sin(Math.PI*2*d);const u=a-(t.outradius+5)*Math.cos(Math.PI*2*d);e.g.attr("transform","translate("+p+","+u+")");const m=60;let h=null,g=0;if(i&&i.root){h=e.g.append("g");h.append("rect").attr("width",m+4).attr("height",c+4).attr("fill","white").attr("shape-rendering","crispEdges");h.append("rect").attr("x",2).attr("y",2).attr("width",m).attr("height",c).attr("fill",i.fbarbg||"#ededed").attr("shape-rendering","crispEdges");i.root.each((e=>{if(e.id==t.id){g=e.value}}));if(g>0){h.append("rect").attr("x",2).attr("y",2).attr("width",m*t.value/g).attr("height",c).attr("fill",i.fbarfg||"#858585").attr("shape-rendering","crispEdges")}}const b=e.g.append("text").attr("stroke","white").attr("stroke-width",3).attr("font-size",l).attr("font-family","Arial");const y=e.g.append("text").attr("fill","black").attr("fill-opacity",1).attr("font-size",l).attr("font-family","Arial");t.data.name+", "+t.value+" sample"+(t.value>1?"s":"");b.text(t.data.name);y.text(t.data.name);const x=e.g.append("text").attr("stroke","white").attr("stroke-width",3).attr("font-size",l).attr("font-family","Arial");const k=e.g.append("text").attr("fill","black").attr("fill-opacity",1).attr("font-size",l).attr("font-family","Arial");const v=t.value+" sample"+(t.value>1?"s":"")+(h?" ("+g+" total)":"");x.text(v);k.text(v);Math.max(y.node().getBBox().width,k.node().getBBox().width);if(d<.25){x.attr("y",h?-3-c-f:0);k.attr("y",h?-3-c-f:0);b.attr("y",(h?-3-c-f:0)-l-f);y.attr("y",(h?-3-c-f:0)-l-f);if(h){h.attr("transform","translate(0,-"+c+")")}}else if(d<.5){b.attr("dominant-baseline","hanging").attr("y",0);y.attr("dominant-baseline","hanging").attr("y",0);x.attr("dominant-baseline","hanging").attr("y",f+l);k.attr("dominant-baseline","hanging").attr("y",f+l);if(h){h.attr("transform","translate(0,"+(l+f)*2+")")}}else if(d<.75){b.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",0);y.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",0);x.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",f+l);k.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",f+l);if(h){h.attr("transform","translate(-"+m+","+(l+f)*2+")")}}else{x.attr("text-anchor","end").attr("y",h?-3-c-f:0);k.attr("text-anchor","end").attr("y",h?-3-c-f:0);b.attr("text-anchor","end").attr("y",(h?-3-c-f:0)-l-f);y.attr("text-anchor","end").attr("y",(h?-3-c-f:0)-l-f);if(h){h.attr("transform","translate(-"+m+",-"+c+")")}}}function Lt(e,s,o,a){const n=[];for(const t in s){n.push({k:t,v:s[t]})}const r=t({x:o,y:a});r.header.text(e);d(r.body,n)}function Et(e,s,o,a){const n=new Set;for(const t of e){const e=s.annotation[t.k4a];for(const t in e){n.add(t)}}const r=t({x:o,y:a});r.header.text(e.length+" "+s.key4annotation+"s");const i=r.body.append("table");const l=[...n];{const t=i.append("tr");for(const e of l){t.append("td").text(e).style("color","#858585").style("font-size",".7em")}}for(const t of e){const e=i.append("tr").attr("class","sja_tr");const o=s.annotation[t.k4a];for(const t of l){e.append("td").text(o[t]==undefined?"":o[t])}}}async function Ut(t,e,s,o,a,n){if(a.ds){if(a.ds.cohort){let t=false;if(a.ds.cohort.annotation){if(a.ds.cohort.variantsunburst){t=true}}else{t=true}if(t){Bt(a,n,{cx:s,cy:o,mlst:e,label:e[0].mname,cohort:a.ds.cohort});return true}}}return false}const Gt=7;const Vt=t=>{if(!t)return"";if(t.length>25){return t.substr(0,20)+"..."}return t};function Ot(t,e,s){const o=t.numericmode;if(!o.axisheight){o.axisheight=100}t.glider.selectAll("*").remove();delete t.skewer;const a=qe(t,e,s);const n=new Map;for(const t of a){if(t.__x==undefined){continue}if(!n.has(t.__x)){n.set(t.__x,[])}n.get(t.__x).push(t)}const r=[];if(e.exonsf>=se){for(const[t,e]of n){r.push({chr:e[0].chr,pos:e[0].pos,mlst:e,x:t})}}else{if(e.usegm&&e.usegm.coding&&e.gmmode!=F.genomic){const t=new Map;for(const[s,o]of n){if(o[0].chr!=e.usegm.chr){continue}let a=undefined;for(const t of o){if(Number.isFinite(t.aapos))a=t.aapos}if(a==undefined){a=_(o[0].pos,e.usegm).aapos}if(a==undefined){console.error("data item cannot map to aaposition");console.log(o[0]);continue}n.delete(s);if(!t.has(a)){t.set(a,[])}let r=true;for(const s of t.get(a)){if(Math.abs(s[0].__x-o[0].__x)<=e.exonsf*3){for(const t of o){s.push(t)}r=false;break}}if(r){t.get(a).push(o)}}e.usegm.utr5?e.usegm.utr5.reduce(((t,e)=>t+e[1]-e[0]),0):0;for(const e of t.values()){for(const t of e){let e=null;for(const s of t){if(Number.isFinite(s.rnapos))e=s}if(e==null){console.log("trying to map mlst to codon, but no rnapos found");for(const e of t){console.log(e)}continue}r.push({chr:t[0].chr,pos:e.pos,mlst:t,x:t[0].__x})}}}const t=[];const s=2;for(const[e,o]of n){const a=Math.floor(e/s);if(!t[a]){t[a]=[]}t[a]=[...t[a],...o]}for(const e of t){if(!e)continue;const t=e.reduce(((t,e)=>t+e.__x),0);r.push({isbin:true,chr:e[0].chr,pos:e[0].pos,mlst:e,x:t/e.length})}}r.sort(((t,e)=>t.x-e.x));if(t.data&&e.pannedpx!=undefined&&(!e.usegm||e.gmmode==F.genomic)){const e={};for(const s of t.data){e[s.chr+"."+s.pos]={xoffset:s.xoffset}}for(const t of r){const s=t.chr+"."+t.pos;if(e[s]){t.xoffset=e[s].xoffset}}}t.data=r;Ht(t,e);t.height_main=t.toppad+o.toplabelheight+o.maxradius+o.axisheight+o.maxradius+t.stem1+t.stem2+t.stem3+o.bottomlabelheight+t.bottompad;if(!t.data||t.data.length==0){Le(t,e);return}}function Tt(t,e){if(e.vcfinfofilter&&e.vcfinfofilter.setidx4mclass!=undefined){const s=e.vcfinfofilter.lst[e.vcfinfofilter.setidx4mclass];const[o,a]=Se(s,t);if(o||a==undefined)return"black";for(const t of a){if(s.categories[t]){return s.categories[t].color}else{return"black"}}}if(f[t.class]){return f[t.class].color}return"black"}function Ht(t,e){const s=t.numericmode;const f=[];for(const e of t.data){e.x0=e.x;if(e.xoffset!=undefined){e.x=e.x0+e.xoffset}continue}let p=0;if(f.length>0){let t=1;for(let e=0;e<f.length;e++){const s=f[e];const o=[];for(let t=0;t<e;t++){const e=f[t];if(Math.max(s.aa,e.aa)<Math.min(s.pxspan+s.aa,e.pxspan+e.aa)){o.push(e)}}s.y=2;for(const e of o){if(Math.max(s.y,e.y)<Math.min(s.y+s.height,e.y+e.height)){s.y=e.y+e.height+t}}p=Math.max(p,s.y+s.height)}}const u=Math.max(14,e.width/110);s.dotwidth=u;s.maxradius=0;for(const e of t.data){for(const t of e.mlst){t.radius=u/2;s.maxradius=Math.max(t.radius,s.maxradius);t.rimwidth=0;t.aa=e}}const m=Zt(t,e);s.showsamplebar=m&&t.ds&&t.ds.samplebynumericvalue;if(!s.showsamplebar){s.showgenotypebyvalue=m&&t.ds&&t.ds.genotypebynumericvalue}t.genotype2color.legend.style("display",s.showsamplebar||s.showgenotypebyvalue?"block":"none");let h;let g=null;let b=null;let y=0;let x=null;if(s.showsamplebar){h={name:t.ds.samplebynumericvalue.axislabel};for(const e of t.data){for(const s of e.mlst){if(!s.sampledata)continue;for(const e of s.sampledata){const s=e.sampleobj[t.ds.cohort.key4annotation];if(!s)continue;const o=t.ds.cohort.annotation[s];if(!o)continue;const a=o[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(a))continue;if(g==null){g=a;b=a}else{g=Math.min(g,a);b=Math.max(b,a)}}}}}else if(s.showgenotypebyvalue){h={name:t.ds.genotypebynumericvalue.axislabel};for(const e of t.data){for(const s of e.mlst){let e=s.info[t.ds.genotypebynumericvalue.refref.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}e=s.info[t.ds.genotypebynumericvalue.refalt.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}e=s.info[t.ds.genotypebynumericvalue.altalt.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}let o=0,a=0,n=0;if(t.ds.genotypebynumericvalue.refref.genotypeCountInfokey){let e=s.info[t.ds.genotypebynumericvalue.refref.genotypeCountInfokey];if(Number.isFinite(e)){o=e}e=s.info[t.ds.genotypebynumericvalue.refalt.genotypeCountInfokey];if(Number.isFinite(e)){n=e}e=s.info[t.ds.genotypebynumericvalue.altalt.genotypeCountInfokey];if(Number.isFinite(e)){a=e}}else{if(!s.sampledata)continue;for(const t of s.sampledata){if(!t.allele2readcount)continue;if(t.allele2readcount[s.alt]){if(t.allele2readcount[s.ref]){n++}else{a++}}else{o++}}}y=Math.max(y,o,n,a)}}const e=Math.pow(12/2,2)*Math.PI;const s=e*10;x=R().domain([1,y*.1,y*.3,y*.6,y*.8,y]).range([e,e+(s-e)*.8,e+(s-e)*.85,e+(s-e)*.9,e+(s-e)*.95,s])}else{h=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4numeric];for(const e of t.data){for(const t of e.mlst){t._v=0;const[e,s]=Se(h,t);if(e){console.log(e)}else if(s==undefined||s.length==0);else{if(!Number.isFinite(s[0])){console.log("invalid numerical value for variant: "+s[0])}else{t._v=s[0]}}if(g==null){g=t._v;b=t._v}else{g=Math.min(t._v,g);b=Math.max(t._v,b)}}}}const k=R().domain([g,b]).range([0,s.axisheight]);for(const e of t.data){for(const t of e.mlst){t._y=k(t._v)}}if(m){t.stem1=5;t.stem2=20;t.stem3=10}else{t.stem1=0;t.stem2=0;t.stem3=0}for(const e of t.data){for(const s of e.mlst){t.glider.append("text").text(Vt(s.mname)).attr("font-family",I).attr("font-size",s.radius*2-2).each((function(){s.labwidth=this.getBBox().width})).remove()}}for(const e of t.data){for(const t of e.mlst){delete t.labattop;delete t.labatbottom}}if(m){for(const e of t.data){if(e.mlst.length==1){const t=e.mlst[0];t.labattop=true}else{if((e.width-e.fixedgew)/(e.mlst.length-1)<Gt);else{for(const t of e.mlst){t.labattop=true}}}}}else{Qt(t)}s.toplabelheight=0;s.bottomlabelheight=0;if(s.showsamplebar||s.showgenotypebyvalue){for(const e of t.data){for(const t of e.mlst){s.toplabelheight=Math.max(s.toplabelheight,t.labwidth)}}}else{for(const e of t.data){for(const t of e.mlst){if(t.labattop){s.toplabelheight=Math.max(s.toplabelheight,t._y+t.labwidth-s.axisheight)}else if(t.labatbottom){s.bottomlabelheight=Math.max(s.bottomlabelheight,t.labwidth-t._y)}}}}{let o=e.labelfontsize+t.labyspace+e.labelfontsize;if(t.label_stratify){o+=t.label_stratify.length*(t.labyspace+e.labelfontsize)}s.toplabelheight=Math.max(s.toplabelheight,o)}t.leftaxis.attr("transform","translate(-"+u/2+","+(s.toplabelheight+s.maxradius)+")").selectAll("*").remove();{const o=R().domain([g,b]).range([s.axisheight,0]);const a=W().scale(o).ticks(4);if(h.numberIsInteger){a.tickFormat(B("d"));if(b-g<3){a.ticks(b-g)}}q({axis:t.leftaxis.call(a),showline:true,fontsize:u});if(g==b){t.leftaxis.append("text").attr("text-anchor","end").attr("font-size",u).attr("dominant-baseline","central").attr("x",e.tkleftlabel_xshift).attr("y",s.axisheight).text(g).attr("fill","black")}{let e=0;t.leftaxis.selectAll("text").each((function(){e=Math.max(e,this.getBBox().width)}));const o=h.name.split(" ");const a=(s.axisheight-o.length*(u+1))/2;let n=0;o.forEach(((s,o)=>{t.leftaxis.append("text").attr("fill","black").attr("font-size",u).attr("dominant-baseline","central").attr("text-anchor","end").attr("y",a+(u+1)*o).attr("x",-(e+15)).text(s).each((function(){n=Math.max(n,this.getBBox().width+15+e)}))}));t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,n)}}const v=t.glider.append("g").attr("transform","translate(0,0)");v.append("line").attr("y1",s.toplabelheight+s.maxradius).attr("y2",s.toplabelheight+s.maxradius).attr("x2",e.width).attr("stroke","#ededed").attr("shape-rendering","crispEdges");v.append("line").attr("y1",s.toplabelheight+s.maxradius+s.axisheight).attr("y2",s.toplabelheight+s.maxradius+s.axisheight).attr("x2",e.width).attr("stroke","#ededed").attr("shape-rendering","crispEdges");t.skewer2=v.selectAll().data(t.data).enter().append("g").attr("class","sja_skg2").each((function(t){t.g=this}));t.skewer2.attr("transform",(t=>"translate("+t.x+","+(s.toplabelheight+ee+s.maxradius+s.axisheight+s.maxradius)+")"));if(m){t.skewer2.append("path").attr("class","sja_aa_stem").attr("d",(e=>Wt(e,t))).attr("stroke",(e=>Tt(e.mlst[0],t))).attr("fill",(t=>t.mlst.length==1?"none":"#ededed"))}const w=t.skewer2.selectAll().data((t=>t.mlst)).enter().append("g").attr("class","sja_aa_discg").each((function(t){t.g=this}));if(s.showsamplebar){w.attr("transform",(t=>"translate("+t.xoff+",0)"));for(const e of t.data){for(const o of e.mlst){if(!o.sampledata)continue;const e=C(o.g);for(const a of o.sampledata){const n=a.sampleobj[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(i))continue;const l=-k(i)-s.maxradius;const c=a.allele2readcount[o.ref];const f=a.allele2readcount[o.alt];if(f)continue;e.append("line").attr("x1",-o.radius).attr("x2",o.radius).attr("y1",l).attr("y2",l).attr("stroke",c?f?t.genotype2color.ra:t.genotype2color.rr:t.genotype2color.aa).attr("shape-rendering","crispEdges").on("mouseover",(e=>{const s=[{k:t.ds.cohort.key4annotation,v:n}];for(const t in r){s.push({k:t,v:r[t]})}s.push({k:"genotype",v:a.genotype});t.tktip.clear().show(e.clientX,e.clientY);d(t.tktip.d,s);e.target.setAttribute("stroke-width",3);e.target.setAttribute("x1",-o.radius-3);e.target.setAttribute("x2",o.radius+3)})).on("mouseout",(e=>{t.tktip.hide();e.target.setAttribute("stroke-width",1);e.target.setAttribute("x1",-o.radius);e.target.setAttribute("x2",o.radius)}))}for(const a of o.sampledata){const n=a.sampleobj[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(i))continue;const l=-k(i)-s.maxradius;const c=a.allele2readcount[o.ref];const f=a.allele2readcount[o.alt];if(!f)continue;e.append("line").attr("x1",-o.radius).attr("x2",o.radius).attr("y1",l).attr("y2",l).attr("stroke",c?f?t.genotype2color.ra:t.genotype2color.rr:t.genotype2color.aa).attr("shape-rendering","crispEdges").on("mouseover",(e=>{const s=[{k:t.ds.cohort.key4annotation,v:n}];for(const t in r){s.push({k:t,v:r[t]})}s.push({k:"genotype",v:a.genotype});t.tktip.clear().show(e.clientX,e.clientY);d(t.tktip.d,s);e.target.setAttribute("stroke-width",3);e.target.setAttribute("x1",-o.radius-3);e.target.setAttribute("x2",o.radius+3)})).on("mouseout",(e=>{t.tktip.hide();e.target.setAttribute("stroke-width",1);e.target.setAttribute("x1",-o.radius);e.target.setAttribute("x2",o.radius)}))}}}}else if(s.showgenotypebyvalue){w.attr("transform",(t=>"translate("+t.xoff+",0)"));for(const e of t.data){for(const o of e.mlst){let e=0,a=0,n=0;if(t.ds.genotypebynumericvalue.refref.genotypeCountInfokey){e=o.info[t.ds.genotypebynumericvalue.refref.genotypeCountInfokey];a=o.info[t.ds.genotypebynumericvalue.altalt.genotypeCountInfokey];n=o.info[t.ds.genotypebynumericvalue.refalt.genotypeCountInfokey]}else{if(!o.sampledata)continue;for(const t of o.sampledata){if(!t.allele2readcount)continue;if(t.allele2readcount[o.alt]){if(t.allele2readcount[o.ref]){n++}else{a++}}else{e++}}}const r=C(o.g);if(e){const a=o.info[t.ds.genotypebynumericvalue.refref.infokey];if(a!=undefined){const n=-k(a)-s.maxradius;r.append("circle").attr("cy",n).attr("r",Math.sqrt(x(e))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.refref.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const n=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Ref/Ref"},{k:"#sample",v:e},{k:t.ds.genotypebynumericvalue.axislabel,v:a}];d(t.tktip.d,n)})).on("mouseout",(()=>{t.tktip.hide()}))}}if(n){const e=o.info[t.ds.genotypebynumericvalue.refalt.infokey];if(e!=undefined){const a=-k(e)-s.maxradius;r.append("circle").attr("cy",a).attr("r",Math.sqrt(x(n))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.refalt.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const a=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Ref/Alt"},{k:"#sample",v:n},{k:t.ds.genotypebynumericvalue.axislabel,v:e}];d(t.tktip.d,a)})).on("mouseout",(()=>{t.tktip.hide()}))}}if(a){const e=o.info[t.ds.genotypebynumericvalue.altalt.infokey];if(e!=undefined){const n=-k(e)-s.maxradius;r.append("circle").attr("cy",n).attr("r",Math.sqrt(x(a))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.altalt.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const n=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Alt/Alt"},{k:"#sample",v:a},{k:t.ds.genotypebynumericvalue.axislabel,v:e}];d(t.tktip.d,n)})).on("mouseout",(()=>{t.tktip.hide()}))}}}}}else{w.attr("transform",(t=>"translate("+t.xoff+","+(t._y+s.maxradius)*-1+")"));const f=w.append("circle");f.filter((t=>t.dt==r||t.dt==o||t.dt==n||t.dt==a)).attr("fill","white").attr("stroke-width",2).attr("stroke",(e=>Tt(e,t))).attr("r",(t=>t.radius-2));f.filter((t=>t.dt==c||t.dt==l||t.dt==i)).attr("fill",(e=>Tt(e,t))).attr("stroke","white").attr("r",(t=>t.radius-.5));w.filter((t=>t.dt==i||t.dt==l)).append("path").attr("fill","white").attr("stroke","none").attr("d",(t=>Q()({innerRadius:0,outerRadius:t.radius-2,startAngle:t.useNterm?0:Math.PI,endAngle:t.useNterm?Math.PI:Math.PI*2})));w.append("circle").attr("r",(t=>t.radius-.5)).attr("stroke",(e=>Tt(e,t))).attr("class","sja_aa_disckick").attr("fill","white").attr("fill-opacity",0).attr("stroke-opacity",0).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>{Xt(s,t);if(t.disc_mouseover){t.disc_mouseover(s,e.target)}else{je(t,[s],true)}})).on("mouseout",((e,s)=>{Yt(s,t);if(t.disc_mouseout){t.disc_mouseout(s)}else{je(t,[s],false)}})).on("click",((s,o)=>{const a=s.target.getBoundingClientRect();Jt(o,a,t,e)}))}const _=w.filter((t=>t.labattop||t.labatbottom)).append("text").each((function(t){t.textlabel=this})).text((t=>Vt(t.mname))).attr("font-family",I).attr("font-size",(t=>{t._labfontsize=Math.max(12,t.radius*1.2);return t._labfontsize})).attr("fill",(e=>Tt(e,t))).attr("x",(t=>s.showsamplebar||s.showgenotypebyvalue?s.axisheight+s.maxradius+4:t.radius+t.rimwidth+ee)).attr("y",(t=>t._labfontsize*te)).attr("class","sja_aa_disclabel").attr("transform",(t=>"rotate("+(t.labattop?"-":"")+"90)")).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>Xt(s,t))).on("mouseout",((e,s)=>Yt(s,t))).on("click",((s,o)=>{Jt(o,{left:s.clientX,top:s.clientY},t,e)}));if(t.hlaachange){_.filter((e=>t.hlaachange.has(e.mname))).classed("sja_pulse",true)}}function Xt(t,e){if(t.textlabel){C(t.textlabel).attr("font-size",t._labfontsize*1.1)}const s=e.numericmode;if(s.showsamplebar)return;if(s.showgenotypebyvalue)return;e.pica.g.attr("transform","translate("+(t.aa.x+t.xoff)+","+(s.toplabelheight+s.maxradius+s.axisheight-t._y)+")");const o=10;const a=4;const n=t._labfontsize||13;const r=Tt(t,e);let i=0,l=false;e.pica.g.append("text").attr("font-size",n).attr("font-family",I).text(t._v).each((function(){i=this.getBBox().width})).remove();if(!t.labattop&&!t.labatbottom){l=true;e.pica.g.append("text").attr("font-size",n).attr("font-family",I).text(t.mname).each((function(){i=Math.max(i,this.getBBox().width)})).remove()}const c=a*2+i;let f,d,p=true;if(c+o>t.aa.x+t.xoff){p=false;d=t.radius+t.rimwidth;f=d+o}else{d=-t.radius-t.rimwidth-o;f=d-c}e.pica.g.append("rect").attr("x",f-2).attr("y",-2-a-(l?n:n/2)).attr("width",4+c).attr("height",4+a*2+n*(l?2:1)).attr("fill","white");e.pica.g.append("line").attr("x1",d).attr("x2",d+o).attr("stroke","white").attr("stroke-width",3).attr("shape-rendering","crispEdges");e.pica.g.append("line").attr("x1",d).attr("x2",d+o).attr("stroke",r).attr("shape-rendering","crispEdges");e.pica.g.append("rect").attr("x",f).attr("y",-a-(l?n:n/2)).attr("width",c).attr("height",a*2+n*(l?2:1)).attr("fill","none").attr("stroke",r).attr("shape-rendering","crispEdges");e.pica.g.append("text").text(t._v).attr("text-anchor",p?"end":"start").attr("font-size",n).attr("font-family",I).attr("x",p?d-a:f+a).attr("y",l?-n/2:0).attr("fill",r).attr("dominant-baseline","central");if(l){e.pica.g.append("text").text(t.mname).attr("text-anchor",p?"end":"start").attr("font-size",n).attr("font-family",I).attr("x",p?d-a:f+a).attr("y",l?n/2:0).attr("fill",r).attr("dominant-baseline","central")}}function Yt(t,e){if(t.textlabel){C(t.textlabel).attr("font-size",t._labfontsize)}e.pica.g.selectAll("*").remove()}async function Jt(t,e,s,o){if(t.dt==i||t.dt==l){$({mlst:[t],pane:true,x:e.left-10,y:e.top-10,tk:s,block:o,svgraph:true});return}if(t.occurrence>1){if(await Ut(t.occurrence,[t],t.aa.x+t.xoff,s.numericmode.toplabelheight+s.numericmode.axisheight-t._y,s,o))return}$({mlst:[t],pane:true,x:e.left-10,y:e.top-10,tk:s,block:o})}function Qt(t){const e=[];for(const s of t.data){for(const t of s.mlst){e.push({m:t,w:2*(t.radius+t.rimwidth),x:s.x0,y:t._y})}}e.sort(((t,e)=>e.y-t.y));for(let t=0;t<e.length;t++){const s=e[t];let o=false;for(let a=0;a<t;a++){const t=e[a];if(Math.abs(s.x-t.x)<(s.w+t.w)/2-2){o=true;break}}if(!o){s.m.labattop=true}}for(let t=e.length-1;t>=0;t--){const s=e[t];if(s.m.labattop)continue;let o=false;for(let a=e.length-1;a>t;a--){const t=e[a];if(t.m.labatbottom&&Math.abs(t.x-s.x)<(t.w+s.w)/2-2){o=true;break}}if(!o){s.m.labatbottom=true}}}function Wt(t,e){if(t.mlst.length==1){return"M0,0v"+e.stem1+"l"+-t.xoffset+","+e.stem2+"v"+e.stem3}return"M0,0"+"v"+e.stem1+"l"+-t.xoffset+","+e.stem2+"v"+e.stem3+"v-"+e.stem3+"l"+(t.stemw+t.xoffset-1)+",-"+e.stem2+"v-"+e.stem1}function Zt(t,e){t.numericmode;const s=100;let o=0;for(const e of t.data){let t=0;for(const s of e.mlst){t+=2*(s.radius+s.rimwidth)}if(e.mlst.length==1){e.width=t}else{e.width=Math.min(s,t);const o=e.mlst[0];const a=e.mlst[e.mlst.length-1];e.fixedgew=o.radius+o.rimwidth+a.radius+a.rimwidth}o+=e.width}if(o<=e.width){let s=0;for(const e of t.data){e.x=s+e.mlst[0].radius+e.mlst[0].rimwidth;s+=e.width;if(e.mlst.length==1){e.stemw=0}else{e.stemw=e.width-e.fixedgew}}Kt(t.data,e.width);for(const e of t.data){e.xoffset=e.x-e.x0;if(e.mlst.length==1){e.mlst[0].xoff=0;e.stemw=0}else{e.stemw=e.width-e.fixedgew;const t=e.stemw/(e.mlst.length-1);for(let s=0;s<e.mlst.length;s++){e.mlst[s].xoff=t*s}}}return true}else{for(const e of t.data){e.x=e.x0;e.xoffset=0;for(const t of e.mlst){t.xoff=0}}return false}}function Kt(t,e){for(let s=0;s<t.length;s++){if(t[s].x0<0)continue;if(t[s].x0>e)break;while(1){let o=0,a=0;for(let n=s;n<t.length;n++){const s=t[n];if(s.x0>e){return}o+=Math.abs(s.x-s.x0-s.stemw/2);s.x++;a+=Math.abs(s.x-s.x0-s.stemw/2)}if(t[s].x>t[s].x0-t[s].stemw/2){for(let e=s;e<t.length;e++){t[e].x--}break}const n=t[t.length-1];if(n.x+n.width/2>=e){return}if(a<=o);else{for(let o=s;o<t.length;o++){if(t[o].x0>e){break}t[o].x--}break}}}}const $t="Not annotated";const te=.3;const ee=1;const se=4;const oe=0;const ae=1;async function ne(t,e){try{if(!t)throw"no tk";if(!t.ds)throw"no ds";if(!e.gmmode||e.gmmode==F.genomic){if(e.viewrangeabovelimit(t.viewrangeupperlimit)){t.mlst=[];t.viewrangeupperlimit_above=true;fe(t,e);return}}delete t.viewrangeupperlimit_above;if(t.isvcf){e.tkcloakon(t);Rt(e,t);return}if(e.ds2handle[t.ds.label]){t.__handlesays=e.ds2handle[t.ds.label].handlesays}if(t.ds.bulkdata||t.ds.mlst){return await ie(t,e)}await le(t,e);re(t,e);t.ds.busy=false;e.tkcloakoff(t,{})}catch(s){if(s.stack)console.log(s.stack);t.ds.busy=false;e.tkcloakoff(t,{error:s.message||s});e.setllabel(t);e.block_setheight()}}function re(t,e){if(!t.legacyDsFilter)return;if(!t.legacyDsFilter.key||!t.legacyDsFilter.value)throw"legacyDsFilter is not {key,value}";const s=t.mlst.filter((e=>e[t.legacyDsFilter.key]==t.legacyDsFilter.value));const o={label:t.ds.label+" - "+t.legacyDsFilter.value,bulkdata:{},parentname:t.ds.label,iscustom:true,sampleselectable:t.ds.sampleselectable};o.bulkdata[e.usegm.name.toUpperCase()]=s;e.addchilddsnoload(o);const a=e.block_addtk_template({type:D.ds,ds:o});ne(a,e)}async function ie(t,e){if(e.usegm){if(t.__handlesays){t.__handlesays.style("background-color","#ddd").style("color","black")}let s=[];if(t.ds.bulkdata){const o=t.ds.bulkdata[e.usegm.name.toUpperCase()];if(o){s=[...o]}}if(t.ds.mlst){for(const o of t.ds.mlst){if(o.gene.toUpperCase()==e.usegm.name.toUpperCase()){s.push(o)}}}if(s.length){const o=[];for(const t of s){if(t.isoform&&t.isoform==e.usegm.isoform){o.push(t)}}if(o.length){ce([{lst:o}],e,t)}else{throw"No data from "+t.ds.label+" for "+e.usegm.isoform}}else{throw"No data from "+t.ds.label+" for "+e.usegm.name}if(t.ds.dbexpression&&(!t.eplst||t.eplst.length==0)){const s={jwt:e.jwt,db:t.ds.dbexpression.dbfile,tablename:t.ds.dbexpression.tablename,keyname:t.ds.dbexpression.keyname,key:e.usegm.name};const o=await w("dbdata",{method:"POST",body:JSON.stringify(s)});if(o.error)throw o.error;if(!t.eplst)t.eplst=[];if(t.ds.dbexpression.tidy)t.ds.dbexpression.tidy(o.rows);const a={data:o.rows,expp:t.ds.dbexpression.config,block:e,genome:e.genome,genename:e.usegm.name,dsname:t.ds.label};const n=await import("./ep-d017ec2f.js");t.eplst.push(new n.default(a))}}else{const s=[];const f=new Map;for(const t of e.rglst){if(!f.has(t.chr)){f.set(t.chr,[])}f.get(t.chr).push(t)}const d=[];if(t.ds.bulkdata){for(const e in t.ds.bulkdata){d.push(...t.ds.bulkdata[e])}}if(t.ds.mlst){d.push(...t.ds.mlst)}for(const t of d){switch(t.dt){case c:case r:case o:case n:case a:if(!t.pos){break}if(!t.chr&&!f.has(t.chr)){break}for(const e of f.get(t.chr)){if(t.pos>=e.start&&t.pos<e.stop){s.push(t);break}}break;case l:case i:if(!t.pairlst){break}let e=false;for(const s of t.pairlst){if(s.a.chr&&f.has(s.a.chr)){const t=s.a.position||s.a.pos;if(t){for(const o of f.get(s.a.chr)){if(t>=o.start&&t<o.stop){e=true;break}}}}if(s.b.chr&&f.has(s.b.chr)){const t=s.b.position||s.b.pos;if(t){for(const o of f.get(s.b.chr)){if(t>=o.start&&t<o.stop){e=true;break}}}}}if(e){s.push(t)}break}}if(s.length){ce([{lst:s}],e,t)}}}async function le(t,e){if(t.__handlesays)t.__handlesays.text("Loading...");t.ds.busy=true;e.tkcloakon(t);const s={genome:e.genome.name,dsname:t.ds.label,range:e.tkarg_maygm(t)[0]};if(e.usegm){s.genename=e.usegm.name;s.isoform=e.usegm.isoform}if(t.eplst){s.noexpression=1}if(e.hidedatasetexpression){s.noexpression=1}const o=await w("dsdata",{method:"POST",body:JSON.stringify(s)});if(t.__handlesays){t.__handlesays.text(t.ds.label).style("background-color","#ddd").style("color","black")}if(o.error)throw o.error;ce(o.data,e,t)}function ce(t,e,s){if(s.dsuninitiated){for(let t=0;t<e.tklst.length;t++){if(e.tklst[t].tkid==s.tkid){e.tklst.splice(t,1);break}}delete s.dsuninitiated;let t=-1;for(let s=0;s<e.tklst.length;s++){const o=e.tklst[s];if(o.type==D.usegm&&!o.hidden){t=s;break}}let o=true;if(t==-1){o=true;e.tklst.push(s)}else{let a=false;for(let s=0;s<t;s++){const t=e.tklst[s];if(!t.hidden&&t.type==D.ds){a=true;break}}if(a){o=false;e.tklst.splice(t+1,0,s)}else{o=true;if(t==0){e.tklst.unshift(s)}else{e.tklst.splice(t-1,0,s)}}}if(s.aboveprotein==undefined){s.aboveprotein=o}s.eplst=[]}s.mlst=[];const o=[];for(const a of t){if(a.isgeneexpression){o.push(Me(a,s,e));continue}if(a.vcfid){It(a,s,e);continue}if(a.lst){Ae(a.lst,s,e);Ee(a,s);continue}e.error("unknown data/query type from "+s.ds.label);return}Promise.all(o).then((()=>{if(s.eplst.length>1){for(let t=1;t<s.eplst.length;t++){const e=s.eplst[t];e.pane.pane.style("left",Number.parseInt(s.eplst[0].pane.pane.style("left"))+50*t+"px");e.pane.pane.style("top",Number.parseInt(s.eplst[0].pane.pane.style("top"))+50*t+"px")}}}));fe(s,e)}function fe(t,e){e.tkcloakoff(t,{});de(t);if(t.vcfinfofilter&&t.vcfinfofilter.setidx4numeric!=undefined){if(!t.numericmode){t.numericmode={axisheight:t.axisheight}}}else{delete t.numericmode}const s=new Set;for(const t in L){if(L[t].hidden){s.add(t)}}Pe(t);if(t.numericmode){Ot(t,e,s)}else{pe(t,e,s)}e.setllabel(t);e.block_setheight();e.tkchangeaffectlegend(t);Ne(t,e);Re(t,e);{const s=Ie(t,e);if(s)console.log("showlegend_sampleattribute: "+s)}}function de(t){if(t.vcfinfofilter&&t.vcfinfofilter.setidx4occurrence!=undefined){const e=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4occurrence];if(!e)throw"mcset not found by setidx4occurrence";for(const s of t.mlst){const[t,o]=Se(e,s);if(t||o==undefined){s.occurrence=1}else{s.occurrence=o[0]}}}else{for(const e of t.mlst){e.occurrence=1}}}function pe(t,e,s){t.leftaxis.selectAll("*").remove();if(e.usegm&&e.gmmode!=F.genomic&&e.pannedpx!=undefined&&t.skewer){De(t,e);t.skewer.attr("transform",(t=>"translate("+t.x+","+t.y+")"));ye(t,e)}else{t.glider.selectAll("*").remove();qe(t,e,s);const o=new Map;for(const e of t.mlst){if(e.__x==undefined){continue}if(!o.has(e.__x)){o.set(e.__x,[])}o.get(e.__x).push(e)}const a=[];if(e.exonsf>=se){for(const[t,e]of o){a.push({chr:e[0].chr,pos:e[0].pos,mlst:e,x:t,groups:ue(e)})}}else{if(e.usegm&&e.usegm.coding&&e.gmmode!=F.genomic){const t=new Map;for(const[s,a]of o){if(a[0].chr!=e.usegm.chr){continue}let n=undefined;for(const t of a){if(Number.isFinite(t.aapos))n=t.aapos}if(n==undefined){n=_(a[0].pos,e.usegm).aapos}if(n==undefined){console.error("data item cannot map to aaposition");console.log(a[0]);continue}o.delete(s);if(!t.has(n)){t.set(n,[])}let r=true;for(const s of t.get(n)){if(Math.abs(s[0].__x-a[0].__x)<=e.exonsf*3){for(const t of a){s.push(t)}r=false;break}}if(r){t.get(n).push(a)}}e.usegm.utr5?e.usegm.utr5.reduce(((t,e)=>t+e[1]-e[0]),0):0;for(const e of t.values()){for(const t of e){let e=null;for(const s of t){if(Number.isFinite(s.rnapos))e=s}if(e==null){console.log("trying to map mlst to codon, but no rnapos found");for(const e of t){console.log(e)}continue}a.push({chr:t[0].chr,pos:e.pos,mlst:t,x:t[0].__x,groups:ue(t)})}}}const t=[];const s=2;for(const[e,a]of o){const o=Math.floor(e/s);if(!t[o]){t[o]=[]}t[o]=[...t[o],...a]}for(const e of t){if(!e)continue;const t=e.reduce(((t,e)=>t+e.__x),0);a.push({isbin:true,chr:e[0].chr,pos:e[0].pos,mlst:e,x:t/e.length,groups:ue(e)})}}a.sort(((t,e)=>t.x-e.x));if(t.data&&e.pannedpx!=undefined&&(!e.usegm||e.gmmode==F.genomic)){const e={};for(const s of t.data){e[s.chr+"."+s.pos]={mode:s.showmode,xoffset:s.xoffset,slabelrotate:s.slabelrotate}}for(const t of a){const s=t.chr+"."+t.pos;if(e[s]){t.showmode=e[s].mode;t.xoffset=e[s].xoffset;t.slabelrotate=e[s].slabelrotate}}}t.data=a;for(const e of t.data){e.occurrence=e.groups.reduce(((t,e)=>t+e.occurrence),0)}me(t,e);t.height_main=t.toppad+t.maxskewerheight+t.stem1+t.stem2+t.stem3+t.bottompad}if(!t.data||t.data.length==0){Le(t,e);return}if(t.hlaachange||t.hlvariants){const s=[];const o=[];if(t.hlaachange){for(const e of t.data){let a=false;for(const s of e.groups){if(t.hlaachange.has(s.mlst[0].mname)){a=true;t.hlaachange.delete(s.mlst[0].mname);break}}if(a){o.push(e)}else{s.push(e)}}if(t.hlaachange.size){if(!e.usegm){e.error("cannot add items from hlaachange: not in gene-mode")}else{ze(t,e)}}delete t.hlaachange}if(t.hlvariants){const e={};for(const s of t.hlvariants){e[s.chr+"."+s.pos+"."+s.ref+"."+s.alt]=1}for(const a of t.data){let t=false;for(const s of a.groups){if(t){break}for(const o of s.mlst){if(e[o.chr+"."+o.pos+"."+o.ref+"."+o.alt]){t=true;break}}}if(t){o.push(a)}else{s.push(a)}}}_e(s,t);xe(o,t,e)}else{ye(t,e)}}function ue(t,e){const s=new Map;for(const e of t){switch(e.dt){case c:if(!s.has(e.dt)){s.set(e.dt,new Map)}if(!s.get(e.dt).has(e.class)){s.get(e.dt).set(e.class,new Map)}const t=e.mname||"";if(!s.get(e.dt).get(e.class).has(t)){s.get(e.dt).get(e.class).set(t,[])}s.get(e.dt).get(e.class).get(t).push(e);break;case l:case i:if(!s.has(e.dt)){s.set(e.dt,new Map)}if(!s.get(e.dt).has(e.class)){s.get(e.dt).set(e.class,{use5:new Map,use3:new Map})}if(e.useNterm){if(!s.get(e.dt).get(e.class).use5.has(e.mname)){s.get(e.dt).get(e.class).use5.set(e.mname,[])}s.get(e.dt).get(e.class).use5.get(e.mname).push(e)}else{if(!s.get(e.dt).get(e.class).use3.has(e.mname)){s.get(e.dt).get(e.class).use3.set(e.mname,[])}s.get(e.dt).get(e.class).use3.get(e.mname).push(e)}break;case r:case o:case n:case a:if(!s.has(e.dt)){s.set(e.dt,[])}s.get(e.dt).push(e);break;default:console.log("unknown datatype: "+e.dt);console.log(e);return}}const f=[];for(const[t,e]of s){switch(t){case c:for(const s of e.values()){for(const e of s.values()){f.push({dt:t,mlst:e})}}break;case l:case i:for(const s of e.values()){for(const e of s.use5.values()){f.push({dt:t,useNterm:true,mlst:e})}for(const e of s.use3.values()){f.push({dt:t,useNterm:false,mlst:e})}}break;case r:case o:case n:case a:f.push({dt:t,mlst:e})}}for(const t of f){let e=0,s=0;for(const o of t.mlst){if(o.isrim1)e++;else if(o.isrim2)s++}t.rim1count=e;t.rim2count=s;t.occurrence=t.mlst.reduce(((t,e)=>t+e.occurrence),0)}f.sort(((t,e)=>e.occurrence-t.occurrence));return f}function me(t,e){delete t.skewer2;const s=e=>{if(t.vcfinfofilter&&t.vcfinfofilter.setidx4mclass!=undefined){const s=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4mclass];const[o,a]=Se(s,e);if(o||a==undefined)return"black";for(const t of a){if(s.categories[t]){return s.categories[t].color}else{return"black"}}}if(f[e.class]){return f[e.class].color}return"black"};const d=[];for(const s of t.data){s.x0=s.x;if(s.xoffset!=undefined){s.x=s.x0+s.xoffset}for(const t of s.groups){t.aa=s;let a=null;if(t.dt==r){a=t.mlst[0].rnaduplength;for(const e of t.mlst){a=Math.max(a,e.rnaduplength)}}else if(t.dt==o){a=t.mlst[0].rnadellength;for(const e of t.mlst){a=Math.max(a,e.rnadellength)}}else{continue}if(!Number.isFinite(a)||a<0){console.log("no rnaspan for stack bar from itd/del");console.log(t.mlst);continue}let n=null;if(e.usegm){const o=t.mlst[0].rnapos;const r=E(o+a,e.usegm);const i=e.seekcoord(e.usegm.chr,r);if(i.length>0){n=i[0].x-s.x}else{console.log(r+" no hit on rglst")}}if(!Number.isFinite(n)){console.log("no pxspan for stack bar from itd/del");console.log(t.mlst);continue}t.stackbar={aa:s.mlst[0].aapos,pxspan:n,height:4,grp:t};s.hasstackbar=true;d.push(t.stackbar)}}let p=0;if(d.length>0){let t=1;for(let e=0;e<d.length;e++){const s=d[e];const o=[];for(let t=0;t<e;t++){const e=d[t];if(Math.max(s.aa,e.aa)<Math.min(s.pxspan+s.aa,e.pxspan+e.aa)){o.push(e)}}s.y=2;for(const e of o){if(Math.max(s.y,e.y)<Math.min(s.y+s.height,e.y+e.height)){s.y=e.y+e.height+t}}p=Math.max(p,s.y+s.height)}}const u=Math.max(14,e.width/110);let m=0;for(const e of t.data){for(const t of e.groups){m=Math.max(m,t.occurrence)}}let h=0;const g=Math.pow(u/2,2)*Math.PI;if(m<=10)h=g*m*.9;else if(m<=100)h=g*10;else if(m<=1e3)h=g*14;else h=g*20;const b=R().domain([1,m*.5,m*.6,m*.7,m*.8,m]).range([g,g+(h-g)*.8,g+(h-g)*.85,g+(h-g)*.9,g+(h-g)*.95,h]);let y=u/2;t.maxskewerheight=0;t.skewer=t.glider.selectAll().data(t.data).enter().append("g").attr("class","sja_skg").each((function(e){e.skewer=this;if(e.showmode==undefined){e.showmode=oe}e.maxradius=0;e.maxrimwidth=0;e.width=0;e.slabelrotate=false;e.slabelwidth=0;for(const t of e.groups){if(t.occurrence==1){t.radius=u/2}else{const e=t.occurrence.toString().length;t.radius=Math.max(Math.sqrt(b(t.occurrence)/Math.PI),e*5)}e.maxradius=Math.max(e.maxradius,t.radius);y=Math.max(y,t.radius);t.rimwidth=t.rim1count+t.rim2count==0?0:Math.max(2,t.radius/6);e.maxrimwidth=Math.max(e.maxrimwidth,t.rimwidth)}let s=0;for(const t of e.groups){t.yoffset=s+t.radius+t.rimwidth;s+=(t.radius+t.rimwidth)*2}t.maxskewerheight=Math.max(t.maxskewerheight,s)}));const x=t.skewer.selectAll().data((t=>t.groups)).enter().append("g").attr("transform",(e=>"translate(0,"+(e.aa.showmode==oe?0:e.yoffset*(t.aboveprotein?-1:1))+")")).attr("class","sja_aa_discg").each((function(t){t.g=this}));const k=x.append("circle");k.filter((t=>t.dt==r||t.dt==o||t.dt==n||t.dt==a)).attr("fill","white").attr("stroke-width",2).attr("stroke",(t=>s(t.mlst[0]))).attr("r",(t=>t.radius-2));k.filter((t=>t.dt==c||t.dt==l||t.dt==i)).attr("fill",(t=>s(t.mlst[0]))).attr("stroke","white").attr("r",(t=>t.radius-.5));x.filter((t=>t.dt==i||t.dt==l)).append("path").attr("fill","white").attr("stroke","none").attr("d",(t=>Q()({innerRadius:0,outerRadius:t.radius-2,startAngle:t.useNterm?0:Math.PI,endAngle:t.useNterm?Math.PI:Math.PI*2})));const v=x.filter((t=>t.occurrence>1)).append("text").text((t=>t.occurrence)).attr("font-family",I).attr("class","sja_aa_discnum").attr("fill-opacity",(t=>t.aa.showmode==oe?0:1)).attr("stroke-opacity",(t=>t.aa.showmode==oe?0:1)).attr("text-anchor","middle").each((t=>{const e=t.radius*1.5;t.discnumfontsize=Math.min(e/(t.occurrence.toString().length*S),e)})).attr("font-size",(t=>t.discnumfontsize)).attr("y",(t=>t.discnumfontsize*te));v.filter((t=>t.dt==c)).attr("fill","white");v.filter((t=>t.dt==l||t.dt==i)).attr("stroke",(t=>s(t.mlst[0]))).attr("stroke-width",.8).attr("font-weight","bold").attr("fill","white");v.filter((t=>t.dt==r||t.dt==o||t.dt==a||t.dt==n)).attr("fill",(t=>s(t.mlst[0])));const w=x.append("text").text((t=>t.mlst[0].mname)).attr("font-size",(t=>{t._labfontsize=Math.max(12,t.radius*1.2);return t._labfontsize})).each((function(e){const s=this.getBBox().width;e._label_width=s;if(e.aa.groups.length==1){e.aa.slabelrotate=true;e.aa.slabelwidth=s;t.maxskewerheight=Math.max(t.maxskewerheight,(e.radius+e.rimwidth)*2+2+s)}})).attr("fill",(t=>s(t.mlst[0]))).attr("x",(t=>t.radius+t.rimwidth+1)).attr("y",(t=>t._labfontsize*te)).attr("font-family",I).classed("sja_aa_disclabel",true).attr("fill-opacity",(t=>t.aa.showmode==oe?0:1)).attr("transform","scale(1) rotate(0)").on("mousedown",(t=>{t.stopPropagation()})).on("click",((s,o)=>{_e([o.aa],t);ke(t,e);if(e.debugmode){console.log(o.aa)}}));if(t.hlaachange){w.filter((e=>t.hlaachange.has(e.mlst[0].mname))).classed("sja_pulse",true)}for(const e of t.data){let t=0,s=0;for(const o of e.groups){t=Math.max(t,o.radius+o.rimwidth);s=Math.max(s,o.radius+o.rimwidth+ee+o._label_width)}e.width=t+s}x.append("circle").attr("r",(t=>t.radius-.5)).attr("stroke",(t=>s(t.mlst[0]))).attr("class","sja_aa_disckick").attr("fill","white").attr("fill-opacity",0).attr("stroke-opacity",0).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>{if(t.disc_mouseover){t.disc_mouseover(s,e.target)}else{je(t,s.mlst,true)}})).on("mouseout",((e,s)=>{if(t.disc_mouseout){t.disc_mouseout(s)}else{je(t,s.mlst,false)}})).on("click",(async(s,o)=>{const a=s.target.getBoundingClientRect();if(o.dt==i||o.dt==l){$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e,svgraph:true});return}if(o.occurrence==1){$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e});return}if(await Ut(o.occurrence,o.mlst,o.aa.x,ge(o,t)+o.yoffset*(t.aboveprotein?-1:1),t,e)){return}$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e})}));const _=Q().innerRadius((t=>t.radius)).outerRadius((t=>t.radius+t.rimwidth)).startAngle(0).endAngle((t=>{t.rim1_startangle=Math.PI*2*t.rim1count/t.occurrence;return t.rim1_startangle}));x.append("path").attr("d",_).attr("fill",(t=>s(t.mlst[0]))).attr("class","sja_aa_discrim").attr("fill-opacity",0);const j=Q().innerRadius((t=>t.radius+.5)).outerRadius((t=>t.radius+.5+t.rimwidth)).startAngle((t=>t.rim1_startangle)).endAngle((t=>t.rim1_startangle+Math.PI*2*t.rim2count/t.occurrence));x.filter((t=>t.rim2count>0)).append("path").attr("d",j).attr("stroke",(t=>s(t.mlst[0]))).attr("fill","none").attr("class","sja_aa_discrim").attr("stroke-opacity",0);{let e=0;let s=0;for(const o of t.data){if(o.x-o.maxradius-o.maxrimwidth<s){e++}s=Math.max(s,o.x+o.width-o.maxradius-o.maxrimwidth)}t.stem1=e==0?0:u;t.stem2=R().domain([0,1,t.data.length]).range([0,u,u*3])(e)}const M=u*.7;let A=0;for(const e of t.data){for(const t of e.groups){A=Math.max(A,t.occurrence)}}t.stem3=Math.max(p+2,M+u*Math.min(5,A));t.skewer.append("circle").attr("class","sja_aa_skkick").attr("fill","white").attr("fill-opacity",0).attr("stroke","none").attr("r",(t=>t.maxradius+1)).attr("cy",(e=>(t.aboveprotein?-1:1)*e.maxradius)).attr("transform",(t=>"scale("+(t.showmode==oe?1:0)+")")).on("mouseover",((e,o)=>{je(t,o.mlst,true);const a=t.aboveprotein;let n=0;let r=0;const i=5;const l=a?7:14;for(const e of o.groups){e.pica_fontsize=Math.max(11,e.radius);n+=e.pica_fontsize+1;t.pica.g.append("text").text(e.mlst[0].mname+(e.occurrence>1?" x"+e.occurrence:"")).attr("font-size",e.pica_fontsize).each((function(){r=Math.max(r,this.getBBox().width)})).remove()}r+=i*2;const c=n+5;t.pica.g.append("rect").attr("y",a?-c:0).attr("width",r).attr("height",c).attr("fill","white").attr("fill-opacity",.8).attr("stroke","#ccc").attr("shape-rendering","crispEdges");n=0;const f=t.pica.g.selectAll().data(o.groups).enter().append("g").attr("transform",((t,e)=>{n+=t.pica_fontsize+1;return"translate("+i+","+n*(a?-1:1)+")"}));f.append("text").text((t=>t.mlst[0].mname)).attr("font-size",(t=>t.pica_fontsize)).each((function(t){t.pica_mlabelwidth=this.getBBox().width})).attr("fill",(t=>s(t.mlst[0]))).attr("dominant-baseline",a?"hanging":"auto");const d=o.groups[0].pica_mlabelwidth;t.pica.x=o.x-i-d/2;t.pica.y=o.y+(a?-1:1)*(o.maxradius*2+l+2);t.pica.g.attr("transform","translate("+t.pica.x+","+t.pica.y+")");f.filter((t=>t.occurrence>1)).append("text").text((t=>"x"+t.occurrence)).attr("x",(t=>t.pica_mlabelwidth+5)).attr("font-size",(t=>t.pica_fontsize)).attr("dominant-baseline",a?"hanging":"auto").attr("fill","#9e9e9e");const p=t.pica.g.append("g").attr("transform","translate("+(i+d/2)+","+(a?1:-1)+")");p.append("line").attr("y2",(a?1:-1)*l).attr("stroke","#858585").attr("shape-rendering","crispEdges");p.append("line").attr("x1",-1).attr("x2",-1).attr("y2",(a?1:-1)*l).attr("stroke","white").attr("shape-rendering","crispEdges");p.append("line").attr("x1",1).attr("x2",1).attr("y2",(a?1:-1)*l).attr("stroke","white").attr("shape-rendering","crispEdges")})).on("mouseout",((e,s)=>{t.pica.g.selectAll("*").remove();je(t,s.mlst,false)})).on("click",((s,o)=>{t.pica.g.selectAll("*").remove();xe([o],t,e)}));let z=0;for(const e of t.data){z=Math.max(z,e.occurrence)}const N=R().domain([1,z]).range([M,t.stem3-y]);t.skewer.attr("transform",(e=>{e.foldyoffset=N(e.occurrence);e.y=ge(e,t);return"translate("+e.x+","+e.y+")"}));if(d.length>0){t.skewer.filter((t=>t.hasstackbar)).selectAll().data((t=>{const e=[];for(const s of t.groups){if(s.stackbar){e.push(s.stackbar)}}return e})).enter().append("g").attr("class","sja_aa_stackbar_g").attr("transform",(e=>"translate(0,"+(t.aboveprotein?1:-1)*(t.stem1-e.y)+")")).append("rect").attr("y",(e=>t.aboveprotein?-e.height:0)).attr("class","sja_aa_stackbar_rect").attr("width",0).attr("shape-rendering","crispEdges").attr("fill-opacity",.5).attr("stroke","none").attr("stroke-width",1).attr("height",(t=>t.height)).attr("fill",(t=>s(t.grp.mlst[0]))).on("mouseover",((e,a)=>{const n=s(a.grp.mlst[0]);C(e.target).attr("stroke",n);const i=t.pica;let l="wrong label";let c="wrong label, ";switch(a.grp.mlst[0].dt){case r:l=f[a.grp.mlst[0].class].desc;c=Math.ceil(a.grp.mlst[0].rnaduplength/3)+" aa, ";break;case o:l=f[a.grp.mlst[0].class].label;c=Math.ceil(a.grp.mlst[0].rnadellength/3)+" aa, ";break}if(a.grp.occurrence==1){const t=a.grp.mlst[0];if(t.sample){c+=t.sample}else if(t.patient){c+=t.patient}else{c+="1 sample"}}else{c+=a.grp.occurrence+" samples"}const d=14,p=10,u=2,m=4;let h=0;i.g.append("text").text(l).attr("font-size",d).attr("font-family",I).each((function(){h=this.getBBox().width})).remove();i.g.append("text").text(c).attr("font-size",p).attr("font-family",I).each((function(){h=Math.max(h,this.getBBox().width)})).remove();const g=u*3+d+p;i.x=a.grp.aa.x0+3;i.y=t.aboveprotein?t.height_main-t.toppad-t.bottompad-a.y-a.height-3-g:a.y+a.height+3;i.g.attr("transform","translate("+i.x+","+i.y+")");i.g.append("rect").attr("width",h+m*2).attr("height",g).attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("fill","white").attr("fill-opacity",.8);i.g.append("text").text(l).attr("x",m).attr("y",u+d/2).attr("dominant-baseline","middle").attr("font-size",d).attr("font-family",I).attr("fill",n);i.g.append("text").text(c).attr("x",m).attr("y",u*2+d+p/2).attr("dominant-baseline","middle").attr("font-size",p).attr("font-family",I).attr("fill","#858585")})).on("mouseout",((e,s)=>{C(e.target).attr("stroke","none");t.pica.g.selectAll("*").remove()})).on("click",((s,o)=>{$({mlst:o.grp.mlst,pane:true,x:s.clientX,y:s.clientY,tk:t,block:e})}))}t.skewer.append("path").attr("class","sja_aa_stem").attr("d",(e=>be(e,t))).attr("stroke",(t=>s(t.groups[0].mlst[0]))).attr("fill","none");const P=t.skewer.filter((t=>t.groups.length>1));P.append("rect").attr("class","sja_aa_ssk_bg").attr("shape-rendering","crispEdges").attr("fill-opacity",0).attr("height",t.stem1).attr("fill",(t=>s(t.groups[0].mlst[0]))).attr("width",(t=>{t.ssk_width=Math.max(t.occurrence.toString().length*8+6,2*(t.maxradius+t.maxrimwidth));return t.ssk_width})).attr("x",(t=>-t.ssk_width/2));P.append("text").attr("class","sja_aa_ssk_text").attr("fill","white").attr("fill-opacity",0).attr("font-weight","bold").attr("text-anchor","middle").attr("dominant-baseline","central").text((t=>t.occurrence)).each((e=>{e.ssk_fontsize=Math.min(t.stem1,e.ssk_width/(e.occurrence.toString().length*S))})).attr("font-size",(t=>t.ssk_fontsize));P.append("rect").attr("class","sja_aa_ssk_kick").attr("fill","white").attr("fill-opacity",0).attr("stroke","none").attr("height",t.stem1).attr("x",(t=>-t.ssk_width/2)).attr("width",(t=>t.ssk_width)).on("mouseover",((e,s)=>{const o=C(e.target.parentNode);o.selectAll(".sja_aa_disckick").transition().attr("stroke-opacity",1);o.select(".sja_aa_ssk_bg").transition().attr("fill-opacity",1).attr("stroke-opacity",1);o.select(".sja_aa_ssk_text").transition().attr("fill-opacity",1);je(t,s.mlst,true)})).on("mouseout",(function(e,s){const o=C(e.target.parentNode);o.selectAll(".sja_aa_disckick").transition().attr("stroke-opacity",0);o.select(".sja_aa_ssk_bg").transition().attr("fill-opacity",0).attr("stroke-opacity",0);o.select(".sja_aa_ssk_text").transition().attr("fill-opacity",0);je(t,s.mlst,false)})).on("click",(async(s,o)=>{const a=s.target.getBoundingClientRect();if(o.occurrence>1){if(await Ut(o.occurrence,o.mlst,o.x,o.y+(t.aboveprotein?1:-1)*t.stem1/2,t,e))return}$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e})}))}function he(t){t.aboveprotein=!t.aboveprotein;if(t.numericmode){return}const e=t.aboveprotein;const s=1e3;const o=t.skewer.filter((t=>t.hasstackbar));o.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(s=>{const o=s.grp.aa;return"translate("+(o.showmode==oe?0:o.x0-o.x)+","+(e?1:-1)*(o.showmode==oe?t.stem1-s.y:t.stem1+t.stem2+t.stem3-s.y)+")"}));o.filter((t=>t.showmode==ae)).selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("y",(t=>e?-t.height:0));t.skewer.transition().duration(s).attr("transform",(e=>{e.y=ge(e,t);return"translate("+e.x+","+e.y+")"}));t.skewer.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(e=>be(e,t)));t.skewer.selectAll(".sja_aa_discg").transition().duration(s).attr("transform",(t=>{t.y=(e?-1:1)*(t.aa.showmode==oe?t.aa.maxradius:t.yoffset);return"translate(0,"+t.y+")"}));t.skewer.selectAll(".sja_aa_ssk_kick").attr("y",e?0:-t.stem1);t.skewer.selectAll(".sja_aa_ssk_bg").attr("y",e?0:-t.stem1);t.skewer.selectAll(".sja_aa_ssk_text").attr("y",(e?1:-1)*t.stem1/2);t.skewer.selectAll(".sja_aa_skkick").attr("cy",(t=>(e?-1:1)*t.maxradius));t.skewer.filter((t=>t.showmode==ae&&t.groups.length==1)).selectAll(".sja_aa_disclabel").transition().duration(s).attr("transform",(t=>"scale(1) rotate("+(t.aa.slabelrotate?(e?"-":"")+"90":"0")+")"))}function ge(t,e){if(e.aboveprotein){if(t.showmode==oe){return e.maxskewerheight+e.stem1+e.stem2+e.stem3-t.foldyoffset}return e.maxskewerheight}if(t.showmode==oe)return t.foldyoffset;return e.stem1+e.stem2+e.stem3}function be(t,e){if(e.aboveprotein){if(t.showmode==oe){return"M0,0v0l0,0v"+t.foldyoffset}return"M0,0v"+e.stem1+"l"+(t.x0-t.x)+","+e.stem2+"v"+e.stem3}if(t.showmode==oe){return"M0,0v0l0,0v-"+t.foldyoffset}return"M0,0v-"+e.stem1+"l"+(t.x0-t.x)+",-"+e.stem2+"v-"+e.stem3}function ye(t,e){if(t.data.length==0){return}const s=0;const o=e.width;let a=0;const n=[];const r=[];for(const e of t.data){if(e.x0<s||e.x0>o){delete e.xoffset;r.push(e)}else{a+=e.slabelrotate?(e.groups[0].radius+e.groups[0].rimwidth)*2:e.width;n.push(e)}}_e(r,t);let i=[];const l=[];if(a<o-s){i=n}else{n.sort(((t,e)=>{if(e.occurrence==t.occurrence){if(e.groups.length==t.groups.length){return Math.abs(t.x0*2-s-o)-Math.abs(e.x0*2-s-o)}else{return e.groups.length-t.groups.length}}return e.occurrence-t.occurrence}));let t=0;let e=(o-s)*.8;let a=false;for(const s of n){if(a){delete s.xoffset;l.push(s);s.showmode=oe}else{if(t+s.width<e){i.push(s);t+=s.width}else{a=true;delete s.xoffset;l.push(s);s.showmode=oe}}}}_e(l,t);xe(i,t,e)}function xe(t,e,s){const o=1e3;const a=e.aboveprotein;const n=new Set;const r=new Set;let i=false;for(const s of t){if(s.showmode==ae){n.add(s.x0)}else{s.showmode=ae;r.add(s.x0);i=true;s.y=ge(s,e)}}if(i){const t=e.skewer.filter((t=>r.has(t.x0)));t.transition().duration(o).attr("transform",(t=>"translate("+t.x+","+t.y+")"));t.selectAll(".sja_aa_discg").transition().duration(o).attr("transform",(t=>{t.y=t.yoffset*(a?-1:1);return"translate(0,"+t.y+")"}));setTimeout((function(){t.selectAll(".sja_aa_disckick").attr("transform","scale(1)")}),o);t.selectAll(".sja_aa_discnum").transition().duration(o).attr("fill-opacity",1).attr("stroke-opacity",1);t.filter((t=>t.groups.length>1)).selectAll(".sja_aa_disclabel").transition().duration(o).attr("fill-opacity",1).attr("transform","scale(1)");t.selectAll(".sja_aa_discrim").transition().duration(o).attr("fill-opacity",1).attr("stroke-opacity",1);t.selectAll(".sja_aa_ssk_kick").attr("transform","scale(1)").attr("y",a?0:-e.stem1);t.selectAll(".sja_aa_ssk_bg").attr("transform","scale(1)").attr("y",a?0:-e.stem1);t.selectAll(".sja_aa_ssk_text").attr("transform","scale(1)").attr("y",(a?1:-1)*e.stem1/2);t.selectAll(".sja_aa_skkick").attr("transform","scale(0)");t.filter((t=>t.hasstackbar)).selectAll(".sja_aa_stackbar_g").attr("transform",(t=>"translate(0,"+(a?1:-1)*(e.stem1+e.stem2+e.stem3-t.y)+")"));let n=0;t.selectAll(".sja_aa_stem").transition().duration(o).attr("d",(t=>be(t,e))).each((()=>++n)).on("end",(()=>{if(! --n){ke(e,s)}}))}else{ke(e,s)}}function ke(t,e){const s=1e3;const o=t.aboveprotein;const a=[];const n=new Set;const r=0;const i=e.width;for(const e of t.data){if(e.x0<r||e.x0>i)continue;if(e.showmode==ae){e.x=e.x0;a.push(e);n.add(e.x0)}}if(a.length==0){return}ve(a,t,e);for(const t of a){t.xoffset=t.x-t.x0}for(let e=0;e<a.length;e++){const s=a[e];if(s.groups.length>1)continue;const o=s.groups[0];if(t.slabel_forcerotate){s.slabelrotate=true}else{const t=a[e+1];const n=t?t.x-t.maxradius-t.maxrimwidth:i;s.slabelrotate=n-s.x-o.radius-o.rimwidth-1<s.slabelwidth}s.width=(o.radius+o.rimwidth)*2+(s.slabelrotate?0:2+s.slabelwidth)}const l=t.skewer.filter((t=>n.has(t.x0)));l.transition().duration(s).attr("transform",(t=>"translate("+t.x+","+t.y+")"));l.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(e=>be(e,t)));l.filter((t=>t.groups.length==1)).selectAll(".sja_aa_disclabel").transition().duration(s).attr("fill-opacity",1).attr("transform",(t=>"scale(1) rotate("+(t.aa.slabelrotate?(o?"-":"")+"90":"0")+")"));t.slabel_forcerotate=false;const c=l.filter((t=>t.hasstackbar));c.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(e=>"translate("+(e.grp.aa.x0-e.grp.aa.x)+","+(o?1:-1)*(t.stem1+t.stem2+t.stem3-e.y)+")"));c.selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("width",(t=>t.pxspan)).attr("y",(t=>o?-t.height:0))}function ve(t,e,s){const o=0;const a=s.width;let n=o;let r=false;for(const e of t){if(e.x0<o||e.x0>a)continue;if(e.groups.length==1){e.slabelrotate=true;const t=e.groups[0];e.width=(t.radius+t.rimwidth)*2}const t=e.x-e.maxradius-e.maxrimwidth;if(t<n){r=true}if(t+e.width>a){r=true}n=Math.max(n,t+e.width)}if(!r){return false}n=o;for(const e of t){if(e.x0<o||e.x0>a)continue;e.x=n+e.maxradius+e.maxrimwidth;n+=e.width}we(t,s.width)}function we(t,e){for(let s=0;s<t.length;s++){if(t[s].x0<0)continue;if(t[s].x0>e)break;while(1){let o=0,a=0;for(let n=s;n<t.length;n++){const s=t[n];if(s.x0>e){return}o+=Math.abs(s.x-s.x0);s.x++;a+=Math.abs(s.x-s.x0)}if(t[s].x>=t[s].x0){for(let e=s;e<t.length;e++){t[e].x--}break}const n=t[t.length-1];if(n.x+n.width/2>=e){return}if(a<=o);else{for(let o=s;o<t.length;o++){if(t[o].x0>e){break}t[o].x--}break}}}}function _e(t,e){if(t.length==0)return;const s=1e3;const o=e.aboveprotein;const a=new Set;for(const s of t){s.x=s.x0;a.add(s.x0);s.showmode=oe;s.y=ge(s,e)}const n=e.skewer.filter((t=>a.has(t.x0)));n.transition().duration(s).attr("transform",(t=>"translate("+t.x+","+t.y+")"));n.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(t=>be(t,e)));n.selectAll(".sja_aa_discg").transition().duration(s).attr("transform",(t=>"translate(0,"+(o?"-":"")+t.aa.maxradius+")"));n.selectAll(".sja_aa_disckick").attr("transform","scale(0)");n.selectAll(".sja_aa_discnum").transition().duration(s).attr("fill-opacity",0).attr("stroke-opacity",0);n.selectAll(".sja_aa_disclabel").transition().duration(s).attr("fill-opacity",0).attr("transform","scale(0)");n.selectAll(".sja_aa_discrim").transition().duration(s).attr("fill-opacity",0).attr("stroke-opacity",0);n.selectAll(".sja_aa_ssk_kick").attr("transform","scale(0)");n.selectAll(".sja_aa_ssk_bg").attr("transform","scale(0)");n.selectAll(".sja_aa_ssk_text").attr("transform","scale(0)");n.selectAll(".sja_aa_skkick").transition().duration(s).attr("transform","scale(1)");const r=n.filter((t=>t.hasstackbar));r.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(t=>"translate(0,"+(o?1:-1)*(e.stem1-t.y)+")"));r.selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("width",0)}function je(t,e,s){if(!t.eplst)return;for(const o of t.eplst){o.may_hl(e,s)}}function Me(t,e,s){if(!t.config){s.error("config missing for expression data in "+e.ds.label);return}if(t.config.maf){try{t.config.maf.get=new Function(...t.config.maf.get)}catch(t){s.error("invalid javascript for config.maf.get of "+e.ds.label);return}}const o=t.config;if(o.usecohort){o.cohort=e.ds.cohort}const a={data:t.lst,expp:o,block:s,genome:s.genome,genename:s.usegm.name,dsname:e.ds.label};if(s.samplecart){if(e.ds.sampleselectable){a.samplecart=s.samplecart}}return import("./ep-d017ec2f.js").then((t=>{e.eplst.push(new t.default(a))}))}function Ae(t,e,s){for(const f of t){switch(f.dt){case c:if(s.usegm){const t=_(f.pos,s.usegm);f.rnapos=t.rnapos;f.aapos=t.aapos}e.mlst.push(f);break;case l:case i:if(!f.pairlst){console.error("pairlst missing from sv/fusion");break}if(s.usegm&&f.dt==l){if(f.pairlst.length==1){const t=f.pairlst[0].a;const e=f.pairlst[0].b;if(t.chr!=null&&e.chr!=null&&t.chr==e.chr&&t.position!=null&&e.position!=null){if(t.position<e.position){if(s.usegm.strand=="+"){t.strand="+";e.strand="+"}else{t.strand="-";e.strand="-";f.pairlst[0].a=e;f.pairlst[0].b=t}}}}}if(s.usegm&&s.gmmode!=F.genomic){f.isoform=s.usegm.isoform;let t=true;for(let e=0;e<f.pairlst.length;e++){const o=f.pairlst[e];if(s.usegm.isoform==(o.a.isoform||o.a.name)){f.useNterm=e==0;f.chr=s.usegm.chr;f.strand=o.a.strand;if(o.a.position==undefined){if(o.a.rnaposition==undefined){if(o.a.codon==undefined){console.error("no position/rnaposition/codon available for "+s.usegm.isoform);break}else{f.pos=U(o.a.codon,s.usegm);o.a.position=f.pos}}else{f.pos=E(o.a.rnaposition-1,s.usegm);if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+o.a.rnaposition);break}o.a.position=f.pos}}else{f.pos=o.a.position}const a=_(f.pos,s.usegm);f.rnapos=a.rnapos;f.aapos=a.aapos;if(o.a.codon){f.aapos=o.a.codon}f.mname=o.b.name;t=false;break}if(s.usegm.isoform==(o.b.isoform||o.b.name)){f.useNterm=false;f.chr=s.usegm.chr;f.strand=o.b.strand;if(o.b.position==undefined){if(o.b.rnaposition==undefined){if(o.b.codon==undefined){console.error("no position/rnaposition/codon available for "+s.usegm.isoform);break}else{f.pos=U(o.b.codon,s.usegm);o.b.position=f.pos}}else{f.pos=E(o.b.rnaposition-1,s.usegm);if(f.pos==null){console.error("failed to convert rnaposition to genomic");break}o.b.position=f.pos}}else{f.pos=o.b.position}const e=_(f.pos,s.usegm);f.rnapos=e.rnapos;f.aapos=e.aapos;if(o.b.codon){f.aapos=o.b.codon}f.mname=o.a.name;t=false;break}}if(t){console.error("sv/fusion isoform no match to gm isoform: "+s.usegm.isoform)}else{e.mlst.push(f)}}else{for(const t of f.pairlst){let o=false,a=false;for(let e=s.startidx;e<=s.stopidx;e++){const n=s.rglst[e];if(t.a.chr==n.chr&&t.a.position>=n.start&&t.a.position<=n.stop){o=true}if(t.b.chr==n.chr&&t.b.position>=n.start&&t.b.position<=n.stop){a=true}}if(o){const s=G(f);const o=t.a;s.chr=o.chr;s.strand=o.strand;s.useNterm=o.strand=="+";s.pos=o.pos||o.position;s.mname=t.b.name||t.b.chr;if(!Number.isFinite(s.pos)){console.error("no genomic pos for breakend a")}else if(!s.chr){console.error("no chromosome for breakend a")}else{e.mlst.push(s)}}if(a){const s=G(f);const o=t.b;s.chr=o.chr;s.strand=o.strand;s.useNterm=o.strand=="+";s.pos=o.pos||o.position;s.mname=t.a.name||t.a.chr;if(!Number.isFinite(s.pos)){console.error("no genomic pos for breakend b")}else if(!s.chr){console.error("no chromosome for breakend b")}else{e.mlst.push(s)}}}}break;case r:case o:if(f.chrpos1&&f.chrpos2){let t=_(f.chrpos1,s.usegm);const e=t.rnapos;t=_(f.chrpos2,s.usegm);const a=t.rnapos;if(e<a){f.pos=f.chrpos1}else{f.pos=f.chrpos2}delete f.chrpos1;delete f.chrpos2;const n=Math.abs(e-a);if(f.dt==r){f.rnaduplength=n}else if(f.dt==o){f.rnadellength=n}}if(f.position){f.pos=f.position;delete f.position}if(!f.pos){if(f.dt==r){if(f.b){if(f.b.position){f.pos=f.b.position;f.chr=f.b.chr}}}}if(!f.pos){if(f.rnaposition){if(s.usegm){f.pos=E(f.rnaposition-1,s.usegm);f.chr=s.usegm.chr;if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+f.rnaposition);break}}}else if(f.aapos);}if(!f.pos){console.error("no genomic pos for itd");break}if(s.usegm){const t=_(f.pos,s.usegm);if(f.rnaposition){f.rnapos=f.rnaposition}else{f.rnapos=t.rnapos}f.aapos=t.aapos}if(f.dt==r){if(!f.rnaduplength){console.error("itd has no rnaduplength");f.rnaduplength=1}}else{if(!f.rnadellength){console.error("deletion has no rnadellength");f.rnadellength=1}}e.mlst.push(f);break;case n:case a:if(f.position){f.pos=f.position;delete f.position}if(!f.pos){if(f.rnaposition){if(s.usegm){f.pos=E(f.rnaposition-1,s.usegm);f.chr=s.usegm.chr;if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+f.rnaposition);break}}}else if(f.aapos);}if(!f.pos){console.error("no genomic pos for truncation");break}if(s.usegm){const t=_(f.pos,s.usegm);if(f.rnaposition){f.rnapos=f.rnaposition}else{f.rnapos=t.rnapos}f.aapos=t.aapos}e.mlst.push(f);break;default:console.error("unknown dt: "+f.dt)}}}function ze(t,e){const s=new Map;for(const t in f){s.set(f[t].label.toUpperCase(),t)}const o=[];for(const[a,n]of t.hlaachange){if(n==false){continue}if(!n.name){e.error("hlaachange item .name missing");continue}if(n.codon==undefined||!Number.isFinite(n.codon)){e.error("hlaachange invalid codon for "+n.name);continue}if(!n.class){e.error("hlaachange .class missing");continue}const t=f[n.class]?n.class:s.get(n.class.toUpperCase());if(!t){e.error("hlaachange invalid class: "+n.class);continue}n.class=t;n.mname=n.name;delete n.name;n.chr=e.usegm.chr;n.pos=U(n.codon,e.usegm);delete n.codon;n.dt=c;n.isoform=e.usegm.isoform;o.push(n)}if(o.length){const t={label:"Highlight",type:D.ds,iscustom:true,bulkdata:{}};t.bulkdata[e.usegm.name.toUpperCase()]=o;e.ownds[t.label]=t;const s=e.block_addtk_template({type:D.ds,ds:t});ne(s,e)}}function Ne(t,e){if(!t.vcfinfofilter)return;for(const s of t.vcfinfofilter.lst){s.holder.selectAll("*").remove();if(s.numericfilter){for(const t of s.numericfilter){t.count=0}for(const e of t.mlst){const[t,o]=Se(s,e);if(t){continue}if(!o)continue;const a=o[0];if(!Number.isFinite(a))continue;for(const t of s.numericfilter){if(t.side=="<"){if(a<t.value){t.count++}}else{if(a>t.value){t.count++}}}}for(const o of s.numericfilter){const a=s.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{if(s.numericCutoff==o.value&&s.numericCutoffSide==o.side){delete s.numericCutoff}else{s.numericCutoff=o.value;s.numericCutoffSide=o.side}fe(t,e)}));if(s.numericCutoff==o.value&&s.numericCutoffSide==o.side){a.style("border-bottom","solid 2px #ccc").style("background-color","#f1f1f1")}if(o.count>0){a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color","#ccc").style("color","white").html(o.count>1?o.count:"&nbsp;").style("margin-right","5px")}a.append("span").text(o.side+o.value)}continue}if(!s.categories){continue}const o=new Map;let a=0;for(const e of t.mlst){const[t,n]=Se(s,e);if(t){continue}if(n==undefined){a++}else{for(const t of n){if(!o.has(t)){o.set(t,0)}o.set(t,o.get(t)+1)}}}const n=[...o];if(a){n.push([$t,a])}n.sort(((t,e)=>e[1]-t[1]));for(const[o,a]of n){const n=s.categories[o]||{color:"black",label:o};const r=s.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{t.vcfinfofilter.tip.showunder(r.node());Ce(s,o,t,e)}));r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color",n.color).style("color","white").html(a>1?a:"&nbsp;").style("margin-right","5px");const i=r.append("span").text(n.label).style("color",n.color);if(s.categoryhidden[o]){i.style("text-decoration","line-through")}}}}function Pe(t,e){if(!t.vcfinfofilter)return;for(const e of t.vcfinfofilter.lst){if(e.numericfilter){continue}if(!e.autocategory){continue}const s=new Map;for(const o of t.mlst){const[t,a]=Se(e,o);if(t){continue}if(a!=undefined){for(const t of a){if(!s.has(t)){s.set(t,0)}s.set(t,s.get(t)+1)}}}const o=[...s];o.sort(((t,e)=>e[1]-t[1]));const a=M(Z);e.categories={};for(const[t,s]of o){e.categories[t]={label:t,color:a(t)}}}}function Se(t,e){if(t.altalleleinfo){if(!e.altinfo)return["no .altinfo"];const s=e.altinfo[t.altalleleinfo.key];if(s==undefined){if(t.numericfilter){return[null,[0]]}return[null,undefined]}let o=Array.isArray(s)?s:[s];if(t.altalleleinfo.separator){o=o[0].split(t.altalleleinfo.separator)}return[null,o]}if(t.locusinfo){if(!e.info)return["no .info"];const s=e.info[t.locusinfo.key];if(s==undefined){if(t.numericfilter){return[null,[0]]}return[null,undefined]}let o=Array.isArray(s)?s:[s];if(t.locusinfo.separator){o=o[0].split(t.locusinfo.separator)}return[null,o]}return["no trigger"]}function Ce(t,e,s,o){const a=s.vcfinfofilter.tip;a.clear();const n=t.categoryhidden[e];a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{a.hide();t.categoryhidden={};for(const s in t.categories){if(s!=e){t.categoryhidden[s]=1}}if(e!=$t){t.categoryhidden[$t]=1}fe(s,o)}));if(n){a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{a.hide();delete t.categoryhidden[e];fe(s,o)}))}else{a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{a.hide();t.categoryhidden[e]=1;fe(s,o)}))}let r=0;for(const e in t.categoryhidden){r++}if(r>1){a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{a.hide();t.categoryhidden={};fe(s,o)}))}}function Fe(t,e){if(!t.vcfid)return[".vcfid missing"];if(!t.sampledata)return[".sampledata missing"];const s=e.ds.id2vcf[t.vcfid];if(!s)return["no vcf"];if(!s.samples||s.samples.length==0)return["vcf no samples"];let o=0;for(const e of t.sampledata){if(!e.gtallref)o++}return[null,o/s.samples.length]}function Re(t,e){if(!t.populationfrequencyfilter)return;for(const e of t.populationfrequencyfilter.lst){e.count=0}for(const e of t.mlst){const[s,o]=Fe(e,t);if(s){continue}for(const e of t.populationfrequencyfilter.lst){if(o<e.value){e.count++}}}t.populationfrequencyfilter.holder.selectAll("*").remove();for(const s of t.populationfrequencyfilter.lst){const o=t.populationfrequencyfilter.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{if(t.populationfrequencyfilter.cutoff==s.value){delete t.populationfrequencyfilter.cutoff}else{t.populationfrequencyfilter.cutoff=s.value}fe(t,e)}));if(t.populationfrequencyfilter.cutoff==s.value){o.style("border-bottom","solid 2px #ccc").style("background-color","#f1f1f1")}o.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color","#ccc").style("color","white").html(s.count>1?s.count:"&nbsp;").style("margin-right","5px");o.append("span").text("< "+s.value)}}function Ie(t,e){if(!t.ds||!t.ds.cohort||!t.ds.cohort.sampleattribute)return;if(!t.ds.cohort.annotation)return".ds.cohort.annotation missing";if(!t.ds.cohort.key4annotation)return".ds.cohort.key4annotation missing";const s=t.ds.cohort.sampleattribute;if(!s.lst)return".lst missing";if(!s.holder)return".holder missing";s.holder.selectAll("*").remove();if(t.mlst.length==0){return}for(const t of s.lst){if(!t.k)return".k missing for an attribute";if(!t.hiddenvalues)t.hiddenvalues=new Set}const o=[];if(t.mlst[0].sampledata){for(const e of s.lst){let s=0;const a=new Map;for(const o of t.mlst){if(!o.sampledata)continue;for(const n of o.sampledata){const o=n.sampleobj[t.ds.cohort.key4annotation];if(!o)continue;const r=t.ds.cohort.annotation[o];if(!r)continue;const i=r[e.k];if(i==undefined)continue;s++;if(!a.has(i)){a.set(i,0)}a.set(i,a.get(i)+1)}}if(s==0){continue}o.push({samplecount:s,key:e,lst:[...a].sort(((t,e)=>e[1]-t[1])).map((t=>({value:t[0],count:t[1]})))})}}else{for(const e of s.lst){let s=0;const a=new Map;for(const o of t.mlst){const n=o[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[e.k];if(i==undefined)continue;s++;if(!a.has(i)){a.set(i,0)}a.set(i,a.get(i)+1)}if(s==0){continue}o.push({samplecount:s,key:e,lst:[...a].sort(((t,e)=>e[1]-t[1])).map((t=>({value:t[0],count:t[1]})))})}}if(o.length==0){delete s.runtimelst;return}s.runtimelst=o;const a=s.holder.append("table").style("border-spacing","5px");for(const n of o){const o=a.append("tr");o.append("td").style("color","#858585").style("text-align","right").text(n.key.label||n.key.k);const r=o.append("td");for(const o of n.lst){const a=r.append("div").style("display","inline-block").style("padding","5px").attr("class","sja_clb").on("click",(()=>{s.tip.showunder(a.node());Be(o,n,s.tip,t,e)}));a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 3px").style("background-color","#858585").style("color","white").html(o.count>1?o.count:"&nbsp;").style("margin-right","5px");const i=a.append("span").text(o.value);if(n.key.hiddenvalues.has(o.value)){i.style("text-decoration","line-through")}}}return null}function Be(t,e,s,o,a){s.clear();s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{s.hide();for(const t of e.lst){e.key.hiddenvalues.add(t.value)}e.key.hiddenvalues.delete(t.value);fe(o,a)}));if(e.key.hiddenvalues.has(t.value)){s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{s.hide();e.key.hiddenvalues.delete(t.value);fe(o,a)}))}else{s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{s.hide();e.key.hiddenvalues.add(t.value);fe(o,a)}))}if(e.key.hiddenvalues.size>1){s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{s.hide();e.key.hiddenvalues.clear();fe(o,a)}))}}function qe(t,e,s){let o=0;let a=0;let n=[];let r=[];for(const i of t.mlst){delete i.__x;if(e.legend&&e.legend.mclasses.has(i.class)&&e.legend.mclasses.get(i.class).hidden){continue}if(e.legend&&e.legend.morigins.has(i.origin)&&e.legend.morigins.get(i.origin).hidden){continue}if(i.origin&&s.has(i.origin)){continue}if(e.gmmode==V.protein&&e.usegm.codingstart&&e.usegm.codingstop){if(i.pos<e.usegm.codingstart||i.pos>e.usegm.codingstop)continue}if(t.vcfinfofilter){let e=false;for(const s of t.vcfinfofilter.lst){const[t,o]=Se(s,i);if(t){continue}const a=o==undefined?[$t]:o;if(s.numericCutoff!=undefined){const t=Number.parseFloat(a[0]);if(Number.isNaN(t)){e=true;break}if(s.numericCutoffSide=="<"){if(t>=s.numericCutoff){e=true;break}}else if(s.numericCutoffSide==">"){if(t<=s.numericCutoff){e=true;break}}}else if(s.categoryhidden){let t=false;for(const e of a){if(!s.categoryhidden[e]){t=true;break}}if(!t){e=true;break}}}if(e){continue}}if(t.populationfrequencyfilter&&t.populationfrequencyfilter.cutoff){const[e,s]=Fe(i,t);if(e);else{if(s>t.populationfrequencyfilter.cutoff){continue}}}if(t.ds&&t.ds.cohort&&t.ds.cohort.annotation&&t.ds.cohort.key4annotation&&t.ds.cohort.sampleattribute&&t.ds.cohort.sampleattribute.runtimelst){let e=0;for(const s of t.ds.cohort.sampleattribute.runtimelst){if(s.key&&s.key.hiddenvalues){e+=s.key.hiddenvalues.size}}if(e>0){if(t.ds.vcfcohorttrack);else if(i.sampledata){let e=0;for(const s of i.sampledata){if(!O(s.genotype,i.alt)){continue}const o=s.sampleobj[t.ds.cohort.key4annotation];if(o){const e=t.ds.cohort.annotation[o];if(e){let s=false;for(const o of t.ds.cohort.sampleattribute.runtimelst){const t=e[o.key.k];if(t!=undefined){if(o.key.hiddenvalues.has(t)){s=true;break}}}if(s){continue}}}e++}if(e==0){continue}}else{const e=i[t.ds.cohort.key4annotation];if(e){const s=t.ds.cohort.annotation[e];if(s){let e=false;for(const o of t.ds.cohort.sampleattribute.runtimelst){const t=s[o.key.k];if(t!=undefined){if(o.key.hiddenvalues.has(t)){e=true;break}}}if(e){continue}}}}}}if(!i.chr){a++;continue}if(!Number.isInteger(i.pos)){o++;continue}const l=e.seekcoord(i.chr,i.pos);if(l.length==0){n.push(i);continue}if(l.length==1){i.__x=l[0].x}else{i.__x=l[0].x}if(i.__x<-1||i.__x>e.width+1){continue}r.push(i)}const i=[];t.tklabel.each((function(){i.push(this.getBBox().width)}));if(r.length==0){t.label_mcount.text("")}else{t.label_mcount.text(r.length<t.mlst.length?r.length+" of "+t.mlst.length+" "+t.itemlabelname+"s":r.length+" "+t.itemlabelname+(r.length>1?"s":"")).each((function(){i.push(this.getBBox().width)}))}if(t.label_stratify){for(const e of t.label_stratify){let s;if(e.bycohort){const e=new Set;for(const s of r){let o="";for(const e of t.ds.cohort.levels){const t=s[e.k];if(t){o+=t}}e.add(o)}s=e.size}else{const t=new Set;for(const s of r){let o=s[e.attr1.k];if(!o)continue;if(e.attr2){const t=s[e.attr2.k];if(t){o+=t}}if(e.attr3){const t=s[e.attr3.k];if(t){o+=t}}t.add(o)}s=t.size}if(s==0){e.svglabel.text("")}else{e.svglabel.text(s+" "+e.label+(s>1?"s":"")).each((function(){i.push(this.getBBox().width)}))}}}t.leftLabelMaxwidth=Math.max(...i);if(o+a>0){e.tkerror(t,o+a+" items have no chromosome or genomic position")}if(n.length){console.error(n.length+" items not mapped to any region");for(const t of n)console.log(t)}return r}function De(t,e){for(const s of t.data){if(s.isbin){let t=0;for(const o of s.mlst){const s=e.seekcoord(o.chr,o.pos);if(o.usehitidx!=undefined&&s[o.usehitidx]){t+=s[o.usehitidx].x}else if(s.length==1){t+=s[0].x}else{console.log("cannot map item");console.log(o)}}s.x0=t/s.mlst.length;s.x=s.x0+(s.xoffset!=undefined?s.xoffset:0)}else{const t=e.seekcoord(s.chr,s.pos);if(t.length>0){s.x0=t[0].x;s.x=s.x0+(s.xoffset!=undefined?s.xoffset:0)}else{console.log("cannot map group of item");console.log(s)}}}}function Le(t,e){t.height_main=t.toppad+e.labelfontsize+t.bottompad;if(t.label_mcount&&t.label_mcount.text().length>0){t.height_main+=t.labyspace+e.labelfontsize}if(t.label_stratify){for(const s of t.label_stratify){if(s.svglabel.text().length>0){t.height_main+=t.labyspace+e.labelfontsize}}}t.glider.selectAll("*").remove();t.leftaxis.selectAll("*").remove();if(t.viewrangeupperlimit_above){e.tkerror(t,t.name+": zoom in under "+T(t.viewrangeupperlimit)+" to view data")}else{let s;if(!t.skewer.data||t.skewer.data.length==0){if(e.pannedpx!=undefined||e.zoomedin==true){s="view range"}else if(e.usegm&&e.gmmode!="genomic"){s=e.usegm.name||e.usegm.isoform}}e.tkerror(t,t.name+": no mutation in "+s)}if(t.hlaachange){ze(t,e);delete t.hlaachange}}function Ee(t,e){if(!t.stratifycount)return;for(const[s,o]of t.stratifycount){const t=e.label_stratify.find((t=>t.label==s));if(!t){console.error("unknown strat label: "+s);continue}t.servercount=o}}const Ue=new H({padding:"0px"});function Ge(t,e){const s=t.legend.holder.append("tr");const o=s.append("td").text(e).style("padding-right","10px").style("text-align","right").style("color","#555").style("border-right","solid 1px "+t.legend.legendcolor);const a=s.append("td");return[s,a,o]}function Ve(t){if(!t.legend){return}const e=new Set;for(const[s,o]of t.legend.mclasses){if(o.hidden){e.add(s)}}const s=new Map;for(const e of t.tklst){if(e.hidden||e.type!=D.ds)continue;if(!e.mlst){continue}for(const t of e.mlst){if(t.class){if(!s.has(t.class)){s.set(t.class,{count:0})}s.get(t.class).count++}}}const o=[];for(const[t,a]of s){if(e.has(t)){s.get(t).hidden=true}o.push({key:t,count:a.count})}t.legend.mclasses=s;if(s.size==0){t.legend.tr_mclass.style("display","none");return}t.legend.tr_mclass.style("display","table-row");o.sort(((t,e)=>e.count-t.count));t.legend.td_mclass.selectAll("*").remove();for(const s of o){const o=t.legend.td_mclass.append("div").style("display","inline-block").style("white-space","nowrap").style("padding",t.legend.vpad+" 20px "+t.legend.vpad+" 0px").classed("sja_clb",true).on("click",(()=>{Ue.clear();Ue.showunder(o.node());Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.mclasses.values()){e.hidden=true}t.legend.mclasses.get(s.key).hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}));if(t.legend.mclasses.get(s.key).hidden){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.mclasses.get(s.key).hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}else{Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.mclasses.get(s.key).hidden=true;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}if(e.size>1){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.mclasses.values()){e.hidden=false}for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}const a=Ue.d.append("div").style("margin","20px");a.append("div").text(f[s.key].label.toUpperCase()).style("color",f[s.key].color).style("font-size",".8em");a.append("div").html(f[s.key].desc).style("color","#858585").style("font-size",".8em").style("width","210px")}));o.append("div").style("display","inline-block").style("background-color",f[s.key].color).style("margin-right","5px").style("border-radius","15px").style("padding","4px 8px").style("color","white").style("font-size",".8em").text(s.count);const a=o.append("div").style("display","inline-block").style("color",f[s.key].color).text(f[s.key].label);if(e.has(s.key)){a.style("text-decoration","line-through")}}}function Oe(t){if(!t.legend){return}const e=new Set;for(const[s,o]of t.legend.morigins){if(o.hidden){e.add(s)}}const s=new Map;for(const o of t.tklst){if(o.hidden||o.type!=D.ds)continue;if(!o.mlst){continue}for(const t of o.mlst){if(!t.origin)continue;if(!s.has(t.origin)){let o=false;if(L[t.origin]&&L[t.origin].hidden){o=true;e.add(t.origin)}s.set(t.origin,{count:0,hidden:o})}s.get(t.origin).count++}}const o=[];for(const[t,a]of s){if(e.has(t)){s.get(t).hidden=true}o.push({key:t,count:a.count})}t.legend.morigins=s;if(s.size==0){t.legend.tr_morigin.style("display","none");return}t.legend.tr_morigin.style("display","table-row");o.sort(((t,e)=>e.count-t.count));t.legend.td_morigin.selectAll("*").remove();for(const s of o){const o=t.legend.td_morigin.append("div").style("display","inline-block").style("white-space","nowrap").style("padding",t.legend.vpad+" 20px "+t.legend.vpad+" 0px").classed("sja_clb",true).on("click",(()=>{Ue.clear();Ue.showunder(o.node());Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.morigins.values()){e.hidden=true}t.legend.morigins.get(s.key).hidden=false;L[s.key].hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}));if(t.legend.morigins.get(s.key).hidden){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.morigins.get(s.key).hidden=false;L[s.key].hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}else{Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.morigins.get(s.key).hidden=true;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}if(e.size>1){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.morigins.values()){e.hidden=false}for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}const a=Ue.d.append("div").style("margin","20px");a.append("div").text(L[s.key].label.toUpperCase()).style("color",L[s.key].color).style("font-size",".8em");a.append("div").html(L[s.key].desc).style("color","#858585").style("font-size",".8em").style("width","210px")}));o.append("svg").style("margin-right","5px").attr("width",19).attr("height",19).html(L[s.key].legend);const a=o.append("div").style("display","inline-block").style("color","#858585").text(L[s.key].label+", "+s.count);if(e.has(s.key)){a.style("text-decoration","line-through")}}}export{fe as a,ht as b,bt as c,ne as d,yt as e,_e as f,mt as g,he as h,$ as i,Ve as j,Oe as k,Ge as l,Ut as m,gt as r,ye as s};
1
+ import{Z as t,B as e,ap as s,aP as o,aQ as a,aR as n,ar as r,at as i,as as l,ak as c,z as f,a9 as d,p,ac as u,b6 as m,b7 as h,aN as g,q as b,b8 as y,j as x,b9 as k,ba as v,a7 as w,aG as _,bb as j,a8 as M,af as A,aM as z,aL as N,r as P,aW as S,d as C,aF as F,I as R,ah as I,W as B,ag as q,ad as D,O as L,aJ as E,bc as U,bd as G,be as V,bf as O,ae as T,M as H}from"./app-2cd97738.js";import{v as X,a as Y}from"./vcf-145bf5dd.js";import{p as J}from"./partition-db811f6b.js";import{d as Q}from"./arc-3d6751aa.js";import{b as W}from"./axis-747c801e.js";import{s as Z}from"./legacy-d3-polyfill-bdb2d792.js";const K="__";function $(f){const{mlst:d,tk:p,block:u}=f;if(!d||d.length==0)return;let m;if(f.pane){const e=t({x:f.x,y:f.y});e.header.html(tt(d));m=e.body}else{m=f.holder}if(!m){console.error("no holder provided for showing table");return}const h=new Map;for(const t of d){if(!h.has(t.dt)){h.set(t.dt,[])}h.get(t.dt).push(t)}delete p.__singlevariant_table;for(const[t,f]of h){const d=m.append("div").style("margin","10px");if(h.size>1){d.append("p").text(e[t]).style("color","#858585")}switch(t){case c:et(f,d,p,u);break;case l:case i:ct(f,d,p,u);break;case r:dt(f,d,p,u.genome);break;case n:case a:ut(f,d,p,u.genome);break;case o:pt(f,d,p,u.genome);break;case s:d.append("p").text("cnv not supported yet");break;default:d.append("p").text("unknown dt: "+t)}}Ft(d,m,p,u)}function tt(t){if(t.length==1){const e=t[0];const d=f[e.class];if(e.dt==c){return'<span style="font-weight:bold;color:'+d.color+'">'+(e.mname?e.mname:e.pos?e.chr+":"+(e.pos+1):"")+'</span> <span style="font-size:80%">'+d.label+"</span>"}if(e.dt==l||e.dt==i){const t=[];for(let s=0;s<e.pairlst.length;s++){if(s==0)t.push(e.pairlst[s].a.name?e.pairlst[s].a.name:e.pairlst[s].a.chr);t.push(e.pairlst[s].b.name?e.pairlst[s].b.name:e.pairlst[s].b.chr)}return t.join(" - ")+'&nbsp;&nbsp;<span style="font-size:80%">'+d.label+"</span>"}if(e.dt==n||e.dt==a||e.dt==r||e.dt==o||e.dt==s){return'<span style="font-size:80%">'+d.label+"</span>"}return"unknown dt "+e.dt}const d=new Set;for(const e of t){d.add(e.dt)}if(d.size==1){const s=[...d][0];return t.length+" "+e[s]}return t.length+" mutations"}function et(e,s,o,a){if(o.ds&&o.ds.id2vcf){if(e.length==1){const t=o.ds.id2vcf[e[0].vcfid];if(!t){s.append("p").text("No vcf config file (id: "+e[0].vcfid+")");return}at(e[0],t,s,o,a);return}for(const n of e){const e=o.ds.id2vcf[n.vcfid];if(!e){s.append("p").text("No vcf config file (id: "+n.vcfid+")");continue}const r=s.append("div").attr("class","sja_menuoption").on("click",(s=>{const r=t({x:s.clientX+100,y:Math.max(100,s.clientY-100)});at(n,e,r.body,o,a)}));if(n.mname){r.append("span").html(n.mname+'\t<span style="font-size:80%;color:#858585">'+f[n.class].label+"</span>")}else if(n.csq){r.append("span").html(n.csq[0]._mname+'\t<span style="font-size:80%;color:#858585">'+n.csq[0].Consequence+"</span>")}r.append("span").html("&nbsp;&nbsp;"+n.chr+":"+(n.pos+1)+' <span style="font-size:70%">REF</span> '+n.ref+' <span style="font-size:70%">ALT</span> '+n.alt)}return}const n=a.genome.hasSNP;const r={chr:null,bprange:[],holder:null,says:null};const i={set:new Map,butholder:null};for(const t of e){if(n&&t.chr&&t.pos){r.chr=t.chr;let e=true;for(const s of r.bprange){if(s.start<=t.pos&&s.stop>=t.pos){e=false;break}}if(e){r.bprange.push({start:t.pos,stop:t.pos+1})}}}if(!o.snvindelattr){mt(o,e)}if(a.variantPageCall_snv){i.butholder=s.append("div").style("margin","10px")}if(e.length==1){const t=e[0];r.alleleLst=[t.ref,t.alt];if(a.variantPageCall_snv){if(t.chr!=undefined&&t.pos!=undefined&&t.ref!=undefined&&t.alt!=undefined){i.set.set(t.chr+K+t.pos+K+t.ref+K+t.alt,{mname:t.mname,class:t.class})}}const l=[];for(const e of o.snvindelattr){if(e.lst){const s=[];for(const o of e.lst){if(o.ismaf){const e=o.get(t);s.push({k:o.label,v:e?Number.isFinite(e.f)?'<span style="color:'+o.fill+'">'+(e.f*100).toFixed(0)+"% ("+e.v1+"/"+e.v2+")</span>":"n/a":""})}else{s.push({k:o.label,v:o.get(t)})}}if(s.length){l.push({k:e.label,kvlst:s})}}else if(e.ismaf){const s=e.get(t);l.push({k:e.label,v:s?Number.isFinite(s.f)?'<span style="color:'+e.fill+'">'+(s.f*100).toFixed(0)+"% ("+s.v1+"/"+s.v2+")</span>":"n/a":""})}else{let s=e.get(t);if(e.hover){const o=e.hover(t);if(o){s+=' <span style="color:#aaa;font-size:80%">'+o+"</span>"}}l.push({k:e.label,v:s})}}const c=d(s,l);if(n){const t=c.append("tr");t.append("td").attr("colspan",2).style("color","#9e9e9e").text("dbSNP");r.says=t.append("td").text("loading...")}const f=s.append("div").style("margin-top","10px");if(o.eplst){for(const t of o.eplst){lt(t,f,e)}}if(o.ds&&o.ds.snvindel_legend){f.append("button").text("Legend").on("click",(()=>{if(t.style("display")=="none"){p(t)}else{u(t)}}));const t=f.append("div").style("display","none").style("margin","10px").style("width","400px").html(o.ds.snvindel_legend)}}else{if(a.variantPageCall_snv){for(const t of e){if(t.chr!=undefined&&t.pos!=undefined&&t.ref!=undefined&&t.alt!=undefined){i.set.set(t.chr+K+t.pos+K+t.ref+K+t.alt,{mname:t.mname,class:t.class})}}}const t=s.append("table").style("border-spacing","3px").style("border-collapse","separate").style("margin","0px 7px 7px 0px").style("font-size","90%").style("color","black").style("background-color","white");st(e,t,o.snvindelattr,o);const l=s.append("div").style("margin","10px 5px");let c,f,d;l.append("button").text("Table columns").on("click",(function(){if(c.style("display")=="block"){this.style.color="black";u(c)}else{this.style.color="red";p(c)}}));if(n&&r.bprange.length){r.button=l.append("button").text("loading...").on("click",(function(){if(f.style("display")=="block"){this.style.color="black";u(f)}else{this.style.color="red";p(f)}}))}if(o.eplst){for(const t of o.eplst){lt(t,l,e)}}if(o.ds&&o.ds.snvindel_legend){l.append("button").text("Legend").on("click",(function(){if(d.style("display")=="block"){this.style.color="black";u(d)}else{this.style.color="red";p(d)}}))}c=s.append("div").style("margin","10px").style("display","none");for(const s of o.snvindelattr){const a=Math.random();const n=c.append("input").attr("type","checkbox").attr("id",a);if(!s.hide)n.attr("checked",true);n.on("change",(()=>{s.hide=!n.node().checked;st(e,t,o.snvindelattr,o)}));c.append("label").attr("for",a).text(s.label);c.append("br")}if(n){f=s.append("div").style("margin","10px").style("display","none");r.holder=f;r.says=f}if(o.ds&&o.ds.snvindel_legend){d=s.append("div").style("display","none").style("width","300px").html(o.ds.snvindel_legend)}}if(n&&r.bprange.length){m(r.chr,r.bprange,a.genome,r.alleleLst).then((t=>{if(!t||t.length==0)throw{message:"no SNP"};r.says.text("");if(r.button){r.button.text(t.length+" SNP"+(t.length>1?"s":""))}for(const e of t){const t=r.says.append("div");h(e,t)}})).catch((t=>{r.says.text(t.message);if(r.button){r.button.attr("disabled",true)}if(t.stack)console.log(t.stack)}))}if(a.variantPageCall_snv){const t=[];for(const[e,s]of i.set){const o=e.split(K);t.push({chr:o[0],position:Number.parseInt(o[1])+1,refallele:o[2],altallele:o[3],class:s.class,aachange:s.mname})}if(t.length==1){const e=t[0];e.container=i.butholder;a.variantPageCall_snv(e)}else if(t.length>1){i.butholder.append("div").classed("sja_variantpagesnv",true).text("Variant Page").on("click",(e=>{const s=o.tktip.clear().showunder(e.target).d.append("table");for(const e of t){const t=s.append("tr");t.append("td").text(e.aachange);t.append("td").text(f[e.class].label).style("font-size",".7em").style("color",f[e.class].color);t.append("td").text(e.chr+":"+e.position+" "+e.refallele+">"+e.altallele).attr("font-size",".7em");e.container=t.append("td");a.variantPageCall_snv(e)}}))}}}function st(t,e,s,o,a){e.selectAll("*").remove();let n=null;for(const t of s){if(t.lst){for(const e of t.lst){if(e.sort)n=e}}else if(t.sort)n=t}if(n){t.sort(((t,e)=>{const s=n.get(t);const o=n.get(e);if(n.ismaf){if(s==undefined){if(o==undefined)return 0;return 1}else{if(o==undefined)return-1;return n.descend?o.f-s.f:s.f-o.f}}if(s==undefined||s===""){if(o==undefined||o==="")return 0;return 1}if(o==undefined||o==="")return-1;if(typeof s=="string"){if(s<o)return n.descend?1:-1;if(s>o)return n.descend?-1:1}if(typeof s=="number")return n.descend?o-s:s-o;return 0}))}const r=e.append("tr");const i=e.append("tr");r.append("td").attr("rowspan",2);for(const n of s){if(n.hide)continue;if(n.lst){r.append("td").attr("colspan",n.lst.length).style("color","#aaa").style("border-bottom","solid 1px #ccc").style("text-align","center").html(n.label);for(const r of n.lst){i.append("td").attr("class","sja_clbtext").html(r.label+(r.sort?r.descend?" &#9660;":" &#9650;":"")).on("click",(()=>{if(r.sort){r.descend=!r.descend}for(const t of s){if(t.lst){for(const e of t.lst)e.sort=false}else{t.sort=false}}r.sort=true;st(t,e,s,o,a)}))}}else{r.append("td").attr("rowspan",2).attr("class","sja_clbtext").html(n.label+(n.sort?n.descend?" &#9660;":" &#9650;":"")).on("click",(()=>{if(n.sort){n.descend=!n.descend}for(const t of s){if(t.lst){for(const e of t.lst)e.sort=false}else{t.sort=false}}n.sort=true;st(t,e,s,o,a)}))}}const l=t.length>1e3?900:t.length;for(let n=0;n<l;n++){const r=t[n];const i=e.append("tr").attr("class","sja_tr");if(a){i.on("click",(()=>a(r)))}if(o.eplst){i.on("mouseover",((t,e)=>{for(const t of o.eplst)t.may_hl([r],true)})).on("mouseout",((t,e)=>{for(const t of o.eplst)t.may_hl([r],false)}))}i.append("td").style("font-size",".8em").text(n+1);for(const t of s){if(t.hide)continue;if(t.lst){for(const e of t.lst){const t=i.append("td");if(e.ismaf){const s=e.get(r);if(s&&typeof s=="object"){if(s.v2==0){t.text("0/0");t.attr("aria-label","No coverage")}else{g(t,s,e)}}}else{t.html(e.get(r))}}}else{const e=i.append("td");if(t.hover){const s=t.hover(r);if(s!=undefined){e.attr("aria-label",s)}}if(t.tablecellwidth){e.style("width",t.tablecellwidth).style("word-break","break-all")}if(t.ismaf){const s=t.get(r);if(s){if(s.v2==0){e.text("0/0");e.attr("aria-label","No coverage")}else{g(e,s,t)}}}else{e.html(t.get(r))}}}}}function ot(t){return'<span style="font-size:70%;color:#858585">'+t+"</span>"}function at(t,e,s,o,a){if(!e){s.append("p").text("vcfobj config object missing");return}const n=s.append("div").style("margin-top","10px");n.append("span").text(t.type).style("padding-right","10px");n.append("span").text(t.chr+":"+(t.pos+1)).style("padding-right","10px");if(t.dt==c){n.append("span").style("padding-right","10px").html(ot("REF")+" "+t.ref+" "+ot("ALT")+" "+t.alt);if(a.variantPageCall_snv){const e={chr:t.chr,position:t.pos+1,refallele:t.ref,altallele:t.alt,container:n.append("span").style("padding-left","20px")};a.variantPageCall_snv(e)}if(o.button4variant){zt(n,t,o.button4variant)}if(o.url4variant){At(n,t,o.url4variant)}}if(e.info&&e.info.CSQ&&e.info.CSQ.csqheader&&t.csq){vt(t.csq,n,o,e.info.CSQ.csqheader)}if(e.info&&e.info.ANN&&e.info.ANN.annheader&&t.ann){wt(t.ann,n,o,e.info.ANN.annheader)}if(o.variant2img){_t(t,n,s.append("div"),o)}const r=s.append("div");if(Pt(t,o,r)){r.style("margin-top","10px")}else if(t.sampledata){const e=r.append("div");Promise.resolve().then((()=>{if(t.sampledata.length==0&&o.ds.vcfcohorttrack){e.text("Loading ...");return Mt(t,o,a).then((e=>{if(!e){return}t.sampledata=e.sampledata;return}))}return})).then((()=>{e.remove();if(t.sampledata.length==0){return}if(t.sampledata.length==1){St(t,o,r);return}if(Nt(t,o,r)){r.style("margin-top","10px")}else if(jt(t,o,r)){r.style("margin-top","10px")}else if(Pt(t,o,r)){r.style("margin-top","10px")}else{kt(t,n,o)}})).catch((t=>{e.text(t)}))}if(e.infopipejoin){const o=[];if(t.altinfo){for(const s of e.infopipejoin){const e=t.altinfo[s.key];if(e){if(Array.isArray(e)){o.push(e)}else{o.push(e.split(/[,|]/))}}else{o.push([])}}}if(o.length){const t=s.append("div");for(let s=0;s<o[0].length;s++){const a=[];for(let t=0;t<e.infopipejoin.length;t++){const n=e.infopipejoin[t];a.push({k:n.label,v:n.values?n.values[o[t][s]]:o[t][s]})}d(t,a).style("display","inline-block").style("border","solid 1px black").style("margin","20px")}}}nt(t,s,o);rt(t,s,o);const i={};const l={};if(o.vcfinfofilter){for(const t of o.vcfinfofilter.lst){if(t.categories){if(t.altalleleinfo){i[t.altalleleinfo.key]=t.categories}else if(t.locusinfo){l[t.locusinfo.key]=t.categories}}}}{const o=[];for(const s in t.altinfo){const a=Array.isArray(t.altinfo[s])?t.altinfo[s]:[t.altinfo[s]];let n;if(i[s]){n=a.map((t=>{const e=i[s][t];if(e){return'<span style="padding:1px 3px;background:'+e.color+";color:"+(e.textcolor||"black")+';">'+t+"</span>"}return t}))}else{n=a}o.push({k:s,v:n.join(", ")+(e.info&&e.info[s]?' <span style="font-size:70%;color:#858585">'+e.info[s].Description+"</span>":"")})}if(o.length){s.append("h3").text("Alternative allele:");d(s,o)}}{const a=[];for(const s in t.info){if(o.info2table&&o.info2table[s]){continue}const n=Array.isArray(t.info[s])?t.info[s]:[t.info[s]];let r;if(l[s]){r=n.map((t=>{const e=l[s][t];if(e){return'<span style="padding:1px 3px;background:'+e.color+";color:"+(e.textcolor||"black")+';">'+t+"</span>"}return t}))}else{r=n}a.push({k:s,v:r.join(", ")+(e.info&&e.info[s]?' <span style="font-size:70%;color:#858585">'+e.info[s].Description+"</span>":"")})}if(a.length){s.append("h3").text("This locus:");d(s,a)}}}function nt(t,e,s){if(!s.info2singletable)return;for(const o in s.info2singletable){const a=s.info2singletable[o];const n=t.info[o];if(!n||!n[0])continue;const r=[];const i=n[0].split(a.col_separator);for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;r.push({k:a.fields[t].name,v:it(a,i,t)})}d(e,r)}}function rt(t,e,s){if(!s.info2table)return;for(const o in s.info2table){const a=s.info2table[o];const n=t.info[o];if(!n)continue;if(a.separate_tables){const t=JSON.parse(JSON.stringify(a.separate_tables));t.forEach((t=>t.rows=[]));for(const e of n){const s=e.split(a.col_separator);const o=new Map;for(let t=0;t<a.fields.length;t++){o.set(a.fields[t].name,s[t])}for(const e of t){if(e.groupers.reduce(((t,e)=>o.get(e.field)==e.value?t:false),true)){e.rows.push(o)}}}for(const s of t){if(s.rows.length==0)continue;e.append("h3").html(s.headhtml);const t=e.append("table").style("border-spacing","2px").style("border-collapse","separate").style("font-size","90%");const o=t.append("tr");for(const t of a.fields){if(t.hide)continue;o.append("td").text(t.name)}for(const e of s.rows){const s=t.append("tr").attr("class","sja_tr");const o=a.fields.map((t=>e.get(t.name)));for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;const e=s.append("td");e.html(it(a,o,t))}}}continue}const r=e.append("table").style("border-spacing","2px").style("border-collapse","separate").style("font-size","90%");const i=r.append("tr");for(const t of a.fields){if(t.hide)continue;i.append("td").text(t.name)}for(const t of n){const e=r.append("tr").attr("class","sja_tr");const s=t.split(a.col_separator);for(let t=0;t<a.fields.length;t++){if(a.fields[t].hide)continue;const o=e.append("td");o.html(it(a,s,t))}}}}function it(t,e,s){const o=t.fields[s];if(o.hide)return;let a=e[s];if(a==undefined)return;if(o.eval){a=(0,eval)('"'+a+'"')}if(o.isurl)return"<a href="+a+" target=_blank>"+a+"</a>";if(o.appendUrl){if(o.separator){return a.split(o.separator).map((t=>"<a href="+o.appendUrl+t+" target=_blank>"+t+"</a>")).join(", ")}return"<a href="+o.appendUrl+a+" target=_blank>"+a+"</a>"}if(o.insert2url){return"<a href="+o.insert2url.left+a+o.insert2url.right+" target=_blank>"+a+"</a>"}if(o.ampersand2br)return a.replace(/&/g,"<br>");if(o.urlMatchLst){const t=a.toLowerCase();const e=t.split(o.urlMatchLst.separator)[o.urlMatchLst.idIndex];if(e){for(const s of o.urlMatchLst.types){if(t.indexOf(s.type)!=-1){if(s.appendUrl){return'<span style="font-size:.7em">'+s.type.toUpperCase()+"</span> <a href="+s.appendUrl+e+" target=_blank>"+e+"</a>"}}}}}return a}function lt(t,e,s){let o=true;for(const e of s){if(e[t.p.sampletype]in t.sampletype2value){o=false;break}}if(o){return}let a=false;e.append("button").text("Highlight in "+t.p.name).on("click",(()=>{a=!a;t.may_hl(s,a)}))}function ct(t,e,s,o){const a=e.append("div").style("margin-bottom","10px");ft(t[0].pairlst,o,a);if(!s.svattr){yt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.svattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const n=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const r=n.append("tr");for(const t of s.svattr){r.append("td").text(t.label)}st(t,n,s.svattr,s,(t=>{a.selectAll("*").remove();ft(t.pairlst,o,a)}));if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function ft(t,e,s){for(const e of t){if(e.a.isoform){e.a.gm={isoform:e.a.isoform}}if(e.b.isoform){e.b.gm={isoform:e.b.isoform}}}const o={jwt:e.jwt,hostURL:e.hostURL,pairlst:t,genome:e.genome,holder:s};import("./svgraph-6ab3011b.js").then((t=>{t.default(o)}))}function dt(t,e,s,o){if(!s.itdattr){bt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.itdattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.itdattr){n.append("td").text(t.label)}st(t,a,s.itdattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function pt(t,e,s,o){if(!s.delattr){gt(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.delattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.delattr){n.append("td").text(t.label)}st(t,a,s.delattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function ut(t,e,s,o){if(!s.truncattr){ht(s,t)}if(t.length==1){const o=t[0];const a=[];for(const t of s.truncattr){a.push({k:t.label,v:t.get(o)})}d(e,a);if(s.eplst){const o=e.append("div").style("margin-top","10px");for(const e of s.eplst){lt(e,o,t)}}return}const a=e.append("table").style("font-size","90%").style("border-spacing","2px").style("border-collapse","separate");const n=a.append("tr");for(const t of s.truncattr){n.append("td").text(t.label)}st(t,a,s.truncattr,s);if(s.eplst){const o=e.append("div").style("margin-top","5px");for(const e of s.eplst){lt(e,o,t)}}}function mt(t,e){t.snvindelattr=[];if(t.ds&&t.ds.snvindel_attributes){for(const e of t.ds.snvindel_attributes){t.snvindelattr.push(e)}}else{const s=new Set(["pos","aapos","rnapos","dt","vcfid","isrim1","isrim2","alt","__x"]);if(t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k)}}const o=[];for(const t in e[0]){if(s.has(t))continue;switch(t){case"chr":o.push({label:"Genome pos.",get:t=>t.chr+":"+(t.pos+1)});break;case"class":o.push({label:"Class",get:t=>f[t.class].label});break;case"mname":o.push({label:"Mutation",get:t=>t.mname});break;case"ref":o.push({label:"Allele",lst:[{label:"Ref",get:t=>t.ref},{label:"Alt",get:t=>t.alt}]});break;case"pmid":o.push(xt());break;case"maf_tumor":o.push({get:t=>t.maf_tumor,ismaf:true,width:40,height:12,label:"Tumor MAF",fill:"#ff4d4d",fillbg:"#ffcccc"});break;case"maf_normal":o.push({get:t=>t.maf_normal,ismaf:true,width:40,height:12,label:"Germline MAF",fill:"#4d4dff",fillbg:"#ccccff"});break;default:o.push({label:t,get:e=>e[t]})}}t.snvindelattr=o}if(t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){t.snvindelattr.push({label:e.label||e.k,hide:e.hide,get:t=>{if(t[e.k])return t[e.k]+(e.full?t[e.full]?' <span style="font-size:.8em;color:#858585">'+t[e.full]+"</span>":"":"");return""}})}}if(t.eplst){for(const e of t.eplst){if(!e.p){console.error("no config object for epaint");continue}if(e.p.maf){t.snvindelattr.push({label:e.p.name,lst:[{label:e.p.datatype,get:t=>{const s=t[e.p.sampletype];if(!s)return"";return e.sampletype2value[s]}},{label:e.p.maf.label,width:40,height:12,fill:e.p.hlcolor,fillbg:e.p.hlcolor2,get:e.p.maf.get,readcountcredible:e.p.maf.readcountcredible,ismaf:true}]})}else{t.snvindelattr.push({label:e.p.name+" "+e.p.datatype,get:t=>{const s=t[e.p.sampletype];if(!s)return"";return e.sampletype2value[s]}})}}}}function ht(t,e){const s=new Set(["__x","mname","gene","strand","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","partner"]);t.truncattr=[];for(const o of e){if(o.sample){t.truncattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.truncattr.push({label:"Position",get:t=>t.chr+":"+t.pos});const o=new Set;for(const t of e){o.add(t.dt)}if(o.size>1){t.truncattr.push({label:"Truncated",get:t=>t.dt==n?"N-term":"C-term"})}for(const o of e){if(o.pmid){t.truncattr.push(xt());s.add("pmid");break}}for(const s of e){if(s.partner){t.truncattr.push({get:t=>{const e=[];for(const s in t.partner){e.push(s+": "+t.partner[s])}return e.join("&nbsp;&nbsp;")},label:"Translocation"});break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.truncattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.truncattr.push({label:o,get:t=>t[o]})}}function gt(t,e){const s=new Set(["__x","mname","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","rnadellength","a","b"]);t.delattr=[];for(const o of e){if(o.sample){t.delattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.delattr.push({label:"Position",get:t=>t.chr+":"+t.pos});t.delattr.push({label:"Del. length",get:t=>t.rnadellength+" bp"});for(const o of e){if(o.pmid){t.delattr.push(xt());s.add("pmid");break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.delattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.delattr.push({label:o,get:t=>t[o]})}}function bt(t,e){const s=new Set(["__x","mname","isoform","aapos","rnapos","chr","pos","class","dt","rnaposition","rnaduplength","a","b"]);t.itdattr=[];for(const o of e){if(o.sample){t.itdattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.itdattr.push({label:"Position",get:t=>t.chr+":"+t.pos});t.itdattr.push({label:"Dup. length",get:t=>t.rnaduplength+" bp"});for(const o of e){if(o.pmid){t.itdattr.push(xt());s.add("pmid");break}}if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.itdattr.push({label:e.label||e.k,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.itdattr.push({label:o,get:t=>t[o]})}}function yt(t,e){const s=new Set(["__x","mname","aapos","chr","class","dt","inframe","origin","pos","rnapos","strand","useNterm","pairlst"]);t.svattr=[];for(const o of e){if(o.sample){t.svattr.push({label:"Sample",get:t=>t.sample});s.add("sample");break}}t.svattr.push({label:"Genomic breakpoint",get:t=>{if(!t.pairlst)return"no pairlst";const e=t.pairlst.map((t=>(t.a.name?"<strong>"+t.a.name+"</strong> ":"")+(t.a.chr?'<span style="color:#858585">'+t.a.chr+":"+(t.a.position+1)+" "+(t.a.strand=="+"?"forward":"reverse")+"</span> &#10140; ":"")+(t.b.name?"<strong>"+t.b.name+"</strong> ":"")+(t.b.chr?'<span style="color:#858585">'+t.b.chr+":"+(t.b.position+1)+" "+(t.b.strand=="+"?"forward":"reverse")+"</span>":"")));return e.join("<br>")}});for(const s of e){if(s.pairlst[0].a.rnaposition!=undefined){t.svattr.push({label:"RNA breakpoint",get:t=>{if(!t.pairlst)return"no pairlst";const e=t.pairlst.map((t=>(t.a.name?"<strong>"+t.a.name+"</strong> ":"")+'<span style="color:#858585">r.'+(t.a.rnaposition+1)+"</span> &#10140; "+(t.b.name?"<strong>"+t.b.name+"</strong> ":"")+'<span style="color:#858585">r.'+(t.b.rnaposition+1)+"</span>"));return e.join("<br>")}});break}}for(const o of e){if(o.pmid){t.svattr.push(xt());s.add("pmid");break}}let o=false;for(const s of e){if(o)break;for(const e of s.pairlst){if(e.translocationname){t.svattr.push({get:t=>t.pairlst.map((t=>t.translocationname?t.translocationname:"")).join("_"),label:"Translocation name"});o=true;break}}}if(e[0].pairlst[0].a.ratio!=undefined){t.svattr.push({label:"Chimeric reads ratio",get:t=>{const e=[];const s=40,o=12,a="#FF850A",n="#FFCF9E";for(const r of t.pairlst){e.push((r.a.name?r.a.name:r.a.chr)+" <svg width="+s+" height="+o+"><g><title>"+r.a.ratio+"</title><rect width="+s+" height="+o+' fill="'+n+'"></rect>'+"<rect width="+s*r.a.ratio+" height="+o+' fill="'+a+'"></rect>'+"</g></svg>"+"&nbsp;&nbsp;"+(r.b.name?r.b.name:r.b.chr)+" <svg width="+s+" height="+o+"><g><title>"+r.b.ratio+"</title><rect width="+s+" height="+o+' fill="'+n+'"></rect>'+"<rect width="+s*r.b.ratio+" height="+o+' fill="'+a+'"></rect>'+"</g></svg>")}return e.join("<br>")}})}t.svattr.push({label:"Frame",get:t=>{function e(t){if(t==0)return'<span style="white-space:nowrap;background-color:'+k+';font-size:80%;color:white;padding:1px 3px">OUT of frame</span>';if(t==1)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span>';if(t==2)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span> <span style="font-size:80%;color:#858585">promoter fusion</span>';if(t==3)return'<span style="white-space:nowrap;background-color:'+v+';font-size:80%;color:white;padding:1px 3px">IN frame</span> <span style="font-size:80%;color:#858585">alternative promoter</span>';return"err ("+t+")"}const s=[];for(const e of t.pairlst){if(e.frame!=undefined){s.push({frame:e.frame,a:e.a.name?e.a.name:e.a.chr,b:e.b.name?e.b.name:e.b.chr})}}if(s.length==1)return e(s[0].frame);return s.map((t=>t.a+"-"+t.b+": "+e(t.frame))).join("<br>")}});if(t.ds&&t.ds.cohort&&t.ds.cohort.levels){for(const e of t.ds.cohort.levels){s.add(e.k);s.add(e.full);t.svattr.push({label:e.label||e.k,hide:e.hide,get:t=>t[e.k]?t[e.k]+(e.full?' <span style="color:#858585;font-size:.8em">'+t[e.full]+"</span>":""):""})}}for(const o in e[0]){if(s.has(o))continue;t.svattr.push({label:o,get:t=>t[o]})}}function xt(t){return{get:t=>{if(!t.pmid){return""}if(typeof t.pmid=="number"){return"<a target=_blank href=https://pubmed.ncbi.nlm.nih.gov/"+t.pmid+">"+t.pmid+"</a>"}const e=t.pmid.split(",");const s=[];for(const t of e){if(t=="")continue;const e=Number.parseInt(t);if(Number.isNaN(e)){s.push(t)}else{s.push("<a target=_blank href=https://pubmed.ncbi.nlm.nih.gov/"+t+">"+t+"</a>")}}return s.join(" ")},label:"PubMed"}}function kt(t,e,s){let o=t.sampledata;if(s.ds&&s.ds.cohort&&s.ds.cohort.annotation&&s.ds.cohort.key4annotation&&s.ds.cohort.sampleattribute&&s.ds.cohort.sampleattribute.runtimelst){o=[];for(const e of t.sampledata){const t=e.sampleobj[s.ds.cohort.key4annotation];if(!t)continue;const a=s.ds.cohort.annotation[t];if(a){let t=false;for(const e of s.ds.cohort.sampleattribute.runtimelst){if(e.key&&e.key.k&&e.key.hiddenvalues&&e.key.hiddenvalues.size){const s=a[e.key.k];if(e.key.hiddenvalues.has(s)){t=true;break}}}if(t)continue}o.push(e)}}e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text(o.length+" sample"+(o.length>1?"s":"")).on("click",(t=>{s.tktip.showunder(t.target).clear();const e=s.tktip.d.append("table");const a=e.append("tr").style("font-size",".8em").style("color","#858585");a.append("td").text("Name");a.append("td").text("Genotype");let n=false;if(o[0].DP!=undefined){a.append("td").text("Read depth");n=true}let r=false;if(o[0].allele2readcount){a.append("td").text("Allele read count");r=true}for(const t of o){const s=e.append("tr");s.append("td").text(t.sampleobj.name);s.append("td").style("padding-left","10px").text(t.genotype);if(n){s.append("td").style("padding-left","10px").text(t.DP||"")}if(r){const e=[];for(const s in t.allele2readcount){e.push(s+":"+t.allele2readcount[s])}s.append("td").style("padding-left","10px").text(e.join(", "))}}}))}function vt(t,e,s,o){e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("VEP annotation").on("click",(e=>{s.tktip.clear();s.tktip.showunder(e.target);for(const e of t){let t=false;let a;{const t=[];if(e.HGVSp){t.push('<span style="font-size:.7em;color:#858585">HGVSp</span> '+e.HGVSp)}else if(e.HGVSc){t.push('<span style="font-size:.7em;color:#858585">HGVSc</span> '+e.HGVSc)}else{t.push("no_HGVS")}if(e.Consequence){t.push('<span style="font-size:.7em;color:#858585">CONSEQUENCE</span> '+e.Consequence)}else{t.push("no_consequence")}a=t.join(" ")}const n=s.tktip.d.append("div").attr("class","sja_menuoption").style("margin","5px").html(a).on("click",(()=>{if(t){t=false;n.html(a)}else{t=true;n.text("");const s=[];for(const t of o){const o=e[t.name];if(o){s.push({k:t.name,v:o})}}d(n,s)}}))}}))}function wt(t,e,s,o){e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("Annotation").on("click",(e=>{s.tktip.clear();s.tktip.showunder(e.target);for(const e of t){let t=false;let a;{const t=[];if(e["HGVS.p"]){t.push('<span style="font-size:.7em;color:#858585">HGVS.p</span> '+e["HGVS.p"])}else if(e["HGVS.c"]){t.push('<span style="font-size:.7em;color:#858585">HGVS.c</span> '+e["HGVS.c"])}else{t.push("no_HGVS")}if(e.Annotation){t.push('<span style="font-size:.7em;color:#858585">Annotation</span> '+e.Annotation)}else{t.push("no_annotation")}a=t.join(" ")}const n=s.tktip.d.append("div").attr("class","sja_menuoption").style("margin","5px").html(a).on("click",(()=>{if(t){t=false;n.html(a)}else{t=true;n.text("");const s=[];for(const t of o){const o=e[t.name];if(o){s.push({k:t.name,v:o})}}d(n,s)}}))}}))}function _t(t,e,s,o,a){let n=false;e.append("div").attr("class","sja_menuoption").style("display","inline-block").style("margin-right","10px").text("Image").on("click",(async()=>{if(n)return;n=true;const e=s.append("div").style("margin","20px").text("Loading...");try{const a=await b("img",{file:[o.variant2img.path,t.chr+"."+(t.pos+1)+"."+t.ref+"."+t.alt+"."+o.variant2img.ext].join("/")});if(a.error)throw a.error;e.remove();s.append("img").attr("src",a.src).style("width",a.size.width+"px").style("height",a.size.height+"px")}catch(t){e.text("Error loading image")}}))}function jt(t,e,s){if(!e.ds.vaf2coverageplot){return false}if(!t.sampledata){return false}const o=[];const a={};const n=new Map;let r=0;for(const s of t.sampledata){if(!s.allele2readcount){r++;continue}if(s.DP==undefined){s.DP=0;for(const t in s.allele2readcount){s.DP+=s.allele2readcount[t]}}const i=s.allele2readcount[t.alt]||0;if(i>s.DP){console.log("alt coverage > DP: "+i+" "+s.DP);continue}const l={sampleobj:{},mut:i,total:s.DP,maf:s.DP==0?0:i/s.DP,genotype:s.genotype};if(s.sampleobj){if(e.ds.cohort&&e.ds.cohort.annotation&&e.ds.cohort.key4annotation){const t=s.sampleobj[e.ds.cohort.key4annotation];if(t){const s=e.ds.cohort.annotation[t];if(s){if(e.ds.cohort.levels){for(const t of e.ds.cohort.levels){if(!s[t.k])continue;l.sampleobj[t.label||t.k]=s[t.k]+(t.full&&s[t.full]?' <span style="font-size:.8em;color:#858585">'+s[t.full]+"</span>":"")}l.sampleobj[e.ds.cohort.key4annotation]=t}else{for(const t in s){l.sampleobj[t]=s[t]}}}}}else{for(const t in s.sampleobj){l.sampleobj[t]=s.sampleobj[t]}}}if(e.ds.vaf2coverageplot.categorykey&&e.ds.vaf2coverageplot.categories){const t=l.sampleobj[e.ds.vaf2coverageplot.categorykey];if(t&&e.ds.vaf2coverageplot.categories[t]){l.color=e.ds.vaf2coverageplot.categories[t].color;if(!n.has(t)){n.set(t,0)}n.set(t,n.get(t)+1);delete l.sampleobj[e.ds.vaf2coverageplot.categorykey];l.sampleobj[e.ds.vaf2coverageplot.categorylabel]=t}}if(e.ds.vaf2coverageplot.samplegroupkey){if(l.sampleobj&&l.sampleobj[e.ds.vaf2coverageplot.samplegroupkey]){const t=l.sampleobj[e.ds.vaf2coverageplot.samplegroupkey];if(!a[t]){a[t]=[]}a[t].push(l)}else{o.push(l)}}else{o.push(l)}}if(r){console.log("skipped "+r+" items")}const i=[];if(o.length){i.push({name:"no "+(e.ds.vaf2coverageplot.samplegroupkey||"sampletype"),lst:o})}for(const t in a){i.push({name:t,lst:a[t]})}if(i.length==0){return false}if(n.size>0){const t=s.append("div").style("margin","20px 20px 0px 20px");for(const[s,o]of n){const o=e.ds.vaf2coverageplot.categories[s];const a=t.append("div").style("margin-bottom","3px");a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("margin-right","5px").style("background-color",o.color).html("&nbsp;&nbsp;");a.append("span").style("color",o.color).text(o.label||s)}}const l=s.append("div").style("margin-bottom","10px");import("./plot.vaf2cov-ba8332ed.js").then((t=>{const s={};for(const o of i){let a=l.append("div").style("display","inline-block").style("vertical-align","top");if(i.length>1){a.style("margin-right","30px").append("div").style("margin-top","10px").style("padding","3px 10px").style("background-color","#aaa").style("color","white").style("display","inline-block").style("font-size",".8em").style("font-weight","bold").text(o.name.toUpperCase());a=a.append("div").style("border","solid 1px #aaa")}const n={holder:a,data:o.lst,name:o.name,tip:e.tktip,automax:true,mouseover:t=>{if(!t.sampleobj)return;for(const e in s){if(e==o.name)continue;s[e].filter((e=>e.sampleobj.patient==t.sampleobj.patient)).each((t=>{t.crosshair1.attr("transform","scale(2.5)");t.crosshair2.attr("transform","scale(2.5)")}))}},mouseout:t=>{if(!t.sampleobj)return;for(const e in s){if(e==o.name)continue;s[e].filter((e=>e.sampleobj.patient==t.sampleobj.patient)).each((t=>{t.crosshair1.attr("transform","scale(1)");t.crosshair2.attr("transform","scale(1)")}))}}};s[o.name]=t.default(n)}}));return true}function Mt(t,e,s){const o=e.ds.vcfcohorttrack;return Promise.resolve().then((()=>{if(o.info){return null}const t={jwt:s.jwt,file:o.file,url:o.url,indexURL:o.indexURL,header:1};return fetch(new Request(s.hostURL+"/vcf",{method:"POST",body:JSON.stringify(t)})).then((t=>t.json()))})).then((t=>{if(t==null)return;if(!t.metastr)throw{message:"no meta lines for the cohort vcf file "};if(!t.chrstr)throw{message:"no chromosome names found for the cohort vcf file"};const[e,a,n,r]=X(t.metastr.split("\n"));if(r)throw{message:"vcf meta error for the cohort vcf file: "+r.join("; ")};o.info=e;o.format=a;if(o.samplenamemap){o.samples=n.map(o.samplenamemap)}else{o.samples=n}o.nochr=y(s.genome,t.chrstr.split("\n"));return})).then((()=>{const e={jwt:s.jwt,file:o.file,url:o.url,indexURL:o.indexURL,rglst:[{chr:o.nochr?t.chr.replace("chr",""):t.chr,start:t.pos+1,stop:t.pos+1}]};return fetch(new Request(s.hostURL+"/vcf",{method:"POST",body:JSON.stringify(e)})).then((t=>t.json())).then((e=>{if(e.error)throw{message:"Error querying vcf file: "+e.error};const s=e.linestr?e.linestr.trim().split("\n"):[];for(const e of s){const[s,a,n]=Y(e,o);for(const e of a){if(e.pos==t.pos&&e.ref==t.ref&&e.alt==t.alt){return e}}}return null}))}))}function At(t,e,s){for(const o of s){if(!o.makeurl)continue;const s=o.makeurl(e);if(!s){continue}t.append("a").attr("href",s).attr("target","_blank").text(o.makelabel?o.makelabel(e):o.label||"link").style("margin-right","10px")}}function zt(t,e,s){s.forEach((s=>{if(!s.makebutton)return;const o=t.append("div").style("display","inline-block").style("margin","0px 10px 2px 3px");s.makebutton(e,o.node())}))}function Nt(t,e,s){const o=e.ds.germline2dvafplot;if(!o)return false;const a=o.individualkey;const n=new Map;let r=0;for(const e of t.sampledata){if(e.DP==undefined||!e.allele2readcount){r++;continue}const s=e.allele2readcount[t.alt]||0;if(s>e.DP){console.log("alt coverage > DP: "+s+" "+e.DP);continue}const i=e.sampleobj[a];if(!i){continue}const l=e.sampleobj[o.sampletypekey];if(!l){continue}if(!n.has(i)){const t={sampletypes:{}};for(const s in e.sampleobj){t[s]=e.sampleobj[s]}n.set(i,t)}n.get(i).sampletypes[l]={total:e.DP,vaf:e.DP==0?0:s/e.DP}}if(r){console.log(r+" samples has no valid DP/allele2readcount")}const i=[];for(const[t,e]of n){if(!e.sampletypes[o.xsampletype]){continue}if(e.sampletypes[o.yleftsampletype]){const t={};for(const s in e){t[s]=e[s]}t.sampletypes={};t.sampletypes[o.xsampletype]=e.sampletypes[o.xsampletype];t.sampletypes[o.yleftsampletype]=e.sampletypes[o.yleftsampletype];i.push(t)}if(o.yrightsampletype&&e.sampletypes[o.yrightsampletype]){const t={};for(const s in e){t[s]=e[s]}t.sampletypes={};t.sampletypes[o.xsampletype]=e.sampletypes[o.xsampletype];t.sampletypes[o.yrightsampletype]=e.sampletypes[o.yrightsampletype];i.push(t)}}if(i.length){const t=s.append("div").style("display","inline-block");import("./plot.2dvaf-4016e75e.js").then((e=>{e.default(i,o,t)}));return true}return false}function Pt(t,e,s){const o=e.ds.genotype2boxplot;if(!o)return false;if(o.boxplotvaluekey){const e=t.info[o.boxplotvaluekey];if(!e)return false;const a=e.split("|");const n=[];for(const t of a){const e=t.split("/");const s=Number.parseFloat(e[1]);const o=Number.parseFloat(e[2]);const a=Number.parseFloat(e[3]);const r=Number.parseFloat(e[4]);const i=Number.parseFloat(e[5]);if(Number.isNaN(s)||Number.isNaN(o)||Number.isNaN(a)||Number.isNaN(r)||Number.isNaN(i)){continue}n.push({label:e[0],color:"#4F8F38",minvalue:s,maxvalue:i,percentile:{p05:s,p25:o,p50:a,p75:r,p95:i}})}const r=s.append("div").style("display","inline-block");import("./plot.boxplot-76229491.js").then((t=>{const e=t.default({holder:r,axislabel:o.axislabel,list:n});if(e){x(r,"Boxplot: "+e)}}));return true}if(!e.ds.cohort||!e.ds.cohort.annotation||!e.ds.cohort.key4annotation){console.log("genotype2boxplot but ds.cohort is incomplete");return false}const a=new Map;t.sampledata.forEach((t=>{if(!t.genotype)return;const s=t.sampleobj[e.ds.cohort.key4annotation];if(!s)return;const n=e.ds.cohort.annotation[s];if(!n)return;const r=n[o.sampleannotationkey];if(!Number.isFinite(r))return;if(!a.has(t.genotype)){a.set(t.genotype,[])}a.get(t.genotype).push({value:r,key:s})}));if(a.size==0){return false}const n=[];for(const[t,e]of a){n.push({label:t,color:"#4F8F38",samples:e})}const r=s.append("div").style("display","inline-block");import("./plot.boxplot-76229491.js").then((t=>{const e=t.default({holder:r,axislabel:o.axislabel,list:n});if(e){x(r,"Boxplot: "+e)}}));return true}function St(t,e,s){const o=t.sampledata[0];const a=[];if(o.genotype){a.push({k:"genotype",v:o.genotype})}if(o.DP!=undefined){a.push({k:"total reads",v:o.DP})}if(o.allele2readcount&&o.allele2readcount[t.alt]!=undefined){a.push({k:"alt reads",v:o.allele2readcount[t.alt]})}else{Ct(a,t,e)}if(o.sampleobj){if(e.ds.cohort&&e.ds.cohort.annotation&&e.ds.cohort.key4annotation){const t=o.sampleobj[e.ds.cohort.key4annotation];if(t){a.push({k:e.ds.cohort.key4annotation,v:t});const s=e.ds.cohort.annotation[t];if(s){if(e.ds.cohort.levels){for(const t of e.ds.cohort.levels){if(!s[t.k])continue;a.push({k:t.label||t.k,v:s[t.k]+(t.full&&s[t.full]?' <span style="font-size:.8em;color:#858585">'+s[t.full]+"</span>":"")})}}else{for(const t in s){if(t=="color")continue;a.push({k:t,v:s[t]})}}}}}else if(o.sampleobj.name){a.push({k:"name",v:o.sampleobj.name})}}d(s,a)}function Ct(t,e,s){let o;if(e.vcfid&&s.ds&&s.ds.id2vcf)o=s.ds.id2vcf[e.vcfid];if(!o)return;if(!o.format)return;const a=e.sampledata[0];for(const s in o.format){const n=o.format[s];if(!(s in a))continue;let r=n.Number=="R"||n.Number=="A";if(!r){if(s=="AD"){r=true}}if(r){const o=[];const r=[];let i;for(const t in a[s]){if(t==e.ref)continue;o.push(t);i=a[s][t];r.push(i)}const l=a[s][e.ref];if(l!=undefined){o.push(e.ref);r.push(l)}let c;if(l+i>0){c=g(null,{f:i/(i+l)})}t.push({k:s,v:(c?c+" ":"")+'<span style="font-size:.8em;opacity:.5">'+o.join(" / ")+"</span> "+r.join(" / ")+(n.Description?' <span style="font-size:.7em;opacity:.5">'+n.Description+"</span>":"")})}else{t.push({k:s,v:a[s]})}}}function Ft(t,e,s,o){if(!o.samplecart||!s.ds||!s.ds.sampleselectable)return;const a=new Set;for(const e of t){if(e.sample){a.add(e.sample)}}if(a.size==0){return}const n=new Set;for(const e of t){const t=f[e.class].label;let s;if(e.dt==i||e.dt==l){if(e.mname){if(e.useNterm){s=(o.usegm?o.usegm.name+"-":"")+e.mname+" "+t}else{s=e.mname+(o.usegm?"-"+o.usegm.name:"")+" "+t}}else{s=(o.usegm?o.usegm.name:"")+" "+t}}else{s=(e.mname?e.mname+" ":"")+t+(o.usegm?" in "+o.usegm.name:"")}n.add(s)}if(n.size==1){"having "+[...n][0]}else{"having mutations"+(o.usegm?" in "+o.usegm.name:"")}o.samplecart.setBtns({samplelst:[...a],id:n.size?[...n][0]:o.usegm?o.usegm.name:"",basket:"Gene Mutation",container:e.append("div").style("margin-left","10px").append("div")})}function Rt(t,e){let s=null;for(const t in e.ds.id2vcf){s=e.ds.id2vcf[t]}if(!s){t.tkcloakoff(e,{error:"no vcf config found"});return}Promise.resolve().then((()=>{if(!s.headernotloaded)return;delete s.headernotloaded;const o=["genome="+t.genome.name];if(s.file){o.push("file="+s.file)}else{o.push("url="+s.url);if(s.indexURL)o.push("indexURL="+s.indexURL)}return w("vcfheader?"+o.join("&")).then((t=>{if(t.error)throw{message:t.error};if(!t.metastr)throw{message:"no meta lines for vcf file "+e.name};const[o,a,n,r]=X(t.metastr.split("\n"));if(r)throw{error:"vcf meta error for file "+e.name+": "+r.join("; ")};s.info=o;s.format=a;if(s.samplenamemap){s.samples=n.map(s.samplenamemap)}else{s.samples=n}s.nochr=t.nochr}))})).then((()=>{const o={file:s.file,url:s.url,indexURL:s.indexURL,rglst:t.tkarg_maygm(e)};if(s.nochr){for(const t of o.rglst){t.chr=t.chr.replace("chr","")}}return w("vcf",{method:"POST",body:JSON.stringify(o)}).then((o=>{if(o.error)throw{message:o.error};const a=o.linestr?o.linestr.trim().split("\n"):[];ce([{vcfid:s.vcfid,lines:a}],t,e);return}))})).catch((t=>{if(t.stack)console.log(t.stack);return t.message})).then((s=>{t.tkcloakoff(e,{error:s})}))}function It(t,e,s){const o=e.ds.id2vcf[t.vcfid];if(!o){s.error("vcf not found by id: "+t.vcfid);return}if(!t.lines){s.error("no vcf lines from vcf file "+t.vcfid);return}const a=[];for(const n of t.lines){const[r,i,l]=Y(n,o);if(r){a.push(r)}if(!i){continue}for(const o of i){if(o.alt=="NON_REF"){continue}if(e.ds.discardsymbolicallele&&o.issymbolicallele){continue}if(s.usegm){const t=_(o.pos,s.usegm);o.rnapos=t.rnapos;o.aapos=t.aapos}o.vcfid=t.vcfid;j(o,s);e.mlst.push(o)}}if(!e.dstk_novcferror&&a.length){s.error(a[0]+(a.length==1?"":" and "+(a.length-1)+" more errors with the VCF track"))}}function Bt(t,e,s){if(!s.cohort){console.error("arg.cohort missing");return}if(!s.cohort.levels){console.error("arg.cohort.levels missing");return}if(!s.cohort.key2color&&!s.cohort.suncolor){s.cohort.suncolor=M(A)}let o;if(!s.cohort.annotation){o=s.mlst}else{if(!s.cohort.key4annotation){console.error("arg.cohort.key4annotation missing");return}o=[];if(s.mlst[0].sampledata){for(const t of s.mlst){if(!t.sampledata){continue}for(const e of t.sampledata){const t=e.sampleobj[s.cohort.key4annotation];if(!t){continue}const a=s.cohort.annotation[t];if(!a){continue}const n={k4a:t};for(const t of s.cohort.levels){n[t.k]=a[t.k];if(t.full){n[t.full]=a[t.full]}}o.push(n)}}}else{for(const t of s.mlst){const e=t[s.cohort.key4annotation];if(!e){continue}const a=s.cohort.annotation[e];if(!a){continue}const n={k4a:e};for(const t of s.cohort.levels){n[t.k]=a[t.k];if(t.full){n[t.full]=a[t.full]}}o.push(n)}}if(o.length==0){if(s.m2detail){$({mlst:[s.m2detail],pane:true,x:s.cx,y:s.cy,tk:t,block:e})}else{$({mlst:s.mlst,pane:true,x:s.cx,y:s.cy,tk:t,block:e})}return}}let a=s.cx,n=s.cy,r=500,i=250;const l=t.glider.append("g").attr("transform","translate("+a+","+n+")");const c=t.pica;const f=l.append("g");const d=l.append("g");const p={g:l,eye:f,ring:d,pica:c,busy:false};let u=Math.log(o.length)*24;if(u>t.height*.42){u=t.height*.42}else if(u<t.height*.2){u=t.height*.2}let m=a,h=n;if(a-u<0){m=u}else if(a+u>e.width){m=e.width-u}if(n-u<0){h=u}else if(n+u>t.height){h=t.height-u}if(m!=a||h!=n){l.transition().delay(r+i).attr("transform","translate("+m+","+h+")");a=m;n=h}const g=z(o,s.cohort.levels);const b=N()(g);b.sum((t=>t.value));b.sort(((t,e)=>e.value-t.value));J().size([1,Math.pow(u,2)])(b);f.append("circle").attr("r",u).attr("fill","white").attr("fill-opacity",0);let y;const x=Q().startAngle((t=>Math.PI*2*t.x0)).endAngle((t=>Math.PI*2*t.x1)).innerRadius((t=>{if(!t.parent){y=Math.sqrt(t.y1)-u/15;return y}return Math.sqrt(t.y0)})).outerRadius((t=>{t.outradius=Math.sqrt(t.y1);return t.outradius}));d.selectAll().data(b.descendants()).enter().append("path").attr("d",x).attr("stroke","white").attr("fill",(t=>{if(!t.parent){return"white"}let e;if(t.children){e=t.id}else{if(!t.parent.parent){e=t.id}else{e=t.parent.id}}let o;if(s.cohort.key2color){o=s.cohort.key2color[e];if(!o){console.log(e);o="#858585"}}else{o=s.cohort.suncolor(e)}t._color=o;return o})).on("mouseover",((o,r)=>{if(!r.parent)return;if(p.busy)return;o.target.setAttribute("fill",P(r._color).darker(.5).toString());Dt(r,c,s,a,n,t,e)})).on("mouseout",((t,e)=>{c.g.selectAll("*").remove();if(!e.parent)return;t.target.setAttribute("fill",e._color)})).on("click",((o,a)=>{if(s.noclickring){return}if(!a.parent){return}if(s.cohort.annotation){if(a.data.lst.length==1){Lt(a.data.lst[0].k4a,s.cohort.annotation[a.data.lst[0].k4a],o.clientX,o.clientY);return}Et(a.data.lst,s.cohort,o.clientX,o.clientY);return}$({mlst:a.data.lst,x:o.clientX,y:o.clientY,tk:t,block:e,pane:true})}));const k=y*2;d.attr("transform","scale(.3,.3)").attr("fill-opacity",0).transition().duration(r).attr("transform","scale(1,1)").attr("fill-opacity",1).on("end",(()=>{f.shutter=f.append("rect").attr("x",-y).attr("y",-y).attr("width",y*2).attr("height",0).attr("fill","#ededed").on("click",(()=>qt(p)));f.shutter.transition().duration(i).attr("height",y*2).on("end",(()=>{f.fore=f.append("g");const r=Math.min(k/(s.label.length*S),y*.6);f.fore.append("text").text(s.label).attr("text-anchor","middle").attr("dominant-baseline","central").attr("fill","#858585").attr("font-weight","bold").attr("font-family","Arial").attr("font-size",r);const i=Math.min(18,Math.min(y*.7/(o.length.toString().length*S),(y-r/2)*.7));f.fore.append("text").text(o.length).attr("text-anchor","middle").attr("fill","#858585").attr("y",-r/2-2).attr("font-family","Arial").attr("font-size",i);f.append("rect").attr("x",-y).attr("y",-y).attr("width",y*2).attr("height",y*2).attr("fill","black").attr("fill-opacity",0).on("click",(()=>{if(p.busy)return;qt(p)})).on("mousedown",(t=>{t.preventDefault();t.stopPropagation();let e=a,s=n,o=t.clientX,r=t.clientY,i=C(document.body);i.on("mousemove",(t=>{p.busy=true;a=e+t.clientX-o;n=s+t.clientY-r;l.attr("transform","translate("+a+","+n+")")})).on("mouseup",(()=>{setTimeout((()=>p.busy=false),10);i.on("mousemove",null).on("mouseup",null)}))}));p.listbutt=f.append("g").attr("transform","translate(0,"+r/2+")");const c=p.listbutt.append("rect").attr("x",-k/2).attr("width",k).attr("height",y-r/2).attr("fill","#d9d9d9");const d=p.listbutt.append("text").text(s.m2detail?"Show":"List").attr("y",(y-r/2)/2).attr("dominant-baseline","central").attr("text-anchor","middle").attr("font-family","Arial").attr("fill","#858585").attr("font-size",Math.min(18,i));p.listbutt.append("rect").attr("x",-k/2).attr("width",k).attr("height",y-r/2).attr("fill-opacity",0).on("mouseover",(()=>{c.attr("fill","#bababa");d.attr("fill","white")})).on("mouseout",(()=>{c.attr("fill","#d9d9d9");d.attr("fill","#858585")})).on("click",(o=>{if(s.m2detail){qt(p);$({mlst:[s.m2detail],pane:true,x:o.clientX-u,y:o.clientY-u*2,tk:t,block:e});return}const a=o.target.getBoundingClientRect();qt(p);setTimeout((()=>$({mlst:s.mlst,x:a.left,y:a.top,tk:t,block:e,pane:true})),500)}))}))}))}function qt(t){t.busy=true;if(t.eye.fore){t.eye.fore.remove()}if(t.listbutt){t.listbutt.remove()}if(t.eye.shutter){t.eye.shutter.transition().attr("height",0).on("end",(()=>{t.ring.transition().attr("transform","scale(.5,.5)").attr("fill-opacity",0).on("end",(()=>{t.g.remove();t.pica.g.selectAll("*").remove()}))}))}else{t.ring.transition().attr("transform","scale(.5,.5)").attr("fill-opacity",0).on("end",(()=>{t.g.remove();t.pica.g.selectAll("*").remove()}))}t.pica.g.selectAll("*").remove()}function Dt(t,e,s,o,a,n,r){const i=s.cohort;const l=13;const c=10;const f=1;let d=(t.x0+t.x1)/2;if(d>=.375&&d<=.625){const e=n.yoff+a+t.outradius;const s=Number.parseFloat(r.svg.attr("height"));l+f+l+(i&&i.root?f+c+5:0);if(e>=s-30){if(d<=.5){d=Math.max(.25,t.x0)}else{d=Math.min(.75,t.x1)}}}e.g.selectAll("*").remove();const p=o+(t.outradius+5)*Math.sin(Math.PI*2*d);const u=a-(t.outradius+5)*Math.cos(Math.PI*2*d);e.g.attr("transform","translate("+p+","+u+")");const m=60;let h=null,g=0;if(i&&i.root){h=e.g.append("g");h.append("rect").attr("width",m+4).attr("height",c+4).attr("fill","white").attr("shape-rendering","crispEdges");h.append("rect").attr("x",2).attr("y",2).attr("width",m).attr("height",c).attr("fill",i.fbarbg||"#ededed").attr("shape-rendering","crispEdges");i.root.each((e=>{if(e.id==t.id){g=e.value}}));if(g>0){h.append("rect").attr("x",2).attr("y",2).attr("width",m*t.value/g).attr("height",c).attr("fill",i.fbarfg||"#858585").attr("shape-rendering","crispEdges")}}const b=e.g.append("text").attr("stroke","white").attr("stroke-width",3).attr("font-size",l).attr("font-family","Arial");const y=e.g.append("text").attr("fill","black").attr("fill-opacity",1).attr("font-size",l).attr("font-family","Arial");t.data.name+", "+t.value+" sample"+(t.value>1?"s":"");b.text(t.data.name);y.text(t.data.name);const x=e.g.append("text").attr("stroke","white").attr("stroke-width",3).attr("font-size",l).attr("font-family","Arial");const k=e.g.append("text").attr("fill","black").attr("fill-opacity",1).attr("font-size",l).attr("font-family","Arial");const v=t.value+" sample"+(t.value>1?"s":"")+(h?" ("+g+" total)":"");x.text(v);k.text(v);Math.max(y.node().getBBox().width,k.node().getBBox().width);if(d<.25){x.attr("y",h?-3-c-f:0);k.attr("y",h?-3-c-f:0);b.attr("y",(h?-3-c-f:0)-l-f);y.attr("y",(h?-3-c-f:0)-l-f);if(h){h.attr("transform","translate(0,-"+c+")")}}else if(d<.5){b.attr("dominant-baseline","hanging").attr("y",0);y.attr("dominant-baseline","hanging").attr("y",0);x.attr("dominant-baseline","hanging").attr("y",f+l);k.attr("dominant-baseline","hanging").attr("y",f+l);if(h){h.attr("transform","translate(0,"+(l+f)*2+")")}}else if(d<.75){b.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",0);y.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",0);x.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",f+l);k.attr("dominant-baseline","hanging").attr("text-anchor","end").attr("y",f+l);if(h){h.attr("transform","translate(-"+m+","+(l+f)*2+")")}}else{x.attr("text-anchor","end").attr("y",h?-3-c-f:0);k.attr("text-anchor","end").attr("y",h?-3-c-f:0);b.attr("text-anchor","end").attr("y",(h?-3-c-f:0)-l-f);y.attr("text-anchor","end").attr("y",(h?-3-c-f:0)-l-f);if(h){h.attr("transform","translate(-"+m+",-"+c+")")}}}function Lt(e,s,o,a){const n=[];for(const t in s){n.push({k:t,v:s[t]})}const r=t({x:o,y:a});r.header.text(e);d(r.body,n)}function Et(e,s,o,a){const n=new Set;for(const t of e){const e=s.annotation[t.k4a];for(const t in e){n.add(t)}}const r=t({x:o,y:a});r.header.text(e.length+" "+s.key4annotation+"s");const i=r.body.append("table");const l=[...n];{const t=i.append("tr");for(const e of l){t.append("td").text(e).style("color","#858585").style("font-size",".7em")}}for(const t of e){const e=i.append("tr").attr("class","sja_tr");const o=s.annotation[t.k4a];for(const t of l){e.append("td").text(o[t]==undefined?"":o[t])}}}async function Ut(t,e,s,o,a,n){if(a.ds){if(a.ds.cohort){let t=false;if(a.ds.cohort.annotation){if(a.ds.cohort.variantsunburst){t=true}}else{t=true}if(t){Bt(a,n,{cx:s,cy:o,mlst:e,label:e[0].mname,cohort:a.ds.cohort});return true}}}return false}const Gt=7;const Vt=t=>{if(!t)return"";if(t.length>25){return t.substr(0,20)+"..."}return t};function Ot(t,e,s){const o=t.numericmode;if(!o.axisheight){o.axisheight=100}t.glider.selectAll("*").remove();delete t.skewer;const a=qe(t,e,s);const n=new Map;for(const t of a){if(t.__x==undefined){continue}if(!n.has(t.__x)){n.set(t.__x,[])}n.get(t.__x).push(t)}const r=[];if(e.exonsf>=se){for(const[t,e]of n){r.push({chr:e[0].chr,pos:e[0].pos,mlst:e,x:t})}}else{if(e.usegm&&e.usegm.coding&&e.gmmode!=F.genomic){const t=new Map;for(const[s,o]of n){if(o[0].chr!=e.usegm.chr){continue}let a=undefined;for(const t of o){if(Number.isFinite(t.aapos))a=t.aapos}if(a==undefined){a=_(o[0].pos,e.usegm).aapos}if(a==undefined){console.error("data item cannot map to aaposition");console.log(o[0]);continue}n.delete(s);if(!t.has(a)){t.set(a,[])}let r=true;for(const s of t.get(a)){if(Math.abs(s[0].__x-o[0].__x)<=e.exonsf*3){for(const t of o){s.push(t)}r=false;break}}if(r){t.get(a).push(o)}}e.usegm.utr5?e.usegm.utr5.reduce(((t,e)=>t+e[1]-e[0]),0):0;for(const e of t.values()){for(const t of e){let e=null;for(const s of t){if(Number.isFinite(s.rnapos))e=s}if(e==null){console.log("trying to map mlst to codon, but no rnapos found");for(const e of t){console.log(e)}continue}r.push({chr:t[0].chr,pos:e.pos,mlst:t,x:t[0].__x})}}}const t=[];const s=2;for(const[e,o]of n){const a=Math.floor(e/s);if(!t[a]){t[a]=[]}t[a]=[...t[a],...o]}for(const e of t){if(!e)continue;const t=e.reduce(((t,e)=>t+e.__x),0);r.push({isbin:true,chr:e[0].chr,pos:e[0].pos,mlst:e,x:t/e.length})}}r.sort(((t,e)=>t.x-e.x));if(t.data&&e.pannedpx!=undefined&&(!e.usegm||e.gmmode==F.genomic)){const e={};for(const s of t.data){e[s.chr+"."+s.pos]={xoffset:s.xoffset}}for(const t of r){const s=t.chr+"."+t.pos;if(e[s]){t.xoffset=e[s].xoffset}}}t.data=r;Ht(t,e);t.height_main=t.toppad+o.toplabelheight+o.maxradius+o.axisheight+o.maxradius+t.stem1+t.stem2+t.stem3+o.bottomlabelheight+t.bottompad;if(!t.data||t.data.length==0){Le(t,e);return}}function Tt(t,e){if(e.vcfinfofilter&&e.vcfinfofilter.setidx4mclass!=undefined){const s=e.vcfinfofilter.lst[e.vcfinfofilter.setidx4mclass];const[o,a]=Se(s,t);if(o||a==undefined)return"black";for(const t of a){if(s.categories[t]){return s.categories[t].color}else{return"black"}}}if(f[t.class]){return f[t.class].color}return"black"}function Ht(t,e){const s=t.numericmode;const f=[];for(const e of t.data){e.x0=e.x;if(e.xoffset!=undefined){e.x=e.x0+e.xoffset}continue}let p=0;if(f.length>0){let t=1;for(let e=0;e<f.length;e++){const s=f[e];const o=[];for(let t=0;t<e;t++){const e=f[t];if(Math.max(s.aa,e.aa)<Math.min(s.pxspan+s.aa,e.pxspan+e.aa)){o.push(e)}}s.y=2;for(const e of o){if(Math.max(s.y,e.y)<Math.min(s.y+s.height,e.y+e.height)){s.y=e.y+e.height+t}}p=Math.max(p,s.y+s.height)}}const u=Math.max(14,e.width/110);s.dotwidth=u;s.maxradius=0;for(const e of t.data){for(const t of e.mlst){t.radius=u/2;s.maxradius=Math.max(t.radius,s.maxradius);t.rimwidth=0;t.aa=e}}const m=Zt(t,e);s.showsamplebar=m&&t.ds&&t.ds.samplebynumericvalue;if(!s.showsamplebar){s.showgenotypebyvalue=m&&t.ds&&t.ds.genotypebynumericvalue}t.genotype2color.legend.style("display",s.showsamplebar||s.showgenotypebyvalue?"block":"none");let h;let g=null;let b=null;let y=0;let x=null;if(s.showsamplebar){h={name:t.ds.samplebynumericvalue.axislabel};for(const e of t.data){for(const s of e.mlst){if(!s.sampledata)continue;for(const e of s.sampledata){const s=e.sampleobj[t.ds.cohort.key4annotation];if(!s)continue;const o=t.ds.cohort.annotation[s];if(!o)continue;const a=o[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(a))continue;if(g==null){g=a;b=a}else{g=Math.min(g,a);b=Math.max(b,a)}}}}}else if(s.showgenotypebyvalue){h={name:t.ds.genotypebynumericvalue.axislabel};for(const e of t.data){for(const s of e.mlst){let e=s.info[t.ds.genotypebynumericvalue.refref.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}e=s.info[t.ds.genotypebynumericvalue.refalt.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}e=s.info[t.ds.genotypebynumericvalue.altalt.infokey];if(e!=undefined){if(g==null){g=e;b=e}else{g=Math.min(g,e);b=Math.max(b,e)}}let o=0,a=0,n=0;if(t.ds.genotypebynumericvalue.refref.genotypeCountInfokey){let e=s.info[t.ds.genotypebynumericvalue.refref.genotypeCountInfokey];if(Number.isFinite(e)){o=e}e=s.info[t.ds.genotypebynumericvalue.refalt.genotypeCountInfokey];if(Number.isFinite(e)){n=e}e=s.info[t.ds.genotypebynumericvalue.altalt.genotypeCountInfokey];if(Number.isFinite(e)){a=e}}else{if(!s.sampledata)continue;for(const t of s.sampledata){if(!t.allele2readcount)continue;if(t.allele2readcount[s.alt]){if(t.allele2readcount[s.ref]){n++}else{a++}}else{o++}}}y=Math.max(y,o,n,a)}}const e=Math.pow(12/2,2)*Math.PI;const s=e*10;x=R().domain([1,y*.1,y*.3,y*.6,y*.8,y]).range([e,e+(s-e)*.8,e+(s-e)*.85,e+(s-e)*.9,e+(s-e)*.95,s])}else{h=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4numeric];for(const e of t.data){for(const t of e.mlst){t._v=0;const[e,s]=Se(h,t);if(e){console.log(e)}else if(s==undefined||s.length==0);else{if(!Number.isFinite(s[0])){console.log("invalid numerical value for variant: "+s[0])}else{t._v=s[0]}}if(g==null){g=t._v;b=t._v}else{g=Math.min(t._v,g);b=Math.max(t._v,b)}}}}const k=R().domain([g,b]).range([0,s.axisheight]);for(const e of t.data){for(const t of e.mlst){t._y=k(t._v)}}if(m){t.stem1=5;t.stem2=20;t.stem3=10}else{t.stem1=0;t.stem2=0;t.stem3=0}for(const e of t.data){for(const s of e.mlst){t.glider.append("text").text(Vt(s.mname)).attr("font-family",I).attr("font-size",s.radius*2-2).each((function(){s.labwidth=this.getBBox().width})).remove()}}for(const e of t.data){for(const t of e.mlst){delete t.labattop;delete t.labatbottom}}if(m){for(const e of t.data){if(e.mlst.length==1){const t=e.mlst[0];t.labattop=true}else{if((e.width-e.fixedgew)/(e.mlst.length-1)<Gt);else{for(const t of e.mlst){t.labattop=true}}}}}else{Qt(t)}s.toplabelheight=0;s.bottomlabelheight=0;if(s.showsamplebar||s.showgenotypebyvalue){for(const e of t.data){for(const t of e.mlst){s.toplabelheight=Math.max(s.toplabelheight,t.labwidth)}}}else{for(const e of t.data){for(const t of e.mlst){if(t.labattop){s.toplabelheight=Math.max(s.toplabelheight,t._y+t.labwidth-s.axisheight)}else if(t.labatbottom){s.bottomlabelheight=Math.max(s.bottomlabelheight,t.labwidth-t._y)}}}}{let o=e.labelfontsize+t.labyspace+e.labelfontsize;if(t.label_stratify){o+=t.label_stratify.length*(t.labyspace+e.labelfontsize)}s.toplabelheight=Math.max(s.toplabelheight,o)}t.leftaxis.attr("transform","translate(-"+u/2+","+(s.toplabelheight+s.maxradius)+")").selectAll("*").remove();{const o=R().domain([g,b]).range([s.axisheight,0]);const a=W().scale(o).ticks(4);if(h.numberIsInteger){a.tickFormat(B("d"));if(b-g<3){a.ticks(b-g)}}q({axis:t.leftaxis.call(a),showline:true,fontsize:u});if(g==b){t.leftaxis.append("text").attr("text-anchor","end").attr("font-size",u).attr("dominant-baseline","central").attr("x",e.tkleftlabel_xshift).attr("y",s.axisheight).text(g).attr("fill","black")}{let e=0;t.leftaxis.selectAll("text").each((function(){e=Math.max(e,this.getBBox().width)}));const o=h.name.split(" ");const a=(s.axisheight-o.length*(u+1))/2;let n=0;o.forEach(((s,o)=>{t.leftaxis.append("text").attr("fill","black").attr("font-size",u).attr("dominant-baseline","central").attr("text-anchor","end").attr("y",a+(u+1)*o).attr("x",-(e+15)).text(s).each((function(){n=Math.max(n,this.getBBox().width+15+e)}))}));t.leftLabelMaxwidth=Math.max(t.leftLabelMaxwidth,n)}}const v=t.glider.append("g").attr("transform","translate(0,0)");v.append("line").attr("y1",s.toplabelheight+s.maxradius).attr("y2",s.toplabelheight+s.maxradius).attr("x2",e.width).attr("stroke","#ededed").attr("shape-rendering","crispEdges");v.append("line").attr("y1",s.toplabelheight+s.maxradius+s.axisheight).attr("y2",s.toplabelheight+s.maxradius+s.axisheight).attr("x2",e.width).attr("stroke","#ededed").attr("shape-rendering","crispEdges");t.skewer2=v.selectAll().data(t.data).enter().append("g").attr("class","sja_skg2").each((function(t){t.g=this}));t.skewer2.attr("transform",(t=>"translate("+t.x+","+(s.toplabelheight+ee+s.maxradius+s.axisheight+s.maxradius)+")"));if(m){t.skewer2.append("path").attr("class","sja_aa_stem").attr("d",(e=>Wt(e,t))).attr("stroke",(e=>Tt(e.mlst[0],t))).attr("fill",(t=>t.mlst.length==1?"none":"#ededed"))}const w=t.skewer2.selectAll().data((t=>t.mlst)).enter().append("g").attr("class","sja_aa_discg").each((function(t){t.g=this}));if(s.showsamplebar){w.attr("transform",(t=>"translate("+t.xoff+",0)"));for(const e of t.data){for(const o of e.mlst){if(!o.sampledata)continue;const e=C(o.g);for(const a of o.sampledata){const n=a.sampleobj[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(i))continue;const l=-k(i)-s.maxradius;const c=a.allele2readcount[o.ref];const f=a.allele2readcount[o.alt];if(f)continue;e.append("line").attr("x1",-o.radius).attr("x2",o.radius).attr("y1",l).attr("y2",l).attr("stroke",c?f?t.genotype2color.ra:t.genotype2color.rr:t.genotype2color.aa).attr("shape-rendering","crispEdges").on("mouseover",(e=>{const s=[{k:t.ds.cohort.key4annotation,v:n}];for(const t in r){s.push({k:t,v:r[t]})}s.push({k:"genotype",v:a.genotype});t.tktip.clear().show(e.clientX,e.clientY);d(t.tktip.d,s);e.target.setAttribute("stroke-width",3);e.target.setAttribute("x1",-o.radius-3);e.target.setAttribute("x2",o.radius+3)})).on("mouseout",(e=>{t.tktip.hide();e.target.setAttribute("stroke-width",1);e.target.setAttribute("x1",-o.radius);e.target.setAttribute("x2",o.radius)}))}for(const a of o.sampledata){const n=a.sampleobj[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[t.ds.samplebynumericvalue.attrkey];if(!Number.isFinite(i))continue;const l=-k(i)-s.maxradius;const c=a.allele2readcount[o.ref];const f=a.allele2readcount[o.alt];if(!f)continue;e.append("line").attr("x1",-o.radius).attr("x2",o.radius).attr("y1",l).attr("y2",l).attr("stroke",c?f?t.genotype2color.ra:t.genotype2color.rr:t.genotype2color.aa).attr("shape-rendering","crispEdges").on("mouseover",(e=>{const s=[{k:t.ds.cohort.key4annotation,v:n}];for(const t in r){s.push({k:t,v:r[t]})}s.push({k:"genotype",v:a.genotype});t.tktip.clear().show(e.clientX,e.clientY);d(t.tktip.d,s);e.target.setAttribute("stroke-width",3);e.target.setAttribute("x1",-o.radius-3);e.target.setAttribute("x2",o.radius+3)})).on("mouseout",(e=>{t.tktip.hide();e.target.setAttribute("stroke-width",1);e.target.setAttribute("x1",-o.radius);e.target.setAttribute("x2",o.radius)}))}}}}else if(s.showgenotypebyvalue){w.attr("transform",(t=>"translate("+t.xoff+",0)"));for(const e of t.data){for(const o of e.mlst){let e=0,a=0,n=0;if(t.ds.genotypebynumericvalue.refref.genotypeCountInfokey){e=o.info[t.ds.genotypebynumericvalue.refref.genotypeCountInfokey];a=o.info[t.ds.genotypebynumericvalue.altalt.genotypeCountInfokey];n=o.info[t.ds.genotypebynumericvalue.refalt.genotypeCountInfokey]}else{if(!o.sampledata)continue;for(const t of o.sampledata){if(!t.allele2readcount)continue;if(t.allele2readcount[o.alt]){if(t.allele2readcount[o.ref]){n++}else{a++}}else{e++}}}const r=C(o.g);if(e){const a=o.info[t.ds.genotypebynumericvalue.refref.infokey];if(a!=undefined){const n=-k(a)-s.maxradius;r.append("circle").attr("cy",n).attr("r",Math.sqrt(x(e))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.refref.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const n=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Ref/Ref"},{k:"#sample",v:e},{k:t.ds.genotypebynumericvalue.axislabel,v:a}];d(t.tktip.d,n)})).on("mouseout",(()=>{t.tktip.hide()}))}}if(n){const e=o.info[t.ds.genotypebynumericvalue.refalt.infokey];if(e!=undefined){const a=-k(e)-s.maxradius;r.append("circle").attr("cy",a).attr("r",Math.sqrt(x(n))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.refalt.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const a=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Ref/Alt"},{k:"#sample",v:n},{k:t.ds.genotypebynumericvalue.axislabel,v:e}];d(t.tktip.d,a)})).on("mouseout",(()=>{t.tktip.hide()}))}}if(a){const e=o.info[t.ds.genotypebynumericvalue.altalt.infokey];if(e!=undefined){const n=-k(e)-s.maxradius;r.append("circle").attr("cy",n).attr("r",Math.sqrt(x(a))/Math.PI).attr("stroke",t.ds.genotypebynumericvalue.altalt.color).attr("fill","white").attr("fill-opacity",0).on("mouseover",(s=>{t.tktip.show(s.clientX,s.clientY).clear();const n=[{k:"Variant",v:o.chr+":"+(o.pos+1)+" "+o.ref+">"+o.alt},{k:"Genotype",v:"Alt/Alt"},{k:"#sample",v:a},{k:t.ds.genotypebynumericvalue.axislabel,v:e}];d(t.tktip.d,n)})).on("mouseout",(()=>{t.tktip.hide()}))}}}}}else{w.attr("transform",(t=>"translate("+t.xoff+","+(t._y+s.maxradius)*-1+")"));const f=w.append("circle");f.filter((t=>t.dt==r||t.dt==o||t.dt==n||t.dt==a)).attr("fill","white").attr("stroke-width",2).attr("stroke",(e=>Tt(e,t))).attr("r",(t=>t.radius-2));f.filter((t=>t.dt==c||t.dt==l||t.dt==i)).attr("fill",(e=>Tt(e,t))).attr("stroke","white").attr("r",(t=>t.radius-.5));w.filter((t=>t.dt==i||t.dt==l)).append("path").attr("fill","white").attr("stroke","none").attr("d",(t=>Q()({innerRadius:0,outerRadius:t.radius-2,startAngle:t.useNterm?0:Math.PI,endAngle:t.useNterm?Math.PI:Math.PI*2})));w.append("circle").attr("r",(t=>t.radius-.5)).attr("stroke",(e=>Tt(e,t))).attr("class","sja_aa_disckick").attr("fill","white").attr("fill-opacity",0).attr("stroke-opacity",0).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>{Xt(s,t);if(t.disc_mouseover){t.disc_mouseover(s,e.target)}else{je(t,[s],true)}})).on("mouseout",((e,s)=>{Yt(s,t);if(t.disc_mouseout){t.disc_mouseout(s)}else{je(t,[s],false)}})).on("click",((s,o)=>{const a=s.target.getBoundingClientRect();Jt(o,a,t,e)}))}const _=w.filter((t=>t.labattop||t.labatbottom)).append("text").each((function(t){t.textlabel=this})).text((t=>Vt(t.mname))).attr("font-family",I).attr("font-size",(t=>{t._labfontsize=Math.max(12,t.radius*1.2);return t._labfontsize})).attr("fill",(e=>Tt(e,t))).attr("x",(t=>s.showsamplebar||s.showgenotypebyvalue?s.axisheight+s.maxradius+4:t.radius+t.rimwidth+ee)).attr("y",(t=>t._labfontsize*te)).attr("class","sja_aa_disclabel").attr("transform",(t=>"rotate("+(t.labattop?"-":"")+"90)")).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>Xt(s,t))).on("mouseout",((e,s)=>Yt(s,t))).on("click",((s,o)=>{Jt(o,{left:s.clientX,top:s.clientY},t,e)}));if(t.hlaachange){_.filter((e=>t.hlaachange.has(e.mname))).classed("sja_pulse",true)}}function Xt(t,e){if(t.textlabel){C(t.textlabel).attr("font-size",t._labfontsize*1.1)}const s=e.numericmode;if(s.showsamplebar)return;if(s.showgenotypebyvalue)return;e.pica.g.attr("transform","translate("+(t.aa.x+t.xoff)+","+(s.toplabelheight+s.maxradius+s.axisheight-t._y)+")");const o=10;const a=4;const n=t._labfontsize||13;const r=Tt(t,e);let i=0,l=false;e.pica.g.append("text").attr("font-size",n).attr("font-family",I).text(t._v).each((function(){i=this.getBBox().width})).remove();if(!t.labattop&&!t.labatbottom){l=true;e.pica.g.append("text").attr("font-size",n).attr("font-family",I).text(t.mname).each((function(){i=Math.max(i,this.getBBox().width)})).remove()}const c=a*2+i;let f,d,p=true;if(c+o>t.aa.x+t.xoff){p=false;d=t.radius+t.rimwidth;f=d+o}else{d=-t.radius-t.rimwidth-o;f=d-c}e.pica.g.append("rect").attr("x",f-2).attr("y",-2-a-(l?n:n/2)).attr("width",4+c).attr("height",4+a*2+n*(l?2:1)).attr("fill","white");e.pica.g.append("line").attr("x1",d).attr("x2",d+o).attr("stroke","white").attr("stroke-width",3).attr("shape-rendering","crispEdges");e.pica.g.append("line").attr("x1",d).attr("x2",d+o).attr("stroke",r).attr("shape-rendering","crispEdges");e.pica.g.append("rect").attr("x",f).attr("y",-a-(l?n:n/2)).attr("width",c).attr("height",a*2+n*(l?2:1)).attr("fill","none").attr("stroke",r).attr("shape-rendering","crispEdges");e.pica.g.append("text").text(t._v).attr("text-anchor",p?"end":"start").attr("font-size",n).attr("font-family",I).attr("x",p?d-a:f+a).attr("y",l?-n/2:0).attr("fill",r).attr("dominant-baseline","central");if(l){e.pica.g.append("text").text(t.mname).attr("text-anchor",p?"end":"start").attr("font-size",n).attr("font-family",I).attr("x",p?d-a:f+a).attr("y",l?n/2:0).attr("fill",r).attr("dominant-baseline","central")}}function Yt(t,e){if(t.textlabel){C(t.textlabel).attr("font-size",t._labfontsize)}e.pica.g.selectAll("*").remove()}async function Jt(t,e,s,o){if(t.dt==i||t.dt==l){$({mlst:[t],pane:true,x:e.left-10,y:e.top-10,tk:s,block:o,svgraph:true});return}if(t.occurrence>1){if(await Ut(t.occurrence,[t],t.aa.x+t.xoff,s.numericmode.toplabelheight+s.numericmode.axisheight-t._y,s,o))return}$({mlst:[t],pane:true,x:e.left-10,y:e.top-10,tk:s,block:o})}function Qt(t){const e=[];for(const s of t.data){for(const t of s.mlst){e.push({m:t,w:2*(t.radius+t.rimwidth),x:s.x0,y:t._y})}}e.sort(((t,e)=>e.y-t.y));for(let t=0;t<e.length;t++){const s=e[t];let o=false;for(let a=0;a<t;a++){const t=e[a];if(Math.abs(s.x-t.x)<(s.w+t.w)/2-2){o=true;break}}if(!o){s.m.labattop=true}}for(let t=e.length-1;t>=0;t--){const s=e[t];if(s.m.labattop)continue;let o=false;for(let a=e.length-1;a>t;a--){const t=e[a];if(t.m.labatbottom&&Math.abs(t.x-s.x)<(t.w+s.w)/2-2){o=true;break}}if(!o){s.m.labatbottom=true}}}function Wt(t,e){if(t.mlst.length==1){return"M0,0v"+e.stem1+"l"+-t.xoffset+","+e.stem2+"v"+e.stem3}return"M0,0"+"v"+e.stem1+"l"+-t.xoffset+","+e.stem2+"v"+e.stem3+"v-"+e.stem3+"l"+(t.stemw+t.xoffset-1)+",-"+e.stem2+"v-"+e.stem1}function Zt(t,e){t.numericmode;const s=100;let o=0;for(const e of t.data){let t=0;for(const s of e.mlst){t+=2*(s.radius+s.rimwidth)}if(e.mlst.length==1){e.width=t}else{e.width=Math.min(s,t);const o=e.mlst[0];const a=e.mlst[e.mlst.length-1];e.fixedgew=o.radius+o.rimwidth+a.radius+a.rimwidth}o+=e.width}if(o<=e.width){let s=0;for(const e of t.data){e.x=s+e.mlst[0].radius+e.mlst[0].rimwidth;s+=e.width;if(e.mlst.length==1){e.stemw=0}else{e.stemw=e.width-e.fixedgew}}Kt(t.data,e.width);for(const e of t.data){e.xoffset=e.x-e.x0;if(e.mlst.length==1){e.mlst[0].xoff=0;e.stemw=0}else{e.stemw=e.width-e.fixedgew;const t=e.stemw/(e.mlst.length-1);for(let s=0;s<e.mlst.length;s++){e.mlst[s].xoff=t*s}}}return true}else{for(const e of t.data){e.x=e.x0;e.xoffset=0;for(const t of e.mlst){t.xoff=0}}return false}}function Kt(t,e){for(let s=0;s<t.length;s++){if(t[s].x0<0)continue;if(t[s].x0>e)break;while(1){let o=0,a=0;for(let n=s;n<t.length;n++){const s=t[n];if(s.x0>e){return}o+=Math.abs(s.x-s.x0-s.stemw/2);s.x++;a+=Math.abs(s.x-s.x0-s.stemw/2)}if(t[s].x>t[s].x0-t[s].stemw/2){for(let e=s;e<t.length;e++){t[e].x--}break}const n=t[t.length-1];if(n.x+n.width/2>=e){return}if(a<=o);else{for(let o=s;o<t.length;o++){if(t[o].x0>e){break}t[o].x--}break}}}}const $t="Not annotated";const te=.3;const ee=1;const se=4;const oe=0;const ae=1;async function ne(t,e){try{if(!t)throw"no tk";if(!t.ds)throw"no ds";if(!e.gmmode||e.gmmode==F.genomic){if(e.viewrangeabovelimit(t.viewrangeupperlimit)){t.mlst=[];t.viewrangeupperlimit_above=true;fe(t,e);return}}delete t.viewrangeupperlimit_above;if(t.isvcf){e.tkcloakon(t);Rt(e,t);return}if(e.ds2handle[t.ds.label]){t.__handlesays=e.ds2handle[t.ds.label].handlesays}if(t.ds.bulkdata||t.ds.mlst){return await ie(t,e)}await le(t,e);re(t,e);t.ds.busy=false;e.tkcloakoff(t,{})}catch(s){if(s.stack)console.log(s.stack);t.ds.busy=false;e.tkcloakoff(t,{error:s.message||s});e.setllabel(t);e.block_setheight()}}function re(t,e){if(!t.legacyDsFilter)return;if(!t.legacyDsFilter.key||!t.legacyDsFilter.value)throw"legacyDsFilter is not {key,value}";const s=t.mlst.filter((e=>e[t.legacyDsFilter.key]==t.legacyDsFilter.value));const o={label:t.ds.label+" - "+t.legacyDsFilter.value,bulkdata:{},parentname:t.ds.label,iscustom:true,sampleselectable:t.ds.sampleselectable};o.bulkdata[e.usegm.name.toUpperCase()]=s;e.addchilddsnoload(o);const a=e.block_addtk_template({type:D.ds,ds:o});ne(a,e)}async function ie(t,e){if(e.usegm){if(t.__handlesays){t.__handlesays.style("background-color","#ddd").style("color","black")}let s=[];if(t.ds.bulkdata){const o=t.ds.bulkdata[e.usegm.name.toUpperCase()];if(o){s=[...o]}}if(t.ds.mlst){for(const o of t.ds.mlst){if(o.gene.toUpperCase()==e.usegm.name.toUpperCase()){s.push(o)}}}if(s.length){const o=[];for(const t of s){if(t.isoform&&t.isoform==e.usegm.isoform){o.push(t)}}if(o.length){ce([{lst:o}],e,t)}else{throw"No data from "+t.ds.label+" for "+e.usegm.isoform}}else{throw"No data from "+t.ds.label+" for "+e.usegm.name}if(t.ds.dbexpression&&(!t.eplst||t.eplst.length==0)){const s={jwt:e.jwt,db:t.ds.dbexpression.dbfile,tablename:t.ds.dbexpression.tablename,keyname:t.ds.dbexpression.keyname,key:e.usegm.name};const o=await w("dbdata",{method:"POST",body:JSON.stringify(s)});if(o.error)throw o.error;if(!t.eplst)t.eplst=[];if(t.ds.dbexpression.tidy)t.ds.dbexpression.tidy(o.rows);const a={data:o.rows,expp:t.ds.dbexpression.config,block:e,genome:e.genome,genename:e.usegm.name,dsname:t.ds.label};const n=await import("./ep-a5c1ee3a.js");t.eplst.push(new n.default(a))}}else{const s=[];const f=new Map;for(const t of e.rglst){if(!f.has(t.chr)){f.set(t.chr,[])}f.get(t.chr).push(t)}const d=[];if(t.ds.bulkdata){for(const e in t.ds.bulkdata){d.push(...t.ds.bulkdata[e])}}if(t.ds.mlst){d.push(...t.ds.mlst)}for(const t of d){switch(t.dt){case c:case r:case o:case n:case a:if(!t.pos){break}if(!t.chr&&!f.has(t.chr)){break}for(const e of f.get(t.chr)){if(t.pos>=e.start&&t.pos<e.stop){s.push(t);break}}break;case l:case i:if(!t.pairlst){break}let e=false;for(const s of t.pairlst){if(s.a.chr&&f.has(s.a.chr)){const t=s.a.position||s.a.pos;if(t){for(const o of f.get(s.a.chr)){if(t>=o.start&&t<o.stop){e=true;break}}}}if(s.b.chr&&f.has(s.b.chr)){const t=s.b.position||s.b.pos;if(t){for(const o of f.get(s.b.chr)){if(t>=o.start&&t<o.stop){e=true;break}}}}}if(e){s.push(t)}break}}if(s.length){ce([{lst:s}],e,t)}}}async function le(t,e){if(t.__handlesays)t.__handlesays.text("Loading...");t.ds.busy=true;e.tkcloakon(t);const s={genome:e.genome.name,dsname:t.ds.label,range:e.tkarg_maygm(t)[0]};if(e.usegm){s.genename=e.usegm.name;s.isoform=e.usegm.isoform}if(t.eplst){s.noexpression=1}if(e.hidedatasetexpression){s.noexpression=1}const o=await w("dsdata",{method:"POST",body:JSON.stringify(s)});if(t.__handlesays){t.__handlesays.text(t.ds.label).style("background-color","#ddd").style("color","black")}if(o.error)throw o.error;ce(o.data,e,t)}function ce(t,e,s){if(s.dsuninitiated){for(let t=0;t<e.tklst.length;t++){if(e.tklst[t].tkid==s.tkid){e.tklst.splice(t,1);break}}delete s.dsuninitiated;let t=-1;for(let s=0;s<e.tklst.length;s++){const o=e.tklst[s];if(o.type==D.usegm&&!o.hidden){t=s;break}}let o=true;if(t==-1){o=true;e.tklst.push(s)}else{let a=false;for(let s=0;s<t;s++){const t=e.tklst[s];if(!t.hidden&&t.type==D.ds){a=true;break}}if(a){o=false;e.tklst.splice(t+1,0,s)}else{o=true;if(t==0){e.tklst.unshift(s)}else{e.tklst.splice(t-1,0,s)}}}if(s.aboveprotein==undefined){s.aboveprotein=o}s.eplst=[]}s.mlst=[];const o=[];for(const a of t){if(a.isgeneexpression){o.push(Me(a,s,e));continue}if(a.vcfid){It(a,s,e);continue}if(a.lst){Ae(a.lst,s,e);Ee(a,s);continue}e.error("unknown data/query type from "+s.ds.label);return}Promise.all(o).then((()=>{if(s.eplst.length>1){for(let t=1;t<s.eplst.length;t++){const e=s.eplst[t];e.pane.pane.style("left",Number.parseInt(s.eplst[0].pane.pane.style("left"))+50*t+"px");e.pane.pane.style("top",Number.parseInt(s.eplst[0].pane.pane.style("top"))+50*t+"px")}}}));fe(s,e)}function fe(t,e){e.tkcloakoff(t,{});de(t);if(t.vcfinfofilter&&t.vcfinfofilter.setidx4numeric!=undefined){if(!t.numericmode){t.numericmode={axisheight:t.axisheight}}}else{delete t.numericmode}const s=new Set;for(const t in L){if(L[t].hidden){s.add(t)}}Pe(t);if(t.numericmode){Ot(t,e,s)}else{pe(t,e,s)}e.setllabel(t);e.block_setheight();e.tkchangeaffectlegend(t);Ne(t,e);Re(t,e);{const s=Ie(t,e);if(s)console.log("showlegend_sampleattribute: "+s)}}function de(t){if(t.vcfinfofilter&&t.vcfinfofilter.setidx4occurrence!=undefined){const e=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4occurrence];if(!e)throw"mcset not found by setidx4occurrence";for(const s of t.mlst){const[t,o]=Se(e,s);if(t||o==undefined){s.occurrence=1}else{s.occurrence=o[0]}}}else{for(const e of t.mlst){e.occurrence=1}}}function pe(t,e,s){t.leftaxis.selectAll("*").remove();if(e.usegm&&e.gmmode!=F.genomic&&e.pannedpx!=undefined&&t.skewer){De(t,e);t.skewer.attr("transform",(t=>"translate("+t.x+","+t.y+")"));ye(t,e)}else{t.glider.selectAll("*").remove();qe(t,e,s);const o=new Map;for(const e of t.mlst){if(e.__x==undefined){continue}if(!o.has(e.__x)){o.set(e.__x,[])}o.get(e.__x).push(e)}const a=[];if(e.exonsf>=se){for(const[t,e]of o){a.push({chr:e[0].chr,pos:e[0].pos,mlst:e,x:t,groups:ue(e)})}}else{if(e.usegm&&e.usegm.coding&&e.gmmode!=F.genomic){const t=new Map;for(const[s,a]of o){if(a[0].chr!=e.usegm.chr){continue}let n=undefined;for(const t of a){if(Number.isFinite(t.aapos))n=t.aapos}if(n==undefined){n=_(a[0].pos,e.usegm).aapos}if(n==undefined){console.error("data item cannot map to aaposition");console.log(a[0]);continue}o.delete(s);if(!t.has(n)){t.set(n,[])}let r=true;for(const s of t.get(n)){if(Math.abs(s[0].__x-a[0].__x)<=e.exonsf*3){for(const t of a){s.push(t)}r=false;break}}if(r){t.get(n).push(a)}}e.usegm.utr5?e.usegm.utr5.reduce(((t,e)=>t+e[1]-e[0]),0):0;for(const e of t.values()){for(const t of e){let e=null;for(const s of t){if(Number.isFinite(s.rnapos))e=s}if(e==null){console.log("trying to map mlst to codon, but no rnapos found");for(const e of t){console.log(e)}continue}a.push({chr:t[0].chr,pos:e.pos,mlst:t,x:t[0].__x,groups:ue(t)})}}}const t=[];const s=2;for(const[e,a]of o){const o=Math.floor(e/s);if(!t[o]){t[o]=[]}t[o]=[...t[o],...a]}for(const e of t){if(!e)continue;const t=e.reduce(((t,e)=>t+e.__x),0);a.push({isbin:true,chr:e[0].chr,pos:e[0].pos,mlst:e,x:t/e.length,groups:ue(e)})}}a.sort(((t,e)=>t.x-e.x));if(t.data&&e.pannedpx!=undefined&&(!e.usegm||e.gmmode==F.genomic)){const e={};for(const s of t.data){e[s.chr+"."+s.pos]={mode:s.showmode,xoffset:s.xoffset,slabelrotate:s.slabelrotate}}for(const t of a){const s=t.chr+"."+t.pos;if(e[s]){t.showmode=e[s].mode;t.xoffset=e[s].xoffset;t.slabelrotate=e[s].slabelrotate}}}t.data=a;for(const e of t.data){e.occurrence=e.groups.reduce(((t,e)=>t+e.occurrence),0)}me(t,e);t.height_main=t.toppad+t.maxskewerheight+t.stem1+t.stem2+t.stem3+t.bottompad}if(!t.data||t.data.length==0){Le(t,e);return}if(t.hlaachange||t.hlvariants){const s=[];const o=[];if(t.hlaachange){for(const e of t.data){let a=false;for(const s of e.groups){if(t.hlaachange.has(s.mlst[0].mname)){a=true;t.hlaachange.delete(s.mlst[0].mname);break}}if(a){o.push(e)}else{s.push(e)}}if(t.hlaachange.size){if(!e.usegm){e.error("cannot add items from hlaachange: not in gene-mode")}else{ze(t,e)}}delete t.hlaachange}if(t.hlvariants){const e={};for(const s of t.hlvariants){e[s.chr+"."+s.pos+"."+s.ref+"."+s.alt]=1}for(const a of t.data){let t=false;for(const s of a.groups){if(t){break}for(const o of s.mlst){if(e[o.chr+"."+o.pos+"."+o.ref+"."+o.alt]){t=true;break}}}if(t){o.push(a)}else{s.push(a)}}}_e(s,t);xe(o,t,e)}else{ye(t,e)}}function ue(t,e){const s=new Map;for(const e of t){switch(e.dt){case c:if(!s.has(e.dt)){s.set(e.dt,new Map)}if(!s.get(e.dt).has(e.class)){s.get(e.dt).set(e.class,new Map)}const t=e.mname||"";if(!s.get(e.dt).get(e.class).has(t)){s.get(e.dt).get(e.class).set(t,[])}s.get(e.dt).get(e.class).get(t).push(e);break;case l:case i:if(!s.has(e.dt)){s.set(e.dt,new Map)}if(!s.get(e.dt).has(e.class)){s.get(e.dt).set(e.class,{use5:new Map,use3:new Map})}if(e.useNterm){if(!s.get(e.dt).get(e.class).use5.has(e.mname)){s.get(e.dt).get(e.class).use5.set(e.mname,[])}s.get(e.dt).get(e.class).use5.get(e.mname).push(e)}else{if(!s.get(e.dt).get(e.class).use3.has(e.mname)){s.get(e.dt).get(e.class).use3.set(e.mname,[])}s.get(e.dt).get(e.class).use3.get(e.mname).push(e)}break;case r:case o:case n:case a:if(!s.has(e.dt)){s.set(e.dt,[])}s.get(e.dt).push(e);break;default:console.log("unknown datatype: "+e.dt);console.log(e);return}}const f=[];for(const[t,e]of s){switch(t){case c:for(const s of e.values()){for(const e of s.values()){f.push({dt:t,mlst:e})}}break;case l:case i:for(const s of e.values()){for(const e of s.use5.values()){f.push({dt:t,useNterm:true,mlst:e})}for(const e of s.use3.values()){f.push({dt:t,useNterm:false,mlst:e})}}break;case r:case o:case n:case a:f.push({dt:t,mlst:e})}}for(const t of f){let e=0,s=0;for(const o of t.mlst){if(o.isrim1)e++;else if(o.isrim2)s++}t.rim1count=e;t.rim2count=s;t.occurrence=t.mlst.reduce(((t,e)=>t+e.occurrence),0)}f.sort(((t,e)=>e.occurrence-t.occurrence));return f}function me(t,e){delete t.skewer2;const s=e=>{if(t.vcfinfofilter&&t.vcfinfofilter.setidx4mclass!=undefined){const s=t.vcfinfofilter.lst[t.vcfinfofilter.setidx4mclass];const[o,a]=Se(s,e);if(o||a==undefined)return"black";for(const t of a){if(s.categories[t]){return s.categories[t].color}else{return"black"}}}if(f[e.class]){return f[e.class].color}return"black"};const d=[];for(const s of t.data){s.x0=s.x;if(s.xoffset!=undefined){s.x=s.x0+s.xoffset}for(const t of s.groups){t.aa=s;let a=null;if(t.dt==r){a=t.mlst[0].rnaduplength;for(const e of t.mlst){a=Math.max(a,e.rnaduplength)}}else if(t.dt==o){a=t.mlst[0].rnadellength;for(const e of t.mlst){a=Math.max(a,e.rnadellength)}}else{continue}if(!Number.isFinite(a)||a<0){console.log("no rnaspan for stack bar from itd/del");console.log(t.mlst);continue}let n=null;if(e.usegm){const o=t.mlst[0].rnapos;const r=E(o+a,e.usegm);const i=e.seekcoord(e.usegm.chr,r);if(i.length>0){n=i[0].x-s.x}else{console.log(r+" no hit on rglst")}}if(!Number.isFinite(n)){console.log("no pxspan for stack bar from itd/del");console.log(t.mlst);continue}t.stackbar={aa:s.mlst[0].aapos,pxspan:n,height:4,grp:t};s.hasstackbar=true;d.push(t.stackbar)}}let p=0;if(d.length>0){let t=1;for(let e=0;e<d.length;e++){const s=d[e];const o=[];for(let t=0;t<e;t++){const e=d[t];if(Math.max(s.aa,e.aa)<Math.min(s.pxspan+s.aa,e.pxspan+e.aa)){o.push(e)}}s.y=2;for(const e of o){if(Math.max(s.y,e.y)<Math.min(s.y+s.height,e.y+e.height)){s.y=e.y+e.height+t}}p=Math.max(p,s.y+s.height)}}const u=Math.max(14,e.width/110);let m=0;for(const e of t.data){for(const t of e.groups){m=Math.max(m,t.occurrence)}}let h=0;const g=Math.pow(u/2,2)*Math.PI;if(m<=10)h=g*m*.9;else if(m<=100)h=g*10;else if(m<=1e3)h=g*14;else h=g*20;const b=R().domain([1,m*.5,m*.6,m*.7,m*.8,m]).range([g,g+(h-g)*.8,g+(h-g)*.85,g+(h-g)*.9,g+(h-g)*.95,h]);let y=u/2;t.maxskewerheight=0;t.skewer=t.glider.selectAll().data(t.data).enter().append("g").attr("class","sja_skg").each((function(e){e.skewer=this;if(e.showmode==undefined){e.showmode=oe}e.maxradius=0;e.maxrimwidth=0;e.width=0;e.slabelrotate=false;e.slabelwidth=0;for(const t of e.groups){if(t.occurrence==1){t.radius=u/2}else{const e=t.occurrence.toString().length;t.radius=Math.max(Math.sqrt(b(t.occurrence)/Math.PI),e*5)}e.maxradius=Math.max(e.maxradius,t.radius);y=Math.max(y,t.radius);t.rimwidth=t.rim1count+t.rim2count==0?0:Math.max(2,t.radius/6);e.maxrimwidth=Math.max(e.maxrimwidth,t.rimwidth)}let s=0;for(const t of e.groups){t.yoffset=s+t.radius+t.rimwidth;s+=(t.radius+t.rimwidth)*2}t.maxskewerheight=Math.max(t.maxskewerheight,s)}));const x=t.skewer.selectAll().data((t=>t.groups)).enter().append("g").attr("transform",(e=>"translate(0,"+(e.aa.showmode==oe?0:e.yoffset*(t.aboveprotein?-1:1))+")")).attr("class","sja_aa_discg").each((function(t){t.g=this}));const k=x.append("circle");k.filter((t=>t.dt==r||t.dt==o||t.dt==n||t.dt==a)).attr("fill","white").attr("stroke-width",2).attr("stroke",(t=>s(t.mlst[0]))).attr("r",(t=>t.radius-2));k.filter((t=>t.dt==c||t.dt==l||t.dt==i)).attr("fill",(t=>s(t.mlst[0]))).attr("stroke","white").attr("r",(t=>t.radius-.5));x.filter((t=>t.dt==i||t.dt==l)).append("path").attr("fill","white").attr("stroke","none").attr("d",(t=>Q()({innerRadius:0,outerRadius:t.radius-2,startAngle:t.useNterm?0:Math.PI,endAngle:t.useNterm?Math.PI:Math.PI*2})));const v=x.filter((t=>t.occurrence>1)).append("text").text((t=>t.occurrence)).attr("font-family",I).attr("class","sja_aa_discnum").attr("fill-opacity",(t=>t.aa.showmode==oe?0:1)).attr("stroke-opacity",(t=>t.aa.showmode==oe?0:1)).attr("text-anchor","middle").each((t=>{const e=t.radius*1.5;t.discnumfontsize=Math.min(e/(t.occurrence.toString().length*S),e)})).attr("font-size",(t=>t.discnumfontsize)).attr("y",(t=>t.discnumfontsize*te));v.filter((t=>t.dt==c)).attr("fill","white");v.filter((t=>t.dt==l||t.dt==i)).attr("stroke",(t=>s(t.mlst[0]))).attr("stroke-width",.8).attr("font-weight","bold").attr("fill","white");v.filter((t=>t.dt==r||t.dt==o||t.dt==a||t.dt==n)).attr("fill",(t=>s(t.mlst[0])));const w=x.append("text").text((t=>t.mlst[0].mname)).attr("font-size",(t=>{t._labfontsize=Math.max(12,t.radius*1.2);return t._labfontsize})).each((function(e){const s=this.getBBox().width;e._label_width=s;if(e.aa.groups.length==1){e.aa.slabelrotate=true;e.aa.slabelwidth=s;t.maxskewerheight=Math.max(t.maxskewerheight,(e.radius+e.rimwidth)*2+2+s)}})).attr("fill",(t=>s(t.mlst[0]))).attr("x",(t=>t.radius+t.rimwidth+1)).attr("y",(t=>t._labfontsize*te)).attr("font-family",I).classed("sja_aa_disclabel",true).attr("fill-opacity",(t=>t.aa.showmode==oe?0:1)).attr("transform","scale(1) rotate(0)").on("mousedown",(t=>{t.stopPropagation()})).on("click",((s,o)=>{_e([o.aa],t);ke(t,e);if(e.debugmode){console.log(o.aa)}}));if(t.hlaachange){w.filter((e=>t.hlaachange.has(e.mlst[0].mname))).classed("sja_pulse",true)}for(const e of t.data){let t=0,s=0;for(const o of e.groups){t=Math.max(t,o.radius+o.rimwidth);s=Math.max(s,o.radius+o.rimwidth+ee+o._label_width)}e.width=t+s}x.append("circle").attr("r",(t=>t.radius-.5)).attr("stroke",(t=>s(t.mlst[0]))).attr("class","sja_aa_disckick").attr("fill","white").attr("fill-opacity",0).attr("stroke-opacity",0).on("mousedown",(t=>{t.stopPropagation()})).on("mouseover",((e,s)=>{if(t.disc_mouseover){t.disc_mouseover(s,e.target)}else{je(t,s.mlst,true)}})).on("mouseout",((e,s)=>{if(t.disc_mouseout){t.disc_mouseout(s)}else{je(t,s.mlst,false)}})).on("click",(async(s,o)=>{const a=s.target.getBoundingClientRect();if(o.dt==i||o.dt==l){$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e,svgraph:true});return}if(o.occurrence==1){$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e});return}if(await Ut(o.occurrence,o.mlst,o.aa.x,ge(o,t)+o.yoffset*(t.aboveprotein?-1:1),t,e)){return}$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e})}));const _=Q().innerRadius((t=>t.radius)).outerRadius((t=>t.radius+t.rimwidth)).startAngle(0).endAngle((t=>{t.rim1_startangle=Math.PI*2*t.rim1count/t.occurrence;return t.rim1_startangle}));x.append("path").attr("d",_).attr("fill",(t=>s(t.mlst[0]))).attr("class","sja_aa_discrim").attr("fill-opacity",0);const j=Q().innerRadius((t=>t.radius+.5)).outerRadius((t=>t.radius+.5+t.rimwidth)).startAngle((t=>t.rim1_startangle)).endAngle((t=>t.rim1_startangle+Math.PI*2*t.rim2count/t.occurrence));x.filter((t=>t.rim2count>0)).append("path").attr("d",j).attr("stroke",(t=>s(t.mlst[0]))).attr("fill","none").attr("class","sja_aa_discrim").attr("stroke-opacity",0);{let e=0;let s=0;for(const o of t.data){if(o.x-o.maxradius-o.maxrimwidth<s){e++}s=Math.max(s,o.x+o.width-o.maxradius-o.maxrimwidth)}t.stem1=e==0?0:u;t.stem2=R().domain([0,1,t.data.length]).range([0,u,u*3])(e)}const M=u*.7;let A=0;for(const e of t.data){for(const t of e.groups){A=Math.max(A,t.occurrence)}}t.stem3=Math.max(p+2,M+u*Math.min(5,A));t.skewer.append("circle").attr("class","sja_aa_skkick").attr("fill","white").attr("fill-opacity",0).attr("stroke","none").attr("r",(t=>t.maxradius+1)).attr("cy",(e=>(t.aboveprotein?-1:1)*e.maxradius)).attr("transform",(t=>"scale("+(t.showmode==oe?1:0)+")")).on("mouseover",((e,o)=>{je(t,o.mlst,true);const a=t.aboveprotein;let n=0;let r=0;const i=5;const l=a?7:14;for(const e of o.groups){e.pica_fontsize=Math.max(11,e.radius);n+=e.pica_fontsize+1;t.pica.g.append("text").text(e.mlst[0].mname+(e.occurrence>1?" x"+e.occurrence:"")).attr("font-size",e.pica_fontsize).each((function(){r=Math.max(r,this.getBBox().width)})).remove()}r+=i*2;const c=n+5;t.pica.g.append("rect").attr("y",a?-c:0).attr("width",r).attr("height",c).attr("fill","white").attr("fill-opacity",.8).attr("stroke","#ccc").attr("shape-rendering","crispEdges");n=0;const f=t.pica.g.selectAll().data(o.groups).enter().append("g").attr("transform",((t,e)=>{n+=t.pica_fontsize+1;return"translate("+i+","+n*(a?-1:1)+")"}));f.append("text").text((t=>t.mlst[0].mname)).attr("font-size",(t=>t.pica_fontsize)).each((function(t){t.pica_mlabelwidth=this.getBBox().width})).attr("fill",(t=>s(t.mlst[0]))).attr("dominant-baseline",a?"hanging":"auto");const d=o.groups[0].pica_mlabelwidth;t.pica.x=o.x-i-d/2;t.pica.y=o.y+(a?-1:1)*(o.maxradius*2+l+2);t.pica.g.attr("transform","translate("+t.pica.x+","+t.pica.y+")");f.filter((t=>t.occurrence>1)).append("text").text((t=>"x"+t.occurrence)).attr("x",(t=>t.pica_mlabelwidth+5)).attr("font-size",(t=>t.pica_fontsize)).attr("dominant-baseline",a?"hanging":"auto").attr("fill","#9e9e9e");const p=t.pica.g.append("g").attr("transform","translate("+(i+d/2)+","+(a?1:-1)+")");p.append("line").attr("y2",(a?1:-1)*l).attr("stroke","#858585").attr("shape-rendering","crispEdges");p.append("line").attr("x1",-1).attr("x2",-1).attr("y2",(a?1:-1)*l).attr("stroke","white").attr("shape-rendering","crispEdges");p.append("line").attr("x1",1).attr("x2",1).attr("y2",(a?1:-1)*l).attr("stroke","white").attr("shape-rendering","crispEdges")})).on("mouseout",((e,s)=>{t.pica.g.selectAll("*").remove();je(t,s.mlst,false)})).on("click",((s,o)=>{t.pica.g.selectAll("*").remove();xe([o],t,e)}));let z=0;for(const e of t.data){z=Math.max(z,e.occurrence)}const N=R().domain([1,z]).range([M,t.stem3-y]);t.skewer.attr("transform",(e=>{e.foldyoffset=N(e.occurrence);e.y=ge(e,t);return"translate("+e.x+","+e.y+")"}));if(d.length>0){t.skewer.filter((t=>t.hasstackbar)).selectAll().data((t=>{const e=[];for(const s of t.groups){if(s.stackbar){e.push(s.stackbar)}}return e})).enter().append("g").attr("class","sja_aa_stackbar_g").attr("transform",(e=>"translate(0,"+(t.aboveprotein?1:-1)*(t.stem1-e.y)+")")).append("rect").attr("y",(e=>t.aboveprotein?-e.height:0)).attr("class","sja_aa_stackbar_rect").attr("width",0).attr("shape-rendering","crispEdges").attr("fill-opacity",.5).attr("stroke","none").attr("stroke-width",1).attr("height",(t=>t.height)).attr("fill",(t=>s(t.grp.mlst[0]))).on("mouseover",((e,a)=>{const n=s(a.grp.mlst[0]);C(e.target).attr("stroke",n);const i=t.pica;let l="wrong label";let c="wrong label, ";switch(a.grp.mlst[0].dt){case r:l=f[a.grp.mlst[0].class].desc;c=Math.ceil(a.grp.mlst[0].rnaduplength/3)+" aa, ";break;case o:l=f[a.grp.mlst[0].class].label;c=Math.ceil(a.grp.mlst[0].rnadellength/3)+" aa, ";break}if(a.grp.occurrence==1){const t=a.grp.mlst[0];if(t.sample){c+=t.sample}else if(t.patient){c+=t.patient}else{c+="1 sample"}}else{c+=a.grp.occurrence+" samples"}const d=14,p=10,u=2,m=4;let h=0;i.g.append("text").text(l).attr("font-size",d).attr("font-family",I).each((function(){h=this.getBBox().width})).remove();i.g.append("text").text(c).attr("font-size",p).attr("font-family",I).each((function(){h=Math.max(h,this.getBBox().width)})).remove();const g=u*3+d+p;i.x=a.grp.aa.x0+3;i.y=t.aboveprotein?t.height_main-t.toppad-t.bottompad-a.y-a.height-3-g:a.y+a.height+3;i.g.attr("transform","translate("+i.x+","+i.y+")");i.g.append("rect").attr("width",h+m*2).attr("height",g).attr("stroke",n).attr("stroke-width",1).attr("shape-rendering","crispEdges").attr("fill","white").attr("fill-opacity",.8);i.g.append("text").text(l).attr("x",m).attr("y",u+d/2).attr("dominant-baseline","middle").attr("font-size",d).attr("font-family",I).attr("fill",n);i.g.append("text").text(c).attr("x",m).attr("y",u*2+d+p/2).attr("dominant-baseline","middle").attr("font-size",p).attr("font-family",I).attr("fill","#858585")})).on("mouseout",((e,s)=>{C(e.target).attr("stroke","none");t.pica.g.selectAll("*").remove()})).on("click",((s,o)=>{$({mlst:o.grp.mlst,pane:true,x:s.clientX,y:s.clientY,tk:t,block:e})}))}t.skewer.append("path").attr("class","sja_aa_stem").attr("d",(e=>be(e,t))).attr("stroke",(t=>s(t.groups[0].mlst[0]))).attr("fill","none");const P=t.skewer.filter((t=>t.groups.length>1));P.append("rect").attr("class","sja_aa_ssk_bg").attr("shape-rendering","crispEdges").attr("fill-opacity",0).attr("height",t.stem1).attr("fill",(t=>s(t.groups[0].mlst[0]))).attr("width",(t=>{t.ssk_width=Math.max(t.occurrence.toString().length*8+6,2*(t.maxradius+t.maxrimwidth));return t.ssk_width})).attr("x",(t=>-t.ssk_width/2));P.append("text").attr("class","sja_aa_ssk_text").attr("fill","white").attr("fill-opacity",0).attr("font-weight","bold").attr("text-anchor","middle").attr("dominant-baseline","central").text((t=>t.occurrence)).each((e=>{e.ssk_fontsize=Math.min(t.stem1,e.ssk_width/(e.occurrence.toString().length*S))})).attr("font-size",(t=>t.ssk_fontsize));P.append("rect").attr("class","sja_aa_ssk_kick").attr("fill","white").attr("fill-opacity",0).attr("stroke","none").attr("height",t.stem1).attr("x",(t=>-t.ssk_width/2)).attr("width",(t=>t.ssk_width)).on("mouseover",((e,s)=>{const o=C(e.target.parentNode);o.selectAll(".sja_aa_disckick").transition().attr("stroke-opacity",1);o.select(".sja_aa_ssk_bg").transition().attr("fill-opacity",1).attr("stroke-opacity",1);o.select(".sja_aa_ssk_text").transition().attr("fill-opacity",1);je(t,s.mlst,true)})).on("mouseout",(function(e,s){const o=C(e.target.parentNode);o.selectAll(".sja_aa_disckick").transition().attr("stroke-opacity",0);o.select(".sja_aa_ssk_bg").transition().attr("fill-opacity",0).attr("stroke-opacity",0);o.select(".sja_aa_ssk_text").transition().attr("fill-opacity",0);je(t,s.mlst,false)})).on("click",(async(s,o)=>{const a=s.target.getBoundingClientRect();if(o.occurrence>1){if(await Ut(o.occurrence,o.mlst,o.x,o.y+(t.aboveprotein?1:-1)*t.stem1/2,t,e))return}$({mlst:o.mlst,pane:true,x:a.left-10,y:a.top-10,tk:t,block:e})}))}function he(t){t.aboveprotein=!t.aboveprotein;if(t.numericmode){return}const e=t.aboveprotein;const s=1e3;const o=t.skewer.filter((t=>t.hasstackbar));o.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(s=>{const o=s.grp.aa;return"translate("+(o.showmode==oe?0:o.x0-o.x)+","+(e?1:-1)*(o.showmode==oe?t.stem1-s.y:t.stem1+t.stem2+t.stem3-s.y)+")"}));o.filter((t=>t.showmode==ae)).selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("y",(t=>e?-t.height:0));t.skewer.transition().duration(s).attr("transform",(e=>{e.y=ge(e,t);return"translate("+e.x+","+e.y+")"}));t.skewer.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(e=>be(e,t)));t.skewer.selectAll(".sja_aa_discg").transition().duration(s).attr("transform",(t=>{t.y=(e?-1:1)*(t.aa.showmode==oe?t.aa.maxradius:t.yoffset);return"translate(0,"+t.y+")"}));t.skewer.selectAll(".sja_aa_ssk_kick").attr("y",e?0:-t.stem1);t.skewer.selectAll(".sja_aa_ssk_bg").attr("y",e?0:-t.stem1);t.skewer.selectAll(".sja_aa_ssk_text").attr("y",(e?1:-1)*t.stem1/2);t.skewer.selectAll(".sja_aa_skkick").attr("cy",(t=>(e?-1:1)*t.maxradius));t.skewer.filter((t=>t.showmode==ae&&t.groups.length==1)).selectAll(".sja_aa_disclabel").transition().duration(s).attr("transform",(t=>"scale(1) rotate("+(t.aa.slabelrotate?(e?"-":"")+"90":"0")+")"))}function ge(t,e){if(e.aboveprotein){if(t.showmode==oe){return e.maxskewerheight+e.stem1+e.stem2+e.stem3-t.foldyoffset}return e.maxskewerheight}if(t.showmode==oe)return t.foldyoffset;return e.stem1+e.stem2+e.stem3}function be(t,e){if(e.aboveprotein){if(t.showmode==oe){return"M0,0v0l0,0v"+t.foldyoffset}return"M0,0v"+e.stem1+"l"+(t.x0-t.x)+","+e.stem2+"v"+e.stem3}if(t.showmode==oe){return"M0,0v0l0,0v-"+t.foldyoffset}return"M0,0v-"+e.stem1+"l"+(t.x0-t.x)+",-"+e.stem2+"v-"+e.stem3}function ye(t,e){if(t.data.length==0){return}const s=0;const o=e.width;let a=0;const n=[];const r=[];for(const e of t.data){if(e.x0<s||e.x0>o){delete e.xoffset;r.push(e)}else{a+=e.slabelrotate?(e.groups[0].radius+e.groups[0].rimwidth)*2:e.width;n.push(e)}}_e(r,t);let i=[];const l=[];if(a<o-s){i=n}else{n.sort(((t,e)=>{if(e.occurrence==t.occurrence){if(e.groups.length==t.groups.length){return Math.abs(t.x0*2-s-o)-Math.abs(e.x0*2-s-o)}else{return e.groups.length-t.groups.length}}return e.occurrence-t.occurrence}));let t=0;let e=(o-s)*.8;let a=false;for(const s of n){if(a){delete s.xoffset;l.push(s);s.showmode=oe}else{if(t+s.width<e){i.push(s);t+=s.width}else{a=true;delete s.xoffset;l.push(s);s.showmode=oe}}}}_e(l,t);xe(i,t,e)}function xe(t,e,s){const o=1e3;const a=e.aboveprotein;const n=new Set;const r=new Set;let i=false;for(const s of t){if(s.showmode==ae){n.add(s.x0)}else{s.showmode=ae;r.add(s.x0);i=true;s.y=ge(s,e)}}if(i){const t=e.skewer.filter((t=>r.has(t.x0)));t.transition().duration(o).attr("transform",(t=>"translate("+t.x+","+t.y+")"));t.selectAll(".sja_aa_discg").transition().duration(o).attr("transform",(t=>{t.y=t.yoffset*(a?-1:1);return"translate(0,"+t.y+")"}));setTimeout((function(){t.selectAll(".sja_aa_disckick").attr("transform","scale(1)")}),o);t.selectAll(".sja_aa_discnum").transition().duration(o).attr("fill-opacity",1).attr("stroke-opacity",1);t.filter((t=>t.groups.length>1)).selectAll(".sja_aa_disclabel").transition().duration(o).attr("fill-opacity",1).attr("transform","scale(1)");t.selectAll(".sja_aa_discrim").transition().duration(o).attr("fill-opacity",1).attr("stroke-opacity",1);t.selectAll(".sja_aa_ssk_kick").attr("transform","scale(1)").attr("y",a?0:-e.stem1);t.selectAll(".sja_aa_ssk_bg").attr("transform","scale(1)").attr("y",a?0:-e.stem1);t.selectAll(".sja_aa_ssk_text").attr("transform","scale(1)").attr("y",(a?1:-1)*e.stem1/2);t.selectAll(".sja_aa_skkick").attr("transform","scale(0)");t.filter((t=>t.hasstackbar)).selectAll(".sja_aa_stackbar_g").attr("transform",(t=>"translate(0,"+(a?1:-1)*(e.stem1+e.stem2+e.stem3-t.y)+")"));let n=0;t.selectAll(".sja_aa_stem").transition().duration(o).attr("d",(t=>be(t,e))).each((()=>++n)).on("end",(()=>{if(! --n){ke(e,s)}}))}else{ke(e,s)}}function ke(t,e){const s=1e3;const o=t.aboveprotein;const a=[];const n=new Set;const r=0;const i=e.width;for(const e of t.data){if(e.x0<r||e.x0>i)continue;if(e.showmode==ae){e.x=e.x0;a.push(e);n.add(e.x0)}}if(a.length==0){return}ve(a,t,e);for(const t of a){t.xoffset=t.x-t.x0}for(let e=0;e<a.length;e++){const s=a[e];if(s.groups.length>1)continue;const o=s.groups[0];if(t.slabel_forcerotate){s.slabelrotate=true}else{const t=a[e+1];const n=t?t.x-t.maxradius-t.maxrimwidth:i;s.slabelrotate=n-s.x-o.radius-o.rimwidth-1<s.slabelwidth}s.width=(o.radius+o.rimwidth)*2+(s.slabelrotate?0:2+s.slabelwidth)}const l=t.skewer.filter((t=>n.has(t.x0)));l.transition().duration(s).attr("transform",(t=>"translate("+t.x+","+t.y+")"));l.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(e=>be(e,t)));l.filter((t=>t.groups.length==1)).selectAll(".sja_aa_disclabel").transition().duration(s).attr("fill-opacity",1).attr("transform",(t=>"scale(1) rotate("+(t.aa.slabelrotate?(o?"-":"")+"90":"0")+")"));t.slabel_forcerotate=false;const c=l.filter((t=>t.hasstackbar));c.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(e=>"translate("+(e.grp.aa.x0-e.grp.aa.x)+","+(o?1:-1)*(t.stem1+t.stem2+t.stem3-e.y)+")"));c.selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("width",(t=>t.pxspan)).attr("y",(t=>o?-t.height:0))}function ve(t,e,s){const o=0;const a=s.width;let n=o;let r=false;for(const e of t){if(e.x0<o||e.x0>a)continue;if(e.groups.length==1){e.slabelrotate=true;const t=e.groups[0];e.width=(t.radius+t.rimwidth)*2}const t=e.x-e.maxradius-e.maxrimwidth;if(t<n){r=true}if(t+e.width>a){r=true}n=Math.max(n,t+e.width)}if(!r){return false}n=o;for(const e of t){if(e.x0<o||e.x0>a)continue;e.x=n+e.maxradius+e.maxrimwidth;n+=e.width}we(t,s.width)}function we(t,e){for(let s=0;s<t.length;s++){if(t[s].x0<0)continue;if(t[s].x0>e)break;while(1){let o=0,a=0;for(let n=s;n<t.length;n++){const s=t[n];if(s.x0>e){return}o+=Math.abs(s.x-s.x0);s.x++;a+=Math.abs(s.x-s.x0)}if(t[s].x>=t[s].x0){for(let e=s;e<t.length;e++){t[e].x--}break}const n=t[t.length-1];if(n.x+n.width/2>=e){return}if(a<=o);else{for(let o=s;o<t.length;o++){if(t[o].x0>e){break}t[o].x--}break}}}}function _e(t,e){if(t.length==0)return;const s=1e3;const o=e.aboveprotein;const a=new Set;for(const s of t){s.x=s.x0;a.add(s.x0);s.showmode=oe;s.y=ge(s,e)}const n=e.skewer.filter((t=>a.has(t.x0)));n.transition().duration(s).attr("transform",(t=>"translate("+t.x+","+t.y+")"));n.selectAll(".sja_aa_stem").transition().duration(s).attr("d",(t=>be(t,e)));n.selectAll(".sja_aa_discg").transition().duration(s).attr("transform",(t=>"translate(0,"+(o?"-":"")+t.aa.maxradius+")"));n.selectAll(".sja_aa_disckick").attr("transform","scale(0)");n.selectAll(".sja_aa_discnum").transition().duration(s).attr("fill-opacity",0).attr("stroke-opacity",0);n.selectAll(".sja_aa_disclabel").transition().duration(s).attr("fill-opacity",0).attr("transform","scale(0)");n.selectAll(".sja_aa_discrim").transition().duration(s).attr("fill-opacity",0).attr("stroke-opacity",0);n.selectAll(".sja_aa_ssk_kick").attr("transform","scale(0)");n.selectAll(".sja_aa_ssk_bg").attr("transform","scale(0)");n.selectAll(".sja_aa_ssk_text").attr("transform","scale(0)");n.selectAll(".sja_aa_skkick").transition().duration(s).attr("transform","scale(1)");const r=n.filter((t=>t.hasstackbar));r.selectAll(".sja_aa_stackbar_g").transition().duration(s).attr("transform",(t=>"translate(0,"+(o?1:-1)*(e.stem1-t.y)+")"));r.selectAll(".sja_aa_stackbar_rect").transition().duration(s).attr("width",0)}function je(t,e,s){if(!t.eplst)return;for(const o of t.eplst){o.may_hl(e,s)}}function Me(t,e,s){if(!t.config){s.error("config missing for expression data in "+e.ds.label);return}if(t.config.maf){try{t.config.maf.get=new Function(...t.config.maf.get)}catch(t){s.error("invalid javascript for config.maf.get of "+e.ds.label);return}}const o=t.config;if(o.usecohort){o.cohort=e.ds.cohort}const a={data:t.lst,expp:o,block:s,genome:s.genome,genename:s.usegm.name,dsname:e.ds.label};if(s.samplecart){if(e.ds.sampleselectable){a.samplecart=s.samplecart}}return import("./ep-a5c1ee3a.js").then((t=>{e.eplst.push(new t.default(a))}))}function Ae(t,e,s){for(const f of t){switch(f.dt){case c:if(s.usegm){const t=_(f.pos,s.usegm);f.rnapos=t.rnapos;f.aapos=t.aapos}e.mlst.push(f);break;case l:case i:if(!f.pairlst){console.error("pairlst missing from sv/fusion");break}if(s.usegm&&f.dt==l){if(f.pairlst.length==1){const t=f.pairlst[0].a;const e=f.pairlst[0].b;if(t.chr!=null&&e.chr!=null&&t.chr==e.chr&&t.position!=null&&e.position!=null){if(t.position<e.position){if(s.usegm.strand=="+"){t.strand="+";e.strand="+"}else{t.strand="-";e.strand="-";f.pairlst[0].a=e;f.pairlst[0].b=t}}}}}if(s.usegm&&s.gmmode!=F.genomic){f.isoform=s.usegm.isoform;let t=true;for(let e=0;e<f.pairlst.length;e++){const o=f.pairlst[e];if(s.usegm.isoform==(o.a.isoform||o.a.name)){f.useNterm=e==0;f.chr=s.usegm.chr;f.strand=o.a.strand;if(o.a.position==undefined){if(o.a.rnaposition==undefined){if(o.a.codon==undefined){console.error("no position/rnaposition/codon available for "+s.usegm.isoform);break}else{f.pos=U(o.a.codon,s.usegm);o.a.position=f.pos}}else{f.pos=E(o.a.rnaposition-1,s.usegm);if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+o.a.rnaposition);break}o.a.position=f.pos}}else{f.pos=o.a.position}const a=_(f.pos,s.usegm);f.rnapos=a.rnapos;f.aapos=a.aapos;if(o.a.codon){f.aapos=o.a.codon}f.mname=o.b.name;t=false;break}if(s.usegm.isoform==(o.b.isoform||o.b.name)){f.useNterm=false;f.chr=s.usegm.chr;f.strand=o.b.strand;if(o.b.position==undefined){if(o.b.rnaposition==undefined){if(o.b.codon==undefined){console.error("no position/rnaposition/codon available for "+s.usegm.isoform);break}else{f.pos=U(o.b.codon,s.usegm);o.b.position=f.pos}}else{f.pos=E(o.b.rnaposition-1,s.usegm);if(f.pos==null){console.error("failed to convert rnaposition to genomic");break}o.b.position=f.pos}}else{f.pos=o.b.position}const e=_(f.pos,s.usegm);f.rnapos=e.rnapos;f.aapos=e.aapos;if(o.b.codon){f.aapos=o.b.codon}f.mname=o.a.name;t=false;break}}if(t){console.error("sv/fusion isoform no match to gm isoform: "+s.usegm.isoform)}else{e.mlst.push(f)}}else{for(const t of f.pairlst){let o=false,a=false;for(let e=s.startidx;e<=s.stopidx;e++){const n=s.rglst[e];if(t.a.chr==n.chr&&t.a.position>=n.start&&t.a.position<=n.stop){o=true}if(t.b.chr==n.chr&&t.b.position>=n.start&&t.b.position<=n.stop){a=true}}if(o){const s=G(f);const o=t.a;s.chr=o.chr;s.strand=o.strand;s.useNterm=o.strand=="+";s.pos=o.pos||o.position;s.mname=t.b.name||t.b.chr;if(!Number.isFinite(s.pos)){console.error("no genomic pos for breakend a")}else if(!s.chr){console.error("no chromosome for breakend a")}else{e.mlst.push(s)}}if(a){const s=G(f);const o=t.b;s.chr=o.chr;s.strand=o.strand;s.useNterm=o.strand=="+";s.pos=o.pos||o.position;s.mname=t.a.name||t.a.chr;if(!Number.isFinite(s.pos)){console.error("no genomic pos for breakend b")}else if(!s.chr){console.error("no chromosome for breakend b")}else{e.mlst.push(s)}}}}break;case r:case o:if(f.chrpos1&&f.chrpos2){let t=_(f.chrpos1,s.usegm);const e=t.rnapos;t=_(f.chrpos2,s.usegm);const a=t.rnapos;if(e<a){f.pos=f.chrpos1}else{f.pos=f.chrpos2}delete f.chrpos1;delete f.chrpos2;const n=Math.abs(e-a);if(f.dt==r){f.rnaduplength=n}else if(f.dt==o){f.rnadellength=n}}if(f.position){f.pos=f.position;delete f.position}if(!f.pos){if(f.dt==r){if(f.b){if(f.b.position){f.pos=f.b.position;f.chr=f.b.chr}}}}if(!f.pos){if(f.rnaposition){if(s.usegm){f.pos=E(f.rnaposition-1,s.usegm);f.chr=s.usegm.chr;if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+f.rnaposition);break}}}else if(f.aapos);}if(!f.pos){console.error("no genomic pos for itd");break}if(s.usegm){const t=_(f.pos,s.usegm);if(f.rnaposition){f.rnapos=f.rnaposition}else{f.rnapos=t.rnapos}f.aapos=t.aapos}if(f.dt==r){if(!f.rnaduplength){console.error("itd has no rnaduplength");f.rnaduplength=1}}else{if(!f.rnadellength){console.error("deletion has no rnadellength");f.rnadellength=1}}e.mlst.push(f);break;case n:case a:if(f.position){f.pos=f.position;delete f.position}if(!f.pos){if(f.rnaposition){if(s.usegm){f.pos=E(f.rnaposition-1,s.usegm);f.chr=s.usegm.chr;if(f.pos==null){console.error("failed to convert rnaposition to genomic position: "+f.rnaposition);break}}}else if(f.aapos);}if(!f.pos){console.error("no genomic pos for truncation");break}if(s.usegm){const t=_(f.pos,s.usegm);if(f.rnaposition){f.rnapos=f.rnaposition}else{f.rnapos=t.rnapos}f.aapos=t.aapos}e.mlst.push(f);break;default:console.error("unknown dt: "+f.dt)}}}function ze(t,e){const s=new Map;for(const t in f){s.set(f[t].label.toUpperCase(),t)}const o=[];for(const[a,n]of t.hlaachange){if(n==false){continue}if(!n.name){e.error("hlaachange item .name missing");continue}if(n.codon==undefined||!Number.isFinite(n.codon)){e.error("hlaachange invalid codon for "+n.name);continue}if(!n.class){e.error("hlaachange .class missing");continue}const t=f[n.class]?n.class:s.get(n.class.toUpperCase());if(!t){e.error("hlaachange invalid class: "+n.class);continue}n.class=t;n.mname=n.name;delete n.name;n.chr=e.usegm.chr;n.pos=U(n.codon,e.usegm);delete n.codon;n.dt=c;n.isoform=e.usegm.isoform;o.push(n)}if(o.length){const t={label:"Highlight",type:D.ds,iscustom:true,bulkdata:{}};t.bulkdata[e.usegm.name.toUpperCase()]=o;e.ownds[t.label]=t;const s=e.block_addtk_template({type:D.ds,ds:t});ne(s,e)}}function Ne(t,e){if(!t.vcfinfofilter)return;for(const s of t.vcfinfofilter.lst){s.holder.selectAll("*").remove();if(s.numericfilter){for(const t of s.numericfilter){t.count=0}for(const e of t.mlst){const[t,o]=Se(s,e);if(t){continue}if(!o)continue;const a=o[0];if(!Number.isFinite(a))continue;for(const t of s.numericfilter){if(t.side=="<"){if(a<t.value){t.count++}}else{if(a>t.value){t.count++}}}}for(const o of s.numericfilter){const a=s.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{if(s.numericCutoff==o.value&&s.numericCutoffSide==o.side){delete s.numericCutoff}else{s.numericCutoff=o.value;s.numericCutoffSide=o.side}fe(t,e)}));if(s.numericCutoff==o.value&&s.numericCutoffSide==o.side){a.style("border-bottom","solid 2px #ccc").style("background-color","#f1f1f1")}if(o.count>0){a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color","#ccc").style("color","white").html(o.count>1?o.count:"&nbsp;").style("margin-right","5px")}a.append("span").text(o.side+o.value)}continue}if(!s.categories){continue}const o=new Map;let a=0;for(const e of t.mlst){const[t,n]=Se(s,e);if(t){continue}if(n==undefined){a++}else{for(const t of n){if(!o.has(t)){o.set(t,0)}o.set(t,o.get(t)+1)}}}const n=[...o];if(a){n.push([$t,a])}n.sort(((t,e)=>e[1]-t[1]));for(const[o,a]of n){const n=s.categories[o]||{color:"black",label:o};const r=s.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{t.vcfinfofilter.tip.showunder(r.node());Ce(s,o,t,e)}));r.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color",n.color).style("color","white").html(a>1?a:"&nbsp;").style("margin-right","5px");const i=r.append("span").text(n.label).style("color",n.color);if(s.categoryhidden[o]){i.style("text-decoration","line-through")}}}}function Pe(t,e){if(!t.vcfinfofilter)return;for(const e of t.vcfinfofilter.lst){if(e.numericfilter){continue}if(!e.autocategory){continue}const s=new Map;for(const o of t.mlst){const[t,a]=Se(e,o);if(t){continue}if(a!=undefined){for(const t of a){if(!s.has(t)){s.set(t,0)}s.set(t,s.get(t)+1)}}}const o=[...s];o.sort(((t,e)=>e[1]-t[1]));const a=M(Z);e.categories={};for(const[t,s]of o){e.categories[t]={label:t,color:a(t)}}}}function Se(t,e){if(t.altalleleinfo){if(!e.altinfo)return["no .altinfo"];const s=e.altinfo[t.altalleleinfo.key];if(s==undefined){if(t.numericfilter){return[null,[0]]}return[null,undefined]}let o=Array.isArray(s)?s:[s];if(t.altalleleinfo.separator){o=o[0].split(t.altalleleinfo.separator)}return[null,o]}if(t.locusinfo){if(!e.info)return["no .info"];const s=e.info[t.locusinfo.key];if(s==undefined){if(t.numericfilter){return[null,[0]]}return[null,undefined]}let o=Array.isArray(s)?s:[s];if(t.locusinfo.separator){o=o[0].split(t.locusinfo.separator)}return[null,o]}return["no trigger"]}function Ce(t,e,s,o){const a=s.vcfinfofilter.tip;a.clear();const n=t.categoryhidden[e];a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{a.hide();t.categoryhidden={};for(const s in t.categories){if(s!=e){t.categoryhidden[s]=1}}if(e!=$t){t.categoryhidden[$t]=1}fe(s,o)}));if(n){a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{a.hide();delete t.categoryhidden[e];fe(s,o)}))}else{a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{a.hide();t.categoryhidden[e]=1;fe(s,o)}))}let r=0;for(const e in t.categoryhidden){r++}if(r>1){a.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{a.hide();t.categoryhidden={};fe(s,o)}))}}function Fe(t,e){if(!t.vcfid)return[".vcfid missing"];if(!t.sampledata)return[".sampledata missing"];const s=e.ds.id2vcf[t.vcfid];if(!s)return["no vcf"];if(!s.samples||s.samples.length==0)return["vcf no samples"];let o=0;for(const e of t.sampledata){if(!e.gtallref)o++}return[null,o/s.samples.length]}function Re(t,e){if(!t.populationfrequencyfilter)return;for(const e of t.populationfrequencyfilter.lst){e.count=0}for(const e of t.mlst){const[s,o]=Fe(e,t);if(s){continue}for(const e of t.populationfrequencyfilter.lst){if(o<e.value){e.count++}}}t.populationfrequencyfilter.holder.selectAll("*").remove();for(const s of t.populationfrequencyfilter.lst){const o=t.populationfrequencyfilter.holder.append("div").style("display","inline-block").style("padding","10px").attr("class","sja_clb").on("click",(()=>{if(t.populationfrequencyfilter.cutoff==s.value){delete t.populationfrequencyfilter.cutoff}else{t.populationfrequencyfilter.cutoff=s.value}fe(t,e)}));if(t.populationfrequencyfilter.cutoff==s.value){o.style("border-bottom","solid 2px #ccc").style("background-color","#f1f1f1")}o.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 5px").style("background-color","#ccc").style("color","white").html(s.count>1?s.count:"&nbsp;").style("margin-right","5px");o.append("span").text("< "+s.value)}}function Ie(t,e){if(!t.ds||!t.ds.cohort||!t.ds.cohort.sampleattribute)return;if(!t.ds.cohort.annotation)return".ds.cohort.annotation missing";if(!t.ds.cohort.key4annotation)return".ds.cohort.key4annotation missing";const s=t.ds.cohort.sampleattribute;if(!s.lst)return".lst missing";if(!s.holder)return".holder missing";s.holder.selectAll("*").remove();if(t.mlst.length==0){return}for(const t of s.lst){if(!t.k)return".k missing for an attribute";if(!t.hiddenvalues)t.hiddenvalues=new Set}const o=[];if(t.mlst[0].sampledata){for(const e of s.lst){let s=0;const a=new Map;for(const o of t.mlst){if(!o.sampledata)continue;for(const n of o.sampledata){const o=n.sampleobj[t.ds.cohort.key4annotation];if(!o)continue;const r=t.ds.cohort.annotation[o];if(!r)continue;const i=r[e.k];if(i==undefined)continue;s++;if(!a.has(i)){a.set(i,0)}a.set(i,a.get(i)+1)}}if(s==0){continue}o.push({samplecount:s,key:e,lst:[...a].sort(((t,e)=>e[1]-t[1])).map((t=>({value:t[0],count:t[1]})))})}}else{for(const e of s.lst){let s=0;const a=new Map;for(const o of t.mlst){const n=o[t.ds.cohort.key4annotation];if(!n)continue;const r=t.ds.cohort.annotation[n];if(!r)continue;const i=r[e.k];if(i==undefined)continue;s++;if(!a.has(i)){a.set(i,0)}a.set(i,a.get(i)+1)}if(s==0){continue}o.push({samplecount:s,key:e,lst:[...a].sort(((t,e)=>e[1]-t[1])).map((t=>({value:t[0],count:t[1]})))})}}if(o.length==0){delete s.runtimelst;return}s.runtimelst=o;const a=s.holder.append("table").style("border-spacing","5px");for(const n of o){const o=a.append("tr");o.append("td").style("color","#858585").style("text-align","right").text(n.key.label||n.key.k);const r=o.append("td");for(const o of n.lst){const a=r.append("div").style("display","inline-block").style("padding","5px").attr("class","sja_clb").on("click",(()=>{s.tip.showunder(a.node());Be(o,n,s.tip,t,e)}));a.append("div").style("display","inline-block").attr("class","sja_mcdot").style("padding","1px 3px").style("background-color","#858585").style("color","white").html(o.count>1?o.count:"&nbsp;").style("margin-right","5px");const i=a.append("span").text(o.value);if(n.key.hiddenvalues.has(o.value)){i.style("text-decoration","line-through")}}}return null}function Be(t,e,s,o,a){s.clear();s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{s.hide();for(const t of e.lst){e.key.hiddenvalues.add(t.value)}e.key.hiddenvalues.delete(t.value);fe(o,a)}));if(e.key.hiddenvalues.has(t.value)){s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{s.hide();e.key.hiddenvalues.delete(t.value);fe(o,a)}))}else{s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{s.hide();e.key.hiddenvalues.add(t.value);fe(o,a)}))}if(e.key.hiddenvalues.size>1){s.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{s.hide();e.key.hiddenvalues.clear();fe(o,a)}))}}function qe(t,e,s){let o=0;let a=0;let n=[];let r=[];for(const i of t.mlst){delete i.__x;if(e.legend&&e.legend.mclasses.has(i.class)&&e.legend.mclasses.get(i.class).hidden){continue}if(e.legend&&e.legend.morigins.has(i.origin)&&e.legend.morigins.get(i.origin).hidden){continue}if(i.origin&&s.has(i.origin)){continue}if(e.gmmode==V.protein&&e.usegm.codingstart&&e.usegm.codingstop){if(i.pos<e.usegm.codingstart||i.pos>e.usegm.codingstop)continue}if(t.vcfinfofilter){let e=false;for(const s of t.vcfinfofilter.lst){const[t,o]=Se(s,i);if(t){continue}const a=o==undefined?[$t]:o;if(s.numericCutoff!=undefined){const t=Number.parseFloat(a[0]);if(Number.isNaN(t)){e=true;break}if(s.numericCutoffSide=="<"){if(t>=s.numericCutoff){e=true;break}}else if(s.numericCutoffSide==">"){if(t<=s.numericCutoff){e=true;break}}}else if(s.categoryhidden){let t=false;for(const e of a){if(!s.categoryhidden[e]){t=true;break}}if(!t){e=true;break}}}if(e){continue}}if(t.populationfrequencyfilter&&t.populationfrequencyfilter.cutoff){const[e,s]=Fe(i,t);if(e);else{if(s>t.populationfrequencyfilter.cutoff){continue}}}if(t.ds&&t.ds.cohort&&t.ds.cohort.annotation&&t.ds.cohort.key4annotation&&t.ds.cohort.sampleattribute&&t.ds.cohort.sampleattribute.runtimelst){let e=0;for(const s of t.ds.cohort.sampleattribute.runtimelst){if(s.key&&s.key.hiddenvalues){e+=s.key.hiddenvalues.size}}if(e>0){if(t.ds.vcfcohorttrack);else if(i.sampledata){let e=0;for(const s of i.sampledata){if(!O(s.genotype,i.alt)){continue}const o=s.sampleobj[t.ds.cohort.key4annotation];if(o){const e=t.ds.cohort.annotation[o];if(e){let s=false;for(const o of t.ds.cohort.sampleattribute.runtimelst){const t=e[o.key.k];if(t!=undefined){if(o.key.hiddenvalues.has(t)){s=true;break}}}if(s){continue}}}e++}if(e==0){continue}}else{const e=i[t.ds.cohort.key4annotation];if(e){const s=t.ds.cohort.annotation[e];if(s){let e=false;for(const o of t.ds.cohort.sampleattribute.runtimelst){const t=s[o.key.k];if(t!=undefined){if(o.key.hiddenvalues.has(t)){e=true;break}}}if(e){continue}}}}}}if(!i.chr){a++;continue}if(!Number.isInteger(i.pos)){o++;continue}const l=e.seekcoord(i.chr,i.pos);if(l.length==0){n.push(i);continue}if(l.length==1){i.__x=l[0].x}else{i.__x=l[0].x}if(i.__x<-1||i.__x>e.width+1){continue}r.push(i)}const i=[];t.tklabel.each((function(){i.push(this.getBBox().width)}));if(r.length==0){t.label_mcount.text("")}else{t.label_mcount.text(r.length<t.mlst.length?r.length+" of "+t.mlst.length+" "+t.itemlabelname+"s":r.length+" "+t.itemlabelname+(r.length>1?"s":"")).each((function(){i.push(this.getBBox().width)}))}if(t.label_stratify){for(const e of t.label_stratify){let s;if(e.bycohort){const e=new Set;for(const s of r){let o="";for(const e of t.ds.cohort.levels){const t=s[e.k];if(t){o+=t}}e.add(o)}s=e.size}else{const t=new Set;for(const s of r){let o=s[e.attr1.k];if(!o)continue;if(e.attr2){const t=s[e.attr2.k];if(t){o+=t}}if(e.attr3){const t=s[e.attr3.k];if(t){o+=t}}t.add(o)}s=t.size}if(s==0){e.svglabel.text("")}else{e.svglabel.text(s+" "+e.label+(s>1?"s":"")).each((function(){i.push(this.getBBox().width)}))}}}t.leftLabelMaxwidth=Math.max(...i);if(o+a>0){e.tkerror(t,o+a+" items have no chromosome or genomic position")}if(n.length){console.error(n.length+" items not mapped to any region");for(const t of n)console.log(t)}return r}function De(t,e){for(const s of t.data){if(s.isbin){let t=0;for(const o of s.mlst){const s=e.seekcoord(o.chr,o.pos);if(o.usehitidx!=undefined&&s[o.usehitidx]){t+=s[o.usehitidx].x}else if(s.length==1){t+=s[0].x}else{console.log("cannot map item");console.log(o)}}s.x0=t/s.mlst.length;s.x=s.x0+(s.xoffset!=undefined?s.xoffset:0)}else{const t=e.seekcoord(s.chr,s.pos);if(t.length>0){s.x0=t[0].x;s.x=s.x0+(s.xoffset!=undefined?s.xoffset:0)}else{console.log("cannot map group of item");console.log(s)}}}}function Le(t,e){t.height_main=t.toppad+e.labelfontsize+t.bottompad;if(t.label_mcount&&t.label_mcount.text().length>0){t.height_main+=t.labyspace+e.labelfontsize}if(t.label_stratify){for(const s of t.label_stratify){if(s.svglabel.text().length>0){t.height_main+=t.labyspace+e.labelfontsize}}}t.glider.selectAll("*").remove();t.leftaxis.selectAll("*").remove();if(t.viewrangeupperlimit_above){e.tkerror(t,t.name+": zoom in under "+T(t.viewrangeupperlimit)+" to view data")}else{let s;if(!t.skewer.data||t.skewer.data.length==0){if(e.pannedpx!=undefined||e.zoomedin==true){s="view range"}else if(e.usegm&&e.gmmode!="genomic"){s=e.usegm.name||e.usegm.isoform}}e.tkerror(t,t.name+": no mutation in "+s)}if(t.hlaachange){ze(t,e);delete t.hlaachange}}function Ee(t,e){if(!t.stratifycount)return;for(const[s,o]of t.stratifycount){const t=e.label_stratify.find((t=>t.label==s));if(!t){console.error("unknown strat label: "+s);continue}t.servercount=o}}const Ue=new H({padding:"0px"});function Ge(t,e){const s=t.legend.holder.append("tr");const o=s.append("td").text(e).style("padding-right","10px").style("text-align","right").style("color","#555").style("border-right","solid 1px "+t.legend.legendcolor);const a=s.append("td");return[s,a,o]}function Ve(t){if(!t.legend){return}const e=new Set;for(const[s,o]of t.legend.mclasses){if(o.hidden){e.add(s)}}const s=new Map;for(const e of t.tklst){if(e.hidden||e.type!=D.ds)continue;if(!e.mlst){continue}for(const t of e.mlst){if(t.class){if(!s.has(t.class)){s.set(t.class,{count:0})}s.get(t.class).count++}}}const o=[];for(const[t,a]of s){if(e.has(t)){s.get(t).hidden=true}o.push({key:t,count:a.count})}t.legend.mclasses=s;if(s.size==0){t.legend.tr_mclass.style("display","none");return}t.legend.tr_mclass.style("display","table-row");o.sort(((t,e)=>e.count-t.count));t.legend.td_mclass.selectAll("*").remove();for(const s of o){const o=t.legend.td_mclass.append("div").style("display","inline-block").style("white-space","nowrap").style("padding",t.legend.vpad+" 20px "+t.legend.vpad+" 0px").classed("sja_clb",true).on("click",(()=>{Ue.clear();Ue.showunder(o.node());Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.mclasses.values()){e.hidden=true}t.legend.mclasses.get(s.key).hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}));if(t.legend.mclasses.get(s.key).hidden){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.mclasses.get(s.key).hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}else{Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.mclasses.get(s.key).hidden=true;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}if(e.size>1){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.mclasses.values()){e.hidden=false}for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}const a=Ue.d.append("div").style("margin","20px");a.append("div").text(f[s.key].label.toUpperCase()).style("color",f[s.key].color).style("font-size",".8em");a.append("div").html(f[s.key].desc).style("color","#858585").style("font-size",".8em").style("width","210px")}));o.append("div").style("display","inline-block").style("background-color",f[s.key].color).style("margin-right","5px").style("border-radius","15px").style("padding","4px 8px").style("color","white").style("font-size",".8em").text(s.count);const a=o.append("div").style("display","inline-block").style("color",f[s.key].color).text(f[s.key].label);if(e.has(s.key)){a.style("text-decoration","line-through")}}}function Oe(t){if(!t.legend){return}const e=new Set;for(const[s,o]of t.legend.morigins){if(o.hidden){e.add(s)}}const s=new Map;for(const o of t.tklst){if(o.hidden||o.type!=D.ds)continue;if(!o.mlst){continue}for(const t of o.mlst){if(!t.origin)continue;if(!s.has(t.origin)){let o=false;if(L[t.origin]&&L[t.origin].hidden){o=true;e.add(t.origin)}s.set(t.origin,{count:0,hidden:o})}s.get(t.origin).count++}}const o=[];for(const[t,a]of s){if(e.has(t)){s.get(t).hidden=true}o.push({key:t,count:a.count})}t.legend.morigins=s;if(s.size==0){t.legend.tr_morigin.style("display","none");return}t.legend.tr_morigin.style("display","table-row");o.sort(((t,e)=>e.count-t.count));t.legend.td_morigin.selectAll("*").remove();for(const s of o){const o=t.legend.td_morigin.append("div").style("display","inline-block").style("white-space","nowrap").style("padding",t.legend.vpad+" 20px "+t.legend.vpad+" 0px").classed("sja_clb",true).on("click",(()=>{Ue.clear();Ue.showunder(o.node());Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show alone').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.morigins.values()){e.hidden=true}t.legend.morigins.get(s.key).hidden=false;L[s.key].hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}));if(t.legend.morigins.get(s.key).hidden){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.morigins.get(s.key).hidden=false;L[s.key].hidden=false;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}else{Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&times;</div> hide').on("click",(()=>{Ue.hide();t.pannedpx=undefined;t.legend.morigins.get(s.key).hidden=true;for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}if(e.size>1){Ue.d.append("div").attr("class","sja_menuoption").html('<div style="display:inline-block;width:25px">&#10003;</div> show all').on("click",(()=>{Ue.hide();t.pannedpx=undefined;for(const e of t.legend.morigins.values()){e.hidden=false}for(const e of t.tklst){if(!e.hidden&&e.type==D.ds){fe(e,t)}}}))}const a=Ue.d.append("div").style("margin","20px");a.append("div").text(L[s.key].label.toUpperCase()).style("color",L[s.key].color).style("font-size",".8em");a.append("div").html(L[s.key].desc).style("color","#858585").style("font-size",".8em").style("width","210px")}));o.append("svg").style("margin-right","5px").attr("width",19).attr("height",19).html(L[s.key].legend);const a=o.append("div").style("display","inline-block").style("color","#858585").text(L[s.key].label+", "+s.count);if(e.has(s.key)){a.style("text-decoration","line-through")}}}export{fe as a,ht as b,bt as c,ne as d,yt as e,_e as f,mt as g,he as h,$ as i,Ve as j,Oe as k,Ge as l,Ut as m,gt as r,ye as s};