npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gmod/tabix

v3.13.1

Published

Read Tabix-indexed files, supports both .tbi and .csi indexes

Readme

@gmod/tabix

NPM version Build Status

Read Tabix-indexed files using either .tbi or .csi indexes.

Install

npm install @gmod/tabix

Usage

import { TabixIndexedFile } from '@gmod/tabix'

// Local file — TBI index assumed at path + '.tbi'
const file = new TabixIndexedFile({ path: 'file.vcf.gz' })

// CSI index
const csi = new TabixIndexedFile({
  path: 'file.vcf.gz',
  csiPath: 'file.vcf.gz.csi',
})

// Remote files: one HTTP request per read
const remote = new TabixIndexedFile({
  url: 'https://example.com/file.vcf.gz',
  tbiUrl: 'https://example.com/file.vcf.gz.tbi',
})

// Remote files through a range cache (recommended)
import { RemoteFileWithRangeCache } from '@gmod/range-cache-filehandle'

const cached = new TabixIndexedFile({
  filehandle: new RemoteFileWithRangeCache('https://example.com/file.vcf.gz'),
  tbiFilehandle: new RemoteFileWithRangeCache(
    'https://example.com/file.vcf.gz.tbi',
  ),
})

A bare url sends one request per read and caches nothing. @gmod/range-cache-filehandle merges neighboring blocks into one request and fetches each byte once. Without it, twenty half-overlapping windows panned across the 3.4 MB test BED file read 11 MB.

getLines

Fetches lines overlapping a region. start/end are 0-based half-open coordinates (unlike the tabix CLI which uses 1-based closed).

const lines: string[] = []
await file.getLines('chr1', 200, 300, line => lines.push(line))

The callback also receives the virtual file offset and parsed coordinates for the line:

await file.getLines('chr1', 200, 300, (line, fileOffset, start, end) => {
  lines.push(line)
})

Pass an options object instead of a bare callback to abort the query or track download progress:

const aborter = new AbortController()
await file.getLines('chr1', 200, 300, {
  lineCallback: (line, fileOffset, start, end) => lines.push(line),
  signal: aborter.signal,
  onProgress: (bytesDownloaded, totalBytes) => {
    console.log(`${bytesDownloaded}/${totalBytes}`)
  },
})

onProgress ticks once per chunk, the run of BGZF blocks the index resolves a query to. totalBytes comes from the index and is known up front.

Notes:

  • The scan skips meta/comment lines
  • Line strings have no trailing whitespace
  • Pass undefined for end to read to the end of the contig
  • A refName that is not in the index yields no lines and no error, so a chr1/1 naming mismatch looks like an empty region. Check against getReferenceSequenceNames if a query comes back unexpectedly empty
  • start > end throws a TypeError; start === end returns without reading

GAF

tabix-js reads tabix -p gaf indexes of sorted GAF (e.g. from vg gamsort):

  • refName is ignored; getReferenceSequenceNames() returns []
  • start/end are node ids: a read matches when its lowest-to-highest node range [min, max] touches any of start..end-1, the same reads as tabix file.gaf.gz "{x}:start-end" (no +1)
  • The callback gets min and max + 1
  • getLines skips reads whose path is a stable sequence name (no >/<)

Without NPM (CDN)

<script src="https://unpkg.com/@gmod/tabix/dist/tabix-bundle.js"></script>

See example/index.html for a demo; serve the directory (e.g. npx serve example) rather than opening the file directly.

How a query flows

getLines looks up a region's BGZF chunks in the index, decompresses each chunk in wasm, and scans the bytes for matching lines in JS; see docs/dataflow.md.

TabixIndexedFile caches decompressed chunks, up to 1GB per file, and drops them after three idle minutes. A consumer holding one file per track should bound them together with a shared chunkCacheBudget rather than shrinking each file's ceiling; see docs/caching.md.

Decompressing on a worker pool

BGZF blocks inflate independently, so a worker pool can spread decompression across threads.

import { getSharedWorkerPool } from '@gmod/bgzf-filehandle'

const file = new TabixIndexedFile({
  url: 'https://example.com/yourfile.vcf.gz',
  // the pending promise is fine — it is awaited at the point of use
  bgzfWorkerPool: getSharedWorkerPool(),
})

You can pass the pool unconditionally: getSharedWorkerPool() returns undefined under node, or anywhere the host forbids Workers, and tabix-js then decompresses in-process. The pool needs no cross-origin isolation, and tabix-js never creates one itself, so the consumer controls the thread budget.

On a multi-sample VCF the pool speeds up end-to-end queries by about 1.4x; see docs/optimizations.md and bgzf-filehandle's worker pool docs.

Docs

Academic Use

Written with NHGRI funding as part of JBrowse. If you use this in a publication, please cite the most recent JBrowse paper at jbrowse.org.

License

MIT