@gmod/cram

中文文档
14.5.0发布于 2026/11/16MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3.8万

使用纯 Javascript 读取 CMRA 文件

中文使用文档
文档目录9 节
  1. 快开始
  2. 错位
  3. 记录
  4. 标题、参考名称和取消
  5. 业绩
  6. 脚本标签
  7. 文档
  8. 学术用途
  9. 许可证

@ gmod/ cram (英语)

NPM version Build Status

在节点或浏览器中读取CMAM文件.

  • 处理 CRAM 2.x和 3.x, .crai 索引,和每v3和v3.1代码, 包括 fqzcomp 和 tok3 .
  • 编解码器是 samtool 使用的 Htscodecs C 库,编译为 网络大会和内嵌在捆绑中,所以没有 .wasm 要服务的文件 .
  • Golomb和Golomb-Rice仅使用v2文件,但没有执行.
npm install @gmod/cram

快开始

import { IndexedCramFile, CraiIndex } from '@gmod/cram'
import { IndexedFasta } from '@gmod/indexedfasta'
import { RemoteFile } from 'generic-filehandle2'

const fasta = new IndexedFasta({
  fasta: new RemoteFile('https://example.com/reference.fa'),
  fai: new RemoteFile('https://example.com/reference.fa.fai'),
})

const indexedFile = new IndexedCramFile({
  cramUrl: 'https://example.com/file.cram',
  index: new CraiIndex({ url: 'https://example.com/file.cram.crai' }),
  fetchReferenceSequence: (seqId, start, end, refName, opts) =>
    fasta.getSequence(refName, start, end, opts),
})

const records = await indexedFile.getRecordsForRange('chr1', 10000, 20000)

for (const record of records) {
  for (const { code, refPos, bases } of record.getMismatches()) {
    console.log(record.readName, String.fromCharCode(code), refPos, bases)
  }
}

本地文件, 密码 cramPath, (中文(简体) ), CraiIndex({ path }) 财务报告和审定财务报表 IndexedFasta({ path })。 。 。 .

  • 坐标为0-半开,如: @gmod/bam; 为基于 1 的添加 1 sAM 等格式 POS。 。 。 .
  • 在文件头中查询其名称的引用, 例如 chr1, (中文(简体) ), 1 或者说 CHROMOSOME_I。文件名称缺少返回 []。 。 。 .

错位

record.getMismatches() 列表替换、插入、删除、引用 跳过和剪辑,和 forEachMismatch 把它们交给一个召回. code 是一个CIGAR字符代码(88 for X) (中文(简体) ).

import { RF_SUBST } from '@gmod/cram'

record.forEachMismatch(
  (code, refPos, length, bases, qual, refBaseCode, clipLength) => {
    if (code === RF_SUBST) {
      console.log(refPos, bases)
    }
  },
  { start: 10000, end: 20000 }, // optional window
)

替换需要快速启动 fetchReferenceSequence,并读 N 没有它。 见 错配 用于字段和窗口,以及 参考序列 为召回.

记录

record.getReadBases() // 'ACGT…', the read sequence
record.getCigarString() // '50M2I48M'
record.getTag('NM') // one auxiliary tag
record.qualityScoreAt(0) // one base quality
record.isReverseComplemented() // the usual SAM flags

文件/附录 列出所有财产和方法.

标题、参考名称和取消

await indexedFile.cram.getReferenceInfo() // [{ name, length, md5 }, ...]
await indexedFile.cram.getSamHeader() // parsed SAM header
await indexedFile.hasDataForReferenceSequence('chrY') // false if the file has no chrY

const controller = new AbortController()
await indexedFile.getRecordsForRange('chr1', 0, 1_000_000, {
  signal: controller.signal,
})

业绩

@gmod/range-cache-filehandle 将许多小 HTTP 请求的查询合并为更少, 重复使用字节 各种查询:

import { RemoteFileWithRangeCache } from '@gmod/range-cache-filehandle'

const indexedFile = new IndexedCramFile({
  cramFilehandle: new RemoteFileWithRangeCache(url),
  index: new CraiIndex({
    filehandle: new RemoteFileWithRangeCache(`${url}.crai`),
  }),
})

在浏览器中,切片默认在工人池上解码. 过 useSliceWorkerPool: false 关闭,或 numSliceWorkers 设置大小 (单位:千美元)工人) (中文(简体) ).

脚本标签

一个独立的浏览器构建将同样的导出打开 window.gmodCRAM,装入 它的编码工作从同一个目录中解码,没有它,在程序中解码. 这个 示例目录 有工作页.

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

文档

  • 文件/附录:每个选项、财产和方法,包括 记录的原始读取特性
  • 移民.md: 打破变化, 首先是最新变化
  • 文件/数据流.md:从索引到记录的查询 链接到设计文档和发展成果评估

学术用途

写为 (原始内容存档于2018-09-21) (韩语). NHGRI 供资,作为 J 浏览如果您在出版物中使用,请引用 最近JBrowse的论文 jbrowse.org (英语)。 。 。 .

许可证

麻省理工学院

版本与发布记录

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

版本发布日期距今
14.5.0latest2026/11/161 天前
14.4.02026/11/097 天前
14.3.22026/10/141 个月前
14.3.12026/10/121 个月前
14.3.02026/10/111 个月前
14.2.12026/10/091 个月前

关于 @gmod/cram 的常见问题

@gmod/cram 是什么?

使用纯 Javascript 读取 CMRA 文件

如何安装 @gmod/cram?

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

@gmod/cram 支持 TypeScript 吗?

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

@gmod/cram 支持 ESM 还是 CommonJS?

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

@gmod/cram 可以商用吗?

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

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

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

@gmod/cram 还在维护吗?

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