nx_bam.nx
buildroot/runtime/nx_bam.nx
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
imports: nx_syscalls.nxnx_const.nxnx_le.nx
imported by: nx_bam_file_compose_test.nxnx_bam_test.nx
structs
| none |
consts
| 28 | const NX_MAGIC_65535: i64 = 65535 |
| 100 | const NX_BAM_REC_REF_ID: i64 = 0 |
| 101 | const NX_BAM_REC_POS: i64 = 1 // 0-indexed (NOT 1-indexed like SAM) |
| 102 | const NX_BAM_REC_MAPQ: i64 = 2 |
| 103 | const NX_BAM_REC_BIN: i64 = 3 // UCSC bin (0 for unbinned) |
| 104 | const NX_BAM_REC_FLAG: i64 = 4 |
| 105 | const NX_BAM_REC_NEXT_REF: i64 = 5 |
| 106 | const NX_BAM_REC_NEXT_POS: i64 = 6 // 0-indexed |
| 107 | const NX_BAM_REC_TLEN: i64 = 7 // signed |
| 108 | const NX_BAM_REC_NO_QUAL: i64 = 8 // 0 = qual present, 1 = fill 0xFF |
| 109 | const NX_BAM_REC_READ_NAME_LEN: i64 = 9 // bytes (NUL appended internally) |
| 110 | const NX_BAM_REC_N_CIGAR_OP: i64 = 10 |
| 111 | const NX_BAM_REC_L_SEQ: i64 = 11 |
functions
| 33 | func nx_bam_iupac_to_nibble(c: i64) -> i64 |
| 71 | func nx_bam_pack_seq(seq_ascii: *u8, seq_len: i64, |
| 116 | func nx_bam_pack_cigar(ops: *i64, lens: *i64, n_op: i64, |
| 172 | func nx_bam_write_record(read_name_ascii: *u8, |