nx_peptide_isotope_test.nx source
↩ module page · 141 lines · 8292 B
1// nx_peptide_isotope_test.nx -- gate for the isotopic-envelope rung, liar-
2// killed against the textbook per-carbon law and published peptide envelopes.
3// T2 is the triangulation: the computed M+1 must match the independent
4// "1.08% per carbon" empirical constant. T6 is the SOTA payoff: a large
5// peptide's base peak is NOT the monoisotopic peak.
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_peptide.nx"
9import "nx_peptide_formula.nx"
10import "nx_peptide_isotope.nx"
11
12func t_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
13func t_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 }
14
15func main() -> i64 {
16 var pass: i64 = 0
17 var total: i64 = 0
18
19 let ang: *u8 = "DRVYIHPF" as *u8 // C50H71N13O12
20
21 // --- T1 ANGIOTENSIN II M+1 == published ~60% (601 permil) ---
22 total = total + 1
23 let m1: i64 = iso_m1_permil(ang)
24 t_puts("T1 angiotensin II M+1/M = " as *u8); t_putn(m1); t_puts(" permil, published ~600 (band 580..620): " as *u8)
25 var ok1: i64 = 1
26 if m1 < 580 { ok1 = 0 }
27 if m1 > 620 { ok1 = 0 }
28 if ok1 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
29
30 // --- T2 LIAR-KILL: computed M+1 matches the INDEPENDENT per-carbon law
31 // (10.8 permil/C over 50 C = 540) within the small N/H/O addition ---
32 total = total + 1
33 let carbon_only: i64 = iso_carbon_rule_permil(50)
34 let per_c: i64 = iso_m1_per_carbon(ang)
35 var d2: i64 = m1 - carbon_only
36 t_puts("T2 carbon-only rule=" as *u8); t_putn(carbon_only); t_puts(" full M+1=" as *u8); t_putn(m1); t_puts(" (carbon dominates, delta " as *u8); t_putn(d2); t_puts(" from N/H/O) per-carbon=" as *u8); t_putn(per_c); t_puts(" (x100, ~1200): " as *u8)
37 var ok2: i64 = 1
38 if m1 <= carbon_only { ok2 = 0 } // full must exceed carbon-only
39 if d2 > 80 { ok2 = 0 } // but only by the modest N/H/O term
40 if per_c < 1150 { ok2 = 0 } // ~12.0 permil/carbon incl N/H/O
41 if per_c > 1250 { ok2 = 0 }
42 if ok2 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
43
44 // --- T3 M+2 is dominated by the 13C-PAIR combinatorial term ---
45 // For C50 the 13C2 term is ~143 permil, far above the 18O ~25 permil.
46 total = total + 1
47 let m2: i64 = iso_m2_permil(ang)
48 t_puts("T3 angiotensin M+2/M = " as *u8); t_putn(m2); t_puts(" permil, published ~170 (band 150..190): " as *u8)
49 var ok3: i64 = 1
50 if m2 < 150 { ok3 = 0 }
51 if m2 > 190 { ok3 = 0 }
52 if ok3 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
53
54 // --- T4 the envelope descends for a SMALL peptide: M > M+1 > M+2,
55 // so the monoisotopic peak IS the base peak ---
56 total = total + 1
57 let small: *u8 = "GG" as *u8 // tiny, few carbons
58 let s_m1: i64 = iso_m1_permil(small)
59 let s_m2: i64 = iso_m2_permil(small)
60 let s_base: i64 = iso_base_peak(small)
61 let s_mono: i64 = iso_monoisotopic_is_base_peak(small)
62 t_puts("T4 GG: M+1=" as *u8); t_putn(s_m1); t_puts(" M+2=" as *u8); t_putn(s_m2); t_puts(" base_peak=" as *u8); t_putn(s_base); t_puts(" mono-is-base=" as *u8); t_putn(s_mono); t_puts(" want 0/1: " as *u8)
63 var ok4: i64 = 1
64 if s_m1 >= 1000 { ok4 = 0 }
65 if s_m2 >= s_m1 { ok4 = 0 }
66 if s_base != 0 { ok4 = 0 }
67 if s_mono != 1 { ok4 = 0 }
68 if ok4 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
69
70 // --- T5 SULFUR SIGNATURE: adding Met/Cys lifts M+2 via 34S (4.47%/S).
71 // Two peptides of similar size, one sulfur-bearing, must differ
72 // in M+2 -- the isotope pattern distinguishes them. ---
73 total = total + 1
74 let nosulf: i64 = iso_m2_permil("AAAAAA" as *u8)
75 let sulf: i64 = iso_m2_permil("AAAMCA" as *u8) // + Met + Cys = 2 S
76 let bump: i64 = sulf - nosulf
77 t_puts("T5 M+2 no-sulfur=" as *u8); t_putn(nosulf); t_puts(" +2 sulfur=" as *u8); t_putn(sulf); t_puts(" 34S bump=" as *u8); t_putn(bump); t_puts(" (2*44.7=~89 permil): " as *u8)
78 var ok5: i64 = 1
79 if bump < 80 { ok5 = 0 }
80 if bump > 100 { ok5 = 0 }
81 if ok5 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
82
83 // --- T6 THE SOTA PAYOFF: a LARGE peptide's base peak is NOT the
84 // monoisotopic peak -- a nominal-mass method silently gets the
85 // reported mass wrong ---
86 total = total + 1
87 // ~100-carbon peptide: 10 x a carbon-rich decamer. WYFWYFWYFW repeated.
88 let big: *u8 = "WYFWYFWYFWWYFWYFWYFW" as *u8 // Trp/Tyr/Phe rich, ~180 C
89 let b_m1: i64 = iso_m1_permil(big)
90 let b_base: i64 = iso_base_peak(big)
91 let b_mono: i64 = iso_monoisotopic_is_base_peak(big)
92 let bf: *NxFormula = pfm_formula(big)
93 t_puts("T6 20-mer (C" as *u8); t_putn(bf.c); t_puts("): M+1=" as *u8); t_putn(b_m1); t_puts(" permil (>1000 = M+1 taller than mono!) base_peak=" as *u8); t_putn(b_base); t_puts(" mono-is-base=" as *u8); t_putn(b_mono); t_puts(": " as *u8)
94 var ok6: i64 = 1
95 if b_m1 <= 1000 { ok6 = 0 } // M+1 exceeds the monoisotopic peak
96 if b_base == 0 { ok6 = 0 } // base peak is NOT monoisotopic
97 if b_mono != 0 { ok6 = 0 }
98 if ok6 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
99
100 // --- T7 M+1 grows MONOTONICALLY with carbon count (physical sanity) ---
101 total = total + 1
102 let mono1: i64 = iso_m1_permil("W" as *u8)
103 let mono2: i64 = iso_m1_permil("WW" as *u8)
104 let mono4: i64 = iso_m1_permil("WWWW" as *u8)
105 t_puts("T7 M+1 for W/WW/WWWW = " as *u8); t_putn(mono1); t_puts("/" as *u8); t_putn(mono2); t_puts("/" as *u8); t_putn(mono4); t_puts(" (increasing): " as *u8)
106 var ok7: i64 = 1
107 if mono2 <= mono1 { ok7 = 0 }
108 if mono4 <= mono2 { ok7 = 0 }
109 if ok7 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
110
111 // --- T8 fail-closed: a non-standard residue refuses in all envelope fns ---
112 total = total + 1
113 let bm1: i64 = iso_m1_permil("DRVYIHPZ" as *u8)
114 let bm2: i64 = iso_m2_permil("DRVYIHPZ" as *u8)
115 let bbp: i64 = iso_base_peak("DRVYIHPZ" as *u8)
116 t_puts("T8 bad residue: M+1=" as *u8); t_putn(bm1); t_puts(" M+2=" as *u8); t_putn(bm2); t_puts(" base=" as *u8); t_putn(bbp); t_puts(" want all -1: " as *u8)
117 var ok8: i64 = 1
118 if bm1 != PEP_INVALID { ok8 = 0 }
119 if bm2 != PEP_INVALID { ok8 = 0 }
120 if bbp != PEP_INVALID { ok8 = 0 }
121 if ok8 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
122
123 // --- T9 bradykinin (C50H73N15O11) M+1 also ~60%, cross-anchored ---
124 total = total + 1
125 let bk_m1: i64 = iso_m1_permil("RPPGFSPFR" as *u8)
126 t_puts("T9 bradykinin M+1/M = " as *u8); t_putn(bk_m1); t_puts(" permil (~600, band 580..620): " as *u8)
127 if bk_m1 >= 580 { if bk_m1 <= 620 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) }
128
129 // --- T10 the base-peak crossover happens near ~90 carbons, as theory
130 // predicts (M+1 = M when 1.08%/C * nC = 100%) ---
131 total = total + 1
132 // 15 Trp = C165; M+1 should exceed 1000. 8 Gly = C16; M+1 far below.
133 let cross_hi: i64 = iso_monoisotopic_is_base_peak("WWWWWWWWWWWWWWW" as *u8)
134 let cross_lo: i64 = iso_monoisotopic_is_base_peak("GGGGGGGG" as *u8)
135 t_puts("T10 mono-is-base: 15xTrp(C165)=" as *u8); t_putn(cross_hi); t_puts(" 8xGly(C16)=" as *u8); t_putn(cross_lo); t_puts(" want 0/1 (crossover between): " as *u8)
136 if cross_hi == 0 { if cross_lo == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) }
137
138 t_puts("PEPTIDE-ISOTOPE-GATE passed " as *u8); t_putn(pass); t_puts("/" as *u8); t_putn(total)
139 if pass == total { t_puts(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
140 t_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1
141}