(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[5813],{2401:e=>{var t=/\{([0-9a-zA-Z_]+)\}/g;e.exports=function(e){var s;if(2===arguments.length&&"object"==typeof arguments[1])s=arguments[1];else{s=new Array(arguments.length-1);for(var a=1;a<arguments.length;++a)s[a-1]=arguments[a]}return s&&s.hasOwnProperty||(s={}),e.replace(t,function(t,a,r){var n;return"{"===e[r-1]&&"}"===e[r+t.length]?a:null==(n=s.hasOwnProperty(a)?s[a]:null)?"":n})}},75813:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>f});var a=s(68584),r=s(46377),n=s(66885),u=s(6434),o=s(2401),i=s.n(o);class f extends r.BaseFeatureDataAdapter{constructor(e,t,s){super(e,t,s),this.endpoint=(0,a.readConfObject)(e,"endpoint").uri,this.queryTemplate=(0,a.readConfObject)(e,"queryTemplate"),this.additionalQueryParams=(0,a.readConfObject)(e,"additionalQueryParams"),this.refNamesQueryTemplate=(0,a.readConfObject)(e,"refNamesQueryTemplate"),this.configRefNames=(0,a.readConfObject)(e,"refNames")}async getRefNames(e){if(this.refNames)return this.refNames;if(this.refNamesQueryTemplate){const t=encodeURIComponent(this.refNamesQueryTemplate),s=await this.querySparql(t,e);this.refNames=this.resultsToRefNames(s)}else this.refNames=this.configRefNames;return this.refNames}getFeatures(e,t={}){return(0,n.ObservableCreate)(async s=>{const a=encodeURIComponent(i()(this.queryTemplate,e)),{refName:r}=e,n=await this.querySparql(a,t),u=this.resultsToFeatures(n,r);for(const e of u)s.next(e);s.complete()},t.stopToken)}async querySparql(e,t){let s="";this.additionalQueryParams.length&&(s=`&${this.additionalQueryParams.join("&")}`);const a=`${this.endpoint}?query=${e}${s}`;return(await fetch(a,{headers:{accept:"application/json,application/sparql-results+json"}})).json()}resultsToRefNames(e){const t=e.results.bindings||[];if(!e.head.vars.includes("refName"))throw new Error('"refName" not found in refNamesQueryTemplate response');return t.map(e=>e.refName.value)}resultsToFeatures(e,t){const s=e.results.bindings||[],a=e.head.vars,r=["start","end","uniqueId"];for(const e of r)a.includes(e)||console.error(`Required field ${e} missing from feature data`);const n={};for(const e of s){const s=[{}];for(let t of a)if(t in e){const{value:a}=e[t];let r=0;for(;t.startsWith("sub_");)t=t.slice(4),r+=1;for(;r>s.length-1;)s.push({});s[r][t]=a}for(const[e,a]of s.entries()){const{uniqueId:r,start:u,end:o,strand:i}=a;e<s.length-1&&(s[e+1].parentUniqueId=r),n[r]={data:{...a,uniqueId:r,refName:t,start:Number.parseInt(u,10),end:Number.parseInt(o,10),strand:Number.parseInt(i,10)||0}}}}for(const[e,t]of Object.entries(n)){const s=t.data.parentUniqueId;if(t.data.parentUniqueId=void 0,s){const a=n[s];if(a)a.data.subfeatures||(a.data.subfeatures=[]),a.data.subfeatures.push({...t.data,uniqueId:e}),delete n[e];else{const a=Object.values(n).map(e=>e.data.subfeatures).filter(e=>!!e).flat();let r=!1;for(const u of a){if(u.uniqueId===s){u.subfeatures||(u.subfeatures=[]),u.subfeatures.push({...t.data,uniqueId:e}),delete n[e],r=!0;break}u.subfeatures&&a.push(...u.subfeatures)}r||console.error(`Could not find parentID ${s}`)}}}return Object.keys(n).map(e=>new u.A({...n[e].data,uniqueId:e,subfeatures:n[e].data.subfeatures}))}async hasDataForRefName(e,t={}){const s=await this.getRefNames(t);return!(s.length&&!s.includes(e))}}}}]);
//# sourceMappingURL=5813.b6de49de.chunk.js.map