@genome-spy/core 0.73.0 → 0.74.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.
Files changed (359) hide show
  1. package/dist/bundle/AbortablePromiseCache-3gHJdF3E.js +96 -0
  2. package/dist/bundle/browser-BTgw5ieH.js +126 -0
  3. package/dist/bundle/chunk-DmhlhrBa.js +11 -0
  4. package/dist/bundle/esm-BDFRLEuD.js +1248 -0
  5. package/dist/bundle/esm-BygJiwh0.js +573 -0
  6. package/dist/bundle/esm-CGX-qz1d.js +155 -0
  7. package/dist/bundle/esm-CgfVIRJ-.js +121 -0
  8. package/dist/bundle/esm-CuMSzCHy.js +298 -0
  9. package/dist/bundle/esm-DMXpJXM4.js +369 -0
  10. package/dist/bundle/esm-DQiq2Zhd.js +1426 -0
  11. package/dist/bundle/esm-DtE8VqAv.js +1015 -0
  12. package/dist/bundle/esm-sIoQYZ21.js +461 -0
  13. package/dist/bundle/index.es.js +21071 -25935
  14. package/dist/bundle/index.js +363 -379
  15. package/dist/bundle/parquetRead-DG_-F5j5.js +1609 -0
  16. package/dist/schema.json +13098 -7095
  17. package/dist/src/config/axisConfig.d.ts +16 -0
  18. package/dist/src/config/axisConfig.d.ts.map +1 -0
  19. package/dist/src/config/axisConfig.js +84 -0
  20. package/dist/src/config/defaultConfig.d.ts +3 -0
  21. package/dist/src/config/defaultConfig.d.ts.map +1 -0
  22. package/dist/src/config/defaultConfig.js +38 -0
  23. package/dist/src/config/defaults/axisDefaults.d.ts +5 -0
  24. package/dist/src/config/defaults/axisDefaults.d.ts.map +1 -0
  25. package/dist/src/config/defaults/axisDefaults.js +72 -0
  26. package/dist/src/config/defaults/markDefaults.d.ts +15 -0
  27. package/dist/src/config/defaults/markDefaults.d.ts.map +1 -0
  28. package/dist/src/config/defaults/markDefaults.js +121 -0
  29. package/dist/src/config/defaults/scaleDefaults.d.ts +5 -0
  30. package/dist/src/config/defaults/scaleDefaults.d.ts.map +1 -0
  31. package/dist/src/config/defaults/scaleDefaults.js +18 -0
  32. package/dist/src/config/defaults/titleDefaults.d.ts +5 -0
  33. package/dist/src/config/defaults/titleDefaults.d.ts.map +1 -0
  34. package/dist/src/config/defaults/titleDefaults.js +47 -0
  35. package/dist/src/config/defaults/viewDefaults.d.ts +3 -0
  36. package/dist/src/config/defaults/viewDefaults.d.ts.map +1 -0
  37. package/dist/src/config/defaults/viewDefaults.js +2 -0
  38. package/dist/src/config/markConfig.d.ts +8 -0
  39. package/dist/src/config/markConfig.d.ts.map +1 -0
  40. package/dist/src/config/markConfig.js +27 -0
  41. package/dist/src/config/mergeConfig.d.ts +8 -0
  42. package/dist/src/config/mergeConfig.d.ts.map +1 -0
  43. package/dist/src/config/mergeConfig.js +81 -0
  44. package/dist/src/config/resolveConfig.d.ts +22 -0
  45. package/dist/src/config/resolveConfig.d.ts.map +1 -0
  46. package/dist/src/config/resolveConfig.js +32 -0
  47. package/dist/src/config/scaleConfig.d.ts +40 -0
  48. package/dist/src/config/scaleConfig.d.ts.map +1 -0
  49. package/dist/src/config/scaleConfig.js +220 -0
  50. package/dist/src/config/styleUtils.d.ts +6 -0
  51. package/dist/src/config/styleUtils.d.ts.map +1 -0
  52. package/dist/src/config/styleUtils.js +10 -0
  53. package/dist/src/config/themes.d.ts +15 -0
  54. package/dist/src/config/themes.d.ts.map +1 -0
  55. package/dist/src/config/themes.js +293 -0
  56. package/dist/src/config/titleConfig.d.ts +12 -0
  57. package/dist/src/config/titleConfig.d.ts.map +1 -0
  58. package/dist/src/config/titleConfig.js +42 -0
  59. package/dist/src/config/viewConfig.d.ts +7 -0
  60. package/dist/src/config/viewConfig.d.ts.map +1 -0
  61. package/dist/src/config/viewConfig.js +29 -0
  62. package/dist/src/data/flowNode.d.ts +22 -1
  63. package/dist/src/data/flowNode.d.ts.map +1 -1
  64. package/dist/src/data/flowNode.js +37 -1
  65. package/dist/src/data/formats/bed.d.ts.map +1 -1
  66. package/dist/src/data/formats/bed.js +6 -1
  67. package/dist/src/data/formats/bedpe.d.ts.map +1 -1
  68. package/dist/src/data/formats/bedpe.js +4 -0
  69. package/dist/src/data/formats/fasta.d.ts.map +1 -1
  70. package/dist/src/data/formats/fasta.js +4 -0
  71. package/dist/src/data/formats/parquet.d.ts.map +1 -1
  72. package/dist/src/data/formats/parquet.js +4 -0
  73. package/dist/src/data/sources/dataSourceFactory.d.ts +2 -13
  74. package/dist/src/data/sources/dataSourceFactory.d.ts.map +1 -1
  75. package/dist/src/data/sources/dataSourceFactory.js +5 -141
  76. package/dist/src/data/sources/lazy/axisGenomeSource.d.ts.map +1 -1
  77. package/dist/src/data/sources/lazy/axisGenomeSource.js +11 -0
  78. package/dist/src/data/sources/lazy/axisTickSource.d.ts +1 -1
  79. package/dist/src/data/sources/lazy/axisTickSource.d.ts.map +1 -1
  80. package/dist/src/data/sources/lazy/axisTickSource.js +19 -8
  81. package/dist/src/data/sources/lazy/bamSource.d.ts.map +1 -1
  82. package/dist/src/data/sources/lazy/bamSource.js +11 -0
  83. package/dist/src/data/sources/lazy/bigBedSource.d.ts.map +1 -1
  84. package/dist/src/data/sources/lazy/bigBedSource.js +12 -1
  85. package/dist/src/data/sources/lazy/bigWigSource.d.ts.map +1 -1
  86. package/dist/src/data/sources/lazy/bigWigSource.js +11 -0
  87. package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
  88. package/dist/src/data/sources/lazy/gff3Source.js +12 -1
  89. package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
  90. package/dist/src/data/sources/lazy/indexedFastaSource.js +11 -0
  91. package/dist/src/data/sources/lazy/lazyDataSourceRegistry.d.ts +27 -0
  92. package/dist/src/data/sources/lazy/lazyDataSourceRegistry.d.ts.map +1 -0
  93. package/dist/src/data/sources/lazy/lazyDataSourceRegistry.js +65 -0
  94. package/dist/src/data/sources/lazy/registerBuiltInLazySources.d.ts +2 -0
  95. package/dist/src/data/sources/lazy/registerBuiltInLazySources.d.ts.map +1 -0
  96. package/dist/src/data/sources/lazy/registerBuiltInLazySources.js +8 -0
  97. package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
  98. package/dist/src/data/sources/lazy/singleAxisLazySource.js +11 -2
  99. package/dist/src/data/sources/lazy/vcfSource.d.ts.map +1 -1
  100. package/dist/src/data/sources/lazy/vcfSource.js +11 -0
  101. package/dist/src/data/sources/urlSource.d.ts.map +1 -1
  102. package/dist/src/data/sources/urlSource.js +5 -2
  103. package/dist/src/data/transforms/aggregate.d.ts +1 -0
  104. package/dist/src/data/transforms/aggregate.d.ts.map +1 -1
  105. package/dist/src/data/transforms/aggregate.js +30 -8
  106. package/dist/src/data/transforms/aggregateOps.d.ts.map +1 -1
  107. package/dist/src/data/transforms/aggregateOps.js +12 -1
  108. package/dist/src/data/transforms/coverage.js +2 -2
  109. package/dist/src/data/transforms/filter.js +1 -1
  110. package/dist/src/data/transforms/filterScoredLabels.d.ts +6 -0
  111. package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
  112. package/dist/src/data/transforms/filterScoredLabels.js +9 -0
  113. package/dist/src/data/transforms/measureText.d.ts +1 -0
  114. package/dist/src/data/transforms/measureText.d.ts.map +1 -1
  115. package/dist/src/data/transforms/measureText.js +14 -5
  116. package/dist/src/data/transforms/pileup.d.ts.map +1 -1
  117. package/dist/src/data/transforms/pileup.js +1 -2
  118. package/dist/src/data/transforms/regexFold.d.ts.map +1 -1
  119. package/dist/src/data/transforms/regexFold.js +0 -1
  120. package/dist/src/embedFactory.d.ts +13 -0
  121. package/dist/src/embedFactory.d.ts.map +1 -0
  122. package/dist/src/embedFactory.js +127 -0
  123. package/dist/src/encoder/accessor.d.ts +3 -12
  124. package/dist/src/encoder/accessor.d.ts.map +1 -1
  125. package/dist/src/encoder/accessor.js +10 -65
  126. package/dist/src/encoder/encoder.d.ts +51 -8
  127. package/dist/src/encoder/encoder.d.ts.map +1 -1
  128. package/dist/src/encoder/encoder.js +179 -55
  129. package/dist/src/fonts/bmFontManager.js +1 -1
  130. package/dist/src/full.d.ts +2 -0
  131. package/dist/src/full.d.ts.map +1 -0
  132. package/dist/src/full.js +2 -0
  133. package/dist/src/genome/genome.d.ts +8 -0
  134. package/dist/src/genome/genome.d.ts.map +1 -1
  135. package/dist/src/genome/genome.js +16 -2
  136. package/dist/src/genome/genomeStore.js +1 -1
  137. package/dist/src/genome/rootGenomeConfig.d.ts.map +1 -1
  138. package/dist/src/genome/rootGenomeConfig.js +6 -2
  139. package/dist/src/genome/scaleLocus.d.ts.map +1 -1
  140. package/dist/src/genome/scaleLocus.js +26 -7
  141. package/dist/src/genomeSpy/cursorManager.d.ts +69 -0
  142. package/dist/src/genomeSpy/cursorManager.d.ts.map +1 -0
  143. package/dist/src/genomeSpy/cursorManager.js +131 -0
  144. package/dist/src/genomeSpy/headlessBootstrap.d.ts +113 -0
  145. package/dist/src/genomeSpy/headlessBootstrap.d.ts.map +1 -0
  146. package/dist/src/genomeSpy/headlessBootstrap.js +246 -0
  147. package/dist/src/genomeSpy/interactionController.d.ts +5 -0
  148. package/dist/src/genomeSpy/interactionController.d.ts.map +1 -1
  149. package/dist/src/genomeSpy/interactionController.js +212 -19
  150. package/dist/src/genomeSpy/interactionDispatcher.d.ts +50 -0
  151. package/dist/src/genomeSpy/interactionDispatcher.d.ts.map +1 -0
  152. package/dist/src/genomeSpy/interactionDispatcher.js +203 -0
  153. package/dist/src/genomeSpy/viewContextFactory.d.ts +4 -2
  154. package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -1
  155. package/dist/src/genomeSpy/viewContextFactory.js +12 -4
  156. package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -1
  157. package/dist/src/genomeSpy/viewDataInit.js +7 -3
  158. package/dist/src/genomeSpy.d.ts +1 -124
  159. package/dist/src/genomeSpy.d.ts.map +1 -1
  160. package/dist/src/genomeSpy.js +7 -688
  161. package/dist/src/genomeSpyBase.d.ts +133 -0
  162. package/dist/src/genomeSpyBase.d.ts.map +1 -0
  163. package/dist/src/genomeSpyBase.js +719 -0
  164. package/dist/src/gl/arrayBuilder.d.ts.map +1 -1
  165. package/dist/src/gl/arrayBuilder.js +0 -3
  166. package/dist/src/gl/colorUtils.d.ts.map +1 -1
  167. package/dist/src/gl/colorUtils.js +3 -0
  168. package/dist/src/gl/dataToVertices.d.ts.map +1 -1
  169. package/dist/src/gl/dataToVertices.js +13 -8
  170. package/dist/src/gl/glslScaleGenerator.d.ts +2 -2
  171. package/dist/src/gl/glslScaleGenerator.d.ts.map +1 -1
  172. package/dist/src/gl/glslScaleGenerator.js +5 -7
  173. package/dist/src/index.d.ts +3 -9
  174. package/dist/src/index.d.ts.map +1 -1
  175. package/dist/src/index.js +5 -114
  176. package/dist/src/marks/__snapshots__/shaderSnapshot.test.js.snap +4462 -0
  177. package/dist/src/marks/link.d.ts.map +1 -1
  178. package/dist/src/marks/link.js +0 -23
  179. package/dist/src/marks/mark.d.ts +8 -1
  180. package/dist/src/marks/mark.d.ts.map +1 -1
  181. package/dist/src/marks/mark.js +61 -20
  182. package/dist/src/marks/markUtils.d.ts +18 -1
  183. package/dist/src/marks/markUtils.d.ts.map +1 -1
  184. package/dist/src/marks/markUtils.js +52 -4
  185. package/dist/src/marks/point.d.ts.map +1 -1
  186. package/dist/src/marks/point.js +6 -26
  187. package/dist/src/marks/rect.d.ts.map +1 -1
  188. package/dist/src/marks/rect.js +13 -21
  189. package/dist/src/marks/rule.d.ts +7 -2
  190. package/dist/src/marks/rule.d.ts.map +1 -1
  191. package/dist/src/marks/rule.js +125 -16
  192. package/dist/src/marks/text.d.ts.map +1 -1
  193. package/dist/src/marks/text.js +5 -47
  194. package/dist/src/minimal.d.ts +8 -0
  195. package/dist/src/minimal.d.ts.map +1 -0
  196. package/dist/src/minimal.js +21 -0
  197. package/dist/src/paramRuntime/viewParamRuntime.d.ts +19 -0
  198. package/dist/src/paramRuntime/viewParamRuntime.d.ts.map +1 -1
  199. package/dist/src/paramRuntime/viewParamRuntime.js +35 -0
  200. package/dist/src/scale/scale.d.ts.map +1 -1
  201. package/dist/src/scale/scale.js +13 -7
  202. package/dist/src/scales/axisResolution.d.ts.map +1 -1
  203. package/dist/src/scales/axisResolution.js +9 -5
  204. package/dist/src/scales/domainPlanner.d.ts +28 -8
  205. package/dist/src/scales/domainPlanner.d.ts.map +1 -1
  206. package/dist/src/scales/domainPlanner.js +207 -73
  207. package/dist/src/scales/indexLikeDomainUtils.d.ts +29 -0
  208. package/dist/src/scales/indexLikeDomainUtils.d.ts.map +1 -0
  209. package/dist/src/scales/indexLikeDomainUtils.js +67 -0
  210. package/dist/src/scales/resolutionMemberOrder.d.ts +15 -0
  211. package/dist/src/scales/resolutionMemberOrder.d.ts.map +1 -0
  212. package/dist/src/scales/resolutionMemberOrder.js +22 -0
  213. package/dist/src/scales/scaleInteractionController.d.ts.map +1 -1
  214. package/dist/src/scales/scaleInteractionController.js +43 -4
  215. package/dist/src/scales/scalePropsResolver.d.ts +3 -1
  216. package/dist/src/scales/scalePropsResolver.d.ts.map +1 -1
  217. package/dist/src/scales/scalePropsResolver.js +83 -6
  218. package/dist/src/scales/scaleResolution.d.ts +23 -0
  219. package/dist/src/scales/scaleResolution.d.ts.map +1 -1
  220. package/dist/src/scales/scaleResolution.js +220 -58
  221. package/dist/src/scales/scaleResolutionTestUtils.d.ts.map +1 -1
  222. package/dist/src/scales/scaleResolutionTestUtils.js +6 -2
  223. package/dist/src/scales/scaleRules.d.ts.map +1 -1
  224. package/dist/src/scales/scaleRules.js +16 -2
  225. package/dist/src/scales/selectionDomainUtils.d.ts +30 -0
  226. package/dist/src/scales/selectionDomainUtils.d.ts.map +1 -1
  227. package/dist/src/scales/selectionDomainUtils.js +116 -1
  228. package/dist/src/screenshotHarness.js +3 -4
  229. package/dist/src/spec/axis.d.ts +41 -30
  230. package/dist/src/spec/channel.d.ts +15 -9
  231. package/dist/src/spec/config.d.ts +264 -0
  232. package/dist/src/spec/data.d.ts +7 -0
  233. package/dist/src/spec/decoration.d.ts +51 -0
  234. package/dist/src/spec/exampleFiles.d.ts +12 -0
  235. package/dist/src/spec/exampleFiles.d.ts.map +1 -0
  236. package/dist/src/spec/exampleFiles.js +52 -0
  237. package/dist/src/spec/font.d.ts +1 -1
  238. package/dist/src/spec/mark.d.ts +97 -13
  239. package/dist/src/spec/parameter.d.ts +30 -10
  240. package/dist/src/spec/root.d.ts +14 -0
  241. package/dist/src/spec/scale.d.ts +18 -13
  242. package/dist/src/spec/title.d.ts +13 -2
  243. package/dist/src/spec/tooltip.d.ts +1 -1
  244. package/dist/src/spec/transform.d.ts +39 -4
  245. package/dist/src/spec/view.d.ts +67 -19
  246. package/dist/src/styles/genome-spy.css +55 -55
  247. package/dist/src/styles/genome-spy.css.d.ts +1 -1
  248. package/dist/src/styles/genome-spy.css.d.ts.map +1 -1
  249. package/dist/src/styles/genome-spy.css.js +23 -22
  250. package/dist/src/testSetup.d.ts +2 -0
  251. package/dist/src/testSetup.d.ts.map +1 -0
  252. package/dist/src/testSetup.js +5 -0
  253. package/dist/src/tooltip/dataTooltipHandler.js +8 -2
  254. package/dist/src/tooltip/tooltipContext.d.ts.map +1 -1
  255. package/dist/src/tooltip/tooltipContext.js +3 -2
  256. package/dist/src/types/embedApi.d.ts +7 -0
  257. package/dist/src/types/encoder.d.ts +17 -15
  258. package/dist/src/types/scaleResolutionApi.d.ts +20 -0
  259. package/dist/src/types/viewContext.d.ts +23 -1
  260. package/dist/src/utils/expression.d.ts +2 -2
  261. package/dist/src/utils/expression.d.ts.map +1 -1
  262. package/dist/src/utils/expression.js +63 -8
  263. package/dist/src/utils/field.d.ts.map +1 -1
  264. package/dist/src/utils/field.js +0 -1
  265. package/dist/src/utils/inertia.d.ts.map +1 -1
  266. package/dist/src/utils/inertia.js +0 -1
  267. package/dist/src/utils/inputBinding.d.ts +1 -1
  268. package/dist/src/utils/interaction.d.ts +109 -0
  269. package/dist/src/utils/interaction.d.ts.map +1 -0
  270. package/dist/src/utils/interaction.js +200 -0
  271. package/dist/src/utils/interactionEvent.d.ts +21 -42
  272. package/dist/src/utils/interactionEvent.d.ts.map +1 -1
  273. package/dist/src/utils/interactionEvent.js +43 -66
  274. package/dist/src/utils/kWayMerge.js +1 -1
  275. package/dist/src/utils/mergeObjects.d.ts.map +1 -1
  276. package/dist/src/utils/mergeObjects.js +0 -2
  277. package/dist/src/utils/radixSort.d.ts.map +1 -1
  278. package/dist/src/utils/radixSort.js +0 -2
  279. package/dist/src/utils/throttle.d.ts.map +1 -1
  280. package/dist/src/utils/throttle.js +0 -2
  281. package/dist/src/utils/ui/tooltip.d.ts +1 -0
  282. package/dist/src/utils/ui/tooltip.d.ts.map +1 -1
  283. package/dist/src/utils/ui/tooltip.js +1 -0
  284. package/dist/src/utils/url.js +1 -1
  285. package/dist/src/view/axisGridView.d.ts +1 -1
  286. package/dist/src/view/axisGridView.d.ts.map +1 -1
  287. package/dist/src/view/axisGridView.js +2 -47
  288. package/dist/src/view/axisView.d.ts +2 -3
  289. package/dist/src/view/axisView.d.ts.map +1 -1
  290. package/dist/src/view/axisView.js +251 -106
  291. package/dist/src/view/concatView.d.ts +2 -1
  292. package/dist/src/view/concatView.d.ts.map +1 -1
  293. package/dist/src/view/concatView.js +4 -2
  294. package/dist/src/view/containerMutationHelper.d.ts +3 -0
  295. package/dist/src/view/containerMutationHelper.d.ts.map +1 -1
  296. package/dist/src/view/containerMutationHelper.js +4 -1
  297. package/dist/src/view/facetView.d.ts +1 -1
  298. package/dist/src/view/facetView.js +3 -3
  299. package/dist/src/view/flowBuilder.js +2 -2
  300. package/dist/src/view/gridView/gridChild.d.ts +6 -0
  301. package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
  302. package/dist/src/view/gridView/gridChild.js +72 -43
  303. package/dist/src/view/gridView/gridView.d.ts.map +1 -1
  304. package/dist/src/view/gridView/gridView.js +255 -101
  305. package/dist/src/view/gridView/keyboardZoomController.d.ts +2 -2
  306. package/dist/src/view/gridView/keyboardZoomController.d.ts.map +1 -1
  307. package/dist/src/view/gridView/keyboardZoomController.js +1 -1
  308. package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
  309. package/dist/src/view/gridView/scrollbar.js +4 -2
  310. package/dist/src/view/gridView/selectionRect.d.ts +4 -0
  311. package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
  312. package/dist/src/view/gridView/selectionRect.js +20 -1
  313. package/dist/src/view/gridView/separatorView.d.ts +1 -0
  314. package/dist/src/view/gridView/separatorView.d.ts.map +1 -1
  315. package/dist/src/view/gridView/separatorView.js +9 -0
  316. package/dist/src/view/interactionRouting.d.ts +20 -0
  317. package/dist/src/view/interactionRouting.d.ts.map +1 -0
  318. package/dist/src/view/interactionRouting.js +53 -0
  319. package/dist/src/view/layerView.d.ts.map +1 -1
  320. package/dist/src/view/layerView.js +12 -9
  321. package/dist/src/view/layout/grid.js +1 -1
  322. package/dist/src/view/renderingContext/bufferedViewRenderingContext.d.ts.map +1 -1
  323. package/dist/src/view/renderingContext/bufferedViewRenderingContext.js +0 -2
  324. package/dist/src/view/testUtils.d.ts +17 -3
  325. package/dist/src/view/testUtils.d.ts.map +1 -1
  326. package/dist/src/view/testUtils.js +62 -69
  327. package/dist/src/view/title.d.ts +8 -1
  328. package/dist/src/view/title.d.ts.map +1 -1
  329. package/dist/src/view/title.js +66 -76
  330. package/dist/src/view/unitView.d.ts +1 -1
  331. package/dist/src/view/unitView.d.ts.map +1 -1
  332. package/dist/src/view/unitView.js +67 -17
  333. package/dist/src/view/view.d.ts +76 -30
  334. package/dist/src/view/view.d.ts.map +1 -1
  335. package/dist/src/view/view.js +136 -47
  336. package/dist/src/view/viewFactory.d.ts +11 -3
  337. package/dist/src/view/viewFactory.d.ts.map +1 -1
  338. package/dist/src/view/viewFactory.js +37 -11
  339. package/dist/src/view/viewUtils.d.ts.map +1 -1
  340. package/dist/src/view/viewUtils.js +41 -5
  341. package/dist/src/view/zoom.d.ts +2 -2
  342. package/dist/src/view/zoom.d.ts.map +1 -1
  343. package/dist/src/view/zoom.js +21 -23
  344. package/package.json +18 -10
  345. package/dist/bundle/AbortablePromiseCache-Dj0vzLnp.js +0 -149
  346. package/dist/bundle/browser-0iNU5Wit.js +0 -138
  347. package/dist/bundle/index-BYsZN7b0.js +0 -1597
  348. package/dist/bundle/index-C3kClAEN.js +0 -1771
  349. package/dist/bundle/index-C7wOh6y1.js +0 -657
  350. package/dist/bundle/index-CRaQAuki.js +0 -326
  351. package/dist/bundle/index-D9v1PCj9.js +0 -507
  352. package/dist/bundle/index-GDOuv_D5.js +0 -266
  353. package/dist/bundle/index-Gt44EOIH.js +0 -628
  354. package/dist/bundle/inflate-GtwLkvSP.js +0 -1048
  355. package/dist/bundle/parquetRead-BnAGCa4_.js +0 -1663
  356. package/dist/bundle/unzip-Bac01w6X.js +0 -1492
  357. package/dist/src/config/scaleDefaults.d.ts +0 -8
  358. package/dist/src/config/scaleDefaults.d.ts.map +0 -1
  359. package/dist/src/config/scaleDefaults.js +0 -45
