@sjcrh/proteinpaint-server 2.18.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cards/bam.json +1 -1
- package/cards/dnanexusTips.txt +10 -10
- package/cards/exprank.json +1 -1
- package/cards/genomepaint.json +1 -1
- package/cards/index.json +25 -27
- package/cards/junction.json +4 -4
- package/cards/pgv.json +1 -1
- package/cards/singlecell.json +1 -1
- package/cards/study.json +1 -1
- package/cards/svview.txt +5 -5
- package/cards/tklist.json +1 -1
- package/package.json +1 -1
- package/server.js +1 -1
package/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var t={4052:(t,e,n)=>{"use strict";n.r(e),n.d(e,{schemeCategory20:()=>r});const r=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"]},6733:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for CNV";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");return-1==o?"gene missing from header":(n[o]="gene",o=r("cnv"),-1==o?"CNV missing from header":(n[o]="cnv",o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.cnv.header=n,e.cnv.loaded=!0,!1))}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.cnv.header.length;t++)s[n.cnv.header[t]]=i[t];if(!s.gene)return void n.cnv.badlines.push([t,"missing gene",i]);if(!s.cnv)return void n.cnv.badlines.push([t,"missing cnv value",i]);switch(s.cnv.toLowerCase()){case"amplification":case"gain":s.class=r.mclasscnvgain;break;case"deletion":case"loss":s.class=r.mclasscnvloss;break;case"loh":s.class=r.mclasscnvloh;break;default:n.cnv.badlines.push([t,"invalid cnv value: "+s.cnv,i]),s.class=null}if(!s.class)return;if(o.parsesample(s,n,t,i,n.cnv.badlines))return;s.dt=r.dtcnv,n.good++;const a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}},5558:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for intragenic deletion";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";if(n[o]="isoform",o=r("rnaposition"),-1!=o){if(n[o]="rnaposition",o=r("rnadellength"),-1==o)return"rnadellength is required when rnaPosition is used";n[o]="rnadellength"}if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("chr_start"),-1==o)return"chr_start is required when chr is used";if(n[o]="chrpos1",o=r("chr_stop"),-1==o)return"chr_stop is required when chr is used";n[o]="chrpos2"}return o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.del.header=n,e.del.loaded=!0,!1}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.del.header.length&&null!=i[t];t++)s[n.del.header[t]]=i[t];if(s.gene){if(s.rnaposition){let e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid rnaPosition value",i]);if(s.rnaposition=e,!s.rnadellength)return void n.del.badlines.push([t,"missing rnaDellength value",i]);if(e=Number.parseInt(s.rnadellength),Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid rnaDellength value",i]);s.rnadellength=e}if(s.chr){let e=Number.parseInt(s.chrpos1);if(Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid chr_start value",i]);if(s.chrpos1=e,e=Number.parseInt(s.chrpos2),Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid chr_stop value",i]);s.chrpos2=e}if(!o.parsesample(s,n,t,i,n.del.badlines)){s.dt=r.dtdel,s.class=r.mclassdel,s.mname="DEL",n.good++;var a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}}else n.del.badlines.push([t,"missing gene",i])}},3602:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for ITD";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";if(n[o]="isoform",o=r("rnaposition"),-1!=o){if(n[o]="rnaposition",o=r("rnaduplength"),-1==o)return"rnaduplength is required when rnaposition is present";n[o]="rnaduplength"}if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("chr_start"),-1==o)return"chr_start is required when chr is present";if(n[o]="chrpos1",o=r("chr_stop"),-1==o)return"chr_stop is required when chr is present";n[o]="chrpos2"}return o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.itd.header=n,e.itd.loaded=!0,!1}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.itd.header.length&&null!=i[t];t++)s[n.itd.header[t]]=i[t];if(s.gene){if(s.rnaposition){let e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid rnaPosition value",i]);if(s.rnaposition=e,!s.rnaduplength)return void n.itd.badlines.push([t,"missing rnaDuplength value",i]);if(e=Number.parseInt(s.rnaduplength),Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid rnaDuplength value",i]);s.rnaduplength=e}if(s.chr){let e=Number.parseInt(s.chrpos1);if(Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid chr_start value",i]);if(s.chrpos1=e,e=Number.parseInt(s.chrpos2),Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid chr_stop value",i]);s.chrpos2=e}if(!o.parsesample(s,n,t,i,n.itd.badlines)){s.dt=r.dtitd,s.class=r.mclassitd,s.mname="ITD",n.good++;var a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}}else n.itd.badlines.push([t,"missing gene",i])}},8064:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>o,init_bulk_flag:()=>i,parsesample:()=>s});var r=n(2273);const o={};function i(t){if(!t)return null;const e={};for(const t in r.mclass)e[r.mclass[t].label.toUpperCase()]=t;return{genome:t,mclasslabel2key:e,data:{},sample2disease:{},patient2st:{},good:0,geneToUpper:!0,snv:{loaded:!1,header:null,badlines:[],missense:0,silent:0},svjson:{loaded:!1,header:null,badlines:[]},fusion:{loaded:!1,header:null,badlines:[],original:[]},sv:{loaded:!1,header:null,badlines:[],original:[]},cnv:{loaded:!1,header:null,badlines:[]},itd:{loaded:!1,header:null,badlines:[]},del:{loaded:!1,header:null,badlines:[]},truncation:{loaded:!1,header:null,badlines:[]}}}function s(t,e,n,o,i){let s=r.moriginsomatic;if(t.sampletype){switch(t.sampletype.toLowerCase()){case"relapse":s=r.moriginrelapse;break;case"germline":s=r.morigingermline}t.sample?t.patient||(t.patient=t.sample+" "+t.sampletype):t.patient&&(t.sample=t.patient+" "+t.sampletype)}else t.patient?t.sample?t.sampletype=t.sample:t.sample=t.sampletype=t.patient:t.sample&&(t.sampletype=t.sample);if(t.origin){switch(t.origin.toLowerCase()){case"r":case"relapse":s=r.moriginrelapse,t.isrim2=!0;break;case"g":case"germline":s=r.morigingermline,t.isrim1=!0;break;case"gp":case"germline pathogenic":s=r.morigingermlinepathogenic,t.isrim1=!0;break;case"gnp":case"germline nonpathogenic":case"germline non-pathogenic":s=r.morigingermlinenonpathogenic,t.isrim1=!0;break;case"s":case"somatic":case"diagnosis":s=r.moriginsomatic}}if(t.origin=s,!t.sample&&!t.patient)return;const a="no patient/individual name";if(t.patient?(e.patient2st[t.patient]||(e.patient2st[t.patient]={}),e.patient2st[t.patient][t.sampletype]=t.sample):(e.patient2st[a]||(e.patient2st[a]={}),e.patient2st[a][t.sampletype]=t.sample),t.sample&&t.disease)if(t.sample in e.sample2disease){if(t.disease!=e.sample2disease[t.sample])return e.snv.badlines.push([n,'conflict of disease types for sample "'+t.sample+'": '+t.disease+", "+e.sample2disease[t.sample],o]),!0}else e.sample2disease[t.sample]=t.disease;return!1}},5494:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for snv/indel";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("annovar_gene","annovar_sj_gene","gene","genename","gene_symbol","hugo_symbol");return-1==o?"gene missing from header":(n[o]="gene",o=r("annovar_aachange","amino_acid_change","annovar_sj_aachange","aachange","protein_change","variant"),-1==o?"amino_acid_change missing from header":(n[o]="mname",o=r("annovar_class","class","mclass","variant_class","variant_classification","annovar_sj_class"),-1==o?"variant_class missing from header":(n[o]="class",o=r("chromosome","chr"),-1==o?"chromosome missing from header":(n[o]="chr",o=r("wu_hg19_pos","start","start_position","chr_position","position"),-1==o?"start missing from header":(n[o]="pos",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o?"isoform missing from header":(n[o]="isoform",o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("quantitative_measurements"),-1!=o&&(n[o]="qmset"),o=r("mutant_reads_in_case","mutant_in_tumor","tumor_readcount_alt"),-1!=o&&(n[o]="maf_tumor_v1"),o=r("total_reads_in_case","total_in_tumor","tumor_readcount_total"),-1!=o&&(n[o]="maf_tumor_v2"),o=r("mutant_reads_in_control","mutant_in_normal","normal_readcount_alt"),-1!=o&&(n[o]="maf_normal_v1"),o=r("total_reads_in_control","total_in_normal","normal_readcount_total"),-1!=o&&(n[o]="maf_normal_v2"),o=r("cdna_change"),-1!=o&&(n[o]="cdna_change"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("cancer","disease","diagnosis"),-1!=o&&(n[o]="disease"),e.snv.header=n,e.snv.loaded=!0,!1))))))}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.snv.header.length&&null!=i[t];t++)s[n.snv.header[t]]=i[t];if(!s.gene)return void n.snv.badlines.push([t,"missing gene",i]);if("UNKNOWN"==s.gene.toUpperCase())return void n.snv.badlines.push([t,"gene name is UNKNOWN",i]);if(!s.isoform)return void n.snv.badlines.push([t,"missing isoform",i]);if(s.mname)0==s.mname.indexOf("p.")&&(s.mname=s.mname.replace(/^p\./,""));else if(s.mname=s.cdna_change,!s.mname)return void n.snv.badlines.push([t,"missing amino acid change",i]);if(!s.class)return void n.snv.badlines.push([t,"missing mutation class",i]);let a=n.mclasslabel2key[s.class.toUpperCase()];if(a)s.class=a;else{if(a=r.mclasstester(s.class),!a)return void n.snv.badlines.push([t,"wrong mutation class: "+s.class,i]);s.class=a}if(o.parsesample(s,n,t,i,n.snv.badlines))return;if(!s.chr)return void n.snv.badlines.push([t,"missing chromosome",i]);if(0!=s.chr.toLowerCase().indexOf("chr")&&(s.chr="chr"+s.chr),!s.pos)return void n.snv.badlines.push([t,"missing chromosome position",i]);const l=Number.parseInt(s.pos);if(Number.isNaN(l))return void n.snv.badlines.push([t,"invalid chromosome position",i]);if(s.pos=l-1,null!=s.maf_tumor_v2&&null!=s.maf_tumor_v1){if(""==s.maf_tumor_v2);else{let e=Number.parseInt(s.maf_tumor_v1),r=Number.parseInt(s.maf_tumor_v2);if(Number.isNaN(e)||Number.isNaN(r))return void n.snv.badlines.push([t,"invalid maf_tumor mutant and/or total read count",i]);s.maf_tumor={f:e/r,v1:e,v2:r}}delete s.maf_tumor_v1,delete s.maf_tumor_v2}if(null!=s.maf_normal_v1&&null!=s.maf_normal_v2){if(""==s.maf_normal_v2);else{let e=Number.parseInt(s.maf_normal_v1),r=Number.parseInt(s.maf_normal_v2);if(Number.isNaN(e)||Number.isNaN(r))return void n.snv.badlines.push([t,"invalid maf_normal mutant and/or total read count",i]);s.maf_normal={f:e/r,v1:e,v2:r}}delete s.maf_normal_v1,delete s.maf_normal_v2}n.good++,"M"==s.class?n.snv.missense++:"S"==s.class&&n.snv.silent++;const c=n.geneToUpper?s.gene.toUpperCase():s.gene;n.data[c]||(n.data[c]=[]),s.dt=r.dtsnvindel,n.data[c].push(s)}},6279:(t,e,n)=>{"use strict";n.r(e),n.d(e,{duplicate:()=>a,parseheader:()=>i,parseline:()=>s});var r=n(8064),o=n(2273);function i(t,e,n){const r=t.toLowerCase().split("\t");if(r.length<=1)return"invalid file header for fusions";const o=(...t)=>{for(const e of t){const t=r.indexOf(e);if(-1!=t)return t}return-1};let i=o("gene_a","gene1","genea");return-1==i?"gene_a missing from header":(r[i]="gene1",i=o("gene_b","gene2","geneb"),-1==i?"gene_b missing from header":(r[i]="gene2",i=o("chr_a","chr1","chra"),-1==i?"chr_a missing from header":(r[i]="chr1",i=o("chr_b","chr2","chrb"),-1==i?"chr_b missing from header":(r[i]="chr2",i=o("pos_a","position_a","position1","posa"),-1==i?"pos_a missing from header":(r[i]="position1",i=o("pos_b","position_b","position2","posb"),-1==i?"pos_b missing from header":(r[i]="position2",i=o("isoform_a","refseq_a","refseq1","isoform1","sv_refseqa"),-1==i?"isoform_a missing from header":(r[i]="isoform1",i=o("isoform_b","refseq_b","refseq2","isoform2","sv_refseqb"),-1==i?"isoform_b missing from header":(r[i]="isoform2",i=o("strand_a","orta"),-1==i?"strand_a missing from header":(r[i]="strand1",i=o("strand_b","ortb"),-1==i?"strand_b missing from header":(r[i]="strand2",i=o("sample","sample_name","tumor_sample_barcode"),-1!=i&&(r[i]="sample"),i=o("patient","donor","target_case_id"),-1!=i&&(r[i]="patient"),i=o("sampletype","sample type","sample_type"),-1!=i&&(r[i]="sampletype"),i=o("disease"),-1!=i&&(r[i]="disease"),i=o("origin"),-1!=i&&(r[i]="origin"),n?(e.sv.loaded=!0,e.sv.header=r):(e.fusion.loaded=!0,e.fusion.header=r),!1))))))))))}function s(t,e,n,i){if(""==e||"#"==e[0])return;const s=e.split("\t"),a={},l=i?n.sv.header:n.fusion.header,c=i?n.sv.badlines:n.fusion.badlines;for(let t=0;t<l.length;t++)a[l[t]]=s[t];if(!a.chr1)return void c.push([t,"missing chr1",s]);if(0!=a.chr1.toLowerCase().indexOf("chr")&&(a.chr1="chr"+a.chr1),!a.chr2)return void c.push([t,"missing chr2",s]);0!=a.chr2.toLowerCase().indexOf("chr")&&(a.chr2="chr"+a.chr2);let u=a.position1;if(!u)return void c.push([t,"missing position1",s]);let f=Number.parseInt(u);if(Number.isNaN(f)||f<=0)c.push([t,"invalid value for position1",s]);else if(a.position1=f,u=a.position2,u){if(f=Number.parseInt(u),Number.isNaN(f)||f<=0)c.push([t,"invalid value for position2",s]);else if(a.position2=f,!r.parsesample(a,n,t,s,c)){if(a.isoform1&&-1!=a.isoform1.indexOf(",")){const t=a.isoform1.split(",");a.isoform1=void 0;for(const e of t)""!=e&&(a.isoform1=e)}if(a.isoform2&&-1!=a.isoform2.indexOf(",")){const t=a.isoform2.split(",");a.isoform2=void 0;for(const e of t)""!=e&&(a.isoform2=e)}if(a.gene1||(a.isoform1=void 0),a.gene2||(a.isoform2=void 0),a.gene1){n.good++;const t={dt:i?o.dtsv:o.dtfusionrna,class:i?o.mclasssv:o.mclassfusionrna,isoform:a.isoform1,mname:a.gene2||a.chr2,sample:a.sample,patient:a.patient,sampletype:a.sampletype,origin:a.origin,disease:a.disease,pairlst:[{a:{name:a.gene1,isoform:a.isoform1,strand:a.strand1,chr:a.chr1,position:a.position1},b:{name:a.gene2,isoform:a.isoform2,strand:a.strand2,chr:a.chr2,position:a.position2}}]},e=n.geneToUpper?a.gene1.toUpperCase():a.gene1;n.data[e]||(n.data[e]=[]),n.data[e].push(t)}if(a.gene2&&a.gene2!=a.gene1){n.good++;const t={dt:i?o.dtsv:o.dtfusionrna,class:i?o.mclasssv:o.mclassfusionrna,isoform:a.isoform2,mname:a.gene1||a.chr1,sample:a.sample,patient:a.patient,sampletype:a.sampletype,origin:a.origin,disease:a.disease,pairlst:[{a:{name:a.gene1,isoform:a.isoform1,strand:a.strand1,chr:a.chr1,position:a.position1},b:{name:a.gene2,isoform:a.isoform2,strand:a.strand2,chr:a.chr2,position:a.position2}}]},e=n.geneToUpper?a.gene2.toUpperCase():a.gene2;n.data[e]||(n.data[e]=[]),n.data[e].push(t)}}}else c.push([t,"missing position2",s])}function a(t){const e={};for(const n in t){if("pairlst"==n)continue;const r=t[n];"object"!=typeof r&&(e[n]=r)}if(t.pairlst){e.pairlst=[];for(const n of t.pairlst){const t={};for(const e in n)"a"!=e&&"b"!=e&&"interstitial"!=e&&(t[e]=n[e]);if(n.a){t.a={};for(const e in n.a){const r=n.a[e];"object"!=typeof r&&(t.a[e]=r)}}if(n.b){t.b={};for(const e in n.b){const r=n.b[e];"object"!=typeof r&&(t.b[e]=r)}}if(n.interstitial){t.interstitial={};for(const e in n.interstitial){const r=n.interstitial[e];"object"!=typeof r&&(t.interstitial[e]=r)}}e.pairlst.push(t)}}return e}},8423:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for svjson";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("sample");return-1!=o&&(n[o]="sample"),o=r("sampletype"),-1!=o&&(n[o]="sampletype"),o=r("patient"),-1!=o&&(n[o]="patient"),o=r("json","jsontext"),-1==o?["json missing from header"]:(n[o]="jsontext",[null,n])}function s(t,e,n,i){if(""==e||"#"==e[0])return;const s=e.split("\t"),l={},c=n.svjson.badlines;for(let t=0;t<i.length;t++)l[i[t]]=s[t];if(!l.jsontext)return void c.push([t,"missing jsontext",s]);if(o.parsesample(l,n,t,s,c))return;let u;try{u=JSON.parse(l.jsontext)}catch(e){return void c.push([t,"invalid JSON text",s])}if(Array.isArray(u))for(const t of u){if(t.a&&t.a.name&&t.a.isoform){n.good++;const e={dt:r.dtfusionrna,class:r.mclassfusionrna,isoform:t.a.isoform,mname:t.b.name};for(const t in l)"jsontext"!=t&&(e[t]=l[t]);e.pairlst=a(u);const o=t.a.name.toUpperCase();n.data[o]||(n.data[o]=[]),n.data[o].push(e)}if(t.b&&t.b.name&&t.b.isoform){n.good++;const e={dt:r.dtfusionrna,class:r.mclassfusionrna,isoform:t.b.isoform,mname:t.a.name};for(const t in l)"jsontext"!=t&&(e[t]=l[t]);e.pairlst=a(u);const o=t.b.name.toUpperCase();n.data[o]||(n.data[o]=[]),n.data[o].push(e)}}else{switch(u.dt=u.typecode,delete u.typecode,u.dt){case r.dtitd:u.class=r.mclassitd,u.mname="ITD";break;case r.dtnloss:u.class=r.mclassnloss,u.mname="N-loss";break;case r.dtcloss:u.class=r.mclasscloss,u.mname="C-loss";break;case r.dtdel:u.class=r.mclassdel,u.mname="Del";break;default:return void c.push([t,"unknown datatype",s])}if(!u.gene)return void c.push([t,"json.gene missing",s]);n.good++;for(const t in l)"jsontext"!=t&&(u[t]=l[t]);const e=(n.geneToUpper,u.gene.toUpperCase());n.data[e]||(n.data[e]=[]),n.data[e].push(u)}}function a(t){const e=[];for(const n of t){const t={a:{},b:{}};for(const e in n)"a"!=e&&"b"!=e&&(t[e]=n[e]);for(const e in n.a)t.a[e]=n.a[e];for(const e in n.b)t.b[e]=n.b[e];e.push(t)}return e}},8235:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for truncation";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";n[o]="isoform";let i=!1;if(o=r("rnaposition"),-1!=o&&(n[o]="rnaposition",i=!0),o=r("losstype"),-1==o)return"lossType missing from header";n[o]="losstype";let s=!1;if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("start","start_position","wu_hg19_pos","chr_position","position"),-1==o)return"genomic position missing from header";n[o]="pos",s=!0}return i||s?(o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.truncation.header=n,e.truncation.loaded=!0,!1):"neither rnaposition nor genomic position is given"}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.truncation.header.length;t++)s[n.truncation.header[t]]=i[t];if(!s.gene)return void n.truncation.badlines.push([t,"missing gene",i]);if(s.rnaposition){const e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.truncation.badlines.push([t,"invalid rnaPosition value",i]);s.rnaposition=e}if(s.pos){const e=Number.parseInt(s.pos);if(Number.isNaN(e)||e<0)return void n.truncation.badlines.push([t,"invalid genomic position",i]);s.pos=e}if(!s.losstype)return void n.truncation.badlines.push([t,"missing lossType value",i]);if("n"!=s.losstype&&"c"!=s.losstype)return void n.truncation.badlines.push([t,'lossType value not "n" or "c"',i]);if(o.parsesample(s,n,t,i,n.truncation.badlines))return;"n"==s.losstype?(s.dt=r.dtnloss,s.class=r.mclassnloss,s.mname="N-loss"):(s.dt=r.dtcloss,s.class=r.mclasscloss,s.mname="C-loss"),n.good++;const a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}},2273:(t,e,n)=>{"use strict";n.r(e),n.d(e,{IN_frame:()=>c,OUT_frame:()=>u,alleleInGenotypeStr:()=>ht,applyOverrides:()=>z,basecolor:()=>ot,basecompliment:()=>it,bplen:()=>rt,codon:()=>tt,codon_stop:()=>et,contigNameNoChr:()=>ut,contigNameNoChr2:()=>ft,custommdstktype:()=>X,default_text_color:()=>a,defaultcolor:()=>s,dt2label:()=>w,dtcloss:()=>b,dtcnv:()=>p,dtdel:()=>y,dtfusionrna:()=>d,dtgeneexpression:()=>h,dtitd:()=>g,dtloh:()=>_,dtnloss:()=>v,dtsnvindel:()=>f,dtsv:()=>m,exoncolor:()=>l,fasta2gmframecheck:()=>lt,germlinelegend:()=>$,getColorScheme:()=>wt,getColors:()=>xt,getMax_byiqr:()=>dt,gmmode:()=>pt,kernelDensityEstimator:()=>yt,kernelEpanechnikov:()=>vt,mclass:()=>x,mclasscloss:()=>S,mclasscnvgain:()=>R,mclasscnvloh:()=>P,mclasscnvloss:()=>I,mclassdel:()=>q,mclassdeletion:()=>B,mclassfusionrna:()=>O,mclassinsertion:()=>D,mclassitd:()=>k,mclassmnv:()=>L,mclassnloss:()=>N,mclassnoncoding:()=>C,mclassnonstandard:()=>T,mclasssnv:()=>F,mclasssv:()=>E,mclasstester:()=>j,mclassutr3:()=>A,mclassutr5:()=>M,mdsvcftype:()=>K,morigin:()=>G,morigingermline:()=>H,morigingermlinenonpathogenic:()=>V,morigingermlinepathogenic:()=>J,moriginrelapse:()=>W,moriginsomatic:()=>U,not_annotated:()=>gt,nt2aa:()=>nt,reversecompliment:()=>st,schemeCategory2:()=>_t,schemeCategory20:()=>bt,spliceeventchangegmexon:()=>at,tkt:()=>Y,validate_vcfinfofilter:()=>ct,validtkt:()=>Q,vcfcopymclass:()=>mt,vepinfo:()=>Z});var r=n(1495);const o=n(2282),i=n(2554),s=(0,r.B8)("#8AB1D4").darker(),a=(0,r.B8)("#aaa").darker().darker(),l="#4F8053",c=!0,u=!1,f=1,d=2,h=3,p=4,m=5,g=6,y=7,v=8,b=9,_=10,w={[f]:"SNV/indel",[d]:"Fusion RNA",[p]:"CNV",[m]:"SV",[g]:"ITD",[y]:"Deletion",[v]:"N-loss",[b]:"C-loss",[_]:"LOH",[h]:"Gene Expression"},x={M:{label:"MISSENSE",color:"#3987CC",dt:f,desc:"A substitution variant in the coding region resulting in altered protein coding.",key:"M"},E:{label:"EXON",color:"#bcbd22",dt:f,desc:"A variant in the exon of a non-coding RNA.",key:"E"},F:{label:"FRAMESHIFT",color:"#db3d3d",dt:f,desc:"An insertion or deletion variant that alters the protein coding frame.",key:"F"},N:{label:"NONSENSE",color:"#ff7f0e",dt:f,desc:"A variant altering protein coding to produce a premature stopgain or stoploss.",key:"N"},S:{label:"SILENT",color:"#2ca02c",dt:f,desc:"A substitution variant in the coding region that does not alter protein coding.",key:"S"},D:{label:"PROTEINDEL",color:"#7f7f7f",dt:f,desc:"A deletion resulting in a loss of one or more codons from the product, but not altering the protein coding frame.",key:"D"},I:{label:"PROTEININS",color:"#8c564b",dt:f,desc:"An insertion introducing one or more codons into the product, but not altering the protein coding frame.",key:"I"},P:{label:"SPLICE_REGION",color:"#9467bd",dt:f,desc:"A variant in an intron within 10 nt of an exon boundary.",key:"P"},L:{label:"SPLICE",color:"#6633FF",dt:f,desc:"A variant near an exon edge that may affect splicing functionality.",key:"L"},Intron:{label:"INTRON",color:"#656565",dt:f,desc:"An intronic variant.",key:"Intron"},Blank:{label:"Not tested",color:"#fff",dt:f,desc:"This gene is not tested.",key:"Blank"},WT:{label:"Wildtype",color:"#D3D3D3",dt:f,desc:"Wildtype",key:"WT"}},k="ITD";x[k]={label:"ITD",color:"#ff70ff",dt:g,desc:"In-frame internal tandem duplication.",key:k};const q="DEL";x[q]={label:"DELETION, intragenic",color:"#858585",dt:y,desc:"Intragenic deletion.",key:q};const N="NLOSS";x[N]={label:"N-terminus loss",color:"#545454",dt:v,desc:"N-terminus loss due to translocation",key:N};const S="CLOSS";x[S]={label:"C-terminus loss",color:"#545454",dt:b,desc:"C-terminus loss due to translocation",key:S};const A="Utr3";x[A]={label:"UTR_3",color:"#998199",dt:f,desc:"A variant in the 3' untranslated region.",key:A};const M="Utr5";x[M]={label:"UTR_5",color:"#819981",dt:f,desc:"A variant in the 5' untranslated region.",key:M};const T="X";x[T]={label:"NONSTANDARD",color:"black",dt:f,desc:"A mutation class that either does not match our notation, or is unspecified.",key:T};const C="noncoding";function j(t){switch(t.toLowerCase()){case"missense_mutation":return"M";case"nonsense_mutation":case"nonstop_mutation":return"N";case"splice_site":return"L";case"rna":case"3'flank":case"5'flank":return C;case"frame_shift_del":case"frame_shift_ins":return"F";case"in_frame_del":return"D";case"in_frame_ins":return"I";case"translation_start_site":return T;case"3'utr":return A;case"5'utr":return M;case"blank":return"Blank";default:return null}}x[C]={label:"NONCODING",color:"black",dt:f,desc:"Noncoding mutation.",key:C};const O="Fuserna";x[O]={label:"Fusion transcript",color:"#545454",dt:d,desc:"Marks the break points leading to fusion transcripts.<br><span style=\"font-size:150%\">◐</span> - 3' end of the break point is fused to the 5' end of another break point in a different gene.<br><span style=\"font-size:150%\">◑</span> - 5' end of the break point is fused to the 3' end of another break point in a different gene.",key:O};const E="SV";x[E]={label:"Structural variation",color:"#858585",dt:m,desc:"Structural variation detected in genomic DNA.",key:E};const R="CNV_amp";x[R]={label:"Copy number gain",color:"#e9a3c9",dt:p,desc:"Copy number gain",key:R};const I="CNV_loss";x[I]={label:"Copy number loss",color:"#a1d76a",dt:p,desc:"Copy number loss",key:I};const P="CNV_loh";x[P]={label:"LOH",color:"#12EDFC",dt:p,desc:"Loss of heterozygosity",key:P};const F="snv";x[F]={label:"SNV",color:"#92a2d4",dt:f,desc:"Single nucleotide variation",key:F};const L="mnv";x[L]={label:"MNV",color:"#92a2d4",dt:f,desc:"Multiple nucleotide variation",key:L};const D="insertion";x[D]={label:"Sequence insertion",color:"#bd8e91",dt:f,desc:"Sequence insertion",key:D};const B="deletion";function z(t={}){if(t.mclass)for(const e in t.mclass){x[e]||(x[e]={});for(const n in t.mclass[e])x[e][n]=t.mclass[e][n]}}x[B]={label:"Sequence deletion",color:"#b5a174",dt:f,desc:"Sequence deletion",key:B};const Z=function(t){const e=t.toLowerCase().split(",");let n=1;return-1!=e.indexOf("transcript_ablation")?[y,q,n]:(n++,-1!=e.indexOf("splice_acceptor_variant")?[f,"L",n]:(n++,-1!=e.indexOf("splice_donor_variant")?[f,"L",n]:(n++,-1!=e.indexOf("stop_gained")?[f,"N",n]:(n++,-1!=e.indexOf("frameshift_variant")?[f,"F",n]:(n++,-1!=e.indexOf("stop_lost")?[f,"N",n]:(n++,-1!=e.indexOf("start_lost")?[f,"N",n]:(n++,-1!=e.indexOf("transcript_amplification")?[f,T,n]:(n++,-1!=e.indexOf("inframe_insertion")||-1!=e.indexOf("conservative_inframe_insertion")||-1!=e.indexOf("disruptive_inframe_insertion")?[f,"I",n]:(n++,-1!=e.indexOf("inframe_deletion")||-1!=e.indexOf("conservative_inframe_deletion")||-1!=e.indexOf("disruptive_inframe_deletion")?[f,"D",n]:(n++,-1!=e.indexOf("missense_variant")?[f,"M",n]:(n++,-1!=e.indexOf("protein_altering_variant")?[f,"N",n]:(n++,-1!=e.indexOf("splice_region_variant")?[f,"P",n]:(n++,-1!=e.indexOf("incomplete_terminal_codon_variant")?[f,"N",n]:(n++,-1!=e.indexOf("stop_retained_variant")?[f,"S",n]:(n++,-1!=e.indexOf("synonymous_variant")?[f,"S",n]:(n++,-1!=e.indexOf("coding_sequence_variant")?[f,T,n]:(n++,-1!=e.indexOf("mature_mirna_variant")?[f,"E",n]:(n++,-1!=e.indexOf("5_prime_utr_variant")?[f,M,n]:(n++,-1!=e.indexOf("3_prime_utr_variant")?[f,A,n]:(n++,-1!=e.indexOf("non_coding_transcript_exon_variant")?[f,"E",n]:(n++,-1!=e.indexOf("intron_variant")?[f,"Intron",n]:(n++,-1!=e.indexOf("nmd_transcript_variant")?[f,"S",n]:(n++,-1!=e.indexOf("non_coding_transcript_variant")?[f,"E",n]:(n++,-1!=e.indexOf("upstream_gene_variant")?[f,C,n]:(n++,-1!=e.indexOf("downstream_gene_variant")?[f,C,n]:(n++,-1!=e.indexOf("tfbs_ablation")?[f,C,n]:(n++,-1!=e.indexOf("tfbs_amplification")?[f,C,n]:(n++,-1!=e.indexOf("tf_binding_site_variant")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_ablation")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_amplification")?[f,C,n]:(n++,-1!=e.indexOf("feature_elongation")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_variant")?[f,C,n]:(n++,-1!=e.indexOf("feature_truncation")?[f,C,n]:(n++,-1!=e.indexOf("intergenic_variant")?[f,C,n]:(n++,[f,T,n])))))))))))))))))))))))))))))))))))},$='<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle><path d="M6.735557395310443e-16,-11A11,11 0 0,1 11,0L9,0A9,9 0 0,0 5.51091059616309e-16,-9Z" transform="translate(7,12)" fill="#858585" stroke="none"></path>',G={},U="S";G[U]={label:"Somatic",desc:"A variant found only in a tumor sample. The proportion is indicated by lack of any arc.",legend:'<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle>'};const H="G";G[H]={label:"Germline",desc:"A constitutional variant found in a normal sample. The proportion is indicated by the span of the solid arc within the whole circle.",legend:$},G.germline=G[H],G.somatic=G[U];const W="R";G[W]={label:"Relapse",desc:"A somatic variant found only in a relapse sample. The proportion is indicated by the span of the hollow arc within the whole circle.",legend:'<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle><path d="M6.735557395310443e-16,-11A11,11 0 0,1 11,0L9,0A9,9 0 0,0 5.51091059616309e-16,-9Z" transform="translate(7,12)" fill="none" stroke="#858585"></path>'};const J="GP";G[J]={label:"Germline pathogenic",desc:"A constitutional variant with pathogenic allele.",legend:$};const V="GNP";G[V]={label:"Germline non-pathogenic",desc:"A constitutional variant with non-pathogenic allele.",legend:$,hidden:!0};const Y={usegm:"usegm",ds:"dataset",bigwig:"bigwig",bigwigstranded:"bigwigstranded",junction:"junction",mdsjunction:"mdsjunction",mdscnv:"mdscnv",mdssvcnv:"mdssvcnv",mdsexpressionrank:"mdsexpressionrank",mdsvcf:"mdsvcf",bedj:"bedj",pgv:"profilegenevalue",bampile:"bampile",hicstraw:"hicstraw",expressionrank:"expressionrank",aicheck:"aicheck",ase:"ase",mds2:"mds2",mds3:"mds3",bedgraphdot:"bedgraphdot",bam:"bam",ld:"ld"};function Q(t){for(const e in Y)if(t==Y[e])return!0;return!1}const K={vcf:"vcf"},X={vcf:"vcf",svcnvitd:"svcnvitd",geneexpression:"geneexpression"},tt={GCT:"A",GCC:"A",GCA:"A",GCG:"A",CGT:"R",CGC:"R",CGA:"R",CGG:"R",AGA:"R",AGG:"R",AAT:"N",AAC:"N",GAT:"D",GAC:"D",TGT:"C",TGC:"C",CAA:"Q",CAG:"Q",GAA:"E",GAG:"E",GGT:"G",GGC:"G",GGA:"G",GGG:"G",CAT:"H",CAC:"H",ATT:"I",ATC:"I",ATA:"I",TTA:"L",TTG:"L",CTT:"L",CTC:"L",CTA:"L",CTG:"L",AAA:"K",AAG:"K",ATG:"M",TTT:"F",TTC:"F",CCT:"P",CCC:"P",CCA:"P",CCG:"P",TCT:"S",TCC:"S",TCA:"S",TCG:"S",AGT:"S",AGC:"S",ACT:"T",ACC:"T",ACA:"T",ACG:"T",TGG:"W",TAT:"Y",TAC:"Y",GTT:"V",GTC:"V",GTA:"V",GTG:"V"},et="*";function nt(t){if(!t.genomicseq)return;const e=[];if(t.coding)for(const[n,r]of t.coding.entries()){const n=t.genomicseq.substr(r[0]-t.start,r[1]-r[0]);"-"==t.strand?e.push(st(n)):e.push(n)}const n=e.join(""),r=[];for(let e=t.startCodonFrame?3-t.startCodonFrame:0;e<n.length;e+=3){const t=tt[n.substr(e,3)];r.push(t||et)}return t.cdseq=n,r.join("")}function rt(t,e){return t>=1e9?(t/1e9).toFixed(1)+" Gb":t>=1e7?Math.ceil(t/1e6)+" Mb":t>=1e6?(t/1e6).toFixed(1)+" Mb":t>=1e4?Math.ceil(t/1e3)+" Kb":t>=1e3?(t/1e3).toFixed(1)+" Kb":t+(e?"bytes":" bp")}const ot={A:"#ca0020",T:"#f4a582",C:"#92c5de",G:"#0571b0"};function it(t){switch(t){case"A":return"T";case"T":return"A";case"C":return"G";case"G":return"C";case"a":return"t";case"t":return"a";case"c":return"g";case"g":return"c";default:return t}}function st(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(it(t[n]));return e.join("")}function at(t,e){const n={chr:t.chr,start:t.start,stop:t.stop,strand:t.strand,coding:[]};if(e.isskipexon||e.isaltexon)for(let r=0;r<t.exon.length;r++){const o=Math.max(t.codingstart,t.exon[r][0]),i=Math.min(t.codingstop,t.exon[r][1]);o>i||-1==e.skippedexon.indexOf(r)&&n.coding.push([o,i])}else if(e.a5ss||e.a3ss){const r=t.exon.map((t=>[t[0],t[1]])),o="+"==t.strand;e.a5ss?o?r[e.exon5idx][1]=e.junctionB.start:r[e.exon5idx+1][0]=e.junctionB.stop:o?r[e.exon5idx+1][0]=e.junctionB.stop:r[e.exon5idx][1]=e.junctionB.start;for(const e of r){const r=Math.max(t.codingstart,e[0]),o=Math.min(t.codingstop,e[1]);r>o||n.coding.push([r,o])}}return n}function lt(t,e){const n=e.split("\n");n.shift(),t.genomicseq=n.join("").toUpperCase();const r=nt(t);let o=u;return r.indexOf(et)==r.length-1&&(o=c),o}function ct(t){if(!t.lst)return".lst missing";if(!Array.isArray(t.lst))return"input is not an array";for(const e of t.lst){if(!e.name)return"name missing from a set of .vcfinfofilter.lst";if(e.autocategory||e.categories){if(!e.autocategory)for(const t in e.categories){const n=e.categories[t];if(!e.autocolor&&!n.color)return".color missing for class "+t+" from .categories of set "+e.name;n.label||(n.label=t)}if(e.categoryhidden){for(const t in e.categoryhidden)if(!e.categories[t])return"unknown hidden-by-default category "+t+" from set "+e.name}else e.categoryhidden={}}else if(e.numericfilter){const t=[];for(const n of e.numericfilter)"number"==typeof n?t.push({side:"<",value:n}):t.push({side:n.side||"<",value:n.value});e.numericfilter=t}if(e.altalleleinfo){if(!e.altalleleinfo.key)return".key missing from .altalleleinfo from set "+e.name}else{if(!e.locusinfo)return"neither .altalleleinfo or .locusinfo is available from set "+e.name;if(!e.locusinfo.key)return".key missing from .locusinfo from set "+e.name}}}function ut(t,e){for(const n in t.majorchr)if(-1!=e.indexOf(n.replace("chr","")))return!0;if(t.minorchr)for(const n in t.minorchr)if(-1!=e.indexOf(n.replace("chr","")))return!0;return!1}function ft(t,e){let n=0,r=0;for(const o in t.majorchr)e.includes(o)?r++:e.includes(o.replace("chr",""))&&n++;if(t.minorchr)for(const o in t.minorchr)e.includes(o)?r++:e.includes(o.replace("chr",""))&&n++;return[n,r]}function dt(t,e){if(0==t.length)return e;t.sort(((t,e)=>t-e));const n=t[t.length-1];if(t.length<=5)return n;const r=t[Math.floor(t.length/4)],o=t[Math.floor(3*t.length/4)];return Math.min(o+1.5*(o-r),n)}function ht(t,e){return!!t&&(-1!=t.indexOf("/")?-1!=t.split("/").indexOf(e):-1!=t.split("|").indexOf(e))}const pt={genomic:"genomic",splicingrna:"splicing RNA",exononly:"exon only",protein:"protein",gmsum:"aggregated exons"};function mt(t,e){if(t.csq){let n;if(e.usegm&&(n=t.csq.find((t=>t._isoform==e.usegm.isoform))),!n&&(n=t.csq.find((t=>t.CANONICAL)),!n)){n=t.csq[0];for(const e of t.csq)e._csqrank<n._csqrank&&(n=e)}n&&(t.gene=n._gene,t.isoform=n._isoform,t.class=n._class,t.dt=n._dt,t.mname=n._mname,t.class==C&&delete t.class)}else if(t.ann){let n=null;if(e.usegm){for(const r of t.ann)r._isoform==e.usegm.isoform&&(n?r._csqrank<n._csqrank&&(n=r):n=r);n||e.gmmode!=pt.genomic||(n=t.ann[0])}else{n=t.ann[0];for(const e of t.ann)e._csqrank<n._csqrank&&(n=e)}n&&(t.gene=n._gene,t.isoform=n._isoform,t.class=n._class,t.dt=n._dt,t.mname=n._mname,t.class==C&&delete t.class)}null==t.class&&(x[t.type]?(t.class=t.type,t.dt=x[t.type].dt,t.mname=t.id&&"."!=t.id?t.id:t.ref+">"+t.alt,t.mname.length>15&&(t.mname=t.type)):(t.class=T,t.dt=f,t.mname=t.type)),delete t.type}const gt="Unannotated";function yt(t,e){return function(n){return e.map((e=>[e,n.map((n=>t(e-n))).reduce(((t,e)=>t+e),0)/n.length]))}}function vt(t){return function(e){return Math.abs(e/=t)<=1?.75*(1-e*e)/t:0}}const bt=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],_t=["#e75480","blue"];function wt(t){return t>12?bt:t>8?i.schemePaired:t>2?i.schemeDark2:_t}function xt(t){return o.scaleOrdinal(wt(t))}},7027:(t,e,n)=>{"use strict";function r(t,e){t.sort(((t,e)=>t-e));const n=Math.abs(e/100*t.length-1);return Number.isInteger(n)?(t[n]+t[n+1])/2:t[Math.ceil(n)]}n.d(e,{Z:()=>r})},478:(t,e,n)=>{"use strict";function r(t,e){i(e);const n=new Set;for(const r of t){if(n.has(r.sample))continue;const t=r.s||r.data;t&&o(t,e)&&n.add(r.sample)}return n}function o(t,e){const n="tvslst"==e.type?e.lst:[e];let r=0;for(const i of n){if("tvslst"==i.type)o(t,i)&&r++;else{const e=i.tvs,n=t[e.term.id];let o;if("categorical"==e.term.type){if(void 0===n)continue;o=e.valueset.has(n)}else if("integer"==e.term.type||"float"==e.term.type){if(void 0===n)continue;for(const t of e.ranges){if("value"in t){if(o=n===t.value,o)break}else{if(e.term.values){const t=e.term.values[n.toString()];if(t&&t.uncomputable)continue}let r,i;t.startunbounded?r=!0:"start"in t&&(r=t.startinclusive?n>=t.start:n>t.start),t.stopunbounded?i=!0:"stop"in t&&(i=t.stopinclusive?n<=t.stop:n<t.stop),o=r&&i}if(o)break}}else{if("condition"!=e.term.type)throw"unknown term type";{const t=s(e),r=n&&n[t];r&&(o=Array.isArray(r)?e.values.find((t=>r.includes(t.key))):e.values.find((t=>t.key==r)))}}e.isnot&&(o=!o),o&&r++}if("or"==e.join){if(r&&e.in)return!0;if(!r&&!e.in)return!0}}return e.in==(r==n.length)}function i(t,e=null){if("tvslst"==t.type)for(const n of t.lst)i(n,e);else e&&"function"==typeof e.setAnnoByTermId&&e.setAnnoByTermId(t.tvs.term.id),"categorical"==t.tvs.term.type&&(t.tvs.valueset=new Set(t.tvs.values.map((t=>t.key))))}function s(t){const e=t.bar_by_children&&t.value_by_max_grade?"childrenAtMaxGrade":t.bar_by_children&&t.value_by_most_recent?"childrenAtMostRecent":t.bar_by_children&&t.value_by_computable_grade?"children":t.bar_by_grade&&t.value_by_max_grade?"maxGrade":t.bar_by_grade&&t.value_by_most_recent?"mostRecentGrades":t.bar_by_grade&&t.value_by_computable_grade?"computableGrades":"";if(!e)throw"unknown condition term bar_by_* and/or value_by_*";return e}function a(t){if(!t||0==t.length)return;let e=JSON.parse(JSON.stringify(t[0]));if(1==t.length)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("or"==e.join)e={type:"tvslst",join:"and",in:!0,lst:[e]};else if("and"!=e.join)throw'filter.join must be either "and" or "or" when .lst length > 1';for(let n=1;n<t.length;n++){const r=JSON.parse(JSON.stringify(t[n]));"or"==r.join?e.lst.push(r):e.lst.push(...r.lst)}return 1==e.lst.length&&"tvs"==e.lst[0].type&&(e.join=""),e}n.r(e),n.d(e,{filterJoin:()=>a,getFilteredSamples:()=>r,sample_match_termvaluesetting:()=>o,setDatasetAnnotations:()=>i})},2235:(t,e,n)=>{"use strict";function r(t,e){if(t.startunbounded){if(t.stopunbounded)throw"both start & stop are unbounded from "+e;if(!Number.isFinite(t.stop))throw".stop undefined when start is unbounded from "+e}else if(t.stopunbounded){if(!Number.isFinite(t.start))throw".start undefined when stop is unbounded from "+e}else{if(!Number.isFinite(t.start))throw".start undefined when start is not unbounded from "+e;if(!Number.isFinite(t.stop))throw".stop undefined when stop is not unbounded from "+e;if(t.start>=t.stop)throw".start is not lower than stop from "+e}}n.d(e,{r:()=>r})},5684:(t,e,n)=>{"use strict";function r(t,e){const n=Number(t);return Number.isInteger(n)?n:Math.abs(n)<1?Number(n.toPrecision(e)):Number(n.toFixed(e))}n.d(e,{Z:()=>r})},4048:(t,e,n)=>{"use strict";n.r(e),n.d(e,{compute_bins:()=>a,get_bin_label:()=>c,get_bin_range_equation:()=>u,target_percentiles:()=>f,validate_bins:()=>s});var r=n(2163),o=n(2273);function i(t){return!isNaN(parseFloat(t))&&isFinite(t)}function s(t){const e=t;if(!e||"object"!=typeof e)throw"bin schema must be an object";if("type"in e||(e.type="regular-bin"),"custom-bin"==e.type){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],n=e.lst[e.lst.length-1];for(const r of e.lst){if(!("startinclusive"in r)&&!("stopinclusive"in r))throw"custom bin.startinclusive and/or bin.stopinclusive must be defined";if(r==t){if("startunbounded"in r&&!r.startunbounded)throw"a custom first bin must not set bin.startunbounded to false";if(r.startunbounded=!0,"start"in r)throw"a custom first bin must not set a bin.start value";if("start_percentile"in r)throw"the first bin must not set a bin.start_percentile value";if(!("stop"in r))throw"a custom first bin must define a bin.stop value";if(!i(r.stop))throw"a custom first bin.stop value should be numeric"}else if(r==n){if(!("start"in r))throw"a custom last bin must define a bin.start value";if(!i(r.start))throw"a custom last bin.start must be numeric";if("stopunbounded"in r&&!r.stopunbounded)throw"a custom last bin must not set bin.stopunbounded to false";if(r.stopunbounded=!0,"stop"in r)throw"a custom last bin must not set a bin.stop value"}else{if(!i(r.start))throw"bin.start must be numeric for a non-first bin";if(!i(r.stop))throw"bin.stop must be numeric for a non-last bin"}}}else{if("regular-bin"!=e.type)throw`invalid binconfig.type="${e.type}"`;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),!e.first_bin)throw"first_bin{} missing";if("object"!=typeof e.first_bin)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;if(t.startunbounded=!0,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";if(t.stopunbounded=!0,"stop"in t)throw"a regular last bin must not set a bin.stop value"}}}function a(t,e){const n=t;if(s(n),n.lst){const t=(0,o.getColors)(n.lst.length);for(const e of n.lst)e.color=t(e.label)}if("custom-bin"==n.type)return JSON.parse(JSON.stringify(n.lst));if("function"!=typeof e)throw"summaryfxn required for modules/termdb.bins.js compute_bins()";const r=e(f(n));if(!r||"object"!=typeof r)throw"invalid returned value by summaryfxn";n.results={summary:r},n.binLabelFormatter||(n.binLabelFormatter=l(n));const a=Math.floor(100*r.min)/100,u=Math.ceil(100*r.max)/100,d=n.first_bin.startunbounded?a:n.first_bin.start_percentile?r["p"+n.first_bin.start_percentile]:n.first_bin.start;let h,p,m=u;if(n.last_bin)m=n.last_bin.stopunbounded?u:n.last_bin.stop_percentile?r["p"+n.last_bin.stop_percentile]:i(n.last_bin.stop)&&n.last_bin.stop<=r.max?n.last_bin.stop:u,h=i(n.last_bin.start_percentile)?r["p"+n.last_bin.start_percentile]:i(n.last_bin.start)?n.last_bin.start:void 0,p=n.last_bin.stopunbounded?null:n.last_bin.stop_percentile?r["p"+n.last_bin.stop_percentile]:i(n.last_bin.stop)?n.last_bin.stop:null;else if(n.lst){const t=n.lst[n.lst.length-1];h=t.start,p="stop"in t&&!t.stopunbounded?t.stop:u,m=p}else h=u,p=u;const g=i(m),y=i(h),v=i(p);if(!g&&!y)return[];const b=[];let _={startunbounded:n.first_bin.startunbounded,start:n.first_bin.startunbounded?void 0:d,stop:i(n.first_bin.stop_percentile)?+r["p"+n.first_bin.stop_percentile]:i(n.first_bin.stop)?+n.first_bin.stop:d+n.bin_size,startinclusive:n.startinclusive,stopinclusive:n.stopinclusive};if(!i(_.stop))throw"the computed first_bin.stop is non-numeric"+_.stop;for(;(g&&_.stop<=m||_.startunbounded&&!b.length||_.stopunbounded)&&(b.push(_),_.stop>=m&&(_.stopunbounded=!0,b.length>1&&delete _.stop),_.label=c(_,n),!_.stopunbounded);){const t=_.stop+n.bin_size,e=_.stop;if(_={startinclusive:n.startinclusive,stopinclusive:n.stopinclusive,start:e,stop:v&&(e==h||t>p)?p:y&&t>h&&e!=h?h:t},_.stop>=m&&(_.stop=m,n.last_bin&&n.last_bin.stopunbounded&&(_.stopunbounded=1),n.last_bin&&n.last_bin.stopinclusive&&(_.stopinclusive=1)),y&&_.start==h&&n.last_bin&&n.last_bin.stopunbounded&&(_.stopunbounded=1),_.start>_.stop){if(!(y&&_.stop==h&&n.last_bin&&n.last_bin.stopunbounded))break;_.stopunbounded=!0}if(b.length+1>=100){n.error="max_num_bins_reached";break}}delete n.binLabelFormatter,b.length>1&&delete b[b.length-1].stop;const w=(0,o.getColors)(b.length);for(const t of b)t.color=w(t.label);return b}function l(t){return"rounding"in t?(0,r.WU)(t.rounding):t=>t}function c(t,e){const n=e;n.binLabelFormatter||(n.binLabelFormatter=l(n)),t.startunbounded||t.stopunbounded||"startinclusive"in t||"stopinclusive"in t||(n.startinclusive?t.startinclusive=!0:n.stopinclusive&&(t.stopinclusive=!0));const r="bins"==n.use_as||t.start,o="bins"==n.use_as||t.stop;let i=0;if("label_offset"in n?(n.label_offset_ignored="bin_size"in n&&n.bin_size<n.label_offset,n.label_offset_ignored||(i=n.label_offset)):1===n.bin_size&&"integer"==n.termtype&&(i=1),t.startunbounded){return(t.stopinclusive?"≤":"<")+n.binLabelFormatter(o)}if(t.stopunbounded||r===o){return(t.startinclusive?"≥":">")+n.binLabelFormatter(r)}if(i&&t.startinclusive&&!t.stopinclusive){if(Number.isInteger(n.bin_size)&&Math.abs(r-o)===i)return""+n.binLabelFormatter(r);{const t=n.binLabelFormatter(r),e=n.binLabelFormatter(o-i);return+t>=+e?t.toString():t+" to "+e}}{const e=t.startinclusive?"":">",i=t.stopinclusive?"":"<",s=Number.isInteger(r)?r:n.binLabelFormatter(r),a=Number.isInteger(o)?o:n.binLabelFormatter(o);if(+s>=+a){return(t.startinclusive?"≥":">")+s}return e+s+" to "+i+a}}function u(t,e){const n='<span style="font-family:Times;font-style:italic;">x</span>';let r;const o=c(t,e);return t.startunbounded||t.stopunbounded?r=n+" "+o:t.startinclusive?r=o.replace("to <","≤ "+n+" <"):t.stopinclusive&&(r=o.replace(">","").replace("to","< "+n+" ≤")),r}function f(t){const e=[],n=t.first_bin;n&&i(n.start_percentile)&&e.push(n.start_percentile),n&&i(n.stop_percentile)&&e.push(n.stop_percentile);const r=t.last_bin;return r&&i(r.start_percentile)&&e.push(r.start_percentile),r&&i(r.stop_percentile)&&e.push(r.stop_percentile),e}},1575:(t,e,n)=>{"use strict";n.r(e),n.d(e,{graphableTypes:()=>o,isUsableTerm:()=>i,nonDictionaryTermTypes:()=>r});const r=new Set(["snplst","prs","snplocus","geneVariant","samplelst"]),o=new Set(["categorical","integer","float","condition","survival","snplst","snplocus","geneVariant","samplelst"]);function i(t,e,n){const r=e||{};if(n&&n.usecase&&use.target in n.usecase)return n.usecase[use.target](t,use);const i=new Set,l=t.child_types||[];switch(r.target){case"barchart":case"summary":case"matrix":return"term0"==r.detail&&"geneVariant"==t.type||("term2"==r.detail&&"geneVariant"==t.type&&"geneVariant"==r.term1type||(t.type&&"survival"!==t.type&&i.add("plot"),s(l)&&i.add("branch"))),i;case"table":return"term"==r.detail&&i.add("plot"),l.length>1&&i.add("branch"),i;case"scatterplot":return"float"!=t.type&&"integer"!=t.type||i.add("plot"),a(l)&&i.add("branch"),i;case"sampleScatter":return"numeric"==r.detail?("float"!=t.type&&"integer"!=t.type||i.add("plot"),a(l)&&i.add("branch")):(o.has(t.type)&&i.add("plot"),t.isleaf||i.add("branch")),i;case"boxplot":return"float"!=t.type&&"integer"!=t.type||i.add("plot"),"term2"===r.detail&&a(l)&&i.add("branch"),i;case"cuminc":if("term"==r.detail)return"condition"==t.type&&i.add("plot"),l.includes("condition")&&i.add("branch"),i;if("term2"===r.detail)return t.type&&"survival"!=t.type&&i.add("plot"),s(l)&&i.add("branch"),i;if("term0"==r.detail)return i.add("plot"),i;case"survival":return"term"==r.detail?("survival"==t.type&&i.add("plot"),l.includes("survival")&&i.add("branch"),i):"term2"===r.detail?("survival"!=t.type&&(t.type&&i.add("plot"),s(l)&&i.add("branch")),i):"term0"==r.detail?(t.type&&i.add("plot"),s(l)&&i.add("branch"),i):(t.isleaf?i.add("plot"):i.add("branch"),i);case"regression":if("outcome"==r.detail){if("linear"==r.regressionType)return"float"!=t.type&&"integer"!=t.type||i.add("plot"),a(l)&&i.add("branch"),i;if("logistic"==r.regressionType)return t.type&&"survival"!=t.type&&i.add("plot"),s(l)&&i.add("branch"),i;if("cox"==r.regressionType)return"condition"==t.type&&i.add("plot"),l.includes("condition")&&i.add("branch"),i}if("independent"==r.detail)return"float"!=t.type&&"integer"!=t.type&&"categorical"!=t.type||i.add("plot"),function(t,e){for(const n of e)if(t.includes(n))return!0}(l,["categorical","float","integer"])&&i.add("branch"),i;default:return o.has(t.type)&&i.add("plot"),t.isleaf||i.add("branch"),i}}function s(t){return!!t.length&&(t.length>1||"survival"!=t[0])}function a(t){return t.includes("float")||t.includes("integer")}},1881:(t,e,n)=>{"use strict";n.r(e),n.d(e,{stratinput:()=>o});const r="root";function o(t,e){const n=Object.create(null),o=Object.create(null),s=Object.create(null);for(const r of t)for(const[t,a]of e.entries()){const l=i(r,t,e),c=i(r,t-1,e);if(!r[a.k]){t>0&&(s[c]+=1);break}if(n[l]=c,l in s||(s[l]=0),!(l in o)){const n={lst:[]};a.full&&(n.full=r[a.full]),n.id0=e[0].k,n.v0=r[e[0].k],1==t&&(n.id1=e[1].k,n.v1=r[e[1].k]),2==t&&(n.id2=e[2].k,n.v1=r[e[2].k]),o[l]=n}o[l].lst.push(r),t==e.length-1&&(s[l]+=1)}const a=[{id:r,name:r}];for(const t in n){const e=n[t],r=o[t],i=t.split("...");a.push({id:t,parentId:e,lst:r.lst,value:s[t],name:i[i.length-1],full:r.full,id0:r.id0,v0:r.v0,id1:r.id1,v1:r.v1,id2:r.id2,v2:r.v2})}return a}function i(t,e,n){const o=[r];for(let r=0;r<e;r++)o.push(t[n[r].k]);return e>=0&&o.push(t[n[e].k]),o.join("...")}},4298:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parse_CSQ:()=>o});var r=n(2273);function o(t,e,n){if(!e)return null;for(const o of t.split(",")){const t=o.replace(/&/g,",").split("|"),i={};for(let n=0;n<e.length;n++)t[n]&&(i[e[n].name]=t[n]);if(!i.Allele)continue;let s=null;for(const t of n.mlst||n.alleles)if(t.allele_original==i.Allele){s=t;break}if(!s){if("-"==i.Allele)n.mlst?1==n.mlst.length&&(s=n.mlst[0]):n.alleles&&1==n.alleles.length&&(s=n.alleles[0]);else for(const t of n.mlst||n.alleles)if(t.allele_original.substr(1)==i.Allele){s=t;break}if(!s)continue}if(s.csq||(s.csq=[]),s.csq.push(i),i._gene=i.SYMBOL||i.Gene,i.Feature_type&&"Transcript"==i.Feature_type?i._isoform=i.Feature.split(".")[0]:i._isoform=i._gene,i.Consequence){const[t,e,n]=(0,r.vepinfo)(i.Consequence);i._dt=t,i._class=e,i._csqrank=n}else i._dt=dtsnvindel,i._class=mclassnonstandard;i.HGVSp?i._mname=decodeURIComponent(i.HGVSp.substr(i.HGVSp.indexOf(":")+1)):i.Protein_position&&i.Amino_acids?i._mname=decodeURIComponent(i.Protein_position+i.Amino_acids):i.HGVSc?i._mname=i.HGVSc.substr(i.HGVSc.indexOf(":")+1):i.Existing_variation&&(i._name=i.Existing_variation)}return!0}},9380:(t,e,n)=>{"use strict";function r(t){let e=!1,n=!0,r=0,o=0;const i={};let s;for(;r<t.length;){const a=t[r];n?"="==a?(e=!0,n=!1,s=t.substring(o,r),o=r+1):";"==a&&(i[t.substring(o,r)]=1,o=r+1):e&&";"==a&&(n=!0,e=!1,i[s]=t.substring(o,r),s=null,o=r+1),r++}const a=t.substr(o,r);return s?i[s]=a:i[a]=1,i}n.r(e),n.d(e,{dissect_INFO:()=>r})},6819:(t,e,n)=>{"use strict";n.r(e),n.d(e,{vcfparseline:()=>d,vcfparsemeta:()=>f});var r=n(2273),o=n(9380),s=n(4298);function a(t,e,n){if(!e)return null;for(const o of t.split(",")){const t=o.replace(/&/g,",").split("|"),i={};for(let n=0;n<e.length;n++)t[n]&&(i[e[n].name]=t[n]);if(!i.Allele)continue;let s=null;for(const t of n.alleles)if(t.allele==i.Allele){s=t;break}if(s){if(s.ann||(s.ann=[]),s.ann.push(i),i._gene=i.Gene_Name,i.Feature_Type&&"transcript"==i.Feature_Type&&i.Feature_ID&&(i._isoform=i.Feature_ID.split(".")[0]),i.Annotation){const[t,e,n]=(0,r.vepinfo)(i.Annotation);i._dt=t,i._class=e,i._csqrank=n}else i._dt=dtsnvindel,i._class=mclassnonstandard;i["HGVS.p"]?i._mname=i["HGVS.p"]:i["HGVS.c"]&&(i._mname=i["HGVS.c"])}}return!0}var l=n(736);const c=new RegExp(/<(.+)>/),u={};for(const t in r.mclass)u[r.mclass[t].label.toUpperCase()]=t;function f(t){let e=[],n=[],r={},o=!1,i={},s=!1;for(const a of t)if(a.startsWith("#"))if(a.startsWith("#C"))e=a.split("\t").slice(9);else if(a.startsWith("##INFO")){const t=p(a.substring(8,a.length-1),r);t?n.push("INFO error: "+t):o=!0}else if(a.startsWith("##FORMAT")){const t=p(a.substring(10,a.length-1),i);t?n.push("FORMAT error: "+t):s=!0}const a=[];for(const t of e){const e={name:t};a.push(e)}if(r.CSQ){const t=r.CSQ.Description.split(" Format: ");if(t[1]){const e=t[1].split("|");if(e.length>1){r.CSQ.csqheader=[];for(const t of e){const e={name:t};r.CSQ.csqheader.push(e)}}else n.push("unknown format for CSQ header: "+r.CSQ.Description)}else n.push("unknown format for CSQ header: "+r.CSQ.Description)}if(r.ANN){const t=r.ANN.Description.split("'");if(t[1]){const e=t[1].split(" | ");if(e.length){r.ANN.annheader=[];for(const t of e){const e={name:t};r.ANN.annheader.push(e)}}else n.push('no " | " joined annotation fields for ANN (snpEff annotation): '+r.ANN.Description)}else n.push("no single-quote enclosed annotation fields for ANN (snpEff annotation): "+r.ANN.Description)}return[o?r:null,s?i:null,a,n.length?n:null]}function d(t,e){const n=t.split("\t");if(n.length<8)return["line has less than 8 fields",null,null];const r=Number.parseInt(n[1]);if(!Number.isInteger(r))return["invalid value for genomic position",null,null];const i=n[3],u={vcf_ID:n[2],chr:(e.nochr?"chr":"")+n[0],pos:r-1,ref:i,altstr:n[4],alleles:[{allele:i,sampledata:[]}],info:{},name:"."==n[2]?null:n[2]},f=[];for(const t of n[4].split(",")){const e={ref:u.ref,allele:t,allele_original:t,sampledata:[],_m:u,info:{}};if(u.alleles.push(e),"<"==t[0]){const n=t.match(c);if(!n){f.push(t);continue}e.type=n[1],e.allele=n[1],e.issymbolicallele=!0}else{const[t,n,r]=h(u.pos,u.ref,e.allele);e.pos=t,e.ref=n,e.allele=r}}n[8]&&n[9]&&function(t,e,n){const r=t[8].split(":");for(let o=9;o<t.length;o++){const i=t[o].split(":");{let t=!0;for(const e of i)if("."!=e){t=!1;break}if(t)continue}const s=o-9;for(let t=1;t<e.alleles.length;t++){const r={};if(n.samples&&n.samples[s])for(const t in n.samples[s])r[t]=n.samples[s][t];else r.name="missing_samplename_from_vcf_header";e.alleles[t].sampledata.push({sampleobj:r})}for(let t=0;t<r.length;t++){const o=r[t],s=i[t];if("."==s)continue;if("GT"==o){const t=-1!=s.indexOf("/")?"/":"|";let n=0,r=!1;const o=[];for(const i of s.split(t)){if("."==i){r=!0;continue}const t=Number.parseInt(i);if(Number.isNaN(t)){r=!0;continue}n+=t;const s=e.alleles[t];s&&o.push(s.allele)}let i=!1;r||(i=0==n);const a=o.join(t);for(let t=1;t<e.alleles.length;t++){const n=e.alleles[t].sampledata[e.alleles[t].sampledata.length-1];n.GT=s,n.genotype=a,i&&(n.gtallref=!0),n.__gtalleles=o}continue}const a=n.format?n.format[o]:null;if(!a){for(let t=1;t<e.alleles.length;t++)e.alleles[t].sampledata[e.alleles[t].sampledata.length-1][o]=s;continue}const l="Integer"==a.Type,c="Float"==a.Type;if(a.Number&&"R"==a.Number||"AD"==o){const t=s.split(",").map((t=>l?Number.parseInt(t):c?Number.parseFloat(t):t));for(let n=1;n<e.alleles.length;n++)if(null!=t[n]){const r=e.alleles[n],i=r.sampledata[r.sampledata.length-1];i[o]={},i[o][r.ref]=t[0],i[o][r.allele]=t[n]}}else if(a.Number&&"A"==a.Number){const t=s.split(",").map((t=>l?Number.parseInt(t):c?Number.parseFloat(t):t));for(let n=1;n<e.alleles.length;n++)if(null!=t[n-1]){const r=e.alleles[n],i=r.sampledata[r.sampledata.length-1];i[o]={},i[o][r.allele]=t[n-1]}}else for(let t=1;t<e.alleles.length;t++)e.alleles[t].sampledata[e.alleles[t].sampledata.length-1][o]=s}}for(const t of e.alleles)for(const e of t.sampledata)if(e.AD){e.allele2readcount={};for(const t in e.AD)e.allele2readcount[t]=e.AD[t]}}(n,u,e),u.alleles.shift();const d="."==n[7]?[]:(0,o.dissect_INFO)(n[7]);let p=[];e.info?p=function(t,e,n){const r=[];for(const o in t){if(null==n.info[o]){r.push(o);continue}const i=t[o];if("CSQ"==o){(0,s.parse_CSQ)(i,n.info.CSQ.csqheader,e)||(e.info[o]=i);continue}if("ANN"==o){a(i,n.info.ANN.annheader,e)||(e.info[o]=i);continue}if("Flag"==n.info[o].Type){e.info[o]=o;continue}const l=n.info[o].Number,c="Integer"==n.info[o].Type,u="Float"==n.info[o].Type;if("0"==l){e.info[o]=o;continue}if("A"==l){const t=i.split(",");for(let n=0;n<t.length;n++)e.alleles[n]&&(e.alleles[n].info[o]=c?Number.parseInt(t[n]):u?Number.parseFloat(t[n]):t[n]);continue}if("1"==l){e.info[o]=c?Number.parseInt(i):u?Number.parseFloat(i):i;continue}if(!i.split)continue;const f=i.split(",");e.info[o]=c?f.map(Number.parseInt):u?f.map(Number.parseFloat):f}return r}(d,u,e):u.info=d;const m=[];for(const t of u.alleles){const e={};for(const t in u)"alleles"!=t&&(e[t]=u[t]);for(const n in t)"allele"==n?e.alt=t[n]:"info"==n?e.altinfo=t[n]:e[n]=t[n];e.issymbolicallele||"NON_REF"==e.alt||(e.type=(0,l.getVariantType)(e.ref,e.alt)),m.push(e)}return[p.length?"unknown info keys: "+p.join(","):null,m,f.length>0?f:null]}function h(t,e,n){for(;e.length>1&&n.length>1&&e[e.length-1]==n[n.length-1];)e=e.substr(0,e.length-1),n=n.substr(0,n.length-1);for(;e.length>1&&n.length>1&&e[0]==n[0];)e=e.substr(1),n=n.substr(1),t++;return[t,e,n]}function p(t,e){const n={},r=[];let o=0,s=!1,a=null;for(let e=0;e<t.length;e++)if('"'!=t[e])"="!=t[e]?","!=t[e]||(s?s=!1:a?(n[a]=t.substring(o,e),a=null):r.push("k undefined"),o=e+1):(a=t.substring(o,e),o=e+1);else{e++;const o=e;for(;'"'!=t[e];)e++;a?(n[a]=t.substring(o,e),a=null):r.push("k undefined before double quotes"),s=!0}return a&&(n[a]=t.substring(o,i)),n.ID?(e[n.ID]=n,r.length?r.join("\n"):void 0):"no ID"}},736:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getVariantType:()=>o});var r=n(2273);function o(t,e){return 1==t.length&&1==e.length?"."==e?r.mclassdeletion:r.mclasssnv:t.length==e.length?r.mclassmnv:t.length<e.length?r.mclassinsertion:t.length>e.length?r.mclassdeletion:r.mclassnonstandard}},7011:(t,e,n)=>{"use strict";n.r(e),n.d(e,{violinBinsObj:()=>o});const{bin:r}=n(9060);function o(t,e){const n=function(t,e){const n=new Set(e),o=1===n.size?50:n.size<=9?5:15;return r().domain(t.domain()).thresholds(t.ticks(o)).value((t=>t))(e)}(t,e.values),o=[];for(const t of n){const e={x0:t.x0,x1:t.x1};delete t.x0,delete t.x1,e.binValueCount=t.length,o.push(e)}return{bins0:n,bins:o}}},3306:(t,e,n)=>{const r=n(9699),o=(n(1017),n(7147),n(3856)),i=n(6718).createCanvas;n(334);t.exports=t=>async(t,e)=>{try{e.send(await async function(t){const[e,n,s]=r.fileurl(t);if(e)throw e;const a=Number(t.query.coveragemax)||100;if(!Number.isInteger(a))throw"invalid coveragemax";const l=Number(t.query.vafheight);if(!Number.isInteger(l))throw"invalid vafheight";const c=Number(t.query.coverageheight);if(!Number.isInteger(c))throw"invalid coverageheight";const u=Number(t.query.rowspace);if(!Number.isInteger(u))throw"invalid rowspace";const f=Number(t.query.dotsize)||1;if(!Number.isInteger(f))throw"invalid dotsize";if(!t.query.rglst)throw".rglst missing";"string"==typeof t.query.rglst&&(t.query.rglst=JSON.parse(t.query.rglst));const d=t.query.gtotalcutoff,h=t.query.gmafrestrict,p=i(t.query.width*t.query.devicePixelRatio,(3*l+4*u+2*c)*t.query.devicePixelRatio),m=p.getContext("2d");t.query.devicePixelRatio>1&&m.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);let g;m.fillStyle="#f1f1f1",m.fillRect(0,0,t.query.width,l/2),m.fillRect(0,2*u+l+c,t.query.width,l/2),m.fillStyle="#FAFAD9",m.fillRect(0,l/2,t.query.width,l/2),m.fillRect(0,2*u+1.5*l+c,t.query.width,l/2),s&&(g=await o.cache_index(n,t.query.indexURL));let y=0;for(const e of t.query.rglst)e.x=y,y+=t.query.regionspace+e.width;const v="#786312",b="#122778",_="#858585",w="red";for(const e of t.query.rglst){const t=e.width/(e.stop-e.start);await o.get_lines_bigfile({args:[n,e.chr+":"+e.start+"-"+e.stop],dir:g,callback:n=>{const r=n.split("\t"),o=Number.parseInt(r[1]),i=Number.parseInt(r[2]),s=Number.parseInt(r[3]),p=Number.parseInt(r[4]),g=Number.parseInt(r[5]);if(Number.isNaN(i)||Number.isNaN(s)||Number.isNaN(p)||Number.isNaN(g))return;if(d&&g<d)return;const y=Math.ceil(e.x+t*(e.reverse?e.stop-o:o-e.start)-f/2);m.fillStyle=v;const x=i/s;m.fillRect(y,l*(1-x),f,2);const k=p/g;if(h&&(k<h||k>1-h))return;m.fillRect(y,l+u+c+u+l*(1-k),f,2),m.fillStyle=b;const q=Math.abs(x-k);m.fillRect(y,2*l+4*u+2*c+l*(1-q),f,2),m.fillStyle=_;let N=(s>=a?a:s)*c/a,S=c-N;m.fillRect(y,S+l+u,f,N),m.fillStyle=_,N=(g>=a?a:g)*c/a,S=c-N,m.fillRect(y,S+3*u+2*l+c,f,N),s>=a&&(m.fillStyle=w,m.fillRect(y,l+u,f,2)),g>=a&&(m.fillStyle=w,m.fillRect(y,3*u+2*l+c,f,2))}})}return{src:p.toDataURL(),coveragemax:a}}(t))}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},9699:(t,e,n)=>{const r=t=>t.startsWith("[E::idx_test_and_fetch]");e.tabixnoterror=r;new Map;const o=n(334);e.features=Object.freeze(o.features||{});const i=n(6860),s=(n(6464),n(4269)),a=n(3685),l=n(5687),c=n(7147),u=n(1017),f=n(6452),d=n(9292),h=n(7455),p=n(2081),m=p.spawn,g=n(6718).createCanvas,y=n(1881).stratinput,v=n(3986),b=n(7219),_=n(4521),w=n(9344),x=n(3856),k=n(2273),q=n(6819),N=n(8064),S=n(5494),A=n(6733),M=n(5558),T=n(3602),C=n(6279),j=n(8423),O=n(8235),E=(n(7346),n(5505).QP),R=(n(2282),n(2884)),I=n(4308),P=n(7860),F=n(2824).q,L=n(9211).e,D=n(1711),B=n(2388),z=n(7253),Z=n(9574),$=n(8164).gdc_bam_request,G=n(5243),U=n(3306),H=n(1270),W=n(4695),J=n(8145),V=n(4353).x,Y=n(8089).f,Q=n(1883).server_updateAttr,K=n(2728),X=n(9535),tt=n(7510),et=n(8025),nt=n(7395),rt=n(9320),ot=n(5728).g,it=n(8405).v,st=n(1185).Z,at=n(5708),lt=n(6979).u,ct=n(8206),ut=n(9710),ft=n(6191),{server_init_db_queries:dt,listDbTables:ht}=n(394),{handle_healthcheck_closure:pt}=n(2084),{handle_genelookup_closure:mt}=n(4065),gt=n(6828),yt={},vt=o.tabix,bt=o.samtools,_t=o.bcftools,wt=(o.bigwigsummary,o.hicstraw);let xt,kt;const qt="Unannotated",Nt=i();Nt.disable("x-powered-by"),o.users&&Nt.use(I({users:o.users,challenge:!0}));const St=o.basepath||"";function At(t){t.header("Access-Control-Allow-Origin","*"),t.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept, Authorization, origin, x-requested-with, content-type, accept, authorization, X-Auth-Token, X-Ds-Access-Token, X-SjPPDs-Sessionid, x-auth-token, x-ds-access-token, x-sjppds-sessionid")}if(!o.backend_only){const t=i.static(u.join(process.cwd(),"./public"),{setHeaders:At});Nt.use(t)}function Mt(t){const e={};for(const n in t.query)"jwt"!=n&&(e[n]=t.query[n]);console.log("%s\t%s\t%s\t%s",s.parse(t.url).pathname,new Date,t.header("x-forwarded-for")||t.connection.remoteAddress,JSON.stringify(e).replace(/\\"/g,'"'))}function Tt(t){const e=yt[t],n={species:e.species,name:t,hasSNP:!!e.snp,hasIdeogram:e.genedb.hasIdeogram,hasClinvarVCF:!!e.clinvarVCF,fimo_motif:!!e.fimo_motif,blat:!!e.blat,geneset:e.geneset,defaultcoord:e.defaultcoord,isdefault:e.isdefault,majorchr:e.majorchr,majorchrorder:e.majorchrorder,minorchr:e.minorchr,tracks:e.tracks,hicenzymefragment:e.hicenzymefragment,datasets:{}};if(e.termdbs){n.termdbs={};for(const t in e.termdbs)n.termdbs[t]={label:e.termdbs[t].label}}for(const t in e.datasets){const r=e.datasets[t];r.isMds3?n.datasets[r.label]={isMds3:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}:r.isMds?n.datasets[r.label]={isMds:!0,mdsIsUninitiated:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}:n.datasets[r.label]={isofficial:!0,legacyDsIsUninitiated:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}}if(e.hicdomain){n.hicdomain={groups:{}};for(const t in e.hicdomain.groups){const r=e.hicdomain.groups[t];n.hicdomain.groups[t]={name:r.name,reference:r.reference,sets:{}};for(const e in r.sets)n.hicdomain.groups[t].sets[e]={name:r.sets[e].name,longname:r.sets[e].longname}}}return n}function Ct(t){const e={noHandleOnClient:t.noHandleOnClient,sampleselectable:t.sampleselectable,label:t.label,dsinfo:t.dsinfo,stratify:t.stratify,cohort:t.cohort,vcfinfofilter:t.vcfinfofilter,info2table:t.info2table,info2singletable:t.info2singletable,url4variant:t.url4variant,itemlabelname:t.itemlabelname};if(t.snvindel_attributes){e.snvindel_attributes=[];for(const n of t.snvindel_attributes){const t={};for(const e in n)if("lst"==e){t.lst=[];for(const e of n.lst){const n={};for(const t in e)n[t]=e[t];t.lst.push(n)}}else t[e]=n[e];e.snvindel_attributes.push(t)}}t.snvindel_legend&&(e.snvindel_legend=t.snvindel_legend);const n={};let r=!1;for(const e of t.queries)e.vcf&&(r=!0,n[e.vcf.vcfid]=e.vcf);return r&&(e.id2vcf=n),e}function jt(t){const e={isMds:!0,noHandleOnClient:t.noHandleOnClient,label:t.label,version:t.version,annotationsampleset2matrix:t.annotationsampleset2matrix,mutationAttribute:t.mutationAttribute,locusAttribute:t.locusAttribute,alleleAttribute:t.alleleAttribute,hide_genotypedownload:t.hide_genotypedownload,hide_phewas:t.hide_phewas,sample2bam:t.sample2bam};if(t.queries&&(e.queries={}),t.track&&(e.track=K.client_copy(t)),t.singlesamplemutationjson&&(e.singlesamplemutationjson=1),t.gene2mutcount&&(e.gene2mutcount=!0,e.mutCountType=t.gene2mutcount.mutationTypes),t.assayAvailability&&(e.assayAvailability=1),t.cohort&&t.cohort.sampleAttribute){const n={};for(const e in t.cohort.sampleAttribute.attributes){const r=t.cohort.sampleAttribute.attributes[e];r.clientnoshow||(n[e]=r)}e.sampleAttribute={attributes:n}}if(t.cohort){if(t.cohort.termdb&&(e.termdb={selectCohort:t.cohort.termdb.selectCohort}),t.cohort.attributes&&t.cohort.attributes.defaulthidden&&(e.cohortHiddenAttr=t.cohort.attributes.defaulthidden),t.cohort.survivalplot){e.survivalplot={samplegroupattrlst:t.cohort.survivalplot.samplegroupattrlst,plots:[]};for(const n in t.cohort.survivalplot.plots){const r=t.cohort.survivalplot.plots[n];e.survivalplot.plots.push({key:n,name:r.name,timelabel:r.timelabel})}}if(t.cohort.mutation_signature){const n={};for(const e in t.cohort.mutation_signature.sets){const r=t.cohort.mutation_signature.sets[e];n[e]={name:r.name,signatures:r.signatures}}e.mutation_signature={sets:n}}}for(const n in t.queries){const r=t.queries[n],o={name:r.name,hideforthemoment:r.hideforthemoment};if(r.istrack){if(o.istrack=!0,o.type=r.type,o.isfull=r.isfull,null!=r.nochr&&(o.nochr=r.nochr),r.infoFilter&&(o.infoFilter=r.infoFilter),r.readcountCutoff&&(o.readcountCutoff=r.readcountCutoff),r.valueLabel&&(o.valueLabel=r.valueLabel),r.valueCutoff&&(o.valueCutoff=r.valueCutoff),r.bplengthUpperLimit&&(o.bplengthUpperLimit=r.bplengthUpperLimit),r.segmeanValueCutoff&&(o.segmeanValueCutoff=r.segmeanValueCutoff),r.lohLengthUpperLimit&&(o.lohLengthUpperLimit=r.lohLengthUpperLimit),r.type==k.tkt.mdssvcnv){if(r.groupsamplebyattr&&(o.groupsamplebyattr=r.groupsamplebyattr),o.multihidelabel_fusion=r.multihidelabel_fusion,o.multihidelabel_sv=r.multihidelabel_sv,o.multihidelabel_vcf=r.multihidelabel_vcf,o.showfullmode=r.showfullmode,o.legend_vorigin=r.legend_vorigin,o.no_loh=r.no_loh,r.expressionrank_querykey){const e=t.queries[r.expressionrank_querykey];if(o.checkexpressionrank={querykey:r.expressionrank_querykey,datatype:e.datatype},e.boxplotbysamplegroup&&e.boxplotbysamplegroup.additionals){const t=[];e.boxplotbysamplegroup.attributes&&t.push(e.boxplotbysamplegroup.attributes.map((t=>t.label)).join(", "));for(const n of e.boxplotbysamplegroup.additionals)t.push(n.label);o.checkexpressionrank.boxplotgroupers=t}}if(r.vcf_querykey){o.checkvcf={querykey:r.vcf_querykey,info:t.queries[r.vcf_querykey].info,format:{}};for(const e of t.queries[r.vcf_querykey].tracks)if(e.format)for(const t in e.format)o.checkvcf.format[t]=e.format[t]}}}else{if(!r.isgenenumeric)continue;o.isgenenumeric=!0,o.datatype=r.datatype,o.no_ase=r.no_ase}e.queries[n]=o}return e}function Ot(t){const e=t.split("\t"),n=e[4],r=e[6].split(",").filter(Boolean),o=n+"/"+r.join("/");return{chrom:e[0],chromStart:Number(e[1]),chromEnd:Number(e[2]),name:e[3],observed:o,alleles:[n,...r]}}function Et(t,e,n){if(n.query.isoform&&yt[n.query.genome].genomicNameRegexp.test(n.query.isoform))return;const[r,o]=e.makequery(n.query);if(!r)return;const i=t.newconn.prepare(r).all(o);let s;s=e.tidy?i.map((t=>e.tidy(t))):i;const a={};if(e.isgeneexpression){a.lst=s,a.isgeneexpression=!0,a.config=e.config;for(const e of t.queries)if(e.dsblocktracklst)for(const t of e.dsblocktracklst)t.type==k.tkt.junction&&(a.config.dsjunctiontk=t)}else a.lst=s;return a}function Rt(t,e){const n=[u.join(o.tpmasterdir,t.vcffile),(t.vcf.nochr?e.query.range.chr.replace("chr",""):e.query.range.chr)+":"+e.query.range.start+"-"+e.query.range.stop];return new Promise(((e,r)=>{const o=m(vt,n),i=[],s=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>s.push(t))),o.on("close",(n=>{""!=s.join("").trim()&&r("error querying vcf file");const o=i.join("").trim();e({lines:""==o?[]:o.split("\n"),vcfid:t.vcf.vcfid})}))}))}function It(t){if(!t.genome)return["no genome"];const e=yt[t.genome];if(!e)return["invalid genome"];if(!e.datasets)return["genome is not equipped with datasets"];if(!t.dslabel)return["dslabel missing"];const n=e.datasets[t.dslabel];if(!n)return["invalid dslabel"];if(!n.queries)return["dataset is not equipped with queries"];if(!t.querykey)return["querykey missing"];const r=n.queries[t.querykey];return r?[null,e,n,r]:["invalid querykey"]}async function Pt(t,e,n,r,i,s){const a=await async function(t,e,n,r){const i=t.checkvcf.tracks[0],s={file:i.file,url:i.url,indexURL:i.indexURL,dir:i.dir,nochr:i.nochr,samples:i.samples,info:t.checkvcf.info,format:i.format},a=await Jt(s.file?u.join(o.tpmasterdir,s.file):s.url,(s.nochr?e.replace("chr",""):e)+":"+n+"-"+r,s.dir),l=[];for(const t of a||[]){const[e,n,r]=q.vcfparseline(t,s);for(const t of n)k.basecolor[t.ref]&&k.basecolor[t.alt]&&t.sampledata&&l.push(t)}return l}(i,e,n,r),l=[];for(const t in i.checkrnabam.samples){const n=i.checkrnabam.samples[t];n.hetsnps=[];for(const e of a){const r=Ht(e,t,i.checkrnabam);r&&r.dnacount.ishet&&n.hetsnps.push(r)}if(n.url?n.dir=await x.cache_index(n.url,n.indexURL||n.url+".bai"):n.file&&(n.file=u.join(o.tpmasterdir,n.file)),n.hetsnps.length>0){await Dt(n,n.hetsnps,e,i.checkrnabam);for(const e of n.hetsnps)e.rnacount.nocoverage||e.rnacount.ref+e.rnacount.alt<i.checkrnabam.rna_mintotalreads||l.push(t+"."+e.pos+"."+e.ref+"."+e.alt+"\t\t\t\t\t\t\t\t"+e.rnacount.ref+"\t"+e.rnacount.alt)}}l.length>0&&await async function(t,e){const n=await function(t){const e=u.join(o.cachedir,Math.random().toString());return new Promise(((n,r)=>{c.writeFile(e,t.join("\n")+"\n",(t=>{t&&r("cannot write"),n(e)}))}))}(t),r=await Gt(n);await function(t,e){return new Promise(((n,r)=>{c.readFile(t,"utf8",((t,o)=>{if(t&&r("cannot read binom pvalue"),o){for(const t of o.trim().split("\n")){const n=t.split("\t"),r=n[0].split("."),o=e[r[0]];if(!o)continue;const i=o.hetsnps.find((t=>t.pos+"."+t.ref+"."+t.alt==r[1]+"."+r[2]+"."+r[3]));i&&(i.rnacount.pvalue=Number.parseFloat(n[10]))}n()}else n()}))}))}(r,e),c.unlink(n,(()=>{})),c.unlink(r,(()=>{}))}(l,i.checkrnabam.samples),s.checkrnabam=[];for(const n in i.checkrnabam.samples){const r=i.checkrnabam.samples[n],o=[];for(const[n,s]of t){const t={gene:n,chr:e,start:s.start,stop:s.stop},a=r.hetsnps.filter((t=>t.pos>=s.start&&t.pos<=s.stop)),l=a.filter((t=>!t.rnacount.nocoverage));if(l.length>0){const e=l.reduce(((t,e)=>t+Math.abs(e.rnacount.f-.5)),0);let n=null,r=0;for(const t of l)null!=t.rnacount.pvalue&&(null==n?n=t.rnacount.pvalue:n*=t.rnacount.pvalue,t.rnacount.pvalue<=i.checkrnabam.binompvaluecutoff&&r++);null!=n&&(t.ase={markers:a.filter((t=>t.dnacount.ishet)).length,ase_markers:r,mean_delta:e/l.length,geometricmean:Math.pow(n,1/l.length)})}let c;c=r.pairedend?await Lt(r,e,s):await Ft(r,e,s),t.fpkm=1e9*c/(r.totalreads*s.exonlength),t.snps=a,o.push(t)}o.length&&s.checkrnabam.push({sample:n,genes:o})}}async function Ft(t,e,n){const r=["view","-c","-M",t.url||t.file];for(const o of n.exonunion)r.push((t.nochr?e.replace("chr",""):e)+":"+(o[0]+1)+"-"+(o[1]+1));let o;return await x.get_lines_bigfile({isbam:!0,args:r,dir:t.dir,callback:t=>o=t}),Number.parseInt(o)}function Lt(t,e,n){return new Promise(((r,o)=>{const i=["view","-M",t.url||t.file];for(const r of n.exonunion)i.push((t.nochr?e.replace("chr",""):e)+":"+(r[0]+1)+"-"+(r[1]+1));const s=m(bt,i,{cwd:t.dir}),a=m("cut",["-f1"],{cwd:t.dir}),l=m("sort",["-u"],{cwd:t.dir}),c=m("wc",["-l"],{cwd:t.dir});s.stdout.pipe(a.stdin),a.stdout.pipe(l.stdin),l.stdout.pipe(c.stdin);const u=[],f=[];c.stdout.on("data",(t=>u.push(t))),c.stderr.on("data",(t=>f.push(t))),c.on("close",(()=>{r(Number.parseInt(u.join("")))}))}))}function Dt(t,e,n,r){const o=[];for(const r of e)r.rnacount={nocoverage:1},o.push((t.nochr?n.replace("chr",""):n)+":"+(r.pos+1)+"-"+(r.pos+1));return new Promise(((n,i)=>{const s=m(_t,["mpileup","--no-reference","-a","INFO/AD","-d",999999,"-r",o.join(","),"-q",r.rnapileup_q,"-Q",r.rnapileup_Q,t.url||t.file],{cwd:t.dir});_.createInterface({input:s.stdout}).on("line",(t=>{if("#"==t[0])return;const n=Ut(t);if(!n)return;const r=e.find((t=>t.pos==n.pos));if(r){const t=n.allele2count[r.ref]||0,e=n.allele2count[r.alt]||0;t+e>0&&(r.rnacount={ref:t,alt:e,f:e/(t+e)})}})),s.on("close",(()=>{n()}))}))}function Bt(t,e,n,r,o,i){e.hideLOHwithCNVoverlap&&zt(o);const s=[];if(i){const t=new Map;for(const[e,n]of o){const r=i.sample2group.get(e);t.has(r)||t.set(r,[]),t.get(r).push({samplename:e,items:n})}if(r)for(const e of r)if(e.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf: "+e.dt);else for(const n of e.sampledata){const e=i.sample2group.get(n.sampleobj.name);t.has(e)||t.set(e,[]),t.get(e).find((t=>t.samplename==n.sampleobj.name))||t.get(e).push({samplename:n.sampleobj.name,items:[]})}for(const[e,n]of t)s.push({name:e,samples:n})}else if(t.cohort&&t.cohort.annotation&&e.groupsamplebyattr){const n=new Map,i=[];for(const[r,s]of o)Zt(r,s,n,i,t,e);if(r)for(const o of r)if(o.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf data: "+o.dt);else for(const r of o.sampledata)Zt(r.sampleobj.name,[],n,i,t,e);for(const t of n.values())if(s.push(t),e.groupsamplebyattr.key2group){const n=e.groupsamplebyattr.key2group.get(t.name);n&&(t.sampletotalnum=n.samples.length)}i.length&&s.push({name:"Unannotated",samples:i});for(const e of s)for(const n of e.samples)t.cohort.annotation[n.samplename]&&(n.sampletype=t.cohort.annotation[n.samplename].sample_type)}else{const t=[];for(const[e,n]of o)t.push({samplename:e,items:n});if(r)for(const e of r)if(e.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf: "+e.dt);else for(const n of e.sampledata){let e=!0;for(const r of t)if(r.samplename==n.sampleobj.name){e=!1;break}e&&t.push({samplename:n.sampleobj.name,items:[]})}t.length&&s.push({samples:t})}return s}function zt(t){for(const[e,n]of t){const r=new Map,o=new Map,i=[];for(const t of n)t.dt!=k.dtloh?(t.dt==k.dtcnv&&(o.has(t.chr)||o.set(t.chr,[]),o.get(t.chr).push(t)),i.push(t)):(r.has(t.chr)||r.set(t.chr,[]),r.get(t.chr).push(t));if(0!=r.size){for(const[t,e]of r){const n=o.get(t);if(n)for(const t of e){let e=!0;for(const r of n)if(Math.max(t.start,r.start)<Math.min(t.stop,r.stop)){e=!1;break}e&&i.push(t)}else for(const t of e)i.push(t)}t.set(e,i)}}}function Zt(t,e,n,r,o,i){const s=o.cohort.annotation[t];if(!s)return void r.push({samplename:t,items:e});const a=s[i.groupsamplebyattr.attrlst[0].k];if(null==a)return void r.push({samplename:t,items:e});const l=[];for(let t=1;t<i.groupsamplebyattr.attrlst.length;t++){const e=s[i.groupsamplebyattr.attrlst[t].k];if(null==e)break;l.push(e)}l.unshift(a);const c=l.join(i.groupsamplebyattr.attrnamespacer);if(!n.has(c)){const t=[];for(const e of i.groupsamplebyattr.attrlst){const n=s[e.k];if(null==n)break;const r={k:e.k,kvalue:n};e.full&&(r.full=e.full,r.fullvalue=s[e.full]),t.push(r)}const e=[];for(const t of i.groupsamplebyattr.attrlst){const n=s[t.k];if(null==n)break;const r=(t.full?s[t.full]:null)||n;e.push(r)}n.set(c,{name:c,samples:[],attributes:t})}let u=!0;for(const r of n.get(c).samples)if(r.samplename==t){for(const t of e)r.items.push(t);u=!1;break}u&&n.get(c).samples.push({samplename:t,items:e})}function $t(t){return Number.isFinite(t.dna_mintotalreads)?Number.isFinite(t.rna_mintotalreads)?Number.isFinite(t.hetsnp_minbaf)?Number.isFinite(t.hetsnp_maxbaf)?Number.isFinite(t.rnapileup_q)?Number.isFinite(t.rnapileup_Q)?void 0:"invalid value for rnapileup_Q":"invalid value for rnapileup_q":"invalid value for hetsnp_maxbaf":"invalid value for hetsnp_minbaf":"invalid value for rna_mintotalreads":"invalid value for dna_mintotalreads"}function Gt(t){const e=t+".pvalue";return new Promise(((n,r)=>{const i=m("Rscript",[u.join(o.binpath,"utils/binom.R"),t,e]);i.on("close",(()=>{n(e)})),i.on("error",(t=>{r(`cannot do binom test: ${t}`)})),i.stderr.on("data",(t=>{r(`cannot do binom test: ${t}`)}))}))}function Ut(t){const e=t.split("\t");if(e.length<8)return;const n={pos:Number.parseInt(e[1])-1},r=[e[3],...e[4].split(",")],o={};for(const t of e[7].split(";")){const e=t.split("=");o[e[0]]=e[1]}if(o.DP&&(n.DP=Number.parseInt(o.DP)),o.AD){n.allele2count={};const t=o.AD.split(",");for(const[e,o]of r.entries())n.allele2count[o]=Number.parseInt(t[e])}return n}function Ht(t,e,n){const r=t.sampledata.find((t=>t.sampleobj.name==e));if(r){if(r.AD){const e=r.AD[t.ref]||0,o=r.AD[t.alt]||0,i={chr:t.chr,pos:t.pos,ref:t.ref,alt:t.alt,dnacount:{ref:e,alt:o}};return i.dnacount.f=o+e==0?0:o/(o+e),e+o>=n.dna_mintotalreads&&i.dnacount.f>=n.hetsnp_minbaf&&i.dnacount.f<=n.hetsnp_maxbaf&&(i.dnacount.ishet=!0),i}return null}}async function Wt(t,e,n,r,i){const s=await Jt(u.join(o.tpmasterdir,e.file),n+":"+r+"-"+i),a=new Map;if(s)for(const t of s){const e=t.split("\t"),n=JSON.parse(e[3]),r=Number.parseInt(e[1]),o=Number.parseInt(e[2]);if(a.has(n.name)){const t=a.get(n.name);t.start=Math.min(t.start,r),t.stop=Math.max(t.stop,o)}else a.set(n.name,{gene:n.name,start:r,stop:o,exonunion:[]});const i=a.get(n.name);if(n.exon)for(const t of n.exon){const e=i.exonunion.find((e=>Math.max(e[0],t[0])<Math.min(e[1],t[1])));e?(e[0]=Math.min(t[0],e[0]),e[1]=Math.max(t[1],e[1])):i.exonunion.push([t[0],t[1]])}}for(const[t,e]of a)e.exonlength=e.exonunion.reduce(((t,e)=>t+e[1]-e[0]),0);return a}async function Jt(t,e,n){return new Promise(((r,o)=>{const i=m(vt,[t,e],{cwd:n}),s=[],a=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>a.push(t))),i.on("close",(()=>{const t=a.join("");t&&o(t);const e=s.join("").trim();e||r(),r(e.split("\n"))}))}))}function Vt(t,e){return new Promise(((n,r)=>{const o=m(vt,["-H",t],{cwd:e}),i=[],s=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>s.push(t))),o.on("close",(()=>{const t=s.join("");t&&r(t);const e=i.join("").trim();e||r("cannot list vcf meta lines"),n(e.split("\n"))}))}))}function Yt(t,e){const n=e.findIndex((e=>e.value>=t));return-1==n||n==e.length-1?100:0==n?0:Math.ceil(100*n/e.length)}function Qt(t,e,n){if(!t.key)return[".key missing"];if(!e.cohort)return["ds.cohort missing"];if(!e.cohort.annotation)return["ds.cohort.annotation missing"];return[null,Promise.resolve().then((()=>{const r=[];for(const o in e.cohort.annotation){if(n&&!n.has(o))continue;const i=e.cohort.annotation[o][t.key];null!=i&&r.push({sample:o,value:i})}return{id:t.id,items:r}}))]}function Kt(t,e,n,i){if(!t.genename)return["genename missing"];const s=t.genename.toLowerCase();if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["gene feature too long (> 10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((a,l)=>{const c=[],f=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:f.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.gene&&n.gene.toLowerCase()==s&&n.sample&&(i&&!i.has(n.sample)||c.push(n))}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(e=>{const n=d.join("");!n||r(n)?a({id:t.id,items:c}):l(n)}))}))))]}function Xt(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];if(null!=t.valuecutoff&&!Number.isFinite(t.valuecutoff))return["invalid value for valuecutoff"];if(null!=t.focalsizelimit&&!Number.isInteger(t.focalsizelimit))return["invalid value for focalsizelimit"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);r.dt==k.dtcnv&&(t.valuecutoff&&Math.abs(r.value)<t.valuecutoff||(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.focalsizelimit&&r.stop-r.start>=t.focalsizelimit||r.sample&&(i&&!i.has(r.sample)||l.push(r))))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function te(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];if(null!=t.valuecutoff&&!Number.isFinite(t.valuecutoff))return["invalid value for valuecutoff"];if(null!=t.focalsizelimit&&!Number.isInteger(t.focalsizelimit))return["invalid value for focalsizelimit"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);r.dt==k.dtloh&&(t.valuecutoff&&r.segmean<t.valuecutoff||(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.focalsizelimit&&r.stop-r.start>=t.focalsizelimit||r.sample&&(i&&!i.has(r.sample)||l.push(r))))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function ee(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.dt==k.dtitd&&(n.chr=e[0],n.start=Number.parseInt(e[1]),n.stop=Number.parseInt(e[2]),n.sample&&(i&&!i.has(n.sample)||l.push(n)))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function ne(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.dt!=k.dtsv&&n.dt!=k.dtfusionrna||n.sample&&(i&&!i.has(n.sample)||(n._chr=e[0],n._pos=Number.parseInt(e[1]),n.chrA?(n.chrB=n._chr,n.posB=n._pos):(n.chrA=n._chr,n.posA=n._pos),l.push(n)))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function re(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(r.sample&&(!i||i.has(r.sample))){if(r.dt==k.dtsv||r.dt==k.dtfusionrna){if(r.dt==k.dtsv&&t.sv&&t.sv.hidden)return;if(r.dt==k.dtfusionrna&&t.fusion&&t.fusion.hidden)return;r._chr=n[0],r._pos=Number.parseInt(n[1]),r.chrA?(r.chrB=r._chr,r.posB=r._pos):(r.chrA=r._chr,r.posA=r._pos)}else if(r.dt==k.dtcnv){if(t.cnv&&t.cnv.hidden)return;if(t.cnv&&t.cnv.valuecutoff&&Math.abs(r.value)<t.cnv.valuecutoff)return;if(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.cnv&&t.cnv.focalsizelimit&&r.stop-r.start>=t.cnv.focalsizelimit)return}else if(r.dt==k.dtloh){if(t.loh&&t.loh.hidden)return;if(t.loh&&t.loh.valuecutoff&&r.segmean<t.loh.valuecutoff)return;if(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.loh&&t.loh.focalsizelimit&&r.stop-r.start>=t.loh.focalsizelimit)return}else{if(r.dt!=k.dtitd)return void console.error("unknown datatype",r.dt);if(t.itd&&t.itd.hidden)return;r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2])}l.push(r)}}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const o=f.join("");if(o&&!r(o))return void a(o);const i=new Map;for(const t of l)i.has(t.sample)||i.set(t.sample,[]),i.get(t.sample).push(t);n.hideLOHwithCNVoverlap&&zt(i);const c=[];for(const[t,e]of i)for(const t of e)c.push(t);s({id:t.id,items:c})}))}))))]}function oe(t,e,n,r){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];const o=[];for(const i of n)if(i.type==k.tkt.mdsvcf){const[n,s]=ie(t,e,i,r);if(n)return[n];o.push(s)}else{if(i.type!=k.tkt.mdssvcnv)return["unsupported track type: "+i.type];{const[e,n]=re(t,0,i,r);if(e)return[e];o.push(n)}}return[null,Promise.all(o).then((t=>{const e=[];for(const n of t)for(const t of n.items)e.push(t);return{id:t[0].id,items:e}}))]}function ie(t,e,n,i){if(!n.tracks)return"tracks[] missing from dsquery";if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>3e6)return["look range too big (>3Mb)"];const s=[];for(const e of n.tracks){const a=Promise.resolve().then((()=>{if(!e.file)return x.cache_index(e.url,e.indexURL)})).then((s=>new Promise(((a,l)=>{const c=[],f=m(vt,[e.file?u.join(o.tpmasterdir,e.file):e.url,(e.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+(t.stop+1)],{cwd:s});_.createInterface({input:f.stdout}).on("line",(r=>{if(n.iscustom)c.push(r);else if(e.type==k.mdsvcftype.vcf){const[o,s,a]=q.vcfparseline(r,{nochr:e.nochr,samples:e.samples,info:n.info,format:e.format});for(const e of s)if(e.sampledata&&(k.vcfcopymclass(e,{}),!(t.snvindel&&t.snvindel.excludeclasses&&t.snvindel.excludeclasses[e.class]))){if(i){const t=[];for(const n of e.sampledata)i.has(n.sampleobj.name)&&t.push(n);if(0==t.length)continue;e.sampledata=t}for(const t of e.sampledata)delete t.allele2readcount;delete e._m,delete e.vcf_ID,delete e.name,e.dt=k.dtsnvindel,c.push(e)}}else console.error("type not one of mdsvcftype: "+e.type)}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(t=>{const e=d.join("");!e||r(e)?a(c):l(e)}))}))));s.push(a)}return[null,Promise.all(s).then((e=>{const n=[];for(const t of e)for(const e of t)n.push(e);return{id:t.id,items:n}}))]}function se(t){if(!t.endsWith(".gz"))return["no .gz suffix (file should be compressed by bgzip)"];const e=u.join(o.tpmasterdir,t);return c.existsSync(e)?c.existsSync(e+".tbi")||c.existsSync(e+".csi")?[null,e]:[".tbi/.csi index missing"]:[".gz file not found"]}Nt.use(h()),Nt.use(((t,e,n)=>{"POST"==t.method.toUpperCase()&&(t.headers["content-type"]="application/json");try{for(const e in t.query){const n=t.query[e];(n.startsWith('"')&&n.endsWith('"')||n.startsWith("{")&&n.endsWith("}")||n.startsWith("[")&&n.endsWith("]"))&&(t.query[e]=JSON.parse(n))}}catch(t){return void e.send({error:t})}n()})),Nt.use(ut()),Nt.use(v.json({limit:"5mb"})),Nt.use(v.text({limit:"5mb"})),Nt.use(v.urlencoded({extended:!0})),Nt.use(((t,e,n)=>{"POST"==t.method.toUpperCase()&&t.body&&"application/json"!=t.headers["content-type"]?e.send({error:"invalid HTTP request.header['content-type'], must be 'application/json'"}):("application/json"==t.headers["content-type"]&&(t.query||(t.query={}),Object.assign(t.query,t.body)),Mt(t),At(e),e.header("Access-Control-Allow-Origin",t.get("origin")||t.get("referrer")||t.protocol+"://"+t.get("host").split(":")[0]||"*"),e.header("Access-Control-Allow-Credentials",!0),"GET"!=t.method||t.path.includes(".")&&!t.path.endsWith("proteinpaint.js")||e.header("Cache-control",`immutable,max-age=${o.responseMaxAge||1}`),n())})),Nt.use(ct.middleware),Nt.use(((t,e,n,r)=>{Mt(e),t&&(t&&"entity.parse.failed"==t.type?n.send({error:"invalid request body, must be a valid JSON-encoded object"}):n.send({error:t}))})),o.jwt&&(console.log("JWT is activated"),Nt.use(((t,e,n)=>{let r={};t.body&&"POST"==t.method&&(r=t.body);const i=r.jwt?r.jwt:t.headers&&t.headers.authorization&&t.headers.authorization.startsWith("Bearer ")?t.headers.authorization.split(" ")[1]:null;if(!i)return e.send({error:"json web token missing"});w.verify(i,o.jwt.secret,((t,r)=>t?e.send({error:"Invalid token"}):r[o.jwt.permissioncheck]?void n():e.send({error:"Not authorized"})))}))),function(){if(!o.routeSetters)return;for(const t of o.routeSetters)if(t.endsWith(".js")){require(t)(Nt,St)}}(),ft.maySetAuthRoutes(Nt,St,o),Nt.get(St+"/healthcheck",pt(yt)),Nt.get(St+"/cardsjson",(async function(t,e){try{if(t.query.datafile&&t.query.tabixCoord)return new Promise(((n,r)=>{const i=m(vt,[u.join(o.tpmasterdir,t.query.datafile),t.query.tabixCoord]),s=[],a=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>a.push(t))),i.on("close",(t=>{""!=a.join("").trim()&&r("error querying bedj file");const o=s.join("").trim();n(e.send({file:o.split("\n")}))}))})).catch((t=>{t.stack&&console.error(t.stack)}));throw"invalid cards request"}catch(t){e.send({error:t.message||t})}})),Nt.post(St+"/mdsjsonform",(async function(t,n){if(!e.features.mdsjsonform)return n.send({error:"This feature is not enabled on this server."});if(t.query.deposit){const e=Math.random().toString(),r=await function(){const t=u.join(o.cachedir,"mdsjsonform");return new Promise(((e,n)=>{c.stat(t,((r,o)=>{if(r){if("ENOENT"==r.code)return void c.mkdir(t,(r=>{r&&n("error creating dir"),e(t)}));n("error checking directory")}else o.isDirectory()?e(t):n('"mdsjsonform" exists but not directory')}))}))}(),i=u.join(r,e);return await x.write_file(i,JSON.stringify(t.query.deposit)),void n.send({id:e})}if(t.query.draw){const e=u.join(o.cachedir,"mdsjsonform",t.query.draw),r=await x.read_file(e);try{const t=JSON.parse(r);n.send({json:t})}catch(t){n.send({error:"Invalid JSON"})}return}n.send({})})),Nt.get(St+"/genomes",(async function(t,n){var r;Mt(t);try{await c.promises.stat(o.tpmasterdir)}catch(t){let e="Error with TP directory ("+t.code+")";const r=o.maintenance||{};if("start"in r&&"stop"in r&&r.tpMessage){const t=+new Date(r.start),n=+new Date(r.stop),o=+new Date;t<=o&&o<=n&&(e=r.tpMessage)}return void n.send({error:e})}const i={};if(t.query&&t.query.genome)i[t.query.genome]=Tt(t.query.genome);else for(const t in yt)i[t]=Tt(t);let s=!1;for(const t in yt)yt[t].blat&&(s=!0);n.send({genomes:i,debugmode:o.debugmode,headermessage:o.headermessage,base_zindex:o.base_zindex,codedate:xt.toDateString(),launchdate:kt,hasblat:s,features:e.features,dsAuth:ft.getDsAuth(t),commonOverrides:o.commonOverrides,targetPortal:o.targetPortal,cardsPath:null===(r=o.cards)||void 0===r?void 0:r.path})})),Nt.get(St+"/getDataset",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.datasets)throw"genomeobj.datasets{} missing";let r;for(const e in n.datasets)if(e.toLowerCase()==t.query.dsname.toLowerCase()){r=n.datasets[e];break}if(!r)throw"invalid dsname";return r.isMds3?e.send({ds:X.client_copy(r,null,null,Nt,St)}):r.isMds?e.send({ds:jt(r)}):e.send({ds:Ct(r)})}catch(t){e.send({error:t.message||t})}})),Nt.all(St+"/genelookup",mt(yt)),Nt.all(St+"/ntseq",(async function(t,e){try{if(!t.query.coord)throw"coord missing";const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.genomefile)throw"no sequence file available";const r=await x.get_fasta(n,t.query.coord);e.send({seq:r.split("\n").slice(1).join("")})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/pdomain",(function(t,e){try{const n=t.query.genome;if(!n)throw"no genome";const r=yt[n];if(!r)throw"invalid genome "+n;if(!r.proteindomain)return e.send({lst:[]});if(!Array.isArray(t.query.isoforms))throw"isoforms[] missing";const o=[];for(const e of t.query.isoforms){if(r.genomicNameRegexp.test(e))continue;const t=r.proteindomain.getbyisoform.all(e);o.push({name:e,pdomains:t.map((t=>{const n=JSON.parse(t.data);return n.refseq=e,n}))})}e.send({lst:o})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/tkbedj",J(yt)),Nt.post(St+"/tkbedgraphdot",B(yt)),Nt.all(St+"/tkbam",z(yt)),Nt.get(St+"/gdcbam",$),Nt.get(St+"/gdc_ssms",G.handle_gdc_ssms(yt)),Nt.get(St+"/gdc_filter2topGenes",G.handle_filter2topGenes(yt)),Nt.get(St+"/tkaicheck",U(yt)),Nt.get(St+"/blat",V(yt)),Nt.all(St+"/mds3",Y(yt)),Nt.get(St+"/tkbampile",H),Nt.post(St+"/dsdata",(async function(t,e){try{if(!yt[t.query.genome])throw"invalid genome";if(!t.query.dsname)throw".dsname missing";const n=yt[t.query.genome].datasets[t.query.dsname];if(!n)throw"invalid dsname";const r=[];for(const e of n.queries)if((!t.query.expressiononly||e.isgeneexpression)&&!(t.query.noexpression&&e.isgeneexpression||e.dsblocktracklst))if(e.vcffile){const n=await Rt(e,t);r.push(n)}else{if(!e.makequery)throw"unknow type from one of ds.queries[]";{const o=Et(n,e,t);r.push(o)}}e.send({data:r})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/tkbigwig",F),Nt.post(St+"/tkld",L(yt)),Nt.get(St+"/tabixheader",(async function(t,e){Mt(t);try{const[n,r,o]=ue(t);if(n)throw n;const i=o?await x.cache_index(r,t.query.indexURL):null,s=await x.get_header_tabix(r,i);e.send({lines:s})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.all(St+"/snp",(async function(t,e){try{const n=t.query.genome;if(!n)throw"no genome";const r=yt[n];if(!r)throw"invalid genome";if(!r.snp)throw"snp is not configured for this genome";const o=[];if(t.query.byCoord){if(r.genomicNameRegexp.test(t.query.chr))throw"invalid chr name";if(!Array.isArray(t.query.ranges))throw"ranges not an array";for(const e of t.query.ranges){if(!Number.isInteger(e.start)||!Number.isInteger(e.stop)||e.start<0||e.stop<e.start)throw"invalid start/stop";if(e.stop-e.start>=100)throw"range too big";const n=await x.query_bigbed_by_coord(r.snp.bigbedfile,t.query.chr,e.start,e.stop);for(const e of n){const n=Ot(e);if(t.query.alleleLst){let e=!1;for(const r of t.query.alleleLst)if(r&&!n.alleles.includes(r)){e=!0;break}if(e)continue}o.push(n)}}}else{if(!t.query.byName)throw"unknown query method";if(!Array.isArray(t.query.lst))throw".lst[] missing";for(const e of t.query.lst){if(r.genomicNameRegexp.test(e))continue;const t=await x.query_bigbed_by_name(r.snp.bigbedfile,e);for(const e of t){const t=Ot(e);o.push(t)}}}e.send({results:o})}catch(t){return t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/clinvarVCF",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.clinvarVCF)throw"no clinvar for this genome";const r=Number(t.query.pos);if(!Number.isInteger(r))throw"pos is not integer";if(r<0)throw"pos is not positive integer";if(!t.query.chr)throw"chr missing";{const e=n.chrlookup[t.query.chr.toUpperCase()];if(!e)throw"invalid chr";if(r>e.len)throw"pos out of bound"}let o;if(await x.get_lines_bigfile({args:[n.clinvarVCF.file,(n.clinvarVCF.nochr?t.query.chr.replace("chr",""):t.query.chr)+":"+r+"-"+(r+1)],callback:e=>{const[i,s,a]=q.vcfparseline(e,n.clinvarVCF);for(const e of s)e.pos==r&&e.ref==t.query.ref&&e.alt==t.query.alt&&(o=e)}}),!o)return e.send({});const i=o.info[n.clinvarVCF.infokey],s=n.clinvarVCF.categories[i];e.send({hit:{id:o.vcf_ID,value:s?s.label:i,bg:s?s.color:"#858585",textcolor:s&&s.textcolor?s.textcolor:"black"}})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/isoformlst",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!Array.isArray(t.query.lst))throw".lst missing";const r=[];for(const e of t.query.lst){if(n.genomicNameRegexp.test(e))continue;const t=n.genedb.getjsonbyisoform.all(e);r.push(t.map((t=>{const e=JSON.parse(t.genemodel);return t.isdefault&&(e.isdefault=!0),e})))}e.send({lst:r})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/dbdata",(function(t,e){})),Nt.get(St+"/img",(async function(t,e){Mt(t);const[n,r,o]=ue(t);try{if(n)throw"invalid image file";const t=await c.promises.readFile(r);e.send({src:"data:image/jpeg;base64,"+new Buffer.from(t).toString("base64"),size:b(r)})}catch(n){e.send({error:n.message||n})}})),Nt.post(St+"/svmr",(function(t,e){if(t.query.file){const[n,r,o]=ue(t);if(n)return void e.send({error:"illegal file name"});c.readFile(r,"utf8",((t,n)=>{t?e.send({error:"cannot read file"}):e.send({raw:n})}))}else e.send({error:"missing file"})})),Nt.post(St+"/study",(async function(t,e){try{if(ce(t.query.file))throw"invalid file path";const n=u.join(o.tpmasterdir,t.query.file.endsWith(".json")?t.query.file:t.query.file+".json"),r=JSON.parse(await x.read_file(n));if(!r.genome)throw"genome missing";const i={};let s=0;for(const t of r.mutationset||[]){const e=N.init_bulk_flag(r.genome);if(!e)throw"init_bulk_flag() failed";if(r.mutationset.length>1&&(e.tpsetname=t.name?t.name:"set"+ ++s),i[Math.random()]=e,t.snvindel){const n=(await x.read_file(u.join(o.tpmasterdir,t.snvindel))).trim().split(/\r?\n/),r=S.parseheader(n[0],e);if(r)throw"snvindel header line error: "+r;for(let t=1;t<n.length;t++)S.parseline(t,n[t],e)}if(t.sv){const n=(await x.read_file(u.join(o.tpmasterdir,t.sv))).trim().split(/\r?\n/),r=C.parseheader(n[0],e,!0);if(r)throw"sv header line error: "+r;for(let t=1;t<n.length;t++)C.parseline(t,n[t],e,!0)}if(t.fusion){const n=(await x.read_file(u.join(o.tpmasterdir,t.fusion))).trim().split(/\r?\n/),r=C.parseheader(n[0],e,!1);if(r)throw"fusion header line error: "+r;for(let t=1;t<n.length;t++)C.parseline(t,n[t],e,!1)}if(t.svjson){const n=(await x.read_file(u.join(o.tpmasterdir,t.svjson))).trim().split(/\r?\n/),[r,i]=j.parseheader(n[0],e);if(r)throw"svjson header line error: "+r;for(let t=1;t<n.length;t++)j.parseline(t,n[t],e,i)}if(t.cnv){const n=(await x.read_file(u.join(o.tpmasterdir,t.cnv))).trim().split(/\r?\n/),r=A.parseheader(n[0],e);if(r)throw"cnv header line error: "+r;for(let t=1;t<n.length;t++)A.parseline(t,n[t],e)}if(t.itd){const n=(await x.read_file(u.join(o.tpmasterdir,t.itd))).trim().split(/\r?\n/),r=T.parseheader(n[0],e);if(r)throw"itd header line error: "+r;for(let t=1;t<n.length;t++)T.parseline(t,n[t],e)}if(t.deletion){const n=(await x.read_file(u.join(o.tpmasterdir,t.deletion))).trim().split(/\r?\n/),r=M.parseheader(n[0],e);if(r)throw"deletion header line error: "+r;for(let t=1;t<n.length;t++)M.parseline(t,n[t],e)}if(t.truncation){const n=(await x.read_file(u.join(o.tpmasterdir,t.truncation))).trim().split(/\r?\n/),r=O.parseheader(n[0],e);if(r)throw"Truncation header line error: "+r;for(let t=1;t<n.length;t++)O.parseline(t,n[t],e)}}if(r.annotations){const t=r.annotations.idkey?r.annotations.idkey:"sample";r.annotations.data={};for(const e of r.annotations.files){const n=await x.read_file(u.join(o.tpmasterdir,e));R.tsvParse(n).forEach((e=>{const n=e[t].trim();r.annotations.data[n]||(r.annotations.data[n]=[]),r.annotations.data[n].push(e)}))}}for(const t in i)ae(i[t]);delete r.mutationset,e.send({cohort:r,flagset:i})}catch(t){return void e.send({error:t.message||t})}})),Nt.post(St+"/textfile",(function(t,e){if(!t.query.file)return e.send({error:"no file"});if(ce(t.query.file))return e.send({error:"invalid file name"});const n=u.join(o.tpmasterdir,t.query.file);if(null!=t.query.from){if(!Number.isInteger(t.query.from))return void e.send({error:"invalid value for from"});if(!Number.isInteger(t.query.to))return void e.send({error:"invalid value for to"});const r=[];d(c.createReadStream(n)).on("end",(()=>{e.send({text:r.join("\n")})})).lines.map(String).skip(t.query.from-1).take(t.query.to).forEach((t=>{r.push(t)}))}else c.readFile(n,{encoding:"utf8"},((t,n)=>{t?e.send({error:"error reading file"}):e.send({text:n})}))})),Nt.post(St+"/urltextfile",(async function(t,e){const n=t.query.url.replace(o.URL,`http://127.0.0.1:${o.port}`);try{const t=await f(n);switch(t.statusCode){case 200:return void e.send({text:x.stripJsScript(t.body)});case 404:return void e.send({error:"File not found: "+n});default:e.send({error:"unknown status code: "+t.status})}}catch(t){return e.send({error:"Error downloading file: "+n})}})),Nt.get(St+"/junction",W),Nt.post(St+"/mdsjunction",Z(yt)),Nt.post(St+"/mdscnv",(function(t,e){const[n,i,s,a]=It(t.query);if(n)return e.send({error:n});if(!t.query.rglst)return e.send({error:"rglst missing"});if(!t.query.gain)return e.send({error:".gain missing"});if(!t.query.loss)return e.send({error:".loss missing"});if(a.viewrangeupperlimit){if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a.viewrangeupperlimit)return e.send({error:"zoom in under "+k.bplen(a.viewrangeupperlimit)+" to view details"})}if(t.query.permanentHierarchy){const n=function(t,e){if(!e.cohort)return".cohort missing from ds";if(!e.cohort.hierarchies)return".hierarchies missing from ds.cohort";if(!e.cohort.hierarchies.lst)return".hierarchies.lst[] missing from ds.cohort";const n=e.cohort.hierarchies.lst.find((e=>e.name==t.permanentHierarchy.hierarchyname));if(!n)return"unknown hierarchy "+t.permanentHierarchy.hierarchyname;if(!n.levels)return".levels[] missing in hierarchy "+n.name;const r=n.levels[t.permanentHierarchy.levelidx];if(!r)return"level not found by array idx "+t.permanentHierarchy.levelidx;const o=r.k;return delete t.cohortHiddenAttr,t.cohortOnlyAttr={},t.cohortOnlyAttr[o]={},t.cohortOnlyAttr[o][t.permanentHierarchy.valuekey]=1,null}(t.query,s);if(n)return e.send({error:"permanentHierarchy error: "+n})}const l=[],c={count:0,samples:new Set},f={count:0,samples:new Set};for(const e of t.query.rglst){const n=new Promise(((n,i)=>{const l=m(vt,[a.file?u.join(o.tpmasterdir,a.file):a.url,e.chr+":"+e.start+"-"+e.stop],{cwd:a.usedir}),d=_.createInterface({input:l.stdout}),h=(e.stop-e.start)/e.width,p=[];for(let t=0;t<e.width;t++)p.push({positive:0,negative:0});d.on("line",(n=>{const r=n.split("\t"),o=Number.parseInt(r[1]),i=Number.parseInt(r[2]);if(t.query.bplengthUpperLimit&&i-o>t.query.bplengthUpperLimit)return;const a=JSON.parse(r[3]);if(t.query.valueCutoff&&Math.abs(a.value)<t.query.valueCutoff)return;if(a.sample&&s.cohort&&s.cohort.annotation){const e=s.cohort.annotation[a.sample];if(!e)return;if(t.query.cohortOnlyAttr&&s.cohort&&s.cohort.annotation){let n=!1;for(const r in t.query.cohortOnlyAttr){const o=e[r];if(o&&t.query.cohortOnlyAttr[r][o]){n=!0;break}}if(!n)return}if(t.query.cohortHiddenAttr&&s.cohort.attributes){let n=!1;for(const r in t.query.cohortHiddenAttr){s.cohort.attributes.lst.find((t=>t.key==r)).isNumeric;const o=e[r];if(o){if(t.query.cohortHiddenAttr[r][o]){n=!0;break}}else if(t.query.cohortHiddenAttr[r].Unannotated){n=!0;break}}if(n)return}}a.value>0?(c.count++,c.samples.add(a.sample)):a.value<0&&(f.count++,f.samples.add(a.sample));const l=Math.max(e.start,o),u=Math.min(e.stop,i);let d,m;e.reverse?(d=Math.floor((e.stop-u)/h),m=Math.floor((e.stop-l)/h)):(d=Math.floor((l-e.start)/h),m=Math.floor((u-e.start)/h));for(let t=d;t<m;t++)a.value>0?p[t].positive++:a.value<0&&p[t].negative++}));const g=[];l.stderr.on("data",(t=>g.push(t))),l.on("close",(t=>{const e=g.join("");!e||r(e)?n(p):i(e)}))}));l.push(n)}Promise.all(l).then((n=>{const r=t.query.rglst.reduce(((e,n)=>e+n.width+t.query.regionspace),0)-t.query.regionspace,o=g(r,t.query.gain.barheight+t.query.loss.barheight),i=o.getContext("2d"),l={gain:{count:c.count,samplenumber:c.samples.size},loss:{count:f.count,samplenumber:f.samples.size},maxvalue:0};if(c.count+f.count==0)return i.font="15px Arial",i.fillStyle="#aaa",i.textAlign="center",i.textBaseline="middle",i.fillText("No data in view range",r/2,t.query.gain.barheight),l.src=o.toDataURL(),void e.send(l);for(const t of n)for(const e of t)l.maxvalue=Math.max(l.maxvalue,e.positive,e.negative);const u=t.query.maxvalue||l.maxvalue;let d=0;for(const e of n){for(const n of e){if(n.positive){i.fillStyle=t.query.gain.color||"#67a9cf";const e=Math.ceil(t.query.gain.barheight*Math.min(u,n.positive)/u),r=t.query.gain.barheight-e;i.fillRect(d,r,1,e)}if(n.negative){i.fillStyle=t.query.loss.color||"#ef8a62";const e=Math.ceil(t.query.loss.barheight*Math.min(u,n.negative)/u),r=t.query.gain.barheight;i.fillRect(d,r,1,e)}d++}d+=t.query.regionspace}if(l.src=o.toDataURL(),c.samples.size||f.samples.size){const t=new Set([...c.samples,...f.samples]),[e,n]=function(t,e,n){if(!t.cohort||!t.cohort.annotation||0==n.length)return[null,null];const r=[];for(const e of n){const n=t.cohort.annotation[e];n&&r.push(n)}if(0==r.length)return[null,null];let o,i;if(t.cohort.attributes){o=[];for(const n of t.cohort.attributes.lst){const i={label:n.label,key:n.key};if(n.isNumeric){i.isNumeric=!0;continue}const s=new Map;let a=0;for(const e of r){const r=e[n.key];null!=r?(s.has(r)||s.set(r,new Set),s.get(r).add(e[t.cohort.samplenamekey])):a++}const l=[...s];a&&l.push([qt,a]),l.sort(((t,e)=>e[1]-t[1])),i.values=[];for(const[t,r]of l){const o={name:t,sampleset:r};if(n.values&&n.values[t])for(const e in n.values[t])o[e]=n.values[t][e];e.attributeSummary&&e.attributeSummary[n.key]&&e.attributeSummary[n.key][t]&&(o.totalCount=e.attributeSummary[n.key][t]),i.values.push(o)}o.push(i)}}if(t.cohort.hierarchies){i={};for(const n of t.cohort.hierarchies.lst){const o=E()(y(r,n.levels));o.sum((t=>t.value));const s=[];o.eachBefore((r=>{const o={id:r.data.id,name:r.data.name,label:r.data.full,depth:r.depth};if(r.data.lst){o.sampleset=new Set;for(const e of r.data.lst)o.sampleset.add(e[t.cohort.samplenamekey])}r.children||(o.isleaf=1),e.hierarchySummary&&e.hierarchySummary[n.name]&&(o.totalCount=e.hierarchySummary[n.name][r.id]),s.push(o)})),i[n.name]=s}}return[o,i]}(s,a,[...t]);if(e){for(const t of e)for(const e of t.values){e.gain=0,e.loss=0;for(const t of e.sampleset)c.samples.has(t)&&e.gain++,f.samples.has(t)&&e.loss++;delete e.sampleset}l.attributeSummary=e}if(n){for(const t in n)for(const e of n[t])if(e.sampleset){e.gain=0,e.loss=0;for(const t of e.sampleset)c.samples.has(t)&&e.gain++,f.samples.has(t)&&e.loss++}l.hierarchySummary=n}}e.send(l)})).catch((t=>{e.send({error:t}),t.stack&&console.error(t.stack)}))})),Nt.post(St+"/mdssvcnv",(async function(t,n){let i,s,a,l,f,d,h,p,g;if(t.query.iscustom){if(i=yt[t.query.genome],!i)return n.send({error:"invalid genome"});if(s={},a={iscustom:1,file:t.query.file,url:t.query.url,indexURL:t.query.indexURL,allow_getallsamples:!0},t.query.checkexpressionrank){if(!t.query.checkexpressionrank.file&&!t.query.checkexpressionrank.url)return n.send({error:"no file or url for checkexpressionrank"});a.checkexpressionrank={file:t.query.checkexpressionrank.file,url:t.query.checkexpressionrank.url,indexURL:t.query.checkexpressionrank.indexURL}}if(t.query.checkvcf){let e;try{e=JSON.parse(t.query.checkvcf)}catch(t){return n.send({error:"invalid JSON for VCF object"})}if(!e.file&&!e.url)return n.send({error:"no file or url for custom VCF track"});e.type=k.mdsvcftype.vcf,a.checkvcf={info:e.info,tracks:[e]}}if(t.query.checkrnabam){if(!t.query.checkrnabam.samples)return n.send({error:"samples{} missing from checkrnabam"});let e=0;for(const n in t.query.checkrnabam.samples)e++;if(e>13)return n.send({error:"no more than 13 BAM files allowed"});const r=$t(t.query.checkrnabam);if(r)return n.send({error:r});a.checkrnabam=t.query.checkrnabam}}else{if(i=yt[t.query.genome],!i)return n.send({error:"invalid genome"});if(!i.datasets)return n.send({error:"genome is not equipped with datasets"});if(s=i.datasets[t.query.dslabel],!s)return n.send({error:"invalid dslabel"});if(t.query.getsample4disco)return function(t,e,n,r){if(t.query.iscustom)return e.send({error:"not for custom track"});if(!r.singlesamplemutationjson)return e.send({error:"singlesamplemutationjson not available for this dataset"});const i=t.query.getsample4disco,s=r.singlesamplemutationjson.samples[i];if(!s)return e.send({error:"no data"});const a=u.join(o.tpmasterdir,s);c.readFile(a,{encoding:"utf8"},((t,n)=>{if(t)return e.send({error:"error getting data for this sample"});e.send({text:n})}))}(t,n,0,s);if(t.query.gettrack4singlesample)return function(t,e,n){const r=t.query.gettrack4singlesample;if(t.query.iscustom)return e.send({error:"no server-side config available for custom track"});if(!n.sampleAssayTrack)return e.send({});return e.send({tracks:n.sampleAssayTrack.samples.get(r)})}(t,n,s);if(t.query.findsamplename)return function(t,e,n){if(t.query.iscustom)return e.send({error:"cannot search sample by name in custom track"});const r=t.query.findsamplename.toLowerCase(),o=[];if(!n.cohort.__samplelst){n.cohort.__samplelst=[];for(const t in n.cohort.annotation)n.cohort.__samplelst.push({name:t,low:t.toLowerCase()})}i(n.cohort.__samplelst);for(const t in n.queries){const e=n.queries[t];if(e.type==k.tkt.mdssvcnv&&e.groupsamplebyattr)for(const t of o){const r=n.cohort.annotation[t.name];if(!r)continue;const o=[];for(const t of e.groupsamplebyattr.attrlst){const e=r[t.k];e&&o.push({k:t.k,kvalue:e})}o.length&&(t.attributes=o,t.grouplabel=o.map((t=>t.kvalue)).join(e.groupsamplebyattr.attrnamespacer))}}if(n.cohort&&n.cohort.sampleAttribute&&n.cohort.sampleAttribute.attributes&&n.cohort.annotation)for(const t of o){const e=n.cohort.annotation[t.name];if(!e)continue;const r=[];for(const t in n.cohort.sampleAttribute.attributes){if(n.cohort.sampleAttribute.attributes[t].clientnoshow)continue;const o=e[t];null!=o&&r.push({k:t,v:o})}r.length&&(t.attr=r)}if(n.sampleAssayTrack)for(const t of o){const e=n.sampleAssayTrack.samples.get(t.name);e&&(t.num_assay_tracks=e.length)}if(n.cohort&&n.cohort.mutation_signature)for(const t in n.cohort.mutation_signature.sets){const e=n.cohort.mutation_signature.sets[t];if(e.samples)for(const t of o)e.samples.map.has(t.name)&&(t.mutation_signature=1)}if(n.singlesamplemutationjson)for(const t of o)n.singlesamplemutationjson.samples[t.name]&&(t.disco=1);return e.send({result:o});function i(t){for(const e of t){if(o.length>10)return;-1!=e.low.indexOf(r)&&(o.find((t=>t.name==e.name))||o.push(e))}}}(t,n,s);if(t.query.assaymap)return async function(t,e,n){try{if(!n.assayAvailability)throw"assay availability not enabled for this dataset";const r=new Set(t.query.skip_termids||[]),o=new Map;for(const e in n.cohort.annotation){if(t.query.key){if(n.cohort.annotation[e][t.query.key]!=t.query.value)continue}o.set(e,new Map)}for(const[t,e]of o){const o=n.assayAvailability.samples.get(t);if(o)for(const t of n.assayAvailability.assays)r.has(t.id)||o[t.id]&&e.set(t.id,"yes")}for(const t of o.keys())0==o.get(t).size&&o.delete(t);const i={};i.totalsample=o.size,i.terms=ot({sample2term:o,terms:n.assayAvailability.assays,config:{termidorder:t.query.termidorder}}),e.send(i)}catch(t){e.send({error:t.message||t})}}(t,n,s);if(!s.queries)return n.send({error:"dataset is not equipped with queries"});if(a=s.queries[t.query.querykey],!a)return n.send({error:"invalid querykey"})}if(t.query.getexpression4gene)return async function(t,e,n,r,i){try{const n=t.query.getexpression4gene;if(!n.chr)throw"chr missing";if(!Number.isFinite(n.start))throw"invalid start pos";if(!Number.isFinite(n.stop))throw"invalid stop pos";if(!n.name)throw"unknown gene name";if(i.checkrnabam){const r=yt[t.query.genome],o=r.tracks.find((t=>t.__isgene)),s=(await Wt(r,o,n.chr,n.start,n.stop)).get(n.name);if(!s)throw"no gene matching with "+n.name;const a={};await Pt(new Map([[n.name,s]]),n.chr,n.start,n.stop,i,a);const l={};for(const t of a.checkrnabam)if(t.genes){const e=t.genes.find((t=>t.gene==n.name));e&&(l[t.sample]=e)}return void e.send({sample2rnabam:l})}let s;if(i.iscustom?s=i.checkexpressionrank:i.expressionrank_querykey&&(s=r.queries[i.expressionrank_querykey]),!s)throw"missing expression data source";const a=s.file?null:await x.cache_index(s.url,s.indexURL),l=[];await x.get_lines_bigfile({args:[s.file?u.join(o.tpmasterdir,s.file):s.url,n.chr+":"+n.start+"-"+n.stop],dir:a,callback:t=>{const e=t.split("\t");let r;try{r=JSON.parse(e[3])}catch(t){reject("invalid json from expression data")}r.sample&&r.gene&&Number.isFinite(r.value)&&(delete r.outlier,r.gene.toLowerCase()==n.name.toLowerCase()&&l.push(r))}});const c=function(t,e,n){const r={};if(t&&t.cohort&&t.cohort.annotation&&e.groupsamplebyattr&&e.groupsamplebyattr.attrlst){const o=new Map;for(const r of n){const n=t.cohort.annotation[r.sample];if(!n)continue;const i=[];for(const t of e.groupsamplebyattr.attrlst)i.push(n[t.k]);const s=i.join(",");o.has(s)||o.set(s,[]),o.get(s).push(r)}for(const t of o.values()){t.sort(((t,e)=>t.value-e.value));for(const e of t)e.rank=Yt(e.value,t),r[e.sample]=e}}else{n.sort(((t,e)=>t.value-e.value));for(const t of n)t.rank=Yt(t.value,n),r[t.sample]=t}return r}(r,i,l);e.send({sample2rank:c})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}}(t,n,0,s,a);if(t.query.ifsamplehasvcf)return function(t,e,n,r,o){if(t.query.iscustom)return e.send({no:1});if(!o.vcf_querykey)return e.send({yes:1});const i=r.queries[o.vcf_querykey];if(!i)return e.send({error:"vcf query missing"});e.send(i.singlesamples?{yes:1}:{no:1})}(t,n,0,s,a);if(!t.query.rglst)return n.send({error:"rglst missing"});if(a.viewrangeupperlimit){if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a.viewrangeupperlimit)return n.send({error:"zoom in under "+k.bplen(a.viewrangeupperlimit)+" to view details"})}t.query.hiddendt&&(l=new Set(t.query.hiddendt));if(t.query.hiddenmattr){f={};for(const e in t.query.hiddenmattr)f[e]=new Set(t.query.hiddenmattr[e])}if(t.query.filteralleleattr){d={};for(const e in t.query.filteralleleattr){const n=t.query.filteralleleattr[e];n.cutoffvalue,d[e]=n}}if(t.query.filterlocusattr){h={};for(const e in t.query.filterlocusattr){const n=t.query.filterlocusattr[e];n.cutoffvalue,h[e]=n}}if(t.query.sampleset){const e=new Set,n=new Map;for(const r of t.query.sampleset)for(const t of r.samples)e.add(t),n.set(t,r.name);e.size&&(p={set:e,sample2group:n})}if(t.query.hiddensampleattr){g={};for(const e in t.query.hiddensampleattr)g[e]=new Set(t.query.hiddensampleattr[e])}if(a.url)try{a.dir=await x.cache_index(a.url,a.indexURL)}catch(t){return n.send({error:"svcnv file index url error"})}const y=await function(t,e,n,i,s,a,l){if(!e.file&&!e.url)return[];const c=[];for(const f of n.query.rglst){const d=new Promise(((c,d)=>{const h=[],p=m(vt,[e.file?u.join(o.tpmasterdir,e.file):e.url,f.chr+":"+f.start+"-"+f.stop],{cwd:e.dir});_.createInterface({input:p.stdout}).on("line",(e=>{const r=e.split("\t"),o=Number.parseInt(r[1]),c=Number.parseInt(r[2]);let u;try{u=JSON.parse(r[3])}catch(t){return}if(!(null==u.dt||i&&i.has(u.dt))){if(u.dt==k.dtloh){if(u.segmean&&n.query.segmeanValueCutoff&&u.segmean<n.query.segmeanValueCutoff)return;if(n.query.lohLengthUpperLimit&&c-o>n.query.lohLengthUpperLimit)return;u.chr=r[0],u.start=o,u.stop=c}else if(u.dt==k.dtfusionrna||u.dt==k.dtsv)u._chr=r[0],u._pos=o,u.chrA?(u.chrB=r[0],u.posB=o):(u.chrA=r[0],u.posA=o);else if(u.dt==k.dtcnv){if(n.query.hide_cnvloss&&u.value<0)return;if(n.query.hide_cnvgain&&u.value>0)return;if(n.query.valueCutoff&&Math.abs(u.value)<n.query.valueCutoff)return;if(n.query.bplengthUpperLimit&&c-o>n.query.bplengthUpperLimit)return;u.chr=r[0],u.start=o,u.stop=c}else{if(u.dt!=k.dtitd)return void console.error("unknown dt from svcnv file: "+u.dt);u.chr=r[0],u.start=o,u.stop=c}if(n.query.singlesample){if(u.sample!=n.query.singlesample)return}else if(l){if(!l.set.has(u.sample))return}else if(u.sample&&t.cohort&&t.cohort.annotation){const e=t.cohort.annotation[u.sample];if(!e)return;if(s)for(const t in s){const n=e[t];if(s[t].has(n))return}}if(a)for(const t in a){let e=u.mattr?u.mattr[t]:void 0;if(null==e&&(e=k.not_annotated),a[t].has(e))return}h.push(u)}}));const g=[];p.stderr.on("data",(t=>g.push(t))),p.on("close",(t=>{const e=g.join("");!e||r(e)?c(h):d(e)}))}));c.push(d)}return Promise.all(c)}(s,a,t,l,g,f,p),[v,b]=await function(t,e,n,i){if(n.query.singlesample)return[];let s;e.iscustom?s=e.checkexpressionrank:e.expressionrank_querykey&&t.queries[e.expressionrank_querykey]&&(s=t.queries[e.expressionrank_querykey]);if(!s)return[];let a=s.viewrangeupperlimit;!a&&e.iscustom&&(a=5e6);if(a){if(n.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a)return[a]}return Promise.resolve().then((()=>s.file?"":x.cache_index(s.url,s.indexURL))).then((t=>{const e=new Map,i=[];for(const a of n.query.rglst){const n=new Promise(((n,i)=>{const l=m(vt,[s.file?u.join(o.tpmasterdir,s.file):s.url,a.chr+":"+a.start+"-"+a.stop],{cwd:t});_.createInterface({input:l.stdout}).on("line",(t=>{const n=t.split("\t");let r;try{r=JSON.parse(n[3])}catch(t){return}r.gene&&r.sample&&Number.isFinite(r.value)&&(e.has(r.gene)||e.set(r.gene,{chr:n[0],start:Number.parseInt(n[1]),stop:Number.parseInt(n[2]),samples:new Map}),e.get(r.gene).samples.set(r.sample,{value:r.value,ase:r.ase}))}));const c=[];l.stderr.on("data",(t=>c.push(t))),l.on("close",(t=>{const e=c.join("");!e||r(e)?n():i(e)}))}));i.push(n)}return Promise.all(i).then((()=>[!1,e]))}))}(s,a,t),[w,N]=await async function(t,n,i,s,a,l,f,d,h,p){let g;i.iscustom?g=i.checkvcf:i.vcf_querykey&&n.queries[i.vcf_querykey]&&(g=n.queries[i.vcf_querykey]);if(!g)return[null,null];if(s.query.singlesample&&g.singlesamples){const e=g.singlesamples.samples[s.query.singlesample];if(e){const i={file:u.join(o.tpmasterdir,e)};try{await c.promises.stat(i.file)}catch(t){return[null,null]}const l=await Vt(i.file),[f,p,g,y]=q.vcfparsemeta(l);if(y)throw y;return i.info=f,i.format=p,i.samples=g,i.nochr=await x.tabix_is_nochr(i.file,null,t),function(t,e,n,o,i,s,a){const l=[],c=[];for(const i of t.query.rglst){const u=new Promise(((c,u)=>{const f=m(vt,[n.file,(n.nochr?i.chr.replace("chr",""):i.chr)+":"+i.start+"-"+i.stop]);_.createInterface({input:f.stdout}).on("line",(r=>{const[i,c,u]=q.vcfparseline(r,n);for(const n of c){if(!n.sampledata)continue;const r=n.sampledata.find((e=>e.sampleobj.name==t.query.singlesample));if(r){if(delete r.allele2readcount,n.sampledata=[r],o){let t=!1;for(const e in o){const r=n.altinfo[e];if(null==r){t=!0;break}const i=o[e];if(null!=i.cutoffvalue){if(!Number.isFinite(r)){t=!0;break}if(i.keeplowerthan){if(r>i.cutoffvalue){t=!0;break}}else if(r<i.cutoffvalue){t=!0;break}}}if(t)continue}if(!r.gtallref){if(r.__gtalleles){if(-1==r.__gtalleles.indexOf(n.alt))continue;delete r.__gtalleles}if(s){const t=[];for(const e of n.sampledata){let n=!0;for(const t in s){let r=e[t];if(null==r&&(r=k.not_annotated),s[t].has(r)){n=!1;break}}n&&t.push(e)}if(0==t.length)continue;n.sampledata=t}if(a&&e.cohort&&e.cohort.annotation){const t=[];for(const r of n.sampledata){const n=e.cohort.annotation[r.sampleobj.name];if(!n)continue;let o=!0;for(const t in a){const e=n[t];if(a[t].has(e)){o=!1;break}}o&&t.push(r)}if(0==t.length)continue;n.sampledata=t}delete n._m,delete n.vcf_ID,delete n.name,n.dt=k.dtsnvindel,l.push(n)}}}}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(t=>{const e=d.join("");!e||r(e)?c():u(e)}))}));c.push(u)}return Promise.all(c).then((()=>[null,l]))}(s,n,i,a,0,d,h)}}let y=g.viewrangeupperlimit;!y&&i.iscustom&&(y=e.features.customMdsSingleSampleVcfNoRangeLimit?0:2e6);s.query.singlesample&&(y*=5);if(y){if(s.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=y)return[y,null]}const v=[];for(const t of g.tracks){const e=Promise.resolve().then((()=>t.file?"":x.cache_index(t.url,t.indexURL))).then((e=>{t.dir=e;const i=[],c=[];for(const f of s.query.rglst){const y=new Promise(((c,y)=>{const v=m(vt,[t.file?u.join(o.tpmasterdir,t.file):t.url,(t.nochr?f.chr.replace("chr",""):f.chr)+":"+f.start+"-"+f.stop],{cwd:e});_.createInterface({input:v.stdout}).on("line",(e=>{if(t.type==k.mdsvcftype.vcf){const[r,o,c]=q.vcfparseline(e,{nochr:t.nochr,samples:t.samples,info:g.info,format:t.format});for(const t of o)if(t.sampledata){if(a){let e=!1;for(const n in a){const r=t.altinfo[n];if(null==r){e=!0;break}const o=a[n];if(null!=o.cutoffvalue){if(!Number.isFinite(r)){e=!0;break}if(o.keeplowerthan){if(r>o.cutoffvalue){e=!0;break}}else if(r<o.cutoffvalue){e=!0;break}}else if(o.includes(r)){e=!0;break}}if(e)continue}if(l){let e=!1;for(const n in l){const r=t.info[n];if(null==r){e=!0;break}let o=r;if(Array.isArray(r)&&(o=r[0],"."==o)){e=!0;break}const i=l[n];if(null!=i.cutoffvalue){if(!Number.isFinite(o)){e=!0;break}if(i.keeplowerthan){if(o>i.cutoffvalue){e=!0;break}}else if(o<i.cutoffvalue){e=!0;break}}else if(i.includes(o)){e=!0;break}}if(e)continue}{const e=[];for(const n of t.sampledata)if(!n.gtallref){if(n.__gtalleles){if(-1==n.__gtalleles.indexOf(t.alt))continue;delete n.__gtalleles}e.push(n)}if(0==e.length)continue;t.sampledata=e}if(s.query.singlesample){let e=null;for(const n of t.sampledata)if(n.sampleobj.name==s.query.singlesample){e=n;break}if(!e)continue;t.sampledata=[e]}else if(p){const e=t.sampledata.filter((t=>p.set.has(t.sampleobj.name)));if(!e.length)continue;t.sampledata=e}if(d){const e=[];for(const n of t.sampledata){let t=!0;for(const e in d){let r=n[e];if(null==r&&(r=k.not_annotated),d[e].has(r)){t=!1;break}}t&&e.push(n)}if(0==e.length)continue;t.sampledata=e}if(h&&n.cohort&&n.cohort.annotation){const e=[];for(const r of t.sampledata){const t=n.cohort.annotation[r.sampleobj.name];if(!t)continue;let o=!0;for(const e in h){const n=t[e];if(h[e].has(n)){o=!1;break}}o&&e.push(r)}if(0==e.length)continue;t.sampledata=e}for(const e of t.sampledata)delete e.allele2readcount;delete t._m,delete t.vcf_ID,delete t.name,t.dt=k.dtsnvindel,i.push(t)}}else console.error('unknown "type" from a vcf file')}));const b=[];v.stderr.on("data",(t=>b.push(t))),v.on("close",(t=>{const e=b.join("");!e||r(e)?c():y(e)}))}));c.push(y)}return Promise.all(c).then((()=>i))}));v.push(e)}return Promise.all(v).then((t=>{const e=[];for(const n of t)for(const t of n)if(t.dt!=k.dtsnvindel)console.error("unknown dt: "+t.dt);else{if(!t.sampledata)continue;let n=!0;for(const r of e)if(t.chr==r.chr&&t.pos==r.pos&&t.ref==r.ref&&t.alt==r.alt){for(const e of t.sampledata)r.sampledata.push(e);n=!1;break}n&&e.push(t)}return e.sort(((t,e)=>t.pos-e.pos)),[null,e]}))}(i,s,a,t,d,h,0,f,g,p),S=function(t){const e=new Map;for(const n of t)for(const t of n){if(!t.sample)continue;const n=t.sample;e.has(n)||e.set(n,[]),t._chr?e.get(n).push(t):(delete t.sample,delete t.sampletype,e.get(n).push(t))}return e}(y);if(t.query.singlesample){const e={lst:S.get(t.query.singlesample)};return w?e.vcfrangelimit=w:e.data_vcf=N,void n.send(e)}const A={samplegroups:Bt(s,a,y,N,S,p),vcfrangelimit:w,data_vcf:N};t.query.getallsamples&&a.allow_getallsamples&&(A.getallsamples=!0);a.checkrnabam?await async function(t,e,n,r){if(!n.checkvcf)return;if(t.stop-t.start>=5e5)return void(r.expressionrangelimit=5e5);const o=e.tracks.find((t=>t.__isgene)),i=await Wt(e,o,t.chr,t.start,t.stop);let s,a=null;for(const t of i.values())null==a?(a=t.start,s=t.stop):(a=Math.min(a,t.start),s=Math.max(s,t.stop));await Pt(i,t.chr,a,s,n,r)}(t.query.rglst[0],i,a,A):function(t,e,n,r){if(n)return void(t.expressionrangelimit=n);if(r){t.gene2coord={};for(const[e,n]of r)t.gene2coord[e]={chr:n.chr,start:n.start,stop:n.stop};if(0==t.samplegroups.length)return;if(t.getallsamples){const e=new Set(t.samplegroups[0].samples.map((t=>t.samplename))),n=new Set;for(const[t,o]of r)for(const t of o.samples.keys())e.has(t)||n.add(t);for(const e of n)t.samplegroups[0].samples.push({samplename:e,items:[]})}for(const n of t.samplegroups){const t=new Map;for(const[o,i]of r){t.set(o,[]);for(const[r,s]of i.samples)if(n.attributes&&e.cohort&&e.cohort.annotation){const i=e.cohort.annotation[r];if(!i)continue;let a=!0;for(const t of n.attributes)if(i[t.k]!=t.kvalue){a=!1;break}a&&t.get(o).push(s)}else t.get(o).push(s)}for(const[e,n]of t)n.sort(((t,e)=>t.value-e.value));for(const e of n.samples){e.expressionrank={};for(const[n,o]of t){const t=r.get(n).samples.get(e.samplename);if(null==t)continue;const i=Yt(t.value,o);e.expressionrank[n]={rank:i};for(const r in t)e.expressionrank[n][r]=t[r]}}}}}(A,s,v,b);(function(t,e){if(t.cohort&&t.cohort.sampleAttribute&&t.cohort.sampleAttribute.attributes&&t.cohort.annotation){e.sampleannotation={};const n=[];for(const e in t.cohort.sampleAttribute.attributes){t.cohort.sampleAttribute.attributes[e].clientnoshow||n.push(e)}for(const r of e.samplegroups)for(const o of r.samples){const r=t.cohort.annotation[o.samplename];if(r){const t={};let i=!1;for(const e of n){const n=r[e];null!=n&&(i=!0,t[e]=n)}i&&(e.sampleannotation[o.samplename]=t)}}}})(s,A),n.send(A)})),Nt.post(St+"/mdsgenecount",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.datasets)throw"no datasets from genome";const r=n.datasets[t.query.dslabel];if(!r)throw"invalid dataset";if(!r.gene2mutcount)throw"not supported on this dataset";if(!t.query.samples)throw".samples missing";let o,i;o=t.query.selectedMutTypes?t.query.selectedMutTypes.join("+"):"total",i=t.query.nGenes?t.query.nGenes:15;const s=`WITH\n\tfiltered AS (\n\t\tSELECT gene, ${o} AS total FROM genecount\n\t\tWHERE sample IN (${JSON.stringify(t.query.samples).replace(/[[\]\"]/g,"").split(",").map((t=>"'"+t+"'")).join(",")})\n\t)\n\tSELECT gene, SUM(total) AS count\n\tFROM filtered\n\tGROUP BY gene\n\tORDER BY count DESC\n\tLIMIT ${i}`,a=r.gene2mutcount.db.prepare(s).all(),l=[];for(const t of a){const e=n.genedb.getCoordByGene.get(t.gene);e&&(e.gene=t.gene,e.count=t.count,delete e.name,l.push(e))}e.send({genes:l})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/mds2",tt.handle_request(yt)),Nt.post(St+"/mdsexpressionrank",(function(t,e){let n,i,s,a=new Set;Promise.resolve().then((()=>{if(!t.query.rglst)throw"rglst missing";if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>1e7)throw"Zoom in below 10 Mb to show expression rank";if(!t.query.sample)throw"sample missing";if(t.query.iscustom){if(n=yt[t.query.genome],!n)throw"invalid genome";if(!t.query.file&&!t.query.url)throw"no file or url for expression data";i={},s={file:t.query.file,url:t.query.url,indexURL:t.query.indexURL}}else{const[e,r,o,a]=It(t.query);if(e)throw e;if(n=r,i=o,s=a,!s.samples)throw"total samples missing from server config";if(-1==s.samples.indexOf(t.query.sample))throw{nodata:1}}if(s.viewrangeupperlimit&&t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>s.viewrangeupperlimit)throw"zoom in under "+k.bplen(s.viewrangeupperlimit)+" to view data";if(t.query.levelkey){if(!t.query.levelvalue)throw"levelvalue is required when levelkey is used";if(!i.cohort||!i.cohort.annotation)throw".cohort.annotation missing from dataset"}if(!s.file){if(!s.url)throw"file or url missing";return x.cache_index(s.url,s.indexURL)}})).then((e=>{const n=[];for(const l of t.query.rglst)n.push(new Promise(((n,c)=>{const f=m(vt,[s.file?u.join(o.tpmasterdir,s.file):s.url,l.chr+":"+l.start+"-"+l.stop],{cwd:e}),d=_.createInterface({input:f.stdout}),h=new Map;d.on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(!r.gene)return;if(!r.sample)return;if(!Number.isFinite(r.value))return;const o=n[0],s=Number.parseInt(n[1]),l=Number.parseInt(n[2]);if(r.sample==t.query.sample)return h.has(r.gene)||h.set(r.gene,{chr:o,start:s,stop:l,allvalues:[]}),h.get(r.gene).thisvalue=r.value,void(r.ase&&(h.get(r.gene).ase=r.ase));if(t.query.attributes){const e=i.cohort.annotation[r.sample];if(!e)return;for(const n of t.query.attributes)if(n.k&&n.kvalue&&n.kvalue!=e[n.k])return}a.add(r.sample),h.has(r.gene)||h.set(r.gene,{chr:o,start:s,stop:l,allvalues:[]}),h.get(r.gene).allvalues.push({value:r.value})}));const p=[];f.stderr.on("data",(t=>p.push(t))),f.on("close",(t=>{const e=p.join("");e&&!r(e)&&c({message:e}),n(h)}))})));return Promise.all(n)})).then((t=>{const n=[];for(const e of t)for(const[t,r]of e)null!=r.thisvalue&&(r.allvalues.sort(((t,e)=>t.value-e.value)),r.rank=Yt(r.thisvalue,r.allvalues),delete r.allvalues,r.gene=t,n.push(r));e.send({result:n,samplecount:a.size})})).catch((t=>{t.stack&&console.log(t),t.nodata?e.send({nodata:1}):e.send({error:t.message?t.message:t})}))})),Nt.post(St+"/mdsgeneboxplot",st(yt)),Nt.post(St+"/mdsgenevalueonesample",(async function(t,e){const n=t.query;try{if(!n.sample)throw".sample missing";if(!n.genes)throw".genes[] missing";let r,i,s;if(t.query.iscustom){if(r=yt[n.genome],!r)throw"invalid genome";if(!n.file&&!n.url)throw"no file or url for expression data";i={},s={file:n.file,url:n.url,indexURL:n.indexURL}}else{const[t,e,o,a]=It(n);if(t)throw t;r=e,i=o,s=a}const a=s.file?null:await x.cache_index(s.url,s.indexURL),l={};let c=!0;for(const t of n.genes){let e;await x.get_lines_bigfile({args:[s.file?u.join(o.tpmasterdir,s.file):s.url,t.chr+":"+t.start+"-"+t.stop],dir:a,callback:r=>{const o=r.split("\t");if(!o[3])return;const i=JSON.parse(o[3]);i.gene==t.gene&&i.sample==n.sample&&(e=i.value)}}),Number.isFinite(e)&&(l[t.gene]=e,c=!1)}c?e.send({nodata:1}):e.send({result:l})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/vcf",(async function(t,e){try{const[n,r,o]=ue(t);if(n)throw n;const i=o?await x.cache_index(r,t.query.indexURL):null;if(!t.query.rglst)throw"rglst missing";const s=[];for(const e of t.query.rglst)await x.get_lines_bigfile({args:[r,e.chr+":"+e.start+"-"+e.stop],dir:i,callback:t=>s.push(t)});e.send({linestr:s.join("\n")})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/vcfheader",(async function(t,e){try{if(!t.query.genome)throw"genome missing";const n=yt[t.query.genome];if(!n)throw"invalid genome";const[r,o,i]=ue(t);if(r)throw r;const s=i?await x.cache_index(o,t.query.indexURL):null;e.send({metastr:(await x.get_header_tabix(o,s)).join("\n"),nochr:await x.tabix_is_nochr(o,s,n)})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/translategm",(async function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";const r=t.query.gm;if(!r)throw"missing gm{}";if(!r.chr)throw"gm.chr missing";if(!r.start)throw"gm.start missing";if(!Number.isInteger(r.start))throw"gm.start not integer";if(!r.stop)throw"gm.stop missing";if(!Number.isInteger(r.stop))throw"gm.stop not integer";const o=await x.get_fasta(n,r.chr+":"+(r.start+1)+"-"+r.stop),i=k.fasta2gmframecheck(r,o);e.send({frame:i})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.get(St+"/hicstat",(async function(t,e){Mt(t);try{const[n,r,o]=ue(t);if(n)throw"illegal file name";o||await x.file_is_readable(r);const i=await it(r,o);e.send({out:i})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/hicdata",(function(t,e){const[n,r,o]=ue(t);if(n)return void e.send({error:"illegal file name"});const i=[t.query.nmeth||"NONE",r,t.query.pos1,t.query.pos2,t.query.isfrag?"FRAG":"BP",t.query.resolution],s=m(wt,i),a=_.createInterface({input:s.stdout}),l=[],c=[];let u=0,f=0;a.on("line",(e=>{const n=e.split("\t");if(3!=n.length)return void u++;const r=Number.parseInt(n[0]),o=Number.parseInt(n[1]),i=Number.parseFloat(n[2]);Number.isNaN(r)||Number.isNaN(o)||Number.isNaN(i)?f++:null!=t.query.mincutoff&&i<=t.query.mincutoff||l.push([r,o,i])})),s.stderr.on("data",(t=>c.push(t))),s.on("close",(()=>{const t=c.join("");return t?e.send({error:t}):u?e.send({error:u+" lines have other than 3 fields"}):f?e.send({error:f+" lines have non-numerical values in any of the 3 fields"}):void e.send({items:l})}))})),Nt.post(St+"/samplematrix",(function(t,e){Promise.resolve().then((()=>{const e=yt[t.query.genome];if(!e)throw"invalid genome";let n,r;if(t.query.iscustom){if(!t.query.querykey2tracks)throw"querykey2tracks{} missing for custom dataset";n={queries:{}};for(const e in t.query.querykey2tracks){const r=t.query.querykey2tracks[e];if(!r.type)throw'missing "type" for a data track';if(r.type==k.tkt.mdsvcf){const r=t.query.querykey2tracks[e];r.type=k.mdsvcftype.vcf,n.queries[e]={type:k.tkt.mdsvcf,info:r.info,tracks:[r]}}else if(r.type==k.tkt.mdssvcnv)n.queries[e]=r;else{if(r.type!=k.tkt.mdsexpressionrank)throw"unknown type of data track: "+r.type;n.queries[e]=r}}}else{if(!e.datasets)throw"genome is not equipped with datasets";if(!t.query.dslabel)throw"dslabel missing";if(n=e.datasets[t.query.dslabel],!n)throw"invalid dslabel";if(!n.queries)throw"dataset is not equipped with queries"}if(t.query.sampleset)r=new Set(t.query.sampleset);else if(t.query.limitsamplebyeitherannotation){if(!n.cohort)throw"limitsamplebyeitherannotation but no cohort in ds";if(!n.cohort.annotation)throw"limitsamplebyeitherannotation but no cohort.annotation in ds";r=new Set;for(const e in n.cohort.annotation){const o=n.cohort.annotation[e];for(const n of t.query.limitsamplebyeitherannotation)if(o[n.key]==n.value){r.add(e);break}}}const o=[];for(const e of t.query.features){let t,i=[];if(e.querykey){if(!n.queries)throw"using querykey for a feature but no ds.queries";if(t=n.queries[e.querykey],!t)throw"unknown dsquery by key "+e.querykey}else if(e.querykeylst){if(!n.queries)throw"using querykeylst for a feature but no ds.queries";for(const t of e.querykeylst){const e=n.queries[t];if(!e)throw'unknown key "'+t+'" from querykeylst';i.push(e)}if(0==i.length)throw"no valid keys in querykeylst"}else if(!e.issampleattribute)throw"unknown way to query a feature";if(e.isgenevalue){const[i,s]=Kt(e,n,t,r);if(i)throw"error with isgenevalue: "+i;o.push(s)}else if(e.iscnv){const[i,s]=Xt(e,n,t,r);if(i)throw"error with iscnv: "+i;o.push(s)}else if(e.isloh){const[i,s]=te(e,n,t,r);if(i)throw"error with isloh: "+i;o.push(s)}else if(e.isvcf){const[i,s]=ie(e,n,t,r);if(i)throw"error with isvcf: "+i;o.push(s)}else if(e.isitd){const[i,s]=ee(e,n,t,r);if(i)throw"error with isitd: "+i;o.push(s)}else if(e.issvfusion){const[i,s]=ne(e,n,t,r);if(i)throw"error with issvfusion: "+i;o.push(s)}else if(e.issvcnv){const[i,s]=re(e,n,t,r);if(i)throw"error with issvcnv: "+i;o.push(s)}else if(e.ismutation){const[t,s]=oe(e,n,i,r);if(t)throw"error with ismutation: "+t;o.push(s)}else{if(!e.issampleattribute)throw"unknown type of feature";{const[t,i]=Qt(e,n,r);if(t)throw"error with issampleattribute: "+t;o.push(i)}}}return Promise.all(o)})).then((t=>{e.send({results:t})})).catch((t=>{e.send({error:"string"==typeof t?t:t.message}),t.stack&&console.error(t.stack)}))})),Nt.get(St+"/mdssamplescatterplot",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"invalid genome";const r=n.datasets[t.query.dslabel];if(!r)throw"invalid dataset";if(!r.cohort)throw"no cohort for dataset";if(!r.cohort.annotation)throw"cohort.annotation missing for dataset";const o=r.cohort.scatterplot;if(!o)throw"scatterplot not supported for this dataset";const i=[];for(const e in r.cohort.annotation){const n=r.cohort.annotation[e];if(t.query.subsetkey&&n[t.query.subsetkey]!=t.query.subsetvalue)continue;const s=n[o.x.attribute];if(!Number.isFinite(s))continue;const a=n[o.y.attribute];Number.isFinite(a)&&i.push({sample:e,x:s,y:a,s:n})}e.send({colorbyattributes:o.colorbyattributes,colorbygeneexpression:o.colorbygeneexpression,querykey:o.querykey,dots:i,tracks:o.tracks})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/mdssamplesignature",(function(t,e){try{const n=t.query;if(!n.sample)throw".sample missing";const r=yt[n.genome];if(!r)throw"invalid genome";const o=r.datasets[n.dslabel];if(!o)throw"invalid dataset";if(!o.cohort)throw"no cohort for dataset";if(!o.cohort.mutation_signature)throw"no mutation_signature for cohort";const i=[];for(const t in o.cohort.mutation_signature.sets){const e=o.cohort.mutation_signature.sets[t];if(!e.samples)continue;const r=e.samples.map.get(n.sample);if(!r)continue;const s=[];for(const t in e.signatures)r[t]&&s.push({k:t,v:r[t]});s.length&&i.push({key:t,valuename:e.samples.valuename,annotation:s.sort(((t,e)=>e.v-t.v))})}e.send({lst:i})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/mdssurvivalplot",lt(yt)),Nt.post(St+"/fimo",rt.handle_closure(yt)),Nt.all(St+"/termdb",P.handle_request_closure(yt)),Nt.all(St+"/termdb-barsql",D.handle_request_closure(yt)),Nt.post(St+"/singlecell",nt.handle_singlecell_closure(yt)),Nt.post(St+"/massSession",et.save),Nt.get(St+"/massSession",et.get),Nt.get(St+"/isoformbycoord",(async function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!t.query.chr)throw"chr missing";const r=Number(t.query.pos);if(!Number.isInteger(r))throw"pos must be positive integer";const i=n.tracks.find((t=>t.__isgene));i||reject("no gene track");const s=[];await x.get_lines_bigfile({args:[u.join(o.tpmasterdir,i.file),t.query.chr+":"+r+"-"+r],callback:t=>{const e=t.split("\t")[3];if(!e)return;const r=JSON.parse(e);if(!r.isoform)return;const o={isoform:r.isoform},i=n.genedb.getjsonbyisoform.get(r.isoform);i&&(o.name=JSON.parse(i.genemodel).name,o.isdefault=i.isdefault),s.push(o)}}),e.send({lst:s})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/ase",(async function(t,e){const n=t.query,r=3e6,i=5e5;try{const t=yt[n.genome];if(!t)throw"invalid genome";if(!n.samplename)throw"samplename missing";if(!n.chr)throw"no chr";if(!n.start||!n.stop)throw"no start/stop";if(!n.rnabarheight)throw"no rnabarheight";if(!n.dnabarheight)throw"no dnabarheight";if(!Number.isInteger(n.barypad))throw"invalid barypad";if(n.rnamax&&!Number.isFinite(n.rnamax))throw"invalid value for rnamax";if(!n.checkrnabam)throw".checkrnabam{} missing";const s=$t(n.checkrnabam);if(s)throw s;if(n.refcolor||(n.refcolor="blue"),n.altcolor||(n.altcolor="red"),!t.tracks)throw"genome.tracks[] missing";const a=t.tracks.find((t=>t.__isgene));if(!a)throw"no gene track from this genome";await async function(t,e){if(t.rnabamfile)t.rnabamfile=u.join(o.tpmasterdir,t.rnabamfile);else{if(!t.rnabamurl)throw"no file or url for rna bam";t.rnabamurl_dir=await x.cache_index(t.rnabamurl,t.rnabamindexURL||t.rnabamurl+".bai")}if(t.rnabam_nochr=await x.bam_ifnochr(t.rnabamfile||t.rnabamurl,e,t.rnabamurl_dir),t.vcffile)t.vcffile=u.join(o.tpmasterdir,t.vcffile);else{if(!t.vcfurl)throw"no file or url for vcf";t.vcfurl_dir=await x.cache_index(t.vcfurl,t.vcfindexURL)}t.vcf_nochr=await x.tabix_is_nochr(t.vcffile||t.vcfurl,t.vcfurl_dir,e)}(n,t);const l=await Wt(t,a,n.chr,n.start,n.stop),f={};if(n.stop-n.start<r)for(const[t,e]of l){const t={file:n.rnabamfile,url:n.rnabamurl,dir:n.rnabamurl_dir,nochr:n.rnabam_nochr};let r;r=n.rnabamispairedend?await Lt(t,n.chr,e):await Ft(t,n.chr,e),e.fpkm=1e9*r/(n.rnabamtotalreads*e.exonlength)}else f.fpkmrangelimit=r;const[d,h,p,y]=function(t,e){let n=t.start,r=t.stop;for(const[t,o]of e)n=Math.min(n,o.start),r=Math.max(r,o.stop);const o=t.start,i=t.stop;return[n,r,o,i]}(n,l),v=await async function(t,e,n,r,o){const i=await Vt(t.vcffile||t.vcfurl,t.vcfurl_dir),[s,a,l,c]=q.vcfparsemeta(i);if(c)throw c;const u={info:s,format:a,samples:l},f=await Jt(t.vcffile||t.vcfurl,(t.vcf_nochr?t.chr.replace("chr",""):t.chr)+":"+r+"-"+o,t.vcfurl_dir),d=[];for(const e of f||[]){const[n,r,o]=q.vcfparseline(e,u);for(const e of r){if(!k.basecolor[e.ref]||!k.basecolor[e.alt])continue;if(!e.sampledata)continue;const n=Ht(e,t.samplename,t.checkrnabam);n&&d.push(n)}}const h=[];for(const t of d)for(const[e,r]of n)if(t.pos>=r.start&&t.pos<=r.stop){h.push(t);break}return h}(n,0,l,d,h);for(const t of v)t.rnacount={nocoverage:1};let b,w;y-p>=i?f.covplotrangelimit=i:(n.rnamax?b=n.rnamax:(b=await async function(t,e,n){let r=0;return await x.get_lines_bigfile({isbam:!0,args:["depth","-r",(t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(e+1)+"-"+(n+1),"-g","DUP",t.rnabamurl||t.rnabamfile],dir:t.rnabamurl_dir,callback:t=>{const e=t.split("\t");if(3!=e.length)return;const n=Number.parseInt(e[2]);Number.isInteger(n)&&(r=Math.max(r,n))}}),r}(n,p,y),f.rnamax=b),w=await async function(t,e,n,r,o){const i=new Map;for(const t of r)t.dnacount.ishet&&t.pos>=e&&t.pos<=n&&i.set(t.pos,t);const s=g(t.width*t.devicePixelRatio,(t.rnabarheight+t.barypad+t.dnabarheight)*t.devicePixelRatio),a=s.getContext("2d");t.devicePixelRatio>1&&a.scale(t.devicePixelRatio,t.devicePixelRatio);let l,c,u=!1;n-e<=t.width?(u=!0,l=1,c=t.width/(n-e),a.lineWidth=c):(c=1,l=(n-e)/t.width);return await x.get_lines_bigfile({isbam:!0,args:["depth","-r",(t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(e+1)+"-"+(n+1),"-g","DUP",t.rnabamurl||t.rnabamfile],dir:t.rnabamurl_dir,callback:n=>{const r=n.split("\t");if(3!=r.length)return;const s=Number.parseInt(r[1])-1;if(!Number.isInteger(s))return;const f=Number.parseInt(r[2]);if(!Number.isInteger(f))return;const d=t.rnabarheight*Math.min(f,o)/o,h=u?(s-e)*c:(s-e)/l;a.strokeStyle="#ccc",a.beginPath(),a.moveTo(h+c/2,t.rnabarheight),a.lineTo(h+c/2,t.rnabarheight-d),a.stroke(),a.closePath(),f>o&&(a.strokeStyle="blue",a.beginPath(),a.moveTo(h+c/2,0),a.lineTo(h+c/2,2),a.stroke(),a.closePath());const p=i.get(s);p&&(p.rnacount.h=d)}}),{canvas:s,ctx:a,isbp:u,binpxw:c,binbpsize:l}}(n,p,y,v,b)),f.coveragesrc=await function(t,e,n,r,o,i,s,a){const l=[];for(const n of e)n.dnacount.ishet&&l.push((t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(n.pos+1)+"-"+(n.pos+1));return new Promise(((n,r)=>{const c=m(_t,["mpileup","-q",t.checkrnabam.rnapileup_q,"-Q",t.checkrnabam.rnapileup_Q,"--no-reference","-a","INFO/AD","-d",999999,"-r",l.join(","),t.rnabamurl||t.rnabamfile],{cwd:t.rnabamurl_dir});_.createInterface({input:c.stdout}).on("line",(t=>{if("#"==t[0])return;const n=Ut(t);if(!n)return;let r;n.pos>=o&&n.pos<=i&&n.DP;const s=e.find((t=>t.pos==n.pos));if(s){s.__x=r;const t=n.allele2count[s.ref]||0,e=n.allele2count[s.alt]||0;t+e>0&&(delete s.rnacount.nocoverage,s.rnacount.ref=t,s.rnacount.alt=e,s.rnacount.f=e/(t+e))}})),c.on("close",(()=>{if(!s)return void n();const{canvas:r,ctx:l,binpxw:c}=s;l.lineWidth=Math.max(3,c);let u=0;for(const n of e)n.dnacount&&(n.pos<o||n.pos>i||(n.__x=t.width*(n.pos-o)/(i-o),u=Math.max(u,n.dnacount.ref+n.dnacount.alt)));for(const n of e){if(null==n.__x)continue;n.rnacount.nocoverage||(null==n.rnacount.h&&(n.rnacount.h=t.rnabarheight*(n.rnacount.ref+n.rnacount.alt)/a),l.strokeStyle=t.refcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight),l.lineTo(n.__x+c/2,t.rnabarheight-(1-n.rnacount.f)*n.rnacount.h),l.stroke(),l.closePath(),l.strokeStyle=t.altcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight-(1-n.rnacount.f)*n.rnacount.h),l.lineTo(n.__x+c/2,t.rnabarheight-n.rnacount.h),l.stroke(),l.closePath());const e=t.dnabarheight*(n.dnacount.ref+n.dnacount.alt)/u;n.dnacount.ishet&&(l.strokeStyle=t.refcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight+t.barypad),l.lineTo(n.__x+c/2,t.rnabarheight+t.barypad+(1-n.dnacount.f)*e),l.stroke(),l.closePath(),l.strokeStyle=t.altcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight+t.barypad+(1-n.dnacount.f)*e),l.lineTo(n.__x+c/2,t.rnabarheight+t.barypad+e),l.stroke(),l.closePath()),delete n.__x}n(r.toDataURL())}))}))}(n,v,0,0,p,y,w,b),await async function(t,e){if(0==t.length)return;const n=[];for(const r of t)r.rnacount.nocoverage||r.rnacount.ref+r.rnacount.alt<e.checkrnabam.rna_mintotalreads||n.push(r);if(0==n.length)return;const r=await function(t){const e=u.join(o.cachedir,Math.random().toString())+".snp",n=[];for(const e of t)e.rnacount.nocoverage||null!=e.rnacount.ref&&null!=e.rnacount.alt&&n.push(e.pos+"."+e.ref+"."+e.alt+"\t\t\t\t\t\t\t\t"+e.rnacount.ref+"\t"+e.rnacount.alt);return new Promise(((t,r)=>{c.writeFile(e,n.join("\n")+"\n",(n=>{n&&r("cannot write"),t(e)}))}))}(n),i=await Gt(r);await function(t,e){return new Promise(((n,r)=>{c.readFile(e,"utf8",((e,o)=>{e&&r("cannot read binom pvalue"),o||n();for(const e of o.trim().split("\n")){const n=e.split("\t"),r=t.find((t=>n[0]==t.pos+"."+t.ref+"."+t.alt));r&&(r.rnacount.pvalue=Number.parseFloat(n[10]))}n()}))}))}(t,i),c.unlink(r,(()=>{})),c.unlink(i,(()=>{}))}(v,n),f.genes=function(t,e,n){const r=[];for(const[o,i]of e){r.push(i);const e=t.filter((t=>t.pos>=i.start&&t.pos<=i.stop));if(0==e.length){i.nosnp=1;continue}i.snps=e;const o=e.filter((t=>null!=t.rnacount.pvalue));if(0==o.length){i.nornasnp=1;continue}const s=o.reduce(((t,e)=>t+Math.abs(e.rnacount.f-.5)),0);let a=null,l=0;for(const t of o)null==a?a=t.rnacount.pvalue:a*=t.rnacount.pvalue,t.rnacount.pvalue<=n.checkrnabam.binompvaluecutoff&&l++;i.ase={markers:e.filter((t=>t.dnacount.ishet)).length,ase_markers:l,mean_delta:s/o.length,geometricmean:Math.pow(a,1/o.length)}}return r}(v,l,n);let N=0;for(const t of v)t.dnacount&&t.pos>=p&&t.pos<=y&&(N=Math.max(N,t.dnacount.ref+t.dnacount.alt));f.dnamax=N,e.send(f)}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/bamnochr",(async function(t,e){const n=t.query;try{const t=yt[n.genome];if(!t)throw"invalid genome";if(n.file)n.file=u.join(o.tpmasterdir,n.file);else{if(!n.url)throw"no bam file or url";n.url_dir=await x.cache_index(n.url,n.indexURL||n.url+".bai")}const r=await x.bam_ifnochr(n.file||n.url,t,n.url_dir);e.send({nochr:r})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/gene2canonicalisoform",(function(t,e){Mt(t);try{if(!t.query.gene)throw".gene missing";const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.genedb.get_gene2canonicalisoform)throw"gene2canonicalisoform not supported on this genome";const r=n.genedb.get_gene2canonicalisoform.get(t.query.gene);e.send(r)}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.get(St+"/ideogram",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.genedb.hasIdeogram)throw"ideogram not supported on this genome";if(!t.query.chr)throw".chr missing";const r=n.genedb.getIdeogramByChr.all(t.query.chr);if(!r.length)throw"no ideogram data for this chr";e.send(r)}catch(t){e.send({error:t.message||t})}})),async function(){try{await c.promises.stat(o.tpmasterdir)}catch(t){const e="Error with "+o.tpmasterdir+": "+t.code;if("validate"==process.argv[2])throw e;return void console.log("\n!!! "+e+"\n")}if(function(){if(o.features.skip_checkDependenciesAndVersions)return void console.log("SKIPPED checkDependenciesAndVersions()");const t=["jsonlite","cmprsk","hwde","lmtest"];for(const e of t){const t=p.spawnSync(o.Rscript,["-e",`suppressPackageStartupMessages(library("${e}"))`],{encoding:"utf8"});if(t.stderr.trim())throw t.stderr}{const t=p.execSync(o.samtools+" --version",{encoding:"utf8"}).trim().split("\n"),[e,n]=t[0].split(" ");if("samtools"!=e||!n)throw'cannot run "samtools version"';const[r,i]=n.split(".");if("1"!=r)throw"samtools not 1.*";if(Number(i)<10)throw"samtools not >= 1.10"}{const t=p.execSync(o.bcftools+" -v",{encoding:"utf8"}).trim().split("\n"),[e,n]=t[0].split(" ");if("bcftools"!=e||!n)throw'cannot run "bcftools version"';const[r,i]=n.split(".");if("1"!=r)throw"bcftools not 1.*";if(Number(i)<10)throw"bcftools not >= 1.10"}}(),xt=function(){const t=c.statSync(o.binpath+"/server.js").mtime,e=c.existsSync("public/bin/proteinpaint.js")&&c.statSync("public/bin/proteinpaint.js").mtime||0;return t>e?t:e}(),kt=Date(Date.now()).toString().split(" ").slice(0,5).join(" "),null!=o.base_zindex){const t=Number.parseInt(o.base_zindex);if(Number.isNaN(t)||t<=0)throw"base_zindex must be positive integer";o.base_zindex=t}if(o.jwt){if(!o.jwt.secret)throw"jwt.secret missing";if(!o.jwt.permissioncheck)throw"jwt.permissioncheck missing"}if(!o.tpmasterdir)throw".tpmasterdir missing";if(!o.cachedir)throw".cachedir missing";o.cachedir_massSession=await pe("massSession"),o.cachedir_massSessionTrash=await pe("massSessionTrash"),o.cache_snpgt={dir:await pe("snpgt"),fileNameRegexp:/[^\w]/,sampleColumn:6},o.cachedir_bam=await pe("bam"),o.cachedir_genome=await pe("genome"),o.cachedir_ssid=await pe("ssid"),o.commonOverrides&&k.applyOverrides(o.commonOverrides);if(!o.genomes)throw".genomes[] missing";if(!Array.isArray(o.genomes))throw".genomes[] not array";for(const t of o.genomes){if(!t.name)throw".name missing from a genome: "+JSON.stringify(t);if(!t.file)throw".file missing from genome "+t.name;const e=u.join(process.cwd(),t.file),n=require(c.existsSync(e)?e:t.file),r=n.default||n;if(yt[t.name]=r,!r.genomefile)throw".genomefile missing from .js file of genome "+t.name;if("NA"==r.genomefile||(r.genomefile=u.join(o.tpmasterdir,r.genomefile)),r.genomicNameRegexp||(r.genomicNameRegexp=/[^a-zA-Z0-9.:_-]/),r.tracks||(r.tracks=[]),t.tracks)for(const e of t.tracks)r.tracks.push(e);if(t.datasets&&(r.rawdslst=t.datasets),t.snp&&(r.snp=t.snp),t.blat){if(!t.blat.host)throw".blat.host missing for "+t.name;if(!t.blat.port)throw".blat.port missing for "+t.name;r.blat=t.blat}if(t.nosnp&&delete r.snp,t.nohicenzyme&&delete r.hicenzymefragment,t.nohicdomain&&delete r.hicdomain,r.genedb&&t.no_gene2canonicalisoform&&delete r.genedb.gene2canonicalisoform,t.updateAttr)for(const e of t.updateAttr){let t=r;for(const[n,r]of e.entries())if(t)if("object"==typeof r)for(const e in r)t[e]=r[e];else{if("string"==typeof t[r]){e[n+1]&&(t[r]=e[n+1]);break}t=t[r]}}}o.defaultgenome&&yt[o.defaultgenome]&&(yt[o.defaultgenome].isdefault=!0);for(const t in yt){const n=yt[t];if(!n.majorchr)throw t+": majorchr missing";if(!n.defaultcoord)throw t+": defaultcoord missing";if(await x.get_fasta(n,n.defaultcoord.chr+":"+n.defaultcoord.start+"-"+(n.defaultcoord.start+1)),n.tracks||(n.tracks=[]),"string"==typeof n.majorchr){const e=n.majorchr.trim().split(/[\s\t\n]+/),r={},o=[];for(let n=0;n<e.length;n+=2){const i=e[n],s=Number.parseInt(e[n+1]);if(Number.isNaN(s))throw t+" majorchr invalid chr size for "+i+" ("+e[n+1]+")";r[i]=s,o.push(i)}n.majorchr=r,n.majorchrorder=o}n.chrlookup={};for(const t in n.majorchr)n.chrlookup[t.toUpperCase()]={name:t,len:n.majorchr[t],major:!0};if(n.minorchr){if("string"==typeof n.minorchr){const e=n.minorchr.trim().split(/[\s\t\n]+/),r={};for(let n=0;n<e.length;n+=2){const o=Number.parseInt(e[n+1]);if(Number.isNaN(o))throw t+" minorchr invalid chr size for "+e[n]+" ("+e[n+1]+")";r[e[n]]=o}n.minorchr=r}for(const t in n.minorchr)n.chrlookup[t.toUpperCase()]={name:t,len:n.minorchr[t]}}if(n.genedb){if(!n.genedb.dbfile)throw t+": .genedb.dbfile missing";try{console.log("Connecting",n.genedb.dbfile),n.genedb.db=x.connect_db(n.genedb.dbfile)}catch(t){throw`Cannot connect genedb: ${n.genedb.dbfile}: ${t}`}n.genedb.getnamebynameorisoform=n.genedb.db.prepare("select name from genes where name=? or isoform=?"),n.genedb.getnamebyisoform=n.genedb.db.prepare("select distinct name from genes where isoform=?"),n.genedb.getjsonbyname=n.genedb.db.prepare("select isdefault,genemodel from genes where name=?"),n.genedb.getjsonbyisoform=n.genedb.db.prepare("select isdefault,genemodel from genes where isoform=?"),n.genedb.getnameslike=n.genedb.db.prepare("select distinct name from genes where name like ? limit 20");const e=ht(n.genedb.db);e.has("genealias")&&(n.genedb.getNameByAlias=n.genedb.db.prepare("select name from genealias where alias=?"),n.genedb.tableSize=n.genedb.db.prepare("select count(*) from genealias where alias=?")),e.has("gene2coord")&&(n.genedb.getCoordByGene=n.genedb.db.prepare("select * from gene2coord where name=?")),e.has("ideogram")?(n.genedb.hasIdeogram=!0,n.genedb.getIdeogramByChr=n.genedb.db.prepare("select * from ideogram where chromosome=?")):n.genedb.hasIdeogram=!1,e.has("gene2canonicalisoform")&&(n.genedb.get_gene2canonicalisoform=n.genedb.db.prepare("select isoform from gene2canonicalisoform where gene=?")),e.has("buildDate")&&(n.genedb.get_buildDate=n.genedb.db.prepare("select date from buildDate")),n.genedb.hasTable_refseq2ensembl=e.has("refseq2ensembl"),n.genedb.sqlTables=[...e],n.genedb.tableSize={};for(const t of e)"buildDate"!=t&&(n.genedb.tableSize[t]=n.genedb.db.prepare(`select count(*) as size from ${t}`).get().size)}if(n.termdbs)for(const r in n.termdbs)dt(n.termdbs[r],e.features),console.log(`${r} initiated as ${t}-level termdb`);for(const t of n.tracks)if(t.__isgene){if(!t.file)throw"Tabix file missing for gene track: "+JSON.stringify(t);try{await x.validate_tabixfile(u.join(o.tpmasterdir,t.file))}catch(e){throw"Error with "+t.file+": "+e}}if(n.proteindomain){if(!n.proteindomain.dbfile)throw t+".proteindomain: missing dbfile for sqlite db";if(!n.proteindomain.statement)throw t+".proteindomain: missing statement for sqlite db";let e;try{console.log("Connecting",n.proteindomain.dbfile),e=x.connect_db(n.proteindomain.dbfile)}catch(t){throw"Error with "+n.proteindomain.dbfile+": "+t}n.proteindomain.getbyisoform=e.prepare(n.proteindomain.statement)}if(n.snp){if(!n.snp.bigbedfile)throw t+".snp: missing bigBed file";n.snp.bigbedfile=u.join(o.tpmasterdir,n.snp.bigbedfile),await x.file_is_readable(n.snp.bigbedfile)}if(n.clinvarVCF){if(!n.clinvarVCF.file)throw t+".clinvarVCF: VCF file missing";n.clinvarVCF.file=u.join(o.tpmasterdir,n.clinvarVCF.file);try{await x.validate_tabixfile(n.clinvarVCF.file)}catch(t){throw"Error with "+n.clinvarVCF.file+": "+t}if(!n.clinvarVCF.infokey)throw t+".clinvarVCF.infokey missing";if(!n.clinvarVCF.categories)throw t+".clinvarVCF.categories{} missing";{const e=p.execSync(vt+" -H "+n.clinvarVCF.file,{encoding:"utf8"}).trim();if(!e)throw t+".clinvarVCF: no meta/header lines";const[r,o,i,s]=q.vcfparsemeta(e.split("\n"));if(s)throw t+".clinvarVCF: error parsing vcf meta: "+s.join("\n");if(!r[n.clinvarVCF.infokey])throw t+".clinvarVCF: unknown INFO key for "+n.clinvarVCF.infokey;n.clinvarVCF.info=r,n.clinvarVCF.format=o}{const e=p.execSync(vt+" -l "+n.clinvarVCF.file,{encoding:"utf8"}).trim();if(""==e)throw t+".clinvarVCF: no chr listing";n.clinvarVCF.nochr=k.contigNameNoChr(n,e.split("\n"))}}if(n.fimo_motif){if(!n.fimo_motif.db)throw t+".fimo_motif: db file missing";if(n.fimo_motif.db=u.join(o.tpmasterdir,n.fimo_motif.db),n.fimo_motif.annotationfile){const[t,e]=fe(c.readFileSync(u.join(o.tpmasterdir,n.fimo_motif.annotationfile),{encoding:"utf8"}).trim());n.fimo_motif.tf2attr={};for(const t of e)n.fimo_motif.tf2attr[t.Model.split("_")[0]]=t}}if(n.hicenzymefragment){if(!Array.isArray(n.hicenzymefragment))throw"hicenzymefragment should be an array";for(const t of n.hicenzymefragment){if(!t.enzyme)throw".enzyme missing for one element of hicenzymefragment[]";if(!t.file)throw".file missing for one element of hicenzymefragment[]";try{await x.validate_tabixfile(u.join(o.tpmasterdir,t.file))}catch(e){throw"Error with "+t.file+": "+e}}}if(n.hicdomain){if(!n.hicdomain.groups)throw".groups{} missing from hicdomain";for(const t in n.hicdomain.groups){const e=n.hicdomain.groups[t];if(!e.name)throw".name missing from hicdomain "+t;if(!e.sets)throw".set{} missing from hicdomain "+t;for(const n in e.sets){const r=e.sets[n];if(!r.name)throw".name missing from hicdomain "+t+" > "+n;if(!r.file)throw".file missing from hicdomain "+t+" > "+n;r.file=u.join(o.tpmasterdir,r.file);try{await x.validate_tabixfile(r.file)}catch(t){throw"Error with "+r.file+": "+t}}}}if(n.rawdslst){n.datasets={};for(const e of n.rawdslst){if(!e.name)throw"a nameless dataset from "+t;if(n.datasets[e.name])throw t+" has duplicating dataset name: "+e.name;if(!e.jsfile)throw"jsfile not available for dataset "+e.name+" of "+t;const r=u.join(process.cwd(),e.jsfile),o=require(c.existsSync(r)?r:e.jsfile),i="function"==typeof o?o(k):"function"==typeof(null==o?void 0:o.default)?o.default(k):o.default||o;if(Q(i,e),i.noHandleOnClient=e.noHandleOnClient,i.label=e.name,i.genomename=t,n.datasets[i.label]=i,i.isMds3)try{await X.init(i,n,e,Nt,St)}catch(t){throw t.stack&&console.log(t.stack),"Error with mds3 dataset "+i.label+": "+t}else if(i.isMds)try{await ge(i,n,e)}catch(t){throw"Error with mds dataset "+i.label+": "+t}else he(i,n)}de(),delete n.rawdslst}}}().then((async()=>{if(console.log(`\n${new Date} ${o.commitHash||""}`),console.log("\nValidation succeeded.\n"),"validate"!=process.argv[2])if("phewas-precompute"!=process.argv[2])await async function(){try{if(o.preListenScript){const{cmd:t,args:e}=o.preListenScript,n=p.spawnSync(t,e,{encoding:"utf-8"});if(n.stderr.trim())throw n.stderr.trim();console.log(n.stdout)}o.appEnable&&o.appEnable.forEach((t=>Nt.enable(t)));const t=o.port,e=`STANDBY AT PORT ${t}`;if(o.ssl){const n={key:c.readFileSync(o.ssl.key),cert:c.readFileSync(o.ssl.cert)},r=await l.createServer(n,Nt);return r.listen(t,"0.0.0.0",(()=>{console.log(`HTTPS ${e}`)})),r}{const n=await a.createServer(Nt);return n.listen(t,"0.0.0.0",(()=>{process.send&&process.send("ready"),console.log(e)})),n}}catch(t){throw t}}();else{const t=process.argv[3],e=process.argv[4],n=yt[t];if(!n)throw"invalid genome name: "+t;const r=n.datasets[e];if(!r)throw"invalid dataset: "+e;at.do_precompute(r)}else console.log("You may now run the server.")})).catch((t=>{let e=1;if(!c.existsSync(o.tpmasterdir)){const t=o.maintenance||{};if("start"in t&&"stop"in t&&"tpErrorCode"in t){const n=+new Date(t.start),r=+new Date(t.stop),o=+new Date;n<=o&&o<=r&&(e=t.tpErrorCode)}}t.stack&&console.log(t.stack),e?console.error("\n!!!\n"+t+"\n\n"):console.log("\n!!!\n"+t+"\n\n"),process.exit(e)})),e.log=Mt,e.boxplot_getvalue=function(t){const e=t.length;if(e<5)return{out:t};const n=t[Math.floor(e/2)].value,r=t[Math.floor(e/4)].value,o=t[Math.floor(3*e/4)].value,i=t[Math.floor(.05*e)].value,s=t[Math.floor(.95*e)].value,a=(t[Math.floor(.01*e)].value,o-r);let l,c;if(0==a)l=0,c=0;else{const n=t.findIndex((t=>t.value>r-1.5*a));l=t[-1==n?0:n].value;const i=t.findIndex((t=>t.value>o+1.5*a));c=t[-1==i?e-1:i-1].value}const u=t.filter((t=>t.value<r-1.5*a||t.value>o+1.5*a));return{w1:l,w2:c,p05:i,p25:r,p50:n,p75:o,p95:s,iqr:a,out:u}};function ae(t){delete t.mclasslabel2key,delete t.sample2disease,delete t.patient2ori2sample}const le=Object.freeze([".bam",".bai",".gz",".tbi",".csi",".bw",".bb"]);function ce(t,e=!1,n=!0){if("/"==t[0])return!0;if(t.includes('"')||t.includes("'"))return!0;if(t.includes("|")||t.includes("&"))return!0;if(t.includes(" "))return!0;if(-1!=t.indexOf(".."))return!0;if(t.match(/(\<script|script\>)/i))return!0;if(e&&o.whiteListPaths){let e=!0;for(const n of o.whiteListPaths){if(t.startsWith(n)||"!"!=n[0]&>(t,n)){e=!1;break}if("!"==n[0]&&!gt(t,n)){e=!0;break}}if(e)return!0}if(n)for(const e of le)if(e===u.extname(t).toLowerCase())return!0;return!1}function ue(t,e=!0){let n=null,r=!1;if(t.query.file){if(n=t.query.file,ce(n,e,!1))return["illegal file path"];n=u.join(o.tpmasterdir,n)}else if(t.query.url){if(n=t.query.url,n.includes(" "))return["url must not contain whitespace"];if(n.includes('"')||n.includes("'"))return["url must not contain single or double quotes"];r=!0}return n?[null,n,r]:["file unspecified"]}function fe(t){const e=t.split(/\r?\n/);if(e.length<=1||!e[0])return[null,[]];const n=e[0].split("\t"),r=[];for(let t=1;t<e.length;t++){if("#"==e[t][0])continue;const o=e[t].split("\t"),i={};for(let t=0;t<n.length;t++){const e=o[t];e&&(i[n[t]]=e)}r.push(i)}return[null,r]}async function de(){const t=await c.promises.readdir(o.cachedir_massSession);try{t.forEach((async t=>{const e=(await c.promises.stat(u.join(o.cachedir_massSession,t))).birthtime,n=new Date,r=new Date(e),i=o.features.massSessionDuration||30;Math.round((n.getTime()-r.getTime())/864e5)>i&&(await c.promises.copyFile(u.join(o.cachedir_massSession,t),u.join(o.cachedir_massSessionTrash,t)),await c.promises.unlink(u.join(o.cachedir_massSession,t)),console.log("File deleted: ",t,e))}))}catch(t){throw`Error: ${t}`}}function he(t,e){if(t.dbfile)try{console.log("Connecting",t.dbfile),t.newconn=x.connect_db(t.dbfile)}catch(e){throw"Error with "+t.dbfile+": "+e}if(t.snvindel_attributes)for(const e of t.snvindel_attributes)if(e.lst)for(const t of e.lst)t.get=t.get.toString();else e.get=e.get.toString();if(t.cohort){if(t.cohort.levels){if(!Array.isArray(t.cohort.levels))throw"cohort.levels must be array for "+t.genomename+"."+t.label;if(0==t.cohort.levels.length)throw"levels is blank array for cohort of "+t.genomename+"."+t.label;for(const e of t.cohort.levels)if(!e.k)throw".k key missing in one of the levels, .cohort, in "+t.genomename+"."+t.label}if(t.cohort.fromdb){if(!t.cohort.fromdb.sql)throw".sql missing from ds.cohort.fromdb in "+t.genomename+"."+t.label;const e=t.newconn.prepare(t.cohort.fromdb.sql).all();delete t.cohort.fromdb,t.cohort.raw=e,console.log(e.length+" rows retrieved for "+t.label+" sample annotation")}if(t.cohort.files){let e=[];for(const n of t.cohort.files){if(!n.file)throw".file missing from one of cohort.files[] for "+t.genomename+"."+t.label;const r=c.readFileSync(u.join(o.tpmasterdir,n.file),"utf8").trim();if(!r)throw n.file+" is empty for "+t.genomename+"."+t.label;e=[...e,...R.tsvParse(r)]}delete t.cohort.files,t.cohort.raw?t.cohort.raw=[...t.cohort.raw,...e]:t.cohort.raw=e,console.log(e.length+" rows retrieved for "+t.label+" sample annotation")}if(t.cohort.tosampleannotation){if(!t.cohort.tosampleannotation.samplekey)throw".samplekey missing from .cohort.tosampleannotation for "+t.genomename+"."+t.label;if(!t.cohort.key4annotation)throw".cohort.key4annotation missing when .cohort.tosampleannotation is on for "+t.genomename+"."+t.label}}if(!t.queries)throw".queries missing from dataset "+t.label+", "+t.genomename;if(!Array.isArray(t.queries))throw t.label+".queries is not array";for(const n of t.queries){const r=me(n,t,e);if(r)throw'Error parsing a query in "'+t.label+'": '+r}if(t.vcfinfofilter){const e=k.validate_vcfinfofilter(t.vcfinfofilter);if(e)throw t.label+": vcfinfofilter error: "+e}if(t.url4variant)for(const e of t.url4variant){if(!e.makelabel)throw"makelabel() missing for one item of url4variant from "+t.label;if(!e.makeurl)throw"makeurl() missing for one item of url4variant from "+t.label;e.makelabel=e.makelabel.toString(),e.makeurl=e.makeurl.toString()}}async function pe(t){const e=u.join(o.cachedir,t);try{await c.promises.stat(e)}catch(t){if("ENOENT"!=t.code)throw"error stating dir";try{await c.promises.mkdir(e)}catch(t){throw"cannot make dir"}}return e}function me(t,e,n){if(!t.name)return".name missing";if(t.dsblocktracklst){if(!Array.isArray(t.dsblocktracklst))return"dsblocktracklst not an array in "+e.label;for(const n of t.dsblocktracklst){if(!n.type)return"missing type for a blocktrack of "+e.label;if(!n.file&&!n.url)return"neither file or url given for a blocktrack of "+e.label}}else if(t.vcffile){const e=p.execSync(vt+" -H "+u.join(o.tpmasterdir,t.vcffile),{encoding:"utf8"}).trim();if(""==e)return"no meta lines in VCF file "+t.vcffile+" of query "+t.name;const[r,i,s,a]=q.vcfparsemeta(e.split("\n"));if(a)return"error parsing VCF meta lines of "+t.vcffile+": "+a.join("; ");t.vcf={vcfid:Math.random().toString(),info:r,format:i,samples:s},t.hlinfo&&(t.vcf.hlinfo=t.hlinfo,delete t.hlinfo),t.infopipejoin&&(t.vcf.infopipejoin=t.infopipejoin,delete t.infopipejoin);const l=p.execSync(vt+" -l "+u.join(o.tpmasterdir,t.vcffile),{encoding:"utf8"}).trim();if(""==l)return"tabix -l found no chromosomes/contigs in "+t.vcffile+" of query "+t.name;t.vcf.nochr=k.contigNameNoChr(n,l.split("\n"));let c=0;if(r)for(const t in r)c++;console.log("Parsed vcf meta from "+t.vcffile+": "+c+" INFO, "+s.length+" sample, "+(t.vcf.nochr?'no "chr"':'has "chr"'))}else{if(!t.makequery)return"do not know how to parse query: "+t.name;if(t.isgeneexpression){if(!t.config)return"config object missing for gene expression query of "+t.name;t.config.maf&&(t.config.maf.get=t.config.maf.get.toString())}}}async function ge(t,e,n){if((t.isMds2||t.isMds3||t.isMds)&&Q(t,n),t.assayAvailability){if(!t.assayAvailability.file)throw".assayAvailability.file missing";if(!t.assayAvailability.assays)throw".assayAvailability.assays[] missing";Object.freeze(t.assayAvailability.assays),t.assayAvailability.samples=new Map;for(const e of c.readFileSync(u.join(o.tpmasterdir,t.assayAvailability.file),{encoding:"utf8"}).trim().split("\n")){const[n,r]=e.split("\t");t.assayAvailability.samples.set(n,JSON.parse(r))}console.log(t.assayAvailability.samples.size+" samples with assay availability ("+t.label+")")}if(t.gene2mutcount){if(!t.gene2mutcount.dbfile)throw".gene2mutcount.dbfile missing";try{console.log("Connecting",t.gene2mutcount.dbfile),t.gene2mutcount.db=x.connect_db(t.gene2mutcount.dbfile),console.log("DB connected for "+t.label+": "+t.gene2mutcount.dbfile)}catch(t){throw"Error connecting db at ds.gene2mutcount.dbfile"}}if(t.sampleAssayTrack){if(!t.sampleAssayTrack.file)throw".file missing from sampleAssayTrack";t.sampleAssayTrack.samples=new Map;let e=0,n=new Set;for(const r of c.readFileSync(u.join(o.tpmasterdir,t.sampleAssayTrack.file),{encoding:"utf8"}).trim().split("\n")){if(!r)continue;if("#"==r[0])continue;const[o,i,s]=r.split("\t");if(!i||!s)continue;if(!t.sampleAssayTrack.samples.has(o)){if(t.cohort&&t.cohort.annotation&&!t.cohort.annotation[o]){n.add(o);continue}t.sampleAssayTrack.samples.set(o,[])}const a=JSON.parse(s);if(!k.tkt[a.type])throw"invalid type from a sample track: "+s;a.name||(a.name=o+" "+i),a.assayName=i,t.sampleAssayTrack.samples.get(o).push(a),e++}console.log(e+" assay-tracks from "+t.sampleAssayTrack.samples.size+" samples ("+t.label+")"),n.size&&console.log("Error: "+n.size+" samples with assay tracks are unannotated: "+[...n].join(" "))}if(t.singlesamplemutationjson){const e=t.singlesamplemutationjson;if(!e.file)throw".file missing from singlesamplemutationjson";e.samples={};let n=0;for(const t of c.readFileSync(u.join(o.tpmasterdir,e.file),{encoding:"utf8"}).trim().split("\n")){if(!t)continue;if("#"==t[0])continue;const[r,o]=t.split("\t");r&&o&&(n++,e.samples[r]=o)}console.log(n+" samples for disco plot")}if(t.cohort&&t.cohort.db&&t.cohort.termdb&&await K.init_db(t,Nt,St),t.cohort&&t.cohort.files){if(!Array.isArray(t.cohort.files))throw".cohort.files is not array";if(!t.cohort.tohash)throw".tohash() missing from cohort";if("function"!=typeof t.cohort.tohash)throw".cohort.tohash is not function";if(!t.cohort.samplenamekey)throw".samplenamekey missing";if(t.cohort.annotation={},t.cohort.mutation_signature){const e=t.cohort.mutation_signature;if(!e.sets)throw".mutation_signature.sets missing";for(const n in e.sets){const r=e.sets[n];if(r.name||(r.name=n),!r.signatures)throw".signatures{} missing from a signature set";if(r.samples){if(!r.samples.file)throw".samples.file missing from a signature set";const[e,n]=fe(c.readFileSync(u.join(o.tpmasterdir,r.samples.file),{encoding:"utf8"}).trim());r.samples.map=new Map;for(const e of n){const n=e[t.cohort.samplenamekey];if(!n)throw t.cohort.samplenamekey+" missing in file "+r.samples.file;r.samples.map.set(n,e);for(const t in r.signatures)if(e[t]){const o=Number.parseFloat(e[t]);if(Number.isNaN(o))throw"mutation signature value is not float: "+e[t]+" from sample "+n;r.samples.skipzero&&0==o?delete e[t]:e[t]=o}}}}}if(t.cohort.attributes){if(!t.cohort.attributes.lst)throw".lst[] missing for cohort.attributes";if(!Array.isArray(t.cohort.attributes.lst))return".cohort.attributes.lst is not array";for(const e of t.cohort.attributes.lst){if(!e.key)throw".key missing from one of the .cohort.attributes.lst[]";if(!e.label)throw".label missing from one of the .cohort.attributes.lst[]";if(!e.values)throw".values{} missing from "+e.label+" of .cohort.attributes.lst";for(const t in e.values)if(!e.values[t].label)throw".label missing from one value of "+e.label+" in .cohort.attributes.lst"}if(t.cohort.attributes.defaulthidden)for(const e in t.cohort.attributes.defaulthidden){const n=t.cohort.attributes.lst.find((t=>t.key==e));if(!n)throw"invalid defaulthidden key: "+e;for(const r in t.cohort.attributes.defaulthidden[e])if(!n.values[r])throw"invalid defaulthidden value "+r+" for "+e}}if(t.cohort.hierarchies){if(!t.cohort.hierarchies.lst)throw".lst[] missing from .cohort.hierarchies";if(!Array.isArray(t.cohort.hierarchies.lst))throw".cohort.hierarchies.lst is not array";for(const e of t.cohort.hierarchies.lst){if(!e.name)throw".name missing from one hierarchy";if(!e.levels)throw".levels[] missing from one hierarchy";if(!Array.isArray(e.levels))throw".levels is not array from one hierarchy";for(const t of e.levels)if(!t.k)throw".k missing from one level in hierarchy "+e.name}}if(t.cohort.sampleAttribute){if(!t.cohort.sampleAttribute.attributes)throw"attributes{} missing from cohort.sampleAttribute";for(const e in t.cohort.sampleAttribute.attributes){const n=t.cohort.sampleAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from cohort.sampleAttribute.attributes";if(n.values)for(const t in n.values){const e=n.values[t];if("object"!=typeof e)throw'value "'+t+'" not pointing to {} from sampleAttribute';e.name||(e.name=t)}if(n.showintrack&&!n.isinteger&&!n.isfloat)throw n.label+": .showintrack requires .isinteger or .isfloat"}}if(t.cohort.scatterplot){if(!t.cohort.sampleAttribute)throw".sampleAttribute missing but required for .cohort.scatterplot";const e=t.cohort.scatterplot;if(!e.querykey)throw".querykey missing from .cohort.scatterplot";{if(!t.queries)throw".cohort.scatterplot.querykey in use but ds.queries{} missing";const n=t.queries[e.querykey];if(!n)throw"unknown query by .cohort.scatterplot.querykey: "+e.querykey;if(n.type!=k.tkt.mdssvcnv)throw"type is not "+k.tkt.mdssvcnv+" of the track pointed to by .cohort.scatterplot.querykey"}if(e.colorbygeneexpression){if(!e.colorbygeneexpression.querykey)throw"querykey missing from .cohort.scatterplot.colorbygeneexpression";if(!t.queries)throw".cohort.scatterplot.colorbygeneexpression in use but ds.queries{} missing";const n=t.queries[e.colorbygeneexpression.querykey];if(!n)throw"unknown query by .cohort.scatterplot.colorbygeneexpression.querykey: "+e.colorbygeneexpression.querykey;if(!n.isgenenumeric)throw"isgenenumeric missing from the track pointed to by .cohort.scatterplot.colorbygeneexpression.querykey"}if(e.tracks,!e.x)throw".x missing from .cohort.scatterplot";if(!e.x.attribute)throw".attribute missing from .cohort.scatterplot.x";const n=t.cohort.sampleAttribute.attributes[e.x.attribute];if(!n)throw"scatterplot.x.attribute is not defined in sampleAttribute";if(!n.isfloat)throw'scatterplot.x is not "isfloat"';if(!e.y)throw".y missing from .cohort.scatterplot";if(!e.y.attribute)throw".attribute missing from .cohort.scatterplot.y";const r=t.cohort.sampleAttribute.attributes[e.y.attribute];if(!r)throw"scatterplot.y.attribute is not defined in sampleAttribute";if(!r.isfloat)throw'scatterplot.y is not "isfloat"';if(e.colorbyattributes)for(const n of e.colorbyattributes){if(!n.key)throw".key missing from one of scatterplot.colorbyattributes";const e=t.cohort.sampleAttribute.attributes[n.key];if(!e)throw"unknown attribute by key "+n.key+" from scatterplot.colorbyattributes";n.label=e.label,n.values=e.values}}for(const e of t.cohort.files){if(!e.file)throw".file missing from one of .cohort.files";const[n,r]=fe(c.readFileSync(u.join(o.tpmasterdir,e.file),{encoding:"utf8"}).trim());if(n)throw'cohort annotation file "'+e.file+'": '+n;console.log(t.label+": "+r.length+" samples loaded from annotation file "+e.file),r.forEach((e=>{for(const n in e){let r;t.cohort.sampleAttribute&&(r=t.cohort.sampleAttribute.attributes[n]),r||t.cohort.termdb&&t.cohort.termdb.termjson&&t.cohort.termdb.termjson.map&&(r=t.cohort.termdb.termjson.map.get(n)),r&&(r.isfloat?e[n]=Number.parseFloat(e[n]):r.isinteger&&(e[n]=Number.parseInt(e[n])))}t.cohort.tohash(e,t)}))}if(t.cohort.annorows=Object.values(t.cohort.annotation),console.log(t.label+": total samples from sample table: "+t.cohort.annorows.length),t.cohort.survivalplot){const e=t.cohort.survivalplot;if(!e.plots)throw".plots{} missing from survivalplot";e.init={plottypes:[]};for(const t in e.plots){const n=e.plots[t];if(!n.name)throw".name missing from survivalplot "+t;if(!n.serialtimekey)throw".serialtimekey missing from survivalplot "+t;if(!n.iscensoredkey)throw".iscensoredkey missing from survivalplot "+t;if(!n.timelabel)throw".timelabel missing from survivalplot "+t;n.key=t,e.init.plottypes.push({key:t,name:n.name,timelabel:n.timelabel})}if(e.samplegroupattrlst){e.init.samplegroupings=[];for(const n of e.samplegroupattrlst){if(!n.key)throw".key missing from an attr of samplegroupattrlst for survival";const r=t.cohort.sampleAttribute.attributes[n.key];if(!r)throw'unknown attribute key "'+n.key+'" from survival samplegroupattrlst';const o=new Map;for(const r in t.cohort.annotation){const i=t.cohort.annotation[r],s=i[n.key];if(null==s)continue;let a=!1;for(const t in e.plots)if(null!=i[e.plots[t].serialtimekey]){a=!0;break}a&&(o.has(s)?o.set(s,o.get(s)+1):o.set(s,1))}if(0==o.size)throw'no value found for "'+n.key+'" from survival samplegroupattrlst';const i=[];for(const[t,e]of o)i.push({value:t,count:e});e.init.samplegroupings.push({key:n.key,label:r.label,values:i})}}}}if(t.mutationAttribute){if(!t.mutationAttribute.attributes)throw"attributes{} missing from mutationAttribute";for(const e in t.mutationAttribute.attributes){const n=t.mutationAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from mutationAttribute.attributes";if(!n.appendto_link&&n.values)for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from mutationAttribute.attributes"}}}if(t.alleleAttribute){if(!t.alleleAttribute.attributes)throw"attributes{} missing from alleleAttribute";for(const e in t.alleleAttribute.attributes){const n=t.alleleAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from alleleAttribute.attributes";if(!n.isnumeric){if(!n.values)throw".values{} missing for non-numeric key "+e+" from alleleAttribute.attributes";for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from alleleAttribute.attributes"}}}}if(t.locusAttribute){if(!t.locusAttribute.attributes)throw"attributes{} missing from locusAttribute";for(const e in t.locusAttribute.attributes){const n=t.locusAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from locusAttribute.attributes";if(!n.isnumeric&&!n.appendto_link){if(!n.values)throw".values{} missing for non-numeric key "+e+" from locusAttribute.attributes";for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from locusAttribute.attributes"}}}}if(t.queries)for(const r in t.queries){if(n.remove_queries&&-1!=n.remove_queries.indexOf(r)){delete t.queries[r];continue}const o=t.queries[r];if(n.hide_queries&&-1!=n.hide_queries.indexOf(r)&&(o.hideforthemoment=1),o.istrack){if(!o.type)throw".type missing for track query "+r;if(o.viewrangeupperlimit&&!Number.isInteger(o.viewrangeupperlimit))throw".viewrangeupperlimit should be integer for track query "+r;if(o.type==k.tkt.mdsjunction){const n=ve(o,t,e);if(n)throw r+" (mdsjunction) error: "+n}else if(o.type==k.tkt.mdscnv){const n=we(o,t,e);if(n)throw r+" (mdscnv) error: "+n}else if(o.type==k.tkt.mdssvcnv){const n=xe(o,t,e);if(n)throw r+" (svcnv) error: "+n}else{if(o.type!=k.tkt.mdsvcf)throw"unknown track type for a query: "+o.type+" "+r;{const n=await qe(o,t,e);if(n)throw r+" (vcf) error: "+n}}ye(o,t)}else{if(!o.isgenenumeric)throw"unknown type of query from "+r;{const n=ke(o,t,e);if(n)throw r+" (genenumeric) error: "+n}}}if(t.track&&await K.init_track(t,e),t.annotationsampleset2matrix){if(!t.cohort)throw"ds.cohort misssing when annotationsampleset2matrix is in use";if(!t.cohort.annotation)throw"ds.cohort.annotation misssing when annotationsampleset2matrix is in use";if(!t.queries)throw"ds.queries misssing when annotationsampleset2matrix is in use";if(!t.annotationsampleset2matrix.key)throw".key STR missing in annotationsampleset2matrix";if(!t.annotationsampleset2matrix.groups)throw".groups{} missing in annotationsampleset2matrix";if("object"!=typeof t.annotationsampleset2matrix.groups)throw"ds.annotationsampleset2matrix.groups{} not an object";for(const e in t.annotationsampleset2matrix.groups){const n=t.annotationsampleset2matrix.groups[e];if(!n.groups||!Array.isArray(n.groups)||0==n.groups.length)throw".groups[] must be nonempty array in "+e;for(const r of n.groups){if(!r.name)throw".name missing from one of .groups[] in "+e;const n=r.matrixconfig;if(!n)throw".matrixconfig missing from one of .groups[] of "+e;if(!n.features)throw".features[] missing from group "+e;if(!Array.isArray(n.features))throw".features[] should be array from group "+e;if(0==n.features.length)throw".features[] zero length from group "+e;for(const r of n.features){if(t.annotationsampleset2matrix.commonfeatureattributes)for(const e in t.annotationsampleset2matrix.commonfeatureattributes)null==r[e]&&(r[e]=t.annotationsampleset2matrix.commonfeatureattributes[e]);if(!r.ismutation)return"unknown feature type from group "+e;if(!r.position)throw"position missing from feature "+JSON.stringify(r)+" from group "+e;if(!r.querykeylst)throw".querykeylst[] missing from ismutation feature from group "+e;if(!Array.isArray(r.querykeylst))throw".querykeylst[] not an array from ismutation feature from group "+e;if(0==r.querykeylst.length)throw".querykeylst[] zero length from ismutation feature from group "+e;for(const n of r.querykeylst)if(!t.queries[n])throw'unknown query key "'+n+'" from ismutation feature of group '+e}if(!n.limitsamplebyeitherannotation)throw".limitsamplebyeitherannotation[] missing from group "+e;if(!Array.isArray(n.limitsamplebyeitherannotation))throw".limitsamplebyeitherannotation[] should be array from group "+e;if(0==n.limitsamplebyeitherannotation.length)throw".limitsamplebyeitherannotation[] zero length from group "+e;for(const t of n.limitsamplebyeitherannotation){if(!t.key)throw"key missing from one of limitsamplebyeitherannotation from group "+e;if(!t.value)throw"value missing from one of limitsamplebyeitherannotation from group "+e}}}delete t.annotationsampleset2matrix.commonfeatureattributes}}function ye(t,e){if(t.groupsamplebyattr){t.groupsamplebyattr.key2group=new Map;for(const n in e.cohort.annotation)Zt(n,[],t.groupsamplebyattr.key2group,[],e,t)}}function ve(t,e,n){if(t.readcountCutoff&&(!Number.isInteger(t.readcountCutoff)||t.readcountCutoff<1))return"readcountCutoff must be positive integer";let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;t.file=n,r=n}else{if(!t.url)return"no file or url given for mdsjunction "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=i.split("\n");if(1!=n.length)return"mdsjunction file has multiple header lines (begin with #), but should have just 1";const r=n[0].split("\t");if(r[5]){t.samples=r.slice(5),t.attributeSummary=be(t.samples,e),t.hierarchySummary=_e(t.samples,e);for(const e in t.hierarchySummary){let n=0;for(const r in t.hierarchySummary[e])n++;console.log(n+" "+e+" hierarchy levels for "+t.name)}}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}if(console.log("(mdsjunction) "+t.name+": "+(t.samples?t.samples.length:0)+" samples, "+(t.nochr?'no "chr"':'has "chr"')),!t.infoFilter)return".infoFilter{} missing";if(!t.infoFilter.lst)return".lst[] missing from .infoFilter";for(const e of t.infoFilter.lst){if(!e.key)return".key missing from one of infoFilter";if(!e.label)return".label missing from one of infoFilter";if(!e.categories)return".categories missing from one of infoFilter";for(const t in e.categories){if(!e.categories[t].label)return".label missing from one category of "+e.label;if(!e.categories[t].color)return".color missing from on category of "+e.label}if(e.hiddenCategories){for(const t in e.hiddenCategories)if(!e.categories[t])return"invalid hidden key "+t+" of "+e.label}else e.hiddenCategories={}}if(!t.singlejunctionsummary)return".singlejunctionsummary missing but is currently required from "+t.name;if(t.singlejunctionsummary.readcountboxplotpercohort){if(!t.singlejunctionsummary.readcountboxplotpercohort.groups)return".groups[] missing from query.singlejunctionsummary.readcountboxplotpercohort for "+t.name;for(const e of t.singlejunctionsummary.readcountboxplotpercohort.groups){if(!e.key)return".key missing from one group of query.singlejunctionsummary.readcountboxplotpercohort.groups";if(!e.label)return".label missing from one group of query.singlejunctionsummary.readcountboxplotpercohort.groups"}}}function be(t,e){if(!(e.cohort&&e.cohort.annotation&&e.cohort.attributes&&t))return;const n={};for(const r of e.cohort.attributes.lst){const o={};for(const t in r.values)o[t]=0;for(const n of t){const t=e.cohort.annotation[n];if(!t)continue;const i=t[r.key];null!=i&&(i in o&&o[i]++)}n[r.key]=o}return n}function _e(t,e){if(!e.cohort||!e.cohort.annotation||!e.cohort.hierarchies||0==t.length)return;const n=[];for(const r of t){const t=e.cohort.annotation[r];t&&n.push(t)}const r={};for(const t of e.cohort.hierarchies.lst){const e=y(n,t.levels),o=E()(e);o.sum((t=>t.value));const i={};o.eachBefore((t=>{i[t.id]=t.value})),r[t.name]=i}return r}function we(t,e,n){let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}else{if(!t.url)return"no file or url given for (mdscnv) "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=i.split("\n");if(1!=n.length)return"mdscnv file has multiple header lines (begin with #), but should have just 1";const r=n[0].split("\t");t.samples=r.slice(5),t.attributeSummary=be(t.samples,e),t.hierarchySummary=_e(t.samples,e);for(const e in t.hierarchySummary){let n=0;for(const r in t.hierarchySummary[e])n++;console.log(n+" "+e+" hierarchy levels for "+t.name)}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}console.log("("+t.type+") "+t.name+": "+(t.samples?t.samples.length:"no")+" samples, "+(t.nochr?'no "chr"':'has "chr"'))}function xe(t,e,n){let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}else{if(!t.url)return"no file or url given for (svcnv) "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=new Set;for(const t of i.split("\n"))for(const e of t.split(" ").slice(1))n.add(e);if(0==n.size)return"no samples from the header line";if(t.samples=[...n],e.cohort&&e.cohort.annotation){const n=new Set;for(const r of t.samples)e.cohort.annotation[r]||n.add(r);n.size&&console.log("mdssvcnv unannotated samples: "+(t.noprintunannotatedsamples?n.size:[...n].join(" ")))}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}if(t.expressionrank_querykey){const n=e.queries[t.expressionrank_querykey];if(!n)return"invalid key by expressionrank_querykey";if(!n.isgenenumeric)return"query "+t.expressionrank_querykey+" not tagged as isgenenumeric"}if(t.vcf_querykey){const n=e.queries[t.vcf_querykey];if(!n)return"invalid key by vcf_querykey";if(n.type!=k.tkt.mdsvcf)return"query "+t.vcf_querykey+" not of mdsvcf type"}if(t.groupsamplebyattr){if(!t.groupsamplebyattr.attrlst)return".attrlst[] missing from groupsamplebyattr";if(0==t.groupsamplebyattr.attrlst.length)return"groupsamplebyattr.attrlst[] empty array";if(!e.cohort)return"groupsamplebyattr in use but ds.cohort missing";if(!e.cohort.annotation)return"groupsamplebyattr in use but ds.cohort.annotation missing";e.cohort.sampleAttribute||(e.cohort.sampleAttribute={}),e.cohort.sampleAttribute.attributes||(e.cohort.sampleAttribute.attributes={},console.log("cohort.sampleAttribute added when groupsamplebyattr is in use"));for(const n of t.groupsamplebyattr.attrlst){if(!n.k)return"k missing from one of groupsamplebyattr.attrlst[]";e.cohort.sampleAttribute.attributes[n.k]||(e.cohort.sampleAttribute.attributes[n.k]={label:n.label||n.k})}if(t.groupsamplebyattr.sortgroupby){if(!t.groupsamplebyattr.sortgroupby.key)return".key missing from .sortgroupby";if(!t.groupsamplebyattr.sortgroupby.order)return".order[] missing from .sortgroupby";if(!Array.isArray(t.groupsamplebyattr.sortgroupby.order))return".order must be an array"}t.groupsamplebyattr.attrnamespacer||(t.groupsamplebyattr.attrnamespacer=", ")}console.log("("+t.type+") "+t.name+": "+(t.samples?t.samples.length:"no")+" samples, "+(t.nochr?'no "chr"':'has "chr"'))}function ke(t,e,n){if(!t.datatype)return"datatype missing";if(t.viewrangeupperlimit&&Number.isNaN(t.viewrangeupperlimit))return"invalid value for viewrangeupperlimit";let r;if(!t.file)return"file missing";{const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}const o={cwd:null,encoding:"utf8"};{const e=p.execSync(vt+" -H "+r,o).trim();if(!e)return"no header line (#sample <sample1> ...)";const n=new Set;for(const t of e.split("\n")){const e=t.split(" ");for(let t=1;t<e.length;t++)n.add(e[t])}if(0==n.size)return"no sample names from header line";t.samples=[...n],console.log("(genenumeric) "+t.name+": "+t.samples.length+" samples")}if(t.boxplotbysamplegroup){if(!t.boxplotbysamplegroup.attributes)return"boxplotbysamplegroup.attributes missing";if(!Array.isArray(t.boxplotbysamplegroup.attributes))return"boxplotbysamplegroup.attributes should be array";for(const e of t.boxplotbysamplegroup.attributes)if(!e.k)return"k missing from one of boxplotbysamplegroup.attributes[]"}}async function qe(t,e,n){if(!t.tracks)return"tracks[] missing";if(!Array.isArray(t.tracks))return"tracks should be array";t.info={};for(const r of t.tracks){if(!r.file)return"file missing from a track (url not supported yet)";const[o,i]=se(r.file);if(o)return"tabix file error: "+o;if(r.type!=k.mdsvcftype.vcf)return"invalid track type: "+r.type;{r.cwd;const e=await x.get_header_tabix(i,r.cwd);if(0==e.length)return"no meta/header lines for "+i;const[n,o,s,a]=q.vcfparsemeta(e);if(a)return"error parsing vcf meta for "+i+": "+a.join("\n");if(0==s.length)return"vcf file has no sample: "+i;for(const e in n)t.info[e]=n[e];if(r.format=o,r.samplenameconvert){if("function"!=typeof r.samplenameconvert)return".samplenameconvert must be function";for(const t of s)t.name=r.samplenameconvert(t.name)}r.samples=s}if(e.cohort&&e.cohort.annotation){const t=[];for(const n of r.samples)e.cohort.annotation[n.name]||t.push(n.name);t.length&&console.log(e.label+": VCF "+r.file+" has unannotated samples: "+t.join(","))}{const t=[];if(await x.get_lines_bigfile({args:["-l",i],dir:r.cwd,callback:e=>{t.push(e)}}),0==t.length)return"no chr from "+i;r.nochr=k.contigNameNoChr(n,t)}console.log("("+t.type+") "+i+": "+r.samples.length+" samples, "+(r.nochr?"no chr":"has chr"))}if(t.singlesamples){if(!t.singlesamples.tablefile)return".singlesamples.tablefile missing for the VCF query";t.singlesamples.samples={};let e=0;for(const n of c.readFileSync(u.join(o.tpmasterdir,t.singlesamples.tablefile),{encoding:"utf8"}).trim().split("\n")){if(!n)continue;if("#"==n[0])continue;const r=n.split("\t");r[0]&&r[1]&&(t.singlesamples.samples[r[0]]=r[1],e++)}console.log(e+" single-sample VCF files")}}e.illegalpath=ce,e.fileurl=ue},6191:(t,e,n)=>{const r=n(7147).promises,o=n(7147).existsSync,i=n(1017),s=n(9344);function a(t){return t.cookies[`${t.query.dslabel}SessionId`]||t.headers["x-sjppds-sessionid"]||t.query["x-sjppds-sessionid"]}async function l(t,e,n,o,i,s,a="set-cookie"){const l=Date.now(),c=Math.random().toString()+"."+l.toString().slice(4),u=s.ip;return n[t.dslabel]||(n[t.dslabel]={}),n[t.dslabel][c]={id:c,time:l,email:i,ip:u},await r.appendFile(o,`${t.dslabel}\t${c}\t${l}\t${i}\t${u}\n`),a&&"set-cookie"!=a||e.header("Set-Cookie",`${t.dslabel}SessionId=${c}; HttpOnly; SameSite=None; Secure`),c}function c(t,e,n={},r,o=null){var i;const a=n[t.dslabel];if(!a)return;if(!t.embedder)throw"missing q.embedder";const l=a.embedders[t.embedder];if(!l)throw`unknown q.embedder='${t.embedder}'`;const c=l.secret;if(!c)throw"missing embedder setting";const u=Math.floor((r||Date.now())/1e3),f=e[a.headerKey];if(!f)throw`missing header['${a.headerKey}']`;const d=l.processor?require(l.processor):{},h=(null===(i=d.handleToken)||void 0===i?void 0:i.call(d,f))||f,p=s.verify(h,c);if(o)return{iat:p.iat,email:p.email,ip:p.ip};if(d.handlePayload)try{d.handlePayload(l,p,u)}catch(t){if("bad decrypt"==t.reason)throw`Please login again to access this feature. (${t.reason})`;throw t}if(u>p.exp)throw"Please login again to access this feature. (expired token)";const m=(l.dsnames||[t.dslabel]).filter((t=>!p.datasets.includes(t.id))).map((t=>t.id));if(m.length)throw{error:"Missing access",linkKey:m.join(",")};return{iat:p.iat,email:p.email,ip:p.ip}}function u(t,e){var n,r;if(!e)throw"Server error: missing ip address in saved session";if(t.ip!=e&&(null===(n=t.ips)||void 0===n?void 0:n[0])!=e&&(null===(r=t.connection)||void 0===r?void 0:r.remoteAddress)!=e)throw"Your connection has changed, please refresh your page or sign in again."}function f(t,e){const n=d.getDsAuth(t).find((t=>t.dslabel==e.label));return!n||n.insession}const d={maySetAuthRoutes:async function(t,e="",s=null){const f=s||n(334),h=i.join(f.cachedir,"dsSessions"),p=i.join(f.cachedir,"authorizedActions"),m=f.dsCredentials,g=f.maxSessionAge||576e5;let y;if(m&&Object.keys(m).length){t.use(((t,e,n)=>{const r=t.query;if(r.dslabel&&r.dslabel in m&&"/dslogin"!=t.path&&("jwt"!=m[r.dslabel].type||"/termdb"==t.path&&"matrix"==r.for))try{const e=a(t);if(!e)throw"missing session cookie";const o=y[r.dslabel][e];if(!o)throw"unestablished or expired browser session";u(t,o.ip);const i=Date.now();if(i-o.time>g){const{iat:n}=c(r,t.headers,m,o),s=i-n;if(s>g)throw delete y[r.dslabel][e],"Please login again to access this feature. (expired session)";if(s<3e5)return void(o.time=i)}o.time-i<900&&(o.time=i),n()}catch(t){e.send("object"==typeof t?t:{error:t})}else n()}));try{y=await async function(t,e,n){const i={};for(const e in t)i[e]||(i[e]={});try{const t=await r.readFile(e,"utf8"),o=+new Date;for(const e of t.split("\n")){if(!e)continue;const[t,r,s,a,l]=e.split("\t"),c=Number(s);i[t]||(i[t]={}),o-c<n&&(i[t][r]={id:r,time:c,email:a,ip:l})}return i}catch(t){return o(e)&&console.log(t),i}}(m,h,g)}catch(t){throw t}var v;await(v=0,new Promise((t=>setTimeout(t,v)))),t.post(e+"/dslogin",(async(t,e)=>{let n=401;try{var r,o,i;const s=t.query;if(!s.dslabel||!(s.dslabel in m))throw n=400,`No login required for dataset='${s.dslabel}'`;if(!t.headers.authorization)throw"missing authorization header";const[a,c]=t.headers.authorization.split(" ");if("basic"!=a.toLowerCase())throw`unsupported authorization type='${a}', allowed: 'Basic'`;if(Buffer.from(c,"base64").toString()!=m[s.dslabel].password)throw"invalid password";await l(s,e,y,h,"",t,null===(r=m[s.dslabel])||void 0===r||null===(o=r.embedders)||void 0===o||null===(i=o[s.embedder])||void 0===i?void 0:i.cookieMode),e.send({status:"ok"})}catch(t){e.status(n),e.send({error:t})}})),t.post(e+"/jwt-status",(async(t,e)=>{try{const n=t.query,{email:r,ip:o}=await c(n,t.headers,m);u(t,o);const i=await l(n,e,y,h,r,t,m[n.dslabel].embedders[n.embedder].cookieMode);e.send({status:"ok","x-sjppds-sessionid":i})}catch(t){console.log(t),e.status(401),e.send(t instanceof Error||"object"!=typeof t?{error:t}:t)}})),t.post(e+"/authorizedActions",(async(t,e)=>{const n=t.query;try{const o=a(t),{email:i}=y[n.dslabel][o],s=new Date;await r.appendFile(p,`${n.dslabel}\t${i}\t${s}\t${n.action}\t${JSON.stringify(n.details)}\n`),e.send({status:"ok"})}catch(t){e.status(401),e.send("object"==typeof t?t:{error:t})}})),d.getDsAuth=function(t){return Object.keys(m||{}).map((e=>{try{var n,r;const o=m[e],i=a(t),s=(null===(n=y[e])||void 0===n||null===(r=n[i])||void 0===r?void 0:r.time)||0;return{dslabel:e,insession:("jwt"!=o.type||i)&&Date.now()-s<g,type:o.type||"login"}}catch(t){throw t}}))}}},checkDsSecret:c,getDsAuth:()=>[],canDisplaySampleIds:(t,e)=>!!e.cohort.termdb.displaySampleIds&&f(t,e),userCanAccess:f};t.exports=d},2384:(t,e,n)=>{"use strict";n.r(e),n.d(e,{duplicateRegions:()=>u,make_type2group:()=>c,type_all:()=>r,type_supportalt:()=>i,type_supportamb:()=>a,type_supportno:()=>s,type_supportref:()=>o,type_supportsv:()=>l});const r="all",o="support_ref",i="support_alt",s="support_no",a="support_amb",l="support_sv";function c(t){const e={};if(t.variant)if(t.grouptype)e[t.grouptype]={partstack:t.partstack};else{e[o]={},e[s]={},e[a]={};for(let n=0;n<t.variant.length;n++)e[i+n.toString()]={}}else{if(!t.sv)throw"q.variant or q.sv missing";t.grouptype?e[t.grouptype]={partstack:t.partstack}:(e[l]={},e[o]={})}for(const n in e){const r=e[n];r.type=n,r.templates=[],r.regions=u(t.regions),r.messages=[]}return e}function u(t){return t.map((t=>({x:t.x,scale:t.scale,ntwidth:t.ntwidth})))}},8164:(t,e,n)=>{"use strict";n.r(e),n.d(e,{gdcCheckPermission:()=>m,gdc_bam_request:()=>i});const r=n(6452),o=n(1017);async function i(t,e){try{if(t.query.gdc_id){const n=await async function(t,e){const n={file_metadata:[],numFilesSkippedByWorkflow:0},r=await u(t,n,e);if(!r.data.hits.length){if(n.is_case_id||n.is_case_uuid)throw"No bam files available for this case.";if(e){if((await u(t,n)).data.hits.length)throw"Case not in current cohort.";throw"Invalid input ID."}throw"Invalid input ID."}for(const t of r.data.hits){if(t.analysis.workflow_type==c){n.numFilesSkippedByWorkflow++;continue}const e={};e.file_uuid=t.id,e.file_size=(Number.parseFloat(t.file_size)/1e9).toFixed(2)+" GB",e.experimental_strategy=t.experimental_strategy,e.entity_id=t.associated_entities[0].entity_submitter_id,e.case_id=t.associated_entities[0].case_id,e.sample_type=t.cases[0].samples[0].sample_type,n.file_metadata.push(e)}return n}(t.query.gdc_id,t.query.filter0);await async function(t,e){var n;if(null===(n=t.file_metadata)||void 0===n||!n.length)return;const r=e.cookies.sessionid;if(!r)return;try{await m(t.file_metadata[0].file_uuid,null,r)}catch(e){"Permission denied"==e&&(t.userHasNoAccess=!0)}}(n,t),e.send(n)}else{const n=await async function(t){var e,n,r;const o=await d(null,null,t,g),i={};if(!Array.isArray(null===(e=o.data)||void 0===e?void 0:e.hits))throw"re.data.hits[] not array";for(const t of o.data.hits){var s,a,l,u;if(t.analysis.workflow_type==c)continue;const e=null===(s=t.cases)||void 0===s||null===(a=s[0])||void 0===a?void 0:a.submitter_id;e&&(i[e]||(i[e]=[]),i[e].push({file_uuid:t.id,sample_type:null===(l=t.cases)||void 0===l||null===(u=l[0].samples)||void 0===u?void 0:u[0].sample_type,experimental_strategy:t.experimental_strategy,file_size:(Number.parseFloat(t.file_size)/1e9).toFixed(2)+" GB"}))}return{case2files:i,total:null===(n=o.data)||void 0===n||null===(r=n.pagination)||void 0===r?void 0:r.total,loaded:g}}(t.query.filter0);e.send(n)}}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}}const s=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",a={end_point:o.join(s,"files/"),fields:["id","file_size","experimental_strategy","cases.submitter_id","associated_entities.entity_submitter_id","associated_entities.case_id","cases.samples.sample_type","analysis.workflow_type"],size:100},l={end_point:o.join(s,"cases/"),fields:["case_id"]},c="STAR 2-Pass Transcriptome";async function u(t,e,n){if(await f(t,"cases.case_id",n))return e.is_case_uuid=!0,await d(t,"cases.case_id",n);if(await f(t,"cases.submitter_id",n))return e.is_case_id=!0,await d(t,"cases.submitter_id",n);const r=await h(t,"file_id",n);if(r.data.hits.length)return e.is_file_uuid=!0,r;const o=await h(t,"file_name",n);return o.data.hits.length&&(e.is_file_id=!0),o}async function f(t,e,n){const r={op:"and",content:[{op:"in",content:{field:e,value:t}}]};n&&r.content.push(n);return(await p(r,l)).data.hits.length>0}async function d(t,e,n,r){const o={op:"and",content:[{op:"=",content:{field:"data_category",value:"Sequencing Reads"}},{op:"=",content:{field:"index_files.data_format",value:"bai"}},{op:"=",content:{field:"data_type",value:"Aligned Reads"}},{op:"=",content:{field:"data_format",value:"bam"}}]};return t&&e&&o.content.push({op:"in",content:{field:e,value:t}}),n&&o.content.push(n),await p(o,a,r)}async function h(t,e,n){const r={op:"and",content:[{op:"in",content:{field:e,value:t}}]};return n&&r.content.push(n),await p(r,a)}async function p(t,e,n){const o={filters:t,size:n||10,fields:e.fields.join(",")},i=await r(e.end_point,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(o)});let s;try{s=JSON.parse(i.body)}catch(t){throw"invalid JSON from "+e.end_point}if(!s.data||!s.data.hits)throw"data structure not data.hits[]";return s}async function m(t,e,n){const o={Range:"bytes=0-0"};n?o.Cookie=`sessionid=${n}`:o["X-Auth-Token"]=e;const i=s+"/data/"+t;try{const t=await r(i,{headers:o,decompress:!1});if(!(t.statusCode>=200&&t.statusCode<400))throw console.log(`gdcCheckPermission() error for got(${i})`,t),"Invalid status code: "+t.statusCode}catch(t){throw console.log("gdcCheckPermission error: ",(null==t?void 0:t.code)||t),"Permission denied"}}const g=1e3},7253:(t,e,n)=>{const r=n(9699),o=n(2781),i=n(6113),{promisify:s}=n(6464),a=n(6452),l=s(o.pipeline),c=n(1017),u=n(7147),f=n(2781).Readable,d=n(3856),h=n(1271).run_rust,p=n(6718).createCanvas,m=n(2081).spawn,g=(n(4521),n(6778).interpolateRgb),y=n(8953).Y,v=n(2384),{basecolor:b,bplen:_}=n(2273),{gdcCheckPermission:w}=n(8164),x=n(334),k=x.clustalo,q="rgb(120,120,120)",N="rgb(230,230,230)",S=g(N,q),A="#d48b37",M=g("#dbc6ad",A),T="#3B7A57",C=g("#E5FFCC",T),j="#d13232",O="#ffdbdd",E=g(O,j),R="#4888bf",I="#c9e6ff",P=g(I,R),F="#6B4423",L=g("#987654",F),D="#fc6df3",B=g("#dea4da",D),z="#47FFFC",Z="#B2D7D7",$=g(Z,z),G="#ededed",U="blue",H="#e0e0e0",W="#FF0000",J="#6cc24a",V="#ffff00",Y="#DEB887",Q="#CD853F",K="#9a92ec",X="#47C8FF",tt=40,et=.5,nt=7e3,rt=1500,ot=(new Set(["A","T","C","G"]),process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov"),it=Math.random.toString();async function st(t,e,n,r,o){const i=t.diff_score_plotwidth/(r-o),s=r*i-o*i,a=p(s*t.devicePixelRatio,e.canvasheight*t.devicePixelRatio),l=a.getContext("2d");t.devicePixelRatio>1&&l.scale(t.devicePixelRatio,t.devicePixelRatio);const c=n.map((t=>t.__tempscore)),u=e.canvasheight/c.length;let f=0;const d=e.stackspace/e.canvasheight;for(const t of c){let e=0;for(const n of t)"alt0"==n?l.fillStyle=W:"ref"==n?l.fillStyle=X:"alt1"==n?l.fillStyle=J:"alt2"==n?l.fillStyle=V:"alt3"==n?l.fillStyle=Y:"alt4"==n?l.fillStyle=Q:"alt5"==n&&(l.fillStyle=K),l.fillRect(i*e,f*u,i,u-d*u),e+=1;f+=1}return{height:e.canvasheight,width:s,src:a.toDataURL(),read_height:u}}function at(t,e,n,r){for(const o of n)for(const n of o.segments)if(!(n.ridx!=t||Math.max(n.segstart,e.start)>Math.min(n.segstop,e.stop)))for(const t of n.boxes)if(e.ntwidth>=1){if(("S"==t.opr||"X"==t.opr)&&t.s)for(let e=0;e<t.s.length;e++){const n=t.start+e,o=r.find((t=>t.position==n));if(!o)continue;const i=t.s[e];o[i]=1+(o[i]||0),"S"==t.opr&&o.total++}}else if("S"==t.opr){const n=Math.floor((t.start-e.start)*e.ntwidth),o=Math.floor((t.start+t.len-e.start)*e.ntwidth);for(let t=n;t<=o;t++){const e=r[t];e&&(e.softclip=1+(e.softclip||0),e.total++)}}}async function lt(t,e){if(!await d.file_not_exist(e))return;if(!t.query.gdcFilePosition)throw".gdcFilePosition missing";const n=t.query.regions,r=t.query.gdcFilePosition.split(".");t.query.regions=[{chr:r[0],start:Number(r[1]),stop:Number(r[2])}],await Tt(t),t.query.regions=n}async function ct(t,e,n,r,o){const i=t.map((t=>t.segments[0].seq)),s=t.map((t=>t.segments[0].qual));let a="",l="";o&&(a+=">seq\n"+o.replace("\n","")+"\n");let c=0;for(const t of i){if(!(c<200))break;a+=">seq\n"+t.replace("\n","")+"\n",l+=_t(s[c].replace("\n",""))+"\n",c+=1}return await function(t,e,n,r,o,i,s,a){return new Promise(((n,l)=>{const c=m(k,["-i","-","-t","DNA","--outfmt=clu","--wrap=5000","--maxnumseq="+(e+1),"--maxseqlen=1000"]),u=[],d=[];f.from(t).pipe(c.stdin),c.stdout.on("data",(t=>u.push(t))),c.stderr.on("data",(t=>d.push(t))),c.on("error",(t=>{console.log("stderr (clustalo):",d),l(t)})),c.on("close",(t=>{let e=0;const c=[],f={final_read_align:[],qual_r:[],qual_g:[],qual_b:[]};let d=0;for(const t of u.toString().split("\n"))if(t.includes("seq ")){let n=0,l="",u=0,h="";0!=e&&a?h=r.split("\n")[e-1].split(","):a||(h=r.split("\n")[e].split(","));let p="",m="",g="";for(const r of t.replace("seq ",""))if(","!=r){if("-"!=r){if(n+=1,l+=r,0==e&&a)c.push(r);else if(r==c[u]&&a||!a){const t=S(h[n-1]/tt).replace("rgb(","").replace(")","").split(",");p+=t[0]+",",m+=t[1]+",",g+=t[2]+","}else if(r!=c[u]&&a){const t=E(h[n-1]/tt).replace("rgb(","").replace(")","").split(",");p+=t[0]+",",m+=t[1]+",",g+=t[2]+","}}else n>0&&n<t.replace(/-/g,"").replace(/,/g,"").replace("seq ","").length?(l+=r,0==e&&(c.push(r),u<o&&(d+=1))):(l+=" ",0==e&&c.push(r)),p+="255,",m+="255,",g+="255,";u+=1}e+=1,f.gaps_before_variant=d,f.read_count=a?e-1:e,f.qual_r.push(p),f.qual_g.push(m),f.qual_b.push(g),f.final_read_align.push(l),0!=i&&0!=s&&(f.partstack_start=i,f.partstack_stop=s)}else(t.includes("FATAL:")||t.includes("ERROR:"))&&(console.log(t),l(t));n(f)}))}))}(a,200,i.length,l,e,n,r,o)}async function ut(t,e){let n=0;for(const r of e){const e=["view","-c",t.file];t.gdc_case_id||e.push((t.nochr?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop),await d.get_lines_bigfile({isbam:!0,args:e,dir:t.dir,callback:t=>{const e=Number(t);if(!Number.isInteger(e))throw"total number of reads from a region not integer";n+=e}})}if(n<1.1*nt)return;const r=(n-nt)/700;t.downsample={keep:10,skip:Math.floor(r),pointer:0},t.read_limit_reached=n}async function ft(t,e){t.lines=[];const n=["view",e.file];e.gdc_case_id||n.push((e.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop),await d.get_lines_bigfile({isbam:!0,args:n,dir:e.dir,callback:(n,r)=>{if(!(1024&n.split("\t")[1]&&e.drop_pcrduplicates)){if(e.downsample){const t=e.downsample;if(t.pointer++,t.pointer>=t.keep&&t.pointer<t.keep+t.skip)return;t.pointer>=t.keep+t.skip&&(t.pointer=0)}t.lines.push(n)}}})}async function dt(t,e){const n=[],r=["depth","-r",(t.nochr?e.chr.replace("chr",""):e.chr)+":"+(e.start+1)+"-"+e.stop,"-g","DUP",t.file||t.url];if(t.drop_pcrduplicates&&(r.push("-G"),r.push("0x400")),await d.get_lines_bigfile({isbam:!0,args:r,dir:t.dir,callback:t=>{const r=t.split("\t"),o=Number.parseInt(r[1])-1,i=Number.parseInt(r[2]);if(e.ntwidth>=1)return void n.push({position:o,total:i});const s=Math.floor((o-e.start)*e.ntwidth);n[s]||(n[s]={position:o,sum:0,count:0}),n[s].sum+=i,n[s].count++}}),e.ntwidth<1)for(const t of n)t&&(t.total=t.sum/t.count,delete t.sum,delete t.count);return n}async function ht(t,e){for(const t of e.regions)t.lines.length>0&&t.ntwidth>=.9&&(t.to_checkmismatch=!0,t.referenceseq=await vt(e.genome,t.chr+":"+(t.start+1)+"-"+t.stop));for(const n of t)for(const t of n.segments){const n=e.regions[t.ridx];if(!n.to_checkmismatch)continue;const r=[];for(const e of t.boxes)null!=e.cidx&&"M"==e.opr&&(e.s=t.seq.substr(e.cidx,e.len),xt(r,n,e,e.s));r.length&&t.boxes.push(...r)}for(const t of e.regions)delete t.to_checkmismatch,delete t.referenceseq}function pt(t,e){if(!t.asPaired){const n=[];for(let r=0;r<t.regions.length;r++){const o=t.regions[r];for(const i of e.templates){i.ridx=r;const e=mt(i,o,t);e&&n.push({x1:e.x1,x2:e.x2,__tempscore:e.tempscore,segments:[e]})}}return n}const n=new Map;for(let r=0;r<t.regions.length;r++){const o=t.regions[r];for(const i of e.templates){i.ridx=r;const e=mt(i,o,t);if(!e||!e.qname)continue;const s=n.get(e.qname);s?(s.segments.push(e),s.x2=Math.max(s.x2,e.x2)):n.set(e.qname,{x1:Math.max(e.x1,o.x),x2:Math.min(e.x2,o.x+o.width),__tempscore:e.tempscore,segments:[e]})}}return[...n.values()]}function mt(t,e,n){const{sam_info:r,tempscore:o,ridx:i,keepallboxes:s,keepmatepos:a,keepunmappedread:l}=t,c=r.trim().split("\t");if(c.length<11)return;const u=c[0],f=c[1],d=Number.parseInt(c[3]),h=c[5],p=c[6],m=c[7],g=Number.parseInt(c[8]),y=c[9],v=c[10];if(Number.isNaN(d)||d<=0)return;const b=d-1,_={qname:u,segstart:b,segstart_original:b,segstop:b,boxes:[],forward:!(16&f),ridx:i,seq:y,qual:v,cigarstr:h,tlen:g,flag:f,tempscore:o};if(function(t,e,n,r,o,i){const s=t.flag;if(!(1&s))return;64&s?t.isfirst=!0:128&s&&(t.islast=!0);if("="!=e&&"*"!=e&&e!=r.chr)return t.rnext=e,void(t.pnext=n);if(8&s)return void(t.discord_unmapped2=!0);32&s&&!(16&s)&&64&s||16&s&&!(32&s)&&128&s||16&s&&!(32&s)&&64&s||32&s&&!(16&s)&&128&s||(t.discord_orientation=!0,o&&(16&s?32&s?t.discord_orientation_direction="R1R2":n>i&&(t.discord_orientation_direction="R1F2"):32&s?n<i&&(t.discord_orientation_direction="R1F2"):t.discord_orientation_direction="F1F2")),2&s||(t.discord_wrong_insertsize=!0,o&&(t.pnext=n))}(_,p,m,e,a,d),4&f)return l?(_.boxes.push({opr:h,start:b,len:y.length,cidx:0,qual:v}),_.discord_unmapped1=!0,_):void 0;if("*"!=h){let t=b,r=0,o=0;for(let n=0;n<h.length;n++){const i=h[n];if(i.match(/[0-9]/))continue;const a=Number.parseInt(h.substring(r,n));if("H"!=i)if("N"==i||"P"==i||"D"==i||(o+=a),r=n+1,"="!=i&&"M"!=i)if("I"!=i)if("N"!=i&&"D"!=i)if("X"!=i)if("S"!=i){if("P"!=i)console.log("unknown cigar: "+i);else if(s||t>e.start&&t<e.stop){const e={opr:"P",start:t,len:a,cidx:o-a};_.boxes.push(e)}}else{const n={opr:i,start:t,len:a,cidx:o-a};0==_.boxes.length?(n.start-=a,(s||Math.max(t,e.start)<=Math.min(t+a-1,e.stop))&&_.boxes.push(n)):_.boxes.push(n)}else{if(s||Math.max(t,e.start)<Math.min(t+a-1,e.stop)){const e={opr:i,start:t,len:a,cidx:o-a};_.boxes.push(e)}t+=a}else(t>=e.start&&t<=e.stop||t+a-1>=e.start&&t+a-1<=e.stop||s)&&_.boxes.push({opr:i,start:t,len:a}),t+=a;else(s||t>e.start&&t<e.stop)&&a*e.ntwidth>=1&&_.boxes.push({opr:"I",start:t,len:a,cidx:o-a});else(s||Math.max(t,e.start)<=Math.min(t+a-1,e.stop))&&_.boxes.push({opr:i,start:t,len:a,cidx:o-a}),t+=a;else _.boxes.push({opr:i,start:t,len:a,cidx:o-a}),r=n+1}if(0==_.boxes.length)return void(n&&n.readcount_skipped++);_.segstop=t,_.x1=e.x+e.scale(_.boxes[0].start),_.x2=e.x+e.scale((w=_.boxes,Math.max(...w.map((t=>t.start+t.len)))))}var w;return _}async function gt(t,e,n){const[r,o]=function(t,e){let n=(e.groups.length>1?750:rt)/t;return n>10?[Math.min(15,Math.floor(n)),1]:n>7?[Math.floor(n),1]:n>3?[Math.ceil(n),0]:n>1?[Math.floor(n),0]:[n,0]}(t.stacks.length,e);t.stackheight=r,t.stackspace=o;for(const e of t.regions)e.to_printnt=t.stackheight>7&&e.ntwidth>=7,e.to_qual=e.ntwidth>=1;if(t.stacks.length&&(t.stackheight>=7&&n.length<2e3?t.returntemplatebox=[]:t.partstack||(t.allowpartstack=!0)),t.stackheight>=7){let e=0;for(const t of n)for(const n of t.segments)e=Math.max(e,n.x2-n.x1);e>.7*t.stackheight&&(t.canClipArrowhead=!0)}}function yt(t,e,n){if(e.asPaired){t.stacks=[];const r=[],o=[];for(const t of n){let n=t.segments[0].ridx;1==t.segments.length||2==t.segments.length&&t.segments[0].ridx==t.segments[1].ridx?(t.x1=Math.max(e.regions[n].x,t.x1),t.x2=Math.min(e.regions[n].x+e.regions[n].width,t.x2),r.push(t)):2==t.segments.length&&t.segments[0].ridx!=t.segments[1].ridx&&(t.x1=t.x1,t.x2=t.x2,o.push(t))}if(r.sort(((t,e)=>t.x1-e.x1)),o.sort(((t,e)=>t.x1-e.x1)),o.length>0){const t=[],e=[],i=o[0];for(const n of r)n.x1<i.x1&&n.x2<i.x1?t.push(n):e.push(n);n=[...t,...o,...e]}for(const r of n){let n=r.segments[0].ridx,o=null;if(!e.variant)for(let i=0;i<t.stacks.length;i++){if(r.x2==e.regions[n].x+e.regions[n].width&&t.stacks[i]<r.x1){o=i,t.stacks[i]=r.x2;break}if(t.stacks[i]+e.stacksegspacing<r.x1){o=i,t.stacks[i]=r.x2;break}}null==o&&(o=t.stacks.length,t.stacks[o]=r.x2),r.y=o}}else{n.sort(((t,e)=>t.x1-e.x1)),t.stacks=[];for(let r=0;r<e.regions.length;r++)for(const o of n)if(o.segments[0].ridx==r){let n=null;if(!e.variant&&!e.sv)for(let i=0;i<t.stacks.length;i++)if(t.stacks[i]+e.stacksegspacing<o.x1&&t.stacks[i]+e.stacksegspacing<e.regions[r].x+e.regions[r].width){n=i,t.stacks[i]=o.x2;break}null==n&&(n=t.stacks.length,t.stacks[n]=o.x2),o.y=n}}return n=function(t,e,n){if(!t.partstack)return e;const r=e.filter((e=>e.y>=t.partstack.start&&e.y<=t.partstack.stop));r.forEach((e=>e.y-=t.partstack.start)),e=r,t.stacks=[];for(let e=t.partstack.start;e<=t.partstack.stop;e++)t.stacks.push(0);return t.returntemplatebox=[],e}(t,n),n}async function vt(t,e){const n=(await d.get_fasta(t,e)).split("\n");return n.shift(),n.join("").toUpperCase()}function bt(t,e,n){const r=function(t,e,n){const r=[];for(let e=0;e<t.stacks.length;e++)r.push(t.stackheight);if(function(t,e){if(!e.asPaired)return;for(const e of t.regions)if(e.ntwidth<=.4)return;t.overlapRP_multirows=!0,t.overlapRP_hlline=t.stackspace>0}(t,n),t.overlapRP_multirows)for(const n of e)n.segments.length<=1||n.segments[0].ridx!=n.segments[1].ridx||(n.height=wt(n,t.stackheight),r[n.y]=Math.max(r[n.y],n.height));const o=[];let i=t.stackspace;for(const e of r)o.push(i),i+=e+t.stackspace;return t.canvasheight=i,o}(t,e,n);for(const n of e){n.y=r[n.y];for(const e of n.segments){const n=t.regions[e.ridx].to_qual?_t(e.qual):null;for(const t of e.boxes)null!=t.cidx&&"H"!=t.opr&&(n&&(t.qual=n.slice(t.cidx,t.cidx+t.len)),"I"==t.opr?t.s=e.seq.substr(t.cidx,t.len):"X"!=t.opr&&"S"!=t.opr||(t.s=e.seq.substr(t.cidx,t.len)),delete t.cidx);delete e.seq,delete e.qual}}}function _t(t){if("*"==t)return null;const e=[];for(let n=0;n<t.length;n++){const r=t[n].charCodeAt(0)-33;e.push(r)}return e}function wt(t,e){if(2==t.segments.length){const[n,r]=t.segments;return n.x2>r.x1?(r.shiftdownrow=1,2*e):e}console.log("more than 2 segments",t.segments.length);const n=[];for(const e of t.segments){let t=null;for(let r=0;r<n.length;r++)if(n[r]<e.x1){t=r,n[r]=e.x2;break}null==t&&(t=n.length,n[t]=e.x2),e.shiftdownrow=t}return e*n.length}function xt(t,e,n,r){for(let o=0;o<r.length;o++){if(n.start+o<e.start||n.start+o>e.stop)continue;const i=r[o];if(e.referenceseq[n.start+o-e.start]!=i.toUpperCase()){const e={opr:"X",start:n.start+o,len:1,s:i,cidx:n.cidx+o};t.push(e)}}}function kt(t,e,n,r){if(n.returntemplatebox){const t=n.regions[e.segments[0].ridx];let o;if(t.width=n.widths[e.segments[0].ridx],r.asPaired)if(2==e.segments.length)o=e.segments[0].ridx!=e.segments[1].ridx?{qname:e.segments[0].qname,x1:e.x1,x2:e.x2,y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop))),multi_region:!0}:{qname:e.segments[0].qname,x1:Math.max(t.x,e.x1),x2:Math.min(e.x2,t.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))};else{const t=e.segments[0],r=n.regions[t.ridx];r.width=n.widths[t.ridx],o={qname:e.segments[0].qname,x1:Math.max(r.x,e.x1),x2:Math.min(e.x2,r.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))}}else o={qname:e.segments[0].qname,x1:Math.max(t.x,e.x1),x2:Math.min(e.x2,t.x+t.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))},e.segments[0].isfirst&&(o.isfirst=!0),e.segments[0].islast&&(o.islast=!0);n.returntemplatebox.push(o)}for(let o=0;o<e.segments.length;o++){const i=e.segments[o],s=n.regions[i.ridx];if(s.width=n.widths[i.ridx],0==o){qt(t,i,e.y,n,r);continue}const a=e.segments[o-1],l=n.regions[a.ridx];if(l.width=n.widths[a.ridx],a.x2<=i.x1||e.segments[0].ridx!=e.segments[1].ridx){qt(t,i,e.y,n,r);const o=Math.floor(e.y+n.stackheight/2)+.5;if(t.strokeStyle=n.stackheight<=2?G:q,t.setLineDash([5,3]),t.beginPath(),l.x==s.x?(t.moveTo(a.x2,o),t.lineTo(i.x1,o)):l.x<a.x2&&i.x1<s.width&&(t.moveTo(Math.min(a.x2,l.width),o),t.lineTo(Math.max(i.x1,s.x),o)),t.stroke(),n.overlapRP_hlline){const r=a.boxes.reduce(((t,e)=>t.start+t.len>e.start+e.len?t:e));if(r.start+r.len==i.boxes[0].start){t.strokeStyle=U,t.setLineDash([]),t.beginPath();const r=Math.floor(i.x1)+.5;t.moveTo(r,e.y),t.lineTo(r,e.y+n.stackheight),t.stroke()}}}else if(n.overlapRP_multirows){if(qt(t,i,e.y+n.stackheight,n,r),n.overlapRP_hlline){const r=Math.floor(e.y+n.stackheight)+.5;t.strokeStyle=U,t.setLineDash([]),t.beginPath(),l.x<=a.x2&&i.x1<=s.width&&(t.moveTo(Math.max(i.x1,s.x),r),t.lineTo(Math.min(a.x2,l.width),r)),t.stroke()}}else qt(t,i,e.y,n,r)}null!=e.__tempscore&&x.features.indel_read_alignment_scores&&(t.fillStyle="blue",t.font=n.stackheight+"pt Arial",t.fillText(e.__tempscore,r.regions[0].width-100,e.y+n.stackheight/2))}function qt(t,e,n,r,o){const i=r.regions[e.ridx];i.width=r.widths[e.ridx];for(const o of e.boxes){const s=i.x+i.scale(o.start);if("P"!=o.opr&&"H"!=o.opr&&"I"!=o.opr)if("D"!=o.opr&&"N"!=o.opr)if("*"!=o.opr){if("X"!=o.opr&&"S"!=o.opr){if("M"!=o.opr&&"="!=o.opr)throw"unknown opr at rendering: "+o.opr;if(i.to_qual&&o.qual){let a=s;o.qual.forEach((o=>{e.rnext?t.fillStyle=M(o/tt):e.discord_orientation?t.fillStyle=B(o/tt):e.discord_wrong_insertsize?t.fillStyle=C(o/tt):e.discord_unmapped2?t.fillStyle=L(o/tt):t.fillStyle=S(o/tt),a+i.ntwidth+et<i.width&&i.x<=a?t.fillRect(a,n,i.ntwidth+et,r.stackheight):a<i.width&&a+i.ntwidth+et>=i.width&&i.x<=a?t.fillRect(a,n,i.width-a,r.stackheight):a<=i.x&&a+i.ntwidth+et>i.x&&t.fillRect(i.x,n,i.ntwidth+et+a-i.x,r.stackheight),a+=i.ntwidth}))}else o.qual?e.rnext?t.fillStyle=A:e.discord_orientation?t.fillStyle=D:e.discord_wrong_insertsize?t.fillStyle=T:e.discord_unmapped2?t.fillStyle=F:t.fillStyle=q:i.to_printnt?t.fillStyle="white":e.rnext?t.fillStyle=A:e.discord_orientation?t.fillStyle=D:e.discord_wrong_insertsize?t.fillStyle=T:e.discord_unmapped2?t.fillStyle=F:t.fillStyle=q,s+o.len*i.ntwidth+et<i.width&&s<i.width&&i.x<s+et?t.fillRect(s,n,o.len*i.ntwidth+et,r.stackheight):s+o.len*i.ntwidth+et<i.width&&i.x>=s?t.fillRect(i.x,n,o.len*i.ntwidth+et+s-i.x,r.stackheight):s+o.len*i.ntwidth+et>=i.width&&i.x<s?t.fillRect(s,n,i.width-s,r.stackheight):s+o.len*i.ntwidth+et>=i.width&&i.x>=s&&t.fillRect(i.x,n,i.width-s,r.stackheight);if(i.to_printnt){t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial",o.qual?t.fillStyle="white":t.fillStyle="black";for(let e=0;e<o.s.length;e++)s+i.ntwidth*(e+.5)<i.width&&s<i.width&&i.x<=s+i.ntwidth*(e+.5)&&t.fillText(o.s[e],s+i.ntwidth*(e+.5),n+r.stackheight/2)}}else if(i.to_qual&&o.qual){i.to_printnt&&(t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial");let e=s;for(let s=0;s<o.qual.length;s++){const a=o.qual[s]/tt;t.fillStyle="S"==o.opr?P(a):E(a),e+i.ntwidth+et<i.x+i.width&&i.x<=e?t.fillRect(e,n,i.ntwidth+et,r.stackheight):e<i.x+i.width&&e+i.ntwidth+et>=i.x+i.width&&i.x<=e?t.fillRect(e,n,i.width+i.x-e,r.stackheight):e<=i.x&&e+i.ntwidth+et>i.x&&t.fillRect(i.x,n,i.ntwidth+et+e-i.x,r.stackheight),i.to_printnt&&(o.qual?t.fillStyle="white":t.fillStyle="black",e+i.ntwidth/2<i.width&&e<i.width&&i.x<=e+i.ntwidth/2&&t.fillText(o.s[s],e+i.ntwidth/2,n+r.stackheight/2)),e+=i.ntwidth}}else if(t.fillStyle="S"==o.opr?R:j,s+o.len*i.ntwidth+et<i.width&&i.x<s?t.fillRect(s,n,o.len*i.ntwidth+et,r.stackheight):s+o.len*i.ntwidth+et<i.width&&i.x>=s?t.fillRect(i.x,n,o.len*i.ntwidth+et+s-i.x,r.stackheight):s+o.len*i.ntwidth+et<=i.width&&i.x<s&&t.fillRect(s,n,i.width-s,r.stackheight),i.to_printnt&&!o.qual){t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial",o.qual?t.fillStyle="white":t.fillStyle="black";for(let e=0;e<o.s.length;e++)s+i.ntwidth*(e+.5)<i.width&&s<i.width&&i.x<=s+i.ntwidth*(e+.5)&&t.fillText(o.s[e],s+i.ntwidth*(e+.5),n+r.stackheight/2)}}else{if(i.to_qual&&o.qual){let a=s;o.qual.forEach((o=>{e.discord_unmapped2&&(t.fillStyle=L(o/tt)),t.fillRect(a,n,i.ntwidth+et,r.stackheight),a+=i.ntwidth}))}else e.discord_unmapped2&&(t.fillStyle=F),t.fillRect(s,n,o.len*i.ntwidth+et,r.stackheight);i.to_printnt&&(t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial")}else{"D"==o.opr?t.strokeStyle="black":t.strokeStyle=r.stackheight<=2?G:q,t.setLineDash([]);const e=Math.floor(n+r.stackheight/2)+.5;if(t.beginPath(),t.moveTo(Math.max(s,i.x),e),t.lineTo(Math.min(s+o.len*i.ntwidth,i.x+i.width),e),t.stroke(),r.stackheight>7){const e=Math.max(i.x,s),a=Math.min(i.x+i.width,s+o.len*i.ntwidth);if(a-e>=50){const s=Math.min(10,Math.max(7,r.stackheight-2));t.font=s+"pt Arial";const l=t.measureText(o.len+" bp").width;l<a-e-20&&(t.fillStyle="white",(a+e)/2+l/2<i.width&&i.x<(a+e)/2-l/2?(t.fillRect((a+e)/2-l/2,n,l,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)):(a+e)/2+l/2<i.width&&i.x>=(a+e)/2-l/2?(t.fillRect(i.x,n,l+(a+e)/2-l/2-i.x,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)):(a+e)/2+l/2>=i.width&&i.x<(a+e)/2-l/2&&(t.fillRect((a+e)/2-l/2,n,i.width-(a+e)/2+l/2,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)))}}}}!function(t,e,n,r,o){if(!n.canClipArrowhead)return;if(e.x2-e.x1<5)return;if(e.forward){const i=Math.ceil(e.x2+et);i<=r.width+n.stackheight/2&&(t.fillStyle="white",t.beginPath(),t.moveTo(i-n.stackheight/2,o),t.lineTo(i,o),t.lineTo(i,o+n.stackheight/2),t.lineTo(i-n.stackheight/2,o),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i-n.stackheight/2,o+n.stackheight),t.lineTo(i,o+n.stackheight),t.lineTo(i,o+n.stackheight/2),t.lineTo(i-n.stackheight/2,o+n.stackheight),t.closePath(),t.fill())}else{const i=e.x1;i>=r.x&&(t.fillStyle="white",t.beginPath(),t.moveTo(i+n.stackheight/2,o),t.lineTo(i,o),t.lineTo(i,o+n.stackheight/2),t.lineTo(i+n.stackheight/2,o),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i+n.stackheight/2,o+n.stackheight),t.lineTo(i,o+n.stackheight),t.lineTo(i,o+n.stackheight/2),t.lineTo(i+n.stackheight/2,o+n.stackheight),t.closePath(),t.fill())}}(t,e,r,i,n),e.rnext&&(i.to_qual||e.x2-e.x1>=20&&r.stackheight>=7&&(t.font=Math.min(12,Math.max(7,r.stackheight-4))+"pt Arial",t.fillStyle="white",t.fillText((o.nochr?"chr":"")+e.rnext,(e.x1+e.x2)/2,n+r.stackheight/2,e.x2-e.x1)))}function Nt(t,e,n,r){for(const[t,n]of e.regions.entries()){if(!n.to_printnt)continue;const e=new Set;for(const o of r)for(const r of o.segments){if(r.ridx!=t)continue;const o=r.boxes.filter((t=>"I"==t.opr));if(o.length)for(const t of o)e.add(n.x+n.scale(t.start))}}for(const n of r)for(const r of n.segments){const o=e.regions[r.ridx],i=r.boxes.filter((t=>"I"==t.opr));if(i.length){t.font=Math.max(12,e.stackheight-2)+"pt Arial";for(const s of i){const i=o.x+o.scale(s.start);s.qual?t.fillStyle=$(s.qual.reduce(((t,e)=>t+e),0)/s.qual.length/tt):t.fillStyle=z;const a=1==s.s.length?s.s:s.s.length;t.fillText(a,i,n.y+e.stackheight*(r.on2ndrow||0)+e.stackheight/2)}}}}async function St(t,e,n){const r=_t(t.qual),o=['<td style="color:black;text-align:left">Read</td>'];for(const e of t.boxes)for(let n=0;n<e.len;n++){t.seq[e.cidx+n];o.push('<td style="background:'+S(r[e.cidx+n]/tt)+'">'+t.seq[e.cidx+n]+"</td>")}const i=[];i.push('<li><span style="background:#6B4423;color:white">This segment in template is unmapped</span></li>'),1&t.flag&&i.push("<li>Template has multiple segments</li>"),2&t.flag&&i.push("<li>Each segment properly aligned</li>"),16&t.flag&&i.push("<li>Reverse complemented</li>"),32&t.flag&&i.push("<li>Next segment in the template is reverse complemented</li>"),64&t.flag&&i.push("<li>This is the first segment in the template</li>"),128&t.flag&&i.push("<li>This is the last segment in the template</li>"),256&t.flag&&i.push("<li>Secondary alignment</li>"),512&t.flag&&i.push("<li>Not passing filters</li>"),1024&t.flag&&i.push("<li>PCR or optical duplicate</li>"),2048&t.flag&&i.push("<li>Supplementary alignment</li>");let s={seq:t.seq,alignment:`<table style="border-spacing:0px;border-collapse:separate;text-align:center">\n\t\t\t <tr style="color:white">${o.join("")}</tr>\n\t\t\t</table>`,info:`<div style='margin-top:10px'>\n\t\t\t<span style="opacity:.5;font-size:.7em">TEMPLATE</span>: ${Math.abs(t.seq.length)} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">CIGAR</span>: ${t.cigarstr}\n\t\t\t<span style="opacity:.5;font-size:.7em">FLAG</span>: ${t.flag}\n\t\t\t<span style="opacity:.5;font-size:.7em">NAME: ${t.qname}</span>\n\t\t </div>\n\t\t <ul style='padding-left:15px'>${i.join("")}</ul>`};return t.discord_unmapped2&&(s.unmapped_mate=!0),s}async function At(t,e,n){const r=t.boxes[0].start,o=t.boxes[t.boxes.length-1],i=o.start+o.len,s=await vt(e,n.chr+":"+(r+1)+"-"+i),a=_t(t.qual),l=["<td>Reference</td>"],c=['<td style="color:black;text-align:left">Read</td>'];for(const e of t.boxes)if("H"!=e.opr)if("I"!=e.opr)if("D"!=e.opr&&"N"!=e.opr)if("S"!=e.opr)if("M"!=e.opr&&"="!=e.opr&&"X"!=e.opr&&"*"!=e.opr);else for(let n=0;n<e.len;n++){const o=s[e.start-r+n],i=t.seq[e.cidx+n];l.push("<td>"+o+"</td>"),"*"==t.qual?c.push('<td style="color:black;background:'+(o.toUpperCase()==i.toUpperCase()?S:E)+'">'+t.seq[e.cidx+n]+"</td>"):c.push('<td style="background:'+(o.toUpperCase()==i.toUpperCase()?S:E)(a[e.cidx+n]/tt)+'">'+t.seq[e.cidx+n]+"</td>")}else for(let n=0;n<e.len;n++)l.push("<td>"+s[e.start-r+n]+"</td>"),"*"==t.qual?c.push('<td style="background:'+P(1)+'">'+t.seq[e.cidx+n]+"</td>"):c.push('<td style="background:'+P(a[e.cidx+n]/tt)+'">'+t.seq[e.cidx+n]+"</td>");else if(e.len>=20)l.push('<td style="font-size:.8em;opacity:.5;white-space:nowrap">'+e.len+" bp</td>"),c.push('<td style="color:black;white-space:nowrap">-----------</td>');else for(let t=0;t<e.len;t++)l.push("<td>"+s[e.start-r+t]+"</td>"),c.push('<td style="color:black">-</td>');else for(let n=e.cidx;n<e.cidx+e.len;n++)l.push("<td>-</td>"),"*"==t.qual?c.push('<td style="color:#47FFFC;background:white">'+t.seq[n]+"</td>"):c.push('<td style="color:#47FFFC;background:'+S(a[n]/tt)+'">'+t.seq[n]+"</td>");let u=0,f=0,d=[],h=[],p=0;for(const e of t.boxes)u=f,f+=e.len,"S"==e.opr&&(p=1,d.push(u),h.push(f));const m=[];t.rnext&&m.push('<li>Next segment on <span style="background:#d48b37">'+(n.nochr?"chr":"")+t.rnext+", "+t.pnext+"</span></li>"),t.discord_wrong_insertsize&&t.discord_orientation?m.push('<li><span style="background:#3B7A57;color:white">Wrong insert size</span> mate position: '+t.pnext+'</li><li><span style="background:'+'#fc6df3;color:white">Segments also having wrong orientation</span> '+t.discord_orientation_direction+"</li>"):t.discord_wrong_insertsize?m.push('<li><span style="background:#3B7A57;color:white">Wrong insert size</span> mate position: '+t.pnext+"</li>"):t.discord_orientation?m.push('<li><span style="background:#fc6df3;color:white">Segments having wrong orientation</span> '+t.discord_orientation_direction+"</li>"):t.discord_unmapped2&&m.push('<li><span style="background:#6B4423;color:white">Other segment in template is unmapped</span></li>'),1&t.flag&&m.push("<li>Template has multiple segments</li>"),2&t.flag&&m.push("<li>Each segment properly aligned</li>"),16&t.flag&&m.push("<li>Reverse complemented</li>"),32&t.flag&&m.push("<li>Next segment in the template is reverse complemented</li>"),64&t.flag&&m.push("<li>This is the first segment in the template</li>"),128&t.flag&&m.push("<li>This is the last segment in the template</li>"),256&t.flag&&m.push("<li>Secondary alignment</li>"),512&t.flag&&m.push("<li>Not passing filters</li>"),1024&t.flag&&m.push("<li>PCR or optical duplicate</li>"),2048&t.flag&&m.push("<li>Supplementary alignment</li>");let g={seq:t.seq,alignment:`<table style="border-spacing:0px;border-collapse:separate;text-align:center;font-family:courier">\n\t\t\t <tr style="opacity:.6">${l.join("")}</tr>\n\t\t\t <tr style="color:white">${c.join("")}</tr>\n\t\t\t</table>`,info:`<div style='margin-top:10px'>\n\t\t\t<span style="opacity:.5;font-size:.7em">CHR</span>: ${n.chr.replace("chr","")},\n\t\t\t<span style="opacity:.5;font-size:.7em">START</span>: ${t.segstart_original+1},\n\t\t\t<span style="opacity:.5;font-size:.7em">STOP</span>: ${i},\n\t\t\t<span style="opacity:.5;font-size:.7em">READ LENGTH</span>: ${t.seq.length} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">TEMPLATE LENGTH</span>: ${Math.abs(t.tlen)} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">CIGAR</span>: ${t.cigarstr}\n\t\t\t<span style="opacity:.5;font-size:.7em">FLAG</span>: ${t.flag}\n\t\t\t<span style="opacity:.5;font-size:.7em">NAME: ${t.qname}</span>\n\t\t </div>\n\t\t <ul style='padding-left:15px'>${m.join("")}</ul>`,start_readpos:r+1,boxes:t.boxes,readpanel_DN_maxlength:20};return 1==p&&(g.soft_starts=d,g.soft_stops=h),t.discord_unmapped2&&(g.unmapped_mate=!0),g}function Mt(t){const e=i.createHmac("md5",it),n=[t.get("X-Auth-Token")||t.cookies.sessionid,t.query.gdcFileUUID,t.query.gdcFilePosition];return e.update(n.join("")).digest("hex")+".bam"}async function Tt(t){const e=t.query.regions;if(!Array.isArray(e)||0==e.length)throw"req.query.regions[] not non-empty array";const n=[];for(const r of e){const e=await Ct(r.chr,r.start,r.stop,t.get("X-Auth-Token"),t.query.gdcFileUUID,Mt(t),t.cookies.sessionid);n.push({filesize:e})}return n}async function Ct(t,e,n,r,o,i,s){const f={compression:!1};s?f.Cookie=`sessionid=${s}`:f["X-Auth-Token"]=r;const h=c.join(x.cachedir_bam,i),p=ot+"/slicing/view/"+o+"?region="+t+":"+e+"-"+n;try{if(await d.file_not_exist(h)&&(await l(a.stream(p,{method:"GET",headers:f}),u.createWriteStream(h)),await d.file_not_exist(h)))throw"BAM file slice is not found after downloading";const t=h+".bai";if(await d.file_not_exist(t)&&(await async function(t){await d.get_lines_bigfile({isbam:!0,args:["index",t],callback:()=>{}})}(h),await d.file_not_exist(t)))throw"index file is missing after indexing";const e=await u.promises.stat(h);return _(e.size,!0)}catch(t){throw t.stack&&console.log(t.stack),"Error with BAM slicing: "+(t.message||t)}}t.exports=t=>async(e,n)=>{try{if(delete e.query.isFileSlice,e.query.gdcFileUUID){const t=e.cookies.sessionid,n=e.get("X-Auth-Token");if(!n&&!t)throw"GDC token or sessionid missing";await w(e.query.gdcFileUUID,n,t),e.query.file=Mt(e),e.query.isFileSlice=!0}if(e.query.downloadgdc)return void n.send(await Tt(e));if(e.query.clientdownloadgdcslice){if(!e.query.file||!e.query.isFileSlice)throw"invalid query";const t=c.join(x.cachedir_bam,e.query.file),r=await u.promises.readFile(t);return n.writeHead(200,{"Content-Type":"application/octet-stream","Content-Disposition":"attachment; filename=gdc.bam","Content-Length":r.length}),void n.end(Buffer.from(r,"binary"))}if(!e.query.genome)throw".genome missing";const o=t[e.query.genome];if(!o)throw"invalid genome";if(e.query.getread)return void n.send(await async function(t,e){if(!e.query.chr)throw".chr missing";if(!e.query.qname)throw".qname missing";if(e.query.qname=decodeURIComponent(e.query.qname),!e.query.start)throw".start missing";if(!e.query.stop)throw".stop missing";const n={chr:e.query.chr,start:Number(e.query.start),stop:Number(e.query.stop),scale:()=>{},ntwidth:10};if(!Number.isInteger(n.start))throw".start not integer";if(!Number.isInteger(n.stop))throw".stop not integer";const o=await async function(t,e){let n,o,i,s,a,l,u,f,p;if(t.query.isFileSlice)a=c.join(x.cachedir_bam,t.query.file),await lt(t,a);else{if([s,a,l]=r.fileurl(t),s)throw s;i=l?await d.cache_index(a,t.query.indexURL||a+".bai"):null}if(t.query.unknownorder&&(u=Number(t.query.readstart),f=Number(t.query.readstop),Number.isNaN(u)||Number.isNaN(f)))throw"readstart/stop not provided for read with unknown order";if(await d.get_lines_bigfile({isbam:!0,args:["view",a,(t.query.nochr?t.query.chr.replace("chr",""):t.query.chr)+":"+e.start+"-"+e.stop],dir:i,callback:(r,i)=>{if(r.split("\t")[0]!=t.query.qname)return;const s=mt({sam_info:r,keepallboxes:!0,keepmatepos:!0,keepunmappedread:!0},e);if(s&&(!t.query.show_unmapped||!s.discord_unmapped2))if(t.query.show_unmapped&&t.query.getfirst){if(s.islast)return i.kill(),void(p=[s])}else if(t.query.show_unmapped&&t.query.getlast){if(s.isfirst)return i.kill(),void(p=[s])}else if(t.query.getfirst){if(s.isfirst)return i.kill(),void(p=[s])}else if(t.query.getlast){if(s.islast)return i.kill(),void(p=[s])}else if(t.query.unknownorder){if(s.segstart==u&&s.segstop==f)return i.kill(),void(p=[s])}else if(s.isfirst?n=s:s.islast&&(o=s),n&&o)return i.kill(),void(p=[n,o])}}),p){if(t.query.altseqs){const e={query_seq:p[0].seq,refseqs:t.query.refseqs,altseqs:t.query.altseqs,cigar_seq:p[0].cigarstr,start_position:p[0].segstart,ref_positions:t.query.ref_positions,refalleles:t.query.refalleles,altalleles:t.query.altalleles},n=(await h("align",JSON.stringify(e))).split("\n");let r;for(let t of n)t.includes("Final_output:")?r=JSON.parse(t.replace("Final_output:","")):console.log(t);p.alignments=r}return p}p=[],n&&p.push(n);o&&p.push(o);return p.length?p:null}(e,n);if(!o){if(e.query.show_unmapped)throw"mate not found";throw"read not found"}const i=[];for(const n of o)n.discord_unmapped1?i.push(await St(n,t,e.query)):i.push(await At(n,t,e.query));o.alignments&&(i[0].alignments=o.alignments);return{lst:i}}(o,e));const i=x.debugmode?new Date:null,s=await async function(t,e){let n;if(e.query.isFileSlice)n={genome:t,file:c.join(x.cachedir_bam,e.query.file),asPaired:e.query.asPaired,getcolorscale:e.query.getcolorscale,devicePixelRatio:e.query.devicePixelRatio?Number(e.query.devicePixelRatio):1},await lt(e,n.file);else{const[o,i,s]=r.fileurl(e);if(o)throw o;n={genome:t,file:i,asPaired:e.query.asPaired,getcolorscale:e.query.getcolorscale,devicePixelRatio:e.query.devicePixelRatio?Number(e.query.devicePixelRatio):1},s&&(n.dir=await d.cache_index(i,e.query.indexURL||i+".bai"))}if(e.query.pileupheight&&(n.pileupheight=Number(e.query.pileupheight),Number.isNaN(n.pileupheight)))throw".pileupheight is not integer";e.query.drop_pcrduplicates&&(n.drop_pcrduplicates=!0);if(e.query.variant){n.diff_score_plotwidth=Number(e.query.diff_score_plotwidth),e.query.max_diff_score&&(n.max_diff_score=Number(e.query.max_diff_score),n.min_diff_score=Number(e.query.min_diff_score));const t=e.query.variant.split(".");if(n.strictness=e.query.strictness,!Number.isInteger(t.length%4))throw"invalid variant, not chr.pos.ref.alt";n.alleleAlreadyUpdated=e.query.alleleAlreadyUpdated,n.alleleAlreadyUpdated&&(n.altseqs=e.query.altseqs,n.refseqs=e.query.refseqs,n.altalleles=e.query.altalleles,n.refalleles=e.query.refalleles,n.leftflankseqs=e.query.leftflankseqs,n.rightflankseqs=e.query.rightflankseqs,n.ref_positions=e.query.ref_positions);const r=t.length/4,o=[];for(let e=0;e<r;e++)o.push({chr:t[4*e],pos:Number(t[4*e+1]),ref:t[4*e+2],alt:t[4*e+3]});if(n.variant=o,e.query.alignOneGroup&&(n.alignOneGroup=e.query.alignOneGroup),Number.isNaN(n.variant.pos))throw"variant pos not integer"}else if(e.query.sv){const t=e.query.sv.split(".");if(t.length<6)throw"invalid sv, not chrA.posA.chrB.posB";if(n.sv={chrA:t[0],startA:Number(t[1]),strandA:Number(t[2]),chrB:t[3],startB:Number(t[4]),strandB:Number(t[5])},Number.isNaN(n.sv.startA))throw"sv.startA not integer";if(Number.isNaN(n.sv.startB))throw"sv.startB not integer"}if(Number.isFinite(Number(e.query.stackstart))){if(!e.query.stackstop)throw".stackstop missing";if(n.partstack={start:Number(e.query.stackstart),stop:Number(e.query.stackstop)},Number.isNaN(n.partstack.start))throw".stackstart not integer";if(Number.isNaN(n.partstack.stop))throw".stackstop not integer";if(!e.query.grouptype)throw".grouptype required for partstack";n.grouptype=e.query.grouptype}e.query.gdc||(e.query.nochr?n.nochr="string"==typeof e.query.nochr?JSON.parse(e.query.nochr):e.query.nochr:n.nochr=await d.bam_ifnochr(n.file,t,n.dir));if(n.regions=e.query.regions,!Array.isArray(n.regions)||0==n.regions.length)throw"q.regions[] not non-empty array";let o=0;for(const t of n.regions){if(!t.chr)throw".chr missing from a region";if(!Number.isInteger(t.start))throw".start not integer of a region";if(!Number.isInteger(t.stop))throw".stop not integer of a region";t.scale=e=>Math.ceil(t.width*(e-t.start)/(t.stop-t.start)),t.ntwidth=t.width/(t.stop-t.start),o=Math.max(o,t.ntwidth)}return n.stacksegspacing=Math.max(2,5*o),n.readcount_skipped=0,n}(o,e);n.send(await async function(t){await async function(t){if(t.variant){let e=0,n=0,r=0,o=t.variant[0].pos,i=t.variant[0].pos+Math.max(t.variant[0].ref.length,t.variant[0].alt.length);for(const s of t.variant){const t=Math.abs(s.pos-Math.max(s.ref.length,s.alt.length));t>e&&(e=t,n=r),o>s.pos&&(o=s.pos),i<s.pos+Math.max(s.ref.length,s.alt.length)&&(i=s.pos+Math.max(s.ref.length,s.alt.length)),r+=1}e=Math.floor(1.5*Math.max(t.variant[n].ref.length,t.variant[n].alt.length));const s={chr:t.variant[0].chr,start:o-e,stop:i+e};return await ut(t,[s]),await ft(s,t),void(t.regions[0].lines=s.lines)}await ut(t,t.regions);for(const e of t.regions)await ft(e,t)}(t),t.totalnumreads=t.regions.reduce(((t,e)=>t+e.lines.length),0);const e={nochr:t.nochr,count:{r:t.totalnumreads},groups:[]};t.read_limit_reached&&(e.count.read_limit_reached=t.read_limit_reached);t.canvaswidth=t.regions[t.regions.length-1].x+t.regions[t.regions.length-1].width;{const n=await async function(t){const e=[],n=[];let r=0;for(const o of t.regions){for(const t of o.lines)e.push({sam_info:t,tempscore:""});r=o.x+o.width,n.push(r)}if(0==e.length)return{groups:[{type:v.type_all,regions:v.duplicateRegions(t.regions),templates:e,messages:[],partstack:t.partstack,widths:n}]};if(t.variant){if(1==t.regions.length)return await y(t,e,n);console.log("Indel pipeline works only in single region. Please check!")}if(t.sv&&t.regions.length>1)return async function(t,e,n){const r=v.make_type2group(e),o=[];for(let t=0;t<e.regions.length;t++){const n=e.regions[t],r=(await d.get_fasta(e.genome,n.chr+":"+n.start+"-"+n.stop)).split("\n").slice(1).join("").toUpperCase(),i=[];for(const e of n.lines)i.push({sam_info:e,tempscore:"",ridx:t});const s={refseq:r,start:n.start,stop:n.stop,entries:i};0==t?(s.chr=e.sv.chrA,s.pos=e.sv.startA):1==t?(s.chr=e.sv.chrB,s.pos=e.sv.startB):console.log("More than two regions, please check"),o.push(s)}const i=new Date,s=(await h("sv",JSON.stringify(o))).split("\n"),a=new Date;let l,c;console.log("Time taken to run rust SV pipeline:",a-i,"ms");for(let t of s)t.includes("multi_region_templates:")?l=JSON.parse(t.replace("multi_region_templates:","")):t.includes("single_region_templates:")&&(c=JSON.parse(t.replace("single_region_templates:","")));if(!e.grouptype||"support_sv"==e.grouptype)for(const t of l)r[v.type_supportsv].templates.push(t);if(!e.grouptype||"support_ref"==e.grouptype)for(const t of c)r[v.type_supportref].templates.push(t);const u=[];for(const t in r){const e=r[t];0!=e.templates.length&&(t==v.type_supportsv?1==e.templates.length?e.messages.push({isheader:!0,t:e.templates.length+" read supporting SV/fusion"}):e.messages.push({isheader:!0,t:e.templates.length+" reads supporting SV/fusion"}):t==v.type_supportref&&e.messages.push({isheader:!0,t:e.templates.length+" reads supporting reference allele"}),e.widths=n,u.push(e))}return{groups:u}}(0,t,n);return{groups:[{type:v.type_all,regions:v.duplicateRegions(t.regions),templates:e,messages:[],partstack:t.partstack,widths:n}]}}(t);t.groups=n.groups,t.variant&&(e.ref_alleles=n.refalleles,e.alt_alleles=n.altalleles,e.allele_positions=n.ref_positions,e.strand_probability=n.strand_probability,e.alternate_forward_count=n.alternate_forward_count,e.reference_forward_count=n.reference_forward_count,e.alternate_reverse_count=n.alternate_reverse_count,e.reference_reverse_count=n.reference_reverse_count,1==n.strand_significance&&(e.strand_significance=!0),t.alleleAlreadyUpdated||(e.refseqs=n.refseqs,e.altseqs=n.altseqs,e.leftflankseqs=n.leftflankseqs,e.rightflankseqs=n.rightflankseqs,e.ref_positions=n.ref_positions,e.refalleles=n.refalleles,e.altalleles=n.altalleles)),Number.isFinite(t.max_diff_score)&&t.variant?(e.max_diff_score=t.max_diff_score,e.min_diff_score=t.min_diff_score):Number.isFinite(n.max_diff_score)&&(e.max_diff_score=n.max_diff_score,e.min_diff_score=n.min_diff_score),n.refalleleerror&&(e.refalleleerror=n.refalleleerror)}if(0==e.count.r)throw"No reads in view range.";if(t.alignOneGroup){const e=t.groups.find((e=>e.type==t.alignOneGroup));if(!e)throw"cannot find group for realignment";let n=pt(t,e);return n=yt(e,t,n),await async function(t,e,n){let r;if(e.variant)if("support_ref"==t.type){let o=e.leftflankseqs[0].length;r=t.partstack?await ct(n,o,t.partstack.start,t.partstack.stop,e.refseqs[0]):await ct(n,o,0,0,e.refseqs[0])}else if("support_no"==t.type){let o=e.leftflankseqs[0].length;r=t.partstack?await ct(n,o,t.partstack.start,t.partstack.stop):await ct(n,o)}else if("support_amb"==t.type)console.log("Realignment of reads in ambiguous group is not currently implemented");else if(t.type.includes("support_alt")){for(let o=0;o<e.variant.length;o++)if(t.type=="support_alt"+o.toString()){let i=e.leftflankseqs[o].length;r=t.partstack?await ct(n,i,t.partstack.start,t.partstack.stop,e.altseqs[o]):await ct(n,i,0,0,e.altseqs[o])}}else console.log("Unaccounted group, please check");return{alignmentData:r}}(e,t,n)}let n=[];for(const r of t.groups){let o=pt(t,r);o=yt(r,t,o),await gt(r,t,o),await ht(o,t),bt(r,o,t);const i={type:r.type,width:t.canvaswidth,height:r.canvasheight,stackheight:r.stackheight,stackcount:r.stacks.length,allowpartstack:r.allowpartstack,templatebox:r.returntemplatebox,count:{r:o.reduce(((t,e)=>t+e.segments.length),0)}},s=p(t.canvaswidth*t.devicePixelRatio,r.canvasheight*t.devicePixelRatio),a=s.getContext("2d");t.devicePixelRatio>1&&a.scale(t.devicePixelRatio,t.devicePixelRatio),a.textAlign="center",a.textBaseline="middle",i.messages=r.messages,i.messagerowheights=0;for(const e of o)kt(a,e,r,t);Nt(a,r,t,o),t.asPaired&&(i.count.t=o.length),t.variant&&(i.diff_scores_img=await st(t,r,o,e.max_diff_score,e.min_diff_score),"support_alt0"==i.type?i.group_color=W:"support_alt1"==i.type?i.group_color=J:"support_alt2"==i.type?i.group_color=V:"support_alt3"==i.type?i.group_color=Y:"support_alt4"==i.type?i.group_color=Q:"support_alt5"==i.type?i.group_color=K:"support_ref"==i.type&&(i.group_color=X)),i.src=s.toDataURL(),e.groups.push(i),n=[...n,...o]}t.readcount_skipped&&(e.count.skipped=t.readcount_skipped);t.getcolorscale&&(e.colorscale=function(t){const e=160,n=20,r=1,o=12,i=5,s=100,a=4,l=s+e+10,c=2*o+i+a+4*(n+r),u=p(t.devicePixelRatio*l,t.devicePixelRatio*c),f=u.getContext("2d");t.devicePixelRatio>1&&f.scale(t.devicePixelRatio,t.devicePixelRatio);f.fillStyle="black",f.font=o+"pt Arial",f.textAlign="center",f.fillText("Base quality",s+e/2,o);let d=2*o+i;function h(t,r,o){const i=s,a=f.createLinearGradient(i,o,i+e,o);a.addColorStop(0,r),a.addColorStop(1,t),f.fillStyle=a,f.fillRect(i,o,e,n)}return f.strokeStyle="black",f.beginPath(),f.moveTo(s,d),f.lineTo(s,d+a),f.moveTo(s+e/4,d),f.lineTo(s+e/4,d+a),f.moveTo(s+e/2,d),f.lineTo(s+e/2,d+a),f.moveTo(s+3*e/4,d),f.lineTo(s+3*e/4,d+a),f.moveTo(s+e,d),f.lineTo(s+e,d+a),f.closePath(),f.stroke(),f.fillText(40,s,d),f.fillText(30,s+e/4,d),f.fillText(20,s+e/2,d),f.fillText(10,s+3*e/4,d),f.fillText(0,s+e,d),f.textAlign="left",f.textBaseline="middle",d+=a,f.fillText("Match",0,d+n/2),h(N,q,d),d+=n+r,f.fillStyle="black",f.fillText("Mismatch",0,d+n/2),h(O,j,d),d+=n+r,f.fillStyle="black",f.fillText("Softclip",0,d+n/2),h(I,R,d),d+=n+r,f.fillStyle="black",f.fillText("Insertion",0,d+n/2),h(Z,z,d),{width:l,height:c,src:u.toDataURL()}}(t));if(!t.partstack)if(0==e.count.r);else{if(!t.pileupheight)throw"pileupheight missing";e.pileup_data=await async function(t,e){const n=p(t.canvaswidth*t.devicePixelRatio,t.pileupheight*t.devicePixelRatio),r=n.getContext("2d");t.devicePixelRatio>1&&r.scale(t.devicePixelRatio,t.devicePixelRatio);const o=[];let i=0;for(const[n,r]of t.regions.entries()){o[n]=await dt(t,r),at(n,r,e,o[n]);for(const t of o[n])t&&(i=Math.max(i,t.total))}for(const[e,n]of t.regions.entries()){const s=t.pileupheight/i;for(const i of o[e]){if(!i)continue;const e=(i.position-n.start)*n.ntwidth+n.x,o=n.ntwidth>=1?e:Math.floor(e),a=Math.max(1,n.ntwidth);{r.fillStyle=H;const e=i.total*s;r.fillRect(o,t.pileupheight-e,a,e)}let l=0;if(i.A){r.fillStyle=b.A;const e=i.A*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.C){r.fillStyle=b.C;const e=i.C*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.G){r.fillStyle=b.G;const e=i.G*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.T){r.fillStyle=b.T;const e=i.T*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.softclip){r.fillStyle=R;const e=i.softclip*s;r.fillRect(o,t.pileupheight-l-e,a,e)}}}return{width:t.canvaswidth,maxValue:i,src:n.toDataURL()}}(t,n)}return e}(s)),x.debugmode&&console.log("bam.js time ms",new Date-i)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},8953:(t,e,n)=>{"use strict";n.d(e,{Y:()=>s});n(8171).jStat,n(1017),n(9699).features;const r=n(3856),o=n(1271).run_rust,i=(n(2081).spawn,n(2781).Readable,n(4521),n(2384));n(7147),n(334).clustalo;async function s(t,e,n){const s=t.regions[0].lines[0].split("\t")[9].length;let a=!1,l=[],c=[],u=[],f=[],d=[],h=[],p=[];if(t.alleleAlreadyUpdated)l=t.leftflankseqs,c=t.rightflankseqs,h=t.refseqs,p=t.altseqs,u=t.refalleles,f=t.altalleles,d=t.ref_positions,0!=h[0].toUpperCase().localeCompare((l[0]+u[0]+c[0]).toUpperCase())&&(console.log("Reference allele is not correct for variant 0"),a=!0);else{let e,n,o=0;for(const i of t.variant){let a="",l="";if(!(0!=i.ref.length&&"-"!=i.ref||"-"!=i.alt&&0!=i.alt.length))throw"Both Ref and Alt alleles are missing";if(0==i.ref.length||"-"==i.ref)a=(await r.get_fasta(t.genome,i.chr+":"+i.pos+"-"+i.pos)).split("\n").slice(1).join("").toUpperCase(),l=a+i.alt,i.pos-=1;else if("-"==i.alt||0==i.alt.length){const e=(await r.get_fasta(t.genome,i.chr+":"+i.pos+"-"+i.pos)).split("\n").slice(1).join("").toUpperCase();a=e+i.ref,l=e,i.pos-=1}else l=i.alt,a=i.ref;const c=i.pos,h=a.toUpperCase(),p=l.toUpperCase();0==o?(e=c-s,n=c+a.length+1+s):(c-s<e&&(e=c-s),c+a.length+1+s>n&&(n=c+a.length+1+s)),u.push(h),f.push(p),d.push(c),o+=1}o=0;for(const i of t.variant){const s=(await r.get_fasta(t.genome,i.chr+":"+e+"-"+d[o])).split("\n").slice(1).join("").toUpperCase(),a=(await r.get_fasta(t.genome,i.chr+":"+(d[o]+u[o].length+1)+"-"+n)).split("\n").slice(1).join("").toUpperCase(),m=s+u[o]+a,g=s+f[o]+a;console.log(i.chr+"."+d[o]+"."+u[o]+"."+f[o]),o+=1,l.push(s),c.push(a),h.push(m),p.push(g)}}const m=[];for(let t=0;t<e.length;t++){const n=e[t].sam_info.split("\t");m.push({read_sequence:n[9],start_position:Number(n[3]),cigar:n[5],flag:Number(n[1])})}const g=[];for(let t=0;t<u.length;t++)g.push({ref_position:Number(d[t]),refallele:u[t],altallele:f[t],refseq:h[t],altseq:p[t],leftflankseq:l[t],rightflankseq:c[t]});Number.isFinite(Number(t.strictness))||(t.strictness=1);const y={reads:m,alleles:g,strictness:Number(t.strictness)},v=new Date,b=await o("indel",JSON.stringify(y)),_=new Date;console.log("Time taken to run rust indel pipeline:",_-v,"ms");const w=b.split("\n");let x,k,q,N,S,A,M=0;for(let t of w)t.includes("Final_output:")?x=JSON.parse(JSON.parse(t.replace("Final_output:",""))):1==u.length&&t.includes("fisher_strand:")?(k=JSON.parse(t.replace("fisher_strand:","")),q=k.alternate_forward_count,N=k.alternate_reverse_count,S=k.reference_forward_count,A=k.reference_reverse_count,M=k.p_value):console.log(t);let T=!1;1==t.variant.length&&M>60&&(T=!0);const C=i.make_type2group(t);t.variant.length;let j=1;for(let n=0;n<x.length;n++){const r=x[n],o=r.read_number,s=r.categories,a=r.categories[0],l=[];if(s.length>1){for(let t=1;t<s.length;t++)l.push(s[t]);s.length-1>j&&(j=s.length-1)}if(a.includes("alt"))for(let n=0;n<t.variant.length;n++)a=="alt"+n.toString()&&C[i.type_supportalt+n.toString()]&&(e[o].tempscore=["alt"+n.toString()],C[i.type_supportalt+n.toString()].templates.push(e[o]));else"ref"==a?C[i.type_supportref]&&(e[o].tempscore=["ref"],C[i.type_supportref].templates.push(e[o])):"none"==a?C[i.type_supportno]&&(e[o].tempscore=l,C[i.type_supportno].templates.push(e[o])):"amb"==a?C[i.type_supportamb]&&(e[o].tempscore=l,C[i.type_supportamb].templates.push(e[o])):console.log("Unaccounted group, please check")}const O=[];for(const e in C){const r=C[e];if(0!=r.templates.length){if(e.includes(i.type_supportalt))for(let n=0;n<t.variant.length;n++)e==i.type_supportalt+n.toString()&&(1==t.variant.length?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting the alternative allele"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting the alternative allele"}):1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read support the alternative allele with "+f[n]+" sequence"}):r.messages.push({isheader:!0,t:r.templates.length+" reads support the alternative allele with "+f[n]+" sequence"}));else e==i.type_supportamb?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" ambiguous read"}):r.messages.push({isheader:!0,t:r.templates.length+" ambiguous reads"}):e==i.type_supportref?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting the reference allele"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting the reference allele"}):e==i.type_supportno?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting neither reference nor alternative alleles"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting neither reference nor alternative alleles"}):console.log("Unaccounted group, please check");r.widths=n,O.push(r)}}const E=[];for(let t=0;t<O.length;t++)O[t].type.includes("support_alt")&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_ref"==O[t].type&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_no"==O[t].type&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_amb"==O[t].type&&E.push(O[t]);return{groups:E,refalleleerror:a,ref_positions:d,refalleles:u,altalleles:f,max_diff_score:j,min_diff_score:0,strand_probability:M,strand_significance:T,refseqs:h,altseqs:p,leftflankseqs:l,rightflankseqs:c,alternate_forward_count:q,alternate_reverse_count:N,reference_forward_count:S,reference_reverse_count:A}}},1270:(t,e,n)=>{const r=n(9699),o=n(3856),i=n(6718).createCanvas,s=n(2273).basecolor;t.exports=async(t,e)=>{try{const[n,a,l]=r.fileurl(t);if(n)throw n;let c=t.query.usegrade;const u=Number(t.query.allheight),f=Number(t.query.fineheight),d=Number(t.query.fineymax),h=Number(t.query.midpad),p=Number(t.query.regionspace),m=Number(t.query.width);if(!Number.isInteger(u))throw"allheight is not integer";if(!Number.isInteger(f))throw"fineheight is not integer";if(!Number.isInteger(d))throw"fineymax is not integer";if(!Number.isInteger(h))throw"midpad is not integer";if(!Number.isInteger(p))throw"regionspace is not integer";if(!Number.isFinite(m))throw"width is not a number";const g="string"==typeof t.query.rglst?JSON.parse(t.query.rglst):t.query.rglst;if(!g)throw"no rglst[]";if(!Array.isArray(g))throw"rglst is not an array";if(0==g.length)throw"empty rglst";for(const t of g)t.reverse?t.scale=e=>Math.ceil(t.width*(t.stop-e)/(t.stop-t.start)):t.scale=e=>Math.ceil(t.width*(e-t.start)/(t.stop-t.start));let y;l&&(y=await o.cache_index(a,t.query.indexURL));for(const t of g){t.items=[];let e=0;await o.get_lines_bigfile({args:[a,t.chr+":"+t.start+"-"+t.stop],dir:y,callback:n=>{const r=n.split("\t");let o;try{o=JSON.parse(r[2])}catch(t){return void e++}const i=Number.parseInt(r[1]);t.items.push({pos:i,data:o})}})}const v=u+h+f,b=i(m,v),_=g.reduce(((t,e)=>t+e.items.length),0),w=b.getContext("2d");if(0==_)return w.font="15px Arial",w.fillStyle="#aaa",w.textAlign="center",w.textBaseline="middle",w.fillText("No data in view range",m/2,v/2),void e.send({src:b.toDataURL()});let x=null;if(!c){const t=new Set;for(const e of g)for(const n of e.items)for(const e in n.data)t.add(e);if(x=[...t],x.length>0&&(c=x[0]),!c)return void e.send({src:b.toDataURL()})}let k=0;for(const t of g)for(const e of t.items)if(e.data[c]){let t=0;for(const n in e.data[c])t+=e.data[c][n];k=Math.max(k,t)}const q="#ededed";let N=0;const S=u/k,A=f/d;for(const t of g){const e=t.width/(t.stop-t.start);for(const n of t.items){const r=n.data[c];if(!r)continue;const o=t.scale(n.pos);let i=0;const a=[];for(const t in r)a.push({nt:t,v:r[t]}),i+=r[t];w.fillStyle=q;const l=S*(k-i);if(w.fillRect(N+o,l,e,S*i),a.length>1){a.sort(((t,e)=>e.v-t.v));for(let t=1;t<a.length;t++){let n=0;for(let e=0;e<t;e++)n+=a[e].v;w.fillStyle=s[a[t].nt],w.fillRect(N+o,l+S*n,e,S*a[t].v)}}w.fillStyle=q;const f=u+h+A*(d-Math.min(i,d));if(w.fillRect(N+o,f,e,A*Math.min(i,d)),a.length>1)for(let t=1;t<a.length;t++){let n=0;for(let e=0;e<t;e++)n+=a[e].v;w.fillStyle=s[a[t].nt],w.fillRect(N+o,f+A*(d-Math.min(d,i-n)),e,A*Math.min(d,a[t].v))}}N+=t.width+p}e.send({src:b.toDataURL(),allgrades:x,usegrade:c,allmax:k})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}},2388:(t,e,n)=>{const r=n(9699),o=n(1017),i=(n(7147),n(3856)),s=n(6718).createCanvas,a=n(334);async function l(t,e,n){const o={rglst:[]};let a=0,l=0;if(t.autoscale){for(const r of t.rglst){const o=(n?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop;await i.get_lines_bigfile({args:[t.file,o],dir:e,callback:t=>{const[e,n,r,o]=t.split("\t");for(const t of o.split(",")){const e=Number(t);a=Math.min(a,e),l=Math.max(l,e)}}})}o.minv=a,o.maxv=l}else a=t.minv,l=t.maxv;const c=r.makeyscale().height(t.barheight).min(a).max(l);for(const r of t.rglst){const u={chr:r.chr,start:r.start,stop:r.stop,width:r.width,reverse:r.reverse,xoff:r.xoff},f=s(r.width,t.barheight),d=f.getContext("2d"),h=(n?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop;await i.get_lines_bigfile({args:[t.file,h],dir:e,callback:e=>{const[n,o,i,s]=e.split("\t"),u=Math.max(Number.parseInt(o),r.start),f=Math.min(Number.parseInt(i),r.stop),h=(r.reverse?r.stop-f:u-r.start)*r.width/(r.stop-r.start),p=(r.reverse?r.stop-u:f-r.start)*r.width/(r.stop-r.start);for(const e of s.split(",")){const n=Number(e);d.fillStyle=n>0?t.pcolor:t.ncolor;const r=c(n),o=Math.max(1,p-h);d.fillRect(h,r.y,o,2),n>l?(d.fillStyle=req.query.pcolor2,d.fillRect(h,0,o,2)):n<a&&(d.fillStyle=req.query.ncolor2,d.fillRect(h,t.barheight-2,o,2))}}}),u.img=f.toDataURL(),o.rglst.push(u)}return o}t.exports=t=>async(e,n)=>{try{const r=e.query,s=t[r.genome];if(!s)throw"unknown genome";let c=null;if(r.file)r.file=o.join(a.tpmasterdir,r.file);else{if(!r.url)throw"file or url missing";c=await i.cache_index(r.url,r.indexURL)}const u=await i.tabix_is_nochr(r.file||r.url,c,s),f=await l(r,c,u);n.send(f)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},8145:(t,e,n)=>{const r=n(9699),o=(n(1017),n(7147),n(3856)),i=n(6718).createCanvas,s=n(2273).nt2aa,a=n(2818).X,l=400,c="rgba(122,103,44,.7)",u="#edad0c",f="rgba(255,0,0,.5)",d="#ccc";function h(t,e,n,r,o){if(!t)return;if(!o.name&&!o.isoform)return;const i=[];o.name&&i.push(o.name),o.isoform&&i.push(o.isoform),t.push({chr:o.chr,start:o.start,stop:o.stop,x1:e,x2:n,y:r,isoform:o.isoform,name:i.join(" ")})}function p(t,e,n,r,o,i){const s=i/2,a=i/2,l=Math.max(i/2,6);if(o-2*s<a)return;const c=Math.ceil((o-2*s)/(a+l));if(c<=0)return;const u="+"==e;let f=Math.ceil(n+(o-a*c-l*(c-1))/2);for(let e=0;e<c;e++)t.beginPath(),u?(t.moveTo(f,r),t.lineTo(f+a,r+i/2),t.moveTo(f+a,r+i/2+1),t.lineTo(f,r+i)):(t.moveTo(f+a,r),t.lineTo(f,r+i/2),t.moveTo(f,r+i/2+1),t.lineTo(f+a,r+i)),t.stroke(),f+=a+l}t.exports=t=>async(e,n)=>{try{n.send(await async function(t,e){const[n,m,g]=r.fileurl(t);if(n)throw n;let y,v,b,_,w;if(t.query.fileIsBigbed=await o.testIfFileIsBigbed(m),t.query.getdata)t.query.getBED;else{if(y=Number(t.query.stackheight),v=Number(t.query.stackspace),b=Number(t.query.regionspace),_=Number(t.query.width),Number.isNaN(y))throw"stackheight is not integer";if(w=Math.max(10,y-2),Number.isNaN(v))throw"stackspace is not integer";if(Number.isNaN(b))throw"regionspace is not integer";if(Number.isNaN(_))throw"width is not a number"}if(t.query.usevalue){if(!t.query.usevalue.key)throw".key missing from .usevalue";if(t.query.usevalue.dropBelowCutoff&&(t.query.usevalue.dropBelowCutoff=Number(t.query.usevalue.dropBelowCutoff),Number.isNaN(t.query.usevalue.dropBelowCutoff)))throw".usevalue.dropBelowCutoff is not number"}if(t.query.bplengthUpperLimit&&(t.query.bplengthUpperLimit=Number(t.query.bplengthUpperLimit),Number.isNaN(t.query.bplengthUpperLimit)))throw"bplengthUpperLimit not number";if(!t.query.rglst)throw"no rglst[]";if(!Array.isArray(t.query.rglst))throw"rglst is not an array";if(0==t.query.rglst.length)throw"empty rglst";for(const e of t.query.rglst)e.reverse?e.scale=t=>Math.ceil(e.width*(e.stop-t)/(e.stop-e.start)):e.scale=t=>Math.ceil(e.width*(t-e.start)/(e.stop-e.start));const x=t.query.color||"#3D7A4B",k=t.query.gmregion||null,q=t.query.isoform,N=t.query.onerow,S=t.query.categories||null,A=t.query.__isgene;let M;!t.query.fileIsBigbed&&g&&(M=await o.cache_index(m,t.query.indexURL));const T=await async function(t,e,n,r,i){let s;if(r){const l=[];if(t.fileIsBigbed){const n=await o.query_bigbed_by_coord(e,r.chr,r.start,r.stop);for(const e of n){const n=e.split("\t"),r=a(n);r.chr=n[0],r.start=Number(n[1]),r.stop=Number(n[2]),r.rglst=[];for(let e=0;e<t.rglst.length;e++){const n=t.rglst[e];Math.max(r.start,n.start)<Math.min(r.stop,n.stop)&&r.rglst.push({idx:e})}0!=r.rglst.length&&l.push(r)}}else await o.get_lines_bigfile({args:[e,r.chr+":"+r.start+"-"+r.stop],dir:n,callback:e=>{const n=e.split("\t");let r={};if(t.getBED)r.rest=n.slice(3);else if(n[3])try{r=JSON.parse(n[3])}catch(t){return void(s=e)}if(!r.isoformonly||r.isoformonly==i){r.chr=n[0],r.start=Number(n[1]),r.stop=Number(n[2]),r.rglst=[];for(let e=0;e<t.rglst.length;e++){const n=t.rglst[e];Math.max(r.start,n.start)<Math.min(r.stop,n.stop)&&r.rglst.push({idx:e})}0!=r.rglst.length&&l.push(r)}}});if(s)throw"Line with invalid JSON: "+s;return[l]}const l=[];for(const[r,i]of t.rglst.entries()){const c=[];if(t.fileIsBigbed){const t=await o.query_bigbed_by_coord(e,i.chr,i.start,i.stop);for(const e of t){const t=e.split("\t"),n=a(t);n.chr=t[0],n.start=Number(t[1]),n.stop=Number(t[2]),n.rglst=[{idx:r}],c.push(n)}}else await o.get_lines_bigfile({args:[e,i.chr+":"+i.start+"-"+i.stop],dir:n,callback:e=>{const n=e.split("\t");let o={};if(t.getBED)o.rest=n.slice(3);else if(n[3])try{o=JSON.parse(n[3])}catch(t){return void(s=e)}o.chr=n[0],o.start=Number(n[1]),o.stop=Number(n[2]),o.rglst=[{idx:r}],c.push(o)}});l.push(c)}if(s)throw"Line with invalid JSON: "+s;return l}(t.query,m,M,k,q);let C;t.query.filterByName&&(C=new Set(t.query.filterByName.split(/[\s\n]/).map((t=>t.trim()))));const j=[];for(const e of T)for(const n of e){if(t.query.usevalue){const e=n[t.query.usevalue.key];if(!Number.isFinite(e))continue;if(t.query.usevalue.dropBelowCutoff&&e<t.query.usevalue.dropBelowCutoff)continue}if(!(t.query.bplengthUpperLimit&&n.stop-n.start>t.query.bplengthUpperLimit)){if(C)if(n.isoform){if(!C.has(n.isoform))continue}else{if(!n.name)continue;if(!C.has(n.name))continue}j.push(n)}}if(t.query.getdata)return{items:j};if(0==j.length){const e=i(_*t.query.devicePixelRatio,y*t.query.devicePixelRatio),n=e.getContext("2d");return t.query.devicePixelRatio>1&&n.scale(t.query.devicePixelRatio,t.query.devicePixelRatio),n.font=y+"px Arial",n.fillStyle="#aaa",n.textAlign="center",n.textBaseline="middle",n.fillText("No data in view range",_/2,y/2),{src:e.toDataURL(),height:y}}const O=Math.ceil(y/4)-1;if(N||j.length>=600){const e=j.length<200,n=i(_*t.query.devicePixelRatio,y*t.query.devicePixelRatio),r=n.getContext("2d");t.query.devicePixelRatio>1&&r.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);const o=j.length<=200?[]:null;for(const n of j){const i=S&&n.category&&S[n.category]?S[n.category].color:n.color||x;r.fillStyle=i;for(const i of n.rglst){let s=0;for(let e=0;e<i.idx;e++)s+=t.query.rglst[e].width+b;const a=t.query.rglst[i.idx],l=[];n.utr5&&l.push(...n.utr5),n.utr3&&l.push(...n.utr3),!n.exon||n.coding&&0!=n.coding.length||l.push(...n.exon);for(const t of l){const e=Math.max(a.start,t[0]),i=Math.min(a.stop,t[1]),l=s+a.scale(a.reverse?i:e),c=s+a.scale(a.reverse?e:i);r.fillRect(l,O,Math.max(1,c-l),y-2*O),h(o,l,c,1,n)}const c=[];n.exon?n.coding&&n.coding.length>0&&c.push(...n.coding):c.push([n.start,n.stop]);for(const t of c){const i=Math.max(a.start,t[0]),l=Math.min(a.stop,t[1]),c=s+a.scale(a.reverse?l:i),u=s+a.scale(a.reverse?i:l);r.fillRect(c,0,Math.max(1,u-c),y),h(o,c,u,1,n),n.strand&&e&&(r.strokeStyle="white",p(r,n.strand,c,O,u-c,y-2*O))}}}return{src:n.toDataURL(),height:y,mapisoform:o}}if(t.query.hideItemNames)for(const t of j)delete t.name;let E=null;if(A&&j.length<50){E=[];for(const t of j){const e={};for(const n in t)"canvas"!=n&&"rglst"!=n&&(e[n]=t[n]);E.push(e)}}const R=t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0),I=t.query.translatecoding&&R<3*_;let P;if(I){if(!t.query.genome)throw"genome missing for translating genes";if(P=e[t.query.genome],!P)throw"invalid genome"}const F=[],L=i(10,10);let D=L.getContext("2d");t.query.devicePixelRatio>1&&D.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);D.font="bold "+w+"px Arial";const B=j.length<l,z=j.length<l?[]:null;let Z=!1;k&&(Z=k.reverse);for(const e of t.query.rglst)e.reverse&&(Z=!0);j.sort(((t,e)=>Z?t.stop==e.stop?t.start-e.start:e.stop-t.stop:t.start==e.start?e.stop-t.stop:t.start-e.start));const $=j.some((t=>t.exon)),G=[0];let U=1,H=null;for(const e of j){let n=null,r=null;for(const o of e.rglst){let i=0;for(let e=0;e<o.idx;e++)i+=t.query.rglst[e].width+b;const s=t.query.rglst[o.idx],a=Math.max(e.start,s.start),l=Math.min(e.stop,s.stop);if(a<l){const t=i+s.scale(s.reverse?l:a),e=i+s.scale(s.reverse?a:l);null==n?(n=t,r=e):(n=Math.min(n,t),r=Math.max(r,e))}}if(null==n)continue;e.canvas={start:n,stop:r,stranded:null!=e.strand},e.coding&&I&&(e.willtranslate=!0,F.push(e));let o=n,i=r;if(B){const t=e.name;if(t){e.canvas.namestr=t;const n=D.measureText(t).width;e.canvas.namewidth=n,$?e.canvas.start>=n+1?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):e.canvas.stop+n+1<=_?(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):n>e.canvas.stop-e.canvas.start?e.canvas.start>_-e.canvas.stop?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):(e.canvas.namehover=!0,e.canvas.textalign="left"):Math.min(_,e.canvas.stop)-Math.max(0,e.canvas.start)>=n+20?e.canvas.namein=!0:e.canvas.start>=n+1?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):e.canvas.stop+n+1<=_?(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):e.canvas.namein=!0}}e.canvas.stop-e.canvas.start>.3*_&&(H=[]);for(let t=1;t<=U;t++)if(null==G[t]||G[t]<o){e.canvas.stack=t,G[t]=i;break}null==e.canvas.stack&&(U++,G[U]=i,e.canvas.stack=U),h(z,o,i,e.canvas.stack,e)}L.width=_*t.query.devicePixelRatio;const W=(y+v)*U-v;L.height=W*t.query.devicePixelRatio,D=L.getContext("2d"),t.query.devicePixelRatio>1&&D.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);D.font="bold "+w+"px Arial",D.textBaseline="middle",D.lineWidth=1;for(const e of j){const n=e.canvas;if(!n)continue;const r=S&&e.category&&S[e.category]?S[e.category].color:e.color||x,o=(y+v)*(n.stack-1);D.fillStyle=r,(e.exon||e.rglst.length>1)&&(D.strokeStyle=r,D.beginPath(),D.moveTo(n.start,Math.floor(o+y/2)+.5),D.lineTo(n.stop,Math.floor(o+y/2)+.5),D.stroke());for(const i of e.rglst){let s=0;for(let e=0;e<i.idx;e++)s+=t.query.rglst[e].width+b;const a=t.query.rglst[i.idx],l=[];e.utr3&&l.push(...e.utr3),e.utr5&&l.push(...e.utr5),!e.exon||e.coding&&0!=e.coding.length||l.push(...e.exon);for(const t of l){const n=Math.max(t[0],a.start),i=Math.min(t[1],a.stop);if(n<i){if(e.exon2color)for(const t of e.exon2color)if(n>=t.start&&i<=t.stop){D.fillStyle=t.color;break}const t=s+a.scale(a.reverse?i:n),l=s+a.scale(a.reverse?n:i);D.fillRect(t,o+O,Math.max(1,l-t),y-2*O),e.exon2color&&(D.fillStyle=r)}}const c=[];e.exon?e.coding&&e.coding.length>0&&c.push(...e.coding):c.push([e.start,e.stop]);let u=e.strand;n.stranded&&a.reverse&&(u="+"==e.strand?"-":"+");for(const t of c){const i=Math.max(t[0],a.start),l=Math.min(t[1],a.stop);if(i<l){if(e.exon2color)for(const t of e.exon2color)if(i>=t.start&&l<=t.stop){D.fillStyle=t.color;break}const t=s+a.scale(a.reverse?l:i),c=s+a.scale(a.reverse?i:l);if(D.fillRect(t,o,Math.max(1,c-t),y),e.exon2color&&(D.fillStyle=r),n.stranded&&!e.willtranslate)if(D.strokeStyle="white",n.namein){const e=(c-t-n.namewidth)/2;p(D,u,t,o+O,e,y-2*O),p(D,u,t+e+n.namewidth,o+O,e,y-2*O)}else p(D,u,t,o+O,c-t,y-2*O)}}if(n.stranded&&e.intron){D.strokeStyle=r;for(const t of e.intron){const e=Math.max(t[0],a.start),n=Math.min(t[1],a.stop);if(e<n){const t=s+a.scale(a.reverse?n:e);p(D,u,t,o+O,s+a.scale(a.reverse?e:n)-t,y-2*O)}}}if(H&&e.exon){for(let t=0;t<e.exon.length;t++){const r=e.exon[t];if(r[1]<=a.start||r[0]>=a.stop)continue;const o=Math.max(r[0],a.start),i=Math.min(r[1],a.stop);if(o<i){const l=s+a.scale(a.reverse?i:o),c=s+a.scale(a.reverse?o:i);H.push({chr:e.chr,start:Math.min(r[0],r[1]),stop:Math.max(r[0],r[1]),x1:l,x2:c,y:n.stack,name:"Exon "+(t+1)+"/"+e.exon.length})}}for(let t=1;t<e.exon.length;t++){const r=e.exon["+"==e.strand?t-1:t][1],o=e.exon["+"==e.strand?t:t-1][0];if(o<=a.start||r>=a.stop)continue;const i=Math.max(r,a.start),l=Math.min(o,a.stop);if(i<l){const c=s+a.scale(a.reverse?l:i),u=s+a.scale(a.reverse?i:l);if(u<0)continue;H.push({chr:e.chr,start:r,stop:o,x1:c,x2:u,y:n.stack,name:"Intron "+t+"/"+(e.exon.length-1)})}}}}if(null!=n.namestart)D.textAlign=n.textalign,D.fillStyle=r,D.fillText(n.namestr,n.namestart,o+y/2);else if(n.namehover&&!t.query.noNameHover){const t=Math.max(10,n.start+10);D.fillStyle="white",D.fillRect(t,o,n.namewidth+10,y),D.strokeStyle=r,D.strokeRect(t+1.5,o+.5,n.namewidth+10-3,y-2),D.fillStyle=r,D.textAlign="center",D.fillText(n.namestr,t+n.namewidth/2+5,o+y/2)}else n.namein&&(D.textAlign="center",D.fillStyle="white",D.fillText(n.namestr,(Math.max(0,n.start)+Math.min(_,n.stop))/2,o+y/2))}const J={height:W,mapisoform:z,mapexon:H,returngmdata:E};if(0==F.length)return J.src=L.toDataURL(),J;const V=[];D.textAlign="center",D.textBaseline="middle";for(const[e,n]of F.entries()){const e=S&&n.category&&S[n.category]?S[n.category].color:n.color||x,r=n.canvas,i=(y+v)*(r.stack-1);n.genomicseq=(await o.get_fasta(P,n.chr+":"+(n.start+1)+"-"+n.stop)).split("\n").slice(1).join("").toUpperCase();const a=s(n);for(const e of n.rglst){const o=t.query.rglst[e.idx];let s=0;for(let n=0;n<e.idx;n++)s+=t.query.rglst[n].width+b;const l=o.width/(o.stop-o.start),h=Math.min(y,3*l),p=h<8?null:h;let m=!1;r.stranded&&"-"==n.strand&&(m=!0);let g=0;p&&(D.font=p+"px Arial");for(const[t,e]of n.coding.entries()){let[r,h]=e;if(m){if(r>=o.stop){g+=h-r,0==t&&n.startCodonFrame&&(g-=3-n.startCodonFrame);continue}if(h<=o.start)break}else{if(h<=o.start){g+=h-r,0==t&&n.startCodonFrame&&(g-=3-n.startCodonFrame);continue}if(r>=o.stop)break}if(0==t&&n.startCodonFrame){m?h-=3-n.startCodonFrame:r+=3-n.startCodonFrame;let t=Math.max(e[0],o.start),a=Math.min(e[1],o.stop);if(m?t=Math.max(h,o.start):a=Math.min(r,o.stop),t<a){D.fillStyle=d;const e=s+o.scale(o.reverse?a:t),n=s+o.scale(o.reverse?t:a);D.fillRect(e,i,Math.max(1,n-e),y)}}const v=Math.max(o.start,r),b=Math.min(o.stop,h);g+=m?h-b:v-r;let _=0;for(let t=0;t<b-v;t++){let e;if(g++,_++,g%3==0)e=g/3-1;else{if(t<b-v-1)continue;e=Math.floor(g/3)}let r=a[e],d=Math.ceil(g/3)%2==0?c:null;r?"M"==r?d=u:"*"==r&&(d=f):(r=4,d="red");let h,w=l*_;if(m){const e=b-1-t;h=s+o.scale(e)}else{const e=v+t+1-_;h=s+o.scale(e)}o.reverse&&(h-=w),_=0,h>=s&&h<=s+o.width&&(d&&(D.fillStyle=d,D.fillRect(h,i,w,y)),p&&(D.fillStyle="white",D.fillText(r,h+w/2,i+y/2)),V.push({x1:h,x2:h+w,y:n.canvas.stack,name:r+(e+1)+' <span style="font-size:.7em;color:#858585">AA residue</span>'}))}}}if(r.namehover&&!t.query.noNameHover){D.font="bold "+w+"px Arial";const t=Math.max(10,r.start+10);D.fillStyle="white",D.fillRect(t,i,r.namewidth+10,y),D.strokeStyle=e,D.strokeRect(t+1.5,i+.5,r.namewidth+10-3,y-2),D.fillStyle=e,D.fillText(r.namestr,t+r.namewidth/2+5,i+y/2)}}return J.src=L.toDataURL(),J.mapaa=V,J}(e,t))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},2818:(t,e,n)=>{const r=n(5727),o=new Set(["-1","0","1","2"]);e.X=function(t,e){t[0];const n=Number(t[1]),i=(t[2],t[3].split(".")[0]),s=t[5];if("+"!=s&&"-"!=s)return{name:i};const a="+"==s,l=Number(t[6]),c=Number(t[7]);if(!Number.isInteger(l)||!Number.isInteger(c))return{name:i,strand:s};const u=[],f=[],d=[],h=[],p=[],m=t[15],g=t[17],y=t[20];if(!t[10].includes(",")||!t[11].includes(","))return{name:i,strand:s};const v=t[10].split(",");v.pop();const b=v.map(Number),_=t[11].split(",");_.pop();const w=_.map(Number);if(b.includes(NaN)||w.includes(NaN))return{name:i,strand:s};let x=null,k=0,q=0;for(const[t,e]of b.entries()){k+=e;const r=n+w[t],o=r+e;a?p.push([r,o]):p.unshift([r,o]),t>0&&(a?h.push([x,r]):h.unshift([x,r])),x=o,r<l?o<l?a?f.push([r,o]):u.unshift([r,o]):(a?f.push([r,l]):u.unshift([r,l]),o>c?(l<c&&(a?d.push([l,c]):d.unshift([l,c]),q+=c-l),a?u.push([c,o]):f.unshift([c,o])):l<o&&(a?d.push([l,o]):d.unshift([l,o]),q+=o-l)):r<c?o<=c?r<o&&(a?d.push([r,o]):d.unshift([r,o]),q+=o-r):(r<c&&(a?d.push([r,c]):d.unshift([r,c]),q+=c-r),a?u.push([c,o]):f.unshift([c,o])):a?u.push([r,o]):f.unshift([r,o])}const N={name:g,isoform:i,strand:s,exon:p,rnalen:k};26==t.length&&(N.category=y),e&&e.has(i)&&(N.description=e.get(i)),h.length>0&&(N.intron=h),l==c||(N.cdslen=q,N.codingstart=l,N.codingstop=c,N.coding=d,f.length&&(N.utr5=f),u.length&&(N.utr3=u));const S=m.split(",");return S.pop(),S.length<1||S.some((t=>!o.has(t)))||r.default(N,m),N}},4353:(t,e,n)=>{const r=n(7147),o=n(1017),i=n(2081).spawn,s=n(3856),a=(n(9699),n(334)),l=(a.tabix,a.gfClient||"gfClient"),c=a.gfServer||"gfServer";function u(t,e){return new Promise(((n,r)=>{const o=i(c,["status",e.blat.host,e.blat.port]),s=[],a=[];o.stdout.on("data",(t=>s.push(t))),o.stderr.on("data",(t=>a.push(t))),o.on("close",(e=>{a.join("").trim()&&n(t+" OFF");const r=s.join("").trim().split("\n");let o=0;for(const t of r)t.startsWith("blat requests")&&(o=t.split(" ")[2]);n(t+" ON, "+o+" requests")}))}))}function f(t,e){const n=o.join(a.cachedir,Math.random().toString());return new Promise(((r,o)=>{const s=i(l,[t.blat.host,t.blat.port,"",e,n,"-q=dna","-nohead","-minScore=20","-minIdentity=0","-out=psl"]),a=[];s.stderr.on("data",(t=>a.push(t))),s.on("close",(t=>{const e=a.join("");e&&(console.log("BLAT error",e),o("blat server problem")),r(n)}))}))}e.x=t=>async(e,n)=>{try{if(e.query.serverstat){const e=[];for(const n in t){const r=t[n];r.blat&&e.push(await u(n,r))}if(0==e.length)throw"found no genome with blat";return void n.send({lst:e})}if(!e.query.genome)throw".genome missing";const i=t[e.query.genome];if(!i)throw"invalid genome";if(!i.blat)throw"blat not enabled";if(!e.query.seq)throw".seq missing";n.send(await async function(t,e,n,i){const l=o.join(a.cachedir,await s.write_tmpfile(">query\n"+e+"\n")),c=await f(t,l),u=(await s.read_file(c)).trim();if(r.unlink(c,(()=>{})),r.unlink(l,(()=>{})),""==u)return{nohit:1};const d=u.split("\n"),h=[];for(const t of d){const e={},n=t.split(" ").filter((function(t){return""!=t}))[0].split("\t");e.query_match=n[0],e.query_startpos=(parseInt(n[11])+1).toString(),e.query_stoppos=n[12],e.query_strand=n[8],e.query_totallen=n[10],e.query_alignlen=Math.abs(parseInt(n[11])-parseInt(n[12])).toString(),e.ref_chr=n[13],e.ref_startpos=(parseInt(n[15])+1).toString(),e.ref_stoppos=n[16],e.ref_alignlen=Math.abs(n[16]-n[15]).toString(),e.ref_totallen=n[14],h.push(e)}return h.sort(((t,e)=>e.query_match-t.query_match)),{hits:h}}(i,e.query.seq,e.query.soft_starts,e.query.soft_stops))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},7833:(t,e,n)=>{const r=n(8064),o=n(5494),i=n(6733),s=n(5558),a=n(3602),l=n(6279),c=n(8423),u=n(8235),f=n(1017),d=n(7147),h=n(334),{get_samples:p}=n(2852),m={snvindel:o,sv:l,fusion:l,svjson:c,cnv:i,itd:a,deletion:s,truncation:u};function g(t,e,n,r,o,i){for(const s of e.yesSamples){if(i&&!i.includes(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:parseInt(t),class:"WT",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:parseInt(t),class:"WT",_SAMPLEID_:s})}for(const s of e.noSamples){if(i&&!i.includes(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:parseInt(t),class:"Blank",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:parseInt(t),class:"Blank",_SAMPLEID_:s})}}async function y(t,e){const n=t.cohort;try{if(n.mutationFlagSet)return n.mutationFlagSet;if(!n.mutationset)return;const r={},o=t.sampleName2Id;for(const[t,i]of n.mutationset.entries()){const n=await v(t,i,e);r[Math.random()]=n;for(const t in n.data)for(const e of n.data[t])e._SAMPLENAME_=e.sample.split(";")[0].trim(),e._SAMPLEID_=o.get(e._SAMPLENAME_)||e._SAMPLENAME_}return n.mutationFlagSet=r,r}catch(t){throw t}}async function v(t,e,n){const o=r.init_bulk_flag(n);if(!o)throw"init_bulk_flag() failed";o.tpsetname=e.name?e.name:"set"+t;for(const t in e){if(!(t in m))throw`unknown mutationset: ${t}`;const n=e[t].startsWith("/")?e[t]:f.join(h.tpmasterdir,e[t]);try{const e=(await d.promises.readFile(n,"utf8")).trim().split(/\r?\n/);if(m[t].parseheader(e[0],o))throw`${t} header line error: herr`;for(let n=1;n<e.length;n++)m[t].parseline(n,e[n],o)}catch(t){throw t}}return o}e.mayGetGeneVariantData=async function(t,e){var n;const r=this,o=t.term.name,i=await y(r,e.genome),s=new Map;if(!i)return s;let a;(null==e||null===(n=e.filter)||void 0===n?void 0:n.lst.length)>0&&(a=[...new Set((await p(e.filter,r)).map((t=>t.id)))]);for(const t in i){var l;const e=i[t];if(o in e.data){for(const t of e.data[o]){const e=t._SAMPLEID_;if(a&&!a.includes(e))continue;s.has(e)||s.set(e,{sample:e});const n=s.get(e);o in n||(n[o]={key:o,values:[],label:o}),n[o].values.push(t)}if(null!==(l=r.assayAvailability)&&void 0!==l&&l.byDt)for(const t in r.assayAvailability.byDt){const e=r.assayAvailability.byDt[t];if(e.byOrigin)for(const n in e.byOrigin){g(t,e.byOrigin[n],s,o,n,a)}else g(t,e,s,o,!1,a)}}}return s},e.getTermTypes=async function(t){const e=this;try{const n="string"==typeof t.ids?JSON.parse(t.ids):t.ids,r=n.map((()=>"?")).join(","),o=`SELECT id, name, type, jsondata, parent_id FROM terms WHERE id IN (${r}) OR name IN (${r})`,i=e.cohort.db.connection.prepare(o).all([...n,...n]),s={};for(const t of i)t.jsondata&&Object.assign(t,JSON.parse(t.jsondata)),s[t.id]=t;const a=n.filter((t=>!s[t])),l=await y(e,t.genome);if(l)for(const t in l){const e=l[t];if(e.data)for(const t of a)t in e.data&&!(t in s)&&(s[t]={name:t,type:"geneVariant"})}return s}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}},e.mayGetMatchingGeneNames=async function(t,e,n,r=25){const o=await y(this,n.genome);if(o)for(const n in o){const s=o[n];for(const n in s.data){var i;if(n.length>r)continue;if(null===(i=s.data[n])||void 0===i||!i.length)continue;const o={name:n,type:"geneVariant",isleaf:!0};n===e?t.equals.push(o):n.startsWith(e)?t.startsWith.push(o):n.includes(" "+e)?t.startsWord.push(o):n.includes(e)?t.includes.push(o):"TP53"==n&&0}}},e.get_flagset=y},2824:(t,e,n)=>{"use strict";n.d(e,{q:()=>u});const r=n(9699),o=n(6718).createCanvas,i=n(3856),s=n(1271).run_rust,a=n(334),l=n(2081).spawn,{rgb:c}=n(7346);async function u(t,e){try{let n,l,u,p,m=!1,g=!1;const[y,v,b]=r.fileurl(t);if(y)throw y;if(v.endsWith(".gz")&&(g=!0,b&&(p=await i.cache_index(v,t.query.indexURL))),t.query.autoscale)m=!0;else if(t.query.percentile){if(u=t.query.percentile,!Number.isFinite(u))throw"invalid percentile"}else{if(n=t.query.minv,l=t.query.maxv,!Number.isFinite(n))throw"invalid minv";if(!Number.isFinite(l))throw"invalid maxv"}if(!Number.isFinite(t.query.barheight))throw"invalid barheight";if(!Number.isFinite(t.query.regionspace))throw"invalid regionspace";if(!Number.isFinite(t.query.width))throw"invalid width";if(!t.query.rglst)throw"region list missing";if(t.query.dotplotfactor&&!Number.isInteger(t.query.dotplotfactor))throw"dotplotfactor value should be positive integer";if(g)return await async function(t,e,n,r,i,s){if(null==n||null==r)throw"Y axis scale must be defined for bedgraph track";const a=o(t.query.width*t.query.devicePixelRatio,t.query.barheight*t.query.devicePixelRatio),l=a.getContext("2d");t.query.devicePixelRatio>1&&l.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);let c=0;for(let e of t.query.rglst)await f(t,e,c,n,r,i,s,l),c+=e.width+t.query.regionspace;e.send({src:a.toDataURL()})}(t,e,n,l,v,p);for(const e of t.query.rglst){let n;if(a.features.bigwig_rust){const r=v+","+e.chr+","+e.start+","+e.stop+","+Math.ceil(e.width*(t.query.dotplotfactor||1));n=await s("bigwig",r)}else n=await h(t,e,v);n&&(e.values=n.trim().split("\t").map(Number.parseFloat),t.query.dividefactor&&(e.values=e.values.map((e=>e/t.query.dividefactor))))}let _=!0;for(const e of t.query.rglst)e.values&&(_=!1);const w=o(t.query.width*t.query.devicePixelRatio,t.query.barheight*t.query.devicePixelRatio),x=w.getContext("2d");if(t.query.devicePixelRatio>1&&x.scale(t.query.devicePixelRatio,t.query.devicePixelRatio),_)return x.font="14px Arial",x.fillStyle="#858585",x.textAlign="center",x.textBaseline="middle",x.fillText(t.query.name+": no data in view range",t.query.width/2,t.query.barheight/2),void e.send({src:w.toDataURL(),nodata:!0});const k=1,q=t.query.dotplotfactor?1/t.query.dotplotfactor:1;let N=0,S=0;const A={};if(m||u){const e=[],n=[];for(const r of t.query.rglst)if(r.values)for(const t of r.values)Number.isNaN(t)||(t>=0&&e.push(t),t<=0&&n.push(t));e.length&&(e.sort(((t,e)=>t-e)),N=m?e[e.length-1]:e[Math.floor(e.length*u/100)]),n.length&&(n.sort(((t,e)=>e-t)),S=m?n[n.length-1]:n[Math.floor(n.length*u/100)]),A.minv=S,A.maxv=N}else S=n,N=l;if(t.query.barheight<10){let e=c(t.query.pcolor);const n=e.r+","+e.g+","+e.b;e=c(t.query.ncolor);const r=e.r+","+e.g+","+e.b;let o=0;for(const e of t.query.rglst){if(e.values)for(let i=0;i<e.values.length;i++){const s=e.values[i];if(Number.isNaN(s))continue;x.fillStyle=s>=N?t.query.pcolor2:s>=0?"rgba("+n+","+s/N+")":s<=S?t.query.ncolor2:"rgba("+r+","+s/S+")";const a=Math.ceil(o+(e.reverse?e.width-q*i:q*i));x.fillRect(a,0,k,t.query.barheight)}o+=e.width+t.query.regionspace}}else{const e=d().height(t.query.barheight).min(S).max(N);let n=0;for(const r of t.query.rglst){if(r.values)for(let o=0;o<r.values.length;o++){const i=r.values[o];if(Number.isNaN(i))continue;x.fillStyle=i>0?t.query.pcolor:t.query.ncolor;const s=Math.ceil(n+(r.reverse?r.width-q*o:q*o)),a=e(i);if(i>0)x.fillRect(s,a.y,k,t.query.dotplotfactor?Math.min(2,a.h):a.h);else if(t.query.dotplotfactor){const t=Math.min(2,a.h);x.fillRect(s,a.y+a.h-t,k,t)}else x.fillRect(s,a.y,k,a.h);i>N?(x.fillStyle=t.query.pcolor2,x.fillRect(s,0,k,2)):i<S&&(x.fillStyle=t.query.ncolor2,x.fillRect(s,t.query.barheight-2,k,2))}n+=r.width+t.query.regionspace}}A.src=w.toDataURL(),e.send(A)}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}async function f(t,e,n,r,o,s,a,l){const c=d().height(t.query.barheight).min(r).max(o),u=e.width/(e.stop-e.start);await i.get_lines_bigfile({args:[s,e.chr+":"+e.start+"-"+e.stop],dir:a,callback:i=>{const s=i.split("\t"),a=Number.parseInt(s[1]);if(Number.isNaN(a))return;const f=Number.parseInt(s[2]);if(Number.isNaN(f))return;const d=Number.parseFloat(s[3]);if(Number.isNaN(d))return;l.fillStyle=d>0?t.query.pcolor:t.query.ncolor;const h=c(d),p=n+(Math.max(a,e.start)-e.start)*u,m=n+(Math.min(f,e.stop)-e.start)*u,g=Math.max(1,m-p);l.fillRect(p,h.y,g,h.h),d>o?(l.fillStyle=t.query.pcolor2,l.fillRect(p,0,g,2)):d<r&&(l.fillStyle=t.query.ncolor2,l.fillRect(p,t.query.barheight-2,g,2))}})}function d(){var t=50,e=0,n=100;function r(r){var o,i=!1,s=0;return 0==e&&0==n||e<=0&&n>=0&&(i=!0,s=t*n/(n-e)),i?r>=n?{y:0,h:s}:r>=0?{y:s-(o=s*r/n),h:o}:r<=e?{y:s,h:t-s}:{y:s,h:o=(t-s)*r/e}:r<=e?{y:t,h:0}:{y:t-(o=t*(r-e)/(n-e)),h:o}}return r.height=function(e){return t=e,r},r.min=function(t){return e=t,r},r.max=function(t){return n=t,r},r}function h(t,e,n){return new Promise(((r,o)=>{const i=l(a.bigwigsummary,["-udcDir="+a.cachedir,n,e.chr,e.start,e.stop,Math.ceil(e.width*(t.query.dotplotfactor||1))]),s=[],c=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>c.push(t))),i.on("close",(t=>{const e=c.join("");e.length?e.startsWith("no data")?r():o("Cannot read bigWig file"):r(s.join(""))}))}))}},5727:(t,e)=>{e.default=(t,e)=>{if(!t.codingstart)return;const n="+"==t.strand?t.codingstart:t.codingstop;let r=t.exon.findIndex((t=>t[1]>=n&&t[0]<=n));if(-1==r)throw"start codon not matched to an exon: "+JSON.stringify(t);"-"==t.strand&&(r=t.exon.length-r-1);const o=e.split(",")[r];if("-1"==o)throw"start codon frame is -1: "+t.isoform;if("0"!=o){if("1"!=o&&"2"!=o)throw"start codon frame not 0/1/2: "+o+" "+t.isoform;t.startCodonFrame=Number.parseInt(o)}}},1883:(t,e,n)=>{const r=n(1017),o=n(7147).promises,i=n(334),s=n(9535).validate_termdb;e.server_updateAttr=function(t,e){if(e.updateAttr&&!t.label){for(const n of e.updateAttr){let e=t;for(const t of n)if(e)if("object"==typeof t)for(const n in t)e[n]=t[n];else e=e[t]}t.label&&delete e.updateAttr}},e.setDbRefreshRoute=function(t,e,n){var a,l;if(null===(a=t.cohort)||void 0===a||null===(l=a.db)||void 0===l||!l.refresh)return;const c=t.cohort.db.refresh;delete t.cohort.db.refresh,e.get(`${n}/${c.route}`,(async(e,n)=>{n.send({label:t.label,files:[]})})),e.post(`${n}/${c.route}`,(async(e,n)=>{try{var a,l;const c=null!==(a=t.cohort.db)&&void 0!==a&&null!==(l=a.file)&&void 0!==l&&l.startsWith(i.tpmasterdir)?t.cohort.db.file:r.join(i.tpmasterdir,t.cohort.db.file||""),u=e.body;if(!u.dbfile)throw"Updating input text files via the termdb-refresh page has been deprecated.Please use the buildTermdb.bundle.js. pipeline before triggering this route to replace the db file.";{const e=r.join(i.tpmasterdir,u.dbfile);if(!await o.stat(e))throw`dbfile not found: '${e}'`;const n=t.cohort.db.file_fullpath||c;if(e===n)throw"db file source and target are the same";console.log(`copying ${e} to ${n}`),await o.copyFile(e,n)}await s(t),n.send({status:"ok"})}catch(t){console.log(t),n.send({error:t.error||t})}}))}},9320:(t,e,n)=>{n(9699);const r=n(7147),o=n(3856),i=n(2081).spawn,s=n(1017),a=n(334),l=a.fimo||"fimo";async function c(t,e,n){const c=s.join(a.cachedir,Math.random().toString());return await o.write_file(c,n),new Promise(((n,o)=>{const s=["--parse-genomic-coord","--verbosity",1,"--text"];t.fimo_thresh&&(s.push("--thresh"),s.push(t.fimo_thresh)),s.push(e.fimo_motif.db),s.push(c);const a=i(l,s),u=[];a.stdout.on("data",(t=>u.push(t))),a.on("close",(o=>{r.unlink(c,(()=>{}));const i=u.join("").trim();i||n([]);const s=[],a=i.split("\n");for(let n=1;n<a.length;n++){const r=a[n].split("\t"),o=r[0].split("_")[0],i=Number.parseInt(r[3]),l=Number.parseInt(r[4]);if(i>t.m.pos||l<t.m.pos+1)continue;const c=Number.parseFloat(r[7]),u={start:i,stop:l,strand:r[5],name:o,pvalue:c,score:Number.parseFloat(r[6]),logpvalue:-Math.log10(c)};e.fimo_motif.tf2attr&&(u.attr=e.fimo_motif.tf2attr[u.name]),s.push(u)}n(s)}))}))}e.handle_closure=t=>async(e,n)=>{try{const r=e.query;if(!r.m)throw"no mutation";if(!r.m.chr)throw"mutation chr missing";if(!Number.isInteger(r.m.pos))throw"mutation position is not integer";if(!r.m.ref)throw"mutation ref allele missing";if(!r.m.alt)throw"mutation alt allele missing";const i=t[r.genome];if(!i)throw"invalid genome";if(!i.fimo_motif)throw"motif finding not supported on this genome";const s=await async function(t,e){const n=t.m.pos-t.flankspan,r=t.m.pos+t.flankspan,i=await o.get_fasta(e,t.m.chr+":"+n+"-"+r);!function(t,e,n){if(!t.m.ref)return;if("-"==t.m.ref)return;const r=n.split("\n").slice(1).join("").toUpperCase().substring(t.m.pos-e,t.m.pos-e+t.m.ref.length);if(r==t.m.ref.toUpperCase())return;if(common.reversecompliment(r)==t.m.ref.toUpperCase())t.m.ref=r,"-"!=t.m.alt&&(t.m.alt=common.reversecompliment(t.m.alt))}(t,n,i);const s=await c(t,e,i),a=new Map;for(const t of s)t.pvalue_ref=t.pvalue,delete t.pvalue,t.logpvalue_ref=t.logpvalue,delete t.logpvalue,a.has(t.name)||a.set(t.name,[]),a.get(t.name).push(t);const l=function(t,e,n,r){const o=r.split("\n"),i=o.slice(1).join("");return o[0]+"\n"+i.substr(0,t.pos-e)+("-"==t.alt?"":t.alt)+i.substr(t.pos-e+("-"==t.ref?0:t.ref.length))}(t.m,n,0,i),u=await c(t,e,l);for(const t of u){t.pvalue_alt=t.pvalue,delete t.pvalue,t.logpvalue_alt=t.logpvalue,delete t.logpvalue,a.has(t.name)||a.set(t.name,[]);let e=!0;for(const n of a.get(t.name))if(null!=n.logpvalue_ref&&n.strand==t.strand&&Math.abs(t.start-n.start)<=2&&Math.abs(t.stop-n.stop)<=2){n.pvalue_alt=t.pvalue_alt,n.logpvalue_alt=t.logpvalue_alt,n.logpvaluediff=t.logpvalue_alt-n.logpvalue_ref,n.logpvaluediff>0?n.gain=!0:n.loss=!0,e=!1;break}e&&a.get(t.name).push(t)}let f=0,d=0;const h=[];for(const e of a.values())for(const n of e)null==n.logpvaluediff&&(null==n.pvalue_ref?(n.gain=!0,n.logpvaluediff=n.logpvalue_alt):null==n.pvalue_alt&&(n.loss=!0,n.logpvaluediff=-n.logpvalue_ref)),null!=t.minabslogp&&Math.abs(n.logpvaluediff)<t.minabslogp||(n.logpvaluediff>0?f=Math.max(f,n.logpvaluediff):d=Math.min(d,n.logpvaluediff),h.push(n));return{items:h,valuemin:d,valuemax:f,refstart:n,refstop:r,refseq:i.split("\n").slice(1).join("")}}(r,i);n.send(s)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},4065:(t,e,n)=>{"use strict";function r(t){return(e,n)=>{try{const r=t[e.query.genome];if(!r)throw"invalid genome name";n.send(o(r,e.query))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}function o(t,e){if(t.genomicNameRegexp.test(e.input))throw"invalid character in gene name";if(e.deep){const n={};let r;{const n=t.genedb.getnamebynameorisoform.get(e.input,e.input);n&&(r=n.name)}if(!r&&t.genedb.getNameByAlias){const n=t.genedb.getNameByAlias.get(e.input);n&&(r=n.name)}if(!r&&t.genedb.get_gene2canonicalisoform&&e.input.toUpperCase().startsWith("ENSG")){const o=t.genedb.get_gene2canonicalisoform.get(e.input);if(o&&o.isoform){const e=o.isoform;n.found_isoform=e;const i=t.genedb.getnamebynameorisoform.get(e,e);if(!i)throw"cannot map enst isoform to symbol";r=i.name}}r||(r=e.input);const o=t.genedb.getjsonbyname.all(r);return n.gmlst=o.map((t=>{const e=JSON.parse(t.genemodel);return t.isdefault&&(e.isdefault=!0),e})),n}const n=e.input.toUpperCase(),r=(n.substr(0,2),t.genedb.getnameslike.all(n+"%"));if(r.length)return r.sort(),{hits:r.map((t=>t.name))};if(t.genedb.getNameByAlias){const e=t.genedb.getNameByAlias.all(n);if(e.length)return{hits:e.map((t=>t.name))}}{const n=t.genedb.getnamebynameorisoform.get(e.input,e.input);if(n)return{hits:[n.name]}}return{hits:[]}}n.r(e),n.d(e,{getResult:()=>o,handle_genelookup_closure:()=>r})},2084:(t,e,n)=>{"use strict";n.r(e),n.d(e,{handle_healthcheck_closure:()=>l});const r=n(334),o=n(7147),i=n(1017),s=n(2081),a=n(6464).promisify(s.exec);function l(t){const e=i.join(process.cwd(),"./rev.txt");let n="";return o.existsSync(e)&&(n=o.readFileSync(e,{encoding:"utf8"})),async(e,o)=>{try{o.send(await async function(t,e){const n={status:"ok",rev:e},o=r.features.healthcheck_keys||[];if(o.includes("w")){const{stdout:t,stderr:e}=await a("w | head -n1");if(e)throw e;n.w=t.toString().trim().split(" ").slice(-3).map((t=>t.endsWith(",")?+t.slice(0,-1):+t))}if(o.includes("rs")){const{stdout:t,stderr:e}=await a("ps aux | grep rsync -w");if(e)throw e;n.rs=t.toString().trim().split("\n").length-1}n.rev||(n.rev=r.rev);r.commitHash&&(n.commitHash=r.commitHash);r.version&&(n.version=r.version);for(const e in t){n[e]={};const r=t[e];if(r.genedb&&(n[e].genedb={buildDate:r.genedb.get_buildDate?r.genedb.get_buildDate.get().date:"unknown",tables:r.genedb.tableSize}),r.termdbs){n[e].termdbs={};for(const t in r.termdbs){const o=r.termdbs[t];n[e].termdbs[t]={buildDate:o.cohort.termdb.q.get_buildDate?o.cohort.termdb.q.get_buildDate.get().date:"unknown"}}}}return n}(t,n))}catch(t){o.send({error:t.message||t})}}}},8405:(t,e,n)=>{"use strict";n.d(e,{v:()=>s});const r=n(7147),o=n(6464),i=n(6452);async function s(t,e){const n={},s=e?await async function(t,e,n){try{const r=await i(t,{headers:{Range:"bytes="+e+"-"+(n-1)}}).buffer();return r.buffer.slice(e,e+n)}catch(t){throw console.log(t.response),"error reading file, check file details"}}(t,0,32e3):await async function(t,e,n){const i=o.promisify(r.open),s=o.promisify(r.read),a=Buffer.alloc(n),l=await i(t,"r"),c=await s(l,a,0,n,e);r.close(l,(function(t){return t}));const u=c.buffer;return u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength)}(t,0,32e3),a=new DataView(s);let l=0;if("HIC"!==_())throw Error("Unsupported hic file");const c=w();if(8!==c)throw Error("Unsupported hic version: "+c);n["Hic Version"]=c,l+=8;const u=_();n["Genome ID"]=u;let f={};const d=w();let h=0;for(;h!==d;)f[_()]=_(),h++;n.Chromosomes={},n.chrorder=[];let p=w(),m=0;for(;m!==p;){const t=_();n.chrorder.push(t),n.Chromosomes[t]=w(),m++}n["Base pair-delimited resolutions"]=[];let g=w(),y=0;for(;y!==g;)n["Base pair-delimited resolutions"].push(w()),y++;n["Fragment-delimited resolutions"]=[];let v=w(),b=0;for(;b!==v;)n["Fragment-delimited resolutions"].push(w()),b++;return JSON.stringify(n);function _(){let t,e="";for(;0!=(t=a.getUint8(l++));)e+=String.fromCharCode(t);return e}function w(){const t=a.getInt32(l,!0);return l+=4,t}}},4695:(t,e,n)=>{const r=n(9699),o=n(3856),i=n(7147),s=n(4521);function a(t){return new Promise(((e,n)=>{const r=s.createInterface({input:i.createReadStream(t.file,{encoding:"utf8"})}),o=[];let a=!0;r.on("line",(e=>{if(a)return void(a=!1);const n=e.split("\t"),[i,s,l,c,u,f]=n[0].split(/[:,]/);if(i!=t.chr)return;const d=Number.parseInt(s),h=Number.parseInt(u);if(Number.isNaN(d)||Number.isNaN(h))return;const p=d-1,m=h-1;if(p>t.start&&p<t.stop||m>t.start&&m<t.stop){const t=Number.parseInt(n[1]),e=n[2];o.push({chr:i,start:p,stop:m,type:e,rawdata:[t]})}else p>t.stop&&r.close()})),r.on("close",(()=>{e(o)}))}))}t.exports=async(t,e)=>{try{const[n,s,l]=r.fileurl(t);if(n)throw n;if(!t.query.rglst)throw"rglst[] missing";if("string"==typeof t.query.rglst&&(t.query.rglst=JSON.parse(t.query.rglst)),!Array.isArray(t.query.rglst))throw"rglst[] not an array";if(t.query.rglst.reduce(((t,e)=>e.stop-e.start+t),0)>1e6)throw"Zoom in below 1 Mb to show junctions";let c;if(t.query.isrnapeg){if(!r.features.junctionrnapeg)throw"rnapeg not supported on this server";if(l)throw"rnapeg file from url is not supported";c=await async function(t,e){try{await i.promises.stat(e)}catch(t){if("EACCES"==t.code)throw"permission denied for rnapeg file";if("ENOENT"==t.code)throw"rnapeg file not found";throw"cannot access rnapeg file ("+t.code+")"}const n=[];for(const r of t.rglst){const t=await a({file:e,chr:r.chr,start:r.start,stop:r.stop});for(const e of t)n.push(e)}return n}(t.query,s)}else{const e=l?await o.cache_index(s,t.query.indexURL):null;c=await async function(t,e,n){const r=[];for(const i of t.rglst)await o.get_lines_bigfile({args:[e,i.chr+":"+i.start+"-"+i.stop],dir:n,callback:t=>{const e=t.split("\t"),n=Number.parseInt(e[1]),o=Number.parseInt(e[2]);if(n>=i.start&&n<=i.stop||o>=i.start&&o<=i.stop){const t={chr:i.chr,start:n,stop:o,type:e[4],rawdata:[]};for(let n=5;n<e.length;n++)t.rawdata.push(Number.parseInt(e[n]));r.push(t)}}});return r}(t.query,s,e)}e.send({lst:c})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}},6979:(t,e,n)=>{n(7147);const r=n(1017),o=(n(2081).spawn,n(4521),n(9699),n(3856)),i=n(2273),s=n(334),a=n(6819),l=n(9157);async function c(t){const e=["futime\tfustat\trx"];for(const[n,r]of t.entries())for(const t of r.lst)e.push(t.serialtime+"\t"+t.censored+"\t"+n);const n=await l(r.join(s.binpath,"/utils/km.R"),e);return Number(n.join(""))}async function u(t,e,n,r){const o=new Set(t.map((t=>t.name))),s=e.samplerule.set;let a,l;for(const t in n.queries){const e=n.queries[t];e.type==i.tkt.mdsvcf?a=e:e.type==i.tkt.mdssvcnv&&(l=e)}const c=new Set;if(s.cnv||s.loh||s.sv||s.fusion||s.itd){if(!l)throw"no svcnv found in ds.queries";if(r)return await f(l,o,e,!0);const t=await f(l,o,e);for(const e of t)c.add(e)}if(s.snvindel){if(!a)throw"no vcf found in ds.queries";for(const t of a.tracks)await d(a,t,o,c,e)}return t.filter((t=>c.has(t.name)))}async function f(t,e,n,a){const l=n.samplerule.set,c=t.url?await o.cache_index(t.url,t.indexURL):null,u=new Set,f=new Set,d=new Set;return await o.get_lines_bigfile({args:[t.file?r.join(s.tpmasterdir,t.file):t.url,(t.nochr?l.chr.replace("chr",""):l.chr)+":"+l.start+"-"+(l.stop+1)],dir:c,callback:t=>{const n=t.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),s=JSON.parse(n[3]);if(e.has(s.sample)){if(s.dt==i.dtcnv){if(!l.cnv)return;if(l.cnv.focalsizelimit&&o-r>=l.cnv.focalsizelimit)return;if(l.cnv.valuecutoff&&Math.abs(s.value)<l.cnv.valuecutoff)return;return a?s.value>0?u.add(s.sample):f.add(s.sample):d.add(s.sample),void l.samples_cnv.add(s.sample)}if(s.dt==i.dtloh){if(!l.loh)return;if(l.loh.focalsizelimit&&o-r>=l.loh.focalsizelimit)return;if(l.loh.valuecutoff&&s.segmean<l.loh.valuecutoff)return;return d.add(s.sample),void l.samples_loh.add(s.sample)}if(s.dt==i.dtsv){if(!l.sv)return;return d.add(s.sample),void l.samples_sv.add(s.sample)}if(s.dt==i.dtfusionrna){if(!l.fusion)return;return d.add(s.sample),void l.samples_fusion.add(s.sample)}if(s.dt==i.dtitd){if(!l.itd)return;return d.add(s.sample),void l.samples_itd.add(s.sample)}}}}),a?[u,f]:d}async function d(t,e,n,l,c){const u=c.samplerule.set,f=e.url?await o.cache_index(e.url,e.indexURL):null;await o.get_lines_bigfile({args:[e.file?r.join(s.tpmasterdir,e.file):e.url,(e.nochr?u.chr.replace("chr",""):u.chr)+":"+u.start+"-"+(u.stop+1)],dir:f,callback:r=>{if(e.type==i.mdsvcftype.vcf){const[o,s,c]=a.vcfparseline(r,{nochr:e.nochr,samples:e.samples,info:t.info,format:e.format});for(const t of s)if(t.sampledata&&!(u.snvindel.ref&&(t.ref!=u.snvindel.ref||t.alt!=u.snvindel.alt)||u.snvindel.hiddenclass&&(i.vcfcopymclass(t,{}),u.snvindel.hiddenclass[t.class])))for(const e of t.sampledata)n.has(e.sampleobj.name)&&(l.add(e.sampleobj.name),u.samples_snvindel.add(e.sampleobj.name))}}})}async function h(t,e,n){if(!n.queries)throw".queries{} missing from ds";let i;for(const t in n.queries)n.queries[t].isgenenumeric&&(i=n.queries[t]);if(!i)throw"no gene numeric query from ds";const a=i.url?await o.cache_index(i.url,i.indexURL):null,l=e.samplerule.set,c=new Map;await o.get_lines_bigfile({args:[i.file?r.join(s.tpmasterdir,i.file):i.url,l.chr+":"+l.start+"-"+l.stop],dir:a,callback:t=>{const e=JSON.parse(t.split("\t")[3]);e.sample&&Number.isFinite(e.value)&&e.gene==l.gene&&c.set(e.sample,e.value)}});const u=[];for(const e of t)c.has(e.name)&&(e.genevalue=c.get(e.name),u.push(e));return u.sort(((t,e)=>t.genevalue-e.genevalue)),[i,u]}function p(t){t.lst.sort(((t,e)=>t.serialtime-e.serialtime));let e=t.lst.length,n=[],r=0;t.steps=[];for(const o of t.lst){if(0==o.censored){n.push(o.serialtime);continue}const i=1*(1-r)/(e-n.length);t.steps.push({x:o.serialtime,y:r,drop:i,censored:n}),r+=i,e-=n.length+1,n=[]}n.length>0&&t.steps.push({x:t.lst[t.lst.length-1].serialtime,y:r,drop:0,censored:n})}e.u=t=>async(e,n)=>{try{const r=e.query,o=t[r.genome];if(!o)throw"invalid genome";const i=o.datasets[r.dslabel];if(!i)throw"invalid dataset";if(!i.cohort)throw"no cohort for dataset";if(!i.cohort.annotation)throw"cohort.annotation missing for dataset";const s=i.cohort.survivalplot;if(!s)throw"survivalplot not supported for this dataset";if(!s.plots)throw".plots{} missing";if(e.query.init)return void n.send(s.init);if(!r.type)throw".type missing";const a=s.plots[r.type];if(!a)throw"unknown plot type: "+r.type;const l=function(t,e,n){if(!t.samplerule)throw".samplerule missing";if(!t.samplerule.full)throw".samplerule.full missing";const r=[];if(t.samplerule.full.byattr){const n=t.samplerule.full.key;if(!n)throw"key missing from samplerule.full{}";const o=t.samplerule.full.value;if(null==o)throw"value missing from samplerule.full{}";for(const t in e.cohort.annotation){const i=e.cohort.annotation[t];i[n]==o&&r.push({name:t,o:i})}}else if(t.samplerule.full.useall)for(const t in e.cohort.annotation){const n=e.cohort.annotation[t];r.push({name:t,o:n})}else{if(!t.samplerule.full.usesampleset)throw"unknown rule for samplerule.full";{const n=t.samplerule.full.sampleset;for(const t in n){const o=n[t],i=e.cohort.annotation[o];null!=i&&r.push({name:o,o:i})}}}const o=[];for(const t of r)Number.isFinite(t.o[n.serialtimekey])&&(t.serialtime=t.o[n.serialtimekey],t.censored=t.o[n.iscensoredkey],o.push(t));if(0==o.length)throw"no samples found for full set";return o}(r,i,a),f=await async function(t,e,n,r){if(e.samplerule.mutated_sets){const n=new Set(t.map((t=>t.name))),r=e.samplerule.mutated_sets.reduce(((e,r)=>{const o=new Set(r.samplenames);r.lst=t.filter((t=>o.has(t.name)));for(const t of r.samplenames)n.delete(t);return delete r.samplenames,e.push(r),e}),[]);return r.push({name:"No mutation (n="+n.size+")",lst:t.filter((t=>n.has(t.name))),is_notmutated:!0}),r}const o=e.samplerule.set;if(!o)return[{name:"All",lst:t}];if(o.geneexpression){if(!o.gene)throw".gene missing from samplerule.set";if(!o.chr)throw".chr missing from samplerule.set";if(!Number.isInteger(o.start))throw".start not integer from samplerule.set";if(!Number.isInteger(o.stop))throw".start not integer from samplerule.set";if(o.bymedian)return await async function(t,e,n,r){const o=e.samplerule.set,[i,s]=await h(t,e,n),a=Math.ceil(s.length/2),l=s[a-1].genevalue;return[{name:o.gene+" "+i.datatype+" below median (n="+a+", value<"+l+")",lst:s.slice(0,a)},{name:o.gene+" "+i.datatype+" above median (n="+(s.length-a)+", value>="+l+")",lst:s.slice(a,s.length)}]}(t,e,n);if(o.byquartile)return await async function(t,e,n,r){const o=e.samplerule.set,[i,s]=await h(t,e,n),a=Math.ceil(.25*s.length),l=Math.ceil(.5*s.length),c=Math.ceil(.75*s.length),u=s[a-1].genevalue,f=s[l-1].genevalue,d=s[c-1].genevalue;return[{name:o.gene+" "+i.datatype+" from 1st quartile (n="+a+", value<"+u+")",lst:s.slice(0,a),isfirstquartile:!0},{name:o.gene+" "+i.datatype+" from 2nd quartile (n="+(l-a)+", "+u+"<=value<"+f+")",lst:s.slice(a,l)},{name:o.gene+" "+i.datatype+" from 3rd quartile (n="+(c-l)+", "+f+"<=value<"+d+")",lst:s.slice(l,c)},{name:o.gene+" "+i.datatype+" from 4th quartile (n="+(s.length-c)+", value>="+d+")",lst:s.slice(c,s.length),isfourthquartile:!0}]}(t,e,n)}if(o.mutation){if(!o.chr)throw".chr missing from samplerule.set";if(!Number.isInteger(o.start))throw".start not integer from samplerule.set";if(!Number.isInteger(o.stop))throw".start not integer from samplerule.set";return await async function(t,e,n){const r=e.samplerule.set;if(r.samples_snvindel=new Set,r.samples_cnv=new Set,r.samples_loh=new Set,r.samples_sv=new Set,r.samples_fusion=new Set,r.samples_itd=new Set,r.cnv&&!r.snvindel&&!r.loh&&!r.sv&&!r.fusion&&!r.itd){const[r,o]=await u(t,e,n,!0),i=[],s=[],a=[];for(const e of t)r.has(e.name)?i.push(e):o.has(e.name)?s.push(e):a.push(e);const l=[];return s.length&&l.push({name:"Copy number loss (n="+s.length+")",lst:s}),i.length&&l.push({name:"Copy number gain (n="+i.length+")",lst:i}),a.length&&l.push({name:"No copy number variation (n="+a.length+")",lst:a}),l}const o=await u(t,e,n),i=[];for(const e of t)o.find((t=>t.name==e.name))||i.push(e);const s=[];o.length&&s.push({name:"With mutation (n="+o.length+")",lst:o});i.length&&s.push({name:"No mutation (n="+i.length+")",lst:i});return s}(t,e,n)}throw"unknown rule for samplerule.set{}"}(l,r,i);let d;f.length>1&&(d=await c(f)),await async function(t,e){if(!t.samplerule.mutated_sets)return;const n=e.find((t=>t.is_notmutated));if(!n)return;for(const t of e){if(t.is_notmutated)continue;const e=await c([t,n]);t.pvalue=e}}(r,f),await async function(t,e){if(!t.samplerule.set)return;if(!t.samplerule.set.geneexpression)return;if(!t.samplerule.set.byquartile)return;if(4!=e.length)return;if(t.samplerule.set.against1st){for(let t=1;t<4;t++)e[t].pvalue=await c([e[0],e[t]]);return}if(t.samplerule.set.against4th){for(let t=0;t<3;t++)e[t].pvalue=await c([e[t],e[3]]);return}}(r,f);for(const t of f)p(t),delete t.lst;const m={samplesets:f,pvalue:d};r.samplerule.set&&r.samplerule.set.mutation&&(m.count_snvindel=r.samplerule.set.samples_snvindel.size,m.count_cnv=r.samplerule.set.samples_cnv.size,m.count_loh=r.samplerule.set.samples_loh.size,m.count_sv=r.samplerule.set.samples_sv.size,m.count_fusion=r.samplerule.set.samples_fusion.size,m.count_itd=r.samplerule.set.samples_itd.size),n.send(m)}catch(t){t.stack&&console.error(t.stack),n.send({error:t.message||t})}}},9211:(t,e,n)=>{"use strict";n.d(e,{e:()=>s});const r=n(9699),o=(n(7147),n(1017),n(2081).spawn,n(3856)),i=n(6718).createCanvas;n(2273).bplen;function s(t){return async(e,n)=>{try{const i=t[e.query.genome];if(!i)throw"unknown genome";n.send(await async function(t,e){const[n,i,s]=r.fileurl(t);if(n)throw n;let l;s&&(l=await o.cache_index(i,t.query.indexURL));if(!t.query.rglst)throw"rglst missing";const c=await o.tabix_is_nochr(i,l,e),u=t.query.connheight||50,f={rglst:[]};for(const e of t.query.rglst){const n={chr:e.chr,start:e.start,stop:e.stop,width:e.width,reverse:e.reverse,xoff:e.xoff};f.rglst.push(n);const r=[],s=new Set,d=(c?e.chr.replace("chr",""):e.chr)+":"+e.start+"-"+e.stop;await o.get_lines_bigfile({args:[i,d],dir:l,callback:t=>{const n=t.split("\t"),o=Number.parseInt(n[1]);if(o<e.start)return;const i=Number.parseInt(n[2]);if(i>e.stop)return;const a=Number.parseFloat(n[5]);r.push({start:o,stop:i,r2:a}),s.add(o),s.add(i)}}),n.img=a(e,r,s,u,t.query.devicePixelRatio||1)}return f}(e,i))}catch(t){n.send({error:t.message||t})}}}function a(t,e,n,r,o){const[s,a]=function(t,e){let n=t.width/e.size,r=0;n>40&&(n=40,r=(t.width-n*e.size)/2);const o=new Map,i=t.reverse?[...e].sort(((t,e)=>e-t)):[...e].sort(((t,e)=>t-e));let s=r;for(const t of i)o.set(t,s+n/2),s+=n;return[n,o]}(t,n),l=new Map;{const e=(t.stop-t.start)/t.width;for(const r of n)t.reverse?l.set(r,(t.stop-r)/e):l.set(r,(r-t.start)/e)}let c=0;for(const t of e)c=Math.max(c,(a.get(t.stop)-a.get(t.start))/2);const u=r+c+s/2,f=i(t.width*o,u*o),d=f.getContext("2d");o>1&&d.scale(o,o),d.strokeStyle="black";for(const t of n)d.beginPath(),d.moveTo(l.get(t),0),d.lineTo(a.get(t),r),d.closePath(),d.stroke();for(const t of e){const e=a.get(t.start),n=a.get(t.stop),o=(e+n)/2,i=r+Math.abs(n-e)/2,l=Math.floor(255*(1-t.r2));d.fillStyle="rgb(255,"+l+","+l+")",d.beginPath(),d.moveTo(o,i-s/2),d.lineTo(o-s/2,i),d.lineTo(o,i+s/2),d.lineTo(o+s/2,i),d.lineTo(o,i-s/2),d.closePath(),d.fill()}return{height:u,src:f.toDataURL()}}},9157:(t,e,n)=>{n(1017);const r=n(7147),o=n(2081).spawn,i=n(2781).Readable,s=n(334);t.exports=async function(t,e,n=[]){try{await r.promises.stat(t)}catch(e){throw`${t} does not exist`}const a=[],l=[];return new Promise(((r,c)=>{const u=o(s.Rscript,[t,...n]);if(e&&e.length>0)try{const t=e.join("\n")+"\n";i.from(t).pipe(u.stdin)}catch(t){u.kill();let e=t;l.length>0&&(e+=`\nR stderr: ${l.join("").trim()}`),c(e)}u.stdout.on("data",(t=>a.push(t))),u.stderr.on("data",(t=>l.push(t))),u.on("error",(t=>c(t))),u.on("close",(t=>{if(0!==t){let e=`R process exited with non-zero status code=${t}`;a.length>0&&(e+=`\nR stdout: ${a.join("").trim()}`),l.length>0&&(e+=`\nR stderr: ${l.join("").trim()}`),c(e)}if(l.length>0){const t=l.join("").trim();c(`R process emitted standard error\nR stderr: ${t}`)}const e=a.join("").trim().split("\n");r(e)}))}))}},8025:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get:()=>l,save:()=>a});const r=n(334),o=n(1017),i=n(7147),s=n(3856);async function a(t,e){try{const n=function(){const t=[];for(;t.length<15;){const e=46+Math.floor(80*Math.random());(e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122)&&t.push(String.fromCharCode(e))}return t.join("")}(),i=JSON.stringify(t.body);await s.write_file(o.join(r.cachedir_massSession,n),i),e.send({id:n})}catch(t){e.send({error:t.message||t})}}async function l(t,e){try{if(!t.query.id)throw"session id missing";const n=o.join(r.cachedir_massSession,t.query.id);let a;try{a=(await i.promises.stat(n)).birthtime}catch(t){throw"invalid session"}const l=await s.read_file(n),c=new Date,u=new Date(a),f=r.features.massSessionDuration||30,d=f-Math.round((c.getTime()-u.getTime())/864e5);e.send({state:JSON.parse(l),sessionDaysLeft:d,massSessionDuration:f})}catch(t){e.send({error:t.message||t})}}},1185:(t,e,n)=>{"use strict";n.d(e,{Z:()=>a});const r=n(9699),o=n(3856),i=n(334),s=n(1017),a=t=>async(e,n)=>{try{const[a,l,c,u]=function(t,e){if(!e.query.gene)throw"gene name missing";if(!e.query.chr)throw"chr missing";if(!Number.isInteger(e.query.start))throw"start missing";if(!Number.isInteger(e.query.stop))throw"stop missing";const n=t[e.query.genome];if(!n)throw"invalid genome";let r,o,i;if(e.query.iscustom){if(!e.query.file&&!e.query.url)throw"no file or url for expression data";r={},o={file:e.query.file,url:e.query.url,indexURL:e.query.indexURL}}else{if(!n.datasets)throw"genome is not equipped with datasets";if(!e.query.dslabel)throw"dslabel missing";if(r=n.datasets[e.query.dslabel],!r)throw"invalid dslabel";if(!r.queries)throw"dataset is not equipped with queries";if(!e.query.querykey)throw"querykey missing";if(o=r.queries[e.query.querykey],!o)throw"invalid querykey"}if(e.query.svcnv)if(i={},e.query.iscustom)i.dsquery={file:e.query.svcnv.file,url:e.query.svcnv.url,indexURL:e.query.svcnv.indexURL};else{e.query.svcnv.genome=e.query.genome;const t=n.datasets[e.query.svcnv.dslabel];if(!t)throw"invalid dslabel";if(!t.queries)throw"dataset is not equipped with queries";if(!e.query.svcnv.querykey)throw"querykey missing";const r=t.queries[e.query.svcnv.querykey];if(!r)throw"invalid querykey";i.ds=t,i.dsquery=r}if(e.query.getgroup)if(e.query.sampleset);else{if(!r.cohort||!r.cohort.annotation)throw"no sample annotation for getting group";if(e.query.getgroup_unannotated){if(!o.boxplotbysamplegroup)throw"dsquery.boxplotbysamplegroup{} missing when getgroup_unannotated"}else{if(!Array.isArray(e.query.getgroup))throw"getgroup should be array";for(const t of e.query.getgroup){if(!t.k)throw"k missing from one of getgroup";if(!t.kvalue)throw"kvalue missing from one of getgroup"}}}return[n,r,o,i]}(t,e);e.query.getalllst,n.send(await async function(t,e,n,a,l){n.url&&(n.dir=await o.cache_index(n.url,n.indexURL));a&&a.dsquery.url&&(a.dsquery.dir=await o.cache_index(a.dsquery.url,a.dsquery.indexURL));const c=function(t){if(!t.query.sampleset)return;const e=new Map;for(const n of t.query.sampleset)for(const t of n.samples)e.set(t,n.name);return e}(l),u=new Map,f=[],d=[];if(await o.get_lines_bigfile({args:[n.file?s.join(i.tpmasterdir,n.file):n.url,l.query.chr+":"+l.query.start+"-"+l.query.stop],dir:n.dir,callback:t=>{const r=t.split("\t"),o=JSON.parse(r[3]);if(o.gene&&o.gene==l.query.gene&&Number.isFinite(o.value))if(l.query.getalllst)f.push({sample:o.sample,value:o.value});else if(l.query.getgroup){if(!o.sample)return;if(c)return void(l.query.getgroup_unannotated?c.has(o.sample)||d.push(o):c.get(o.sample)==l.query.getgroup[0].full&&d.push(o));const t=e.cohort.annotation[o.sample];if(l.query.getgroup_unannotated){if(!t)return void d.push(o);for(const e of n.boxplotbysamplegroup.attributes)if(null==t[e.k])return void d.push(o);return}if(!t)return;for(const e of l.query.getgroup)if(e.kvalue!=t[e.k])return;d.push(o)}else if(n.boxplotbysamplegroup&&e.cohort&&e.cohort.annotation){if(!o.sample)return;let t;t=null==l.query.index_boxplotgroupers||0==l.query.index_boxplotgroupers?n.boxplotbysamplegroup.attributes:n.boxplotbysamplegroup.additionals[l.query.index_boxplotgroupers-1].attributes;const r=e.cohort.annotation[o.sample];if(!r)return void f.push({sample:o.sample,value:o.value});const i=r[t[0].k];if(null==i)return void f.push({sample:o.sample,value:o.value});const s=[];for(let e=1;e<t.length;e++){const n=r[t[e].k];if(null==n)break;s.push(n)}s.unshift(i);const a=s.join(", ");if(!u.has(a)){const e={samples:[],attributes:[]};for(const n of t){const t=r[n.k];if(null==t)break;const o={k:n.k,kvalue:t};n.full&&(o.full=n.full,o.fullvalue=r[n.full]),e.attributes.push(o)}u.set(a,e)}u.get(a).samples.push({sample:o.sample,value:o.value})}else if(c){if(!o.sample)return;const t=c.get(o.sample);if(!t)return void f.push({sample:o.sample,value:o.value});u.has(t)||u.set(t,{samples:[],attributes:[{full:t}]}),u.get(t).samples.push({sample:o.sample,value:o.value})}else f.push({sample:o.sample,value:o.value})}}),l.query.getgroup2boxplot){d.sort(((t,e)=>t.value-e.value));const{w1:t,w2:e,p25:n,p50:o,p75:i,out:s}=r.boxplot_getvalue(d);return{n:d.length,min:d[0].value,max:d[d.length-1].value,w1:t,w2:e,p25:n,p50:o,p75:i,out:s}}const h=[];for(const[t,e]of u)h.push({name:t,values:e.samples,attributes:e.attributes});f.length&&h.push({name:"Unannotated",values:f});d.length&&h.push({values:d});if(l.query.getalllst)return{lst:h[0].values};if(l.query.iscustom&&!c||1==h.length){if(h[0]){const t=h[0].values;return t.sort(((t,e)=>e.value-t.value)),{lst:t,max:t[0].value,min:t[t.length-1].value}}return{nodata:1}}const p=await async function(t,e){if(!e||!t.query.svcnv.useloss&&!t.query.svcnv.usegain&&!t.query.svcnv.usesv)return;let n=t.query.start,r=t.query.stop;t.query.svcnv.usesv&&Number.isInteger(t.query.svcnv.svflank)&&(n=Math.max(0,n-t.query.svcnv.svflank),r+=t.query.svcnv.svflank);const a=new Map;return await o.get_lines_bigfile({args:[e.dsquery.file?s.join(i.tpmasterdir,e.dsquery.file):e.dsquery.url,t.query.chr+":"+n+"-"+r],dir:e.dsquery.dir,callback:e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(r.sample)if(r.chrA||r.chrB){if(!t.query.svcnv.usesv)return;a.has(r.sample)||a.set(r.sample,{}),a.get(r.sample).sv=1}else{if(!t.query.svcnv.usegain&&!t.query.svcnv.useloss)return;if(t.query.svcnv.usesv&&t.query.svcnv.svflank){const e=Number.parseInt(n[1]),r=Number.parseInt(n[2]);if(Math.max(t.query.start,e)>Math.min(t.query.stop,r))return}if(!Number.isFinite(r.value))return;if(!t.query.svcnv.usegain&&r.value>0)return;if(!t.query.svcnv.useloss&&r.value<0)return;if(t.query.svcnv.valueCutoff&&Math.abs(r.value)<t.query.svcnv.valueCutoff)return;if(t.query.svcnv.bplengthUpperLimit&&Number.parseInt(n[2])-Number.parseInt(n[1])>t.query.svcnv.bplengthUpperLimit)return;a.has(r.sample)||a.set(r.sample,{}),r.value>0?a.get(r.sample).gain=1:r.value<0&&(a.get(r.sample).loss=1)}}}),a}(l,a);if(l.query.getgroup){if(h[0]){const t=h[0].values;if(t.sort(((t,e)=>e.value-t.value)),p)for(const e of t){const t=p.get(e.sample);if(t)for(const n in t)e[n]=t[n]}return{lst:t,max:t[0].value,min:t[t.length-1].value}}return{nodata:1}}const m=[];let g=null,y=null;for(const t of h){t.values.sort(((t,e)=>t.value-e.value));const e=t.values.length;null==g?(g=t.values[0].value,y=t.values[e-1].value):(g=Math.min(g,t.values[0].value),y=Math.max(y,t.values[e-1].value));const{w1:n,w2:o,p25:i,p50:s,p75:a,out:c}=r.boxplot_getvalue(t.values),u=[{isall:1,w1:n,w2:o,p25:i,p50:s,p75:a,out:c}];if(p){if(l.query.svcnv.usegain){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).gain));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({iscnvgain:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}if(l.query.svcnv.useloss){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).loss));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({iscnvloss:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}if(l.query.svcnv.usesv){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).sv));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({issv:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}}m.push({name:t.name+" ("+t.values.length+")",boxplots:u,attributes:t.attributes})}return m.sort(((t,e)=>t.name<e.name?-1:t.name>e.name?1:0)),{groups:m,min:g,max:y}}(0,l,c,u,e))}catch(t){t.stack&&console.log(t),n.send({error:t.message||t})}}},9574:(t,e,n)=>{n(9699);const r=n(334),o=n(3856),i=n(1017),s="Unannotated";function a(t){return t.file?t.file:t.file2?t.file2:t.url}function l(t,e,n,r){const o=[];for(const i of t.samples)if(Number.isFinite(i.readcount)&&(i.readcount=Math.floor(i.readcount),!(i.readcount<=0||e.readcountCutoff&&i.readcount<e.readcountCutoff))){if(r.samples&&n.cohort&&n.cohort.annotation){const t=r.samples[i.i];if(!t)continue;const o=n.cohort.annotation[t];if(i.anno=o,e.cohortOnlyAttr&&n.cohort&&n.cohort.annotation){if(!o)continue;let t=!1;for(const n in e.cohortOnlyAttr){const r=o[n];if(r&&e.cohortOnlyAttr[n][r]){t=!0;break}}if(!t)continue}if(e.cohortHiddenAttr&&n.cohort&&n.cohort.annotation&&n.cohort.attributes){if(!o)continue;let t=!1;for(const r in e.cohortHiddenAttr){n.cohort.attributes.lst.find((t=>t.key==r)).isNumeric;const i=o[r];if(i){if(e.cohortHiddenAttr[r][i]){t=!0;break}}else if(e.cohortHiddenAttr[r].Unannotated){t=!0;break}}if(t)continue}}if(i.events&&e.spliceEventPercentage){let n=!1;for(const r in i.events){if(!t.events[r])continue;const o=t.events[r].attrValue,s=e.spliceEventPercentage[o];if(!s)continue;const a=i.events[r].percentage;if(null!=a)if(">"==s.side){if(a<=s.value){n=!0;break}}else if(a>=s.value){n=!0;break}}if(n)continue}o.push(i)}return o}function c(t,...e){if(0==t.length)return 0;const n=t.sort(((t,e)=>t.readcount-e.readcount)),r=[];return e.forEach((t=>{!Number.isFinite(t)||t<0||t>1?r.push(null):r.push(n[Math.floor(n.length*t)].readcount)})),r}t.exports=t=>async(e,n)=>{try{const[u,f,d]=await async function(t,e){const n=t.query;if(!n.genome)throw"genome missing";const s=e[n.genome];if(!s)throw"invalid genome";let a={},l={};if(n.iscustom)if(l.listsamples=!0,n.url)l.url=n.url,l.dir=await o.cache_index(n.url,n.indexURL);else if(n.file)l.file=i.join(r.tpmasterdir,n.file);else{if(!n.file2)throw"no file or url given";l.file2=i.join(r.tpmasterdir,n.file2)}else{if(!s.datasets)throw"genome is not equipped with datasets";if(!n.dslabel)throw"dslabel missing";if(a=s.datasets[n.dslabel],!a)throw"invalid dslabel";if(!a.queries)throw"dataset is not equipped with queries";if(!n.querykey)throw"querykey missing";if(l=a.queries[n.querykey],!l)throw"invalid querykey"}return[n,a,l]}(e,t),h=await async function(t,e,n){if(t.junction)return await async function(t,e,n){const r=t.junction;if(!r.chr||!Number.isInteger(r.start)||!Number.isInteger(r.stop))throw"incomplete/invalid info about querying junction";let i;if(await o.get_lines_bigfile({args:[a(n),r.chr+":"+r.start+"-"+r.stop],dir:n.dir,callback:o=>{const s=o.split("\t"),a=Number.parseInt(s[1]),c=Number.parseInt(s[2]);if(a==r.start&&c==r.stop)if(n.file2){i=[];for(let t=5;t<s.length;t++){const e=s[t];if(!e)continue;const n=Number.parseInt(e);Number.isNaN(n)||(n<=0||i.push({i:t-5,readcount:n}))}}else{const r=JSON.parse(s[5]);i=l(r,t,e,n)}}}),0==i.length)throw"no sample passing filters";const s={};if(n.listsamples){const t=i.map((t=>{const e={readcount:t.readcount};return t.anno?e.sample_name=t.anno.sample_name:e.i=t.i,e}));t.sort(((t,e)=>e.readcount-t.readcount)),t.length>100?(s.samples=t.slice(0,100),s.sampletotalnumber=t.length):s.samples=t}else if(n.singlejunctionsummary&&n.singlejunctionsummary.readcountboxplotpercohort){s.readcountboxplotpercohort=[];for(const t of n.singlejunctionsummary.readcountboxplotpercohort.groups){const e=new Map;for(const n of i){if(!n.anno)continue;const r=n.anno[t.key];null!=r&&(e.has(r)||e.set(r,[]),e.get(r).push(n))}if(0==e.size)continue;const n=[...e].sort(((t,e)=>e[1].length-t[1].length)),r=[];for(const[t,e]of n){let n=e[0].readcount,o=n;e.forEach((t=>{n=Math.min(n,t.readcount),o=Math.max(o,t.readcount)}));const i=c(e,.05,.25,.5,.75,.95);r.push({label:t,samplecount:e.length,percentile:{p05:i[0],p25:i[1],p50:i[2],p75:i[3],p95:i[4]},minvalue:n,maxvalue:o})}s.readcountboxplotpercohort.push({label:t.label,boxplots:r})}}return s}(t,e,n);if(t.readcountByjBsamples)return await async function(t,e,n){if(!t.junctionAposlst)throw".junctionAposlst[] missing";let r,i=t.junctionB.start,s=t.junctionB.stop;t.junctionAposlst.forEach((t=>{i=Math.min(i,t[0]),s=Math.max(s,t[1])}));let a=[];if(await o.get_lines_bigfile({args:[n.file||n.url,t.junctionB.chr+":"+i+"-"+s],dir:n.dir,callback:e=>{const n=e.split("\t"),o=Number.parseInt(n[1]),i=Number.parseInt(n[2]);if(o==t.junctionB.start&&i==t.junctionB.stop)r=JSON.parse(n[5]);else for(const[e,r]of t.junctionAposlst)if(e==o&&r==i){const t=JSON.parse(n[5]);t.start=o,t.stop=i,a.push(t);break}}}),!r)throw"jB not found";if(0==a.length)throw"none of jA is found";const u=l(r,t,e,n);if(0==u.length)throw"no sample passing filters for junctionB";const f=new Set;u.forEach((t=>f.add(t.i)));const d=[];for(const e of a){const n=[];for(const r of e.samples)f.has(r.i)&&(t.readcountCutoff&&r.readcount<t.readcountCutoff||n.push(r));d.push({start:e.start,stop:e.stop,v:Math.floor(c(n,.5))})}return{lst:d}}(t,e,n);const r={};if(t.iscustom&&t.getsamples){const t=await o.get_header_tabix(a(n),n.dir);if(t[0]){const e=t[0].split("\t");e.length>5&&(r.sample2client=e.slice(5))}}if(!t.rglst)throw"rglst missing";if(n.viewrangeupperlimit){if(t.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=n.viewrangeupperlimit)throw"zoom in under "+common.bplen(n.viewrangeupperlimit)+" to view details"}let i=0,u=0;const f=[],d=new Set,h=new Set;for(const r of t.rglst)await o.get_lines_bigfile({args:[a(n),r.chr+":"+r.start+"-"+r.stop],dir:n.dir,callback:o=>{const a=o.split("\t"),p=Number.parseInt(a[1]),m=Number.parseInt(a[2]);if(n.file2){a[3];const e=a[4];let n;if("known"==e)n="canonical";else{if("novel"!=e)throw"unknown rnapeg type: "+e;n=s}if(t.infoFilter&&t.infoFilter.type&&t.infoFilter.type[n])return;const o={chr:r.chr,start:p,stop:m,info:{type:{lst:[{attrValue:n}]}}},l=[];for(let t=5;t<a.length;t++){const e=a[t];if(!e)continue;const n=Number.parseInt(e);Number.isNaN(n)||(n<=0||(l.push({readcount:n}),i=Math.max(i,n)))}if(0==l.length)return;if(u++,o.sampleCount=l.length,1==o.sampleCount)o.medianReadCount=l[0].readcount;else{const t=c(l,.05,.25,.5,.75,.95);o.medianReadCount=t[2],o.readcountBoxplot={percentile:t}}f.push(o)}else{a[3],a[4];if(!(p>=r.start&&p<=r.stop||m>=r.start&&m<=r.stop))return;u++;const o={chr:r.chr,start:p,stop:m,info:{type:{lst:[]}}},g=JSON.parse(a[5]);if(g.sv){o.sv=g.sv;const t=o.chr+"."+o.start+"."+o.sv.mate.chr+"."+o.sv.mate.start;if(d.has(t))return;d.add(t),d.add(o.sv.mate.chr+"."+o.sv.mate.start+"."+o.chr+"."+o.start)}if(g.canonical&&o.info.type.lst.push({attrValue:"canonical"}),g.events)for(const t in g.events){const e=g.events[t];e.__ek=t,o.info.type.lst.push(e)}else g.canonical||o.info.type.lst.push({attrValue:s});if(t.infoFilter&&t.infoFilter.type)for(const e of o.info.type.lst)if(t.infoFilter.type[e.attrValue])return;const y=l(g,t,e,n);if(0==y.length)return;if((g.exonleft||g.exonright||g.exonleftin||g.exonrightin||g.intronleft||g.intronright||g.leftout||g.rightout)&&(o.ongene={},g.exonleft&&(o.ongene.exonleft=g.exonleft),g.exonright&&(o.ongene.exonright=g.exonright),g.exonleftin&&(o.ongene.exonleftin=g.exonleftin),g.exonrightin&&(o.ongene.exonrightin=g.exonrightin),g.intronleft&&(o.ongene.intronleft=g.intronleft),g.intronright&&(o.ongene.intronright=g.intronright),g.leftout&&(o.ongene.leftout=g.leftout),g.rightout&&(o.ongene.rightout=g.rightout)),y.forEach((t=>{h.add(t.i),i=Math.max(i,t.readcount)})),o.sampleCount=y.length,1==o.sampleCount)o.medianReadCount=y[0].readcount;else{const t=c(y,.05,.25,.5,.75,.95);o.medianReadCount=t[2],o.readcountBoxplot={percentile:t}}f.push(o)}}});r.lst=f,r.maxreadcount=i,r.junctiontotalnumber=u,h.size;return r}(u,f,d);n.send(h)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},2728:(t,e,n)=>{"use strict";n.r(e),n.d(e,{client_copy:()=>d,init_db:()=>u,init_track:()=>f});n(9699);const r=n(1017),o=(n(7147).promises,n(2081).spawn,n(3856)),i=n(394).server_init_db_queries,s=n(2235).r,a=n(334),{setDbRefreshRoute:l}=n(1883),c="Ancestry_PC_";async function u(t,e=null,s=null){var c,u;if(!t.cohort.termdb)throw"cohort.termdb missing when cohort.db is used";await async function(t){if(t.phewas){if(t.phewas.samplefilter4termtype&&t.phewas.samplefilter4termtype.condition&&!t.phewas.samplefilter4termtype.condition.filter)throw"filter{} missing from tdb.phewas.samplefilter4termtype.condition";if(t.phewas.comparison_groups){if(!Array.isArray(t.phewas.comparison_groups))throw"tdb.phewas.comparison_groups is not array";if(0==t.phewas.comparison_groups.length)throw"tdb.phewas.comparison_groups[] cannot be empty"}}if(t.selectCohort){if(!t.selectCohort.term)throw"term{} missing from termdb.selectCohort";if(!t.selectCohort.term.id)throw"id missing from termdb.selectCohort.term";if("string"!=typeof t.selectCohort.term.id)throw"termdb.selectCohort.term.id is not string";if("categorical"!=t.selectCohort.term.type)throw'type is not hardcoded "categorical" from termdb.selectCohort.term';if(!t.selectCohort.values)throw"values[] missing from termdb.selectCohort";if(!Array.isArray(t.selectCohort.values))throw"termdb.selectCohort.values is not array";if(0==t.selectCohort.values.length)throw"termdb.selectCohort.values[] cannot be empty";for(const e of t.selectCohort.values){if(!e.keys)throw"keys[] missing from one of selectCohort.values[]";if(!Array.isArray(e.keys))throw"keys[] is not array from one of selectCohort.values[]";if(0==e.keys.length)throw"keys[] is empty from one of selectCohort.values[]"}}if(t.restrictAncestries){if(!Array.isArray(t.restrictAncestries)||0==t.restrictAncestries.length)throw"termdb.restrictAncestries[] is not non-empty array";for(const e of t.restrictAncestries){if(!e.name)throw"name missing from one of restrictAncestries";if("object"!=typeof e.tvs)throw".tvs{} missing from one of restrictAncestries";if(!Number.isInteger(e.PCcount))throw"PCcount is not integer";if(e.PCfile)e.pcs=await h(e.PCfile,e.PCcount);else if(e.PCfileBySubcohort)for(const t in e.PCfileBySubcohort){const n=e.PCfileBySubcohort[t];if(!n.file)throw".file missing for a subcohort in PCfileBySubcohort";n.pcs=await h(n.file,e.PCcount)}}}}(t.cohort.termdb),await async function(t){if("scatterplots"in t)for(const e of t.scatterplots.plots){const t=r.join(a.tpmasterdir,e.file);await o.file_is_readable(t)}}(t.cohort),i(t),function(t){t.sampleName2Id=new Map,t.sampleId2Name=new Map;const e="SELECT * FROM sampleidmap",n=t.cohort.db.connection.prepare(e).all();for(const e of n)t.sampleId2Name.set(e.id,e.name),t.sampleName2Id.set(e.name,e.id);t.getSampleIdMap=e=>{const n={};for(const r in e)n[r]=t.sampleId2Name.get(+r);return n}}(t);const{mayGetGeneVariantData:f,getTermTypes:d,mayGetMatchingGeneNames:p}=n(7833);t.mayGetGeneVariantData=f,t.getTermTypes=d,t.mayGetMatchingGeneNames=p,null!==(c=t.cohort)&&void 0!==c&&null!==(u=c.db)&&void 0!==u&&u.refresh&&e&&l(t,e,s)}async function f(t,e){if(!t.track)throw"no mds2 track; missing ds.track{}";const n=t.track;n.name||(n.name=t.label),function(t){if(!t.populations)return;if(!Array.isArray(t.populations))throw"populations should be array";for(const e of t.populations){if(!e.key)throw"key missing from a population";if(e.label||(e.label=e.key),!Array.isArray(e.sets))throw".sets is not an array in population: "+e.key;for(const t of e.sets){if(!t.infokey_AC)throw"infokey_AC missing from a set of population: "+e.key;if(!t.infokey_AN)throw"infokey_AN missing from a set of population: "+e.key;if(e.termfilter&&!t.termfilter_value)throw"termfilter_value missing from a set of population where termfilter is set: "+e.key}}}(n),await async function(t,e,n){if(!t)return;if(!t.chr2bcffile)throw"vcftk.chr2bcffile is missing";{if("object"!=typeof t.chr2bcffile)throw"chr2bcffile not an object";for(const e in t.chr2bcffile)t.chr2bcffile[e]=r.join(a.tpmasterdir,t.chr2bcffile[e]);const n={file:t.chr2bcffile[e.defaultcoord.chr]};if(!n.file)throw"default chr missing from chr2bcffile";await o.init_one_vcf(n,e,!0),t.info=n.info,t.format=n.format,t.samples=n.samples,t.nochr=n.nochr}if(t.AD&&t.AD.chr2bcffile){if("object"!=typeof t.AD.chr2bcffile)throw"AD.chr2bcffile not an object";for(const e in t.AD.chr2bcffile)t.AD.chr2bcffile[e]=r.join(a.tpmasterdir,t.AD.chr2bcffile[e]);const i={file:t.AD.chr2bcffile[e.defaultcoord.chr]};if(!i.file)throw"default chr missing from AD.chr2bcffile";await o.init_one_vcf(i,e,!0),t.AD.info=i.info,t.AD.format=i.format,t.AD.samples=i.samples,t.AD.nochr=i.nochr,console.log(n.label+" vcf: AD: "+t.AD.samples.length+" samples");for(const e of t.AD.samples){const t=Number(e.name);if(!Number.isInteger(t))throw"non-integer vcf sample: "+e.name;e.name=t}}if(t.samples){for(const e of t.samples){const t=Number(e.name);if(!Number.isInteger(t))throw"non-integer vcf sample: "+e.name;e.name=t}console.log(n.label+" vcf: "+t.samples.length+" samples")}else console.log(n.label+" vcf: no samples");if(t.numerical_axis&&t.numerical_axis.info_keys){if(!Array.isArray(t.numerical_axis.info_keys))throw"numerical_axis.info_keys should be an array";for(const e of t.numerical_axis.info_keys){const n=t.info[e.key];if(!n)throw'INFO field "'+e.key+'" not found for numerical_axis';if("Float"!=n.Type&&"Integer"!=n.Type)throw'INFO field "'+e.key+'" from numerical_axis not of integer or float type';if("1"!=n.Number&&"A"!=n.Number)throw'for numerical axis, INFO field "'+e.key+'" only allows to be Number=1 or Number=A'}}if(t.plot_mafcov){if(!t.AD)throw".plot_mafcov enabled but .AD{} missing from vcf";if(!t.AD.samples)throw".plot_mafcov enabled but no samples from vcf";if(!t.AD.format)throw".plot_mafcov enabled but no FORMAT fields from vcf";if(!t.AD.format.AD)throw".plot_mafcov enabled but the AD FORMAT field is missing";if("R"!=t.AD.format.AD.Number)throw"AD FORMAT field Number=R is not true";if("Integer"!=t.AD.format.AD.Type)throw"AD FORMAT field Type=Integer is not true";if(t.plot_mafcov.overlay_term){if(!n.cohort)throw"ds.cohort missing when plot_mafcov.overlay_term defined";if(!n.cohort.termdb)throw"ds.cohort.termdb missing when plot_mafcov.overlay_term defined";if(!n.cohort.termdb.q)throw"ERR: termdb.q{} missing while trying to access termdb helper functions";if(!n.cohort.termdb.q.termjsonByOneid)throw"ERR: q.termjsonByOneid missing";const e=n.cohort.termdb.q.termjsonByOneid(t.plot_mafcov.overlay_term);if(!e)throw'unknown term id "'+t.plot_mafcov.overlay_term+'" from vcftk.plot_mafcov.overlay_term';t.plot_mafcov.overlay_term=e}}if(t.termdb_bygenotype){if(!t.samples)throw".termdb_bygenotype enabled but no samples from vcf";if(!t.format)throw".termdb_bygenotype enabled but no FORMAT fields from vcf";if(!t.format.GT)throw".termdb_bygenotype enabled but the GT FORMAT field is missing";if(!n.cohort)throw"termdb_bygenotype but ds.cohort missing";if(!n.cohort.termdb)throw"termdb_bygenotype but ds.cohort.termdb missing";if(t.termdb_bygenotype.getAF){if(!t.termdb_bygenotype.termid_sex)throw"termid_sex missing for getAF at termdb_bygenotype";if(!t.termdb_bygenotype.value_male)throw"value_male missing for getAF at termdb_bygenotype";const e=n.cohort.termdb.q.getSample2value(t.termdb_bygenotype.termid_sex);t.termdb_bygenotype.male_samples=new Set;for(const n of e)n.value==t.termdb_bygenotype.value_male&&t.termdb_bygenotype.male_samples.add(n.sample);if(!t.termdb_bygenotype.sex_chrs)throw"sex_chrs missing for getAF at termdb_bygenotype";if(!Array.isArray(t.termdb_bygenotype.sex_chrs))throw"sex_chrs is not array";t.termdb_bygenotype.sex_chrs=new Set(t.termdb_bygenotype.sex_chrs)}}if(t.samples){t.sample2arrayidx=new Map;for(const[e,n]of t.samples.entries())t.sample2arrayidx.set(n.name,e)}}(n.vcf,e,t),function(t){if(!t.info_fields)return;if(!Array.isArray(t.info_fields))throw"tk.info_fields is not array";for(const e of t.info_fields){if(!e.key)throw".key missing from one of tk.info_fields[]";if(t.vcf&&t.vcf.info&&!t.vcf.info[e.key])throw`info field ${e.key} missing from tk.vcf.info{}`;if(e.label||(e.label=e.key),e.iscategorical){if(!Array.isArray(e.values))throw".values[] not an array of categorical INFO field: "+e.key;for(const t of e.values){if(!t.key)throw"key missing from a value of categorical INFO: "+e.key;t.label||(t.label=t.key)}}else if(e.isfloat||e.isinteger){if(!e.range)throw".range{} missing from a numerical INFO: "+e.key;s(e.range,"tk.info_fields[]")}else if(!e.isflag)throw"tk.info_fields unknown type: "+e.key}}(n),await async function(t,e,n){if(!t)return;if(!Array.isArray(t.tracks))throw"ld.tracks[] not an array";if(0==t.tracks.length)throw"ld.tracks[] is empty array";for(const n of t.tracks){if(!n.name)throw".name missing from a ld track";if(!Number.isInteger(n.viewrangelimit))throw'viewrangelimit missing from ld track "'+n.name+'"';if(n.file)n.file.startsWith(a.tpmasterdir)||(n.file=r.join(a.tpmasterdir,n.file)),await o.validate_tabixfile(n.file),n.nochr=await o.tabix_is_nochr(n.file,null,e),console.log(n.file+": "+(n.nochr?"no chr":"has chr"));else if(!n.chr2file)throw"ld tk has no file or chr2file"}}(n.ld,e),await async function(t,e){if(!t)return}(n.svcnv,0),function(t){const e=new Set;if(t.vcf&&t.vcf.samples)for(const n of t.vcf.samples)e.add(n.name);t.svcnv;e.size&&(t.samples=[...e])}(n),n.samples&&console.log(t.label+": mds2: "+n.samples.length+" samples")}function d(t){const e=t.track,n={name:e.name,info_fields:e.info_fields,sample_termfilter:e.sample_termfilter};return e.vcf&&(n.vcf={numerical_axis:e.vcf.numerical_axis,format:e.vcf.format,info:e.vcf.info,check_pecanpie:e.vcf.check_pecanpie},e.vcf.plot_mafcov&&(n.vcf.plot_mafcov={},t.cohort&&t.cohort.termdb&&(n.vcf.plot_mafcov.overlay_term=e.vcf.plot_mafcov.overlay_term||{})),e.vcf.termdb_bygenotype&&(n.vcf.termdb_bygenotype=!0),e.populations&&(n.populations=e.populations)),e.ld&&(n.ld={tracks:e.ld.tracks.map((t=>({name:t.name,shown:t.shown}))),overlay:e.ld.overlay}),n}async function h(t,e){const n=new Map;for(let t=1;t<=e;t++)n.set(c+t,new Map);let i=0;for(const s of(await o.read_file(r.join(a.tpmasterdir,t))).trim().split("\n")){i++;const t=s.split("\t"),r=Number(t[0]);if(!Number.isInteger(r))throw"non-integer sample id from a line of restrictAncestries pc file";for(let o=1;o<=e;o++){const e=c+o,i=Number(t[o]);if(Number.isNaN(i))throw"non-numeric PC value from restrictAncestries file";n.get(e).set(r,i)}}return console.log(i,"samples loaded from "+t),Object.freeze(n)}},7510:(t,e,n)=>{n(9699),n(7147),n(1017);const r=n(3856),o=(n(2273),n(6280)),i=n(6234),s=n(2581);e.handle_request=t=>async(e,n)=>{const a=e.query;try{const e=t[a.genome],l=await async function(t,e){if(!e)throw"invalid genome";if(t.dslabel){const n=e.datasets[t.dslabel];if(!n)throw"invalid dslabel";if(!n.track)throw"no mds2 track found for dataset";return n}const n={iscustom:1,track:{}};t.vcf&&(n.track.vcf=t.vcf,await r.init_one_vcf(n.track.vcf,e));t.ld;return n}(a,e);if(a.trigger_overlayld)return await s.overlay(a,l,n);a.hidden_mclass&&(a.hidden_mclass=new Set(a.hidden_mclass));const c={mclass2count:{}};if(a.info_fields){c.info_fields={};for(const t of a.info_fields)if(t.iscategorical)c.info_fields[t.key]={value2count:{}};else if(t.isnumerical)c.info_fields[t.key]={filteredcount:0};else{if(!t.isflag)throw"unknown info type";c.info_fields[t.key]={count_yes:0,count_no:0}}}if(a.trigger_mafcovplot&&await i.plot(a,e,l,c),a.trigger_vcfbyrange&&(await o.handle_vcfbyrange(a,e,l,c),a.trigger_ld)){c.__mposset=new Set;for(const t of c.vcf.rglst)if(t.variants)for(const e of t.variants)c.__mposset.add(e.pos)}if(a.trigger_ld){c.ld={};for(const t of a.trigger_ld.tracks)await s.load_tk(t,a,e,l,c);delete c.__mposset}a.trigger_ssid_onevcfm&&await o.handle_ssidbyonem(a,e,l,c),a.trigger_getvcfcsq&&await o.handle_getcsq(a,e,l,c),n.send(c)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},2581:(t,e,n)=>{"use strict";n.r(e),n.d(e,{load_tk:()=>s,overlay:()=>l});n(7147),n(1017),n(2081).spawn;const r=n(3856),o=n(6718).createCanvas,i=n(2273).bplen;async function s(t,e,n,o,s){const l=o.track.ld.tracks.find((e=>e.name==t.name));if(!l)throw"ld track not found by name: "+t.name;if(!e.rglst)throw"rglst missing";s.ld[l.name]={rglst:[]};const c=e.trigger_ld.connheight||50;for(const t of e.rglst){const e={chr:t.chr,start:t.start,stop:t.stop,width:t.width,reverse:t.reverse,xoff:t.xoff};if(s.ld[l.name].rglst.push(e),t.stop-t.start>=l.viewrangelimit){e.rangetoobig="Zoom in under "+i(l.viewrangelimit)+" to view LD data";continue}const n=[],o=new Set,u=(l.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop;await r.get_lines_bigfile({args:[l.file,u],dir:l.dir,callback:e=>{const r=e.split("\t"),i=Number.parseInt(r[1]);if(i<t.start)return;const a=Number.parseInt(r[2]);if(a>t.stop)return;if(s.__mposset){if(!s.__mposset.has(i))return;if(!s.__mposset.has(a))return}const l=Number.parseFloat(r[5]);n.push({start:i,stop:a,r2:l}),o.add(i),o.add(a)}}),e.img=a(t,n,o,c)}}function a(t,e,n,r){const[i,s]=function(t,e){let n=t.width/e.size,r=0;n>40&&(n=40,r=(t.width-n*e.size)/2);const o=new Map,i=t.reverse?[...e].sort(((t,e)=>e-t)):[...e].sort(((t,e)=>t-e));let s=r;for(const t of i)o.set(t,s+n/2),s+=n;return[n,o]}(t,n),a=new Map;{const e=(t.stop-t.start)/t.width;for(const r of n)t.reverse?a.set(r,(t.stop-r)/e):a.set(r,(r-t.start)/e)}let l=0;for(const t of e)l=Math.max(l,(s.get(t.stop)-s.get(t.start))/2);const c=r+l+i/2,u=o(t.width,c),f=u.getContext("2d");f.strokeStyle="black";for(const t of n)f.beginPath(),f.moveTo(a.get(t),0),f.lineTo(s.get(t),r),f.closePath(),f.stroke();for(const t of e){const e=s.get(t.start),n=s.get(t.stop),o=(e+n)/2,a=r+Math.abs(n-e)/2,l=Math.floor(255*(1-t.r2));f.fillStyle="rgb(255,"+l+","+l+")",f.beginPath(),f.moveTo(o,a-i/2),f.lineTo(o-i/2,a),f.lineTo(o,a+i/2),f.lineTo(o+i/2,a),f.lineTo(o,a-i/2),f.closePath(),f.fill()}return{height:c,src:u.toDataURL()}}async function l(t,e,n){if(!t.ldtkname)throw".ldtkname missing";const o=e.track.ld.tracks.find((e=>e.name==t.ldtkname));if(!o)throw"ld tk not found by name: "+t.ldtkname;const i=t.m.ref+"."+t.m.alt,s=(o.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+t.m.pos+"-"+(t.m.pos+1),a=[];await r.get_lines_bigfile({args:[o.file,s],dir:o.dir,callback:e=>{const n=e.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),s=n[3],l=n[4],c=Number.parseFloat(n[5]);r==t.m.pos&&s==i?a.push({pos:o,alleles:l,r2:c}):o==t.m.pos&&l==i&&a.push({pos:r,alleles:s,r2:c})}}),n.send({lst:a})}},6280:(t,e,n)=>{"use strict";n.r(e),n.d(e,{handle_getcsq:()=>p,handle_ssidbyonem:()=>f,handle_vcfbyrange:()=>d});n(7147);const r=n(1017),o=(n(2081).spawn,n(3856)),i=n(6819),s=n(2273),a=n(2852),l=n(9157),c=n(334),u="%CHROM\t%POS\t%ID\t%REF\t%ALT\t%QUAL\t%FILTER\t%INFO";async function f(t,e,n,s){if(n.iscustom)throw"custom ds not allowed";const a=n.track.vcf;if(!a)throw"ds.track.vcf missing";if(!t.m)throw"q.m missing";const l=(a.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),f=a.chr2bcffile[t.m.chr];if(!f)throw"chr not in chr2bcffile";let d;if(await o.get_lines_bigfile({isbcf:!0,args:["query",f,"-r",l,"-f",u+"\t%FORMAT\n"],dir:a.dir,callback:e=>{const[n,r,o]=i.vcfparseline(e,a);for(const e of r)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(d=e)}}),!d)throw"variant not found";const h=[],p=[],m=[];for(const e of d.sampledata){if(!e.genotype)continue;const n=-1!=e.genotype.indexOf(t.m.ref),r=-1!=e.genotype.indexOf(t.m.alt);n?r?p.push(e.sampleobj.name):h.push(e.sampleobj.name):r&&m.push(e.sampleobj.name)}const g=Math.random().toString();s.ssid=g,s.groups={};const y=[];if(h.length){const t="Homozygous reference";s.groups[t]={size:h.length},y.push(t+"\t"+h.join(","))}if(p.length){const t="Heterozygous";s.groups[t]={size:p.length},y.push(t+"\t"+p.join(","))}if(m.length){const t="Homozygous alternative";s.groups[t]={size:m.length},y.push(t+"\t"+m.join(","))}await o.write_file(r.join(c.cachedir_ssid,g),y.join("\n"))}async function d(t,e,n,f){if(!t.rglst)throw".rglst[] missing";const d=n.track.vcf;if(!d)throw"ds.track.vcf missing";const p={info:d.info,format:d.format,samples:d.samples};await async function(t,e,n){if(t.querymode={},t.AFtest){if(n.iscustom)throw"custom track does not support AFtest";for(const e of t.AFtest.groups)if(!e.is_infofield)if(e.is_termdb)e.columnidx=await h(e.filter,n);else{if(!e.is_population)throw"Cannot set query mode: unknown group type";{if(!n.track.populations)throw"ds.track.populations missing";const r=n.track.populations.find((t=>t.key==e.key));if(!r)throw"unknown population key: "+e.key;if(e.population=JSON.parse(JSON.stringify(r)),t.AFtest.termfilter&&t.AFtest.termfilter[0].term.id==e.population.termfilter){const n=e.population.sets.find((e=>e.termfilter_value==t.AFtest.termfilter[0].values[0].key));if(!n)throw"no matching set found for a termfilter from a population";e.population.sets=[n]}}}if(t.AFtest.testby_fisher&&t.AFtest.groups.find((t=>t.is_infofield)))throw"cannot do fisher test for an INFO field";{const e=t.AFtest.groups.find((t=>t.is_population));if(e&&e.adjust_race){const r=t.AFtest.groups.find((t=>t.is_termdb));if(!r)throw"cannot adjust race: termdb group missing";r.pop2average=await async function(t,e,n,r){const o=new Map;let i=0;for(const e of t){const t={infokey_AC:e.infokey_AC,infokey_AN:e.infokey_AN,average:0},r=await a.get_rows_by_one_key({ds:n,key:e.key});for(const e of r){if(!n.track.vcf.sample2arrayidx.has(e.sample))continue;const r=Number(e.value);Number.isFinite(r)&&(t.average+=r,i+=r)}o.set(e.key,t)}for(const[t,e]of o)e.average/=i;return o}(e.population.sets,r.columnidx,n)}}return void(t.querymode.range_AFtest=!0)}t.querymode.range_variantonly=!0}(t,0,n),function(t,e){if(e.querymode.range_variantonly||e.querymode.range_AFtest){delete t.samples;for(const t of e.rglst)t.variants=[]}e.bcfformat=u,e.exportgenotype||e.querymode.range_AFtest?e.bcfformat+="\t%FORMAT\n":e.querymode.range_variantonly&&(e.querymode.slicecolumnindex||(e.bcfformat+="\\n"))}(p,t),t.exportgenotype&&(f.mlst=[]),function(t,e){const n=(r=t.rglst[0],r.usegm_isoform?{gmmode:"protein",usegm:{isoform:r.usegm_isoform}}:{});var r;t.m_is_filtered=r=>{let o=!1;if(t.info_fields)for(const n of t.info_fields){const t=e.info_fields[n.key];let i;if(r.info&&(i=r.info[n.key]),null==i&&r.altinfo&&(i=r.altinfo[n.key]),n.iscategorical)null==i?(t.unannotated_count=1+(t.unannotated_count||0),n.unannotated_ishidden&&(o=!0)):(t.value2count[i]=1+(t.value2count[i]||0),n.hiddenvalues[i]&&(o=!0));else if(n.isnumerical)null==i&&null!=n.missing_value&&(i=n.missing_value),n.range.startunbounded||(n.range.startinclusive?i<n.range.start&&(o=!0):i<=n.range.start&&(o=!0)),n.range.stopunbounded||(n.range.stopinclusive?i>n.range.stop&&(o=!0):i>=n.range.stop&&(o=!0)),o&&t.filteredcount++;else{if(!n.isflag)throw"unknown info type";i?t.count_yes++:t.count_no++,(n.remove_yes&&i||n.remove_no&&!i)&&(o=!0)}}return!!o||(s.vcfcopymclass(r,n),e.mclass2count[r.class]=(e.mclass2count[r.class]||0)+1,t.hidden_mclass&&t.hidden_mclass.has(r.class)&&(o=!0),o)}}(t,f);for(const e of t.rglst){if(d.viewrangeupperlimit&&e.stop-e.start>=d.viewrangeupperlimit){e.rangetoobig="Zoom in under "+s.bplen(d.viewrangeupperlimit)+" to view VCF data";continue}const n=(d.nochr?e.chr.replace("chr",""):e.chr)+":"+e.start+"-"+e.stop,r=d.chr2bcffile[e.chr];if(!r)throw"chr not found in chr2bcffile";await o.get_lines_bigfile({isbcf:!0,args:["query",r,"-r",n,"-f",t.bcfformat],dir:d.dir,callback:y(e)})}function y(e){return n=>{if(t.exportgenotype){const e=n.split("\t"),[r,o,s]=i.vcfparseline(e.slice(0,8).join("\t"),p);for(const n of o){if(t.m_is_filtered(n))continue;const r=[n.chr+"."+(n.pos+1)+"."+n.ref+"."+n.alt,n.name||""];for(let t=9;t<e.length;t++){const o=e[t].split(":",1)[0];if("."==o){r.push(".");continue}const i=o.split(-1==o.indexOf("/")?"|":"/");r.push(("0"==i[0]?n.ref:n.alt)+("0"==i[1]?n.ref:n.alt))}f.mlst.push(r.join("\t"))}return}let r;if(t.querymode.range_variantonly)if(t.querymode.slicecolumnindex);else{const[e,o,s]=i.vcfparseline(n,p);r=[];for(const e of o)t.m_is_filtered(e)||r.push(e)}else t.querymode.range_AFtest&&(r=function(t,e,n,r){const o=t.split("\t"),[s,a,l]=i.vcfparseline(o.slice(0,8).join("\t"),n),c=a.filter((t=>!e.m_is_filtered(t)));if(0==c.length)return;const u=[o[3],...o[4].split(",")],f=[];for(const t of c){const n=g(o,t,u,e);if(m(n)){if(f.push(t),e.AFtest.testby_AFdiff){for(const t of n)if(t.is_infofield)t.v=t.infofieldvalue;else{if(!t.is_termdb&&!t.is_population)throw"unknown group type";t.v=t.altcount/(t.refcount+t.altcount)}t.AFtest_group_values=[n[0].v,n[1].v],t.nm_axis_value=n[0].v-n[1].v}else e.AFtest.testby_fisher&&(t.contigencytable=[n[0].altcount,n[0].refcount,n[1].altcount,n[1].refcount]);{const r=e.AFtest.groups.find((t=>t.is_population));if(r&&r.adjust_race){const e=n.find((t=>t.is_population));t.popsetadjvalue=[];for(const[n,r]of e.set2value)t.popsetadjvalue.push([n,r.ACraw,r.ANraw-r.ACraw,Number.parseInt(r.ACadj),Number.parseInt(r.ANadj-r.ACadj)])}}}}return f}(n,t,p));if(r)for(const t of r)t.csq&&(t.csq_count=t.csq.length,delete t.csq),delete t._m,delete t.vcf_ID,delete t.sampledata,d.nochr&&(t.chr="chr"+t.chr),e.variants.push(t)}}await async function(t){if(!t.querymode.range_AFtest)return;if(!t.AFtest.testby_fisher)return;const e=[],n={};for(const r of t.rglst)if(r.variants)for(const t of r.variants)if(t.contigencytable){const r=t.chr+"."+t.pos+"."+t.ref+"."+t.alt;e.push(r+"\t"+t.contigencytable.join("\t")),n[r]=t}if(0==e.length)return;const o=await l(r.join(c.binpath,"/utils/fisher.R"),e);for(const t of o){const e=t.split("\t"),r=n[e[0]];if(r){const t=Number.parseFloat(e[5]);r.AFtest_pvalue=t,r.nm_axis_value=Number.isNaN(t)?0:-Math.log10(t)}}}(t),function(t,e,n,r){if(e.exportgenotype)return t.exportgenotype="variant\tSNP\t"+n.samples.map((t=>r.cohort.termdb.id2sampleName(t.name))).join("\t")+"\n"+t.mlst.join("\n"),void delete t.mlst;t.vcf={rglst:[]};for(const n of e.rglst){const e={chr:n.chr,start:n.start,stop:n.stop,width:n.width,reverse:n.reverse,xoff:n.xoff};t.vcf.rglst.push(e),n.rangetoobig?(e.rangetoobig=n.rangetoobig,delete n.rangetoobig):n.variants?(e.variants=n.variants,delete n.variants):n.canvas&&(e.img=n.canvas.toDataURL(),delete n.canvas)}if(e.AFtest&&e.AFtest.groups.find((t=>t.is_termdb))){t.AFtest_termdbgroup=[];let n=e.AFtest.groups[0];if(n.is_termdb&&(t.AFtest_termdbgroup[0]={samplecount:n.columnidx.length},n.pop2average)){t.AFtest_termdbgroup[0].popsetaverage=[];for(const[e,r]of n.pop2average)t.AFtest_termdbgroup[0].popsetaverage.push([e,r.average])}if(n=e.AFtest.groups[1],n.is_termdb&&(t.AFtest_termdbgroup[1]={samplecount:n.columnidx.length},n.pop2average)){t.AFtest_termdbgroup[1].popsetaverage=[];for(const[e,r]of n.pop2average)t.AFtest_termdbgroup[1].popsetaverage.push([e,r.average])}}}(f,t,d,n)}async function h(t,e){if(!e.track)throw"ds.track{} missing";return(await a.get_samples(t,e)).reduce(((t,n)=>{const r=e.track.vcf.sample2arrayidx.get(n);return r>=0&&t.push(r),t}),[])}async function p(t,e,n,r){const s=n.track.vcf;if(!s)throw"ds.track.vcf missing";if(!t.m)throw"q.m missing";const a=(s.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),l=s.chr2bcffile[t.m.chr];if(!l)throw"chr not in chr2bcffile";await o.get_lines_bigfile({isbcf:!0,args:["query",l,"-r",a,"-f",u+"\\n"],dir:s.dir,callback:e=>{const[n,o,a]=i.vcfparseline(e,s);for(const e of o)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(r.csq=e.csq)}})}function m(t){if(t.find((t=>t.is_infofield)))return!0;return t[0].altcount+t[1].altcount>0}function g(t,e,n,r){return r.AFtest.groups.reduce(((o,i)=>{if(i.is_infofield)o.push({is_infofield:!0,infofieldvalue:y(e,i)});else if(i.is_termdb){const r=function(t,e,n){let r=!0;const o=new Map;for(const e of t)o.set(e,0);for(const i of n){if(!e[9+i])continue;const n=e[9+i].split(":")[0];"."!=n&&n.split(-1==n.indexOf("/")?"|":"/").forEach((e=>{const n=Number.parseInt(e);if(Number.isNaN(n))return;const i=t[n];i&&(0!=n&&(r=!1),o.set(i,1+o.get(i)))}))}return{allref:r,alleles:o}}(n,t,i.columnidx);o.push({is_termdb:!0,allref:r.allref,refcount:r.alleles.get(e.ref)||0,altcount:r.alleles.get(e.alt)||0})}else{if(!i.is_population)throw"unknown group type";{const t=new Map;for(const n of i.population.sets)t.set(n.key,{ACraw:y(e,{key:n.infokey_AC,missing_value:0}),ANraw:y(e,{key:n.infokey_AN,missing_value:0})});let n=0,s=0;if(i.adjust_race)[n,s]=function(t,e){if(!e)throw"group_termdb missing";if(!e.pop2average)throw"group_termdb.pop2average missing";let n=0;for(const e of t.values())n+=e.ANraw;let r=0,o=0;for(const[i,s]of t)s.ANadj=n*e.pop2average.get(i).average,s.ACadj=0==s.ANadj?0:s.ACraw*s.ANadj/s.ANraw,r+=s.ACadj,o+=s.ANadj;return[o-r,r]}(t,r.AFtest.groups.find((t=>t.is_termdb)));else for(const e of t.values())s+=e.ACraw,n+=e.ANraw-e.ACraw;o.push({is_population:!0,refcount:n,altcount:s,set2value:t})}}return o}),[])}function y(t,e){if(t.info){const n=t.info[e.key];if(null!=n)return n}if(t.altinfo){const n=t.altinfo[e.key];if(null!=n)return n}return e.missing_value}},6234:(t,e,n)=>{"use strict";n.r(e),n.d(e,{plot:()=>l});const r=n(3856),o=n(6819),i=n(2282),s=n(2852),a="#aaa";async function l(t,e,n,l){try{if(!n.track)throw"ds.track missing";const e=n.track.vcf;if(!e)throw"ds.track.vcf missing";if(n.iscustom)e.plot_mafcov={show_samplename:1};else if(!e.plot_mafcov)throw"maf-cov plot is not supported on this track";if(!t.m)throw".m{} missing";if(!e.AD)throw"vcf.AD{} missing";const c=(e.AD.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),u=e.AD.chr2bcffile[t.m.chr];if(!u)throw"chr not in tk.AD.chr2bcffile";let f;if(await r.get_lines_bigfile({isbcf:!0,args:["query","-r",c,"-f","%CHROM\t%POS\t%ID\t%REF\t%ALT\t%QUAL\t%FILTER\t%INFO\t%FORMAT\n",u],dir:e.AD.dir,callback:n=>{const[r,i,s]=o.vcfparseline(n,e.AD);for(const e of i)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(f=e)}}),!f)throw"variant not found";if(l.plotgroups=function(t,e,n){const r=[],o={name:"?",lst:[]};for(const r of t.sampledata){const i=r.AD[t.ref]||0,s=r.AD[t.alt]||0,a=i+s,l={mut:s,total:i+s,maf:0==a?0:s/a};e.plot_mafcov.show_samplename&&(l.sampleobj={name:n.cohort.termdb.q.id2sampleName(r.sampleobj.name)}),o.lst.push(l)}return r.push(o),r}(f,e,n),t.overlay_term){const e=await s.get_rows({ds:n,term1_id:t.overlay_term,term1_q:t.overlay_term_q}),r=new Map;for(const t of e.lst)r.set(t.sample,t.key1);const o=i.scaleOrdinal(i.schemeCategory10),c=new Map;let u=0;for(const t of l.plotgroups)for(const e of t.lst){const t=r.get(e.sampleobj.name);if(t){const n=o(t);e.sampleobj.color=n,c.has(t)||c.set(t,{count:0,color:n,label:t}),c.get(t).count++}else u++,e.sampleobj.color=a}if(l.categories=[],e.CTE1&&e.CTE1.name2bin)for(const t of e.CTE1.name2bin.keys()){const e=c.get(t);e&&l.categories.push(e)}else for(const[t,e]of c)l.categories.push(e);u&&l.categories.push({count:u,color:a,label:"Unannotated"})}}catch(t){l.error=t.message||t,t.stack&&console.log(t.stack)}}},9402:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_densityplot:()=>i});const r=n(2282).scaleLinear,{violinBinsObj:o}=n(7011);async function i(t,e){const n=[];let i=null,s=null;for(const r of e.map((e=>e[t.id]))){var a,l;if(null!==(a=t.values)&&void 0!==a&&null!==(l=a[r])&&void 0!==l&&l.uncomputable)continue;const e=Number(r);Number.isFinite(e)&&(n.push(e),null===i?i=s=e:(i=Math.min(i,e),s=Math.max(s,e)))}const c=r().domain([i,s]).range([10,510]),u=o(c,{values:n});if(!Array.isArray(u.bins))throw"violinBins does not return {bins[]}";if(0==u.bins.length)throw"violinBins {bins[]} empty array";const f={minvalue:i,maxvalue:s,densitymax:0,density:[],samplecount:n.length,unit:t.unit};for(const t of u.bins){if(!Number.isFinite(t.x0))throw"b.x0 not number";if(!Number.isFinite(t.x1))throw"b.x1 not number";if(!Number.isFinite(t.binValueCount))throw"b.binValueCount not number";f.density.push([(t.x0+t.x1)/2,t.binValueCount]),f.densitymax=Math.max(f.densitymax,t.binValueCount)}return f}},9432:(t,e)=>{function n(t){const e=t.split(".");return"case"==e[0]&&(e[0]="cases"),e.join(".")}e.P=t=>{const e={op:"and",content:[]};if(!Array.isArray(t.lst))throw"filter.lst[] not array";for(const r of t.lst){if("tvs"!=r.type)throw'filter.lst[] item.type!="tvs"';if(!r.tvs)throw"item.tvs missing";if(!r.tvs.term)throw"item.tvs.term missing";if(r.tvs.values){const t={op:"in",content:{field:n(r.tvs.term.id),value:r.tvs.values.map((t=>t.key))}};e.content.push(t)}else if(r.tvs.ranges)for(const t of r.tvs.ranges)t.startunbounded?e.content.push({op:t.stopinclusive?"<=":"<",content:{field:n(r.tvs.term.id),value:t.stop}}):t.stopunbounded?e.content.push({op:t.startinclusive?">=":">",content:{field:n(r.tvs.term.id),value:t.start}}):e.content.push({op:"and",content:[{op:t.startinclusive?">=":">",content:{field:n(r.tvs.term.id),value:t.start}},{op:t.stopinclusive?"<=":"<",content:{field:n(r.tvs.term.id),value:t.stop}}]})}return e}},5243:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_termlst2size:()=>T,handle_filter2topGenes:()=>R,handle_gdc_ssms:()=>O,querySamples_gdcapi:()=>N,validate_m2csq:()=>C,validate_query_geneCnv:()=>b,validate_query_geneCnv2:()=>_,validate_query_singleSampleMutation:()=>j,validate_query_snvindel_byisoform:()=>p,validate_query_snvindel_byisoform_2:()=>m,validate_query_snvindel_byrange:()=>h,validate_ssm2canonicalisoform:()=>f,validate_variant2sample:()=>d});const r=n(2273),o=n(6452),i=n(1017),{get_crosstabCombinations:s,combineSamplesById:a}=n(817),l=n(9432).P,c=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",u=c+(c.includes("/v0")?"":"/v0")+"/graphql";async function f(t){const e=["consequence.transcript.is_canonical","consequence.transcript.transcript_id"];t.get=async t=>{if(!t.ssm_id)throw".ssm_id missing";const n=await o(c+"/ssms/"+t.ssm_id+"?fields="+e.join(","),{method:"GET",headers:x(t)});let r;try{r=JSON.parse(n.body)}catch(t){throw"invalid json in response"}if(!r.data||!r.data.consequence)throw"returned data not .data.consequence";if(!Array.isArray(r.data.consequence))throw".data.consequence not array";const i=r.data.consequence.find((t=>t.transcript.is_canonical));return i?i.transcript.transcript_id:r.data.consequence[0].transcript.transcript_id}}function d(t){if("function"!=typeof t.filters)throw".variant2samples.gdcapi.filters() not a function"}function h(t){const e=t.queries.snvindel.byrange.gdcapi;if(!e.query)throw".query missing for byrange.gdcapi";if("string"!=typeof e.query)throw".query not string in byrange.gdcapi";if("function"!=typeof e.variables)throw".byrange.gdcapi.variables() not a function";t.queries.snvindel.byrange.get=async n=>{const i=await o.post(u,{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:e.query,variables:e.variables(n)})});let s;try{s=JSON.parse(i.body)}catch(t){throw"invalid JSON from GDC"}if(!(s.data&&s.data.explore&&s.data.explore.ssms&&s.data.explore.ssms.hits&&s.data.explore.ssms.hits.edges))throw"returned structure not data.explore.ssms.hits.edges";if(!Array.isArray(s.data.explore.ssms.hits.edges))throw"data.explore.ssms.hits.edges not array";const a=[];for(const e of s.data.explore.ssms.hits.edges){const o={dt:r.dtsnvindel,ssm_id:e.node.ssm_id,chr:e.node.chromosome,pos:e.node.start_position-1,ref:e.node.reference_allele,alt:e.node.tumor_allele,samples:[]};if(e.node.consequence&&e.node.consequence.hits&&e.node.consequence.hits.edges){let t;o.csqcount=e.node.consequence.hits.edges.length,n.isoform&&(t=e.node.consequence.hits.edges.find((t=>t.node.transcript.transcript_id==n.isoform)));v(o,(t||e.node.consequence.hits.edges[0]).node)}if(e.node.occurrence.hits.edges)for(const n of e.node.occurrence.hits.edges){const e=y(n.node.case,t);e.sample_id=n.node.case.case_id,o.samples.push(e)}a.push(o)}return a}}function p(t){t.queries.snvindel.byisoform.get=async e=>{const n=g(e,t),s=await async function(t,e){if(!t.isoform)throw"snvindel_byisoform: .isoform missing";if("string"!=typeof t.isoform)throw".isoform value not string";const n=F,r=L,s=x(t),a=o.post(i.join(c,n.endpoint),{headers:s,body:JSON.stringify({size:n.size,fields:n.fields.join(","),filters:n.filters(t)})}),l=o.post(i.join(c,r.endpoint),{headers:s,body:JSON.stringify({size:r.size,fields:r.fields.join(","),filters:r.filters(t,e)})}),[u,f]=await Promise.all([a,l]);let d,h;try{d=JSON.parse(u.body),h=JSON.parse(f.body)}catch(t){throw"invalid JSON returned by GDC"}if(!d.data||!d.data.hits)throw"query1 did not return .data.hits";if(!h.data||!h.data.hits)throw"query2 did not return .data.hits[]";if(!Array.isArray(d.data.hits)||!Array.isArray(h.data.hits))throw"re.data.hits[] is not array";const p=new Map;for(const e of d.data.hits){if(!e.ssm_id)throw"ssm_id missing from a ssms hit";if(!e.consequence)throw".consequence[] missing from a ssm";if(!Number.isInteger(e.start_position))throw"hit.start_position is not integer";e.csqcount=e.consequence.length;const n=e.consequence.find((e=>e.transcript.transcript_id==t.isoform));e.consequence=n,e.cases=[],p.set(e.ssm_id,e)}for(const t of h.data.hits){if(!t.ssm)throw".ssm{} missing from a case";if(!t.ssm.ssm_id)throw".ssm.ssm_id missing from a case";const e=p.get(t.ssm.ssm_id);if(!e)throw"ssm_id not found in ssms query";if(!t.case)throw".case{} missing from a case";e.cases.push(t.case)}return[...p.values()]}(e,t),a=[];for(const n of s){const o={ssm_id:n.ssm_id,dt:r.dtsnvindel,chr:n.chromosome,pos:n.start_position-1,ref:n.reference_allele,alt:n.tumor_allele,isoform:e.isoform,csqcount:n.csqcount};if(v(o,n.consequence),!e.hiddenmclass||!e.hiddenmclass.has(o.class)){o.samples=[];for(const r of n.cases){const n={sample_id:await S(r,t,e.useCaseid4sample)};r.case_id&&(n["case.case_id"]=r.case_id),o.samples.push(n)}a.push(o)}}if(n){e.isoform=n;for(const t of a)t.isoform=n}return a}}function m(t){const e=t.queries.snvindel.byisoform.gdcapi;if(!e.query)throw".query missing for byisoform.gdcapi";if(!e.filters)throw".filters missing for byisoform.gdcapi";if("function"!=typeof e.filters)throw"byisoform.gdcapi.filters() is not function";t.queries.snvindel.byisoform.get=async n=>{const i=g(n,t),s=x(n),a=await o.post(e.apihost,{headers:s,body:JSON.stringify({query:e.query,variables:e.filters(n)})}),l=JSON.parse(a.body);if(!(l.data&&l.data.analysis&&l.data.analysis.protein_mutations&&l.data.analysis.protein_mutations.data))throw"data not .data.analysis.protein_mutations.data";const c=JSON.parse(l.data.analysis.protein_mutations.data);if(!c.hits)throw"re.hits missing";const u=[];for(const t of c.hits){const e=t._source,o={ssm_id:e.ssm_id,dt:r.dtsnvindel,chr:e.chromosome,pos:e.start_position-1,ref:e.reference_allele,alt:e.tumor_allele,isoform:n.isoform,occurrence:t._score,csqcount:e.consequence.length};v(o,e.consequence.find((t=>t.transcript.transcript_id==n.isoform))),u.push(o)}if(i){n.isoform=i;for(const t of u)t.isoform=i}return u}}function g(t,e){if(!t.isoform)return;let n;if("N"==t.isoform[0]&&e.refseq2ensembl_query){const r=e.refseq2ensembl_query.get(t.isoform);r&&(n=t.isoform,t.isoform=r.ensembl)}return n}function y(t,e){const n={};if(e.sampleSummaries)for(const r of e.sampleSummaries.lst){{const o=e.cohort.termdb.q.termjsonByOneid(r.label1);if(o){n[r.label1]=t[o.fields[0]];for(let t=1;t<o.fields.length;t++)n[r.label1]&&(n[r.label1]=n[r.label1][o.fields[t]])}}if(r.label2){const o=e.cohort.termdb.q.termjsonByOneid(r.label2);if(o){n[r.label2]=t[o.fields[0]];for(let t=1;t<o.fields.length;t++)n[r.label2]&&(n[r.label2]=n[r.label2][o.fields[t]])}}}return n}function v(t,e){if(e&&e.transcript.consequence_type){const[n,o,i]=r.vepinfo(e.transcript.consequence_type);t.class=o,t.mname=e.transcript.aa_change}t.mname||(t.mname=t.ref+">"+t.alt),t.class||(r.basecolor[t.ref]&&r.basecolor[t.alt]?t.class=r.mclasssnv:"-"==t.ref?t.class=r.mclassinsertion:"-"==t.alt?t.class=r.mclassdeletion:t.class=r.mclassmnv)}function b(t){const e=["cnv_id","cnv_change","gene_level_cn","occurrence.case.submitter_id","consequence.gene.symbol"];function n(t){const n=e.slice();if(t.twLst)for(const e of t.twLst){let t=e.term.id;t.startsWith("case.")&&(t="occurrence."+t),n.push(t)}return n.join(",")}function s(t){if(!t.gene&&"string"!=typeof t.gene)throw"p.gene does not provide non-empty string";const e={op:"and",content:[]};return t.gene&&e.content.push({op:"=",content:{field:"consequence.gene.symbol",value:t.gene.split(",")}}),t.filter0&&e.content.push(function(t){const e="string"==typeof t?t:JSON.stringify(t);return JSON.parse(e.replace('"cases.case_id"','"occurrence.case.case_id"'))}(t.filter0)),t.filterObj&&e.content.push(l("string"==typeof t.filterObj?JSON.parse(t.filterObj):t.filterObj)),e}t.queries.geneCnv.bygene.get=async t=>{var e;const a=x(t),l=await o.post(i.join(c,"cnvs"),{headers:a,body:JSON.stringify({size:1e5,fields:n(t),filters:s(t)})}),u=JSON.parse(l.body);if(!Array.isArray(null==u||null===(e=u.data)||void 0===e?void 0:e.hits))throw"geneCnv response body is not {data:hits[]}";const f=[];for(const e of u.data.hits){if(!e.gene_level_cn)throw"hit.gene_level_cn is not true";if(!e.cnv_id)throw"hit.cnv_id missing";const n={ssm_id:e.cnv_id,dt:r.dtcnv,samples:[]};if("Gain"==e.cnv_change?n.class=r.mclasscnvgain:"Loss"==e.cnv_change?n.class=r.mclasscnvloss:(console.log("cnv_change not Gain/Loss"),n.class=e.cnv_change),!Array.isArray(e.occurrence))throw"hit.occurrence[] not array";for(const r of e.occurrence){if(!r.case)throw"hit.occurrence[].case{} missing";if(!r.case.submitter_id)throw"hit.occurrence[].case.submitter_id missing";const e={sample_id:r.case.submitter_id};if(t.twLst)for(const n of t.twLst)k(e,r.case,n);n.samples.push(e)}f.push(n)}return f}}function _(t){const e=["cnv.cnv_change","cnv.gene_level_cn","cnv.consequence.gene.symbol","case.submitter_id","case.case_id"];function n(t){const n=e.slice();if(t.twLst)for(const e of t.twLst){let t=e.term.id;t.startsWith("case.")&&(t="occurrence."+t),n.push(t)}return n.join(",")}function s(t){if(!t.gene&&"string"!=typeof t.gene)throw"p.gene does not provide non-empty string";const e={op:"and",content:[]};return t.gene&&e.content.push({op:"=",content:{field:"cnv.consequence.gene.symbol",value:t.gene.split(",")}}),t.filter0&&e.content.push(t.filter0),t.filterObj&&e.content.push(l("string"==typeof t.filterObj?JSON.parse(t.filterObj):t.filterObj)),e}t.queries.geneCnv.bygene.get=async t=>{var e;const a=x(t),l=await o.post(i.join(c,"cnv_occurrences"),{headers:a,body:JSON.stringify({size:1e5,fields:n(t),filters:s(t)})}),u=JSON.parse(l.body);if(!Array.isArray(null==u||null===(e=u.data)||void 0===e?void 0:e.hits))throw"geneCnv response body is not {data:hits[]}";const f={ssm_id:"geneCnvGain",dt:r.dtcnv,class:r.mclasscnvgain,samples:[]},d={ssm_id:"geneCnvLoss",dt:r.dtcnv,class:r.mclasscnvloss,samples:[]};for(const e of u.data.hits){if("object"!=typeof e.cnv)throw"hit.cnv{} not obj";if("object"!=typeof e.case)throw"hit.case{} not obj";if(!e.cnv.gene_level_cn)throw"hit.cnv.gene_level_cn is not true";let n;if("Gain"==e.cnv.cnv_change)n=f;else{if("Loss"!=e.cnv.cnv_change)throw"hit.cnv.cnv_change is not Gain/Loss";n=d}const r={sample_id:e.case.submitter_id};if(t.twLst)for(const n of t.twLst)k(r,e.case,n);r["case.case_id"]=e.case.case_id,n.samples.push(r)}const h=[];return f.samples.length&&h.push(f),d.samples.length&&h.push(d),h}}function w(t,e){if(!e)return;const n=e.split(",");for(const e of n){const n=e.split("--");if(2==n.length)return t.geneA=n[0].split("(")[0],void(t.geneB=n[1].split("(")[0])}}function x(t){const e={"Content-Type":"application/json",Accept:"application/json"};return t&&(t.token&&(e["X-Auth-Token"]=t.token),t.sessionid&&(e.Cookie="sessionid="+t.sessionid)),e}function k(t,e,n){const r=n.term.id.split(".");if(function e(o,i){const s=r[i];if(i==r.length-1)return void(t[n.term.id]?t[n.term.id].add(o[s]):t[n.term.id]=o[s]);const a=o[s];if(null==a)return;if(Array.isArray(a)){t[n.term.id]=new Set;for(const t of a)e(t,i+1);return}e(a,i+1)}(e,1),t[n.term.id]instanceof Set&&(t[n.term.id]=[...t[n.term.id]][0]),n.term.id in t)if("categorical"==n.term.type){const e=function(t,e){var n,r,o,i,s,a,l;if("custom-groupset"==(null===(n=e.q)||void 0===n?void 0:n.type)&&Array.isArray(null===(r=e.q)||void 0===r||null===(o=r.groupsetting)||void 0===o||null===(i=o.customset)||void 0===i?void 0:i.groups))for(const n of e.q.groupsetting.customset.groups){if(!Array.isArray(n.values))throw"group.values[] not array from tw.q.groupsetting.customset.groups";if(-1!=n.values.findIndex((e=>e.key==t)))return n.name}if("predefined-groupset"==(null===(s=e.q)||void 0===s?void 0:s.type)&&Number.isInteger(null===(a=e.q.groupsetting)||void 0===a?void 0:a.predefined_groupset_idx)&&null!==(l=e.term.groupsetting)&&void 0!==l&&l.lst[e.q.groupsetting.predefined_groupset_idx])for(const n of e.term.groupsetting.lst[e.q.groupsetting.predefined_groupset_idx]){if(!Array.isArray(n.values))throw"group.values[] not array from tw.term.groupsetting.lst[]";if(-1!=n.values.findIndex((e=>e.key==t)))return n.name}}(t[n.term.id],n);e&&(t[n.term.id]=e)}else if("integer"==n.term.type||"float"==n.term.type){const e=void t[n.term.id];e&&(t[n.term.id]=e)}}function q(t){for(const n of t)if(null==n.id||""==n.id){var e;if(null==n||null===(e=n.term)||void 0===e||!e.id)throw"tw.id and tw.term are both missing";n.id=n.term.id}else n.term||(n.term={id:n.id})}async function N(t,e,n,r){if(q(e),r){if(!Array.isArray(r))throw"geneTwLst not array";t.isoforms=[];for(const e of r){var s;if(null==e||null===(s=e.term)||void 0===s||!s.name)throw"gene tw missing .term.name";if(e.term.isoform)t.isoforms.push(e.term.isoform);else{var l,u;if("object"!=typeof t.genome)throw"serverside genome obj missing, needed to map gene name to canonical isoform";if(null===(l=t.genome)||void 0===l||null===(u=l.genedb)||void 0===u||!u.get_gene2canonicalisoform)throw"gene2canonicalisoform not supported on this genome";const n=t.genome.genedb.get_gene2canonicalisoform.get(e.term.name);if(null==n||!n.isoform)continue;t.isoforms.push(n.isoform)}}}"samples"==t.get&&((t.ssm_id_lst||t.isoform)&&(e.some((t=>"ssm.ssm_id"==t.id))||e.push({term:{id:"ssm.ssm_id"}}),e.some((t=>"case.observation.read_depth.t_alt_count"==t.id))||e.push({term:{id:"case.observation.read_depth.t_alt_count"}}),e.some((t=>"case.observation.read_depth.t_depth"==t.id))||e.push({term:{id:"case.observation.read_depth.t_depth"}}),e.some((t=>"case.observation.read_depth.n_depth"==t.id))||e.push({term:{id:"case.observation.read_depth.n_depth"}}),e.some((t=>"case.observation.sample.tumor_sample_uuid"==t.id))||e.push({term:{id:"case.observation.sample.tumor_sample_uuid"}})),r&&(e.some((t=>"case.submitter_id"==t.id))||e.push({term:{id:"case.submitter_id"}})),e.some((t=>"case.case_id"==t.id))||e.push({term:{id:"case.case_id"}})),"summary"!=t.get&&"sunburst"!=t.get||e.some((t=>"case.submitter_id"==t.id))||e.push({term:{id:"case.submitter_id"}});const f=[];for(const t of e){const e=n.cohort.termdb.q.termjsonByOneid(t.term.id);e&&f.push({term:e,q:t.q})}const d=e.map((t=>t.term.id));t.hiddenmclass&&(d.push("ssm.consequence.transcript.consequence_type"),d.push("ssm.consequence.transcript.transcript_id")),t.rglst&&(d.push("ssm.chromosome"),d.push("ssm.start_position"));const h={size:1e4,fields:d.join(",")};g(t,n),h.filters=L.filters(t,n);const p=x(t),m=await o.post(i.join(c,L.endpoint),{headers:p,body:JSON.stringify(h)});let y;delete t.isoforms;try{y=JSON.parse(m.body)}catch(t){throw"invalid JSON from GDC for variant2samples query"}if(!y.data||!y.data.hits)throw"variant2samples data structure not data.hits[]";if(!Array.isArray(y.data.hits))throw"variant2samples re.data.hits is not array for query";const b=[];for(const e of y.data.hits){if(!e.case)throw"variant2samples .case{} missing from a hit";const r={};if(e.ssm&&(r.ssm_id=e.ssm.ssm_id),t.hiddenmclass){var _;if(!Array.isArray(null===(_=e.ssm)||void 0===_?void 0:_.consequence))continue;const n={};if(v(n,e.ssm.consequence.find((e=>e.transcript.transcript_id==t.isoform))),t.hiddenmclass.has(n.class))continue}if(t.rglst){var w,N;if(null===(w=e.ssm)||void 0===w||!w.chromosome||null===(N=e.ssm)||void 0===N||!N.start_position)continue;if(!t.rglst.find((t=>t.chr==e.ssm.chromosome&&t.start<e.ssm.start_position&&t.stop>=e.ssm.start_position)))continue}var T,C,j,O;if(r.sample_id=await S(e.case,n,!0),e.case.case_id)r.sample_URLid=e.case.case_id,null!==(T=e.case)&&void 0!==T&&null!==(C=T.observation)&&void 0!==C&&null!==(j=C[0])&&void 0!==j&&null!==(O=j.sample)&&void 0!==O&&O.tumor_sample_uuid&&(r.sample_URLid=r.sample_URLid+"?bioId="+e.case.observation[0].sample.tumor_sample_uuid);for(const t of f)k(r,e.case,t);A(e.case,r),M(r,n),b.push(r)}if(r){const t={gene:r.map((t=>t.term.name)).join(","),twLst:f},e=await n.queries.geneCnv.bygene.get(t);for(const t of e)for(const e of t.samples)b.push(e)}const E=new Map;for(const t of b)a([t],E,t.ssm_id);return[...E.values()]}async function S(t,e,n){var r,o,i;return n&&t.submitter_id?t.submitter_id:null!=t&&null!==(r=t.observation)&&void 0!==r&&null!==(o=r[0])&&void 0!==o&&null!==(i=o.sample)&&void 0!==i&&i.tumor_sample_uuid?await e.aliquot2submitter.get(t.observation[0].sample.tumor_sample_uuid):t.case_id||t.submitter_id}function A(t,e){if(!t.observation)return;const n=t.observation[0];n&&n.read_depth&&(e.formatK2v={TumorAC:n.read_depth.t_depth-n.read_depth.t_alt_count+","+n.read_depth.t_alt_count,NormalDepth:n.read_depth.n_depth})}function M(t,e){var n;const r=t["case.project.project_id"];r&&(t.caseIsOpenAccess=null===(n=e.gdcOpenProjects)||void 0===n?void 0:n.has(r))}async function T(t,e,n,r){q(t);const i=[];for(const e of t)e.term&&"categorical"==e.term.type&&i.push({id:e.id,path:e.id.replace("case.","").replace(/\./g,"__"),type:e.term.type});const s=function(t){const e=[];for(const n of t)if(n.id)if(n.type="categorical")e.push(n.path+" {buckets { doc_count, key }}");else{if("integer"!=n.type&&"float"!=n.type)throw"unknown term type";e.push(n.path+" {stats { count }}")}return`query termislst2total( $filters: FiltersArgument) {\n\t\texplore {\n\t\t\tcases {\n\t\t\t\taggregations (filters: $filters, aggregations_filter_themselves: true) {\n\t\t\t\t\t${e.join("\n")}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}`}(i),a=function(t,e){const n={filters:{op:"and",content:[{op:"in",content:{field:"cases.available_variation_data",value:["ssm"]}}]}};if(t&&t.tid2value)for(const r in t.tid2value){e.cohort.termdb.q.termjsonByOneid(r)&&n.filters.content.push({op:"in",content:{field:r.replace(/^case\./,"cases."),value:[t.tid2value[r]]}})}t&&t.ssm_id_lst&&n.filters.content.push({op:"=",content:{field:"cases.gene.ssm.ssm_id",value:t.ssm_id_lst.split(",")}});return n}(e,r),l=await o.post(u,{headers:x(e),body:JSON.stringify({query:s,variables:a})});let c;try{c=JSON.parse(l.body)}catch(t){throw"invalid JSON from GDC for cohortTotal for query :"+s+" and filter: "+filter}const f=["data","explore","cases","aggregations"];let d=c[f[0]];for(let t=1;t<f.length;t++)if(d=d[f[t]],!d)throw"."+f[t]+" missing from data structure of termid2totalsize2 for query :"+s+" and filter: "+filter;for(const t of i){if("categorical"==t.type&&!Array.isArray(d[t.path].buckets))throw f.join(".")+" not array for query :"+s+" and filter: "+filter;if(("integer"==t.type||"float"==t.type)&&"object"!=typeof d[t.path].stats)throw f.join(".")+" not object for query :"+s+" and filter: "+filter}const h=new Map;for(const t of i)if("categorical"==t.type){const e=d[t.path].buckets;let n=[];for(const t of e)n.push([t.key.replace(".","__"),t.doc_count]);h.set(t.id,n)}else if("integer"==t.type||"float"==t.type){const e=d[t.path].stats.count;h.set(t.id,{total:e})}return n?[h,n]:h}function C(t){const e=["consequence.transcript.transcript_id","consequence.transcript.consequence_type","consequence.transcript.aa_change"];t.queries.snvindel.m2csq.get=async t=>{const n=await o(c+"/ssms/"+t.ssm_id+"?fields="+e.join(","),{method:"GET",headers:x(t)});let r;try{r=JSON.parse(n.body)}catch(t){throw"invalid json in response"}if(!r.data||!r.data.consequence)throw"returned data not .data.consequence";if(!Array.isArray(r.data.consequence))throw".data.consequence not array";return r.data.consequence.map((t=>t.transcript))}}function j(t,e){t.queries.singleSampleMutation.get=async(n,r)=>{if(!n)throw"sampleName missing";return r.case_id=await async function(t){const e=await o.post("https://api.gdc.cancer.gov/cases",{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({size:1,fields:"case_id,submitter_id",filters:{op:"or",content:[{op:"=",content:{field:"samples.portions.analytes.aliquots.aliquot_id",value:[t]}},{op:"=",content:{field:"submitter_id",value:[t]}},{op:"=",content:{field:"samples.submitter_id",value:[t]}}]}})}),n=JSON.parse(e.body);for(const t of n.data.hits)if(t.case_id)return t.case_id;throw"cannot convert to case_id (uuid)"}(n),await E(r,t,e)}}function O(t){return async(e,n)=>{try{const r=t[e.query.genome];if(!r)throw"invalid genome";const o=r.datasets[e.query.dslabel];if(!o)throw"invalid dslabel";if(!e.query.case_id)throw".case_id missing";n.send({mlst:await E(e.query,o,r)})}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}}async function E(t,e,n){const s=[];{const e=await o.post(i.join(c,F.endpoint),{headers:x(t),body:JSON.stringify({size:1e3,fields:F.fields.join(","),filters:F.filters(t)})}),a=JSON.parse(e.body);for(const t of a.data.hits){let e;for(const n of t.consequence)if(n.transcript&&n.transcript.gene&&n.transcript.gene.symbol){e=n.transcript.gene.symbol;break}if(!e)continue;const o=n.genedb.get_gene2canonicalisoform.get(e);if(null==o||!o.isoform)continue;let i=t.consequence.find((t=>t.transcript.transcript_id==o.isoform));i||(i=t.consequence[0]);const a=i.transcript.aa_change||i.transcript.consequence_type,[l,c,u]=r.vepinfo(i.transcript.consequence_type);s.push({dt:r.dtsnvindel,mname:a,class:c,gene:i.transcript.gene.symbol,chr:t.chromosome,pos:t.start_position,ref:t.reference_allele,alt:t.tumor_allele})}}{const e=await async function(t){const e=x(t),n=await o.post(i.join(c,"files"),{headers:e,body:JSON.stringify({size:1e4,fields:["cases.samples.sample_type","data_type","file_id","data_format","experimental_strategy","analysis.workflow_type"].join(","),filters:function(t){if(!t.case_id)throw".case_id missing";return{op:"and",content:[{op:"in",content:{field:"cases.case_id",value:[t.case_id]}},{op:"in",content:{field:"data_type",value:["Masked Copy Number Segment","Copy Number Segment","Transcript Fusion"]}}]}}(t)})}),s=JSON.parse(n.body);if(!Array.isArray(s.data.hits))throw"re.data.hits[] not array";let a,l,u;for(const t of s.data.hits)if("BEDPE"!=t.data_format){if("TXT"==t.data_format){if("Genotyping Array"==t.experimental_strategy){var f,d,h;const e=null===(f=t.cases)||void 0===f||null===(d=f[0].samples)||void 0===d||null===(h=d[0])||void 0===h?void 0:h.sample_type;if(!e)continue;if(e.includes("Normal"))continue;if("Masked Copy Number Segment"!=t.data_type)continue;a=t.file_id;continue}if("WGS"==t.experimental_strategy){if(!t.file_id)continue;if("Copy Number Segment"!=t.data_type)continue;l=t.file_id;continue}}}else{var p;if("RNA-Seq"!=t.experimental_strategy)continue;if("Arriba"!=(null===(p=t.analysis)||void 0===p?void 0:p.workflow_type))continue;if("Transcript Fusion"!=t.data_type)continue;u=t.file_id}const m=[];if(l){const t=(await o(i.join(c,"data")+"/"+l,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t");if(7!=n.length)continue;const o=Number(n[4]),i=Number(n[5]),s=Number(n[6]);if(Number.isNaN(o)||Number.isNaN(i)||Number.isNaN(s))continue;const a={dt:r.dtcnv,chr:n[1],start:Number(n[2]),stop:Number(n[3]),value:o};!a.chr||Number.isNaN(a.start)||Number.isNaN(a.stop)||(m.push(a),o>0&&0==s&&i>0&&m.push({dt:r.dtloh,chr:a.chr,start:a.start,stop:a.stop,segmean:.5}))}}else if(a){const t=(await o(i.join(c,"data")+"/"+a,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t");if(6!=n.length)continue;if(!n[1])continue;const o={dt:r.dtcnv,chr:"chr"+n[1],start:Number(n[2]),stop:Number(n[3]),value:Number(n[5])};Number.isNaN(o.start)||Number.isNaN(o.stop)||Number.isNaN(o.value)||m.push(o)}}if(u)try{const t=(await o(i.join(c,"data")+"/"+u,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t"),o={dt:r.dtfusionrna,chrA:n[0],posA:Number(n[1]),chrB:n[3],posB:Number(n[4])};o.chrA&&o.chrB&&!Number.isNaN(o.posA)&&!Number.isNaN(o.posB)&&(w(o,n[6]),m.push(o))}}catch(t){}return m}(t);s.push(...e)}return s}function R(t){return async(e,n)=>{try{if(!t[e.query.genome])throw"invalid genome";n.send({genes:await I({filter:e.query.filter0,CGConly:parseInt(e.query.CGConly),maxGenes:e.query.maxGenes})})}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}}async function I({filter:t,CGConly:e,maxGenes:n}){let r={op:"and",content:[]};if(t){if("object"!=typeof t)throw"filter not object";r=t}const s=await o.post(i.join(c,"/analysis/top_mutated_genes_by_project"),{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({size:n||50,fields:"symbol",filters:P(r,e)})}),a=JSON.parse(s.body),l=[];for(const t of a.data.hits)t.symbol&&l.push(t.symbol);return l}function P(t,e){let n;if("in"==t.op)n={op:"and",content:[t]};else{if("and"!=t.op)throw'f.op not "in" or "and"';n=t}return n.content.push({op:"NOT",content:{field:"ssms.consequence.transcript.annotation.vep_impact",value:"missing"}}),n.content.push({op:"in",content:{field:"ssms.consequence.transcript.consequence_type",value:["missense_variant","frameshift_variant","start_lost","stop_lost","stop_gained"]}}),e&&n.content.push({op:"in",content:{field:"genes.is_cancer_gene_census",value:["true"]}}),n}const F={endpoint:"/ssms",size:1e5,fields:["ssm_id","chromosome","start_position","reference_allele","tumor_allele","consequence.transcript.transcript_id","consequence.transcript.consequence_type","consequence.transcript.aa_change","consequence.transcript.gene.symbol"],filters:t=>{const e={op:"and",content:[]};if(t.isoform){if("string"!=typeof t.isoform)throw".isoform value not string";e.content.push({op:"=",content:{field:"consequence.transcript.transcript_id",value:[t.isoform]}})}if(t.case_id){if("string"!=typeof t.case_id)throw".case_id value not string";e.content.push({op:"=",content:{field:"cases.case_id",value:[t.case_id]}})}if(t.set_id){if("string"!=typeof t.set_id)throw".set_id value not string";e.content.push({op:"in",content:{field:"cases.case_id",value:[t.set_id]}})}return t.filter0&&e.content.push(t.filter0),t.filterObj&&e.content.push(l(t.filterObj)),e}},L={endpoint:"/ssm_occurrences",size:1e5,fields:["ssm.ssm_id","case.case_id","case.submitter_id","case.observation.sample.tumor_sample_uuid"],filters:(t,e)=>{const n={op:"and",content:[]};if(t.ssm_id_lst){if("string"!=typeof t.ssm_id_lst)throw"ssm_id_lst not string";n.content.push({op:"=",content:{field:"ssm.ssm_id",value:t.ssm_id_lst.split(",")}})}else if(t.isoform)n.content.push({op:"=",content:{field:"ssms.consequence.transcript.transcript_id",value:[t.isoform]}});else{if(!t.isoforms)throw".ssm_id_lst, .isoform, .isoforms are all missing";if(!Array.isArray(t.isoforms))throw".isoforms[] not array";n.content.push({op:"in",content:{field:"ssms.consequence.transcript.transcript_id",value:t.isoforms}})}if(t.rglst&&(n.content.push({op:">=",content:{field:"ssms.start_position",value:t.rglst[0].start}}),n.content.push({op:"<=",content:{field:"ssms.start_position",value:t.rglst[0].stop}})),t.set_id){if("string"!=typeof t.set_id)throw".set_id value not string";n.content.push({op:"in",content:{field:"cases.case_id",value:[t.set_id]}})}if(t.filter0&&n.content.push(t.filter0),t.filterObj&&n.content.push(l(t.filterObj)),t.tid2value)for(const r in t.tid2value){const o=e.cohort.termdb.q.termjsonByOneid(r);if(o)if("categorical"==o.type)n.content.push({op:"in",content:{field:r,value:[t.tid2value[r]]}});else if("integer"==o.type)for(const e of t.tid2value[r])n.content.push({op:e.op,content:{field:r,value:e.range}})}return n}}},9535:(t,e,n)=>{"use strict";n.r(e),n.d(e,{client_copy:()=>E,cnvByRangeGetter_file:()=>W,init:()=>O,snvindelByRangeGetter_bcf:()=>F,ssmIdFieldsSeparator:()=>T,svfusionByRangeGetter_file:()=>H,validate_termdb:()=>R});const r=n(5243),o=n(7147),i=n(4521),s=n(1017),a=n(2282).scaleLinear,l=n(6718).createCanvas,{initGDCdictionary:c}=n(1778),{validate_variant2samples:u}=n(817),f=n(3856),d=n(3625).compute_mclass,h=n(334),{dtsnvindel:p,dtfusionrna:m,dtsv:g,dtcnv:y,mclassfusionrna:v,mclasssv:b,mclasscnvgain:_,mclasscnvloss:w}=n(2273),{get_samples:x}=n(2852),{server_init_db_queries:k}=n(394),{barchart_data:q}=n(1711),{setDbRefreshRoute:N}=n(1883),S=n(2188).wz,A=n(2974).mayInitiateMatrixplots,{add_bcf_variant_filter:M}=n(3795),T=".",C="Ancestry_PC_",j="Unannotated";async function O(t,e,n,i=null,a=null){var l,c;await R(t),t.queries&&(await async function(t,e){const n=t.queries.snvindel;if(!n)return;if(n.url){if(!n.url.base)throw".snvindel.url.base missing";if(!n.url.key)throw".snvindel.url.key missing"}if(!n.byisoform&&!n.byrange)throw"byisoform and byrange are both missing on queries.snvindel";if(n.byrange)if(n.byrange.gdcapi)r.validate_query_snvindel_byrange(t);else if(n.byrange.bcffile){var o;n.byrange.bcffile=s.join(h.tpmasterdir,n.byrange.bcffile),n.byrange._tk={file:n.byrange.bcffile},n.byrange.get=await F(t,e),null!==(o=n.byrange._tk)&&void 0!==o&&o.samples.length||delete n.byrange._tk.samples,P(t,n.byrange._tk.samples,"snvindel.byrange.bcffile")}else{if(!n.byrange.chr2bcffile)throw"unknown query method for queries.snvindel.byrange";n.byrange._tk={chr2files:{}};for(const t in n.byrange.chr2bcffile)n.byrange._tk.chr2files[t]={file:s.join(h.tpmasterdir,n.byrange.chr2bcffile[t])};delete n.byrange.chr2bcffile,n.byrange.get=await F(t,e),n.byrange._tk.samples.length||delete n.byrange._tk.samples,P(t,n.byrange._tk.samples,"snvindel.byrange.bcffile")}if(n.byisoform){if(!n.byisoform.gdcapi)throw"unknown query method for queries.snvindel.byisoform";r.validate_query_snvindel_byisoform(t)}if(n.m2csq){if(!n.m2csq.by)throw".by missing from queries.snvindel.m2csq";if("ssm_id"!=n.m2csq.by)throw"unknown value of queries.snvindel.m2csq.by";if(!n.m2csq.gdcapi)throw"unknown query method for queries.snvindel.m2csq";r.validate_m2csq(t)}}(t,e),await async function(t,e){const n=t.queries.svfusion;if(!n)return;if(!n.byrange)throw"byrange missing from queries.svfusion";if(n.byrange){if(!n.byrange.file)throw"unknown query method for svfusion.byrange";n.byrange.file=s.join(h.tpmasterdir,n.byrange.file),n.byrange.get=await H(t,e),P(t,n.byrange.samples,"svfusion.byrange")}}(t,e),await async function(t,e){const n=t.queries.geneCnv;if(!n)return;if(!n.bygene)throw"geneCnv.bygene missing";n.bygene.gdcapi&&r.validate_query_geneCnv2(t)}(t),await async function(t,e){const n=t.queries.cnv;if(!n)return;if(!n.byrange)throw"byrange missing from queries.cnv";if(n.byrange){if(!n.byrange.file)throw"unknown query method for cnv.byrange";n.byrange.file=s.join(h.tpmasterdir,n.byrange.file),n.byrange.get=await W(t,e),P(t,n.byrange.samples,"cnv.byrange")}}(t,e),await async function(t,e){const n=t.queries.ld;if(!n)return;if(!Array.isArray(n.tracks)||!n.tracks.length)throw"ld.tracks[] not nonempty array";for(const t of n.tracks){if(!t.name)throw"name missing from one of ld.tracks[]";if(!t.file)throw".file missing from one of ld.tracks[]";t.file0=t.file,t.file=s.join(h.tpmasterdir,t.file),await f.validate_tabixfile(t.file),t.nochr=await f.tabix_is_nochr(t.file,null,e)}if(!n.overlay)throw"ld.overlay{} missing";if(!n.overlay.color_0)throw"ld.overlay.color_0 missing";if(!n.overlay.color_1)throw"ld.overlay.color_1 missing"}(t,e),await async function(t,e){const n=t.queries.geneExpression;if(!n)return;if(n.gdcapi)return void r.validate_query_geneExpression(t);if(!n.file)throw".file missing from queries.geneExpression";n.file=s.join(h.tpmasterdir,n.file),await f.validate_tabixfile(n.file),n.nochr=await f.tabix_is_nochr(n.file,null,e),n.get=async e=>{let r;{const n=await z(e,null,t);n&&(r=new Set(n.map((t=>t.name))))}const o=new Map;for(const t of e.genes)o.set(t.gene,{}),await f.get_lines_bigfile({args:[n.file,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:e=>{const n=e.split("\t");let i;try{i=JSON.parse(n[3])}catch(t){return}i.gene==t.gene&&(r&&!r.has(i.sample)||(o.get(t.gene)[i.sample]=i.value))}});return o}}(t,e),await async function(t,e){const n=t.queries.singleSampleMutation;if(!n)return;if(n.gdcapi)r.validate_query_singleSampleMutation(t,e);else{if(!n.folder)throw"unknown query method for singleSampleMutation";n.get=async e=>{var r,o,i;let a=e;if(null!==(r=t.cohort)&&void 0!==r&&null!==(o=r.termdb)&&void 0!==o&&null!==(i=o.q)&&void 0!==i&&i.sampleName2id&&(a=t.cohort.termdb.q.sampleName2id(e),null==a))return[];const l=await f.read_file(s.join(h.tpmasterdir,n.folder,a.toString()));return JSON.parse(l)}}}(t,e),await async function(t,e){const n=t.queries.singleSampleGenomeQuantification;if(!n)return;for(const r in n){if(!Number.isFinite(n[r].min))throw"min not a number";if(!Number.isFinite(n[r].max))throw"max not a number";if(n[r].min>=n[r].max)throw"min>=max";if(!n[r].folder)throw"unknown query method for singleSampleGenomeQuantification";n[r].get=async(o,i)=>{var a,l,c;let u=o;if(null!==(a=t.cohort)&&void 0!==a&&null!==(l=a.termdb)&&void 0!==l&&null!==(c=l.q)&&void 0!==c&&c.sampleName2id&&(u=t.cohort.termdb.q.sampleName2id(o),null==u))return[];return await U(s.join(h.tpmasterdir,n[r].folder,u.toString()),e,n[r],i)}}}(t,e),await async function(t,e){const n=t.queries.singleSampleGbtk;if(!n)return;for(const e in n){if(!Number.isFinite(n[e].min))throw"min not a number";if(!Number.isFinite(n[e].max))throw"max not a number";if(n[e].min>=n[e].max)throw"min>=max";if(!n[e].folder)throw"unknown query method for singleSampleGbtk";n[e].get=async r=>{var i,a,l;let c=r;if(null!==(i=t.cohort)&&void 0!==i&&null!==(a=i.termdb)&&void 0!==a&&null!==(l=a.q)&&void 0!==l&&l.sampleName2id&&(c=t.cohort.termdb.q.sampleName2id(r),null==c))return{};const u=s.join(n[e].folder,c+".gz");try{return await o.promises.stat(s.join(h.tpmasterdir,u)),{path:u}}catch(t){return{}}}}}(t),u(t),function(t){if(!t.ssm2canonicalisoform)return;if(t.ssm2canonicalisoform.gdcapi)return void r.validate_ssm2canonicalisoform(t.ssm2canonicalisoform);throw"ssm2canonicalisoform.gdcapi is false"}(t),function(t,e){if(!e.genedb.hasTable_refseq2ensembl)return;t.refseq2ensembl_query=e.genedb.db.prepare("select ensembl from refseq2ensembl where refseq=?")}(t,e),function(t,e){if(!t.queries.snvindel&&!t.queries.svfusion&&!t.queries.geneCnv)return;t.mayGetGeneVariantData=async(n,r)=>{if("object"!=typeof n.term)throw"tw.term{} is not object";if("geneVariant"!=n.term.type)throw"tw.term.type is not geneVariant";if("string"!=typeof n.term.name)throw"tw.term.name is not string";if(!n.term.name)throw"tw.term.name should be gene symbol but is empty string";const o=[];if(t.queries.snvindel){const i=await async function(t,e,n,r){const o={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter};t.queries.geneCnv&&(o.useCaseid4sample=!0);if(t.queries.snvindel.byisoform)return await async function(t,e){if(t.isoform&&"string"==typeof t.isoform)return;if(!t.name)throw"both term.name and term.isoform";const n=e.genedb.getjsonbyname.all(t.name);if(0==n.length)return;const r=n.find((t=>t.isdefault))||n[0],o=JSON.parse(r.genemodel);if(!o.isoform)throw"isoform missing from returned gm";t.isoform=o.isoform}(e,n),e.isoform?(o.isoform=e.isoform,await t.queries.snvindel.byisoform.get(o)):[];if(t.queries.snvindel.byrange)return await V(e,n),o.rglst=[e],await t.queries.snvindel.byrange.get(o);throw"unknown queries.snvindel method"}(t,n.term,e,r);o.push(...i)}if(t.queries.svfusion){const i=await async function(t,e,n,r){const o={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter};if(t.queries.svfusion.byrange)return await V(e,n),o.rglst=[e],await t.queries.svfusion.byrange.get(o);throw"unknown queries.svfusion method"}(t,n.term,e,r);o.push(...i)}if(t.queries.cnv){const i=await async function(t,e,n,r){var o,i,s;const a={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter,cnvMaxLength:null==e||null===(o=e.q)||void 0===o?void 0:o.cnvMaxLength,cnvGainCutoff:null==e||null===(i=e.q)||void 0===i?void 0:i.cnvGainCutoff,cnvLossCutoff:null==e||null===(s=e.q)||void 0===s?void 0:s.cnvLossCutoff};if(t.queries.cnv.byrange)return await V(e.term,n),a.rglst=[e.term],await t.queries.cnv.byrange.get(a);throw"unknown queries.cnv method"}(t,n,e,r);o.push(...i)}if(t.queries.geneCnv){const e=await async function(t,e,n,r){const o={filter0:r.filter0};if(t.queries.geneCnv.bygene)return e.name?(o.gene=e.name,await t.queries.geneCnv.bygene.get(o)):[];throw"unknown queries.geneCnv method"}(t,n.term,0,r);o.push(...e)}const i=new Map;for(const e of o)if(Array.isArray(e.samples))for(const r of e.samples){var s,a;if(i.has(r.sample_id)||i.set(r.sample_id,{sample:r.sample_id}),null!==(s=t.cohort)&&void 0!==s&&null!==(a=s.termdb)&&void 0!==a&&a.additionalSampleAttributes)for(const e of t.cohort.termdb.additionalSampleAttributes)e in r&&(i.get(r.sample_id)[e]=r[e]);i.get(r.sample_id)[n.term.name]||(i.get(r.sample_id)[n.term.name]={key:n.term.name,label:n.term.name,values:[]});const o={gene:n.term.name,isoform:e.isoform,dt:e.dt,chr:n.term.chr,class:e.class,pos:e.pos||(e.start?e.start+"-"+e.stop:""),mname:e.mname,_SAMPLEID_:r.sample_id,_SAMPLENAME_:r.sample_id};if("value"in e&&(o.value=e.value),r.formatK2v)for(const t in r.formatK2v)o[t]=r.formatK2v[t];e.dt==p||e.dt==m||e.dt,t.cohort.termdb.q.id2sampleName&&Number.isInteger(r.sample_id)&&(o._SAMPLENAME_=t.cohort.termdb.q.id2sampleName(r.sample_id)),i.get(r.sample_id)[n.term.name].values.push(o)}return await async function(t,e,n,r){var o;if(null===(o=e.assayAvailability)||void 0===o||!o.byDt)return;const i=t.filter?new Set((await x(t.filter,e)).map((t=>t.id))):null;for(const t in e.assayAvailability.byDt){const o=e.assayAvailability.byDt[t];if(o.byOrigin)for(const e in o.byOrigin){J(t,o.byOrigin[e],n,r,e,i)}else J(t,o,n,r,!1,i)}}(r,t,i,n.term.name),i}}(t,e)),function(t){if(!t.assayAvailability)return;if(t.assayAvailability.byDt)for(const e in t.assayAvailability.byDt){const n=t.assayAvailability.byDt[e];if(n.byOrigin)for(const e in n.byOrigin){const r=n.byOrigin[e];if(!r.yes||!r.no||!r.term_id)throw"ds.assayAvailability.byDt.*.byOrigin properties require .term_id .yes{} .no{}";Y(t,r)}else{if(!n.yes||!n.no||!n.term_id)throw"ds.assayAvailability.byDt properties require .term_id .yes{} .no{}";Y(t,n)}}}(t),null!==(l=t.cohort)&&void 0!==l&&null!==(c=l.db)&&void 0!==c&&c.refresh&&i&&N(t,i,a)}function E(t){var e;const n={isMds3:!0,label:t.label};if(function(t,e){if(!t.queries)return;const n={};t.queries.singleSampleMutation&&(n.singleSampleMutation={sample_id_key:t.queries.singleSampleMutation.sample_id_key,discoSkipChrM:t.queries.singleSampleMutation.discoSkipChrM});if(t.queries.singleSampleGenomeQuantification){n.singleSampleGenomeQuantification={};for(const e in t.queries.singleSampleGenomeQuantification)n.singleSampleGenomeQuantification[e]=JSON.parse(JSON.stringify(t.queries.singleSampleGenomeQuantification[e])),delete n.singleSampleGenomeQuantification[e].folder}if(t.queries.singleSampleGbtk){n.singleSampleGbtk={};for(const e in t.queries.singleSampleGbtk)n.singleSampleGbtk[e]=JSON.parse(JSON.stringify(t.queries.singleSampleGbtk[e])),delete n.singleSampleGbtk[e].folder}const r=t.queries.snvindel;r&&(e.has_skewer=!0,n.snvindel={forTrack:r.forTrack,vcfid4skewerName:r.vcfid4skewerName,variantUrl:r.variantUrl,skewerRim:r.skewerRim},r.m2csq&&(n.snvindel.m2csq={by:r.m2csq.by}),r.info&&(e.bcf={info:r.info}),r.format&&(e.bcf||(e.bcf={}),e.bcf.format=r.format));if(t.queries.ld){n.ld=JSON.parse(JSON.stringify(t.queries.ld));for(const t of n.ld.tracks)delete t.file}e.queries=n}(t,n),null!==(e=t.cohort)&&void 0!==e&&e.termdb&&(n.termdb={},t.cohort.termdb.allowCaseDetails&&(n.termdb.allowCaseDetails={sample_id_key:t.cohort.termdb.allowCaseDetails.sample_id_key})),t.variant2samples){const e=t.variant2samples;n.variant2samples={sunburst_twLst:e.sunburst_twLst,twLst:e.twLst,type_samples:e.type_samples,type_summary:e.type_summary,type_sunburst:e.type_sunburst,url:e.url,variantkey:e.variantkey}}return n}async function R(t){var e,o,i,s;if(t.cohort){if(!t.cohort.termdb)throw"ds.cohort is set but cohort.termdb{} missing";if(!t.cohort.db)throw"ds.cohort is set but cohort.db{} missing";if(!t.cohort.db.file&&!t.cohort.db.file_fullpath)throw"ds.cohort.db.file missing"}else{if(!t.termdb)return;t.cohort={},t.cohort.termdb=t.termdb,delete t.termdb}const a=t.cohort.termdb;if(null!=a&&null!==(e=a.dictionary)&&void 0!==e&&e.gdcapi)await c(t);else if(null!=a&&null!==(o=a.dictionary)&&void 0!==o&&o.dbFile)t.cohort.db={file:a.dictionary.dbFile},delete a.dictionary.dbFile,k(t);else{if(!t.cohort.db)throw"unknown method to initiate dictionary";k(t)}if(a.termid2totalsize2&&(a.termid2totalsize2.gdcapi,a.termid2totalsize2.get=async(e,n={},o=null)=>a.termid2totalsize2.gdcapi?await r.get_termlst2size(e,n,o,t):await async function(t,e,n,r){const o=new Map;for(const n of t)if(n.term&&"categorical"==n.term.type){var i,s;const t={term1_id:n.id,term1_q:{type:"values"}};e.tid2value&&(t.filter=Z(e.tid2value,r));const a=await q(t,r,r.cohort.termdb);if(null==a||null===(i=a.data)||void 0===i||null===(s=i.charts)||void 0===s||!s[0])continue;const l=[];for(const t of a.data.charts[0].serieses)l.push([t.seriesId,t.total]);o.set(n.id,l)}return n?[o,n]:o}(e,n,o,t)),function(t){const e=t.selectCohort;if(!e)return;if("object"!=typeof e)throw"selectCohort{} not object";if(!e.term)throw"term{} missing from termdb.selectCohort";if(!e.term.id)throw"id missing from termdb.selectCohort.term";if("string"!=typeof e.term.id)throw"termdb.selectCohort.term.id is not string";if("categorical"!=e.term.type)throw'type is not hardcoded "categorical" from termdb.selectCohort.term';{const n=t.q.termjsonByOneid(e.term.id);if(!n)throw"termdb.selectCohort.term.id is invalid";if("categorical"!=n.type)throw"termdb.selectCohort.term type is not categorical"}if(!e.values)throw"values[] missing from termdb.selectCohort";if(!Array.isArray(e.values))throw"termdb.selectCohort.values is not array";if(0==e.values.length)throw"termdb.selectCohort.values[] cannot be empty";for(const t of e.values){if(!t.keys)throw"keys[] missing from one of selectCohort.values[]";if(!Array.isArray(t.keys))throw"keys[] is not array from one of selectCohort.values[]";if(0==t.keys.length)throw"keys[] is empty from one of selectCohort.values[]"}}(a),await async function(t){if(!t.restrictAncestries)return;if(!Array.isArray(t.restrictAncestries)||0==t.restrictAncestries.length)throw"termdb.restrictAncestries[] is not non-empty array";for(const e of t.restrictAncestries){if(!e.name)throw"name missing from one of restrictAncestries";if("object"!=typeof e.tvs)throw".tvs{} missing from one of restrictAncestries";if(!e.tvs.term)throw"tvs.term{} missing from an ancestry";if(!e.tvs.term.id)throw"tvs.term.id missing from an ancestry";{const n=t.q.termjsonByOneid(e.tvs.term.id);if(!n)throw"tvs.term.id is invalid from an ancestry";if("categorical"!=n.type)throw"tvs.term.type is not categorical from an ancestry"}if(!Number.isInteger(e.PCcount))throw"PCcount is not integer";if(e.PCfile)e.pcs=await I(e.PCfile,e.PCcount);else if(e.PCfileBySubcohort){if(!t.selectCohort)throw"PCfileBySubcohort is in use but selectCohort is not enabled";for(const n in e.PCfileBySubcohort){let r=!0;for(const e of t.selectCohort.values)if(n==e.keys.sort().join(",")){r=!1;break}if(r)throw"unknown subcohort from PCfileBySubcohort";const o=e.PCfileBySubcohort[n];if(!o.file)throw".file missing for a subcohort in PCfileBySubcohort";o.pcs=await I(o.file,e.PCcount)}}}}(a),await S(t),await A(t),"minTimeSinceDx"in a){if(!Number.isFinite(a.minTimeSinceDx))throw"termdb.minTimeSinceDx not number";if(a.minTimeSinceDx<=0)throw"termdb.minTimeSinceDx<=0"}if("ageEndOffset"in a){if(!Number.isFinite(a.ageEndOffset))throw"termdb.ageEndOffset not number";if(a.ageEndOffset<=0)throw"termdb.ageEndOffset<=0"}if(t.cohort.termdb.additionalSampleAttributes){if(!Array.isArray(t.cohort.termdb.additionalSampleAttributes))throw"termdb.additionalSampleAttributes not array";for(const e of t.cohort.termdb.additionalSampleAttributes)if("string"!=typeof e)throw"non-str key in termdb.additionalSampleAttributes[]"}if(null!==(i=t.cohort)&&void 0!==i&&null!==(s=i.db)&&void 0!==s&&s.connection){t.sampleName2Id=new Map,t.sampleId2Name=new Map;const e="SELECT * FROM sampleidmap",n=t.cohort.db.connection.prepare(e).all();for(const e of n)t.sampleId2Name.set(e.id,e.name),t.sampleName2Id.set(e.name,e.id);t.getSampleIdMap=e=>{const n={};for(const r in e)n[r]=t.sampleId2Name.get(+r);return n}}if(t.cohort.mutationset){const{mayGetGeneVariantData:e,getTermTypes:r,mayGetMatchingGeneNames:o}=n(7833);t.mayGetGeneVariantData=e,t.getTermTypes=r,t.mayGetMatchingGeneNames=o}}async function I(t,e){const n=new Map;for(let t=1;t<=e;t++)n.set(C+t,new Map);let r=0;for(const o of(await f.read_file(s.join(h.tpmasterdir,t))).trim().split("\n")){r++;const t=o.split("\t"),i=Number(t[0]);if(!Number.isInteger(i))throw"non-integer sample id from a line of restrictAncestries pc file";for(let r=1;r<=e;r++){const e=C+r,o=Number(t[r]);if(Number.isNaN(o))throw"non-numeric PC value from restrictAncestries file";n.get(e).set(i,o)}}return console.log(r,"samples loaded from "+t),Object.freeze(n)}function P(t,e,n){var r;if(!e)return;let o;if(null!=t&&null!==(r=t.cohort)&&void 0!==r&&r.termdb){for(const t of e){const e=Number(t.name);if(!Number.isInteger(e))throw"non-integer sample id from "+n;t.name=e}o=", all integer IDs"}console.log(e.length,"samples from "+n+" of "+t.label+o)}async function F(t,e){var n;const r=t.queries.snvindel.byrange;if(r._tk.file)await f.init_one_vcf(r._tk,e,!0);else if(r._tk.chr2files){let t;for(const n in r._tk.chr2files){if("chr17"!=n)continue;const o=r._tk.chr2files[n];try{await f.init_one_vcf(o,e,!0);const i=JSON.stringify(o.samples);if(t){if(i!=t)throw"Different samples found in bcf file of "+n}else t=i,r._tk.samples=o.samples,r._tk.format=o.format,r._tk.info=o.info,r._tk.nochr=o.nochr}catch(t){console.log("missing file ignored:",o.file)}}}if(null!==(n=r._tk)&&void 0!==n&&n.samples.length){if(!r._tk.format)throw"bcf file has samples but no FORMAT"}else if(r._tk.format)throw"bcf file has FORMAT but no samples";if(r._tk.format){for(const t in r._tk.format)"GT"==t&&(r._tk.format[t].isGT=!0);if(t.queries.snvindel.format4filters){if(!Array.isArray(t.queries.snvindel.format4filters))throw"snvindel.format4filters[] is not array";for(const e of t.queries.snvindel.format4filters)r._tk.format[e]&&(r._tk.format[e].isFilter=!0);delete t.queries.snvindel.format4filters}}if(r._tk.info){if(r.infoFields){for(const t of r.infoFields){if(!t.key)throw".key missing from one of snvindel.byrange.infoFields[]";t.name||(t.name=t.key);const e=r._tk.info[t.key];if(!e)throw"invalid key from one of snvindel.byrange.infoFields[]";e.categories=t.categories,e.name=t.name,e.separator=t.separator}delete r.infoFields}if(t.queries.snvindel.infoUrl){for(const e of t.queries.snvindel.infoUrl){const t=r._tk.info[e.key];if(!t)throw"invalid key from one of snvindel.infoUrl[]";t.urlBase=e.base}delete t.queries.snvindel.infoUrl}}return t.queries.snvindel.info=r._tk.info,t.queries.snvindel.format=r._tk.format,async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";const n=L(e);let o;if(r._tk.chr2files){const t=r._tk.chr2files[e.rglst[0].chr];if(!t)throw"unknown chr for chr2files";o=t.file}else o=r._tk.file||r._tk.url;const i=["query",o,"-r",e.rglst.map((t=>(r._tk.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+(t.stop+1))).join(","),"-f","%ID\t%CHROM\t%POS\t%REF\t%ALT\t%INFO\t%FORMAT\n"],s=await z(e,r._tk.samples,t);s&&i.push("-s",s.map((t=>t.name)).join(",")),e.variantFilter&&M(e.variantFilter,i);const a=[];return await f.get_lines_bigfile({isbcf:!0,args:i,dir:r._tk.dir,callback:o=>{const i=o.split("\t"),l=i[0],c=i[1],u=Number(i[2]),f=i[3],h=i[4].split(","),p=i[5],m={pos:u-1};d(r._tk,f,h,m,p,l,e.isoform);for(const o of m.mlst){var g,y,v;e.hiddenmclass&&e.hiddenmclass.has(o.class)||(D(o,e)||m.mlst.length>1&&null!==(g=e.variantFilter)&&void 0!==g&&g.lst&&B(o,e)||(o.chr=(r._tk.nochr?"chr":"")+c,o.ssm_id=[o.chr,o.pos,o.ref,o.alt].join(T),null!==(y=r._tk)&&void 0!==y&&null!==(v=y.samples)&&void 0!==v&&v.length&&($(r,o,i,e.addFormatValues,t,s,n),!o.samples)||a.push(o)))}}}),a}}function L(t){var e,n;const r=t.formatFilter||{};return"format"==(null===(e=t.skewerRim)||void 0===e?void 0:e.type)&&null!==(n=t.skewerRim.hiddenvalues)&&void 0!==n&&n.size&&(r[t.skewerRim.formatKey]=t.skewerRim.hiddenvalues),Object.keys(r).length?r:void 0}function D(t,e){if(!e.infoFilter)return!1;for(const n in e.infoFilter){const r=t.info[n];if(r)if(Array.isArray(r)){for(const t of e.infoFilter[n])if(r.includes(t))return!0}else if(e.infoFilter[n].includes(r))return!0}return!1}function B(t,e){for(const r of e.variantFilter.lst){const e=t.info[r.tvs.term.id];if(null==e)return!0;if("integer"==r.tvs.term.type||"float"==r.tvs.term.type){var n;const t=Number(e);if(Number.isNaN(t))return!0;const o=null===(n=r.tvs.ranges)||void 0===n?void 0:n[0];if(o){if("start"in o)if(o.startinclusive){if(t<o.start)return!0}else if(t<=o.start)return!0;if("stop"in o)if(o.stopinclusive){if(t>o.stop)return!0}else if(t>=o.stop)return!0}}}return!1}async function z(t,e,n){if(!e)return null;const r=function(t,e){if(t.filterObj){if(!Array.isArray(t.filterObj.lst))throw"filterObj.lst is not array";return 0==t.filterObj.lst.length?null:t.filterObj}if(t.tid2value){if("object"!=typeof t.tid2value)throw"q.tid2value{} not object";return Z(t.tid2value,e)}}(t,n);if(!r)return null;const o=[...new Set((await x(r,n)).map((t=>t.id)))],i=new Set(e.map((t=>t.name)));return o.filter((t=>i.has(t))).map((t=>({name:t})))}function Z(t,e){const n={type:"tvslst",in:!0,join:"and",lst:[]};for(const r in t){const o=e.cohort.termdb.q.termjsonByOneid(r);if(!o)continue;const i=t[r];n.lst.push({type:"tvs",tvs:{term:o,values:[{key:i}]}})}return n}function $(t,e,n,r,o,i,s){if(!n[6]||"."==n[6])return;const a=[];for(const e of n[6].split(":")){const n=t._tk.format[e];if(!n)throw"invalid format field: "+n;a.push(n)}const l=[];for(const[e,o]of(i||t._tk.samples).entries()){const t=n[e+7];if(!t||"."==t)continue;const i=G(t.split(":"),a,o,r);if(i){if(s){let t=!1;for(const e in s){const n=e in i.formatK2v?i.formatK2v[e]:j;if(s[e].has(n)){t=!0;break}}if(t)continue}l.push(i)}}l.length&&(e.samples=l)}function G(t,e,n,r){const o={};for(const[n,r]of e.entries()){const e=t[n];if(e&&"."!=e)if(r.isGT){if("./."==e||".|."==e)continue;o.GT=e}else o[r.ID]=e}if(0==Object.keys(o).length)return null;const i={sample_id:n.name};return r&&(i.formatK2v=o),i}function U(t,e,n,r=1){r=Number(r);const s=200,c=20;let u=0;for(const t in e.majorchr)u+=e.majorchr[t];const f=800/u,d={};let h=0;const p=[];for(const t in e.majorchr){const n=e.majorchr[t];d[t]=a().domain([0,n]).range([f*h,f*(h+n)]),h+=n,p.push({chr:t,chrLen:n,xStart:f*(h-n),xStop:f*h})}const m=a().domain([n.min,n.max]).range([s,0]),g=l(890*r,240*r),y=g.getContext("2d");r>1&&y.scale(r,r),b(n.max),b(0),b(n.min);const v=i.createInterface({input:o.createReadStream(t)});return new Promise(((t,r)=>{v.on("line",(t=>{const e=t.split("\t"),r=e[0];if(!r)return;if(!d[r])return;const o=Number(e[1]);if(!Number.isInteger(o))return;const i=Number(e[2]);if(!Number.isFinite(i))return;if(i<n.min||i>n.max)return;y.fillStyle=i>0?n.positiveColor:n.negativeColor;const s=d[r](o),a=c+m(i);y.fillRect(70+s,a,1,1)})),v.on("close",(()=>{!function(){y.strokeStyle="black",y.beginPath();{const t=220-m(0);y.moveTo(70,t),y.lineTo(870,t),y.stroke()}let t=!0;y.fillStyle="black",y.font="12px Arial",y.textAlign="center";for(const n in d){if(y.fillText(n.replace("chr",""),70+d[n](e.majorchr[n]/2),234),t){t=!1;continue}const r=Math.floor(70+d[n](0))+.5;y.moveTo(r,c),y.lineTo(r,220),y.stroke()}y.closePath()}(),t({src:g.toDataURL(),canvasWidth:890,canvasHeight:240,xoff:70,chrLst:p})}))}));function b(t){y.fillStyle="black",y.font="12px Arial",y.textAlign="right";const e=c+m(t);y.fillText(t,64,e+5),y.strokeStyle="black",y.beginPath(),y.moveTo(66,e),y.lineTo(70,e),y.stroke(),y.closePath()}}async function H(t,e){const n=t.queries.svfusion.byrange;if(n.file)await f.validate_tabixfile(n.file);else{if(!n.url)throw"file and url both missing on svfusion.byrange{}";n.dir=await f.cache_index(n.url,n.indexURL)}n.nochr=await f.tabix_is_nochr(n.file||n.url,null,e);{const t=await f.get_header_tabix(n.file);if(!t[0])throw"header line missing from "+n.file;const e=t[0].split(" ");if("#sample"!=e[0])throw"header line not starting with #sample: "+n.file;n.samples=e.slice(1).map((t=>({name:t})))}return async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";const r=L(e);let o;{const r=await z(e,n.samples,t);r&&(o=new Set(r.map((t=>t.name))))}const i=new Map;for(const t of e.rglst)await f.get_lines_bigfile({args:[n.file||n.url,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:n=>{const s=n.split("\t"),a=Number(s[1]);let l,c,u,f,d;try{l=JSON.parse(s[3])}catch(t){return}if(l.dt!=m&&l.dt!=g)return;if(l.class=l.dt==g?b:v,e.hiddenmclass&&e.hiddenmclass.has(l.class))return;if(l.sample&&o&&!o.has(l.sample))return;if(l.chrA)c=1,u=l.geneA||l.chrA,f=l.strandA,d=[{a:{chr:l.chrA,pos:l.posA,strand:l.strandA,name:l.geneA},b:{chr:t.chr,pos:a,strand:l.strandB,name:l.geneB}}];else if(l.chrB)c=0,u=l.geneB||l.chrB,f=l.strandB,d=[{a:{chr:t.chr,pos:a,strand:l.strandA,name:l.geneA},b:{chr:l.chrB,pos:l.posB,strand:l.strandB,name:l.geneB}}];else{if(!l.pairlst)throw"missing chrA and chrB";{d=l.pairlst;const t=l.pairlst.findIndex((t=>t.chr==chr&&t.pos==a));if(-1==t)throw"current point missing from pairlst";c=t}}const h=[l.dt,t.chr,a,f,c,encodeURIComponent(u)].join(T);let p;if(l.sample&&(p={sample_id:l.sample},l.mattr)){if(r)for(const t in r){const e=t in l.mattr?l.mattr[t]:j;if(r[t].has(e))return}e.addFormatValues&&(p.formatK2v=l.mattr)}i.has(h)||i.set(h,{ssm_id:h,dt:l.dt,class:l.class,chr:t.chr,pos:a,strand:f,pairlstIdx:c,mname:u,pairlst:d,samples:[]}),p&&i.get(h).samples.push(p)}});return[...i.values()]}}async function W(t,e){const n=t.queries.cnv.byrange;if(n.file)await f.validate_tabixfile(n.file);else{if(!n.url)throw"file and url both missing on cnv.byrange{}";n.dir=await f.cache_index(n.url,n.indexURL)}n.nochr=await f.tabix_is_nochr(n.file||n.url,null,e);{const t=await f.get_header_tabix(n.file);if(!t[0])throw"header line missing from "+n.file;const e=t[0].split(" ");if("#sample"!=e[0])throw"header line not starting with #sample: "+n.file;n.samples=e.slice(1).map((t=>({name:t})))}return async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";if(e.cnvMaxLength&&!Number.isInteger(e.cnvMaxLength))throw"cnvMaxLength is not integer";if(e.cnvGainCutoff&&!Number.isFinite(e.cnvGainCutoff))throw"cnvGainCutoff is not finite";if(e.cnvLossCutoff&&!Number.isFinite(e.cnvLossCutoff))throw"cnvLossCutoff is not finite";const r=L(e);let o;{const r=await z(e,n.samples,t);r&&(o=new Set(r.map((t=>t.name))))}const i=[],s=[];for(const t of e.rglst)s.push(f.get_lines_bigfile({args:[n.file||n.url,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:n=>{const s=n.split("\t"),a=Number(s[1]),l=Number(s[2]);if(e.cnvMaxLength&&l-a>=e.cnvMaxLength)return;let c;try{c=JSON.parse(s[3])}catch(t){return}if(c.dt==y&&Number.isFinite(c.value)&&!(c.value>0&&e.cnvGainCutoff&&c.value<e.cnvGainCutoff)&&!(c.value<0&&e.cnvLossCutoff&&c.value>e.cnvLossCutoff)&&(c.start=a,c.stop=l,c.class=c.value>0?_:w,(!e.hiddenmclass||!e.hiddenmclass.has(c.class))&&(!c.sample||!o||o.has(c.sample)))){if(c.ssm_id=[t.chr,c.start,c.stop,c.value].join(T),c.sample){const t={sample_id:c.sample};if(c.mattr){if(r)for(const t in r){const e=t in c.mattr?c.mattr[t]:j;if(r[t].has(e))return}e.addFormatValues&&(t.formatK2v=c.mattr)}delete c.sample,c.samples=[t]}i.push(c)}}}));return await Promise.all(s),i}}function J(t,e,n,r,o,i){for(const s of e.yesSamples){if(i&&!i.has(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:Number.parseInt(t),class:"WT",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:Number.parseInt(t),class:"WT",_SAMPLEID_:s})}for(const s of e.noSamples){if(i&&!i.has(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:Number.parseInt(t),class:"Blank",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:Number.parseInt(t),class:"Blank",_SAMPLEID_:s})}}async function V(t,e){if(t.chr&&Number.isInteger(t.start)&&Number.isInteger(t.stop))return;if(!t.name)throw"both term.name and term.chr/start/stop missing";const n=e.genedb.getjsonbyname.all(t.name);if(0==n.length)throw"unknown gene name";const r=n.find((t=>t.isdefault))||n[0],o=JSON.parse(r.genemodel);if(!o.chr||!Number.isInteger(o.start)||!Number.isInteger(o.stop))throw"invalid chr/start/stop from returned gm";t.chr=o.chr,t.start=o.start,t.stop=o.stop}function Y(t,e){e.yesSamples=new Set,e.noSamples=new Set;const n=`SELECT sample, value\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id = '${e.term_id}'`,r=t.cohort.db.connection.prepare(n).all();for(const t of r)e.yes.value.includes(t.value)?e.yesSamples.add(t.sample):e.no.value.includes(t.value)&&e.noSamples.add(t.sample)}},8089:(t,e,n)=>{"use strict";n.d(e,{f:()=>u});const r=n(9699),o=n(7147),i=n(1017),s=n(2081).spawn,a=n(3856),l=n(334),c=n(9535).snvindelByRangeGetter_bcf;n(1271).run_rust;function u(t){return async(e,n)=>{try{if(!e.query.genome)throw".genome missing";const o=t[e.query.genome];if(!o)throw"invalid genome";const i=function(t,e){const n=t.query;t.get("X-Auth-Token")&&(n.token=t.get("X-Auth-Token"));t.cookies.sessionid&&(n.sessionid=t.cookies.sessionid);n.hiddenmclasslst&&(n.hiddenmclass=new Set(n.hiddenmclasslst.split(",")),delete n.hiddenmclasslst);return n}(e),s=await async function(t,e){if(t.dslabel){if(!e.datasets)throw".datasets{} missing from genome";const n=e.datasets[t.dslabel];if(!n)throw"invalid dslabel";return n}const n={queries:{}};if(t.bcffile||t.bcfurl){const[o,i,s]=r.fileurl({query:{file:t.bcffile,url:t.bcfurl}});if(o)throw o;const a={};s?(a.url=i,a.indexURL=t.bcfindexURL):a.file=i,n.queries.snvindel={byrange:{_tk:a}},n.queries.snvindel.byrange.get=await c(n,e)}return n}(i,o);!function(t,e){var n;if(t.filter0){const n="object"==typeof t.filter0?t.filter0:JSON.parse("string"==typeof t.filter0&&t.filter0.startsWith("%")?decodeURIComponent(t.filter0):t.filter0);t.filter0=e.validate_filter0(n)}t.filterObj&&"string"==typeof t.filterObj&&(t.filterObj=JSON.parse("string"==typeof t.filterObj&&t.filterObj.startsWith("%")?decodeURIComponent(t.filterObj):t.filterObj));if(t.skewerRim){if("format"!=t.skewerRim.type)throw"unknown skewerRim.type";var r,o;if(!t.skewerRim.formatKey)throw"skewerRim.formatKey missing when type=format";if(null===(r=e.queries)||void 0===r||null===(o=r.snvindel)||void 0===o||!o.format)throw"snvindel.format{} not found when type=format";if(!e.queries.snvindel.format[t.skewerRim.formatKey])throw"invalid skewerRim.formatKey";if(t.skewerRim.hiddenvalues=new Set,t.skewerRim.hiddenvaluelst){if(!Array.isArray(t.skewerRim.hiddenvaluelst))throw"query.skewerRim.hiddenvaluelst is not array";for(const e of t.skewerRim.hiddenvaluelst)t.skewerRim.hiddenvalues.add(e);delete t.skewerRim.hiddenvaluelst}}if(t.formatFilter){var i,s;if("object"!=typeof t.formatFilter)throw"formatFilter{} not object";if(null===(i=e.queries)||void 0===i||null===(s=i.snvindel)||void 0===s||!s.format)throw"snvindel.format{} not found when formatFilter is used";const n={};for(const r in t.formatFilter){if(!e.queries.snvindel.format[r])throw"invalid format key from formatFilter";if(!Array.isArray(t.formatFilter[r]))throw"formatFilter[k] value is not array";n[r]=new Set(t.formatFilter[r])}t.formatFilter=n}("format"==(null===(n=t.skewerRim)||void 0===n?void 0:n.type)||t.formatFilter)&&(t.addFormatValues=!0)}(i,s);const a=await async function(t,e){if(t.singleSampleMutation){var n;if(null===(n=e.queries.singleSampleMutation)||void 0===n||!n.get)throw"not supported on this dataset";return{mlst:await e.queries.singleSampleMutation.get(t.singleSampleMutation,t)}}if(t.singleSampleGenomeQuantification){if(!e.queries.singleSampleGenomeQuantification)throw"not supported on this dataset";const n=e.queries.singleSampleGenomeQuantification[t.singleSampleGenomeQuantification.dataType];if(!n)throw"invalid dataType";return await n.get(t.singleSampleGenomeQuantification.sample,t.devicePixelRatio)}if(t.singleSampleGbtk){if(!e.queries.singleSampleGbtk)throw"not supported on this dataset";const n=e.queries.singleSampleGbtk[t.singleSampleGbtk.dataType];if(!n)throw"invalid dataType";return await n.get(t.singleSampleGbtk.sample)}if(t.ssm2canonicalisoform){if(!e.ssm2canonicalisoform)throw"ssm2canonicalisoform not supported on this dataset";return{isoform:await e.ssm2canonicalisoform.get(t)}}if(t.variant2samples){if(!e.variant2samples)throw"not supported by server";return{variant2samples:await e.variant2samples.get(t)}}if(t.m2csq){if(e.queries&&e.queries.snvindel&&e.queries.snvindel.m2csq)return{csq:await e.queries.snvindel.m2csq.get(t)};throw"m2csq not supported on this dataset"}if(t.forTrack){const n={};if(t.skewer){if(n.skewer=[],e.queries.snvindel){const r=await async function(t,e){if(t.isoform){if(t.atgenomic){if(!e.queries.snvindel.byrange)throw".atgenomic but missing byrange query method";return await e.queries.snvindel.byrange.get(t)}if(e.queries.snvindel.byisoform)return await e.queries.snvindel.byisoform.get(t)}if(t.rglst){if(!e.queries.snvindel.byrange)throw"q.rglst[] provided but .byrange{} is missing";return await e.queries.snvindel.byrange.get(t)}throw"insufficient query parameters for snvindel"}(t,e);n.skewer.push(...r)}if(e.queries.svfusion){const r=await async function(t,e){if(t.rglst){if(!e.queries.svfusion.byrange)throw"q.rglst provided but svfusion.byrange missing";return await e.queries.svfusion.byrange.get(t)}throw"insufficient query parameters for svfusion"}(t,e);n.skewer.push(...r)}if(e.queries.geneCnv){const r=await async function(t,e){if(t.gene){if(!e.queries.geneCnv.bygene)throw"q.gene provided but geneCnv.bygene missing";return await e.queries.geneCnv.bygene.get(t)}throw"insufficient query parameters for geneCnv"}(t,e);n.geneCnv=r}!function(t,e){if(e.skewer){const n=[];for(const r of e.skewer)t.rglst&&!t.rglst.find((t=>r.chr==t.chr&&r.pos>=t.start&&r.pos<=t.stop))||n.push(r);e.skewer=n}e.genecnvAtsample}(t,n),n.mclass2variantcount=function(t){const e=new Map;for(const n of t){const t=n.class||n.dt;e.set(t,1+(e.get(t)||0))}return[...e].sort(((t,e)=>e[1]-t[1]))}(n.skewer)}return function(t,e,n){const r=new Set;if(n.skewer)for(const o of n.skewer)if(o.samples){o.occurrence=o.samples.length,f(o,t,e),d(o,e);for(const t of o.samples)r.add(t.sample_id);delete o.samples}r.size&&(n.sampleTotalNumber=r.size)}(t,e,n),n}if(t.geneExpression){if(!e.queries.geneExpression)throw"not supported";const n=await e.queries.geneExpression.get(t);if(0==n.size)throw"no data";return 1==n.size?{gene2sample2value:n}:{clustering:await h(n,t)}}throw"do not know what client wants"}(i,s);n.send(a)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}function f(t,e,n){if(e.skewerRim){if("format"!=e.skewerRim.type)throw"unknown skewerRim.type";t.rim1count=0;for(const n of t.samples){var r;(null===(r=n.formatK2v)||void 0===r?void 0:r[e.skewerRim.formatKey])==e.skewerRim.rim1value&&t.rim1count++}}}function d(t,e){var n;if(null!==(n=e.queries.snvindel)&&void 0!==n&&n.format)for(const n in e.queries.snvindel.format)if(e.queries.snvindel.format[n].isFilter){t.formatK2count||(t.formatK2count={}),t.formatK2count[n]||(t.formatK2count[n]={v2c:{},unannotatedCount:0});for(const e of t.samples){var r;const o=null===(r=e.formatK2v)||void 0===r?void 0:r[n];null==o?t.formatK2count[n].unannotatedCount++:t.formatK2count[n].v2c[o]=1+(t.formatK2count[n].v2c[o]||0)}}}async function h(t,e){const n=new Set;for(const e of t.values())for(const t in e)n.add(t);const r={matrix:[],row_names:[],col_names:[...n],cluster_method:e.clusterMethod,plot_image:!1};for(const[e,n]of t){r.row_names.push(e);const t=[];for(const e of r.col_names)t.push(n[e]||0);const o=p(t);r.matrix.push(o)}new Date;const c=i.join(l.cachedir,Math.random().toString()+".json");await a.write_file(c,JSON.stringify(r));const u=await async function(t,e=[]){try{await o.promises.stat(t)}catch(e){throw`${t} does not exist`}const n=[],r=[];return new Promise(((o,i)=>{console.log("serverconfig.Rscript:",l.Rscript),console.log("Rscript:",t),console.log("args:",...e);const a=s(l.Rscript,[t,...e]);a.stdout.on("data",(t=>n.push(t))),a.stderr.on("data",(t=>r.push(t))),a.on("error",(t=>i(t))),a.on("close",(t=>{const e=n.join("").trim().split("\n");o(e)}))}))}(i.join(l.binpath,"utils","fastclust.R"),[c]);o.unlink(c,(()=>{}));let f,d,h=[],g=[],y=!1,v=!1;for(const t of u)t.includes('[1] "RowCoordinates"')?y=!0:t.includes('"ColumnCoordinates"')?(v=!0,y=!1):t.includes("rownames")?f=t.replace("rownames\t","").split("\t").map((t=>parseInt(t))).filter((t=>t)):t.includes("colnames")?d=t.replace("colnames\t","").split("\t").map((t=>parseInt(t))).filter((t=>t)):t.includes('"Done"')?v=!1:1==y?h.push(t):1==v&&g.push(t);let b=await m(h,f),_=await m(g,d);return{geneNameLst:r.row_names,sampleNameLst:r.col_names,matrix:r.matrix,row_dendro:b.dendrogram,row_children:b.children,row_names_index:f,col_dendro:_.dendrogram,col_children:_.children,col_names_index:d}}function p(t){let e=0;for(const n of t)e+=n;const n=e/t.length,r=Math.sqrt(t.map((t=>(t-n)**2)).reduce(((t,e)=>t+e),0)/(t.length-1));return 0==r?t:t.map((t=>(t-n)/r))}async function m(t,e){let n=1,r=[],o=[];for(const e of t)if(1==n)n=0;else if(0==e.length);else{let t=e.split(/(\s+)/);Number(t[t.length-3])%1!=0&&0==Number(t[t.length-1])?(r.push(Number(t[t.length-3])),o.push(1e-4)):(r.push(Number(t[t.length-3])),o.push(Number(t[t.length-1])))}let i=[],s=[],a=[],l=!1,c=[],u=0;for(let t=0;t<o.length;t++)if(1==l){let n=0;for(let e=0;e<s.length;e++){let l=s.length-e-1;if(s[l]>o[t]){i.push({id1:t,x1:r[t],y1:o[t],id2:l,x2:a[l],y2:s[l]}),n=1;break}}0==n&&console.log("No suitable branch point found"),i.push({id1:t,x1:r[t],y1:o[t],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t]),l=!1}else o[t]>o[t+1]&&t<=o.length-1?(i.push({id1:t,x1:r[t],y1:o[t],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t])):o[t]==o[t+1]&&t<=o.length-1?(i.push({id1:t-1,x1:r[t-1],y1:o[t-1],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t])):(t==o.length-1||(s.push(o[t]),a.push(r[t]),l=!0),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1));return{dendrogram:i,children:c}}async function g(t,e,n,r){let o=e;if(n.find((t=>t.id==o))){let t=n.findIndex((t=>t.id==o));n[t].children.push(r)}else n.push({id:o,children:[r]});for(;0!=o;){let e,i,s=t.find((t=>t.id1==o));s&&s.y1<=s.y2&&(e=s.id2);let a=t.find((t=>t.id2==o));if(a&&a.y1>=a.y2&&(i=a.id1),!s&&a?o=i:s&&!a?o=e:s&&a?o=s.y2>a.y1?e:i:console.log("No connections found!"),n.find((t=>t.id==o))){let t=n.findIndex((t=>t.id==o));n[t].children.push(r)}else n.push({id:o,children:[r]})}return n}},4143:(t,e,n)=>{"use strict";n.d(e,{R:()=>s});const{filterJoin:r}=n(478),{get_rows_by_one_key:o}=n(2852),i=n(1271).run_rust;n(1017),n(334);async function s(t,e,n,r){!function(t,e){if(!t.chr)throw"q.chr missing";if(t.start=Number(t.start),t.stop=Number(t.stop),!Number.isInteger(t.start)||!Number.isInteger(t.stop))throw"q.start/stop is not integer";if("object"!=typeof t.details)throw"q.details{} not object";if(!Array.isArray(t.details.groups))throw"q.details.groups[] not array";if(!t.details.groups[0])throw"q.details.groups[0] missing";if(t.details.groups.length>2)throw"q.details.groups[] has more than 2";for(const r of t.details.groups)if("filter"==r.type){if("object"!=typeof r.filter)throw".filter not an object for group type=filter"}else if("population"==r.type){var n;if(!r.key)throw".key missing from group type=population";if(null===(n=e.queries.snvindel)||void 0===n||!n.populations)throw"group type=population but this ds does not have populations";if(!e.queries.snvindel.populations.find((t=>t.key==r.key)))throw"invalid key of group type=population"}else{if("info"!=r.type)throw"unknown group type from details.groups[]";if(!r.infoKey)throw".infoKey missing from group type=info"}if(t.details.groupTestMethods){if(!Array.isArray(t.details.groupTestMethods))throw"details.groupTestMethods[] not array";if(!Number.isInteger(t.details.groupTestMethodsIdx))throw"details.groupTestMethodsIdx not integer";if(!t.details.groupTestMethods[t.details.groupTestMethodsIdx])throw"invalid array index of details.groupTestMethodsIdx"}}(t,n);const i=await async function(t,e){const n={rglst:[{chr:t.chr,start:t.start,stop:t.stop}],addFormatValues:!0,variantFilter:t.variantFilter},[r,o]=t.details.groups;if("filter"==r.type&&"filter"==(null==o?void 0:o.type)){n.filterObj=c(t,r.filter);const i=l(await e.queries.snvindel.byrange.get(n));n.filterObj=c(t,o.filter);const s=l(await e.queries.snvindel.byrange.get(n)),u=function(t,e,n){const[r,o]=n.details.groups,i=[];for(const n of t){n.groupData=[{refCount:n._refCount,altCount:n._altCount}];const t=e.find((t=>t.chr==n.chr&&t.pos==n.pos&&t.ref==n.ref&&t.alt==n.alt));t?n.groupData.push({refCount:t._refCount,altCount:t._altCount}):n.groupData.push({refCount:0,altCount:0}),i.push(n)}for(const n of e){t.find((t=>t.chr==n.chr&&t.pos==n.pos&&t.ref==n.ref&&t.alt==n.alt))||(n.groupData=[{refCount:0,altCount:0},{refCount:n._refCount,altCount:n._altCount}],i.push(n))}return i}(i.mlst,s.mlst,t);return{mlst:u,totalSampleCount_group1:a(i.mlst),totalSampleCount_group2:a(s.mlst)}}n.filterObj=c(t);const i=await e.queries.snvindel.byrange.get(n),s=l(i);"filter"==r.type?s.totalSampleCount_group1=a(i):"filter"==(null==o?void 0:o.type)&&(s.totalSampleCount_group2=a(i));return s}(t,n);if(1==t.details.groups.length)u(n,i.mlst,t.details.groups[0]);else{if(2!=t.details.groups.length)throw"q.details.groups.length not 1 or 2";await async function(t,e,n){const[r,i]=e.groups;if("filter"==r.type&&"filter"==i.type)return void await async function(t,e,n){const r=e.groupTestMethods[e.groupTestMethodsIdx];if(!r)throw"details.groupTestMethodsIdx out of bound";switch(r.name){case"Allele frequency difference":return void d(t,e,n);case"Fisher's exact test":return void await m(n);default:throw"unknown value from groupTestMethods[]"}}(t,e,n);if("population"==r.type&&"filter"==i.type||"population"==i.type&&"filter"==r.type)return void await async function(t,e,n){const r=await async function(t,e,n){const r=e.groups.find((t=>"population"==t.type));if(!r)return;if(!r.adjust_race)return;const i=t.queries.snvindel.populations.find((t=>t.key==r.key));if(!i)throw"invalid group.key for population";const s=new Set;for(const t of n)for(const e of t.samples)s.add(e.sample_id);const a=new Map;let l=0;for(const e of i.sets){const n={infokey_AC:e.infokey_AC,infokey_AN:e.infokey_AN,average:0},r=await o({ds:t,key:e.key});for(const t of r){if(!s.has(t.sample))continue;const e=Number(t.value);Number.isFinite(e)&&(n.average+=e,l+=e)}a.set(e.key,n)}for(const[t,e]of a)e.average/=l;return a}(t,e,n);for(const o of n)o.groupData=h(t,e,o,r);const i=e.groupTestMethods[e.groupTestMethodsIdx];if(!i)throw"details.groupTestMethodsIdx out of bound";switch(i.name){case"Allele frequency difference":return void d(t,e,n);case"Fisher's exact test":return void await m(n);default:throw"unknown value from groupTestMethods[]"}}(t,e,n);d(t,e,n)}(n,t.details,i.mlst)}for(const t of i.mlst)delete t.samples,delete t._altCount,delete t._refCount;e.send(i)}function a(t){const e=new Set;for(const n of t)if(n.samples)for(const t of n.samples)e.add(t.sample_id);return e.size}function l(t){const e={mlst:[],skipMcountWithoutAlt:0};for(const n of t){const[t,r]=f(n);0!=t?(n._altCount=t,n._refCount=r-t,e.mlst.push(n)):e.skipMcountWithoutAlt++}return e}function c(t,e){const n=[t.filter];if(e)n.push(e);else for(const e of t.details.groups)"filter"==e.type&&n.push(e.filter);return r(n)}function u(t,e,n){if("filter"!=n.type)if("info"!=n.type){if("population"!=n.type)throw"unknown type of single group";{const r=t.queries.snvindel.populations.find((t=>t.key==n.key));if(!r)throw"unknown population";for(const t of e){let e=0,n=0;for(const o of r.sets)e+=Number(t.info[o.infokey_AC]||0),n+=Number(t.info[o.infokey_AN]||0);t.nm_axis_value=e/n}}}else{if(!n.infoKey)throw"infoKey missing on single group.type=info";for(const t of e){const e=t.info[n.infoKey];if(null==e);else{const n=Number(e);Number.isNaN(n)||(t.nm_axis_value=n)}}}else for(const t of e)t.nm_axis_value=Number((t._altCount/(t._altCount+t._refCount)).toPrecision(2))}function f(t){let e=0,n=0;for(const o of t.samples){var r;if(null==o||null===(r=o.formatK2v)||void 0===r||!r.GT)continue;const i=o.formatK2v.GT.split("/").map(Number);n+=i.length;for(const n of i)n==t.altAlleleIdx&&e++}return[e,n]}function d(t,e,n){const[r,o]=e.groups;u(t,n,r);const i=n.map((t=>t.nm_axis_value));u(t,n,o);for(const[t,e]of n.entries())e.nm_axis_value=i[t]-e.nm_axis_value}function h(t,e,n,r){const o=[];for(const i of e.groups)if("info"!=i.type)if("filter"!=i.type){if("population"!=i.type)throw"unknown group.type";{if(!i.key)throw"group.key missing for type=population";const e=t.queries.snvindel.populations.find((t=>t.key==i.key));if(!e)throw"invalid group.key for population";const s=new Map;for(const t of e.sets)s.set(t.key,{ACraw:Number(n.info[t.infokey_AC]||0),ANraw:Number(n.info[t.infokey_AN]||0)});let a=0,l=0;if(i.adjust_race)[a,l]=p(s,r);else for(const t of s.values())l+=t.ACraw,a+=t.ANraw-t.ACraw;o.push({altCount:l,refCount:a})}}else o.push({altCount:n._altCount,refCount:n._refCount});else{if(!i.key)throw"group.key missing for type=info";o.push({value:n.info[i.key]})}return o}function p(t,e){let n=0;for(const e of t.values())n+=e.ANraw;let r=0,o=0;for(const[i,s]of t)s.ANadj=n*e.get(i).average,s.ACadj=0==s.ANadj?0:s.ACraw*s.ANadj/s.ANraw,r+=s.ACadj,o+=s.ANadj;return[o-r,r]}async function m(t){for(let e=0;e<Math.ceil(t.length/200);e++){const n=[];for(let r=200*e;r<200*(e+1);r++){const e=t[r];if(!e)break;const o=e.groupData;o&&o[0]&&o[1]&&Number.isFinite(o[0].altCount)&&Number.isFinite(o[0].refCount)&&Number.isFinite(o[1].altCount)&&Number.isFinite(o[1].refCount)?(n.push({index:r,n1:o[0].altCount,n2:o[0].refCount,n3:Math.floor(o[1].altCount),n4:Math.floor(o[1].refCount)}),e.htmlSections=[{key:"Contigency table",html:`<table style="font-size:.9em">\n\t\t\t\t<tr style="opacity:.5">\n\t\t\t\t <td></td>\n\t\t\t\t <td>Group1</td>\n\t\t\t\t <td>Group 2</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">ALT allele count</td>\n\t\t\t\t <td>${o[0].altCount}</td>\n\t\t\t\t <td>${Math.floor(o[1].altCount)}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">REF allele count</td>\n\t\t\t\t <td>${o[0].refCount}</td>\n\t\t\t\t <td>${Math.floor(o[1].refCount)}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">Allele frequency</td>\n\t\t\t\t <td>${(o[0].altCount/(o[0].altCount+o[0].refCount)).toFixed(3)}</td>\n\t\t\t\t <td>${(o[1].altCount/(o[1].altCount+o[1].refCount)).toFixed(3)}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>`}]):console.log(`${e.chr}.${e.pos}.${e.ref}.${e.alt}\t${JSON.stringify(o)}`)}const r=await i("fisher",JSON.stringify({input:n}));for(const e of JSON.parse(r)){const n=t[e.index];n&&(n.p_value=e.p_value.toPrecision(2),e.p_value>0&&(n.nm_axis_value=Number((-Math.log10(e.p_value)).toPrecision(2))))}}let e=0;for(const n of t)n.p_value>0&&(e=Math.max(e,n.nm_axis_value));for(const n of t)0==n.p_value&&(n.nm_axis_value=Math.max(50,e))}},817:(t,e,n)=>{"use strict";n.r(e),n.d(e,{combineSamplesById:()=>d,get_crosstabCombinations:()=>g,validate_variant2samples:()=>f});const{stratinput:r}=n(1881),{querySamples_gdcapi:o}=n(5243),{get_densityplot:i}=n(9402),{ssmIdFieldsSeparator:s}=n(9535),{dtfusionrna:a,dtsv:l}=(n(3856),n(2273)),c=n(4065),{getSampleData_dictionaryTerms_termdb:u}=n(2974);function f(t){const e=t.variant2samples;if(e){if(e.type_samples="samples",e.type_sunburst="sunburst",e.type_summary="summary",!e.variantkey)throw".variantkey missing from variant2samples";if(-1==["ssm_id"].indexOf(e.variantkey))throw"invalid value of variantkey";if(e.twLst){if(!Array.isArray(e.twLst))throw"variant2samples.twLst[] is not array";if(0==e.twLst.length)throw"variant2samples.twLst[] empty array";if(!t.cohort||!t.cohort.termdb)throw"ds.cohort.termdb missing when variant2samples.twLst is in use";for(const n of e.twLst){if(!n.id)throw"tw.id missing from one of variant2samples.twLst[]";const e=t.cohort.termdb.q.termjsonByOneid(n.id);if(!e)throw"term not found for one of variant2samples.twLst: "+n.id;if(n.term=e,!n.q)throw"tw.q{} missing for one of variant2samples.twLst: "+n.id}}if(e.sunburst_twLst){if(!Array.isArray(e.sunburst_twLst))throw".sunburst_twLst[] not array from variant2samples";if(0==e.sunburst_twLst.length)throw".sunburst_twLst[] empty array from variant2samples";if(!t.cohort||!t.cohort.termdb)throw"ds.cohort.termdb missing when variant2samples.sunburst_twLst is in use";for(const n of e.sunburst_twLst){if(!n.id)throw"tw.id missing from one of variant2samples.sunburst_twLst[]";const e=t.cohort.termdb.q.termjsonByOneid(n.id);if(!e)throw"term not found for one of variant2samples.sunburst_twLst: "+n.id;if(n.term=e,!n.q)throw"tw.q{} missing for one of variant2samples.sunburst_twLst: "+n.id}}if(e.gdcapi);else{var n,f,y,v,b,_,w;let e=!1;if(null!==(n=t.queries)&&void 0!==n&&null!==(f=n.snvindel)&&void 0!==f&&null!==(y=f.byrange)&&void 0!==y&&null!==(v=y._tk)&&void 0!==v&&v.samples&&(e=!0),null!==(b=t.queries)&&void 0!==b&&null!==(_=b.svfusion)&&void 0!==_&&null!==(w=_.byrange)&&void 0!==w&&w.samples&&(e=!0),!e)throw"cannot find a sample source from ds.queries{}"}if(e.get=async e=>await async function(t,e){!function(t,e){if("samples"==t.get){var n,r;const o=null===(n=e.queries)||void 0===n||null===(r=n.snvindel)||void 0===r?void 0:r.byrange;o&&(o.bcffile||o.chr2bcffile)&&o._tk.format&&(t.addFormatValues=!0)}}(t,e);const n=await async function(t,e){var n;const r=t.twLst?t.twLst.slice():[];if(e.variant2samples.gdcapi)return await o(t,r,e,t.geneTwLst);if(t.ssm_id_lst)return await async function(t,e,n){const r=new Map;for(const e of t.ssm_id_lst.split(",")){const o=e.split(s);if(4!=o.length){if(6!=o.length)throw"unknown format of ssm id";{if(!n.queries.svfusion||!n.queries.svfusion.byrange)throw"queries.svfusion.byrange missing when id has 6 fields";const[e,i,s,c,u,f]=o,h=decodeURIComponent(f),p=Number(e);if(p!=l&&p!=a)throw"dt not sv/fusion";const m=Number(s);if(Number.isNaN(m))throw"position not integer";const g=Number(u);if(Number.isNaN(g))throw"pairlstIdx not integer";const y=Object.assign({},t,{rglst:[{chr:i,start:m,stop:m+1}]}),v=await n.queries.svfusion.byrange.get(y);for(const t of v)t.dt==p&&t.pos==m&&t.strand==c&&t.pairlstIdx==g&&t.mname==h&&d(t.samples,r,t.ssm_id)}}else{if(!n.queries.snvindel||!n.queries.snvindel.byrange)throw"queries.snvindel.byrange missing when id has 4 fields";const[e,i,s,a]=o,l=Number(i);if(Number.isNaN(l))throw"no integer position for snvindel from ssm id";const c=Object.assign({},t,{rglst:[{chr:e,start:l,stop:l}]}),u=await n.queries.snvindel.byrange.get(c);for(const t of u)t.pos==l&&t.ref==s&&t.alt==a&&d(t.samples,r,t.ssm_id)}}return h(r,e,n),[...r.values()]}(t,r,e);if(t.rglst)return await p(t,r,e);if(t.geneTwLst){if("object"!=typeof t.genome)throw"serverside genome obj needed";t.rglst=[];for(const e of t.geneTwLst)if(e.term.chr&&e.term.start&&e.term.stop)t.rglst.push({chr:e.term.chr,start:e.term.start,stop:e.term.stop});else{const n=c.getResult(t.genome,{deep:1,input:e.term.name});if(n.gmlst){const e=n.gmlst[0];t.rglst.push({chr:e.chr,start:e.start,stop:e.stop})}}const n=await p(t,r,e);return delete t.rglst,n}if(null==e||null===(n=e.cohort)||void 0===n||!n.termdb)throw"unable to do sql query: .cohort.termdb missing for ds";const i={ds:e,filter:t.filter||t.filterObj},f=await u(i,t.twLst),m=[];for(const e in f.samples){const n=f.samples[e];n.sample_id=n.sample,delete n.sample;for(const e of t.twLst)n[e.term.id]&&(n[e.term.id]=n[e.term.id].key);m.push(n)}return m}(t,e);if(t.get==e.variant2samples.type_samples){var f,y,v;return!t.useIntegerSampleId&&null!=e&&null!==(f=e.cohort)&&void 0!==f&&null!==(y=f.termdb)&&void 0!==y&&null!==(v=y.q)&&void 0!==v&&v.id2sampleName&&n.forEach((t=>t.sample_id=e.cohort.termdb.q.id2sampleName(t.sample_id))),n}if(t.get==e.variant2samples.type_sunburst)return await async function(t,e,n){var o,i;const s=r(t,n.twLst.map((t=>({k:t.id}))));for(const t of s)delete t.lst;if(null!=e&&null!==(o=e.cohort)&&void 0!==o&&null!==(i=o.termdb)&&void 0!==i&&i.termid2totalsize2){const t=await g(n.twLst,e,n,s);await async function(t,e,n){for(const r of t){if(!r.id0)continue;if(!r.v0)continue;const t=n.cohort.termdb.useLower?r.v0.toLowerCase():r.v0;if(!r.id1){const n=e.find((e=>null==e.id1&&e.v0==t));n&&(r.cohortsize=n.count);continue}if(!r.v1)continue;const o=n.cohort.termdb.useLower?r.v1.toLowerCase():r.v1;if(!r.id2){const n=e.find((e=>null==e.id2&&e.v0==t&&e.v1==o));n&&(r.cohortsize=n.count);continue}if(!r.v2)continue;const i=n.cohort.termdb.useLower?r.v2.toLowerCase():r.v2;if(!r.id3){const e=crosstabL2.find((e=>e.v0==t&&e.v1==o&&e.v2==i));e&&(r.cohortsize=e.count)}}}(s,t,e)}return s}(n,e,t);if(t.get==e.variant2samples.type_summary){const r=await async function(t,e,n){if(!n.twLst)throw"q.twLst[] missing for make_summary()";const r=[];for(const e of n.twLst)if(e.term)if("categorical"==e.term.type){const n=m(t,e.id);r.push({termid:e.id,termname:e.term.name,numbycategory:[...n].sort(((t,e)=>e[1]-t[1]))})}else{if("integer"!=e.term.type&&"float"!=e.term.type)throw"unknown term type";{const n=await i(e.term,t);r.push({termid:e.id,termname:e.term.name,density_data:n})}}if(e.cohort.termdb.termid2totalsize2){const t=await e.cohort.termdb.termid2totalsize2.get(n.twLst,n);for(const{termid:e,numbycategory:n}of r){if(!n)continue;const r=t.get(e);if(r)for(const t of n){const e=r.find((e=>e[0].toLowerCase()==t[0].toLowerCase()));e&&t.push(e[1])}}}return r}(n,e,t);return r}throw"unknown get type"}(e,t),e.url&&!e.url.base)throw".variant2samples.url.base missing"}}function d(t,e,n){for(const r of t){e.has(r.sample_id)||(r.ssm_id_lst=[],r.formatK2v&&(r.ssmid2format={}),e.set(r.sample_id,r));const t=e.get(r.sample_id);t.ssm_id_lst.push(n),t.ssmid2format&&(t.ssmid2format[n]=r.formatK2v)}}function h(t,e,n){if(e)for(const r of t.values())for(const t of e){const e=n.cohort.termdb.q.getSample2value(t.id,r.sample_id);e[0]&&(r[t.id]=e[0].value)}}async function p(t,e,n){const r=new Map;if(n.queries.snvindel){const e=await n.queries.snvindel.byrange.get(t);for(const t of e)d(t.samples,r,t.ssm_id)}if(n.queries.svfusion){const e=await n.queries.svfusion.byrange.get(t);for(const t of e)d(t.samples,r,t.ssm_id)}return h(r,e,n),[...r.values()]}function m(t,e){const n=new Map;if("sample_id"in t[0]){for(const r of t){const t=r[e];t&&(n.has(t)||n.set(t,new Set),n.get(t).add(r.sample_id))}const r=new Map;for(const[t,e]of n)r.set(t,e.size);return r}if("case_uuid"in t[0]){for(const r of t){const t=r[e];t&&(n.has(t)||n.set(t,new Set),n.get(t).add(r.case_uuid))}const r=new Map;for(const[t,e]of n)r.set(t,e.size);return r}for(const e of t){const t=e[term.id];t&&n.set(t,1+(n.get(t)||0))}return n}async function g(t,e,n,r){var o,i;if(0==t.length)throw"zero terms for crosstab";if(t.length>3)throw"crosstab will not work with more than 3 levels";const s=[],a=new Map;for(const e of t)a.set(e.id,new Set);const l=!r;if(r)for(const n of r){if(n.id0){if(!n.v0)continue;a.get(n.id0).add(e.cohort.termdb.useLower?n.v0.toLowerCase():n.v0)}if(n.id1&&t[1]){if(!n.v1)continue;a.get(n.id1).add(e.cohort.termdb.useLower?n.v1.toLowerCase():n.v1)}if(n.id2&&t[2]){if(!n.v2)continue;a.get(n.id2).add(e.cohort.termdb.useLower?n.v2.toLowerCase():n.v2)}}const c=t[0].id;{const n=await e.cohort.termdb.termid2totalsize2.get([t[0]]);for(const[t,r]of n.get(c)){const n=e.cohort.termdb.useLower?t.toLowerCase():t;l?(a.get(c).add(n),s.push({count:r,id0:c,v0:n})):a.get(c).has(n)&&s.push({count:r,id0:c,v0:n})}}const u=null==t||null===(o=t[1])||void 0===o?void 0:o.id;if(u){const n=[];for(const r of a.get(c))n.push(e.cohort.termdb.termid2totalsize2.get([t[1]],{tid2value:{[c]:r}},r));const r=await Promise.all(n);for(const[t,n]of r)for(const[r,o]of t.get(u)){const t=e.cohort.termdb.useLower?r.toLowerCase():r;l?(a.get(u).add(t),s.push({count:o,id0:c,v0:n,id1:u,v1:t})):a.get(u).has(t)&&s.push({count:o,id0:c,v0:n,id1:u,v1:t})}}const f=null==t||null===(i=t[2])||void 0===i?void 0:i.id;if(f){const r=[];for(const o of a.get(c))for(const i of a.get(u)){JSON.parse(JSON.stringify(n));r.push(e.cohort.termdb.termid2totalsize2.get([t[2]],{tid2value:{[c]:o,[u]:i}},{v0:o,v1:i}))}const o=await Promise.all(r);for(const[t,n]of o)for(const[t,r]of v2counts.get(f)){const o=e.cohort.termdb.useLower?t.toLowerCase():t;l?(a.get(f).add(o),s.push({count:r,id0:c,v0:n.v0,id1:u,v1:n.v1,id2:f,v2:o})):a.get(f).has(o)&&s.push({count:r,id0:c,v0:n.v0,id1:u,v1:n.v1,id2:f,v2:o})}}return s}},5728:(t,e)=>{function n(t,e,n){const r=[];for(const o of t){const t=new Map,i=[];for(const r of o.samples){const o=n.sample2term.get(r);if(o){const n=o.get(e);null==n?i.push(r):(t.has(n)||t.set(n,[]),t.get(n).push(r))}else i.push(r)}const s=[...t].sort(((t,e)=>e[1].length-t[1].length));for(const t of s){const e={value:t[0],samples:t[1],children:[]};r.push(e),o.children&&o.children.push(e)}if(i.length){const t={isgap:!0,samples:i,children:[]};r.push(t),o.children&&o.children.push(t)}}return r}e.g=t=>{!function(t){if(!t.sample2term)throw".sample2term missing";if(!t.terms)throw".terms[] missing";if(!t.config)throw".config{} missing"}(t);const e=function(t){const e=new Map;for(const n of t.sample2term.values())for(const t of n.keys())e.set(t,1+(e.get(t)||0));if(t.config.termidorder){const n=[];for(const r of t.config.termidorder){const t=e.get(r);null!=t&&n.push({id:r,samplecount:t})}return n}return[...e].sort(((t,e)=>e[1]-t[1])).map((t=>({id:t[0],samplecount:t[1]})))}(t),r=function(t,e){const n=[];for(const[r,o]of t.sample2term)e.find((t=>o.has(t.id)))&&n.push(r);return n}(t,e);return function(t,e,r){for(const[o,i]of e.entries()){const s=0==o?[{samples:r}]:e[o-1].blocks;i.blocks=n(s,i.id,t)}}(t,e,r),function(t,e){for(const n of t){const t=e.terms.find((t=>t.id==n.id));n.name=t.name;for(const e of n.blocks)e.samplecount=e.samples.length,delete e.samples,e.value&&(e.color=t.values[e.value].color)}}(e,t),function(t){for(let e=t.length-1;e>=0;e--){const n=t[e];for(const t of n.blocks){let e=0;for(const n of t.children)e+=n.symbolwidth;const n=t.isgap?1:t.samplecount.toString().length;t.symbolwidth=Math.max(n,e)}}let e=0;for(const n of t[0].blocks){n.x=e;let t=e;for(const e of n.children)e.x=t,t+=e.symbolwidth;e+=n.symbolwidth}for(let e=1;e<t.length;e++)for(const n of t[e].blocks){let t=n.x;for(const e of n.children)e.x=t,t+=e.symbolwidth}for(const e of t)delete e.children}(e),e}},334:(t,e,n)=>{var r;const o=n(7147),i=n(1017),s=process.cwd()?process.cwd()+"/serverconfig.json":"",a=i.join(__dirname,"../serverconfig.json"),l=i.join(__dirname,"../../serverconfig.json"),c=s&&o.existsSync(s)?s:o.existsSync(a)?a:o.existsSync(l)?l:"";let u;if(!c)throw"missing serverconfig.json";try{const t=o.readFileSync(c,{encoding:"utf8"});u=JSON.parse(t)}catch(t){throw`Error reading or parsing ${c}:`+t}if(u.port||(u.port=process.env.PP_PORT||3e3),u.tabix||(u.tabix="tabix"),u.samtools||(u.samtools="samtools"),u.bcftools||(u.bcftools="bcftools"),u.hicstraw||(u.hicstraw="straw"),u.bigwigsummary||(u.bigwigsummary="bigWigSummary"),u.bigBedToBed||(u.bigBedToBed="bigBedToBed"),u.bigBedInfo||(u.bigBedInfo="bigBedInfo"),u.bigBedNamedItems||(u.bigBedNamedItems="bigBedNamedItems"),u.clustalo||(u.clustalo="clustalo"),u.Rscript||(u.Rscript="Rscript"),!("allow_env_overrides"in u)&&u.debugmode&&(u.allow_env_overrides=!0),!u.binpath){const t=process.argv.find((t=>t.includes("/build")));if(t)u.binpath=t.split("/build")[0]+"/server";else{if(process.argv.find((t=>t.includes(".spec.js"))))u.binpath=i.dirname(__dirname);else{const t=process.argv.find((t=>t.endsWith("/bin.js")||t.endsWith("/server.js")||t.endsWith("/proteinpaint")||t.endsWith("/proteinpaint-server")));if(t)try{const e=o.realpathSync(t);u.binpath=i.dirname(e)}catch(t){throw t}else if(o.existsSync("./server"))u.binpath=o.realpathSync("./server");else if(o.existsSync("./src"))u.binpath=o.realpathSync("./src/..");else if(__dirname.includes("/server/"))u.binpath=__dirname.split("/server/")[0]+"/server";else{if(!__dirname.includes("/proteinpaint"))throw"unable to determine the serverconfig.binpath";u.binpath=__dirname}}}}if(u.debugmode){const t=[],e=i.join(u.binpath,"src/test/routes"),n=["gdc.js","specs.js","readme.js"];if(u.routeSetters)for(const r of u.routeSetters)if(!n.includes(r))if(o.existsSync(r))t.push(r);else if(o.existsSync(`${e}/${r}`))t.push(`${e}/${r}`);else{const e=i.join(u.binpath,r);o.existsSync(e)&&t.push(e)}for(const r of n){const n=`${e}/${r}`;!t.includes(n)&&o.existsSync(n)&&t.push(n)}u.routeSetters=t}if(u.allow_env_overrides){if(process.env.PP_URL&&(u.URL=process.env.URL),"PP_BASEPATH"in process.env&&(u.basepath=process.env.PP_BASEPATH),o.existsSync("./.ssl")&&!u.ssl){u.ssl={};const t=o.readdirSync("./.ssl");for(const e of t)e.endsWith(".key")&&(u.ssl.key=process.cwd()+"/.ssl/"+e),e.endsWith(".crt")&&(u.ssl.cert=process.cwd()+"/.ssl/"+e)}"PP_BACKEND_ONLY"in process.env&&(u.backend_only=1==+process.env.PP_BACKEND_ONLY||"true"===process.env.PP_BACKEND_ONLY)}if(null!==(r=process.env.PP_MODE)&&void 0!==r&&r.startsWith("container")&&Object.assign(u,{port:3e3,tpmasterdir:"/home/root/pp/tp",cachedir:"/home/root/pp/cache",hicstraw:"/home/root/pp/tools/straw",bigwigsummary:"/home/root/pp/tools/bigWigSummary",bigBedToBed:"/home/root/pp/tools/bigBedToBed",bigBedNamedItems:"/home/root/pp/tools/bigBedNamedItems",bigBedInfo:"/home/root/pp/tools/bigBedInfo"}),u.features||(u.features={}),!u.backend_only&&o.existsSync(i.join(process.cwd(),"./public"))){const t=i.join(u.binpath,"cards");u.cards||(u.cards={target:t,path:"cards"});const e=u.cards,n=i.join(process.cwd(),"./public/",e.path);let r;try{r=o.lstatSync(n)}catch(t){r=!1}!e.path||o.existsSync(n)||r||(e.target||(e.target=t),o.symlink(u.cards.target,n,"dir",console.error))}if(o.existsSync("./public/rev.txt")){const t=o.readFileSync("./public/rev.txt",{encoding:"utf8"}).trim().split(" ")[1];t&&(u.commitHash=t)}if(o.existsSync("./package.json")){const t=o.readFileSync("./package.json",{encoding:"utf8"});u.version=JSON.parse(t).version}t.exports=u},7395:(t,e,n)=>{const r=n(9699),o=n(7147),i=n(4521),s=n(2282),a=n(7346),l=n(6778),c=n(3856),{schemeCategory10:u}=n(895),{schemeCategory20:f}=n(4052);function d(t){const e=t.toString(16);return 1==e.length?"0"+e:e}function h(t,e,n){return d(t)+d(e)+d(n)}function p(t){if(!t.cellfile)throw"cellfile missing";{const[e,n,o]=r.fileurl({query:{file:t.cellfile}});if(e)throw"cellfile error: "+e;t.cellfile=n}if(!t.delimiter)throw"delimiter missing";if(!Number.isInteger(t.barcodecolumnidx))throw"barcodecolumnidx missing";if(!Number.isInteger(t.categorycolumnidx))throw"categorycolumnidx missing";return new Promise(((e,n)=>{const r=new Map,s=i.createInterface({input:o.createReadStream(t.cellfile)});let a=!0;s.on("line",(e=>{if(a)return void(a=!1);const n=e.split(t.delimiter);r.set(n[t.barcodecolumnidx],{category:n[t.categorycolumnidx],expvalue:0})})),s.on("close",(()=>{e(r)}))}))}e.handle_singlecell_closure=t=>async(e,n)=>{try{const d=e.query,m=t[d.genome];if(!m)throw"invalid genome";if(d.getpcd)return void await async function(t,e){const n={},d=await async function(t,e){if(!t.textfile)throw".textfile missing";{const[e,n,o]=r.fileurl({query:{file:t.textfile}});if(e)throw".textfile error: "+e;if(!o){if(await c.file_not_exist(n))throw"file not exist: "+t.textfile;if(await c.file_not_readable(n))throw"file not readable: "+t.textfile}t.textfile=n}let n,d,p,m,g;if(t.getpcd.category_autocolor){const e=t.getpcd.values_count&&t.getpcd.values_count<=10?u:f;n=s.scaleOrdinal(e),p={},m={}}else if(t.getpcd.category_customcolor){const e=s.scaleOrdinal(f);y=t.getpcd.cat_values,v=e,n=t=>{let e=!1;for(const n of y)if(n.value==t)return e=!0,n.color;if(!e)return v(t)},p={},m={},g={}}else if(t.getpcd.gene_expression){const n=t.getpcd.gene_expression;if(!n.file)throw"gene_expression.file missing";{const[t,e,o]=r.fileurl({query:{file:n.file}});if(t)throw t;n.file=e}if(!Number.isInteger(n.barcodecolumnidx))throw"gene_expression.barcodecolumnidx missing";if(!n.chr)throw"gene_expression.chr missing";if(!n.start)throw"gene_expression.start missing";if(!n.stop)throw"gene_expression.stop missing";if(!n.genename)throw"gene_expression.genename missing";if(!n.autoscale)throw"gene_expression: unknown scaling method";if(!n.color_min)throw"gene_expression.color_min missing at autoscale";if(!n.color_max)throw"gene_expression.color_max missing at autoscale";const o=(n.nochr?n.chr.replace("chr",""):n.chr)+":"+n.start+"-"+n.stop,i=new Map;d=new Map;let s=0,u=0;if(e.numbercellwithgeneexp=0,e.numbercelltotal=0,await c.get_lines_bigfile({args:[n.file,o],callback:t=>{const r=JSON.parse(t.split("\t")[3]);r.gene==n.genename&&Number.isFinite(r.value)&&(e.numbercellwithgeneexp++,n.autoscale&&(s=Math.min(s,r.value),u=Math.max(u,r.value)),i.set(r.sample,r.value))}}),n.autoscale){e.minexpvalue=s,e.maxexpvalue=u;const t=l.interpolateRgb(n.color_min,n.color_max);for(const[e,n]of i){const r=a.color(t((n-s)/(u-s)));d.set(e,Number.parseInt(h(r.r,r.g,r.b),16))}}}var y,v;return new Promise(((r,s)=>{const l=[],c=i.createInterface({input:o.createReadStream(t.textfile)});let u=!0,f=0,g=0;c.on("line",(r=>{if(u)return void(u=!1);const o=r.split(t.delimiter),i=[];for(const e of t.getpcd.coord)i.push(o[e]),f=Math.max(f,o[e]),g=Math.min(g,o[e]);if(2==t.getpcd.coord.length&&i.push("0"),n){const e=o[t.getpcd.category_index],r=n(e);if(t.hidden_types.includes(e))if(t.background_color){const e=a.color(t.background_color),n=Number.parseInt(h(e.r,e.g,e.b),16);i.push(n)}else i.push(16777215);else i.push(Number.parseInt(r.slice(1),16));p&&(p[e]=r),m&&(m[e]=e in m?m[e]+1:1)}else if(d){e.numbercelltotal++;const n=o[t.getpcd.gene_expression.barcodecolumnidx];let r=d.get(n);if(void 0===r)if(t.getpcd.gene_expression.color_no_exp){const e=a.color(t.getpcd.gene_expression.color_no_exp);r=Number.parseInt(h(e.r,e.g,e.b),16)}else r="2894892";i.push(r)}l.push(i.join(" "))})),c.on("close",(()=>{p&&(t.getpcd.category_customorder&&(p=function(t,e){let n={};const r=Object.keys(t).length;for(var o=1;o<=r;o++){const r=e.find((t=>{if(t.order==o)return t.value}));r&&(n[r.value]=t[r.value])}for(const r of e)r.order||(n[r.value]=t[r.value]);for(const r in t){e.find((t=>{if(t.value==JSON.stringify(r))return!0}))||(n[r]=t[r])}return n}(p,t.getpcd.cat_values)),e.category2color=p,e.categorycount=m),e.data_sphere_r=Math.max(Math.abs(f),Math.abs(g)),r(l)}))}))}(t,n),p="# .PCD v.7 - Point Cloud Data file format\nVERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F F\nCOUNT 1 1 1 1\nWIDTH 1200\nHEIGHT 800\nVIEWPOINT 0 0 0 1 0 0 0\nPOINTS 960000\nDATA ascii\n";n.pcddata=p+d.join("\n"),e.send(n)}(d,n);if(d.getgeneboxplot)return void await async function(t,e,n){const o=t.getgeneboxplot,i=t.getgeneboxplot.values_count&&t.getgeneboxplot.values_count<=10?s.scaleOrdinal(u):s.scaleOrdinal(f);if(!o.expfile)throw"getgeneboxplot.expfile missing";{const[t,e,n]=r.fileurl({query:{file:o.expfile}});if(t)throw"getgeneboxplot.expfile error: "+t;o.expfile=e}if(!o.chr)throw"getgeneboxplot.chr missing";if(!o.start)throw"getgeneboxplot.start missing";if(!o.stop)throw"getgeneboxplot.stop missing";if(!o.genename)throw"getgeneboxplot.genename missing";const a=await p(o),l=(o.nochr?o.chr.replace("chr",""):o.chr)+":"+o.start+"-"+o.stop;let d=0,h=0;await c.get_lines_bigfile({args:[o.expfile,l],callback:t=>{const e=JSON.parse(t.split("\t")[3]);if(e.gene!=o.genename)return;if(!e.sample)return;if(!Number.isFinite(e.value))return;const n=a.get(e.sample);n&&(n.expvalue=e.value,d=Math.min(d,e.value),h=Math.max(h,e.value))}});const m=new Map;for(const[t,e]of a)m.has(e.category)||m.set(e.category,[]),o.exclude_cells&&0==parseInt(e.expvalue)||m.get(e.category).push({value:e.expvalue});const g=[],y=(v=s.scaleLinear().domain([d,h]).ticks(20),t=>{const e=[];for(let t=1;t<v.length;t++)e.push(0);for(const n of t)for(let t=1;t<v.length;t++)if(n.value<=v[t]){e[t-1]++;break}return e});var v;for(const[t,e]of m){e.sort(((t,e)=>t.value-e.value));const n=r.boxplot_getvalue(e);delete n.out;const o=i(t);n.category=t,n.color=o,n.numberofcells=e.length,n.density=y(e),g.push(n)}let b=[];if(t.getgeneboxplot.cat_values){const e=Object.keys(t.getgeneboxplot.cat_values).length;for(var _=1;_<=e;_++){const e=t.getgeneboxplot.cat_values.find((t=>{if(t.order==_)return t.value}));e&&b.push(g.filter((t=>t.category==e.value))[0])}for(const e of t.getgeneboxplot.cat_values)e.order||b.push(g.filter((t=>t.category==e.value))[0]);for(const e of g){t.getgeneboxplot.cat_values.find((t=>{if(t.value==e.category)return!0}))||b.push(e)}for(const e of b){const n=t.getgeneboxplot.cat_values.find((t=>{if(t.value==e.category)return t}));n&&n.color&&(e.color=n.color)}}else b=g;n.send({boxplots:b,minexpvalue:d,maxexpvalue:h})}(d,0,n);if(d.getheatmap)return void await async function(t,e,n){const o=t.getheatmap,i=[];if(!o.expfile)throw"getgeneboxplot.expfile missing";{const[t,e,n]=r.fileurl({query:{file:o.expfile}});if(t)throw"getgeneboxplot.expfile error: "+t;o.expfile=e}o.gene_list.forEach((t=>{if(!t.chr)throw"getgeneboxplot.chr missing";if(!t.start)throw"getgeneboxplot.start missing";if(!t.stop)throw"getgeneboxplot.stop missing";if(!t.gene)throw"getgeneboxplot.genename missing"}));const s=await p(o);for(const t of o.gene_list){const e=(t.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop;let n=0,r=0;const a=t.gene;await c.get_lines_bigfile({args:[o.expfile,e],callback:e=>{const o=JSON.parse(e.split("\t")[3]);if(o.gene.toUpperCase()!==t.gene.toUpperCase())return;if(!o.sample)return;if(!Number.isFinite(o.value))return;const i=s.get(o.sample);i&&(i.expvalue=o.value,n=Math.min(n,o.value),r=Math.max(r,o.value))}});const l=new Map;for(const[t,e]of s)l.has(e.category)||l.set(e.category,[]),l.get(e.category).push({value:e.expvalue});const u=[];for(const[t,e]of l){let n=0;for(const t of e)n+=t.value;const r=e.length,o=(n/r).toFixed(3);u.push({category:t,mean:o,numberofcells:r})}i.push({genename:a,heatmap:u})}n.send({gene_heatmap:i})}(d,0,n)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},1711:(t,e,n)=>{"use strict";n.r(e),n.d(e,{barchart_data:()=>f,getOrderedLabels:()=>h,handle_request_closure:()=>u});const r=n(9699),o=(n(1017),n(3856)),i=n(5346),s=(n(8288).format(".3r"),n(1271).run_rust),{getData:a}=n(2974),{mclass:l,dt2label:c}=n(2273);function u(t){return async(e,n)=>{const r=e.query;for(const t of[0,1,2]){const e="term"+t,n=e+"_id";"string"==typeof r[n]?r[n]=decodeURIComponent(r[n]):"string"==typeof r[e]&&(r[e]=JSON.parse(decodeURIComponent(r[e])));const o=e+"_q";"string"==typeof r[o]&&(r[o]=JSON.parse(decodeURIComponent(r[o])))}try{const e=t[r.genome];if(!e)throw"invalid genome";const o=e.datasets[r.dslabel];if(!o)throw"invalid dslabel";if(!o.cohort)throw"ds.cohort missing";const i=o.cohort.termdb;if(!i)throw"no termdb for this dataset";const a=await f(r,o,i);r.term2_q&&await async function(t,e){t.tests={};for(const n of t.charts){const r={};for(const t of n.serieses)for(const e of t.data)r[e.dataId]=void 0===r[e.dataId]?e.total:r[e.dataId]+e.total;const o=[];let i=0;const a=new Map;for(const t of n.serieses)for(const e of t.data){const s=e.total,l=r[e.dataId]-e.total,c=t.total-e.total,u=n.total-r[e.dataId]-(t.total-e.total),f=t.seriesId,d=e.dataId;o.push({index:i,n1:s,n2:l,n3:c,n4:u}),a.set(i,{seriesId:f,dataId:d}),i++}const l={input:o},c=e.cohort.termdb.multipleTestingCorrection;c&&(l.mtc=c.method,c.skipLowSampleSize&&(l.skipLowSampleSize=c.skipLowSampleSize));const u=await s("fisher",JSON.stringify(l)),f=[];for(const t of JSON.parse(u)){const e=a.get(t.index).seriesId,n=a.get(t.index).dataId,r=t.n1,o=t.n2,i=t.n3,s=t.n4,l=t.p_value,c="chisq"===t.fisher_chisq,u=null===l,d=t.adjusted_p_value,h=f.find((t=>t.term1comparison===e));h?h.term2tests.push({term2id:n,pvalue:l,adjusted_p_value:d,tableValues:{R1C1:r,R2C1:o,R1C2:i,R2C2:s},isChi:c,skipped:u}):f.push({term1comparison:e,term2tests:[{term2id:n,pvalue:l,adjusted_p_value:d,tableValues:{R1C1:r,R2C1:o,R1C2:i,R2C2:s},isChi:c,skipped:u}]})}t.tests[n.chartId]=f}}(a.data,o),n.send(a)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}async function f(t,e,n){if(t.ds=e,t.ssid){const[e,n]=await o.loadfile_ssid(t.ssid);t.sample2gt=e,t.genotype2sample=n}const s=+new Date;t.results={};const u=new Map;for(let e=0;e<=2;e++){let n=null;if(t[`term${e}_id`]){const r=t[`term${e}_id`];n={id:r,q:t[`term${e}_q`],term:{id:r}}}else t[`term${e}`]&&(n={term:t[`term${e}`],q:t[`term${e}_q`]});n&&u.set(e,n)}const f=[...u.values()],p=await a({filter:t.filter,terms:f},t.ds,t.genome),m=new Map,g=[];var y,v,b,_;if(p.samples)if("geneVariant"==(null===(y=u.get(1))||void 0===y||null===(v=y.term)||void 0===v?void 0:v.type)||"geneVariant"==(null===(b=u.get(2))||void 0===b||null===(_=b.term)||void 0===_?void 0:_.type))!function(t,e,n,r,o){var i,s,a,u;e.push([]);let f=1;const d=t.get(1)?t.get(1).term:null,h=null!=d&&d.id?d.id:null==d?void 0:d.name;h&&null!==(i=n.refs.byTermId[h])&&void 0!==i&&i.bins?e.push(null===(s=n.refs.byTermId[h])||void 0===s?void 0:s.bins):e.push([]);const p=t.get(2)?t.get(2).term:null,m=null!=p&&p.id?p.id:null==p?void 0:p.name;m&&null!==(a=n.refs.byTermId[m])&&void 0!==a&&a.bins?e.push(null===(u=n.refs.byTermId[m])||void 0===u?void 0:u.bins):e.push([]);for(const[e,i]of Object.entries(n.samples)){var g,y,v,b;const n=parseInt(e);if("geneVariant"==(null===(g=t.get(1))||void 0===g||null===(y=g.term)||void 0===y?void 0:y.type)){const t=[],e=i[h];for(const r of e.values)if(t.some((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))){const e=t.filter((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))[0];if("object"!=typeof e.item.key1){const t=e.item.key1;e.item.key1={},e.item.key1[t]=1}e.item.key1[l[r.class].label]=e.item.key1[l[r.class].label]?e.item.key1[l[r.class].label]+1:1}else{var _,w,x;const e={sample:f,name:o.sampleId2Name.get(n)};e.key1=l[r.class].label,e.val1=l[r.class].label;const s=null===(_=o.assayAvailability)||void 0===_||null===(w=_.byDt)||void 0===w||null===(x=w[r.dt])||void 0===x?void 0:x.byOrigin;var k;if(s)e.key0=e.val0=((null===(k=s[r.origin])||void 0===k?void 0:k.label)||r.origin)+" "+c[r.dt];else e.key0=e.val0=c[r.dt];e.key2=i[m]?i[m].key:"",e.val2=i[m]?i[m].value:"",t.push({value:r,item:e})}for(const e of t){if("object"==typeof e.item.key1){let t="";for(const[n,r]of Object.entries(e.item.key1))t+=`${n}(${r})+`;e.item.key1=t.slice(0,-1),e.item.val1=t.slice(0,-1)}r.set(f.toString(),e.item),f++}}else if("geneVariant"==(null===(v=t.get(2))||void 0===v||null===(b=v.term)||void 0===b?void 0:b.type)){const t=[],e=i[m],s=i[h];for(const r of e.values)if(t.some((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))){const e=t.filter((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))[0];if("object"!=typeof e.item.key2){const t=e.item.key2;e.item.key2={},e.item.key2[t]=1}e.item.key2[l[r.class].label]=e.item.key2[l[r.class].label]?e.item.key2[l[r.class].label]+1:1}else{var q,N,S;const e={sample:f,name:o.sampleId2Name.get(n)};e.key1=s.key,e.val1=s.value;const i=null===(q=o.assayAvailability)||void 0===q||null===(N=q.byDt)||void 0===N||null===(S=N[r.dt])||void 0===S?void 0:S.byOrigin;var A;if(i)e.key0=e.val0=((null===(A=i[r.origin])||void 0===A?void 0:A.label)||r.origin)+" "+c[r.dt];else e.key0=e.val0=c[r.dt];e.key2=l[r.class].label,e.val2=l[r.class].label,t.push({value:r,item:e})}for(const e of t){if("object"==typeof e.item.key2){let t="";for(const[n,r]of Object.entries(e.item.key2))t+=`${n}(${r})+`;e.item.key2=t.slice(0,-1),e.item.val2=t.slice(0,-1)}r.set(f.toString(),e.item),f++}}}}(u,g,p,m,e);else for(let t=0;t<=2;t++){var w,x,k;const n=null===(w=u.get(t))||void 0===w?void 0:w.q,r=u.get(t)?u.get(t).term:null,o=null!=r&&r.id?r.id:null==r?void 0:r.name;if(o&&null!==(x=p.refs.byTermId[o])&&void 0!==x&&x.bins?g.push(null===(k=p.refs.byTermId[o])||void 0===k?void 0:k.bins):g.push([]),null!=n&&n.binColored)for(const e of g[t]){const t=n.binColored;e.start==t.start&&e.stop==t.stop&&(e.color=t.color)}for(const[n,r]of Object.entries(p.samples)){let i;if(m.get(n))i=m.get(n);else if(!m.has(n)){const t=parseInt(n);i={sample:t,name:e.sampleId2Name.get(t)},m.set(n,i)}if(i)if(o){const e=r[o];e?(i[`key${t}`]=e.key,i[`val${t}`]=e.value):m.set(n,null)}else i[`key${t}`]="",i[`val${t}`]=""}}t.results.lst=[...m.values()].filter((t=>null!==t)),t.results.bins=g;const q=+new Date,N=function(t,e,n,s){const a=[0,1,2].map((e=>{const r=function(t,e,n){const r=t["term"+n+"_id"];let o={};t[r]||r?o=e.q.termjsonByOneid(r):t[`term${n}`]&&(o=t[`term${n}`]);const i="integer"==o.type||"float"==o.type,s=o.values?Object.keys(o.values).filter((t=>o.values[t].uncomputable)).map((t=>+t)):[],a=t=>i&&!s.includes(t),l=t["term"+n+"_q"]?t["term"+n+"_q"]:{};return{term:o,isComputableVal:a,q:l}}(t,n,e);r.q.index=e;const o=t.results.bins[e];return Object.assign(r,{key:"key"+e,val:"val"+e,nval:"nval"+e,bins:o,q:r.q,orderedLabels:h(r.term,o,r.q)})}));return new i({data:e,seed:'{"results": {"charts": [], "refs":{}}}',template:d,"=":{prep(t){for(const e of a)"condition"==e.term.type?(t[e.key]=e.q.bar_by_grade&&t[e.key]in e.term.values?e.term.values[t[e.key]].label:t[e.key],t[e.val]=t[e.key]):"float"!=e.term.type&&"integer"!=e.term.type||e.isComputableVal(t[e.val])&&(t[e.nval]=t[e.val]);return!0},sampleCount:(t,e)=>e.self.samples?e.self.samples.size:void 0,maxSeriesTotal(t,e){let n=0;for(const t of e.self.serieses)t&&t.total>n&&(n=t.total);return n},maxAcrossCharts(t,e){let n=0;for(const t of e.self.charts)t.maxSeriesTotal>n&&(n=t.maxSeriesTotal);return n},boxplot(t,e){const n=e.self.values;if(!n||!n.length)return;n.sort(((t,e)=>t-e));const o=r.boxplot_getvalue(n.map((t=>({value:+t}))));o.mean=e.self.sum/n.length;let i=0;for(const t of n)i+=Math.pow(t-o.mean,2);return o.sd=Math.sqrt(i/(n.length-1)),o.min=e.self.min,o.max=e.self.max,o},getAF(e,n){if(s.track&&s.track.vcf&&s.track.vcf.termdb_bygenotype&&s.track.vcf.termdb_bygenotype.getAF&&t.term2_is_genotype){if(!t.chr)throw"chr missing for getting AF";if(!t.pos)throw"pos missing for getting AF";return function(t,e,n,r,i){const s=i.track.vcf.termdb_bygenotype,a=r.has(o.genotype_types.href)?r.get(o.genotype_types.href):new Set,l=r.has(o.genotype_types.halt)?r.get(o.genotype_types.halt):new Set,c=r.has(o.genotype_types.het)?r.get(o.genotype_types.het):new Set;let u=0,f=0;for(const r of t){let t=!1;if(s.sex_chrs.has(e))if(s.male_samples.has(r)){if(s.chr2par&&s.chr2par[e])for(const r of s.chr2par[e])if(n>=r.start&&n<=r.stop){t=!0;break}}else t=!0;else t=!0;t?(f+=2,l.has(r)?u+=2:c.has(r)&&u++):(f++,a.has(r)||u++)}return 0==f||0==u?0:(u/f).toFixed(3)}(n.self.samples?[...n.self.samples]:[],t.chr,Number(t.pos),t.genotype2sample,s)}},filterEmptySeries(t){const e=t.serieses.filter((t=>t.total));t.serieses.splice(0,t.serieses.length,...e)},bins:()=>a.map((t=>t.bins)),q:()=>a.map(((t,e)=>{const n={};for(const e in t.q)"index"!=e&&(n[e]=t.q[e]);return n})),useColOrder:()=>a[1].orderedLabels.length>0,useRowOrder:()=>a[2].orderedLabels.length>0,sortColsRows(t){if(a[1].orderedLabels.length){const e=a[1].orderedLabels;t.cols.sort(((t,n)=>e.indexOf(t)-e.indexOf(n)))}if(a[2].orderedLabels.length){const e=a[2].orderedLabels;t.rows.sort(((t,n)=>e.indexOf(t)-e.indexOf(n)))}},sortCharts(t){if(a[0].orderedLabels.length){const e=a[0].orderedLabels;t.charts.sort(((t,n)=>e.indexOf(t.chartId)-e.indexOf(n.chartId)))}}}})}(t,t.results.lst,n,e);return N.tree.results&&(N.tree.results.times={sql:q-s,pj:N.times}),{data:N.tree.results,samples:t.results.lst,bins:g}}const d=JSON.stringify({"@errmode":["","","",""],"@before()":"=prep()",results:{"_2:maxAcrossCharts":"=maxAcrossCharts()","_:_min":">$nval1","_:_max":"<$nval1",charts:[{chartId:"@key","~samples":["$sample","set"],"__:total":"=sampleCount()","_1:maxSeriesTotal":"=maxSeriesTotal()","@done()":"=filterEmptySeries()",serieses:[{seriesId:"@key",data:[{dataId:"@key","~samples":["$sample","set"],"__:total":"=sampleCount()"},"$key2"],"_:_max":"<$nval2","~values":["$nval2",0],"~sum":"+$nval2","~samples":["$sample","set"],"__:total":"=sampleCount()","__:boxplot":"=boxplot()","__:AF":"=getAF()"},"$key1"]},"$key0"],"~sum":"+$nval1","~values":["$nval1",0],"__:boxplot":"=boxplot()","_:_refs":{cols:["$key1"],colgrps:["-"],rows:["$key2"],rowgrps:["-"],col2name:{$key1:{name:"@branch",grp:"-"}},row2name:{$key2:{name:"@branch",grp:"-"}},"__:useColOrder":"=useColOrder()","__:useRowOrder":"=useRowOrder()","__:bins":"=bins()","__:q":"=q()","@done()":"=sortColsRows()"},"@done()":"=sortCharts()"}});function h(t,e,n){if("condition"==t.type){var r;if(null!=n&&null!==(r=n.groups)&&void 0!==r&&r.length)return n.groups.map((t=>t.name));if(t.values)return Object.keys(t.values).map(Number).sort(((t,e)=>t-e)).map((e=>t.values[e].label))}const o=Object.values(t.values||{})[0];return o&&"order"in o?Object.keys(t.values).sort(((e,n)=>"order"in t.values[e]&&"order"in t.values[n]?t.values[e].order-t.values[n].order:"order"in t.values[e]?t.values[e].order:"order"in t.values[n]?t.values[n].order:0)).map((e=>t.values[e].key)):e.map((t=>t.name?t.name:t.label))}},601:(t,e,n)=>{"use strict";n.d(e,{v:()=>o});const{getCohortsData:r}=n(6759);async function o(t,e,n){const o=r(n);e.send(o)}},5174:(t,e,n)=>{"use strict";n.r(e),n.d(e,{make:()=>i});const r=n(334),{mayComputeTermtypeByCohort:o}=n(394);function i(t,e,n,o){const i=n.cohort.termdb,a={selectCohort:i.selectCohort,supportedChartTypes:i.q.getSupportedChartTypes(t.embedder),allowedTermTypes:s(n),termMatch2geneSet:i.termMatch2geneSet,massSessionDuration:r.features.massSessionDuration||30,dataDownloadCatch:i.dataDownloadCatch,matrix:i.matrix,mclass:i.mclass,alwaysRefillCategoricalTermValues:i.alwaysRefillCategoricalTermValues,isGeneSetTermdb:i.isGeneSetTermdb};i.multipleTestingCorrection&&(a.multipleTestingCorrection=i.multipleTestingCorrection),i.helpPages&&(a.helpPages=i.helpPages),i.timeScale&&(a.timeScale=i.timeScale),i.minTimeSinceDx&&(a.minTimeSinceDx=i.minTimeSinceDx),i.coxTimeMsg&&(a.coxTimeMsg=i.coxTimeMsg),i.coxStartTimeMsg&&(a.coxStartTimeMsg=i.coxStartTimeMsg),i.displaySampleIds&&(a.displaySampleIds=i.displaySampleIds),i.additionalSampleAttributes&&(a.additionalSampleAttributes=i.additionalSampleAttributes),i.logscaleBase2&&(a.logscaleBase2=i.logscaleBase2),n.assayAvailability&&(a.assayAvailability=n.assayAvailability),n.customTwQByType&&(a.customTwQByType=n.customTwQByType),function(t,e){var n;const o=null===(n=r.dsCredentials)||void 0===n?void 0:n[e.dslabel];if(!o)return;t.requiredAuth={type:o.type||"login",headerKey:o.headerKey}}(a,t),function(t,e){if(!e.restrictAncestries)return;t.restrictAncestries=e.restrictAncestries.map((t=>({name:t.name,tvs:t.tvs})))}(a,i),function(t,e){if(!e.cohort.scatterplots)return;t.scatterplots=e.cohort.scatterplots.plots.map((t=>({name:t.name,dimensions:t.dimensions,colorTW:t.colorTW,shapeTW:t.shapeTW})))}(a,n),function(t,e){if(!e.cohort.matrixplots)return;t.matrixplots=e.cohort.matrixplots.plots.map((t=>({name:t.name})))}(a,n),function(t,e,n){const r=e.queries;if(!r)return;t.queries={defaultCoord:r.defaultCoord||n.defaultcoord};const o=t.queries;r.defaultBlock2GeneMode&&(o.defaultBlock2GeneMode=r.defaultBlock2GeneMode);r.snvindel&&(o.snvindel=!0);r.topMutatedGenes&&(o.topMutatedGenes=r.topMutatedGenes);r.topVariablyExpressedGenes&&(o.topVariablyExpressedGenes=r.topVariablyExpressedGenes.arguments);r.singleSampleMutation&&(o.singleSampleMutation={sample_id_key:r.singleSampleMutation.sample_id_key,discoSkipChrM:r.singleSampleMutation.discoSkipChrM});if(r.singleSampleGenomeQuantification){o.singleSampleGenomeQuantification={};for(const t in r.singleSampleGenomeQuantification)o.singleSampleGenomeQuantification[t]=JSON.parse(JSON.stringify(r.singleSampleGenomeQuantification[t])),delete o.singleSampleGenomeQuantification[t].folder}if(r.singleSampleGbtk){o.singleSampleGbtk={};for(const t in r.singleSampleGbtk)o.singleSampleGbtk[t]=JSON.parse(JSON.stringify(r.singleSampleGbtk[t])),delete o.singleSampleGbtk[t].folder}}(a,n,o),e.send({termdbConfig:a})}function s(t){var e;o(t);const n=new Set;for(const e of t.cohort.termdb.termtypeByCohort)e.type&&n.add(e.type);if(t.cohort.termdb.allowedTermTypes)for(const e of t.cohort.termdb.allowedTermTypes)n.add(e);return null!=t&&null!==(e=t.queries)&&void 0!==e&&e.defaultBlock2GeneMode&&n.add("geneVariant"),[...n]}},4453:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_incidence:()=>c,runCumincR:()=>u});const r=n(1017),o=n(2852).get_rows,i=n(3856).write_file,s=n(7147),a=n(9157),l=n(334);async function c(t,e){try{if(!e.cohort)throw"cohort missing from ds";const n=e.cohort.termdb.minTimeSinceDx;if(!n)throw"missing min time since dx";t.ds=e;const r=await o(t),i={};for(const t of r.lst){const e=t.key0,n=t.val1,r=t.key1,o=t.key2;e in i||(i[e]=[]),i[e].push({time:n,event:r,series:o})}const s={keys:["chartId","seriesId","time","cuminc","low","high","nrisk","nevent","ncensor"],case:[],refs:{bins:t.term2_id&&r.CTE2.bins?r.CTE2.bins:[]}},a={data:{},startTime:n};for(const e in i){const n=new Map;for(const t of i[e]){let e=n.get(t.series);e?(e.samplesize++,1==t.event&&e.eventcnt++,n.set(t.series,e)):(e={samplesize:1,eventcnt:1==t.event?1:0},n.set(t.series,e))}const r=new Set,o=new Set;for(const[e,i]of n)i.samplesize<t.minSampleSize&&r.add(e),0===i.eventcnt&&o.add(e);r.size&&(s.lowSampleSize||(s.lowSampleSize={}),s.lowSampleSize[e]=[...r]),o.size&&(s.lowEventCnt||(s.lowEventCnt={}),s.lowEventCnt[e]=[...o]);const l=i[e].filter((t=>!r.has(t.series)&&!o.has(t.series)));l.length?a.data[e]=l:(s.skippedCharts||(s.skippedCharts=[]),s.skippedCharts.push(e))}return await u(a,s),s}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}async function u(t,e){for(let e in t.data)""===e&&(e="*",t.data[e]=t.data[""],delete t.data[""]),t.data[e]=t.data[e].map((t=>({time:t.time,event:t.event,series:""===t.series?"*":t.series})));const n=r.join(l.cachedir,Math.random().toString()+".json");await i(n,JSON.stringify(t));const o=await a(r.join(l.binpath,"utils/cuminc.R"),[],[n]),c=JSON.parse(o[0]);for(const t in c)"*"===t&&(c[""]=c[t],delete c[t]);for(const t in c)for(const e in c[t].estimates)"*"===e&&(c[t].estimates[""]=c[t].estimates[e],delete c[t].estimates[e]);for(const t in c){for(const n in c[t].estimates){const r=c[t].estimates[n];for(let o=0;o<r.length;o++)e.case.push([t,n,r[o].time,r[o].est,r[o].low,r[o].up,r[o].nrisk,r[o].nevent,r[o].ncensor])}c[t].tests&&(e.tests||(e.tests={}),e.tests[t]=c[t].tests)}s.unlink(n,(()=>{}))}},5257:(t,e)=>{function n(t,e){return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id = ?\n\t\t\t\tAND value ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[t.term.id,...t.values.map((t=>t.key))],CTEname:e}}function r(t,e){var n,r;return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM survival\n\t\t\t\tWHERE term_id = ?\n\t\t\t\t${null!==(n=t.q)&&void 0!==n&&n.cutoff?"AND tte >= "+(null===(r=t.q)||void 0===r?void 0:r.cutoff):""}\n\t\t\t\tAND exit_code ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[t.term.id,...t.values.map((t=>t.key))],CTEname:e}}function o(t,e){return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT id as sample\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE id IN (${Array(t.values.length).fill("?").join(", ")})\n\t\t\t)`],values:[...t.values.map((t=>t.sampleId))],CTEname:e}}async function i(t,e,n){const r={term:t.term,q:{}},o=await n.mayGetGeneVariantData(r,{genome:n.genomename}),i=[];for(const[e,n]of o){const r=n[t.term.name].values;let o=!0;for(const e of t.values){const t=r.filter((t=>t.dt==e.dt&&(!e.origin||e.origin==t.origin)));for(const n of t)if(e.mclassExcludeLst.includes(null==n?void 0:n.class)){o=!1;break}}o&&i.push(e)}return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT id as sample\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE id IN (${i.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[...i],CTEname:e}}function s(t,e,n){if(!t.ranges)throw".ranges{} missing";const r=[t.term.id],o=n.cohort.termdb.q.termjsonByOneid(t.term.id),i=[];let s,a=!1;for(const e of t.ranges)if("value"in e){const n=t.isnot?"!":"";i.push(`value ${n}= ?`),r.push(""+e.value)}else{a=!0;const n=[];e.startunbounded||(e.startinclusive?n.push("value >= ?"):n.push("value > ? "),r.push(e.start)),e.stopunbounded||(e.stopinclusive?n.push("value <= ?"):n.push("value < ? "),r.push(e.stop));const o=t.isnot?"NOT ":"";n.length&&i.push(o+"("+n.join(" AND ")+")")}a&&o.values&&(s=Object.keys(o.values).filter((t=>o.values[t].uncomputable)).map(Number).filter((e=>t.isnot||!t.ranges.find((t=>"value"in t&&Number(t.value)==e)))),s.length&&r.push(...s));const l=i.join(" OR ");return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM anno_${o.type}\n\t\t\t\tWHERE term_id = ?\n\t\t\t\t${l?"AND ("+l+")":""}\n\t\t\t\t${s&&s.length?`AND value NOT IN (${s.map((t=>"?")).join(",")})`:""}\n\t\t\t)`],values:r,CTEname:e}}function a(t,e){let n,r;if(t.bar_by_children)n="child";else{if(!t.bar_by_grade)throw"must set the bar_by_grade or bar_by_children query parameter";n="grade"}if(t.value_by_max_grade)r="max_grade";else if(t.value_by_most_recent)r="most_recent";else{if(!t.value_by_computable_grade)throw"unknown setting of value_by_?";r="computable_grade"}const o=[],i=[];if(!t.values)throw t.grade_and_child?"-- Todo: tvs.grade_and_child":'unknown condition term filter type: expecting term-value "values" or "grade_and_child" key';return i.push(t.term.id,...t.values.map((t=>""+t.key))),o.push(`\n\t\t\t${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM ${"grade"==n?"precomputed_chc_grade":"precomputed_chc_child"}\n\t\t\t\tWHERE term_id = ? \n\t\t\t\tAND ${r} = 1\n\t\t\t\tAND value ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`),{CTEs:o,values:i,CTEname:e}}e.getFilterCTEs=async function t(e,l,c="f"){if(!e)return;if("tvslst"!=e.type)throw'filter.type is not "tvslst" but: '+e.type;if(!Array.isArray(e.lst))throw"filter.lst must be an array";if(0==e.lst.length)return console.error("filter.lst[] is zero length, see if is an error");if(1==e.lst.length){if("tvslst"==e.lst[0].type)throw'only one element at a level: type should not be "tvslst"'}else if("or"!=e.join&&"and"!=e.join)throw'multiple elements at a level: filter.join must equal either "or" or "and"';"in"in e||(e.in=!0);const u=[],f=[],d=[];for(const[h,p]of e.lst.entries()){const e=c+"_"+h;let m;if("tvslst"==p.type)m=await t(p,l,e);else if("categorical"==p.tvs.term.type)m=n(p.tvs,e);else if("survival"==p.tvs.term.type)m=r(p.tvs,e);else if("samplelst"==p.tvs.term.type)m=o(p.tvs,e);else if("integer"==p.tvs.term.type||"float"==p.tvs.term.type)m=s(p.tvs,e,l);else if("condition"==p.tvs.term.type)m=a(p.tvs,e);else{if("geneVariant"!=p.tvs.term.type)throw"unknown term type";m=await i(p.tvs,e,l)}u.push(m.CTEname),f.push(...m.CTEs),d.push(...m.values)}const h="and"==e.join?"INTERSECT":"UNION",p=u.map((t=>"SELECT * FROM "+t)).join("\n"+h+"\n");return e.in?f.push(`\n\t\t\t\t${c} AS (\n\t\t\t\t\t${p}\n\t\t\t\t)\n\t\t\t`):f.push(`\n\t\t\t\t${c} AS (\n\t\t\t\t\tSELECT id as sample\n\t\t\t\t\tFROM sampleidmap\n\t\t\t\t\tWHERE sample NOT IN (\n\t\t\t\t\t\t${p}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t`),{filters:f.join(",\n"),CTEs:f,values:d,CTEname:c}}},1778:(t,e,n)=>{"use strict";n.r(e),n.d(e,{initGDCdictionary:()=>d});const r=n(6452),o=n(1017),i=n(1575).isUsableTerm,s=n(334),a=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",l=a+(a.includes("/v0")?"":"/v0")+"/graphql",c=o.join(a,"ssm_occurrences/_mapping"),u={default:{mode:"discrete",type:"regular-bin",bin_size:1,startinclusive:!1,stopinclusive:!0,first_bin:{startunbounded:!0,stop:0},last_bin:{start:1,stopunbounded:!0}}},f={};async function d(t){const e=new Map,n=await r(c,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"}});let d;try{d=JSON.parse(n.body)}catch(t){throw"invalid JSON from GDC dictionary"}if(!d._mapping)throw"returned data does not have ._mapping";if(!Array.isArray(d.fields))throw".fields not array";if(!Array.isArray(d.nested))throw".nested not array";const g=new Set(d.nested);let y=0,v=0,b=0,_=0,w=0,x=0;for(const t of d.fields){if((k=t).startsWith("ssm")||k.startsWith("case.observation")||k.startsWith("case.available_variation_data")){y++;continue}const n=t.split(".");for(let t=1;t<n.length;t++){const r=n.slice(0,t).join("."),o=r+"."+n[t];if(o.endsWith("_id")&&!o.endsWith("project_id"))continue;if(o.endsWith("consent_type")||"case.days_to_consent"==o||"case.days_to_index"==o)continue;const i=n[t][0].toUpperCase()+n[t].slice(1).replace(/_/g," "),s={id:o.toLowerCase(),name:i,included_types_set:new Set,child_types_set:new Set};if(t==n.length-1){s.isleaf=!0;const t=d._mapping["ssm_occurrence_centrics."+o];t&&("keyword"==t.type?(s.type="categorical",b++):"long"==t.type?(s.type="integer",s.bins=f[s.id]||JSON.parse(JSON.stringify(u)),_++):"double"==t.type&&(s.type="float",s.bins=f[s.id]||JSON.parse(JSON.stringify(u)),w++)),s.type||v++,h(s)}if(1==t);else if(s.parent_id=r,s.type){s.included_types_set.add(s.type);let t=e.get(r);for(;t&&(t.included_types_set.add(s.type),t.child_types_set.add(s.type),t.parent_id);)t=e.get(t.parent_id)}g.has(o)&&(s.isObjectList=!0),e.set(o,s)}}var k;for(const t of e.values())t.type||x++,t.included_types=[...t.included_types_set],t.child_types=[...t.child_types_set],delete t.included_types_set,delete t.child_types_set;console.log("GDC dictionary:",e.size,"total variables,",y,"lines skipped,",v,"lines with unknown term type,","categorical="+b,"integer="+_,"float="+w,"parent="+x),Object.freeze(e),function(t,e){const n=t.cohort.termdb.q={};async function r(e,n){if(0==e.length||!n)return;const r=await t.termdb.termid2totalsize2.get(e.map((t=>t.id)),JSON.parse(n));for(const t of e)if(t){const e=r.get(t.id);"categorical"==t.type&&e?e.length?t.samplecount=e.map((t=>t[1])).reduce(((t,e)=>t+e)):(t.disabled=!0,t.samplecount=0):"integer"!=t.type&&"float"!=t.type||(t.samplecount=e.total,0==e.total&&(t.disabled=!0))}}n.getRootTerms=async(t,n=null)=>{const o=[];for(const t of e.values())null==t.parent_id&&o.push(JSON.parse(JSON.stringify(t)));return await r(o,n),o},n.getTermChildren=async(t,n=null,o=null)=>{const i=[];for(const n of e.values())n.parent_id==t&&i.push(JSON.parse(JSON.stringify(n)));return await r(i,o),i},n.findTermByName=async(t,n=null,o,s=null,a=null)=>{(t=t.toLowerCase()).includes(" ")&&(t=t.replace(/\s/g,"_"));const l=[];for(const n of e.values())a&&!i(n,a)||n.id.includes(t)&&l.push(JSON.parse(JSON.stringify(n)));return await r(l,s),l},n.getAncestorIDs=t=>{if(!e.has(t))return;const n=t.split("."),r=[];for(let t=1;t<n.length;t++)r.push(n.slice(0,t+1).join("."));return r},n.getAncestorNames=n.getAncestorIDs,n.termjsonByOneid=t=>{const n=e.get(t);return n?JSON.parse(JSON.stringify(n)):null},n.getSupportedChartTypes=()=>{const t={},n={};for(const r of e.values())r.type&&(r.cohort in t||(t[r.cohort]=["barchart","table","regression"],n[r.cohort]=0),"survival"!=r.type||t[r.cohort].includes("survival")||t[r.cohort].push("survival"),"condition"!=r.type||t[r.cohort].includes("cuminc")||t[r.cohort].push("cuminc"),"float"!=r.type&&"integer"!=r.type||(n[r.cohort]+=r.samplecount));for(const e in n)n[e]>0&&t[e].push("boxplot"),n[e]>1&&t[e].push("scatterplot");return t}}(t,e),t.cohort.termdb.termtypeByCohort=[],b&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"categorical"}),_&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"integer"}),w&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"float"}),await async function(t){var e,n,i;const s={"Content-Type":"application/json",Accept:"application/json"},l={filters:{op:"and",content:[{op:"=",content:{field:"access",value:"open"}},{op:"=",content:{field:"data_type",value:"Masked Somatic Mutation"}}]},facets:"cases.project.project_id",size:0},c=await r(o.join(a,"files"),{method:"POST",headers:s,body:JSON.stringify(l)}),u=JSON.parse(c.body);if(t.gdcOpenProjects=new Set,null!=u&&null!==(e=u.data)&&void 0!==e&&null!==(n=e.aggregations)&&void 0!==n&&null!==(i=n["cases.project.project_id"])&&void 0!==i&&i.buckets){for(const e of u.data.aggregations["cases.project.project_id"].buckets)e.key&&t.gdcOpenProjects.add(e.key);console.log("GDC open-access projects:",t.gdcOpenProjects.size)}else console.log("getting open project_id but return is not re.data.aggregations['cases.project.project_id'].buckets")}(t),async function(){try{await p(a+"/ssms"),await p(a+"/ssm_occurrences"),await p(a+"/cases"),await p(a+"/files"),await p(a+"/analysis/top_mutated_genes_by_project"),await async function(t){const e=new Date;try{const e="query termislst2total( $filters: FiltersArgument) {\n\t\texplore {\n\t\t\tcases {\n\t\t\t\taggregations (filters: $filters, aggregations_filter_themselves: true) {\n\t\t\t\t\tprimary_site {buckets { doc_count, key }}\n\t\t\t\t}\n\t\t\t}\n\t\t}}";await r.post(t,{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:e,variables:{}})})}catch(e){throw"gdc api down: "+t}console.log("GDC GraphQL API okay: "+t,new Date-e,"ms")}(l)}catch(t){console.error(`\n##########################################\n#\n# GDC API unavailable\n# ${a}\n# ${l}\n#\n##########################################`)}}(),async function(t){try{if(t.aliquot2submitter={cache:new Map,get:async e=>t.aliquot2submitter.cache.has(e)?t.aliquot2submitter.cache.get(e):e},s.features.stopGdcCacheAliquot)return console.log("GDC aliquot2submitter not cached!");const e=await m(t,1,0);if(!Number.isInteger(e))throw"gdc totalCases not integer";const n=new Date;console.log("Start to cache aliquot IDs of",e,"cases...");const r=1e3;for(let n=0;n<Math.ceil(e/r);n++)await m(t,r,1e3*n);console.log("Done caching",t.aliquot2submitter.cache.size,"aliquot IDs.",new Date-n,"ms")}catch(t){console.log("Error at caching: "+t)}}(t)}function h(t){"case.diagnoses.age_at_diagnosis"!=t.id||(t.printDays2years=!0)}async function p(t){try{const e=new Date;await r(t),console.log("GDC API okay: "+t,new Date-e,"ms")}catch(e){throw"gdc api down: "+t}}async function m(t,e,n,o){var i,s,l;const c=["fields=samples.portions.analytes.aliquots.aliquot_id,samples.submitter_id"];if(o)c.push('filters={"op":"and","content":[{"op":"=","content":{"field":"samples.portions.analytes.aliquots.aliquot_id","value":["'+o+'"]}}]}');else{if(!Number.isInteger(e)||!Number.isInteger(n))throw"size and from not integers";c.push("size="+e),c.push("from="+n)}const u=await r(a+"/cases?"+c.join("&")),f=JSON.parse(u.body);if(!Array.isArray(null==f||null===(i=f.data)||void 0===i?void 0:i.hits))throw"re.data.hits[] not array";for(const e of f.data.hits)if(Array.isArray(e.samples))for(const n of e.samples){const e=n.submitter_id;if(Array.isArray(n.portions))for(const r of n.portions)if(Array.isArray(r.analytes))for(const n of r.analytes)if(Array.isArray(n.aliquots))for(const r of n.aliquots){const n=r.aliquot_id;if(!n)throw"aliquot.aliquot_id missing";t.aliquot2submitter.cache.set(n,e)}}return null===(s=f.data)||void 0===s||null===(l=s.pagination)||void 0===l?void 0:l.total}},7860:(t,e,n)=>{"use strict";n.r(e),n.d(e,{copy_term:()=>N,handle_request_closure:()=>q});var r=n(5684),o=n(7027),i=n(3856),s=n(6191),a=n.n(s),l=n(4065);const c=n(5174),u=n(2852),f=n(5708),d=n(4453),h=n(1468),p=n(8599),m=n(3795),g=n(1711).getOrderedLabels,y=n(1575).isUsableTerm,v=n(2188).uR,b=n(2188).v8,_=n(4603).g,w=n(2974).getData,x=n(601).v,k=n(4143).R;function q(t){return async(e,n)=>{const s=e.query;try{const q=t[s.genome];if(!q)throw"invalid genome";const[A,M]=function(t,e){{const r=t.datasets[e.dslabel];if(r){var n;if(null!=r&&null!==(n=r.cohort)&&void 0!==n&&n.termdb)return[r,r.cohort.termdb];throw".cohort.termdb not found on this dataset"}}if(!t.termdbs)throw"genome-level termdb not available";const r=t.termdbs[e.dslabel];if(!r)throw"invalid dslabel";if(!r.cohort)throw"ds.cohort missing for genome-level termdb";if(!r.cohort.termdb)throw"ds.cohort.termdb{} missing for a genome-level termdb";return[r,r.cohort.termdb]}(q,s);if(s.gettermbyid)return function(t,e,n){const r=n.q.termjsonByOneid(t.gettermbyid);e.send({term:r?N(r):void 0})}(s,n,M);if(s.getcategories)return await async function(t,e,n,r,o){var i,s,a;if(!t.tid)throw".tid missing";const l="geneVariant"==t.type?{name:t.tid,type:"geneVariant",isleaf:!0}:n.q.termjsonByOneid(t.tid),c={filter:t.filter,terms:"geneVariant"==t.type?[{term:l,q:{isAtomic:!0}}]:[{id:t.tid,term:l,q:t.term1_q||S(l,t)}],currentGeneNames:t.currentGeneNames},u=await w(c,r,o);if(u.error)throw u.error;const f=[];if("geneVariant"==t.type){var d;const e=u.samples,n=new Map;if(null!==(d=r.assayAvailability)&&void 0!==d&&d.byDt)for(const[t,e]of Object.entries(r.assayAvailability.byDt))e.byOrigin&&n.set(parseInt(t),{byOrigin:{germline:{},somatic:{}}});for(const[r,o]of Object.entries(e)){const e=o[t.tid].values;for(const t of e){n.has(t.dt)||n.set(t.dt,{});const e=n.get(t.dt);e.byOrigin?e.byOrigin[t.origin][t.class]=e.byOrigin[t.origin][t.class]?e.byOrigin[t.origin][t.class]+1:1:e[t.class]=e[t.class]?e[t.class]+1:1}}for(const[t,e]of n)f.push({dt:t,classes:e})}else{const e=new Map;for(const n in u.samples){const r=u.samples[n][t.tid];r&&("key"in r&&e.set(r.key,1+(e.get(r.key)||0)))}for(const[n,r]of e){var h,p,m,y;f.push({samplecount:r,key:"cox"==(null===(h=t.term1_q)||void 0===h?void 0:h.mode)?JSON.parse(n).event:n,label:"cox"==(null===(p=t.term1_q)||void 0===p?void 0:p.mode)?JSON.parse(n).label:(null==l||null===(m=l.values)||void 0===m||null===(y=m[n])||void 0===y?void 0:y.label)||n})}}const v=g(l,(null===(i=u.refs)||void 0===i||null===(s=i.byTermId)||void 0===s||null===(a=s[t.tid])||void 0===a?void 0:a.bins)||[],t.term1_q);v.length&&f.sort(((t,e)=>v.indexOf(t.label)-v.indexOf(e.label)));e.send({lst:f,orderedLabels:v})}(s,n,M,A,q);if(s.getpercentile)return async function(t,e,n){const r=n.cohort.termdb.q.termjsonByOneid(t.tid);if(!r)throw"invalid termid";if("float"!=r.type&&"integer"!=r.type)throw"not numerical term";const i=t.getpercentile,s=[],a=[],l=await u.get_rows_by_one_key({ds:n,key:t.tid,filter:t.filter?"string"==typeof t.filter?JSON.parse(t.filter):t.filter:null});for(const{value:t}of l)r.values&&r.values[t]&&r.values[t].uncomputable||r.skip0forPercentile&&0==t||a.push(Number(t));for(const t of i){const e=(0,o.Z)(a,t);s.push(e)}e.send({values:s})}(s,n,A);if(s.getdescrstats)return async function(t,e,n){const i=n.cohort.termdb.q.termjsonByOneid(t.tid);if(!i)throw"invalid termid";if("float"!=i.type&&"integer"!=i.type)throw"not numerical term";const s=await u.get_rows_by_one_key({ds:n,key:t.tid,filter:t.filter?"string"==typeof t.filter?JSON.parse(t.filter):t.filter:null}),a=[];for(const{value:e}of s){var l,c;i.values&&i.values[e]&&i.values[e].uncomputable||("log"===(null===(l=t.settings)||void 0===l||null===(c=l.violin)||void 0===c?void 0:c.unit)&&0===e||a.push(Number(e)))}const f=a.length,d=a.reduce(((t,e)=>t+e),0)/f,h=(0,o.Z)(a,25),p=(0,o.Z)(a,50),m=(0,o.Z)(a,75),g=a.map((t=>(t-d)**2)).reduce(((t,e)=>t+e),0)/(a.length-1),y=Math.sqrt(g),v=Math.min(...a),b=Math.max(...a);e.send({values:[{id:"total",label:"n",value:f},{id:"min",label:"Minimum",value:(0,r.Z)(v,2)},{id:"p25",label:"1st quartile",value:(0,r.Z)(h,2)},{id:"median",label:"Median",value:(0,r.Z)(p,2)},{id:"mean",label:"Mean",value:(0,r.Z)(d,2)},{id:"p75",label:"3rd quartile",value:(0,r.Z)(m,2)},{id:"max",label:"Maximum",value:(0,r.Z)(b,2)},{id:"sd",label:"Standard deviation",value:(0,r.Z)(y,2)}]})}(s,n,A);if(s.getnumericcategories)return await async function(t,e,n,r){if(!t.tid)throw".tid missing";n.q.termjsonByOneid(t.tid);const o={ds:r,term_id:t.tid};t.filter&&(o.filter=t.filter);const i=await u.get_summary_numericcategories(o);e.send({lst:i})}(s,n,M,A);if(s.default_rootterm)return await async function(t,e,n){const r=t.cohortValues?t.cohortValues:"",o=t.treeFilter?t.treeFilter:"";e.send({lst:await n.q.getRootTerms(r,o)})}(s,n,M);if(s.get_children)return await async function(t,e,n){if(!t.tid)throw"no parent term id";const r=t.cohortValues?t.cohortValues:"",o=t.treeFilter?t.treeFilter:"",i=await n.q.getTermChildren(t.tid,r,o);e.send({lst:i.map(N)})}(s,n,M);if(s.findterm)return await async function(t,e,n,r,o){var i;const s={equals:[],startsWith:[],startsWord:[],includes:[]},a=decodeURIComponent(t.findterm).toUpperCase(),c=y({type:"geneVariant"},t.usecase).has("plot");r.mayGetMatchingGeneNames&&c&&await r.mayGetMatchingGeneNames(s,a,t);const u=[];if(null!==(i=r.queries)&&void 0!==i&&i.defaultBlock2GeneMode&&c){const t=(0,l.getResult)(o,{input:a});if(Array.isArray(t.hits))for(let e=0;e<7&&t.hits[e];e++)u.push({name:t.hits[e],type:"geneVariant"})}"string"!=typeof t.cohortStr&&(t.cohortStr="");const f=await n.q.findTermByName(a,10,t.cohortStr,t.treeFilter,t.usecase,s);u.push(...f.map(N));u.forEach((t=>{"geneVariant"!=t.type&&(t.__ancestors=n.q.getAncestorIDs(t.id),t.__ancestorNames=n.q.getAncestorNames(t.id))})),e.send({lst:u})}(s,n,M,A,q);if(s.getterminfo)return function(t,e,n){if(!t.tid)throw"no term id";e.send({terminfo:n.q.getTermInfo(t.tid)})}(s,n,M);if(s.phewas)return s.update?await f.update_image(s,n):s.getgroup?await f.getgroup(s,n):await f.trigger(s,n,A);if(s.gettermdbconfig)return c.make(s,n,A,q);if(s.getcohortsamplecount)return n.send({count:A.cohort.termdb.q.getcohortsamplecount(s.cohort)});if(s.getsamplecount)return n.send(await async function(t,e,n){const r=a().canDisplaySampleIds(t,n);if("list"==e.getsamplecount){return await u.get_samples(e.filter,n,r)}return await u.get_samplecount(e,n)}(e,s,A));if(s.getsamples)return await async function(t,e,n){const r=(await u.get_samples(t.filter,n)).map((t=>n.cohort.termdb.q.id2sampleName(t)));e.send({samples:r})}(s,n,A);if(s.getcuminc)return await async function(t,e,n){if(!t.minSampleSize)throw"missing minSampleSize";t.minSampleSize=Number(t.minSampleSize);const r=await d.get_incidence(t,n);e.send(r)}(s,n,A);if(s.getsurvival)return await async function(t,e,n){const r=await h.get_survival(t,n);e.send(r)}(s,n,A);if(s.getregression)return await async function(t,e,n){const r=await p.get_regression(t,n);e.send(r)}(s,n,A);if(s.validateSnps)return n.send(await m.validate(s,M,A,q));if(s.getvariantfilter)return function(t,e){var n,r;if(e.track)return void t.send(e.track.variant_filter);t.send((null==e||null===(n=e.queries)||void 0===n||null===(r=n.snvindel)||void 0===r?void 0:r.variant_filter)||{})}(n,A);if(s.getLDdata)return await async function(t,e,n){var r,o;if(!t.ldtkname)throw".ldtkname missing";if(null===(r=e.queries)||void 0===r||null===(o=r.ld)||void 0===o||!o.tracks)throw"no ld tk";const s=e.queries.ld.tracks.find((e=>e.name==t.ldtkname));if(!s)throw"unknown ld tk";if("object"!=typeof t.m)throw"q.m{} not object";if(!t.m.chr)throw"q.m.chr missing";if(!Number.isInteger(t.m.pos))throw"q.m.pos not integer";if(!t.m.ref||!t.m.alt)throw"q.m{} invalid alleles";const a=t.m.ref+"."+t.m.alt,l=(s.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+t.m.pos+"-"+(t.m.pos+1),c=[];await(0,i.get_lines_bigfile)({args:[s.file,l],dir:s.dir,callback:e=>{const n=e.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),i=n[3],s=n[4],l=Number.parseFloat(n[5]);r==t.m.pos&&i==a?c.push({pos:o,alleles:s,r2:l}):o==t.m.pos&&s==a&&c.push({pos:r,alleles:i,r2:l})}}),n.send({lst:c})}(s,A,n);if(s.genesetByTermId)return function(t,e,n){if(!n.termMatch2geneSet)throw"this feature is not enabled";if("string"!=typeof t.genesetByTermId||0==t.genesetByTermId.length)throw"invalid query term id";const r=n.q.getGenesetByTermId(t.genesetByTermId);e.send(r)}(s,n,M);if(s.getSampleScatter)return await v(e,s,n,A,q);if(s.getLowessCurve)return await b(e,s,n);if(s.getCohortsData)return await x(s,n,A);if(s.getViolinPlotData)return await _(s,n,A,q);if("mds3queryDetails"==s.for)return function(t,e){const n={},r=e.queries||{};r.snvindel&&(n.snvindel={},r.snvindel.details&&(n.snvindel.details=r.snvindel.details),r.snvindel.populations&&(n.snvindel.populations=r.snvindel.populations));r.trackLst&&(n.trackLst=r.trackLst);if(r.ld){n.ld=JSON.parse(JSON.stringify(r.ld));for(const t of n.ld.tracks)delete t.file}t.send(n)}(n,A);if("termTypes"==s.for)return n.send(await A.getTermTypes(s));if("matrix"==s.for)return await async function(t,e,n,r,o){if(t.getPlotDataByName){if(!r.cohort.matrixplots)throw"ds.cohort.matrixplots missing for the dataset";if(!r.cohort.matrixplots.plots)throw"ds.cohort.matrixplots.plots missing for the dataset";const e=r.cohort.matrixplots.plots.find((e=>e.name===t.getPlotDataByName));if(!e)throw`plot name: q.getPlotDataByName=${getPlotDataByName} missing in ds.cohort.matrixplots.plots`;return void n.send(e.matrixConfig)}const i=await w(t,r,o);if(a().canDisplaySampleIds(e,r))for(const t of Object.values(i.samples))t.sampleName=r.sampleId2Name.get(t.sample);n.send(i)}(s,e,n,A,q);if("mds3variantData"==s.for)return await k(s,n,A,q);throw s.for,"termdb: doesn't know what to do"}catch(t){n.send({error:t.message||t}),t.stack?console.log(t.stack):console.log(t)}}}function N(t){return JSON.parse(JSON.stringify(t))}function S(t,e){if("categorical"==t.type)return{};if("survival"==t.type)return{};if("integer"==t.type||"float"==t.type)return t.bins.default;if("condition"==t.type)return{mode:e.mode,breaks:e.breaks,bar_by_grade:e.bar_by_grade,bar_by_children:e.bar_by_children,value_by_max_grade:e.value_by_max_grade,value_by_most_recent:e.value_by_most_recent,value_by_computable_grade:e.value_by_computable_grade};if("geneVariant"==t.type)return{};throw"unknown term type"}},2974:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getData:()=>f,getSampleData_dictionaryTerms_termdb:()=>d,mayInitiateMatrixplots:()=>h});const r=n(1017),{get_samples:o,get_term_cte:i,interpolateSqlValues:s}=n(2852),{getFilterCTEs:a}=n(5257),l=(n(9157),n(7147),n(7219),n(334)),c=n(3856),{getSampleData_snplstOrLocus:u}=(n(2852),n(8599));async function f(t,e,n){try{return function(t,e,n){if(!e.cohort)throw"cohort missing from ds";if(!t.terms)throw"missing 'terms' parameter";t.ds=e,t.genome=n;for(const e of t.terms)e.term.name||(e.term=t.ds.cohort.termdb.q.termjsonByOneid(e.term.id)),e.q||console.log("do something??");if(t.currentGeneNames&&!Array.isArray(t.currentGeneNames))throw"currentGeneNames[] is not array";t.filter0&&"string"==typeof t.filter0&&(t.filter0=JSON.parse(t.filter0))}(t,e,n),await async function(t){const[e,n]=function(t){const e=[],n=[];for(const r of t){const t=r.term.type;"snplst"==t||"snplocus"==t||"geneVariant"==t?n.push(r):e.push(r)}return[e,n]}(t.terms),{samples:r,refs:i}=await async function(t,e){var n,r,o,i;if(!e.length)return{samples:{},refs:{byTermId:{}}};if(null!==(n=t.ds)&&void 0!==n&&null!==(r=n.cohort)&&void 0!==r&&r.db)return await d(t,e);if(null!==(o=t.ds)&&void 0!==o&&null!==(i=o.variant2samples)&&void 0!==i&&i.get)return await async function(t,e){const n={filter0:t.filter0,filterObj:t.filter,genome:t.genome,get:"samples",twLst:e,useIntegerSampleId:!0};if(t.currentGeneNames){n.geneTwLst=[];for(const e of t.currentGeneNames)n.geneTwLst.push({term:{name:e,type:"geneVariant"}})}const r=await t.ds.variant2samples.get(n),o={},i={byTermId:{}};for(const t of r){const n={sample:t.sample_id};for(const r of e){const e=t[r.term.id];Array.isArray(e)&&null!=e[0]&&null!=e[0]?n[r.term.id]={key:e[0],value:e[0]}:null!=e&&null!=e&&(n[r.term.id]={key:e,value:e})}o[t.sample_id]=n}return{samples:o,refs:i}}(t,e);throw"unknown method for dictionary terms"}(t,e);t.ds.getSampleIdMap&&(i.bySampleId=t.ds.getSampleIdMap(r));if(e.length&&!Object.keys(r).length)return{samples:r,refs:i};const s=await async function(t,e){if(!e.find((t=>"snplst"==t.term.type||"snplocus"==t.term.type)))return;if(!t.filter)return;return new Set((await o(t.filter,t.ds)).map((t=>t.id)))}(t,n);for(const o of n)if("geneVariant"==o.term.type){const n=await t.ds.mayGetGeneVariantData(o,t);for(const[i,s]of n.entries()){var a,l;if(o.term.name in s)if(e.length||i in r||(r[i]={sample:i}),r[i])if(r[i][o.term.name]=s[o.term.name],null!==(a=t.ds.cohort)&&void 0!==a&&null!==(l=a.termdb)&&void 0!==l&&l.additionalSampleAttributes)for(const e of null===(c=t.ds.cohort)||void 0===c||null===(f=c.termdb)||void 0===f?void 0:f.additionalSampleAttributes){var c,f;e in s&&(r[i][e]=s[e])}}}else{if("snplst"!=o.term.type&&"snplocus"!=o.term.type)throw"unknown type of non-dictionary term";{o.type=o.term.type;const t=new Map;await u(o,t,!0);for(const[e,n]of t){if(s&&!s.has(e))continue;e in r||(r[e]={sample:e});const t={};for(const[e,r]of n.id2value)t[e]=r.value;r[e][o.term.id]=t}}}return{samples:r,refs:i}}(t)}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}async function d(t,e){const n={},r={byTermId:{}},o={},s=await a(t.filter,t.ds),l=s?s.values.slice():[],c=await Promise.all(e.map((async(e,n)=>{const a=await i(t,l,n,s,e);if(a.bins&&(r.byTermId[e.term.id]={bins:a.bins}),e.term.values){const t=Object.values(e.term.values);t.find((t=>"order"in t))&&(r.byTermId[e.term.id]={keyOrder:t.sort(((t,e)=>t.order-e.order)).map((t=>t.key))})}return"id"in e.term&&(o[e.term.id]=e),a}))).catch(console.error);l.push(...e.map((t=>t.term.id||t.term.name)));const u=`WITH\n\t\t${s?s.filters+",":""}\n\t\t${c.map((t=>t.sql)).join(",\n")}\n\t\t${c.map((t=>`\n\t\t\tSELECT sample, key, value, ? as term_id\n\t\t\tFROM ${t.tablename}\n\t\t\t${s?`WHERE sample IN ${s.CTEname}`:""}\n\t\t\t`)).join("UNION ALL")}`,f=t.ds.cohort.db.connection.prepare(u).all(l),d=await async function(t){if(!t.currentGeneNames)return;const e=new Set;for(const n of t.currentGeneNames){const r={term:{name:n,type:"geneVariant"}},o=await t.ds.mayGetGeneVariantData(r,t);for(const[t,n]of o.entries())e.add(t)}return e}(t);for(const{sample:t,term_id:e,key:r,value:i}of f){if(d&&!d.has(t))continue;n[t]||(n[t]={sample:t});o[e];n[t][e]={key:r,value:i}}return{samples:n,refs:r}}async function h(t){if(t.cohort.matrixplots){if(!Array.isArray(t.cohort.matrixplots.plots))throw"cohort.matrixplots.plots is not array";for(const e of t.cohort.matrixplots.plots){if(!e.name)throw".name missing from one of matrixplots.plots[]";if(!e.file)throw"unknown data source of one of matrixplots.plots[]";{const t=await c.read_file(r.join(l.tpmasterdir,e.file));e.matrixConfig=JSON.parse(t),e.getConfig&&(e.matrixConfig=e.getConfig(e.matrixConfig))}}}}},5708:(t,e,n)=>{"use strict";n.r(e),n.d(e,{do_precompute:()=>h,getgroup:()=>w,trigger:()=>d,update_image:()=>v});const r=n(7147),o=n(1017),i=n(3856),s=n(2852),a=n(6718).createCanvas,l=n(7860),c=n(4521),u=n(334),f=n(9157);async function d(t,e,n){if(!n.cohort)throw"ds.cohort missing";if(!n.cohort.termdb)throw"cohort.termdb missing";if(!n.cohort.termdb.phewas)throw"not allowed on this dataset";if(!t.ssid)throw"ssid missing";const r={};let a;t.filter&&(a=new Set(await s.get_samples(t.filter,n)));const[c,d]=await i.loadfile_ssid(t.ssid,a);r.numberofsamples=c.size;const h=d.has(i.genotype_types.het)?d.get(i.genotype_types.het).size:0,p=d.has(i.genotype_types.href)?d.get(i.genotype_types.href).size:0,m=d.has(i.genotype_types.halt)?d.get(i.genotype_types.halt).size:0,g=function(t,e,n,r,o,i){const s=[];let a;if(e.cohort.termdb.selectCohort&&t){const e=t.lst.find((t=>"cohortFilter"==t.tag));e&&(a=e.tvs.values.map((t=>t.key)).sort().join(","))}for(const t of e.cohort.termdb.q.getcategory2vcfsample()){if(a&&t.subcohort!=a)continue;const c=l.copy_term(e.cohort.termdb.q.termjsonByOneid(t.term_id));for(const e of t.categories){const[a,l,u]=_(n,e.group1lst);let f,d,h;e.group2lst?[f,d,h]=_(n,e.group2lst):(f=r-a,d=i-l,h=o-u),a+f+l+d+u+h!=0&&s.push({term:c,group_name:t.group_name,parent_name:t.parent_name,group1label:e.group1label,group2label:e.group2label,table:[u,h,a,f,l,d]})}}return s}(t.filter,n,c,h,p,m);r.testcount=g.length;{const t=[];for(let e=0;e<g.length;e++)t.push(e+"\t"+g[e].table.join("\t"));const e=await f(o.join(u.binpath,"utils/fisher.2x3.R"),t);let n=0;for(const t of e)g[n++].pvalue=Number(t.split("\t")[7])}r.maxlogp=function(t){let e=0;for(const n of t)0==n.pvalue?n.logp=100:n.logp=-Math.log10(n.pvalue),e=Math.max(e,n.logp);return e}(g);const y=function(t){const e=new Map;for(const n of t)e.has(n.group_name)||e.set(n.group_name,[]),e.get(n.group_name).push(n);const n=[];for(const[t,r]of e)n.push({group_name:t,categories:r});return n}(g);r.tmpfile=await function(t){const e=[];for(const n of t)for(const t of n.categories)e.push(n.group_name+"\t"+t.logp+"\t"+t.pvalue+"\t"+JSON.stringify(t));return i.write_tmpfile(e.join("\n"))}(y),b(y,r,t);{const t=.05;r.hoverdots=g.filter((e=>e.pvalue<=t))}e.send(r)}async function h(t){if(!t.cohort)throw"ds.cohort missing";if(!t.cohort.termdb)throw"cohort.termdb missing";if(!t.cohort.termdb.phewas)throw"not allowed on this dataset";t.cohort.termdb.selectCohort?await async function(t){const e=await async function(t){if(!t.cohort.termdb.phewas.precompute_subcohort2totalsamples)return;for(const e in t.cohort.termdb.phewas.precompute_subcohort2totalsamples){const n=t.cohort.termdb.phewas.precompute_subcohort2totalsamples[e];if(n.termtype)for(const e in n.termtype)n.termtype[e].samples=await s.get_samples(n.termtype[e].filter,t)}return t.cohort.termdb.phewas.precompute_subcohort2totalsamples}(t),n=function(t){const e=new Map,n=t.cohort.db.connection.prepare("SELECT * FROM subcohort_terms");for(const{term_id:t,cohort:r}of n.all())e.has(t)||e.set(t,new Set),e.get(t).add(r);return e}(t),o=r.createWriteStream("category2vcfsample"),i=[];for(const{group_name:r,term:a}of t.cohort.termdb.q.getAlltermsbyorder()){if(!a.type)continue;if(!n.has(a.id)){i.push(a.id);continue}let l="";{const e=t.cohort.termdb.q.getTermParent(a.id);e&&(l=e.name)}const c=m(a,t,n);for(const n of c){const i=await s.get_rows(n);let c;if("categorical"==a.type||"integer"==a.type||"float"==a.type)c=g(i.lst,a,t);else{if("condition"!=a.type)throw"unknown term type";c=t.cohort.termdb.phewas.comparison_groups?y(i.lst,t):g(i.lst,a,t)}c=p({categories:c,q:n,subcohortTermtype2samples:e,term:a});for(const t of c)console.log(t.group1lst.length+(t.group2lst?"/"+t.group2lst.length:"")+"\t"+t.group1label+"\t"+a.name+"\t"+n.cohortname);o.write(n.cohortname+"\t"+r+"\t"+a.id+"\t"+l+"\t"+(n.term1_q?JSON.stringify(n.term1_q):"{}")+"\t"+JSON.stringify(c)+"\n")}}o.end((()=>{console.log('Phewas precompute result written to file "category2vcfsample".'),i.length&&(console.log(i.length+" empty terms:"),console.log(i.join("\n")))}))}(t):await async function(t){const[e]=await async function(t){let e=null;if(t.cohort.termdb.phewas.samplefilter4termtype&&t.cohort.termdb.phewas.samplefilter4termtype.condition){const n=await s.get_samples(t.cohort.termdb.phewas.samplefilter4termtype.condition.filter,t);if(t.track&&t.track.vcf&&t.track.vcf.sample2arrayidx){e=[];for(const r of n)t.track.vcf.sample2arrayidx.has(r)&&e.push(r)}else e=n}return[e]}(t),n=[];for(const{group_name:r,term:o}of t.cohort.termdb.q.getAlltermsbyorder()){if(!o.type)continue;let i="";{const e=t.cohort.termdb.q.getTermParent(o.id);e&&(i=e.name)}const a=m(o,t);for(const l of a){const a=await s.get_rows(l);let c;if("categorical"==o.type||"integer"==o.type||"float"==o.type)c=g(a.lst,o,t);else{if("condition"!=o.type)throw"unknown term type";c=t.cohort.termdb.phewas.comparison_groups?y(a.lst,t):g(a.lst,o,t)}c=p({categories:c,q:l,term:o,condition_samplelst:e});for(const t of c)console.log(t.group1lst.length+(t.group2lst?"/"+t.group2lst.length:"")+"\t"+t.group1label+"\t"+o.name);n.push(r+"\t"+o.id+"\t"+i+"\t"+(l.term1_q?JSON.stringify(l.term1_q):"{}")+"\t"+JSON.stringify(c))}}r.writeFileSync("category2vcfsample",n.join("\n")),console.log('Phewas precompute result written to file "category2vcfsample".')}(t)}function p(t){const{categories:e,q:n,term:r,subcohortTermtype2samples:o,condition_samplelst:i}=t;if(o&&o[n.cohortname]&&o[n.cohortname].termtype&&o[n.cohortname].termtype[r.type]){const t=o[n.cohortname].termtype[r.type].samples;for(const n of e)if(n.group2lst)n.group2lst=n.group2lst.filter((e=>-1!=t.indexOf(e)));else if(n.copycontrolfrom1stgroup){n.group2lst=[];for(const t of e[0].group2lst)n.group2lst.push(t)}else{const e=new Set(n.group1lst);n.group2lst=t.filter((t=>!e.has(t)))}return e}if(i&&"condition"==r.type){for(const t of e)if(t.group2lst)t.group2lst=t.group2lst.filter((t=>-1!=i.indexOf(t)));else if(t.copycontrolfrom1stgroup){t.group2lst=[];for(const n of e[0].group2lst)t.group2lst.push(n)}else{const e=new Set(t.group1lst);t.group2lst=i.filter((t=>!e.has(t)))}return e}if(!r.values)return e;const s=new Set;for(const t in r.values)r.values[t].uncomputable&&s.add(r.values[t].label);if(0==s.size)return e;const a=[];for(const t of e)s.has(t.group1label)?console.log("skip "+t.group1label+", "+r.id):a.push(t);for(let t=0;t<a.length;t++){const e=a[t];e.group2lst=[];for(let n=0;n<a.length;n++)n!=t&&e.group2lst.push(...a[n].group1lst)}return a}function m(t,e,n){const r=[];if(e.cohort.termdb.selectCohort){if(!n)throw"term2cohort is required when cohort selection is enabled";for(const o of e.cohort.termdb.selectCohort.values){const i=o.keys.sort().join(",");if(!n.get(t.id).has(i))continue;const s={type:"tvslst",in:!0,join:"",lst:[{type:"tvs",tvs:{term:e.cohort.termdb.selectCohort.term,values:o.keys.map((t=>({key:t})))}}]};if("categorical"==t.type)r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id});else if("float"==t.type||"integer"==t.type)r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id,term1_q:t.bins.default});else{if("condition"!=t.type)throw"unknown term type";r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id,term1_q:{bar_by_grade:!0,value_by_max_grade:!0}})}}}else if("categorical"==t.type)r.push({ds:e,term1_id:t.id});else if("float"==t.type||"integer"==t.type)r.push({ds:e,term1_id:t.id,term1_q:t.bins.default});else{if("condition"!=t.type)throw"unknown term type";r.push({ds:e,term1_id:t.id,term1_q:{bar_by_grade:!0,value_by_max_grade:!0}})}return r}function g(t,e,n){const r=new Map;for(const o of t){if(n.track&&n.track.vcf&&n.track.vcf.sample2arrayidx&&!n.track.vcf.sample2arrayidx.has(o.sample))continue;const t=o.key1;if(!r.has(t)){let n=t;e.values&&(n=e.values[t]?e.values[t].label:t),r.set(t,{group1label:n,group2label:"All others",group1lst:[]})}r.get(t).group1lst.push(o.sample)}return[...r.values()]}function y(t,e){const n=[];for(const r of e.cohort.termdb.phewas.comparison_groups){const o=[],i=[];for(const n of t){if(e.track&&e.track.vcf&&e.track.vcf.sample2arrayidx&&!e.track.vcf.sample2arrayidx.has(n.sample))continue;const t=Number(n.key1);r.group1grades.has(t)?o.push(n.sample):r.group2grades&&r.group2grades.has(t)&&i.push(n.sample)}0!=o.length?n.push({group1label:r.group1label,group2label:r.group2label,group1lst:o,group2lst:i.length?i:void 0,copycontrolfrom1stgroup:r.copycontrolfrom1stgroup}):console.log("Empty group1: "+r.group1label)}return n}async function v(t,e){const n=await i.read_file(o.join(u.cachedir,t.file)),r=[];for(const t of n.trim().split("\n")){const[e,n]=t.split("\t",2),o=Number(n);0!=r.length&&r[r.length-1].group_name==e||r.push({group_name:e,categories:[]}),r[r.length-1].categories.push({logp:o})}const s={maxlogp:Number(t.max)};b(r,s,t),e.send(s)}function b(t,e,n){const r=Number(n.intendwidth),o=Number(n.axisheight),i=Number(n.groupnamefontsize),s=Number(n.dotradius),l=Number(n.groupxspace),c=Number(n.leftpad),u=Number(n.rightpad),f=Number(n.toppad),d=Number(n.bottompad),h=Number(n.devicePixelRatio),p=r/t.reduce(((t,e)=>t+e.categories.length),0),m=a(10,10),g=m.getContext("2d");let y=0;for(const e of t){const t=e.categories.length*p;e.width=Math.max(t,i)+2*l,e.dotshiftx=t>i?p:i/e.categories.length,y+=e.width}const v=c+y+u;m.width=v*h;const b=f+o+d;m.height=b*h,h>1&&g.scale(h,h),y=0,g.fillStyle="#FDFEE2";for(const[e,n]of t.entries())e%2==0&&g.fillRect(y,f,n.width,o),y+=n.width;y=0,g.fillStyle="black",e.grouplabels=[];for(const n of t){e.grouplabels.push({name:n.group_name,x:y+n.width/2,y:f+o+2*s});let t=0;for(const r of n.categories){const i=0==e.maxlogp?0:r.logp>=e.maxlogp?o:o*r.logp/e.maxlogp;g.beginPath(),g.arc(y+l+t,f+o-i,s,0,2*Math.PI),g.fill(),r.x=y+l+t,t+=n.dotshiftx}y+=n.width}e.canvaswidth=v,e.canvasheight=b,e.toppad=f,e.bottompad=d,e.axisheight=o,e.dotradius=s,e.groupnamefontsize=i,e.src=m.toDataURL()}function _(t,e){const n=new Map;for(const r of e){const e=t.get(r);e&&n.set(e,1+(n.get(e)||0))}return[n.get(i.genotype_types.het)||0,n.get(i.genotype_types.halt)||0,n.get(i.genotype_types.href)||0]}async function w(t,e){if(!t.file)throw"file missing";return new Promise(((n,i)=>{const s=[],a=c.createInterface({input:r.createReadStream(o.join(u.cachedir,t.file))});a.on("line",(e=>{if(!e.startsWith(t.getgroup+"\t"))return;const n=e.split("\t"),r=JSON.parse(n[3]);r.pvalue=Number(n[2]),s.push(r)})),a.on("close",(()=>{e.send({categories:s}),n()}))}))}},8599:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getSampleData_snplstOrLocus:()=>A,get_regression:()=>v});const r=n(1017),{get_term_cte:o}=n(2852),{getFilterCTEs:i}=n(5257),s=n(9157),a=n(7147),l=n(7219),c=n(334),u=n(3856),f=n(1271).run_rust,d=(n(2852),n(4453).runCumincR),h=n(9699),p=["linear","logistic","cox"];let m,g;const y={NodeJS:{},"regression.R":{}};async function v(t,e){try{!function(t,e){if(!e.cohort)throw"cohort missing from ds";if(t.ds=e,!t.regressionType)throw"regressionType missing";if(!p.includes(t.regressionType))throw"unknown regressionType";if(!t.outcome)throw"missing 'outcome' parameter";if(!("id"in t.outcome))throw"outcome.id missing";if(!t.outcome.q)throw"outcome.q missing";if(t.outcome.q.computableValuesOnly=!0,t.outcome.term=e.cohort.termdb.q.termjsonByOneid(t.outcome.id),!t.outcome.term)throw"invalid outcome term: "+t.outcome.id;if(!t.independent)throw"independent[] missing";if(!Array.isArray(t.independent)||0==t.independent.length)throw"q.independent is not non-empty array";for(const n of t.independent){if(!n.q)throw`missing q for independent term '${n.id}'`;if(b(n,t,e),"snplst"!=n.type&&"snplocus"!=n.type){if(n.q.computableValuesOnly=!0,!n.id)throw".id missing for an independent term";if(n.term=e.cohort.termdb.q.termjsonByOneid(n.id),!n.term)throw`invalid independent term='${n.id}'`}else{if(!n.q.cacheid)throw"q.cacheid missing";if(c.cache_snpgt.fileNameRegexp.test(n.q.cacheid))throw"invalid cacheid";if("object"!=typeof n.q.snp2effAle)throw"q.snp2effAle{} is not object";if(!Number.isInteger(n.q.alleleType))throw"q.alleleType is not integer";if(!Number.isInteger(n.q.geneticModel))throw"q.geneticModel is not integer";if(3==n.q.geneticModel&&"object"!=typeof n.q.snp2refGrp)throw"q.snp2refGrp{} is not object when geneticMode=3";if("snplst"==n.type&&!Number.isInteger(n.q.missingGenotype))throw"q.missingGenotype is not integer for snplst"}}for(const e of t.independent){e.interactions||(e.interactions=[]);for(const n of e.interactions)if(!t.independent.find((t=>t.id==n)))throw"interacting term id missing from independent[]: "+n}}(t,e),m=(new Date).getTime();const n=await async function(t,e,n){const[r,s]=function(t){const e=[],n=[];for(const r of t)"snplst"==r.type||"snplocus"==r.type?n.push(r):e.push(r);return[e,n]}(e),a=await async function(t,e){const n=new Map,r=await i(t.filter,t.ds),s=r?r.values.slice():[],a=await Promise.all(e.map((async(e,n)=>await o(t,s,n,r,e)))).catch(console.error);s.push(...e.map((t=>t.id)));const l=`WITH\n\t\t${r?r.filters+",":""}\n\t\t${a.map((t=>t.sql)).join(",\n")}\n\t\t${a.map((t=>`\n\t\t\tSELECT sample, key, value, ? as term_id\n\t\t\tFROM ${t.tablename}\n\t\t\t${r?`WHERE sample IN ${r.CTEname}`:""}\n\t\t\t`)).join("UNION ALL")}`,c=t.ds.cohort.db.connection.prepare(l).all(s),u=[],f=t.ds.cohort.termdb.ageEndOffset;if(!f)throw"missing age end offset";for(const e of c)if("cox"==t.regressionType&&e.term_id==t.outcome.id){const{event:n}=JSON.parse(e.key),{age_start:r,age_end:o}=JSON.parse(e.value);if(-1==n)continue;const i={age_start:r,age_end:"age"==t.outcome.q.timeScale?o+f:o};u.push({sample:e.sample,key:n,value:i,term_id:e.term_id})}else u.push(e);for(const{sample:t,term_id:r,key:o,value:i}of u){const s=e.find((t=>t.id==r));if(n.has(t)||n.set(t,{sample:t,id2value:new Map}),n.get(t).id2value.has(r))throw`duplicate '${r}' entry for sample='${t}'`;n.get(t).id2value.set(r,{key:s.q.scale?o/s.q.scale:o,value:s.q.scale?i/s.q.scale:i})}const d=new Set;for(const t of n.values())for(const n of e)if(!t.id2value.has(n.id)){d.add(t.sample);break}for(const t of d)n.delete(t);return n}(t,r);for(const t of s){if(S(t,a,n),"snplst"!=t.type&&"snplocus"!=t.type)throw"unknown type of independent non-dictionary term";await A(t,a)}return[...a.values()]}(t,[t.outcome,...t.independent],e);g=(new Date).getTime(),y.NodeJS.getSampleData=(g-m)/1e3+" sec",m=(new Date).getTime();const r=function(t,e){const n={id:t.outcome.id,name:t.outcome.term.name,rtype:"numeric"};"logistic"==t.regressionType&&(n.categories={ref:t.outcome.refGrp,nonref:x(t.outcome)});"cox"==t.regressionType&&(n.timeToEvent={timeId:t.outcome.id+"_time",eventId:t.outcome.id+"_event",timeScale:t.outcome.q.timeScale},"age"==n.timeToEvent.timeScale&&(n.timeToEvent.agestartId=t.outcome.id+"_agestart",n.timeToEvent.ageendId=t.outcome.id+"_ageend"));const r=[];for(const e of t.independent)"snplst"==e.type||"snplocus"==e.type?w(e,r,t):_(e,r,t);const o=[];for(const i of e){const{sample:e,id2value:s}=i;if(!s.has(t.outcome.id)){i.noOutcome=!0;continue}const a=s.get(t.outcome.id);let l=!1;for(const e of t.independent)if("snplocus"!=e.type)if("snplst"==e.type){for(const t of e.highAFsnps.keys())if(!s.get(t)){l=!0;break}}else{if(!s.get(e.id)){l=!0;break}}if(l)continue;const c={};if("linear"==t.regressionType&&(c[n.id]=a.value),"logistic"==t.regressionType&&(c[n.id]=a.key===t.outcome.refGrp?0:1),"cox"==t.regressionType){c[n.timeToEvent.eventId]=a.key;const{age_start:e,age_end:r}=a.value;c[n.timeToEvent.timeId]=r-e,"age"==t.outcome.q.timeScale&&(c[n.timeToEvent.agestartId]=e,c[n.timeToEvent.ageendId]=r)}for(const t of r){const e=s.get(t.id);c[t.id]=e?"numeric"===t.rtype?e.value:e.key:null}o.push(c)}return{regressionType:t.regressionType,binpath:c.binpath,data:o,outcome:n,independent:r}}(t,n);g=(new Date).getTime(),y.NodeJS.makeRinput=(g-m)/1e3+" sec",function(t){const e=t.regressionType,n=t.outcome;if(t.data.length<1)throw"too few samples to fit model";let r=t.independent.length;if("cox"==e)if("time"==n.timeToEvent.timeScale)r+=2;else{if("age"!=n.timeToEvent.timeScale)throw"unknown cox regression time scale";r+=4}else r+=1;if(t.data.find((t=>Object.keys(t).length!=r)))throw"unequal number of variables in data entries";if("logistic"==e){if([...new Set(t.data.map((t=>t[n.id])))].find((t=>![0,1].includes(t))))throw"non-0/1 outcome values found"}if("cox"==e){if([...new Set(t.data.map((t=>t[n.timeToEvent.eventId])))].find((t=>![0,1].includes(t))))throw"non-0/1 outcome event values found"}for(const e of t.independent)if("numeric"==e.rtype){if(e.refGrp)throw`reference group given for '${e.id}'`}else{if("factor"!=e.rtype)throw`variable rtype='${e.rtype}' not recognized`;{if(!e.refGrp)throw`reference group not given for '${e.id}'`;if("snplst"==e.type||"snplocus"==e.type)continue;const n=new Set(t.data.map((t=>t[e.id])));if(n.size<2)throw`fewer than 2 categories in data of variable='${e.id}'`;if(!n.has(e.refGrp))throw`reference group missing in data of variable='${e.id}'`}}}(r);const[s,a]=function(t){const e={},n={};if(e.outcome=t.outcome.id,n[t.outcome.id]="outcome",t.outcome.timeToEvent){const r=t.outcome.timeToEvent;e.outcome_time=r.timeId,n[r.timeId]="outcome_time",e.outcome_event=r.eventId,n[r.eventId]="outcome_event","age"==r.timeScale&&(e.outcome_agestart=r.agestartId,e.outcome_ageend=r.ageendId,n[r.agestartId]="outcome_agestart",n[r.ageendId]="outcome_ageend")}for(const[r,o]of t.independent.entries())e["id"+r+"_"]=o.id,n[o.id]="id"+r+"_";if(t.outcome.id=n[t.outcome.id],t.outcome.timeToEvent){const e=t.outcome.timeToEvent;e.timeId=n[e.timeId],e.eventId=n[e.eventId],"age"==e.timeScale&&(e.agestartId=n[e.agestartId],e.ageendId=n[e.ageendId])}for(const e of t.independent)if(e.id=n[e.id],e.interactions&&e.interactions.length>0)for(const[t,r]of e.interactions.entries())e.interactions[t]=n[r];for(const e of t.data)for(const t in e)e[n[t]]=e[t],delete e[t];return[e,n]}(r),l={resultLst:[]};return await Promise.all([k(r,s,t,l),q(t,n,r,l)]),console.log("benchmark:",y),l}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function b(t,e,n){if(!t.q.restrictAncestry)return;if(!("name"in t.q.restrictAncestry))throw".name missing from tw.q.restrictAncestry";if(!n.cohort.termdb.restrictAncestries)throw"ds.cohort.termdb.restrictAncestries missing";const r=n.cohort.termdb.restrictAncestries.find((e=>e.name==t.q.restrictAncestry.name));if(!r)throw"unknown ancestry for restriction: "+t.q.restrictAncestry.name;if(r.pcs)t.q.restrictAncestry.pcs=r.pcs;else{if(!r.PCfileBySubcohort)throw"unknown way of accessing pcs from ds.cohort.termdb.restrictAncestries: "+t.q.restrictAncestry.name;{if(!e.filter)throw"q.filter missing while trying to access subcohort for PCfileBySubcohort";const n=T(e.filter,"cohortFilter");if(!n)throw"tvs by tag=cohortFilter missing from q.filter.lst[] while trying to access subcohort for PCfileBySubcohort";const o=n.tvs.values.map((t=>t.key)).sort().join(","),i=r.PCfileBySubcohort[o];if(!i)throw"unknown key for PCfileBySubcohort: "+o;if(!i.pcs)throw"pcs Map() missing from PCfileBySubcohort[]: "+o;t.q.restrictAncestry.pcs=i.pcs}}}function _(t,e,n){const o={id:t.id,name:t.term.name,type:"spline"==t.q.mode?"spline":"other",rtype:"continuous"==t.q.mode||"spline"==t.q.mode?"numeric":"factor"};if(t.interactions.length>0){o.interactions=[];for(const e of t.interactions){const t=n.independent.find((t=>t.id==e));if("snplst"==t.type)for(const e of t.highAFsnps.keys())o.interactions.push(e);else{if("snplocus"==t.type)continue;o.interactions.push(e)}}}"factor"===o.rtype&&(o.refGrp=t.refGrp),"spline"==t.q.mode&&(o.spline={knots:t.q.knots.map((t=>Number(t.value)))},n.independent.find((t=>"snplocus"==t.type))||(o.spline.plotfile=r.join(c.cachedir,Math.random().toString()+".png"))),e.push(o)}function w(t,e,n){for(const r of t.highAFsnps.keys()){const o={id:r,name:r,type:t.type};3==t.q.geneticModel?(o.rtype="factor",o.refGrp=t.q.snp2refGrp[r]):o.rtype="numeric";for(const e of n.independent)e.interactions.includes(t.id)&&(o.interactions||(o.interactions=[]),o.interactions.push(e.id));e.push(o)}if(t.q.restrictAncestry)for(const n of t.q.restrictAncestry.pcs.keys())e.push({id:n,name:n,type:"float",rtype:"numeric"})}function x(t){if("condition"==t.term.type){for(const e of t.q.groups)if(e.name!=t.refGrp)return e;throw"nonref group not found for logistic outcome"}if("predefined-groupset"==t.q.type){if(!t.q.groupsetting)throw"outcome.q.groupsetting{} missing when type=predefined-groupset";if(!Number.isInteger(t.q.groupsetting.predefined_groupset_idx))throw'outcome.q.predefined_groupset_idx not integer when q.type is "predefined-groupset"';if(!t.term.groupsetting)throw"outcome.term.groupsetting missing";const e=t.term.groupsetting.lst[t.q.groupsetting.predefined_groupset_idx];if(!e)throw"groupset not found by outcome.q.predefined_groupset_idx";const n=e.groups.find((e=>e.name!=t.refGrp));if(!n)throw"non-ref group not found for predefined-groupset";return n.name}if("custom-groupset"==t.q.type){if(!t.q.groupsetting)throw"outcome.q.groupsetting{} missing when type=predefined-groupset";if(!t.q.groupsetting.customset)throw"outcome.q.customset missing";const e=t.q.groupsetting.customset.groups.find((e=>e.name!=t.refGrp));if(!e)throw"non-ref group not found for custom-groupset";return e.name}if("values"==t.q.type){if(!t.term.values)throw"outcome.term.values{} missing";for(const e in t.term.values){const n=t.term.values[e];if(n.label!=t.refGrp)return n.label}throw"unknown nonref group from outcome.term.values"}if("custom-bin"==t.q.type){const e=t.q.lst.find((e=>e.label!=t.refGrp));if(!e)throw"non-ref bin is not found for custom-bin";return e.label}if("regular-bin"==t.q.type)throw"do not know a way to find computed bin list for type=regular-bin";throw"unknown outcome.q.type"}async function k(t,e,n,o){m=(new Date).getTime();const i=r.join(c.cachedir,Math.random().toString()+".json");await u.write_file(i,JSON.stringify(t));const f=await s(r.join(c.binpath,"utils","regression.R"),[],[i]);a.unlink(i,(()=>{})),await async function(t,e,n,r,o){if(1!=e.length)throw"expected 1 json line in R output";const i=JSON.parse(e[0]),s=i.data;y["regression.R"]=i.benchmark;for(const e of s){const i={data:{sampleSize:e.data.sampleSize,eventCnt:e.data.eventCnt?e.data.eventCnt:null}};if(e.id){const t=n[e.id];i.id=t;const o=r.independent.find((t=>"snplocus"==t.type));if(!o)throw"snplocus term missing";i.AFstr=o.snpid2AFstr.get(t),i.data.headerRow=N(t,o)}const s=e.data;if(s.residuals&&(i.data.residuals=s.residuals,i.data.residuals.label="linear"==t.regressionType?"Residuals":"Deviance residuals"),"cox"==t.regressionType){if(s.coefficients.rows.length<1)throw"fewer than 1 row in coefficients table"}else if(s.coefficients.rows.length<2)throw"fewer than 2 rows in coefficients table";i.data.coefficients={header:s.coefficients.header,intercept:"cox"==t.regressionType?null:s.coefficients.rows.shift(),terms:{},interactions:[]};for(const t of s.coefficients.rows)if(-1!=t[0].indexOf(":")){const e={},[r,o]=t.shift().split(":"),[s,a]=t.shift().split(":");e.term1=n[r],e.category1=s,e.term2=n[o],e.category2=a,e.lst=t,i.data.coefficients.interactions.push(e)}else{const e=t.shift(),r=t.shift(),o=n[e];i.data.coefficients.terms[o]||(i.data.coefficients.terms[o]={}),r?(i.data.coefficients.terms[o].categories||(i.data.coefficients.terms[o].categories={}),i.data.coefficients.terms[o].categories[r]=t):i.data.coefficients.terms[o].fields=t}i.data.coefficients.label="Coefficients",i.data.type3={header:s.type3.header,terms:{},interactions:[]},"cox"!=t.regressionType&&(i.data.type3.intercept=s.type3.rows.shift());for(const t of s.type3.rows)if(-1!=t[0].indexOf(":")){const e={},[r,o]=t.shift().split(":");e.term1=n[r],e.term2=n[o],e.lst=t,i.data.type3.interactions.push(e)}else{const e=n[t.shift()];i.data.type3.terms[e]||(i.data.type3.terms[e]=t)}if(i.data.type3.label="Type III statistics",s.totalSnpEffect){if(1!=s.totalSnpEffect.rows.length)throw"total SNP effect table should have 1 row";i.data.totalSnpEffect={header:s.totalSnpEffect.header.slice(0,4)};const t=s.totalSnpEffect.rows[0].slice(0,4),e=s.totalSnpEffect.rows[0][4].split(";"),r=e.findIndex((t=>!t.includes(":"))),o=e.splice(r,1)[0];i.data.totalSnpEffect.snp=n[o];const a=[];for(const t of e){if(!t.includes(":"))throw"expected interaction";const[e,r]=t.split(":");a.push({term1:n[e],term2:n[r]})}i.data.totalSnpEffect.interactions=a,i.data.totalSnpEffect.lst=t,i.data.totalSnpEffect.label="Total SNP effect"}s.tests&&(i.data.tests=s.tests,i.data.tests.label="Statistical tests"),i.data.other=s.other,i.data.other.label="Other summary statistics";for(const e of t.independent)if(e.spline&&e.spline.plotfile){i.data.splinePlots||(i.data.splinePlots=[]);const t=e.spline.plotfile,n=await a.promises.readFile(t);i.data.splinePlots.push({src:"data:image/png;base64,"+new Buffer.from(n).toString("base64"),size:l(t)}),a.unlink(t,(t=>{if(t)throw t}))}s.warnings&&(i.data.warnings=s.warnings);const c=r.independent.find((t=>"snplst"==t.type));if(c){if(c.lowAFsnps&&c.lowAFsnps.size){i.data.warnings||(i.data.warnings=[]);for(const t of c.lowAFsnps.keys())i.data.warnings.push(`${t}: effect allele frequency below cutoff, excluded from analysis`)}if(c.monomorphicLst&&c.monomorphicLst.length){i.data.warnings||(i.data.warnings=[]);for(const t of c.monomorphicLst)i.data.warnings.push(`${t}: monomorphic, excluded from analysis`)}}o.resultLst.push(i)}}(t,f,e,n,o),g=(new Date).getTime(),y.NodeJS.runRegression=(g-m)/1e3+" sec"}async function q(t,e,n,o){const i=t.independent.find((t=>"snplocus"==t.type));if(i){if(m=(new Date).getTime(),function(t,e){for(const n of t.monomorphicLst){const r=t.snpgt2count.get(n),o=[];for(const[t,e]of r)o.push(t+"="+e);const i={id:n,data:{headerRow:N(n,t)}};e.resultLst.push(i)}}(i,o),i.lowAFsnps.size)if("linear"==t.regressionType)await async function(t,e,n,o){const i={},l=new Map;for(const[r,o]of t.lowAFsnps){let t=0,s=null,a=null;const c=[],u=[];for(const{sample:r,noOutcome:i}of e){if(i)continue;const e=n.data[t++].outcome;if(!Number.isFinite(e))continue;const l=o.samples.get(r);if(!l)continue;null==s?s=a=e:(s=Math.min(s,e),a=Math.max(a,e));const[f,d]=l.split("/");f==o.effAle||d==o.effAle?c.push(e):u.push(e)}i[r]={group1values:c,group2values:u},l.set(r,{minv:s,maxv:a})}const f=r.join(c.cachedir,Math.random().toString()+".json");await u.write_file(f,JSON.stringify(i));const d=await s(r.join(c.binpath,"utils/wilcoxon.R"),[],[f]);a.unlink(f,(()=>{}));const p=JSON.parse(d);for(const e in p){const{group1values:n,group2values:r}=i[e],{minv:s,maxv:a}=l.get(e),c=h.boxplot_getvalue(n.sort(((t,e)=>t-e)).map((t=>({value:t}))));c.label=`Carry ${0==t.q.alleleType?"minor":"alternative"} allele, n=${n.length}`;const u=h.boxplot_getvalue(r.sort(((t,e)=>t-e)).map((t=>({value:t}))));u.label=`No ${0==t.q.alleleType?"minor":"alternative"} allele, n=${r.length}`;const f={id:e,AFstr:t.snpid2AFstr.get(e),data:{headerRow:N(e,t),wilcoxon:{pvalue:p[e],boxplots:{minv:s,maxv:a,hasEff:c,noEff:u}}}};o.resultLst.push(f)}}(i,e,n,o);else if("logistic"==t.regressionType)await async function(t,e,n,r){const o=[];let i=0;const s=new Map;for(const[r,a]of t.lowAFsnps){let t=0,l=0,c=0,u=0,f=0;for(const{sample:r,noOutcome:o}of e){if(o)continue;const e=n.data[f++],i="outcome"in e?e.outcome:e.outcome_event;if(0!=i&&1!=i)throw"outcome is not 0 or 1";const s=a.samples.get(r);if(!s)continue;const[d,h]=s.split("/"),p=a.effAle==d||a.effAle==h;0==i?p?l++:t++:p?u++:c++}s.set(i,r);const d={index:i,n1:u,n2:l,n3:c,n4:t};o.push(d),i++}const a=await f("fisher",JSON.stringify({input:o}));for(const e of JSON.parse(a)){const n=s.get(e.index),{effAle:o}=t.lowAFsnps.get(n),i=e.p_value,a="chisq"===e.fisher_chisq,l={id:n,AFstr:t.snpid2AFstr.get(n),data:{headerRow:N(n,t),fisher:{isChi:a,pvalue:Number(i.toFixed(4)),rows:[["","Carry "+o+" allele","No "+o+" allele"],["Have event",e.n1,e.n3],["No event",e.n2,e.n4]]}}};r.resultLst.push(l)}}(i,e,n,o);else{if("cox"!=t.regressionType)throw"unknown regression type";await async function(t,e,n,r){const o={data:{}},i=new Set;for(const[r,s]of t.lowAFsnps){const t=[];let a=0;for(const{sample:r,noOutcome:o}of e){if(o)continue;const e=n.data[a++];if(0!==e.outcome_event&&1!==e.outcome_event)throw"d.outcome_event is not 0/1";if(!Number.isFinite(e.outcome_time))throw"d.outcome_time is not numeric";const i={time:e.outcome_time,event:e.outcome_event},l=s.samples.get(r);if(!l)continue;const[c,u]=l.split("/");i.series=s.effAle==c||s.effAle==u?"1":"2",t.push(i)}new Set(t.map((t=>t.series))).size<2?i.add(r):o.data[r]=t}const s={case:[],tests:{}};let a;await d(o,s);for(const[e,n]of t.lowAFsnps){if(i.has(e)){a={pvalue:"NA",msg:"Cannot perform cumulative incidence test on this snp - at least one allele is not found in any sample"}}else{const t=[];for(const n of s.case)n[0]==e&&t.push(n);if(!s.tests[e]||!s.tests[e].length)throw"no tests for snp";const n=Number(s.tests[e][0].pvalue);if(!Number.isFinite(n))throw"invalid pvalue";const r={};r[e]=s.tests[e],a={pvalue:Number(n.toFixed(4)),final_data:{case:t,tests:r}}}const n={id:e,AFstr:t.snpid2AFstr.get(e),data:{headerRow:N(e,t),cuminc:a}};r.resultLst.push(n)}}(i,e,n,o)}g=(new Date).getTime(),y.NodeJS.snplocusPostprocess=(g-m)/1e3+" sec"}}function N(t,e){const n=e.snpgt2count.get(t);if(!n)return{k:"Error",v:"Variant not found"};if(e.monomorphicLst.includes(t)){const[t,e]=[...n][0];return{k:"Genotype",v:t+"="+e}}const r=[`${0==e.q.alleleType?"Minor":"Alternative"} allele=${e.highAFsnps.has(t)?e.highAFsnps.get(t).effAle:e.lowAFsnps.get(t).effAle}`,"AF="+e.snpid2AFstr.get(t)];for(const[t,e]of n)r.push(t+"="+e);return{k:"Variant:",v:r.join(" ")}}function S(t,e,n){if(t.q.restrictAncestry)for(const[n,r]of t.q.restrictAncestry.pcs)for(const[t,o]of r)e.has(t)&&e.get(t).id2value.set(n,{key:o,value:o})}async function A(t,e,n){const o=(await u.read_file(r.join(c.cache_snpgt.dir,t.q.cacheid))).split("\n"),i=o[0].split("\t").slice(c.cache_snpgt.sampleColumn).map(Number);if(n)for(const t of i)e.set(t,{id2value:new Map});const s=i.map((t=>e.has(t))),a=new Map;for(let e=1;e<o.length;e++){const n=o[e].split("\t"),r=n[0],l={refAle:n[3],altAles:n[4].split(","),samples:new Map};t.q.snp2effAle?l.effAle=t.q.snp2effAle[r]:l.effAle=l.altAles[0],a.set(r,l);for(const[t,e]of i.entries()){if(!s[t])continue;const o=n[t+c.cache_snpgt.sampleColumn];o&&a.get(r).samples.set(e,o)}}"snplocus"!=t.type&&function(t,e,n,r){if(0==e.q.missingGenotype){for(const e of t.values()){let t;if(e.refAle!=e.effAle)t=e.refAle;else for(const n of e.altAles)if(n!=e.effAle){t=n;break}if(!t)throw"not finding a non-effect allele";for(const[o,i]of n.entries())r[o]&&(e.samples.has(i)||e.samples.set(i,t+"/"+t))}return}if(1==e.q.missingGenotype)throw"not done";if(2==e.q.missingGenotype){const e=new Set;for(const{samples:o}of t.values())for(const[t,i]of n.entries())r[t]&&(o.has(i)||e.add(i));for(const{samples:n}of t.values())for(const t of e)n.delete(t);return}throw"invalid missingGenotype value"}(a,t,i,s),t.snpgt2count=new Map;for(const[e,n]of a){const r=new Map;for(const[t,e]of n.samples)r.set(e,1+(r.get(e)||0));t.snpgt2count.set(e,r)}!function(t,e){t.lowAFsnps=new Map,t.highAFsnps=new Map,t.monomorphicLst=[],t.snpid2AFstr=new Map;for(const[n,r]of e){if(1==t.snpgt2count.get(n).size){t.monomorphicLst.push(n);continue}const e=r.samples.size;let o=0;for(const[t,e]of r.samples){const[t,n]=e.split("/");o+=(t==r.effAle?1:0)+(n==r.effAle?1:0)}const i=o/(2*e);t.snpid2AFstr.set(n,(100*i).toFixed(1)+"%"),i<t.q.AFcutoff/100?t.lowAFsnps.set(n,r):t.highAFsnps.set(n,r)}}(t,a);for(const[n,r]of t.highAFsnps)for(const[o,i]of r.samples){const[s,a]=i.split("/"),l=M(t,r.effAle,s,a);e.get(o).id2value.set(n,{key:l,value:l})}}function M(t,e,n,r){switch(t.q.geneticModel){case 0:return(n==e?1:0)+(r==e?1:0);case 1:return n==e||r==e?1:0;case 2:return n==e&&r==e?1:0;case 3:return n+"/"+r;default:throw"unknown geneticModel option"}}function T(t,e){if(t.tag===e)return t;if("tvslst"===t.type)for(const n of t.lst){const t=T(n,e);if(t)return t}}},2188:(t,e,n)=>{"use strict";n.d(e,{uR:()=>b,v8:()=>S,wz:()=>v});var r=n(2974),o=n(1017),i=n.n(o),s=n(3856),a=n(334),l=n.n(a),c=n(2273),u=n(2852),f=n(5257),d=n(6191),h=n.n(d),p=n(9157),m=n.n(p);const g=n(3856).write_file,y="#F5F5DC";async function v(t){if(t.cohort.scatterplots){if(!Array.isArray(t.cohort.scatterplots.plots))throw"cohort.scatterplots.plots is not array";for(const e of t.cohort.scatterplots.plots){if(!e.name)throw".name missing from one of scatterplots.plots[]";if(!e.file)throw"unknown data source of one of scatterplots.plots[]";{const n=(await s.read_file(i().join(l().tpmasterdir,e.file))).trim().split("\n"),r=n[0].split("\t");e.filterableSamples=[];const o=[];let a=0,c=0;for(let i=1;i<n.length;i++){const s=n[i].split("\t"),l=Number(s[1]),u=Number(s[2]);if(Number.isNaN(l)||Number.isNaN(u)){a++;continue}const f={sample:s[0],x:l,y:u},d=t.cohort.termdb.q.sampleName2id(s[0]);if(null==d){if(r[3]){f.info={};for(let t=3;t<r.length;t++)f.info[r[t]]=s[t]}o.push(f)}else c++,f.sampleId=d,e.filterableSamples.push(f)}o.length&&(e.referenceSamples=o),console.log(e.filterableSamples.length,`scatterplot lines from ${e.name} of ${t.label},`,e.referenceSamples?e.referenceSamples.length+" reference cases":"",a?a+" lines with invalid X/Y values":"")}}}}async function b(t,e,n,o,i){try{let s,a;if(2==e.coordTWs.length)s=[],a=await async function(t,e,n){e.ds=n;const r=[];if(2!=e.coordTWs.length)return r;const o=await(0,f.getFilterCTEs)(e.filter,e.ds);let i="";o&&(i+=(0,u.interpolateSqlValues)(`WITH ${o.filters}`,o.values.slice()));const s=e.coordTWs[0].term,a=e.coordTWs[1].term;let l;e.divideByTW&&"continuous"==e.divideByTW.q.mode&&(l=e.divideByTW.term);i+=`SELECT ax.sample AS sampleId, ax.value as x, ay.value AS y , ${l?"az.value AS z":"0 as z"}\n\t\t\tFROM anno_${s.type} ax \n\t\t\tJOIN anno_${a.type} ay on ax.sample = ay.sample and ay.term_id = '${a.id}' \n\t\t\t${l?`JOIN anno_${l.type} az on ax.sample = az.sample and az.term_id = '${l.id}' `:""}\n\t\t\tWHERE ax.term_id = '${s.id}'`,o&&(i+=` AND ax.sample IN ${o.CTEname}`);const c=e.ds.cohort.db.connection.prepare(i).all(),d=h().canDisplaySampleIds(t,n);for(const{sampleId:t,x:o,y:i,z:s}of c){var p;if(null!==(p=l)&&void 0!==p&&p.values&&s in l.values)continue;const a={sampleId:t,x:o,y:i,z:s};d&&(a.sample=n.sampleId2Name.get(t));const c=N(e.coordTWs[0].term,o)&&N(e.coordTWs[1].term,i);a&&c&&r.push(a)}return r}(t,e,o);else{if(!e.plotName)throw"Neither plot name or coordinates where provided";if(!o.cohort.scatterplots||!o.cohort.scatterplots.plots)throw"not supported";const t=o.cohort.scatterplots.plots.find((t=>t.name==e.plotName));if(!t)throw`plot not found with plotName ${e.plotName}`;const n=await async function(t,e,n){if(n.filterableSamples){let t=[],e=[];return n.referenceSamples&&(e=r(n.referenceSamples)),n.filterableSamples&&(t=r(n.filterableSamples)),[e,t]}if(n.gdcapi)throw"gdcapi not implemented yet";throw"do not know how to load data from this plot";function r(t){const e=[];for(const n of JSON.parse(JSON.stringify(t)))e.push(n);return e}}(0,0,t);s=n[0],a=n[1]}const l=[];e.coordTWs&&l.push(...e.coordTWs),e.colorTW&&l.push(e.colorTW),e.shapeTW&&l.push(e.shapeTW),e.divideByTW&&l.push(e.divideByTW);const d=await(0,r.getData)({filter:e.filter,terms:l},o,i);if(d.error)throw d.error;const p=await async function(t,e,n,r){const o={};for(const c of e){const e=n.samples[c.sampleId.toString()];if(!e&&r.colorTW){console.log(JSON.stringify(c)+" not in the database or filtered");continue}if(r.colorTW&&!_(e,r.colorTW)||r.shapeTW&&!_(e,r.shapeTW))continue;let f="Default";if(r.divideByTW&&"continuous"!=r.divideByTW.q.mode)if(c.z=0,"geneVariant"==r.divideByTW.term.type)f=x(!0,e,r.divideByTW)||x(!1,e,r.divideByTW);else{var i,s,a;const t=null===(i=e[r.divideByTW.term.id||r.divideByTW.term.name])||void 0===i?void 0:i.key;f=(null===(s=r.divideByTW.term.values)||void 0===s||null===(a=s[t])||void 0===a?void 0:a.label)||t}if(!o[f]){const e=t.map((t=>({...t,category:"Ref",shape:"Ref",z:0})));o[f]={samples:e,colorMap:{},shapeMap:{}}}var l,u;if(r.divideByTW||(c.z=0),c.cat_info={},c.hidden={},r.colorTW)"continuous"===(null===(l=r.colorTW)||void 0===l||null===(u=l.q)||void 0===u?void 0:u.mode)?e&&(c.category=e[r.colorTW.term.id||r.colorTW.term.name].value):w(e,c,r.colorTW,o[f].colorMap,"category");else c.category="Default";r.shapeTW?w(e,c,r.shapeTW,o[f].shapeMap,"shape"):c.shape="Ref",o[f].samples.push(c)}let f=0;for(const[t,e]of Object.entries(o))f=Math.max(f,Object.keys(e.colorMap).length);const d=(0,c.getColors)(f);for(const[i,s]of Object.entries(o)){var h,p,m;if(r.colorTW&&"continuous"!==r.colorTW.q.mode){let t=20;const e=c.schemeCategory20,o=Object.entries(s.colorMap);for(const[i,s]of o){var g,v,b;const o=null===(g=r.colorTW.term.values)||void 0===g?void 0:g[i];if(o&&"color"in o)s.color=o.color;else if(null!==(v=n.refs)&&void 0!==v&&null!==(b=v.byTermId[r.colorTW.term.id])&&void 0!==b&&b.bins){const o=n.refs.byTermId[r.colorTW.term.id].bins.find((t=>t.name===i));o?s.color=o.color:(s.color=e[t],t--)}else"geneVariant"!=r.colorTW.term.type&&(s.color=d(i))}}let o=1;for(const[t,e]of Object.entries(s.shapeMap))"shape"in e||(e.shape=o),o++;s.colorLegend=r.colorTW?q(s.colorMap,r.colorTW,n.refs):[["Default",{sampleCount:e.length,color:"blue"}]],s.colorLegend.push(["Ref",{sampleCount:t.length,color:null!==(h=r.colorTW)&&void 0!==h&&null!==(p=h.term.values)&&void 0!==p&&p.Ref?null===(m=r.colorTW.term.values)||void 0===m?void 0:m.Ref.color:y}]),s.shapeLegend=q(s.shapeMap,r.shapeTW,n.refs),s.shapeLegend.push(["Ref",{sampleCount:t.length,shape:0}])}return o}(s,a,d,e);n.send(p)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}function _(t,e){var n,r,o;const i=void 0!==(null==t||null===(n=t[(null==e||null===(r=e.term)||void 0===r?void 0:r.id)||(null==e||null===(o=e.term)||void 0===o?void 0:o.name)])||void 0===n?void 0:n.key);return i||console.log(JSON.stringify(t)+" missing value for the term "+JSON.stringify(e)),i}function w(t,e,n,r,o){let i=null;var s,a,l,u,f,d;"geneVariant"==n.term.type?function(t,e,n,r,o){if("geneVariant"==n.term.type){var i;const s=null==t||null===(i=t[n.term.name])||void 0===i?void 0:i.values;e.cat_info[o]=[];for(const t of s){const n=c.mclass[t.class],i=k(t);let s;e.cat_info[o].push(t),null==r[i]?(s={color:n.color,sampleCount:1,hasOrigin:"origin"in t},r[i]=s):(s=r[i],s.sampleCount=s.sampleCount+1,s.hasOrigin=s.hasOrigin||"origin"in t)}e[o]=x(!0,t,n)||x(!1,t,n),e[o]||(e[o]=k(s[0])),e.hidden[o]=!!n.q.hiddenValues&&e[o]in n.q.hiddenValues}}(t,e,n,r,o):(i=null==t||null===(s=t[n.id||n.term.name])||void 0===s?void 0:s.key,null!==(a=n.term.values)&&void 0!==a&&null!==(l=a[i])&&void 0!==l&&l.label&&(i=null===(u=n.term.values)||void 0===u||null===(f=u[i])||void 0===f?void 0:f.label),e.hidden[o]=!!n.q.hiddenValues&&(null==t||null===(d=t[n.id])||void 0===d?void 0:d.key)in n.q.hiddenValues,i&&(e[o]=i.toString(),null==r[i]?r[i]={sampleCount:1}:r[i].sampleCount++))}function x(t,e,n){var r;const o=null==e||null===(r=e[n.term.name])||void 0===r?void 0:r.values;for(const[e,r]of Object.entries(c.dt2label)){const r=o.find((t=>{const r=k(t),o=!(n.q.hiddenValues&&r in n.q.hiddenValues);return t.dt==e&&o}));if(!r)continue;if(t&&("WT"==r.class||"Blank"==r.class))continue;return k(r)}}function k(t){var e;const n=t.dt,r=c.mclass[t.class],o=null===(e=c.morigin[t.origin])||void 0===e?void 0:e.label,i=o?`${o[0]} ${c.dt2label[n]}`:c.dt2label[n];return`${r.label},${i}`}function q(t,e,n){var r;let o=[];if(!e||0==t.size)return o;if("geneVariant"==e.term.type)o=Object.entries(t),o.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0));else if(null!=n&&null!==(r=n.byTermId[e.term.id])&&void 0!==r&&r.bins){const r=n.byTermId[e.term.id].bins;for(const e of r)t[e.name]&&o.push([e.name,t[e.name]]);for(const[e,n]of Object.entries(t))o.some((t=>t[0]===e))||o.push([e,n])}else o=Object.entries(t),o.sort(((t,n)=>{var r;const o=null===(r=e.term.values)||void 0===r?void 0:r[t[0]];if(o&&"order"in o){const t=e.term.values[n[0]];return o.order<t.order?-1:1}return t[1].sampleCount>n[1].sampleCount?-1:1}));return o}function N(t,e){var n,r;return!(null!==(n=t.values)&&void 0!==n&&null!==(r=n[e])&&void 0!==r&&r.uncomputable)}async function S(t,e,n){const r=e.coords,o=i().join(l().cachedir,Math.random().toString()+".json");await g(o,JSON.stringify(r));let s=await m()(i().join(l().binpath,"utils/lowess.R"),[],[o]);s=JSON.parse(s);const a=[];for(const[t,e]of Object.entries(s.x))a.push([e,s.y[t]]);return n.send(a)}},394:(t,e,n)=>{"use strict";n.r(e),n.d(e,{listDbTables:()=>a,mayComputeTermtypeByCohort:()=>l,server_init_db_queries:()=>s});const r=n(334),o=n(3856).connect_db,{isUsableTerm:i}=n(1575);function s(t){if(!t.cohort)throw"ds.cohort missing";if(!t.cohort.db)throw"ds.cohort.db missing";if(!t.cohort.termdb)throw"ds.cohort.termdb missing";const e=t.cohort.db.file_fullpath||t.cohort.db.file;if(!e)throw"both file and file_fullpath missing";let n;try{console.log("Connecting",e),n=o(e),console.log(`DB connected for ${t.label}: ${e}`)}catch(t){throw`Cannot connect db ${e}: ${t.message||t}`}t.cohort.db.connection=n;const s=a(n);if(!s.has("terms"))throw"terms table missing";if(!s.has("ancestry"))throw"ancestry table missing";if(t.cohort.termdb.selectCohort&&!s.has("subcohort_terms"))throw"subcohort_terms table is missing while termdb.selectCohort is enabled";t.cohort.termdb.q={};const c=t.cohort.termdb.q;if(s.has("buildDate")&&(c.get_buildDate=n.prepare("select date from buildDate")),s.has("term2genes")){t.cohort.termdb.termMatch2geneSet=!0;const e=n.prepare("SELECT genes FROM term2genes WHERE id=?"),r=new Map;c.getGenesetByTermId=t=>{if(r.has(t))return r.get(t);const n=e.get(t);if(n&&n.genes){const e=JSON.parse(n.genes);return r.set(t,e),e}}}if(s.has("sampleidmap")){const e=new Map,r=new Map,o=n.prepare("SELECT * FROM sampleidmap");let i=0;for(const{id:t,name:n}of o.all())e.set(t,n),r.set(n,t),i++;if(c.id2sampleName=t=>e.get(t),c.sampleName2id=t=>r.get(t),t.cohort.termdb.selectCohort){const t=n.prepare("SELECT cohort,sample_count from cohorts").all(),e={};for(const n of t)e[n.cohort]=n.sample_count;c.getcohortsamplecount=t=>t?e[t]||0:i}else c.getcohortsamplecount=()=>i}if(s.has("category2vcfsample")){const t=n.prepare("SELECT * FROM category2vcfsample");let e;c.getcategory2vcfsample=()=>{if(e)return e;e=t.all();for(const t of e)t.q=JSON.parse(t.q),t.categories=JSON.parse(t.categories);return e}}if(s.has("alltermsbyorder")){const t=n.prepare("SELECT * FROM alltermsbyorder");let e;c.getAlltermsbyorder=()=>{if(e)return e;const n=t.all();e=[];for(const t of n){const n=c.termjsonByOneid(t.id);n&&e.push({group_name:t.group_name,term:n})}return e}}{const t=n.prepare("SELECT name, jsondata FROM terms WHERE id=?"),e=new Map;c.termjsonByOneid=n=>{if(e.has(n))return e.get(n);const r=t.get(n);if(r){const t=JSON.parse(r.jsondata);return t.id=n,t.name=r.name||t.name,e.set(n,t),t}}}{const t=n.prepare("select id from terms where parent_id=?"),e=new Map;c.termIsLeaf=n=>{if(e.has(n))return e.get(n);let r=!0;const o=t.get(n);return o&&o.id&&(r=!1),e.set(n,r),r}}{const t=n.prepare("SELECT id, name, jsondata, s.included_types, s.child_types\n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=?\n\t\t\tWHERE parent_id is null\n\t\t\tGROUP BY id\n\t\t\tORDER BY child_order ASC"),e=new Map;c.getRootTerms=(n="")=>{const r=n;if(e.has(r))return e.get(r);const o=t.all(n).map((t=>{const e=JSON.parse(t.jsondata);return e.id=t.id,e.name=t.name||e.name,e.included_types=t.included_types?t.included_types.split(","):["TO-DO-PLACEHOLDER"],e.child_types=t.child_types?t.child_types.split(","):[],e}));return e.set(r,o),o}}{const t=n.prepare("SELECT parent_id FROM terms WHERE id=?");{const e=new Map;c.termHasParent=n=>{if(e.has(n))return e.get(n);let r=!1;const o=t.get(n);return o&&o.parent_id&&(r=!0),e.set(n,r),r}}{const e=new Map;c.getTermParentId=n=>{if(e.has(n))return e.get(n);let r;const o=t.get(n);return o&&o.parent_id&&(r=o.parent_id),e.set(n,r),r}}{const t=new Map;c.getTermParent=e=>{if(t.has(e))return t.get(e);const n=c.getTermParentId(e);let r;return n&&(r=c.termjsonByOneid(n)),t.set(e,r),r}}}{const t=n.prepare("SELECT id, name, type, jsondata, s.included_types, s.child_types \n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=? \n\t\t\tWHERE id IN (SELECT id FROM terms WHERE parent_id=?)\n\t\t\tGROUP BY id\n\t\t\tORDER BY child_order ASC"),e=new Map;c.getTermChildren=(n,r="")=>{const o=n+";;"+r;if(e.has(o))return e.get(o);const i=t.all([r,n]);let s;return i&&(s=i.map((t=>{const e=JSON.parse(t.jsondata);return e.id=t.id,e.name=t.name||e.name,e.included_types=t.included_types?t.included_types.split(","):[],e.child_types=t.child_types?t.child_types.split(","):[],e}))),e.set(o,s),s}}{const t=n.prepare("SELECT id, name, jsondata, s.included_types\n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=?\n\t\t\tWHERE name LIKE ?");c.findTermByName=(e,n=10,r="",o=null,s=null,a=null)=>{const l=t.all([r,"%"+e+"%"]);if(l){const t=a||{equals:[],startsWith:[],startsWord:[],includes:[]};for(const n of l){if(!n.jsondata)continue;const r=n.name.toLowerCase(),o=JSON.parse(n.jsondata);o.id=n.id,o.name=n.name||o.name,o.included_types=n.included_types?n.included_types.split(","):[],s&&!i(o,s).has("plot")||(r===e?t.equals.push(o):r.startsWith(e)?t.startsWith.push(o):r.includes(" "+e)?t.startsWord.push(o):t.includes.push(o))}return[...t.equals,...t.startsWith,...t.startsWord,...t.includes].slice(0,n)}}}{const t=n.prepare("SELECT MAX(value) AS v FROM anno_integer WHERE term_id=?"),e=n.prepare("SELECT MAX(value) AS v FROM anno_float WHERE term_id=?"),r=new Map;c.findTermMaxvalue=(n,o)=>{if(r.has(n))return r.get(n);const i=(o?t:e).get(n);return i?(r.set(n,i.v),i.v):void 0}}{const t=n.prepare("SELECT ancestor_id FROM ancestry WHERE term_id=?"),e=new Map;c.getAncestorIDs=n=>{if(e.has(n))return e.get(n);const r=t.all(n).map((t=>t.ancestor_id));return e.set(n,r),r}}{const t=n.prepare("SELECT t.name FROM ancestry as a, terms as t WHERE a.term_id=? AND t.id=a.ancestor_id"),e=new Map;c.getAncestorNames=n=>{if(e.has(n))return e.get(n);const r=t.all(n).map((t=>t.name));return e.set(n,r),r}}{const t={categorical:n.prepare("SELECT value FROM anno_categorical WHERE term_id=?"),integer:n.prepare("SELECT value FROM anno_integer WHERE term_id=?"),float:n.prepare("SELECT value FROM anno_float WHERE term_id=?")},e={categorical:n.prepare("SELECT value FROM anno_categorical WHERE term_id=? AND sample=?"),integer:n.prepare("SELECT value FROM anno_integer WHERE term_id=? AND sample=?"),float:n.prepare("SELECT value FROM anno_float WHERE term_id=? AND sample=?")},r={categorical:n.prepare("SELECT value FROM anno_categorical a,sampleidmap s WHERE term_id=? AND s.name=?"),integer:n.prepare("SELECT value FROM anno_integer a,sampleidmap s WHERE term_id=? AND s.name=?"),float:n.prepare("SELECT value FROM anno_float a, sampleidmap s WHERE term_id=? AND s.name=?")};c.getSample2value=(n,o=null)=>{const i=c.termjsonByOneid(n);return o?"string"==typeof o?r[i.type].all(n,o):e[i.type].all(n,o):t[i.type].all(n)}}if(s.has("termhtmldef")){const t=n.prepare("SELECT jsonhtml FROM termhtmldef WHERE id=?"),e=new Map;c.getTermInfo=n=>{if(e.has(n))return e.get(n);const r=t.get(n);if(r){const t=JSON.parse(r.jsonhtml);return t.id=n,e.set(n,t),t}}}c.getSupportedChartTypes=e=>{var n;l(t);const o=null===(n=r.dsCredentials)||void 0===n?void 0:n[t.label],i={},s={};for(const n of t.cohort.termdb.termtypeByCohort){var a;if(n.type){var c,u;if(!(n.cohort in i))i[n.cohort]=new Set(["regression","summary"]),t.cohort.scatterplots&&i[n.cohort].add("sampleScatter"),s[n.cohort]=0,null!==(c=t.cohort.allowedChartTypes)&&void 0!==c&&c.includes("matrix")&&i[n.cohort].add("matrix"),(!o||null!==(u=o.embedders)&&void 0!==u&&u[e])&&i[n.cohort].add("dataDownload");null!==(a=r.features)&&void 0!==a&&a.draftChartTypes&&i[n.cohort].add(...r.features.draftChartTypes),"survival"!=n.type||i[n.cohort].has("survival")||i[n.cohort].add("survival"),"condition"!=n.type||i[n.cohort].has("cuminc")||i[n.cohort].add("cuminc"),"float"!=n.type&&"integer"!=n.type||(s[n.cohort]+=n.samplecount)}}for(const t in s)s[t]>1&&i[t].add("sampleScatter");for(const t in i)i[t]=[...i[t]];if(t.cohort.allowedChartTypes)for(const e in i)i[e]=i[e].filter((e=>t.cohort.allowedChartTypes.includes(e)));if(t.queries){if(t.queries.snvindel||t.queries.trackLst)for(const t in i)i[t].push("genomeBrowser");if(t.queries.geneExpression)for(const t in i)i[t].push("geneExpression")}return i}}function a(t){const e=t.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();return new Set(e.map((t=>t.name)))}function l(t){var e,n;if(t.cohort.termdb.termtypeByCohort){if(!Array.isArray(t.cohort.termdb.termtypeByCohort))throw"termtypeByCohort is not array"}else{if(null===(e=t.cohort)||void 0===e||null===(n=e.db)||void 0===n||!n.connection)throw"termtypeByCohort[] not set but cohort.db.connection missing";t.cohort.termdb.termtypeByCohort=t.cohort.db.connection.prepare("WITH c AS (\n\t\t\tSELECT cohort, term_id\n\t\t\tFROM subcohort_terms s\n\t\t\tGROUP BY cohort, term_id\n\t\t) \n\t\tSELECT cohort, type, count(*) as samplecount\n\t\tFROM terms t\n\t\tJOIN c ON c.term_id = t.id\n\t\tGROUP BY cohort, type").all()}}},3795:(t,e,n)=>{"use strict";n.r(e),n.d(e,{add_bcf_variant_filter:()=>h,validate:()=>d});const r=n(7147),o=n(1017),i=n(3856),s=n(2852),a=(n(7860),n(4521),n(334)),{compute_mclass:l}=n(3625),c="%CHROM\t%POS\t%REF\t%ALT[\t%TGT]\n",u="%POS\t%ID\t%REF\t%ALT\t%INFO[\t%TGT]\n",f=".";async function d(t,e,n,d){try{if(t.sumSamples)return await async function(t,e,n,r){if(!t.cacheid)throw"cacheid missing";if(a.cache_snpgt.fileNameRegexp.test(t.cacheid))throw"invalid cacheid";let l,c;if(n.track){if(l=n.track.vcf,!l)throw"ds.track.vcf missing"}else l=n.queries.snvindel.byrange._tk;if(t.filter){const e=new Set((await s.get_samples(t.filter,n)).map((t=>t.id)));if(0==e.size)throw"no samples from filter";c=l.samples.map((t=>e.has(t.name)))}else c=l.samples.map((t=>!0));const u=(await i.read_file(o.join(a.cache_snpgt.dir,t.cacheid))).split("\n"),f=new Set,d=[];for(let t=1;t<u.length;t++){const e=u[t].split("\t"),n=e[0],r=e[3],o={},i={};for(let t=a.cache_snpgt.sampleColumn;t<e.length;t++){const n=e[t];if(!n)continue;if(!c[t-a.cache_snpgt.sampleColumn])continue;f.add(l.samples[t-a.cache_snpgt.sampleColumn].name),i[n]=1+(i[n]||0);const r=n.split("/");for(const t of r)o[t]=1+(o[t]||0)}const s=[];for(const t in o)s.push({allele:t,count:o[t],isRef:t==r});d.push({snpid:n,alleles:s,gt2count:i})}return{numOfSampleWithAnyValidGT:f.size,snps:d}}(t,0,n);if(t.snptext)return await async function(t,e,n){if(!n.snp)throw"snp not supported by genome";if(!t.snptext)throw".snptext missing";const s=function(t){const e=[];for(const n of t.trim().split("\n")){const[t,r]=n.trim().split(/[\s\t]/);if(t&&t.startsWith("rs")){if(e.find((e=>e.rsid==t)))continue;const n={rsid:t,snpid:t};r&&(n.effectAllele=r),e.push(n)}else e.push({rsid:t,snpid:t,invalid:"INVALID RSID"})}return e}(t.snptext);if(!s.length)throw"no snps";await async function(t,e){for(const n of t)if(!n.invalid)if(n.chr&&"string"==typeof n.chr){const t=e.chrlookup[n.chr.toUpperCase()];if(!t){n.invalid=!0;continue}if(!Number.isInteger(n.pos)){n.invalid=!0;continue}if(n.pos<=0||n.pos>=t.len){n.invalid=!0;continue}}else if(n.rsid){const t=await i.query_bigbed_by_name(e.snp.bigbedfile,n.rsid),r=[];for(const n of t){const t=n.split("\t"),o=e.chrlookup[t[0].toUpperCase()];o&&o.major&&r.push(t)}if(0==r.length){n.invalid=!0;continue}const o=r[0];n.chr=o[0],n.pos=Number.parseInt(o[1]),n.dbsnpRef=o[4],n.dbsnpAlts=o[6].split(",").filter(Boolean)}else n.invalid=!0;if(!t.find((t=>!t.invalid)))throw"no valid variants"}(s,n);const l=await async function(t,e,n){let s;if(n.track){if(s=n.track.vcf,!s)throw"ds.track.vcf missing"}else s=n.queries.snvindel.byrange._tk;const l=new Set,u=[];for(const t of e){if(t.invalid)continue;let e;var f;if(s.chr2files){if(e=null===(f=s.chr2files)||void 0===f?void 0:f[t.chr].file,!e)throw"chr not in chr2files"}else if(s.chr2bcffile){if(e=s.chr2bcffile[t.chr],!e)throw"chr not in chr2bcffile"}else e=s.file||s.url;l.add(e);const n=(s.nochr?t.chr.replace("chr",""):t.chr)+"\t"+(t.pos+1);u.push(n)}const d=o.join(a.cachedir,await i.write_tmpfile(u.join("\n"))),h=o.join(a.cachedir,await i.write_tmpfile([...l].join("\n")));await i.get_lines_bigfile({isbcf:!0,args:["query","-R",d,"-f",c,"-v",h],dir:s.dir,callback:t=>{const n=t.split("\t"),r=(s.nochr?"chr":"")+n[0],o=n[1],i=n[2],a=n[3].split(","),l=e.find((t=>{if(t.chr==r&&t.pos===o-1&&t.dbsnpRef==i&&t.dbsnpAlts.some((t=>a.includes(t))))return t}));if(l){l.referenceAllele=i,l.altAlleles=a,l.gtlst=[];for(let t=4;t<n.length;t++)l.gtlst.push("."==n[t]?"":n[t])}}}),r.unlink(d,(()=>{})),r.unlink(h,(()=>{}));const p=["snpid\tchr\tpos\tref\talt\teff\t"+s.samples.map((t=>t.name)).join("\t")];for(const t of e)t.invalid||t.gtlst&&(p.push(t.snpid+"\t"+t.chr+"\t"+t.pos+"\t"+t.referenceAllele+"\t"+t.altAlleles.join(",")+"\t"+(t.effectAllele||"")+"\t"+t.gtlst.join("\t")),delete t.gtlst);const m=t.genome+"_"+t.dslabel+"_"+new Date/1+"_"+Math.ceil(1e4*Math.random());return await i.write_file(o.join(a.cache_snpgt.dir,m),p.join("\n")),m}(t,s,e);return{snps:s,cacheid:l}}(t,n,d);if(t.chr)return await async function(t,e,n){const r=Number(t.start),s=Number(t.stop);if(!Number.isInteger(r)||!Number.isInteger(s))throw"start/stop are not integers";if(r>s||r<0)throw"invalid start/stop coordinate";let c,d;if(e.track){if(c=e.track.vcf,!c)throw"ds.track.vcf missing";if(d=c.chr2bcffile[t.chr],!d)throw"chr not in chr2bcffile"}else{var p;if(c=e.queries.snvindel.byrange._tk,c.chr2files)d=null===(p=c.chr2files)||void 0===p?void 0:p[t.chr].file;else d=c.file||c.url;if(!d)throw"no bcf file"}const m=(c.nochr?t.chr.replace("chr",""):t.chr)+":"+r+"-"+s,g=["query",d,"-r",m,"-f",u];t.variant_filter&&h(t.variant_filter,g);const y={snps:[]},v=["snpid\tchr\tpos\tref\talt\teff\t"+c.samples.map((t=>t.name)).join("\t")];return await i.get_lines_bigfile({isbcf:!0,args:g,dir:c.dir,callback:(e,n)=>{if(y.snps.length>=1e3)return n.kill(),void(y.reachedVariantLimit=!0);const r=e.split("\t"),o=Number(r[0])-1,i=r[2],s=r[3].split(","),a=o+"."+i+"."+s.join(","),u={snpid:a,chr:t.chr,pos:o};l(c,i,s,u,r[4],r[1]);for(const t of u.mlst)t.vcf_id&&(t.mname=t.vcf_id);y.snps.push(u);const d=[a,t.chr,o,i,s.join(","),""];for(let t=5;t<r.length;t++)d.push(r[t]==f?"":r[t]);v.push(d.join("\t"))}}),y.cacheid=t.genome+"_"+t.dslabel+"_"+new Date/1+"_"+Math.ceil(1e4*Math.random()),await i.write_file(o.join(a.cache_snpgt.dir,y.cacheid),v.join("\n")),y}(t,n);throw"unknown how to validate"}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function h(t,e){const n=[];for(const e of t.lst)if(e.tvs.values){const t=e.tvs.isnot?"!=":"=";for(const r of e.tvs.values){const o=isNaN(r.key)?`"${r.key}"`:Number(r.key);n.push(`INFO/${e.tvs.term.id}${t}${o}`)}}else{if(!e.tvs.ranges)throw`unknown tvs spec for info_field: type=${e.type}, term.id=${e.tvs.term.id}`;for(const t of e.tvs.ranges)"start"in t&&n.push(`INFO/${e.tvs.term.id} ${t.startinclusive?">=":">"} ${t.start}`),"stop"in t&&n.push(`INFO/${e.tvs.term.id} ${t.stopinclusive?"<=":"<"} ${t.stop}`)}0!=n.length&&e.push("-i",n.join(" && "))}},2747:(t,e,n)=>{"use strict";n.r(e),n.d(e,{groupset:()=>s,values:()=>o});var r=n(2852);const o={getCTE(t,e,n,o,i){i.push(e.id);const s=(0,r.getUncomputableClause)(e,o);return i.push(...s.values),{sql:`${t} AS (\n\t\t\t\tSELECT sample,value as key, value as value\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id=? ${s.clause}\n\t\t\t)`,tablename:t}}};let i=0;const s={async getCTE(t,e,n,r,o,s){if(!s.groups)throw`.groups[] missing from a group-set, term.id='${e.id}'`;const a=[],l=[];for(const t of s.groups)if("values"==t.type)a.push(`SELECT sample, ? as key, value\n\t\t\t\t\tFROM anno_categorical a\n\t\t\t\t\tWHERE term_id=?\n\t\t\t\t\t\tAND value IN (${t.values.map((t=>"?")).join(",")})\n\t\t\t\t`),o.push(t.name,e.id,...t.values.map((t=>t.key.toString())));else{if("filter"!=t.type)throw`unsupported groupset type='${t.type}'`;if(!("activeCohort"in r.groupsetting)||!t.filter4activeCohort)throw`activeCohort error: cannot construct filter statement for group name='${t.name}', term.id=${e.id}`;{const s=t.filter4activeCohort[r.groupsetting.activeCohort],c=await getFilterCTEs(s,n,"xf"+i++);if(!c)throw`unable to construct a group='${t.name}' filter for term.id='${e.id}'`;l.push(c.filters),o.push(...c.values.slice(),t.name,t.name),a.push(`SELECT sample, ? AS key, ? AS value\n\t\t\t\t\t\tFROM ${c.CTEname}`)}}return{sql:`${l.length?l.join("\n,")+",":""}\n\t\t\t${t} AS (\n\t\t\t\t${a.join("\nUNION ALL\n")}\n\t\t\t)`,tablename:t}}}},6759:(t,e,n)=>{"use strict";function r(t){const e=t.cohort.db.connection.prepare("select * from features").all();return{cohorts:t.cohort.db.connection.prepare("select * from cohorts where cohort in (select distinct(cohort) from cohort_features)\n\t\t order by sample_count desc").all(),features:e,cfeatures:t.cohort.db.connection.prepare("select * from cohort_features").all()}}n.r(e),n.d(e,{getCohortsData:()=>r})},9723:(t,e,n)=>{"use strict";n.r(e),n.d(e,{binary:()=>i,cox:()=>a,cuminc:()=>s,discrete:()=>o});var r=n(2852);const o={getCTE(t,e,n,o,i){if(o.breaks&&o.breaks.length>0)return c(t,e,o,i);{const[n,s]=l(o);i.push(e.id);const a=(0,r.getUncomputableClause)(e,o);return i.push(...a.values),{sql:`${t} AS (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tsample,\n\t\t\t\t\t\tvalue as key,\n\t\t\t\t\t\tvalue\n\t\t\t\t\tFROM\n\t\t\t\t\t\t${"grade"==n?"precomputed_chc_grade":"precomputed_chc_child"}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id = ?\n\t\t\t\t\t\tAND ${s} = 1\n\t\t\t\t\t\t${a.clause}\n\t\t\t\t)`,tablename:t}}}},i={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"binary mode requires one break";return c(t,e,r,o)}},s={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"cuminc mode requires one break";return o.push(e.id,r.breaks[0]),{sql:`${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tevent AS key,\n\t\t\t\t\ttime AS value\n\t\t\t\tFROM\n\t\t\t\t\tprecomputed_cuminc\n\t\t\t\tWHERE\n\t\t\t\t\tterm_id = ?\n\t\t\t\t\tAND grade_cutoff = ?\n\t\t\t)`,tablename:t}}},a={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"cox mode requires one break";return o.push(e.id,r.breaks[0]),{sql:`${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tjson_object('event', event, 'label', IIF(event = 0, 'Censored', IIF(event = 1, 'Event (grade ${r.breaks[0]}-5)', IIF(event = -1, 'Event before entry into the cohort', 'NA')))) AS key,\n\t\t\t\t\tjson_object('age_start', age_start, 'age_end', age_end) AS value\n\t\t\t\tFROM\n\t\t\t\t\tprecomputed_cox\n\t\t\t\tWHERE\n\t\t\t\t\tterm_id = ?\n\t\t\t\t\tAND grade_cutoff = ?\n\t\t\t)`,tablename:t}}};function l(t){const e=t.bar_by_children?"child":t.bar_by_grade?"grade":"";if(!e)throw"must set the bar_by_grade or bar_by_children query parameter";const n=t.value_by_max_grade?"max_grade":t.value_by_most_recent?"most_recent":t.value_by_computable_grade?"computable_grade":"";if(!n)throw"must set a valid value_by_*";return[e,n]}function c(t,e,n,r){const[o,i]=l(n);if("grade"!=o)throw"breaks must be used on grade values";const s=[];for(const t of n.groups)s.push(`SELECT sample, ? as key, value\n\t\t\tFROM precomputed_chc_grade\n\t\t\tWHERE\n\t\t\t\tterm_id=?\n\t\t\t\tAND ${i}=1\n\t\t\t\tAND value IN (${t.values.map((t=>"?")).join(",")})\n\t\t`),r.push(t.name,e.id,...t.values.map((t=>t.toString())));return{sql:`${t} AS (\n\t\t\t${s.join("\nUNION ALL\n")}\n\t\t)`,tablename:t}}},2852:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getUncomputableClause:()=>v,get_bins:()=>_,get_numericMinMaxPct:()=>x,get_numericsummary:()=>w,get_rows:()=>p,get_rows_by_one_key:()=>h,get_samplecount:()=>f,get_samples:()=>u,get_summary:()=>g,get_summary_numericcategories:()=>d,get_term_cte:()=>m,interpolateSqlValues:()=>k});const r=n(9699),o=n(4048),i=n(5257).getFilterCTEs,s=n(827),a=n(2747),l=n(9723),c=n(610).s;n(334);async function u(t,e,n=!1){const r=await i(t,e),o=e.cohort.db.connection.prepare(r?`WITH ${r.filters} SELECT sample as id, name FROM ${r.CTEname} join sampleidmap on sample = sampleidmap.id`:"SELECT id, name FROM sampleidmap");let s;if(s=r?o.all(r.values):o.all(),n)return s;for(const t of s)delete t.name;return s}async function f(t,e){if(!t.filter)throw"filter missing";let n;if("object"==typeof t.filter)n=t.filter;else{if("string"!=typeof t.filter)throw"q.filter not obj or str";n=JSON.parse(t.filter)}const r=await i(n,e),o=`WITH ${r.filters}\n\t\tSELECT 'FILTERED_COHORT' as subcohort, count(distinct sample) as samplecount \n\t\tFROM ${r.CTEname}`;return e.cohort.db.connection.prepare(o).all(r.values)}async function d(t){const e=t.ds.cohort.termdb.q.termjsonByOneid(t.term_id);if("integer"!=e.type&&"float"!=e.type)throw"term is not numeric";if(!e.values)return[];const n=await i(t.filter,t.ds),r=n?n.values.slice():[];r.push(t.term_id);const o=[];for(const t in e.values)o.push("?"),r.push(Number(t));const s=`\n\t\t${n?"WITH "+n.filters:""}\n\t\tSELECT count(sample) AS samplecount,value\n\t\tFROM anno_${e.type}\n\t\tWHERE term_id=?\n\t\t${n?"AND sample IN "+n.CTEname:""}\n\t\tAND value IN (${o.join(",")})\n\t\tGROUP BY value`;return t.ds.cohort.db.connection.prepare(s).all(r)}async function h(t){if(!t.key)throw".key missing";if(!t.ds)throw".ds{} missing";const e=await i(t.filter,t.ds),n=e?e.values.slice():[],r=t.ds.cohort.termdb.q.termjsonByOneid(t.key);n.push(t.key);const o=`\n\t\t${e?"WITH "+e.filters:""}\n\t\tSELECT sample, value\n\t\tFROM anno_${r.type}\n\t\tWHERE term_id=?\n\t\t${e?" AND sample IN "+e.CTEname:""}`;return t.ds.cohort.db.connection.prepare(o).all(n)}async function p(t,e={}){"string"==typeof t.filter&&(t.filter=JSON.parse(decodeURIComponent(t.filter)));const n=Object.assign({withCTEs:!0,columnas:"t1.sample AS sample",groupby:""},e),r=await i(t.filter,t.ds),o=r?r.values.slice():[],s=await m(t,o,0,r),a=await m(t,o,1,r),l=await m(t,o,2,r),c=[s,a,l].map(((t,e)=>`\n\t\tSELECT sample, key, value, ${e} as termNum\n\t\tFROM ${t.tablename}\n\t\t${r?"WHERE sample IN "+r.CTEname:""}\n\t`)).join("\nUNION ALL\n"),u=`WITH\n\t\t${r?r.filters+",":""}\n\t\t${s.sql},\n\t\t${a.sql},\n\t\t${l.sql}\n\t\t${c}`;try{const e=t.ds.cohort.db.connection.prepare(u).all(o),i=new Map;for(const t of e){i.has(t.sample)||i.set(t.sample,{sample:t.sample});const e=i.get(t.sample),n=`key${t.termNum}`;n in e||(e[n]=[]),e[n].push(t)}const c=[],f=new Map;for(const e of i.values())if("key1"in e){if(t.term0_q&&t.term0_id){if(!("key0"in e))continue}else e.key0=[{key:"",value:""}];if(t.term2_q&&(t.term2_id||"samplelst"===t.term2.type)){if(!("key2"in e))continue}else e.key2=[{key:"",value:""}];e.rows=[];for(const t of e.key0)for(const n of e.key1)for(const r of e.key2)e.rows.push({sample:e.sample,key0:t.key,val0:t.value,key1:n.key,val1:n.value,key2:r.key,val2:r.value});for(const t of e.rows)if(n.groupby){if(!f.has(t[n.groupby])){const e=Object.assign({samplecount:0},t);c.push(e),f.set(t[n.groupby],e)}f.get(t[n.groupby]).samplecount++}else c.push(t)}return n.withCTEs?{lst:c,CTE0:s,CTE1:a,CTE2:l,filter:r}:c}catch(t){throw console.log("error in sql:\n",k(u,o)),t}}async function m(t,e,n,r,o=null){const i=o&&o.term||t[`term${n}`],u=i?i.id:t["term"+n+"_id"];if("samplelst"!=(null==i?void 0:i.type))if(o||1!=n){if(!u){const t="samplekey_"+n;return{tablename:t,sql:`${t} AS (\nSELECT null AS sample, '' as key, '' as value\n)`}}}else if(!u)throw"missing term1 id";const f=i&&i.type?i:t.ds.cohort.termdb.q.termjsonByOneid(u);if(!f)throw`no term found by id='${u}'`;let d=o&&o.q||t["term"+n+"_q"]||{};"string"==typeof d&&(d=JSON.parse(decodeURIComponent(d)));const h="samplekey_"+n;let p;if("categorical"==f.type){const n=b(f,d);p=await a[n?"groupset":"values"].getCTE(h,f,t.ds,d,e,n)}else if("integer"==f.type||"float"==f.type){const o="spline"==d.mode?"cubicSpline":d.mode||"discrete";p=await s[o].getCTE(h,f,t.ds,d,e,n,r)}else if("condition"==f.type){const n=d.mode||"discrete";p=await l[n].getCTE(h,f,t.ds,d,e)}else if("survival"==f.type)p=function(t,e,n,r,o){return r.push(e.id),{sql:`${t} AS (\n\t\t\tSELECT sample, exit_code as key, tte AS value\n\t\t\tFROM survival s\n\t\t\tWHERE s.term_id=?\n\t\t\t${o?"AND s.sample IN "+o.CTEname:""}\n\t\t)`,tablename:t}}(h,f,0,e,r);else{if("samplelst"!=f.type)throw"unknown term type";p=await c.getCTE(h,o||{term:f,q:d},e)}return p}async function g(t){const e=await p(t,{withCTEs:!0,groupby:"key1"}),n=[0,1,2],r={};for(const o of n)r[o]=y(t,o,e);for(const t of e.lst)for(const e of n)r[e](t);return e}function y(t,e,n){const r="key"+e,o="val"+e,i=t=>{delete t[r],delete t[o]},s=t["term"+e+"_id"];if(!s)return i;const a=t.ds.cohort.termdb.q.termjsonByOneid(s);if(!a)return i;const l=1!=e||t.term0_id||t.term2_id?r:"key",c=1!=e||t.term0_id||t.term2_id?r:"label";if("integer"==a.type||"float"==a.type){const i=n["CTE"+e],s="range"+(1!=e||t.term0_id||t.term2_id?e:"");return t=>{t[s]=i.name2bin.get(t[r]),t[c]=t[r],delete t[o],l!==r&&(t[l]=t[r],delete t[r])}}{const n=t["term"+e+"_q"];return e=>{e[c]=function(t,e,n,r){if("categorical"==e.type)return e.values&&t in e.values?e.values[t].label:t;if("condition"==e.type){var o;if(0==(null===(o=n.breaks)||void 0===o?void 0:o.length)){if(!(t in e.values))throw`unknown grade='${t}'`;return e.values[t].label}return t}if(e.values)return t in e.values?e.values[t].label:t;if("integer"==e.type||"float"==e.type)throw"should not work for numeric term";throw"unknown term type"}(e[r],a,n,t.ds),delete e[o],l!==r&&(e[l]=e[r],delete e[r])}}}function v(t,e,n=""){if(!t.values||!e.computableValuesOnly)return{values:[],clause:""};const r=Object.keys(t.values).filter((e=>t.values[e].uncomputable)),o=n?`${n}.value`:"value";return{values:r,clause:r.length?`AND ${o} NOT IN (${r.map((()=>"?")).join(",")})`:""}}function b(t,e){if(e.groupsetting&&!e.groupsetting.disabled&&e.groupsetting.inuse){if(Number.isInteger(e.groupsetting.predefined_groupset_idx)){if(e.groupsetting.predefined_groupset_idx<0)throw"q.predefined_groupset_idx out of bound";if(!t.groupsetting)throw"term.groupsetting missing when q.predefined_groupset_idx in use";if(!t.groupsetting.lst)throw"term.groupsetting.lst missing when q.predefined_groupset_idx in use";const n=t.groupsetting.lst[e.groupsetting.predefined_groupset_idx];if(!n)throw"q.predefined_groupset_idx out of bound";return n}if(e.groupsetting.customset)return e.groupsetting.customset;throw"do not know how to get groupset"}}function _(t,e,n,r,i){if("continuous"!=t.mode&&"spline"!=t.mode)return o.compute_bins(t,(t=>x(n,e,i,t)))}async function w(t,e,n,o=!1){const s="string"==typeof t.filter?JSON.parse(decodeURIComponent(t.filter)):t.filter;"integer"!=e.type&&"float"!=e.type||a.lst.find((t=>t.term.id==e.id&&"ranges"in t))||a.lst.push({type:"tvs",tvs:{term:e,ranges:_(t,e,n)}});const a=await i(s,n),l=[];a&&l.push(...a.values);const c=e.values?Object.keys(e.values).filter((t=>e.values[t].uncomputable)):[],u=`${a?"WITH "+a.filters+" ":""}\n\t\tSELECT value\n\t\tFROM anno_${e.type}\n\t\tWHERE\n\t\t${a?"sample IN "+a.CTEname+" AND ":""}\n\t\tterm_id=?\n\t\t${c.length?"AND value NOT IN ("+c.join(",")+")":""}`;l.push(e.id);const f=n.cohort.db.connection.prepare(u).all(l);if(!f.length)return null;f.sort(((t,e)=>t.value-e.value));const d=r.boxplot_getvalue(f);d.mean=f.length?f.reduce(((t,e)=>t+e.value),0)/f.length:0;let h=0;for(const t of f)h+=Math.pow(t.value-d.mean,2);return d.sd=Math.sqrt(h/(f.length-1)),d.min=f[0].value,d.max=f[f.length-1].value,o&&(d.values=f.map((t=>t.value))),d}function x(t,e,n,r=[]){const o=[];n&&o.push(...n.values),o.push(e.id);const i=e.values?Object.keys(e.values).filter((t=>e.values[t].uncomputable)):[],s=[],a=[],l=[];let c;for(const t of r)c="pct_"+t,s.push(`\n\t\t${c} AS (\n\t\t SELECT value\n\t\t FROM vals\n\t\t LIMIT 1\n\t\t OFFSET (\n\t\t SELECT cast ( x as int ) - ( x < cast ( x as int ))\n\t\t FROM (\n\t\t SELECT cast(?*pct as int) as x \n\t\t FROM p\n\t\t )\n\t\t )\n\t\t)`),o.push(t),a.push(c),l.push(`${c}.value AS ${"p"+t}`);const u=`WITH\n\t\t${n?n.filters+", ":""} \n\t\tvals AS (\n\t\t\tSELECT value\n\t\t\tFROM anno_${e.type}\n\t\t\tWHERE\n\t\t\t${n?"sample IN "+n.CTEname+" AND ":""}\n\t\t\tterm_id=?\n\t\t\t${i.length?"AND value NOT IN ("+i.join(",")+")":""}\n\t\t\tORDER BY value ASC\n\t\t),\n\t\tp AS (\n\t\t\tSELECT count(value)/100 as pct\n\t\t\tFROM vals\n\t\t)\n\t\t${s.length?",\n"+s.join(","):""}\n\t\tSELECT \n\t\t\tmin(vals.value) as vmin,\n\t\t\tmax(vals.value) as vmax\n\t\t\t${l.length?",\n"+l.join(",\n"):""} \n\t\tFROM vals ${a.length?","+a.join(","):""}`,f=t.cohort.db.connection.prepare(u).all(o),d=f.length?f[0]:{};return d.max=f[0].vmax,d.min=f[0].vmin,d}function k(t,e){const n=e.slice();let r;return t.split("").map((t=>{if("?"==t){r=t;const e=n.shift();return"string"==typeof e?`'${e}'`:e}return"\t"==t?"":"\n"!=t&&" "!=t||r!==t?(r=t,t):""})).join("")}},827:(t,e,n)=>{"use strict";n.r(e),n.d(e,{binary:()=>a,continuous:()=>o,cubicSpline:()=>i,discrete:()=>s});var r=n(2852);const o={getCTE(t,e,n,o,i,s,a){i.push(e.id);const l=(0,r.getUncomputableClause)(e,o);return i.push(...l.values),{sql:`${t} AS (\n\t\t\t\tSELECT \n\t\t\t\t\tsample,\n\t\t\t\t\tvalue as key, \n\t\t\t\t\tvalue\n\t\t\t\tFROM anno_${e.type}\n\t\t\t\tWHERE term_id=? ${l.clause}\n\t\t\t)`,tablename:t}}},i=o,s={getCTE(t,e,n,o,i,s,a){i.push(e.id);const l=(0,r.get_bins)(o,e,n,s,a),c=[],u=new Map;o.bin_size;for(const t of l)!("name"in t)&&t.label&&(t.name=t.label),u.set(t.name,t),c.push(`SELECT '${t.name}' AS name,\n\t\t\t\t${null==t.start?0:t.start} AS start,\n\t\t\t\t${null==t.stop?0:t.stop} AS stop,\n\t\t\t\t0 AS unannotated,\n\t\t\t\t${t.startunbounded?1:0} AS startunbounded,\n\t\t\t\t${t.stopunbounded?1:0} AS stopunbounded,\n\t\t\t\t${t.startinclusive?1:0} AS startinclusive,\n\t\t\t\t${t.stopinclusive?1:0} AS stopinclusive`);const f=[];if(e.values)for(const t in e.values){const n=e.values[t].uncomputable;if(o.computableValuesOnly&&n)continue;if(!o.computableValuesOnly&&!n)continue;f.push(t);const r=e.values[t];c.push(`SELECT '${r.label}' AS name,\n\t ${t} AS start,\n\t 0 AS stop,\n\t 1 AS unannotated,\n\t 0 AS startunbounded,\n\t 0 AS stopunbounded,\n\t 0 AS startinclusive,\n\t 0 AS stopinclusive`),u.set(r.label,{is_unannotated:!0,value:t,label:r.label})}const d="bin_defs_"+s,h=(0,r.getUncomputableClause)(e,o,"a");i.push(...h.values);return{sql:`${d} AS (\n\t\t\t\t${c.join("\nUNION ALL\n")}\n\t\t\t),\n\t\t\t${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tb.name AS key,\n\t\t\t\t\tvalue\n\t\t\t\tFROM\n\t\t\t\t\tanno_${e.type} a\n\t\t\t\tJOIN ${d} b ON\n\t\t\t\t\t( b.unannotated=1 AND value=b.start )\n\t\t\t\t\tOR\n\t\t\t\t\t(\n\t\t\t\t\t\tb.unannotated=0 AND\n\t\t\t\t\t\t${f.length?"value NOT IN ("+f.join(",")+") AND":""}\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tb.startunbounded = 1\n\t\t\t\t\t\t\tOR value > b.start\n\t\t\t\t\t\t\tOR (b.startinclusive=1 AND value = b.start)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tb.stopunbounded\n\t\t\t\t\t\t\tOR value < b.stop\n\t\t\t\t\t\t\tOR (b.stopinclusive=1 AND value = b.stop)\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\tWHERE\n\t\t\t\tterm_id=? ${h.clause}\n\t\t\t)`,tablename:t,name2bin:u,bins:l}}},a=s},610:(t,e,n)=>{"use strict";n.d(e,{s:()=>r});const r={getCTE(t,e,n){let r,o,i="";for(const[t,s]of e.q.groups.entries())"in"in s||(s.in=!0),r=s.values.map((t=>t.sampleId)),o=r.map((()=>"?")).join(","),i+=`SELECT id as sample, ? as key, ? as value\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE sample ${s.in?"":"NOT"} IN (${o})\n\t\t\t`,t!=e.q.groups.length-1&&(i+="UNION ALL "),n.push(s.name,s.name,...r);return{sql:`${t} AS (${i})`,tablename:t}}}},1468:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_survival:()=>c});const r=n(1017),{getData:o}=n(2974),i=n(3856).write_file,s=n(7147),a=n(334),l=n(9157);async function c(t,e){try{var n;if(!e.cohort)throw"cohort missing from ds";t.ds=e;const c=[];for(const e of[0,1,2]){const n="term"+e,r=n+"_id";"string"==typeof t[r]?(t[r]=decodeURIComponent(t[r]),t[n]=t.ds.cohort.termdb.q.termjsonByOneid(t[r])):"string"==typeof t[n]&&(t[n]=JSON.parse(decodeURIComponent(t[n])));const o=n+"_q";t[n]&&c.push({term:t[n],q:t[o]})}if(t.term2){if("survival"==t.term2.type&&"survival"==t.term1.type)throw"term and overlay are both survival terms - only one could be a survival term";if("survival"!=t.term2.type&&"survival"!=t.term1.type)throw"no survival terms, either the main term OR the overlay term must be a survival term"}else if("survival"!=t.term1.type)throw"non-survival term";if(t.term0&&"survival"==t.term0.type)throw"term0 must not be a survival term";const f=function(t){if(t.term1&&"survival"==t.term1.type)return 1;if(!t.term2)throw"term1.type is not survival and term2 is missing";if("survival"!=t.term2.type)throw"both term1 and term2 are not survival type";return 2}(t),d=t[`term${f}`],h=t["term"+(1==f?2:1)],p=await o({terms:c,filter:t.filter},e,t.genome);if(p.error)throw p.error;const m=function(t,e){return Object.values(t.samples).filter((t=>t[e.id])).sort(((t,n)=>t[e.id].value<n[e.id].value?-1:1))}(p,d),g={},y={chart:new Set,series:new Set};for(const e of m){const n=e[d.id],r=n.value;if(r<0)continue;const o=n.key;let i;if(h)if("id"in h){if(!(h.id in e))continue;i=e[h.id].key}else if("samplelst"==h.type){if(!(h.name in e))continue;i=e[h.name].key}else i=u(h,e);else i="*";y.series.add(i);const s=t.term0&&e[t.term0.id||t.term0.name]||{key:""};s.key in g||(g[s.key]=[],y.chart.add(s.key)),g[s.key].push({time:r,status:o,series:i})}const v=t.term2_id&&(null===(n=p.refs[t.term2.id])||void 0===n?void 0:n.bins)||[],b={keys:["chartId","seriesId","time","survival","lower","upper","nevent","ncensor","nrisk"],case:[],refs:{bins:v}};for(const t in g){const e=g[t],n=r.join(a.cachedir,Math.random().toString()+".json");await i(n,JSON.stringify(e));const o=await l(r.join(a.binpath,"utils/survival.R"),[],[n]),c=JSON.parse(o);for(const e of c.estimates){for(const t in e)e[t]="series"==t?"*"==e[t]?"":e[t]:Number(e[t]);b.case.push([t,e.series,e.time,e.surv,e.lower,e.upper,e.nevent,e.ncensor,e.nrisk])}c.tests&&(b.tests||(b.tests={}),b.tests[t]=c.tests),s.unlink(n,(()=>{}))}b.case.sort(((t,e)=>t[2]-e[2]));const _=function(t,e=[]){if(t){if("condition"==t.type&&t.values)return Object.keys(t.values).map(Number).sort(((t,e)=>t-e)).map((e=>t.values[e].label));if(t.values)return Object.keys(t.values).sort(((e,n)=>"order"in t.values[e]&&"order"in t.values[n]?t.values[e].order-t.values[n].order:0)).map((e=>t.values[e].label))}return e.map((t=>t.name?t.name:t.label))}(t.term2,v?v.map((t=>t.name?t.name:t.label)):[]);return b.refs.orderedKeys={chart:[...y.chart].sort(),series:[...y.series].sort(_?(t,e)=>_.indexOf(t)-_.indexOf(e):void 0)},b}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function u(t,e){const n=t.name;if("geneVariant"==t.type){if(!e[n]||!e[n].values)return"Wildtype";const t=e[n].values.filter((t=>"Blank"!=t.class));return t.find((t=>"WT"!=t.class))?`${n} Variant`:t.find((t=>"WT"==t.class))?`${n} Wildtype`:e[n].values.length>t.length?"Not tested":"Not sure"}throw`cannot get series key for term='${n}'`}},4603:(t,e,n)=>{"use strict";n.d(e,{g:()=>v});var r=n(7147),o=n(2554),i=n(334),s=n.n(i),a=n(9157),l=n.n(a),c=n(1017),u=n.n(c),f=n(3856),d=n(2974),h=n(6718),p=n(7011),m=n(7027),g=n(5684);function y(t){let e=t;"string"==typeof t[0]&&(e=t.map(Number));const n=e.length;function r(t){return t.reduce(((t,e)=>t+e))/n}const o=(0,m.Z)(e,50),i=e.map((t=>(t-r(e))**2)).reduce(((t,e)=>t+e),0)/(n-1),s=Math.sqrt(i),a=(0,m.Z)(e,25),l=(0,m.Z)(e,75),c=l-a,u=Math.min(...e),f=Math.max(...e);return{values:[{id:"total",label:"Total",value:n},{id:"min",label:"Minimum",value:(0,g.Z)(u,2)},{id:"p25",label:"1st quartile",value:(0,g.Z)(a,2)},{id:"median",label:"Median",value:(0,g.Z)(o,2)},{id:"mean",label:"Mean",value:(0,g.Z)(r(e),2)},{id:"p75",label:"3rd quartile",value:(0,g.Z)(l,2)},{id:"max",label:"Maximum",value:(0,g.Z)(f,2)},{id:"SD",label:"Standard deviation",value:(0,g.Z)(s,2)},{id:"variance",label:"Variance",value:(0,g.Z)(i,2)},{id:"IQR",label:"Inter-quartile range",value:(0,g.Z)(c,2)}]}}async function v(t,e,n,i){const a=n.cohort.termdb.q.termjsonByOneid(t.termid);if(!a)throw".termid invalid";if("integer"!=a.type&&"float"!=a.type)throw"term type is not integer/float.";const c=[{id:t.termid,term:a,q:{mode:"continuous"}}];t.divideTw&&(null===t.divideTw||void 0===t.divideTw||"object"!=typeof t.divideTw||"id"in t.divideTw||(t.divideTw.id=t.divideTw.term.name,t.divideTw.term.id=t.divideTw.term.name),c.push(t.divideTw),t.term2_q=t.divideTw.q);const m=await(0,d.getData)({terms:c,filter:t.filter,currentGeneNames:t.currentGeneNames},n,i);if(m.error)throw m.error;t.scale&&function(t,e,n){if(!t.scale)return;const r=Number(t.scale);for(const[t,a]of Object.entries(e.samples)){var o,i,s;a[n.id]&&(null!==(o=n.values)&&void 0!==o&&null!==(i=o[null===(s=a[n.id])||void 0===s?void 0:s.value])&&void 0!==i&&i.uncomputable||(a[n.id].key=a[n.id].key/r,a[n.id].value=a[n.id].value/r))}}(t,m,a);const v=function(t,e,n,r){const o="log"==t.unit,i=new Map;let s=1/0,a=-1/0;const l={};let c=0;for(const[t,_]of Object.entries(e.samples)){var u,f,d;const t=(0,g.Z)(null===(u=_[n.id])||void 0===u?void 0:u.value,1);if(Number.isFinite(t))if(null!==(f=n.values)&&void 0!==f&&null!==(d=f[t])&&void 0!==d&&d.uncomputable){const e=n.values[t].label;l[e]=(l[e]||0)+1}else if(o&&t<=0)c++;else if(s>t&&(s=t),a<t&&(a=t),"log"===o&&0===s&&(s=Math.max(s,t)),r){var h,p,m,y,v,b,w;if(!_[null==r?void 0:r.id])continue;if(null!==(h=r.term)&&void 0!==h&&null!==(p=h.values)&&void 0!==p&&null!==(m=p[null===(y=_[r.id])||void 0===y?void 0:y.key])&&void 0!==m&&m.uncomputable){var x,k;const t=null===(x=r.term.values[null===(k=_[r.id])||void 0===k?void 0:k.value])||void 0===x?void 0:x.label;l[t]=(l[t]||0)+1}i.has(null===(v=_[r.id])||void 0===v?void 0:v.key)||i.set(null===(b=_[r.id])||void 0===b?void 0:b.key,[]),i.get(null===(w=_[r.id])||void 0===w?void 0:w.key).push(t)}else i.has("All samples")||i.set("All samples",[]),i.get("All samples").push(t)}return{key2values:i,minMaxValues:{min:s,max:a},uncomputableValueObj:_(l),skipNonPositiveCount:c}}(t,m,a,t.divideTw),w=function(t,e,n){const r=n.divideTw,o={min:t.minMaxValues.min,max:t.minMaxValues.max,plots:[],pvalues:[],plotThickness:Number,uncomputableValueObj:Object.keys(t.uncomputableValueObj).length>0?t.uncomputableValueObj:null};for(const[n,f]of function(t,e,n){var r,o,i,s;const a=null===(r=t.refs.byTermId[null==n||null===(o=n.term)||void 0===o?void 0:o.id])||void 0===r?void 0:r.keyOrder;return e=new Map([...e].sort(a?(t,e)=>a.indexOf(t[0])-a.indexOf(e[0]):"categorical"===(null==n||null===(i=n.term)||void 0===i?void 0:i.type)?(t,e)=>e[1].length-t[1].length:"condition"===(null==n||null===(s=n.term)||void 0===s?void 0:s.type)?(t,e)=>t[0]-e[0]:(t,e)=>t.toString().replace(/[^a-zA-Z0-9<]/g,"").localeCompare(e.toString().replace(/[^a-zA-Z0-9<]/g,""),void 0,{numeric:!0})))}(e,t.key2values,r)){var i,s,a,l,c,u;if(r)o.plots.push({label:(null==r||null===(i=r.term)||void 0===i||null===(s=i.values)||void 0===s||null===(a=s[n])||void 0===a?void 0:a.label)||n,values:f,seriesId:n,plotValueCount:null==f?void 0:f.length,color:(null==r||null===(l=r.term)||void 0===l||null===(c=l.values)||void 0===c||null===(u=c[n])||void 0===u?void 0:u.color)||null,divideTwBins:b(r,e).has(n)?b(r,e).get(n):null,uncomputableValueObj:Object.keys(t.uncomputableValueObj).length>0?t.uncomputableValueObj:null});else o.plots.push({label:"All samples",values:f,plotValueCount:f.length})}o.plots.length>=1&&(o.plotThickness=n.plotThickness?Number(n.plotThickness):function(t,e){const n=e.screenThickness/t.plots.length;return Math.round(Math.min(n,e.maxThickness))}(o,n));return o}(v,m,t);await async function(t,e){if(!t)return;const n={},o=e.plots.length;for(let t=0;t<o;t++){const{label:r,values:i}=e.plots[t],s=r.split(",")[0].trim();for(let r=t+1;r<o;r++){const t=i,o=e.plots[r].values;n[`${s}, ${e.plots[r].label.split(",")[0].trim()}`]={group1values:t,group2values:o}}}const i=u().join(s().cachedir,Math.random().toString()+".json");await f.write_file(i,JSON.stringify(n));const a=await l()(u().join(s().binpath,"utils/wilcoxon.R"),[],[i]);(0,r.unlink)(i,(()=>{}));for(const[t,n]of Object.entries(JSON.parse(a))){const r=t.split(",");e.pvalues.push([{value:r[0].trim()},{value:r[1].trim()},{html:n}])}}(t.divideTw,w),function(t,e,n){t.radius||(t.radius=5);if(t.radius<=0)throw"q.radius is not a number";t.radius=+t.radius;t.strokeWidth||(t.strokeWidth=.2);const r=4*t.radius;let i;i="log"==t.unit?(0,o.scaleLog)().base(n.cohort.termdb.logscaleBase2?2:10).domain([e.min,e.max+e.max]).range("horizontal"===t.orientation?[0,t.svgw]:[t.svgw,0]):(0,o.scaleLinear)().domain([e.min,e.max+e.max/r]).range("horizontal"===t.orientation?[0,t.svgw]:[t.svgw,0]);const[s,a]="horizontal"==t.orientation?[t.svgw*t.devicePixelRatio,r*t.devicePixelRatio]:[r*t.devicePixelRatio,t.svgw*t.devicePixelRatio],l=t.radius/t.devicePixelRatio,c=l*Math.PI;for(const n of e.plots){const e=(0,h.createCanvas)(s,a),r=e.getContext("2d");r.strokeStyle="rgba(0,0,0,0.8)",r.lineWidth=t.strokeWidth/t.devicePixelRatio,r.globalAlpha=.5,r.fillStyle="#ffe6e6",1!=t.devicePixelRatio&&r.scale(t.devicePixelRatio,t.devicePixelRatio),"rug"===t.datasymbol?n.values.forEach((e=>{r.beginPath(),"horizontal"==t.orientation?(r.moveTo(+i(e),0),r.lineTo(+i(e),2*l)):(r.moveTo(0,+i(e)),r.lineTo(2*l,+i(e))),r.stroke()})):"bean"===t.datasymbol&&n.values.forEach((e=>{r.beginPath(),"horizontal"===t.orientation?r.arc(+i(e),t.radius,l,0,c):r.arc(t.radius,+i(e),l,0,c),r.fill(),r.stroke()})),n.src=e.toDataURL();const o=(0,p.violinBinsObj)(i,n);n.bins=o.bins,n.biggestBin=Math.max(...o.bins0.map((t=>t.length))),n.summaryStats=y(n.values),delete n.values}}(t,w,n),e.send(w)}function b(t,e){var n,r;const o=new Map,i=null===(n=e.refs.byTermId[null==t||null===(r=t.term)||void 0===r?void 0:r.id])||void 0===n?void 0:n.bins;if(i)for(const t of i)o.set(t.label,t);return o}function _(t){return Object.fromEntries(Object.entries(t).sort((([,t],[,e])=>t-e)))}},3856:(t,n,r)=>{const o=r(7147),i=r(1017),s=r(2081).spawn,a=r(4521),l=r(2273),c=r(6819),u=r(4809).default,f=r(5890),d=r(334);r(2781).Readable;n.serverconfig=d;const h=d.tabix,p=d.samtools,m=d.bcftools,g=d.bigBedToBed,y=d.bigBedNamedItems,v=d.bigBedInfo;function b(t){const e=t.split("://");return 2!=e.length?["improper url"]:e[0].length<3?["protocol string length too short"]:e[1].length<5?["body string length too short"]:[null,e[0],e[1]]}function _(t){return new Promise(((e,n)=>{o.access(t,o.constants.F_OK,(t=>{t&&e(!0),e(!1)}))}))}function w(t){return new Promise(((e,n)=>{o.access(t,o.constants.R_OK,(t=>{t&&e(!0),e(!1)}))}))}function x(t,e){return new Promise(((n,r)=>{o.writeFile(t,e,(t=>{t&&r("cannot write"),n()}))}))}function k(t){return new Promise(((e,n)=>{o.readFile(t,{encoding:"utf8"},((r,o)=>{r&&n("cannot read file: "+t),e(o)}))}))}n.cache_index=async(t,e)=>{if(!t)throw".gz file URL missing";if("string"!=typeof t)throw".gz file URL not string";if(e&&"string"!=typeof e)throw"index URL not string";const[n,r,s]=b(t);if(n)throw".gz file URL error: "+n;const a=i.join(d.cachedir,r,s);try{await o.promises.stat(a)}catch(n){if("ENOENT"!=n.code)throw"stating gz url dir: "+n.code;try{await o.promises.mkdir(a,{recursive:!0})}catch(n){throw"url dir: cannot mkdir"}}if(!e)return a;{const[t,r,s]=b(e);if(t)throw"indexl url error: "+t;const l=i.join(a,i.basename(s));try{return await o.promises.stat(l),a}catch(n){if("ENOENT"==n.code)return await async function(t,e){try{const i=await u(t);if(200!=i.status)throw"index file not accessible from url with status code "+i.status;await(n=i.body,r=e,new Promise(((t,e)=>{const i=o.createWriteStream(r);n.pipe(i),n.on("end",(()=>t()))})))}catch(t){throw"cannot download from url"}var n,r}(e,l),a;throw"stating indexl url file: "+n.code}}},n.file_is_readable=async t=>{try{await o.promises.stat(t)}catch(e){const n=d.debugmode?`file='${t}'`:"";if("EACCES"==e.code)throw`Permission denied ${n}`;if("ENOENT"==e.code)throw`No such file or directory ${n}`;if("EPERM"==e.code)throw`Operation not permitted ${n}`;throw`cannot access file (' + e.code + ') ${n}`}},n.init_one_vcf=async function(t,e,r){let o;if(t.file)t.file.startsWith(d.tpmasterdir)||(t.file=i.join(d.tpmasterdir,t.file)),o=t.file,await n.validate_tabixfile(t.file);else{if(!t.url)throw"no file or url given for vcf file";o=t.url,t.dir=await utils.cache_index(t.url,t.indexURL)}const[s,a,l,c]=r?await n.get_header_bcf(o,t.dir):await n.get_header_vcf(o,t.dir);if(c)throw console.log(c.join("\n")),"got above errors parsing vcf";t.info=s,t.format=a,t.samples=l,await n.tabix_is_nochr(o,t.dir,e)&&(t.nochr=!0)},n.validate_tabixfile=async function(t){if(!t.endsWith(".gz"))throw"tabix file not ending with .gz";if(await _(t))throw t+" file not exist";if(await w(t))throw".gz file not readable";const e=t+".tbi";if(await _(e)){const e=t+".csi";if(await _(e))throw"neither .tbi .csi index file exist for "+t;if(await w(e))throw".csi index file not readable"}else if(await w(e))throw".tbi index file not readable"},n.tabix_is_nochr=async function(t,e,r){const o=[];return await n.get_lines_bigfile({args:["-l",t],dir:e,callback:t=>{o.push(t)}}),l.contigNameNoChr(r,o)},n.file_not_readable=w,n.file_not_exist=_,n.get_header_tabix=async(t,e)=>{const r=[];return await n.get_lines_bigfile({args:["-H",t],dir:e,callback:t=>{r.push(t)}}),r},n.get_header_bcf=(t,e)=>new Promise(((n,r)=>{const o=s(m,["view","-h",t],{cwd:e}),i=[];o.stdout.on("data",(t=>i.push(t))),o.on("close",(()=>{n(c.vcfparsemeta(i.join("").trim().split("\n")))}))})),n.get_header_vcf=async(t,e)=>c.vcfparsemeta(await n.get_header_tabix(t,e)),n.get_lines_bigfile=function({args:t,dir:e,callback:n,isbcf:r,isbam:o}){if(!t)throw"args is missing";if(!Array.isArray(t))throw"args[] is not array";if(0==t.length)throw"args[] empty array";if(!n)throw"callback is missing";if("function"!=typeof n)throw"callback() not a function";return new Promise(((i,l)=>{const c=s(r?m:o?p:h,t,{cwd:e}),u=a.createInterface({input:c.stdout}),f=[];u.on("line",(t=>n(t,c))),c.stderr.on("data",(t=>f.push(t))),c.on("close",(()=>{const t=f.join("").trim();t&&!t.startsWith("[E::idx_test_and_fetch]")&&l(t),i()}))}))},n.write_file=x,n.write_tmpfile=async function(t){const e=Math.random().toString();return await x(i.join(d.cachedir,e),t),e},n.read_file=k,n.get_fasta=async(t,e)=>{if("NA"==t.genomefile){const t=e.split(/[:-]/),n=[];for(let e=Number(t[1]);e<=Number(t[2]);e++)n.push("N");return`>${e}\n${n.join("")}`}const r=[];return await n.get_lines_bigfile({isbam:!0,args:["faidx",t.genomefile,e],callback:t=>r.push(t)}),r.join("\n")},n.connect_db=function(t,e={}){const n="/"==t[0]?t:i.join(d.tpmasterdir,t);try{return new f(n,Object.assign({readonly:!0,fileMustExist:!0},e))}catch(t){throw`error connecting to ${n}: ${t}`}};const q=new Set(["Homozygous reference","Homozygous alternative","Heterozygous"]);n.genotype_type_set=q,n.genotype_types={href:"Homozygous reference",halt:"Homozygous alternative",het:"Heterozygous"},n.loadfile_ssid=async function(t,e){const n=await k(i.join(d.cachedir_ssid,t)),r=new Map,o=new Map;for(const t of n.trim().split("\n")){if(!t)continue;const[n,i]=t.split("\t");if(!i)continue;if(!q.has(n))throw"unknown hardcoded genotype label: "+n;const s=i.split(",").map((t=>Number(t))),a=e?s.filter((t=>e.has(t))):s;for(const t of a)r.set(t,n);o.set(n,new Set(a))}return[r,o]},n.run_fdr=async function(t){const n=i.join(d.cachedir,Math.random().toString()),r=n+".out";await x(n,t.join("\t")),await function(t,n){return new Promise(((r,o)=>{const a=s("Rscript",[i.join(d.binpath,"utils/fdr.R"),t,n]);a.on("close",(()=>r())),a.on("error",(()=>o(e)))}))}(n,r);const a=await k(r);return o.unlink(n,(()=>{})),o.unlink(r,(()=>{})),a.trim().split("\n").map(Number)},n.stripJsScript=function(t){return t.replace(/\<script|\bon[\w]{1,38}\b[\ \t\n]*\=/gi," _")},n.bam_ifnochr=async(t,e,r)=>{const o=[];if(await n.get_lines_bigfile({isbam:!0,args:["view","-H",t],dir:r,callback:t=>o.push(t)}),0==o.length)throw"cannot list bam header lines";const i=[];for(const t of o){if(!t.startsWith("@SQ"))continue;const e=t.split("\t")[1];e||reject("2nd field missing from @SQ line");const n=e.split(":");"SN"!=n[0]&&reject('@SQ line 2nd field is not "SN" but '+n[0]),n[1]||reject("@SQ line no value for SN"),i.push(n[1])}return l.contigNameNoChr(e,i)},n.query_bigbed_by_coord=function(t,e,n,r){return new Promise(((o,i)=>{const a=s(g,[`-chrom=${e}`,`-start=${n}`,`-end=${r}`,t,"stdout"]),l=[],c=[];a.stdout.on("data",(t=>l.push(t))),a.stderr.on("data",(t=>c.push(t))),a.on("close",(t=>{0!==t&&i(`bigBed query exited with non-zero status and this standard error:\n${c.join("")}`),c.length>0&&i(c.join(""));const e=l.join("").trim();o(e?e.split("\n"):[])}))}))},n.query_bigbed_by_name=function(t,e){return new Promise(((n,r)=>{const o=s(y,[t,e,"stdout"]),i=[],a=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>a.push(t))),o.on("close",(t=>{0!==t&&r(`bigBed query exited with non-zero status and this standard error:\n${a.join("")}`),a.length>0&&r(a.join(""));const e=i.join("").trim();n(e?e.split("\n"):[])}))}))},n.getRandomInt=function(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1)+t)},n.sleep=function(t){return new Promise((e=>setTimeout(e,t)))},n.testIfFileIsBigbed=async function(t){return new Promise(((e,n)=>{const r=s(v,[t]),o=[],i=[];r.stdout.on("data",(t=>o.push(t))),r.stderr.on("data",(t=>i.push(t))),r.on("close",(t=>{const n=i.join("");n&&(n.includes("is not a big bed file")||n.includes("Couldn't open"),e(!1));o.join("").trim().startsWith("version")&&e(!0)}))}))}},8206:(t,e,n)=>{"use strict";n.r(e),n.d(e,{byExpectedVal:()=>a,byReqKey:()=>s,middleware:()=>i});const r=n(9699),o={};function i(t,e,n){try{const e=t.query;for(const t in e)t in s&&(e[t]=s[t](e[t]));n()}catch(n){r.catch(t,e,n.message||n)}}r.catch=function(t,e,n){const r=+new Date;if(t.ip in o||(o[t.ip]={time:r,count:0}),r-o[t.ip].time>3e4)delete o[t.ip];else{if(o[t.ip].count>10)return void e.send({error:"busy"});o[t.ip].count++}throw e.send({error:n}),new Date+" "+n};const s={genome(t){if("string"!=typeof t)throw"genome should be a non-empty string";if(/\s+/.test(t))throw"invalid genome character";return t},chr(t){if("string"!=typeof t)throw"chr should be a string";if(/\s+/.test(t))throw"invalid chr character";return t},start:t=>Number(t),term(t){const e="string"==typeof t?JSON.parse(t):t;if(!("id"in e))throw"missing termWrapper.id";if(!("q"in e))throw"missing termWrapper.q";return e}},a={alphaNumeric(t,e,n){try{if(!e)throw`empty ${t} value`;if("string"!=typeof e)throw`${t} should be a non-empty alphanumeric string`;if(/\s+/.test(e))throw`invalid ${t} character`;return e}catch(t){throw n.send({error:t}),t}}}},3625:(t,e,n)=>{"use strict";n.r(e),n.d(e,{compute_mclass:()=>a});const{dissect_INFO:r}=n(9380),{parse_CSQ:o}=n(4298),{getVariantType:i}=n(736),{vcfcopymclass:s}=n(2273);function a(t,e,n,a,l,c,u){var f;const d=r(l);for(const e in t.info)if("A"==t.info[e].Number&&e in d&&(d[e]=d[e].split(",")),t.info[e].separator&&e in d){const n=d[e].split(t.info[e].separator);n.length>1&&(d[e]=n)}a.mlst=n.map((t=>{const[n,r,o]=function(t,e,n){for(;e.length>1&&n.length>1&&e[e.length-1]==n[n.length-1];)e=e.substring(0,e.length-1),n=n.substring(0,n.length-1);for(;e.length>1&&n.length>1&&e[0]==n[0];)e=e.substring(1),n=n.substring(1),t++;return[t,e,n]}(a.pos,e,t),s={allele_original:t,ref:r,alt:o,pos:n,type:i(r,o)};return c&&"."!=c&&(s.vcf_id=c),s})),null!==(f=t.info)&&void 0!==f&&f.CSQ&&d.CSQ&&o(d.CSQ,t.info.CSQ.csqheader,a);const h={};u&&(h.usegm={isoform:u});for(const[n,r]of a.mlst.entries()){s(r,h),delete r.csq,r.mname||(r.mname="."!=c?c:a.pos+":"+e+">"+r.allele_original),r.altAlleleIdx=n+1,r.info={};for(const e in d){var p,m;"A"==(null===(p=t.info)||void 0===p||null===(m=p[e])||void 0===m?void 0:m.Number)?r.info[e]=d[e][n]:r.info[e]=d[e]}}}},1271:t=>{"use strict";t.exports=require("@sjcrh/proteinpaint-rust")},5890:t=>{"use strict";t.exports=require("better-sqlite3")},3986:t=>{"use strict";t.exports=require("body-parser")},6718:t=>{"use strict";t.exports=require("canvas")},7455:t=>{"use strict";t.exports=require("compression")},9710:t=>{"use strict";t.exports=require("cookie-parser")},6860:t=>{"use strict";t.exports=require("express")},4308:t=>{"use strict";t.exports=require("express-basic-auth")},6452:t=>{"use strict";t.exports=require("got")},7219:t=>{"use strict";t.exports=require("image-size")},9344:t=>{"use strict";t.exports=require("jsonwebtoken")},8171:t=>{"use strict";t.exports=require("jstat")},9292:t=>{"use strict";t.exports=require("lazy")},6828:t=>{"use strict";t.exports=require("minimatch")},4809:t=>{"use strict";t.exports=require("node-fetch")},5346:t=>{"use strict";t.exports=require("partjson")},4269:t=>{"use strict";t.exports=require("url")},6464:t=>{"use strict";t.exports=require("util")},2081:t=>{"use strict";t.exports=require("child_process")},6113:t=>{"use strict";t.exports=require("crypto")},7147:t=>{"use strict";t.exports=require("fs")},3685:t=>{"use strict";t.exports=require("http")},5687:t=>{"use strict";t.exports=require("https")},1017:t=>{"use strict";t.exports=require("path")},4521:t=>{"use strict";t.exports=require("readline")},2781:t=>{"use strict";t.exports=require("stream")},9263:(t,e,n)=>{"use strict";function r(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}n.d(e,{Z:()=>r})},5519:(t,e,n)=>{"use strict";n.d(e,{Nw:()=>l,ZP:()=>u,ZR:()=>c,ml:()=>a});var r=n(9263),o=n(3292),i=n(3745);const s=(0,o.Z)(r.Z),a=s.right,l=s.left,c=(0,o.Z)(i.Z).center,u=a},3292:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i});var r=n(9263),o=n(788);function i(t){let e,n,i;function a(t,r,o=0,i=t.length){if(o<i){if(0!==e(r,r))return i;do{const e=o+i>>>1;n(t[e],r)<0?o=e+1:i=e}while(o<i)}return o}return 2!==t.length?(e=r.Z,n=(e,n)=>(0,r.Z)(t(e),n),i=(e,n)=>t(e)-n):(e=t===r.Z||t===o.Z?t:s,n=t,i=t),{left:a,center:function(t,e,n=0,r=t.length){const o=a(t,e,n,r-1);return o>n&&i(t[o-1],e)>-i(t[o],e)?o-1:o},right:function(t,r,o=0,i=t.length){if(o<i){if(0!==e(r,r))return i;do{const e=o+i>>>1;n(t[e],r)<=0?o=e+1:i=e}while(o<i)}return o}}}function s(){return 0}},1045:(t,e,n)=>{"use strict";function r(t,e){if(!((e=+e)>=0))throw new RangeError("invalid r");let n=t.length;if(!((n=Math.floor(n))>=0))throw new RangeError("invalid length");if(!n||!e)return t;const r=c(e),o=t.slice();return r(t,o,0,n,1),r(o,t,0,n,1),r(t,o,0,n,1),t}n.d(e,{TX:()=>i,u8:()=>o,yv:()=>r});const o=s(c),i=s((function(t){const e=c(t);return(t,n,r,o,i)=>{e(t,n,(r<<=2)+0,(o<<=2)+0,i<<=2),e(t,n,r+1,o+1,i),e(t,n,r+2,o+2,i),e(t,n,r+3,o+3,i)}}));function s(t){return function(e,n,r=n){if(!((n=+n)>=0))throw new RangeError("invalid rx");if(!((r=+r)>=0))throw new RangeError("invalid ry");let{data:o,width:i,height:s}=e;if(!((i=Math.floor(i))>=0))throw new RangeError("invalid width");if(!((s=Math.floor(void 0!==s?s:o.length/i))>=0))throw new RangeError("invalid height");if(!i||!s||!n&&!r)return e;const c=n&&t(n),u=r&&t(r),f=o.slice();return c&&u?(a(c,f,o,i,s),a(c,o,f,i,s),a(c,f,o,i,s),l(u,o,f,i,s),l(u,f,o,i,s),l(u,o,f,i,s)):c?(a(c,o,f,i,s),a(c,f,o,i,s),a(c,o,f,i,s)):u&&(l(u,o,f,i,s),l(u,f,o,i,s),l(u,o,f,i,s)),e}}function a(t,e,n,r,o){for(let i=0,s=r*o;i<s;)t(e,n,i,i+=r,1)}function l(t,e,n,r,o){for(let i=0,s=r*o;i<r;++i)t(e,n,i,i+s,r)}function c(t){const e=Math.floor(t);if(e===t)return function(t){const e=2*t+1;return(n,r,o,i,s)=>{if(!((i-=s)>=o))return;let a=t*r[o];const l=s*t;for(let t=o,e=o+l;t<e;t+=s)a+=r[Math.min(i,t)];for(let t=o,c=i;t<=c;t+=s)a+=r[Math.min(i,t+l)],n[t]=a/e,a-=r[Math.max(o,t-l)]}}(t);const n=t-e,r=2*t+1;return(t,o,i,s,a)=>{if(!((s-=a)>=i))return;let l=e*o[i];const c=a*e,u=c+a;for(let t=i,e=i+c;t<e;t+=a)l+=o[Math.min(s,t)];for(let e=i,f=s;e<=f;e+=a)l+=o[Math.min(s,e+c)],t[e]=(l+n*(o[Math.max(i,e-u)]+o[Math.min(s,e+u)]))/r,l-=o[Math.max(i,e-c)]}}},879:(t,e,n)=>{"use strict";function r(t,e){let n=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&++n;else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(o=+o)>=o&&++n}return n}n.d(e,{Z:()=>r})},788:(t,e,n)=>{"use strict";function r(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}n.d(e,{Z:()=>r})},2038:(t,e,n)=>{"use strict";function r(t,e){let n,r;if(void 0===e)for(const e of t)null!=e&&(void 0===n?e>=e&&(n=r=e):(n>e&&(n=e),r<e&&(r=e)));else{let o=-1;for(let i of t)null!=(i=e(i,++o,t))&&(void 0===n?i>=i&&(n=r=i):(n>i&&(n=i),r<i&&(r=i)))}return[n,r]}n.d(e,{Z:()=>r})},9343:(t,e,n)=>{"use strict";n.d(e,{Kd:()=>i,dU:()=>r,e3:()=>o});class r{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const e=this._partials;let n=0;for(let r=0;r<this._n&&r<32;r++){const o=e[r],i=t+o,s=Math.abs(t)<Math.abs(o)?t-(i-o):o-(i-t);s&&(e[n++]=s),t=i}return e[n]=t,this._n=n+1,this}valueOf(){const t=this._partials;let e,n,r,o=this._n,i=0;if(o>0){for(i=t[--o];o>0&&(e=i,n=t[--o],i=e+n,r=n-(i-e),!r););o>0&&(r<0&&t[o-1]<0||r>0&&t[o-1]>0)&&(n=2*r,e=i+n,n==e-i&&(i=e))}return i}}function o(t,e){const n=new r;if(void 0===e)for(let e of t)(e=+e)&&n.add(e);else{let r=-1;for(let o of t)(o=+e(o,++r,t))&&n.add(o)}return+n}function i(t,e){const n=new r;let o=-1;return Float64Array.from(t,void 0===e?t=>n.add(+t||0):r=>n.add(+e(r,++o,t)||0))}},2942:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(9263);function o(t,e=r.Z){let n,o=!1;if(1===e.length){let i;for(const s of t){const t=e(s);(o?(0,r.Z)(t,i)>0:0===(0,r.Z)(t,t))&&(n=s,i=t,o=!0)}}else for(const r of t)(o?e(r,n)>0:0===e(r,r))&&(n=r,o=!0);return n}},9060:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Adder:()=>y.dU,InternMap:()=>v.L,InternSet:()=>v.H,ascending:()=>o.Z,bin:()=>D,bisect:()=>r.ZP,bisectCenter:()=>r.ZR,bisectLeft:()=>r.Nw,bisectRight:()=>r.ml,bisector:()=>i.Z,blur:()=>s.yv,blur2:()=>s.u8,blurImage:()=>s.TX,count:()=>a.Z,cross:()=>f,cumsum:()=>d,descending:()=>h.Z,deviation:()=>m,difference:()=>wt,disjoint:()=>xt,every:()=>mt,extent:()=>g.Z,fcumsum:()=>y.Kd,filter:()=>yt,flatGroup:()=>k,flatRollup:()=>q,fsum:()=>y.e3,greatest:()=>st.Z,greatestIndex:()=>at,group:()=>_,groupSort:()=>O,groups:()=>w,histogram:()=>D,index:()=>A,indexes:()=>M,intersection:()=>kt,least:()=>ot,leastIndex:()=>it,map:()=>vt,max:()=>$.Z,maxIndex:()=>G.Z,mean:()=>U,median:()=>H,medianIndex:()=>W,merge:()=>J.Z,min:()=>V.Z,minIndex:()=>Y.Z,mode:()=>Q,nice:()=>F,pairs:()=>K,permute:()=>tt.Z,quantile:()=>B.ZP,quantileIndex:()=>B.Cr,quantileSorted:()=>B.s7,quickselect:()=>et.Z,range:()=>nt.Z,rank:()=>rt,reduce:()=>bt,reverse:()=>_t,rollup:()=>N,rollups:()=>S,scan:()=>lt,shuffle:()=>ct,shuffler:()=>ut,some:()=>gt,sort:()=>j.ZP,subset:()=>At,sum:()=>ft,superset:()=>Nt,thresholdFreedmanDiaconis:()=>z,thresholdScott:()=>Z,thresholdSturges:()=>L.Z,tickIncrement:()=>P.G9,tickStep:()=>P.ly,ticks:()=>P.ZP,transpose:()=>dt,union:()=>Mt,variance:()=>p,zip:()=>pt});var r=n(5519),o=n(9263),i=n(3292),s=n(1045),a=n(879);function l(t){return 0|t.length}function c(t){return!(t>0)}function u(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function f(...t){const e="function"==typeof t[t.length-1]&&function(t){return e=>t(...e)}(t.pop()),n=(t=t.map(u)).map(l),r=t.length-1,o=new Array(r+1).fill(0),i=[];if(r<0||n.some(c))return i;for(;;){i.push(o.map(((e,n)=>t[n][e])));let s=r;for(;++o[s]===n[s];){if(0===s)return e?i.map(e):i;o[s--]=0}}}function d(t,e){var n=0,r=0;return Float64Array.from(t,void 0===e?t=>n+=+t||0:o=>n+=+e(o,r++,t)||0)}var h=n(788);function p(t,e){let n,r=0,o=0,i=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(n=e-o,o+=n/++r,i+=n*(e-o));else{let s=-1;for(let a of t)null!=(a=e(a,++s,t))&&(a=+a)>=a&&(n=a-o,o+=n/++r,i+=n*(a-o))}if(r>1)return i/(r-1)}function m(t,e){const n=p(t,e);return n?Math.sqrt(n):n}var g=n(2038),y=n(9343),v=n(8828);function b(t){return t}function _(t,...e){return C(t,b,b,e)}function w(t,...e){return C(t,Array.from,b,e)}function x(t,e){for(let n=1,r=e.length;n<r;++n)t=t.flatMap((t=>t.pop().map((([e,n])=>[...t,e,n]))));return t}function k(t,...e){return x(w(t,...e),e)}function q(t,e,...n){return x(S(t,e,...n),n)}function N(t,e,...n){return C(t,b,e,n)}function S(t,e,...n){return C(t,Array.from,e,n)}function A(t,...e){return C(t,b,T,e)}function M(t,...e){return C(t,Array.from,T,e)}function T(t){if(1!==t.length)throw new Error("duplicate key");return t[0]}function C(t,e,n,r){return function t(o,i){if(i>=r.length)return n(o);const s=new v.L,a=r[i++];let l=-1;for(const t of o){const e=a(t,++l,o),n=s.get(e);n?n.push(t):s.set(e,[t])}for(const[e,n]of s)s.set(e,t(n,i));return e(s)}(t,0)}var j=n(3897);function O(t,e,n){return(2!==e.length?(0,j.ZP)(N(t,e,n),(([t,e],[n,r])=>(0,o.Z)(e,r)||(0,o.Z)(t,n))):(0,j.ZP)(_(t,n),(([t,n],[r,i])=>e(n,i)||(0,o.Z)(t,r)))).map((([t])=>t))}var E=Array.prototype,R=E.slice;E.map;function I(t){return()=>t}var P=n(6106);function F(t,e,n){let r;for(;;){const o=(0,P.G9)(t,e,n);if(o===r||0===o||!isFinite(o))return[t,e];o>0?(t=Math.floor(t/o)*o,e=Math.ceil(e/o)*o):o<0&&(t=Math.ceil(t*o)/o,e=Math.floor(e*o)/o),r=o}}var L=n(2327);function D(){var t=b,e=g.Z,n=L.Z;function o(o){Array.isArray(o)||(o=Array.from(o));var i,s,a,l=o.length,c=new Array(l);for(i=0;i<l;++i)c[i]=t(o[i],i,o);var u=e(c),f=u[0],d=u[1],h=n(c,f,d);if(!Array.isArray(h)){const t=d,n=+h;if(e===g.Z&&([f,d]=F(f,d,n)),(h=(0,P.ZP)(f,d,n))[0]<=f&&(a=(0,P.G9)(f,d,n)),h[h.length-1]>=d)if(t>=d&&e===g.Z){const t=(0,P.G9)(f,d,n);isFinite(t)&&(t>0?d=(Math.floor(d/t)+1)*t:t<0&&(d=(Math.ceil(d*-t)+1)/-t))}else h.pop()}for(var p=h.length;h[0]<=f;)h.shift(),--p;for(;h[p-1]>d;)h.pop(),--p;var m,y=new Array(p+1);for(i=0;i<=p;++i)(m=y[i]=[]).x0=i>0?h[i-1]:f,m.x1=i<p?h[i]:d;if(isFinite(a)){if(a>0)for(i=0;i<l;++i)null!=(s=c[i])&&f<=s&&s<=d&&y[Math.min(p,Math.floor((s-f)/a))].push(o[i]);else if(a<0)for(i=0;i<l;++i)if(null!=(s=c[i])&&f<=s&&s<=d){const t=Math.floor((f-s)*a);y[Math.min(p,t+(h[t]<=s))].push(o[i])}}else for(i=0;i<l;++i)null!=(s=c[i])&&f<=s&&s<=d&&y[(0,r.ZP)(h,s,0,p)].push(o[i]);return y}return o.value=function(e){return arguments.length?(t="function"==typeof e?e:I(e),o):t},o.domain=function(t){return arguments.length?(e="function"==typeof t?t:I([t[0],t[1]]),o):e},o.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:Array.isArray(t)?I(R.call(t)):I(t),o):n},o}var B=n(1177);function z(t,e,n){return Math.ceil((n-e)/(2*((0,B.ZP)(t,.75)-(0,B.ZP)(t,.25))*Math.pow((0,a.Z)(t),-1/3)))}function Z(t,e,n){return Math.ceil((n-e)*Math.cbrt((0,a.Z)(t))/(3.49*m(t)))}var $=n(8319),G=n(5374);function U(t,e){let n=0,r=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(++n,r+=e);else{let o=-1;for(let i of t)null!=(i=e(i,++o,t))&&(i=+i)>=i&&(++n,r+=i)}if(n)return r/n}function H(t,e){return(0,B.ZP)(t,.5,e)}function W(t,e){return(0,B.Cr)(t,.5,e)}var J=n(1740),V=n(816),Y=n(2980);function Q(t,e){const n=new v.L;if(void 0===e)for(let e of t)null!=e&&e>=e&&n.set(e,(n.get(e)||0)+1);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&o>=o&&n.set(o,(n.get(o)||0)+1)}let r,o=0;for(const[t,e]of n)e>o&&(o=e,r=t);return r}function K(t,e=X){const n=[];let r,o=!1;for(const i of t)o&&n.push(e(r,i)),r=i,o=!0;return n}function X(t,e){return[t,e]}var tt=n(362),et=n(551),nt=n(1265);function rt(t,e=o.Z){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");let n=Array.from(t);const r=new Float64Array(n.length);2!==e.length&&(n=n.map(e),e=o.Z);const i=(t,r)=>e(n[t],n[r]);let s,a;return Uint32Array.from(n,((t,e)=>e)).sort(e===o.Z?(t,e)=>(0,j.Wv)(n[t],n[e]):(0,j.di)(i)).forEach(((t,e)=>{const n=i(t,void 0===s?t:s);n>=0?((void 0===s||n>0)&&(s=t,a=e),r[t]=a):r[t]=NaN})),r}function ot(t,e=o.Z){let n,r=!1;if(1===e.length){let i;for(const s of t){const t=e(s);(r?(0,o.Z)(t,i)<0:0===(0,o.Z)(t,t))&&(n=s,i=t,r=!0)}}else for(const o of t)(r?e(o,n)<0:0===e(o,o))&&(n=o,r=!0);return n}function it(t,e=o.Z){if(1===e.length)return(0,Y.Z)(t,e);let n,r=-1,i=-1;for(const o of t)++i,(r<0?0===e(o,o):e(o,n)<0)&&(n=o,r=i);return r}var st=n(2942);function at(t,e=o.Z){if(1===e.length)return(0,G.Z)(t,e);let n,r=-1,i=-1;for(const o of t)++i,(r<0?0===e(o,o):e(o,n)>0)&&(n=o,r=i);return r}function lt(t,e){const n=it(t,e);return n<0?void 0:n}const ct=ut(Math.random);function ut(t){return function(e,n=0,r=e.length){let o=r-(n=+n);for(;o;){const r=t()*o--|0,i=e[o+n];e[o+n]=e[r+n],e[r+n]=i}return e}}function ft(t,e){let n=0;if(void 0===e)for(let e of t)(e=+e)&&(n+=e);else{let r=-1;for(let o of t)(o=+e(o,++r,t))&&(n+=o)}return n}function dt(t){if(!(o=t.length))return[];for(var e=-1,n=(0,V.Z)(t,ht),r=new Array(n);++e<n;)for(var o,i=-1,s=r[e]=new Array(o);++i<o;)s[i]=t[i][e];return r}function ht(t){return t.length}function pt(){return dt(arguments)}function mt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");let n=-1;for(const r of t)if(!e(r,++n,t))return!1;return!0}function gt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");let n=-1;for(const r of t)if(e(r,++n,t))return!0;return!1}function yt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");const n=[];let r=-1;for(const o of t)e(o,++r,t)&&n.push(o);return n}function vt(t,e){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");if("function"!=typeof e)throw new TypeError("mapper is not a function");return Array.from(t,((n,r)=>e(n,r,t)))}function bt(t,e,n){if("function"!=typeof e)throw new TypeError("reducer is not a function");const r=t[Symbol.iterator]();let o,i,s=-1;if(arguments.length<3){if(({done:o,value:n}=r.next()),o)return;++s}for(;({done:o,value:i}=r.next()),!o;)n=e(n,i,++s,t);return n}function _t(t){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");return Array.from(t).reverse()}function wt(t,...e){t=new v.H(t);for(const n of e)for(const e of n)t.delete(e);return t}function xt(t,e){const n=e[Symbol.iterator](),r=new v.H;for(const e of t){if(r.has(e))return!1;let t,o;for(;({value:t,done:o}=n.next())&&!o;){if(Object.is(e,t))return!1;r.add(t)}}return!0}function kt(t,...e){t=new v.H(t),e=e.map(qt);t:for(const n of t)for(const r of e)if(!r.has(n)){t.delete(n);continue t}return t}function qt(t){return t instanceof v.H?t:new v.H(t)}function Nt(t,e){const n=t[Symbol.iterator](),r=new Set;for(const t of e){const e=St(t);if(r.has(e))continue;let o,i;for(;({value:o,done:i}=n.next());){if(i)return!1;const t=St(o);if(r.add(t),Object.is(e,t))break}}return!0}function St(t){return null!==t&&"object"==typeof t?t.valueOf():t}function At(t,e){return Nt(e,t)}function Mt(...t){const e=new v.H;for(const n of t)for(const t of n)e.add(t);return e}},8319:(t,e,n)=>{"use strict";function r(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(n<o||void 0===n&&o>=o)&&(n=o)}return n}n.d(e,{Z:()=>r})},5374:(t,e,n)=>{"use strict";function r(t,e){let n,r=-1,o=-1;if(void 0===e)for(const e of t)++o,null!=e&&(n<e||void 0===n&&e>=e)&&(n=e,r=o);else for(let i of t)null!=(i=e(i,++o,t))&&(n<i||void 0===n&&i>=i)&&(n=i,r=o);return r}n.d(e,{Z:()=>r})},1740:(t,e,n)=>{"use strict";function r(t){return Array.from(function*(t){for(const e of t)yield*e}(t))}n.d(e,{Z:()=>r})},816:(t,e,n)=>{"use strict";function r(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(n>o||void 0===n&&o>=o)&&(n=o)}return n}n.d(e,{Z:()=>r})},2980:(t,e,n)=>{"use strict";function r(t,e){let n,r=-1,o=-1;if(void 0===e)for(const e of t)++o,null!=e&&(n>e||void 0===n&&e>=e)&&(n=e,r=o);else for(let i of t)null!=(i=e(i,++o,t))&&(n>i||void 0===n&&i>=i)&&(n=i,r=o);return r}n.d(e,{Z:()=>r})},3745:(t,e,n)=>{"use strict";function r(t){return null===t?NaN:+t}function*o(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let r of t)null!=(r=e(r,++n,t))&&(r=+r)>=r&&(yield r)}}n.d(e,{K:()=>o,Z:()=>r})},362:(t,e,n)=>{"use strict";function r(t,e){return Array.from(e,(e=>t[e]))}n.d(e,{Z:()=>r})},1177:(t,e,n)=>{"use strict";n.d(e,{Cr:()=>h,ZP:()=>f,s7:()=>d});var r=n(8319),o=n(5374),i=n(816),s=n(2980),a=n(551),l=n(3745),c=n(3897),u=n(2942);function f(t,e,n){if(o=(t=Float64Array.from((0,l.K)(t,n))).length){if((e=+e)<=0||o<2)return(0,i.Z)(t);if(e>=1)return(0,r.Z)(t);var o,s=(o-1)*e,c=Math.floor(s),u=(0,r.Z)((0,a.Z)(t,c).subarray(0,c+1));return u+((0,i.Z)(t.subarray(c+1))-u)*(s-c)}}function d(t,e,n=l.Z){if(r=t.length){if((e=+e)<=0||r<2)return+n(t[0],0,t);if(e>=1)return+n(t[r-1],r-1,t);var r,o=(r-1)*e,i=Math.floor(o),s=+n(t[i],i,t);return s+(+n(t[i+1],i+1,t)-s)*(o-i)}}function h(t,e,n){if(r=(t=Float64Array.from((0,l.K)(t,n))).length){if((e=+e)<=0||r<2)return(0,s.Z)(t);if(e>=1)return(0,o.Z)(t);var r,i=Math.floor((r-1)*e),f=(0,a.Z)(Uint32Array.from(t,((t,e)=>e)),i,0,r-1,((e,n)=>(0,c.Wv)(t[e],t[n])));return(0,u.Z)(f.subarray(0,i+1),(e=>t[e]))}}},551:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(3897);function o(t,e,n=0,s=t.length-1,a){for(a=void 0===a?r.Wv:(0,r.di)(a);s>n;){if(s-n>600){const r=s-n+1,i=e-n+1,l=Math.log(r),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(r-c)/r)*(i-r/2<0?-1:1);o(t,e,Math.max(n,Math.floor(e-i*c/r+u)),Math.min(s,Math.floor(e+(r-i)*c/r+u)),a)}const r=t[e];let l=n,c=s;for(i(t,n,e),a(t[s],r)>0&&i(t,n,s);l<c;){for(i(t,l,c),++l,--c;a(t[l],r)<0;)++l;for(;a(t[c],r)>0;)--c}0===a(t[n],r)?i(t,n,c):(++c,i(t,c,s)),c<=e&&(n=c+1),e<=c&&(s=c-1)}return t}function i(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}},1265:(t,e,n)=>{"use strict";function r(t,e,n){t=+t,e=+e,n=(o=arguments.length)<2?(e=t,t=0,1):o<3?1:+n;for(var r=-1,o=0|Math.max(0,Math.ceil((e-t)/n)),i=new Array(o);++r<o;)i[r]=t+r*n;return i}n.d(e,{Z:()=>r})},3897:(t,e,n)=>{"use strict";n.d(e,{Wv:()=>a,ZP:()=>i,di:()=>s});var r=n(9263),o=n(362);function i(t,...e){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");t=Array.from(t);let[n]=e;if(n&&2!==n.length||e.length>1){const r=Uint32Array.from(t,((t,e)=>e));return e.length>1?(e=e.map((e=>t.map(e))),r.sort(((t,n)=>{for(const r of e){const e=a(r[t],r[n]);if(e)return e}}))):(n=t.map(n),r.sort(((t,e)=>a(n[t],n[e])))),(0,o.Z)(t,r)}return t.sort(s(n))}function s(t=r.Z){if(t===r.Z)return a;if("function"!=typeof t)throw new TypeError("compare is not a function");return(e,n)=>{const r=t(e,n);return r||0===r?r:(0===t(n,n))-(0===t(e,e))}}function a(t,e){return(null==t||!(t>=t))-(null==e||!(e>=e))||(t<e?-1:t>e?1:0)}},2327:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(879);function o(t){return Math.ceil(Math.log((0,r.Z)(t))/Math.LN2)+1}},6106:(t,e,n)=>{"use strict";n.d(e,{G9:()=>a,ZP:()=>s,ly:()=>l});var r=Math.sqrt(50),o=Math.sqrt(10),i=Math.sqrt(2);function s(t,e,n){var r,o,i,s,l=-1;if(n=+n,(t=+t)===(e=+e)&&n>0)return[t];if((r=e<t)&&(o=t,t=e,e=o),0===(s=a(t,e,n))||!isFinite(s))return[];if(s>0){let n=Math.round(t/s),r=Math.round(e/s);for(n*s<t&&++n,r*s>e&&--r,i=new Array(o=r-n+1);++l<o;)i[l]=(n+l)*s}else{s=-s;let n=Math.round(t*s),r=Math.round(e*s);for(n/s<t&&++n,r/s>e&&--r,i=new Array(o=r-n+1);++l<o;)i[l]=(n+l)/s}return r&&i.reverse(),i}function a(t,e,n){var s=(e-t)/Math.max(0,n),a=Math.floor(Math.log(s)/Math.LN10),l=s/Math.pow(10,a);return a>=0?(l>=r?10:l>=o?5:l>=i?2:1)*Math.pow(10,a):-Math.pow(10,-a)/(l>=r?10:l>=o?5:l>=i?2:1)}function l(t,e,n){var s=Math.abs(e-t)/Math.max(0,n),a=Math.pow(10,Math.floor(Math.log(s)/Math.LN10)),l=s/a;return l>=r?a*=10:l>=o?a*=5:l>=i&&(a*=2),e<t?-a:a}},1495:(t,e,n)=>{"use strict";n.d(e,{B8:()=>q,Il:()=>o,J5:()=>s,SU:()=>k,Ss:()=>N,Ym:()=>E,ZP:()=>_,xV:()=>i});var r=n(3456);function o(){}var i=.7,s=1/i,a="\\s*([+-]?\\d+)\\s*",l="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",c="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",u=/^#([0-9a-f]{3,8})$/,f=new RegExp(`^rgb\\(${a},${a},${a}\\)$`),d=new RegExp(`^rgb\\(${c},${c},${c}\\)$`),h=new RegExp(`^rgba\\(${a},${a},${a},${l}\\)$`),p=new RegExp(`^rgba\\(${c},${c},${c},${l}\\)$`),m=new RegExp(`^hsl\\(${l},${c},${c}\\)$`),g=new RegExp(`^hsla\\(${l},${c},${c},${l}\\)$`),y={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function v(){return this.rgb().formatHex()}function b(){return this.rgb().formatRgb()}function _(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=u.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?w(e):3===n?new N(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?x(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?x(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=f.exec(t))?new N(e[1],e[2],e[3],1):(e=d.exec(t))?new N(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=h.exec(t))?x(e[1],e[2],e[3],e[4]):(e=p.exec(t))?x(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=m.exec(t))?j(e[1],e[2]/100,e[3]/100,1):(e=g.exec(t))?j(e[1],e[2]/100,e[3]/100,e[4]):y.hasOwnProperty(t)?w(y[t]):"transparent"===t?new N(NaN,NaN,NaN,0):null}function w(t){return new N(t>>16&255,t>>8&255,255&t,1)}function x(t,e,n,r){return r<=0&&(t=e=n=NaN),new N(t,e,n,r)}function k(t){return t instanceof o||(t=_(t)),t?new N((t=t.rgb()).r,t.g,t.b,t.opacity):new N}function q(t,e,n,r){return 1===arguments.length?k(t):new N(t,e,n,null==r?1:r)}function N(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function S(){return`#${C(this.r)}${C(this.g)}${C(this.b)}`}function A(){const t=M(this.opacity);return`${1===t?"rgb(":"rgba("}${T(this.r)}, ${T(this.g)}, ${T(this.b)}${1===t?")":`, ${t})`}`}function M(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function T(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function C(t){return((t=T(t))<16?"0":"")+t.toString(16)}function j(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new R(t,e,n,r)}function O(t){if(t instanceof R)return new R(t.h,t.s,t.l,t.opacity);if(t instanceof o||(t=_(t)),!t)return new R;if(t instanceof R)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),s=Math.max(e,n,r),a=NaN,l=s-i,c=(s+i)/2;return l?(a=e===s?(n-r)/l+6*(n<r):n===s?(r-e)/l+2:(e-n)/l+4,l/=c<.5?s+i:2-s-i,a*=60):l=c>0&&c<1?0:a,new R(a,l,c,t.opacity)}function E(t,e,n,r){return 1===arguments.length?O(t):new R(t,e,n,null==r?1:r)}function R(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function I(t){return(t=(t||0)%360)<0?t+360:t}function P(t){return Math.max(0,Math.min(1,t||0))}function F(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}(0,r.Z)(o,_,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:v,formatHex:v,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return O(this).formatHsl()},formatRgb:b,toString:b}),(0,r.Z)(N,q,(0,r.l)(o,{brighter(t){return t=null==t?s:Math.pow(s,t),new N(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?i:Math.pow(i,t),new N(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new N(T(this.r),T(this.g),T(this.b),M(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:S,formatHex:S,formatHex8:function(){return`#${C(this.r)}${C(this.g)}${C(this.b)}${C(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:A,toString:A})),(0,r.Z)(R,E,(0,r.l)(o,{brighter(t){return t=null==t?s:Math.pow(s,t),new R(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?i:Math.pow(i,t),new R(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,o=2*n-r;return new N(F(t>=240?t-240:t+120,o,r),F(t,o,r),F(t<120?t+240:t-120,o,r),this.opacity)},clamp(){return new R(I(this.h),P(this.s),P(this.l),M(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=M(this.opacity);return`${1===t?"hsl(":"hsla("}${I(this.h)}, ${100*P(this.s)}%, ${100*P(this.l)}%${1===t?")":`, ${t})`}`}}))},3763:(t,e,n)=>{"use strict";n.d(e,{Z:()=>m});var r=n(3456),o=n(1495),i=n(7274),s=-.14861,a=1.78277,l=-.29227,c=-.90649,u=1.97294,f=u*c,d=u*a,h=a*l-c*s;function p(t){if(t instanceof g)return new g(t.h,t.s,t.l,t.opacity);t instanceof o.Ss||(t=(0,o.SU)(t));var e=t.r/255,n=t.g/255,r=t.b/255,s=(h*r+f*e-d*n)/(h+f-d),a=r-s,p=(u*(n-s)-l*a)/c,m=Math.sqrt(p*p+a*a)/(u*s*(1-s)),y=m?Math.atan2(p,a)*i.R-120:NaN;return new g(y<0?y+360:y,m,s,t.opacity)}function m(t,e,n,r){return 1===arguments.length?p(t):new g(t,e,n,null==r?1:r)}function g(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}(0,r.Z)(g,m,(0,r.l)(o.Il,{brighter(t){return t=null==t?o.J5:Math.pow(o.J5,t),new g(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?o.xV:Math.pow(o.xV,t),new g(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=isNaN(this.h)?0:(this.h+120)*i.u,e=+this.l,n=isNaN(this.s)?0:this.s*e*(1-e),r=Math.cos(t),f=Math.sin(t);return new o.Ss(255*(e+n*(s*r+a*f)),255*(e+n*(l*r+c*f)),255*(e+n*(u*r)),this.opacity)}}))},3456:(t,e,n)=>{"use strict";function r(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function o(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}n.d(e,{Z:()=>r,l:()=>o})},7346:(t,e,n)=>{"use strict";n.r(e),n.d(e,{color:()=>r.ZP,cubehelix:()=>i.Z,gray:()=>o.MA,hcl:()=>o.Uc,hsl:()=>r.Ym,lab:()=>o.ZP,lch:()=>o.tW,rgb:()=>r.B8});var r=n(1495),o=n(3334),i=n(3763)},3334:(t,e,n)=>{"use strict";n.d(e,{MA:()=>d,Uc:()=>w,ZP:()=>h,tW:()=>_});var r=n(3456),o=n(1495),i=n(7274);const s=.96422,a=.82521,l=4/29,c=6/29,u=3*c*c;function f(t){if(t instanceof p)return new p(t.l,t.a,t.b,t.opacity);if(t instanceof x)return k(t);t instanceof o.Ss||(t=(0,o.SU)(t));var e,n,r=v(t.r),i=v(t.g),l=v(t.b),c=m((.2225045*r+.7168786*i+.0606169*l)/1);return r===i&&i===l?e=n=c:(e=m((.4360747*r+.3850649*i+.1430804*l)/s),n=m((.0139322*r+.0971045*i+.7141733*l)/a)),new p(116*c-16,500*(e-c),200*(c-n),t.opacity)}function d(t,e){return new p(t,0,0,null==e?1:e)}function h(t,e,n,r){return 1===arguments.length?f(t):new p(t,e,n,null==r?1:r)}function p(t,e,n,r){this.l=+t,this.a=+e,this.b=+n,this.opacity=+r}function m(t){return t>.008856451679035631?Math.pow(t,1/3):t/u+l}function g(t){return t>c?t*t*t:u*(t-l)}function y(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function v(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function b(t){if(t instanceof x)return new x(t.h,t.c,t.l,t.opacity);if(t instanceof p||(t=f(t)),0===t.a&&0===t.b)return new x(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*i.R;return new x(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function _(t,e,n,r){return 1===arguments.length?b(t):new x(n,e,t,null==r?1:r)}function w(t,e,n,r){return 1===arguments.length?b(t):new x(t,e,n,null==r?1:r)}function x(t,e,n,r){this.h=+t,this.c=+e,this.l=+n,this.opacity=+r}function k(t){if(isNaN(t.h))return new p(t.l,0,0,t.opacity);var e=t.h*i.u;return new p(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}(0,r.Z)(p,h,(0,r.l)(o.Il,{brighter(t){return new p(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker(t){return new p(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return e=s*g(e),t=1*g(t),n=a*g(n),new o.Ss(y(3.1338561*e-1.6168667*t-.4906146*n),y(-.9787684*e+1.9161415*t+.033454*n),y(.0719453*e-.2289914*t+1.4052427*n),this.opacity)}})),(0,r.Z)(x,w,(0,r.l)(o.Il,{brighter(t){return new x(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker(t){return new x(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb(){return k(this).rgb()}}))},7274:(t,e,n)=>{"use strict";n.d(e,{R:()=>o,u:()=>r});const r=Math.PI/180,o=180/Math.PI},9106:(t,e,n)=>{"use strict";n.d(e,{Bj:()=>i,Jb:()=>l,S:()=>a,Sf:()=>s,eX:()=>u,fh:()=>c,ue:()=>o});var r=(0,n(4476).Z)(","),o=r.parse,i=r.parseRows,s=r.format,a=r.formatBody,l=r.formatRows,c=r.formatRow,u=r.formatValue},4476:(t,e,n)=>{"use strict";n.d(e,{Z:()=>c});var r={},o={};function i(t){return new Function("d","return {"+t.map((function(t,e){return JSON.stringify(t)+": d["+e+'] || ""'})).join(",")+"}")}function s(t){var e=Object.create(null),n=[];return t.forEach((function(t){for(var r in t)r in e||n.push(e[r]=r)})),n}function a(t,e){var n=t+"",r=n.length;return r<e?new Array(e-r+1).join(0)+n:n}function l(t){var e,n=t.getUTCHours(),r=t.getUTCMinutes(),o=t.getUTCSeconds(),i=t.getUTCMilliseconds();return isNaN(t)?"Invalid Date":((e=t.getUTCFullYear())<0?"-"+a(-e,6):e>9999?"+"+a(e,6):a(e,4))+"-"+a(t.getUTCMonth()+1,2)+"-"+a(t.getUTCDate(),2)+(i?"T"+a(n,2)+":"+a(r,2)+":"+a(o,2)+"."+a(i,3)+"Z":o?"T"+a(n,2)+":"+a(r,2)+":"+a(o,2)+"Z":r||n?"T"+a(n,2)+":"+a(r,2)+"Z":"")}function c(t){var e=new RegExp('["'+t+"\n\r]"),n=t.charCodeAt(0);function a(t,e){var i,s=[],a=t.length,l=0,c=0,u=a<=0,f=!1;function d(){if(u)return o;if(f)return f=!1,r;var e,i,s=l;if(34===t.charCodeAt(s)){for(;l++<a&&34!==t.charCodeAt(l)||34===t.charCodeAt(++l););return(e=l)>=a?u=!0:10===(i=t.charCodeAt(l++))?f=!0:13===i&&(f=!0,10===t.charCodeAt(l)&&++l),t.slice(s+1,e-1).replace(/""/g,'"')}for(;l<a;){if(10===(i=t.charCodeAt(e=l++)))f=!0;else if(13===i)f=!0,10===t.charCodeAt(l)&&++l;else if(i!==n)continue;return t.slice(s,e)}return u=!0,t.slice(s,a)}for(10===t.charCodeAt(a-1)&&--a,13===t.charCodeAt(a-1)&&--a;(i=d())!==o;){for(var h=[];i!==r&&i!==o;)h.push(i),i=d();e&&null==(h=e(h,c++))||s.push(h)}return s}function c(e,n){return e.map((function(e){return n.map((function(t){return f(e[t])})).join(t)}))}function u(e){return e.map(f).join(t)}function f(t){return null==t?"":t instanceof Date?l(t):e.test(t+="")?'"'+t.replace(/"/g,'""')+'"':t}return{parse:function(t,e){var n,r,o=a(t,(function(t,o){if(n)return n(t,o-1);r=t,n=e?function(t,e){var n=i(t);return function(r,o){return e(n(r),o,t)}}(t,e):i(t)}));return o.columns=r||[],o},parseRows:a,format:function(e,n){return null==n&&(n=s(e)),[n.map(f).join(t)].concat(c(e,n)).join("\n")},formatBody:function(t,e){return null==e&&(e=s(t)),c(t,e).join("\n")},formatRows:function(t){return t.map(u).join("\n")},formatRow:u,formatValue:f}}},2884:(t,e,n)=>{"use strict";n.r(e),n.d(e,{autoType:()=>s,csvFormat:()=>o.Sf,csvFormatBody:()=>o.S,csvFormatRow:()=>o.fh,csvFormatRows:()=>o.Jb,csvFormatValue:()=>o.eX,csvParse:()=>o.ue,csvParseRows:()=>o.Bj,dsvFormat:()=>r.Z,tsvFormat:()=>i.vP,tsvFormatBody:()=>i.uH,tsvFormatRow:()=>i.Hf,tsvFormatRows:()=>i.n5,tsvFormatValue:()=>i.sS,tsvParse:()=>i.tJ,tsvParseRows:()=>i.E0});var r=n(4476),o=n(9106),i=n(5026);function s(t){for(var e in t){var n,r,o=t[e].trim();if(o)if("true"===o)o=!0;else if("false"===o)o=!1;else if("NaN"===o)o=NaN;else if(isNaN(n=+o)){if(!(r=o.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;a&&r[4]&&!r[7]&&(o=o.replace(/-/g,"/").replace(/T/," ")),o=new Date(o)}else o=n;else o=null;t[e]=o}return t}const a=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours()},5026:(t,e,n)=>{"use strict";n.d(e,{E0:()=>i,Hf:()=>c,n5:()=>l,sS:()=>u,tJ:()=>o,uH:()=>a,vP:()=>s});var r=(0,n(4476).Z)("\t"),o=r.parse,i=r.parseRows,s=r.format,a=r.formatBody,l=r.formatRows,c=r.formatRow,u=r.formatValue},2163:(t,e,n)=>{"use strict";n.d(e,{WU:()=>o,ZP:()=>a,jH:()=>i});var r,o,i,s=n(2107);function a(t){return r=(0,s.Z)(t),o=r.format,i=r.formatPrefix,r}a({thousands:",",grouping:[3],currency:["$",""]})},2313:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(4218);function o(t){return(t=(0,r.V)(Math.abs(t)))?t[1]:NaN}},4218:(t,e,n)=>{"use strict";function r(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function o(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}n.d(e,{V:()=>o,Z:()=>r})},7259:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o,v:()=>i});var r=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function o(t){if(!(e=r.exec(t)))throw new Error("invalid format: "+t);var e;return new i({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function i(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}o.prototype=i.prototype,i.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type}},8288:(t,e,n)=>{"use strict";n.r(e),n.d(e,{FormatSpecifier:()=>i.v,format:()=>r.WU,formatDefaultLocale:()=>r.ZP,formatLocale:()=>o.Z,formatPrefix:()=>r.jH,formatSpecifier:()=>i.Z,precisionFixed:()=>s.Z,precisionPrefix:()=>a.Z,precisionRound:()=>l.Z});var r=n(2163),o=n(2107),i=n(7259),s=n(9680),a=n(3150),l=n(3621)},2107:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(2313);var o=n(7259);var i,s=n(4218);function a(t,e){var n=(0,s.V)(t,e);if(!n)return t+"";var r=n[0],o=n[1];return o<0?"0."+new Array(-o).join("0")+r:r.length>o+1?r.slice(0,o+1)+"."+r.slice(o+1):r+new Array(o-r.length+2).join("0")}const l={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:s.Z,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>a(100*t,e),r:a,s:function(t,e){var n=(0,s.V)(t,e);if(!n)return t+"";var r=n[0],o=n[1],a=o-(i=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,l=r.length;return a===l?r:a>l?r+new Array(a-l+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+(0,s.V)(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function c(t){return t}var u=Array.prototype.map,f=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function d(t){var e,n,s=void 0===t.grouping||void 0===t.thousands?c:(e=u.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var o=t.length,i=[],s=0,a=e[0],l=0;o>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),i.push(t.substring(o-=a,o+a)),!((l+=a+1)>r));)a=e[s=(s+1)%e.length];return i.reverse().join(n)}),a=void 0===t.currency?"":t.currency[0]+"",d=void 0===t.currency?"":t.currency[1]+"",h=void 0===t.decimal?".":t.decimal+"",p=void 0===t.numerals?c:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(u.call(t.numerals,String)),m=void 0===t.percent?"%":t.percent+"",g=void 0===t.minus?"−":t.minus+"",y=void 0===t.nan?"NaN":t.nan+"";function v(t){var e=(t=(0,o.Z)(t)).fill,n=t.align,r=t.sign,c=t.symbol,u=t.zero,v=t.width,b=t.comma,_=t.precision,w=t.trim,x=t.type;"n"===x?(b=!0,x="g"):l[x]||(void 0===_&&(_=12),w=!0,x="g"),(u||"0"===e&&"="===n)&&(u=!0,e="0",n="=");var k="$"===c?a:"#"===c&&/[boxX]/.test(x)?"0"+x.toLowerCase():"",q="$"===c?d:/[%p]/.test(x)?m:"",N=l[x],S=/[defgprs%]/.test(x);function A(t){var o,a,l,c=k,d=q;if("c"===x)d=N(t)+d,t="";else{var m=(t=+t)<0||1/t<0;if(t=isNaN(t)?y:N(Math.abs(t),_),w&&(t=function(t){t:for(var e,n=t.length,r=1,o=-1;r<n;++r)switch(t[r]){case".":o=e=r;break;case"0":0===o&&(o=r),e=r;break;default:if(!+t[r])break t;o>0&&(o=0)}return o>0?t.slice(0,o)+t.slice(e+1):t}(t)),m&&0==+t&&"+"!==r&&(m=!1),c=(m?"("===r?r:g:"-"===r||"("===r?"":r)+c,d=("s"===x?f[8+i/3]:"")+d+(m&&"("===r?")":""),S)for(o=-1,a=t.length;++o<a;)if(48>(l=t.charCodeAt(o))||l>57){d=(46===l?h+t.slice(o+1):t.slice(o))+d,t=t.slice(0,o);break}}b&&!u&&(t=s(t,1/0));var A=c.length+t.length+d.length,M=A<v?new Array(v-A+1).join(e):"";switch(b&&u&&(t=s(M+t,M.length?v-d.length:1/0),M=""),n){case"<":t=c+t+d+M;break;case"=":t=c+M+t+d;break;case"^":t=M.slice(0,A=M.length>>1)+c+t+d+M.slice(A);break;default:t=M+c+t+d}return p(t)}return _=void 0===_?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_)),A.toString=function(){return t+""},A}return{format:v,formatPrefix:function(t,e){var n=v(((t=(0,o.Z)(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor((0,r.Z)(e)/3))),s=Math.pow(10,-i),a=f[8+i/3];return function(t){return n(s*t)+a}}}}},9680:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t){return Math.max(0,-(0,r.Z)(Math.abs(t)))}},3150:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor((0,r.Z)(e)/3)))-(0,r.Z)(Math.abs(t)))}},3621:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,(0,r.Z)(e)-(0,r.Z)(t))+1}},5505:(t,e,n)=>{"use strict";function r(t,e){return t.parent===e.parent?1:2}function o(t,e){return t+e.x}function i(t,e){return Math.max(t,e.y)}function s(){var t=r,e=1,n=1,s=!1;function a(r){var a,l=0;r.eachAfter((function(e){var n=e.children;n?(e.x=function(t){return t.reduce(o,0)/t.length}(n),e.y=function(t){return 1+t.reduce(i,0)}(n)):(e.x=a?l+=t(e,a):0,e.y=0,a=e)}));var c=function(t){for(var e;e=t.children;)t=e[0];return t}(r),u=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(r),f=c.x-t(c,u)/2,d=u.x+t(u,c)/2;return r.eachAfter(s?function(t){t.x=(t.x-r.x)*e,t.y=(r.y-t.y)*n}:function(t){t.x=(t.x-f)/(d-f)*e,t.y=(1-(r.y?t.y/r.y:1))*n})}return a.separation=function(e){return arguments.length?(t=e,a):t},a.size=function(t){return arguments.length?(s=!1,e=+t[0],n=+t[1],a):s?null:[e,n]},a.nodeSize=function(t){return arguments.length?(s=!0,e=+t[0],n=+t[1],a):s?[e,n]:null},a}function a(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function l(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=u)):void 0===e&&(e=c);for(var n,r,o,i,s,a=new h(t),l=[a];n=l.pop();)if((o=e(n.data))&&(s=(o=Array.from(o)).length))for(n.children=o,i=s-1;i>=0;--i)l.push(r=o[i]=new h(o[i])),r.parent=n,r.depth=n.depth+1;return a.eachBefore(d)}function c(t){return t.children}function u(t){return Array.isArray(t)?t[1]:null}function f(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function d(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function p(t){return null==t?null:m(t)}function m(t){if("function"!=typeof t)throw new Error;return t}function g(){return 0}function y(t){return function(){return t}}n.d(e,{NB:()=>h,ki:()=>s,bT:()=>l,P2:()=>P,O1:()=>_,jA:()=>R,uK:()=>Z,QP:()=>J,G_:()=>rt,pN:()=>lt,wL:()=>ct,LQ:()=>z,eA:()=>ft,Km:()=>ot,E_:()=>ut,o$:()=>at}),h.prototype=l.prototype={constructor:h,count:function(){return this.eachAfter(a)},each:function(t,e){let n=-1;for(const r of this)t.call(e,r,++n,this);return this},eachAfter:function(t,e){for(var n,r,o,i=this,s=[i],a=[],l=-1;i=s.pop();)if(a.push(i),n=i.children)for(r=0,o=n.length;r<o;++r)s.push(n[r]);for(;i=a.pop();)t.call(e,i,++l,this);return this},eachBefore:function(t,e){for(var n,r,o=this,i=[o],s=-1;o=i.pop();)if(t.call(e,o,++s,this),n=o.children)for(r=n.length-1;r>=0;--r)i.push(n[r]);return this},find:function(t,e){let n=-1;for(const r of this)if(t.call(e,r,++n,this))return r},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,o=r&&r.length;--o>=0;)n+=r[o].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),o=null;t=n.pop(),e=r.pop();for(;t===e;)o=t,t=n.pop(),e=r.pop();return o}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var o=r.length;t!==n;)r.splice(o,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return l(this).eachBefore(f)},[Symbol.iterator]:function*(){var t,e,n,r,o=this,i=[o];do{for(t=i.reverse(),i=[];o=t.pop();)if(yield o,e=o.children)for(n=0,r=e.length;n<r;++n)i.push(e[n])}while(i.length)}};const v=4294967296;function b(){let t=1;return()=>(t=(1664525*t+1013904223)%v)/v}function _(t){return w(t,b())}function w(t,e){for(var n,r,o=0,i=(t=function(t,e){let n,r,o=t.length;for(;o;)r=e()*o--|0,n=t[o],t[o]=t[r],t[r]=n;return t}(Array.from(t),e)).length,s=[];o<i;)n=t[o],r&&q(r,n)?++o:(r=S(s=x(s,n)),o=0);return r}function x(t,e){var n,r;if(N(e,t))return[e];for(n=0;n<t.length;++n)if(k(e,t[n])&&N(A(t[n],e),t))return[t[n],e];for(n=0;n<t.length-1;++n)for(r=n+1;r<t.length;++r)if(k(A(t[n],t[r]),e)&&k(A(t[n],e),t[r])&&k(A(t[r],e),t[n])&&N(M(t[n],t[r],e),t))return[t[n],t[r],e];throw new Error}function k(t,e){var n=t.r-e.r,r=e.x-t.x,o=e.y-t.y;return n<0||n*n<r*r+o*o}function q(t,e){var n=t.r-e.r+1e-9*Math.max(t.r,e.r,1),r=e.x-t.x,o=e.y-t.y;return n>0&&n*n>r*r+o*o}function N(t,e){for(var n=0;n<e.length;++n)if(!q(t,e[n]))return!1;return!0}function S(t){switch(t.length){case 1:return function(t){return{x:t.x,y:t.y,r:t.r}}(t[0]);case 2:return A(t[0],t[1]);case 3:return M(t[0],t[1],t[2])}}function A(t,e){var n=t.x,r=t.y,o=t.r,i=e.x,s=e.y,a=e.r,l=i-n,c=s-r,u=a-o,f=Math.sqrt(l*l+c*c);return{x:(n+i+l/f*u)/2,y:(r+s+c/f*u)/2,r:(f+o+a)/2}}function M(t,e,n){var r=t.x,o=t.y,i=t.r,s=e.x,a=e.y,l=e.r,c=n.x,u=n.y,f=n.r,d=r-s,h=r-c,p=o-a,m=o-u,g=l-i,y=f-i,v=r*r+o*o-i*i,b=v-s*s-a*a+l*l,_=v-c*c-u*u+f*f,w=h*p-d*m,x=(p*_-m*b)/(2*w)-r,k=(m*g-p*y)/w,q=(h*b-d*_)/(2*w)-o,N=(d*y-h*g)/w,S=k*k+N*N-1,A=2*(i+x*k+q*N),M=x*x+q*q-i*i,T=-(Math.abs(S)>1e-6?(A+Math.sqrt(A*A-4*S*M))/(2*S):M/A);return{x:r+x+k*T,y:o+q+N*T,r:T}}function T(t,e,n){var r,o,i,s,a=t.x-e.x,l=t.y-e.y,c=a*a+l*l;c?(o=e.r+n.r,o*=o,s=t.r+n.r,o>(s*=s)?(r=(c+s-o)/(2*c),i=Math.sqrt(Math.max(0,s/c-r*r)),n.x=t.x-r*a-i*l,n.y=t.y-r*l+i*a):(r=(c+o-s)/(2*c),i=Math.sqrt(Math.max(0,o/c-r*r)),n.x=e.x+r*a-i*l,n.y=e.y+r*l+i*a)):(n.x=e.x+n.r,n.y=e.y)}function C(t,e){var n=t.r+e.r-1e-6,r=e.x-t.x,o=e.y-t.y;return n>0&&n*n>r*r+o*o}function j(t){var e=t._,n=t.next._,r=e.r+n.r,o=(e.x*n.r+n.x*e.r)/r,i=(e.y*n.r+n.y*e.r)/r;return o*o+i*i}function O(t){this._=t,this.next=null,this.previous=null}function E(t,e){if(!(s=(n=t,t="object"==typeof n&&"length"in n?n:Array.from(n)).length))return 0;var n,r,o,i,s,a,l,c,u,f,d,h;if((r=t[0]).x=0,r.y=0,!(s>1))return r.r;if(o=t[1],r.x=-o.r,o.x=r.r,o.y=0,!(s>2))return r.r+o.r;T(o,r,i=t[2]),r=new O(r),o=new O(o),i=new O(i),r.next=i.previous=o,o.next=r.previous=i,i.next=o.previous=r;t:for(c=3;c<s;++c){T(r._,o._,i=t[c]),i=new O(i),u=o.next,f=r.previous,d=o._.r,h=r._.r;do{if(d<=h){if(C(u._,i._)){o=u,r.next=o,o.previous=r,--c;continue t}d+=u._.r,u=u.next}else{if(C(f._,i._)){(r=f).next=o,o.previous=r,--c;continue t}h+=f._.r,f=f.previous}}while(u!==f.next);for(i.previous=r,i.next=o,r.next=o.previous=o=i,a=j(r);(i=i.next)!==o;)(l=j(i))<a&&(r=i,a=l);o=r.next}for(r=[o._],i=o;(i=i.next)!==o;)r.push(i._);for(i=w(r,e),c=0;c<s;++c)(r=t[c]).x-=i.x,r.y-=i.y;return i.r}function R(t){return E(t,b()),t}function I(t){return Math.sqrt(t.value)}function P(){var t=null,e=1,n=1,r=g;function o(o){const i=b();return o.x=e/2,o.y=n/2,t?o.eachBefore(F(t)).eachAfter(L(r,.5,i)).eachBefore(D(1)):o.eachBefore(F(I)).eachAfter(L(g,1,i)).eachAfter(L(r,o.r/Math.min(e,n),i)).eachBefore(D(Math.min(e,n)/(2*o.r))),o}return o.radius=function(e){return arguments.length?(t=p(e),o):t},o.size=function(t){return arguments.length?(e=+t[0],n=+t[1],o):[e,n]},o.padding=function(t){return arguments.length?(r="function"==typeof t?t:y(+t),o):r},o}function F(t){return function(e){e.children||(e.r=Math.max(0,+t(e)||0))}}function L(t,e,n){return function(r){if(o=r.children){var o,i,s,a=o.length,l=t(r)*e||0;if(l)for(i=0;i<a;++i)o[i].r+=l;if(s=E(o,n),l)for(i=0;i<a;++i)o[i].r-=l;r.r=s+l}}}function D(t){return function(e){var n=e.parent;e.r*=t,n&&(e.x=n.x+t*e.x,e.y=n.y+t*e.y)}}function B(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function z(t,e,n,r,o){for(var i,s=t.children,a=-1,l=s.length,c=t.value&&(r-e)/t.value;++a<l;)(i=s[a]).y0=n,i.y1=o,i.x0=e,i.x1=e+=i.value*c}function Z(){var t=1,e=1,n=0,r=!1;function o(o){var i=o.height+1;return o.x0=o.y0=n,o.x1=t,o.y1=e/i,o.eachBefore(function(t,e){return function(r){r.children&&z(r,r.x0,t*(r.depth+1)/e,r.x1,t*(r.depth+2)/e);var o=r.x0,i=r.y0,s=r.x1-n,a=r.y1-n;s<o&&(o=s=(o+s)/2),a<i&&(i=a=(i+a)/2),r.x0=o,r.y0=i,r.x1=s,r.y1=a}}(e,i)),r&&o.eachBefore(B),o}return o.round=function(t){return arguments.length?(r=!!t,o):r},o.size=function(n){return arguments.length?(t=+n[0],e=+n[1],o):[t,e]},o.padding=function(t){return arguments.length?(n=+t,o):n},o}var $={depth:-1},G={},U={};function H(t){return t.id}function W(t){return t.parentId}function J(){var t,e=H,n=W;function r(r){var o,i,s,a,l,c,u,f,p=Array.from(r),m=e,g=n,y=new Map;if(null!=t){const e=p.map(((e,n)=>function(t){let e=(t=`${t}`).length;Y(t,e-1)&&!Y(t,e-2)&&(t=t.slice(0,-1));return"/"===t[0]?t:`/${t}`}(t(e,n,r)))),n=e.map(V),o=new Set(e).add("");for(const t of n)o.has(t)||(o.add(t),e.push(t),n.push(V(t)),p.push(U));m=(t,n)=>e[n],g=(t,e)=>n[e]}for(s=0,o=p.length;s<o;++s)i=p[s],c=p[s]=new h(i),null!=(u=m(i,s,r))&&(u+="")&&(f=c.id=u,y.set(f,y.has(f)?G:c)),null!=(u=g(i,s,r))&&(u+="")&&(c.parent=u);for(s=0;s<o;++s)if(u=(c=p[s]).parent){if(!(l=y.get(u)))throw new Error("missing: "+u);if(l===G)throw new Error("ambiguous: "+u);l.children?l.children.push(c):l.children=[c],c.parent=l}else{if(a)throw new Error("multiple roots");a=c}if(!a)throw new Error("no root");if(null!=t){for(;a.data===U&&1===a.children.length;)a=a.children[0],--o;for(let t=p.length-1;t>=0&&(c=p[t],c.data===U);--t)c.data=null}if(a.parent=$,a.eachBefore((function(t){t.depth=t.parent.depth+1,--o})).eachBefore(d),a.parent=null,o>0)throw new Error("cycle");return a}return r.id=function(t){return arguments.length?(e=p(t),r):e},r.parentId=function(t){return arguments.length?(n=p(t),r):n},r.path=function(e){return arguments.length?(t=p(e),r):t},r}function V(t){let e=t.length;if(e<2)return"";for(;--e>1&&!Y(t,e););return t.slice(0,e)}function Y(t,e){if("/"===t[e]){let n=0;for(;e>0&&"\\"===t[--e];)++n;if(0==(1&n))return!0}return!1}function Q(t,e){return t.parent===e.parent?1:2}function K(t){var e=t.children;return e?e[0]:t.t}function X(t){var e=t.children;return e?e[e.length-1]:t.t}function tt(t,e,n){var r=n/(e.i-t.i);e.c-=r,e.s+=n,t.c+=r,e.z+=n,e.m+=n}function et(t,e,n){return t.a.parent===e.parent?t.a:n}function nt(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function rt(){var t=Q,e=1,n=1,r=null;function o(o){var l=function(t){for(var e,n,r,o,i,s=new nt(t,0),a=[s];e=a.pop();)if(r=e._.children)for(e.children=new Array(i=r.length),o=i-1;o>=0;--o)a.push(n=e.children[o]=new nt(r[o],o)),n.parent=e;return(s.parent=new nt(null,0)).children=[s],s}(o);if(l.eachAfter(i),l.parent.m=-l.z,l.eachBefore(s),r)o.eachBefore(a);else{var c=o,u=o,f=o;o.eachBefore((function(t){t.x<c.x&&(c=t),t.x>u.x&&(u=t),t.depth>f.depth&&(f=t)}));var d=c===u?1:t(c,u)/2,h=d-c.x,p=e/(u.x+d+h),m=n/(f.depth||1);o.eachBefore((function(t){t.x=(t.x+h)*p,t.y=t.depth*m}))}return o}function i(e){var n=e.children,r=e.parent.children,o=e.i?r[e.i-1]:null;if(n){!function(t){for(var e,n=0,r=0,o=t.children,i=o.length;--i>=0;)(e=o[i]).z+=n,e.m+=n,n+=e.s+(r+=e.c)}(e);var i=(n[0].z+n[n.length-1].z)/2;o?(e.z=o.z+t(e._,o._),e.m=e.z-i):e.z=i}else o&&(e.z=o.z+t(e._,o._));e.parent.A=function(e,n,r){if(n){for(var o,i=e,s=e,a=n,l=i.parent.children[0],c=i.m,u=s.m,f=a.m,d=l.m;a=X(a),i=K(i),a&&i;)l=K(l),(s=X(s)).a=e,(o=a.z+f-i.z-c+t(a._,i._))>0&&(tt(et(a,e,r),e,o),c+=o,u+=o),f+=a.m,c+=i.m,d+=l.m,u+=s.m;a&&!X(s)&&(s.t=a,s.m+=f-u),i&&!K(l)&&(l.t=i,l.m+=c-d,r=e)}return r}(e,o,e.parent.A||r[0])}function s(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function a(t){t.x*=e,t.y=t.depth*n}return o.separation=function(e){return arguments.length?(t=e,o):t},o.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],o):r?null:[e,n]},o.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],o):r?[e,n]:null},o}function ot(t,e,n,r,o){for(var i,s=t.children,a=-1,l=s.length,c=t.value&&(o-n)/t.value;++a<l;)(i=s[a]).x0=e,i.x1=r,i.y0=n,i.y1=n+=i.value*c}nt.prototype=Object.create(h.prototype);var it=(1+Math.sqrt(5))/2;function st(t,e,n,r,o,i){for(var s,a,l,c,u,f,d,h,p,m,g,y=[],v=e.children,b=0,_=0,w=v.length,x=e.value;b<w;){l=o-n,c=i-r;do{u=v[_++].value}while(!u&&_<w);for(f=d=u,g=u*u*(m=Math.max(c/l,l/c)/(x*t)),p=Math.max(d/g,g/f);_<w;++_){if(u+=a=v[_].value,a<f&&(f=a),a>d&&(d=a),g=u*u*m,(h=Math.max(d/g,g/f))>p){u-=a;break}p=h}y.push(s={value:u,dice:l<c,children:v.slice(b,_)}),s.dice?z(s,n,r,o,x?r+=c*u/x:i):ot(s,n,r,x?n+=l*u/x:o,i),x-=u,b=_}return y}const at=function t(e){function n(t,n,r,o,i){st(e,t,n,r,o,i)}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(it);function lt(){var t=at,e=!1,n=1,r=1,o=[0],i=g,s=g,a=g,l=g,c=g;function u(t){return t.x0=t.y0=0,t.x1=n,t.y1=r,t.eachBefore(f),o=[0],e&&t.eachBefore(B),t}function f(e){var n=o[e.depth],r=e.x0+n,u=e.y0+n,f=e.x1-n,d=e.y1-n;f<r&&(r=f=(r+f)/2),d<u&&(u=d=(u+d)/2),e.x0=r,e.y0=u,e.x1=f,e.y1=d,e.children&&(n=o[e.depth+1]=i(e)/2,r+=c(e)-n,u+=s(e)-n,(f-=a(e)-n)<r&&(r=f=(r+f)/2),(d-=l(e)-n)<u&&(u=d=(u+d)/2),t(e,r,u,f,d))}return u.round=function(t){return arguments.length?(e=!!t,u):e},u.size=function(t){return arguments.length?(n=+t[0],r=+t[1],u):[n,r]},u.tile=function(e){return arguments.length?(t=m(e),u):t},u.padding=function(t){return arguments.length?u.paddingInner(t).paddingOuter(t):u.paddingInner()},u.paddingInner=function(t){return arguments.length?(i="function"==typeof t?t:y(+t),u):i},u.paddingOuter=function(t){return arguments.length?u.paddingTop(t).paddingRight(t).paddingBottom(t).paddingLeft(t):u.paddingTop()},u.paddingTop=function(t){return arguments.length?(s="function"==typeof t?t:y(+t),u):s},u.paddingRight=function(t){return arguments.length?(a="function"==typeof t?t:y(+t),u):a},u.paddingBottom=function(t){return arguments.length?(l="function"==typeof t?t:y(+t),u):l},u.paddingLeft=function(t){return arguments.length?(c="function"==typeof t?t:y(+t),u):c},u}function ct(t,e,n,r,o){var i,s,a=t.children,l=a.length,c=new Array(l+1);for(c[0]=s=i=0;i<l;++i)c[i+1]=s+=a[i].value;!function t(e,n,r,o,i,s,l){if(e>=n-1){var u=a[e];return u.x0=o,u.y0=i,u.x1=s,void(u.y1=l)}var f=c[e],d=r/2+f,h=e+1,p=n-1;for(;h<p;){var m=h+p>>>1;c[m]<d?h=m+1:p=m}d-c[h-1]<c[h]-d&&e+1<h&&--h;var g=c[h]-f,y=r-g;if(s-o>l-i){var v=r?(o*y+s*g)/r:s;t(e,h,g,o,i,v,l),t(h,n,y,v,i,s,l)}else{var b=r?(i*y+l*g)/r:l;t(e,h,g,o,i,s,b),t(h,n,y,o,b,s,l)}}(0,l,t.value,e,n,r,o)}function ut(t,e,n,r,o){(1&t.depth?ot:z)(t,e,n,r,o)}const ft=function t(e){function n(t,n,r,o,i){if((s=t._squarify)&&s.ratio===e)for(var s,a,l,c,u,f=-1,d=s.length,h=t.value;++f<d;){for(l=(a=s[f]).children,c=a.value=0,u=l.length;c<u;++c)a.value+=l[c].value;a.dice?z(a,n,r,o,h?r+=(i-r)*a.value/h:i):ot(a,n,r,h?n+=(o-n)*a.value/h:o,i),h-=a.value}else t._squarify=s=st(e,t,n,r,o,i),s.ratio=e}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(it)},4321:(t,e,n)=>{"use strict";n.d(e,{M:()=>s,Z:()=>i});var r=n(2303),o=n(5003);function i(t,e){return((0,o.v)(e)?o.Z:s)(t,e)}function s(t,e){var n,o=e?e.length:0,i=t?Math.min(o,t.length):0,s=new Array(i),a=new Array(o);for(n=0;n<i;++n)s[n]=(0,r.Z)(t[n],e[n]);for(;n<o;++n)a[n]=e[n];return function(t){for(n=0;n<i;++n)a[n]=s[n](t);return a}}},5409:(t,e,n)=>{"use strict";function r(t,e,n,r,o){var i=t*t,s=i*t;return((1-3*t+3*i-s)*e+(4-6*i+3*s)*n+(1+3*t+3*i-3*s)*r+s*o)/6}function o(t){var e=t.length-1;return function(n){var o=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),i=t[o],s=t[o+1],a=o>0?t[o-1]:2*i-s,l=o<e-1?t[o+2]:2*s-i;return r((n-o/e)*e,a,i,s,l)}}n.d(e,{Z:()=>o,t:()=>r})},7855:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(5409);function o(t){var e=t.length;return function(n){var o=Math.floor(((n%=1)<0?++n:n)*e),i=t[(o+e-1)%e],s=t[o%e],a=t[(o+1)%e],l=t[(o+2)%e];return(0,r.t)((n-o/e)*e,i,s,a,l)}}},8190:(t,e,n)=>{"use strict";n.d(e,{ZP:()=>a,wx:()=>i,yi:()=>s});var r=n(8486);function o(t,e){return function(n){return t+n*e}}function i(t,e){var n=e-t;return n?o(t,n>180||n<-180?n-360*Math.round(n/360):n):(0,r.Z)(isNaN(t)?e:t)}function s(t){return 1==(t=+t)?a:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):(0,r.Z)(isNaN(e)?n:e)}}function a(t,e){var n=e-t;return n?o(t,n):(0,r.Z)(isNaN(t)?e:t)}},8486:(t,e,n)=>{"use strict";n.d(e,{Z:()=>r});const r=t=>()=>t},711:(t,e,n)=>{"use strict";n.d(e,{B:()=>a,Z:()=>s});var r=n(3763),o=n(8190);function i(t){return function e(n){function i(e,i){var s=t((e=(0,r.Z)(e)).h,(i=(0,r.Z)(i)).h),a=(0,o.ZP)(e.s,i.s),l=(0,o.ZP)(e.l,i.l),c=(0,o.ZP)(e.opacity,i.opacity);return function(t){return e.h=s(t),e.s=a(t),e.l=l(Math.pow(t,n)),e.opacity=c(t),e+""}}return n=+n,i.gamma=e,i}(1)}const s=i(o.wx);var a=i(o.ZP)},6261:(t,e,n)=>{"use strict";function r(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}n.d(e,{Z:()=>r})},6778:(t,e,n)=>{"use strict";n.r(e),n.d(e,{interpolate:()=>r.Z,interpolateArray:()=>o.Z,interpolateBasis:()=>i.Z,interpolateBasisClosed:()=>s.Z,interpolateCubehelix:()=>M.Z,interpolateCubehelixLong:()=>M.B,interpolateDate:()=>a.Z,interpolateDiscrete:()=>l,interpolateHcl:()=>S,interpolateHclLong:()=>A,interpolateHsl:()=>w,interpolateHslLong:()=>x,interpolateHue:()=>u,interpolateLab:()=>q,interpolateNumber:()=>f.Z,interpolateNumberArray:()=>d.Z,interpolateObject:()=>h.Z,interpolateRgb:()=>v.ZP,interpolateRgbBasis:()=>v.hD,interpolateRgbBasisClosed:()=>v.YD,interpolateRound:()=>p.Z,interpolateString:()=>m.Z,interpolateTransformCss:()=>g.Y,interpolateTransformSvg:()=>g.w,interpolateZoom:()=>y.Z,piecewise:()=>T.Z,quantize:()=>C});var r=n(2303),o=n(4321),i=n(5409),s=n(7855),a=n(6261);function l(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}var c=n(8190);function u(t,e){var n=(0,c.wx)(+t,+e);return function(t){var e=n(t);return e-360*Math.floor(e/360)}}var f=n(8403),d=n(5003),h=n(8765),p=n(5250),m=n(9009),g=n(2650),y=n(6564),v=n(490),b=n(1495);function _(t){return function(e,n){var r=t((e=(0,b.Ym)(e)).h,(n=(0,b.Ym)(n)).h),o=(0,c.ZP)(e.s,n.s),i=(0,c.ZP)(e.l,n.l),s=(0,c.ZP)(e.opacity,n.opacity);return function(t){return e.h=r(t),e.s=o(t),e.l=i(t),e.opacity=s(t),e+""}}}const w=_(c.wx);var x=_(c.ZP),k=n(3334);function q(t,e){var n=(0,c.ZP)((t=(0,k.ZP)(t)).l,(e=(0,k.ZP)(e)).l),r=(0,c.ZP)(t.a,e.a),o=(0,c.ZP)(t.b,e.b),i=(0,c.ZP)(t.opacity,e.opacity);return function(e){return t.l=n(e),t.a=r(e),t.b=o(e),t.opacity=i(e),t+""}}function N(t){return function(e,n){var r=t((e=(0,k.Uc)(e)).h,(n=(0,k.Uc)(n)).h),o=(0,c.ZP)(e.c,n.c),i=(0,c.ZP)(e.l,n.l),s=(0,c.ZP)(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=o(t),e.l=i(t),e.opacity=s(t),e+""}}}const S=N(c.wx);var A=N(c.ZP),M=n(711),T=n(9444);function C(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t(r/(e-1));return n}},8403:(t,e,n)=>{"use strict";function r(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}n.d(e,{Z:()=>r})},5003:(t,e,n)=>{"use strict";function r(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,o=e.slice();return function(i){for(n=0;n<r;++n)o[n]=t[n]*(1-i)+e[n]*i;return o}}function o(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}n.d(e,{Z:()=>r,v:()=>o})},8765:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2303);function o(t,e){var n,o={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?o[n]=(0,r.Z)(t[n],e[n]):i[n]=e[n];return function(t){for(n in o)i[n]=o[n](t);return i}}},9444:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2303);function o(t,e){void 0===e&&(e=t,t=r.Z);for(var n=0,o=e.length-1,i=e[0],s=new Array(o<0?0:o);n<o;)s[n]=t(i,i=e[++n]);return function(t){var e=Math.max(0,Math.min(o-1,Math.floor(t*=o)));return s[e](t-e)}}},490:(t,e,n)=>{"use strict";n.d(e,{YD:()=>u,ZP:()=>a,hD:()=>c});var r=n(1495),o=n(5409),i=n(7855),s=n(8190);const a=function t(e){var n=(0,s.yi)(e);function o(t,e){var o=n((t=(0,r.B8)(t)).r,(e=(0,r.B8)(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),l=(0,s.ZP)(t.opacity,e.opacity);return function(e){return t.r=o(e),t.g=i(e),t.b=a(e),t.opacity=l(e),t+""}}return o.gamma=t,o}(1);function l(t){return function(e){var n,o,i=e.length,s=new Array(i),a=new Array(i),l=new Array(i);for(n=0;n<i;++n)o=(0,r.B8)(e[n]),s[n]=o.r||0,a[n]=o.g||0,l[n]=o.b||0;return s=t(s),a=t(a),l=t(l),o.opacity=1,function(t){return o.r=s(t),o.g=a(t),o.b=l(t),o+""}}}var c=l(o.Z),u=l(i.Z)},5250:(t,e,n)=>{"use strict";function r(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}n.d(e,{Z:()=>r})},9009:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s});var r=n(8403),o=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,i=new RegExp(o.source,"g");function s(t,e){var n,s,a,l=o.lastIndex=i.lastIndex=0,c=-1,u=[],f=[];for(t+="",e+="";(n=o.exec(t))&&(s=i.exec(e));)(a=s.index)>l&&(a=e.slice(l,a),u[c]?u[c]+=a:u[++c]=a),(n=n[0])===(s=s[0])?u[c]?u[c]+=s:u[++c]=s:(u[++c]=null,f.push({i:c,x:(0,r.Z)(n,s)})),l=i.lastIndex;return l<e.length&&(a=e.slice(l),u[c]?u[c]+=a:u[++c]=a),u.length<2?f[0]?function(t){return function(e){return t(e)+""}}(f[0].x):function(t){return function(){return t}}(e):(e=f.length,function(t){for(var n,r=0;r<e;++r)u[(n=f[r]).i]=n.x(t);return u.join("")})}},2650:(t,e,n)=>{"use strict";n.d(e,{Y:()=>c,w:()=>u});var r,o=n(8403),i=180/Math.PI,s={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function a(t,e,n,r,o,s){var a,l,c;return(a=Math.sqrt(t*t+e*e))&&(t/=a,e/=a),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),t*r<e*n&&(t=-t,e=-e,c=-c,a=-a),{translateX:o,translateY:s,rotate:Math.atan2(e,t)*i,skewX:Math.atan(c)*i,scaleX:a,scaleY:l}}function l(t,e,n,r){function i(t){return t.length?t.pop()+" ":""}return function(s,a){var l=[],c=[];return s=t(s),a=t(a),function(t,r,i,s,a,l){if(t!==i||r!==s){var c=a.push("translate(",null,e,null,n);l.push({i:c-4,x:(0,o.Z)(t,i)},{i:c-2,x:(0,o.Z)(r,s)})}else(i||s)&&a.push("translate("+i+e+s+n)}(s.translateX,s.translateY,a.translateX,a.translateY,l,c),function(t,e,n,s){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),s.push({i:n.push(i(n)+"rotate(",null,r)-2,x:(0,o.Z)(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(s.rotate,a.rotate,l,c),function(t,e,n,s){t!==e?s.push({i:n.push(i(n)+"skewX(",null,r)-2,x:(0,o.Z)(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(s.skewX,a.skewX,l,c),function(t,e,n,r,s,a){if(t!==n||e!==r){var l=s.push(i(s)+"scale(",null,",",null,")");a.push({i:l-4,x:(0,o.Z)(t,n)},{i:l-2,x:(0,o.Z)(e,r)})}else 1===n&&1===r||s.push(i(s)+"scale("+n+","+r+")")}(s.scaleX,s.scaleY,a.scaleX,a.scaleY,l,c),s=a=null,function(t){for(var e,n=-1,r=c.length;++n<r;)l[(e=c[n]).i]=e.x(t);return l.join("")}}}var c=l((function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?s:a(e.a,e.b,e.c,e.d,e.e,e.f)}),"px, ","px)","deg)"),u=l((function(t){return null==t?s:(r||(r=document.createElementNS("http://www.w3.org/2000/svg","g")),r.setAttribute("transform",t),(t=r.transform.baseVal.consolidate())?a((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):s)}),", ",")",")")},2303:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(1495),o=n(490),i=n(4321),s=n(6261),a=n(8403),l=n(8765),c=n(9009),u=n(8486),f=n(5003);function d(t,e){var n,d=typeof e;return null==e||"boolean"===d?(0,u.Z)(e):("number"===d?a.Z:"string"===d?(n=(0,r.ZP)(e))?(e=n,o.ZP):c.Z:e instanceof r.ZP?o.ZP:e instanceof Date?s.Z:(0,f.v)(e)?f.Z:Array.isArray(e)?i.M:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?l.Z:a.Z)(t,e)}},6564:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});function r(t){return((t=Math.exp(t))+1/t)/2}const o=function t(e,n,o){function i(t,i){var s,a,l=t[0],c=t[1],u=t[2],f=i[0],d=i[1],h=i[2],p=f-l,m=d-c,g=p*p+m*m;if(g<1e-12)a=Math.log(h/u)/e,s=function(t){return[l+t*p,c+t*m,u*Math.exp(e*t*a)]};else{var y=Math.sqrt(g),v=(h*h-u*u+o*g)/(2*u*n*y),b=(h*h-u*u-o*g)/(2*h*n*y),_=Math.log(Math.sqrt(v*v+1)-v),w=Math.log(Math.sqrt(b*b+1)-b);a=(w-_)/e,s=function(t){var o,i=t*a,s=r(_),f=u/(n*y)*(s*(o=e*i+_,((o=Math.exp(2*o))-1)/(o+1))-function(t){return((t=Math.exp(t))-1/t)/2}(_));return[l+f*p,c+f*m,u*s/r(e*i+_)]}}return s.duration=1e3*a*e/Math.SQRT2,s}return i.rho=function(e){var n=Math.max(.001,+e),r=n*n;return t(n,r,r*r)},i}(Math.SQRT2,2,4)},895:(t,e,n)=>{"use strict";function r(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}n.r(e),n.d(e,{interpolateBlues:()=>it,interpolateBrBG:()=>y,interpolateBuGn:()=>I,interpolateBuPu:()=>F,interpolateCividis:()=>gt,interpolateCool:()=>wt,interpolateCubehelixDefault:()=>bt,interpolateGnBu:()=>D,interpolateGreens:()=>at,interpolateGreys:()=>ct,interpolateInferno:()=>Ot,interpolateMagma:()=>jt,interpolateOrRd:()=>z,interpolateOranges:()=>mt,interpolatePRGn:()=>b,interpolatePiYG:()=>w,interpolatePlasma:()=>Et,interpolatePuBu:()=>U,interpolatePuBuGn:()=>$,interpolatePuOr:()=>k,interpolatePuRd:()=>W,interpolatePurples:()=>ft,interpolateRainbow:()=>kt,interpolateRdBu:()=>N,interpolateRdGy:()=>A,interpolateRdPu:()=>V,interpolateRdYlBu:()=>T,interpolateRdYlGn:()=>j,interpolateReds:()=>ht,interpolateSinebow:()=>At,interpolateSpectral:()=>E,interpolateTurbo:()=>Mt,interpolateViridis:()=>Ct,interpolateWarm:()=>_t,interpolateYlGn:()=>X,interpolateYlGnBu:()=>Q,interpolateYlOrBr:()=>et,interpolateYlOrRd:()=>rt,schemeAccent:()=>i,schemeBlues:()=>ot,schemeBrBG:()=>g,schemeBuGn:()=>R,schemeBuPu:()=>P,schemeCategory10:()=>o,schemeDark2:()=>s,schemeGnBu:()=>L,schemeGreens:()=>st,schemeGreys:()=>lt,schemeOrRd:()=>B,schemeOranges:()=>pt,schemePRGn:()=>v,schemePaired:()=>a,schemePastel1:()=>l,schemePastel2:()=>c,schemePiYG:()=>_,schemePuBu:()=>G,schemePuBuGn:()=>Z,schemePuOr:()=>x,schemePuRd:()=>H,schemePurples:()=>ut,schemeRdBu:()=>q,schemeRdGy:()=>S,schemeRdPu:()=>J,schemeRdYlBu:()=>M,schemeRdYlGn:()=>C,schemeReds:()=>dt,schemeSet1:()=>u,schemeSet2:()=>f,schemeSet3:()=>d,schemeSpectral:()=>O,schemeTableau10:()=>h,schemeYlGn:()=>K,schemeYlGnBu:()=>Y,schemeYlOrBr:()=>tt,schemeYlOrRd:()=>nt});const o=r("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),i=r("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),s=r("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),a=r("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),l=r("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),c=r("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),u=r("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),f=r("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),d=r("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),h=r("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");var p=n(490);const m=t=>(0,p.hD)(t[t.length-1]);var g=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(r);const y=m(g);var v=new Array(3).concat("af8dc3f7f7f77fbf7b","7b3294c2a5cfa6dba0008837","7b3294c2a5cff7f7f7a6dba0008837","762a83af8dc3e7d4e8d9f0d37fbf7b1b7837","762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837","762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837","762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837","40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b","40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b").map(r);const b=m(v);var _=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(r);const w=m(_);var x=new Array(3).concat("998ec3f7f7f7f1a340","5e3c99b2abd2fdb863e66101","5e3c99b2abd2f7f7f7fdb863e66101","542788998ec3d8daebfee0b6f1a340b35806","542788998ec3d8daebf7f7f7fee0b6f1a340b35806","5427888073acb2abd2d8daebfee0b6fdb863e08214b35806","5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806","2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08","2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08").map(r);const k=m(x);var q=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(r);const N=m(q);var S=new Array(3).concat("ef8a62ffffff999999","ca0020f4a582bababa404040","ca0020f4a582ffffffbababa404040","b2182bef8a62fddbc7e0e0e09999994d4d4d","b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d","b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d","b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d","67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a","67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a").map(r);const A=m(S);var M=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(r);const T=m(M);var C=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(r);const j=m(C);var O=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(r);const E=m(O);var R=new Array(3).concat("e5f5f999d8c92ca25f","edf8fbb2e2e266c2a4238b45","edf8fbb2e2e266c2a42ca25f006d2c","edf8fbccece699d8c966c2a42ca25f006d2c","edf8fbccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b").map(r);const I=m(R);var P=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(r);const F=m(P);var L=new Array(3).concat("e0f3dba8ddb543a2ca","f0f9e8bae4bc7bccc42b8cbe","f0f9e8bae4bc7bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081").map(r);const D=m(L);var B=new Array(3).concat("fee8c8fdbb84e34a33","fef0d9fdcc8afc8d59d7301f","fef0d9fdcc8afc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000").map(r);const z=m(B);var Z=new Array(3).concat("ece2f0a6bddb1c9099","f6eff7bdc9e167a9cf02818a","f6eff7bdc9e167a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636").map(r);const $=m(Z);var G=new Array(3).concat("ece7f2a6bddb2b8cbe","f1eef6bdc9e174a9cf0570b0","f1eef6bdc9e174a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858").map(r);const U=m(G);var H=new Array(3).concat("e7e1efc994c7dd1c77","f1eef6d7b5d8df65b0ce1256","f1eef6d7b5d8df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f").map(r);const W=m(H);var J=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(r);const V=m(J);var Y=new Array(3).concat("edf8b17fcdbb2c7fb8","ffffcca1dab441b6c4225ea8","ffffcca1dab441b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58").map(r);const Q=m(Y);var K=new Array(3).concat("f7fcb9addd8e31a354","ffffccc2e69978c679238443","ffffccc2e69978c67931a354006837","ffffccd9f0a3addd8e78c67931a354006837","ffffccd9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529").map(r);const X=m(K);var tt=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(r);const et=m(tt);var nt=new Array(3).concat("ffeda0feb24cf03b20","ffffb2fecc5cfd8d3ce31a1c","ffffb2fecc5cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026").map(r);const rt=m(nt);var ot=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(r);const it=m(ot);var st=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(r);const at=m(st);var lt=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(r);const ct=m(lt);var ut=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(r);const ft=m(ut);var dt=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(r);const ht=m(dt);var pt=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(r);const mt=m(pt);function gt(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-t*(35.34-t*(2381.73-t*(6402.7-t*(7024.72-2710.57*t)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+t*(170.73+t*(52.82-t*(131.46-t*(176.58-67.37*t)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+t*(442.36-t*(2482.43-t*(6167.24-t*(6614.94-2475.67*t)))))))+")"}var yt=n(3763),vt=n(711);const bt=(0,vt.B)((0,yt.Z)(300,.5,0),(0,yt.Z)(-240,.5,1));var _t=(0,vt.B)((0,yt.Z)(-100,.75,.35),(0,yt.Z)(80,1.5,.8)),wt=(0,vt.B)((0,yt.Z)(260,.75,.35),(0,yt.Z)(80,1.5,.8)),xt=(0,yt.Z)();function kt(t){(t<0||t>1)&&(t-=Math.floor(t));var e=Math.abs(t-.5);return xt.h=360*t-100,xt.s=1.5-1.5*e,xt.l=.8-.9*e,xt+""}var qt=(0,n(1495).B8)(),Nt=Math.PI/3,St=2*Math.PI/3;function At(t){var e;return t=(.5-t)*Math.PI,qt.r=255*(e=Math.sin(t))*e,qt.g=255*(e=Math.sin(t+Nt))*e,qt.b=255*(e=Math.sin(t+St))*e,qt+""}function Mt(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+t*(1172.33-t*(10793.56-t*(33300.12-t*(38394.49-14825.05*t)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+t*(557.33+t*(1225.33-t*(3574.96-t*(1073.77+707.56*t)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+t*(3211.1-t*(15327.97-t*(27814-t*(22569.18-6838.66*t)))))))+")"}function Tt(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}const Ct=Tt(r("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var jt=Tt(r("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),Ot=Tt(r("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),Et=Tt(r("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"))},2282:(t,e,n)=>{"use strict";n.r(e),n.d(e,{scaleBand:()=>c,scaleDiverging:()=>Lt,scaleDivergingLog:()=>Dt,scaleDivergingPow:()=>zt,scaleDivergingSqrt:()=>Zt,scaleDivergingSymlog:()=>Bt,scaleIdentity:()=>R,scaleImplicit:()=>a,scaleLinear:()=>E,scaleLog:()=>$,scaleOrdinal:()=>l,scalePoint:()=>f,scalePow:()=>K,scaleQuantile:()=>it,scaleQuantize:()=>st,scaleRadial:()=>nt,scaleSequential:()=>Ct,scaleSequentialLog:()=>jt,scaleSequentialPow:()=>Et,scaleSequentialQuantile:()=>It,scaleSequentialSqrt:()=>Rt,scaleSequentialSymlog:()=>Ot,scaleSqrt:()=>X,scaleSymlog:()=>W,scaleThreshold:()=>at,scaleTime:()=>_t,scaleUtc:()=>At,tickFormat:()=>j});var r=n(1265);function o(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function i(t,e){switch(arguments.length){case 0:break;case 1:"function"==typeof t?this.interpolator(t):this.range(t);break;default:this.domain(t),"function"==typeof e?this.interpolator(e):this.range(e)}return this}var s=n(8828);const a=Symbol("implicit");function l(){var t=new s.L,e=[],n=[],r=a;function i(o){let i=t.get(o);if(void 0===i){if(r!==a)return r;t.set(o,i=e.push(o)-1)}return n[i%n.length]}return i.domain=function(n){if(!arguments.length)return e.slice();e=[],t=new s.L;for(const r of n)t.has(r)||t.set(r,e.push(r)-1);return i},i.range=function(t){return arguments.length?(n=Array.from(t),i):n.slice()},i.unknown=function(t){return arguments.length?(r=t,i):r},i.copy=function(){return l(e,n).unknown(r)},o.apply(i,arguments),i}function c(){var t,e,n=l().unknown(void 0),i=n.domain,s=n.range,a=0,u=1,f=!1,d=0,h=0,p=.5;function m(){var n=i().length,o=u<a,l=o?u:a,c=o?a:u;t=(c-l)/Math.max(1,n-d+2*h),f&&(t=Math.floor(t)),l+=(c-l-t*(n-d))*p,e=t*(1-d),f&&(l=Math.round(l),e=Math.round(e));var m=(0,r.Z)(n).map((function(e){return l+t*e}));return s(o?m.reverse():m)}return delete n.unknown,n.domain=function(t){return arguments.length?(i(t),m()):i()},n.range=function(t){return arguments.length?([a,u]=t,a=+a,u=+u,m()):[a,u]},n.rangeRound=function(t){return[a,u]=t,a=+a,u=+u,f=!0,m()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(f=!!t,m()):f},n.padding=function(t){return arguments.length?(d=Math.min(1,h=+t),m()):d},n.paddingInner=function(t){return arguments.length?(d=Math.min(1,t),m()):d},n.paddingOuter=function(t){return arguments.length?(h=+t,m()):h},n.align=function(t){return arguments.length?(p=Math.max(0,Math.min(1,t)),m()):p},n.copy=function(){return c(i(),[a,u]).round(f).paddingInner(d).paddingOuter(h).align(p)},o.apply(m(),arguments)}function u(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return u(e())},t}function f(){return u(c.apply(null,arguments).paddingInner(1))}var d=n(6106),h=n(5519),p=n(2303),m=n(8403),g=n(5250);function y(t){return+t}var v=[0,1];function b(t){return t}function _(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function w(t,e,n){var r=t[0],o=t[1],i=e[0],s=e[1];return o<r?(r=_(o,r),i=n(s,i)):(r=_(r,o),i=n(i,s)),function(t){return i(r(t))}}function x(t,e,n){var r=Math.min(t.length,e.length)-1,o=new Array(r),i=new Array(r),s=-1;for(t[r]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++s<r;)o[s]=_(t[s],t[s+1]),i[s]=n(e[s],e[s+1]);return function(e){var n=(0,h.ZP)(t,e,1,r)-1;return i[n](o[n](e))}}function k(t,e){return e.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function q(){var t,e,n,r,o,i,s=v,a=v,l=p.Z,c=b;function u(){var t,e,n,l=Math.min(s.length,a.length);return c!==b&&(t=s[0],e=s[l-1],t>e&&(n=t,t=e,e=n),c=function(n){return Math.max(t,Math.min(e,n))}),r=l>2?x:w,o=i=null,f}function f(e){return null==e||isNaN(e=+e)?n:(o||(o=r(s.map(t),a,l)))(t(c(e)))}return f.invert=function(n){return c(e((i||(i=r(a,s.map(t),m.Z)))(n)))},f.domain=function(t){return arguments.length?(s=Array.from(t,y),u()):s.slice()},f.range=function(t){return arguments.length?(a=Array.from(t),u()):a.slice()},f.rangeRound=function(t){return a=Array.from(t),l=g.Z,u()},f.clamp=function(t){return arguments.length?(c=!!t||b,u()):c!==b},f.interpolate=function(t){return arguments.length?(l=t,u()):l},f.unknown=function(t){return arguments.length?(n=t,f):n},function(n,r){return t=n,e=r,u()}}function N(){return q()(b,b)}var S=n(7259),A=n(3150),M=n(2163),T=n(3621),C=n(9680);function j(t,e,n,r){var o,i=(0,d.ly)(t,e,n);switch((r=(0,S.Z)(null==r?",f":r)).type){case"s":var s=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(o=(0,A.Z)(i,s))||(r.precision=o),(0,M.jH)(r,s);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(o=(0,T.Z)(i,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=o-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(o=(0,C.Z)(i))||(r.precision=o-2*("%"===r.type))}return(0,M.WU)(r)}function O(t){var e=t.domain;return t.ticks=function(t){var n=e();return(0,d.ZP)(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return j(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var r,o,i=e(),s=0,a=i.length-1,l=i[s],c=i[a],u=10;for(c<l&&(o=l,l=c,c=o,o=s,s=a,a=o);u-- >0;){if((o=(0,d.G9)(l,c,n))===r)return i[s]=l,i[a]=c,e(i);if(o>0)l=Math.floor(l/o)*o,c=Math.ceil(c/o)*o;else{if(!(o<0))break;l=Math.ceil(l*o)/o,c=Math.floor(c*o)/o}r=o}return t},t}function E(){var t=N();return t.copy=function(){return k(t,E())},o.apply(t,arguments),O(t)}function R(t){var e;function n(t){return null==t||isNaN(t=+t)?e:t}return n.invert=n,n.domain=n.range=function(e){return arguments.length?(t=Array.from(e,y),n):t.slice()},n.unknown=function(t){return arguments.length?(e=t,n):e},n.copy=function(){return R(t).unknown(e)},t=arguments.length?Array.from(t,y):[0,1],O(n)}function I(t,e){var n,r=0,o=(t=t.slice()).length-1,i=t[r],s=t[o];return s<i&&(n=r,r=o,o=n,n=i,i=s,s=n),t[r]=e.floor(i),t[o]=e.ceil(s),t}function P(t){return Math.log(t)}function F(t){return Math.exp(t)}function L(t){return-Math.log(-t)}function D(t){return-Math.exp(-t)}function B(t){return isFinite(t)?+("1e"+t):t<0?0:t}function z(t){return(e,n)=>-t(-e,n)}function Z(t){const e=t(P,F),n=e.domain;let r,o,i=10;function s(){return r=function(t){return t===Math.E?Math.log:10===t&&Math.log10||2===t&&Math.log2||(t=Math.log(t),e=>Math.log(e)/t)}(i),o=function(t){return 10===t?B:t===Math.E?Math.exp:e=>Math.pow(t,e)}(i),n()[0]<0?(r=z(r),o=z(o),t(L,D)):t(P,F),e}return e.base=function(t){return arguments.length?(i=+t,s()):i},e.domain=function(t){return arguments.length?(n(t),s()):n()},e.ticks=t=>{const e=n();let s=e[0],a=e[e.length-1];const l=a<s;l&&([s,a]=[a,s]);let c,u,f=r(s),h=r(a);const p=null==t?10:+t;let m=[];if(!(i%1)&&h-f<p){if(f=Math.floor(f),h=Math.ceil(h),s>0){for(;f<=h;++f)for(c=1;c<i;++c)if(u=f<0?c/o(-f):c*o(f),!(u<s)){if(u>a)break;m.push(u)}}else for(;f<=h;++f)for(c=i-1;c>=1;--c)if(u=f>0?c/o(-f):c*o(f),!(u<s)){if(u>a)break;m.push(u)}2*m.length<p&&(m=(0,d.ZP)(s,a,p))}else m=(0,d.ZP)(f,h,Math.min(h-f,p)).map(o);return l?m.reverse():m},e.tickFormat=(t,n)=>{if(null==t&&(t=10),null==n&&(n=10===i?"s":","),"function"!=typeof n&&(i%1||null!=(n=(0,S.Z)(n)).precision||(n.trim=!0),n=(0,M.WU)(n)),t===1/0)return n;const s=Math.max(1,i*t/e.ticks().length);return t=>{let e=t/o(Math.round(r(t)));return e*i<i-.5&&(e*=i),e<=s?n(t):""}},e.nice=()=>n(I(n(),{floor:t=>o(Math.floor(r(t))),ceil:t=>o(Math.ceil(r(t)))})),e}function $(){const t=Z(q()).domain([1,10]);return t.copy=()=>k(t,$()).base(t.base()),o.apply(t,arguments),t}function G(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function U(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function H(t){var e=1,n=t(G(e),U(e));return n.constant=function(n){return arguments.length?t(G(e=+n),U(e)):e},O(n)}function W(){var t=H(q());return t.copy=function(){return k(t,W()).constant(t.constant())},o.apply(t,arguments)}function J(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function V(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function Y(t){return t<0?-t*t:t*t}function Q(t){var e=t(b,b),n=1;function r(){return 1===n?t(b,b):.5===n?t(V,Y):t(J(n),J(1/n))}return e.exponent=function(t){return arguments.length?(n=+t,r()):n},O(e)}function K(){var t=Q(q());return t.copy=function(){return k(t,K()).exponent(t.exponent())},o.apply(t,arguments),t}function X(){return K.apply(null,arguments).exponent(.5)}function tt(t){return Math.sign(t)*t*t}function et(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}function nt(){var t,e=N(),n=[0,1],r=!1;function i(n){var o=et(e(n));return isNaN(o)?t:r?Math.round(o):o}return i.invert=function(t){return e.invert(tt(t))},i.domain=function(t){return arguments.length?(e.domain(t),i):e.domain()},i.range=function(t){return arguments.length?(e.range((n=Array.from(t,y)).map(tt)),i):n.slice()},i.rangeRound=function(t){return i.range(t).round(!0)},i.round=function(t){return arguments.length?(r=!!t,i):r},i.clamp=function(t){return arguments.length?(e.clamp(t),i):e.clamp()},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return nt(e.domain(),n).round(r).clamp(e.clamp()).unknown(t)},o.apply(i,arguments),O(i)}var rt=n(1177),ot=n(9263);function it(){var t,e=[],n=[],r=[];function i(){var t=0,o=Math.max(1,n.length);for(r=new Array(o-1);++t<o;)r[t-1]=(0,rt.s7)(e,t/o);return s}function s(e){return null==e||isNaN(e=+e)?t:n[(0,h.ZP)(r,e)]}return s.invertExtent=function(t){var o=n.indexOf(t);return o<0?[NaN,NaN]:[o>0?r[o-1]:e[0],o<r.length?r[o]:e[e.length-1]]},s.domain=function(t){if(!arguments.length)return e.slice();e=[];for(let n of t)null==n||isNaN(n=+n)||e.push(n);return e.sort(ot.Z),i()},s.range=function(t){return arguments.length?(n=Array.from(t),i()):n.slice()},s.unknown=function(e){return arguments.length?(t=e,s):t},s.quantiles=function(){return r.slice()},s.copy=function(){return it().domain(e).range(n).unknown(t)},o.apply(s,arguments)}function st(){var t,e=0,n=1,r=1,i=[.5],s=[0,1];function a(e){return null!=e&&e<=e?s[(0,h.ZP)(i,e,0,r)]:t}function l(){var t=-1;for(i=new Array(r);++t<r;)i[t]=((t+1)*n-(t-r)*e)/(r+1);return a}return a.domain=function(t){return arguments.length?([e,n]=t,e=+e,n=+n,l()):[e,n]},a.range=function(t){return arguments.length?(r=(s=Array.from(t)).length-1,l()):s.slice()},a.invertExtent=function(t){var o=s.indexOf(t);return o<0?[NaN,NaN]:o<1?[e,i[0]]:o>=r?[i[r-1],n]:[i[o-1],i[o]]},a.unknown=function(e){return arguments.length?(t=e,a):a},a.thresholds=function(){return i.slice()},a.copy=function(){return st().domain([e,n]).range(s).unknown(t)},o.apply(O(a),arguments)}function at(){var t,e=[.5],n=[0,1],r=1;function i(o){return null!=o&&o<=o?n[(0,h.ZP)(e,o,0,r)]:t}return i.domain=function(t){return arguments.length?(e=Array.from(t),r=Math.min(e.length,n.length-1),i):e.slice()},i.range=function(t){return arguments.length?(n=Array.from(t),r=Math.min(e.length,n.length-1),i):n.slice()},i.invertExtent=function(t){var r=n.indexOf(t);return[e[r-1],e[r]]},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return at().domain(e).range(n).unknown(t)},o.apply(i,arguments)}var lt=n(7150),ct=n(2311),ut=n(7905),ft=n(6018),dt=n(8467),ht=n(6596),pt=n(2991),mt=n(1343),gt=n(1852);function yt(t){return new Date(t)}function vt(t){return t instanceof Date?+t:+new Date(+t)}function bt(t,e,n,r,o,i,s,a,l,c){var u=N(),f=u.invert,d=u.domain,h=c(".%L"),p=c(":%S"),m=c("%I:%M"),g=c("%I %p"),y=c("%a %d"),v=c("%b %d"),b=c("%B"),_=c("%Y");function w(t){return(l(t)<t?h:a(t)<t?p:s(t)<t?m:i(t)<t?g:r(t)<t?o(t)<t?y:v:n(t)<t?b:_)(t)}return u.invert=function(t){return new Date(f(t))},u.domain=function(t){return arguments.length?d(Array.from(t,vt)):d().map(yt)},u.ticks=function(e){var n=d();return t(n[0],n[n.length-1],null==e?10:e)},u.tickFormat=function(t,e){return null==e?w:c(e)},u.nice=function(t){var n=d();return t&&"function"==typeof t.range||(t=e(n[0],n[n.length-1],null==t?10:t)),t?d(I(n,t)):u},u.copy=function(){return k(u,bt(t,e,n,r,o,i,s,a,l,c))},u}function _t(){return o.apply(bt(lt.jK,lt._g,ct.Z,ut.Z,ft.OM,dt.Z,ht.Z,pt.Z,mt.Z,gt.i$).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}var wt=n(4552),xt=n(7351),kt=n(1887),qt=n(7445),Nt=n(8927),St=n(8593);function At(){return o.apply(bt(lt.WG,lt.jo,wt.Z,xt.Z,kt.Ox,qt.Z,Nt.Z,St.Z,mt.Z,gt.g0).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)}function Mt(){var t,e,n,r,o,i=0,s=1,a=b,l=!1;function c(e){return null==e||isNaN(e=+e)?o:a(0===n?.5:(e=(r(e)-t)*n,l?Math.max(0,Math.min(1,e)):e))}function u(t){return function(e){var n,r;return arguments.length?([n,r]=e,a=t(n,r),c):[a(0),a(1)]}}return c.domain=function(o){return arguments.length?([i,s]=o,t=r(i=+i),e=r(s=+s),n=t===e?0:1/(e-t),c):[i,s]},c.clamp=function(t){return arguments.length?(l=!!t,c):l},c.interpolator=function(t){return arguments.length?(a=t,c):a},c.range=u(p.Z),c.rangeRound=u(g.Z),c.unknown=function(t){return arguments.length?(o=t,c):o},function(o){return r=o,t=o(i),e=o(s),n=t===e?0:1/(e-t),c}}function Tt(t,e){return e.domain(t.domain()).interpolator(t.interpolator()).clamp(t.clamp()).unknown(t.unknown())}function Ct(){var t=O(Mt()(b));return t.copy=function(){return Tt(t,Ct())},i.apply(t,arguments)}function jt(){var t=Z(Mt()).domain([1,10]);return t.copy=function(){return Tt(t,jt()).base(t.base())},i.apply(t,arguments)}function Ot(){var t=H(Mt());return t.copy=function(){return Tt(t,Ot()).constant(t.constant())},i.apply(t,arguments)}function Et(){var t=Q(Mt());return t.copy=function(){return Tt(t,Et()).exponent(t.exponent())},i.apply(t,arguments)}function Rt(){return Et.apply(null,arguments).exponent(.5)}function It(){var t=[],e=b;function n(n){if(null!=n&&!isNaN(n=+n))return e(((0,h.ZP)(t,n,1)-1)/(t.length-1))}return n.domain=function(e){if(!arguments.length)return t.slice();t=[];for(let n of e)null==n||isNaN(n=+n)||t.push(n);return t.sort(ot.Z),n},n.interpolator=function(t){return arguments.length?(e=t,n):e},n.range=function(){return t.map(((n,r)=>e(r/(t.length-1))))},n.quantiles=function(e){return Array.from({length:e+1},((n,r)=>(0,rt.ZP)(t,r/e)))},n.copy=function(){return It(e).domain(t)},i.apply(n,arguments)}var Pt=n(9444);function Ft(){var t,e,n,r,o,i,s,a=0,l=.5,c=1,u=1,f=b,d=!1;function h(t){return isNaN(t=+t)?s:(t=.5+((t=+i(t))-e)*(u*t<u*e?r:o),f(d?Math.max(0,Math.min(1,t)):t))}function m(t){return function(e){var n,r,o;return arguments.length?([n,r,o]=e,f=(0,Pt.Z)(t,[n,r,o]),h):[f(0),f(.5),f(1)]}}return h.domain=function(s){return arguments.length?([a,l,c]=s,t=i(a=+a),e=i(l=+l),n=i(c=+c),r=t===e?0:.5/(e-t),o=e===n?0:.5/(n-e),u=e<t?-1:1,h):[a,l,c]},h.clamp=function(t){return arguments.length?(d=!!t,h):d},h.interpolator=function(t){return arguments.length?(f=t,h):f},h.range=m(p.Z),h.rangeRound=m(g.Z),h.unknown=function(t){return arguments.length?(s=t,h):s},function(s){return i=s,t=s(a),e=s(l),n=s(c),r=t===e?0:.5/(e-t),o=e===n?0:.5/(n-e),u=e<t?-1:1,h}}function Lt(){var t=O(Ft()(b));return t.copy=function(){return Tt(t,Lt())},i.apply(t,arguments)}function Dt(){var t=Z(Ft()).domain([.1,1,10]);return t.copy=function(){return Tt(t,Dt()).base(t.base())},i.apply(t,arguments)}function Bt(){var t=H(Ft());return t.copy=function(){return Tt(t,Bt()).constant(t.constant())},i.apply(t,arguments)}function zt(){var t=Q(Ft());return t.copy=function(){return Tt(t,zt()).exponent(t.exponent())},i.apply(t,arguments)}function Zt(){return zt.apply(null,arguments).exponent(.5)}},1852:(t,e,n)=>{"use strict";n.d(e,{Z1:()=>i,ZP:()=>c,g0:()=>s,i$:()=>o,wp:()=>a});var r,o,i,s,a,l=n(3015);function c(t){return r=(0,l.Z)(t),o=r.format,i=r.parse,s=r.utcFormat,a=r.utcParse,r}c({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]})},3015:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(1887),o=n(7445),i=n(6018),s=n(8467),a=n(2311),l=n(4552);function c(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function u(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function f(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}function d(t){var e=t.dateTime,n=t.date,a=t.time,l=t.periods,d=t.days,p=t.shortDays,m=t.months,g=t.shortMonths,y=b(l),v=_(l),K=b(d),vt=_(d),Ct=b(p),jt=_(p),Ot=b(m),Et=_(m),Rt=b(g),It=_(g),Pt={a:function(t){return p[t.getDay()]},A:function(t){return d[t.getDay()]},b:function(t){return g[t.getMonth()]},B:function(t){return m[t.getMonth()]},c:null,d:z,e:z,f:H,g:rt,G:it,H:Z,I:$,j:G,L:U,m:W,M:J,p:function(t){return l[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Mt,s:Tt,S:V,u:Y,U:Q,V:X,w:tt,W:et,x:null,X:null,y:nt,Y:ot,Z:st,"%":At},Ft={a:function(t){return p[t.getUTCDay()]},A:function(t){return d[t.getUTCDay()]},b:function(t){return g[t.getUTCMonth()]},B:function(t){return m[t.getUTCMonth()]},c:null,d:at,e:at,f:dt,g:kt,G:Nt,H:lt,I:ct,j:ut,L:ft,m:ht,M:pt,p:function(t){return l[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Mt,s:Tt,S:mt,u:gt,U:yt,V:bt,w:_t,W:wt,x:null,X:null,y:xt,Y:qt,Z:St,"%":At},Lt={a:function(t,e,n){var r=Ct.exec(e.slice(n));return r?(t.w=jt.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=K.exec(e.slice(n));return r?(t.w=vt.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=Rt.exec(e.slice(n));return r?(t.m=It.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=Ot.exec(e.slice(n));return r?(t.m=Et.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return zt(t,e,n,r)},d:j,e:j,f:F,g:A,G:S,H:E,I:E,j:O,L:P,m:C,M:R,p:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.p=v.get(r[0].toLowerCase()),n+r[0].length):-1},q:T,Q:D,s:B,S:I,u:x,U:k,V:q,w,W:N,x:function(t,e,r){return zt(t,n,e,r)},X:function(t,e,n){return zt(t,a,e,n)},y:A,Y:S,Z:M,"%":L};function Dt(t,e){return function(n){var r,o,i,s=[],a=-1,l=0,c=t.length;for(n instanceof Date||(n=new Date(+n));++a<c;)37===t.charCodeAt(a)&&(s.push(t.slice(l,a)),null!=(o=h[r=t.charAt(++a)])?r=t.charAt(++a):o="e"===r?" ":"0",(i=e[r])&&(r=i(n,o)),s.push(r),l=a+1);return s.push(t.slice(l,a)),s.join("")}}function Bt(t,e){return function(n){var a,l,d=f(1900,void 0,1);if(zt(d,t,n+="",0)!=n.length)return null;if("Q"in d)return new Date(d.Q);if("s"in d)return new Date(1e3*d.s+("L"in d?d.L:0));if(e&&!("Z"in d)&&(d.Z=0),"p"in d&&(d.H=d.H%12+12*d.p),void 0===d.m&&(d.m="q"in d?d.q:0),"V"in d){if(d.V<1||d.V>53)return null;"w"in d||(d.w=1),"Z"in d?(l=(a=u(f(d.y,0,1))).getUTCDay(),a=l>4||0===l?r.l6.ceil(a):(0,r.l6)(a),a=o.Z.offset(a,7*(d.V-1)),d.y=a.getUTCFullYear(),d.m=a.getUTCMonth(),d.d=a.getUTCDate()+(d.w+6)%7):(l=(a=c(f(d.y,0,1))).getDay(),a=l>4||0===l?i.wA.ceil(a):(0,i.wA)(a),a=s.Z.offset(a,7*(d.V-1)),d.y=a.getFullYear(),d.m=a.getMonth(),d.d=a.getDate()+(d.w+6)%7)}else("W"in d||"U"in d)&&("w"in d||(d.w="u"in d?d.u%7:"W"in d?1:0),l="Z"in d?u(f(d.y,0,1)).getUTCDay():c(f(d.y,0,1)).getDay(),d.m=0,d.d="W"in d?(d.w+6)%7+7*d.W-(l+5)%7:d.w+7*d.U-(l+6)%7);return"Z"in d?(d.H+=d.Z/100|0,d.M+=d.Z%100,u(d)):c(d)}}function zt(t,e,n,r){for(var o,i,s=0,a=e.length,l=n.length;s<a;){if(r>=l)return-1;if(37===(o=e.charCodeAt(s++))){if(o=e.charAt(s++),!(i=Lt[o in h?e.charAt(s++):o])||(r=i(t,n,r))<0)return-1}else if(o!=n.charCodeAt(r++))return-1}return r}return Pt.x=Dt(n,Pt),Pt.X=Dt(a,Pt),Pt.c=Dt(e,Pt),Ft.x=Dt(n,Ft),Ft.X=Dt(a,Ft),Ft.c=Dt(e,Ft),{format:function(t){var e=Dt(t+="",Pt);return e.toString=function(){return t},e},parse:function(t){var e=Bt(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=Dt(t+="",Ft);return e.toString=function(){return t},e},utcParse:function(t){var e=Bt(t+="",!0);return e.toString=function(){return t},e}}}var h={"-":"",_:" ",0:"0"},p=/^\s*\d+/,m=/^%/,g=/[\\^$*+?|[\]().{}]/g;function y(t,e,n){var r=t<0?"-":"",o=(r?-t:t)+"",i=o.length;return r+(i<n?new Array(n-i+1).join(e)+o:o)}function v(t){return t.replace(g,"\\$&")}function b(t){return new RegExp("^(?:"+t.map(v).join("|")+")","i")}function _(t){return new Map(t.map(((t,e)=>[t.toLowerCase(),e])))}function w(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function x(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function k(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function q(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function N(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function S(t,e,n){var r=p.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function A(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function M(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function T(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function C(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function j(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function O(t,e,n){var r=p.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function E(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function R(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function I(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function P(t,e,n){var r=p.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function F(t,e,n){var r=p.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function L(t,e,n){var r=m.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function D(t,e,n){var r=p.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function B(t,e,n){var r=p.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function z(t,e){return y(t.getDate(),e,2)}function Z(t,e){return y(t.getHours(),e,2)}function $(t,e){return y(t.getHours()%12||12,e,2)}function G(t,e){return y(1+s.Z.count((0,a.Z)(t),t),e,3)}function U(t,e){return y(t.getMilliseconds(),e,3)}function H(t,e){return U(t,e)+"000"}function W(t,e){return y(t.getMonth()+1,e,2)}function J(t,e){return y(t.getMinutes(),e,2)}function V(t,e){return y(t.getSeconds(),e,2)}function Y(t){var e=t.getDay();return 0===e?7:e}function Q(t,e){return y(i.OM.count((0,a.Z)(t)-1,t),e,2)}function K(t){var e=t.getDay();return e>=4||0===e?(0,i.bL)(t):i.bL.ceil(t)}function X(t,e){return t=K(t),y(i.bL.count((0,a.Z)(t),t)+(4===(0,a.Z)(t).getDay()),e,2)}function tt(t){return t.getDay()}function et(t,e){return y(i.wA.count((0,a.Z)(t)-1,t),e,2)}function nt(t,e){return y(t.getFullYear()%100,e,2)}function rt(t,e){return y((t=K(t)).getFullYear()%100,e,2)}function ot(t,e){return y(t.getFullYear()%1e4,e,4)}function it(t,e){var n=t.getDay();return y((t=n>=4||0===n?(0,i.bL)(t):i.bL.ceil(t)).getFullYear()%1e4,e,4)}function st(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+y(e/60|0,"0",2)+y(e%60,"0",2)}function at(t,e){return y(t.getUTCDate(),e,2)}function lt(t,e){return y(t.getUTCHours(),e,2)}function ct(t,e){return y(t.getUTCHours()%12||12,e,2)}function ut(t,e){return y(1+o.Z.count((0,l.Z)(t),t),e,3)}function ft(t,e){return y(t.getUTCMilliseconds(),e,3)}function dt(t,e){return ft(t,e)+"000"}function ht(t,e){return y(t.getUTCMonth()+1,e,2)}function pt(t,e){return y(t.getUTCMinutes(),e,2)}function mt(t,e){return y(t.getUTCSeconds(),e,2)}function gt(t){var e=t.getUTCDay();return 0===e?7:e}function yt(t,e){return y(r.Ox.count((0,l.Z)(t)-1,t),e,2)}function vt(t){var e=t.getUTCDay();return e>=4||0===e?(0,r.hB)(t):r.hB.ceil(t)}function bt(t,e){return t=vt(t),y(r.hB.count((0,l.Z)(t),t)+(4===(0,l.Z)(t).getUTCDay()),e,2)}function _t(t){return t.getUTCDay()}function wt(t,e){return y(r.l6.count((0,l.Z)(t)-1,t),e,2)}function xt(t,e){return y(t.getUTCFullYear()%100,e,2)}function kt(t,e){return y((t=vt(t)).getUTCFullYear()%100,e,2)}function qt(t,e){return y(t.getUTCFullYear()%1e4,e,4)}function Nt(t,e){var n=t.getUTCDay();return y((t=n>=4||0===n?(0,r.hB)(t):r.hB.ceil(t)).getUTCFullYear()%1e4,e,4)}function St(){return"+0000"}function At(){return"%"}function Mt(t){return+t}function Tt(t){return Math.floor(+t/1e3)}},8467:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,a:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((t=>t.setHours(0,0,0,0)),((t,e)=>t.setDate(t.getDate()+e)),((t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*o.yB)/o.UD),(t=>t.getDate()-1));const s=i;var a=i.range},9123:(t,e,n)=>{"use strict";n.d(e,{UD:()=>s,Y2:()=>i,Ym:()=>r,iM:()=>a,jz:()=>l,qz:()=>c,yB:()=>o});const r=1e3,o=60*r,i=60*o,s=24*i,a=7*s,l=30*s,c=365*s},6596:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,i:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*o.Ym-t.getMinutes()*o.yB)}),(function(t,e){t.setTime(+t+e*o.Y2)}),(function(t,e){return(e-t)/o.Y2}),(function(t){return t.getHours()}));const s=i;var a=i.range},3606:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i});var r=new Date,o=new Date;function i(t,e,n,s){function a(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return a.floor=function(e){return t(e=new Date(+e)),e},a.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},a.round=function(t){var e=a(t),n=a.ceil(t);return t-e<n-t?e:n},a.offset=function(t,n){return e(t=new Date(+t),null==n?1:Math.floor(n)),t},a.range=function(n,r,o){var i,s=[];if(n=a.ceil(n),o=null==o?1:Math.floor(o),!(n<r&&o>0))return s;do{s.push(i=new Date(+n)),e(n,o),t(n)}while(i<n&&n<r);return s},a.filter=function(n){return i((function(e){if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(a.count=function(e,i){return r.setTime(+e),o.setTime(+i),t(r),t(o),Math.floor(n(r,o))},a.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?a.filter(s?function(e){return s(e)%t==0}:function(e){return a.count(0,e)%t==0}):a:null}),a}},8383:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i,m:()=>s});var r=n(3606),o=(0,r.Z)((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));o.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?(0,r.Z)((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,n){e.setTime(+e+n*t)}),(function(e,n){return(n-e)/t})):o:null};const i=o;var s=o.range},2991:(t,e,n)=>{"use strict";n.d(e,{L:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*o.Ym)}),(function(t,e){t.setTime(+t+e*o.yB)}),(function(t,e){return(e-t)/o.yB}),(function(t){return t.getMinutes()}));const s=i;var a=i.range},7905:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o,e:()=>i});var r=(0,n(3606).Z)((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()}));const o=r;var i=r.range},1343:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,m:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+e*o.Ym)}),(function(t,e){return(e-t)/o.Ym}),(function(t){return t.getUTCSeconds()}));const s=i;var a=i.range},7150:(t,e,n)=>{"use strict";n.d(e,{WG:()=>w,_g:()=>q,jK:()=>k,jo:()=>x});var r=n(3292),o=n(6106),i=n(9123),s=n(8383),a=n(1343),l=n(2991),c=n(6596),u=n(8467),f=n(6018),d=n(7905),h=n(2311),p=n(8593),m=n(8927),g=n(7445),y=n(1887),v=n(7351),b=n(4552);function _(t,e,n,l,c,u){const f=[[a.Z,1,i.Ym],[a.Z,5,5*i.Ym],[a.Z,15,15*i.Ym],[a.Z,30,30*i.Ym],[u,1,i.yB],[u,5,5*i.yB],[u,15,15*i.yB],[u,30,30*i.yB],[c,1,i.Y2],[c,3,3*i.Y2],[c,6,6*i.Y2],[c,12,12*i.Y2],[l,1,i.UD],[l,2,2*i.UD],[n,1,i.iM],[e,1,i.jz],[e,3,3*i.jz],[t,1,i.qz]];function d(e,n,a){const l=Math.abs(n-e)/a,c=(0,r.Z)((([,,t])=>t)).right(f,l);if(c===f.length)return t.every((0,o.ly)(e/i.qz,n/i.qz,a));if(0===c)return s.Z.every(Math.max((0,o.ly)(e,n,a),1));const[u,d]=f[l/f[c-1][2]<f[c][2]/l?c-1:c];return u.every(d)}return[function(t,e,n){const r=e<t;r&&([t,e]=[e,t]);const o=n&&"function"==typeof n.range?n:d(t,e,n),i=o?o.range(t,+e+1):[];return r?i.reverse():i},d]}const[w,x]=_(b.Z,v.Z,y.Ox,g.Z,m.Z,p.Z),[k,q]=_(h.Z,d.Z,f.OM,u.Z,c.Z,l.Z)},7445:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,y:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/o.UD}),(function(t){return t.getUTCDate()-1}));const s=i;var a=i.range},8927:(t,e,n)=>{"use strict";n.d(e,{X:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCMinutes(0,0,0)}),(function(t,e){t.setTime(+t+e*o.Y2)}),(function(t,e){return(e-t)/o.Y2}),(function(t){return t.getUTCHours()}));const s=i;var a=i.range},8593:(t,e,n)=>{"use strict";n.d(e,{N:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCSeconds(0,0)}),(function(t,e){t.setTime(+t+e*o.yB)}),(function(t,e){return(e-t)/o.yB}),(function(t){return t.getUTCMinutes()}));const s=i;var a=i.range},7351:(t,e,n)=>{"use strict";n.d(e,{K:()=>i,Z:()=>o});var r=(0,n(3606).Z)((function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCMonth(t.getUTCMonth()+e)}),(function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())}),(function(t){return t.getUTCMonth()}));const o=r;var i=r.range},1887:(t,e,n)=>{"use strict";n.d(e,{$3:()=>p,DK:()=>m,J1:()=>l,Ox:()=>s,QQ:()=>f,Q_:()=>b,SU:()=>h,b3:()=>c,fz:()=>v,g4:()=>d,hB:()=>u,l6:()=>a,uy:()=>g,xj:()=>y});var r=n(3606),o=n(9123);function i(t){return(0,r.Z)((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/o.iM}))}var s=i(0),a=i(1),l=i(2),c=i(3),u=i(4),f=i(5),d=i(6),h=s.range,p=a.range,m=l.range,g=c.range,y=u.range,v=f.range,b=d.range},4552:(t,e,n)=>{"use strict";n.d(e,{D:()=>s,Z:()=>i});var r=n(3606),o=(0,r.Z)((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));o.every=function(t){return isFinite(t=Math.floor(t))&&t>0?(0,r.Z)((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const i=o;var s=o.range},6018:(t,e,n)=>{"use strict";n.d(e,{$t:()=>y,EY:()=>d,Ff:()=>b,Ld:()=>g,OM:()=>s,aU:()=>m,b$:()=>v,bJ:()=>p,bL:()=>u,mC:()=>f,sy:()=>l,vm:()=>h,wA:()=>a,zg:()=>c});var r=n(3606),o=n(9123);function i(t){return(0,r.Z)((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*o.yB)/o.iM}))}var s=i(0),a=i(1),l=i(2),c=i(3),u=i(4),f=i(5),d=i(6),h=s.range,p=a.range,m=l.range,g=c.range,y=u.range,v=f.range,b=d.range},2311:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i,g:()=>s});var r=n(3606),o=(0,r.Z)((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));o.every=function(t){return isFinite(t=Math.floor(t))&&t>0?(0,r.Z)((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const i=o;var s=o.range},2554:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Adder:()=>r.Adder,Delaunay:()=>mo,FormatSpecifier:()=>Ji.FormatSpecifier,InternMap:()=>r.InternMap,InternSet:()=>r.InternSet,Node:()=>Wu.NB,Voronoi:()=>lo,ZoomTransform:()=>Ep,active:()=>cn,arc:()=>Xf,area:()=>ad,areaRadial:()=>gd,ascending:()=>r.ascending,autoType:()=>ko.autoType,axisBottom:()=>p,axisLeft:()=>m,axisRight:()=>h,axisTop:()=>d,bin:()=>r.bin,bisect:()=>r.bisect,bisectCenter:()=>r.bisectCenter,bisectLeft:()=>r.bisectLeft,bisectRight:()=>r.bisectRight,bisector:()=>r.bisector,blob:()=>ri,blur:()=>r.blur,blur2:()=>r.blur2,blurImage:()=>r.blurImage,brush:()=>Bn,brushSelection:()=>Fn,brushX:()=>Ln,brushY:()=>Dn,buffer:()=>ii,chord:()=>Kn,chordDirected:()=>tr,chordTranspose:()=>Xn,cluster:()=>Wu.ki,color:()=>wr.color,contourDensity:()=>Dr,contours:()=>Er,count:()=>r.count,create:()=>Sf,creator:()=>kt,cross:()=>r.cross,csv:()=>hi,csvFormat:()=>ko.csvFormat,csvFormatBody:()=>ko.csvFormatBody,csvFormatRow:()=>ko.csvFormatRow,csvFormatRows:()=>ko.csvFormatRows,csvFormatValue:()=>ko.csvFormatValue,csvParse:()=>ko.csvParse,csvParseRows:()=>ko.csvParseRows,cubehelix:()=>wr.cubehelix,cumsum:()=>r.cumsum,curveBasis:()=>sh,curveBasisClosed:()=>lh,curveBasisOpen:()=>uh,curveBumpX:()=>_d,curveBumpY:()=>wd,curveBundle:()=>dh,curveCardinal:()=>mh,curveCardinalClosed:()=>yh,curveCardinalOpen:()=>bh,curveCatmullRom:()=>xh,curveCatmullRomClosed:()=>qh,curveCatmullRomOpen:()=>Sh,curveLinear:()=>rd,curveLinearClosed:()=>Mh,curveMonotoneX:()=>Ph,curveMonotoneY:()=>Fh,curveNatural:()=>Bh,curveStep:()=>Zh,curveStepAfter:()=>Gh,curveStepBefore:()=>$h,descending:()=>r.descending,deviation:()=>r.deviation,difference:()=>r.difference,disjoint:()=>r.disjoint,dispatch:()=>x,drag:()=>xo,dragDisable:()=>$t,dragEnable:()=>Gt,dsv:()=>di,dsvFormat:()=>ko.dsvFormat,easeBack:()=>Qo,easeBackIn:()=>Vo,easeBackInOut:()=>Qo,easeBackOut:()=>Yo,easeBounce:()=>Ho,easeBounceIn:()=>Uo,easeBounceInOut:()=>Wo,easeBounceOut:()=>Ho,easeCircle:()=>Zo,easeCircleIn:()=>Bo,easeCircleInOut:()=>Zo,easeCircleOut:()=>zo,easeCubic:()=>on,easeCubicIn:()=>nn,easeCubicInOut:()=>on,easeCubicOut:()=>rn,easeElastic:()=>ti,easeElasticIn:()=>Xo,easeElasticInOut:()=>ei,easeElasticOut:()=>ti,easeExp:()=>Do,easeExpIn:()=>Fo,easeExpInOut:()=>Do,easeExpOut:()=>Lo,easeLinear:()=>qo,easePoly:()=>Co,easePolyIn:()=>Mo,easePolyInOut:()=>Co,easePolyOut:()=>To,easeQuad:()=>Ao,easeQuadIn:()=>No,easeQuadInOut:()=>Ao,easeQuadOut:()=>So,easeSin:()=>Io,easeSinIn:()=>Eo,easeSinInOut:()=>Io,easeSinOut:()=>Ro,every:()=>r.every,extent:()=>r.extent,fcumsum:()=>r.fcumsum,filter:()=>r.filter,flatGroup:()=>r.flatGroup,flatRollup:()=>r.flatRollup,forceCenter:()=>xi,forceCollide:()=>Ii,forceLink:()=>Li,forceManyBody:()=>Gi,forceRadial:()=>Ui,forceSimulation:()=>$i,forceX:()=>Hi,forceY:()=>Wi,format:()=>Ji.format,formatDefaultLocale:()=>Ji.formatDefaultLocale,formatLocale:()=>Ji.formatLocale,formatPrefix:()=>Ji.formatPrefix,formatSpecifier:()=>Ji.formatSpecifier,fsum:()=>r.fsum,geoAlbers:()=>fu,geoAlbersUsa:()=>du,geoArea:()=>Ys,geoAzimuthalEqualArea:()=>gu,geoAzimuthalEqualAreaRaw:()=>mu,geoAzimuthalEquidistant:()=>vu,geoAzimuthalEquidistantRaw:()=>yu,geoBounds:()=>ja,geoCentroid:()=>$a,geoCircle:()=>tl,geoClipAntimeridian:()=>dl,geoClipCircle:()=>hl,geoClipExtent:()=>wl,geoClipRectangle:()=>_l,geoConicConformal:()=>qu,geoConicConformalRaw:()=>ku,geoConicEqualArea:()=>uu,geoConicEqualAreaRaw:()=>cu,geoConicEquidistant:()=>Mu,geoConicEquidistantRaw:()=>Au,geoContains:()=>Ll,geoDistance:()=>Tl,geoEqualEarth:()=>Iu,geoEqualEarthRaw:()=>Ru,geoEquirectangular:()=>Su,geoEquirectangularRaw:()=>Nu,geoGnomonic:()=>Fu,geoGnomonicRaw:()=>Pu,geoGraticule:()=>Zl,geoGraticule10:()=>$l,geoIdentity:()=>Lu,geoInterpolate:()=>Gl,geoLength:()=>Sl,geoMercator:()=>_u,geoMercatorRaw:()=>bu,geoNaturalEarth1:()=>Bu,geoNaturalEarth1Raw:()=>Du,geoOrthographic:()=>Zu,geoOrthographicRaw:()=>zu,geoPath:()=>Wc,geoProjection:()=>su,geoProjectionMutator:()=>au,geoRotation:()=>Qa,geoStereographic:()=>Gu,geoStereographicRaw:()=>$u,geoStream:()=>Ss,geoTransform:()=>Jc,geoTransverseMercator:()=>Hu,geoTransverseMercatorRaw:()=>Uu,gray:()=>wr.gray,greatest:()=>r.greatest,greatestIndex:()=>r.greatestIndex,group:()=>r.group,groupSort:()=>r.groupSort,groups:()=>r.groups,hcl:()=>wr.hcl,hierarchy:()=>Wu.bT,histogram:()=>r.histogram,hsl:()=>wr.hsl,html:()=>_i,image:()=>mi,index:()=>r.index,indexes:()=>r.indexes,interpolate:()=>Ju.interpolate,interpolateArray:()=>Ju.interpolateArray,interpolateBasis:()=>Ju.interpolateBasis,interpolateBasisClosed:()=>Ju.interpolateBasisClosed,interpolateBlues:()=>Nf.interpolateBlues,interpolateBrBG:()=>Nf.interpolateBrBG,interpolateBuGn:()=>Nf.interpolateBuGn,interpolateBuPu:()=>Nf.interpolateBuPu,interpolateCividis:()=>Nf.interpolateCividis,interpolateCool:()=>Nf.interpolateCool,interpolateCubehelix:()=>Ju.interpolateCubehelix,interpolateCubehelixDefault:()=>Nf.interpolateCubehelixDefault,interpolateCubehelixLong:()=>Ju.interpolateCubehelixLong,interpolateDate:()=>Ju.interpolateDate,interpolateDiscrete:()=>Ju.interpolateDiscrete,interpolateGnBu:()=>Nf.interpolateGnBu,interpolateGreens:()=>Nf.interpolateGreens,interpolateGreys:()=>Nf.interpolateGreys,interpolateHcl:()=>Ju.interpolateHcl,interpolateHclLong:()=>Ju.interpolateHclLong,interpolateHsl:()=>Ju.interpolateHsl,interpolateHslLong:()=>Ju.interpolateHslLong,interpolateHue:()=>Ju.interpolateHue,interpolateInferno:()=>Nf.interpolateInferno,interpolateLab:()=>Ju.interpolateLab,interpolateMagma:()=>Nf.interpolateMagma,interpolateNumber:()=>Ju.interpolateNumber,interpolateNumberArray:()=>Ju.interpolateNumberArray,interpolateObject:()=>Ju.interpolateObject,interpolateOrRd:()=>Nf.interpolateOrRd,interpolateOranges:()=>Nf.interpolateOranges,interpolatePRGn:()=>Nf.interpolatePRGn,interpolatePiYG:()=>Nf.interpolatePiYG,interpolatePlasma:()=>Nf.interpolatePlasma,interpolatePuBu:()=>Nf.interpolatePuBu,interpolatePuBuGn:()=>Nf.interpolatePuBuGn,interpolatePuOr:()=>Nf.interpolatePuOr,interpolatePuRd:()=>Nf.interpolatePuRd,interpolatePurples:()=>Nf.interpolatePurples,interpolateRainbow:()=>Nf.interpolateRainbow,interpolateRdBu:()=>Nf.interpolateRdBu,interpolateRdGy:()=>Nf.interpolateRdGy,interpolateRdPu:()=>Nf.interpolateRdPu,interpolateRdYlBu:()=>Nf.interpolateRdYlBu,interpolateRdYlGn:()=>Nf.interpolateRdYlGn,interpolateReds:()=>Nf.interpolateReds,interpolateRgb:()=>Ju.interpolateRgb,interpolateRgbBasis:()=>Ju.interpolateRgbBasis,interpolateRgbBasisClosed:()=>Ju.interpolateRgbBasisClosed,interpolateRound:()=>Ju.interpolateRound,interpolateSinebow:()=>Nf.interpolateSinebow,interpolateSpectral:()=>Nf.interpolateSpectral,interpolateString:()=>Ju.interpolateString,interpolateTransformCss:()=>Ju.interpolateTransformCss,interpolateTransformSvg:()=>Ju.interpolateTransformSvg,interpolateTurbo:()=>Nf.interpolateTurbo,interpolateViridis:()=>Nf.interpolateViridis,interpolateWarm:()=>Nf.interpolateWarm,interpolateYlGn:()=>Nf.interpolateYlGn,interpolateYlGnBu:()=>Nf.interpolateYlGnBu,interpolateYlOrBr:()=>Nf.interpolateYlOrBr,interpolateYlOrRd:()=>Nf.interpolateYlOrRd,interpolateZoom:()=>Ju.interpolateZoom,interrupt:()=>be,intersection:()=>r.intersection,interval:()=>Tp,isoFormat:()=>Sp,isoParse:()=>Mp,json:()=>yi,lab:()=>wr.lab,lch:()=>wr.lch,least:()=>r.least,leastIndex:()=>r.leastIndex,line:()=>sd,lineRadial:()=>md,link:()=>Nd,linkHorizontal:()=>Sd,linkRadial:()=>Md,linkVertical:()=>Ad,local:()=>Mf,map:()=>r.map,matcher:()=>M,max:()=>r.max,maxIndex:()=>r.maxIndex,mean:()=>r.mean,median:()=>r.median,medianIndex:()=>r.medianIndex,merge:()=>r.merge,min:()=>r.min,minIndex:()=>r.minIndex,mode:()=>r.mode,namespace:()=>G,namespaces:()=>$,nice:()=>r.nice,now:()=>oe,pack:()=>Wu.P2,packEnclose:()=>Wu.O1,packSiblings:()=>Wu.jA,pairs:()=>r.pairs,partition:()=>Wu.uK,path:()=>lr,permute:()=>r.permute,pie:()=>ud,piecewise:()=>Ju.piecewise,pointRadial:()=>yd,pointer:()=>Wt,pointers:()=>Cf,polygonArea:()=>Vu,polygonCentroid:()=>Yu,polygonContains:()=>ef,polygonHull:()=>tf,polygonLength:()=>nf,precisionFixed:()=>Ji.precisionFixed,precisionPrefix:()=>Ji.precisionPrefix,precisionRound:()=>Ji.precisionRound,quadtree:()=>Ai,quantile:()=>r.quantile,quantileIndex:()=>r.quantileIndex,quantileSorted:()=>r.quantileSorted,quantize:()=>Ju.quantize,quickselect:()=>r.quickselect,radialArea:()=>gd,radialLine:()=>md,randomBates:()=>uf,randomBernoulli:()=>hf,randomBeta:()=>gf,randomBinomial:()=>yf,randomCauchy:()=>bf,randomExponential:()=>ff,randomGamma:()=>mf,randomGeometric:()=>pf,randomInt:()=>sf,randomIrwinHall:()=>cf,randomLcg:()=>kf,randomLogNormal:()=>lf,randomLogistic:()=>_f,randomNormal:()=>af,randomPareto:()=>df,randomPoisson:()=>wf,randomUniform:()=>of,randomWeibull:()=>vf,range:()=>r.range,rank:()=>r.rank,reduce:()=>r.reduce,reverse:()=>r.reverse,rgb:()=>wr.rgb,ribbon:()=>br,ribbonArrow:()=>_r,rollup:()=>r.rollup,rollups:()=>r.rollups,scaleBand:()=>qf.scaleBand,scaleDiverging:()=>qf.scaleDiverging,scaleDivergingLog:()=>qf.scaleDivergingLog,scaleDivergingPow:()=>qf.scaleDivergingPow,scaleDivergingSqrt:()=>qf.scaleDivergingSqrt,scaleDivergingSymlog:()=>qf.scaleDivergingSymlog,scaleIdentity:()=>qf.scaleIdentity,scaleImplicit:()=>qf.scaleImplicit,scaleLinear:()=>qf.scaleLinear,scaleLog:()=>qf.scaleLog,scaleOrdinal:()=>qf.scaleOrdinal,scalePoint:()=>qf.scalePoint,scalePow:()=>qf.scalePow,scaleQuantile:()=>qf.scaleQuantile,scaleQuantize:()=>qf.scaleQuantize,scaleRadial:()=>qf.scaleRadial,scaleSequential:()=>qf.scaleSequential,scaleSequentialLog:()=>qf.scaleSequentialLog,scaleSequentialPow:()=>qf.scaleSequentialPow,scaleSequentialQuantile:()=>qf.scaleSequentialQuantile,scaleSequentialSqrt:()=>qf.scaleSequentialSqrt,scaleSequentialSymlog:()=>qf.scaleSequentialSymlog,scaleSqrt:()=>qf.scaleSqrt,scaleSymlog:()=>qf.scaleSymlog,scaleThreshold:()=>qf.scaleThreshold,scaleTime:()=>qf.scaleTime,scaleUtc:()=>qf.scaleUtc,scan:()=>r.scan,schemeAccent:()=>Nf.schemeAccent,schemeBlues:()=>Nf.schemeBlues,schemeBrBG:()=>Nf.schemeBrBG,schemeBuGn:()=>Nf.schemeBuGn,schemeBuPu:()=>Nf.schemeBuPu,schemeCategory10:()=>Nf.schemeCategory10,schemeDark2:()=>Nf.schemeDark2,schemeGnBu:()=>Nf.schemeGnBu,schemeGreens:()=>Nf.schemeGreens,schemeGreys:()=>Nf.schemeGreys,schemeOrRd:()=>Nf.schemeOrRd,schemeOranges:()=>Nf.schemeOranges,schemePRGn:()=>Nf.schemePRGn,schemePaired:()=>Nf.schemePaired,schemePastel1:()=>Nf.schemePastel1,schemePastel2:()=>Nf.schemePastel2,schemePiYG:()=>Nf.schemePiYG,schemePuBu:()=>Nf.schemePuBu,schemePuBuGn:()=>Nf.schemePuBuGn,schemePuOr:()=>Nf.schemePuOr,schemePuRd:()=>Nf.schemePuRd,schemePurples:()=>Nf.schemePurples,schemeRdBu:()=>Nf.schemeRdBu,schemeRdGy:()=>Nf.schemeRdGy,schemeRdPu:()=>Nf.schemeRdPu,schemeRdYlBu:()=>Nf.schemeRdYlBu,schemeRdYlGn:()=>Nf.schemeRdYlGn,schemeReds:()=>Nf.schemeReds,schemeSet1:()=>Nf.schemeSet1,schemeSet2:()=>Nf.schemeSet2,schemeSet3:()=>Nf.schemeSet3,schemeSpectral:()=>Nf.schemeSpectral,schemeTableau10:()=>Nf.schemeTableau10,schemeYlGn:()=>Nf.schemeYlGn,schemeYlGnBu:()=>Nf.schemeYlGnBu,schemeYlOrBr:()=>Nf.schemeYlOrBr,schemeYlOrRd:()=>Nf.schemeYlOrRd,select:()=>Lt,selectAll:()=>jf,selection:()=>Ft,selector:()=>q,selectorAll:()=>A,shuffle:()=>r.shuffle,shuffler:()=>r.shuffler,some:()=>r.some,sort:()=>r.sort,stack:()=>Vh,stackOffsetDiverging:()=>Qh,stackOffsetExpand:()=>Yh,stackOffsetNone:()=>Uh,stackOffsetSilhouette:()=>Kh,stackOffsetWiggle:()=>Xh,stackOrderAppearance:()=>tp,stackOrderAscending:()=>np,stackOrderDescending:()=>op,stackOrderInsideOut:()=>ip,stackOrderNone:()=>Hh,stackOrderReverse:()=>sp,stratify:()=>Wu.QP,style:()=>et,subset:()=>r.subset,sum:()=>r.sum,superset:()=>r.superset,svg:()=>wi,symbol:()=>nh,symbolAsterisk:()=>Cd,symbolCircle:()=>jd,symbolCross:()=>Od,symbolDiamond:()=>Id,symbolDiamond2:()=>Pd,symbolPlus:()=>Fd,symbolSquare:()=>Ld,symbolSquare2:()=>Dd,symbolStar:()=>$d,symbolTriangle:()=>Ud,symbolTriangle2:()=>Wd,symbolWye:()=>Kd,symbolX:()=>Xd,symbols:()=>th,symbolsFill:()=>th,symbolsStroke:()=>eh,text:()=>ui,thresholdFreedmanDiaconis:()=>r.thresholdFreedmanDiaconis,thresholdScott:()=>r.thresholdScott,thresholdSturges:()=>r.thresholdSturges,tickFormat:()=>qf.tickFormat,tickIncrement:()=>r.tickIncrement,tickStep:()=>r.tickStep,ticks:()=>r.ticks,timeDay:()=>dp.Z,timeDays:()=>dp.a,timeFormat:()=>kp.i$,timeFormatDefaultLocale:()=>kp.ZP,timeFormatLocale:()=>qp.Z,timeFriday:()=>hp.mC,timeFridays:()=>hp.b$,timeHour:()=>fp.Z,timeHours:()=>fp.i,timeInterval:()=>ap.Z,timeMillisecond:()=>lp.Z,timeMilliseconds:()=>lp.m,timeMinute:()=>up.Z,timeMinutes:()=>up.L,timeMonday:()=>hp.wA,timeMondays:()=>hp.bJ,timeMonth:()=>pp.Z,timeMonths:()=>pp.e,timeParse:()=>kp.Z1,timeSaturday:()=>hp.EY,timeSaturdays:()=>hp.Ff,timeSecond:()=>cp.Z,timeSeconds:()=>cp.m,timeSunday:()=>hp.OM,timeSundays:()=>hp.vm,timeThursday:()=>hp.bL,timeThursdays:()=>hp.$t,timeTickInterval:()=>xp._g,timeTicks:()=>xp.jK,timeTuesday:()=>hp.sy,timeTuesdays:()=>hp.aU,timeWednesday:()=>hp.zg,timeWednesdays:()=>hp.Ld,timeWeek:()=>hp.OM,timeWeeks:()=>hp.vm,timeYear:()=>mp.Z,timeYears:()=>mp.g,timeout:()=>de,timer:()=>ae,timerFlush:()=>le,transition:()=>Xe,transpose:()=>r.transpose,tree:()=>Wu.G_,treemap:()=>Wu.pN,treemapBinary:()=>Wu.wL,treemapDice:()=>Wu.LQ,treemapResquarify:()=>Wu.eA,treemapSlice:()=>Wu.Km,treemapSliceDice:()=>Wu.E_,treemapSquarify:()=>Wu.o$,tsv:()=>pi,tsvFormat:()=>ko.tsvFormat,tsvFormatBody:()=>ko.tsvFormatBody,tsvFormatRow:()=>ko.tsvFormatRow,tsvFormatRows:()=>ko.tsvFormatRows,tsvFormatValue:()=>ko.tsvFormatValue,tsvParse:()=>ko.tsvParse,tsvParseRows:()=>ko.tsvParseRows,union:()=>r.union,utcDay:()=>vp.Z,utcDays:()=>vp.y,utcFormat:()=>kp.g0,utcFriday:()=>bp.QQ,utcFridays:()=>bp.fz,utcHour:()=>yp.Z,utcHours:()=>yp.X,utcMillisecond:()=>lp.Z,utcMilliseconds:()=>lp.m,utcMinute:()=>gp.Z,utcMinutes:()=>gp.N,utcMonday:()=>bp.l6,utcMondays:()=>bp.$3,utcMonth:()=>_p.Z,utcMonths:()=>_p.K,utcParse:()=>kp.wp,utcSaturday:()=>bp.g4,utcSaturdays:()=>bp.Q_,utcSecond:()=>cp.Z,utcSeconds:()=>cp.m,utcSunday:()=>bp.Ox,utcSundays:()=>bp.SU,utcThursday:()=>bp.hB,utcThursdays:()=>bp.xj,utcTickInterval:()=>xp.jo,utcTicks:()=>xp.WG,utcTuesday:()=>bp.J1,utcTuesdays:()=>bp.DK,utcWednesday:()=>bp.b3,utcWednesdays:()=>bp.uy,utcWeek:()=>bp.Ox,utcWeeks:()=>bp.SU,utcYear:()=>wp.Z,utcYears:()=>wp.D,variance:()=>r.variance,window:()=>Q,xml:()=>bi,zip:()=>r.zip,zoom:()=>Gp,zoomIdentity:()=>Rp,zoomTransform:()=>Ip});var r=n(9060);function o(t){return t}var i=1e-6;function s(t){return"translate("+t+",0)"}function a(t){return"translate(0,"+t+")"}function l(t){return e=>+t(e)}function c(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function u(){return!this.__axis}function f(t,e){var n=[],r=null,f=null,d=6,h=6,p=3,m="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,g=1===t||4===t?-1:1,y=4===t||2===t?"x":"y",v=1===t||3===t?s:a;function b(s){var a=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,b=null==f?e.tickFormat?e.tickFormat.apply(e,n):o:f,_=Math.max(d,0)+p,w=e.range(),x=+w[0]+m,k=+w[w.length-1]+m,q=(e.bandwidth?c:l)(e.copy(),m),N=s.selection?s.selection():s,S=N.selectAll(".domain").data([null]),A=N.selectAll(".tick").data(a,e).order(),M=A.exit(),T=A.enter().append("g").attr("class","tick"),C=A.select("line"),j=A.select("text");S=S.merge(S.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),A=A.merge(T),C=C.merge(T.append("line").attr("stroke","currentColor").attr(y+"2",g*d)),j=j.merge(T.append("text").attr("fill","currentColor").attr(y,g*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),s!==N&&(S=S.transition(s),A=A.transition(s),C=C.transition(s),j=j.transition(s),M=M.transition(s).attr("opacity",i).attr("transform",(function(t){return isFinite(t=q(t))?v(t+m):this.getAttribute("transform")})),T.attr("opacity",i).attr("transform",(function(t){var e=this.parentNode.__axis;return v((e&&isFinite(e=e(t))?e:q(t))+m)}))),M.remove(),S.attr("d",4===t||2===t?h?"M"+g*h+","+x+"H"+m+"V"+k+"H"+g*h:"M"+m+","+x+"V"+k:h?"M"+x+","+g*h+"V"+m+"H"+k+"V"+g*h:"M"+x+","+m+"H"+k),A.attr("opacity",1).attr("transform",(function(t){return v(q(t)+m)})),C.attr(y+"2",g*d),j.attr(y,g*_).text(b),N.filter(u).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),N.each((function(){this.__axis=q}))}return b.scale=function(t){return arguments.length?(e=t,b):e},b.ticks=function(){return n=Array.from(arguments),b},b.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),b):n.slice()},b.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),b):r&&r.slice()},b.tickFormat=function(t){return arguments.length?(f=t,b):f},b.tickSize=function(t){return arguments.length?(d=h=+t,b):d},b.tickSizeInner=function(t){return arguments.length?(d=+t,b):d},b.tickSizeOuter=function(t){return arguments.length?(h=+t,b):h},b.tickPadding=function(t){return arguments.length?(p=+t,b):p},b.offset=function(t){return arguments.length?(m=+t,b):m},b}function d(t){return f(1,t)}function h(t){return f(2,t)}function p(t){return f(3,t)}function m(t){return f(4,t)}var g={value:()=>{}};function y(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new v(r)}function v(t){this._=t}function b(t,e){return t.trim().split(/^|\s+/).map((function(t){var n="",r=t.indexOf(".");if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function _(t,e){for(var n,r=0,o=t.length;r<o;++r)if((n=t[r]).name===e)return n.value}function w(t,e,n){for(var r=0,o=t.length;r<o;++r)if(t[r].name===e){t[r]=g,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}v.prototype=y.prototype={constructor:v,on:function(t,e){var n,r=this._,o=b(t+"",r),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(n=(t=o[i]).type)r[n]=w(r[n],t.name,e);else if(null==e)for(n in r)r[n]=w(r[n],t.name,null);return this}for(;++i<s;)if((n=(t=o[i]).type)&&(n=_(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new v(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,o=new Array(n),i=0;i<n;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,n=(r=this._[t]).length;i<n;++i)r[i].value.apply(e,o)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],o=0,i=r.length;o<i;++o)r[o].value.apply(e,n)}};const x=y;function k(){}function q(t){return null==t?k:function(){return this.querySelector(t)}}function N(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function S(){return[]}function A(t){return null==t?S:function(){return this.querySelectorAll(t)}}function M(t){return function(){return this.matches(t)}}function T(t){return function(e){return e.matches(t)}}var C=Array.prototype.find;function j(){return this.firstElementChild}var O=Array.prototype.filter;function E(){return Array.from(this.children)}function R(t){return new Array(t.length)}function I(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function P(t){return function(){return t}}function F(t,e,n,r,o,i){for(var s,a=0,l=e.length,c=i.length;a<c;++a)(s=e[a])?(s.__data__=i[a],r[a]=s):n[a]=new I(t,i[a]);for(;a<l;++a)(s=e[a])&&(o[a]=s)}function L(t,e,n,r,o,i,s){var a,l,c,u=new Map,f=e.length,d=i.length,h=new Array(f);for(a=0;a<f;++a)(l=e[a])&&(h[a]=c=s.call(l,l.__data__,a,e)+"",u.has(c)?o[a]=l:u.set(c,l));for(a=0;a<d;++a)c=s.call(t,i[a],a,i)+"",(l=u.get(c))?(r[a]=l,l.__data__=i[a],u.delete(c)):n[a]=new I(t,i[a]);for(a=0;a<f;++a)(l=e[a])&&u.get(h[a])===l&&(o[a]=l)}function D(t){return t.__data__}function B(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function z(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}I.prototype={constructor:I,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Z="http://www.w3.org/1999/xhtml";const $={svg:"http://www.w3.org/2000/svg",xhtml:Z,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function G(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),$.hasOwnProperty(e)?{space:$[e],local:t}:t}function U(t){return function(){this.removeAttribute(t)}}function H(t){return function(){this.removeAttributeNS(t.space,t.local)}}function W(t,e){return function(){this.setAttribute(t,e)}}function J(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function V(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Y(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Q(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function K(t){return function(){this.style.removeProperty(t)}}function X(t,e,n){return function(){this.style.setProperty(t,e,n)}}function tt(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function et(t,e){return t.style.getPropertyValue(e)||Q(t).getComputedStyle(t,null).getPropertyValue(e)}function nt(t){return function(){delete this[t]}}function rt(t,e){return function(){this[t]=e}}function ot(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function it(t){return t.trim().split(/^|\s+/)}function st(t){return t.classList||new at(t)}function at(t){this._node=t,this._names=it(t.getAttribute("class")||"")}function lt(t,e){for(var n=st(t),r=-1,o=e.length;++r<o;)n.add(e[r])}function ct(t,e){for(var n=st(t),r=-1,o=e.length;++r<o;)n.remove(e[r])}function ut(t){return function(){lt(this,t)}}function ft(t){return function(){ct(this,t)}}function dt(t,e){return function(){(e.apply(this,arguments)?lt:ct)(this,t)}}function ht(){this.textContent=""}function pt(t){return function(){this.textContent=t}}function mt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function gt(){this.innerHTML=""}function yt(t){return function(){this.innerHTML=t}}function vt(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function bt(){this.nextSibling&&this.parentNode.appendChild(this)}function _t(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function wt(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===Z&&e.documentElement.namespaceURI===Z?e.createElement(t):e.createElementNS(n,t)}}function xt(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function kt(t){var e=G(t);return(e.local?xt:wt)(e)}function qt(){return null}function Nt(){var t=this.parentNode;t&&t.removeChild(this)}function St(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function At(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Mt(t){return t.trim().split(/^|\s+/).map((function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Tt(t){return function(){var e=this.__on;if(e){for(var n,r=0,o=-1,i=e.length;r<i;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++o]=n:this.removeEventListener(n.type,n.listener,n.options);++o?e.length=o:delete this.__on}}}function Ct(t,e,n){return function(){var r,o=this.__on,i=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(o)for(var s=0,a=o.length;s<a;++s)if((r=o[s]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=i,r.options=n),void(r.value=e);this.addEventListener(t.type,i,n),r={type:t.type,name:t.name,value:e,listener:i,options:n},o?o.push(r):this.__on=[r]}}function jt(t,e,n){var r=Q(t),o=r.CustomEvent;"function"==typeof o?o=new o(e,n):(o=r.document.createEvent("Event"),n?(o.initEvent(e,n.bubbles,n.cancelable),o.detail=n.detail):o.initEvent(e,!1,!1)),t.dispatchEvent(o)}function Ot(t,e){return function(){return jt(this,t,e)}}function Et(t,e){return function(){return jt(this,t,e.apply(this,arguments))}}at.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Rt=[null];function It(t,e){this._groups=t,this._parents=e}function Pt(){return new It([[document.documentElement]],Rt)}It.prototype=Pt.prototype={constructor:It,select:function(t){"function"!=typeof t&&(t=q(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s,a=e[o],l=a.length,c=r[o]=new Array(l),u=0;u<l;++u)(i=a[u])&&(s=t.call(i,i.__data__,u,a))&&("__data__"in i&&(s.__data__=i.__data__),c[u]=s);return new It(r,this._parents)},selectAll:function(t){t="function"==typeof t?function(t){return function(){return N(t.apply(this,arguments))}}(t):A(t);for(var e=this._groups,n=e.length,r=[],o=[],i=0;i<n;++i)for(var s,a=e[i],l=a.length,c=0;c<l;++c)(s=a[c])&&(r.push(t.call(s,s.__data__,c,a)),o.push(s));return new It(r,o)},selectChild:function(t){return this.select(null==t?j:function(t){return function(){return C.call(this.children,t)}}("function"==typeof t?t:T(t)))},selectChildren:function(t){return this.selectAll(null==t?E:function(t){return function(){return O.call(this.children,t)}}("function"==typeof t?t:T(t)))},filter:function(t){"function"!=typeof t&&(t=M(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s=e[o],a=s.length,l=r[o]=[],c=0;c<a;++c)(i=s[c])&&t.call(i,i.__data__,c,s)&&l.push(i);return new It(r,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,D);var n=e?L:F,r=this._parents,o=this._groups;"function"!=typeof t&&(t=P(t));for(var i=o.length,s=new Array(i),a=new Array(i),l=new Array(i),c=0;c<i;++c){var u=r[c],f=o[c],d=f.length,h=B(t.call(u,u&&u.__data__,c,r)),p=h.length,m=a[c]=new Array(p),g=s[c]=new Array(p),y=l[c]=new Array(d);n(u,f,m,g,y,h,e);for(var v,b,_=0,w=0;_<p;++_)if(v=m[_]){for(_>=w&&(w=_+1);!(b=g[w])&&++w<p;);v._next=b||null}}return(s=new It(s,r))._enter=a,s._exit=l,s},enter:function(){return new It(this._enter||this._groups.map(R),this._parents)},exit:function(){return new It(this._exit||this._groups.map(R),this._parents)},join:function(t,e,n){var r=this.enter(),o=this,i=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=e&&(o=e(o))&&(o=o.selection()),null==n?i.remove():n(i),r&&o?r.merge(o).order():o},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,r=e._groups,o=n.length,i=r.length,s=Math.min(o,i),a=new Array(o),l=0;l<s;++l)for(var c,u=n[l],f=r[l],d=u.length,h=a[l]=new Array(d),p=0;p<d;++p)(c=u[p]||f[p])&&(h[p]=c);for(;l<o;++l)a[l]=n[l];return new It(a,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,o=t[e],i=o.length-1,s=o[i];--i>=0;)(r=o[i])&&(s&&4^r.compareDocumentPosition(s)&&s.parentNode.insertBefore(r,s),s=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=z);for(var n=this._groups,r=n.length,o=new Array(r),i=0;i<r;++i){for(var s,a=n[i],l=a.length,c=o[i]=new Array(l),u=0;u<l;++u)(s=a[u])&&(c[u]=s);c.sort(e)}return new It(o,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],o=0,i=r.length;o<i;++o){var s=r[o];if(s)return s}return null},size:function(){let t=0;for(const e of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var o,i=e[n],s=0,a=i.length;s<a;++s)(o=i[s])&&t.call(o,o.__data__,s,i);return this},attr:function(t,e){var n=G(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?H:U:"function"==typeof e?n.local?Y:V:n.local?J:W)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?K:"function"==typeof e?tt:X)(t,e,null==n?"":n)):et(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?nt:"function"==typeof e?ot:rt)(t,e)):this.node()[t]},classed:function(t,e){var n=it(t+"");if(arguments.length<2){for(var r=st(this.node()),o=-1,i=n.length;++o<i;)if(!r.contains(n[o]))return!1;return!0}return this.each(("function"==typeof e?dt:e?ut:ft)(n,e))},text:function(t){return arguments.length?this.each(null==t?ht:("function"==typeof t?mt:pt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?gt:("function"==typeof t?vt:yt)(t)):this.node().innerHTML},raise:function(){return this.each(bt)},lower:function(){return this.each(_t)},append:function(t){var e="function"==typeof t?t:kt(t);return this.select((function(){return this.appendChild(e.apply(this,arguments))}))},insert:function(t,e){var n="function"==typeof t?t:kt(t),r=null==e?qt:"function"==typeof e?e:q(e);return this.select((function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)}))},remove:function(){return this.each(Nt)},clone:function(t){return this.select(t?At:St)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,o,i=Mt(t+""),s=i.length;if(!(arguments.length<2)){for(a=e?Ct:Tt,r=0;r<s;++r)this.each(a(i[r],e,n));return this}var a=this.node().__on;if(a)for(var l,c=0,u=a.length;c<u;++c)for(r=0,l=a[c];r<s;++r)if((o=i[r]).type===l.type&&o.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?Et:Ot)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r,o=t[e],i=0,s=o.length;i<s;++i)(r=o[i])&&(yield r)}};const Ft=Pt;function Lt(t){return"string"==typeof t?new It([[document.querySelector(t)]],[document.documentElement]):new It([[t]],Rt)}const Dt={passive:!1},Bt={capture:!0,passive:!1};function zt(t){t.stopImmediatePropagation()}function Zt(t){t.preventDefault(),t.stopImmediatePropagation()}function $t(t){var e=t.document.documentElement,n=Lt(t).on("dragstart.drag",Zt,Bt);"onselectstart"in e?n.on("selectstart.drag",Zt,Bt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Gt(t,e){var n=t.document.documentElement,r=Lt(t).on("dragstart.drag",null);e&&(r.on("click.drag",Zt,Bt),setTimeout((function(){r.on("click.drag",null)}),0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var Ut=n(2303);function Ht(t){let e;for(;e=t.sourceEvent;)t=e;return t}function Wt(t,e){if(t=Ht(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(e.getScreenCTM().inverse())).x,r.y]}if(e.getBoundingClientRect){var o=e.getBoundingClientRect();return[t.clientX-o.left-e.clientLeft,t.clientY-o.top-e.clientTop]}}return[t.pageX,t.pageY]}var Jt,Vt,Yt=0,Qt=0,Kt=0,Xt=0,te=0,ee=0,ne="object"==typeof performance&&performance.now?performance:Date,re="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function oe(){return te||(re(ie),te=ne.now()+ee)}function ie(){te=0}function se(){this._call=this._time=this._next=null}function ae(t,e,n){var r=new se;return r.restart(t,e,n),r}function le(){oe(),++Yt;for(var t,e=Jt;e;)(t=te-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Yt}function ce(){te=(Xt=ne.now())+ee,Yt=Qt=0;try{le()}finally{Yt=0,function(){var t,e,n=Jt,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Jt=e);Vt=t,fe(r)}(),te=0}}function ue(){var t=ne.now(),e=t-Xt;e>1e3&&(ee-=e,Xt=t)}function fe(t){Yt||(Qt&&(Qt=clearTimeout(Qt)),t-te>24?(t<1/0&&(Qt=setTimeout(ce,t-ne.now()-ee)),Kt&&(Kt=clearInterval(Kt))):(Kt||(Xt=ne.now(),Kt=setInterval(ue,1e3)),Yt=1,re(ce)))}function de(t,e,n){var r=new se;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}se.prototype=ae.prototype={constructor:se,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?oe():+n)+(null==e?0:+e),this._next||Vt===this||(Vt?Vt._next=this:Jt=this,Vt=this),this._call=t,this._time=n,fe()},stop:function(){this._call&&(this._call=null,this._time=1/0,fe())}};var he=x("start","end","cancel","interrupt"),pe=[];function me(t,e,n,r,o,i){var s=t.__transition;if(s){if(n in s)return}else t.__transition={};!function(t,e,n){var r,o=t.__transition;function i(t){n.state=1,n.timer.restart(s,n.delay,n.time),n.delay<=t&&s(t-n.delay)}function s(i){var c,u,f,d;if(1!==n.state)return l();for(c in o)if((d=o[c]).name===n.name){if(3===d.state)return de(s);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete o[c]):+c<e&&(d.state=6,d.timer.stop(),d.on.call("cancel",t,t.__data__,d.index,d.group),delete o[c])}if(de((function(){3===n.state&&(n.state=4,n.timer.restart(a,n.delay,n.time),a(i))})),n.state=2,n.on.call("start",t,t.__data__,n.index,n.group),2===n.state){for(n.state=3,r=new Array(f=n.tween.length),c=0,u=-1;c<f;++c)(d=n.tween[c].value.call(t,t.__data__,n.index,n.group))&&(r[++u]=d);r.length=u+1}}function a(e){for(var o=e<n.duration?n.ease.call(null,e/n.duration):(n.timer.restart(l),n.state=5,1),i=-1,s=r.length;++i<s;)r[i].call(t,o);5===n.state&&(n.on.call("end",t,t.__data__,n.index,n.group),l())}function l(){for(var r in n.state=6,n.timer.stop(),delete o[e],o)return;delete t.__transition}o[e]=n,n.timer=ae(i,0,n.time)}(t,n,{name:e,index:r,group:o,on:he,tween:pe,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:0})}function ge(t,e){var n=ve(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function ye(t,e){var n=ve(t,e);if(n.state>3)throw new Error("too late; already running");return n}function ve(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function be(t,e){var n,r,o,i=t.__transition,s=!0;if(i){for(o in e=null==e?null:e+"",i)(n=i[o]).name===e?(r=n.state>2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete i[o]):s=!1;s&&delete t.__transition}}var _e=n(2650);function we(t,e){var n,r;return function(){var o=ye(this,t),i=o.tween;if(i!==n)for(var s=0,a=(r=n=i).length;s<a;++s)if(r[s].name===e){(r=r.slice()).splice(s,1);break}o.tween=r}}function xe(t,e,n){var r,o;if("function"!=typeof n)throw new Error;return function(){var i=ye(this,t),s=i.tween;if(s!==r){o=(r=s).slice();for(var a={name:e,value:n},l=0,c=o.length;l<c;++l)if(o[l].name===e){o[l]=a;break}l===c&&o.push(a)}i.tween=o}}function ke(t,e,n){var r=t._id;return t.each((function(){var t=ye(this,r);(t.value||(t.value={}))[e]=n.apply(this,arguments)})),function(t){return ve(t,r).value[e]}}var qe=n(1495),Ne=n(8403),Se=n(490),Ae=n(9009);function Me(t,e){var n;return("number"==typeof e?Ne.Z:e instanceof qe.ZP?Se.ZP:(n=(0,qe.ZP)(e))?(e=n,Se.ZP):Ae.Z)(t,e)}function Te(t){return function(){this.removeAttribute(t)}}function Ce(t){return function(){this.removeAttributeNS(t.space,t.local)}}function je(t,e,n){var r,o,i=n+"";return function(){var s=this.getAttribute(t);return s===i?null:s===r?o:o=e(r=s,n)}}function Oe(t,e,n){var r,o,i=n+"";return function(){var s=this.getAttributeNS(t.space,t.local);return s===i?null:s===r?o:o=e(r=s,n)}}function Ee(t,e,n){var r,o,i;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttribute(t))===(a=l+"")?null:s===r&&a===o?i:(o=a,i=e(r=s,l));this.removeAttribute(t)}}function Re(t,e,n){var r,o,i;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttributeNS(t.space,t.local))===(a=l+"")?null:s===r&&a===o?i:(o=a,i=e(r=s,l));this.removeAttributeNS(t.space,t.local)}}function Ie(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}function Pe(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}function Fe(t,e){var n,r;function o(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&Pe(t,o)),n}return o._value=e,o}function Le(t,e){var n,r;function o(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&Ie(t,o)),n}return o._value=e,o}function De(t,e){return function(){ge(this,t).delay=+e.apply(this,arguments)}}function Be(t,e){return e=+e,function(){ge(this,t).delay=e}}function ze(t,e){return function(){ye(this,t).duration=+e.apply(this,arguments)}}function Ze(t,e){return e=+e,function(){ye(this,t).duration=e}}function $e(t,e){if("function"!=typeof e)throw new Error;return function(){ye(this,t).ease=e}}function Ge(t,e,n){var r,o,i=function(t){return(t+"").trim().split(/^|\s+/).every((function(t){var e=t.indexOf(".");return e>=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?ge:ye;return function(){var s=i(this,t),a=s.on;a!==r&&(o=(r=a).copy()).on(e,n),s.on=o}}var Ue=Ft.prototype.constructor;function He(t){return function(){this.style.removeProperty(t)}}function We(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function Je(t,e,n){var r,o;function i(){var i=e.apply(this,arguments);return i!==o&&(r=(o=i)&&We(t,i,n)),r}return i._value=e,i}function Ve(t){return function(e){this.textContent=t.call(this,e)}}function Ye(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&Ve(r)),e}return r._value=t,r}var Qe=0;function Ke(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function Xe(t){return Ft().transition(t)}function tn(){return++Qe}var en=Ft.prototype;function nn(t){return t*t*t}function rn(t){return--t*t*t+1}function on(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}Ke.prototype=Xe.prototype={constructor:Ke,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=q(t));for(var r=this._groups,o=r.length,i=new Array(o),s=0;s<o;++s)for(var a,l,c=r[s],u=c.length,f=i[s]=new Array(u),d=0;d<u;++d)(a=c[d])&&(l=t.call(a,a.__data__,d,c))&&("__data__"in a&&(l.__data__=a.__data__),f[d]=l,me(f[d],e,n,d,f,ve(a,n)));return new Ke(i,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=A(t));for(var r=this._groups,o=r.length,i=[],s=[],a=0;a<o;++a)for(var l,c=r[a],u=c.length,f=0;f<u;++f)if(l=c[f]){for(var d,h=t.call(l,l.__data__,f,c),p=ve(l,n),m=0,g=h.length;m<g;++m)(d=h[m])&&me(d,e,n,m,h,p);i.push(h),s.push(l)}return new Ke(i,s,e,n)},selectChild:en.selectChild,selectChildren:en.selectChildren,filter:function(t){"function"!=typeof t&&(t=M(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s=e[o],a=s.length,l=r[o]=[],c=0;c<a;++c)(i=s[c])&&t.call(i,i.__data__,c,s)&&l.push(i);return new Ke(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var e=this._groups,n=t._groups,r=e.length,o=n.length,i=Math.min(r,o),s=new Array(r),a=0;a<i;++a)for(var l,c=e[a],u=n[a],f=c.length,d=s[a]=new Array(f),h=0;h<f;++h)(l=c[h]||u[h])&&(d[h]=l);for(;a<r;++a)s[a]=e[a];return new Ke(s,this._parents,this._name,this._id)},selection:function(){return new Ue(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=tn(),r=this._groups,o=r.length,i=0;i<o;++i)for(var s,a=r[i],l=a.length,c=0;c<l;++c)if(s=a[c]){var u=ve(s,e);me(s,t,n,c,a,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Ke(r,this._parents,t,n)},call:en.call,nodes:en.nodes,node:en.node,size:en.size,empty:en.empty,each:en.each,on:function(t,e){var n=this._id;return arguments.length<2?ve(this.node(),n).on.on(t):this.each(Ge(n,t,e))},attr:function(t,e){var n=G(t),r="transform"===n?_e.w:Me;return this.attrTween(t,"function"==typeof e?(n.local?Re:Ee)(n,r,ke(this,"attr."+t,e)):null==e?(n.local?Ce:Te)(n):(n.local?Oe:je)(n,r,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var r=G(t);return this.tween(n,(r.local?Fe:Le)(r,e))},style:function(t,e,n){var r="transform"==(t+="")?_e.Y:Me;return null==e?this.styleTween(t,function(t,e){var n,r,o;return function(){var i=et(this,t),s=(this.style.removeProperty(t),et(this,t));return i===s?null:i===n&&s===r?o:o=e(n=i,r=s)}}(t,r)).on("end.style."+t,He(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var r,o,i;return function(){var s=et(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=et(this,t)),s===l?null:s===r&&l===o?i:(o=l,i=e(r=s,a))}}(t,r,ke(this,"style."+t,e))).each(function(t,e){var n,r,o,i,s="style."+e,a="end."+s;return function(){var l=ye(this,t),c=l.on,u=null==l.value[s]?i||(i=He(e)):void 0;c===n&&o===u||(r=(n=c).copy()).on(a,o=u),l.on=r}}(this._id,t)):this.styleTween(t,function(t,e,n){var r,o,i=n+"";return function(){var s=et(this,t);return s===i?null:s===r?o:o=e(r=s,n)}}(t,r,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!=typeof e)throw new Error;return this.tween(r,Je(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(ke(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,Ye(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var r,o=ve(this.node(),n).tween,i=0,s=o.length;i<s;++i)if((r=o[i]).name===t)return r.value;return null}return this.each((null==e?we:xe)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?De:Be)(e,t)):ve(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?ze:Ze)(e,t)):ve(this.node(),e).duration},ease:function(t){var e=this._id;return arguments.length?this.each($e(e,t)):ve(this.node(),e).ease},easeVarying:function(t){if("function"!=typeof t)throw new Error;return this.each(function(t,e){return function(){var n=e.apply(this,arguments);if("function"!=typeof n)throw new Error;ye(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,r=n._id,o=n.size();return new Promise((function(i,s){var a={value:s},l={value:function(){0==--o&&i()}};n.each((function(){var n=ye(this,r),o=n.on;o!==t&&((e=(t=o).copy())._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),n.on=e})),0===o&&i()}))},[Symbol.iterator]:en[Symbol.iterator]};var sn={time:null,delay:0,duration:250,ease:on};function an(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}Ft.prototype.interrupt=function(t){return this.each((function(){be(this,t)}))},Ft.prototype.transition=function(t){var e,n;t instanceof Ke?(e=t._id,t=t._name):(e=tn(),(n=sn).time=oe(),t=null==t?null:t+"");for(var r=this._groups,o=r.length,i=0;i<o;++i)for(var s,a=r[i],l=a.length,c=0;c<l;++c)(s=a[c])&&me(s,t,e,c,a,n||an(s,e));return new Ke(r,this._parents,t,e)};var ln=[null];function cn(t,e){var n,r,o=t.__transition;if(o)for(r in e=null==e?null:e+"",o)if((n=o[r]).state>1&&n.name===e)return new Ke([[t]],ln,e,+r);return null}const un=t=>()=>t;function fn(t,{sourceEvent:e,target:n,selection:r,mode:o,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},selection:{value:r,enumerable:!0,configurable:!0},mode:{value:o,enumerable:!0,configurable:!0},_:{value:i}})}function dn(t){t.stopImmediatePropagation()}function hn(t){t.preventDefault(),t.stopImmediatePropagation()}var pn={name:"drag"},mn={name:"space"},gn={name:"handle"},yn={name:"center"};const{abs:vn,max:bn,min:_n}=Math;function wn(t){return[+t[0],+t[1]]}function xn(t){return[wn(t[0]),wn(t[1])]}var kn={name:"x",handles:["w","e"].map(jn),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},qn={name:"y",handles:["n","s"].map(jn),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},Nn={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(jn),input:function(t){return null==t?null:xn(t)},output:function(t){return t}},Sn={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},An={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},Mn={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},Tn={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},Cn={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function jn(t){return{type:t}}function On(t){return!t.ctrlKey&&!t.button}function En(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function Rn(){return navigator.maxTouchPoints||"ontouchstart"in this}function In(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function Pn(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}function Fn(t){var e=t.__brush;return e?e.dim.output(e.selection):null}function Ln(){return zn(kn)}function Dn(){return zn(qn)}function Bn(){return zn(Nn)}function zn(t){var e,n=En,r=On,o=Rn,i=!0,s=x("start","brush","end"),a=6;function l(e){var n=e.property("__brush",m).selectAll(".overlay").data([jn("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",Sn.overlay).merge(n).each((function(){var t=In(this).extent;Lt(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])})),e.selectAll(".selection").data([jn("selection")]).enter().append("rect").attr("class","selection").attr("cursor",Sn.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,(function(t){return t.type}));r.exit().remove(),r.enter().append("rect").attr("class",(function(t){return"handle handle--"+t.type})).attr("cursor",(function(t){return Sn[t.type]})),e.each(c).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",d).filter(o).on("touchstart.brush",d).on("touchmove.brush",h).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function c(){var t=Lt(this),e=In(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",(function(t){return"e"===t.type[t.type.length-1]?e[1][0]-a/2:e[0][0]-a/2})).attr("y",(function(t){return"s"===t.type[0]?e[1][1]-a/2:e[0][1]-a/2})).attr("width",(function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+a:a})).attr("height",(function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+a:a}))):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function u(t,e,n){var r=t.__brush.emitter;return!r||n&&r.clean?new f(t,e,n):r}function f(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function d(n){if((!e||n.touches)&&r.apply(this,arguments)){var o,s,a,l,f,d,h,p,m,g,y,v=this,b=n.target.__data__.type,_="selection"===(i&&n.metaKey?b="overlay":b)?pn:i&&n.altKey?yn:gn,w=t===qn?null:Tn[b],x=t===kn?null:Cn[b],k=In(v),q=k.extent,N=k.selection,S=q[0][0],A=q[0][1],M=q[1][0],T=q[1][1],C=0,j=0,O=w&&x&&i&&n.shiftKey,E=Array.from(n.touches||[n],(t=>{const e=t.identifier;return(t=Wt(t,v)).point0=t.slice(),t.identifier=e,t}));be(v);var R=u(v,arguments,!0).beforestart();if("overlay"===b){N&&(m=!0);const e=[E[0],E[1]||E[0]];k.selection=N=[[o=t===qn?S:_n(e[0][0],e[1][0]),a=t===kn?A:_n(e[0][1],e[1][1])],[f=t===qn?M:bn(e[0][0],e[1][0]),h=t===kn?T:bn(e[0][1],e[1][1])]],E.length>1&&D(n)}else o=N[0][0],a=N[0][1],f=N[1][0],h=N[1][1];s=o,l=a,d=f,p=h;var I=Lt(v).attr("pointer-events","none"),P=I.selectAll(".overlay").attr("cursor",Sn[b]);if(n.touches)R.moved=L,R.ended=B;else{var F=Lt(n.view).on("mousemove.brush",L,!0).on("mouseup.brush",B,!0);i&&F.on("keydown.brush",z,!0).on("keyup.brush",Z,!0),$t(n.view)}c.call(v),R.start(n,_.name)}function L(t){for(const e of t.changedTouches||[t])for(const t of E)t.identifier===e.identifier&&(t.cur=Wt(e,v));if(O&&!g&&!y&&1===E.length){const t=E[0];vn(t.cur[0]-t[0])>vn(t.cur[1]-t[1])?y=!0:g=!0}for(const t of E)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);m=!0,hn(t),D(t)}function D(t){const e=E[0],n=e.point0;var r;switch(C=e[0]-n[0],j=e[1]-n[1],_){case mn:case pn:w&&(C=bn(S-o,_n(M-f,C)),s=o+C,d=f+C),x&&(j=bn(A-a,_n(T-h,j)),l=a+j,p=h+j);break;case gn:E[1]?(w&&(s=bn(S,_n(M,E[0][0])),d=bn(S,_n(M,E[1][0])),w=1),x&&(l=bn(A,_n(T,E[0][1])),p=bn(A,_n(T,E[1][1])),x=1)):(w<0?(C=bn(S-o,_n(M-o,C)),s=o+C,d=f):w>0&&(C=bn(S-f,_n(M-f,C)),s=o,d=f+C),x<0?(j=bn(A-a,_n(T-a,j)),l=a+j,p=h):x>0&&(j=bn(A-h,_n(T-h,j)),l=a,p=h+j));break;case yn:w&&(s=bn(S,_n(M,o-C*w)),d=bn(S,_n(M,f+C*w))),x&&(l=bn(A,_n(T,a-j*x)),p=bn(A,_n(T,h+j*x)))}d<s&&(w*=-1,r=o,o=f,f=r,r=s,s=d,d=r,b in An&&P.attr("cursor",Sn[b=An[b]])),p<l&&(x*=-1,r=a,a=h,h=r,r=l,l=p,p=r,b in Mn&&P.attr("cursor",Sn[b=Mn[b]])),k.selection&&(N=k.selection),g&&(s=N[0][0],d=N[1][0]),y&&(l=N[0][1],p=N[1][1]),N[0][0]===s&&N[0][1]===l&&N[1][0]===d&&N[1][1]===p||(k.selection=[[s,l],[d,p]],c.call(v),R.brush(t,_.name))}function B(t){if(dn(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout((function(){e=null}),500)}else Gt(t.view,m),F.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);I.attr("pointer-events","all"),P.attr("cursor",Sn.overlay),k.selection&&(N=k.selection),Pn(N)&&(k.selection=null,c.call(v)),R.end(t,_.name)}function z(t){switch(t.keyCode){case 16:O=w&&x;break;case 18:_===gn&&(w&&(f=d-C*w,o=s+C*w),x&&(h=p-j*x,a=l+j*x),_=yn,D(t));break;case 32:_!==gn&&_!==yn||(w<0?f=d-C:w>0&&(o=s-C),x<0?h=p-j:x>0&&(a=l-j),_=mn,P.attr("cursor",Sn.selection),D(t));break;default:return}hn(t)}function Z(t){switch(t.keyCode){case 16:O&&(g=y=O=!1,D(t));break;case 18:_===yn&&(w<0?f=d:w>0&&(o=s),x<0?h=p:x>0&&(a=l),_=gn,D(t));break;case 32:_===mn&&(t.altKey?(w&&(f=d-C*w,o=s+C*w),x&&(h=p-j*x,a=l+j*x),_=yn):(w<0?f=d:w>0&&(o=s),x<0?h=p:x>0&&(a=l),_=gn),P.attr("cursor",Sn[b]),D(t));break;default:return}hn(t)}}function h(t){u(this,arguments).moved(t)}function p(t){u(this,arguments).ended(t)}function m(){var e=this.__brush||{selection:null};return e.extent=xn(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,r){e.tween?e.on("start.brush",(function(t){u(this,arguments).beforestart().start(t)})).on("interrupt.brush end.brush",(function(t){u(this,arguments).end(t)})).tween("brush",(function(){var e=this,r=e.__brush,o=u(e,arguments),i=r.selection,s=t.input("function"==typeof n?n.apply(this,arguments):n,r.extent),a=(0,Ut.Z)(i,s);function l(t){r.selection=1===t&&null===s?null:a(t),c.call(e),o.brush()}return null!==i&&null!==s?l:l(1)})):e.each((function(){var e=this,o=arguments,i=e.__brush,s=t.input("function"==typeof n?n.apply(e,o):n,i.extent),a=u(e,o).beforestart();be(e),i.selection=null===s?null:s,c.call(e),a.start(r).brush(r).end(r)}))},l.clear=function(t,e){l.move(t,null,e)},f.prototype={beforestart:function(){return 1==++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(t,e){return this.starting?(this.starting=!1,this.emit("start",t,e)):this.emit("brush",t),this},brush:function(t,e){return this.emit("brush",t,e),this},end:function(t,e){return 0==--this.active&&(delete this.state.emitter,this.emit("end",t,e)),this},emit:function(e,n,r){var o=Lt(this.that).datum();s.call(e,this.that,new fn(e,{sourceEvent:n,target:l,selection:t.output(this.state.selection),mode:r,dispatch:s}),o)}},l.extent=function(t){return arguments.length?(n="function"==typeof t?t:un(xn(t)),l):n},l.filter=function(t){return arguments.length?(r="function"==typeof t?t:un(!!t),l):r},l.touchable=function(t){return arguments.length?(o="function"==typeof t?t:un(!!t),l):o},l.handleSize=function(t){return arguments.length?(a=+t,l):a},l.keyModifiers=function(t){return arguments.length?(i=!!t,l):i},l.on=function(){var t=s.on.apply(s,arguments);return t===s?l:t},l}var Zn=Math.abs,$n=Math.cos,Gn=Math.sin,Un=Math.PI,Hn=Un/2,Wn=2*Un,Jn=Math.max,Vn=1e-12;function Yn(t,e){return Array.from({length:e-t},((e,n)=>t+n))}function Qn(t){return function(e,n){return t(e.source.value+e.target.value,n.source.value+n.target.value)}}function Kn(){return er(!1,!1)}function Xn(){return er(!1,!0)}function tr(){return er(!0,!1)}function er(t,e){var n=0,r=null,o=null,i=null;function s(s){var a,l=s.length,c=new Array(l),u=Yn(0,l),f=new Array(l*l),d=new Array(l),h=0;s=Float64Array.from({length:l*l},e?(t,e)=>s[e%l][e/l|0]:(t,e)=>s[e/l|0][e%l]);for(let e=0;e<l;++e){let n=0;for(let r=0;r<l;++r)n+=s[e*l+r]+t*s[r*l+e];h+=c[e]=n}a=(h=Jn(0,Wn-n*l)/h)?n:Wn/l;{let e=0;r&&u.sort(((t,e)=>r(c[t],c[e])));for(const n of u){const r=e;if(t){const t=Yn(1+~l,l).filter((t=>t<0?s[~t*l+n]:s[n*l+t]));o&&t.sort(((t,e)=>o(t<0?-s[~t*l+n]:s[n*l+t],e<0?-s[~e*l+n]:s[n*l+e])));for(const r of t)if(r<0){(f[~r*l+n]||(f[~r*l+n]={source:null,target:null})).target={index:n,startAngle:e,endAngle:e+=s[~r*l+n]*h,value:s[~r*l+n]}}else{(f[n*l+r]||(f[n*l+r]={source:null,target:null})).source={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]}}d[n]={index:n,startAngle:r,endAngle:e,value:c[n]}}else{const t=Yn(0,l).filter((t=>s[n*l+t]||s[t*l+n]));o&&t.sort(((t,e)=>o(s[n*l+t],s[n*l+e])));for(const r of t){let t;if(n<r?(t=f[n*l+r]||(f[n*l+r]={source:null,target:null}),t.source={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]}):(t=f[r*l+n]||(f[r*l+n]={source:null,target:null}),t.target={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]},n===r&&(t.source=t.target)),t.source&&t.target&&t.source.value<t.target.value){const e=t.source;t.source=t.target,t.target=e}}d[n]={index:n,startAngle:r,endAngle:e,value:c[n]}}e+=a}}return(f=Object.values(f)).groups=d,i?f.sort(i):f}return s.padAngle=function(t){return arguments.length?(n=Jn(0,t),s):n},s.sortGroups=function(t){return arguments.length?(r=t,s):r},s.sortSubgroups=function(t){return arguments.length?(o=t,s):o},s.sortChords=function(t){return arguments.length?(null==t?i=null:(i=Qn(t))._=t,s):i&&i._},s}const nr=Math.PI,rr=2*nr,or=1e-6,ir=rr-or;function sr(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function ar(){return new sr}sr.prototype=ar.prototype={constructor:sr,moveTo:function(t,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,e){this._+="L"+(this._x1=+t)+","+(this._y1=+e)},quadraticCurveTo:function(t,e,n,r){this._+="Q"+ +t+","+ +e+","+(this._x1=+n)+","+(this._y1=+r)},bezierCurveTo:function(t,e,n,r,o,i){this._+="C"+ +t+","+ +e+","+ +n+","+ +r+","+(this._x1=+o)+","+(this._y1=+i)},arcTo:function(t,e,n,r,o){t=+t,e=+e,n=+n,r=+r,o=+o;var i=this._x1,s=this._y1,a=n-t,l=r-e,c=i-t,u=s-e,f=c*c+u*u;if(o<0)throw new Error("negative radius: "+o);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=e);else if(f>or)if(Math.abs(u*a-l*c)>or&&o){var d=n-i,h=r-s,p=a*a+l*l,m=d*d+h*h,g=Math.sqrt(p),y=Math.sqrt(f),v=o*Math.tan((nr-Math.acos((p+f-m)/(2*g*y)))/2),b=v/y,_=v/g;Math.abs(b-1)>or&&(this._+="L"+(t+b*c)+","+(e+b*u)),this._+="A"+o+","+o+",0,0,"+ +(u*d>c*h)+","+(this._x1=t+_*a)+","+(this._y1=e+_*l)}else this._+="L"+(this._x1=t)+","+(this._y1=e);else;},arc:function(t,e,n,r,o,i){t=+t,e=+e,i=!!i;var s=(n=+n)*Math.cos(r),a=n*Math.sin(r),l=t+s,c=e+a,u=1^i,f=i?r-o:o-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+l+","+c:(Math.abs(this._x1-l)>or||Math.abs(this._y1-c)>or)&&(this._+="L"+l+","+c),n&&(f<0&&(f=f%rr+rr),f>ir?this._+="A"+n+","+n+",0,1,"+u+","+(t-s)+","+(e-a)+"A"+n+","+n+",0,1,"+u+","+(this._x1=l)+","+(this._y1=c):f>or&&(this._+="A"+n+","+n+",0,"+ +(f>=nr)+","+u+","+(this._x1=t+n*Math.cos(o))+","+(this._y1=e+n*Math.sin(o))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};const lr=ar;var cr=Array.prototype.slice;function ur(t){return function(){return t}}function fr(t){return t.source}function dr(t){return t.target}function hr(t){return t.radius}function pr(t){return t.startAngle}function mr(t){return t.endAngle}function gr(){return 0}function yr(){return 10}function vr(t){var e=fr,n=dr,r=hr,o=hr,i=pr,s=mr,a=gr,l=null;function c(){var c,u=e.apply(this,arguments),f=n.apply(this,arguments),d=a.apply(this,arguments)/2,h=cr.call(arguments),p=+r.apply(this,(h[0]=u,h)),m=i.apply(this,h)-Hn,g=s.apply(this,h)-Hn,y=+o.apply(this,(h[0]=f,h)),v=i.apply(this,h)-Hn,b=s.apply(this,h)-Hn;if(l||(l=c=lr()),d>Vn&&(Zn(g-m)>2*d+Vn?g>m?(m+=d,g-=d):(m-=d,g+=d):m=g=(m+g)/2,Zn(b-v)>2*d+Vn?b>v?(v+=d,b-=d):(v-=d,b+=d):v=b=(v+b)/2),l.moveTo(p*$n(m),p*Gn(m)),l.arc(0,0,p,m,g),m!==v||g!==b)if(t){var _=+t.apply(this,arguments),w=y-_,x=(v+b)/2;l.quadraticCurveTo(0,0,w*$n(v),w*Gn(v)),l.lineTo(y*$n(x),y*Gn(x)),l.lineTo(w*$n(b),w*Gn(b))}else l.quadraticCurveTo(0,0,y*$n(v),y*Gn(v)),l.arc(0,0,y,v,b);if(l.quadraticCurveTo(0,0,p*$n(m),p*Gn(m)),l.closePath(),c)return l=null,c+""||null}return t&&(c.headRadius=function(e){return arguments.length?(t="function"==typeof e?e:ur(+e),c):t}),c.radius=function(t){return arguments.length?(r=o="function"==typeof t?t:ur(+t),c):r},c.sourceRadius=function(t){return arguments.length?(r="function"==typeof t?t:ur(+t),c):r},c.targetRadius=function(t){return arguments.length?(o="function"==typeof t?t:ur(+t),c):o},c.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:ur(+t),c):i},c.endAngle=function(t){return arguments.length?(s="function"==typeof t?t:ur(+t),c):s},c.padAngle=function(t){return arguments.length?(a="function"==typeof t?t:ur(+t),c):a},c.source=function(t){return arguments.length?(e=t,c):e},c.target=function(t){return arguments.length?(n=t,c):n},c.context=function(t){return arguments.length?(l=null==t?null:t,c):l},c}function br(){return vr()}function _r(){return vr(yr)}var wr=n(7346),xr=n(2327),kr=n(2038),qr=n(6106),Nr=Array.prototype.slice;function Sr(t,e){return t-e}const Ar=t=>()=>t;function Mr(t,e){for(var n,r=-1,o=e.length;++r<o;)if(n=Tr(t,e[r]))return n;return 0}function Tr(t,e){for(var n=e[0],r=e[1],o=-1,i=0,s=t.length,a=s-1;i<s;a=i++){var l=t[i],c=l[0],u=l[1],f=t[a],d=f[0],h=f[1];if(Cr(l,f,e))return 0;u>r!=h>r&&n<(d-c)*(r-u)/(h-u)+c&&(o=-o)}return o}function Cr(t,e,n){var r,o,i,s;return function(t,e,n){return(e[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(e[1]-t[1])}(t,e,n)&&(o=t[r=+(t[0]===e[0])],i=n[r],s=e[r],o<=i&&i<=s||s<=i&&i<=o)}function jr(){}var Or=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Er(){var t=1,e=1,n=xr.Z,r=a;function o(t){var e=n(t);if(Array.isArray(e))e=e.slice().sort(Sr);else{const n=(0,kr.Z)(t),r=(0,qr.ly)(n[0],n[1],e);e=(0,qr.ZP)(Math.floor(n[0]/r)*r,Math.floor(n[1]/r-1)*r,e)}return e.map((e=>i(t,e)))}function i(n,o){var i=[],a=[];return function(n,r,o){var i,a,l,c,u,f,d=new Array,h=new Array;i=a=-1,c=n[0]>=r,Or[c<<1].forEach(p);for(;++i<t-1;)l=c,c=n[i+1]>=r,Or[l|c<<1].forEach(p);Or[c<<0].forEach(p);for(;++a<e-1;){for(i=-1,c=n[a*t+t]>=r,u=n[a*t]>=r,Or[c<<1|u<<2].forEach(p);++i<t-1;)l=c,c=n[a*t+t+i+1]>=r,f=u,u=n[a*t+i+1]>=r,Or[l|c<<1|u<<2|f<<3].forEach(p);Or[c|u<<3].forEach(p)}i=-1,u=n[a*t]>=r,Or[u<<2].forEach(p);for(;++i<t-1;)f=u,u=n[a*t+i+1]>=r,Or[u<<2|f<<3].forEach(p);function p(t){var e,n,r=[t[0][0]+i,t[0][1]+a],l=[t[1][0]+i,t[1][1]+a],c=s(r),u=s(l);(e=h[c])?(n=d[u])?(delete h[e.end],delete d[n.start],e===n?(e.ring.push(l),o(e.ring)):d[e.start]=h[n.end]={start:e.start,end:n.end,ring:e.ring.concat(n.ring)}):(delete h[e.end],e.ring.push(l),h[e.end=u]=e):(e=d[u])?(n=h[c])?(delete d[e.start],delete h[n.end],e===n?(e.ring.push(l),o(e.ring)):d[n.start]=h[e.end]={start:n.start,end:e.end,ring:n.ring.concat(e.ring)}):(delete d[e.start],e.ring.unshift(r),d[e.start=c]=e):d[c]=h[u]={start:c,end:u,ring:[r,l]}}Or[u<<3].forEach(p)}(n,o,(function(t){r(t,n,o),function(t){for(var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++e<n;)r+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return r}(t)>0?i.push([t]):a.push(t)})),a.forEach((function(t){for(var e,n=0,r=i.length;n<r;++n)if(-1!==Mr((e=i[n])[0],t))return void e.push(t)})),{type:"MultiPolygon",value:o,coordinates:i}}function s(e){return 2*e[0]+e[1]*(t+1)*4}function a(n,r,o){n.forEach((function(n){var i,s=n[0],a=n[1],l=0|s,c=0|a,u=r[c*t+l];s>0&&s<t&&l===s&&(i=r[c*t+l-1],n[0]=s+(o-i)/(u-i)-.5),a>0&&a<e&&c===a&&(i=r[(c-1)*t+l],n[1]=a+(o-i)/(u-i)-.5)}))}return o.contour=i,o.size=function(n){if(!arguments.length)return[t,e];var r=Math.floor(n[0]),i=Math.floor(n[1]);if(!(r>=0&&i>=0))throw new Error("invalid size");return t=r,e=i,o},o.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:Array.isArray(t)?Ar(Nr.call(t)):Ar(t),o):n},o.smooth=function(t){return arguments.length?(r=t?a:jr,o):r===a},o}var Rr=n(1045),Ir=n(8319);function Pr(t){return t[0]}function Fr(t){return t[1]}function Lr(){return 1}function Dr(){var t=Pr,e=Fr,n=Lr,r=960,o=500,i=20,s=2,a=3*i,l=r+2*a>>s,c=o+2*a>>s,u=Ar(20);function f(r){var o=new Float32Array(l*c),u=Math.pow(2,-s),f=-1;for(const i of r){var d=(t(i,++f,r)+a)*u,h=(e(i,f,r)+a)*u,p=+n(i,f,r);if(d>=0&&d<l&&h>=0&&h<c){var m=Math.floor(d),g=Math.floor(h),y=d-m-.5,v=h-g-.5;o[m+g*l]+=(1-y)*(1-v)*p,o[m+1+g*l]+=y*(1-v)*p,o[m+1+(g+1)*l]+=y*v*p,o[m+(g+1)*l]+=(1-y)*v*p}}return(0,Rr.u8)({data:o,width:l,height:c},i*u),o}function d(t){var e=f(t),n=u(e),r=Math.pow(2,2*s);return Array.isArray(n)||(n=(0,qr.ZP)(Number.MIN_VALUE,(0,Ir.Z)(e)/r,n)),Er().size([l,c]).thresholds(n.map((t=>t*r)))(e).map(((t,e)=>(t.value=+n[e],h(t))))}function h(t){return t.coordinates.forEach(p),t}function p(t){t.forEach(m)}function m(t){t.forEach(g)}function g(t){t[0]=t[0]*Math.pow(2,s)-a,t[1]=t[1]*Math.pow(2,s)-a}function y(){return l=r+2*(a=3*i)>>s,c=o+2*a>>s,d}return d.contours=function(t){var e=f(t),n=Er().size([l,c]),r=Math.pow(2,2*s),o=t=>{t=+t;var o=h(n.contour(e,t*r));return o.value=t,o};return Object.defineProperty(o,"max",{get:()=>(0,Ir.Z)(e)/r}),o},d.x=function(e){return arguments.length?(t="function"==typeof e?e:Ar(+e),d):t},d.y=function(t){return arguments.length?(e="function"==typeof t?t:Ar(+t),d):e},d.weight=function(t){return arguments.length?(n="function"==typeof t?t:Ar(+t),d):n},d.size=function(t){if(!arguments.length)return[r,o];var e=+t[0],n=+t[1];if(!(e>=0&&n>=0))throw new Error("invalid size");return r=e,o=n,y()},d.cellSize=function(t){if(!arguments.length)return 1<<s;if(!((t=+t)>=1))throw new Error("invalid cell size");return s=Math.floor(Math.log(t)/Math.LN2),y()},d.thresholds=function(t){return arguments.length?(u="function"==typeof t?t:Array.isArray(t)?Ar(Nr.call(t)):Ar(t),d):u},d.bandwidth=function(t){if(!arguments.length)return Math.sqrt(i*(i+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return i=(Math.sqrt(4*t*t+1)-1)/2,y()},d}const Br=134217729;function zr(t,e,n,r,o){let i,s,a,l,c=e[0],u=r[0],f=0,d=0;u>c==u>-c?(i=c,c=e[++f]):(i=u,u=r[++d]);let h=0;if(f<t&&d<n)for(u>c==u>-c?(s=c+i,a=i-(s-c),c=e[++f]):(s=u+i,a=i-(s-u),u=r[++d]),i=s,0!==a&&(o[h++]=a);f<t&&d<n;)u>c==u>-c?(s=i+c,l=s-i,a=i-(s-l)+(c-l),c=e[++f]):(s=i+u,l=s-i,a=i-(s-l)+(u-l),u=r[++d]),i=s,0!==a&&(o[h++]=a);for(;f<t;)s=i+c,l=s-i,a=i-(s-l)+(c-l),c=e[++f],i=s,0!==a&&(o[h++]=a);for(;d<n;)s=i+u,l=s-i,a=i-(s-l)+(u-l),u=r[++d],i=s,0!==a&&(o[h++]=a);return 0===i&&0!==h||(o[h++]=i),h}function Zr(t){return new Float64Array(t)}const $r=Zr(4),Gr=Zr(8),Ur=Zr(12),Hr=Zr(16),Wr=Zr(4);function Jr(t,e,n,r,o,i){const s=(e-i)*(n-o),a=(t-o)*(r-i),l=s-a;if(0===s||0===a||s>0!=a>0)return l;const c=Math.abs(s+a);return Math.abs(l)>=33306690738754716e-32*c?l:-function(t,e,n,r,o,i,s){let a,l,c,u,f,d,h,p,m,g,y,v,b,_,w,x,k,q;const N=t-o,S=n-o,A=e-i,M=r-i;_=N*M,d=Br*N,h=d-(d-N),p=N-h,d=Br*M,m=d-(d-M),g=M-m,w=p*g-(_-h*m-p*m-h*g),x=A*S,d=Br*A,h=d-(d-A),p=A-h,d=Br*S,m=d-(d-S),g=S-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,$r[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,$r[1]=b-(y+f)+(f-x),q=v+y,f=q-v,$r[2]=v-(q-f)+(y-f),$r[3]=q;let T=function(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}(4,$r),C=22204460492503146e-32*s;if(T>=C||-T>=C)return T;if(f=t-N,a=t-(N+f)+(f-o),f=n-S,c=n-(S+f)+(f-o),f=e-A,l=e-(A+f)+(f-i),f=r-M,u=r-(M+f)+(f-i),0===a&&0===l&&0===c&&0===u)return T;if(C=11093356479670487e-47*s+33306690738754706e-32*Math.abs(T),T+=N*u+M*a-(A*c+S*l),T>=C||-T>=C)return T;_=a*M,d=Br*a,h=d-(d-a),p=a-h,d=Br*M,m=d-(d-M),g=M-m,w=p*g-(_-h*m-p*m-h*g),x=l*S,d=Br*l,h=d-(d-l),p=l-h,d=Br*S,m=d-(d-S),g=S-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Wr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Wr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Wr[2]=v-(q-f)+(y-f),Wr[3]=q;const j=zr(4,$r,4,Wr,Gr);_=N*u,d=Br*N,h=d-(d-N),p=N-h,d=Br*u,m=d-(d-u),g=u-m,w=p*g-(_-h*m-p*m-h*g),x=A*c,d=Br*A,h=d-(d-A),p=A-h,d=Br*c,m=d-(d-c),g=c-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Wr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Wr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Wr[2]=v-(q-f)+(y-f),Wr[3]=q;const O=zr(j,Gr,4,Wr,Ur);_=a*u,d=Br*a,h=d-(d-a),p=a-h,d=Br*u,m=d-(d-u),g=u-m,w=p*g-(_-h*m-p*m-h*g),x=l*c,d=Br*l,h=d-(d-l),p=l-h,d=Br*c,m=d-(d-c),g=c-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Wr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Wr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Wr[2]=v-(q-f)+(y-f),Wr[3]=q;const E=zr(O,Ur,4,Wr,Hr);return Hr[E-1]}(t,e,n,r,o,i,c)}Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(8),Zr(8),Zr(8),Zr(4),Zr(8),Zr(8),Zr(8),Zr(12);Zr(192),Zr(192);Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(8),Zr(8),Zr(8),Zr(8),Zr(8),Zr(8),Zr(8),Zr(8),Zr(8),Zr(4),Zr(4),Zr(4),Zr(8),Zr(16),Zr(16),Zr(16),Zr(32),Zr(32),Zr(48),Zr(64);Zr(1152),Zr(1152);Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(4),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(24),Zr(1152),Zr(1152),Zr(1152),Zr(1152),Zr(1152),Zr(2304),Zr(2304),Zr(3456),Zr(5760),Zr(8),Zr(8),Zr(8),Zr(16),Zr(24),Zr(48),Zr(48),Zr(96),Zr(192),Zr(384),Zr(384),Zr(384),Zr(768);Zr(96),Zr(96),Zr(96),Zr(1152);const Vr=Math.pow(2,-52),Yr=new Uint32Array(512);class Qr{static from(t,e=ro,n=oo){const r=t.length,o=new Float64Array(2*r);for(let i=0;i<r;i++){const r=t[i];o[2*i]=e(r),o[2*i+1]=n(r)}return new Qr(o)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const n=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*n),this._halfedges=new Int32Array(3*n),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:r,_hullHash:o}=this,i=t.length>>1;let s=1/0,a=1/0,l=-1/0,c=-1/0;for(let e=0;e<i;e++){const n=t[2*e],r=t[2*e+1];n<s&&(s=n),r<a&&(a=r),n>l&&(l=n),r>c&&(c=r),this._ids[e]=e}const u=(s+l)/2,f=(a+c)/2;let d,h,p,m=1/0;for(let e=0;e<i;e++){const n=Kr(u,f,t[2*e],t[2*e+1]);n<m&&(d=e,m=n)}const g=t[2*d],y=t[2*d+1];m=1/0;for(let e=0;e<i;e++){if(e===d)continue;const n=Kr(g,y,t[2*e],t[2*e+1]);n<m&&n>0&&(h=e,m=n)}let v=t[2*h],b=t[2*h+1],_=1/0;for(let e=0;e<i;e++){if(e===d||e===h)continue;const n=to(g,y,v,b,t[2*e],t[2*e+1]);n<_&&(p=e,_=n)}let w=t[2*p],x=t[2*p+1];if(_===1/0){for(let e=0;e<i;e++)this._dists[e]=t[2*e]-t[0]||t[2*e+1]-t[1];eo(this._ids,this._dists,0,i-1);const e=new Uint32Array(i);let n=0;for(let t=0,r=-1/0;t<i;t++){const o=this._ids[t];this._dists[o]>r&&(e[n++]=o,r=this._dists[o])}return this.hull=e.subarray(0,n),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(Jr(g,y,v,b,w,x)<0){const t=h,e=v,n=b;h=p,v=w,b=x,p=t,w=e,x=n}const k=function(t,e,n,r,o,i){const s=n-t,a=r-e,l=o-t,c=i-e,u=s*s+a*a,f=l*l+c*c,d=.5/(s*c-a*l);return{x:t+(c*u-a*f)*d,y:e+(s*f-l*u)*d}}(g,y,v,b,w,x);this._cx=k.x,this._cy=k.y;for(let e=0;e<i;e++)this._dists[e]=Kr(t[2*e],t[2*e+1],k.x,k.y);eo(this._ids,this._dists,0,i-1),this._hullStart=d;let q=3;n[d]=e[p]=h,n[h]=e[d]=p,n[p]=e[h]=d,r[d]=0,r[h]=1,r[p]=2,o.fill(-1),o[this._hashKey(g,y)]=d,o[this._hashKey(v,b)]=h,o[this._hashKey(w,x)]=p,this.trianglesLen=0,this._addTriangle(d,h,p,-1,-1,-1);for(let i,s,a=0;a<this._ids.length;a++){const l=this._ids[a],c=t[2*l],u=t[2*l+1];if(a>0&&Math.abs(c-i)<=Vr&&Math.abs(u-s)<=Vr)continue;if(i=c,s=u,l===d||l===h||l===p)continue;let f=0;for(let t=0,e=this._hashKey(c,u);t<this._hashSize&&(f=o[(e+t)%this._hashSize],-1===f||f===n[f]);t++);f=e[f];let m,g=f;for(;m=n[g],Jr(c,u,t[2*g],t[2*g+1],t[2*m],t[2*m+1])>=0;)if(g=m,g===f){g=-1;break}if(-1===g)continue;let y=this._addTriangle(g,l,n[g],-1,-1,r[g]);r[l]=this._legalize(y+2),r[g]=y,q++;let v=n[g];for(;m=n[v],Jr(c,u,t[2*v],t[2*v+1],t[2*m],t[2*m+1])<0;)y=this._addTriangle(v,l,m,r[l],-1,r[v]),r[l]=this._legalize(y+2),n[v]=v,q--,v=m;if(g===f)for(;m=e[g],Jr(c,u,t[2*m],t[2*m+1],t[2*g],t[2*g+1])<0;)y=this._addTriangle(m,l,g,-1,r[g],r[m]),this._legalize(y+2),r[m]=y,n[g]=g,q--,g=m;this._hullStart=e[l]=g,n[g]=e[v]=l,n[l]=v,o[this._hashKey(c,u)]=l,o[this._hashKey(t[2*g],t[2*g+1])]=g}this.hull=new Uint32Array(q);for(let t=0,e=this._hullStart;t<q;t++)this.hull[t]=e,e=n[e];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:n,coords:r}=this;let o=0,i=0;for(;;){const s=n[t],a=t-t%3;if(i=a+(t+2)%3,-1===s){if(0===o)break;t=Yr[--o];continue}const l=s-s%3,c=a+(t+1)%3,u=l+(s+2)%3,f=e[i],d=e[t],h=e[c],p=e[u];if(Xr(r[2*f],r[2*f+1],r[2*d],r[2*d+1],r[2*h],r[2*h+1],r[2*p],r[2*p+1])){e[t]=p,e[s]=f;const r=n[u];if(-1===r){let e=this._hullStart;do{if(this._hullTri[e]===u){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,r),this._link(s,n[i]),this._link(i,u);const a=l+(s+1)%3;o<Yr.length&&(Yr[o++]=a)}else{if(0===o)break;t=Yr[--o]}}return i}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,n,r,o,i){const s=this.trianglesLen;return this._triangles[s]=t,this._triangles[s+1]=e,this._triangles[s+2]=n,this._link(s,r),this._link(s+1,o),this._link(s+2,i),this.trianglesLen+=3,s}}function Kr(t,e,n,r){const o=t-n,i=e-r;return o*o+i*i}function Xr(t,e,n,r,o,i,s,a){const l=t-s,c=e-a,u=n-s,f=r-a,d=o-s,h=i-a,p=u*u+f*f,m=d*d+h*h;return l*(f*m-p*h)-c*(u*m-p*d)+(l*l+c*c)*(u*h-f*d)<0}function to(t,e,n,r,o,i){const s=n-t,a=r-e,l=o-t,c=i-e,u=s*s+a*a,f=l*l+c*c,d=.5/(s*c-a*l),h=(c*u-a*f)*d,p=(s*f-l*u)*d;return h*h+p*p}function eo(t,e,n,r){if(r-n<=20)for(let o=n+1;o<=r;o++){const r=t[o],i=e[r];let s=o-1;for(;s>=n&&e[t[s]]>i;)t[s+1]=t[s--];t[s+1]=r}else{let o=n+1,i=r;no(t,n+r>>1,o),e[t[n]]>e[t[r]]&&no(t,n,r),e[t[o]]>e[t[r]]&&no(t,o,r),e[t[n]]>e[t[o]]&&no(t,n,o);const s=t[o],a=e[s];for(;;){do{o++}while(e[t[o]]<a);do{i--}while(e[t[i]]>a);if(i<o)break;no(t,o,i)}t[n+1]=t[i],t[i]=s,r-o+1>=i-n?(eo(t,e,o,r),eo(t,e,n,i-1)):(eo(t,e,n,i-1),eo(t,e,o,r))}}function no(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function ro(t){return t[0]}function oo(t){return t[1]}const io=1e-6;class so{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,n){const r=(t=+t)+(n=+n),o=e=+e;if(n<0)throw new Error("negative radius");null===this._x1?this._+=`M${r},${o}`:(Math.abs(this._x1-r)>io||Math.abs(this._y1-o)>io)&&(this._+="L"+r+","+o),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=r},${this._y1=o}`)}rect(t,e,n,r){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+r}h${-n}Z`}value(){return this._||null}}class ao{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class lo{constructor(t,[e,n,r,o]=[0,0,960,500]){if(!((r=+r)>=(e=+e)&&(o=+o)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=r,this.xmin=e,this.ymax=o,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:r}=this,o=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let e,r,i=0,s=0,a=n.length;i<a;i+=3,s+=2){const a=2*n[i],l=2*n[i+1],c=2*n[i+2],u=t[a],f=t[a+1],d=t[l],h=t[l+1],p=t[c],m=t[c+1],g=d-u,y=h-f,v=p-u,b=m-f,_=2*(g*b-y*v);if(Math.abs(_)<1e-9){let o=1e9;const i=2*n[0];o*=Math.sign((t[i]-u)*b-(t[i+1]-f)*v),e=(u+p)/2-o*b,r=(f+m)/2+o*v}else{const t=1/_,n=g*g+y*y,o=v*v+b*b;e=u+(b*n-y*o)*t,r=f+(g*o-v*n)*t}o[s]=e,o[s+1]=r}let i,s,a,l=e[e.length-1],c=4*l,u=t[2*l],f=t[2*l+1];r.fill(0);for(let n=0;n<e.length;++n)l=e[n],i=c,s=u,a=f,c=4*l,u=t[2*l],f=t[2*l+1],r[i+2]=r[c]=a-f,r[i+3]=r[c+1]=u-s}render(t){const e=null==t?t=new so:void 0,{delaunay:{halfedges:n,inedges:r,hull:o},circumcenters:i,vectors:s}=this;if(o.length<=1)return null;for(let e=0,r=n.length;e<r;++e){const r=n[e];if(r<e)continue;const o=2*Math.floor(e/3),s=2*Math.floor(r/3),a=i[o],l=i[o+1],c=i[s],u=i[s+1];this._renderSegment(a,l,c,u,t)}let a,l=o[o.length-1];for(let e=0;e<o.length;++e){a=l,l=o[e];const n=2*Math.floor(r[l]/3),c=i[n],u=i[n+1],f=4*a,d=this._project(c,u,s[f+2],s[f+3]);d&&this._renderSegment(c,u,d[0],d[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new so:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=null==e?e=new so:void 0,r=this._clip(t);if(null===r||!r.length)return;e.moveTo(r[0],r[1]);let o=r.length;for(;r[0]===r[o-2]&&r[1]===r[o-1]&&o>1;)o-=2;for(let t=2;t<o;t+=2)r[t]===r[t-2]&&r[t+1]===r[t-1]||e.lineTo(r[t],r[t+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const t=this.cellPolygon(e);t&&(t.index=e,yield t)}}cellPolygon(t){const e=new ao;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,r,o){let i;const s=this._regioncode(t,e),a=this._regioncode(n,r);0===s&&0===a?(o.moveTo(t,e),o.lineTo(n,r)):(i=this._clipSegment(t,e,n,r,s,a))&&(o.moveTo(i[0],i[1]),o.lineTo(i[2],i[3]))}contains(t,e,n){return(e=+e)==e&&(n=+n)==n&&this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const t=this._clip(n);if(t)t:for(let r=0,o=e.length;r<o;r+=2)for(let i=0,s=t.length;i<s;i+=2)if(e[r]==t[i]&&e[r+1]==t[i+1]&&e[(r+2)%o]==t[(i+s-2)%s]&&e[(r+3)%o]==t[(i+s-1)%s]){yield n;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:r,triangles:o}}=this,i=n[t];if(-1===i)return null;const s=[];let a=i;do{const n=Math.floor(a/3);if(s.push(e[2*n],e[2*n+1]),a=a%3==2?a-2:a+1,o[a]!==t)break;a=r[a]}while(a!==i&&-1!==a);return s}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:n}=this,r=4*t;return n[r]||n[r+1]?this._clipInfinite(t,e,n[r],n[r+1],n[r+2],n[r+3]):this._clipFinite(t,e)}_clipFinite(t,e){const n=e.length;let r,o,i,s,a=null,l=e[n-2],c=e[n-1],u=this._regioncode(l,c),f=0;for(let d=0;d<n;d+=2)if(r=l,o=c,l=e[d],c=e[d+1],i=u,u=this._regioncode(l,c),0===i&&0===u)s=f,f=0,a?a.push(l,c):a=[l,c];else{let e,n,d,h,p;if(0===i){if(null===(e=this._clipSegment(r,o,l,c,i,u)))continue;[n,d,h,p]=e}else{if(null===(e=this._clipSegment(l,c,r,o,u,i)))continue;[h,p,n,d]=e,s=f,f=this._edgecode(n,d),s&&f&&this._edge(t,s,f,a,a.length),a?a.push(n,d):a=[n,d]}s=f,f=this._edgecode(h,p),s&&f&&this._edge(t,s,f,a,a.length),a?a.push(h,p):a=[h,p]}if(a)s=f,f=this._edgecode(a[0],a[1]),s&&f&&this._edge(t,s,f,a,a.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return a}_clipSegment(t,e,n,r,o,i){for(;;){if(0===o&&0===i)return[t,e,n,r];if(o&i)return null;let s,a,l=o||i;8&l?(s=t+(n-t)*(this.ymax-e)/(r-e),a=this.ymax):4&l?(s=t+(n-t)*(this.ymin-e)/(r-e),a=this.ymin):2&l?(a=e+(r-e)*(this.xmax-t)/(n-t),s=this.xmax):(a=e+(r-e)*(this.xmin-t)/(n-t),s=this.xmin),o?(t=s,e=a,o=this._regioncode(t,e)):(n=s,r=a,i=this._regioncode(n,r))}}_clipInfinite(t,e,n,r,o,i){let s,a=Array.from(e);if((s=this._project(a[0],a[1],n,r))&&a.unshift(s[0],s[1]),(s=this._project(a[a.length-2],a[a.length-1],o,i))&&a.push(s[0],s[1]),a=this._clipFinite(t,a))for(let e,n=0,r=a.length,o=this._edgecode(a[r-2],a[r-1]);n<r;n+=2)e=o,o=this._edgecode(a[n],a[n+1]),e&&o&&(n=this._edge(t,e,o,a,n),r=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,n,r,o){for(;e!==n;){let n,i;switch(e){case 5:e=4;continue;case 4:e=6,n=this.xmax,i=this.ymin;break;case 6:e=2;continue;case 2:e=10,n=this.xmax,i=this.ymax;break;case 10:e=8;continue;case 8:e=9,n=this.xmin,i=this.ymax;break;case 9:e=1;continue;case 1:e=5,n=this.xmin,i=this.ymin}r[o]===n&&r[o+1]===i||!this.contains(t,n,i)||(r.splice(o,0,n,i),o+=2)}if(r.length>4)for(let t=0;t<r.length;t+=2){const e=(t+2)%r.length,n=(t+4)%r.length;(r[t]===r[e]&&r[e]===r[n]||r[t+1]===r[e+1]&&r[e+1]===r[n+1])&&(r.splice(e,2),t-=2)}return o}_project(t,e,n,r){let o,i,s,a=1/0;if(r<0){if(e<=this.ymin)return null;(o=(this.ymin-e)/r)<a&&(s=this.ymin,i=t+(a=o)*n)}else if(r>0){if(e>=this.ymax)return null;(o=(this.ymax-e)/r)<a&&(s=this.ymax,i=t+(a=o)*n)}if(n>0){if(t>=this.xmax)return null;(o=(this.xmax-t)/n)<a&&(i=this.xmax,s=e+(a=o)*r)}else if(n<0){if(t<=this.xmin)return null;(o=(this.xmin-t)/n)<a&&(i=this.xmin,s=e+(a=o)*r)}return[i,s]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const co=2*Math.PI,uo=Math.pow;function fo(t){return t[0]}function ho(t){return t[1]}function po(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class mo{static from(t,e=fo,n=ho,r){return new mo("length"in t?function(t,e,n,r){const o=t.length,i=new Float64Array(2*o);for(let s=0;s<o;++s){const o=t[s];i[2*s]=e.call(r,o,s,t),i[2*s+1]=n.call(r,o,s,t)}return i}(t,e,n,r):Float64Array.from(function*(t,e,n,r){let o=0;for(const i of t)yield e.call(r,i,o,t),yield n.call(r,i,o,t),++o}(t,e,n,r)))}constructor(t){this._delaunator=new Qr(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:n}=t;for(let t=0;t<e.length;t+=3){const r=2*e[t],o=2*e[t+1],i=2*e[t+2];if((n[i]-n[r])*(n[o+1]-n[r+1])-(n[o]-n[r])*(n[i+1]-n[r+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},((t,e)=>e)).sort(((t,n)=>e[2*t]-e[2*n]||e[2*t+1]-e[2*n+1]));const t=this.collinear[0],n=this.collinear[this.collinear.length-1],r=[e[2*t],e[2*t+1],e[2*n],e[2*n+1]],o=1e-8*Math.hypot(r[3]-r[1],r[2]-r[0]);for(let t=0,n=e.length/2;t<n;++t){const n=po(e[2*t],e[2*t+1],o);e[2*t]=n[0],e[2*t+1]=n[1]}this._delaunator=new Qr(e)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,o=this.triangles=this._delaunator.triangles,i=this.inedges.fill(-1),s=this._hullIndex.fill(-1);for(let t=0,e=n.length;t<e;++t){const e=o[t%3==2?t-2:t+1];-1!==n[t]&&-1!==i[e]||(i[e]=t)}for(let t=0,e=r.length;t<e;++t)s[r[t]]=t;r.length<=2&&r.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=r[0],i[r[0]]=1,2===r.length&&(i[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(t){return new lo(this,t)}*neighbors(t){const{inedges:e,hull:n,_hullIndex:r,halfedges:o,triangles:i,collinear:s}=this;if(s){const e=s.indexOf(t);return e>0&&(yield s[e-1]),void(e<s.length-1&&(yield s[e+1]))}const a=e[t];if(-1===a)return;let l=a,c=-1;do{if(yield c=i[l],l=l%3==2?l-2:l+1,i[l]!==t)return;if(l=o[l],-1===l){const e=n[(r[t]+1)%n.length];return void(e!==c&&(yield e))}}while(l!==a)}find(t,e,n=0){if((t=+t)!=t||(e=+e)!=e)return-1;const r=n;let o;for(;(o=this._step(n,t,e))>=0&&o!==n&&o!==r;)n=o;return o}_step(t,e,n){const{inedges:r,hull:o,_hullIndex:i,halfedges:s,triangles:a,points:l}=this;if(-1===r[t]||!l.length)return(t+1)%(l.length>>1);let c=t,u=uo(e-l[2*t],2)+uo(n-l[2*t+1],2);const f=r[t];let d=f;do{let r=a[d];const f=uo(e-l[2*r],2)+uo(n-l[2*r+1],2);if(f<u&&(u=f,c=r),d=d%3==2?d-2:d+1,a[d]!==t)break;if(d=s[d],-1===d){if(d=o[(i[t]+1)%o.length],d!==r&&uo(e-l[2*d],2)+uo(n-l[2*d+1],2)<u)return d;break}}while(d!==f);return c}render(t){const e=null==t?t=new so:void 0,{points:n,halfedges:r,triangles:o}=this;for(let e=0,i=r.length;e<i;++e){const i=r[e];if(i<e)continue;const s=2*o[e],a=2*o[i];t.moveTo(n[s],n[s+1]),t.lineTo(n[a],n[a+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){void 0!==e||t&&"function"==typeof t.moveTo||(e=t,t=null),e=null==e?2:+e;const n=null==t?t=new so:void 0,{points:r}=this;for(let n=0,o=r.length;n<o;n+=2){const o=r[n],i=r[n+1];t.moveTo(o+e,i),t.arc(o,i,e,0,co)}return n&&n.value()}renderHull(t){const e=null==t?t=new so:void 0,{hull:n,points:r}=this,o=2*n[0],i=n.length;t.moveTo(r[o],r[o+1]);for(let e=1;e<i;++e){const o=2*n[e];t.lineTo(r[o],r[o+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new ao;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new so:void 0,{points:r,triangles:o}=this,i=2*o[t*=3],s=2*o[t+1],a=2*o[t+2];return e.moveTo(r[i],r[i+1]),e.lineTo(r[s],r[s+1]),e.lineTo(r[a],r[a+1]),e.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,n=t.length/3;e<n;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new ao;return this.renderTriangle(t,e),e.value()}}const go=t=>()=>t;function yo(t,{sourceEvent:e,subject:n,target:r,identifier:o,active:i,x:s,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}function vo(t){return!t.ctrlKey&&!t.button}function bo(){return this.parentNode}function _o(t,e){return null==e?{x:t.x,y:t.y}:e}function wo(){return navigator.maxTouchPoints||"ontouchstart"in this}function xo(){var t,e,n,r,o=vo,i=bo,s=_o,a=wo,l={},c=x("start","drag","end"),u=0,f=0;function d(t){t.on("mousedown.drag",h).filter(a).on("touchstart.drag",g).on("touchmove.drag",y,Dt).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(s,a){if(!r&&o.call(this,s,a)){var l=b(this,i.call(this,s,a),s,a,"mouse");l&&(Lt(s.view).on("mousemove.drag",p,Bt).on("mouseup.drag",m,Bt),$t(s.view),zt(s),n=!1,t=s.clientX,e=s.clientY,l("start",s))}}function p(r){if(Zt(r),!n){var o=r.clientX-t,i=r.clientY-e;n=o*o+i*i>f}l.mouse("drag",r)}function m(t){Lt(t.view).on("mousemove.drag mouseup.drag",null),Gt(t.view,n),Zt(t),l.mouse("end",t)}function g(t,e){if(o.call(this,t,e)){var n,r,s=t.changedTouches,a=i.call(this,t,e),l=s.length;for(n=0;n<l;++n)(r=b(this,a,t,e,s[n].identifier,s[n]))&&(zt(t),r("start",t,s[n]))}}function y(t){var e,n,r=t.changedTouches,o=r.length;for(e=0;e<o;++e)(n=l[r[e].identifier])&&(Zt(t),n("drag",t,r[e]))}function v(t){var e,n,o=t.changedTouches,i=o.length;for(r&&clearTimeout(r),r=setTimeout((function(){r=null}),500),e=0;e<i;++e)(n=l[o[e].identifier])&&(zt(t),n("end",t,o[e]))}function b(t,e,n,r,o,i){var a,f,h,p=c.copy(),m=Wt(i||n,e);if(null!=(h=s.call(t,new yo("beforestart",{sourceEvent:n,target:d,identifier:o,active:u,x:m[0],y:m[1],dx:0,dy:0,dispatch:p}),r)))return a=h.x-m[0]||0,f=h.y-m[1]||0,function n(i,s,c){var g,y=m;switch(i){case"start":l[o]=n,g=u++;break;case"end":delete l[o],--u;case"drag":m=Wt(c||s,e),g=u}p.call(i,t,new yo(i,{sourceEvent:s,subject:h,target:d,identifier:o,active:g,x:m[0]+a,y:m[1]+f,dx:m[0]-y[0],dy:m[1]-y[1],dispatch:p}),r)}}return d.filter=function(t){return arguments.length?(o="function"==typeof t?t:go(!!t),d):o},d.container=function(t){return arguments.length?(i="function"==typeof t?t:go(t),d):i},d.subject=function(t){return arguments.length?(s="function"==typeof t?t:go(t),d):s},d.touchable=function(t){return arguments.length?(a="function"==typeof t?t:go(!!t),d):a},d.on=function(){var t=c.on.apply(c,arguments);return t===c?d:t},d.clickDistance=function(t){return arguments.length?(f=(t=+t)*t,d):Math.sqrt(f)},d}yo.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};var ko=n(2884);const qo=t=>+t;function No(t){return t*t}function So(t){return t*(2-t)}function Ao(t){return((t*=2)<=1?t*t:--t*(2-t)+1)/2}var Mo=function t(e){function n(t){return Math.pow(t,e)}return e=+e,n.exponent=t,n}(3),To=function t(e){function n(t){return 1-Math.pow(1-t,e)}return e=+e,n.exponent=t,n}(3),Co=function t(e){function n(t){return((t*=2)<=1?Math.pow(t,e):2-Math.pow(2-t,e))/2}return e=+e,n.exponent=t,n}(3),jo=Math.PI,Oo=jo/2;function Eo(t){return 1==+t?1:1-Math.cos(t*Oo)}function Ro(t){return Math.sin(t*Oo)}function Io(t){return(1-Math.cos(jo*t))/2}function Po(t){return 1.0009775171065494*(Math.pow(2,-10*t)-.0009765625)}function Fo(t){return Po(1-+t)}function Lo(t){return 1-Po(t)}function Do(t){return((t*=2)<=1?Po(1-t):2-Po(t-1))/2}function Bo(t){return 1-Math.sqrt(1-t*t)}function zo(t){return Math.sqrt(1- --t*t)}function Zo(t){return((t*=2)<=1?1-Math.sqrt(1-t*t):Math.sqrt(1-(t-=2)*t)+1)/2}var $o=4/11,Go=7.5625;function Uo(t){return 1-Ho(1-t)}function Ho(t){return(t=+t)<$o?Go*t*t:t<.7272727272727273?Go*(t-=.5454545454545454)*t+.75:t<.9090909090909091?Go*(t-=.8181818181818182)*t+.9375:Go*(t-=.9545454545454546)*t+.984375}function Wo(t){return((t*=2)<=1?1-Ho(1-t):Ho(t-1)+1)/2}var Jo=1.70158,Vo=function t(e){function n(t){return(t=+t)*t*(e*(t-1)+t)}return e=+e,n.overshoot=t,n}(Jo),Yo=function t(e){function n(t){return--t*t*((t+1)*e+t)+1}return e=+e,n.overshoot=t,n}(Jo),Qo=function t(e){function n(t){return((t*=2)<1?t*t*((e+1)*t-e):(t-=2)*t*((e+1)*t+e)+2)/2}return e=+e,n.overshoot=t,n}(Jo),Ko=2*Math.PI,Xo=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=Ko);function o(t){return e*Po(- --t)*Math.sin((r-t)/n)}return o.amplitude=function(e){return t(e,n*Ko)},o.period=function(n){return t(e,n)},o}(1,.3),ti=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=Ko);function o(t){return 1-e*Po(t=+t)*Math.sin((t+r)/n)}return o.amplitude=function(e){return t(e,n*Ko)},o.period=function(n){return t(e,n)},o}(1,.3),ei=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=Ko);function o(t){return((t=2*t-1)<0?e*Po(-t)*Math.sin((r-t)/n):2-e*Po(t)*Math.sin((r+t)/n))/2}return o.amplitude=function(e){return t(e,n*Ko)},o.period=function(n){return t(e,n)},o}(1,.3);function ni(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.blob()}function ri(t,e){return fetch(t,e).then(ni)}function oi(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.arrayBuffer()}function ii(t,e){return fetch(t,e).then(oi)}var si=n(4476),ai=n(9106),li=n(5026);function ci(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function ui(t,e){return fetch(t,e).then(ci)}function fi(t){return function(e,n,r){return 2===arguments.length&&"function"==typeof n&&(r=n,n=void 0),ui(e,n).then((function(e){return t(e,r)}))}}function di(t,e,n,r){3===arguments.length&&"function"==typeof n&&(r=n,n=void 0);var o=(0,si.Z)(t);return ui(e,n).then((function(t){return o.parse(t,r)}))}var hi=fi(ai.ue),pi=fi(li.tJ);function mi(t,e){return new Promise((function(n,r){var o=new Image;for(var i in e)o[i]=e[i];o.onerror=r,o.onload=function(){n(o)},o.src=t}))}function gi(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);if(204!==t.status&&205!==t.status)return t.json()}function yi(t,e){return fetch(t,e).then(gi)}function vi(t){return(e,n)=>ui(e,n).then((e=>(new DOMParser).parseFromString(e,t)))}const bi=vi("application/xml");var _i=vi("text/html"),wi=vi("image/svg+xml");function xi(t,e){var n,r=1;function o(){var o,i,s=n.length,a=0,l=0;for(o=0;o<s;++o)a+=(i=n[o]).x,l+=i.y;for(a=(a/s-t)*r,l=(l/s-e)*r,o=0;o<s;++o)(i=n[o]).x-=a,i.y-=l}return null==t&&(t=0),null==e&&(e=0),o.initialize=function(t){n=t},o.x=function(e){return arguments.length?(t=+e,o):t},o.y=function(t){return arguments.length?(e=+t,o):e},o.strength=function(t){return arguments.length?(r=+t,o):r},o}function ki(t,e,n,r){if(isNaN(e)||isNaN(n))return t;var o,i,s,a,l,c,u,f,d,h=t._root,p={data:r},m=t._x0,g=t._y0,y=t._x1,v=t._y1;if(!h)return t._root=p,t;for(;h.length;)if((c=e>=(i=(m+y)/2))?m=i:y=i,(u=n>=(s=(g+v)/2))?g=s:v=s,o=h,!(h=h[f=u<<1|c]))return o[f]=p,t;if(a=+t._x.call(null,h.data),l=+t._y.call(null,h.data),e===a&&n===l)return p.next=h,o?o[f]=p:t._root=p,t;do{o=o?o[f]=new Array(4):t._root=new Array(4),(c=e>=(i=(m+y)/2))?m=i:y=i,(u=n>=(s=(g+v)/2))?g=s:v=s}while((f=u<<1|c)==(d=(l>=s)<<1|a>=i));return o[d]=h,o[f]=p,t}function qi(t,e,n,r,o){this.node=t,this.x0=e,this.y0=n,this.x1=r,this.y1=o}function Ni(t){return t[0]}function Si(t){return t[1]}function Ai(t,e,n){var r=new Mi(null==e?Ni:e,null==n?Si:n,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Mi(t,e,n,r,o,i){this._x=t,this._y=e,this._x0=n,this._y0=r,this._x1=o,this._y1=i,this._root=void 0}function Ti(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var Ci=Ai.prototype=Mi.prototype;function ji(t){return function(){return t}}function Oi(t){return 1e-6*(t()-.5)}function Ei(t){return t.x+t.vx}function Ri(t){return t.y+t.vy}function Ii(t){var e,n,r,o=1,i=1;function s(){for(var t,s,l,c,u,f,d,h=e.length,p=0;p<i;++p)for(s=Ai(e,Ei,Ri).visitAfter(a),t=0;t<h;++t)l=e[t],f=n[l.index],d=f*f,c=l.x+l.vx,u=l.y+l.vy,s.visit(m);function m(t,e,n,i,s){var a=t.data,h=t.r,p=f+h;if(!a)return e>c+p||i<c-p||n>u+p||s<u-p;if(a.index>l.index){var m=c-a.x-a.vx,g=u-a.y-a.vy,y=m*m+g*g;y<p*p&&(0===m&&(y+=(m=Oi(r))*m),0===g&&(y+=(g=Oi(r))*g),y=(p-(y=Math.sqrt(y)))/y*o,l.vx+=(m*=y)*(p=(h*=h)/(d+h)),l.vy+=(g*=y)*p,a.vx-=m*(p=1-p),a.vy-=g*p)}}}function a(t){if(t.data)return t.r=n[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function l(){if(e){var r,o,i=e.length;for(n=new Array(i),r=0;r<i;++r)o=e[r],n[o.index]=+t(o,r,e)}}return"function"!=typeof t&&(t=ji(null==t?1:+t)),s.initialize=function(t,n){e=t,r=n,l()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:ji(+e),l(),s):t},s}function Pi(t){return t.index}function Fi(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function Li(t){var e,n,r,o,i,s,a=Pi,l=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},c=ji(30),u=1;function f(r){for(var o=0,a=t.length;o<u;++o)for(var l,c,f,d,h,p,m,g=0;g<a;++g)c=(l=t[g]).source,d=(f=l.target).x+f.vx-c.x-c.vx||Oi(s),h=f.y+f.vy-c.y-c.vy||Oi(s),d*=p=((p=Math.sqrt(d*d+h*h))-n[g])/p*r*e[g],h*=p,f.vx-=d*(m=i[g]),f.vy-=h*m,c.vx+=d*(m=1-m),c.vy+=h*m}function d(){if(r){var s,l,c=r.length,u=t.length,f=new Map(r.map(((t,e)=>[a(t,e,r),t])));for(s=0,o=new Array(c);s<u;++s)(l=t[s]).index=s,"object"!=typeof l.source&&(l.source=Fi(f,l.source)),"object"!=typeof l.target&&(l.target=Fi(f,l.target)),o[l.source.index]=(o[l.source.index]||0)+1,o[l.target.index]=(o[l.target.index]||0)+1;for(s=0,i=new Array(u);s<u;++s)l=t[s],i[s]=o[l.source.index]/(o[l.source.index]+o[l.target.index]);e=new Array(u),h(),n=new Array(u),p()}}function h(){if(r)for(var n=0,o=t.length;n<o;++n)e[n]=+l(t[n],n,t)}function p(){if(r)for(var e=0,o=t.length;e<o;++e)n[e]=+c(t[e],e,t)}return null==t&&(t=[]),f.initialize=function(t,e){r=t,s=e,d()},f.links=function(e){return arguments.length?(t=e,d(),f):t},f.id=function(t){return arguments.length?(a=t,f):a},f.iterations=function(t){return arguments.length?(u=+t,f):u},f.strength=function(t){return arguments.length?(l="function"==typeof t?t:ji(+t),h(),f):l},f.distance=function(t){return arguments.length?(c="function"==typeof t?t:ji(+t),p(),f):c},f}Ci.copy=function(){var t,e,n=new Mi(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return n;if(!r.length)return n._root=Ti(r),n;for(t=[{source:r,target:n._root=new Array(4)}];r=t.pop();)for(var o=0;o<4;++o)(e=r.source[o])&&(e.length?t.push({source:e,target:r.target[o]=new Array(4)}):r.target[o]=Ti(e));return n},Ci.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return ki(this.cover(e,n),e,n,t)},Ci.addAll=function(t){var e,n,r,o,i=t.length,s=new Array(i),a=new Array(i),l=1/0,c=1/0,u=-1/0,f=-1/0;for(n=0;n<i;++n)isNaN(r=+this._x.call(null,e=t[n]))||isNaN(o=+this._y.call(null,e))||(s[n]=r,a[n]=o,r<l&&(l=r),r>u&&(u=r),o<c&&(c=o),o>f&&(f=o));if(l>u||c>f)return this;for(this.cover(l,c).cover(u,f),n=0;n<i;++n)ki(this,s[n],a[n],t[n]);return this},Ci.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,r=this._y0,o=this._x1,i=this._y1;if(isNaN(n))o=(n=Math.floor(t))+1,i=(r=Math.floor(e))+1;else{for(var s,a,l=o-n||1,c=this._root;n>t||t>=o||r>e||e>=i;)switch(a=(e<r)<<1|t<n,(s=new Array(4))[a]=c,c=s,l*=2,a){case 0:o=n+l,i=r+l;break;case 1:n=o-l,i=r+l;break;case 2:o=n+l,r=i-l;break;case 3:n=o-l,r=i-l}this._root&&this._root.length&&(this._root=c)}return this._x0=n,this._y0=r,this._x1=o,this._y1=i,this},Ci.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},Ci.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},Ci.find=function(t,e,n){var r,o,i,s,a,l,c,u=this._x0,f=this._y0,d=this._x1,h=this._y1,p=[],m=this._root;for(m&&p.push(new qi(m,u,f,d,h)),null==n?n=1/0:(u=t-n,f=e-n,d=t+n,h=e+n,n*=n);l=p.pop();)if(!(!(m=l.node)||(o=l.x0)>d||(i=l.y0)>h||(s=l.x1)<u||(a=l.y1)<f))if(m.length){var g=(o+s)/2,y=(i+a)/2;p.push(new qi(m[3],g,y,s,a),new qi(m[2],o,y,g,a),new qi(m[1],g,i,s,y),new qi(m[0],o,i,g,y)),(c=(e>=y)<<1|t>=g)&&(l=p[p.length-1],p[p.length-1]=p[p.length-1-c],p[p.length-1-c]=l)}else{var v=t-+this._x.call(null,m.data),b=e-+this._y.call(null,m.data),_=v*v+b*b;if(_<n){var w=Math.sqrt(n=_);u=t-w,f=e-w,d=t+w,h=e+w,r=m.data}}return r},Ci.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,n,r,o,i,s,a,l,c,u,f,d,h=this._root,p=this._x0,m=this._y0,g=this._x1,y=this._y1;if(!h)return this;if(h.length)for(;;){if((c=i>=(a=(p+g)/2))?p=a:g=a,(u=s>=(l=(m+y)/2))?m=l:y=l,e=h,!(h=h[f=u<<1|c]))return this;if(!h.length)break;(e[f+1&3]||e[f+2&3]||e[f+3&3])&&(n=e,d=f)}for(;h.data!==t;)if(r=h,!(h=h.next))return this;return(o=h.next)&&delete h.next,r?(o?r.next=o:delete r.next,this):e?(o?e[f]=o:delete e[f],(h=e[0]||e[1]||e[2]||e[3])&&h===(e[3]||e[2]||e[1]||e[0])&&!h.length&&(n?n[d]=h:this._root=h),this):(this._root=o,this)},Ci.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},Ci.root=function(){return this._root},Ci.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},Ci.visit=function(t){var e,n,r,o,i,s,a=[],l=this._root;for(l&&a.push(new qi(l,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(l=e.node,r=e.x0,o=e.y0,i=e.x1,s=e.y1)&&l.length){var c=(r+i)/2,u=(o+s)/2;(n=l[3])&&a.push(new qi(n,c,u,i,s)),(n=l[2])&&a.push(new qi(n,r,u,c,s)),(n=l[1])&&a.push(new qi(n,c,o,i,u)),(n=l[0])&&a.push(new qi(n,r,o,c,u))}return this},Ci.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new qi(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,l=e.x1,c=e.y1,u=(s+l)/2,f=(a+c)/2;(i=o[0])&&n.push(new qi(i,s,a,u,f)),(i=o[1])&&n.push(new qi(i,u,a,l,f)),(i=o[2])&&n.push(new qi(i,s,f,u,c)),(i=o[3])&&n.push(new qi(i,u,f,l,c))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},Ci.x=function(t){return arguments.length?(this._x=t,this):this._x},Ci.y=function(t){return arguments.length?(this._y=t,this):this._y};const Di=4294967296;function Bi(t){return t.x}function zi(t){return t.y}var Zi=Math.PI*(3-Math.sqrt(5));function $i(t){var e,n=1,r=.001,o=1-Math.pow(r,1/300),i=0,s=.6,a=new Map,l=ae(f),c=x("tick","end"),u=function(){let t=1;return()=>(t=(1664525*t+1013904223)%Di)/Di}();function f(){d(),c.call("tick",e),n<r&&(l.stop(),c.call("end",e))}function d(r){var l,c,u=t.length;void 0===r&&(r=1);for(var f=0;f<r;++f)for(n+=(i-n)*o,a.forEach((function(t){t(n)})),l=0;l<u;++l)null==(c=t[l]).fx?c.x+=c.vx*=s:(c.x=c.fx,c.vx=0),null==c.fy?c.y+=c.vy*=s:(c.y=c.fy,c.vy=0);return e}function h(){for(var e,n=0,r=t.length;n<r;++n){if((e=t[n]).index=n,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+n),i=n*Zi;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function p(e){return e.initialize&&e.initialize(t,u),e}return null==t&&(t=[]),h(),e={tick:d,restart:function(){return l.restart(f),e},stop:function(){return l.stop(),e},nodes:function(n){return arguments.length?(t=n,h(),a.forEach(p),e):t},alpha:function(t){return arguments.length?(n=+t,e):n},alphaMin:function(t){return arguments.length?(r=+t,e):r},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(u=t,a.forEach(p),e):u},force:function(t,n){return arguments.length>1?(null==n?a.delete(t):a.set(t,p(n)),e):a.get(t)},find:function(e,n,r){var o,i,s,a,l,c=0,u=t.length;for(null==r?r=1/0:r*=r,c=0;c<u;++c)(s=(o=e-(a=t[c]).x)*o+(i=n-a.y)*i)<r&&(l=a,r=s);return l},on:function(t,n){return arguments.length>1?(c.on(t,n),e):c.on(t)}}}function Gi(){var t,e,n,r,o,i=ji(-30),s=1,a=1/0,l=.81;function c(n){var o,i=t.length,s=Ai(t,Bi,zi).visitAfter(f);for(r=n,o=0;o<i;++o)e=t[o],s.visit(d)}function u(){if(t){var e,n,r=t.length;for(o=new Array(r),e=0;e<r;++e)n=t[e],o[n.index]=+i(n,e,t)}}function f(t){var e,n,r,i,s,a=0,l=0;if(t.length){for(r=i=s=0;s<4;++s)(e=t[s])&&(n=Math.abs(e.value))&&(a+=e.value,l+=n,r+=n*e.x,i+=n*e.y);t.x=r/l,t.y=i/l}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function d(t,i,c,u){if(!t.value)return!0;var f=t.x-e.x,d=t.y-e.y,h=u-i,p=f*f+d*d;if(h*h/l<p)return p<a&&(0===f&&(p+=(f=Oi(n))*f),0===d&&(p+=(d=Oi(n))*d),p<s&&(p=Math.sqrt(s*p)),e.vx+=f*t.value*r/p,e.vy+=d*t.value*r/p),!0;if(!(t.length||p>=a)){(t.data!==e||t.next)&&(0===f&&(p+=(f=Oi(n))*f),0===d&&(p+=(d=Oi(n))*d),p<s&&(p=Math.sqrt(s*p)));do{t.data!==e&&(h=o[t.data.index]*r/p,e.vx+=f*h,e.vy+=d*h)}while(t=t.next)}}return c.initialize=function(e,r){t=e,n=r,u()},c.strength=function(t){return arguments.length?(i="function"==typeof t?t:ji(+t),u(),c):i},c.distanceMin=function(t){return arguments.length?(s=t*t,c):Math.sqrt(s)},c.distanceMax=function(t){return arguments.length?(a=t*t,c):Math.sqrt(a)},c.theta=function(t){return arguments.length?(l=t*t,c):Math.sqrt(l)},c}function Ui(t,e,n){var r,o,i,s=ji(.1);function a(t){for(var s=0,a=r.length;s<a;++s){var l=r[s],c=l.x-e||1e-6,u=l.y-n||1e-6,f=Math.sqrt(c*c+u*u),d=(i[s]-f)*o[s]*t/f;l.vx+=c*d,l.vy+=u*d}}function l(){if(r){var e,n=r.length;for(o=new Array(n),i=new Array(n),e=0;e<n;++e)i[e]=+t(r[e],e,r),o[e]=isNaN(i[e])?0:+s(r[e],e,r)}}return"function"!=typeof t&&(t=ji(+t)),null==e&&(e=0),null==n&&(n=0),a.initialize=function(t){r=t,l()},a.strength=function(t){return arguments.length?(s="function"==typeof t?t:ji(+t),l(),a):s},a.radius=function(e){return arguments.length?(t="function"==typeof e?e:ji(+e),l(),a):t},a.x=function(t){return arguments.length?(e=+t,a):e},a.y=function(t){return arguments.length?(n=+t,a):n},a}function Hi(t){var e,n,r,o=ji(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(r[i]-o.x)*n[i]*t}function s(){if(e){var i,s=e.length;for(n=new Array(s),r=new Array(s),i=0;i<s;++i)n[i]=isNaN(r[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=ji(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:ji(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:ji(+e),s(),i):t},i}function Wi(t){var e,n,r,o=ji(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(r[i]-o.y)*n[i]*t}function s(){if(e){var i,s=e.length;for(n=new Array(s),r=new Array(s),i=0;i<s;++i)n[i]=isNaN(r[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=ji(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:ji(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:ji(+e),s(),i):t},i}var Ji=n(8288),Vi=n(9343),Yi=1e-6,Qi=1e-12,Ki=Math.PI,Xi=Ki/2,ts=Ki/4,es=2*Ki,ns=180/Ki,rs=Ki/180,os=Math.abs,is=Math.atan,ss=Math.atan2,as=Math.cos,ls=Math.ceil,cs=Math.exp,us=(Math.floor,Math.hypot),fs=Math.log,ds=Math.pow,hs=Math.sin,ps=Math.sign||function(t){return t>0?1:t<0?-1:0},ms=Math.sqrt,gs=Math.tan;function ys(t){return t>1?0:t<-1?Ki:Math.acos(t)}function vs(t){return t>1?Xi:t<-1?-Xi:Math.asin(t)}function bs(t){return(t=hs(t/2))*t}function _s(){}function ws(t,e){t&&ks.hasOwnProperty(t.type)&&ks[t.type](t,e)}var xs={Feature:function(t,e){ws(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,o=n.length;++r<o;)ws(n[r].geometry,e)}},ks={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)t=n[r],e.point(t[0],t[1],t[2])},LineString:function(t,e){qs(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)qs(n[r],e,0)},Polygon:function(t,e){Ns(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)Ns(n[r],e)},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,o=n.length;++r<o;)ws(n[r],e)}};function qs(t,e,n){var r,o=-1,i=t.length-n;for(e.lineStart();++o<i;)r=t[o],e.point(r[0],r[1],r[2]);e.lineEnd()}function Ns(t,e){var n=-1,r=t.length;for(e.polygonStart();++n<r;)qs(t[n],e,1);e.polygonEnd()}function Ss(t,e){t&&xs.hasOwnProperty(t.type)?xs[t.type](t,e):ws(t,e)}var As,Ms,Ts,Cs,js,Os,Es,Rs,Is,Ps,Fs,Ls,Ds,Bs,zs,Zs,$s=new Vi.dU,Gs=new Vi.dU,Us={point:_s,lineStart:_s,lineEnd:_s,polygonStart:function(){$s=new Vi.dU,Us.lineStart=Hs,Us.lineEnd=Ws},polygonEnd:function(){var t=+$s;Gs.add(t<0?es+t:t),this.lineStart=this.lineEnd=this.point=_s},sphere:function(){Gs.add(es)}};function Hs(){Us.point=Js}function Ws(){Vs(As,Ms)}function Js(t,e){Us.point=Vs,As=t,Ms=e,Ts=t*=rs,Cs=as(e=(e*=rs)/2+ts),js=hs(e)}function Vs(t,e){var n=(t*=rs)-Ts,r=n>=0?1:-1,o=r*n,i=as(e=(e*=rs)/2+ts),s=hs(e),a=js*s,l=Cs*i+a*as(o),c=a*r*hs(o);$s.add(ss(c,l)),Ts=t,Cs=i,js=s}function Ys(t){return Gs=new Vi.dU,Ss(t,Us),2*Gs}function Qs(t){return[ss(t[1],t[0]),vs(t[2])]}function Ks(t){var e=t[0],n=t[1],r=as(n);return[r*as(e),r*hs(e),hs(n)]}function Xs(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function ta(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function ea(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function na(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function ra(t){var e=ms(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var oa,ia,sa,aa,la,ca,ua,fa,da,ha,pa,ma,ga,ya,va,ba,_a={point:wa,lineStart:ka,lineEnd:qa,polygonStart:function(){_a.point=Na,_a.lineStart=Sa,_a.lineEnd=Aa,Bs=new Vi.dU,Us.polygonStart()},polygonEnd:function(){Us.polygonEnd(),_a.point=wa,_a.lineStart=ka,_a.lineEnd=qa,$s<0?(Os=-(Rs=180),Es=-(Is=90)):Bs>Yi?Is=90:Bs<-1e-6&&(Es=-90),Zs[0]=Os,Zs[1]=Rs},sphere:function(){Os=-(Rs=180),Es=-(Is=90)}};function wa(t,e){zs.push(Zs=[Os=t,Rs=t]),e<Es&&(Es=e),e>Is&&(Is=e)}function xa(t,e){var n=Ks([t*rs,e*rs]);if(Ds){var r=ta(Ds,n),o=ta([r[1],-r[0],0],r);ra(o),o=Qs(o);var i,s=t-Ps,a=s>0?1:-1,l=o[0]*ns*a,c=os(s)>180;c^(a*Ps<l&&l<a*t)?(i=o[1]*ns)>Is&&(Is=i):c^(a*Ps<(l=(l+360)%360-180)&&l<a*t)?(i=-o[1]*ns)<Es&&(Es=i):(e<Es&&(Es=e),e>Is&&(Is=e)),c?t<Ps?Ma(Os,t)>Ma(Os,Rs)&&(Rs=t):Ma(t,Rs)>Ma(Os,Rs)&&(Os=t):Rs>=Os?(t<Os&&(Os=t),t>Rs&&(Rs=t)):t>Ps?Ma(Os,t)>Ma(Os,Rs)&&(Rs=t):Ma(t,Rs)>Ma(Os,Rs)&&(Os=t)}else zs.push(Zs=[Os=t,Rs=t]);e<Es&&(Es=e),e>Is&&(Is=e),Ds=n,Ps=t}function ka(){_a.point=xa}function qa(){Zs[0]=Os,Zs[1]=Rs,_a.point=wa,Ds=null}function Na(t,e){if(Ds){var n=t-Ps;Bs.add(os(n)>180?n+(n>0?360:-360):n)}else Fs=t,Ls=e;Us.point(t,e),xa(t,e)}function Sa(){Us.lineStart()}function Aa(){Na(Fs,Ls),Us.lineEnd(),os(Bs)>Yi&&(Os=-(Rs=180)),Zs[0]=Os,Zs[1]=Rs,Ds=null}function Ma(t,e){return(e-=t)<0?e+360:e}function Ta(t,e){return t[0]-e[0]}function Ca(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function ja(t){var e,n,r,o,i,s,a;if(Is=Rs=-(Os=Es=1/0),zs=[],Ss(t,_a),n=zs.length){for(zs.sort(Ta),e=1,i=[r=zs[0]];e<n;++e)Ca(r,(o=zs[e])[0])||Ca(r,o[1])?(Ma(r[0],o[1])>Ma(r[0],r[1])&&(r[1]=o[1]),Ma(o[0],r[1])>Ma(r[0],r[1])&&(r[0]=o[0])):i.push(r=o);for(s=-1/0,e=0,r=i[n=i.length-1];e<=n;r=o,++e)o=i[e],(a=Ma(r[1],o[0]))>s&&(s=a,Os=o[0],Rs=r[1])}return zs=Zs=null,Os===1/0||Es===1/0?[[NaN,NaN],[NaN,NaN]]:[[Os,Es],[Rs,Is]]}var Oa={sphere:_s,point:Ea,lineStart:Ia,lineEnd:La,polygonStart:function(){Oa.lineStart=Da,Oa.lineEnd=Ba},polygonEnd:function(){Oa.lineStart=Ia,Oa.lineEnd=La}};function Ea(t,e){t*=rs;var n=as(e*=rs);Ra(n*as(t),n*hs(t),hs(e))}function Ra(t,e,n){++oa,sa+=(t-sa)/oa,aa+=(e-aa)/oa,la+=(n-la)/oa}function Ia(){Oa.point=Pa}function Pa(t,e){t*=rs;var n=as(e*=rs);ya=n*as(t),va=n*hs(t),ba=hs(e),Oa.point=Fa,Ra(ya,va,ba)}function Fa(t,e){t*=rs;var n=as(e*=rs),r=n*as(t),o=n*hs(t),i=hs(e),s=ss(ms((s=va*i-ba*o)*s+(s=ba*r-ya*i)*s+(s=ya*o-va*r)*s),ya*r+va*o+ba*i);ia+=s,ca+=s*(ya+(ya=r)),ua+=s*(va+(va=o)),fa+=s*(ba+(ba=i)),Ra(ya,va,ba)}function La(){Oa.point=Ea}function Da(){Oa.point=za}function Ba(){Za(ma,ga),Oa.point=Ea}function za(t,e){ma=t,ga=e,t*=rs,e*=rs,Oa.point=Za;var n=as(e);ya=n*as(t),va=n*hs(t),ba=hs(e),Ra(ya,va,ba)}function Za(t,e){t*=rs;var n=as(e*=rs),r=n*as(t),o=n*hs(t),i=hs(e),s=va*i-ba*o,a=ba*r-ya*i,l=ya*o-va*r,c=us(s,a,l),u=vs(c),f=c&&-u/c;da.add(f*s),ha.add(f*a),pa.add(f*l),ia+=u,ca+=u*(ya+(ya=r)),ua+=u*(va+(va=o)),fa+=u*(ba+(ba=i)),Ra(ya,va,ba)}function $a(t){oa=ia=sa=aa=la=ca=ua=fa=0,da=new Vi.dU,ha=new Vi.dU,pa=new Vi.dU,Ss(t,Oa);var e=+da,n=+ha,r=+pa,o=us(e,n,r);return o<Qi&&(e=ca,n=ua,r=fa,ia<Yi&&(e=sa,n=aa,r=la),(o=us(e,n,r))<Qi)?[NaN,NaN]:[ss(n,e)*ns,vs(r/o)*ns]}function Ga(t){return function(){return t}}function Ua(t,e){function n(n,r){return n=t(n,r),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,r){return(n=e.invert(n,r))&&t.invert(n[0],n[1])}),n}function Ha(t,e){return[os(t)>Ki?t+Math.round(-t/es)*es:t,e]}function Wa(t,e,n){return(t%=es)?e||n?Ua(Va(t),Ya(e,n)):Va(t):e||n?Ya(e,n):Ha}function Ja(t){return function(e,n){return[(e+=t)>Ki?e-es:e<-Ki?e+es:e,n]}}function Va(t){var e=Ja(t);return e.invert=Ja(-t),e}function Ya(t,e){var n=as(t),r=hs(t),o=as(e),i=hs(e);function s(t,e){var s=as(e),a=as(t)*s,l=hs(t)*s,c=hs(e),u=c*n+a*r;return[ss(l*o-u*i,a*n-c*r),vs(u*o+l*i)]}return s.invert=function(t,e){var s=as(e),a=as(t)*s,l=hs(t)*s,c=hs(e),u=c*o-l*i;return[ss(l*o+c*i,a*n+u*r),vs(u*n-a*r)]},s}function Qa(t){function e(e){return(e=t(e[0]*rs,e[1]*rs))[0]*=ns,e[1]*=ns,e}return t=Wa(t[0]*rs,t[1]*rs,t.length>2?t[2]*rs:0),e.invert=function(e){return(e=t.invert(e[0]*rs,e[1]*rs))[0]*=ns,e[1]*=ns,e},e}function Ka(t,e,n,r,o,i){if(n){var s=as(e),a=hs(e),l=r*n;null==o?(o=e+r*es,i=e-l/2):(o=Xa(s,o),i=Xa(s,i),(r>0?o<i:o>i)&&(o+=r*es));for(var c,u=o;r>0?u>i:u<i;u-=l)c=Qs([s,-a*as(u),-a*hs(u)]),t.point(c[0],c[1])}}function Xa(t,e){(e=Ks(e))[0]-=t,ra(e);var n=ys(-e[1]);return((-e[2]<0?-n:n)+es-Yi)%es}function tl(){var t,e,n=Ga([0,0]),r=Ga(90),o=Ga(6),i={point:function(n,r){t.push(n=e(n,r)),n[0]*=ns,n[1]*=ns}};function s(){var s=n.apply(this,arguments),a=r.apply(this,arguments)*rs,l=o.apply(this,arguments)*rs;return t=[],e=Wa(-s[0]*rs,-s[1]*rs,0).invert,Ka(i,a,l,1),s={type:"Polygon",coordinates:[t]},t=e=null,s}return s.center=function(t){return arguments.length?(n="function"==typeof t?t:Ga([+t[0],+t[1]]),s):n},s.radius=function(t){return arguments.length?(r="function"==typeof t?t:Ga(+t),s):r},s.precision=function(t){return arguments.length?(o="function"==typeof t?t:Ga(+t),s):o},s}function el(){var t,e=[];return{point:function(e,n,r){t.push([e,n,r])},lineStart:function(){e.push(t=[])},lineEnd:_s,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function nl(t,e){return os(t[0]-e[0])<Yi&&os(t[1]-e[1])<Yi}function rl(t,e,n,r){this.x=t,this.z=e,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function ol(t,e,n,r,o){var i,s,a=[],l=[];if(t.forEach((function(t){if(!((e=t.length-1)<=0)){var e,n,r=t[0],s=t[e];if(nl(r,s)){if(!r[2]&&!s[2]){for(o.lineStart(),i=0;i<e;++i)o.point((r=t[i])[0],r[1]);return void o.lineEnd()}s[0]+=2e-6}a.push(n=new rl(r,t,null,!0)),l.push(n.o=new rl(r,null,n,!1)),a.push(n=new rl(s,t,null,!1)),l.push(n.o=new rl(s,null,n,!0))}})),a.length){for(l.sort(e),il(a),il(l),i=0,s=l.length;i<s;++i)l[i].e=n=!n;for(var c,u,f=a[0];;){for(var d=f,h=!0;d.v;)if((d=d.n)===f)return;c=d.z,o.lineStart();do{if(d.v=d.o.v=!0,d.e){if(h)for(i=0,s=c.length;i<s;++i)o.point((u=c[i])[0],u[1]);else r(d.x,d.n.x,1,o);d=d.n}else{if(h)for(c=d.p.z,i=c.length-1;i>=0;--i)o.point((u=c[i])[0],u[1]);else r(d.x,d.p.x,-1,o);d=d.p}c=(d=d.o).z,h=!h}while(!d.v);o.lineEnd()}}}function il(t){if(e=t.length){for(var e,n,r=0,o=t[0];++r<e;)o.n=n=t[r],n.p=o,o=n;o.n=n=t[0],n.p=o}}function sl(t){return os(t[0])<=Ki?t[0]:ps(t[0])*((os(t[0])+Ki)%es-Ki)}function al(t,e){var n=sl(e),r=e[1],o=hs(r),i=[hs(n),-as(n),0],s=0,a=0,l=new Vi.dU;1===o?r=Xi+Yi:-1===o&&(r=-Xi-Yi);for(var c=0,u=t.length;c<u;++c)if(d=(f=t[c]).length)for(var f,d,h=f[d-1],p=sl(h),m=h[1]/2+ts,g=hs(m),y=as(m),v=0;v<d;++v,p=_,g=x,y=k,h=b){var b=f[v],_=sl(b),w=b[1]/2+ts,x=hs(w),k=as(w),q=_-p,N=q>=0?1:-1,S=N*q,A=S>Ki,M=g*x;if(l.add(ss(M*N*hs(S),y*k+M*as(S))),s+=A?q+N*es:q,A^p>=n^_>=n){var T=ta(Ks(h),Ks(b));ra(T);var C=ta(i,T);ra(C);var j=(A^q>=0?-1:1)*vs(C[2]);(r>j||r===j&&(T[0]||T[1]))&&(a+=A^q>=0?1:-1)}}return(s<-1e-6||s<Yi&&l<-1e-12)^1&a}Ha.invert=Ha;var ll=n(1740);function cl(t,e,n,r){return function(o){var i,s,a,l=e(o),c=el(),u=e(c),f=!1,d={point:h,lineStart:m,lineEnd:g,polygonStart:function(){d.point=y,d.lineStart=v,d.lineEnd=b,s=[],i=[]},polygonEnd:function(){d.point=h,d.lineStart=m,d.lineEnd=g,s=(0,ll.Z)(s);var t=al(i,r);s.length?(f||(o.polygonStart(),f=!0),ol(s,fl,t,n,o)):t&&(f||(o.polygonStart(),f=!0),o.lineStart(),n(null,null,1,o),o.lineEnd()),f&&(o.polygonEnd(),f=!1),s=i=null},sphere:function(){o.polygonStart(),o.lineStart(),n(null,null,1,o),o.lineEnd(),o.polygonEnd()}};function h(e,n){t(e,n)&&o.point(e,n)}function p(t,e){l.point(t,e)}function m(){d.point=p,l.lineStart()}function g(){d.point=h,l.lineEnd()}function y(t,e){a.push([t,e]),u.point(t,e)}function v(){u.lineStart(),a=[]}function b(){y(a[0][0],a[0][1]),u.lineEnd();var t,e,n,r,l=u.clean(),d=c.result(),h=d.length;if(a.pop(),i.push(a),a=null,h)if(1&l){if((e=(n=d[0]).length-1)>0){for(f||(o.polygonStart(),f=!0),o.lineStart(),t=0;t<e;++t)o.point((r=n[t])[0],r[1]);o.lineEnd()}}else h>1&&2&l&&d.push(d.pop().concat(d.shift())),s.push(d.filter(ul))}return d}}function ul(t){return t.length>1}function fl(t,e){return((t=t.x)[0]<0?t[1]-Xi-Yi:Xi-t[1])-((e=e.x)[0]<0?e[1]-Xi-Yi:Xi-e[1])}const dl=cl((function(){return!0}),(function(t){var e,n=NaN,r=NaN,o=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(i,s){var a=i>0?Ki:-Ki,l=os(i-n);os(l-Ki)<Yi?(t.point(n,r=(r+s)/2>0?Xi:-Xi),t.point(o,r),t.lineEnd(),t.lineStart(),t.point(a,r),t.point(i,r),e=0):o!==a&&l>=Ki&&(os(n-o)<Yi&&(n-=o*Yi),os(i-a)<Yi&&(i-=a*Yi),r=function(t,e,n,r){var o,i,s=hs(t-n);return os(s)>Yi?is((hs(e)*(i=as(r))*hs(n)-hs(r)*(o=as(e))*hs(t))/(o*i*s)):(e+r)/2}(n,r,i,s),t.point(o,r),t.lineEnd(),t.lineStart(),t.point(a,r),e=0),t.point(n=i,r=s),o=a},lineEnd:function(){t.lineEnd(),n=r=NaN},clean:function(){return 2-e}}}),(function(t,e,n,r){var o;if(null==t)o=n*Xi,r.point(-Ki,o),r.point(0,o),r.point(Ki,o),r.point(Ki,0),r.point(Ki,-o),r.point(0,-o),r.point(-Ki,-o),r.point(-Ki,0),r.point(-Ki,o);else if(os(t[0]-e[0])>Yi){var i=t[0]<e[0]?Ki:-Ki;o=n*i/2,r.point(-i,o),r.point(0,o),r.point(i,o)}else r.point(e[0],e[1])}),[-Ki,-Xi]);function hl(t){var e=as(t),n=6*rs,r=e>0,o=os(e)>Yi;function i(t,n){return as(t)*as(n)>e}function s(t,n,r){var o=[1,0,0],i=ta(Ks(t),Ks(n)),s=Xs(i,i),a=i[0],l=s-a*a;if(!l)return!r&&t;var c=e*s/l,u=-e*a/l,f=ta(o,i),d=na(o,c);ea(d,na(i,u));var h=f,p=Xs(d,h),m=Xs(h,h),g=p*p-m*(Xs(d,d)-1);if(!(g<0)){var y=ms(g),v=na(h,(-p-y)/m);if(ea(v,d),v=Qs(v),!r)return v;var b,_=t[0],w=n[0],x=t[1],k=n[1];w<_&&(b=_,_=w,w=b);var q=w-_,N=os(q-Ki)<Yi;if(!N&&k<x&&(b=x,x=k,k=b),N||q<Yi?N?x+k>0^v[1]<(os(v[0]-_)<Yi?x:k):x<=v[1]&&v[1]<=k:q>Ki^(_<=v[0]&&v[0]<=w)){var S=na(h,(-p+y)/m);return ea(S,d),[v,Qs(S)]}}}function a(e,n){var o=r?t:Ki-t,i=0;return e<-o?i|=1:e>o&&(i|=2),n<-o?i|=4:n>o&&(i|=8),i}return cl(i,(function(t){var e,n,l,c,u;return{lineStart:function(){c=l=!1,u=1},point:function(f,d){var h,p=[f,d],m=i(f,d),g=r?m?0:a(f,d):m?a(f+(f<0?Ki:-Ki),d):0;if(!e&&(c=l=m)&&t.lineStart(),m!==l&&(!(h=s(e,p))||nl(e,h)||nl(p,h))&&(p[2]=1),m!==l)u=0,m?(t.lineStart(),h=s(p,e),t.point(h[0],h[1])):(h=s(e,p),t.point(h[0],h[1],2),t.lineEnd()),e=h;else if(o&&e&&r^m){var y;g&n||!(y=s(p,e,!0))||(u=0,r?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1],3)))}!m||e&&nl(e,p)||t.point(p[0],p[1]),e=p,l=m,n=g},lineEnd:function(){l&&t.lineEnd(),e=null},clean:function(){return u|(c&&l)<<1}}}),(function(e,r,o,i){Ka(i,t,n,o,e,r)}),r?[0,-t]:[-Ki,t-Ki])}var pl,ml,gl,yl,vl=1e9,bl=-vl;function _l(t,e,n,r){function o(o,i){return t<=o&&o<=n&&e<=i&&i<=r}function i(o,i,a,c){var u=0,f=0;if(null==o||(u=s(o,a))!==(f=s(i,a))||l(o,i)<0^a>0)do{c.point(0===u||3===u?t:n,u>1?r:e)}while((u=(u+a+4)%4)!==f);else c.point(i[0],i[1])}function s(r,o){return os(r[0]-t)<Yi?o>0?0:3:os(r[0]-n)<Yi?o>0?2:1:os(r[1]-e)<Yi?o>0?1:0:o>0?3:2}function a(t,e){return l(t.x,e.x)}function l(t,e){var n=s(t,1),r=s(e,1);return n!==r?n-r:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(s){var l,c,u,f,d,h,p,m,g,y,v,b=s,_=el(),w={point:x,lineStart:function(){w.point=k,c&&c.push(u=[]);y=!0,g=!1,p=m=NaN},lineEnd:function(){l&&(k(f,d),h&&g&&_.rejoin(),l.push(_.result()));w.point=x,g&&b.lineEnd()},polygonStart:function(){b=_,l=[],c=[],v=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,o=c.length;n<o;++n)for(var i,s,a=c[n],l=1,u=a.length,f=a[0],d=f[0],h=f[1];l<u;++l)i=d,s=h,d=(f=a[l])[0],h=f[1],s<=r?h>r&&(d-i)*(r-s)>(h-s)*(t-i)&&++e:h<=r&&(d-i)*(r-s)<(h-s)*(t-i)&&--e;return e}(),n=v&&e,o=(l=(0,ll.Z)(l)).length;(n||o)&&(s.polygonStart(),n&&(s.lineStart(),i(null,null,1,s),s.lineEnd()),o&&ol(l,a,e,i,s),s.polygonEnd());b=s,l=c=u=null}};function x(t,e){o(t,e)&&b.point(t,e)}function k(i,s){var a=o(i,s);if(c&&u.push([i,s]),y)f=i,d=s,h=a,y=!1,a&&(b.lineStart(),b.point(i,s));else if(a&&g)b.point(i,s);else{var l=[p=Math.max(bl,Math.min(vl,p)),m=Math.max(bl,Math.min(vl,m))],_=[i=Math.max(bl,Math.min(vl,i)),s=Math.max(bl,Math.min(vl,s))];!function(t,e,n,r,o,i){var s,a=t[0],l=t[1],c=0,u=1,f=e[0]-a,d=e[1]-l;if(s=n-a,f||!(s>0)){if(s/=f,f<0){if(s<c)return;s<u&&(u=s)}else if(f>0){if(s>u)return;s>c&&(c=s)}if(s=o-a,f||!(s<0)){if(s/=f,f<0){if(s>u)return;s>c&&(c=s)}else if(f>0){if(s<c)return;s<u&&(u=s)}if(s=r-l,d||!(s>0)){if(s/=d,d<0){if(s<c)return;s<u&&(u=s)}else if(d>0){if(s>u)return;s>c&&(c=s)}if(s=i-l,d||!(s<0)){if(s/=d,d<0){if(s>u)return;s>c&&(c=s)}else if(d>0){if(s<c)return;s<u&&(u=s)}return c>0&&(t[0]=a+c*f,t[1]=l+c*d),u<1&&(e[0]=a+u*f,e[1]=l+u*d),!0}}}}}(l,_,t,e,n,r)?a&&(b.lineStart(),b.point(i,s),v=!1):(g||(b.lineStart(),b.point(l[0],l[1])),b.point(_[0],_[1]),a||b.lineEnd(),v=!1)}p=i,m=s,g=a}return w}}function wl(){var t,e,n,r=0,o=0,i=960,s=500;return n={stream:function(n){return t&&e===n?t:t=_l(r,o,i,s)(e=n)},extent:function(a){return arguments.length?(r=+a[0][0],o=+a[0][1],i=+a[1][0],s=+a[1][1],t=e=null,n):[[r,o],[i,s]]}}}var xl={sphere:_s,point:_s,lineStart:function(){xl.point=ql,xl.lineEnd=kl},lineEnd:_s,polygonStart:_s,polygonEnd:_s};function kl(){xl.point=xl.lineEnd=_s}function ql(t,e){ml=t*=rs,gl=hs(e*=rs),yl=as(e),xl.point=Nl}function Nl(t,e){t*=rs;var n=hs(e*=rs),r=as(e),o=os(t-ml),i=as(o),s=r*hs(o),a=yl*n-gl*r*i,l=gl*n+yl*r*i;pl.add(ss(ms(s*s+a*a),l)),ml=t,gl=n,yl=r}function Sl(t){return pl=new Vi.dU,Ss(t,xl),+pl}var Al=[null,null],Ml={type:"LineString",coordinates:Al};function Tl(t,e){return Al[0]=t,Al[1]=e,Sl(Ml)}var Cl={Feature:function(t,e){return Ol(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,o=n.length;++r<o;)if(Ol(n[r].geometry,e))return!0;return!1}},jl={Sphere:function(){return!0},Point:function(t,e){return El(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(El(n[r],e))return!0;return!1},LineString:function(t,e){return Rl(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(Rl(n[r],e))return!0;return!1},Polygon:function(t,e){return Il(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(Il(n[r],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,o=n.length;++r<o;)if(Ol(n[r],e))return!0;return!1}};function Ol(t,e){return!(!t||!jl.hasOwnProperty(t.type))&&jl[t.type](t,e)}function El(t,e){return 0===Tl(t,e)}function Rl(t,e){for(var n,r,o,i=0,s=t.length;i<s;i++){if(0===(r=Tl(t[i],e)))return!0;if(i>0&&(o=Tl(t[i],t[i-1]))>0&&n<=o&&r<=o&&(n+r-o)*(1-Math.pow((n-r)/o,2))<Qi*o)return!0;n=r}return!1}function Il(t,e){return!!al(t.map(Pl),Fl(e))}function Pl(t){return(t=t.map(Fl)).pop(),t}function Fl(t){return[t[0]*rs,t[1]*rs]}function Ll(t,e){return(t&&Cl.hasOwnProperty(t.type)?Cl[t.type]:Ol)(t,e)}var Dl=n(1265);function Bl(t,e,n){var r=(0,Dl.Z)(t,e-Yi,n).concat(e);return function(t){return r.map((function(e){return[t,e]}))}}function zl(t,e,n){var r=(0,Dl.Z)(t,e-Yi,n).concat(e);return function(t){return r.map((function(e){return[e,t]}))}}function Zl(){var t,e,n,r,o,i,s,a,l,c,u,f,d=10,h=d,p=90,m=360,g=2.5;function y(){return{type:"MultiLineString",coordinates:v()}}function v(){return(0,Dl.Z)(ls(r/p)*p,n,p).map(u).concat((0,Dl.Z)(ls(a/m)*m,s,m).map(f)).concat((0,Dl.Z)(ls(e/d)*d,t,d).filter((function(t){return os(t%p)>Yi})).map(l)).concat((0,Dl.Z)(ls(i/h)*h,o,h).filter((function(t){return os(t%m)>Yi})).map(c))}return y.lines=function(){return v().map((function(t){return{type:"LineString",coordinates:t}}))},y.outline=function(){return{type:"Polygon",coordinates:[u(r).concat(f(s).slice(1),u(n).reverse().slice(1),f(a).reverse().slice(1))]}},y.extent=function(t){return arguments.length?y.extentMajor(t).extentMinor(t):y.extentMinor()},y.extentMajor=function(t){return arguments.length?(r=+t[0][0],n=+t[1][0],a=+t[0][1],s=+t[1][1],r>n&&(t=r,r=n,n=t),a>s&&(t=a,a=s,s=t),y.precision(g)):[[r,a],[n,s]]},y.extentMinor=function(n){return arguments.length?(e=+n[0][0],t=+n[1][0],i=+n[0][1],o=+n[1][1],e>t&&(n=e,e=t,t=n),i>o&&(n=i,i=o,o=n),y.precision(g)):[[e,i],[t,o]]},y.step=function(t){return arguments.length?y.stepMajor(t).stepMinor(t):y.stepMinor()},y.stepMajor=function(t){return arguments.length?(p=+t[0],m=+t[1],y):[p,m]},y.stepMinor=function(t){return arguments.length?(d=+t[0],h=+t[1],y):[d,h]},y.precision=function(d){return arguments.length?(g=+d,l=Bl(i,o,90),c=zl(e,t,g),u=Bl(a,s,90),f=zl(r,n,g),y):g},y.extentMajor([[-180,-89.999999],[180,89.999999]]).extentMinor([[-180,-80.000001],[180,80.000001]])}function $l(){return Zl()()}function Gl(t,e){var n=t[0]*rs,r=t[1]*rs,o=e[0]*rs,i=e[1]*rs,s=as(r),a=hs(r),l=as(i),c=hs(i),u=s*as(n),f=s*hs(n),d=l*as(o),h=l*hs(o),p=2*vs(ms(bs(i-r)+s*l*bs(o-n))),m=hs(p),g=p?function(t){var e=hs(t*=p)/m,n=hs(p-t)/m,r=n*u+e*d,o=n*f+e*h,i=n*a+e*c;return[ss(o,r)*ns,ss(i,ms(r*r+o*o))*ns]}:function(){return[n*ns,r*ns]};return g.distance=p,g}const Ul=t=>t;var Hl,Wl,Jl,Vl,Yl=new Vi.dU,Ql=new Vi.dU,Kl={point:_s,lineStart:_s,lineEnd:_s,polygonStart:function(){Kl.lineStart=Xl,Kl.lineEnd=nc},polygonEnd:function(){Kl.lineStart=Kl.lineEnd=Kl.point=_s,Yl.add(os(Ql)),Ql=new Vi.dU},result:function(){var t=Yl/2;return Yl=new Vi.dU,t}};function Xl(){Kl.point=tc}function tc(t,e){Kl.point=ec,Hl=Jl=t,Wl=Vl=e}function ec(t,e){Ql.add(Vl*t-Jl*e),Jl=t,Vl=e}function nc(){ec(Hl,Wl)}const rc=Kl;var oc=1/0,ic=oc,sc=-oc,ac=sc,lc={point:function(t,e){t<oc&&(oc=t);t>sc&&(sc=t);e<ic&&(ic=e);e>ac&&(ac=e)},lineStart:_s,lineEnd:_s,polygonStart:_s,polygonEnd:_s,result:function(){var t=[[oc,ic],[sc,ac]];return sc=ac=-(ic=oc=1/0),t}};const cc=lc;var uc,fc,dc,hc,pc=0,mc=0,gc=0,yc=0,vc=0,bc=0,_c=0,wc=0,xc=0,kc={point:qc,lineStart:Nc,lineEnd:Mc,polygonStart:function(){kc.lineStart=Tc,kc.lineEnd=Cc},polygonEnd:function(){kc.point=qc,kc.lineStart=Nc,kc.lineEnd=Mc},result:function(){var t=xc?[_c/xc,wc/xc]:bc?[yc/bc,vc/bc]:gc?[pc/gc,mc/gc]:[NaN,NaN];return pc=mc=gc=yc=vc=bc=_c=wc=xc=0,t}};function qc(t,e){pc+=t,mc+=e,++gc}function Nc(){kc.point=Sc}function Sc(t,e){kc.point=Ac,qc(dc=t,hc=e)}function Ac(t,e){var n=t-dc,r=e-hc,o=ms(n*n+r*r);yc+=o*(dc+t)/2,vc+=o*(hc+e)/2,bc+=o,qc(dc=t,hc=e)}function Mc(){kc.point=qc}function Tc(){kc.point=jc}function Cc(){Oc(uc,fc)}function jc(t,e){kc.point=Oc,qc(uc=dc=t,fc=hc=e)}function Oc(t,e){var n=t-dc,r=e-hc,o=ms(n*n+r*r);yc+=o*(dc+t)/2,vc+=o*(hc+e)/2,bc+=o,_c+=(o=hc*t-dc*e)*(dc+t),wc+=o*(hc+e),xc+=3*o,qc(dc=t,hc=e)}const Ec=kc;function Rc(t){this._context=t}Rc.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._context.moveTo(t,e),this._point=1;break;case 1:this._context.lineTo(t,e);break;default:this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,es)}},result:_s};var Ic,Pc,Fc,Lc,Dc,Bc=new Vi.dU,zc={point:_s,lineStart:function(){zc.point=Zc},lineEnd:function(){Ic&&$c(Pc,Fc),zc.point=_s},polygonStart:function(){Ic=!0},polygonEnd:function(){Ic=null},result:function(){var t=+Bc;return Bc=new Vi.dU,t}};function Zc(t,e){zc.point=$c,Pc=Lc=t,Fc=Dc=e}function $c(t,e){Lc-=t,Dc-=e,Bc.add(ms(Lc*Lc+Dc*Dc)),Lc=t,Dc=e}const Gc=zc;function Uc(){this._string=[]}function Hc(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function Wc(t,e){var n,r,o=4.5;function i(t){return t&&("function"==typeof o&&r.pointRadius(+o.apply(this,arguments)),Ss(t,n(r))),r.result()}return i.area=function(t){return Ss(t,n(rc)),rc.result()},i.measure=function(t){return Ss(t,n(Gc)),Gc.result()},i.bounds=function(t){return Ss(t,n(cc)),cc.result()},i.centroid=function(t){return Ss(t,n(Ec)),Ec.result()},i.projection=function(e){return arguments.length?(n=null==e?(t=null,Ul):(t=e).stream,i):t},i.context=function(t){return arguments.length?(r=null==t?(e=null,new Uc):new Rc(e=t),"function"!=typeof o&&r.pointRadius(o),i):e},i.pointRadius=function(t){return arguments.length?(o="function"==typeof t?t:(r.pointRadius(+t),+t),i):o},i.projection(t).context(e)}function Jc(t){return{stream:Vc(t)}}function Vc(t){return function(e){var n=new Yc;for(var r in t)n[r]=t[r];return n.stream=e,n}}function Yc(){}function Qc(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=r&&t.clipExtent(null),Ss(n,t.stream(cc)),e(cc.result()),null!=r&&t.clipExtent(r),t}function Kc(t,e,n){return Qc(t,(function(n){var r=e[1][0]-e[0][0],o=e[1][1]-e[0][1],i=Math.min(r/(n[1][0]-n[0][0]),o/(n[1][1]-n[0][1])),s=+e[0][0]+(r-i*(n[1][0]+n[0][0]))/2,a=+e[0][1]+(o-i*(n[1][1]+n[0][1]))/2;t.scale(150*i).translate([s,a])}),n)}function Xc(t,e,n){return Kc(t,[[0,0],e],n)}function tu(t,e,n){return Qc(t,(function(n){var r=+e,o=r/(n[1][0]-n[0][0]),i=(r-o*(n[1][0]+n[0][0]))/2,s=-o*n[0][1];t.scale(150*o).translate([i,s])}),n)}function eu(t,e,n){return Qc(t,(function(n){var r=+e,o=r/(n[1][1]-n[0][1]),i=-o*n[0][0],s=(r-o*(n[1][1]+n[0][1]))/2;t.scale(150*o).translate([i,s])}),n)}Uc.prototype={_radius:4.5,_circle:Hc(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._string.push("M",t,",",e),this._point=1;break;case 1:this._string.push("L",t,",",e);break;default:null==this._circle&&(this._circle=Hc(this._radius)),this._string.push("M",t,",",e,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}},Yc.prototype={constructor:Yc,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var nu=as(30*rs);function ru(t,e){return+e?function(t,e){function n(r,o,i,s,a,l,c,u,f,d,h,p,m,g){var y=c-r,v=u-o,b=y*y+v*v;if(b>4*e&&m--){var _=s+d,w=a+h,x=l+p,k=ms(_*_+w*w+x*x),q=vs(x/=k),N=os(os(x)-1)<Yi||os(i-f)<Yi?(i+f)/2:ss(w,_),S=t(N,q),A=S[0],M=S[1],T=A-r,C=M-o,j=v*T-y*C;(j*j/b>e||os((y*T+v*C)/b-.5)>.3||s*d+a*h+l*p<nu)&&(n(r,o,i,s,a,l,A,M,N,_/=k,w/=k,x,m,g),g.point(A,M),n(A,M,N,_,w,x,c,u,f,d,h,p,m,g))}}return function(e){var r,o,i,s,a,l,c,u,f,d,h,p,m={point:g,lineStart:y,lineEnd:b,polygonStart:function(){e.polygonStart(),m.lineStart=_},polygonEnd:function(){e.polygonEnd(),m.lineStart=y}};function g(n,r){n=t(n,r),e.point(n[0],n[1])}function y(){u=NaN,m.point=v,e.lineStart()}function v(r,o){var i=Ks([r,o]),s=t(r,o);n(u,f,c,d,h,p,u=s[0],f=s[1],c=r,d=i[0],h=i[1],p=i[2],16,e),e.point(u,f)}function b(){m.point=g,e.lineEnd()}function _(){y(),m.point=w,m.lineEnd=x}function w(t,e){v(r=t,e),o=u,i=f,s=d,a=h,l=p,m.point=v}function x(){n(u,f,c,d,h,p,o,i,r,s,a,l,16,e),m.lineEnd=b,b()}return m}}(t,e):function(t){return Vc({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var ou=Vc({point:function(t,e){this.stream.point(t*rs,e*rs)}});function iu(t,e,n,r,o,i){if(!i)return function(t,e,n,r,o){function i(i,s){return[e+t*(i*=r),n-t*(s*=o)]}return i.invert=function(i,s){return[(i-e)/t*r,(n-s)/t*o]},i}(t,e,n,r,o);var s=as(i),a=hs(i),l=s*t,c=a*t,u=s/t,f=a/t,d=(a*n-s*e)/t,h=(a*e+s*n)/t;function p(t,i){return[l*(t*=r)-c*(i*=o)+e,n-c*t-l*i]}return p.invert=function(t,e){return[r*(u*t-f*e+d),o*(h-f*t-u*e)]},p}function su(t){return au((function(){return t}))()}function au(t){var e,n,r,o,i,s,a,l,c,u,f=150,d=480,h=250,p=0,m=0,g=0,y=0,v=0,b=0,_=1,w=1,x=null,k=dl,q=null,N=Ul,S=.5;function A(t){return l(t[0]*rs,t[1]*rs)}function M(t){return(t=l.invert(t[0],t[1]))&&[t[0]*ns,t[1]*ns]}function T(){var t=iu(f,0,0,_,w,b).apply(null,e(p,m)),r=iu(f,d-t[0],h-t[1],_,w,b);return n=Wa(g,y,v),a=Ua(e,r),l=Ua(n,a),s=ru(a,S),C()}function C(){return c=u=null,A}return A.stream=function(t){return c&&u===t?c:c=ou(function(t){return Vc({point:function(e,n){var r=t(e,n);return this.stream.point(r[0],r[1])}})}(n)(k(s(N(u=t)))))},A.preclip=function(t){return arguments.length?(k=t,x=void 0,C()):k},A.postclip=function(t){return arguments.length?(N=t,q=r=o=i=null,C()):N},A.clipAngle=function(t){return arguments.length?(k=+t?hl(x=t*rs):(x=null,dl),C()):x*ns},A.clipExtent=function(t){return arguments.length?(N=null==t?(q=r=o=i=null,Ul):_l(q=+t[0][0],r=+t[0][1],o=+t[1][0],i=+t[1][1]),C()):null==q?null:[[q,r],[o,i]]},A.scale=function(t){return arguments.length?(f=+t,T()):f},A.translate=function(t){return arguments.length?(d=+t[0],h=+t[1],T()):[d,h]},A.center=function(t){return arguments.length?(p=t[0]%360*rs,m=t[1]%360*rs,T()):[p*ns,m*ns]},A.rotate=function(t){return arguments.length?(g=t[0]%360*rs,y=t[1]%360*rs,v=t.length>2?t[2]%360*rs:0,T()):[g*ns,y*ns,v*ns]},A.angle=function(t){return arguments.length?(b=t%360*rs,T()):b*ns},A.reflectX=function(t){return arguments.length?(_=t?-1:1,T()):_<0},A.reflectY=function(t){return arguments.length?(w=t?-1:1,T()):w<0},A.precision=function(t){return arguments.length?(s=ru(a,S=t*t),C()):ms(S)},A.fitExtent=function(t,e){return Kc(A,t,e)},A.fitSize=function(t,e){return Xc(A,t,e)},A.fitWidth=function(t,e){return tu(A,t,e)},A.fitHeight=function(t,e){return eu(A,t,e)},function(){return e=t.apply(this,arguments),A.invert=e.invert&&M,T()}}function lu(t){var e=0,n=Ki/3,r=au(t),o=r(e,n);return o.parallels=function(t){return arguments.length?r(e=t[0]*rs,n=t[1]*rs):[e*ns,n*ns]},o}function cu(t,e){var n=hs(t),r=(n+hs(e))/2;if(os(r)<Yi)return function(t){var e=as(t);function n(t,n){return[t*e,hs(n)/e]}return n.invert=function(t,n){return[t/e,vs(n*e)]},n}(t);var o=1+n*(2*r-n),i=ms(o)/r;function s(t,e){var n=ms(o-2*r*hs(e))/r;return[n*hs(t*=r),i-n*as(t)]}return s.invert=function(t,e){var n=i-e,s=ss(t,os(n))*ps(n);return n*r<0&&(s-=Ki*ps(t)*ps(n)),[s/r,vs((o-(t*t+n*n)*r*r)/(2*r))]},s}function uu(){return lu(cu).scale(155.424).center([0,33.6442])}function fu(){return uu().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function du(){var t,e,n,r,o,i,s=fu(),a=uu().rotate([154,0]).center([-2,58.5]).parallels([55,65]),l=uu().rotate([157,0]).center([-3,19.9]).parallels([8,18]),c={point:function(t,e){i=[t,e]}};function u(t){var e=t[0],s=t[1];return i=null,n.point(e,s),i||(r.point(e,s),i)||(o.point(e,s),i)}function f(){return t=e=null,u}return u.invert=function(t){var e=s.scale(),n=s.translate(),r=(t[0]-n[0])/e,o=(t[1]-n[1])/e;return(o>=.12&&o<.234&&r>=-.425&&r<-.214?a:o>=.166&&o<.234&&r>=-.214&&r<-.115?l:s).invert(t)},u.stream=function(n){return t&&e===n?t:(r=[s.stream(e=n),a.stream(n),l.stream(n)],o=r.length,t={point:function(t,e){for(var n=-1;++n<o;)r[n].point(t,e)},sphere:function(){for(var t=-1;++t<o;)r[t].sphere()},lineStart:function(){for(var t=-1;++t<o;)r[t].lineStart()},lineEnd:function(){for(var t=-1;++t<o;)r[t].lineEnd()},polygonStart:function(){for(var t=-1;++t<o;)r[t].polygonStart()},polygonEnd:function(){for(var t=-1;++t<o;)r[t].polygonEnd()}});var r,o},u.precision=function(t){return arguments.length?(s.precision(t),a.precision(t),l.precision(t),f()):s.precision()},u.scale=function(t){return arguments.length?(s.scale(t),a.scale(.35*t),l.scale(t),u.translate(s.translate())):s.scale()},u.translate=function(t){if(!arguments.length)return s.translate();var e=s.scale(),i=+t[0],u=+t[1];return n=s.translate(t).clipExtent([[i-.455*e,u-.238*e],[i+.455*e,u+.238*e]]).stream(c),r=a.translate([i-.307*e,u+.201*e]).clipExtent([[i-.425*e+Yi,u+.12*e+Yi],[i-.214*e-Yi,u+.234*e-Yi]]).stream(c),o=l.translate([i-.205*e,u+.212*e]).clipExtent([[i-.214*e+Yi,u+.166*e+Yi],[i-.115*e-Yi,u+.234*e-Yi]]).stream(c),f()},u.fitExtent=function(t,e){return Kc(u,t,e)},u.fitSize=function(t,e){return Xc(u,t,e)},u.fitWidth=function(t,e){return tu(u,t,e)},u.fitHeight=function(t,e){return eu(u,t,e)},u.scale(1070)}function hu(t){return function(e,n){var r=as(e),o=as(n),i=t(r*o);return i===1/0?[2,0]:[i*o*hs(e),i*hs(n)]}}function pu(t){return function(e,n){var r=ms(e*e+n*n),o=t(r),i=hs(o),s=as(o);return[ss(e*i,r*s),vs(r&&n*i/r)]}}var mu=hu((function(t){return ms(2/(1+t))}));function gu(){return su(mu).scale(124.75).clipAngle(179.999)}mu.invert=pu((function(t){return 2*vs(t/2)}));var yu=hu((function(t){return(t=ys(t))&&t/hs(t)}));function vu(){return su(yu).scale(79.4188).clipAngle(179.999)}function bu(t,e){return[t,fs(gs((Xi+e)/2))]}function _u(){return wu(bu).scale(961/es)}function wu(t){var e,n,r,o=su(t),i=o.center,s=o.scale,a=o.translate,l=o.clipExtent,c=null;function u(){var i=Ki*s(),a=o(Qa(o.rotate()).invert([0,0]));return l(null==c?[[a[0]-i,a[1]-i],[a[0]+i,a[1]+i]]:t===bu?[[Math.max(a[0]-i,c),e],[Math.min(a[0]+i,n),r]]:[[c,Math.max(a[1]-i,e)],[n,Math.min(a[1]+i,r)]])}return o.scale=function(t){return arguments.length?(s(t),u()):s()},o.translate=function(t){return arguments.length?(a(t),u()):a()},o.center=function(t){return arguments.length?(i(t),u()):i()},o.clipExtent=function(t){return arguments.length?(null==t?c=e=n=r=null:(c=+t[0][0],e=+t[0][1],n=+t[1][0],r=+t[1][1]),u()):null==c?null:[[c,e],[n,r]]},u()}function xu(t){return gs((Xi+t)/2)}function ku(t,e){var n=as(t),r=t===e?hs(t):fs(n/as(e))/fs(xu(e)/xu(t)),o=n*ds(xu(t),r)/r;if(!r)return bu;function i(t,e){o>0?e<-Xi+Yi&&(e=-Xi+Yi):e>Xi-Yi&&(e=Xi-Yi);var n=o/ds(xu(e),r);return[n*hs(r*t),o-n*as(r*t)]}return i.invert=function(t,e){var n=o-e,i=ps(r)*ms(t*t+n*n),s=ss(t,os(n))*ps(n);return n*r<0&&(s-=Ki*ps(t)*ps(n)),[s/r,2*is(ds(o/i,1/r))-Xi]},i}function qu(){return lu(ku).scale(109.5).parallels([30,30])}function Nu(t,e){return[t,e]}function Su(){return su(Nu).scale(152.63)}function Au(t,e){var n=as(t),r=t===e?hs(t):(n-as(e))/(e-t),o=n/r+t;if(os(r)<Yi)return Nu;function i(t,e){var n=o-e,i=r*t;return[n*hs(i),o-n*as(i)]}return i.invert=function(t,e){var n=o-e,i=ss(t,os(n))*ps(n);return n*r<0&&(i-=Ki*ps(t)*ps(n)),[i/r,o-ps(r)*ms(t*t+n*n)]},i}function Mu(){return lu(Au).scale(131.154).center([0,13.9389])}yu.invert=pu((function(t){return t})),bu.invert=function(t,e){return[t,2*is(cs(e))-Xi]},Nu.invert=Nu;var Tu=1.340264,Cu=-.081106,ju=893e-6,Ou=.003796,Eu=ms(3)/2;function Ru(t,e){var n=vs(Eu*hs(e)),r=n*n,o=r*r*r;return[t*as(n)/(Eu*(Tu+3*Cu*r+o*(7*ju+9*Ou*r))),n*(Tu+Cu*r+o*(ju+Ou*r))]}function Iu(){return su(Ru).scale(177.158)}function Pu(t,e){var n=as(e),r=as(t)*n;return[n*hs(t)/r,hs(e)/r]}function Fu(){return su(Pu).scale(144.049).clipAngle(60)}function Lu(){var t,e,n,r,o,i,s,a=1,l=0,c=0,u=1,f=1,d=0,h=null,p=1,m=1,g=Vc({point:function(t,e){var n=b([t,e]);this.stream.point(n[0],n[1])}}),y=Ul;function v(){return p=a*u,m=a*f,i=s=null,b}function b(n){var r=n[0]*p,o=n[1]*m;if(d){var i=o*t-r*e;r=r*t+o*e,o=i}return[r+l,o+c]}return b.invert=function(n){var r=n[0]-l,o=n[1]-c;if(d){var i=o*t+r*e;r=r*t-o*e,o=i}return[r/p,o/m]},b.stream=function(t){return i&&s===t?i:i=g(y(s=t))},b.postclip=function(t){return arguments.length?(y=t,h=n=r=o=null,v()):y},b.clipExtent=function(t){return arguments.length?(y=null==t?(h=n=r=o=null,Ul):_l(h=+t[0][0],n=+t[0][1],r=+t[1][0],o=+t[1][1]),v()):null==h?null:[[h,n],[r,o]]},b.scale=function(t){return arguments.length?(a=+t,v()):a},b.translate=function(t){return arguments.length?(l=+t[0],c=+t[1],v()):[l,c]},b.angle=function(n){return arguments.length?(e=hs(d=n%360*rs),t=as(d),v()):d*ns},b.reflectX=function(t){return arguments.length?(u=t?-1:1,v()):u<0},b.reflectY=function(t){return arguments.length?(f=t?-1:1,v()):f<0},b.fitExtent=function(t,e){return Kc(b,t,e)},b.fitSize=function(t,e){return Xc(b,t,e)},b.fitWidth=function(t,e){return tu(b,t,e)},b.fitHeight=function(t,e){return eu(b,t,e)},b}function Du(t,e){var n=e*e,r=n*n;return[t*(.8707-.131979*n+r*(r*(.003971*n-.001529*r)-.013791)),e*(1.007226+n*(.015085+r*(.028874*n-.044475-.005916*r)))]}function Bu(){return su(Du).scale(175.295)}function zu(t,e){return[as(e)*hs(t),hs(e)]}function Zu(){return su(zu).scale(249.5).clipAngle(90.000001)}function $u(t,e){var n=as(e),r=1+as(t)*n;return[n*hs(t)/r,hs(e)/r]}function Gu(){return su($u).scale(250).clipAngle(142)}function Uu(t,e){return[fs(gs((Xi+e)/2)),-t]}function Hu(){var t=wu(Uu),e=t.center,n=t.rotate;return t.center=function(t){return arguments.length?e([-t[1],t[0]]):[(t=e())[1],-t[0]]},t.rotate=function(t){return arguments.length?n([t[0],t[1],t.length>2?t[2]+90:90]):[(t=n())[0],t[1],t[2]-90]},n([0,0,90]).scale(159.155)}Ru.invert=function(t,e){for(var n,r=e,o=r*r,i=o*o*o,s=0;s<12&&(i=(o=(r-=n=(r*(Tu+Cu*o+i*(ju+Ou*o))-e)/(Tu+3*Cu*o+i*(7*ju+9*Ou*o)))*r)*o*o,!(os(n)<Qi));++s);return[Eu*t*(Tu+3*Cu*o+i*(7*ju+9*Ou*o))/as(r),vs(hs(r)/Eu)]},Pu.invert=pu(is),Du.invert=function(t,e){var n,r=e,o=25;do{var i=r*r,s=i*i;r-=n=(r*(1.007226+i*(.015085+s*(.028874*i-.044475-.005916*s)))-e)/(1.007226+i*(.045255+s*(.259866*i-.311325-.005916*11*s)))}while(os(n)>Yi&&--o>0);return[t/(.8707+(i=r*r)*(i*(i*i*i*(.003971-.001529*i)-.013791)-.131979)),r]},zu.invert=pu(vs),$u.invert=pu((function(t){return 2*is(t)})),Uu.invert=function(t,e){return[-e,2*is(cs(t))-Xi]};var Wu=n(5505),Ju=n(6778);function Vu(t){for(var e,n=-1,r=t.length,o=t[r-1],i=0;++n<r;)e=o,o=t[n],i+=e[1]*o[0]-e[0]*o[1];return i/2}function Yu(t){for(var e,n,r=-1,o=t.length,i=0,s=0,a=t[o-1],l=0;++r<o;)e=a,a=t[r],l+=n=e[0]*a[1]-a[0]*e[1],i+=(e[0]+a[0])*n,s+=(e[1]+a[1])*n;return[i/(l*=3),s/l]}function Qu(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0])}function Ku(t,e){return t[0]-e[0]||t[1]-e[1]}function Xu(t){const e=t.length,n=[0,1];let r,o=2;for(r=2;r<e;++r){for(;o>1&&Qu(t[n[o-2]],t[n[o-1]],t[r])<=0;)--o;n[o++]=r}return n.slice(0,o)}function tf(t){if((n=t.length)<3)return null;var e,n,r=new Array(n),o=new Array(n);for(e=0;e<n;++e)r[e]=[+t[e][0],+t[e][1],e];for(r.sort(Ku),e=0;e<n;++e)o[e]=[r[e][0],-r[e][1]];var i=Xu(r),s=Xu(o),a=s[0]===i[0],l=s[s.length-1]===i[i.length-1],c=[];for(e=i.length-1;e>=0;--e)c.push(t[r[i[e]][2]]);for(e=+a;e<s.length-l;++e)c.push(t[r[s[e]][2]]);return c}function ef(t,e){for(var n,r,o=t.length,i=t[o-1],s=e[0],a=e[1],l=i[0],c=i[1],u=!1,f=0;f<o;++f)n=(i=t[f])[0],(r=i[1])>a!=c>a&&s<(l-n)*(a-r)/(c-r)+n&&(u=!u),l=n,c=r;return u}function nf(t){for(var e,n,r=-1,o=t.length,i=t[o-1],s=i[0],a=i[1],l=0;++r<o;)e=s,n=a,e-=s=(i=t[r])[0],n-=a=i[1],l+=Math.hypot(e,n);return l}const rf=Math.random,of=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,1===arguments.length?(n=t,t=0):n-=t,function(){return e()*n+t}}return n.source=t,n}(rf),sf=function t(e){function n(t,n){return arguments.length<2&&(n=t,t=0),t=Math.floor(t),n=Math.floor(n)-t,function(){return Math.floor(e()*n+t)}}return n.source=t,n}(rf),af=function t(e){function n(t,n){var r,o;return t=null==t?0:+t,n=null==n?1:+n,function(){var i;if(null!=r)i=r,r=null;else do{r=2*e()-1,i=2*e()-1,o=r*r+i*i}while(!o||o>1);return t+n*i*Math.sqrt(-2*Math.log(o)/o)}}return n.source=t,n}(rf),lf=function t(e){var n=af.source(e);function r(){var t=n.apply(this,arguments);return function(){return Math.exp(t())}}return r.source=t,r}(rf),cf=function t(e){function n(t){return(t=+t)<=0?()=>0:function(){for(var n=0,r=t;r>1;--r)n+=e();return n+r*e()}}return n.source=t,n}(rf),uf=function t(e){var n=cf.source(e);function r(t){if(0==(t=+t))return e;var r=n(t);return function(){return r()/t}}return r.source=t,r}(rf),ff=function t(e){function n(t){return function(){return-Math.log1p(-e())/t}}return n.source=t,n}(rf),df=function t(e){function n(t){if((t=+t)<0)throw new RangeError("invalid alpha");return t=1/-t,function(){return Math.pow(1-e(),t)}}return n.source=t,n}(rf),hf=function t(e){function n(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return function(){return Math.floor(e()+t)}}return n.source=t,n}(rf),pf=function t(e){function n(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return 0===t?()=>1/0:1===t?()=>1:(t=Math.log1p(-t),function(){return 1+Math.floor(Math.log1p(-e())/t)})}return n.source=t,n}(rf),mf=function t(e){var n=af.source(e)();function r(t,r){if((t=+t)<0)throw new RangeError("invalid k");if(0===t)return()=>0;if(r=null==r?1:+r,1===t)return()=>-Math.log1p(-e())*r;var o=(t<1?t+1:t)-1/3,i=1/(3*Math.sqrt(o)),s=t<1?()=>Math.pow(e(),1/t):()=>1;return function(){do{do{var t=n(),a=1+i*t}while(a<=0);a*=a*a;var l=1-e()}while(l>=1-.0331*t*t*t*t&&Math.log(l)>=.5*t*t+o*(1-a+Math.log(a)));return o*a*s()*r}}return r.source=t,r}(rf),gf=function t(e){var n=mf.source(e);function r(t,e){var r=n(t),o=n(e);return function(){var t=r();return 0===t?0:t/(t+o())}}return r.source=t,r}(rf),yf=function t(e){var n=pf.source(e),r=gf.source(e);function o(t,e){return t=+t,(e=+e)>=1?()=>t:e<=0?()=>0:function(){for(var o=0,i=t,s=e;i*s>16&&i*(1-s)>16;){var a=Math.floor((i+1)*s),l=r(a,i-a+1)();l<=s?(o+=a,i-=a,s=(s-l)/(1-l)):(i=a-1,s/=l)}for(var c=s<.5,u=n(c?s:1-s),f=u(),d=0;f<=i;++d)f+=u();return o+(c?d:i-d)}}return o.source=t,o}(rf),vf=function t(e){function n(t,n,r){var o;return 0==(t=+t)?o=t=>-Math.log(t):(t=1/t,o=e=>Math.pow(e,t)),n=null==n?0:+n,r=null==r?1:+r,function(){return n+r*o(-Math.log1p(-e()))}}return n.source=t,n}(rf),bf=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,function(){return t+n*Math.tan(Math.PI*e())}}return n.source=t,n}(rf),_f=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,function(){var r=e();return t+n*Math.log(r/(1-r))}}return n.source=t,n}(rf),wf=function t(e){var n=mf.source(e),r=yf.source(e);function o(t){return function(){for(var o=0,i=t;i>16;){var s=Math.floor(.875*i),a=n(s)();if(a>i)return o+r(s-1,i/a)();o+=s,i-=a}for(var l=-Math.log1p(-e()),c=0;l<=i;++c)l-=Math.log1p(-e());return o+c}}return o.source=t,o}(rf),xf=1/4294967296;function kf(t=Math.random()){let e=0|(0<=t&&t<1?t/xf:Math.abs(t));return()=>(e=1664525*e+1013904223|0,xf*(e>>>0))}var qf=n(2282),Nf=n(895);function Sf(t){return Lt(kt(t).call(document.documentElement))}var Af=0;function Mf(){return new Tf}function Tf(){this._="@"+(++Af).toString(36)}function Cf(t,e){return t.target&&(t=Ht(t),void 0===e&&(e=t.currentTarget),t=t.touches||[t]),Array.from(t,(t=>Wt(t,e)))}function jf(t){return"string"==typeof t?new It([document.querySelectorAll(t)],[document.documentElement]):new It([N(t)],Rt)}function Of(t){return function(){return t}}Tf.prototype=Mf.prototype={constructor:Tf,get:function(t){for(var e=this._;!(e in t);)if(!(t=t.parentNode))return;return t[e]},set:function(t,e){return t[this._]=e},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}};const Ef=Math.abs,Rf=Math.atan2,If=Math.cos,Pf=Math.max,Ff=Math.min,Lf=Math.sin,Df=Math.sqrt,Bf=1e-12,zf=Math.PI,Zf=zf/2,$f=2*zf;function Gf(t){return t>1?0:t<-1?zf:Math.acos(t)}function Uf(t){return t>=1?Zf:t<=-1?-Zf:Math.asin(t)}function Hf(t){return t.innerRadius}function Wf(t){return t.outerRadius}function Jf(t){return t.startAngle}function Vf(t){return t.endAngle}function Yf(t){return t&&t.padAngle}function Qf(t,e,n,r,o,i,s,a){var l=n-t,c=r-e,u=s-o,f=a-i,d=f*l-u*c;if(!(d*d<Bf))return[t+(d=(u*(e-i)-f*(t-o))/d)*l,e+d*c]}function Kf(t,e,n,r,o,i,s){var a=t-n,l=e-r,c=(s?i:-i)/Df(a*a+l*l),u=c*l,f=-c*a,d=t+u,h=e+f,p=n+u,m=r+f,g=(d+p)/2,y=(h+m)/2,v=p-d,b=m-h,_=v*v+b*b,w=o-i,x=d*m-p*h,k=(b<0?-1:1)*Df(Pf(0,w*w*_-x*x)),q=(x*b-v*k)/_,N=(-x*v-b*k)/_,S=(x*b+v*k)/_,A=(-x*v+b*k)/_,M=q-g,T=N-y,C=S-g,j=A-y;return M*M+T*T>C*C+j*j&&(q=S,N=A),{cx:q,cy:N,x01:-u,y01:-f,x11:q*(o/w-1),y11:N*(o/w-1)}}function Xf(){var t=Hf,e=Wf,n=Of(0),r=null,o=Jf,i=Vf,s=Yf,a=null;function l(){var l,c,u=+t.apply(this,arguments),f=+e.apply(this,arguments),d=o.apply(this,arguments)-Zf,h=i.apply(this,arguments)-Zf,p=Ef(h-d),m=h>d;if(a||(a=l=lr()),f<u&&(c=f,f=u,u=c),f>Bf)if(p>$f-Bf)a.moveTo(f*If(d),f*Lf(d)),a.arc(0,0,f,d,h,!m),u>Bf&&(a.moveTo(u*If(h),u*Lf(h)),a.arc(0,0,u,h,d,m));else{var g,y,v=d,b=h,_=d,w=h,x=p,k=p,q=s.apply(this,arguments)/2,N=q>Bf&&(r?+r.apply(this,arguments):Df(u*u+f*f)),S=Ff(Ef(f-u)/2,+n.apply(this,arguments)),A=S,M=S;if(N>Bf){var T=Uf(N/u*Lf(q)),C=Uf(N/f*Lf(q));(x-=2*T)>Bf?(_+=T*=m?1:-1,w-=T):(x=0,_=w=(d+h)/2),(k-=2*C)>Bf?(v+=C*=m?1:-1,b-=C):(k=0,v=b=(d+h)/2)}var j=f*If(v),O=f*Lf(v),E=u*If(w),R=u*Lf(w);if(S>Bf){var I,P=f*If(b),F=f*Lf(b),L=u*If(_),D=u*Lf(_);if(p<zf&&(I=Qf(j,O,L,D,P,F,E,R))){var B=j-I[0],z=O-I[1],Z=P-I[0],$=F-I[1],G=1/Lf(Gf((B*Z+z*$)/(Df(B*B+z*z)*Df(Z*Z+$*$)))/2),U=Df(I[0]*I[0]+I[1]*I[1]);A=Ff(S,(u-U)/(G-1)),M=Ff(S,(f-U)/(G+1))}}k>Bf?M>Bf?(g=Kf(L,D,j,O,f,M,m),y=Kf(P,F,E,R,f,M,m),a.moveTo(g.cx+g.x01,g.cy+g.y01),M<S?a.arc(g.cx,g.cy,M,Rf(g.y01,g.x01),Rf(y.y01,y.x01),!m):(a.arc(g.cx,g.cy,M,Rf(g.y01,g.x01),Rf(g.y11,g.x11),!m),a.arc(0,0,f,Rf(g.cy+g.y11,g.cx+g.x11),Rf(y.cy+y.y11,y.cx+y.x11),!m),a.arc(y.cx,y.cy,M,Rf(y.y11,y.x11),Rf(y.y01,y.x01),!m))):(a.moveTo(j,O),a.arc(0,0,f,v,b,!m)):a.moveTo(j,O),u>Bf&&x>Bf?A>Bf?(g=Kf(E,R,P,F,u,-A,m),y=Kf(j,O,L,D,u,-A,m),a.lineTo(g.cx+g.x01,g.cy+g.y01),A<S?a.arc(g.cx,g.cy,A,Rf(g.y01,g.x01),Rf(y.y01,y.x01),!m):(a.arc(g.cx,g.cy,A,Rf(g.y01,g.x01),Rf(g.y11,g.x11),!m),a.arc(0,0,u,Rf(g.cy+g.y11,g.cx+g.x11),Rf(y.cy+y.y11,y.cx+y.x11),m),a.arc(y.cx,y.cy,A,Rf(y.y11,y.x11),Rf(y.y01,y.x01),!m))):a.arc(0,0,u,w,_,m):a.lineTo(E,R)}else a.moveTo(0,0);if(a.closePath(),l)return a=null,l+""||null}return l.centroid=function(){var n=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,r=(+o.apply(this,arguments)+ +i.apply(this,arguments))/2-zf/2;return[If(r)*n,Lf(r)*n]},l.innerRadius=function(e){return arguments.length?(t="function"==typeof e?e:Of(+e),l):t},l.outerRadius=function(t){return arguments.length?(e="function"==typeof t?t:Of(+t),l):e},l.cornerRadius=function(t){return arguments.length?(n="function"==typeof t?t:Of(+t),l):n},l.padRadius=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Of(+t),l):r},l.startAngle=function(t){return arguments.length?(o="function"==typeof t?t:Of(+t),l):o},l.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:Of(+t),l):i},l.padAngle=function(t){return arguments.length?(s="function"==typeof t?t:Of(+t),l):s},l.context=function(t){return arguments.length?(a=null==t?null:t,l):a},l}var td=Array.prototype.slice;function ed(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function nd(t){this._context=t}function rd(t){return new nd(t)}function od(t){return t[0]}function id(t){return t[1]}function sd(t,e){var n=Of(!0),r=null,o=rd,i=null;function s(s){var a,l,c,u=(s=ed(s)).length,f=!1;for(null==r&&(i=o(c=lr())),a=0;a<=u;++a)!(a<u&&n(l=s[a],a,s))===f&&((f=!f)?i.lineStart():i.lineEnd()),f&&i.point(+t(l,a,s),+e(l,a,s));if(c)return i=null,c+""||null}return t="function"==typeof t?t:void 0===t?od:Of(t),e="function"==typeof e?e:void 0===e?id:Of(e),s.x=function(e){return arguments.length?(t="function"==typeof e?e:Of(+e),s):t},s.y=function(t){return arguments.length?(e="function"==typeof t?t:Of(+t),s):e},s.defined=function(t){return arguments.length?(n="function"==typeof t?t:Of(!!t),s):n},s.curve=function(t){return arguments.length?(o=t,null!=r&&(i=o(r)),s):o},s.context=function(t){return arguments.length?(null==t?r=i=null:i=o(r=t),s):r},s}function ad(t,e,n){var r=null,o=Of(!0),i=null,s=rd,a=null;function l(l){var c,u,f,d,h,p=(l=ed(l)).length,m=!1,g=new Array(p),y=new Array(p);for(null==i&&(a=s(h=lr())),c=0;c<=p;++c){if(!(c<p&&o(d=l[c],c,l))===m)if(m=!m)u=c,a.areaStart(),a.lineStart();else{for(a.lineEnd(),a.lineStart(),f=c-1;f>=u;--f)a.point(g[f],y[f]);a.lineEnd(),a.areaEnd()}m&&(g[c]=+t(d,c,l),y[c]=+e(d,c,l),a.point(r?+r(d,c,l):g[c],n?+n(d,c,l):y[c]))}if(h)return a=null,h+""||null}function c(){return sd().defined(o).curve(s).context(i)}return t="function"==typeof t?t:void 0===t?od:Of(+t),e="function"==typeof e?e:Of(void 0===e?0:+e),n="function"==typeof n?n:void 0===n?id:Of(+n),l.x=function(e){return arguments.length?(t="function"==typeof e?e:Of(+e),r=null,l):t},l.x0=function(e){return arguments.length?(t="function"==typeof e?e:Of(+e),l):t},l.x1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Of(+t),l):r},l.y=function(t){return arguments.length?(e="function"==typeof t?t:Of(+t),n=null,l):e},l.y0=function(t){return arguments.length?(e="function"==typeof t?t:Of(+t),l):e},l.y1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:Of(+t),l):n},l.lineX0=l.lineY0=function(){return c().x(t).y(e)},l.lineY1=function(){return c().x(t).y(n)},l.lineX1=function(){return c().x(r).y(e)},l.defined=function(t){return arguments.length?(o="function"==typeof t?t:Of(!!t),l):o},l.curve=function(t){return arguments.length?(s=t,null!=i&&(a=s(i)),l):s},l.context=function(t){return arguments.length?(null==t?i=a=null:a=s(i=t),l):i},l}function ld(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function cd(t){return t}function ud(){var t=cd,e=ld,n=null,r=Of(0),o=Of($f),i=Of(0);function s(s){var a,l,c,u,f,d=(s=ed(s)).length,h=0,p=new Array(d),m=new Array(d),g=+r.apply(this,arguments),y=Math.min($f,Math.max(-$f,o.apply(this,arguments)-g)),v=Math.min(Math.abs(y)/d,i.apply(this,arguments)),b=v*(y<0?-1:1);for(a=0;a<d;++a)(f=m[p[a]=a]=+t(s[a],a,s))>0&&(h+=f);for(null!=e?p.sort((function(t,n){return e(m[t],m[n])})):null!=n&&p.sort((function(t,e){return n(s[t],s[e])})),a=0,c=h?(y-d*b)/h:0;a<d;++a,g=u)l=p[a],u=g+((f=m[l])>0?f*c:0)+b,m[l]={data:s[l],index:a,value:f,startAngle:g,endAngle:u,padAngle:v};return m}return s.value=function(e){return arguments.length?(t="function"==typeof e?e:Of(+e),s):t},s.sortValues=function(t){return arguments.length?(e=t,n=null,s):e},s.sort=function(t){return arguments.length?(n=t,e=null,s):n},s.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:Of(+t),s):r},s.endAngle=function(t){return arguments.length?(o="function"==typeof t?t:Of(+t),s):o},s.padAngle=function(t){return arguments.length?(i="function"==typeof t?t:Of(+t),s):i},s}nd.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}};var fd=hd(rd);function dd(t){this._curve=t}function hd(t){function e(e){return new dd(t(e))}return e._curve=t,e}function pd(t){var e=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?e(hd(t)):e()._curve},t}function md(){return pd(sd().curve(fd))}function gd(){var t=ad().curve(fd),e=t.curve,n=t.lineX0,r=t.lineX1,o=t.lineY0,i=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return pd(n())},delete t.lineX0,t.lineEndAngle=function(){return pd(r())},delete t.lineX1,t.lineInnerRadius=function(){return pd(o())},delete t.lineY0,t.lineOuterRadius=function(){return pd(i())},delete t.lineY1,t.curve=function(t){return arguments.length?e(hd(t)):e()._curve},t}function yd(t,e){return[(e=+e)*Math.cos(t-=Math.PI/2),e*Math.sin(t)]}dd.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,e){this._curve.point(e*Math.sin(t),e*-Math.cos(t))}};class vd{constructor(t,e){this._context=t,this._x=e}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line}point(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+t)/2,this._y0,this._x0,e,t,e):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+e)/2,t,this._y0,t,e)}this._x0=t,this._y0=e}}class bd{constructor(t){this._context=t}lineStart(){this._point=0}lineEnd(){}point(t,e){if(t=+t,e=+e,0==this._point++)this._x0=t,this._y0=e;else{const n=yd(this._x0,this._y0),r=yd(this._x0,this._y0=(this._y0+e)/2),o=yd(t,this._y0),i=yd(t,e);this._context.moveTo(...n),this._context.bezierCurveTo(...r,...o,...i)}}}function _d(t){return new vd(t,!0)}function wd(t){return new vd(t,!1)}function xd(t){return new bd(t)}function kd(t){return t.source}function qd(t){return t.target}function Nd(t){let e=kd,n=qd,r=od,o=id,i=null,s=null;function a(){let a;const l=td.call(arguments),c=e.apply(this,l),u=n.apply(this,l);if(null==i&&(s=t(a=lr())),s.lineStart(),l[0]=c,s.point(+r.apply(this,l),+o.apply(this,l)),l[0]=u,s.point(+r.apply(this,l),+o.apply(this,l)),s.lineEnd(),a)return s=null,a+""||null}return a.source=function(t){return arguments.length?(e=t,a):e},a.target=function(t){return arguments.length?(n=t,a):n},a.x=function(t){return arguments.length?(r="function"==typeof t?t:Of(+t),a):r},a.y=function(t){return arguments.length?(o="function"==typeof t?t:Of(+t),a):o},a.context=function(e){return arguments.length?(null==e?i=s=null:s=t(i=e),a):i},a}function Sd(){return Nd(_d)}function Ad(){return Nd(wd)}function Md(){const t=Nd(xd);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t}const Td=Df(3),Cd={draw(t,e){const n=.59436*Df(e+Ff(e/28,.75)),r=n/2,o=r*Td;t.moveTo(0,n),t.lineTo(0,-n),t.moveTo(-o,-r),t.lineTo(o,r),t.moveTo(-o,r),t.lineTo(o,-r)}},jd={draw(t,e){const n=Df(e/zf);t.moveTo(n,0),t.arc(0,0,n,0,$f)}},Od={draw(t,e){const n=Df(e/5)/2;t.moveTo(-3*n,-n),t.lineTo(-n,-n),t.lineTo(-n,-3*n),t.lineTo(n,-3*n),t.lineTo(n,-n),t.lineTo(3*n,-n),t.lineTo(3*n,n),t.lineTo(n,n),t.lineTo(n,3*n),t.lineTo(-n,3*n),t.lineTo(-n,n),t.lineTo(-3*n,n),t.closePath()}},Ed=Df(1/3),Rd=2*Ed,Id={draw(t,e){const n=Df(e/Rd),r=n*Ed;t.moveTo(0,-n),t.lineTo(r,0),t.lineTo(0,n),t.lineTo(-r,0),t.closePath()}},Pd={draw(t,e){const n=.62625*Df(e);t.moveTo(0,-n),t.lineTo(n,0),t.lineTo(0,n),t.lineTo(-n,0),t.closePath()}},Fd={draw(t,e){const n=.87559*Df(e-Ff(e/7,2));t.moveTo(-n,0),t.lineTo(n,0),t.moveTo(0,n),t.lineTo(0,-n)}},Ld={draw(t,e){const n=Df(e),r=-n/2;t.rect(r,r,n,n)}},Dd={draw(t,e){const n=.4431*Df(e);t.moveTo(n,n),t.lineTo(n,-n),t.lineTo(-n,-n),t.lineTo(-n,n),t.closePath()}},Bd=Lf(zf/10)/Lf(7*zf/10),zd=Lf($f/10)*Bd,Zd=-If($f/10)*Bd,$d={draw(t,e){const n=Df(.8908130915292852*e),r=zd*n,o=Zd*n;t.moveTo(0,-n),t.lineTo(r,o);for(let e=1;e<5;++e){const i=$f*e/5,s=If(i),a=Lf(i);t.lineTo(a*n,-s*n),t.lineTo(s*r-a*o,a*r+s*o)}t.closePath()}},Gd=Df(3),Ud={draw(t,e){const n=-Df(e/(3*Gd));t.moveTo(0,2*n),t.lineTo(-Gd*n,-n),t.lineTo(Gd*n,-n),t.closePath()}},Hd=Df(3),Wd={draw(t,e){const n=.6824*Df(e),r=n/2,o=n*Hd/2;t.moveTo(0,-n),t.lineTo(o,r),t.lineTo(-o,r),t.closePath()}},Jd=-.5,Vd=Df(3)/2,Yd=1/Df(12),Qd=3*(Yd/2+1),Kd={draw(t,e){const n=Df(e/Qd),r=n/2,o=n*Yd,i=r,s=n*Yd+n,a=-i,l=s;t.moveTo(r,o),t.lineTo(i,s),t.lineTo(a,l),t.lineTo(Jd*r-Vd*o,Vd*r+Jd*o),t.lineTo(Jd*i-Vd*s,Vd*i+Jd*s),t.lineTo(Jd*a-Vd*l,Vd*a+Jd*l),t.lineTo(Jd*r+Vd*o,Jd*o-Vd*r),t.lineTo(Jd*i+Vd*s,Jd*s-Vd*i),t.lineTo(Jd*a+Vd*l,Jd*l-Vd*a),t.closePath()}},Xd={draw(t,e){const n=.6189*Df(e-Ff(e/6,1.7));t.moveTo(-n,-n),t.lineTo(n,n),t.moveTo(-n,n),t.lineTo(n,-n)}},th=[jd,Od,Id,Ld,$d,Ud,Kd],eh=[jd,Fd,Xd,Wd,Cd,Dd,Pd];function nh(t,e){let n=null;function r(){let r;if(n||(n=r=lr()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),r)return n=null,r+""||null}return t="function"==typeof t?t:Of(t||jd),e="function"==typeof e?e:Of(void 0===e?64:+e),r.type=function(e){return arguments.length?(t="function"==typeof e?e:Of(e),r):t},r.size=function(t){return arguments.length?(e="function"==typeof t?t:Of(+t),r):e},r.context=function(t){return arguments.length?(n=null==t?null:t,r):n},r}function rh(){}function oh(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function ih(t){this._context=t}function sh(t){return new ih(t)}function ah(t){this._context=t}function lh(t){return new ah(t)}function ch(t){this._context=t}function uh(t){return new ch(t)}function fh(t,e){this._basis=new ih(t),this._beta=e}ih.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:oh(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:oh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},ah.prototype={areaStart:rh,areaEnd:rh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:oh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},ch.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:oh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},fh.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,n=t.length-1;if(n>0)for(var r,o=t[0],i=e[0],s=t[n]-o,a=e[n]-i,l=-1;++l<=n;)r=l/n,this._basis.point(this._beta*t[l]+(1-this._beta)*(o+r*s),this._beta*e[l]+(1-this._beta)*(i+r*a));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};const dh=function t(e){function n(t){return 1===e?new ih(t):new fh(t,e)}return n.beta=function(e){return t(+e)},n}(.85);function hh(t,e,n){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-n),t._x2,t._y2)}function ph(t,e){this._context=t,this._k=(1-e)/6}ph.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:hh(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:hh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const mh=function t(e){function n(t){return new ph(t,e)}return n.tension=function(e){return t(+e)},n}(0);function gh(t,e){this._context=t,this._k=(1-e)/6}gh.prototype={areaStart:rh,areaEnd:rh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:hh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const yh=function t(e){function n(t){return new gh(t,e)}return n.tension=function(e){return t(+e)},n}(0);function vh(t,e){this._context=t,this._k=(1-e)/6}vh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:hh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const bh=function t(e){function n(t){return new vh(t,e)}return n.tension=function(e){return t(+e)},n}(0);function _h(t,e,n){var r=t._x1,o=t._y1,i=t._x2,s=t._y2;if(t._l01_a>Bf){var a=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,l=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*a-t._x0*t._l12_2a+t._x2*t._l01_2a)/l,o=(o*a-t._y0*t._l12_2a+t._y2*t._l01_2a)/l}if(t._l23_a>Bf){var c=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,u=3*t._l23_a*(t._l23_a+t._l12_a);i=(i*c+t._x1*t._l23_2a-e*t._l12_2a)/u,s=(s*c+t._y1*t._l23_2a-n*t._l12_2a)/u}t._context.bezierCurveTo(r,o,i,s,t._x2,t._y2)}function wh(t,e){this._context=t,this._alpha=e}wh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:_h(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const xh=function t(e){function n(t){return e?new wh(t,e):new ph(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function kh(t,e){this._context=t,this._alpha=e}kh.prototype={areaStart:rh,areaEnd:rh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:_h(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const qh=function t(e){function n(t){return e?new kh(t,e):new gh(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function Nh(t,e){this._context=t,this._alpha=e}Nh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:_h(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Sh=function t(e){function n(t){return e?new Nh(t,e):new vh(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function Ah(t){this._context=t}function Mh(t){return new Ah(t)}function Th(t){return t<0?-1:1}function Ch(t,e,n){var r=t._x1-t._x0,o=e-t._x1,i=(t._y1-t._y0)/(r||o<0&&-0),s=(n-t._y1)/(o||r<0&&-0),a=(i*o+s*r)/(r+o);return(Th(i)+Th(s))*Math.min(Math.abs(i),Math.abs(s),.5*Math.abs(a))||0}function jh(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function Oh(t,e,n){var r=t._x0,o=t._y0,i=t._x1,s=t._y1,a=(i-r)/3;t._context.bezierCurveTo(r+a,o+a*e,i-a,s-a*n,i,s)}function Eh(t){this._context=t}function Rh(t){this._context=new Ih(t)}function Ih(t){this._context=t}function Ph(t){return new Eh(t)}function Fh(t){return new Rh(t)}function Lh(t){this._context=t}function Dh(t){var e,n,r=t.length-1,o=new Array(r),i=new Array(r),s=new Array(r);for(o[0]=0,i[0]=2,s[0]=t[0]+2*t[1],e=1;e<r-1;++e)o[e]=1,i[e]=4,s[e]=4*t[e]+2*t[e+1];for(o[r-1]=2,i[r-1]=7,s[r-1]=8*t[r-1]+t[r],e=1;e<r;++e)n=o[e]/i[e-1],i[e]-=n,s[e]-=n*s[e-1];for(o[r-1]=s[r-1]/i[r-1],e=r-2;e>=0;--e)o[e]=(s[e]-o[e+1])/i[e];for(i[r-1]=(t[r]+o[r-1])/2,e=0;e<r-1;++e)i[e]=2*t[e+1]-o[e+1];return[o,i]}function Bh(t){return new Lh(t)}function zh(t,e){this._context=t,this._t=e}function Zh(t){return new zh(t,.5)}function $h(t){return new zh(t,0)}function Gh(t){return new zh(t,1)}function Uh(t,e){if((o=t.length)>1)for(var n,r,o,i=1,s=t[e[0]],a=s.length;i<o;++i)for(r=s,s=t[e[i]],n=0;n<a;++n)s[n][1]+=s[n][0]=isNaN(r[n][1])?r[n][0]:r[n][1]}function Hh(t){for(var e=t.length,n=new Array(e);--e>=0;)n[e]=e;return n}function Wh(t,e){return t[e]}function Jh(t){const e=[];return e.key=t,e}function Vh(){var t=Of([]),e=Hh,n=Uh,r=Wh;function o(o){var i,s,a=Array.from(t.apply(this,arguments),Jh),l=a.length,c=-1;for(const t of o)for(i=0,++c;i<l;++i)(a[i][c]=[0,+r(t,a[i].key,c,o)]).data=t;for(i=0,s=ed(e(a));i<l;++i)a[s[i]].index=i;return n(a,s),a}return o.keys=function(e){return arguments.length?(t="function"==typeof e?e:Of(Array.from(e)),o):t},o.value=function(t){return arguments.length?(r="function"==typeof t?t:Of(+t),o):r},o.order=function(t){return arguments.length?(e=null==t?Hh:"function"==typeof t?t:Of(Array.from(t)),o):e},o.offset=function(t){return arguments.length?(n=null==t?Uh:t,o):n},o}function Yh(t,e){if((r=t.length)>0){for(var n,r,o,i=0,s=t[0].length;i<s;++i){for(o=n=0;n<r;++n)o+=t[n][i][1]||0;if(o)for(n=0;n<r;++n)t[n][i][1]/=o}Uh(t,e)}}function Qh(t,e){if((a=t.length)>0)for(var n,r,o,i,s,a,l=0,c=t[e[0]].length;l<c;++l)for(i=s=0,n=0;n<a;++n)(o=(r=t[e[n]][l])[1]-r[0])>0?(r[0]=i,r[1]=i+=o):o<0?(r[1]=s,r[0]=s+=o):(r[0]=0,r[1]=o)}function Kh(t,e){if((n=t.length)>0){for(var n,r=0,o=t[e[0]],i=o.length;r<i;++r){for(var s=0,a=0;s<n;++s)a+=t[s][r][1]||0;o[r][1]+=o[r][0]=-a/2}Uh(t,e)}}function Xh(t,e){if((o=t.length)>0&&(r=(n=t[e[0]]).length)>0){for(var n,r,o,i=0,s=1;s<r;++s){for(var a=0,l=0,c=0;a<o;++a){for(var u=t[e[a]],f=u[s][1]||0,d=(f-(u[s-1][1]||0))/2,h=0;h<a;++h){var p=t[e[h]];d+=(p[s][1]||0)-(p[s-1][1]||0)}l+=f,c+=d*f}n[s-1][1]+=n[s-1][0]=i,l&&(i-=c/l)}n[s-1][1]+=n[s-1][0]=i,Uh(t,e)}}function tp(t){var e=t.map(ep);return Hh(t).sort((function(t,n){return e[t]-e[n]}))}function ep(t){for(var e,n=-1,r=0,o=t.length,i=-1/0;++n<o;)(e=+t[n][1])>i&&(i=e,r=n);return r}function np(t){var e=t.map(rp);return Hh(t).sort((function(t,n){return e[t]-e[n]}))}function rp(t){for(var e,n=0,r=-1,o=t.length;++r<o;)(e=+t[r][1])&&(n+=e);return n}function op(t){return np(t).reverse()}function ip(t){var e,n,r=t.length,o=t.map(rp),i=tp(t),s=0,a=0,l=[],c=[];for(e=0;e<r;++e)n=i[e],s<a?(s+=o[n],l.push(n)):(a+=o[n],c.push(n));return c.reverse().concat(l)}function sp(t){return Hh(t).reverse()}Ah.prototype={areaStart:rh,areaEnd:rh,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}},Eh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Oh(this,this._t0,jh(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(e=+e,(t=+t)!==this._x1||e!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,Oh(this,jh(this,n=Ch(this,t,e)),n);break;default:Oh(this,this._t0,n=Ch(this,t,e))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}},(Rh.prototype=Object.create(Eh.prototype)).point=function(t,e){Eh.prototype.point.call(this,e,t)},Ih.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,n,r,o,i){this._context.bezierCurveTo(e,t,r,n,i,o)}},Lh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,n=t.length;if(n)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),2===n)this._context.lineTo(t[1],e[1]);else for(var r=Dh(t),o=Dh(e),i=0,s=1;s<n;++i,++s)this._context.bezierCurveTo(r[0][i],o[0][i],r[1][i],o[1][i],t[s],e[s]);(this._line||0!==this._line&&1===n)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,e){this._x.push(+t),this._y.push(+e)}},zh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var ap=n(3606),lp=n(8383),cp=n(1343),up=n(2991),fp=n(6596),dp=n(8467),hp=n(6018),pp=n(7905),mp=n(2311),gp=n(8593),yp=n(8927),vp=n(7445),bp=n(1887),_p=n(7351),wp=n(4552),xp=n(7150),kp=n(1852),qp=n(3015),Np="%Y-%m-%dT%H:%M:%S.%LZ";const Sp=Date.prototype.toISOString?function(t){return t.toISOString()}:(0,kp.g0)(Np);var Ap=+new Date("2000-01-01T00:00:00.000Z")?function(t){var e=new Date(t);return isNaN(e)?null:e}:(0,kp.wp)(Np);const Mp=Ap;function Tp(t,e,n){var r=new se,o=e;return null==e?(r.restart(t,e,n),r):(r._restart=r.restart,r.restart=function(t,e,n){e=+e,n=null==n?oe():+n,r._restart((function i(s){s+=o,r._restart(i,o+=e,n),t(s)}),e,n)},r.restart(t,e,n),r)}var Cp=n(6564);const jp=t=>()=>t;function Op(t,{sourceEvent:e,target:n,transform:r,dispatch:o}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:o}})}function Ep(t,e,n){this.k=t,this.x=e,this.y=n}Ep.prototype={constructor:Ep,scale:function(t){return 1===t?this:new Ep(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Ep(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Rp=new Ep(1,0,0);function Ip(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Rp;return t.__zoom}function Pp(t){t.stopImmediatePropagation()}function Fp(t){t.preventDefault(),t.stopImmediatePropagation()}function Lp(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Dp(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Bp(){return this.__zoom||Rp}function zp(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function Zp(){return navigator.maxTouchPoints||"ontouchstart"in this}function $p(t,e,n){var r=t.invertX(e[0][0])-n[0][0],o=t.invertX(e[1][0])-n[1][0],i=t.invertY(e[0][1])-n[0][1],s=t.invertY(e[1][1])-n[1][1];return t.translate(o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o),s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s))}function Gp(){var t,e,n,r=Lp,o=Dp,i=$p,s=zp,a=Zp,l=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],u=250,f=Cp.Z,d=x("start","zoom","end"),h=500,p=0,m=10;function g(t){t.property("__zoom",Bp).on("wheel.zoom",q,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",S).filter(a).on("touchstart.zoom",A).on("touchmove.zoom",M).on("touchend.zoom touchcancel.zoom",T).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(l[0],Math.min(l[1],e)))===t.k?t:new Ep(e,t.x,t.y)}function v(t,e,n){var r=e[0]-n[0]*t.k,o=e[1]-n[1]*t.k;return r===t.x&&o===t.y?t:new Ep(t.k,r,o)}function b(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function _(t,e,n,r){t.on("start.zoom",(function(){w(this,arguments).event(r).start()})).on("interrupt.zoom end.zoom",(function(){w(this,arguments).event(r).end()})).tween("zoom",(function(){var t=this,i=arguments,s=w(t,i).event(r),a=o.apply(t,i),l=null==n?b(a):"function"==typeof n?n.apply(t,i):n,c=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),u=t.__zoom,d="function"==typeof e?e.apply(t,i):e,h=f(u.invert(l).concat(c/u.k),d.invert(l).concat(c/d.k));return function(t){if(1===t)t=d;else{var e=h(t),n=c/e[2];t=new Ep(n,l[0]-e[0]*n,l[1]-e[1]*n)}s.zoom(null,t)}}))}function w(t,e,n){return!n&&t.__zooming||new k(t,e)}function k(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=o.apply(t,e),this.taps=0}function q(t,...e){if(r.apply(this,arguments)){var n=w(this,e).event(t),o=this.__zoom,a=Math.max(l[0],Math.min(l[1],o.k*Math.pow(2,s.apply(this,arguments)))),u=Wt(t);if(n.wheel)n.mouse[0][0]===u[0]&&n.mouse[0][1]===u[1]||(n.mouse[1]=o.invert(n.mouse[0]=u)),clearTimeout(n.wheel);else{if(o.k===a)return;n.mouse=[u,o.invert(u)],be(this),n.start()}Fp(t),n.wheel=setTimeout(f,150),n.zoom("mouse",i(v(y(o,a),n.mouse[0],n.mouse[1]),n.extent,c))}function f(){n.wheel=null,n.end()}}function N(t,...e){if(!n&&r.apply(this,arguments)){var o=t.currentTarget,s=w(this,e,!0).event(t),a=Lt(t.view).on("mousemove.zoom",d,!0).on("mouseup.zoom",h,!0),l=Wt(t,o),u=t.clientX,f=t.clientY;$t(t.view),Pp(t),s.mouse=[l,this.__zoom.invert(l)],be(this),s.start()}function d(t){if(Fp(t),!s.moved){var e=t.clientX-u,n=t.clientY-f;s.moved=e*e+n*n>p}s.event(t).zoom("mouse",i(v(s.that.__zoom,s.mouse[0]=Wt(t,o),s.mouse[1]),s.extent,c))}function h(t){a.on("mousemove.zoom mouseup.zoom",null),Gt(t.view,s.moved),Fp(t),s.event(t).end()}}function S(t,...e){if(r.apply(this,arguments)){var n=this.__zoom,s=Wt(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(s),l=n.k*(t.shiftKey?.5:2),f=i(v(y(n,l),s,a),o.apply(this,e),c);Fp(t),u>0?Lt(this).transition().duration(u).call(_,f,s,t):Lt(this).call(g.transform,f,s,t)}}function A(n,...o){if(r.apply(this,arguments)){var i,s,a,l,c=n.touches,u=c.length,f=w(this,o,n.changedTouches.length===u).event(n);for(Pp(n),s=0;s<u;++s)l=[l=Wt(a=c[s],this),this.__zoom.invert(l),a.identifier],f.touch0?f.touch1||f.touch0[2]===l[2]||(f.touch1=l,f.taps=0):(f.touch0=l,i=!0,f.taps=1+!!t);t&&(t=clearTimeout(t)),i&&(f.taps<2&&(e=l[0],t=setTimeout((function(){t=null}),h)),be(this),f.start())}}function M(t,...e){if(this.__zooming){var n,r,o,s,a=w(this,e).event(t),l=t.changedTouches,u=l.length;for(Fp(t),n=0;n<u;++n)o=Wt(r=l[n],this),a.touch0&&a.touch0[2]===r.identifier?a.touch0[0]=o:a.touch1&&a.touch1[2]===r.identifier&&(a.touch1[0]=o);if(r=a.that.__zoom,a.touch1){var f=a.touch0[0],d=a.touch0[1],h=a.touch1[0],p=a.touch1[1],m=(m=h[0]-f[0])*m+(m=h[1]-f[1])*m,g=(g=p[0]-d[0])*g+(g=p[1]-d[1])*g;r=y(r,Math.sqrt(m/g)),o=[(f[0]+h[0])/2,(f[1]+h[1])/2],s=[(d[0]+p[0])/2,(d[1]+p[1])/2]}else{if(!a.touch0)return;o=a.touch0[0],s=a.touch0[1]}a.zoom("touch",i(v(r,o,s),a.extent,c))}}function T(t,...r){if(this.__zooming){var o,i,s=w(this,r).event(t),a=t.changedTouches,l=a.length;for(Pp(t),n&&clearTimeout(n),n=setTimeout((function(){n=null}),h),o=0;o<l;++o)i=a[o],s.touch0&&s.touch0[2]===i.identifier?delete s.touch0:s.touch1&&s.touch1[2]===i.identifier&&delete s.touch1;if(s.touch1&&!s.touch0&&(s.touch0=s.touch1,delete s.touch1),s.touch0)s.touch0[1]=this.__zoom.invert(s.touch0[0]);else if(s.end(),2===s.taps&&(i=Wt(i,this),Math.hypot(e[0]-i[0],e[1]-i[1])<m)){var c=Lt(this).on("dblclick.zoom");c&&c.apply(this,arguments)}}}return g.transform=function(t,e,n,r){var o=t.selection?t.selection():t;o.property("__zoom",Bp),t!==o?_(t,e,n,r):o.interrupt().each((function(){w(this,arguments).event(r).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()}))},g.scaleBy=function(t,e,n,r){g.scaleTo(t,(function(){var t=this.__zoom.k,n="function"==typeof e?e.apply(this,arguments):e;return t*n}),n,r)},g.scaleTo=function(t,e,n,r){g.transform(t,(function(){var t=o.apply(this,arguments),r=this.__zoom,s=null==n?b(t):"function"==typeof n?n.apply(this,arguments):n,a=r.invert(s),l="function"==typeof e?e.apply(this,arguments):e;return i(v(y(r,l),s,a),t,c)}),n,r)},g.translateBy=function(t,e,n,r){g.transform(t,(function(){return i(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof n?n.apply(this,arguments):n),o.apply(this,arguments),c)}),null,r)},g.translateTo=function(t,e,n,r,s){g.transform(t,(function(){var t=o.apply(this,arguments),s=this.__zoom,a=null==r?b(t):"function"==typeof r?r.apply(this,arguments):r;return i(Rp.translate(a[0],a[1]).scale(s.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof n?-n.apply(this,arguments):-n),t,c)}),r,s)},k.prototype={event:function(t){return t&&(this.sourceEvent=t),this},start:function(){return 1==++this.active&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(t,e){return this.mouse&&"mouse"!==t&&(this.mouse[1]=e.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=e.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=e.invert(this.touch1[0])),this.that.__zoom=e,this.emit("zoom"),this},end:function(){return 0==--this.active&&(delete this.that.__zooming,this.emit("end")),this},emit:function(t){var e=Lt(this.that).datum();d.call(t,this.that,new Op(t,{sourceEvent:this.sourceEvent,target:g,type:t,transform:this.that.__zoom,dispatch:d}),e)}},g.wheelDelta=function(t){return arguments.length?(s="function"==typeof t?t:jp(+t),g):s},g.filter=function(t){return arguments.length?(r="function"==typeof t?t:jp(!!t),g):r},g.touchable=function(t){return arguments.length?(a="function"==typeof t?t:jp(!!t),g):a},g.extent=function(t){return arguments.length?(o="function"==typeof t?t:jp([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),g):o},g.scaleExtent=function(t){return arguments.length?(l[0]=+t[0],l[1]=+t[1],g):[l[0],l[1]]},g.translateExtent=function(t){return arguments.length?(c[0][0]=+t[0][0],c[1][0]=+t[1][0],c[0][1]=+t[0][1],c[1][1]=+t[1][1],g):[[c[0][0],c[0][1]],[c[1][0],c[1][1]]]},g.constrain=function(t){return arguments.length?(i=t,g):i},g.duration=function(t){return arguments.length?(u=+t,g):u},g.interpolate=function(t){return arguments.length?(f=t,g):f},g.on=function(){var t=d.on.apply(d,arguments);return t===d?g:t},g.clickDistance=function(t){return arguments.length?(p=(t=+t)*t,g):Math.sqrt(p)},g.tapDistance=function(t){return arguments.length?(m=+t,g):m},g}Ip.prototype=Ep.prototype},8828:(t,e,n)=>{"use strict";n.d(e,{H:()=>o,L:()=>r});class r extends Map{constructor(t,e=l){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(i(this,t))}has(t){return super.has(i(this,t))}set(t,e){return super.set(s(this,t),e)}delete(t){return super.delete(a(this,t))}}class o extends Set{constructor(t,e=l){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const e of t)this.add(e)}has(t){return super.has(i(this,t))}add(t){return super.add(s(this,t))}delete(t){return super.delete(a(this,t))}}function i({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function s({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}function a({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}function l(t){return null!==t&&"object"==typeof t?t.valueOf():t}}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};r(9699)})();
|
|
1
|
+
(()=>{var t={4052:(t,e,n)=>{"use strict";n.r(e),n.d(e,{schemeCategory20:()=>r});const r=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"]},6733:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for CNV";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");return-1==o?"gene missing from header":(n[o]="gene",o=r("cnv"),-1==o?"CNV missing from header":(n[o]="cnv",o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.cnv.header=n,e.cnv.loaded=!0,!1))}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.cnv.header.length;t++)s[n.cnv.header[t]]=i[t];if(!s.gene)return void n.cnv.badlines.push([t,"missing gene",i]);if(!s.cnv)return void n.cnv.badlines.push([t,"missing cnv value",i]);switch(s.cnv.toLowerCase()){case"amplification":case"gain":s.class=r.mclasscnvgain;break;case"deletion":case"loss":s.class=r.mclasscnvloss;break;case"loh":s.class=r.mclasscnvloh;break;default:n.cnv.badlines.push([t,"invalid cnv value: "+s.cnv,i]),s.class=null}if(!s.class)return;if(o.parsesample(s,n,t,i,n.cnv.badlines))return;s.dt=r.dtcnv,n.good++;const a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}},5558:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for intragenic deletion";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";if(n[o]="isoform",o=r("rnaposition"),-1!=o){if(n[o]="rnaposition",o=r("rnadellength"),-1==o)return"rnadellength is required when rnaPosition is used";n[o]="rnadellength"}if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("chr_start"),-1==o)return"chr_start is required when chr is used";if(n[o]="chrpos1",o=r("chr_stop"),-1==o)return"chr_stop is required when chr is used";n[o]="chrpos2"}return o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.del.header=n,e.del.loaded=!0,!1}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.del.header.length&&null!=i[t];t++)s[n.del.header[t]]=i[t];if(s.gene){if(s.rnaposition){let e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid rnaPosition value",i]);if(s.rnaposition=e,!s.rnadellength)return void n.del.badlines.push([t,"missing rnaDellength value",i]);if(e=Number.parseInt(s.rnadellength),Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid rnaDellength value",i]);s.rnadellength=e}if(s.chr){let e=Number.parseInt(s.chrpos1);if(Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid chr_start value",i]);if(s.chrpos1=e,e=Number.parseInt(s.chrpos2),Number.isNaN(e)||e<0)return void n.del.badlines.push([t,"invalid chr_stop value",i]);s.chrpos2=e}if(!o.parsesample(s,n,t,i,n.del.badlines)){s.dt=r.dtdel,s.class=r.mclassdel,s.mname="DEL",n.good++;var a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}}else n.del.badlines.push([t,"missing gene",i])}},3602:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for ITD";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";if(n[o]="isoform",o=r("rnaposition"),-1!=o){if(n[o]="rnaposition",o=r("rnaduplength"),-1==o)return"rnaduplength is required when rnaposition is present";n[o]="rnaduplength"}if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("chr_start"),-1==o)return"chr_start is required when chr is present";if(n[o]="chrpos1",o=r("chr_stop"),-1==o)return"chr_stop is required when chr is present";n[o]="chrpos2"}return o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.itd.header=n,e.itd.loaded=!0,!1}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.itd.header.length&&null!=i[t];t++)s[n.itd.header[t]]=i[t];if(s.gene){if(s.rnaposition){let e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid rnaPosition value",i]);if(s.rnaposition=e,!s.rnaduplength)return void n.itd.badlines.push([t,"missing rnaDuplength value",i]);if(e=Number.parseInt(s.rnaduplength),Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid rnaDuplength value",i]);s.rnaduplength=e}if(s.chr){let e=Number.parseInt(s.chrpos1);if(Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid chr_start value",i]);if(s.chrpos1=e,e=Number.parseInt(s.chrpos2),Number.isNaN(e)||e<0)return void n.itd.badlines.push([t,"invalid chr_stop value",i]);s.chrpos2=e}if(!o.parsesample(s,n,t,i,n.itd.badlines)){s.dt=r.dtitd,s.class=r.mclassitd,s.mname="ITD",n.good++;var a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}}else n.itd.badlines.push([t,"missing gene",i])}},8064:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>o,init_bulk_flag:()=>i,parsesample:()=>s});var r=n(2273);const o={};function i(t){if(!t)return null;const e={};for(const t in r.mclass)e[r.mclass[t].label.toUpperCase()]=t;return{genome:t,mclasslabel2key:e,data:{},sample2disease:{},patient2st:{},good:0,geneToUpper:!0,snv:{loaded:!1,header:null,badlines:[],missense:0,silent:0},svjson:{loaded:!1,header:null,badlines:[]},fusion:{loaded:!1,header:null,badlines:[],original:[]},sv:{loaded:!1,header:null,badlines:[],original:[]},cnv:{loaded:!1,header:null,badlines:[]},itd:{loaded:!1,header:null,badlines:[]},del:{loaded:!1,header:null,badlines:[]},truncation:{loaded:!1,header:null,badlines:[]}}}function s(t,e,n,o,i){let s=r.moriginsomatic;if(t.sampletype){switch(t.sampletype.toLowerCase()){case"relapse":s=r.moriginrelapse;break;case"germline":s=r.morigingermline}t.sample?t.patient||(t.patient=t.sample+" "+t.sampletype):t.patient&&(t.sample=t.patient+" "+t.sampletype)}else t.patient?t.sample?t.sampletype=t.sample:t.sample=t.sampletype=t.patient:t.sample&&(t.sampletype=t.sample);if(t.origin){switch(t.origin.toLowerCase()){case"r":case"relapse":s=r.moriginrelapse,t.isrim2=!0;break;case"g":case"germline":s=r.morigingermline,t.isrim1=!0;break;case"gp":case"germline pathogenic":s=r.morigingermlinepathogenic,t.isrim1=!0;break;case"gnp":case"germline nonpathogenic":case"germline non-pathogenic":s=r.morigingermlinenonpathogenic,t.isrim1=!0;break;case"s":case"somatic":case"diagnosis":s=r.moriginsomatic}}if(t.origin=s,!t.sample&&!t.patient)return;const a="no patient/individual name";if(t.patient?(e.patient2st[t.patient]||(e.patient2st[t.patient]={}),e.patient2st[t.patient][t.sampletype]=t.sample):(e.patient2st[a]||(e.patient2st[a]={}),e.patient2st[a][t.sampletype]=t.sample),t.sample&&t.disease)if(t.sample in e.sample2disease){if(t.disease!=e.sample2disease[t.sample])return e.snv.badlines.push([n,'conflict of disease types for sample "'+t.sample+'": '+t.disease+", "+e.sample2disease[t.sample],o]),!0}else e.sample2disease[t.sample]=t.disease;return!1}},5494:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for snv/indel";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("annovar_gene","annovar_sj_gene","gene","genename","gene_symbol","hugo_symbol");return-1==o?"gene missing from header":(n[o]="gene",o=r("annovar_aachange","amino_acid_change","annovar_sj_aachange","aachange","protein_change","variant"),-1==o?"amino_acid_change missing from header":(n[o]="mname",o=r("annovar_class","class","mclass","variant_class","variant_classification","annovar_sj_class"),-1==o?"variant_class missing from header":(n[o]="class",o=r("chromosome","chr"),-1==o?"chromosome missing from header":(n[o]="chr",o=r("wu_hg19_pos","start","start_position","chr_position","position"),-1==o?"start missing from header":(n[o]="pos",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o?"isoform missing from header":(n[o]="isoform",o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("quantitative_measurements"),-1!=o&&(n[o]="qmset"),o=r("mutant_reads_in_case","mutant_in_tumor","tumor_readcount_alt"),-1!=o&&(n[o]="maf_tumor_v1"),o=r("total_reads_in_case","total_in_tumor","tumor_readcount_total"),-1!=o&&(n[o]="maf_tumor_v2"),o=r("mutant_reads_in_control","mutant_in_normal","normal_readcount_alt"),-1!=o&&(n[o]="maf_normal_v1"),o=r("total_reads_in_control","total_in_normal","normal_readcount_total"),-1!=o&&(n[o]="maf_normal_v2"),o=r("cdna_change"),-1!=o&&(n[o]="cdna_change"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("cancer","disease","diagnosis"),-1!=o&&(n[o]="disease"),e.snv.header=n,e.snv.loaded=!0,!1))))))}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.snv.header.length&&null!=i[t];t++)s[n.snv.header[t]]=i[t];if(!s.gene)return void n.snv.badlines.push([t,"missing gene",i]);if("UNKNOWN"==s.gene.toUpperCase())return void n.snv.badlines.push([t,"gene name is UNKNOWN",i]);if(!s.isoform)return void n.snv.badlines.push([t,"missing isoform",i]);if(s.mname)0==s.mname.indexOf("p.")&&(s.mname=s.mname.replace(/^p\./,""));else if(s.mname=s.cdna_change,!s.mname)return void n.snv.badlines.push([t,"missing amino acid change",i]);if(!s.class)return void n.snv.badlines.push([t,"missing mutation class",i]);let a=n.mclasslabel2key[s.class.toUpperCase()];if(a)s.class=a;else{if(a=r.mclasstester(s.class),!a)return void n.snv.badlines.push([t,"wrong mutation class: "+s.class,i]);s.class=a}if(o.parsesample(s,n,t,i,n.snv.badlines))return;if(!s.chr)return void n.snv.badlines.push([t,"missing chromosome",i]);if(0!=s.chr.toLowerCase().indexOf("chr")&&(s.chr="chr"+s.chr),!s.pos)return void n.snv.badlines.push([t,"missing chromosome position",i]);const l=Number.parseInt(s.pos);if(Number.isNaN(l))return void n.snv.badlines.push([t,"invalid chromosome position",i]);if(s.pos=l-1,null!=s.maf_tumor_v2&&null!=s.maf_tumor_v1){if(""==s.maf_tumor_v2);else{let e=Number.parseInt(s.maf_tumor_v1),r=Number.parseInt(s.maf_tumor_v2);if(Number.isNaN(e)||Number.isNaN(r))return void n.snv.badlines.push([t,"invalid maf_tumor mutant and/or total read count",i]);s.maf_tumor={f:e/r,v1:e,v2:r}}delete s.maf_tumor_v1,delete s.maf_tumor_v2}if(null!=s.maf_normal_v1&&null!=s.maf_normal_v2){if(""==s.maf_normal_v2);else{let e=Number.parseInt(s.maf_normal_v1),r=Number.parseInt(s.maf_normal_v2);if(Number.isNaN(e)||Number.isNaN(r))return void n.snv.badlines.push([t,"invalid maf_normal mutant and/or total read count",i]);s.maf_normal={f:e/r,v1:e,v2:r}}delete s.maf_normal_v1,delete s.maf_normal_v2}n.good++,"M"==s.class?n.snv.missense++:"S"==s.class&&n.snv.silent++;const c=n.geneToUpper?s.gene.toUpperCase():s.gene;n.data[c]||(n.data[c]=[]),s.dt=r.dtsnvindel,n.data[c].push(s)}},6279:(t,e,n)=>{"use strict";n.r(e),n.d(e,{duplicate:()=>a,parseheader:()=>i,parseline:()=>s});var r=n(8064),o=n(2273);function i(t,e,n){const r=t.toLowerCase().split("\t");if(r.length<=1)return"invalid file header for fusions";const o=(...t)=>{for(const e of t){const t=r.indexOf(e);if(-1!=t)return t}return-1};let i=o("gene_a","gene1","genea");return-1==i?"gene_a missing from header":(r[i]="gene1",i=o("gene_b","gene2","geneb"),-1==i?"gene_b missing from header":(r[i]="gene2",i=o("chr_a","chr1","chra"),-1==i?"chr_a missing from header":(r[i]="chr1",i=o("chr_b","chr2","chrb"),-1==i?"chr_b missing from header":(r[i]="chr2",i=o("pos_a","position_a","position1","posa"),-1==i?"pos_a missing from header":(r[i]="position1",i=o("pos_b","position_b","position2","posb"),-1==i?"pos_b missing from header":(r[i]="position2",i=o("isoform_a","refseq_a","refseq1","isoform1","sv_refseqa"),-1==i?"isoform_a missing from header":(r[i]="isoform1",i=o("isoform_b","refseq_b","refseq2","isoform2","sv_refseqb"),-1==i?"isoform_b missing from header":(r[i]="isoform2",i=o("strand_a","orta"),-1==i?"strand_a missing from header":(r[i]="strand1",i=o("strand_b","ortb"),-1==i?"strand_b missing from header":(r[i]="strand2",i=o("sample","sample_name","tumor_sample_barcode"),-1!=i&&(r[i]="sample"),i=o("patient","donor","target_case_id"),-1!=i&&(r[i]="patient"),i=o("sampletype","sample type","sample_type"),-1!=i&&(r[i]="sampletype"),i=o("disease"),-1!=i&&(r[i]="disease"),i=o("origin"),-1!=i&&(r[i]="origin"),n?(e.sv.loaded=!0,e.sv.header=r):(e.fusion.loaded=!0,e.fusion.header=r),!1))))))))))}function s(t,e,n,i){if(""==e||"#"==e[0])return;const s=e.split("\t"),a={},l=i?n.sv.header:n.fusion.header,c=i?n.sv.badlines:n.fusion.badlines;for(let t=0;t<l.length;t++)a[l[t]]=s[t];if(!a.chr1)return void c.push([t,"missing chr1",s]);if(0!=a.chr1.toLowerCase().indexOf("chr")&&(a.chr1="chr"+a.chr1),!a.chr2)return void c.push([t,"missing chr2",s]);0!=a.chr2.toLowerCase().indexOf("chr")&&(a.chr2="chr"+a.chr2);let u=a.position1;if(!u)return void c.push([t,"missing position1",s]);let f=Number.parseInt(u);if(Number.isNaN(f)||f<=0)c.push([t,"invalid value for position1",s]);else if(a.position1=f,u=a.position2,u){if(f=Number.parseInt(u),Number.isNaN(f)||f<=0)c.push([t,"invalid value for position2",s]);else if(a.position2=f,!r.parsesample(a,n,t,s,c)){if(a.isoform1&&-1!=a.isoform1.indexOf(",")){const t=a.isoform1.split(",");a.isoform1=void 0;for(const e of t)""!=e&&(a.isoform1=e)}if(a.isoform2&&-1!=a.isoform2.indexOf(",")){const t=a.isoform2.split(",");a.isoform2=void 0;for(const e of t)""!=e&&(a.isoform2=e)}if(a.gene1||(a.isoform1=void 0),a.gene2||(a.isoform2=void 0),a.gene1){n.good++;const t={dt:i?o.dtsv:o.dtfusionrna,class:i?o.mclasssv:o.mclassfusionrna,isoform:a.isoform1,mname:a.gene2||a.chr2,sample:a.sample,patient:a.patient,sampletype:a.sampletype,origin:a.origin,disease:a.disease,pairlst:[{a:{name:a.gene1,isoform:a.isoform1,strand:a.strand1,chr:a.chr1,position:a.position1},b:{name:a.gene2,isoform:a.isoform2,strand:a.strand2,chr:a.chr2,position:a.position2}}]},e=n.geneToUpper?a.gene1.toUpperCase():a.gene1;n.data[e]||(n.data[e]=[]),n.data[e].push(t)}if(a.gene2&&a.gene2!=a.gene1){n.good++;const t={dt:i?o.dtsv:o.dtfusionrna,class:i?o.mclasssv:o.mclassfusionrna,isoform:a.isoform2,mname:a.gene1||a.chr1,sample:a.sample,patient:a.patient,sampletype:a.sampletype,origin:a.origin,disease:a.disease,pairlst:[{a:{name:a.gene1,isoform:a.isoform1,strand:a.strand1,chr:a.chr1,position:a.position1},b:{name:a.gene2,isoform:a.isoform2,strand:a.strand2,chr:a.chr2,position:a.position2}}]},e=n.geneToUpper?a.gene2.toUpperCase():a.gene2;n.data[e]||(n.data[e]=[]),n.data[e].push(t)}}}else c.push([t,"missing position2",s])}function a(t){const e={};for(const n in t){if("pairlst"==n)continue;const r=t[n];"object"!=typeof r&&(e[n]=r)}if(t.pairlst){e.pairlst=[];for(const n of t.pairlst){const t={};for(const e in n)"a"!=e&&"b"!=e&&"interstitial"!=e&&(t[e]=n[e]);if(n.a){t.a={};for(const e in n.a){const r=n.a[e];"object"!=typeof r&&(t.a[e]=r)}}if(n.b){t.b={};for(const e in n.b){const r=n.b[e];"object"!=typeof r&&(t.b[e]=r)}}if(n.interstitial){t.interstitial={};for(const e in n.interstitial){const r=n.interstitial[e];"object"!=typeof r&&(t.interstitial[e]=r)}}e.pairlst.push(t)}}return e}},8423:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid file header for svjson";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("sample");return-1!=o&&(n[o]="sample"),o=r("sampletype"),-1!=o&&(n[o]="sampletype"),o=r("patient"),-1!=o&&(n[o]="patient"),o=r("json","jsontext"),-1==o?["json missing from header"]:(n[o]="jsontext",[null,n])}function s(t,e,n,i){if(""==e||"#"==e[0])return;const s=e.split("\t"),l={},c=n.svjson.badlines;for(let t=0;t<i.length;t++)l[i[t]]=s[t];if(!l.jsontext)return void c.push([t,"missing jsontext",s]);if(o.parsesample(l,n,t,s,c))return;let u;try{u=JSON.parse(l.jsontext)}catch(e){return void c.push([t,"invalid JSON text",s])}if(Array.isArray(u))for(const t of u){if(t.a&&t.a.name&&t.a.isoform){n.good++;const e={dt:r.dtfusionrna,class:r.mclassfusionrna,isoform:t.a.isoform,mname:t.b.name};for(const t in l)"jsontext"!=t&&(e[t]=l[t]);e.pairlst=a(u);const o=t.a.name.toUpperCase();n.data[o]||(n.data[o]=[]),n.data[o].push(e)}if(t.b&&t.b.name&&t.b.isoform){n.good++;const e={dt:r.dtfusionrna,class:r.mclassfusionrna,isoform:t.b.isoform,mname:t.a.name};for(const t in l)"jsontext"!=t&&(e[t]=l[t]);e.pairlst=a(u);const o=t.b.name.toUpperCase();n.data[o]||(n.data[o]=[]),n.data[o].push(e)}}else{switch(u.dt=u.typecode,delete u.typecode,u.dt){case r.dtitd:u.class=r.mclassitd,u.mname="ITD";break;case r.dtnloss:u.class=r.mclassnloss,u.mname="N-loss";break;case r.dtcloss:u.class=r.mclasscloss,u.mname="C-loss";break;case r.dtdel:u.class=r.mclassdel,u.mname="Del";break;case r.dtsv:u.class=r.mclasssv,u.mname="SV";break;default:return void c.push([t,"unknown datatype",s])}if(!u.gene)return void c.push([t,"json.gene missing",s]);n.good++;for(const t in l)"jsontext"!=t&&(u[t]=l[t]);const e=(n.geneToUpper,u.gene.toUpperCase());n.data[e]||(n.data[e]=[]),n.data[e].push(u)}}function a(t){const e=[];for(const n of t){const t={a:{},b:{}};for(const e in n)"a"!=e&&"b"!=e&&(t[e]=n[e]);for(const e in n.a)t.a[e]=n.a[e];for(const e in n.b)t.b[e]=n.b[e];e.push(t)}return e}},8235:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parseheader:()=>i,parseline:()=>s});var r=n(2273),o=n(8064);function i(t,e){const n=t.toLowerCase().split("\t");if(n.length<=1)return"invalid header line for truncation";const r=(...t)=>{for(const e of t){const t=n.indexOf(e);if(-1!=t)return t}return-1};let o=r("gene");if(-1==o)return"gene missing from header";if(n[o]="gene",o=r("annovar_isoform","mrna_accession","mrna accession","refseq_mrna_id","annovar_sj_filter_isoform","refseq","isoform"),-1==o)return"isoform missing from header";n[o]="isoform";let i=!1;if(o=r("rnaposition"),-1!=o&&(n[o]="rnaposition",i=!0),o=r("losstype"),-1==o)return"lossType missing from header";n[o]="losstype";let s=!1;if(o=r("chromosome","chr"),-1!=o){if(n[o]="chr",o=r("start","start_position","wu_hg19_pos","chr_position","position"),-1==o)return"genomic position missing from header";n[o]="pos",s=!0}return i||s?(o=r("sample","sample_name","tumor_sample_barcode"),-1!=o&&(n[o]="sample"),o=r("patient","donor","target_case_id"),-1!=o&&(n[o]="patient"),o=r("disease"),-1!=o&&(n[o]="disease"),o=r("origin"),-1!=o&&(n[o]="origin"),o=r("sampletype","sample type","sample_type"),-1!=o&&(n[o]="sampletype"),e.truncation.header=n,e.truncation.loaded=!0,!1):"neither rnaposition nor genomic position is given"}function s(t,e,n){if(""==e||"#"==e[0])return;const i=e.split("\t"),s={};for(let t=0;t<n.truncation.header.length;t++)s[n.truncation.header[t]]=i[t];if(!s.gene)return void n.truncation.badlines.push([t,"missing gene",i]);if(s.rnaposition){const e=Number.parseInt(s.rnaposition);if(Number.isNaN(e)||e<0)return void n.truncation.badlines.push([t,"invalid rnaPosition value",i]);s.rnaposition=e}if(s.pos){const e=Number.parseInt(s.pos);if(Number.isNaN(e)||e<0)return void n.truncation.badlines.push([t,"invalid genomic position",i]);s.pos=e}if(!s.losstype)return void n.truncation.badlines.push([t,"missing lossType value",i]);if("n"!=s.losstype&&"c"!=s.losstype)return void n.truncation.badlines.push([t,'lossType value not "n" or "c"',i]);if(o.parsesample(s,n,t,i,n.truncation.badlines))return;"n"==s.losstype?(s.dt=r.dtnloss,s.class=r.mclassnloss,s.mname="N-loss"):(s.dt=r.dtcloss,s.class=r.mclasscloss,s.mname="C-loss"),n.good++;const a=n.geneToUpper?s.gene.toUpperCase():s.gene;a in n.data||(n.data[a]=[]),n.data[a].push(s)}},2273:(t,e,n)=>{"use strict";n.r(e),n.d(e,{IN_frame:()=>c,OUT_frame:()=>u,alleleInGenotypeStr:()=>ht,applyOverrides:()=>z,basecolor:()=>ot,basecompliment:()=>it,bplen:()=>rt,codon:()=>tt,codon_stop:()=>et,contigNameNoChr:()=>ut,contigNameNoChr2:()=>ft,custommdstktype:()=>X,default_text_color:()=>a,defaultcolor:()=>s,dt2label:()=>w,dtcloss:()=>b,dtcnv:()=>p,dtdel:()=>y,dtfusionrna:()=>d,dtgeneexpression:()=>h,dtitd:()=>g,dtloh:()=>_,dtnloss:()=>v,dtsnvindel:()=>f,dtsv:()=>m,exoncolor:()=>l,fasta2gmframecheck:()=>lt,germlinelegend:()=>$,getColorScheme:()=>wt,getColors:()=>xt,getMax_byiqr:()=>dt,gmmode:()=>pt,kernelDensityEstimator:()=>yt,kernelEpanechnikov:()=>vt,mclass:()=>x,mclasscloss:()=>S,mclasscnvgain:()=>R,mclasscnvloh:()=>P,mclasscnvloss:()=>I,mclassdel:()=>q,mclassdeletion:()=>B,mclassfusionrna:()=>O,mclassinsertion:()=>D,mclassitd:()=>k,mclassmnv:()=>L,mclassnloss:()=>N,mclassnoncoding:()=>C,mclassnonstandard:()=>T,mclasssnv:()=>F,mclasssv:()=>E,mclasstester:()=>j,mclassutr3:()=>A,mclassutr5:()=>M,mdsvcftype:()=>K,morigin:()=>G,morigingermline:()=>J,morigingermlinenonpathogenic:()=>V,morigingermlinepathogenic:()=>H,moriginrelapse:()=>W,moriginsomatic:()=>U,not_annotated:()=>gt,nt2aa:()=>nt,reversecompliment:()=>st,schemeCategory2:()=>_t,schemeCategory20:()=>bt,spliceeventchangegmexon:()=>at,tkt:()=>Y,validate_vcfinfofilter:()=>ct,validtkt:()=>Q,vcfcopymclass:()=>mt,vepinfo:()=>Z});var r=n(1495);const o=n(502),i=n(2554),s=(0,r.B8)("#8AB1D4").darker(),a=(0,r.B8)("#aaa").darker().darker(),l="#4F8053",c=!0,u=!1,f=1,d=2,h=3,p=4,m=5,g=6,y=7,v=8,b=9,_=10,w={[f]:"SNV/indel",[d]:"Fusion RNA",[p]:"CNV",[m]:"SV",[g]:"ITD",[y]:"Deletion",[v]:"N-loss",[b]:"C-loss",[_]:"LOH",[h]:"Gene Expression"},x={M:{label:"MISSENSE",color:"#3987CC",dt:f,desc:"A substitution variant in the coding region resulting in altered protein coding.",key:"M"},E:{label:"EXON",color:"#bcbd22",dt:f,desc:"A variant in the exon of a non-coding RNA.",key:"E"},F:{label:"FRAMESHIFT",color:"#db3d3d",dt:f,desc:"An insertion or deletion variant that alters the protein coding frame.",key:"F"},N:{label:"NONSENSE",color:"#ff7f0e",dt:f,desc:"A variant altering protein coding to produce a premature stopgain or stoploss.",key:"N"},S:{label:"SILENT",color:"#2ca02c",dt:f,desc:"A substitution variant in the coding region that does not alter protein coding.",key:"S"},D:{label:"PROTEINDEL",color:"#7f7f7f",dt:f,desc:"A deletion resulting in a loss of one or more codons from the product, but not altering the protein coding frame.",key:"D"},I:{label:"PROTEININS",color:"#8c564b",dt:f,desc:"An insertion introducing one or more codons into the product, but not altering the protein coding frame.",key:"I"},P:{label:"SPLICE_REGION",color:"#9467bd",dt:f,desc:"A variant in an intron within 10 nt of an exon boundary.",key:"P"},L:{label:"SPLICE",color:"#6633FF",dt:f,desc:"A variant near an exon edge that may affect splicing functionality.",key:"L"},Intron:{label:"INTRON",color:"#656565",dt:f,desc:"An intronic variant.",key:"Intron"},Blank:{label:"Not tested",color:"#fff",dt:f,desc:"This gene is not tested.",key:"Blank"},WT:{label:"Wildtype",color:"#D3D3D3",dt:f,desc:"Wildtype",key:"WT"}},k="ITD";x[k]={label:"ITD",color:"#ff70ff",dt:g,desc:"In-frame internal tandem duplication.",key:k};const q="DEL";x[q]={label:"DELETION, intragenic",color:"#858585",dt:y,desc:"Intragenic deletion.",key:q};const N="NLOSS";x[N]={label:"N-terminus loss",color:"#545454",dt:v,desc:"N-terminus loss due to translocation",key:N};const S="CLOSS";x[S]={label:"C-terminus loss",color:"#545454",dt:b,desc:"C-terminus loss due to translocation",key:S};const A="Utr3";x[A]={label:"UTR_3",color:"#998199",dt:f,desc:"A variant in the 3' untranslated region.",key:A};const M="Utr5";x[M]={label:"UTR_5",color:"#819981",dt:f,desc:"A variant in the 5' untranslated region.",key:M};const T="X";x[T]={label:"NONSTANDARD",color:"black",dt:f,desc:"A mutation class that either does not match our notation, or is unspecified.",key:T};const C="noncoding";function j(t){switch(t.toLowerCase()){case"missense_mutation":return"M";case"nonsense_mutation":case"nonstop_mutation":return"N";case"splice_site":return"L";case"rna":case"3'flank":case"5'flank":return C;case"frame_shift_del":case"frame_shift_ins":return"F";case"in_frame_del":return"D";case"in_frame_ins":return"I";case"translation_start_site":return T;case"3'utr":return A;case"5'utr":return M;case"blank":return"Blank";default:return null}}x[C]={label:"NONCODING",color:"black",dt:f,desc:"Noncoding mutation.",key:C};const O="Fuserna";x[O]={label:"Fusion transcript",color:"#545454",dt:d,desc:"Marks the break points leading to fusion transcripts.<br><span style=\"font-size:150%\">◐</span> - 3' end of the break point is fused to the 5' end of another break point in a different gene.<br><span style=\"font-size:150%\">◑</span> - 5' end of the break point is fused to the 3' end of another break point in a different gene.",key:O};const E="SV";x[E]={label:"Structural variation",color:"#858585",dt:m,desc:"Structural variation detected in genomic DNA.",key:E};const R="CNV_amp";x[R]={label:"Copy number gain",color:"#e9a3c9",dt:p,desc:"Copy number gain",key:R};const I="CNV_loss";x[I]={label:"Copy number loss",color:"#a1d76a",dt:p,desc:"Copy number loss",key:I};const P="CNV_loh";x[P]={label:"LOH",color:"#12EDFC",dt:p,desc:"Loss of heterozygosity",key:P};const F="snv";x[F]={label:"SNV",color:"#92a2d4",dt:f,desc:"Single nucleotide variation",key:F};const L="mnv";x[L]={label:"MNV",color:"#92a2d4",dt:f,desc:"Multiple nucleotide variation",key:L};const D="insertion";x[D]={label:"Sequence insertion",color:"#bd8e91",dt:f,desc:"Sequence insertion",key:D};const B="deletion";function z(t={}){if(t.mclass)for(const e in t.mclass){x[e]||(x[e]={});for(const n in t.mclass[e])x[e][n]=t.mclass[e][n]}}x[B]={label:"Sequence deletion",color:"#b5a174",dt:f,desc:"Sequence deletion",key:B};const Z=function(t){const e=t.toLowerCase().split(",");let n=1;return-1!=e.indexOf("transcript_ablation")?[y,q,n]:(n++,-1!=e.indexOf("splice_acceptor_variant")?[f,"L",n]:(n++,-1!=e.indexOf("splice_donor_variant")?[f,"L",n]:(n++,-1!=e.indexOf("stop_gained")?[f,"N",n]:(n++,-1!=e.indexOf("frameshift_variant")?[f,"F",n]:(n++,-1!=e.indexOf("stop_lost")?[f,"N",n]:(n++,-1!=e.indexOf("start_lost")?[f,"N",n]:(n++,-1!=e.indexOf("transcript_amplification")?[f,T,n]:(n++,-1!=e.indexOf("inframe_insertion")||-1!=e.indexOf("conservative_inframe_insertion")||-1!=e.indexOf("disruptive_inframe_insertion")?[f,"I",n]:(n++,-1!=e.indexOf("inframe_deletion")||-1!=e.indexOf("conservative_inframe_deletion")||-1!=e.indexOf("disruptive_inframe_deletion")?[f,"D",n]:(n++,-1!=e.indexOf("missense_variant")?[f,"M",n]:(n++,-1!=e.indexOf("protein_altering_variant")?[f,"N",n]:(n++,-1!=e.indexOf("splice_region_variant")?[f,"P",n]:(n++,-1!=e.indexOf("incomplete_terminal_codon_variant")?[f,"N",n]:(n++,-1!=e.indexOf("stop_retained_variant")?[f,"S",n]:(n++,-1!=e.indexOf("synonymous_variant")?[f,"S",n]:(n++,-1!=e.indexOf("coding_sequence_variant")?[f,T,n]:(n++,-1!=e.indexOf("mature_mirna_variant")?[f,"E",n]:(n++,-1!=e.indexOf("5_prime_utr_variant")?[f,M,n]:(n++,-1!=e.indexOf("3_prime_utr_variant")?[f,A,n]:(n++,-1!=e.indexOf("non_coding_transcript_exon_variant")?[f,"E",n]:(n++,-1!=e.indexOf("intron_variant")?[f,"Intron",n]:(n++,-1!=e.indexOf("nmd_transcript_variant")?[f,"S",n]:(n++,-1!=e.indexOf("non_coding_transcript_variant")?[f,"E",n]:(n++,-1!=e.indexOf("upstream_gene_variant")?[f,C,n]:(n++,-1!=e.indexOf("downstream_gene_variant")?[f,C,n]:(n++,-1!=e.indexOf("tfbs_ablation")?[f,C,n]:(n++,-1!=e.indexOf("tfbs_amplification")?[f,C,n]:(n++,-1!=e.indexOf("tf_binding_site_variant")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_ablation")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_amplification")?[f,C,n]:(n++,-1!=e.indexOf("feature_elongation")?[f,C,n]:(n++,-1!=e.indexOf("regulatory_region_variant")?[f,C,n]:(n++,-1!=e.indexOf("feature_truncation")?[f,C,n]:(n++,-1!=e.indexOf("intergenic_variant")?[f,C,n]:(n++,[f,T,n])))))))))))))))))))))))))))))))))))},$='<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle><path d="M6.735557395310443e-16,-11A11,11 0 0,1 11,0L9,0A9,9 0 0,0 5.51091059616309e-16,-9Z" transform="translate(7,12)" fill="#858585" stroke="none"></path>',G={},U="S";G[U]={label:"Somatic",desc:"A variant found only in a tumor sample. The proportion is indicated by lack of any arc.",legend:'<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle>'};const J="G";G[J]={label:"Germline",desc:"A constitutional variant found in a normal sample. The proportion is indicated by the span of the solid arc within the whole circle.",legend:$},G.germline=G[J],G.somatic=G[U];const W="R";G[W]={label:"Relapse",desc:"A somatic variant found only in a relapse sample. The proportion is indicated by the span of the hollow arc within the whole circle.",legend:'<circle cx="7" cy="12" r="7" fill="#b1b1b1"></circle><path d="M6.735557395310443e-16,-11A11,11 0 0,1 11,0L9,0A9,9 0 0,0 5.51091059616309e-16,-9Z" transform="translate(7,12)" fill="none" stroke="#858585"></path>'};const H="GP";G[H]={label:"Germline pathogenic",desc:"A constitutional variant with pathogenic allele.",legend:$};const V="GNP";G[V]={label:"Germline non-pathogenic",desc:"A constitutional variant with non-pathogenic allele.",legend:$,hidden:!0};const Y={usegm:"usegm",ds:"dataset",bigwig:"bigwig",bigwigstranded:"bigwigstranded",junction:"junction",mdsjunction:"mdsjunction",mdscnv:"mdscnv",mdssvcnv:"mdssvcnv",mdsexpressionrank:"mdsexpressionrank",mdsvcf:"mdsvcf",bedj:"bedj",pgv:"profilegenevalue",bampile:"bampile",hicstraw:"hicstraw",expressionrank:"expressionrank",aicheck:"aicheck",ase:"ase",mds2:"mds2",mds3:"mds3",bedgraphdot:"bedgraphdot",bam:"bam",ld:"ld"};function Q(t){for(const e in Y)if(t==Y[e])return!0;return!1}const K={vcf:"vcf"},X={vcf:"vcf",svcnvitd:"svcnvitd",geneexpression:"geneexpression"},tt={GCT:"A",GCC:"A",GCA:"A",GCG:"A",CGT:"R",CGC:"R",CGA:"R",CGG:"R",AGA:"R",AGG:"R",AAT:"N",AAC:"N",GAT:"D",GAC:"D",TGT:"C",TGC:"C",CAA:"Q",CAG:"Q",GAA:"E",GAG:"E",GGT:"G",GGC:"G",GGA:"G",GGG:"G",CAT:"H",CAC:"H",ATT:"I",ATC:"I",ATA:"I",TTA:"L",TTG:"L",CTT:"L",CTC:"L",CTA:"L",CTG:"L",AAA:"K",AAG:"K",ATG:"M",TTT:"F",TTC:"F",CCT:"P",CCC:"P",CCA:"P",CCG:"P",TCT:"S",TCC:"S",TCA:"S",TCG:"S",AGT:"S",AGC:"S",ACT:"T",ACC:"T",ACA:"T",ACG:"T",TGG:"W",TAT:"Y",TAC:"Y",GTT:"V",GTC:"V",GTA:"V",GTG:"V"},et="*";function nt(t){if(!t.genomicseq)return;const e=[];if(t.coding)for(const[n,r]of t.coding.entries()){const n=t.genomicseq.substr(r[0]-t.start,r[1]-r[0]);"-"==t.strand?e.push(st(n)):e.push(n)}const n=e.join(""),r=[];for(let e=t.startCodonFrame?3-t.startCodonFrame:0;e<n.length;e+=3){const t=tt[n.substr(e,3)];r.push(t||et)}return t.cdseq=n,r.join("")}function rt(t,e){return t>=1e9?(t/1e9).toFixed(1)+" Gb":t>=1e7?Math.ceil(t/1e6)+" Mb":t>=1e6?(t/1e6).toFixed(1)+" Mb":t>=1e4?Math.ceil(t/1e3)+" Kb":t>=1e3?(t/1e3).toFixed(1)+" Kb":t+(e?"bytes":" bp")}const ot={A:"#ca0020",T:"#f4a582",C:"#92c5de",G:"#0571b0"};function it(t){switch(t){case"A":return"T";case"T":return"A";case"C":return"G";case"G":return"C";case"a":return"t";case"t":return"a";case"c":return"g";case"g":return"c";default:return t}}function st(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(it(t[n]));return e.join("")}function at(t,e){const n={chr:t.chr,start:t.start,stop:t.stop,strand:t.strand,coding:[]};if(e.isskipexon||e.isaltexon)for(let r=0;r<t.exon.length;r++){const o=Math.max(t.codingstart,t.exon[r][0]),i=Math.min(t.codingstop,t.exon[r][1]);o>i||-1==e.skippedexon.indexOf(r)&&n.coding.push([o,i])}else if(e.a5ss||e.a3ss){const r=t.exon.map((t=>[t[0],t[1]])),o="+"==t.strand;e.a5ss?o?r[e.exon5idx][1]=e.junctionB.start:r[e.exon5idx+1][0]=e.junctionB.stop:o?r[e.exon5idx+1][0]=e.junctionB.stop:r[e.exon5idx][1]=e.junctionB.start;for(const e of r){const r=Math.max(t.codingstart,e[0]),o=Math.min(t.codingstop,e[1]);r>o||n.coding.push([r,o])}}return n}function lt(t,e){const n=e.split("\n");n.shift(),t.genomicseq=n.join("").toUpperCase();const r=nt(t);let o=u;return r.indexOf(et)==r.length-1&&(o=c),o}function ct(t){if(!t.lst)return".lst missing";if(!Array.isArray(t.lst))return"input is not an array";for(const e of t.lst){if(!e.name)return"name missing from a set of .vcfinfofilter.lst";if(e.autocategory||e.categories){if(!e.autocategory)for(const t in e.categories){const n=e.categories[t];if(!e.autocolor&&!n.color)return".color missing for class "+t+" from .categories of set "+e.name;n.label||(n.label=t)}if(e.categoryhidden){for(const t in e.categoryhidden)if(!e.categories[t])return"unknown hidden-by-default category "+t+" from set "+e.name}else e.categoryhidden={}}else if(e.numericfilter){const t=[];for(const n of e.numericfilter)"number"==typeof n?t.push({side:"<",value:n}):t.push({side:n.side||"<",value:n.value});e.numericfilter=t}if(e.altalleleinfo){if(!e.altalleleinfo.key)return".key missing from .altalleleinfo from set "+e.name}else{if(!e.locusinfo)return"neither .altalleleinfo or .locusinfo is available from set "+e.name;if(!e.locusinfo.key)return".key missing from .locusinfo from set "+e.name}}}function ut(t,e){for(const n in t.majorchr)if(-1!=e.indexOf(n.replace("chr","")))return!0;if(t.minorchr)for(const n in t.minorchr)if(-1!=e.indexOf(n.replace("chr","")))return!0;return!1}function ft(t,e){let n=0,r=0;for(const o in t.majorchr)e.includes(o)?r++:e.includes(o.replace("chr",""))&&n++;if(t.minorchr)for(const o in t.minorchr)e.includes(o)?r++:e.includes(o.replace("chr",""))&&n++;return[n,r]}function dt(t,e){if(0==t.length)return e;t.sort(((t,e)=>t-e));const n=t[t.length-1];if(t.length<=5)return n;const r=t[Math.floor(t.length/4)],o=t[Math.floor(3*t.length/4)];return Math.min(o+1.5*(o-r),n)}function ht(t,e){return!!t&&(-1!=t.indexOf("/")?-1!=t.split("/").indexOf(e):-1!=t.split("|").indexOf(e))}const pt={genomic:"genomic",splicingrna:"splicing RNA",exononly:"exon only",protein:"protein",gmsum:"aggregated exons"};function mt(t,e){if(t.csq){let n;if(e.usegm&&(n=t.csq.find((t=>t._isoform==e.usegm.isoform))),!n&&(n=t.csq.find((t=>t.CANONICAL)),!n)){n=t.csq[0];for(const e of t.csq)e._csqrank<n._csqrank&&(n=e)}n&&(t.gene=n._gene,t.isoform=n._isoform,t.class=n._class,t.dt=n._dt,t.mname=n._mname,t.class==C&&delete t.class)}else if(t.ann){let n=null;if(e.usegm){for(const r of t.ann)r._isoform==e.usegm.isoform&&(n?r._csqrank<n._csqrank&&(n=r):n=r);n||e.gmmode!=pt.genomic||(n=t.ann[0])}else{n=t.ann[0];for(const e of t.ann)e._csqrank<n._csqrank&&(n=e)}n&&(t.gene=n._gene,t.isoform=n._isoform,t.class=n._class,t.dt=n._dt,t.mname=n._mname,t.class==C&&delete t.class)}null==t.class&&(x[t.type]?(t.class=t.type,t.dt=x[t.type].dt,t.mname=t.id&&"."!=t.id?t.id:t.ref+">"+t.alt,t.mname.length>15&&(t.mname=t.type)):(t.class=T,t.dt=f,t.mname=t.type)),delete t.type}const gt="Unannotated";function yt(t,e){return function(n){return e.map((e=>[e,n.map((n=>t(e-n))).reduce(((t,e)=>t+e),0)/n.length]))}}function vt(t){return function(e){return Math.abs(e/=t)<=1?.75*(1-e*e)/t:0}}const bt=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],_t=["#e75480","blue"];function wt(t){return t>12?bt:t>8?i.schemePaired:t>2?i.schemeDark2:_t}function xt(t){return o.scaleOrdinal(wt(t))}},7027:(t,e,n)=>{"use strict";function r(t,e){t.sort(((t,e)=>t-e));const n=Math.abs(e/100*t.length-1);return Number.isInteger(n)?(t[n]+t[n+1])/2:t[Math.ceil(n)]}n.d(e,{Z:()=>r})},478:(t,e,n)=>{"use strict";function r(t,e){i(e);const n=new Set;for(const r of t){if(n.has(r.sample))continue;const t=r.s||r.data;t&&o(t,e)&&n.add(r.sample)}return n}function o(t,e){const n="tvslst"==e.type?e.lst:[e];let r=0;for(const i of n){if("tvslst"==i.type)o(t,i)&&r++;else{const e=i.tvs,n=t[e.term.id];let o;if("categorical"==e.term.type){if(void 0===n)continue;o=e.valueset.has(n)}else if("integer"==e.term.type||"float"==e.term.type){if(void 0===n)continue;for(const t of e.ranges){if("value"in t){if(o=n===t.value,o)break}else{if(e.term.values){const t=e.term.values[n.toString()];if(t&&t.uncomputable)continue}let r,i;t.startunbounded?r=!0:"start"in t&&(r=t.startinclusive?n>=t.start:n>t.start),t.stopunbounded?i=!0:"stop"in t&&(i=t.stopinclusive?n<=t.stop:n<t.stop),o=r&&i}if(o)break}}else{if("condition"!=e.term.type)throw"unknown term type";{const t=s(e),r=n&&n[t];r&&(o=Array.isArray(r)?e.values.find((t=>r.includes(t.key))):e.values.find((t=>t.key==r)))}}e.isnot&&(o=!o),o&&r++}if("or"==e.join){if(r&&e.in)return!0;if(!r&&!e.in)return!0}}return e.in==(r==n.length)}function i(t,e=null){if("tvslst"==t.type)for(const n of t.lst)i(n,e);else e&&"function"==typeof e.setAnnoByTermId&&e.setAnnoByTermId(t.tvs.term.id),"categorical"==t.tvs.term.type&&(t.tvs.valueset=new Set(t.tvs.values.map((t=>t.key))))}function s(t){const e=t.bar_by_children&&t.value_by_max_grade?"childrenAtMaxGrade":t.bar_by_children&&t.value_by_most_recent?"childrenAtMostRecent":t.bar_by_children&&t.value_by_computable_grade?"children":t.bar_by_grade&&t.value_by_max_grade?"maxGrade":t.bar_by_grade&&t.value_by_most_recent?"mostRecentGrades":t.bar_by_grade&&t.value_by_computable_grade?"computableGrades":"";if(!e)throw"unknown condition term bar_by_* and/or value_by_*";return e}function a(t){if(!t||0==t.length)return;let e=JSON.parse(JSON.stringify(t[0]));if(1==t.length)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("or"==e.join)e={type:"tvslst",join:"and",in:!0,lst:[e]};else if("and"!=e.join)throw'filter.join must be either "and" or "or" when .lst length > 1';for(let n=1;n<t.length;n++){const r=JSON.parse(JSON.stringify(t[n]));"or"==r.join?e.lst.push(r):e.lst.push(...r.lst)}return 1==e.lst.length&&"tvs"==e.lst[0].type&&(e.join=""),e}n.r(e),n.d(e,{filterJoin:()=>a,getFilteredSamples:()=>r,sample_match_termvaluesetting:()=>o,setDatasetAnnotations:()=>i})},2235:(t,e,n)=>{"use strict";function r(t,e){if(t.startunbounded){if(t.stopunbounded)throw"both start & stop are unbounded from "+e;if(!Number.isFinite(t.stop))throw".stop undefined when start is unbounded from "+e}else if(t.stopunbounded){if(!Number.isFinite(t.start))throw".start undefined when stop is unbounded from "+e}else{if(!Number.isFinite(t.start))throw".start undefined when start is not unbounded from "+e;if(!Number.isFinite(t.stop))throw".stop undefined when stop is not unbounded from "+e;if(t.start>=t.stop)throw".start is not lower than stop from "+e}}n.d(e,{r:()=>r})},5684:(t,e,n)=>{"use strict";function r(t,e){const n=Number(t);return Number.isInteger(n)?n:Math.abs(n)<1?Number(n.toPrecision(e)):Number(n.toFixed(e))}n.d(e,{Z:()=>r})},4048:(t,e,n)=>{"use strict";n.r(e),n.d(e,{compute_bins:()=>a,get_bin_label:()=>c,get_bin_range_equation:()=>u,target_percentiles:()=>f,validate_bins:()=>s});var r=n(2163),o=n(2273);function i(t){return!isNaN(parseFloat(t))&&isFinite(t)}function s(t){const e=t;if(!e||"object"!=typeof e)throw"bin schema must be an object";if("type"in e||(e.type="regular-bin"),"custom-bin"==e.type){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],n=e.lst[e.lst.length-1];for(const r of e.lst){if(!("startinclusive"in r)&&!("stopinclusive"in r))throw"custom bin.startinclusive and/or bin.stopinclusive must be defined";if(r==t){if("startunbounded"in r&&!r.startunbounded)throw"a custom first bin must not set bin.startunbounded to false";if(r.startunbounded=!0,"start"in r)throw"a custom first bin must not set a bin.start value";if("start_percentile"in r)throw"the first bin must not set a bin.start_percentile value";if(!("stop"in r))throw"a custom first bin must define a bin.stop value";if(!i(r.stop))throw"a custom first bin.stop value should be numeric"}else if(r==n){if(!("start"in r))throw"a custom last bin must define a bin.start value";if(!i(r.start))throw"a custom last bin.start must be numeric";if("stopunbounded"in r&&!r.stopunbounded)throw"a custom last bin must not set bin.stopunbounded to false";if(r.stopunbounded=!0,"stop"in r)throw"a custom last bin must not set a bin.stop value"}else{if(!i(r.start))throw"bin.start must be numeric for a non-first bin";if(!i(r.stop))throw"bin.stop must be numeric for a non-last bin"}}}else{if("regular-bin"!=e.type)throw`invalid binconfig.type="${e.type}"`;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),!e.first_bin)throw"first_bin{} missing";if("object"!=typeof e.first_bin)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;if(t.startunbounded=!0,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";if(t.stopunbounded=!0,"stop"in t)throw"a regular last bin must not set a bin.stop value"}}}function a(t,e){const n=t;if(s(n),n.lst){const t=(0,o.getColors)(n.lst.length);for(const e of n.lst)e.color=t(e.label)}if("custom-bin"==n.type)return JSON.parse(JSON.stringify(n.lst));if("function"!=typeof e)throw"summaryfxn required for modules/termdb.bins.js compute_bins()";const r=e(f(n));if(!r||"object"!=typeof r)throw"invalid returned value by summaryfxn";n.results={summary:r},n.binLabelFormatter||(n.binLabelFormatter=l(n));const a=Math.floor(100*r.min)/100,u=Math.ceil(100*r.max)/100,d=n.first_bin.startunbounded?a:n.first_bin.start_percentile?r["p"+n.first_bin.start_percentile]:n.first_bin.start;let h,p,m=u;if(n.last_bin)m=n.last_bin.stopunbounded?u:n.last_bin.stop_percentile?r["p"+n.last_bin.stop_percentile]:i(n.last_bin.stop)&&n.last_bin.stop<=r.max?n.last_bin.stop:u,h=i(n.last_bin.start_percentile)?r["p"+n.last_bin.start_percentile]:i(n.last_bin.start)?n.last_bin.start:void 0,p=n.last_bin.stopunbounded?null:n.last_bin.stop_percentile?r["p"+n.last_bin.stop_percentile]:i(n.last_bin.stop)?n.last_bin.stop:null;else if(n.lst){const t=n.lst[n.lst.length-1];h=t.start,p="stop"in t&&!t.stopunbounded?t.stop:u,m=p}else h=u,p=u;const g=i(m),y=i(h),v=i(p);if(!g&&!y)return[];const b=[];let _={startunbounded:n.first_bin.startunbounded,start:n.first_bin.startunbounded?void 0:d,stop:i(n.first_bin.stop_percentile)?+r["p"+n.first_bin.stop_percentile]:i(n.first_bin.stop)?+n.first_bin.stop:d+n.bin_size,startinclusive:n.startinclusive,stopinclusive:n.stopinclusive};if(!i(_.stop))throw"the computed first_bin.stop is non-numeric"+_.stop;for(;(g&&_.stop<=m||_.startunbounded&&!b.length||_.stopunbounded)&&(b.push(_),_.stop>=m&&(_.stopunbounded=!0,b.length>1&&delete _.stop),_.label=c(_,n),!_.stopunbounded);){const t=_.stop+n.bin_size,e=_.stop;if(_={startinclusive:n.startinclusive,stopinclusive:n.stopinclusive,start:e,stop:v&&(e==h||t>p)?p:y&&t>h&&e!=h?h:t},_.stop>=m&&(_.stop=m,n.last_bin&&n.last_bin.stopunbounded&&(_.stopunbounded=1),n.last_bin&&n.last_bin.stopinclusive&&(_.stopinclusive=1)),y&&_.start==h&&n.last_bin&&n.last_bin.stopunbounded&&(_.stopunbounded=1),_.start>_.stop){if(!(y&&_.stop==h&&n.last_bin&&n.last_bin.stopunbounded))break;_.stopunbounded=!0}if(b.length+1>=100){n.error="max_num_bins_reached";break}}delete n.binLabelFormatter,b.length>1&&delete b[b.length-1].stop;const w=(0,o.getColors)(b.length);for(const t of b)t.color=w(t.label);return b}function l(t){return"rounding"in t?(0,r.WU)(t.rounding):t=>t}function c(t,e){const n=e;n.binLabelFormatter||(n.binLabelFormatter=l(n)),t.startunbounded||t.stopunbounded||"startinclusive"in t||"stopinclusive"in t||(n.startinclusive?t.startinclusive=!0:n.stopinclusive&&(t.stopinclusive=!0));const r="bins"==n.use_as||t.start,o="bins"==n.use_as||t.stop;let i=0;if("label_offset"in n?(n.label_offset_ignored="bin_size"in n&&n.bin_size<n.label_offset,n.label_offset_ignored||(i=n.label_offset)):1===n.bin_size&&"integer"==n.termtype&&(i=1),t.startunbounded){return(t.stopinclusive?"≤":"<")+n.binLabelFormatter(o)}if(t.stopunbounded||r===o){return(t.startinclusive?"≥":">")+n.binLabelFormatter(r)}if(i&&t.startinclusive&&!t.stopinclusive){if(Number.isInteger(n.bin_size)&&Math.abs(r-o)===i)return""+n.binLabelFormatter(r);{const t=n.binLabelFormatter(r),e=n.binLabelFormatter(o-i);return+t>=+e?t.toString():t+" to "+e}}{const e=t.startinclusive?"":">",i=t.stopinclusive?"":"<",s=Number.isInteger(r)?r:n.binLabelFormatter(r),a=Number.isInteger(o)?o:n.binLabelFormatter(o);if(+s>=+a){return(t.startinclusive?"≥":">")+s}return e+s+" to "+i+a}}function u(t,e){const n='<span style="font-family:Times;font-style:italic;">x</span>';let r;const o=c(t,e);return t.startunbounded||t.stopunbounded?r=n+" "+o:t.startinclusive?r=o.replace("to <","≤ "+n+" <"):t.stopinclusive&&(r=o.replace(">","").replace("to","< "+n+" ≤")),r}function f(t){const e=[],n=t.first_bin;n&&i(n.start_percentile)&&e.push(n.start_percentile),n&&i(n.stop_percentile)&&e.push(n.stop_percentile);const r=t.last_bin;return r&&i(r.start_percentile)&&e.push(r.start_percentile),r&&i(r.stop_percentile)&&e.push(r.stop_percentile),e}},1575:(t,e,n)=>{"use strict";n.d(e,{CG:()=>o});new Set(["snplst","prs","snplocus","geneVariant","samplelst"]);const r=new Set(["categorical","integer","float","condition","survival","snplst","snplocus","geneVariant","samplelst"]);function o(t,e,n){const o=e||{};if(n&&n.usecase&&use.target in n.usecase)return n.usecase[use.target](t,use);const a=new Set,l=t.child_types||[];switch(o.target){case"barchart":case"summary":case"matrix":return"term0"==o.detail&&"geneVariant"==t.type||("term2"==o.detail&&"geneVariant"==t.type&&"geneVariant"==o.term1type||(t.type&&"survival"!==t.type&&a.add("plot"),i(l)&&a.add("branch"))),a;case"table":return"term"==o.detail&&a.add("plot"),l.length>1&&a.add("branch"),a;case"scatterplot":return"float"!=t.type&&"integer"!=t.type||a.add("plot"),s(l)&&a.add("branch"),a;case"sampleScatter":return"numeric"==o.detail?("float"!=t.type&&"integer"!=t.type||a.add("plot"),s(l)&&a.add("branch")):(r.has(t.type)&&a.add("plot"),t.isleaf||a.add("branch")),a;case"boxplot":return"float"!=t.type&&"integer"!=t.type||a.add("plot"),"term2"===o.detail&&s(l)&&a.add("branch"),a;case"cuminc":if("term"==o.detail)return"condition"==t.type&&a.add("plot"),l.includes("condition")&&a.add("branch"),a;if("term2"===o.detail)return t.type&&"survival"!=t.type&&a.add("plot"),i(l)&&a.add("branch"),a;if("term0"==o.detail)return a.add("plot"),a;case"survival":return"term"==o.detail?("survival"==t.type&&a.add("plot"),l.includes("survival")&&a.add("branch"),a):"term2"===o.detail?("survival"!=t.type&&(t.type&&a.add("plot"),i(l)&&a.add("branch")),a):"term0"==o.detail?(t.type&&a.add("plot"),i(l)&&a.add("branch"),a):(t.isleaf?a.add("plot"):a.add("branch"),a);case"regression":if("outcome"==o.detail){if("linear"==o.regressionType)return"float"!=t.type&&"integer"!=t.type||a.add("plot"),s(l)&&a.add("branch"),a;if("logistic"==o.regressionType)return t.type&&"survival"!=t.type&&a.add("plot"),i(l)&&a.add("branch"),a;if("cox"==o.regressionType)return"condition"==t.type&&a.add("plot"),l.includes("condition")&&a.add("branch"),a}if("independent"==o.detail)return"float"!=t.type&&"integer"!=t.type&&"categorical"!=t.type||a.add("plot"),function(t,e){for(const n of e)if(t.includes(n))return!0}(l,["categorical","float","integer"])&&a.add("branch"),a;default:return r.has(t.type)&&a.add("plot"),t.isleaf||a.add("branch"),a}}function i(t){return!!t.length&&(t.length>1||"survival"!=t[0])}function s(t){return t.includes("float")||t.includes("integer")}},1881:(t,e,n)=>{"use strict";n.r(e),n.d(e,{stratinput:()=>i});const r="root",o="...";function i(t,e){const n=Object.create(null),i=Object.create(null),a=Object.create(null);for(const r of t)for(const[t,o]of e.entries()){const l=s(r,t,e),c=s(r,t-1,e);if(!r[o.k]){t>0&&(a[c]+=1);break}if(n[l]=c,l in a||(a[l]=0),!(l in i)){const n={lst:[]};o.full&&(n.full=r[o.full]),n.id0=e[0].k,n.v0=r[e[0].k],1==t&&(n.id1=e[1].k,n.v1=r[e[1].k]),2==t&&(n.id2=e[2].k,n.v1=r[e[2].k]),i[l]=n}i[l].lst.push(r),t==e.length-1&&(a[l]+=1)}const l=[{id:r,name:r}];for(const t in n){const e=n[t],r=i[t],s=t.split(o);l.push({id:t,parentId:e,lst:r.lst,value:a[t],name:s[s.length-1],full:r.full,id0:r.id0,v0:r.v0,id1:r.id1,v1:r.v1,id2:r.id2,v2:r.v2})}return l}function s(t,e,n){const i=[r];for(let r=0;r<e;r++)i.push(t[n[r].k]);return e>=0&&i.push(t[n[e].k]),i.join(o)}},4298:(t,e,n)=>{"use strict";n.r(e),n.d(e,{parse_CSQ:()=>o});var r=n(2273);function o(t,e,n){if(!e)return null;for(const o of t.split(",")){const t=o.replace(/&/g,",").split("|"),i={};for(let n=0;n<e.length;n++)t[n]&&(i[e[n].name]=t[n]);if(!i.Allele)continue;let s=null;for(const t of n.mlst||n.alleles)if(t.allele_original==i.Allele){s=t;break}if(!s){if("-"==i.Allele)n.mlst?1==n.mlst.length&&(s=n.mlst[0]):n.alleles&&1==n.alleles.length&&(s=n.alleles[0]);else for(const t of n.mlst||n.alleles)if(t.allele_original.substr(1)==i.Allele){s=t;break}if(!s)continue}if(s.csq||(s.csq=[]),s.csq.push(i),i._gene=i.SYMBOL||i.Gene,i.Feature_type&&"Transcript"==i.Feature_type?i._isoform=i.Feature.split(".")[0]:i._isoform=i._gene,i.Consequence){const[t,e,n]=(0,r.vepinfo)(i.Consequence);i._dt=t,i._class=e,i._csqrank=n}else i._dt=dtsnvindel,i._class=mclassnonstandard;i.HGVSp?i._mname=decodeURIComponent(i.HGVSp.substr(i.HGVSp.indexOf(":")+1)):i.Protein_position&&i.Amino_acids?i._mname=decodeURIComponent(i.Protein_position+i.Amino_acids):i.HGVSc?i._mname=i.HGVSc.substr(i.HGVSc.indexOf(":")+1):i.Existing_variation&&(i._name=i.Existing_variation)}return!0}},9380:(t,e,n)=>{"use strict";function r(t){let e=!1,n=!0,r=0,o=0;const i={};let s;for(;r<t.length;){const a=t[r];n?"="==a?(e=!0,n=!1,s=t.substring(o,r),o=r+1):";"==a&&(i[t.substring(o,r)]=1,o=r+1):e&&";"==a&&(n=!0,e=!1,i[s]=t.substring(o,r),s=null,o=r+1),r++}const a=t.substr(o,r);return s?i[s]=a:i[a]=1,i}n.r(e),n.d(e,{dissect_INFO:()=>r})},6819:(t,e,n)=>{"use strict";n.r(e),n.d(e,{vcfparseline:()=>d,vcfparsemeta:()=>f});var r=n(2273),o=n(9380),s=n(4298);function a(t,e,n){if(!e)return null;for(const o of t.split(",")){const t=o.replace(/&/g,",").split("|"),i={};for(let n=0;n<e.length;n++)t[n]&&(i[e[n].name]=t[n]);if(!i.Allele)continue;let s=null;for(const t of n.alleles)if(t.allele==i.Allele){s=t;break}if(s){if(s.ann||(s.ann=[]),s.ann.push(i),i._gene=i.Gene_Name,i.Feature_Type&&"transcript"==i.Feature_Type&&i.Feature_ID&&(i._isoform=i.Feature_ID.split(".")[0]),i.Annotation){const[t,e,n]=(0,r.vepinfo)(i.Annotation);i._dt=t,i._class=e,i._csqrank=n}else i._dt=dtsnvindel,i._class=mclassnonstandard;i["HGVS.p"]?i._mname=i["HGVS.p"]:i["HGVS.c"]&&(i._mname=i["HGVS.c"])}}return!0}var l=n(736);const c=new RegExp(/<(.+)>/),u={};for(const t in r.mclass)u[r.mclass[t].label.toUpperCase()]=t;function f(t){let e=[],n=[],r={},o=!1,i={},s=!1;for(const a of t)if(a.startsWith("#"))if(a.startsWith("#C"))e=a.split("\t").slice(9);else if(a.startsWith("##INFO")){const t=p(a.substring(8,a.length-1),r);t?n.push("INFO error: "+t):o=!0}else if(a.startsWith("##FORMAT")){const t=p(a.substring(10,a.length-1),i);t?n.push("FORMAT error: "+t):s=!0}const a=[];for(const t of e){const e={name:t};a.push(e)}if(r.CSQ){const t=r.CSQ.Description.split(" Format: ");if(t[1]){const e=t[1].split("|");if(e.length>1){r.CSQ.csqheader=[];for(const t of e){const e={name:t};r.CSQ.csqheader.push(e)}}else n.push("unknown format for CSQ header: "+r.CSQ.Description)}else n.push("unknown format for CSQ header: "+r.CSQ.Description)}if(r.ANN){const t=r.ANN.Description.split("'");if(t[1]){const e=t[1].split(" | ");if(e.length){r.ANN.annheader=[];for(const t of e){const e={name:t};r.ANN.annheader.push(e)}}else n.push('no " | " joined annotation fields for ANN (snpEff annotation): '+r.ANN.Description)}else n.push("no single-quote enclosed annotation fields for ANN (snpEff annotation): "+r.ANN.Description)}return[o?r:null,s?i:null,a,n.length?n:null]}function d(t,e){const n=t.split("\t");if(n.length<8)return["line has less than 8 fields",null,null];const r=Number.parseInt(n[1]);if(!Number.isInteger(r))return["invalid value for genomic position",null,null];const i=n[3],u={vcf_ID:n[2],chr:(e.nochr?"chr":"")+n[0],pos:r-1,ref:i,altstr:n[4],alleles:[{allele:i,sampledata:[]}],info:{},name:"."==n[2]?null:n[2]},f=[];for(const t of n[4].split(",")){const e={ref:u.ref,allele:t,allele_original:t,sampledata:[],_m:u,info:{}};if(u.alleles.push(e),"<"==t[0]){const n=t.match(c);if(!n){f.push(t);continue}e.type=n[1],e.allele=n[1],e.issymbolicallele=!0}else{const[t,n,r]=h(u.pos,u.ref,e.allele);e.pos=t,e.ref=n,e.allele=r}}n[8]&&n[9]&&function(t,e,n){const r=t[8].split(":");for(let o=9;o<t.length;o++){const i=t[o].split(":");{let t=!0;for(const e of i)if("."!=e){t=!1;break}if(t)continue}const s=o-9;for(let t=1;t<e.alleles.length;t++){const r={};if(n.samples&&n.samples[s])for(const t in n.samples[s])r[t]=n.samples[s][t];else r.name="missing_samplename_from_vcf_header";e.alleles[t].sampledata.push({sampleobj:r})}for(let t=0;t<r.length;t++){const o=r[t],s=i[t];if("."==s)continue;if("GT"==o){const t=-1!=s.indexOf("/")?"/":"|";let n=0,r=!1;const o=[];for(const i of s.split(t)){if("."==i){r=!0;continue}const t=Number.parseInt(i);if(Number.isNaN(t)){r=!0;continue}n+=t;const s=e.alleles[t];s&&o.push(s.allele)}let i=!1;r||(i=0==n);const a=o.join(t);for(let t=1;t<e.alleles.length;t++){const n=e.alleles[t].sampledata[e.alleles[t].sampledata.length-1];n.GT=s,n.genotype=a,i&&(n.gtallref=!0),n.__gtalleles=o}continue}const a=n.format?n.format[o]:null;if(!a){for(let t=1;t<e.alleles.length;t++)e.alleles[t].sampledata[e.alleles[t].sampledata.length-1][o]=s;continue}const l="Integer"==a.Type,c="Float"==a.Type;if(a.Number&&"R"==a.Number||"AD"==o){const t=s.split(",").map((t=>l?Number.parseInt(t):c?Number.parseFloat(t):t));for(let n=1;n<e.alleles.length;n++)if(null!=t[n]){const r=e.alleles[n],i=r.sampledata[r.sampledata.length-1];i[o]={},i[o][r.ref]=t[0],i[o][r.allele]=t[n]}}else if(a.Number&&"A"==a.Number){const t=s.split(",").map((t=>l?Number.parseInt(t):c?Number.parseFloat(t):t));for(let n=1;n<e.alleles.length;n++)if(null!=t[n-1]){const r=e.alleles[n],i=r.sampledata[r.sampledata.length-1];i[o]={},i[o][r.allele]=t[n-1]}}else for(let t=1;t<e.alleles.length;t++)e.alleles[t].sampledata[e.alleles[t].sampledata.length-1][o]=s}}for(const t of e.alleles)for(const e of t.sampledata)if(e.AD){e.allele2readcount={};for(const t in e.AD)e.allele2readcount[t]=e.AD[t]}}(n,u,e),u.alleles.shift();const d="."==n[7]?[]:(0,o.dissect_INFO)(n[7]);let p=[];e.info?p=function(t,e,n){const r=[];for(const o in t){if(null==n.info[o]){r.push(o);continue}const i=t[o];if("CSQ"==o){(0,s.parse_CSQ)(i,n.info.CSQ.csqheader,e)||(e.info[o]=i);continue}if("ANN"==o){a(i,n.info.ANN.annheader,e)||(e.info[o]=i);continue}if("Flag"==n.info[o].Type){e.info[o]=o;continue}const l=n.info[o].Number,c="Integer"==n.info[o].Type,u="Float"==n.info[o].Type;if("0"==l){e.info[o]=o;continue}if("A"==l){const t=i.split(",");for(let n=0;n<t.length;n++)e.alleles[n]&&(e.alleles[n].info[o]=c?Number.parseInt(t[n]):u?Number.parseFloat(t[n]):t[n]);continue}if("1"==l){e.info[o]=c?Number.parseInt(i):u?Number.parseFloat(i):i;continue}if(!i.split)continue;const f=i.split(",");e.info[o]=c?f.map(Number.parseInt):u?f.map(Number.parseFloat):f}return r}(d,u,e):u.info=d;const m=[];for(const t of u.alleles){const e={};for(const t in u)"alleles"!=t&&(e[t]=u[t]);for(const n in t)"allele"==n?e.alt=t[n]:"info"==n?e.altinfo=t[n]:e[n]=t[n];e.issymbolicallele||"NON_REF"==e.alt||(e.type=(0,l.getVariantType)(e.ref,e.alt)),m.push(e)}return[p.length?"unknown info keys: "+p.join(","):null,m,f.length>0?f:null]}function h(t,e,n){for(;e.length>1&&n.length>1&&e[e.length-1]==n[n.length-1];)e=e.substr(0,e.length-1),n=n.substr(0,n.length-1);for(;e.length>1&&n.length>1&&e[0]==n[0];)e=e.substr(1),n=n.substr(1),t++;return[t,e,n]}function p(t,e){const n={},r=[];let o=0,s=!1,a=null;for(let e=0;e<t.length;e++)if('"'!=t[e])"="!=t[e]?","!=t[e]||(s?s=!1:a?(n[a]=t.substring(o,e),a=null):r.push("k undefined"),o=e+1):(a=t.substring(o,e),o=e+1);else{e++;const o=e;for(;'"'!=t[e];)e++;a?(n[a]=t.substring(o,e),a=null):r.push("k undefined before double quotes"),s=!0}return a&&(n[a]=t.substring(o,i)),n.ID?(e[n.ID]=n,r.length?r.join("\n"):void 0):"no ID"}},736:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getVariantType:()=>o});var r=n(2273);function o(t,e){return 1==t.length&&1==e.length?"."==e?r.mclassdeletion:r.mclasssnv:t.length==e.length?r.mclassmnv:t.length<e.length?r.mclassinsertion:t.length>e.length?r.mclassdeletion:r.mclassnonstandard}},7011:(t,e,n)=>{"use strict";n.r(e),n.d(e,{violinBinsObj:()=>o});const{bin:r}=n(9060);function o(t,e){const n=function(t,e){const n=new Set(e),o=1===n.size?50:n.size<=9?5:15,i=r().domain(t.domain()).thresholds(t.ticks(o)).value((t=>t));return i(e)}(t,e.values),o=[];for(const t of n){const e={x0:t.x0,x1:t.x1};delete t.x0,delete t.x1,e.binValueCount=t.length,o.push(e)}return{bins0:n,bins:o}}},3306:(t,e,n)=>{const r=n(9699),o=(n(1017),n(7147),n(3856)),i=n(6718).createCanvas;n(334);t.exports=t=>async(t,e)=>{try{e.send(await async function(t){const[e,n,s]=r.fileurl(t);if(e)throw e;const a=Number(t.query.coveragemax)||100;if(!Number.isInteger(a))throw"invalid coveragemax";const l=Number(t.query.vafheight);if(!Number.isInteger(l))throw"invalid vafheight";const c=Number(t.query.coverageheight);if(!Number.isInteger(c))throw"invalid coverageheight";const u=Number(t.query.rowspace);if(!Number.isInteger(u))throw"invalid rowspace";const f=Number(t.query.dotsize)||1;if(!Number.isInteger(f))throw"invalid dotsize";if(!t.query.rglst)throw".rglst missing";"string"==typeof t.query.rglst&&(t.query.rglst=JSON.parse(t.query.rglst));const d=t.query.gtotalcutoff,h=t.query.gmafrestrict,p=i(t.query.width*t.query.devicePixelRatio,(3*l+4*u+2*c)*t.query.devicePixelRatio),m=p.getContext("2d");t.query.devicePixelRatio>1&&m.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);let g;m.fillStyle="#f1f1f1",m.fillRect(0,0,t.query.width,l/2),m.fillRect(0,2*u+l+c,t.query.width,l/2),m.fillStyle="#FAFAD9",m.fillRect(0,l/2,t.query.width,l/2),m.fillRect(0,2*u+1.5*l+c,t.query.width,l/2),s&&(g=await o.cache_index(n,t.query.indexURL));let y=0;for(const e of t.query.rglst)e.x=y,y+=t.query.regionspace+e.width;const v="#786312",b="#122778",_="#858585",w="red";for(const e of t.query.rglst){const t=e.width/(e.stop-e.start);await o.get_lines_bigfile({args:[n,e.chr+":"+e.start+"-"+e.stop],dir:g,callback:n=>{const r=n.split("\t"),o=Number.parseInt(r[1]),i=Number.parseInt(r[2]),s=Number.parseInt(r[3]),p=Number.parseInt(r[4]),g=Number.parseInt(r[5]);if(Number.isNaN(i)||Number.isNaN(s)||Number.isNaN(p)||Number.isNaN(g))return;if(d&&g<d)return;const y=Math.ceil(e.x+t*(e.reverse?e.stop-o:o-e.start)-f/2);m.fillStyle=v;const x=i/s;m.fillRect(y,l*(1-x),f,2);const k=p/g;if(h&&(k<h||k>1-h))return;m.fillRect(y,l+u+c+u+l*(1-k),f,2),m.fillStyle=b;const q=Math.abs(x-k);m.fillRect(y,2*l+4*u+2*c+l*(1-q),f,2),m.fillStyle=_;let N=(s>=a?a:s)*c/a,S=c-N;m.fillRect(y,S+l+u,f,N),m.fillStyle=_,N=(g>=a?a:g)*c/a,S=c-N,m.fillRect(y,S+3*u+2*l+c,f,N),s>=a&&(m.fillStyle=w,m.fillRect(y,l+u,f,2)),g>=a&&(m.fillStyle=w,m.fillRect(y,3*u+2*l+c,f,2))}})}return{src:p.toDataURL(),coveragemax:a}}(t))}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},9699:(t,e,n)=>{const r=t=>t.startsWith("[E::idx_test_and_fetch]");e.tabixnoterror=r;new Map;const o=n(334);e.features=Object.freeze(o.features||{});const i=n(6860),s=(n(6464),n(4269)),a=n(3685),l=n(5687),c=n(7147),u=n(1017),f=n(6452),d=n(9292),h=n(7455),p=n(2081),m=p.spawn,g=n(6718).createCanvas,y=n(1881).stratinput,v=n(3986),b=n(7219),_=n(4521),w=n(9344),x=n(3856),k=n(2273),q=n(6819),N=n(8064),S=n(5494),A=n(6733),M=n(5558),T=n(3602),C=n(6279),j=n(8423),O=n(8235),E=(n(7346),n(5505).QP),R=(n(502),n(2884)),I=n(4308),P=n(7860),F=n(2824).q,L=n(9211).e,D=n(1711),B=n(2388),z=n(7253),Z=n(9574),$=n(8164).gdc_bam_request,G=n(5243),U=n(3306),J=n(1270),W=n(4695),H=n(8145),V=n(4353).x,Y=n(8089).f,Q=n(1883).server_updateAttr,K=n(2728),X=n(9191),tt=n(7510),et=n(8025),nt=n(7395),rt=n(9320),ot=n(5728).g,it=n(8405).v,st=n(1185).Z,at=n(5708),lt=n(6979).u,ct=n(8206),ut=n(9710),ft=n(6191),{server_init_db_queries:dt,listDbTables:ht}=n(394),{handle_healthcheck_closure:pt}=n(2084),{handle_genelookup_closure:mt}=n(4065),gt=n(6828),yt={},vt=o.tabix,bt=o.samtools,_t=o.bcftools,wt=(o.bigwigsummary,o.hicstraw);let xt,kt;const qt="Unannotated",Nt=i();Nt.disable("x-powered-by"),o.users&&Nt.use(I({users:o.users,challenge:!0}));const St=o.basepath||"";function At(t){t.header("Access-Control-Allow-Origin","*"),t.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept, Authorization, origin, x-requested-with, content-type, accept, authorization, X-Auth-Token, X-Ds-Access-Token, X-SjPPDs-Sessionid, x-auth-token, x-ds-access-token, x-sjppds-sessionid")}if(!o.backend_only){const t=i.static(u.join(process.cwd(),"./public"),{setHeaders:At});Nt.use(t)}function Mt(t){const e={};for(const n in t.query)"jwt"!=n&&(e[n]=t.query[n]);console.log("%s\t%s\t%s\t%s",s.parse(t.url).pathname,new Date,t.header("x-forwarded-for")||t.connection.remoteAddress,JSON.stringify(e).replace(/\\"/g,'"'))}function Tt(t){const e=yt[t],n={species:e.species,name:t,hasSNP:!!e.snp,hasIdeogram:e.genedb.hasIdeogram,hasClinvarVCF:!!e.clinvarVCF,fimo_motif:!!e.fimo_motif,blat:!!e.blat,geneset:e.geneset,defaultcoord:e.defaultcoord,isdefault:e.isdefault,majorchr:e.majorchr,majorchrorder:e.majorchrorder,minorchr:e.minorchr,tracks:e.tracks,hicenzymefragment:e.hicenzymefragment,datasets:{}};if(e.termdbs){n.termdbs={};for(const t in e.termdbs)n.termdbs[t]={label:e.termdbs[t].label}}for(const t in e.datasets){const r=e.datasets[t];r.isMds3?n.datasets[r.label]={isMds3:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}:r.isMds?n.datasets[r.label]={isMds:!0,mdsIsUninitiated:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}:n.datasets[r.label]={isofficial:!0,legacyDsIsUninitiated:!0,noHandleOnClient:r.noHandleOnClient,label:r.label}}if(e.hicdomain){n.hicdomain={groups:{}};for(const t in e.hicdomain.groups){const r=e.hicdomain.groups[t];n.hicdomain.groups[t]={name:r.name,reference:r.reference,sets:{}};for(const e in r.sets)n.hicdomain.groups[t].sets[e]={name:r.sets[e].name,longname:r.sets[e].longname}}}return n}function Ct(t){const e={noHandleOnClient:t.noHandleOnClient,sampleselectable:t.sampleselectable,label:t.label,dsinfo:t.dsinfo,stratify:t.stratify,cohort:t.cohort,vcfinfofilter:t.vcfinfofilter,info2table:t.info2table,info2singletable:t.info2singletable,url4variant:t.url4variant,itemlabelname:t.itemlabelname};if(t.snvindel_attributes){e.snvindel_attributes=[];for(const n of t.snvindel_attributes){const t={};for(const e in n)if("lst"==e){t.lst=[];for(const e of n.lst){const n={};for(const t in e)n[t]=e[t];t.lst.push(n)}}else t[e]=n[e];e.snvindel_attributes.push(t)}}t.snvindel_legend&&(e.snvindel_legend=t.snvindel_legend);const n={};let r=!1;for(const e of t.queries)e.vcf&&(r=!0,n[e.vcf.vcfid]=e.vcf);return r&&(e.id2vcf=n),e}function jt(t){const e={isMds:!0,noHandleOnClient:t.noHandleOnClient,label:t.label,version:t.version,annotationsampleset2matrix:t.annotationsampleset2matrix,mutationAttribute:t.mutationAttribute,locusAttribute:t.locusAttribute,alleleAttribute:t.alleleAttribute,hide_genotypedownload:t.hide_genotypedownload,hide_phewas:t.hide_phewas,sample2bam:t.sample2bam};if(t.queries&&(e.queries={}),t.track&&(e.track=K.client_copy(t)),t.singlesamplemutationjson&&(e.singlesamplemutationjson=1),t.gene2mutcount&&(e.gene2mutcount=!0,e.mutCountType=t.gene2mutcount.mutationTypes),t.assayAvailability&&(e.assayAvailability=1),t.cohort&&t.cohort.sampleAttribute){const n={};for(const e in t.cohort.sampleAttribute.attributes){const r=t.cohort.sampleAttribute.attributes[e];r.clientnoshow||(n[e]=r)}e.sampleAttribute={attributes:n}}if(t.cohort){if(t.cohort.termdb&&(e.termdb={selectCohort:t.cohort.termdb.selectCohort}),t.cohort.attributes&&t.cohort.attributes.defaulthidden&&(e.cohortHiddenAttr=t.cohort.attributes.defaulthidden),t.cohort.survivalplot){e.survivalplot={samplegroupattrlst:t.cohort.survivalplot.samplegroupattrlst,plots:[]};for(const n in t.cohort.survivalplot.plots){const r=t.cohort.survivalplot.plots[n];e.survivalplot.plots.push({key:n,name:r.name,timelabel:r.timelabel})}}if(t.cohort.mutation_signature){const n={};for(const e in t.cohort.mutation_signature.sets){const r=t.cohort.mutation_signature.sets[e];n[e]={name:r.name,signatures:r.signatures}}e.mutation_signature={sets:n}}}for(const n in t.queries){const r=t.queries[n],o={name:r.name,hideforthemoment:r.hideforthemoment};if(r.istrack){if(o.istrack=!0,o.type=r.type,o.isfull=r.isfull,null!=r.nochr&&(o.nochr=r.nochr),r.infoFilter&&(o.infoFilter=r.infoFilter),r.readcountCutoff&&(o.readcountCutoff=r.readcountCutoff),r.valueLabel&&(o.valueLabel=r.valueLabel),r.valueCutoff&&(o.valueCutoff=r.valueCutoff),r.bplengthUpperLimit&&(o.bplengthUpperLimit=r.bplengthUpperLimit),r.segmeanValueCutoff&&(o.segmeanValueCutoff=r.segmeanValueCutoff),r.lohLengthUpperLimit&&(o.lohLengthUpperLimit=r.lohLengthUpperLimit),r.type==k.tkt.mdssvcnv){if(r.groupsamplebyattr&&(o.groupsamplebyattr=r.groupsamplebyattr),o.multihidelabel_fusion=r.multihidelabel_fusion,o.multihidelabel_sv=r.multihidelabel_sv,o.multihidelabel_vcf=r.multihidelabel_vcf,o.showfullmode=r.showfullmode,o.legend_vorigin=r.legend_vorigin,o.no_loh=r.no_loh,r.expressionrank_querykey){const e=t.queries[r.expressionrank_querykey];if(o.checkexpressionrank={querykey:r.expressionrank_querykey,datatype:e.datatype},e.boxplotbysamplegroup&&e.boxplotbysamplegroup.additionals){const t=[];e.boxplotbysamplegroup.attributes&&t.push(e.boxplotbysamplegroup.attributes.map((t=>t.label)).join(", "));for(const n of e.boxplotbysamplegroup.additionals)t.push(n.label);o.checkexpressionrank.boxplotgroupers=t}}if(r.vcf_querykey){o.checkvcf={querykey:r.vcf_querykey,info:t.queries[r.vcf_querykey].info,format:{}};for(const e of t.queries[r.vcf_querykey].tracks)if(e.format)for(const t in e.format)o.checkvcf.format[t]=e.format[t]}}}else{if(!r.isgenenumeric)continue;o.isgenenumeric=!0,o.datatype=r.datatype,o.no_ase=r.no_ase}e.queries[n]=o}return e}function Ot(t){const e=t.split("\t"),n=e[4],r=e[6].split(",").filter(Boolean),o=n+"/"+r.join("/");return{chrom:e[0],chromStart:Number(e[1]),chromEnd:Number(e[2]),name:e[3],observed:o,alleles:[n,...r]}}function Et(t,e,n){if(n.query.isoform&&yt[n.query.genome].genomicNameRegexp.test(n.query.isoform))return;const[r,o]=e.makequery(n.query);if(!r)return;const i=t.newconn.prepare(r).all(o);let s;s=e.tidy?i.map((t=>e.tidy(t))):i;const a={};if(e.isgeneexpression){a.lst=s,a.isgeneexpression=!0,a.config=e.config;for(const e of t.queries)if(e.dsblocktracklst)for(const t of e.dsblocktracklst)t.type==k.tkt.junction&&(a.config.dsjunctiontk=t)}else a.lst=s;return a}function Rt(t,e){const n=[u.join(o.tpmasterdir,t.vcffile),(t.vcf.nochr?e.query.range.chr.replace("chr",""):e.query.range.chr)+":"+e.query.range.start+"-"+e.query.range.stop];return new Promise(((e,r)=>{const o=m(vt,n),i=[],s=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>s.push(t))),o.on("close",(n=>{""!=s.join("").trim()&&r("error querying vcf file");const o=i.join("").trim();e({lines:""==o?[]:o.split("\n"),vcfid:t.vcf.vcfid})}))}))}function It(t){if(!t.genome)return["no genome"];const e=yt[t.genome];if(!e)return["invalid genome"];if(!e.datasets)return["genome is not equipped with datasets"];if(!t.dslabel)return["dslabel missing"];const n=e.datasets[t.dslabel];if(!n)return["invalid dslabel"];if(!n.queries)return["dataset is not equipped with queries"];if(!t.querykey)return["querykey missing"];const r=n.queries[t.querykey];return r?[null,e,n,r]:["invalid querykey"]}async function Pt(t,e,n,r,i,s){const a=await async function(t,e,n,r){const i=t.checkvcf.tracks[0],s={file:i.file,url:i.url,indexURL:i.indexURL,dir:i.dir,nochr:i.nochr,samples:i.samples,info:t.checkvcf.info,format:i.format},a=await Ht(s.file?u.join(o.tpmasterdir,s.file):s.url,(s.nochr?e.replace("chr",""):e)+":"+n+"-"+r,s.dir),l=[];for(const t of a||[]){const[e,n,r]=q.vcfparseline(t,s);for(const t of n)k.basecolor[t.ref]&&k.basecolor[t.alt]&&t.sampledata&&l.push(t)}return l}(i,e,n,r),l=[];for(const t in i.checkrnabam.samples){const n=i.checkrnabam.samples[t];n.hetsnps=[];for(const e of a){const r=Jt(e,t,i.checkrnabam);r&&r.dnacount.ishet&&n.hetsnps.push(r)}if(n.url?n.dir=await x.cache_index(n.url,n.indexURL||n.url+".bai"):n.file&&(n.file=u.join(o.tpmasterdir,n.file)),n.hetsnps.length>0){await Dt(n,n.hetsnps,e,i.checkrnabam);for(const e of n.hetsnps)e.rnacount.nocoverage||e.rnacount.ref+e.rnacount.alt<i.checkrnabam.rna_mintotalreads||l.push(t+"."+e.pos+"."+e.ref+"."+e.alt+"\t\t\t\t\t\t\t\t"+e.rnacount.ref+"\t"+e.rnacount.alt)}}l.length>0&&await async function(t,e){const n=await function(t){const e=u.join(o.cachedir,Math.random().toString());return new Promise(((n,r)=>{c.writeFile(e,t.join("\n")+"\n",(t=>{t&&r("cannot write"),n(e)}))}))}(t),r=await Gt(n);await function(t,e){return new Promise(((n,r)=>{c.readFile(t,"utf8",((t,o)=>{if(t&&r("cannot read binom pvalue"),o){for(const t of o.trim().split("\n")){const n=t.split("\t"),r=n[0].split("."),o=e[r[0]];if(!o)continue;const i=o.hetsnps.find((t=>t.pos+"."+t.ref+"."+t.alt==r[1]+"."+r[2]+"."+r[3]));i&&(i.rnacount.pvalue=Number.parseFloat(n[10]))}n()}else n()}))}))}(r,e),c.unlink(n,(()=>{})),c.unlink(r,(()=>{}))}(l,i.checkrnabam.samples),s.checkrnabam=[];for(const n in i.checkrnabam.samples){const r=i.checkrnabam.samples[n],o=[];for(const[n,s]of t){const t={gene:n,chr:e,start:s.start,stop:s.stop},a=r.hetsnps.filter((t=>t.pos>=s.start&&t.pos<=s.stop)),l=a.filter((t=>!t.rnacount.nocoverage));if(l.length>0){const e=l.reduce(((t,e)=>t+Math.abs(e.rnacount.f-.5)),0);let n=null,r=0;for(const t of l)null!=t.rnacount.pvalue&&(null==n?n=t.rnacount.pvalue:n*=t.rnacount.pvalue,t.rnacount.pvalue<=i.checkrnabam.binompvaluecutoff&&r++);null!=n&&(t.ase={markers:a.filter((t=>t.dnacount.ishet)).length,ase_markers:r,mean_delta:e/l.length,geometricmean:Math.pow(n,1/l.length)})}let c;c=r.pairedend?await Lt(r,e,s):await Ft(r,e,s),t.fpkm=1e9*c/(r.totalreads*s.exonlength),t.snps=a,o.push(t)}o.length&&s.checkrnabam.push({sample:n,genes:o})}}async function Ft(t,e,n){const r=["view","-c","-M",t.url||t.file];for(const o of n.exonunion)r.push((t.nochr?e.replace("chr",""):e)+":"+(o[0]+1)+"-"+(o[1]+1));let o;return await x.get_lines_bigfile({isbam:!0,args:r,dir:t.dir,callback:t=>o=t}),Number.parseInt(o)}function Lt(t,e,n){return new Promise(((r,o)=>{const i=["view","-M",t.url||t.file];for(const r of n.exonunion)i.push((t.nochr?e.replace("chr",""):e)+":"+(r[0]+1)+"-"+(r[1]+1));const s=m(bt,i,{cwd:t.dir}),a=m("cut",["-f1"],{cwd:t.dir}),l=m("sort",["-u"],{cwd:t.dir}),c=m("wc",["-l"],{cwd:t.dir});s.stdout.pipe(a.stdin),a.stdout.pipe(l.stdin),l.stdout.pipe(c.stdin);const u=[],f=[];c.stdout.on("data",(t=>u.push(t))),c.stderr.on("data",(t=>f.push(t))),c.on("close",(()=>{r(Number.parseInt(u.join("")))}))}))}function Dt(t,e,n,r){const o=[];for(const r of e)r.rnacount={nocoverage:1},o.push((t.nochr?n.replace("chr",""):n)+":"+(r.pos+1)+"-"+(r.pos+1));return new Promise(((n,i)=>{const s=m(_t,["mpileup","--no-reference","-a","INFO/AD","-d",999999,"-r",o.join(","),"-q",r.rnapileup_q,"-Q",r.rnapileup_Q,t.url||t.file],{cwd:t.dir});_.createInterface({input:s.stdout}).on("line",(t=>{if("#"==t[0])return;const n=Ut(t);if(!n)return;const r=e.find((t=>t.pos==n.pos));if(r){const t=n.allele2count[r.ref]||0,e=n.allele2count[r.alt]||0;t+e>0&&(r.rnacount={ref:t,alt:e,f:e/(t+e)})}})),s.on("close",(()=>{n()}))}))}function Bt(t,e,n,r,o,i){e.hideLOHwithCNVoverlap&&zt(o);const s=[];if(i){const t=new Map;for(const[e,n]of o){const r=i.sample2group.get(e);t.has(r)||t.set(r,[]),t.get(r).push({samplename:e,items:n})}if(r)for(const e of r)if(e.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf: "+e.dt);else for(const n of e.sampledata){const e=i.sample2group.get(n.sampleobj.name);t.has(e)||t.set(e,[]),t.get(e).find((t=>t.samplename==n.sampleobj.name))||t.get(e).push({samplename:n.sampleobj.name,items:[]})}for(const[e,n]of t)s.push({name:e,samples:n})}else if(t.cohort&&t.cohort.annotation&&e.groupsamplebyattr){const n=new Map,i=[];for(const[r,s]of o)Zt(r,s,n,i,t,e);if(r)for(const o of r)if(o.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf data: "+o.dt);else for(const r of o.sampledata)Zt(r.sampleobj.name,[],n,i,t,e);for(const t of n.values())if(s.push(t),e.groupsamplebyattr.key2group){const n=e.groupsamplebyattr.key2group.get(t.name);n&&(t.sampletotalnum=n.samples.length)}i.length&&s.push({name:"Unannotated",samples:i});for(const e of s)for(const n of e.samples)t.cohort.annotation[n.samplename]&&(n.sampletype=t.cohort.annotation[n.samplename].sample_type)}else{const t=[];for(const[e,n]of o)t.push({samplename:e,items:n});if(r)for(const e of r)if(e.dt!=k.dtsnvindel)console.log("unknown dt when grouping samples from vcf: "+e.dt);else for(const n of e.sampledata){let e=!0;for(const r of t)if(r.samplename==n.sampleobj.name){e=!1;break}e&&t.push({samplename:n.sampleobj.name,items:[]})}t.length&&s.push({samples:t})}return s}function zt(t){for(const[e,n]of t){const r=new Map,o=new Map,i=[];for(const t of n)t.dt!=k.dtloh?(t.dt==k.dtcnv&&(o.has(t.chr)||o.set(t.chr,[]),o.get(t.chr).push(t)),i.push(t)):(r.has(t.chr)||r.set(t.chr,[]),r.get(t.chr).push(t));if(0!=r.size){for(const[t,e]of r){const n=o.get(t);if(n)for(const t of e){let e=!0;for(const r of n)if(Math.max(t.start,r.start)<Math.min(t.stop,r.stop)){e=!1;break}e&&i.push(t)}else for(const t of e)i.push(t)}t.set(e,i)}}}function Zt(t,e,n,r,o,i){const s=o.cohort.annotation[t];if(!s)return void r.push({samplename:t,items:e});const a=s[i.groupsamplebyattr.attrlst[0].k];if(null==a)return void r.push({samplename:t,items:e});const l=[];for(let t=1;t<i.groupsamplebyattr.attrlst.length;t++){const e=s[i.groupsamplebyattr.attrlst[t].k];if(null==e)break;l.push(e)}l.unshift(a);const c=l.join(i.groupsamplebyattr.attrnamespacer);if(!n.has(c)){const t=[];for(const e of i.groupsamplebyattr.attrlst){const n=s[e.k];if(null==n)break;const r={k:e.k,kvalue:n};e.full&&(r.full=e.full,r.fullvalue=s[e.full]),t.push(r)}const e=[];for(const t of i.groupsamplebyattr.attrlst){const n=s[t.k];if(null==n)break;const r=(t.full?s[t.full]:null)||n;e.push(r)}n.set(c,{name:c,samples:[],attributes:t})}let u=!0;for(const r of n.get(c).samples)if(r.samplename==t){for(const t of e)r.items.push(t);u=!1;break}u&&n.get(c).samples.push({samplename:t,items:e})}function $t(t){return Number.isFinite(t.dna_mintotalreads)?Number.isFinite(t.rna_mintotalreads)?Number.isFinite(t.hetsnp_minbaf)?Number.isFinite(t.hetsnp_maxbaf)?Number.isFinite(t.rnapileup_q)?Number.isFinite(t.rnapileup_Q)?void 0:"invalid value for rnapileup_Q":"invalid value for rnapileup_q":"invalid value for hetsnp_maxbaf":"invalid value for hetsnp_minbaf":"invalid value for rna_mintotalreads":"invalid value for dna_mintotalreads"}function Gt(t){const e=t+".pvalue";return new Promise(((n,r)=>{const i=m("Rscript",[u.join(o.binpath,"utils/binom.R"),t,e]);i.on("close",(()=>{n(e)})),i.on("error",(t=>{r(`cannot do binom test: ${t}`)})),i.stderr.on("data",(t=>{r(`cannot do binom test: ${t}`)}))}))}function Ut(t){const e=t.split("\t");if(e.length<8)return;const n={pos:Number.parseInt(e[1])-1},r=[e[3],...e[4].split(",")],o={};for(const t of e[7].split(";")){const e=t.split("=");o[e[0]]=e[1]}if(o.DP&&(n.DP=Number.parseInt(o.DP)),o.AD){n.allele2count={};const t=o.AD.split(",");for(const[e,o]of r.entries())n.allele2count[o]=Number.parseInt(t[e])}return n}function Jt(t,e,n){const r=t.sampledata.find((t=>t.sampleobj.name==e));if(r){if(r.AD){const e=r.AD[t.ref]||0,o=r.AD[t.alt]||0,i={chr:t.chr,pos:t.pos,ref:t.ref,alt:t.alt,dnacount:{ref:e,alt:o}};return i.dnacount.f=o+e==0?0:o/(o+e),e+o>=n.dna_mintotalreads&&i.dnacount.f>=n.hetsnp_minbaf&&i.dnacount.f<=n.hetsnp_maxbaf&&(i.dnacount.ishet=!0),i}return null}}async function Wt(t,e,n,r,i){const s=await Ht(u.join(o.tpmasterdir,e.file),n+":"+r+"-"+i),a=new Map;if(s)for(const t of s){const e=t.split("\t"),n=JSON.parse(e[3]),r=Number.parseInt(e[1]),o=Number.parseInt(e[2]);if(a.has(n.name)){const t=a.get(n.name);t.start=Math.min(t.start,r),t.stop=Math.max(t.stop,o)}else a.set(n.name,{gene:n.name,start:r,stop:o,exonunion:[]});const i=a.get(n.name);if(n.exon)for(const t of n.exon){const e=i.exonunion.find((e=>Math.max(e[0],t[0])<Math.min(e[1],t[1])));e?(e[0]=Math.min(t[0],e[0]),e[1]=Math.max(t[1],e[1])):i.exonunion.push([t[0],t[1]])}}for(const[t,e]of a)e.exonlength=e.exonunion.reduce(((t,e)=>t+e[1]-e[0]),0);return a}async function Ht(t,e,n){return new Promise(((r,o)=>{const i=m(vt,[t,e],{cwd:n}),s=[],a=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>a.push(t))),i.on("close",(()=>{const t=a.join("");t&&o(t);const e=s.join("").trim();e||r(),r(e.split("\n"))}))}))}function Vt(t,e){return new Promise(((n,r)=>{const o=m(vt,["-H",t],{cwd:e}),i=[],s=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>s.push(t))),o.on("close",(()=>{const t=s.join("");t&&r(t);const e=i.join("").trim();e||r("cannot list vcf meta lines"),n(e.split("\n"))}))}))}function Yt(t,e){const n=e.findIndex((e=>e.value>=t));return-1==n||n==e.length-1?100:0==n?0:Math.ceil(100*n/e.length)}function Qt(t,e,n){if(!t.key)return[".key missing"];if(!e.cohort)return["ds.cohort missing"];if(!e.cohort.annotation)return["ds.cohort.annotation missing"];return[null,Promise.resolve().then((()=>{const r=[];for(const o in e.cohort.annotation){if(n&&!n.has(o))continue;const i=e.cohort.annotation[o][t.key];null!=i&&r.push({sample:o,value:i})}return{id:t.id,items:r}}))]}function Kt(t,e,n,i){if(!t.genename)return["genename missing"];const s=t.genename.toLowerCase();if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["gene feature too long (> 10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((a,l)=>{const c=[],f=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:f.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.gene&&n.gene.toLowerCase()==s&&n.sample&&(i&&!i.has(n.sample)||c.push(n))}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(e=>{const n=d.join("");!n||r(n)?a({id:t.id,items:c}):l(n)}))}))))]}function Xt(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];if(null!=t.valuecutoff&&!Number.isFinite(t.valuecutoff))return["invalid value for valuecutoff"];if(null!=t.focalsizelimit&&!Number.isInteger(t.focalsizelimit))return["invalid value for focalsizelimit"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);r.dt==k.dtcnv&&(t.valuecutoff&&Math.abs(r.value)<t.valuecutoff||(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.focalsizelimit&&r.stop-r.start>=t.focalsizelimit||r.sample&&(i&&!i.has(r.sample)||l.push(r))))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function te(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];if(null!=t.valuecutoff&&!Number.isFinite(t.valuecutoff))return["invalid value for valuecutoff"];if(null!=t.focalsizelimit&&!Number.isInteger(t.focalsizelimit))return["invalid value for focalsizelimit"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);r.dt==k.dtloh&&(t.valuecutoff&&r.segmean<t.valuecutoff||(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.focalsizelimit&&r.stop-r.start>=t.focalsizelimit||r.sample&&(i&&!i.has(r.sample)||l.push(r))))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function ee(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.dt==k.dtitd&&(n.chr=e[0],n.start=Number.parseInt(e[1]),n.stop=Number.parseInt(e[2]),n.sample&&(i&&!i.has(n.sample)||l.push(n)))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function ne(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(t=>{const e=t.split("\t"),n=JSON.parse(e[3]);n.dt!=k.dtsv&&n.dt!=k.dtfusionrna||n.sample&&(i&&!i.has(n.sample)||(n._chr=e[0],n._pos=Number.parseInt(e[1]),n.chrA?(n.chrB=n._chr,n.posB=n._pos):(n.chrA=n._chr,n.posA=n._pos),l.push(n)))}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const n=f.join("");!n||r(n)?s({id:t.id,items:l}):a(n)}))}))))]}function re(t,e,n,i){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];return[null,Promise.resolve().then((()=>{if(!n.file)return x.cache_index(n.url,n.indexURL)})).then((e=>new Promise(((s,a)=>{const l=[],c=m(vt,[n.file?u.join(o.tpmasterdir,n.file):n.url,t.chr+":"+t.start+"-"+t.stop],{cwd:e});_.createInterface({input:c.stdout}).on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(r.sample&&(!i||i.has(r.sample))){if(r.dt==k.dtsv||r.dt==k.dtfusionrna){if(r.dt==k.dtsv&&t.sv&&t.sv.hidden)return;if(r.dt==k.dtfusionrna&&t.fusion&&t.fusion.hidden)return;r._chr=n[0],r._pos=Number.parseInt(n[1]),r.chrA?(r.chrB=r._chr,r.posB=r._pos):(r.chrA=r._chr,r.posA=r._pos)}else if(r.dt==k.dtcnv){if(t.cnv&&t.cnv.hidden)return;if(t.cnv&&t.cnv.valuecutoff&&Math.abs(r.value)<t.cnv.valuecutoff)return;if(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.cnv&&t.cnv.focalsizelimit&&r.stop-r.start>=t.cnv.focalsizelimit)return}else if(r.dt==k.dtloh){if(t.loh&&t.loh.hidden)return;if(t.loh&&t.loh.valuecutoff&&r.segmean<t.loh.valuecutoff)return;if(r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2]),t.loh&&t.loh.focalsizelimit&&r.stop-r.start>=t.loh.focalsizelimit)return}else{if(r.dt!=k.dtitd)return void console.error("unknown datatype",r.dt);if(t.itd&&t.itd.hidden)return;r.chr=n[0],r.start=Number.parseInt(n[1]),r.stop=Number.parseInt(n[2])}l.push(r)}}));const f=[];c.stderr.on("data",(t=>f.push(t))),c.on("close",(e=>{const o=f.join("");if(o&&!r(o))return void a(o);const i=new Map;for(const t of l)i.has(t.sample)||i.set(t.sample,[]),i.get(t.sample).push(t);n.hideLOHwithCNVoverlap&&zt(i);const c=[];for(const[t,e]of i)for(const t of e)c.push(t);s({id:t.id,items:c})}))}))))]}function oe(t,e,n,r){if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>1e7)return["look range too big (>10Mb)"];const o=[];for(const i of n)if(i.type==k.tkt.mdsvcf){const[n,s]=ie(t,e,i,r);if(n)return[n];o.push(s)}else{if(i.type!=k.tkt.mdssvcnv)return["unsupported track type: "+i.type];{const[e,n]=re(t,0,i,r);if(e)return[e];o.push(n)}}return[null,Promise.all(o).then((t=>{const e=[];for(const n of t)for(const t of n.items)e.push(t);return{id:t[0].id,items:e}}))]}function ie(t,e,n,i){if(!n.tracks)return"tracks[] missing from dsquery";if(!t.chr)return["chr missing"];if(!Number.isInteger(t.start)||!Number.isInteger(t.stop))return["invalid start/stop coordinate"];if(t.stop-t.start>3e6)return["look range too big (>3Mb)"];const s=[];for(const e of n.tracks){const a=Promise.resolve().then((()=>{if(!e.file)return x.cache_index(e.url,e.indexURL)})).then((s=>new Promise(((a,l)=>{const c=[],f=m(vt,[e.file?u.join(o.tpmasterdir,e.file):e.url,(e.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+(t.stop+1)],{cwd:s});_.createInterface({input:f.stdout}).on("line",(r=>{if(n.iscustom)c.push(r);else if(e.type==k.mdsvcftype.vcf){const[o,s,a]=q.vcfparseline(r,{nochr:e.nochr,samples:e.samples,info:n.info,format:e.format});for(const e of s)if(e.sampledata&&(k.vcfcopymclass(e,{}),!(t.snvindel&&t.snvindel.excludeclasses&&t.snvindel.excludeclasses[e.class]))){if(i){const t=[];for(const n of e.sampledata)i.has(n.sampleobj.name)&&t.push(n);if(0==t.length)continue;e.sampledata=t}for(const t of e.sampledata)delete t.allele2readcount;delete e._m,delete e.vcf_ID,delete e.name,e.dt=k.dtsnvindel,c.push(e)}}else console.error("type not one of mdsvcftype: "+e.type)}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(t=>{const e=d.join("");!e||r(e)?a(c):l(e)}))}))));s.push(a)}return[null,Promise.all(s).then((e=>{const n=[];for(const t of e)for(const e of t)n.push(e);return{id:t.id,items:n}}))]}function se(t){if(!t.endsWith(".gz"))return["no .gz suffix (file should be compressed by bgzip)"];const e=u.join(o.tpmasterdir,t);return c.existsSync(e)?c.existsSync(e+".tbi")||c.existsSync(e+".csi")?[null,e]:[".tbi/.csi index missing"]:[".gz file not found"]}Nt.use(h()),Nt.use(((t,e,n)=>{"POST"==t.method.toUpperCase()&&(t.headers["content-type"]="application/json");try{for(const e in t.query){const n=t.query[e];(n.startsWith('"')&&n.endsWith('"')||n.startsWith("{")&&n.endsWith("}")||n.startsWith("[")&&n.endsWith("]"))&&(t.query[e]=JSON.parse(n))}}catch(t){return void e.send({error:t})}n()})),Nt.use(ut()),Nt.use(v.json({limit:"5mb"})),Nt.use(v.text({limit:"5mb"})),Nt.use(v.urlencoded({extended:!0})),Nt.use(((t,e,n)=>{"POST"==t.method.toUpperCase()&&t.body&&"application/json"!=t.headers["content-type"]?e.send({error:"invalid HTTP request.header['content-type'], must be 'application/json'"}):("application/json"==t.headers["content-type"]&&(t.query||(t.query={}),Object.assign(t.query,t.body)),Mt(t),At(e),e.header("Access-Control-Allow-Origin",t.get("origin")||t.get("referrer")||t.protocol+"://"+t.get("host").split(":")[0]||"*"),e.header("Access-Control-Allow-Credentials",!0),"GET"!=t.method||t.path.includes(".")&&!t.path.endsWith("proteinpaint.js")||e.header("Cache-control",`immutable,max-age=${o.responseMaxAge||1}`),n())})),Nt.use(ct.middleware),Nt.use(((t,e,n,r)=>{Mt(e),t&&(t&&"entity.parse.failed"==t.type?n.send({error:"invalid request body, must be a valid JSON-encoded object"}):n.send({error:t}))})),o.jwt&&(console.log("JWT is activated"),Nt.use(((t,e,n)=>{let r={};t.body&&"POST"==t.method&&(r=t.body);const i=r.jwt?r.jwt:t.headers&&t.headers.authorization&&t.headers.authorization.startsWith("Bearer ")?t.headers.authorization.split(" ")[1]:null;if(!i)return e.send({error:"json web token missing"});w.verify(i,o.jwt.secret,((t,r)=>t?e.send({error:"Invalid token"}):r[o.jwt.permissioncheck]?void n():e.send({error:"Not authorized"})))}))),function(){if(!o.routeSetters)return;for(const t of o.routeSetters)if(t.endsWith(".js")){require(t)(Nt,St)}}(),ft.maySetAuthRoutes(Nt,St,o),Nt.get(St+"/healthcheck",pt(yt)),Nt.get(St+"/cardsjson",(async function(t,e){try{if(t.query.datafile&&t.query.tabixCoord)return new Promise(((n,r)=>{const i=m(vt,[u.join(o.tpmasterdir,t.query.datafile),t.query.tabixCoord]),s=[],a=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>a.push(t))),i.on("close",(t=>{""!=a.join("").trim()&&r("error querying bedj file");const o=s.join("").trim();n(e.send({file:o.split("\n")}))}))})).catch((t=>{t.stack&&console.error(t.stack)}));throw"invalid cards request"}catch(t){e.send({error:t.message||t})}})),Nt.post(St+"/mdsjsonform",(async function(t,n){if(!e.features.mdsjsonform)return n.send({error:"This feature is not enabled on this server."});if(t.query.deposit){const e=Math.random().toString(),r=await function(){const t=u.join(o.cachedir,"mdsjsonform");return new Promise(((e,n)=>{c.stat(t,((r,o)=>{if(r){if("ENOENT"==r.code)return void c.mkdir(t,(r=>{r&&n("error creating dir"),e(t)}));n("error checking directory")}else o.isDirectory()?e(t):n('"mdsjsonform" exists but not directory')}))}))}(),i=u.join(r,e);return await x.write_file(i,JSON.stringify(t.query.deposit)),void n.send({id:e})}if(t.query.draw){const e=u.join(o.cachedir,"mdsjsonform",t.query.draw),r=await x.read_file(e);try{const t=JSON.parse(r);n.send({json:t})}catch(t){n.send({error:"Invalid JSON"})}return}n.send({})})),Nt.get(St+"/genomes",(async function(t,n){var r;Mt(t);try{await c.promises.stat(o.tpmasterdir)}catch(t){let e="Error with TP directory ("+t.code+")";const r=o.maintenance||{};if("start"in r&&"stop"in r&&r.tpMessage){const t=+new Date(r.start),n=+new Date(r.stop),o=+new Date;t<=o&&o<=n&&(e=r.tpMessage)}return void n.send({error:e})}const i={};if(t.query&&t.query.genome)i[t.query.genome]=Tt(t.query.genome);else for(const t in yt)i[t]=Tt(t);let s=!1;for(const t in yt)yt[t].blat&&(s=!0);n.send({genomes:i,debugmode:o.debugmode,headermessage:o.headermessage,base_zindex:o.base_zindex,codedate:xt.toDateString(),launchdate:kt,hasblat:s,features:e.features,dsAuth:ft.getDsAuth(t),commonOverrides:o.commonOverrides,targetPortal:o.targetPortal,cardsPath:null===(r=o.cards)||void 0===r?void 0:r.path})})),Nt.get(St+"/getDataset",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.datasets)throw"genomeobj.datasets{} missing";let r;for(const e in n.datasets)if(e.toLowerCase()==t.query.dsname.toLowerCase()){r=n.datasets[e];break}if(!r)throw"invalid dsname";return r.isMds3?e.send({ds:X.client_copy(r,null,null,Nt,St)}):r.isMds?e.send({ds:jt(r)}):e.send({ds:Ct(r)})}catch(t){e.send({error:t.message||t})}})),Nt.all(St+"/genelookup",mt(yt)),Nt.all(St+"/ntseq",(async function(t,e){try{if(!t.query.coord)throw"coord missing";const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.genomefile)throw"no sequence file available";const r=await x.get_fasta(n,t.query.coord);e.send({seq:r.split("\n").slice(1).join("")})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/pdomain",(function(t,e){try{const n=t.query.genome;if(!n)throw"no genome";const r=yt[n];if(!r)throw"invalid genome "+n;if(!r.proteindomain)return e.send({lst:[]});if(!Array.isArray(t.query.isoforms))throw"isoforms[] missing";const o=[];for(const e of t.query.isoforms){if(r.genomicNameRegexp.test(e))continue;const t=r.proteindomain.getbyisoform.all(e);o.push({name:e,pdomains:t.map((t=>{const n=JSON.parse(t.data);return n.refseq=e,n}))})}e.send({lst:o})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/tkbedj",H(yt)),Nt.post(St+"/tkbedgraphdot",B(yt)),Nt.all(St+"/tkbam",z(yt)),Nt.get(St+"/gdcbam",$),Nt.get(St+"/gdc_ssms",G.handle_gdc_ssms(yt)),Nt.get(St+"/gdc_filter2topGenes",G.handle_filter2topGenes(yt)),Nt.get(St+"/tkaicheck",U(yt)),Nt.get(St+"/blat",V(yt)),Nt.all(St+"/mds3",Y(yt)),Nt.get(St+"/tkbampile",J),Nt.post(St+"/dsdata",(async function(t,e){try{if(!yt[t.query.genome])throw"invalid genome";if(!t.query.dsname)throw".dsname missing";const n=yt[t.query.genome].datasets[t.query.dsname];if(!n)throw"invalid dsname";const r=[];for(const e of n.queries)if((!t.query.expressiononly||e.isgeneexpression)&&!(t.query.noexpression&&e.isgeneexpression||e.dsblocktracklst))if(e.vcffile){const n=await Rt(e,t);r.push(n)}else{if(!e.makequery)throw"unknow type from one of ds.queries[]";{const o=Et(n,e,t);r.push(o)}}e.send({data:r})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/tkbigwig",F),Nt.post(St+"/tkld",L(yt)),Nt.get(St+"/tabixheader",(async function(t,e){Mt(t);try{const[n,r,o]=ue(t);if(n)throw n;const i=o?await x.cache_index(r,t.query.indexURL):null,s=await x.get_header_tabix(r,i);e.send({lines:s})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.all(St+"/snp",(async function(t,e){try{const n=t.query.genome;if(!n)throw"no genome";const r=yt[n];if(!r)throw"invalid genome";if(!r.snp)throw"snp is not configured for this genome";const o=[];if(t.query.byCoord){if(r.genomicNameRegexp.test(t.query.chr))throw"invalid chr name";if(!Array.isArray(t.query.ranges))throw"ranges not an array";for(const e of t.query.ranges){if(!Number.isInteger(e.start)||!Number.isInteger(e.stop)||e.start<0||e.stop<e.start)throw"invalid start/stop";if(e.stop-e.start>=100)throw"range too big";const n=await x.query_bigbed_by_coord(r.snp.bigbedfile,t.query.chr,e.start,e.stop);for(const e of n){const n=Ot(e);if(t.query.alleleLst){let e=!1;for(const r of t.query.alleleLst)if(r&&!n.alleles.includes(r)){e=!0;break}if(e)continue}o.push(n)}}}else{if(!t.query.byName)throw"unknown query method";if(!Array.isArray(t.query.lst))throw".lst[] missing";for(const e of t.query.lst){if(r.genomicNameRegexp.test(e))continue;const t=await x.query_bigbed_by_name(r.snp.bigbedfile,e);for(const e of t){const t=Ot(e);o.push(t)}}}e.send({results:o})}catch(t){return t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/clinvarVCF",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.clinvarVCF)throw"no clinvar for this genome";const r=Number(t.query.pos);if(!Number.isInteger(r))throw"pos is not integer";if(r<0)throw"pos is not positive integer";if(!t.query.chr)throw"chr missing";{const e=n.chrlookup[t.query.chr.toUpperCase()];if(!e)throw"invalid chr";if(r>e.len)throw"pos out of bound"}let o;if(await x.get_lines_bigfile({args:[n.clinvarVCF.file,(n.clinvarVCF.nochr?t.query.chr.replace("chr",""):t.query.chr)+":"+r+"-"+(r+1)],callback:e=>{const[i,s,a]=q.vcfparseline(e,n.clinvarVCF);for(const e of s)e.pos==r&&e.ref==t.query.ref&&e.alt==t.query.alt&&(o=e)}}),!o)return e.send({});const i=o.info[n.clinvarVCF.infokey],s=n.clinvarVCF.categories[i];e.send({hit:{id:o.vcf_ID,value:s?s.label:i,bg:s?s.color:"#858585",textcolor:s&&s.textcolor?s.textcolor:"black"}})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/isoformlst",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!Array.isArray(t.query.lst))throw".lst missing";const r=[];for(const e of t.query.lst){if(n.genomicNameRegexp.test(e))continue;const t=n.genedb.getjsonbyisoform.all(e);r.push(t.map((t=>{const e=JSON.parse(t.genemodel);return t.isdefault&&(e.isdefault=!0),e})))}e.send({lst:r})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/dbdata",(function(t,e){})),Nt.get(St+"/img",(async function(t,e){Mt(t);const[n,r,o]=ue(t);try{if(n)throw"invalid image file";const t=await c.promises.readFile(r);e.send({src:"data:image/jpeg;base64,"+new Buffer.from(t).toString("base64"),size:b(r)})}catch(n){e.send({error:n.message||n})}})),Nt.post(St+"/svmr",(function(t,e){if(t.query.file){const[n,r,o]=ue(t);if(n)return void e.send({error:"illegal file name"});c.readFile(r,"utf8",((t,n)=>{t?e.send({error:"cannot read file"}):e.send({raw:n})}))}else e.send({error:"missing file"})})),Nt.post(St+"/study",(async function(t,e){try{if(ce(t.query.file))throw"invalid file path";const n=u.join(o.tpmasterdir,t.query.file.endsWith(".json")?t.query.file:t.query.file+".json"),r=JSON.parse(await x.read_file(n));if(!r.genome)throw"genome missing";const i={};let s=0;for(const t of r.mutationset||[]){const e=N.init_bulk_flag(r.genome);if(!e)throw"init_bulk_flag() failed";if(r.mutationset.length>1&&(e.tpsetname=t.name?t.name:"set"+ ++s),i[Math.random()]=e,t.snvindel){const n=(await x.read_file(u.join(o.tpmasterdir,t.snvindel))).trim().split(/\r?\n/),r=S.parseheader(n[0],e);if(r)throw"snvindel header line error: "+r;for(let t=1;t<n.length;t++)S.parseline(t,n[t],e)}if(t.sv){const n=(await x.read_file(u.join(o.tpmasterdir,t.sv))).trim().split(/\r?\n/),r=C.parseheader(n[0],e,!0);if(r)throw"sv header line error: "+r;for(let t=1;t<n.length;t++)C.parseline(t,n[t],e,!0)}if(t.fusion){const n=(await x.read_file(u.join(o.tpmasterdir,t.fusion))).trim().split(/\r?\n/),r=C.parseheader(n[0],e,!1);if(r)throw"fusion header line error: "+r;for(let t=1;t<n.length;t++)C.parseline(t,n[t],e,!1)}if(t.svjson){const n=(await x.read_file(u.join(o.tpmasterdir,t.svjson))).trim().split(/\r?\n/),[r,i]=j.parseheader(n[0],e);if(r)throw"svjson header line error: "+r;for(let t=1;t<n.length;t++)j.parseline(t,n[t],e,i)}if(t.cnv){const n=(await x.read_file(u.join(o.tpmasterdir,t.cnv))).trim().split(/\r?\n/),r=A.parseheader(n[0],e);if(r)throw"cnv header line error: "+r;for(let t=1;t<n.length;t++)A.parseline(t,n[t],e)}if(t.itd){const n=(await x.read_file(u.join(o.tpmasterdir,t.itd))).trim().split(/\r?\n/),r=T.parseheader(n[0],e);if(r)throw"itd header line error: "+r;for(let t=1;t<n.length;t++)T.parseline(t,n[t],e)}if(t.deletion){const n=(await x.read_file(u.join(o.tpmasterdir,t.deletion))).trim().split(/\r?\n/),r=M.parseheader(n[0],e);if(r)throw"deletion header line error: "+r;for(let t=1;t<n.length;t++)M.parseline(t,n[t],e)}if(t.truncation){const n=(await x.read_file(u.join(o.tpmasterdir,t.truncation))).trim().split(/\r?\n/),r=O.parseheader(n[0],e);if(r)throw"Truncation header line error: "+r;for(let t=1;t<n.length;t++)O.parseline(t,n[t],e)}}if(r.annotations){const t=r.annotations.idkey?r.annotations.idkey:"sample";r.annotations.data={};for(const e of r.annotations.files){const n=await x.read_file(u.join(o.tpmasterdir,e));R.tsvParse(n).forEach((e=>{const n=e[t].trim();r.annotations.data[n]||(r.annotations.data[n]=[]),r.annotations.data[n].push(e)}))}}for(const t in i)ae(i[t]);delete r.mutationset,e.send({cohort:r,flagset:i})}catch(t){return void e.send({error:t.message||t})}})),Nt.post(St+"/textfile",(function(t,e){if(!t.query.file)return e.send({error:"no file"});if(ce(t.query.file))return e.send({error:"invalid file name"});const n=u.join(o.tpmasterdir,t.query.file);if(null!=t.query.from){if(!Number.isInteger(t.query.from))return void e.send({error:"invalid value for from"});if(!Number.isInteger(t.query.to))return void e.send({error:"invalid value for to"});const r=[];d(c.createReadStream(n)).on("end",(()=>{e.send({text:r.join("\n")})})).lines.map(String).skip(t.query.from-1).take(t.query.to).forEach((t=>{r.push(t)}))}else c.readFile(n,{encoding:"utf8"},((t,n)=>{t?e.send({error:"error reading file"}):e.send({text:n})}))})),Nt.post(St+"/urltextfile",(async function(t,e){const n=t.query.url.replace(o.URL,`http://127.0.0.1:${o.port}`);try{const t=await f(n);switch(t.statusCode){case 200:return void e.send({text:x.stripJsScript(t.body)});case 404:return void e.send({error:"File not found: "+n});default:e.send({error:"unknown status code: "+t.status})}}catch(t){return e.send({error:"Error downloading file: "+n})}})),Nt.get(St+"/junction",W),Nt.post(St+"/mdsjunction",Z(yt)),Nt.post(St+"/mdscnv",(function(t,e){const[n,i,s,a]=It(t.query);if(n)return e.send({error:n});if(!t.query.rglst)return e.send({error:"rglst missing"});if(!t.query.gain)return e.send({error:".gain missing"});if(!t.query.loss)return e.send({error:".loss missing"});if(a.viewrangeupperlimit){if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a.viewrangeupperlimit)return e.send({error:"zoom in under "+k.bplen(a.viewrangeupperlimit)+" to view details"})}if(t.query.permanentHierarchy){const n=function(t,e){if(!e.cohort)return".cohort missing from ds";if(!e.cohort.hierarchies)return".hierarchies missing from ds.cohort";if(!e.cohort.hierarchies.lst)return".hierarchies.lst[] missing from ds.cohort";const n=e.cohort.hierarchies.lst.find((e=>e.name==t.permanentHierarchy.hierarchyname));if(!n)return"unknown hierarchy "+t.permanentHierarchy.hierarchyname;if(!n.levels)return".levels[] missing in hierarchy "+n.name;const r=n.levels[t.permanentHierarchy.levelidx];if(!r)return"level not found by array idx "+t.permanentHierarchy.levelidx;const o=r.k;return delete t.cohortHiddenAttr,t.cohortOnlyAttr={},t.cohortOnlyAttr[o]={},t.cohortOnlyAttr[o][t.permanentHierarchy.valuekey]=1,null}(t.query,s);if(n)return e.send({error:"permanentHierarchy error: "+n})}const l=[],c={count:0,samples:new Set},f={count:0,samples:new Set};for(const e of t.query.rglst){const n=new Promise(((n,i)=>{const l=m(vt,[a.file?u.join(o.tpmasterdir,a.file):a.url,e.chr+":"+e.start+"-"+e.stop],{cwd:a.usedir}),d=_.createInterface({input:l.stdout}),h=(e.stop-e.start)/e.width,p=[];for(let t=0;t<e.width;t++)p.push({positive:0,negative:0});d.on("line",(n=>{const r=n.split("\t"),o=Number.parseInt(r[1]),i=Number.parseInt(r[2]);if(t.query.bplengthUpperLimit&&i-o>t.query.bplengthUpperLimit)return;const a=JSON.parse(r[3]);if(t.query.valueCutoff&&Math.abs(a.value)<t.query.valueCutoff)return;if(a.sample&&s.cohort&&s.cohort.annotation){const e=s.cohort.annotation[a.sample];if(!e)return;if(t.query.cohortOnlyAttr&&s.cohort&&s.cohort.annotation){let n=!1;for(const r in t.query.cohortOnlyAttr){const o=e[r];if(o&&t.query.cohortOnlyAttr[r][o]){n=!0;break}}if(!n)return}if(t.query.cohortHiddenAttr&&s.cohort.attributes){let n=!1;for(const r in t.query.cohortHiddenAttr){s.cohort.attributes.lst.find((t=>t.key==r)).isNumeric;const o=e[r];if(o){if(t.query.cohortHiddenAttr[r][o]){n=!0;break}}else if(t.query.cohortHiddenAttr[r][qt]){n=!0;break}}if(n)return}}a.value>0?(c.count++,c.samples.add(a.sample)):a.value<0&&(f.count++,f.samples.add(a.sample));const l=Math.max(e.start,o),u=Math.min(e.stop,i);let d,m;e.reverse?(d=Math.floor((e.stop-u)/h),m=Math.floor((e.stop-l)/h)):(d=Math.floor((l-e.start)/h),m=Math.floor((u-e.start)/h));for(let t=d;t<m;t++)a.value>0?p[t].positive++:a.value<0&&p[t].negative++}));const g=[];l.stderr.on("data",(t=>g.push(t))),l.on("close",(t=>{const e=g.join("");!e||r(e)?n(p):i(e)}))}));l.push(n)}Promise.all(l).then((n=>{const r=t.query.rglst.reduce(((e,n)=>e+n.width+t.query.regionspace),0)-t.query.regionspace,o=g(r,t.query.gain.barheight+t.query.loss.barheight),i=o.getContext("2d"),l={gain:{count:c.count,samplenumber:c.samples.size},loss:{count:f.count,samplenumber:f.samples.size},maxvalue:0};if(c.count+f.count==0)return i.font="15px Arial",i.fillStyle="#aaa",i.textAlign="center",i.textBaseline="middle",i.fillText("No data in view range",r/2,t.query.gain.barheight),l.src=o.toDataURL(),void e.send(l);for(const t of n)for(const e of t)l.maxvalue=Math.max(l.maxvalue,e.positive,e.negative);const u=t.query.maxvalue||l.maxvalue;let d=0;for(const e of n){for(const n of e){if(n.positive){i.fillStyle=t.query.gain.color||"#67a9cf";const e=Math.ceil(t.query.gain.barheight*Math.min(u,n.positive)/u),r=t.query.gain.barheight-e;i.fillRect(d,r,1,e)}if(n.negative){i.fillStyle=t.query.loss.color||"#ef8a62";const e=Math.ceil(t.query.loss.barheight*Math.min(u,n.negative)/u),r=t.query.gain.barheight;i.fillRect(d,r,1,e)}d++}d+=t.query.regionspace}if(l.src=o.toDataURL(),c.samples.size||f.samples.size){const t=new Set([...c.samples,...f.samples]),[e,n]=function(t,e,n){if(!t.cohort||!t.cohort.annotation||0==n.length)return[null,null];const r=[];for(const e of n){const n=t.cohort.annotation[e];n&&r.push(n)}if(0==r.length)return[null,null];let o,i;if(t.cohort.attributes){o=[];for(const n of t.cohort.attributes.lst){const i={label:n.label,key:n.key};if(n.isNumeric){i.isNumeric=!0;continue}const s=new Map;let a=0;for(const e of r){const r=e[n.key];null!=r?(s.has(r)||s.set(r,new Set),s.get(r).add(e[t.cohort.samplenamekey])):a++}const l=[...s];a&&l.push([qt,a]),l.sort(((t,e)=>e[1]-t[1])),i.values=[];for(const[t,r]of l){const o={name:t,sampleset:r};if(n.values&&n.values[t])for(const e in n.values[t])o[e]=n.values[t][e];e.attributeSummary&&e.attributeSummary[n.key]&&e.attributeSummary[n.key][t]&&(o.totalCount=e.attributeSummary[n.key][t]),i.values.push(o)}o.push(i)}}if(t.cohort.hierarchies){i={};for(const n of t.cohort.hierarchies.lst){const o=E()(y(r,n.levels));o.sum((t=>t.value));const s=[];o.eachBefore((r=>{const o={id:r.data.id,name:r.data.name,label:r.data.full,depth:r.depth};if(r.data.lst){o.sampleset=new Set;for(const e of r.data.lst)o.sampleset.add(e[t.cohort.samplenamekey])}r.children||(o.isleaf=1),e.hierarchySummary&&e.hierarchySummary[n.name]&&(o.totalCount=e.hierarchySummary[n.name][r.id]),s.push(o)})),i[n.name]=s}}return[o,i]}(s,a,[...t]);if(e){for(const t of e)for(const e of t.values){e.gain=0,e.loss=0;for(const t of e.sampleset)c.samples.has(t)&&e.gain++,f.samples.has(t)&&e.loss++;delete e.sampleset}l.attributeSummary=e}if(n){for(const t in n)for(const e of n[t])if(e.sampleset){e.gain=0,e.loss=0;for(const t of e.sampleset)c.samples.has(t)&&e.gain++,f.samples.has(t)&&e.loss++}l.hierarchySummary=n}}e.send(l)})).catch((t=>{e.send({error:t}),t.stack&&console.error(t.stack)}))})),Nt.post(St+"/mdssvcnv",(async function(t,n){let i,s,a,l,f,d,h,p,g;if(t.query.iscustom){if(i=yt[t.query.genome],!i)return n.send({error:"invalid genome"});if(s={},a={iscustom:1,file:t.query.file,url:t.query.url,indexURL:t.query.indexURL,allow_getallsamples:!0},t.query.checkexpressionrank){if(!t.query.checkexpressionrank.file&&!t.query.checkexpressionrank.url)return n.send({error:"no file or url for checkexpressionrank"});a.checkexpressionrank={file:t.query.checkexpressionrank.file,url:t.query.checkexpressionrank.url,indexURL:t.query.checkexpressionrank.indexURL}}if(t.query.checkvcf){let e;try{e=JSON.parse(t.query.checkvcf)}catch(t){return n.send({error:"invalid JSON for VCF object"})}if(!e.file&&!e.url)return n.send({error:"no file or url for custom VCF track"});e.type=k.mdsvcftype.vcf,a.checkvcf={info:e.info,tracks:[e]}}if(t.query.checkrnabam){if(!t.query.checkrnabam.samples)return n.send({error:"samples{} missing from checkrnabam"});let e=0;for(const n in t.query.checkrnabam.samples)e++;if(e>13)return n.send({error:"no more than 13 BAM files allowed"});const r=$t(t.query.checkrnabam);if(r)return n.send({error:r});a.checkrnabam=t.query.checkrnabam}}else{if(i=yt[t.query.genome],!i)return n.send({error:"invalid genome"});if(!i.datasets)return n.send({error:"genome is not equipped with datasets"});if(s=i.datasets[t.query.dslabel],!s)return n.send({error:"invalid dslabel"});if(t.query.getsample4disco)return function(t,e,n,r){if(t.query.iscustom)return e.send({error:"not for custom track"});if(!r.singlesamplemutationjson)return e.send({error:"singlesamplemutationjson not available for this dataset"});const i=t.query.getsample4disco,s=r.singlesamplemutationjson.samples[i];if(!s)return e.send({error:"no data"});const a=u.join(o.tpmasterdir,s);c.readFile(a,{encoding:"utf8"},((t,n)=>{if(t)return e.send({error:"error getting data for this sample"});e.send({text:n})}))}(t,n,0,s);if(t.query.gettrack4singlesample)return function(t,e,n){const r=t.query.gettrack4singlesample;if(t.query.iscustom)return e.send({error:"no server-side config available for custom track"});if(!n.sampleAssayTrack)return e.send({});return e.send({tracks:n.sampleAssayTrack.samples.get(r)})}(t,n,s);if(t.query.findsamplename)return function(t,e,n){if(t.query.iscustom)return e.send({error:"cannot search sample by name in custom track"});const r=t.query.findsamplename.toLowerCase(),o=[];if(!n.cohort.__samplelst){n.cohort.__samplelst=[];for(const t in n.cohort.annotation)n.cohort.__samplelst.push({name:t,low:t.toLowerCase()})}i(n.cohort.__samplelst);for(const t in n.queries){const e=n.queries[t];if(e.type==k.tkt.mdssvcnv&&e.groupsamplebyattr)for(const t of o){const r=n.cohort.annotation[t.name];if(!r)continue;const o=[];for(const t of e.groupsamplebyattr.attrlst){const e=r[t.k];e&&o.push({k:t.k,kvalue:e})}o.length&&(t.attributes=o,t.grouplabel=o.map((t=>t.kvalue)).join(e.groupsamplebyattr.attrnamespacer))}}if(n.cohort&&n.cohort.sampleAttribute&&n.cohort.sampleAttribute.attributes&&n.cohort.annotation)for(const t of o){const e=n.cohort.annotation[t.name];if(!e)continue;const r=[];for(const t in n.cohort.sampleAttribute.attributes){if(n.cohort.sampleAttribute.attributes[t].clientnoshow)continue;const o=e[t];null!=o&&r.push({k:t,v:o})}r.length&&(t.attr=r)}if(n.sampleAssayTrack)for(const t of o){const e=n.sampleAssayTrack.samples.get(t.name);e&&(t.num_assay_tracks=e.length)}if(n.cohort&&n.cohort.mutation_signature)for(const t in n.cohort.mutation_signature.sets){const e=n.cohort.mutation_signature.sets[t];if(e.samples)for(const t of o)e.samples.map.has(t.name)&&(t.mutation_signature=1)}if(n.singlesamplemutationjson)for(const t of o)n.singlesamplemutationjson.samples[t.name]&&(t.disco=1);return e.send({result:o});function i(t){for(const e of t){if(o.length>10)return;-1!=e.low.indexOf(r)&&(o.find((t=>t.name==e.name))||o.push(e))}}}(t,n,s);if(t.query.assaymap)return async function(t,e,n){try{if(!n.assayAvailability)throw"assay availability not enabled for this dataset";const r=new Set(t.query.skip_termids||[]),o=new Map;for(const e in n.cohort.annotation){if(t.query.key){if(n.cohort.annotation[e][t.query.key]!=t.query.value)continue}o.set(e,new Map)}for(const[t,e]of o){const o=n.assayAvailability.samples.get(t);if(o)for(const t of n.assayAvailability.assays)r.has(t.id)||o[t.id]&&e.set(t.id,"yes")}for(const t of o.keys())0==o.get(t).size&&o.delete(t);const i={};i.totalsample=o.size,i.terms=ot({sample2term:o,terms:n.assayAvailability.assays,config:{termidorder:t.query.termidorder}}),e.send(i)}catch(t){e.send({error:t.message||t})}}(t,n,s);if(!s.queries)return n.send({error:"dataset is not equipped with queries"});if(a=s.queries[t.query.querykey],!a)return n.send({error:"invalid querykey"})}if(t.query.getexpression4gene)return async function(t,e,n,r,i){try{const n=t.query.getexpression4gene;if(!n.chr)throw"chr missing";if(!Number.isFinite(n.start))throw"invalid start pos";if(!Number.isFinite(n.stop))throw"invalid stop pos";if(!n.name)throw"unknown gene name";if(i.checkrnabam){const r=yt[t.query.genome],o=r.tracks.find((t=>t.__isgene)),s=(await Wt(r,o,n.chr,n.start,n.stop)).get(n.name);if(!s)throw"no gene matching with "+n.name;const a={};await Pt(new Map([[n.name,s]]),n.chr,n.start,n.stop,i,a);const l={};for(const t of a.checkrnabam)if(t.genes){const e=t.genes.find((t=>t.gene==n.name));e&&(l[t.sample]=e)}return void e.send({sample2rnabam:l})}let s;if(i.iscustom?s=i.checkexpressionrank:i.expressionrank_querykey&&(s=r.queries[i.expressionrank_querykey]),!s)throw"missing expression data source";const a=s.file?null:await x.cache_index(s.url,s.indexURL),l=[];await x.get_lines_bigfile({args:[s.file?u.join(o.tpmasterdir,s.file):s.url,n.chr+":"+n.start+"-"+n.stop],dir:a,callback:t=>{const e=t.split("\t");let r;try{r=JSON.parse(e[3])}catch(t){reject("invalid json from expression data")}r.sample&&r.gene&&Number.isFinite(r.value)&&(delete r.outlier,r.gene.toLowerCase()==n.name.toLowerCase()&&l.push(r))}});const c=function(t,e,n){const r={};if(t&&t.cohort&&t.cohort.annotation&&e.groupsamplebyattr&&e.groupsamplebyattr.attrlst){const o=new Map;for(const r of n){const n=t.cohort.annotation[r.sample];if(!n)continue;const i=[];for(const t of e.groupsamplebyattr.attrlst)i.push(n[t.k]);const s=i.join(",");o.has(s)||o.set(s,[]),o.get(s).push(r)}for(const t of o.values()){t.sort(((t,e)=>t.value-e.value));for(const e of t)e.rank=Yt(e.value,t),r[e.sample]=e}}else{n.sort(((t,e)=>t.value-e.value));for(const t of n)t.rank=Yt(t.value,n),r[t.sample]=t}return r}(r,i,l);e.send({sample2rank:c})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}}(t,n,0,s,a);if(t.query.ifsamplehasvcf)return function(t,e,n,r,o){if(t.query.iscustom)return e.send({no:1});if(!o.vcf_querykey)return e.send({yes:1});const i=r.queries[o.vcf_querykey];if(!i)return e.send({error:"vcf query missing"});e.send(i.singlesamples?{yes:1}:{no:1})}(t,n,0,s,a);if(!t.query.rglst)return n.send({error:"rglst missing"});if(a.viewrangeupperlimit){if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a.viewrangeupperlimit)return n.send({error:"zoom in under "+k.bplen(a.viewrangeupperlimit)+" to view details"})}t.query.hiddendt&&(l=new Set(t.query.hiddendt));if(t.query.hiddenmattr){f={};for(const e in t.query.hiddenmattr)f[e]=new Set(t.query.hiddenmattr[e])}if(t.query.filteralleleattr){d={};for(const e in t.query.filteralleleattr){const n=t.query.filteralleleattr[e];n.cutoffvalue,d[e]=n}}if(t.query.filterlocusattr){h={};for(const e in t.query.filterlocusattr){const n=t.query.filterlocusattr[e];n.cutoffvalue,h[e]=n}}if(t.query.sampleset){const e=new Set,n=new Map;for(const r of t.query.sampleset)for(const t of r.samples)e.add(t),n.set(t,r.name);e.size&&(p={set:e,sample2group:n})}if(t.query.hiddensampleattr){g={};for(const e in t.query.hiddensampleattr)g[e]=new Set(t.query.hiddensampleattr[e])}if(a.url)try{a.dir=await x.cache_index(a.url,a.indexURL)}catch(t){return n.send({error:"svcnv file index url error"})}const y=await function(t,e,n,i,s,a,l){if(!e.file&&!e.url)return[];const c=[];for(const f of n.query.rglst){const d=new Promise(((c,d)=>{const h=[],p=m(vt,[e.file?u.join(o.tpmasterdir,e.file):e.url,f.chr+":"+f.start+"-"+f.stop],{cwd:e.dir});_.createInterface({input:p.stdout}).on("line",(e=>{const r=e.split("\t"),o=Number.parseInt(r[1]),c=Number.parseInt(r[2]);let u;try{u=JSON.parse(r[3])}catch(t){return}if(!(null==u.dt||i&&i.has(u.dt))){if(u.dt==k.dtloh){if(u.segmean&&n.query.segmeanValueCutoff&&u.segmean<n.query.segmeanValueCutoff)return;if(n.query.lohLengthUpperLimit&&c-o>n.query.lohLengthUpperLimit)return;u.chr=r[0],u.start=o,u.stop=c}else if(u.dt==k.dtfusionrna||u.dt==k.dtsv)u._chr=r[0],u._pos=o,u.chrA?(u.chrB=r[0],u.posB=o):(u.chrA=r[0],u.posA=o);else if(u.dt==k.dtcnv){if(n.query.hide_cnvloss&&u.value<0)return;if(n.query.hide_cnvgain&&u.value>0)return;if(n.query.valueCutoff&&Math.abs(u.value)<n.query.valueCutoff)return;if(n.query.bplengthUpperLimit&&c-o>n.query.bplengthUpperLimit)return;u.chr=r[0],u.start=o,u.stop=c}else{if(u.dt!=k.dtitd)return void console.error("unknown dt from svcnv file: "+u.dt);u.chr=r[0],u.start=o,u.stop=c}if(n.query.singlesample){if(u.sample!=n.query.singlesample)return}else if(l){if(!l.set.has(u.sample))return}else if(u.sample&&t.cohort&&t.cohort.annotation){const e=t.cohort.annotation[u.sample];if(!e)return;if(s)for(const t in s){const n=e[t];if(s[t].has(n))return}}if(a)for(const t in a){let e=u.mattr?u.mattr[t]:void 0;if(null==e&&(e=k.not_annotated),a[t].has(e))return}h.push(u)}}));const g=[];p.stderr.on("data",(t=>g.push(t))),p.on("close",(t=>{const e=g.join("");!e||r(e)?c(h):d(e)}))}));c.push(d)}return Promise.all(c)}(s,a,t,l,g,f,p),[v,b]=await function(t,e,n,i){if(n.query.singlesample)return[];let s;e.iscustom?s=e.checkexpressionrank:e.expressionrank_querykey&&t.queries[e.expressionrank_querykey]&&(s=t.queries[e.expressionrank_querykey]);if(!s)return[];let a=s.viewrangeupperlimit;!a&&e.iscustom&&(a=5e6);if(a){if(n.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=a)return[a]}return Promise.resolve().then((()=>s.file?"":x.cache_index(s.url,s.indexURL))).then((t=>{const e=new Map,i=[];for(const a of n.query.rglst){const n=new Promise(((n,i)=>{const l=m(vt,[s.file?u.join(o.tpmasterdir,s.file):s.url,a.chr+":"+a.start+"-"+a.stop],{cwd:t});_.createInterface({input:l.stdout}).on("line",(t=>{const n=t.split("\t");let r;try{r=JSON.parse(n[3])}catch(t){return}r.gene&&r.sample&&Number.isFinite(r.value)&&(e.has(r.gene)||e.set(r.gene,{chr:n[0],start:Number.parseInt(n[1]),stop:Number.parseInt(n[2]),samples:new Map}),e.get(r.gene).samples.set(r.sample,{value:r.value,ase:r.ase}))}));const c=[];l.stderr.on("data",(t=>c.push(t))),l.on("close",(t=>{const e=c.join("");!e||r(e)?n():i(e)}))}));i.push(n)}return Promise.all(i).then((()=>[!1,e]))}))}(s,a,t),[w,N]=await async function(t,n,i,s,a,l,f,d,h,p){let g;i.iscustom?g=i.checkvcf:i.vcf_querykey&&n.queries[i.vcf_querykey]&&(g=n.queries[i.vcf_querykey]);if(!g)return[null,null];if(s.query.singlesample&&g.singlesamples){const e=g.singlesamples.samples[s.query.singlesample];if(e){const i={file:u.join(o.tpmasterdir,e)};try{await c.promises.stat(i.file)}catch(t){return[null,null]}const l=await Vt(i.file),[f,p,g,y]=q.vcfparsemeta(l);if(y)throw y;return i.info=f,i.format=p,i.samples=g,i.nochr=await x.tabix_is_nochr(i.file,null,t),function(t,e,n,o,i,s,a){const l=[],c=[];for(const i of t.query.rglst){const u=new Promise(((c,u)=>{const f=m(vt,[n.file,(n.nochr?i.chr.replace("chr",""):i.chr)+":"+i.start+"-"+i.stop]);_.createInterface({input:f.stdout}).on("line",(r=>{const[i,c,u]=q.vcfparseline(r,n);for(const n of c){if(!n.sampledata)continue;const r=n.sampledata.find((e=>e.sampleobj.name==t.query.singlesample));if(r){if(delete r.allele2readcount,n.sampledata=[r],o){let t=!1;for(const e in o){const r=n.altinfo[e];if(null==r){t=!0;break}const i=o[e];if(null!=i.cutoffvalue){if(!Number.isFinite(r)){t=!0;break}if(i.keeplowerthan){if(r>i.cutoffvalue){t=!0;break}}else if(r<i.cutoffvalue){t=!0;break}}}if(t)continue}if(!r.gtallref){if(r.__gtalleles){if(-1==r.__gtalleles.indexOf(n.alt))continue;delete r.__gtalleles}if(s){const t=[];for(const e of n.sampledata){let n=!0;for(const t in s){let r=e[t];if(null==r&&(r=k.not_annotated),s[t].has(r)){n=!1;break}}n&&t.push(e)}if(0==t.length)continue;n.sampledata=t}if(a&&e.cohort&&e.cohort.annotation){const t=[];for(const r of n.sampledata){const n=e.cohort.annotation[r.sampleobj.name];if(!n)continue;let o=!0;for(const t in a){const e=n[t];if(a[t].has(e)){o=!1;break}}o&&t.push(r)}if(0==t.length)continue;n.sampledata=t}delete n._m,delete n.vcf_ID,delete n.name,n.dt=k.dtsnvindel,l.push(n)}}}}));const d=[];f.stderr.on("data",(t=>d.push(t))),f.on("close",(t=>{const e=d.join("");!e||r(e)?c():u(e)}))}));c.push(u)}return Promise.all(c).then((()=>[null,l]))}(s,n,i,a,0,d,h)}}let y=g.viewrangeupperlimit;!y&&i.iscustom&&(y=e.features.customMdsSingleSampleVcfNoRangeLimit?0:2e6);s.query.singlesample&&(y*=5);if(y){if(s.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=y)return[y,null]}const v=[];for(const t of g.tracks){const e=Promise.resolve().then((()=>t.file?"":x.cache_index(t.url,t.indexURL))).then((e=>{t.dir=e;const i=[],c=[];for(const f of s.query.rglst){const y=new Promise(((c,y)=>{const v=m(vt,[t.file?u.join(o.tpmasterdir,t.file):t.url,(t.nochr?f.chr.replace("chr",""):f.chr)+":"+f.start+"-"+f.stop],{cwd:e});_.createInterface({input:v.stdout}).on("line",(e=>{if(t.type==k.mdsvcftype.vcf){const[r,o,c]=q.vcfparseline(e,{nochr:t.nochr,samples:t.samples,info:g.info,format:t.format});for(const t of o)if(t.sampledata){if(a){let e=!1;for(const n in a){const r=t.altinfo[n];if(null==r){e=!0;break}const o=a[n];if(null!=o.cutoffvalue){if(!Number.isFinite(r)){e=!0;break}if(o.keeplowerthan){if(r>o.cutoffvalue){e=!0;break}}else if(r<o.cutoffvalue){e=!0;break}}else if(o.includes(r)){e=!0;break}}if(e)continue}if(l){let e=!1;for(const n in l){const r=t.info[n];if(null==r){e=!0;break}let o=r;if(Array.isArray(r)&&(o=r[0],"."==o)){e=!0;break}const i=l[n];if(null!=i.cutoffvalue){if(!Number.isFinite(o)){e=!0;break}if(i.keeplowerthan){if(o>i.cutoffvalue){e=!0;break}}else if(o<i.cutoffvalue){e=!0;break}}else if(i.includes(o)){e=!0;break}}if(e)continue}{const e=[];for(const n of t.sampledata)if(!n.gtallref){if(n.__gtalleles){if(-1==n.__gtalleles.indexOf(t.alt))continue;delete n.__gtalleles}e.push(n)}if(0==e.length)continue;t.sampledata=e}if(s.query.singlesample){let e=null;for(const n of t.sampledata)if(n.sampleobj.name==s.query.singlesample){e=n;break}if(!e)continue;t.sampledata=[e]}else if(p){const e=t.sampledata.filter((t=>p.set.has(t.sampleobj.name)));if(!e.length)continue;t.sampledata=e}if(d){const e=[];for(const n of t.sampledata){let t=!0;for(const e in d){let r=n[e];if(null==r&&(r=k.not_annotated),d[e].has(r)){t=!1;break}}t&&e.push(n)}if(0==e.length)continue;t.sampledata=e}if(h&&n.cohort&&n.cohort.annotation){const e=[];for(const r of t.sampledata){const t=n.cohort.annotation[r.sampleobj.name];if(!t)continue;let o=!0;for(const e in h){const n=t[e];if(h[e].has(n)){o=!1;break}}o&&e.push(r)}if(0==e.length)continue;t.sampledata=e}for(const e of t.sampledata)delete e.allele2readcount;delete t._m,delete t.vcf_ID,delete t.name,t.dt=k.dtsnvindel,i.push(t)}}else console.error('unknown "type" from a vcf file')}));const b=[];v.stderr.on("data",(t=>b.push(t))),v.on("close",(t=>{const e=b.join("");!e||r(e)?c():y(e)}))}));c.push(y)}return Promise.all(c).then((()=>i))}));v.push(e)}return Promise.all(v).then((t=>{const e=[];for(const n of t)for(const t of n)if(t.dt!=k.dtsnvindel)console.error("unknown dt: "+t.dt);else{if(!t.sampledata)continue;let n=!0;for(const r of e)if(t.chr==r.chr&&t.pos==r.pos&&t.ref==r.ref&&t.alt==r.alt){for(const e of t.sampledata)r.sampledata.push(e);n=!1;break}n&&e.push(t)}return e.sort(((t,e)=>t.pos-e.pos)),[null,e]}))}(i,s,a,t,d,h,0,f,g,p),S=function(t){const e=new Map;for(const n of t)for(const t of n){if(!t.sample)continue;const n=t.sample;e.has(n)||e.set(n,[]),t._chr?e.get(n).push(t):(delete t.sample,delete t.sampletype,e.get(n).push(t))}return e}(y);if(t.query.singlesample){const e={lst:S.get(t.query.singlesample)};return w?e.vcfrangelimit=w:e.data_vcf=N,void n.send(e)}const A={samplegroups:Bt(s,a,y,N,S,p),vcfrangelimit:w,data_vcf:N};t.query.getallsamples&&a.allow_getallsamples&&(A.getallsamples=!0);a.checkrnabam?await async function(t,e,n,r){if(!n.checkvcf)return;if(t.stop-t.start>=5e5)return void(r.expressionrangelimit=5e5);const o=e.tracks.find((t=>t.__isgene)),i=await Wt(e,o,t.chr,t.start,t.stop);let s,a=null;for(const t of i.values())null==a?(a=t.start,s=t.stop):(a=Math.min(a,t.start),s=Math.max(s,t.stop));await Pt(i,t.chr,a,s,n,r)}(t.query.rglst[0],i,a,A):function(t,e,n,r){if(n)return void(t.expressionrangelimit=n);if(r){t.gene2coord={};for(const[e,n]of r)t.gene2coord[e]={chr:n.chr,start:n.start,stop:n.stop};if(0==t.samplegroups.length)return;if(t.getallsamples){const e=new Set(t.samplegroups[0].samples.map((t=>t.samplename))),n=new Set;for(const[t,o]of r)for(const t of o.samples.keys())e.has(t)||n.add(t);for(const e of n)t.samplegroups[0].samples.push({samplename:e,items:[]})}for(const n of t.samplegroups){const t=new Map;for(const[o,i]of r){t.set(o,[]);for(const[r,s]of i.samples)if(n.attributes&&e.cohort&&e.cohort.annotation){const i=e.cohort.annotation[r];if(!i)continue;let a=!0;for(const t of n.attributes)if(i[t.k]!=t.kvalue){a=!1;break}a&&t.get(o).push(s)}else t.get(o).push(s)}for(const[e,n]of t)n.sort(((t,e)=>t.value-e.value));for(const e of n.samples){e.expressionrank={};for(const[n,o]of t){const t=r.get(n).samples.get(e.samplename);if(null==t)continue;const i=Yt(t.value,o);e.expressionrank[n]={rank:i};for(const r in t)e.expressionrank[n][r]=t[r]}}}}}(A,s,v,b);(function(t,e){if(t.cohort&&t.cohort.sampleAttribute&&t.cohort.sampleAttribute.attributes&&t.cohort.annotation){e.sampleannotation={};const n=[];for(const e in t.cohort.sampleAttribute.attributes){t.cohort.sampleAttribute.attributes[e].clientnoshow||n.push(e)}for(const r of e.samplegroups)for(const o of r.samples){const r=t.cohort.annotation[o.samplename];if(r){const t={};let i=!1;for(const e of n){const n=r[e];null!=n&&(i=!0,t[e]=n)}i&&(e.sampleannotation[o.samplename]=t)}}}})(s,A),n.send(A)})),Nt.post(St+"/mdsgenecount",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.datasets)throw"no datasets from genome";const r=n.datasets[t.query.dslabel];if(!r)throw"invalid dataset";if(!r.gene2mutcount)throw"not supported on this dataset";if(!t.query.samples)throw".samples missing";let o,i;o=t.query.selectedMutTypes?t.query.selectedMutTypes.join("+"):"total",i=t.query.nGenes?t.query.nGenes:15;const s=`WITH\n\tfiltered AS (\n\t\tSELECT gene, ${o} AS total FROM genecount\n\t\tWHERE sample IN (${JSON.stringify(t.query.samples).replace(/[[\]\"]/g,"").split(",").map((t=>"'"+t+"'")).join(",")})\n\t)\n\tSELECT gene, SUM(total) AS count\n\tFROM filtered\n\tGROUP BY gene\n\tORDER BY count DESC\n\tLIMIT ${i}`,a=r.gene2mutcount.db.prepare(s).all(),l=[];for(const t of a){const e=n.genedb.getCoordByGene.get(t.gene);e&&(e.gene=t.gene,e.count=t.count,delete e.name,l.push(e))}e.send({genes:l})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/mds2",tt.handle_request(yt)),Nt.post(St+"/mdsexpressionrank",(function(t,e){let n,i,s,a=new Set;Promise.resolve().then((()=>{if(!t.query.rglst)throw"rglst missing";if(t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>1e7)throw"Zoom in below 10 Mb to show expression rank";if(!t.query.sample)throw"sample missing";if(t.query.iscustom){if(n=yt[t.query.genome],!n)throw"invalid genome";if(!t.query.file&&!t.query.url)throw"no file or url for expression data";i={},s={file:t.query.file,url:t.query.url,indexURL:t.query.indexURL}}else{const[e,r,o,a]=It(t.query);if(e)throw e;if(n=r,i=o,s=a,!s.samples)throw"total samples missing from server config";if(-1==s.samples.indexOf(t.query.sample))throw{nodata:1}}if(s.viewrangeupperlimit&&t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>s.viewrangeupperlimit)throw"zoom in under "+k.bplen(s.viewrangeupperlimit)+" to view data";if(t.query.levelkey){if(!t.query.levelvalue)throw"levelvalue is required when levelkey is used";if(!i.cohort||!i.cohort.annotation)throw".cohort.annotation missing from dataset"}if(!s.file){if(!s.url)throw"file or url missing";return x.cache_index(s.url,s.indexURL)}})).then((e=>{const n=[];for(const l of t.query.rglst)n.push(new Promise(((n,c)=>{const f=m(vt,[s.file?u.join(o.tpmasterdir,s.file):s.url,l.chr+":"+l.start+"-"+l.stop],{cwd:e}),d=_.createInterface({input:f.stdout}),h=new Map;d.on("line",(e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(!r.gene)return;if(!r.sample)return;if(!Number.isFinite(r.value))return;const o=n[0],s=Number.parseInt(n[1]),l=Number.parseInt(n[2]);if(r.sample==t.query.sample)return h.has(r.gene)||h.set(r.gene,{chr:o,start:s,stop:l,allvalues:[]}),h.get(r.gene).thisvalue=r.value,void(r.ase&&(h.get(r.gene).ase=r.ase));if(t.query.attributes){const e=i.cohort.annotation[r.sample];if(!e)return;for(const n of t.query.attributes)if(n.k&&n.kvalue&&n.kvalue!=e[n.k])return}a.add(r.sample),h.has(r.gene)||h.set(r.gene,{chr:o,start:s,stop:l,allvalues:[]}),h.get(r.gene).allvalues.push({value:r.value})}));const p=[];f.stderr.on("data",(t=>p.push(t))),f.on("close",(t=>{const e=p.join("");e&&!r(e)&&c({message:e}),n(h)}))})));return Promise.all(n)})).then((t=>{const n=[];for(const e of t)for(const[t,r]of e)null!=r.thisvalue&&(r.allvalues.sort(((t,e)=>t.value-e.value)),r.rank=Yt(r.thisvalue,r.allvalues),delete r.allvalues,r.gene=t,n.push(r));e.send({result:n,samplecount:a.size})})).catch((t=>{t.stack&&console.log(t),t.nodata?e.send({nodata:1}):e.send({error:t.message?t.message:t})}))})),Nt.post(St+"/mdsgeneboxplot",st(yt)),Nt.post(St+"/mdsgenevalueonesample",(async function(t,e){const n=t.query;try{if(!n.sample)throw".sample missing";if(!n.genes)throw".genes[] missing";let r,i,s;if(t.query.iscustom){if(r=yt[n.genome],!r)throw"invalid genome";if(!n.file&&!n.url)throw"no file or url for expression data";i={},s={file:n.file,url:n.url,indexURL:n.indexURL}}else{const[t,e,o,a]=It(n);if(t)throw t;r=e,i=o,s=a}const a=s.file?null:await x.cache_index(s.url,s.indexURL),l={};let c=!0;for(const t of n.genes){let e;await x.get_lines_bigfile({args:[s.file?u.join(o.tpmasterdir,s.file):s.url,t.chr+":"+t.start+"-"+t.stop],dir:a,callback:r=>{const o=r.split("\t");if(!o[3])return;const i=JSON.parse(o[3]);i.gene==t.gene&&i.sample==n.sample&&(e=i.value)}}),Number.isFinite(e)&&(l[t.gene]=e,c=!1)}c?e.send({nodata:1}):e.send({result:l})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/vcf",(async function(t,e){try{const[n,r,o]=ue(t);if(n)throw n;const i=o?await x.cache_index(r,t.query.indexURL):null;if(!t.query.rglst)throw"rglst missing";const s=[];for(const e of t.query.rglst)await x.get_lines_bigfile({args:[r,e.chr+":"+e.start+"-"+e.stop],dir:i,callback:t=>s.push(t)});e.send({linestr:s.join("\n")})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/vcfheader",(async function(t,e){try{if(!t.query.genome)throw"genome missing";const n=yt[t.query.genome];if(!n)throw"invalid genome";const[r,o,i]=ue(t);if(r)throw r;const s=i?await x.cache_index(o,t.query.indexURL):null;e.send({metastr:(await x.get_header_tabix(o,s)).join("\n"),nochr:await x.tabix_is_nochr(o,s,n)})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/translategm",(async function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";const r=t.query.gm;if(!r)throw"missing gm{}";if(!r.chr)throw"gm.chr missing";if(!r.start)throw"gm.start missing";if(!Number.isInteger(r.start))throw"gm.start not integer";if(!r.stop)throw"gm.stop missing";if(!Number.isInteger(r.stop))throw"gm.stop not integer";const o=await x.get_fasta(n,r.chr+":"+(r.start+1)+"-"+r.stop),i=k.fasta2gmframecheck(r,o);e.send({frame:i})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.get(St+"/hicstat",(async function(t,e){Mt(t);try{const[n,r,o]=ue(t);if(n)throw"illegal file name";o||await x.file_is_readable(r);const i=await it(r,o);e.send({out:i})}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.post(St+"/hicdata",(function(t,e){const[n,r,o]=ue(t);if(n)return void e.send({error:"illegal file name"});const i=[t.query.nmeth||"NONE",r,t.query.pos1,t.query.pos2,t.query.isfrag?"FRAG":"BP",t.query.resolution],s=m(wt,i),a=_.createInterface({input:s.stdout}),l=[],c=[];let u=0,f=0;a.on("line",(e=>{const n=e.split("\t");if(3!=n.length)return void u++;const r=Number.parseInt(n[0]),o=Number.parseInt(n[1]),i=Number.parseFloat(n[2]);Number.isNaN(r)||Number.isNaN(o)||Number.isNaN(i)?f++:null!=t.query.mincutoff&&i<=t.query.mincutoff||l.push([r,o,i])})),s.stderr.on("data",(t=>c.push(t))),s.on("close",(()=>{const t=c.join("");return t?e.send({error:t}):u?e.send({error:u+" lines have other than 3 fields"}):f?e.send({error:f+" lines have non-numerical values in any of the 3 fields"}):void e.send({items:l})}))})),Nt.post(St+"/samplematrix",(function(t,e){Promise.resolve().then((()=>{const e=yt[t.query.genome];if(!e)throw"invalid genome";let n,r;if(t.query.iscustom){if(!t.query.querykey2tracks)throw"querykey2tracks{} missing for custom dataset";n={queries:{}};for(const e in t.query.querykey2tracks){const r=t.query.querykey2tracks[e];if(!r.type)throw'missing "type" for a data track';if(r.type==k.tkt.mdsvcf){const r=t.query.querykey2tracks[e];r.type=k.mdsvcftype.vcf,n.queries[e]={type:k.tkt.mdsvcf,info:r.info,tracks:[r]}}else if(r.type==k.tkt.mdssvcnv)n.queries[e]=r;else{if(r.type!=k.tkt.mdsexpressionrank)throw"unknown type of data track: "+r.type;n.queries[e]=r}}}else{if(!e.datasets)throw"genome is not equipped with datasets";if(!t.query.dslabel)throw"dslabel missing";if(n=e.datasets[t.query.dslabel],!n)throw"invalid dslabel";if(!n.queries)throw"dataset is not equipped with queries"}if(t.query.sampleset)r=new Set(t.query.sampleset);else if(t.query.limitsamplebyeitherannotation){if(!n.cohort)throw"limitsamplebyeitherannotation but no cohort in ds";if(!n.cohort.annotation)throw"limitsamplebyeitherannotation but no cohort.annotation in ds";r=new Set;for(const e in n.cohort.annotation){const o=n.cohort.annotation[e];for(const n of t.query.limitsamplebyeitherannotation)if(o[n.key]==n.value){r.add(e);break}}}const o=[];for(const e of t.query.features){let t,i=[];if(e.querykey){if(!n.queries)throw"using querykey for a feature but no ds.queries";if(t=n.queries[e.querykey],!t)throw"unknown dsquery by key "+e.querykey}else if(e.querykeylst){if(!n.queries)throw"using querykeylst for a feature but no ds.queries";for(const t of e.querykeylst){const e=n.queries[t];if(!e)throw'unknown key "'+t+'" from querykeylst';i.push(e)}if(0==i.length)throw"no valid keys in querykeylst"}else if(!e.issampleattribute)throw"unknown way to query a feature";if(e.isgenevalue){const[i,s]=Kt(e,n,t,r);if(i)throw"error with isgenevalue: "+i;o.push(s)}else if(e.iscnv){const[i,s]=Xt(e,n,t,r);if(i)throw"error with iscnv: "+i;o.push(s)}else if(e.isloh){const[i,s]=te(e,n,t,r);if(i)throw"error with isloh: "+i;o.push(s)}else if(e.isvcf){const[i,s]=ie(e,n,t,r);if(i)throw"error with isvcf: "+i;o.push(s)}else if(e.isitd){const[i,s]=ee(e,n,t,r);if(i)throw"error with isitd: "+i;o.push(s)}else if(e.issvfusion){const[i,s]=ne(e,n,t,r);if(i)throw"error with issvfusion: "+i;o.push(s)}else if(e.issvcnv){const[i,s]=re(e,n,t,r);if(i)throw"error with issvcnv: "+i;o.push(s)}else if(e.ismutation){const[t,s]=oe(e,n,i,r);if(t)throw"error with ismutation: "+t;o.push(s)}else{if(!e.issampleattribute)throw"unknown type of feature";{const[t,i]=Qt(e,n,r);if(t)throw"error with issampleattribute: "+t;o.push(i)}}}return Promise.all(o)})).then((t=>{e.send({results:t})})).catch((t=>{e.send({error:"string"==typeof t?t:t.message}),t.stack&&console.error(t.stack)}))})),Nt.get(St+"/mdssamplescatterplot",(async function(t,e){Mt(t);try{const n=yt[t.query.genome];if(!n)throw"invalid genome";const r=n.datasets[t.query.dslabel];if(!r)throw"invalid dataset";if(!r.cohort)throw"no cohort for dataset";if(!r.cohort.annotation)throw"cohort.annotation missing for dataset";const o=r.cohort.scatterplot;if(!o)throw"scatterplot not supported for this dataset";const i=[];for(const e in r.cohort.annotation){const n=r.cohort.annotation[e];if(t.query.subsetkey&&n[t.query.subsetkey]!=t.query.subsetvalue)continue;const s=n[o.x.attribute];if(!Number.isFinite(s))continue;const a=n[o.y.attribute];Number.isFinite(a)&&i.push({sample:e,x:s,y:a,s:n})}e.send({colorbyattributes:o.colorbyattributes,colorbygeneexpression:o.colorbygeneexpression,querykey:o.querykey,dots:i,tracks:o.tracks})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/mdssamplesignature",(function(t,e){try{const n=t.query;if(!n.sample)throw".sample missing";const r=yt[n.genome];if(!r)throw"invalid genome";const o=r.datasets[n.dslabel];if(!o)throw"invalid dataset";if(!o.cohort)throw"no cohort for dataset";if(!o.cohort.mutation_signature)throw"no mutation_signature for cohort";const i=[];for(const t in o.cohort.mutation_signature.sets){const e=o.cohort.mutation_signature.sets[t];if(!e.samples)continue;const r=e.samples.map.get(n.sample);if(!r)continue;const s=[];for(const t in e.signatures)r[t]&&s.push({k:t,v:r[t]});s.length&&i.push({key:t,valuename:e.samples.valuename,annotation:s.sort(((t,e)=>e.v-t.v))})}e.send({lst:i})}catch(t){t.stack&&console.error(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/mdssurvivalplot",lt(yt)),Nt.post(St+"/fimo",rt.handle_closure(yt)),Nt.all(St+"/termdb",P.handle_request_closure(yt)),Nt.all(St+"/termdb-barsql",D.handle_request_closure(yt)),Nt.post(St+"/singlecell",nt.handle_singlecell_closure(yt)),Nt.post(St+"/massSession",et.save),Nt.get(St+"/massSession",et.get),Nt.get(St+"/isoformbycoord",(async function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!t.query.chr)throw"chr missing";const r=Number(t.query.pos);if(!Number.isInteger(r))throw"pos must be positive integer";const i=n.tracks.find((t=>t.__isgene));i||reject("no gene track");const s=[];await x.get_lines_bigfile({args:[u.join(o.tpmasterdir,i.file),t.query.chr+":"+r+"-"+r],callback:t=>{const e=t.split("\t")[3];if(!e)return;const r=JSON.parse(e);if(!r.isoform)return;const o={isoform:r.isoform},i=n.genedb.getjsonbyisoform.get(r.isoform);i&&(o.name=JSON.parse(i.genemodel).name,o.isdefault=i.isdefault),s.push(o)}}),e.send({lst:s})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/ase",(async function(t,e){const n=t.query,r=3e6,i=5e5;try{const t=yt[n.genome];if(!t)throw"invalid genome";if(!n.samplename)throw"samplename missing";if(!n.chr)throw"no chr";if(!n.start||!n.stop)throw"no start/stop";if(!n.rnabarheight)throw"no rnabarheight";if(!n.dnabarheight)throw"no dnabarheight";if(!Number.isInteger(n.barypad))throw"invalid barypad";if(n.rnamax&&!Number.isFinite(n.rnamax))throw"invalid value for rnamax";if(!n.checkrnabam)throw".checkrnabam{} missing";const s=$t(n.checkrnabam);if(s)throw s;if(n.refcolor||(n.refcolor="blue"),n.altcolor||(n.altcolor="red"),!t.tracks)throw"genome.tracks[] missing";const a=t.tracks.find((t=>t.__isgene));if(!a)throw"no gene track from this genome";await async function(t,e){if(t.rnabamfile)t.rnabamfile=u.join(o.tpmasterdir,t.rnabamfile);else{if(!t.rnabamurl)throw"no file or url for rna bam";t.rnabamurl_dir=await x.cache_index(t.rnabamurl,t.rnabamindexURL||t.rnabamurl+".bai")}if(t.rnabam_nochr=await x.bam_ifnochr(t.rnabamfile||t.rnabamurl,e,t.rnabamurl_dir),t.vcffile)t.vcffile=u.join(o.tpmasterdir,t.vcffile);else{if(!t.vcfurl)throw"no file or url for vcf";t.vcfurl_dir=await x.cache_index(t.vcfurl,t.vcfindexURL)}t.vcf_nochr=await x.tabix_is_nochr(t.vcffile||t.vcfurl,t.vcfurl_dir,e)}(n,t);const l=await Wt(t,a,n.chr,n.start,n.stop),f={};if(n.stop-n.start<r)for(const[t,e]of l){const t={file:n.rnabamfile,url:n.rnabamurl,dir:n.rnabamurl_dir,nochr:n.rnabam_nochr};let r;r=n.rnabamispairedend?await Lt(t,n.chr,e):await Ft(t,n.chr,e),e.fpkm=1e9*r/(n.rnabamtotalreads*e.exonlength)}else f.fpkmrangelimit=r;const[d,h,p,y]=function(t,e){let n=t.start,r=t.stop;for(const[t,o]of e)n=Math.min(n,o.start),r=Math.max(r,o.stop);const o=t.start,i=t.stop;return[n,r,o,i]}(n,l),v=await async function(t,e,n,r,o){const i=await Vt(t.vcffile||t.vcfurl,t.vcfurl_dir),[s,a,l,c]=q.vcfparsemeta(i);if(c)throw c;const u={info:s,format:a,samples:l},f=await Ht(t.vcffile||t.vcfurl,(t.vcf_nochr?t.chr.replace("chr",""):t.chr)+":"+r+"-"+o,t.vcfurl_dir),d=[];for(const e of f||[]){const[n,r,o]=q.vcfparseline(e,u);for(const e of r){if(!k.basecolor[e.ref]||!k.basecolor[e.alt])continue;if(!e.sampledata)continue;const n=Jt(e,t.samplename,t.checkrnabam);n&&d.push(n)}}const h=[];for(const t of d)for(const[e,r]of n)if(t.pos>=r.start&&t.pos<=r.stop){h.push(t);break}return h}(n,0,l,d,h);for(const t of v)t.rnacount={nocoverage:1};let b,w;y-p>=i?f.covplotrangelimit=i:(n.rnamax?b=n.rnamax:(b=await async function(t,e,n){let r=0;return await x.get_lines_bigfile({isbam:!0,args:["depth","-r",(t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(e+1)+"-"+(n+1),"-g","DUP",t.rnabamurl||t.rnabamfile],dir:t.rnabamurl_dir,callback:t=>{const e=t.split("\t");if(3!=e.length)return;const n=Number.parseInt(e[2]);Number.isInteger(n)&&(r=Math.max(r,n))}}),r}(n,p,y),f.rnamax=b),w=await async function(t,e,n,r,o){const i=new Map;for(const t of r)t.dnacount.ishet&&t.pos>=e&&t.pos<=n&&i.set(t.pos,t);const s=g(t.width*t.devicePixelRatio,(t.rnabarheight+t.barypad+t.dnabarheight)*t.devicePixelRatio),a=s.getContext("2d");t.devicePixelRatio>1&&a.scale(t.devicePixelRatio,t.devicePixelRatio);let l,c,u=!1;n-e<=t.width?(u=!0,l=1,c=t.width/(n-e),a.lineWidth=c):(c=1,l=(n-e)/t.width);return await x.get_lines_bigfile({isbam:!0,args:["depth","-r",(t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(e+1)+"-"+(n+1),"-g","DUP",t.rnabamurl||t.rnabamfile],dir:t.rnabamurl_dir,callback:n=>{const r=n.split("\t");if(3!=r.length)return;const s=Number.parseInt(r[1])-1;if(!Number.isInteger(s))return;const f=Number.parseInt(r[2]);if(!Number.isInteger(f))return;const d=t.rnabarheight*Math.min(f,o)/o,h=u?(s-e)*c:(s-e)/l;a.strokeStyle="#ccc",a.beginPath(),a.moveTo(h+c/2,t.rnabarheight),a.lineTo(h+c/2,t.rnabarheight-d),a.stroke(),a.closePath(),f>o&&(a.strokeStyle="blue",a.beginPath(),a.moveTo(h+c/2,0),a.lineTo(h+c/2,2),a.stroke(),a.closePath());const p=i.get(s);p&&(p.rnacount.h=d)}}),{canvas:s,ctx:a,isbp:u,binpxw:c,binbpsize:l}}(n,p,y,v,b)),f.coveragesrc=await function(t,e,n,r,o,i,s,a){const l=[];for(const n of e)n.dnacount.ishet&&l.push((t.rnabam_nochr?t.chr.replace("chr",""):t.chr)+":"+(n.pos+1)+"-"+(n.pos+1));return new Promise(((n,r)=>{const c=m(_t,["mpileup","-q",t.checkrnabam.rnapileup_q,"-Q",t.checkrnabam.rnapileup_Q,"--no-reference","-a","INFO/AD","-d",999999,"-r",l.join(","),t.rnabamurl||t.rnabamfile],{cwd:t.rnabamurl_dir});_.createInterface({input:c.stdout}).on("line",(t=>{if("#"==t[0])return;const n=Ut(t);if(!n)return;let r;n.pos>=o&&n.pos<=i&&n.DP;const s=e.find((t=>t.pos==n.pos));if(s){s.__x=r;const t=n.allele2count[s.ref]||0,e=n.allele2count[s.alt]||0;t+e>0&&(delete s.rnacount.nocoverage,s.rnacount.ref=t,s.rnacount.alt=e,s.rnacount.f=e/(t+e))}})),c.on("close",(()=>{if(!s)return void n();const{canvas:r,ctx:l,binpxw:c}=s;l.lineWidth=Math.max(3,c);let u=0;for(const n of e)n.dnacount&&(n.pos<o||n.pos>i||(n.__x=t.width*(n.pos-o)/(i-o),u=Math.max(u,n.dnacount.ref+n.dnacount.alt)));for(const n of e){if(null==n.__x)continue;n.rnacount.nocoverage||(null==n.rnacount.h&&(n.rnacount.h=t.rnabarheight*(n.rnacount.ref+n.rnacount.alt)/a),l.strokeStyle=t.refcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight),l.lineTo(n.__x+c/2,t.rnabarheight-(1-n.rnacount.f)*n.rnacount.h),l.stroke(),l.closePath(),l.strokeStyle=t.altcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight-(1-n.rnacount.f)*n.rnacount.h),l.lineTo(n.__x+c/2,t.rnabarheight-n.rnacount.h),l.stroke(),l.closePath());const e=t.dnabarheight*(n.dnacount.ref+n.dnacount.alt)/u;n.dnacount.ishet&&(l.strokeStyle=t.refcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight+t.barypad),l.lineTo(n.__x+c/2,t.rnabarheight+t.barypad+(1-n.dnacount.f)*e),l.stroke(),l.closePath(),l.strokeStyle=t.altcolor,l.beginPath(),l.moveTo(n.__x+c/2,t.rnabarheight+t.barypad+(1-n.dnacount.f)*e),l.lineTo(n.__x+c/2,t.rnabarheight+t.barypad+e),l.stroke(),l.closePath()),delete n.__x}n(r.toDataURL())}))}))}(n,v,0,0,p,y,w,b),await async function(t,e){if(0==t.length)return;const n=[];for(const r of t)r.rnacount.nocoverage||r.rnacount.ref+r.rnacount.alt<e.checkrnabam.rna_mintotalreads||n.push(r);if(0==n.length)return;const r=await function(t){const e=u.join(o.cachedir,Math.random().toString())+".snp",n=[];for(const e of t)e.rnacount.nocoverage||null!=e.rnacount.ref&&null!=e.rnacount.alt&&n.push(e.pos+"."+e.ref+"."+e.alt+"\t\t\t\t\t\t\t\t"+e.rnacount.ref+"\t"+e.rnacount.alt);return new Promise(((t,r)=>{c.writeFile(e,n.join("\n")+"\n",(n=>{n&&r("cannot write"),t(e)}))}))}(n),i=await Gt(r);await function(t,e){return new Promise(((n,r)=>{c.readFile(e,"utf8",((e,o)=>{e&&r("cannot read binom pvalue"),o||n();for(const e of o.trim().split("\n")){const n=e.split("\t"),r=t.find((t=>n[0]==t.pos+"."+t.ref+"."+t.alt));r&&(r.rnacount.pvalue=Number.parseFloat(n[10]))}n()}))}))}(t,i),c.unlink(r,(()=>{})),c.unlink(i,(()=>{}))}(v,n),f.genes=function(t,e,n){const r=[];for(const[o,i]of e){r.push(i);const e=t.filter((t=>t.pos>=i.start&&t.pos<=i.stop));if(0==e.length){i.nosnp=1;continue}i.snps=e;const o=e.filter((t=>null!=t.rnacount.pvalue));if(0==o.length){i.nornasnp=1;continue}const s=o.reduce(((t,e)=>t+Math.abs(e.rnacount.f-.5)),0);let a=null,l=0;for(const t of o)null==a?a=t.rnacount.pvalue:a*=t.rnacount.pvalue,t.rnacount.pvalue<=n.checkrnabam.binompvaluecutoff&&l++;i.ase={markers:e.filter((t=>t.dnacount.ishet)).length,ase_markers:l,mean_delta:s/o.length,geometricmean:Math.pow(a,1/o.length)}}return r}(v,l,n);let N=0;for(const t of v)t.dnacount&&t.pos>=p&&t.pos<=y&&(N=Math.max(N,t.dnacount.ref+t.dnacount.alt));f.dnamax=N,e.send(f)}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.post(St+"/bamnochr",(async function(t,e){const n=t.query;try{const t=yt[n.genome];if(!t)throw"invalid genome";if(n.file)n.file=u.join(o.tpmasterdir,n.file);else{if(!n.url)throw"no bam file or url";n.url_dir=await x.cache_index(n.url,n.indexURL||n.url+".bai")}const r=await x.bam_ifnochr(n.file||n.url,t,n.url_dir);e.send({nochr:r})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}})),Nt.get(St+"/gene2canonicalisoform",(function(t,e){Mt(t);try{if(!t.query.gene)throw".gene missing";const n=yt[t.query.genome];if(!n)throw"unknown genome";if(!n.genedb.get_gene2canonicalisoform)throw"gene2canonicalisoform not supported on this genome";const r=n.genedb.get_gene2canonicalisoform.get(t.query.gene);e.send(r)}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}})),Nt.get(St+"/ideogram",(function(t,e){try{const n=yt[t.query.genome];if(!n)throw"invalid genome";if(!n.genedb.hasIdeogram)throw"ideogram not supported on this genome";if(!t.query.chr)throw".chr missing";const r=n.genedb.getIdeogramByChr.all(t.query.chr);if(!r.length)throw"no ideogram data for this chr";e.send(r)}catch(t){e.send({error:t.message||t})}})),async function(){try{await c.promises.stat(o.tpmasterdir)}catch(t){const e="Error with "+o.tpmasterdir+": "+t.code;if("validate"==process.argv[2])throw e;return void console.log("\n!!! "+e+"\n")}if(function(){if(o.features.skip_checkDependenciesAndVersions)return void console.log("SKIPPED checkDependenciesAndVersions()");const t=["jsonlite","cmprsk","hwde","lmtest"];for(const e of t){const t=p.spawnSync(o.Rscript,["-e",`suppressPackageStartupMessages(library("${e}"))`],{encoding:"utf8"});if(t.stderr.trim())throw t.stderr}{const t=p.execSync(o.samtools+" --version",{encoding:"utf8"}).trim().split("\n"),[e,n]=t[0].split(" ");if("samtools"!=e||!n)throw'cannot run "samtools version"';const[r,i]=n.split(".");if("1"!=r)throw"samtools not 1.*";if(Number(i)<10)throw"samtools not >= 1.10"}{const t=p.execSync(o.bcftools+" -v",{encoding:"utf8"}).trim().split("\n"),[e,n]=t[0].split(" ");if("bcftools"!=e||!n)throw'cannot run "bcftools version"';const[r,i]=n.split(".");if("1"!=r)throw"bcftools not 1.*";if(Number(i)<10)throw"bcftools not >= 1.10"}}(),xt=function(){const t=c.statSync(o.binpath+"/server.js").mtime,e=c.existsSync("public/bin/proteinpaint.js")&&c.statSync("public/bin/proteinpaint.js").mtime||0;return t>e?t:e}(),kt=Date(Date.now()).toString().split(" ").slice(0,5).join(" "),null!=o.base_zindex){const t=Number.parseInt(o.base_zindex);if(Number.isNaN(t)||t<=0)throw"base_zindex must be positive integer";o.base_zindex=t}if(o.jwt){if(!o.jwt.secret)throw"jwt.secret missing";if(!o.jwt.permissioncheck)throw"jwt.permissioncheck missing"}if(!o.tpmasterdir)throw".tpmasterdir missing";if(!o.cachedir)throw".cachedir missing";o.cachedir_massSession=await pe("massSession"),o.cachedir_massSessionTrash=await pe("massSessionTrash"),o.cache_snpgt={dir:await pe("snpgt"),fileNameRegexp:/[^\w]/,sampleColumn:6},o.cachedir_bam=await pe("bam"),o.cachedir_genome=await pe("genome"),o.cachedir_ssid=await pe("ssid"),o.commonOverrides&&k.applyOverrides(o.commonOverrides);if(!o.genomes)throw".genomes[] missing";if(!Array.isArray(o.genomes))throw".genomes[] not array";for(const t of o.genomes){if(!t.name)throw".name missing from a genome: "+JSON.stringify(t);if(!t.file)throw".file missing from genome "+t.name;const e=u.join(process.cwd(),t.file),n=require(c.existsSync(e)?e:t.file),r=n.default||n;if(yt[t.name]=r,!r.genomefile)throw".genomefile missing from .js file of genome "+t.name;if("NA"==r.genomefile||(r.genomefile=u.join(o.tpmasterdir,r.genomefile)),r.genomicNameRegexp||(r.genomicNameRegexp=/[^a-zA-Z0-9.:_-]/),r.tracks||(r.tracks=[]),t.tracks)for(const e of t.tracks)r.tracks.push(e);if(t.datasets&&(r.rawdslst=t.datasets),t.snp&&(r.snp=t.snp),t.blat){if(!t.blat.host)throw".blat.host missing for "+t.name;if(!t.blat.port)throw".blat.port missing for "+t.name;r.blat=t.blat}if(t.nosnp&&delete r.snp,t.nohicenzyme&&delete r.hicenzymefragment,t.nohicdomain&&delete r.hicdomain,r.genedb&&t.no_gene2canonicalisoform&&delete r.genedb.gene2canonicalisoform,t.updateAttr)for(const e of t.updateAttr){let t=r;for(const[n,r]of e.entries())if(t)if("object"==typeof r)for(const e in r)t[e]=r[e];else{if("string"==typeof t[r]){e[n+1]&&(t[r]=e[n+1]);break}t=t[r]}}}o.defaultgenome&&yt[o.defaultgenome]&&(yt[o.defaultgenome].isdefault=!0);for(const t in yt){const n=yt[t];if(!n.majorchr)throw t+": majorchr missing";if(!n.defaultcoord)throw t+": defaultcoord missing";if(await x.get_fasta(n,n.defaultcoord.chr+":"+n.defaultcoord.start+"-"+(n.defaultcoord.start+1)),n.tracks||(n.tracks=[]),"string"==typeof n.majorchr){const e=n.majorchr.trim().split(/[\s\t\n]+/),r={},o=[];for(let n=0;n<e.length;n+=2){const i=e[n],s=Number.parseInt(e[n+1]);if(Number.isNaN(s))throw t+" majorchr invalid chr size for "+i+" ("+e[n+1]+")";r[i]=s,o.push(i)}n.majorchr=r,n.majorchrorder=o}n.chrlookup={};for(const t in n.majorchr)n.chrlookup[t.toUpperCase()]={name:t,len:n.majorchr[t],major:!0};if(n.minorchr){if("string"==typeof n.minorchr){const e=n.minorchr.trim().split(/[\s\t\n]+/),r={};for(let n=0;n<e.length;n+=2){const o=Number.parseInt(e[n+1]);if(Number.isNaN(o))throw t+" minorchr invalid chr size for "+e[n]+" ("+e[n+1]+")";r[e[n]]=o}n.minorchr=r}for(const t in n.minorchr)n.chrlookup[t.toUpperCase()]={name:t,len:n.minorchr[t]}}if(n.genedb){if(!n.genedb.dbfile)throw t+": .genedb.dbfile missing";try{console.log("Connecting",n.genedb.dbfile),n.genedb.db=x.connect_db(n.genedb.dbfile)}catch(t){throw`Cannot connect genedb: ${n.genedb.dbfile}: ${t}`}n.genedb.getnamebynameorisoform=n.genedb.db.prepare("select name from genes where name=? or isoform=?"),n.genedb.getnamebyisoform=n.genedb.db.prepare("select distinct name from genes where isoform=?"),n.genedb.getjsonbyname=n.genedb.db.prepare("select isdefault,genemodel from genes where name=?"),n.genedb.getjsonbyisoform=n.genedb.db.prepare("select isdefault,genemodel from genes where isoform=?"),n.genedb.getnameslike=n.genedb.db.prepare("select distinct name from genes where name like ? limit 20");const e=ht(n.genedb.db);e.has("genealias")&&(n.genedb.getNameByAlias=n.genedb.db.prepare("select name from genealias where alias=?"),n.genedb.tableSize=n.genedb.db.prepare("select count(*) from genealias where alias=?")),e.has("gene2coord")&&(n.genedb.getCoordByGene=n.genedb.db.prepare("select * from gene2coord where name=?")),e.has("ideogram")?(n.genedb.hasIdeogram=!0,n.genedb.getIdeogramByChr=n.genedb.db.prepare("select * from ideogram where chromosome=?")):n.genedb.hasIdeogram=!1,e.has("gene2canonicalisoform")&&(n.genedb.get_gene2canonicalisoform=n.genedb.db.prepare("select isoform from gene2canonicalisoform where gene=?")),e.has("buildDate")&&(n.genedb.get_buildDate=n.genedb.db.prepare("select date from buildDate")),n.genedb.hasTable_refseq2ensembl=e.has("refseq2ensembl"),n.genedb.sqlTables=[...e],n.genedb.tableSize={};for(const t of e)"buildDate"!=t&&(n.genedb.tableSize[t]=n.genedb.db.prepare(`select count(*) as size from ${t}`).get().size)}if(n.termdbs)for(const r in n.termdbs)dt(n.termdbs[r],e.features),console.log(`${r} initiated as ${t}-level termdb`);for(const t of n.tracks)if(t.__isgene){if(!t.file)throw"Tabix file missing for gene track: "+JSON.stringify(t);try{await x.validate_tabixfile(u.join(o.tpmasterdir,t.file))}catch(e){throw"Error with "+t.file+": "+e}}if(n.proteindomain){if(!n.proteindomain.dbfile)throw t+".proteindomain: missing dbfile for sqlite db";if(!n.proteindomain.statement)throw t+".proteindomain: missing statement for sqlite db";let e;try{console.log("Connecting",n.proteindomain.dbfile),e=x.connect_db(n.proteindomain.dbfile)}catch(t){throw"Error with "+n.proteindomain.dbfile+": "+t}n.proteindomain.getbyisoform=e.prepare(n.proteindomain.statement)}if(n.snp){if(!n.snp.bigbedfile)throw t+".snp: missing bigBed file";n.snp.bigbedfile=u.join(o.tpmasterdir,n.snp.bigbedfile),await x.file_is_readable(n.snp.bigbedfile)}if(n.clinvarVCF){if(!n.clinvarVCF.file)throw t+".clinvarVCF: VCF file missing";n.clinvarVCF.file=u.join(o.tpmasterdir,n.clinvarVCF.file);try{await x.validate_tabixfile(n.clinvarVCF.file)}catch(t){throw"Error with "+n.clinvarVCF.file+": "+t}if(!n.clinvarVCF.infokey)throw t+".clinvarVCF.infokey missing";if(!n.clinvarVCF.categories)throw t+".clinvarVCF.categories{} missing";{const e=p.execSync(vt+" -H "+n.clinvarVCF.file,{encoding:"utf8"}).trim();if(!e)throw t+".clinvarVCF: no meta/header lines";const[r,o,i,s]=q.vcfparsemeta(e.split("\n"));if(s)throw t+".clinvarVCF: error parsing vcf meta: "+s.join("\n");if(!r[n.clinvarVCF.infokey])throw t+".clinvarVCF: unknown INFO key for "+n.clinvarVCF.infokey;n.clinvarVCF.info=r,n.clinvarVCF.format=o}{const e=p.execSync(vt+" -l "+n.clinvarVCF.file,{encoding:"utf8"}).trim();if(""==e)throw t+".clinvarVCF: no chr listing";n.clinvarVCF.nochr=k.contigNameNoChr(n,e.split("\n"))}}if(n.fimo_motif){if(!n.fimo_motif.db)throw t+".fimo_motif: db file missing";if(n.fimo_motif.db=u.join(o.tpmasterdir,n.fimo_motif.db),n.fimo_motif.annotationfile){const[t,e]=fe(c.readFileSync(u.join(o.tpmasterdir,n.fimo_motif.annotationfile),{encoding:"utf8"}).trim());n.fimo_motif.tf2attr={};for(const t of e)n.fimo_motif.tf2attr[t.Model.split("_")[0]]=t}}if(n.hicenzymefragment){if(!Array.isArray(n.hicenzymefragment))throw"hicenzymefragment should be an array";for(const t of n.hicenzymefragment){if(!t.enzyme)throw".enzyme missing for one element of hicenzymefragment[]";if(!t.file)throw".file missing for one element of hicenzymefragment[]";try{await x.validate_tabixfile(u.join(o.tpmasterdir,t.file))}catch(e){throw"Error with "+t.file+": "+e}}}if(n.hicdomain){if(!n.hicdomain.groups)throw".groups{} missing from hicdomain";for(const t in n.hicdomain.groups){const e=n.hicdomain.groups[t];if(!e.name)throw".name missing from hicdomain "+t;if(!e.sets)throw".set{} missing from hicdomain "+t;for(const n in e.sets){const r=e.sets[n];if(!r.name)throw".name missing from hicdomain "+t+" > "+n;if(!r.file)throw".file missing from hicdomain "+t+" > "+n;r.file=u.join(o.tpmasterdir,r.file);try{await x.validate_tabixfile(r.file)}catch(t){throw"Error with "+r.file+": "+t}}}}if(n.rawdslst){n.datasets={};for(const e of n.rawdslst){if(!e.name)throw"a nameless dataset from "+t;if(n.datasets[e.name])throw t+" has duplicating dataset name: "+e.name;if(!e.jsfile)throw"jsfile not available for dataset "+e.name+" of "+t;const r=u.join(process.cwd(),e.jsfile),o=require(c.existsSync(r)?r:e.jsfile),i="function"==typeof o?o(k):"function"==typeof(null==o?void 0:o.default)?o.default(k):o.default||o;if(Q(i,e),i.noHandleOnClient=e.noHandleOnClient,i.label=e.name,i.genomename=t,n.datasets[i.label]=i,i.isMds3)try{await X.init(i,n,e,Nt,St)}catch(t){throw t.stack&&console.log(t.stack),"Error with mds3 dataset "+i.label+": "+t}else if(i.isMds)try{await ge(i,n,e)}catch(t){throw"Error with mds dataset "+i.label+": "+t}else he(i,n)}de(),delete n.rawdslst}}}().then((async()=>{if(console.log(`\n${new Date} ${o.commitHash||""}`),console.log("\nValidation succeeded.\n"),"validate"!=process.argv[2])if("phewas-precompute"!=process.argv[2])await async function(){try{if(o.preListenScript){const{cmd:t,args:e}=o.preListenScript,n=p.spawnSync(t,e,{encoding:"utf-8"});if(n.stderr.trim())throw n.stderr.trim();console.log(n.stdout)}o.appEnable&&o.appEnable.forEach((t=>Nt.enable(t)));const t=o.port,e=`STANDBY AT PORT ${t}`;if(o.ssl){const n={key:c.readFileSync(o.ssl.key),cert:c.readFileSync(o.ssl.cert)},r=await l.createServer(n,Nt);return r.listen(t,"0.0.0.0",(()=>{console.log(`HTTPS ${e}`)})),r}{const n=await a.createServer(Nt);return n.listen(t,"0.0.0.0",(()=>{process.send&&process.send("ready"),console.log(e)})),n}}catch(t){throw t}}();else{const t=process.argv[3],e=process.argv[4],n=yt[t];if(!n)throw"invalid genome name: "+t;const r=n.datasets[e];if(!r)throw"invalid dataset: "+e;at.do_precompute(r)}else console.log("You may now run the server.")})).catch((t=>{let e=1;if(!c.existsSync(o.tpmasterdir)){const t=o.maintenance||{};if("start"in t&&"stop"in t&&"tpErrorCode"in t){const n=+new Date(t.start),r=+new Date(t.stop),o=+new Date;n<=o&&o<=r&&(e=t.tpErrorCode)}}t.stack&&console.log(t.stack),e?console.error("\n!!!\n"+t+"\n\n"):console.log("\n!!!\n"+t+"\n\n"),process.exit(e)})),e.log=Mt,e.boxplot_getvalue=function(t){const e=t.length;if(e<5)return{out:t};const n=t[Math.floor(e/2)].value,r=t[Math.floor(e/4)].value,o=t[Math.floor(3*e/4)].value,i=t[Math.floor(.05*e)].value,s=t[Math.floor(.95*e)].value,a=(t[Math.floor(.01*e)].value,o-r);let l,c;if(0==a)l=0,c=0;else{const n=t.findIndex((t=>t.value>r-1.5*a));l=t[-1==n?0:n].value;const i=t.findIndex((t=>t.value>o+1.5*a));c=t[-1==i?e-1:i-1].value}const u=t.filter((t=>t.value<r-1.5*a||t.value>o+1.5*a));return{w1:l,w2:c,p05:i,p25:r,p50:n,p75:o,p95:s,iqr:a,out:u}};function ae(t){delete t.mclasslabel2key,delete t.sample2disease,delete t.patient2ori2sample}const le=Object.freeze([".bam",".bai",".gz",".tbi",".csi",".bw",".bb"]);function ce(t,e=!1,n=!0){if("/"==t[0])return!0;if(t.includes('"')||t.includes("'"))return!0;if(t.includes("|")||t.includes("&"))return!0;if(t.includes(" "))return!0;if(-1!=t.indexOf(".."))return!0;if(t.match(/(\<script|script\>)/i))return!0;if(e&&o.whiteListPaths){let e=!0;for(const n of o.whiteListPaths){if(t.startsWith(n)||"!"!=n[0]&>(t,n)){e=!1;break}if("!"==n[0]&&!gt(t,n)){e=!0;break}}if(e)return!0}if(n)for(const e of le)if(e===u.extname(t).toLowerCase())return!0;return!1}function ue(t,e=!0){let n=null,r=!1;if(t.query.file){if(n=t.query.file,ce(n,e,!1))return["illegal file path"];n=u.join(o.tpmasterdir,n)}else if(t.query.url){if(n=t.query.url,n.includes(" "))return["url must not contain whitespace"];if(n.includes('"')||n.includes("'"))return["url must not contain single or double quotes"];r=!0}return n?[null,n,r]:["file unspecified"]}function fe(t){const e=t.split(/\r?\n/);if(e.length<=1||!e[0])return[null,[]];const n=e[0].split("\t"),r=[];for(let t=1;t<e.length;t++){if("#"==e[t][0])continue;const o=e[t].split("\t"),i={};for(let t=0;t<n.length;t++){const e=o[t];e&&(i[n[t]]=e)}r.push(i)}return[null,r]}async function de(){const t=await c.promises.readdir(o.cachedir_massSession);try{t.forEach((async t=>{const e=(await c.promises.stat(u.join(o.cachedir_massSession,t))).birthtime,n=new Date,r=new Date(e),i=o.features.massSessionDuration||30;Math.round((n.getTime()-r.getTime())/864e5)>i&&(await c.promises.copyFile(u.join(o.cachedir_massSession,t),u.join(o.cachedir_massSessionTrash,t)),await c.promises.unlink(u.join(o.cachedir_massSession,t)),console.log("File deleted: ",t,e))}))}catch(t){throw`Error: ${t}`}}function he(t,e){if(t.dbfile)try{console.log("Connecting",t.dbfile),t.newconn=x.connect_db(t.dbfile)}catch(e){throw"Error with "+t.dbfile+": "+e}if(t.snvindel_attributes)for(const e of t.snvindel_attributes)if(e.lst)for(const t of e.lst)t.get=t.get.toString();else e.get=e.get.toString();if(t.cohort){if(t.cohort.levels){if(!Array.isArray(t.cohort.levels))throw"cohort.levels must be array for "+t.genomename+"."+t.label;if(0==t.cohort.levels.length)throw"levels is blank array for cohort of "+t.genomename+"."+t.label;for(const e of t.cohort.levels)if(!e.k)throw".k key missing in one of the levels, .cohort, in "+t.genomename+"."+t.label}if(t.cohort.fromdb){if(!t.cohort.fromdb.sql)throw".sql missing from ds.cohort.fromdb in "+t.genomename+"."+t.label;const e=t.newconn.prepare(t.cohort.fromdb.sql).all();delete t.cohort.fromdb,t.cohort.raw=e,console.log(e.length+" rows retrieved for "+t.label+" sample annotation")}if(t.cohort.files){let e=[];for(const n of t.cohort.files){if(!n.file)throw".file missing from one of cohort.files[] for "+t.genomename+"."+t.label;const r=c.readFileSync(u.join(o.tpmasterdir,n.file),"utf8").trim();if(!r)throw n.file+" is empty for "+t.genomename+"."+t.label;e=[...e,...R.tsvParse(r)]}delete t.cohort.files,t.cohort.raw?t.cohort.raw=[...t.cohort.raw,...e]:t.cohort.raw=e,console.log(e.length+" rows retrieved for "+t.label+" sample annotation")}if(t.cohort.tosampleannotation){if(!t.cohort.tosampleannotation.samplekey)throw".samplekey missing from .cohort.tosampleannotation for "+t.genomename+"."+t.label;if(!t.cohort.key4annotation)throw".cohort.key4annotation missing when .cohort.tosampleannotation is on for "+t.genomename+"."+t.label}}if(!t.queries)throw".queries missing from dataset "+t.label+", "+t.genomename;if(!Array.isArray(t.queries))throw t.label+".queries is not array";for(const n of t.queries){const r=me(n,t,e);if(r)throw'Error parsing a query in "'+t.label+'": '+r}if(t.vcfinfofilter){const e=k.validate_vcfinfofilter(t.vcfinfofilter);if(e)throw t.label+": vcfinfofilter error: "+e}if(t.url4variant)for(const e of t.url4variant){if(!e.makelabel)throw"makelabel() missing for one item of url4variant from "+t.label;if(!e.makeurl)throw"makeurl() missing for one item of url4variant from "+t.label;e.makelabel=e.makelabel.toString(),e.makeurl=e.makeurl.toString()}}async function pe(t){const e=u.join(o.cachedir,t);try{await c.promises.stat(e)}catch(t){if("ENOENT"!=t.code)throw"error stating dir";try{await c.promises.mkdir(e)}catch(t){throw"cannot make dir"}}return e}function me(t,e,n){if(!t.name)return".name missing";if(t.dsblocktracklst){if(!Array.isArray(t.dsblocktracklst))return"dsblocktracklst not an array in "+e.label;for(const n of t.dsblocktracklst){if(!n.type)return"missing type for a blocktrack of "+e.label;if(!n.file&&!n.url)return"neither file or url given for a blocktrack of "+e.label}}else if(t.vcffile){const e=p.execSync(vt+" -H "+u.join(o.tpmasterdir,t.vcffile),{encoding:"utf8"}).trim();if(""==e)return"no meta lines in VCF file "+t.vcffile+" of query "+t.name;const[r,i,s,a]=q.vcfparsemeta(e.split("\n"));if(a)return"error parsing VCF meta lines of "+t.vcffile+": "+a.join("; ");t.vcf={vcfid:Math.random().toString(),info:r,format:i,samples:s},t.hlinfo&&(t.vcf.hlinfo=t.hlinfo,delete t.hlinfo),t.infopipejoin&&(t.vcf.infopipejoin=t.infopipejoin,delete t.infopipejoin);const l=p.execSync(vt+" -l "+u.join(o.tpmasterdir,t.vcffile),{encoding:"utf8"}).trim();if(""==l)return"tabix -l found no chromosomes/contigs in "+t.vcffile+" of query "+t.name;t.vcf.nochr=k.contigNameNoChr(n,l.split("\n"));let c=0;if(r)for(const t in r)c++;console.log("Parsed vcf meta from "+t.vcffile+": "+c+" INFO, "+s.length+" sample, "+(t.vcf.nochr?'no "chr"':'has "chr"'))}else{if(!t.makequery)return"do not know how to parse query: "+t.name;if(t.isgeneexpression){if(!t.config)return"config object missing for gene expression query of "+t.name;t.config.maf&&(t.config.maf.get=t.config.maf.get.toString())}}}async function ge(t,e,n){if((t.isMds2||t.isMds3||t.isMds)&&Q(t,n),t.assayAvailability){if(!t.assayAvailability.file)throw".assayAvailability.file missing";if(!t.assayAvailability.assays)throw".assayAvailability.assays[] missing";Object.freeze(t.assayAvailability.assays),t.assayAvailability.samples=new Map;for(const e of c.readFileSync(u.join(o.tpmasterdir,t.assayAvailability.file),{encoding:"utf8"}).trim().split("\n")){const[n,r]=e.split("\t");t.assayAvailability.samples.set(n,JSON.parse(r))}console.log(t.assayAvailability.samples.size+" samples with assay availability ("+t.label+")")}if(t.gene2mutcount){if(!t.gene2mutcount.dbfile)throw".gene2mutcount.dbfile missing";try{console.log("Connecting",t.gene2mutcount.dbfile),t.gene2mutcount.db=x.connect_db(t.gene2mutcount.dbfile),console.log("DB connected for "+t.label+": "+t.gene2mutcount.dbfile)}catch(t){throw"Error connecting db at ds.gene2mutcount.dbfile"}}if(t.sampleAssayTrack){if(!t.sampleAssayTrack.file)throw".file missing from sampleAssayTrack";t.sampleAssayTrack.samples=new Map;let e=0,n=new Set;for(const r of c.readFileSync(u.join(o.tpmasterdir,t.sampleAssayTrack.file),{encoding:"utf8"}).trim().split("\n")){if(!r)continue;if("#"==r[0])continue;const[o,i,s]=r.split("\t");if(!i||!s)continue;if(!t.sampleAssayTrack.samples.has(o)){if(t.cohort&&t.cohort.annotation&&!t.cohort.annotation[o]){n.add(o);continue}t.sampleAssayTrack.samples.set(o,[])}const a=JSON.parse(s);if(!k.tkt[a.type])throw"invalid type from a sample track: "+s;a.name||(a.name=o+" "+i),a.assayName=i,t.sampleAssayTrack.samples.get(o).push(a),e++}console.log(e+" assay-tracks from "+t.sampleAssayTrack.samples.size+" samples ("+t.label+")"),n.size&&console.log("Error: "+n.size+" samples with assay tracks are unannotated: "+[...n].join(" "))}if(t.singlesamplemutationjson){const e=t.singlesamplemutationjson;if(!e.file)throw".file missing from singlesamplemutationjson";e.samples={};let n=0;for(const t of c.readFileSync(u.join(o.tpmasterdir,e.file),{encoding:"utf8"}).trim().split("\n")){if(!t)continue;if("#"==t[0])continue;const[r,o]=t.split("\t");r&&o&&(n++,e.samples[r]=o)}console.log(n+" samples for disco plot")}if(t.cohort&&t.cohort.db&&t.cohort.termdb&&await K.init_db(t,Nt,St),t.cohort&&t.cohort.files){if(!Array.isArray(t.cohort.files))throw".cohort.files is not array";if(!t.cohort.tohash)throw".tohash() missing from cohort";if("function"!=typeof t.cohort.tohash)throw".cohort.tohash is not function";if(!t.cohort.samplenamekey)throw".samplenamekey missing";if(t.cohort.annotation={},t.cohort.mutation_signature){const e=t.cohort.mutation_signature;if(!e.sets)throw".mutation_signature.sets missing";for(const n in e.sets){const r=e.sets[n];if(r.name||(r.name=n),!r.signatures)throw".signatures{} missing from a signature set";if(r.samples){if(!r.samples.file)throw".samples.file missing from a signature set";const[e,n]=fe(c.readFileSync(u.join(o.tpmasterdir,r.samples.file),{encoding:"utf8"}).trim());r.samples.map=new Map;for(const e of n){const n=e[t.cohort.samplenamekey];if(!n)throw t.cohort.samplenamekey+" missing in file "+r.samples.file;r.samples.map.set(n,e);for(const t in r.signatures)if(e[t]){const o=Number.parseFloat(e[t]);if(Number.isNaN(o))throw"mutation signature value is not float: "+e[t]+" from sample "+n;r.samples.skipzero&&0==o?delete e[t]:e[t]=o}}}}}if(t.cohort.attributes){if(!t.cohort.attributes.lst)throw".lst[] missing for cohort.attributes";if(!Array.isArray(t.cohort.attributes.lst))return".cohort.attributes.lst is not array";for(const e of t.cohort.attributes.lst){if(!e.key)throw".key missing from one of the .cohort.attributes.lst[]";if(!e.label)throw".label missing from one of the .cohort.attributes.lst[]";if(!e.values)throw".values{} missing from "+e.label+" of .cohort.attributes.lst";for(const t in e.values)if(!e.values[t].label)throw".label missing from one value of "+e.label+" in .cohort.attributes.lst"}if(t.cohort.attributes.defaulthidden)for(const e in t.cohort.attributes.defaulthidden){const n=t.cohort.attributes.lst.find((t=>t.key==e));if(!n)throw"invalid defaulthidden key: "+e;for(const r in t.cohort.attributes.defaulthidden[e])if(!n.values[r])throw"invalid defaulthidden value "+r+" for "+e}}if(t.cohort.hierarchies){if(!t.cohort.hierarchies.lst)throw".lst[] missing from .cohort.hierarchies";if(!Array.isArray(t.cohort.hierarchies.lst))throw".cohort.hierarchies.lst is not array";for(const e of t.cohort.hierarchies.lst){if(!e.name)throw".name missing from one hierarchy";if(!e.levels)throw".levels[] missing from one hierarchy";if(!Array.isArray(e.levels))throw".levels is not array from one hierarchy";for(const t of e.levels)if(!t.k)throw".k missing from one level in hierarchy "+e.name}}if(t.cohort.sampleAttribute){if(!t.cohort.sampleAttribute.attributes)throw"attributes{} missing from cohort.sampleAttribute";for(const e in t.cohort.sampleAttribute.attributes){const n=t.cohort.sampleAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from cohort.sampleAttribute.attributes";if(n.values)for(const t in n.values){const e=n.values[t];if("object"!=typeof e)throw'value "'+t+'" not pointing to {} from sampleAttribute';e.name||(e.name=t)}if(n.showintrack&&!n.isinteger&&!n.isfloat)throw n.label+": .showintrack requires .isinteger or .isfloat"}}if(t.cohort.scatterplot){if(!t.cohort.sampleAttribute)throw".sampleAttribute missing but required for .cohort.scatterplot";const e=t.cohort.scatterplot;if(!e.querykey)throw".querykey missing from .cohort.scatterplot";{if(!t.queries)throw".cohort.scatterplot.querykey in use but ds.queries{} missing";const n=t.queries[e.querykey];if(!n)throw"unknown query by .cohort.scatterplot.querykey: "+e.querykey;if(n.type!=k.tkt.mdssvcnv)throw"type is not "+k.tkt.mdssvcnv+" of the track pointed to by .cohort.scatterplot.querykey"}if(e.colorbygeneexpression){if(!e.colorbygeneexpression.querykey)throw"querykey missing from .cohort.scatterplot.colorbygeneexpression";if(!t.queries)throw".cohort.scatterplot.colorbygeneexpression in use but ds.queries{} missing";const n=t.queries[e.colorbygeneexpression.querykey];if(!n)throw"unknown query by .cohort.scatterplot.colorbygeneexpression.querykey: "+e.colorbygeneexpression.querykey;if(!n.isgenenumeric)throw"isgenenumeric missing from the track pointed to by .cohort.scatterplot.colorbygeneexpression.querykey"}if(e.tracks,!e.x)throw".x missing from .cohort.scatterplot";if(!e.x.attribute)throw".attribute missing from .cohort.scatterplot.x";const n=t.cohort.sampleAttribute.attributes[e.x.attribute];if(!n)throw"scatterplot.x.attribute is not defined in sampleAttribute";if(!n.isfloat)throw'scatterplot.x is not "isfloat"';if(!e.y)throw".y missing from .cohort.scatterplot";if(!e.y.attribute)throw".attribute missing from .cohort.scatterplot.y";const r=t.cohort.sampleAttribute.attributes[e.y.attribute];if(!r)throw"scatterplot.y.attribute is not defined in sampleAttribute";if(!r.isfloat)throw'scatterplot.y is not "isfloat"';if(e.colorbyattributes)for(const n of e.colorbyattributes){if(!n.key)throw".key missing from one of scatterplot.colorbyattributes";const e=t.cohort.sampleAttribute.attributes[n.key];if(!e)throw"unknown attribute by key "+n.key+" from scatterplot.colorbyattributes";n.label=e.label,n.values=e.values}}for(const e of t.cohort.files){if(!e.file)throw".file missing from one of .cohort.files";const[n,r]=fe(c.readFileSync(u.join(o.tpmasterdir,e.file),{encoding:"utf8"}).trim());if(n)throw'cohort annotation file "'+e.file+'": '+n;console.log(t.label+": "+r.length+" samples loaded from annotation file "+e.file),r.forEach((e=>{for(const n in e){let r;t.cohort.sampleAttribute&&(r=t.cohort.sampleAttribute.attributes[n]),r||t.cohort.termdb&&t.cohort.termdb.termjson&&t.cohort.termdb.termjson.map&&(r=t.cohort.termdb.termjson.map.get(n)),r&&(r.isfloat?e[n]=Number.parseFloat(e[n]):r.isinteger&&(e[n]=Number.parseInt(e[n])))}t.cohort.tohash(e,t)}))}if(t.cohort.annorows=Object.values(t.cohort.annotation),console.log(t.label+": total samples from sample table: "+t.cohort.annorows.length),t.cohort.survivalplot){const e=t.cohort.survivalplot;if(!e.plots)throw".plots{} missing from survivalplot";e.init={plottypes:[]};for(const t in e.plots){const n=e.plots[t];if(!n.name)throw".name missing from survivalplot "+t;if(!n.serialtimekey)throw".serialtimekey missing from survivalplot "+t;if(!n.iscensoredkey)throw".iscensoredkey missing from survivalplot "+t;if(!n.timelabel)throw".timelabel missing from survivalplot "+t;n.key=t,e.init.plottypes.push({key:t,name:n.name,timelabel:n.timelabel})}if(e.samplegroupattrlst){e.init.samplegroupings=[];for(const n of e.samplegroupattrlst){if(!n.key)throw".key missing from an attr of samplegroupattrlst for survival";const r=t.cohort.sampleAttribute.attributes[n.key];if(!r)throw'unknown attribute key "'+n.key+'" from survival samplegroupattrlst';const o=new Map;for(const r in t.cohort.annotation){const i=t.cohort.annotation[r],s=i[n.key];if(null==s)continue;let a=!1;for(const t in e.plots)if(null!=i[e.plots[t].serialtimekey]){a=!0;break}a&&(o.has(s)?o.set(s,o.get(s)+1):o.set(s,1))}if(0==o.size)throw'no value found for "'+n.key+'" from survival samplegroupattrlst';const i=[];for(const[t,e]of o)i.push({value:t,count:e});e.init.samplegroupings.push({key:n.key,label:r.label,values:i})}}}}if(t.mutationAttribute){if(!t.mutationAttribute.attributes)throw"attributes{} missing from mutationAttribute";for(const e in t.mutationAttribute.attributes){const n=t.mutationAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from mutationAttribute.attributes";if(!n.appendto_link&&n.values)for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from mutationAttribute.attributes"}}}if(t.alleleAttribute){if(!t.alleleAttribute.attributes)throw"attributes{} missing from alleleAttribute";for(const e in t.alleleAttribute.attributes){const n=t.alleleAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from alleleAttribute.attributes";if(!n.isnumeric){if(!n.values)throw".values{} missing for non-numeric key "+e+" from alleleAttribute.attributes";for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from alleleAttribute.attributes"}}}}if(t.locusAttribute){if(!t.locusAttribute.attributes)throw"attributes{} missing from locusAttribute";for(const e in t.locusAttribute.attributes){const n=t.locusAttribute.attributes[e];if(!n.label)throw".label missing for key "+e+" from locusAttribute.attributes";if(!n.isnumeric&&!n.appendto_link){if(!n.values)throw".values{} missing for non-numeric key "+e+" from locusAttribute.attributes";for(const t in n.values){if(!n.values[t].name)throw".name missing for value "+t+" of key "+e+" from locusAttribute.attributes"}}}}if(t.queries)for(const r in t.queries){if(n.remove_queries&&-1!=n.remove_queries.indexOf(r)){delete t.queries[r];continue}const o=t.queries[r];if(n.hide_queries&&-1!=n.hide_queries.indexOf(r)&&(o.hideforthemoment=1),o.istrack){if(!o.type)throw".type missing for track query "+r;if(o.viewrangeupperlimit&&!Number.isInteger(o.viewrangeupperlimit))throw".viewrangeupperlimit should be integer for track query "+r;if(o.type==k.tkt.mdsjunction){const n=ve(o,t,e);if(n)throw r+" (mdsjunction) error: "+n}else if(o.type==k.tkt.mdscnv){const n=we(o,t,e);if(n)throw r+" (mdscnv) error: "+n}else if(o.type==k.tkt.mdssvcnv){const n=xe(o,t,e);if(n)throw r+" (svcnv) error: "+n}else{if(o.type!=k.tkt.mdsvcf)throw"unknown track type for a query: "+o.type+" "+r;{const n=await qe(o,t,e);if(n)throw r+" (vcf) error: "+n}}ye(o,t)}else{if(!o.isgenenumeric)throw"unknown type of query from "+r;{const n=ke(o,t,e);if(n)throw r+" (genenumeric) error: "+n}}}if(t.track&&await K.init_track(t,e),t.annotationsampleset2matrix){if(!t.cohort)throw"ds.cohort misssing when annotationsampleset2matrix is in use";if(!t.cohort.annotation)throw"ds.cohort.annotation misssing when annotationsampleset2matrix is in use";if(!t.queries)throw"ds.queries misssing when annotationsampleset2matrix is in use";if(!t.annotationsampleset2matrix.key)throw".key STR missing in annotationsampleset2matrix";if(!t.annotationsampleset2matrix.groups)throw".groups{} missing in annotationsampleset2matrix";if("object"!=typeof t.annotationsampleset2matrix.groups)throw"ds.annotationsampleset2matrix.groups{} not an object";for(const e in t.annotationsampleset2matrix.groups){const n=t.annotationsampleset2matrix.groups[e];if(!n.groups||!Array.isArray(n.groups)||0==n.groups.length)throw".groups[] must be nonempty array in "+e;for(const r of n.groups){if(!r.name)throw".name missing from one of .groups[] in "+e;const n=r.matrixconfig;if(!n)throw".matrixconfig missing from one of .groups[] of "+e;if(!n.features)throw".features[] missing from group "+e;if(!Array.isArray(n.features))throw".features[] should be array from group "+e;if(0==n.features.length)throw".features[] zero length from group "+e;for(const r of n.features){if(t.annotationsampleset2matrix.commonfeatureattributes)for(const e in t.annotationsampleset2matrix.commonfeatureattributes)null==r[e]&&(r[e]=t.annotationsampleset2matrix.commonfeatureattributes[e]);if(!r.ismutation)return"unknown feature type from group "+e;if(!r.position)throw"position missing from feature "+JSON.stringify(r)+" from group "+e;if(!r.querykeylst)throw".querykeylst[] missing from ismutation feature from group "+e;if(!Array.isArray(r.querykeylst))throw".querykeylst[] not an array from ismutation feature from group "+e;if(0==r.querykeylst.length)throw".querykeylst[] zero length from ismutation feature from group "+e;for(const n of r.querykeylst)if(!t.queries[n])throw'unknown query key "'+n+'" from ismutation feature of group '+e}if(!n.limitsamplebyeitherannotation)throw".limitsamplebyeitherannotation[] missing from group "+e;if(!Array.isArray(n.limitsamplebyeitherannotation))throw".limitsamplebyeitherannotation[] should be array from group "+e;if(0==n.limitsamplebyeitherannotation.length)throw".limitsamplebyeitherannotation[] zero length from group "+e;for(const t of n.limitsamplebyeitherannotation){if(!t.key)throw"key missing from one of limitsamplebyeitherannotation from group "+e;if(!t.value)throw"value missing from one of limitsamplebyeitherannotation from group "+e}}}delete t.annotationsampleset2matrix.commonfeatureattributes}}function ye(t,e){if(t.groupsamplebyattr){t.groupsamplebyattr.key2group=new Map;for(const n in e.cohort.annotation)Zt(n,[],t.groupsamplebyattr.key2group,[],e,t)}}function ve(t,e,n){if(t.readcountCutoff&&(!Number.isInteger(t.readcountCutoff)||t.readcountCutoff<1))return"readcountCutoff must be positive integer";let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;t.file=n,r=n}else{if(!t.url)return"no file or url given for mdsjunction "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=i.split("\n");if(1!=n.length)return"mdsjunction file has multiple header lines (begin with #), but should have just 1";const r=n[0].split("\t");if(r[5]){t.samples=r.slice(5),t.attributeSummary=be(t.samples,e),t.hierarchySummary=_e(t.samples,e);for(const e in t.hierarchySummary){let n=0;for(const r in t.hierarchySummary[e])n++;console.log(n+" "+e+" hierarchy levels for "+t.name)}}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}if(console.log("(mdsjunction) "+t.name+": "+(t.samples?t.samples.length:0)+" samples, "+(t.nochr?'no "chr"':'has "chr"')),!t.infoFilter)return".infoFilter{} missing";if(!t.infoFilter.lst)return".lst[] missing from .infoFilter";for(const e of t.infoFilter.lst){if(!e.key)return".key missing from one of infoFilter";if(!e.label)return".label missing from one of infoFilter";if(!e.categories)return".categories missing from one of infoFilter";for(const t in e.categories){if(!e.categories[t].label)return".label missing from one category of "+e.label;if(!e.categories[t].color)return".color missing from on category of "+e.label}if(e.hiddenCategories){for(const t in e.hiddenCategories)if(!e.categories[t])return"invalid hidden key "+t+" of "+e.label}else e.hiddenCategories={}}if(!t.singlejunctionsummary)return".singlejunctionsummary missing but is currently required from "+t.name;if(t.singlejunctionsummary.readcountboxplotpercohort){if(!t.singlejunctionsummary.readcountboxplotpercohort.groups)return".groups[] missing from query.singlejunctionsummary.readcountboxplotpercohort for "+t.name;for(const e of t.singlejunctionsummary.readcountboxplotpercohort.groups){if(!e.key)return".key missing from one group of query.singlejunctionsummary.readcountboxplotpercohort.groups";if(!e.label)return".label missing from one group of query.singlejunctionsummary.readcountboxplotpercohort.groups"}}}function be(t,e){if(!(e.cohort&&e.cohort.annotation&&e.cohort.attributes&&t))return;const n={};for(const r of e.cohort.attributes.lst){const o={};for(const t in r.values)o[t]=0;for(const n of t){const t=e.cohort.annotation[n];if(!t)continue;const i=t[r.key];null!=i&&(i in o&&o[i]++)}n[r.key]=o}return n}function _e(t,e){if(!e.cohort||!e.cohort.annotation||!e.cohort.hierarchies||0==t.length)return;const n=[];for(const r of t){const t=e.cohort.annotation[r];t&&n.push(t)}const r={};for(const t of e.cohort.hierarchies.lst){const e=y(n,t.levels),o=E()(e);o.sum((t=>t.value));const i={};o.eachBefore((t=>{i[t.id]=t.value})),r[t.name]=i}return r}function we(t,e,n){let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}else{if(!t.url)return"no file or url given for (mdscnv) "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=i.split("\n");if(1!=n.length)return"mdscnv file has multiple header lines (begin with #), but should have just 1";const r=n[0].split("\t");t.samples=r.slice(5),t.attributeSummary=be(t.samples,e),t.hierarchySummary=_e(t.samples,e);for(const e in t.hierarchySummary){let n=0;for(const r in t.hierarchySummary[e])n++;console.log(n+" "+e+" hierarchy levels for "+t.name)}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}console.log("("+t.type+") "+t.name+": "+(t.samples?t.samples.length:"no")+" samples, "+(t.nochr?'no "chr"':'has "chr"'))}function xe(t,e,n){let r;if(t.file){const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}else{if(!t.url)return"no file or url given for (svcnv) "+t.name;r=t.url}const o={encoding:"utf8"};const i=p.execSync(vt+" -H "+r,o).trim();if(i){const n=new Set;for(const t of i.split("\n"))for(const e of t.split(" ").slice(1))n.add(e);if(0==n.size)return"no samples from the header line";if(t.samples=[...n],e.cohort&&e.cohort.annotation){const n=new Set;for(const r of t.samples)e.cohort.annotation[r]||n.add(r);n.size&&console.log("mdssvcnv unannotated samples: "+(t.noprintunannotatedsamples?n.size:[...n].join(" ")))}}{const e=p.execSync(vt+" -l "+r,o).trim();if(!e)return"no chromosomes found";t.nochr=k.contigNameNoChr(n,e.split("\n"))}if(t.expressionrank_querykey){const n=e.queries[t.expressionrank_querykey];if(!n)return"invalid key by expressionrank_querykey";if(!n.isgenenumeric)return"query "+t.expressionrank_querykey+" not tagged as isgenenumeric"}if(t.vcf_querykey){const n=e.queries[t.vcf_querykey];if(!n)return"invalid key by vcf_querykey";if(n.type!=k.tkt.mdsvcf)return"query "+t.vcf_querykey+" not of mdsvcf type"}if(t.groupsamplebyattr){if(!t.groupsamplebyattr.attrlst)return".attrlst[] missing from groupsamplebyattr";if(0==t.groupsamplebyattr.attrlst.length)return"groupsamplebyattr.attrlst[] empty array";if(!e.cohort)return"groupsamplebyattr in use but ds.cohort missing";if(!e.cohort.annotation)return"groupsamplebyattr in use but ds.cohort.annotation missing";e.cohort.sampleAttribute||(e.cohort.sampleAttribute={}),e.cohort.sampleAttribute.attributes||(e.cohort.sampleAttribute.attributes={},console.log("cohort.sampleAttribute added when groupsamplebyattr is in use"));for(const n of t.groupsamplebyattr.attrlst){if(!n.k)return"k missing from one of groupsamplebyattr.attrlst[]";e.cohort.sampleAttribute.attributes[n.k]||(e.cohort.sampleAttribute.attributes[n.k]={label:n.label||n.k})}if(t.groupsamplebyattr.sortgroupby){if(!t.groupsamplebyattr.sortgroupby.key)return".key missing from .sortgroupby";if(!t.groupsamplebyattr.sortgroupby.order)return".order[] missing from .sortgroupby";if(!Array.isArray(t.groupsamplebyattr.sortgroupby.order))return".order must be an array"}t.groupsamplebyattr.attrnamespacer||(t.groupsamplebyattr.attrnamespacer=", ")}console.log("("+t.type+") "+t.name+": "+(t.samples?t.samples.length:"no")+" samples, "+(t.nochr?'no "chr"':'has "chr"'))}function ke(t,e,n){if(!t.datatype)return"datatype missing";if(t.viewrangeupperlimit&&Number.isNaN(t.viewrangeupperlimit))return"invalid value for viewrangeupperlimit";let r;if(!t.file)return"file missing";{const[e,n]=se(t.file);if(e)return"tabix file error: "+e;r=n}const o={cwd:null,encoding:"utf8"};{const e=p.execSync(vt+" -H "+r,o).trim();if(!e)return"no header line (#sample <sample1> ...)";const n=new Set;for(const t of e.split("\n")){const e=t.split(" ");for(let t=1;t<e.length;t++)n.add(e[t])}if(0==n.size)return"no sample names from header line";t.samples=[...n],console.log("(genenumeric) "+t.name+": "+t.samples.length+" samples")}if(t.boxplotbysamplegroup){if(!t.boxplotbysamplegroup.attributes)return"boxplotbysamplegroup.attributes missing";if(!Array.isArray(t.boxplotbysamplegroup.attributes))return"boxplotbysamplegroup.attributes should be array";for(const e of t.boxplotbysamplegroup.attributes)if(!e.k)return"k missing from one of boxplotbysamplegroup.attributes[]"}}async function qe(t,e,n){if(!t.tracks)return"tracks[] missing";if(!Array.isArray(t.tracks))return"tracks should be array";t.info={};for(const r of t.tracks){if(!r.file)return"file missing from a track (url not supported yet)";const[o,i]=se(r.file);if(o)return"tabix file error: "+o;if(r.type!=k.mdsvcftype.vcf)return"invalid track type: "+r.type;{r.cwd;const e=await x.get_header_tabix(i,r.cwd);if(0==e.length)return"no meta/header lines for "+i;const[n,o,s,a]=q.vcfparsemeta(e);if(a)return"error parsing vcf meta for "+i+": "+a.join("\n");if(0==s.length)return"vcf file has no sample: "+i;for(const e in n)t.info[e]=n[e];if(r.format=o,r.samplenameconvert){if("function"!=typeof r.samplenameconvert)return".samplenameconvert must be function";for(const t of s)t.name=r.samplenameconvert(t.name)}r.samples=s}if(e.cohort&&e.cohort.annotation){const t=[];for(const n of r.samples)e.cohort.annotation[n.name]||t.push(n.name);t.length&&console.log(e.label+": VCF "+r.file+" has unannotated samples: "+t.join(","))}{const t=[];if(await x.get_lines_bigfile({args:["-l",i],dir:r.cwd,callback:e=>{t.push(e)}}),0==t.length)return"no chr from "+i;r.nochr=k.contigNameNoChr(n,t)}console.log("("+t.type+") "+i+": "+r.samples.length+" samples, "+(r.nochr?"no chr":"has chr"))}if(t.singlesamples){if(!t.singlesamples.tablefile)return".singlesamples.tablefile missing for the VCF query";t.singlesamples.samples={};let e=0;for(const n of c.readFileSync(u.join(o.tpmasterdir,t.singlesamples.tablefile),{encoding:"utf8"}).trim().split("\n")){if(!n)continue;if("#"==n[0])continue;const r=n.split("\t");r[0]&&r[1]&&(t.singlesamples.samples[r[0]]=r[1],e++)}console.log(e+" single-sample VCF files")}}e.illegalpath=ce,e.fileurl=ue},6191:(t,e,n)=>{const r=n(7147).promises,o=n(7147).existsSync,i=n(1017),s=n(9344);function a(t){return t.cookies[`${t.query.dslabel}SessionId`]||t.headers["x-sjppds-sessionid"]||t.query["x-sjppds-sessionid"]}async function l(t,e,n,o,i,s,a="set-cookie"){const l=Date.now(),c=Math.random().toString()+"."+l.toString().slice(4),u=s.ip;return n[t.dslabel]||(n[t.dslabel]={}),n[t.dslabel][c]={id:c,time:l,email:i,ip:u},await r.appendFile(o,`${t.dslabel}\t${c}\t${l}\t${i}\t${u}\n`),a&&"set-cookie"!=a||e.header("Set-Cookie",`${t.dslabel}SessionId=${c}; HttpOnly; SameSite=None; Secure`),c}function c(t,e,n={},r,o=null){var i;const a=n[t.dslabel];if(!a)return;if(!t.embedder)throw"missing q.embedder";const l=a.embedders[t.embedder];if(!l)throw`unknown q.embedder='${t.embedder}'`;const c=l.secret;if(!c)throw"missing embedder setting";const u=Math.floor((r||Date.now())/1e3),f=e[a.headerKey];if(!f)throw`missing header['${a.headerKey}']`;const d=l.processor?require(l.processor):{},h=(null===(i=d.handleToken)||void 0===i?void 0:i.call(d,f))||f,p=s.verify(h,c);if(o)return{iat:p.iat,email:p.email,ip:p.ip};if(d.handlePayload)try{d.handlePayload(l,p,u)}catch(t){if("bad decrypt"==t.reason)throw`Please login again to access this feature. (${t.reason})`;throw t}if(u>p.exp)throw"Please login again to access this feature. (expired token)";const m=(l.dsnames||[t.dslabel]).filter((t=>!p.datasets.includes(t.id))).map((t=>t.id));if(m.length)throw{error:"Missing access",linkKey:m.join(",")};return{iat:p.iat,email:p.email,ip:p.ip}}function u(t,e){var n,r;if(!e)throw"Server error: missing ip address in saved session";if(t.ip!=e&&(null===(n=t.ips)||void 0===n?void 0:n[0])!=e&&(null===(r=t.connection)||void 0===r?void 0:r.remoteAddress)!=e)throw"Your connection has changed, please refresh your page or sign in again."}function f(t,e){const n=d.getDsAuth(t).find((t=>t.dslabel==e.label));return!n||n.insession}const d={maySetAuthRoutes:async function(t,e="",s=null){const f=s||n(334),h=i.join(f.cachedir,"dsSessions"),p=i.join(f.cachedir,"authorizedActions"),m=f.dsCredentials,g=f.maxSessionAge||576e5;let y;if(m&&Object.keys(m).length){t.use(((t,e,n)=>{const r=t.query;if(r.dslabel&&r.dslabel in m&&"/dslogin"!=t.path&&("jwt"!=m[r.dslabel].type||"/termdb"==t.path&&"matrix"==r.for))try{const e=a(t);if(!e)throw"missing session cookie";const o=y[r.dslabel][e];if(!o)throw"unestablished or expired browser session";u(t,o.ip);const i=Date.now();if(i-o.time>g){const{iat:n}=c(r,t.headers,m,o),s=i-n;if(s>g)throw delete y[r.dslabel][e],"Please login again to access this feature. (expired session)";if(s<3e5)return void(o.time=i)}o.time-i<900&&(o.time=i),n()}catch(t){e.send("object"==typeof t?t:{error:t})}else n()}));try{y=await async function(t,e,n){const i={};for(const e in t)i[e]||(i[e]={});try{const t=await r.readFile(e,"utf8"),o=+new Date;for(const e of t.split("\n")){if(!e)continue;const[t,r,s,a,l]=e.split("\t"),c=Number(s);i[t]||(i[t]={}),o-c<n&&(i[t][r]={id:r,time:c,email:a,ip:l})}return i}catch(t){return o(e)&&console.log(t),i}}(m,h,g)}catch(t){throw t}var v;await(v=0,new Promise((t=>setTimeout(t,v)))),t.post(e+"/dslogin",(async(t,e)=>{let n=401;try{var r,o,i;const s=t.query;if(!s.dslabel||!(s.dslabel in m))throw n=400,`No login required for dataset='${s.dslabel}'`;if(!t.headers.authorization)throw"missing authorization header";const[a,c]=t.headers.authorization.split(" ");if("basic"!=a.toLowerCase())throw`unsupported authorization type='${a}', allowed: 'Basic'`;if(Buffer.from(c,"base64").toString()!=m[s.dslabel].password)throw"invalid password";await l(s,e,y,h,"",t,null===(r=m[s.dslabel])||void 0===r||null===(o=r.embedders)||void 0===o||null===(i=o[s.embedder])||void 0===i?void 0:i.cookieMode),e.send({status:"ok"})}catch(t){e.status(n),e.send({error:t})}})),t.post(e+"/jwt-status",(async(t,e)=>{try{const n=t.query,{email:r,ip:o}=await c(n,t.headers,m);u(t,o);const i=await l(n,e,y,h,r,t,m[n.dslabel].embedders[n.embedder].cookieMode);e.send({status:"ok","x-sjppds-sessionid":i})}catch(t){console.log(t),e.status(401),e.send(t instanceof Error||"object"!=typeof t?{error:t}:t)}})),t.post(e+"/authorizedActions",(async(t,e)=>{const n=t.query;try{const o=a(t),{email:i}=y[n.dslabel][o],s=new Date;await r.appendFile(p,`${n.dslabel}\t${i}\t${s}\t${n.action}\t${JSON.stringify(n.details)}\n`),e.send({status:"ok"})}catch(t){e.status(401),e.send("object"==typeof t?t:{error:t})}})),d.getDsAuth=function(t){return Object.keys(m||{}).map((e=>{try{var n,r;const o=m[e],i=a(t),s=(null===(n=y[e])||void 0===n||null===(r=n[i])||void 0===r?void 0:r.time)||0;return{dslabel:e,insession:("jwt"!=o.type||i)&&Date.now()-s<g,type:o.type||"login"}}catch(t){throw t}}))}}},checkDsSecret:c,getDsAuth:()=>[],canDisplaySampleIds:(t,e)=>!!e.cohort.termdb.displaySampleIds&&f(t,e),userCanAccess:f};t.exports=d},2384:(t,e,n)=>{"use strict";n.r(e),n.d(e,{duplicateRegions:()=>u,make_type2group:()=>c,type_all:()=>r,type_supportalt:()=>i,type_supportamb:()=>a,type_supportno:()=>s,type_supportref:()=>o,type_supportsv:()=>l});const r="all",o="support_ref",i="support_alt",s="support_no",a="support_amb",l="support_sv";function c(t){const e={};if(t.variant)if(t.grouptype)e[t.grouptype]={partstack:t.partstack};else{e[o]={},e[s]={},e[a]={};for(let n=0;n<t.variant.length;n++)e[i+n.toString()]={}}else{if(!t.sv)throw"q.variant or q.sv missing";t.grouptype?e[t.grouptype]={partstack:t.partstack}:(e[l]={},e[o]={})}for(const n in e){const r=e[n];r.type=n,r.templates=[],r.regions=u(t.regions),r.messages=[]}return e}function u(t){return t.map((t=>({x:t.x,scale:t.scale,ntwidth:t.ntwidth})))}},8164:(t,e,n)=>{"use strict";n.r(e),n.d(e,{gdcCheckPermission:()=>m,gdc_bam_request:()=>i});const r=n(6452),o=n(1017);async function i(t,e){try{if(t.query.gdc_id){const n=await async function(t,e){const n={file_metadata:[],numFilesSkippedByWorkflow:0},r=await u(t,n,e);if(!r.data.hits.length){if(n.is_case_id||n.is_case_uuid)throw"No bam files available for this case.";if(e){if((await u(t,n)).data.hits.length)throw"Case not in current cohort.";throw"Invalid input ID."}throw"Invalid input ID."}for(const t of r.data.hits){if(t.analysis.workflow_type==c){n.numFilesSkippedByWorkflow++;continue}const e={};e.file_uuid=t.id,e.file_size=(Number.parseFloat(t.file_size)/1e9).toFixed(2)+" GB",e.experimental_strategy=t.experimental_strategy,e.entity_id=t.associated_entities[0].entity_submitter_id,e.case_id=t.associated_entities[0].case_id,e.sample_type=t.cases[0].samples[0].sample_type,n.file_metadata.push(e)}return n}(t.query.gdc_id,t.query.filter0);await async function(t,e){var n;if(null===(n=t.file_metadata)||void 0===n||!n.length)return;const r=e.cookies.sessionid;if(!r)return;try{await m(t.file_metadata[0].file_uuid,null,r)}catch(e){"Permission denied"==e&&(t.userHasNoAccess=!0)}}(n,t),e.send(n)}else{const n=await async function(t){var e,n,r;const o=await d(null,null,t,g),i={};if(!Array.isArray(null===(e=o.data)||void 0===e?void 0:e.hits))throw"re.data.hits[] not array";for(const t of o.data.hits){var s,a,l,u;if(t.analysis.workflow_type==c)continue;const e=null===(s=t.cases)||void 0===s||null===(a=s[0])||void 0===a?void 0:a.submitter_id;e&&(i[e]||(i[e]=[]),i[e].push({file_uuid:t.id,sample_type:null===(l=t.cases)||void 0===l||null===(u=l[0].samples)||void 0===u?void 0:u[0].sample_type,experimental_strategy:t.experimental_strategy,file_size:(Number.parseFloat(t.file_size)/1e9).toFixed(2)+" GB"}))}return{case2files:i,total:null===(n=o.data)||void 0===n||null===(r=n.pagination)||void 0===r?void 0:r.total,loaded:g}}(t.query.filter0);e.send(n)}}catch(t){e.send({error:t.message||t}),t.stack&&console.log(t.stack)}}const s=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",a={end_point:o.join(s,"files/"),fields:["id","file_size","experimental_strategy","cases.submitter_id","associated_entities.entity_submitter_id","associated_entities.case_id","cases.samples.sample_type","analysis.workflow_type"],size:100},l={end_point:o.join(s,"cases/"),fields:["case_id"]},c="STAR 2-Pass Transcriptome";async function u(t,e,n){if(await f(t,"cases.case_id",n))return e.is_case_uuid=!0,await d(t,"cases.case_id",n);if(await f(t,"cases.submitter_id",n))return e.is_case_id=!0,await d(t,"cases.submitter_id",n);const r=await h(t,"file_id",n);if(r.data.hits.length)return e.is_file_uuid=!0,r;const o=await h(t,"file_name",n);return o.data.hits.length&&(e.is_file_id=!0),o}async function f(t,e,n){const r={op:"and",content:[{op:"in",content:{field:e,value:t}}]};n&&r.content.push(n);return(await p(r,l)).data.hits.length>0}async function d(t,e,n,r){const o={op:"and",content:[{op:"=",content:{field:"data_category",value:"Sequencing Reads"}},{op:"=",content:{field:"index_files.data_format",value:"bai"}},{op:"=",content:{field:"data_type",value:"Aligned Reads"}},{op:"=",content:{field:"data_format",value:"bam"}}]};return t&&e&&o.content.push({op:"in",content:{field:e,value:t}}),n&&o.content.push(n),await p(o,a,r)}async function h(t,e,n){const r={op:"and",content:[{op:"in",content:{field:e,value:t}}]};return n&&r.content.push(n),await p(r,a)}async function p(t,e,n){const o={filters:t,size:n||10,fields:e.fields.join(",")},i=await r(e.end_point,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(o)});let s;try{s=JSON.parse(i.body)}catch(t){throw"invalid JSON from "+e.end_point}if(!s.data||!s.data.hits)throw"data structure not data.hits[]";return s}async function m(t,e,n){const o={Range:"bytes=0-0"};n?o.Cookie=`sessionid=${n}`:o["X-Auth-Token"]=e;const i=s+"/data/"+t;try{const t=await r(i,{headers:o,decompress:!1});if(!(t.statusCode>=200&&t.statusCode<400))throw console.log(`gdcCheckPermission() error for got(${i})`,t),"Invalid status code: "+t.statusCode}catch(t){throw console.log("gdcCheckPermission error: ",(null==t?void 0:t.code)||t),"Permission denied"}}const g=1e3},7253:(t,e,n)=>{const r=n(9699),o=n(2781),i=n(6113),{promisify:s}=n(6464),a=n(6452),l=s(o.pipeline),c=n(1017),u=n(7147),f=n(2781).Readable,d=n(3856),h=n(1271).run_rust,p=n(6718).createCanvas,m=n(2081).spawn,g=(n(4521),n(6778).interpolateRgb),y=n(8953).Y,v=n(2384),{basecolor:b,bplen:_}=n(2273),{gdcCheckPermission:w}=n(8164),x=n(334),k=x.clustalo,q="rgb(120,120,120)",N="rgb(230,230,230)",S=g(N,q),A="#d48b37",M=g("#dbc6ad",A),T="#3B7A57",C=g("#E5FFCC",T),j="#d13232",O="#ffdbdd",E=g(O,j),R="#4888bf",I="#c9e6ff",P=g(I,R),F="#6B4423",L=g("#987654",F),D="#fc6df3",B=g("#dea4da",D),z="#47FFFC",Z="#B2D7D7",$=g(Z,z),G=12,U=7,J="black",W="#ededed",H="blue",V="#e0e0e0",Y="#FF0000",Q="#6cc24a",K="#ffff00",X="#DEB887",tt="#CD853F",et="#9a92ec",nt="#47C8FF",rt=1,ot=1,it=.4,st=.9,at=7,lt=7,ct=10,ut=7,ft=40,dt=.5,ht=7e3,pt=1500,mt=2e3,gt=7,yt=200,vt=20,bt=(new Set(["A","T","C","G"]),process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov"),_t=Math.random.toString();async function wt(t,e,n,r,o){const i=t.diff_score_plotwidth/(r-o),s=r*i-o*i,a=p(s*t.devicePixelRatio,e.canvasheight*t.devicePixelRatio),l=a.getContext("2d");t.devicePixelRatio>1&&l.scale(t.devicePixelRatio,t.devicePixelRatio);const c=n.map((t=>t.__tempscore)),u=e.canvasheight/c.length;let f=0;const d=e.stackspace/e.canvasheight;for(const t of c){let e=0;for(const n of t)"alt0"==n?l.fillStyle=Y:"ref"==n?l.fillStyle=nt:"alt1"==n?l.fillStyle=Q:"alt2"==n?l.fillStyle=K:"alt3"==n?l.fillStyle=X:"alt4"==n?l.fillStyle=tt:"alt5"==n&&(l.fillStyle=et),l.fillRect(i*e,f*u,i,u-d*u),e+=1;f+=1}return{height:e.canvasheight,width:s,src:a.toDataURL(),read_height:u}}function xt(t,e,n,r){for(const o of n)for(const n of o.segments)if(!(n.ridx!=t||Math.max(n.segstart,e.start)>Math.min(n.segstop,e.stop)))for(const t of n.boxes)if(e.ntwidth>=1){if(("S"==t.opr||"X"==t.opr)&&t.s)for(let e=0;e<t.s.length;e++){const n=t.start+e,o=r.find((t=>t.position==n));if(!o)continue;const i=t.s[e];o[i]=1+(o[i]||0),"S"==t.opr&&o.total++}}else if("S"==t.opr){const n=Math.floor((t.start-e.start)*e.ntwidth),o=Math.floor((t.start+t.len-e.start)*e.ntwidth);for(let t=n;t<=o;t++){const e=r[t];e&&(e.softclip=1+(e.softclip||0),e.total++)}}}async function kt(t,e){if(!await d.file_not_exist(e))return;if(!t.query.gdcFilePosition)throw".gdcFilePosition missing";const n=t.query.regions,r=t.query.gdcFilePosition.split(".");t.query.regions=[{chr:r[0],start:Number(r[1]),stop:Number(r[2])}],await Gt(t),t.query.regions=n}async function qt(t,e,n,r,o){const i=t.map((t=>t.segments[0].seq)),s=t.map((t=>t.segments[0].qual));let a="",l="";o&&(a+=">seq\n"+o.replace("\n","")+"\n");let c=0;for(const t of i){if(!(c<yt))break;a+=">seq\n"+t.replace("\n","")+"\n",l+=It(s[c].replace("\n",""))+"\n",c+=1}return await function(t,e,n,r,o,i,s,a){return new Promise(((n,l)=>{const c=m(k,["-i","-","-t","DNA","--outfmt=clu","--wrap=5000","--maxnumseq="+(e+1),"--maxseqlen=1000"]),u=[],d=[];f.from(t).pipe(c.stdin),c.stdout.on("data",(t=>u.push(t))),c.stderr.on("data",(t=>d.push(t))),c.on("error",(t=>{console.log("stderr (clustalo):",d),l(t)})),c.on("close",(t=>{let e=0;const c=[],f={final_read_align:[],qual_r:[],qual_g:[],qual_b:[]};let d=0;for(const t of u.toString().split("\n"))if(t.includes("seq ")){let n=0,l="",u=0,h="";0!=e&&a?h=r.split("\n")[e-1].split(","):a||(h=r.split("\n")[e].split(","));let p="",m="",g="";for(const r of t.replace("seq ",""))if(","!=r){if("-"!=r){if(n+=1,l+=r,0==e&&a)c.push(r);else if(r==c[u]&&a||!a){const t=S(h[n-1]/ft).replace("rgb(","").replace(")","").split(",");p+=t[0]+",",m+=t[1]+",",g+=t[2]+","}else if(r!=c[u]&&a){const t=E(h[n-1]/ft).replace("rgb(","").replace(")","").split(",");p+=t[0]+",",m+=t[1]+",",g+=t[2]+","}}else n>0&&n<t.replace(/-/g,"").replace(/,/g,"").replace("seq ","").length?(l+=r,0==e&&(c.push(r),u<o&&(d+=1))):(l+=" ",0==e&&c.push(r)),p+="255,",m+="255,",g+="255,";u+=1}e+=1,f.gaps_before_variant=d,f.read_count=a?e-1:e,f.qual_r.push(p),f.qual_g.push(m),f.qual_b.push(g),f.final_read_align.push(l),0!=i&&0!=s&&(f.partstack_start=i,f.partstack_stop=s)}else(t.includes("FATAL:")||t.includes("ERROR:"))&&(console.log(t),l(t));n(f)}))}))}(a,yt,i.length,l,e,n,r,o)}async function Nt(t,e){let n=0;for(const r of e){const e=["view","-c",t.file];t.gdc_case_id||e.push((t.nochr?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop),await d.get_lines_bigfile({isbam:!0,args:e,dir:t.dir,callback:t=>{const e=Number(t);if(!Number.isInteger(e))throw"total number of reads from a region not integer";n+=e}})}if(n<1.1*ht)return;const r=(n-ht)/(.1*ht);t.downsample={keep:10,skip:Math.floor(r),pointer:0},t.read_limit_reached=n}async function St(t,e){t.lines=[];const n=["view",e.file];e.gdc_case_id||n.push((e.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop),await d.get_lines_bigfile({isbam:!0,args:n,dir:e.dir,callback:(n,r)=>{if(!(1024&n.split("\t")[1]&&e.drop_pcrduplicates)){if(e.downsample){const t=e.downsample;if(t.pointer++,t.pointer>=t.keep&&t.pointer<t.keep+t.skip)return;t.pointer>=t.keep+t.skip&&(t.pointer=0)}t.lines.push(n)}}})}async function At(t,e){const n=[],r=["depth","-r",(t.nochr?e.chr.replace("chr",""):e.chr)+":"+(e.start+1)+"-"+e.stop,"-g","DUP",t.file||t.url];if(t.drop_pcrduplicates&&(r.push("-G"),r.push("0x400")),await d.get_lines_bigfile({isbam:!0,args:r,dir:t.dir,callback:t=>{const r=t.split("\t"),o=Number.parseInt(r[1])-1,i=Number.parseInt(r[2]);if(e.ntwidth>=1)return void n.push({position:o,total:i});const s=Math.floor((o-e.start)*e.ntwidth);n[s]||(n[s]={position:o,sum:0,count:0}),n[s].sum+=i,n[s].count++}}),e.ntwidth<1)for(const t of n)t&&(t.total=t.sum/t.count,delete t.sum,delete t.count);return n}async function Mt(t,e){for(const t of e.regions)t.lines.length>0&&t.ntwidth>=st&&(t.to_checkmismatch=!0,t.referenceseq=await Et(e.genome,t.chr+":"+(t.start+1)+"-"+t.stop));for(const n of t)for(const t of n.segments){const n=e.regions[t.ridx];if(!n.to_checkmismatch)continue;const r=[];for(const e of t.boxes)null!=e.cidx&&"M"==e.opr&&(e.s=t.seq.substr(e.cidx,e.len),Ft(r,n,e,e.s));r.length&&t.boxes.push(...r)}for(const t of e.regions)delete t.to_checkmismatch,delete t.referenceseq}function Tt(t,e){if(!t.asPaired){const n=[];for(let r=0;r<t.regions.length;r++){const o=t.regions[r];for(const i of e.templates){i.ridx=r;const e=Ct(i,o,t);e&&n.push({x1:e.x1,x2:e.x2,__tempscore:e.tempscore,segments:[e]})}}return n}const n=new Map;for(let r=0;r<t.regions.length;r++){const o=t.regions[r];for(const i of e.templates){i.ridx=r;const e=Ct(i,o,t);if(!e||!e.qname)continue;const s=n.get(e.qname);s?(s.segments.push(e),s.x2=Math.max(s.x2,e.x2)):n.set(e.qname,{x1:Math.max(e.x1,o.x),x2:Math.min(e.x2,o.x+o.width),__tempscore:e.tempscore,segments:[e]})}}return[...n.values()]}function Ct(t,e,n){const{sam_info:r,tempscore:o,ridx:i,keepallboxes:s,keepmatepos:a,keepunmappedread:l}=t,c=r.trim().split("\t");if(c.length<11)return;const u=c[0],f=c[1],d=Number.parseInt(c[3]),h=c[5],p=c[6],m=c[7],g=Number.parseInt(c[8]),y=c[9],v=c[10];if(Number.isNaN(d)||d<=0)return;const b=d-1,_={qname:u,segstart:b,segstart_original:b,segstop:b,boxes:[],forward:!(16&f),ridx:i,seq:y,qual:v,cigarstr:h,tlen:g,flag:f,tempscore:o};if(function(t,e,n,r,o,i){const s=t.flag;if(!(1&s))return;64&s?t.isfirst=!0:128&s&&(t.islast=!0);if("="!=e&&"*"!=e&&e!=r.chr)return t.rnext=e,void(t.pnext=n);if(8&s)return void(t.discord_unmapped2=!0);32&s&&!(16&s)&&64&s||16&s&&!(32&s)&&128&s||16&s&&!(32&s)&&64&s||32&s&&!(16&s)&&128&s||(t.discord_orientation=!0,o&&(16&s?32&s?t.discord_orientation_direction="R1R2":n>i&&(t.discord_orientation_direction="R1F2"):32&s?n<i&&(t.discord_orientation_direction="R1F2"):t.discord_orientation_direction="F1F2")),2&s||(t.discord_wrong_insertsize=!0,o&&(t.pnext=n))}(_,p,m,e,a,d),4&f)return l?(_.boxes.push({opr:h,start:b,len:y.length,cidx:0,qual:v}),_.discord_unmapped1=!0,_):void 0;if("*"!=h){let t=b,r=0,o=0;for(let n=0;n<h.length;n++){const i=h[n];if(i.match(/[0-9]/))continue;const a=Number.parseInt(h.substring(r,n));if("H"!=i)if("N"==i||"P"==i||"D"==i||(o+=a),r=n+1,"="!=i&&"M"!=i)if("I"!=i)if("N"!=i&&"D"!=i)if("X"!=i)if("S"!=i){if("P"!=i)console.log("unknown cigar: "+i);else if(s||t>e.start&&t<e.stop){const e={opr:"P",start:t,len:a,cidx:o-a};_.boxes.push(e)}}else{const n={opr:i,start:t,len:a,cidx:o-a};0==_.boxes.length?(n.start-=a,(s||Math.max(t,e.start)<=Math.min(t+a-1,e.stop))&&_.boxes.push(n)):_.boxes.push(n)}else{if(s||Math.max(t,e.start)<Math.min(t+a-1,e.stop)){const e={opr:i,start:t,len:a,cidx:o-a};_.boxes.push(e)}t+=a}else(t>=e.start&&t<=e.stop||t+a-1>=e.start&&t+a-1<=e.stop||s)&&_.boxes.push({opr:i,start:t,len:a}),t+=a;else(s||t>e.start&&t<e.stop)&&a*e.ntwidth>=rt&&_.boxes.push({opr:"I",start:t,len:a,cidx:o-a});else(s||Math.max(t,e.start)<=Math.min(t+a-1,e.stop))&&_.boxes.push({opr:i,start:t,len:a,cidx:o-a}),t+=a;else _.boxes.push({opr:i,start:t,len:a,cidx:o-a}),r=n+1}if(0==_.boxes.length)return void(n&&n.readcount_skipped++);_.segstop=t,_.x1=e.x+e.scale(_.boxes[0].start),_.x2=e.x+e.scale((w=_.boxes,Math.max(...w.map((t=>t.start+t.len)))))}var w;return _}async function jt(t,e,n){const[r,o]=function(t,e){let n=(e.groups.length>1?pt/2:pt)/t;return n>10?[Math.min(15,Math.floor(n)),1]:n>7?[Math.floor(n),1]:n>3?[Math.ceil(n),0]:n>1?[Math.floor(n),0]:[n,0]}(t.stacks.length,e);t.stackheight=r,t.stackspace=o;for(const e of t.regions)e.to_printnt=t.stackheight>7&&e.ntwidth>=7,e.to_qual=e.ntwidth>=ot;if(t.stacks.length&&(t.stackheight>=gt&&n.length<mt?t.returntemplatebox=[]:t.partstack||(t.allowpartstack=!0)),t.stackheight>=at){let e=0;for(const t of n)for(const n of t.segments)e=Math.max(e,n.x2-n.x1);e>.7*t.stackheight&&(t.canClipArrowhead=!0)}}function Ot(t,e,n){if(e.asPaired){t.stacks=[];const r=[],o=[];for(const t of n){let n=t.segments[0].ridx;1==t.segments.length||2==t.segments.length&&t.segments[0].ridx==t.segments[1].ridx?(t.x1=Math.max(e.regions[n].x,t.x1),t.x2=Math.min(e.regions[n].x+e.regions[n].width,t.x2),r.push(t)):2==t.segments.length&&t.segments[0].ridx!=t.segments[1].ridx&&(t.x1=t.x1,t.x2=t.x2,o.push(t))}if(r.sort(((t,e)=>t.x1-e.x1)),o.sort(((t,e)=>t.x1-e.x1)),o.length>0){const t=[],e=[],i=o[0];for(const n of r)n.x1<i.x1&&n.x2<i.x1?t.push(n):e.push(n);n=[...t,...o,...e]}for(const r of n){let n=r.segments[0].ridx,o=null;if(!e.variant)for(let i=0;i<t.stacks.length;i++){if(r.x2==e.regions[n].x+e.regions[n].width&&t.stacks[i]<r.x1){o=i,t.stacks[i]=r.x2;break}if(t.stacks[i]+e.stacksegspacing<r.x1){o=i,t.stacks[i]=r.x2;break}}null==o&&(o=t.stacks.length,t.stacks[o]=r.x2),r.y=o}}else{n.sort(((t,e)=>t.x1-e.x1)),t.stacks=[];for(let r=0;r<e.regions.length;r++)for(const o of n)if(o.segments[0].ridx==r){let n=null;if(!e.variant&&!e.sv)for(let i=0;i<t.stacks.length;i++)if(t.stacks[i]+e.stacksegspacing<o.x1&&t.stacks[i]+e.stacksegspacing<e.regions[r].x+e.regions[r].width){n=i,t.stacks[i]=o.x2;break}null==n&&(n=t.stacks.length,t.stacks[n]=o.x2),o.y=n}}return n=function(t,e,n){if(!t.partstack)return e;const r=e.filter((e=>e.y>=t.partstack.start&&e.y<=t.partstack.stop));r.forEach((e=>e.y-=t.partstack.start)),e=r,t.stacks=[];for(let e=t.partstack.start;e<=t.partstack.stop;e++)t.stacks.push(0);return t.returntemplatebox=[],e}(t,n),n}async function Et(t,e){const n=(await d.get_fasta(t,e)).split("\n");return n.shift(),n.join("").toUpperCase()}function Rt(t,e,n){const r=function(t,e,n){const r=[];for(let e=0;e<t.stacks.length;e++)r.push(t.stackheight);if(function(t,e){if(!e.asPaired)return;for(const e of t.regions)if(e.ntwidth<=it)return;t.overlapRP_multirows=!0,t.overlapRP_hlline=t.stackspace>0}(t,n),t.overlapRP_multirows)for(const n of e)n.segments.length<=1||n.segments[0].ridx!=n.segments[1].ridx||(n.height=Pt(n,t.stackheight),r[n.y]=Math.max(r[n.y],n.height));const o=[];let i=t.stackspace;for(const e of r)o.push(i),i+=e+t.stackspace;return t.canvasheight=i,o}(t,e,n);for(const n of e){n.y=r[n.y];for(const e of n.segments){const n=t.regions[e.ridx].to_qual?It(e.qual):null;for(const t of e.boxes)null!=t.cidx&&"H"!=t.opr&&(n&&(t.qual=n.slice(t.cidx,t.cidx+t.len)),"I"==t.opr?t.s=e.seq.substr(t.cidx,t.len):"X"!=t.opr&&"S"!=t.opr||(t.s=e.seq.substr(t.cidx,t.len)),delete t.cidx);delete e.seq,delete e.qual}}}function It(t){if("*"==t)return null;const e=[];for(let n=0;n<t.length;n++){const r=t[n].charCodeAt(0)-33;e.push(r)}return e}function Pt(t,e){if(2==t.segments.length){const[n,r]=t.segments;return n.x2>r.x1?(r.shiftdownrow=1,2*e):e}console.log("more than 2 segments",t.segments.length);const n=[];for(const e of t.segments){let t=null;for(let r=0;r<n.length;r++)if(n[r]<e.x1){t=r,n[r]=e.x2;break}null==t&&(t=n.length,n[t]=e.x2),e.shiftdownrow=t}return e*n.length}function Ft(t,e,n,r){for(let o=0;o<r.length;o++){if(n.start+o<e.start||n.start+o>e.stop)continue;const i=r[o];if(e.referenceseq[n.start+o-e.start]!=i.toUpperCase()){const e={opr:"X",start:n.start+o,len:1,s:i,cidx:n.cidx+o};t.push(e)}}}function Lt(t,e,n,r){if(n.returntemplatebox){const t=n.regions[e.segments[0].ridx];let o;if(t.width=n.widths[e.segments[0].ridx],r.asPaired)if(2==e.segments.length)o=e.segments[0].ridx!=e.segments[1].ridx?{qname:e.segments[0].qname,x1:e.x1,x2:e.x2,y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop))),multi_region:!0}:{qname:e.segments[0].qname,x1:Math.max(t.x,e.x1),x2:Math.min(e.x2,t.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))};else{const t=e.segments[0],r=n.regions[t.ridx];r.width=n.widths[t.ridx],o={qname:e.segments[0].qname,x1:Math.max(r.x,e.x1),x2:Math.min(e.x2,r.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))}}else o={qname:e.segments[0].qname,x1:Math.max(t.x,e.x1),x2:Math.min(e.x2,t.x+t.width),y1:e.y,y2:e.y+(e.height||n.stackheight),start:Math.min(...e.segments.map((t=>t.segstart))),stop:Math.max(...e.segments.map((t=>t.segstop)))},e.segments[0].isfirst&&(o.isfirst=!0),e.segments[0].islast&&(o.islast=!0);n.returntemplatebox.push(o)}for(let o=0;o<e.segments.length;o++){const i=e.segments[o],s=n.regions[i.ridx];if(s.width=n.widths[i.ridx],0==o){Dt(t,i,e.y,n,r);continue}const a=e.segments[o-1],l=n.regions[a.ridx];if(l.width=n.widths[a.ridx],a.x2<=i.x1||e.segments[0].ridx!=e.segments[1].ridx){Dt(t,i,e.y,n,r);const o=Math.floor(e.y+n.stackheight/2)+.5;if(t.strokeStyle=n.stackheight<=2?W:q,t.setLineDash([5,3]),t.beginPath(),l.x==s.x?(t.moveTo(a.x2,o),t.lineTo(i.x1,o)):l.x<a.x2&&i.x1<s.width&&(t.moveTo(Math.min(a.x2,l.width),o),t.lineTo(Math.max(i.x1,s.x),o)),t.stroke(),n.overlapRP_hlline){const r=a.boxes.reduce(((t,e)=>t.start+t.len>e.start+e.len?t:e));if(r.start+r.len==i.boxes[0].start){t.strokeStyle=H,t.setLineDash([]),t.beginPath();const r=Math.floor(i.x1)+.5;t.moveTo(r,e.y),t.lineTo(r,e.y+n.stackheight),t.stroke()}}}else if(n.overlapRP_multirows){if(Dt(t,i,e.y+n.stackheight,n,r),n.overlapRP_hlline){const r=Math.floor(e.y+n.stackheight)+.5;t.strokeStyle=H,t.setLineDash([]),t.beginPath(),l.x<=a.x2&&i.x1<=s.width&&(t.moveTo(Math.max(i.x1,s.x),r),t.lineTo(Math.min(a.x2,l.width),r)),t.stroke()}}else Dt(t,i,e.y,n,r)}null!=e.__tempscore&&x.features.indel_read_alignment_scores&&(t.fillStyle="blue",t.font=n.stackheight+"pt Arial",t.fillText(e.__tempscore,r.regions[0].width-100,e.y+n.stackheight/2))}function Dt(t,e,n,r,o){const i=r.regions[e.ridx];i.width=r.widths[e.ridx];for(const o of e.boxes){const s=i.x+i.scale(o.start);if("P"!=o.opr&&"H"!=o.opr&&"I"!=o.opr)if("D"!=o.opr&&"N"!=o.opr)if("*"!=o.opr){if("X"!=o.opr&&"S"!=o.opr){if("M"!=o.opr&&"="!=o.opr)throw"unknown opr at rendering: "+o.opr;if(i.to_qual&&o.qual){let a=s;o.qual.forEach((o=>{e.rnext?t.fillStyle=M(o/ft):e.discord_orientation?t.fillStyle=B(o/ft):e.discord_wrong_insertsize?t.fillStyle=C(o/ft):e.discord_unmapped2?t.fillStyle=L(o/ft):t.fillStyle=S(o/ft),a+i.ntwidth+dt<i.width&&i.x<=a?t.fillRect(a,n,i.ntwidth+dt,r.stackheight):a<i.width&&a+i.ntwidth+dt>=i.width&&i.x<=a?t.fillRect(a,n,i.width-a,r.stackheight):a<=i.x&&a+i.ntwidth+dt>i.x&&t.fillRect(i.x,n,i.ntwidth+dt+a-i.x,r.stackheight),a+=i.ntwidth}))}else o.qual?e.rnext?t.fillStyle=A:e.discord_orientation?t.fillStyle=D:e.discord_wrong_insertsize?t.fillStyle=T:e.discord_unmapped2?t.fillStyle=F:t.fillStyle=q:i.to_printnt?t.fillStyle="white":e.rnext?t.fillStyle=A:e.discord_orientation?t.fillStyle=D:e.discord_wrong_insertsize?t.fillStyle=T:e.discord_unmapped2?t.fillStyle=F:t.fillStyle=q,s+o.len*i.ntwidth+dt<i.width&&s<i.width&&i.x<s+dt?t.fillRect(s,n,o.len*i.ntwidth+dt,r.stackheight):s+o.len*i.ntwidth+dt<i.width&&i.x>=s?t.fillRect(i.x,n,o.len*i.ntwidth+dt+s-i.x,r.stackheight):s+o.len*i.ntwidth+dt>=i.width&&i.x<s?t.fillRect(s,n,i.width-s,r.stackheight):s+o.len*i.ntwidth+dt>=i.width&&i.x>=s&&t.fillRect(i.x,n,i.width-s,r.stackheight);if(i.to_printnt){t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial",o.qual?t.fillStyle="white":t.fillStyle="black";for(let e=0;e<o.s.length;e++)s+i.ntwidth*(e+.5)<i.width&&s<i.width&&i.x<=s+i.ntwidth*(e+.5)&&t.fillText(o.s[e],s+i.ntwidth*(e+.5),n+r.stackheight/2)}}else if(i.to_qual&&o.qual){i.to_printnt&&(t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial");let e=s;for(let s=0;s<o.qual.length;s++){const a=o.qual[s]/ft;t.fillStyle="S"==o.opr?P(a):E(a),e+i.ntwidth+dt<i.x+i.width&&i.x<=e?t.fillRect(e,n,i.ntwidth+dt,r.stackheight):e<i.x+i.width&&e+i.ntwidth+dt>=i.x+i.width&&i.x<=e?t.fillRect(e,n,i.width+i.x-e,r.stackheight):e<=i.x&&e+i.ntwidth+dt>i.x&&t.fillRect(i.x,n,i.ntwidth+dt+e-i.x,r.stackheight),i.to_printnt&&(o.qual?t.fillStyle="white":t.fillStyle="black",e+i.ntwidth/2<i.width&&e<i.width&&i.x<=e+i.ntwidth/2&&t.fillText(o.s[s],e+i.ntwidth/2,n+r.stackheight/2)),e+=i.ntwidth}}else if(t.fillStyle="S"==o.opr?R:j,s+o.len*i.ntwidth+dt<i.width&&i.x<s?t.fillRect(s,n,o.len*i.ntwidth+dt,r.stackheight):s+o.len*i.ntwidth+dt<i.width&&i.x>=s?t.fillRect(i.x,n,o.len*i.ntwidth+dt+s-i.x,r.stackheight):s+o.len*i.ntwidth+dt<=i.width&&i.x<s&&t.fillRect(s,n,i.width-s,r.stackheight),i.to_printnt&&!o.qual){t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial",o.qual?t.fillStyle="white":t.fillStyle="black";for(let e=0;e<o.s.length;e++)s+i.ntwidth*(e+.5)<i.width&&s<i.width&&i.x<=s+i.ntwidth*(e+.5)&&t.fillText(o.s[e],s+i.ntwidth*(e+.5),n+r.stackheight/2)}}else{if(i.to_qual&&o.qual){let a=s;o.qual.forEach((o=>{e.discord_unmapped2&&(t.fillStyle=L(o/ft)),t.fillRect(a,n,i.ntwidth+dt,r.stackheight),a+=i.ntwidth}))}else e.discord_unmapped2&&(t.fillStyle=F),t.fillRect(s,n,o.len*i.ntwidth+dt,r.stackheight);i.to_printnt&&(t.font=Math.min(i.ntwidth,r.stackheight-2)+"pt Arial")}else{"D"==o.opr?t.strokeStyle=J:t.strokeStyle=r.stackheight<=2?W:q,t.setLineDash([]);const e=Math.floor(n+r.stackheight/2)+.5;if(t.beginPath(),t.moveTo(Math.max(s,i.x),e),t.lineTo(Math.min(s+o.len*i.ntwidth,i.x+i.width),e),t.stroke(),r.stackheight>lt){const e=Math.max(i.x,s),a=Math.min(i.x+i.width,s+o.len*i.ntwidth);if(a-e>=50){const s=Math.min(ct,Math.max(ut,r.stackheight-2));t.font=s+"pt Arial";const l=t.measureText(o.len+" bp").width;l<a-e-20&&(t.fillStyle="white",(a+e)/2+l/2<i.width&&i.x<(a+e)/2-l/2?(t.fillRect((a+e)/2-l/2,n,l,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)):(a+e)/2+l/2<i.width&&i.x>=(a+e)/2-l/2?(t.fillRect(i.x,n,l+(a+e)/2-l/2-i.x,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)):(a+e)/2+l/2>=i.width&&i.x<(a+e)/2-l/2&&(t.fillRect((a+e)/2-l/2,n,i.width-(a+e)/2+l/2,r.stackheight),t.fillStyle=q,t.fillText(o.len+" bp",(a+e)/2,n+r.stackheight/2)))}}}}!function(t,e,n,r,o){if(!n.canClipArrowhead)return;if(e.x2-e.x1<5)return;if(e.forward){const i=Math.ceil(e.x2+dt);i<=r.width+n.stackheight/2&&(t.fillStyle="white",t.beginPath(),t.moveTo(i-n.stackheight/2,o),t.lineTo(i,o),t.lineTo(i,o+n.stackheight/2),t.lineTo(i-n.stackheight/2,o),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i-n.stackheight/2,o+n.stackheight),t.lineTo(i,o+n.stackheight),t.lineTo(i,o+n.stackheight/2),t.lineTo(i-n.stackheight/2,o+n.stackheight),t.closePath(),t.fill())}else{const i=e.x1;i>=r.x&&(t.fillStyle="white",t.beginPath(),t.moveTo(i+n.stackheight/2,o),t.lineTo(i,o),t.lineTo(i,o+n.stackheight/2),t.lineTo(i+n.stackheight/2,o),t.closePath(),t.fill(),t.beginPath(),t.moveTo(i+n.stackheight/2,o+n.stackheight),t.lineTo(i,o+n.stackheight),t.lineTo(i,o+n.stackheight/2),t.lineTo(i+n.stackheight/2,o+n.stackheight),t.closePath(),t.fill())}}(t,e,r,i,n),e.rnext&&(i.to_qual||e.x2-e.x1>=20&&r.stackheight>=7&&(t.font=Math.min(G,Math.max(U,r.stackheight-4))+"pt Arial",t.fillStyle="white",t.fillText((o.nochr?"chr":"")+e.rnext,(e.x1+e.x2)/2,n+r.stackheight/2,e.x2-e.x1)))}function Bt(t,e,n,r){for(const[t,n]of e.regions.entries()){if(!n.to_printnt)continue;const e=new Set;for(const o of r)for(const r of o.segments){if(r.ridx!=t)continue;const o=r.boxes.filter((t=>"I"==t.opr));if(o.length)for(const t of o)e.add(n.x+n.scale(t.start))}}for(const n of r)for(const r of n.segments){const o=e.regions[r.ridx],i=r.boxes.filter((t=>"I"==t.opr));if(i.length){t.font=Math.max(G,e.stackheight-2)+"pt Arial";for(const s of i){const i=o.x+o.scale(s.start);s.qual?t.fillStyle=$(s.qual.reduce(((t,e)=>t+e),0)/s.qual.length/ft):t.fillStyle=z;const a=1==s.s.length?s.s:s.s.length;t.fillText(a,i,n.y+e.stackheight*(r.on2ndrow||0)+e.stackheight/2)}}}}async function zt(t,e,n){const r=It(t.qual),o=['<td style="color:black;text-align:left">Read</td>'];for(const e of t.boxes)for(let n=0;n<e.len;n++){t.seq[e.cidx+n];o.push('<td style="background:'+S(r[e.cidx+n]/ft)+'">'+t.seq[e.cidx+n]+"</td>")}const i=[];i.push('<li><span style="background:'+F+';color:white">This segment in template is unmapped</span></li>'),1&t.flag&&i.push("<li>Template has multiple segments</li>"),2&t.flag&&i.push("<li>Each segment properly aligned</li>"),16&t.flag&&i.push("<li>Reverse complemented</li>"),32&t.flag&&i.push("<li>Next segment in the template is reverse complemented</li>"),64&t.flag&&i.push("<li>This is the first segment in the template</li>"),128&t.flag&&i.push("<li>This is the last segment in the template</li>"),256&t.flag&&i.push("<li>Secondary alignment</li>"),512&t.flag&&i.push("<li>Not passing filters</li>"),1024&t.flag&&i.push("<li>PCR or optical duplicate</li>"),2048&t.flag&&i.push("<li>Supplementary alignment</li>");let s={seq:t.seq,alignment:`<table style="border-spacing:0px;border-collapse:separate;text-align:center">\n\t\t\t <tr style="color:white">${o.join("")}</tr>\n\t\t\t</table>`,info:`<div style='margin-top:10px'>\n\t\t\t<span style="opacity:.5;font-size:.7em">TEMPLATE</span>: ${Math.abs(t.seq.length)} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">CIGAR</span>: ${t.cigarstr}\n\t\t\t<span style="opacity:.5;font-size:.7em">FLAG</span>: ${t.flag}\n\t\t\t<span style="opacity:.5;font-size:.7em">NAME: ${t.qname}</span>\n\t\t </div>\n\t\t <ul style='padding-left:15px'>${i.join("")}</ul>`};return t.discord_unmapped2&&(s.unmapped_mate=!0),s}async function Zt(t,e,n){const r=t.boxes[0].start,o=t.boxes[t.boxes.length-1],i=o.start+o.len,s=await Et(e,n.chr+":"+(r+1)+"-"+i),a=It(t.qual),l=["<td>Reference</td>"],c=['<td style="color:black;text-align:left">Read</td>'];for(const e of t.boxes)if("H"!=e.opr)if("I"!=e.opr)if("D"!=e.opr&&"N"!=e.opr)if("S"!=e.opr)if("M"!=e.opr&&"="!=e.opr&&"X"!=e.opr&&"*"!=e.opr);else for(let n=0;n<e.len;n++){const o=s[e.start-r+n],i=t.seq[e.cidx+n];l.push("<td>"+o+"</td>"),"*"==t.qual?c.push('<td style="color:black;background:'+(o.toUpperCase()==i.toUpperCase()?S:E)+'">'+t.seq[e.cidx+n]+"</td>"):c.push('<td style="background:'+(o.toUpperCase()==i.toUpperCase()?S:E)(a[e.cidx+n]/ft)+'">'+t.seq[e.cidx+n]+"</td>")}else for(let n=0;n<e.len;n++)l.push("<td>"+s[e.start-r+n]+"</td>"),"*"==t.qual?c.push('<td style="background:'+P(1)+'">'+t.seq[e.cidx+n]+"</td>"):c.push('<td style="background:'+P(a[e.cidx+n]/ft)+'">'+t.seq[e.cidx+n]+"</td>");else if(e.len>=vt)l.push('<td style="font-size:.8em;opacity:.5;white-space:nowrap">'+e.len+" bp</td>"),c.push('<td style="color:black;white-space:nowrap">-----------</td>');else for(let t=0;t<e.len;t++)l.push("<td>"+s[e.start-r+t]+"</td>"),c.push('<td style="color:black">-</td>');else for(let n=e.cidx;n<e.cidx+e.len;n++)l.push("<td>-</td>"),"*"==t.qual?c.push('<td style="color:'+z+';background:white">'+t.seq[n]+"</td>"):c.push('<td style="color:'+z+";background:"+S(a[n]/ft)+'">'+t.seq[n]+"</td>");let u=0,f=0,d=[],h=[],p=0;for(const e of t.boxes)u=f,f+=e.len,"S"==e.opr&&(p=1,d.push(u),h.push(f));const m=[];t.rnext&&m.push('<li>Next segment on <span style="background:'+A+'">'+(n.nochr?"chr":"")+t.rnext+", "+t.pnext+"</span></li>"),t.discord_wrong_insertsize&&t.discord_orientation?m.push('<li><span style="background:'+T+';color:white">Wrong insert size</span> mate position: '+t.pnext+'</li><li><span style="background:'+D+';color:white">Segments also having wrong orientation</span> '+t.discord_orientation_direction+"</li>"):t.discord_wrong_insertsize?m.push('<li><span style="background:'+T+';color:white">Wrong insert size</span> mate position: '+t.pnext+"</li>"):t.discord_orientation?m.push('<li><span style="background:'+D+';color:white">Segments having wrong orientation</span> '+t.discord_orientation_direction+"</li>"):t.discord_unmapped2&&m.push('<li><span style="background:'+F+';color:white">Other segment in template is unmapped</span></li>'),1&t.flag&&m.push("<li>Template has multiple segments</li>"),2&t.flag&&m.push("<li>Each segment properly aligned</li>"),16&t.flag&&m.push("<li>Reverse complemented</li>"),32&t.flag&&m.push("<li>Next segment in the template is reverse complemented</li>"),64&t.flag&&m.push("<li>This is the first segment in the template</li>"),128&t.flag&&m.push("<li>This is the last segment in the template</li>"),256&t.flag&&m.push("<li>Secondary alignment</li>"),512&t.flag&&m.push("<li>Not passing filters</li>"),1024&t.flag&&m.push("<li>PCR or optical duplicate</li>"),2048&t.flag&&m.push("<li>Supplementary alignment</li>");let g={seq:t.seq,alignment:`<table style="border-spacing:0px;border-collapse:separate;text-align:center;font-family:courier">\n\t\t\t <tr style="opacity:.6">${l.join("")}</tr>\n\t\t\t <tr style="color:white">${c.join("")}</tr>\n\t\t\t</table>`,info:`<div style='margin-top:10px'>\n\t\t\t<span style="opacity:.5;font-size:.7em">CHR</span>: ${n.chr.replace("chr","")},\n\t\t\t<span style="opacity:.5;font-size:.7em">START</span>: ${t.segstart_original+1},\n\t\t\t<span style="opacity:.5;font-size:.7em">STOP</span>: ${i},\n\t\t\t<span style="opacity:.5;font-size:.7em">READ LENGTH</span>: ${t.seq.length} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">TEMPLATE LENGTH</span>: ${Math.abs(t.tlen)} bp,\n\t\t\t<span style="opacity:.5;font-size:.7em">CIGAR</span>: ${t.cigarstr}\n\t\t\t<span style="opacity:.5;font-size:.7em">FLAG</span>: ${t.flag}\n\t\t\t<span style="opacity:.5;font-size:.7em">NAME: ${t.qname}</span>\n\t\t </div>\n\t\t <ul style='padding-left:15px'>${m.join("")}</ul>`,start_readpos:r+1,boxes:t.boxes,readpanel_DN_maxlength:vt};return 1==p&&(g.soft_starts=d,g.soft_stops=h),t.discord_unmapped2&&(g.unmapped_mate=!0),g}function $t(t){const e=i.createHmac("md5",_t),n=[t.get("X-Auth-Token")||t.cookies.sessionid,t.query.gdcFileUUID,t.query.gdcFilePosition];return e.update(n.join("")).digest("hex")+".bam"}async function Gt(t){const e=t.query.regions;if(!Array.isArray(e)||0==e.length)throw"req.query.regions[] not non-empty array";const n=[];for(const r of e){const e=await Ut(r.chr,r.start,r.stop,t.get("X-Auth-Token"),t.query.gdcFileUUID,$t(t),t.cookies.sessionid);n.push({filesize:e})}return n}async function Ut(t,e,n,r,o,i,s){const f={compression:!1};s?f.Cookie=`sessionid=${s}`:f["X-Auth-Token"]=r;const h=c.join(x.cachedir_bam,i),p=bt+"/slicing/view/"+o+"?region="+t+":"+e+"-"+n;try{if(await d.file_not_exist(h)&&(await l(a.stream(p,{method:"GET",headers:f}),u.createWriteStream(h)),await d.file_not_exist(h)))throw"BAM file slice is not found after downloading";const t=h+".bai";if(await d.file_not_exist(t)&&(await async function(t){await d.get_lines_bigfile({isbam:!0,args:["index",t],callback:()=>{}})}(h),await d.file_not_exist(t)))throw"index file is missing after indexing";const e=await u.promises.stat(h);return _(e.size,!0)}catch(t){throw t.stack&&console.log(t.stack),"Error with BAM slicing: "+(t.message||t)}}t.exports=t=>async(e,n)=>{try{if(delete e.query.isFileSlice,e.query.gdcFileUUID){const t=e.cookies.sessionid,n=e.get("X-Auth-Token");if(!n&&!t)throw"GDC token or sessionid missing";await w(e.query.gdcFileUUID,n,t),e.query.file=$t(e),e.query.isFileSlice=!0}if(e.query.downloadgdc)return void n.send(await Gt(e));if(e.query.clientdownloadgdcslice){if(!e.query.file||!e.query.isFileSlice)throw"invalid query";const t=c.join(x.cachedir_bam,e.query.file),r=await u.promises.readFile(t);return n.writeHead(200,{"Content-Type":"application/octet-stream","Content-Disposition":"attachment; filename=gdc.bam","Content-Length":r.length}),void n.end(Buffer.from(r,"binary"))}if(!e.query.genome)throw".genome missing";const o=t[e.query.genome];if(!o)throw"invalid genome";if(e.query.getread)return void n.send(await async function(t,e){if(!e.query.chr)throw".chr missing";if(!e.query.qname)throw".qname missing";if(e.query.qname=decodeURIComponent(e.query.qname),!e.query.start)throw".start missing";if(!e.query.stop)throw".stop missing";const n={chr:e.query.chr,start:Number(e.query.start),stop:Number(e.query.stop),scale:()=>{},ntwidth:10};if(!Number.isInteger(n.start))throw".start not integer";if(!Number.isInteger(n.stop))throw".stop not integer";const o=await async function(t,e){let n,o,i,s,a,l,u,f,p;if(t.query.isFileSlice)a=c.join(x.cachedir_bam,t.query.file),await kt(t,a);else{if([s,a,l]=r.fileurl(t),s)throw s;i=l?await d.cache_index(a,t.query.indexURL||a+".bai"):null}if(t.query.unknownorder&&(u=Number(t.query.readstart),f=Number(t.query.readstop),Number.isNaN(u)||Number.isNaN(f)))throw"readstart/stop not provided for read with unknown order";if(await d.get_lines_bigfile({isbam:!0,args:["view",a,(t.query.nochr?t.query.chr.replace("chr",""):t.query.chr)+":"+e.start+"-"+e.stop],dir:i,callback:(r,i)=>{if(r.split("\t")[0]!=t.query.qname)return;const s=Ct({sam_info:r,keepallboxes:!0,keepmatepos:!0,keepunmappedread:!0},e);if(s&&(!t.query.show_unmapped||!s.discord_unmapped2))if(t.query.show_unmapped&&t.query.getfirst){if(s.islast)return i.kill(),void(p=[s])}else if(t.query.show_unmapped&&t.query.getlast){if(s.isfirst)return i.kill(),void(p=[s])}else if(t.query.getfirst){if(s.isfirst)return i.kill(),void(p=[s])}else if(t.query.getlast){if(s.islast)return i.kill(),void(p=[s])}else if(t.query.unknownorder){if(s.segstart==u&&s.segstop==f)return i.kill(),void(p=[s])}else if(s.isfirst?n=s:s.islast&&(o=s),n&&o)return i.kill(),void(p=[n,o])}}),p){if(t.query.altseqs){const e={query_seq:p[0].seq,refseqs:t.query.refseqs,altseqs:t.query.altseqs,cigar_seq:p[0].cigarstr,start_position:p[0].segstart,ref_positions:t.query.ref_positions,refalleles:t.query.refalleles,altalleles:t.query.altalleles},n=(await h("align",JSON.stringify(e))).split("\n");let r;for(let t of n)t.includes("Final_output:")?r=JSON.parse(t.replace("Final_output:","")):console.log(t);p.alignments=r}return p}p=[],n&&p.push(n);o&&p.push(o);return p.length?p:null}(e,n);if(!o){if(e.query.show_unmapped)throw"mate not found";throw"read not found"}const i=[];for(const n of o)n.discord_unmapped1?i.push(await zt(n,t,e.query)):i.push(await Zt(n,t,e.query));o.alignments&&(i[0].alignments=o.alignments);return{lst:i}}(o,e));const i=x.debugmode?new Date:null,s=await async function(t,e){let n;if(e.query.isFileSlice)n={genome:t,file:c.join(x.cachedir_bam,e.query.file),asPaired:e.query.asPaired,getcolorscale:e.query.getcolorscale,devicePixelRatio:e.query.devicePixelRatio?Number(e.query.devicePixelRatio):1},await kt(e,n.file);else{const[o,i,s]=r.fileurl(e);if(o)throw o;n={genome:t,file:i,asPaired:e.query.asPaired,getcolorscale:e.query.getcolorscale,devicePixelRatio:e.query.devicePixelRatio?Number(e.query.devicePixelRatio):1},s&&(n.dir=await d.cache_index(i,e.query.indexURL||i+".bai"))}if(e.query.pileupheight&&(n.pileupheight=Number(e.query.pileupheight),Number.isNaN(n.pileupheight)))throw".pileupheight is not integer";e.query.drop_pcrduplicates&&(n.drop_pcrduplicates=!0);if(e.query.variant){n.diff_score_plotwidth=Number(e.query.diff_score_plotwidth),e.query.max_diff_score&&(n.max_diff_score=Number(e.query.max_diff_score),n.min_diff_score=Number(e.query.min_diff_score));const t=e.query.variant.split(".");if(n.strictness=e.query.strictness,!Number.isInteger(t.length%4))throw"invalid variant, not chr.pos.ref.alt";n.alleleAlreadyUpdated=e.query.alleleAlreadyUpdated,n.alleleAlreadyUpdated&&(n.altseqs=e.query.altseqs,n.refseqs=e.query.refseqs,n.altalleles=e.query.altalleles,n.refalleles=e.query.refalleles,n.leftflankseqs=e.query.leftflankseqs,n.rightflankseqs=e.query.rightflankseqs,n.ref_positions=e.query.ref_positions);const r=t.length/4,o=[];for(let e=0;e<r;e++)o.push({chr:t[4*e],pos:Number(t[4*e+1]),ref:t[4*e+2],alt:t[4*e+3]});if(n.variant=o,e.query.alignOneGroup&&(n.alignOneGroup=e.query.alignOneGroup),Number.isNaN(n.variant.pos))throw"variant pos not integer"}else if(e.query.sv){const t=e.query.sv.split(".");if(t.length<6)throw"invalid sv, not chrA.posA.chrB.posB";if(n.sv={chrA:t[0],startA:Number(t[1]),strandA:Number(t[2]),chrB:t[3],startB:Number(t[4]),strandB:Number(t[5])},Number.isNaN(n.sv.startA))throw"sv.startA not integer";if(Number.isNaN(n.sv.startB))throw"sv.startB not integer"}if(Number.isFinite(Number(e.query.stackstart))){if(!e.query.stackstop)throw".stackstop missing";if(n.partstack={start:Number(e.query.stackstart),stop:Number(e.query.stackstop)},Number.isNaN(n.partstack.start))throw".stackstart not integer";if(Number.isNaN(n.partstack.stop))throw".stackstop not integer";if(!e.query.grouptype)throw".grouptype required for partstack";n.grouptype=e.query.grouptype}e.query.gdc||(e.query.nochr?n.nochr="string"==typeof e.query.nochr?JSON.parse(e.query.nochr):e.query.nochr:n.nochr=await d.bam_ifnochr(n.file,t,n.dir));if(n.regions=e.query.regions,!Array.isArray(n.regions)||0==n.regions.length)throw"q.regions[] not non-empty array";let o=0;for(const t of n.regions){if(!t.chr)throw".chr missing from a region";if(!Number.isInteger(t.start))throw".start not integer of a region";if(!Number.isInteger(t.stop))throw".stop not integer of a region";t.scale=e=>Math.ceil(t.width*(e-t.start)/(t.stop-t.start)),t.ntwidth=t.width/(t.stop-t.start),o=Math.max(o,t.ntwidth)}return n.stacksegspacing=Math.max(2,5*o),n.readcount_skipped=0,n}(o,e);n.send(await async function(t){await async function(t){if(t.variant){let e=0,n=0,r=0,o=t.variant[0].pos,i=t.variant[0].pos+Math.max(t.variant[0].ref.length,t.variant[0].alt.length);for(const s of t.variant){const t=Math.abs(s.pos-Math.max(s.ref.length,s.alt.length));t>e&&(e=t,n=r),o>s.pos&&(o=s.pos),i<s.pos+Math.max(s.ref.length,s.alt.length)&&(i=s.pos+Math.max(s.ref.length,s.alt.length)),r+=1}e=Math.floor(1.5*Math.max(t.variant[n].ref.length,t.variant[n].alt.length));const s={chr:t.variant[0].chr,start:o-e,stop:i+e};return await Nt(t,[s]),await St(s,t),void(t.regions[0].lines=s.lines)}await Nt(t,t.regions);for(const e of t.regions)await St(e,t)}(t),t.totalnumreads=t.regions.reduce(((t,e)=>t+e.lines.length),0);const e={nochr:t.nochr,count:{r:t.totalnumreads},groups:[]};t.read_limit_reached&&(e.count.read_limit_reached=t.read_limit_reached);t.canvaswidth=t.regions[t.regions.length-1].x+t.regions[t.regions.length-1].width;{const n=await async function(t){const e=[],n=[];let r=0;for(const o of t.regions){for(const t of o.lines)e.push({sam_info:t,tempscore:""});r=o.x+o.width,n.push(r)}if(0==e.length)return{groups:[{type:v.type_all,regions:v.duplicateRegions(t.regions),templates:e,messages:[],partstack:t.partstack,widths:n}]};if(t.variant){if(1==t.regions.length)return await y(t,e,n);console.log("Indel pipeline works only in single region. Please check!")}if(t.sv&&t.regions.length>1)return async function(t,e,n){const r=v.make_type2group(e),o=[];for(let t=0;t<e.regions.length;t++){const n=e.regions[t],r=(await d.get_fasta(e.genome,n.chr+":"+n.start+"-"+n.stop)).split("\n").slice(1).join("").toUpperCase(),i=[];for(const e of n.lines)i.push({sam_info:e,tempscore:"",ridx:t});const s={refseq:r,start:n.start,stop:n.stop,entries:i};0==t?(s.chr=e.sv.chrA,s.pos=e.sv.startA):1==t?(s.chr=e.sv.chrB,s.pos=e.sv.startB):console.log("More than two regions, please check"),o.push(s)}const i=new Date,s=(await h("sv",JSON.stringify(o))).split("\n"),a=new Date;let l,c;console.log("Time taken to run rust SV pipeline:",a-i,"ms");for(let t of s)t.includes("multi_region_templates:")?l=JSON.parse(t.replace("multi_region_templates:","")):t.includes("single_region_templates:")&&(c=JSON.parse(t.replace("single_region_templates:","")));if(!e.grouptype||"support_sv"==e.grouptype)for(const t of l)r[v.type_supportsv].templates.push(t);if(!e.grouptype||"support_ref"==e.grouptype)for(const t of c)r[v.type_supportref].templates.push(t);const u=[];for(const t in r){const e=r[t];0!=e.templates.length&&(t==v.type_supportsv?1==e.templates.length?e.messages.push({isheader:!0,t:e.templates.length+" read supporting SV/fusion"}):e.messages.push({isheader:!0,t:e.templates.length+" reads supporting SV/fusion"}):t==v.type_supportref&&e.messages.push({isheader:!0,t:e.templates.length+" reads supporting reference allele"}),e.widths=n,u.push(e))}return{groups:u}}(0,t,n);return{groups:[{type:v.type_all,regions:v.duplicateRegions(t.regions),templates:e,messages:[],partstack:t.partstack,widths:n}]}}(t);t.groups=n.groups,t.variant&&(e.ref_alleles=n.refalleles,e.alt_alleles=n.altalleles,e.allele_positions=n.ref_positions,e.strand_probability=n.strand_probability,e.alternate_forward_count=n.alternate_forward_count,e.reference_forward_count=n.reference_forward_count,e.alternate_reverse_count=n.alternate_reverse_count,e.reference_reverse_count=n.reference_reverse_count,1==n.strand_significance&&(e.strand_significance=!0),t.alleleAlreadyUpdated||(e.refseqs=n.refseqs,e.altseqs=n.altseqs,e.leftflankseqs=n.leftflankseqs,e.rightflankseqs=n.rightflankseqs,e.ref_positions=n.ref_positions,e.refalleles=n.refalleles,e.altalleles=n.altalleles)),Number.isFinite(t.max_diff_score)&&t.variant?(e.max_diff_score=t.max_diff_score,e.min_diff_score=t.min_diff_score):Number.isFinite(n.max_diff_score)&&(e.max_diff_score=n.max_diff_score,e.min_diff_score=n.min_diff_score),n.refalleleerror&&(e.refalleleerror=n.refalleleerror)}if(0==e.count.r)throw"No reads in view range.";if(t.alignOneGroup){const e=t.groups.find((e=>e.type==t.alignOneGroup));if(!e)throw"cannot find group for realignment";let n=Tt(t,e);return n=Ot(e,t,n),await async function(t,e,n){let r;if(e.variant)if("support_ref"==t.type){let o=e.leftflankseqs[0].length;r=t.partstack?await qt(n,o,t.partstack.start,t.partstack.stop,e.refseqs[0]):await qt(n,o,0,0,e.refseqs[0])}else if("support_no"==t.type){let o=e.leftflankseqs[0].length;r=t.partstack?await qt(n,o,t.partstack.start,t.partstack.stop):await qt(n,o)}else if("support_amb"==t.type)console.log("Realignment of reads in ambiguous group is not currently implemented");else if(t.type.includes("support_alt")){for(let o=0;o<e.variant.length;o++)if(t.type=="support_alt"+o.toString()){let i=e.leftflankseqs[o].length;r=t.partstack?await qt(n,i,t.partstack.start,t.partstack.stop,e.altseqs[o]):await qt(n,i,0,0,e.altseqs[o])}}else console.log("Unaccounted group, please check");return{alignmentData:r}}(e,t,n)}let n=[];for(const r of t.groups){let o=Tt(t,r);o=Ot(r,t,o),await jt(r,t,o),await Mt(o,t),Rt(r,o,t);const i={type:r.type,width:t.canvaswidth,height:r.canvasheight,stackheight:r.stackheight,stackcount:r.stacks.length,allowpartstack:r.allowpartstack,templatebox:r.returntemplatebox,count:{r:o.reduce(((t,e)=>t+e.segments.length),0)}},s=p(t.canvaswidth*t.devicePixelRatio,r.canvasheight*t.devicePixelRatio),a=s.getContext("2d");t.devicePixelRatio>1&&a.scale(t.devicePixelRatio,t.devicePixelRatio),a.textAlign="center",a.textBaseline="middle",i.messages=r.messages,i.messagerowheights=0;for(const e of o)Lt(a,e,r,t);Bt(a,r,t,o),t.asPaired&&(i.count.t=o.length),t.variant&&(i.diff_scores_img=await wt(t,r,o,e.max_diff_score,e.min_diff_score),"support_alt0"==i.type?i.group_color=Y:"support_alt1"==i.type?i.group_color=Q:"support_alt2"==i.type?i.group_color=K:"support_alt3"==i.type?i.group_color=X:"support_alt4"==i.type?i.group_color=tt:"support_alt5"==i.type?i.group_color=et:"support_ref"==i.type&&(i.group_color=nt)),i.src=s.toDataURL(),e.groups.push(i),n=[...n,...o]}t.readcount_skipped&&(e.count.skipped=t.readcount_skipped);t.getcolorscale&&(e.colorscale=function(t){const e=160,n=20,r=1,o=12,i=5,s=100,a=4,l=s+e+10,c=2*o+i+a+4*(n+r),u=p(t.devicePixelRatio*l,t.devicePixelRatio*c),f=u.getContext("2d");t.devicePixelRatio>1&&f.scale(t.devicePixelRatio,t.devicePixelRatio);f.fillStyle="black",f.font=o+"pt Arial",f.textAlign="center",f.fillText("Base quality",s+e/2,o);let d=2*o+i;function h(t,r,o){const i=s,a=f.createLinearGradient(i,o,i+e,o);a.addColorStop(0,r),a.addColorStop(1,t),f.fillStyle=a,f.fillRect(i,o,e,n)}return f.strokeStyle="black",f.beginPath(),f.moveTo(s,d),f.lineTo(s,d+a),f.moveTo(s+e/4,d),f.lineTo(s+e/4,d+a),f.moveTo(s+e/2,d),f.lineTo(s+e/2,d+a),f.moveTo(s+3*e/4,d),f.lineTo(s+3*e/4,d+a),f.moveTo(s+e,d),f.lineTo(s+e,d+a),f.closePath(),f.stroke(),f.fillText(40,s,d),f.fillText(30,s+e/4,d),f.fillText(20,s+e/2,d),f.fillText(10,s+3*e/4,d),f.fillText(0,s+e,d),f.textAlign="left",f.textBaseline="middle",d+=a,f.fillText("Match",0,d+n/2),h(N,q,d),d+=n+r,f.fillStyle="black",f.fillText("Mismatch",0,d+n/2),h(O,j,d),d+=n+r,f.fillStyle="black",f.fillText("Softclip",0,d+n/2),h(I,R,d),d+=n+r,f.fillStyle="black",f.fillText("Insertion",0,d+n/2),h(Z,z,d),{width:l,height:c,src:u.toDataURL()}}(t));if(!t.partstack)if(0==e.count.r);else{if(!t.pileupheight)throw"pileupheight missing";e.pileup_data=await async function(t,e){const n=p(t.canvaswidth*t.devicePixelRatio,t.pileupheight*t.devicePixelRatio),r=n.getContext("2d");t.devicePixelRatio>1&&r.scale(t.devicePixelRatio,t.devicePixelRatio);const o=[];let i=0;for(const[n,r]of t.regions.entries()){o[n]=await At(t,r),xt(n,r,e,o[n]);for(const t of o[n])t&&(i=Math.max(i,t.total))}for(const[e,n]of t.regions.entries()){const s=t.pileupheight/i;for(const i of o[e]){if(!i)continue;const e=(i.position-n.start)*n.ntwidth+n.x,o=n.ntwidth>=1?e:Math.floor(e),a=Math.max(1,n.ntwidth);{r.fillStyle=V;const e=i.total*s;r.fillRect(o,t.pileupheight-e,a,e)}let l=0;if(i.A){r.fillStyle=b.A;const e=i.A*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.C){r.fillStyle=b.C;const e=i.C*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.G){r.fillStyle=b.G;const e=i.G*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.T){r.fillStyle=b.T;const e=i.T*s;r.fillRect(o,t.pileupheight-l-e,a,e),l+=e}if(i.softclip){r.fillStyle=R;const e=i.softclip*s;r.fillRect(o,t.pileupheight-l-e,a,e)}}}return{width:t.canvaswidth,maxValue:i,src:n.toDataURL()}}(t,n)}return e}(s)),x.debugmode&&console.log("bam.js time ms",new Date-i)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},8953:(t,e,n)=>{"use strict";n.d(e,{Y:()=>s});n(8171).jStat,n(1017),n(9699).features;const r=n(3856),o=n(1271).run_rust,i=(n(2081).spawn,n(2781).Readable,n(4521),n(2384));n(7147),n(334).clustalo;async function s(t,e,n){const s=t.regions[0].lines[0].split("\t")[9].length;let a=!1,l=[],c=[],u=[],f=[],d=[],h=[],p=[];if(t.alleleAlreadyUpdated)l=t.leftflankseqs,c=t.rightflankseqs,h=t.refseqs,p=t.altseqs,u=t.refalleles,f=t.altalleles,d=t.ref_positions,0!=h[0].toUpperCase().localeCompare((l[0]+u[0]+c[0]).toUpperCase())&&(console.log("Reference allele is not correct for variant 0"),a=!0);else{let e,n,o=0;for(const i of t.variant){let a="",l="";if(!(0!=i.ref.length&&"-"!=i.ref||"-"!=i.alt&&0!=i.alt.length))throw"Both Ref and Alt alleles are missing";if(0==i.ref.length||"-"==i.ref)a=(await r.get_fasta(t.genome,i.chr+":"+i.pos+"-"+i.pos)).split("\n").slice(1).join("").toUpperCase(),l=a+i.alt,i.pos-=1;else if("-"==i.alt||0==i.alt.length){const e=(await r.get_fasta(t.genome,i.chr+":"+i.pos+"-"+i.pos)).split("\n").slice(1).join("").toUpperCase();a=e+i.ref,l=e,i.pos-=1}else l=i.alt,a=i.ref;const c=i.pos,h=a.toUpperCase(),p=l.toUpperCase();0==o?(e=c-s,n=c+a.length+1+s):(c-s<e&&(e=c-s),c+a.length+1+s>n&&(n=c+a.length+1+s)),u.push(h),f.push(p),d.push(c),o+=1}o=0;for(const i of t.variant){const s=(await r.get_fasta(t.genome,i.chr+":"+e+"-"+d[o])).split("\n").slice(1).join("").toUpperCase(),a=(await r.get_fasta(t.genome,i.chr+":"+(d[o]+u[o].length+1)+"-"+n)).split("\n").slice(1).join("").toUpperCase(),m=s+u[o]+a,g=s+f[o]+a;console.log(i.chr+"."+d[o]+"."+u[o]+"."+f[o]),o+=1,l.push(s),c.push(a),h.push(m),p.push(g)}}const m=[];for(let t=0;t<e.length;t++){const n=e[t].sam_info.split("\t");m.push({read_sequence:n[9],start_position:Number(n[3]),cigar:n[5],flag:Number(n[1])})}const g=[];for(let t=0;t<u.length;t++)g.push({ref_position:Number(d[t]),refallele:u[t],altallele:f[t],refseq:h[t],altseq:p[t],leftflankseq:l[t],rightflankseq:c[t]});Number.isFinite(Number(t.strictness))||(t.strictness=1);const y={reads:m,alleles:g,strictness:Number(t.strictness)},v=new Date,b=await o("indel",JSON.stringify(y)),_=new Date;console.log("Time taken to run rust indel pipeline:",_-v,"ms");const w=b.split("\n");let x,k,q,N,S,A,M=0;for(let t of w)t.includes("Final_output:")?x=JSON.parse(JSON.parse(t.replace("Final_output:",""))):1==u.length&&t.includes("fisher_strand:")?(k=JSON.parse(t.replace("fisher_strand:","")),q=k.alternate_forward_count,N=k.alternate_reverse_count,S=k.reference_forward_count,A=k.reference_reverse_count,M=k.p_value):console.log(t);let T=!1;1==t.variant.length&&M>60&&(T=!0);const C=i.make_type2group(t);t.variant.length;let j=1;for(let n=0;n<x.length;n++){const r=x[n],o=r.read_number,s=r.categories,a=r.categories[0],l=[];if(s.length>1){for(let t=1;t<s.length;t++)l.push(s[t]);s.length-1>j&&(j=s.length-1)}if(a.includes("alt"))for(let n=0;n<t.variant.length;n++)a=="alt"+n.toString()&&C[i.type_supportalt+n.toString()]&&(e[o].tempscore=["alt"+n.toString()],C[i.type_supportalt+n.toString()].templates.push(e[o]));else"ref"==a?C[i.type_supportref]&&(e[o].tempscore=["ref"],C[i.type_supportref].templates.push(e[o])):"none"==a?C[i.type_supportno]&&(e[o].tempscore=l,C[i.type_supportno].templates.push(e[o])):"amb"==a?C[i.type_supportamb]&&(e[o].tempscore=l,C[i.type_supportamb].templates.push(e[o])):console.log("Unaccounted group, please check")}const O=[];for(const e in C){const r=C[e];if(0!=r.templates.length){if(e.includes(i.type_supportalt))for(let n=0;n<t.variant.length;n++)e==i.type_supportalt+n.toString()&&(1==t.variant.length?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting the alternative allele"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting the alternative allele"}):1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read support the alternative allele with "+f[n]+" sequence"}):r.messages.push({isheader:!0,t:r.templates.length+" reads support the alternative allele with "+f[n]+" sequence"}));else e==i.type_supportamb?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" ambiguous read"}):r.messages.push({isheader:!0,t:r.templates.length+" ambiguous reads"}):e==i.type_supportref?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting the reference allele"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting the reference allele"}):e==i.type_supportno?1==r.templates.length?r.messages.push({isheader:!0,t:r.templates.length+" read supporting neither reference nor alternative alleles"}):r.messages.push({isheader:!0,t:r.templates.length+" reads supporting neither reference nor alternative alleles"}):console.log("Unaccounted group, please check");r.widths=n,O.push(r)}}const E=[];for(let t=0;t<O.length;t++)O[t].type.includes("support_alt")&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_ref"==O[t].type&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_no"==O[t].type&&E.push(O[t]);for(let t=0;t<O.length;t++)"support_amb"==O[t].type&&E.push(O[t]);return{groups:E,refalleleerror:a,ref_positions:d,refalleles:u,altalleles:f,max_diff_score:j,min_diff_score:0,strand_probability:M,strand_significance:T,refseqs:h,altseqs:p,leftflankseqs:l,rightflankseqs:c,alternate_forward_count:q,alternate_reverse_count:N,reference_forward_count:S,reference_reverse_count:A}}},1270:(t,e,n)=>{const r=n(9699),o=n(3856),i=n(6718).createCanvas,s=n(2273).basecolor;t.exports=async(t,e)=>{try{const[n,a,l]=r.fileurl(t);if(n)throw n;let c=t.query.usegrade;const u=Number(t.query.allheight),f=Number(t.query.fineheight),d=Number(t.query.fineymax),h=Number(t.query.midpad),p=Number(t.query.regionspace),m=Number(t.query.width);if(!Number.isInteger(u))throw"allheight is not integer";if(!Number.isInteger(f))throw"fineheight is not integer";if(!Number.isInteger(d))throw"fineymax is not integer";if(!Number.isInteger(h))throw"midpad is not integer";if(!Number.isInteger(p))throw"regionspace is not integer";if(!Number.isFinite(m))throw"width is not a number";const g="string"==typeof t.query.rglst?JSON.parse(t.query.rglst):t.query.rglst;if(!g)throw"no rglst[]";if(!Array.isArray(g))throw"rglst is not an array";if(0==g.length)throw"empty rglst";for(const t of g)t.reverse?t.scale=e=>Math.ceil(t.width*(t.stop-e)/(t.stop-t.start)):t.scale=e=>Math.ceil(t.width*(e-t.start)/(t.stop-t.start));let y;l&&(y=await o.cache_index(a,t.query.indexURL));for(const t of g){t.items=[];let e=0;await o.get_lines_bigfile({args:[a,t.chr+":"+t.start+"-"+t.stop],dir:y,callback:n=>{const r=n.split("\t");let o;try{o=JSON.parse(r[2])}catch(t){return void e++}const i=Number.parseInt(r[1]);t.items.push({pos:i,data:o})}})}const v=u+h+f,b=i(m,v),_=g.reduce(((t,e)=>t+e.items.length),0),w=b.getContext("2d");if(0==_)return w.font="15px Arial",w.fillStyle="#aaa",w.textAlign="center",w.textBaseline="middle",w.fillText("No data in view range",m/2,v/2),void e.send({src:b.toDataURL()});let x=null;if(!c){const t=new Set;for(const e of g)for(const n of e.items)for(const e in n.data)t.add(e);if(x=[...t],x.length>0&&(c=x[0]),!c)return void e.send({src:b.toDataURL()})}let k=0;for(const t of g)for(const e of t.items)if(e.data[c]){let t=0;for(const n in e.data[c])t+=e.data[c][n];k=Math.max(k,t)}const q="#ededed";let N=0;const S=u/k,A=f/d;for(const t of g){const e=t.width/(t.stop-t.start);for(const n of t.items){const r=n.data[c];if(!r)continue;const o=t.scale(n.pos);let i=0;const a=[];for(const t in r)a.push({nt:t,v:r[t]}),i+=r[t];w.fillStyle=q;const l=S*(k-i);if(w.fillRect(N+o,l,e,S*i),a.length>1){a.sort(((t,e)=>e.v-t.v));for(let t=1;t<a.length;t++){let n=0;for(let e=0;e<t;e++)n+=a[e].v;w.fillStyle=s[a[t].nt],w.fillRect(N+o,l+S*n,e,S*a[t].v)}}w.fillStyle=q;const f=u+h+A*(d-Math.min(i,d));if(w.fillRect(N+o,f,e,A*Math.min(i,d)),a.length>1)for(let t=1;t<a.length;t++){let n=0;for(let e=0;e<t;e++)n+=a[e].v;w.fillStyle=s[a[t].nt],w.fillRect(N+o,f+A*(d-Math.min(d,i-n)),e,A*Math.min(d,a[t].v))}}N+=t.width+p}e.send({src:b.toDataURL(),allgrades:x,usegrade:c,allmax:k})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}},2388:(t,e,n)=>{const r=n(9699),o=n(1017),i=(n(7147),n(3856)),s=n(6718).createCanvas,a=n(334);async function l(t,e,n){const o={rglst:[]};let a=0,l=0;if(t.autoscale){for(const r of t.rglst){const o=(n?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop;await i.get_lines_bigfile({args:[t.file,o],dir:e,callback:t=>{const[e,n,r,o]=t.split("\t");for(const t of o.split(",")){const e=Number(t);a=Math.min(a,e),l=Math.max(l,e)}}})}o.minv=a,o.maxv=l}else a=t.minv,l=t.maxv;const c=r.makeyscale().height(t.barheight).min(a).max(l);for(const r of t.rglst){const u={chr:r.chr,start:r.start,stop:r.stop,width:r.width,reverse:r.reverse,xoff:r.xoff},f=s(r.width,t.barheight),d=f.getContext("2d"),h=(n?r.chr.replace("chr",""):r.chr)+":"+r.start+"-"+r.stop;await i.get_lines_bigfile({args:[t.file,h],dir:e,callback:e=>{const[n,o,i,s]=e.split("\t"),u=Math.max(Number.parseInt(o),r.start),f=Math.min(Number.parseInt(i),r.stop),h=(r.reverse?r.stop-f:u-r.start)*r.width/(r.stop-r.start),p=(r.reverse?r.stop-u:f-r.start)*r.width/(r.stop-r.start);for(const e of s.split(",")){const n=Number(e);d.fillStyle=n>0?t.pcolor:t.ncolor;const r=c(n),o=Math.max(1,p-h);d.fillRect(h,r.y,o,2),n>l?(d.fillStyle=req.query.pcolor2,d.fillRect(h,0,o,2)):n<a&&(d.fillStyle=req.query.ncolor2,d.fillRect(h,t.barheight-2,o,2))}}}),u.img=f.toDataURL(),o.rglst.push(u)}return o}t.exports=t=>async(e,n)=>{try{const r=e.query,s=t[r.genome];if(!s)throw"unknown genome";let c=null;if(r.file)r.file=o.join(a.tpmasterdir,r.file);else{if(!r.url)throw"file or url missing";c=await i.cache_index(r.url,r.indexURL)}const u=await i.tabix_is_nochr(r.file||r.url,c,s),f=await l(r,c,u);n.send(f)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},8145:(t,e,n)=>{const r=n(9699),o=(n(1017),n(7147),n(3856)),i=n(6718).createCanvas,s=n(2273).nt2aa,a=n(2818).X,l=400,c="rgba(122,103,44,.7)",u="#edad0c",f="rgba(255,0,0,.5)",d="#ccc";function h(t,e,n,r,o){if(!t)return;if(!o.name&&!o.isoform)return;const i=[];o.name&&i.push(o.name),o.isoform&&i.push(o.isoform),t.push({chr:o.chr,start:o.start,stop:o.stop,x1:e,x2:n,y:r,isoform:o.isoform,name:i.join(" ")})}function p(t,e,n,r,o,i){const s=i/2,a=i/2,l=Math.max(i/2,6);if(o-2*s<a)return;const c=Math.ceil((o-2*s)/(a+l));if(c<=0)return;const u="+"==e;let f=Math.ceil(n+(o-a*c-l*(c-1))/2);for(let e=0;e<c;e++)t.beginPath(),u?(t.moveTo(f,r),t.lineTo(f+a,r+i/2),t.moveTo(f+a,r+i/2+1),t.lineTo(f,r+i)):(t.moveTo(f+a,r),t.lineTo(f,r+i/2),t.moveTo(f,r+i/2+1),t.lineTo(f+a,r+i)),t.stroke(),f+=a+l}t.exports=t=>async(e,n)=>{try{n.send(await async function(t,e){const[n,m,g]=r.fileurl(t);if(n)throw n;let y,v,b,_,w;if(t.query.fileIsBigbed=await o.testIfFileIsBigbed(m),t.query.getdata)t.query.getBED;else{if(y=Number(t.query.stackheight),v=Number(t.query.stackspace),b=Number(t.query.regionspace),_=Number(t.query.width),Number.isNaN(y))throw"stackheight is not integer";if(w=Math.max(10,y-2),Number.isNaN(v))throw"stackspace is not integer";if(Number.isNaN(b))throw"regionspace is not integer";if(Number.isNaN(_))throw"width is not a number"}if(t.query.usevalue){if(!t.query.usevalue.key)throw".key missing from .usevalue";if(t.query.usevalue.dropBelowCutoff&&(t.query.usevalue.dropBelowCutoff=Number(t.query.usevalue.dropBelowCutoff),Number.isNaN(t.query.usevalue.dropBelowCutoff)))throw".usevalue.dropBelowCutoff is not number"}if(t.query.bplengthUpperLimit&&(t.query.bplengthUpperLimit=Number(t.query.bplengthUpperLimit),Number.isNaN(t.query.bplengthUpperLimit)))throw"bplengthUpperLimit not number";if(!t.query.rglst)throw"no rglst[]";if(!Array.isArray(t.query.rglst))throw"rglst is not an array";if(0==t.query.rglst.length)throw"empty rglst";for(const e of t.query.rglst)e.reverse?e.scale=t=>Math.ceil(e.width*(e.stop-t)/(e.stop-e.start)):e.scale=t=>Math.ceil(e.width*(t-e.start)/(e.stop-e.start));const x=t.query.color||"#3D7A4B",k=t.query.gmregion||null,q=t.query.isoform,N=t.query.onerow,S=t.query.categories||null,A=t.query.__isgene;let M;!t.query.fileIsBigbed&&g&&(M=await o.cache_index(m,t.query.indexURL));const T=await async function(t,e,n,r,i){let s;if(r){const l=[];if(t.fileIsBigbed){const n=await o.query_bigbed_by_coord(e,r.chr,r.start,r.stop);for(const e of n){const n=e.split("\t"),r=a(n);r.chr=n[0],r.start=Number(n[1]),r.stop=Number(n[2]),r.rglst=[];for(let e=0;e<t.rglst.length;e++){const n=t.rglst[e];Math.max(r.start,n.start)<Math.min(r.stop,n.stop)&&r.rglst.push({idx:e})}0!=r.rglst.length&&l.push(r)}}else await o.get_lines_bigfile({args:[e,r.chr+":"+r.start+"-"+r.stop],dir:n,callback:e=>{const n=e.split("\t");let r={};if(t.getBED)r.rest=n.slice(3);else if(n[3])try{r=JSON.parse(n[3])}catch(t){return void(s=e)}if(!r.isoformonly||r.isoformonly==i){r.chr=n[0],r.start=Number(n[1]),r.stop=Number(n[2]),r.rglst=[];for(let e=0;e<t.rglst.length;e++){const n=t.rglst[e];Math.max(r.start,n.start)<Math.min(r.stop,n.stop)&&r.rglst.push({idx:e})}0!=r.rglst.length&&l.push(r)}}});if(s)throw"Line with invalid JSON: "+s;return[l]}const l=[];for(const[r,i]of t.rglst.entries()){const c=[];if(t.fileIsBigbed){const t=await o.query_bigbed_by_coord(e,i.chr,i.start,i.stop);for(const e of t){const t=e.split("\t"),n=a(t);n.chr=t[0],n.start=Number(t[1]),n.stop=Number(t[2]),n.rglst=[{idx:r}],c.push(n)}}else await o.get_lines_bigfile({args:[e,i.chr+":"+i.start+"-"+i.stop],dir:n,callback:e=>{const n=e.split("\t");let o={};if(t.getBED)o.rest=n.slice(3);else if(n[3])try{o=JSON.parse(n[3])}catch(t){return void(s=e)}o.chr=n[0],o.start=Number(n[1]),o.stop=Number(n[2]),o.rglst=[{idx:r}],c.push(o)}});l.push(c)}if(s)throw"Line with invalid JSON: "+s;return l}(t.query,m,M,k,q);let C;t.query.filterByName&&(C=new Set(t.query.filterByName.split(/[\s\n]/).map((t=>t.trim()))));const j=[];for(const e of T)for(const n of e){if(t.query.usevalue){const e=n[t.query.usevalue.key];if(!Number.isFinite(e))continue;if(t.query.usevalue.dropBelowCutoff&&e<t.query.usevalue.dropBelowCutoff)continue}if(!(t.query.bplengthUpperLimit&&n.stop-n.start>t.query.bplengthUpperLimit)){if(C)if(n.isoform){if(!C.has(n.isoform))continue}else{if(!n.name)continue;if(!C.has(n.name))continue}j.push(n)}}if(t.query.getdata)return{items:j};if(0==j.length){const e=i(_*t.query.devicePixelRatio,y*t.query.devicePixelRatio),n=e.getContext("2d");return t.query.devicePixelRatio>1&&n.scale(t.query.devicePixelRatio,t.query.devicePixelRatio),n.font=y+"px Arial",n.fillStyle="#aaa",n.textAlign="center",n.textBaseline="middle",n.fillText("No data in view range",_/2,y/2),{src:e.toDataURL(),height:y}}const O=Math.ceil(y/4)-1;if(N||j.length>=600){const e=j.length<200,n=i(_*t.query.devicePixelRatio,y*t.query.devicePixelRatio),r=n.getContext("2d");t.query.devicePixelRatio>1&&r.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);const o=j.length<=200?[]:null;for(const n of j){const i=S&&n.category&&S[n.category]?S[n.category].color:n.color||x;r.fillStyle=i;for(const i of n.rglst){let s=0;for(let e=0;e<i.idx;e++)s+=t.query.rglst[e].width+b;const a=t.query.rglst[i.idx],l=[];n.utr5&&l.push(...n.utr5),n.utr3&&l.push(...n.utr3),!n.exon||n.coding&&0!=n.coding.length||l.push(...n.exon);for(const t of l){const e=Math.max(a.start,t[0]),i=Math.min(a.stop,t[1]),l=s+a.scale(a.reverse?i:e),c=s+a.scale(a.reverse?e:i);r.fillRect(l,O,Math.max(1,c-l),y-2*O),h(o,l,c,1,n)}const c=[];n.exon?n.coding&&n.coding.length>0&&c.push(...n.coding):c.push([n.start,n.stop]);for(const t of c){const i=Math.max(a.start,t[0]),l=Math.min(a.stop,t[1]),c=s+a.scale(a.reverse?l:i),u=s+a.scale(a.reverse?i:l);r.fillRect(c,0,Math.max(1,u-c),y),h(o,c,u,1,n),n.strand&&e&&(r.strokeStyle="white",p(r,n.strand,c,O,u-c,y-2*O))}}}return{src:n.toDataURL(),height:y,mapisoform:o}}if(t.query.hideItemNames)for(const t of j)delete t.name;let E=null;if(A&&j.length<50){E=[];for(const t of j){const e={};for(const n in t)"canvas"!=n&&"rglst"!=n&&(e[n]=t[n]);E.push(e)}}const R=t.query.rglst.reduce(((t,e)=>t+e.stop-e.start),0),I=t.query.translatecoding&&R<3*_;let P;if(I){if(!t.query.genome)throw"genome missing for translating genes";if(P=e[t.query.genome],!P)throw"invalid genome"}const F=[],L=i(10,10);let D=L.getContext("2d");t.query.devicePixelRatio>1&&D.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);D.font="bold "+w+"px Arial";const B=j.length<l,z=j.length<l?[]:null;let Z=!1;k&&(Z=k.reverse);for(const e of t.query.rglst)e.reverse&&(Z=!0);j.sort(((t,e)=>Z?t.stop==e.stop?t.start-e.start:e.stop-t.stop:t.start==e.start?e.stop-t.stop:t.start-e.start));const $=j.some((t=>t.exon)),G=[0];let U=1,J=null;for(const e of j){let n=null,r=null;for(const o of e.rglst){let i=0;for(let e=0;e<o.idx;e++)i+=t.query.rglst[e].width+b;const s=t.query.rglst[o.idx],a=Math.max(e.start,s.start),l=Math.min(e.stop,s.stop);if(a<l){const t=i+s.scale(s.reverse?l:a),e=i+s.scale(s.reverse?a:l);null==n?(n=t,r=e):(n=Math.min(n,t),r=Math.max(r,e))}}if(null==n)continue;e.canvas={start:n,stop:r,stranded:null!=e.strand},e.coding&&I&&(e.willtranslate=!0,F.push(e));let o=n,i=r;if(B){const t=e.name;if(t){e.canvas.namestr=t;const n=D.measureText(t).width;e.canvas.namewidth=n,$?e.canvas.start>=n+1?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):e.canvas.stop+n+1<=_?(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):n>e.canvas.stop-e.canvas.start?e.canvas.start>_-e.canvas.stop?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):(e.canvas.namehover=!0,e.canvas.textalign="left"):Math.min(_,e.canvas.stop)-Math.max(0,e.canvas.start)>=n+20?e.canvas.namein=!0:e.canvas.start>=n+1?(e.canvas.namestart=e.canvas.start-1,o=e.canvas.namestart-n,e.canvas.textalign="right"):e.canvas.stop+n+1<=_?(e.canvas.namestart=e.canvas.stop+1,i=e.canvas.namestart+n,e.canvas.textalign="left"):e.canvas.namein=!0}}e.canvas.stop-e.canvas.start>.3*_&&(J=[]);for(let t=1;t<=U;t++)if(null==G[t]||G[t]<o){e.canvas.stack=t,G[t]=i;break}null==e.canvas.stack&&(U++,G[U]=i,e.canvas.stack=U),h(z,o,i,e.canvas.stack,e)}L.width=_*t.query.devicePixelRatio;const W=(y+v)*U-v;L.height=W*t.query.devicePixelRatio,D=L.getContext("2d"),t.query.devicePixelRatio>1&&D.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);D.font="bold "+w+"px Arial",D.textBaseline="middle",D.lineWidth=1;for(const e of j){const n=e.canvas;if(!n)continue;const r=S&&e.category&&S[e.category]?S[e.category].color:e.color||x,o=(y+v)*(n.stack-1);D.fillStyle=r,(e.exon||e.rglst.length>1)&&(D.strokeStyle=r,D.beginPath(),D.moveTo(n.start,Math.floor(o+y/2)+.5),D.lineTo(n.stop,Math.floor(o+y/2)+.5),D.stroke());for(const i of e.rglst){let s=0;for(let e=0;e<i.idx;e++)s+=t.query.rglst[e].width+b;const a=t.query.rglst[i.idx],l=[];e.utr3&&l.push(...e.utr3),e.utr5&&l.push(...e.utr5),!e.exon||e.coding&&0!=e.coding.length||l.push(...e.exon);for(const t of l){const n=Math.max(t[0],a.start),i=Math.min(t[1],a.stop);if(n<i){if(e.exon2color)for(const t of e.exon2color)if(n>=t.start&&i<=t.stop){D.fillStyle=t.color;break}const t=s+a.scale(a.reverse?i:n),l=s+a.scale(a.reverse?n:i);D.fillRect(t,o+O,Math.max(1,l-t),y-2*O),e.exon2color&&(D.fillStyle=r)}}const c=[];e.exon?e.coding&&e.coding.length>0&&c.push(...e.coding):c.push([e.start,e.stop]);let u=e.strand;n.stranded&&a.reverse&&(u="+"==e.strand?"-":"+");for(const t of c){const i=Math.max(t[0],a.start),l=Math.min(t[1],a.stop);if(i<l){if(e.exon2color)for(const t of e.exon2color)if(i>=t.start&&l<=t.stop){D.fillStyle=t.color;break}const t=s+a.scale(a.reverse?l:i),c=s+a.scale(a.reverse?i:l);if(D.fillRect(t,o,Math.max(1,c-t),y),e.exon2color&&(D.fillStyle=r),n.stranded&&!e.willtranslate)if(D.strokeStyle="white",n.namein){const e=(c-t-n.namewidth)/2;p(D,u,t,o+O,e,y-2*O),p(D,u,t+e+n.namewidth,o+O,e,y-2*O)}else p(D,u,t,o+O,c-t,y-2*O)}}if(n.stranded&&e.intron){D.strokeStyle=r;for(const t of e.intron){const e=Math.max(t[0],a.start),n=Math.min(t[1],a.stop);if(e<n){const t=s+a.scale(a.reverse?n:e);p(D,u,t,o+O,s+a.scale(a.reverse?e:n)-t,y-2*O)}}}if(J&&e.exon){for(let t=0;t<e.exon.length;t++){const r=e.exon[t];if(r[1]<=a.start||r[0]>=a.stop)continue;const o=Math.max(r[0],a.start),i=Math.min(r[1],a.stop);if(o<i){const l=s+a.scale(a.reverse?i:o),c=s+a.scale(a.reverse?o:i);J.push({chr:e.chr,start:Math.min(r[0],r[1]),stop:Math.max(r[0],r[1]),x1:l,x2:c,y:n.stack,name:"Exon "+(t+1)+"/"+e.exon.length})}}for(let t=1;t<e.exon.length;t++){const r=e.exon["+"==e.strand?t-1:t][1],o=e.exon["+"==e.strand?t:t-1][0];if(o<=a.start||r>=a.stop)continue;const i=Math.max(r,a.start),l=Math.min(o,a.stop);if(i<l){const c=s+a.scale(a.reverse?l:i),u=s+a.scale(a.reverse?i:l);if(u<0)continue;J.push({chr:e.chr,start:r,stop:o,x1:c,x2:u,y:n.stack,name:"Intron "+t+"/"+(e.exon.length-1)})}}}}if(null!=n.namestart)D.textAlign=n.textalign,D.fillStyle=r,D.fillText(n.namestr,n.namestart,o+y/2);else if(n.namehover&&!t.query.noNameHover){const t=Math.max(10,n.start+10);D.fillStyle="white",D.fillRect(t,o,n.namewidth+10,y),D.strokeStyle=r,D.strokeRect(t+1.5,o+.5,n.namewidth+10-3,y-2),D.fillStyle=r,D.textAlign="center",D.fillText(n.namestr,t+n.namewidth/2+5,o+y/2)}else n.namein&&(D.textAlign="center",D.fillStyle="white",D.fillText(n.namestr,(Math.max(0,n.start)+Math.min(_,n.stop))/2,o+y/2))}const H={height:W,mapisoform:z,mapexon:J,returngmdata:E};if(0==F.length)return H.src=L.toDataURL(),H;const V=[];D.textAlign="center",D.textBaseline="middle";for(const[e,n]of F.entries()){const e=S&&n.category&&S[n.category]?S[n.category].color:n.color||x,r=n.canvas,i=(y+v)*(r.stack-1);n.genomicseq=(await o.get_fasta(P,n.chr+":"+(n.start+1)+"-"+n.stop)).split("\n").slice(1).join("").toUpperCase();const a=s(n);for(const e of n.rglst){const o=t.query.rglst[e.idx];let s=0;for(let n=0;n<e.idx;n++)s+=t.query.rglst[n].width+b;const l=o.width/(o.stop-o.start),h=Math.min(y,3*l),p=h<8?null:h;let m=!1;r.stranded&&"-"==n.strand&&(m=!0);let g=0;p&&(D.font=p+"px Arial");for(const[t,e]of n.coding.entries()){let[r,h]=e;if(m){if(r>=o.stop){g+=h-r,0==t&&n.startCodonFrame&&(g-=3-n.startCodonFrame);continue}if(h<=o.start)break}else{if(h<=o.start){g+=h-r,0==t&&n.startCodonFrame&&(g-=3-n.startCodonFrame);continue}if(r>=o.stop)break}if(0==t&&n.startCodonFrame){m?h-=3-n.startCodonFrame:r+=3-n.startCodonFrame;let t=Math.max(e[0],o.start),a=Math.min(e[1],o.stop);if(m?t=Math.max(h,o.start):a=Math.min(r,o.stop),t<a){D.fillStyle=d;const e=s+o.scale(o.reverse?a:t),n=s+o.scale(o.reverse?t:a);D.fillRect(e,i,Math.max(1,n-e),y)}}const v=Math.max(o.start,r),b=Math.min(o.stop,h);g+=m?h-b:v-r;let _=0;for(let t=0;t<b-v;t++){let e;if(g++,_++,g%3==0)e=g/3-1;else{if(t<b-v-1)continue;e=Math.floor(g/3)}let r=a[e],d=Math.ceil(g/3)%2==0?c:null;r?"M"==r?d=u:"*"==r&&(d=f):(r=4,d="red");let h,w=l*_;if(m){const e=b-1-t;h=s+o.scale(e)}else{const e=v+t+1-_;h=s+o.scale(e)}o.reverse&&(h-=w),_=0,h>=s&&h<=s+o.width&&(d&&(D.fillStyle=d,D.fillRect(h,i,w,y)),p&&(D.fillStyle="white",D.fillText(r,h+w/2,i+y/2)),V.push({x1:h,x2:h+w,y:n.canvas.stack,name:r+(e+1)+' <span style="font-size:.7em;color:#858585">AA residue</span>'}))}}}if(r.namehover&&!t.query.noNameHover){D.font="bold "+w+"px Arial";const t=Math.max(10,r.start+10);D.fillStyle="white",D.fillRect(t,i,r.namewidth+10,y),D.strokeStyle=e,D.strokeRect(t+1.5,i+.5,r.namewidth+10-3,y-2),D.fillStyle=e,D.fillText(r.namestr,t+r.namewidth/2+5,i+y/2)}}return H.src=L.toDataURL(),H.mapaa=V,H}(e,t))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},2818:(t,e,n)=>{const r=n(5727),o=new Set(["-1","0","1","2"]);e.X=function(t,e){t[0];const n=Number(t[1]),i=(t[2],t[3].split(".")[0]),s=t[5];if("+"!=s&&"-"!=s)return{name:i};const a="+"==s,l=Number(t[6]),c=Number(t[7]);if(!Number.isInteger(l)||!Number.isInteger(c))return{name:i,strand:s};const u=[],f=[],d=[],h=[],p=[],m=t[15],g=t[17],y=t[20];if(!t[10].includes(",")||!t[11].includes(","))return{name:i,strand:s};const v=t[10].split(",");v.pop();const b=v.map(Number),_=t[11].split(",");_.pop();const w=_.map(Number);if(b.includes(NaN)||w.includes(NaN))return{name:i,strand:s};let x=null,k=0,q=0;for(const[t,e]of b.entries()){k+=e;const r=n+w[t],o=r+e;a?p.push([r,o]):p.unshift([r,o]),t>0&&(a?h.push([x,r]):h.unshift([x,r])),x=o,r<l?o<l?a?f.push([r,o]):u.unshift([r,o]):(a?f.push([r,l]):u.unshift([r,l]),o>c?(l<c&&(a?d.push([l,c]):d.unshift([l,c]),q+=c-l),a?u.push([c,o]):f.unshift([c,o])):l<o&&(a?d.push([l,o]):d.unshift([l,o]),q+=o-l)):r<c?o<=c?r<o&&(a?d.push([r,o]):d.unshift([r,o]),q+=o-r):(r<c&&(a?d.push([r,c]):d.unshift([r,c]),q+=c-r),a?u.push([c,o]):f.unshift([c,o])):a?u.push([r,o]):f.unshift([r,o])}const N={name:g,isoform:i,strand:s,exon:p,rnalen:k};26==t.length&&(N.category=y),e&&e.has(i)&&(N.description=e.get(i)),h.length>0&&(N.intron=h),l==c||(N.cdslen=q,N.codingstart=l,N.codingstop=c,N.coding=d,f.length&&(N.utr5=f),u.length&&(N.utr3=u));const S=m.split(",");return S.pop(),S.length<1||S.some((t=>!o.has(t)))||r.default(N,m),N}},4353:(t,e,n)=>{const r=n(7147),o=n(1017),i=n(2081).spawn,s=n(3856),a=(n(9699),n(334)),l=(a.tabix,a.gfClient||"gfClient"),c=a.gfServer||"gfServer";function u(t,e){return new Promise(((n,r)=>{const o=i(c,["status",e.blat.host,e.blat.port]),s=[],a=[];o.stdout.on("data",(t=>s.push(t))),o.stderr.on("data",(t=>a.push(t))),o.on("close",(e=>{a.join("").trim()&&n(t+" OFF");const r=s.join("").trim().split("\n");let o=0;for(const t of r)t.startsWith("blat requests")&&(o=t.split(" ")[2]);n(t+" ON, "+o+" requests")}))}))}function f(t,e){const n=o.join(a.cachedir,Math.random().toString());return new Promise(((r,o)=>{const s=i(l,[t.blat.host,t.blat.port,"",e,n,"-q=dna","-nohead","-minScore=20","-minIdentity=0","-out=psl"]),a=[];s.stderr.on("data",(t=>a.push(t))),s.on("close",(t=>{const e=a.join("");e&&(console.log("BLAT error",e),o("blat server problem")),r(n)}))}))}e.x=t=>async(e,n)=>{try{if(e.query.serverstat){const e=[];for(const n in t){const r=t[n];r.blat&&e.push(await u(n,r))}if(0==e.length)throw"found no genome with blat";return void n.send({lst:e})}if(!e.query.genome)throw".genome missing";const i=t[e.query.genome];if(!i)throw"invalid genome";if(!i.blat)throw"blat not enabled";if(!e.query.seq)throw".seq missing";n.send(await async function(t,e,n,i){const l=o.join(a.cachedir,await s.write_tmpfile(">query\n"+e+"\n")),c=await f(t,l),u=(await s.read_file(c)).trim();if(r.unlink(c,(()=>{})),r.unlink(l,(()=>{})),""==u)return{nohit:1};const d=u.split("\n"),h=[];for(const t of d){const e={},n=t.split(" ").filter((function(t){return""!=t}))[0].split("\t");e.query_match=n[0],e.query_startpos=(parseInt(n[11])+1).toString(),e.query_stoppos=n[12],e.query_strand=n[8],e.query_totallen=n[10],e.query_alignlen=Math.abs(parseInt(n[11])-parseInt(n[12])).toString(),e.ref_chr=n[13],e.ref_startpos=(parseInt(n[15])+1).toString(),e.ref_stoppos=n[16],e.ref_alignlen=Math.abs(n[16]-n[15]).toString(),e.ref_totallen=n[14],h.push(e)}return h.sort(((t,e)=>e.query_match-t.query_match)),{hits:h}}(i,e.query.seq,e.query.soft_starts,e.query.soft_stops))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},7833:(t,e,n)=>{const r=n(8064),o=n(5494),i=n(6733),s=n(5558),a=n(3602),l=n(6279),c=n(8423),u=n(8235),f=n(1017),d=n(7147),h=n(334),{get_samples:p}=n(2852),m={snvindel:o,sv:l,fusion:l,svjson:c,cnv:i,itd:a,deletion:s,truncation:u};function g(t,e,n,r,o,i){for(const s of e.yesSamples){if(i&&!i.includes(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:parseInt(t),class:"WT",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:parseInt(t),class:"WT",_SAMPLEID_:s})}for(const s of e.noSamples){if(i&&!i.includes(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:parseInt(t),class:"Blank",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:parseInt(t),class:"Blank",_SAMPLEID_:s})}}async function y(t,e){const n=t.cohort;try{if(n.mutationFlagSet)return n.mutationFlagSet;if(!n.mutationset)return;const r={},o=t.sampleName2Id;for(const[t,i]of n.mutationset.entries()){const n=await v(t,i,e);r[Math.random()]=n;for(const t in n.data)for(const e of n.data[t])e._SAMPLENAME_=e.sample.split(";")[0].trim(),e._SAMPLEID_=o.get(e._SAMPLENAME_)||e._SAMPLENAME_}return n.mutationFlagSet=r,r}catch(t){throw t}}async function v(t,e,n){const o=r.init_bulk_flag(n);if(!o)throw"init_bulk_flag() failed";o.tpsetname=e.name?e.name:"set"+t;for(const t in e){if(!(t in m))throw`unknown mutationset: ${t}`;const n=e[t].startsWith("/")?e[t]:f.join(h.tpmasterdir,e[t]);try{const e=(await d.promises.readFile(n,"utf8")).trim().split(/\r?\n/);if(m[t].parseheader(e[0],o))throw`${t} header line error: herr`;for(let n=1;n<e.length;n++)m[t].parseline(n,e[n],o)}catch(t){throw t}}return o}e.mayGetGeneVariantData=async function(t,e){var n;const r=this,o=t.term.name,i=await y(r,e.genome),s=new Map;if(!i)return s;let a;(null==e||null===(n=e.filter)||void 0===n?void 0:n.lst.length)>0&&(a=[...new Set((await p(e.filter,r)).map((t=>t.id)))]);for(const t in i){var l;const e=i[t];if(o in e.data){for(const t of e.data[o]){const e=t._SAMPLEID_;if(a&&!a.includes(e))continue;s.has(e)||s.set(e,{sample:e});const n=s.get(e);o in n||(n[o]={key:o,values:[],label:o}),n[o].values.push(t)}if(null!==(l=r.assayAvailability)&&void 0!==l&&l.byDt)for(const t in r.assayAvailability.byDt){const e=r.assayAvailability.byDt[t];if(e.byOrigin)for(const n in e.byOrigin){g(t,e.byOrigin[n],s,o,n,a)}else g(t,e,s,o,!1,a)}}}return s},e.getTermTypes=async function(t){const e=this;try{const n="string"==typeof t.ids?JSON.parse(t.ids):t.ids,r=n.map((()=>"?")).join(","),o=`SELECT id, name, type, jsondata, parent_id FROM terms WHERE id IN (${r}) OR name IN (${r})`,i=e.cohort.db.connection.prepare(o).all([...n,...n]),s={};for(const t of i)t.jsondata&&Object.assign(t,JSON.parse(t.jsondata)),s[t.id]=t;const a=n.filter((t=>!s[t])),l=await y(e,t.genome);if(l)for(const t in l){const e=l[t];if(e.data)for(const t of a)t in e.data&&!(t in s)&&(s[t]={name:t,type:"geneVariant"})}return s}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}},e.mayGetMatchingGeneNames=async function(t,e,n,r=25){const o=await y(this,n.genome);if(o)for(const n in o){const s=o[n];for(const n in s.data){var i;if(n.length>r)continue;if(null===(i=s.data[n])||void 0===i||!i.length)continue;const o={name:n,type:"geneVariant",isleaf:!0};n===e?t.equals.push(o):n.startsWith(e)?t.startsWith.push(o):n.includes(" "+e)?t.startsWord.push(o):n.includes(e)?t.includes.push(o):"TP53"==n&&0}}},e.get_flagset=y},2824:(t,e,n)=>{"use strict";n.d(e,{q:()=>u});const r=n(9699),o=n(6718).createCanvas,i=n(3856),s=n(1271).run_rust,a=n(334),l=n(2081).spawn,{rgb:c}=n(7346);async function u(t,e){try{let n,l,u,p,m=!1,g=!1;const[y,v,b]=r.fileurl(t);if(y)throw y;if(v.endsWith(".gz")&&(g=!0,b&&(p=await i.cache_index(v,t.query.indexURL))),t.query.autoscale)m=!0;else if(t.query.percentile){if(u=t.query.percentile,!Number.isFinite(u))throw"invalid percentile"}else{if(n=t.query.minv,l=t.query.maxv,!Number.isFinite(n))throw"invalid minv";if(!Number.isFinite(l))throw"invalid maxv"}if(!Number.isFinite(t.query.barheight))throw"invalid barheight";if(!Number.isFinite(t.query.regionspace))throw"invalid regionspace";if(!Number.isFinite(t.query.width))throw"invalid width";if(!t.query.rglst)throw"region list missing";if(t.query.dotplotfactor&&!Number.isInteger(t.query.dotplotfactor))throw"dotplotfactor value should be positive integer";if(g)return await async function(t,e,n,r,i,s){if(null==n||null==r)throw"Y axis scale must be defined for bedgraph track";const a=o(t.query.width*t.query.devicePixelRatio,t.query.barheight*t.query.devicePixelRatio),l=a.getContext("2d");t.query.devicePixelRatio>1&&l.scale(t.query.devicePixelRatio,t.query.devicePixelRatio);let c=0;for(let e of t.query.rglst)await f(t,e,c,n,r,i,s,l),c+=e.width+t.query.regionspace;e.send({src:a.toDataURL()})}(t,e,n,l,v,p);for(const e of t.query.rglst){let n;if(a.features.bigwig_rust){const r=v+","+e.chr+","+e.start+","+e.stop+","+Math.ceil(e.width*(t.query.dotplotfactor||1));n=await s("bigwig",r)}else n=await h(t,e,v);n&&(e.values=n.trim().split("\t").map(Number.parseFloat),t.query.dividefactor&&(e.values=e.values.map((e=>e/t.query.dividefactor))))}let _=!0;for(const e of t.query.rglst)e.values&&(_=!1);const w=o(t.query.width*t.query.devicePixelRatio,t.query.barheight*t.query.devicePixelRatio),x=w.getContext("2d");if(t.query.devicePixelRatio>1&&x.scale(t.query.devicePixelRatio,t.query.devicePixelRatio),_)return x.font="14px Arial",x.fillStyle="#858585",x.textAlign="center",x.textBaseline="middle",x.fillText(t.query.name+": no data in view range",t.query.width/2,t.query.barheight/2),void e.send({src:w.toDataURL(),nodata:!0});const k=1,q=t.query.dotplotfactor?1/t.query.dotplotfactor:1;let N=0,S=0;const A={};if(m||u){const e=[],n=[];for(const r of t.query.rglst)if(r.values)for(const t of r.values)Number.isNaN(t)||(t>=0&&e.push(t),t<=0&&n.push(t));e.length&&(e.sort(((t,e)=>t-e)),N=m?e[e.length-1]:e[Math.floor(e.length*u/100)]),n.length&&(n.sort(((t,e)=>e-t)),S=m?n[n.length-1]:n[Math.floor(n.length*u/100)]),A.minv=S,A.maxv=N}else S=n,N=l;if(t.query.barheight<10){let e=c(t.query.pcolor);const n=e.r+","+e.g+","+e.b;e=c(t.query.ncolor);const r=e.r+","+e.g+","+e.b;let o=0;for(const e of t.query.rglst){if(e.values)for(let i=0;i<e.values.length;i++){const s=e.values[i];if(Number.isNaN(s))continue;x.fillStyle=s>=N?t.query.pcolor2:s>=0?"rgba("+n+","+s/N+")":s<=S?t.query.ncolor2:"rgba("+r+","+s/S+")";const a=Math.ceil(o+(e.reverse?e.width-q*i:q*i));x.fillRect(a,0,k,t.query.barheight)}o+=e.width+t.query.regionspace}}else{const e=d().height(t.query.barheight).min(S).max(N);let n=0;for(const r of t.query.rglst){if(r.values)for(let o=0;o<r.values.length;o++){const i=r.values[o];if(Number.isNaN(i))continue;x.fillStyle=i>0?t.query.pcolor:t.query.ncolor;const s=Math.ceil(n+(r.reverse?r.width-q*o:q*o)),a=e(i);if(i>0)x.fillRect(s,a.y,k,t.query.dotplotfactor?Math.min(2,a.h):a.h);else if(t.query.dotplotfactor){const t=Math.min(2,a.h);x.fillRect(s,a.y+a.h-t,k,t)}else x.fillRect(s,a.y,k,a.h);i>N?(x.fillStyle=t.query.pcolor2,x.fillRect(s,0,k,2)):i<S&&(x.fillStyle=t.query.ncolor2,x.fillRect(s,t.query.barheight-2,k,2))}n+=r.width+t.query.regionspace}}A.src=w.toDataURL(),e.send(A)}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}async function f(t,e,n,r,o,s,a,l){const c=d().height(t.query.barheight).min(r).max(o),u=e.width/(e.stop-e.start);await i.get_lines_bigfile({args:[s,e.chr+":"+e.start+"-"+e.stop],dir:a,callback:i=>{const s=i.split("\t"),a=Number.parseInt(s[1]);if(Number.isNaN(a))return;const f=Number.parseInt(s[2]);if(Number.isNaN(f))return;const d=Number.parseFloat(s[3]);if(Number.isNaN(d))return;l.fillStyle=d>0?t.query.pcolor:t.query.ncolor;const h=c(d),p=n+(Math.max(a,e.start)-e.start)*u,m=n+(Math.min(f,e.stop)-e.start)*u,g=Math.max(1,m-p);l.fillRect(p,h.y,g,h.h),d>o?(l.fillStyle=t.query.pcolor2,l.fillRect(p,0,g,2)):d<r&&(l.fillStyle=t.query.ncolor2,l.fillRect(p,t.query.barheight-2,g,2))}})}function d(){var t=50,e=0,n=100;function r(r){var o,i=!1,s=0;return 0==e&&0==n||e<=0&&n>=0&&(i=!0,s=t*n/(n-e)),i?r>=n?{y:0,h:s}:r>=0?{y:s-(o=s*r/n),h:o}:r<=e?{y:s,h:t-s}:{y:s,h:o=(t-s)*r/e}:r<=e?{y:t,h:0}:{y:t-(o=t*(r-e)/(n-e)),h:o}}return r.height=function(e){return t=e,r},r.min=function(t){return e=t,r},r.max=function(t){return n=t,r},r}function h(t,e,n){return new Promise(((r,o)=>{const i=l(a.bigwigsummary,["-udcDir="+a.cachedir,n,e.chr,e.start,e.stop,Math.ceil(e.width*(t.query.dotplotfactor||1))]),s=[],c=[];i.stdout.on("data",(t=>s.push(t))),i.stderr.on("data",(t=>c.push(t))),i.on("close",(t=>{const e=c.join("");e.length?e.startsWith("no data")?r():o("Cannot read bigWig file"):r(s.join(""))}))}))}},5727:(t,e)=>{e.default=(t,e)=>{if(!t.codingstart)return;const n="+"==t.strand?t.codingstart:t.codingstop;let r=t.exon.findIndex((t=>t[1]>=n&&t[0]<=n));if(-1==r)throw"start codon not matched to an exon: "+JSON.stringify(t);"-"==t.strand&&(r=t.exon.length-r-1);const o=e.split(",")[r];if("-1"==o)throw"start codon frame is -1: "+t.isoform;if("0"!=o){if("1"!=o&&"2"!=o)throw"start codon frame not 0/1/2: "+o+" "+t.isoform;t.startCodonFrame=Number.parseInt(o)}}},1883:(t,e,n)=>{const r=n(1017),o=n(7147).promises,i=n(334),s=n(9191).validate_termdb;e.server_updateAttr=function(t,e){if(e.updateAttr&&!t.label){for(const n of e.updateAttr){let e=t;for(const t of n)if(e)if("object"==typeof t)for(const n in t)e[n]=t[n];else e=e[t]}t.label&&delete e.updateAttr}},e.setDbRefreshRoute=function(t,e,n){var a,l;if(null===(a=t.cohort)||void 0===a||null===(l=a.db)||void 0===l||!l.refresh)return;const c=t.cohort.db.refresh;delete t.cohort.db.refresh,e.get(`${n}/${c.route}`,(async(e,n)=>{n.send({label:t.label,files:[]})})),e.post(`${n}/${c.route}`,(async(e,n)=>{try{var a,l;const c=null!==(a=t.cohort.db)&&void 0!==a&&null!==(l=a.file)&&void 0!==l&&l.startsWith(i.tpmasterdir)?t.cohort.db.file:r.join(i.tpmasterdir,t.cohort.db.file||""),u=e.body;if(!u.dbfile)throw"Updating input text files via the termdb-refresh page has been deprecated.Please use the buildTermdb.bundle.js. pipeline before triggering this route to replace the db file.";{const e=r.join(i.tpmasterdir,u.dbfile);if(!await o.stat(e))throw`dbfile not found: '${e}'`;const n=t.cohort.db.file_fullpath||c;if(e===n)throw"db file source and target are the same";console.log(`copying ${e} to ${n}`),await o.copyFile(e,n)}await s(t),n.send({status:"ok"})}catch(t){console.log(t),n.send({error:t.error||t})}}))}},9320:(t,e,n)=>{n(9699);const r=n(7147),o=n(3856),i=n(2081).spawn,s=n(1017),a=n(334),l=a.fimo||"fimo";async function c(t,e,n){const c=s.join(a.cachedir,Math.random().toString());return await o.write_file(c,n),new Promise(((n,o)=>{const s=["--parse-genomic-coord","--verbosity",1,"--text"];t.fimo_thresh&&(s.push("--thresh"),s.push(t.fimo_thresh)),s.push(e.fimo_motif.db),s.push(c);const a=i(l,s),u=[];a.stdout.on("data",(t=>u.push(t))),a.on("close",(o=>{r.unlink(c,(()=>{}));const i=u.join("").trim();i||n([]);const s=[],a=i.split("\n");for(let n=1;n<a.length;n++){const r=a[n].split("\t"),o=r[0].split("_")[0],i=Number.parseInt(r[3]),l=Number.parseInt(r[4]);if(i>t.m.pos||l<t.m.pos+1)continue;const c=Number.parseFloat(r[7]),u={start:i,stop:l,strand:r[5],name:o,pvalue:c,score:Number.parseFloat(r[6]),logpvalue:-Math.log10(c)};e.fimo_motif.tf2attr&&(u.attr=e.fimo_motif.tf2attr[u.name]),s.push(u)}n(s)}))}))}e.handle_closure=t=>async(e,n)=>{try{const r=e.query;if(!r.m)throw"no mutation";if(!r.m.chr)throw"mutation chr missing";if(!Number.isInteger(r.m.pos))throw"mutation position is not integer";if(!r.m.ref)throw"mutation ref allele missing";if(!r.m.alt)throw"mutation alt allele missing";const i=t[r.genome];if(!i)throw"invalid genome";if(!i.fimo_motif)throw"motif finding not supported on this genome";const s=await async function(t,e){const n=t.m.pos-t.flankspan,r=t.m.pos+t.flankspan,i=await o.get_fasta(e,t.m.chr+":"+n+"-"+r);!function(t,e,n){if(!t.m.ref)return;if("-"==t.m.ref)return;const r=n.split("\n").slice(1).join("").toUpperCase(),o=r.substring(t.m.pos-e,t.m.pos-e+t.m.ref.length);if(o==t.m.ref.toUpperCase())return;if(common.reversecompliment(o)==t.m.ref.toUpperCase())t.m.ref=o,"-"!=t.m.alt&&(t.m.alt=common.reversecompliment(t.m.alt))}(t,n,i);const s=await c(t,e,i),a=new Map;for(const t of s)t.pvalue_ref=t.pvalue,delete t.pvalue,t.logpvalue_ref=t.logpvalue,delete t.logpvalue,a.has(t.name)||a.set(t.name,[]),a.get(t.name).push(t);const l=function(t,e,n,r){const o=r.split("\n"),i=o.slice(1).join("");return o[0]+"\n"+i.substr(0,t.pos-e)+("-"==t.alt?"":t.alt)+i.substr(t.pos-e+("-"==t.ref?0:t.ref.length))}(t.m,n,0,i),u=await c(t,e,l);for(const t of u){t.pvalue_alt=t.pvalue,delete t.pvalue,t.logpvalue_alt=t.logpvalue,delete t.logpvalue,a.has(t.name)||a.set(t.name,[]);let e=!0;for(const n of a.get(t.name))if(null!=n.logpvalue_ref&&n.strand==t.strand&&Math.abs(t.start-n.start)<=2&&Math.abs(t.stop-n.stop)<=2){n.pvalue_alt=t.pvalue_alt,n.logpvalue_alt=t.logpvalue_alt,n.logpvaluediff=t.logpvalue_alt-n.logpvalue_ref,n.logpvaluediff>0?n.gain=!0:n.loss=!0,e=!1;break}e&&a.get(t.name).push(t)}let f=0,d=0;const h=[];for(const e of a.values())for(const n of e)null==n.logpvaluediff&&(null==n.pvalue_ref?(n.gain=!0,n.logpvaluediff=n.logpvalue_alt):null==n.pvalue_alt&&(n.loss=!0,n.logpvaluediff=-n.logpvalue_ref)),null!=t.minabslogp&&Math.abs(n.logpvaluediff)<t.minabslogp||(n.logpvaluediff>0?f=Math.max(f,n.logpvaluediff):d=Math.min(d,n.logpvaluediff),h.push(n));return{items:h,valuemin:d,valuemax:f,refstart:n,refstop:r,refseq:i.split("\n").slice(1).join("")}}(r,i);n.send(s)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},4065:(t,e,n)=>{"use strict";function r(t){return(e,n)=>{try{const r=t[e.query.genome];if(!r)throw"invalid genome name";n.send(o(r,e.query))}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}function o(t,e){if(t.genomicNameRegexp.test(e.input))throw"invalid character in gene name";if(e.deep){const n={};let r;{const n=t.genedb.getnamebynameorisoform.get(e.input,e.input);n&&(r=n.name)}if(!r&&t.genedb.getNameByAlias){const n=t.genedb.getNameByAlias.get(e.input);n&&(r=n.name)}if(!r&&t.genedb.get_gene2canonicalisoform&&e.input.toUpperCase().startsWith("ENSG")){const o=t.genedb.get_gene2canonicalisoform.get(e.input);if(o&&o.isoform){const e=o.isoform;n.found_isoform=e;const i=t.genedb.getnamebynameorisoform.get(e,e);if(!i)throw"cannot map enst isoform to symbol";r=i.name}}r||(r=e.input);const o=t.genedb.getjsonbyname.all(r);return n.gmlst=o.map((t=>{const e=JSON.parse(t.genemodel);return t.isdefault&&(e.isdefault=!0),e})),n}const n=e.input.toUpperCase(),r=(n.substr(0,2),t.genedb.getnameslike.all(n+"%"));if(r.length)return r.sort(),{hits:r.map((t=>t.name))};if(t.genedb.getNameByAlias){const e=t.genedb.getNameByAlias.all(n);if(e.length)return{hits:e.map((t=>t.name))}}{const n=t.genedb.getnamebynameorisoform.get(e.input,e.input);if(n)return{hits:[n.name]}}return{hits:[]}}n.r(e),n.d(e,{getResult:()=>o,handle_genelookup_closure:()=>r})},2084:(t,e,n)=>{"use strict";n.r(e),n.d(e,{handle_healthcheck_closure:()=>l});const r=n(334),o=n(7147),i=n(1017),s=n(2081),a=n(6464).promisify(s.exec);function l(t){const e=i.join(process.cwd(),"./rev.txt");let n="";return o.existsSync(e)&&(n=o.readFileSync(e,{encoding:"utf8"})),async(e,o)=>{try{o.send(await async function(t,e){const n={status:"ok",rev:e},o=r.features.healthcheck_keys||[];if(o.includes("w")){const{stdout:t,stderr:e}=await a("w | head -n1");if(e)throw e;n.w=t.toString().trim().split(" ").slice(-3).map((t=>t.endsWith(",")?+t.slice(0,-1):+t))}if(o.includes("rs")){const{stdout:t,stderr:e}=await a("ps aux | grep rsync -w");if(e)throw e;n.rs=t.toString().trim().split("\n").length-1}n.rev||(n.rev=r.rev);r.commitHash&&(n.commitHash=r.commitHash);r.version&&(n.version=r.version);for(const e in t){n[e]={};const r=t[e];if(r.genedb&&(n[e].genedb={buildDate:r.genedb.get_buildDate?r.genedb.get_buildDate.get().date:"unknown",tables:r.genedb.tableSize}),r.termdbs){n[e].termdbs={};for(const t in r.termdbs){const o=r.termdbs[t];n[e].termdbs[t]={buildDate:o.cohort.termdb.q.get_buildDate?o.cohort.termdb.q.get_buildDate.get().date:"unknown"}}}}return n}(t,n))}catch(t){o.send({error:t.message||t})}}}},8405:(t,e,n)=>{"use strict";n.d(e,{v:()=>s});const r=n(7147),o=n(6464),i=n(6452);async function s(t,e){const n={},s=e?await async function(t,e,n){try{const r=await i(t,{headers:{Range:"bytes="+e+"-"+(n-1)}}).buffer();return r.buffer.slice(e,e+n)}catch(t){throw console.log(t.response),"error reading file, check file details"}}(t,0,32e3):await async function(t,e,n){const i=o.promisify(r.open),s=o.promisify(r.read),a=Buffer.alloc(n),l=await i(t,"r"),c=await s(l,a,0,n,e);r.close(l,(function(t){return t}));const u=c.buffer;return u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength)}(t,0,32e3),a=new DataView(s);let l=0;if("HIC"!==_())throw Error("Unsupported hic file");const c=w();if(8!==c)throw Error("Unsupported hic version: "+c);n["Hic Version"]=c,l+=8;const u=_();n["Genome ID"]=u;let f={};const d=w();let h=0;for(;h!==d;)f[_()]=_(),h++;n.Chromosomes={},n.chrorder=[];let p=w(),m=0;for(;m!==p;){const t=_();n.chrorder.push(t),n.Chromosomes[t]=w(),m++}n["Base pair-delimited resolutions"]=[];let g=w(),y=0;for(;y!==g;)n["Base pair-delimited resolutions"].push(w()),y++;n["Fragment-delimited resolutions"]=[];let v=w(),b=0;for(;b!==v;)n["Fragment-delimited resolutions"].push(w()),b++;return JSON.stringify(n);function _(){let t,e="";for(;0!=(t=a.getUint8(l++));)e+=String.fromCharCode(t);return e}function w(){const t=a.getInt32(l,!0);return l+=4,t}}},4695:(t,e,n)=>{const r=n(9699),o=n(3856),i=n(7147),s=n(4521);function a(t){return new Promise(((e,n)=>{const r=s.createInterface({input:i.createReadStream(t.file,{encoding:"utf8"})}),o=[];let a=!0;r.on("line",(e=>{if(a)return void(a=!1);const n=e.split("\t"),[i,s,l,c,u,f]=n[0].split(/[:,]/);if(i!=t.chr)return;const d=Number.parseInt(s),h=Number.parseInt(u);if(Number.isNaN(d)||Number.isNaN(h))return;const p=d-1,m=h-1;if(p>t.start&&p<t.stop||m>t.start&&m<t.stop){const t=Number.parseInt(n[1]),e=n[2];o.push({chr:i,start:p,stop:m,type:e,rawdata:[t]})}else p>t.stop&&r.close()})),r.on("close",(()=>{e(o)}))}))}t.exports=async(t,e)=>{try{const[n,s,l]=r.fileurl(t);if(n)throw n;if(!t.query.rglst)throw"rglst[] missing";if("string"==typeof t.query.rglst&&(t.query.rglst=JSON.parse(t.query.rglst)),!Array.isArray(t.query.rglst))throw"rglst[] not an array";if(t.query.rglst.reduce(((t,e)=>e.stop-e.start+t),0)>1e6)throw"Zoom in below 1 Mb to show junctions";let c;if(t.query.isrnapeg){if(!r.features.junctionrnapeg)throw"rnapeg not supported on this server";if(l)throw"rnapeg file from url is not supported";c=await async function(t,e){try{await i.promises.stat(e)}catch(t){if("EACCES"==t.code)throw"permission denied for rnapeg file";if("ENOENT"==t.code)throw"rnapeg file not found";throw"cannot access rnapeg file ("+t.code+")"}const n=[];for(const r of t.rglst){const t=await a({file:e,chr:r.chr,start:r.start,stop:r.stop});for(const e of t)n.push(e)}return n}(t.query,s)}else{const e=l?await o.cache_index(s,t.query.indexURL):null;c=await async function(t,e,n){const r=[];for(const i of t.rglst)await o.get_lines_bigfile({args:[e,i.chr+":"+i.start+"-"+i.stop],dir:n,callback:t=>{const e=t.split("\t"),n=Number.parseInt(e[1]),o=Number.parseInt(e[2]);if(n>=i.start&&n<=i.stop||o>=i.start&&o<=i.stop){const t={chr:i.chr,start:n,stop:o,type:e[4],rawdata:[]};for(let n=5;n<e.length;n++)t.rawdata.push(Number.parseInt(e[n]));r.push(t)}}});return r}(t.query,s,e)}e.send({lst:c})}catch(t){t.stack&&console.log(t.stack),e.send({error:t.message||t})}}},6979:(t,e,n)=>{n(7147);const r=n(1017),o=(n(2081).spawn,n(4521),n(9699),n(3856)),i=n(2273),s=n(334),a=n(6819),l=n(9157);async function c(t){const e=["futime\tfustat\trx"];for(const[n,r]of t.entries())for(const t of r.lst)e.push(t.serialtime+"\t"+t.censored+"\t"+n);const n=await l(r.join(s.binpath,"/utils/km.R"),e);return Number(n.join(""))}async function u(t,e,n,r){const o=new Set(t.map((t=>t.name))),s=e.samplerule.set;let a,l;for(const t in n.queries){const e=n.queries[t];e.type==i.tkt.mdsvcf?a=e:e.type==i.tkt.mdssvcnv&&(l=e)}const c=new Set;if(s.cnv||s.loh||s.sv||s.fusion||s.itd){if(!l)throw"no svcnv found in ds.queries";if(r)return await f(l,o,e,!0);const t=await f(l,o,e);for(const e of t)c.add(e)}if(s.snvindel){if(!a)throw"no vcf found in ds.queries";for(const t of a.tracks)await d(a,t,o,c,e)}return t.filter((t=>c.has(t.name)))}async function f(t,e,n,a){const l=n.samplerule.set,c=t.url?await o.cache_index(t.url,t.indexURL):null,u=new Set,f=new Set,d=new Set;return await o.get_lines_bigfile({args:[t.file?r.join(s.tpmasterdir,t.file):t.url,(t.nochr?l.chr.replace("chr",""):l.chr)+":"+l.start+"-"+(l.stop+1)],dir:c,callback:t=>{const n=t.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),s=JSON.parse(n[3]);if(e.has(s.sample)){if(s.dt==i.dtcnv){if(!l.cnv)return;if(l.cnv.focalsizelimit&&o-r>=l.cnv.focalsizelimit)return;if(l.cnv.valuecutoff&&Math.abs(s.value)<l.cnv.valuecutoff)return;return a?s.value>0?u.add(s.sample):f.add(s.sample):d.add(s.sample),void l.samples_cnv.add(s.sample)}if(s.dt==i.dtloh){if(!l.loh)return;if(l.loh.focalsizelimit&&o-r>=l.loh.focalsizelimit)return;if(l.loh.valuecutoff&&s.segmean<l.loh.valuecutoff)return;return d.add(s.sample),void l.samples_loh.add(s.sample)}if(s.dt==i.dtsv){if(!l.sv)return;return d.add(s.sample),void l.samples_sv.add(s.sample)}if(s.dt==i.dtfusionrna){if(!l.fusion)return;return d.add(s.sample),void l.samples_fusion.add(s.sample)}if(s.dt==i.dtitd){if(!l.itd)return;return d.add(s.sample),void l.samples_itd.add(s.sample)}}}}),a?[u,f]:d}async function d(t,e,n,l,c){const u=c.samplerule.set,f=e.url?await o.cache_index(e.url,e.indexURL):null;await o.get_lines_bigfile({args:[e.file?r.join(s.tpmasterdir,e.file):e.url,(e.nochr?u.chr.replace("chr",""):u.chr)+":"+u.start+"-"+(u.stop+1)],dir:f,callback:r=>{if(e.type==i.mdsvcftype.vcf){const[o,s,c]=a.vcfparseline(r,{nochr:e.nochr,samples:e.samples,info:t.info,format:e.format});for(const t of s)if(t.sampledata&&!(u.snvindel.ref&&(t.ref!=u.snvindel.ref||t.alt!=u.snvindel.alt)||u.snvindel.hiddenclass&&(i.vcfcopymclass(t,{}),u.snvindel.hiddenclass[t.class])))for(const e of t.sampledata)n.has(e.sampleobj.name)&&(l.add(e.sampleobj.name),u.samples_snvindel.add(e.sampleobj.name))}}})}async function h(t,e,n){if(!n.queries)throw".queries{} missing from ds";let i;for(const t in n.queries)n.queries[t].isgenenumeric&&(i=n.queries[t]);if(!i)throw"no gene numeric query from ds";const a=i.url?await o.cache_index(i.url,i.indexURL):null,l=e.samplerule.set,c=new Map;await o.get_lines_bigfile({args:[i.file?r.join(s.tpmasterdir,i.file):i.url,l.chr+":"+l.start+"-"+l.stop],dir:a,callback:t=>{const e=JSON.parse(t.split("\t")[3]);e.sample&&Number.isFinite(e.value)&&e.gene==l.gene&&c.set(e.sample,e.value)}});const u=[];for(const e of t)c.has(e.name)&&(e.genevalue=c.get(e.name),u.push(e));return u.sort(((t,e)=>t.genevalue-e.genevalue)),[i,u]}function p(t){t.lst.sort(((t,e)=>t.serialtime-e.serialtime));let e=t.lst.length,n=[],r=0;t.steps=[];for(const o of t.lst){if(0==o.censored){n.push(o.serialtime);continue}const i=1*(1-r)/(e-n.length);t.steps.push({x:o.serialtime,y:r,drop:i,censored:n}),r+=i,e-=n.length+1,n=[]}n.length>0&&t.steps.push({x:t.lst[t.lst.length-1].serialtime,y:r,drop:0,censored:n})}e.u=t=>async(e,n)=>{try{const r=e.query,o=t[r.genome];if(!o)throw"invalid genome";const i=o.datasets[r.dslabel];if(!i)throw"invalid dataset";if(!i.cohort)throw"no cohort for dataset";if(!i.cohort.annotation)throw"cohort.annotation missing for dataset";const s=i.cohort.survivalplot;if(!s)throw"survivalplot not supported for this dataset";if(!s.plots)throw".plots{} missing";if(e.query.init)return void n.send(s.init);if(!r.type)throw".type missing";const a=s.plots[r.type];if(!a)throw"unknown plot type: "+r.type;const l=function(t,e,n){if(!t.samplerule)throw".samplerule missing";if(!t.samplerule.full)throw".samplerule.full missing";const r=[];if(t.samplerule.full.byattr){const n=t.samplerule.full.key;if(!n)throw"key missing from samplerule.full{}";const o=t.samplerule.full.value;if(null==o)throw"value missing from samplerule.full{}";for(const t in e.cohort.annotation){const i=e.cohort.annotation[t];i[n]==o&&r.push({name:t,o:i})}}else if(t.samplerule.full.useall)for(const t in e.cohort.annotation){const n=e.cohort.annotation[t];r.push({name:t,o:n})}else{if(!t.samplerule.full.usesampleset)throw"unknown rule for samplerule.full";{const n=t.samplerule.full.sampleset;for(const t in n){const o=n[t],i=e.cohort.annotation[o];null!=i&&r.push({name:o,o:i})}}}const o=[];for(const t of r)Number.isFinite(t.o[n.serialtimekey])&&(t.serialtime=t.o[n.serialtimekey],t.censored=t.o[n.iscensoredkey],o.push(t));if(0==o.length)throw"no samples found for full set";return o}(r,i,a),f=await async function(t,e,n,r){if(e.samplerule.mutated_sets){const n=new Set(t.map((t=>t.name))),r=e.samplerule.mutated_sets.reduce(((e,r)=>{const o=new Set(r.samplenames);r.lst=t.filter((t=>o.has(t.name)));for(const t of r.samplenames)n.delete(t);return delete r.samplenames,e.push(r),e}),[]);return r.push({name:"No mutation (n="+n.size+")",lst:t.filter((t=>n.has(t.name))),is_notmutated:!0}),r}const o=e.samplerule.set;if(!o)return[{name:"All",lst:t}];if(o.geneexpression){if(!o.gene)throw".gene missing from samplerule.set";if(!o.chr)throw".chr missing from samplerule.set";if(!Number.isInteger(o.start))throw".start not integer from samplerule.set";if(!Number.isInteger(o.stop))throw".start not integer from samplerule.set";if(o.bymedian)return await async function(t,e,n,r){const o=e.samplerule.set,[i,s]=await h(t,e,n),a=Math.ceil(s.length/2),l=s[a-1].genevalue;return[{name:o.gene+" "+i.datatype+" below median (n="+a+", value<"+l+")",lst:s.slice(0,a)},{name:o.gene+" "+i.datatype+" above median (n="+(s.length-a)+", value>="+l+")",lst:s.slice(a,s.length)}]}(t,e,n);if(o.byquartile)return await async function(t,e,n,r){const o=e.samplerule.set,[i,s]=await h(t,e,n),a=Math.ceil(.25*s.length),l=Math.ceil(.5*s.length),c=Math.ceil(.75*s.length),u=s[a-1].genevalue,f=s[l-1].genevalue,d=s[c-1].genevalue;return[{name:o.gene+" "+i.datatype+" from 1st quartile (n="+a+", value<"+u+")",lst:s.slice(0,a),isfirstquartile:!0},{name:o.gene+" "+i.datatype+" from 2nd quartile (n="+(l-a)+", "+u+"<=value<"+f+")",lst:s.slice(a,l)},{name:o.gene+" "+i.datatype+" from 3rd quartile (n="+(c-l)+", "+f+"<=value<"+d+")",lst:s.slice(l,c)},{name:o.gene+" "+i.datatype+" from 4th quartile (n="+(s.length-c)+", value>="+d+")",lst:s.slice(c,s.length),isfourthquartile:!0}]}(t,e,n)}if(o.mutation){if(!o.chr)throw".chr missing from samplerule.set";if(!Number.isInteger(o.start))throw".start not integer from samplerule.set";if(!Number.isInteger(o.stop))throw".start not integer from samplerule.set";return await async function(t,e,n){const r=e.samplerule.set;if(r.samples_snvindel=new Set,r.samples_cnv=new Set,r.samples_loh=new Set,r.samples_sv=new Set,r.samples_fusion=new Set,r.samples_itd=new Set,r.cnv&&!r.snvindel&&!r.loh&&!r.sv&&!r.fusion&&!r.itd){const[r,o]=await u(t,e,n,!0),i=[],s=[],a=[];for(const e of t)r.has(e.name)?i.push(e):o.has(e.name)?s.push(e):a.push(e);const l=[];return s.length&&l.push({name:"Copy number loss (n="+s.length+")",lst:s}),i.length&&l.push({name:"Copy number gain (n="+i.length+")",lst:i}),a.length&&l.push({name:"No copy number variation (n="+a.length+")",lst:a}),l}const o=await u(t,e,n),i=[];for(const e of t)o.find((t=>t.name==e.name))||i.push(e);const s=[];o.length&&s.push({name:"With mutation (n="+o.length+")",lst:o});i.length&&s.push({name:"No mutation (n="+i.length+")",lst:i});return s}(t,e,n)}throw"unknown rule for samplerule.set{}"}(l,r,i);let d;f.length>1&&(d=await c(f)),await async function(t,e){if(!t.samplerule.mutated_sets)return;const n=e.find((t=>t.is_notmutated));if(!n)return;for(const t of e){if(t.is_notmutated)continue;const e=await c([t,n]);t.pvalue=e}}(r,f),await async function(t,e){if(!t.samplerule.set)return;if(!t.samplerule.set.geneexpression)return;if(!t.samplerule.set.byquartile)return;if(4!=e.length)return;if(t.samplerule.set.against1st){for(let t=1;t<4;t++)e[t].pvalue=await c([e[0],e[t]]);return}if(t.samplerule.set.against4th){for(let t=0;t<3;t++)e[t].pvalue=await c([e[t],e[3]]);return}}(r,f);for(const t of f)p(t),delete t.lst;const m={samplesets:f,pvalue:d};r.samplerule.set&&r.samplerule.set.mutation&&(m.count_snvindel=r.samplerule.set.samples_snvindel.size,m.count_cnv=r.samplerule.set.samples_cnv.size,m.count_loh=r.samplerule.set.samples_loh.size,m.count_sv=r.samplerule.set.samples_sv.size,m.count_fusion=r.samplerule.set.samples_fusion.size,m.count_itd=r.samplerule.set.samples_itd.size),n.send(m)}catch(t){t.stack&&console.error(t.stack),n.send({error:t.message||t})}}},9211:(t,e,n)=>{"use strict";n.d(e,{e:()=>s});const r=n(9699),o=(n(7147),n(1017),n(2081).spawn,n(3856)),i=n(6718).createCanvas;n(2273).bplen;function s(t){return async(e,n)=>{try{const i=t[e.query.genome];if(!i)throw"unknown genome";n.send(await async function(t,e){const[n,i,s]=r.fileurl(t);if(n)throw n;let l;s&&(l=await o.cache_index(i,t.query.indexURL));if(!t.query.rglst)throw"rglst missing";const c=await o.tabix_is_nochr(i,l,e),u=t.query.connheight||50,f={rglst:[]};for(const e of t.query.rglst){const n={chr:e.chr,start:e.start,stop:e.stop,width:e.width,reverse:e.reverse,xoff:e.xoff};f.rglst.push(n);const r=[],s=new Set,d=(c?e.chr.replace("chr",""):e.chr)+":"+e.start+"-"+e.stop;await o.get_lines_bigfile({args:[i,d],dir:l,callback:t=>{const n=t.split("\t"),o=Number.parseInt(n[1]);if(o<e.start)return;const i=Number.parseInt(n[2]);if(i>e.stop)return;const a=Number.parseFloat(n[5]);r.push({start:o,stop:i,r2:a}),s.add(o),s.add(i)}}),n.img=a(e,r,s,u,t.query.devicePixelRatio||1)}return f}(e,i))}catch(t){n.send({error:t.message||t})}}}function a(t,e,n,r,o){const[s,a]=function(t,e){let n=t.width/e.size,r=0;n>40&&(n=40,r=(t.width-n*e.size)/2);const o=new Map,i=t.reverse?[...e].sort(((t,e)=>e-t)):[...e].sort(((t,e)=>t-e));let s=r;for(const t of i)o.set(t,s+n/2),s+=n;return[n,o]}(t,n),l=new Map;{const e=(t.stop-t.start)/t.width;for(const r of n)t.reverse?l.set(r,(t.stop-r)/e):l.set(r,(r-t.start)/e)}let c=0;for(const t of e)c=Math.max(c,(a.get(t.stop)-a.get(t.start))/2);const u=r+c+s/2,f=i(t.width*o,u*o),d=f.getContext("2d");o>1&&d.scale(o,o),d.strokeStyle="black";for(const t of n)d.beginPath(),d.moveTo(l.get(t),0),d.lineTo(a.get(t),r),d.closePath(),d.stroke();for(const t of e){const e=a.get(t.start),n=a.get(t.stop),o=(e+n)/2,i=r+Math.abs(n-e)/2,l=Math.floor(255*(1-t.r2));d.fillStyle="rgb(255,"+l+","+l+")",d.beginPath(),d.moveTo(o,i-s/2),d.lineTo(o-s/2,i),d.lineTo(o,i+s/2),d.lineTo(o+s/2,i),d.lineTo(o,i-s/2),d.closePath(),d.fill()}return{height:u,src:f.toDataURL()}}},9157:(t,e,n)=>{n(1017);const r=n(7147),o=n(2081).spawn,i=n(2781).Readable,s=n(334);t.exports=async function(t,e,n=[]){try{await r.promises.stat(t)}catch(e){throw`${t} does not exist`}const a=[],l=[];return new Promise(((r,c)=>{const u=o(s.Rscript,[t,...n]);if(e&&e.length>0)try{const t=e.join("\n")+"\n";i.from(t).pipe(u.stdin)}catch(t){u.kill();let e=t;l.length>0&&(e+=`\nR stderr: ${l.join("").trim()}`),c(e)}u.stdout.on("data",(t=>a.push(t))),u.stderr.on("data",(t=>l.push(t))),u.on("error",(t=>c(t))),u.on("close",(t=>{if(0!==t){let e=`R process exited with non-zero status code=${t}`;a.length>0&&(e+=`\nR stdout: ${a.join("").trim()}`),l.length>0&&(e+=`\nR stderr: ${l.join("").trim()}`),c(e)}if(l.length>0){const t=l.join("").trim();c(`R process emitted standard error\nR stderr: ${t}`)}const e=a.join("").trim().split("\n");r(e)}))}))}},8025:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get:()=>l,save:()=>a});const r=n(334),o=n(1017),i=n(7147),s=n(3856);async function a(t,e){try{const n=function(){const t=[];for(;t.length<15;){const e=46+Math.floor(80*Math.random());(e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122)&&t.push(String.fromCharCode(e))}return t.join("")}(),i=JSON.stringify(t.body);await s.write_file(o.join(r.cachedir_massSession,n),i),e.send({id:n})}catch(t){e.send({error:t.message||t})}}async function l(t,e){try{if(!t.query.id)throw"session id missing";const n=o.join(r.cachedir_massSession,t.query.id);let a;try{a=(await i.promises.stat(n)).birthtime}catch(t){throw"invalid session"}const l=await s.read_file(n),c=new Date,u=new Date(a),f=r.features.massSessionDuration||30,d=f-Math.round((c.getTime()-u.getTime())/864e5);e.send({state:JSON.parse(l),sessionDaysLeft:d,massSessionDuration:f})}catch(t){e.send({error:t.message||t})}}},1185:(t,e,n)=>{"use strict";n.d(e,{Z:()=>a});const r=n(9699),o=n(3856),i=n(334),s=n(1017),a=t=>async(e,n)=>{try{const[a,l,c,u]=function(t,e){if(!e.query.gene)throw"gene name missing";if(!e.query.chr)throw"chr missing";if(!Number.isInteger(e.query.start))throw"start missing";if(!Number.isInteger(e.query.stop))throw"stop missing";const n=t[e.query.genome];if(!n)throw"invalid genome";let r,o,i;if(e.query.iscustom){if(!e.query.file&&!e.query.url)throw"no file or url for expression data";r={},o={file:e.query.file,url:e.query.url,indexURL:e.query.indexURL}}else{if(!n.datasets)throw"genome is not equipped with datasets";if(!e.query.dslabel)throw"dslabel missing";if(r=n.datasets[e.query.dslabel],!r)throw"invalid dslabel";if(!r.queries)throw"dataset is not equipped with queries";if(!e.query.querykey)throw"querykey missing";if(o=r.queries[e.query.querykey],!o)throw"invalid querykey"}if(e.query.svcnv)if(i={},e.query.iscustom)i.dsquery={file:e.query.svcnv.file,url:e.query.svcnv.url,indexURL:e.query.svcnv.indexURL};else{e.query.svcnv.genome=e.query.genome;const t=n.datasets[e.query.svcnv.dslabel];if(!t)throw"invalid dslabel";if(!t.queries)throw"dataset is not equipped with queries";if(!e.query.svcnv.querykey)throw"querykey missing";const r=t.queries[e.query.svcnv.querykey];if(!r)throw"invalid querykey";i.ds=t,i.dsquery=r}if(e.query.getgroup)if(e.query.sampleset);else{if(!r.cohort||!r.cohort.annotation)throw"no sample annotation for getting group";if(e.query.getgroup_unannotated){if(!o.boxplotbysamplegroup)throw"dsquery.boxplotbysamplegroup{} missing when getgroup_unannotated"}else{if(!Array.isArray(e.query.getgroup))throw"getgroup should be array";for(const t of e.query.getgroup){if(!t.k)throw"k missing from one of getgroup";if(!t.kvalue)throw"kvalue missing from one of getgroup"}}}return[n,r,o,i]}(t,e);e.query.getalllst,n.send(await async function(t,e,n,a,l){n.url&&(n.dir=await o.cache_index(n.url,n.indexURL));a&&a.dsquery.url&&(a.dsquery.dir=await o.cache_index(a.dsquery.url,a.dsquery.indexURL));const c=function(t){if(!t.query.sampleset)return;const e=new Map;for(const n of t.query.sampleset)for(const t of n.samples)e.set(t,n.name);return e}(l),u=new Map,f=[],d=[];if(await o.get_lines_bigfile({args:[n.file?s.join(i.tpmasterdir,n.file):n.url,l.query.chr+":"+l.query.start+"-"+l.query.stop],dir:n.dir,callback:t=>{const r=t.split("\t"),o=JSON.parse(r[3]);if(o.gene&&o.gene==l.query.gene&&Number.isFinite(o.value))if(l.query.getalllst)f.push({sample:o.sample,value:o.value});else if(l.query.getgroup){if(!o.sample)return;if(c)return void(l.query.getgroup_unannotated?c.has(o.sample)||d.push(o):c.get(o.sample)==l.query.getgroup[0].full&&d.push(o));const t=e.cohort.annotation[o.sample];if(l.query.getgroup_unannotated){if(!t)return void d.push(o);for(const e of n.boxplotbysamplegroup.attributes)if(null==t[e.k])return void d.push(o);return}if(!t)return;for(const e of l.query.getgroup)if(e.kvalue!=t[e.k])return;d.push(o)}else if(n.boxplotbysamplegroup&&e.cohort&&e.cohort.annotation){if(!o.sample)return;let t;t=null==l.query.index_boxplotgroupers||0==l.query.index_boxplotgroupers?n.boxplotbysamplegroup.attributes:n.boxplotbysamplegroup.additionals[l.query.index_boxplotgroupers-1].attributes;const r=e.cohort.annotation[o.sample];if(!r)return void f.push({sample:o.sample,value:o.value});const i=r[t[0].k];if(null==i)return void f.push({sample:o.sample,value:o.value});const s=[];for(let e=1;e<t.length;e++){const n=r[t[e].k];if(null==n)break;s.push(n)}s.unshift(i);const a=s.join(", ");if(!u.has(a)){const e={samples:[],attributes:[]};for(const n of t){const t=r[n.k];if(null==t)break;const o={k:n.k,kvalue:t};n.full&&(o.full=n.full,o.fullvalue=r[n.full]),e.attributes.push(o)}u.set(a,e)}u.get(a).samples.push({sample:o.sample,value:o.value})}else if(c){if(!o.sample)return;const t=c.get(o.sample);if(!t)return void f.push({sample:o.sample,value:o.value});u.has(t)||u.set(t,{samples:[],attributes:[{full:t}]}),u.get(t).samples.push({sample:o.sample,value:o.value})}else f.push({sample:o.sample,value:o.value})}}),l.query.getgroup2boxplot){d.sort(((t,e)=>t.value-e.value));const{w1:t,w2:e,p25:n,p50:o,p75:i,out:s}=r.boxplot_getvalue(d);return{n:d.length,min:d[0].value,max:d[d.length-1].value,w1:t,w2:e,p25:n,p50:o,p75:i,out:s}}const h=[];for(const[t,e]of u)h.push({name:t,values:e.samples,attributes:e.attributes});f.length&&h.push({name:"Unannotated",values:f});d.length&&h.push({values:d});if(l.query.getalllst)return{lst:h[0].values};if(l.query.iscustom&&!c||1==h.length){if(h[0]){const t=h[0].values;return t.sort(((t,e)=>e.value-t.value)),{lst:t,max:t[0].value,min:t[t.length-1].value}}return{nodata:1}}const p=await async function(t,e){if(!e||!t.query.svcnv.useloss&&!t.query.svcnv.usegain&&!t.query.svcnv.usesv)return;let n=t.query.start,r=t.query.stop;t.query.svcnv.usesv&&Number.isInteger(t.query.svcnv.svflank)&&(n=Math.max(0,n-t.query.svcnv.svflank),r+=t.query.svcnv.svflank);const a=new Map;return await o.get_lines_bigfile({args:[e.dsquery.file?s.join(i.tpmasterdir,e.dsquery.file):e.dsquery.url,t.query.chr+":"+n+"-"+r],dir:e.dsquery.dir,callback:e=>{const n=e.split("\t"),r=JSON.parse(n[3]);if(r.sample)if(r.chrA||r.chrB){if(!t.query.svcnv.usesv)return;a.has(r.sample)||a.set(r.sample,{}),a.get(r.sample).sv=1}else{if(!t.query.svcnv.usegain&&!t.query.svcnv.useloss)return;if(t.query.svcnv.usesv&&t.query.svcnv.svflank){const e=Number.parseInt(n[1]),r=Number.parseInt(n[2]);if(Math.max(t.query.start,e)>Math.min(t.query.stop,r))return}if(!Number.isFinite(r.value))return;if(!t.query.svcnv.usegain&&r.value>0)return;if(!t.query.svcnv.useloss&&r.value<0)return;if(t.query.svcnv.valueCutoff&&Math.abs(r.value)<t.query.svcnv.valueCutoff)return;if(t.query.svcnv.bplengthUpperLimit&&Number.parseInt(n[2])-Number.parseInt(n[1])>t.query.svcnv.bplengthUpperLimit)return;a.has(r.sample)||a.set(r.sample,{}),r.value>0?a.get(r.sample).gain=1:r.value<0&&(a.get(r.sample).loss=1)}}}),a}(l,a);if(l.query.getgroup){if(h[0]){const t=h[0].values;if(t.sort(((t,e)=>e.value-t.value)),p)for(const e of t){const t=p.get(e.sample);if(t)for(const n in t)e[n]=t[n]}return{lst:t,max:t[0].value,min:t[t.length-1].value}}return{nodata:1}}const m=[];let g=null,y=null;for(const t of h){t.values.sort(((t,e)=>t.value-e.value));const e=t.values.length;null==g?(g=t.values[0].value,y=t.values[e-1].value):(g=Math.min(g,t.values[0].value),y=Math.max(y,t.values[e-1].value));const{w1:n,w2:o,p25:i,p50:s,p75:a,out:c}=r.boxplot_getvalue(t.values),u=[{isall:1,w1:n,w2:o,p25:i,p50:s,p75:a,out:c}];if(p){if(l.query.svcnv.usegain){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).gain));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({iscnvgain:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}if(l.query.svcnv.useloss){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).loss));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({iscnvloss:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}if(l.query.svcnv.usesv){const e=t.values.filter((t=>p.has(t.sample)&&p.get(t.sample).sv));if(e.length){const{w1:t,w2:n,p25:o,p50:i,p75:s,out:a}=r.boxplot_getvalue(e);u.push({issv:1,samplecount:e.length,w1:t,w2:n,p25:o,p50:i,p75:s,out:a})}}}m.push({name:t.name+" ("+t.values.length+")",boxplots:u,attributes:t.attributes})}return m.sort(((t,e)=>t.name<e.name?-1:t.name>e.name?1:0)),{groups:m,min:g,max:y}}(0,l,c,u,e))}catch(t){t.stack&&console.log(t),n.send({error:t.message||t})}}},9574:(t,e,n)=>{n(9699);const r=n(334),o=n(3856),i=n(1017),s="Unannotated";function a(t){return t.file?t.file:t.file2?t.file2:t.url}function l(t,e,n,r){const o=[];for(const i of t.samples)if(Number.isFinite(i.readcount)&&(i.readcount=Math.floor(i.readcount),!(i.readcount<=0||e.readcountCutoff&&i.readcount<e.readcountCutoff))){if(r.samples&&n.cohort&&n.cohort.annotation){const t=r.samples[i.i];if(!t)continue;const o=n.cohort.annotation[t];if(i.anno=o,e.cohortOnlyAttr&&n.cohort&&n.cohort.annotation){if(!o)continue;let t=!1;for(const n in e.cohortOnlyAttr){const r=o[n];if(r&&e.cohortOnlyAttr[n][r]){t=!0;break}}if(!t)continue}if(e.cohortHiddenAttr&&n.cohort&&n.cohort.annotation&&n.cohort.attributes){if(!o)continue;let t=!1;for(const r in e.cohortHiddenAttr){n.cohort.attributes.lst.find((t=>t.key==r)).isNumeric;const i=o[r];if(i){if(e.cohortHiddenAttr[r][i]){t=!0;break}}else if(e.cohortHiddenAttr[r][s]){t=!0;break}}if(t)continue}}if(i.events&&e.spliceEventPercentage){let n=!1;for(const r in i.events){if(!t.events[r])continue;const o=t.events[r].attrValue,s=e.spliceEventPercentage[o];if(!s)continue;const a=i.events[r].percentage;if(null!=a)if(">"==s.side){if(a<=s.value){n=!0;break}}else if(a>=s.value){n=!0;break}}if(n)continue}o.push(i)}return o}function c(t,...e){if(0==t.length)return 0;const n=t.sort(((t,e)=>t.readcount-e.readcount)),r=[];return e.forEach((t=>{!Number.isFinite(t)||t<0||t>1?r.push(null):r.push(n[Math.floor(n.length*t)].readcount)})),r}t.exports=t=>async(e,n)=>{try{const[u,f,d]=await async function(t,e){const n=t.query;if(!n.genome)throw"genome missing";const s=e[n.genome];if(!s)throw"invalid genome";let a={},l={};if(n.iscustom)if(l.listsamples=!0,n.url)l.url=n.url,l.dir=await o.cache_index(n.url,n.indexURL);else if(n.file)l.file=i.join(r.tpmasterdir,n.file);else{if(!n.file2)throw"no file or url given";l.file2=i.join(r.tpmasterdir,n.file2)}else{if(!s.datasets)throw"genome is not equipped with datasets";if(!n.dslabel)throw"dslabel missing";if(a=s.datasets[n.dslabel],!a)throw"invalid dslabel";if(!a.queries)throw"dataset is not equipped with queries";if(!n.querykey)throw"querykey missing";if(l=a.queries[n.querykey],!l)throw"invalid querykey"}return[n,a,l]}(e,t),h=await async function(t,e,n){if(t.junction)return await async function(t,e,n){const r=t.junction;if(!r.chr||!Number.isInteger(r.start)||!Number.isInteger(r.stop))throw"incomplete/invalid info about querying junction";let i;if(await o.get_lines_bigfile({args:[a(n),r.chr+":"+r.start+"-"+r.stop],dir:n.dir,callback:o=>{const s=o.split("\t"),a=Number.parseInt(s[1]),c=Number.parseInt(s[2]);if(a==r.start&&c==r.stop)if(n.file2){i=[];for(let t=5;t<s.length;t++){const e=s[t];if(!e)continue;const n=Number.parseInt(e);Number.isNaN(n)||(n<=0||i.push({i:t-5,readcount:n}))}}else{const r=JSON.parse(s[5]);i=l(r,t,e,n)}}}),0==i.length)throw"no sample passing filters";const s={};if(n.listsamples){const t=i.map((t=>{const e={readcount:t.readcount};return t.anno?e.sample_name=t.anno.sample_name:e.i=t.i,e}));t.sort(((t,e)=>e.readcount-t.readcount)),t.length>100?(s.samples=t.slice(0,100),s.sampletotalnumber=t.length):s.samples=t}else if(n.singlejunctionsummary&&n.singlejunctionsummary.readcountboxplotpercohort){s.readcountboxplotpercohort=[];for(const t of n.singlejunctionsummary.readcountboxplotpercohort.groups){const e=new Map;for(const n of i){if(!n.anno)continue;const r=n.anno[t.key];null!=r&&(e.has(r)||e.set(r,[]),e.get(r).push(n))}if(0==e.size)continue;const n=[...e].sort(((t,e)=>e[1].length-t[1].length)),r=[];for(const[t,e]of n){let n=e[0].readcount,o=n;e.forEach((t=>{n=Math.min(n,t.readcount),o=Math.max(o,t.readcount)}));const i=c(e,.05,.25,.5,.75,.95);r.push({label:t,samplecount:e.length,percentile:{p05:i[0],p25:i[1],p50:i[2],p75:i[3],p95:i[4]},minvalue:n,maxvalue:o})}s.readcountboxplotpercohort.push({label:t.label,boxplots:r})}}return s}(t,e,n);if(t.readcountByjBsamples)return await async function(t,e,n){if(!t.junctionAposlst)throw".junctionAposlst[] missing";let r,i=t.junctionB.start,s=t.junctionB.stop;t.junctionAposlst.forEach((t=>{i=Math.min(i,t[0]),s=Math.max(s,t[1])}));let a=[];if(await o.get_lines_bigfile({args:[n.file||n.url,t.junctionB.chr+":"+i+"-"+s],dir:n.dir,callback:e=>{const n=e.split("\t"),o=Number.parseInt(n[1]),i=Number.parseInt(n[2]);if(o==t.junctionB.start&&i==t.junctionB.stop)r=JSON.parse(n[5]);else for(const[e,r]of t.junctionAposlst)if(e==o&&r==i){const t=JSON.parse(n[5]);t.start=o,t.stop=i,a.push(t);break}}}),!r)throw"jB not found";if(0==a.length)throw"none of jA is found";const u=l(r,t,e,n);if(0==u.length)throw"no sample passing filters for junctionB";const f=new Set;u.forEach((t=>f.add(t.i)));const d=[];for(const e of a){const n=[];for(const r of e.samples)f.has(r.i)&&(t.readcountCutoff&&r.readcount<t.readcountCutoff||n.push(r));d.push({start:e.start,stop:e.stop,v:Math.floor(c(n,.5))})}return{lst:d}}(t,e,n);const r={};if(t.iscustom&&t.getsamples){const t=await o.get_header_tabix(a(n),n.dir);if(t[0]){const e=t[0].split("\t");e.length>5&&(r.sample2client=e.slice(5))}}if(!t.rglst)throw"rglst missing";if(n.viewrangeupperlimit){if(t.rglst.reduce(((t,e)=>t+e.stop-e.start),0)>=n.viewrangeupperlimit)throw"zoom in under "+common.bplen(n.viewrangeupperlimit)+" to view details"}let i=0,u=0;const f=[],d=new Set,h=new Set;for(const r of t.rglst)await o.get_lines_bigfile({args:[a(n),r.chr+":"+r.start+"-"+r.stop],dir:n.dir,callback:o=>{const a=o.split("\t"),p=Number.parseInt(a[1]),m=Number.parseInt(a[2]);if(n.file2){a[3];const e=a[4];let n;if("known"==e)n="canonical";else{if("novel"!=e)throw"unknown rnapeg type: "+e;n=s}if(t.infoFilter&&t.infoFilter.type&&t.infoFilter.type[n])return;const o={chr:r.chr,start:p,stop:m,info:{type:{lst:[{attrValue:n}]}}},l=[];for(let t=5;t<a.length;t++){const e=a[t];if(!e)continue;const n=Number.parseInt(e);Number.isNaN(n)||(n<=0||(l.push({readcount:n}),i=Math.max(i,n)))}if(0==l.length)return;if(u++,o.sampleCount=l.length,1==o.sampleCount)o.medianReadCount=l[0].readcount;else{const t=c(l,.05,.25,.5,.75,.95);o.medianReadCount=t[2],o.readcountBoxplot={percentile:t}}f.push(o)}else{a[3],a[4];if(!(p>=r.start&&p<=r.stop||m>=r.start&&m<=r.stop))return;u++;const o={chr:r.chr,start:p,stop:m,info:{type:{lst:[]}}},g=JSON.parse(a[5]);if(g.sv){o.sv=g.sv;const t=o.chr+"."+o.start+"."+o.sv.mate.chr+"."+o.sv.mate.start;if(d.has(t))return;d.add(t),d.add(o.sv.mate.chr+"."+o.sv.mate.start+"."+o.chr+"."+o.start)}if(g.canonical&&o.info.type.lst.push({attrValue:"canonical"}),g.events)for(const t in g.events){const e=g.events[t];e.__ek=t,o.info.type.lst.push(e)}else g.canonical||o.info.type.lst.push({attrValue:s});if(t.infoFilter&&t.infoFilter.type)for(const e of o.info.type.lst)if(t.infoFilter.type[e.attrValue])return;const y=l(g,t,e,n);if(0==y.length)return;if((g.exonleft||g.exonright||g.exonleftin||g.exonrightin||g.intronleft||g.intronright||g.leftout||g.rightout)&&(o.ongene={},g.exonleft&&(o.ongene.exonleft=g.exonleft),g.exonright&&(o.ongene.exonright=g.exonright),g.exonleftin&&(o.ongene.exonleftin=g.exonleftin),g.exonrightin&&(o.ongene.exonrightin=g.exonrightin),g.intronleft&&(o.ongene.intronleft=g.intronleft),g.intronright&&(o.ongene.intronright=g.intronright),g.leftout&&(o.ongene.leftout=g.leftout),g.rightout&&(o.ongene.rightout=g.rightout)),y.forEach((t=>{h.add(t.i),i=Math.max(i,t.readcount)})),o.sampleCount=y.length,1==o.sampleCount)o.medianReadCount=y[0].readcount;else{const t=c(y,.05,.25,.5,.75,.95);o.medianReadCount=t[2],o.readcountBoxplot={percentile:t}}f.push(o)}}});r.lst=f,r.maxreadcount=i,r.junctiontotalnumber=u,h.size;return r}(u,f,d);n.send(h)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}},2728:(t,e,n)=>{"use strict";n.r(e),n.d(e,{client_copy:()=>d,init_db:()=>u,init_track:()=>f});n(9699);const r=n(1017),o=(n(7147).promises,n(2081).spawn,n(3856)),i=n(394).server_init_db_queries,s=n(2235).r,a=n(334),{setDbRefreshRoute:l}=n(1883),c="Ancestry_PC_";async function u(t,e=null,s=null){var c,u;if(!t.cohort.termdb)throw"cohort.termdb missing when cohort.db is used";await async function(t){if(t.phewas){if(t.phewas.samplefilter4termtype&&t.phewas.samplefilter4termtype.condition&&!t.phewas.samplefilter4termtype.condition.filter)throw"filter{} missing from tdb.phewas.samplefilter4termtype.condition";if(t.phewas.comparison_groups){if(!Array.isArray(t.phewas.comparison_groups))throw"tdb.phewas.comparison_groups is not array";if(0==t.phewas.comparison_groups.length)throw"tdb.phewas.comparison_groups[] cannot be empty"}}if(t.selectCohort){if(!t.selectCohort.term)throw"term{} missing from termdb.selectCohort";if(!t.selectCohort.term.id)throw"id missing from termdb.selectCohort.term";if("string"!=typeof t.selectCohort.term.id)throw"termdb.selectCohort.term.id is not string";if("categorical"!=t.selectCohort.term.type)throw'type is not hardcoded "categorical" from termdb.selectCohort.term';if(!t.selectCohort.values)throw"values[] missing from termdb.selectCohort";if(!Array.isArray(t.selectCohort.values))throw"termdb.selectCohort.values is not array";if(0==t.selectCohort.values.length)throw"termdb.selectCohort.values[] cannot be empty";for(const e of t.selectCohort.values){if(!e.keys)throw"keys[] missing from one of selectCohort.values[]";if(!Array.isArray(e.keys))throw"keys[] is not array from one of selectCohort.values[]";if(0==e.keys.length)throw"keys[] is empty from one of selectCohort.values[]"}}if(t.restrictAncestries){if(!Array.isArray(t.restrictAncestries)||0==t.restrictAncestries.length)throw"termdb.restrictAncestries[] is not non-empty array";for(const e of t.restrictAncestries){if(!e.name)throw"name missing from one of restrictAncestries";if("object"!=typeof e.tvs)throw".tvs{} missing from one of restrictAncestries";if(!Number.isInteger(e.PCcount))throw"PCcount is not integer";if(e.PCfile)e.pcs=await h(e.PCfile,e.PCcount);else if(e.PCfileBySubcohort)for(const t in e.PCfileBySubcohort){const n=e.PCfileBySubcohort[t];if(!n.file)throw".file missing for a subcohort in PCfileBySubcohort";n.pcs=await h(n.file,e.PCcount)}}}}(t.cohort.termdb),await async function(t){if("scatterplots"in t)for(const e of t.scatterplots.plots){const t=r.join(a.tpmasterdir,e.file);await o.file_is_readable(t)}}(t.cohort),i(t),function(t){t.sampleName2Id=new Map,t.sampleId2Name=new Map;const e="SELECT * FROM sampleidmap",n=t.cohort.db.connection.prepare(e).all();for(const e of n)t.sampleId2Name.set(e.id,e.name),t.sampleName2Id.set(e.name,e.id);t.getSampleIdMap=e=>{const n={};for(const r in e)n[r]=t.sampleId2Name.get(+r);return n}}(t);const{mayGetGeneVariantData:f,getTermTypes:d,mayGetMatchingGeneNames:p}=n(7833);t.mayGetGeneVariantData=f,t.getTermTypes=d,t.mayGetMatchingGeneNames=p,null!==(c=t.cohort)&&void 0!==c&&null!==(u=c.db)&&void 0!==u&&u.refresh&&e&&l(t,e,s)}async function f(t,e){if(!t.track)throw"no mds2 track; missing ds.track{}";const n=t.track;n.name||(n.name=t.label),function(t){if(!t.populations)return;if(!Array.isArray(t.populations))throw"populations should be array";for(const e of t.populations){if(!e.key)throw"key missing from a population";if(e.label||(e.label=e.key),!Array.isArray(e.sets))throw".sets is not an array in population: "+e.key;for(const t of e.sets){if(!t.infokey_AC)throw"infokey_AC missing from a set of population: "+e.key;if(!t.infokey_AN)throw"infokey_AN missing from a set of population: "+e.key;if(e.termfilter&&!t.termfilter_value)throw"termfilter_value missing from a set of population where termfilter is set: "+e.key}}}(n),await async function(t,e,n){if(!t)return;if(!t.chr2bcffile)throw"vcftk.chr2bcffile is missing";{if("object"!=typeof t.chr2bcffile)throw"chr2bcffile not an object";for(const e in t.chr2bcffile)t.chr2bcffile[e]=r.join(a.tpmasterdir,t.chr2bcffile[e]);const n={file:t.chr2bcffile[e.defaultcoord.chr]};if(!n.file)throw"default chr missing from chr2bcffile";await o.init_one_vcf(n,e,!0),t.info=n.info,t.format=n.format,t.samples=n.samples,t.nochr=n.nochr}if(t.AD&&t.AD.chr2bcffile){if("object"!=typeof t.AD.chr2bcffile)throw"AD.chr2bcffile not an object";for(const e in t.AD.chr2bcffile)t.AD.chr2bcffile[e]=r.join(a.tpmasterdir,t.AD.chr2bcffile[e]);const i={file:t.AD.chr2bcffile[e.defaultcoord.chr]};if(!i.file)throw"default chr missing from AD.chr2bcffile";await o.init_one_vcf(i,e,!0),t.AD.info=i.info,t.AD.format=i.format,t.AD.samples=i.samples,t.AD.nochr=i.nochr,console.log(n.label+" vcf: AD: "+t.AD.samples.length+" samples");for(const e of t.AD.samples){const t=Number(e.name);if(!Number.isInteger(t))throw"non-integer vcf sample: "+e.name;e.name=t}}if(t.samples){for(const e of t.samples){const t=Number(e.name);if(!Number.isInteger(t))throw"non-integer vcf sample: "+e.name;e.name=t}console.log(n.label+" vcf: "+t.samples.length+" samples")}else console.log(n.label+" vcf: no samples");if(t.numerical_axis&&t.numerical_axis.info_keys){if(!Array.isArray(t.numerical_axis.info_keys))throw"numerical_axis.info_keys should be an array";for(const e of t.numerical_axis.info_keys){const n=t.info[e.key];if(!n)throw'INFO field "'+e.key+'" not found for numerical_axis';if("Float"!=n.Type&&"Integer"!=n.Type)throw'INFO field "'+e.key+'" from numerical_axis not of integer or float type';if("1"!=n.Number&&"A"!=n.Number)throw'for numerical axis, INFO field "'+e.key+'" only allows to be Number=1 or Number=A'}}if(t.plot_mafcov){if(!t.AD)throw".plot_mafcov enabled but .AD{} missing from vcf";if(!t.AD.samples)throw".plot_mafcov enabled but no samples from vcf";if(!t.AD.format)throw".plot_mafcov enabled but no FORMAT fields from vcf";if(!t.AD.format.AD)throw".plot_mafcov enabled but the AD FORMAT field is missing";if("R"!=t.AD.format.AD.Number)throw"AD FORMAT field Number=R is not true";if("Integer"!=t.AD.format.AD.Type)throw"AD FORMAT field Type=Integer is not true";if(t.plot_mafcov.overlay_term){if(!n.cohort)throw"ds.cohort missing when plot_mafcov.overlay_term defined";if(!n.cohort.termdb)throw"ds.cohort.termdb missing when plot_mafcov.overlay_term defined";if(!n.cohort.termdb.q)throw"ERR: termdb.q{} missing while trying to access termdb helper functions";if(!n.cohort.termdb.q.termjsonByOneid)throw"ERR: q.termjsonByOneid missing";const e=n.cohort.termdb.q.termjsonByOneid(t.plot_mafcov.overlay_term);if(!e)throw'unknown term id "'+t.plot_mafcov.overlay_term+'" from vcftk.plot_mafcov.overlay_term';t.plot_mafcov.overlay_term=e}}if(t.termdb_bygenotype){if(!t.samples)throw".termdb_bygenotype enabled but no samples from vcf";if(!t.format)throw".termdb_bygenotype enabled but no FORMAT fields from vcf";if(!t.format.GT)throw".termdb_bygenotype enabled but the GT FORMAT field is missing";if(!n.cohort)throw"termdb_bygenotype but ds.cohort missing";if(!n.cohort.termdb)throw"termdb_bygenotype but ds.cohort.termdb missing";if(t.termdb_bygenotype.getAF){if(!t.termdb_bygenotype.termid_sex)throw"termid_sex missing for getAF at termdb_bygenotype";if(!t.termdb_bygenotype.value_male)throw"value_male missing for getAF at termdb_bygenotype";const e=n.cohort.termdb.q.getSample2value(t.termdb_bygenotype.termid_sex);t.termdb_bygenotype.male_samples=new Set;for(const n of e)n.value==t.termdb_bygenotype.value_male&&t.termdb_bygenotype.male_samples.add(n.sample);if(!t.termdb_bygenotype.sex_chrs)throw"sex_chrs missing for getAF at termdb_bygenotype";if(!Array.isArray(t.termdb_bygenotype.sex_chrs))throw"sex_chrs is not array";t.termdb_bygenotype.sex_chrs=new Set(t.termdb_bygenotype.sex_chrs)}}if(t.samples){t.sample2arrayidx=new Map;for(const[e,n]of t.samples.entries())t.sample2arrayidx.set(n.name,e)}}(n.vcf,e,t),function(t){if(!t.info_fields)return;if(!Array.isArray(t.info_fields))throw"tk.info_fields is not array";for(const e of t.info_fields){if(!e.key)throw".key missing from one of tk.info_fields[]";if(t.vcf&&t.vcf.info&&!t.vcf.info[e.key])throw`info field ${e.key} missing from tk.vcf.info{}`;if(e.label||(e.label=e.key),e.iscategorical){if(!Array.isArray(e.values))throw".values[] not an array of categorical INFO field: "+e.key;for(const t of e.values){if(!t.key)throw"key missing from a value of categorical INFO: "+e.key;t.label||(t.label=t.key)}}else if(e.isfloat||e.isinteger){if(!e.range)throw".range{} missing from a numerical INFO: "+e.key;s(e.range,"tk.info_fields[]")}else if(!e.isflag)throw"tk.info_fields unknown type: "+e.key}}(n),await async function(t,e,n){if(!t)return;if(!Array.isArray(t.tracks))throw"ld.tracks[] not an array";if(0==t.tracks.length)throw"ld.tracks[] is empty array";for(const n of t.tracks){if(!n.name)throw".name missing from a ld track";if(!Number.isInteger(n.viewrangelimit))throw'viewrangelimit missing from ld track "'+n.name+'"';if(n.file)n.file.startsWith(a.tpmasterdir)||(n.file=r.join(a.tpmasterdir,n.file)),await o.validate_tabixfile(n.file),n.nochr=await o.tabix_is_nochr(n.file,null,e),console.log(n.file+": "+(n.nochr?"no chr":"has chr"));else if(!n.chr2file)throw"ld tk has no file or chr2file"}}(n.ld,e),await async function(t,e){if(!t)return}(n.svcnv,0),function(t){const e=new Set;if(t.vcf&&t.vcf.samples)for(const n of t.vcf.samples)e.add(n.name);t.svcnv;e.size&&(t.samples=[...e])}(n),n.samples&&console.log(t.label+": mds2: "+n.samples.length+" samples")}function d(t){const e=t.track,n={name:e.name,info_fields:e.info_fields,sample_termfilter:e.sample_termfilter};return e.vcf&&(n.vcf={numerical_axis:e.vcf.numerical_axis,format:e.vcf.format,info:e.vcf.info,check_pecanpie:e.vcf.check_pecanpie},e.vcf.plot_mafcov&&(n.vcf.plot_mafcov={},t.cohort&&t.cohort.termdb&&(n.vcf.plot_mafcov.overlay_term=e.vcf.plot_mafcov.overlay_term||{})),e.vcf.termdb_bygenotype&&(n.vcf.termdb_bygenotype=!0),e.populations&&(n.populations=e.populations)),e.ld&&(n.ld={tracks:e.ld.tracks.map((t=>({name:t.name,shown:t.shown}))),overlay:e.ld.overlay}),n}async function h(t,e){const n=new Map;for(let t=1;t<=e;t++)n.set(c+t,new Map);let i=0;for(const s of(await o.read_file(r.join(a.tpmasterdir,t))).trim().split("\n")){i++;const t=s.split("\t"),r=Number(t[0]);if(!Number.isInteger(r))throw"non-integer sample id from a line of restrictAncestries pc file";for(let o=1;o<=e;o++){const e=c+o,i=Number(t[o]);if(Number.isNaN(i))throw"non-numeric PC value from restrictAncestries file";n.get(e).set(r,i)}}return console.log(i,"samples loaded from "+t),Object.freeze(n)}},7510:(t,e,n)=>{n(9699),n(7147),n(1017);const r=n(3856),o=(n(2273),n(6280)),i=n(6234),s=n(2581);e.handle_request=t=>async(e,n)=>{const a=e.query;try{const e=t[a.genome],l=await async function(t,e){if(!e)throw"invalid genome";if(t.dslabel){const n=e.datasets[t.dslabel];if(!n)throw"invalid dslabel";if(!n.track)throw"no mds2 track found for dataset";return n}const n={iscustom:1,track:{}};t.vcf&&(n.track.vcf=t.vcf,await r.init_one_vcf(n.track.vcf,e));t.ld;return n}(a,e);if(a.trigger_overlayld)return await s.overlay(a,l,n);a.hidden_mclass&&(a.hidden_mclass=new Set(a.hidden_mclass));const c={mclass2count:{}};if(a.info_fields){c.info_fields={};for(const t of a.info_fields)if(t.iscategorical)c.info_fields[t.key]={value2count:{}};else if(t.isnumerical)c.info_fields[t.key]={filteredcount:0};else{if(!t.isflag)throw"unknown info type";c.info_fields[t.key]={count_yes:0,count_no:0}}}if(a.trigger_mafcovplot&&await i.plot(a,e,l,c),a.trigger_vcfbyrange&&(await o.handle_vcfbyrange(a,e,l,c),a.trigger_ld)){c.__mposset=new Set;for(const t of c.vcf.rglst)if(t.variants)for(const e of t.variants)c.__mposset.add(e.pos)}if(a.trigger_ld){c.ld={};for(const t of a.trigger_ld.tracks)await s.load_tk(t,a,e,l,c);delete c.__mposset}a.trigger_ssid_onevcfm&&await o.handle_ssidbyonem(a,e,l,c),a.trigger_getvcfcsq&&await o.handle_getcsq(a,e,l,c),n.send(c)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},2581:(t,e,n)=>{"use strict";n.r(e),n.d(e,{load_tk:()=>s,overlay:()=>l});n(7147),n(1017),n(2081).spawn;const r=n(3856),o=n(6718).createCanvas,i=n(2273).bplen;async function s(t,e,n,o,s){const l=o.track.ld.tracks.find((e=>e.name==t.name));if(!l)throw"ld track not found by name: "+t.name;if(!e.rglst)throw"rglst missing";s.ld[l.name]={rglst:[]};const c=e.trigger_ld.connheight||50;for(const t of e.rglst){const e={chr:t.chr,start:t.start,stop:t.stop,width:t.width,reverse:t.reverse,xoff:t.xoff};if(s.ld[l.name].rglst.push(e),t.stop-t.start>=l.viewrangelimit){e.rangetoobig="Zoom in under "+i(l.viewrangelimit)+" to view LD data";continue}const n=[],o=new Set,u=(l.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop;await r.get_lines_bigfile({args:[l.file,u],dir:l.dir,callback:e=>{const r=e.split("\t"),i=Number.parseInt(r[1]);if(i<t.start)return;const a=Number.parseInt(r[2]);if(a>t.stop)return;if(s.__mposset){if(!s.__mposset.has(i))return;if(!s.__mposset.has(a))return}const l=Number.parseFloat(r[5]);n.push({start:i,stop:a,r2:l}),o.add(i),o.add(a)}}),e.img=a(t,n,o,c)}}function a(t,e,n,r){const[i,s]=function(t,e){let n=t.width/e.size,r=0;n>40&&(n=40,r=(t.width-n*e.size)/2);const o=new Map,i=t.reverse?[...e].sort(((t,e)=>e-t)):[...e].sort(((t,e)=>t-e));let s=r;for(const t of i)o.set(t,s+n/2),s+=n;return[n,o]}(t,n),a=new Map;{const e=(t.stop-t.start)/t.width;for(const r of n)t.reverse?a.set(r,(t.stop-r)/e):a.set(r,(r-t.start)/e)}let l=0;for(const t of e)l=Math.max(l,(s.get(t.stop)-s.get(t.start))/2);const c=r+l+i/2,u=o(t.width,c),f=u.getContext("2d");f.strokeStyle="black";for(const t of n)f.beginPath(),f.moveTo(a.get(t),0),f.lineTo(s.get(t),r),f.closePath(),f.stroke();for(const t of e){const e=s.get(t.start),n=s.get(t.stop),o=(e+n)/2,a=r+Math.abs(n-e)/2,l=Math.floor(255*(1-t.r2));f.fillStyle="rgb(255,"+l+","+l+")",f.beginPath(),f.moveTo(o,a-i/2),f.lineTo(o-i/2,a),f.lineTo(o,a+i/2),f.lineTo(o+i/2,a),f.lineTo(o,a-i/2),f.closePath(),f.fill()}return{height:c,src:u.toDataURL()}}async function l(t,e,n){if(!t.ldtkname)throw".ldtkname missing";const o=e.track.ld.tracks.find((e=>e.name==t.ldtkname));if(!o)throw"ld tk not found by name: "+t.ldtkname;const i=t.m.ref+"."+t.m.alt,s=(o.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+t.m.pos+"-"+(t.m.pos+1),a=[];await r.get_lines_bigfile({args:[o.file,s],dir:o.dir,callback:e=>{const n=e.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),s=n[3],l=n[4],c=Number.parseFloat(n[5]);r==t.m.pos&&s==i?a.push({pos:o,alleles:l,r2:c}):o==t.m.pos&&l==i&&a.push({pos:r,alleles:s,r2:c})}}),n.send({lst:a})}},6280:(t,e,n)=>{"use strict";n.r(e),n.d(e,{handle_getcsq:()=>p,handle_ssidbyonem:()=>f,handle_vcfbyrange:()=>d});n(7147);const r=n(1017),o=(n(2081).spawn,n(3856)),i=n(6819),s=n(2273),a=n(2852),l=n(9157),c=n(334),u="%CHROM\t%POS\t%ID\t%REF\t%ALT\t%QUAL\t%FILTER\t%INFO";async function f(t,e,n,s){if(n.iscustom)throw"custom ds not allowed";const a=n.track.vcf;if(!a)throw"ds.track.vcf missing";if(!t.m)throw"q.m missing";const l=(a.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),f=a.chr2bcffile[t.m.chr];if(!f)throw"chr not in chr2bcffile";let d;if(await o.get_lines_bigfile({isbcf:!0,args:["query",f,"-r",l,"-f",u+"\t%FORMAT\n"],dir:a.dir,callback:e=>{const[n,r,o]=i.vcfparseline(e,a);for(const e of r)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(d=e)}}),!d)throw"variant not found";const h=[],p=[],m=[];for(const e of d.sampledata){if(!e.genotype)continue;const n=-1!=e.genotype.indexOf(t.m.ref),r=-1!=e.genotype.indexOf(t.m.alt);n?r?p.push(e.sampleobj.name):h.push(e.sampleobj.name):r&&m.push(e.sampleobj.name)}const g=Math.random().toString();s.ssid=g,s.groups={};const y=[];if(h.length){const t="Homozygous reference";s.groups[t]={size:h.length},y.push(t+"\t"+h.join(","))}if(p.length){const t="Heterozygous";s.groups[t]={size:p.length},y.push(t+"\t"+p.join(","))}if(m.length){const t="Homozygous alternative";s.groups[t]={size:m.length},y.push(t+"\t"+m.join(","))}await o.write_file(r.join(c.cachedir_ssid,g),y.join("\n"))}async function d(t,e,n,f){if(!t.rglst)throw".rglst[] missing";const d=n.track.vcf;if(!d)throw"ds.track.vcf missing";const p={info:d.info,format:d.format,samples:d.samples};await async function(t,e,n){if(t.querymode={},t.AFtest){if(n.iscustom)throw"custom track does not support AFtest";for(const e of t.AFtest.groups)if(!e.is_infofield)if(e.is_termdb)e.columnidx=await h(e.filter,n);else{if(!e.is_population)throw"Cannot set query mode: unknown group type";{if(!n.track.populations)throw"ds.track.populations missing";const r=n.track.populations.find((t=>t.key==e.key));if(!r)throw"unknown population key: "+e.key;if(e.population=JSON.parse(JSON.stringify(r)),t.AFtest.termfilter&&t.AFtest.termfilter[0].term.id==e.population.termfilter){const n=e.population.sets.find((e=>e.termfilter_value==t.AFtest.termfilter[0].values[0].key));if(!n)throw"no matching set found for a termfilter from a population";e.population.sets=[n]}}}if(t.AFtest.testby_fisher&&t.AFtest.groups.find((t=>t.is_infofield)))throw"cannot do fisher test for an INFO field";{const e=t.AFtest.groups.find((t=>t.is_population));if(e&&e.adjust_race){const r=t.AFtest.groups.find((t=>t.is_termdb));if(!r)throw"cannot adjust race: termdb group missing";r.pop2average=await async function(t,e,n,r){const o=new Map;let i=0;for(const e of t){const t={infokey_AC:e.infokey_AC,infokey_AN:e.infokey_AN,average:0},r=await a.get_rows_by_one_key({ds:n,key:e.key});for(const e of r){if(!n.track.vcf.sample2arrayidx.has(e.sample))continue;const r=Number(e.value);Number.isFinite(r)&&(t.average+=r,i+=r)}o.set(e.key,t)}for(const[t,e]of o)e.average/=i;return o}(e.population.sets,r.columnidx,n)}}return void(t.querymode.range_AFtest=!0)}t.querymode.range_variantonly=!0}(t,0,n),function(t,e){if(e.querymode.range_variantonly||e.querymode.range_AFtest){delete t.samples;for(const t of e.rglst)t.variants=[]}e.bcfformat=u,e.exportgenotype||e.querymode.range_AFtest?e.bcfformat+="\t%FORMAT\n":e.querymode.range_variantonly&&(e.querymode.slicecolumnindex||(e.bcfformat+="\\n"))}(p,t),t.exportgenotype&&(f.mlst=[]),function(t,e){const n=(r=t.rglst[0],r.usegm_isoform?{gmmode:"protein",usegm:{isoform:r.usegm_isoform}}:{});var r;t.m_is_filtered=r=>{let o=!1;if(t.info_fields)for(const n of t.info_fields){const t=e.info_fields[n.key];let i;if(r.info&&(i=r.info[n.key]),null==i&&r.altinfo&&(i=r.altinfo[n.key]),n.iscategorical)null==i?(t.unannotated_count=1+(t.unannotated_count||0),n.unannotated_ishidden&&(o=!0)):(t.value2count[i]=1+(t.value2count[i]||0),n.hiddenvalues[i]&&(o=!0));else if(n.isnumerical)null==i&&null!=n.missing_value&&(i=n.missing_value),n.range.startunbounded||(n.range.startinclusive?i<n.range.start&&(o=!0):i<=n.range.start&&(o=!0)),n.range.stopunbounded||(n.range.stopinclusive?i>n.range.stop&&(o=!0):i>=n.range.stop&&(o=!0)),o&&t.filteredcount++;else{if(!n.isflag)throw"unknown info type";i?t.count_yes++:t.count_no++,(n.remove_yes&&i||n.remove_no&&!i)&&(o=!0)}}return!!o||(s.vcfcopymclass(r,n),e.mclass2count[r.class]=(e.mclass2count[r.class]||0)+1,t.hidden_mclass&&t.hidden_mclass.has(r.class)&&(o=!0),o)}}(t,f);for(const e of t.rglst){if(d.viewrangeupperlimit&&e.stop-e.start>=d.viewrangeupperlimit){e.rangetoobig="Zoom in under "+s.bplen(d.viewrangeupperlimit)+" to view VCF data";continue}const n=(d.nochr?e.chr.replace("chr",""):e.chr)+":"+e.start+"-"+e.stop,r=d.chr2bcffile[e.chr];if(!r)throw"chr not found in chr2bcffile";await o.get_lines_bigfile({isbcf:!0,args:["query",r,"-r",n,"-f",t.bcfformat],dir:d.dir,callback:y(e)})}function y(e){return n=>{if(t.exportgenotype){const e=n.split("\t"),[r,o,s]=i.vcfparseline(e.slice(0,8).join("\t"),p);for(const n of o){if(t.m_is_filtered(n))continue;const r=[n.chr+"."+(n.pos+1)+"."+n.ref+"."+n.alt,n.name||""];for(let t=9;t<e.length;t++){const o=e[t].split(":",1)[0];if("."==o){r.push(".");continue}const i=o.split(-1==o.indexOf("/")?"|":"/");r.push(("0"==i[0]?n.ref:n.alt)+("0"==i[1]?n.ref:n.alt))}f.mlst.push(r.join("\t"))}return}let r;if(t.querymode.range_variantonly)if(t.querymode.slicecolumnindex);else{const[e,o,s]=i.vcfparseline(n,p);r=[];for(const e of o)t.m_is_filtered(e)||r.push(e)}else t.querymode.range_AFtest&&(r=function(t,e,n,r){const o=t.split("\t"),[s,a,l]=i.vcfparseline(o.slice(0,8).join("\t"),n),c=a.filter((t=>!e.m_is_filtered(t)));if(0==c.length)return;const u=[o[3],...o[4].split(",")],f=[];for(const t of c){const n=g(o,t,u,e);if(m(n)){if(f.push(t),e.AFtest.testby_AFdiff){for(const t of n)if(t.is_infofield)t.v=t.infofieldvalue;else{if(!t.is_termdb&&!t.is_population)throw"unknown group type";t.v=t.altcount/(t.refcount+t.altcount)}t.AFtest_group_values=[n[0].v,n[1].v],t.nm_axis_value=n[0].v-n[1].v}else e.AFtest.testby_fisher&&(t.contigencytable=[n[0].altcount,n[0].refcount,n[1].altcount,n[1].refcount]);{const r=e.AFtest.groups.find((t=>t.is_population));if(r&&r.adjust_race){const e=n.find((t=>t.is_population));t.popsetadjvalue=[];for(const[n,r]of e.set2value)t.popsetadjvalue.push([n,r.ACraw,r.ANraw-r.ACraw,Number.parseInt(r.ACadj),Number.parseInt(r.ANadj-r.ACadj)])}}}}return f}(n,t,p));if(r)for(const t of r)t.csq&&(t.csq_count=t.csq.length,delete t.csq),delete t._m,delete t.vcf_ID,delete t.sampledata,d.nochr&&(t.chr="chr"+t.chr),e.variants.push(t)}}await async function(t){if(!t.querymode.range_AFtest)return;if(!t.AFtest.testby_fisher)return;const e=[],n={};for(const r of t.rglst)if(r.variants)for(const t of r.variants)if(t.contigencytable){const r=t.chr+"."+t.pos+"."+t.ref+"."+t.alt;e.push(r+"\t"+t.contigencytable.join("\t")),n[r]=t}if(0==e.length)return;const o=await l(r.join(c.binpath,"/utils/fisher.R"),e);for(const t of o){const e=t.split("\t"),r=n[e[0]];if(r){const t=Number.parseFloat(e[5]);r.AFtest_pvalue=t,r.nm_axis_value=Number.isNaN(t)?0:-Math.log10(t)}}}(t),function(t,e,n,r){if(e.exportgenotype)return t.exportgenotype="variant\tSNP\t"+n.samples.map((t=>r.cohort.termdb.id2sampleName(t.name))).join("\t")+"\n"+t.mlst.join("\n"),void delete t.mlst;t.vcf={rglst:[]};for(const n of e.rglst){const e={chr:n.chr,start:n.start,stop:n.stop,width:n.width,reverse:n.reverse,xoff:n.xoff};t.vcf.rglst.push(e),n.rangetoobig?(e.rangetoobig=n.rangetoobig,delete n.rangetoobig):n.variants?(e.variants=n.variants,delete n.variants):n.canvas&&(e.img=n.canvas.toDataURL(),delete n.canvas)}if(e.AFtest&&e.AFtest.groups.find((t=>t.is_termdb))){t.AFtest_termdbgroup=[];let n=e.AFtest.groups[0];if(n.is_termdb&&(t.AFtest_termdbgroup[0]={samplecount:n.columnidx.length},n.pop2average)){t.AFtest_termdbgroup[0].popsetaverage=[];for(const[e,r]of n.pop2average)t.AFtest_termdbgroup[0].popsetaverage.push([e,r.average])}if(n=e.AFtest.groups[1],n.is_termdb&&(t.AFtest_termdbgroup[1]={samplecount:n.columnidx.length},n.pop2average)){t.AFtest_termdbgroup[1].popsetaverage=[];for(const[e,r]of n.pop2average)t.AFtest_termdbgroup[1].popsetaverage.push([e,r.average])}}}(f,t,d,n)}async function h(t,e){if(!e.track)throw"ds.track{} missing";return(await a.get_samples(t,e)).reduce(((t,n)=>{const r=e.track.vcf.sample2arrayidx.get(n);return r>=0&&t.push(r),t}),[])}async function p(t,e,n,r){const s=n.track.vcf;if(!s)throw"ds.track.vcf missing";if(!t.m)throw"q.m missing";const a=(s.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),l=s.chr2bcffile[t.m.chr];if(!l)throw"chr not in chr2bcffile";await o.get_lines_bigfile({isbcf:!0,args:["query",l,"-r",a,"-f",u+"\\n"],dir:s.dir,callback:e=>{const[n,o,a]=i.vcfparseline(e,s);for(const e of o)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(r.csq=e.csq)}})}function m(t){if(t.find((t=>t.is_infofield)))return!0;return t[0].altcount+t[1].altcount>0}function g(t,e,n,r){return r.AFtest.groups.reduce(((o,i)=>{if(i.is_infofield)o.push({is_infofield:!0,infofieldvalue:y(e,i)});else if(i.is_termdb){const r=function(t,e,n){let r=!0;const o=new Map;for(const e of t)o.set(e,0);for(const i of n){if(!e[9+i])continue;const n=e[9+i].split(":")[0];"."!=n&&n.split(-1==n.indexOf("/")?"|":"/").forEach((e=>{const n=Number.parseInt(e);if(Number.isNaN(n))return;const i=t[n];i&&(0!=n&&(r=!1),o.set(i,1+o.get(i)))}))}return{allref:r,alleles:o}}(n,t,i.columnidx);o.push({is_termdb:!0,allref:r.allref,refcount:r.alleles.get(e.ref)||0,altcount:r.alleles.get(e.alt)||0})}else{if(!i.is_population)throw"unknown group type";{const t=new Map;for(const n of i.population.sets)t.set(n.key,{ACraw:y(e,{key:n.infokey_AC,missing_value:0}),ANraw:y(e,{key:n.infokey_AN,missing_value:0})});let n=0,s=0;if(i.adjust_race)[n,s]=function(t,e){if(!e)throw"group_termdb missing";if(!e.pop2average)throw"group_termdb.pop2average missing";let n=0;for(const e of t.values())n+=e.ANraw;let r=0,o=0;for(const[i,s]of t)s.ANadj=n*e.pop2average.get(i).average,s.ACadj=0==s.ANadj?0:s.ACraw*s.ANadj/s.ANraw,r+=s.ACadj,o+=s.ANadj;return[o-r,r]}(t,r.AFtest.groups.find((t=>t.is_termdb)));else for(const e of t.values())s+=e.ACraw,n+=e.ANraw-e.ACraw;o.push({is_population:!0,refcount:n,altcount:s,set2value:t})}}return o}),[])}function y(t,e){if(t.info){const n=t.info[e.key];if(null!=n)return n}if(t.altinfo){const n=t.altinfo[e.key];if(null!=n)return n}return e.missing_value}},6234:(t,e,n)=>{"use strict";n.r(e),n.d(e,{plot:()=>c});const r=n(3856),o=n(6819),i=n(502),s=n(2852),a="#aaa",l="%CHROM\t%POS\t%ID\t%REF\t%ALT\t%QUAL\t%FILTER\t%INFO\t%FORMAT\n";async function c(t,e,n,c){try{if(!n.track)throw"ds.track missing";const e=n.track.vcf;if(!e)throw"ds.track.vcf missing";if(n.iscustom)e.plot_mafcov={show_samplename:1};else if(!e.plot_mafcov)throw"maf-cov plot is not supported on this track";if(!t.m)throw".m{} missing";if(!e.AD)throw"vcf.AD{} missing";const u=(e.AD.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+(t.m.pos+1)+"-"+(t.m.pos+1),f=e.AD.chr2bcffile[t.m.chr];if(!f)throw"chr not in tk.AD.chr2bcffile";let d;if(await r.get_lines_bigfile({isbcf:!0,args:["query","-r",u,"-f",l,f],dir:e.AD.dir,callback:n=>{const[r,i,s]=o.vcfparseline(n,e.AD);for(const e of i)if(e.pos==t.m.pos&&e.ref==t.m.ref&&e.alt==t.m.alt)return void(d=e)}}),!d)throw"variant not found";if(c.plotgroups=function(t,e,n){const r=[],o={name:"?",lst:[]};for(const r of t.sampledata){const i=r.AD[t.ref]||0,s=r.AD[t.alt]||0,a=i+s,l={mut:s,total:i+s,maf:0==a?0:s/a};e.plot_mafcov.show_samplename&&(l.sampleobj={name:n.cohort.termdb.q.id2sampleName(r.sampleobj.name)}),o.lst.push(l)}return r.push(o),r}(d,e,n),t.overlay_term){const e=await s.get_rows({ds:n,term1_id:t.overlay_term,term1_q:t.overlay_term_q}),r=new Map;for(const t of e.lst)r.set(t.sample,t.key1);const o=i.scaleOrdinal(i.schemeCategory10),l=new Map;let u=0;for(const t of c.plotgroups)for(const e of t.lst){const t=r.get(e.sampleobj.name);if(t){const n=o(t);e.sampleobj.color=n,l.has(t)||l.set(t,{count:0,color:n,label:t}),l.get(t).count++}else u++,e.sampleobj.color=a}if(c.categories=[],e.CTE1&&e.CTE1.name2bin)for(const t of e.CTE1.name2bin.keys()){const e=l.get(t);e&&c.categories.push(e)}else for(const[t,e]of l)c.categories.push(e);u&&c.categories.push({count:u,color:a,label:"Unannotated"})}}catch(t){c.error=t.message||t,t.stack&&console.log(t.stack)}}},9402:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_densityplot:()=>i});const r=n(502).scaleLinear,{violinBinsObj:o}=n(7011);async function i(t,e){const n=[];let i=null,s=null;for(const r of e.map((e=>e[t.id]))){var a,l;if(null!==(a=t.values)&&void 0!==a&&null!==(l=a[r])&&void 0!==l&&l.uncomputable)continue;const e=Number(r);Number.isFinite(e)&&(n.push(e),null===i?i=s=e:(i=Math.min(i,e),s=Math.max(s,e)))}const c=r().domain([i,s]).range([10,510]),u=o(c,{values:n});if(!Array.isArray(u.bins))throw"violinBins does not return {bins[]}";if(0==u.bins.length)throw"violinBins {bins[]} empty array";const f={minvalue:i,maxvalue:s,densitymax:0,density:[],samplecount:n.length,unit:t.unit};for(const t of u.bins){if(!Number.isFinite(t.x0))throw"b.x0 not number";if(!Number.isFinite(t.x1))throw"b.x1 not number";if(!Number.isFinite(t.binValueCount))throw"b.binValueCount not number";f.density.push([(t.x0+t.x1)/2,t.binValueCount]),f.densitymax=Math.max(f.densitymax,t.binValueCount)}return f}},9432:(t,e)=>{function n(t){const e=t.split(".");return"case"==e[0]&&(e[0]="cases"),e.join(".")}e.P=t=>{const e={op:"and",content:[]};if(!Array.isArray(t.lst))throw"filter.lst[] not array";for(const r of t.lst){if("tvs"!=r.type)throw'filter.lst[] item.type!="tvs"';if(!r.tvs)throw"item.tvs missing";if(!r.tvs.term)throw"item.tvs.term missing";if(r.tvs.values){const t={op:"in",content:{field:n(r.tvs.term.id),value:r.tvs.values.map((t=>t.key))}};e.content.push(t)}else if(r.tvs.ranges)for(const t of r.tvs.ranges)t.startunbounded?e.content.push({op:t.stopinclusive?"<=":"<",content:{field:n(r.tvs.term.id),value:t.stop}}):t.stopunbounded?e.content.push({op:t.startinclusive?">=":">",content:{field:n(r.tvs.term.id),value:t.start}}):e.content.push({op:"and",content:[{op:t.startinclusive?">=":">",content:{field:n(r.tvs.term.id),value:t.start}},{op:t.stopinclusive?"<=":"<",content:{field:n(r.tvs.term.id),value:t.stop}}]})}return e}},5243:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_termlst2size:()=>O,handle_filter2topGenes:()=>F,handle_gdc_ssms:()=>I,querySamples_gdcapi:()=>M,validate_m2csq:()=>E,validate_query_geneCnv:()=>w,validate_query_geneCnv2:()=>x,validate_query_geneExpression:()=>m,validate_query_singleSampleMutation:()=>R,validate_query_snvindel_byisoform:()=>g,validate_query_snvindel_byisoform_2:()=>y,validate_query_snvindel_byrange:()=>p,validate_ssm2canonicalisoform:()=>d,validate_variant2sample:()=>h});var r=n(4048);const o=n(2273),i=n(6452),s=n(1017),{get_crosstabCombinations:a,combineSamplesById:l}=n(817),c=n(9432).P,u=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",f=u+(u.includes("/v0")?"":"/v0")+"/graphql";async function d(t){const e=["consequence.transcript.is_canonical","consequence.transcript.transcript_id"];t.get=async t=>{if(!t.ssm_id)throw".ssm_id missing";const n=await i(u+"/ssms/"+t.ssm_id+"?fields="+e.join(","),{method:"GET",headers:q(t)});let r;try{r=JSON.parse(n.body)}catch(t){throw"invalid json in response"}if(!r.data||!r.data.consequence)throw"returned data not .data.consequence";if(!Array.isArray(r.data.consequence))throw".data.consequence not array";const o=r.data.consequence.find((t=>t.transcript.is_canonical));return o?o.transcript.transcript_id:r.data.consequence[0].transcript.transcript_id}}function h(t){if("function"!=typeof t.filters)throw".variant2samples.gdcapi.filters() not a function"}function p(t){const e=t.queries.snvindel.byrange.gdcapi;if(!e.query)throw".query missing for byrange.gdcapi";if("string"!=typeof e.query)throw".query not string in byrange.gdcapi";if("function"!=typeof e.variables)throw".byrange.gdcapi.variables() not a function";t.queries.snvindel.byrange.get=async n=>{const r=await i.post(f,{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:e.query,variables:e.variables(n)})});let s;try{s=JSON.parse(r.body)}catch(t){throw"invalid JSON from GDC"}if(!(s.data&&s.data.explore&&s.data.explore.ssms&&s.data.explore.ssms.hits&&s.data.explore.ssms.hits.edges))throw"returned structure not data.explore.ssms.hits.edges";if(!Array.isArray(s.data.explore.ssms.hits.edges))throw"data.explore.ssms.hits.edges not array";const a=[];for(const e of s.data.explore.ssms.hits.edges){const r={dt:o.dtsnvindel,ssm_id:e.node.ssm_id,chr:e.node.chromosome,pos:e.node.start_position-1,ref:e.node.reference_allele,alt:e.node.tumor_allele,samples:[]};if(e.node.consequence&&e.node.consequence.hits&&e.node.consequence.hits.edges){let t;r.csqcount=e.node.consequence.hits.edges.length,n.isoform&&(t=e.node.consequence.hits.edges.find((t=>t.node.transcript.transcript_id==n.isoform)));_(r,(t||e.node.consequence.hits.edges[0]).node)}if(e.node.occurrence.hits.edges)for(const n of e.node.occurrence.hits.edges){const e=b(n.node.case,t);e.sample_id=n.node.case.case_id,r.samples.push(e)}a.push(r)}return a}}function m(t){}function g(t){t.queries.snvindel.byisoform.get=async e=>{const n=v(e,t),r=await async function(t,e){if(!t.isoform)throw"snvindel_byisoform: .isoform missing";if("string"!=typeof t.isoform)throw".isoform value not string";const n=B,r=z,o=q(t),a=i.post(s.join(u,n.endpoint),{headers:o,body:JSON.stringify({size:n.size,fields:n.fields.join(","),filters:n.filters(t)})}),l=i.post(s.join(u,r.endpoint),{headers:o,body:JSON.stringify({size:r.size,fields:r.fields.join(","),filters:r.filters(t,e)})}),[c,f]=await Promise.all([a,l]);let d,h;try{d=JSON.parse(c.body),h=JSON.parse(f.body)}catch(t){throw"invalid JSON returned by GDC"}if(!d.data||!d.data.hits)throw"query1 did not return .data.hits";if(!h.data||!h.data.hits)throw"query2 did not return .data.hits[]";if(!Array.isArray(d.data.hits)||!Array.isArray(h.data.hits))throw"re.data.hits[] is not array";const p=new Map;for(const e of d.data.hits){if(!e.ssm_id)throw"ssm_id missing from a ssms hit";if(!e.consequence)throw".consequence[] missing from a ssm";if(!Number.isInteger(e.start_position))throw"hit.start_position is not integer";e.csqcount=e.consequence.length;const n=e.consequence.find((e=>e.transcript.transcript_id==t.isoform));e.consequence=n,e.cases=[],p.set(e.ssm_id,e)}for(const t of h.data.hits){if(!t.ssm)throw".ssm{} missing from a case";if(!t.ssm.ssm_id)throw".ssm.ssm_id missing from a case";const e=p.get(t.ssm.ssm_id);if(!e)throw"ssm_id not found in ssms query";if(!t.case)throw".case{} missing from a case";e.cases.push(t.case)}return[...p.values()]}(e,t),a=[];for(const n of r){const r={ssm_id:n.ssm_id,dt:o.dtsnvindel,chr:n.chromosome,pos:n.start_position-1,ref:n.reference_allele,alt:n.tumor_allele,isoform:e.isoform,csqcount:n.csqcount};if(_(r,n.consequence),!e.hiddenmclass||!e.hiddenmclass.has(r.class)){r.samples=[];for(const o of n.cases){const n={sample_id:await T(o,t,e.useCaseid4sample)};o.case_id&&(n["case.case_id"]=o.case_id),r.samples.push(n)}a.push(r)}}if(n){e.isoform=n;for(const t of a)t.isoform=n}return a}}function y(t){const e=t.queries.snvindel.byisoform.gdcapi;if(!e.query)throw".query missing for byisoform.gdcapi";if(!e.filters)throw".filters missing for byisoform.gdcapi";if("function"!=typeof e.filters)throw"byisoform.gdcapi.filters() is not function";t.queries.snvindel.byisoform.get=async n=>{const r=v(n,t),s=q(n),a=await i.post(e.apihost,{headers:s,body:JSON.stringify({query:e.query,variables:e.filters(n)})}),l=JSON.parse(a.body);if(!(l.data&&l.data.analysis&&l.data.analysis.protein_mutations&&l.data.analysis.protein_mutations.data))throw"data not .data.analysis.protein_mutations.data";const c=JSON.parse(l.data.analysis.protein_mutations.data);if(!c.hits)throw"re.hits missing";const u=[];for(const t of c.hits){const e=t._source,r={ssm_id:e.ssm_id,dt:o.dtsnvindel,chr:e.chromosome,pos:e.start_position-1,ref:e.reference_allele,alt:e.tumor_allele,isoform:n.isoform,occurrence:t._score,csqcount:e.consequence.length};_(r,e.consequence.find((t=>t.transcript.transcript_id==n.isoform))),u.push(r)}if(r){n.isoform=r;for(const t of u)t.isoform=r}return u}}function v(t,e){if(!t.isoform)return;let n;if("N"==t.isoform[0]&&e.refseq2ensembl_query){const r=e.refseq2ensembl_query.get(t.isoform);r&&(n=t.isoform,t.isoform=r.ensembl)}return n}function b(t,e){const n={};if(e.sampleSummaries)for(const r of e.sampleSummaries.lst){{const o=e.cohort.termdb.q.termjsonByOneid(r.label1);if(o){n[r.label1]=t[o.fields[0]];for(let t=1;t<o.fields.length;t++)n[r.label1]&&(n[r.label1]=n[r.label1][o.fields[t]])}}if(r.label2){const o=e.cohort.termdb.q.termjsonByOneid(r.label2);if(o){n[r.label2]=t[o.fields[0]];for(let t=1;t<o.fields.length;t++)n[r.label2]&&(n[r.label2]=n[r.label2][o.fields[t]])}}}return n}function _(t,e){if(e&&e.transcript.consequence_type){const[n,r,i]=o.vepinfo(e.transcript.consequence_type);t.class=r,t.mname=e.transcript.aa_change}t.mname||(t.mname=t.ref+">"+t.alt),t.class||(o.basecolor[t.ref]&&o.basecolor[t.alt]?t.class=o.mclasssnv:"-"==t.ref?t.class=o.mclassinsertion:"-"==t.alt?t.class=o.mclassdeletion:t.class=o.mclassmnv)}function w(t){const e=["cnv_id","cnv_change","gene_level_cn","occurrence.case.submitter_id","consequence.gene.symbol"];function n(t){const n=e.slice();if(t.twLst)for(const e of t.twLst){let t=e.term.id;t.startsWith("case.")&&(t="occurrence."+t),n.push(t)}return n.join(",")}function r(t){if(!t.gene&&"string"!=typeof t.gene)throw"p.gene does not provide non-empty string";const e={op:"and",content:[]};return t.gene&&e.content.push({op:"=",content:{field:"consequence.gene.symbol",value:t.gene.split(",")}}),t.filter0&&e.content.push(function(t){const e="string"==typeof t?t:JSON.stringify(t);return JSON.parse(e.replace('"cases.case_id"','"occurrence.case.case_id"'))}(t.filter0)),t.filterObj&&e.content.push(c("string"==typeof t.filterObj?JSON.parse(t.filterObj):t.filterObj)),e}t.queries.geneCnv.bygene.get=async t=>{var e;const a=q(t),l=await i.post(s.join(u,"cnvs"),{headers:a,body:JSON.stringify({size:1e5,fields:n(t),filters:r(t)})}),c=JSON.parse(l.body);if(!Array.isArray(null==c||null===(e=c.data)||void 0===e?void 0:e.hits))throw"geneCnv response body is not {data:hits[]}";const f=[];for(const e of c.data.hits){if(!e.gene_level_cn)throw"hit.gene_level_cn is not true";if(!e.cnv_id)throw"hit.cnv_id missing";const n={ssm_id:e.cnv_id,dt:o.dtcnv,samples:[]};if("Gain"==e.cnv_change?n.class=o.mclasscnvgain:"Loss"==e.cnv_change?n.class=o.mclasscnvloss:(console.log("cnv_change not Gain/Loss"),n.class=e.cnv_change),!Array.isArray(e.occurrence))throw"hit.occurrence[] not array";for(const r of e.occurrence){if(!r.case)throw"hit.occurrence[].case{} missing";if(!r.case.submitter_id)throw"hit.occurrence[].case.submitter_id missing";const e={sample_id:r.case.submitter_id};if(t.twLst)for(const n of t.twLst)N(e,r.case,n);n.samples.push(e)}f.push(n)}return f}}function x(t){const e=["cnv.cnv_change","cnv.gene_level_cn","cnv.consequence.gene.symbol","case.submitter_id"];function n(t){const n=e.slice();if(t.twLst)for(const e of t.twLst){let t=e.term.id;t.startsWith("case.")&&(t="occurrence."+t),n.push(t)}return n.join(",")}function r(t){if(!t.gene&&"string"!=typeof t.gene)throw"p.gene does not provide non-empty string";const e={op:"and",content:[]};return t.gene&&e.content.push({op:"=",content:{field:"cnv.consequence.gene.symbol",value:t.gene.split(",")}}),t.filter0&&e.content.push(t.filter0),t.filterObj&&e.content.push(c("string"==typeof t.filterObj?JSON.parse(t.filterObj):t.filterObj)),e}t.queries.geneCnv.bygene.get=async t=>{var e;const a=q(t),l=await i.post(s.join(u,"cnv_occurrences"),{headers:a,body:JSON.stringify({size:1e5,fields:n(t),filters:r(t)})}),c=JSON.parse(l.body);if(!Array.isArray(null==c||null===(e=c.data)||void 0===e?void 0:e.hits))throw"geneCnv response body is not {data:hits[]}";const f={ssm_id:"geneCnvGain",dt:o.dtcnv,class:o.mclasscnvgain,samples:[]},d={ssm_id:"geneCnvLoss",dt:o.dtcnv,class:o.mclasscnvloss,samples:[]};for(const e of c.data.hits){if("object"!=typeof e.cnv)throw"hit.cnv{} not obj";if("object"!=typeof e.case)throw"hit.case{} not obj";if(!e.cnv.gene_level_cn)throw"hit.cnv.gene_level_cn is not true";let n;if("Gain"==e.cnv.cnv_change)n=f;else{if("Loss"!=e.cnv.cnv_change)throw"hit.cnv.cnv_change is not Gain/Loss";n=d}const r={sample_id:e.case.submitter_id};if(t.twLst)for(const n of t.twLst)N(r,e.case,n);n.samples.push(r)}const h=[];return f.samples.length&&h.push(f),d.samples.length&&h.push(d),h}}function k(t,e){if(!e)return;const n=e.split(",");for(const e of n){const n=e.split("--");if(2==n.length)return t.geneA=n[0].split("(")[0],void(t.geneB=n[1].split("(")[0])}}function q(t){const e={"Content-Type":"application/json",Accept:"application/json"};return t&&(t.token&&(e["X-Auth-Token"]=t.token),t.sessionid&&(e.Cookie="sessionid="+t.sessionid)),e}function N(t,e,n){const r=n.term.id.split(".");if(function e(o,i){const s=r[i];if(i==r.length-1)return void(t[n.term.id]?t[n.term.id].add(o[s]):t[n.term.id]=o[s]);const a=o[s];if(null==a)return;if(Array.isArray(a)){t[n.term.id]=new Set;for(const t of a)e(t,i+1);return}e(a,i+1)}(e,1),t[n.term.id]instanceof Set&&(t[n.term.id]=[...t[n.term.id]][0]),n.term.id in t&&"categorical"==n.term.type){const e=function(t,e){var n,r,o,i,s,a,l;if("custom-groupset"==(null===(n=e.q)||void 0===n?void 0:n.type)&&Array.isArray(null===(r=e.q)||void 0===r||null===(o=r.groupsetting)||void 0===o||null===(i=o.customset)||void 0===i?void 0:i.groups))for(const n of e.q.groupsetting.customset.groups){if(!Array.isArray(n.values))throw"group.values[] not array from tw.q.groupsetting.customset.groups";if(-1!=n.values.findIndex((e=>e.key==t)))return n.name}if("predefined-groupset"==(null===(s=e.q)||void 0===s?void 0:s.type)&&Number.isInteger(null===(a=e.q.groupsetting)||void 0===a?void 0:a.predefined_groupset_idx)&&null!==(l=e.term.groupsetting)&&void 0!==l&&l.lst[e.q.groupsetting.predefined_groupset_idx])for(const n of e.term.groupsetting.lst[e.q.groupsetting.predefined_groupset_idx]){if(!Array.isArray(n.values))throw"group.values[] not array from tw.term.groupsetting.lst[]";if(-1!=n.values.findIndex((e=>e.key==t)))return n.name}}(t[n.term.id],n);e&&(t[n.term.id]=e)}}function S(t,e){for(const n of t)if(n.startunbounded){if(e<n.stop)return n.label;if(n.stopinclusive&&e==n.stop)return n.label}else if(n.stopunbounded){if(e>n.start)return n.label;if(n.startinclusive&&e==n.start)return n.label}else if((e>n.start||e===n.start&&n.startinclusive)&&(e<n.stop||e===n.stop&&n.stopinclusive))return n.label}function A(t){for(const n of t)if(null==n.id||""==n.id){var e;if(null==n||null===(e=n.term)||void 0===e||!e.id)throw"tw.id and tw.term are both missing";n.id=n.term.id}else n.term||(n.term={id:n.id})}async function M(t,e,n,o){if(A(e),o){if(!Array.isArray(o))throw"geneTwLst not array";t.isoforms=[];for(const e of o){var a;if(null==e||null===(a=e.term)||void 0===a||!a.name)throw"gene tw missing .term.name";if(e.term.isoform)t.isoforms.push(e.term.isoform);else{var c,f;if("object"!=typeof t.genome)throw"serverside genome obj missing, needed to map gene name to canonical isoform";if(null===(c=t.genome)||void 0===c||null===(f=c.genedb)||void 0===f||!f.get_gene2canonicalisoform)throw"gene2canonicalisoform not supported on this genome";const n=t.genome.genedb.get_gene2canonicalisoform.get(e.term.name);if(null==n||!n.isoform)continue;t.isoforms.push(n.isoform)}}}"samples"==t.get&&((t.ssm_id_lst||t.isoform)&&(e.some((t=>"ssm.ssm_id"==t.id))||e.push({term:{id:"ssm.ssm_id"}}),e.some((t=>"case.observation.read_depth.t_alt_count"==t.id))||e.push({term:{id:"case.observation.read_depth.t_alt_count"}}),e.some((t=>"case.observation.read_depth.t_depth"==t.id))||e.push({term:{id:"case.observation.read_depth.t_depth"}}),e.some((t=>"case.observation.read_depth.n_depth"==t.id))||e.push({term:{id:"case.observation.read_depth.n_depth"}}),e.some((t=>"case.observation.sample.tumor_sample_uuid"==t.id))||e.push({term:{id:"case.observation.sample.tumor_sample_uuid"}})),o&&(e.some((t=>"case.submitter_id"==t.id))||e.push({term:{id:"case.submitter_id"}})),e.some((t=>"case.case_id"==t.id))||e.push({term:{id:"case.case_id"}})),"summary"!=t.get&&"sunburst"!=t.get||e.some((t=>"case.submitter_id"==t.id))||e.push({term:{id:"case.submitter_id"}});const d=[];for(const t of e){const e=n.cohort.termdb.q.termjsonByOneid(t.term.id);e&&d.push({term:e,q:t.q})}const h=e.map((t=>t.term.id));t.hiddenmclass&&(h.push("ssm.consequence.transcript.consequence_type"),h.push("ssm.consequence.transcript.transcript_id")),t.rglst&&(h.push("ssm.chromosome"),h.push("ssm.start_position"));const p={size:1e4,fields:h.join(",")};v(t,n),p.filters=z.filters(t,n);const m=q(t),g=await i.post(s.join(u,z.endpoint),{headers:m,body:JSON.stringify(p)});let y;delete t.isoforms;try{y=JSON.parse(g.body)}catch(t){throw"invalid JSON from GDC for variant2samples query"}if(!y.data||!y.data.hits)throw"variant2samples data structure not data.hits[]";if(!Array.isArray(y.data.hits))throw"variant2samples re.data.hits is not array for query";const b=[];for(const e of y.data.hits){if(!e.case)throw"variant2samples .case{} missing from a hit";const r={};if(e.ssm&&(r.ssm_id=e.ssm.ssm_id),t.hiddenmclass){var w;if(!Array.isArray(null===(w=e.ssm)||void 0===w?void 0:w.consequence))continue;const n={};if(_(n,e.ssm.consequence.find((e=>e.transcript.transcript_id==t.isoform))),t.hiddenmclass.has(n.class))continue}if(t.rglst){var x,k;if(null===(x=e.ssm)||void 0===x||!x.chromosome||null===(k=e.ssm)||void 0===k||!k.start_position)continue;if(!t.rglst.find((t=>t.chr==e.ssm.chromosome&&t.start<e.ssm.start_position&&t.stop>=e.ssm.start_position)))continue}var M,O,E,R;if(r.sample_id=await T(e.case,n,!0),e.case.case_id)r.sample_URLid=e.case.case_id,null!==(M=e.case)&&void 0!==M&&null!==(O=M.observation)&&void 0!==O&&null!==(E=O[0])&&void 0!==E&&null!==(R=E.sample)&&void 0!==R&&R.tumor_sample_uuid&&(r.sample_URLid=r.sample_URLid+"?bioId="+e.case.observation[0].sample.tumor_sample_uuid);for(const t of d)N(r,e.case,t);C(e.case,r),j(r,n),b.push(r)}if(function(t,e){for(const o of e){var n;if(("integer"==o.term.type||"float"==o.term.type)&&null!==(n=o.q)&&void 0!==n&&n.mode)if("discrete"==o.q.mode||"binary"==o.q.mode){const e={};for(const n of t){const t=n[o.term.id];Number.isFinite(t)&&("min"in e?(e.min=Math.min(t,e.min),e.max=Math.max(t,e.max)):(e.min=t,e.max=t))}const n=(0,r.compute_bins)(o.q,(t=>e));for(const e of t){const t=e[o.term.id];Number.isFinite(t)&&(e[o.term.id]=S(n,t))}}else if("continuous"!=o.q.mode)throw"mayApplyBinning: unknown numeric q.mode"}}(b,d),o){const t={gene:o.map((t=>t.term.name)).join(","),twLst:d},e=await n.queries.geneCnv.bygene.get(t);for(const t of e)for(const e of t.samples)b.push(e)}const I=new Map;for(const t of b)l([t],I,t.ssm_id);return[...I.values()]}async function T(t,e,n){var r,o,i;return n&&t.submitter_id?t.submitter_id:null!=t&&null!==(r=t.observation)&&void 0!==r&&null!==(o=r[0])&&void 0!==o&&null!==(i=o.sample)&&void 0!==i&&i.tumor_sample_uuid?await e.aliquot2submitter.get(t.observation[0].sample.tumor_sample_uuid):t.case_id||t.submitter_id}function C(t,e){if(!t.observation)return;const n=t.observation[0];n&&n.read_depth&&(e.formatK2v={TumorAC:n.read_depth.t_depth-n.read_depth.t_alt_count+","+n.read_depth.t_alt_count,NormalDepth:n.read_depth.n_depth})}function j(t,e){var n;const r=t["case.project.project_id"];r&&(t.caseIsOpenAccess=null===(n=e.gdcOpenProjects)||void 0===n?void 0:n.has(r))}async function O(t,e,n,r){A(t);const o=[];for(const e of t)e.term&&"categorical"==e.term.type&&o.push({id:e.id,path:e.id.replace("case.","").replace(/\./g,"__"),type:e.term.type});const s=function(t){const e=[];for(const n of t)if(n.id)if(n.type="categorical")e.push(n.path+" {buckets { doc_count, key }}");else{if("integer"!=n.type&&"float"!=n.type)throw"unknown term type";e.push(n.path+" {stats { count }}")}const n=`query termislst2total( $filters: FiltersArgument) {\n\t\texplore {\n\t\t\tcases {\n\t\t\t\taggregations (filters: $filters, aggregations_filter_themselves: true) {\n\t\t\t\t\t${e.join("\n")}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}`;return n}(o),a=function(t,e){const n={filters:{op:"and",content:[{op:"in",content:{field:"cases.available_variation_data",value:["ssm"]}}]}};if(t&&t.tid2value)for(const r in t.tid2value){e.cohort.termdb.q.termjsonByOneid(r)&&n.filters.content.push({op:"in",content:{field:r.replace(/^case\./,"cases."),value:[t.tid2value[r]]}})}t&&t.ssm_id_lst&&n.filters.content.push({op:"=",content:{field:"cases.gene.ssm.ssm_id",value:t.ssm_id_lst.split(",")}});return n}(e,r),l=await i.post(f,{headers:q(e),body:JSON.stringify({query:s,variables:a})});let c;try{c=JSON.parse(l.body)}catch(t){throw"invalid JSON from GDC for cohortTotal for query :"+s+" and filter: "+filter}const u=["data","explore","cases","aggregations"];let d=c[u[0]];for(let t=1;t<u.length;t++)if(d=d[u[t]],!d)throw"."+u[t]+" missing from data structure of termid2totalsize2 for query :"+s+" and filter: "+filter;for(const t of o){if("categorical"==t.type&&!Array.isArray(d[t.path].buckets))throw u.join(".")+" not array for query :"+s+" and filter: "+filter;if(("integer"==t.type||"float"==t.type)&&"object"!=typeof d[t.path].stats)throw u.join(".")+" not object for query :"+s+" and filter: "+filter}const h=new Map;for(const t of o)if("categorical"==t.type){const e=d[t.path].buckets;let n=[];for(const t of e)n.push([t.key.replace(".","__"),t.doc_count]);h.set(t.id,n)}else if("integer"==t.type||"float"==t.type){const e=d[t.path].stats.count;h.set(t.id,{total:e})}return n?[h,n]:h}function E(t){const e=["consequence.transcript.transcript_id","consequence.transcript.consequence_type","consequence.transcript.aa_change"];t.queries.snvindel.m2csq.get=async t=>{const n=await i(u+"/ssms/"+t.ssm_id+"?fields="+e.join(","),{method:"GET",headers:q(t)});let r;try{r=JSON.parse(n.body)}catch(t){throw"invalid json in response"}if(!r.data||!r.data.consequence)throw"returned data not .data.consequence";if(!Array.isArray(r.data.consequence))throw".data.consequence not array";return r.data.consequence.map((t=>t.transcript))}}function R(t,e){t.queries.singleSampleMutation.get=async(n,r)=>{if(!n)throw"sampleName missing";return r.case_id=await async function(t){const e=await i.post("https://api.gdc.cancer.gov/cases",{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({size:1,fields:"case_id,submitter_id",filters:{op:"or",content:[{op:"=",content:{field:"samples.portions.analytes.aliquots.aliquot_id",value:[t]}},{op:"=",content:{field:"submitter_id",value:[t]}},{op:"=",content:{field:"samples.submitter_id",value:[t]}}]}})}),n=JSON.parse(e.body);for(const t of n.data.hits)if(t.case_id)return t.case_id;throw"cannot convert to case_id (uuid)"}(n),await P(r,t,e)}}function I(t){return async(e,n)=>{try{const r=t[e.query.genome];if(!r)throw"invalid genome";const o=r.datasets[e.query.dslabel];if(!o)throw"invalid dslabel";if(!e.query.case_id)throw".case_id missing";n.send({mlst:await P(e.query,o,r)})}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}}async function P(t,e,n){const r=[];{const e=await i.post(s.join(u,B.endpoint),{headers:q(t),body:JSON.stringify({size:1e3,fields:B.fields.join(","),filters:B.filters(t)})}),a=JSON.parse(e.body);for(const t of a.data.hits){let e;for(const n of t.consequence)if(n.transcript&&n.transcript.gene&&n.transcript.gene.symbol){e=n.transcript.gene.symbol;break}if(!e)continue;const i=n.genedb.get_gene2canonicalisoform.get(e);if(null==i||!i.isoform)continue;let s=t.consequence.find((t=>t.transcript.transcript_id==i.isoform));s||(s=t.consequence[0]);const a=s.transcript.aa_change||s.transcript.consequence_type,[l,c,u]=o.vepinfo(s.transcript.consequence_type);r.push({dt:o.dtsnvindel,mname:a,class:c,gene:s.transcript.gene.symbol,chr:t.chromosome,pos:t.start_position,ref:t.reference_allele,alt:t.tumor_allele})}}{const e=await async function(t){const e=q(t),n=await i.post(s.join(u,"files"),{headers:e,body:JSON.stringify({size:1e4,fields:["cases.samples.sample_type","data_type","file_id","data_format","experimental_strategy","analysis.workflow_type"].join(","),filters:function(t){if(!t.case_id)throw".case_id missing";return{op:"and",content:[{op:"in",content:{field:"cases.case_id",value:[t.case_id]}},{op:"in",content:{field:"data_type",value:["Masked Copy Number Segment","Copy Number Segment","Transcript Fusion"]}}]}}(t)})}),r=JSON.parse(n.body);if(!Array.isArray(r.data.hits))throw"re.data.hits[] not array";let a,l,c;for(const t of r.data.hits)if("BEDPE"!=t.data_format){if("TXT"==t.data_format){if("Genotyping Array"==t.experimental_strategy){var f,d,h;const e=null===(f=t.cases)||void 0===f||null===(d=f[0].samples)||void 0===d||null===(h=d[0])||void 0===h?void 0:h.sample_type;if(!e)continue;if(e.includes("Normal"))continue;if("Masked Copy Number Segment"!=t.data_type)continue;a=t.file_id;continue}if("WGS"==t.experimental_strategy){if(!t.file_id)continue;if("Copy Number Segment"!=t.data_type)continue;l=t.file_id;continue}}}else{var p;if("RNA-Seq"!=t.experimental_strategy)continue;if("Arriba"!=(null===(p=t.analysis)||void 0===p?void 0:p.workflow_type))continue;if("Transcript Fusion"!=t.data_type)continue;c=t.file_id}const m=[];if(l){const t=(await i(s.join(u,"data")+"/"+l,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t");if(7!=n.length)continue;const r=Number(n[4]),i=Number(n[5]),s=Number(n[6]);if(Number.isNaN(r)||Number.isNaN(i)||Number.isNaN(s))continue;const a={dt:o.dtcnv,chr:n[1],start:Number(n[2]),stop:Number(n[3]),value:r};!a.chr||Number.isNaN(a.start)||Number.isNaN(a.stop)||(m.push(a),r>0&&0==s&&i>0&&m.push({dt:o.dtloh,chr:a.chr,start:a.start,stop:a.stop,segmean:.5}))}}else if(a){const t=(await i(s.join(u,"data")+"/"+a,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t");if(6!=n.length)continue;if(!n[1])continue;const r={dt:o.dtcnv,chr:"chr"+n[1],start:Number(n[2]),stop:Number(n[3]),value:Number(n[5])};Number.isNaN(r.start)||Number.isNaN(r.stop)||Number.isNaN(r.value)||m.push(r)}}if(c)try{const t=(await i(s.join(u,"data")+"/"+c,{method:"GET",headers:e})).body.split("\n");for(let e=1;e<t.length;e++){const n=t[e].split("\t"),r={dt:o.dtfusionrna,chrA:n[0],posA:Number(n[1]),chrB:n[3],posB:Number(n[4])};r.chrA&&r.chrB&&!Number.isNaN(r.posA)&&!Number.isNaN(r.posB)&&(k(r,n[6]),m.push(r))}}catch(t){}return m}(t);r.push(...e)}return r}function F(t){return async(e,n)=>{try{if(!t[e.query.genome])throw"invalid genome";n.send({genes:await L({filter:e.query.filter0,CGConly:parseInt(e.query.CGConly),maxGenes:e.query.maxGenes})})}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}}async function L({filter:t,CGConly:e,maxGenes:n}){let r={op:"and",content:[]};if(t){if("object"!=typeof t)throw"filter not object";r=t}const o=await i.post(s.join(u,"/analysis/top_mutated_genes_by_project"),{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({size:n||50,fields:"symbol",filters:D(r,e)})}),a=JSON.parse(o.body),l=[];for(const t of a.data.hits)t.symbol&&l.push(t.symbol);return l}function D(t,e){let n;if("in"==t.op)n={op:"and",content:[t]};else{if("and"!=t.op)throw'f.op not "in" or "and"';n=t}return n.content.push({op:"NOT",content:{field:"ssms.consequence.transcript.annotation.vep_impact",value:"missing"}}),n.content.push({op:"in",content:{field:"ssms.consequence.transcript.consequence_type",value:["missense_variant","frameshift_variant","start_lost","stop_lost","stop_gained"]}}),e&&n.content.push({op:"in",content:{field:"genes.is_cancer_gene_census",value:["true"]}}),n}const B={endpoint:"/ssms",size:1e5,fields:["ssm_id","chromosome","start_position","reference_allele","tumor_allele","consequence.transcript.transcript_id","consequence.transcript.consequence_type","consequence.transcript.aa_change","consequence.transcript.gene.symbol"],filters:t=>{const e={op:"and",content:[]};if(t.isoform){if("string"!=typeof t.isoform)throw".isoform value not string";e.content.push({op:"=",content:{field:"consequence.transcript.transcript_id",value:[t.isoform]}})}if(t.case_id){if("string"!=typeof t.case_id)throw".case_id value not string";e.content.push({op:"=",content:{field:"cases.case_id",value:[t.case_id]}})}if(t.set_id){if("string"!=typeof t.set_id)throw".set_id value not string";e.content.push({op:"in",content:{field:"cases.case_id",value:[t.set_id]}})}return t.filter0&&e.content.push(t.filter0),t.filterObj&&e.content.push(c(t.filterObj)),e}},z={endpoint:"/ssm_occurrences",size:1e5,fields:["ssm.ssm_id","case.case_id","case.submitter_id","case.observation.sample.tumor_sample_uuid"],filters:(t,e)=>{const n={op:"and",content:[]};if(t.ssm_id_lst){if("string"!=typeof t.ssm_id_lst)throw"ssm_id_lst not string";n.content.push({op:"=",content:{field:"ssm.ssm_id",value:t.ssm_id_lst.split(",")}})}else if(t.isoform)n.content.push({op:"=",content:{field:"ssms.consequence.transcript.transcript_id",value:[t.isoform]}});else{if(!t.isoforms)throw".ssm_id_lst, .isoform, .isoforms are all missing";if(!Array.isArray(t.isoforms))throw".isoforms[] not array";n.content.push({op:"in",content:{field:"ssms.consequence.transcript.transcript_id",value:t.isoforms}})}if(t.rglst&&(n.content.push({op:">=",content:{field:"ssms.start_position",value:t.rglst[0].start}}),n.content.push({op:"<=",content:{field:"ssms.start_position",value:t.rglst[0].stop}})),t.set_id){if("string"!=typeof t.set_id)throw".set_id value not string";n.content.push({op:"in",content:{field:"cases.case_id",value:[t.set_id]}})}if(t.filter0&&n.content.push(t.filter0),t.filterObj&&n.content.push(c(t.filterObj)),t.tid2value)for(const r in t.tid2value){const o=e.cohort.termdb.q.termjsonByOneid(r);if(o)if("categorical"==o.type)n.content.push({op:"in",content:{field:r,value:[t.tid2value[r]]}});else if("integer"==o.type)for(const e of t.tid2value[r])n.content.push({op:e.op,content:{field:r,value:e.range}})}return n}}},9191:(t,e,n)=>{"use strict";n.r(e),n.d(e,{client_copy:()=>J,cnvByRangeGetter_file:()=>st,init:()=>U,snvindelByRangeGetter_bcf:()=>Y,ssmIdFieldsSeparator:()=>Z,svfusionByRangeGetter_file:()=>it,validate_termdb:()=>W});var r=n(7147),o=n.n(r),i=n(4521),s=n.n(i),a=n(1017),l=n.n(a),c=n(9064),u=n(6718),f=n(5243);const d=n(6452),h=n(1017),p=n(1575).CG,m=n(334),g=process.env.PP_GDC_HOST||"https://api.gdc.cancer.gov",y=g+(g.includes("/v0")?"":"/v0")+"/graphql",v=h.join(g,"ssm_occurrences/_mapping"),b={default:{mode:"discrete",type:"regular-bin",bin_size:1,startinclusive:!1,stopinclusive:!0,first_bin:{startunbounded:!0,stop:0},last_bin:{start:1,stopunbounded:!0}}},_={"case.demographic.age_at_index":{default:{mode:"discrete",type:"regular-bin",bin_size:10,startinclusive:!1,stopinclusive:!0,first_bin:{startunbounded:!0,stop:30}}},"case.demographic.days_to_birth":{default:{mode:"discrete",type:"regular-bin",bin_size:1e4,startinclusive:!1,stopinclusive:!0,first_bin:{startunbounded:!0,stop:-3e4}}},"case.demographic.days_to_death":{default:{mode:"discrete",type:"regular-bin",bin_size:1e3,startinclusive:!1,stopinclusive:!0,first_bin:{startunbounded:!0,stop:1e3}}}},w="ssm_occurrence_centrics";async function x(t){const e=new Map,n=await d(v,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"}});let r;try{r=JSON.parse(n.body)}catch(t){throw"invalid JSON from GDC dictionary"}if(!r._mapping)throw"returned data does not have ._mapping";if(!Array.isArray(r.fields))throw".fields not array";if(!Array.isArray(r.nested))throw".nested not array";const o=new Set(r.nested);let i=0,s=0,a=0,l=0,c=0,u=0;for(const t of r.fields){if(N(t)){i++;continue}const n=t.split(".");for(let t=1;t<n.length;t++){const i=n.slice(0,t).join("."),u=i+"."+n[t],f=n[t][0].toUpperCase()+n[t].slice(1).replace(/_/g," "),d={id:u.toLowerCase(),name:f,included_types_set:new Set,child_types_set:new Set};if(t==n.length-1){d.isleaf=!0;const t=r._mapping[w+"."+u];t&&("keyword"==t.type?(d.type="categorical",a++):"long"==t.type?(d.type="integer",d.bins=_[d.id]||JSON.parse(JSON.stringify(b)),_[d.id]||console.log("lack bin config for integer "+d.id),l++):"double"==t.type&&(d.type="float",d.bins=_[d.id]||JSON.parse(JSON.stringify(b)),_[d.id]||console.log("lack bin config for float "+d.id),c++)),d.type||s++,k(d)}if(1==t);else if(d.parent_id=i,d.type){d.included_types_set.add(d.type);let t=e.get(i);for(;t&&(t.included_types_set.add(d.type),t.child_types_set.add(d.type),t.parent_id);)t=e.get(t.parent_id)}o.has(u)&&(d.isObjectList=!0),e.set(u,d)}}for(const t of e.values())t.type||u++,t.included_types=[...t.included_types_set],t.child_types=[...t.child_types_set],delete t.included_types_set,delete t.child_types_set;console.log("GDC dictionary:",e.size,"total variables,",i,"lines skipped,",s,"lines with unknown term type,","categorical="+a,"integer="+l,"float="+c,"parent="+u),Object.freeze(e),function(t,e){const n=t.cohort.termdb.q={};async function r(e,n){if(0==e.length||!n)return;const r=await t.termdb.termid2totalsize2.get(e.map((t=>t.id)),JSON.parse(n));for(const t of e)if(t){const e=r.get(t.id);"categorical"==t.type&&e?e.length?t.samplecount=e.map((t=>t[1])).reduce(((t,e)=>t+e)):(t.disabled=!0,t.samplecount=0):"integer"!=t.type&&"float"!=t.type||(t.samplecount=e.total,0==e.total&&(t.disabled=!0))}}n.getRootTerms=async(t,n=null)=>{const o=[];for(const t of e.values())null==t.parent_id&&o.push(JSON.parse(JSON.stringify(t)));return await r(o,n),o},n.getTermChildren=async(t,n=null,o=null)=>{const i=[];for(const n of e.values())n.parent_id==t&&i.push(JSON.parse(JSON.stringify(n)));return await r(i,o),i},n.findTermByName=async(t,n=null,o,i=null,s=null)=>{(t=t.toLowerCase()).includes(" ")&&(t=t.replace(/\s/g,"_"));const a=[];for(const n of e.values())s&&!p(n,s)||n.id.includes(t)&&a.push(JSON.parse(JSON.stringify(n)));return await r(a,i),a},n.getAncestorIDs=t=>{if(!e.has(t))return;const n=t.split("."),r=[];for(let t=1;t<n.length;t++)r.push(n.slice(0,t+1).join("."));return r},n.getAncestorNames=n.getAncestorIDs,n.termjsonByOneid=t=>{const n=e.get(t);return n?JSON.parse(JSON.stringify(n)):null},n.getSupportedChartTypes=()=>{const t={},n={};for(const r of e.values())r.type&&(r.cohort in t||(t[r.cohort]=["barchart","table","regression"],n[r.cohort]=0),"survival"!=r.type||t[r.cohort].includes("survival")||t[r.cohort].push("survival"),"condition"!=r.type||t[r.cohort].includes("cuminc")||t[r.cohort].push("cuminc"),"float"!=r.type&&"integer"!=r.type||(n[r.cohort]+=r.samplecount));for(const e in n)n[e]>0&&t[e].push("boxplot"),n[e]>1&&t[e].push("scatterplot");return t}}(t,e),t.cohort.termdb.termtypeByCohort=[],a&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"categorical"}),l&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"integer"}),c&&t.cohort.termdb.termtypeByCohort.push({cohort:"",type:"float"}),await async function(t){var e,n,r;const o={"Content-Type":"application/json",Accept:"application/json"},i={filters:{op:"and",content:[{op:"=",content:{field:"access",value:"open"}},{op:"=",content:{field:"data_type",value:"Masked Somatic Mutation"}}]},facets:"cases.project.project_id",size:0},s=await d(h.join(g,"files"),{method:"POST",headers:o,body:JSON.stringify(i)}),a=JSON.parse(s.body);if(t.gdcOpenProjects=new Set,null!=a&&null!==(e=a.data)&&void 0!==e&&null!==(n=e.aggregations)&&void 0!==n&&null!==(r=n["cases.project.project_id"])&&void 0!==r&&r.buckets){for(const e of a.data.aggregations["cases.project.project_id"].buckets)e.key&&t.gdcOpenProjects.add(e.key);console.log("GDC open-access projects:",t.gdcOpenProjects.size)}else console.log("getting open project_id but return is not re.data.aggregations['cases.project.project_id'].buckets")}(t),async function(){try{await S(g+"/ssms"),await S(g+"/ssm_occurrences"),await S(g+"/cases"),await S(g+"/files"),await S(g+"/analysis/top_mutated_genes_by_project"),await async function(t){const e=new Date;try{const e="query termislst2total( $filters: FiltersArgument) {\n\t\texplore {\n\t\t\tcases {\n\t\t\t\taggregations (filters: $filters, aggregations_filter_themselves: true) {\n\t\t\t\t\tprimary_site {buckets { doc_count, key }}\n\t\t\t\t}\n\t\t\t}\n\t\t}}";await d.post(t,{headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:e,variables:{}})})}catch(e){throw"gdc api down: "+t}console.log("GDC GraphQL API okay: "+t,new Date-e,"ms")}(y)}catch(t){console.error(`\n##########################################\n#\n# GDC API unavailable\n# ${g}\n# ${y}\n#\n##########################################`)}}(),async function(t){try{if(t.aliquot2submitter={cache:new Map,get:async e=>t.aliquot2submitter.cache.has(e)?t.aliquot2submitter.cache.get(e):e},m.features.stopGdcCacheAliquot)return console.log("GDC aliquot2submitter not cached!");const e=await A(t,1,0);if(!Number.isInteger(e))throw"gdc totalCases not integer";const n=new Date;console.log("Start to cache aliquot IDs of",e,"cases...");const r=1e3;for(let n=0;n<Math.ceil(e/r);n++)await A(t,r,1e3*n);console.log("Done caching",t.aliquot2submitter.cache.size,"aliquot IDs.",new Date-n,"ms")}catch(t){console.log("Error at caching: "+t)}}(t)}function k(t){"case.diagnoses.age_at_diagnosis"!=t.id||(t.printDays2years=!0)}const q=new Set(["case.consent_type","case.days_to_consent","case.days_to_index"]);function N(t){return!!(t.startsWith("ssm")||t.startsWith("case.observation")||t.startsWith("case.available_variation_data"))||(!(!t.endsWith("_id")||t.endsWith("project_id"))||(!!q.has(t)||void 0))}async function S(t){try{const e=new Date;await d(t),console.log("GDC API okay: "+t,new Date-e,"ms")}catch(e){throw"gdc api down: "+t}}async function A(t,e,n,r){var o,i,s;const a=["fields=samples.portions.analytes.aliquots.aliquot_id,samples.submitter_id"];if(r)a.push('filters={"op":"and","content":[{"op":"=","content":{"field":"samples.portions.analytes.aliquots.aliquot_id","value":["'+r+'"]}}]}');else{if(!Number.isInteger(e)||!Number.isInteger(n))throw"size and from not integers";a.push("size="+e),a.push("from="+n)}const l=await d(g+"/cases?"+a.join("&")),c=JSON.parse(l.body);if(!Array.isArray(null==c||null===(o=c.data)||void 0===o?void 0:o.hits))throw"re.data.hits[] not array";for(const e of c.data.hits)if(Array.isArray(e.samples))for(const n of e.samples){const e=n.submitter_id;if(Array.isArray(n.portions))for(const r of n.portions)if(Array.isArray(r.analytes))for(const n of r.analytes)if(Array.isArray(n.aliquots))for(const r of n.aliquots){const n=r.aliquot_id;if(!n)throw"aliquot.aliquot_id missing";t.aliquot2submitter.cache.set(n,e)}}return null===(i=c.data)||void 0===i||null===(s=i.pagination)||void 0===s?void 0:s.total}var M=n(817),T=n(3856),C=n(3625),j=n(7027),O=n(334),E=n.n(O),R=n(2273),I=n(2852),P=n(394),F=n(1711),L=n(1883),D=n(2188),B=n(2974),z=n(3795);const Z=".",$="Ancestry_PC_",G="Unannotated";async function U(t,e,n,r=null,i=null){var s,a;await W(t),t.queries&&(await async function(t,e){const n=t.queries.snvindel;if(!n)return;if(n.url){if(!n.url.base)throw".snvindel.url.base missing";if(!n.url.key)throw".snvindel.url.key missing"}if(!n.byisoform&&!n.byrange)throw"byisoform and byrange are both missing on queries.snvindel";if(n.byrange)if(n.byrange.gdcapi)f.validate_query_snvindel_byrange(t);else if(n.byrange.bcffile){var r;n.byrange.bcffile=l().join(E().tpmasterdir,n.byrange.bcffile),n.byrange._tk={file:n.byrange.bcffile},n.byrange.get=await Y(t,e),null!==(r=n.byrange._tk)&&void 0!==r&&r.samples.length||delete n.byrange._tk.samples,V(t,n.byrange._tk.samples,"snvindel.byrange.bcffile")}else{if(!n.byrange.chr2bcffile)throw"unknown query method for queries.snvindel.byrange";n.byrange._tk={chr2files:{}};for(const t in n.byrange.chr2bcffile)n.byrange._tk.chr2files[t]={file:l().join(E().tpmasterdir,n.byrange.chr2bcffile[t])};delete n.byrange.chr2bcffile,n.byrange.get=await Y(t,e),n.byrange._tk.samples.length||delete n.byrange._tk.samples,V(t,n.byrange._tk.samples,"snvindel.byrange.bcffile")}if(n.byisoform){if(!n.byisoform.gdcapi)throw"unknown query method for queries.snvindel.byisoform";f.validate_query_snvindel_byisoform(t)}if(n.m2csq){if(!n.m2csq.by)throw".by missing from queries.snvindel.m2csq";if("ssm_id"!=n.m2csq.by)throw"unknown value of queries.snvindel.m2csq.by";if(!n.m2csq.gdcapi)throw"unknown query method for queries.snvindel.m2csq";f.validate_m2csq(t)}}(t,e),await async function(t,e){const n=t.queries.svfusion;if(!n)return;if(!n.byrange)throw"byrange missing from queries.svfusion";if(n.byrange){if(!n.byrange.file)throw"unknown query method for svfusion.byrange";n.byrange.file=l().join(E().tpmasterdir,n.byrange.file),n.byrange.get=await it(t,e),V(t,n.byrange.samples,"svfusion.byrange")}}(t,e),await async function(t,e){const n=t.queries.geneCnv;if(!n)return;if(!n.bygene)throw"geneCnv.bygene missing";n.bygene.gdcapi&&f.validate_query_geneCnv2(t)}(t),await async function(t,e){const n=t.queries.cnv;if(!n)return;if(!n.byrange)throw"byrange missing from queries.cnv";if(n.byrange){if(!n.byrange.file)throw"unknown query method for cnv.byrange";n.byrange.file=l().join(E().tpmasterdir,n.byrange.file),n.byrange.get=await st(t,e),V(t,n.byrange.samples,"cnv.byrange")}}(t,e),await async function(t,e){const n=t.queries.ld;if(!n)return;if(!Array.isArray(n.tracks)||!n.tracks.length)throw"ld.tracks[] not nonempty array";for(const t of n.tracks){if(!t.name)throw"name missing from one of ld.tracks[]";if(!t.file)throw".file missing from one of ld.tracks[]";t.file0=t.file,t.file=l().join(E().tpmasterdir,t.file),await T.validate_tabixfile(t.file),t.nochr=await T.tabix_is_nochr(t.file,null,e)}if(!n.overlay)throw"ld.overlay{} missing";if(!n.overlay.color_0)throw"ld.overlay.color_0 missing";if(!n.overlay.color_1)throw"ld.overlay.color_1 missing"}(t,e),await async function(t,e){const n=t.queries.geneExpression;if(!n)return;if(n.gdcapi)return void f.validate_query_geneExpression(t);if(!n.file)throw".file missing from queries.geneExpression";n.file=l().join(E().tpmasterdir,n.file),await T.validate_tabixfile(n.file),n.nochr=await T.tabix_is_nochr(n.file,null,e),n.get=async e=>{const r=await tt(e,null,t),o=new Map;for(const t of e.genes)o.set(t.gene,{}),await T.get_lines_bigfile({args:[n.file,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:e=>{const n=e.split("\t");let i;try{i=JSON.parse(n[3])}catch(t){return}i.gene==t.gene&&(r&&!r.has(i.sample)||(o.get(t.gene)[i.sample]=i.value))}});return o}}(t,e),await async function(t,e){const n=t.queries.singleSampleMutation;if(!n)return;if(n.gdcapi)f.validate_query_singleSampleMutation(t,e);else{if(!n.folder)throw"unknown query method for singleSampleMutation";n.get=async e=>{var r,o,i;let s=e;if(null!==(r=t.cohort)&&void 0!==r&&null!==(o=r.termdb)&&void 0!==o&&null!==(i=o.q)&&void 0!==i&&i.sampleName2id&&(s=t.cohort.termdb.q.sampleName2id(e),null==s))return[];const a=await T.read_file(l().join(E().tpmasterdir,n.folder,s.toString()));return JSON.parse(a)}}}(t,e),await async function(t,e){const n=t.queries.singleSampleGenomeQuantification;if(!n)return;for(const r in n){if(!Number.isFinite(n[r].min))throw"min not a number";if(!Number.isFinite(n[r].max))throw"max not a number";if(n[r].min>=n[r].max)throw"min>=max";if(!n[r].folder)throw"unknown query method for singleSampleGenomeQuantification";n[r].get=async(o,i)=>{var s,a,c;let u=o;if(null!==(s=t.cohort)&&void 0!==s&&null!==(a=s.termdb)&&void 0!==a&&null!==(c=a.q)&&void 0!==c&&c.sampleName2id&&(u=t.cohort.termdb.q.sampleName2id(o),null==u))return[];return await ot(l().join(E().tpmasterdir,n[r].folder,u.toString()),e,n[r],i)}}}(t,e),await async function(t,e){const n=t.queries.singleSampleGbtk;if(!n)return;for(const e in n){if(!Number.isFinite(n[e].min))throw"min not a number";if(!Number.isFinite(n[e].max))throw"max not a number";if(n[e].min>=n[e].max)throw"min>=max";if(!n[e].folder)throw"unknown query method for singleSampleGbtk";n[e].get=async r=>{var i,s,a;let c=r;if(null!==(i=t.cohort)&&void 0!==i&&null!==(s=i.termdb)&&void 0!==s&&null!==(a=s.q)&&void 0!==a&&a.sampleName2id&&(c=t.cohort.termdb.q.sampleName2id(r),null==c))return{};const u=l().join(n[e].folder,c+".gz");try{return await o().promises.stat(l().join(E().tpmasterdir,u)),{path:u}}catch(t){return{}}}}}(t),await async function(t,e){const n=t.queries.probe2cnv;if(!n)return;if(n.file)n.file=l().join(E().tpmasterdir,n.file),await T.validate_tabixfile(n.file);else{if(!n.url)throw"file and url both missing on probe2cnv";n.dir=await T.cache_index(n.url,n.indexURL)}n.nochr=await T.tabix_is_nochr(n.file||n.url,null,e);{const e=await T.get_header_tabix(n.file);if(!e[0])throw"header line missing from "+n.file;const r=e[0].split("\t");if(r.length<3)throw"probe2cnv header line less than 3 fields";n.samples=r.slice(2).map((e=>({name:t.cohort.termdb.q.sampleName2id(e)})))}n.get=async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";if(e.cnvGainCutoff&&!Number.isFinite(e.cnvGainCutoff))throw"cnvGainCutoff is not finite";if(e.cnvLossCutoff&&!Number.isFinite(e.cnvLossCutoff))throw"cnvLossCutoff is not finite";const r=[];{const o=await tt(e,n.samples,t);if(o)for(const[t,e]of n.samples.entries())o.has(e.name)?r.push([]):r.push(null);else for(const t of n.samples)r.push([])}for(const t of e.rglst)await T.get_lines_bigfile({args:[n.file,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:t=>{const e=t.split("\t");for(const[t,n]of r.entries()){if(!n)continue;const r=Number(e[t+2]);Number.isFinite(r)&&n.push(r)}}});const o=[];for(const[t,i]of r.entries()){if(!i)continue;const r=(0,j.Z)(i,50),s={dt:R.dtcnv,value:r,samples:[{sample_id:n.samples[t].name}]};r>0&&r>(e.cnvGainCutoff||.1)?s.class=R.mclasscnvgain:r<0&&r<(e.cnvLossCutoff||-.1)&&(s.class=R.mclasscnvloss),s.class&&o.push(s)}return o}}(t,e),(0,M.validate_variant2samples)(t),function(t){if(!t.ssm2canonicalisoform)return;if(t.ssm2canonicalisoform.gdcapi)return void f.validate_ssm2canonicalisoform(t.ssm2canonicalisoform);throw"ssm2canonicalisoform.gdcapi is false"}(t),function(t,e){if(!e.genedb.hasTable_refseq2ensembl)return;t.refseq2ensembl_query=e.genedb.db.prepare("select ensembl from refseq2ensembl where refseq=?")}(t,e),function(t,e){if(!t.queries.snvindel&&!t.queries.svfusion&&!t.queries.geneCnv)return;t.mayGetGeneVariantData=async(n,r)=>{if("object"!=typeof n.term)throw"tw.term{} is not object";if("geneVariant"!=n.term.type)throw"tw.term.type is not geneVariant";if("string"!=typeof n.term.name)throw"tw.term.name is not string";if(!n.term.name)throw"tw.term.name should be gene symbol but is empty string";const o=[];if(t.queries.snvindel){const i=await async function(t,e,n,r){const o={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter};t.queries.geneCnv&&(o.useCaseid4sample=!0);if(t.queries.snvindel.byisoform)return await async function(t,e){if(t.isoform&&"string"==typeof t.isoform)return;if(!t.name)throw"both term.name and term.isoform";const n=e.genedb.getjsonbyname.all(t.name);if(0==n.length)return;const r=n.find((t=>t.isdefault))||n[0],o=JSON.parse(r.genemodel);if(!o.isoform)throw"isoform missing from returned gm";t.isoform=o.isoform}(e,n),e.isoform?(o.isoform=e.isoform,await t.queries.snvindel.byisoform.get(o)):[];if(t.queries.snvindel.byrange)return await lt(e,n),o.rglst=[e],await t.queries.snvindel.byrange.get(o);throw"unknown queries.snvindel method"}(t,n.term,e,r);o.push(...i)}if(t.queries.svfusion){const i=await async function(t,e,n,r){const o={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter};if(t.queries.svfusion.byrange)return await lt(e,n),o.rglst=[e],await t.queries.svfusion.byrange.get(o);throw"unknown queries.svfusion method"}(t,n.term,e,r);o.push(...i)}if(t.queries.cnv){const i=await async function(t,e,n,r){var o,i,s;const a={addFormatValues:!0,filter0:r.filter0,filterObj:r.filter,cnvMaxLength:null==e||null===(o=e.q)||void 0===o?void 0:o.cnvMaxLength,cnvGainCutoff:null==e||null===(i=e.q)||void 0===i?void 0:i.cnvGainCutoff,cnvLossCutoff:null==e||null===(s=e.q)||void 0===s?void 0:s.cnvLossCutoff};if(t.queries.cnv.byrange)return await lt(e.term,n),a.rglst=[e.term],await t.queries.cnv.byrange.get(a);throw"unknown queries.cnv method"}(t,n,e,r);o.push(...i)}if(t.queries.probe2cnv){const i=await async function(t,e,n,r){var o,i;const s={filter0:r.filter0,filterObj:r.filter,cnvGainCutoff:null==e||null===(o=e.q)||void 0===o?void 0:o.cnvGainCutoff,cnvLossCutoff:null==e||null===(i=e.q)||void 0===i?void 0:i.cnvLossCutoff};return await lt(e.term,n),s.rglst=[e.term],await t.queries.probe2cnv.get(s)}(t,n,e,r);o.push(...i)}if(t.queries.geneCnv){const e=await async function(t,e,n,r){const o={filter0:r.filter0};if(t.queries.geneCnv.bygene)return e.name?(o.gene=e.name,await t.queries.geneCnv.bygene.get(o)):[];throw"unknown queries.geneCnv method"}(t,n.term,0,r);o.push(...e)}const i=new Map;for(const e of o)if(Array.isArray(e.samples))for(const r of e.samples){var s,a;if(i.has(r.sample_id)||i.set(r.sample_id,{sample:r.sample_id}),null!==(s=t.cohort)&&void 0!==s&&null!==(a=s.termdb)&&void 0!==a&&a.additionalSampleAttributes)for(const e of t.cohort.termdb.additionalSampleAttributes)e in r&&(i.get(r.sample_id)[e]=r[e]);i.get(r.sample_id)[n.term.name]||(i.get(r.sample_id)[n.term.name]={key:n.term.name,label:n.term.name,values:[]});const o={gene:n.term.name,isoform:e.isoform,dt:e.dt,chr:n.term.chr,class:e.class,pos:e.pos||(e.start?e.start+"-"+e.stop:""),mname:e.mname,_SAMPLEID_:r.sample_id,_SAMPLENAME_:r.sample_id};if("value"in e&&(o.value=e.value),r.formatK2v)for(const t in r.formatK2v)o[t]=r.formatK2v[t];e.dt==R.dtsnvindel||e.dt==R.dtfusionrna||(e.dt,R.dtsv),t.cohort.termdb.q.id2sampleName&&Number.isInteger(r.sample_id)&&(o._SAMPLENAME_=t.cohort.termdb.q.id2sampleName(r.sample_id)),i.get(r.sample_id)[n.term.name].values.push(o)}return await async function(t,e,n,r){var o;if(null===(o=e.assayAvailability)||void 0===o||!o.byDt)return;const i=t.filter?new Set((await(0,I.get_samples)(t.filter,e)).map((t=>t.id))):null;for(const t in e.assayAvailability.byDt){const o=e.assayAvailability.byDt[t];if(o.byOrigin)for(const e in o.byOrigin){at(t,o.byOrigin[e],n,r,e,i)}else at(t,o,n,r,!1,i)}}(r,t,i,n.term.name),i}}(t,e)),function(t){if(!t.assayAvailability)return;if(t.assayAvailability.byDt)for(const e in t.assayAvailability.byDt){const n=t.assayAvailability.byDt[e];if(n.byOrigin)for(const e in n.byOrigin){const r=n.byOrigin[e];if(!r.yes||!r.no||!r.term_id)throw"ds.assayAvailability.byDt.*.byOrigin properties require .term_id .yes{} .no{}";ct(t,r)}else{if(!n.yes||!n.no||!n.term_id)throw"ds.assayAvailability.byDt properties require .term_id .yes{} .no{}";ct(t,n)}}}(t),null!==(s=t.cohort)&&void 0!==s&&null!==(a=s.db)&&void 0!==a&&a.refresh&&r&&(0,L.setDbRefreshRoute)(t,r,i)}function J(t){var e;const n={isMds3:!0,label:t.label};if(function(t,e){if(!t.queries)return;const n={};t.queries.singleSampleMutation&&(n.singleSampleMutation={sample_id_key:t.queries.singleSampleMutation.sample_id_key,discoSkipChrM:t.queries.singleSampleMutation.discoSkipChrM});if(t.queries.singleSampleGenomeQuantification){n.singleSampleGenomeQuantification={};for(const e in t.queries.singleSampleGenomeQuantification)n.singleSampleGenomeQuantification[e]=JSON.parse(JSON.stringify(t.queries.singleSampleGenomeQuantification[e])),delete n.singleSampleGenomeQuantification[e].folder}if(t.queries.singleSampleGbtk){n.singleSampleGbtk={};for(const e in t.queries.singleSampleGbtk)n.singleSampleGbtk[e]=JSON.parse(JSON.stringify(t.queries.singleSampleGbtk[e])),delete n.singleSampleGbtk[e].folder}const r=t.queries.snvindel;r&&(e.has_skewer=!0,n.snvindel={forTrack:r.forTrack,vcfid4skewerName:r.vcfid4skewerName,variantUrl:r.variantUrl,skewerRim:r.skewerRim},r.m2csq&&(n.snvindel.m2csq={by:r.m2csq.by}),r.info&&(e.bcf={info:r.info}),r.format&&(e.bcf||(e.bcf={}),e.bcf.format=r.format));if(t.queries.ld){n.ld=JSON.parse(JSON.stringify(t.queries.ld));for(const t of n.ld.tracks)delete t.file}e.queries=n}(t,n),null!==(e=t.cohort)&&void 0!==e&&e.termdb&&(n.termdb={},t.cohort.termdb.allowCaseDetails&&(n.termdb.allowCaseDetails={sample_id_key:t.cohort.termdb.allowCaseDetails.sample_id_key})),t.variant2samples){const e=t.variant2samples;n.variant2samples={sunburst_twLst:e.sunburst_twLst,twLst:e.twLst,type_samples:e.type_samples,type_summary:e.type_summary,type_sunburst:e.type_sunburst,url:e.url,variantkey:e.variantkey}}return n}async function W(t){var e,r,o,i;if(t.cohort){if(!t.cohort.termdb)throw"ds.cohort is set but cohort.termdb{} missing";if(!t.cohort.db)throw"ds.cohort is set but cohort.db{} missing";if(!t.cohort.db.file&&!t.cohort.db.file_fullpath)throw"ds.cohort.db.file missing"}else{if(!t.termdb)return;t.cohort={},t.cohort.termdb=t.termdb,delete t.termdb}const s=t.cohort.termdb;if(null!=s&&null!==(e=s.dictionary)&&void 0!==e&&e.gdcapi)await x(t);else if(null!=s&&null!==(r=s.dictionary)&&void 0!==r&&r.dbFile)t.cohort.db={file:s.dictionary.dbFile},delete s.dictionary.dbFile,(0,P.server_init_db_queries)(t);else{if(!t.cohort.db)throw"unknown method to initiate dictionary";(0,P.server_init_db_queries)(t)}if(s.termid2totalsize2&&(s.termid2totalsize2.gdcapi,s.termid2totalsize2.get=async(e,n={},r=null)=>s.termid2totalsize2.gdcapi?await f.get_termlst2size(e,n,r,t):await async function(t,e,n,r){const o=new Map;for(const n of t)if(n.term&&"categorical"==n.term.type){var i,s;const t={term1_id:n.id,term1_q:{type:"values"}};e.tid2value&&(t.filter=et(e.tid2value,r));const a=await(0,F.barchart_data)(t,r,r.cohort.termdb);if(null==a||null===(i=a.data)||void 0===i||null===(s=i.charts)||void 0===s||!s[0])continue;const l=[];for(const t of a.data.charts[0].serieses)l.push([t.seriesId,t.total]);o.set(n.id,l)}return n?[o,n]:o}(e,n,r,t)),function(t){const e=t.selectCohort;if(!e)return;if("object"!=typeof e)throw"selectCohort{} not object";if(!e.term)throw"term{} missing from termdb.selectCohort";if(!e.term.id)throw"id missing from termdb.selectCohort.term";if("string"!=typeof e.term.id)throw"termdb.selectCohort.term.id is not string";if("categorical"!=e.term.type)throw'type is not hardcoded "categorical" from termdb.selectCohort.term';{const n=t.q.termjsonByOneid(e.term.id);if(!n)throw"termdb.selectCohort.term.id is invalid";if("categorical"!=n.type)throw"termdb.selectCohort.term type is not categorical"}if(!e.values)throw"values[] missing from termdb.selectCohort";if(!Array.isArray(e.values))throw"termdb.selectCohort.values is not array";if(0==e.values.length)throw"termdb.selectCohort.values[] cannot be empty";for(const t of e.values){if(!t.keys)throw"keys[] missing from one of selectCohort.values[]";if(!Array.isArray(t.keys))throw"keys[] is not array from one of selectCohort.values[]";if(0==t.keys.length)throw"keys[] is empty from one of selectCohort.values[]"}}(s),await async function(t){if(!t.restrictAncestries)return;if(!Array.isArray(t.restrictAncestries)||0==t.restrictAncestries.length)throw"termdb.restrictAncestries[] is not non-empty array";for(const e of t.restrictAncestries){if(!e.name)throw"name missing from one of restrictAncestries";if("object"!=typeof e.tvs)throw".tvs{} missing from one of restrictAncestries";if(!e.tvs.term)throw"tvs.term{} missing from an ancestry";if(!e.tvs.term.id)throw"tvs.term.id missing from an ancestry";{const n=t.q.termjsonByOneid(e.tvs.term.id);if(!n)throw"tvs.term.id is invalid from an ancestry";if("categorical"!=n.type)throw"tvs.term.type is not categorical from an ancestry"}if(!Number.isInteger(e.PCcount))throw"PCcount is not integer";if(e.PCfile)e.pcs=await H(e.PCfile,e.PCcount);else if(e.PCfileBySubcohort){if(!t.selectCohort)throw"PCfileBySubcohort is in use but selectCohort is not enabled";for(const n in e.PCfileBySubcohort){let r=!0;for(const e of t.selectCohort.values)if(n==e.keys.sort().join(",")){r=!1;break}if(r)throw"unknown subcohort from PCfileBySubcohort";const o=e.PCfileBySubcohort[n];if(!o.file)throw".file missing for a subcohort in PCfileBySubcohort";o.pcs=await H(o.file,e.PCcount)}}}}(s),await(0,D.wz)(t),await(0,B.mayInitiateMatrixplots)(t),"minTimeSinceDx"in s){if(!Number.isFinite(s.minTimeSinceDx))throw"termdb.minTimeSinceDx not number";if(s.minTimeSinceDx<=0)throw"termdb.minTimeSinceDx<=0"}if("ageEndOffset"in s){if(!Number.isFinite(s.ageEndOffset))throw"termdb.ageEndOffset not number";if(s.ageEndOffset<=0)throw"termdb.ageEndOffset<=0"}if(t.cohort.termdb.additionalSampleAttributes){if(!Array.isArray(t.cohort.termdb.additionalSampleAttributes))throw"termdb.additionalSampleAttributes not array";for(const e of t.cohort.termdb.additionalSampleAttributes)if("string"!=typeof e)throw"non-str key in termdb.additionalSampleAttributes[]"}if(null!==(o=t.cohort)&&void 0!==o&&null!==(i=o.db)&&void 0!==i&&i.connection){t.sampleName2Id=new Map,t.sampleId2Name=new Map;const e="SELECT * FROM sampleidmap",n=t.cohort.db.connection.prepare(e).all();for(const e of n)t.sampleId2Name.set(e.id,e.name),t.sampleName2Id.set(e.name,e.id);t.getSampleIdMap=e=>{const n={};for(const r in e)n[r]=t.sampleId2Name.get(+r);return n}}if(t.cohort.mutationset){const{mayGetGeneVariantData:e,getTermTypes:r,mayGetMatchingGeneNames:o}=n(7833);t.mayGetGeneVariantData=e,t.getTermTypes=r,t.mayGetMatchingGeneNames=o}}async function H(t,e){const n=new Map;for(let t=1;t<=e;t++)n.set($+t,new Map);let r=0;for(const o of(await T.read_file(l().join(E().tpmasterdir,t))).trim().split("\n")){r++;const t=o.split("\t"),i=Number(t[0]);if(!Number.isInteger(i))throw"non-integer sample id from a line of restrictAncestries pc file";for(let r=1;r<=e;r++){const e=$+r,o=Number(t[r]);if(Number.isNaN(o))throw"non-numeric PC value from restrictAncestries file";n.get(e).set(i,o)}}return console.log(r,"samples loaded from "+t),Object.freeze(n)}function V(t,e,n){var r;if(!e)return;let o;if(null!=t&&null!==(r=t.cohort)&&void 0!==r&&r.termdb){for(const t of e){const e=Number(t.name);if(!Number.isInteger(e))throw"non-integer sample id from "+n;t.name=e}o=", all integer IDs"}console.log(e.length,"samples from "+n+" of "+t.label+o)}async function Y(t,e){var n;const r=t.queries.snvindel.byrange;if(r._tk.file)await T.init_one_vcf(r._tk,e,!0);else if(r._tk.chr2files){let t;for(const n in r._tk.chr2files){if("chr17"!=n)continue;const o=r._tk.chr2files[n];try{await T.init_one_vcf(o,e,!0);const i=JSON.stringify(o.samples);if(t){if(i!=t)throw"Different samples found in bcf file of "+n}else t=i,r._tk.samples=o.samples,r._tk.format=o.format,r._tk.info=o.info,r._tk.nochr=o.nochr}catch(t){console.log("missing file ignored:",o.file)}}}if(null!==(n=r._tk)&&void 0!==n&&n.samples.length){if(!r._tk.format)throw"bcf file has samples but no FORMAT"}else if(r._tk.format)throw"bcf file has FORMAT but no samples";if(r._tk.format){for(const t in r._tk.format)"GT"==t&&(r._tk.format[t].isGT=!0);if(t.queries.snvindel.format4filters){if(!Array.isArray(t.queries.snvindel.format4filters))throw"snvindel.format4filters[] is not array";for(const e of t.queries.snvindel.format4filters)r._tk.format[e]&&(r._tk.format[e].isFilter=!0);delete t.queries.snvindel.format4filters}}if(r._tk.info){if(r.infoFields){for(const t of r.infoFields){if(!t.key)throw".key missing from one of snvindel.byrange.infoFields[]";t.name||(t.name=t.key);const e=r._tk.info[t.key];if(!e)throw"invalid key from one of snvindel.byrange.infoFields[]";e.categories=t.categories,e.name=t.name,e.separator=t.separator}delete r.infoFields}if(t.queries.snvindel.infoUrl){for(const e of t.queries.snvindel.infoUrl){const t=r._tk.info[e.key];if(!t)throw"invalid key from one of snvindel.infoUrl[]";t.urlBase=e.base}delete t.queries.snvindel.infoUrl}}return t.queries.snvindel.info=r._tk.info,t.queries.snvindel.format=r._tk.format,async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";const n=Q(e);let o;if(r._tk.chr2files){const t=r._tk.chr2files[e.rglst[0].chr];if(!t)throw"unknown chr for chr2files";o=t.file}else o=r._tk.file||r._tk.url;const i=["query",o,"-r",e.rglst.map((t=>(r._tk.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+(t.stop+1))).join(","),"-f","%ID\t%CHROM\t%POS\t%REF\t%ALT\t%INFO\t%FORMAT\n"],s=await tt(e,r._tk.samples,t);s&&i.push("-s",[...s].join(",")),e.variantFilter&&(0,z.add_bcf_variant_filter)(e.variantFilter,i);const a=[];return await T.get_lines_bigfile({isbcf:!0,args:i,dir:r._tk.dir,callback:o=>{const i=o.split("\t"),l=i[0],c=i[1],u=Number(i[2]),f=i[3],d=i[4].split(","),h=i[5],p={pos:u-1};(0,C.compute_mclass)(r._tk,f,d,p,h,l,e.isoform);for(const o of p.mlst){var m,g,y;e.hiddenmclass&&e.hiddenmclass.has(o.class)||(K(o,e)||p.mlst.length>1&&null!==(m=e.variantFilter)&&void 0!==m&&m.lst&&X(o,e)||(o.chr=(r._tk.nochr?"chr":"")+c,o.ssm_id=[o.chr,o.pos,o.ref,o.alt].join(Z),null!==(g=r._tk)&&void 0!==g&&null!==(y=g.samples)&&void 0!==y&&y.length&&(nt(r,o,i,e.addFormatValues,t,s,n),!o.samples)||a.push(o)))}}}),a}}function Q(t){var e,n;const r=t.formatFilter||{};return"format"==(null===(e=t.skewerRim)||void 0===e?void 0:e.type)&&null!==(n=t.skewerRim.hiddenvalues)&&void 0!==n&&n.size&&(r[t.skewerRim.formatKey]=t.skewerRim.hiddenvalues),Object.keys(r).length?r:void 0}function K(t,e){if(!e.infoFilter)return!1;for(const n in e.infoFilter){const r=t.info[n];if(r)if(Array.isArray(r)){for(const t of e.infoFilter[n])if(r.includes(t))return!0}else if(e.infoFilter[n].includes(r))return!0}return!1}function X(t,e){for(const r of e.variantFilter.lst){const e=t.info[r.tvs.term.id];if(null==e)return!0;if("integer"==r.tvs.term.type||"float"==r.tvs.term.type){var n;const t=Number(e);if(Number.isNaN(t))return!0;const o=null===(n=r.tvs.ranges)||void 0===n?void 0:n[0];if(o){if("start"in o)if(o.startinclusive){if(t<o.start)return!0}else if(t<=o.start)return!0;if("stop"in o)if(o.stopinclusive){if(t>o.stop)return!0}else if(t>=o.stop)return!0}}}return!1}async function tt(t,e,n){if(!e)return;const r=function(t,e){if(t.filterObj){if(!Array.isArray(t.filterObj.lst))throw"filterObj.lst is not array";return 0==t.filterObj.lst.length?null:t.filterObj}if(t.tid2value){if("object"!=typeof t.tid2value)throw"q.tid2value{} not object";return et(t.tid2value,e)}}(t,n);if(!r)return;const o=[...new Set((await(0,I.get_samples)(r,n)).map((t=>t.id)))],i=new Set(e.map((t=>t.name))),s=new Set;for(const t of o)i.has(t)&&s.add(t);return s}function et(t,e){const n={type:"tvslst",in:!0,join:"and",lst:[]};for(const r in t){const o=e.cohort.termdb.q.termjsonByOneid(r);if(!o)continue;const i=t[r];n.lst.push({type:"tvs",tvs:{term:o,values:[{key:i}]}})}return n}function nt(t,e,n,r,o,i,s){if(!n[6]||"."==n[6])return;const a=[];for(const e of n[6].split(":")){const n=t._tk.format[e];if(!n)throw"invalid format field: "+n;a.push(n)}const l=[];let c=t._tk.samples;i&&(c=[...i].map((t=>({name:t}))));for(const[t,e]of c.entries()){const o=n[t+7];if(!o||"."==o)continue;const i=rt(o.split(":"),a,e,r);if(i){if(s){let t=!1;for(const e in s){const n=e in i.formatK2v?i.formatK2v[e]:G;if(s[e].has(n)){t=!0;break}}if(t)continue}l.push(i)}}l.length&&(e.samples=l)}function rt(t,e,n,r){const o={};for(const[n,r]of e.entries()){const e=t[n];if(e&&"."!=e)if(r.isGT){if("./."==e||".|."==e)continue;o.GT=e}else o[r.ID]=e}if(0==Object.keys(o).length)return null;const i={sample_id:n.name};return r&&(i.formatK2v=o),i}function ot(t,e,n,r=1){r=Number(r);const i=200,a=20;let l=0;for(const t in e.majorchr)l+=e.majorchr[t];const f=800/l,d={};let h=0;const p=[];for(const t in e.majorchr){const n=e.majorchr[t];d[t]=(0,c.Z)().domain([0,n]).range([f*h,f*(h+n)]),h+=n,p.push({chr:t,chrLen:n,xStart:f*(h-n),xStop:f*h})}const m=(0,c.Z)().domain([n.min,n.max]).range([i,0]),g=(0,u.createCanvas)(890*r,240*r),y=g.getContext("2d");r>1&&y.scale(r,r),b(n.max),b(0),b(n.min);const v=s().createInterface({input:o().createReadStream(t)});return new Promise(((t,r)=>{v.on("line",(t=>{const e=t.split("\t"),r=e[0];if(!r)return;if(!d[r])return;const o=Number(e[1]);if(!Number.isInteger(o))return;const i=Number(e[2]);if(!Number.isFinite(i))return;if(i<n.min||i>n.max)return;y.fillStyle=i>0?n.positiveColor:n.negativeColor;const s=d[r](o),l=a+m(i);y.fillRect(70+s,l,1,1)})),v.on("close",(()=>{!function(){y.strokeStyle="black",y.beginPath();{const t=220-m(0);y.moveTo(70,t),y.lineTo(870,t),y.stroke()}let t=!0;y.fillStyle="black",y.font="12px Arial",y.textAlign="center";for(const n in d){if(y.fillText(n.replace("chr",""),70+d[n](e.majorchr[n]/2),234),t){t=!1;continue}const r=Math.floor(70+d[n](0))+.5;y.moveTo(r,a),y.lineTo(r,220),y.stroke()}y.closePath()}(),t({src:g.toDataURL(),canvasWidth:890,canvasHeight:240,xoff:70,chrLst:p})}))}));function b(t){y.fillStyle="black",y.font="12px Arial",y.textAlign="right";const e=a+m(t);y.fillText(t,64,e+5),y.strokeStyle="black",y.beginPath(),y.moveTo(66,e),y.lineTo(70,e),y.stroke(),y.closePath()}}async function it(t,e){const n=t.queries.svfusion.byrange;if(n.file)await T.validate_tabixfile(n.file);else{if(!n.url)throw"file and url both missing on svfusion.byrange{}";n.dir=await T.cache_index(n.url,n.indexURL)}n.nochr=await T.tabix_is_nochr(n.file||n.url,null,e);{const t=await T.get_header_tabix(n.file);if(!t[0])throw"header line missing from "+n.file;const e=t[0].split(" ");if("#sample"!=e[0])throw"header line not starting with #sample: "+n.file;n.samples=e.slice(1).map((t=>({name:t})))}return async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";const r=Q(e),o=await tt(e,n.samples,t),i=new Map;for(const t of e.rglst)await T.get_lines_bigfile({args:[n.file||n.url,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:n=>{const s=n.split("\t"),a=Number(s[1]);let l,c,u,f,d;try{l=JSON.parse(s[3])}catch(t){return}if(l.dt!=R.dtfusionrna&&l.dt!=R.dtsv)return;if(l.class=l.dt==R.dtsv?R.mclasssv:R.mclassfusionrna,e.hiddenmclass&&e.hiddenmclass.has(l.class))return;if(l.sample&&o&&!o.has(l.sample))return;if(l.chrA)c=1,u=l.geneA||l.chrA,f=l.strandA,d=[{a:{chr:l.chrA,pos:l.posA,strand:l.strandA,name:l.geneA},b:{chr:t.chr,pos:a,strand:l.strandB,name:l.geneB}}];else if(l.chrB)c=0,u=l.geneB||l.chrB,f=l.strandB,d=[{a:{chr:t.chr,pos:a,strand:l.strandA,name:l.geneA},b:{chr:l.chrB,pos:l.posB,strand:l.strandB,name:l.geneB}}];else{if(!l.pairlst)throw"missing chrA and chrB";{d=l.pairlst;const t=l.pairlst.findIndex((t=>t.chr==chr&&t.pos==a));if(-1==t)throw"current point missing from pairlst";c=t}}const h=[l.dt,t.chr,a,f,c,encodeURIComponent(u)].join(Z);let p;if(l.sample&&(p={sample_id:l.sample},l.mattr)){if(r)for(const t in r){const e=t in l.mattr?l.mattr[t]:G;if(r[t].has(e))return}e.addFormatValues&&(p.formatK2v=l.mattr)}i.has(h)||i.set(h,{ssm_id:h,dt:l.dt,class:l.class,chr:t.chr,pos:a,strand:f,pairlstIdx:c,mname:u,pairlst:d,samples:[]}),p&&i.get(h).samples.push(p)}});return[...i.values()]}}async function st(t,e){const n=t.queries.cnv.byrange;if(n.file)await T.validate_tabixfile(n.file);else{if(!n.url)throw"file and url both missing on cnv.byrange{}";n.dir=await T.cache_index(n.url,n.indexURL)}n.nochr=await T.tabix_is_nochr(n.file||n.url,null,e);{const t=await T.get_header_tabix(n.file);if(!t[0])throw"header line missing from "+n.file;const e=t[0].split(" ");if("#sample"!=e[0])throw"header line not starting with #sample: "+n.file;n.samples=e.slice(1).map((t=>({name:t})))}return async e=>{if(!Array.isArray(e.rglst))throw"q.rglst[] is not array";if(0==e.rglst.length)throw"q.rglst[] blank array";if(e.cnvMaxLength&&!Number.isInteger(e.cnvMaxLength))throw"cnvMaxLength is not integer";if(e.cnvGainCutoff&&!Number.isFinite(e.cnvGainCutoff))throw"cnvGainCutoff is not finite";if(e.cnvLossCutoff&&!Number.isFinite(e.cnvLossCutoff))throw"cnvLossCutoff is not finite";const r=Q(e),o=await tt(e,n.samples,t),i=[],s=[];for(const t of e.rglst)s.push(T.get_lines_bigfile({args:[n.file||n.url,(n.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop],dir:n.dir,callback:n=>{const s=n.split("\t"),a=Number(s[1]),l=Number(s[2]);if(e.cnvMaxLength&&l-a>=e.cnvMaxLength)return;let c;try{c=JSON.parse(s[3])}catch(t){return}if(c.dt==R.dtcnv){if(c.start=a,c.stop=l,Number.isFinite(c.value)){if(c.value>0&&e.cnvGainCutoff&&c.value<e.cnvGainCutoff)return;if(c.value<0&&e.cnvLossCutoff&&c.value>e.cnvLossCutoff)return;c.class=c.value>0?R.mclasscnvgain:R.mclasscnvloss}else if(c.class!=R.mclasscnvgain&&c.class!=R.mclasscnvloss)return;if(c.ssm_id=[t.chr,c.start,c.stop,c.class].join(Z),(!e.hiddenmclass||!e.hiddenmclass.has(c.class))&&(!c.sample||!o||o.has(c.sample))){if(c.sample){const t={sample_id:c.sample};if(c.mattr){if(r)for(const t in r){const e=t in c.mattr?c.mattr[t]:G;if(r[t].has(e))return}e.addFormatValues&&(t.formatK2v=c.mattr)}delete c.sample,c.samples=[t]}i.push(c)}}}}));return await Promise.all(s),i}}function at(t,e,n,r,o,i){for(const s of e.yesSamples){if(i&&!i.has(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:Number.parseInt(t),class:"WT",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:Number.parseInt(t),class:"WT",_SAMPLEID_:s})}for(const s of e.noSamples){if(i&&!i.has(s))continue;n.has(s)||n.set(s,{sample:s});const e=n.get(s);r in e||(e[r]={key:r,values:[],label:r}),o?e[r].values.some((e=>e.dt==t&&e.origin==o))||e[r].values.push({dt:Number.parseInt(t),class:"Blank",_SAMPLEID_:s,origin:o}):e[r].values.some((e=>e.dt==t))||e[r].values.push({dt:Number.parseInt(t),class:"Blank",_SAMPLEID_:s})}}async function lt(t,e){if(t.chr&&Number.isInteger(t.start)&&Number.isInteger(t.stop))return;if(!t.name)throw"both term.name and term.chr/start/stop missing";const n=e.genedb.getjsonbyname.all(t.name);if(0==n.length)throw"unknown gene name";const r=n.find((t=>t.isdefault))||n[0],o=JSON.parse(r.genemodel);if(!o.chr||!Number.isInteger(o.start)||!Number.isInteger(o.stop))throw"invalid chr/start/stop from returned gm";t.chr=o.chr,t.start=o.start,t.stop=o.stop}function ct(t,e){e.yesSamples=new Set,e.noSamples=new Set;const n=`SELECT sample, value\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id = '${e.term_id}'`,r=t.cohort.db.connection.prepare(n).all();for(const t of r)e.yes.value.includes(t.value)?e.yesSamples.add(t.sample):e.no.value.includes(t.value)&&e.noSamples.add(t.sample)}},8089:(t,e,n)=>{"use strict";n.d(e,{f:()=>u});const r=n(9699),o=n(7147),i=n(1017),s=n(2081).spawn,a=n(3856),l=n(334),c=n(9191).snvindelByRangeGetter_bcf;n(1271).run_rust;function u(t){return async(e,n)=>{try{if(!e.query.genome)throw".genome missing";const o=t[e.query.genome];if(!o)throw"invalid genome";const i=function(t,e){const n=t.query;t.get("X-Auth-Token")&&(n.token=t.get("X-Auth-Token"));t.cookies.sessionid&&(n.sessionid=t.cookies.sessionid);n.hiddenmclasslst&&(n.hiddenmclass=new Set(n.hiddenmclasslst.split(",")),delete n.hiddenmclasslst);return n}(e),s=await async function(t,e){if(t.dslabel){if(!e.datasets)throw".datasets{} missing from genome";const n=e.datasets[t.dslabel];if(!n)throw"invalid dslabel";return n}const n={queries:{}};if(t.bcffile||t.bcfurl){const[o,i,s]=r.fileurl({query:{file:t.bcffile,url:t.bcfurl}});if(o)throw o;const a={};s?(a.url=i,a.indexURL=t.bcfindexURL):a.file=i,n.queries.snvindel={byrange:{_tk:a}},n.queries.snvindel.byrange.get=await c(n,e)}return n}(i,o);!function(t,e){var n;if(t.filter0){const n="object"==typeof t.filter0?t.filter0:JSON.parse("string"==typeof t.filter0&&t.filter0.startsWith("%")?decodeURIComponent(t.filter0):t.filter0);t.filter0=e.validate_filter0(n)}t.filterObj&&"string"==typeof t.filterObj&&(t.filterObj=JSON.parse("string"==typeof t.filterObj&&t.filterObj.startsWith("%")?decodeURIComponent(t.filterObj):t.filterObj));if(t.skewerRim){if("format"!=t.skewerRim.type)throw"unknown skewerRim.type";var r,o;if(!t.skewerRim.formatKey)throw"skewerRim.formatKey missing when type=format";if(null===(r=e.queries)||void 0===r||null===(o=r.snvindel)||void 0===o||!o.format)throw"snvindel.format{} not found when type=format";if(!e.queries.snvindel.format[t.skewerRim.formatKey])throw"invalid skewerRim.formatKey";if(t.skewerRim.hiddenvalues=new Set,t.skewerRim.hiddenvaluelst){if(!Array.isArray(t.skewerRim.hiddenvaluelst))throw"query.skewerRim.hiddenvaluelst is not array";for(const e of t.skewerRim.hiddenvaluelst)t.skewerRim.hiddenvalues.add(e);delete t.skewerRim.hiddenvaluelst}}if(t.formatFilter){var i,s;if("object"!=typeof t.formatFilter)throw"formatFilter{} not object";if(null===(i=e.queries)||void 0===i||null===(s=i.snvindel)||void 0===s||!s.format)throw"snvindel.format{} not found when formatFilter is used";const n={};for(const r in t.formatFilter){if(!e.queries.snvindel.format[r])throw"invalid format key from formatFilter";if(!Array.isArray(t.formatFilter[r]))throw"formatFilter[k] value is not array";n[r]=new Set(t.formatFilter[r])}t.formatFilter=n}("format"==(null===(n=t.skewerRim)||void 0===n?void 0:n.type)||t.formatFilter)&&(t.addFormatValues=!0)}(i,s);const a=await async function(t,e){if(t.singleSampleMutation){var n;if(null===(n=e.queries.singleSampleMutation)||void 0===n||!n.get)throw"not supported on this dataset";return{mlst:await e.queries.singleSampleMutation.get(t.singleSampleMutation,t)}}if(t.singleSampleGenomeQuantification){if(!e.queries.singleSampleGenomeQuantification)throw"not supported on this dataset";const n=e.queries.singleSampleGenomeQuantification[t.singleSampleGenomeQuantification.dataType];if(!n)throw"invalid dataType";return await n.get(t.singleSampleGenomeQuantification.sample,t.devicePixelRatio)}if(t.singleSampleGbtk){if(!e.queries.singleSampleGbtk)throw"not supported on this dataset";const n=e.queries.singleSampleGbtk[t.singleSampleGbtk.dataType];if(!n)throw"invalid dataType";return await n.get(t.singleSampleGbtk.sample)}if(t.ssm2canonicalisoform){if(!e.ssm2canonicalisoform)throw"ssm2canonicalisoform not supported on this dataset";return{isoform:await e.ssm2canonicalisoform.get(t)}}if(t.variant2samples){if(!e.variant2samples)throw"not supported by server";return{variant2samples:await e.variant2samples.get(t)}}if(t.m2csq){if(e.queries&&e.queries.snvindel&&e.queries.snvindel.m2csq)return{csq:await e.queries.snvindel.m2csq.get(t)};throw"m2csq not supported on this dataset"}if(t.forTrack){const n={};if(t.skewer){if(n.skewer=[],e.queries.snvindel){const r=await async function(t,e){if(t.isoform){if(t.atgenomic){if(!e.queries.snvindel.byrange)throw".atgenomic but missing byrange query method";return await e.queries.snvindel.byrange.get(t)}if(e.queries.snvindel.byisoform)return await e.queries.snvindel.byisoform.get(t)}if(t.rglst){if(!e.queries.snvindel.byrange)throw"q.rglst[] provided but .byrange{} is missing";return await e.queries.snvindel.byrange.get(t)}throw"insufficient query parameters for snvindel"}(t,e);n.skewer.push(...r)}if(e.queries.svfusion){const r=await async function(t,e){if(t.rglst){if(!e.queries.svfusion.byrange)throw"q.rglst provided but svfusion.byrange missing";return await e.queries.svfusion.byrange.get(t)}throw"insufficient query parameters for svfusion"}(t,e);n.skewer.push(...r)}if(e.queries.geneCnv){const r=await async function(t,e){if(t.gene){if(!e.queries.geneCnv.bygene)throw"q.gene provided but geneCnv.bygene missing";return await e.queries.geneCnv.bygene.get(t)}throw"insufficient query parameters for geneCnv"}(t,e);n.geneCnv=r}!function(t,e){if(e.skewer){const n=[];for(const r of e.skewer)t.rglst&&!t.rglst.find((t=>r.chr==t.chr&&r.pos>=t.start&&r.pos<=t.stop))||n.push(r);e.skewer=n}e.genecnvAtsample}(t,n),n.mclass2variantcount=function(t){const e=new Map;for(const n of t){const t=n.class||n.dt;e.set(t,1+(e.get(t)||0))}return[...e].sort(((t,e)=>e[1]-t[1]))}(n.skewer)}return function(t,e,n){const r=new Set;if(n.skewer)for(const o of n.skewer)if(o.samples){o.occurrence=o.samples.length,f(o,t,e),d(o,e);for(const t of o.samples)r.add(t.sample_id);delete o.samples}r.size&&(n.sampleTotalNumber=r.size)}(t,e,n),n}if(t.geneExpression){if(!e.queries.geneExpression)throw"not supported";const n=await e.queries.geneExpression.get(t);if(0==n.size)throw"no data";return 1==n.size?{gene2sample2value:n}:{clustering:await h(n,t)}}throw"do not know what client wants"}(i,s);n.send(a)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}function f(t,e,n){if(e.skewerRim){if("format"!=e.skewerRim.type)throw"unknown skewerRim.type";t.rim1count=0;for(const n of t.samples){var r;(null===(r=n.formatK2v)||void 0===r?void 0:r[e.skewerRim.formatKey])==e.skewerRim.rim1value&&t.rim1count++}}}function d(t,e){var n;if(null!==(n=e.queries.snvindel)&&void 0!==n&&n.format)for(const n in e.queries.snvindel.format)if(e.queries.snvindel.format[n].isFilter){t.formatK2count||(t.formatK2count={}),t.formatK2count[n]||(t.formatK2count[n]={v2c:{},unannotatedCount:0});for(const e of t.samples){var r;const o=null===(r=e.formatK2v)||void 0===r?void 0:r[n];null==o?t.formatK2count[n].unannotatedCount++:t.formatK2count[n].v2c[o]=1+(t.formatK2count[n].v2c[o]||0)}}}async function h(t,e){const n=new Set;for(const e of t.values())for(const t in e)n.add(t);const r={matrix:[],row_names:[],col_names:[...n],cluster_method:e.clusterMethod,plot_image:!1};for(const[e,n]of t){r.row_names.push(e);const t=[];for(const e of r.col_names)t.push(n[e]||0);const o=p(t);r.matrix.push(o)}new Date;const c=i.join(l.cachedir,Math.random().toString()+".json");await a.write_file(c,JSON.stringify(r));const u=await async function(t,e=[]){try{await o.promises.stat(t)}catch(e){throw`${t} does not exist`}const n=[],r=[];return new Promise(((o,i)=>{console.log("serverconfig.Rscript:",l.Rscript),console.log("Rscript:",t),console.log("args:",...e);const a=s(l.Rscript,[t,...e]);a.stdout.on("data",(t=>n.push(t))),a.stderr.on("data",(t=>r.push(t))),a.on("error",(t=>i(t))),a.on("close",(t=>{const e=n.join("").trim().split("\n");o(e)}))}))}(i.join(l.binpath,"utils","fastclust.R"),[c]);o.unlink(c,(()=>{}));let f,d,h=[],g=[],y=!1,v=!1;for(const t of u)t.includes('[1] "RowCoordinates"')?y=!0:t.includes('"ColumnCoordinates"')?(v=!0,y=!1):t.includes("rownames")?f=t.replace("rownames\t","").split("\t").map((t=>parseInt(t))).filter((t=>t)):t.includes("colnames")?d=t.replace("colnames\t","").split("\t").map((t=>parseInt(t))).filter((t=>t)):t.includes('"Done"')?v=!1:1==y?h.push(t):1==v&&g.push(t);let b=await m(h,f),_=await m(g,d);return{geneNameLst:r.row_names,sampleNameLst:r.col_names,matrix:r.matrix,row_dendro:b.dendrogram,row_children:b.children,row_names_index:f,col_dendro:_.dendrogram,col_children:_.children,col_names_index:d}}function p(t){let e=0;for(const n of t)e+=n;const n=e/t.length,r=Math.sqrt(t.map((t=>(t-n)**2)).reduce(((t,e)=>t+e),0)/(t.length-1));return 0==r?t:t.map((t=>(t-n)/r))}async function m(t,e){let n=1,r=[],o=[];for(const e of t)if(1==n)n=0;else if(0==e.length);else{let t=e.split(/(\s+)/);Number(t[t.length-3])%1!=0&&0==Number(t[t.length-1])?(r.push(Number(t[t.length-3])),o.push(1e-4)):(r.push(Number(t[t.length-3])),o.push(Number(t[t.length-1])))}let i=[],s=[],a=[],l=!1,c=[],u=0;for(let t=0;t<o.length;t++)if(1==l){let n=0;for(let e=0;e<s.length;e++){let l=s.length-e-1;if(s[l]>o[t]){i.push({id1:t,x1:r[t],y1:o[t],id2:l,x2:a[l],y2:s[l]}),n=1;break}}0==n&&console.log("No suitable branch point found"),i.push({id1:t,x1:r[t],y1:o[t],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t]),l=!1}else o[t]>o[t+1]&&t<=o.length-1?(i.push({id1:t,x1:r[t],y1:o[t],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t])):o[t]==o[t+1]&&t<=o.length-1?(i.push({id1:t-1,x1:r[t-1],y1:o[t-1],id2:t+1,x2:r[t+1],y2:o[t+1]}),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1),s.push(o[t]),a.push(r[t])):(t==o.length-1||(s.push(o[t]),a.push(r[t]),l=!0),0==o[t]&&(c=await g(i,t,c,e[u]),u+=1));return{dendrogram:i,children:c}}async function g(t,e,n,r){let o=e;if(n.find((t=>t.id==o))){let t=n.findIndex((t=>t.id==o));n[t].children.push(r)}else n.push({id:o,children:[r]});for(;0!=o;){let e,i,s=t.find((t=>t.id1==o));s&&s.y1<=s.y2&&(e=s.id2);let a=t.find((t=>t.id2==o));if(a&&a.y1>=a.y2&&(i=a.id1),!s&&a?o=i:s&&!a?o=e:s&&a?o=s.y2>a.y1?e:i:console.log("No connections found!"),n.find((t=>t.id==o))){let t=n.findIndex((t=>t.id==o));n[t].children.push(r)}else n.push({id:o,children:[r]})}return n}},4143:(t,e,n)=>{"use strict";n.d(e,{R:()=>s});const{filterJoin:r}=n(478),{get_rows_by_one_key:o}=n(2852),i=n(1271).run_rust;n(1017),n(334);async function s(t,e,n,r){!function(t,e){if(!t.chr)throw"q.chr missing";if(t.start=Number(t.start),t.stop=Number(t.stop),!Number.isInteger(t.start)||!Number.isInteger(t.stop))throw"q.start/stop is not integer";if("object"!=typeof t.details)throw"q.details{} not object";if(!Array.isArray(t.details.groups))throw"q.details.groups[] not array";if(!t.details.groups[0])throw"q.details.groups[0] missing";if(t.details.groups.length>2)throw"q.details.groups[] has more than 2";for(const r of t.details.groups)if("filter"==r.type){if("object"!=typeof r.filter)throw".filter not an object for group type=filter"}else if("population"==r.type){var n;if(!r.key)throw".key missing from group type=population";if(null===(n=e.queries.snvindel)||void 0===n||!n.populations)throw"group type=population but this ds does not have populations";if(!e.queries.snvindel.populations.find((t=>t.key==r.key)))throw"invalid key of group type=population"}else{if("info"!=r.type)throw"unknown group type from details.groups[]";if(!r.infoKey)throw".infoKey missing from group type=info"}if(t.details.groupTestMethods){if(!Array.isArray(t.details.groupTestMethods))throw"details.groupTestMethods[] not array";if(!Number.isInteger(t.details.groupTestMethodsIdx))throw"details.groupTestMethodsIdx not integer";if(!t.details.groupTestMethods[t.details.groupTestMethodsIdx])throw"invalid array index of details.groupTestMethodsIdx"}}(t,n);const i=await async function(t,e){const n={rglst:[{chr:t.chr,start:t.start,stop:t.stop}],addFormatValues:!0,variantFilter:t.variantFilter},[r,o]=t.details.groups;if("filter"==r.type&&"filter"==(null==o?void 0:o.type)){n.filterObj=c(t,r.filter);const i=l(await e.queries.snvindel.byrange.get(n));n.filterObj=c(t,o.filter);const s=l(await e.queries.snvindel.byrange.get(n)),u=function(t,e,n){const[r,o]=n.details.groups,i=[];for(const n of t){n.groupData=[{refCount:n._refCount,altCount:n._altCount}];const t=e.find((t=>t.chr==n.chr&&t.pos==n.pos&&t.ref==n.ref&&t.alt==n.alt));t?n.groupData.push({refCount:t._refCount,altCount:t._altCount}):n.groupData.push({refCount:0,altCount:0}),i.push(n)}for(const n of e){t.find((t=>t.chr==n.chr&&t.pos==n.pos&&t.ref==n.ref&&t.alt==n.alt))||(n.groupData=[{refCount:0,altCount:0},{refCount:n._refCount,altCount:n._altCount}],i.push(n))}return i}(i.mlst,s.mlst,t);return{mlst:u,totalSampleCount_group1:a(i.mlst),totalSampleCount_group2:a(s.mlst)}}n.filterObj=c(t);const i=await e.queries.snvindel.byrange.get(n),s=l(i);"filter"==r.type?s.totalSampleCount_group1=a(i):"filter"==(null==o?void 0:o.type)&&(s.totalSampleCount_group2=a(i));return s}(t,n);if(1==t.details.groups.length)u(n,i.mlst,t.details.groups[0]);else{if(2!=t.details.groups.length)throw"q.details.groups.length not 1 or 2";await async function(t,e,n){const[r,i]=e.groups;if("filter"==r.type&&"filter"==i.type)return void await async function(t,e,n){const r=e.groupTestMethods[e.groupTestMethodsIdx];if(!r)throw"details.groupTestMethodsIdx out of bound";switch(r.name){case"Allele frequency difference":return void d(t,e,n);case"Fisher's exact test":return void await m(n);default:throw"unknown value from groupTestMethods[]"}}(t,e,n);if("population"==r.type&&"filter"==i.type||"population"==i.type&&"filter"==r.type)return void await async function(t,e,n){const r=await async function(t,e,n){const r=e.groups.find((t=>"population"==t.type));if(!r)return;if(!r.adjust_race)return;const i=t.queries.snvindel.populations.find((t=>t.key==r.key));if(!i)throw"invalid group.key for population";const s=new Set;for(const t of n)for(const e of t.samples)s.add(e.sample_id);const a=new Map;let l=0;for(const e of i.sets){const n={infokey_AC:e.infokey_AC,infokey_AN:e.infokey_AN,average:0},r=await o({ds:t,key:e.key});for(const t of r){if(!s.has(t.sample))continue;const e=Number(t.value);Number.isFinite(e)&&(n.average+=e,l+=e)}a.set(e.key,n)}for(const[t,e]of a)e.average/=l;return a}(t,e,n);for(const o of n)o.groupData=h(t,e,o,r);const i=e.groupTestMethods[e.groupTestMethodsIdx];if(!i)throw"details.groupTestMethodsIdx out of bound";switch(i.name){case"Allele frequency difference":return void d(t,e,n);case"Fisher's exact test":return void await m(n);default:throw"unknown value from groupTestMethods[]"}}(t,e,n);d(t,e,n)}(n,t.details,i.mlst)}for(const t of i.mlst)delete t.samples,delete t._altCount,delete t._refCount;e.send(i)}function a(t){const e=new Set;for(const n of t)if(n.samples)for(const t of n.samples)e.add(t.sample_id);return e.size}function l(t){const e={mlst:[],skipMcountWithoutAlt:0};for(const n of t){const[t,r]=f(n);0!=t?(n._altCount=t,n._refCount=r-t,e.mlst.push(n)):e.skipMcountWithoutAlt++}return e}function c(t,e){const n=[t.filter];if(e)n.push(e);else for(const e of t.details.groups)"filter"==e.type&&n.push(e.filter);return r(n)}function u(t,e,n){if("filter"!=n.type)if("info"!=n.type){if("population"!=n.type)throw"unknown type of single group";{const r=t.queries.snvindel.populations.find((t=>t.key==n.key));if(!r)throw"unknown population";for(const t of e){let e=0,n=0;for(const o of r.sets)e+=Number(t.info[o.infokey_AC]||0),n+=Number(t.info[o.infokey_AN]||0);t.nm_axis_value=e/n}}}else{if(!n.infoKey)throw"infoKey missing on single group.type=info";for(const t of e){const e=t.info[n.infoKey];if(null==e);else{const n=Number(e);Number.isNaN(n)||(t.nm_axis_value=n)}}}else for(const t of e)t.nm_axis_value=Number((t._altCount/(t._altCount+t._refCount)).toPrecision(2))}function f(t){let e=0,n=0;for(const o of t.samples){var r;if(null==o||null===(r=o.formatK2v)||void 0===r||!r.GT)continue;const i=o.formatK2v.GT.split("/").map(Number);n+=i.length;for(const n of i)n==t.altAlleleIdx&&e++}return[e,n]}function d(t,e,n){const[r,o]=e.groups;u(t,n,r);const i=n.map((t=>t.nm_axis_value));u(t,n,o);for(const[t,e]of n.entries())e.nm_axis_value=i[t]-e.nm_axis_value}function h(t,e,n,r){const o=[];for(const i of e.groups)if("info"!=i.type)if("filter"!=i.type){if("population"!=i.type)throw"unknown group.type";{if(!i.key)throw"group.key missing for type=population";const e=t.queries.snvindel.populations.find((t=>t.key==i.key));if(!e)throw"invalid group.key for population";const s=new Map;for(const t of e.sets)s.set(t.key,{ACraw:Number(n.info[t.infokey_AC]||0),ANraw:Number(n.info[t.infokey_AN]||0)});let a=0,l=0;if(i.adjust_race)[a,l]=p(s,r);else for(const t of s.values())l+=t.ACraw,a+=t.ANraw-t.ACraw;o.push({altCount:l,refCount:a})}}else o.push({altCount:n._altCount,refCount:n._refCount});else{if(!i.key)throw"group.key missing for type=info";o.push({value:n.info[i.key]})}return o}function p(t,e){let n=0;for(const e of t.values())n+=e.ANraw;let r=0,o=0;for(const[i,s]of t)s.ANadj=n*e.get(i).average,s.ACadj=0==s.ANadj?0:s.ACraw*s.ANadj/s.ANraw,r+=s.ACadj,o+=s.ANadj;return[o-r,r]}async function m(t){for(let e=0;e<Math.ceil(t.length/200);e++){const n=[];for(let r=200*e;r<200*(e+1);r++){const e=t[r];if(!e)break;const o=e.groupData;o&&o[0]&&o[1]&&Number.isFinite(o[0].altCount)&&Number.isFinite(o[0].refCount)&&Number.isFinite(o[1].altCount)&&Number.isFinite(o[1].refCount)?(n.push({index:r,n1:o[0].altCount,n2:o[0].refCount,n3:Math.floor(o[1].altCount),n4:Math.floor(o[1].refCount)}),e.htmlSections=[{key:"Contigency table",html:`<table style="font-size:.9em">\n\t\t\t\t<tr style="opacity:.5">\n\t\t\t\t <td></td>\n\t\t\t\t <td>Group1</td>\n\t\t\t\t <td>Group 2</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">ALT allele count</td>\n\t\t\t\t <td>${o[0].altCount}</td>\n\t\t\t\t <td>${Math.floor(o[1].altCount)}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">REF allele count</td>\n\t\t\t\t <td>${o[0].refCount}</td>\n\t\t\t\t <td>${Math.floor(o[1].refCount)}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t <td style="opacity:.5">Allele frequency</td>\n\t\t\t\t <td>${(o[0].altCount/(o[0].altCount+o[0].refCount)).toFixed(3)}</td>\n\t\t\t\t <td>${(o[1].altCount/(o[1].altCount+o[1].refCount)).toFixed(3)}</td>\n\t\t\t\t</tr>\n\t\t\t\t</table>`}]):console.log(`${e.chr}.${e.pos}.${e.ref}.${e.alt}\t${JSON.stringify(o)}`)}const r=await i("fisher",JSON.stringify({input:n}));for(const e of JSON.parse(r)){const n=t[e.index];n&&(n.p_value=e.p_value.toPrecision(2),e.p_value>0&&(n.nm_axis_value=Number((-Math.log10(e.p_value)).toPrecision(2))))}}let e=0;for(const n of t)n.p_value>0&&(e=Math.max(e,n.nm_axis_value));for(const n of t)0==n.p_value&&(n.nm_axis_value=Math.max(50,e))}},817:(t,e,n)=>{"use strict";n.r(e),n.d(e,{combineSamplesById:()=>d,get_crosstabCombinations:()=>g,validate_variant2samples:()=>f});const{stratinput:r}=n(1881),{querySamples_gdcapi:o}=n(5243),{get_densityplot:i}=n(9402),{ssmIdFieldsSeparator:s}=n(9191),{dtfusionrna:a,dtsv:l}=(n(3856),n(2273)),c=n(4065),{getSampleData_dictionaryTerms_termdb:u}=n(2974);function f(t){const e=t.variant2samples;if(e){if(e.type_samples="samples",e.type_sunburst="sunburst",e.type_summary="summary",!e.variantkey)throw".variantkey missing from variant2samples";if(-1==["ssm_id"].indexOf(e.variantkey))throw"invalid value of variantkey";if(e.twLst){if(!Array.isArray(e.twLst))throw"variant2samples.twLst[] is not array";if(0==e.twLst.length)throw"variant2samples.twLst[] empty array";if(!t.cohort||!t.cohort.termdb)throw"ds.cohort.termdb missing when variant2samples.twLst is in use";for(const n of e.twLst){if(!n.id)throw"tw.id missing from one of variant2samples.twLst[]";const e=t.cohort.termdb.q.termjsonByOneid(n.id);if(!e)throw"term not found for one of variant2samples.twLst: "+n.id;if(n.term=e,!n.q)throw"tw.q{} missing for one of variant2samples.twLst: "+n.id}}if(e.sunburst_twLst){if(!Array.isArray(e.sunburst_twLst))throw".sunburst_twLst[] not array from variant2samples";if(0==e.sunburst_twLst.length)throw".sunburst_twLst[] empty array from variant2samples";if(!t.cohort||!t.cohort.termdb)throw"ds.cohort.termdb missing when variant2samples.sunburst_twLst is in use";for(const n of e.sunburst_twLst){if(!n.id)throw"tw.id missing from one of variant2samples.sunburst_twLst[]";const e=t.cohort.termdb.q.termjsonByOneid(n.id);if(!e)throw"term not found for one of variant2samples.sunburst_twLst: "+n.id;if(n.term=e,!n.q)throw"tw.q{} missing for one of variant2samples.sunburst_twLst: "+n.id}}if(e.gdcapi);else{var n,f,y,v,b,_,w;let e=!1;if(null!==(n=t.queries)&&void 0!==n&&null!==(f=n.snvindel)&&void 0!==f&&null!==(y=f.byrange)&&void 0!==y&&null!==(v=y._tk)&&void 0!==v&&v.samples&&(e=!0),null!==(b=t.queries)&&void 0!==b&&null!==(_=b.svfusion)&&void 0!==_&&null!==(w=_.byrange)&&void 0!==w&&w.samples&&(e=!0),!e)throw"cannot find a sample source from ds.queries{}"}if(e.get=async e=>await async function(t,e){!function(t,e){if("samples"==t.get){var n,r;const o=null===(n=e.queries)||void 0===n||null===(r=n.snvindel)||void 0===r?void 0:r.byrange;o&&(o.bcffile||o.chr2bcffile)&&o._tk.format&&(t.addFormatValues=!0)}}(t,e);const n=await async function(t,e){var n;const r=t.twLst?t.twLst.slice():[];if(e.variant2samples.gdcapi)return await o(t,r,e,t.geneTwLst);if(t.ssm_id_lst)return await async function(t,e,n){const r=new Map;for(const e of t.ssm_id_lst.split(",")){const o=e.split(s);if(4!=o.length){if(6!=o.length)throw"unknown format of ssm id";{if(!n.queries.svfusion||!n.queries.svfusion.byrange)throw"queries.svfusion.byrange missing when id has 6 fields";const[e,i,s,c,u,f]=o,h=decodeURIComponent(f),p=Number(e);if(p!=l&&p!=a)throw"dt not sv/fusion";const m=Number(s);if(Number.isNaN(m))throw"position not integer";const g=Number(u);if(Number.isNaN(g))throw"pairlstIdx not integer";const y=Object.assign({},t,{rglst:[{chr:i,start:m,stop:m+1}]}),v=await n.queries.svfusion.byrange.get(y);for(const t of v)t.dt==p&&t.pos==m&&t.strand==c&&t.pairlstIdx==g&&t.mname==h&&d(t.samples,r,t.ssm_id)}}else{if(!n.queries.snvindel||!n.queries.snvindel.byrange)throw"queries.snvindel.byrange missing when id has 4 fields";const[e,i,s,a]=o,l=Number(i);if(Number.isNaN(l))throw"no integer position for snvindel from ssm id";const c=Object.assign({},t,{rglst:[{chr:e,start:l,stop:l}]}),u=await n.queries.snvindel.byrange.get(c);for(const t of u)t.pos==l&&t.ref==s&&t.alt==a&&d(t.samples,r,t.ssm_id)}}return h(r,e,n),[...r.values()]}(t,r,e);if(t.rglst)return await p(t,r,e);if(t.geneTwLst){if("object"!=typeof t.genome)throw"serverside genome obj needed";t.rglst=[];for(const e of t.geneTwLst)if(e.term.chr&&e.term.start&&e.term.stop)t.rglst.push({chr:e.term.chr,start:e.term.start,stop:e.term.stop});else{const n=c.getResult(t.genome,{deep:1,input:e.term.name});if(n.gmlst){const e=n.gmlst[0];t.rglst.push({chr:e.chr,start:e.start,stop:e.stop})}}const n=await p(t,r,e);return delete t.rglst,n}if(null==e||null===(n=e.cohort)||void 0===n||!n.termdb)throw"unable to do sql query: .cohort.termdb missing for ds";const i={ds:e,filter:t.filter||t.filterObj},f=await u(i,t.twLst),m=[];for(const e in f.samples){const n=f.samples[e];n.sample_id=n.sample,delete n.sample;for(const e of t.twLst)n[e.term.id]&&(n[e.term.id]=n[e.term.id].key);m.push(n)}return m}(t,e);if(t.get==e.variant2samples.type_samples){var f,y,v;return!t.useIntegerSampleId&&null!=e&&null!==(f=e.cohort)&&void 0!==f&&null!==(y=f.termdb)&&void 0!==y&&null!==(v=y.q)&&void 0!==v&&v.id2sampleName&&n.forEach((t=>t.sample_id=e.cohort.termdb.q.id2sampleName(t.sample_id))),n}if(t.get==e.variant2samples.type_sunburst)return await async function(t,e,n){var o,i;const s=r(t,n.twLst.map((t=>({k:t.id}))));for(const t of s)delete t.lst;if(null!=e&&null!==(o=e.cohort)&&void 0!==o&&null!==(i=o.termdb)&&void 0!==i&&i.termid2totalsize2){const t=await g(n.twLst,e,n,s);await async function(t,e,n){for(const r of t){if(!r.id0)continue;if(!r.v0)continue;const t=n.cohort.termdb.useLower?r.v0.toLowerCase():r.v0;if(!r.id1){const n=e.find((e=>null==e.id1&&e.v0==t));n&&(r.cohortsize=n.count);continue}if(!r.v1)continue;const o=n.cohort.termdb.useLower?r.v1.toLowerCase():r.v1;if(!r.id2){const n=e.find((e=>null==e.id2&&e.v0==t&&e.v1==o));n&&(r.cohortsize=n.count);continue}if(!r.v2)continue;const i=n.cohort.termdb.useLower?r.v2.toLowerCase():r.v2;if(!r.id3){const e=crosstabL2.find((e=>e.v0==t&&e.v1==o&&e.v2==i));e&&(r.cohortsize=e.count)}}}(s,t,e)}return s}(n,e,t);if(t.get==e.variant2samples.type_summary){const r=await async function(t,e,n){if(!n.twLst)throw"q.twLst[] missing for make_summary()";const r=[];for(const e of n.twLst)if(e.term)if("categorical"==e.term.type){const n=m(t,e.id);r.push({termid:e.id,termname:e.term.name,numbycategory:[...n].sort(((t,e)=>e[1]-t[1]))})}else{if("integer"!=e.term.type&&"float"!=e.term.type)throw"unknown term type";{const n=await i(e.term,t);r.push({termid:e.id,termname:e.term.name,density_data:n})}}if(e.cohort.termdb.termid2totalsize2){const t=await e.cohort.termdb.termid2totalsize2.get(n.twLst,n);for(const{termid:e,numbycategory:n}of r){if(!n)continue;const r=t.get(e);if(r)for(const t of n){const e=r.find((e=>e[0].toLowerCase()==t[0].toLowerCase()));e&&t.push(e[1])}}}return r}(n,e,t);return r}throw"unknown get type"}(e,t),e.url&&!e.url.base)throw".variant2samples.url.base missing"}}function d(t,e,n){for(const r of t){e.has(r.sample_id)||(r.ssm_id_lst=[],r.formatK2v&&(r.ssmid2format={}),e.set(r.sample_id,r));const t=e.get(r.sample_id);t.ssm_id_lst.push(n),t.ssmid2format&&(t.ssmid2format[n]=r.formatK2v)}}function h(t,e,n){if(e)for(const r of t.values())for(const t of e){const e=n.cohort.termdb.q.getSample2value(t.id,r.sample_id);e[0]&&(r[t.id]=e[0].value)}}async function p(t,e,n){const r=new Map;if(n.queries.snvindel){const e=await n.queries.snvindel.byrange.get(t);for(const t of e)d(t.samples,r,t.ssm_id)}if(n.queries.svfusion){const e=await n.queries.svfusion.byrange.get(t);for(const t of e)d(t.samples,r,t.ssm_id)}return h(r,e,n),[...r.values()]}function m(t,e){const n=new Map;if("sample_id"in t[0]){for(const r of t){const t=r[e];t&&(n.has(t)||n.set(t,new Set),n.get(t).add(r.sample_id))}const r=new Map;for(const[t,e]of n)r.set(t,e.size);return r}if("case_uuid"in t[0]){for(const r of t){const t=r[e];t&&(n.has(t)||n.set(t,new Set),n.get(t).add(r.case_uuid))}const r=new Map;for(const[t,e]of n)r.set(t,e.size);return r}for(const e of t){const t=e[term.id];t&&n.set(t,1+(n.get(t)||0))}return n}async function g(t,e,n,r){var o,i;if(0==t.length)throw"zero terms for crosstab";if(t.length>3)throw"crosstab will not work with more than 3 levels";const s=[],a=new Map;for(const e of t)a.set(e.id,new Set);const l=!r;if(r)for(const n of r){if(n.id0){if(!n.v0)continue;a.get(n.id0).add(e.cohort.termdb.useLower?n.v0.toLowerCase():n.v0)}if(n.id1&&t[1]){if(!n.v1)continue;a.get(n.id1).add(e.cohort.termdb.useLower?n.v1.toLowerCase():n.v1)}if(n.id2&&t[2]){if(!n.v2)continue;a.get(n.id2).add(e.cohort.termdb.useLower?n.v2.toLowerCase():n.v2)}}const c=t[0].id;{const n=await e.cohort.termdb.termid2totalsize2.get([t[0]]);for(const[t,r]of n.get(c)){const n=e.cohort.termdb.useLower?t.toLowerCase():t;l?(a.get(c).add(n),s.push({count:r,id0:c,v0:n})):a.get(c).has(n)&&s.push({count:r,id0:c,v0:n})}}const u=null==t||null===(o=t[1])||void 0===o?void 0:o.id;if(u){const n=[];for(const r of a.get(c))n.push(e.cohort.termdb.termid2totalsize2.get([t[1]],{tid2value:{[c]:r}},r));const r=await Promise.all(n);for(const[t,n]of r)for(const[r,o]of t.get(u)){const t=e.cohort.termdb.useLower?r.toLowerCase():r;l?(a.get(u).add(t),s.push({count:o,id0:c,v0:n,id1:u,v1:t})):a.get(u).has(t)&&s.push({count:o,id0:c,v0:n,id1:u,v1:t})}}const f=null==t||null===(i=t[2])||void 0===i?void 0:i.id;if(f){const r=[];for(const o of a.get(c))for(const i of a.get(u)){JSON.parse(JSON.stringify(n));r.push(e.cohort.termdb.termid2totalsize2.get([t[2]],{tid2value:{[c]:o,[u]:i}},{v0:o,v1:i}))}const o=await Promise.all(r);for(const[t,n]of o)for(const[t,r]of v2counts.get(f)){const o=e.cohort.termdb.useLower?t.toLowerCase():t;l?(a.get(f).add(o),s.push({count:r,id0:c,v0:n.v0,id1:u,v1:n.v1,id2:f,v2:o})):a.get(f).has(o)&&s.push({count:r,id0:c,v0:n.v0,id1:u,v1:n.v1,id2:f,v2:o})}}return s}},5728:(t,e)=>{function n(t,e,n){const r=[];for(const o of t){const t=new Map,i=[];for(const r of o.samples){const o=n.sample2term.get(r);if(o){const n=o.get(e);null==n?i.push(r):(t.has(n)||t.set(n,[]),t.get(n).push(r))}else i.push(r)}const s=[...t].sort(((t,e)=>e[1].length-t[1].length));for(const t of s){const e={value:t[0],samples:t[1],children:[]};r.push(e),o.children&&o.children.push(e)}if(i.length){const t={isgap:!0,samples:i,children:[]};r.push(t),o.children&&o.children.push(t)}}return r}e.g=t=>{!function(t){if(!t.sample2term)throw".sample2term missing";if(!t.terms)throw".terms[] missing";if(!t.config)throw".config{} missing"}(t);const e=function(t){const e=new Map;for(const n of t.sample2term.values())for(const t of n.keys())e.set(t,1+(e.get(t)||0));if(t.config.termidorder){const n=[];for(const r of t.config.termidorder){const t=e.get(r);null!=t&&n.push({id:r,samplecount:t})}return n}return[...e].sort(((t,e)=>e[1]-t[1])).map((t=>({id:t[0],samplecount:t[1]})))}(t),r=function(t,e){const n=[];for(const[r,o]of t.sample2term)e.find((t=>o.has(t.id)))&&n.push(r);return n}(t,e);return function(t,e,r){for(const[o,i]of e.entries()){const s=0==o?[{samples:r}]:e[o-1].blocks;i.blocks=n(s,i.id,t)}}(t,e,r),function(t,e){for(const n of t){const t=e.terms.find((t=>t.id==n.id));n.name=t.name;for(const e of n.blocks)e.samplecount=e.samples.length,delete e.samples,e.value&&(e.color=t.values[e.value].color)}}(e,t),function(t){for(let e=t.length-1;e>=0;e--){const n=t[e];for(const t of n.blocks){let e=0;for(const n of t.children)e+=n.symbolwidth;const n=t.isgap?1:t.samplecount.toString().length;t.symbolwidth=Math.max(n,e)}}let e=0;for(const n of t[0].blocks){n.x=e;let t=e;for(const e of n.children)e.x=t,t+=e.symbolwidth;e+=n.symbolwidth}for(let e=1;e<t.length;e++)for(const n of t[e].blocks){let t=n.x;for(const e of n.children)e.x=t,t+=e.symbolwidth}for(const e of t)delete e.children}(e),e}},334:(t,e,n)=>{var r;const o=n(7147),i=n(1017),s=process.cwd()?process.cwd()+"/serverconfig.json":"",a=i.join(__dirname,"../serverconfig.json"),l=i.join(__dirname,"../../serverconfig.json"),c=s&&o.existsSync(s)?s:o.existsSync(a)?a:o.existsSync(l)?l:"";let u;if(!c)throw"missing serverconfig.json";try{const t=o.readFileSync(c,{encoding:"utf8"});u=JSON.parse(t)}catch(t){throw`Error reading or parsing ${c}:`+t}if(u.port||(u.port=process.env.PP_PORT||3e3),u.tabix||(u.tabix="tabix"),u.samtools||(u.samtools="samtools"),u.bcftools||(u.bcftools="bcftools"),u.hicstraw||(u.hicstraw="straw"),u.bigwigsummary||(u.bigwigsummary="bigWigSummary"),u.bigBedToBed||(u.bigBedToBed="bigBedToBed"),u.bigBedInfo||(u.bigBedInfo="bigBedInfo"),u.bigBedNamedItems||(u.bigBedNamedItems="bigBedNamedItems"),u.clustalo||(u.clustalo="clustalo"),u.Rscript||(u.Rscript="Rscript"),!("allow_env_overrides"in u)&&u.debugmode&&(u.allow_env_overrides=!0),!u.binpath){const t=process.argv.find((t=>t.includes("/build")));if(t)u.binpath=t.split("/build")[0]+"/server";else{if(process.argv.find((t=>t.includes(".spec.js"))))u.binpath=i.dirname(__dirname);else{const t=process.argv.find((t=>t.endsWith("/bin.js")||t.endsWith("/server.js")||t.endsWith("/proteinpaint")||t.endsWith("/proteinpaint-server")));if(t)try{const e=o.realpathSync(t);u.binpath=i.dirname(e)}catch(t){throw t}else if(o.existsSync("./server"))u.binpath=o.realpathSync("./server");else if(o.existsSync("./src"))u.binpath=o.realpathSync("./src/..");else if(__dirname.includes("/server/"))u.binpath=__dirname.split("/server/")[0]+"/server";else{if(!__dirname.includes("/proteinpaint"))throw"unable to determine the serverconfig.binpath";u.binpath=__dirname}}}}if(u.debugmode){const t=[],e=i.join(u.binpath,"src/test/routes"),n=["gdc.js","specs.js","readme.js"];if(u.routeSetters)for(const r of u.routeSetters)if(!n.includes(r))if(o.existsSync(r))t.push(r);else if(o.existsSync(`${e}/${r}`))t.push(`${e}/${r}`);else{const e=i.join(u.binpath,r);o.existsSync(e)&&t.push(e)}for(const r of n){const n=`${e}/${r}`;!t.includes(n)&&o.existsSync(n)&&t.push(n)}u.routeSetters=t}if(u.allow_env_overrides){if(process.env.PP_URL&&(u.URL=process.env.URL),"PP_BASEPATH"in process.env&&(u.basepath=process.env.PP_BASEPATH),o.existsSync("./.ssl")&&!u.ssl){u.ssl={};const t=o.readdirSync("./.ssl");for(const e of t)e.endsWith(".key")&&(u.ssl.key=process.cwd()+"/.ssl/"+e),e.endsWith(".crt")&&(u.ssl.cert=process.cwd()+"/.ssl/"+e)}"PP_BACKEND_ONLY"in process.env&&(u.backend_only=1==+process.env.PP_BACKEND_ONLY||"true"===process.env.PP_BACKEND_ONLY)}if(null!==(r=process.env.PP_MODE)&&void 0!==r&&r.startsWith("container")&&Object.assign(u,{port:3e3,tpmasterdir:"/home/root/pp/tp",cachedir:"/home/root/pp/cache",hicstraw:"/home/root/pp/tools/straw",bigwigsummary:"/home/root/pp/tools/bigWigSummary",bigBedToBed:"/home/root/pp/tools/bigBedToBed",bigBedNamedItems:"/home/root/pp/tools/bigBedNamedItems",bigBedInfo:"/home/root/pp/tools/bigBedInfo"}),u.features||(u.features={}),!u.backend_only&&o.existsSync(i.join(process.cwd(),"./public"))){const t=i.join(u.binpath,"cards");u.cards||(u.cards={target:t,path:"cards"});const e=u.cards,n=i.join(process.cwd(),"./public/",e.path);let r;try{r=o.lstatSync(n)}catch(t){r=!1}!e.path||o.existsSync(n)||r||(e.target||(e.target=t),o.symlink(u.cards.target,n,"dir",console.error))}if(o.existsSync("./public/rev.txt")){const t=o.readFileSync("./public/rev.txt",{encoding:"utf8"}).trim().split(" ")[1];t&&(u.commitHash=t)}if(o.existsSync("./package.json")){const t=o.readFileSync("./package.json",{encoding:"utf8"});u.version=JSON.parse(t).version}t.exports=u},7395:(t,e,n)=>{const r=n(9699),o=n(7147),i=n(4521),s=n(502),a=n(7346),l=n(6778),c=n(3856),{schemeCategory10:u}=n(895),{schemeCategory20:f}=n(4052);function d(t){const e=t.toString(16);return 1==e.length?"0"+e:e}function h(t,e,n){return d(t)+d(e)+d(n)}function p(t){if(!t.cellfile)throw"cellfile missing";{const[e,n,o]=r.fileurl({query:{file:t.cellfile}});if(e)throw"cellfile error: "+e;t.cellfile=n}if(!t.delimiter)throw"delimiter missing";if(!Number.isInteger(t.barcodecolumnidx))throw"barcodecolumnidx missing";if(!Number.isInteger(t.categorycolumnidx))throw"categorycolumnidx missing";return new Promise(((e,n)=>{const r=new Map,s=i.createInterface({input:o.createReadStream(t.cellfile)});let a=!0;s.on("line",(e=>{if(a)return void(a=!1);const n=e.split(t.delimiter);r.set(n[t.barcodecolumnidx],{category:n[t.categorycolumnidx],expvalue:0})})),s.on("close",(()=>{e(r)}))}))}e.handle_singlecell_closure=t=>async(e,n)=>{try{const d=e.query,m=t[d.genome];if(!m)throw"invalid genome";if(d.getpcd)return void await async function(t,e){const n={},d=await async function(t,e){if(!t.textfile)throw".textfile missing";{const[e,n,o]=r.fileurl({query:{file:t.textfile}});if(e)throw".textfile error: "+e;if(!o){if(await c.file_not_exist(n))throw"file not exist: "+t.textfile;if(await c.file_not_readable(n))throw"file not readable: "+t.textfile}t.textfile=n}let n,d,p,m,g;if(t.getpcd.category_autocolor){const e=t.getpcd.values_count&&t.getpcd.values_count<=10?u:f;n=s.scaleOrdinal(e),p={},m={}}else if(t.getpcd.category_customcolor){const e=s.scaleOrdinal(f);y=t.getpcd.cat_values,v=e,n=t=>{let e=!1;for(const n of y)if(n.value==t)return e=!0,n.color;if(!e)return v(t)},p={},m={},g={}}else if(t.getpcd.gene_expression){const n=t.getpcd.gene_expression;if(!n.file)throw"gene_expression.file missing";{const[t,e,o]=r.fileurl({query:{file:n.file}});if(t)throw t;n.file=e}if(!Number.isInteger(n.barcodecolumnidx))throw"gene_expression.barcodecolumnidx missing";if(!n.chr)throw"gene_expression.chr missing";if(!n.start)throw"gene_expression.start missing";if(!n.stop)throw"gene_expression.stop missing";if(!n.genename)throw"gene_expression.genename missing";if(!n.autoscale)throw"gene_expression: unknown scaling method";if(!n.color_min)throw"gene_expression.color_min missing at autoscale";if(!n.color_max)throw"gene_expression.color_max missing at autoscale";const o=(n.nochr?n.chr.replace("chr",""):n.chr)+":"+n.start+"-"+n.stop,i=new Map;d=new Map;let s=0,u=0;if(e.numbercellwithgeneexp=0,e.numbercelltotal=0,await c.get_lines_bigfile({args:[n.file,o],callback:t=>{const r=JSON.parse(t.split("\t")[3]);r.gene==n.genename&&Number.isFinite(r.value)&&(e.numbercellwithgeneexp++,n.autoscale&&(s=Math.min(s,r.value),u=Math.max(u,r.value)),i.set(r.sample,r.value))}}),n.autoscale){e.minexpvalue=s,e.maxexpvalue=u;const t=l.interpolateRgb(n.color_min,n.color_max);for(const[e,n]of i){const r=a.color(t((n-s)/(u-s)));d.set(e,Number.parseInt(h(r.r,r.g,r.b),16))}}}var y,v;return new Promise(((r,s)=>{const l=[],c=i.createInterface({input:o.createReadStream(t.textfile)});let u=!0,f=0,g=0;c.on("line",(r=>{if(u)return void(u=!1);const o=r.split(t.delimiter),i=[];for(const e of t.getpcd.coord)i.push(o[e]),f=Math.max(f,o[e]),g=Math.min(g,o[e]);if(2==t.getpcd.coord.length&&i.push("0"),n){const e=o[t.getpcd.category_index],r=n(e);if(t.hidden_types.includes(e))if(t.background_color){const e=a.color(t.background_color),n=Number.parseInt(h(e.r,e.g,e.b),16);i.push(n)}else i.push(16777215);else i.push(Number.parseInt(r.slice(1),16));p&&(p[e]=r),m&&(m[e]=e in m?m[e]+1:1)}else if(d){e.numbercelltotal++;const n=o[t.getpcd.gene_expression.barcodecolumnidx];let r=d.get(n);if(void 0===r)if(t.getpcd.gene_expression.color_no_exp){const e=a.color(t.getpcd.gene_expression.color_no_exp);r=Number.parseInt(h(e.r,e.g,e.b),16)}else r="2894892";i.push(r)}l.push(i.join(" "))})),c.on("close",(()=>{p&&(t.getpcd.category_customorder&&(p=function(t,e){let n={};const r=Object.keys(t).length;for(var o=1;o<=r;o++){const r=e.find((t=>{if(t.order==o)return t.value}));r&&(n[r.value]=t[r.value])}for(const r of e)r.order||(n[r.value]=t[r.value]);for(const r in t){e.find((t=>{if(t.value==JSON.stringify(r))return!0}))||(n[r]=t[r])}return n}(p,t.getpcd.cat_values)),e.category2color=p,e.categorycount=m),e.data_sphere_r=Math.max(Math.abs(f),Math.abs(g)),r(l)}))}))}(t,n),p="# .PCD v.7 - Point Cloud Data file format\nVERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F F\nCOUNT 1 1 1 1\nWIDTH 1200\nHEIGHT 800\nVIEWPOINT 0 0 0 1 0 0 0\nPOINTS 960000\nDATA ascii\n";n.pcddata=p+d.join("\n"),e.send(n)}(d,n);if(d.getgeneboxplot)return void await async function(t,e,n){const o=t.getgeneboxplot,i=t.getgeneboxplot.values_count&&t.getgeneboxplot.values_count<=10?s.scaleOrdinal(u):s.scaleOrdinal(f);if(!o.expfile)throw"getgeneboxplot.expfile missing";{const[t,e,n]=r.fileurl({query:{file:o.expfile}});if(t)throw"getgeneboxplot.expfile error: "+t;o.expfile=e}if(!o.chr)throw"getgeneboxplot.chr missing";if(!o.start)throw"getgeneboxplot.start missing";if(!o.stop)throw"getgeneboxplot.stop missing";if(!o.genename)throw"getgeneboxplot.genename missing";const a=await p(o),l=(o.nochr?o.chr.replace("chr",""):o.chr)+":"+o.start+"-"+o.stop;let d=0,h=0;await c.get_lines_bigfile({args:[o.expfile,l],callback:t=>{const e=JSON.parse(t.split("\t")[3]);if(e.gene!=o.genename)return;if(!e.sample)return;if(!Number.isFinite(e.value))return;const n=a.get(e.sample);n&&(n.expvalue=e.value,d=Math.min(d,e.value),h=Math.max(h,e.value))}});const m=new Map;for(const[t,e]of a)m.has(e.category)||m.set(e.category,[]),o.exclude_cells&&0==parseInt(e.expvalue)||m.get(e.category).push({value:e.expvalue});const g=[],y=(v=s.scaleLinear().domain([d,h]).ticks(20),t=>{const e=[];for(let t=1;t<v.length;t++)e.push(0);for(const n of t)for(let t=1;t<v.length;t++)if(n.value<=v[t]){e[t-1]++;break}return e});var v;for(const[t,e]of m){e.sort(((t,e)=>t.value-e.value));const n=r.boxplot_getvalue(e);delete n.out;const o=i(t);n.category=t,n.color=o,n.numberofcells=e.length,n.density=y(e),g.push(n)}let b=[];if(t.getgeneboxplot.cat_values){const e=Object.keys(t.getgeneboxplot.cat_values).length;for(var _=1;_<=e;_++){const e=t.getgeneboxplot.cat_values.find((t=>{if(t.order==_)return t.value}));e&&b.push(g.filter((t=>t.category==e.value))[0])}for(const e of t.getgeneboxplot.cat_values)e.order||b.push(g.filter((t=>t.category==e.value))[0]);for(const e of g){t.getgeneboxplot.cat_values.find((t=>{if(t.value==e.category)return!0}))||b.push(e)}for(const e of b){const n=t.getgeneboxplot.cat_values.find((t=>{if(t.value==e.category)return t}));n&&n.color&&(e.color=n.color)}}else b=g;n.send({boxplots:b,minexpvalue:d,maxexpvalue:h})}(d,0,n);if(d.getheatmap)return void await async function(t,e,n){const o=t.getheatmap,i=[];if(!o.expfile)throw"getgeneboxplot.expfile missing";{const[t,e,n]=r.fileurl({query:{file:o.expfile}});if(t)throw"getgeneboxplot.expfile error: "+t;o.expfile=e}o.gene_list.forEach((t=>{if(!t.chr)throw"getgeneboxplot.chr missing";if(!t.start)throw"getgeneboxplot.start missing";if(!t.stop)throw"getgeneboxplot.stop missing";if(!t.gene)throw"getgeneboxplot.genename missing"}));const s=await p(o);for(const t of o.gene_list){const e=(t.nochr?t.chr.replace("chr",""):t.chr)+":"+t.start+"-"+t.stop;let n=0,r=0;const a=t.gene;await c.get_lines_bigfile({args:[o.expfile,e],callback:e=>{const o=JSON.parse(e.split("\t")[3]);if(o.gene.toUpperCase()!==t.gene.toUpperCase())return;if(!o.sample)return;if(!Number.isFinite(o.value))return;const i=s.get(o.sample);i&&(i.expvalue=o.value,n=Math.min(n,o.value),r=Math.max(r,o.value))}});const l=new Map;for(const[t,e]of s)l.has(e.category)||l.set(e.category,[]),l.get(e.category).push({value:e.expvalue});const u=[];for(const[t,e]of l){let n=0;for(const t of e)n+=t.value;const r=e.length,o=(n/r).toFixed(3);u.push({category:t,mean:o,numberofcells:r})}i.push({genename:a,heatmap:u})}n.send({gene_heatmap:i})}(d,0,n)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}},1711:(t,e,n)=>{"use strict";n.r(e),n.d(e,{barchart_data:()=>f,getOrderedLabels:()=>h,handle_request_closure:()=>u});const r=n(9699),o=(n(1017),n(3856)),i=n(5346),s=(n(8288).format(".3r"),n(1271).run_rust),{getData:a}=n(2974),{mclass:l,dt2label:c}=n(2273);function u(t){return async(e,n)=>{const r=e.query;for(const t of[0,1,2]){const e="term"+t,n=e+"_id";"string"==typeof r[n]?r[n]=decodeURIComponent(r[n]):"string"==typeof r[e]&&(r[e]=JSON.parse(decodeURIComponent(r[e])));const o=e+"_q";"string"==typeof r[o]&&(r[o]=JSON.parse(decodeURIComponent(r[o])))}try{const e=t[r.genome];if(!e)throw"invalid genome";const o=e.datasets[r.dslabel];if(!o)throw"invalid dslabel";if(!o.cohort)throw"ds.cohort missing";const i=o.cohort.termdb;if(!i)throw"no termdb for this dataset";const a=await f(r,o,i);r.term2_q&&await async function(t,e){t.tests={};for(const n of t.charts){const r={};for(const t of n.serieses)for(const e of t.data)r[e.dataId]=void 0===r[e.dataId]?e.total:r[e.dataId]+e.total;const o=[];let i=0;const a=new Map;for(const t of n.serieses)for(const e of t.data){const s=e.total,l=r[e.dataId]-e.total,c=t.total-e.total,u=n.total-r[e.dataId]-(t.total-e.total),f=t.seriesId,d=e.dataId;o.push({index:i,n1:s,n2:l,n3:c,n4:u}),a.set(i,{seriesId:f,dataId:d}),i++}const l={input:o},c=e.cohort.termdb.multipleTestingCorrection;c&&(l.mtc=c.method,c.skipLowSampleSize&&(l.skipLowSampleSize=c.skipLowSampleSize));const u=await s("fisher",JSON.stringify(l)),f=[];for(const t of JSON.parse(u)){const e=a.get(t.index).seriesId,n=a.get(t.index).dataId,r=t.n1,o=t.n2,i=t.n3,s=t.n4,l=t.p_value,c="chisq"===t.fisher_chisq,u=null===l,d=t.adjusted_p_value,h=f.find((t=>t.term1comparison===e));h?h.term2tests.push({term2id:n,pvalue:l,adjusted_p_value:d,tableValues:{R1C1:r,R2C1:o,R1C2:i,R2C2:s},isChi:c,skipped:u}):f.push({term1comparison:e,term2tests:[{term2id:n,pvalue:l,adjusted_p_value:d,tableValues:{R1C1:r,R2C1:o,R1C2:i,R2C2:s},isChi:c,skipped:u}]})}t.tests[n.chartId]=f}}(a.data,o),n.send(a)}catch(t){n.send({error:t.message||t}),t.stack&&console.log(t.stack)}}}async function f(t,e,n){if(t.ds=e,t.ssid){const[e,n]=await o.loadfile_ssid(t.ssid);t.sample2gt=e,t.genotype2sample=n}const s=+new Date;t.results={};const u=new Map;for(let e=0;e<=2;e++){let n=null;if(t[`term${e}_id`]){const r=t[`term${e}_id`];n={id:r,q:t[`term${e}_q`],term:{id:r}}}else t[`term${e}`]&&(n={term:t[`term${e}`],q:t[`term${e}_q`]});n&&u.set(e,n)}const f=[...u.values()],p=await a({filter:t.filter,terms:f},t.ds,t.genome),m=new Map,g=[];var y,v,b,_;if(p.samples)if("geneVariant"==(null===(y=u.get(1))||void 0===y||null===(v=y.term)||void 0===v?void 0:v.type)||"geneVariant"==(null===(b=u.get(2))||void 0===b||null===(_=b.term)||void 0===_?void 0:_.type))!function(t,e,n,r,o){var i,s,a,u;e.push([]);let f=1;const d=t.get(1)?t.get(1).term:null,h=null!=d&&d.id?d.id:null==d?void 0:d.name;h&&null!==(i=n.refs.byTermId[h])&&void 0!==i&&i.bins?e.push(null===(s=n.refs.byTermId[h])||void 0===s?void 0:s.bins):e.push([]);const p=t.get(2)?t.get(2).term:null,m=null!=p&&p.id?p.id:null==p?void 0:p.name;m&&null!==(a=n.refs.byTermId[m])&&void 0!==a&&a.bins?e.push(null===(u=n.refs.byTermId[m])||void 0===u?void 0:u.bins):e.push([]);for(const[e,i]of Object.entries(n.samples)){var g,y,v,b;const n=parseInt(e);if("geneVariant"==(null===(g=t.get(1))||void 0===g||null===(y=g.term)||void 0===y?void 0:y.type)){const t=[],e=i[h];for(const r of e.values)if(t.some((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))){const e=t.filter((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))[0];if("object"!=typeof e.item.key1){const t=e.item.key1;e.item.key1={},e.item.key1[t]=1}e.item.key1[l[r.class].label]=e.item.key1[l[r.class].label]?e.item.key1[l[r.class].label]+1:1}else{var _,w,x;const e={sample:f,name:o.sampleId2Name.get(n)};e.key1=l[r.class].label,e.val1=l[r.class].label;const s=null===(_=o.assayAvailability)||void 0===_||null===(w=_.byDt)||void 0===w||null===(x=w[r.dt])||void 0===x?void 0:x.byOrigin;var k;if(s)e.key0=e.val0=((null===(k=s[r.origin])||void 0===k?void 0:k.label)||r.origin)+" "+c[r.dt];else e.key0=e.val0=c[r.dt];e.key2=i[m]?i[m].key:"",e.val2=i[m]?i[m].value:"",t.push({value:r,item:e})}for(const e of t){if("object"==typeof e.item.key1){let t="";for(const[n,r]of Object.entries(e.item.key1))t+=`${n}(${r})+`;e.item.key1=t.slice(0,-1),e.item.val1=t.slice(0,-1)}r.set(f.toString(),e.item),f++}}else if("geneVariant"==(null===(v=t.get(2))||void 0===v||null===(b=v.term)||void 0===b?void 0:b.type)){const t=[],e=i[m],s=i[h];for(const r of e.values)if(t.some((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))){const e=t.filter((t=>t.value.dt==r.dt&&(!r.origin||r.origin==t.value.origin)))[0];if("object"!=typeof e.item.key2){const t=e.item.key2;e.item.key2={},e.item.key2[t]=1}e.item.key2[l[r.class].label]=e.item.key2[l[r.class].label]?e.item.key2[l[r.class].label]+1:1}else{var q,N,S;const e={sample:f,name:o.sampleId2Name.get(n)};e.key1=s.key,e.val1=s.value;const i=null===(q=o.assayAvailability)||void 0===q||null===(N=q.byDt)||void 0===N||null===(S=N[r.dt])||void 0===S?void 0:S.byOrigin;var A;if(i)e.key0=e.val0=((null===(A=i[r.origin])||void 0===A?void 0:A.label)||r.origin)+" "+c[r.dt];else e.key0=e.val0=c[r.dt];e.key2=l[r.class].label,e.val2=l[r.class].label,t.push({value:r,item:e})}for(const e of t){if("object"==typeof e.item.key2){let t="";for(const[n,r]of Object.entries(e.item.key2))t+=`${n}(${r})+`;e.item.key2=t.slice(0,-1),e.item.val2=t.slice(0,-1)}r.set(f.toString(),e.item),f++}}}}(u,g,p,m,e);else for(let t=0;t<=2;t++){var w,x,k;const n=null===(w=u.get(t))||void 0===w?void 0:w.q,r=u.get(t)?u.get(t).term:null,o=null!=r&&r.id?r.id:null==r?void 0:r.name;if(o&&null!==(x=p.refs.byTermId[o])&&void 0!==x&&x.bins?g.push(null===(k=p.refs.byTermId[o])||void 0===k?void 0:k.bins):g.push([]),null!=n&&n.binColored)for(const e of g[t]){const t=n.binColored;e.start==t.start&&e.stop==t.stop&&(e.color=t.color)}for(const[n,r]of Object.entries(p.samples)){let i;if(m.get(n))i=m.get(n);else if(!m.has(n)){const t=parseInt(n);i={sample:t,name:e.sampleId2Name.get(t)},m.set(n,i)}if(i)if(o){const e=r[o];e?(i[`key${t}`]=e.key,i[`val${t}`]=e.value):m.set(n,null)}else i[`key${t}`]="",i[`val${t}`]=""}}t.results.lst=[...m.values()].filter((t=>null!==t)),t.results.bins=g;const q=+new Date,N=function(t,e,n,s){const a=[0,1,2].map((e=>{const r=function(t,e,n){const r=t["term"+n+"_id"];let o={};t[r]||r?o=e.q.termjsonByOneid(r):t[`term${n}`]&&(o=t[`term${n}`]);const i="integer"==o.type||"float"==o.type,s=o.values?Object.keys(o.values).filter((t=>o.values[t].uncomputable)).map((t=>+t)):[],a=t=>i&&!s.includes(t),l=t["term"+n+"_q"]?t["term"+n+"_q"]:{};return{term:o,isComputableVal:a,q:l}}(t,n,e);r.q.index=e;const o=t.results.bins[e];return Object.assign(r,{key:"key"+e,val:"val"+e,nval:"nval"+e,bins:o,q:r.q,orderedLabels:h(r.term,o,r.q)})}));return new i({data:e,seed:'{"results": {"charts": [], "refs":{}}}',template:d,"=":{prep(t){for(const e of a)"condition"==e.term.type?(t[e.key]=e.q.bar_by_grade&&t[e.key]in e.term.values?e.term.values[t[e.key]].label:t[e.key],t[e.val]=t[e.key]):"float"!=e.term.type&&"integer"!=e.term.type||e.isComputableVal(t[e.val])&&(t[e.nval]=t[e.val]);return!0},sampleCount:(t,e)=>e.self.samples?e.self.samples.size:void 0,maxSeriesTotal(t,e){let n=0;for(const t of e.self.serieses)t&&t.total>n&&(n=t.total);return n},maxAcrossCharts(t,e){let n=0;for(const t of e.self.charts)t.maxSeriesTotal>n&&(n=t.maxSeriesTotal);return n},boxplot(t,e){const n=e.self.values;if(!n||!n.length)return;n.sort(((t,e)=>t-e));const o=r.boxplot_getvalue(n.map((t=>({value:+t}))));o.mean=e.self.sum/n.length;let i=0;for(const t of n)i+=Math.pow(t-o.mean,2);return o.sd=Math.sqrt(i/(n.length-1)),o.min=e.self.min,o.max=e.self.max,o},getAF(e,n){if(s.track&&s.track.vcf&&s.track.vcf.termdb_bygenotype&&s.track.vcf.termdb_bygenotype.getAF&&t.term2_is_genotype){if(!t.chr)throw"chr missing for getting AF";if(!t.pos)throw"pos missing for getting AF";return function(t,e,n,r,i){const s=i.track.vcf.termdb_bygenotype,a=r.has(o.genotype_types.href)?r.get(o.genotype_types.href):new Set,l=r.has(o.genotype_types.halt)?r.get(o.genotype_types.halt):new Set,c=r.has(o.genotype_types.het)?r.get(o.genotype_types.het):new Set;let u=0,f=0;for(const r of t){let t=!1;if(s.sex_chrs.has(e))if(s.male_samples.has(r)){if(s.chr2par&&s.chr2par[e])for(const r of s.chr2par[e])if(n>=r.start&&n<=r.stop){t=!0;break}}else t=!0;else t=!0;t?(f+=2,l.has(r)?u+=2:c.has(r)&&u++):(f++,a.has(r)||u++)}return 0==f||0==u?0:(u/f).toFixed(3)}(n.self.samples?[...n.self.samples]:[],t.chr,Number(t.pos),t.genotype2sample,s)}},filterEmptySeries(t){const e=t.serieses.filter((t=>t.total));t.serieses.splice(0,t.serieses.length,...e)},bins:()=>a.map((t=>t.bins)),q:()=>a.map(((t,e)=>{const n={};for(const e in t.q)"index"!=e&&(n[e]=t.q[e]);return n})),useColOrder:()=>a[1].orderedLabels.length>0,useRowOrder:()=>a[2].orderedLabels.length>0,sortColsRows(t){if(a[1].orderedLabels.length){const e=a[1].orderedLabels;t.cols.sort(((t,n)=>e.indexOf(t)-e.indexOf(n)))}if(a[2].orderedLabels.length){const e=a[2].orderedLabels;t.rows.sort(((t,n)=>e.indexOf(t)-e.indexOf(n)))}},sortCharts(t){if(a[0].orderedLabels.length){const e=a[0].orderedLabels;t.charts.sort(((t,n)=>e.indexOf(t.chartId)-e.indexOf(n.chartId)))}}}})}(t,t.results.lst,n,e);return N.tree.results&&(N.tree.results.times={sql:q-s,pj:N.times}),{data:N.tree.results,samples:t.results.lst,bins:g}}const d=JSON.stringify({"@errmode":["","","",""],"@before()":"=prep()",results:{"_2:maxAcrossCharts":"=maxAcrossCharts()","_:_min":">$nval1","_:_max":"<$nval1",charts:[{chartId:"@key","~samples":["$sample","set"],"__:total":"=sampleCount()","_1:maxSeriesTotal":"=maxSeriesTotal()","@done()":"=filterEmptySeries()",serieses:[{seriesId:"@key",data:[{dataId:"@key","~samples":["$sample","set"],"__:total":"=sampleCount()"},"$key2"],"_:_max":"<$nval2","~values":["$nval2",0],"~sum":"+$nval2","~samples":["$sample","set"],"__:total":"=sampleCount()","__:boxplot":"=boxplot()","__:AF":"=getAF()"},"$key1"]},"$key0"],"~sum":"+$nval1","~values":["$nval1",0],"__:boxplot":"=boxplot()","_:_refs":{cols:["$key1"],colgrps:["-"],rows:["$key2"],rowgrps:["-"],col2name:{$key1:{name:"@branch",grp:"-"}},row2name:{$key2:{name:"@branch",grp:"-"}},"__:useColOrder":"=useColOrder()","__:useRowOrder":"=useRowOrder()","__:bins":"=bins()","__:q":"=q()","@done()":"=sortColsRows()"},"@done()":"=sortCharts()"}});function h(t,e,n){if("condition"==t.type){var r;if(null!=n&&null!==(r=n.groups)&&void 0!==r&&r.length)return n.groups.map((t=>t.name));if(t.values)return Object.keys(t.values).map(Number).sort(((t,e)=>t-e)).map((e=>t.values[e].label))}const o=Object.values(t.values||{})[0];return o&&"order"in o?Object.keys(t.values).sort(((e,n)=>"order"in t.values[e]&&"order"in t.values[n]?t.values[e].order-t.values[n].order:"order"in t.values[e]?t.values[e].order:"order"in t.values[n]?t.values[n].order:0)).map((e=>t.values[e].key)):e.map((t=>t.name?t.name:t.label))}},601:(t,e,n)=>{"use strict";n.d(e,{v:()=>o});const{getCohortsData:r}=n(6759);async function o(t,e,n){const o=r(n);e.send(o)}},5174:(t,e,n)=>{"use strict";n.r(e),n.d(e,{make:()=>i});const r=n(334),{mayComputeTermtypeByCohort:o}=n(394);function i(t,e,n,o){const i=n.cohort.termdb,a={selectCohort:i.selectCohort,supportedChartTypes:i.q.getSupportedChartTypes(t.embedder),allowedTermTypes:s(n),termMatch2geneSet:i.termMatch2geneSet,massSessionDuration:r.features.massSessionDuration||30,dataDownloadCatch:i.dataDownloadCatch,matrix:i.matrix,mclass:i.mclass,alwaysRefillCategoricalTermValues:i.alwaysRefillCategoricalTermValues,isGeneSetTermdb:i.isGeneSetTermdb,lollipop:i.lollipop};i.chartConfigByType&&(a.chartConfigByType=i.chartConfigByType),i.multipleTestingCorrection&&(a.multipleTestingCorrection=i.multipleTestingCorrection),i.helpPages&&(a.helpPages=i.helpPages),i.timeScale&&(a.timeScale=i.timeScale),i.minTimeSinceDx&&(a.minTimeSinceDx=i.minTimeSinceDx),i.coxTimeMsg&&(a.coxTimeMsg=i.coxTimeMsg),i.coxStartTimeMsg&&(a.coxStartTimeMsg=i.coxStartTimeMsg),i.displaySampleIds&&(a.displaySampleIds=i.displaySampleIds),i.additionalSampleAttributes&&(a.additionalSampleAttributes=i.additionalSampleAttributes),i.logscaleBase2&&(a.logscaleBase2=i.logscaleBase2),n.assayAvailability&&(a.assayAvailability=n.assayAvailability),n.customTwQByType&&(a.customTwQByType=n.customTwQByType),function(t,e){var n;const o=null===(n=r.dsCredentials)||void 0===n?void 0:n[e.dslabel];if(!o)return;t.requiredAuth={type:o.type||"login",headerKey:o.headerKey}}(a,t),function(t,e){if(!e.restrictAncestries)return;t.restrictAncestries=e.restrictAncestries.map((t=>({name:t.name,tvs:t.tvs})))}(a,i),function(t,e){if(!e.cohort.scatterplots)return;t.scatterplots=e.cohort.scatterplots.plots.map((t=>({name:t.name,dimensions:t.dimensions,colorTW:t.colorTW,shapeTW:t.shapeTW})))}(a,n),function(t,e){if(!e.cohort.matrixplots)return;t.matrixplots=e.cohort.matrixplots.plots.map((t=>({name:t.name})))}(a,n),function(t,e,n){const r=e.queries;if(!r)return;t.queries={defaultCoord:r.defaultCoord||n.defaultcoord};const o=t.queries;r.defaultBlock2GeneMode&&(o.defaultBlock2GeneMode=r.defaultBlock2GeneMode);r.snvindel&&(o.snvindel=!0);r.topMutatedGenes&&(o.topMutatedGenes=r.topMutatedGenes);r.topVariablyExpressedGenes&&(o.topVariablyExpressedGenes=r.topVariablyExpressedGenes.arguments);r.singleSampleMutation&&(o.singleSampleMutation={sample_id_key:r.singleSampleMutation.sample_id_key,discoSkipChrM:r.singleSampleMutation.discoSkipChrM});if(r.singleSampleGenomeQuantification){o.singleSampleGenomeQuantification={};for(const t in r.singleSampleGenomeQuantification)o.singleSampleGenomeQuantification[t]=JSON.parse(JSON.stringify(r.singleSampleGenomeQuantification[t])),delete o.singleSampleGenomeQuantification[t].folder}if(r.singleSampleGbtk){o.singleSampleGbtk={};for(const t in r.singleSampleGbtk)o.singleSampleGbtk[t]=JSON.parse(JSON.stringify(r.singleSampleGbtk[t])),delete o.singleSampleGbtk[t].folder}}(a,n,o),e.send({termdbConfig:a})}function s(t){var e;o(t);const n=new Set;for(const e of t.cohort.termdb.termtypeByCohort)e.type&&n.add(e.type);if(t.cohort.termdb.allowedTermTypes)for(const e of t.cohort.termdb.allowedTermTypes)n.add(e);return null!=t&&null!==(e=t.queries)&&void 0!==e&&e.defaultBlock2GeneMode&&n.add("geneVariant"),[...n]}},4453:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_incidence:()=>c,runCumincR:()=>u});const r=n(1017),o=n(2852).get_rows,i=n(3856).write_file,s=n(7147),a=n(9157),l=n(334);async function c(t,e){try{if(!e.cohort)throw"cohort missing from ds";const n=e.cohort.termdb.minTimeSinceDx;if(!n)throw"missing min time since dx";t.ds=e;const r=await o(t),i={};for(const t of r.lst){const e=t.key0,n=t.val1,r=t.key1,o=t.key2;e in i||(i[e]=[]),i[e].push({time:n,event:r,series:o})}const s={keys:["chartId","seriesId","time","cuminc","low","high","nrisk","nevent","ncensor"],case:[],refs:{bins:t.term2_id&&r.CTE2.bins?r.CTE2.bins:[]}},a={data:{},startTime:n};for(const e in i){const n=new Map;for(const t of i[e]){let e=n.get(t.series);e?(e.samplesize++,1==t.event&&e.eventcnt++,n.set(t.series,e)):(e={samplesize:1,eventcnt:1==t.event?1:0},n.set(t.series,e))}const r=new Set,o=new Set;for(const[e,i]of n)i.samplesize<t.minSampleSize&&r.add(e),0===i.eventcnt&&o.add(e);r.size&&(s.lowSampleSize||(s.lowSampleSize={}),s.lowSampleSize[e]=[...r]),o.size&&(s.lowEventCnt||(s.lowEventCnt={}),s.lowEventCnt[e]=[...o]);const l=i[e].filter((t=>!r.has(t.series)&&!o.has(t.series)));l.length?a.data[e]=l:(s.skippedCharts||(s.skippedCharts=[]),s.skippedCharts.push(e))}return await u(a,s),s}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}async function u(t,e){for(let e in t.data)""===e&&(e="*",t.data[e]=t.data[""],delete t.data[""]),t.data[e]=t.data[e].map((t=>({time:t.time,event:t.event,series:""===t.series?"*":t.series})));const n=r.join(l.cachedir,Math.random().toString()+".json");await i(n,JSON.stringify(t));const o=await a(r.join(l.binpath,"utils/cuminc.R"),[],[n]),c=JSON.parse(o[0]);for(const t in c)"*"===t&&(c[""]=c[t],delete c[t]);for(const t in c)for(const e in c[t].estimates)"*"===e&&(c[t].estimates[""]=c[t].estimates[e],delete c[t].estimates[e]);for(const t in c){for(const n in c[t].estimates){const r=c[t].estimates[n];for(let o=0;o<r.length;o++)e.case.push([t,n,r[o].time,r[o].est,r[o].low,r[o].up,r[o].nrisk,r[o].nevent,r[o].ncensor])}c[t].tests&&(e.tests||(e.tests={}),e.tests[t]=c[t].tests)}s.unlink(n,(()=>{}))}},5257:(t,e)=>{function n(t,e){return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id = ?\n\t\t\t\tAND value ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[t.term.id,...t.values.map((t=>t.key))],CTEname:e}}function r(t,e){var n,r;return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM survival\n\t\t\t\tWHERE term_id = ?\n\t\t\t\t${null!==(n=t.q)&&void 0!==n&&n.cutoff?"AND tte >= "+(null===(r=t.q)||void 0===r?void 0:r.cutoff):""}\n\t\t\t\tAND exit_code ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[t.term.id,...t.values.map((t=>t.key))],CTEname:e}}function o(t,e){const n=[];for(const e in t.term.values)n.push(...t.term.values[e].list);return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT id as sample\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE id IN (${Array(n.length).fill("?").join(", ")})\n\t\t\t)`],values:[...n.map((t=>t.sampleId))],CTEname:e}}async function i(t,e,n){const r={term:t.term,q:{}},o=await n.mayGetGeneVariantData(r,{genome:n.genomename}),i=[];for(const[e,n]of o){const r=n[t.term.name].values;let o=!0;for(const e of t.values){const t=r.filter((t=>t.dt==e.dt&&(!e.origin||e.origin==t.origin)));for(const n of t)if(e.mclassExcludeLst.includes(null==n?void 0:n.class)){o=!1;break}}o&&i.push(e)}return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT id as sample\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE id IN (${i.map((t=>"?")).join(", ")})\n\t\t\t)`],values:[...i],CTEname:e}}function s(t,e,n){if(!t.ranges)throw".ranges{} missing";const r=[t.term.id],o=n.cohort.termdb.q.termjsonByOneid(t.term.id),i=[];let s,a=!1;for(const e of t.ranges)if("value"in e){const n=t.isnot?"!":"";i.push(`value ${n}= ?`),r.push(""+e.value)}else{a=!0;const n=[];e.startunbounded||(e.startinclusive?n.push("value >= ?"):n.push("value > ? "),r.push(e.start)),e.stopunbounded||(e.stopinclusive?n.push("value <= ?"):n.push("value < ? "),r.push(e.stop));const o=t.isnot?"NOT ":"";n.length&&i.push(o+"("+n.join(" AND ")+")")}a&&o.values&&(s=Object.keys(o.values).filter((t=>o.values[t].uncomputable)).map(Number).filter((e=>t.isnot||!t.ranges.find((t=>"value"in t&&Number(t.value)==e)))),s.length&&r.push(...s));const l=i.join(" OR ");return{CTEs:[`\n\t\t ${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM anno_${o.type}\n\t\t\t\tWHERE term_id = ?\n\t\t\t\t${l?"AND ("+l+")":""}\n\t\t\t\t${s&&s.length?`AND value NOT IN (${s.map((t=>"?")).join(",")})`:""}\n\t\t\t)`],values:r,CTEname:e}}function a(t,e){let n,r;if(t.bar_by_children)n="child";else{if(!t.bar_by_grade)throw"must set the bar_by_grade or bar_by_children query parameter";n="grade"}if(t.value_by_max_grade)r="max_grade";else if(t.value_by_most_recent)r="most_recent";else{if(!t.value_by_computable_grade)throw"unknown setting of value_by_?";r="computable_grade"}const o=[],i=[];if(!t.values)throw t.grade_and_child?"-- Todo: tvs.grade_and_child":'unknown condition term filter type: expecting term-value "values" or "grade_and_child" key';return i.push(t.term.id,...t.values.map((t=>""+t.key))),o.push(`\n\t\t\t${e} AS (\n\t\t\t\tSELECT sample\n\t\t\t\tFROM ${"grade"==n?"precomputed_chc_grade":"precomputed_chc_child"}\n\t\t\t\tWHERE term_id = ? \n\t\t\t\tAND ${r} = 1\n\t\t\t\tAND value ${t.isnot?"NOT":""} IN (${t.values.map((t=>"?")).join(", ")})\n\t\t\t)`),{CTEs:o,values:i,CTEname:e}}e.getFilterCTEs=async function t(e,l,c="f"){if(!e)return;if("tvslst"!=e.type)throw'filter.type is not "tvslst" but: '+e.type;if(!Array.isArray(e.lst))throw"filter.lst must be an array";if(0==e.lst.length)return console.error("filter.lst[] is zero length, see if is an error");if(1==e.lst.length){if("tvslst"==e.lst[0].type)throw'only one element at a level: type should not be "tvslst"'}else if("or"!=e.join&&"and"!=e.join)throw'multiple elements at a level: filter.join must equal either "or" or "and"';"in"in e||(e.in=!0);const u=[],f=[],d=[];for(const[h,p]of e.lst.entries()){const e=c+"_"+h;let m;if("tvslst"==p.type)m=await t(p,l,e);else if("categorical"==p.tvs.term.type)m=n(p.tvs,e);else if("survival"==p.tvs.term.type)m=r(p.tvs,e);else if("samplelst"==p.tvs.term.type)m=o(p.tvs,e);else if("integer"==p.tvs.term.type||"float"==p.tvs.term.type)m=s(p.tvs,e,l);else if("condition"==p.tvs.term.type)m=a(p.tvs,e);else{if("geneVariant"!=p.tvs.term.type)throw"unknown term type";m=await i(p.tvs,e,l)}u.push(m.CTEname),f.push(...m.CTEs),d.push(...m.values)}const h="and"==e.join?"INTERSECT":"UNION",p=u.map((t=>"SELECT * FROM "+t)).join("\n"+h+"\n");return e.in?f.push(`\n\t\t\t\t${c} AS (\n\t\t\t\t\t${p}\n\t\t\t\t)\n\t\t\t`):f.push(`\n\t\t\t\t${c} AS (\n\t\t\t\t\tSELECT id as sample\n\t\t\t\t\tFROM sampleidmap\n\t\t\t\t\tWHERE sample NOT IN (\n\t\t\t\t\t\t${p}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t`),{filters:f.join(",\n"),CTEs:f,values:d,CTEname:c}}},7860:(t,e,n)=>{"use strict";n.r(e),n.d(e,{copy_term:()=>S,handle_request_closure:()=>N});var r=n(5684),o=n(7027),i=n(3856),s=n(6191),a=n.n(s),l=n(4065);const c=n(5174),u=n(2852),f=n(5708),d=n(4453),h=n(1468),p=n(8599),m=n(3795),g=n(1711).getOrderedLabels,y=n(1575).CG,v=n(2188).uR,b=n(2188).v8,_=n(4603).g,w=n(2974).getData,x=n(601).v,k=n(4143).R,q=10;function N(t){return async(e,n)=>{const s=e.query;try{const N=t[s.genome];if(!N)throw"invalid genome";const[M,T]=function(t,e){{const r=t.datasets[e.dslabel];if(r){var n;if(null!=r&&null!==(n=r.cohort)&&void 0!==n&&n.termdb)return[r,r.cohort.termdb];throw".cohort.termdb not found on this dataset"}}if(!t.termdbs)throw"genome-level termdb not available";const r=t.termdbs[e.dslabel];if(!r)throw"invalid dslabel";if(!r.cohort)throw"ds.cohort missing for genome-level termdb";if(!r.cohort.termdb)throw"ds.cohort.termdb{} missing for a genome-level termdb";return[r,r.cohort.termdb]}(N,s);if(s.gettermbyid)return function(t,e,n){const r=n.q.termjsonByOneid(t.gettermbyid);e.send({term:r?S(r):void 0})}(s,n,T);if(s.getcategories)return await async function(t,e,n,r,o){var i,s,a;if(!t.tid)throw".tid missing";const l="geneVariant"==t.type?{name:t.tid,type:"geneVariant",isleaf:!0}:n.q.termjsonByOneid(t.tid),c={filter:t.filter,terms:"geneVariant"==t.type?[{term:l,q:{isAtomic:!0}}]:[{id:t.tid,term:l,q:t.term1_q||A(l,t)}],currentGeneNames:t.currentGeneNames},u=await w(c,r,o);if(u.error)throw u.error;const f=[];if("geneVariant"==t.type){var d;const e=u.samples,n=new Map;if(null!==(d=r.assayAvailability)&&void 0!==d&&d.byDt)for(const[t,e]of Object.entries(r.assayAvailability.byDt))e.byOrigin&&n.set(parseInt(t),{byOrigin:{germline:{},somatic:{}}});for(const[r,o]of Object.entries(e)){const e=o[t.tid].values;for(const t of e){n.has(t.dt)||n.set(t.dt,{});const e=n.get(t.dt);e.byOrigin?e.byOrigin[t.origin][t.class]=e.byOrigin[t.origin][t.class]?e.byOrigin[t.origin][t.class]+1:1:e[t.class]=e[t.class]?e[t.class]+1:1}}for(const[t,e]of n)f.push({dt:t,classes:e})}else{const e=new Map;for(const n in u.samples){const r=u.samples[n][t.tid];r&&("key"in r&&e.set(r.key,1+(e.get(r.key)||0)))}for(const[n,r]of e){var h,p,m,y;f.push({samplecount:r,key:"cox"==(null===(h=t.term1_q)||void 0===h?void 0:h.mode)?JSON.parse(n).event:n,label:"cox"==(null===(p=t.term1_q)||void 0===p?void 0:p.mode)?JSON.parse(n).label:(null==l||null===(m=l.values)||void 0===m||null===(y=m[n])||void 0===y?void 0:y.label)||n})}}const v=g(l,(null===(i=u.refs)||void 0===i||null===(s=i.byTermId)||void 0===s||null===(a=s[t.tid])||void 0===a?void 0:a.bins)||[],t.term1_q);v.length&&f.sort(((t,e)=>v.indexOf(t.label)-v.indexOf(e.label)));e.send({lst:f,orderedLabels:v})}(s,n,T,M,N);if(s.getpercentile)return async function(t,e,n){const r=n.cohort.termdb.q.termjsonByOneid(t.tid);if(!r)throw"invalid termid";if("float"!=r.type&&"integer"!=r.type)throw"not numerical term";const i=t.getpercentile,s=[],a=[],l=await u.get_rows_by_one_key({ds:n,key:t.tid,filter:t.filter?"string"==typeof t.filter?JSON.parse(t.filter):t.filter:null});for(const{value:t}of l)r.values&&r.values[t]&&r.values[t].uncomputable||r.skip0forPercentile&&0==t||a.push(Number(t));for(const t of i){const e=(0,o.Z)(a,t);s.push(e)}e.send({values:s})}(s,n,M);if(s.getdescrstats)return async function(t,e,n){const i=n.cohort.termdb.q.termjsonByOneid(t.tid);if(!i)throw"invalid termid";if("float"!=i.type&&"integer"!=i.type)throw"not numerical term";const s=await u.get_rows_by_one_key({ds:n,key:t.tid,filter:t.filter?"string"==typeof t.filter?JSON.parse(t.filter):t.filter:null}),a=[];for(const{value:e}of s){var l,c;i.values&&i.values[e]&&i.values[e].uncomputable||("log"===(null===(l=t.settings)||void 0===l||null===(c=l.violin)||void 0===c?void 0:c.unit)&&0===e||a.push(Number(e)))}const f=a.length,d=a.reduce(((t,e)=>t+e),0)/f,h=(0,o.Z)(a,25),p=(0,o.Z)(a,50),m=(0,o.Z)(a,75),g=a.map((t=>(t-d)**2)).reduce(((t,e)=>t+e),0)/(a.length-1),y=Math.sqrt(g),v=Math.min(...a),b=Math.max(...a);e.send({values:[{id:"total",label:"n",value:f},{id:"min",label:"Minimum",value:(0,r.Z)(v,2)},{id:"p25",label:"1st quartile",value:(0,r.Z)(h,2)},{id:"median",label:"Median",value:(0,r.Z)(p,2)},{id:"mean",label:"Mean",value:(0,r.Z)(d,2)},{id:"p75",label:"3rd quartile",value:(0,r.Z)(m,2)},{id:"max",label:"Maximum",value:(0,r.Z)(b,2)},{id:"sd",label:"Standard deviation",value:(0,r.Z)(y,2)}]})}(s,n,M);if(s.getnumericcategories)return await async function(t,e,n,r){if(!t.tid)throw".tid missing";n.q.termjsonByOneid(t.tid);const o={ds:r,term_id:t.tid};t.filter&&(o.filter=t.filter);const i=await u.get_summary_numericcategories(o);e.send({lst:i})}(s,n,T,M);if(s.default_rootterm)return await async function(t,e,n){const r=t.cohortValues?t.cohortValues:"",o=t.treeFilter?t.treeFilter:"";e.send({lst:await n.q.getRootTerms(r,o)})}(s,n,T);if(s.get_children)return await async function(t,e,n){if(!t.tid)throw"no parent term id";const r=t.cohortValues?t.cohortValues:"",o=t.treeFilter?t.treeFilter:"",i=await n.q.getTermChildren(t.tid,r,o);e.send({lst:i.map(S)})}(s,n,T);if(s.findterm)return await async function(t,e,n,r,o){var i;const s={equals:[],startsWith:[],startsWord:[],includes:[]},a=decodeURIComponent(t.findterm).toUpperCase(),c=y({type:"geneVariant"},t.usecase).has("plot");r.mayGetMatchingGeneNames&&c&&await r.mayGetMatchingGeneNames(s,a,t);const u=[];if(null!==(i=r.queries)&&void 0!==i&&i.defaultBlock2GeneMode&&c){const t=(0,l.getResult)(o,{input:a});if(Array.isArray(t.hits))for(let e=0;e<7&&t.hits[e];e++)u.push({name:t.hits[e],type:"geneVariant"})}"string"!=typeof t.cohortStr&&(t.cohortStr="");const f=await n.q.findTermByName(a,q,t.cohortStr,t.treeFilter,t.usecase,s);u.push(...f.map(S));u.forEach((t=>{"geneVariant"!=t.type&&(t.__ancestors=n.q.getAncestorIDs(t.id),t.__ancestorNames=n.q.getAncestorNames(t.id))})),e.send({lst:u})}(s,n,T,M,N);if(s.getterminfo)return function(t,e,n){if(!t.tid)throw"no term id";e.send({terminfo:n.q.getTermInfo(t.tid)})}(s,n,T);if(s.phewas)return s.update?await f.update_image(s,n):s.getgroup?await f.getgroup(s,n):await f.trigger(s,n,M);if(s.gettermdbconfig)return c.make(s,n,M,N);if(s.getcohortsamplecount)return n.send({count:M.cohort.termdb.q.getcohortsamplecount(s.cohort)});if(s.getsamplecount)return n.send(await async function(t,e,n){const r=a().canDisplaySampleIds(t,n);if("list"==e.getsamplecount){return await u.get_samples(e.filter,n,r)}return await u.get_samplecount(e,n)}(e,s,M));if(s.getsamples)return await async function(t,e,n){const r=await u.get_samples(t.filter,n),o=r.map((t=>n.cohort.termdb.q.id2sampleName(t)));e.send({samples:o})}(s,n,M);if(s.getcuminc)return await async function(t,e,n){if(!t.minSampleSize)throw"missing minSampleSize";t.minSampleSize=Number(t.minSampleSize);const r=await d.get_incidence(t,n);e.send(r)}(s,n,M);if(s.getsurvival)return await async function(t,e,n){const r=await h.get_survival(t,n);e.send(r)}(s,n,M);if(s.getregression)return await async function(t,e,n){const r=await p.get_regression(t,n);e.send(r)}(s,n,M);if(s.validateSnps)return n.send(await m.validate(s,T,M,N));if(s.getvariantfilter)return function(t,e){var n,r;if(e.track)return void t.send(e.track.variant_filter);t.send((null==e||null===(n=e.queries)||void 0===n||null===(r=n.snvindel)||void 0===r?void 0:r.variant_filter)||{})}(n,M);if(s.getLDdata)return await async function(t,e,n){var r,o;if(!t.ldtkname)throw".ldtkname missing";if(null===(r=e.queries)||void 0===r||null===(o=r.ld)||void 0===o||!o.tracks)throw"no ld tk";const s=e.queries.ld.tracks.find((e=>e.name==t.ldtkname));if(!s)throw"unknown ld tk";if("object"!=typeof t.m)throw"q.m{} not object";if(!t.m.chr)throw"q.m.chr missing";if(!Number.isInteger(t.m.pos))throw"q.m.pos not integer";if(!t.m.ref||!t.m.alt)throw"q.m{} invalid alleles";const a=t.m.ref+"."+t.m.alt,l=(s.nochr?t.m.chr.replace("chr",""):t.m.chr)+":"+t.m.pos+"-"+(t.m.pos+1),c=[];await(0,i.get_lines_bigfile)({args:[s.file,l],dir:s.dir,callback:e=>{const n=e.split("\t"),r=Number.parseInt(n[1]),o=Number.parseInt(n[2]),i=n[3],s=n[4],l=Number.parseFloat(n[5]);r==t.m.pos&&i==a?c.push({pos:o,alleles:s,r2:l}):o==t.m.pos&&s==a&&c.push({pos:r,alleles:i,r2:l})}}),n.send({lst:c})}(s,M,n);if(s.genesetByTermId)return function(t,e,n){if(!n.termMatch2geneSet)throw"this feature is not enabled";if("string"!=typeof t.genesetByTermId||0==t.genesetByTermId.length)throw"invalid query term id";const r=n.q.getGenesetByTermId(t.genesetByTermId);e.send(r)}(s,n,T);if(s.getSampleScatter)return await v(e,s,n,M,N);if(s.getLowessCurve)return await b(e,s,n);if(s.getCohortsData)return await x(s,n,M);if(s.getViolinPlotData)return await _(s,n,M,N);if("mds3queryDetails"==s.for)return function(t,e){const n={},r=e.queries||{};r.snvindel&&(n.snvindel={},r.snvindel.details&&(n.snvindel.details=r.snvindel.details),r.snvindel.populations&&(n.snvindel.populations=r.snvindel.populations));r.trackLst&&(n.trackLst=r.trackLst);if(r.ld){n.ld=JSON.parse(JSON.stringify(r.ld));for(const t of n.ld.tracks)delete t.file}t.send(n)}(n,M);if("termTypes"==s.for)return n.send(await M.getTermTypes(s));if("matrix"==s.for)return await async function(t,e,n,r,o){if(t.getPlotDataByName){if(!r.cohort.matrixplots)throw"ds.cohort.matrixplots missing for the dataset";if(!r.cohort.matrixplots.plots)throw"ds.cohort.matrixplots.plots missing for the dataset";const e=r.cohort.matrixplots.plots.find((e=>e.name===t.getPlotDataByName));if(!e)throw`plot name: q.getPlotDataByName=${getPlotDataByName} missing in ds.cohort.matrixplots.plots`;return void n.send(e.matrixConfig)}const i=await w(t,r,o);if(a().canDisplaySampleIds(e,r))for(const t of Object.values(i.samples))t.sampleName=r.sampleId2Name.get(t.sample);n.send(i)}(s,e,n,M,N);if("mds3variantData"==s.for)return await k(s,n,M,N);throw s.for,"termdb: doesn't know what to do"}catch(t){n.send({error:t.message||t}),t.stack?console.log(t.stack):console.log(t)}}}function S(t){return JSON.parse(JSON.stringify(t))}function A(t,e){if("categorical"==t.type)return{};if("survival"==t.type)return{};if("integer"==t.type||"float"==t.type)return t.bins.default;if("condition"==t.type)return{mode:e.mode,breaks:e.breaks,bar_by_grade:e.bar_by_grade,bar_by_children:e.bar_by_children,value_by_max_grade:e.value_by_max_grade,value_by_most_recent:e.value_by_most_recent,value_by_computable_grade:e.value_by_computable_grade};if("geneVariant"==t.type)return{};throw"unknown term type"}},2974:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getData:()=>f,getSampleData_dictionaryTerms_termdb:()=>d,mayInitiateMatrixplots:()=>h});const r=n(1017),{get_samples:o,get_term_cte:i,interpolateSqlValues:s}=n(2852),{getFilterCTEs:a}=n(5257),l=(n(9157),n(7147),n(7219),n(334)),c=n(3856),{getSampleData_snplstOrLocus:u}=(n(2852),n(8599));async function f(t,e,n){try{return function(t,e,n){if(!e.cohort)throw"cohort missing from ds";if(!t.terms)throw"missing 'terms' parameter";t.ds=e,t.genome=n;for(const e of t.terms)e.term.name||(e.term=t.ds.cohort.termdb.q.termjsonByOneid(e.term.id)),e.q||console.log("do something??");if(t.currentGeneNames&&!Array.isArray(t.currentGeneNames))throw"currentGeneNames[] is not array";t.filter0&&"string"==typeof t.filter0&&(t.filter0=JSON.parse(t.filter0))}(t,e,n),await async function(t){const[e,n]=function(t){const e=[],n=[];for(const r of t){const t=r.term.type;"snplst"==t||"snplocus"==t||"geneVariant"==t?n.push(r):e.push(r)}return[e,n]}(t.terms),{samples:r,refs:i}=await async function(t,e){var n,r,o,i;if(!e.length)return{samples:{},refs:{byTermId:{}}};if(null!==(n=t.ds)&&void 0!==n&&null!==(r=n.cohort)&&void 0!==r&&r.db)return await d(t,e);if(null!==(o=t.ds)&&void 0!==o&&null!==(i=o.variant2samples)&&void 0!==i&&i.get)return await async function(t,e){const n={filter0:t.filter0,filterObj:t.filter,genome:t.genome,get:"samples",twLst:e,useIntegerSampleId:!0};if(t.currentGeneNames){n.geneTwLst=[];for(const e of t.currentGeneNames)n.geneTwLst.push({term:{name:e,type:"geneVariant"}})}const r=await t.ds.variant2samples.get(n),o={},i={byTermId:{}};for(const t of r){const n={sample:t.sample_id};for(const r of e){const e=t[r.term.id];Array.isArray(e)&&null!=e[0]&&null!=e[0]?n[r.term.id]={key:e[0],value:e[0]}:null!=e&&null!=e&&(n[r.term.id]={key:e,value:e})}o[t.sample_id]=n}return{samples:o,refs:i}}(t,e);throw"unknown method for dictionary terms"}(t,e);t.ds.getSampleIdMap&&(i.bySampleId=t.ds.getSampleIdMap(r));if(e.length&&!Object.keys(r).length)return{samples:r,refs:i};const s=await async function(t,e){if(!e.find((t=>"snplst"==t.term.type||"snplocus"==t.term.type)))return;if(!t.filter)return;return new Set((await o(t.filter,t.ds)).map((t=>t.id)))}(t,n);for(const o of n)if("geneVariant"==o.term.type){const n=await t.ds.mayGetGeneVariantData(o,t);for(const[i,s]of n.entries()){var a,l;if(o.term.name in s)if(e.length||i in r||(r[i]={sample:i}),r[i])if(r[i][o.term.name]=s[o.term.name],null!==(a=t.ds.cohort)&&void 0!==a&&null!==(l=a.termdb)&&void 0!==l&&l.additionalSampleAttributes)for(const e of null===(c=t.ds.cohort)||void 0===c||null===(f=c.termdb)||void 0===f?void 0:f.additionalSampleAttributes){var c,f;e in s&&(r[i][e]=s[e])}}}else{if("snplst"!=o.term.type&&"snplocus"!=o.term.type)throw"unknown type of non-dictionary term";{o.type=o.term.type;const t=new Map;await u(o,t,!0);for(const[e,n]of t){if(s&&!s.has(e))continue;e in r||(r[e]={sample:e});const t={};for(const[e,r]of n.id2value)t[e]=r.value;r[e][o.term.id]=t}}}return{samples:r,refs:i}}(t)}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}async function d(t,e){const n={},r={byTermId:{}},o={},s=await a(t.filter,t.ds),l=s?s.values.slice():[],c=await Promise.all(e.map((async(e,n)=>{const a=await i(t,l,n,s,e);if(a.bins&&(r.byTermId[e.term.id]={bins:a.bins}),e.term.values){const t=Object.values(e.term.values);t.find((t=>"order"in t))&&(r.byTermId[e.term.id]={keyOrder:t.sort(((t,e)=>t.order-e.order)).map((t=>t.key))})}return"id"in e.term&&(o[e.term.id]=e),a}))).catch(console.error);l.push(...e.map((t=>t.term.id||t.term.name)));const u=`WITH\n\t\t${s?s.filters+",":""}\n\t\t${c.map((t=>t.sql)).join(",\n")}\n\t\t${c.map((t=>`\n\t\t\tSELECT sample, key, value, ? as term_id\n\t\t\tFROM ${t.tablename}\n\t\t\t${s?`WHERE sample IN ${s.CTEname}`:""}\n\t\t\t`)).join("UNION ALL")}`,f=t.ds.cohort.db.connection.prepare(u).all(l),d=await async function(t){if(!t.currentGeneNames)return;const e=new Set;for(const n of t.currentGeneNames){const r={term:{name:n,type:"geneVariant"}},o=await t.ds.mayGetGeneVariantData(r,t);for(const[t,n]of o.entries())e.add(t)}return e}(t);for(const{sample:t,term_id:e,key:r,value:i}of f){if(d&&!d.has(t))continue;n[t]||(n[t]={sample:t});o[e];n[t][e]={key:r,value:i}}return{samples:n,refs:r}}async function h(t){if(t.cohort.matrixplots){if(!Array.isArray(t.cohort.matrixplots.plots))throw"cohort.matrixplots.plots is not array";for(const e of t.cohort.matrixplots.plots){if(!e.name)throw".name missing from one of matrixplots.plots[]";if(!e.file)throw"unknown data source of one of matrixplots.plots[]";{const t=await c.read_file(r.join(l.tpmasterdir,e.file));e.matrixConfig=JSON.parse(t),e.getConfig&&(e.matrixConfig=e.getConfig(e.matrixConfig))}}}}},5708:(t,e,n)=>{"use strict";n.r(e),n.d(e,{do_precompute:()=>h,getgroup:()=>w,trigger:()=>d,update_image:()=>v});const r=n(7147),o=n(1017),i=n(3856),s=n(2852),a=n(6718).createCanvas,l=n(7860),c=n(4521),u=n(334),f=n(9157);async function d(t,e,n){if(!n.cohort)throw"ds.cohort missing";if(!n.cohort.termdb)throw"cohort.termdb missing";if(!n.cohort.termdb.phewas)throw"not allowed on this dataset";if(!t.ssid)throw"ssid missing";const r={};let a;t.filter&&(a=new Set(await s.get_samples(t.filter,n)));const[c,d]=await i.loadfile_ssid(t.ssid,a);r.numberofsamples=c.size;const h=d.has(i.genotype_types.het)?d.get(i.genotype_types.het).size:0,p=d.has(i.genotype_types.href)?d.get(i.genotype_types.href).size:0,m=d.has(i.genotype_types.halt)?d.get(i.genotype_types.halt).size:0,g=function(t,e,n,r,o,i){const s=[];let a;if(e.cohort.termdb.selectCohort&&t){const e=t.lst.find((t=>"cohortFilter"==t.tag));e&&(a=e.tvs.values.map((t=>t.key)).sort().join(","))}for(const t of e.cohort.termdb.q.getcategory2vcfsample()){if(a&&t.subcohort!=a)continue;const c=l.copy_term(e.cohort.termdb.q.termjsonByOneid(t.term_id));for(const e of t.categories){const[a,l,u]=_(n,e.group1lst);let f,d,h;e.group2lst?[f,d,h]=_(n,e.group2lst):(f=r-a,d=i-l,h=o-u),a+f+l+d+u+h!=0&&s.push({term:c,group_name:t.group_name,parent_name:t.parent_name,group1label:e.group1label,group2label:e.group2label,table:[u,h,a,f,l,d]})}}return s}(t.filter,n,c,h,p,m);r.testcount=g.length;{const t=[];for(let e=0;e<g.length;e++)t.push(e+"\t"+g[e].table.join("\t"));const e=await f(o.join(u.binpath,"utils/fisher.2x3.R"),t);let n=0;for(const t of e)g[n++].pvalue=Number(t.split("\t")[7])}r.maxlogp=function(t){let e=0;for(const n of t)0==n.pvalue?n.logp=100:n.logp=-Math.log10(n.pvalue),e=Math.max(e,n.logp);return e}(g);const y=function(t){const e=new Map;for(const n of t)e.has(n.group_name)||e.set(n.group_name,[]),e.get(n.group_name).push(n);const n=[];for(const[t,r]of e)n.push({group_name:t,categories:r});return n}(g);r.tmpfile=await function(t){const e=[];for(const n of t)for(const t of n.categories)e.push(n.group_name+"\t"+t.logp+"\t"+t.pvalue+"\t"+JSON.stringify(t));return i.write_tmpfile(e.join("\n"))}(y),b(y,r,t);{const t=.05;r.hoverdots=g.filter((e=>e.pvalue<=t))}e.send(r)}async function h(t){if(!t.cohort)throw"ds.cohort missing";if(!t.cohort.termdb)throw"cohort.termdb missing";if(!t.cohort.termdb.phewas)throw"not allowed on this dataset";t.cohort.termdb.selectCohort?await async function(t){const e=await async function(t){if(!t.cohort.termdb.phewas.precompute_subcohort2totalsamples)return;for(const e in t.cohort.termdb.phewas.precompute_subcohort2totalsamples){const n=t.cohort.termdb.phewas.precompute_subcohort2totalsamples[e];if(n.termtype)for(const e in n.termtype)n.termtype[e].samples=await s.get_samples(n.termtype[e].filter,t)}return t.cohort.termdb.phewas.precompute_subcohort2totalsamples}(t),n=function(t){const e=new Map,n=t.cohort.db.connection.prepare("SELECT * FROM subcohort_terms");for(const{term_id:t,cohort:r}of n.all())e.has(t)||e.set(t,new Set),e.get(t).add(r);return e}(t),o=r.createWriteStream("category2vcfsample"),i=[];for(const{group_name:r,term:a}of t.cohort.termdb.q.getAlltermsbyorder()){if(!a.type)continue;if(!n.has(a.id)){i.push(a.id);continue}let l="";{const e=t.cohort.termdb.q.getTermParent(a.id);e&&(l=e.name)}const c=m(a,t,n);for(const n of c){const i=await s.get_rows(n);let c;if("categorical"==a.type||"integer"==a.type||"float"==a.type)c=g(i.lst,a,t);else{if("condition"!=a.type)throw"unknown term type";c=t.cohort.termdb.phewas.comparison_groups?y(i.lst,t):g(i.lst,a,t)}c=p({categories:c,q:n,subcohortTermtype2samples:e,term:a});for(const t of c)console.log(t.group1lst.length+(t.group2lst?"/"+t.group2lst.length:"")+"\t"+t.group1label+"\t"+a.name+"\t"+n.cohortname);o.write(n.cohortname+"\t"+r+"\t"+a.id+"\t"+l+"\t"+(n.term1_q?JSON.stringify(n.term1_q):"{}")+"\t"+JSON.stringify(c)+"\n")}}o.end((()=>{console.log('Phewas precompute result written to file "category2vcfsample".'),i.length&&(console.log(i.length+" empty terms:"),console.log(i.join("\n")))}))}(t):await async function(t){const[e]=await async function(t){let e=null;if(t.cohort.termdb.phewas.samplefilter4termtype&&t.cohort.termdb.phewas.samplefilter4termtype.condition){const n=await s.get_samples(t.cohort.termdb.phewas.samplefilter4termtype.condition.filter,t);if(t.track&&t.track.vcf&&t.track.vcf.sample2arrayidx){e=[];for(const r of n)t.track.vcf.sample2arrayidx.has(r)&&e.push(r)}else e=n}return[e]}(t),n=[];for(const{group_name:r,term:o}of t.cohort.termdb.q.getAlltermsbyorder()){if(!o.type)continue;let i="";{const e=t.cohort.termdb.q.getTermParent(o.id);e&&(i=e.name)}const a=m(o,t);for(const l of a){const a=await s.get_rows(l);let c;if("categorical"==o.type||"integer"==o.type||"float"==o.type)c=g(a.lst,o,t);else{if("condition"!=o.type)throw"unknown term type";c=t.cohort.termdb.phewas.comparison_groups?y(a.lst,t):g(a.lst,o,t)}c=p({categories:c,q:l,term:o,condition_samplelst:e});for(const t of c)console.log(t.group1lst.length+(t.group2lst?"/"+t.group2lst.length:"")+"\t"+t.group1label+"\t"+o.name);n.push(r+"\t"+o.id+"\t"+i+"\t"+(l.term1_q?JSON.stringify(l.term1_q):"{}")+"\t"+JSON.stringify(c))}}r.writeFileSync("category2vcfsample",n.join("\n")),console.log('Phewas precompute result written to file "category2vcfsample".')}(t)}function p(t){const{categories:e,q:n,term:r,subcohortTermtype2samples:o,condition_samplelst:i}=t;if(o&&o[n.cohortname]&&o[n.cohortname].termtype&&o[n.cohortname].termtype[r.type]){const t=o[n.cohortname].termtype[r.type].samples;for(const n of e)if(n.group2lst)n.group2lst=n.group2lst.filter((e=>-1!=t.indexOf(e)));else if(n.copycontrolfrom1stgroup){n.group2lst=[];for(const t of e[0].group2lst)n.group2lst.push(t)}else{const e=new Set(n.group1lst);n.group2lst=t.filter((t=>!e.has(t)))}return e}if(i&&"condition"==r.type){for(const t of e)if(t.group2lst)t.group2lst=t.group2lst.filter((t=>-1!=i.indexOf(t)));else if(t.copycontrolfrom1stgroup){t.group2lst=[];for(const n of e[0].group2lst)t.group2lst.push(n)}else{const e=new Set(t.group1lst);t.group2lst=i.filter((t=>!e.has(t)))}return e}if(!r.values)return e;const s=new Set;for(const t in r.values)r.values[t].uncomputable&&s.add(r.values[t].label);if(0==s.size)return e;const a=[];for(const t of e)s.has(t.group1label)?console.log("skip "+t.group1label+", "+r.id):a.push(t);for(let t=0;t<a.length;t++){const e=a[t];e.group2lst=[];for(let n=0;n<a.length;n++)n!=t&&e.group2lst.push(...a[n].group1lst)}return a}function m(t,e,n){const r=[];if(e.cohort.termdb.selectCohort){if(!n)throw"term2cohort is required when cohort selection is enabled";for(const o of e.cohort.termdb.selectCohort.values){const i=o.keys.sort().join(",");if(!n.get(t.id).has(i))continue;const s={type:"tvslst",in:!0,join:"",lst:[{type:"tvs",tvs:{term:e.cohort.termdb.selectCohort.term,values:o.keys.map((t=>({key:t})))}}]};if("categorical"==t.type)r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id});else if("float"==t.type||"integer"==t.type)r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id,term1_q:t.bins.default});else{if("condition"!=t.type)throw"unknown term type";r.push({cohortname:i,filter:JSON.parse(JSON.stringify(s)),ds:e,term1_id:t.id,term1_q:{bar_by_grade:!0,value_by_max_grade:!0}})}}}else if("categorical"==t.type)r.push({ds:e,term1_id:t.id});else if("float"==t.type||"integer"==t.type)r.push({ds:e,term1_id:t.id,term1_q:t.bins.default});else{if("condition"!=t.type)throw"unknown term type";r.push({ds:e,term1_id:t.id,term1_q:{bar_by_grade:!0,value_by_max_grade:!0}})}return r}function g(t,e,n){const r=new Map;for(const o of t){if(n.track&&n.track.vcf&&n.track.vcf.sample2arrayidx&&!n.track.vcf.sample2arrayidx.has(o.sample))continue;const t=o.key1;if(!r.has(t)){let n=t;e.values&&(n=e.values[t]?e.values[t].label:t),r.set(t,{group1label:n,group2label:"All others",group1lst:[]})}r.get(t).group1lst.push(o.sample)}return[...r.values()]}function y(t,e){const n=[];for(const r of e.cohort.termdb.phewas.comparison_groups){const o=[],i=[];for(const n of t){if(e.track&&e.track.vcf&&e.track.vcf.sample2arrayidx&&!e.track.vcf.sample2arrayidx.has(n.sample))continue;const t=Number(n.key1);r.group1grades.has(t)?o.push(n.sample):r.group2grades&&r.group2grades.has(t)&&i.push(n.sample)}0!=o.length?n.push({group1label:r.group1label,group2label:r.group2label,group1lst:o,group2lst:i.length?i:void 0,copycontrolfrom1stgroup:r.copycontrolfrom1stgroup}):console.log("Empty group1: "+r.group1label)}return n}async function v(t,e){const n=await i.read_file(o.join(u.cachedir,t.file)),r=[];for(const t of n.trim().split("\n")){const[e,n]=t.split("\t",2),o=Number(n);0!=r.length&&r[r.length-1].group_name==e||r.push({group_name:e,categories:[]}),r[r.length-1].categories.push({logp:o})}const s={maxlogp:Number(t.max)};b(r,s,t),e.send(s)}function b(t,e,n){const r=Number(n.intendwidth),o=Number(n.axisheight),i=Number(n.groupnamefontsize),s=Number(n.dotradius),l=Number(n.groupxspace),c=Number(n.leftpad),u=Number(n.rightpad),f=Number(n.toppad),d=Number(n.bottompad),h=Number(n.devicePixelRatio),p=r/t.reduce(((t,e)=>t+e.categories.length),0),m=a(10,10),g=m.getContext("2d");let y=0;for(const e of t){const t=e.categories.length*p;e.width=Math.max(t,i)+2*l,e.dotshiftx=t>i?p:i/e.categories.length,y+=e.width}const v=c+y+u;m.width=v*h;const b=f+o+d;m.height=b*h,h>1&&g.scale(h,h),y=0,g.fillStyle="#FDFEE2";for(const[e,n]of t.entries())e%2==0&&g.fillRect(y,f,n.width,o),y+=n.width;y=0,g.fillStyle="black",e.grouplabels=[];for(const n of t){e.grouplabels.push({name:n.group_name,x:y+n.width/2,y:f+o+2*s});let t=0;for(const r of n.categories){const i=0==e.maxlogp?0:r.logp>=e.maxlogp?o:o*r.logp/e.maxlogp;g.beginPath(),g.arc(y+l+t,f+o-i,s,0,2*Math.PI),g.fill(),r.x=y+l+t,t+=n.dotshiftx}y+=n.width}e.canvaswidth=v,e.canvasheight=b,e.toppad=f,e.bottompad=d,e.axisheight=o,e.dotradius=s,e.groupnamefontsize=i,e.src=m.toDataURL()}function _(t,e){const n=new Map;for(const r of e){const e=t.get(r);e&&n.set(e,1+(n.get(e)||0))}return[n.get(i.genotype_types.het)||0,n.get(i.genotype_types.halt)||0,n.get(i.genotype_types.href)||0]}async function w(t,e){if(!t.file)throw"file missing";return new Promise(((n,i)=>{const s=[],a=c.createInterface({input:r.createReadStream(o.join(u.cachedir,t.file))});a.on("line",(e=>{if(!e.startsWith(t.getgroup+"\t"))return;const n=e.split("\t"),r=JSON.parse(n[3]);r.pvalue=Number(n[2]),s.push(r)})),a.on("close",(()=>{e.send({categories:s}),n()}))}))}},8599:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getSampleData_snplstOrLocus:()=>M,get_regression:()=>b});const r=n(1017),{get_term_cte:o}=n(2852),{getFilterCTEs:i}=n(5257),s=n(9157),a=n(7147),l=n(7219),c=n(334),u=n(3856),f=n(1271).run_rust,d=(n(2852),n(4453).runCumincR),h=n(9699),p=["linear","logistic","cox"],m=1;let g,y;const v={NodeJS:{},"regression.R":{}};async function b(t,e){try{!function(t,e){if(!e.cohort)throw"cohort missing from ds";if(t.ds=e,!t.regressionType)throw"regressionType missing";if(!p.includes(t.regressionType))throw"unknown regressionType";if(!t.outcome)throw"missing 'outcome' parameter";if(!("id"in t.outcome))throw"outcome.id missing";if(!t.outcome.q)throw"outcome.q missing";if(t.outcome.q.computableValuesOnly=!0,t.outcome.term=e.cohort.termdb.q.termjsonByOneid(t.outcome.id),!t.outcome.term)throw"invalid outcome term: "+t.outcome.id;if(!t.independent)throw"independent[] missing";if(!Array.isArray(t.independent)||0==t.independent.length)throw"q.independent is not non-empty array";for(const n of t.independent){if(!n.q)throw`missing q for independent term '${n.id}'`;if(_(n,t,e),"snplst"!=n.type&&"snplocus"!=n.type){if(n.q.computableValuesOnly=!0,!n.id)throw".id missing for an independent term";if(n.term=e.cohort.termdb.q.termjsonByOneid(n.id),!n.term)throw`invalid independent term='${n.id}'`}else{if(!n.q.cacheid)throw"q.cacheid missing";if(c.cache_snpgt.fileNameRegexp.test(n.q.cacheid))throw"invalid cacheid";if("object"!=typeof n.q.snp2effAle)throw"q.snp2effAle{} is not object";if(!Number.isInteger(n.q.alleleType))throw"q.alleleType is not integer";if(!Number.isInteger(n.q.geneticModel))throw"q.geneticModel is not integer";if(3==n.q.geneticModel&&"object"!=typeof n.q.snp2refGrp)throw"q.snp2refGrp{} is not object when geneticMode=3";if("snplst"==n.type&&!Number.isInteger(n.q.missingGenotype))throw"q.missingGenotype is not integer for snplst"}}for(const e of t.independent){e.interactions||(e.interactions=[]);for(const n of e.interactions)if(!t.independent.find((t=>t.id==n)))throw"interacting term id missing from independent[]: "+n}}(t,e),g=(new Date).getTime();const n=await async function(t,e,n){const[r,s]=function(t){const e=[],n=[];for(const r of t)"snplst"==r.type||"snplocus"==r.type?n.push(r):e.push(r);return[e,n]}(e),a=await async function(t,e){const n=new Map,r=await i(t.filter,t.ds),s=r?r.values.slice():[],a=await Promise.all(e.map((async(e,n)=>await o(t,s,n,r,e)))).catch(console.error);s.push(...e.map((t=>t.id)));const l=`WITH\n\t\t${r?r.filters+",":""}\n\t\t${a.map((t=>t.sql)).join(",\n")}\n\t\t${a.map((t=>`\n\t\t\tSELECT sample, key, value, ? as term_id\n\t\t\tFROM ${t.tablename}\n\t\t\t${r?`WHERE sample IN ${r.CTEname}`:""}\n\t\t\t`)).join("UNION ALL")}`,c=t.ds.cohort.db.connection.prepare(l).all(s),u=[],f=t.ds.cohort.termdb.ageEndOffset;if(!f)throw"missing age end offset";for(const e of c)if("cox"==t.regressionType&&e.term_id==t.outcome.id){const{event:n}=JSON.parse(e.key),{age_start:r,age_end:o}=JSON.parse(e.value);if(-1==n)continue;const i={age_start:r,age_end:"age"==t.outcome.q.timeScale?o+f:o};u.push({sample:e.sample,key:n,value:i,term_id:e.term_id})}else u.push(e);for(const{sample:t,term_id:r,key:o,value:i}of u){const s=e.find((t=>t.id==r));if(n.has(t)||n.set(t,{sample:t,id2value:new Map}),n.get(t).id2value.has(r))throw`duplicate '${r}' entry for sample='${t}'`;n.get(t).id2value.set(r,{key:s.q.scale?o/s.q.scale:o,value:s.q.scale?i/s.q.scale:i})}const d=new Set;for(const t of n.values())for(const n of e)if(!t.id2value.has(n.id)){d.add(t.sample);break}for(const t of d)n.delete(t);return n}(t,r);for(const t of s){if(A(t,a,n),"snplst"!=t.type&&"snplocus"!=t.type)throw"unknown type of independent non-dictionary term";await M(t,a)}return[...a.values()]}(t,[t.outcome,...t.independent],e);y=(new Date).getTime(),v.NodeJS.getSampleData=(y-g)/1e3+" sec",g=(new Date).getTime();const r=function(t,e){const n={id:t.outcome.id,name:t.outcome.term.name,rtype:"numeric"};"logistic"==t.regressionType&&(n.categories={ref:t.outcome.refGrp,nonref:k(t.outcome)});"cox"==t.regressionType&&(n.timeToEvent={timeId:t.outcome.id+"_time",eventId:t.outcome.id+"_event",timeScale:t.outcome.q.timeScale},"age"==n.timeToEvent.timeScale&&(n.timeToEvent.agestartId=t.outcome.id+"_agestart",n.timeToEvent.ageendId=t.outcome.id+"_ageend"));const r=[];for(const e of t.independent)"snplst"==e.type||"snplocus"==e.type?x(e,r,t):w(e,r,t);const o=[];for(const i of e){const{sample:e,id2value:s}=i;if(!s.has(t.outcome.id)){i.noOutcome=!0;continue}const a=s.get(t.outcome.id);let l=!1;for(const e of t.independent)if("snplocus"!=e.type)if("snplst"==e.type){for(const t of e.highAFsnps.keys())if(!s.get(t)){l=!0;break}}else{if(!s.get(e.id)){l=!0;break}}if(l)continue;const c={};if("linear"==t.regressionType&&(c[n.id]=a.value),"logistic"==t.regressionType&&(c[n.id]=a.key===t.outcome.refGrp?0:1),"cox"==t.regressionType){c[n.timeToEvent.eventId]=a.key;const{age_start:e,age_end:r}=a.value;c[n.timeToEvent.timeId]=r-e,"age"==t.outcome.q.timeScale&&(c[n.timeToEvent.agestartId]=e,c[n.timeToEvent.ageendId]=r)}for(const t of r){const e=s.get(t.id);c[t.id]=e?"numeric"===t.rtype?e.value:e.key:null}o.push(c)}const i={regressionType:t.regressionType,binpath:c.binpath,data:o,outcome:n,independent:r};return i}(t,n);y=(new Date).getTime(),v.NodeJS.makeRinput=(y-g)/1e3+" sec",function(t){const e=t.regressionType,n=t.outcome;if(t.data.length<m)throw"too few samples to fit model";let r=t.independent.length;if("cox"==e)if("time"==n.timeToEvent.timeScale)r+=2;else{if("age"!=n.timeToEvent.timeScale)throw"unknown cox regression time scale";r+=4}else r+=1;if(t.data.find((t=>Object.keys(t).length!=r)))throw"unequal number of variables in data entries";if("logistic"==e){if([...new Set(t.data.map((t=>t[n.id])))].find((t=>![0,1].includes(t))))throw"non-0/1 outcome values found"}if("cox"==e){if([...new Set(t.data.map((t=>t[n.timeToEvent.eventId])))].find((t=>![0,1].includes(t))))throw"non-0/1 outcome event values found"}for(const e of t.independent)if("numeric"==e.rtype){if(e.refGrp)throw`reference group given for '${e.id}'`}else{if("factor"!=e.rtype)throw`variable rtype='${e.rtype}' not recognized`;{if(!e.refGrp)throw`reference group not given for '${e.id}'`;if("snplst"==e.type||"snplocus"==e.type)continue;const n=new Set(t.data.map((t=>t[e.id])));if(n.size<2)throw`fewer than 2 categories in data of variable='${e.id}'`;if(!n.has(e.refGrp))throw`reference group missing in data of variable='${e.id}'`}}}(r);const[s,a]=function(t){const e={},n={};if(e.outcome=t.outcome.id,n[t.outcome.id]="outcome",t.outcome.timeToEvent){const r=t.outcome.timeToEvent;e.outcome_time=r.timeId,n[r.timeId]="outcome_time",e.outcome_event=r.eventId,n[r.eventId]="outcome_event","age"==r.timeScale&&(e.outcome_agestart=r.agestartId,e.outcome_ageend=r.ageendId,n[r.agestartId]="outcome_agestart",n[r.ageendId]="outcome_ageend")}for(const[r,o]of t.independent.entries())e["id"+r+"_"]=o.id,n[o.id]="id"+r+"_";if(t.outcome.id=n[t.outcome.id],t.outcome.timeToEvent){const e=t.outcome.timeToEvent;e.timeId=n[e.timeId],e.eventId=n[e.eventId],"age"==e.timeScale&&(e.agestartId=n[e.agestartId],e.ageendId=n[e.ageendId])}for(const e of t.independent)if(e.id=n[e.id],e.interactions&&e.interactions.length>0)for(const[t,r]of e.interactions.entries())e.interactions[t]=n[r];for(const e of t.data)for(const t in e)e[n[t]]=e[t],delete e[t];return[e,n]}(r),l={resultLst:[]};return await Promise.all([q(r,s,t,l),N(t,n,r,l)]),console.log("benchmark:",v),l}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function _(t,e,n){if(!t.q.restrictAncestry)return;if(!("name"in t.q.restrictAncestry))throw".name missing from tw.q.restrictAncestry";if(!n.cohort.termdb.restrictAncestries)throw"ds.cohort.termdb.restrictAncestries missing";const r=n.cohort.termdb.restrictAncestries.find((e=>e.name==t.q.restrictAncestry.name));if(!r)throw"unknown ancestry for restriction: "+t.q.restrictAncestry.name;if(r.pcs)t.q.restrictAncestry.pcs=r.pcs;else{if(!r.PCfileBySubcohort)throw"unknown way of accessing pcs from ds.cohort.termdb.restrictAncestries: "+t.q.restrictAncestry.name;{if(!e.filter)throw"q.filter missing while trying to access subcohort for PCfileBySubcohort";const n=C(e.filter,"cohortFilter");if(!n)throw"tvs by tag=cohortFilter missing from q.filter.lst[] while trying to access subcohort for PCfileBySubcohort";const o=n.tvs.values.map((t=>t.key)).sort().join(","),i=r.PCfileBySubcohort[o];if(!i)throw"unknown key for PCfileBySubcohort: "+o;if(!i.pcs)throw"pcs Map() missing from PCfileBySubcohort[]: "+o;t.q.restrictAncestry.pcs=i.pcs}}}function w(t,e,n){const o={id:t.id,name:t.term.name,type:"spline"==t.q.mode?"spline":"other",rtype:"continuous"==t.q.mode||"spline"==t.q.mode?"numeric":"factor"};if(t.interactions.length>0){o.interactions=[];for(const e of t.interactions){const t=n.independent.find((t=>t.id==e));if("snplst"==t.type)for(const e of t.highAFsnps.keys())o.interactions.push(e);else{if("snplocus"==t.type)continue;o.interactions.push(e)}}}"factor"===o.rtype&&(o.refGrp=t.refGrp),"spline"==t.q.mode&&(o.spline={knots:t.q.knots.map((t=>Number(t.value)))},n.independent.find((t=>"snplocus"==t.type))||(o.spline.plotfile=r.join(c.cachedir,Math.random().toString()+".png"))),e.push(o)}function x(t,e,n){for(const r of t.highAFsnps.keys()){const o={id:r,name:r,type:t.type};3==t.q.geneticModel?(o.rtype="factor",o.refGrp=t.q.snp2refGrp[r]):o.rtype="numeric";for(const e of n.independent)e.interactions.includes(t.id)&&(o.interactions||(o.interactions=[]),o.interactions.push(e.id));e.push(o)}if(t.q.restrictAncestry)for(const n of t.q.restrictAncestry.pcs.keys())e.push({id:n,name:n,type:"float",rtype:"numeric"})}function k(t){if("condition"==t.term.type){for(const e of t.q.groups)if(e.name!=t.refGrp)return e;throw"nonref group not found for logistic outcome"}if("predefined-groupset"==t.q.type){if(!t.q.groupsetting)throw"outcome.q.groupsetting{} missing when type=predefined-groupset";if(!Number.isInteger(t.q.groupsetting.predefined_groupset_idx))throw'outcome.q.predefined_groupset_idx not integer when q.type is "predefined-groupset"';if(!t.term.groupsetting)throw"outcome.term.groupsetting missing";const e=t.term.groupsetting.lst[t.q.groupsetting.predefined_groupset_idx];if(!e)throw"groupset not found by outcome.q.predefined_groupset_idx";const n=e.groups.find((e=>e.name!=t.refGrp));if(!n)throw"non-ref group not found for predefined-groupset";return n.name}if("custom-groupset"==t.q.type){if(!t.q.groupsetting)throw"outcome.q.groupsetting{} missing when type=predefined-groupset";if(!t.q.groupsetting.customset)throw"outcome.q.customset missing";const e=t.q.groupsetting.customset.groups.find((e=>e.name!=t.refGrp));if(!e)throw"non-ref group not found for custom-groupset";return e.name}if("values"==t.q.type){if(!t.term.values)throw"outcome.term.values{} missing";for(const e in t.term.values){const n=t.term.values[e];if(n.label!=t.refGrp)return n.label}throw"unknown nonref group from outcome.term.values"}if("custom-bin"==t.q.type){const e=t.q.lst.find((e=>e.label!=t.refGrp));if(!e)throw"non-ref bin is not found for custom-bin";return e.label}if("regular-bin"==t.q.type)throw"do not know a way to find computed bin list for type=regular-bin";throw"unknown outcome.q.type"}async function q(t,e,n,o){g=(new Date).getTime();const i=r.join(c.cachedir,Math.random().toString()+".json");await u.write_file(i,JSON.stringify(t));const f=await s(r.join(c.binpath,"utils","regression.R"),[],[i]);a.unlink(i,(()=>{})),await async function(t,e,n,r,o){if(1!=e.length)throw"expected 1 json line in R output";const i=JSON.parse(e[0]),s=i.data;v["regression.R"]=i.benchmark;for(const e of s){const i={data:{sampleSize:e.data.sampleSize,eventCnt:e.data.eventCnt?e.data.eventCnt:null}};if(e.id){const t=n[e.id];i.id=t;const o=r.independent.find((t=>"snplocus"==t.type));if(!o)throw"snplocus term missing";i.AFstr=o.snpid2AFstr.get(t),i.data.headerRow=S(t,o)}const s=e.data;if(s.residuals&&(i.data.residuals=s.residuals,i.data.residuals.label="linear"==t.regressionType?"Residuals":"Deviance residuals"),"cox"==t.regressionType){if(s.coefficients.rows.length<1)throw"fewer than 1 row in coefficients table"}else if(s.coefficients.rows.length<2)throw"fewer than 2 rows in coefficients table";i.data.coefficients={header:s.coefficients.header,intercept:"cox"==t.regressionType?null:s.coefficients.rows.shift(),terms:{},interactions:[]};for(const t of s.coefficients.rows)if(-1!=t[0].indexOf(":")){const e={},[r,o]=t.shift().split(":"),[s,a]=t.shift().split(":");e.term1=n[r],e.category1=s,e.term2=n[o],e.category2=a,e.lst=t,i.data.coefficients.interactions.push(e)}else{const e=t.shift(),r=t.shift(),o=n[e];i.data.coefficients.terms[o]||(i.data.coefficients.terms[o]={}),r?(i.data.coefficients.terms[o].categories||(i.data.coefficients.terms[o].categories={}),i.data.coefficients.terms[o].categories[r]=t):i.data.coefficients.terms[o].fields=t}i.data.coefficients.label="Coefficients",i.data.type3={header:s.type3.header,terms:{},interactions:[]},"cox"!=t.regressionType&&(i.data.type3.intercept=s.type3.rows.shift());for(const t of s.type3.rows)if(-1!=t[0].indexOf(":")){const e={},[r,o]=t.shift().split(":");e.term1=n[r],e.term2=n[o],e.lst=t,i.data.type3.interactions.push(e)}else{const e=n[t.shift()];i.data.type3.terms[e]||(i.data.type3.terms[e]=t)}if(i.data.type3.label="Type III statistics",s.totalSnpEffect){if(1!=s.totalSnpEffect.rows.length)throw"total SNP effect table should have 1 row";i.data.totalSnpEffect={header:s.totalSnpEffect.header.slice(0,4)};const t=s.totalSnpEffect.rows[0].slice(0,4),e=s.totalSnpEffect.rows[0][4].split(";"),r=e.findIndex((t=>!t.includes(":"))),o=e.splice(r,1)[0];i.data.totalSnpEffect.snp=n[o];const a=[];for(const t of e){if(!t.includes(":"))throw"expected interaction";const[e,r]=t.split(":");a.push({term1:n[e],term2:n[r]})}i.data.totalSnpEffect.interactions=a,i.data.totalSnpEffect.lst=t,i.data.totalSnpEffect.label="Total SNP effect"}s.tests&&(i.data.tests=s.tests,i.data.tests.label="Statistical tests"),i.data.other=s.other,i.data.other.label="Other summary statistics";for(const e of t.independent)if(e.spline&&e.spline.plotfile){i.data.splinePlots||(i.data.splinePlots=[]);const t=e.spline.plotfile,n=await a.promises.readFile(t);i.data.splinePlots.push({src:"data:image/png;base64,"+new Buffer.from(n).toString("base64"),size:l(t)}),a.unlink(t,(t=>{if(t)throw t}))}s.warnings&&(i.data.warnings=s.warnings);const c=r.independent.find((t=>"snplst"==t.type));if(c){if(c.lowAFsnps&&c.lowAFsnps.size){i.data.warnings||(i.data.warnings=[]);for(const t of c.lowAFsnps.keys())i.data.warnings.push(`${t}: effect allele frequency below cutoff, excluded from analysis`)}if(c.monomorphicLst&&c.monomorphicLst.length){i.data.warnings||(i.data.warnings=[]);for(const t of c.monomorphicLst)i.data.warnings.push(`${t}: monomorphic, excluded from analysis`)}}o.resultLst.push(i)}}(t,f,e,n,o),y=(new Date).getTime(),v.NodeJS.runRegression=(y-g)/1e3+" sec"}async function N(t,e,n,o){const i=t.independent.find((t=>"snplocus"==t.type));if(i){if(g=(new Date).getTime(),function(t,e){for(const n of t.monomorphicLst){const r=t.snpgt2count.get(n),o=[];for(const[t,e]of r)o.push(t+"="+e);const i={id:n,data:{headerRow:S(n,t)}};e.resultLst.push(i)}}(i,o),i.lowAFsnps.size)if("linear"==t.regressionType)await async function(t,e,n,o){const i={},l=new Map;for(const[r,o]of t.lowAFsnps){let t=0,s=null,a=null;const c=[],u=[];for(const{sample:r,noOutcome:i}of e){if(i)continue;const e=n.data[t++].outcome;if(!Number.isFinite(e))continue;const l=o.samples.get(r);if(!l)continue;null==s?s=a=e:(s=Math.min(s,e),a=Math.max(a,e));const[f,d]=l.split("/");f==o.effAle||d==o.effAle?c.push(e):u.push(e)}i[r]={group1values:c,group2values:u},l.set(r,{minv:s,maxv:a})}const f=r.join(c.cachedir,Math.random().toString()+".json");await u.write_file(f,JSON.stringify(i));const d=await s(r.join(c.binpath,"utils/wilcoxon.R"),[],[f]);a.unlink(f,(()=>{}));const p=JSON.parse(d);for(const e in p){const{group1values:n,group2values:r}=i[e],{minv:s,maxv:a}=l.get(e),c=h.boxplot_getvalue(n.sort(((t,e)=>t-e)).map((t=>({value:t}))));c.label=`Carry ${0==t.q.alleleType?"minor":"alternative"} allele, n=${n.length}`;const u=h.boxplot_getvalue(r.sort(((t,e)=>t-e)).map((t=>({value:t}))));u.label=`No ${0==t.q.alleleType?"minor":"alternative"} allele, n=${r.length}`;const f={id:e,AFstr:t.snpid2AFstr.get(e),data:{headerRow:S(e,t),wilcoxon:{pvalue:p[e],boxplots:{minv:s,maxv:a,hasEff:c,noEff:u}}}};o.resultLst.push(f)}}(i,e,n,o);else if("logistic"==t.regressionType)await async function(t,e,n,r){const o=[];let i=0;const s=new Map;for(const[r,a]of t.lowAFsnps){let t=0,l=0,c=0,u=0,f=0;for(const{sample:r,noOutcome:o}of e){if(o)continue;const e=n.data[f++],i="outcome"in e?e.outcome:e.outcome_event;if(0!=i&&1!=i)throw"outcome is not 0 or 1";const s=a.samples.get(r);if(!s)continue;const[d,h]=s.split("/"),p=a.effAle==d||a.effAle==h;0==i?p?l++:t++:p?u++:c++}s.set(i,r);const d={index:i,n1:u,n2:l,n3:c,n4:t};o.push(d),i++}const a=await f("fisher",JSON.stringify({input:o}));for(const e of JSON.parse(a)){const n=s.get(e.index),{effAle:o}=t.lowAFsnps.get(n),i=e.p_value,a="chisq"===e.fisher_chisq,l={id:n,AFstr:t.snpid2AFstr.get(n),data:{headerRow:S(n,t),fisher:{isChi:a,pvalue:Number(i.toFixed(4)),rows:[["","Carry "+o+" allele","No "+o+" allele"],["Have event",e.n1,e.n3],["No event",e.n2,e.n4]]}}};r.resultLst.push(l)}}(i,e,n,o);else{if("cox"!=t.regressionType)throw"unknown regression type";await async function(t,e,n,r){const o={data:{}},i=new Set;for(const[r,s]of t.lowAFsnps){const t=[];let a=0;for(const{sample:r,noOutcome:o}of e){if(o)continue;const e=n.data[a++];if(0!==e.outcome_event&&1!==e.outcome_event)throw"d.outcome_event is not 0/1";if(!Number.isFinite(e.outcome_time))throw"d.outcome_time is not numeric";const i={time:e.outcome_time,event:e.outcome_event},l=s.samples.get(r);if(!l)continue;const[c,u]=l.split("/");i.series=s.effAle==c||s.effAle==u?"1":"2",t.push(i)}new Set(t.map((t=>t.series))).size<2?i.add(r):o.data[r]=t}const s={case:[],tests:{}};let a;await d(o,s);for(const[e,n]of t.lowAFsnps){if(i.has(e)){a={pvalue:"NA",msg:"Cannot perform cumulative incidence test on this snp - at least one allele is not found in any sample"}}else{const t=[];for(const n of s.case)n[0]==e&&t.push(n);if(!s.tests[e]||!s.tests[e].length)throw"no tests for snp";const n=Number(s.tests[e][0].pvalue);if(!Number.isFinite(n))throw"invalid pvalue";const r={};r[e]=s.tests[e],a={pvalue:Number(n.toFixed(4)),final_data:{case:t,tests:r}}}const n={id:e,AFstr:t.snpid2AFstr.get(e),data:{headerRow:S(e,t),cuminc:a}};r.resultLst.push(n)}}(i,e,n,o)}y=(new Date).getTime(),v.NodeJS.snplocusPostprocess=(y-g)/1e3+" sec"}}function S(t,e){const n=e.snpgt2count.get(t);if(!n)return{k:"Error",v:"Variant not found"};if(e.monomorphicLst.includes(t)){const[t,e]=[...n][0];return{k:"Genotype",v:t+"="+e}}const r=[`${0==e.q.alleleType?"Minor":"Alternative"} allele=${e.highAFsnps.has(t)?e.highAFsnps.get(t).effAle:e.lowAFsnps.get(t).effAle}`,"AF="+e.snpid2AFstr.get(t)];for(const[t,e]of n)r.push(t+"="+e);return{k:"Variant:",v:r.join(" ")}}function A(t,e,n){if(t.q.restrictAncestry)for(const[n,r]of t.q.restrictAncestry.pcs)for(const[t,o]of r)e.has(t)&&e.get(t).id2value.set(n,{key:o,value:o})}async function M(t,e,n){const o=(await u.read_file(r.join(c.cache_snpgt.dir,t.q.cacheid))).split("\n"),i=o[0].split("\t").slice(c.cache_snpgt.sampleColumn).map(Number);if(n)for(const t of i)e.set(t,{id2value:new Map});const s=i.map((t=>e.has(t))),a=new Map;for(let e=1;e<o.length;e++){const n=o[e].split("\t"),r=n[0],l={refAle:n[3],altAles:n[4].split(","),samples:new Map};t.q.snp2effAle?l.effAle=t.q.snp2effAle[r]:l.effAle=l.altAles[0],a.set(r,l);for(const[t,e]of i.entries()){if(!s[t])continue;const o=n[t+c.cache_snpgt.sampleColumn];o&&a.get(r).samples.set(e,o)}}"snplocus"!=t.type&&function(t,e,n,r){if(0==e.q.missingGenotype){for(const e of t.values()){let t;if(e.refAle!=e.effAle)t=e.refAle;else for(const n of e.altAles)if(n!=e.effAle){t=n;break}if(!t)throw"not finding a non-effect allele";for(const[o,i]of n.entries())r[o]&&(e.samples.has(i)||e.samples.set(i,t+"/"+t))}return}if(1==e.q.missingGenotype)throw"not done";if(2==e.q.missingGenotype){const e=new Set;for(const{samples:o}of t.values())for(const[t,i]of n.entries())r[t]&&(o.has(i)||e.add(i));for(const{samples:n}of t.values())for(const t of e)n.delete(t);return}throw"invalid missingGenotype value"}(a,t,i,s),t.snpgt2count=new Map;for(const[e,n]of a){const r=new Map;for(const[t,e]of n.samples)r.set(e,1+(r.get(e)||0));t.snpgt2count.set(e,r)}!function(t,e){t.lowAFsnps=new Map,t.highAFsnps=new Map,t.monomorphicLst=[],t.snpid2AFstr=new Map;for(const[n,r]of e){if(1==t.snpgt2count.get(n).size){t.monomorphicLst.push(n);continue}const e=r.samples.size;let o=0;for(const[t,e]of r.samples){const[t,n]=e.split("/");o+=(t==r.effAle?1:0)+(n==r.effAle?1:0)}const i=o/(2*e);t.snpid2AFstr.set(n,(100*i).toFixed(1)+"%"),i<t.q.AFcutoff/100?t.lowAFsnps.set(n,r):t.highAFsnps.set(n,r)}}(t,a);for(const[n,r]of t.highAFsnps)for(const[o,i]of r.samples){const[s,a]=i.split("/"),l=T(t,r.effAle,s,a);e.get(o).id2value.set(n,{key:l,value:l})}}function T(t,e,n,r){switch(t.q.geneticModel){case 0:return(n==e?1:0)+(r==e?1:0);case 1:return n==e||r==e?1:0;case 2:return n==e&&r==e?1:0;case 3:return n+"/"+r;default:throw"unknown geneticModel option"}}function C(t,e){if(t.tag===e)return t;if("tvslst"===t.type)for(const n of t.lst){const t=C(n,e);if(t)return t}}},2188:(t,e,n)=>{"use strict";n.d(e,{uR:()=>b,v8:()=>S,wz:()=>v});var r=n(2974),o=n(1017),i=n.n(o),s=n(3856),a=n(334),l=n.n(a),c=n(2273),u=n(2852),f=n(5257),d=n(6191),h=n.n(d),p=n(9157),m=n.n(p);const g=n(3856).write_file,y="#F5F5DC";async function v(t){if(t.cohort.scatterplots){if(!Array.isArray(t.cohort.scatterplots.plots))throw"cohort.scatterplots.plots is not array";for(const e of t.cohort.scatterplots.plots){if(!e.name)throw".name missing from one of scatterplots.plots[]";if(!e.file)throw"unknown data source of one of scatterplots.plots[]";{const n=(await s.read_file(i().join(l().tpmasterdir,e.file))).trim().split("\n"),r=n[0].split("\t");e.filterableSamples=[];const o=[];let a=0,c=0;for(let i=1;i<n.length;i++){const s=n[i].split("\t"),l=Number(s[1]),u=Number(s[2]);if(Number.isNaN(l)||Number.isNaN(u)){a++;continue}const f={sample:s[0],x:l,y:u},d=t.cohort.termdb.q.sampleName2id(s[0]);if(null==d){if(r[3]){f.info={};for(let t=3;t<r.length;t++)f.info[r[t]]=s[t]}o.push(f)}else c++,f.sampleId=d,e.filterableSamples.push(f)}o.length&&(e.referenceSamples=o),console.log(e.filterableSamples.length,`scatterplot lines from ${e.name} of ${t.label},`,e.referenceSamples?e.referenceSamples.length+" reference cases":"",a?a+" lines with invalid X/Y values":"")}}}}async function b(t,e,n,o,i){try{let s,a;if(2==e.coordTWs.length)s=[],a=await async function(t,e,n){e.ds=n;const r=[];if(2!=e.coordTWs.length)return r;const o=await(0,f.getFilterCTEs)(e.filter,e.ds);let i="";o&&(i+=(0,u.interpolateSqlValues)(`WITH ${o.filters}`,o.values.slice()));const s=e.coordTWs[0].term,a=e.coordTWs[1].term;let l;e.divideByTW&&"continuous"==e.divideByTW.q.mode&&(l=e.divideByTW.term);i+=`SELECT ax.sample AS sampleId, ax.value as x, ay.value AS y , ${l?"az.value AS z":"0 as z"}\n\t\t\tFROM anno_${s.type} ax \n\t\t\tJOIN anno_${a.type} ay on ax.sample = ay.sample and ay.term_id = '${a.id}' \n\t\t\t${l?`JOIN anno_${l.type} az on ax.sample = az.sample and az.term_id = '${l.id}' `:""}\n\t\t\tWHERE ax.term_id = '${s.id}'`,o&&(i+=` AND ax.sample IN ${o.CTEname}`);const c=e.ds.cohort.db.connection.prepare(i).all(),d=h().canDisplaySampleIds(t,n);for(const{sampleId:t,x:o,y:i,z:s}of c){var p;if(null!==(p=l)&&void 0!==p&&p.values&&s in l.values)continue;const a={sampleId:t,x:o,y:i,z:s};d&&(a.sample=n.sampleId2Name.get(t));const c=N(e.coordTWs[0].term,o)&&N(e.coordTWs[1].term,i);a&&c&&r.push(a)}return r}(t,e,o);else{if(!e.plotName)throw"Neither plot name or coordinates where provided";if(!o.cohort.scatterplots||!o.cohort.scatterplots.plots)throw"not supported";const t=o.cohort.scatterplots.plots.find((t=>t.name==e.plotName));if(!t)throw`plot not found with plotName ${e.plotName}`;const n=await async function(t,e,n){if(n.filterableSamples){let t=[],e=[];return n.referenceSamples&&(e=r(n.referenceSamples)),n.filterableSamples&&(t=r(n.filterableSamples)),[e,t]}if(n.gdcapi)throw"gdcapi not implemented yet";throw"do not know how to load data from this plot";function r(t){const e=[];for(const n of JSON.parse(JSON.stringify(t)))e.push(n);return e}}(0,0,t);s=n[0],a=n[1]}const l=[];e.coordTWs&&l.push(...e.coordTWs),e.colorTW&&l.push(e.colorTW),e.shapeTW&&l.push(e.shapeTW),e.divideByTW&&l.push(e.divideByTW);const d=await(0,r.getData)({filter:e.filter,terms:l},o,i);if(d.error)throw d.error;const p=await async function(t,e,n,r){const o={};for(const c of e){const e=n.samples[c.sampleId.toString()];if(!e&&r.colorTW){console.log(JSON.stringify(c)+" not in the database or filtered");continue}if(r.colorTW&&!_(e,r.colorTW)||r.shapeTW&&!_(e,r.shapeTW))continue;let f="Default";if(r.divideByTW&&"continuous"!=r.divideByTW.q.mode)if(c.z=0,"geneVariant"==r.divideByTW.term.type)f=x(!0,e,r.divideByTW)||x(!1,e,r.divideByTW);else{var i,s,a;const t=null===(i=e[r.divideByTW.term.id||r.divideByTW.term.name])||void 0===i?void 0:i.key;f=(null===(s=r.divideByTW.term.values)||void 0===s||null===(a=s[t])||void 0===a?void 0:a.label)||t}if(!o[f]){const e=t.map((t=>({...t,category:"Ref",shape:"Ref",z:0})));o[f]={samples:e,colorMap:{},shapeMap:{}}}var l,u;if(r.divideByTW||(c.z=0),c.cat_info={},c.hidden={},r.colorTW)"continuous"===(null===(l=r.colorTW)||void 0===l||null===(u=l.q)||void 0===u?void 0:u.mode)?e&&(c.category=e[r.colorTW.term.id||r.colorTW.term.name].value):w(e,c,r.colorTW,o[f].colorMap,"category");else c.category="Default";r.shapeTW?w(e,c,r.shapeTW,o[f].shapeMap,"shape"):c.shape="Ref",o[f].samples.push(c)}let f=0;for(const[t,e]of Object.entries(o))f=Math.max(f,Object.keys(e.colorMap).length);const d=(0,c.getColors)(f);for(const[i,s]of Object.entries(o)){var h,p,m;if(r.colorTW&&"continuous"!==r.colorTW.q.mode){let t=20;const e=c.schemeCategory20,o=Object.entries(s.colorMap);for(const[i,s]of o){var g,v,b,k;let o;if(null!==(g=r.colorTW.term.values)&&void 0!==g&&g[i])o=null===(v=r.colorTW.term.values)||void 0===v?void 0:v[i];else for(const t in r.colorTW.term.values){var N,S;(null===(N=r.colorTW.term.values)||void 0===N?void 0:N[t].label)==i&&(o=null===(S=r.colorTW.term.values)||void 0===S?void 0:S[t])}if(o&&"color"in o)s.color=o.color;else if(null!==(b=n.refs)&&void 0!==b&&null!==(k=b.byTermId[r.colorTW.term.id])&&void 0!==k&&k.bins){const o=n.refs.byTermId[r.colorTW.term.id].bins.find((t=>t.name===i));o?s.color=o.color:(s.color=e[t],t--)}else"geneVariant"!=r.colorTW.term.type&&(s.color=d(i))}}let o=1;for(const[t,e]of Object.entries(s.shapeMap))"shape"in e||(e.shape=o),o++;s.colorLegend=r.colorTW?q(s.colorMap,r.colorTW,n.refs):[["Default",{sampleCount:e.length,color:"blue"}]],s.colorLegend.push(["Ref",{sampleCount:t.length,color:null!==(h=r.colorTW)&&void 0!==h&&null!==(p=h.term.values)&&void 0!==p&&p.Ref?null===(m=r.colorTW.term.values)||void 0===m?void 0:m.Ref.color:y}]),s.shapeLegend=q(s.shapeMap,r.shapeTW,n.refs),s.shapeLegend.push(["Ref",{sampleCount:t.length,shape:0}])}return o}(s,a,d,e);n.send(p)}catch(t){t.stack&&console.log(t.stack),n.send({error:t.message||t})}}function _(t,e){var n,r,o;const i=void 0!==(null==t||null===(n=t[(null==e||null===(r=e.term)||void 0===r?void 0:r.id)||(null==e||null===(o=e.term)||void 0===o?void 0:o.name)])||void 0===n?void 0:n.key);return i||console.log(JSON.stringify(t)+" missing value for the term "+JSON.stringify(e)),i}function w(t,e,n,r,o){let i=null;var s,a,l,u,f,d;"geneVariant"==n.term.type?function(t,e,n,r,o){if("geneVariant"==n.term.type){var i;const s=null==t||null===(i=t[n.term.name])||void 0===i?void 0:i.values;e.cat_info[o]=[];for(const t of s){const n=c.mclass[t.class],i=k(t);let s;e.cat_info[o].push(t),null==r[i]?(s={color:n.color,sampleCount:1,hasOrigin:"origin"in t},r[i]=s):(s=r[i],s.sampleCount=s.sampleCount+1,s.hasOrigin=s.hasOrigin||"origin"in t)}e[o]=x(!0,t,n)||x(!1,t,n),e[o]||(e[o]=k(s[0])),e.hidden[o]=!!n.q.hiddenValues&&e[o]in n.q.hiddenValues}}(t,e,n,r,o):(i=null==t||null===(s=t[n.id||n.term.name])||void 0===s?void 0:s.key,null!==(a=n.term.values)&&void 0!==a&&null!==(l=a[i])&&void 0!==l&&l.label&&(i=null===(u=n.term.values)||void 0===u||null===(f=u[i])||void 0===f?void 0:f.label),e.hidden[o]=!!n.q.hiddenValues&&(null==t||null===(d=t[n.id])||void 0===d?void 0:d.key)in n.q.hiddenValues,i&&(e[o]=i.toString(),null==r[i]?r[i]={sampleCount:1}:r[i].sampleCount++))}function x(t,e,n){var r;const o=null==e||null===(r=e[n.term.name])||void 0===r?void 0:r.values;for(const[e,r]of Object.entries(c.dt2label)){const r=o.find((t=>{const r=k(t),o=!(n.q.hiddenValues&&r in n.q.hiddenValues);return t.dt==e&&o}));if(!r)continue;if(t&&("WT"==r.class||"Blank"==r.class))continue;return k(r)}}function k(t){var e;const n=t.dt,r=c.mclass[t.class],o=null===(e=c.morigin[t.origin])||void 0===e?void 0:e.label,i=o?`${o[0]} ${c.dt2label[n]}`:c.dt2label[n];return`${r.label},${i}`}function q(t,e,n){var r;let o=[];if(!e||0==t.size)return o;if("geneVariant"==e.term.type)o=Object.entries(t),o.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0));else if(null!=n&&null!==(r=n.byTermId[e.term.id])&&void 0!==r&&r.bins){const r=n.byTermId[e.term.id].bins;for(const e of r)t[e.name]&&o.push([e.name,t[e.name]]);for(const[e,n]of Object.entries(t))o.some((t=>t[0]===e))||o.push([e,n])}else o=Object.entries(t),o.sort(((t,n)=>{var r;const o=null===(r=e.term.values)||void 0===r?void 0:r[t[0]];if(o&&"order"in o){const t=e.term.values[n[0]];return(null==o?void 0:o.order)<(null==t?void 0:t.order)?-1:1}return t[1].sampleCount>n[1].sampleCount?-1:1}));return o}function N(t,e){var n,r;return!(null!==(n=t.values)&&void 0!==n&&null!==(r=n[e])&&void 0!==r&&r.uncomputable)}async function S(t,e,n){const r=e.coords,o=i().join(l().cachedir,Math.random().toString()+".json");await g(o,JSON.stringify(r));let s=await m()(i().join(l().binpath,"utils/lowess.R"),[],[o]);s=JSON.parse(s);const a=[];for(const[t,e]of Object.entries(s.x))a.push([e,s.y[t]]);return n.send(a)}},394:(t,e,n)=>{"use strict";n.r(e),n.d(e,{listDbTables:()=>l,mayComputeTermtypeByCohort:()=>c,server_init_db_queries:()=>a});var r=n(334),o=n.n(r),i=n(3856),s=n(1575);function a(t){if(!t.cohort)throw"ds.cohort missing";if(!t.cohort.db)throw"ds.cohort.db missing";if(!t.cohort.termdb)throw"ds.cohort.termdb missing";const e=t.cohort.db.file_fullpath||t.cohort.db.file;if(!e)throw"both file and file_fullpath missing";let n;try{console.log("Connecting",e),n=(0,i.connect_db)(e),console.log(`DB connected for ${t.label}: ${e}`)}catch(t){throw`Cannot connect db ${e}: ${t.message||t}`}t.cohort.db.connection=n;const r=l(n);if(!r.has("terms"))throw"terms table missing";if(!r.has("ancestry"))throw"ancestry table missing";if(t.cohort.termdb.selectCohort&&!r.has("subcohort_terms"))throw"subcohort_terms table is missing while termdb.selectCohort is enabled";t.cohort.termdb.q={};const a=t.cohort.termdb.q;if(r.has("buildDate")&&(a.get_buildDate=n.prepare("select date from buildDate")),r.has("term2genes")){t.cohort.termdb.termMatch2geneSet=!0;const e=n.prepare("SELECT genes FROM term2genes WHERE id=?"),r=new Map;a.getGenesetByTermId=t=>{if(r.has(t))return r.get(t);const n=e.get(t);if(n&&n.genes){const e=JSON.parse(n.genes);return r.set(t,e),e}}}if(r.has("sampleidmap")){const e=new Map,r=new Map,o=n.prepare("SELECT * FROM sampleidmap");let i=0;for(const{id:t,name:n}of o.all())e.set(t,n),r.set(n,t),i++;if(a.id2sampleName=t=>e.get(t),a.sampleName2id=t=>r.get(t),t.cohort.termdb.selectCohort){const t=n.prepare("SELECT cohort,sample_count from cohorts").all(),e={};for(const n of t)e[n.cohort]=n.sample_count;a.getcohortsamplecount=t=>t?e[t]||0:i}else a.getcohortsamplecount=()=>i}if(r.has("category2vcfsample")){const t=n.prepare("SELECT * FROM category2vcfsample");let e;a.getcategory2vcfsample=()=>{if(e)return e;e=t.all();for(const t of e)t.q=JSON.parse(t.q),t.categories=JSON.parse(t.categories);return e}}if(r.has("alltermsbyorder")){const t=n.prepare("SELECT * FROM alltermsbyorder");let e;a.getAlltermsbyorder=()=>{if(e)return e;const n=t.all();e=[];for(const t of n){const n=a.termjsonByOneid(t.id);n&&e.push({group_name:t.group_name,term:n})}return e}}{const t=n.prepare("SELECT name, jsondata FROM terms WHERE id=?"),e=new Map;a.termjsonByOneid=n=>{if(e.has(n))return e.get(n);const r=t.get(n);if(r){const t=JSON.parse(r.jsondata);return t.id=n,t.name=r.name||t.name,e.set(n,t),t}}}{const t=n.prepare("select id from terms where parent_id=?"),e=new Map;a.termIsLeaf=n=>{if(e.has(n))return e.get(n);let r=!0;const o=t.get(n);return o&&o.id&&(r=!1),e.set(n,r),r}}{const t=n.prepare("SELECT id, name, jsondata, s.included_types, s.child_types\n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=?\n\t\t\tWHERE parent_id is null\n\t\t\tGROUP BY id\n\t\t\tORDER BY child_order ASC"),e=new Map;a.getRootTerms=(n="")=>{const r=n;if(e.has(r))return e.get(r);const o=t.all(n).map((t=>{const e=JSON.parse(t.jsondata);return e.id=t.id,e.name=t.name||e.name,e.included_types=t.included_types?t.included_types.split(","):["TO-DO-PLACEHOLDER"],e.child_types=t.child_types?t.child_types.split(","):[],e}));return e.set(r,o),o}}{const t=n.prepare("SELECT parent_id FROM terms WHERE id=?");{const e=new Map;a.termHasParent=n=>{if(e.has(n))return e.get(n);let r=!1;const o=t.get(n);return o&&o.parent_id&&(r=!0),e.set(n,r),r}}{const e=new Map;a.getTermParentId=n=>{if(e.has(n))return e.get(n);let r;const o=t.get(n);return o&&o.parent_id&&(r=o.parent_id),e.set(n,r),r}}{const t=new Map;a.getTermParent=e=>{if(t.has(e))return t.get(e);const n=a.getTermParentId(e);let r;return n&&(r=a.termjsonByOneid(n)),t.set(e,r),r}}}{const t=n.prepare("SELECT id, name, type, jsondata, s.included_types, s.child_types \n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=? \n\t\t\tWHERE id IN (SELECT id FROM terms WHERE parent_id=?)\n\t\t\tGROUP BY id\n\t\t\tORDER BY child_order ASC"),e=new Map;a.getTermChildren=(n,r="")=>{const o=n+";;"+r;if(e.has(o))return e.get(o);const i=t.all([r,n]);let s;return i&&(s=i.map((t=>{const e=JSON.parse(t.jsondata);return e.id=t.id,e.name=t.name||e.name,e.included_types=t.included_types?t.included_types.split(","):[],e.child_types=t.child_types?t.child_types.split(","):[],e}))),e.set(o,s),s}}{const t=n.prepare("SELECT id, name, jsondata, s.included_types\n\t\t\tFROM terms t\n\t\t\tJOIN subcohort_terms s ON s.term_id = t.id AND s.cohort=?\n\t\t\tWHERE name LIKE ?");a.findTermByName=(e,n=10,r="",o=null,i=null,a=null)=>{const l=t.all([r,"%"+e+"%"]);if(l){const t=a||{equals:[],startsWith:[],startsWord:[],includes:[]};for(const n of l){if(!n.jsondata)continue;const r=n.name.toLowerCase(),o=JSON.parse(n.jsondata);o.id=n.id,o.name=n.name||o.name,o.included_types=n.included_types?n.included_types.split(","):[],i&&!(0,s.CG)(o,i).has("plot")||(r===e?t.equals.push(o):r.startsWith(e)?t.startsWith.push(o):r.includes(" "+e)?t.startsWord.push(o):t.includes.push(o))}return[...t.equals,...t.startsWith,...t.startsWord,...t.includes].slice(0,n)}}}{const t=n.prepare("SELECT MAX(value) AS v FROM anno_integer WHERE term_id=?"),e=n.prepare("SELECT MAX(value) AS v FROM anno_float WHERE term_id=?"),r=new Map;a.findTermMaxvalue=(n,o)=>{if(r.has(n))return r.get(n);const i=(o?t:e).get(n);return i?(r.set(n,i.v),i.v):void 0}}{const t=n.prepare("SELECT ancestor_id FROM ancestry WHERE term_id=?"),e=new Map;a.getAncestorIDs=n=>{if(e.has(n))return e.get(n);const r=t.all(n).map((t=>t.ancestor_id));return e.set(n,r),r}}{const t=n.prepare("SELECT t.name FROM ancestry as a, terms as t WHERE a.term_id=? AND t.id=a.ancestor_id"),e=new Map;a.getAncestorNames=n=>{if(e.has(n))return e.get(n);const r=t.all(n).map((t=>t.name));return e.set(n,r),r}}{const t={categorical:n.prepare("SELECT value FROM anno_categorical WHERE term_id=?"),integer:n.prepare("SELECT value FROM anno_integer WHERE term_id=?"),float:n.prepare("SELECT value FROM anno_float WHERE term_id=?")},e={categorical:n.prepare("SELECT value FROM anno_categorical WHERE term_id=? AND sample=?"),integer:n.prepare("SELECT value FROM anno_integer WHERE term_id=? AND sample=?"),float:n.prepare("SELECT value FROM anno_float WHERE term_id=? AND sample=?")},r={categorical:n.prepare("SELECT value FROM anno_categorical a,sampleidmap s WHERE term_id=? AND s.name=?"),integer:n.prepare("SELECT value FROM anno_integer a,sampleidmap s WHERE term_id=? AND s.name=?"),float:n.prepare("SELECT value FROM anno_float a, sampleidmap s WHERE term_id=? AND s.name=?")};a.getSample2value=(n,o=null)=>{const i=a.termjsonByOneid(n);return o?"string"==typeof o?r[i.type].all(n,o):e[i.type].all(n,o):t[i.type].all(n)}}if(r.has("termhtmldef")){const t=n.prepare("SELECT jsonhtml FROM termhtmldef WHERE id=?"),e=new Map;a.getTermInfo=n=>{if(e.has(n))return e.get(n);const r=t.get(n);if(r){const t=JSON.parse(r.jsonhtml);return t.id=n,e.set(n,t),t}}}a.getSupportedChartTypes=e=>{var n;c(t);const r=null===(n=o().dsCredentials)||void 0===n?void 0:n[t.label],i={},s={};for(const n of t.cohort.termdb.termtypeByCohort){var a;if(n.type){var l,u;if(!(n.cohort in i))i[n.cohort]=new Set(["regression","summary"]),t.cohort.scatterplots&&i[n.cohort].add("sampleScatter"),s[n.cohort]=0,null!==(l=t.cohort.allowedChartTypes)&&void 0!==l&&l.includes("matrix")&&i[n.cohort].add("matrix"),(!r||null!==(u=r.embedders)&&void 0!==u&&u[e])&&i[n.cohort].add("dataDownload");null!==(a=o().features)&&void 0!==a&&a.draftChartTypes&&i[n.cohort].add(...o().features.draftChartTypes),"survival"!=n.type||i[n.cohort].has("survival")||i[n.cohort].add("survival"),"condition"!=n.type||i[n.cohort].has("cuminc")||i[n.cohort].add("cuminc"),"float"!=n.type&&"integer"!=n.type||(s[n.cohort]+=n.samplecount)}}for(const t in s)s[t]>1&&i[t].add("sampleScatter");for(const t in i)i[t]=[...i[t]];if(t.cohort.allowedChartTypes)for(const e in i)i[e]=i[e].filter((e=>t.cohort.allowedChartTypes.includes(e)));if(t.queries){if(t.queries.snvindel||t.queries.trackLst)for(const t in i)i[t].push("genomeBrowser");if(t.queries.geneExpression)for(const t in i)i[t].push("geneExpression")}return i}}function l(t){const e=t.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();return new Set(e.map((t=>t.name)))}function c(t){var e,n;if(t.cohort.termdb.termtypeByCohort){if(!Array.isArray(t.cohort.termdb.termtypeByCohort))throw"termtypeByCohort is not array"}else{if(null===(e=t.cohort)||void 0===e||null===(n=e.db)||void 0===n||!n.connection)throw"termtypeByCohort[] not set but cohort.db.connection missing";t.cohort.termdb.termtypeByCohort=t.cohort.db.connection.prepare("WITH c AS (\n\t\t\tSELECT cohort, term_id\n\t\t\tFROM subcohort_terms s\n\t\t\tGROUP BY cohort, term_id\n\t\t) \n\t\tSELECT cohort, type, count(*) as samplecount\n\t\tFROM terms t\n\t\tJOIN c ON c.term_id = t.id\n\t\tGROUP BY cohort, type").all()}}},3795:(t,e,n)=>{"use strict";n.r(e),n.d(e,{add_bcf_variant_filter:()=>p,validate:()=>h});const r=n(7147),o=n(1017),i=n(3856),s=n(2852),a=(n(7860),n(4521),n(334)),{compute_mclass:l}=n(3625),c="%CHROM\t%POS\t%REF\t%ALT[\t%TGT]\n",u="%POS\t%ID\t%REF\t%ALT\t%INFO[\t%TGT]\n",f=".",d=1e3;async function h(t,e,n,h){try{if(t.sumSamples)return await async function(t,e,n,r){if(!t.cacheid)throw"cacheid missing";if(a.cache_snpgt.fileNameRegexp.test(t.cacheid))throw"invalid cacheid";let l,c;if(n.track){if(l=n.track.vcf,!l)throw"ds.track.vcf missing"}else l=n.queries.snvindel.byrange._tk;if(t.filter){const e=new Set((await s.get_samples(t.filter,n)).map((t=>t.id)));if(0==e.size)throw"no samples from filter";c=l.samples.map((t=>e.has(t.name)))}else c=l.samples.map((t=>!0));const u=(await i.read_file(o.join(a.cache_snpgt.dir,t.cacheid))).split("\n"),f=new Set,d=[];for(let t=1;t<u.length;t++){const e=u[t].split("\t"),n=e[0],r=e[3],o={},i={};for(let t=a.cache_snpgt.sampleColumn;t<e.length;t++){const n=e[t];if(!n)continue;if(!c[t-a.cache_snpgt.sampleColumn])continue;f.add(l.samples[t-a.cache_snpgt.sampleColumn].name),i[n]=1+(i[n]||0);const r=n.split("/");for(const t of r)o[t]=1+(o[t]||0)}const s=[];for(const t in o)s.push({allele:t,count:o[t],isRef:t==r});d.push({snpid:n,alleles:s,gt2count:i})}return{numOfSampleWithAnyValidGT:f.size,snps:d}}(t,0,n);if(t.snptext)return await async function(t,e,n){if(!n.snp)throw"snp not supported by genome";if(!t.snptext)throw".snptext missing";const s=function(t){const e=[];for(const n of t.trim().split("\n")){const[t,r]=n.trim().split(/[\s\t]/);if(t&&t.startsWith("rs")){if(e.find((e=>e.rsid==t)))continue;const n={rsid:t,snpid:t};r&&(n.effectAllele=r),e.push(n)}else e.push({rsid:t,snpid:t,invalid:"INVALID RSID"})}return e}(t.snptext);if(!s.length)throw"no snps";await async function(t,e){for(const n of t)if(!n.invalid)if(n.chr&&"string"==typeof n.chr){const t=e.chrlookup[n.chr.toUpperCase()];if(!t){n.invalid=!0;continue}if(!Number.isInteger(n.pos)){n.invalid=!0;continue}if(n.pos<=0||n.pos>=t.len){n.invalid=!0;continue}}else if(n.rsid){const t=await i.query_bigbed_by_name(e.snp.bigbedfile,n.rsid),r=[];for(const n of t){const t=n.split("\t"),o=e.chrlookup[t[0].toUpperCase()];o&&o.major&&r.push(t)}if(0==r.length){n.invalid=!0;continue}const o=r[0];n.chr=o[0],n.pos=Number.parseInt(o[1]),n.dbsnpRef=o[4],n.dbsnpAlts=o[6].split(",").filter(Boolean)}else n.invalid=!0;if(!t.find((t=>!t.invalid)))throw"no valid variants"}(s,n);const l=await async function(t,e,n){let s;if(n.track){if(s=n.track.vcf,!s)throw"ds.track.vcf missing"}else s=n.queries.snvindel.byrange._tk;const l=new Set,u=[];for(const t of e){if(t.invalid)continue;let e;var d;if(s.chr2files){if(e=null===(d=s.chr2files)||void 0===d?void 0:d[t.chr].file,!e)throw"chr not in chr2files"}else if(s.chr2bcffile){if(e=s.chr2bcffile[t.chr],!e)throw"chr not in chr2bcffile"}else e=s.file||s.url;l.add(e);const n=(s.nochr?t.chr.replace("chr",""):t.chr)+"\t"+(t.pos+1);u.push(n)}const h=o.join(a.cachedir,await i.write_tmpfile(u.join("\n"))),p=o.join(a.cachedir,await i.write_tmpfile([...l].join("\n")));await i.get_lines_bigfile({isbcf:!0,args:["query","-R",h,"-f",c,"-v",p],dir:s.dir,callback:t=>{const n=t.split("\t"),r=(s.nochr?"chr":"")+n[0],o=n[1],i=n[2],a=n[3].split(","),l=e.find((t=>{if(t.chr==r&&t.pos===o-1&&t.dbsnpRef==i&&t.dbsnpAlts.some((t=>a.includes(t))))return t}));if(l){l.referenceAllele=i,l.altAlleles=a,l.gtlst=[];for(let t=4;t<n.length;t++)l.gtlst.push(n[t]==f?"":n[t])}}}),r.unlink(h,(()=>{})),r.unlink(p,(()=>{}));const m=["snpid\tchr\tpos\tref\talt\teff\t"+s.samples.map((t=>t.name)).join("\t")];for(const t of e)t.invalid||t.gtlst&&(m.push(t.snpid+"\t"+t.chr+"\t"+t.pos+"\t"+t.referenceAllele+"\t"+t.altAlleles.join(",")+"\t"+(t.effectAllele||"")+"\t"+t.gtlst.join("\t")),delete t.gtlst);const g=t.genome+"_"+t.dslabel+"_"+new Date/1+"_"+Math.ceil(1e4*Math.random());return await i.write_file(o.join(a.cache_snpgt.dir,g),m.join("\n")),g}(t,s,e);return{snps:s,cacheid:l}}(t,n,h);if(t.chr)return await async function(t,e,n){const r=Number(t.start),s=Number(t.stop);if(!Number.isInteger(r)||!Number.isInteger(s))throw"start/stop are not integers";if(r>s||r<0)throw"invalid start/stop coordinate";let c,h;if(e.track){if(c=e.track.vcf,!c)throw"ds.track.vcf missing";if(h=c.chr2bcffile[t.chr],!h)throw"chr not in chr2bcffile"}else{var m;if(c=e.queries.snvindel.byrange._tk,c.chr2files)h=null===(m=c.chr2files)||void 0===m?void 0:m[t.chr].file;else h=c.file||c.url;if(!h)throw"no bcf file"}const g=(c.nochr?t.chr.replace("chr",""):t.chr)+":"+r+"-"+s,y=["query",h,"-r",g,"-f",u];t.variant_filter&&p(t.variant_filter,y);const v={snps:[]},b=["snpid\tchr\tpos\tref\talt\teff\t"+c.samples.map((t=>t.name)).join("\t")];return await i.get_lines_bigfile({isbcf:!0,args:y,dir:c.dir,callback:(e,n)=>{if(v.snps.length>=d)return n.kill(),void(v.reachedVariantLimit=!0);const r=e.split("\t"),o=Number(r[0])-1,i=r[2],s=r[3].split(","),a=o+"."+i+"."+s.join(","),u={snpid:a,chr:t.chr,pos:o};l(c,i,s,u,r[4],r[1]);for(const t of u.mlst)t.vcf_id&&(t.mname=t.vcf_id);v.snps.push(u);const h=[a,t.chr,o,i,s.join(","),""];for(let t=5;t<r.length;t++)h.push(r[t]==f?"":r[t]);b.push(h.join("\t"))}}),v.cacheid=t.genome+"_"+t.dslabel+"_"+new Date/1+"_"+Math.ceil(1e4*Math.random()),await i.write_file(o.join(a.cache_snpgt.dir,v.cacheid),b.join("\n")),v}(t,n);throw"unknown how to validate"}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function p(t,e){const n=[];for(const e of t.lst)if(e.tvs.values){const t=e.tvs.isnot?"!=":"=";for(const r of e.tvs.values){const o=isNaN(r.key)?`"${r.key}"`:Number(r.key);n.push(`INFO/${e.tvs.term.id}${t}${o}`)}}else{if(!e.tvs.ranges)throw`unknown tvs spec for info_field: type=${e.type}, term.id=${e.tvs.term.id}`;for(const t of e.tvs.ranges)"start"in t&&n.push(`INFO/${e.tvs.term.id} ${t.startinclusive?">=":">"} ${t.start}`),"stop"in t&&n.push(`INFO/${e.tvs.term.id} ${t.stopinclusive?"<=":"<"} ${t.stop}`)}0!=n.length&&e.push("-i",n.join(" && "))}},2747:(t,e,n)=>{"use strict";n.r(e),n.d(e,{groupset:()=>s,values:()=>o});var r=n(2852);const o={getCTE(t,e,n,o,i){i.push(e.id);const s=(0,r.getUncomputableClause)(e,o);return i.push(...s.values),{sql:`${t} AS (\n\t\t\t\tSELECT sample,value as key, value as value\n\t\t\t\tFROM anno_categorical\n\t\t\t\tWHERE term_id=? ${s.clause}\n\t\t\t)`,tablename:t}}};let i=0;const s={async getCTE(t,e,n,r,o,s){if(!s.groups)throw`.groups[] missing from a group-set, term.id='${e.id}'`;const a=[],l=[];for(const t of s.groups)if("values"==t.type)a.push(`SELECT sample, ? as key, value\n\t\t\t\t\tFROM anno_categorical a\n\t\t\t\t\tWHERE term_id=?\n\t\t\t\t\t\tAND value IN (${t.values.map((t=>"?")).join(",")})\n\t\t\t\t`),o.push(t.name,e.id,...t.values.map((t=>t.key.toString())));else{if("filter"!=t.type)throw`unsupported groupset type='${t.type}'`;if(!("activeCohort"in r.groupsetting)||!t.filter4activeCohort)throw`activeCohort error: cannot construct filter statement for group name='${t.name}', term.id=${e.id}`;{const s=t.filter4activeCohort[r.groupsetting.activeCohort],c=await getFilterCTEs(s,n,"xf"+i++);if(!c)throw`unable to construct a group='${t.name}' filter for term.id='${e.id}'`;l.push(c.filters),o.push(...c.values.slice(),t.name,t.name),a.push(`SELECT sample, ? AS key, ? AS value\n\t\t\t\t\t\tFROM ${c.CTEname}`)}}return{sql:`${l.length?l.join("\n,")+",":""}\n\t\t\t${t} AS (\n\t\t\t\t${a.join("\nUNION ALL\n")}\n\t\t\t)`,tablename:t}}}},6759:(t,e,n)=>{"use strict";function r(t){const e=t.cohort.db.connection.prepare("select * from features").all();return{cohorts:t.cohort.db.connection.prepare("select * from cohorts where cohort in (select distinct(cohort) from cohort_features)\n\t\t order by sample_count desc").all(),features:e,cfeatures:t.cohort.db.connection.prepare("select * from cohort_features").all()}}n.r(e),n.d(e,{getCohortsData:()=>r})},9723:(t,e,n)=>{"use strict";n.r(e),n.d(e,{binary:()=>i,cox:()=>a,cuminc:()=>s,discrete:()=>o});var r=n(2852);const o={getCTE(t,e,n,o,i){if(o.breaks&&o.breaks.length>0)return c(t,e,o,i);{const[n,s]=l(o);i.push(e.id);const a=(0,r.getUncomputableClause)(e,o);return i.push(...a.values),{sql:`${t} AS (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tsample,\n\t\t\t\t\t\tvalue as key,\n\t\t\t\t\t\tvalue\n\t\t\t\t\tFROM\n\t\t\t\t\t\t${"grade"==n?"precomputed_chc_grade":"precomputed_chc_child"}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id = ?\n\t\t\t\t\t\tAND ${s} = 1\n\t\t\t\t\t\t${a.clause}\n\t\t\t\t)`,tablename:t}}}},i={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"binary mode requires one break";return c(t,e,r,o)}},s={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"cuminc mode requires one break";return o.push(e.id,r.breaks[0]),{sql:`${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tevent AS key,\n\t\t\t\t\ttime AS value\n\t\t\t\tFROM\n\t\t\t\t\tprecomputed_cuminc\n\t\t\t\tWHERE\n\t\t\t\t\tterm_id = ?\n\t\t\t\t\tAND grade_cutoff = ?\n\t\t\t)`,tablename:t}}},a={getCTE(t,e,n,r,o){var i;if(1!=(null===(i=r.breaks)||void 0===i?void 0:i.length))throw"cox mode requires one break";return o.push(e.id,r.breaks[0]),{sql:`${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tjson_object('event', event, 'label', IIF(event = 0, 'Censored', IIF(event = 1, 'Event (grade ${r.breaks[0]}-5)', IIF(event = -1, 'Event before entry into the cohort', 'NA')))) AS key,\n\t\t\t\t\tjson_object('age_start', age_start, 'age_end', age_end) AS value\n\t\t\t\tFROM\n\t\t\t\t\tprecomputed_cox\n\t\t\t\tWHERE\n\t\t\t\t\tterm_id = ?\n\t\t\t\t\tAND grade_cutoff = ?\n\t\t\t)`,tablename:t}}};function l(t){const e=t.bar_by_children?"child":t.bar_by_grade?"grade":"";if(!e)throw"must set the bar_by_grade or bar_by_children query parameter";const n=t.value_by_max_grade?"max_grade":t.value_by_most_recent?"most_recent":t.value_by_computable_grade?"computable_grade":"";if(!n)throw"must set a valid value_by_*";return[e,n]}function c(t,e,n,r){const[o,i]=l(n);if("grade"!=o)throw"breaks must be used on grade values";const s=[];for(const t of n.groups)s.push(`SELECT sample, ? as key, value\n\t\t\tFROM precomputed_chc_grade\n\t\t\tWHERE\n\t\t\t\tterm_id=?\n\t\t\t\tAND ${i}=1\n\t\t\t\tAND value IN (${t.values.map((t=>"?")).join(",")})\n\t\t`),r.push(t.name,e.id,...t.values.map((t=>t.toString())));return{sql:`${t} AS (\n\t\t\t${s.join("\nUNION ALL\n")}\n\t\t)`,tablename:t}}},2852:(t,e,n)=>{"use strict";n.r(e),n.d(e,{getUncomputableClause:()=>v,get_bins:()=>_,get_numericMinMaxPct:()=>x,get_numericsummary:()=>w,get_rows:()=>p,get_rows_by_one_key:()=>h,get_samplecount:()=>f,get_samples:()=>u,get_summary:()=>g,get_summary_numericcategories:()=>d,get_term_cte:()=>m,interpolateSqlValues:()=>k});const r=n(9699),o=n(4048),i=n(5257).getFilterCTEs,s=n(827),a=n(2747),l=n(9723),c=n(610).s;n(334);async function u(t,e,n=!1){const r=await i(t,e),o=e.cohort.db.connection.prepare(r?`WITH ${r.filters} SELECT sample as id, name FROM ${r.CTEname} join sampleidmap on sample = sampleidmap.id`:"SELECT id, name FROM sampleidmap");let s;if(s=r?o.all(r.values):o.all(),n)return s;for(const t of s)delete t.name;return s}async function f(t,e){if(!t.filter)throw"filter missing";let n;if("object"==typeof t.filter)n=t.filter;else{if("string"!=typeof t.filter)throw"q.filter not obj or str";n=JSON.parse(t.filter)}const r=await i(n,e),o=`WITH ${r.filters}\n\t\tSELECT 'FILTERED_COHORT' as subcohort, count(distinct sample) as samplecount \n\t\tFROM ${r.CTEname}`;return e.cohort.db.connection.prepare(o).all(r.values)}async function d(t){const e=t.ds.cohort.termdb.q.termjsonByOneid(t.term_id);if("integer"!=e.type&&"float"!=e.type)throw"term is not numeric";if(!e.values)return[];const n=await i(t.filter,t.ds),r=n?n.values.slice():[];r.push(t.term_id);const o=[];for(const t in e.values)o.push("?"),r.push(Number(t));const s=`\n\t\t${n?"WITH "+n.filters:""}\n\t\tSELECT count(sample) AS samplecount,value\n\t\tFROM anno_${e.type}\n\t\tWHERE term_id=?\n\t\t${n?"AND sample IN "+n.CTEname:""}\n\t\tAND value IN (${o.join(",")})\n\t\tGROUP BY value`;return t.ds.cohort.db.connection.prepare(s).all(r)}async function h(t){if(!t.key)throw".key missing";if(!t.ds)throw".ds{} missing";const e=await i(t.filter,t.ds),n=e?e.values.slice():[],r=t.ds.cohort.termdb.q.termjsonByOneid(t.key);n.push(t.key);const o=`\n\t\t${e?"WITH "+e.filters:""}\n\t\tSELECT sample, value\n\t\tFROM anno_${r.type}\n\t\tWHERE term_id=?\n\t\t${e?" AND sample IN "+e.CTEname:""}`;return t.ds.cohort.db.connection.prepare(o).all(n)}async function p(t,e={}){"string"==typeof t.filter&&(t.filter=JSON.parse(decodeURIComponent(t.filter)));const n=Object.assign({withCTEs:!0,columnas:"t1.sample AS sample",groupby:""},e),r=await i(t.filter,t.ds),o=r?r.values.slice():[],s=await m(t,o,0,r),a=await m(t,o,1,r),l=await m(t,o,2,r),c=[s,a,l].map(((t,e)=>`\n\t\tSELECT sample, key, value, ${e} as termNum\n\t\tFROM ${t.tablename}\n\t\t${r?"WHERE sample IN "+r.CTEname:""}\n\t`)).join("\nUNION ALL\n"),u=`WITH\n\t\t${r?r.filters+",":""}\n\t\t${s.sql},\n\t\t${a.sql},\n\t\t${l.sql}\n\t\t${c}`;try{const e=t.ds.cohort.db.connection.prepare(u).all(o),i=new Map;for(const t of e){i.has(t.sample)||i.set(t.sample,{sample:t.sample});const e=i.get(t.sample),n=`key${t.termNum}`;n in e||(e[n]=[]),e[n].push(t)}const c=[],f=new Map;for(const e of i.values())if("key1"in e){if(t.term0_q&&t.term0_id){if(!("key0"in e))continue}else e.key0=[{key:"",value:""}];if(t.term2_q&&(t.term2_id||"samplelst"===t.term2.type)){if(!("key2"in e))continue}else e.key2=[{key:"",value:""}];e.rows=[];for(const t of e.key0)for(const n of e.key1)for(const r of e.key2)e.rows.push({sample:e.sample,key0:t.key,val0:t.value,key1:n.key,val1:n.value,key2:r.key,val2:r.value});for(const t of e.rows)if(n.groupby){if(!f.has(t[n.groupby])){const e=Object.assign({samplecount:0},t);c.push(e),f.set(t[n.groupby],e)}f.get(t[n.groupby]).samplecount++}else c.push(t)}return n.withCTEs?{lst:c,CTE0:s,CTE1:a,CTE2:l,filter:r}:c}catch(t){throw console.log("error in sql:\n",k(u,o)),t}}async function m(t,e,n,r,o=null){const i=o&&o.term||t[`term${n}`],u=i?i.id:t["term"+n+"_id"];if("samplelst"!=(null==i?void 0:i.type))if(o||1!=n){if(!u){const t="samplekey_"+n;return{tablename:t,sql:`${t} AS (\nSELECT null AS sample, '' as key, '' as value\n)`}}}else if(!u)throw"missing term1 id";const f=i&&i.type?i:t.ds.cohort.termdb.q.termjsonByOneid(u);if(!f)throw`no term found by id='${u}'`;let d=o&&o.q||t["term"+n+"_q"]||{};"string"==typeof d&&(d=JSON.parse(decodeURIComponent(d)));const h="samplekey_"+n;let p;if("categorical"==f.type){const n=b(f,d);p=await a[n?"groupset":"values"].getCTE(h,f,t.ds,d,e,n)}else if("integer"==f.type||"float"==f.type){const o="spline"==d.mode?"cubicSpline":d.mode||"discrete";p=await s[o].getCTE(h,f,t.ds,d,e,n,r)}else if("condition"==f.type){const n=d.mode||"discrete";p=await l[n].getCTE(h,f,t.ds,d,e)}else if("survival"==f.type)p=function(t,e,n,r,o){return r.push(e.id),{sql:`${t} AS (\n\t\t\tSELECT sample, exit_code as key, tte AS value\n\t\t\tFROM survival s\n\t\t\tWHERE s.term_id=?\n\t\t\t${o?"AND s.sample IN "+o.CTEname:""}\n\t\t)`,tablename:t}}(h,f,0,e,r);else{if("samplelst"!=f.type)throw"unknown term type";p=await c.getCTE(h,o||{term:f,q:d},e)}return p}async function g(t){const e=await p(t,{withCTEs:!0,groupby:"key1"}),n=[0,1,2],r={};for(const o of n)r[o]=y(t,o,e);for(const t of e.lst)for(const e of n)r[e](t);return e}function y(t,e,n){const r="key"+e,o="val"+e,i=t=>{delete t[r],delete t[o]},s=t["term"+e+"_id"];if(!s)return i;const a=t.ds.cohort.termdb.q.termjsonByOneid(s);if(!a)return i;const l=1!=e||t.term0_id||t.term2_id?r:"key",c=1!=e||t.term0_id||t.term2_id?r:"label";if("integer"==a.type||"float"==a.type){const i=n["CTE"+e],s="range"+(1!=e||t.term0_id||t.term2_id?e:"");return t=>{t[s]=i.name2bin.get(t[r]),t[c]=t[r],delete t[o],l!==r&&(t[l]=t[r],delete t[r])}}{const n=t["term"+e+"_q"];return e=>{e[c]=function(t,e,n,r){if("categorical"==e.type)return e.values&&t in e.values?e.values[t].label:t;if("condition"==e.type){var o;if(0==(null===(o=n.breaks)||void 0===o?void 0:o.length)){if(!(t in e.values))throw`unknown grade='${t}'`;return e.values[t].label}return t}if(e.values)return t in e.values?e.values[t].label:t;if("integer"==e.type||"float"==e.type)throw"should not work for numeric term";throw"unknown term type"}(e[r],a,n,t.ds),delete e[o],l!==r&&(e[l]=e[r],delete e[r])}}}function v(t,e,n=""){if(!t.values||!e.computableValuesOnly)return{values:[],clause:""};const r=Object.keys(t.values).filter((e=>t.values[e].uncomputable)),o=n?`${n}.value`:"value";return{values:r,clause:r.length?`AND ${o} NOT IN (${r.map((()=>"?")).join(",")})`:""}}function b(t,e){if(e.groupsetting&&!e.groupsetting.disabled&&e.groupsetting.inuse){if(Number.isInteger(e.groupsetting.predefined_groupset_idx)){if(e.groupsetting.predefined_groupset_idx<0)throw"q.predefined_groupset_idx out of bound";if(!t.groupsetting)throw"term.groupsetting missing when q.predefined_groupset_idx in use";if(!t.groupsetting.lst)throw"term.groupsetting.lst missing when q.predefined_groupset_idx in use";const n=t.groupsetting.lst[e.groupsetting.predefined_groupset_idx];if(!n)throw"q.predefined_groupset_idx out of bound";return n}if(e.groupsetting.customset)return e.groupsetting.customset;throw"do not know how to get groupset"}}function _(t,e,n,r,i){if("continuous"!=t.mode&&"spline"!=t.mode)return o.compute_bins(t,(t=>x(n,e,i,t)))}async function w(t,e,n,o=!1){const s="string"==typeof t.filter?JSON.parse(decodeURIComponent(t.filter)):t.filter;"integer"!=e.type&&"float"!=e.type||a.lst.find((t=>t.term.id==e.id&&"ranges"in t))||a.lst.push({type:"tvs",tvs:{term:e,ranges:_(t,e,n)}});const a=await i(s,n),l=[];a&&l.push(...a.values);const c=e.values?Object.keys(e.values).filter((t=>e.values[t].uncomputable)):[],u=`${a?"WITH "+a.filters+" ":""}\n\t\tSELECT value\n\t\tFROM anno_${e.type}\n\t\tWHERE\n\t\t${a?"sample IN "+a.CTEname+" AND ":""}\n\t\tterm_id=?\n\t\t${c.length?"AND value NOT IN ("+c.join(",")+")":""}`;l.push(e.id);const f=n.cohort.db.connection.prepare(u).all(l);if(!f.length)return null;f.sort(((t,e)=>t.value-e.value));const d=r.boxplot_getvalue(f);d.mean=f.length?f.reduce(((t,e)=>t+e.value),0)/f.length:0;let h=0;for(const t of f)h+=Math.pow(t.value-d.mean,2);return d.sd=Math.sqrt(h/(f.length-1)),d.min=f[0].value,d.max=f[f.length-1].value,o&&(d.values=f.map((t=>t.value))),d}function x(t,e,n,r=[]){const o=[];n&&o.push(...n.values),o.push(e.id);const i=e.values?Object.keys(e.values).filter((t=>e.values[t].uncomputable)):[],s=[],a=[],l=[];let c;for(const t of r)c="pct_"+t,s.push(`\n\t\t${c} AS (\n\t\t SELECT value\n\t\t FROM vals\n\t\t LIMIT 1\n\t\t OFFSET (\n\t\t SELECT cast ( x as int ) - ( x < cast ( x as int ))\n\t\t FROM (\n\t\t SELECT cast(?*pct as int) as x \n\t\t FROM p\n\t\t )\n\t\t )\n\t\t)`),o.push(t),a.push(c),l.push(`${c}.value AS ${"p"+t}`);const u=`WITH\n\t\t${n?n.filters+", ":""} \n\t\tvals AS (\n\t\t\tSELECT value\n\t\t\tFROM anno_${e.type}\n\t\t\tWHERE\n\t\t\t${n?"sample IN "+n.CTEname+" AND ":""}\n\t\t\tterm_id=?\n\t\t\t${i.length?"AND value NOT IN ("+i.join(",")+")":""}\n\t\t\tORDER BY value ASC\n\t\t),\n\t\tp AS (\n\t\t\tSELECT count(value)/100 as pct\n\t\t\tFROM vals\n\t\t)\n\t\t${s.length?",\n"+s.join(","):""}\n\t\tSELECT \n\t\t\tmin(vals.value) as vmin,\n\t\t\tmax(vals.value) as vmax\n\t\t\t${l.length?",\n"+l.join(",\n"):""} \n\t\tFROM vals ${a.length?","+a.join(","):""}`,f=t.cohort.db.connection.prepare(u).all(o),d=f.length?f[0]:{};return d.max=f[0].vmax,d.min=f[0].vmin,d}function k(t,e){const n=e.slice();let r;return t.split("").map((t=>{if("?"==t){r=t;const e=n.shift();return"string"==typeof e?`'${e}'`:e}return"\t"==t?"":"\n"!=t&&" "!=t||r!==t?(r=t,t):""})).join("")}},827:(t,e,n)=>{"use strict";n.r(e),n.d(e,{binary:()=>a,continuous:()=>o,cubicSpline:()=>i,discrete:()=>s});var r=n(2852);const o={getCTE(t,e,n,o,i,s,a){i.push(e.id);const l=(0,r.getUncomputableClause)(e,o);return i.push(...l.values),{sql:`${t} AS (\n\t\t\t\tSELECT \n\t\t\t\t\tsample,\n\t\t\t\t\tvalue as key, \n\t\t\t\t\tvalue\n\t\t\t\tFROM anno_${e.type}\n\t\t\t\tWHERE term_id=? ${l.clause}\n\t\t\t)`,tablename:t}}},i=o,s={getCTE(t,e,n,o,i,s,a){i.push(e.id);const l=(0,r.get_bins)(o,e,n,s,a),c=[],u=new Map;o.bin_size;for(const t of l)!("name"in t)&&t.label&&(t.name=t.label),u.set(t.name,t),c.push(`SELECT '${t.name}' AS name,\n\t\t\t\t${null==t.start?0:t.start} AS start,\n\t\t\t\t${null==t.stop?0:t.stop} AS stop,\n\t\t\t\t0 AS unannotated,\n\t\t\t\t${t.startunbounded?1:0} AS startunbounded,\n\t\t\t\t${t.stopunbounded?1:0} AS stopunbounded,\n\t\t\t\t${t.startinclusive?1:0} AS startinclusive,\n\t\t\t\t${t.stopinclusive?1:0} AS stopinclusive`);const f=[];if(e.values)for(const t in e.values){const n=e.values[t].uncomputable;if(o.computableValuesOnly&&n)continue;if(!o.computableValuesOnly&&!n)continue;f.push(t);const r=e.values[t];c.push(`SELECT '${r.label}' AS name,\n\t ${t} AS start,\n\t 0 AS stop,\n\t 1 AS unannotated,\n\t 0 AS startunbounded,\n\t 0 AS stopunbounded,\n\t 0 AS startinclusive,\n\t 0 AS stopinclusive`),u.set(r.label,{is_unannotated:!0,value:t,label:r.label})}const d="bin_defs_"+s,h=(0,r.getUncomputableClause)(e,o,"a");i.push(...h.values);return{sql:`${d} AS (\n\t\t\t\t${c.join("\nUNION ALL\n")}\n\t\t\t),\n\t\t\t${t} AS (\n\t\t\t\tSELECT\n\t\t\t\t\tsample,\n\t\t\t\t\tb.name AS key,\n\t\t\t\t\tvalue\n\t\t\t\tFROM\n\t\t\t\t\tanno_${e.type} a\n\t\t\t\tJOIN ${d} b ON\n\t\t\t\t\t( b.unannotated=1 AND value=b.start )\n\t\t\t\t\tOR\n\t\t\t\t\t(\n\t\t\t\t\t\tb.unannotated=0 AND\n\t\t\t\t\t\t${f.length?"value NOT IN ("+f.join(",")+") AND":""}\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tb.startunbounded = 1\n\t\t\t\t\t\t\tOR value > b.start\n\t\t\t\t\t\t\tOR (b.startinclusive=1 AND value = b.start)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tb.stopunbounded\n\t\t\t\t\t\t\tOR value < b.stop\n\t\t\t\t\t\t\tOR (b.stopinclusive=1 AND value = b.stop)\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\tWHERE\n\t\t\t\tterm_id=? ${h.clause}\n\t\t\t)`,tablename:t,name2bin:u,bins:l}}},a=s},610:(t,e,n)=>{"use strict";n.d(e,{s:()=>r});const r={getCTE(t,e,n){let r,o,i="";for(const[t,s]of e.q.groups.entries())"in"in s||(s.in=!0),r=s.values.map((t=>t.sampleId)),o=r.map((()=>"?")).join(","),i+=`SELECT id as sample, ? as key, ? as value\n\t\t\t\tFROM sampleidmap\n\t\t\t\tWHERE sample ${s.in?"":"NOT"} IN (${o})\n\t\t\t`,t!=e.q.groups.length-1&&(i+="UNION ALL "),n.push(s.name,s.name,...r);return{sql:`${t} AS (${i})`,tablename:t}}}},1468:(t,e,n)=>{"use strict";n.r(e),n.d(e,{get_survival:()=>c});const r=n(1017),{getData:o}=n(2974),i=n(3856).write_file,s=n(7147),a=n(334),l=n(9157);async function c(t,e){try{var n;if(!e.cohort)throw"cohort missing from ds";t.ds=e;const c=[];for(const e of[0,1,2]){const n="term"+e,r=n+"_id";"string"==typeof t[r]?(t[r]=decodeURIComponent(t[r]),t[n]=t.ds.cohort.termdb.q.termjsonByOneid(t[r])):"string"==typeof t[n]&&(t[n]=JSON.parse(decodeURIComponent(t[n])));const o=n+"_q";t[n]&&c.push({term:t[n],q:t[o]})}if(t.term2){if("survival"==t.term2.type&&"survival"==t.term1.type)throw"term and overlay are both survival terms - only one could be a survival term";if("survival"!=t.term2.type&&"survival"!=t.term1.type)throw"no survival terms, either the main term OR the overlay term must be a survival term"}else if("survival"!=t.term1.type)throw"non-survival term";if(t.term0&&"survival"==t.term0.type)throw"term0 must not be a survival term";const f=function(t){if(t.term1&&"survival"==t.term1.type)return 1;if(!t.term2)throw"term1.type is not survival and term2 is missing";if("survival"!=t.term2.type)throw"both term1 and term2 are not survival type";return 2}(t),d=t[`term${f}`],h=t["term"+(1==f?2:1)],p=await o({terms:c,filter:t.filter},e,t.genome);if(p.error)throw p.error;const m=function(t,e){const n=Object.values(t.samples).filter((t=>t[e.id]));return n.sort(((t,n)=>t[e.id].value<n[e.id].value?-1:1))}(p,d),g={},y={chart:new Set,series:new Set};for(const e of m){const n=e[d.id],r=n.value;if(r<0)continue;const o=n.key;let i;if(h)if("id"in h){if(!(h.id in e))continue;i=e[h.id].key}else if("samplelst"==h.type){if(!(h.name in e))continue;i=e[h.name].key}else i=u(h,e);else i="*";y.series.add(i);const s=t.term0&&e[t.term0.id||t.term0.name]||{key:""};s.key in g||(g[s.key]=[],y.chart.add(s.key)),g[s.key].push({time:r,status:o,series:i})}const v=t.term2_id&&(null===(n=p.refs[t.term2.id])||void 0===n?void 0:n.bins)||[],b={keys:["chartId","seriesId","time","survival","lower","upper","nevent","ncensor","nrisk"],case:[],refs:{bins:v}};for(const t in g){const e=g[t],n=r.join(a.cachedir,Math.random().toString()+".json");await i(n,JSON.stringify(e));const o=await l(r.join(a.binpath,"utils/survival.R"),[],[n]),c=JSON.parse(o);for(const e of c.estimates){for(const t in e)e[t]="series"==t?"*"==e[t]?"":e[t]:Number(e[t]);b.case.push([t,e.series,e.time,e.surv,e.lower,e.upper,e.nevent,e.ncensor,e.nrisk])}c.tests&&(b.tests||(b.tests={}),b.tests[t]=c.tests),s.unlink(n,(()=>{}))}b.case.sort(((t,e)=>t[2]-e[2]));const _=function(t,e=[]){if(t){if("condition"==t.type&&t.values)return Object.keys(t.values).map(Number).sort(((t,e)=>t-e)).map((e=>t.values[e].label));if(t.values)return Object.keys(t.values).sort(((e,n)=>"order"in t.values[e]&&"order"in t.values[n]?t.values[e].order-t.values[n].order:0)).map((e=>t.values[e].label))}return e.map((t=>t.name?t.name:t.label))}(t.term2,v?v.map((t=>t.name?t.name:t.label)):[]);return b.refs.orderedKeys={chart:[...y.chart].sort(),series:[...y.series].sort(_?(t,e)=>_.indexOf(t)-_.indexOf(e):void 0)},b}catch(t){return t.stack&&console.log(t.stack),{error:t.message||t}}}function u(t,e){const n=t.name;if("geneVariant"==t.type){if(!e[n]||!e[n].values)return"Wildtype";const t=e[n].values.filter((t=>"Blank"!=t.class));return t.find((t=>"WT"!=t.class))?`${n} Variant`:t.find((t=>"WT"==t.class))?`${n} Wildtype`:e[n].values.length>t.length?"Not tested":"Not sure"}throw`cannot get series key for term='${n}'`}},4603:(t,e,n)=>{"use strict";n.d(e,{g:()=>v});var r=n(7147),o=n(2554),i=n(334),s=n.n(i),a=n(9157),l=n.n(a),c=n(1017),u=n.n(c),f=n(3856),d=n(2974),h=n(6718),p=n(7011),m=n(7027),g=n(5684);function y(t){let e=t;"string"==typeof t[0]&&(e=t.map(Number));const n=e.length;function r(t){return t.reduce(((t,e)=>t+e))/n}const o=(0,m.Z)(e,50),i=e.map((t=>(t-r(e))**2)).reduce(((t,e)=>t+e),0)/(n-1),s=Math.sqrt(i),a=(0,m.Z)(e,25),l=(0,m.Z)(e,75),c=l-a,u=Math.min(...e),f=Math.max(...e);return{values:[{id:"total",label:"Total",value:n},{id:"min",label:"Minimum",value:(0,g.Z)(u,2)},{id:"p25",label:"1st quartile",value:(0,g.Z)(a,2)},{id:"median",label:"Median",value:(0,g.Z)(o,2)},{id:"mean",label:"Mean",value:(0,g.Z)(r(e),2)},{id:"p75",label:"3rd quartile",value:(0,g.Z)(l,2)},{id:"max",label:"Maximum",value:(0,g.Z)(f,2)},{id:"SD",label:"Standard deviation",value:(0,g.Z)(s,2)},{id:"variance",label:"Variance",value:(0,g.Z)(i,2)},{id:"IQR",label:"Inter-quartile range",value:(0,g.Z)(c,2)}]}}async function v(t,e,n,i){const a=n.cohort.termdb.q.termjsonByOneid(t.termid);if(!a)throw".termid invalid";if("integer"!=a.type&&"float"!=a.type)throw"term type is not integer/float.";const c=[{id:t.termid,term:a,q:{mode:"continuous"}}];t.divideTw&&(null===t.divideTw||void 0===t.divideTw||"object"!=typeof t.divideTw||"id"in t.divideTw||(t.divideTw.id=t.divideTw.term.name,t.divideTw.term.id=t.divideTw.term.name),c.push(t.divideTw),t.term2_q=t.divideTw.q);const m=await(0,d.getData)({terms:c,filter:t.filter,currentGeneNames:t.currentGeneNames},n,i);if(m.error)throw m.error;t.scale&&function(t,e,n){if(!t.scale)return;const r=Number(t.scale);for(const[t,a]of Object.entries(e.samples)){var o,i,s;a[n.id]&&(null!==(o=n.values)&&void 0!==o&&null!==(i=o[null===(s=a[n.id])||void 0===s?void 0:s.value])&&void 0!==i&&i.uncomputable||(a[n.id].key=a[n.id].key/r,a[n.id].value=a[n.id].value/r))}}(t,m,a);const v=function(t,e,n,r){const o="log"==t.unit,i=new Map;let s=1/0,a=-1/0;const l={};let c=0;for(const[t,_]of Object.entries(e.samples)){var u,f,d;const t=(0,g.Z)(null===(u=_[n.id])||void 0===u?void 0:u.value,1);if(Number.isFinite(t))if(null!==(f=n.values)&&void 0!==f&&null!==(d=f[t])&&void 0!==d&&d.uncomputable){const e=n.values[t].label;l[e]=(l[e]||0)+1}else if(o&&t<=0)c++;else if(s>t&&(s=t),a<t&&(a=t),"log"===o&&0===s&&(s=Math.max(s,t)),r){var h,p,m,y,v,b,w;if(!_[null==r?void 0:r.id])continue;if(null!==(h=r.term)&&void 0!==h&&null!==(p=h.values)&&void 0!==p&&null!==(m=p[null===(y=_[r.id])||void 0===y?void 0:y.key])&&void 0!==m&&m.uncomputable){var x,k;const t=null===(x=r.term.values[null===(k=_[r.id])||void 0===k?void 0:k.value])||void 0===x?void 0:x.label;l[t]=(l[t]||0)+1}i.has(null===(v=_[r.id])||void 0===v?void 0:v.key)||i.set(null===(b=_[r.id])||void 0===b?void 0:b.key,[]),i.get(null===(w=_[r.id])||void 0===w?void 0:w.key).push(t)}else i.has("All samples")||i.set("All samples",[]),i.get("All samples").push(t)}return{key2values:i,minMaxValues:{min:s,max:a},uncomputableValueObj:_(l),skipNonPositiveCount:c}}(t,m,a,t.divideTw),w=function(t,e,n){const r=n.divideTw,o={min:t.minMaxValues.min,max:t.minMaxValues.max,plots:[],pvalues:[],plotThickness:Number,uncomputableValueObj:Object.keys(t.uncomputableValueObj).length>0?t.uncomputableValueObj:null};for(const[n,f]of function(t,e,n){var r,o,i,s;const a=null===(r=t.refs.byTermId[null==n||null===(o=n.term)||void 0===o?void 0:o.id])||void 0===r?void 0:r.keyOrder;return e=new Map([...e].sort(a?(t,e)=>a.indexOf(t[0])-a.indexOf(e[0]):"categorical"===(null==n||null===(i=n.term)||void 0===i?void 0:i.type)?(t,e)=>e[1].length-t[1].length:"condition"===(null==n||null===(s=n.term)||void 0===s?void 0:s.type)?(t,e)=>t[0]-e[0]:(t,e)=>t.toString().replace(/[^a-zA-Z0-9<]/g,"").localeCompare(e.toString().replace(/[^a-zA-Z0-9<]/g,""),void 0,{numeric:!0}))),e}(e,t.key2values,r)){var i,s,a,l,c,u;if(r)o.plots.push({label:(null==r||null===(i=r.term)||void 0===i||null===(s=i.values)||void 0===s||null===(a=s[n])||void 0===a?void 0:a.label)||n,values:f,seriesId:n,plotValueCount:null==f?void 0:f.length,color:(null==r||null===(l=r.term)||void 0===l||null===(c=l.values)||void 0===c||null===(u=c[n])||void 0===u?void 0:u.color)||null,divideTwBins:b(r,e).has(n)?b(r,e).get(n):null,uncomputableValueObj:Object.keys(t.uncomputableValueObj).length>0?t.uncomputableValueObj:null});else o.plots.push({label:"All samples",values:f,plotValueCount:f.length})}o.plots.length>=1&&(o.plotThickness=n.plotThickness?Number(n.plotThickness):function(t,e){const n=e.screenThickness/t.plots.length,r=Math.round(Math.min(n,e.maxThickness));return r}(o,n));return o}(v,m,t);await async function(t,e){if(!t)return;const n={},o=e.plots.length;for(let t=0;t<o;t++){const{label:r,values:i}=e.plots[t],s=r.split(",")[0].trim();for(let r=t+1;r<o;r++){const t=i,o=e.plots[r].values;n[`${s}, ${e.plots[r].label.split(",")[0].trim()}`]={group1values:t,group2values:o}}}const i=u().join(s().cachedir,Math.random().toString()+".json");await f.write_file(i,JSON.stringify(n));const a=await l()(u().join(s().binpath,"utils/wilcoxon.R"),[],[i]);(0,r.unlink)(i,(()=>{}));for(const[t,n]of Object.entries(JSON.parse(a))){const r=t.split(",");e.pvalues.push([{value:r[0].trim()},{value:r[1].trim()},{html:n}])}}(t.divideTw,w),function(t,e,n){t.radius||(t.radius=5);if(t.radius<=0)throw"q.radius is not a number";t.radius=+t.radius;t.strokeWidth||(t.strokeWidth=.2);const r=4*t.radius;let i;const s="log"==t.unit;i=s?(0,o.scaleLog)().base(n.cohort.termdb.logscaleBase2?2:10).domain([e.min,e.max+e.max]).range("horizontal"===t.orientation?[0,t.svgw]:[t.svgw,0]):(0,o.scaleLinear)().domain([e.min,e.max+e.max/r]).range("horizontal"===t.orientation?[0,t.svgw]:[t.svgw,0]);const[a,l]="horizontal"==t.orientation?[t.svgw*t.devicePixelRatio,r*t.devicePixelRatio]:[r*t.devicePixelRatio,t.svgw*t.devicePixelRatio],c=t.radius/t.devicePixelRatio,u=c*Math.PI;for(const n of e.plots){const e=(0,h.createCanvas)(a,l),r=e.getContext("2d");r.strokeStyle="rgba(0,0,0,0.8)",r.lineWidth=t.strokeWidth/t.devicePixelRatio,r.globalAlpha=.5,r.fillStyle="#ffe6e6",1!=t.devicePixelRatio&&r.scale(t.devicePixelRatio,t.devicePixelRatio),"rug"===t.datasymbol?n.values.forEach((e=>{r.beginPath(),"horizontal"==t.orientation?(r.moveTo(+i(e),0),r.lineTo(+i(e),2*c)):(r.moveTo(0,+i(e)),r.lineTo(2*c,+i(e))),r.stroke()})):"bean"===t.datasymbol&&n.values.forEach((e=>{r.beginPath(),"horizontal"===t.orientation?r.arc(+i(e),t.radius,c,0,u):r.arc(t.radius,+i(e),c,0,u),r.fill(),r.stroke()})),n.src=e.toDataURL();const o=(0,p.violinBinsObj)(i,n);n.bins=o.bins,n.biggestBin=Math.max(...o.bins0.map((t=>t.length))),n.summaryStats=y(n.values),delete n.values}}(t,w,n),e.send(w)}function b(t,e){var n,r;const o=new Map,i=null===(n=e.refs.byTermId[null==t||null===(r=t.term)||void 0===r?void 0:r.id])||void 0===n?void 0:n.bins;if(i)for(const t of i)o.set(t.label,t);return o}function _(t){return Object.fromEntries(Object.entries(t).sort((([,t],[,e])=>t-e)))}},3856:(t,n,r)=>{const o=r(7147),i=r(1017),s=r(2081).spawn,a=r(4521),l=r(2273),c=r(6819),u=r(4809).default,f=r(5890),d=r(334);r(2781).Readable;n.serverconfig=d;const h=d.tabix,p=d.samtools,m=d.bcftools,g=d.bigBedToBed,y=d.bigBedNamedItems,v=d.bigBedInfo;function b(t){const e=t.split("://");return 2!=e.length?["improper url"]:e[0].length<3?["protocol string length too short"]:e[1].length<5?["body string length too short"]:[null,e[0],e[1]]}function _(t){return new Promise(((e,n)=>{o.access(t,o.constants.F_OK,(t=>{t&&e(!0),e(!1)}))}))}function w(t){return new Promise(((e,n)=>{o.access(t,o.constants.R_OK,(t=>{t&&e(!0),e(!1)}))}))}function x(t,e){return new Promise(((n,r)=>{o.writeFile(t,e,(t=>{t&&r("cannot write"),n()}))}))}function k(t){return new Promise(((e,n)=>{o.readFile(t,{encoding:"utf8"},((r,o)=>{r&&n("cannot read file: "+t),e(o)}))}))}n.cache_index=async(t,e)=>{if(!t)throw".gz file URL missing";if("string"!=typeof t)throw".gz file URL not string";if(e&&"string"!=typeof e)throw"index URL not string";const[n,r,s]=b(t);if(n)throw".gz file URL error: "+n;const a=i.join(d.cachedir,r,s);try{await o.promises.stat(a)}catch(n){if("ENOENT"!=n.code)throw"stating gz url dir: "+n.code;try{await o.promises.mkdir(a,{recursive:!0})}catch(n){throw"url dir: cannot mkdir"}}if(!e)return a;{const[t,r,s]=b(e);if(t)throw"indexl url error: "+t;const l=i.join(a,i.basename(s));try{return await o.promises.stat(l),a}catch(n){if("ENOENT"==n.code)return await async function(t,e){try{const i=await u(t);if(200!=i.status)throw"index file not accessible from url with status code "+i.status;await(n=i.body,r=e,new Promise(((t,e)=>{const i=o.createWriteStream(r);n.pipe(i),n.on("end",(()=>t()))})))}catch(t){throw"cannot download from url"}var n,r}(e,l),a;throw"stating indexl url file: "+n.code}}},n.file_is_readable=async t=>{try{await o.promises.stat(t)}catch(e){const n=d.debugmode?`file='${t}'`:"";if("EACCES"==e.code)throw`Permission denied ${n}`;if("ENOENT"==e.code)throw`No such file or directory ${n}`;if("EPERM"==e.code)throw`Operation not permitted ${n}`;throw`cannot access file (' + e.code + ') ${n}`}},n.init_one_vcf=async function(t,e,r){let o;if(t.file)t.file.startsWith(d.tpmasterdir)||(t.file=i.join(d.tpmasterdir,t.file)),o=t.file,await n.validate_tabixfile(t.file);else{if(!t.url)throw"no file or url given for vcf file";o=t.url,t.dir=await utils.cache_index(t.url,t.indexURL)}const[s,a,l,c]=r?await n.get_header_bcf(o,t.dir):await n.get_header_vcf(o,t.dir);if(c)throw console.log(c.join("\n")),"got above errors parsing vcf";t.info=s,t.format=a,t.samples=l,await n.tabix_is_nochr(o,t.dir,e)&&(t.nochr=!0)},n.validate_tabixfile=async function(t){if(!t.endsWith(".gz"))throw"tabix file not ending with .gz";if(await _(t))throw t+" file not exist";if(await w(t))throw".gz file not readable";const e=t+".tbi";if(await _(e)){const e=t+".csi";if(await _(e))throw"neither .tbi .csi index file exist for "+t;if(await w(e))throw".csi index file not readable"}else if(await w(e))throw".tbi index file not readable"},n.tabix_is_nochr=async function(t,e,r){const o=[];return await n.get_lines_bigfile({args:["-l",t],dir:e,callback:t=>{o.push(t)}}),l.contigNameNoChr(r,o)},n.file_not_readable=w,n.file_not_exist=_,n.get_header_tabix=async(t,e)=>{const r=[];return await n.get_lines_bigfile({args:["-H",t],dir:e,callback:t=>{r.push(t)}}),r},n.get_header_bcf=(t,e)=>new Promise(((n,r)=>{const o=s(m,["view","-h",t],{cwd:e}),i=[];o.stdout.on("data",(t=>i.push(t))),o.on("close",(()=>{n(c.vcfparsemeta(i.join("").trim().split("\n")))}))})),n.get_header_vcf=async(t,e)=>c.vcfparsemeta(await n.get_header_tabix(t,e)),n.get_lines_bigfile=function({args:t,dir:e,callback:n,isbcf:r,isbam:o}){if(!t)throw"args is missing";if(!Array.isArray(t))throw"args[] is not array";if(0==t.length)throw"args[] empty array";if(!n)throw"callback is missing";if("function"!=typeof n)throw"callback() not a function";return new Promise(((i,l)=>{const c=s(r?m:o?p:h,t,{cwd:e}),u=a.createInterface({input:c.stdout}),f=[];u.on("line",(t=>n(t,c))),c.stderr.on("data",(t=>f.push(t))),c.on("close",(()=>{const t=f.join("").trim();t&&!t.startsWith("[E::idx_test_and_fetch]")&&l(t),i()}))}))},n.write_file=x,n.write_tmpfile=async function(t){const e=Math.random().toString();return await x(i.join(d.cachedir,e),t),e},n.read_file=k,n.get_fasta=async(t,e)=>{if("NA"==t.genomefile){const t=e.split(/[:-]/),n=[];for(let e=Number(t[1]);e<=Number(t[2]);e++)n.push("N");return`>${e}\n${n.join("")}`}const r=[];return await n.get_lines_bigfile({isbam:!0,args:["faidx",t.genomefile,e],callback:t=>r.push(t)}),r.join("\n")},n.connect_db=function(t,e={}){const n="/"==t[0]?t:i.join(d.tpmasterdir,t);try{return new f(n,Object.assign({readonly:!0,fileMustExist:!0},e))}catch(t){throw`error connecting to ${n}: ${t}`}};const q=new Set(["Homozygous reference","Homozygous alternative","Heterozygous"]);n.genotype_type_set=q,n.genotype_types={href:"Homozygous reference",halt:"Homozygous alternative",het:"Heterozygous"},n.loadfile_ssid=async function(t,e){const n=await k(i.join(d.cachedir_ssid,t)),r=new Map,o=new Map;for(const t of n.trim().split("\n")){if(!t)continue;const[n,i]=t.split("\t");if(!i)continue;if(!q.has(n))throw"unknown hardcoded genotype label: "+n;const s=i.split(",").map((t=>Number(t))),a=e?s.filter((t=>e.has(t))):s;for(const t of a)r.set(t,n);o.set(n,new Set(a))}return[r,o]},n.run_fdr=async function(t){const n=i.join(d.cachedir,Math.random().toString()),r=n+".out";await x(n,t.join("\t")),await function(t,n){return new Promise(((r,o)=>{const a=s("Rscript",[i.join(d.binpath,"utils/fdr.R"),t,n]);a.on("close",(()=>r())),a.on("error",(()=>o(e)))}))}(n,r);const a=await k(r);return o.unlink(n,(()=>{})),o.unlink(r,(()=>{})),a.trim().split("\n").map(Number)},n.stripJsScript=function(t){return t.replace(/\<script|\bon[\w]{1,38}\b[\ \t\n]*\=/gi," _")},n.bam_ifnochr=async(t,e,r)=>{const o=[];if(await n.get_lines_bigfile({isbam:!0,args:["view","-H",t],dir:r,callback:t=>o.push(t)}),0==o.length)throw"cannot list bam header lines";const i=[];for(const t of o){if(!t.startsWith("@SQ"))continue;const e=t.split("\t")[1];e||reject("2nd field missing from @SQ line");const n=e.split(":");"SN"!=n[0]&&reject('@SQ line 2nd field is not "SN" but '+n[0]),n[1]||reject("@SQ line no value for SN"),i.push(n[1])}return l.contigNameNoChr(e,i)},n.query_bigbed_by_coord=function(t,e,n,r){return new Promise(((o,i)=>{const a=s(g,[`-chrom=${e}`,`-start=${n}`,`-end=${r}`,t,"stdout"]),l=[],c=[];a.stdout.on("data",(t=>l.push(t))),a.stderr.on("data",(t=>c.push(t))),a.on("close",(t=>{0!==t&&i(`bigBed query exited with non-zero status and this standard error:\n${c.join("")}`),c.length>0&&i(c.join(""));const e=l.join("").trim();o(e?e.split("\n"):[])}))}))},n.query_bigbed_by_name=function(t,e){return new Promise(((n,r)=>{const o=s(y,[t,e,"stdout"]),i=[],a=[];o.stdout.on("data",(t=>i.push(t))),o.stderr.on("data",(t=>a.push(t))),o.on("close",(t=>{0!==t&&r(`bigBed query exited with non-zero status and this standard error:\n${a.join("")}`),a.length>0&&r(a.join(""));const e=i.join("").trim();n(e?e.split("\n"):[])}))}))},n.getRandomInt=function(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1)+t)},n.sleep=function(t){return new Promise((e=>setTimeout(e,t)))},n.testIfFileIsBigbed=async function(t){return new Promise(((e,n)=>{const r=s(v,[t]),o=[],i=[];r.stdout.on("data",(t=>o.push(t))),r.stderr.on("data",(t=>i.push(t))),r.on("close",(t=>{const n=i.join("");n&&(n.includes("is not a big bed file")||n.includes("Couldn't open"),e(!1));o.join("").trim().startsWith("version")&&e(!0)}))}))}},8206:(t,e,n)=>{"use strict";n.r(e),n.d(e,{byExpectedVal:()=>a,byReqKey:()=>s,middleware:()=>i});const r=n(9699),o={};function i(t,e,n){try{const e=t.query;for(const t in e)t in s&&(e[t]=s[t](e[t]));n()}catch(n){r.catch(t,e,n.message||n)}}r.catch=function(t,e,n){const r=+new Date;if(t.ip in o||(o[t.ip]={time:r,count:0}),r-o[t.ip].time>3e4)delete o[t.ip];else{if(o[t.ip].count>10)return void e.send({error:"busy"});o[t.ip].count++}throw e.send({error:n}),new Date+" "+n};const s={genome(t){if("string"!=typeof t)throw"genome should be a non-empty string";if(/\s+/.test(t))throw"invalid genome character";return t},chr(t){if("string"!=typeof t)throw"chr should be a string";if(/\s+/.test(t))throw"invalid chr character";return t},start:t=>Number(t),term(t){const e="string"==typeof t?JSON.parse(t):t;if(!("id"in e))throw"missing termWrapper.id";if(!("q"in e))throw"missing termWrapper.q";return e}},a={alphaNumeric(t,e,n){try{if(!e)throw`empty ${t} value`;if("string"!=typeof e)throw`${t} should be a non-empty alphanumeric string`;if(/\s+/.test(e))throw`invalid ${t} character`;return e}catch(t){throw n.send({error:t}),t}}}},3625:(t,e,n)=>{"use strict";n.r(e),n.d(e,{compute_mclass:()=>a});const{dissect_INFO:r}=n(9380),{parse_CSQ:o}=n(4298),{getVariantType:i}=n(736),{vcfcopymclass:s}=n(2273);function a(t,e,n,a,l,c,u){var f;const d=r(l);for(const e in t.info)if("A"==t.info[e].Number&&e in d&&(d[e]=d[e].split(",")),t.info[e].separator&&e in d){const n=d[e].split(t.info[e].separator);n.length>1&&(d[e]=n)}a.mlst=n.map((t=>{const[n,r,o]=function(t,e,n){for(;e.length>1&&n.length>1&&e[e.length-1]==n[n.length-1];)e=e.substring(0,e.length-1),n=n.substring(0,n.length-1);for(;e.length>1&&n.length>1&&e[0]==n[0];)e=e.substring(1),n=n.substring(1),t++;return[t,e,n]}(a.pos,e,t),s={allele_original:t,ref:r,alt:o,pos:n,type:i(r,o)};return c&&"."!=c&&(s.vcf_id=c),s})),null!==(f=t.info)&&void 0!==f&&f.CSQ&&d.CSQ&&o(d.CSQ,t.info.CSQ.csqheader,a);const h={};u&&(h.usegm={isoform:u});for(const[n,r]of a.mlst.entries()){s(r,h),delete r.csq,r.mname||(r.mname="."!=c?c:a.pos+":"+e+">"+r.allele_original),r.altAlleleIdx=n+1,r.info={};for(const e in d){var p,m;"A"==(null===(p=t.info)||void 0===p||null===(m=p[e])||void 0===m?void 0:m.Number)?r.info[e]=d[e][n]:r.info[e]=d[e]}}}},1271:t=>{"use strict";t.exports=require("@sjcrh/proteinpaint-rust")},5890:t=>{"use strict";t.exports=require("better-sqlite3")},3986:t=>{"use strict";t.exports=require("body-parser")},6718:t=>{"use strict";t.exports=require("canvas")},7455:t=>{"use strict";t.exports=require("compression")},9710:t=>{"use strict";t.exports=require("cookie-parser")},6860:t=>{"use strict";t.exports=require("express")},4308:t=>{"use strict";t.exports=require("express-basic-auth")},6452:t=>{"use strict";t.exports=require("got")},7219:t=>{"use strict";t.exports=require("image-size")},9344:t=>{"use strict";t.exports=require("jsonwebtoken")},8171:t=>{"use strict";t.exports=require("jstat")},9292:t=>{"use strict";t.exports=require("lazy")},6828:t=>{"use strict";t.exports=require("minimatch")},4809:t=>{"use strict";t.exports=require("node-fetch")},5346:t=>{"use strict";t.exports=require("partjson")},4269:t=>{"use strict";t.exports=require("url")},6464:t=>{"use strict";t.exports=require("util")},2081:t=>{"use strict";t.exports=require("child_process")},6113:t=>{"use strict";t.exports=require("crypto")},7147:t=>{"use strict";t.exports=require("fs")},3685:t=>{"use strict";t.exports=require("http")},5687:t=>{"use strict";t.exports=require("https")},1017:t=>{"use strict";t.exports=require("path")},4521:t=>{"use strict";t.exports=require("readline")},2781:t=>{"use strict";t.exports=require("stream")},9263:(t,e,n)=>{"use strict";function r(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}n.d(e,{Z:()=>r})},5519:(t,e,n)=>{"use strict";n.d(e,{Nw:()=>l,ZP:()=>u,ZR:()=>c,ml:()=>a});var r=n(9263),o=n(3292),i=n(3745);const s=(0,o.Z)(r.Z),a=s.right,l=s.left,c=(0,o.Z)(i.Z).center,u=a},3292:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i});var r=n(9263),o=n(788);function i(t){let e,n,i;function a(t,r,o=0,i=t.length){if(o<i){if(0!==e(r,r))return i;do{const e=o+i>>>1;n(t[e],r)<0?o=e+1:i=e}while(o<i)}return o}return 2!==t.length?(e=r.Z,n=(e,n)=>(0,r.Z)(t(e),n),i=(e,n)=>t(e)-n):(e=t===r.Z||t===o.Z?t:s,n=t,i=t),{left:a,center:function(t,e,n=0,r=t.length){const o=a(t,e,n,r-1);return o>n&&i(t[o-1],e)>-i(t[o],e)?o-1:o},right:function(t,r,o=0,i=t.length){if(o<i){if(0!==e(r,r))return i;do{const e=o+i>>>1;n(t[e],r)<=0?o=e+1:i=e}while(o<i)}return o}}}function s(){return 0}},1045:(t,e,n)=>{"use strict";function r(t,e){if(!((e=+e)>=0))throw new RangeError("invalid r");let n=t.length;if(!((n=Math.floor(n))>=0))throw new RangeError("invalid length");if(!n||!e)return t;const r=c(e),o=t.slice();return r(t,o,0,n,1),r(o,t,0,n,1),r(t,o,0,n,1),t}n.d(e,{TX:()=>i,u8:()=>o,yv:()=>r});const o=s(c),i=s((function(t){const e=c(t);return(t,n,r,o,i)=>{e(t,n,(r<<=2)+0,(o<<=2)+0,i<<=2),e(t,n,r+1,o+1,i),e(t,n,r+2,o+2,i),e(t,n,r+3,o+3,i)}}));function s(t){return function(e,n,r=n){if(!((n=+n)>=0))throw new RangeError("invalid rx");if(!((r=+r)>=0))throw new RangeError("invalid ry");let{data:o,width:i,height:s}=e;if(!((i=Math.floor(i))>=0))throw new RangeError("invalid width");if(!((s=Math.floor(void 0!==s?s:o.length/i))>=0))throw new RangeError("invalid height");if(!i||!s||!n&&!r)return e;const c=n&&t(n),u=r&&t(r),f=o.slice();return c&&u?(a(c,f,o,i,s),a(c,o,f,i,s),a(c,f,o,i,s),l(u,o,f,i,s),l(u,f,o,i,s),l(u,o,f,i,s)):c?(a(c,o,f,i,s),a(c,f,o,i,s),a(c,o,f,i,s)):u&&(l(u,o,f,i,s),l(u,f,o,i,s),l(u,o,f,i,s)),e}}function a(t,e,n,r,o){for(let i=0,s=r*o;i<s;)t(e,n,i,i+=r,1)}function l(t,e,n,r,o){for(let i=0,s=r*o;i<r;++i)t(e,n,i,i+s,r)}function c(t){const e=Math.floor(t);if(e===t)return function(t){const e=2*t+1;return(n,r,o,i,s)=>{if(!((i-=s)>=o))return;let a=t*r[o];const l=s*t;for(let t=o,e=o+l;t<e;t+=s)a+=r[Math.min(i,t)];for(let t=o,c=i;t<=c;t+=s)a+=r[Math.min(i,t+l)],n[t]=a/e,a-=r[Math.max(o,t-l)]}}(t);const n=t-e,r=2*t+1;return(t,o,i,s,a)=>{if(!((s-=a)>=i))return;let l=e*o[i];const c=a*e,u=c+a;for(let t=i,e=i+c;t<e;t+=a)l+=o[Math.min(s,t)];for(let e=i,f=s;e<=f;e+=a)l+=o[Math.min(s,e+c)],t[e]=(l+n*(o[Math.max(i,e-u)]+o[Math.min(s,e+u)]))/r,l-=o[Math.max(i,e-c)]}}},879:(t,e,n)=>{"use strict";function r(t,e){let n=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&++n;else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(o=+o)>=o&&++n}return n}n.d(e,{Z:()=>r})},788:(t,e,n)=>{"use strict";function r(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}n.d(e,{Z:()=>r})},2038:(t,e,n)=>{"use strict";function r(t,e){let n,r;if(void 0===e)for(const e of t)null!=e&&(void 0===n?e>=e&&(n=r=e):(n>e&&(n=e),r<e&&(r=e)));else{let o=-1;for(let i of t)null!=(i=e(i,++o,t))&&(void 0===n?i>=i&&(n=r=i):(n>i&&(n=i),r<i&&(r=i)))}return[n,r]}n.d(e,{Z:()=>r})},9343:(t,e,n)=>{"use strict";n.d(e,{Kd:()=>i,dU:()=>r,e3:()=>o});class r{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const e=this._partials;let n=0;for(let r=0;r<this._n&&r<32;r++){const o=e[r],i=t+o,s=Math.abs(t)<Math.abs(o)?t-(i-o):o-(i-t);s&&(e[n++]=s),t=i}return e[n]=t,this._n=n+1,this}valueOf(){const t=this._partials;let e,n,r,o=this._n,i=0;if(o>0){for(i=t[--o];o>0&&(e=i,n=t[--o],i=e+n,r=n-(i-e),!r););o>0&&(r<0&&t[o-1]<0||r>0&&t[o-1]>0)&&(n=2*r,e=i+n,n==e-i&&(i=e))}return i}}function o(t,e){const n=new r;if(void 0===e)for(let e of t)(e=+e)&&n.add(e);else{let r=-1;for(let o of t)(o=+e(o,++r,t))&&n.add(o)}return+n}function i(t,e){const n=new r;let o=-1;return Float64Array.from(t,void 0===e?t=>n.add(+t||0):r=>n.add(+e(r,++o,t)||0))}},2942:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(9263);function o(t,e=r.Z){let n,o=!1;if(1===e.length){let i;for(const s of t){const t=e(s);(o?(0,r.Z)(t,i)>0:0===(0,r.Z)(t,t))&&(n=s,i=t,o=!0)}}else for(const r of t)(o?e(r,n)>0:0===e(r,r))&&(n=r,o=!0);return n}},9060:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Adder:()=>y.dU,InternMap:()=>v.L,InternSet:()=>v.H,ascending:()=>o.Z,bin:()=>D,bisect:()=>r.ZP,bisectCenter:()=>r.ZR,bisectLeft:()=>r.Nw,bisectRight:()=>r.ml,bisector:()=>i.Z,blur:()=>s.yv,blur2:()=>s.u8,blurImage:()=>s.TX,count:()=>a.Z,cross:()=>f,cumsum:()=>d,descending:()=>h.Z,deviation:()=>m,difference:()=>wt,disjoint:()=>xt,every:()=>mt,extent:()=>g.Z,fcumsum:()=>y.Kd,filter:()=>yt,flatGroup:()=>k,flatRollup:()=>q,fsum:()=>y.e3,greatest:()=>st.Z,greatestIndex:()=>at,group:()=>_,groupSort:()=>O,groups:()=>w,histogram:()=>D,index:()=>A,indexes:()=>M,intersection:()=>kt,least:()=>ot,leastIndex:()=>it,map:()=>vt,max:()=>$.Z,maxIndex:()=>G.Z,mean:()=>U,median:()=>J,medianIndex:()=>W,merge:()=>H.Z,min:()=>V.Z,minIndex:()=>Y.Z,mode:()=>Q,nice:()=>F,pairs:()=>K,permute:()=>tt.Z,quantile:()=>B.ZP,quantileIndex:()=>B.Cr,quantileSorted:()=>B.s7,quickselect:()=>et.Z,range:()=>nt.Z,rank:()=>rt,reduce:()=>bt,reverse:()=>_t,rollup:()=>N,rollups:()=>S,scan:()=>lt,shuffle:()=>ct,shuffler:()=>ut,some:()=>gt,sort:()=>j.ZP,subset:()=>At,sum:()=>ft,superset:()=>Nt,thresholdFreedmanDiaconis:()=>z,thresholdScott:()=>Z,thresholdSturges:()=>L.Z,tickIncrement:()=>P.G9,tickStep:()=>P.ly,ticks:()=>P.ZP,transpose:()=>dt,union:()=>Mt,variance:()=>p,zip:()=>pt});var r=n(5519),o=n(9263),i=n(3292),s=n(1045),a=n(879);function l(t){return 0|t.length}function c(t){return!(t>0)}function u(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function f(...t){const e="function"==typeof t[t.length-1]&&function(t){return e=>t(...e)}(t.pop()),n=(t=t.map(u)).map(l),r=t.length-1,o=new Array(r+1).fill(0),i=[];if(r<0||n.some(c))return i;for(;;){i.push(o.map(((e,n)=>t[n][e])));let s=r;for(;++o[s]===n[s];){if(0===s)return e?i.map(e):i;o[s--]=0}}}function d(t,e){var n=0,r=0;return Float64Array.from(t,void 0===e?t=>n+=+t||0:o=>n+=+e(o,r++,t)||0)}var h=n(788);function p(t,e){let n,r=0,o=0,i=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(n=e-o,o+=n/++r,i+=n*(e-o));else{let s=-1;for(let a of t)null!=(a=e(a,++s,t))&&(a=+a)>=a&&(n=a-o,o+=n/++r,i+=n*(a-o))}if(r>1)return i/(r-1)}function m(t,e){const n=p(t,e);return n?Math.sqrt(n):n}var g=n(2038),y=n(9343),v=n(8828);function b(t){return t}function _(t,...e){return C(t,b,b,e)}function w(t,...e){return C(t,Array.from,b,e)}function x(t,e){for(let n=1,r=e.length;n<r;++n)t=t.flatMap((t=>t.pop().map((([e,n])=>[...t,e,n]))));return t}function k(t,...e){return x(w(t,...e),e)}function q(t,e,...n){return x(S(t,e,...n),n)}function N(t,e,...n){return C(t,b,e,n)}function S(t,e,...n){return C(t,Array.from,e,n)}function A(t,...e){return C(t,b,T,e)}function M(t,...e){return C(t,Array.from,T,e)}function T(t){if(1!==t.length)throw new Error("duplicate key");return t[0]}function C(t,e,n,r){return function t(o,i){if(i>=r.length)return n(o);const s=new v.L,a=r[i++];let l=-1;for(const t of o){const e=a(t,++l,o),n=s.get(e);n?n.push(t):s.set(e,[t])}for(const[e,n]of s)s.set(e,t(n,i));return e(s)}(t,0)}var j=n(3897);function O(t,e,n){return(2!==e.length?(0,j.ZP)(N(t,e,n),(([t,e],[n,r])=>(0,o.Z)(e,r)||(0,o.Z)(t,n))):(0,j.ZP)(_(t,n),(([t,n],[r,i])=>e(n,i)||(0,o.Z)(t,r)))).map((([t])=>t))}var E=Array.prototype,R=E.slice;E.map;function I(t){return()=>t}var P=n(6106);function F(t,e,n){let r;for(;;){const o=(0,P.G9)(t,e,n);if(o===r||0===o||!isFinite(o))return[t,e];o>0?(t=Math.floor(t/o)*o,e=Math.ceil(e/o)*o):o<0&&(t=Math.ceil(t*o)/o,e=Math.floor(e*o)/o),r=o}}var L=n(2327);function D(){var t=b,e=g.Z,n=L.Z;function o(o){Array.isArray(o)||(o=Array.from(o));var i,s,a,l=o.length,c=new Array(l);for(i=0;i<l;++i)c[i]=t(o[i],i,o);var u=e(c),f=u[0],d=u[1],h=n(c,f,d);if(!Array.isArray(h)){const t=d,n=+h;if(e===g.Z&&([f,d]=F(f,d,n)),(h=(0,P.ZP)(f,d,n))[0]<=f&&(a=(0,P.G9)(f,d,n)),h[h.length-1]>=d)if(t>=d&&e===g.Z){const t=(0,P.G9)(f,d,n);isFinite(t)&&(t>0?d=(Math.floor(d/t)+1)*t:t<0&&(d=(Math.ceil(d*-t)+1)/-t))}else h.pop()}for(var p=h.length;h[0]<=f;)h.shift(),--p;for(;h[p-1]>d;)h.pop(),--p;var m,y=new Array(p+1);for(i=0;i<=p;++i)(m=y[i]=[]).x0=i>0?h[i-1]:f,m.x1=i<p?h[i]:d;if(isFinite(a)){if(a>0)for(i=0;i<l;++i)null!=(s=c[i])&&f<=s&&s<=d&&y[Math.min(p,Math.floor((s-f)/a))].push(o[i]);else if(a<0)for(i=0;i<l;++i)if(null!=(s=c[i])&&f<=s&&s<=d){const t=Math.floor((f-s)*a);y[Math.min(p,t+(h[t]<=s))].push(o[i])}}else for(i=0;i<l;++i)null!=(s=c[i])&&f<=s&&s<=d&&y[(0,r.ZP)(h,s,0,p)].push(o[i]);return y}return o.value=function(e){return arguments.length?(t="function"==typeof e?e:I(e),o):t},o.domain=function(t){return arguments.length?(e="function"==typeof t?t:I([t[0],t[1]]),o):e},o.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:Array.isArray(t)?I(R.call(t)):I(t),o):n},o}var B=n(1177);function z(t,e,n){return Math.ceil((n-e)/(2*((0,B.ZP)(t,.75)-(0,B.ZP)(t,.25))*Math.pow((0,a.Z)(t),-1/3)))}function Z(t,e,n){return Math.ceil((n-e)*Math.cbrt((0,a.Z)(t))/(3.49*m(t)))}var $=n(8319),G=n(5374);function U(t,e){let n=0,r=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(++n,r+=e);else{let o=-1;for(let i of t)null!=(i=e(i,++o,t))&&(i=+i)>=i&&(++n,r+=i)}if(n)return r/n}function J(t,e){return(0,B.ZP)(t,.5,e)}function W(t,e){return(0,B.Cr)(t,.5,e)}var H=n(1740),V=n(816),Y=n(2980);function Q(t,e){const n=new v.L;if(void 0===e)for(let e of t)null!=e&&e>=e&&n.set(e,(n.get(e)||0)+1);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&o>=o&&n.set(o,(n.get(o)||0)+1)}let r,o=0;for(const[t,e]of n)e>o&&(o=e,r=t);return r}function K(t,e=X){const n=[];let r,o=!1;for(const i of t)o&&n.push(e(r,i)),r=i,o=!0;return n}function X(t,e){return[t,e]}var tt=n(362),et=n(551),nt=n(1265);function rt(t,e=o.Z){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");let n=Array.from(t);const r=new Float64Array(n.length);2!==e.length&&(n=n.map(e),e=o.Z);const i=(t,r)=>e(n[t],n[r]);let s,a;return Uint32Array.from(n,((t,e)=>e)).sort(e===o.Z?(t,e)=>(0,j.Wv)(n[t],n[e]):(0,j.di)(i)).forEach(((t,e)=>{const n=i(t,void 0===s?t:s);n>=0?((void 0===s||n>0)&&(s=t,a=e),r[t]=a):r[t]=NaN})),r}function ot(t,e=o.Z){let n,r=!1;if(1===e.length){let i;for(const s of t){const t=e(s);(r?(0,o.Z)(t,i)<0:0===(0,o.Z)(t,t))&&(n=s,i=t,r=!0)}}else for(const o of t)(r?e(o,n)<0:0===e(o,o))&&(n=o,r=!0);return n}function it(t,e=o.Z){if(1===e.length)return(0,Y.Z)(t,e);let n,r=-1,i=-1;for(const o of t)++i,(r<0?0===e(o,o):e(o,n)<0)&&(n=o,r=i);return r}var st=n(2942);function at(t,e=o.Z){if(1===e.length)return(0,G.Z)(t,e);let n,r=-1,i=-1;for(const o of t)++i,(r<0?0===e(o,o):e(o,n)>0)&&(n=o,r=i);return r}function lt(t,e){const n=it(t,e);return n<0?void 0:n}const ct=ut(Math.random);function ut(t){return function(e,n=0,r=e.length){let o=r-(n=+n);for(;o;){const r=t()*o--|0,i=e[o+n];e[o+n]=e[r+n],e[r+n]=i}return e}}function ft(t,e){let n=0;if(void 0===e)for(let e of t)(e=+e)&&(n+=e);else{let r=-1;for(let o of t)(o=+e(o,++r,t))&&(n+=o)}return n}function dt(t){if(!(o=t.length))return[];for(var e=-1,n=(0,V.Z)(t,ht),r=new Array(n);++e<n;)for(var o,i=-1,s=r[e]=new Array(o);++i<o;)s[i]=t[i][e];return r}function ht(t){return t.length}function pt(){return dt(arguments)}function mt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");let n=-1;for(const r of t)if(!e(r,++n,t))return!1;return!0}function gt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");let n=-1;for(const r of t)if(e(r,++n,t))return!0;return!1}function yt(t,e){if("function"!=typeof e)throw new TypeError("test is not a function");const n=[];let r=-1;for(const o of t)e(o,++r,t)&&n.push(o);return n}function vt(t,e){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");if("function"!=typeof e)throw new TypeError("mapper is not a function");return Array.from(t,((n,r)=>e(n,r,t)))}function bt(t,e,n){if("function"!=typeof e)throw new TypeError("reducer is not a function");const r=t[Symbol.iterator]();let o,i,s=-1;if(arguments.length<3){if(({done:o,value:n}=r.next()),o)return;++s}for(;({done:o,value:i}=r.next()),!o;)n=e(n,i,++s,t);return n}function _t(t){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");return Array.from(t).reverse()}function wt(t,...e){t=new v.H(t);for(const n of e)for(const e of n)t.delete(e);return t}function xt(t,e){const n=e[Symbol.iterator](),r=new v.H;for(const e of t){if(r.has(e))return!1;let t,o;for(;({value:t,done:o}=n.next())&&!o;){if(Object.is(e,t))return!1;r.add(t)}}return!0}function kt(t,...e){t=new v.H(t),e=e.map(qt);t:for(const n of t)for(const r of e)if(!r.has(n)){t.delete(n);continue t}return t}function qt(t){return t instanceof v.H?t:new v.H(t)}function Nt(t,e){const n=t[Symbol.iterator](),r=new Set;for(const t of e){const e=St(t);if(r.has(e))continue;let o,i;for(;({value:o,done:i}=n.next());){if(i)return!1;const t=St(o);if(r.add(t),Object.is(e,t))break}}return!0}function St(t){return null!==t&&"object"==typeof t?t.valueOf():t}function At(t,e){return Nt(e,t)}function Mt(...t){const e=new v.H;for(const n of t)for(const t of n)e.add(t);return e}},8319:(t,e,n)=>{"use strict";function r(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(n<o||void 0===n&&o>=o)&&(n=o)}return n}n.d(e,{Z:()=>r})},5374:(t,e,n)=>{"use strict";function r(t,e){let n,r=-1,o=-1;if(void 0===e)for(const e of t)++o,null!=e&&(n<e||void 0===n&&e>=e)&&(n=e,r=o);else for(let i of t)null!=(i=e(i,++o,t))&&(n<i||void 0===n&&i>=i)&&(n=i,r=o);return r}n.d(e,{Z:()=>r})},1740:(t,e,n)=>{"use strict";function r(t){return Array.from(function*(t){for(const e of t)yield*e}(t))}n.d(e,{Z:()=>r})},816:(t,e,n)=>{"use strict";function r(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let o of t)null!=(o=e(o,++r,t))&&(n>o||void 0===n&&o>=o)&&(n=o)}return n}n.d(e,{Z:()=>r})},2980:(t,e,n)=>{"use strict";function r(t,e){let n,r=-1,o=-1;if(void 0===e)for(const e of t)++o,null!=e&&(n>e||void 0===n&&e>=e)&&(n=e,r=o);else for(let i of t)null!=(i=e(i,++o,t))&&(n>i||void 0===n&&i>=i)&&(n=i,r=o);return r}n.d(e,{Z:()=>r})},3745:(t,e,n)=>{"use strict";function r(t){return null===t?NaN:+t}function*o(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let r of t)null!=(r=e(r,++n,t))&&(r=+r)>=r&&(yield r)}}n.d(e,{K:()=>o,Z:()=>r})},362:(t,e,n)=>{"use strict";function r(t,e){return Array.from(e,(e=>t[e]))}n.d(e,{Z:()=>r})},1177:(t,e,n)=>{"use strict";n.d(e,{Cr:()=>h,ZP:()=>f,s7:()=>d});var r=n(8319),o=n(5374),i=n(816),s=n(2980),a=n(551),l=n(3745),c=n(3897),u=n(2942);function f(t,e,n){if(o=(t=Float64Array.from((0,l.K)(t,n))).length){if((e=+e)<=0||o<2)return(0,i.Z)(t);if(e>=1)return(0,r.Z)(t);var o,s=(o-1)*e,c=Math.floor(s),u=(0,r.Z)((0,a.Z)(t,c).subarray(0,c+1));return u+((0,i.Z)(t.subarray(c+1))-u)*(s-c)}}function d(t,e,n=l.Z){if(r=t.length){if((e=+e)<=0||r<2)return+n(t[0],0,t);if(e>=1)return+n(t[r-1],r-1,t);var r,o=(r-1)*e,i=Math.floor(o),s=+n(t[i],i,t);return s+(+n(t[i+1],i+1,t)-s)*(o-i)}}function h(t,e,n){if(r=(t=Float64Array.from((0,l.K)(t,n))).length){if((e=+e)<=0||r<2)return(0,s.Z)(t);if(e>=1)return(0,o.Z)(t);var r,i=Math.floor((r-1)*e),f=(0,a.Z)(Uint32Array.from(t,((t,e)=>e)),i,0,r-1,((e,n)=>(0,c.Wv)(t[e],t[n])));return(0,u.Z)(f.subarray(0,i+1),(e=>t[e]))}}},551:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(3897);function o(t,e,n=0,s=t.length-1,a){for(a=void 0===a?r.Wv:(0,r.di)(a);s>n;){if(s-n>600){const r=s-n+1,i=e-n+1,l=Math.log(r),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(r-c)/r)*(i-r/2<0?-1:1);o(t,e,Math.max(n,Math.floor(e-i*c/r+u)),Math.min(s,Math.floor(e+(r-i)*c/r+u)),a)}const r=t[e];let l=n,c=s;for(i(t,n,e),a(t[s],r)>0&&i(t,n,s);l<c;){for(i(t,l,c),++l,--c;a(t[l],r)<0;)++l;for(;a(t[c],r)>0;)--c}0===a(t[n],r)?i(t,n,c):(++c,i(t,c,s)),c<=e&&(n=c+1),e<=c&&(s=c-1)}return t}function i(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}},1265:(t,e,n)=>{"use strict";function r(t,e,n){t=+t,e=+e,n=(o=arguments.length)<2?(e=t,t=0,1):o<3?1:+n;for(var r=-1,o=0|Math.max(0,Math.ceil((e-t)/n)),i=new Array(o);++r<o;)i[r]=t+r*n;return i}n.d(e,{Z:()=>r})},3897:(t,e,n)=>{"use strict";n.d(e,{Wv:()=>a,ZP:()=>i,di:()=>s});var r=n(9263),o=n(362);function i(t,...e){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");t=Array.from(t);let[n]=e;if(n&&2!==n.length||e.length>1){const r=Uint32Array.from(t,((t,e)=>e));return e.length>1?(e=e.map((e=>t.map(e))),r.sort(((t,n)=>{for(const r of e){const e=a(r[t],r[n]);if(e)return e}}))):(n=t.map(n),r.sort(((t,e)=>a(n[t],n[e])))),(0,o.Z)(t,r)}return t.sort(s(n))}function s(t=r.Z){if(t===r.Z)return a;if("function"!=typeof t)throw new TypeError("compare is not a function");return(e,n)=>{const r=t(e,n);return r||0===r?r:(0===t(n,n))-(0===t(e,e))}}function a(t,e){return(null==t||!(t>=t))-(null==e||!(e>=e))||(t<e?-1:t>e?1:0)}},2327:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(879);function o(t){return Math.ceil(Math.log((0,r.Z)(t))/Math.LN2)+1}},6106:(t,e,n)=>{"use strict";n.d(e,{G9:()=>a,ZP:()=>s,ly:()=>l});var r=Math.sqrt(50),o=Math.sqrt(10),i=Math.sqrt(2);function s(t,e,n){var r,o,i,s,l=-1;if(n=+n,(t=+t)===(e=+e)&&n>0)return[t];if((r=e<t)&&(o=t,t=e,e=o),0===(s=a(t,e,n))||!isFinite(s))return[];if(s>0){let n=Math.round(t/s),r=Math.round(e/s);for(n*s<t&&++n,r*s>e&&--r,i=new Array(o=r-n+1);++l<o;)i[l]=(n+l)*s}else{s=-s;let n=Math.round(t*s),r=Math.round(e*s);for(n/s<t&&++n,r/s>e&&--r,i=new Array(o=r-n+1);++l<o;)i[l]=(n+l)/s}return r&&i.reverse(),i}function a(t,e,n){var s=(e-t)/Math.max(0,n),a=Math.floor(Math.log(s)/Math.LN10),l=s/Math.pow(10,a);return a>=0?(l>=r?10:l>=o?5:l>=i?2:1)*Math.pow(10,a):-Math.pow(10,-a)/(l>=r?10:l>=o?5:l>=i?2:1)}function l(t,e,n){var s=Math.abs(e-t)/Math.max(0,n),a=Math.pow(10,Math.floor(Math.log(s)/Math.LN10)),l=s/a;return l>=r?a*=10:l>=o?a*=5:l>=i&&(a*=2),e<t?-a:a}},1495:(t,e,n)=>{"use strict";n.d(e,{B8:()=>q,Il:()=>o,J5:()=>s,SU:()=>k,Ss:()=>N,Ym:()=>E,ZP:()=>_,xV:()=>i});var r=n(3456);function o(){}var i=.7,s=1/i,a="\\s*([+-]?\\d+)\\s*",l="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",c="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",u=/^#([0-9a-f]{3,8})$/,f=new RegExp(`^rgb\\(${a},${a},${a}\\)$`),d=new RegExp(`^rgb\\(${c},${c},${c}\\)$`),h=new RegExp(`^rgba\\(${a},${a},${a},${l}\\)$`),p=new RegExp(`^rgba\\(${c},${c},${c},${l}\\)$`),m=new RegExp(`^hsl\\(${l},${c},${c}\\)$`),g=new RegExp(`^hsla\\(${l},${c},${c},${l}\\)$`),y={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function v(){return this.rgb().formatHex()}function b(){return this.rgb().formatRgb()}function _(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=u.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?w(e):3===n?new N(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?x(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?x(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=f.exec(t))?new N(e[1],e[2],e[3],1):(e=d.exec(t))?new N(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=h.exec(t))?x(e[1],e[2],e[3],e[4]):(e=p.exec(t))?x(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=m.exec(t))?j(e[1],e[2]/100,e[3]/100,1):(e=g.exec(t))?j(e[1],e[2]/100,e[3]/100,e[4]):y.hasOwnProperty(t)?w(y[t]):"transparent"===t?new N(NaN,NaN,NaN,0):null}function w(t){return new N(t>>16&255,t>>8&255,255&t,1)}function x(t,e,n,r){return r<=0&&(t=e=n=NaN),new N(t,e,n,r)}function k(t){return t instanceof o||(t=_(t)),t?new N((t=t.rgb()).r,t.g,t.b,t.opacity):new N}function q(t,e,n,r){return 1===arguments.length?k(t):new N(t,e,n,null==r?1:r)}function N(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function S(){return`#${C(this.r)}${C(this.g)}${C(this.b)}`}function A(){const t=M(this.opacity);return`${1===t?"rgb(":"rgba("}${T(this.r)}, ${T(this.g)}, ${T(this.b)}${1===t?")":`, ${t})`}`}function M(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function T(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function C(t){return((t=T(t))<16?"0":"")+t.toString(16)}function j(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new R(t,e,n,r)}function O(t){if(t instanceof R)return new R(t.h,t.s,t.l,t.opacity);if(t instanceof o||(t=_(t)),!t)return new R;if(t instanceof R)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),s=Math.max(e,n,r),a=NaN,l=s-i,c=(s+i)/2;return l?(a=e===s?(n-r)/l+6*(n<r):n===s?(r-e)/l+2:(e-n)/l+4,l/=c<.5?s+i:2-s-i,a*=60):l=c>0&&c<1?0:a,new R(a,l,c,t.opacity)}function E(t,e,n,r){return 1===arguments.length?O(t):new R(t,e,n,null==r?1:r)}function R(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function I(t){return(t=(t||0)%360)<0?t+360:t}function P(t){return Math.max(0,Math.min(1,t||0))}function F(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}(0,r.Z)(o,_,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:v,formatHex:v,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return O(this).formatHsl()},formatRgb:b,toString:b}),(0,r.Z)(N,q,(0,r.l)(o,{brighter(t){return t=null==t?s:Math.pow(s,t),new N(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?i:Math.pow(i,t),new N(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new N(T(this.r),T(this.g),T(this.b),M(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:S,formatHex:S,formatHex8:function(){return`#${C(this.r)}${C(this.g)}${C(this.b)}${C(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:A,toString:A})),(0,r.Z)(R,E,(0,r.l)(o,{brighter(t){return t=null==t?s:Math.pow(s,t),new R(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?i:Math.pow(i,t),new R(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,o=2*n-r;return new N(F(t>=240?t-240:t+120,o,r),F(t,o,r),F(t<120?t+240:t-120,o,r),this.opacity)},clamp(){return new R(I(this.h),P(this.s),P(this.l),M(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=M(this.opacity);return`${1===t?"hsl(":"hsla("}${I(this.h)}, ${100*P(this.s)}%, ${100*P(this.l)}%${1===t?")":`, ${t})`}`}}))},3763:(t,e,n)=>{"use strict";n.d(e,{Z:()=>p});var r=n(3456),o=n(1495),i=n(7274),s=-.14861,a=1.78277,l=-.29227,c=-.90649,u=1.97294,f=u*c,d=u*a,h=a*l-c*s;function p(t,e,n,r){return 1===arguments.length?function(t){if(t instanceof m)return new m(t.h,t.s,t.l,t.opacity);t instanceof o.Ss||(t=(0,o.SU)(t));var e=t.r/255,n=t.g/255,r=t.b/255,s=(h*r+f*e-d*n)/(h+f-d),a=r-s,p=(u*(n-s)-l*a)/c,g=Math.sqrt(p*p+a*a)/(u*s*(1-s)),y=g?Math.atan2(p,a)*i.R-120:NaN;return new m(y<0?y+360:y,g,s,t.opacity)}(t):new m(t,e,n,null==r?1:r)}function m(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}(0,r.Z)(m,p,(0,r.l)(o.Il,{brighter(t){return t=null==t?o.J5:Math.pow(o.J5,t),new m(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?o.xV:Math.pow(o.xV,t),new m(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=isNaN(this.h)?0:(this.h+120)*i.u,e=+this.l,n=isNaN(this.s)?0:this.s*e*(1-e),r=Math.cos(t),f=Math.sin(t);return new o.Ss(255*(e+n*(s*r+a*f)),255*(e+n*(l*r+c*f)),255*(e+n*(u*r)),this.opacity)}}))},3456:(t,e,n)=>{"use strict";function r(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function o(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}n.d(e,{Z:()=>r,l:()=>o})},7346:(t,e,n)=>{"use strict";n.r(e),n.d(e,{color:()=>r.ZP,cubehelix:()=>i.Z,gray:()=>o.MA,hcl:()=>o.Uc,hsl:()=>r.Ym,lab:()=>o.ZP,lch:()=>o.tW,rgb:()=>r.B8});var r=n(1495),o=n(3334),i=n(3763)},3334:(t,e,n)=>{"use strict";n.d(e,{MA:()=>p,Uc:()=>k,ZP:()=>m,tW:()=>x});var r=n(3456),o=n(1495),i=n(7274);const s=.96422,a=1,l=.82521,c=4/29,u=6/29,f=3*u*u,d=u*u*u;function h(t){if(t instanceof g)return new g(t.l,t.a,t.b,t.opacity);if(t instanceof q)return N(t);t instanceof o.Ss||(t=(0,o.SU)(t));var e,n,r=_(t.r),i=_(t.g),c=_(t.b),u=y((.2225045*r+.7168786*i+.0606169*c)/a);return r===i&&i===c?e=n=u:(e=y((.4360747*r+.3850649*i+.1430804*c)/s),n=y((.0139322*r+.0971045*i+.7141733*c)/l)),new g(116*u-16,500*(e-u),200*(u-n),t.opacity)}function p(t,e){return new g(t,0,0,null==e?1:e)}function m(t,e,n,r){return 1===arguments.length?h(t):new g(t,e,n,null==r?1:r)}function g(t,e,n,r){this.l=+t,this.a=+e,this.b=+n,this.opacity=+r}function y(t){return t>d?Math.pow(t,1/3):t/f+c}function v(t){return t>u?t*t*t:f*(t-c)}function b(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function _(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function w(t){if(t instanceof q)return new q(t.h,t.c,t.l,t.opacity);if(t instanceof g||(t=h(t)),0===t.a&&0===t.b)return new q(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*i.R;return new q(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function x(t,e,n,r){return 1===arguments.length?w(t):new q(n,e,t,null==r?1:r)}function k(t,e,n,r){return 1===arguments.length?w(t):new q(t,e,n,null==r?1:r)}function q(t,e,n,r){this.h=+t,this.c=+e,this.l=+n,this.opacity=+r}function N(t){if(isNaN(t.h))return new g(t.l,0,0,t.opacity);var e=t.h*i.u;return new g(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}(0,r.Z)(g,m,(0,r.l)(o.Il,{brighter(t){return new g(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker(t){return new g(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return e=s*v(e),t=a*v(t),n=l*v(n),new o.Ss(b(3.1338561*e-1.6168667*t-.4906146*n),b(-.9787684*e+1.9161415*t+.033454*n),b(.0719453*e-.2289914*t+1.4052427*n),this.opacity)}})),(0,r.Z)(q,k,(0,r.l)(o.Il,{brighter(t){return new q(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker(t){return new q(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb(){return N(this).rgb()}}))},7274:(t,e,n)=>{"use strict";n.d(e,{R:()=>o,u:()=>r});const r=Math.PI/180,o=180/Math.PI},9106:(t,e,n)=>{"use strict";n.d(e,{Bj:()=>i,Jb:()=>l,S:()=>a,Sf:()=>s,eX:()=>u,fh:()=>c,ue:()=>o});var r=(0,n(4476).Z)(","),o=r.parse,i=r.parseRows,s=r.format,a=r.formatBody,l=r.formatRows,c=r.formatRow,u=r.formatValue},4476:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r={},o={},i=34,s=10,a=13;function l(t){return new Function("d","return {"+t.map((function(t,e){return JSON.stringify(t)+": d["+e+'] || ""'})).join(",")+"}")}function c(t){var e=Object.create(null),n=[];return t.forEach((function(t){for(var r in t)r in e||n.push(e[r]=r)})),n}function u(t,e){var n=t+"",r=n.length;return r<e?new Array(e-r+1).join(0)+n:n}function f(t){var e,n=t.getUTCHours(),r=t.getUTCMinutes(),o=t.getUTCSeconds(),i=t.getUTCMilliseconds();return isNaN(t)?"Invalid Date":((e=t.getUTCFullYear())<0?"-"+u(-e,6):e>9999?"+"+u(e,6):u(e,4))+"-"+u(t.getUTCMonth()+1,2)+"-"+u(t.getUTCDate(),2)+(i?"T"+u(n,2)+":"+u(r,2)+":"+u(o,2)+"."+u(i,3)+"Z":o?"T"+u(n,2)+":"+u(r,2)+":"+u(o,2)+"Z":r||n?"T"+u(n,2)+":"+u(r,2)+"Z":"")}function d(t){var e=new RegExp('["'+t+"\n\r]"),n=t.charCodeAt(0);function u(t,e){var l,c=[],u=t.length,f=0,d=0,h=u<=0,p=!1;function m(){if(h)return o;if(p)return p=!1,r;var e,l,c=f;if(t.charCodeAt(c)===i){for(;f++<u&&t.charCodeAt(f)!==i||t.charCodeAt(++f)===i;);return(e=f)>=u?h=!0:(l=t.charCodeAt(f++))===s?p=!0:l===a&&(p=!0,t.charCodeAt(f)===s&&++f),t.slice(c+1,e-1).replace(/""/g,'"')}for(;f<u;){if((l=t.charCodeAt(e=f++))===s)p=!0;else if(l===a)p=!0,t.charCodeAt(f)===s&&++f;else if(l!==n)continue;return t.slice(c,e)}return h=!0,t.slice(c,u)}for(t.charCodeAt(u-1)===s&&--u,t.charCodeAt(u-1)===a&&--u;(l=m())!==o;){for(var g=[];l!==r&&l!==o;)g.push(l),l=m();e&&null==(g=e(g,d++))||c.push(g)}return c}function d(e,n){return e.map((function(e){return n.map((function(t){return p(e[t])})).join(t)}))}function h(e){return e.map(p).join(t)}function p(t){return null==t?"":t instanceof Date?f(t):e.test(t+="")?'"'+t.replace(/"/g,'""')+'"':t}return{parse:function(t,e){var n,r,o=u(t,(function(t,o){if(n)return n(t,o-1);r=t,n=e?function(t,e){var n=l(t);return function(r,o){return e(n(r),o,t)}}(t,e):l(t)}));return o.columns=r||[],o},parseRows:u,format:function(e,n){return null==n&&(n=c(e)),[n.map(p).join(t)].concat(d(e,n)).join("\n")},formatBody:function(t,e){return null==e&&(e=c(t)),d(t,e).join("\n")},formatRows:function(t){return t.map(h).join("\n")},formatRow:h,formatValue:p}}},2884:(t,e,n)=>{"use strict";n.r(e),n.d(e,{autoType:()=>s,csvFormat:()=>o.Sf,csvFormatBody:()=>o.S,csvFormatRow:()=>o.fh,csvFormatRows:()=>o.Jb,csvFormatValue:()=>o.eX,csvParse:()=>o.ue,csvParseRows:()=>o.Bj,dsvFormat:()=>r.Z,tsvFormat:()=>i.vP,tsvFormatBody:()=>i.uH,tsvFormatRow:()=>i.Hf,tsvFormatRows:()=>i.n5,tsvFormatValue:()=>i.sS,tsvParse:()=>i.tJ,tsvParseRows:()=>i.E0});var r=n(4476),o=n(9106),i=n(5026);function s(t){for(var e in t){var n,r,o=t[e].trim();if(o)if("true"===o)o=!0;else if("false"===o)o=!1;else if("NaN"===o)o=NaN;else if(isNaN(n=+o)){if(!(r=o.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;a&&r[4]&&!r[7]&&(o=o.replace(/-/g,"/").replace(/T/," ")),o=new Date(o)}else o=n;else o=null;t[e]=o}return t}const a=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours()},5026:(t,e,n)=>{"use strict";n.d(e,{E0:()=>i,Hf:()=>c,n5:()=>l,sS:()=>u,tJ:()=>o,uH:()=>a,vP:()=>s});var r=(0,n(4476).Z)("\t"),o=r.parse,i=r.parseRows,s=r.format,a=r.formatBody,l=r.formatRows,c=r.formatRow,u=r.formatValue},2163:(t,e,n)=>{"use strict";n.d(e,{WU:()=>o,ZP:()=>a,jH:()=>i});var r,o,i,s=n(2107);function a(t){return r=(0,s.Z)(t),o=r.format,i=r.formatPrefix,r}a({thousands:",",grouping:[3],currency:["$",""]})},2313:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(4218);function o(t){return(t=(0,r.V)(Math.abs(t)))?t[1]:NaN}},4218:(t,e,n)=>{"use strict";function r(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function o(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}n.d(e,{V:()=>o,Z:()=>r})},7259:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o,v:()=>i});var r=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function o(t){if(!(e=r.exec(t)))throw new Error("invalid format: "+t);var e;return new i({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function i(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}o.prototype=i.prototype,i.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type}},8288:(t,e,n)=>{"use strict";n.r(e),n.d(e,{FormatSpecifier:()=>i.v,format:()=>r.WU,formatDefaultLocale:()=>r.ZP,formatLocale:()=>o.Z,formatPrefix:()=>r.jH,formatSpecifier:()=>i.Z,precisionFixed:()=>s.Z,precisionPrefix:()=>a.Z,precisionRound:()=>l.Z});var r=n(2163),o=n(2107),i=n(7259),s=n(9680),a=n(3150),l=n(3621)},2107:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(2313);var o=n(7259);var i,s=n(4218);function a(t,e){var n=(0,s.V)(t,e);if(!n)return t+"";var r=n[0],o=n[1];return o<0?"0."+new Array(-o).join("0")+r:r.length>o+1?r.slice(0,o+1)+"."+r.slice(o+1):r+new Array(o-r.length+2).join("0")}const l={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:s.Z,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>a(100*t,e),r:a,s:function(t,e){var n=(0,s.V)(t,e);if(!n)return t+"";var r=n[0],o=n[1],a=o-(i=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,l=r.length;return a===l?r:a>l?r+new Array(a-l+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+(0,s.V)(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function c(t){return t}var u=Array.prototype.map,f=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function d(t){var e,n,s=void 0===t.grouping||void 0===t.thousands?c:(e=u.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var o=t.length,i=[],s=0,a=e[0],l=0;o>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),i.push(t.substring(o-=a,o+a)),!((l+=a+1)>r));)a=e[s=(s+1)%e.length];return i.reverse().join(n)}),a=void 0===t.currency?"":t.currency[0]+"",d=void 0===t.currency?"":t.currency[1]+"",h=void 0===t.decimal?".":t.decimal+"",p=void 0===t.numerals?c:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(u.call(t.numerals,String)),m=void 0===t.percent?"%":t.percent+"",g=void 0===t.minus?"−":t.minus+"",y=void 0===t.nan?"NaN":t.nan+"";function v(t){var e=(t=(0,o.Z)(t)).fill,n=t.align,r=t.sign,c=t.symbol,u=t.zero,v=t.width,b=t.comma,_=t.precision,w=t.trim,x=t.type;"n"===x?(b=!0,x="g"):l[x]||(void 0===_&&(_=12),w=!0,x="g"),(u||"0"===e&&"="===n)&&(u=!0,e="0",n="=");var k="$"===c?a:"#"===c&&/[boxX]/.test(x)?"0"+x.toLowerCase():"",q="$"===c?d:/[%p]/.test(x)?m:"",N=l[x],S=/[defgprs%]/.test(x);function A(t){var o,a,l,c=k,d=q;if("c"===x)d=N(t)+d,t="";else{var m=(t=+t)<0||1/t<0;if(t=isNaN(t)?y:N(Math.abs(t),_),w&&(t=function(t){t:for(var e,n=t.length,r=1,o=-1;r<n;++r)switch(t[r]){case".":o=e=r;break;case"0":0===o&&(o=r),e=r;break;default:if(!+t[r])break t;o>0&&(o=0)}return o>0?t.slice(0,o)+t.slice(e+1):t}(t)),m&&0==+t&&"+"!==r&&(m=!1),c=(m?"("===r?r:g:"-"===r||"("===r?"":r)+c,d=("s"===x?f[8+i/3]:"")+d+(m&&"("===r?")":""),S)for(o=-1,a=t.length;++o<a;)if(48>(l=t.charCodeAt(o))||l>57){d=(46===l?h+t.slice(o+1):t.slice(o))+d,t=t.slice(0,o);break}}b&&!u&&(t=s(t,1/0));var A=c.length+t.length+d.length,M=A<v?new Array(v-A+1).join(e):"";switch(b&&u&&(t=s(M+t,M.length?v-d.length:1/0),M=""),n){case"<":t=c+t+d+M;break;case"=":t=c+M+t+d;break;case"^":t=M.slice(0,A=M.length>>1)+c+t+d+M.slice(A);break;default:t=M+c+t+d}return p(t)}return _=void 0===_?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_)),A.toString=function(){return t+""},A}return{format:v,formatPrefix:function(t,e){var n=v(((t=(0,o.Z)(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor((0,r.Z)(e)/3))),s=Math.pow(10,-i),a=f[8+i/3];return function(t){return n(s*t)+a}}}}},9680:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t){return Math.max(0,-(0,r.Z)(Math.abs(t)))}},3150:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor((0,r.Z)(e)/3)))-(0,r.Z)(Math.abs(t)))}},3621:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2313);function o(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,(0,r.Z)(e)-(0,r.Z)(t))+1}},5505:(t,e,n)=>{"use strict";function r(t,e){return t.parent===e.parent?1:2}function o(t,e){return t+e.x}function i(t,e){return Math.max(t,e.y)}function s(){var t=r,e=1,n=1,s=!1;function a(r){var a,l=0;r.eachAfter((function(e){var n=e.children;n?(e.x=function(t){return t.reduce(o,0)/t.length}(n),e.y=function(t){return 1+t.reduce(i,0)}(n)):(e.x=a?l+=t(e,a):0,e.y=0,a=e)}));var c=function(t){for(var e;e=t.children;)t=e[0];return t}(r),u=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(r),f=c.x-t(c,u)/2,d=u.x+t(u,c)/2;return r.eachAfter(s?function(t){t.x=(t.x-r.x)*e,t.y=(r.y-t.y)*n}:function(t){t.x=(t.x-f)/(d-f)*e,t.y=(1-(r.y?t.y/r.y:1))*n})}return a.separation=function(e){return arguments.length?(t=e,a):t},a.size=function(t){return arguments.length?(s=!1,e=+t[0],n=+t[1],a):s?null:[e,n]},a.nodeSize=function(t){return arguments.length?(s=!0,e=+t[0],n=+t[1],a):s?[e,n]:null},a}function a(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function l(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=u)):void 0===e&&(e=c);for(var n,r,o,i,s,a=new h(t),l=[a];n=l.pop();)if((o=e(n.data))&&(s=(o=Array.from(o)).length))for(n.children=o,i=s-1;i>=0;--i)l.push(r=o[i]=new h(o[i])),r.parent=n,r.depth=n.depth+1;return a.eachBefore(d)}function c(t){return t.children}function u(t){return Array.isArray(t)?t[1]:null}function f(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function d(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function p(t){return null==t?null:m(t)}function m(t){if("function"!=typeof t)throw new Error;return t}function g(){return 0}function y(t){return function(){return t}}n.d(e,{NB:()=>h,ki:()=>s,bT:()=>l,P2:()=>L,O1:()=>x,jA:()=>P,uK:()=>G,QP:()=>Y,G_:()=>it,pN:()=>ut,wL:()=>ft,LQ:()=>$,eA:()=>ht,Km:()=>st,E_:()=>dt,o$:()=>ct}),h.prototype=l.prototype={constructor:h,count:function(){return this.eachAfter(a)},each:function(t,e){let n=-1;for(const r of this)t.call(e,r,++n,this);return this},eachAfter:function(t,e){for(var n,r,o,i=this,s=[i],a=[],l=-1;i=s.pop();)if(a.push(i),n=i.children)for(r=0,o=n.length;r<o;++r)s.push(n[r]);for(;i=a.pop();)t.call(e,i,++l,this);return this},eachBefore:function(t,e){for(var n,r,o=this,i=[o],s=-1;o=i.pop();)if(t.call(e,o,++s,this),n=o.children)for(r=n.length-1;r>=0;--r)i.push(n[r]);return this},find:function(t,e){let n=-1;for(const r of this)if(t.call(e,r,++n,this))return r},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,o=r&&r.length;--o>=0;)n+=r[o].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),o=null;t=n.pop(),e=r.pop();for(;t===e;)o=t,t=n.pop(),e=r.pop();return o}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var o=r.length;t!==n;)r.splice(o,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return l(this).eachBefore(f)},[Symbol.iterator]:function*(){var t,e,n,r,o=this,i=[o];do{for(t=i.reverse(),i=[];o=t.pop();)if(yield o,e=o.children)for(n=0,r=e.length;n<r;++n)i.push(e[n])}while(i.length)}};const v=1664525,b=1013904223,_=4294967296;function w(){let t=1;return()=>(t=(v*t+b)%_)/_}function x(t){return k(t,w())}function k(t,e){for(var n,r,o=0,i=(t=function(t,e){let n,r,o=t.length;for(;o;)r=e()*o--|0,n=t[o],t[o]=t[r],t[r]=n;return t}(Array.from(t),e)).length,s=[];o<i;)n=t[o],r&&S(r,n)?++o:(r=M(s=q(s,n)),o=0);return r}function q(t,e){var n,r;if(A(e,t))return[e];for(n=0;n<t.length;++n)if(N(e,t[n])&&A(T(t[n],e),t))return[t[n],e];for(n=0;n<t.length-1;++n)for(r=n+1;r<t.length;++r)if(N(T(t[n],t[r]),e)&&N(T(t[n],e),t[r])&&N(T(t[r],e),t[n])&&A(C(t[n],t[r],e),t))return[t[n],t[r],e];throw new Error}function N(t,e){var n=t.r-e.r,r=e.x-t.x,o=e.y-t.y;return n<0||n*n<r*r+o*o}function S(t,e){var n=t.r-e.r+1e-9*Math.max(t.r,e.r,1),r=e.x-t.x,o=e.y-t.y;return n>0&&n*n>r*r+o*o}function A(t,e){for(var n=0;n<e.length;++n)if(!S(t,e[n]))return!1;return!0}function M(t){switch(t.length){case 1:return function(t){return{x:t.x,y:t.y,r:t.r}}(t[0]);case 2:return T(t[0],t[1]);case 3:return C(t[0],t[1],t[2])}}function T(t,e){var n=t.x,r=t.y,o=t.r,i=e.x,s=e.y,a=e.r,l=i-n,c=s-r,u=a-o,f=Math.sqrt(l*l+c*c);return{x:(n+i+l/f*u)/2,y:(r+s+c/f*u)/2,r:(f+o+a)/2}}function C(t,e,n){var r=t.x,o=t.y,i=t.r,s=e.x,a=e.y,l=e.r,c=n.x,u=n.y,f=n.r,d=r-s,h=r-c,p=o-a,m=o-u,g=l-i,y=f-i,v=r*r+o*o-i*i,b=v-s*s-a*a+l*l,_=v-c*c-u*u+f*f,w=h*p-d*m,x=(p*_-m*b)/(2*w)-r,k=(m*g-p*y)/w,q=(h*b-d*_)/(2*w)-o,N=(d*y-h*g)/w,S=k*k+N*N-1,A=2*(i+x*k+q*N),M=x*x+q*q-i*i,T=-(Math.abs(S)>1e-6?(A+Math.sqrt(A*A-4*S*M))/(2*S):M/A);return{x:r+x+k*T,y:o+q+N*T,r:T}}function j(t,e,n){var r,o,i,s,a=t.x-e.x,l=t.y-e.y,c=a*a+l*l;c?(o=e.r+n.r,o*=o,s=t.r+n.r,o>(s*=s)?(r=(c+s-o)/(2*c),i=Math.sqrt(Math.max(0,s/c-r*r)),n.x=t.x-r*a-i*l,n.y=t.y-r*l+i*a):(r=(c+o-s)/(2*c),i=Math.sqrt(Math.max(0,o/c-r*r)),n.x=e.x+r*a-i*l,n.y=e.y+r*l+i*a)):(n.x=e.x+n.r,n.y=e.y)}function O(t,e){var n=t.r+e.r-1e-6,r=e.x-t.x,o=e.y-t.y;return n>0&&n*n>r*r+o*o}function E(t){var e=t._,n=t.next._,r=e.r+n.r,o=(e.x*n.r+n.x*e.r)/r,i=(e.y*n.r+n.y*e.r)/r;return o*o+i*i}function R(t){this._=t,this.next=null,this.previous=null}function I(t,e){if(!(s=(n=t,t="object"==typeof n&&"length"in n?n:Array.from(n)).length))return 0;var n,r,o,i,s,a,l,c,u,f,d,h;if((r=t[0]).x=0,r.y=0,!(s>1))return r.r;if(o=t[1],r.x=-o.r,o.x=r.r,o.y=0,!(s>2))return r.r+o.r;j(o,r,i=t[2]),r=new R(r),o=new R(o),i=new R(i),r.next=i.previous=o,o.next=r.previous=i,i.next=o.previous=r;t:for(c=3;c<s;++c){j(r._,o._,i=t[c]),i=new R(i),u=o.next,f=r.previous,d=o._.r,h=r._.r;do{if(d<=h){if(O(u._,i._)){o=u,r.next=o,o.previous=r,--c;continue t}d+=u._.r,u=u.next}else{if(O(f._,i._)){(r=f).next=o,o.previous=r,--c;continue t}h+=f._.r,f=f.previous}}while(u!==f.next);for(i.previous=r,i.next=o,r.next=o.previous=o=i,a=E(r);(i=i.next)!==o;)(l=E(i))<a&&(r=i,a=l);o=r.next}for(r=[o._],i=o;(i=i.next)!==o;)r.push(i._);for(i=k(r,e),c=0;c<s;++c)(r=t[c]).x-=i.x,r.y-=i.y;return i.r}function P(t){return I(t,w()),t}function F(t){return Math.sqrt(t.value)}function L(){var t=null,e=1,n=1,r=g;function o(o){const i=w();return o.x=e/2,o.y=n/2,t?o.eachBefore(D(t)).eachAfter(B(r,.5,i)).eachBefore(z(1)):o.eachBefore(D(F)).eachAfter(B(g,1,i)).eachAfter(B(r,o.r/Math.min(e,n),i)).eachBefore(z(Math.min(e,n)/(2*o.r))),o}return o.radius=function(e){return arguments.length?(t=p(e),o):t},o.size=function(t){return arguments.length?(e=+t[0],n=+t[1],o):[e,n]},o.padding=function(t){return arguments.length?(r="function"==typeof t?t:y(+t),o):r},o}function D(t){return function(e){e.children||(e.r=Math.max(0,+t(e)||0))}}function B(t,e,n){return function(r){if(o=r.children){var o,i,s,a=o.length,l=t(r)*e||0;if(l)for(i=0;i<a;++i)o[i].r+=l;if(s=I(o,n),l)for(i=0;i<a;++i)o[i].r-=l;r.r=s+l}}}function z(t){return function(e){var n=e.parent;e.r*=t,n&&(e.x=n.x+t*e.x,e.y=n.y+t*e.y)}}function Z(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)}function $(t,e,n,r,o){for(var i,s=t.children,a=-1,l=s.length,c=t.value&&(r-e)/t.value;++a<l;)(i=s[a]).y0=n,i.y1=o,i.x0=e,i.x1=e+=i.value*c}function G(){var t=1,e=1,n=0,r=!1;function o(o){var i=o.height+1;return o.x0=o.y0=n,o.x1=t,o.y1=e/i,o.eachBefore(function(t,e){return function(r){r.children&&$(r,r.x0,t*(r.depth+1)/e,r.x1,t*(r.depth+2)/e);var o=r.x0,i=r.y0,s=r.x1-n,a=r.y1-n;s<o&&(o=s=(o+s)/2),a<i&&(i=a=(i+a)/2),r.x0=o,r.y0=i,r.x1=s,r.y1=a}}(e,i)),r&&o.eachBefore(Z),o}return o.round=function(t){return arguments.length?(r=!!t,o):r},o.size=function(n){return arguments.length?(t=+n[0],e=+n[1],o):[t,e]},o.padding=function(t){return arguments.length?(n=+t,o):n},o}var U={depth:-1},J={},W={};function H(t){return t.id}function V(t){return t.parentId}function Y(){var t,e=H,n=V;function r(r){var o,i,s,a,l,c,u,f,p=Array.from(r),m=e,g=n,y=new Map;if(null!=t){const e=p.map(((e,n)=>function(t){t=`${t}`;let e=t.length;K(t,e-1)&&!K(t,e-2)&&(t=t.slice(0,-1));return"/"===t[0]?t:`/${t}`}(t(e,n,r)))),n=e.map(Q),o=new Set(e).add("");for(const t of n)o.has(t)||(o.add(t),e.push(t),n.push(Q(t)),p.push(W));m=(t,n)=>e[n],g=(t,e)=>n[e]}for(s=0,o=p.length;s<o;++s)i=p[s],c=p[s]=new h(i),null!=(u=m(i,s,r))&&(u+="")&&(f=c.id=u,y.set(f,y.has(f)?J:c)),null!=(u=g(i,s,r))&&(u+="")&&(c.parent=u);for(s=0;s<o;++s)if(u=(c=p[s]).parent){if(!(l=y.get(u)))throw new Error("missing: "+u);if(l===J)throw new Error("ambiguous: "+u);l.children?l.children.push(c):l.children=[c],c.parent=l}else{if(a)throw new Error("multiple roots");a=c}if(!a)throw new Error("no root");if(null!=t){for(;a.data===W&&1===a.children.length;)a=a.children[0],--o;for(let t=p.length-1;t>=0&&(c=p[t]).data===W;--t)c.data=null}if(a.parent=U,a.eachBefore((function(t){t.depth=t.parent.depth+1,--o})).eachBefore(d),a.parent=null,o>0)throw new Error("cycle");return a}return r.id=function(t){return arguments.length?(e=p(t),r):e},r.parentId=function(t){return arguments.length?(n=p(t),r):n},r.path=function(e){return arguments.length?(t=p(e),r):t},r}function Q(t){let e=t.length;if(e<2)return"";for(;--e>1&&!K(t,e););return t.slice(0,e)}function K(t,e){if("/"===t[e]){let n=0;for(;e>0&&"\\"===t[--e];)++n;if(0==(1&n))return!0}return!1}function X(t,e){return t.parent===e.parent?1:2}function tt(t){var e=t.children;return e?e[0]:t.t}function et(t){var e=t.children;return e?e[e.length-1]:t.t}function nt(t,e,n){var r=n/(e.i-t.i);e.c-=r,e.s+=n,t.c+=r,e.z+=n,e.m+=n}function rt(t,e,n){return t.a.parent===e.parent?t.a:n}function ot(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function it(){var t=X,e=1,n=1,r=null;function o(o){var l=function(t){for(var e,n,r,o,i,s=new ot(t,0),a=[s];e=a.pop();)if(r=e._.children)for(e.children=new Array(i=r.length),o=i-1;o>=0;--o)a.push(n=e.children[o]=new ot(r[o],o)),n.parent=e;return(s.parent=new ot(null,0)).children=[s],s}(o);if(l.eachAfter(i),l.parent.m=-l.z,l.eachBefore(s),r)o.eachBefore(a);else{var c=o,u=o,f=o;o.eachBefore((function(t){t.x<c.x&&(c=t),t.x>u.x&&(u=t),t.depth>f.depth&&(f=t)}));var d=c===u?1:t(c,u)/2,h=d-c.x,p=e/(u.x+d+h),m=n/(f.depth||1);o.eachBefore((function(t){t.x=(t.x+h)*p,t.y=t.depth*m}))}return o}function i(e){var n=e.children,r=e.parent.children,o=e.i?r[e.i-1]:null;if(n){!function(t){for(var e,n=0,r=0,o=t.children,i=o.length;--i>=0;)(e=o[i]).z+=n,e.m+=n,n+=e.s+(r+=e.c)}(e);var i=(n[0].z+n[n.length-1].z)/2;o?(e.z=o.z+t(e._,o._),e.m=e.z-i):e.z=i}else o&&(e.z=o.z+t(e._,o._));e.parent.A=function(e,n,r){if(n){for(var o,i=e,s=e,a=n,l=i.parent.children[0],c=i.m,u=s.m,f=a.m,d=l.m;a=et(a),i=tt(i),a&&i;)l=tt(l),(s=et(s)).a=e,(o=a.z+f-i.z-c+t(a._,i._))>0&&(nt(rt(a,e,r),e,o),c+=o,u+=o),f+=a.m,c+=i.m,d+=l.m,u+=s.m;a&&!et(s)&&(s.t=a,s.m+=f-u),i&&!tt(l)&&(l.t=i,l.m+=c-d,r=e)}return r}(e,o,e.parent.A||r[0])}function s(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function a(t){t.x*=e,t.y=t.depth*n}return o.separation=function(e){return arguments.length?(t=e,o):t},o.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],o):r?null:[e,n]},o.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],o):r?[e,n]:null},o}function st(t,e,n,r,o){for(var i,s=t.children,a=-1,l=s.length,c=t.value&&(o-n)/t.value;++a<l;)(i=s[a]).x0=e,i.x1=r,i.y0=n,i.y1=n+=i.value*c}ot.prototype=Object.create(h.prototype);var at=(1+Math.sqrt(5))/2;function lt(t,e,n,r,o,i){for(var s,a,l,c,u,f,d,h,p,m,g,y=[],v=e.children,b=0,_=0,w=v.length,x=e.value;b<w;){l=o-n,c=i-r;do{u=v[_++].value}while(!u&&_<w);for(f=d=u,g=u*u*(m=Math.max(c/l,l/c)/(x*t)),p=Math.max(d/g,g/f);_<w;++_){if(u+=a=v[_].value,a<f&&(f=a),a>d&&(d=a),g=u*u*m,(h=Math.max(d/g,g/f))>p){u-=a;break}p=h}y.push(s={value:u,dice:l<c,children:v.slice(b,_)}),s.dice?$(s,n,r,o,x?r+=c*u/x:i):st(s,n,r,x?n+=l*u/x:o,i),x-=u,b=_}return y}const ct=function t(e){function n(t,n,r,o,i){lt(e,t,n,r,o,i)}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(at);function ut(){var t=ct,e=!1,n=1,r=1,o=[0],i=g,s=g,a=g,l=g,c=g;function u(t){return t.x0=t.y0=0,t.x1=n,t.y1=r,t.eachBefore(f),o=[0],e&&t.eachBefore(Z),t}function f(e){var n=o[e.depth],r=e.x0+n,u=e.y0+n,f=e.x1-n,d=e.y1-n;f<r&&(r=f=(r+f)/2),d<u&&(u=d=(u+d)/2),e.x0=r,e.y0=u,e.x1=f,e.y1=d,e.children&&(n=o[e.depth+1]=i(e)/2,r+=c(e)-n,u+=s(e)-n,(f-=a(e)-n)<r&&(r=f=(r+f)/2),(d-=l(e)-n)<u&&(u=d=(u+d)/2),t(e,r,u,f,d))}return u.round=function(t){return arguments.length?(e=!!t,u):e},u.size=function(t){return arguments.length?(n=+t[0],r=+t[1],u):[n,r]},u.tile=function(e){return arguments.length?(t=m(e),u):t},u.padding=function(t){return arguments.length?u.paddingInner(t).paddingOuter(t):u.paddingInner()},u.paddingInner=function(t){return arguments.length?(i="function"==typeof t?t:y(+t),u):i},u.paddingOuter=function(t){return arguments.length?u.paddingTop(t).paddingRight(t).paddingBottom(t).paddingLeft(t):u.paddingTop()},u.paddingTop=function(t){return arguments.length?(s="function"==typeof t?t:y(+t),u):s},u.paddingRight=function(t){return arguments.length?(a="function"==typeof t?t:y(+t),u):a},u.paddingBottom=function(t){return arguments.length?(l="function"==typeof t?t:y(+t),u):l},u.paddingLeft=function(t){return arguments.length?(c="function"==typeof t?t:y(+t),u):c},u}function ft(t,e,n,r,o){var i,s,a=t.children,l=a.length,c=new Array(l+1);for(c[0]=s=i=0;i<l;++i)c[i+1]=s+=a[i].value;!function t(e,n,r,o,i,s,l){if(e>=n-1){var u=a[e];return u.x0=o,u.y0=i,u.x1=s,void(u.y1=l)}var f=c[e],d=r/2+f,h=e+1,p=n-1;for(;h<p;){var m=h+p>>>1;c[m]<d?h=m+1:p=m}d-c[h-1]<c[h]-d&&e+1<h&&--h;var g=c[h]-f,y=r-g;if(s-o>l-i){var v=r?(o*y+s*g)/r:s;t(e,h,g,o,i,v,l),t(h,n,y,v,i,s,l)}else{var b=r?(i*y+l*g)/r:l;t(e,h,g,o,i,s,b),t(h,n,y,o,b,s,l)}}(0,l,t.value,e,n,r,o)}function dt(t,e,n,r,o){(1&t.depth?st:$)(t,e,n,r,o)}const ht=function t(e){function n(t,n,r,o,i){if((s=t._squarify)&&s.ratio===e)for(var s,a,l,c,u,f=-1,d=s.length,h=t.value;++f<d;){for(l=(a=s[f]).children,c=a.value=0,u=l.length;c<u;++c)a.value+=l[c].value;a.dice?$(a,n,r,o,h?r+=(i-r)*a.value/h:i):st(a,n,r,h?n+=(o-n)*a.value/h:o,i),h-=a.value}else t._squarify=s=lt(e,t,n,r,o,i),s.ratio=e}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(at)},4321:(t,e,n)=>{"use strict";n.d(e,{M:()=>s,Z:()=>i});var r=n(2303),o=n(5003);function i(t,e){return((0,o.v)(e)?o.Z:s)(t,e)}function s(t,e){var n,o=e?e.length:0,i=t?Math.min(o,t.length):0,s=new Array(i),a=new Array(o);for(n=0;n<i;++n)s[n]=(0,r.Z)(t[n],e[n]);for(;n<o;++n)a[n]=e[n];return function(t){for(n=0;n<i;++n)a[n]=s[n](t);return a}}},5409:(t,e,n)=>{"use strict";function r(t,e,n,r,o){var i=t*t,s=i*t;return((1-3*t+3*i-s)*e+(4-6*i+3*s)*n+(1+3*t+3*i-3*s)*r+s*o)/6}function o(t){var e=t.length-1;return function(n){var o=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),i=t[o],s=t[o+1],a=o>0?t[o-1]:2*i-s,l=o<e-1?t[o+2]:2*s-i;return r((n-o/e)*e,a,i,s,l)}}n.d(e,{Z:()=>o,t:()=>r})},7855:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(5409);function o(t){var e=t.length;return function(n){var o=Math.floor(((n%=1)<0?++n:n)*e),i=t[(o+e-1)%e],s=t[o%e],a=t[(o+1)%e],l=t[(o+2)%e];return(0,r.t)((n-o/e)*e,i,s,a,l)}}},8190:(t,e,n)=>{"use strict";n.d(e,{ZP:()=>a,wx:()=>i,yi:()=>s});var r=n(8486);function o(t,e){return function(n){return t+n*e}}function i(t,e){var n=e-t;return n?o(t,n>180||n<-180?n-360*Math.round(n/360):n):(0,r.Z)(isNaN(t)?e:t)}function s(t){return 1==(t=+t)?a:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):(0,r.Z)(isNaN(e)?n:e)}}function a(t,e){var n=e-t;return n?o(t,n):(0,r.Z)(isNaN(t)?e:t)}},8486:(t,e,n)=>{"use strict";n.d(e,{Z:()=>r});const r=t=>()=>t},711:(t,e,n)=>{"use strict";n.d(e,{B:()=>a,Z:()=>s});var r=n(3763),o=n(8190);function i(t){return function e(n){function i(e,i){var s=t((e=(0,r.Z)(e)).h,(i=(0,r.Z)(i)).h),a=(0,o.ZP)(e.s,i.s),l=(0,o.ZP)(e.l,i.l),c=(0,o.ZP)(e.opacity,i.opacity);return function(t){return e.h=s(t),e.s=a(t),e.l=l(Math.pow(t,n)),e.opacity=c(t),e+""}}return n=+n,i.gamma=e,i}(1)}const s=i(o.wx);var a=i(o.ZP)},6261:(t,e,n)=>{"use strict";function r(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}n.d(e,{Z:()=>r})},6778:(t,e,n)=>{"use strict";n.r(e),n.d(e,{interpolate:()=>r.Z,interpolateArray:()=>o.Z,interpolateBasis:()=>i.Z,interpolateBasisClosed:()=>s.Z,interpolateCubehelix:()=>M.Z,interpolateCubehelixLong:()=>M.B,interpolateDate:()=>a.Z,interpolateDiscrete:()=>l,interpolateHcl:()=>S,interpolateHclLong:()=>A,interpolateHsl:()=>w,interpolateHslLong:()=>x,interpolateHue:()=>u,interpolateLab:()=>q,interpolateNumber:()=>f.Z,interpolateNumberArray:()=>d.Z,interpolateObject:()=>h.Z,interpolateRgb:()=>v.ZP,interpolateRgbBasis:()=>v.hD,interpolateRgbBasisClosed:()=>v.YD,interpolateRound:()=>p.Z,interpolateString:()=>m.Z,interpolateTransformCss:()=>g.Y,interpolateTransformSvg:()=>g.w,interpolateZoom:()=>y.Z,piecewise:()=>T.Z,quantize:()=>C});var r=n(2303),o=n(4321),i=n(5409),s=n(7855),a=n(6261);function l(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}var c=n(8190);function u(t,e){var n=(0,c.wx)(+t,+e);return function(t){var e=n(t);return e-360*Math.floor(e/360)}}var f=n(8403),d=n(5003),h=n(8765),p=n(5250),m=n(9009),g=n(2650),y=n(6564),v=n(490),b=n(1495);function _(t){return function(e,n){var r=t((e=(0,b.Ym)(e)).h,(n=(0,b.Ym)(n)).h),o=(0,c.ZP)(e.s,n.s),i=(0,c.ZP)(e.l,n.l),s=(0,c.ZP)(e.opacity,n.opacity);return function(t){return e.h=r(t),e.s=o(t),e.l=i(t),e.opacity=s(t),e+""}}}const w=_(c.wx);var x=_(c.ZP),k=n(3334);function q(t,e){var n=(0,c.ZP)((t=(0,k.ZP)(t)).l,(e=(0,k.ZP)(e)).l),r=(0,c.ZP)(t.a,e.a),o=(0,c.ZP)(t.b,e.b),i=(0,c.ZP)(t.opacity,e.opacity);return function(e){return t.l=n(e),t.a=r(e),t.b=o(e),t.opacity=i(e),t+""}}function N(t){return function(e,n){var r=t((e=(0,k.Uc)(e)).h,(n=(0,k.Uc)(n)).h),o=(0,c.ZP)(e.c,n.c),i=(0,c.ZP)(e.l,n.l),s=(0,c.ZP)(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=o(t),e.l=i(t),e.opacity=s(t),e+""}}}const S=N(c.wx);var A=N(c.ZP),M=n(711),T=n(9444);function C(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t(r/(e-1));return n}},8403:(t,e,n)=>{"use strict";function r(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}n.d(e,{Z:()=>r})},5003:(t,e,n)=>{"use strict";function r(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,o=e.slice();return function(i){for(n=0;n<r;++n)o[n]=t[n]*(1-i)+e[n]*i;return o}}function o(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}n.d(e,{Z:()=>r,v:()=>o})},8765:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2303);function o(t,e){var n,o={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?o[n]=(0,r.Z)(t[n],e[n]):i[n]=e[n];return function(t){for(n in o)i[n]=o[n](t);return i}}},9444:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});var r=n(2303);function o(t,e){void 0===e&&(e=t,t=r.Z);for(var n=0,o=e.length-1,i=e[0],s=new Array(o<0?0:o);n<o;)s[n]=t(i,i=e[++n]);return function(t){var e=Math.max(0,Math.min(o-1,Math.floor(t*=o)));return s[e](t-e)}}},490:(t,e,n)=>{"use strict";n.d(e,{YD:()=>u,ZP:()=>a,hD:()=>c});var r=n(1495),o=n(5409),i=n(7855),s=n(8190);const a=function t(e){var n=(0,s.yi)(e);function o(t,e){var o=n((t=(0,r.B8)(t)).r,(e=(0,r.B8)(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),l=(0,s.ZP)(t.opacity,e.opacity);return function(e){return t.r=o(e),t.g=i(e),t.b=a(e),t.opacity=l(e),t+""}}return o.gamma=t,o}(1);function l(t){return function(e){var n,o,i=e.length,s=new Array(i),a=new Array(i),l=new Array(i);for(n=0;n<i;++n)o=(0,r.B8)(e[n]),s[n]=o.r||0,a[n]=o.g||0,l[n]=o.b||0;return s=t(s),a=t(a),l=t(l),o.opacity=1,function(t){return o.r=s(t),o.g=a(t),o.b=l(t),o+""}}}var c=l(o.Z),u=l(i.Z)},5250:(t,e,n)=>{"use strict";function r(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}n.d(e,{Z:()=>r})},9009:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s});var r=n(8403),o=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,i=new RegExp(o.source,"g");function s(t,e){var n,s,a,l=o.lastIndex=i.lastIndex=0,c=-1,u=[],f=[];for(t+="",e+="";(n=o.exec(t))&&(s=i.exec(e));)(a=s.index)>l&&(a=e.slice(l,a),u[c]?u[c]+=a:u[++c]=a),(n=n[0])===(s=s[0])?u[c]?u[c]+=s:u[++c]=s:(u[++c]=null,f.push({i:c,x:(0,r.Z)(n,s)})),l=i.lastIndex;return l<e.length&&(a=e.slice(l),u[c]?u[c]+=a:u[++c]=a),u.length<2?f[0]?function(t){return function(e){return t(e)+""}}(f[0].x):function(t){return function(){return t}}(e):(e=f.length,function(t){for(var n,r=0;r<e;++r)u[(n=f[r]).i]=n.x(t);return u.join("")})}},2650:(t,e,n)=>{"use strict";n.d(e,{Y:()=>c,w:()=>u});var r,o=n(8403),i=180/Math.PI,s={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function a(t,e,n,r,o,s){var a,l,c;return(a=Math.sqrt(t*t+e*e))&&(t/=a,e/=a),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),t*r<e*n&&(t=-t,e=-e,c=-c,a=-a),{translateX:o,translateY:s,rotate:Math.atan2(e,t)*i,skewX:Math.atan(c)*i,scaleX:a,scaleY:l}}function l(t,e,n,r){function i(t){return t.length?t.pop()+" ":""}return function(s,a){var l=[],c=[];return s=t(s),a=t(a),function(t,r,i,s,a,l){if(t!==i||r!==s){var c=a.push("translate(",null,e,null,n);l.push({i:c-4,x:(0,o.Z)(t,i)},{i:c-2,x:(0,o.Z)(r,s)})}else(i||s)&&a.push("translate("+i+e+s+n)}(s.translateX,s.translateY,a.translateX,a.translateY,l,c),function(t,e,n,s){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),s.push({i:n.push(i(n)+"rotate(",null,r)-2,x:(0,o.Z)(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(s.rotate,a.rotate,l,c),function(t,e,n,s){t!==e?s.push({i:n.push(i(n)+"skewX(",null,r)-2,x:(0,o.Z)(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(s.skewX,a.skewX,l,c),function(t,e,n,r,s,a){if(t!==n||e!==r){var l=s.push(i(s)+"scale(",null,",",null,")");a.push({i:l-4,x:(0,o.Z)(t,n)},{i:l-2,x:(0,o.Z)(e,r)})}else 1===n&&1===r||s.push(i(s)+"scale("+n+","+r+")")}(s.scaleX,s.scaleY,a.scaleX,a.scaleY,l,c),s=a=null,function(t){for(var e,n=-1,r=c.length;++n<r;)l[(e=c[n]).i]=e.x(t);return l.join("")}}}var c=l((function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?s:a(e.a,e.b,e.c,e.d,e.e,e.f)}),"px, ","px)","deg)"),u=l((function(t){return null==t?s:(r||(r=document.createElementNS("http://www.w3.org/2000/svg","g")),r.setAttribute("transform",t),(t=r.transform.baseVal.consolidate())?a((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):s)}),", ",")",")")},2303:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(1495),o=n(490),i=n(4321),s=n(6261),a=n(8403),l=n(8765),c=n(9009),u=n(8486),f=n(5003);function d(t,e){var n,d=typeof e;return null==e||"boolean"===d?(0,u.Z)(e):("number"===d?a.Z:"string"===d?(n=(0,r.ZP)(e))?(e=n,o.ZP):c.Z:e instanceof r.ZP?o.ZP:e instanceof Date?s.Z:(0,f.v)(e)?f.Z:Array.isArray(e)?i.M:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?l.Z:a.Z)(t,e)}},6564:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o});function r(t){return((t=Math.exp(t))+1/t)/2}const o=function t(e,n,o){function i(t,i){var s,a,l=t[0],c=t[1],u=t[2],f=i[0],d=i[1],h=i[2],p=f-l,m=d-c,g=p*p+m*m;if(g<1e-12)a=Math.log(h/u)/e,s=function(t){return[l+t*p,c+t*m,u*Math.exp(e*t*a)]};else{var y=Math.sqrt(g),v=(h*h-u*u+o*g)/(2*u*n*y),b=(h*h-u*u-o*g)/(2*h*n*y),_=Math.log(Math.sqrt(v*v+1)-v),w=Math.log(Math.sqrt(b*b+1)-b);a=(w-_)/e,s=function(t){var o,i=t*a,s=r(_),f=u/(n*y)*(s*(o=e*i+_,((o=Math.exp(2*o))-1)/(o+1))-function(t){return((t=Math.exp(t))-1/t)/2}(_));return[l+f*p,c+f*m,u*s/r(e*i+_)]}}return s.duration=1e3*a*e/Math.SQRT2,s}return i.rho=function(e){var n=Math.max(.001,+e),r=n*n;return t(n,r,r*r)},i}(Math.SQRT2,2,4)},895:(t,e,n)=>{"use strict";function r(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}n.r(e),n.d(e,{interpolateBlues:()=>it,interpolateBrBG:()=>y,interpolateBuGn:()=>I,interpolateBuPu:()=>F,interpolateCividis:()=>gt,interpolateCool:()=>wt,interpolateCubehelixDefault:()=>bt,interpolateGnBu:()=>D,interpolateGreens:()=>at,interpolateGreys:()=>ct,interpolateInferno:()=>Ot,interpolateMagma:()=>jt,interpolateOrRd:()=>z,interpolateOranges:()=>mt,interpolatePRGn:()=>b,interpolatePiYG:()=>w,interpolatePlasma:()=>Et,interpolatePuBu:()=>U,interpolatePuBuGn:()=>$,interpolatePuOr:()=>k,interpolatePuRd:()=>W,interpolatePurples:()=>ft,interpolateRainbow:()=>kt,interpolateRdBu:()=>N,interpolateRdGy:()=>A,interpolateRdPu:()=>V,interpolateRdYlBu:()=>T,interpolateRdYlGn:()=>j,interpolateReds:()=>ht,interpolateSinebow:()=>At,interpolateSpectral:()=>E,interpolateTurbo:()=>Mt,interpolateViridis:()=>Ct,interpolateWarm:()=>_t,interpolateYlGn:()=>X,interpolateYlGnBu:()=>Q,interpolateYlOrBr:()=>et,interpolateYlOrRd:()=>rt,schemeAccent:()=>i,schemeBlues:()=>ot,schemeBrBG:()=>g,schemeBuGn:()=>R,schemeBuPu:()=>P,schemeCategory10:()=>o,schemeDark2:()=>s,schemeGnBu:()=>L,schemeGreens:()=>st,schemeGreys:()=>lt,schemeOrRd:()=>B,schemeOranges:()=>pt,schemePRGn:()=>v,schemePaired:()=>a,schemePastel1:()=>l,schemePastel2:()=>c,schemePiYG:()=>_,schemePuBu:()=>G,schemePuBuGn:()=>Z,schemePuOr:()=>x,schemePuRd:()=>J,schemePurples:()=>ut,schemeRdBu:()=>q,schemeRdGy:()=>S,schemeRdPu:()=>H,schemeRdYlBu:()=>M,schemeRdYlGn:()=>C,schemeReds:()=>dt,schemeSet1:()=>u,schemeSet2:()=>f,schemeSet3:()=>d,schemeSpectral:()=>O,schemeTableau10:()=>h,schemeYlGn:()=>K,schemeYlGnBu:()=>Y,schemeYlOrBr:()=>tt,schemeYlOrRd:()=>nt});const o=r("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),i=r("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"),s=r("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"),a=r("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"),l=r("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"),c=r("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"),u=r("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"),f=r("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"),d=r("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"),h=r("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");var p=n(490);const m=t=>(0,p.hD)(t[t.length-1]);var g=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(r);const y=m(g);var v=new Array(3).concat("af8dc3f7f7f77fbf7b","7b3294c2a5cfa6dba0008837","7b3294c2a5cff7f7f7a6dba0008837","762a83af8dc3e7d4e8d9f0d37fbf7b1b7837","762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837","762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837","762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837","40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b","40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b").map(r);const b=m(v);var _=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(r);const w=m(_);var x=new Array(3).concat("998ec3f7f7f7f1a340","5e3c99b2abd2fdb863e66101","5e3c99b2abd2f7f7f7fdb863e66101","542788998ec3d8daebfee0b6f1a340b35806","542788998ec3d8daebf7f7f7fee0b6f1a340b35806","5427888073acb2abd2d8daebfee0b6fdb863e08214b35806","5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806","2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08","2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08").map(r);const k=m(x);var q=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(r);const N=m(q);var S=new Array(3).concat("ef8a62ffffff999999","ca0020f4a582bababa404040","ca0020f4a582ffffffbababa404040","b2182bef8a62fddbc7e0e0e09999994d4d4d","b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d","b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d","b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d","67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a","67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a").map(r);const A=m(S);var M=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(r);const T=m(M);var C=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(r);const j=m(C);var O=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(r);const E=m(O);var R=new Array(3).concat("e5f5f999d8c92ca25f","edf8fbb2e2e266c2a4238b45","edf8fbb2e2e266c2a42ca25f006d2c","edf8fbccece699d8c966c2a42ca25f006d2c","edf8fbccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b").map(r);const I=m(R);var P=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(r);const F=m(P);var L=new Array(3).concat("e0f3dba8ddb543a2ca","f0f9e8bae4bc7bccc42b8cbe","f0f9e8bae4bc7bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081").map(r);const D=m(L);var B=new Array(3).concat("fee8c8fdbb84e34a33","fef0d9fdcc8afc8d59d7301f","fef0d9fdcc8afc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000").map(r);const z=m(B);var Z=new Array(3).concat("ece2f0a6bddb1c9099","f6eff7bdc9e167a9cf02818a","f6eff7bdc9e167a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636").map(r);const $=m(Z);var G=new Array(3).concat("ece7f2a6bddb2b8cbe","f1eef6bdc9e174a9cf0570b0","f1eef6bdc9e174a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858").map(r);const U=m(G);var J=new Array(3).concat("e7e1efc994c7dd1c77","f1eef6d7b5d8df65b0ce1256","f1eef6d7b5d8df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f").map(r);const W=m(J);var H=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(r);const V=m(H);var Y=new Array(3).concat("edf8b17fcdbb2c7fb8","ffffcca1dab441b6c4225ea8","ffffcca1dab441b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58").map(r);const Q=m(Y);var K=new Array(3).concat("f7fcb9addd8e31a354","ffffccc2e69978c679238443","ffffccc2e69978c67931a354006837","ffffccd9f0a3addd8e78c67931a354006837","ffffccd9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529").map(r);const X=m(K);var tt=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(r);const et=m(tt);var nt=new Array(3).concat("ffeda0feb24cf03b20","ffffb2fecc5cfd8d3ce31a1c","ffffb2fecc5cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026").map(r);const rt=m(nt);var ot=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(r);const it=m(ot);var st=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(r);const at=m(st);var lt=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(r);const ct=m(lt);var ut=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(r);const ft=m(ut);var dt=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(r);const ht=m(dt);var pt=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(r);const mt=m(pt);function gt(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-t*(35.34-t*(2381.73-t*(6402.7-t*(7024.72-2710.57*t)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+t*(170.73+t*(52.82-t*(131.46-t*(176.58-67.37*t)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+t*(442.36-t*(2482.43-t*(6167.24-t*(6614.94-2475.67*t)))))))+")"}var yt=n(3763),vt=n(711);const bt=(0,vt.B)((0,yt.Z)(300,.5,0),(0,yt.Z)(-240,.5,1));var _t=(0,vt.B)((0,yt.Z)(-100,.75,.35),(0,yt.Z)(80,1.5,.8)),wt=(0,vt.B)((0,yt.Z)(260,.75,.35),(0,yt.Z)(80,1.5,.8)),xt=(0,yt.Z)();function kt(t){(t<0||t>1)&&(t-=Math.floor(t));var e=Math.abs(t-.5);return xt.h=360*t-100,xt.s=1.5-1.5*e,xt.l=.8-.9*e,xt+""}var qt=(0,n(1495).B8)(),Nt=Math.PI/3,St=2*Math.PI/3;function At(t){var e;return t=(.5-t)*Math.PI,qt.r=255*(e=Math.sin(t))*e,qt.g=255*(e=Math.sin(t+Nt))*e,qt.b=255*(e=Math.sin(t+St))*e,qt+""}function Mt(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+t*(1172.33-t*(10793.56-t*(33300.12-t*(38394.49-14825.05*t)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+t*(557.33+t*(1225.33-t*(3574.96-t*(1073.77+707.56*t)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+t*(3211.1-t*(15327.97-t*(27814-t*(22569.18-6838.66*t)))))))+")"}function Tt(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}const Ct=Tt(r("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var jt=Tt(r("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),Ot=Tt(r("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),Et=Tt(r("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"))},1303:(t,e,n)=>{"use strict";n.d(e,{JG:()=>h,ZP:()=>m,yR:()=>c,l4:()=>p});var r=n(5519),o=n(2303),i=n(8403),s=n(5250);var a=n(9120),l=[0,1];function c(t){return t}function u(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function f(t,e,n){var r=t[0],o=t[1],i=e[0],s=e[1];return o<r?(r=u(o,r),i=n(s,i)):(r=u(r,o),i=n(i,s)),function(t){return i(r(t))}}function d(t,e,n){var o=Math.min(t.length,e.length)-1,i=new Array(o),s=new Array(o),a=-1;for(t[o]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++a<o;)i[a]=u(t[a],t[a+1]),s[a]=n(e[a],e[a+1]);return function(e){var n=(0,r.ZP)(t,e,1,o)-1;return s[n](i[n](e))}}function h(t,e){return e.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function p(){var t,e,n,r,u,h,p=l,m=l,g=o.Z,y=c;function v(){var t,e,n,o=Math.min(p.length,m.length);return y!==c&&(t=p[0],e=p[o-1],t>e&&(n=t,t=e,e=n),y=function(n){return Math.max(t,Math.min(e,n))}),r=o>2?d:f,u=h=null,b}function b(e){return null==e||isNaN(e=+e)?n:(u||(u=r(p.map(t),m,g)))(t(y(e)))}return b.invert=function(n){return y(e((h||(h=r(m,p.map(t),i.Z)))(n)))},b.domain=function(t){return arguments.length?(p=Array.from(t,a.Z),v()):p.slice()},b.range=function(t){return arguments.length?(m=Array.from(t),v()):m.slice()},b.rangeRound=function(t){return m=Array.from(t),g=s.Z,v()},b.clamp=function(t){return arguments.length?(y=!!t||c,v()):y!==c},b.interpolate=function(t){return arguments.length?(g=t,v()):g},b.unknown=function(t){return arguments.length?(n=t,b):n},function(n,r){return t=n,e=r,v()}}function m(){return p()(c,c)}},502:(t,e,n)=>{"use strict";n.r(e),n.d(e,{scaleBand:()=>l,scaleDiverging:()=>kt,scaleDivergingLog:()=>qt,scaleDivergingPow:()=>St,scaleDivergingSqrt:()=>At,scaleDivergingSymlog:()=>Nt,scaleIdentity:()=>h,scaleImplicit:()=>s,scaleLinear:()=>f.Z,scaleLog:()=>S,scaleOrdinal:()=>a,scalePoint:()=>u,scalePow:()=>I,scaleQuantile:()=>Z,scaleQuantize:()=>$,scaleRadial:()=>L,scaleSequential:()=>mt,scaleSequentialLog:()=>gt,scaleSequentialPow:()=>vt,scaleSequentialQuantile:()=>_t,scaleSequentialSqrt:()=>bt,scaleSequentialSymlog:()=>yt,scaleSqrt:()=>P,scaleSymlog:()=>C,scaleThreshold:()=>G,scaleTime:()=>rt,scaleUtc:()=>ut,tickFormat:()=>Mt.Z});var r=n(1265),o=n(2998),i=n(8828);const s=Symbol("implicit");function a(){var t=new i.L,e=[],n=[],r=s;function l(o){let i=t.get(o);if(void 0===i){if(r!==s)return r;t.set(o,i=e.push(o)-1)}return n[i%n.length]}return l.domain=function(n){if(!arguments.length)return e.slice();e=[],t=new i.L;for(const r of n)t.has(r)||t.set(r,e.push(r)-1);return l},l.range=function(t){return arguments.length?(n=Array.from(t),l):n.slice()},l.unknown=function(t){return arguments.length?(r=t,l):r},l.copy=function(){return a(e,n).unknown(r)},o.o.apply(l,arguments),l}function l(){var t,e,n=a().unknown(void 0),i=n.domain,s=n.range,c=0,u=1,f=!1,d=0,h=0,p=.5;function m(){var n=i().length,o=u<c,a=o?u:c,l=o?c:u;t=(l-a)/Math.max(1,n-d+2*h),f&&(t=Math.floor(t)),a+=(l-a-t*(n-d))*p,e=t*(1-d),f&&(a=Math.round(a),e=Math.round(e));var m=(0,r.Z)(n).map((function(e){return a+t*e}));return s(o?m.reverse():m)}return delete n.unknown,n.domain=function(t){return arguments.length?(i(t),m()):i()},n.range=function(t){return arguments.length?([c,u]=t,c=+c,u=+u,m()):[c,u]},n.rangeRound=function(t){return[c,u]=t,c=+c,u=+u,f=!0,m()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(f=!!t,m()):f},n.padding=function(t){return arguments.length?(d=Math.min(1,h=+t),m()):d},n.paddingInner=function(t){return arguments.length?(d=Math.min(1,t),m()):d},n.paddingOuter=function(t){return arguments.length?(h=+t,m()):h},n.align=function(t){return arguments.length?(p=Math.max(0,Math.min(1,t)),m()):p},n.copy=function(){return l(i(),[c,u]).round(f).paddingInner(d).paddingOuter(h).align(p)},o.o.apply(m(),arguments)}function c(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return c(e())},t}function u(){return c(l.apply(null,arguments).paddingInner(1))}var f=n(9064),d=n(9120);function h(t){var e;function n(t){return null==t||isNaN(t=+t)?e:t}return n.invert=n,n.domain=n.range=function(e){return arguments.length?(t=Array.from(e,d.Z),n):t.slice()},n.unknown=function(t){return arguments.length?(e=t,n):e},n.copy=function(){return h(t).unknown(e)},t=arguments.length?Array.from(t,d.Z):[0,1],(0,f.Q)(n)}var p=n(6106),m=n(7259),g=n(2163);function y(t,e){var n,r=0,o=(t=t.slice()).length-1,i=t[r],s=t[o];return s<i&&(n=r,r=o,o=n,n=i,i=s,s=n),t[r]=e.floor(i),t[o]=e.ceil(s),t}var v=n(1303);function b(t){return Math.log(t)}function _(t){return Math.exp(t)}function w(t){return-Math.log(-t)}function x(t){return-Math.exp(-t)}function k(t){return isFinite(t)?+("1e"+t):t<0?0:t}function q(t){return(e,n)=>-t(-e,n)}function N(t){const e=t(b,_),n=e.domain;let r,o,i=10;function s(){return r=function(t){return t===Math.E?Math.log:10===t&&Math.log10||2===t&&Math.log2||(t=Math.log(t),e=>Math.log(e)/t)}(i),o=function(t){return 10===t?k:t===Math.E?Math.exp:e=>Math.pow(t,e)}(i),n()[0]<0?(r=q(r),o=q(o),t(w,x)):t(b,_),e}return e.base=function(t){return arguments.length?(i=+t,s()):i},e.domain=function(t){return arguments.length?(n(t),s()):n()},e.ticks=t=>{const e=n();let s=e[0],a=e[e.length-1];const l=a<s;l&&([s,a]=[a,s]);let c,u,f=r(s),d=r(a);const h=null==t?10:+t;let m=[];if(!(i%1)&&d-f<h){if(f=Math.floor(f),d=Math.ceil(d),s>0){for(;f<=d;++f)for(c=1;c<i;++c)if(u=f<0?c/o(-f):c*o(f),!(u<s)){if(u>a)break;m.push(u)}}else for(;f<=d;++f)for(c=i-1;c>=1;--c)if(u=f>0?c/o(-f):c*o(f),!(u<s)){if(u>a)break;m.push(u)}2*m.length<h&&(m=(0,p.ZP)(s,a,h))}else m=(0,p.ZP)(f,d,Math.min(d-f,h)).map(o);return l?m.reverse():m},e.tickFormat=(t,n)=>{if(null==t&&(t=10),null==n&&(n=10===i?"s":","),"function"!=typeof n&&(i%1||null!=(n=(0,m.Z)(n)).precision||(n.trim=!0),n=(0,g.WU)(n)),t===1/0)return n;const s=Math.max(1,i*t/e.ticks().length);return t=>{let e=t/o(Math.round(r(t)));return e*i<i-.5&&(e*=i),e<=s?n(t):""}},e.nice=()=>n(y(n(),{floor:t=>o(Math.floor(r(t))),ceil:t=>o(Math.ceil(r(t)))})),e}function S(){const t=N((0,v.l4)()).domain([1,10]);return t.copy=()=>(0,v.JG)(t,S()).base(t.base()),o.o.apply(t,arguments),t}function A(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function M(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function T(t){var e=1,n=t(A(e),M(e));return n.constant=function(n){return arguments.length?t(A(e=+n),M(e)):e},(0,f.Q)(n)}function C(){var t=T((0,v.l4)());return t.copy=function(){return(0,v.JG)(t,C()).constant(t.constant())},o.o.apply(t,arguments)}function j(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function O(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function E(t){return t<0?-t*t:t*t}function R(t){var e=t(v.yR,v.yR),n=1;return e.exponent=function(e){return arguments.length?1===(n=+e)?t(v.yR,v.yR):.5===n?t(O,E):t(j(n),j(1/n)):n},(0,f.Q)(e)}function I(){var t=R((0,v.l4)());return t.copy=function(){return(0,v.JG)(t,I()).exponent(t.exponent())},o.o.apply(t,arguments),t}function P(){return I.apply(null,arguments).exponent(.5)}function F(t){return Math.sign(t)*t*t}function L(){var t,e=(0,v.ZP)(),n=[0,1],r=!1;function i(n){var o=function(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}(e(n));return isNaN(o)?t:r?Math.round(o):o}return i.invert=function(t){return e.invert(F(t))},i.domain=function(t){return arguments.length?(e.domain(t),i):e.domain()},i.range=function(t){return arguments.length?(e.range((n=Array.from(t,d.Z)).map(F)),i):n.slice()},i.rangeRound=function(t){return i.range(t).round(!0)},i.round=function(t){return arguments.length?(r=!!t,i):r},i.clamp=function(t){return arguments.length?(e.clamp(t),i):e.clamp()},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return L(e.domain(),n).round(r).clamp(e.clamp()).unknown(t)},o.o.apply(i,arguments),(0,f.Q)(i)}var D=n(1177),B=n(5519),z=n(9263);function Z(){var t,e=[],n=[],r=[];function i(){var t=0,o=Math.max(1,n.length);for(r=new Array(o-1);++t<o;)r[t-1]=(0,D.s7)(e,t/o);return s}function s(e){return null==e||isNaN(e=+e)?t:n[(0,B.ZP)(r,e)]}return s.invertExtent=function(t){var o=n.indexOf(t);return o<0?[NaN,NaN]:[o>0?r[o-1]:e[0],o<r.length?r[o]:e[e.length-1]]},s.domain=function(t){if(!arguments.length)return e.slice();e=[];for(let n of t)null==n||isNaN(n=+n)||e.push(n);return e.sort(z.Z),i()},s.range=function(t){return arguments.length?(n=Array.from(t),i()):n.slice()},s.unknown=function(e){return arguments.length?(t=e,s):t},s.quantiles=function(){return r.slice()},s.copy=function(){return Z().domain(e).range(n).unknown(t)},o.o.apply(s,arguments)}function $(){var t,e=0,n=1,r=1,i=[.5],s=[0,1];function a(e){return null!=e&&e<=e?s[(0,B.ZP)(i,e,0,r)]:t}function l(){var t=-1;for(i=new Array(r);++t<r;)i[t]=((t+1)*n-(t-r)*e)/(r+1);return a}return a.domain=function(t){return arguments.length?([e,n]=t,e=+e,n=+n,l()):[e,n]},a.range=function(t){return arguments.length?(r=(s=Array.from(t)).length-1,l()):s.slice()},a.invertExtent=function(t){var o=s.indexOf(t);return o<0?[NaN,NaN]:o<1?[e,i[0]]:o>=r?[i[r-1],n]:[i[o-1],i[o]]},a.unknown=function(e){return arguments.length?(t=e,a):a},a.thresholds=function(){return i.slice()},a.copy=function(){return $().domain([e,n]).range(s).unknown(t)},o.o.apply((0,f.Q)(a),arguments)}function G(){var t,e=[.5],n=[0,1],r=1;function i(o){return null!=o&&o<=o?n[(0,B.ZP)(e,o,0,r)]:t}return i.domain=function(t){return arguments.length?(e=Array.from(t),r=Math.min(e.length,n.length-1),i):e.slice()},i.range=function(t){return arguments.length?(n=Array.from(t),r=Math.min(e.length,n.length-1),i):n.slice()},i.invertExtent=function(t){var r=n.indexOf(t);return[e[r-1],e[r]]},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return G().domain(e).range(n).unknown(t)},o.o.apply(i,arguments)}var U=n(7150),J=n(2311),W=n(7905),H=n(6018),V=n(8467),Y=n(6596),Q=n(2991),K=n(1343),X=n(1852);function tt(t){return new Date(t)}function et(t){return t instanceof Date?+t:+new Date(+t)}function nt(t,e,n,r,o,i,s,a,l,c){var u=(0,v.ZP)(),f=u.invert,d=u.domain,h=c(".%L"),p=c(":%S"),m=c("%I:%M"),g=c("%I %p"),b=c("%a %d"),_=c("%b %d"),w=c("%B"),x=c("%Y");function k(t){return(l(t)<t?h:a(t)<t?p:s(t)<t?m:i(t)<t?g:r(t)<t?o(t)<t?b:_:n(t)<t?w:x)(t)}return u.invert=function(t){return new Date(f(t))},u.domain=function(t){return arguments.length?d(Array.from(t,et)):d().map(tt)},u.ticks=function(e){var n=d();return t(n[0],n[n.length-1],null==e?10:e)},u.tickFormat=function(t,e){return null==e?k:c(e)},u.nice=function(t){var n=d();return t&&"function"==typeof t.range||(t=e(n[0],n[n.length-1],null==t?10:t)),t?d(y(n,t)):u},u.copy=function(){return(0,v.JG)(u,nt(t,e,n,r,o,i,s,a,l,c))},u}function rt(){return o.o.apply(nt(U.jK,U._g,J.Z,W.Z,H.OM,V.Z,Y.Z,Q.Z,K.Z,X.i$).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}var ot=n(4552),it=n(7351),st=n(1887),at=n(7445),lt=n(8927),ct=n(8593);function ut(){return o.o.apply(nt(U.WG,U.jo,ot.Z,it.Z,st.Ox,at.Z,lt.Z,ct.Z,K.Z,X.g0).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)}var ft=n(2303),dt=n(5250);function ht(){var t,e,n,r,o,i=0,s=1,a=v.yR,l=!1;function c(e){return null==e||isNaN(e=+e)?o:a(0===n?.5:(e=(r(e)-t)*n,l?Math.max(0,Math.min(1,e)):e))}function u(t){return function(e){var n,r;return arguments.length?([n,r]=e,a=t(n,r),c):[a(0),a(1)]}}return c.domain=function(o){return arguments.length?([i,s]=o,t=r(i=+i),e=r(s=+s),n=t===e?0:1/(e-t),c):[i,s]},c.clamp=function(t){return arguments.length?(l=!!t,c):l},c.interpolator=function(t){return arguments.length?(a=t,c):a},c.range=u(ft.Z),c.rangeRound=u(dt.Z),c.unknown=function(t){return arguments.length?(o=t,c):o},function(o){return r=o,t=o(i),e=o(s),n=t===e?0:1/(e-t),c}}function pt(t,e){return e.domain(t.domain()).interpolator(t.interpolator()).clamp(t.clamp()).unknown(t.unknown())}function mt(){var t=(0,f.Q)(ht()(v.yR));return t.copy=function(){return pt(t,mt())},o.O.apply(t,arguments)}function gt(){var t=N(ht()).domain([1,10]);return t.copy=function(){return pt(t,gt()).base(t.base())},o.O.apply(t,arguments)}function yt(){var t=T(ht());return t.copy=function(){return pt(t,yt()).constant(t.constant())},o.O.apply(t,arguments)}function vt(){var t=R(ht());return t.copy=function(){return pt(t,vt()).exponent(t.exponent())},o.O.apply(t,arguments)}function bt(){return vt.apply(null,arguments).exponent(.5)}function _t(){var t=[],e=v.yR;function n(n){if(null!=n&&!isNaN(n=+n))return e(((0,B.ZP)(t,n,1)-1)/(t.length-1))}return n.domain=function(e){if(!arguments.length)return t.slice();t=[];for(let n of e)null==n||isNaN(n=+n)||t.push(n);return t.sort(z.Z),n},n.interpolator=function(t){return arguments.length?(e=t,n):e},n.range=function(){return t.map(((n,r)=>e(r/(t.length-1))))},n.quantiles=function(e){return Array.from({length:e+1},((n,r)=>(0,D.ZP)(t,r/e)))},n.copy=function(){return _t(e).domain(t)},o.O.apply(n,arguments)}var wt=n(9444);function xt(){var t,e,n,r,o,i,s,a=0,l=.5,c=1,u=1,f=v.yR,d=!1;function h(t){return isNaN(t=+t)?s:(t=.5+((t=+i(t))-e)*(u*t<u*e?r:o),f(d?Math.max(0,Math.min(1,t)):t))}function p(t){return function(e){var n,r,o;return arguments.length?([n,r,o]=e,f=(0,wt.Z)(t,[n,r,o]),h):[f(0),f(.5),f(1)]}}return h.domain=function(s){return arguments.length?([a,l,c]=s,t=i(a=+a),e=i(l=+l),n=i(c=+c),r=t===e?0:.5/(e-t),o=e===n?0:.5/(n-e),u=e<t?-1:1,h):[a,l,c]},h.clamp=function(t){return arguments.length?(d=!!t,h):d},h.interpolator=function(t){return arguments.length?(f=t,h):f},h.range=p(ft.Z),h.rangeRound=p(dt.Z),h.unknown=function(t){return arguments.length?(s=t,h):s},function(s){return i=s,t=s(a),e=s(l),n=s(c),r=t===e?0:.5/(e-t),o=e===n?0:.5/(n-e),u=e<t?-1:1,h}}function kt(){var t=(0,f.Q)(xt()(v.yR));return t.copy=function(){return pt(t,kt())},o.O.apply(t,arguments)}function qt(){var t=N(xt()).domain([.1,1,10]);return t.copy=function(){return pt(t,qt()).base(t.base())},o.O.apply(t,arguments)}function Nt(){var t=T(xt());return t.copy=function(){return pt(t,Nt()).constant(t.constant())},o.O.apply(t,arguments)}function St(){var t=R(xt());return t.copy=function(){return pt(t,St()).exponent(t.exponent())},o.O.apply(t,arguments)}function At(){return St.apply(null,arguments).exponent(.5)}var Mt=n(8902)},2998:(t,e,n)=>{"use strict";function r(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function o(t,e){switch(arguments.length){case 0:break;case 1:"function"==typeof t?this.interpolator(t):this.range(t);break;default:this.domain(t),"function"==typeof e?this.interpolator(e):this.range(e)}return this}n.d(e,{O:()=>o,o:()=>r})},9064:(t,e,n)=>{"use strict";n.d(e,{Q:()=>a,Z:()=>l});var r=n(6106),o=n(1303),i=n(2998),s=n(8902);function a(t){var e=t.domain;return t.ticks=function(t){var n=e();return(0,r.ZP)(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return(0,s.Z)(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var o,i,s=e(),a=0,l=s.length-1,c=s[a],u=s[l],f=10;for(u<c&&(i=c,c=u,u=i,i=a,a=l,l=i);f-- >0;){if((i=(0,r.G9)(c,u,n))===o)return s[a]=c,s[l]=u,e(s);if(i>0)c=Math.floor(c/i)*i,u=Math.ceil(u/i)*i;else{if(!(i<0))break;c=Math.ceil(c*i)/i,u=Math.floor(u*i)/i}o=i}return t},t}function l(){var t=(0,o.ZP)();return t.copy=function(){return(0,o.JG)(t,l())},i.o.apply(t,arguments),a(t)}},9120:(t,e,n)=>{"use strict";function r(t){return+t}n.d(e,{Z:()=>r})},8902:(t,e,n)=>{"use strict";n.d(e,{Z:()=>c});var r=n(6106),o=n(7259),i=n(3150),s=n(2163),a=n(3621),l=n(9680);function c(t,e,n,c){var u,f=(0,r.ly)(t,e,n);switch((c=(0,o.Z)(null==c?",f":c)).type){case"s":var d=Math.max(Math.abs(t),Math.abs(e));return null!=c.precision||isNaN(u=(0,i.Z)(f,d))||(c.precision=u),(0,s.jH)(c,d);case"":case"e":case"g":case"p":case"r":null!=c.precision||isNaN(u=(0,a.Z)(f,Math.max(Math.abs(t),Math.abs(e))))||(c.precision=u-("e"===c.type));break;case"f":case"%":null!=c.precision||isNaN(u=(0,l.Z)(f))||(c.precision=u-2*("%"===c.type))}return(0,s.WU)(c)}},1852:(t,e,n)=>{"use strict";n.d(e,{Z1:()=>i,ZP:()=>c,g0:()=>s,i$:()=>o,wp:()=>a});var r,o,i,s,a,l=n(3015);function c(t){return r=(0,l.Z)(t),o=r.format,i=r.parse,s=r.utcFormat,a=r.utcParse,r}c({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]})},3015:(t,e,n)=>{"use strict";n.d(e,{Z:()=>d});var r=n(1887),o=n(7445),i=n(6018),s=n(8467),a=n(2311),l=n(4552);function c(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function u(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function f(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}function d(t){var e=t.dateTime,n=t.date,a=t.time,l=t.periods,d=t.days,p=t.shortDays,m=t.months,g=t.shortMonths,y=b(l),v=_(l),K=b(d),vt=_(d),Ct=b(p),jt=_(p),Ot=b(m),Et=_(m),Rt=b(g),It=_(g),Pt={a:function(t){return p[t.getDay()]},A:function(t){return d[t.getDay()]},b:function(t){return g[t.getMonth()]},B:function(t){return m[t.getMonth()]},c:null,d:z,e:z,f:J,g:rt,G:it,H:Z,I:$,j:G,L:U,m:W,M:H,p:function(t){return l[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Mt,s:Tt,S:V,u:Y,U:Q,V:X,w:tt,W:et,x:null,X:null,y:nt,Y:ot,Z:st,"%":At},Ft={a:function(t){return p[t.getUTCDay()]},A:function(t){return d[t.getUTCDay()]},b:function(t){return g[t.getUTCMonth()]},B:function(t){return m[t.getUTCMonth()]},c:null,d:at,e:at,f:dt,g:kt,G:Nt,H:lt,I:ct,j:ut,L:ft,m:ht,M:pt,p:function(t){return l[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Mt,s:Tt,S:mt,u:gt,U:yt,V:bt,w:_t,W:wt,x:null,X:null,y:xt,Y:qt,Z:St,"%":At},Lt={a:function(t,e,n){var r=Ct.exec(e.slice(n));return r?(t.w=jt.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=K.exec(e.slice(n));return r?(t.w=vt.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=Rt.exec(e.slice(n));return r?(t.m=It.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=Ot.exec(e.slice(n));return r?(t.m=Et.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return zt(t,e,n,r)},d:j,e:j,f:F,g:A,G:S,H:E,I:E,j:O,L:P,m:C,M:R,p:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.p=v.get(r[0].toLowerCase()),n+r[0].length):-1},q:T,Q:D,s:B,S:I,u:x,U:k,V:q,w,W:N,x:function(t,e,r){return zt(t,n,e,r)},X:function(t,e,n){return zt(t,a,e,n)},y:A,Y:S,Z:M,"%":L};function Dt(t,e){return function(n){var r,o,i,s=[],a=-1,l=0,c=t.length;for(n instanceof Date||(n=new Date(+n));++a<c;)37===t.charCodeAt(a)&&(s.push(t.slice(l,a)),null!=(o=h[r=t.charAt(++a)])?r=t.charAt(++a):o="e"===r?" ":"0",(i=e[r])&&(r=i(n,o)),s.push(r),l=a+1);return s.push(t.slice(l,a)),s.join("")}}function Bt(t,e){return function(n){var a,l,d=f(1900,void 0,1);if(zt(d,t,n+="",0)!=n.length)return null;if("Q"in d)return new Date(d.Q);if("s"in d)return new Date(1e3*d.s+("L"in d?d.L:0));if(e&&!("Z"in d)&&(d.Z=0),"p"in d&&(d.H=d.H%12+12*d.p),void 0===d.m&&(d.m="q"in d?d.q:0),"V"in d){if(d.V<1||d.V>53)return null;"w"in d||(d.w=1),"Z"in d?(l=(a=u(f(d.y,0,1))).getUTCDay(),a=l>4||0===l?r.l6.ceil(a):(0,r.l6)(a),a=o.Z.offset(a,7*(d.V-1)),d.y=a.getUTCFullYear(),d.m=a.getUTCMonth(),d.d=a.getUTCDate()+(d.w+6)%7):(l=(a=c(f(d.y,0,1))).getDay(),a=l>4||0===l?i.wA.ceil(a):(0,i.wA)(a),a=s.Z.offset(a,7*(d.V-1)),d.y=a.getFullYear(),d.m=a.getMonth(),d.d=a.getDate()+(d.w+6)%7)}else("W"in d||"U"in d)&&("w"in d||(d.w="u"in d?d.u%7:"W"in d?1:0),l="Z"in d?u(f(d.y,0,1)).getUTCDay():c(f(d.y,0,1)).getDay(),d.m=0,d.d="W"in d?(d.w+6)%7+7*d.W-(l+5)%7:d.w+7*d.U-(l+6)%7);return"Z"in d?(d.H+=d.Z/100|0,d.M+=d.Z%100,u(d)):c(d)}}function zt(t,e,n,r){for(var o,i,s=0,a=e.length,l=n.length;s<a;){if(r>=l)return-1;if(37===(o=e.charCodeAt(s++))){if(o=e.charAt(s++),!(i=Lt[o in h?e.charAt(s++):o])||(r=i(t,n,r))<0)return-1}else if(o!=n.charCodeAt(r++))return-1}return r}return Pt.x=Dt(n,Pt),Pt.X=Dt(a,Pt),Pt.c=Dt(e,Pt),Ft.x=Dt(n,Ft),Ft.X=Dt(a,Ft),Ft.c=Dt(e,Ft),{format:function(t){var e=Dt(t+="",Pt);return e.toString=function(){return t},e},parse:function(t){var e=Bt(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=Dt(t+="",Ft);return e.toString=function(){return t},e},utcParse:function(t){var e=Bt(t+="",!0);return e.toString=function(){return t},e}}}var h={"-":"",_:" ",0:"0"},p=/^\s*\d+/,m=/^%/,g=/[\\^$*+?|[\]().{}]/g;function y(t,e,n){var r=t<0?"-":"",o=(r?-t:t)+"",i=o.length;return r+(i<n?new Array(n-i+1).join(e)+o:o)}function v(t){return t.replace(g,"\\$&")}function b(t){return new RegExp("^(?:"+t.map(v).join("|")+")","i")}function _(t){return new Map(t.map(((t,e)=>[t.toLowerCase(),e])))}function w(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function x(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function k(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function q(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function N(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function S(t,e,n){var r=p.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function A(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function M(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function T(t,e,n){var r=p.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function C(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function j(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function O(t,e,n){var r=p.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function E(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function R(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function I(t,e,n){var r=p.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function P(t,e,n){var r=p.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function F(t,e,n){var r=p.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function L(t,e,n){var r=m.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function D(t,e,n){var r=p.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function B(t,e,n){var r=p.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function z(t,e){return y(t.getDate(),e,2)}function Z(t,e){return y(t.getHours(),e,2)}function $(t,e){return y(t.getHours()%12||12,e,2)}function G(t,e){return y(1+s.Z.count((0,a.Z)(t),t),e,3)}function U(t,e){return y(t.getMilliseconds(),e,3)}function J(t,e){return U(t,e)+"000"}function W(t,e){return y(t.getMonth()+1,e,2)}function H(t,e){return y(t.getMinutes(),e,2)}function V(t,e){return y(t.getSeconds(),e,2)}function Y(t){var e=t.getDay();return 0===e?7:e}function Q(t,e){return y(i.OM.count((0,a.Z)(t)-1,t),e,2)}function K(t){var e=t.getDay();return e>=4||0===e?(0,i.bL)(t):i.bL.ceil(t)}function X(t,e){return t=K(t),y(i.bL.count((0,a.Z)(t),t)+(4===(0,a.Z)(t).getDay()),e,2)}function tt(t){return t.getDay()}function et(t,e){return y(i.wA.count((0,a.Z)(t)-1,t),e,2)}function nt(t,e){return y(t.getFullYear()%100,e,2)}function rt(t,e){return y((t=K(t)).getFullYear()%100,e,2)}function ot(t,e){return y(t.getFullYear()%1e4,e,4)}function it(t,e){var n=t.getDay();return y((t=n>=4||0===n?(0,i.bL)(t):i.bL.ceil(t)).getFullYear()%1e4,e,4)}function st(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+y(e/60|0,"0",2)+y(e%60,"0",2)}function at(t,e){return y(t.getUTCDate(),e,2)}function lt(t,e){return y(t.getUTCHours(),e,2)}function ct(t,e){return y(t.getUTCHours()%12||12,e,2)}function ut(t,e){return y(1+o.Z.count((0,l.Z)(t),t),e,3)}function ft(t,e){return y(t.getUTCMilliseconds(),e,3)}function dt(t,e){return ft(t,e)+"000"}function ht(t,e){return y(t.getUTCMonth()+1,e,2)}function pt(t,e){return y(t.getUTCMinutes(),e,2)}function mt(t,e){return y(t.getUTCSeconds(),e,2)}function gt(t){var e=t.getUTCDay();return 0===e?7:e}function yt(t,e){return y(r.Ox.count((0,l.Z)(t)-1,t),e,2)}function vt(t){var e=t.getUTCDay();return e>=4||0===e?(0,r.hB)(t):r.hB.ceil(t)}function bt(t,e){return t=vt(t),y(r.hB.count((0,l.Z)(t),t)+(4===(0,l.Z)(t).getUTCDay()),e,2)}function _t(t){return t.getUTCDay()}function wt(t,e){return y(r.l6.count((0,l.Z)(t)-1,t),e,2)}function xt(t,e){return y(t.getUTCFullYear()%100,e,2)}function kt(t,e){return y((t=vt(t)).getUTCFullYear()%100,e,2)}function qt(t,e){return y(t.getUTCFullYear()%1e4,e,4)}function Nt(t,e){var n=t.getUTCDay();return y((t=n>=4||0===n?(0,r.hB)(t):r.hB.ceil(t)).getUTCFullYear()%1e4,e,4)}function St(){return"+0000"}function At(){return"%"}function Mt(t){return+t}function Tt(t){return Math.floor(+t/1e3)}},8467:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,a:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((t=>t.setHours(0,0,0,0)),((t,e)=>t.setDate(t.getDate()+e)),((t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*o.yB)/o.UD),(t=>t.getDate()-1));const s=i;var a=i.range},9123:(t,e,n)=>{"use strict";n.d(e,{UD:()=>s,Y2:()=>i,Ym:()=>r,iM:()=>a,jz:()=>l,qz:()=>c,yB:()=>o});const r=1e3,o=60*r,i=60*o,s=24*i,a=7*s,l=30*s,c=365*s},6596:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,i:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*o.Ym-t.getMinutes()*o.yB)}),(function(t,e){t.setTime(+t+e*o.Y2)}),(function(t,e){return(e-t)/o.Y2}),(function(t){return t.getHours()}));const s=i;var a=i.range},3606:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i});var r=new Date,o=new Date;function i(t,e,n,s){function a(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return a.floor=function(e){return t(e=new Date(+e)),e},a.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},a.round=function(t){var e=a(t),n=a.ceil(t);return t-e<n-t?e:n},a.offset=function(t,n){return e(t=new Date(+t),null==n?1:Math.floor(n)),t},a.range=function(n,r,o){var i,s=[];if(n=a.ceil(n),o=null==o?1:Math.floor(o),!(n<r&&o>0))return s;do{s.push(i=new Date(+n)),e(n,o),t(n)}while(i<n&&n<r);return s},a.filter=function(n){return i((function(e){if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(a.count=function(e,i){return r.setTime(+e),o.setTime(+i),t(r),t(o),Math.floor(n(r,o))},a.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?a.filter(s?function(e){return s(e)%t==0}:function(e){return a.count(0,e)%t==0}):a:null}),a}},8383:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i,m:()=>s});var r=n(3606),o=(0,r.Z)((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));o.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?(0,r.Z)((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,n){e.setTime(+e+n*t)}),(function(e,n){return(n-e)/t})):o:null};const i=o;var s=o.range},2991:(t,e,n)=>{"use strict";n.d(e,{L:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*o.Ym)}),(function(t,e){t.setTime(+t+e*o.yB)}),(function(t,e){return(e-t)/o.yB}),(function(t){return t.getMinutes()}));const s=i;var a=i.range},7905:(t,e,n)=>{"use strict";n.d(e,{Z:()=>o,e:()=>i});var r=(0,n(3606).Z)((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()}));const o=r;var i=r.range},1343:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,m:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+e*o.Ym)}),(function(t,e){return(e-t)/o.Ym}),(function(t){return t.getUTCSeconds()}));const s=i;var a=i.range},7150:(t,e,n)=>{"use strict";n.d(e,{WG:()=>w,_g:()=>q,jK:()=>k,jo:()=>x});var r=n(3292),o=n(6106),i=n(9123),s=n(8383),a=n(1343),l=n(2991),c=n(6596),u=n(8467),f=n(6018),d=n(7905),h=n(2311),p=n(8593),m=n(8927),g=n(7445),y=n(1887),v=n(7351),b=n(4552);function _(t,e,n,l,c,u){const f=[[a.Z,1,i.Ym],[a.Z,5,5*i.Ym],[a.Z,15,15*i.Ym],[a.Z,30,30*i.Ym],[u,1,i.yB],[u,5,5*i.yB],[u,15,15*i.yB],[u,30,30*i.yB],[c,1,i.Y2],[c,3,3*i.Y2],[c,6,6*i.Y2],[c,12,12*i.Y2],[l,1,i.UD],[l,2,2*i.UD],[n,1,i.iM],[e,1,i.jz],[e,3,3*i.jz],[t,1,i.qz]];function d(e,n,a){const l=Math.abs(n-e)/a,c=(0,r.Z)((([,,t])=>t)).right(f,l);if(c===f.length)return t.every((0,o.ly)(e/i.qz,n/i.qz,a));if(0===c)return s.Z.every(Math.max((0,o.ly)(e,n,a),1));const[u,d]=f[l/f[c-1][2]<f[c][2]/l?c-1:c];return u.every(d)}return[function(t,e,n){const r=e<t;r&&([t,e]=[e,t]);const o=n&&"function"==typeof n.range?n:d(t,e,n),i=o?o.range(t,+e+1):[];return r?i.reverse():i},d]}const[w,x]=_(b.Z,v.Z,y.Ox,g.Z,m.Z,p.Z),[k,q]=_(h.Z,d.Z,f.OM,u.Z,c.Z,l.Z)},7445:(t,e,n)=>{"use strict";n.d(e,{Z:()=>s,y:()=>a});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/o.UD}),(function(t){return t.getUTCDate()-1}));const s=i;var a=i.range},8927:(t,e,n)=>{"use strict";n.d(e,{X:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCMinutes(0,0,0)}),(function(t,e){t.setTime(+t+e*o.Y2)}),(function(t,e){return(e-t)/o.Y2}),(function(t){return t.getUTCHours()}));const s=i;var a=i.range},8593:(t,e,n)=>{"use strict";n.d(e,{N:()=>a,Z:()=>s});var r=n(3606),o=n(9123),i=(0,r.Z)((function(t){t.setUTCSeconds(0,0)}),(function(t,e){t.setTime(+t+e*o.yB)}),(function(t,e){return(e-t)/o.yB}),(function(t){return t.getUTCMinutes()}));const s=i;var a=i.range},7351:(t,e,n)=>{"use strict";n.d(e,{K:()=>i,Z:()=>o});var r=(0,n(3606).Z)((function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCMonth(t.getUTCMonth()+e)}),(function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())}),(function(t){return t.getUTCMonth()}));const o=r;var i=r.range},1887:(t,e,n)=>{"use strict";n.d(e,{$3:()=>p,DK:()=>m,J1:()=>l,Ox:()=>s,QQ:()=>f,Q_:()=>b,SU:()=>h,b3:()=>c,fz:()=>v,g4:()=>d,hB:()=>u,l6:()=>a,uy:()=>g,xj:()=>y});var r=n(3606),o=n(9123);function i(t){return(0,r.Z)((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/o.iM}))}var s=i(0),a=i(1),l=i(2),c=i(3),u=i(4),f=i(5),d=i(6),h=s.range,p=a.range,m=l.range,g=c.range,y=u.range,v=f.range,b=d.range},4552:(t,e,n)=>{"use strict";n.d(e,{D:()=>s,Z:()=>i});var r=n(3606),o=(0,r.Z)((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));o.every=function(t){return isFinite(t=Math.floor(t))&&t>0?(0,r.Z)((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const i=o;var s=o.range},6018:(t,e,n)=>{"use strict";n.d(e,{$t:()=>y,EY:()=>d,Ff:()=>b,Ld:()=>g,OM:()=>s,aU:()=>m,b$:()=>v,bJ:()=>p,bL:()=>u,mC:()=>f,sy:()=>l,vm:()=>h,wA:()=>a,zg:()=>c});var r=n(3606),o=n(9123);function i(t){return(0,r.Z)((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*o.yB)/o.iM}))}var s=i(0),a=i(1),l=i(2),c=i(3),u=i(4),f=i(5),d=i(6),h=s.range,p=a.range,m=l.range,g=c.range,y=u.range,v=f.range,b=d.range},2311:(t,e,n)=>{"use strict";n.d(e,{Z:()=>i,g:()=>s});var r=n(3606),o=(0,r.Z)((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));o.every=function(t){return isFinite(t=Math.floor(t))&&t>0?(0,r.Z)((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const i=o;var s=o.range},2554:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Adder:()=>r.Adder,Delaunay:()=>go,FormatSpecifier:()=>ss.FormatSpecifier,InternMap:()=>r.InternMap,InternSet:()=>r.InternSet,Node:()=>af.NB,Voronoi:()=>co,ZoomTransform:()=>Jp,active:()=>un,arc:()=>dd,area:()=>_d,areaRadial:()=>Td,ascending:()=>r.ascending,autoType:()=>qo.autoType,axisBottom:()=>v,axisLeft:()=>b,axisRight:()=>y,axisTop:()=>g,bin:()=>r.bin,bisect:()=>r.bisect,bisectCenter:()=>r.bisectCenter,bisectLeft:()=>r.bisectLeft,bisectRight:()=>r.bisectRight,bisector:()=>r.bisector,blob:()=>di,blur:()=>r.blur,blur2:()=>r.blur2,blurImage:()=>r.blurImage,brush:()=>Dn,brushSelection:()=>Pn,brushX:()=>Fn,brushY:()=>Ln,buffer:()=>pi,chord:()=>Yn,chordDirected:()=>Kn,chordTranspose:()=>Qn,cluster:()=>af.ki,color:()=>br.color,contourDensity:()=>Fr,contours:()=>jr,count:()=>r.count,create:()=>zf,creator:()=>Nt,cross:()=>r.cross,csv:()=>xi,csvFormat:()=>qo.csvFormat,csvFormatBody:()=>qo.csvFormatBody,csvFormatRow:()=>qo.csvFormatRow,csvFormatRows:()=>qo.csvFormatRows,csvFormatValue:()=>qo.csvFormatValue,csvParse:()=>qo.csvParse,csvParseRows:()=>qo.csvParseRows,cubehelix:()=>br.cubehelix,cumsum:()=>r.cumsum,curveBasis:()=>bh,curveBasisClosed:()=>wh,curveBasisOpen:()=>kh,curveBumpX:()=>Ed,curveBumpY:()=>Rd,curveBundle:()=>Nh,curveCardinal:()=>Mh,curveCardinalClosed:()=>Ch,curveCardinalOpen:()=>Oh,curveCatmullRom:()=>Ih,curveCatmullRomClosed:()=>Fh,curveCatmullRomOpen:()=>Dh,curveLinear:()=>gd,curveLinearClosed:()=>zh,curveMonotoneX:()=>Vh,curveMonotoneY:()=>Yh,curveNatural:()=>Xh,curveStep:()=>ep,curveStepAfter:()=>rp,curveStepBefore:()=>np,descending:()=>r.descending,deviation:()=>r.deviation,difference:()=>r.difference,disjoint:()=>r.disjoint,dispatch:()=>N,drag:()=>ko,dragDisable:()=>Gt,dragEnable:()=>Ut,dsv:()=>wi,dsvFormat:()=>qo.dsvFormat,easeBack:()=>si,easeBackIn:()=>oi,easeBackInOut:()=>si,easeBackOut:()=>ii,easeBounce:()=>ei,easeBounceIn:()=>ti,easeBounceInOut:()=>ni,easeBounceOut:()=>ei,easeCircle:()=>$o,easeCircleIn:()=>zo,easeCircleInOut:()=>$o,easeCircleOut:()=>Zo,easeCubic:()=>sn,easeCubicIn:()=>rn,easeCubicInOut:()=>sn,easeCubicOut:()=>on,easeElastic:()=>ci,easeElasticIn:()=>li,easeElasticInOut:()=>ui,easeElasticOut:()=>ci,easeExp:()=>Bo,easeExpIn:()=>Lo,easeExpInOut:()=>Bo,easeExpOut:()=>Do,easeLinear:()=>No,easePoly:()=>jo,easePolyIn:()=>To,easePolyInOut:()=>jo,easePolyOut:()=>Co,easeQuad:()=>Mo,easeQuadIn:()=>So,easeQuadInOut:()=>Mo,easeQuadOut:()=>Ao,easeSin:()=>Po,easeSinIn:()=>Ro,easeSinInOut:()=>Po,easeSinOut:()=>Io,every:()=>r.every,extent:()=>r.extent,fcumsum:()=>r.fcumsum,filter:()=>r.filter,flatGroup:()=>r.flatGroup,flatRollup:()=>r.flatRollup,forceCenter:()=>ji,forceCollide:()=>Gi,forceLink:()=>Wi,forceManyBody:()=>ns,forceRadial:()=>rs,forceSimulation:()=>es,forceX:()=>os,forceY:()=>is,format:()=>ss.format,formatDefaultLocale:()=>ss.formatDefaultLocale,formatLocale:()=>ss.formatLocale,formatPrefix:()=>ss.formatPrefix,formatSpecifier:()=>ss.formatSpecifier,fsum:()=>r.fsum,geoAlbers:()=>qu,geoAlbersUsa:()=>Nu,geoArea:()=>la,geoAzimuthalEqualArea:()=>Tu,geoAzimuthalEqualAreaRaw:()=>Mu,geoAzimuthalEquidistant:()=>ju,geoAzimuthalEquidistantRaw:()=>Cu,geoBounds:()=>$a,geoCentroid:()=>el,geoCircle:()=>dl,geoClipAntimeridian:()=>ql,geoClipCircle:()=>Nl,geoClipExtent:()=>El,geoClipRectangle:()=>Ol,geoConicConformal:()=>Fu,geoConicConformalRaw:()=>Pu,geoConicEqualArea:()=>ku,geoConicEqualAreaRaw:()=>xu,geoConicEquidistant:()=>zu,geoConicEquidistantRaw:()=>Bu,geoContains:()=>Yl,geoDistance:()=>zl,geoEqualEarth:()=>Hu,geoEqualEarthRaw:()=>Wu,geoEquirectangular:()=>Du,geoEquirectangularRaw:()=>Lu,geoGnomonic:()=>Yu,geoGnomonicRaw:()=>Vu,geoGraticule:()=>tc,geoGraticule10:()=>ec,geoIdentity:()=>Qu,geoInterpolate:()=>nc,geoLength:()=>Ll,geoMercator:()=>Eu,geoMercatorRaw:()=>Ou,geoNaturalEarth1:()=>Xu,geoNaturalEarth1Raw:()=>Ku,geoOrthographic:()=>ef,geoOrthographicRaw:()=>tf,geoPath:()=>iu,geoProjection:()=>bu,geoProjectionMutator:()=>_u,geoRotation:()=>cl,geoStereographic:()=>rf,geoStereographicRaw:()=>nf,geoStream:()=>Ls,geoTransform:()=>su,geoTransverseMercator:()=>sf,geoTransverseMercatorRaw:()=>of,gray:()=>br.gray,greatest:()=>r.greatest,greatestIndex:()=>r.greatestIndex,group:()=>r.group,groupSort:()=>r.groupSort,groups:()=>r.groups,hcl:()=>br.hcl,hierarchy:()=>af.bT,histogram:()=>r.histogram,hsl:()=>br.hsl,html:()=>Ti,image:()=>qi,index:()=>r.index,indexes:()=>r.indexes,interpolate:()=>lf.interpolate,interpolateArray:()=>lf.interpolateArray,interpolateBasis:()=>lf.interpolateBasis,interpolateBasisClosed:()=>lf.interpolateBasisClosed,interpolateBlues:()=>Bf.interpolateBlues,interpolateBrBG:()=>Bf.interpolateBrBG,interpolateBuGn:()=>Bf.interpolateBuGn,interpolateBuPu:()=>Bf.interpolateBuPu,interpolateCividis:()=>Bf.interpolateCividis,interpolateCool:()=>Bf.interpolateCool,interpolateCubehelix:()=>lf.interpolateCubehelix,interpolateCubehelixDefault:()=>Bf.interpolateCubehelixDefault,interpolateCubehelixLong:()=>lf.interpolateCubehelixLong,interpolateDate:()=>lf.interpolateDate,interpolateDiscrete:()=>lf.interpolateDiscrete,interpolateGnBu:()=>Bf.interpolateGnBu,interpolateGreens:()=>Bf.interpolateGreens,interpolateGreys:()=>Bf.interpolateGreys,interpolateHcl:()=>lf.interpolateHcl,interpolateHclLong:()=>lf.interpolateHclLong,interpolateHsl:()=>lf.interpolateHsl,interpolateHslLong:()=>lf.interpolateHslLong,interpolateHue:()=>lf.interpolateHue,interpolateInferno:()=>Bf.interpolateInferno,interpolateLab:()=>lf.interpolateLab,interpolateMagma:()=>Bf.interpolateMagma,interpolateNumber:()=>lf.interpolateNumber,interpolateNumberArray:()=>lf.interpolateNumberArray,interpolateObject:()=>lf.interpolateObject,interpolateOrRd:()=>Bf.interpolateOrRd,interpolateOranges:()=>Bf.interpolateOranges,interpolatePRGn:()=>Bf.interpolatePRGn,interpolatePiYG:()=>Bf.interpolatePiYG,interpolatePlasma:()=>Bf.interpolatePlasma,interpolatePuBu:()=>Bf.interpolatePuBu,interpolatePuBuGn:()=>Bf.interpolatePuBuGn,interpolatePuOr:()=>Bf.interpolatePuOr,interpolatePuRd:()=>Bf.interpolatePuRd,interpolatePurples:()=>Bf.interpolatePurples,interpolateRainbow:()=>Bf.interpolateRainbow,interpolateRdBu:()=>Bf.interpolateRdBu,interpolateRdGy:()=>Bf.interpolateRdGy,interpolateRdPu:()=>Bf.interpolateRdPu,interpolateRdYlBu:()=>Bf.interpolateRdYlBu,interpolateRdYlGn:()=>Bf.interpolateRdYlGn,interpolateReds:()=>Bf.interpolateReds,interpolateRgb:()=>lf.interpolateRgb,interpolateRgbBasis:()=>lf.interpolateRgbBasis,interpolateRgbBasisClosed:()=>lf.interpolateRgbBasisClosed,interpolateRound:()=>lf.interpolateRound,interpolateSinebow:()=>Bf.interpolateSinebow,interpolateSpectral:()=>Bf.interpolateSpectral,interpolateString:()=>lf.interpolateString,interpolateTransformCss:()=>lf.interpolateTransformCss,interpolateTransformSvg:()=>lf.interpolateTransformSvg,interpolateTurbo:()=>Bf.interpolateTurbo,interpolateViridis:()=>Bf.interpolateViridis,interpolateWarm:()=>Bf.interpolateWarm,interpolateYlGn:()=>Bf.interpolateYlGn,interpolateYlGnBu:()=>Bf.interpolateYlGnBu,interpolateYlOrBr:()=>Bf.interpolateYlOrBr,interpolateYlOrRd:()=>Bf.interpolateYlOrRd,interpolateZoom:()=>lf.interpolateZoom,interrupt:()=>Me,intersection:()=>r.intersection,interval:()=>Zp,isoFormat:()=>Dp,isoParse:()=>zp,json:()=>Si,lab:()=>br.lab,lch:()=>br.lch,least:()=>r.least,leastIndex:()=>r.leastIndex,line:()=>bd,lineRadial:()=>Md,link:()=>Ld,linkHorizontal:()=>Dd,linkRadial:()=>zd,linkVertical:()=>Bd,local:()=>$f,map:()=>r.map,matcher:()=>j,max:()=>r.max,maxIndex:()=>r.maxIndex,mean:()=>r.mean,median:()=>r.median,medianIndex:()=>r.medianIndex,merge:()=>r.merge,min:()=>r.min,minIndex:()=>r.minIndex,mode:()=>r.mode,namespace:()=>J,namespaces:()=>U,nice:()=>r.nice,now:()=>se,pack:()=>af.P2,packEnclose:()=>af.O1,packSiblings:()=>af.jA,pairs:()=>r.pairs,partition:()=>af.uK,path:()=>sr,permute:()=>r.permute,pie:()=>kd,piecewise:()=>lf.piecewise,pointRadial:()=>Cd,pointer:()=>Ht,pointers:()=>Uf,polygonArea:()=>cf,polygonCentroid:()=>uf,polygonContains:()=>mf,polygonHull:()=>pf,polygonLength:()=>gf,precisionFixed:()=>ss.precisionFixed,precisionPrefix:()=>ss.precisionPrefix,precisionRound:()=>ss.precisionRound,quadtree:()=>Pi,quantile:()=>r.quantile,quantileIndex:()=>r.quantileIndex,quantileSorted:()=>r.quantileSorted,quantize:()=>lf.quantize,quickselect:()=>r.quickselect,radialArea:()=>Td,radialLine:()=>Md,randomBates:()=>kf,randomBernoulli:()=>Sf,randomBeta:()=>Tf,randomBinomial:()=>Cf,randomCauchy:()=>Of,randomExponential:()=>qf,randomGamma:()=>Mf,randomGeometric:()=>Af,randomInt:()=>bf,randomIrwinHall:()=>xf,randomLcg:()=>Lf,randomLogNormal:()=>wf,randomLogistic:()=>Ef,randomNormal:()=>_f,randomPareto:()=>Nf,randomPoisson:()=>Rf,randomUniform:()=>vf,randomWeibull:()=>jf,range:()=>r.range,rank:()=>r.rank,reduce:()=>r.reduce,reverse:()=>r.reverse,rgb:()=>br.rgb,ribbon:()=>yr,ribbonArrow:()=>vr,rollup:()=>r.rollup,rollups:()=>r.rollups,scaleBand:()=>Df.scaleBand,scaleDiverging:()=>Df.scaleDiverging,scaleDivergingLog:()=>Df.scaleDivergingLog,scaleDivergingPow:()=>Df.scaleDivergingPow,scaleDivergingSqrt:()=>Df.scaleDivergingSqrt,scaleDivergingSymlog:()=>Df.scaleDivergingSymlog,scaleIdentity:()=>Df.scaleIdentity,scaleImplicit:()=>Df.scaleImplicit,scaleLinear:()=>Df.scaleLinear,scaleLog:()=>Df.scaleLog,scaleOrdinal:()=>Df.scaleOrdinal,scalePoint:()=>Df.scalePoint,scalePow:()=>Df.scalePow,scaleQuantile:()=>Df.scaleQuantile,scaleQuantize:()=>Df.scaleQuantize,scaleRadial:()=>Df.scaleRadial,scaleSequential:()=>Df.scaleSequential,scaleSequentialLog:()=>Df.scaleSequentialLog,scaleSequentialPow:()=>Df.scaleSequentialPow,scaleSequentialQuantile:()=>Df.scaleSequentialQuantile,scaleSequentialSqrt:()=>Df.scaleSequentialSqrt,scaleSequentialSymlog:()=>Df.scaleSequentialSymlog,scaleSqrt:()=>Df.scaleSqrt,scaleSymlog:()=>Df.scaleSymlog,scaleThreshold:()=>Df.scaleThreshold,scaleTime:()=>Df.scaleTime,scaleUtc:()=>Df.scaleUtc,scan:()=>r.scan,schemeAccent:()=>Bf.schemeAccent,schemeBlues:()=>Bf.schemeBlues,schemeBrBG:()=>Bf.schemeBrBG,schemeBuGn:()=>Bf.schemeBuGn,schemeBuPu:()=>Bf.schemeBuPu,schemeCategory10:()=>Bf.schemeCategory10,schemeDark2:()=>Bf.schemeDark2,schemeGnBu:()=>Bf.schemeGnBu,schemeGreens:()=>Bf.schemeGreens,schemeGreys:()=>Bf.schemeGreys,schemeOrRd:()=>Bf.schemeOrRd,schemeOranges:()=>Bf.schemeOranges,schemePRGn:()=>Bf.schemePRGn,schemePaired:()=>Bf.schemePaired,schemePastel1:()=>Bf.schemePastel1,schemePastel2:()=>Bf.schemePastel2,schemePiYG:()=>Bf.schemePiYG,schemePuBu:()=>Bf.schemePuBu,schemePuBuGn:()=>Bf.schemePuBuGn,schemePuOr:()=>Bf.schemePuOr,schemePuRd:()=>Bf.schemePuRd,schemePurples:()=>Bf.schemePurples,schemeRdBu:()=>Bf.schemeRdBu,schemeRdGy:()=>Bf.schemeRdGy,schemeRdPu:()=>Bf.schemeRdPu,schemeRdYlBu:()=>Bf.schemeRdYlBu,schemeRdYlGn:()=>Bf.schemeRdYlGn,schemeReds:()=>Bf.schemeReds,schemeSet1:()=>Bf.schemeSet1,schemeSet2:()=>Bf.schemeSet2,schemeSet3:()=>Bf.schemeSet3,schemeSpectral:()=>Bf.schemeSpectral,schemeTableau10:()=>Bf.schemeTableau10,schemeYlGn:()=>Bf.schemeYlGn,schemeYlGnBu:()=>Bf.schemeYlGnBu,schemeYlOrBr:()=>Bf.schemeYlOrBr,schemeYlOrRd:()=>Bf.schemeYlOrRd,select:()=>Dt,selectAll:()=>Jf,selection:()=>Lt,selector:()=>A,selectorAll:()=>C,shuffle:()=>r.shuffle,shuffler:()=>r.shuffler,some:()=>r.some,sort:()=>r.sort,stack:()=>lp,stackOffsetDiverging:()=>up,stackOffsetExpand:()=>cp,stackOffsetNone:()=>op,stackOffsetSilhouette:()=>fp,stackOffsetWiggle:()=>dp,stackOrderAppearance:()=>hp,stackOrderAscending:()=>mp,stackOrderDescending:()=>yp,stackOrderInsideOut:()=>vp,stackOrderNone:()=>ip,stackOrderReverse:()=>bp,stratify:()=>af.QP,style:()=>rt,subset:()=>r.subset,sum:()=>r.sum,superset:()=>r.superset,svg:()=>Ci,symbol:()=>mh,symbolAsterisk:()=>$d,symbolCircle:()=>Gd,symbolCross:()=>Ud,symbolDiamond:()=>Hd,symbolDiamond2:()=>Vd,symbolPlus:()=>Yd,symbolSquare:()=>Qd,symbolSquare2:()=>Kd,symbolStar:()=>nh,symbolTriangle:()=>oh,symbolTriangle2:()=>sh,symbolWye:()=>fh,symbolX:()=>dh,symbols:()=>hh,symbolsFill:()=>hh,symbolsStroke:()=>ph,text:()=>bi,thresholdFreedmanDiaconis:()=>r.thresholdFreedmanDiaconis,thresholdScott:()=>r.thresholdScott,thresholdSturges:()=>r.thresholdSturges,tickFormat:()=>Df.tickFormat,tickIncrement:()=>r.tickIncrement,tickStep:()=>r.tickStep,ticks:()=>r.ticks,timeDay:()=>Np.Z,timeDays:()=>Np.a,timeFormat:()=>Pp.i$,timeFormatDefaultLocale:()=>Pp.ZP,timeFormatLocale:()=>Fp.Z,timeFriday:()=>Sp.mC,timeFridays:()=>Sp.b$,timeHour:()=>qp.Z,timeHours:()=>qp.i,timeInterval:()=>_p.Z,timeMillisecond:()=>wp.Z,timeMilliseconds:()=>wp.m,timeMinute:()=>kp.Z,timeMinutes:()=>kp.L,timeMonday:()=>Sp.wA,timeMondays:()=>Sp.bJ,timeMonth:()=>Ap.Z,timeMonths:()=>Ap.e,timeParse:()=>Pp.Z1,timeSaturday:()=>Sp.EY,timeSaturdays:()=>Sp.Ff,timeSecond:()=>xp.Z,timeSeconds:()=>xp.m,timeSunday:()=>Sp.OM,timeSundays:()=>Sp.vm,timeThursday:()=>Sp.bL,timeThursdays:()=>Sp.$t,timeTickInterval:()=>Ip._g,timeTicks:()=>Ip.jK,timeTuesday:()=>Sp.sy,timeTuesdays:()=>Sp.aU,timeWednesday:()=>Sp.zg,timeWednesdays:()=>Sp.Ld,timeWeek:()=>Sp.OM,timeWeeks:()=>Sp.vm,timeYear:()=>Mp.Z,timeYears:()=>Mp.g,timeout:()=>pe,timer:()=>ce,timerFlush:()=>ue,transition:()=>tn,transpose:()=>r.transpose,tree:()=>af.G_,treemap:()=>af.pN,treemapBinary:()=>af.wL,treemapDice:()=>af.LQ,treemapResquarify:()=>af.eA,treemapSlice:()=>af.Km,treemapSliceDice:()=>af.E_,treemapSquarify:()=>af.o$,tsv:()=>ki,tsvFormat:()=>qo.tsvFormat,tsvFormatBody:()=>qo.tsvFormatBody,tsvFormatRow:()=>qo.tsvFormatRow,tsvFormatRows:()=>qo.tsvFormatRows,tsvFormatValue:()=>qo.tsvFormatValue,tsvParse:()=>qo.tsvParse,tsvParseRows:()=>qo.tsvParseRows,union:()=>r.union,utcDay:()=>jp.Z,utcDays:()=>jp.y,utcFormat:()=>Pp.g0,utcFriday:()=>Op.QQ,utcFridays:()=>Op.fz,utcHour:()=>Cp.Z,utcHours:()=>Cp.X,utcMillisecond:()=>wp.Z,utcMilliseconds:()=>wp.m,utcMinute:()=>Tp.Z,utcMinutes:()=>Tp.N,utcMonday:()=>Op.l6,utcMondays:()=>Op.$3,utcMonth:()=>Ep.Z,utcMonths:()=>Ep.K,utcParse:()=>Pp.wp,utcSaturday:()=>Op.g4,utcSaturdays:()=>Op.Q_,utcSecond:()=>xp.Z,utcSeconds:()=>xp.m,utcSunday:()=>Op.Ox,utcSundays:()=>Op.SU,utcThursday:()=>Op.hB,utcThursdays:()=>Op.xj,utcTickInterval:()=>Ip.jo,utcTicks:()=>Ip.WG,utcTuesday:()=>Op.J1,utcTuesdays:()=>Op.DK,utcWednesday:()=>Op.b3,utcWednesdays:()=>Op.uy,utcWeek:()=>Op.Ox,utcWeeks:()=>Op.SU,utcYear:()=>Rp.Z,utcYears:()=>Rp.D,variance:()=>r.variance,window:()=>X,xml:()=>Mi,zip:()=>r.zip,zoom:()=>rm,zoomIdentity:()=>Wp,zoomTransform:()=>Hp});var r=n(9060);function o(t){return t}var i=1,s=2,a=3,l=4,c=1e-6;function u(t){return"translate("+t+",0)"}function f(t){return"translate(0,"+t+")"}function d(t){return e=>+t(e)}function h(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function p(){return!this.__axis}function m(t,e){var n=[],r=null,m=null,g=6,y=6,v=3,b="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,_=t===i||t===l?-1:1,w=t===l||t===s?"x":"y",x=t===i||t===a?u:f;function k(u){var f=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,k=null==m?e.tickFormat?e.tickFormat.apply(e,n):o:m,q=Math.max(g,0)+v,N=e.range(),S=+N[0]+b,A=+N[N.length-1]+b,M=(e.bandwidth?h:d)(e.copy(),b),T=u.selection?u.selection():u,C=T.selectAll(".domain").data([null]),j=T.selectAll(".tick").data(f,e).order(),O=j.exit(),E=j.enter().append("g").attr("class","tick"),R=j.select("line"),I=j.select("text");C=C.merge(C.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),j=j.merge(E),R=R.merge(E.append("line").attr("stroke","currentColor").attr(w+"2",_*g)),I=I.merge(E.append("text").attr("fill","currentColor").attr(w,_*q).attr("dy",t===i?"0em":t===a?"0.71em":"0.32em")),u!==T&&(C=C.transition(u),j=j.transition(u),R=R.transition(u),I=I.transition(u),O=O.transition(u).attr("opacity",c).attr("transform",(function(t){return isFinite(t=M(t))?x(t+b):this.getAttribute("transform")})),E.attr("opacity",c).attr("transform",(function(t){var e=this.parentNode.__axis;return x((e&&isFinite(e=e(t))?e:M(t))+b)}))),O.remove(),C.attr("d",t===l||t===s?y?"M"+_*y+","+S+"H"+b+"V"+A+"H"+_*y:"M"+b+","+S+"V"+A:y?"M"+S+","+_*y+"V"+b+"H"+A+"V"+_*y:"M"+S+","+b+"H"+A),j.attr("opacity",1).attr("transform",(function(t){return x(M(t)+b)})),R.attr(w+"2",_*g),I.attr(w,_*q).text(k),T.filter(p).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",t===s?"start":t===l?"end":"middle"),T.each((function(){this.__axis=M}))}return k.scale=function(t){return arguments.length?(e=t,k):e},k.ticks=function(){return n=Array.from(arguments),k},k.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),k):n.slice()},k.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),k):r&&r.slice()},k.tickFormat=function(t){return arguments.length?(m=t,k):m},k.tickSize=function(t){return arguments.length?(g=y=+t,k):g},k.tickSizeInner=function(t){return arguments.length?(g=+t,k):g},k.tickSizeOuter=function(t){return arguments.length?(y=+t,k):y},k.tickPadding=function(t){return arguments.length?(v=+t,k):v},k.offset=function(t){return arguments.length?(b=+t,k):b},k}function g(t){return m(i,t)}function y(t){return m(s,t)}function v(t){return m(a,t)}function b(t){return m(l,t)}var _={value:()=>{}};function w(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new x(r)}function x(t){this._=t}function k(t,e){for(var n,r=0,o=t.length;r<o;++r)if((n=t[r]).name===e)return n.value}function q(t,e,n){for(var r=0,o=t.length;r<o;++r)if(t[r].name===e){t[r]=_,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}x.prototype=w.prototype={constructor:x,on:function(t,e){var n,r,o=this._,i=(r=o,(t+"").trim().split(/^|\s+/).map((function(t){var e="",n=t.indexOf(".");if(n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))),s=-1,a=i.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++s<a;)if(n=(t=i[s]).type)o[n]=q(o[n],t.name,e);else if(null==e)for(n in o)o[n]=q(o[n],t.name,null);return this}for(;++s<a;)if((n=(t=i[s]).type)&&(n=k(o[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new x(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,o=new Array(n),i=0;i<n;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,n=(r=this._[t]).length;i<n;++i)r[i].value.apply(e,o)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],o=0,i=r.length;o<i;++o)r[o].value.apply(e,n)}};const N=w;function S(){}function A(t){return null==t?S:function(){return this.querySelector(t)}}function M(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function T(){return[]}function C(t){return null==t?T:function(){return this.querySelectorAll(t)}}function j(t){return function(){return this.matches(t)}}function O(t){return function(e){return e.matches(t)}}var E=Array.prototype.find;function R(){return this.firstElementChild}var I=Array.prototype.filter;function P(){return Array.from(this.children)}function F(t){return new Array(t.length)}function L(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function D(t,e,n,r,o,i){for(var s,a=0,l=e.length,c=i.length;a<c;++a)(s=e[a])?(s.__data__=i[a],r[a]=s):n[a]=new L(t,i[a]);for(;a<l;++a)(s=e[a])&&(o[a]=s)}function B(t,e,n,r,o,i,s){var a,l,c,u=new Map,f=e.length,d=i.length,h=new Array(f);for(a=0;a<f;++a)(l=e[a])&&(h[a]=c=s.call(l,l.__data__,a,e)+"",u.has(c)?o[a]=l:u.set(c,l));for(a=0;a<d;++a)c=s.call(t,i[a],a,i)+"",(l=u.get(c))?(r[a]=l,l.__data__=i[a],u.delete(c)):n[a]=new L(t,i[a]);for(a=0;a<f;++a)(l=e[a])&&u.get(h[a])===l&&(o[a]=l)}function z(t){return t.__data__}function Z(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function $(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}L.prototype={constructor:L,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var G="http://www.w3.org/1999/xhtml";const U={svg:"http://www.w3.org/2000/svg",xhtml:G,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function J(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),U.hasOwnProperty(e)?{space:U[e],local:t}:t}function W(t){return function(){this.removeAttribute(t)}}function H(t){return function(){this.removeAttributeNS(t.space,t.local)}}function V(t,e){return function(){this.setAttribute(t,e)}}function Y(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Q(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function K(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function X(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function tt(t){return function(){this.style.removeProperty(t)}}function et(t,e,n){return function(){this.style.setProperty(t,e,n)}}function nt(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function rt(t,e){return t.style.getPropertyValue(e)||X(t).getComputedStyle(t,null).getPropertyValue(e)}function ot(t){return function(){delete this[t]}}function it(t,e){return function(){this[t]=e}}function st(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function at(t){return t.trim().split(/^|\s+/)}function lt(t){return t.classList||new ct(t)}function ct(t){this._node=t,this._names=at(t.getAttribute("class")||"")}function ut(t,e){for(var n=lt(t),r=-1,o=e.length;++r<o;)n.add(e[r])}function ft(t,e){for(var n=lt(t),r=-1,o=e.length;++r<o;)n.remove(e[r])}function dt(t){return function(){ut(this,t)}}function ht(t){return function(){ft(this,t)}}function pt(t,e){return function(){(e.apply(this,arguments)?ut:ft)(this,t)}}function mt(){this.textContent=""}function gt(t){return function(){this.textContent=t}}function yt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function vt(){this.innerHTML=""}function bt(t){return function(){this.innerHTML=t}}function _t(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function wt(){this.nextSibling&&this.parentNode.appendChild(this)}function xt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function kt(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===G&&e.documentElement.namespaceURI===G?e.createElement(t):e.createElementNS(n,t)}}function qt(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function Nt(t){var e=J(t);return(e.local?qt:kt)(e)}function St(){return null}function At(){var t=this.parentNode;t&&t.removeChild(this)}function Mt(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Tt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Ct(t){return function(){var e=this.__on;if(e){for(var n,r=0,o=-1,i=e.length;r<i;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++o]=n:this.removeEventListener(n.type,n.listener,n.options);++o?e.length=o:delete this.__on}}}function jt(t,e,n){return function(){var r,o=this.__on,i=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(o)for(var s=0,a=o.length;s<a;++s)if((r=o[s]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=i,r.options=n),void(r.value=e);this.addEventListener(t.type,i,n),r={type:t.type,name:t.name,value:e,listener:i,options:n},o?o.push(r):this.__on=[r]}}function Ot(t,e,n){var r=X(t),o=r.CustomEvent;"function"==typeof o?o=new o(e,n):(o=r.document.createEvent("Event"),n?(o.initEvent(e,n.bubbles,n.cancelable),o.detail=n.detail):o.initEvent(e,!1,!1)),t.dispatchEvent(o)}function Et(t,e){return function(){return Ot(this,t,e)}}function Rt(t,e){return function(){return Ot(this,t,e.apply(this,arguments))}}ct.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var It=[null];function Pt(t,e){this._groups=t,this._parents=e}function Ft(){return new Pt([[document.documentElement]],It)}Pt.prototype=Ft.prototype={constructor:Pt,select:function(t){"function"!=typeof t&&(t=A(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s,a=e[o],l=a.length,c=r[o]=new Array(l),u=0;u<l;++u)(i=a[u])&&(s=t.call(i,i.__data__,u,a))&&("__data__"in i&&(s.__data__=i.__data__),c[u]=s);return new Pt(r,this._parents)},selectAll:function(t){t="function"==typeof t?function(t){return function(){return M(t.apply(this,arguments))}}(t):C(t);for(var e=this._groups,n=e.length,r=[],o=[],i=0;i<n;++i)for(var s,a=e[i],l=a.length,c=0;c<l;++c)(s=a[c])&&(r.push(t.call(s,s.__data__,c,a)),o.push(s));return new Pt(r,o)},selectChild:function(t){return this.select(null==t?R:function(t){return function(){return E.call(this.children,t)}}("function"==typeof t?t:O(t)))},selectChildren:function(t){return this.selectAll(null==t?P:function(t){return function(){return I.call(this.children,t)}}("function"==typeof t?t:O(t)))},filter:function(t){"function"!=typeof t&&(t=j(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s=e[o],a=s.length,l=r[o]=[],c=0;c<a;++c)(i=s[c])&&t.call(i,i.__data__,c,s)&&l.push(i);return new Pt(r,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,z);var n=e?B:D,r=this._parents,o=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var i=o.length,s=new Array(i),a=new Array(i),l=new Array(i),c=0;c<i;++c){var u=r[c],f=o[c],d=f.length,h=Z(t.call(u,u&&u.__data__,c,r)),p=h.length,m=a[c]=new Array(p),g=s[c]=new Array(p);n(u,f,m,g,l[c]=new Array(d),h,e);for(var y,v,b=0,_=0;b<p;++b)if(y=m[b]){for(b>=_&&(_=b+1);!(v=g[_])&&++_<p;);y._next=v||null}}return(s=new Pt(s,r))._enter=a,s._exit=l,s},enter:function(){return new Pt(this._enter||this._groups.map(F),this._parents)},exit:function(){return new Pt(this._exit||this._groups.map(F),this._parents)},join:function(t,e,n){var r=this.enter(),o=this,i=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=e&&(o=e(o))&&(o=o.selection()),null==n?i.remove():n(i),r&&o?r.merge(o).order():o},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,r=e._groups,o=n.length,i=r.length,s=Math.min(o,i),a=new Array(o),l=0;l<s;++l)for(var c,u=n[l],f=r[l],d=u.length,h=a[l]=new Array(d),p=0;p<d;++p)(c=u[p]||f[p])&&(h[p]=c);for(;l<o;++l)a[l]=n[l];return new Pt(a,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,o=t[e],i=o.length-1,s=o[i];--i>=0;)(r=o[i])&&(s&&4^r.compareDocumentPosition(s)&&s.parentNode.insertBefore(r,s),s=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=$);for(var n=this._groups,r=n.length,o=new Array(r),i=0;i<r;++i){for(var s,a=n[i],l=a.length,c=o[i]=new Array(l),u=0;u<l;++u)(s=a[u])&&(c[u]=s);c.sort(e)}return new Pt(o,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],o=0,i=r.length;o<i;++o){var s=r[o];if(s)return s}return null},size:function(){let t=0;for(const e of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var o,i=e[n],s=0,a=i.length;s<a;++s)(o=i[s])&&t.call(o,o.__data__,s,i);return this},attr:function(t,e){var n=J(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?H:W:"function"==typeof e?n.local?K:Q:n.local?Y:V)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?tt:"function"==typeof e?nt:et)(t,e,null==n?"":n)):rt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ot:"function"==typeof e?st:it)(t,e)):this.node()[t]},classed:function(t,e){var n=at(t+"");if(arguments.length<2){for(var r=lt(this.node()),o=-1,i=n.length;++o<i;)if(!r.contains(n[o]))return!1;return!0}return this.each(("function"==typeof e?pt:e?dt:ht)(n,e))},text:function(t){return arguments.length?this.each(null==t?mt:("function"==typeof t?yt:gt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?vt:("function"==typeof t?_t:bt)(t)):this.node().innerHTML},raise:function(){return this.each(wt)},lower:function(){return this.each(xt)},append:function(t){var e="function"==typeof t?t:Nt(t);return this.select((function(){return this.appendChild(e.apply(this,arguments))}))},insert:function(t,e){var n="function"==typeof t?t:Nt(t),r=null==e?St:"function"==typeof e?e:A(e);return this.select((function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)}))},remove:function(){return this.each(At)},clone:function(t){return this.select(t?Tt:Mt)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,o,i=function(t){return t.trim().split(/^|\s+/).map((function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),s=i.length;if(!(arguments.length<2)){for(a=e?jt:Ct,r=0;r<s;++r)this.each(a(i[r],e,n));return this}var a=this.node().__on;if(a)for(var l,c=0,u=a.length;c<u;++c)for(r=0,l=a[c];r<s;++r)if((o=i[r]).type===l.type&&o.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?Rt:Et)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r,o=t[e],i=0,s=o.length;i<s;++i)(r=o[i])&&(yield r)}};const Lt=Ft;function Dt(t){return"string"==typeof t?new Pt([[document.querySelector(t)]],[document.documentElement]):new Pt([[t]],It)}const Bt={passive:!1},zt={capture:!0,passive:!1};function Zt(t){t.stopImmediatePropagation()}function $t(t){t.preventDefault(),t.stopImmediatePropagation()}function Gt(t){var e=t.document.documentElement,n=Dt(t).on("dragstart.drag",$t,zt);"onselectstart"in e?n.on("selectstart.drag",$t,zt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Ut(t,e){var n=t.document.documentElement,r=Dt(t).on("dragstart.drag",null);e&&(r.on("click.drag",$t,zt),setTimeout((function(){r.on("click.drag",null)}),0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var Jt=n(2303);function Wt(t){let e;for(;e=t.sourceEvent;)t=e;return t}function Ht(t,e){if(t=Wt(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(e.getScreenCTM().inverse())).x,r.y]}if(e.getBoundingClientRect){var o=e.getBoundingClientRect();return[t.clientX-o.left-e.clientLeft,t.clientY-o.top-e.clientTop]}}return[t.pageX,t.pageY]}var Vt,Yt,Qt=0,Kt=0,Xt=0,te=1e3,ee=0,ne=0,re=0,oe="object"==typeof performance&&performance.now?performance:Date,ie="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function se(){return ne||(ie(ae),ne=oe.now()+re)}function ae(){ne=0}function le(){this._call=this._time=this._next=null}function ce(t,e,n){var r=new le;return r.restart(t,e,n),r}function ue(){se(),++Qt;for(var t,e=Vt;e;)(t=ne-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Qt}function fe(){ne=(ee=oe.now())+re,Qt=Kt=0;try{ue()}finally{Qt=0,function(){var t,e,n=Vt,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Vt=e);Yt=t,he(r)}(),ne=0}}function de(){var t=oe.now(),e=t-ee;e>te&&(re-=e,ee=t)}function he(t){Qt||(Kt&&(Kt=clearTimeout(Kt)),t-ne>24?(t<1/0&&(Kt=setTimeout(fe,t-oe.now()-re)),Xt&&(Xt=clearInterval(Xt))):(Xt||(ee=oe.now(),Xt=setInterval(de,te)),Qt=1,ie(fe)))}function pe(t,e,n){var r=new le;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}le.prototype=ce.prototype={constructor:le,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?se():+n)+(null==e?0:+e),this._next||Yt===this||(Yt?Yt._next=this:Vt=this,Yt=this),this._call=t,this._time=n,he()},stop:function(){this._call&&(this._call=null,this._time=1/0,he())}};var me=N("start","end","cancel","interrupt"),ge=[],ye=0,ve=1,be=2,_e=3,we=4,xe=5,ke=6;function qe(t,e,n,r,o,i){var s=t.__transition;if(s){if(n in s)return}else t.__transition={};!function(t,e,n){var r,o=t.__transition;function i(t){n.state=ve,n.timer.restart(s,n.delay,n.time),n.delay<=t&&s(t-n.delay)}function s(i){var c,u,f,d;if(n.state!==ve)return l();for(c in o)if((d=o[c]).name===n.name){if(d.state===_e)return pe(s);d.state===we?(d.state=ke,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete o[c]):+c<e&&(d.state=ke,d.timer.stop(),d.on.call("cancel",t,t.__data__,d.index,d.group),delete o[c])}if(pe((function(){n.state===_e&&(n.state=we,n.timer.restart(a,n.delay,n.time),a(i))})),n.state=be,n.on.call("start",t,t.__data__,n.index,n.group),n.state===be){for(n.state=_e,r=new Array(f=n.tween.length),c=0,u=-1;c<f;++c)(d=n.tween[c].value.call(t,t.__data__,n.index,n.group))&&(r[++u]=d);r.length=u+1}}function a(e){for(var o=e<n.duration?n.ease.call(null,e/n.duration):(n.timer.restart(l),n.state=xe,1),i=-1,s=r.length;++i<s;)r[i].call(t,o);n.state===xe&&(n.on.call("end",t,t.__data__,n.index,n.group),l())}function l(){for(var r in n.state=ke,n.timer.stop(),delete o[e],o)return;delete t.__transition}o[e]=n,n.timer=ce(i,0,n.time)}(t,n,{name:e,index:r,group:o,on:me,tween:ge,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:ye})}function Ne(t,e){var n=Ae(t,e);if(n.state>ye)throw new Error("too late; already scheduled");return n}function Se(t,e){var n=Ae(t,e);if(n.state>_e)throw new Error("too late; already running");return n}function Ae(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Me(t,e){var n,r,o,i=t.__transition,s=!0;if(i){for(o in e=null==e?null:e+"",i)(n=i[o]).name===e?(r=n.state>be&&n.state<xe,n.state=ke,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete i[o]):s=!1;s&&delete t.__transition}}var Te=n(2650);function Ce(t,e){var n,r;return function(){var o=Se(this,t),i=o.tween;if(i!==n)for(var s=0,a=(r=n=i).length;s<a;++s)if(r[s].name===e){(r=r.slice()).splice(s,1);break}o.tween=r}}function je(t,e,n){var r,o;if("function"!=typeof n)throw new Error;return function(){var i=Se(this,t),s=i.tween;if(s!==r){o=(r=s).slice();for(var a={name:e,value:n},l=0,c=o.length;l<c;++l)if(o[l].name===e){o[l]=a;break}l===c&&o.push(a)}i.tween=o}}function Oe(t,e,n){var r=t._id;return t.each((function(){var t=Se(this,r);(t.value||(t.value={}))[e]=n.apply(this,arguments)})),function(t){return Ae(t,r).value[e]}}var Ee=n(1495),Re=n(8403),Ie=n(490),Pe=n(9009);function Fe(t,e){var n;return("number"==typeof e?Re.Z:e instanceof Ee.ZP?Ie.ZP:(n=(0,Ee.ZP)(e))?(e=n,Ie.ZP):Pe.Z)(t,e)}function Le(t){return function(){this.removeAttribute(t)}}function De(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Be(t,e,n){var r,o,i=n+"";return function(){var s=this.getAttribute(t);return s===i?null:s===r?o:o=e(r=s,n)}}function ze(t,e,n){var r,o,i=n+"";return function(){var s=this.getAttributeNS(t.space,t.local);return s===i?null:s===r?o:o=e(r=s,n)}}function Ze(t,e,n){var r,o,i;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttribute(t))===(a=l+"")?null:s===r&&a===o?i:(o=a,i=e(r=s,l));this.removeAttribute(t)}}function $e(t,e,n){var r,o,i;return function(){var s,a,l=n(this);if(null!=l)return(s=this.getAttributeNS(t.space,t.local))===(a=l+"")?null:s===r&&a===o?i:(o=a,i=e(r=s,l));this.removeAttributeNS(t.space,t.local)}}function Ge(t,e){var n,r;function o(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&function(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}(t,o)),n}return o._value=e,o}function Ue(t,e){var n,r;function o(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&function(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}(t,o)),n}return o._value=e,o}function Je(t,e){return function(){Ne(this,t).delay=+e.apply(this,arguments)}}function We(t,e){return e=+e,function(){Ne(this,t).delay=e}}function He(t,e){return function(){Se(this,t).duration=+e.apply(this,arguments)}}function Ve(t,e){return e=+e,function(){Se(this,t).duration=e}}var Ye=Lt.prototype.constructor;function Qe(t){return function(){this.style.removeProperty(t)}}var Ke=0;function Xe(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function tn(t){return Lt().transition(t)}function en(){return++Ke}var nn=Lt.prototype;function rn(t){return t*t*t}function on(t){return--t*t*t+1}function sn(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}Xe.prototype=tn.prototype={constructor:Xe,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=A(t));for(var r=this._groups,o=r.length,i=new Array(o),s=0;s<o;++s)for(var a,l,c=r[s],u=c.length,f=i[s]=new Array(u),d=0;d<u;++d)(a=c[d])&&(l=t.call(a,a.__data__,d,c))&&("__data__"in a&&(l.__data__=a.__data__),f[d]=l,qe(f[d],e,n,d,f,Ae(a,n)));return new Xe(i,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=C(t));for(var r=this._groups,o=r.length,i=[],s=[],a=0;a<o;++a)for(var l,c=r[a],u=c.length,f=0;f<u;++f)if(l=c[f]){for(var d,h=t.call(l,l.__data__,f,c),p=Ae(l,n),m=0,g=h.length;m<g;++m)(d=h[m])&&qe(d,e,n,m,h,p);i.push(h),s.push(l)}return new Xe(i,s,e,n)},selectChild:nn.selectChild,selectChildren:nn.selectChildren,filter:function(t){"function"!=typeof t&&(t=j(t));for(var e=this._groups,n=e.length,r=new Array(n),o=0;o<n;++o)for(var i,s=e[o],a=s.length,l=r[o]=[],c=0;c<a;++c)(i=s[c])&&t.call(i,i.__data__,c,s)&&l.push(i);return new Xe(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var e=this._groups,n=t._groups,r=e.length,o=n.length,i=Math.min(r,o),s=new Array(r),a=0;a<i;++a)for(var l,c=e[a],u=n[a],f=c.length,d=s[a]=new Array(f),h=0;h<f;++h)(l=c[h]||u[h])&&(d[h]=l);for(;a<r;++a)s[a]=e[a];return new Xe(s,this._parents,this._name,this._id)},selection:function(){return new Ye(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=en(),r=this._groups,o=r.length,i=0;i<o;++i)for(var s,a=r[i],l=a.length,c=0;c<l;++c)if(s=a[c]){var u=Ae(s,e);qe(s,t,n,c,a,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Xe(r,this._parents,t,n)},call:nn.call,nodes:nn.nodes,node:nn.node,size:nn.size,empty:nn.empty,each:nn.each,on:function(t,e){var n=this._id;return arguments.length<2?Ae(this.node(),n).on.on(t):this.each(function(t,e,n){var r,o,i=function(t){return(t+"").trim().split(/^|\s+/).every((function(t){var e=t.indexOf(".");return e>=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?Ne:Se;return function(){var s=i(this,t),a=s.on;a!==r&&(o=(r=a).copy()).on(e,n),s.on=o}}(n,t,e))},attr:function(t,e){var n=J(t),r="transform"===n?Te.w:Fe;return this.attrTween(t,"function"==typeof e?(n.local?$e:Ze)(n,r,Oe(this,"attr."+t,e)):null==e?(n.local?De:Le)(n):(n.local?ze:Be)(n,r,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var r=J(t);return this.tween(n,(r.local?Ge:Ue)(r,e))},style:function(t,e,n){var r="transform"==(t+="")?Te.Y:Fe;return null==e?this.styleTween(t,function(t,e){var n,r,o;return function(){var i=rt(this,t),s=(this.style.removeProperty(t),rt(this,t));return i===s?null:i===n&&s===r?o:o=e(n=i,r=s)}}(t,r)).on("end.style."+t,Qe(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var r,o,i;return function(){var s=rt(this,t),a=n(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=rt(this,t)),s===l?null:s===r&&l===o?i:(o=l,i=e(r=s,a))}}(t,r,Oe(this,"style."+t,e))).each(function(t,e){var n,r,o,i,s="style."+e,a="end."+s;return function(){var l=Se(this,t),c=l.on,u=null==l.value[s]?i||(i=Qe(e)):void 0;c===n&&o===u||(r=(n=c).copy()).on(a,o=u),l.on=r}}(this._id,t)):this.styleTween(t,function(t,e,n){var r,o,i=n+"";return function(){var s=rt(this,t);return s===i?null:s===r?o:o=e(r=s,n)}}(t,r,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!=typeof e)throw new Error;return this.tween(r,function(t,e,n){var r,o;function i(){var i=e.apply(this,arguments);return i!==o&&(r=(o=i)&&function(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}(t,i,n)),r}return i._value=e,i}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(Oe(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&function(t){return function(e){this.textContent=t.call(this,e)}}(r)),e}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var r,o=Ae(this.node(),n).tween,i=0,s=o.length;i<s;++i)if((r=o[i]).name===t)return r.value;return null}return this.each((null==e?Ce:je)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Je:We)(e,t)):Ae(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?He:Ve)(e,t)):Ae(this.node(),e).duration},ease:function(t){var e=this._id;return arguments.length?this.each(function(t,e){if("function"!=typeof e)throw new Error;return function(){Se(this,t).ease=e}}(e,t)):Ae(this.node(),e).ease},easeVarying:function(t){if("function"!=typeof t)throw new Error;return this.each(function(t,e){return function(){var n=e.apply(this,arguments);if("function"!=typeof n)throw new Error;Se(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,r=n._id,o=n.size();return new Promise((function(i,s){var a={value:s},l={value:function(){0==--o&&i()}};n.each((function(){var n=Se(this,r),o=n.on;o!==t&&((e=(t=o).copy())._.cancel.push(a),e._.interrupt.push(a),e._.end.push(l)),n.on=e})),0===o&&i()}))},[Symbol.iterator]:nn[Symbol.iterator]};var an={time:null,delay:0,duration:250,ease:sn};function ln(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}Lt.prototype.interrupt=function(t){return this.each((function(){Me(this,t)}))},Lt.prototype.transition=function(t){var e,n;t instanceof Xe?(e=t._id,t=t._name):(e=en(),(n=an).time=se(),t=null==t?null:t+"");for(var r=this._groups,o=r.length,i=0;i<o;++i)for(var s,a=r[i],l=a.length,c=0;c<l;++c)(s=a[c])&&qe(s,t,e,c,a,n||ln(s,e));return new Xe(r,this._parents,t,e)};var cn=[null];function un(t,e){var n,r,o=t.__transition;if(o)for(r in e=null==e?null:e+"",o)if((n=o[r]).state>ve&&n.name===e)return new Xe([[t]],cn,e,+r);return null}const fn=t=>()=>t;function dn(t,{sourceEvent:e,target:n,selection:r,mode:o,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},selection:{value:r,enumerable:!0,configurable:!0},mode:{value:o,enumerable:!0,configurable:!0},_:{value:i}})}function hn(t){t.preventDefault(),t.stopImmediatePropagation()}var pn={name:"drag"},mn={name:"space"},gn={name:"handle"},yn={name:"center"};const{abs:vn,max:bn,min:_n}=Math;function wn(t){return[+t[0],+t[1]]}function xn(t){return[wn(t[0]),wn(t[1])]}var kn={name:"x",handles:["w","e"].map(jn),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},qn={name:"y",handles:["n","s"].map(jn),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},Nn={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(jn),input:function(t){return null==t?null:xn(t)},output:function(t){return t}},Sn={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},An={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},Mn={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},Tn={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},Cn={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function jn(t){return{type:t}}function On(t){return!t.ctrlKey&&!t.button}function En(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function Rn(){return navigator.maxTouchPoints||"ontouchstart"in this}function In(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function Pn(t){var e=t.__brush;return e?e.dim.output(e.selection):null}function Fn(){return Bn(kn)}function Ln(){return Bn(qn)}function Dn(){return Bn(Nn)}function Bn(t){var e,n=En,r=On,o=Rn,i=!0,s=N("start","brush","end"),a=6;function l(e){var n=e.property("__brush",m).selectAll(".overlay").data([jn("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",Sn.overlay).merge(n).each((function(){var t=In(this).extent;Dt(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])})),e.selectAll(".selection").data([jn("selection")]).enter().append("rect").attr("class","selection").attr("cursor",Sn.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,(function(t){return t.type}));r.exit().remove(),r.enter().append("rect").attr("class",(function(t){return"handle handle--"+t.type})).attr("cursor",(function(t){return Sn[t.type]})),e.each(c).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",d).filter(o).on("touchstart.brush",d).on("touchmove.brush",h).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function c(){var t=Dt(this),e=In(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",(function(t){return"e"===t.type[t.type.length-1]?e[1][0]-a/2:e[0][0]-a/2})).attr("y",(function(t){return"s"===t.type[0]?e[1][1]-a/2:e[0][1]-a/2})).attr("width",(function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+a:a})).attr("height",(function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+a:a}))):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function u(t,e,n){var r=t.__brush.emitter;return!r||n&&r.clean?new f(t,e,n):r}function f(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function d(n){if((!e||n.touches)&&r.apply(this,arguments)){var o,s,a,l,f,d,h,p,m,g,y,v=this,b=n.target.__data__.type,_="selection"===(i&&n.metaKey?b="overlay":b)?pn:i&&n.altKey?yn:gn,w=t===qn?null:Tn[b],x=t===kn?null:Cn[b],k=In(v),q=k.extent,N=k.selection,S=q[0][0],A=q[0][1],M=q[1][0],T=q[1][1],C=0,j=0,O=w&&x&&i&&n.shiftKey,E=Array.from(n.touches||[n],(t=>{const e=t.identifier;return(t=Ht(t,v)).point0=t.slice(),t.identifier=e,t}));Me(v);var R=u(v,arguments,!0).beforestart();if("overlay"===b){N&&(m=!0);const e=[E[0],E[1]||E[0]];k.selection=N=[[o=t===qn?S:_n(e[0][0],e[1][0]),a=t===kn?A:_n(e[0][1],e[1][1])],[f=t===qn?M:bn(e[0][0],e[1][0]),h=t===kn?T:bn(e[0][1],e[1][1])]],E.length>1&&D(n)}else o=N[0][0],a=N[0][1],f=N[1][0],h=N[1][1];s=o,l=a,d=f,p=h;var I=Dt(v).attr("pointer-events","none"),P=I.selectAll(".overlay").attr("cursor",Sn[b]);if(n.touches)R.moved=L,R.ended=B;else{var F=Dt(n.view).on("mousemove.brush",L,!0).on("mouseup.brush",B,!0);i&&F.on("keydown.brush",(function(t){switch(t.keyCode){case 16:O=w&&x;break;case 18:_===gn&&(w&&(f=d-C*w,o=s+C*w),x&&(h=p-j*x,a=l+j*x),_=yn,D(t));break;case 32:_!==gn&&_!==yn||(w<0?f=d-C:w>0&&(o=s-C),x<0?h=p-j:x>0&&(a=l-j),_=mn,P.attr("cursor",Sn.selection),D(t));break;default:return}hn(t)}),!0).on("keyup.brush",(function(t){switch(t.keyCode){case 16:O&&(g=y=O=!1,D(t));break;case 18:_===yn&&(w<0?f=d:w>0&&(o=s),x<0?h=p:x>0&&(a=l),_=gn,D(t));break;case 32:_===mn&&(t.altKey?(w&&(f=d-C*w,o=s+C*w),x&&(h=p-j*x,a=l+j*x),_=yn):(w<0?f=d:w>0&&(o=s),x<0?h=p:x>0&&(a=l),_=gn),P.attr("cursor",Sn[b]),D(t));break;default:return}hn(t)}),!0),Gt(n.view)}c.call(v),R.start(n,_.name)}function L(t){for(const e of t.changedTouches||[t])for(const t of E)t.identifier===e.identifier&&(t.cur=Ht(e,v));if(O&&!g&&!y&&1===E.length){const t=E[0];vn(t.cur[0]-t[0])>vn(t.cur[1]-t[1])?y=!0:g=!0}for(const t of E)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);m=!0,hn(t),D(t)}function D(t){const e=E[0],n=e.point0;var r;switch(C=e[0]-n[0],j=e[1]-n[1],_){case mn:case pn:w&&(C=bn(S-o,_n(M-f,C)),s=o+C,d=f+C),x&&(j=bn(A-a,_n(T-h,j)),l=a+j,p=h+j);break;case gn:E[1]?(w&&(s=bn(S,_n(M,E[0][0])),d=bn(S,_n(M,E[1][0])),w=1),x&&(l=bn(A,_n(T,E[0][1])),p=bn(A,_n(T,E[1][1])),x=1)):(w<0?(C=bn(S-o,_n(M-o,C)),s=o+C,d=f):w>0&&(C=bn(S-f,_n(M-f,C)),s=o,d=f+C),x<0?(j=bn(A-a,_n(T-a,j)),l=a+j,p=h):x>0&&(j=bn(A-h,_n(T-h,j)),l=a,p=h+j));break;case yn:w&&(s=bn(S,_n(M,o-C*w)),d=bn(S,_n(M,f+C*w))),x&&(l=bn(A,_n(T,a-j*x)),p=bn(A,_n(T,h+j*x)))}d<s&&(w*=-1,r=o,o=f,f=r,r=s,s=d,d=r,b in An&&P.attr("cursor",Sn[b=An[b]])),p<l&&(x*=-1,r=a,a=h,h=r,r=l,l=p,p=r,b in Mn&&P.attr("cursor",Sn[b=Mn[b]])),k.selection&&(N=k.selection),g&&(s=N[0][0],d=N[1][0]),y&&(l=N[0][1],p=N[1][1]),N[0][0]===s&&N[0][1]===l&&N[1][0]===d&&N[1][1]===p||(k.selection=[[s,l],[d,p]],c.call(v),R.brush(t,_.name))}function B(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout((function(){e=null}),500)}else Ut(t.view,m),F.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);I.attr("pointer-events","all"),P.attr("cursor",Sn.overlay),k.selection&&(N=k.selection),function(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}(N)&&(k.selection=null,c.call(v)),R.end(t,_.name)}}function h(t){u(this,arguments).moved(t)}function p(t){u(this,arguments).ended(t)}function m(){var e=this.__brush||{selection:null};return e.extent=xn(n.apply(this,arguments)),e.dim=t,e}return l.move=function(e,n,r){e.tween?e.on("start.brush",(function(t){u(this,arguments).beforestart().start(t)})).on("interrupt.brush end.brush",(function(t){u(this,arguments).end(t)})).tween("brush",(function(){var e=this,r=e.__brush,o=u(e,arguments),i=r.selection,s=t.input("function"==typeof n?n.apply(this,arguments):n,r.extent),a=(0,Jt.Z)(i,s);function l(t){r.selection=1===t&&null===s?null:a(t),c.call(e),o.brush()}return null!==i&&null!==s?l:l(1)})):e.each((function(){var e=this,o=arguments,i=e.__brush,s=t.input("function"==typeof n?n.apply(e,o):n,i.extent),a=u(e,o).beforestart();Me(e),i.selection=null===s?null:s,c.call(e),a.start(r).brush(r).end(r)}))},l.clear=function(t,e){l.move(t,null,e)},f.prototype={beforestart:function(){return 1==++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(t,e){return this.starting?(this.starting=!1,this.emit("start",t,e)):this.emit("brush",t),this},brush:function(t,e){return this.emit("brush",t,e),this},end:function(t,e){return 0==--this.active&&(delete this.state.emitter,this.emit("end",t,e)),this},emit:function(e,n,r){var o=Dt(this.that).datum();s.call(e,this.that,new dn(e,{sourceEvent:n,target:l,selection:t.output(this.state.selection),mode:r,dispatch:s}),o)}},l.extent=function(t){return arguments.length?(n="function"==typeof t?t:fn(xn(t)),l):n},l.filter=function(t){return arguments.length?(r="function"==typeof t?t:fn(!!t),l):r},l.touchable=function(t){return arguments.length?(o="function"==typeof t?t:fn(!!t),l):o},l.handleSize=function(t){return arguments.length?(a=+t,l):a},l.keyModifiers=function(t){return arguments.length?(i=!!t,l):i},l.on=function(){var t=s.on.apply(s,arguments);return t===s?l:t},l}var zn=Math.abs,Zn=Math.cos,$n=Math.sin,Gn=Math.PI,Un=Gn/2,Jn=2*Gn,Wn=Math.max,Hn=1e-12;function Vn(t,e){return Array.from({length:e-t},((e,n)=>t+n))}function Yn(){return Xn(!1,!1)}function Qn(){return Xn(!1,!0)}function Kn(){return Xn(!0,!1)}function Xn(t,e){var n=0,r=null,o=null,i=null;function s(s){var a,l=s.length,c=new Array(l),u=Vn(0,l),f=new Array(l*l),d=new Array(l),h=0;s=Float64Array.from({length:l*l},e?(t,e)=>s[e%l][e/l|0]:(t,e)=>s[e/l|0][e%l]);for(let e=0;e<l;++e){let n=0;for(let r=0;r<l;++r)n+=s[e*l+r]+t*s[r*l+e];h+=c[e]=n}a=(h=Wn(0,Jn-n*l)/h)?n:Jn/l;{let e=0;r&&u.sort(((t,e)=>r(c[t],c[e])));for(const n of u){const r=e;if(t){const t=Vn(1+~l,l).filter((t=>t<0?s[~t*l+n]:s[n*l+t]));o&&t.sort(((t,e)=>o(t<0?-s[~t*l+n]:s[n*l+t],e<0?-s[~e*l+n]:s[n*l+e])));for(const r of t)if(r<0){(f[~r*l+n]||(f[~r*l+n]={source:null,target:null})).target={index:n,startAngle:e,endAngle:e+=s[~r*l+n]*h,value:s[~r*l+n]}}else{(f[n*l+r]||(f[n*l+r]={source:null,target:null})).source={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]}}d[n]={index:n,startAngle:r,endAngle:e,value:c[n]}}else{const t=Vn(0,l).filter((t=>s[n*l+t]||s[t*l+n]));o&&t.sort(((t,e)=>o(s[n*l+t],s[n*l+e])));for(const r of t){let t;if(n<r?(t=f[n*l+r]||(f[n*l+r]={source:null,target:null}),t.source={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]}):(t=f[r*l+n]||(f[r*l+n]={source:null,target:null}),t.target={index:n,startAngle:e,endAngle:e+=s[n*l+r]*h,value:s[n*l+r]},n===r&&(t.source=t.target)),t.source&&t.target&&t.source.value<t.target.value){const e=t.source;t.source=t.target,t.target=e}}d[n]={index:n,startAngle:r,endAngle:e,value:c[n]}}e+=a}}return(f=Object.values(f)).groups=d,i?f.sort(i):f}return s.padAngle=function(t){return arguments.length?(n=Wn(0,t),s):n},s.sortGroups=function(t){return arguments.length?(r=t,s):r},s.sortSubgroups=function(t){return arguments.length?(o=t,s):o},s.sortChords=function(t){return arguments.length?(null==t?i=null:(e=t,i=function(t,n){return e(t.source.value+t.target.value,n.source.value+n.target.value)})._=t,s):i&&i._;var e},s}const tr=Math.PI,er=2*tr,nr=1e-6,rr=er-nr;function or(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function ir(){return new or}or.prototype=ir.prototype={constructor:or,moveTo:function(t,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,e){this._+="L"+(this._x1=+t)+","+(this._y1=+e)},quadraticCurveTo:function(t,e,n,r){this._+="Q"+ +t+","+ +e+","+(this._x1=+n)+","+(this._y1=+r)},bezierCurveTo:function(t,e,n,r,o,i){this._+="C"+ +t+","+ +e+","+ +n+","+ +r+","+(this._x1=+o)+","+(this._y1=+i)},arcTo:function(t,e,n,r,o){t=+t,e=+e,n=+n,r=+r,o=+o;var i=this._x1,s=this._y1,a=n-t,l=r-e,c=i-t,u=s-e,f=c*c+u*u;if(o<0)throw new Error("negative radius: "+o);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=e);else if(f>nr)if(Math.abs(u*a-l*c)>nr&&o){var d=n-i,h=r-s,p=a*a+l*l,m=d*d+h*h,g=Math.sqrt(p),y=Math.sqrt(f),v=o*Math.tan((tr-Math.acos((p+f-m)/(2*g*y)))/2),b=v/y,_=v/g;Math.abs(b-1)>nr&&(this._+="L"+(t+b*c)+","+(e+b*u)),this._+="A"+o+","+o+",0,0,"+ +(u*d>c*h)+","+(this._x1=t+_*a)+","+(this._y1=e+_*l)}else this._+="L"+(this._x1=t)+","+(this._y1=e);else;},arc:function(t,e,n,r,o,i){t=+t,e=+e,i=!!i;var s=(n=+n)*Math.cos(r),a=n*Math.sin(r),l=t+s,c=e+a,u=1^i,f=i?r-o:o-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+l+","+c:(Math.abs(this._x1-l)>nr||Math.abs(this._y1-c)>nr)&&(this._+="L"+l+","+c),n&&(f<0&&(f=f%er+er),f>rr?this._+="A"+n+","+n+",0,1,"+u+","+(t-s)+","+(e-a)+"A"+n+","+n+",0,1,"+u+","+(this._x1=l)+","+(this._y1=c):f>nr&&(this._+="A"+n+","+n+",0,"+ +(f>=tr)+","+u+","+(this._x1=t+n*Math.cos(o))+","+(this._y1=e+n*Math.sin(o))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};const sr=ir;var ar=Array.prototype.slice;function lr(t){return function(){return t}}function cr(t){return t.source}function ur(t){return t.target}function fr(t){return t.radius}function dr(t){return t.startAngle}function hr(t){return t.endAngle}function pr(){return 0}function mr(){return 10}function gr(t){var e=cr,n=ur,r=fr,o=fr,i=dr,s=hr,a=pr,l=null;function c(){var c,u=e.apply(this,arguments),f=n.apply(this,arguments),d=a.apply(this,arguments)/2,h=ar.call(arguments),p=+r.apply(this,(h[0]=u,h)),m=i.apply(this,h)-Un,g=s.apply(this,h)-Un,y=+o.apply(this,(h[0]=f,h)),v=i.apply(this,h)-Un,b=s.apply(this,h)-Un;if(l||(l=c=sr()),d>Hn&&(zn(g-m)>2*d+Hn?g>m?(m+=d,g-=d):(m-=d,g+=d):m=g=(m+g)/2,zn(b-v)>2*d+Hn?b>v?(v+=d,b-=d):(v-=d,b+=d):v=b=(v+b)/2),l.moveTo(p*Zn(m),p*$n(m)),l.arc(0,0,p,m,g),m!==v||g!==b)if(t){var _=y-+t.apply(this,arguments),w=(v+b)/2;l.quadraticCurveTo(0,0,_*Zn(v),_*$n(v)),l.lineTo(y*Zn(w),y*$n(w)),l.lineTo(_*Zn(b),_*$n(b))}else l.quadraticCurveTo(0,0,y*Zn(v),y*$n(v)),l.arc(0,0,y,v,b);if(l.quadraticCurveTo(0,0,p*Zn(m),p*$n(m)),l.closePath(),c)return l=null,c+""||null}return t&&(c.headRadius=function(e){return arguments.length?(t="function"==typeof e?e:lr(+e),c):t}),c.radius=function(t){return arguments.length?(r=o="function"==typeof t?t:lr(+t),c):r},c.sourceRadius=function(t){return arguments.length?(r="function"==typeof t?t:lr(+t),c):r},c.targetRadius=function(t){return arguments.length?(o="function"==typeof t?t:lr(+t),c):o},c.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:lr(+t),c):i},c.endAngle=function(t){return arguments.length?(s="function"==typeof t?t:lr(+t),c):s},c.padAngle=function(t){return arguments.length?(a="function"==typeof t?t:lr(+t),c):a},c.source=function(t){return arguments.length?(e=t,c):e},c.target=function(t){return arguments.length?(n=t,c):n},c.context=function(t){return arguments.length?(l=null==t?null:t,c):l},c}function yr(){return gr()}function vr(){return gr(mr)}var br=n(7346),_r=n(2327),wr=n(2038),xr=n(6106),kr=Array.prototype.slice;function qr(t,e){return t-e}const Nr=t=>()=>t;function Sr(t,e){for(var n,r=-1,o=e.length;++r<o;)if(n=Ar(t,e[r]))return n;return 0}function Ar(t,e){for(var n=e[0],r=e[1],o=-1,i=0,s=t.length,a=s-1;i<s;a=i++){var l=t[i],c=l[0],u=l[1],f=t[a],d=f[0],h=f[1];if(Mr(l,f,e))return 0;u>r!=h>r&&n<(d-c)*(r-u)/(h-u)+c&&(o=-o)}return o}function Mr(t,e,n){var r,o,i,s;return function(t,e,n){return(e[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(e[1]-t[1])}(t,e,n)&&(o=t[r=+(t[0]===e[0])],i=n[r],s=e[r],o<=i&&i<=s||s<=i&&i<=o)}function Tr(){}var Cr=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function jr(){var t=1,e=1,n=_r.Z,r=a;function o(t){var e=n(t);if(Array.isArray(e))e=e.slice().sort(qr);else{const n=(0,wr.Z)(t),r=(0,xr.ly)(n[0],n[1],e);e=(0,xr.ZP)(Math.floor(n[0]/r)*r,Math.floor(n[1]/r-1)*r,e)}return e.map((e=>i(t,e)))}function i(n,o){var i=[],a=[];return function(n,r,o){var i,a,l,c,u,f,d=new Array,h=new Array;i=a=-1,c=n[0]>=r,Cr[c<<1].forEach(p);for(;++i<t-1;)l=c,c=n[i+1]>=r,Cr[l|c<<1].forEach(p);Cr[c<<0].forEach(p);for(;++a<e-1;){for(i=-1,c=n[a*t+t]>=r,u=n[a*t]>=r,Cr[c<<1|u<<2].forEach(p);++i<t-1;)l=c,c=n[a*t+t+i+1]>=r,f=u,u=n[a*t+i+1]>=r,Cr[l|c<<1|u<<2|f<<3].forEach(p);Cr[c|u<<3].forEach(p)}i=-1,u=n[a*t]>=r,Cr[u<<2].forEach(p);for(;++i<t-1;)f=u,u=n[a*t+i+1]>=r,Cr[u<<2|f<<3].forEach(p);function p(t){var e,n,r=[t[0][0]+i,t[0][1]+a],l=[t[1][0]+i,t[1][1]+a],c=s(r),u=s(l);(e=h[c])?(n=d[u])?(delete h[e.end],delete d[n.start],e===n?(e.ring.push(l),o(e.ring)):d[e.start]=h[n.end]={start:e.start,end:n.end,ring:e.ring.concat(n.ring)}):(delete h[e.end],e.ring.push(l),h[e.end=u]=e):(e=d[u])?(n=h[c])?(delete d[e.start],delete h[n.end],e===n?(e.ring.push(l),o(e.ring)):d[n.start]=h[e.end]={start:n.start,end:e.end,ring:n.ring.concat(e.ring)}):(delete d[e.start],e.ring.unshift(r),d[e.start=c]=e):d[c]=h[u]={start:c,end:u,ring:[r,l]}}Cr[u<<3].forEach(p)}(n,o,(function(t){r(t,n,o),function(t){for(var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++e<n;)r+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return r}(t)>0?i.push([t]):a.push(t)})),a.forEach((function(t){for(var e,n=0,r=i.length;n<r;++n)if(-1!==Sr((e=i[n])[0],t))return void e.push(t)})),{type:"MultiPolygon",value:o,coordinates:i}}function s(e){return 2*e[0]+e[1]*(t+1)*4}function a(n,r,o){n.forEach((function(n){var i,s=n[0],a=n[1],l=0|s,c=0|a,u=r[c*t+l];s>0&&s<t&&l===s&&(i=r[c*t+l-1],n[0]=s+(o-i)/(u-i)-.5),a>0&&a<e&&c===a&&(i=r[(c-1)*t+l],n[1]=a+(o-i)/(u-i)-.5)}))}return o.contour=i,o.size=function(n){if(!arguments.length)return[t,e];var r=Math.floor(n[0]),i=Math.floor(n[1]);if(!(r>=0&&i>=0))throw new Error("invalid size");return t=r,e=i,o},o.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:Array.isArray(t)?Nr(kr.call(t)):Nr(t),o):n},o.smooth=function(t){return arguments.length?(r=t?a:Tr,o):r===a},o}var Or=n(1045),Er=n(8319);function Rr(t){return t[0]}function Ir(t){return t[1]}function Pr(){return 1}function Fr(){var t=Rr,e=Ir,n=Pr,r=960,o=500,i=20,s=2,a=3*i,l=r+2*a>>s,c=o+2*a>>s,u=Nr(20);function f(r){var o=new Float32Array(l*c),u=Math.pow(2,-s),f=-1;for(const i of r){var d=(t(i,++f,r)+a)*u,h=(e(i,f,r)+a)*u,p=+n(i,f,r);if(d>=0&&d<l&&h>=0&&h<c){var m=Math.floor(d),g=Math.floor(h),y=d-m-.5,v=h-g-.5;o[m+g*l]+=(1-y)*(1-v)*p,o[m+1+g*l]+=y*(1-v)*p,o[m+1+(g+1)*l]+=y*v*p,o[m+(g+1)*l]+=(1-y)*v*p}}return(0,Or.u8)({data:o,width:l,height:c},i*u),o}function d(t){var e=f(t),n=u(e),r=Math.pow(2,2*s);return Array.isArray(n)||(n=(0,xr.ZP)(Number.MIN_VALUE,(0,Er.Z)(e)/r,n)),jr().size([l,c]).thresholds(n.map((t=>t*r)))(e).map(((t,e)=>(t.value=+n[e],h(t))))}function h(t){return t.coordinates.forEach(p),t}function p(t){t.forEach(m)}function m(t){t.forEach(g)}function g(t){t[0]=t[0]*Math.pow(2,s)-a,t[1]=t[1]*Math.pow(2,s)-a}function y(){return l=r+2*(a=3*i)>>s,c=o+2*a>>s,d}return d.contours=function(t){var e=f(t),n=jr().size([l,c]),r=Math.pow(2,2*s),o=t=>{t=+t;var o=h(n.contour(e,t*r));return o.value=t,o};return Object.defineProperty(o,"max",{get:()=>(0,Er.Z)(e)/r}),o},d.x=function(e){return arguments.length?(t="function"==typeof e?e:Nr(+e),d):t},d.y=function(t){return arguments.length?(e="function"==typeof t?t:Nr(+t),d):e},d.weight=function(t){return arguments.length?(n="function"==typeof t?t:Nr(+t),d):n},d.size=function(t){if(!arguments.length)return[r,o];var e=+t[0],n=+t[1];if(!(e>=0&&n>=0))throw new Error("invalid size");return r=e,o=n,y()},d.cellSize=function(t){if(!arguments.length)return 1<<s;if(!((t=+t)>=1))throw new Error("invalid cell size");return s=Math.floor(Math.log(t)/Math.LN2),y()},d.thresholds=function(t){return arguments.length?(u="function"==typeof t?t:Array.isArray(t)?Nr(kr.call(t)):Nr(t),d):u},d.bandwidth=function(t){if(!arguments.length)return Math.sqrt(i*(i+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return i=(Math.sqrt(4*t*t+1)-1)/2,y()},d}const Lr=134217729,Dr=33306690738754706e-32;function Br(t,e,n,r,o){let i,s,a,l,c=e[0],u=r[0],f=0,d=0;u>c==u>-c?(i=c,c=e[++f]):(i=u,u=r[++d]);let h=0;if(f<t&&d<n)for(u>c==u>-c?(s=c+i,a=i-(s-c),c=e[++f]):(s=u+i,a=i-(s-u),u=r[++d]),i=s,0!==a&&(o[h++]=a);f<t&&d<n;)u>c==u>-c?(s=i+c,l=s-i,a=i-(s-l)+(c-l),c=e[++f]):(s=i+u,l=s-i,a=i-(s-l)+(u-l),u=r[++d]),i=s,0!==a&&(o[h++]=a);for(;f<t;)s=i+c,l=s-i,a=i-(s-l)+(c-l),c=e[++f],i=s,0!==a&&(o[h++]=a);for(;d<n;)s=i+u,l=s-i,a=i-(s-l)+(u-l),u=r[++d],i=s,0!==a&&(o[h++]=a);return 0===i&&0!==h||(o[h++]=i),h}function zr(t){return new Float64Array(t)}const Zr=22204460492503146e-32,$r=11093356479670487e-47,Gr=zr(4),Ur=zr(8),Jr=zr(12),Wr=zr(16),Hr=zr(4);function Vr(t,e,n,r,o,i){const s=(e-i)*(n-o),a=(t-o)*(r-i),l=s-a;if(0===s||0===a||s>0!=a>0)return l;const c=Math.abs(s+a);return Math.abs(l)>=33306690738754716e-32*c?l:-function(t,e,n,r,o,i,s){let a,l,c,u,f,d,h,p,m,g,y,v,b,_,w,x,k,q;const N=t-o,S=n-o,A=e-i,M=r-i;_=N*M,d=Lr*N,h=d-(d-N),p=N-h,d=Lr*M,m=d-(d-M),g=M-m,w=p*g-(_-h*m-p*m-h*g),x=A*S,d=Lr*A,h=d-(d-A),p=A-h,d=Lr*S,m=d-(d-S),g=S-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Gr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Gr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Gr[2]=v-(q-f)+(y-f),Gr[3]=q;let T=function(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}(4,Gr),C=Zr*s;if(T>=C||-T>=C)return T;if(f=t-N,a=t-(N+f)+(f-o),f=n-S,c=n-(S+f)+(f-o),f=e-A,l=e-(A+f)+(f-i),f=r-M,u=r-(M+f)+(f-i),0===a&&0===l&&0===c&&0===u)return T;if(C=$r*s+Dr*Math.abs(T),T+=N*u+M*a-(A*c+S*l),T>=C||-T>=C)return T;_=a*M,d=Lr*a,h=d-(d-a),p=a-h,d=Lr*M,m=d-(d-M),g=M-m,w=p*g-(_-h*m-p*m-h*g),x=l*S,d=Lr*l,h=d-(d-l),p=l-h,d=Lr*S,m=d-(d-S),g=S-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Hr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Hr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Hr[2]=v-(q-f)+(y-f),Hr[3]=q;const j=Br(4,Gr,4,Hr,Ur);_=N*u,d=Lr*N,h=d-(d-N),p=N-h,d=Lr*u,m=d-(d-u),g=u-m,w=p*g-(_-h*m-p*m-h*g),x=A*c,d=Lr*A,h=d-(d-A),p=A-h,d=Lr*c,m=d-(d-c),g=c-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Hr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Hr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Hr[2]=v-(q-f)+(y-f),Hr[3]=q;const O=Br(j,Ur,4,Hr,Jr);_=a*u,d=Lr*a,h=d-(d-a),p=a-h,d=Lr*u,m=d-(d-u),g=u-m,w=p*g-(_-h*m-p*m-h*g),x=l*c,d=Lr*l,h=d-(d-l),p=l-h,d=Lr*c,m=d-(d-c),g=c-m,k=p*g-(x-h*m-p*m-h*g),y=w-k,f=w-y,Hr[0]=w-(y+f)+(f-k),v=_+y,f=v-_,b=_-(v-f)+(y-f),y=b-x,f=b-y,Hr[1]=b-(y+f)+(f-x),q=v+y,f=q-v,Hr[2]=v-(q-f)+(y-f),Hr[3]=q;const E=Br(O,Jr,4,Hr,Wr);return Wr[E-1]}(t,e,n,r,o,i,c)}zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(8),zr(8),zr(8),zr(4),zr(8),zr(8),zr(8),zr(12);zr(192),zr(192);zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(8),zr(8),zr(8),zr(8),zr(8),zr(8),zr(8),zr(8),zr(8),zr(4),zr(4),zr(4),zr(8),zr(16),zr(16),zr(16),zr(32),zr(32),zr(48),zr(64);zr(1152),zr(1152);zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(4),zr(24),zr(24),zr(24),zr(24),zr(24),zr(24),zr(24),zr(24),zr(24),zr(24),zr(1152),zr(1152),zr(1152),zr(1152),zr(1152),zr(2304),zr(2304),zr(3456),zr(5760),zr(8),zr(8),zr(8),zr(16),zr(24),zr(48),zr(48),zr(96),zr(192),zr(384),zr(384),zr(384),zr(768);zr(96),zr(96),zr(96),zr(1152);const Yr=Math.pow(2,-52),Qr=new Uint32Array(512);class Kr{static from(t,e=oo,n=io){const r=t.length,o=new Float64Array(2*r);for(let i=0;i<r;i++){const r=t[i];o[2*i]=e(r),o[2*i+1]=n(r)}return new Kr(o)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const n=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*n),this._halfedges=new Int32Array(3*n),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:r,_hullHash:o}=this,i=t.length>>1;let s=1/0,a=1/0,l=-1/0,c=-1/0;for(let e=0;e<i;e++){const n=t[2*e],r=t[2*e+1];n<s&&(s=n),r<a&&(a=r),n>l&&(l=n),r>c&&(c=r),this._ids[e]=e}const u=(s+l)/2,f=(a+c)/2;let d,h,p,m=1/0;for(let e=0;e<i;e++){const n=Xr(u,f,t[2*e],t[2*e+1]);n<m&&(d=e,m=n)}const g=t[2*d],y=t[2*d+1];m=1/0;for(let e=0;e<i;e++){if(e===d)continue;const n=Xr(g,y,t[2*e],t[2*e+1]);n<m&&n>0&&(h=e,m=n)}let v=t[2*h],b=t[2*h+1],_=1/0;for(let e=0;e<i;e++){if(e===d||e===h)continue;const n=eo(g,y,v,b,t[2*e],t[2*e+1]);n<_&&(p=e,_=n)}let w=t[2*p],x=t[2*p+1];if(_===1/0){for(let e=0;e<i;e++)this._dists[e]=t[2*e]-t[0]||t[2*e+1]-t[1];no(this._ids,this._dists,0,i-1);const e=new Uint32Array(i);let n=0;for(let t=0,r=-1/0;t<i;t++){const o=this._ids[t];this._dists[o]>r&&(e[n++]=o,r=this._dists[o])}return this.hull=e.subarray(0,n),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(Vr(g,y,v,b,w,x)<0){const t=h,e=v,n=b;h=p,v=w,b=x,p=t,w=e,x=n}const k=function(t,e,n,r,o,i){const s=n-t,a=r-e,l=o-t,c=i-e,u=s*s+a*a,f=l*l+c*c,d=.5/(s*c-a*l),h=t+(c*u-a*f)*d,p=e+(s*f-l*u)*d;return{x:h,y:p}}(g,y,v,b,w,x);this._cx=k.x,this._cy=k.y;for(let e=0;e<i;e++)this._dists[e]=Xr(t[2*e],t[2*e+1],k.x,k.y);no(this._ids,this._dists,0,i-1),this._hullStart=d;let q=3;n[d]=e[p]=h,n[h]=e[d]=p,n[p]=e[h]=d,r[d]=0,r[h]=1,r[p]=2,o.fill(-1),o[this._hashKey(g,y)]=d,o[this._hashKey(v,b)]=h,o[this._hashKey(w,x)]=p,this.trianglesLen=0,this._addTriangle(d,h,p,-1,-1,-1);for(let i,s,a=0;a<this._ids.length;a++){const l=this._ids[a],c=t[2*l],u=t[2*l+1];if(a>0&&Math.abs(c-i)<=Yr&&Math.abs(u-s)<=Yr)continue;if(i=c,s=u,l===d||l===h||l===p)continue;let f=0;for(let t=0,e=this._hashKey(c,u);t<this._hashSize&&(f=o[(e+t)%this._hashSize],-1===f||f===n[f]);t++);f=e[f];let m,g=f;for(;m=n[g],Vr(c,u,t[2*g],t[2*g+1],t[2*m],t[2*m+1])>=0;)if(g=m,g===f){g=-1;break}if(-1===g)continue;let y=this._addTriangle(g,l,n[g],-1,-1,r[g]);r[l]=this._legalize(y+2),r[g]=y,q++;let v=n[g];for(;m=n[v],Vr(c,u,t[2*v],t[2*v+1],t[2*m],t[2*m+1])<0;)y=this._addTriangle(v,l,m,r[l],-1,r[v]),r[l]=this._legalize(y+2),n[v]=v,q--,v=m;if(g===f)for(;m=e[g],Vr(c,u,t[2*m],t[2*m+1],t[2*g],t[2*g+1])<0;)y=this._addTriangle(m,l,g,-1,r[g],r[m]),this._legalize(y+2),r[m]=y,n[g]=g,q--,g=m;this._hullStart=e[l]=g,n[g]=e[v]=l,n[l]=v,o[this._hashKey(c,u)]=l,o[this._hashKey(t[2*g],t[2*g+1])]=g}this.hull=new Uint32Array(q);for(let t=0,e=this._hullStart;t<q;t++)this.hull[t]=e,e=n[e];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:n,coords:r}=this;let o=0,i=0;for(;;){const s=n[t],a=t-t%3;if(i=a+(t+2)%3,-1===s){if(0===o)break;t=Qr[--o];continue}const l=s-s%3,c=a+(t+1)%3,u=l+(s+2)%3,f=e[i],d=e[t],h=e[c],p=e[u];if(to(r[2*f],r[2*f+1],r[2*d],r[2*d+1],r[2*h],r[2*h+1],r[2*p],r[2*p+1])){e[t]=p,e[s]=f;const r=n[u];if(-1===r){let e=this._hullStart;do{if(this._hullTri[e]===u){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,r),this._link(s,n[i]),this._link(i,u);const a=l+(s+1)%3;o<Qr.length&&(Qr[o++]=a)}else{if(0===o)break;t=Qr[--o]}}return i}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,n,r,o,i){const s=this.trianglesLen;return this._triangles[s]=t,this._triangles[s+1]=e,this._triangles[s+2]=n,this._link(s,r),this._link(s+1,o),this._link(s+2,i),this.trianglesLen+=3,s}}function Xr(t,e,n,r){const o=t-n,i=e-r;return o*o+i*i}function to(t,e,n,r,o,i,s,a){const l=t-s,c=e-a,u=n-s,f=r-a,d=o-s,h=i-a,p=u*u+f*f,m=d*d+h*h;return l*(f*m-p*h)-c*(u*m-p*d)+(l*l+c*c)*(u*h-f*d)<0}function eo(t,e,n,r,o,i){const s=n-t,a=r-e,l=o-t,c=i-e,u=s*s+a*a,f=l*l+c*c,d=.5/(s*c-a*l),h=(c*u-a*f)*d,p=(s*f-l*u)*d;return h*h+p*p}function no(t,e,n,r){if(r-n<=20)for(let o=n+1;o<=r;o++){const r=t[o],i=e[r];let s=o-1;for(;s>=n&&e[t[s]]>i;)t[s+1]=t[s--];t[s+1]=r}else{let o=n+1,i=r;ro(t,n+r>>1,o),e[t[n]]>e[t[r]]&&ro(t,n,r),e[t[o]]>e[t[r]]&&ro(t,o,r),e[t[n]]>e[t[o]]&&ro(t,n,o);const s=t[o],a=e[s];for(;;){do{o++}while(e[t[o]]<a);do{i--}while(e[t[i]]>a);if(i<o)break;ro(t,o,i)}t[n+1]=t[i],t[i]=s,r-o+1>=i-n?(no(t,e,o,r),no(t,e,n,i-1)):(no(t,e,n,i-1),no(t,e,o,r))}}function ro(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function oo(t){return t[0]}function io(t){return t[1]}const so=1e-6;class ao{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,n){const r=(t=+t)+(n=+n),o=e=+e;if(n<0)throw new Error("negative radius");null===this._x1?this._+=`M${r},${o}`:(Math.abs(this._x1-r)>so||Math.abs(this._y1-o)>so)&&(this._+="L"+r+","+o),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=r},${this._y1=o}`)}rect(t,e,n,r){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+r}h${-n}Z`}value(){return this._||null}}class lo{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class co{constructor(t,[e,n,r,o]=[0,0,960,500]){if(!((r=+r)>=(e=+e)&&(o=+o)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=r,this.xmin=e,this.ymax=o,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:r}=this,o=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let e,r,i=0,s=0,a=n.length;i<a;i+=3,s+=2){const a=2*n[i],l=2*n[i+1],c=2*n[i+2],u=t[a],f=t[a+1],d=t[l],h=t[l+1],p=t[c],m=t[c+1],g=d-u,y=h-f,v=p-u,b=m-f,_=2*(g*b-y*v);if(Math.abs(_)<1e-9){let o=1e9;const i=2*n[0];o*=Math.sign((t[i]-u)*b-(t[i+1]-f)*v),e=(u+p)/2-o*b,r=(f+m)/2+o*v}else{const t=1/_,n=g*g+y*y,o=v*v+b*b;e=u+(b*n-y*o)*t,r=f+(g*o-v*n)*t}o[s]=e,o[s+1]=r}let i,s,a,l=e[e.length-1],c=4*l,u=t[2*l],f=t[2*l+1];r.fill(0);for(let n=0;n<e.length;++n)l=e[n],i=c,s=u,a=f,c=4*l,u=t[2*l],f=t[2*l+1],r[i+2]=r[c]=a-f,r[i+3]=r[c+1]=u-s}render(t){const e=null==t?t=new ao:void 0,{delaunay:{halfedges:n,inedges:r,hull:o},circumcenters:i,vectors:s}=this;if(o.length<=1)return null;for(let e=0,r=n.length;e<r;++e){const r=n[e];if(r<e)continue;const o=2*Math.floor(e/3),s=2*Math.floor(r/3),a=i[o],l=i[o+1],c=i[s],u=i[s+1];this._renderSegment(a,l,c,u,t)}let a,l=o[o.length-1];for(let e=0;e<o.length;++e){a=l,l=o[e];const n=2*Math.floor(r[l]/3),c=i[n],u=i[n+1],f=4*a,d=this._project(c,u,s[f+2],s[f+3]);d&&this._renderSegment(c,u,d[0],d[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new ao:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=null==e?e=new ao:void 0,r=this._clip(t);if(null===r||!r.length)return;e.moveTo(r[0],r[1]);let o=r.length;for(;r[0]===r[o-2]&&r[1]===r[o-1]&&o>1;)o-=2;for(let t=2;t<o;t+=2)r[t]===r[t-2]&&r[t+1]===r[t-1]||e.lineTo(r[t],r[t+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const t=this.cellPolygon(e);t&&(t.index=e,yield t)}}cellPolygon(t){const e=new lo;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,r,o){let i;const s=this._regioncode(t,e),a=this._regioncode(n,r);0===s&&0===a?(o.moveTo(t,e),o.lineTo(n,r)):(i=this._clipSegment(t,e,n,r,s,a))&&(o.moveTo(i[0],i[1]),o.lineTo(i[2],i[3]))}contains(t,e,n){return(e=+e)==e&&(n=+n)==n&&this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const t=this._clip(n);if(t)t:for(let r=0,o=e.length;r<o;r+=2)for(let i=0,s=t.length;i<s;i+=2)if(e[r]==t[i]&&e[r+1]==t[i+1]&&e[(r+2)%o]==t[(i+s-2)%s]&&e[(r+3)%o]==t[(i+s-1)%s]){yield n;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:r,triangles:o}}=this,i=n[t];if(-1===i)return null;const s=[];let a=i;do{const n=Math.floor(a/3);if(s.push(e[2*n],e[2*n+1]),a=a%3==2?a-2:a+1,o[a]!==t)break;a=r[a]}while(a!==i&&-1!==a);return s}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:n}=this,r=4*t;return n[r]||n[r+1]?this._clipInfinite(t,e,n[r],n[r+1],n[r+2],n[r+3]):this._clipFinite(t,e)}_clipFinite(t,e){const n=e.length;let r,o,i,s,a=null,l=e[n-2],c=e[n-1],u=this._regioncode(l,c),f=0;for(let d=0;d<n;d+=2)if(r=l,o=c,l=e[d],c=e[d+1],i=u,u=this._regioncode(l,c),0===i&&0===u)s=f,f=0,a?a.push(l,c):a=[l,c];else{let e,n,d,h,p;if(0===i){if(null===(e=this._clipSegment(r,o,l,c,i,u)))continue;[n,d,h,p]=e}else{if(null===(e=this._clipSegment(l,c,r,o,u,i)))continue;[h,p,n,d]=e,s=f,f=this._edgecode(n,d),s&&f&&this._edge(t,s,f,a,a.length),a?a.push(n,d):a=[n,d]}s=f,f=this._edgecode(h,p),s&&f&&this._edge(t,s,f,a,a.length),a?a.push(h,p):a=[h,p]}if(a)s=f,f=this._edgecode(a[0],a[1]),s&&f&&this._edge(t,s,f,a,a.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return a}_clipSegment(t,e,n,r,o,i){for(;;){if(0===o&&0===i)return[t,e,n,r];if(o&i)return null;let s,a,l=o||i;8&l?(s=t+(n-t)*(this.ymax-e)/(r-e),a=this.ymax):4&l?(s=t+(n-t)*(this.ymin-e)/(r-e),a=this.ymin):2&l?(a=e+(r-e)*(this.xmax-t)/(n-t),s=this.xmax):(a=e+(r-e)*(this.xmin-t)/(n-t),s=this.xmin),o?(t=s,e=a,o=this._regioncode(t,e)):(n=s,r=a,i=this._regioncode(n,r))}}_clipInfinite(t,e,n,r,o,i){let s,a=Array.from(e);if((s=this._project(a[0],a[1],n,r))&&a.unshift(s[0],s[1]),(s=this._project(a[a.length-2],a[a.length-1],o,i))&&a.push(s[0],s[1]),a=this._clipFinite(t,a))for(let e,n=0,r=a.length,o=this._edgecode(a[r-2],a[r-1]);n<r;n+=2)e=o,o=this._edgecode(a[n],a[n+1]),e&&o&&(n=this._edge(t,e,o,a,n),r=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,n,r,o){for(;e!==n;){let n,i;switch(e){case 5:e=4;continue;case 4:e=6,n=this.xmax,i=this.ymin;break;case 6:e=2;continue;case 2:e=10,n=this.xmax,i=this.ymax;break;case 10:e=8;continue;case 8:e=9,n=this.xmin,i=this.ymax;break;case 9:e=1;continue;case 1:e=5,n=this.xmin,i=this.ymin}r[o]===n&&r[o+1]===i||!this.contains(t,n,i)||(r.splice(o,0,n,i),o+=2)}if(r.length>4)for(let t=0;t<r.length;t+=2){const e=(t+2)%r.length,n=(t+4)%r.length;(r[t]===r[e]&&r[e]===r[n]||r[t+1]===r[e+1]&&r[e+1]===r[n+1])&&(r.splice(e,2),t-=2)}return o}_project(t,e,n,r){let o,i,s,a=1/0;if(r<0){if(e<=this.ymin)return null;(o=(this.ymin-e)/r)<a&&(s=this.ymin,i=t+(a=o)*n)}else if(r>0){if(e>=this.ymax)return null;(o=(this.ymax-e)/r)<a&&(s=this.ymax,i=t+(a=o)*n)}if(n>0){if(t>=this.xmax)return null;(o=(this.xmax-t)/n)<a&&(i=this.xmax,s=e+(a=o)*r)}else if(n<0){if(t<=this.xmin)return null;(o=(this.xmin-t)/n)<a&&(i=this.xmin,s=e+(a=o)*r)}return[i,s]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const uo=2*Math.PI,fo=Math.pow;function ho(t){return t[0]}function po(t){return t[1]}function mo(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class go{static from(t,e=ho,n=po,r){return new go("length"in t?function(t,e,n,r){const o=t.length,i=new Float64Array(2*o);for(let s=0;s<o;++s){const o=t[s];i[2*s]=e.call(r,o,s,t),i[2*s+1]=n.call(r,o,s,t)}return i}(t,e,n,r):Float64Array.from(function*(t,e,n,r){let o=0;for(const i of t)yield e.call(r,i,o,t),yield n.call(r,i,o,t),++o}(t,e,n,r)))}constructor(t){this._delaunator=new Kr(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:n}=t;for(let t=0;t<e.length;t+=3){const r=2*e[t],o=2*e[t+1],i=2*e[t+2];if((n[i]-n[r])*(n[o+1]-n[r+1])-(n[o]-n[r])*(n[i+1]-n[r+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},((t,e)=>e)).sort(((t,n)=>e[2*t]-e[2*n]||e[2*t+1]-e[2*n+1]));const t=this.collinear[0],n=this.collinear[this.collinear.length-1],r=[e[2*t],e[2*t+1],e[2*n],e[2*n+1]],o=1e-8*Math.hypot(r[3]-r[1],r[2]-r[0]);for(let t=0,n=e.length/2;t<n;++t){const n=mo(e[2*t],e[2*t+1],o);e[2*t]=n[0],e[2*t+1]=n[1]}this._delaunator=new Kr(e)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,o=this.triangles=this._delaunator.triangles,i=this.inedges.fill(-1),s=this._hullIndex.fill(-1);for(let t=0,e=n.length;t<e;++t){const e=o[t%3==2?t-2:t+1];-1!==n[t]&&-1!==i[e]||(i[e]=t)}for(let t=0,e=r.length;t<e;++t)s[r[t]]=t;r.length<=2&&r.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=r[0],i[r[0]]=1,2===r.length&&(i[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(t){return new co(this,t)}*neighbors(t){const{inedges:e,hull:n,_hullIndex:r,halfedges:o,triangles:i,collinear:s}=this;if(s){const e=s.indexOf(t);return e>0&&(yield s[e-1]),void(e<s.length-1&&(yield s[e+1]))}const a=e[t];if(-1===a)return;let l=a,c=-1;do{if(yield c=i[l],l=l%3==2?l-2:l+1,i[l]!==t)return;if(l=o[l],-1===l){const e=n[(r[t]+1)%n.length];return void(e!==c&&(yield e))}}while(l!==a)}find(t,e,n=0){if((t=+t)!=t||(e=+e)!=e)return-1;const r=n;let o;for(;(o=this._step(n,t,e))>=0&&o!==n&&o!==r;)n=o;return o}_step(t,e,n){const{inedges:r,hull:o,_hullIndex:i,halfedges:s,triangles:a,points:l}=this;if(-1===r[t]||!l.length)return(t+1)%(l.length>>1);let c=t,u=fo(e-l[2*t],2)+fo(n-l[2*t+1],2);const f=r[t];let d=f;do{let r=a[d];const f=fo(e-l[2*r],2)+fo(n-l[2*r+1],2);if(f<u&&(u=f,c=r),d=d%3==2?d-2:d+1,a[d]!==t)break;if(d=s[d],-1===d){if(d=o[(i[t]+1)%o.length],d!==r&&fo(e-l[2*d],2)+fo(n-l[2*d+1],2)<u)return d;break}}while(d!==f);return c}render(t){const e=null==t?t=new ao:void 0,{points:n,halfedges:r,triangles:o}=this;for(let e=0,i=r.length;e<i;++e){const i=r[e];if(i<e)continue;const s=2*o[e],a=2*o[i];t.moveTo(n[s],n[s+1]),t.lineTo(n[a],n[a+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){void 0!==e||t&&"function"==typeof t.moveTo||(e=t,t=null),e=null==e?2:+e;const n=null==t?t=new ao:void 0,{points:r}=this;for(let n=0,o=r.length;n<o;n+=2){const o=r[n],i=r[n+1];t.moveTo(o+e,i),t.arc(o,i,e,0,uo)}return n&&n.value()}renderHull(t){const e=null==t?t=new ao:void 0,{hull:n,points:r}=this,o=2*n[0],i=n.length;t.moveTo(r[o],r[o+1]);for(let e=1;e<i;++e){const o=2*n[e];t.lineTo(r[o],r[o+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new lo;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new ao:void 0,{points:r,triangles:o}=this,i=2*o[t*=3],s=2*o[t+1],a=2*o[t+2];return e.moveTo(r[i],r[i+1]),e.lineTo(r[s],r[s+1]),e.lineTo(r[a],r[a+1]),e.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,n=t.length/3;e<n;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new lo;return this.renderTriangle(t,e),e.value()}}const yo=t=>()=>t;function vo(t,{sourceEvent:e,subject:n,target:r,identifier:o,active:i,x:s,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}function bo(t){return!t.ctrlKey&&!t.button}function _o(){return this.parentNode}function wo(t,e){return null==e?{x:t.x,y:t.y}:e}function xo(){return navigator.maxTouchPoints||"ontouchstart"in this}function ko(){var t,e,n,r,o=bo,i=_o,s=wo,a=xo,l={},c=N("start","drag","end"),u=0,f=0;function d(t){t.on("mousedown.drag",h).filter(a).on("touchstart.drag",g).on("touchmove.drag",y,Bt).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(s,a){if(!r&&o.call(this,s,a)){var l=b(this,i.call(this,s,a),s,a,"mouse");l&&(Dt(s.view).on("mousemove.drag",p,zt).on("mouseup.drag",m,zt),Gt(s.view),Zt(s),n=!1,t=s.clientX,e=s.clientY,l("start",s))}}function p(r){if($t(r),!n){var o=r.clientX-t,i=r.clientY-e;n=o*o+i*i>f}l.mouse("drag",r)}function m(t){Dt(t.view).on("mousemove.drag mouseup.drag",null),Ut(t.view,n),$t(t),l.mouse("end",t)}function g(t,e){if(o.call(this,t,e)){var n,r,s=t.changedTouches,a=i.call(this,t,e),l=s.length;for(n=0;n<l;++n)(r=b(this,a,t,e,s[n].identifier,s[n]))&&(Zt(t),r("start",t,s[n]))}}function y(t){var e,n,r=t.changedTouches,o=r.length;for(e=0;e<o;++e)(n=l[r[e].identifier])&&($t(t),n("drag",t,r[e]))}function v(t){var e,n,o=t.changedTouches,i=o.length;for(r&&clearTimeout(r),r=setTimeout((function(){r=null}),500),e=0;e<i;++e)(n=l[o[e].identifier])&&(Zt(t),n("end",t,o[e]))}function b(t,e,n,r,o,i){var a,f,h,p=c.copy(),m=Ht(i||n,e);if(null!=(h=s.call(t,new vo("beforestart",{sourceEvent:n,target:d,identifier:o,active:u,x:m[0],y:m[1],dx:0,dy:0,dispatch:p}),r)))return a=h.x-m[0]||0,f=h.y-m[1]||0,function n(i,s,c){var g,y=m;switch(i){case"start":l[o]=n,g=u++;break;case"end":delete l[o],--u;case"drag":m=Ht(c||s,e),g=u}p.call(i,t,new vo(i,{sourceEvent:s,subject:h,target:d,identifier:o,active:g,x:m[0]+a,y:m[1]+f,dx:m[0]-y[0],dy:m[1]-y[1],dispatch:p}),r)}}return d.filter=function(t){return arguments.length?(o="function"==typeof t?t:yo(!!t),d):o},d.container=function(t){return arguments.length?(i="function"==typeof t?t:yo(t),d):i},d.subject=function(t){return arguments.length?(s="function"==typeof t?t:yo(t),d):s},d.touchable=function(t){return arguments.length?(a="function"==typeof t?t:yo(!!t),d):a},d.on=function(){var t=c.on.apply(c,arguments);return t===c?d:t},d.clickDistance=function(t){return arguments.length?(f=(t=+t)*t,d):Math.sqrt(f)},d}vo.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};var qo=n(2884);const No=t=>+t;function So(t){return t*t}function Ao(t){return t*(2-t)}function Mo(t){return((t*=2)<=1?t*t:--t*(2-t)+1)/2}var To=function t(e){function n(t){return Math.pow(t,e)}return e=+e,n.exponent=t,n}(3),Co=function t(e){function n(t){return 1-Math.pow(1-t,e)}return e=+e,n.exponent=t,n}(3),jo=function t(e){function n(t){return((t*=2)<=1?Math.pow(t,e):2-Math.pow(2-t,e))/2}return e=+e,n.exponent=t,n}(3),Oo=Math.PI,Eo=Oo/2;function Ro(t){return 1==+t?1:1-Math.cos(t*Eo)}function Io(t){return Math.sin(t*Eo)}function Po(t){return(1-Math.cos(Oo*t))/2}function Fo(t){return 1.0009775171065494*(Math.pow(2,-10*t)-.0009765625)}function Lo(t){return Fo(1-+t)}function Do(t){return 1-Fo(t)}function Bo(t){return((t*=2)<=1?Fo(1-t):2-Fo(t-1))/2}function zo(t){return 1-Math.sqrt(1-t*t)}function Zo(t){return Math.sqrt(1- --t*t)}function $o(t){return((t*=2)<=1?1-Math.sqrt(1-t*t):Math.sqrt(1-(t-=2)*t)+1)/2}var Go=4/11,Uo=6/11,Jo=8/11,Wo=3/4,Ho=9/11,Vo=10/11,Yo=15/16,Qo=21/22,Ko=63/64,Xo=1/Go/Go;function ti(t){return 1-ei(1-t)}function ei(t){return(t=+t)<Go?Xo*t*t:t<Jo?Xo*(t-=Uo)*t+Wo:t<Vo?Xo*(t-=Ho)*t+Yo:Xo*(t-=Qo)*t+Ko}function ni(t){return((t*=2)<=1?1-ei(1-t):ei(t-1)+1)/2}var ri=1.70158,oi=function t(e){function n(t){return(t=+t)*t*(e*(t-1)+t)}return e=+e,n.overshoot=t,n}(ri),ii=function t(e){function n(t){return--t*t*((t+1)*e+t)+1}return e=+e,n.overshoot=t,n}(ri),si=function t(e){function n(t){return((t*=2)<1?t*t*((e+1)*t-e):(t-=2)*t*((e+1)*t+e)+2)/2}return e=+e,n.overshoot=t,n}(ri),ai=2*Math.PI,li=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=ai);function o(t){return e*Fo(- --t)*Math.sin((r-t)/n)}return o.amplitude=function(e){return t(e,n*ai)},o.period=function(n){return t(e,n)},o}(1,.3),ci=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=ai);function o(t){return 1-e*Fo(t=+t)*Math.sin((t+r)/n)}return o.amplitude=function(e){return t(e,n*ai)},o.period=function(n){return t(e,n)},o}(1,.3),ui=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=ai);function o(t){return((t=2*t-1)<0?e*Fo(-t)*Math.sin((r-t)/n):2-e*Fo(t)*Math.sin((r+t)/n))/2}return o.amplitude=function(e){return t(e,n*ai)},o.period=function(n){return t(e,n)},o}(1,.3);function fi(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.blob()}function di(t,e){return fetch(t,e).then(fi)}function hi(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.arrayBuffer()}function pi(t,e){return fetch(t,e).then(hi)}var mi=n(4476),gi=n(9106),yi=n(5026);function vi(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function bi(t,e){return fetch(t,e).then(vi)}function _i(t){return function(e,n,r){return 2===arguments.length&&"function"==typeof n&&(r=n,n=void 0),bi(e,n).then((function(e){return t(e,r)}))}}function wi(t,e,n,r){3===arguments.length&&"function"==typeof n&&(r=n,n=void 0);var o=(0,mi.Z)(t);return bi(e,n).then((function(t){return o.parse(t,r)}))}var xi=_i(gi.ue),ki=_i(yi.tJ);function qi(t,e){return new Promise((function(n,r){var o=new Image;for(var i in e)o[i]=e[i];o.onerror=r,o.onload=function(){n(o)},o.src=t}))}function Ni(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);if(204!==t.status&&205!==t.status)return t.json()}function Si(t,e){return fetch(t,e).then(Ni)}function Ai(t){return(e,n)=>bi(e,n).then((e=>(new DOMParser).parseFromString(e,t)))}const Mi=Ai("application/xml");var Ti=Ai("text/html"),Ci=Ai("image/svg+xml");function ji(t,e){var n,r=1;function o(){var o,i,s=n.length,a=0,l=0;for(o=0;o<s;++o)a+=(i=n[o]).x,l+=i.y;for(a=(a/s-t)*r,l=(l/s-e)*r,o=0;o<s;++o)(i=n[o]).x-=a,i.y-=l}return null==t&&(t=0),null==e&&(e=0),o.initialize=function(t){n=t},o.x=function(e){return arguments.length?(t=+e,o):t},o.y=function(t){return arguments.length?(e=+t,o):e},o.strength=function(t){return arguments.length?(r=+t,o):r},o}function Oi(t,e,n,r){if(isNaN(e)||isNaN(n))return t;var o,i,s,a,l,c,u,f,d,h=t._root,p={data:r},m=t._x0,g=t._y0,y=t._x1,v=t._y1;if(!h)return t._root=p,t;for(;h.length;)if((c=e>=(i=(m+y)/2))?m=i:y=i,(u=n>=(s=(g+v)/2))?g=s:v=s,o=h,!(h=h[f=u<<1|c]))return o[f]=p,t;if(a=+t._x.call(null,h.data),l=+t._y.call(null,h.data),e===a&&n===l)return p.next=h,o?o[f]=p:t._root=p,t;do{o=o?o[f]=new Array(4):t._root=new Array(4),(c=e>=(i=(m+y)/2))?m=i:y=i,(u=n>=(s=(g+v)/2))?g=s:v=s}while((f=u<<1|c)==(d=(l>=s)<<1|a>=i));return o[d]=h,o[f]=p,t}function Ei(t,e,n,r,o){this.node=t,this.x0=e,this.y0=n,this.x1=r,this.y1=o}function Ri(t){return t[0]}function Ii(t){return t[1]}function Pi(t,e,n){var r=new Fi(null==e?Ri:e,null==n?Ii:n,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Fi(t,e,n,r,o,i){this._x=t,this._y=e,this._x0=n,this._y0=r,this._x1=o,this._y1=i,this._root=void 0}function Li(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var Di=Pi.prototype=Fi.prototype;function Bi(t){return function(){return t}}function zi(t){return 1e-6*(t()-.5)}function Zi(t){return t.x+t.vx}function $i(t){return t.y+t.vy}function Gi(t){var e,n,r,o=1,i=1;function s(){for(var t,s,l,c,u,f,d,h=e.length,p=0;p<i;++p)for(s=Pi(e,Zi,$i).visitAfter(a),t=0;t<h;++t)l=e[t],f=n[l.index],d=f*f,c=l.x+l.vx,u=l.y+l.vy,s.visit(m);function m(t,e,n,i,s){var a=t.data,h=t.r,p=f+h;if(!a)return e>c+p||i<c-p||n>u+p||s<u-p;if(a.index>l.index){var m=c-a.x-a.vx,g=u-a.y-a.vy,y=m*m+g*g;y<p*p&&(0===m&&(y+=(m=zi(r))*m),0===g&&(y+=(g=zi(r))*g),y=(p-(y=Math.sqrt(y)))/y*o,l.vx+=(m*=y)*(p=(h*=h)/(d+h)),l.vy+=(g*=y)*p,a.vx-=m*(p=1-p),a.vy-=g*p)}}}function a(t){if(t.data)return t.r=n[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function l(){if(e){var r,o,i=e.length;for(n=new Array(i),r=0;r<i;++r)o=e[r],n[o.index]=+t(o,r,e)}}return"function"!=typeof t&&(t=Bi(null==t?1:+t)),s.initialize=function(t,n){e=t,r=n,l()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:Bi(+e),l(),s):t},s}function Ui(t){return t.index}function Ji(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function Wi(t){var e,n,r,o,i,s,a=Ui,l=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},c=Bi(30),u=1;function f(r){for(var o=0,a=t.length;o<u;++o)for(var l,c,f,d,h,p,m,g=0;g<a;++g)c=(l=t[g]).source,d=(f=l.target).x+f.vx-c.x-c.vx||zi(s),h=f.y+f.vy-c.y-c.vy||zi(s),d*=p=((p=Math.sqrt(d*d+h*h))-n[g])/p*r*e[g],h*=p,f.vx-=d*(m=i[g]),f.vy-=h*m,c.vx+=d*(m=1-m),c.vy+=h*m}function d(){if(r){var s,l,c=r.length,u=t.length,f=new Map(r.map(((t,e)=>[a(t,e,r),t])));for(s=0,o=new Array(c);s<u;++s)(l=t[s]).index=s,"object"!=typeof l.source&&(l.source=Ji(f,l.source)),"object"!=typeof l.target&&(l.target=Ji(f,l.target)),o[l.source.index]=(o[l.source.index]||0)+1,o[l.target.index]=(o[l.target.index]||0)+1;for(s=0,i=new Array(u);s<u;++s)l=t[s],i[s]=o[l.source.index]/(o[l.source.index]+o[l.target.index]);e=new Array(u),h(),n=new Array(u),p()}}function h(){if(r)for(var n=0,o=t.length;n<o;++n)e[n]=+l(t[n],n,t)}function p(){if(r)for(var e=0,o=t.length;e<o;++e)n[e]=+c(t[e],e,t)}return null==t&&(t=[]),f.initialize=function(t,e){r=t,s=e,d()},f.links=function(e){return arguments.length?(t=e,d(),f):t},f.id=function(t){return arguments.length?(a=t,f):a},f.iterations=function(t){return arguments.length?(u=+t,f):u},f.strength=function(t){return arguments.length?(l="function"==typeof t?t:Bi(+t),h(),f):l},f.distance=function(t){return arguments.length?(c="function"==typeof t?t:Bi(+t),p(),f):c},f}Di.copy=function(){var t,e,n=new Fi(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return n;if(!r.length)return n._root=Li(r),n;for(t=[{source:r,target:n._root=new Array(4)}];r=t.pop();)for(var o=0;o<4;++o)(e=r.source[o])&&(e.length?t.push({source:e,target:r.target[o]=new Array(4)}):r.target[o]=Li(e));return n},Di.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return Oi(this.cover(e,n),e,n,t)},Di.addAll=function(t){var e,n,r,o,i=t.length,s=new Array(i),a=new Array(i),l=1/0,c=1/0,u=-1/0,f=-1/0;for(n=0;n<i;++n)isNaN(r=+this._x.call(null,e=t[n]))||isNaN(o=+this._y.call(null,e))||(s[n]=r,a[n]=o,r<l&&(l=r),r>u&&(u=r),o<c&&(c=o),o>f&&(f=o));if(l>u||c>f)return this;for(this.cover(l,c).cover(u,f),n=0;n<i;++n)Oi(this,s[n],a[n],t[n]);return this},Di.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,r=this._y0,o=this._x1,i=this._y1;if(isNaN(n))o=(n=Math.floor(t))+1,i=(r=Math.floor(e))+1;else{for(var s,a,l=o-n||1,c=this._root;n>t||t>=o||r>e||e>=i;)switch(a=(e<r)<<1|t<n,(s=new Array(4))[a]=c,c=s,l*=2,a){case 0:o=n+l,i=r+l;break;case 1:n=o-l,i=r+l;break;case 2:o=n+l,r=i-l;break;case 3:n=o-l,r=i-l}this._root&&this._root.length&&(this._root=c)}return this._x0=n,this._y0=r,this._x1=o,this._y1=i,this},Di.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},Di.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},Di.find=function(t,e,n){var r,o,i,s,a,l,c,u=this._x0,f=this._y0,d=this._x1,h=this._y1,p=[],m=this._root;for(m&&p.push(new Ei(m,u,f,d,h)),null==n?n=1/0:(u=t-n,f=e-n,d=t+n,h=e+n,n*=n);l=p.pop();)if(!(!(m=l.node)||(o=l.x0)>d||(i=l.y0)>h||(s=l.x1)<u||(a=l.y1)<f))if(m.length){var g=(o+s)/2,y=(i+a)/2;p.push(new Ei(m[3],g,y,s,a),new Ei(m[2],o,y,g,a),new Ei(m[1],g,i,s,y),new Ei(m[0],o,i,g,y)),(c=(e>=y)<<1|t>=g)&&(l=p[p.length-1],p[p.length-1]=p[p.length-1-c],p[p.length-1-c]=l)}else{var v=t-+this._x.call(null,m.data),b=e-+this._y.call(null,m.data),_=v*v+b*b;if(_<n){var w=Math.sqrt(n=_);u=t-w,f=e-w,d=t+w,h=e+w,r=m.data}}return r},Di.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,n,r,o,i,s,a,l,c,u,f,d,h=this._root,p=this._x0,m=this._y0,g=this._x1,y=this._y1;if(!h)return this;if(h.length)for(;;){if((c=i>=(a=(p+g)/2))?p=a:g=a,(u=s>=(l=(m+y)/2))?m=l:y=l,e=h,!(h=h[f=u<<1|c]))return this;if(!h.length)break;(e[f+1&3]||e[f+2&3]||e[f+3&3])&&(n=e,d=f)}for(;h.data!==t;)if(r=h,!(h=h.next))return this;return(o=h.next)&&delete h.next,r?(o?r.next=o:delete r.next,this):e?(o?e[f]=o:delete e[f],(h=e[0]||e[1]||e[2]||e[3])&&h===(e[3]||e[2]||e[1]||e[0])&&!h.length&&(n?n[d]=h:this._root=h),this):(this._root=o,this)},Di.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},Di.root=function(){return this._root},Di.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},Di.visit=function(t){var e,n,r,o,i,s,a=[],l=this._root;for(l&&a.push(new Ei(l,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(l=e.node,r=e.x0,o=e.y0,i=e.x1,s=e.y1)&&l.length){var c=(r+i)/2,u=(o+s)/2;(n=l[3])&&a.push(new Ei(n,c,u,i,s)),(n=l[2])&&a.push(new Ei(n,r,u,c,s)),(n=l[1])&&a.push(new Ei(n,c,o,i,u)),(n=l[0])&&a.push(new Ei(n,r,o,c,u))}return this},Di.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new Ei(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,l=e.x1,c=e.y1,u=(s+l)/2,f=(a+c)/2;(i=o[0])&&n.push(new Ei(i,s,a,u,f)),(i=o[1])&&n.push(new Ei(i,u,a,l,f)),(i=o[2])&&n.push(new Ei(i,s,f,u,c)),(i=o[3])&&n.push(new Ei(i,u,f,l,c))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},Di.x=function(t){return arguments.length?(this._x=t,this):this._x},Di.y=function(t){return arguments.length?(this._y=t,this):this._y};const Hi=1664525,Vi=1013904223,Yi=4294967296;function Qi(t){return t.x}function Ki(t){return t.y}var Xi=10,ts=Math.PI*(3-Math.sqrt(5));function es(t){var e,n=1,r=.001,o=1-Math.pow(r,1/300),i=0,s=.6,a=new Map,l=ce(f),c=N("tick","end"),u=function(){let t=1;return()=>(t=(Hi*t+Vi)%Yi)/Yi}();function f(){d(),c.call("tick",e),n<r&&(l.stop(),c.call("end",e))}function d(r){var l,c,u=t.length;void 0===r&&(r=1);for(var f=0;f<r;++f)for(n+=(i-n)*o,a.forEach((function(t){t(n)})),l=0;l<u;++l)null==(c=t[l]).fx?c.x+=c.vx*=s:(c.x=c.fx,c.vx=0),null==c.fy?c.y+=c.vy*=s:(c.y=c.fy,c.vy=0);return e}function h(){for(var e,n=0,r=t.length;n<r;++n){if((e=t[n]).index=n,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=Xi*Math.sqrt(.5+n),i=n*ts;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function p(e){return e.initialize&&e.initialize(t,u),e}return null==t&&(t=[]),h(),e={tick:d,restart:function(){return l.restart(f),e},stop:function(){return l.stop(),e},nodes:function(n){return arguments.length?(t=n,h(),a.forEach(p),e):t},alpha:function(t){return arguments.length?(n=+t,e):n},alphaMin:function(t){return arguments.length?(r=+t,e):r},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(u=t,a.forEach(p),e):u},force:function(t,n){return arguments.length>1?(null==n?a.delete(t):a.set(t,p(n)),e):a.get(t)},find:function(e,n,r){var o,i,s,a,l,c=0,u=t.length;for(null==r?r=1/0:r*=r,c=0;c<u;++c)(s=(o=e-(a=t[c]).x)*o+(i=n-a.y)*i)<r&&(l=a,r=s);return l},on:function(t,n){return arguments.length>1?(c.on(t,n),e):c.on(t)}}}function ns(){var t,e,n,r,o,i=Bi(-30),s=1,a=1/0,l=.81;function c(n){var o,i=t.length,s=Pi(t,Qi,Ki).visitAfter(f);for(r=n,o=0;o<i;++o)e=t[o],s.visit(d)}function u(){if(t){var e,n,r=t.length;for(o=new Array(r),e=0;e<r;++e)n=t[e],o[n.index]=+i(n,e,t)}}function f(t){var e,n,r,i,s,a=0,l=0;if(t.length){for(r=i=s=0;s<4;++s)(e=t[s])&&(n=Math.abs(e.value))&&(a+=e.value,l+=n,r+=n*e.x,i+=n*e.y);t.x=r/l,t.y=i/l}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function d(t,i,c,u){if(!t.value)return!0;var f=t.x-e.x,d=t.y-e.y,h=u-i,p=f*f+d*d;if(h*h/l<p)return p<a&&(0===f&&(p+=(f=zi(n))*f),0===d&&(p+=(d=zi(n))*d),p<s&&(p=Math.sqrt(s*p)),e.vx+=f*t.value*r/p,e.vy+=d*t.value*r/p),!0;if(!(t.length||p>=a)){(t.data!==e||t.next)&&(0===f&&(p+=(f=zi(n))*f),0===d&&(p+=(d=zi(n))*d),p<s&&(p=Math.sqrt(s*p)));do{t.data!==e&&(h=o[t.data.index]*r/p,e.vx+=f*h,e.vy+=d*h)}while(t=t.next)}}return c.initialize=function(e,r){t=e,n=r,u()},c.strength=function(t){return arguments.length?(i="function"==typeof t?t:Bi(+t),u(),c):i},c.distanceMin=function(t){return arguments.length?(s=t*t,c):Math.sqrt(s)},c.distanceMax=function(t){return arguments.length?(a=t*t,c):Math.sqrt(a)},c.theta=function(t){return arguments.length?(l=t*t,c):Math.sqrt(l)},c}function rs(t,e,n){var r,o,i,s=Bi(.1);function a(t){for(var s=0,a=r.length;s<a;++s){var l=r[s],c=l.x-e||1e-6,u=l.y-n||1e-6,f=Math.sqrt(c*c+u*u),d=(i[s]-f)*o[s]*t/f;l.vx+=c*d,l.vy+=u*d}}function l(){if(r){var e,n=r.length;for(o=new Array(n),i=new Array(n),e=0;e<n;++e)i[e]=+t(r[e],e,r),o[e]=isNaN(i[e])?0:+s(r[e],e,r)}}return"function"!=typeof t&&(t=Bi(+t)),null==e&&(e=0),null==n&&(n=0),a.initialize=function(t){r=t,l()},a.strength=function(t){return arguments.length?(s="function"==typeof t?t:Bi(+t),l(),a):s},a.radius=function(e){return arguments.length?(t="function"==typeof e?e:Bi(+e),l(),a):t},a.x=function(t){return arguments.length?(e=+t,a):e},a.y=function(t){return arguments.length?(n=+t,a):n},a}function os(t){var e,n,r,o=Bi(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(r[i]-o.x)*n[i]*t}function s(){if(e){var i,s=e.length;for(n=new Array(s),r=new Array(s),i=0;i<s;++i)n[i]=isNaN(r[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=Bi(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:Bi(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:Bi(+e),s(),i):t},i}function is(t){var e,n,r,o=Bi(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(r[i]-o.y)*n[i]*t}function s(){if(e){var i,s=e.length;for(n=new Array(s),r=new Array(s),i=0;i<s;++i)n[i]=isNaN(r[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=Bi(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:Bi(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:Bi(+e),s(),i):t},i}var ss=n(8288),as=n(9343),ls=1e-6,cs=1e-12,us=Math.PI,fs=us/2,ds=us/4,hs=2*us,ps=180/us,ms=us/180,gs=Math.abs,ys=Math.atan,vs=Math.atan2,bs=Math.cos,_s=Math.ceil,ws=Math.exp,xs=(Math.floor,Math.hypot),ks=Math.log,qs=Math.pow,Ns=Math.sin,Ss=Math.sign||function(t){return t>0?1:t<0?-1:0},As=Math.sqrt,Ms=Math.tan;function Ts(t){return t>1?0:t<-1?us:Math.acos(t)}function Cs(t){return t>1?fs:t<-1?-fs:Math.asin(t)}function js(t){return(t=Ns(t/2))*t}function Os(){}function Es(t,e){t&&Is.hasOwnProperty(t.type)&&Is[t.type](t,e)}var Rs={Feature:function(t,e){Es(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,o=n.length;++r<o;)Es(n[r].geometry,e)}},Is={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)t=n[r],e.point(t[0],t[1],t[2])},LineString:function(t,e){Ps(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)Ps(n[r],e,0)},Polygon:function(t,e){Fs(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)Fs(n[r],e)},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,o=n.length;++r<o;)Es(n[r],e)}};function Ps(t,e,n){var r,o=-1,i=t.length-n;for(e.lineStart();++o<i;)r=t[o],e.point(r[0],r[1],r[2]);e.lineEnd()}function Fs(t,e){var n=-1,r=t.length;for(e.polygonStart();++n<r;)Ps(t[n],e,1);e.polygonEnd()}function Ls(t,e){t&&Rs.hasOwnProperty(t.type)?Rs[t.type](t,e):Es(t,e)}var Ds,Bs,zs,Zs,$s,Gs,Us,Js,Ws,Hs,Vs,Ys,Qs,Ks,Xs,ta,ea=new as.dU,na=new as.dU,ra={point:Os,lineStart:Os,lineEnd:Os,polygonStart:function(){ea=new as.dU,ra.lineStart=oa,ra.lineEnd=ia},polygonEnd:function(){var t=+ea;na.add(t<0?hs+t:t),this.lineStart=this.lineEnd=this.point=Os},sphere:function(){na.add(hs)}};function oa(){ra.point=sa}function ia(){aa(Ds,Bs)}function sa(t,e){ra.point=aa,Ds=t,Bs=e,zs=t*=ms,Zs=bs(e=(e*=ms)/2+ds),$s=Ns(e)}function aa(t,e){var n=(t*=ms)-zs,r=n>=0?1:-1,o=r*n,i=bs(e=(e*=ms)/2+ds),s=Ns(e),a=$s*s,l=Zs*i+a*bs(o),c=a*r*Ns(o);ea.add(vs(c,l)),zs=t,Zs=i,$s=s}function la(t){return na=new as.dU,Ls(t,ra),2*na}function ca(t){return[vs(t[1],t[0]),Cs(t[2])]}function ua(t){var e=t[0],n=t[1],r=bs(n);return[r*bs(e),r*Ns(e),Ns(n)]}function fa(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function da(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function ha(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function pa(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function ma(t){var e=As(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var ga,ya,va,ba,_a,wa,xa,ka,qa,Na,Sa,Aa,Ma,Ta,Ca,ja,Oa={point:Ea,lineStart:Ia,lineEnd:Pa,polygonStart:function(){Oa.point=Fa,Oa.lineStart=La,Oa.lineEnd=Da,Ks=new as.dU,ra.polygonStart()},polygonEnd:function(){ra.polygonEnd(),Oa.point=Ea,Oa.lineStart=Ia,Oa.lineEnd=Pa,ea<0?(Gs=-(Js=180),Us=-(Ws=90)):Ks>ls?Ws=90:Ks<-ls&&(Us=-90),ta[0]=Gs,ta[1]=Js},sphere:function(){Gs=-(Js=180),Us=-(Ws=90)}};function Ea(t,e){Xs.push(ta=[Gs=t,Js=t]),e<Us&&(Us=e),e>Ws&&(Ws=e)}function Ra(t,e){var n=ua([t*ms,e*ms]);if(Qs){var r=da(Qs,n),o=da([r[1],-r[0],0],r);ma(o),o=ca(o);var i,s=t-Hs,a=s>0?1:-1,l=o[0]*ps*a,c=gs(s)>180;c^(a*Hs<l&&l<a*t)?(i=o[1]*ps)>Ws&&(Ws=i):c^(a*Hs<(l=(l+360)%360-180)&&l<a*t)?(i=-o[1]*ps)<Us&&(Us=i):(e<Us&&(Us=e),e>Ws&&(Ws=e)),c?t<Hs?Ba(Gs,t)>Ba(Gs,Js)&&(Js=t):Ba(t,Js)>Ba(Gs,Js)&&(Gs=t):Js>=Gs?(t<Gs&&(Gs=t),t>Js&&(Js=t)):t>Hs?Ba(Gs,t)>Ba(Gs,Js)&&(Js=t):Ba(t,Js)>Ba(Gs,Js)&&(Gs=t)}else Xs.push(ta=[Gs=t,Js=t]);e<Us&&(Us=e),e>Ws&&(Ws=e),Qs=n,Hs=t}function Ia(){Oa.point=Ra}function Pa(){ta[0]=Gs,ta[1]=Js,Oa.point=Ea,Qs=null}function Fa(t,e){if(Qs){var n=t-Hs;Ks.add(gs(n)>180?n+(n>0?360:-360):n)}else Vs=t,Ys=e;ra.point(t,e),Ra(t,e)}function La(){ra.lineStart()}function Da(){Fa(Vs,Ys),ra.lineEnd(),gs(Ks)>ls&&(Gs=-(Js=180)),ta[0]=Gs,ta[1]=Js,Qs=null}function Ba(t,e){return(e-=t)<0?e+360:e}function za(t,e){return t[0]-e[0]}function Za(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function $a(t){var e,n,r,o,i,s,a;if(Ws=Js=-(Gs=Us=1/0),Xs=[],Ls(t,Oa),n=Xs.length){for(Xs.sort(za),e=1,i=[r=Xs[0]];e<n;++e)Za(r,(o=Xs[e])[0])||Za(r,o[1])?(Ba(r[0],o[1])>Ba(r[0],r[1])&&(r[1]=o[1]),Ba(o[0],r[1])>Ba(r[0],r[1])&&(r[0]=o[0])):i.push(r=o);for(s=-1/0,e=0,r=i[n=i.length-1];e<=n;r=o,++e)o=i[e],(a=Ba(r[1],o[0]))>s&&(s=a,Gs=o[0],Js=r[1])}return Xs=ta=null,Gs===1/0||Us===1/0?[[NaN,NaN],[NaN,NaN]]:[[Gs,Us],[Js,Ws]]}var Ga={sphere:Os,point:Ua,lineStart:Wa,lineEnd:Ya,polygonStart:function(){Ga.lineStart=Qa,Ga.lineEnd=Ka},polygonEnd:function(){Ga.lineStart=Wa,Ga.lineEnd=Ya}};function Ua(t,e){t*=ms;var n=bs(e*=ms);Ja(n*bs(t),n*Ns(t),Ns(e))}function Ja(t,e,n){++ga,va+=(t-va)/ga,ba+=(e-ba)/ga,_a+=(n-_a)/ga}function Wa(){Ga.point=Ha}function Ha(t,e){t*=ms;var n=bs(e*=ms);Ta=n*bs(t),Ca=n*Ns(t),ja=Ns(e),Ga.point=Va,Ja(Ta,Ca,ja)}function Va(t,e){t*=ms;var n=bs(e*=ms),r=n*bs(t),o=n*Ns(t),i=Ns(e),s=vs(As((s=Ca*i-ja*o)*s+(s=ja*r-Ta*i)*s+(s=Ta*o-Ca*r)*s),Ta*r+Ca*o+ja*i);ya+=s,wa+=s*(Ta+(Ta=r)),xa+=s*(Ca+(Ca=o)),ka+=s*(ja+(ja=i)),Ja(Ta,Ca,ja)}function Ya(){Ga.point=Ua}function Qa(){Ga.point=Xa}function Ka(){tl(Aa,Ma),Ga.point=Ua}function Xa(t,e){Aa=t,Ma=e,t*=ms,e*=ms,Ga.point=tl;var n=bs(e);Ta=n*bs(t),Ca=n*Ns(t),ja=Ns(e),Ja(Ta,Ca,ja)}function tl(t,e){t*=ms;var n=bs(e*=ms),r=n*bs(t),o=n*Ns(t),i=Ns(e),s=Ca*i-ja*o,a=ja*r-Ta*i,l=Ta*o-Ca*r,c=xs(s,a,l),u=Cs(c),f=c&&-u/c;qa.add(f*s),Na.add(f*a),Sa.add(f*l),ya+=u,wa+=u*(Ta+(Ta=r)),xa+=u*(Ca+(Ca=o)),ka+=u*(ja+(ja=i)),Ja(Ta,Ca,ja)}function el(t){ga=ya=va=ba=_a=wa=xa=ka=0,qa=new as.dU,Na=new as.dU,Sa=new as.dU,Ls(t,Ga);var e=+qa,n=+Na,r=+Sa,o=xs(e,n,r);return o<cs&&(e=wa,n=xa,r=ka,ya<ls&&(e=va,n=ba,r=_a),(o=xs(e,n,r))<cs)?[NaN,NaN]:[vs(n,e)*ps,Cs(r/o)*ps]}function nl(t){return function(){return t}}function rl(t,e){function n(n,r){return n=t(n,r),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,r){return(n=e.invert(n,r))&&t.invert(n[0],n[1])}),n}function ol(t,e){return[gs(t)>us?t+Math.round(-t/hs)*hs:t,e]}function il(t,e,n){return(t%=hs)?e||n?rl(al(t),ll(e,n)):al(t):e||n?ll(e,n):ol}function sl(t){return function(e,n){return[(e+=t)>us?e-hs:e<-us?e+hs:e,n]}}function al(t){var e=sl(t);return e.invert=sl(-t),e}function ll(t,e){var n=bs(t),r=Ns(t),o=bs(e),i=Ns(e);function s(t,e){var s=bs(e),a=bs(t)*s,l=Ns(t)*s,c=Ns(e),u=c*n+a*r;return[vs(l*o-u*i,a*n-c*r),Cs(u*o+l*i)]}return s.invert=function(t,e){var s=bs(e),a=bs(t)*s,l=Ns(t)*s,c=Ns(e),u=c*o-l*i;return[vs(l*o+c*i,a*n+u*r),Cs(u*n-a*r)]},s}function cl(t){function e(e){return(e=t(e[0]*ms,e[1]*ms))[0]*=ps,e[1]*=ps,e}return t=il(t[0]*ms,t[1]*ms,t.length>2?t[2]*ms:0),e.invert=function(e){return(e=t.invert(e[0]*ms,e[1]*ms))[0]*=ps,e[1]*=ps,e},e}function ul(t,e,n,r,o,i){if(n){var s=bs(e),a=Ns(e),l=r*n;null==o?(o=e+r*hs,i=e-l/2):(o=fl(s,o),i=fl(s,i),(r>0?o<i:o>i)&&(o+=r*hs));for(var c,u=o;r>0?u>i:u<i;u-=l)c=ca([s,-a*bs(u),-a*Ns(u)]),t.point(c[0],c[1])}}function fl(t,e){(e=ua(e))[0]-=t,ma(e);var n=Ts(-e[1]);return((-e[2]<0?-n:n)+hs-ls)%hs}function dl(){var t,e,n=nl([0,0]),r=nl(90),o=nl(6),i={point:function(n,r){t.push(n=e(n,r)),n[0]*=ps,n[1]*=ps}};function s(){var s=n.apply(this,arguments),a=r.apply(this,arguments)*ms,l=o.apply(this,arguments)*ms;return t=[],e=il(-s[0]*ms,-s[1]*ms,0).invert,ul(i,a,l,1),s={type:"Polygon",coordinates:[t]},t=e=null,s}return s.center=function(t){return arguments.length?(n="function"==typeof t?t:nl([+t[0],+t[1]]),s):n},s.radius=function(t){return arguments.length?(r="function"==typeof t?t:nl(+t),s):r},s.precision=function(t){return arguments.length?(o="function"==typeof t?t:nl(+t),s):o},s}function hl(){var t,e=[];return{point:function(e,n,r){t.push([e,n,r])},lineStart:function(){e.push(t=[])},lineEnd:Os,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function pl(t,e){return gs(t[0]-e[0])<ls&&gs(t[1]-e[1])<ls}function ml(t,e,n,r){this.x=t,this.z=e,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function gl(t,e,n,r,o){var i,s,a=[],l=[];if(t.forEach((function(t){if(!((e=t.length-1)<=0)){var e,n,r=t[0],s=t[e];if(pl(r,s)){if(!r[2]&&!s[2]){for(o.lineStart(),i=0;i<e;++i)o.point((r=t[i])[0],r[1]);return void o.lineEnd()}s[0]+=2*ls}a.push(n=new ml(r,t,null,!0)),l.push(n.o=new ml(r,null,n,!1)),a.push(n=new ml(s,t,null,!1)),l.push(n.o=new ml(s,null,n,!0))}})),a.length){for(l.sort(e),yl(a),yl(l),i=0,s=l.length;i<s;++i)l[i].e=n=!n;for(var c,u,f=a[0];;){for(var d=f,h=!0;d.v;)if((d=d.n)===f)return;c=d.z,o.lineStart();do{if(d.v=d.o.v=!0,d.e){if(h)for(i=0,s=c.length;i<s;++i)o.point((u=c[i])[0],u[1]);else r(d.x,d.n.x,1,o);d=d.n}else{if(h)for(c=d.p.z,i=c.length-1;i>=0;--i)o.point((u=c[i])[0],u[1]);else r(d.x,d.p.x,-1,o);d=d.p}c=(d=d.o).z,h=!h}while(!d.v);o.lineEnd()}}}function yl(t){if(e=t.length){for(var e,n,r=0,o=t[0];++r<e;)o.n=n=t[r],n.p=o,o=n;o.n=n=t[0],n.p=o}}function vl(t){return gs(t[0])<=us?t[0]:Ss(t[0])*((gs(t[0])+us)%hs-us)}function bl(t,e){var n=vl(e),r=e[1],o=Ns(r),i=[Ns(n),-bs(n),0],s=0,a=0,l=new as.dU;1===o?r=fs+ls:-1===o&&(r=-fs-ls);for(var c=0,u=t.length;c<u;++c)if(d=(f=t[c]).length)for(var f,d,h=f[d-1],p=vl(h),m=h[1]/2+ds,g=Ns(m),y=bs(m),v=0;v<d;++v,p=_,g=x,y=k,h=b){var b=f[v],_=vl(b),w=b[1]/2+ds,x=Ns(w),k=bs(w),q=_-p,N=q>=0?1:-1,S=N*q,A=S>us,M=g*x;if(l.add(vs(M*N*Ns(S),y*k+M*bs(S))),s+=A?q+N*hs:q,A^p>=n^_>=n){var T=da(ua(h),ua(b));ma(T);var C=da(i,T);ma(C);var j=(A^q>=0?-1:1)*Cs(C[2]);(r>j||r===j&&(T[0]||T[1]))&&(a+=A^q>=0?1:-1)}}return(s<-ls||s<ls&&l<-cs)^1&a}ol.invert=ol;var _l=n(1740);function wl(t,e,n,r){return function(o){var i,s,a,l=e(o),c=hl(),u=e(c),f=!1,d={point:h,lineStart:m,lineEnd:g,polygonStart:function(){d.point=y,d.lineStart=v,d.lineEnd=b,s=[],i=[]},polygonEnd:function(){d.point=h,d.lineStart=m,d.lineEnd=g,s=(0,_l.Z)(s);var t=bl(i,r);s.length?(f||(o.polygonStart(),f=!0),gl(s,kl,t,n,o)):t&&(f||(o.polygonStart(),f=!0),o.lineStart(),n(null,null,1,o),o.lineEnd()),f&&(o.polygonEnd(),f=!1),s=i=null},sphere:function(){o.polygonStart(),o.lineStart(),n(null,null,1,o),o.lineEnd(),o.polygonEnd()}};function h(e,n){t(e,n)&&o.point(e,n)}function p(t,e){l.point(t,e)}function m(){d.point=p,l.lineStart()}function g(){d.point=h,l.lineEnd()}function y(t,e){a.push([t,e]),u.point(t,e)}function v(){u.lineStart(),a=[]}function b(){y(a[0][0],a[0][1]),u.lineEnd();var t,e,n,r,l=u.clean(),d=c.result(),h=d.length;if(a.pop(),i.push(a),a=null,h)if(1&l){if((e=(n=d[0]).length-1)>0){for(f||(o.polygonStart(),f=!0),o.lineStart(),t=0;t<e;++t)o.point((r=n[t])[0],r[1]);o.lineEnd()}}else h>1&&2&l&&d.push(d.pop().concat(d.shift())),s.push(d.filter(xl))}return d}}function xl(t){return t.length>1}function kl(t,e){return((t=t.x)[0]<0?t[1]-fs-ls:fs-t[1])-((e=e.x)[0]<0?e[1]-fs-ls:fs-e[1])}const ql=wl((function(){return!0}),(function(t){var e,n=NaN,r=NaN,o=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(i,s){var a=i>0?us:-us,l=gs(i-n);gs(l-us)<ls?(t.point(n,r=(r+s)/2>0?fs:-fs),t.point(o,r),t.lineEnd(),t.lineStart(),t.point(a,r),t.point(i,r),e=0):o!==a&&l>=us&&(gs(n-o)<ls&&(n-=o*ls),gs(i-a)<ls&&(i-=a*ls),r=function(t,e,n,r){var o,i,s=Ns(t-n);return gs(s)>ls?ys((Ns(e)*(i=bs(r))*Ns(n)-Ns(r)*(o=bs(e))*Ns(t))/(o*i*s)):(e+r)/2}(n,r,i,s),t.point(o,r),t.lineEnd(),t.lineStart(),t.point(a,r),e=0),t.point(n=i,r=s),o=a},lineEnd:function(){t.lineEnd(),n=r=NaN},clean:function(){return 2-e}}}),(function(t,e,n,r){var o;if(null==t)o=n*fs,r.point(-us,o),r.point(0,o),r.point(us,o),r.point(us,0),r.point(us,-o),r.point(0,-o),r.point(-us,-o),r.point(-us,0),r.point(-us,o);else if(gs(t[0]-e[0])>ls){var i=t[0]<e[0]?us:-us;o=n*i/2,r.point(-i,o),r.point(0,o),r.point(i,o)}else r.point(e[0],e[1])}),[-us,-fs]);function Nl(t){var e=bs(t),n=6*ms,r=e>0,o=gs(e)>ls;function i(t,n){return bs(t)*bs(n)>e}function s(t,n,r){var o=[1,0,0],i=da(ua(t),ua(n)),s=fa(i,i),a=i[0],l=s-a*a;if(!l)return!r&&t;var c=e*s/l,u=-e*a/l,f=da(o,i),d=pa(o,c);ha(d,pa(i,u));var h=f,p=fa(d,h),m=fa(h,h),g=p*p-m*(fa(d,d)-1);if(!(g<0)){var y=As(g),v=pa(h,(-p-y)/m);if(ha(v,d),v=ca(v),!r)return v;var b,_=t[0],w=n[0],x=t[1],k=n[1];w<_&&(b=_,_=w,w=b);var q=w-_,N=gs(q-us)<ls;if(!N&&k<x&&(b=x,x=k,k=b),N||q<ls?N?x+k>0^v[1]<(gs(v[0]-_)<ls?x:k):x<=v[1]&&v[1]<=k:q>us^(_<=v[0]&&v[0]<=w)){var S=pa(h,(-p+y)/m);return ha(S,d),[v,ca(S)]}}}function a(e,n){var o=r?t:us-t,i=0;return e<-o?i|=1:e>o&&(i|=2),n<-o?i|=4:n>o&&(i|=8),i}return wl(i,(function(t){var e,n,l,c,u;return{lineStart:function(){c=l=!1,u=1},point:function(f,d){var h,p=[f,d],m=i(f,d),g=r?m?0:a(f,d):m?a(f+(f<0?us:-us),d):0;if(!e&&(c=l=m)&&t.lineStart(),m!==l&&(!(h=s(e,p))||pl(e,h)||pl(p,h))&&(p[2]=1),m!==l)u=0,m?(t.lineStart(),h=s(p,e),t.point(h[0],h[1])):(h=s(e,p),t.point(h[0],h[1],2),t.lineEnd()),e=h;else if(o&&e&&r^m){var y;g&n||!(y=s(p,e,!0))||(u=0,r?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1],3)))}!m||e&&pl(e,p)||t.point(p[0],p[1]),e=p,l=m,n=g},lineEnd:function(){l&&t.lineEnd(),e=null},clean:function(){return u|(c&&l)<<1}}}),(function(e,r,o,i){ul(i,t,n,o,e,r)}),r?[0,-t]:[-us,t-us])}var Sl,Al,Ml,Tl,Cl=1e9,jl=-Cl;function Ol(t,e,n,r){function o(o,i){return t<=o&&o<=n&&e<=i&&i<=r}function i(o,i,a,c){var u=0,f=0;if(null==o||(u=s(o,a))!==(f=s(i,a))||l(o,i)<0^a>0)do{c.point(0===u||3===u?t:n,u>1?r:e)}while((u=(u+a+4)%4)!==f);else c.point(i[0],i[1])}function s(r,o){return gs(r[0]-t)<ls?o>0?0:3:gs(r[0]-n)<ls?o>0?2:1:gs(r[1]-e)<ls?o>0?1:0:o>0?3:2}function a(t,e){return l(t.x,e.x)}function l(t,e){var n=s(t,1),r=s(e,1);return n!==r?n-r:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(s){var l,c,u,f,d,h,p,m,g,y,v,b=s,_=hl(),w={point:x,lineStart:function(){w.point=k,c&&c.push(u=[]);y=!0,g=!1,p=m=NaN},lineEnd:function(){l&&(k(f,d),h&&g&&_.rejoin(),l.push(_.result()));w.point=x,g&&b.lineEnd()},polygonStart:function(){b=_,l=[],c=[],v=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,o=c.length;n<o;++n)for(var i,s,a=c[n],l=1,u=a.length,f=a[0],d=f[0],h=f[1];l<u;++l)i=d,s=h,d=(f=a[l])[0],h=f[1],s<=r?h>r&&(d-i)*(r-s)>(h-s)*(t-i)&&++e:h<=r&&(d-i)*(r-s)<(h-s)*(t-i)&&--e;return e}(),n=v&&e,o=(l=(0,_l.Z)(l)).length;(n||o)&&(s.polygonStart(),n&&(s.lineStart(),i(null,null,1,s),s.lineEnd()),o&&gl(l,a,e,i,s),s.polygonEnd());b=s,l=c=u=null}};function x(t,e){o(t,e)&&b.point(t,e)}function k(i,s){var a=o(i,s);if(c&&u.push([i,s]),y)f=i,d=s,h=a,y=!1,a&&(b.lineStart(),b.point(i,s));else if(a&&g)b.point(i,s);else{var l=[p=Math.max(jl,Math.min(Cl,p)),m=Math.max(jl,Math.min(Cl,m))],_=[i=Math.max(jl,Math.min(Cl,i)),s=Math.max(jl,Math.min(Cl,s))];!function(t,e,n,r,o,i){var s,a=t[0],l=t[1],c=0,u=1,f=e[0]-a,d=e[1]-l;if(s=n-a,f||!(s>0)){if(s/=f,f<0){if(s<c)return;s<u&&(u=s)}else if(f>0){if(s>u)return;s>c&&(c=s)}if(s=o-a,f||!(s<0)){if(s/=f,f<0){if(s>u)return;s>c&&(c=s)}else if(f>0){if(s<c)return;s<u&&(u=s)}if(s=r-l,d||!(s>0)){if(s/=d,d<0){if(s<c)return;s<u&&(u=s)}else if(d>0){if(s>u)return;s>c&&(c=s)}if(s=i-l,d||!(s<0)){if(s/=d,d<0){if(s>u)return;s>c&&(c=s)}else if(d>0){if(s<c)return;s<u&&(u=s)}return c>0&&(t[0]=a+c*f,t[1]=l+c*d),u<1&&(e[0]=a+u*f,e[1]=l+u*d),!0}}}}}(l,_,t,e,n,r)?a&&(b.lineStart(),b.point(i,s),v=!1):(g||(b.lineStart(),b.point(l[0],l[1])),b.point(_[0],_[1]),a||b.lineEnd(),v=!1)}p=i,m=s,g=a}return w}}function El(){var t,e,n,r=0,o=0,i=960,s=500;return n={stream:function(n){return t&&e===n?t:t=Ol(r,o,i,s)(e=n)},extent:function(a){return arguments.length?(r=+a[0][0],o=+a[0][1],i=+a[1][0],s=+a[1][1],t=e=null,n):[[r,o],[i,s]]}}}var Rl={sphere:Os,point:Os,lineStart:function(){Rl.point=Pl,Rl.lineEnd=Il},lineEnd:Os,polygonStart:Os,polygonEnd:Os};function Il(){Rl.point=Rl.lineEnd=Os}function Pl(t,e){Al=t*=ms,Ml=Ns(e*=ms),Tl=bs(e),Rl.point=Fl}function Fl(t,e){t*=ms;var n=Ns(e*=ms),r=bs(e),o=gs(t-Al),i=bs(o),s=r*Ns(o),a=Tl*n-Ml*r*i,l=Ml*n+Tl*r*i;Sl.add(vs(As(s*s+a*a),l)),Al=t,Ml=n,Tl=r}function Ll(t){return Sl=new as.dU,Ls(t,Rl),+Sl}var Dl=[null,null],Bl={type:"LineString",coordinates:Dl};function zl(t,e){return Dl[0]=t,Dl[1]=e,Ll(Bl)}var Zl={Feature:function(t,e){return Gl(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,o=n.length;++r<o;)if(Gl(n[r].geometry,e))return!0;return!1}},$l={Sphere:function(){return!0},Point:function(t,e){return Ul(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(Ul(n[r],e))return!0;return!1},LineString:function(t,e){return Jl(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(Jl(n[r],e))return!0;return!1},Polygon:function(t,e){return Wl(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,o=n.length;++r<o;)if(Wl(n[r],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,o=n.length;++r<o;)if(Gl(n[r],e))return!0;return!1}};function Gl(t,e){return!(!t||!$l.hasOwnProperty(t.type))&&$l[t.type](t,e)}function Ul(t,e){return 0===zl(t,e)}function Jl(t,e){for(var n,r,o,i=0,s=t.length;i<s;i++){if(0===(r=zl(t[i],e)))return!0;if(i>0&&(o=zl(t[i],t[i-1]))>0&&n<=o&&r<=o&&(n+r-o)*(1-Math.pow((n-r)/o,2))<cs*o)return!0;n=r}return!1}function Wl(t,e){return!!bl(t.map(Hl),Vl(e))}function Hl(t){return(t=t.map(Vl)).pop(),t}function Vl(t){return[t[0]*ms,t[1]*ms]}function Yl(t,e){return(t&&Zl.hasOwnProperty(t.type)?Zl[t.type]:Gl)(t,e)}var Ql=n(1265);function Kl(t,e,n){var r=(0,Ql.Z)(t,e-ls,n).concat(e);return function(t){return r.map((function(e){return[t,e]}))}}function Xl(t,e,n){var r=(0,Ql.Z)(t,e-ls,n).concat(e);return function(t){return r.map((function(e){return[e,t]}))}}function tc(){var t,e,n,r,o,i,s,a,l,c,u,f,d=10,h=d,p=90,m=360,g=2.5;function y(){return{type:"MultiLineString",coordinates:v()}}function v(){return(0,Ql.Z)(_s(r/p)*p,n,p).map(u).concat((0,Ql.Z)(_s(a/m)*m,s,m).map(f)).concat((0,Ql.Z)(_s(e/d)*d,t,d).filter((function(t){return gs(t%p)>ls})).map(l)).concat((0,Ql.Z)(_s(i/h)*h,o,h).filter((function(t){return gs(t%m)>ls})).map(c))}return y.lines=function(){return v().map((function(t){return{type:"LineString",coordinates:t}}))},y.outline=function(){return{type:"Polygon",coordinates:[u(r).concat(f(s).slice(1),u(n).reverse().slice(1),f(a).reverse().slice(1))]}},y.extent=function(t){return arguments.length?y.extentMajor(t).extentMinor(t):y.extentMinor()},y.extentMajor=function(t){return arguments.length?(r=+t[0][0],n=+t[1][0],a=+t[0][1],s=+t[1][1],r>n&&(t=r,r=n,n=t),a>s&&(t=a,a=s,s=t),y.precision(g)):[[r,a],[n,s]]},y.extentMinor=function(n){return arguments.length?(e=+n[0][0],t=+n[1][0],i=+n[0][1],o=+n[1][1],e>t&&(n=e,e=t,t=n),i>o&&(n=i,i=o,o=n),y.precision(g)):[[e,i],[t,o]]},y.step=function(t){return arguments.length?y.stepMajor(t).stepMinor(t):y.stepMinor()},y.stepMajor=function(t){return arguments.length?(p=+t[0],m=+t[1],y):[p,m]},y.stepMinor=function(t){return arguments.length?(d=+t[0],h=+t[1],y):[d,h]},y.precision=function(d){return arguments.length?(g=+d,l=Kl(i,o,90),c=Xl(e,t,g),u=Kl(a,s,90),f=Xl(r,n,g),y):g},y.extentMajor([[-180,-90+ls],[180,90-ls]]).extentMinor([[-180,-80-ls],[180,80+ls]])}function ec(){return tc()()}function nc(t,e){var n=t[0]*ms,r=t[1]*ms,o=e[0]*ms,i=e[1]*ms,s=bs(r),a=Ns(r),l=bs(i),c=Ns(i),u=s*bs(n),f=s*Ns(n),d=l*bs(o),h=l*Ns(o),p=2*Cs(As(js(i-r)+s*l*js(o-n))),m=Ns(p),g=p?function(t){var e=Ns(t*=p)/m,n=Ns(p-t)/m,r=n*u+e*d,o=n*f+e*h,i=n*a+e*c;return[vs(o,r)*ps,vs(i,As(r*r+o*o))*ps]}:function(){return[n*ps,r*ps]};return g.distance=p,g}const rc=t=>t;var oc,ic,sc,ac,lc=new as.dU,cc=new as.dU,uc={point:Os,lineStart:Os,lineEnd:Os,polygonStart:function(){uc.lineStart=fc,uc.lineEnd=pc},polygonEnd:function(){uc.lineStart=uc.lineEnd=uc.point=Os,lc.add(gs(cc)),cc=new as.dU},result:function(){var t=lc/2;return lc=new as.dU,t}};function fc(){uc.point=dc}function dc(t,e){uc.point=hc,oc=sc=t,ic=ac=e}function hc(t,e){cc.add(ac*t-sc*e),sc=t,ac=e}function pc(){hc(oc,ic)}const mc=uc;var gc=1/0,yc=gc,vc=-gc,bc=vc,_c={point:function(t,e){t<gc&&(gc=t);t>vc&&(vc=t);e<yc&&(yc=e);e>bc&&(bc=e)},lineStart:Os,lineEnd:Os,polygonStart:Os,polygonEnd:Os,result:function(){var t=[[gc,yc],[vc,bc]];return vc=bc=-(yc=gc=1/0),t}};const wc=_c;var xc,kc,qc,Nc,Sc=0,Ac=0,Mc=0,Tc=0,Cc=0,jc=0,Oc=0,Ec=0,Rc=0,Ic={point:Pc,lineStart:Fc,lineEnd:Bc,polygonStart:function(){Ic.lineStart=zc,Ic.lineEnd=Zc},polygonEnd:function(){Ic.point=Pc,Ic.lineStart=Fc,Ic.lineEnd=Bc},result:function(){var t=Rc?[Oc/Rc,Ec/Rc]:jc?[Tc/jc,Cc/jc]:Mc?[Sc/Mc,Ac/Mc]:[NaN,NaN];return Sc=Ac=Mc=Tc=Cc=jc=Oc=Ec=Rc=0,t}};function Pc(t,e){Sc+=t,Ac+=e,++Mc}function Fc(){Ic.point=Lc}function Lc(t,e){Ic.point=Dc,Pc(qc=t,Nc=e)}function Dc(t,e){var n=t-qc,r=e-Nc,o=As(n*n+r*r);Tc+=o*(qc+t)/2,Cc+=o*(Nc+e)/2,jc+=o,Pc(qc=t,Nc=e)}function Bc(){Ic.point=Pc}function zc(){Ic.point=$c}function Zc(){Gc(xc,kc)}function $c(t,e){Ic.point=Gc,Pc(xc=qc=t,kc=Nc=e)}function Gc(t,e){var n=t-qc,r=e-Nc,o=As(n*n+r*r);Tc+=o*(qc+t)/2,Cc+=o*(Nc+e)/2,jc+=o,Oc+=(o=Nc*t-qc*e)*(qc+t),Ec+=o*(Nc+e),Rc+=3*o,Pc(qc=t,Nc=e)}const Uc=Ic;function Jc(t){this._context=t}Jc.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._context.moveTo(t,e),this._point=1;break;case 1:this._context.lineTo(t,e);break;default:this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,hs)}},result:Os};var Wc,Hc,Vc,Yc,Qc,Kc=new as.dU,Xc={point:Os,lineStart:function(){Xc.point=tu},lineEnd:function(){Wc&&eu(Hc,Vc),Xc.point=Os},polygonStart:function(){Wc=!0},polygonEnd:function(){Wc=null},result:function(){var t=+Kc;return Kc=new as.dU,t}};function tu(t,e){Xc.point=eu,Hc=Yc=t,Vc=Qc=e}function eu(t,e){Yc-=t,Qc-=e,Kc.add(As(Yc*Yc+Qc*Qc)),Yc=t,Qc=e}const nu=Xc;function ru(){this._string=[]}function ou(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function iu(t,e){var n,r,o=4.5;function i(t){return t&&("function"==typeof o&&r.pointRadius(+o.apply(this,arguments)),Ls(t,n(r))),r.result()}return i.area=function(t){return Ls(t,n(mc)),mc.result()},i.measure=function(t){return Ls(t,n(nu)),nu.result()},i.bounds=function(t){return Ls(t,n(wc)),wc.result()},i.centroid=function(t){return Ls(t,n(Uc)),Uc.result()},i.projection=function(e){return arguments.length?(n=null==e?(t=null,rc):(t=e).stream,i):t},i.context=function(t){return arguments.length?(r=null==t?(e=null,new ru):new Jc(e=t),"function"!=typeof o&&r.pointRadius(o),i):e},i.pointRadius=function(t){return arguments.length?(o="function"==typeof t?t:(r.pointRadius(+t),+t),i):o},i.projection(t).context(e)}function su(t){return{stream:au(t)}}function au(t){return function(e){var n=new lu;for(var r in t)n[r]=t[r];return n.stream=e,n}}function lu(){}function cu(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=r&&t.clipExtent(null),Ls(n,t.stream(wc)),e(wc.result()),null!=r&&t.clipExtent(r),t}function uu(t,e,n){return cu(t,(function(n){var r=e[1][0]-e[0][0],o=e[1][1]-e[0][1],i=Math.min(r/(n[1][0]-n[0][0]),o/(n[1][1]-n[0][1])),s=+e[0][0]+(r-i*(n[1][0]+n[0][0]))/2,a=+e[0][1]+(o-i*(n[1][1]+n[0][1]))/2;t.scale(150*i).translate([s,a])}),n)}function fu(t,e,n){return uu(t,[[0,0],e],n)}function du(t,e,n){return cu(t,(function(n){var r=+e,o=r/(n[1][0]-n[0][0]),i=(r-o*(n[1][0]+n[0][0]))/2,s=-o*n[0][1];t.scale(150*o).translate([i,s])}),n)}function hu(t,e,n){return cu(t,(function(n){var r=+e,o=r/(n[1][1]-n[0][1]),i=-o*n[0][0],s=(r-o*(n[1][1]+n[0][1]))/2;t.scale(150*o).translate([i,s])}),n)}ru.prototype={_radius:4.5,_circle:ou(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._string.push("M",t,",",e),this._point=1;break;case 1:this._string.push("L",t,",",e);break;default:null==this._circle&&(this._circle=ou(this._radius)),this._string.push("M",t,",",e,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}},lu.prototype={constructor:lu,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var pu=16,mu=bs(30*ms);function gu(t,e){return+e?function(t,e){function n(r,o,i,s,a,l,c,u,f,d,h,p,m,g){var y=c-r,v=u-o,b=y*y+v*v;if(b>4*e&&m--){var _=s+d,w=a+h,x=l+p,k=As(_*_+w*w+x*x),q=Cs(x/=k),N=gs(gs(x)-1)<ls||gs(i-f)<ls?(i+f)/2:vs(w,_),S=t(N,q),A=S[0],M=S[1],T=A-r,C=M-o,j=v*T-y*C;(j*j/b>e||gs((y*T+v*C)/b-.5)>.3||s*d+a*h+l*p<mu)&&(n(r,o,i,s,a,l,A,M,N,_/=k,w/=k,x,m,g),g.point(A,M),n(A,M,N,_,w,x,c,u,f,d,h,p,m,g))}}return function(e){var r,o,i,s,a,l,c,u,f,d,h,p,m={point:g,lineStart:y,lineEnd:b,polygonStart:function(){e.polygonStart(),m.lineStart=_},polygonEnd:function(){e.polygonEnd(),m.lineStart=y}};function g(n,r){n=t(n,r),e.point(n[0],n[1])}function y(){u=NaN,m.point=v,e.lineStart()}function v(r,o){var i=ua([r,o]),s=t(r,o);n(u,f,c,d,h,p,u=s[0],f=s[1],c=r,d=i[0],h=i[1],p=i[2],pu,e),e.point(u,f)}function b(){m.point=g,e.lineEnd()}function _(){y(),m.point=w,m.lineEnd=x}function w(t,e){v(r=t,e),o=u,i=f,s=d,a=h,l=p,m.point=v}function x(){n(u,f,c,d,h,p,o,i,r,s,a,l,pu,e),m.lineEnd=b,b()}return m}}(t,e):function(t){return au({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var yu=au({point:function(t,e){this.stream.point(t*ms,e*ms)}});function vu(t,e,n,r,o,i){if(!i)return function(t,e,n,r,o){function i(i,s){return[e+t*(i*=r),n-t*(s*=o)]}return i.invert=function(i,s){return[(i-e)/t*r,(n-s)/t*o]},i}(t,e,n,r,o);var s=bs(i),a=Ns(i),l=s*t,c=a*t,u=s/t,f=a/t,d=(a*n-s*e)/t,h=(a*e+s*n)/t;function p(t,i){return[l*(t*=r)-c*(i*=o)+e,n-c*t-l*i]}return p.invert=function(t,e){return[r*(u*t-f*e+d),o*(h-f*t-u*e)]},p}function bu(t){return _u((function(){return t}))()}function _u(t){var e,n,r,o,i,s,a,l,c,u,f=150,d=480,h=250,p=0,m=0,g=0,y=0,v=0,b=0,_=1,w=1,x=null,k=ql,q=null,N=rc,S=.5;function A(t){return l(t[0]*ms,t[1]*ms)}function M(t){return(t=l.invert(t[0],t[1]))&&[t[0]*ps,t[1]*ps]}function T(){var t=vu(f,0,0,_,w,b).apply(null,e(p,m)),r=vu(f,d-t[0],h-t[1],_,w,b);return n=il(g,y,v),a=rl(e,r),l=rl(n,a),s=gu(a,S),C()}function C(){return c=u=null,A}return A.stream=function(t){return c&&u===t?c:c=yu(function(t){return au({point:function(e,n){var r=t(e,n);return this.stream.point(r[0],r[1])}})}(n)(k(s(N(u=t)))))},A.preclip=function(t){return arguments.length?(k=t,x=void 0,C()):k},A.postclip=function(t){return arguments.length?(N=t,q=r=o=i=null,C()):N},A.clipAngle=function(t){return arguments.length?(k=+t?Nl(x=t*ms):(x=null,ql),C()):x*ps},A.clipExtent=function(t){return arguments.length?(N=null==t?(q=r=o=i=null,rc):Ol(q=+t[0][0],r=+t[0][1],o=+t[1][0],i=+t[1][1]),C()):null==q?null:[[q,r],[o,i]]},A.scale=function(t){return arguments.length?(f=+t,T()):f},A.translate=function(t){return arguments.length?(d=+t[0],h=+t[1],T()):[d,h]},A.center=function(t){return arguments.length?(p=t[0]%360*ms,m=t[1]%360*ms,T()):[p*ps,m*ps]},A.rotate=function(t){return arguments.length?(g=t[0]%360*ms,y=t[1]%360*ms,v=t.length>2?t[2]%360*ms:0,T()):[g*ps,y*ps,v*ps]},A.angle=function(t){return arguments.length?(b=t%360*ms,T()):b*ps},A.reflectX=function(t){return arguments.length?(_=t?-1:1,T()):_<0},A.reflectY=function(t){return arguments.length?(w=t?-1:1,T()):w<0},A.precision=function(t){return arguments.length?(s=gu(a,S=t*t),C()):As(S)},A.fitExtent=function(t,e){return uu(A,t,e)},A.fitSize=function(t,e){return fu(A,t,e)},A.fitWidth=function(t,e){return du(A,t,e)},A.fitHeight=function(t,e){return hu(A,t,e)},function(){return e=t.apply(this,arguments),A.invert=e.invert&&M,T()}}function wu(t){var e=0,n=us/3,r=_u(t),o=r(e,n);return o.parallels=function(t){return arguments.length?r(e=t[0]*ms,n=t[1]*ms):[e*ps,n*ps]},o}function xu(t,e){var n=Ns(t),r=(n+Ns(e))/2;if(gs(r)<ls)return function(t){var e=bs(t);function n(t,n){return[t*e,Ns(n)/e]}return n.invert=function(t,n){return[t/e,Cs(n*e)]},n}(t);var o=1+n*(2*r-n),i=As(o)/r;function s(t,e){var n=As(o-2*r*Ns(e))/r;return[n*Ns(t*=r),i-n*bs(t)]}return s.invert=function(t,e){var n=i-e,s=vs(t,gs(n))*Ss(n);return n*r<0&&(s-=us*Ss(t)*Ss(n)),[s/r,Cs((o-(t*t+n*n)*r*r)/(2*r))]},s}function ku(){return wu(xu).scale(155.424).center([0,33.6442])}function qu(){return ku().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function Nu(){var t,e,n,r,o,i,s=qu(),a=ku().rotate([154,0]).center([-2,58.5]).parallels([55,65]),l=ku().rotate([157,0]).center([-3,19.9]).parallels([8,18]),c={point:function(t,e){i=[t,e]}};function u(t){var e=t[0],s=t[1];return i=null,n.point(e,s),i||(r.point(e,s),i)||(o.point(e,s),i)}function f(){return t=e=null,u}return u.invert=function(t){var e=s.scale(),n=s.translate(),r=(t[0]-n[0])/e,o=(t[1]-n[1])/e;return(o>=.12&&o<.234&&r>=-.425&&r<-.214?a:o>=.166&&o<.234&&r>=-.214&&r<-.115?l:s).invert(t)},u.stream=function(n){return t&&e===n?t:(r=[s.stream(e=n),a.stream(n),l.stream(n)],o=r.length,t={point:function(t,e){for(var n=-1;++n<o;)r[n].point(t,e)},sphere:function(){for(var t=-1;++t<o;)r[t].sphere()},lineStart:function(){for(var t=-1;++t<o;)r[t].lineStart()},lineEnd:function(){for(var t=-1;++t<o;)r[t].lineEnd()},polygonStart:function(){for(var t=-1;++t<o;)r[t].polygonStart()},polygonEnd:function(){for(var t=-1;++t<o;)r[t].polygonEnd()}});var r,o},u.precision=function(t){return arguments.length?(s.precision(t),a.precision(t),l.precision(t),f()):s.precision()},u.scale=function(t){return arguments.length?(s.scale(t),a.scale(.35*t),l.scale(t),u.translate(s.translate())):s.scale()},u.translate=function(t){if(!arguments.length)return s.translate();var e=s.scale(),i=+t[0],u=+t[1];return n=s.translate(t).clipExtent([[i-.455*e,u-.238*e],[i+.455*e,u+.238*e]]).stream(c),r=a.translate([i-.307*e,u+.201*e]).clipExtent([[i-.425*e+ls,u+.12*e+ls],[i-.214*e-ls,u+.234*e-ls]]).stream(c),o=l.translate([i-.205*e,u+.212*e]).clipExtent([[i-.214*e+ls,u+.166*e+ls],[i-.115*e-ls,u+.234*e-ls]]).stream(c),f()},u.fitExtent=function(t,e){return uu(u,t,e)},u.fitSize=function(t,e){return fu(u,t,e)},u.fitWidth=function(t,e){return du(u,t,e)},u.fitHeight=function(t,e){return hu(u,t,e)},u.scale(1070)}function Su(t){return function(e,n){var r=bs(e),o=bs(n),i=t(r*o);return i===1/0?[2,0]:[i*o*Ns(e),i*Ns(n)]}}function Au(t){return function(e,n){var r=As(e*e+n*n),o=t(r),i=Ns(o),s=bs(o);return[vs(e*i,r*s),Cs(r&&n*i/r)]}}var Mu=Su((function(t){return As(2/(1+t))}));function Tu(){return bu(Mu).scale(124.75).clipAngle(179.999)}Mu.invert=Au((function(t){return 2*Cs(t/2)}));var Cu=Su((function(t){return(t=Ts(t))&&t/Ns(t)}));function ju(){return bu(Cu).scale(79.4188).clipAngle(179.999)}function Ou(t,e){return[t,ks(Ms((fs+e)/2))]}function Eu(){return Ru(Ou).scale(961/hs)}function Ru(t){var e,n,r,o=bu(t),i=o.center,s=o.scale,a=o.translate,l=o.clipExtent,c=null;function u(){var i=us*s(),a=o(cl(o.rotate()).invert([0,0]));return l(null==c?[[a[0]-i,a[1]-i],[a[0]+i,a[1]+i]]:t===Ou?[[Math.max(a[0]-i,c),e],[Math.min(a[0]+i,n),r]]:[[c,Math.max(a[1]-i,e)],[n,Math.min(a[1]+i,r)]])}return o.scale=function(t){return arguments.length?(s(t),u()):s()},o.translate=function(t){return arguments.length?(a(t),u()):a()},o.center=function(t){return arguments.length?(i(t),u()):i()},o.clipExtent=function(t){return arguments.length?(null==t?c=e=n=r=null:(c=+t[0][0],e=+t[0][1],n=+t[1][0],r=+t[1][1]),u()):null==c?null:[[c,e],[n,r]]},u()}function Iu(t){return Ms((fs+t)/2)}function Pu(t,e){var n=bs(t),r=t===e?Ns(t):ks(n/bs(e))/ks(Iu(e)/Iu(t)),o=n*qs(Iu(t),r)/r;if(!r)return Ou;function i(t,e){o>0?e<-fs+ls&&(e=-fs+ls):e>fs-ls&&(e=fs-ls);var n=o/qs(Iu(e),r);return[n*Ns(r*t),o-n*bs(r*t)]}return i.invert=function(t,e){var n=o-e,i=Ss(r)*As(t*t+n*n),s=vs(t,gs(n))*Ss(n);return n*r<0&&(s-=us*Ss(t)*Ss(n)),[s/r,2*ys(qs(o/i,1/r))-fs]},i}function Fu(){return wu(Pu).scale(109.5).parallels([30,30])}function Lu(t,e){return[t,e]}function Du(){return bu(Lu).scale(152.63)}function Bu(t,e){var n=bs(t),r=t===e?Ns(t):(n-bs(e))/(e-t),o=n/r+t;if(gs(r)<ls)return Lu;function i(t,e){var n=o-e,i=r*t;return[n*Ns(i),o-n*bs(i)]}return i.invert=function(t,e){var n=o-e,i=vs(t,gs(n))*Ss(n);return n*r<0&&(i-=us*Ss(t)*Ss(n)),[i/r,o-Ss(r)*As(t*t+n*n)]},i}function zu(){return wu(Bu).scale(131.154).center([0,13.9389])}Cu.invert=Au((function(t){return t})),Ou.invert=function(t,e){return[t,2*ys(ws(e))-fs]},Lu.invert=Lu;var Zu=1.340264,$u=-.081106,Gu=893e-6,Uu=.003796,Ju=As(3)/2;function Wu(t,e){var n=Cs(Ju*Ns(e)),r=n*n,o=r*r*r;return[t*bs(n)/(Ju*(Zu+3*$u*r+o*(7*Gu+9*Uu*r))),n*(Zu+$u*r+o*(Gu+Uu*r))]}function Hu(){return bu(Wu).scale(177.158)}function Vu(t,e){var n=bs(e),r=bs(t)*n;return[n*Ns(t)/r,Ns(e)/r]}function Yu(){return bu(Vu).scale(144.049).clipAngle(60)}function Qu(){var t,e,n,r,o,i,s,a=1,l=0,c=0,u=1,f=1,d=0,h=null,p=1,m=1,g=au({point:function(t,e){var n=b([t,e]);this.stream.point(n[0],n[1])}}),y=rc;function v(){return p=a*u,m=a*f,i=s=null,b}function b(n){var r=n[0]*p,o=n[1]*m;if(d){var i=o*t-r*e;r=r*t+o*e,o=i}return[r+l,o+c]}return b.invert=function(n){var r=n[0]-l,o=n[1]-c;if(d){var i=o*t+r*e;r=r*t-o*e,o=i}return[r/p,o/m]},b.stream=function(t){return i&&s===t?i:i=g(y(s=t))},b.postclip=function(t){return arguments.length?(y=t,h=n=r=o=null,v()):y},b.clipExtent=function(t){return arguments.length?(y=null==t?(h=n=r=o=null,rc):Ol(h=+t[0][0],n=+t[0][1],r=+t[1][0],o=+t[1][1]),v()):null==h?null:[[h,n],[r,o]]},b.scale=function(t){return arguments.length?(a=+t,v()):a},b.translate=function(t){return arguments.length?(l=+t[0],c=+t[1],v()):[l,c]},b.angle=function(n){return arguments.length?(e=Ns(d=n%360*ms),t=bs(d),v()):d*ps},b.reflectX=function(t){return arguments.length?(u=t?-1:1,v()):u<0},b.reflectY=function(t){return arguments.length?(f=t?-1:1,v()):f<0},b.fitExtent=function(t,e){return uu(b,t,e)},b.fitSize=function(t,e){return fu(b,t,e)},b.fitWidth=function(t,e){return du(b,t,e)},b.fitHeight=function(t,e){return hu(b,t,e)},b}function Ku(t,e){var n=e*e,r=n*n;return[t*(.8707-.131979*n+r*(r*(.003971*n-.001529*r)-.013791)),e*(1.007226+n*(.015085+r*(.028874*n-.044475-.005916*r)))]}function Xu(){return bu(Ku).scale(175.295)}function tf(t,e){return[bs(e)*Ns(t),Ns(e)]}function ef(){return bu(tf).scale(249.5).clipAngle(90+ls)}function nf(t,e){var n=bs(e),r=1+bs(t)*n;return[n*Ns(t)/r,Ns(e)/r]}function rf(){return bu(nf).scale(250).clipAngle(142)}function of(t,e){return[ks(Ms((fs+e)/2)),-t]}function sf(){var t=Ru(of),e=t.center,n=t.rotate;return t.center=function(t){return arguments.length?e([-t[1],t[0]]):[(t=e())[1],-t[0]]},t.rotate=function(t){return arguments.length?n([t[0],t[1],t.length>2?t[2]+90:90]):[(t=n())[0],t[1],t[2]-90]},n([0,0,90]).scale(159.155)}Wu.invert=function(t,e){for(var n,r=e,o=r*r,i=o*o*o,s=0;s<12&&(i=(o=(r-=n=(r*(Zu+$u*o+i*(Gu+Uu*o))-e)/(Zu+3*$u*o+i*(7*Gu+9*Uu*o)))*r)*o*o,!(gs(n)<cs));++s);return[Ju*t*(Zu+3*$u*o+i*(7*Gu+9*Uu*o))/bs(r),Cs(Ns(r)/Ju)]},Vu.invert=Au(ys),Ku.invert=function(t,e){var n,r=e,o=25;do{var i=r*r,s=i*i;r-=n=(r*(1.007226+i*(.015085+s*(.028874*i-.044475-.005916*s)))-e)/(1.007226+i*(.045255+s*(.259866*i-.311325-.005916*11*s)))}while(gs(n)>ls&&--o>0);return[t/(.8707+(i=r*r)*(i*(i*i*i*(.003971-.001529*i)-.013791)-.131979)),r]},tf.invert=Au(Cs),nf.invert=Au((function(t){return 2*ys(t)})),of.invert=function(t,e){return[-e,2*ys(ws(t))-fs]};var af=n(5505),lf=n(6778);function cf(t){for(var e,n=-1,r=t.length,o=t[r-1],i=0;++n<r;)e=o,o=t[n],i+=e[1]*o[0]-e[0]*o[1];return i/2}function uf(t){for(var e,n,r=-1,o=t.length,i=0,s=0,a=t[o-1],l=0;++r<o;)e=a,a=t[r],l+=n=e[0]*a[1]-a[0]*e[1],i+=(e[0]+a[0])*n,s+=(e[1]+a[1])*n;return[i/(l*=3),s/l]}function ff(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0])}function df(t,e){return t[0]-e[0]||t[1]-e[1]}function hf(t){const e=t.length,n=[0,1];let r,o=2;for(r=2;r<e;++r){for(;o>1&&ff(t[n[o-2]],t[n[o-1]],t[r])<=0;)--o;n[o++]=r}return n.slice(0,o)}function pf(t){if((n=t.length)<3)return null;var e,n,r=new Array(n),o=new Array(n);for(e=0;e<n;++e)r[e]=[+t[e][0],+t[e][1],e];for(r.sort(df),e=0;e<n;++e)o[e]=[r[e][0],-r[e][1]];var i=hf(r),s=hf(o),a=s[0]===i[0],l=s[s.length-1]===i[i.length-1],c=[];for(e=i.length-1;e>=0;--e)c.push(t[r[i[e]][2]]);for(e=+a;e<s.length-l;++e)c.push(t[r[s[e]][2]]);return c}function mf(t,e){for(var n,r,o=t.length,i=t[o-1],s=e[0],a=e[1],l=i[0],c=i[1],u=!1,f=0;f<o;++f)n=(i=t[f])[0],(r=i[1])>a!=c>a&&s<(l-n)*(a-r)/(c-r)+n&&(u=!u),l=n,c=r;return u}function gf(t){for(var e,n,r=-1,o=t.length,i=t[o-1],s=i[0],a=i[1],l=0;++r<o;)e=s,n=a,e-=s=(i=t[r])[0],n-=a=i[1],l+=Math.hypot(e,n);return l}const yf=Math.random,vf=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,1===arguments.length?(n=t,t=0):n-=t,function(){return e()*n+t}}return n.source=t,n}(yf),bf=function t(e){function n(t,n){return arguments.length<2&&(n=t,t=0),t=Math.floor(t),n=Math.floor(n)-t,function(){return Math.floor(e()*n+t)}}return n.source=t,n}(yf),_f=function t(e){function n(t,n){var r,o;return t=null==t?0:+t,n=null==n?1:+n,function(){var i;if(null!=r)i=r,r=null;else do{r=2*e()-1,i=2*e()-1,o=r*r+i*i}while(!o||o>1);return t+n*i*Math.sqrt(-2*Math.log(o)/o)}}return n.source=t,n}(yf),wf=function t(e){var n=_f.source(e);function r(){var t=n.apply(this,arguments);return function(){return Math.exp(t())}}return r.source=t,r}(yf),xf=function t(e){function n(t){return(t=+t)<=0?()=>0:function(){for(var n=0,r=t;r>1;--r)n+=e();return n+r*e()}}return n.source=t,n}(yf),kf=function t(e){var n=xf.source(e);function r(t){if(0==(t=+t))return e;var r=n(t);return function(){return r()/t}}return r.source=t,r}(yf),qf=function t(e){function n(t){return function(){return-Math.log1p(-e())/t}}return n.source=t,n}(yf),Nf=function t(e){function n(t){if((t=+t)<0)throw new RangeError("invalid alpha");return t=1/-t,function(){return Math.pow(1-e(),t)}}return n.source=t,n}(yf),Sf=function t(e){function n(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return function(){return Math.floor(e()+t)}}return n.source=t,n}(yf),Af=function t(e){function n(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return 0===t?()=>1/0:1===t?()=>1:(t=Math.log1p(-t),function(){return 1+Math.floor(Math.log1p(-e())/t)})}return n.source=t,n}(yf),Mf=function t(e){var n=_f.source(e)();function r(t,r){if((t=+t)<0)throw new RangeError("invalid k");if(0===t)return()=>0;if(r=null==r?1:+r,1===t)return()=>-Math.log1p(-e())*r;var o=(t<1?t+1:t)-1/3,i=1/(3*Math.sqrt(o)),s=t<1?()=>Math.pow(e(),1/t):()=>1;return function(){do{do{var t=n(),a=1+i*t}while(a<=0);a*=a*a;var l=1-e()}while(l>=1-.0331*t*t*t*t&&Math.log(l)>=.5*t*t+o*(1-a+Math.log(a)));return o*a*s()*r}}return r.source=t,r}(yf),Tf=function t(e){var n=Mf.source(e);function r(t,e){var r=n(t),o=n(e);return function(){var t=r();return 0===t?0:t/(t+o())}}return r.source=t,r}(yf),Cf=function t(e){var n=Af.source(e),r=Tf.source(e);function o(t,e){return t=+t,(e=+e)>=1?()=>t:e<=0?()=>0:function(){for(var o=0,i=t,s=e;i*s>16&&i*(1-s)>16;){var a=Math.floor((i+1)*s),l=r(a,i-a+1)();l<=s?(o+=a,i-=a,s=(s-l)/(1-l)):(i=a-1,s/=l)}for(var c=s<.5,u=n(c?s:1-s),f=u(),d=0;f<=i;++d)f+=u();return o+(c?d:i-d)}}return o.source=t,o}(yf),jf=function t(e){function n(t,n,r){var o;return 0==(t=+t)?o=t=>-Math.log(t):(t=1/t,o=e=>Math.pow(e,t)),n=null==n?0:+n,r=null==r?1:+r,function(){return n+r*o(-Math.log1p(-e()))}}return n.source=t,n}(yf),Of=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,function(){return t+n*Math.tan(Math.PI*e())}}return n.source=t,n}(yf),Ef=function t(e){function n(t,n){return t=null==t?0:+t,n=null==n?1:+n,function(){var r=e();return t+n*Math.log(r/(1-r))}}return n.source=t,n}(yf),Rf=function t(e){var n=Mf.source(e),r=Cf.source(e);function o(t){return function(){for(var o=0,i=t;i>16;){var s=Math.floor(.875*i),a=n(s)();if(a>i)return o+r(s-1,i/a)();o+=s,i-=a}for(var l=-Math.log1p(-e()),c=0;l<=i;++c)l-=Math.log1p(-e());return o+c}}return o.source=t,o}(yf),If=1664525,Pf=1013904223,Ff=1/4294967296;function Lf(t=Math.random()){let e=0|(0<=t&&t<1?t/Ff:Math.abs(t));return()=>(e=If*e+Pf|0,Ff*(e>>>0))}var Df=n(502),Bf=n(895);function zf(t){return Dt(Nt(t).call(document.documentElement))}var Zf=0;function $f(){return new Gf}function Gf(){this._="@"+(++Zf).toString(36)}function Uf(t,e){return t.target&&(t=Wt(t),void 0===e&&(e=t.currentTarget),t=t.touches||[t]),Array.from(t,(t=>Ht(t,e)))}function Jf(t){return"string"==typeof t?new Pt([document.querySelectorAll(t)],[document.documentElement]):new Pt([M(t)],It)}function Wf(t){return function(){return t}}Gf.prototype=$f.prototype={constructor:Gf,get:function(t){for(var e=this._;!(e in t);)if(!(t=t.parentNode))return;return t[e]},set:function(t,e){return t[this._]=e},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}};const Hf=Math.abs,Vf=Math.atan2,Yf=Math.cos,Qf=Math.max,Kf=Math.min,Xf=Math.sin,td=Math.sqrt,ed=1e-12,nd=Math.PI,rd=nd/2,od=2*nd;function id(t){return t>=1?rd:t<=-1?-rd:Math.asin(t)}function sd(t){return t.innerRadius}function ad(t){return t.outerRadius}function ld(t){return t.startAngle}function cd(t){return t.endAngle}function ud(t){return t&&t.padAngle}function fd(t,e,n,r,o,i,s){var a=t-n,l=e-r,c=(s?i:-i)/td(a*a+l*l),u=c*l,f=-c*a,d=t+u,h=e+f,p=n+u,m=r+f,g=(d+p)/2,y=(h+m)/2,v=p-d,b=m-h,_=v*v+b*b,w=o-i,x=d*m-p*h,k=(b<0?-1:1)*td(Qf(0,w*w*_-x*x)),q=(x*b-v*k)/_,N=(-x*v-b*k)/_,S=(x*b+v*k)/_,A=(-x*v+b*k)/_,M=q-g,T=N-y,C=S-g,j=A-y;return M*M+T*T>C*C+j*j&&(q=S,N=A),{cx:q,cy:N,x01:-u,y01:-f,x11:q*(o/w-1),y11:N*(o/w-1)}}function dd(){var t=sd,e=ad,n=Wf(0),r=null,o=ld,i=cd,s=ud,a=null;function l(){var l,c,u=+t.apply(this,arguments),f=+e.apply(this,arguments),d=o.apply(this,arguments)-rd,h=i.apply(this,arguments)-rd,p=Hf(h-d),m=h>d;if(a||(a=l=sr()),f<u&&(c=f,f=u,u=c),f>ed)if(p>od-ed)a.moveTo(f*Yf(d),f*Xf(d)),a.arc(0,0,f,d,h,!m),u>ed&&(a.moveTo(u*Yf(h),u*Xf(h)),a.arc(0,0,u,h,d,m));else{var g,y,v=d,b=h,_=d,w=h,x=p,k=p,q=s.apply(this,arguments)/2,N=q>ed&&(r?+r.apply(this,arguments):td(u*u+f*f)),S=Kf(Hf(f-u)/2,+n.apply(this,arguments)),A=S,M=S;if(N>ed){var T=id(N/u*Xf(q)),C=id(N/f*Xf(q));(x-=2*T)>ed?(_+=T*=m?1:-1,w-=T):(x=0,_=w=(d+h)/2),(k-=2*C)>ed?(v+=C*=m?1:-1,b-=C):(k=0,v=b=(d+h)/2)}var j=f*Yf(v),O=f*Xf(v),E=u*Yf(w),R=u*Xf(w);if(S>ed){var I,P=f*Yf(b),F=f*Xf(b),L=u*Yf(_),D=u*Xf(_);if(p<nd&&(I=function(t,e,n,r,o,i,s,a){var l=n-t,c=r-e,u=s-o,f=a-i,d=f*l-u*c;if(!(d*d<ed))return[t+(d=(u*(e-i)-f*(t-o))/d)*l,e+d*c]}(j,O,L,D,P,F,E,R))){var B=j-I[0],z=O-I[1],Z=P-I[0],$=F-I[1],G=1/Xf(function(t){return t>1?0:t<-1?nd:Math.acos(t)}((B*Z+z*$)/(td(B*B+z*z)*td(Z*Z+$*$)))/2),U=td(I[0]*I[0]+I[1]*I[1]);A=Kf(S,(u-U)/(G-1)),M=Kf(S,(f-U)/(G+1))}}k>ed?M>ed?(g=fd(L,D,j,O,f,M,m),y=fd(P,F,E,R,f,M,m),a.moveTo(g.cx+g.x01,g.cy+g.y01),M<S?a.arc(g.cx,g.cy,M,Vf(g.y01,g.x01),Vf(y.y01,y.x01),!m):(a.arc(g.cx,g.cy,M,Vf(g.y01,g.x01),Vf(g.y11,g.x11),!m),a.arc(0,0,f,Vf(g.cy+g.y11,g.cx+g.x11),Vf(y.cy+y.y11,y.cx+y.x11),!m),a.arc(y.cx,y.cy,M,Vf(y.y11,y.x11),Vf(y.y01,y.x01),!m))):(a.moveTo(j,O),a.arc(0,0,f,v,b,!m)):a.moveTo(j,O),u>ed&&x>ed?A>ed?(g=fd(E,R,P,F,u,-A,m),y=fd(j,O,L,D,u,-A,m),a.lineTo(g.cx+g.x01,g.cy+g.y01),A<S?a.arc(g.cx,g.cy,A,Vf(g.y01,g.x01),Vf(y.y01,y.x01),!m):(a.arc(g.cx,g.cy,A,Vf(g.y01,g.x01),Vf(g.y11,g.x11),!m),a.arc(0,0,u,Vf(g.cy+g.y11,g.cx+g.x11),Vf(y.cy+y.y11,y.cx+y.x11),m),a.arc(y.cx,y.cy,A,Vf(y.y11,y.x11),Vf(y.y01,y.x01),!m))):a.arc(0,0,u,w,_,m):a.lineTo(E,R)}else a.moveTo(0,0);if(a.closePath(),l)return a=null,l+""||null}return l.centroid=function(){var n=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,r=(+o.apply(this,arguments)+ +i.apply(this,arguments))/2-nd/2;return[Yf(r)*n,Xf(r)*n]},l.innerRadius=function(e){return arguments.length?(t="function"==typeof e?e:Wf(+e),l):t},l.outerRadius=function(t){return arguments.length?(e="function"==typeof t?t:Wf(+t),l):e},l.cornerRadius=function(t){return arguments.length?(n="function"==typeof t?t:Wf(+t),l):n},l.padRadius=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Wf(+t),l):r},l.startAngle=function(t){return arguments.length?(o="function"==typeof t?t:Wf(+t),l):o},l.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:Wf(+t),l):i},l.padAngle=function(t){return arguments.length?(s="function"==typeof t?t:Wf(+t),l):s},l.context=function(t){return arguments.length?(a=null==t?null:t,l):a},l}var hd=Array.prototype.slice;function pd(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function md(t){this._context=t}function gd(t){return new md(t)}function yd(t){return t[0]}function vd(t){return t[1]}function bd(t,e){var n=Wf(!0),r=null,o=gd,i=null;function s(s){var a,l,c,u=(s=pd(s)).length,f=!1;for(null==r&&(i=o(c=sr())),a=0;a<=u;++a)!(a<u&&n(l=s[a],a,s))===f&&((f=!f)?i.lineStart():i.lineEnd()),f&&i.point(+t(l,a,s),+e(l,a,s));if(c)return i=null,c+""||null}return t="function"==typeof t?t:void 0===t?yd:Wf(t),e="function"==typeof e?e:void 0===e?vd:Wf(e),s.x=function(e){return arguments.length?(t="function"==typeof e?e:Wf(+e),s):t},s.y=function(t){return arguments.length?(e="function"==typeof t?t:Wf(+t),s):e},s.defined=function(t){return arguments.length?(n="function"==typeof t?t:Wf(!!t),s):n},s.curve=function(t){return arguments.length?(o=t,null!=r&&(i=o(r)),s):o},s.context=function(t){return arguments.length?(null==t?r=i=null:i=o(r=t),s):r},s}function _d(t,e,n){var r=null,o=Wf(!0),i=null,s=gd,a=null;function l(l){var c,u,f,d,h,p=(l=pd(l)).length,m=!1,g=new Array(p),y=new Array(p);for(null==i&&(a=s(h=sr())),c=0;c<=p;++c){if(!(c<p&&o(d=l[c],c,l))===m)if(m=!m)u=c,a.areaStart(),a.lineStart();else{for(a.lineEnd(),a.lineStart(),f=c-1;f>=u;--f)a.point(g[f],y[f]);a.lineEnd(),a.areaEnd()}m&&(g[c]=+t(d,c,l),y[c]=+e(d,c,l),a.point(r?+r(d,c,l):g[c],n?+n(d,c,l):y[c]))}if(h)return a=null,h+""||null}function c(){return bd().defined(o).curve(s).context(i)}return t="function"==typeof t?t:void 0===t?yd:Wf(+t),e="function"==typeof e?e:Wf(void 0===e?0:+e),n="function"==typeof n?n:void 0===n?vd:Wf(+n),l.x=function(e){return arguments.length?(t="function"==typeof e?e:Wf(+e),r=null,l):t},l.x0=function(e){return arguments.length?(t="function"==typeof e?e:Wf(+e),l):t},l.x1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Wf(+t),l):r},l.y=function(t){return arguments.length?(e="function"==typeof t?t:Wf(+t),n=null,l):e},l.y0=function(t){return arguments.length?(e="function"==typeof t?t:Wf(+t),l):e},l.y1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:Wf(+t),l):n},l.lineX0=l.lineY0=function(){return c().x(t).y(e)},l.lineY1=function(){return c().x(t).y(n)},l.lineX1=function(){return c().x(r).y(e)},l.defined=function(t){return arguments.length?(o="function"==typeof t?t:Wf(!!t),l):o},l.curve=function(t){return arguments.length?(s=t,null!=i&&(a=s(i)),l):s},l.context=function(t){return arguments.length?(null==t?i=a=null:a=s(i=t),l):i},l}function wd(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function xd(t){return t}function kd(){var t=xd,e=wd,n=null,r=Wf(0),o=Wf(od),i=Wf(0);function s(s){var a,l,c,u,f,d=(s=pd(s)).length,h=0,p=new Array(d),m=new Array(d),g=+r.apply(this,arguments),y=Math.min(od,Math.max(-od,o.apply(this,arguments)-g)),v=Math.min(Math.abs(y)/d,i.apply(this,arguments)),b=v*(y<0?-1:1);for(a=0;a<d;++a)(f=m[p[a]=a]=+t(s[a],a,s))>0&&(h+=f);for(null!=e?p.sort((function(t,n){return e(m[t],m[n])})):null!=n&&p.sort((function(t,e){return n(s[t],s[e])})),a=0,c=h?(y-d*b)/h:0;a<d;++a,g=u)l=p[a],u=g+((f=m[l])>0?f*c:0)+b,m[l]={data:s[l],index:a,value:f,startAngle:g,endAngle:u,padAngle:v};return m}return s.value=function(e){return arguments.length?(t="function"==typeof e?e:Wf(+e),s):t},s.sortValues=function(t){return arguments.length?(e=t,n=null,s):e},s.sort=function(t){return arguments.length?(n=t,e=null,s):n},s.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:Wf(+t),s):r},s.endAngle=function(t){return arguments.length?(o="function"==typeof t?t:Wf(+t),s):o},s.padAngle=function(t){return arguments.length?(i="function"==typeof t?t:Wf(+t),s):i},s}md.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}};var qd=Sd(gd);function Nd(t){this._curve=t}function Sd(t){function e(e){return new Nd(t(e))}return e._curve=t,e}function Ad(t){var e=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?e(Sd(t)):e()._curve},t}function Md(){return Ad(bd().curve(qd))}function Td(){var t=_d().curve(qd),e=t.curve,n=t.lineX0,r=t.lineX1,o=t.lineY0,i=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return Ad(n())},delete t.lineX0,t.lineEndAngle=function(){return Ad(r())},delete t.lineX1,t.lineInnerRadius=function(){return Ad(o())},delete t.lineY0,t.lineOuterRadius=function(){return Ad(i())},delete t.lineY1,t.curve=function(t){return arguments.length?e(Sd(t)):e()._curve},t}function Cd(t,e){return[(e=+e)*Math.cos(t-=Math.PI/2),e*Math.sin(t)]}Nd.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,e){this._curve.point(e*Math.sin(t),e*-Math.cos(t))}};class jd{constructor(t,e){this._context=t,this._x=e}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line}point(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+t)/2,this._y0,this._x0,e,t,e):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+e)/2,t,this._y0,t,e)}this._x0=t,this._y0=e}}class Od{constructor(t){this._context=t}lineStart(){this._point=0}lineEnd(){}point(t,e){if(t=+t,e=+e,0==this._point++)this._x0=t,this._y0=e;else{const n=Cd(this._x0,this._y0),r=Cd(this._x0,this._y0=(this._y0+e)/2),o=Cd(t,this._y0),i=Cd(t,e);this._context.moveTo(...n),this._context.bezierCurveTo(...r,...o,...i)}}}function Ed(t){return new jd(t,!0)}function Rd(t){return new jd(t,!1)}function Id(t){return new Od(t)}function Pd(t){return t.source}function Fd(t){return t.target}function Ld(t){let e=Pd,n=Fd,r=yd,o=vd,i=null,s=null;function a(){let a;const l=hd.call(arguments),c=e.apply(this,l),u=n.apply(this,l);if(null==i&&(s=t(a=sr())),s.lineStart(),l[0]=c,s.point(+r.apply(this,l),+o.apply(this,l)),l[0]=u,s.point(+r.apply(this,l),+o.apply(this,l)),s.lineEnd(),a)return s=null,a+""||null}return a.source=function(t){return arguments.length?(e=t,a):e},a.target=function(t){return arguments.length?(n=t,a):n},a.x=function(t){return arguments.length?(r="function"==typeof t?t:Wf(+t),a):r},a.y=function(t){return arguments.length?(o="function"==typeof t?t:Wf(+t),a):o},a.context=function(e){return arguments.length?(null==e?i=s=null:s=t(i=e),a):i},a}function Dd(){return Ld(Ed)}function Bd(){return Ld(Rd)}function zd(){const t=Ld(Id);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t}const Zd=td(3),$d={draw(t,e){const n=.59436*td(e+Kf(e/28,.75)),r=n/2,o=r*Zd;t.moveTo(0,n),t.lineTo(0,-n),t.moveTo(-o,-r),t.lineTo(o,r),t.moveTo(-o,r),t.lineTo(o,-r)}},Gd={draw(t,e){const n=td(e/nd);t.moveTo(n,0),t.arc(0,0,n,0,od)}},Ud={draw(t,e){const n=td(e/5)/2;t.moveTo(-3*n,-n),t.lineTo(-n,-n),t.lineTo(-n,-3*n),t.lineTo(n,-3*n),t.lineTo(n,-n),t.lineTo(3*n,-n),t.lineTo(3*n,n),t.lineTo(n,n),t.lineTo(n,3*n),t.lineTo(-n,3*n),t.lineTo(-n,n),t.lineTo(-3*n,n),t.closePath()}},Jd=td(1/3),Wd=2*Jd,Hd={draw(t,e){const n=td(e/Wd),r=n*Jd;t.moveTo(0,-n),t.lineTo(r,0),t.lineTo(0,n),t.lineTo(-r,0),t.closePath()}},Vd={draw(t,e){const n=.62625*td(e);t.moveTo(0,-n),t.lineTo(n,0),t.lineTo(0,n),t.lineTo(-n,0),t.closePath()}},Yd={draw(t,e){const n=.87559*td(e-Kf(e/7,2));t.moveTo(-n,0),t.lineTo(n,0),t.moveTo(0,n),t.lineTo(0,-n)}},Qd={draw(t,e){const n=td(e),r=-n/2;t.rect(r,r,n,n)}},Kd={draw(t,e){const n=.4431*td(e);t.moveTo(n,n),t.lineTo(n,-n),t.lineTo(-n,-n),t.lineTo(-n,n),t.closePath()}},Xd=Xf(nd/10)/Xf(7*nd/10),th=Xf(od/10)*Xd,eh=-Yf(od/10)*Xd,nh={draw(t,e){const n=td(.8908130915292852*e),r=th*n,o=eh*n;t.moveTo(0,-n),t.lineTo(r,o);for(let e=1;e<5;++e){const i=od*e/5,s=Yf(i),a=Xf(i);t.lineTo(a*n,-s*n),t.lineTo(s*r-a*o,a*r+s*o)}t.closePath()}},rh=td(3),oh={draw(t,e){const n=-td(e/(3*rh));t.moveTo(0,2*n),t.lineTo(-rh*n,-n),t.lineTo(rh*n,-n),t.closePath()}},ih=td(3),sh={draw(t,e){const n=.6824*td(e),r=n/2,o=n*ih/2;t.moveTo(0,-n),t.lineTo(o,r),t.lineTo(-o,r),t.closePath()}},ah=-.5,lh=td(3)/2,ch=1/td(12),uh=3*(ch/2+1),fh={draw(t,e){const n=td(e/uh),r=n/2,o=n*ch,i=r,s=n*ch+n,a=-i,l=s;t.moveTo(r,o),t.lineTo(i,s),t.lineTo(a,l),t.lineTo(ah*r-lh*o,lh*r+ah*o),t.lineTo(ah*i-lh*s,lh*i+ah*s),t.lineTo(ah*a-lh*l,lh*a+ah*l),t.lineTo(ah*r+lh*o,ah*o-lh*r),t.lineTo(ah*i+lh*s,ah*s-lh*i),t.lineTo(ah*a+lh*l,ah*l-lh*a),t.closePath()}},dh={draw(t,e){const n=.6189*td(e-Kf(e/6,1.7));t.moveTo(-n,-n),t.lineTo(n,n),t.moveTo(-n,n),t.lineTo(n,-n)}},hh=[Gd,Ud,Hd,Qd,nh,oh,fh],ph=[Gd,Yd,dh,sh,$d,Kd,Vd];function mh(t,e){let n=null;function r(){let r;if(n||(n=r=sr()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),r)return n=null,r+""||null}return t="function"==typeof t?t:Wf(t||Gd),e="function"==typeof e?e:Wf(void 0===e?64:+e),r.type=function(e){return arguments.length?(t="function"==typeof e?e:Wf(e),r):t},r.size=function(t){return arguments.length?(e="function"==typeof t?t:Wf(+t),r):e},r.context=function(t){return arguments.length?(n=null==t?null:t,r):n},r}function gh(){}function yh(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function vh(t){this._context=t}function bh(t){return new vh(t)}function _h(t){this._context=t}function wh(t){return new _h(t)}function xh(t){this._context=t}function kh(t){return new xh(t)}function qh(t,e){this._basis=new vh(t),this._beta=e}vh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:yh(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:yh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},_h.prototype={areaStart:gh,areaEnd:gh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:yh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},xh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:yh(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},qh.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,n=t.length-1;if(n>0)for(var r,o=t[0],i=e[0],s=t[n]-o,a=e[n]-i,l=-1;++l<=n;)r=l/n,this._basis.point(this._beta*t[l]+(1-this._beta)*(o+r*s),this._beta*e[l]+(1-this._beta)*(i+r*a));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};const Nh=function t(e){function n(t){return 1===e?new vh(t):new qh(t,e)}return n.beta=function(e){return t(+e)},n}(.85);function Sh(t,e,n){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-n),t._x2,t._y2)}function Ah(t,e){this._context=t,this._k=(1-e)/6}Ah.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Sh(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:Sh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Mh=function t(e){function n(t){return new Ah(t,e)}return n.tension=function(e){return t(+e)},n}(0);function Th(t,e){this._context=t,this._k=(1-e)/6}Th.prototype={areaStart:gh,areaEnd:gh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:Sh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Ch=function t(e){function n(t){return new Th(t,e)}return n.tension=function(e){return t(+e)},n}(0);function jh(t,e){this._context=t,this._k=(1-e)/6}jh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Sh(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Oh=function t(e){function n(t){return new jh(t,e)}return n.tension=function(e){return t(+e)},n}(0);function Eh(t,e,n){var r=t._x1,o=t._y1,i=t._x2,s=t._y2;if(t._l01_a>ed){var a=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,l=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*a-t._x0*t._l12_2a+t._x2*t._l01_2a)/l,o=(o*a-t._y0*t._l12_2a+t._y2*t._l01_2a)/l}if(t._l23_a>ed){var c=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,u=3*t._l23_a*(t._l23_a+t._l12_a);i=(i*c+t._x1*t._l23_2a-e*t._l12_2a)/u,s=(s*c+t._y1*t._l23_2a-n*t._l12_2a)/u}t._context.bezierCurveTo(r,o,i,s,t._x2,t._y2)}function Rh(t,e){this._context=t,this._alpha=e}Rh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:Eh(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Ih=function t(e){function n(t){return e?new Rh(t,e):new Ah(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function Ph(t,e){this._context=t,this._alpha=e}Ph.prototype={areaStart:gh,areaEnd:gh,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:Eh(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Fh=function t(e){function n(t){return e?new Ph(t,e):new Th(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function Lh(t,e){this._context=t,this._alpha=e}Lh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Eh(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Dh=function t(e){function n(t){return e?new Lh(t,e):new jh(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function Bh(t){this._context=t}function zh(t){return new Bh(t)}function Zh(t){return t<0?-1:1}function $h(t,e,n){var r=t._x1-t._x0,o=e-t._x1,i=(t._y1-t._y0)/(r||o<0&&-0),s=(n-t._y1)/(o||r<0&&-0),a=(i*o+s*r)/(r+o);return(Zh(i)+Zh(s))*Math.min(Math.abs(i),Math.abs(s),.5*Math.abs(a))||0}function Gh(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function Uh(t,e,n){var r=t._x0,o=t._y0,i=t._x1,s=t._y1,a=(i-r)/3;t._context.bezierCurveTo(r+a,o+a*e,i-a,s-a*n,i,s)}function Jh(t){this._context=t}function Wh(t){this._context=new Hh(t)}function Hh(t){this._context=t}function Vh(t){return new Jh(t)}function Yh(t){return new Wh(t)}function Qh(t){this._context=t}function Kh(t){var e,n,r=t.length-1,o=new Array(r),i=new Array(r),s=new Array(r);for(o[0]=0,i[0]=2,s[0]=t[0]+2*t[1],e=1;e<r-1;++e)o[e]=1,i[e]=4,s[e]=4*t[e]+2*t[e+1];for(o[r-1]=2,i[r-1]=7,s[r-1]=8*t[r-1]+t[r],e=1;e<r;++e)n=o[e]/i[e-1],i[e]-=n,s[e]-=n*s[e-1];for(o[r-1]=s[r-1]/i[r-1],e=r-2;e>=0;--e)o[e]=(s[e]-o[e+1])/i[e];for(i[r-1]=(t[r]+o[r-1])/2,e=0;e<r-1;++e)i[e]=2*t[e+1]-o[e+1];return[o,i]}function Xh(t){return new Qh(t)}function tp(t,e){this._context=t,this._t=e}function ep(t){return new tp(t,.5)}function np(t){return new tp(t,0)}function rp(t){return new tp(t,1)}function op(t,e){if((o=t.length)>1)for(var n,r,o,i=1,s=t[e[0]],a=s.length;i<o;++i)for(r=s,s=t[e[i]],n=0;n<a;++n)s[n][1]+=s[n][0]=isNaN(r[n][1])?r[n][0]:r[n][1]}function ip(t){for(var e=t.length,n=new Array(e);--e>=0;)n[e]=e;return n}function sp(t,e){return t[e]}function ap(t){const e=[];return e.key=t,e}function lp(){var t=Wf([]),e=ip,n=op,r=sp;function o(o){var i,s,a=Array.from(t.apply(this,arguments),ap),l=a.length,c=-1;for(const t of o)for(i=0,++c;i<l;++i)(a[i][c]=[0,+r(t,a[i].key,c,o)]).data=t;for(i=0,s=pd(e(a));i<l;++i)a[s[i]].index=i;return n(a,s),a}return o.keys=function(e){return arguments.length?(t="function"==typeof e?e:Wf(Array.from(e)),o):t},o.value=function(t){return arguments.length?(r="function"==typeof t?t:Wf(+t),o):r},o.order=function(t){return arguments.length?(e=null==t?ip:"function"==typeof t?t:Wf(Array.from(t)),o):e},o.offset=function(t){return arguments.length?(n=null==t?op:t,o):n},o}function cp(t,e){if((r=t.length)>0){for(var n,r,o,i=0,s=t[0].length;i<s;++i){for(o=n=0;n<r;++n)o+=t[n][i][1]||0;if(o)for(n=0;n<r;++n)t[n][i][1]/=o}op(t,e)}}function up(t,e){if((a=t.length)>0)for(var n,r,o,i,s,a,l=0,c=t[e[0]].length;l<c;++l)for(i=s=0,n=0;n<a;++n)(o=(r=t[e[n]][l])[1]-r[0])>0?(r[0]=i,r[1]=i+=o):o<0?(r[1]=s,r[0]=s+=o):(r[0]=0,r[1]=o)}function fp(t,e){if((n=t.length)>0){for(var n,r=0,o=t[e[0]],i=o.length;r<i;++r){for(var s=0,a=0;s<n;++s)a+=t[s][r][1]||0;o[r][1]+=o[r][0]=-a/2}op(t,e)}}function dp(t,e){if((o=t.length)>0&&(r=(n=t[e[0]]).length)>0){for(var n,r,o,i=0,s=1;s<r;++s){for(var a=0,l=0,c=0;a<o;++a){for(var u=t[e[a]],f=u[s][1]||0,d=(f-(u[s-1][1]||0))/2,h=0;h<a;++h){var p=t[e[h]];d+=(p[s][1]||0)-(p[s-1][1]||0)}l+=f,c+=d*f}n[s-1][1]+=n[s-1][0]=i,l&&(i-=c/l)}n[s-1][1]+=n[s-1][0]=i,op(t,e)}}function hp(t){var e=t.map(pp);return ip(t).sort((function(t,n){return e[t]-e[n]}))}function pp(t){for(var e,n=-1,r=0,o=t.length,i=-1/0;++n<o;)(e=+t[n][1])>i&&(i=e,r=n);return r}function mp(t){var e=t.map(gp);return ip(t).sort((function(t,n){return e[t]-e[n]}))}function gp(t){for(var e,n=0,r=-1,o=t.length;++r<o;)(e=+t[r][1])&&(n+=e);return n}function yp(t){return mp(t).reverse()}function vp(t){var e,n,r=t.length,o=t.map(gp),i=hp(t),s=0,a=0,l=[],c=[];for(e=0;e<r;++e)n=i[e],s<a?(s+=o[n],l.push(n)):(a+=o[n],c.push(n));return c.reverse().concat(l)}function bp(t){return ip(t).reverse()}Bh.prototype={areaStart:gh,areaEnd:gh,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}},Jh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Uh(this,this._t0,Gh(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(e=+e,(t=+t)!==this._x1||e!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,Uh(this,Gh(this,n=$h(this,t,e)),n);break;default:Uh(this,this._t0,n=$h(this,t,e))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}},(Wh.prototype=Object.create(Jh.prototype)).point=function(t,e){Jh.prototype.point.call(this,e,t)},Hh.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,n,r,o,i){this._context.bezierCurveTo(e,t,r,n,i,o)}},Qh.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,n=t.length;if(n)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),2===n)this._context.lineTo(t[1],e[1]);else for(var r=Kh(t),o=Kh(e),i=0,s=1;s<n;++i,++s)this._context.bezierCurveTo(r[0][i],o[0][i],r[1][i],o[1][i],t[s],e[s]);(this._line||0!==this._line&&1===n)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,e){this._x.push(+t),this._y.push(+e)}},tp.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var _p=n(3606),wp=n(8383),xp=n(1343),kp=n(2991),qp=n(6596),Np=n(8467),Sp=n(6018),Ap=n(7905),Mp=n(2311),Tp=n(8593),Cp=n(8927),jp=n(7445),Op=n(1887),Ep=n(7351),Rp=n(4552),Ip=n(7150),Pp=n(1852),Fp=n(3015),Lp="%Y-%m-%dT%H:%M:%S.%LZ";const Dp=Date.prototype.toISOString?function(t){return t.toISOString()}:(0,Pp.g0)(Lp);var Bp=+new Date("2000-01-01T00:00:00.000Z")?function(t){var e=new Date(t);return isNaN(e)?null:e}:(0,Pp.wp)(Lp);const zp=Bp;function Zp(t,e,n){var r=new le,o=e;return null==e?(r.restart(t,e,n),r):(r._restart=r.restart,r.restart=function(t,e,n){e=+e,n=null==n?se():+n,r._restart((function i(s){s+=o,r._restart(i,o+=e,n),t(s)}),e,n)},r.restart(t,e,n),r)}var $p=n(6564);const Gp=t=>()=>t;function Up(t,{sourceEvent:e,target:n,transform:r,dispatch:o}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:o}})}function Jp(t,e,n){this.k=t,this.x=e,this.y=n}Jp.prototype={constructor:Jp,scale:function(t){return 1===t?this:new Jp(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Jp(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Wp=new Jp(1,0,0);function Hp(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Wp;return t.__zoom}function Vp(t){t.stopImmediatePropagation()}function Yp(t){t.preventDefault(),t.stopImmediatePropagation()}function Qp(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Kp(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Xp(){return this.__zoom||Wp}function tm(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function em(){return navigator.maxTouchPoints||"ontouchstart"in this}function nm(t,e,n){var r=t.invertX(e[0][0])-n[0][0],o=t.invertX(e[1][0])-n[1][0],i=t.invertY(e[0][1])-n[0][1],s=t.invertY(e[1][1])-n[1][1];return t.translate(o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o),s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s))}function rm(){var t,e,n,r=Qp,o=Kp,i=nm,s=tm,a=em,l=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],u=250,f=$p.Z,d=N("start","zoom","end"),h=500,p=150,m=0,g=10;function y(t){t.property("__zoom",Xp).on("wheel.zoom",q,{passive:!1}).on("mousedown.zoom",S).on("dblclick.zoom",A).filter(a).on("touchstart.zoom",M).on("touchmove.zoom",T).on("touchend.zoom touchcancel.zoom",C).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function v(t,e){return(e=Math.max(l[0],Math.min(l[1],e)))===t.k?t:new Jp(e,t.x,t.y)}function b(t,e,n){var r=e[0]-n[0]*t.k,o=e[1]-n[1]*t.k;return r===t.x&&o===t.y?t:new Jp(t.k,r,o)}function _(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function w(t,e,n,r){t.on("start.zoom",(function(){x(this,arguments).event(r).start()})).on("interrupt.zoom end.zoom",(function(){x(this,arguments).event(r).end()})).tween("zoom",(function(){var t=this,i=arguments,s=x(t,i).event(r),a=o.apply(t,i),l=null==n?_(a):"function"==typeof n?n.apply(t,i):n,c=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),u=t.__zoom,d="function"==typeof e?e.apply(t,i):e,h=f(u.invert(l).concat(c/u.k),d.invert(l).concat(c/d.k));return function(t){if(1===t)t=d;else{var e=h(t),n=c/e[2];t=new Jp(n,l[0]-e[0]*n,l[1]-e[1]*n)}s.zoom(null,t)}}))}function x(t,e,n){return!n&&t.__zooming||new k(t,e)}function k(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=o.apply(t,e),this.taps=0}function q(t,...e){if(r.apply(this,arguments)){var n=x(this,e).event(t),o=this.__zoom,a=Math.max(l[0],Math.min(l[1],o.k*Math.pow(2,s.apply(this,arguments)))),u=Ht(t);if(n.wheel)n.mouse[0][0]===u[0]&&n.mouse[0][1]===u[1]||(n.mouse[1]=o.invert(n.mouse[0]=u)),clearTimeout(n.wheel);else{if(o.k===a)return;n.mouse=[u,o.invert(u)],Me(this),n.start()}Yp(t),n.wheel=setTimeout((function(){n.wheel=null,n.end()}),p),n.zoom("mouse",i(b(v(o,a),n.mouse[0],n.mouse[1]),n.extent,c))}}function S(t,...e){if(!n&&r.apply(this,arguments)){var o=t.currentTarget,s=x(this,e,!0).event(t),a=Dt(t.view).on("mousemove.zoom",(function(t){if(Yp(t),!s.moved){var e=t.clientX-u,n=t.clientY-f;s.moved=e*e+n*n>m}s.event(t).zoom("mouse",i(b(s.that.__zoom,s.mouse[0]=Ht(t,o),s.mouse[1]),s.extent,c))}),!0).on("mouseup.zoom",(function(t){a.on("mousemove.zoom mouseup.zoom",null),Ut(t.view,s.moved),Yp(t),s.event(t).end()}),!0),l=Ht(t,o),u=t.clientX,f=t.clientY;Gt(t.view),Vp(t),s.mouse=[l,this.__zoom.invert(l)],Me(this),s.start()}}function A(t,...e){if(r.apply(this,arguments)){var n=this.__zoom,s=Ht(t.changedTouches?t.changedTouches[0]:t,this),a=n.invert(s),l=n.k*(t.shiftKey?.5:2),f=i(b(v(n,l),s,a),o.apply(this,e),c);Yp(t),u>0?Dt(this).transition().duration(u).call(w,f,s,t):Dt(this).call(y.transform,f,s,t)}}function M(n,...o){if(r.apply(this,arguments)){var i,s,a,l,c=n.touches,u=c.length,f=x(this,o,n.changedTouches.length===u).event(n);for(Vp(n),s=0;s<u;++s)l=[l=Ht(a=c[s],this),this.__zoom.invert(l),a.identifier],f.touch0?f.touch1||f.touch0[2]===l[2]||(f.touch1=l,f.taps=0):(f.touch0=l,i=!0,f.taps=1+!!t);t&&(t=clearTimeout(t)),i&&(f.taps<2&&(e=l[0],t=setTimeout((function(){t=null}),h)),Me(this),f.start())}}function T(t,...e){if(this.__zooming){var n,r,o,s,a=x(this,e).event(t),l=t.changedTouches,u=l.length;for(Yp(t),n=0;n<u;++n)o=Ht(r=l[n],this),a.touch0&&a.touch0[2]===r.identifier?a.touch0[0]=o:a.touch1&&a.touch1[2]===r.identifier&&(a.touch1[0]=o);if(r=a.that.__zoom,a.touch1){var f=a.touch0[0],d=a.touch0[1],h=a.touch1[0],p=a.touch1[1],m=(m=h[0]-f[0])*m+(m=h[1]-f[1])*m,g=(g=p[0]-d[0])*g+(g=p[1]-d[1])*g;r=v(r,Math.sqrt(m/g)),o=[(f[0]+h[0])/2,(f[1]+h[1])/2],s=[(d[0]+p[0])/2,(d[1]+p[1])/2]}else{if(!a.touch0)return;o=a.touch0[0],s=a.touch0[1]}a.zoom("touch",i(b(r,o,s),a.extent,c))}}function C(t,...r){if(this.__zooming){var o,i,s=x(this,r).event(t),a=t.changedTouches,l=a.length;for(Vp(t),n&&clearTimeout(n),n=setTimeout((function(){n=null}),h),o=0;o<l;++o)i=a[o],s.touch0&&s.touch0[2]===i.identifier?delete s.touch0:s.touch1&&s.touch1[2]===i.identifier&&delete s.touch1;if(s.touch1&&!s.touch0&&(s.touch0=s.touch1,delete s.touch1),s.touch0)s.touch0[1]=this.__zoom.invert(s.touch0[0]);else if(s.end(),2===s.taps&&(i=Ht(i,this),Math.hypot(e[0]-i[0],e[1]-i[1])<g)){var c=Dt(this).on("dblclick.zoom");c&&c.apply(this,arguments)}}}return y.transform=function(t,e,n,r){var o=t.selection?t.selection():t;o.property("__zoom",Xp),t!==o?w(t,e,n,r):o.interrupt().each((function(){x(this,arguments).event(r).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()}))},y.scaleBy=function(t,e,n,r){y.scaleTo(t,(function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)}),n,r)},y.scaleTo=function(t,e,n,r){y.transform(t,(function(){var t=o.apply(this,arguments),r=this.__zoom,s=null==n?_(t):"function"==typeof n?n.apply(this,arguments):n,a=r.invert(s),l="function"==typeof e?e.apply(this,arguments):e;return i(b(v(r,l),s,a),t,c)}),n,r)},y.translateBy=function(t,e,n,r){y.transform(t,(function(){return i(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof n?n.apply(this,arguments):n),o.apply(this,arguments),c)}),null,r)},y.translateTo=function(t,e,n,r,s){y.transform(t,(function(){var t=o.apply(this,arguments),s=this.__zoom,a=null==r?_(t):"function"==typeof r?r.apply(this,arguments):r;return i(Wp.translate(a[0],a[1]).scale(s.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof n?-n.apply(this,arguments):-n),t,c)}),r,s)},k.prototype={event:function(t){return t&&(this.sourceEvent=t),this},start:function(){return 1==++this.active&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(t,e){return this.mouse&&"mouse"!==t&&(this.mouse[1]=e.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=e.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=e.invert(this.touch1[0])),this.that.__zoom=e,this.emit("zoom"),this},end:function(){return 0==--this.active&&(delete this.that.__zooming,this.emit("end")),this},emit:function(t){var e=Dt(this.that).datum();d.call(t,this.that,new Up(t,{sourceEvent:this.sourceEvent,target:y,type:t,transform:this.that.__zoom,dispatch:d}),e)}},y.wheelDelta=function(t){return arguments.length?(s="function"==typeof t?t:Gp(+t),y):s},y.filter=function(t){return arguments.length?(r="function"==typeof t?t:Gp(!!t),y):r},y.touchable=function(t){return arguments.length?(a="function"==typeof t?t:Gp(!!t),y):a},y.extent=function(t){return arguments.length?(o="function"==typeof t?t:Gp([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),y):o},y.scaleExtent=function(t){return arguments.length?(l[0]=+t[0],l[1]=+t[1],y):[l[0],l[1]]},y.translateExtent=function(t){return arguments.length?(c[0][0]=+t[0][0],c[1][0]=+t[1][0],c[0][1]=+t[0][1],c[1][1]=+t[1][1],y):[[c[0][0],c[0][1]],[c[1][0],c[1][1]]]},y.constrain=function(t){return arguments.length?(i=t,y):i},y.duration=function(t){return arguments.length?(u=+t,y):u},y.interpolate=function(t){return arguments.length?(f=t,y):f},y.on=function(){var t=d.on.apply(d,arguments);return t===d?y:t},y.clickDistance=function(t){return arguments.length?(m=(t=+t)*t,y):Math.sqrt(m)},y.tapDistance=function(t){return arguments.length?(g=+t,y):g},y}Hp.prototype=Jp.prototype},8828:(t,e,n)=>{"use strict";n.d(e,{H:()=>o,L:()=>r});class r extends Map{constructor(t,e=l){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(i(this,t))}has(t){return super.has(i(this,t))}set(t,e){return super.set(s(this,t),e)}delete(t){return super.delete(a(this,t))}}class o extends Set{constructor(t,e=l){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const e of t)this.add(e)}has(t){return super.has(i(this,t))}add(t){return super.add(s(this,t))}delete(t){return super.delete(a(this,t))}}function i({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function s({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}function a({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}function l(t){return null!==t&&"object"==typeof t?t.valueOf():t}}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};r(9699)})();
|