dsh-molbio-tools 0.27.1 → 0.28.0
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 +82 -0
- package/README.md +39 -14
- package/benchmark/README.md +7 -7
- package/benchmark/_probe-v28.mjs +60 -0
- package/benchmark/tasks/10-v28.json +300 -0
- package/benchmark/verifications.mjs +49 -0
- package/cordis.patch.yml +2 -2
- package/docs/capability-gap-survey.md +1 -1
- package/docs/client-panel.md +2 -2
- package/docs/history.md +47 -0
- package/docs/maintainer.md +9 -6
- package/docs/roadmap.md +26 -4
- package/docs/v28-plan.md +227 -0
- package/docs/workflow.md +5 -5
- package/index.mjs +636 -2
- package/package.json +5 -2
- package/preset/molbio-lab/agent.cordis.yml +2 -2
- package/preset/molbio-lab/preset.yml +1 -1
- package/protein-annotate.mjs +525 -0
- package/sequence-ops.mjs +203 -0
- package/sequencing.mjs +517 -0
- package/test/contract.mjs +2 -2
- package/test/smoke.mjs +191 -2
- package/test/svgpng.mjs +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-molbio-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
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",
|
|
@@ -96,7 +96,10 @@
|
|
|
96
96
|
"test",
|
|
97
97
|
"docs",
|
|
98
98
|
"CHANGELOG.md",
|
|
99
|
-
"README.md"
|
|
99
|
+
"README.md",
|
|
100
|
+
"protein-annotate.mjs",
|
|
101
|
+
"sequence-ops.mjs",
|
|
102
|
+
"sequencing.mjs"
|
|
100
103
|
],
|
|
101
104
|
"dsh": {
|
|
102
105
|
"compatibility": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
#
|
|
18
18
|
# Edit THIS file, then run `node build/preset-patch.mjs`.
|
|
19
19
|
#
|
|
20
|
-
# NOTE: the mode is the ONLY place these
|
|
20
|
+
# NOTE: the mode is the ONLY place these 72 tools load. The same bundle patch's
|
|
21
21
|
# other insert (`molbio-client` → `./host.mjs`) deliberately registers nothing —
|
|
22
22
|
# registering the tool at the host level as well would put it in every session
|
|
23
23
|
# and is not what this package is for.
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
name: '@deepseek-ai/dsh-plugin-market/tools'
|
|
227
227
|
disabled: true
|
|
228
228
|
|
|
229
|
-
# dsh-molbio-tools: molecular-biology toolset (
|
|
229
|
+
# dsh-molbio-tools: molecular-biology toolset (72 tools across sequence
|
|
230
230
|
# analysis, primers (incl. TaqMan probes and multiplex compatibility),
|
|
231
231
|
# in-silico PCR, cloning (incl. Golden Gate), enzyme catalog, methylation-aware
|
|
232
232
|
# and double digests, plasmids, Sanger verification, proteins (incl. helical
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
name: Molecular Biology Lab
|
|
2
|
-
description: 分子生物学专属模式:标准编码能力 +
|
|
2
|
+
description: 分子生物学专属模式:标准编码能力 + 72 个 molbio_* 工具(序列分析、引物设计(含跨内含子 qPCR、盐/浓度旋钮与目标位置偏好)、TaqMan 水解探针(含 MGB 与订购 CSV)与多重 PCR 互扰/退火温度/浓度建议、克隆模拟与选酶(含 Golden Gate)、酶目录查询、甲基化敏感位点与双酶切 buffer 兼容检查、多序列比对(每个输入残基都会进比对结果)、保守性分析与比对后处理(共识/缺口修剪/同一性矩阵/逐列覆盖度,含 sequence logo 图)、CRISPR gRNA 设计(SpCas9/SaCas9/Cas12a/Cas13,家族特定 PAM/PFS/种子)与脱靶搜索、SnapGene/GenBank 解析与质粒图谱、Sanger 测序验证、蛋白性质/电荷-pH 曲线/密码子优化/螺旋轮投影与疏水性图、qPCR 与绘图、虚拟凝胶、实验台分析(FASTQ 质控、密码子使用、系统发生树(长叶名自动折行)、in-silico PCR、CpG/GC 组成、序列 dotplot、载体/接头污染筛查、FASTQ 修剪/过滤、批量文件分析/CSV)、静默酶切位点突变设计、蛋白注释(PTM 基序/低复杂度/不稳定指数、von Heijne 信号肽与跨膜段、Kolaskar-Tongaonkar 抗原性)、注释格式导出(GFF3/BED/CSV)与序列编辑(rotate/insert/delete/replace/split/join)、Sanger 读段组装与编辑结果归类——生成的 SVG 图片自动用系统默认应用打开,文献/协议/实验记录)。
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-molbio-tools/protein-annotate.mjs
|
|
3
|
+
*
|
|
4
|
+
* Protein annotation that the property tools do not answer: post-translational-
|
|
5
|
+
* modification motifs, low complexity, instability, signal-peptide cleavage and
|
|
6
|
+
* antigenic propensity.
|
|
7
|
+
*
|
|
8
|
+
* Every number here is an ESTIMATE from a published, transcribed table. None of
|
|
9
|
+
* it is a trained predictor: TMHMM / SignalP / NetNGlyc / BepiPred are models;
|
|
10
|
+
* these are documented heuristics, and every tool text says so.
|
|
11
|
+
*
|
|
12
|
+
* Parameter tables (values transcribed here, never downloaded at runtime):
|
|
13
|
+
* - Guruprasad 1990 DIWV instability table (20x20): Biopython 1.88
|
|
14
|
+
* Bio/SeqUtils/ProtParamData.py (BSD-3), the reference implementation of the
|
|
15
|
+
* published table.
|
|
16
|
+
* - Kolaskar & Tongaonkar 1990 A(p) (20 values): EMBOSS 6.6.0
|
|
17
|
+
* data/Eantigenic.dat.
|
|
18
|
+
* - von Heijne 1986 signal-peptide counts (eukaryote 161 sequences,
|
|
19
|
+
* prokaryote 36): EMBOSS 6.6.0 data/Esig.euk and data/Esig.pro. Position
|
|
20
|
+
* weights are log(count/expected), exactly as EMBOSS sigcleave builds them.
|
|
21
|
+
* - Parker 1986 hydrophilicity, Emini 1997 accessibility and Vihinen 1994
|
|
22
|
+
* flexibility (20 values each): Biopython 1.88 ProtParamData.py.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { MolbioInputError } from './lib.mjs';
|
|
26
|
+
import { normalizeProtein } from './protein.mjs';
|
|
27
|
+
import { HYDROPATHY_DEFAULTS, hydropathyProfile } from './protein-structure.mjs';
|
|
28
|
+
import { circle, line, polyline, round, svgDocument, textRun } from './svgio.mjs';
|
|
29
|
+
|
|
30
|
+
const AA20 = [...'ACDEFGHIKLMNPQRSTVWY'];
|
|
31
|
+
const round2 = (x) => Math.round(x * 100) / 100;
|
|
32
|
+
const round3 = (x) => Math.round(x * 1000) / 1000;
|
|
33
|
+
|
|
34
|
+
/** Shared input ceiling for the annotation tools (same as the hydropathy plot). */
|
|
35
|
+
export const PROTEIN_ANNOTATE_LIMITS = { maxSequenceLength: 20000 };
|
|
36
|
+
|
|
37
|
+
// ── transcribed parameter tables ────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
/** Kolaskar & Tongaonkar 1990 antigenic propensity A(p) (EMBOSS Eantigenic.dat). */
|
|
40
|
+
export const ANTIGENIC_PROPENSITY = {
|
|
41
|
+
A: 1.064, C: 1.412, D: 0.866, E: 0.851, F: 1.091, G: 0.874, H: 1.105, I: 1.152, K: 0.93, L: 1.25, M: 0.826, N: 0.776, P: 1.064, Q: 1.015, R: 0.873, S: 1.012, T: 0.909, V: 1.383, W: 0.893, Y: 1.161
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Parker 1986 hydrophilicity (higher = more hydrophilic). */
|
|
45
|
+
export const PARKER_HYDROPHILICITY = {
|
|
46
|
+
A: 2.1, R: 4.2, N: 7, D: 10, C: 1.4, Q: 6, E: 7.8, G: 5.7, H: 2.1, I: -8, L: -9.2, K: 5.7, M: -4.2, F: -9.2, P: 2.1, S: 6.5, T: 5.2, W: -10, Y: -1.9, V: -3.7
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Emini surface fractional probability (higher = more accessible; as transcribed
|
|
50
|
+
* by Biopython, which attributes the table to Vergoten & Theophanides 1997). */
|
|
51
|
+
export const EMINI_ACCESSIBILITY = {
|
|
52
|
+
A: 0.815, R: 1.475, N: 1.296, D: 1.283, C: 0.394, Q: 1.348, E: 1.445, G: 0.714, H: 1.18, I: 0.603, L: 0.603, K: 1.545, M: 0.714, F: 0.695, P: 1.236, S: 1.115, T: 1.184, W: 0.808, Y: 1.089, V: 0.606
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Vihinen 1994 normalized flexibility (higher = more flexible). */
|
|
56
|
+
export const VIHINEN_FLEXIBILITY = {
|
|
57
|
+
A: 0.984, C: 0.906, E: 1.094, D: 1.068, G: 1.031, F: 0.915, I: 0.927, H: 0.95, K: 1.102, M: 0.952, L: 0.935, N: 1.048, Q: 1.037, P: 1.049, S: 1.046, R: 1.008, T: 0.997, W: 0.904, V: 0.931, Y: 0.929
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Guruprasad 1990 dipeptide instability weights (row = first residue). */
|
|
61
|
+
const DIWV = {
|
|
62
|
+
A: { A: 1, C: 44.94, E: 1, D: -7.49, G: 1, F: 1, I: 1, H: -7.49, K: 1, M: 1, L: 1, N: 1, Q: 1, P: 20.26, S: 1, R: 1, T: 1, W: 1, V: 1, Y: 1 },
|
|
63
|
+
C: { A: 1, C: 1, E: 1, D: 20.26, G: 1, F: 1, I: 1, H: 33.6, K: 1, M: 33.6, L: 20.26, N: 1, Q: -6.54, P: 20.26, S: 1, R: 1, T: 33.6, W: 24.68, V: -6.54, Y: 1 },
|
|
64
|
+
E: { A: 1, C: 44.94, E: 33.6, D: 20.26, G: 1, F: 1, I: 20.26, H: -6.54, K: 1, M: 1, L: 1, N: 1, Q: 20.26, P: 20.26, S: 20.26, R: 1, T: 1, W: -14.03, V: 1, Y: 1 },
|
|
65
|
+
D: { A: 1, C: 1, E: 1, D: 1, G: 1, F: -6.54, I: 1, H: 1, K: -7.49, M: 1, L: 1, N: 1, Q: 1, P: 1, S: 20.26, R: -6.54, T: -14.03, W: 1, V: 1, Y: 1 },
|
|
66
|
+
G: { A: -7.49, C: 1, E: -6.54, D: 1, G: 13.34, F: 1, I: -7.49, H: 1, K: -7.49, M: 1, L: 1, N: -7.49, Q: 1, P: 1, S: 1, R: 1, T: -7.49, W: 13.34, V: 1, Y: -7.49 },
|
|
67
|
+
F: { A: 1, C: 1, E: 1, D: 13.34, G: 1, F: 1, I: 1, H: 1, K: -14.03, M: 1, L: 1, N: 1, Q: 1, P: 20.26, S: 1, R: 1, T: 1, W: 1, V: 1, Y: 33.601 },
|
|
68
|
+
I: { A: 1, C: 1, E: 44.94, D: 1, G: 1, F: 1, I: 1, H: 13.34, K: -7.49, M: 1, L: 20.26, N: 1, Q: 1, P: -1.88, S: 1, R: 1, T: 1, W: 1, V: -7.49, Y: 1 },
|
|
69
|
+
H: { A: 1, C: 1, E: 1, D: 1, G: -9.37, F: -9.37, I: 44.94, H: 1, K: 24.68, M: 1, L: 1, N: 24.68, Q: 1, P: -1.88, S: 1, R: 1, T: -6.54, W: -1.88, V: 1, Y: 44.94 },
|
|
70
|
+
K: { A: 1, C: 1, E: 1, D: 1, G: -7.49, F: 1, I: -7.49, H: 1, K: 1, M: 33.6, L: -7.49, N: 1, Q: 24.64, P: -6.54, S: 1, R: 33.6, T: 1, W: 1, V: -7.49, Y: 1 },
|
|
71
|
+
M: { A: 13.34, C: 1, E: 1, D: 1, G: 1, F: 1, I: 1, H: 58.28, K: 1, M: -1.88, L: 1, N: 1, Q: -6.54, P: 44.94, S: 44.94, R: -6.54, T: -1.88, W: 1, V: 1, Y: 24.68 },
|
|
72
|
+
L: { A: 1, C: 1, E: 1, D: 1, G: 1, F: 1, I: 1, H: 1, K: -7.49, M: 1, L: 1, N: 1, Q: 33.6, P: 20.26, S: 1, R: 20.26, T: 1, W: 24.68, V: 1, Y: 1 },
|
|
73
|
+
N: { A: 1, C: -1.88, E: 1, D: 1, G: -14.03, F: -14.03, I: 44.94, H: 1, K: 24.68, M: 1, L: 1, N: 1, Q: -6.54, P: -1.88, S: 1, R: 1, T: -7.49, W: -9.37, V: 1, Y: 1 },
|
|
74
|
+
Q: { A: 1, C: -6.54, E: 20.26, D: 20.26, G: 1, F: -6.54, I: 1, H: 1, K: 1, M: 1, L: 1, N: 1, Q: 20.26, P: 20.26, S: 44.94, R: 1, T: 1, W: 1, V: -6.54, Y: -6.54 },
|
|
75
|
+
P: { A: 20.26, C: -6.54, E: 18.38, D: -6.54, G: 1, F: 20.26, I: 1, H: 1, K: 1, M: -6.54, L: 1, N: 1, Q: 20.26, P: 20.26, S: 20.26, R: -6.54, T: 1, W: -1.88, V: 20.26, Y: 1 },
|
|
76
|
+
S: { A: 1, C: 33.6, E: 20.26, D: 1, G: 1, F: 1, I: 1, H: 1, K: 1, M: 1, L: 1, N: 1, Q: 20.26, P: 44.94, S: 20.26, R: 20.26, T: 1, W: 1, V: 1, Y: 1 },
|
|
77
|
+
R: { A: 1, C: 1, E: 1, D: 1, G: -7.49, F: 1, I: 1, H: 20.26, K: 1, M: 1, L: 1, N: 13.34, Q: 20.26, P: 20.26, S: 44.94, R: 58.28, T: 1, W: 58.28, V: 1, Y: -6.54 },
|
|
78
|
+
T: { A: 1, C: 1, E: 20.26, D: 1, G: -7.49, F: 13.34, I: 1, H: 1, K: 1, M: 1, L: 1, N: -14.03, Q: -6.54, P: 1, S: 1, R: 1, T: 1, W: -14.03, V: 1, Y: 1 },
|
|
79
|
+
W: { A: -14.03, C: 1, E: 1, D: 1, G: -9.37, F: 1, I: 1, H: 24.68, K: 1, M: 24.68, L: 13.34, N: 13.34, Q: 1, P: 1, S: 1, R: 1, T: -14.03, W: 1, V: -7.49, Y: 1 },
|
|
80
|
+
V: { A: 1, C: 1, E: 1, D: -14.03, G: -7.49, F: 1, I: 1, H: 1, K: -1.88, M: 1, L: 1, N: 1, Q: 1, P: 20.26, S: 1, R: 1, T: -7.49, W: 1, V: 1, Y: -6.54 },
|
|
81
|
+
Y: { A: 24.68, C: 1, E: -6.54, D: 24.68, G: -7.49, F: 1, I: 1, H: 13.34, K: 1, M: 44.94, L: 1, N: 1, Q: 1, P: 13.34, S: 1, R: -15.91, T: -7.49, W: -9.37, V: 1, Y: 13.34 },
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** von Heijne 1986 aligned counts: 15 positions (-13..-1, +1, +2) plus Expect. */
|
|
85
|
+
export const SIGNAL_PEPTIDE_COUNTS = {
|
|
86
|
+
eukaryote: {
|
|
87
|
+
A: [16, 13, 14, 15, 20, 18, 18, 17, 25, 15, 47, 6, 80, 18, 6, 14.5],
|
|
88
|
+
C: [3, 6, 9, 7, 9, 14, 6, 8, 5, 6, 19, 3, 9, 8, 3, 4.5],
|
|
89
|
+
D: [0, 0, 0, 0, 0, 0, 0, 0, 5, 3, 0, 5, 0, 10, 11, 8.9],
|
|
90
|
+
E: [0, 0, 0, 1, 0, 0, 0, 0, 3, 7, 0, 7, 0, 13, 14, 10],
|
|
91
|
+
F: [13, 9, 11, 11, 6, 7, 18, 13, 4, 5, 0, 13, 0, 6, 4, 5.6],
|
|
92
|
+
G: [4, 4, 3, 6, 3, 13, 3, 2, 19, 34, 5, 7, 39, 10, 7, 12.1],
|
|
93
|
+
H: [0, 0, 0, 0, 0, 1, 1, 0, 5, 0, 0, 6, 0, 4, 2, 3.4],
|
|
94
|
+
I: [15, 15, 8, 6, 11, 5, 4, 8, 5, 1, 10, 5, 0, 8, 7, 7.4],
|
|
95
|
+
K: [0, 0, 0, 1, 0, 0, 1, 0, 0, 4, 0, 2, 0, 11, 9, 11.3],
|
|
96
|
+
L: [71, 68, 72, 79, 78, 45, 64, 49, 10, 23, 8, 20, 1, 8, 4, 12.1],
|
|
97
|
+
M: [0, 3, 7, 4, 1, 6, 2, 2, 0, 0, 0, 1, 0, 1, 2, 2.7],
|
|
98
|
+
N: [0, 1, 0, 1, 1, 0, 0, 0, 3, 3, 0, 10, 0, 4, 7, 7.1],
|
|
99
|
+
P: [2, 0, 2, 0, 0, 4, 1, 8, 20, 14, 0, 1, 3, 0, 22, 7.4],
|
|
100
|
+
Q: [0, 0, 0, 1, 0, 6, 1, 0, 10, 8, 0, 18, 3, 19, 10, 6.3],
|
|
101
|
+
R: [2, 0, 0, 0, 0, 1, 0, 0, 7, 4, 0, 15, 0, 12, 9, 7.6],
|
|
102
|
+
S: [9, 3, 8, 6, 13, 10, 15, 16, 26, 11, 23, 17, 20, 15, 10, 11.4],
|
|
103
|
+
T: [2, 10, 5, 4, 5, 13, 7, 7, 12, 6, 17, 8, 6, 3, 10, 9.7],
|
|
104
|
+
V: [20, 25, 15, 18, 13, 15, 11, 27, 0, 12, 32, 3, 0, 8, 17, 11.1],
|
|
105
|
+
W: [4, 3, 3, 1, 1, 2, 6, 3, 1, 3, 0, 9, 0, 2, 0, 1.8],
|
|
106
|
+
Y: [0, 1, 4, 0, 0, 1, 3, 1, 1, 2, 0, 5, 0, 1, 7, 5.6],
|
|
107
|
+
},
|
|
108
|
+
gram_negative: {
|
|
109
|
+
A: [10, 8, 8, 9, 6, 7, 5, 6, 7, 7, 24, 2, 31, 18, 4, 3.2],
|
|
110
|
+
C: [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1],
|
|
111
|
+
D: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 2],
|
|
112
|
+
E: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 8, 2.2],
|
|
113
|
+
F: [2, 4, 3, 4, 1, 1, 8, 0, 4, 1, 0, 7, 0, 1, 0, 1.3],
|
|
114
|
+
G: [4, 2, 2, 2, 3, 5, 2, 4, 2, 2, 0, 2, 2, 1, 0, 2.7],
|
|
115
|
+
H: [0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 7, 0, 1, 0, 0.8],
|
|
116
|
+
I: [3, 1, 5, 1, 5, 0, 1, 3, 0, 0, 0, 0, 0, 0, 2, 1.7],
|
|
117
|
+
K: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 2.5],
|
|
118
|
+
L: [8, 11, 9, 8, 9, 13, 1, 0, 2, 2, 1, 2, 0, 0, 1, 2.7],
|
|
119
|
+
M: [0, 2, 1, 1, 3, 2, 3, 0, 1, 2, 0, 4, 0, 0, 1, 0.6],
|
|
120
|
+
N: [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 3, 0, 1, 4, 1.6],
|
|
121
|
+
P: [0, 1, 1, 1, 1, 1, 2, 3, 5, 2, 0, 0, 0, 0, 5, 1.7],
|
|
122
|
+
Q: [0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 3, 0, 0, 1, 1.4],
|
|
123
|
+
R: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1.7],
|
|
124
|
+
S: [1, 0, 1, 4, 4, 1, 5, 15, 5, 8, 5, 2, 2, 0, 0, 2.6],
|
|
125
|
+
T: [2, 0, 4, 2, 2, 2, 2, 2, 5, 1, 3, 0, 1, 1, 2, 2.2],
|
|
126
|
+
V: [5, 7, 1, 3, 1, 4, 7, 0, 0, 4, 3, 0, 0, 2, 0, 2.5],
|
|
127
|
+
W: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0.4],
|
|
128
|
+
Y: [0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 0, 0, 0, 1.3],
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const SIGNAL_POSITIONS = [-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2];
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Position weights exactly as EMBOSS sigcleave derives them: log(count/expected),
|
|
136
|
+
* with a zero count replaced by 1.0 except at the -3 and -1 columns, where
|
|
137
|
+
* EMBOSS substitutes 1e-10 (those two columns define the cleavage site).
|
|
138
|
+
*/
|
|
139
|
+
function buildSignalWeights(counts) {
|
|
140
|
+
const weights = {};
|
|
141
|
+
for (const aa of AA20) {
|
|
142
|
+
const row = counts[aa];
|
|
143
|
+
if (!Array.isArray(row) || row.length !== 16) throw new Error(`signal-peptide table row ${aa} must hold 16 numbers`);
|
|
144
|
+
const expected = row[15];
|
|
145
|
+
if (!(expected > 0)) throw new Error(`signal-peptide table row ${aa} has a non-positive expectation`);
|
|
146
|
+
weights[aa] = row.slice(0, 15).map((count, col) => {
|
|
147
|
+
const value = count === 0 ? (col === 10 || col === 12 ? 1e-10 : 1) : count;
|
|
148
|
+
return Math.log(value / expected);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return weights;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const SIGNAL_WEIGHTS = {
|
|
155
|
+
eukaryote: buildSignalWeights(SIGNAL_PEPTIDE_COUNTS.eukaryote),
|
|
156
|
+
gram_negative: buildSignalWeights(SIGNAL_PEPTIDE_COUNTS.gram_negative),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// ── post-translational-modification motifs (#13) ────────────────────────────
|
|
160
|
+
|
|
161
|
+
const PTM_MOTIFS = [
|
|
162
|
+
{ type: 'N-glycosylation', motif: 'N-{P}-[S/T]', pattern: /N[^P][ST]/g, siteOffset: 0 },
|
|
163
|
+
{ type: 'C-mannosylation', motif: 'W-x-x-W', pattern: /W..W/g, siteOffset: 0 },
|
|
164
|
+
{ type: 'N-myristoylation', motif: 'N-terminal G-{EDRKHPFYW}-x-x-[STAGCN]-{P}', pattern: /^G[EDRKHPFYW]..[STAGCN][^P]/, siteOffset: 0, anchored: true },
|
|
165
|
+
{ type: 'SUMOylation', motif: '[LIVFM]-K-x-E', pattern: /[LIVFM]K.E/g, siteOffset: 1 },
|
|
166
|
+
{ type: 'PKA phosphorylation', motif: 'R-R-x-[S/T]', pattern: /RR.[ST]/g, siteOffset: 2 },
|
|
167
|
+
{ type: 'CK2 phosphorylation', motif: '[S/T]-x-x-[D/E]', pattern: /[ST]..[DE]/g, siteOffset: 0 },
|
|
168
|
+
{ type: 'proline-directed phosphorylation', motif: '[S/T]-P', pattern: /[ST]P/g, siteOffset: 0 },
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
function contextOf(sequence, index) {
|
|
172
|
+
const left = sequence.slice(Math.max(0, index - 3), index);
|
|
173
|
+
const right = sequence.slice(index + 1, index + 4);
|
|
174
|
+
return `${left}[${sequence[index]}]${right}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Shannon entropy (bits) of the residues in one window. */
|
|
178
|
+
function windowEntropy(window) {
|
|
179
|
+
const counts = new Map();
|
|
180
|
+
for (const aa of window) counts.set(aa, (counts.get(aa) ?? 0) + 1);
|
|
181
|
+
let entropy = 0;
|
|
182
|
+
for (const count of counts.values()) {
|
|
183
|
+
const p = count / window.length;
|
|
184
|
+
entropy -= p * Math.log2(p);
|
|
185
|
+
}
|
|
186
|
+
return entropy;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Guruprasad 1990 instability index; values above 40 indicate instability. */
|
|
190
|
+
function instabilityIndex(sequence) {
|
|
191
|
+
let total = 0;
|
|
192
|
+
for (let i = 0; i < sequence.length - 1; i++) total += DIWV[sequence[i]][sequence[i + 1]];
|
|
193
|
+
return (10 / sequence.length) * total;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* PTM motifs, SEG-style low-complexity regions and composition flags.
|
|
198
|
+
*
|
|
199
|
+
* The motifs are documented linear consensus patterns (ELM/Expasy), scanned
|
|
200
|
+
* against the one-letter sequence; low complexity is an entropy-window
|
|
201
|
+
* approximation of SEG, not SEG itself.
|
|
202
|
+
*/
|
|
203
|
+
export function scanProteinFeatures(rawSequence, options = {}) {
|
|
204
|
+
const sequence = normalizeProtein(rawSequence);
|
|
205
|
+
if (sequence.length > PROTEIN_ANNOTATE_LIMITS.maxSequenceLength) {
|
|
206
|
+
throw new MolbioInputError(`the protein is ${sequence.length} residues; the limit is ${PROTEIN_ANNOTATE_LIMITS.maxSequenceLength} per scan`);
|
|
207
|
+
}
|
|
208
|
+
const window = options.window ?? 12;
|
|
209
|
+
if (!Number.isInteger(window) || window < 4 || window > 50) throw new MolbioInputError('window must be an integer between 4 and 50 (12 is the SEG-style default)');
|
|
210
|
+
const entropyThreshold = options.entropyThreshold ?? 2.2;
|
|
211
|
+
if (!(typeof entropyThreshold === 'number') || entropyThreshold < 0 || entropyThreshold > 4.5) throw new MolbioInputError('entropy_threshold must be a number between 0 and 4.5 bits (2.2 is the SEG-style default)');
|
|
212
|
+
const maxSites = options.maxSites ?? 200;
|
|
213
|
+
if (!Number.isInteger(maxSites) || maxSites < 1 || maxSites > 2000) throw new MolbioInputError('max_sites must be an integer between 1 and 2000');
|
|
214
|
+
|
|
215
|
+
const sites = [];
|
|
216
|
+
const seen = new Set();
|
|
217
|
+
for (const motif of PTM_MOTIFS) {
|
|
218
|
+
if (motif.anchored) {
|
|
219
|
+
const match = motif.pattern.exec(sequence);
|
|
220
|
+
if (match === null) continue;
|
|
221
|
+
const index = match.index + motif.siteOffset;
|
|
222
|
+
const key = `${motif.type}:${index}`;
|
|
223
|
+
if (seen.has(key)) continue;
|
|
224
|
+
seen.add(key);
|
|
225
|
+
sites.push({ type: motif.type, motif: motif.motif, position: index + 1, context: contextOf(sequence, index) });
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const pattern = new RegExp(motif.pattern.source, motif.pattern.flags);
|
|
229
|
+
let match;
|
|
230
|
+
while ((match = pattern.exec(sequence)) !== null) {
|
|
231
|
+
const index = match.index + motif.siteOffset;
|
|
232
|
+
const key = `${motif.type}:${index}`;
|
|
233
|
+
if (seen.has(key)) continue;
|
|
234
|
+
seen.add(key);
|
|
235
|
+
sites.push({ type: motif.type, motif: motif.motif, position: index + 1, context: contextOf(sequence, index) });
|
|
236
|
+
if (pattern.lastIndex === match.index) pattern.lastIndex++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
sites.sort((a, b) => a.position - b.position || a.type.localeCompare(b.type));
|
|
240
|
+
const truncated = sites.length > maxSites;
|
|
241
|
+
const kept = truncated ? sites.slice(0, maxSites) : sites;
|
|
242
|
+
|
|
243
|
+
const regions = [];
|
|
244
|
+
if (sequence.length >= window) {
|
|
245
|
+
let current = null;
|
|
246
|
+
let minWindowEntropy = Infinity;
|
|
247
|
+
for (let start = 0; start + window <= sequence.length; start++) {
|
|
248
|
+
const entropy = windowEntropy(sequence.slice(start, start + window));
|
|
249
|
+
if (entropy < entropyThreshold) {
|
|
250
|
+
if (current === null) {
|
|
251
|
+
current = { start: start + 1, end: start + window };
|
|
252
|
+
minWindowEntropy = entropy;
|
|
253
|
+
} else {
|
|
254
|
+
current.end = start + window;
|
|
255
|
+
minWindowEntropy = Math.min(minWindowEntropy, entropy);
|
|
256
|
+
}
|
|
257
|
+
} else if (current !== null) {
|
|
258
|
+
regions.push({ ...current, min_window_entropy: round3(minWindowEntropy), entropy: round3(windowEntropy(sequence.slice(current.start - 1, current.end))) });
|
|
259
|
+
current = null;
|
|
260
|
+
minWindowEntropy = Infinity;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (current !== null) regions.push({ ...current, min_window_entropy: round3(minWindowEntropy), entropy: round3(windowEntropy(sequence.slice(current.start - 1, current.end))) });
|
|
264
|
+
}
|
|
265
|
+
const regionsTruncated = regions.length > 100;
|
|
266
|
+
const keptRegions = (regionsTruncated ? regions.slice(0, 100) : regions).map((region) => ({ ...region, length: region.end - region.start + 1 }));
|
|
267
|
+
|
|
268
|
+
let aromatic = 0;
|
|
269
|
+
for (const aa of sequence) if (aa === 'F' || aa === 'W' || aa === 'Y') aromatic++;
|
|
270
|
+
const index = instabilityIndex(sequence);
|
|
271
|
+
|
|
272
|
+
const notes = [
|
|
273
|
+
'PTM motifs are linear consensus patterns; a motif match does not prove the site is modified in vivo.',
|
|
274
|
+
'Low complexity is an entropy-window approximation of SEG (not SEG); regions are where a window drops below the threshold.',
|
|
275
|
+
'Instability index follows Guruprasad 1990 (DIWV table): above 40 is conventionally read as unstable.',
|
|
276
|
+
];
|
|
277
|
+
if (sequence.length < window) notes.push(`the protein is shorter than the low-complexity window (${window}), so no low-complexity region was scanned`);
|
|
278
|
+
if (truncated) notes.push(`more than ${maxSites} PTM sites were found; the list is truncated at ${maxSites}`);
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
length: sequence.length,
|
|
282
|
+
ptm_sites: kept,
|
|
283
|
+
low_complexity_regions: keptRegions,
|
|
284
|
+
composition: {
|
|
285
|
+
aromaticity: round3(aromatic / sequence.length),
|
|
286
|
+
instability_index: round2(index),
|
|
287
|
+
instability_class: index > 40 ? 'unstable' : 'stable',
|
|
288
|
+
},
|
|
289
|
+
window,
|
|
290
|
+
entropy_threshold: entropyThreshold,
|
|
291
|
+
truncated: truncated || regionsTruncated,
|
|
292
|
+
notes,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ── signal peptide + transmembrane segments (#21) ───────────────────────────
|
|
297
|
+
|
|
298
|
+
export const SIGNAL_PEPTIDE_DEFAULTS = {
|
|
299
|
+
organism: 'eukaryote',
|
|
300
|
+
threshold: 3.5,
|
|
301
|
+
tmWindow: 19,
|
|
302
|
+
tmThreshold: HYDROPATHY_DEFAULTS.threshold,
|
|
303
|
+
maxCleavage: 50,
|
|
304
|
+
maxCandidates: 10,
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/** Score one candidate cleavage position (0-based index of the +1 residue). */
|
|
308
|
+
function signalScore(sequence, cleavage, weights) {
|
|
309
|
+
let score = 0;
|
|
310
|
+
for (let col = 0; col < SIGNAL_POSITIONS.length; col++) {
|
|
311
|
+
score += weights[sequence[cleavage - 13 + col]][col];
|
|
312
|
+
}
|
|
313
|
+
return score;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* von Heijne 1986 signal-peptide cleavage score plus Kyte-Doolittle candidate
|
|
318
|
+
* transmembrane segments.
|
|
319
|
+
*
|
|
320
|
+
* A candidate cleavage after residue k uses the fixed -13..+2 window; the
|
|
321
|
+
* score is the sum of the position weights. The TM segments are the SAME runs
|
|
322
|
+
* `molbio_hydropathy_plot` reports as peaks, with the same window and threshold
|
|
323
|
+
* defaults, so the two tools cannot disagree.
|
|
324
|
+
*/
|
|
325
|
+
export function signalPeptideAnalysis(rawSequence, options = {}) {
|
|
326
|
+
const sequence = normalizeProtein(rawSequence);
|
|
327
|
+
if (sequence.length > PROTEIN_ANNOTATE_LIMITS.maxSequenceLength) {
|
|
328
|
+
throw new MolbioInputError(`the protein is ${sequence.length} residues; the limit is ${PROTEIN_ANNOTATE_LIMITS.maxSequenceLength} per scan`);
|
|
329
|
+
}
|
|
330
|
+
if (sequence.length < 15) throw new MolbioInputError('a signal-peptide score needs at least 15 residues (the -13..+2 window)');
|
|
331
|
+
const organism = options.organism ?? SIGNAL_PEPTIDE_DEFAULTS.organism;
|
|
332
|
+
if (!(organism in SIGNAL_WEIGHTS)) throw new MolbioInputError('organism must be eukaryote or gram_negative');
|
|
333
|
+
const maxCleavage = options.maxCleavage ?? SIGNAL_PEPTIDE_DEFAULTS.maxCleavage;
|
|
334
|
+
if (!Number.isInteger(maxCleavage) || maxCleavage < 15 || maxCleavage > 200) throw new MolbioInputError('max_cleavage must be an integer between 15 and 200 (signal peptides are N-terminal; the default scans the first 50 residues)');
|
|
335
|
+
const threshold = options.threshold ?? SIGNAL_PEPTIDE_DEFAULTS.threshold;
|
|
336
|
+
if (!(typeof threshold === 'number') || threshold < -20 || threshold > 20) throw new MolbioInputError('threshold must be a number between -20 and 20 (the default 3.5 is the EMBOSS sigcleave minweight)');
|
|
337
|
+
const tmWindow = options.tmWindow ?? SIGNAL_PEPTIDE_DEFAULTS.tmWindow;
|
|
338
|
+
if (!Number.isInteger(tmWindow) || tmWindow < 3 || tmWindow > 51) throw new MolbioInputError('tm_window must be an integer between 3 and 51 (19 centres a transmembrane window)');
|
|
339
|
+
const tmThreshold = options.tmThreshold ?? SIGNAL_PEPTIDE_DEFAULTS.tmThreshold;
|
|
340
|
+
if (!(typeof tmThreshold === 'number') || tmThreshold < -4.5 || tmThreshold > 4.5) throw new MolbioInputError('tm_threshold must be a number between -4.5 and 4.5 (the Kyte-Doolittle range)');
|
|
341
|
+
|
|
342
|
+
const weights = SIGNAL_WEIGHTS[organism];
|
|
343
|
+
const profile = [];
|
|
344
|
+
const lastCleavage = Math.min(sequence.length - 2, maxCleavage);
|
|
345
|
+
for (let cleavage = 13; cleavage <= lastCleavage; cleavage++) {
|
|
346
|
+
profile.push({ cleavage_after: cleavage, score: round3(signalScore(sequence, cleavage, weights)) });
|
|
347
|
+
}
|
|
348
|
+
let best = null;
|
|
349
|
+
for (const point of profile) if (best === null || point.score > best.score) best = point;
|
|
350
|
+
const cleavable = best !== null && best.score > threshold;
|
|
351
|
+
const candidates = profile
|
|
352
|
+
.filter((point) => point.score > threshold)
|
|
353
|
+
.sort((a, b) => b.score - a.score || a.cleavage_after - b.cleavage_after)
|
|
354
|
+
.slice(0, SIGNAL_PEPTIDE_DEFAULTS.maxCandidates)
|
|
355
|
+
.map((point) => ({ cleavage_after: point.cleavage_after, score: point.score }));
|
|
356
|
+
|
|
357
|
+
const hydropathy = hydropathyProfile(sequence, { window: tmWindow, threshold: tmThreshold });
|
|
358
|
+
const transmembrane = hydropathy.peaks.map((peak) => ({
|
|
359
|
+
start: peak.start,
|
|
360
|
+
end: peak.end,
|
|
361
|
+
length: peak.length,
|
|
362
|
+
mean_hydropathy: peak.maximum,
|
|
363
|
+
peak_position: peak.maximum_position,
|
|
364
|
+
}));
|
|
365
|
+
|
|
366
|
+
const notes = [
|
|
367
|
+
'Signal-peptide scores are von Heijne 1986 position weights (EMBOSS sigcleave table); a score above the threshold is a candidate, not a SignalP prediction.',
|
|
368
|
+
'Transmembrane segments are the same Kyte-Doolittle runs molbio_hydropathy_plot reports as peaks (same window and threshold); topology and orientation are NOT predicted.',
|
|
369
|
+
];
|
|
370
|
+
if (transmembrane.some((segment) => cleavable && segment.start <= best.cleavage_after)) {
|
|
371
|
+
notes.push('a candidate transmembrane segment overlaps the candidate signal peptide; a signal peptide is also hydrophobic, so this alone does not mean two features');
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return {
|
|
375
|
+
length: sequence.length,
|
|
376
|
+
organism,
|
|
377
|
+
threshold,
|
|
378
|
+
cleavable,
|
|
379
|
+
best_score: best === null ? 0 : best.score,
|
|
380
|
+
cleavage_after: cleavable ? best.cleavage_after : 0,
|
|
381
|
+
scanned_to: lastCleavage,
|
|
382
|
+
window_start: cleavable ? best.cleavage_after - 12 : 0,
|
|
383
|
+
window_end: cleavable ? best.cleavage_after + 2 : 0,
|
|
384
|
+
signal_peptide: cleavable ? sequence.slice(0, best.cleavage_after) : '',
|
|
385
|
+
mature_sequence: cleavable ? sequence.slice(best.cleavage_after) : sequence,
|
|
386
|
+
candidates,
|
|
387
|
+
transmembrane_segments: transmembrane,
|
|
388
|
+
tm_window: tmWindow,
|
|
389
|
+
tm_threshold: tmThreshold,
|
|
390
|
+
notes,
|
|
391
|
+
profile,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Draw the signal-peptide score profile as a standalone SVG. */
|
|
396
|
+
export function renderSignalPeptideProfile(analysis, { title } = {}) {
|
|
397
|
+
const width = 820;
|
|
398
|
+
const height = 280;
|
|
399
|
+
const margin = { top: 52, right: 24, bottom: 44, left: 58 };
|
|
400
|
+
const plotWidth = width - margin.left - margin.right;
|
|
401
|
+
const plotHeight = height - margin.top - margin.bottom;
|
|
402
|
+
const points = analysis.profile;
|
|
403
|
+
const scores = points.map((p) => p.score);
|
|
404
|
+
const maxScore = Math.max(analysis.threshold, ...scores);
|
|
405
|
+
const minScore = Math.min(0, ...scores);
|
|
406
|
+
const xOf = (cleavage) => margin.left + ((cleavage - points[0].cleavage_after) / Math.max(1, points[points.length - 1].cleavage_after - points[0].cleavage_after)) * plotWidth;
|
|
407
|
+
const yOf = (score) => margin.top + plotHeight - ((score - minScore) / (maxScore - minScore || 1)) * plotHeight;
|
|
408
|
+
const body = [];
|
|
409
|
+
body.push(`<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff"/>`);
|
|
410
|
+
body.push(textRun({ x: margin.left, y: 24, text: title ?? 'Signal-peptide cleavage score', size: 15, weight: 'bold' }));
|
|
411
|
+
body.push(textRun({ x: margin.left, y: 41, text: `${analysis.length} aa · ${analysis.organism} · threshold ${analysis.threshold}`, size: 10, fill: '#57606a' }));
|
|
412
|
+
body.push(line({ x1: margin.left, y1: margin.top, x2: margin.left, y2: margin.top + plotHeight, stroke: '#8c959f' }));
|
|
413
|
+
body.push(line({ x1: margin.left, y1: margin.top + plotHeight, x2: margin.left + plotWidth, y2: margin.top + plotHeight, stroke: '#8c959f' }));
|
|
414
|
+
for (let i = 0; i <= 4; i++) {
|
|
415
|
+
const value = minScore + ((maxScore - minScore) * i) / 4;
|
|
416
|
+
const y = yOf(value);
|
|
417
|
+
body.push(line({ x1: margin.left - 4, y1: y, x2: margin.left, y2: y, stroke: '#8c959f' }));
|
|
418
|
+
body.push(textRun({ x: margin.left - 8, y: y + 3, text: round(value, 2).toFixed(2), size: 9, fill: '#57606a', anchor: 'end' }));
|
|
419
|
+
}
|
|
420
|
+
const thresholdY = yOf(analysis.threshold);
|
|
421
|
+
body.push(line({ x1: margin.left, y1: thresholdY, x2: margin.left + plotWidth, y2: thresholdY, stroke: '#cf222e', width: 1, dash: [5, 4] }));
|
|
422
|
+
body.push(textRun({ x: margin.left + plotWidth, y: thresholdY - 5, text: `threshold ${analysis.threshold}`, size: 9, fill: '#cf222e', anchor: 'end' }));
|
|
423
|
+
body.push(polyline(points.map((p) => [round(xOf(p.cleavage_after), 2), round(yOf(p.score), 2)]), { stroke: '#0969da', width: 1.6 }));
|
|
424
|
+
if (analysis.cleavable) {
|
|
425
|
+
const x = xOf(analysis.cleavage_after);
|
|
426
|
+
const y = yOf(analysis.best_score);
|
|
427
|
+
body.push(circle({ cx: round(x, 2), cy: round(y, 2), r: 4, fill: '#cf222e', stroke: '#ffffff', strokeWidth: 1 }));
|
|
428
|
+
body.push(textRun({ x: round(x, 2), y: round(y - 10, 2), text: `cleavage after ${analysis.cleavage_after}`, size: 10, fill: '#cf222e', anchor: 'middle' }));
|
|
429
|
+
}
|
|
430
|
+
body.push(textRun({ x: margin.left + plotWidth / 2, y: height - 12, text: 'candidate cleavage position (residues in the signal peptide)', size: 10, fill: '#57606a', anchor: 'middle' }));
|
|
431
|
+
return svgDocument({
|
|
432
|
+
width,
|
|
433
|
+
height,
|
|
434
|
+
title: `Signal-peptide score profile (${analysis.organism}, threshold ${analysis.threshold})`,
|
|
435
|
+
description: analysis.cleavable ? `Best candidate cleavage after residue ${analysis.cleavage_after} with score ${analysis.best_score}` : 'No candidate exceeded the threshold',
|
|
436
|
+
body: body.join(''),
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// ── antigenic propensity (#14) ──────────────────────────────────────────────
|
|
441
|
+
|
|
442
|
+
export const ANTIGENICITY_DEFAULTS = { window: 7, minRegionLength: 6, maxRegions: 20 };
|
|
443
|
+
|
|
444
|
+
function meanScale(sequence, scale) {
|
|
445
|
+
let total = 0;
|
|
446
|
+
for (const aa of sequence) total += scale[aa];
|
|
447
|
+
return total / sequence.length;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Kolaskar-Tongaonkar antigenic propensity with the three scales the method was
|
|
452
|
+
* derived from (Parker hydrophilicity, Emini accessibility, Vihinen flexibility).
|
|
453
|
+
*
|
|
454
|
+
* The 7-mer <A(p)> is assigned to the central residue; a residue is selected when
|
|
455
|
+
* its <A(p)> reaches the protein mean (or 1.0 when the mean is at least 1.0), and
|
|
456
|
+
* a region is reported when at least `minRegionLength` consecutive residues are
|
|
457
|
+
* selected. This is a propensity ranking, not an epitope predictor.
|
|
458
|
+
*/
|
|
459
|
+
export function antigenicityProfile(rawSequence, options = {}) {
|
|
460
|
+
const sequence = normalizeProtein(rawSequence);
|
|
461
|
+
if (sequence.length > PROTEIN_ANNOTATE_LIMITS.maxSequenceLength) {
|
|
462
|
+
throw new MolbioInputError(`the protein is ${sequence.length} residues; the limit is ${PROTEIN_ANNOTATE_LIMITS.maxSequenceLength} per scan`);
|
|
463
|
+
}
|
|
464
|
+
if (sequence.length < 8) throw new MolbioInputError('antigenic propensity needs at least 8 residues (one centred 7-mer)');
|
|
465
|
+
const minRegionLength = options.minRegionLength ?? ANTIGENICITY_DEFAULTS.minRegionLength;
|
|
466
|
+
if (!Number.isInteger(minRegionLength) || minRegionLength < 1 || minRegionLength > 100) throw new MolbioInputError('min_region_length must be an integer between 1 and 100 (6 is the Kolaskar-Tongaonkar convention)');
|
|
467
|
+
const maxRegions = options.maxRegions ?? ANTIGENICITY_DEFAULTS.maxRegions;
|
|
468
|
+
if (!Number.isInteger(maxRegions) || maxRegions < 1 || maxRegions > 200) throw new MolbioInputError('max_regions must be an integer between 1 and 200');
|
|
469
|
+
|
|
470
|
+
const meanPropensity = meanScale(sequence, ANTIGENIC_PROPENSITY);
|
|
471
|
+
const threshold = meanPropensity < 1 ? meanPropensity : 1;
|
|
472
|
+
const centres = [];
|
|
473
|
+
for (let centre = 3; centre <= sequence.length - 4; centre++) {
|
|
474
|
+
let total = 0;
|
|
475
|
+
for (let k = centre - 3; k <= centre + 3; k++) total += ANTIGENIC_PROPENSITY[sequence[k]];
|
|
476
|
+
centres.push({ position: centre + 1, propensity: total / 7 });
|
|
477
|
+
}
|
|
478
|
+
const selected = centres.filter((point) => point.propensity >= threshold);
|
|
479
|
+
const regions = [];
|
|
480
|
+
let run = [];
|
|
481
|
+
const flush = () => {
|
|
482
|
+
if (run.length < minRegionLength) { run = []; return; }
|
|
483
|
+
const start = run[0].position;
|
|
484
|
+
const end = run[run.length - 1].position;
|
|
485
|
+
const peptide = sequence.slice(start - 1, end);
|
|
486
|
+
let peak = run[0];
|
|
487
|
+
for (const point of run) if (point.propensity > peak.propensity) peak = point;
|
|
488
|
+
regions.push({
|
|
489
|
+
start,
|
|
490
|
+
end,
|
|
491
|
+
length: end - start + 1,
|
|
492
|
+
peak_position: peak.position,
|
|
493
|
+
peak_propensity: round3(peak.propensity),
|
|
494
|
+
parker_mean: round3(meanScale(peptide, PARKER_HYDROPHILICITY)),
|
|
495
|
+
emini_mean: round3(meanScale(peptide, EMINI_ACCESSIBILITY)),
|
|
496
|
+
flexibility_mean: round3(meanScale(peptide, VIHINEN_FLEXIBILITY)),
|
|
497
|
+
});
|
|
498
|
+
run = [];
|
|
499
|
+
};
|
|
500
|
+
for (const point of centres) {
|
|
501
|
+
if (point.propensity >= threshold) run.push(point);
|
|
502
|
+
else if (run.length > 0) flush();
|
|
503
|
+
}
|
|
504
|
+
if (run.length > 0) flush();
|
|
505
|
+
regions.sort((a, b) => b.peak_propensity - a.peak_propensity);
|
|
506
|
+
const truncated = regions.length > maxRegions;
|
|
507
|
+
const kept = (truncated ? regions.slice(0, maxRegions) : regions).sort((a, b) => a.start - b.start);
|
|
508
|
+
|
|
509
|
+
return {
|
|
510
|
+
length: sequence.length,
|
|
511
|
+
window: ANTIGENICITY_DEFAULTS.window,
|
|
512
|
+
mean_propensity: round3(meanPropensity),
|
|
513
|
+
threshold: round3(threshold),
|
|
514
|
+
regions: kept,
|
|
515
|
+
parker_mean: round3(meanScale(sequence, PARKER_HYDROPHILICITY)),
|
|
516
|
+
emini_mean: round3(meanScale(sequence, EMINI_ACCESSIBILITY)),
|
|
517
|
+
flexibility_mean: round3(meanScale(sequence, VIHINEN_FLEXIBILITY)),
|
|
518
|
+
truncated,
|
|
519
|
+
notes: [
|
|
520
|
+
'Antigenic propensity is the Kolaskar & Tongaonkar 1990 7-mer method, not an epitope predictor; BepiPred/NetMHC-style scores are trained models with different semantics.',
|
|
521
|
+
'Regions are runs of residues whose <A(p)> reaches the protein mean (or 1.0 when that mean is at least 1.0); the flanking 3 residues of each 7-mer are not part of the reported span.',
|
|
522
|
+
'Parker hydrophilicity, Emini accessibility and Vihinen flexibility are reported as region means to help read the propensity; they are not combined into a single score.',
|
|
523
|
+
],
|
|
524
|
+
};
|
|
525
|
+
}
|