nx_sam.nx
buildroot/runtime/nx_sam.nx
about
nx_sam.nx -- SAM (Sequence Alignment / Map) single-line writer.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/li-2009-sam-spec-v1.4.6
G6.0 of NISHI_GENOMICS_SUBSTRATE_ROADMAP.md. Closes the aligned-
read output side, parallel to the VCF variant output already
shipped in nx_vcf.nx. SAM is the universal interchange format
for aligned sequencer reads -- consumed by every downstream
tool (bcftools, samtools, IGV, GATK, snakemake pipelines).
SAM v1.4.6 data-line format (Li 2009 + SAMv1 spec):
QNAME FLAG RNAME POS MAPQ CIGAR RNEXT PNEXT TLEN SEQ QUAL [tags]
tab-separated, terminated by LF (or CRLF on Windows)
G6.0 emits the 11 mandatory fields:
QNAME : caller-supplied read identifier
FLAG : SAM flag bitfield (0 for unpaired + mapped + fwd strand)
RNAME : reference sequence name (chrom)
POS : 1-indexed leftmost mapping position
MAPQ : mapping quality 0..60 (from nx_alignment.AlignmentRecord)
CIGAR : ASCII CIGAR string (from nx_cigar.cigar_serialize)
RNEXT : "*" hard-coded (unpaired); paired-end is G6.0b
PNEXT : 0 hard-coded (unpaired)
TLEN : caller-supplied template length (0 for single read)
SEQ : query bases as ASCII (caller decodes from packed via dna_unpack)
QUAL : Phred+33 quality string (caller encodes via nx_phred33_encode_string)
Bundled-args API (5 total) per the recurring nxc2 codegen quirk
where ~10 scalar args silently fail. Strings concatenated into
one buffer + per-string lengths array; numeric fields in a second
array.
API:
sam_write_line(str_buf, str_lens, fields, out_ascii, max_out) -> i64
str_buf : qname || rname || cigar || seq || qual (concat)
str_lens : [qname_len, rname_len, cigar_len, seq_len]
qual_len == seq_len per SAM-spec invariant
fields : [flag, pos_1indexed, mapq, tlen]
dependencies 5 imports · 1 importers
imports: nx_syscalls.nxnx_const.nxnx_sequence.nxnx_cigar.nxnx_vcf.nx
imported by: nx_sam_test.nx
structs
| none |
consts
| 96 | const NX_SAM_FIELD_FLAG: i64 = 0 |
| 97 | const NX_SAM_FIELD_POS: i64 = 1 |
| 98 | const NX_SAM_FIELD_MAPQ: i64 = 2 |
| 99 | const NX_SAM_FIELD_TLEN: i64 = 3 |
| 101 | const NX_SAM_STR_QNAME: i64 = 0 |
| 102 | const NX_SAM_STR_RNAME: i64 = 1 |
| 103 | const NX_SAM_STR_CIGAR: i64 = 2 |
| 104 | const NX_SAM_STR_SEQ: i64 = 3 |
| 115 | const NX_SAM_PE_FIELD_FLAG: i64 = 0 |
| 116 | const NX_SAM_PE_FIELD_POS: i64 = 1 |
| 117 | const NX_SAM_PE_FIELD_MAPQ: i64 = 2 |
| 118 | const NX_SAM_PE_FIELD_PNEXT: i64 = 3 |
| 119 | const NX_SAM_PE_FIELD_TLEN: i64 = 4 |
| 121 | const NX_SAM_PE_STR_QNAME: i64 = 0 |
| 122 | const NX_SAM_PE_STR_RNAME: i64 = 1 |
| 123 | const NX_SAM_PE_STR_RNEXT: i64 = 2 |
| 124 | const NX_SAM_PE_STR_CIGAR: i64 = 3 |
| 125 | const NX_SAM_PE_STR_SEQ: i64 = 4 |
| 154 | const NX_SAM_PG_ID: i64 = 0 |
| 155 | const NX_SAM_PG_NAME: i64 = 1 |
| 156 | const NX_SAM_PG_VERSION: i64 = 2 |
| 159 | const NX_SAM_RG_ID: i64 = 0 |
| 160 | const NX_SAM_RG_SAMPLE: i64 = 1 |
functions
| 131 | func sam_write_hd_line(out_ascii: *u8, max_out: i64) -> i64 called by 1: main |
| 168 | func sam_write_rg_line(str_buf: *u8, |
| 219 | func sam_write_pg_line(str_buf: *u8, |
| 287 | func sam_write_sq_line(chrom: *u8, chrom_len: i64, |
| 334 | func nx_emit_signed_int(n: i64, dst: *u8, dst_off: i64, max_dst: i64) -> i64 |
| 360 | func sam_append_tag_int(out_ascii: *u8, off: i64, max_out: i64, |
| 398 | func sam_append_tag_str(out_ascii: *u8, off: i64, max_out: i64, |
| 424 | func sam_write_line(str_buf: *u8, |
| 560 | func sam_write_line_paired(str_buf: *u8, |