code wiki / (root) / nx_bam.nx

nx_bam.nx

buildroot/runtime/nx_bam.nx

11162 B278 linesdepth 3pulls 4 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_bam.nx -- BAM binary record serialiser (SAMv1 §4). G6.0d.1: nx_bam_pack_seq -- 4-bit IUPAC nucleotide packing. Each base in the ASCII input is mapped to a 4-bit code per SAMv1 §4.2 Table 1 (= 0, A=1, C=2, M=3, G=4, R=5, S=6, V=7, T=8, W=9, Y=10, H=11, K=12, D=13, B=14, N=15). Bases are packed two-per-byte, HIGH nibble first. Output length: ceil(seq_len / 2) bytes. On odd seq_len, last low nibble is zero per spec. Unrecognised ASCII -> NX_BAM_NT_N (15) -- conservative. G6.0d.2: nx_bam_pack_cigar -- pack CIGAR ops into u32 LE words. Each op packs as (op_len << 4) | op_code; written little-endian. Input: parallel arrays ops[] + lens[] of n_op entries. Output: n_op * 4 bytes. G6.0d.3: nx_bam_write_record -- canonical BAM alignment record. block_size + 32-byte fixed header + read_name + cigar + seq + qual per SAMv1 §4.2. Header fields written little-endian via nx_le. expect_exit: 0 license_tier: ORIGINAL

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_const.nx nx_le.nx nx_bam.nx nx_bam_file_compose_test.nx nx_bam_test.nx

imports: nx_syscalls.nxnx_const.nxnx_le.nx

imported by: nx_bam_file_compose_test.nxnx_bam_test.nx

structs

none

consts

28const NX_MAGIC_65535: i64 = 65535
100const NX_BAM_REC_REF_ID: i64 = 0
101const NX_BAM_REC_POS: i64 = 1 // 0-indexed (NOT 1-indexed like SAM)
102const NX_BAM_REC_MAPQ: i64 = 2
103const NX_BAM_REC_BIN: i64 = 3 // UCSC bin (0 for unbinned)
104const NX_BAM_REC_FLAG: i64 = 4
105const NX_BAM_REC_NEXT_REF: i64 = 5
106const NX_BAM_REC_NEXT_POS: i64 = 6 // 0-indexed
107const NX_BAM_REC_TLEN: i64 = 7 // signed
108const NX_BAM_REC_NO_QUAL: i64 = 8 // 0 = qual present, 1 = fill 0xFF
109const NX_BAM_REC_READ_NAME_LEN: i64 = 9 // bytes (NUL appended internally)
110const NX_BAM_REC_N_CIGAR_OP: i64 = 10
111const NX_BAM_REC_L_SEQ: i64 = 11

functions

33func nx_bam_iupac_to_nibble(c: i64) -> i64
called by 2: nx_bam_pack_seqmain
71func nx_bam_pack_seq(seq_ascii: *u8, seq_len: i64,
116func nx_bam_pack_cigar(ops: *i64, lens: *i64, n_op: i64,
172func nx_bam_write_record(read_name_ascii: *u8,