"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[4244],{84244:(e,t,n)=>{n.r(t),n.d(t,{default:()=>j});var i=n(7552),r=n(49823),s=n(99546),o=n(91468),l=n(29499),a=n(36715),c=n(5401),u=n(1343),p=n(58507),d=n(31409),h=n.n(d),g=n(45465),x=n(36422),y=n(75785),m=n(69500);const f=(0,y.n9)()((e=>({textAreaFont:{fontFamily:"Courier New"},mgap:{display:"flex",flexDirection:"column",gap:e.spacing(4)}})));function j({model:e,handleClose:t}){const{classes:n}=f(),[d,y]=(0,i.useState)(),[j,w]=(0,i.useState)(),[b,v]=(0,i.useState)("");return(0,i.useEffect)((()=>{(async()=>{try{w(void 0);const t=(0,s.getContainingView)(e);if(!t.initialized)return;const{rpcManager:n}=(0,s.getSession)(e),{sources:i,minorAlleleFrequencyFilter:r,adapterConfig:l}=e,a=(0,o.getRpcSessionId)(e),c=await n.call(a,"MultiVariantGetGenotypeMatrix",{regions:t.dynamicBlocks.contentBlocks,sources:i,minorAlleleFrequencyFilter:r,sessionId:a,adapterConfig:l}),u=Object.values(c),p=Object.keys(c),d=`try(library(fastcluster), silent=TRUE)\ninputMatrix<-matrix(c(${u.map((e=>e.genotypes.join(","))).join(",\n")}\n),nrow=${u.length},byrow=TRUE)\nrownames(inputMatrix)<-c(${p.map((e=>`'${e}'`)).join(",")})\nresultClusters<-hclust(dist(inputMatrix), method='single')\ncat(resultClusters$order,sep='\\n')`;y(d)}catch(t){!(0,s.isAbortException)(t)&&(0,x.isAlive)(e)&&(console.error(t),w(t))}})()}),[e]),(0,m.jsxs)(r.Dialog,{open:!0,title:"Cluster by genotype",onClose:t,children:[(0,m.jsx)(l.A,{children:(0,m.jsxs)("div",{className:n.mgap,children:[(0,m.jsx)(a.A,{children:"This page will produce an R script that will perform hierarchical clustering on the visible genotype data using `hclust`."}),(0,m.jsx)(a.A,{children:"You can then paste the results in this form to specify the row ordering."}),d?(0,m.jsx)("div",{children:(0,m.jsxs)("div",{children:["Step 1:"," ",(0,m.jsx)(c.A,{variant:"contained",onClick:()=>{(0,g.saveAs)(new Blob([d||""],{type:"text/plain;charset=utf-8"}),"cluster.R")},children:"Download Rscript"})," ","or"," ",(0,m.jsx)(c.A,{variant:"contained",onClick:()=>{h()(d||"")},children:"Copy Rscript to clipboard"}),(0,m.jsx)("div",{children:(0,m.jsx)(u.A,{multiline:!0,fullWidth:!0,variant:"outlined",placeholder:"Step 2. Paste results from Rscript here (sequence of numbers, one per line, specifying the new ordering)",rows:10,value:b,onChange:e=>{v(e.target.value)},slotProps:{input:{classes:{input:n.textAreaFont}}}})})]})}):(0,m.jsx)(r.LoadingEllipses,{variant:"h6",title:"Generating genotype matrix"}),j?(0,m.jsx)(r.ErrorMessage,{error:j}):null]})}),(0,m.jsxs)(p.A,{children:[(0,m.jsx)(c.A,{disabled:!d,variant:"contained",onClick:()=>{const{sources:n}=e;if(n)try{e.setLayout(b.split("\n").map((e=>e.trim())).filter((e=>!!e)).map((e=>+e)).map((e=>{const t=n[e-1];if(!t)throw new Error(`out of bounds at ${e}`);return t})))}catch(e){console.error(e),w(e)}t()},children:"Apply clustering"}),(0,m.jsx)(c.A,{variant:"contained",color:"secondary",onClick:()=>{t()},children:"Cancel"})]})]})}}}]);
//# sourceMappingURL=4244.bbb61f10.chunk.js.map