.gjson 文件定义
.gjson 是 GenePad 的文本 JSON 交换格式,当前写出版本为 1.9。
序列、注释、引物全部是人类可读的 JSON,适合人工查看、版本 diff、脚本生成与跨语言读取;
代价是不保存撤销历史、测序图谱等工程状态(那是 .gen 的职责)。
写出与解析由应用内的 Rust 组件完成,因此键名混合了 camelCase 与 snake_case——见下方命名规则。
Overview
读取规则
- 唯一必须的字段是
sequence,且必须非空——否则整个文件被拒绝(错误「GJSON file contains no sequence」)。version不是必须的,读取器兼容无版本号的旧文件。 - 显示名解析链:
custom_name(非空白)→id(有意义时)→"Unnamed"。占位 id(如"."、空串、去掉非字母数字后为空)不作为名字。 length缺失或为 0 时按sequence实际长度计算;isCircular缺省false;isDoubleStranded缺省true。- 分段容错:
features/primers/baseColorRanges/alignmentEntries/references任何一段反序列化失败,只丢弃该段并记入 warnings——序列本体不受影响。例如某个 feature 的start写成了字符串,整个 features 数组被跳过,但序列照常加载。 - feature 的
segments段数 ≤ 1 时直接忽略(单段 feature 只用顶层 start/end)。 - 不持久化的内容:限制酶位点(加载后重新检测)、Dam/Dcm 甲基化状态、测序图谱(chromatogram)。
- 坐标为 1-based inclusive;环形序列跨原点时
start > end,与.gen相同。
Getting Started
快速上手(Python)
就是普通 JSON,标准库直接读。可下载真实示例文件试跑:41-pPUR-P2A-BFPnls-sgRNA1-RNF2_4AtoG_MS2-MA.gjson(18 KB,7,952 bp 环形慢病毒 sgRNA 载体,25 个 feature、2 条引物):
import json
doc = json.load(open("plasmid.gjson", encoding="utf-8"))
print(doc["custom_name"], doc["length"], "bp,",
"环状" if doc["isCircular"] else "线状")
print(doc["sequence"][:30] + "…")
for f in doc["features"]:
print(f["start"], f["end"], f["type"], f["name"], f["strand"])
for p in doc["primers"]:
for s in p["bindingSites"]:
print(p["name"], s["boundStrand"],
round(s["meltingTemperature"], 1), "°C")
41-pPUR-P2A-BFPnls-sgRNA1-RNF2_4AtoG_MS2-MA 7952 bp, 环状
ttggggttgcgccttttccaaggcagccctgg…
7687 7715 misc_feature 4AtoG forward
...(共 25 个 feature)
Primer 2 reverse 80.9 °C
Primer 1 forward 73.0 °C
Example
最小有效结构与写出骨架
对读取器而言,一行也够——只要有非空的 sequence:
{ "sequence": "ATGGC..." }
而 GenePad 写出器产出的完整骨架如下(真实样本节选,长序列截断;键序即写出顺序)。注意缺失的可选元数据写成显式 null,空数组对应的键整个省略:
{
"version": "1.9",
"id": "gjson-1787405886329",
"type_of_display": "file_name",
"custom_name": "41-pPUR-P2A-BFPnls-sgRNA1-RNF2_4AtoG_MS2-MA",
"description": "ORIGDB|GenBank",
"sequence": "ttggggttgcgccttttccaaggcagccctggg…",
"length": 7952,
"isCircular": true,
"isDoubleStranded": true,
"accession": "-",
"organism": null,
"date": "2021.6.10",
"moleculeType": null,
"division": null,
"gbVersion": null,
"keywords": null,
"source": null,
"comments": null,
"references": null,
"features": [ … ],
"primers": [ … ]
}
该样本没有碱基着色和比对条目,所以没有 baseColorRanges / alignmentEntries 键——为空时写出器直接省略,而不是写 []。
Top Level
顶层字段
| 字段 | 写出行为 | 读取行为 / 默认 |
|---|---|---|
version | 恒 "1.9" | 非必需;不影响解析 |
id | "gjson-{Unix毫秒}",每次导出新生成 | 缺省回退为显示名;custom_name 为空且 id 有意义时用作显示名 |
type_of_display | 恒 "file_name" | 读取时不使用(显示名策略由文件名接管) |
custom_name | = 项目名 | 显示名首选(需非空白) |
description | 恒为字符串(可 "") | 缺失 → "" |
sequence | 主序列原样(大小写保留) | 必须非空,唯一硬性要求 |
length | = sequence.length | 缺失或 0 → 按实际序列长度 |
isCircular | 布尔 | 缺失 → false |
isDoubleStranded | 布尔(内存未知时按 true 写出) | 缺失 → true |
accession | 缺失写 null | GenBank ACCESSION |
organism | 缺失写 null | GenBank ORGANISM |
date | 缺失写 null | GenBank LOCUS 日期 |
moleculeType | 缺失写 null | LOCUS 分子类型 |
division | 缺失写 null | GenBank division |
gbVersion | 缺失写 null | 映射到内部 version(GenBank VERSION) |
keywords | 缺失写 null | GenBank KEYWORDS |
source | 缺失写 null | GenBank SOURCE |
comments | 缺失写 null | GenBank COMMENT |
references | GenBankRef[],缺失写 null | 坏数组 → 跳过并记 warning |
features | 恒写出(可为 []) | 缺失按空数组;坏数组 → 跳过并记 warning |
baseColorRanges | 空则省略整键 | 缺失/坏数组 → 无着色 |
primers | 空则省略整键 | 缺失按无引物;坏数组 → 跳过并记 warning |
alignmentEntries | 空则省略整键 | 缺失按无比对;坏数组 → 跳过并记 warning |
Objects
对象定义
GjsonFeature注释对象(真实样本值)
{
"id": "feature-24",
"name": "MS2 stem loop",
"type": "misc_RNA",
"start": 7716,
"end": 7734,
"strand": "forward",
"color": "#99cc00",
"label": "MS2 stem loop",
"note": "/vntifkey=16",
"frame": null,
"visible": true,
"qualifiers": null
}
前 11 个字段恒写出:color/label/note/frame 缺失时写 null,visible 缺省按 true 写。segments 仅在段数 > 1 时写出,且每段只有 start/end/strand?(.gen 段上可选的 name/color 不导出):"segments": [{ "start": 5627, "end": 5643 }, …]。qualifiers 为 Record<string, string[]> 或 null。坐标 1-based inclusive,环形跨原点时 start > end。
GjsonPrimer / bindingSites引物与结合位点(注意内层 snake_case)
{
"id": "primer-0",
"name": "Primer 2",
"sequence": "acatgggtgatcctcatgtcatcttagtcattacctggg…",
"description": "",
"bindingSites": [
{
"start": 7671,
"end": 7734,
"boundStrand": "reverse",
"annealedBases": "ggcaccgagtcggtgcaacgaacaccccaggtaatgactaagatg…",
"meltingTemperature": 80.86570880948138,
"components": [
{
"hybridized_range": "7670-7733",
"bases": "ggcaccgagtcggtgcaacgaacaccccaggtaatgactaagatg…"
}
],
"alignment": [
{
"type": "annealed",
"primer_bases": "ggcaccgagtcggtgcaac…",
"template_bases": "ggcaccgagtcggtgcaac…",
"template_start": 7671,
"template_end": 7734
}
]
}
],
"visible": null
}
引物层的键是 camelCase(bindingSites/boundStrand/annealedBases/meltingTemperature),但 components 与 alignment 内层是 snake_case(hybridized_range/primer_bases/template_bases/template_start/template_end)——与 .gen 数据库 JSON 列的 camelCase 不同,互转时要改名。visible 恒写 null(写出器固定行为,引主可见性在 .gjson 中不保真)。alignment 段的 type 取值 annealed / unannealed / del;alignment 整体可省略。
BaseColorRange碱基颜色
{
"id": "base-color-0",
"color": "#ffcc00",
"start": 1,
"end": 20,
"strand": "forward"
}
五个字段恒写出。strand 只接受 forward / reverse;非 reverse 会被归一为 forward。顶层 baseColorRanges 为空时整个键省略。
AlignmentEntry比对条目(仅四字段)
{
"id": "align-1",
"name": "Sanger read 1",
"sequence": "ATGC…",
"visible": true
}
.gjson 中比对条目只保留 id, name, sequence, visible(visible 缺省 true);运行时挂在上面的 chromatogram 不写入。顶层 alignmentEntries 为空时整个键省略。
GenBankRef文献条目
{
"number": 1,
"authors": "Smith,J.",
"title": "Cloning of pBR322",
"journal": "Nucleic Acids Res 2026",
"pubmed": "12345678",
"remark": "…"
}
只有 number 必有;其余字段可省略(省略键,而非写 null)。
Writer
写出行为与命名规则
| 规则 | 内容 |
|---|---|
| 序列化 | pretty JSON,2 空格缩进,LF 换行,UTF-8(非 ASCII 字符不转义)。键序固定(即上方骨架的顺序),便于逐行 diff |
| 恒定值 | version = "1.9"、type_of_display = "file_name"、id = "gjson-{Unix毫秒}"、custom_name = 项目名、primers[].visible = null |
| 省略策略 | baseColorRanges / primers / alignmentEntries 为空时整个键省略;feature 的 segments 段数 ≤ 1 时省略;GenBankRef 的可选字段省略键。其余可选值(organism、gbVersion、feature.qualifiers…)写显式 null |
| 命名规则 | 顶层 type_of_display / custom_name 为 snake_case;常规字段 camelCase(isCircular、moleculeType、gbVersion、bindingSites、boundStrand、annealedBases、meltingTemperature、baseColorRanges、alignmentEntries);结合位点内层 components / alignment 的字段为 snake_case(hybridized_range、primer_bases、template_bases、template_start、template_end) |
| 与 .gen 互转 | 除键名改名外,注意 '' ↔ null(.gen 的 GenBank 元数据空串在 .gjson 里是 null)、引物 visible 丢失、segments 段的 name/color 丢失。现成脚本见 .gen 页的导出配方(已用真实文件核对,逐字段一致) |
Fidelity
与 .gen 的保真差异
.gjson 不存储:撤销/重做栈(undo_entries)、编辑审计(edit_history)、附件(attachments)、主序列与比对条目的测序图谱(chromatogram)、Dam/Dcm 甲基化、引物可见性(写出时写 null)、feature 多段注释里的段级 name/color、显示名策略(typeOfDisplay)。需要完整工程快照请使用 .gen;两者坐标体系(1-based inclusive、跨原点 start > end)完全一致,互转不涉及坐标换算。
See Also