dsh-molbio-tools 0.28.0 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/benchmark/harness.mjs +11 -3
- package/benchmark/profile.mjs +2 -2
- package/benchmark/run.mjs +3 -1
- package/benchmark/sequences.mjs +16 -0
- package/benchmark/tasks/01-core.json +1 -1
- package/benchmark/tasks/02-primers.json +1 -5
- package/benchmark/tasks/09-formats.json +1 -1
- package/benchmark/tasks/10-v28.json +1 -1
- package/benchmark/verifications.mjs +2 -8
- package/docs/rules.md +24 -0
- package/index.mjs +155 -77
- package/package.json +3 -2
- package/test/prompt.mjs +149 -0
- package/test/smoke.mjs +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,63 @@
|
|
|
10
10
|
改为按**包名**引用后模块缓存问题随之消失——没有拷贝,也就没有需要保持同步的版本目录。
|
|
11
11
|
下文历史条目里出现的 `vN` 目录保持原样,作为当时的记录。
|
|
12
12
|
|
|
13
|
+
## [0.28.1] — 2026-12-01(提示面受测化 + 文件输入收敛 + 判分口径修正)
|
|
14
|
+
|
|
15
|
+
**工具数 72 不变,benchmark 73 题不变。** 这一版全部是 0.28.0 之后的提示词与工具接口修复:`prompt` 面
|
|
16
|
+
第一次成为受测产物,四个工具补齐了文件输入/输出边界,三处 benchmark 判分口径被修正。没有新增工具,
|
|
17
|
+
`engines`、preset 行清单与面板包均未改。
|
|
18
|
+
|
|
19
|
+
### 1. 提示面(prompt)受测化
|
|
20
|
+
|
|
21
|
+
- **`PROMPT_SECTION` 重写**:按问题路由(72 个工具全覆盖)+ 8 条硬规则 + 5 条约定;删掉 `(v19)`/`(v28)`
|
|
22
|
+
之类版本标记与重复段落;11,185 → 5,813 字符(预算 6,000),最长行 1,408 → 364 字符。
|
|
23
|
+
- **新增 `test/prompt.mjs`**:段落预算 / 单行宽度 / 无版本标记 / 工具覆盖(双向)/ 与工具描述 ≥60 字符
|
|
24
|
+
逐字去重,五个不变量 + 五个突变实验(规则 9:守卫必须被证明会失败),已并入 `npm test`。
|
|
25
|
+
- **描述去重与行为指引**:跨描述 ≥70 字符逐字重合 11 对 → 0 对;同时补进"一次调用拿全"、"报数而不只是
|
|
26
|
+
报路径"、"不要用 translate/脚本复核工具已算过的结果"等指引。
|
|
27
|
+
|
|
28
|
+
### 2. 工具接口修复(来自 4 轮全量 benchmark 的逐题会话复盘)
|
|
29
|
+
|
|
30
|
+
- **`molbio_parse_genbank` 新增 `path`**:此前只收内联文本,逼模型读文件再重打,实测产生 3163 bp 的转录错误
|
|
31
|
+
并丢失 `complement()`;现在与 `molbio_parse_snapgene` 一样直接吃文件。
|
|
32
|
+
- **`molbio_align` 新增 `path1`/`path2`**,并识别 FASTA / GenBank(`LOCUS`)/ SnapGene `.dna`:两条长序列的
|
|
33
|
+
一致性比对从「extract_region ×4 + pwsh 比字符串」收敛为一次调用。
|
|
34
|
+
- **`molbio_editing_outcome` 的 `paths` 支持多记录 FASTA**:此前会把整份 `reads.fa` 当成单条 trace 拒绝
|
|
35
|
+
(`a trace is a single read`)。
|
|
36
|
+
- **`molbio_pcr_simulate`** 对 5' 克隆尾给出明确诊断(整条引物匹配、尾不退火),描述同步;克隆引物设计后
|
|
37
|
+
的"验证"不再显示成假的 `no product`。
|
|
38
|
+
- **`molbio_verify_sanger`**:trace 长于参考直接拒绝;比对窗小于参考全长时输出 **PARTIAL** 说明;等长时
|
|
39
|
+
提示改用 `molbio_align`(此前 1221/3162 bp 的局部窗口会报 `verdict: match`)。
|
|
40
|
+
- **`molbio_conservation`** 超 3000 bp 的错误信息指向 `molbio_align`。
|
|
41
|
+
- **`molbio_enzyme_lookup` 新增 `only_cutting`**。
|
|
42
|
+
- **`molbio_restriction_sites`**:`enzymes: ["common"]` 默认只列真正切开的酶(`only_cutting: false` 可看全表),
|
|
43
|
+
103 个酶的刷屏消失;`test/smoke.mjs` 的契约断言同步覆盖两种模式。
|
|
44
|
+
- **`molbio_clone_primers`** 渲染明确反向引物的"3' 结合段以订购方向给出",避免把模板互补序列当引物。
|
|
45
|
+
|
|
46
|
+
### 3. benchmark 与判分口径
|
|
47
|
+
|
|
48
|
+
- **`editing-outcome` 改用 `reads.fa` fixture**:高重复的 96-mer 不再内联在指令里(序列上移到
|
|
49
|
+
`benchmark/sequences.mjs` 单一来源),从结构上消除转录误差。
|
|
50
|
+
- **`taqman-assay` 不再钉死 #1 探针**:该探针只有 +0.44 °C 余量,与题面"probe 至少高出几度"自相矛盾;
|
|
51
|
+
模型改推一个真正达标的 assay 是正确行为。
|
|
52
|
+
- **`methylation-block` / `fastq-trim`** 的判分正则接受等价表述(`usable`、表格形式的 "Reads 4 → 3")。
|
|
53
|
+
- **`benchmark/profile.mjs` 修复**:`yaml.dump`/`schema` 未定义导致 profile 生成直接崩溃;`loaderYaml` 现在
|
|
54
|
+
同时提供 `dump`(js-yaml + Include 的 `entryListSchema`,能往返 `!!js`)。
|
|
55
|
+
|
|
56
|
+
### 4. 实测(单模型单日,样本不是保证)
|
|
57
|
+
|
|
58
|
+
- 全量 73 题:**工具调用 257 → 217(重复调用 67 → 35)**,12.50M → 11.66M token;
|
|
59
|
+
`genbank-parse` 14 次/93.9s → **3 次/14.4s**,`clone-primers` 6 → 3 次,`intron-qpcr` 71 → 19s,
|
|
60
|
+
`multiplex-panel` 23 → 6 次,`codon-optimize` 16 → 4 次,`editing-outcome` 83 → 34s。
|
|
61
|
+
- 保留一处真实模型失败:`restraint-simple-math`(10 µL × 50 mM / 500 µL 被模型算成 0.5 mM,正确是 1 mM)——
|
|
62
|
+
这是模型口算错误,不用提示词修饰。
|
|
63
|
+
|
|
64
|
+
### 5. 文档
|
|
65
|
+
|
|
66
|
+
- `docs/rules.md` 新增规则 10:提示面(段落 + 工具描述)是受测产物,有预算、覆盖与去重三条不变量。
|
|
67
|
+
- 根包 `0.28.0 → 0.28.1`;面板包保持 `0.1.17`。
|
|
68
|
+
|
|
69
|
+
---
|
|
13
70
|
## [0.28.0] — 2026-11-26(蛋白注释 + 格式互操作 + 测序判读:survey #13/#14/#21/#10/#27/#31)
|
|
14
71
|
|
|
15
72
|
**工具数 65 → 72,benchmark 66 → 73 题(72/72 覆盖)。** 这一版把三条候选线一次做完:蛋白注释、
|
package/benchmark/harness.mjs
CHANGED
|
@@ -124,13 +124,21 @@ export async function importPackage(name, harnessRoot) {
|
|
|
124
124
|
*/
|
|
125
125
|
export async function loaderYaml(harnessRoot) {
|
|
126
126
|
const include = await importPackage('@deepseek-ai/cordis-plugin-include', harnessRoot);
|
|
127
|
-
if (typeof include.parseEntryYaml === 'function') {
|
|
128
|
-
return { parse: include.parseEntryYaml, describe: 'yaml@2 (Include.parseEntryYaml)' };
|
|
129
|
-
}
|
|
130
127
|
const { entryListSchema } = include;
|
|
131
128
|
const yaml = (await importPackage('js-yaml', harnessRoot)).default;
|
|
129
|
+
// The dialect is js-yaml's JSON schema plus one tag: `!!js <expr>`, which
|
|
130
|
+
// round-trips as `{ __jsExpr }`. Reading without the tag turns an expression
|
|
131
|
+
// into a plain string; writing without it cannot put the tag back — and the
|
|
132
|
+
// profile patch carries `disabled: !!js ...` rows, so BOTH halves are needed.
|
|
133
|
+
const dump = entryListSchema === undefined
|
|
134
|
+
? () => { throw new Error('benchmark: this harness exposes no entryListSchema to serialize a profile patch with'); }
|
|
135
|
+
: (document) => yaml.dump(document, { schema: entryListSchema, noRefs: true, lineWidth: -1 });
|
|
136
|
+
if (typeof include.parseEntryYaml === 'function') {
|
|
137
|
+
return { parse: include.parseEntryYaml, dump, describe: 'yaml@2 (Include.parseEntryYaml)' };
|
|
138
|
+
}
|
|
132
139
|
return {
|
|
133
140
|
parse: (text) => yaml.load(text, { schema: entryListSchema }),
|
|
141
|
+
dump,
|
|
134
142
|
describe: 'js-yaml (Include.entryListSchema)',
|
|
135
143
|
};
|
|
136
144
|
}
|
package/benchmark/profile.mjs
CHANGED
|
@@ -166,7 +166,7 @@ function molbioRow(rows) {
|
|
|
166
166
|
* @returns {Promise<string>} the YAML text.
|
|
167
167
|
*/
|
|
168
168
|
export async function renderProfilePatch(options) {
|
|
169
|
-
const { parse } = await loaderYaml(options.harnessRoot);
|
|
169
|
+
const { parse, dump } = await loaderYaml(options.harnessRoot);
|
|
170
170
|
const document = await parse(await readFile(options.presetPath, 'utf8'));
|
|
171
171
|
const rows = presetPlugins(document);
|
|
172
172
|
if (rows.length === 0) {
|
|
@@ -189,7 +189,7 @@ export async function renderProfilePatch(options) {
|
|
|
189
189
|
'# tool execution and file mutation every task here requires.',
|
|
190
190
|
'',
|
|
191
191
|
].join('\n');
|
|
192
|
-
return `${header}${
|
|
192
|
+
return `${header}${dump(profilePatch(kept))}`;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
/** The profile directory for a harness home. */
|
package/benchmark/run.mjs
CHANGED
|
@@ -32,7 +32,7 @@ import { PROFILE_NAME } from './profile.mjs';
|
|
|
32
32
|
import { changedFiles, resolveChanged } from './changed.mjs';
|
|
33
33
|
import { foldEvents, loadTasks, renderInstruction, scoreSuiteOffline, scoreTrace, tasksForTier } from './score.mjs';
|
|
34
34
|
import { makeWorkspace } from './tools.mjs';
|
|
35
|
-
import { FIXTURES } from './sequences.mjs';
|
|
35
|
+
import { FIXTURES, v28EditReadsFasta } from './sequences.mjs';
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* The workspace files a task's tools read but no `fixtures` entry declares.
|
|
@@ -52,6 +52,8 @@ const FILE_FIXTURES = {
|
|
|
52
52
|
'chart-volcano': { 'de.csv': FIXTURES.DE_CSV },
|
|
53
53
|
'chart-heatmap': { 'expression.tsv': FIXTURES.HEATMAP_TSV },
|
|
54
54
|
'fastq-trim': { 'reads.fq': FIXTURES.TRIM_FASTQ_TEXT },
|
|
55
|
+
// Long, repeat-rich reads: inline them and the model retypes them (and drops a base).
|
|
56
|
+
'editing-outcome': { 'reads.fa': v28EditReadsFasta() },
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
/** Where reports land. Gitignored: a report is a measurement, not a source. */
|
package/benchmark/sequences.mjs
CHANGED
|
@@ -28,6 +28,22 @@ import { FIXTURES, reverseComplementOf } from './fixtures.mjs';
|
|
|
28
28
|
|
|
29
29
|
export { FIXTURES, reverseComplementOf };
|
|
30
30
|
|
|
31
|
+
/** The 96 bp reference of the v28 editing-outcome task. */
|
|
32
|
+
export const V28_EDIT_REF = 'ATG' + 'GCT'.repeat(30) + 'TAA';
|
|
33
|
+
|
|
34
|
+
/** Its four reads, derived from the reference so the ground truth cannot drift. */
|
|
35
|
+
export const V28_EDIT_READS = [
|
|
36
|
+
{ name: 'wt1', sequence: V28_EDIT_REF },
|
|
37
|
+
{ name: 'wt2', sequence: V28_EDIT_REF },
|
|
38
|
+
{ name: 'del', sequence: V28_EDIT_REF.slice(0, 3) + V28_EDIT_REF.slice(6) },
|
|
39
|
+
{ name: 'sub', sequence: V28_EDIT_REF.slice(0, 3) + 'A' + V28_EDIT_REF.slice(4) },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/** The same reads as the FASTA file the task's workspace carries. */
|
|
43
|
+
export function v28EditReadsFasta() {
|
|
44
|
+
return V28_EDIT_READS.map((read) => `>${read.name}\n${read.sequence}`).join('\n') + '\n';
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
/** Deterministic pseudo-random DNA (the generator `test/smoke.mjs` uses). */
|
|
32
48
|
export function makeTemplate(n, seed = 42) {
|
|
33
49
|
let s = seed;
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"where": "answer",
|
|
76
|
-
"pattern": "not .{0,
|
|
76
|
+
"pattern": "not .{0,45}(sensitive|affected|blocked|impaired)|unaffected|tolerat|does not (block|inhibit)|cuts? (fine|normally)|no (dam|methylation) (effect|impact)|not (dam|dam-)|usable",
|
|
77
77
|
"note": "the verdict on BamHI. Widened on purpose: the point is that the model reports BamHI as NOT methylation-blocked, however it phrases it. Before 0.16.0 the tool said the opposite and a model that cross-checked the supplier was penalised for being right; now the tool and the supplier agree, so the model's verdict is assertable."
|
|
78
78
|
}
|
|
79
79
|
]
|
|
@@ -66,11 +66,7 @@
|
|
|
66
66
|
"pattern": "[0-9]+ TaqMan assay candidate\\(s\\), best first",
|
|
67
67
|
"note": "the tool returned assay candidates. The count is NOT pinned: it depends on the Tm-margin and amplicon windows the model chooses, and every one of those choices is a legitimate reading of the request."
|
|
68
68
|
},
|
|
69
|
-
|
|
70
|
-
"where": "tool",
|
|
71
|
-
"pattern": "AGTTGAATGGGTAAGCCGGCA",
|
|
72
|
-
"note": "the probe the tool places in the top-ranked amplicon. The amplicon is not pinned either: a model that reads 'a few degrees above the primers' as a hard filter will reject #1 (its probe is BELOW the primers) and choose a later, genuinely qualifying assay — which is a better answer than the one this task first encoded."
|
|
73
|
-
},
|
|
69
|
+
|
|
74
70
|
{
|
|
75
71
|
"where": "tool",
|
|
76
72
|
"pattern": "vs the hotter primer",
|
|
@@ -258,7 +258,7 @@
|
|
|
258
258
|
"covers": [
|
|
259
259
|
"molbio_editing_outcome"
|
|
260
260
|
],
|
|
261
|
-
"instruction": "These four Sanger reads come from editing a 96 bp reference (ATG + 30×GCT + TAA). Cluster them into alleles, and give each frequency and protein effect inside the CDS 1-96. Treat the reference as linear
|
|
261
|
+
"instruction": "These four Sanger reads come from editing a 96 bp reference (ATG + 30×GCT + TAA). They are in the file `reads.fa` (FASTA) in your working directory — pass that file to the tool instead of retyping the sequences. Cluster them into alleles, and give each frequency and protein effect inside the CDS 1-96. Treat the reference as linear.\\n\\n\\n\\nThe reference is ATG + 30×GCT + TAA (96 bp).",
|
|
262
262
|
"timeout_ms": 300000,
|
|
263
263
|
"expect_tools": [
|
|
264
264
|
"molbio_editing_outcome"
|
|
@@ -24,7 +24,7 @@ import { join } from 'node:path';
|
|
|
24
24
|
import { readFileSync } from 'node:fs';
|
|
25
25
|
import { fileURLToPath } from 'node:url';
|
|
26
26
|
|
|
27
|
-
import { FIXTURES, NAMED_SEQUENCES, QPCR_TEMPLATE, makeTemplate, reverseComplementOf } from './sequences.mjs';
|
|
27
|
+
import { FIXTURES, V28_EDIT_READS, V28_EDIT_REF, NAMED_SEQUENCES, QPCR_TEMPLATE, makeTemplate, reverseComplementOf } from './sequences.mjs';
|
|
28
28
|
|
|
29
29
|
/** The committed GenBank fixture's text, read once at module scope. */
|
|
30
30
|
const GENBANK_TEXT = readFileSync(
|
|
@@ -43,13 +43,7 @@ const V28_ASSEMBLY_READS = [
|
|
|
43
43
|
{ name: 'r2', sequence: V28_ASSEMBLY_REF.slice(150, 370) },
|
|
44
44
|
{ name: 'r3', sequence: 'TCCATGTTCGGTATAAACATTGCTGGTCCCTACGTTATCATCAGCTCAAAGTCACCACCCAACTACGCTTTAAGGTAATGTCGCCTTGACAATTCAGTTCCAAACCACGGTTGTCCTCCA' },
|
|
45
45
|
];
|
|
46
|
-
|
|
47
|
-
const V28_EDIT_READS = [
|
|
48
|
-
{ name: 'wt1', sequence: V28_EDIT_REF },
|
|
49
|
-
{ name: 'wt2', sequence: V28_EDIT_REF },
|
|
50
|
-
{ name: 'del', sequence: V28_EDIT_REF.slice(0, 3) + V28_EDIT_REF.slice(6) },
|
|
51
|
-
{ name: 'sub', sequence: V28_EDIT_REF.slice(0, 3) + 'A' + V28_EDIT_REF.slice(4) },
|
|
52
|
-
];
|
|
46
|
+
|
|
53
47
|
/** The plasmid sequence, loaded once per offline run. */
|
|
54
48
|
let puc118;
|
|
55
49
|
|
package/docs/rules.md
CHANGED
|
@@ -217,3 +217,27 @@ ctx.effect(() => ctx.slots.inject(座位, () => ctx.slots.register({name: 座位
|
|
|
217
217
|
出处:0.1.6-alpha.1 的旧 drift 检查只比 id、对真故障只打印 note 并退出 0;
|
|
218
218
|
`contract.mjs` 曾把断言绑在 minifier 的空格上,放宽成"不绑格式"时如果没有自检,
|
|
219
219
|
下一次修改就会退化成"什么都不检查"。
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 10. 提示面是受测产物(预算 / 覆盖 / 去重)
|
|
223
|
+
|
|
224
|
+
`ctx.systemPrompt.section` 那一段,加上 72 条工具 `description`,随**每个请求**发送;
|
|
225
|
+
模型决定“调哪个工具”时读到的就是它们。它们和产物一样有预算、也会腐坏,所以由
|
|
226
|
+
`test/prompt.mjs` 看守五条不变量:
|
|
227
|
+
|
|
228
|
+
1. **预算**:段落 ≤ 6000 字符(0.28.0 实测 11,185,重排后 5,708);
|
|
229
|
+
2. **行宽**:单行 ≤ 400 字符(旧段落最长 1,408,禁令埋在千字符单行里没人读得到);
|
|
230
|
+
3. **无版本标记**:模型可见文本不写 `(v19)` / `(v0.28)`——版本史属于 CHANGELOG;
|
|
231
|
+
4. **覆盖**:每个已注册工具都必须在这段里被点名,反向也查:不许点名不存在的工具;
|
|
232
|
+
5. **去重**:段落与任一工具描述不得有 ≥60 字符逐字重合——一条规则只能有一个归属地。
|
|
233
|
+
|
|
234
|
+
分工是硬约定:**描述**说“这是什么 / 参数什么意思 / 用哪个模型”,**段落**说“什么时候用 /
|
|
235
|
+
跨工具纪律 / 共同约定”。想让模型照做,写进规则段并编号,别塞进描述句末。
|
|
236
|
+
|
|
237
|
+
按规则 9,`test/prompt.mjs` 自带五个突变实验:删一个工具名、塞一个 `(v19)`、抄一段描述、
|
|
238
|
+
拉长一行、撑爆预算——五种改动都必须被它抓红。
|
|
239
|
+
|
|
240
|
+
出处:0.28.0 的 editing-outcome 基准题跑出 10 次调用(5×`editing_outcome` + 2×`translate` +
|
|
241
|
+
1×`pwsh`),而该工具描述早已写着“不要用 translate / shell 重算”——1,067 字符单行末尾的禁令
|
|
242
|
+
没有生效;同一时期 `molbio_protein_charge`、`molbio_dotplot`、`molbio_alignment_postprocess`
|
|
243
|
+
三个工具从未在段落里出现。
|
package/index.mjs
CHANGED
|
@@ -661,7 +661,7 @@ const translateTool = define({
|
|
|
661
661
|
|
|
662
662
|
const restrictionTool = define({
|
|
663
663
|
name: 'molbio_restriction_sites',
|
|
664
|
-
description: 'Find restriction enzyme recognition sites in a sequence and compute the expected digestion fragments (linear or circular). Pass the enzyme names you care about, or ["common"] to scan every enzyme in the built-in table. Cut positions use the standard cut notation of each site (e.g. EcoRI G^AATTC).',
|
|
664
|
+
description: 'Find restriction enzyme recognition sites in a sequence and compute the expected digestion fragments (linear or circular). Pass the enzyme names you care about, or ["common"] to scan every enzyme in the built-in table. Cut positions use the standard cut notation of each site (e.g. EcoRI G^AATTC). With ["common"] only the enzymes that actually cut are listed — pass only_cutting: false for the full table, or name the enzymes you care about.',
|
|
665
665
|
parameters: {
|
|
666
666
|
type: 'object',
|
|
667
667
|
required: ['sequence', 'enzymes'],
|
|
@@ -669,6 +669,7 @@ const restrictionTool = define({
|
|
|
669
669
|
sequence: requiredString('DNA sequence to digest (IUPAC; ambiguous bases in the sequence are treated as no-match).'),
|
|
670
670
|
enzymes: { type: 'array', items: { type: 'string' }, description: 'Enzyme names, or ["common"] for all built-in enzymes.' },
|
|
671
671
|
circular: { type: 'boolean', description: 'True for circular DNA (plasmids): fragments wrap around the origin. Default false (linear).' },
|
|
672
|
+
only_cutting: { type: 'boolean', description: 'Report only enzymes that cut at least once. Defaults to true when `enzymes` is ["common"] (the whole table), which otherwise prints 100+ lines of "no sites"; pass false to see the full table.' },
|
|
672
673
|
},
|
|
673
674
|
},
|
|
674
675
|
outputSchema: {
|
|
@@ -677,6 +678,8 @@ const restrictionTool = define({
|
|
|
677
678
|
required: ['circular', 'enzymes'],
|
|
678
679
|
properties: {
|
|
679
680
|
circular: { type: 'boolean' },
|
|
681
|
+
only_cutting: { type: 'boolean' },
|
|
682
|
+
checked: { type: 'integer' },
|
|
680
683
|
enzymes: {
|
|
681
684
|
type: 'array',
|
|
682
685
|
items: {
|
|
@@ -717,16 +720,22 @@ const restrictionTool = define({
|
|
|
717
720
|
lines.push(` ${enzyme.fragments.length} fragment(s): ${enzyme.fragments.join(', ')} bp`);
|
|
718
721
|
}
|
|
719
722
|
}
|
|
723
|
+
if (value.only_cutting === true && value.checked !== undefined && value.checked > value.enzymes.length) {
|
|
724
|
+
lines.push(`note: showing only the ${value.enzymes.length} of ${value.checked} enzyme(s) that cut; pass only_cutting: false for the full table`);
|
|
725
|
+
}
|
|
720
726
|
return lines.join('\n');
|
|
721
727
|
},
|
|
722
728
|
execute(args) {
|
|
723
729
|
const seq = normalizeSequence(args.sequence);
|
|
724
730
|
let enzymes = args.enzymes;
|
|
725
731
|
if (!Array.isArray(enzymes) || enzymes.length === 0) throw new MolbioInputError('enzymes must be a non-empty array of enzyme names');
|
|
726
|
-
|
|
732
|
+
const expandAll = enzymes.length === 1 && enzymes[0] === 'common';
|
|
733
|
+
if (expandAll) enzymes = ENZYME_NAMES;
|
|
727
734
|
const circular = args.circular === true;
|
|
728
735
|
const results = digest(seq, enzymes, circular);
|
|
729
|
-
|
|
736
|
+
const onlyCutting = args.only_cutting ?? expandAll;
|
|
737
|
+
const kept = onlyCutting ? results.filter((entry) => entry.cut_positions.length > 0) : results;
|
|
738
|
+
return { circular, enzymes: kept, only_cutting: onlyCutting, checked: results.length };
|
|
730
739
|
},
|
|
731
740
|
});
|
|
732
741
|
|
|
@@ -771,6 +780,7 @@ const enzymeLookupTool = define({
|
|
|
771
780
|
enzymes: { type: 'array', items: { type: 'string' }, description: 'Enzyme names to look up; omit (or pass ["common"]) for the whole table, sorted.' },
|
|
772
781
|
sequence: { type: 'string', description: 'Optional sequence (IUPAC) to count cuts and compute fragment sizes on.' },
|
|
773
782
|
circular: { type: 'boolean', description: 'Treat the sequence as circular for the fragment math (default false).' },
|
|
783
|
+
only_cutting: { type: 'boolean', description: 'Report only enzymes that cut the given sequence at least once (default false). Use it when looking for alternatives — the full table prints 100+ enzymes.' },
|
|
774
784
|
},
|
|
775
785
|
},
|
|
776
786
|
outputSchema: {
|
|
@@ -803,10 +813,12 @@ const enzymeLookupTool = define({
|
|
|
803
813
|
: ENZYME_NAMES;
|
|
804
814
|
const sequence = args.sequence !== undefined && args.sequence !== '' ? normalizeSequence(args.sequence) : undefined;
|
|
805
815
|
const circular = args.circular === true;
|
|
816
|
+
let entries = names.map((name) => enzymeCatalog(name, sequence, circular));
|
|
817
|
+
if (args.only_cutting === true && sequence !== undefined) entries = entries.filter((entry) => (entry.cuts ?? 0) > 0);
|
|
806
818
|
return {
|
|
807
|
-
total:
|
|
819
|
+
total: entries.length,
|
|
808
820
|
...(sequence !== undefined ? { sequence_length: sequence.length, circular } : {}),
|
|
809
|
-
enzymes:
|
|
821
|
+
enzymes: entries,
|
|
810
822
|
};
|
|
811
823
|
},
|
|
812
824
|
});
|
|
@@ -1204,7 +1216,7 @@ const PRIMER_SCHEMA = {
|
|
|
1204
1216
|
|
|
1205
1217
|
const designPrimersTool = define({
|
|
1206
1218
|
name: 'molbio_design_primers',
|
|
1207
|
-
description: 'Design PCR primer pairs on a template
|
|
1219
|
+
description: 'Design PCR primer pairs on a template. Scans forward and reverse primers that satisfy Tm (SantaLucia 1998 NN; defaults 50 mM Na+, 1.5 mM Mg2+, 200 nM primer — adjustable via na_mm/mg_mm/dntp_mm/primer_nm), GC content, length, GC clamp, mononucleotide runs, end stability and Primer3-style structural constraints (self-complementarity local alignment, hairpin and primer-dimer Tm at 47 °C), then ranks the pairs inside the amplicon window; lower penalty is better. One call returns the ranked pairs with their Tm, GC and penalties, so a follow-up primer_tm or primer_check pass is not needed. max_mismatches > 0 also allows a few positional mismatches (never at the 3\'-terminal base); check_mispriming penalises primers whose 3\' tail anneals at extra template sites; target_position prefers pairs whose nearer 3\' end lands close to that position. When nothing is returned, the parameters you set are the filters — relax the tightest one and call again.',
|
|
1208
1220
|
parameters: {
|
|
1209
1221
|
type: 'object',
|
|
1210
1222
|
required: ['template'],
|
|
@@ -1422,7 +1434,7 @@ const CONDITIONS_SCHEMA = {
|
|
|
1422
1434
|
const taqmanTool = (ctx) => define({
|
|
1423
1435
|
safe: (args) => args.save_path === undefined || args.save_path === '',
|
|
1424
1436
|
name: 'molbio_design_taqman',
|
|
1425
|
-
description: 'Design a TaqMan (5\'-nuclease, hydrolysis probe) assay: it runs the standard primer-pair designer first (qPCR-sized amplicons, 70-200 bp by default), then places a probe inside the amplicon between the primers and applies the probe rules — no 5\' terminal G (it quenches the reporter), probe Tm at least min_tm_delta °C above the hotter primer, no mononucleotide run or repeat, bounded self-complementarity, and a check that the probe does not dimerize with either primer. Each assay reports the primer pair, the probe (sequence to order, position, orientation, Tm margin) and a transparent ranking penalty. Probe and primer Tm are the same SantaLucia-1998 nearest-neighbour estimates the other molbio tools use; they are design heuristics, not an efficiency prediction.',
|
|
1437
|
+
description: 'Design a TaqMan (5\'-nuclease, hydrolysis probe) assay: it runs the standard primer-pair designer first (qPCR-sized amplicons, 70-200 bp by default), then places a probe inside the amplicon between the primers and applies the probe rules — no 5\' terminal G (it quenches the reporter), probe Tm at least min_tm_delta °C above the hotter primer, no mononucleotide run or repeat, bounded self-complementarity, and a check that the probe does not dimerize with either primer. Each assay reports the primer pair, the probe (sequence to order, position, orientation, Tm margin) and a transparent ranking penalty. Probe and primer Tm are the same SantaLucia-1998 nearest-neighbour estimates the other molbio tools use; they are design heuristics, not an efficiency prediction. The probe-Tm margin RANKS candidate amplicons and is reported with each one: when the top assay\'s margin falls short of min_tm_delta the result says so — pass that note on instead of re-ranking or tightening the Tm window, unless the user explicitly asks for a stricter margin.',
|
|
1426
1438
|
parameters: {
|
|
1427
1439
|
type: 'object',
|
|
1428
1440
|
required: ['sequence'],
|
|
@@ -1636,7 +1648,7 @@ const MULTIPLEX_PRIMER_IN_SCHEMA = {
|
|
|
1636
1648
|
|
|
1637
1649
|
const multiplexTool = define({
|
|
1638
1650
|
name: 'molbio_multiplex_check',
|
|
1639
|
-
description: 'Check whether several
|
|
1651
|
+
description: 'Check whether several primer pairs can share one multiplex tube — one call answers the whole panel: every primer-primer interaction with the most stable (any) and 3\'-anchored duplex Tm (flagged above dimer_tm_threshold), unintended 3\'-tail annealing in the primer\'s own template and in the other targets\' templates, amplicon sizes too close to resolve on a gel, plus concrete redesign advice. Design the pairs first (molbio_design_primers) and pass them all in `targets`; do not pre-screen the panel pair-by-pair with align, primer_tm, primer_check or pcr_simulate — that recomputes what this call reports. Every Tm comes from the primer designer\'s NN model and is a risk estimate, not a prediction of the multiplex result.',
|
|
1640
1652
|
parameters: {
|
|
1641
1653
|
type: 'object',
|
|
1642
1654
|
required: ['targets'],
|
|
@@ -2109,14 +2121,15 @@ function multiPartNote(features) {
|
|
|
2109
2121
|
: `note: ${count} feature(s) have a multi-part location (join/order, or several segments); start-end is their OUTER bound and includes the gaps — read "location" for the parts.`;
|
|
2110
2122
|
}
|
|
2111
2123
|
|
|
2112
|
-
const parseGenbankTool = define({
|
|
2124
|
+
const parseGenbankTool = (ctx) => define({
|
|
2113
2125
|
name: 'molbio_parse_genbank',
|
|
2114
2126
|
description: 'Parse a GenBank flatfile record into structured data: locus name, accession, definition, topology (circular/linear), features (type, 1-based span, strand, label from /product or /gene), and the origin sequence. A feature whose location has several parts (join/order) comes back with `multi_part: true` and its original location string: `start`/`end` are then only the OUTER bounds and include the gaps, so read `location` before calling it a length. Feed the returned features to molbio_plasmid_map to draw the map.',
|
|
2115
2127
|
parameters: {
|
|
2116
2128
|
type: 'object',
|
|
2117
|
-
required: [
|
|
2129
|
+
required: [],
|
|
2118
2130
|
properties: {
|
|
2119
|
-
genbank:
|
|
2131
|
+
genbank: { type: 'string', description: 'Complete GenBank record text (LOCUS ... //).' },
|
|
2132
|
+
path: { type: 'string', description: 'Workspace path to a .gb/.gbk file; alternative to `genbank`. Prefer this for a file: retyping a record can corrupt the sequence (a dropped base changes the ORIGIN length, and a lost complement() flips a strand).' },
|
|
2120
2133
|
},
|
|
2121
2134
|
},
|
|
2122
2135
|
outputSchema: {
|
|
@@ -2168,8 +2181,12 @@ const parseGenbankTool = define({
|
|
|
2168
2181
|
if (value.length_declared !== undefined) lines.push(`note: the LOCUS line declares ${value.length_declared} bp but ORIGIN holds ${value.length} bp; the sequence is what the tools use.`);
|
|
2169
2182
|
return lines.join('\n');
|
|
2170
2183
|
},
|
|
2171
|
-
execute(args) {
|
|
2172
|
-
|
|
2184
|
+
async execute(args, exec) {
|
|
2185
|
+
const hasText = args.genbank !== undefined && args.genbank !== '';
|
|
2186
|
+
const hasPath = args.path !== undefined && args.path !== '';
|
|
2187
|
+
if (hasText === hasPath) throw new MolbioInputError('provide exactly one of genbank (the record text) or path (a .gb/.gbk file in the workspace)');
|
|
2188
|
+
const text = hasPath ? new TextDecoder().decode(await readFileBytes(ctx, exec, args.path)) : args.genbank;
|
|
2189
|
+
return parseGenBank(text);
|
|
2173
2190
|
},
|
|
2174
2191
|
});
|
|
2175
2192
|
|
|
@@ -2217,7 +2234,7 @@ async function autoViewWritten(args, file) {
|
|
|
2217
2234
|
const plasmidMapTool = (ctx) => define({
|
|
2218
2235
|
safe: false,
|
|
2219
2236
|
name: 'molbio_plasmid_map',
|
|
2220
|
-
description: 'Render a plasmid map (circular by default, or linear) from a sequence plus features (from molbio_parse_genbank / molbio_parse_snapgene or hand-written) and WRITE it as a standalone SVG file in the session workspace. The tool writes the file itself
|
|
2237
|
+
description: 'Render a plasmid map (circular by default, or linear) from a sequence plus features (from molbio_parse_genbank / molbio_parse_snapgene or hand-written) and WRITE it as a standalone SVG file in the session workspace. The tool writes the file itself and returns its path. When the user asks about the plasmid itself, relay the topology, feature count and cut-mark count the result states.',
|
|
2221
2238
|
parameters: {
|
|
2222
2239
|
type: 'object',
|
|
2223
2240
|
required: ['sequence'],
|
|
@@ -2422,7 +2439,7 @@ const parseSnapgeneTool = (ctx) => define({
|
|
|
2422
2439
|
const plasmidMapFileTool = (ctx) => define({
|
|
2423
2440
|
safe: false,
|
|
2424
2441
|
name: 'molbio_plasmid_map_file',
|
|
2425
|
-
description: 'Read a plasmid file (.dna SnapGene, or .gb/.gbk GenBank) from disk and render its map, WRITING it as a standalone SVG file in the session workspace in one call. Features come from the file\'s annotations; optionally mark restriction enzyme cut sites. The tool writes the file itself
|
|
2442
|
+
description: 'Read a plasmid file (.dna SnapGene, or .gb/.gbk GenBank) from disk and render its map, WRITING it as a standalone SVG file in the session workspace in one call. Features come from the file\'s annotations; optionally mark restriction enzyme cut sites. The tool writes the file itself and returns its path. When the user asks about the plasmid itself, relay the topology, feature count and cut-mark count the result states.',
|
|
2426
2443
|
parameters: {
|
|
2427
2444
|
type: 'object',
|
|
2428
2445
|
required: ['path'],
|
|
@@ -2645,7 +2662,7 @@ const INTRON_PRIMER_SCHEMA = {
|
|
|
2645
2662
|
|
|
2646
2663
|
const intronPrimersTool = (ctx) => define({
|
|
2647
2664
|
name: 'molbio_design_intron_primers',
|
|
2648
|
-
description: 'Design qPCR primer pairs where ONE primer spans an exon-exon junction (>= min_junction_bases on each side) so genomic DNA cannot be amplified. In the returned pair the junction is carried by the REVERSE primer (the assay sits 5\' of the junction): the forward primer is upstream inside a single exon, and the reverse sequence is the molecule to order (the reverse complement of its spliced site), so F is upstream of R and the pair amplifies as printed. Provide the genomic sequence and the exon spans (1-based, inclusive). min_genomic_span enforces a minimal genomic distance between the primers (making gDNA amplification impossible or easily detectable). Coordinates come back both on the spliced transcript and on the genomic sequence. v12: Primer3-style structural filters (self-complementarity alignment scores, hairpin/dimer folding Tm at 47 °C defaults, end stability/end GC, GC clamp levels); pass max_mismatches > 0 to allow mismatched primers (never on the 3\'-terminal base) with spliced+genomic mismatch reports; pass check_mispriming: true to reject/penalize non-specific 3\'-tail annealing on the transcript.',
|
|
2665
|
+
description: 'Design qPCR primer pairs where ONE primer spans an exon-exon junction (>= min_junction_bases on each side) so genomic DNA cannot be amplified. In the returned pair the junction is carried by the REVERSE primer (the assay sits 5\' of the junction): the forward primer is upstream inside a single exon, and the reverse sequence is the molecule to order (the reverse complement of its spliced site), so F is upstream of R and the pair amplifies as printed. Provide the genomic sequence and the exon spans (1-based, inclusive). min_genomic_span enforces a minimal genomic distance between the primers (making gDNA amplification impossible or easily detectable). Coordinates come back both on the spliced transcript and on the genomic sequence. v12: Primer3-style structural filters (self-complementarity alignment scores, hairpin/dimer folding Tm at 47 °C defaults, end stability/end GC, GC clamp levels); pass max_mismatches > 0 to allow mismatched primers (never on the 3\'-terminal base) with spliced+genomic mismatch reports; pass check_mispriming: true to reject/penalize non-specific 3\'-tail annealing on the transcript. The design, the structural filters and the optional mismatch/mispriming screens all run inside this one call; primer_check and pcr_simulate afterwards only recompute the same pair.',
|
|
2649
2666
|
parameters: {
|
|
2650
2667
|
type: 'object',
|
|
2651
2668
|
required: ['exons'],
|
|
@@ -3001,7 +3018,7 @@ const uniqueCuttersTool = (ctx) => define({
|
|
|
3001
3018
|
const cloneSimulateTool = (ctx) => define({
|
|
3002
3019
|
safe: (args) => args.save_path === undefined && args.map_path === undefined,
|
|
3003
3020
|
name: 'molbio_clone_simulate',
|
|
3004
|
-
description: 'Simulate a cloning reaction in silico and return the final plasmid sequence with its remapped features. method=restriction: the tool itself checks that each enzyme cuts the vector exactly once (do not pre-verify by thinking), digests the insert with the same enzymes, ligates, remaps feature coordinates, and predicts verification digests; add_flanks: true lets the tool add the enzyme sites to a bare insert; orientation=auto (default) reverse-complements an inverted insert automatically. method=gibson: replace the vector region (region_start..region_end) with the insert and report the insert-to-order with homology arms. Save the final plasmid with save_path (FASTA) and/or draw the new plasmid map directly with map_path (SVG),
|
|
3021
|
+
description: 'Simulate a cloning reaction in silico and return the final plasmid sequence with its remapped features. method=restriction: the tool itself checks that each enzyme cuts the vector exactly once (do not pre-verify by thinking), digests the insert with the same enzymes, ligates, remaps feature coordinates, and predicts verification digests; add_flanks: true lets the tool add the enzyme sites to a bare insert; orientation=auto (default) reverse-complements an inverted insert automatically. method=gibson: replace the vector region (region_start..region_end) with the insert and report the insert-to-order with homology arms. Save the final plasmid with save_path (FASTA) and/or draw the new plasmid map directly with map_path (SVG), .',
|
|
3005
3022
|
parameters: {
|
|
3006
3023
|
type: 'object',
|
|
3007
3024
|
required: ['insert'],
|
|
@@ -3192,7 +3209,7 @@ const GG_FRAGMENT_SCHEMA = {
|
|
|
3192
3209
|
const goldenGateTool = (ctx) => define({
|
|
3193
3210
|
safe: false,
|
|
3194
3211
|
name: 'molbio_golden_gate',
|
|
3195
|
-
description: 'Simulate a Golden Gate assembly (type IIS enzyme, e.g. BsaI) in silico. Pass the vector (with its own inward BsaI-style cassette, or BARE with replace_region so the tool adds the cassette and designs both vector junctions) and the BARE fragment sequences in assembly order: the tool designs unique, non-palindromic, non-complementary 4 bp junctions, checks that the enzyme never cuts inside a fragment or the bare vector, builds the fragments-to-order with recognition sites and filler bases, assembles the final plasmid (no recognition site appears at any junction; the vector cassette sites stay in the backbone, as in standard destination vectors), remaps feature coordinates, and predicts verification digests. Save the final plasmid with save_path (FASTA) and/or draw the map with map_path (SVG),
|
|
3212
|
+
description: 'Simulate a Golden Gate assembly (type IIS enzyme, e.g. BsaI) in silico. Pass the vector (with its own inward BsaI-style cassette, or BARE with replace_region so the tool adds the cassette and designs both vector junctions) and the BARE fragment sequences in assembly order: the tool designs unique, non-palindromic, non-complementary 4 bp junctions, checks that the enzyme never cuts inside a fragment or the bare vector, builds the fragments-to-order with recognition sites and filler bases, assembles the final plasmid (no recognition site appears at any junction; the vector cassette sites stay in the backbone, as in standard destination vectors), remaps feature coordinates, and predicts verification digests. Save the final plasmid with save_path (FASTA) and/or draw the map with map_path (SVG), .',
|
|
3196
3213
|
parameters: {
|
|
3197
3214
|
type: 'object',
|
|
3198
3215
|
required: ['inserts'],
|
|
@@ -3340,7 +3357,7 @@ const goldenGateTool = (ctx) => define({
|
|
|
3340
3357
|
|
|
3341
3358
|
const clonePrimersTool = (ctx) => define({
|
|
3342
3359
|
name: 'molbio_clone_primers',
|
|
3343
|
-
description: 'Design primers that amplify a template with cloning tails. mode=restriction: adds 5\' protection bases and restriction site(s) (1 or 2 enzymes) to the primer ends and re-checks Tm/GC/dimers; warns when an enzyme also cuts inside the template. mode=gibson: adds the vector homology arms flanking the replaced region to the primer ends.',
|
|
3360
|
+
description: 'Design primers that amplify a template with cloning tails. mode=restriction: adds 5\' protection bases and restriction site(s) (1 or 2 enzymes) to the primer ends and re-checks Tm/GC/dimers; warns when an enzyme also cuts inside the template. mode=gibson: adds the vector homology arms flanking the replaced region to the primer ends. The render gives the reverse primer\'s 3\' binding part AS ORDERED — pass that string, not its reverse complement, when you verify the pair with molbio_pcr_simulate.',
|
|
3344
3361
|
parameters: {
|
|
3345
3362
|
type: 'object',
|
|
3346
3363
|
required: ['template'],
|
|
@@ -3392,7 +3409,7 @@ const clonePrimersTool = (ctx) => define({
|
|
|
3392
3409
|
const lines = [
|
|
3393
3410
|
`cloning primers (${value.mode}):`,
|
|
3394
3411
|
` forward: ${value.forward} (binding ${value.forward_binding})`,
|
|
3395
|
-
` reverse: ${value.reverse} (binding ${value.reverse_binding})`,
|
|
3412
|
+
` reverse: ${value.reverse} (3' binding part as ordered ${reverseComplement(value.reverse_binding)}; template site ${value.reverse_binding})`,
|
|
3396
3413
|
`Tm: forward ${c.forward_tm} °C / reverse ${c.reverse_tm} °C (binding parts: ${c.binding_tm_forward} / ${c.binding_tm_reverse} °C)`,
|
|
3397
3414
|
`GC: ${c.gc_forward}% / ${c.gc_reverse}% · dimer score ${c.dimer_score} · self scores ${c.forward_self_score}/${c.reverse_self_score}`,
|
|
3398
3415
|
];
|
|
@@ -3423,7 +3440,7 @@ const clonePrimersTool = (ctx) => define({
|
|
|
3423
3440
|
|
|
3424
3441
|
const mutagenesisTool = define({
|
|
3425
3442
|
name: 'molbio_mutagenesis_primers',
|
|
3426
|
-
description: 'Design QuickChange-style site-directed mutagenesis primer pairs. Mutations
|
|
3443
|
+
description: 'Design QuickChange-style site-directed mutagenesis primer pairs. Mutations use the original template coordinates: substitutions "A123G" or "123A>G", deletions "123_125del", insertions "after123insGCT". Pass ALL mutations of the experiment in one `mutations` call: it returns one pair per mutation with Tm (NN estimate), GC, G/C ends, runs and self-complementarity, plus the amino-acid change from the template read in frame 1, so neither a per-mutation re-run nor a separate translate call is needed. The mutation position and the amino-acid change come back in the same result, so do not rebuild or translate the mutant to confirm them; if the result says no pair satisfied the constraints, widen primer_len_min/max or tm_min/max once and retry.',
|
|
3427
3444
|
parameters: {
|
|
3428
3445
|
type: 'object',
|
|
3429
3446
|
required: ['template', 'mutations'],
|
|
@@ -3511,7 +3528,7 @@ const mutagenesisTool = define({
|
|
|
3511
3528
|
|
|
3512
3529
|
const verifySangerTool = (ctx) => define({
|
|
3513
3530
|
name: 'molbio_verify_sanger',
|
|
3514
|
-
description: 'Verify a clone by Sanger sequencing: read a trace file (.ab1 with quality values, or .seq/.txt/.fasta plain text), align it against a reference (sequence or .dna/.gb plasmid file, circular-aware), and report mismatches, deletions, insertions, coverage, identity, and amino-acid consequences inside a CDS window. Low-quality (<20) positions are flagged and excluded from a "differences found" verdict.',
|
|
3531
|
+
description: 'Verify a clone by Sanger sequencing: read a trace file (.ab1 with quality values, or .seq/.txt/.fasta plain text), align it against a reference (sequence or .dna/.gb plasmid file, circular-aware), and report mismatches, deletions, insertions, coverage, identity, and amino-acid consequences inside a CDS window. Low-quality (<20) positions are flagged and excluded from a "differences found" verdict. The trace must be a sequencing read: an input as long as the reference is refused, because a partial alignment window is not a whole-molecule comparison (use molbio_align for that).',
|
|
3515
3532
|
parameters: {
|
|
3516
3533
|
type: 'object',
|
|
3517
3534
|
required: ['trace_path'],
|
|
@@ -3584,6 +3601,12 @@ const verifySangerTool = (ctx) => define({
|
|
|
3584
3601
|
const lines = [
|
|
3585
3602
|
`verdict: ${value.verdict}`,
|
|
3586
3603
|
`aligned ${value.aligned_span.start}-${value.aligned_span.end} of ${value.reference_length} bp reference; identity ${value.identity_percent}%`,
|
|
3604
|
+
...value.aligned_span.end - value.aligned_span.start + 1 < value.reference_length
|
|
3605
|
+
? [`note: the aligned window is ${value.aligned_span.end - value.aligned_span.start + 1} of ${value.reference_length} bp — a PARTIAL window, not a whole-molecule comparison`]
|
|
3606
|
+
: [],
|
|
3607
|
+
...value.trace_length === value.reference_length
|
|
3608
|
+
? ['note: the trace is as long as the reference — if this is a whole molecule rather than a read, use molbio_align']
|
|
3609
|
+
: [],
|
|
3587
3610
|
];
|
|
3588
3611
|
if (value.quality_mean !== undefined) lines.push(`mean trace quality: ${value.quality_mean}`);
|
|
3589
3612
|
const confident = value.differences.filter((d) => !(d.quality !== undefined && d.quality < 20));
|
|
@@ -3617,6 +3640,9 @@ const verifySangerTool = (ctx) => define({
|
|
|
3617
3640
|
} else {
|
|
3618
3641
|
throw new MolbioInputError('provide either `reference` (a sequence) or `reference_path` (a .dna/.gb/.fa file)');
|
|
3619
3642
|
}
|
|
3643
|
+
if (trace.bases.length > reference.length) {
|
|
3644
|
+
throw new MolbioInputError(`the trace is ${trace.bases.length} bp, longer than the ${reference.length} bp reference — a read cannot exceed its reference; use molbio_align for a two-sequence comparison`);
|
|
3645
|
+
}
|
|
3620
3646
|
return verifySanger({
|
|
3621
3647
|
traceBases: trace.bases,
|
|
3622
3648
|
traceQualities: trace.qualities,
|
|
@@ -3869,7 +3895,7 @@ const peptideDigestTool = define({
|
|
|
3869
3895
|
|
|
3870
3896
|
const codonOptimizeTool = define({
|
|
3871
3897
|
name: 'molbio_codon_optimize',
|
|
3872
|
-
description: 'Codon-optimize a protein sequence for a host (E. coli, yeast, or human) using published high-frequency codon tables (heuristic). Optionally avoid introducing restriction sites (avoid_enzymes): synonymous swaps remove them where possible, deterministically.',
|
|
3898
|
+
description: 'Codon-optimize a protein sequence for a host (E. coli, yeast, or human) using published high-frequency codon tables (heuristic). Optionally avoid introducing restriction sites (avoid_enzymes): synonymous swaps remove them where possible, deterministically. The result already carries the optimised CDS with its GC, restriction-site screen and translation check, so re-verifying it with translate, gc_content or restriction_sites adds nothing.',
|
|
3873
3899
|
parameters: {
|
|
3874
3900
|
type: 'object',
|
|
3875
3901
|
required: ['sequence'],
|
|
@@ -3933,7 +3959,7 @@ const helicalWheelTool = (ctx) => define({
|
|
|
3933
3959
|
// never concurrency-safe; the old predicate marked the common case safe.
|
|
3934
3960
|
safe: false,
|
|
3935
3961
|
name: 'molbio_helical_wheel',
|
|
3936
|
-
description: 'Draw the helical wheel (Schiffer-Edmundson projection) of a peptide or protein stretch and analyse it: residues are placed 100° apart on the circle (3.6 residues per turn of an ideal alpha-helix), coloured by residue class (hydrophobic/polar/acidic/basic), with the Eisenberg hydrophobic moment μH of the stretch and the maximum μH over every window of moment_window residues (11 by default). An amphipathic helix shows one hydrophobic face and one polar face. The tool
|
|
3962
|
+
description: 'Draw the helical wheel (Schiffer-Edmundson projection) of a peptide or protein stretch and analyse it: residues are placed 100° apart on the circle (3.6 residues per turn of an ideal alpha-helix), coloured by residue class (hydrophobic/polar/acidic/basic), with the Eisenberg hydrophobic moment μH of the stretch and the maximum μH over every window of moment_window residues (11 by default). An amphipathic helix shows one hydrophobic face and one polar face. The tool writes the SVG file itself (auto_view, default true); all values are sequence-propensity estimates from published scales, not a structure prediction.',
|
|
3937
3963
|
parameters: {
|
|
3938
3964
|
type: 'object',
|
|
3939
3965
|
required: ['sequence'],
|
|
@@ -4053,7 +4079,7 @@ const hydropathyTool = (ctx) => define({
|
|
|
4053
4079
|
// Always writes the SVG; see the helical-wheel note.
|
|
4054
4080
|
safe: false,
|
|
4055
4081
|
name: 'molbio_hydropathy_plot',
|
|
4056
|
-
description: 'Plot the Kyte-Doolittle hydropathy profile of a protein: a sliding-window average (window, default 9; use 19-21 for transmembrane spans), the GRAVY value, and every peak whose window average reaches the threshold (default 1.6, the classic membrane-spanning cutoff). The tool
|
|
4082
|
+
description: 'Plot the Kyte-Doolittle hydropathy profile of a protein: a sliding-window average (window, default 9; use 19-21 for transmembrane spans), the GRAVY value, and every peak whose window average reaches the threshold (default 1.6, the classic membrane-spanning cutoff). The tool writes the SVG file itself (auto_view, default true); the per-residue profile is also returned so it can feed further analysis. Values are the Kyte-Doolittle propensity scale, not a topology prediction.',
|
|
4057
4083
|
parameters: {
|
|
4058
4084
|
type: 'object',
|
|
4059
4085
|
required: ['sequence'],
|
|
@@ -4114,7 +4140,7 @@ const hydropathyTool = (ctx) => define({
|
|
|
4114
4140
|
const qpcrEfficiencyTool = (ctx) => define({
|
|
4115
4141
|
safe: (args) => args.plot_path === undefined || args.plot_path === '',
|
|
4116
4142
|
name: 'molbio_qpcr_efficiency',
|
|
4117
|
-
description: 'Fit a qPCR standard curve from a dilution series: dilution_factors (e.g. [1, 10, 100, 1000]) with the matching ct_values. Fits Ct vs log10(relative quantity), reports slope, intercept, R², and amplification efficiency E = 10^(−1/slope) − 1. Pass plot_path to write the scatter + fit line as an SVG file in the workspace
|
|
4143
|
+
description: 'Fit a qPCR standard curve from a dilution series: dilution_factors (e.g. [1, 10, 100, 1000]) with the matching ct_values. Fits Ct vs log10(relative quantity), reports slope, intercept, R², and amplification efficiency E = 10^(−1/slope) − 1. Pass plot_path to write the scatter + fit line as an SVG file in the workspace.',
|
|
4118
4144
|
parameters: {
|
|
4119
4145
|
type: 'object',
|
|
4120
4146
|
required: ['dilution_factors', 'ct_values'],
|
|
@@ -4609,7 +4635,7 @@ const plotTool = (ctx) => define({
|
|
|
4609
4635
|
const virtualGelTool = (ctx) => define({
|
|
4610
4636
|
safe: false,
|
|
4611
4637
|
name: 'molbio_virtual_gel',
|
|
4612
|
-
description: 'Render a virtual agarose gel as an SVG file in the workspace. Each lane lists the EXPECTED DNA fragment sizes in bp (e.g. a restriction digest, a PCR, or a ligation check) and the tool draws the band pattern with a size ladder so the expected picture can be compared against a real gel. The tool writes the file itself
|
|
4638
|
+
description: 'Render a virtual agarose gel as an SVG file in the workspace. Each lane lists the EXPECTED DNA fragment sizes in bp (e.g. a restriction digest, a PCR, or a ligation check) and the tool draws the band pattern with a size ladder so the expected picture can be compared against a real gel. The tool writes the SVG file itself.',
|
|
4613
4639
|
parameters: {
|
|
4614
4640
|
type: 'object',
|
|
4615
4641
|
required: ['lanes'],
|
|
@@ -4679,15 +4705,17 @@ const virtualGelTool = (ctx) => define({
|
|
|
4679
4705
|
},
|
|
4680
4706
|
});
|
|
4681
4707
|
|
|
4682
|
-
const alignTool = define({
|
|
4708
|
+
const alignTool = (ctx) => define({
|
|
4683
4709
|
name: 'molbio_align',
|
|
4684
|
-
description: 'Locally align two sequences (Smith-Waterman). Returns the aligned strings, the aligned span, identity %, and a list of mismatches/gaps. NOTE the span fields: a_start/b_start are 0-BASED offsets and a_end/b_end are 0-based EXCLUSIVE ends — the 1-based inclusive span is a_start+1..a_end, which is what the rendered text prints. The pairwise matrix is capped at 50,000,000 cells (sequence1 x sequence2, roughly 7,000 x 7,000 bases); a larger pair is refused with an error rather than exhausting host memory, so align a window or use molbio_verify_sanger, which anchors a read to a reference. Use it to compare two sequences, check a primer against a template, or verify an edited region.',
|
|
4710
|
+
description: 'Locally align two sequences (Smith-Waterman). Returns the aligned strings, the aligned span, identity %, and a list of mismatches/gaps. NOTE the span fields: a_start/b_start are 0-BASED offsets and a_end/b_end are 0-based EXCLUSIVE ends — the 1-based inclusive span is a_start+1..a_end, which is what the rendered text prints. The pairwise matrix is capped at 50,000,000 cells (sequence1 x sequence2, roughly 7,000 x 7,000 bases); a larger pair is refused with an error rather than exhausting host memory, so align a window or use molbio_verify_sanger, which anchors a read to a reference. Use it to compare two sequences, check a primer against a template, or verify an edited region. Either side may instead be a workspace file (path1/path2), which makes this the pairwise comparison for two long sequences where the MSA has a 3000 bp cap.',
|
|
4685
4711
|
parameters: {
|
|
4686
4712
|
type: 'object',
|
|
4687
|
-
required: [
|
|
4713
|
+
required: [],
|
|
4688
4714
|
properties: {
|
|
4689
|
-
sequence1:
|
|
4690
|
-
|
|
4715
|
+
sequence1: { type: 'string', description: 'First sequence (typically the query/read).' },
|
|
4716
|
+
path1: { type: 'string', description: 'Workspace file holding sequence1 (FASTA or plain text); alternative to `sequence1`.' },
|
|
4717
|
+
sequence2: { type: 'string', description: 'Second sequence (typically the reference).' },
|
|
4718
|
+
path2: { type: 'string', description: 'Workspace file holding sequence2; alternative to `sequence2`.' },
|
|
4691
4719
|
},
|
|
4692
4720
|
},
|
|
4693
4721
|
outputSchema: {
|
|
@@ -4740,9 +4768,20 @@ const alignTool = define({
|
|
|
4740
4768
|
}
|
|
4741
4769
|
return lines.join('\n');
|
|
4742
4770
|
},
|
|
4743
|
-
execute(args) {
|
|
4744
|
-
const
|
|
4745
|
-
|
|
4771
|
+
async execute(args, exec) {
|
|
4772
|
+
const readSide = async (sequence, path, label, pathLabel) => {
|
|
4773
|
+
const hasSequence = sequence !== undefined && sequence !== '';
|
|
4774
|
+
const hasPath = path !== undefined && path !== '';
|
|
4775
|
+
if (hasSequence === hasPath) throw new MolbioInputError(`provide exactly one of ${label} (a sequence) or ${pathLabel} (a workspace file)`);
|
|
4776
|
+
if (hasSequence) return sequence;
|
|
4777
|
+
const bytes = await readFileBytes(ctx, exec, path);
|
|
4778
|
+
if (String(path).toLowerCase().endsWith('.dna')) return parseSnapGeneBytes(bytes).sequence;
|
|
4779
|
+
const text = new TextDecoder().decode(bytes).replace(/^\uFEFF/, '');
|
|
4780
|
+
if (/^LOCUS\s/.test(text.trimStart())) return parseGenBank(text).sequence;
|
|
4781
|
+
return text.trimStart().startsWith('>') ? parseFasta(text)[0].sequence : text;
|
|
4782
|
+
};
|
|
4783
|
+
const a = normalizeSequence(await readSide(args.sequence1, args.path1, 'sequence1', 'path1'), 'sequence1');
|
|
4784
|
+
const b = normalizeSequence(await readSide(args.sequence2, args.path2, 'sequence2', 'path2'), 'sequence2');
|
|
4746
4785
|
const result = smithWaterman(a, b);
|
|
4747
4786
|
const differences = result.differences.map((d) => ({
|
|
4748
4787
|
kind: d.kind,
|
|
@@ -4892,7 +4931,7 @@ const msaAlignTool = (ctx) => define({
|
|
|
4892
4931
|
const conservationTool = (ctx) => define({
|
|
4893
4932
|
safe: true,
|
|
4894
4933
|
name: 'molbio_conservation',
|
|
4895
|
-
description: 'Conservation analysis of a set of IUPAC DNA sequences: consensus sequence, per-column identity (fraction of residues matching the top residue), entropy-based conservation score, conserved/variable columns, and pairwise identity statistics. Provide exactly one of `alignment` (pre-aligned equal-length
|
|
4934
|
+
description: 'Conservation analysis of a set of IUPAC DNA sequences: consensus sequence, per-column identity (fraction of residues matching the top residue), entropy-based conservation score, conserved/variable columns, and pairwise identity statistics. Provide exactly one of `alignment` (pre-aligned equal-length rows), `sequences` (unaligned) or `fasta_path`. `threshold` (default 0.8) is the column identity at or above which a column counts as conserved; columns below it are listed in variable_positions (capped at 200, see variable_positions_truncated). All-gap columns count as conserved; per_column details are returned for alignments up to 300 columns. Deterministic; all scores are heuristic estimates. Each sequence is capped at 3000 bases; for a two-sequence comparison above that, use molbio_align instead.',
|
|
4896
4935
|
parameters: {
|
|
4897
4936
|
type: 'object',
|
|
4898
4937
|
properties: {
|
|
@@ -4982,7 +5021,14 @@ const conservationTool = (ctx) => define({
|
|
|
4982
5021
|
source = 'alignment';
|
|
4983
5022
|
} else {
|
|
4984
5023
|
const entries = await msaEntries(ctx, exec, args, 'molbio_conservation');
|
|
4985
|
-
|
|
5024
|
+
try {
|
|
5025
|
+
rows = progressiveAlign(entries).alignment.map((row) => row.sequence);
|
|
5026
|
+
} catch (error) {
|
|
5027
|
+
if (error instanceof MolbioInputError && /3000/.test(error.message)) {
|
|
5028
|
+
throw new MolbioInputError(`${error.message} — for a TWO-sequence comparison above that limit use molbio_align (pairwise, up to 50M matrix cells).`);
|
|
5029
|
+
}
|
|
5030
|
+
throw error;
|
|
5031
|
+
}
|
|
4986
5032
|
source = 'msa';
|
|
4987
5033
|
}
|
|
4988
5034
|
return { source, ...conservationAnalysis(rows, threshold) };
|
|
@@ -4991,12 +5037,12 @@ const conservationTool = (ctx) => define({
|
|
|
4991
5037
|
|
|
4992
5038
|
const alignmentPostprocessTool = (ctx) => define({
|
|
4993
5039
|
name: 'molbio_alignment_postprocess',
|
|
4994
|
-
description: 'Post-process an alignment: IUPAC consensus, gap-ratio column trimming, a pairwise identity matrix, and per-column coverage.
|
|
5040
|
+
description: 'Post-process an alignment: IUPAC consensus, gap-ratio column trimming, a pairwise identity matrix, and per-column coverage. One of `alignment` (pre-aligned rows), `sequences` (unaligned) or `fasta_path` (same inputs as molbio_conservation). '
|
|
4995
5041
|
+ '`consensus_mode` picks which consensus is reported, and they are genuinely different answers: "plurality" (default) gives the top residue when it reaches `consensus_threshold` (default 0.5) and otherwise the IUPAC code for everything observed; "union" always gives that IUPAC code; "strict" gives the top residue above the threshold and N otherwise, so a mixed position never masquerades as a base. '
|
|
4996
5042
|
+ '`max_gap_fraction` (default 0.5) marks columns to trim and reports the column numbers BEFORE trimming (original 1-based coordinates, so they stay comparable with the input); the trimmed alignment itself is not returned — only which columns would go and how many remain. '
|
|
4997
5043
|
+ '`coverage_threshold` (default 0.8, a non-gap fraction) lists poorly covered columns; `mean_coverage` and `fully_covered_columns` summarise the same numbers. '
|
|
4998
5044
|
+ 'NOTE ON THE IDENTITY MATRIX: its denominator is the columns where at least one of the two rows has a residue (double-gap columns excluded), which is NOT the convention molbio_conservation uses for its pairwise_identity_percent (that one divides by all columns). Both are documented and internally consistent; do not compare the two numbers directly. '
|
|
4999
|
-
+ 'Heuristic reporting for working comparisons; deterministic.',
|
|
5045
|
+
+ 'Heuristic reporting for working comparisons; deterministic. The four outputs come back together; a second call is only for a different alignment.',
|
|
5000
5046
|
parameters: {
|
|
5001
5047
|
type: 'object',
|
|
5002
5048
|
properties: {
|
|
@@ -5143,7 +5189,7 @@ const sequenceLogoTool = (ctx) => define({
|
|
|
5143
5189
|
// safe let two parallel calls overwrite one file.
|
|
5144
5190
|
safe: false,
|
|
5145
5191
|
name: 'molbio_sequence_logo',
|
|
5146
|
-
description: 'Render a sequence logo (per-position base composition, letter height = information content in bits) as an SVG file in the session workspace, then open it with the OS default application.
|
|
5192
|
+
description: 'Render a sequence logo (per-position base composition, letter height = information content in bits) as an SVG file in the session workspace, then open it with the OS default application. Accepts the same `alignment`, `sequences` or `fasta_path` inputs as molbio_conservation. Frequencies are computed over residues only (gaps excluded and reported per column); IUPAC ambiguity codes are expanded into their base sets. `small_sample` (default true) subtracts the conventional (K-1)/(2·ln2·n) entropy correction, which matters most for few sequences; `score_type: "frequency"` switches to a plain frequency plot (letters sum to 1, y axis 0-1) instead of bits (0-2). Heuristic visualisation of an alignment — it shows the data you give it, and says nothing about function on its own.',
|
|
5147
5193
|
parameters: {
|
|
5148
5194
|
type: 'object',
|
|
5149
5195
|
properties: {
|
|
@@ -5618,7 +5664,7 @@ const fastaFastqTool = (ctx) => define({
|
|
|
5618
5664
|
safe: (args) => !(args.action === 'convert'
|
|
5619
5665
|
|| (args.action === 'extract' && args.output_path !== undefined && args.output_path !== '')),
|
|
5620
5666
|
name: 'molbio_fasta_fastq',
|
|
5621
|
-
description: 'Work with FASTA/FASTQ files in the workspace. action=stats: per-entry and overall statistics (length/GC). action=extract: pull entries by id (exact or substring) and optionally write them to a FASTA file. action=convert: FASTQ → FASTA (output_path required). action=qc: FASTQ quality statistics (mean/min/max Phred, low-quality fraction, per-position means).',
|
|
5667
|
+
description: 'Work with FASTA/FASTQ files in the workspace. action=stats: per-entry and overall statistics (length/GC). action=extract: pull entries by id (exact or substring) and optionally write them to a FASTA file. action=convert: FASTQ → FASTA (output_path required). action=qc: FASTQ quality statistics (mean/min/max Phred, low-quality fraction, per-position means). The result carries the per-file counts and quality numbers: quote them in the answer instead of only pointing at the files. When the request is a QC question, the read count and mean quality ARE the answer: a reply that only lists the written files is incomplete.',
|
|
5622
5668
|
parameters: {
|
|
5623
5669
|
type: 'object',
|
|
5624
5670
|
required: ['path'],
|
|
@@ -6312,7 +6358,7 @@ const PCR_PAIR_IN_SCHEMA = {
|
|
|
6312
6358
|
const pcrSimulateTool = (ctx) => define({
|
|
6313
6359
|
safe: false,
|
|
6314
6360
|
name: 'molbio_pcr_simulate',
|
|
6315
|
-
description: 'In-silico PCR:
|
|
6361
|
+
description: 'In-silico PCR: every amplicon a primer pair produces on a template, both strands, with product sizes, coordinates and mismatch detail. Answers where else a pair amplifies and what band to expect. Pass ALL pairs in one `primer_pairs` call, one template per call — re-calling per pair only repeats the same scan. Mismatch tolerance (`max_mismatches`) and the exact-match requirement at the primer 3\' end (`three_prime_exact`, default 3 bases) are separate knobs: a middle mismatch still extends, a 3\' mismatch usually does not. Handles circular templates (products across the origin) and extra templates, and draws the expected gel. For a whole multiplex panel use molbio_multiplex_check instead of running this pair by pair. Matches the WHOLE primer, so a 5\' cloning or restriction tail cannot anneal — for tailed primers verify the binding part, or pass the bare binding sequence.',
|
|
6316
6362
|
parameters: {
|
|
6317
6363
|
type: 'object',
|
|
6318
6364
|
properties: {
|
|
@@ -6367,6 +6413,9 @@ const pcrSimulateTool = (ctx) => define({
|
|
|
6367
6413
|
}
|
|
6368
6414
|
if (pair.truncated) lines.push(` more products exist than the listing cap (${pair.amplicon_count} shown)`);
|
|
6369
6415
|
if (pair.out_of_range > 0) lines.push(` ${pair.out_of_range} product(s) fell outside the size window`);
|
|
6416
|
+
if (pair.amplicon_count === 0 && pair.forward_sites.length === 0 && pair.reverse_sites.length === 0) {
|
|
6417
|
+
lines.push(" no full-length primer site: this tool matches the WHOLE primer, so a 5' cloning tail (protection bases + restriction site) never anneals — verify the binding part alone, or rely on molbio_clone_primers' own warning.");
|
|
6418
|
+
}
|
|
6370
6419
|
}
|
|
6371
6420
|
for (const screen of value.screens) {
|
|
6372
6421
|
const hits = screen.products.filter((entry) => entry.amplicon_count > 0);
|
|
@@ -7947,7 +7996,7 @@ function paperServiceDeps(ctx, exec, args) {
|
|
|
7947
7996
|
|
|
7948
7997
|
const pubmedSearchTool = (ctx) => define({
|
|
7949
7998
|
name: 'molbio_pubmed_search',
|
|
7950
|
-
description: 'Search PubMed for literature. With an NCBI API key (the api_key argument, the harness credential store under NCBI_API_KEY / MOLBIO_NCBI_API_KEY, or the environment) it queries the official E-utilities API and returns PubMed records with PMIDs, titles, journal/year, authors and DOI; without a key it falls back to the harness web-search service. Add the papers you keep to the reading library with molbio_paper_add.',
|
|
7999
|
+
description: 'Search PubMed for literature. With an NCBI API key (the api_key argument, the harness credential store under NCBI_API_KEY / MOLBIO_NCBI_API_KEY, or the environment) it queries the official E-utilities API and returns PubMed records with PMIDs, titles, journal/year, authors and DOI; without a key it falls back to the harness web-search service. Add the papers you keep to the reading library with molbio_paper_add. One query returns the PMIDs: search once with the combined terms, then fetch abstracts only for the PMIDs you will cite.',
|
|
7951
8000
|
parameters: {
|
|
7952
8001
|
type: 'object',
|
|
7953
8002
|
required: ['query'],
|
|
@@ -8615,6 +8664,17 @@ async function readSequencingInputs(ctx, exec, args) {
|
|
|
8615
8664
|
const reads = [];
|
|
8616
8665
|
for (const path of args.paths ?? []) {
|
|
8617
8666
|
const bytes = await readFileBytes(ctx, exec, path);
|
|
8667
|
+
const lower = String(path).toLowerCase();
|
|
8668
|
+
// A multi-record FASTA is a read SET, not a malformed trace: expand it into
|
|
8669
|
+
// one named read per record so a file can be handed over as-is.
|
|
8670
|
+
if (lower.endsWith('.fasta') || lower.endsWith('.fa') || lower.endsWith('.fna')) {
|
|
8671
|
+
const text = new TextDecoder().decode(bytes).replace(/^\uFEFF/, '');
|
|
8672
|
+
const entries = text.trimStart().startsWith('>') ? parseFasta(text) : [];
|
|
8673
|
+
if (entries.length > 1) {
|
|
8674
|
+
for (const entry of entries) reads.push({ name: entry.id, sequence: normalizeSequence(entry.sequence, `read ${entry.id}`) });
|
|
8675
|
+
continue;
|
|
8676
|
+
}
|
|
8677
|
+
}
|
|
8618
8678
|
const trace = readTraceFromBytes(bytes, path);
|
|
8619
8679
|
const name = String(path).split(/[\\/]/).pop().replace(/\.[^.]*$/, '') || 'read';
|
|
8620
8680
|
reads.push({ name, sequence: trace.bases, qualities: trace.qualities });
|
|
@@ -8754,7 +8814,7 @@ const ALLELE_SCHEMA = {
|
|
|
8754
8814
|
|
|
8755
8815
|
const editingOutcomeTool = (ctx) => define({
|
|
8756
8816
|
name: 'molbio_editing_outcome',
|
|
8757
|
-
description: 'Cluster ALL reads against the reference in ONE call and report each allele\'s frequency and (inside an optional CDS) its protein effect — do not call this once per read and do not re-derive the effect with molbio_translate, a script, or a shell command; the result already carries frameshift/missense/nonsense/silent/in_frame_indel. Pass every read in `reads` as [{name, sequence}] with sequences copied exactly (or pass `paths` for .ab1/.seq/.fasta files instead of retyping them), and pass the COMPLETE reference molecule in `reference` — not the CDS and not one of the reads; `cds_start`/`cds_end` are 1-based inclusive coordinates ON that reference. Reads align in both orientations; reads below the identity/span thresholds are reported as unaligned rather than forced into an allele. Frequencies are fractions of the ALIGNED reads (read-fraction clustering, NOT TIDE peak decomposition). A `wild_type` allele means a read identical to the reference; if you expected wild-type reads and none appear, check that `reference` is the full molecule.',
|
|
8817
|
+
description: 'Cluster ALL reads against the reference in ONE call and report each allele\'s frequency and (inside an optional CDS) its protein effect — do not call this once per read and do not re-derive the effect with molbio_translate, a script, or a shell command; the result already carries frameshift/missense/nonsense/silent/in_frame_indel. Pass every read in `reads` as [{name, sequence}] with sequences copied exactly (or pass `paths` for .ab1/.seq/.fasta files instead of retyping them), and pass the COMPLETE reference molecule in `reference` — not the CDS and not one of the reads; `cds_start`/`cds_end` are 1-based inclusive coordinates ON that reference. Reads align in both orientations; reads below the identity/span thresholds are reported as unaligned rather than forced into an allele. Frequencies are fractions of the ALIGNED reads (read-fraction clustering, NOT TIDE peak decomposition). A `wild_type` allele means a read identical to the reference; if you expected wild-type reads and none appear, check that `reference` is the full molecule. One call answers the whole read set: the CDS effect is already classified, so a translate pass, a shell script or a per-allele re-call adds nothing. Read fidelity decides the answer: prefer `paths`, and if you retype a sequence check its length against the reference first — one missing base turns a 3 bp in-frame deletion into a frameshift.',
|
|
8758
8818
|
parameters: {
|
|
8759
8819
|
type: 'object',
|
|
8760
8820
|
properties: {
|
|
@@ -8810,38 +8870,56 @@ const editingOutcomeTool = (ctx) => define({
|
|
|
8810
8870
|
},
|
|
8811
8871
|
});
|
|
8812
8872
|
|
|
8813
|
-
// ── prompt guidance
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8873
|
+
// ── prompt guidance ─────────────────────────────────────────────────────────
|
|
8874
|
+
//
|
|
8875
|
+
// Routing and cross-tool rules ONLY. What a tool does, what its arguments mean
|
|
8876
|
+
// and which model or table it uses live in that tool's own description, so each
|
|
8877
|
+
// rule belongs in exactly one place. test/prompt.mjs enforces the split: it
|
|
8878
|
+
// fails on a registered tool this list never names, on a release marker such as
|
|
8879
|
+
// "(v19)", on a span copied from a tool description, on an over-long line, and
|
|
8880
|
+
// on a section over its character budget.
|
|
8881
|
+
|
|
8882
|
+
const PROMPT_SECTION = [
|
|
8883
|
+
'Molecular-biology tools (dsh-molbio-tools) are available with the molbio_* prefix. Route by the question being asked: each tool description carries its arguments, its model and its limits, so read it before filling parameters.',
|
|
8884
|
+
'',
|
|
8885
|
+
'## Route by question',
|
|
8886
|
+
'- sequence basics — reverse complement, GC, translation and ORFs, where enzymes cut: molbio_reverse_complement, molbio_gc_content, molbio_translate, molbio_restriction_sites.',
|
|
8887
|
+
'- enzymes — catalog entry and cut geometry, Dam/Dcm blocking, two-enzyme plans: molbio_enzyme_lookup, molbio_methylation_check, molbio_double_digest.',
|
|
8888
|
+
'- primers — automatic pair design, a qPCR pair across an exon junction, Tm, red-flag screen: molbio_design_primers, molbio_design_intron_primers, molbio_primer_tm, molbio_primer_check.',
|
|
8889
|
+
'- probe assays and multiplexing — hydrolysis probe with an ordering CSV, several pairs in one tube: molbio_design_taqman, molbio_multiplex_check.',
|
|
8890
|
+
'- thermodynamics of one exact duplex: molbio_duplex_thermo.',
|
|
8891
|
+
'- qPCR numbers and bench math — Ct to fold change, standard curve, dilutions and molarity: molbio_qpcr_analysis, molbio_qpcr_efficiency, molbio_lab_math.',
|
|
8892
|
+
'- plasmids — open a GenBank text or a SnapGene .dna file, draw and annotate the map: molbio_parse_genbank, molbio_parse_snapgene, molbio_plasmid_map_file, molbio_plasmid_map.',
|
|
8893
|
+
'- cloning — unique cutters, restriction or Gibson simulation, Golden Gate, tails on primers: molbio_unique_cutters, molbio_clone_simulate, molbio_golden_gate, molbio_clone_primers.',
|
|
8894
|
+
'- mutagenesis — QuickChange-style primers, add or drop a site without changing the protein: molbio_mutagenesis_primers, molbio_silent_site_mutagenesis.',
|
|
8895
|
+
'- sequencing — verify a trace against the reference, assemble reads into a contig, classify editing outcomes: molbio_verify_sanger, molbio_sanger_assemble, molbio_editing_outcome.',
|
|
8896
|
+
'- proteins — properties and charge curve, peptide digest, codon optimisation, wheel, hydropathy: molbio_protein_props, molbio_protein_charge, molbio_peptide_digest, molbio_codon_optimize, molbio_helical_wheel, molbio_hydropathy_plot.',
|
|
8897
|
+
'- protein annotation — PTM motifs and low-complexity regions, signal peptide, antigenicity: molbio_protein_features, molbio_signal_peptide, molbio_antigenicity.',
|
|
8898
|
+
'- figures — experiment-data charts, expected gel: molbio_plot, molbio_virtual_gel.',
|
|
8899
|
+
'- alignments — pairwise, multiple, conservation, consensus and column trimming, logo, dotplot: molbio_align, molbio_msa_align, molbio_conservation, molbio_alignment_postprocess, molbio_sequence_logo, molbio_dotplot.',
|
|
8900
|
+
'- CRISPR guide candidates with off-target search: molbio_grna_design.',
|
|
8901
|
+
'- files — FASTA/FASTQ stats and conversion, read QC, trimming, vector/adapter screen: molbio_fasta_fastq, molbio_fastq_qc, molbio_fastq_trim, molbio_contamination_screen.',
|
|
8902
|
+
'- batch and formats — one table for a whole directory, region extraction, feature export (GFF3/BED/CSV), sequence surgery: molbio_batch_analyze, molbio_extract_region, molbio_feature_export, molbio_sequence_edit.',
|
|
8903
|
+
'- predictions over a sequence — in-silico PCR and expected bands, composition and CpG islands, phylogeny, codon usage: molbio_pcr_simulate, molbio_gc_composition, molbio_phylogenetic_tree, molbio_codon_usage.',
|
|
8904
|
+
'- literature and records — search, abstracts, BibTeX, reading library, protocols, experiment log: molbio_pubmed_search, molbio_pubmed_abstract, molbio_paper_export_bibtex, molbio_paper_add, molbio_paper_list, molbio_paper_update, molbio_paper_remove, molbio_protocol_add, molbio_protocol_list, molbio_protocol_update, molbio_experiment_log, molbio_experiment_list.',
|
|
8905
|
+
'',
|
|
8906
|
+
'## Hard rules',
|
|
8907
|
+
'1. Coordinates, feature positions and insert orientation come from tool output. Never re-derive them by reasoning, and never rebuild a feature list by hand.',
|
|
8908
|
+
'2. Call a tool once with all the input it takes — every read, every allele, every row. Do not re-call it per record, and do not recompute what it already returned with another tool, a script or a shell command.',
|
|
8909
|
+
'3. Files a tool writes (SVG, CSV, FASTA, GenBank) are reported by path — but a path is not the answer: state the numbers the tool computed (sizes, counts, quality, verdict) in the reply too. Do not reproduce file content; when one run writes several, pass auto_view: false and list the paths.',
|
|
8910
|
+
'4. Image tools open the SVG themselves (auto_view defaults to true; auto_viewed reports whether it worked). Tell the user it opened, and do not claim to have looked at the picture unless attach_image delivered it to you.',
|
|
8911
|
+
'5. Estimates stay labelled as estimates: Tm (SantaLucia-1998 nearest-neighbour), pI, A280, GRAVY, and every heuristic ranking (guide score, antigenicity, signal peptide, hydropathy peaks). Never present them as SignalP/TMHMM/BepiPred/BLAST/TIDE output.',
|
|
8912
|
+
'6. Positions are 1-based inclusive unless the tool or format says otherwise: GFF3 is 1-based inclusive, BED is 0-based half-open, and molbio_feature_export reports which one it wrote.',
|
|
8913
|
+
'7. On a MolbioInputError, fix the arguments and retry. Do not fall back to computing the biology by hand.',
|
|
8914
|
+
'8. Skip a tool call for a conceptual or literature-only question: these tools compute on real input, they are not needed to explain a method.',
|
|
8915
|
+
'',
|
|
8916
|
+
'## Conventions',
|
|
8917
|
+
'- Prefer a *_path argument over retyping a sequence; workspace files are the normal input.',
|
|
8918
|
+
'- When the numbers are already in a file, pass data_path with columns naming the roles. Do not retype a column into a call.',
|
|
8919
|
+
'- The reading library, protocols and experiments persist in papers.json, protocols.json and experiments.json in the workspace; every other tool is a pure computation.',
|
|
8920
|
+
'- Literature tools need the network: molbio_pubmed_search uses E-utilities when it has an NCBI key (api_key, credential store or environment) and otherwise falls back to the harness search.',
|
|
8921
|
+
'- Report numbers at the precision the tool returns, with units, and say which model produced them when it matters.',
|
|
8819
8922
|
].join('\n');
|
|
8820
|
-
const PROMPT_SECTION = `Molecular-biology tools (dsh-molbio-tools) are available with the molbio_* prefix:
|
|
8821
|
-
- Sequence math: molbio_reverse_complement, molbio_gc_content, molbio_translate, molbio_restriction_sites, molbio_methylation_check (which enzymes a Dam/Dcm-methylated template blocks, plus the enzymes that survive), molbio_double_digest (two enzymes: per-enzyme and combined fragments + whether they share a buffer).
|
|
8822
|
-
- Primer work: molbio_design_primers (automatic pair design), molbio_design_intron_primers (qPCR primers spanning an exon-exon junction against a genomic sequence + exon list, so gDNA does not amplify), molbio_primer_tm, molbio_primer_check, molbio_duplex_thermo (ΔH/ΔS/ΔG°37/Tm for one exact duplex plus hairpin and dimer checks; a mismatched partner is refused, not estimated), molbio_design_taqman (hydrolysis-probe assay: primer pair + probe with the no-5'-G / probe-Tm-margin rules; probe_chemistry='mgb' for shorter MGB probes with an explicitly unmodified NN Tm, and save_path for an ordering CSV of F/R/P with modifications/scale/purification), molbio_multiplex_check (whether several primer pairs can share one tube: cross-dimers, cross-template annealing, gel-resolvable amplicon sizes, plus an annealing-temperature recommendation and a size-balanced starting primer-concentration plan).
|
|
8823
|
-
- qPCR and bench math: molbio_qpcr_analysis, molbio_lab_math.
|
|
8824
|
-
- Plasmids: molbio_parse_genbank (GenBank text), molbio_parse_snapgene (SnapGene .dna files — researchers usually have .dna files, so when the user names a .dna path use this), molbio_plasmid_map_file (reads a .dna/.gb file and writes the map SVG directly into the workspace in one call), molbio_plasmid_map (same, from a sequence + features). Both map tools WRITE the .svg file themselves and return svg_path — never try to reproduce SVG text in the conversation. Every image-writing tool (maps, plots, virtual gels, qPCR standard curves, clone/Golden Gate maps) opens the generated SVG automatically with the OS default application (auto_view defaults to true; the result's auto_viewed field says whether the hand-off worked), so there is normally nothing for the user to open manually; pass auto_view: false only when the caller explicitly wants no viewer window.
|
|
8825
|
-
- Cloning: molbio_unique_cutters (pick enzymes that cut the vector once and never the insert), molbio_clone_simulate (restriction-ligation or Gibson assembly → final plasmid sequence + verification digests; pass save_path to write a FASTA), molbio_golden_gate (type IIS multi-fragment assembly: the tool designs the 4 bp junctions and the fragments-to-order, and simulates the final plasmid — use it for BsaI-style Golden Gate instead of reasoning about overhangs by hand), molbio_enzyme_lookup (enzyme catalog: recognition/cut geometry/overhang, plus every cut of a sequence in both strand orientations), molbio_clone_primers (enzyme tails or Gibson arms on amplification primers, with re-checks), molbio_mutagenesis_primers (QuickChange-style mutation primers), molbio_silent_site_mutagenesis (add or remove a restriction site with synonymous codons only, keeping the protein unchanged; the returned mutation_texts feed molbio_mutagenesis_primers).
|
|
8826
|
-
- Verification: molbio_verify_sanger (read .ab1/.seq traces, align to the reference plasmid — circular-aware — and report mismatches/indels/amino-acid changes).
|
|
8827
|
-
- Proteins: molbio_protein_props (MW/pI/A280/GRAVY — estimates), molbio_peptide_digest (trypsin etc. for MS), molbio_codon_optimize (E. coli/yeast/human, can avoid restriction sites), molbio_helical_wheel (Schiffer-Edmundson wheel + Eisenberg hydrophobic moment, written as an SVG), molbio_hydropathy_plot (Kyte-Doolittle sliding-window profile with the 1.6 threshold peaks, written as an SVG).
|
|
8828
|
-
- Quantitation: molbio_qpcr_efficiency (standard curve + plot), molbio_plot (experiment-data charts written to files), molbio_virtual_gel (expected band pattern as an SVG gel image with a size ladder).
|
|
8829
|
-
- molbio_plot kinds: bar (labelled values + optional SD error bars) and scatter (x/y + optional least-squares line) take their arrays directly in the call; the table kinds read a workspace CSV/TSV — pass data_path plus columns naming which column plays which role, or pass data with the table text inline. Use a table kind whenever the numbers are already in a file: do NOT retype a column into the call. line = one series per group_column; histogram = distribution of one column (bins default to Freedman-Diaconis unless you pass bins); box = Q1-Q3 box, median, 1.5xIQR whiskers, outliers as dots; violin = the same samples as a kernel-density silhouette with the box summary inside (use it when the SHAPE matters, not just the five numbers); volcano = effect size against significance from a log2-fold-change column and a p column, with dashed thresholds — it computes no statistics of its own, so the p-values must already be in the table; heatmap = a row x column matrix, one cell per value plus a colour bar, accepting either a wide table (first column = row labels, the rest = samples) or the long form (columns.row/column/value), with scale row_zscore|log2 as an explicitly-reported DISPLAY transform. The result carries the computed statistics (medians, quartiles, outliers, bin counts, axis ranges, significance counts, matrix extent), so quote THOSE instead of estimating values off the picture.
|
|
8830
|
-
- Sequences & files: molbio_align (local alignment with a readable match line), molbio_msa_align (progressive multiple sequence alignment — pass an array of sequences or a workspace FASTA), molbio_conservation (consensus + per-column identity/conservation + variable positions; accepts aligned rows or raw sequences it aligns first), molbio_sequence_logo (draws the same alignment as a sequence logo SVG — pass the molbio_msa_align output rows as the alignment argument; letters are sized by per-position information content), molbio_fasta_fastq (FASTA/FASTQ stats/extract/convert/QC on workspace files), molbio_contamination_screen (embedded short vector/adapter signatures, both strands, exact or 0-2 mismatches — a short-signature screen, not BLAST), molbio_batch_analyze (run one summary/ORF/enzyme analysis over every matching FASTA/FASTQ/GenBank/.dna file in a directory and write one CSV/TSV table), molbio_extract_region (pull a CDS/promoter/region from a plasmid file by feature label or coordinates).
|
|
8831
|
-
- CRISPR: molbio_grna_design (family-aware guide RNAs over a sequence or plasmid file: cas_family spcas9/sacas9/cas12a/cas13a/cas13b/cas13d selects the PAM side, crRNA length, seed and target type — Cas12a uses a 5' TTTV PAM and 23 nt crRNA; Cas13 targets RNA and reports a PFS preference rather than a PAM. Both strands are scanned for DNA families, the sense strand by default for Cas13; guides are filtered on GC/poly-T/self-complementarity and ranked, with a mismatch-tolerant off-target search over the same sequence — reaching a whole genome simply means passing it as the target). Pass the top candidates on for ordering with save_path (CSV) or map_path (SVG map); the ranking is a heuristic and says so, so present it as candidate ranking, never as a validated efficiency prediction.
|
|
8832
|
-
- Map extras: pass gc_skew: true for the GC skew ring, show_unique_cutters: true to mark single-cutting enzymes on the map.
|
|
8833
|
-
- Literature & records: molbio_pubmed_abstract (fetch abstracts by PMID — needs web fetch; an NCBI key comes from the api_key argument, the credential store's NCBI_API_KEY, or the environment), molbio_paper_export_bibtex (papers.json → .bib), molbio_protocol_add / molbio_protocol_list / molbio_protocol_update (protocols.json), molbio_experiment_log / molbio_experiment_list (experiments.json).
|
|
8834
|
-
- Bench analysis (v19): molbio_fastq_qc (read-level QC for a FASTQ file: per-base quality with quartiles, per-read quality, base content, GC distribution, length, exact duplication, over-represented sequences, adapter screen, plus a report SVG — use it for "is this run good"), molbio_codon_usage (CAI/RSCU/Nc/GC3, rare-codon list and CDS CpG against E. coli/yeast/human — use it for "will this gene express"; it explains, molbio_codon_optimize rewrites), molbio_phylogenetic_tree (distance method: p-distance/JC/K2P/Tamura-Nei, UPGMA or neighbour-joining, bootstrap support, consensus, Newick file and an SVG tree — it is NOT a maximum-likelihood or Bayesian analysis, and bootstrap percentages are not p-values), molbio_pcr_simulate (where a primer pair amplifies: product sizes and coordinates on both strands, mismatch detail, the 3'-end exact-match requirement, circular templates, screening other templates, and an expected gel — use it for "what band will I see"), molbio_gc_composition (sliding-window GC, CpG islands under the Gardiner-Garden or Takai criteria, GC/AT skew with the cumulative-skew origin/terminus indication, dinucleotide obs/exp, entropy, complexity, N50/L50, plus a figure — use it for "is this a promoter or an origin"), molbio_fastq_trim (trim low-quality 3' tails, exact adapters/primers, poly-G/poly-A, then filter by length/N and write FASTQ/FASTA — not a paired-end merger).
|
|
8835
|
-
- Literature: molbio_pubmed_search — with an NCBI API key (api_key argument, the credential store under NCBI_API_KEY / MOLBIO_NCBI_API_KEY, or the environment) it uses the official PubMed E-utilities API and returns PMIDs, titles, journal/year, authors and DOI; without a key it falls back to the harness web search. The reading library is molbio_paper_add / molbio_paper_list / molbio_paper_update / molbio_paper_remove (papers.json in the workspace).
|
|
8836
|
-
|
|
8837
|
-
${NEW_PROMPT_LINES}
|
|
8838
|
-
|
|
8839
|
-
Cloning workflow rules (follow them to avoid slow re-derivation):
|
|
8840
|
-
- To clone a sequence into a plasmid, call molbio_clone_simulate FIRST — pass the BARE insert with add_flanks: true and the tool adds the enzyme recognition sites itself. The tool also validates single cutting, insert orientation, and internal sites itself: never pre-verify enzymes, cutting counts, or flank construction by thinking. Its output already contains final_sequence AND the remapped feature coordinates (features field). NEVER recompute feature coordinates or insert positions by reasoning — always take them from the tool output.
|
|
8841
|
-
- To draw the new plasmid, either pass map_path to molbio_clone_simulate (one call writes the SVG with remapped features and verification enzymes marked) or feed its features + final_sequence to molbio_plasmid_map. Never rebuild the feature list by hand.
|
|
8842
|
-
- Insert orientation is the tool's job: orientation=auto (the default) reverse-complements an inverted insert automatically. If the tool still reports an inverted insert, pass orientation=reverse instead of re-deriving coordinates.
|
|
8843
|
-
- Never parse tool outputs with regex, shell commands, or throwaway scripts — every tool returns structured data that feeds the next tool directly. Mutation descriptions (A123G etc.) are parsed by molbio_mutagenesis_primers, not by you.
|
|
8844
|
-
- All tools are pure computations except the paper library, pubmed search, and file-backed outputs, which use the harness filesystem and web services under the usual sandbox policy. The Tm model is a SantaLucia-1998 nearest-neighbour estimate — always say it is an estimate.`;
|
|
8845
8923
|
|
|
8846
8924
|
export function apply(ctx) {
|
|
8847
8925
|
ctx.systemPrompt.section({
|
|
@@ -8866,7 +8944,7 @@ export function apply(ctx) {
|
|
|
8866
8944
|
multiplexTool,
|
|
8867
8945
|
methylationTool,
|
|
8868
8946
|
doubleDigestTool,
|
|
8869
|
-
parseGenbankTool,
|
|
8947
|
+
parseGenbankTool(ctx),
|
|
8870
8948
|
plasmidMapTool(ctx),
|
|
8871
8949
|
parseSnapgeneTool(ctx),
|
|
8872
8950
|
plasmidMapFileTool(ctx),
|
|
@@ -8886,7 +8964,7 @@ export function apply(ctx) {
|
|
|
8886
8964
|
qpcrEfficiencyTool(ctx),
|
|
8887
8965
|
plotTool(ctx),
|
|
8888
8966
|
virtualGelTool(ctx),
|
|
8889
|
-
alignTool,
|
|
8967
|
+
alignTool(ctx),
|
|
8890
8968
|
msaAlignTool(ctx),
|
|
8891
8969
|
conservationTool(ctx),
|
|
8892
8970
|
alignmentPostprocessTool(ctx),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-molbio-tools",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "Zero-dependency molecular-biology plugin bundle for the DeepSeek Harness: sequence analysis, primer design (incl. cross-intron qPCR primers, TaqMan hydrolysis/MGB probes with ordering CSV and multiplex compatibility, duplex thermodynamics (ΔH/ΔS/ΔG37/Tm with hairpin and dimer checks)), in-silico PCR, cloning simulation, SnapGene .dna parsing and plasmid maps, Sanger verification, protein tools (incl. helical wheel, hydropathy and charge-pH plots), methylation-aware restriction analysis with double-digest buffer checks, qPCR analysis and plotting, multiple sequence alignment that conserves every input residue, conservation analysis, sequence logos, codon-usage analysis, phylogenetic trees with bootstrap support, Newick I/O and long-name label wrapping, CpG-island/GC-skew composition analysis, k-mer dotplots, read-level FASTQ QC, vector/adapter contamination screening, FASTQ trimming/filtering, batch file analysis with CSV export, silent restriction-site mutagenesis, family-aware CRISPR gRNA design (SpCas9/SaCas9/Cas12a/Cas13) with off-target search, an opt-in hand-off that shows a generated plot to the model as an attached image, plus a browser-side right-sidebar panel (plasmid maps, sequence logos, and a rotatable realistic 3D ball-and-stick/space-filling preview of PDB/mmCIF/SDF structures drawn in the Web GUI) and a literature/protocol/experiment record system.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build:client": "node build/client-bundle.mjs",
|
|
20
|
-
"test": "node --run test:unit && node test/contract.mjs && node test/drift-probe.mjs && node test/preset-health.mjs && node test/release.mjs && node test/benchmark-profile.mjs && node test/benchmark-score.mjs && node test/benchmark-coverage.mjs && node test/benchmark-changed.mjs && node --run bench:offline",
|
|
20
|
+
"test": "node --run test:unit && node test/prompt.mjs && node test/contract.mjs && node test/drift-probe.mjs && node test/preset-health.mjs && node test/release.mjs && node test/benchmark-profile.mjs && node test/benchmark-score.mjs && node test/benchmark-coverage.mjs && node test/benchmark-changed.mjs && node --run bench:offline",
|
|
21
21
|
"test:unit": "node test/smoke.mjs && node test/svgpng.mjs && node test/svgio.mjs && node test/charts.mjs && node test/structure.mjs && node test/client.mjs && node test/panel-render.mjs && node test/map-card.mjs && node test/client-mount.mjs",
|
|
22
22
|
"test:smoke": "node test/smoke.mjs",
|
|
23
|
+
"test:prompt": "node test/prompt.mjs",
|
|
23
24
|
"test:svgpng": "node test/svgpng.mjs",
|
|
24
25
|
"test:charts": "node test/charts.mjs",
|
|
25
26
|
"test:svgio": "node test/svgio.mjs",
|
package/test/prompt.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-molbio-tools/test/prompt.mjs
|
|
3
|
+
*
|
|
4
|
+
* The prompt surface is a shipped artifact: the tool:molbio section plus every
|
|
5
|
+
* tool description travels on every request, and it is what the model reads
|
|
6
|
+
* when it picks a tool. Nothing else in this suite measures it, so this file
|
|
7
|
+
* pins five properties and then PROVES each one can fail (docs/rules.md rule 9).
|
|
8
|
+
*
|
|
9
|
+
* The split of responsibility it enforces:
|
|
10
|
+
* - a tool description says what the tool does, what its arguments mean and
|
|
11
|
+
* which model or table it uses;
|
|
12
|
+
* - the section says when to reach for a tool, the cross-tool rules, and the
|
|
13
|
+
* conventions all tools share;
|
|
14
|
+
* - no rule appears in both, which is why a duplicated span is a failure.
|
|
15
|
+
*
|
|
16
|
+
* Usage: node test/prompt.mjs
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
|
|
21
|
+
const SECTION_BUDGET = 6000;
|
|
22
|
+
const MAX_LINE_CHARS = 400;
|
|
23
|
+
const DUPLICATE_WINDOW = 60;
|
|
24
|
+
|
|
25
|
+
// Tools allowed to live only in their description. Empty on purpose: every
|
|
26
|
+
// registered tool must be reachable from the section, so a new tool cannot
|
|
27
|
+
// ship invisible. Add a name here only with a reason, and keep the list short.
|
|
28
|
+
const DESCRIPTION_ONLY = new Set([]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Audit one prompt surface.
|
|
32
|
+
*
|
|
33
|
+
* Pure, so every mutation below exercises the SAME code the real surface goes
|
|
34
|
+
* through; a guard that only ever sees valid input proves nothing.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ section: string, tools: { name: string, description: string }[] }} input
|
|
37
|
+
* @param {{ budget?: number, maxLineChars?: number, window?: number, descriptionOnly?: Set<string> }} [limits]
|
|
38
|
+
* @returns {string[]} problems; empty means the surface passes.
|
|
39
|
+
*/
|
|
40
|
+
function auditPrompt({ section, tools }, limits = {}) {
|
|
41
|
+
const budget = limits.budget ?? SECTION_BUDGET;
|
|
42
|
+
const maxLineChars = limits.maxLineChars ?? MAX_LINE_CHARS;
|
|
43
|
+
const window = limits.window ?? DUPLICATE_WINDOW;
|
|
44
|
+
const descriptionOnly = limits.descriptionOnly ?? DESCRIPTION_ONLY;
|
|
45
|
+
const problems = [];
|
|
46
|
+
if (section.length > budget) {
|
|
47
|
+
problems.push(`budget: section is ${section.length} chars (max ${budget})`);
|
|
48
|
+
}
|
|
49
|
+
section.split('\n').forEach((line, index) => {
|
|
50
|
+
if (line.length > maxLineChars) {
|
|
51
|
+
problems.push(`line: line ${index + 1} is ${line.length} chars (max ${maxLineChars})`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
for (const marker of new Set(section.match(/\(v[\d.]+\)/g) ?? [])) {
|
|
55
|
+
problems.push(`version marker: ${marker} — release history belongs in CHANGELOG.md`);
|
|
56
|
+
}
|
|
57
|
+
const registered = new Set(tools.map((tool) => tool.name));
|
|
58
|
+
const mentioned = new Set(section.match(/molbio_[a-z0-9_]+/g) ?? []);
|
|
59
|
+
for (const name of registered) {
|
|
60
|
+
if (!mentioned.has(name) && !descriptionOnly.has(name)) {
|
|
61
|
+
problems.push(`coverage: ${name} is registered but never named in the section`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const name of mentioned) {
|
|
65
|
+
if (!registered.has(name)) {
|
|
66
|
+
problems.push(`coverage: ${name} is named in the section but not registered`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const sectionWindows = new Set();
|
|
70
|
+
for (let i = 0; i + window <= section.length; i += 1) sectionWindows.add(section.slice(i, i + window));
|
|
71
|
+
for (const tool of tools) {
|
|
72
|
+
const description = String(tool.description ?? '');
|
|
73
|
+
for (let i = 0; i + window <= description.length; i += 1) {
|
|
74
|
+
const span = description.slice(i, i + window);
|
|
75
|
+
if (!sectionWindows.has(span)) continue;
|
|
76
|
+
problems.push(`duplicate: ${window} chars of ${tool.name} description also sit in the section — "${span.replace(/\s+/g, ' ')}"`);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return problems;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── the real surface ────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
const plugin = await import('../index.mjs');
|
|
86
|
+
const registered = [];
|
|
87
|
+
const sections = [];
|
|
88
|
+
const ctx = {
|
|
89
|
+
systemPrompt: { section(options) { sections.push(options); } },
|
|
90
|
+
get() { return undefined; },
|
|
91
|
+
tools: { register(definition) { registered.push(definition); } },
|
|
92
|
+
};
|
|
93
|
+
plugin.apply(ctx);
|
|
94
|
+
|
|
95
|
+
assert.equal(sections.length, 1, 'the plugin must register exactly one prompt section');
|
|
96
|
+
const [section] = sections;
|
|
97
|
+
assert.equal(section.name, 'tool:molbio');
|
|
98
|
+
assert.equal(section.order, 110, 'tool guidance belongs in the 100-199 band, beside tool-bash');
|
|
99
|
+
assert.ok(typeof section.text === 'string' && section.text.length > 0, 'the section must carry text');
|
|
100
|
+
|
|
101
|
+
const tools = registered.map((tool) => ({ name: tool.name, description: tool.description }));
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
assert.ok(typeof tool.description === 'string' && tool.description.length > 0, `${tool.name} must carry a description`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const problems = auditPrompt({ section: section.text, tools });
|
|
107
|
+
assert.deepEqual(problems, [], `prompt audit failed:\n ${problems.join('\n ')}`);
|
|
108
|
+
|
|
109
|
+
// ── the same guard, seen failing (docs/rules.md rule 9) ─────────────────────
|
|
110
|
+
|
|
111
|
+
const firstTool = tools[0];
|
|
112
|
+
const filler = Array.from({ length: 200 }, () => '- padding line to push the section over budget').join('\n');
|
|
113
|
+
const mutations = [
|
|
114
|
+
[
|
|
115
|
+
'an unlisted tool',
|
|
116
|
+
() => ({ section: section.text.replace(firstTool.name, 'molbio_unlisted'), tools }),
|
|
117
|
+
/coverage:/,
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
'a release marker',
|
|
121
|
+
() => ({ section: `${section.text}\n- (v19) legacy wording that should not be here.`, tools }),
|
|
122
|
+
/version marker:/,
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
'a span copied from a description',
|
|
126
|
+
() => ({ section: `${section.text}\n- ${firstTool.description.slice(0, 80)}`, tools }),
|
|
127
|
+
/duplicate:/,
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
'an over-long line',
|
|
131
|
+
() => ({ section: `${section.text}\n${'x'.repeat(MAX_LINE_CHARS + 1)}`, tools }),
|
|
132
|
+
/line:/,
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
'an oversized section',
|
|
136
|
+
() => ({ section: `${section.text}\n${filler}`, tools }),
|
|
137
|
+
/budget:/,
|
|
138
|
+
],
|
|
139
|
+
];
|
|
140
|
+
for (const [label, mutate, expected] of mutations) {
|
|
141
|
+
const mutated = mutate();
|
|
142
|
+
const found = auditPrompt(mutated);
|
|
143
|
+
assert.ok(found.length > 0, `the audit did not notice ${label}`);
|
|
144
|
+
assert.ok(found.some((problem) => expected.test(problem)), `the audit reported ${JSON.stringify(found)} for ${label}, expected ${expected}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const descriptionChars = tools.reduce((sum, tool) => sum + tool.description.length, 0);
|
|
148
|
+
console.log(`prompt section: ${section.text.length} chars (budget ${SECTION_BUDGET}) · ${tools.length} tools · ${descriptionChars} chars of tool descriptions`);
|
|
149
|
+
console.log(`prompt audit: 5 properties hold; ${mutations.length} mutations caught`);
|
package/test/smoke.mjs
CHANGED
|
@@ -312,8 +312,15 @@ function makeTemplate(n, seed = 42) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
{
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
// ["common"] means the WHOLE table, but the default answer is the enzymes that
|
|
316
|
+
// actually cut: printing 100+ "no sites" lines buries the one line that matters.
|
|
317
|
+
const sequence = 'G' + 'AATT'.repeat(0) + 'AATTCAAGCTTA';
|
|
318
|
+
const all = await run('molbio_restriction_sites', { sequence, enzymes: ['common'], only_cutting: false });
|
|
319
|
+
assert.ok(all.enzymes.length > 50);
|
|
320
|
+
const cutting = await run('molbio_restriction_sites', { sequence, enzymes: ['common'] });
|
|
321
|
+
assert.equal(cutting.checked, all.enzymes.length);
|
|
322
|
+
assert.ok(cutting.enzymes.every((entry) => entry.cut_positions.length > 0));
|
|
323
|
+
assert.ok(cutting.enzymes.length < all.enzymes.length);
|
|
317
324
|
}
|
|
318
325
|
|
|
319
326
|
{
|