code wiki / (root) / nx_supplement_screen_test.nx

nx_supplement_screen_test.nx source

↩ module page · 181 lines · 10154 B

1// nx_supplement_screen_test.nx -- gate for nx_supplement_screen. Masses are 2// checked against PUBLISHED values for the real compounds; the multi-charge 3// blind spot is MEASURED per catalog entry rather than asserted; and the 4// terminal-modification handling is proven by showing the unmodified mass 5// does NOT match the modified catalog entry. 6// expect_exit: 0 license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_peptide.nx" 9import "nx_supplement_screen.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 14func main() -> i64 { 15 var pass: i64 = 0 16 var total: i64 = 0 17 18 // --- T1 BPC-157 mass DERIVED from sequence vs published 1418.70 Da --- 19 total = total + 1 20 let m_bpc: i64 = sup_mass_q4(SUP_BPC157) 21 t_puts("T1 BPC-157 monoisotopic Q4=" as *u8); t_putn(m_bpc); t_puts(" vs lit 14187000 tol 100: " as *u8) 22 if pep_mass_agrees(m_bpc, 14187000, 100) == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 23 24 // --- T2 GHRP-6 is C-terminally AMIDATED: mass must shift by -0.984 --- 25 total = total + 1 26 let free_acid: i64 = pep_mass_mono_q4("HWAWFK" as *u8) 27 let m_ghrp: i64 = sup_mass_q4(SUP_GHRP6) 28 let shift: i64 = free_acid - m_ghrp 29 t_puts("T2 GHRP-6 free-acid=" as *u8); t_putn(free_acid); t_puts(" amidated=" as *u8); t_putn(m_ghrp); t_puts(" shift=" as *u8); t_putn(shift); t_puts(" want 9840, lit 8724400: " as *u8) 30 var ok2: i64 = 1 31 if shift != 9840 { ok2 = 0 } 32 if pep_mass_agrees(m_ghrp, 8724400, 100) != 1 { ok2 = 0 } 33 if ok2 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 34 35 // --- T3 the modification MATTERS: free-acid m/z must NOT match --- 36 // If the screen ignored amidation it would hunt the wrong ion by 37 // ~1130 ppm, which at a 20 ppm window is a guaranteed miss. 38 total = total + 1 39 let fa_mz: i64 = pep_mz_q4(free_acid, 1) 40 let hit_wrong: i64 = sup_match_charge(SUP_GHRP6, fa_mz, 200) 41 let right_mz: i64 = sup_mz_q4(SUP_GHRP6, 1) 42 let hit_right: i64 = sup_match_charge(SUP_GHRP6, right_mz, 200) 43 t_puts("T3 free-acid m/z matches=" as *u8); t_putn(hit_wrong); t_puts(" (want 0), amidated m/z matches at z=" as *u8); t_putn(hit_right); t_puts(" (want 1): " as *u8) 44 if hit_wrong == 0 { if hit_right == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 45 46 // --- T4 the charge ladder: BPC-157 across z = 1..4 --- 47 total = total + 1 48 let z1: i64 = sup_mz_q4(SUP_BPC157, 1) 49 let z2: i64 = sup_mz_q4(SUP_BPC157, 2) 50 let z3: i64 = sup_mz_q4(SUP_BPC157, 3) 51 let z4: i64 = sup_mz_q4(SUP_BPC157, 4) 52 t_puts("T4 BPC-157 m/z z1..z4 = " as *u8); t_putn(z1); t_puts(" " as *u8); t_putn(z2); t_puts(" " as *u8); t_putn(z3); t_puts(" " as *u8); t_putn(z4); t_puts(" (descending): " as *u8) 53 var ok4: i64 = 1 54 if z2 >= z1 { ok4 = 0 } 55 if z3 >= z2 { ok4 = 0 } 56 if z4 >= z3 { ok4 = 0 } 57 if z1 != 14197117 { ok4 = 0 } 58 if ok4 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 59 60 // --- T5 THE DEFECT, MEASURED: [M+H]+ of BPC-157 is out of a 61 // 100-1000 m/z window, but z=2,3,4 are inside it --- 62 total = total + 1 63 let mh_in: i64 = sup_mh_plus_in_range(SUP_BPC157) 64 let ndet: i64 = sup_detectable_charges_in_range(SUP_BPC157) 65 let blind: i64 = sup_single_charge_blind_spot(SUP_BPC157) 66 t_puts("T5 BPC-157 [M+H]+ in window=" as *u8); t_putn(mh_in); t_puts(" charges in window=" as *u8); t_putn(ndet); t_puts(" single-charge blind spot=" as *u8); t_putn(blind); t_puts(": " as *u8) 67 var ok5: i64 = 1 68 if mh_in != 0 { ok5 = 0 } 69 if ndet != 3 { ok5 = 0 } 70 if blind != 1 { ok5 = 0 } 71 if ok5 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 72 73 // --- T6 count the blind spots across the whole catalog --- 74 total = total + 1 75 var i6: i64 = 0 76 var nblind: i64 = 0 77 while i6 < SUP_N_ENTRY { 78 let b: i64 = sup_single_charge_blind_spot(i6) 79 nblind = nblind + b 80 i6 = i6 + 1 81 } 82 t_puts("T6 catalog entries invisible to an [M+H]+-only screen: " as *u8); t_putn(nblind); t_puts("/" as *u8); t_putn(SUP_N_ENTRY); t_puts(" want 3: " as *u8) 83 if nblind == 3 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 84 85 // --- T7 small peptides are NOT blind spots (the control) --- 86 total = total + 1 87 let b_tb: i64 = sup_single_charge_blind_spot(SUP_TB500) 88 let b_gh: i64 = sup_single_charge_blind_spot(SUP_GHRP6) 89 t_puts("T7 TB-500 blind=" as *u8); t_putn(b_tb); t_puts(" GHRP-6 blind=" as *u8); t_putn(b_gh); t_puts(" (both 0, so the finding is specific): " as *u8) 90 if b_tb == 0 { if b_gh == 0 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 91 92 // --- T8 screening a doubly-charged peak IDENTIFIES the compound --- 93 // This is the peak a real spiked sample shows; a z=1 screen sees nothing. 94 total = total + 1 95 let obs: i64 = sup_mz_q4(SUP_BPC157, 2) 96 let who: i64 = sup_screen(obs, 200) 97 let zz: i64 = sup_match_charge(SUP_BPC157, obs, 200) 98 t_puts("T8 observed m/z " as *u8); t_putn(obs); t_puts(" identified as entry " as *u8); t_putn(who); t_puts(" at z=" as *u8); t_putn(zz); t_puts(" want 0/2: " as *u8) 99 if who == SUP_BPC157 { if zz == 2 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 100 101 // --- T9 ppm arithmetic + a NEGATIVE control (unrelated peak) --- 102 total = total + 1 103 let ref9: i64 = sup_mz_q4(SUP_BPC157, 2) 104 let p0: i64 = sup_ppm_q1(ref9, ref9) 105 let near: i64 = ref9 + 71 106 let p10: i64 = sup_ppm_q1(near, ref9) 107 let tight: i64 = sup_within_ppm(near, ref9, 50) 108 let loose: i64 = sup_within_ppm(near, ref9, 200) 109 let nomatch: i64 = sup_screen(5000000, 200) 110 t_puts("T9 ppm exact=" as *u8); t_putn(p0); t_puts(" ~10ppm=" as *u8); t_putn(p10); t_puts(" tight(5ppm)=" as *u8); t_putn(tight); t_puts(" loose(20ppm)=" as *u8); t_putn(loose); t_puts(" unrelated peak=" as *u8); t_putn(nomatch); t_puts(": " as *u8) 111 var ok9: i64 = 1 112 if p0 != 0 { ok9 = 0 } 113 if p10 < 90 { ok9 = 0 } 114 if p10 > 110 { ok9 = 0 } 115 if tight != 0 { ok9 = 0 } 116 if loose != 1 { ok9 = 0 } 117 if nomatch != SUP_NO_MATCH { ok9 = 0 } 118 if ok9 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 119 120 // --- T10 regulatory status is carried through --- 121 total = total + 1 122 let pr_bpc: i64 = sup_is_prohibited(SUP_BPC157) 123 let pr_tb: i64 = sup_is_prohibited(SUP_TB500) 124 let pr_ang: i64 = sup_is_prohibited(SUP_ANGII) 125 let st_ang: i64 = sup_status(SUP_ANGII) 126 let st_bk: i64 = sup_status(SUP_BRADYK) 127 t_puts("T10 prohibited BPC/TB/AngII = " as *u8); t_putn(pr_bpc); t_puts("/" as *u8); t_putn(pr_tb); t_puts("/" as *u8); t_putn(pr_ang); t_puts(" AngII status=" as *u8); t_putn(st_ang); t_puts(" bradykinin=" as *u8); t_putn(st_bk); t_puts(": " as *u8) 128 var ok10: i64 = 1 129 if pr_bpc != 1 { ok10 = 0 } 130 if pr_tb != 1 { ok10 = 0 } 131 if pr_ang != 0 { ok10 = 0 } 132 if st_ang != SUP_REG_APPROVED { ok10 = 0 } 133 if st_bk != SUP_REG_ENDOGENOUS { ok10 = 0 } 134 if ok10 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 135 136 // --- T11 FAIL-CLOSED on an out-of-catalog id: refuse, never guess --- 137 total = total + 1 138 let bad_m: i64 = sup_mass_q4(99) 139 let bad_mz: i64 = sup_mz_q4(99, 1) 140 let bad_hit: i64 = sup_match_charge(99, 7103595, 200) 141 t_puts("T11 unknown id mass=" as *u8); t_putn(bad_m); t_puts(" mz=" as *u8); t_putn(bad_mz); t_puts(" match=" as *u8); t_putn(bad_hit); t_puts(" (refused, no false hit): " as *u8) 142 var ok11: i64 = 1 143 if bad_m != PEP_INVALID { ok11 = 0 } 144 if bad_mz != PEP_INVALID { ok11 = 0 } 145 if bad_hit != 0 { ok11 = 0 } 146 if ok11 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 147 148 // --- T12 label-claim dose verification, both failure directions --- 149 total = total + 1 150 let r_ok: i64 = sup_recovery_pct(4750, 5000) 151 let c_ok: i64 = sup_label_compliant(4750, 5000) 152 let v_under: i64 = sup_dose_verdict(4000, 5000) 153 let v_over: i64 = sup_dose_verdict(6000, 5000) 154 let v_ok: i64 = sup_dose_verdict(4750, 5000) 155 let c_zero: i64 = sup_label_compliant(5000, 0) 156 t_puts("T12 recovery=" as *u8); t_putn(r_ok); t_puts("% compliant=" as *u8); t_putn(c_ok); t_puts(" verdict under/over/ok = " as *u8); t_putn(v_under); t_puts("/" as *u8); t_putn(v_over); t_puts("/" as *u8); t_putn(v_ok); t_puts(" zero-declared=" as *u8); t_putn(c_zero); t_puts(": " as *u8) 157 var ok12: i64 = 1 158 if r_ok != 95 { ok12 = 0 } 159 if c_ok != 1 { ok12 = 0 } 160 if v_under != 0 - 1 { ok12 = 0 } 161 if v_over != 1 { ok12 = 0 } 162 if v_ok != 0 { ok12 = 0 } 163 if c_zero != 0 { ok12 = 0 } 164 if ok12 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 165 166 // --- T13 every catalog entry resolves to a real derived mass --- 167 total = total + 1 168 var i13: i64 = 0 169 var ok13: i64 = 1 170 while i13 < SUP_N_ENTRY { 171 let mm: i64 = sup_mass_q4(i13) 172 if mm <= 0 { ok13 = 0 } 173 i13 = i13 + 1 174 } 175 t_puts("T13 all " as *u8); t_putn(SUP_N_ENTRY); t_puts(" catalog masses derive from sequence: " as *u8) 176 if ok13 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 177 178 t_puts("SUPPLEMENT-SCREEN-GATE passed " as *u8); t_putn(pass); t_puts("/" as *u8); t_putn(total) 179 if pass == total { t_puts(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 180 t_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 181}