@gmod/twobit

中文文档
6.0.14发布于 2026/10/12MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3.4万

Read .2bit files in node or webpack

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Academic use
  4. Contributing
  5. License

@gmod/twobit

NPM version Build Status

Read .2bit sequence files, in Node.js or the browser.

Install

$ npm install @gmod/twobit

Usage

import { TwoBitFile } from '@gmod/twobit'

const t = new TwoBitFile({ path: 'path/to/file.2bit' })

// coordinates are 0-based half-open
await t.getSequence('chr1', 0, 10) // first 10 bases
await t.getSequence('chr1') // whole sequence
await t.getSequenceNames() // ['chr1', ...]
await t.getSequenceSizes() // { chr1: length, ... }
await t.getSequenceSize('chr1')

In the browser, or for a file over HTTP, pass a filehandle from generic-filehandle2 instead of a path:

import { RemoteFile } from 'generic-filehandle2'

const t = new TwoBitFile({
  filehandle: new RemoteFile('https://example.com/file.2bit'),
})

Reading a sequence takes four reads: the record header and its two block tables, which come to 32 bytes and sit at the same offsets every time you read that sequence, then the packed bases. Over HTTP that is four round trips per sequence, so a byte-range cache such as @gmod/range-cache-filehandle is a cheap swap for RemoteFile. It serves reads out of 256 KiB chunks, so the header reads come from memory after the first one and neighboring sequences share a request. The index is read once, in chunks sized for typical sequence names, so a scaffold-level assembly with hundreds of thousands of sequences costs a few megabytes rather than a read sized for the longest name the format allows.

Returned sequences preserve the file's encoding: lowercase for soft-masked bases, N/n for ambiguous ones.

See docs/api.md for the full API reference.

Academic use

This package was written with funding from the NHGRI as part of the JBrowse project. If you use it in an academic project that you publish, please cite the most recent JBrowse paper, which will be linked from jbrowse.org.

Contributing

See CONTRIBUTING.md for development and release workflow.

License

MIT © Robert Buels

版本与发布记录

@gmod/twobit 共发布 38 个版本,首次发布于 2018/07/26;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.14latest2026/10/121 个月前
6.0.132026/10/081 个月前
6.0.122026/08/113 个月前
6.0.112026/08/013 个月前
6.0.102026/07/253 个月前
6.0.92026/05/195 个月前

关于 @gmod/twobit 的常见问题

@gmod/twobit 是什么?

Read .2bit files in node or webpack

如何安装 @gmod/twobit?

在项目目录运行 npm install @gmod/twobit,或使用 pnpm add / yarn add / bun add。

@gmod/twobit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gmod/twobit 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gmod/twobit 可以商用吗?

@gmod/twobit 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gmod/twobit 的下载量有多少?

根据 npm 官方下载统计,@gmod/twobit 在 2026/10/17 – 2026/11/15 这 30 天内被下载 33,845 次,日均约 1,128 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gmod/twobit 还在维护吗?

最新版本 6.0.14 发布于 2026/10/12(1 个月前);至今共发布 38 个版本,其中过去 12 个月发布了 12 个;首次发布于 2018/07/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。