# @gmod/cram 中文文档

规范地址：https://npmcn.com/package/%40gmod/cram/

版本：14\.5\.0
npm 元数据更新时间：2026-11-15T17:48:15.647Z
中文译文更新时间：2026-11-16T17:08:14.292Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40gmod/cram
原文对照：https://npmcn.com/package/%40gmod/cram/?lang=original
项目主页：https://github.com/GMOD/cram-js#readme
源码仓库：https://github.com/GMOD/cram-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：4 MB，372 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- 首次发布：2018-07-14T00:51:56.176Z
- 最新版本发布：2026-11-15T17:48:15.275Z
- 近 30 天下载量：38396（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：122（近 12 个月 59 个）

## 中文简介

使用纯 Javascript 读取 CMRA 文件

## 安装

```sh
npm install @gmod/cram
```

也可以使用：`pnpm add @gmod/cram`、`yarn add @gmod/cram`、`bun add @gmod/cram`

## README

# @ gmod/ cram (英语)

[![NPM version](https://img.shields.io/npm/v/@gmod/cram.svg?style=flat-square)](https://npmjs.org/package/@gmod/cram) ![Build Status](https://img.shields.io/github/actions/workflow/status/GMOD/cram-js/publish.yml?branch=main)

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

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

```bash
npm install @gmod/cram
```

## 快开始

```js
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`) (中文(简体) ).

```js
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` 没有它。 见 [错配](https://npmcn.com/package/%40gmod/cram/docs/api.md#mismatch) 用于字段和窗口,以及 [参考序列](https://npmcn.com/package/%40gmod/cram/docs/api.md#reference-sequence) 为召回.

## 记录

```js
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
```

[文件/附录](https://npmcn.com/package/%40gmod/cram/docs/api.md#cramrecord) 列出所有财产和方法.

## 标题、参考名称和取消

```js
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`](https://github.com/GMOD/range-cache-filehandle) 将许多小 HTTP 请求的查询合并为更少, 重复使用字节 各种查询:

```js
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` 设置大小 (单位:千美元)[工人](https://npmcn.com/package/%40gmod/cram/docs/workers.md)) (中文(简体) ).

## 脚本标签

一个独立的浏览器构建将同样的导出打开 `window.gmodCRAM`,装入 它的编码工作从同一个目录中解码,没有它,在程序中解码. 这个 [示例目录](https://npmcn.com/package/%40gmod/cram/example) 有工作页.

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

## 文档

-   [文件/附录](https://npmcn.com/package/%40gmod/cram/docs/api.md):每个选项、财产和方法,包括 记录的原始读取特性
-   [移民.md](https://npmcn.com/package/%40gmod/cram/MIGRATION.md): 打破变化, 首先是最新变化
-   [文件/数据流.md](https://npmcn.com/package/%40gmod/cram/docs/dataflow.md):从索引到记录的查询 链接到设计文档和发展成果评估

## 学术用途

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

## 许可证

麻省理工学院

## 常见问题

### @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 和提交记录判断。

