code wiki / (root) / nx_peptide_chain_test.nx

nx_peptide_chain_test.nx source

↩ module page · 161 lines · 8791 B

1// nx_peptide_chain_test.nx -- gate for nx_peptide_chain. The anchor is human 2// insulin against its published monoisotopic mass 5803.6375 Da, which is only 3// reachable with BOTH chains (two waters, not one) and ALL THREE disulfides. 4// T3 runs the no-bridge and single-sequence variants as negative controls. 5// expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_peptide.nx" 8import "nx_peptide_ext.nx" 9import "nx_peptide_chain.nx" 10 11func 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 } 12func 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 } 13 14// Human insulin: A chain 21 residues, B chain 30, three disulfides -- 15// A6-A11 intra-chain, plus A7-B7 and A20-B19 between the chains. 16func build_insulin() -> *NxPepAssembly { 17 let a: *NxPepAssembly = nx_pep_assembly_new() 18 pca_add_chain_seq(a, "GIVEQCCTSICSLYQLENYCN" as *u8) 19 pca_add_chain_seq(a, "FVNQHLCGSHLVEALYLVCGERGFFYTPKT" as *u8) 20 pca_add_intra_disulfide(a) 21 pca_add_inter_disulfide(a) 22 pca_add_inter_disulfide(a) 23 return a 24} 25 26func main() -> i64 { 27 var pass: i64 = 0 28 var total: i64 = 0 29 30 let ins: *NxPepAssembly = build_insulin() 31 32 // --- T1 HUMAN INSULIN vs published 5803.6375 Da --- 33 total = total + 1 34 let m: i64 = pca_mass_q4(ins) 35 t_puts("T1 human insulin Q4=" as *u8); t_putn(m); t_puts(" vs lit 58036375, tol 30 (51 residues): " as *u8) 36 if pep_mass_agrees(m, 58036375, 30) == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 37 38 // --- T2 the cysteine budget closes EXACTLY: 6 Cys, 3 bridges, 0 free --- 39 total = total + 1 40 let ncys: i64 = ins.n_cys 41 let nss: i64 = pca_total_ss(ins) 42 let free: i64 = pca_free_cys(ins) 43 t_puts("T2 insulin cysteines=" as *u8); t_putn(ncys); t_puts(" bridges=" as *u8); t_putn(nss); t_puts(" free Cys=" as *u8); t_putn(free); t_puts(" want 6/3/0: " as *u8) 44 var ok2: i64 = 1 45 if ncys != 6 { ok2 = 0 } 46 if nss != 3 { ok2 = 0 } 47 if free != 0 { ok2 = 0 } 48 if ok2 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 49 50 // --- T3 NEGATIVE CONTROLS: the reduced form and the naive one-chain 51 // concatenation must BOTH miss the published mass --- 52 total = total + 1 53 let red: i64 = pca_mass_reduced_q4(ins) 54 let bridge_delta: i64 = red - m 55 let naive: i64 = pep_mass_mono_q4("GIVEQCCTSICSLYQLENYCNFVNQHLCGSHLVEALYLVCGERGFFYTPKT" as *u8) 56 let water_short: i64 = red - naive 57 t_puts("T3 reduced=" as *u8); t_putn(red); t_puts(" (bridges worth " as *u8); t_putn(bridge_delta); t_puts(") one-chain concat=" as *u8); t_putn(naive); t_puts(" (short by " as *u8); t_putn(water_short); t_puts(" = one water): " as *u8) 58 var ok3: i64 = 1 59 if bridge_delta != 60471 { ok3 = 0 } 60 if water_short != 180106 { ok3 = 0 } 61 if pep_mass_agrees(red, 58036375, 30) != 0 { ok3 = 0 } 62 if pep_mass_agrees(naive, 58036375, 30) != 0 { ok3 = 0 } 63 if ok3 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 64 65 // --- T4 covalently linked: 2 chains need >=1 inter-chain bridge --- 66 total = total + 1 67 let linked: i64 = pca_is_covalently_linked(ins) 68 let loose: *NxPepAssembly = nx_pep_assembly_new() 69 pca_add_chain_seq(loose, "GIVEQCCTSICSLYQLENYCN" as *u8) 70 pca_add_chain_seq(loose, "FVNQHLCGSHLVEALYLVCGERGFFYTPKT" as *u8) 71 pca_add_intra_disulfide(loose) 72 pca_add_intra_disulfide(loose) 73 pca_add_intra_disulfide(loose) 74 let loose_linked: i64 = pca_is_covalently_linked(loose) 75 t_puts("T4 insulin linked=" as *u8); t_putn(linked); t_puts(" ; same chains, 3 INTRA bridges only, linked=" as *u8); t_putn(loose_linked); t_puts(" want 1/0: " as *u8) 76 if linked == 1 { if loose_linked == 0 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 77 78 // --- T5 a single chain is trivially "linked"; an empty one is not --- 79 total = total + 1 80 let one: *NxPepAssembly = nx_pep_assembly_new() 81 pca_add_chain_seq(one, "GIVEQCCTSICSLYQLENYCN" as *u8) 82 let one_linked: i64 = pca_is_covalently_linked(one) 83 let none: *NxPepAssembly = nx_pep_assembly_new() 84 let none_linked: i64 = pca_is_covalently_linked(none) 85 let none_mass: i64 = pca_mass_q4(none) 86 t_puts("T5 single chain linked=" as *u8); t_putn(one_linked); t_puts(" empty assembly linked=" as *u8); t_putn(none_linked); t_puts(" mass=" as *u8); t_putn(none_mass); t_puts(" want 1/0/-1: " as *u8) 87 var ok5: i64 = 1 88 if one_linked != 1 { ok5 = 0 } 89 if none_linked != 0 { ok5 = 0 } 90 if none_mass != PEP_INVALID { ok5 = 0 } 91 if ok5 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 92 93 // --- T6 STRUCTURAL REFUSAL: more bridges than cysteines allow --- 94 // The mass such a claim produces is entirely plausible, which is exactly 95 // why it must be refused rather than returned. 96 total = total + 1 97 let greedy: *NxPepAssembly = build_insulin() 98 pca_add_inter_disulfide(greedy) 99 let g_free: i64 = pca_free_cys(greedy) 100 let g_ok: i64 = pca_bridges_possible(greedy) 101 let g_mass: i64 = pca_mass_q4(greedy) 102 t_puts("T6 four bridges on six cysteines: free=" as *u8); t_putn(g_free); t_puts(" possible=" as *u8); t_putn(g_ok); t_puts(" mass=" as *u8); t_putn(g_mass); t_puts(" want -2/0/-1: " as *u8) 103 var ok6: i64 = 1 104 if g_free != 0 - 2 { ok6 = 0 } 105 if g_ok != 0 { ok6 = 0 } 106 if g_mass != PEP_INVALID { ok6 = 0 } 107 if ok6 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 108 109 // --- T7 a chain carrying its OWN bridges is refused (no double count) --- 110 total = total + 1 111 let dbl: *NxPepAssembly = nx_pep_assembly_new() 112 let ch: *NxPepBuild = nx_pep_build_new() 113 pex_add_seq(ch, "GIVEQCCTSICSLYQLENYCN" as *u8) 114 pex_add_disulfide(ch) 115 pca_add_chain(dbl, ch, 4) 116 let d_valid: i64 = dbl.valid 117 let d_mass: i64 = pca_mass_q4(dbl) 118 t_puts("T7 chain with its own bridge: assembly valid=" as *u8); t_putn(d_valid); t_puts(" mass=" as *u8); t_putn(d_mass); t_puts(" want 0/-1: " as *u8) 119 if d_valid == 0 { if d_mass == PEP_INVALID { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 120 121 // --- T8 a bad residue anywhere poisons the whole assembly --- 122 total = total + 1 123 let bad: *NxPepAssembly = nx_pep_assembly_new() 124 pca_add_chain_seq(bad, "GIVEQCC" as *u8) 125 pca_add_chain_seq(bad, "FVNQHLZ" as *u8) 126 let b_mass: i64 = pca_mass_q4(bad) 127 t_puts("T8 assembly with an unknown residue: mass=" as *u8); t_putn(b_mass); t_puts(" want -1: " as *u8) 128 if b_mass == PEP_INVALID { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 129 130 // --- T9 insulin on the charge ladder: the z=5/6 ions ESI really gives --- 131 total = total + 1 132 let z1: i64 = pca_mz_q4(ins, 1) 133 let z5: i64 = pca_mz_q4(ins, 5) 134 let z6: i64 = pca_mz_q4(ins, 6) 135 t_puts("T9 insulin m/z z=1/5/6 = " as *u8); t_putn(z1); t_puts("/" as *u8); t_putn(z5); t_puts("/" as *u8); t_putn(z6); t_puts(" (descending, z5 in 1000-1200 range): " as *u8) 136 var ok9: i64 = 1 137 if z5 >= z1 { ok9 = 0 } 138 if z6 >= z5 { ok9 = 0 } 139 if z5 < 10000000 { ok9 = 0 } 140 if z5 > 12000000 { ok9 = 0 } 141 if ok9 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 142 143 // --- T10 chain count and mass scale correctly with a third chain --- 144 total = total + 1 145 let tri: *NxPepAssembly = build_insulin() 146 pca_add_chain_seq(tri, "GG" as *u8) 147 pca_add_inter_disulfide(tri) 148 let t_linked: i64 = pca_is_covalently_linked(tri) 149 let t_chains: i64 = tri.n_chains 150 let t_free: i64 = pca_free_cys(tri) 151 t_puts("T10 three chains, 3 inter bridges: chains=" as *u8); t_putn(t_chains); t_puts(" linked=" as *u8); t_putn(t_linked); t_puts(" free Cys=" as *u8); t_putn(t_free); t_puts(" (needs 2 inter, has 3; but Cys short): " as *u8) 152 var ok10: i64 = 1 153 if t_chains != 3 { ok10 = 0 } 154 if t_linked != 1 { ok10 = 0 } 155 if t_free != 0 - 2 { ok10 = 0 } 156 if ok10 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 157 158 t_puts("PEPTIDE-CHAIN-GATE passed " as *u8); t_putn(pass); t_puts("/" as *u8); t_putn(total) 159 if pass == total { t_puts(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 160 t_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 161}