nx_phred.nx
buildroot/runtime/nx_phred.nx
about
nx_phred.nx -- Phred quality score encode / decode helpers.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/sam-spec-v1.4.6 + ewing-green-1998-phred
G2.0a of NISHI_GENOMICS_SUBSTRATE_ROADMAP.md. Bridges to
FASTQ / SAM real-world data: every sequencer-emitted base carries
a Phred quality score Q = -10 * log10(P_error), encoded in FASTQ
as ASCII byte (Q + offset). This primitive ships ONLY the
encode/decode layer; probability conversions (Q -> P_error in
fixed-point) require log/exp primitives queued for G2.0b.
Two encodings:
Phred+33 (Sanger / Illumina 1.8+): the modern universal default
- ASCII = Q + 33
- Q range [0..93] maps to ASCII [33..126] = '!' to '~'
- Used by ALL contemporary sequencers + SAM/BAM
Phred+64 (legacy Illumina 1.3 / 1.5 / 1.7): historical only
- ASCII = Q + 64
- Q range [0..62] maps to ASCII [64..126] = '@' to '~'
- Substrate supports for archived data + cross-compatibility
Universal Q-value benchmarks:
Q10 = 90% accuracy (10% error)
Q20 = 99% accuracy (1% error) <- variant-calling minimum threshold
Q30 = 99.9% accuracy (0.1% error) <- typical Illumina target
Q40 = 99.99% accuracy <- typical PacBio HiFi
Q60 = 99.9999% accuracy <- consensus / theoretical max
API:
nx_phred33_encode(q) -> i64 Q [0..93] -> ASCII byte; -1 out of range
nx_phred33_decode(ascii) -> i64 ASCII [33..126] -> Q; -1 out of range
nx_phred64_encode(q) -> i64 Q [0..62] -> ASCII byte; -1 out of range
nx_phred64_decode(ascii) -> i64 ASCII [64..126] -> Q; -1 out of range
nx_phred33_encode_string(qs, n, out_ascii) -> i64 bulk encode
nx_phred33_decode_string(ascii, n, out_qs) -> i64 bulk decode
What G2.0a does NOT do (deferred):
- Q -> P_error fixed-point conversion -- needs nx_fixed_point + log10 (G2.0b)
- Per-position quality aggregation (consensus quality scoring) -- G2.0c
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_const.nx
imported by: nx_phred_test.nx
structs
| none |
consts
| none |
functions
| 75 | func nx_phred33_encode(q: i64) -> i64 |
| 83 | func nx_phred33_decode(ascii: i64) -> i64 |
| 94 | func nx_phred64_encode(q: i64) -> i64 called by 1: main |
| 102 | func nx_phred64_decode(ascii: i64) -> i64 called by 1: main |
| 113 | func nx_phred33_encode_string(qs: *i64, n: i64, out_ascii: *u8) -> i64 |
| 128 | func nx_phred33_decode_string(ascii: *u8, n: i64, out_qs: *i64) -> i64 |