code wiki / (root) / nx_sequence.nx

nx_sequence.nx

buildroot/runtime/nx_sequence.nx

9921 B243 linesdepth 2pulls 3 transitivereach 17 importersview sourcekind librarytopic sequence
docsdependenciesstructsconstsfunctions

about

nx_sequence.nx -- foundational DNA / RNA sequence algebra primitive. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/biology/dna_2bit_encoding_field_standard G0.1 of NISHI_GENOMICS_SUBSTRATE_ROADMAP.md. Encoding + reverse-complement + k-mer enumeration + canonical k-mer. Built bits-up against existing nx_syscalls; no other genomics dependency. 2-bit packed DNA encoding: A = 00, C = 01, G = 10, T = 11 Complement = code XOR 0b11 (A<->T, C<->G). 4 bases per byte, packed big-endian within byte: byte bits 7-6 = base position 0 within byte byte bits 5-4 = base position 1 byte bits 3-2 = base position 2 byte bits 1-0 = base position 3 Bytes ordered first-to-last. A trailing partial byte zero-pads the low bits (so "ACG" = 0x18 = 00 01 10 00 in one byte). k-mer encoding (k <= 32): Single i64 holding the 2*k low bits. Base position 0 of the k-mer sits in the highest 2 bits of the 2*k-bit window. This means lexicographic ordering of bases (A < C < G < T) matches arithmetic ordering of the packed i64, so canonical k-mer = min(fwd, rc) is a simple arithmetic min. Why 2-bit: - Minimum storage for an alphabet of 4 (human reference ~750 MB uncompressed FASTA -> ~190 MB packed) - Reverse-complement of a packed code is a single XOR - SIMD-friendly: 16 bases per 32-bit word, 32 bases per i64 - k-mer hashing fits naturally N / ambiguity handling: Out of scope for G0.1. See nx_sequence_ambig.nx (G0.5) for the IUPAC sidecar bitset. In G0.1, callers must filter Ns upstream or the encoder returns -1 (refused) on any non-ACGT input. API:

dependencies 2 imports · 13 importers

nx_syscalls.nx nx_const.nx nx_sequence.nx nx_align_match_stranded_test.nx nx_align_match_test.nx nx_align_minimizer.nx nx_align_minimizer_test.nx nx_align_score.nx nx_align_score_test.nx nx_pileup.nx nx_pileup_test.nx nx_sam.nx nx_sequence_ambig.nx

diagram shows first 10 each side; +0 more imports, +3 more importers in the complete lists below.

imports: nx_syscalls.nxnx_const.nx

imported by: nx_align_match_stranded_test.nxnx_align_match_test.nxnx_align_minimizer.nxnx_align_minimizer_test.nxnx_align_score.nxnx_align_score_test.nxnx_pileup.nxnx_pileup_test.nxnx_sam.nxnx_sequence_ambig.nxnx_sequence_ambig_test.nxnx_sequence_kat_test.nxnx_vcf.nx

structs

none

consts

none

functions

95func dna_encode_base(c: i64) -> i64
110func dna_decode_base(code: i64) -> i64
120func dna_complement_code(code: i64) -> i64
called by 2: dna_revcompmain
129func dna_get_base(bases: *u8, pos: i64) -> i64
139func dna_set_base(bases: *u8, pos: i64, code: i64) -> i64
156func dna_pack(ascii: *u8, len: i64, out_bases: *u8) -> i64
170func dna_unpack(bases: *u8, len: i64, out: *u8) -> i64
called by 1: main calls 2: dna_get_basedna_decode_base
186func dna_revcomp(in_bases: *u8, len: i64, out_bases: *u8) -> i64
203func dna_kmer_at(bases: *u8, pos: i64, k: i64) -> i64
called by 2: minimizer_extractmain calls 1: dna_get_base
219func dna_kmer_revcomp(kmer: i64, k: i64) -> i64
239func dna_kmer_canonical(kmer: i64, k: i64) -> i64