@@ -1,1597 +0,0 @@
1
- import { Q as V, u as D, a as Y } from "./unzip-Bac01w6X.js";
2
- import { LocalFile as v, RemoteFile as B } from "./browser-0iNU5Wit.js";
3
- let G = class {
4
- constructor(e, t, n, r) {
5
- this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = r;
6
- }
7
- toUniqueString() {
8
- return `${this.minv.toString()}..${this.maxv.toString()} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
9
- }
10
- toString() {
11
- return this.toUniqueString();
12
- }
13
- compareTo(e) {
14
- return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
15
- }
16
- fetchedSize() {
17
- return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
18
- }
19
- };
20
- const q = 65536, J = q * q;
21
- function X(h, e = 0) {
22
- const t = h[e] | h[e + 1] << 8 | h[e + 2] << 16 | h[e + 3] << 24;
23
- return ((h[e + 4] | h[e + 5] << 8 | h[e + 6] << 16 | h[e + 7] << 24) >>> 0) * J + (t >>> 0);
24
- }
25
- function Z(h = {}) {
26
- return "aborted" in h ? { signal: h } : h;
27
- }
28
- function N(h, e) {
29
- const t = h.length;
30
- if (t === 0)
31
- return h;
32
- let n;
33
- if (e) {
34
- const a = e.blockPosition, l = e.dataPosition;
35
- n = [];
36
- for (let u = 0; u < t; u++) {
37
- const o = h[u], f = o.maxv;
38
- (f.blockPosition - a || f.dataPosition - l) > 0 && n.push(o);
39
- }
40
- if (n.length === 0)
41
- return n;
42
- } else
43
- n = h;
44
- n.sort((a, l) => {
45
- const u = a.minv.blockPosition - l.minv.blockPosition;
46
- return u !== 0 ? u : a.minv.dataPosition - l.minv.dataPosition;
47
- });
48
- const r = [];
49
- let s = n[0];
50
- r.push(s);
51
- let c = s.minv.blockPosition, i = s.maxv.blockPosition;
52
- for (let a = 1; a < n.length; a++) {
53
- const l = n[a], u = l.minv.blockPosition, o = l.maxv.blockPosition;
54
- if (u - i < 65e3 && o - c < 5e6) {
55
- const f = l.maxv, d = s.maxv;
56
- (o - i || f.dataPosition - d.dataPosition) > 0 && (s.maxv = f, i = o);
57
- } else
58
- r.push(l), s = l, c = u, i = o;
59
- }
60
- return r;
61
- }
62
- function H(h, e) {
63
- return {
64
- lineCount: X(h, e)
65
- };
66
- }
67
- function M(h, e) {
68
- return h ? h.compareTo(e) > 0 ? e : h : e;
69
- }
70
- function ee(h, e = (t) => t) {
71
- let t = 0, n = 0;
72
- const r = [], s = {};
73
- for (let c = 0; c < h.length; c += 1)
74
- if (!h[c]) {
75
- if (n < c) {
76
- let i = "";
77
- for (let a = n; a < c; a++)
78
- i += String.fromCharCode(h[a]);
79
- i = e(i), r[t] = i, s[i] = t;
80
- }
81
- n = c + 1, t += 1;
82
- }
83
- return { refNameToId: s, refIdToName: r };
84
- }
85
- function te(h) {
86
- let e = 0;
87
- for (const r of h)
88
- e += r.length;
89
- const t = new Uint8Array(e);
90
- let n = 0;
91
- for (const r of h)
92
- t.set(r, n), n += r.length;
93
- return t;
94
- }
95
- function ne(h, e, t) {
96
- return !!((h & e) !== e || h & t);
97
- }
98
- function se(h, e) {
99
- return e === "*" ? h === void 0 : `${h}` != `${e}`;
100
- }
101
- function re(h) {
102
- if (!h)
103
- return "";
104
- const { flagInclude: e = 0, flagExclude: t = 0, tagFilter: n } = h, r = n ? `:${n.tag}=${n.value ?? "*"}` : "";
105
- return `:f${e}x${t}${r}`;
106
- }
107
- let j = class {
108
- constructor({ filehandle: e, renameRefSeq: t = (n) => n }) {
109
- this.filehandle = e, this.renameRefSeq = t;
110
- }
111
- async estimatedBytesForRegions(e, t) {
112
- const n = await Promise.all(e.map((c) => this.blocksForRange(c.refId, c.start, c.end, t))), r = N(n.flat());
113
- let s = 0;
114
- for (const c of r)
115
- s += c.fetchedSize();
116
- return s;
117
- }
118
- }, Q = class {
119
- constructor(e, t) {
120
- this.blockPosition = e, this.dataPosition = t;
121
- }
122
- toString() {
123
- return `${this.blockPosition}:${this.dataPosition}`;
124
- }
125
- compareTo(e) {
126
- return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
127
- }
128
- };
129
- function S(h, e = 0, t = !1) {
130
- if (t)
131
- throw new Error("big-endian virtual file offsets not implemented");
132
- return new Q(h[e + 7] * 1099511627776 + h[e + 6] * 4294967296 + h[e + 5] * 16777216 + h[e + 4] * 65536 + h[e + 3] * 256 + h[e + 2], h[e + 1] << 8 | h[e]);
133
- }
134
- const ie = 21578050;
135
- function ae(h, e) {
136
- return h - h % e;
137
- }
138
- function oe(h, e) {
139
- return h - h % e + e;
140
- }
141
- function ce(h, e) {
142
- return e -= 1, [
143
- [0, 0],
144
- [1 + (h >> 26), 1 + (e >> 26)],
145
- [9 + (h >> 23), 9 + (e >> 23)],
146
- [73 + (h >> 20), 73 + (e >> 20)],
147
- [585 + (h >> 17), 585 + (e >> 17)],
148
- [4681 + (h >> 14), 4681 + (e >> 14)]
149
- ];
150
- }
151
- class F extends j {
152
- async lineCount(e, t) {
153
- return (await this.parse(t)).indices(e)?.stats?.lineCount || 0;
154
- }
155
- async _parse(e) {
156
- const t = await this.filehandle.readFile(), n = new DataView(t.buffer);
157
- if (n.getUint32(0, !0) !== ie)
158
- throw new Error("Not a BAI file");
159
- const r = n.getInt32(4, !0), c = ((1 << (5 + 1) * 3) - 1) / 7;
160
- let i = 8, a;
161
- const l = [];
162
- for (let f = 0; f < r; f++) {
163
- l.push(i);
164
- const d = n.getInt32(i, !0);
165
- i += 4;
166
- for (let x = 0; x < d; x += 1) {
167
- const w = n.getUint32(i, !0);
168
- if (i += 4, w === c + 1)
169
- i += 4, i += 32;
170
- else {
171
- if (w > c + 1)
172
- throw new Error("bai index contains too many bins, please use CSI");
173
- {
174
- const _ = n.getInt32(i, !0);
175
- i += 4;
176
- for (let m = 0; m < _; m++)
177
- i += 8, i += 8;
178
- }
179
- }
180
- }
181
- const b = n.getInt32(i, !0);
182
- i += 4;
183
- const g = new Array(b);
184
- for (let x = 0; x < b; x++) {
185
- const w = S(t, i);
186
- i += 8, a = M(a, w), g[x] = w;
187
- }
188
- }
189
- const u = new V({
190
- maxSize: 5
191
- });
192
- function o(f) {
193
- let d = l[f];
194
- if (d === void 0)
195
- return;
196
- const b = n.getInt32(d, !0);
197
- let g;
198
- d += 4;
199
- const x = {};
200
- for (let m = 0; m < b; m += 1) {
201
- const y = n.getUint32(d, !0);
202
- if (d += 4, y === c + 1)
203
- d += 4, g = H(t, d + 16), d += 32;
204
- else {
205
- if (y > c + 1)
206
- throw new Error("bai index contains too many bins, please use CSI");
207
- {
208
- const p = n.getInt32(d, !0);
209
- d += 4;
210
- const C = new Array(p);
211
- for (let I = 0; I < p; I++) {
212
- const k = S(t, d);
213
- d += 8;
214
- const R = S(t, d);
215
- d += 8, a = M(a, k), C[I] = new G(k, R, y);
216
- }
217
- x[y] = C;
218
- }
219
- }
220
- }
221
- const w = n.getInt32(d, !0);
222
- d += 4;
223
- const _ = new Array(w);
224
- for (let m = 0; m < w; m++) {
225
- const y = S(t, d);
226
- d += 8, a = M(a, y), _[m] = y;
227
- }
228
- return {
229
- binIndex: x,
230
- linearIndex: _,
231
- stats: g
232
- };
233
- }
234
- return {
235
- bai: !0,
236
- firstDataLine: a,
237
- maxBlockSize: 65536,
238
- indices: (f) => {
239
- if (!u.has(f)) {
240
- const d = o(f);
241
- return d && u.set(f, d), d;
242
- }
243
- return u.get(f);
244
- },
245
- refCount: r
246
- };
247
- }
248
- async indexCov(e, t, n, r) {
249
- const c = t !== void 0, a = (await this.parse(r)).indices(e);
250
- if (!a)
251
- return [];
252
- const { linearIndex: l, stats: u } = a;
253
- if (l.length === 0)
254
- return [];
255
- const o = n === void 0 ? (l.length - 1) * 16384 : oe(n, 16384), f = t === void 0 ? 0 : ae(t, 16384), d = c ? new Array((o - f) / 16384) : new Array(l.length - 1), b = l[l.length - 1].blockPosition;
256
- if (o > (l.length - 1) * 16384)
257
- throw new Error("query outside of range of linear index");
258
- let g = l[f / 16384].blockPosition;
259
- for (let x = f / 16384, w = 0; x < o / 16384; x++, w++)
260
- d[w] = {
261
- score: l[x + 1].blockPosition - g,
262
- start: x * 16384,
263
- end: x * 16384 + 16384
264
- }, g = l[x + 1].blockPosition;
265
- return d.map((x) => ({
266
- ...x,
267
- score: x.score * (u?.lineCount || 0) / b
268
- }));
269
- }
270
- async blocksForRange(e, t, n, r = {}) {
271
- t < 0 && (t = 0);
272
- const s = await this.parse(r);
273
- if (!s)
274
- return [];
275
- const c = s.indices(e);
276
- if (!c)
277
- return [];
278
- const i = ce(t, n), a = [], { binIndex: l } = c;
279
- for (const [b, g] of i)
280
- for (let x = b; x <= g; x++) {
281
- const w = l[x];
282
- if (w)
283
- for (let _ = 0, m = w.length; _ < m; _++)
284
- a.push(w[_]);
285
- }
286
- const { linearIndex: u } = c, o = u.length, f = Math.min(t >> 14, o - 1), d = u[f];
287
- return N(a, d);
288
- }
289
- async parse(e = {}) {
290
- return this.setupP || (this.setupP = this._parse(e).catch((t) => {
291
- throw this.setupP = void 0, t;
292
- })), this.setupP;
293
- }
294
- async hasRefSeq(e, t = {}) {
295
- return !!(await this.parse(t)).indices(e)?.binIndex;
296
- }
297
- }
298
- let U = [
299
- 0,
300
- 1996959894,
301
- 3993919788,
302
- 2567524794,
303
- 124634137,
304
- 1886057615,
305
- 3915621685,
306
- 2657392035,
307
- 249268274,
308
- 2044508324,
309
- 3772115230,
310
- 2547177864,
311
- 162941995,
312
- 2125561021,
313
- 3887607047,
314
- 2428444049,
315
- 498536548,
316
- 1789927666,
317
- 4089016648,
318
- 2227061214,
319
- 450548861,
320
- 1843258603,
321
- 4107580753,
322
- 2211677639,
323
- 325883990,
324
- 1684777152,
325
- 4251122042,
326
- 2321926636,
327
- 335633487,
328
- 1661365465,
329
- 4195302755,
330
- 2366115317,
331
- 997073096,
332
- 1281953886,
333
- 3579855332,
334
- 2724688242,
335
- 1006888145,
336
- 1258607687,
337
- 3524101629,
338
- 2768942443,
339
- 901097722,
340
- 1119000684,
341
- 3686517206,
342
- 2898065728,
343
- 853044451,
344
- 1172266101,
345
- 3705015759,
346
- 2882616665,
347
- 651767980,
348
- 1373503546,
349
- 3369554304,
350
- 3218104598,
351
- 565507253,
352
- 1454621731,
353
- 3485111705,
354
- 3099436303,
355
- 671266974,
356
- 1594198024,
357
- 3322730930,
358
- 2970347812,
359
- 795835527,
360
- 1483230225,
361
- 3244367275,
362
- 3060149565,
363
- 1994146192,
364
- 31158534,
365
- 2563907772,
366
- 4023717930,
367
- 1907459465,
368
- 112637215,
369
- 2680153253,
370
- 3904427059,
371
- 2013776290,
372
- 251722036,
373
- 2517215374,
374
- 3775830040,
375
- 2137656763,
376
- 141376813,
377
- 2439277719,
378
- 3865271297,
379
- 1802195444,
380
- 476864866,
381
- 2238001368,
382
- 4066508878,
383
- 1812370925,
384
- 453092731,
385
- 2181625025,
386
- 4111451223,
387
- 1706088902,
388
- 314042704,
389
- 2344532202,
390
- 4240017532,
391
- 1658658271,
392
- 366619977,
393
- 2362670323,
394
- 4224994405,
395
- 1303535960,
396
- 984961486,
397
- 2747007092,
398
- 3569037538,
399
- 1256170817,
400
- 1037604311,
401
- 2765210733,
402
- 3554079995,
403
- 1131014506,
404
- 879679996,
405
- 2909243462,
406
- 3663771856,
407
- 1141124467,
408
- 855842277,
409
- 2852801631,
410
- 3708648649,
411
- 1342533948,
412
- 654459306,
413
- 3188396048,
414
- 3373015174,
415
- 1466479909,
416
- 544179635,
417
- 3110523913,
418
- 3462522015,
419
- 1591671054,
420
- 702138776,
421
- 2966460450,
422
- 3352799412,
423
- 1504918807,
424
- 783551873,
425
- 3082640443,
426
- 3233442989,
427
- 3988292384,
428
- 2596254646,
429
- 62317068,
430
- 1957810842,
431
- 3939845945,
432
- 2647816111,
433
- 81470997,
434
- 1943803523,
435
- 3814918930,
436
- 2489596804,
437
- 225274430,
438
- 2053790376,
439
- 3826175755,
440
- 2466906013,
441
- 167816743,
442
- 2097651377,
443
- 4027552580,
444
- 2265490386,
445
- 503444072,
446
- 1762050814,
447
- 4150417245,
448
- 2154129355,
449
- 426522225,
450
- 1852507879,
451
- 4275313526,
452
- 2312317920,
453
- 282753626,
454
- 1742555852,
455
- 4189708143,
456
- 2394877945,
457
- 397917763,
458
- 1622183637,
459
- 3604390888,
460
- 2714866558,
461
- 953729732,
462
- 1340076626,
463
- 3518719985,
464
- 2797360999,
465
- 1068828381,
466
- 1219638859,
467
- 3624741850,
468
- 2936675148,
469
- 906185462,
470
- 1090812512,
471
- 3747672003,
472
- 2825379669,
473
- 829329135,
474
- 1181335161,
475
- 3412177804,
476
- 3160834842,
477
- 628085408,
478
- 1382605366,
479
- 3423369109,
480
- 3138078467,
481
- 570562233,
482
- 1426400815,
483
- 3317316542,
484
- 2998733608,
485
- 733239954,
486
- 1555261956,
487
- 3268935591,
488
- 3050360625,
489
- 752459403,
490
- 1541320221,
491
- 2607071920,
492
- 3965973030,
493
- 1969922972,
494
- 40735498,
495
- 2617837225,
496
- 3943577151,
497
- 1913087877,
498
- 83908371,
499
- 2512341634,
500
- 3803740692,
501
- 2075208622,
502
- 213261112,
503
- 2463272603,
504
- 3855990285,
505
- 2094854071,
506
- 198958881,
507
- 2262029012,
508
- 4057260610,
509
- 1759359992,
510
- 534414190,
511
- 2176718541,
512
- 4139329115,
513
- 1873836001,
514
- 414664567,
515
- 2282248934,
516
- 4279200368,
517
- 1711684554,
518
- 285281116,
519
- 2405801727,
520
- 4167216745,
521
- 1634467795,
522
- 376229701,
523
- 2685067896,
524
- 3608007406,
525
- 1308918612,
526
- 956543938,
527
- 2808555105,
528
- 3495958263,
529
- 1231636301,
530
- 1047427035,
531
- 2932959818,
532
- 3654703836,
533
- 1088359270,
534
- 936918e3,
535
- 2847714899,
536
- 3736837829,
537
- 1202900863,
538
- 817233897,
539
- 3183342108,
540
- 3401237130,
541
- 1404277552,
542
- 615818150,
543
- 3134207493,
544
- 3453421203,
545
- 1423857449,
546
- 601450431,
547
- 3009837614,
548
- 3294710456,
549
- 1567103746,
550
- 711928724,
551
- 3020668471,
552
- 3272380065,
553
- 1510334235,
554
- 755167117
555
- ];
556
- typeof Int32Array < "u" && (U = new Int32Array(U));
557
- const de = (h, e) => {
558
- let t = -1;
559
- for (let n = 0; n < h.length; n++)
560
- t = U[(t ^ h[n]) & 255] ^ t >>> 8;
561
- return t ^ -1;
562
- }, fe = 21582659, he = 38359875;
563
- function ue(h, e) {
564
- return h * 2 ** e;
565
- }
566
- function L(h, e) {
567
- return Math.floor(h / 2 ** e);
568
- }
569
- let $ = class extends j {
570
- constructor() {
571
- super(...arguments), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
572
- }
573
- async lineCount(e, t) {
574
- return (await this.parse(t)).indices(e)?.stats?.lineCount || 0;
575
- }
576
- async indexCov() {
577
- return [];
578
- }
579
- parseAuxData(e, t) {
580
- const n = new DataView(e.buffer), r = n.getUint32(t, !0), s = r & 65536 ? "zero-based-half-open" : "1-based-closed", c = { 0: "generic", 1: "SAM", 2: "VCF" }[r & 15];
581
- if (!c)
582
- throw new Error(`invalid Tabix preset format flags ${r}`);
583
- const i = {
584
- ref: n.getInt32(t + 4, !0),
585
- start: n.getInt32(t + 8, !0),
586
- end: n.getInt32(t + 12, !0)
587
- }, a = n.getInt32(t + 16, !0), l = a ? String.fromCharCode(a) : "", u = n.getInt32(t + 20, !0), o = n.getInt32(t + 24, !0);
588
- return {
589
- columnNumbers: i,
590
- coordinateType: s,
591
- metaValue: a,
592
- metaChar: l,
593
- skipLines: u,
594
- format: c,
595
- formatFlags: r,
596
- ...ee(e.subarray(t + 28, t + 28 + o), this.renameRefSeq)
597
- };
598
- }
599
- // fetch and parse the index
600
- async _parse(e) {
601
- const t = await this.filehandle.readFile(e), n = await D(t), r = new DataView(n.buffer);
602
- let s;
603
- const c = r.getUint32(0, !0);
604
- if (c === fe)
605
- s = 1;
606
- else if (c === he)
607
- s = 2;
608
- else
609
- throw new Error(`Not a CSI file ${c}`);
610
- this.minShift = r.getInt32(4, !0), this.depth = r.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
611
- const i = this.maxBinNumber, a = r.getInt32(12, !0), l = a >= 30 ? this.parseAuxData(n, 16) : void 0, u = r.getInt32(16 + a, !0);
612
- let o = 16 + a + 4, f;
613
- const d = [];
614
- for (let x = 0; x < u; x++) {
615
- d.push(o);
616
- const w = r.getInt32(o, !0);
617
- o += 4;
618
- for (let _ = 0; _ < w; _++) {
619
- const m = r.getUint32(o, !0);
620
- if (o += 4, m > this.maxBinNumber)
621
- o += 44;
622
- else {
623
- o += 8;
624
- const y = r.getInt32(o, !0);
625
- o += 4;
626
- for (let p = 0; p < y; p += 1) {
627
- const C = S(n, o);
628
- o += 8, o += 8, f = M(f, C);
629
- }
630
- }
631
- }
632
- }
633
- const b = new V({
634
- maxSize: 5
635
- });
636
- function g(x) {
637
- let w = d[x];
638
- if (w === void 0)
639
- return;
640
- const _ = r.getInt32(w, !0);
641
- w += 4;
642
- const m = {};
643
- let y;
644
- for (let p = 0; p < _; p++) {
645
- const C = r.getUint32(w, !0);
646
- if (w += 4, C > i)
647
- y = H(n, w + 28), w += 44;
648
- else {
649
- f = M(f, S(n, w)), w += 8;
650
- const I = r.getInt32(w, !0);
651
- w += 4;
652
- const k = new Array(I);
653
- for (let R = 0; R < I; R += 1) {
654
- const T = S(n, w);
655
- w += 8;
656
- const P = S(n, w);
657
- w += 8, k[R] = new G(T, P, C);
658
- }
659
- m[C] = k;
660
- }
661
- }
662
- return {
663
- binIndex: m,
664
- stats: y
665
- };
666
- }
667
- return {
668
- csiVersion: s,
669
- firstDataLine: f,
670
- indices: (x) => {
671
- if (!b.has(x)) {
672
- const w = g(x);
673
- return w && b.set(x, w), w;
674
- }
675
- return b.get(x);
676
- },
677
- refCount: u,
678
- csi: !0,
679
- maxBlockSize: 65536,
680
- ...l
681
- };
682
- }
683
- async blocksForRange(e, t, n, r = {}) {
684
- t < 0 && (t = 0);
685
- const c = (await this.parse(r)).indices(e);
686
- if (!c)
687
- return [];
688
- const i = this.reg2bins(t, n);
689
- if (i.length === 0)
690
- return [];
691
- const a = [], { binIndex: l } = c;
692
- for (const [u, o] of i)
693
- for (let f = u; f <= o; f++) {
694
- const d = l[f];
695
- if (d)
696
- for (let b = 0, g = d.length; b < g; b++)
697
- a.push(d[b]);
698
- }
699
- return N(a, new Q(0, 0));
700
- }
701
- /**
702
- * calculate the list of bins that may overlap with region [beg,end)
703
- * (zero-based half-open)
704
- */
705
- reg2bins(e, t) {
706
- e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
707
- let n = 0, r = 0, s = this.minShift + this.depth * 3;
708
- const c = [];
709
- for (; n <= this.depth; s -= 3, r += ue(1, n * 3), n += 1) {
710
- const i = r + L(e, s), a = r + L(t, s);
711
- if (a - i + c.length > this.maxBinNumber)
712
- throw new Error(`query ${e}-${t} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);
713
- c.push([i, a]);
714
- }
715
- return c;
716
- }
717
- async parse(e = {}) {
718
- return this.setupP || (this.setupP = this._parse(e).catch((t) => {
719
- throw this.setupP = void 0, t;
720
- })), this.setupP;
721
- }
722
- async hasRefSeq(e, t = {}) {
723
- return !!(await this.parse(t)).indices(e)?.binIndex;
724
- }
725
- };
726
- class le {
727
- read() {
728
- throw new Error("never called");
729
- }
730
- stat() {
731
- throw new Error("never called");
732
- }
733
- readFile() {
734
- throw new Error("never called");
735
- }
736
- close() {
737
- throw new Error("never called");
738
- }
739
- }
740
- const xe = 3, be = 4, A = {
741
- // the read is paired in sequencing, no matter whether it is mapped in a pair
742
- BAM_FPAIRED: 1,
743
- // the read is mapped in a proper pair
744
- BAM_FPROPER_PAIR: 2,
745
- // the read itself is unmapped; conflictive with BAM_FPROPER_PAIR
746
- BAM_FUNMAP: 4,
747
- // the mate is unmapped
748
- BAM_FMUNMAP: 8,
749
- // the read is mapped to the reverse strand
750
- BAM_FREVERSE: 16,
751
- // the mate is mapped to the reverse strand
752
- BAM_FMREVERSE: 32,
753
- // this is read1
754
- BAM_FREAD1: 64,
755
- // this is read2
756
- BAM_FREAD2: 128,
757
- // not primary alignment
758
- BAM_FSECONDARY: 256,
759
- // QC failure
760
- BAM_FQCFAIL: 512,
761
- // optical or PCR duplicate
762
- BAM_FDUP: 1024,
763
- // supplementary alignment
764
- BAM_FSUPPLEMENTARY: 2048
765
- }, E = "=ACMGRSVTWYHKDBN".split(""), ge = [
766
- 77,
767
- 73,
768
- 68,
769
- 78,
770
- 83,
771
- 72,
772
- 80,
773
- 61,
774
- 88,
775
- 63,
776
- 63,
777
- 63,
778
- 63,
779
- 63,
780
- 63,
781
- 63
782
- ], O = 461;
783
- class we {
784
- constructor(e) {
785
- this.bytes = e.bytes, this.fileOffset = e.fileOffset, this._dataView = new DataView(this.bytes.byteArray.buffer);
786
- }
787
- get byteArray() {
788
- return this.bytes.byteArray;
789
- }
790
- get flags() {
791
- return this._cachedFlags === void 0 && (this._cachedFlags = (this._dataView.getInt32(this.bytes.start + 16, !0) & 4294901760) >> 16), this._cachedFlags;
792
- }
793
- get ref_id() {
794
- return this._cachedRefId === void 0 && (this._cachedRefId = this._dataView.getInt32(this.bytes.start + 4, !0)), this._cachedRefId;
795
- }
796
- get start() {
797
- return this._cachedStart === void 0 && (this._cachedStart = this._dataView.getInt32(this.bytes.start + 8, !0)), this._cachedStart;
798
- }
799
- get end() {
800
- return this._cachedEnd === void 0 && (this._cachedEnd = this.start + this.length_on_ref), this._cachedEnd;
801
- }
802
- get mq() {
803
- const e = (this.bin_mq_nl & 65280) >> 8;
804
- return e === 255 ? void 0 : e;
805
- }
806
- get score() {
807
- return this.mq;
808
- }
809
- get qual() {
810
- if (this.isSegmentUnmapped())
811
- return null;
812
- {
813
- const e = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes;
814
- return this.byteArray.subarray(e, e + this.seq_length);
815
- }
816
- }
817
- get strand() {
818
- return this.isReverseComplemented() ? -1 : 1;
819
- }
820
- get b0() {
821
- return this.bytes.start + 36;
822
- }
823
- get tagsStart() {
824
- return this._cachedTagsStart === void 0 && (this._cachedTagsStart = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes + this.seq_length), this._cachedTagsStart;
825
- }
826
- // batch fromCharCode: fastest for typical name lengths (see benchmarks/string-building.bench.ts)
827
- get name() {
828
- const e = this.read_name_length - 1, t = this.b0, n = this.byteArray, r = new Array(e);
829
- for (let s = 0; s < e; s++)
830
- r[s] = n[t + s];
831
- return String.fromCharCode(...r);
832
- }
833
- get NUMERIC_MD() {
834
- if (this._cachedNUMERIC_MD === void 0) {
835
- const e = this.getTagRaw("MD");
836
- this._cachedNUMERIC_MD = e instanceof Uint8Array ? e : null;
837
- }
838
- return this._cachedNUMERIC_MD === null ? void 0 : this._cachedNUMERIC_MD;
839
- }
840
- get tags() {
841
- return this._cachedTags === void 0 && (this._cachedTags = this._computeTags()), this._cachedTags;
842
- }
843
- getTag(e) {
844
- return this._cachedTags !== void 0 ? this._cachedTags[e] : this._findTag(e, !1);
845
- }
846
- getTagRaw(e) {
847
- return this._findTag(e, !0);
848
- }
849
- _findTag(e, t) {
850
- const n = e.charCodeAt(0), r = e.charCodeAt(1);
851
- let s = this.tagsStart;
852
- const c = this.bytes.end, i = this.byteArray;
853
- for (; s < c; ) {
854
- const a = i[s], l = i[s + 1], u = i[s + 2];
855
- s += 3;
856
- const o = a === n && l === r;
857
- switch (u) {
858
- case 65:
859
- if (o)
860
- return String.fromCharCode(i[s]);
861
- s += 1;
862
- break;
863
- case 105:
864
- if (o)
865
- return this._dataView.getInt32(s, !0);
866
- s += 4;
867
- break;
868
- case 73:
869
- if (o)
870
- return this._dataView.getUint32(s, !0);
871
- s += 4;
872
- break;
873
- case 99:
874
- if (o)
875
- return this._dataView.getInt8(s);
876
- s += 1;
877
- break;
878
- case 67:
879
- if (o)
880
- return this._dataView.getUint8(s);
881
- s += 1;
882
- break;
883
- case 115:
884
- if (o)
885
- return this._dataView.getInt16(s, !0);
886
- s += 2;
887
- break;
888
- case 83:
889
- if (o)
890
- return this._dataView.getUint16(s, !0);
891
- s += 2;
892
- break;
893
- case 102:
894
- if (o)
895
- return this._dataView.getFloat32(s, !0);
896
- s += 4;
897
- break;
898
- case 90:
899
- // 'Z'
900
- case 72: {
901
- if (o) {
902
- const f = s;
903
- for (; s < c && i[s] !== 0; )
904
- s++;
905
- if (t)
906
- return i.subarray(f, s);
907
- const d = [];
908
- for (let b = f; b < s; b++)
909
- d.push(String.fromCharCode(i[b]));
910
- return d.join("");
911
- }
912
- for (; s <= c && i[s++] !== 0; )
913
- ;
914
- break;
915
- }
916
- case 66: {
917
- const f = i[s++], d = this._dataView.getInt32(s, !0);
918
- s += 4;
919
- const b = i.byteOffset + s;
920
- if (o)
921
- if (f === 105) {
922
- if (b % 4 === 0)
923
- return new Int32Array(i.buffer, b, d);
924
- const g = new Array(d);
925
- for (let x = 0; x < d; x++)
926
- g[x] = this._dataView.getInt32(s + x * 4, !0);
927
- return g;
928
- } else if (f === 73) {
929
- if (b % 4 === 0)
930
- return new Uint32Array(i.buffer, b, d);
931
- const g = new Array(d);
932
- for (let x = 0; x < d; x++)
933
- g[x] = this._dataView.getUint32(s + x * 4, !0);
934
- return g;
935
- } else if (f === 115) {
936
- if (b % 2 === 0)
937
- return new Int16Array(i.buffer, b, d);
938
- const g = new Array(d);
939
- for (let x = 0; x < d; x++)
940
- g[x] = this._dataView.getInt16(s + x * 2, !0);
941
- return g;
942
- } else if (f === 83) {
943
- if (b % 2 === 0)
944
- return new Uint16Array(i.buffer, b, d);
945
- const g = new Array(d);
946
- for (let x = 0; x < d; x++)
947
- g[x] = this._dataView.getUint16(s + x * 2, !0);
948
- return g;
949
- } else {
950
- if (f === 99)
951
- return new Int8Array(i.buffer, b, d);
952
- if (f === 67)
953
- return new Uint8Array(i.buffer, b, d);
954
- if (f === 102) {
955
- if (b % 4 === 0)
956
- return new Float32Array(i.buffer, b, d);
957
- const g = new Array(d);
958
- for (let x = 0; x < d; x++)
959
- g[x] = this._dataView.getFloat32(s + x * 4, !0);
960
- return g;
961
- }
962
- }
963
- f === 105 || f === 73 || f === 102 ? s += d << 2 : f === 115 || f === 83 ? s += d << 1 : (f === 99 || f === 67) && (s += d);
964
- break;
965
- }
966
- }
967
- }
968
- }
969
- _computeTags() {
970
- let e = this.tagsStart;
971
- const t = this.bytes.end, n = this.byteArray, r = {};
972
- for (; e < t; ) {
973
- const s = String.fromCharCode(n[e], n[e + 1]), c = n[e + 2];
974
- switch (e += 3, c) {
975
- case 65:
976
- r[s] = String.fromCharCode(n[e]), e += 1;
977
- break;
978
- case 105:
979
- r[s] = this._dataView.getInt32(e, !0), e += 4;
980
- break;
981
- case 73:
982
- r[s] = this._dataView.getUint32(e, !0), e += 4;
983
- break;
984
- case 99:
985
- r[s] = this._dataView.getInt8(e), e += 1;
986
- break;
987
- case 67:
988
- r[s] = this._dataView.getUint8(e), e += 1;
989
- break;
990
- case 115:
991
- r[s] = this._dataView.getInt16(e, !0), e += 2;
992
- break;
993
- case 83:
994
- r[s] = this._dataView.getUint16(e, !0), e += 2;
995
- break;
996
- case 102:
997
- r[s] = this._dataView.getFloat32(e, !0), e += 4;
998
- break;
999
- case 90:
1000
- // 'Z'
1001
- case 72: {
1002
- const i = [];
1003
- for (; e <= t; ) {
1004
- const a = n[e++];
1005
- if (a !== 0)
1006
- i.push(String.fromCharCode(a));
1007
- else
1008
- break;
1009
- }
1010
- r[s] = i.join("");
1011
- break;
1012
- }
1013
- case 66: {
1014
- const i = n[e++], a = this._dataView.getInt32(e, !0);
1015
- e += 4;
1016
- const l = n.byteOffset + e;
1017
- if (i === 105) {
1018
- if (l % 4 === 0)
1019
- r[s] = new Int32Array(n.buffer, l, a);
1020
- else {
1021
- const u = new Array(a);
1022
- for (let o = 0; o < a; o++)
1023
- u[o] = this._dataView.getInt32(e + o * 4, !0);
1024
- r[s] = u;
1025
- }
1026
- e += a << 2;
1027
- } else if (i === 73) {
1028
- if (l % 4 === 0)
1029
- r[s] = new Uint32Array(n.buffer, l, a);
1030
- else {
1031
- const u = new Array(a);
1032
- for (let o = 0; o < a; o++)
1033
- u[o] = this._dataView.getUint32(e + o * 4, !0);
1034
- r[s] = u;
1035
- }
1036
- e += a << 2;
1037
- } else if (i === 115) {
1038
- if (l % 2 === 0)
1039
- r[s] = new Int16Array(n.buffer, l, a);
1040
- else {
1041
- const u = new Array(a);
1042
- for (let o = 0; o < a; o++)
1043
- u[o] = this._dataView.getInt16(e + o * 2, !0);
1044
- r[s] = u;
1045
- }
1046
- e += a << 1;
1047
- } else if (i === 83) {
1048
- if (l % 2 === 0)
1049
- r[s] = new Uint16Array(n.buffer, l, a);
1050
- else {
1051
- const u = new Array(a);
1052
- for (let o = 0; o < a; o++)
1053
- u[o] = this._dataView.getUint16(e + o * 2, !0);
1054
- r[s] = u;
1055
- }
1056
- e += a << 1;
1057
- } else if (i === 99)
1058
- r[s] = new Int8Array(n.buffer, l, a), e += a;
1059
- else if (i === 67)
1060
- r[s] = new Uint8Array(n.buffer, l, a), e += a;
1061
- else if (i === 102) {
1062
- if (l % 4 === 0)
1063
- r[s] = new Float32Array(n.buffer, l, a);
1064
- else {
1065
- const u = new Array(a);
1066
- for (let o = 0; o < a; o++)
1067
- u[o] = this._dataView.getFloat32(e + o * 4, !0);
1068
- r[s] = u;
1069
- }
1070
- e += a << 2;
1071
- }
1072
- break;
1073
- }
1074
- default:
1075
- console.error("Unknown BAM tag type", c);
1076
- break;
1077
- }
1078
- }
1079
- return r;
1080
- }
1081
- isPaired() {
1082
- return !!(this.flags & A.BAM_FPAIRED);
1083
- }
1084
- isProperlyPaired() {
1085
- return !!(this.flags & A.BAM_FPROPER_PAIR);
1086
- }
1087
- isSegmentUnmapped() {
1088
- return !!(this.flags & A.BAM_FUNMAP);
1089
- }
1090
- isMateUnmapped() {
1091
- return !!(this.flags & A.BAM_FMUNMAP);
1092
- }
1093
- isReverseComplemented() {
1094
- return !!(this.flags & A.BAM_FREVERSE);
1095
- }
1096
- isMateReverseComplemented() {
1097
- return !!(this.flags & A.BAM_FMREVERSE);
1098
- }
1099
- isRead1() {
1100
- return !!(this.flags & A.BAM_FREAD1);
1101
- }
1102
- isRead2() {
1103
- return !!(this.flags & A.BAM_FREAD2);
1104
- }
1105
- isSecondary() {
1106
- return !!(this.flags & A.BAM_FSECONDARY);
1107
- }
1108
- isFailedQc() {
1109
- return !!(this.flags & A.BAM_FQCFAIL);
1110
- }
1111
- isDuplicate() {
1112
- return !!(this.flags & A.BAM_FDUP);
1113
- }
1114
- isSupplementary() {
1115
- return !!(this.flags & A.BAM_FSUPPLEMENTARY);
1116
- }
1117
- get cigarAndLength() {
1118
- return this._cachedCigarAndLength === void 0 && (this._cachedCigarAndLength = this._computeCigarAndLength()), this._cachedCigarAndLength;
1119
- }
1120
- // Benchmark results for CIGAR parsing strategies (see benchmarks/cigar-lifecycle.bench.ts):
1121
- //
1122
- // Aligned data:
1123
- // - Plain array is 1.6-1.8x faster than Uint32Array for small CIGARs (≤50 ops)
1124
- // - Uint32Array view is 1.3-2.2x faster for large CIGARs (≥200 ops)
1125
- // - Crossover point is around 50-100 ops
1126
- //
1127
- // Unaligned data (requires slice+copy for Uint32Array):
1128
- // - Plain array is 3.7-6.1x faster for typical sizes (50-200 ops)
1129
- // - Plain array is 9-10x faster for small CIGARs (1-7 ops)
1130
- // - Uint32Array slice+copy only wins at extreme sizes (10000 ops: 1.4x faster)
1131
- //
1132
- // Using |0 to force 32-bit integers in plain array path:
1133
- // - 1.67x faster for medium CIGARs (50 ops)
1134
- // - Neutral for small CIGARs (1-7 ops)
1135
- //
1136
- // Strategy: use plain array with |0 for small aligned (≤50 ops) and all unaligned,
1137
- // Uint32Array view only for large aligned CIGARs.
1138
- _computeCigarAndLength() {
1139
- if (this.isSegmentUnmapped())
1140
- return {
1141
- length_on_ref: 0,
1142
- NUMERIC_CIGAR: new Uint32Array(0)
1143
- };
1144
- const e = this.num_cigar_ops;
1145
- let t = this.b0 + this.read_name_length;
1146
- const n = this._dataView.getInt32(t, !0), r = n >> 4;
1147
- if ((n & 15) === be && r === this.seq_length) {
1148
- t += 4;
1149
- const u = this._dataView.getInt32(t, !0), o = u >> 4;
1150
- return (u & 15) !== xe && console.warn("CG tag with no N tag"), {
1151
- NUMERIC_CIGAR: this.tags.CG,
1152
- length_on_ref: o
1153
- };
1154
- }
1155
- const c = this.byteArray.byteOffset + t;
1156
- if (c % 4 === 0 && e > 50) {
1157
- const u = new Uint32Array(this.byteArray.buffer, c, e);
1158
- let o = 0;
1159
- for (let f = 0; f < e; ++f) {
1160
- const d = u[f];
1161
- o += (d >> 4) * (O >> (d & 15) & 1);
1162
- }
1163
- return {
1164
- NUMERIC_CIGAR: u,
1165
- length_on_ref: o
1166
- };
1167
- }
1168
- const a = new Array(e);
1169
- let l = 0;
1170
- for (let u = 0; u < e; ++u) {
1171
- const o = this._dataView.getInt32(t + u * 4, !0) | 0;
1172
- a[u] = o, l += (o >> 4) * (O >> (o & 15) & 1);
1173
- }
1174
- return {
1175
- NUMERIC_CIGAR: a,
1176
- length_on_ref: l
1177
- };
1178
- }
1179
- get length_on_ref() {
1180
- return this.cigarAndLength.length_on_ref;
1181
- }
1182
- get NUMERIC_CIGAR() {
1183
- return this.cigarAndLength.NUMERIC_CIGAR;
1184
- }
1185
- get CIGAR() {
1186
- const e = this.NUMERIC_CIGAR;
1187
- let t = "";
1188
- for (let n = 0, r = e.length; n < r; n++) {
1189
- const s = e[n], c = s >> 4, i = ge[s & 15];
1190
- t += c + String.fromCharCode(i);
1191
- }
1192
- return t;
1193
- }
1194
- get num_cigar_ops() {
1195
- return this.flag_nc & 65535;
1196
- }
1197
- get num_cigar_bytes() {
1198
- return this.num_cigar_ops << 2;
1199
- }
1200
- get read_name_length() {
1201
- return this.bin_mq_nl & 255;
1202
- }
1203
- get num_seq_bytes() {
1204
- return this.seq_length + 1 >> 1;
1205
- }
1206
- get NUMERIC_SEQ() {
1207
- const e = this.b0 + this.read_name_length + this.num_cigar_bytes;
1208
- return this.byteArray.subarray(e, e + this.num_seq_bytes);
1209
- }
1210
- get seq() {
1211
- const e = this.NUMERIC_SEQ, t = this.seq_length, n = new Array(t);
1212
- let r = 0;
1213
- const s = t >> 1;
1214
- for (let c = 0; c < s; ++c) {
1215
- const i = e[c];
1216
- n[r++] = E[(i & 240) >> 4], n[r++] = E[i & 15];
1217
- }
1218
- if (r < t) {
1219
- const c = e[s];
1220
- n[r] = E[(c & 240) >> 4];
1221
- }
1222
- return n.join("");
1223
- }
1224
- // adapted from igv.js
1225
- // uses template literal instead of array+join (6.4x faster, see benchmarks/string-building.bench.ts)
1226
- get pair_orientation() {
1227
- if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.ref_id === this.next_refid) {
1228
- const e = this.isReverseComplemented() ? "R" : "F", t = this.isMateReverseComplemented() ? "R" : "F";
1229
- let n = " ", r = " ";
1230
- return this.isRead1() ? (n = "1", r = "2") : this.isRead2() && (n = "2", r = "1"), this.template_length > 0 ? `${e}${n}${t}${r}` : `${t}${r}${e}${n}`;
1231
- }
1232
- }
1233
- get bin_mq_nl() {
1234
- return this._dataView.getInt32(this.bytes.start + 12, !0);
1235
- }
1236
- get flag_nc() {
1237
- return this._dataView.getInt32(this.bytes.start + 16, !0);
1238
- }
1239
- get seq_length() {
1240
- return this._dataView.getInt32(this.bytes.start + 20, !0);
1241
- }
1242
- get next_refid() {
1243
- return this._dataView.getInt32(this.bytes.start + 24, !0);
1244
- }
1245
- get next_pos() {
1246
- return this._dataView.getInt32(this.bytes.start + 28, !0);
1247
- }
1248
- get template_length() {
1249
- return this._dataView.getInt32(this.bytes.start + 32, !0);
1250
- }
1251
- seqAt(e) {
1252
- if (e < this.seq_length) {
1253
- const t = e >> 1, n = this.byteArray[this.b0 + this.read_name_length + this.num_cigar_bytes + t];
1254
- return e % 2 === 0 ? E[(n & 240) >> 4] : E[n & 15];
1255
- } else
1256
- return;
1257
- }
1258
- toJSON() {
1259
- const e = {};
1260
- for (const t of Object.keys(this))
1261
- t.startsWith("_") || t === "bytes" || (e[t] = this[t]);
1262
- return e;
1263
- }
1264
- }
1265
- function K(h) {
1266
- const e = h.split(/\r?\n/), t = [];
1267
- for (const n of e) {
1268
- const [r, ...s] = n.split(/\t/);
1269
- r && t.push({
1270
- tag: r.slice(1),
1271
- data: s.map((c) => {
1272
- const i = c.indexOf(":"), a = c.slice(0, i), l = c.slice(i + 1);
1273
- return { tag: a, value: l };
1274
- })
1275
- });
1276
- }
1277
- return t;
1278
- }
1279
- const W = 21840194, _e = 65536;
1280
- class me {
1281
- constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: c, csiPath: i, csiFilehandle: a, csiUrl: l, htsget: u, renameRefSeqs: o = (d) => d, recordClass: f }) {
1282
- if (this.htsget = !1, this.chunkFeatureCache = new V({
1283
- maxSize: 100
1284
- }), this.renameRefSeq = o, this.RecordClass = f ?? we, e)
1285
- this.bam = e;
1286
- else if (t)
1287
- this.bam = new v(t);
1288
- else if (n)
1289
- this.bam = new B(n);
1290
- else if (u)
1291
- this.htsget = !0, this.bam = new le();
1292
- else
1293
- throw new Error("unable to initialize bam");
1294
- if (a)
1295
- this.index = new $({ filehandle: a });
1296
- else if (i)
1297
- this.index = new $({ filehandle: new v(i) });
1298
- else if (l)
1299
- this.index = new $({ filehandle: new B(l) });
1300
- else if (s)
1301
- this.index = new F({ filehandle: s });
1302
- else if (r)
1303
- this.index = new F({ filehandle: new v(r) });
1304
- else if (c)
1305
- this.index = new F({ filehandle: new B(c) });
1306
- else if (t)
1307
- this.index = new F({ filehandle: new v(`${t}.bai`) });
1308
- else if (n)
1309
- this.index = new F({ filehandle: new B(`${n}.bai`) });
1310
- else if (u)
1311
- this.htsget = !0;
1312
- else
1313
- throw new Error("unable to infer index format");
1314
- }
1315
- async getHeaderPre(e) {
1316
- const t = Z(e);
1317
- if (!this.index)
1318
- return;
1319
- const n = await this.index.parse(t), r = n.firstDataLine === void 0 ? await this.bam.readFile() : (
1320
- // the logic indexData.firstDataLine is a virtualOffset telling us
1321
- // where the data is. It is in the middle of a virtualOffset
1322
- // (provided by the bgzip block offset at blockPosition + the
1323
- // virtualOffset dataPosition, so we add one extra blockLen to make
1324
- // sure we consume the full header)
1325
- await this.bam.read(n.firstDataLine.blockPosition + _e, 0)
1326
- ), s = await D(r), c = new DataView(s.buffer);
1327
- if (c.getInt32(0, !0) !== W)
1328
- throw new Error("Not a BAM file");
1329
- const i = c.getInt32(4, !0), a = new TextDecoder("utf8");
1330
- this.header = a.decode(s.subarray(8, 8 + i));
1331
- const { chrToIndex: l, indexToChr: u } = this._parseRefSeqs(s, i + 8);
1332
- return this.chrToIndex = l, this.indexToChr = u, K(this.header);
1333
- }
1334
- getHeader(e) {
1335
- return this.headerP || (this.headerP = this.getHeaderPre(e).catch((t) => {
1336
- throw this.headerP = void 0, t;
1337
- })), this.headerP;
1338
- }
1339
- async getHeaderText(e = {}) {
1340
- return await this.getHeader(e), this.header;
1341
- }
1342
- _parseRefSeqs(e, t) {
1343
- const n = new DataView(e.buffer), r = n.getInt32(t, !0);
1344
- let s = t + 4;
1345
- const c = {}, i = [], a = new TextDecoder("utf8");
1346
- for (let l = 0; l < r; l += 1) {
1347
- if (s + 8 > e.length)
1348
- throw new Error(`Insufficient data for reference sequences: need more than ${e.length} bytes`);
1349
- const u = n.getInt32(s, !0), o = this.renameRefSeq(a.decode(e.subarray(s + 4, s + 4 + u - 1))), f = n.getInt32(s + u + 4, !0);
1350
- c[o] = l, i.push({
1351
- refName: o,
1352
- length: f
1353
- }), s = s + 8 + u;
1354
- }
1355
- return { chrToIndex: c, indexToChr: i };
1356
- }
1357
- async getRecordsForRange(e, t, n, r) {
1358
- await this.getHeader(r);
1359
- const s = this.chrToIndex?.[e];
1360
- if (s === void 0 || !this.index)
1361
- return [];
1362
- const c = await this.index.blocksForRange(s, t - 1, n, r);
1363
- return this._fetchChunkFeaturesDirect(c, s, t, n, r);
1364
- }
1365
- chunkCacheKey(e, t) {
1366
- const { minv: n, maxv: r } = e;
1367
- return `${n.blockPosition}:${n.dataPosition}-${r.blockPosition}:${r.dataPosition}${re(t)}`;
1368
- }
1369
- blocksOverlap(e, t, n, r) {
1370
- return e <= r && t >= n;
1371
- }
1372
- // Evict any cached chunks that overlap with the given block range
1373
- evictOverlappingChunks(e, t) {
1374
- for (const [n, r] of this.chunkFeatureCache)
1375
- this.blocksOverlap(e, t, r.minBlock, r.maxBlock) && this.chunkFeatureCache.delete(n);
1376
- }
1377
- async _fetchChunkFeaturesDirect(e, t, n, r, s = {}) {
1378
- const { viewAsPairs: c, filterBy: i } = s, { flagInclude: a = 0, flagExclude: l = 0, tagFilter: u } = i || {}, o = [];
1379
- for (let f = 0, d = e.length; f < d; f++) {
1380
- const b = e[f], g = this.chunkCacheKey(b, i), x = b.minv.blockPosition, w = b.maxv.blockPosition;
1381
- let _;
1382
- const m = this.chunkFeatureCache.get(g);
1383
- if (m)
1384
- _ = m.features;
1385
- else {
1386
- this.evictOverlappingChunks(x, w);
1387
- const { data: p, cpositions: C, dpositions: I } = await this._readChunk({
1388
- chunk: b,
1389
- opts: s
1390
- }), k = await this.readBamFeatures(p, C, I, b);
1391
- if (i) {
1392
- _ = [];
1393
- for (let R = 0, T = k.length; R < T; R++) {
1394
- const P = k[R];
1395
- ne(P.flags, a, l) || u && se(P.tags[u.tag], u.value) || _.push(P);
1396
- }
1397
- } else
1398
- _ = k;
1399
- this.chunkFeatureCache.set(g, {
1400
- minBlock: x,
1401
- maxBlock: w,
1402
- features: _
1403
- });
1404
- }
1405
- let y = !1;
1406
- for (let p = 0, C = _.length; p < C; p++) {
1407
- const I = _[p];
1408
- if (I.ref_id === t)
1409
- if (I.start >= r) {
1410
- y = !0;
1411
- break;
1412
- } else I.end >= n && o.push(I);
1413
- }
1414
- if (y)
1415
- break;
1416
- }
1417
- if (c) {
1418
- const f = await this.fetchPairs(t, o, s);
1419
- for (let d = 0, b = f.length; d < b; d++)
1420
- o.push(f[d]);
1421
- }
1422
- return o;
1423
- }
1424
- async fetchPairs(e, t, n) {
1425
- const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n, c = {}, i = {};
1426
- for (let f = 0, d = t.length; f < d; f++) {
1427
- const b = t[f], g = b.name;
1428
- c[g] = (c[g] || 0) + 1, i[b.fileOffset] = 1;
1429
- }
1430
- const a = [];
1431
- for (let f = 0, d = t.length; f < d; f++) {
1432
- const b = t[f], g = b.name;
1433
- this.index && c[g] === 1 && (r || b.next_refid === e && Math.abs(b.start - b.next_pos) < s) && a.push(this.index.blocksForRange(b.next_refid, b.next_pos, b.next_pos + 1, n));
1434
- }
1435
- const l = /* @__PURE__ */ new Map(), u = await Promise.all(a);
1436
- for (let f = 0, d = u.length; f < d; f++) {
1437
- const b = u[f];
1438
- for (let g = 0, x = b.length; g < x; g++) {
1439
- const w = b[g], _ = w.toString();
1440
- l.has(_) || l.set(_, w);
1441
- }
1442
- }
1443
- return (await Promise.all([...l.values()].map(async (f) => {
1444
- const { data: d, cpositions: b, dpositions: g, chunk: x } = await this._readChunk({
1445
- chunk: f,
1446
- opts: n
1447
- }), w = [], _ = await this.readBamFeatures(d, b, g, x);
1448
- for (let m = 0, y = _.length; m < y; m++) {
1449
- const p = _[m];
1450
- c[p.name] === 1 && !i[p.fileOffset] && w.push(p);
1451
- }
1452
- return w;
1453
- }))).flat();
1454
- }
1455
- async _readChunk({ chunk: e, opts: t }) {
1456
- const n = await this.bam.read(e.fetchedSize(), e.minv.blockPosition, t), { buffer: r, cpositions: s, dpositions: c } = await Y(n, e);
1457
- return { data: r, cpositions: s, dpositions: c, chunk: e };
1458
- }
1459
- async readBamFeatures(e, t, n, r) {
1460
- let s = 0;
1461
- const c = [];
1462
- let i = 0;
1463
- const a = new DataView(e.buffer), l = n.length > 0, u = t.length > 0;
1464
- for (; s + 4 < e.length; ) {
1465
- const o = a.getInt32(s, !0), f = s + 4 + o - 1;
1466
- if (l) {
1467
- for (; s + r.minv.dataPosition >= n[i++]; )
1468
- ;
1469
- i--;
1470
- }
1471
- if (f < e.length) {
1472
- const d = new this.RecordClass({
1473
- bytes: {
1474
- byteArray: e,
1475
- start: s,
1476
- end: f
1477
- },
1478
- fileOffset: u ? t[i] * 256 + (s - n[i]) + r.minv.dataPosition + 1 : de(e.subarray(s, f)) >>> 0
1479
- });
1480
- c.push(d);
1481
- }
1482
- s = f + 1;
1483
- }
1484
- return c;
1485
- }
1486
- async hasRefSeq(e) {
1487
- const t = this.chrToIndex?.[e];
1488
- return t === void 0 ? !1 : this.index?.hasRefSeq(t);
1489
- }
1490
- async lineCount(e) {
1491
- const t = this.chrToIndex?.[e];
1492
- return t === void 0 || !this.index ? 0 : this.index.lineCount(t);
1493
- }
1494
- async indexCov(e, t, n) {
1495
- if (!this.index)
1496
- return [];
1497
- await this.index.parse();
1498
- const r = this.chrToIndex?.[e];
1499
- return r === void 0 ? [] : this.index.indexCov(r, t, n);
1500
- }
1501
- async blocksForRange(e, t, n, r) {
1502
- if (!this.index)
1503
- return [];
1504
- await this.index.parse();
1505
- const s = this.chrToIndex?.[e];
1506
- return s === void 0 ? [] : this.index.blocksForRange(s, t, n, r);
1507
- }
1508
- clearFeatureCache() {
1509
- this.chunkFeatureCache.clear();
1510
- }
1511
- async estimatedBytesForRegions(e, t) {
1512
- if (!this.index)
1513
- return 0;
1514
- if (await this.getHeader(t), !this.chrToIndex)
1515
- throw new Error("Header not yet parsed");
1516
- return this.index.estimatedBytesForRegions(e.map((n) => {
1517
- const r = this.chrToIndex[n.refName];
1518
- if (r === void 0)
1519
- throw new Error(`Unknown reference name: ${n.refName}`);
1520
- return {
1521
- refId: r,
1522
- start: n.start,
1523
- end: n.end
1524
- };
1525
- }), t);
1526
- }
1527
- }
1528
- async function z(h, e) {
1529
- const t = await Promise.all(h.map(async (n) => {
1530
- const { url: r, headers: s } = n;
1531
- if (r.startsWith("data:")) {
1532
- const c = await fetch(r);
1533
- if (!c.ok)
1534
- throw new Error("failed to decode base64");
1535
- const i = await c.arrayBuffer();
1536
- return new Uint8Array(i);
1537
- } else {
1538
- const { referer: c, ...i } = s, a = await fetch(r, {
1539
- ...e,
1540
- headers: { ...e?.headers, ...i }
1541
- });
1542
- if (!a.ok)
1543
- throw new Error(`HTTP ${a.status} fetching ${r}: ${await a.text()}`);
1544
- return new Uint8Array(await a.arrayBuffer());
1545
- }
1546
- }));
1547
- return te(await Promise.all(t.map((n) => D(n))));
1548
- }
1549
- class Re extends me {
1550
- constructor(e) {
1551
- super({ htsget: !0, recordClass: e.recordClass }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
1552
- }
1553
- async getRecordsForRange(e, t, n, r) {
1554
- const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, i = this.chrToIndex?.[e];
1555
- if (i === void 0)
1556
- return [];
1557
- const a = await fetch(c, { ...r });
1558
- if (!a.ok)
1559
- throw new Error(`HTTP ${a.status} fetching ${c}: ${await a.text()}`);
1560
- const l = await a.json(), u = await z(l.htsget.urls.slice(1), r), o = await this.readBamFeatures(u, [], [], {
1561
- minv: { dataPosition: 0, blockPosition: 0 },
1562
- maxv: { dataPosition: 0, blockPosition: 0 }
1563
- }), f = [];
1564
- for (let d = 0, b = o.length; d < b; d++) {
1565
- const g = o[d];
1566
- if (g.ref_id === i) {
1567
- if (g.start >= n)
1568
- break;
1569
- g.end >= t && f.push(g);
1570
- }
1571
- }
1572
- return f;
1573
- }
1574
- async getHeader(e = {}) {
1575
- const t = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, n = await fetch(t, e);
1576
- if (!n.ok)
1577
- throw new Error(`HTTP ${n.status} fetching ${t}: ${await n.text()}`);
1578
- const r = await n.json(), s = await z(r.htsget.urls, e), c = new DataView(s.buffer);
1579
- if (c.getInt32(0, !0) !== W)
1580
- throw new Error("Not a BAM file");
1581
- const i = c.getInt32(4, !0), l = new TextDecoder("utf8").decode(s.subarray(8, 8 + i)), u = K(l), o = [], f = {}, d = u.filter((b) => b.tag === "SQ");
1582
- for (const [b, g] of d.entries()) {
1583
- let x = "", w = 0;
1584
- for (const _ of g.data)
1585
- _.tag === "SN" ? x = _.value : _.tag === "LN" && (w = +_.value);
1586
- f[x] = b, o[b] = { refName: x, length: w };
1587
- }
1588
- return this.chrToIndex = f, this.indexToChr = o, u;
1589
- }
1590
- }
1591
- export {
1592
- F as BAI,
1593
- me as BamFile,
1594
- we as BamRecord,
1595
- $ as CSI,
1596
- Re as HtsgetFile
1597
- };