@sjcrh/proteinpaint-client 2.63.0 → 2.63.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/{2dmaf-70c0b6bb.js → 2dmaf-0cabb4a4.js} +1 -1
- package/dist/{ColorScale-b44d51ef.js → ColorScale-9800a609.js} +1 -1
- package/dist/{DEanalysis-b86d0874.js → DEanalysis-567989ff.js} +1 -1
- package/dist/{Disco-16cd51c0.js → Disco-5d1404ce.js} +1 -1
- package/dist/{Disco.UI-a38a12e6.js → Disco.UI-54228bb6.js} +1 -1
- package/dist/{DragControls-0c173a20.js → DragControls-a05737c2.js} +1 -1
- package/dist/{DziViewer-5c2d68e7.js → DziViewer-3f466d90.js} +2 -2
- package/dist/{FilterRxComp-0e75dd8d.js → FilterRxComp-fc769f34.js} +1 -1
- package/dist/{FilterStateless-ad3df967.js → FilterStateless-8f30f856.js} +1 -1
- package/dist/{HicApp-bcf8330c.js → HicApp-aac413df.js} +1 -1
- package/dist/{OrbitControls-c33cf781.js → OrbitControls-8b7f91ca.js} +1 -1
- package/dist/app-59194db0.js +1 -0
- package/dist/{app-f91922b4.js → app-71453429.js} +1 -1
- package/dist/{app-bfce9bf5.js → app-fb676934.js} +1 -1
- package/dist/app.js +1 -1
- package/dist/{bam-95f36008.js → bam-e7f6baea.js} +1 -1
- package/dist/{barchart-e2af00a8.js → barchart-ef4874c8.js} +1 -1
- package/dist/{barchart.events-272fd122.js → barchart.events-e24facf7.js} +1 -1
- package/dist/{bars.renderer-f0e5af5a.js → bars.renderer-c46d3f44.js} +1 -1
- package/dist/{block-ec76524e.js → block-4f585abe.js} +1 -1
- package/dist/block.lazyload-6f83d057.js +1 -0
- package/dist/{block.legend-f8cad7e4.js → block.legend-cec87c6f.js} +1 -1
- package/dist/{block.mds-20655637.js → block.mds-f5a11c42.js} +1 -1
- package/dist/{block.mds.cnv-5feb86a0.js → block.mds.cnv-25423c1e.js} +1 -1
- package/dist/{block.mds.expressionrank-c7043f35.js → block.mds.expressionrank-fc1996d5.js} +1 -1
- package/dist/{block.mds.expressionstat-4bf457f3.js → block.mds.expressionstat-45b6bf47.js} +1 -1
- package/dist/{block.mds.geneboxplot-132e5fe6.js → block.mds.geneboxplot-037df46d.js} +1 -1
- package/dist/{block.mds.junction-1f9810df.js → block.mds.junction-00161de6.js} +1 -1
- package/dist/{block.mds.svcnv-094c416f.js → block.mds.svcnv-0c257af4.js} +1 -1
- package/dist/{block.mds.svcnv.share-bb976e02.js → block.mds.svcnv.share-c0b9dfad.js} +1 -1
- package/dist/{block.mds2-7045e32c.js → block.mds2-9009f8d8.js} +1 -1
- package/dist/{block.svg-d8d76ba7.js → block.svg-86bbfcb0.js} +1 -1
- package/dist/{block.tk.aicheck-317d04bd.js → block.tk.aicheck-a5697794.js} +1 -1
- package/dist/{block.tk.ase-d1577ec1.js → block.tk.ase-ad1be47c.js} +1 -1
- package/dist/{block.tk.bam-3cdc13a0.js → block.tk.bam-14339d16.js} +1 -1
- package/dist/{block.tk.bedgraphdot-5304e06c.js → block.tk.bedgraphdot-efe19e56.js} +1 -1
- package/dist/{block.tk.bigwig.ui-0c96dce5.js → block.tk.bigwig.ui-a92f286b.js} +1 -1
- package/dist/{block.tk.hicstraw-39d89269.js → block.tk.hicstraw-57fbbe61.js} +1 -1
- package/dist/{block.tk.junction-b45b3a95.js → block.tk.junction-64c39cd5.js} +1 -1
- package/dist/{block.tk.junction.textmatrixui-6ec019e1.js → block.tk.junction.textmatrixui-09e5e02f.js} +1 -1
- package/dist/{block.tk.ld-5c54e58b.js → block.tk.ld-f681d099.js} +1 -1
- package/dist/{block.tk.menu-30a2c3a5.js → block.tk.menu-2563364c.js} +1 -1
- package/dist/{block.tk.pgv-7ff2dfaf.js → block.tk.pgv-9dfc00c0.js} +1 -1
- package/dist/{boxplot-7de25274.js → boxplot-a2e1ace0.js} +1 -1
- package/dist/brainImaging-21701238.js +1 -0
- package/dist/{brush-db0ed33a.js → brush-bb4566a3.js} +1 -1
- package/dist/{categorical-bc309399.js → categorical-a00f4ffc.js} +1 -1
- package/dist/{condition-f0eb2343.js → condition-2034db37.js} +1 -1
- package/dist/{controls-8d4972c8.js → controls-0467d2ec.js} +1 -1
- package/dist/{controls.btns-bad9e4cf.js → controls.btns-ad7b28a2.js} +1 -1
- package/dist/{controls.config-e0f394cb.js → controls.config-6cf816fb.js} +1 -1
- package/dist/{controls.divide-d8ac5a9b.js → controls.divide-3c0d52d7.js} +1 -1
- package/dist/{controls.overlay-3ac8773d.js → controls.overlay-3a55c2ec.js} +1 -1
- package/dist/{controls.term1-008f4be4.js → controls.term1-59f4cd60.js} +1 -1
- package/dist/cuminc-8d21132b.js +1 -0
- package/dist/{customdata.inputui-58cd9b32.js → customdata.inputui-40ba6d7f.js} +1 -1
- package/dist/{dataDownload-91da6dd6.js → dataDownload-bfa92dad.js} +1 -1
- package/dist/{databrowser.ui-c50862e4.js → databrowser.ui-4799f04d.js} +1 -1
- package/dist/{density-7c3f91eb.js → density-4c2b53f6.js} +1 -1
- package/dist/{dictionary-48a38837.js → dictionary-89e860ee.js} +1 -1
- package/dist/{drag-c354e2c6.js → drag-88d451b4.js} +1 -1
- package/dist/{e2pca-3bba91fa.js → e2pca-8a3f2566.js} +1 -1
- package/dist/{ep-144d8973.js → ep-5399c5cc.js} +1 -1
- package/dist/{fusion.parse-ae1253f4.js → fusion.parse-fc25e5bd.js} +1 -1
- package/dist/{geneExpClustering-96d09008.js → geneExpClustering-a916ebda.js} +1 -1
- package/dist/{geneExpression-d6494fd3.js → geneExpression-501e95c0.js} +1 -1
- package/dist/{geneExpression-9ca2da4f.js → geneExpression-9047481a.js} +1 -1
- package/dist/{geneExpression-be9b5da2.js → geneExpression-da4b50f0.js} +1 -1
- package/dist/{geneORA-85850143.js → geneORA-ffb2497e.js} +1 -1
- package/dist/{geneVariant-3df05e0c.js → geneVariant-7ab521d6.js} +1 -1
- package/dist/{geneVariant-3d674865.js → geneVariant-d79431a2.js} +1 -1
- package/dist/{genefusion.ui-3e2a3a73.js → genefusion.ui-3ce190c7.js} +1 -1
- package/dist/{geneset-3b761b2c.js → geneset-3522bcda.js} +1 -1
- package/dist/{genomeBrowser-2105a98f.js → genomeBrowser-9b72eb22.js} +1 -1
- package/dist/{genomeBrowser.controls-f9b9bf42.js → genomeBrowser.controls-bef8bf99.js} +1 -1
- package/dist/{groupsetting-4901d033.js → groupsetting-574ad150.js} +1 -1
- package/dist/{hierCluster-a7ff7f5a.js → hierCluster-3b14b2b3.js} +1 -1
- package/dist/{hierCluster.config-3d124abf.js → hierCluster.config-f8686a30.js} +1 -1
- package/dist/{hierCluster.interactivity-3463cc0b.js → hierCluster.interactivity-3b5f1e81.js} +1 -1
- package/dist/{hierCluster.renderers-668d0075.js → hierCluster.renderers-9f9a7cad.js} +1 -1
- package/dist/{html.legend-3e428f9e.js → html.legend-ef8066dd.js} +1 -1
- package/dist/{imagePlot-6d89200c.js → imagePlot-095b9a92.js} +1 -1
- package/dist/{lasso-393c1570.js → lasso-ef63631b.js} +1 -1
- package/dist/{launch.adhoc-9c59874e.js → launch.adhoc-1b356f97.js} +1 -1
- package/dist/{legacyDataset-26ead9cc.js → legacyDataset-056e9d4c.js} +1 -1
- package/dist/{log-4d74231e.js → log-ca1e2a74.js} +1 -1
- package/dist/{lollipop-59f65024.js → lollipop-6ad9ec3c.js} +1 -1
- package/dist/{maf-72e5b7da.js → maf-dfada1c8.js} +1 -1
- package/dist/{maftimeline-ed8aaae8.js → maftimeline-1b715a01.js} +1 -1
- package/dist/{matrix-3d09a31f.js → matrix-3fae58f8.js} +1 -1
- package/dist/matrix.cells-3620eb3a.js +1 -0
- package/dist/{matrix.cluster-acdfc6a7.js → matrix.cluster-15b8a865.js} +1 -1
- package/dist/{matrix.config-cd01ebbd.js → matrix.config-8247bea5.js} +1 -1
- package/dist/{matrix.controls-86eb8d5c.js → matrix.controls-dea65894.js} +1 -1
- package/dist/{matrix.data-e2d7ac16.js → matrix.data-121a1a8c.js} +1 -1
- package/dist/{matrix.dom-e5f91cc0.js → matrix.dom-83c5fa39.js} +1 -1
- package/dist/{matrix.groups-f1969b5c.js → matrix.groups-2e1202ef.js} +1 -1
- package/dist/{matrix.interactivity-92bc8332.js → matrix.interactivity-2b076155.js} +1 -1
- package/dist/{matrix.layout-29a8f334.js → matrix.layout-8dc54c05.js} +1 -1
- package/dist/{matrix.legend-8c28039e.js → matrix.legend-e0078739.js} +1 -1
- package/dist/matrix.renderers-0c8eddc9.js +1 -0
- package/dist/{matrix.serieses-e079f04a.js → matrix.serieses-2898da6b.js} +1 -1
- package/dist/{matrix.sort-e1f83454.js → matrix.sort-249d4a35.js} +1 -1
- package/dist/{matrix.sorterUi-2025f39d.js → matrix.sorterUi-d26208c8.js} +1 -1
- package/dist/{mavb-37fffd68.js → mavb-9a6fa2e9.js} +1 -1
- package/dist/{mds.fimo-68f0eaf5.js → mds.fimo-ce97371c.js} +1 -1
- package/dist/{mds.samplescatterplot-362f3591.js → mds.samplescatterplot-a54b9e93.js} +1 -1
- package/dist/{mds.survivalplot-f5bda05a.js → mds.survivalplot-c5093f73.js} +1 -1
- package/dist/{mdsjsonform-7f0b6cc7.js → mdsjsonform-09b4e1cb.js} +1 -1
- package/dist/metaboliteIntensity-eeb5ad12.js +1 -0
- package/dist/niceNumLabels-ddb76164.js +1 -0
- package/dist/{nodrag-777a34a5.js → nodrag-bed2488c.js} +1 -1
- package/dist/{numeric-2eb8c25b.js → numeric-d5536b1c.js} +1 -1
- package/dist/numeric.binary-d67da945.js +1 -0
- package/dist/numeric.continuous-9a0c88bc.js +1 -0
- package/dist/numeric.discrete-921f7097.js +1 -0
- package/dist/numeric.spline-649308d5.js +1 -0
- package/dist/{numeric.toggle-5316211b.js → numeric.toggle-52789fd2.js} +1 -1
- package/dist/{oncomatrix-cd9fa01b.js → oncomatrix-6950c48c.js} +1 -1
- package/dist/{parseData-1bfa9946.js → parseData-480d1ff3.js} +1 -1
- package/dist/{plot.2dvaf-1ed153c1.js → plot.2dvaf-1ecc4bbc.js} +1 -1
- package/dist/plot.app-c841507a.js +1 -0
- package/dist/{plot.barplot-61742e94.js → plot.barplot-24140b0f.js} +1 -1
- package/dist/{plot.boxplot-fe966ac3.js → plot.boxplot-87fe8ab2.js} +1 -1
- package/dist/{plot.brainImaging-d2c23bb7.js → plot.brainImaging-325ebded.js} +1 -1
- package/dist/{plot.disco-70d493f4.js → plot.disco-621d1b8e.js} +1 -1
- package/dist/{plot.dzi-14e6fdc4.js → plot.dzi-3a7e478e.js} +1 -1
- package/dist/{plot.ssgq-9d364d41.js → plot.ssgq-1949c207.js} +1 -1
- package/dist/{plot.vaf2cov-4d28015b.js → plot.vaf2cov-d03c6409.js} +1 -1
- package/dist/{profileBarchart-c104f8e2.js → profileBarchart-11755d7c.js} +1 -1
- package/dist/{profileHome-a555583d.js → profileHome-9c5e266b.js} +1 -1
- package/dist/{profilePlot-5ce5b6a0.js → profilePlot-8ee3034a.js} +1 -1
- package/dist/{profilePolar-610213d4.js → profilePolar-9fe70c32.js} +1 -1
- package/dist/{profileRadar-fddb18f7.js → profileRadar-0e744181.js} +1 -1
- package/dist/{profileRadarFacility-2c2db1dd.js → profileRadarFacility-102544c5.js} +1 -1
- package/dist/{recover-a08c8d01.js → recover-b1ec4fed.js} +1 -1
- package/dist/{regression.inputs-5718cf72.js → regression.inputs-ad548745.js} +1 -1
- package/dist/{regression.inputs.values.table-d587c1cf.js → regression.inputs.values.table-1618447a.js} +1 -1
- package/dist/{regression.results-748024be.js → regression.results-25008028.js} +1 -1
- package/dist/{renderPvalueTable-c435aefd.js → renderPvalueTable-46056189.js} +1 -1
- package/dist/sampleScatter-47dd82cb.js +1 -0
- package/dist/{sampleScatter.interactivity-e9c30652.js → sampleScatter.interactivity-cfa3451d.js} +1 -1
- package/dist/{sampleScatter.rendererThree-3e6c032e.js → sampleScatter.rendererThree-c5321d24.js} +2 -2
- package/dist/{sampleView-d6a91293.js → sampleView-30b97c7d.js} +1 -1
- package/dist/{samplelst-821ec148.js → samplelst-2bdc1b9d.js} +1 -1
- package/dist/{samplematrix-7aa0a780.js → samplematrix-4f0ec523.js} +1 -1
- package/dist/{scatter-2e2c76f4.js → scatter-8a337eeb.js} +1 -1
- package/dist/{selectGenomeWithTklst-51cd21a4.js → selectGenomeWithTklst-895106fb.js} +1 -1
- package/dist/{singleCellPlot-c7347a27.js → singleCellPlot-360eaec6.js} +1 -1
- package/dist/{singlecell-a668bb17.js → singlecell-29c1cbb1.js} +1 -1
- package/dist/{singlecell-7c851ef8.js → singlecell-75f8af89.js} +1 -1
- package/dist/{snplocus-fe6f4ba1.js → snplocus-0cafa73c.js} +1 -1
- package/dist/{snplst-751cea95.js → snplst-2284d5ce.js} +1 -1
- package/dist/{spliceevent.a53ss.diagram-b157f95d.js → spliceevent.a53ss.diagram-44ccabf9.js} +1 -1
- package/dist/{spliceevent.exonskip.diagram-071a3467.js → spliceevent.exonskip.diagram-c8d1bdf0.js} +1 -1
- package/dist/spliceevent.exonskip.getdefault-9fe16119.js +1 -0
- package/dist/{spliceevent.noeventdiagram-1c731f35.js → spliceevent.noeventdiagram-5e244090.js} +1 -1
- package/dist/{spliceevent.phrase-7a3bfb00.js → spliceevent.phrase-186eb050.js} +1 -1
- package/dist/{stattable-a7713026.js → stattable-886f7dad.js} +1 -1
- package/dist/{style.gdc-40ec2784.js → style.gdc-4ac9b96b.js} +1 -1
- package/dist/{summary-592d8f81.js → summary-ee2045a5.js} +1 -1
- package/dist/{sunburst-452df940.js → sunburst-bbff8818.js} +1 -1
- package/dist/survival-04e279f8.js +1 -0
- package/dist/{survival-450b6df4.js → survival-d7bd3c6b.js} +1 -1
- package/dist/{svg.download-56529955.js → svg.download-54c99186.js} +1 -1
- package/dist/{svg.legend-c82b153f.js → svg.legend-28652faa.js} +1 -1
- package/dist/{svgraph-3c5cd8d2.js → svgraph-a12d89da.js} +1 -1
- package/dist/{svmr-3dd531ef.js → svmr-248055c8.js} +1 -1
- package/dist/{table-d6c411fd.js → table-1dae543a.js} +1 -1
- package/dist/{table-bf604c50.js → table-b4a61573.js} +1 -1
- package/dist/{termInfo-96285f4a.js → termInfo-4c759483.js} +1 -1
- package/dist/{termsetting-9a7511e6.js → termsetting-636d2271.js} +1 -1
- package/dist/{tk-6a8e5bb0.js → tk-741d4674.js} +1 -1
- package/dist/{tp.ui-221efed6.js → tp.ui-23151bb1.js} +1 -1
- package/dist/{tvs.density-9fdae0cc.js → tvs.density-9fe0c7fd.js} +1 -1
- package/dist/{tvs.geneVariant-149e25b7.js → tvs.geneVariant-1b179327.js} +1 -1
- package/dist/tvs.numeric-b4cfc975.js +1 -0
- package/dist/{tvs.samplelst-a38e9c2b.js → tvs.samplelst-681358bc.js} +1 -1
- package/dist/{uiUtils-a6de7f14.js → uiUtils-74700a01.js} +1 -1
- package/dist/{variantBrowser-05375469.js → variantBrowser-910b4bcd.js} +1 -1
- package/dist/{vcf-58904308.js → vcf-16ba1e06.js} +1 -1
- package/dist/{violin-c1b78717.js → violin-a41b2e2b.js} +1 -1
- package/dist/{violin.interactivity-534d6993.js → violin.interactivity-bcf0ccc2.js} +1 -1
- package/dist/{violin.renderer-16540fb8.js → violin.renderer-149310eb.js} +1 -1
- package/dist/{violinRenderer-688abcb2.js → violinRenderer-71c9f3ab.js} +1 -1
- package/dist/{viridis-d3cf2713.js → viridis-81de7bcd.js} +1 -1
- package/dist/{y-2d48b9e4.js → y-76c7da8c.js} +1 -1
- package/dist/{zoom-2d4ede33.js → zoom-a40839cf.js} +1 -1
- package/package.json +7 -7
- package/dist/app-de19f41c.js +0 -1
- package/dist/block.lazyload-ebd949e4.js +0 -1
- package/dist/brainImaging-007edaa3.js +0 -1
- package/dist/cuminc-72257faf.js +0 -1
- package/dist/matrix.cells-a5157233.js +0 -1
- package/dist/matrix.renderers-3b8dfd04.js +0 -1
- package/dist/metaboliteIntensity-512257f3.js +0 -1
- package/dist/niceNumLabels-8fdc6507.js +0 -1
- package/dist/numeric.binary-0a3b17d2.js +0 -1
- package/dist/numeric.continuous-f77038de.js +0 -1
- package/dist/numeric.discrete-b977e88f.js +0 -1
- package/dist/numeric.spline-d64b1abe.js +0 -1
- package/dist/plot.app-91a1d78d.js +0 -1
- package/dist/sampleScatter-031f47de.js +0 -1
- package/dist/spliceevent.exonskip.getdefault-93feb627.js +0 -1
- package/dist/survival-6a4c4f12.js +0 -1
- package/dist/tvs.numeric-f9ce58bc.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{aJ as e,aK as s,M as i,q as n,aB as r,aL as o,S as a,aM as l,aN as c,f as d,aF as p,aO as f,l as u,az as h}from"./app-f91922b4.js";import{r as m}from"./table-d6c411fd.js";const b={continuous:"continuous",discrete:"discrete"};const y={GENE_VARIANT:"geneVariant",GENE_EXPRESSION:"geneExpression",CATEGORICAL:"categorical",INTEGER:"integer",FLOAT:"float",SNP_LIST:"snplst",SNP_LOCUS:"snplocus",CONDITION:"condition",SURVIVAL:"survival",SAMPLELST:"samplelst",METABOLITE_INTENSITY:"metaboliteIntensity"};const g={[y.GENE_EXPRESSION]:e,[y.METABOLITE_INTENSITY]:s};const v={DICTIONARY_VARIABLES:"Dictionary Variables",MUTATION_CNV_FUSION:"Mutation/CNV/Fusion",VARIANT_GENOTYPE:"Variant Genotype",DNA_METHYLATION:"DNA Methylation",GENE_DEPENDENCY:"Gene Dependency",GENE_EXPRESSION:"Gene Expression",PROTEIN_EXPRESSION:"Protein Expression",SPLICE_JUNCTION:"Splice Junction",METABOLITE_INTENSITY:"Metabolite Intensity",GSEA:"GSEA",MUTATION_SIGNATURE:"Mutation Signature",SNP_LIST:"SNP List",SNP_LOCUS:"SNP Locus"};const _={[y.CATEGORICAL]:v.DICTIONARY_VARIABLES,[y.CONDITION]:v.DICTIONARY_VARIABLES,[y.FLOAT]:v.DICTIONARY_VARIABLES,[y.INTEGER]:v.DICTIONARY_VARIABLES,[y.SAMPLELST]:v.DICTIONARY_VARIABLES,[y.SURVIVAL]:v.DICTIONARY_VARIABLES,[y.GENE_VARIANT]:v.MUTATION_CNV_FUSION,[y.SNP_LIST]:v.SNP_LIST,[y.SNP_LOCUS]:v.SNP_LOCUS,[y.GENE_EXPRESSION]:v.GENE_EXPRESSION,[y.METABOLITE_INTENSITY]:v.METABOLITE_INTENSITY};const w=new Set([y.SNP_LIST,y.SNP_LOCUS,y.GENE_EXPRESSION,y.GENE_VARIANT,y.METABOLITE_INTENSITY]);const j=new Set([y.INTEGER,y.FLOAT,y.GENE_EXPRESSION,y.METABOLITE_INTENSITY]);function N(t){if(!t)return false;return j.has(t.type)}function T(t){return!S(t)}function S(t){if(!t)throw new Error("Type is not defined");return w.has(t)}function I(t,e){if(!t)throw new Error("First term is not defined ");if(!e)throw new Error("Second term is not defined ");if(t.type!==e.type)return false;if(T(t.type)&&T(e.type)&&t.type!=y.SAMPLELST)return t.id===e.id;switch(t.type){case y.GENE_EXPRESSION:return t.gene==e.gene;case y.METABOLITE_INTENSITY:return t.name==e.name;case y.GENE_VARIANT:return t.gene==e.gene||t.chr==e.chr&&t.start==e.start&&t.stop==e.stop;default:return false}}function A(t){switch(t){case"./tvs.categorical.js":return import("./tvs.categorical-48a51412.js");case"./tvs.condition.js":return import("./tvs.condition-9e77e3b8.js");case"./tvs.density.js":return import("./tvs.density-9fdae0cc.js");case"./tvs.geneVariant.js":return import("./tvs.geneVariant-149e25b7.js");case"./tvs.numeric.js":return import("./tvs.numeric-f9ce58bc.js");case"./tvs.samplelst.js":return import("./tvs.samplelst-a38e9c2b.js");case"./tvs.survival.js":return import("./tvs.survival-df35b85b.js");default:return new Promise((function(e,s){(typeof queueMicrotask==="function"?queueMicrotask:setTimeout)(s.bind(null,new Error("Unknown variable dynamic import: "+t)))}))}}class O{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,tip:new i({padding:"5px"})};this.durations={exit:0};k(this);this.categoryData={};this.handlerByType={};this.api={main:this.main.bind(this),showMenu:this.showMenu}}validateOpts(t){if(!t.holder)throw".holder missing";if(!t.vocabApi)throw".vocabApi missing";if(typeof t.callback!="function")throw".callback() is not a function";return t}async main(t={}){this.tvs=t.tvs;this.filter=t.filter;await this.setHandler();await this.updateUI()}async setHandler(){if(!this.tvs||!this.tvs.term)return;const t=this.tvs.term;const e=N(t)?"numeric":t.type;if(!this.handlerByType[e]){try{const t=await A(`./tvs.${e}.js`);this.handlerByType[e]=t.handler}catch(t){throw`error with handler='./tvs.${e}.js': ${t}`}}this.handler=this.handlerByType[e]}}const x=r(O);function k(t){t.updateUI=function(){const e=t.dom.holder;const s=e.selectAll(".tvs_pill").data([t.tvs],(t=>t?.term.id));s.exit().each(t.exitPill);s.each(t.updatePill);s.enter().append("div").attr("class","tvs_pill").style("white-space","nowrap").style("display","inline-block").transition().duration(200).each(t.enterPill)};t.enterPill=async function(){const e=n(this).style("font-size",".9em");e.append("div").attr("class","term_name_btn sja_filter_tag_btn").style("display","inline-block").style("border-radius","6px 0 0 6px").style("padding","6px 6px 3px 6px").html(t.handler.term_name_gen).style("text-transform","uppercase");e.append("div").attr("class","negate_btn").style("cursor","default").style("padding","6px 6px 3px 6px").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(t.tvs.isnot&&t.tvs.term.type!=="geneVariant"?"NOT":"IS"));t.updatePill.call(this)};t.showMenu=e=>{const s=e?e:t.dom.tip;if(t.tvs.term.type!=="geneVariant"){C(s,t.tvs,t)}t.handler.fillMenu(t,s,t.tvs)};t.updatePill=async function(){const e=n(this);const s=e.datum();const i=t.tvs.values&&t.tvs.values.length||t.tvs.ranges&&t.tvs.ranges.length||t.tvs.term.type=="samplelst";e.select(".term_name_btn").html(t.handler.term_name_gen);e.select(".negate_btn").style("display",i?"inline-block":"none").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(s.isnot&&s.term.type!=="geneVariant"?"NOT":"IS"));const r=t.handler.get_pill_label(s);if(!("grade_type"in r))r.grade_type="";const o=e.selectAll(".value_btn").data(r?[r]:[],(t=>t.txt+t.grade_type));o.exit().each(t.removeValueBtn);o.enter().append("div").attr("class","value_btn sja_filter_tag_btn").style("display",i?"inline-block":"none").style("padding","6px 6px 3px 6px").style("border-radius","0 6px 6px 0").style("font-style","italic").html((t=>t.txt)).append("div").attr("class","grade_type_btn").style("display","inline-block").style("margin","0 5px").style("font-size",".6em").style("text-transform","uppercase").html((t=>t.grade_type)).style("opacity",0).transition().duration(200).style("opacity",1)};t.exitPill=async function(e){n(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()};t.makeValueTable=function(e,s,i,n){if(i?.length==0)return e;const r=e.append("div").style("font-size","0.8rem");t.clusionNote=r.append("div").style("font-weight","bold").style("margin","10px 0px 5px 10px").text(`Select 1 or more categories for ${s.isnot?"EXCLUSION":"INCLUSION"}`);const o=r.append("div");const a=Math.max(...i.map((t=>t.samplecount)),0);i.forEach((t=>t.bar_width_frac=Number((1-(a-t.samplecount)/a).toFixed(4))));const l=100;const c=[];const d=[];for(const[t,e]of i.entries()){let i=e.label||e.key;if(e.samplecount)i+=" (n="+e.samplecount+")";const n=l*e.bar_width_frac;const r=`<div style='margin:1px 10px;width:${n}px;height:15px;background-color:#ddd'>`;c.push([{value:i},{html:r}]);let o=false;if(s.term.type=="categorical"||s.term.type=="survival")o=s.values.find((t=>t.key===e.key));else if(s.term.type=="float"||s.term.type=="integer")o=s.ranges.find((t=>String(t.value)===e.value.toString()));else if(s.term.type=="condition")o=s.values.find((t=>String(t.key)===String(e.key)));if(o)d.push(t)}const p=[{label:"tvs"},{label:"bar"}];const f={text:"APPLY",class:"sjpp_apply_btn sja_filter_tag_btn",callback:t=>{if(n)n(t)}};t.tableApi=m({rows:c,columns:p,div:o,maxWidth:"40vw",maxHeight:"40vh",buttons:[f],showHeader:false,striped:false,showLines:false,selectedRows:d,selectedRowStyle:{"text-decoration":s.isnot?"line-through":""}});return o};t.removeValueBtn=function(e,s){const i=n(this.parentNode);const r=i.datum();const o=t.handler.getSelectRemovePos(s,r);n(i.selectAll(".value_select")._groups[0][o]).remove();n(i.selectAll(".or_btn")._groups[0][s]).remove();n(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()}}async function E(t){const e=new O(t);e.tvs={term:t.term};e.filter=t.filter;await e.setHandler();if(e.handler.setTvsDefaults)e.handler.setTvsDefaults(e.tvs);e.handler.fillMenu(e,t.holder,e.tvs)}function C(t,e,s){const i=t.selectAll("label").data([{label:"Exclude",value:"false",checked:e.isnot!==undefined?e.isnot:false}]).enter().append("label").style("margin","0 5px");const n=i.append("input").attr("type","checkbox").attr("name","sja_filter_isnot_input").attr("value",(t=>t.value)).property("checked",(t=>t.checked)).style("vertical-align","top").style("margin-right","3px").on("change",(()=>{e.isnot=n.node().checked;if(s.clusionNote)s.clusionNote.text(`Select 1 or more categories for ${e.isnot?"EXCLUSION":"INCLUSION"}`);if(s.tableApi){s.tableApi.update({selectedRowStyle:{"text-decoration":e.isnot?"line-through":""}})}}));i.append("span").style("margin-right","5px").style("vertical-align","top").html((t=>t.label))}function R(t,e){if(t.type==="tvs"&&t.tvs.term.id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=R(s,e);if(t)return t}}function D(t,e){if(t.$id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=D(s,e);if(t)return t}}function V(t,e){if(t.$id===e)return t;if(!t.lst)return;for(const s of t.lst){if(s.$id===e)return t;else if(s.type=="tvslst"){const t=V(s,e);if(t)return t}}}function M(t,e){if(t.tag===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=M(s,e);if(t)return t}}function P(t=[],e="",s=null){const i={type:"tvslst",in:true,join:e,lst:t};if(s!==null&&i.$id!==undefined)i.$id=s;return i}function F(t){if(!t)return P([]);const e=JSON.parse(JSON.stringify(t));const s=L(e);return s.type=="tvslst"?s:P([s])}function L(t){delete t.$id;delete t.tag;if(t.type!="tvslst")return t;const e=t.lst.filter((t=>t.type!=="tvslst"||t.lst.length>0)).map((t=>t.type!=="tvslst"||t.lst.length>1?t:t.lst[0]));e.forEach($);if(!e.length){return P([],"",t.$id)}else if(e.length==1){if(e[0].type==="tvslst"){return L(e[0])}else{return $(e[0])}}else{t.lst=[];for(const s of e){if(s.type==="tvslst"){const e=L(s);if(e.type!=="tvslst"||e.join!=t.join||e.in!=t.in){t.lst.push(e)}else if(e.lst.length){t.lst.push(...e.lst)}}else{t.lst.push(s)}}return t}}function $(t,e=null){delete t.$id;if(typeof e=="function")e(t);if(t.type=="tvslst"){for(const s of t.lst){$(s,e)}}return t}function q(t){if(!t||t.length==0)return;let e=JSON.parse(JSON.stringify(t[0]));if(t.length==1)return e;if(e.lst.length<2){if(e.join!=="")throw'filter.join must be an empty string "" when filter.lst.length < 2';e.join="and"}else if(e.join=="or"){e={type:"tvslst",join:"and",in:true,lst:[e]}}else if(e.join!="and"){throw'filter.join must be either "and" or "or" when .lst length > 1'}for(let s=1;s<t.length;s++){const i=JSON.parse(JSON.stringify(t[s]));if(i.join=="or")e.lst.push(i);else e.lst.push(...i.lst)}if(e.lst.length==1&&e.lst[0].type=="tvs"){e.join=""}return e}let U=0;function J(t){t.initUI=async function(){if(t.opts.newBtn){t.opts.newBtn.on("click.filter",t.displayTreeNew)}else{t.dom.newBtn=t.dom.holder.append("div").attr("class","sja_new_filter_btn sja_menuoption").html(t.opts.emptyLabel).style("display","inline-block").on("click",t.displayTreeNew)}t.dom.filterContainer=t.dom.holder.append("div").attr("class","sja_filter_container");t.dom.holder.selectAll(".sja_filter_add_transformer").data(t.opts.joinWith).enter().append("div").attr("class","sja_filter_add_transformer").style("display",(e=>t.filter&&t.filter.join!=e?"inline-block":"none")).style("margin-left","10px").style("padding","5px").style("border-radius","5px").style("cursor","pointer").html((t=>"+"+t.toUpperCase())).on("click",t.displayTreeNew);t.dom.table=t.dom.controlsTip.clear().d.append("table").style("border-collapse","collapse");const e=[{action:"edit",html:["","Edit","›"],handler:t.editTerm},{action:"join",html:["✚","","›"],handler:t.displayTreeMenu},{action:"switch",html:["","Switch to",""],handler:t.switchJoin},{action:"negate",html:["","Negate",""],handler:t.negateClause},{action:"remove",html:["✖","Remove",""],handler:t.removeTransform}];if(t.opts.vocab){e.splice(1,0,{action:"replace",html:["","Replace","›"],handler:t.displayTreeMenu})}t.dom.table.selectAll("tr").data(e).enter().append("tr").attr("class","sja_menuoption").on("click",t.handleMenuOptionClick).selectAll("td").data((t=>t.html)).enter().append("td").style("padding","5px").style("border-top","solid 1px white").style("color",((t,e)=>t=="✖"?"#a00":e===0?"#0a0":"#111")).style("opacity",((t,e)=>e===0?.8:1)).html((t=>t));t.dom.treeHead=t.dom.treeTip.d.append("div").attr("class","sja_tree_tip_head").style("padding","3px");t.dom.termSrcDiv=t.dom.treeTip.d.append("div").attr("class","sja_term_src_body");t.dom.treeHeadTitle=t.dom.treeHead.append("div");n("body").on("mousedown.sja_filter_"+U++,(e=>{if(["sja_filter_join_label","sja_filter_clause_negate","sja_filter_paren_open","sja_filter_paren_close"].includes(e.target.className))return;t.dom.filterContainer?.selectAll(".sja_filter_grp").style("background-color","transparent");t.removeBlankPill();this.dom.holder?.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay)}))};t.updateUI=async function(e,s){e.datum(s).style("display",!s.lst||!s.lst.length?"none":"inline-block");const i=e.selectAll(":scope > .sja_filter_grp").style("background-color","transparent").data([s],t.getId);i.exit().each(t.removeGrp);i.each(t.updateGrp);i.enter().append("div").attr("class","sja_filter_grp").style("margin","5px").each(t.addGrp);t.updatePromise(0)};t.addGrp=function(e,s){const i=this.parentNode.__data__;n(this).style("display","inline-block");n(this).append("div").attr("class","sja_filter_clause_negate").style("display",i.in?"none":"inline-block").style("color","rgb(102,0,0)").style("font-weight",500).style("cursor","pointer").html("NOT").on("click",t.displayControlsMenu);n(this).append("div").attr("class","sja_filter_paren_open").html("(").style("display","none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);const r=e.type=="tvslst"?e.lst:[e];const o=n(this).selectAll(":scope > .sja_filter_item").data(r,t.getId);o.enter().append("div").attr("class","sja_filter_item").each(t.addItem);if(t.opts.joinWith.length==1){t.dom.last_join_div=n(this).append("div").attr("class","sja_filter_last_join").style("display","inline");t.dom.last_join_label=t.dom.last_join_div.append("div").datum({action:"join",html:["✚","","›"],handler:t.displayTreeMenu}).attr("class","sja_filter_last_join_label").style("padding","0 5px").style("display",i.lst.length?"inline":"none").style("font-weight",500).style("cursor","pointer").html("+"+t.opts.joinWith[0].toUpperCase()).on("click",t.showLastJoinBlank);n("body").on("mousedown.sja_filter_last_join",(()=>{t.dom.last_join_label.style("display","inline")}))}n(this).append("div").attr("class","sja_filter_paren_close").style("padding","0 5px").html(")").style("display","none").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);n(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||r.length<2?"none":!i.in||r.length>1&&i.tag!="filterUiRoot"?"inline-block":"none")};t.updateGrp=function(e,s){const i=this.parentNode.__data__;n(this).select(":scope > .sja_filter_clause_negate").style("display",i.in?"none":"inline-block");const r=e.type=="tvslst"?e.lst:[e];n(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||r.length<2?"none":!i.in||r.length>1&&i.tag!="filterUiRoot"?"inline-block":"none");const o=n(this).selectAll(":scope > .sja_filter_item").data(r,t.getId);o.exit().each(t.removeItem);o.each(t.updateItem);o.enter().insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_item").each(t.addItem);n(this).selectAll(":scope > .sja_filter_item").sort(((t,e)=>r.indexOf(t)-r.indexOf(e)));if(t.dom.last_join_label){t.dom.last_join_div.datum(i);this.insertBefore(t.dom.last_join_div.node(),n(this).select(":scope > .sja_filter_paren_close").node());t.dom.last_join_label.style("display","inline")}};t.removeGrp=function(e){t.numExpectedItems+=1;if(e.type=="tvslst"){for(const s of e.lst){if(s.lst)t.removeGrp(s);else{delete t.pills[s.$id]}}}else{delete t.pills[e.$id]}if(this instanceof Node){n(this).selectAll("*").on("click",null);n(this).on("click",null).remove()}t.updatePromise()};t.addItem=async function(e,s){const i=this.parentNode.__data__;if(e.type=="tvslst"){t.updateUI(n(this),e);t.addJoinLabel(this,i,e);return}t.numExpectedItems+=1;const r=n(this).style("display","inline-block").style("position","relative").style("white-space","nowrap").append("div").attr("class","sja_pill_wrapper").style("display","inline-block").style("margin",t.opts.joinWith.length>1?"":"2px").on("click",e.renderAs==="htmlSelect"?null:t.displayControlsMenu);t.addJoinLabel(this,i,e);if(e.renderAs=="htmlSelect"){const s=B(t,e);const n=r.append("select").on("change",(function(){const n=JSON.parse(JSON.stringify(t.filter));const r=D(n,i.$id);const o=i.lst.indexOf(e);if(o==-1)return;const a=+this.value;const l=JSON.parse(JSON.stringify(e));const c="keys"in s[a]?s[a].keys:[s[a].key];l.tvs.values=c.map((t=>({key:t,label:t})));r.lst[o]=l;t.refresh(n)}));const o=G(t,e);n.selectAll("option").data(s).enter().append("option").property("value",((t,e)=>e)).property("selected",((t,e)=>e==o)).html((t=>t.shortLabel?t.shortLabel:t.label?t.label:t.key))}else{const s=await x({vocabApi:t.vocabApi,holder:r,debug:t.opts.debug,getCategoriesArguments:t.opts.getCategoriesArguments,callback:s=>{const n=JSON.parse(JSON.stringify(t.filter));const r=D(n,i.$id);const o=i.lst.indexOf(e);if(o==-1)return;const a=r.lst.findIndex((t=>t.$id==e.$id));if(a==-1)r.lst[o]={$id:e.$id,type:"tvs",tvs:s};else r.lst[a].tvs=s;t.refresh(n)}});t.pills[e.$id]=s;await s.main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.updateItem=async function(e,s){const i=this.parentNode.__data__;n(this).select(":scope > .sja_filter_join_label").style("display",t.opts.joinWith.length>1&&i.lst.indexOf(e)<i.lst.length-1?"inline-block":"none").style("margin",t.opts.joinWith.length>1?"":"2px").html(i.join=="and"?"AND":"OR");if(e.type=="tvslst"){t.updateUI(n(this),e)}else if(e.renderAs==="htmlSelect"){t.numExpectedItems+=1;n(this).select("select").property("value",""+G(t,e))}else{if(!t.pills[e.$id])return;t.numExpectedItems+=1;await t.pills[e.$id].main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.removeItem=function(e){delete t.pills[e.$id];n(this).on("click",null).remove()};t.addJoinLabel=function(e,s,i){const r=s.lst.findIndex((t=>t.$id===i.$id));n(e).append("div").attr("class","sja_filter_join_label").style("display",t.opts.joinWith.length>1&&s.lst.length>1&&i&&r!=-1&&r<s.lst.length-1?"inline-block":"none").style("width","50px").style("padding","5px").style("border","none").style("border-radius","5px").style("text-align","center").style("cursor","pointer").html(s.lst.length<2?"":s.join=="and"?"AND":"OR").on("click",t.displayControlsMenu)};t.updateJoinLabel=function(e){const s=this.parentNode.parentNode.parentNode.__data__;const i=s.lst.findIndex((t=>t.$id===e.$id));n(this).style("display",t.opts.joinWith.length>1&&s.lst.length>1&&e&&i!=-1&&i<s.lst.length-1?"inline-block":"none")};t.getAddTransformerBtnDisplay=function(e){if(t.opts.joinWith.length<2){return"none"}else if(t.filter&&t.filter.lst.find((t=>t.tag==="cohortFilter"))){return t.filter.lst.length==1&&e=="and"?"inline-block":"none"}else{return t.filter&&t.filter.lst.length>0&&(t.filter.join!==e||!t.filter.in)?"inline-block":"none"}}}function B(t,e){return e.selectOptionsFrom=="selectCohort"?t.opts.termdbConfig.selectCohort.values:Array.isArray(e.tvs.term.values)?e.tvs.term.values:Object.values(e.tvs.term.values)}function G(t,e){const s=B(t,e);const i=JSON.stringify(e.tvs.values.map((t=>t.key)).sort());const n=s.findIndex((t=>t.keys?i===JSON.stringify(t.keys.sort()):t.key===i));return n}const W="#fff";function z(t){t.displayControlsMenu=function(e){e.stopPropagation();if(!t.activeData)return;const s=this.parentNode.__data__;const i=V(t.filter,s.$id);t.activeData={item:s,filter:i,elem:this};t.removeBlankPill();t.resetGrpHighlights(this,i);if(s.noEdit)t.dom.table.selectAll("tr").filter((t=>t.action=="edit")).style("display","none");t.dom.controlsTip.showunder(this)};t.resetGrpHighlights=function(e,s){const i=e.className;const n=i.includes("join")||i.includes("negate")||i.includes("paren");const r=t.dom.controlsTip.d.selectAll("tr").style("background-color","");r.filter((t=>t.action=="edit"||t.action=="replace")).style("display",n?"none":"table-row");r.filter((t=>t.action=="remove")).style("display",i.includes("_join_")&&s.lst.find((t=>t.tag=="cohortFilter"))?"none":"table-row");r.filter((t=>t.action=="join")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||i.includes("negate")||i.includes("paren")?"none":"table-row").select("td:nth-child(2)").html(n?s.join.toUpperCase():s.join=="and"?"OR":"AND");r.filter((t=>t.action=="switch")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||!i.includes("_join_")?"none":"table-row").select("td:nth-child(2)").html((t=>s.join=="and"?"Switch to OR":"Switch to AND"));t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(n){if(i.includes("join"))e.parentNode.parentNode.style.backgroundColor="#ee5";else e.parentNode.style.backgroundColor="#ee5"}};t.handleMenuOptionClick=async function(e,s){e.stopPropagation();if(s==t.activeData.menuOpt)return;t.activeData.menuOpt=s;if(t.activeData.elem.className.includes("join")&&s.action!=="join"&&s.action!="switch"){t.activeData.item=t.activeData.filter;t.activeData.filter=V(t.filter,t.activeData.item)}t.resetBlankPill(s.action);t.dom.controlsTip.d.selectAll("tr").style("background-color","");await s.handler(this,s)};t.resetBlankPill=function(e){t.removeBlankPill();t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(e!="join")return;const s=t.dom.last_join_div?t.dom.last_join_div.node():t.activeData.elem.className.includes("join_label")?t.activeData.elem.parentNode.parentNode:t.activeData.item.type=="tvs"||t.activeData.filter===t.filter?t.activeData.elem:t.activeData.elem.parentNode.parentNode;const i=t.opts.joinWith.length===1?t.opts.joinWith[0].toUpperCase():t.activeData.elem.className.includes("join_label")?t.activeData.filter.join.toUpperCase():t.activeData.btn&&typeof t.activeData.btn.__data__==="string"?t.activeData.btn.__data__.toUpperCase():t.activeData.item.type=="tvslst"?t.activeData.filter.join.toUpperCase():t.activeData.filter.join=="or"?"AND":"OR";if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){n(s).insert("div","div").attr("class","sja_filter_paren_open").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html("(")}const r=n(s).insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_blank_pill").style("display","inline-block").style("height","20px").style("overflow","visible");r.append("div").style("display","inline-block").style("width","50px").style("text-align","center").html(i);r.append("div").style("position","relative").style("top","-7px").style("display","inline-block").style("width","80px").style("height","22px").style("margin-right","5px").style("border","3px dashed #b8d3ea").style("vertical-align","top").style("background-color","#ee5");if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){n(s).append("div").attr("class","sja_filter_paren_close").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html(")")}if(s==t.dom.filterContainer.node()){t.dom.filterContainer.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display",t.opts.joinWith.length>1&&t.filter.lst.length>1?"inline-block":"none")}};t.removeBlankPill=function(){t.dom.holder?.selectAll(".sja_filter_blank_pill, .sja_pill_wrapper > .sja_filter_paren_open, .sja_pill_wrapper > .sja_filter_paren_close").remove();if(t.filter.in&&t.filter.lst.filter((t=>t.type==="tvslst")).length<1){t.dom.filterContainer?.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display","none")}};t.displayTreeNew=async function(e,s){e.stopPropagation();if(t.opts.newBtn&&this.className!=="sja_filter_add_transformer"&&t.filter.lst.length)return;t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(t.filter.lst.length>0){t.activeData={item:t.filter,filter:t.filter,elem:t.dom.filterContainer.node(),btn:this}}if(t.filter.lst.length)t.resetBlankPill("join");const i=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(i){t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");t.dom.treeTip.clear().showunder(i)}else{t.dom.treeTip.clear().showunder(this)}const n=t.activeData?t.getAdjustedRoot(t.activeData.filter.$id,s):JSON.parse(t.rawCopy);const r=await import("./app-bfce9bf5.js");r.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,termfilter:{filter:n},tree:{usecase:{target:"filter"}}},tree:{disable_terms:t.activeData&&t.activeData.filter&&t.activeData.filter.lst&&s=="and"?t.activeData.filter.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):[],click_term2select_tvs(e){t.editFilterRoot(s,[{type:"tvs",tvs:e}])}}})};t.editFilterRoot=(e,s)=>{const i=JSON.parse(JSON.stringify(t.filter));if(!i.lst.length){if(s.length>1)i.join="and";i.lst.push(...s);t.refresh(i)}else if(e!="or"&&e!="and"){throw"unhandled new term(s): invalid appender join value"}else{if(!i.join)i.join=e;if(i.join==e&&i.in){if(s.length<2||i.join=="and"){i.lst.push(...s)}else{i.push({type:"tvslst",in:true,join:"and",lst:s})}t.refresh(i)}else if(e=="and"||s.length<2){delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:e,lst:[i,...s]})}else{delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:"or",lst:[i,{type:"tvslst",in:true,join:"and",lst:s}]})}}};t.displayTreeMenu=async function(e,s){n(e).style("background-color",W);t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");const i=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(i){t.dom.controlsTip.hide();t.dom.treeTip.clear().showunder(i)}else if(e.lastChild instanceof HTMLElement){t.dom.treeTip.clear().showunderoffset(e.lastChild)}else{t.dom.treeTip.clear().showunder(e)}const r=t.activeData.filter;const o=await import("./app-bfce9bf5.js");o.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,header_mode:"search_only",termfilter:{filter:t.getAdjustedRoot(r.$id,r.join)},tree:{usecase:{target:"filter"}}},tree:{disable_terms:r&&r.lst&&r.join=="and"?r.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):!t.activeData.item?[]:t.activeData.item.type=="tvs"?[t.activeData.item.tvs.term.id]:t.activeData.item.lst?t.activeData.item.lst.filter((t=>t.type=="tvs")).map((t=>t.tvs.term.id)):[],click_term2select_tvs:s.action=="replace"?t.replaceTerm:!r.join||!r.lst.length||t.activeData.elem&&t.activeData.elem.className.includes("join")?t.appendTerm:t.subnestFilter}})};t.editTerm=function(e){n(e.parentNode).selectAll("tr").style("background-color",t.highlightEditRow);const s=t.dom.termSrcDiv;const i=t.activeData.item;t.dom.treeTip.clear();t.pills[i.$id].showMenu(s);t.dom.treeTip.showunderoffset(e.lastChild)};t.highlightEditRow=function(t){return t.action=="edit"?W:""};t.handleNotLabelClick=function(e,s){t.activeData={item:this.__data__};t.negateClause()};t.negateClause=function(){const e=JSON.parse(JSON.stringify(t.filter));const s=D(e,t.activeData.item.$id);if(s.type=="tvslst")s.in=!s.in;else if(s.type=="tvs"&&s.tvs?.term?.type=="geneVariant"){const t=s.tvs.values.filter((t=>t.mclassExcludeLst.length>0))[0];const e=t.mclassLst;t.mclassLst=t.mclassExcludeLst;t.mclassExcludeLst=e;s.tvs.isnot=!s.tvs.isnot}else s.tvs.isnot=!s.tvs.isnot;t.refresh(e)};t.replaceTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);const r=n.lst.findIndex((e=>e.$id===t.activeData.item.$id));if(s.length<2||n.join=="and"){n.lst.splice(r,1,...s)}else{n.lst[r]={in:!e.isnot,type:"tvslst",join:"and",lst:s}}t.refresh(i)};t.appendTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);if(s.length<2||n.join=="and"){n.lst.push(...s);if(n.join==""&&t.opts.joinWith.length===1)n.join=t.opts.joinWith[0]}else{n.lst.push({in:true,type:"tvslst",join:"and",lst:s})}t.refresh(i)};t.subnestFilter=e=>{let s;if(Array.isArray(e)){s=e}else{s=[{type:"tvs",tvs:e}]}const i=t.activeData.item;const n=t.activeData.filter;const r=JSON.parse(JSON.stringify(t.filter));const o=D(r,n.$id);const a=o.lst.findIndex((t=>t.$id===i.$id));o.lst[a]={in:true,type:"tvslst",join:n.join=="or"?"and":"or",lst:[i,...s]};t.refresh(r)};t.removeTransform=function(e,s){const i=s.action||typeof s!=="object"?t.activeData.item:D(t.filter,s.$id);const n=V(t.filter,i.$id);if(i==n){t.refresh(P([],"",i.$id));return}const r=n.lst.findIndex((t=>t.$id===i.$id));if(r==-1)return;const o=JSON.parse(JSON.stringify(t.filter));const a=D(o,n.$id);a.lst.splice(r,1);if(a.lst.length===1){const e=V(o,a.$id);if(a.lst[0].type=="tvslst"){if(e==o){a.lst[0].tag="filterUiRoot";t.refresh(a.lst[0])}else{const s=e.lst.findIndex((t=>t.$id==a.$id));if(a.lst[0].join==e.join){e.lst.splice(s,1,...a.lst[0].lst);t.refresh(o)}else{e.lst[s]=a.lst[0];t.refresh(o)}}}else{a.join="";const s=e.lst.findIndex((t=>t.$id===a.$id));e.lst[s]=a.lst[0];if(!a.in){e.lst[s].tvs.isnot=!e.lst[s].tvs.isnot;if(e==o)e.in=true}t.refresh(o)}}else{t.refresh(o)}};t.showLastJoinBlank=function(e,s){e.stopPropagation();const i=t.dom.last_join_div.node();t.dom.last_join_label.style("display","none");const n=this.parentNode.__data__;t.activeData={item:n,filter:n,elem:i};t.resetBlankPill(s.action);t.displayTreeMenu(i,s)};t.switchJoin=function(e,s){const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);if(n.join<2)return;n.join=n.join=="and"?"or":"and";t.refresh(i)}}function H(t,e={}){if(t.find((t=>!Number.isFinite(t))))throw"non-numeric values found";let s;const i=new Set(t);if(i.size===1){const t=[...i][0];s={type:"custom-bin",lst:[{stop:t,stopinclusive:false,startunbounded:true,label:"<"+t},{start:t,stop:t,startinclusive:true,stopinclusive:true,label:"="+t},{start:t,startinclusive:false,stopunbounded:true,label:">"+t}]}}else{t.sort(((t,e)=>t-e));const e=t.length;const i=t[0];const n=t[e-1];const r=(n-i)/8;let o=Math.round(e*.05)-1;if(o<0)o=0;const a=t[o];const l=Math.max(i+r,a);let[c,d,p,f]=Y(r,l,n,i);s={type:"regular-bin",startinclusive:true,bin_size:c,first_bin:{stop:d}};if(p)s.last_bin={start:p};if(f)s.rounding=f}if("format"in e){if(e.format==="string"){return JSON.stringify(s)}else{throw"options are not in the correct format"}}else{return s}}function Y(t,e,s,i){let n,r,o,a;const l=Math.floor(Math.log10(t));if(t>=.1&&t<=2){n=Math.round(t/(1*10**l))*(1*10**l);r=Math.round(e/(1*10**l))*(1*10**l)}else{n=Math.round(t/(5*10**l))*(5*10**l);r=Math.round(e/(5*10**l))*(5*10**l);if(n===0)n=1*10**l;if(r===0)r=1*10**l;if(n===5*10**l&&r===1*10**l)r=5*10**l}if(r<i)r=r*2;const c=r+n*7;if(s>c){o=r+n*6}if(t<1){const t=Math.abs(l);n=Number(n.toFixed(t));r=Number(r.toFixed(t));if(o)o=Number(o.toFixed(t));a="."+t+"f"}if(Object.is(r,-0))r=0;return[n,r,o,a]}class K{constructor(t){this.app=t.app;this.opts=t;this.state=t.state;this.vocab=t.state.vocab;this.currAnnoData={samples:{},refs:{byTermId:{}},lastTerms:[],lastFilter:{}};this.missingCatValsByTermId={};const e=localStorage.getItem("jwtByDsRoute")||`{}`;this.jwtByDsRoute=JSON.parse(e);const s=this.vocab?.dslabel||this.state?.dslabel;this.jwtByRoute=this.jwtByDsRoute[s]||{}}async main(t=null){if(t)Object.assign(this.state,t);else this.state=structuredClone(this.app?.getState?.()||this.opts.state);if(this.state.vocab)this.vocab=this.state.vocab;const e=this.state.dslabel||this.state.vocab.dslabel;this.verifiedToken=!this.state.termdbConfig?.requiredAuth?.length||o(e,"termdb");if(e)await this.maySetVerifiedToken(e)}async maySetVerifiedToken(t){if(this.verifiedToken===true)return this.verifiedToken;let e=this.opts.getDatasetAccessToken?.();if(!e)e=this.jwtByRoute["termdb"];if(this.verifedToken&&e===this.verifiedToken)return this.verifiedToken;try{const s=this.state.termdbConfig?.requiredAuth.find((t=>t.route=="termdb"));if(!s){this.verifiedToken=true;return}if(s.type==="jwt"){if(!e){delete this.verifiedToken;return}const i={[s.headerKey]:e};const n="termdb";if(!i.authorization&&this.jwtByRoute[n])i.authorization=`Bearer ${btoa(this.jwtByRoute[n])}`;const r=await a("/jwt-status",{method:"POST",headers:i,body:{dslabel:t,route:n,embedder:location.hostname}});this.verifiedToken=r.status==="ok"&&e;if(r.error){this.tokenVerificationPayload=r;throw r.error}else{this.sessionId=s.headerKey&&r[s.headerKey]||r["x-sjppds-sessionid"]||r["x-ds-access-token"];delete this.tokenVerificationMessage;delete this.tokenVerificationPayload;if(r.jwt){if(!this.jwtByDsRoute[t]){this.jwtByDsRoute[t]={};this.jwtByRoute=this.jwtByDsRoute[t]}this.jwtByDsRoute[t][r.route]=r.jwt;localStorage.setItem("jwtByDsRoute",JSON.stringify(this.jwtByDsRoute))}}}else{throw`unsupported requiredAuth='${s.type}'`}}catch(t){this.tokenVerificationMessage=t.message||t.reason||t;if(typeof t=="object")console.log(t)}}hasVerifiedToken(){return this.verifiedToken&&true}mayGetAuthHeaders(t=""){const e=this.state.termdbConfig?.requiredAuth;if(!e)return{};if(!this.verifiedToken){this.tokenVerificationMessage=`requires login for this data`;return}const s={};if(e.headerKey)s[e.headerKey]=this.verifiedToken;if(this.sessionId)s["x-sjppds-sessionid"]=this.sessionId;if(t&&this.jwtByRoute[t]){const e=this.jwtByRoute[t];s.authorization=`Bearer ${btoa(e)}`}return s}async trackDsAction({action:t,details:e}){const s={"x-sjppds-sessionid":this.sessionId};const i=this.jwtByRoute.termdb;if(i)s.authorization="Bearer "+btoa(i);await a("/authorizedActions",{method:"POST",credentials:"include",headers:s,body:Object.assign({dslabel:this.vocab.dslabel,action:t,details:e,"x-sjppds-sessionid":this.sessionId})})}getTwMinCopy(t){const e={$id:t.$id,term:{},q:t.q};if(T(t.term?.type)){e.term.id=t.term?.id;e.term.name=t.term?.name;e.term.type=t.term?.type;e.term.values=t.term?.values}else{e.term=t.term}return e}cacheTermQ(t,e){if(!e.reuseId)throw`missing term q.reuseId for term.id='${t.id}'`;this.app.dispatch({type:"cache_termq",termId:t.id,q:e})}async uncacheTermQ(t,e){await this.app.dispatch({type:"uncache_termq",term:t,q:e})}getCustomTermQLst(t){if(t.id){const e=this.state.reuse.customTermQ.byId[t.id]||{};const s=Object.values(e).map((t=>JSON.parse(JSON.stringify(t))));for(let t=s.length+1;t<1e3;t++){const e=`Setting #${t}`;if(!s.find((t=>t.reuseId===e))){s.nextReuseId=e;break}}if(!s.nextReuseId){s.nextReuseId=btoa((+new Date).toString()).slice(10,-3)}return s}else return[]}async addCustomTerm(t){await this.app.dispatch({type:"add_customTerm",obj:t})}async deleteCustomTerm(t){await this.app.dispatch({type:"delete_customTerm",name:t})}async getCustomTerms(){if(!Array.isArray(this.state.customTerms))return[];return this.state.customTerms.map((t=>t.tw))}async addGroup(t){await this.app.dispatch({type:"add_group",obj:t})}async deleteGroup(t){await this.app.dispatch({type:"delete_group",name:t})}async getGroups(){if(!Array.isArray(this.state.groups))return[];return this.state.groups}}const X=new Set(["categorical","integer","float","condition","survival","snplst","snplocus","geneVariant","samplelst","geneExpression",y.METABOLITE_INTENSITY]);function Q(t,e,s){const i=e||{};if(s&&s.usecase&&use.target in s.usecase){return s.usecase[use.target](t,use)}const n=new Set;const r=t.child_types||[];switch(i.target){case"barchart":case"summary":if(i.detail=="term0"&&t.type=="geneVariant"){return n}if(i.detail=="term2"&&t.type=="geneVariant"&&i.term1type=="geneVariant"){return n}if(t.type&&t.type!=="survival")n.add("plot");if(Z(r))n.add("branch");return n;case"matrix":if(t.type)n.add("plot");if(!t.isleaf)n.add("branch");return n;case"table":if(i.detail=="term")n.add("plot");if(r.length>1)n.add("branch");return n;case"scatterplot":if(t.type=="float"||t.type=="integer")n.add("plot");if(tt(r))n.add("branch");return n;case"sampleScatter":if(i.detail=="numeric"){if(N(t)){n.add("plot")}if(tt(r))n.add("branch")}else{if(X.has(t.type))n.add("plot");if(!t.isleaf)n.add("branch")}return n;case"boxplot":if(t.type=="float"||t.type=="integer")n.add("plot");if(i.detail==="term2"&&tt(r))n.add("branch");return n;case"cuminc":if(i.detail=="term"){if(t.type=="condition")n.add("plot");if(r.includes("condition"))n.add("branch");return n}if(i.detail==="term2"){if(t.type&&t.type!="survival")n.add("plot");if(Z(r))n.add("branch");return n}if(i.detail=="term0"){n.add("plot");return n}case"survival":if(i.detail=="term"){if(t.type=="survival")n.add("plot");if(r.includes("survival"))n.add("branch");return n}if(i.detail==="term2"){if(t.type!="survival"){if(t.type)n.add("plot");if(Z(r))n.add("branch")}return n}if(i.detail=="term0"){if(t.type)n.add("plot");if(Z(r))n.add("branch");return n}if(t.isleaf)n.add("plot");else n.add("branch");return n;case"regression":if(i.detail=="outcome"){if(i.regressionType=="linear"){if(t.type=="float"||t.type=="integer")n.add("plot");if(tt(r))n.add("branch");return n}if(i.regressionType=="logistic"){if(t.type&&t.type!="survival")n.add("plot");if(Z(r))n.add("branch");return n}else if(i.regressionType=="cox"){if(t.type=="condition"||t.type=="survival")n.add("plot");if(r.includes("condition")||r.includes("survival"))n.add("branch");return n}}if(i.detail=="independent"){if(t.type=="float"||t.type=="integer"||t.type=="categorical")n.add("plot");if(et(r,["categorical","float","integer"]))n.add("branch");return n}default:if(X.has(t.type))n.add("plot");if(!t.isleaf)n.add("branch");return n}}function Z(t){if(!t.length)return false;return t.length>1||t[0]!="survival"}function tt(t){return t.includes("float")||t.includes("integer")}function et(t,e){for(const s of e){if(t.includes(s))return true}}class st extends K{async getTermdbConfig(){const t=await a("termdb/config",{body:{genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname}});if(t.error)throw t.error;this.termdbConfig=t.termdbConfig||{};return this.termdbConfig}async getTermChildren(t,e){let s;const i={genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(e){i.cohortValues=e.slice().sort().join(",")}if(this.state.treeFilter){i.treeFilter=this.state.treeFilter}if(t.__tree_isroot){i.default_rootterm=1;s=await a("termdb/rootterm",{body:i},this.opts.fetchOpts)}else{i.get_children=1;i.tid=t.id;s=await a("termdb/termchildren",{body:i},this.opts.fetchOpts)}if(s.error)throw s.error;for(const t of s.lst){if(t.type=="integer"||t.type=="float"){if(t.bins.rounding)t.bins.default.rounding=t.bins.rounding;if(t.bins.label_offset&&!t.bins.default.label_offset)t.bins.default.label_offset=t.bins.label_offset}}return s}async getNestedChartSeriesData(t){const e=this.getTdbDataUrl(t);const s=this.mayGetAuthHeaders("termdb");const i=await a(e,{headers:s},this.opts.fetchOpts);if(i.error)throw i.error;if(i.charts){for(const e of i.charts){this.mayFillInMissingCatValues(t.term0,e.chartId,e.total);for(const s of e.serieses){this.mayFillInMissingCatValues(t.term,s.seriesId,s.total);for(const e of s.data){this.mayFillInMissingCatValues(t.term2,e.dataId,e.total)}}}}return i}mayFillInMissingCatValues(t,e,s){if(!e)return;if(!(t?.id in this.missingCatValsByTermId))return;const i=this.missingCatValsByTermId[t.id];if(!(e in i.values)){i.values[e]={key:e,label:e};i.samplecount[e]={samplecount:0,key:e,label:e}}i.samplecount[e].samplecount+=s}getTdbDataUrl(t){const e=[`embedder=${window.location.hostname}`];if(t.chartType=="cuminc")e.push("getcuminc=1");if(t.chartType=="survival")e.push("getsurvival=1");for(const s of["term0","term","term2"]){const i=t[s];if(!i)continue;const n=s=="term"?"term1":s;e.push(n+"_$id="+encodeURIComponent(i.$id));if("id"in i.term&&(!i.term?.type||T(i.term.type))){e.push(n+"_id="+encodeURIComponent(i.term.id))}else{e.push(n+"="+encodeURIComponent(JSON.stringify(i.term)))}if(!i.q)throw"plot."+s+".q{} missing: "+i.term.id;e.push(n+"_q="+Pt(i.q))}if(t.filter){const s=F(t.filter);if(s.lst.length){e.push("filter="+encodeURIComponent(JSON.stringify(s)))}}if(t.ssid){e.push("term2_is_genotype=1","ssid="+t.ssid.ssid,"mname="+t.ssid.mutation_name,"chr="+t.ssid.chr,"pos="+t.ssid.pos)}if("grade"in t)e.push(`grade=${t.grade}`);if("minSampleSize"in t)e.push(`minSampleSize=${t.minSampleSize}`);if(t.term2){const s={term1:t.term.q.hiddenValues?Object.keys(t.term.q.hiddenValues).map((e=>t.term.term.values?.[e]?.label||e)):[],term2:t.term2.q.hiddenValues?Object.keys(t.term2.q.hiddenValues).map((e=>t.term2.term.values?.[e]?.label||e)):[]};e.push(`hiddenValues=${encodeURIComponent(JSON.stringify(s))}`)}if(t.get)e.push("get="+t.get);const s=t.chartType?"termdb":"termdb-barsql";return`/${s}?${e.join("&")}&genome=${this.vocab.genome}&dslabel=${this.vocab.dslabel}`}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[i,n]of["term0","term","term2"].entries()){const r=t[n];const o=!s[n]||s[n].term?.id===r?.term?.id;if(r=="genotype")continue;if(!r){if(n=="term")throw`missing plot.term{}`;continue}if(e.refs.bins){r.bins=e.refs.bins[i];if(e.refs.q&&e.refs.q[i]){if(!r.q)r.q={};const t=e.refs.q[i];if(t!==r.q||!o){if(t.type!=r.q.type||t.mode!=r.q.mode){for(const t in r.q){if(t!="hiddenValues"||!o)delete r.q[t]}}Object.assign(r.q,t)}}}if(!r.q)r.q={};if(!r.q.groupsetting)r.q.groupsetting={}}}async getRegressionData(t){if(!T(t.outcome.term.type))throw"outcome must be dictionary term";const e={id:t.outcome.term.id,q:JSON.parse(JSON.stringify(t.outcome.q))};if(!e.q.mode&&t.regressionType=="linear")e.q.mode="continuous";const s=["mode","scale"];e.refGrp=e.q.mode=="continuous"?"NA":t.outcome.refGrp;if(e.q.mode=="continuous"){for(const t in e.q){if(!s.includes(t))delete e.q[t]}}const i={getregression:1,genome:this.vocab.genome,dslabel:this.vocab.dslabel,regressionType:t.regressionType,outcome:e,independent:t.independent.map((t=>{const e=JSON.parse(JSON.stringify(t.q));delete e.values;delete e.totalCount;if(t.q.mode=="continuous"){for(const t in e){if(!s.includes(t))delete e[t]}}return{id:t.term.id,q:e,type:t.term.type,refGrp:t.q.mode=="continuous"?"NA":t.refGrp,interactions:t.interactions||[],values:t.term.values}}))};const n=F(t.filter);if(n.lst.length)i.filter=n;const r=await a("termdb",{body:i},this.opts.fetchOpts);if(r.error)throw r.error;return r}async findTerm(t,e="",s=null,i=""){const n={genome:this.vocab.genome,dslabel:this.vocab.dslabel,findterm:encodeURIComponent(t),cohortStr:e};if(s)n.usecase=s;if(this.state.treeFilter)n.treeFilter=this.state.treeFilter;if(i)n.targetType=i;const r=await a("termdb",{body:n});if(r.error)throw r.error;const o=t.toUpperCase();const l={equals:[],startsWith:[],startsWord:[],includes:[]};for(const t of r.lst){const e=t.name.toUpperCase();if(e===o)l.equals.push(t);else if(e.startsWith(o))l.startsWith.push(t);else if(e.includes(" "+o))l.startsWord.push(t);else l.includes.push(t)}r.lst=[...l.equals,...l.startsWith,...l.startsWord,...l.includes];return r}async getTermInfo(t){if(!t)throw".getTermInfo: Missing term id";const e=["genome="+this.vocab.genome+"&dslabel="+this.vocab.dslabel+"&getterminfo=1&tid="+t];const s=await a("/termdb?"+e.join("&"),{},this.opts.fetchOpts);if(s.error)throw s.error;return s}async getCohortSampleCount(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,cohort:t};const s=await a("termdb/cohort/summary",{body:e},this.opts.fetchOpts);if(!s)throw"missing data";if(s.error)throw s.error;return s[0]?.samplecount||s.count||0}async getFilteredSampleCount(t,e){const s={genome:this.vocab.genome,dslabel:this.vocab.dslabel,getsamplecount:e||"count",filter:typeof t=="string"?t:F(t)};const i=await a("termdb",{body:s},this.opts.fetchOpts);if(!i)throw`missing data`;if(i.error)throw i.error;if(e){if(!Array.isArray(i))throw"data is not array";return i}return i[0]?.samplecount||i.count||0}async getViolinPlotData(t,e={}){const s=this.mayGetAuthHeaders("termdb");const i=Object.assign({getViolinPlotData:1,genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname,devicePixelRatio:window.devicePixelRatio,isKDE:"isKDE"in t?t.isKDE:true,ticks:t.ticks,datasymbol:t.datasymbol||"rug",orientation:t.orientation||"horizontal",radius:t.radius||3,svgw:t.svgw||200,unit:t.unit||"abs"},t,e);if(i.filter)i.filter=F(i.filter);const n=await a("termdb/violin",{headers:s,body:i});return n}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i={getpercentile:e,tid:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(s){i.filter=F(s)}return await a("termdb/getpercentile",{body:i})}async getDescrStats(t,e,s){const i={tw:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel,settings:s};if(e){i.filter=F(e)}return await a("/termdb/descrstats",{body:i})}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i=e||this.state.vocab?.dslabel;const n=s||this.state.vocab?.genome;if(!i)throw"getTerms: dslabel missing";if(!n)throw"getTerms: genome missing";const r={genome:n,dslabel:i,ids:t,embedder:window.location.hostname};const o=await a(`termdb/termsbyids`,{body:r});if(o.error)throw"getTerm: "+o.error;for(const t in o.terms){const e=o.terms[t];if(e.type=="categorical"&&!e.values&&!e.groupsetting?.inuse)this.missingCatValsByTermId[e.id]=e}return o.terms}async getterm(t,e=null,s=null){if(!t)throw"getterm: termid missing";const i=await this.getTerms([t],e,s);const n=i[t];if(!n)throw"no term found for "+t;return n}graphable(t){if(!t)throw"graphable: term is missing";return Q(t).has("plot")}async getCategories(t,e,s={}){const i=this.mayGetAuthHeaders();if(t.type=="snplst"||t.type=="snplocus"){const t=Object.assign({validateSnps:1,sumSamples:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel},s);if(e){t.filter=F(e)}return await a("/termdb",{headers:i,body:t})}if(t.category2samplecount){const e=[];for(const s in t.category2samplecount){e.push({key:s,label:t?.values?.[s]?.label||s,samplecount:t.category2samplecount[s]})}return{lst:e}}const n={getcategories:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,term:t,...s};if(e){n.filter=F(e)}try{const t=await a("termdb/categories",{headers:i,body:n});if(t.error)l(t.error);return t}catch(t){window.alert(t.message||t)}}async getNumericUncomputableCategories(t,e){const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tid:t.id};if(e){s.filter=F(e)}try{const t=await a("/termdb/numericcategories",{body:s});if(t.error)throw t.error;return t}catch(t){window.alert(t.message||t)}}async validateSnps(t){const e=["validateSnps=1","genome="+this.state.vocab.genome,"dslabel="+this.state.vocab.dslabel];if(t.text){e.push("snptext="+encodeURIComponent(t.text))}else if(t.chr){e.push("chr="+t.chr);e.push("start="+t.start);e.push("stop="+t.stop);if(t.variant_filter)e.push("variant_filter="+encodeURIComponent(JSON.stringify(t.variant_filter)))}return await a("/termdb?"+e.join("&"))}async get_variantFilter(){return await a("termdb",{body:{getvariantfilter:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getSamplesPerFilter(t){return await a("termdb",{body:{for:"getSamplesPerFilter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,filters:t.filters}})}async getAnnotatedSampleData(t,e={}){const s=this.mayGetAuthHeaders("termdb");if(!s)return;const i=F(t.filter);const n={};const r={byTermId:e.byTermId||{},bySampleId:e.bySampleId||{}};const o=[];const l=new Set;const c=t.isHierCluster?null:t.terms.filter((t=>t.term.type==="geneVariant")).map((t=>t.term.chr?`${t.term.chr}:${t.term.start}-${t.term.stop}`:t.term.name)).sort();const d=t.terms.slice();let p=0;if(t.loadingDiv)t.loadingDiv.html("Updating data ...");while(true){const e=nt(d,t.termsPerRequest||1);if(e.length==0)break;const f={headers:s,credentials:"include",body:{for:"matrix",genome:this.vocab.genome,dslabel:this.vocab.dslabel,terms:e.map(this.getTwMinCopy),filter:i,embedder:window.location.hostname}};if(t.signal)f.signal=t.signal;if(t.filter0)f.body.filter0=t.filter0;if(t.isHierCluster)f.body.isHierCluster=true;if(this.vocab.dslabel=="GDC"&&e.find((t=>t.term.id&&(!t.term?.type||T(t.term.type))))&&c?.length){f.body.currentGeneNames=c}o.push(a("termdb",f,{cacheAs:"decoded"}).then((s=>{if(s.error)throw s.error;if(!s.refs.bySampleId)s.refs.bySampleId={};for(const t of e){for(const e in s.samples){const i=s.samples[e];if(!Object.keys(i).filter((t=>t!="sample")).length)continue;l.add(e);if(!(e in n)){if(!s.refs.bySampleId[e])s.refs.bySampleId[e]={};if(typeof s.refs.bySampleId[e]=="string")s.refs.bySampleId[e]={label:s.refs.bySampleId[e]};const t=s.refs.bySampleId[e];if(!t.label)t.label=e;const i={sample:e,_ref_:t};n[e]=i}if(t.$id in i)n[e][t.$id]=i[t.$id]}for(const t in s.refs.bySampleId){r.bySampleId[t]=s.refs.bySampleId[t]}r.byTermId[t.$id]=t;if(t.$id in s.refs.byTermId){r.byTermId[t.$id]=Object.assign({},r.byTermId[t.$id],s.refs.byTermId[t.$id])}}p++;if(t.loadingDiv)t.loadingDiv.html(`Updating data (${p}/${o.length}) ...`)})))}try{if(t.loadingDiv)t.loadingDiv.html(`Updating data (0/${o.length})`);await Promise.all(o);if(t.loadingDiv)t.loadingDiv.html("")}catch(t){if(typeof t=="string"){t.toLowerCase();if(t.includes("token")||t.includes("jwt")||t.includes("login")||t.includes("sign")||t.includes("auth")||t.includes("credential")){this.tokenVerificationMessage=t}}throw t}try{if(t.loadingDiv)t.loadingDiv.html(`Processing data ...`);const e=t.terms.filter((t=>T(t.term.type))).map((t=>t.$id));const s=[];if(!e.length){s.push(...Object.values(n))}else{for(const t in n){const i=n[t];for(const t in i){if(e.includes(t)){s.push(i);break}}}if(!s.length&&this.termdbConfig?.matrix?.settings?.displayDictRowWithNoValues){s.push(...Object.values(n))}}const i=new RegExp(t.sampleNameFilter||".*");const o={lst:s.filter((t=>l.has(t.sample)&&i.test(t.sample))),refs:r};o.samples=o.lst.reduce(((t,e)=>{t[e.sample]=e;return t}),{});for(const e of t.terms){it(e,o.lst,this.termdbConfig)}return o}catch(t){throw t}}async getTermTypes(t){const e={body:{for:"termTypes",genome:this.vocab.genome,dslabel:this.vocab.dslabel,ids:JSON.stringify(t)}};const s=await a("termdb",e,this.opts.fetchOpts);if(s.error)throw s.error;return s}async getLDdata(t,e){const s={getLDdata:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,ldtkname:t,m:{chr:e.chr,pos:e.pos,ref:e.ref,alt:e.alt}};return await a("termdb",{body:s})}async getScatterData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"scatter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,plotName:t.name,coordTWs:t.coordTWs,filter:F(t.filter),embedder:window.location.hostname};if(t.colorColumn)s.colorColumn=t.colorColumn;if(t.colorTW)s.colorTW=t.colorTW;if(t.shapeTW)s.shapeTW=t.shapeTW;if(t.divideByTW)s.divideByTW=t.divideByTW;if(t.scaleDotTW)s.scaleDotTW=t.scaleDotTW;return await a("termdb",{headers:e,body:s})}async getDefaultBins(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"getDefaultBins",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tw:t.tw,embedder:window.location.hostname};return await a("termdb",{headers:e,body:s})}async getSingleSampleData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"singleSampleData",sampleId:t.sampleId,term_ids:t.term_ids,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const i=await a("termdb",{headers:e,body:s});const n={};if("error"in i)return i;for(const t of i){const e=JSON.parse(t.jsondata);n[t.term_id]={value:t.value,term:e}}return n}async getAllSamples(){const t=this.mayGetAuthHeaders("termdb");const e={for:"getAllSamples",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});return s}async getSamplesByName(t){const e=this.mayGetAuthHeaders("termb");const s={for:"getSamplesByName",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};if(t?.filter)s.filter=t.filter;const i=await a("termdb",{headers:e,body:s});return i}async getProfileFacilities(){const t=this.mayGetAuthHeaders("termb");const e={for:"getProfileFacilities",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});const i=[];for(const t of s)i.push(t.name);return i}async getLowessCurve(t){const e=this.mayGetAuthHeaders("termb");const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,getLowessCurve:1,coords:t.coords};return await a("termdb",{headers:e,body:s})}async getCohortsData(t){const e={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel};return await a("termdb/cohorts",{body:e})}async getMds3queryDetails(){return await a("termdb",{body:{for:"mds3queryDetails",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getMatrixByName(t){return await a("termdb",{body:{for:"matrix",getPlotDataByName:t,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getTopMutatedGenes(t){return await a("gdc/topMutatedGenes",{method:"GET",body:t})}async getTopVariablyExpressedGenes(t){return await a("termdb/topVariablyExpressedGenes",{method:"GET",body:t})}async getTopTermsByType(t){t.genome=this.state.vocab.genome;t.dslabel=this.state.vocab.dslabel;return await a("termdb/getTopTermsByType",{method:"GET",body:t})}async getSampleImages(t){const e={};e.genome=this.state.vocab.genome;e.dslabel=this.state.vocab.dslabel;e.sampleId=t;return await a("termdb/getSampleImages",{method:"GET",body:e})}async convertSampleId(t,e){const s=new Map;const i=[];for(const n of t){const t={};i.push(t);for(const i of e){if(!("to"in i))i.to=i.from;if(!i.convert){t[i.to]=n[i.from];continue}if(!s.has(i))s.set(i,{});const e=s.get(i);const r=n[i.from];if(!e[r])e[r]=[];e[r].push({obj:t,sample:n})}}const n=[];for(const[t,e]of s){const s=Object.keys(e);n.push(await a("termdb",{body:{for:"convertSampleId",inputs:s,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}}).then((i=>{for(const n of s){for(const{sample:s,obj:r}of e[n]){r[t.to]=i.mapping[n]}}})))}await Promise.all(n);return i}}function it(t,e,s){if(t.term.type!="categorical"){return}if(!("$id"in t)){return}const i={};const n={};for(const s of e){if(!s[t.$id])continue;const e=s[t.$id].key;i[e]=1+(i[e]||0);n[e]={key:e,label:e}}t.term.category2samplecount=i;if(s.alwaysRefillCategoricalTermValues||!t.term.values||Object.keys(t.term.values).length==0){t.term.values=n}}function nt(t,e){const s=[];let i=0,n=t.length;while(i<n){i++;const n=t.shift();if(s.find((t=>t.term.type===n.term.type&&(("id"in t.term||"id"in n.term)&&t.term.id===n.term.id||t.term.name===n.term.name)))){t.push(n)}else{s.push(n)}if(s.length>=e)break}return s}class rt{constructor(t){this.Pj=t,this.opts=["@delimit","@errmode"],this.contexts=["@branch","@parent","@root","@self","@values","@key"],this.filters=["@split()","@before()","@join()","@ignore()"],this.post=["@after()","@dist()","@end()"],this.terms=[...this.opts,...this.contexts,...this.filters,...this.post]}setFxn(t,e,s,i){this[t]?s[t]=this[t](i,e,s):e.errors.push(["key","UNRECOGNIZED-RESERVED-"+t])}trueFxn(){return!0}notDefined(t){return void 0===t}}rt.prototype["@split"]=function(t){const e=t.slice(1,-2),s=this.Pj.opts["="][e];if(!s)throw`missing @split() function ${e}`;this.Pj.split=s},rt.prototype["@before"]=function(t,e){const s=t.slice(1,-2),i=this.Pj.opts["="][s];return i||(e.errors.push(["val","MISSING-"+e.term+"-FXN",s]),this.trueFxn)},rt.prototype["@after"]=rt.prototype["@before"],rt.prototype["@done"]=rt.prototype["@before"],rt.prototype["@join"]=function(t,e,s){return(s,i)=>{let n=!0;for(const r in t){const o=t[r].slice(1,-2),a=this.Pj.opts["="][o];if(a){const t=a(s,i,r);t?this.Pj.joins.set(r,t):n=!1}else e.errors.push(["val","MISSING-@join-FXN",o])}return n}},rt.prototype["@dist"]=function(t,e){const s=Array.isArray(t)?t:[t],i={};for(const t of s)i[t]=this.Pj.converter.subs["@"](this.Pj,t);return t=>{t["@dist"]=s=>{for(const n in i){const r=(0,i[n])(null,t);r?Array.isArray(r)?r.includes(s)||r.push(s):t.errors.push([e,"NON-ARRAY-DIST-TARGET",n]):t.errors.push([e,"MISSING-DIST-TARGET",n])}}}},rt.prototype["@ignore"]=function(t,e,s){if(!t["@ignore()"])return e;const i=Array.isArray(t["@ignore()"])||"string"==typeof t["@ignore()"]||"object"!=typeof t["@ignore()"],n=i?{"@":t["@ignore()"]}:t["@ignore()"],r={};for(const t in n){const e=n[t];if(Array.isArray(e))r[t]=t=>e.includes(t);else if("string"==typeof e&&"="==e[0]){const i=this.Pj.opts["="][e.slice(1,-2)];i?r[t]=i:(s.errors.push(["val","MISSING-@ignore()-FXN",e]),r[t]=this.notDefined)}else s.errors.push(["val","UNSUPPORTED-@ignore()-VALUE",e]),r[t]=this.notDefined}return i?r:Object.assign({},e,r)};class ot{constructor(t){this.Pj=t,this.allowedKeyTypes=new Set(["string","number"])}getFxn(t,e){const[s,i]=this.Pj.converter.default(this.Pj,t,e,t.term);if(s)return this[i.conv](s,t)}getAllowedKeys(t,e,s,i){if(!Array.isArray(t))return i.errors.push(["key","NON-ARRAY-KEYS",e]),[];const n=[];for(const r of t)s.ignore(r)||(this.allowedKeyTypes.has(typeof r)?n.push(r):i.errors.push([s,"INVALID-RESULT-KEY",e]));return n}}ot.prototype[""]=function(t,e){return(s,i)=>this.getAllowedKeys([t(s,i)],s,e,i)},ot.prototype["()"]=ot.prototype[""],ot.prototype["[]"]=function(t,e){return(s,i)=>this.getAllowedKeys(t(s,i),s,e,i)},ot.prototype["(]"]=ot.prototype["[]"];class at{constructor(t){this.Pj=t}getFxn(t,e){return this[this.getValType(t.templateVal)+"Filler"](t,e,t.templateVal)}getValType(t){return"string"==typeof t?"str":Array.isArray(t)?"arr":t&&"object"==typeof t?"obj":"default"}strFiller(t,e,s,i){const[n,r]=this.Pj.converter.default(this.Pj,t,e,s);if(!n)return;const o=(i||r.aggr)+","+r.conv;return o in this?this[o](n,t):void 0}arrFiller(t,e,s){const i=this.getValType(s[0]);return"str"==i?this.strFiller(t,e,s[0],"[]"):"arr"==i?this["[[,]]"](s[0],t):"obj"==i?this["[{}]"](s[0],t):this.defaultFiller(t,e,s)}objFiller(t,e,s){return this.Pj.parseTemplate(s,t.inheritedIgnore,t.lineage),(t,e,i)=>{this.Pj.setResultContext("{}",e,i),this.Pj.processRow(t,s,i[e])}}defaultFiller(t,e,s){const i=JSON.stringify(s);return(t,e,s)=>{s[e]=JSON.parse(i)}}getArrSeed(t){const e=t.templateVal&&t.templateVal.length>1?t.templateVal[1]:1;if("set"==e)return(t,e,s)=>{e in t?Array.isArray(t[e])&&(t[e]=new Set(t[e])):t[e]=new Set,t[e].add(s)};if(0==e)return(t,e,s)=>{e in t||(t[e]=[]),t[e].push(s)};if(this.isNumeric(e)){const t=new Map;return(s,i,n)=>{i in s||(s[i]=[]),t.has(s[i])||t.set(s[i],new Map);const r=t.get(s[i]);r.has(n)||r.set(n,0);const o=r.get(n);o<e&&(s[i].push(n),r.set(n,o+1))}}}isNumeric(t){return!isNaN(parseFloat(t))&&isFinite(t)&&""!==t}}at.prototype[","]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);e.ignore(o,i,s)||(n[i]=o)}},at.prototype[",()"]=at.prototype[","],at.prototype[",[]"]=at.prototype[","],at.prototype[",(]"]=at.prototype[","],at.prototype["[],"]=function(t,e){const s=this.getArrSeed(e);if(s)return(i,n,r,o)=>{const a=t(i,o);e.ignore(a,n,i,o)||s(r,n,a)};e.errors.push(["val","INVALID-[]-OPTION"])},at.prototype["[],()"]=at.prototype["[],"],at.prototype["[],[]"]=function(t,e){const s=this.getArrSeed(e);return(i,n,r,o)=>{const a=t(i,o);if(Array.isArray(a))for(const t of a)e.ignore(t,n,i,o)||s(r,n,t);else o.errors.push([e,"NON-ARRAY-VALS",i])}},at.prototype["[],(]"]=at.prototype["[],[]"],at.prototype["[{}]"]=function(t,e){this.Pj.parseTemplate(t,e.inheritedIgnore,e.lineage);const s=e.templateVal&&e.templateVal.length>1?e.templateVal[1]:"";if(!s)return(e,s,i)=>{this.Pj.setResultContext("[]",s,i);const n=this.Pj.setResultContext("{}",i[s].length,i[s]);this.Pj.processRow(e,t,n)};if("string"==typeof s){const[i,n]=this.Pj.converter.default(this.Pj,Object.assign({},{templateVal:s}),e.inheritedIgnore,s);return n.aggr||n.skip||n.timing?void e.errors.push(["val","INVALID-[{}]-OPTION-TOKEN"]):(n,r,o,a)=>{const l=this.Pj.setResultContext("[]",r,o,!0),c=this.Pj.contexts.get(l).tracker,d=i(n,a),p="]"==s.slice(-1)?d:[d];if(Array.isArray(p))for(const e of p)if(c.has(e))this.Pj.processRow(n,t,c.get(e));else{const s=this.Pj.setResultContext("{}",l.length,l,!1,e,n,t);s&&(c.set(e,s),this.Pj.processRow(n,t,s))}else a.errors.push([e,"NON-ARRAY-VALS",n])}}e.errors.push(["val","INVALID-[{}]-OPTION"])},at.prototype["[[,]]"]=function(t,e){const s=[];for(const i of t){const t=Object.assign({},e,{templateVal:i});s.push(this.getFxn(t,e.inheritedIgnore))}return"map"!=(e.templateVal[1]?e.templateVal[1]:"")?(t,e,i)=>{e in i||(i[e]=[]);const n=[];for(const e in s)s[+e](t,+e,n);i[e].push(n)}:(t,e,i)=>{e in i?i[e]instanceof Map||(i[e]=new Map(i[e])):i[e]=new Map;const n=[];s[0](t,0,n),i[e].has(n[0])&&(n[1]=i[e].get(n[0])),s[1](t,1,n),i[e].set(n[0],n[1])}},at.prototype["+,"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?n[i]+=+o:r.errors.push([e,"NON-NUMERIC-INCREMENT",s]))}},at.prototype["+,()"]=at.prototype["+,"],at.prototype["+,[]"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);if(Array.isArray(o))for(const t of o)e.ignore(t,i,s,r)||(this.isNumeric(t)?n[i]+=+t:r.errors.push([e,"NON-NUMERIC-INCREMENT",s]));else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["+,(]"]=at.prototype["+,[]"],at.prototype["-,"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?n[i]+=-o:r.errors.push([e,"NON-NUMERIC-DECREMENT",s]))}},at.prototype["-,()"]=at.prototype["-,"],at.prototype["-,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o)){i in n||(n[i]=0);for(const t of o)e.ignore(t,i,s,r)||(n[i]+=-t)}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["-,(]"]=at.prototype["-,[]"],at.prototype["<,"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(e.ignore(o,i,s,r))return;const a=+o;this.isNumeric(a)?i in n?n[i]<a&&(n[i]=a):n[i]=a:r.errors.push([e,"NON-NUMERIC-THAN",s])}},at.prototype["<,()"]=at.prototype["<,"],at.prototype["<,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o))for(const t of o){if(e.ignore(t,i,s,r))return;if(!this.isNumeric(t))return void r.errors.push([e,"NON-NUMERIC-THAN",s]);const o=+t;i in n?n[i]<o&&(n[i]=o):n[i]=o}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["<,(]"]=at.prototype["<,[]"],at.prototype[">,"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?i in n?n[i]>o&&(n[i]=o):n[i]=o:r.errors.push([e,"NON-NUMERIC-THAN",s]))}},at.prototype[">,()"]=at.prototype[">,"],at.prototype[">,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o))for(const t of o){if(e.ignore(t,i,s,r))return;if(!this.isNumeric(t))return void r.errors.push([e,"NON-NUMERIC-THAN",s]);const o=+t;i in n?n[i]>o&&(n[i]=o):n[i]=o}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype[">,(]"]=at.prototype[">,[]"];class lt{constructor(t){this.Pj=t,this.allErrSet=new Set,this.allErrObj=Object.create(null),this.mode={input:"{}",result:"{}-",root:"",console:"{}"},this.modeKeys=["input","result","root","console"],this.setMode()}setMode(t={}){Array.isArray(t)?this.modeKeys.forEach(((e,s)=>this.mode[e]=t[s])):"object"==typeof t&&this.modeKeys.forEach((e=>{e in t&&(this.mode[e]=t[e])}))}clear(t={}){this.allErrSet.clear(),this.allErrObj=Object.create(null),this.setMode(t)}markErrors(t,e){if(!e)return;const s="[]"==this.mode.result.slice(0,2)?[]:{};for(const i in e.filler.inputs){const n=e.filler.inputs[i];for(const e of n.errors){const[i,r,o]=e;"key"==i?(this.track(s,e,n.lineage.join(this.Pj.delimit)),this.mode.input&&(t["{{ "+r+" }} "+n.term]=n.templateVal)):"val"==i&&(Array.isArray(n.templateVal)?(this.track(s,e,n.templateVal[0]),this.mode.input&&(t[n.term]=["{{ "+r+" }} ",...n.templateVal])):"string"==typeof n.templateVal?(this.track(s,e,n.templateVal),this.mode.input&&(t[n.term]="{{ "+r+" }} "+n.templateVal)):(this.track(s,e,n.templateVal),this.mode.input&&(t[n.term]="{{ "+r+" }} ")))}}if(e.errors.length){const i={};t["@errors"]=i;for(const t of e.errors){const[e,n,r]=t;if(this.track(s,t,e.term),!this.mode.input)continue;const o="{{ "+n+" }} "+e.term;o in i||(i[o]=0),i[o]+=1}}if(e.filler.errors.length)for(const t of e.filler.errors)this.track(s,t,t[2],!1);Object.keys(s).length&&this.mode.result&&(t["@errors"]=s)}track(t,e,s,i=!0){this.allErrSet.add(e),this.trackAsObj(this.allErrObj,e,s),i&&"-"==this.mode.result.slice(-1)||(Array.isArray(t)?t.push(e):this.trackAsObj(t,e,s))}trackAsObj(t,e,s){const[i,n,r]=e;n in t||(t[n]=Object.create(null)),s in t[n]||(t[n][s]=r?[]:0),r?t[n][s].includes(r)||t[n][s].push(r):t[n][s]+=1}log(){const t=[...this.allErrSet];if(t.length){if(this.mode.root){const e=this.mode.root;this.Pj.tree["@errorsAll"]="[]"==e?t:this.allErrObj}if(this.mode.console){const e=this.mode.console.slice(0,2);console.log("[]"==e?t:this.allErrObj)}}}}function ct(t,e){const s=t.skipSymbols.includes(e[0])?e[0]:"",i=e.slice(s.length,s.length+3),n=t.timeSymbols.includes(i)?i:"",r=s.length+n.length,o=e[r],a=e.slice(-2),l=t.aggrSymbols.includes(o)&&o!=e?o:"",c=t.convSymbols.includes(a)&&a!=e?a:"",d=l&&c?e.slice(r+1,-2):l?e.slice(r+1):c?e.slice(r,-2):s||n?e.slice(r):e,p=t.subsSymbols.includes(d[0])?d[0]:"",f=l+p+c,u=p?d.slice(1):d;return[d,f,{skip:s,time:n,aggr:l,subs:p,stem:u,conv:c,subterm:d},t.steps.indexOf(n)]}const dt={"#":function(t,e,s){t.commentedTerms.has(s)||t.commentedTerms.set(s,[]),t.commentedTerms.get(s).push(e)},"*":function(t,e,s){t.focusTemplate[s.term.slice(1)]=s.templateVal},"":function(t,e,s){return t.valFiller.isNumeric(e)?()=>+e:()=>e},$:function(t,e,s){if("$"==e||e=="$"+t.delimit)return t=>t;if(e.includes(t.delimit)){const s=e.slice(1).split(t.delimit);""==s[0]&&s.shift();const i=(t,e)=>t?t[e]:void 0;return t=>s.reduce(i,t)}{const t=e.slice(1);return e=>e[t]}},"=":function(t,e,s){const i=e.slice(1).split(t.delimit).reduce(((t,e)=>t&&e in t?t[e]:void 0),t.opts["="]);if(i)return t=>i;s.errors.push(["val","MISSING-EXTERNAL-SUBS"])},"@":function(t,e,s){if(!t.reserved.opts.includes(e)){if("@"==e||e=="@"+t.delimit)return(t,e)=>e.self;if(e.includes(t.delimit)){const i=e.split(t.delimit),n=(i,n)=>{if("@"==n[0]&&n.length>1&&!t.reserved.contexts.includes(n))return s.errors.push(["val","UNRECOGNIZED-CONTEXT-"+e,s.lineage.join(".")+"."+n]),[null,null];const[r,o]=i;return r&&n?"@"==n?[o.self,o]:"@values"==n?[Object.values(r),o]:"@"==n[0]?[o[n.slice(1)],t.contexts.get(o[n.slice(1)])]:[r[n],t.contexts.get(r[n])]:[null,null]};return(t,e)=>i.reduce(n,[e.self,e])[0]}if(t.reserved.contexts.includes(e)){const t=e.slice(1);return(e,s)=>s[t]}s.errors.push(["val","UNRECOGNIZED-CONTEXT-"+e])}},"&":function(t,e,s){const i=e.slice(1).split(t.delimit),n=i.shift();if(i.length){if(1==i.length){const e=i[0];return()=>{const s=t.joins.get(n);return s?s[e]:null}}{const e=(t,e)=>t?t[e]:null;t.joins.get(n);return s=>i.reduce(e,t.joins.get(n))}}return()=>t.joins.get(n)}},pt={"":function(t,e,s){return t},"()":function(t,e,s){if("="==s.subs){const i=t();return"function"!=typeof i?void e.errors.push(["val","NOT-A-FUNCTION",s.subs+s.term+s.conv]):i}return(s,i)=>{const n=t(s,i);if("function"==typeof n)return n(s,i);e.errors.push(["val","NOT-A-FUNCTION",s])}}};pt["[]"]=pt[""],pt["(]"]=pt["()"];var ft=Object.freeze({__proto__:null,default:function(t,e,s,i){const[n,r,o]=ct(t,i);if(t.reserved.opts.includes(n))return[];const a=n+o.conv;if(e.ignore=a in s?s[a]:s["@"],o.skip&&"~"!=o.skip)return dt[o.skip](t,n,e),[];if(o.subs in dt){const s=dt[o.subs](t,n,e);return s?[pt[o.conv](s,e,o),o]:[]}return e.errors.push(["val","UNSUPPORTED-SYMBOL-"+o.subs]),[]},parseTerm:ct,subs:dt,conv:pt});class ut{constructor(t={}){this.defaultOpts={template:{},seed:"{}","=":{}},this.opts=Object.assign(this.defaultOpts,t),this.delimit=".",this.subsSymbols=["$","=","@","&"],this.convSymbols=["()","[]","(]"],this.aggrSymbols=["+","-","<",">"],this.timePost=["_0:","_1:","_2:","_3:","_4:","_5:","_6:","_7:","_8:","_9:"],this.timeSymbols=[":__","_:_","__:",...this.timePost],this.skipSymbols=["#","*","~"],this.steps=[":__","","_:_"],this.errors=new lt(this),this.reserved=new rt(this),this.keyFiller=new ot(this),this.valFiller=new at(this),this.commentedTerms=new Map,this.joins=new Map,this.fillers=new Map,this.contexts=new Map,this.temps=new Map,this.refresh()}refresh(t={}){this.times={start:+new Date},Object.assign(this.opts,t),"string"!=typeof this.opts.template&&(this.opts.template=JSON.stringify(this.opts.template));const e=JSON.parse(this.opts.template);this.errors.clear(e["@errmode"]),e["@delimit"]&&(this.delimit=e["@delimit"]),this.commentedTerms.clear(),this.joins.clear(),this.fillers.clear(),this.contexts.clear(),this.temps.clear(),delete this.tree,this.tree=this.setResultContext(this.opts.seed),this.focusTemplate=Object.create(null),this.parseTemplate(e,{"@":this.reserved.notDefined}),this.times.parse=+new Date-this.times.start,Object.keys(this.focusTemplate).length?(this.parseTemplate(this.focusTemplate,{"@":this.reserved.notDefined}),this.template=this.focusTemplate):this.template=e,this.postLoopTerms=Object.create(null),this.done=[],this.opts.data&&this.add(this.opts.data,!1),this.errors.log(this.fillers)}setResultContext(t,e=null,s=null,i=!1,n,r=null,o=null){const a=null!==e&&e in s?s[e]:JSON.parse(t);if(this.contexts.has(a))return a;const l={branch:e,parent:s,context:this.contexts.get(s),self:a,root:this.tree?this.tree:a,joins:this.joins,errors:[],key:n};if(i&&(l.tracker=new Map),r&&o){const t=this.fillers.get(o);if(!t["@before"](r,l))return;if(t["@join"]&&!t["@join"](r,l))return}return this.contexts.set(a,l),null!==e&&(s[e]=a),a}parseTemplate(t,e,s=[]){const i=Object.create(null);i.inputs=Object.create(null),i["@before"]=this.reserved.trueFxn,i["@after"]=this.reserved.trueFxn,i.postTerms={},i.errors=[];const n=this.reserved["@ignore"](t,e,i);i["@ignore"]=n,this.fillers.set(t,i);const r=this.steps.map((t=>[]));for(const e in t){const[o,a,l,c]=ct(this,e),d=t[e],p=i.inputs[e]={term:e,subterm:o,symbols:a,keyTokens:l,templateVal:d,lineage:[...s,e],inheritedIgnore:n,errors:[]};"@()"==a?this.reserved.setFxn(o,p,i,d):(p.keyFxn=this.keyFiller.getFxn(p,n),p.keyFxn&&(p.valFxn=this.valFiller.getFxn(p,n),"__:"==l.time||this.timePost.includes(l.time)?(i.postTerms[l.time]||(i.postTerms[l.time]=[]),i.postTerms[l.time].includes(e)||i.postTerms[l.time].push(e)):r[c].push(e)))}i.steps=r.filter((t=>t.length))}add(t,e=!0){this.times.start||(this.times.start=+new Date),e&&this.errors.clear(),this.joins.clear();for(const e of t)if(this.split)for(const t of this.split(e))this.processRow(t,this.template,this.tree),this.joins.clear();else this.processRow(e,this.template,this.tree),this.joins.clear();this.processResult(this.tree);for(const t of this.timePost)if(this.postLoopTerms[t])for(const e of this.postLoopTerms[t])this.postLoop(e.self,e,t);for(const t of this.done)t.done(t.self,t);for(const[t,e]of this.temps)for(const s of e)delete t[s];this.times.total=+new Date-this.times.start,delete this.times.start,e&&this.errors.log()}processRow(t,e,s){const i=this.contexts.get(s),n=this.fillers.get(e);if(i.filler=n,n["@before"](t,i)&&(!n["@join"]||n["@join"](t,i))){for(const e of n.steps)for(const r of e){const e=n.inputs[r];if(e.keyFxn&&e.valFxn){const n=e.keyFxn(t,i);for(const r of n)e.valFxn(t,r,s,i),"~"==e.keyTokens.skip&&(this.temps.has(s)||this.temps.set(s,new Set),this.temps.get(s).add(r))}}n["@after"](t,i),n["@dist"]&&n["@dist"](i),n["@done"]&&!this.done.includes(i)&&(i.done=n["@done"],this.done.push(i));for(const t in n.postTerms)this.postLoopTerms[t]||(this.postLoopTerms[t]=[]),this.postLoopTerms[t].includes(i)||this.postLoopTerms[t].push(i);return!0}}postLoop(t,e,s="__:"){if(e&&e.filler&&e.filler.postTerms[s])for(const i of e.filler.postTerms[s]){const s=e.filler.inputs[i];if(s.keyFxn&&s.valFxn){const i=s.keyFxn(null,e);for(const n of i)s.valFxn(null,n,t,e)}}}processResult(t){const e=this.contexts.get(t);this.postLoop(t,e,"__:");for(const e in t){const s=t[e];if(s)if(Array.isArray(s)||s instanceof Set||s instanceof Map)for(const t of s)"object"==typeof t&&this.processResult(t);else if("object"==typeof s){const t=this.contexts.get(s);t&&t["@dist"]&&t["@dist"](s),this.processResult(s)}}e&&e.filler&&this.errors.markErrors(t,e)}copyResult(t,e={}){if(arguments.length&&void 0===t)return;const s=arguments.length?t:this.tree;for(const t in s){const i=s[t];if(i instanceof Set||i instanceof Map)e[t]=[...i];else if(Array.isArray(i)){e[t]=[];for(const s of i)if(Array.isArray(s)){const i=[];e[t].push(i),this.copyResult(s,i)}else if(s&&"object"==typeof s){const i=Object.create(null);e[t].push(i),this.copyResult(s,i)}else e[t]=JSON.parse(JSON.stringify(i))}else i&&"object"==typeof i?(e[t]=Object.create(null),this.copyResult(i,e[t])):e[t]=JSON.parse(JSON.stringify(i))}return e}}ut.prototype.converter=ft;function ht(t){const e=t;if(!e||typeof e!=="object")throw"bin schema must be an object";if(!("type"in e))e.type="regular-bin";if(e.type=="custom-bin"){if(!Array.isArray(e.lst))throw"binconfig.lst must be an array";if(!e.lst.length)throw"binconfig.lst must have entries";const t=e.lst[0];const s=e.lst[e.lst.length-1];for(const i of e.lst){if(!("startinclusive"in i)&&!("stopinclusive"in i)){throw"custom bin.startinclusive and/or bin.stopinclusive must be defined"}if(i==t){if("startunbounded"in i&&!i.startunbounded){throw`a custom first bin must not set bin.startunbounded to false`}i.startunbounded=true;if("start"in i){throw"a custom first bin must not set a bin.start value"}if("start_percentile"in i){throw"the first bin must not set a bin.start_percentile value"}if(!("stop"in i)){throw`a custom first bin must define a bin.stop value`}if(!f(i.stop)){throw`a custom first bin.stop value should be numeric`}}else if(i==s){if(!("start"in i)){throw`a custom last bin must define a bin.start value`}if(!f(i.start)){throw`a custom last bin.start must be numeric`}if("stopunbounded"in i&&!i.stopunbounded){throw"a custom last bin must not set bin.stopunbounded to false"}i.stopunbounded=true;if("stop"in i){throw"a custom last bin must not set a bin.stop value"}}else{if(!f(i.start))throw"bin.start must be numeric for a non-first bin";if(!f(i.stop))throw"bin.stop must be numeric for a non-last bin"}}}else if(e.type=="regular-bin"){if(!Number.isFinite(e.bin_size))throw"non-numeric bin_size";if(e.bin_size<=0)throw"bin_size must be greater than 0";if(!e.startinclusive&&!e.stopinclusive){e.startinclusive=1;e.stopinclusive=0}if(!e.first_bin)throw"first_bin{} missing";if(typeof e.first_bin!="object")throw"first_bin{} is not an object";if(!Object.keys(e.first_bin).length)throw"first_bin is an empty object";{const t=e.first_bin;t.startunbounded=true;if(t.stop_percentile){if(!Number.isInteger(t.stop_percentile))throw"first_bin.stop_percentile should be integer";if(t.stop_percentile<=0||t.stop_percentile>=100)throw"first_bin.stop_percentile out of bound (0-100)"}else if(!Number.isFinite(t.stop)){throw"first_bin.stop not a number when stop_percentile is not set"}}if(e.last_bin){const t=e.last_bin;if(t.start_percentile){if(!Number.isInteger(t.start_percentile))throw"last_bin.start_percentile should be integer";if(t.start_percentile<=0||t.start_percentile>=100)throw"last_bin.start_percentile out of bound (0-100)"}else if(!Number.isFinite(t.start)){throw"last_bin.start not a number when start_percentile is not set"}t.stopunbounded=true;if("stop"in t){throw"a regular last bin must not set a bin.stop value"}}}else{throw`invalid binconfig.type="${e.type}"`}}function mt(t,e,s){const i=t;ht(i);if(i.lst){const t=p(i.lst.length);for(const e of i.lst)e.color=t(e.label)}if(i.type=="custom-bin")return JSON.parse(JSON.stringify(i.lst));if(typeof e!="function")throw"summaryfxn required for modules/termdb.bins.js compute_bins()";const n=vt(i);const r=e(n);if(!r||typeof r!=="object")throw"invalid returned value by summaryfxn";i.results={summary:r};if(!i.binLabelFormatter)i.binLabelFormatter=bt(i);const o=Math.floor(r.min*100)/100;const a=Math.ceil(r.max*100)/100;const l=i.first_bin.startunbounded?o:i.first_bin.start_percentile?r["p"+i.first_bin.start_percentile]:i.first_bin.start;let c=a,d,u;if(i.last_bin){c=i.last_bin.stopunbounded?a:i.last_bin.stop_percentile?r["p"+i.last_bin.stop_percentile]:f(i.last_bin.stop)&&i.last_bin.stop<=r.max?i.last_bin.stop:a;d=f(i.last_bin.start_percentile)?r["p"+i.last_bin.start_percentile]:f(i.last_bin.start)?i.last_bin.start:undefined;u=i.last_bin.stopunbounded?null:i.last_bin.stop_percentile?r["p"+i.last_bin.stop_percentile]:f(i.last_bin.stop)?i.last_bin.stop:null}else if(i.lst){const t=i.lst[i.lst.length-1];d=t.start;u="stop"in t&&!t.stopunbounded?t.stop:a;c=u}else{d=a;u=a}const h=f(c);const m=f(d);const b=f(u);if(!h&&!m)return[];const y=[];let g={startunbounded:i.first_bin.startunbounded,start:i.first_bin.startunbounded?undefined:l,stop:f(i.first_bin.stop_percentile)?+r["p"+i.first_bin.stop_percentile]:f(i.first_bin.stop)?+i.first_bin.stop:l+i.bin_size,startinclusive:i.startinclusive,stopinclusive:i.stopinclusive};if(!f(g.stop))throw"the computed first_bin.stop is non-numeric"+g.stop;const v=100;while(h&&g.stop<=c||g.startunbounded&&!y.length||g.stopunbounded){y.push(g);if(g.stop>=c){g.stopunbounded=true;if(y.length>1){delete g.stop}}g.label=yt(g,i,s);if(g.stopunbounded)break;const t=g.stop+i.bin_size;const e=g.stop;g={startinclusive:i.startinclusive,stopinclusive:i.stopinclusive,start:e,stop:b&&(e==d||t>u)?u:m&&t>d&&e!=d?d:t};if(g.stop>=c){g.stop=c;if(i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=1;if(i.last_bin&&i.last_bin.stopinclusive)g.stopinclusive=1}if(m&&g.start==d){if(i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=1}if(g.start>g.stop){if(m&&g.stop==d&&i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=true;else break}if(y.length+1>=v){i.error="max_num_bins_reached";break}}delete i.binLabelFormatter;if(y.length>1){delete y[y.length-1].stop}const _=p(y.length);for(const t of y)t.color=_(t.label);return y}function bt(t){return"rounding"in t?d(t.rounding):t=>t}function yt(t,e,s){const i=e;if(!i.binLabelFormatter)i.binLabelFormatter=bt(i);if(!t.startunbounded&&!t.stopunbounded&&!("startinclusive"in t)&&!("stopinclusive"in t)){if(i.startinclusive)t.startinclusive=true;else if(i.stopinclusive)t.stopinclusive=true}const n=i.use_as=="bins"||t.start;const r=i.use_as=="bins"||t.stop;let o=0;if("label_offset"in i){i.label_offset_ignored="bin_size"in i&&i.bin_size<i.label_offset;if(!i.label_offset_ignored)o=i.label_offset}else if(i.bin_size===1&&i.termtype=="integer"){o=1}if(t.startunbounded){const e=t.stopinclusive?"≤":"<";const n=s?c(r,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(r);return e+n}if(t.stopunbounded||n===r){const e=t.startinclusive?"≥":">";const r=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n);return e+r}if(o&&t.startinclusive&&!t.stopinclusive){if(Number.isInteger(i.bin_size)&&Math.abs(n-r)===o){return""+(s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n))}else{const t=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n);const e=s?c(r-o,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(r-o);return+t>=+e?t.toString():t+" to "+e}}else{const e=t.startinclusive?"":">";const o=t.stopinclusive?"":"<";const a=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):Number.isInteger(n)?n:i.binLabelFormatter(n);const l=s?c(r,s.fromUnit,s.toUnit,s.scaleFactor,true):Number.isInteger(r)?r:i.binLabelFormatter(r);if(+a>=+l){const e=t.startinclusive?"≥":">";return e+a}else{return e+a+" to "+o+l}}}function gt(t,e){const s='<span style="font-family:Times;font-style:italic;">x</span>';let i;const n=yt(t,e);if(t.startunbounded||t.stopunbounded){i=s+" "+n}else if(t.startinclusive){i=n.replace("to <","≤ "+s+" <")}else if(t.stopinclusive){i=n.replace(">","").replace("to","< "+s+" ≤")}return i}function vt(t){const e=[];const s=t.first_bin;if(s&&f(s.start_percentile))e.push(s.start_percentile);if(s&&f(s.stop_percentile))e.push(s.stop_percentile);const i=t.last_bin;if(i&&f(i.start_percentile))e.push(i.start_percentile);if(i&&f(i.stop_percentile))e.push(i.stop_percentile);return e}function _t(t,e,s){const i=!e?[]:e.type=="tvslst"?e.lst:[e];let n=0;for(const r of i){if(r.type=="tvslst"){if(_t(t,r)){n++}}else{const e=r.tvs;let i;if(e.term.type=="geneVariant"){i=s.map((e=>t[e])).filter((t=>t))}else if(e.term.type=="integer"||e.term.type=="float"){i=t[e.term.id]||t[e.term.$id]?.key}else if(e.term.type=="survival"){i=t[e.term.$id]?.key}else{i=t[e.term.id]||t[e.term.$id]?.value}let o;if(e.term.type=="categorical"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));o=t.has(i)}else if(e.term.type=="integer"||e.term.type=="float"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}for(const t of e.ranges){if("value"in t){o=i===t.value;if(o)break}else if(i==t.name){o=true;break}else{if(e.term.values){const t=e.term.values[i.toString()];if(t&&t.uncomputable){continue}}let s,n;if(t.startunbounded){s=true}else if("start"in t){if(t.startinclusive){s=i>=t.start}else{s=i>t.start}}if(t.stopunbounded){n=true}else if("stop"in t){if(t.stopinclusive){n=i<=t.stop}else{n=i<t.stop}}o=s&&n}if(o)break}}else if(e.term.type=="condition"){const t=getPrecomputedKey(e);const s=i&&i[t];if(s){o=Array.isArray(s)?e.values.find((t=>s.includes(t.key))):e.values.find((t=>t.key==s))}}else if(e.term.type=="survival"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));o=t.has(i)}else if(e.term.type=="geneVariant"&&e.legendFilterType=="geneVariant_hard"){const t=e.values[0];o=i.find((e=>{for(const s of e.values){if(s.dt==t.dt&&(!s.origin||s.origin==t.origin)&&t.mclasslst.includes(s.class))return true}}))&&true}else if(e.term.type==y.GENE_EXPRESSION);else if(e.term.type==y.METABOLITE_INTENSITY);else{throw"unknown term type"}if(e.isnot){o=!o}if(o)n++}if(e.join=="or"&&n)return true}if(n==i.length)return true}function wt(t,e){const s=JSON.parse(JSON.stringify(t));if(!s.term1)s.term1=s.term?s.term:{};if(!s.term1_q)s.term1_q={};if(!s.term0)s.term0={};if(!s.term0_q)s.term0_q={};if(!s.term2)s.term2={};if(!s.term2_q)s.term2_q={};if(!s.filter)s.filter={type:"tvslst",join:"",lst:[]};const i=Nt(s,e);return i.tree.results}const jt=JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"_2:maxAcrossCharts":"=maxAcrossCharts()",charts:[{chartId:"@key",total:"+1","_1:maxSeriesTotal":"=maxSeriesTotal()","@done()":"=filterEmptySeries()",serieses:[{total:"+1",seriesId:"@key",max:"<&idVal.dataVal","~values":["&idVal.dataVal",0],"~sum":"+&idVal.dataVal","__:boxplot":"=boxplot()","~samples":["$sample","set"],data:[{dataId:"@key",total:"+1"},"&idVal.dataId[]"]},"&idVal.seriesId[]"]},"&idVal.chartId[]"],"~sum":"+&idVal.seriesVal","~values":["&idVal.seriesVal",0],"__:boxplot":"=boxplot()",refs:{cols:["&idVal.seriesId[]"],colgrps:["-"],rows:["&idVal.dataId[]"],rowgrps:["-"],col2name:{"&idVal.seriesId[]":{name:"@branch",grp:"-"}},row2name:{"&idVal.dataId[]":{name:"@branch",grp:"-"}},"__:useColOrder":"=useColOrder()","__:useRowOrder":"=useRowOrder()","__:bins":"=bins()","@done()":"=sortColsRows()"},"@done()":"=sortCharts()"}});function Nt(t,e){const s={categorical:Tt,integer:St,float:St,undefined:It};return new ut({data:e,seed:`{"values": []}`,template:jt,"=":{idVal(i,n){const[r,o]=s[t.term0.type](i.data,t.term0,t.term0_q,e);const[a,l]=s[t.term1.type](i.data,t.term1,t.term1_q,e);const[c,d]=s[t.term2.type](i.data,t.term2,t.term2_q,e);return{chartId:r,chartVal:o,seriesId:a,seriesVal:l,dataId:c,dataVal:d}},prep(e){return _t(e.data,t.filter)},maxSeriesTotal(t,e){let s=0;for(const t of e.self.serieses){if(t&&t.total>s){s=t.total}}return s},maxAcrossCharts(t,e){let s=0;for(const t of e.self.charts){if(t.maxSeriesTotal>s){s=t.maxSeriesTotal}}return s},boxplot(t,e){if(!e.self.values||!e.self.values.length)return;const s=e.self.values.filter((t=>t!==null&&!isNaN(t)));if(!s.length)return;s.sort(((t,e)=>t-e));const i=At(s.map((t=>({value:+t}))));i.mean=e.self.sum/s.length;let n=0;for(const t of s){n+=Math.pow(t-i.mean,2)}i.sd=Math.sqrt(n/(s.length-1));if(isNaN(i.sd))i.sd=null;return i},numSamples(t,e){return e.self.samples.size},filterEmptySeries(t){const e=t.serieses.filter((t=>t.total));t.serieses.splice(0,t.serieses.length,...e)},sortColsRows(e){if(t.term1_q.orderedLabels){const s=t.term1_q.orderedLabels;e.cols.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}if(t.term2.orderedLabels){const s=t.term2_q.orderedLabels;e.rows.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}},sortCharts(t){},useColOrder(){return t.term1_q.orderedLabels&&t.term1_q.orderedLabels.length>0},useRowOrder(){return t.term2_q.orderedLabels&&t.term2_q.orderedLabels.length>0},bins(){return[t.term0_q,t.term1_q,t.term2_q].map((t=>t.computed_bins))},q(){}}})}function Tt(t,e){const s="id"in e?t[e.id]:"-";const i="id"in e&&f(t[e.id])?+t[e.id]:0;return[[s],i]}function St(t,e,s,i){if(!("id"in e)||!(e.id in t))return[[],undefined];if(!s.computed_bins){const t={};i.map((s=>{if(!f(s.data[e.id]))return;const i=+s.data[e.id];if(!("min"in t)||t.min>i)t.min=i;if(!("max"in t)||t.max<i)t.max=i}));s.computed_bins=mt(s,(e=>t));s.orderedLabels=s.computed_bins.map((t=>t.label))}const n=t[e.id];if(e.values&&n in e.values&&e.values[n].uncomputable){return[[e.values[n].label],undefined]}if(f(t[e.id])){const t=[];for(const e of s.computed_bins){if(e.startunbounded){if(n<e.stop){t.push(e.label)}else if(e.stopinclusive&&n===e.stop){t.push(e.label)}}else if(e.stopunbounded){if(n>e.start){t.push(e.label)}else if(e.stopinclusive&&n===e.start){t.push(e.label)}}else if((n>e.start||n===e.start&&e.startinclusive)&&(n<e.stop||n===e.stop&&e.stopinclusive)){t.push(e.label)}if(t.length)break}return[t,n]}return[[],undefined]}function It(){return[["-"],undefined]}function At(t){const e=t.length;if(e<5){return{out:t}}const s=t[Math.floor(e/2)].value;const i=t[Math.floor(e/4)].value;const n=t[Math.floor(e*3/4)].value;const r=t[Math.floor(e*.05)].value;const o=t[Math.floor(e*.95)].value;t[Math.floor(e*.01)].value;const a=n-i;let l,c;if(a==0){l=0;c=0}else{const s=t.findIndex((t=>t.value>i-a*1.5));l=t[s==-1?0:s].value;const r=t.findIndex((t=>t.value>n+a*1.5));c=t[r==-1?e-1:Math.max(0,r-1)].value}const d=t.filter((t=>t.value<i-a*1.5||t.value>n+a*1.5));return{w1:l,w2:c,p05:r,p25:i,p50:s,p75:n,p95:o,iqr:a,out:d}}function Ot(t,e){if(!e||!e.length){return{lst:Object.keys(t.term.values).map((e=>({key:e,label:t.term.values[e].label,value:e})))}}const s=new ut({data:e,template:JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"&idVal.id":{samplecount:"+1",":__key":"&idVal.id",":__label":"&idVal.id",":__value":"&idVal.id"}}}),"=":{prep(e){return _t(e.data,t.filter)},idVal(e,s){const[i,n]=Tt(e.data,t.term);return{id:i[0],value:n}}}});return{lst:Object.values(s.tree.results)}}var xt=Object.freeze({__proto__:null,getBarchartData:wt,getCategoryData:Ot});function kt(t,e){const s=Number(t);if(Number.isInteger(s))return s;if(Math.abs(s)<1)return Number(s.toPrecision(e));return Number(s.toFixed(e))}function Et(t){let e=t>1?2:Ct(t)+2;return kt(t,e)}function Ct(t){const e=t.toString();const s=e.indexOf(".");if(s===-1||s===e.length-1){return 0}let i=0;for(let t=s+1;t<e.length;t++){if(e[t]==="0"){i++}else if(e[t]>="1"&&e[t]<="9"){break}}return i}function Rt(t,e){t.sort(((t,e)=>t-e));const s=Math.abs(e/100*t.length-1);const i=Number.isInteger(s)?(t[s]+t[s+1])/2:t[Math.ceil(s)];return i}class Dt extends K{constructor(t){super(t);this.datarows=[];if(t.state.vocab.sampleannotation){const e=t.state.vocab.sampleannotation;Object.keys(e).forEach((t=>this.datarows.push({sample:t,data:e[t]})))}}getTermdbConfig(){return{selectCohort:this.vocab.selectCohort,supportedChartTypes:[]}}getTermChildren(t,e){const s=(e||[]).slice().sort().join(",");const i=t.__tree_isroot?null:t.id;return{lst:this.vocab.terms.filter((t=>t.parent_id===i&&(!s.length||s===t.cohortValues.slice().sort.join(","))))}}async getNestedChartSeriesData(t){const e={term1:t.term?t.term.term:{},term1_q:t.term?t.term.q:undefined,term0:t.term0?t.term0.term:undefined,term0_q:t.term0?t.term0.q:undefined,term2:t.term2?t.term2.term:undefined,term2_q:t.term2?t.term2.q:undefined,filter:this.state.termfilter&&this.state.termfilter.filter};return wt(e,this.datarows)}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[s,i]of["term0","term","term2"].entries()){const n=t[i];if(n=="genotype")return;if(!n){if(i=="term")throw`missing plot.term{}`;return}if(e.refs.bins){n.bins=e.refs.bins[s];if(e.refs.q&&e.refs.q[s]){if(!n.q)n.q={};const t=e.refs.q[s];if(t!==n.q){for(const t in n.q)delete n.q[t];Object.assign(n.q,t)}}}if(!n.q)n.q={};if(!n.q.groupsetting)n.q.groupsetting={}}}async findTerm(t,e,s=null){return{lst:this.vocab.terms.filter((s=>s.name.includes(t)&&(!e||e===s.cohortValues.slice().sort.join(","))))}}async getTermInfo(e){const s=this.vocab.find((t=>t.id===e));if(!s)return undefined;return{terminfo:t.info}}async getCohortSampleCount(t){if(!t)return;const e=this.vocab.find((t=>t.id===id));if(!e||!e.cohortValues.includes(t))return;if(!e.samplecount)e.samplecount={};if(!(t in e.samplecount)){e.samplecount[t]=Object.keys(this.vocab.sampleannotation).length}return{samplecount:e.samplecount[t]}}async getCohortsData(t){return null}async getFilteredSampleCount(t){return"TBD"}async getDensityPlotData(t,e,s){if(!this.datarows||!this.datarows.length){const e=this.vocab.terms.find((e=>e.id===t));e.range&&e.range;return{minvalue:e.range&&e.range.start,maxvalue:e.range&&e.range.stop}}const i=[];const n=new Set;let r,o,a=0;let l={};for(const t of this.datarows){if(l[t.sample])continue;const e=t.s||t.data;if(e&&_t(e,s)){l[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in l){if(!(t in this.vocab.sampleannotation[e]))continue;const s=this.vocab.sampleannotation[e][t];if(f(s)){const t=+s;a+=1;if(r===undefined||t<r)r=t;if(o===undefined||t>o)o=t;i.push(t);n.add(t)}}const c=this.vocab.terms.find((e=>e.id==t));const d=40;const p=c.type=="integer"&&o-r<d?o-r:c.type=="float"&&n.size<d?n:d;const h=u().domain([r,o]).range([e.plot_size.xpad,e.plot_size.width-e.plot_size.xpad]);const m=Vt(h.ticks(p))(i);return{density:m,densitymax:m.reduce(((t,e,s)=>s===0||e[1]>t?e[1]:t),0),minvalue:r,maxvalue:o,samplecount:a}}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i=[];const n=[];const r={};for(const t of this.datarows){if(r[t.sample])continue;const e=t.s||t.data;if(e&&_t(e,s)){r[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in r){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";n.push(s)}n.sort(((t,e)=>t-e));for(const t of e){const e=Math.abs(t/100*n.length-1);const s=Number.isInteger(e)?(n[e]+n[e+1])/2:n[Math.ceil(e)];i.push(s)}return{values:i}}async getDescrStats(t,e,s){const i=[];const n={};for(const t of this.datarows){if(n[t.sample])continue;const s=t.s||t.data;if(s&&_t(s,e)){n[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in n){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";i.push(s)}i.sort(((t,e)=>t-e));const r=i.length;const o=i.reduce(((t,e)=>t+e),0);const a=o/r;const l=Rt(i,25);const c=Rt(i,50);const d=Rt(i,75);const p=i.map((t=>(t-a)**2)).reduce(((t,e)=>t+e),0);const f=p/(i.length-1);const u=Math.sqrt(f);const h=Math.min(...i);const m=Math.max(...i);return{values:[{id:"total",label:"n",value:r},{id:"min",label:"Minimum",value:kt(h,2)},{id:"p25",label:"1st quartile",value:kt(l,2)},{id:"median",label:"Median",value:kt(c,2)},{id:"mean",label:"Mean",value:kt(a,2)},{id:"p75",label:"3rd quartile",value:kt(d,2)},{id:"max",label:"Maximum",value:kt(m,2)},{id:"sd",label:"Standard deviation",value:kt(u,2)}]}}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i={};for(const e of t){const t=this.vocab.terms.find((t=>t.id===e));if(t)i[e]=t}return i}async getterm(t){if(!t)throw"getterm: termid missing";return this.vocab.terms.find((e=>e.id==t))}async getCategories(t,e,s=null){const i={term:t,filter:e};const n=Ot(i,this.datarows);return n}getNumericUncomputableCategories(t,e){throw"to be implemented!! getNumericUncomputableCategories"}graphable(t){if(!t)throw"graphable: term is missing";return Q(t).has("plot")}q_to_param(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}}function Vt(t){return e=>{const s=[];for(let e=0;e<t.length;e++)s.push([t[e],0]);for(const i of e){for(let e=1;e<t.length;e++){if(i<=t[e]){s[e-1][1]++;break}}}return s}}function Mt(t){if(t.vocab&&!t.state){t.state={vocab:t.vocab}}if(!t.state)throw"missing opts.state";if(!t.state.vocab){t.state.vocab=t.vocab?t.vocab:{}}const e=t.state.vocab;if(t.state.genome){e.genome=t.state.genome;delete t.state.genome}if(t.state.dslabel){e.dslabel=t.state.dslabel;delete t.state.dslabel}if(e.dslabel){return new st(t)}else if(e.terms){return new Dt(t)}}function Pt(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}function Ft({samples:t,sample_attributes:e}){const s={__root:{id:"root",name:"root",__tree_isroot:true}};const i={};for(const n of t){const t=n.sample;if(!i[t])i[t]={};Object.assign(i[t],n.s);for(const t in n.s){if(!s[t]){const i=e[t]&&e[t].label?e[t].label:t;s[t]={id:t,name:i,parent_id:null,type:e[t].type=="float"?"float":e[t].type=="integer"?"integer":"categorical",values:{},isleaf:true}}const i=s[t];if(!("id"in i))i.id=t;if(!("parent_id"in i))i.parent_id=null;if(!("values"in i))i.values={};if(!("isleaf"in i))i.isleaf=true;if(!i.computableVals&&(i.type=="float"||i.type=="integer")){i.computableVals=[]}const r=n.s[t];if(i.type=="categorical"){i.groupsetting={disabled:true};if(!(r in i.values)){i.values[r]={key:r,label:r}}}else if(i.type=="integer"||i.type=="float"){if(r==="Not Available"&&!(r in i.values)){i.values[r]={label:r,uncomputable:true}}if(!(r in i.values)){if(!f(n.s[t]))throw`non-numeric term value='${r}' for term='${t}'`;n.s[t]=Number(n.s[t]);const e=n.s[t];i.computableVals.push(e)}}else if(i.type=="condition");else{throw"Term type not supported:"+i.type}}}for(const t in s){const e=s[t];if((e.type=="integer"||e.type=="float")&&!e.bins){e.bins={default:H(e.computableVals)};delete e.computableVals}}return{sampleannotation:i,terms:Object.values(s)}}var Lt=Object.freeze({__proto__:null,vocabInit:Mt,q_to_param:Pt,getVocabFromSamplesArray:Ft});const $t={joinWith:["and","or"]};class qt{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,controlsTip:new i({padding:"0px",parent_menu:this.opts.holder.node()&&this.opts.holder.node().closest(".sja_menu_div")}),treeTip:new i({padding:"5px",offsetX:20,offsetY:-34,clearSelector:".sja_term_src_body"})};this.durations={exit:500};this.lastId=0;this.categoryData={};this.pills={};z(this);J(this);this.initUI();this.filter={type:"tvslst",tag:"filterUiRoot",join:"and",in:true,lst:[]};this.promises={}}validateOpts(t){const e=Object.assign({},$t,t);if(!e.holder)throw".holder missing";if(e.vocabApi){this.vocabApi=e.vocabApi}else{if(!e.vocab)throw".vocab missing";if(e.vocab.dslabel){if(!e.vocab.genome)throw"vocab.genome missing"}else{if(!e.vocab.terms)throw"vocab.terms missing"}}if(typeof e.callback!="function")throw".callback() is not a function";if(e.getVisibleRoot&&typeof e.getVisibleRoot!="function")throw".getVisibleRoot() must be a function if set as an option";if(!e.emptyLabel)e.emptyLabel="+NEW";return e}async main(t,e={}){this.promises.postRender=new Promise(((t,e)=>{this.mainResolve=t;this.mainReject=e}));this.numProcessedItems=0;this.numExpectedItems=0;this.opts=Object.assign({},this.opts,e);this.activeCohort=this.opts.activeCohort;this.rawCopy=t;this.rawFilter=JSON.parse(this.rawCopy);this.validateFilter(this.rawFilter);this.filter=M(this.rawFilter,"filterUiRoot");if(!this.filter){this.filter=this.rawFilter;this.filter.tag="filterUiRoot"}await this.resetActiveData(this.filter);this.removeBlankPill();this.dom.newBtn.style("display",this.opts.newBtn?"":this.filter.lst.length==0?"inline-block":"none");this.dom.holder.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay);this.setVocabApi();this.updateUI(this.dom.filterContainer,this.filter);return this.promises.postRender}validateFilter(t){if(!("$id"in t))t.$id=this.lastId++;else if(this.lastId<=t.$id)this.lastId=t.$id+1;if(!("type"in t))throw"missing filter.type";if(t.type!="tvs"&&t.type!="tvslst")throw"invalid filter.type";if(t.type!="tvslst")return;if(!Array.isArray(t.lst))throw"invalid or missing filter.lst[]";if(t.lst.length>1){if(t.join!="and"&&t.join!="or")throw"invalid filter.join value for lst.length > 1"}else if(t.join!==""){throw"filter.join must be an empty string when lst.length < 2"}if(!t.lst.length)t.in=true;for(const[e,s]of t.lst.entries()){this.validateFilter(s)}}resetActiveData(t){if(this.dom.controlsTip.d.style("display")=="none"){this.activeData={item:{},filter:{}}}else{this.activeData={item:D(t,this.activeData.item.$id),filter:D(t,this.activeData.filter.$id),menuOpt:this.activeData.menuOpt}}}refresh(t){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=JSON.parse(JSON.stringify(this.rawFilter));delete e.tag;t.tag="filterUiRoot";const s=V(e,this.filter.$id);if(!s||this.rawFilter.$id===this.filter.$id){this.api.main(t);this.opts.callback(t)}else{const i=s.lst.findIndex((t=>t.$id==this.filter.$id));s.lst[i]=t;this.api.main(e);this.opts.callback(t)}}getId(t){return t.$id}getFilterExcludingPill(t){const e=JSON.parse(JSON.stringify(this.rawFilter));const s=V(e,t);const i=s.lst.findIndex((e=>e.$id===t));if(i==-1)return null;s.lst.splice(i,1);return F(e)}getAdjustedRoot(t,e){const s=JSON.parse(JSON.stringify(this.rawFilter));if(e=="and")return s;const i=M(s,"cohortFilter");const n=V(s,t);if(!n){return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]}}const r=n.lst.findIndex((t=>t.$id===n.$id));if(r==-1)return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]};n.lst.splice(r,1);if(i&&!n.lst.find((t=>t===i))){return F({type:"tvslst",join:"and",lst:[i,n]})}return F(n)}setVocabApi(){if(!this.vocabApi){const t={getState:()=>{const t=JSON.parse(this.rawCopy);const e=M(t,"cohortFilter");if(e&&this.opts.termdbConfig){e.tvs.values=this.activeCohort==-1||this.activeCohort===undefined?[]:this.opts.termdbConfig.selectCohort.values[this.activeCohort].keys.map((t=>({key:t,label:t})))}return{vocab:this.opts.vocab,termfilter:{filter:t},tree:{plots:{}}}}};const e=t.getState();const s=e.vocab||{genome:e.genome,dslabel:e.dslabel};if(!this.vocabApi){this.vocabApi=Mt({app:t,state:{vocab:s}})}}this.vocabApi.main()}updatePromise=function(t=1){if(!this.mainResolve)return;this.numProcessedItems+=t;if(this.numExpectedItems==this.numProcessedItems){this.mainResolve();if(this.bus)this.bus.emit("postRender");delete this.mainResolve}}}class Ut extends qt{constructor(t){super(t);this.type="filter";this.initHolder()}async preApiFreeze(t){t.main=this.main.bind(this);t.getNormalRoot=()=>F(this.rawFilter)}getState(t){return{termfilter:t.termfilter,activeCohort:t.activeCohort}}async main(t=null){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=this.state&&this.state.termfilter;if(!e){this.dom.holder.style("display","none");return}this.dom.holder.style("display","inline-block");const s=JSON.stringify(t||e.filter);super.main(s,{activeCohort:this.state.activeCohort})}initHolder(){const t=this.dom.holder.attr("class","filter_div").style("position","relative").style("width","fit-content").style("margin","10px").style("margin-top","5px").style("display","table").style("border",this.opts.hideLabel?"none":"solid 1px #ddd");if(this.opts.hideLabel){this.dom.filterDiv=t.style("display","inline-block").style("padding","5px 10px")}else{t.append("span").text("Filter").style("padding","0 10px");this.dom.filterDiv=t.append("div").style("display","inline-block").style("padding","5px 10px")}}}const Jt=h(Ut);export{qt as F,b as N,y as T,M as a,Jt as b,q as c,T as d,v as e,V as f,F as g,Q as h,N as i,I as j,S as k,R as l,Ct as m,Ft as n,ut as o,g as p,_t as q,Et as r,E as s,_ as t,yt as u,Mt as v,gt as w,kt as x,xt as y,Lt as z};
|
|
1
|
+
import{aJ as e,aK as s,M as i,q as n,aB as r,aL as o,S as a,aM as l,aN as c,f as d,aF as p,aO as f,l as u,az as h}from"./app-71453429.js";import{r as m}from"./table-1dae543a.js";const b={continuous:"continuous",discrete:"discrete"};const y={GENE_VARIANT:"geneVariant",GENE_EXPRESSION:"geneExpression",CATEGORICAL:"categorical",INTEGER:"integer",FLOAT:"float",SNP_LIST:"snplst",SNP_LOCUS:"snplocus",CONDITION:"condition",SURVIVAL:"survival",SAMPLELST:"samplelst",METABOLITE_INTENSITY:"metaboliteIntensity"};const g={[y.GENE_EXPRESSION]:e,[y.METABOLITE_INTENSITY]:s};const v={DICTIONARY_VARIABLES:"Dictionary Variables",MUTATION_CNV_FUSION:"Mutation/CNV/Fusion",VARIANT_GENOTYPE:"Variant Genotype",DNA_METHYLATION:"DNA Methylation",GENE_DEPENDENCY:"Gene Dependency",GENE_EXPRESSION:"Gene Expression",PROTEIN_EXPRESSION:"Protein Expression",SPLICE_JUNCTION:"Splice Junction",METABOLITE_INTENSITY:"Metabolite Intensity",GSEA:"GSEA",MUTATION_SIGNATURE:"Mutation Signature",SNP_LIST:"SNP List",SNP_LOCUS:"SNP Locus"};const _={[y.CATEGORICAL]:v.DICTIONARY_VARIABLES,[y.CONDITION]:v.DICTIONARY_VARIABLES,[y.FLOAT]:v.DICTIONARY_VARIABLES,[y.INTEGER]:v.DICTIONARY_VARIABLES,[y.SAMPLELST]:v.DICTIONARY_VARIABLES,[y.SURVIVAL]:v.DICTIONARY_VARIABLES,[y.GENE_VARIANT]:v.MUTATION_CNV_FUSION,[y.SNP_LIST]:v.SNP_LIST,[y.SNP_LOCUS]:v.SNP_LOCUS,[y.GENE_EXPRESSION]:v.GENE_EXPRESSION,[y.METABOLITE_INTENSITY]:v.METABOLITE_INTENSITY};const w=new Set([y.SNP_LIST,y.SNP_LOCUS,y.GENE_EXPRESSION,y.GENE_VARIANT,y.METABOLITE_INTENSITY]);const j=new Set([y.INTEGER,y.FLOAT,y.GENE_EXPRESSION,y.METABOLITE_INTENSITY]);function N(t){if(!t)return false;return j.has(t.type)}function T(t){return!S(t)}function S(t){if(!t)throw new Error("Type is not defined");return w.has(t)}function I(t,e){if(!t)throw new Error("First term is not defined ");if(!e)throw new Error("Second term is not defined ");if(t.type!==e.type)return false;if(T(t.type)&&T(e.type)&&t.type!=y.SAMPLELST)return t.id===e.id;switch(t.type){case y.GENE_EXPRESSION:return t.gene==e.gene;case y.METABOLITE_INTENSITY:return t.name==e.name;case y.GENE_VARIANT:return t.gene==e.gene||t.chr==e.chr&&t.start==e.start&&t.stop==e.stop;default:return false}}function A(t){switch(t){case"./tvs.categorical.js":return import("./tvs.categorical-48a51412.js");case"./tvs.condition.js":return import("./tvs.condition-9e77e3b8.js");case"./tvs.density.js":return import("./tvs.density-9fe0c7fd.js");case"./tvs.geneVariant.js":return import("./tvs.geneVariant-1b179327.js");case"./tvs.numeric.js":return import("./tvs.numeric-b4cfc975.js");case"./tvs.samplelst.js":return import("./tvs.samplelst-681358bc.js");case"./tvs.survival.js":return import("./tvs.survival-df35b85b.js");default:return new Promise((function(e,s){(typeof queueMicrotask==="function"?queueMicrotask:setTimeout)(s.bind(null,new Error("Unknown variable dynamic import: "+t)))}))}}class O{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,tip:new i({padding:"5px"})};this.durations={exit:0};k(this);this.categoryData={};this.handlerByType={};this.api={main:this.main.bind(this),showMenu:this.showMenu}}validateOpts(t){if(!t.holder)throw".holder missing";if(!t.vocabApi)throw".vocabApi missing";if(typeof t.callback!="function")throw".callback() is not a function";return t}async main(t={}){this.tvs=t.tvs;this.filter=t.filter;await this.setHandler();await this.updateUI()}async setHandler(){if(!this.tvs||!this.tvs.term)return;const t=this.tvs.term;const e=N(t)?"numeric":t.type;if(!this.handlerByType[e]){try{const t=await A(`./tvs.${e}.js`);this.handlerByType[e]=t.handler}catch(t){throw`error with handler='./tvs.${e}.js': ${t}`}}this.handler=this.handlerByType[e]}}const x=r(O);function k(t){t.updateUI=function(){const e=t.dom.holder;const s=e.selectAll(".tvs_pill").data([t.tvs],(t=>t?.term.id));s.exit().each(t.exitPill);s.each(t.updatePill);s.enter().append("div").attr("class","tvs_pill").style("white-space","nowrap").style("display","inline-block").transition().duration(200).each(t.enterPill)};t.enterPill=async function(){const e=n(this).style("font-size",".9em");e.append("div").attr("class","term_name_btn sja_filter_tag_btn").style("display","inline-block").style("border-radius","6px 0 0 6px").style("padding","6px 6px 3px 6px").html(t.handler.term_name_gen).style("text-transform","uppercase");e.append("div").attr("class","negate_btn").style("cursor","default").style("padding","6px 6px 3px 6px").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(t.tvs.isnot&&t.tvs.term.type!=="geneVariant"?"NOT":"IS"));t.updatePill.call(this)};t.showMenu=e=>{const s=e?e:t.dom.tip;if(t.tvs.term.type!=="geneVariant"){C(s,t.tvs,t)}t.handler.fillMenu(t,s,t.tvs)};t.updatePill=async function(){const e=n(this);const s=e.datum();const i=t.tvs.values&&t.tvs.values.length||t.tvs.ranges&&t.tvs.ranges.length||t.tvs.term.type=="samplelst";e.select(".term_name_btn").html(t.handler.term_name_gen);e.select(".negate_btn").style("display",i?"inline-block":"none").style("background",t.tvs.isnot?"#f4cccc":"#a2c4c9").html(t.handler.getNegateText?.(t)||(s.isnot&&s.term.type!=="geneVariant"?"NOT":"IS"));const r=t.handler.get_pill_label(s);if(!("grade_type"in r))r.grade_type="";const o=e.selectAll(".value_btn").data(r?[r]:[],(t=>t.txt+t.grade_type));o.exit().each(t.removeValueBtn);o.enter().append("div").attr("class","value_btn sja_filter_tag_btn").style("display",i?"inline-block":"none").style("padding","6px 6px 3px 6px").style("border-radius","0 6px 6px 0").style("font-style","italic").html((t=>t.txt)).append("div").attr("class","grade_type_btn").style("display","inline-block").style("margin","0 5px").style("font-size",".6em").style("text-transform","uppercase").html((t=>t.grade_type)).style("opacity",0).transition().duration(200).style("opacity",1)};t.exitPill=async function(e){n(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()};t.makeValueTable=function(e,s,i,n){if(i?.length==0)return e;const r=e.append("div").style("font-size","0.8rem");t.clusionNote=r.append("div").style("font-weight","bold").style("margin","10px 0px 5px 10px").text(`Select 1 or more categories for ${s.isnot?"EXCLUSION":"INCLUSION"}`);const o=r.append("div");const a=Math.max(...i.map((t=>t.samplecount)),0);i.forEach((t=>t.bar_width_frac=Number((1-(a-t.samplecount)/a).toFixed(4))));const l=100;const c=[];const d=[];for(const[t,e]of i.entries()){let i=e.label||e.key;if(e.samplecount)i+=" (n="+e.samplecount+")";const n=l*e.bar_width_frac;const r=`<div style='margin:1px 10px;width:${n}px;height:15px;background-color:#ddd'>`;c.push([{value:i},{html:r}]);let o=false;if(s.term.type=="categorical"||s.term.type=="survival")o=s.values.find((t=>t.key===e.key));else if(s.term.type=="float"||s.term.type=="integer")o=s.ranges.find((t=>String(t.value)===e.value.toString()));else if(s.term.type=="condition")o=s.values.find((t=>String(t.key)===String(e.key)));if(o)d.push(t)}const p=[{label:"tvs"},{label:"bar"}];const f={text:"APPLY",class:"sjpp_apply_btn sja_filter_tag_btn",callback:t=>{if(n)n(t)}};t.tableApi=m({rows:c,columns:p,div:o,maxWidth:"40vw",maxHeight:"40vh",buttons:[f],showHeader:false,striped:false,showLines:false,selectedRows:d,selectedRowStyle:{"text-decoration":s.isnot?"line-through":""}});return o};t.removeValueBtn=function(e,s){const i=n(this.parentNode);const r=i.datum();const o=t.handler.getSelectRemovePos(s,r);n(i.selectAll(".value_select")._groups[0][o]).remove();n(i.selectAll(".or_btn")._groups[0][s]).remove();n(this).style("opacity",1).transition().duration(t.durations.exit).style("opacity",0).remove()}}async function E(t){const e=new O(t);e.tvs={term:t.term};e.filter=t.filter;await e.setHandler();if(e.handler.setTvsDefaults)e.handler.setTvsDefaults(e.tvs);e.handler.fillMenu(e,t.holder,e.tvs)}function C(t,e,s){const i=t.selectAll("label").data([{label:"Exclude",value:"false",checked:e.isnot!==undefined?e.isnot:false}]).enter().append("label").style("margin","0 5px");const n=i.append("input").attr("type","checkbox").attr("name","sja_filter_isnot_input").attr("value",(t=>t.value)).property("checked",(t=>t.checked)).style("vertical-align","top").style("margin-right","3px").on("change",(()=>{e.isnot=n.node().checked;if(s.clusionNote)s.clusionNote.text(`Select 1 or more categories for ${e.isnot?"EXCLUSION":"INCLUSION"}`);if(s.tableApi){s.tableApi.update({selectedRowStyle:{"text-decoration":e.isnot?"line-through":""}})}}));i.append("span").style("margin-right","5px").style("vertical-align","top").html((t=>t.label))}function R(t,e){if(t.type==="tvs"&&t.tvs.term.id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=R(s,e);if(t)return t}}function D(t,e){if(t.$id===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=D(s,e);if(t)return t}}function V(t,e){if(t.$id===e)return t;if(!t.lst)return;for(const s of t.lst){if(s.$id===e)return t;else if(s.type=="tvslst"){const t=V(s,e);if(t)return t}}}function M(t,e){if(t.tag===e)return t;if(t.type!=="tvslst")return;for(const s of t.lst){const t=M(s,e);if(t)return t}}function P(t=[],e="",s=null){const i={type:"tvslst",in:true,join:e,lst:t};if(s!==null&&i.$id!==undefined)i.$id=s;return i}function F(t){if(!t)return P([]);const e=JSON.parse(JSON.stringify(t));const s=L(e);return s.type=="tvslst"?s:P([s])}function L(t){delete t.$id;delete t.tag;if(t.type!="tvslst")return t;const e=t.lst.filter((t=>t.type!=="tvslst"||t.lst.length>0)).map((t=>t.type!=="tvslst"||t.lst.length>1?t:t.lst[0]));e.forEach($);if(!e.length){return P([],"",t.$id)}else if(e.length==1){if(e[0].type==="tvslst"){return L(e[0])}else{return $(e[0])}}else{t.lst=[];for(const s of e){if(s.type==="tvslst"){const e=L(s);if(e.type!=="tvslst"||e.join!=t.join||e.in!=t.in){t.lst.push(e)}else if(e.lst.length){t.lst.push(...e.lst)}}else{t.lst.push(s)}}return t}}function $(t,e=null){delete t.$id;if(typeof e=="function")e(t);if(t.type=="tvslst"){for(const s of t.lst){$(s,e)}}return t}function q(t){if(!t||t.length==0)return;let e=JSON.parse(JSON.stringify(t[0]));if(t.length==1)return e;if(e.lst.length<2){if(e.join!=="")throw'filter.join must be an empty string "" when filter.lst.length < 2';e.join="and"}else if(e.join=="or"){e={type:"tvslst",join:"and",in:true,lst:[e]}}else if(e.join!="and"){throw'filter.join must be either "and" or "or" when .lst length > 1'}for(let s=1;s<t.length;s++){const i=JSON.parse(JSON.stringify(t[s]));if(i.join=="or")e.lst.push(i);else e.lst.push(...i.lst)}if(e.lst.length==1&&e.lst[0].type=="tvs"){e.join=""}return e}let U=0;function J(t){t.initUI=async function(){if(t.opts.newBtn){t.opts.newBtn.on("click.filter",t.displayTreeNew)}else{t.dom.newBtn=t.dom.holder.append("div").attr("class","sja_new_filter_btn sja_menuoption").html(t.opts.emptyLabel).style("display","inline-block").on("click",t.displayTreeNew)}t.dom.filterContainer=t.dom.holder.append("div").attr("class","sja_filter_container");t.dom.holder.selectAll(".sja_filter_add_transformer").data(t.opts.joinWith).enter().append("div").attr("class","sja_filter_add_transformer").style("display",(e=>t.filter&&t.filter.join!=e?"inline-block":"none")).style("margin-left","10px").style("padding","5px").style("border-radius","5px").style("cursor","pointer").html((t=>"+"+t.toUpperCase())).on("click",t.displayTreeNew);t.dom.table=t.dom.controlsTip.clear().d.append("table").style("border-collapse","collapse");const e=[{action:"edit",html:["","Edit","›"],handler:t.editTerm},{action:"join",html:["✚","","›"],handler:t.displayTreeMenu},{action:"switch",html:["","Switch to",""],handler:t.switchJoin},{action:"negate",html:["","Negate",""],handler:t.negateClause},{action:"remove",html:["✖","Remove",""],handler:t.removeTransform}];if(t.opts.vocab){e.splice(1,0,{action:"replace",html:["","Replace","›"],handler:t.displayTreeMenu})}t.dom.table.selectAll("tr").data(e).enter().append("tr").attr("class","sja_menuoption").on("click",t.handleMenuOptionClick).selectAll("td").data((t=>t.html)).enter().append("td").style("padding","5px").style("border-top","solid 1px white").style("color",((t,e)=>t=="✖"?"#a00":e===0?"#0a0":"#111")).style("opacity",((t,e)=>e===0?.8:1)).html((t=>t));t.dom.treeHead=t.dom.treeTip.d.append("div").attr("class","sja_tree_tip_head").style("padding","3px");t.dom.termSrcDiv=t.dom.treeTip.d.append("div").attr("class","sja_term_src_body");t.dom.treeHeadTitle=t.dom.treeHead.append("div");n("body").on("mousedown.sja_filter_"+U++,(e=>{if(["sja_filter_join_label","sja_filter_clause_negate","sja_filter_paren_open","sja_filter_paren_close"].includes(e.target.className))return;t.dom.filterContainer?.selectAll(".sja_filter_grp").style("background-color","transparent");t.removeBlankPill();this.dom.holder?.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay)}))};t.updateUI=async function(e,s){e.datum(s).style("display",!s.lst||!s.lst.length?"none":"inline-block");const i=e.selectAll(":scope > .sja_filter_grp").style("background-color","transparent").data([s],t.getId);i.exit().each(t.removeGrp);i.each(t.updateGrp);i.enter().append("div").attr("class","sja_filter_grp").style("margin","5px").each(t.addGrp);t.updatePromise(0)};t.addGrp=function(e,s){const i=this.parentNode.__data__;n(this).style("display","inline-block");n(this).append("div").attr("class","sja_filter_clause_negate").style("display",i.in?"none":"inline-block").style("color","rgb(102,0,0)").style("font-weight",500).style("cursor","pointer").html("NOT").on("click",t.displayControlsMenu);n(this).append("div").attr("class","sja_filter_paren_open").html("(").style("display","none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);const r=e.type=="tvslst"?e.lst:[e];const o=n(this).selectAll(":scope > .sja_filter_item").data(r,t.getId);o.enter().append("div").attr("class","sja_filter_item").each(t.addItem);if(t.opts.joinWith.length==1){t.dom.last_join_div=n(this).append("div").attr("class","sja_filter_last_join").style("display","inline");t.dom.last_join_label=t.dom.last_join_div.append("div").datum({action:"join",html:["✚","","›"],handler:t.displayTreeMenu}).attr("class","sja_filter_last_join_label").style("padding","0 5px").style("display",i.lst.length?"inline":"none").style("font-weight",500).style("cursor","pointer").html("+"+t.opts.joinWith[0].toUpperCase()).on("click",t.showLastJoinBlank);n("body").on("mousedown.sja_filter_last_join",(()=>{t.dom.last_join_label.style("display","inline")}))}n(this).append("div").attr("class","sja_filter_paren_close").style("padding","0 5px").html(")").style("display","none").style("font-weight",500).style("font-size","24px").style("cursor","pointer").on("click",t.displayControlsMenu);n(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||r.length<2?"none":!i.in||r.length>1&&i.tag!="filterUiRoot"?"inline-block":"none")};t.updateGrp=function(e,s){const i=this.parentNode.__data__;n(this).select(":scope > .sja_filter_clause_negate").style("display",i.in?"none":"inline-block");const r=e.type=="tvslst"?e.lst:[e];n(this).selectAll(":scope > .sja_filter_paren_open, :scope > .sja_filter_paren_close").style("display",t.opts.joinWith.length<2||r.length<2?"none":!i.in||r.length>1&&i.tag!="filterUiRoot"?"inline-block":"none");const o=n(this).selectAll(":scope > .sja_filter_item").data(r,t.getId);o.exit().each(t.removeItem);o.each(t.updateItem);o.enter().insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_item").each(t.addItem);n(this).selectAll(":scope > .sja_filter_item").sort(((t,e)=>r.indexOf(t)-r.indexOf(e)));if(t.dom.last_join_label){t.dom.last_join_div.datum(i);this.insertBefore(t.dom.last_join_div.node(),n(this).select(":scope > .sja_filter_paren_close").node());t.dom.last_join_label.style("display","inline")}};t.removeGrp=function(e){t.numExpectedItems+=1;if(e.type=="tvslst"){for(const s of e.lst){if(s.lst)t.removeGrp(s);else{delete t.pills[s.$id]}}}else{delete t.pills[e.$id]}if(this instanceof Node){n(this).selectAll("*").on("click",null);n(this).on("click",null).remove()}t.updatePromise()};t.addItem=async function(e,s){const i=this.parentNode.__data__;if(e.type=="tvslst"){t.updateUI(n(this),e);t.addJoinLabel(this,i,e);return}t.numExpectedItems+=1;const r=n(this).style("display","inline-block").style("position","relative").style("white-space","nowrap").append("div").attr("class","sja_pill_wrapper").style("display","inline-block").style("margin",t.opts.joinWith.length>1?"":"2px").on("click",e.renderAs==="htmlSelect"?null:t.displayControlsMenu);t.addJoinLabel(this,i,e);if(e.renderAs=="htmlSelect"){const s=B(t,e);const n=r.append("select").on("change",(function(){const n=JSON.parse(JSON.stringify(t.filter));const r=D(n,i.$id);const o=i.lst.indexOf(e);if(o==-1)return;const a=+this.value;const l=JSON.parse(JSON.stringify(e));const c="keys"in s[a]?s[a].keys:[s[a].key];l.tvs.values=c.map((t=>({key:t,label:t})));r.lst[o]=l;t.refresh(n)}));const o=G(t,e);n.selectAll("option").data(s).enter().append("option").property("value",((t,e)=>e)).property("selected",((t,e)=>e==o)).html((t=>t.shortLabel?t.shortLabel:t.label?t.label:t.key))}else{const s=await x({vocabApi:t.vocabApi,holder:r,debug:t.opts.debug,getCategoriesArguments:t.opts.getCategoriesArguments,callback:s=>{const n=JSON.parse(JSON.stringify(t.filter));const r=D(n,i.$id);const o=i.lst.indexOf(e);if(o==-1)return;const a=r.lst.findIndex((t=>t.$id==e.$id));if(a==-1)r.lst[o]={$id:e.$id,type:"tvs",tvs:s};else r.lst[a].tvs=s;t.refresh(n)}});t.pills[e.$id]=s;await s.main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.updateItem=async function(e,s){const i=this.parentNode.__data__;n(this).select(":scope > .sja_filter_join_label").style("display",t.opts.joinWith.length>1&&i.lst.indexOf(e)<i.lst.length-1?"inline-block":"none").style("margin",t.opts.joinWith.length>1?"":"2px").html(i.join=="and"?"AND":"OR");if(e.type=="tvslst"){t.updateUI(n(this),e)}else if(e.renderAs==="htmlSelect"){t.numExpectedItems+=1;n(this).select("select").property("value",""+G(t,e))}else{if(!t.pills[e.$id])return;t.numExpectedItems+=1;await t.pills[e.$id].main({tvs:e.tvs,filter:t.getFilterExcludingPill(e.$id)})}t.updatePromise()};t.removeItem=function(e){delete t.pills[e.$id];n(this).on("click",null).remove()};t.addJoinLabel=function(e,s,i){const r=s.lst.findIndex((t=>t.$id===i.$id));n(e).append("div").attr("class","sja_filter_join_label").style("display",t.opts.joinWith.length>1&&s.lst.length>1&&i&&r!=-1&&r<s.lst.length-1?"inline-block":"none").style("width","50px").style("padding","5px").style("border","none").style("border-radius","5px").style("text-align","center").style("cursor","pointer").html(s.lst.length<2?"":s.join=="and"?"AND":"OR").on("click",t.displayControlsMenu)};t.updateJoinLabel=function(e){const s=this.parentNode.parentNode.parentNode.__data__;const i=s.lst.findIndex((t=>t.$id===e.$id));n(this).style("display",t.opts.joinWith.length>1&&s.lst.length>1&&e&&i!=-1&&i<s.lst.length-1?"inline-block":"none")};t.getAddTransformerBtnDisplay=function(e){if(t.opts.joinWith.length<2){return"none"}else if(t.filter&&t.filter.lst.find((t=>t.tag==="cohortFilter"))){return t.filter.lst.length==1&&e=="and"?"inline-block":"none"}else{return t.filter&&t.filter.lst.length>0&&(t.filter.join!==e||!t.filter.in)?"inline-block":"none"}}}function B(t,e){return e.selectOptionsFrom=="selectCohort"?t.opts.termdbConfig.selectCohort.values:Array.isArray(e.tvs.term.values)?e.tvs.term.values:Object.values(e.tvs.term.values)}function G(t,e){const s=B(t,e);const i=JSON.stringify(e.tvs.values.map((t=>t.key)).sort());const n=s.findIndex((t=>t.keys?i===JSON.stringify(t.keys.sort()):t.key===i));return n}const W="#fff";function z(t){t.displayControlsMenu=function(e){e.stopPropagation();if(!t.activeData)return;const s=this.parentNode.__data__;const i=V(t.filter,s.$id);t.activeData={item:s,filter:i,elem:this};t.removeBlankPill();t.resetGrpHighlights(this,i);if(s.noEdit)t.dom.table.selectAll("tr").filter((t=>t.action=="edit")).style("display","none");t.dom.controlsTip.showunder(this)};t.resetGrpHighlights=function(e,s){const i=e.className;const n=i.includes("join")||i.includes("negate")||i.includes("paren");const r=t.dom.controlsTip.d.selectAll("tr").style("background-color","");r.filter((t=>t.action=="edit"||t.action=="replace")).style("display",n?"none":"table-row");r.filter((t=>t.action=="remove")).style("display",i.includes("_join_")&&s.lst.find((t=>t.tag=="cohortFilter"))?"none":"table-row");r.filter((t=>t.action=="join")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||i.includes("negate")||i.includes("paren")?"none":"table-row").select("td:nth-child(2)").html(n?s.join.toUpperCase():s.join=="and"?"OR":"AND");r.filter((t=>t.action=="switch")).style("display",t.opts.joinWith.length<2||s.$id==t.filter.$id&&s.lst.length==1||!i.includes("_join_")?"none":"table-row").select("td:nth-child(2)").html((t=>s.join=="and"?"Switch to OR":"Switch to AND"));t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(n){if(i.includes("join"))e.parentNode.parentNode.style.backgroundColor="#ee5";else e.parentNode.style.backgroundColor="#ee5"}};t.handleMenuOptionClick=async function(e,s){e.stopPropagation();if(s==t.activeData.menuOpt)return;t.activeData.menuOpt=s;if(t.activeData.elem.className.includes("join")&&s.action!=="join"&&s.action!="switch"){t.activeData.item=t.activeData.filter;t.activeData.filter=V(t.filter,t.activeData.item)}t.resetBlankPill(s.action);t.dom.controlsTip.d.selectAll("tr").style("background-color","");await s.handler(this,s)};t.resetBlankPill=function(e){t.removeBlankPill();t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(e!="join")return;const s=t.dom.last_join_div?t.dom.last_join_div.node():t.activeData.elem.className.includes("join_label")?t.activeData.elem.parentNode.parentNode:t.activeData.item.type=="tvs"||t.activeData.filter===t.filter?t.activeData.elem:t.activeData.elem.parentNode.parentNode;const i=t.opts.joinWith.length===1?t.opts.joinWith[0].toUpperCase():t.activeData.elem.className.includes("join_label")?t.activeData.filter.join.toUpperCase():t.activeData.btn&&typeof t.activeData.btn.__data__==="string"?t.activeData.btn.__data__.toUpperCase():t.activeData.item.type=="tvslst"?t.activeData.filter.join.toUpperCase():t.activeData.filter.join=="or"?"AND":"OR";if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){n(s).insert("div","div").attr("class","sja_filter_paren_open").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html("(")}const r=n(s).insert("div",":scope > .sja_filter_paren_close").attr("class","sja_filter_blank_pill").style("display","inline-block").style("height","20px").style("overflow","visible");r.append("div").style("display","inline-block").style("width","50px").style("text-align","center").html(i);r.append("div").style("position","relative").style("top","-7px").style("display","inline-block").style("width","80px").style("height","22px").style("margin-right","5px").style("border","3px dashed #b8d3ea").style("vertical-align","top").style("background-color","#ee5");if(t.activeData.item.type=="tvs"&&!t.activeData.elem.className.includes("join_label")){n(s).append("div").attr("class","sja_filter_paren_close").style("display",t.opts.joinWith.length>1?"inline-block":"none").style("padding","0 5px").style("font-weight",500).style("font-size","24px").style("cursor","pointer").html(")")}if(s==t.dom.filterContainer.node()){t.dom.filterContainer.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display",t.opts.joinWith.length>1&&t.filter.lst.length>1?"inline-block":"none")}};t.removeBlankPill=function(){t.dom.holder?.selectAll(".sja_filter_blank_pill, .sja_pill_wrapper > .sja_filter_paren_open, .sja_pill_wrapper > .sja_filter_paren_close").remove();if(t.filter.in&&t.filter.lst.filter((t=>t.type==="tvslst")).length<1){t.dom.filterContainer?.selectAll(":scope > .sja_filter_grp > .sja_filter_paren_open, :scope > .sja_filter_grp > .sja_filter_paren_close").style("display","none")}};t.displayTreeNew=async function(e,s){e.stopPropagation();if(t.opts.newBtn&&this.className!=="sja_filter_add_transformer"&&t.filter.lst.length)return;t.dom.filterContainer.selectAll(".sja_filter_grp").style("background-color","transparent");if(t.filter.lst.length>0){t.activeData={item:t.filter,filter:t.filter,elem:t.dom.filterContainer.node(),btn:this}}if(t.filter.lst.length)t.resetBlankPill("join");const i=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(i){t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");t.dom.treeTip.clear().showunder(i)}else{t.dom.treeTip.clear().showunder(this)}const n=t.activeData?t.getAdjustedRoot(t.activeData.filter.$id,s):JSON.parse(t.rawCopy);const r=await import("./app-fb676934.js");r.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,termfilter:{filter:n},tree:{usecase:{target:"filter"}}},tree:{disable_terms:t.activeData&&t.activeData.filter&&t.activeData.filter.lst&&s=="and"?t.activeData.filter.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):[],click_term2select_tvs(e){t.editFilterRoot(s,[{type:"tvs",tvs:e}])}}})};t.editFilterRoot=(e,s)=>{const i=JSON.parse(JSON.stringify(t.filter));if(!i.lst.length){if(s.length>1)i.join="and";i.lst.push(...s);t.refresh(i)}else if(e!="or"&&e!="and"){throw"unhandled new term(s): invalid appender join value"}else{if(!i.join)i.join=e;if(i.join==e&&i.in){if(s.length<2||i.join=="and"){i.lst.push(...s)}else{i.push({type:"tvslst",in:true,join:"and",lst:s})}t.refresh(i)}else if(e=="and"||s.length<2){delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:e,lst:[i,...s]})}else{delete i.tag;t.refresh({tag:"filterUiRoot",type:"tvslst",in:true,join:"or",lst:[i,{type:"tvslst",in:true,join:"and",lst:s}]})}}};t.displayTreeMenu=async function(e,s){n(e).style("background-color",W);t.dom.holder.selectAll(".sja_filter_add_transformer").style("display","none");const i=t.dom.filterContainer.select(".sja_filter_blank_pill").node();if(i){t.dom.controlsTip.hide();t.dom.treeTip.clear().showunder(i)}else if(e.lastChild instanceof HTMLElement){t.dom.treeTip.clear().showunderoffset(e.lastChild)}else{t.dom.treeTip.clear().showunder(e)}const r=t.activeData.filter;const o=await import("./app-fb676934.js");o.appInit({vocabApi:t.vocabApi,holder:t.dom.termSrcDiv,getCategoriesArguments:t.opts.getCategoriesArguments,state:{activeCohort:t.activeCohort,header_mode:"search_only",termfilter:{filter:t.getAdjustedRoot(r.$id,r.join)},tree:{usecase:{target:"filter"}}},tree:{disable_terms:r&&r.lst&&r.join=="and"?r.lst.filter((t=>t.type==="tvs"&&t.tvs.term.type!=="condition")).map((t=>t.tvs.term.id)):!t.activeData.item?[]:t.activeData.item.type=="tvs"?[t.activeData.item.tvs.term.id]:t.activeData.item.lst?t.activeData.item.lst.filter((t=>t.type=="tvs")).map((t=>t.tvs.term.id)):[],click_term2select_tvs:s.action=="replace"?t.replaceTerm:!r.join||!r.lst.length||t.activeData.elem&&t.activeData.elem.className.includes("join")?t.appendTerm:t.subnestFilter}})};t.editTerm=function(e){n(e.parentNode).selectAll("tr").style("background-color",t.highlightEditRow);const s=t.dom.termSrcDiv;const i=t.activeData.item;t.dom.treeTip.clear();t.pills[i.$id].showMenu(s);t.dom.treeTip.showunderoffset(e.lastChild)};t.highlightEditRow=function(t){return t.action=="edit"?W:""};t.handleNotLabelClick=function(e,s){t.activeData={item:this.__data__};t.negateClause()};t.negateClause=function(){const e=JSON.parse(JSON.stringify(t.filter));const s=D(e,t.activeData.item.$id);if(s.type=="tvslst")s.in=!s.in;else if(s.type=="tvs"&&s.tvs?.term?.type=="geneVariant"){const t=s.tvs.values.filter((t=>t.mclassExcludeLst.length>0))[0];const e=t.mclassLst;t.mclassLst=t.mclassExcludeLst;t.mclassExcludeLst=e;s.tvs.isnot=!s.tvs.isnot}else s.tvs.isnot=!s.tvs.isnot;t.refresh(e)};t.replaceTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);const r=n.lst.findIndex((e=>e.$id===t.activeData.item.$id));if(s.length<2||n.join=="and"){n.lst.splice(r,1,...s)}else{n.lst[r]={in:!e.isnot,type:"tvslst",join:"and",lst:s}}t.refresh(i)};t.appendTerm=e=>{const s=Array.isArray(e)?e:[{type:"tvs",tvs:e}];const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);if(s.length<2||n.join=="and"){n.lst.push(...s);if(n.join==""&&t.opts.joinWith.length===1)n.join=t.opts.joinWith[0]}else{n.lst.push({in:true,type:"tvslst",join:"and",lst:s})}t.refresh(i)};t.subnestFilter=e=>{let s;if(Array.isArray(e)){s=e}else{s=[{type:"tvs",tvs:e}]}const i=t.activeData.item;const n=t.activeData.filter;const r=JSON.parse(JSON.stringify(t.filter));const o=D(r,n.$id);const a=o.lst.findIndex((t=>t.$id===i.$id));o.lst[a]={in:true,type:"tvslst",join:n.join=="or"?"and":"or",lst:[i,...s]};t.refresh(r)};t.removeTransform=function(e,s){const i=s.action||typeof s!=="object"?t.activeData.item:D(t.filter,s.$id);const n=V(t.filter,i.$id);if(i==n){t.refresh(P([],"",i.$id));return}const r=n.lst.findIndex((t=>t.$id===i.$id));if(r==-1)return;const o=JSON.parse(JSON.stringify(t.filter));const a=D(o,n.$id);a.lst.splice(r,1);if(a.lst.length===1){const e=V(o,a.$id);if(a.lst[0].type=="tvslst"){if(e==o){a.lst[0].tag="filterUiRoot";t.refresh(a.lst[0])}else{const s=e.lst.findIndex((t=>t.$id==a.$id));if(a.lst[0].join==e.join){e.lst.splice(s,1,...a.lst[0].lst);t.refresh(o)}else{e.lst[s]=a.lst[0];t.refresh(o)}}}else{a.join="";const s=e.lst.findIndex((t=>t.$id===a.$id));e.lst[s]=a.lst[0];if(!a.in){e.lst[s].tvs.isnot=!e.lst[s].tvs.isnot;if(e==o)e.in=true}t.refresh(o)}}else{t.refresh(o)}};t.showLastJoinBlank=function(e,s){e.stopPropagation();const i=t.dom.last_join_div.node();t.dom.last_join_label.style("display","none");const n=this.parentNode.__data__;t.activeData={item:n,filter:n,elem:i};t.resetBlankPill(s.action);t.displayTreeMenu(i,s)};t.switchJoin=function(e,s){const i=JSON.parse(JSON.stringify(t.filter));const n=D(i,t.activeData.filter.$id);if(n.join<2)return;n.join=n.join=="and"?"or":"and";t.refresh(i)}}function H(t,e={}){if(t.find((t=>!Number.isFinite(t))))throw"non-numeric values found";let s;const i=new Set(t);if(i.size===1){const t=[...i][0];s={type:"custom-bin",lst:[{stop:t,stopinclusive:false,startunbounded:true,label:"<"+t},{start:t,stop:t,startinclusive:true,stopinclusive:true,label:"="+t},{start:t,startinclusive:false,stopunbounded:true,label:">"+t}]}}else{t.sort(((t,e)=>t-e));const e=t.length;const i=t[0];const n=t[e-1];const r=(n-i)/8;let o=Math.round(e*.05)-1;if(o<0)o=0;const a=t[o];const l=Math.max(i+r,a);let[c,d,p,f]=Y(r,l,n,i);s={type:"regular-bin",startinclusive:true,bin_size:c,first_bin:{stop:d}};if(p)s.last_bin={start:p};if(f)s.rounding=f}if("format"in e){if(e.format==="string"){return JSON.stringify(s)}else{throw"options are not in the correct format"}}else{return s}}function Y(t,e,s,i){let n,r,o,a;const l=Math.floor(Math.log10(t));if(t>=.1&&t<=2){n=Math.round(t/(1*10**l))*(1*10**l);r=Math.round(e/(1*10**l))*(1*10**l)}else{n=Math.round(t/(5*10**l))*(5*10**l);r=Math.round(e/(5*10**l))*(5*10**l);if(n===0)n=1*10**l;if(r===0)r=1*10**l;if(n===5*10**l&&r===1*10**l)r=5*10**l}if(r<i)r=r*2;const c=r+n*7;if(s>c){o=r+n*6}if(t<1){const t=Math.abs(l);n=Number(n.toFixed(t));r=Number(r.toFixed(t));if(o)o=Number(o.toFixed(t));a="."+t+"f"}if(Object.is(r,-0))r=0;return[n,r,o,a]}class K{constructor(t){this.app=t.app;this.opts=t;this.state=t.state;this.vocab=t.state.vocab;this.currAnnoData={samples:{},refs:{byTermId:{}},lastTerms:[],lastFilter:{}};this.missingCatValsByTermId={};const e=localStorage.getItem("jwtByDsRoute")||`{}`;this.jwtByDsRoute=JSON.parse(e);const s=this.vocab?.dslabel||this.state?.dslabel;this.jwtByRoute=this.jwtByDsRoute[s]||{}}async main(t=null){if(t)Object.assign(this.state,t);else this.state=structuredClone(this.app?.getState?.()||this.opts.state);if(this.state.vocab)this.vocab=this.state.vocab;const e=this.state.dslabel||this.state.vocab.dslabel;this.verifiedToken=!this.state.termdbConfig?.requiredAuth?.length||o(e,"termdb");if(e)await this.maySetVerifiedToken(e)}async maySetVerifiedToken(t){if(this.verifiedToken===true)return this.verifiedToken;let e=this.opts.getDatasetAccessToken?.();if(!e)e=this.jwtByRoute["termdb"];if(this.verifedToken&&e===this.verifiedToken)return this.verifiedToken;try{const s=this.state.termdbConfig?.requiredAuth.find((t=>t.route=="termdb"));if(!s){this.verifiedToken=true;return}if(s.type==="jwt"){if(!e){delete this.verifiedToken;return}const i={[s.headerKey]:e};const n="termdb";if(!i.authorization&&this.jwtByRoute[n])i.authorization=`Bearer ${btoa(this.jwtByRoute[n])}`;const r=await a("/jwt-status",{method:"POST",headers:i,body:{dslabel:t,route:n,embedder:location.hostname}});this.verifiedToken=r.status==="ok"&&e;if(r.error){this.tokenVerificationPayload=r;throw r.error}else{this.sessionId=s.headerKey&&r[s.headerKey]||r["x-sjppds-sessionid"]||r["x-ds-access-token"];delete this.tokenVerificationMessage;delete this.tokenVerificationPayload;if(r.jwt){if(!this.jwtByDsRoute[t]){this.jwtByDsRoute[t]={};this.jwtByRoute=this.jwtByDsRoute[t]}this.jwtByDsRoute[t][r.route]=r.jwt;localStorage.setItem("jwtByDsRoute",JSON.stringify(this.jwtByDsRoute))}}}else{throw`unsupported requiredAuth='${s.type}'`}}catch(t){this.tokenVerificationMessage=t.message||t.reason||t;if(typeof t=="object")console.log(t)}}hasVerifiedToken(){return this.verifiedToken&&true}mayGetAuthHeaders(t=""){const e=this.state.termdbConfig?.requiredAuth;if(!e)return{};if(!this.verifiedToken){this.tokenVerificationMessage=`requires login for this data`;return}const s={};if(e.headerKey)s[e.headerKey]=this.verifiedToken;if(this.sessionId)s["x-sjppds-sessionid"]=this.sessionId;if(t&&this.jwtByRoute[t]){const e=this.jwtByRoute[t];s.authorization=`Bearer ${btoa(e)}`}return s}async trackDsAction({action:t,details:e}){const s={"x-sjppds-sessionid":this.sessionId};const i=this.jwtByRoute.termdb;if(i)s.authorization="Bearer "+btoa(i);await a("/authorizedActions",{method:"POST",credentials:"include",headers:s,body:Object.assign({dslabel:this.vocab.dslabel,action:t,details:e,"x-sjppds-sessionid":this.sessionId})})}getTwMinCopy(t){const e={$id:t.$id,term:{},q:t.q};if(T(t.term?.type)){e.term.id=t.term?.id;e.term.name=t.term?.name;e.term.type=t.term?.type;e.term.values=t.term?.values}else{e.term=t.term}return e}cacheTermQ(t,e){if(!e.reuseId)throw`missing term q.reuseId for term.id='${t.id}'`;this.app.dispatch({type:"cache_termq",termId:t.id,q:e})}async uncacheTermQ(t,e){await this.app.dispatch({type:"uncache_termq",term:t,q:e})}getCustomTermQLst(t){if(t.id){const e=this.state.reuse.customTermQ.byId[t.id]||{};const s=Object.values(e).map((t=>JSON.parse(JSON.stringify(t))));for(let t=s.length+1;t<1e3;t++){const e=`Setting #${t}`;if(!s.find((t=>t.reuseId===e))){s.nextReuseId=e;break}}if(!s.nextReuseId){s.nextReuseId=btoa((+new Date).toString()).slice(10,-3)}return s}else return[]}async addCustomTerm(t){await this.app.dispatch({type:"add_customTerm",obj:t})}async deleteCustomTerm(t){await this.app.dispatch({type:"delete_customTerm",name:t})}async getCustomTerms(){if(!Array.isArray(this.state.customTerms))return[];return this.state.customTerms.map((t=>t.tw))}async addGroup(t){await this.app.dispatch({type:"add_group",obj:t})}async deleteGroup(t){await this.app.dispatch({type:"delete_group",name:t})}async getGroups(){if(!Array.isArray(this.state.groups))return[];return this.state.groups}}const X=new Set(["categorical","integer","float","condition","survival","snplst","snplocus","geneVariant","samplelst","geneExpression",y.METABOLITE_INTENSITY]);function Q(t,e,s){const i=e||{};if(s&&s.usecase&&use.target in s.usecase){return s.usecase[use.target](t,use)}const n=new Set;const r=t.child_types||[];switch(i.target){case"barchart":case"summary":if(i.detail=="term0"&&t.type=="geneVariant"){return n}if(i.detail=="term2"&&t.type=="geneVariant"&&i.term1type=="geneVariant"){return n}if(t.type&&t.type!=="survival")n.add("plot");if(Z(r))n.add("branch");return n;case"matrix":if(t.type)n.add("plot");if(!t.isleaf)n.add("branch");return n;case"table":if(i.detail=="term")n.add("plot");if(r.length>1)n.add("branch");return n;case"scatterplot":if(t.type=="float"||t.type=="integer")n.add("plot");if(tt(r))n.add("branch");return n;case"sampleScatter":if(i.detail=="numeric"){if(N(t)){n.add("plot")}if(tt(r))n.add("branch")}else{if(X.has(t.type))n.add("plot");if(!t.isleaf)n.add("branch")}return n;case"boxplot":if(t.type=="float"||t.type=="integer")n.add("plot");if(i.detail==="term2"&&tt(r))n.add("branch");return n;case"cuminc":if(i.detail=="term"){if(t.type=="condition")n.add("plot");if(r.includes("condition"))n.add("branch");return n}if(i.detail==="term2"){if(t.type&&t.type!="survival")n.add("plot");if(Z(r))n.add("branch");return n}if(i.detail=="term0"){n.add("plot");return n}case"survival":if(i.detail=="term"){if(t.type=="survival")n.add("plot");if(r.includes("survival"))n.add("branch");return n}if(i.detail==="term2"){if(t.type!="survival"){if(t.type)n.add("plot");if(Z(r))n.add("branch")}return n}if(i.detail=="term0"){if(t.type)n.add("plot");if(Z(r))n.add("branch");return n}if(t.isleaf)n.add("plot");else n.add("branch");return n;case"regression":if(i.detail=="outcome"){if(i.regressionType=="linear"){if(t.type=="float"||t.type=="integer")n.add("plot");if(tt(r))n.add("branch");return n}if(i.regressionType=="logistic"){if(t.type&&t.type!="survival")n.add("plot");if(Z(r))n.add("branch");return n}else if(i.regressionType=="cox"){if(t.type=="condition"||t.type=="survival")n.add("plot");if(r.includes("condition")||r.includes("survival"))n.add("branch");return n}}if(i.detail=="independent"){if(t.type=="float"||t.type=="integer"||t.type=="categorical")n.add("plot");if(et(r,["categorical","float","integer"]))n.add("branch");return n}default:if(X.has(t.type))n.add("plot");if(!t.isleaf)n.add("branch");return n}}function Z(t){if(!t.length)return false;return t.length>1||t[0]!="survival"}function tt(t){return t.includes("float")||t.includes("integer")}function et(t,e){for(const s of e){if(t.includes(s))return true}}class st extends K{async getTermdbConfig(){const t=await a("termdb/config",{body:{genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname}});if(t.error)throw t.error;this.termdbConfig=t.termdbConfig||{};return this.termdbConfig}async getTermChildren(t,e){let s;const i={genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(e){i.cohortValues=e.slice().sort().join(",")}if(this.state.treeFilter){i.treeFilter=this.state.treeFilter}if(t.__tree_isroot){i.default_rootterm=1;s=await a("termdb/rootterm",{body:i},this.opts.fetchOpts)}else{i.get_children=1;i.tid=t.id;s=await a("termdb/termchildren",{body:i},this.opts.fetchOpts)}if(s.error)throw s.error;for(const t of s.lst){if(t.type=="integer"||t.type=="float"){if(t.bins.rounding)t.bins.default.rounding=t.bins.rounding;if(t.bins.label_offset&&!t.bins.default.label_offset)t.bins.default.label_offset=t.bins.label_offset}}return s}async getNestedChartSeriesData(t){const e=this.getTdbDataUrl(t);const s=this.mayGetAuthHeaders("termdb");const i=await a(e,{headers:s},this.opts.fetchOpts);if(i.error)throw i.error;if(i.charts){for(const e of i.charts){this.mayFillInMissingCatValues(t.term0,e.chartId,e.total);for(const s of e.serieses){this.mayFillInMissingCatValues(t.term,s.seriesId,s.total);for(const e of s.data){this.mayFillInMissingCatValues(t.term2,e.dataId,e.total)}}}}return i}mayFillInMissingCatValues(t,e,s){if(!e)return;if(!(t?.id in this.missingCatValsByTermId))return;const i=this.missingCatValsByTermId[t.id];if(!(e in i.values)){i.values[e]={key:e,label:e};i.samplecount[e]={samplecount:0,key:e,label:e}}i.samplecount[e].samplecount+=s}getTdbDataUrl(t){const e=[`embedder=${window.location.hostname}`];if(t.chartType=="cuminc")e.push("getcuminc=1");if(t.chartType=="survival")e.push("getsurvival=1");for(const s of["term0","term","term2"]){const i=t[s];if(!i)continue;const n=s=="term"?"term1":s;e.push(n+"_$id="+encodeURIComponent(i.$id));if("id"in i.term&&(!i.term?.type||T(i.term.type))){e.push(n+"_id="+encodeURIComponent(i.term.id))}else{e.push(n+"="+encodeURIComponent(JSON.stringify(i.term)))}if(!i.q)throw"plot."+s+".q{} missing: "+i.term.id;e.push(n+"_q="+Pt(i.q))}if(t.filter){const s=F(t.filter);if(s.lst.length){e.push("filter="+encodeURIComponent(JSON.stringify(s)))}}if(t.ssid){e.push("term2_is_genotype=1","ssid="+t.ssid.ssid,"mname="+t.ssid.mutation_name,"chr="+t.ssid.chr,"pos="+t.ssid.pos)}if("grade"in t)e.push(`grade=${t.grade}`);if("minSampleSize"in t)e.push(`minSampleSize=${t.minSampleSize}`);if(t.term2){const s={term1:t.term.q.hiddenValues?Object.keys(t.term.q.hiddenValues).map((e=>t.term.term.values?.[e]?.label||e)):[],term2:t.term2.q.hiddenValues?Object.keys(t.term2.q.hiddenValues).map((e=>t.term2.term.values?.[e]?.label||e)):[]};e.push(`hiddenValues=${encodeURIComponent(JSON.stringify(s))}`)}if(t.get)e.push("get="+t.get);const s=t.chartType?"termdb":"termdb-barsql";return`/${s}?${e.join("&")}&genome=${this.vocab.genome}&dslabel=${this.vocab.dslabel}`}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[i,n]of["term0","term","term2"].entries()){const r=t[n];const o=!s[n]||s[n].term?.id===r?.term?.id;if(r=="genotype")continue;if(!r){if(n=="term")throw`missing plot.term{}`;continue}if(e.refs.bins){r.bins=e.refs.bins[i];if(e.refs.q&&e.refs.q[i]){if(!r.q)r.q={};const t=e.refs.q[i];if(t!==r.q||!o){if(t.type!=r.q.type||t.mode!=r.q.mode){for(const t in r.q){if(t!="hiddenValues"||!o)delete r.q[t]}}Object.assign(r.q,t)}}}if(!r.q)r.q={};if(!r.q.groupsetting)r.q.groupsetting={}}}async getRegressionData(t){if(!T(t.outcome.term.type))throw"outcome must be dictionary term";const e={id:t.outcome.term.id,q:JSON.parse(JSON.stringify(t.outcome.q))};if(!e.q.mode&&t.regressionType=="linear")e.q.mode="continuous";const s=["mode","scale"];e.refGrp=e.q.mode=="continuous"?"NA":t.outcome.refGrp;if(e.q.mode=="continuous"){for(const t in e.q){if(!s.includes(t))delete e.q[t]}}const i={getregression:1,genome:this.vocab.genome,dslabel:this.vocab.dslabel,regressionType:t.regressionType,outcome:e,independent:t.independent.map((t=>{const e=JSON.parse(JSON.stringify(t.q));delete e.values;delete e.totalCount;if(t.q.mode=="continuous"){for(const t in e){if(!s.includes(t))delete e[t]}}return{id:t.term.id,q:e,type:t.term.type,refGrp:t.q.mode=="continuous"?"NA":t.refGrp,interactions:t.interactions||[],values:t.term.values}}))};const n=F(t.filter);if(n.lst.length)i.filter=n;const r=await a("termdb",{body:i},this.opts.fetchOpts);if(r.error)throw r.error;return r}async findTerm(t,e="",s=null,i=""){const n={genome:this.vocab.genome,dslabel:this.vocab.dslabel,findterm:encodeURIComponent(t),cohortStr:e};if(s)n.usecase=s;if(this.state.treeFilter)n.treeFilter=this.state.treeFilter;if(i)n.targetType=i;const r=await a("termdb",{body:n});if(r.error)throw r.error;const o=t.toUpperCase();const l={equals:[],startsWith:[],startsWord:[],includes:[]};for(const t of r.lst){const e=t.name.toUpperCase();if(e===o)l.equals.push(t);else if(e.startsWith(o))l.startsWith.push(t);else if(e.includes(" "+o))l.startsWord.push(t);else l.includes.push(t)}r.lst=[...l.equals,...l.startsWith,...l.startsWord,...l.includes];return r}async getTermInfo(t){if(!t)throw".getTermInfo: Missing term id";const e=["genome="+this.vocab.genome+"&dslabel="+this.vocab.dslabel+"&getterminfo=1&tid="+t];const s=await a("/termdb?"+e.join("&"),{},this.opts.fetchOpts);if(s.error)throw s.error;return s}async getCohortSampleCount(t){const e={genome:this.vocab.genome,dslabel:this.vocab.dslabel,cohort:t};const s=await a("termdb/cohort/summary",{body:e},this.opts.fetchOpts);if(!s)throw"missing data";if(s.error)throw s.error;return s[0]?.samplecount||s.count||0}async getFilteredSampleCount(t,e){const s={genome:this.vocab.genome,dslabel:this.vocab.dslabel,getsamplecount:e||"count",filter:typeof t=="string"?t:F(t)};const i=await a("termdb",{body:s},this.opts.fetchOpts);if(!i)throw`missing data`;if(i.error)throw i.error;if(e){if(!Array.isArray(i))throw"data is not array";return i}return i[0]?.samplecount||i.count||0}async getViolinPlotData(t,e={}){const s=this.mayGetAuthHeaders("termdb");const i=Object.assign({getViolinPlotData:1,genome:this.vocab.genome,dslabel:this.vocab.dslabel,embedder:window.location.hostname,devicePixelRatio:window.devicePixelRatio,isKDE:"isKDE"in t?t.isKDE:true,ticks:t.ticks,datasymbol:t.datasymbol||"rug",orientation:t.orientation||"horizontal",radius:t.radius||3,svgw:t.svgw||200,unit:t.unit||"abs"},t,e);if(i.filter)i.filter=F(i.filter);const n=await a("termdb/violin",{headers:s,body:i});return n}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i={getpercentile:e,tid:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel};if(s){i.filter=F(s)}return await a("termdb/getpercentile",{body:i})}async getDescrStats(t,e,s){const i={tw:t,genome:this.vocab.genome,dslabel:this.vocab.dslabel,settings:s};if(e){i.filter=F(e)}return await a("/termdb/descrstats",{body:i})}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i=e||this.state.vocab?.dslabel;const n=s||this.state.vocab?.genome;if(!i)throw"getTerms: dslabel missing";if(!n)throw"getTerms: genome missing";const r={genome:n,dslabel:i,ids:t,embedder:window.location.hostname};const o=await a(`termdb/termsbyids`,{body:r});if(o.error)throw"getTerm: "+o.error;for(const t in o.terms){const e=o.terms[t];if(e.type=="categorical"&&!e.values&&!e.groupsetting?.inuse)this.missingCatValsByTermId[e.id]=e}return o.terms}async getterm(t,e=null,s=null){if(!t)throw"getterm: termid missing";const i=await this.getTerms([t],e,s);const n=i[t];if(!n)throw"no term found for "+t;return n}graphable(t){if(!t)throw"graphable: term is missing";return Q(t).has("plot")}async getCategories(t,e,s={}){const i=this.mayGetAuthHeaders();if(t.type=="snplst"||t.type=="snplocus"){const t=Object.assign({validateSnps:1,sumSamples:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel},s);if(e){t.filter=F(e)}return await a("/termdb",{headers:i,body:t})}if(t.category2samplecount){const e=[];for(const s in t.category2samplecount){e.push({key:s,label:t?.values?.[s]?.label||s,samplecount:t.category2samplecount[s]})}return{lst:e}}const n={getcategories:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,term:t,...s};if(e){n.filter=F(e)}try{const t=await a("termdb/categories",{headers:i,body:n});if(t.error)l(t.error);return t}catch(t){window.alert(t.message||t)}}async getNumericUncomputableCategories(t,e){const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tid:t.id};if(e){s.filter=F(e)}try{const t=await a("/termdb/numericcategories",{body:s});if(t.error)throw t.error;return t}catch(t){window.alert(t.message||t)}}async validateSnps(t){const e=["validateSnps=1","genome="+this.state.vocab.genome,"dslabel="+this.state.vocab.dslabel];if(t.text){e.push("snptext="+encodeURIComponent(t.text))}else if(t.chr){e.push("chr="+t.chr);e.push("start="+t.start);e.push("stop="+t.stop);if(t.variant_filter)e.push("variant_filter="+encodeURIComponent(JSON.stringify(t.variant_filter)))}return await a("/termdb?"+e.join("&"))}async get_variantFilter(){return await a("termdb",{body:{getvariantfilter:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getSamplesPerFilter(t){return await a("termdb",{body:{for:"getSamplesPerFilter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,filters:t.filters}})}async getAnnotatedSampleData(t,e={}){const s=this.mayGetAuthHeaders("termdb");if(!s)return;const i=F(t.filter);const n={};const r={byTermId:e.byTermId||{},bySampleId:e.bySampleId||{}};const o=[];const l=new Set;const c=t.isHierCluster?null:t.terms.filter((t=>t.term.type==="geneVariant")).map((t=>t.term.chr?`${t.term.chr}:${t.term.start}-${t.term.stop}`:t.term.name)).sort();const d=t.terms.slice();let p=0;if(t.loadingDiv)t.loadingDiv.html("Updating data ...");while(true){const e=nt(d,t.termsPerRequest||1);if(e.length==0)break;const f={headers:s,credentials:"include",body:{for:"matrix",genome:this.vocab.genome,dslabel:this.vocab.dslabel,terms:e.map(this.getTwMinCopy),filter:i,embedder:window.location.hostname}};if(t.signal)f.signal=t.signal;if(t.filter0)f.body.filter0=t.filter0;if(t.isHierCluster)f.body.isHierCluster=true;if(this.vocab.dslabel=="GDC"&&e.find((t=>t.term.id&&(!t.term?.type||T(t.term.type))))&&c?.length){f.body.currentGeneNames=c}o.push(a("termdb",f,{cacheAs:"decoded"}).then((s=>{if(s.error)throw s.error;if(!s.refs.bySampleId)s.refs.bySampleId={};for(const t of e){for(const e in s.samples){const i=s.samples[e];if(!Object.keys(i).filter((t=>t!="sample")).length)continue;l.add(e);if(!(e in n)){if(!s.refs.bySampleId[e])s.refs.bySampleId[e]={};if(typeof s.refs.bySampleId[e]=="string")s.refs.bySampleId[e]={label:s.refs.bySampleId[e]};const t=s.refs.bySampleId[e];if(!t.label)t.label=e;const i={sample:e,_ref_:t};n[e]=i}if(t.$id in i)n[e][t.$id]=i[t.$id]}for(const t in s.refs.bySampleId){r.bySampleId[t]=s.refs.bySampleId[t]}r.byTermId[t.$id]=t;if(t.$id in s.refs.byTermId){r.byTermId[t.$id]=Object.assign({},r.byTermId[t.$id],s.refs.byTermId[t.$id])}}p++;if(t.loadingDiv)t.loadingDiv.html(`Updating data (${p}/${o.length}) ...`)})))}try{if(t.loadingDiv)t.loadingDiv.html(`Updating data (0/${o.length})`);await Promise.all(o);if(t.loadingDiv)t.loadingDiv.html("")}catch(t){if(typeof t=="string"){t.toLowerCase();if(t.includes("token")||t.includes("jwt")||t.includes("login")||t.includes("sign")||t.includes("auth")||t.includes("credential")){this.tokenVerificationMessage=t}}throw t}try{if(t.loadingDiv)t.loadingDiv.html(`Processing data ...`);const e=t.terms.filter((t=>T(t.term.type))).map((t=>t.$id));const s=[];if(!e.length){s.push(...Object.values(n))}else{for(const t in n){const i=n[t];for(const t in i){if(e.includes(t)){s.push(i);break}}}if(!s.length&&this.termdbConfig?.matrix?.settings?.displayDictRowWithNoValues){s.push(...Object.values(n))}}const i=new RegExp(t.sampleNameFilter||".*");const o={lst:s.filter((t=>l.has(t.sample)&&i.test(t.sample))),refs:r};o.samples=o.lst.reduce(((t,e)=>{t[e.sample]=e;return t}),{});for(const e of t.terms){it(e,o.lst,this.termdbConfig)}return o}catch(t){throw t}}async getTermTypes(t){const e={body:{for:"termTypes",genome:this.vocab.genome,dslabel:this.vocab.dslabel,ids:JSON.stringify(t)}};const s=await a("termdb",e,this.opts.fetchOpts);if(s.error)throw s.error;return s}async getLDdata(t,e){const s={getLDdata:1,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,ldtkname:t,m:{chr:e.chr,pos:e.pos,ref:e.ref,alt:e.alt}};return await a("termdb",{body:s})}async getScatterData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"scatter",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,plotName:t.name,coordTWs:t.coordTWs,filter:F(t.filter),embedder:window.location.hostname};if(t.colorColumn)s.colorColumn=t.colorColumn;if(t.colorTW)s.colorTW=t.colorTW;if(t.shapeTW)s.shapeTW=t.shapeTW;if(t.divideByTW)s.divideByTW=t.divideByTW;if(t.scaleDotTW)s.scaleDotTW=t.scaleDotTW;return await a("termdb",{headers:e,body:s})}async getDefaultBins(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"getDefaultBins",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,tw:t.tw,embedder:window.location.hostname};return await a("termdb",{headers:e,body:s})}async getSingleSampleData(t){const e=this.mayGetAuthHeaders("termdb");const s={for:"singleSampleData",sampleId:t.sampleId,term_ids:t.term_ids,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const i=await a("termdb",{headers:e,body:s});const n={};if("error"in i)return i;for(const t of i){const e=JSON.parse(t.jsondata);n[t.term_id]={value:t.value,term:e}}return n}async getAllSamples(){const t=this.mayGetAuthHeaders("termdb");const e={for:"getAllSamples",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});return s}async getSamplesByName(t){const e=this.mayGetAuthHeaders("termb");const s={for:"getSamplesByName",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};if(t?.filter)s.filter=t.filter;const i=await a("termdb",{headers:e,body:s});return i}async getProfileFacilities(){const t=this.mayGetAuthHeaders("termb");const e={for:"getProfileFacilities",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,embedder:window.location.hostname};const s=await a("termdb",{headers:t,body:e});const i=[];for(const t of s)i.push(t.name);return i}async getLowessCurve(t){const e=this.mayGetAuthHeaders("termb");const s={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel,getLowessCurve:1,coords:t.coords};return await a("termdb",{headers:e,body:s})}async getCohortsData(t){const e={genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel};return await a("termdb/cohorts",{body:e})}async getMds3queryDetails(){return await a("termdb",{body:{for:"mds3queryDetails",genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getMatrixByName(t){return await a("termdb",{body:{for:"matrix",getPlotDataByName:t,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}})}async getTopMutatedGenes(t){return await a("gdc/topMutatedGenes",{method:"GET",body:t})}async getTopVariablyExpressedGenes(t){return await a("termdb/topVariablyExpressedGenes",{method:"GET",body:t})}async getTopTermsByType(t){t.genome=this.state.vocab.genome;t.dslabel=this.state.vocab.dslabel;return await a("termdb/getTopTermsByType",{method:"GET",body:t})}async getSampleImages(t){const e={};e.genome=this.state.vocab.genome;e.dslabel=this.state.vocab.dslabel;e.sampleId=t;return await a("termdb/getSampleImages",{method:"GET",body:e})}async convertSampleId(t,e){const s=new Map;const i=[];for(const n of t){const t={};i.push(t);for(const i of e){if(!("to"in i))i.to=i.from;if(!i.convert){t[i.to]=n[i.from];continue}if(!s.has(i))s.set(i,{});const e=s.get(i);const r=n[i.from];if(!e[r])e[r]=[];e[r].push({obj:t,sample:n})}}const n=[];for(const[t,e]of s){const s=Object.keys(e);n.push(await a("termdb",{body:{for:"convertSampleId",inputs:s,genome:this.state.vocab.genome,dslabel:this.state.vocab.dslabel}}).then((i=>{for(const n of s){for(const{sample:s,obj:r}of e[n]){r[t.to]=i.mapping[n]}}})))}await Promise.all(n);return i}}function it(t,e,s){if(t.term.type!="categorical"){return}if(!("$id"in t)){return}const i={};const n={};for(const s of e){if(!s[t.$id])continue;const e=s[t.$id].key;i[e]=1+(i[e]||0);n[e]={key:e,label:e}}t.term.category2samplecount=i;if(s.alwaysRefillCategoricalTermValues||!t.term.values||Object.keys(t.term.values).length==0){t.term.values=n}}function nt(t,e){const s=[];let i=0,n=t.length;while(i<n){i++;const n=t.shift();if(s.find((t=>t.term.type===n.term.type&&(("id"in t.term||"id"in n.term)&&t.term.id===n.term.id||t.term.name===n.term.name)))){t.push(n)}else{s.push(n)}if(s.length>=e)break}return s}class rt{constructor(t){this.Pj=t,this.opts=["@delimit","@errmode"],this.contexts=["@branch","@parent","@root","@self","@values","@key"],this.filters=["@split()","@before()","@join()","@ignore()"],this.post=["@after()","@dist()","@end()"],this.terms=[...this.opts,...this.contexts,...this.filters,...this.post]}setFxn(t,e,s,i){this[t]?s[t]=this[t](i,e,s):e.errors.push(["key","UNRECOGNIZED-RESERVED-"+t])}trueFxn(){return!0}notDefined(t){return void 0===t}}rt.prototype["@split"]=function(t){const e=t.slice(1,-2),s=this.Pj.opts["="][e];if(!s)throw`missing @split() function ${e}`;this.Pj.split=s},rt.prototype["@before"]=function(t,e){const s=t.slice(1,-2),i=this.Pj.opts["="][s];return i||(e.errors.push(["val","MISSING-"+e.term+"-FXN",s]),this.trueFxn)},rt.prototype["@after"]=rt.prototype["@before"],rt.prototype["@done"]=rt.prototype["@before"],rt.prototype["@join"]=function(t,e,s){return(s,i)=>{let n=!0;for(const r in t){const o=t[r].slice(1,-2),a=this.Pj.opts["="][o];if(a){const t=a(s,i,r);t?this.Pj.joins.set(r,t):n=!1}else e.errors.push(["val","MISSING-@join-FXN",o])}return n}},rt.prototype["@dist"]=function(t,e){const s=Array.isArray(t)?t:[t],i={};for(const t of s)i[t]=this.Pj.converter.subs["@"](this.Pj,t);return t=>{t["@dist"]=s=>{for(const n in i){const r=(0,i[n])(null,t);r?Array.isArray(r)?r.includes(s)||r.push(s):t.errors.push([e,"NON-ARRAY-DIST-TARGET",n]):t.errors.push([e,"MISSING-DIST-TARGET",n])}}}},rt.prototype["@ignore"]=function(t,e,s){if(!t["@ignore()"])return e;const i=Array.isArray(t["@ignore()"])||"string"==typeof t["@ignore()"]||"object"!=typeof t["@ignore()"],n=i?{"@":t["@ignore()"]}:t["@ignore()"],r={};for(const t in n){const e=n[t];if(Array.isArray(e))r[t]=t=>e.includes(t);else if("string"==typeof e&&"="==e[0]){const i=this.Pj.opts["="][e.slice(1,-2)];i?r[t]=i:(s.errors.push(["val","MISSING-@ignore()-FXN",e]),r[t]=this.notDefined)}else s.errors.push(["val","UNSUPPORTED-@ignore()-VALUE",e]),r[t]=this.notDefined}return i?r:Object.assign({},e,r)};class ot{constructor(t){this.Pj=t,this.allowedKeyTypes=new Set(["string","number"])}getFxn(t,e){const[s,i]=this.Pj.converter.default(this.Pj,t,e,t.term);if(s)return this[i.conv](s,t)}getAllowedKeys(t,e,s,i){if(!Array.isArray(t))return i.errors.push(["key","NON-ARRAY-KEYS",e]),[];const n=[];for(const r of t)s.ignore(r)||(this.allowedKeyTypes.has(typeof r)?n.push(r):i.errors.push([s,"INVALID-RESULT-KEY",e]));return n}}ot.prototype[""]=function(t,e){return(s,i)=>this.getAllowedKeys([t(s,i)],s,e,i)},ot.prototype["()"]=ot.prototype[""],ot.prototype["[]"]=function(t,e){return(s,i)=>this.getAllowedKeys(t(s,i),s,e,i)},ot.prototype["(]"]=ot.prototype["[]"];class at{constructor(t){this.Pj=t}getFxn(t,e){return this[this.getValType(t.templateVal)+"Filler"](t,e,t.templateVal)}getValType(t){return"string"==typeof t?"str":Array.isArray(t)?"arr":t&&"object"==typeof t?"obj":"default"}strFiller(t,e,s,i){const[n,r]=this.Pj.converter.default(this.Pj,t,e,s);if(!n)return;const o=(i||r.aggr)+","+r.conv;return o in this?this[o](n,t):void 0}arrFiller(t,e,s){const i=this.getValType(s[0]);return"str"==i?this.strFiller(t,e,s[0],"[]"):"arr"==i?this["[[,]]"](s[0],t):"obj"==i?this["[{}]"](s[0],t):this.defaultFiller(t,e,s)}objFiller(t,e,s){return this.Pj.parseTemplate(s,t.inheritedIgnore,t.lineage),(t,e,i)=>{this.Pj.setResultContext("{}",e,i),this.Pj.processRow(t,s,i[e])}}defaultFiller(t,e,s){const i=JSON.stringify(s);return(t,e,s)=>{s[e]=JSON.parse(i)}}getArrSeed(t){const e=t.templateVal&&t.templateVal.length>1?t.templateVal[1]:1;if("set"==e)return(t,e,s)=>{e in t?Array.isArray(t[e])&&(t[e]=new Set(t[e])):t[e]=new Set,t[e].add(s)};if(0==e)return(t,e,s)=>{e in t||(t[e]=[]),t[e].push(s)};if(this.isNumeric(e)){const t=new Map;return(s,i,n)=>{i in s||(s[i]=[]),t.has(s[i])||t.set(s[i],new Map);const r=t.get(s[i]);r.has(n)||r.set(n,0);const o=r.get(n);o<e&&(s[i].push(n),r.set(n,o+1))}}}isNumeric(t){return!isNaN(parseFloat(t))&&isFinite(t)&&""!==t}}at.prototype[","]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);e.ignore(o,i,s)||(n[i]=o)}},at.prototype[",()"]=at.prototype[","],at.prototype[",[]"]=at.prototype[","],at.prototype[",(]"]=at.prototype[","],at.prototype["[],"]=function(t,e){const s=this.getArrSeed(e);if(s)return(i,n,r,o)=>{const a=t(i,o);e.ignore(a,n,i,o)||s(r,n,a)};e.errors.push(["val","INVALID-[]-OPTION"])},at.prototype["[],()"]=at.prototype["[],"],at.prototype["[],[]"]=function(t,e){const s=this.getArrSeed(e);return(i,n,r,o)=>{const a=t(i,o);if(Array.isArray(a))for(const t of a)e.ignore(t,n,i,o)||s(r,n,t);else o.errors.push([e,"NON-ARRAY-VALS",i])}},at.prototype["[],(]"]=at.prototype["[],[]"],at.prototype["[{}]"]=function(t,e){this.Pj.parseTemplate(t,e.inheritedIgnore,e.lineage);const s=e.templateVal&&e.templateVal.length>1?e.templateVal[1]:"";if(!s)return(e,s,i)=>{this.Pj.setResultContext("[]",s,i);const n=this.Pj.setResultContext("{}",i[s].length,i[s]);this.Pj.processRow(e,t,n)};if("string"==typeof s){const[i,n]=this.Pj.converter.default(this.Pj,Object.assign({},{templateVal:s}),e.inheritedIgnore,s);return n.aggr||n.skip||n.timing?void e.errors.push(["val","INVALID-[{}]-OPTION-TOKEN"]):(n,r,o,a)=>{const l=this.Pj.setResultContext("[]",r,o,!0),c=this.Pj.contexts.get(l).tracker,d=i(n,a),p="]"==s.slice(-1)?d:[d];if(Array.isArray(p))for(const e of p)if(c.has(e))this.Pj.processRow(n,t,c.get(e));else{const s=this.Pj.setResultContext("{}",l.length,l,!1,e,n,t);s&&(c.set(e,s),this.Pj.processRow(n,t,s))}else a.errors.push([e,"NON-ARRAY-VALS",n])}}e.errors.push(["val","INVALID-[{}]-OPTION"])},at.prototype["[[,]]"]=function(t,e){const s=[];for(const i of t){const t=Object.assign({},e,{templateVal:i});s.push(this.getFxn(t,e.inheritedIgnore))}return"map"!=(e.templateVal[1]?e.templateVal[1]:"")?(t,e,i)=>{e in i||(i[e]=[]);const n=[];for(const e in s)s[+e](t,+e,n);i[e].push(n)}:(t,e,i)=>{e in i?i[e]instanceof Map||(i[e]=new Map(i[e])):i[e]=new Map;const n=[];s[0](t,0,n),i[e].has(n[0])&&(n[1]=i[e].get(n[0])),s[1](t,1,n),i[e].set(n[0],n[1])}},at.prototype["+,"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?n[i]+=+o:r.errors.push([e,"NON-NUMERIC-INCREMENT",s]))}},at.prototype["+,()"]=at.prototype["+,"],at.prototype["+,[]"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);if(Array.isArray(o))for(const t of o)e.ignore(t,i,s,r)||(this.isNumeric(t)?n[i]+=+t:r.errors.push([e,"NON-NUMERIC-INCREMENT",s]));else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["+,(]"]=at.prototype["+,[]"],at.prototype["-,"]=function(t,e){return(s,i,n,r)=>{i in n||(n[i]=0);const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?n[i]+=-o:r.errors.push([e,"NON-NUMERIC-DECREMENT",s]))}},at.prototype["-,()"]=at.prototype["-,"],at.prototype["-,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o)){i in n||(n[i]=0);for(const t of o)e.ignore(t,i,s,r)||(n[i]+=-t)}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["-,(]"]=at.prototype["-,[]"],at.prototype["<,"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(e.ignore(o,i,s,r))return;const a=+o;this.isNumeric(a)?i in n?n[i]<a&&(n[i]=a):n[i]=a:r.errors.push([e,"NON-NUMERIC-THAN",s])}},at.prototype["<,()"]=at.prototype["<,"],at.prototype["<,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o))for(const t of o){if(e.ignore(t,i,s,r))return;if(!this.isNumeric(t))return void r.errors.push([e,"NON-NUMERIC-THAN",s]);const o=+t;i in n?n[i]<o&&(n[i]=o):n[i]=o}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype["<,(]"]=at.prototype["<,[]"],at.prototype[">,"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);e.ignore(o,i,s,r)||(this.isNumeric(o)?i in n?n[i]>o&&(n[i]=o):n[i]=o:r.errors.push([e,"NON-NUMERIC-THAN",s]))}},at.prototype[">,()"]=at.prototype[">,"],at.prototype[">,[]"]=function(t,e){return(s,i,n,r)=>{const o=t(s,r);if(Array.isArray(o))for(const t of o){if(e.ignore(t,i,s,r))return;if(!this.isNumeric(t))return void r.errors.push([e,"NON-NUMERIC-THAN",s]);const o=+t;i in n?n[i]>o&&(n[i]=o):n[i]=o}else e.errors.push(["val","NON-ARRAY-VALS",s])}},at.prototype[">,(]"]=at.prototype[">,[]"];class lt{constructor(t){this.Pj=t,this.allErrSet=new Set,this.allErrObj=Object.create(null),this.mode={input:"{}",result:"{}-",root:"",console:"{}"},this.modeKeys=["input","result","root","console"],this.setMode()}setMode(t={}){Array.isArray(t)?this.modeKeys.forEach(((e,s)=>this.mode[e]=t[s])):"object"==typeof t&&this.modeKeys.forEach((e=>{e in t&&(this.mode[e]=t[e])}))}clear(t={}){this.allErrSet.clear(),this.allErrObj=Object.create(null),this.setMode(t)}markErrors(t,e){if(!e)return;const s="[]"==this.mode.result.slice(0,2)?[]:{};for(const i in e.filler.inputs){const n=e.filler.inputs[i];for(const e of n.errors){const[i,r,o]=e;"key"==i?(this.track(s,e,n.lineage.join(this.Pj.delimit)),this.mode.input&&(t["{{ "+r+" }} "+n.term]=n.templateVal)):"val"==i&&(Array.isArray(n.templateVal)?(this.track(s,e,n.templateVal[0]),this.mode.input&&(t[n.term]=["{{ "+r+" }} ",...n.templateVal])):"string"==typeof n.templateVal?(this.track(s,e,n.templateVal),this.mode.input&&(t[n.term]="{{ "+r+" }} "+n.templateVal)):(this.track(s,e,n.templateVal),this.mode.input&&(t[n.term]="{{ "+r+" }} ")))}}if(e.errors.length){const i={};t["@errors"]=i;for(const t of e.errors){const[e,n,r]=t;if(this.track(s,t,e.term),!this.mode.input)continue;const o="{{ "+n+" }} "+e.term;o in i||(i[o]=0),i[o]+=1}}if(e.filler.errors.length)for(const t of e.filler.errors)this.track(s,t,t[2],!1);Object.keys(s).length&&this.mode.result&&(t["@errors"]=s)}track(t,e,s,i=!0){this.allErrSet.add(e),this.trackAsObj(this.allErrObj,e,s),i&&"-"==this.mode.result.slice(-1)||(Array.isArray(t)?t.push(e):this.trackAsObj(t,e,s))}trackAsObj(t,e,s){const[i,n,r]=e;n in t||(t[n]=Object.create(null)),s in t[n]||(t[n][s]=r?[]:0),r?t[n][s].includes(r)||t[n][s].push(r):t[n][s]+=1}log(){const t=[...this.allErrSet];if(t.length){if(this.mode.root){const e=this.mode.root;this.Pj.tree["@errorsAll"]="[]"==e?t:this.allErrObj}if(this.mode.console){const e=this.mode.console.slice(0,2);console.log("[]"==e?t:this.allErrObj)}}}}function ct(t,e){const s=t.skipSymbols.includes(e[0])?e[0]:"",i=e.slice(s.length,s.length+3),n=t.timeSymbols.includes(i)?i:"",r=s.length+n.length,o=e[r],a=e.slice(-2),l=t.aggrSymbols.includes(o)&&o!=e?o:"",c=t.convSymbols.includes(a)&&a!=e?a:"",d=l&&c?e.slice(r+1,-2):l?e.slice(r+1):c?e.slice(r,-2):s||n?e.slice(r):e,p=t.subsSymbols.includes(d[0])?d[0]:"",f=l+p+c,u=p?d.slice(1):d;return[d,f,{skip:s,time:n,aggr:l,subs:p,stem:u,conv:c,subterm:d},t.steps.indexOf(n)]}const dt={"#":function(t,e,s){t.commentedTerms.has(s)||t.commentedTerms.set(s,[]),t.commentedTerms.get(s).push(e)},"*":function(t,e,s){t.focusTemplate[s.term.slice(1)]=s.templateVal},"":function(t,e,s){return t.valFiller.isNumeric(e)?()=>+e:()=>e},$:function(t,e,s){if("$"==e||e=="$"+t.delimit)return t=>t;if(e.includes(t.delimit)){const s=e.slice(1).split(t.delimit);""==s[0]&&s.shift();const i=(t,e)=>t?t[e]:void 0;return t=>s.reduce(i,t)}{const t=e.slice(1);return e=>e[t]}},"=":function(t,e,s){const i=e.slice(1).split(t.delimit).reduce(((t,e)=>t&&e in t?t[e]:void 0),t.opts["="]);if(i)return t=>i;s.errors.push(["val","MISSING-EXTERNAL-SUBS"])},"@":function(t,e,s){if(!t.reserved.opts.includes(e)){if("@"==e||e=="@"+t.delimit)return(t,e)=>e.self;if(e.includes(t.delimit)){const i=e.split(t.delimit),n=(i,n)=>{if("@"==n[0]&&n.length>1&&!t.reserved.contexts.includes(n))return s.errors.push(["val","UNRECOGNIZED-CONTEXT-"+e,s.lineage.join(".")+"."+n]),[null,null];const[r,o]=i;return r&&n?"@"==n?[o.self,o]:"@values"==n?[Object.values(r),o]:"@"==n[0]?[o[n.slice(1)],t.contexts.get(o[n.slice(1)])]:[r[n],t.contexts.get(r[n])]:[null,null]};return(t,e)=>i.reduce(n,[e.self,e])[0]}if(t.reserved.contexts.includes(e)){const t=e.slice(1);return(e,s)=>s[t]}s.errors.push(["val","UNRECOGNIZED-CONTEXT-"+e])}},"&":function(t,e,s){const i=e.slice(1).split(t.delimit),n=i.shift();if(i.length){if(1==i.length){const e=i[0];return()=>{const s=t.joins.get(n);return s?s[e]:null}}{const e=(t,e)=>t?t[e]:null;t.joins.get(n);return s=>i.reduce(e,t.joins.get(n))}}return()=>t.joins.get(n)}},pt={"":function(t,e,s){return t},"()":function(t,e,s){if("="==s.subs){const i=t();return"function"!=typeof i?void e.errors.push(["val","NOT-A-FUNCTION",s.subs+s.term+s.conv]):i}return(s,i)=>{const n=t(s,i);if("function"==typeof n)return n(s,i);e.errors.push(["val","NOT-A-FUNCTION",s])}}};pt["[]"]=pt[""],pt["(]"]=pt["()"];var ft=Object.freeze({__proto__:null,default:function(t,e,s,i){const[n,r,o]=ct(t,i);if(t.reserved.opts.includes(n))return[];const a=n+o.conv;if(e.ignore=a in s?s[a]:s["@"],o.skip&&"~"!=o.skip)return dt[o.skip](t,n,e),[];if(o.subs in dt){const s=dt[o.subs](t,n,e);return s?[pt[o.conv](s,e,o),o]:[]}return e.errors.push(["val","UNSUPPORTED-SYMBOL-"+o.subs]),[]},parseTerm:ct,subs:dt,conv:pt});class ut{constructor(t={}){this.defaultOpts={template:{},seed:"{}","=":{}},this.opts=Object.assign(this.defaultOpts,t),this.delimit=".",this.subsSymbols=["$","=","@","&"],this.convSymbols=["()","[]","(]"],this.aggrSymbols=["+","-","<",">"],this.timePost=["_0:","_1:","_2:","_3:","_4:","_5:","_6:","_7:","_8:","_9:"],this.timeSymbols=[":__","_:_","__:",...this.timePost],this.skipSymbols=["#","*","~"],this.steps=[":__","","_:_"],this.errors=new lt(this),this.reserved=new rt(this),this.keyFiller=new ot(this),this.valFiller=new at(this),this.commentedTerms=new Map,this.joins=new Map,this.fillers=new Map,this.contexts=new Map,this.temps=new Map,this.refresh()}refresh(t={}){this.times={start:+new Date},Object.assign(this.opts,t),"string"!=typeof this.opts.template&&(this.opts.template=JSON.stringify(this.opts.template));const e=JSON.parse(this.opts.template);this.errors.clear(e["@errmode"]),e["@delimit"]&&(this.delimit=e["@delimit"]),this.commentedTerms.clear(),this.joins.clear(),this.fillers.clear(),this.contexts.clear(),this.temps.clear(),delete this.tree,this.tree=this.setResultContext(this.opts.seed),this.focusTemplate=Object.create(null),this.parseTemplate(e,{"@":this.reserved.notDefined}),this.times.parse=+new Date-this.times.start,Object.keys(this.focusTemplate).length?(this.parseTemplate(this.focusTemplate,{"@":this.reserved.notDefined}),this.template=this.focusTemplate):this.template=e,this.postLoopTerms=Object.create(null),this.done=[],this.opts.data&&this.add(this.opts.data,!1),this.errors.log(this.fillers)}setResultContext(t,e=null,s=null,i=!1,n,r=null,o=null){const a=null!==e&&e in s?s[e]:JSON.parse(t);if(this.contexts.has(a))return a;const l={branch:e,parent:s,context:this.contexts.get(s),self:a,root:this.tree?this.tree:a,joins:this.joins,errors:[],key:n};if(i&&(l.tracker=new Map),r&&o){const t=this.fillers.get(o);if(!t["@before"](r,l))return;if(t["@join"]&&!t["@join"](r,l))return}return this.contexts.set(a,l),null!==e&&(s[e]=a),a}parseTemplate(t,e,s=[]){const i=Object.create(null);i.inputs=Object.create(null),i["@before"]=this.reserved.trueFxn,i["@after"]=this.reserved.trueFxn,i.postTerms={},i.errors=[];const n=this.reserved["@ignore"](t,e,i);i["@ignore"]=n,this.fillers.set(t,i);const r=this.steps.map((t=>[]));for(const e in t){const[o,a,l,c]=ct(this,e),d=t[e],p=i.inputs[e]={term:e,subterm:o,symbols:a,keyTokens:l,templateVal:d,lineage:[...s,e],inheritedIgnore:n,errors:[]};"@()"==a?this.reserved.setFxn(o,p,i,d):(p.keyFxn=this.keyFiller.getFxn(p,n),p.keyFxn&&(p.valFxn=this.valFiller.getFxn(p,n),"__:"==l.time||this.timePost.includes(l.time)?(i.postTerms[l.time]||(i.postTerms[l.time]=[]),i.postTerms[l.time].includes(e)||i.postTerms[l.time].push(e)):r[c].push(e)))}i.steps=r.filter((t=>t.length))}add(t,e=!0){this.times.start||(this.times.start=+new Date),e&&this.errors.clear(),this.joins.clear();for(const e of t)if(this.split)for(const t of this.split(e))this.processRow(t,this.template,this.tree),this.joins.clear();else this.processRow(e,this.template,this.tree),this.joins.clear();this.processResult(this.tree);for(const t of this.timePost)if(this.postLoopTerms[t])for(const e of this.postLoopTerms[t])this.postLoop(e.self,e,t);for(const t of this.done)t.done(t.self,t);for(const[t,e]of this.temps)for(const s of e)delete t[s];this.times.total=+new Date-this.times.start,delete this.times.start,e&&this.errors.log()}processRow(t,e,s){const i=this.contexts.get(s),n=this.fillers.get(e);if(i.filler=n,n["@before"](t,i)&&(!n["@join"]||n["@join"](t,i))){for(const e of n.steps)for(const r of e){const e=n.inputs[r];if(e.keyFxn&&e.valFxn){const n=e.keyFxn(t,i);for(const r of n)e.valFxn(t,r,s,i),"~"==e.keyTokens.skip&&(this.temps.has(s)||this.temps.set(s,new Set),this.temps.get(s).add(r))}}n["@after"](t,i),n["@dist"]&&n["@dist"](i),n["@done"]&&!this.done.includes(i)&&(i.done=n["@done"],this.done.push(i));for(const t in n.postTerms)this.postLoopTerms[t]||(this.postLoopTerms[t]=[]),this.postLoopTerms[t].includes(i)||this.postLoopTerms[t].push(i);return!0}}postLoop(t,e,s="__:"){if(e&&e.filler&&e.filler.postTerms[s])for(const i of e.filler.postTerms[s]){const s=e.filler.inputs[i];if(s.keyFxn&&s.valFxn){const i=s.keyFxn(null,e);for(const n of i)s.valFxn(null,n,t,e)}}}processResult(t){const e=this.contexts.get(t);this.postLoop(t,e,"__:");for(const e in t){const s=t[e];if(s)if(Array.isArray(s)||s instanceof Set||s instanceof Map)for(const t of s)"object"==typeof t&&this.processResult(t);else if("object"==typeof s){const t=this.contexts.get(s);t&&t["@dist"]&&t["@dist"](s),this.processResult(s)}}e&&e.filler&&this.errors.markErrors(t,e)}copyResult(t,e={}){if(arguments.length&&void 0===t)return;const s=arguments.length?t:this.tree;for(const t in s){const i=s[t];if(i instanceof Set||i instanceof Map)e[t]=[...i];else if(Array.isArray(i)){e[t]=[];for(const s of i)if(Array.isArray(s)){const i=[];e[t].push(i),this.copyResult(s,i)}else if(s&&"object"==typeof s){const i=Object.create(null);e[t].push(i),this.copyResult(s,i)}else e[t]=JSON.parse(JSON.stringify(i))}else i&&"object"==typeof i?(e[t]=Object.create(null),this.copyResult(i,e[t])):e[t]=JSON.parse(JSON.stringify(i))}return e}}ut.prototype.converter=ft;function ht(t){const e=t;if(!e||typeof e!=="object")throw"bin schema must be an object";if(!("type"in e))e.type="regular-bin";if(e.type=="custom-bin"){if(!Array.isArray(e.lst))throw"binconfig.lst must be an array";if(!e.lst.length)throw"binconfig.lst must have entries";const t=e.lst[0];const s=e.lst[e.lst.length-1];for(const i of e.lst){if(!("startinclusive"in i)&&!("stopinclusive"in i)){throw"custom bin.startinclusive and/or bin.stopinclusive must be defined"}if(i==t){if("startunbounded"in i&&!i.startunbounded){throw`a custom first bin must not set bin.startunbounded to false`}i.startunbounded=true;if("start"in i){throw"a custom first bin must not set a bin.start value"}if("start_percentile"in i){throw"the first bin must not set a bin.start_percentile value"}if(!("stop"in i)){throw`a custom first bin must define a bin.stop value`}if(!f(i.stop)){throw`a custom first bin.stop value should be numeric`}}else if(i==s){if(!("start"in i)){throw`a custom last bin must define a bin.start value`}if(!f(i.start)){throw`a custom last bin.start must be numeric`}if("stopunbounded"in i&&!i.stopunbounded){throw"a custom last bin must not set bin.stopunbounded to false"}i.stopunbounded=true;if("stop"in i){throw"a custom last bin must not set a bin.stop value"}}else{if(!f(i.start))throw"bin.start must be numeric for a non-first bin";if(!f(i.stop))throw"bin.stop must be numeric for a non-last bin"}}}else if(e.type=="regular-bin"){if(!Number.isFinite(e.bin_size))throw"non-numeric bin_size";if(e.bin_size<=0)throw"bin_size must be greater than 0";if(!e.startinclusive&&!e.stopinclusive){e.startinclusive=1;e.stopinclusive=0}if(!e.first_bin)throw"first_bin{} missing";if(typeof e.first_bin!="object")throw"first_bin{} is not an object";if(!Object.keys(e.first_bin).length)throw"first_bin is an empty object";{const t=e.first_bin;t.startunbounded=true;if(t.stop_percentile){if(!Number.isInteger(t.stop_percentile))throw"first_bin.stop_percentile should be integer";if(t.stop_percentile<=0||t.stop_percentile>=100)throw"first_bin.stop_percentile out of bound (0-100)"}else if(!Number.isFinite(t.stop)){throw"first_bin.stop not a number when stop_percentile is not set"}}if(e.last_bin){const t=e.last_bin;if(t.start_percentile){if(!Number.isInteger(t.start_percentile))throw"last_bin.start_percentile should be integer";if(t.start_percentile<=0||t.start_percentile>=100)throw"last_bin.start_percentile out of bound (0-100)"}else if(!Number.isFinite(t.start)){throw"last_bin.start not a number when start_percentile is not set"}t.stopunbounded=true;if("stop"in t){throw"a regular last bin must not set a bin.stop value"}}}else{throw`invalid binconfig.type="${e.type}"`}}function mt(t,e,s){const i=t;ht(i);if(i.lst){const t=p(i.lst.length);for(const e of i.lst)e.color=t(e.label)}if(i.type=="custom-bin")return JSON.parse(JSON.stringify(i.lst));if(typeof e!="function")throw"summaryfxn required for modules/termdb.bins.js compute_bins()";const n=vt(i);const r=e(n);if(!r||typeof r!=="object")throw"invalid returned value by summaryfxn";i.results={summary:r};if(!i.binLabelFormatter)i.binLabelFormatter=bt(i);const o=Math.floor(r.min*100)/100;const a=Math.ceil(r.max*100)/100;const l=i.first_bin.startunbounded?o:i.first_bin.start_percentile?r["p"+i.first_bin.start_percentile]:i.first_bin.start;let c=a,d,u;if(i.last_bin){c=i.last_bin.stopunbounded?a:i.last_bin.stop_percentile?r["p"+i.last_bin.stop_percentile]:f(i.last_bin.stop)&&i.last_bin.stop<=r.max?i.last_bin.stop:a;d=f(i.last_bin.start_percentile)?r["p"+i.last_bin.start_percentile]:f(i.last_bin.start)?i.last_bin.start:undefined;u=i.last_bin.stopunbounded?null:i.last_bin.stop_percentile?r["p"+i.last_bin.stop_percentile]:f(i.last_bin.stop)?i.last_bin.stop:null}else if(i.lst){const t=i.lst[i.lst.length-1];d=t.start;u="stop"in t&&!t.stopunbounded?t.stop:a;c=u}else{d=a;u=a}const h=f(c);const m=f(d);const b=f(u);if(!h&&!m)return[];const y=[];let g={startunbounded:i.first_bin.startunbounded,start:i.first_bin.startunbounded?undefined:l,stop:f(i.first_bin.stop_percentile)?+r["p"+i.first_bin.stop_percentile]:f(i.first_bin.stop)?+i.first_bin.stop:l+i.bin_size,startinclusive:i.startinclusive,stopinclusive:i.stopinclusive};if(!f(g.stop))throw"the computed first_bin.stop is non-numeric"+g.stop;const v=100;while(h&&g.stop<=c||g.startunbounded&&!y.length||g.stopunbounded){y.push(g);if(g.stop>=c){g.stopunbounded=true;if(y.length>1){delete g.stop}}g.label=yt(g,i,s);if(g.stopunbounded)break;const t=g.stop+i.bin_size;const e=g.stop;g={startinclusive:i.startinclusive,stopinclusive:i.stopinclusive,start:e,stop:b&&(e==d||t>u)?u:m&&t>d&&e!=d?d:t};if(g.stop>=c){g.stop=c;if(i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=1;if(i.last_bin&&i.last_bin.stopinclusive)g.stopinclusive=1}if(m&&g.start==d){if(i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=1}if(g.start>g.stop){if(m&&g.stop==d&&i.last_bin&&i.last_bin.stopunbounded)g.stopunbounded=true;else break}if(y.length+1>=v){i.error="max_num_bins_reached";break}}delete i.binLabelFormatter;if(y.length>1){delete y[y.length-1].stop}const _=p(y.length);for(const t of y)t.color=_(t.label);return y}function bt(t){return"rounding"in t?d(t.rounding):t=>t}function yt(t,e,s){const i=e;if(!i.binLabelFormatter)i.binLabelFormatter=bt(i);if(!t.startunbounded&&!t.stopunbounded&&!("startinclusive"in t)&&!("stopinclusive"in t)){if(i.startinclusive)t.startinclusive=true;else if(i.stopinclusive)t.stopinclusive=true}const n=i.use_as=="bins"||t.start;const r=i.use_as=="bins"||t.stop;let o=0;if("label_offset"in i){i.label_offset_ignored="bin_size"in i&&i.bin_size<i.label_offset;if(!i.label_offset_ignored)o=i.label_offset}else if(i.bin_size===1&&i.termtype=="integer"){o=1}if(t.startunbounded){const e=t.stopinclusive?"≤":"<";const n=s?c(r,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(r);return e+n}if(t.stopunbounded||n===r){const e=t.startinclusive?"≥":">";const r=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n);return e+r}if(o&&t.startinclusive&&!t.stopinclusive){if(Number.isInteger(i.bin_size)&&Math.abs(n-r)===o){return""+(s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n))}else{const t=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(n);const e=s?c(r-o,s.fromUnit,s.toUnit,s.scaleFactor,true):i.binLabelFormatter(r-o);return+t>=+e?t.toString():t+" to "+e}}else{const e=t.startinclusive?"":">";const o=t.stopinclusive?"":"<";const a=s?c(n,s.fromUnit,s.toUnit,s.scaleFactor,true):Number.isInteger(n)?n:i.binLabelFormatter(n);const l=s?c(r,s.fromUnit,s.toUnit,s.scaleFactor,true):Number.isInteger(r)?r:i.binLabelFormatter(r);if(+a>=+l){const e=t.startinclusive?"≥":">";return e+a}else{return e+a+" to "+o+l}}}function gt(t,e){const s='<span style="font-family:Times;font-style:italic;">x</span>';let i;const n=yt(t,e);if(t.startunbounded||t.stopunbounded){i=s+" "+n}else if(t.startinclusive){i=n.replace("to <","≤ "+s+" <")}else if(t.stopinclusive){i=n.replace(">","").replace("to","< "+s+" ≤")}return i}function vt(t){const e=[];const s=t.first_bin;if(s&&f(s.start_percentile))e.push(s.start_percentile);if(s&&f(s.stop_percentile))e.push(s.stop_percentile);const i=t.last_bin;if(i&&f(i.start_percentile))e.push(i.start_percentile);if(i&&f(i.stop_percentile))e.push(i.stop_percentile);return e}function _t(t,e,s){const i=!e?[]:e.type=="tvslst"?e.lst:[e];let n=0;for(const r of i){if(r.type=="tvslst"){if(_t(t,r)){n++}}else{const e=r.tvs;let i;if(e.term.type=="geneVariant"){i=s.map((e=>t[e])).filter((t=>t))}else if(e.term.type=="integer"||e.term.type=="float"){i=t[e.term.id]||t[e.term.$id]?.key}else if(e.term.type=="survival"){i=t[e.term.$id]?.key}else{i=t[e.term.id]||t[e.term.$id]?.value}let o;if(e.term.type=="categorical"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));o=t.has(i)}else if(e.term.type=="integer"||e.term.type=="float"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}for(const t of e.ranges){if("value"in t){o=i===t.value;if(o)break}else if(i==t.name){o=true;break}else{if(e.term.values){const t=e.term.values[i.toString()];if(t&&t.uncomputable){continue}}let s,n;if(t.startunbounded){s=true}else if("start"in t){if(t.startinclusive){s=i>=t.start}else{s=i>t.start}}if(t.stopunbounded){n=true}else if("stop"in t){if(t.stopinclusive){n=i<=t.stop}else{n=i<t.stop}}o=s&&n}if(o)break}}else if(e.term.type=="condition"){const t=getPrecomputedKey(e);const s=i&&i[t];if(s){o=Array.isArray(s)?e.values.find((t=>s.includes(t.key))):e.values.find((t=>t.key==s))}}else if(e.term.type=="survival"){if(i===undefined){if(e.isnot)o=!o;if(o)n++;continue}const t=e.valueset?e.valueset:new Set(e.values.map((t=>t.key)));o=t.has(i)}else if(e.term.type=="geneVariant"&&e.legendFilterType=="geneVariant_hard"){const t=e.values[0];o=i.find((e=>{for(const s of e.values){if(s.dt==t.dt&&(!s.origin||s.origin==t.origin)&&t.mclasslst.includes(s.class))return true}}))&&true}else if(e.term.type==y.GENE_EXPRESSION);else if(e.term.type==y.METABOLITE_INTENSITY);else{throw"unknown term type"}if(e.isnot){o=!o}if(o)n++}if(e.join=="or"&&n)return true}if(n==i.length)return true}function wt(t,e){const s=JSON.parse(JSON.stringify(t));if(!s.term1)s.term1=s.term?s.term:{};if(!s.term1_q)s.term1_q={};if(!s.term0)s.term0={};if(!s.term0_q)s.term0_q={};if(!s.term2)s.term2={};if(!s.term2_q)s.term2_q={};if(!s.filter)s.filter={type:"tvslst",join:"",lst:[]};const i=Nt(s,e);return i.tree.results}const jt=JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"_2:maxAcrossCharts":"=maxAcrossCharts()",charts:[{chartId:"@key",total:"+1","_1:maxSeriesTotal":"=maxSeriesTotal()","@done()":"=filterEmptySeries()",serieses:[{total:"+1",seriesId:"@key",max:"<&idVal.dataVal","~values":["&idVal.dataVal",0],"~sum":"+&idVal.dataVal","__:boxplot":"=boxplot()","~samples":["$sample","set"],data:[{dataId:"@key",total:"+1"},"&idVal.dataId[]"]},"&idVal.seriesId[]"]},"&idVal.chartId[]"],"~sum":"+&idVal.seriesVal","~values":["&idVal.seriesVal",0],"__:boxplot":"=boxplot()",refs:{cols:["&idVal.seriesId[]"],colgrps:["-"],rows:["&idVal.dataId[]"],rowgrps:["-"],col2name:{"&idVal.seriesId[]":{name:"@branch",grp:"-"}},row2name:{"&idVal.dataId[]":{name:"@branch",grp:"-"}},"__:useColOrder":"=useColOrder()","__:useRowOrder":"=useRowOrder()","__:bins":"=bins()","@done()":"=sortColsRows()"},"@done()":"=sortCharts()"}});function Nt(t,e){const s={categorical:Tt,integer:St,float:St,undefined:It};return new ut({data:e,seed:`{"values": []}`,template:jt,"=":{idVal(i,n){const[r,o]=s[t.term0.type](i.data,t.term0,t.term0_q,e);const[a,l]=s[t.term1.type](i.data,t.term1,t.term1_q,e);const[c,d]=s[t.term2.type](i.data,t.term2,t.term2_q,e);return{chartId:r,chartVal:o,seriesId:a,seriesVal:l,dataId:c,dataVal:d}},prep(e){return _t(e.data,t.filter)},maxSeriesTotal(t,e){let s=0;for(const t of e.self.serieses){if(t&&t.total>s){s=t.total}}return s},maxAcrossCharts(t,e){let s=0;for(const t of e.self.charts){if(t.maxSeriesTotal>s){s=t.maxSeriesTotal}}return s},boxplot(t,e){if(!e.self.values||!e.self.values.length)return;const s=e.self.values.filter((t=>t!==null&&!isNaN(t)));if(!s.length)return;s.sort(((t,e)=>t-e));const i=At(s.map((t=>({value:+t}))));i.mean=e.self.sum/s.length;let n=0;for(const t of s){n+=Math.pow(t-i.mean,2)}i.sd=Math.sqrt(n/(s.length-1));if(isNaN(i.sd))i.sd=null;return i},numSamples(t,e){return e.self.samples.size},filterEmptySeries(t){const e=t.serieses.filter((t=>t.total));t.serieses.splice(0,t.serieses.length,...e)},sortColsRows(e){if(t.term1_q.orderedLabels){const s=t.term1_q.orderedLabels;e.cols.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}if(t.term2.orderedLabels){const s=t.term2_q.orderedLabels;e.rows.sort(((t,e)=>s.indexOf(t)-s.indexOf(e)))}},sortCharts(t){},useColOrder(){return t.term1_q.orderedLabels&&t.term1_q.orderedLabels.length>0},useRowOrder(){return t.term2_q.orderedLabels&&t.term2_q.orderedLabels.length>0},bins(){return[t.term0_q,t.term1_q,t.term2_q].map((t=>t.computed_bins))},q(){}}})}function Tt(t,e){const s="id"in e?t[e.id]:"-";const i="id"in e&&f(t[e.id])?+t[e.id]:0;return[[s],i]}function St(t,e,s,i){if(!("id"in e)||!(e.id in t))return[[],undefined];if(!s.computed_bins){const t={};i.map((s=>{if(!f(s.data[e.id]))return;const i=+s.data[e.id];if(!("min"in t)||t.min>i)t.min=i;if(!("max"in t)||t.max<i)t.max=i}));s.computed_bins=mt(s,(e=>t));s.orderedLabels=s.computed_bins.map((t=>t.label))}const n=t[e.id];if(e.values&&n in e.values&&e.values[n].uncomputable){return[[e.values[n].label],undefined]}if(f(t[e.id])){const t=[];for(const e of s.computed_bins){if(e.startunbounded){if(n<e.stop){t.push(e.label)}else if(e.stopinclusive&&n===e.stop){t.push(e.label)}}else if(e.stopunbounded){if(n>e.start){t.push(e.label)}else if(e.stopinclusive&&n===e.start){t.push(e.label)}}else if((n>e.start||n===e.start&&e.startinclusive)&&(n<e.stop||n===e.stop&&e.stopinclusive)){t.push(e.label)}if(t.length)break}return[t,n]}return[[],undefined]}function It(){return[["-"],undefined]}function At(t){const e=t.length;if(e<5){return{out:t}}const s=t[Math.floor(e/2)].value;const i=t[Math.floor(e/4)].value;const n=t[Math.floor(e*3/4)].value;const r=t[Math.floor(e*.05)].value;const o=t[Math.floor(e*.95)].value;t[Math.floor(e*.01)].value;const a=n-i;let l,c;if(a==0){l=0;c=0}else{const s=t.findIndex((t=>t.value>i-a*1.5));l=t[s==-1?0:s].value;const r=t.findIndex((t=>t.value>n+a*1.5));c=t[r==-1?e-1:Math.max(0,r-1)].value}const d=t.filter((t=>t.value<i-a*1.5||t.value>n+a*1.5));return{w1:l,w2:c,p05:r,p25:i,p50:s,p75:n,p95:o,iqr:a,out:d}}function Ot(t,e){if(!e||!e.length){return{lst:Object.keys(t.term.values).map((e=>({key:e,label:t.term.values[e].label,value:e})))}}const s=new ut({data:e,template:JSON.stringify({"@before()":"=prep()","@join()":{idVal:"=idVal()"},results:{"&idVal.id":{samplecount:"+1",":__key":"&idVal.id",":__label":"&idVal.id",":__value":"&idVal.id"}}}),"=":{prep(e){return _t(e.data,t.filter)},idVal(e,s){const[i,n]=Tt(e.data,t.term);return{id:i[0],value:n}}}});return{lst:Object.values(s.tree.results)}}var xt=Object.freeze({__proto__:null,getBarchartData:wt,getCategoryData:Ot});function kt(t,e){const s=Number(t);if(Number.isInteger(s))return s;if(Math.abs(s)<1)return Number(s.toPrecision(e));return Number(s.toFixed(e))}function Et(t){let e=t>1?2:Ct(t)+2;return kt(t,e)}function Ct(t){const e=t.toString();const s=e.indexOf(".");if(s===-1||s===e.length-1){return 0}let i=0;for(let t=s+1;t<e.length;t++){if(e[t]==="0"){i++}else if(e[t]>="1"&&e[t]<="9"){break}}return i}function Rt(t,e){t.sort(((t,e)=>t-e));const s=Math.abs(e/100*t.length-1);const i=Number.isInteger(s)?(t[s]+t[s+1])/2:t[Math.ceil(s)];return i}class Dt extends K{constructor(t){super(t);this.datarows=[];if(t.state.vocab.sampleannotation){const e=t.state.vocab.sampleannotation;Object.keys(e).forEach((t=>this.datarows.push({sample:t,data:e[t]})))}}getTermdbConfig(){return{selectCohort:this.vocab.selectCohort,supportedChartTypes:[]}}getTermChildren(t,e){const s=(e||[]).slice().sort().join(",");const i=t.__tree_isroot?null:t.id;return{lst:this.vocab.terms.filter((t=>t.parent_id===i&&(!s.length||s===t.cohortValues.slice().sort.join(","))))}}async getNestedChartSeriesData(t){const e={term1:t.term?t.term.term:{},term1_q:t.term?t.term.q:undefined,term0:t.term0?t.term0.term:undefined,term0_q:t.term0?t.term0.q:undefined,term2:t.term2?t.term2.term:undefined,term2_q:t.term2?t.term2.q:undefined,filter:this.state.termfilter&&this.state.termfilter.filter};return wt(e,this.datarows)}syncTermData(t,e,s={}){if(!e||!e.refs)return;for(const[s,i]of["term0","term","term2"].entries()){const n=t[i];if(n=="genotype")return;if(!n){if(i=="term")throw`missing plot.term{}`;return}if(e.refs.bins){n.bins=e.refs.bins[s];if(e.refs.q&&e.refs.q[s]){if(!n.q)n.q={};const t=e.refs.q[s];if(t!==n.q){for(const t in n.q)delete n.q[t];Object.assign(n.q,t)}}}if(!n.q)n.q={};if(!n.q.groupsetting)n.q.groupsetting={}}}async findTerm(t,e,s=null){return{lst:this.vocab.terms.filter((s=>s.name.includes(t)&&(!e||e===s.cohortValues.slice().sort.join(","))))}}async getTermInfo(e){const s=this.vocab.find((t=>t.id===e));if(!s)return undefined;return{terminfo:t.info}}async getCohortSampleCount(t){if(!t)return;const e=this.vocab.find((t=>t.id===id));if(!e||!e.cohortValues.includes(t))return;if(!e.samplecount)e.samplecount={};if(!(t in e.samplecount)){e.samplecount[t]=Object.keys(this.vocab.sampleannotation).length}return{samplecount:e.samplecount[t]}}async getCohortsData(t){return null}async getFilteredSampleCount(t){return"TBD"}async getDensityPlotData(t,e,s){if(!this.datarows||!this.datarows.length){const e=this.vocab.terms.find((e=>e.id===t));e.range&&e.range;return{minvalue:e.range&&e.range.start,maxvalue:e.range&&e.range.stop}}const i=[];const n=new Set;let r,o,a=0;let l={};for(const t of this.datarows){if(l[t.sample])continue;const e=t.s||t.data;if(e&&_t(e,s)){l[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in l){if(!(t in this.vocab.sampleannotation[e]))continue;const s=this.vocab.sampleannotation[e][t];if(f(s)){const t=+s;a+=1;if(r===undefined||t<r)r=t;if(o===undefined||t>o)o=t;i.push(t);n.add(t)}}const c=this.vocab.terms.find((e=>e.id==t));const d=40;const p=c.type=="integer"&&o-r<d?o-r:c.type=="float"&&n.size<d?n:d;const h=u().domain([r,o]).range([e.plot_size.xpad,e.plot_size.width-e.plot_size.xpad]);const m=Vt(h.ticks(p))(i);return{density:m,densitymax:m.reduce(((t,e,s)=>s===0||e[1]>t?e[1]:t),0),minvalue:r,maxvalue:o,samplecount:a}}async getPercentile(t,e,s){if(e.find((t=>!Number.isInteger(t))))throw"non-integer percentiles found";if(Math.max(...e)>99||Math.min(...e)<1)throw"percentiles must be between 1-99";const i=[];const n=[];const r={};for(const t of this.datarows){if(r[t.sample])continue;const e=t.s||t.data;if(e&&_t(e,s)){r[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in r){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";n.push(s)}n.sort(((t,e)=>t-e));for(const t of e){const e=Math.abs(t/100*n.length-1);const s=Number.isInteger(e)?(n[e]+n[e+1])/2:n[Math.ceil(e)];i.push(s)}return{values:i}}async getDescrStats(t,e,s){const i=[];const n={};for(const t of this.datarows){if(n[t.sample])continue;const s=t.s||t.data;if(s&&_t(s,e)){n[t.sample]=this.vocab.sampleannotation[t.sample]}}for(const e in n){if(!(t in this.vocab.sampleannotation[e]))continue;const s=Number(this.vocab.sampleannotation[e][t]);if(!Number.isFinite(s))throw"non-numeric value";i.push(s)}i.sort(((t,e)=>t-e));const r=i.length;const o=i.reduce(((t,e)=>t+e),0);const a=o/r;const l=Rt(i,25);const c=Rt(i,50);const d=Rt(i,75);const p=i.map((t=>(t-a)**2)).reduce(((t,e)=>t+e),0);const f=p/(i.length-1);const u=Math.sqrt(f);const h=Math.min(...i);const m=Math.max(...i);return{values:[{id:"total",label:"n",value:r},{id:"min",label:"Minimum",value:kt(h,2)},{id:"p25",label:"1st quartile",value:kt(l,2)},{id:"median",label:"Median",value:kt(c,2)},{id:"mean",label:"Mean",value:kt(a,2)},{id:"p75",label:"3rd quartile",value:kt(d,2)},{id:"max",label:"Maximum",value:kt(m,2)},{id:"sd",label:"Standard deviation",value:kt(u,2)}]}}async getTerms(t,e=null,s=null){if(!t)throw"getTerms: ids missing";if(!Array.isArray(t))throw`invalid ids`;const i={};for(const e of t){const t=this.vocab.terms.find((t=>t.id===e));if(t)i[e]=t}return i}async getterm(t){if(!t)throw"getterm: termid missing";return this.vocab.terms.find((e=>e.id==t))}async getCategories(t,e,s=null){const i={term:t,filter:e};const n=Ot(i,this.datarows);return n}getNumericUncomputableCategories(t,e){throw"to be implemented!! getNumericUncomputableCategories"}graphable(t){if(!t)throw"graphable: term is missing";return Q(t).has("plot")}q_to_param(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}}function Vt(t){return e=>{const s=[];for(let e=0;e<t.length;e++)s.push([t[e],0]);for(const i of e){for(let e=1;e<t.length;e++){if(i<=t[e]){s[e-1][1]++;break}}}return s}}function Mt(t){if(t.vocab&&!t.state){t.state={vocab:t.vocab}}if(!t.state)throw"missing opts.state";if(!t.state.vocab){t.state.vocab=t.vocab?t.vocab:{}}const e=t.state.vocab;if(t.state.genome){e.genome=t.state.genome;delete t.state.genome}if(t.state.dslabel){e.dslabel=t.state.dslabel;delete t.state.dslabel}if(e.dslabel){return new st(t)}else if(e.terms){return new Dt(t)}}function Pt(t){const e=JSON.parse(JSON.stringify(t));delete e.hiddenValues;return encodeURIComponent(JSON.stringify(e))}function Ft({samples:t,sample_attributes:e}){const s={__root:{id:"root",name:"root",__tree_isroot:true}};const i={};for(const n of t){const t=n.sample;if(!i[t])i[t]={};Object.assign(i[t],n.s);for(const t in n.s){if(!s[t]){const i=e[t]&&e[t].label?e[t].label:t;s[t]={id:t,name:i,parent_id:null,type:e[t].type=="float"?"float":e[t].type=="integer"?"integer":"categorical",values:{},isleaf:true}}const i=s[t];if(!("id"in i))i.id=t;if(!("parent_id"in i))i.parent_id=null;if(!("values"in i))i.values={};if(!("isleaf"in i))i.isleaf=true;if(!i.computableVals&&(i.type=="float"||i.type=="integer")){i.computableVals=[]}const r=n.s[t];if(i.type=="categorical"){i.groupsetting={disabled:true};if(!(r in i.values)){i.values[r]={key:r,label:r}}}else if(i.type=="integer"||i.type=="float"){if(r==="Not Available"&&!(r in i.values)){i.values[r]={label:r,uncomputable:true}}if(!(r in i.values)){if(!f(n.s[t]))throw`non-numeric term value='${r}' for term='${t}'`;n.s[t]=Number(n.s[t]);const e=n.s[t];i.computableVals.push(e)}}else if(i.type=="condition");else{throw"Term type not supported:"+i.type}}}for(const t in s){const e=s[t];if((e.type=="integer"||e.type=="float")&&!e.bins){e.bins={default:H(e.computableVals)};delete e.computableVals}}return{sampleannotation:i,terms:Object.values(s)}}var Lt=Object.freeze({__proto__:null,vocabInit:Mt,q_to_param:Pt,getVocabFromSamplesArray:Ft});const $t={joinWith:["and","or"]};class qt{constructor(t){this.opts=this.validateOpts(t);this.dom={holder:t.holder,controlsTip:new i({padding:"0px",parent_menu:this.opts.holder.node()&&this.opts.holder.node().closest(".sja_menu_div")}),treeTip:new i({padding:"5px",offsetX:20,offsetY:-34,clearSelector:".sja_term_src_body"})};this.durations={exit:500};this.lastId=0;this.categoryData={};this.pills={};z(this);J(this);this.initUI();this.filter={type:"tvslst",tag:"filterUiRoot",join:"and",in:true,lst:[]};this.promises={}}validateOpts(t){const e=Object.assign({},$t,t);if(!e.holder)throw".holder missing";if(e.vocabApi){this.vocabApi=e.vocabApi}else{if(!e.vocab)throw".vocab missing";if(e.vocab.dslabel){if(!e.vocab.genome)throw"vocab.genome missing"}else{if(!e.vocab.terms)throw"vocab.terms missing"}}if(typeof e.callback!="function")throw".callback() is not a function";if(e.getVisibleRoot&&typeof e.getVisibleRoot!="function")throw".getVisibleRoot() must be a function if set as an option";if(!e.emptyLabel)e.emptyLabel="+NEW";return e}async main(t,e={}){this.promises.postRender=new Promise(((t,e)=>{this.mainResolve=t;this.mainReject=e}));this.numProcessedItems=0;this.numExpectedItems=0;this.opts=Object.assign({},this.opts,e);this.activeCohort=this.opts.activeCohort;this.rawCopy=t;this.rawFilter=JSON.parse(this.rawCopy);this.validateFilter(this.rawFilter);this.filter=M(this.rawFilter,"filterUiRoot");if(!this.filter){this.filter=this.rawFilter;this.filter.tag="filterUiRoot"}await this.resetActiveData(this.filter);this.removeBlankPill();this.dom.newBtn.style("display",this.opts.newBtn?"":this.filter.lst.length==0?"inline-block":"none");this.dom.holder.selectAll(".sja_filter_add_transformer").style("display",this.getAddTransformerBtnDisplay);this.setVocabApi();this.updateUI(this.dom.filterContainer,this.filter);return this.promises.postRender}validateFilter(t){if(!("$id"in t))t.$id=this.lastId++;else if(this.lastId<=t.$id)this.lastId=t.$id+1;if(!("type"in t))throw"missing filter.type";if(t.type!="tvs"&&t.type!="tvslst")throw"invalid filter.type";if(t.type!="tvslst")return;if(!Array.isArray(t.lst))throw"invalid or missing filter.lst[]";if(t.lst.length>1){if(t.join!="and"&&t.join!="or")throw"invalid filter.join value for lst.length > 1"}else if(t.join!==""){throw"filter.join must be an empty string when lst.length < 2"}if(!t.lst.length)t.in=true;for(const[e,s]of t.lst.entries()){this.validateFilter(s)}}resetActiveData(t){if(this.dom.controlsTip.d.style("display")=="none"){this.activeData={item:{},filter:{}}}else{this.activeData={item:D(t,this.activeData.item.$id),filter:D(t,this.activeData.filter.$id),menuOpt:this.activeData.menuOpt}}}refresh(t){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=JSON.parse(JSON.stringify(this.rawFilter));delete e.tag;t.tag="filterUiRoot";const s=V(e,this.filter.$id);if(!s||this.rawFilter.$id===this.filter.$id){this.api.main(t);this.opts.callback(t)}else{const i=s.lst.findIndex((t=>t.$id==this.filter.$id));s.lst[i]=t;this.api.main(e);this.opts.callback(t)}}getId(t){return t.$id}getFilterExcludingPill(t){const e=JSON.parse(JSON.stringify(this.rawFilter));const s=V(e,t);const i=s.lst.findIndex((e=>e.$id===t));if(i==-1)return null;s.lst.splice(i,1);return F(e)}getAdjustedRoot(t,e){const s=JSON.parse(JSON.stringify(this.rawFilter));if(e=="and")return s;const i=M(s,"cohortFilter");const n=V(s,t);if(!n){return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]}}const r=n.lst.findIndex((t=>t.$id===n.$id));if(r==-1)return{type:"tvslst",in:true,join:"and",lst:i?[i]:[]};n.lst.splice(r,1);if(i&&!n.lst.find((t=>t===i))){return F({type:"tvslst",join:"and",lst:[i,n]})}return F(n)}setVocabApi(){if(!this.vocabApi){const t={getState:()=>{const t=JSON.parse(this.rawCopy);const e=M(t,"cohortFilter");if(e&&this.opts.termdbConfig){e.tvs.values=this.activeCohort==-1||this.activeCohort===undefined?[]:this.opts.termdbConfig.selectCohort.values[this.activeCohort].keys.map((t=>({key:t,label:t})))}return{vocab:this.opts.vocab,termfilter:{filter:t},tree:{plots:{}}}}};const e=t.getState();const s=e.vocab||{genome:e.genome,dslabel:e.dslabel};if(!this.vocabApi){this.vocabApi=Mt({app:t,state:{vocab:s}})}}this.vocabApi.main()}updatePromise=function(t=1){if(!this.mainResolve)return;this.numProcessedItems+=t;if(this.numExpectedItems==this.numProcessedItems){this.mainResolve();if(this.bus)this.bus.emit("postRender");delete this.mainResolve}}}class Ut extends qt{constructor(t){super(t);this.type="filter";this.initHolder()}async preApiFreeze(t){t.main=this.main.bind(this);t.getNormalRoot=()=>F(this.rawFilter)}getState(t){return{termfilter:t.termfilter,activeCohort:t.activeCohort}}async main(t=null){this.dom.controlsTip.hide();this.dom.treeTip.hide();const e=this.state&&this.state.termfilter;if(!e){this.dom.holder.style("display","none");return}this.dom.holder.style("display","inline-block");const s=JSON.stringify(t||e.filter);super.main(s,{activeCohort:this.state.activeCohort})}initHolder(){const t=this.dom.holder.attr("class","filter_div").style("position","relative").style("width","fit-content").style("margin","10px").style("margin-top","5px").style("display","table").style("border",this.opts.hideLabel?"none":"solid 1px #ddd");if(this.opts.hideLabel){this.dom.filterDiv=t.style("display","inline-block").style("padding","5px 10px")}else{t.append("span").text("Filter").style("padding","0 10px");this.dom.filterDiv=t.append("div").style("display","inline-block").style("padding","5px 10px")}}}const Jt=h(Ut);export{qt as F,b as N,y as T,M as a,Jt as b,q as c,T as d,v as e,V as f,F as g,Q as h,N as i,I as j,S as k,R as l,Ct as m,Ft as n,ut as o,g as p,_t as q,Et as r,E as s,_ as t,yt as u,Mt as v,gt as w,kt as x,xt as y,Lt as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{aB as t,aX as i}from"./app-
|
|
1
|
+
import{aB as t,aX as i}from"./app-71453429.js";import{F as s,g as o}from"./FilterRxComp-fc769f34.js";class r extends s{constructor(t){super(t);this.api={main:this.main.bind(this),getNormalRoot:()=>o(this.rawFilter),getPromise:t=>this.promises[t]};if(t.callbacks){this.events=["postInit","postRender","firstRender"];this.bus=new i(this.api,this.events,t.callbacks)}}async main(t,i={}){this.dom.controlsTip.hide();this.dom.treeTip.hide();const s="activeCohort"in i?i.activeCohort:this.activeCohort;const o=JSON.stringify(t);if(this.rawCopy==o&&JSON.stringify(this.activeCohort)==JSON.stringify(s))return;await super.main(o,i)}}const a=t(r);export{a as f};
|