code wiki / (root) / nx_sam.nx

nx_sam.nx

buildroot/runtime/nx_sam.nx

25517 B669 linesdepth 4pulls 6 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_const.nx nx_sequence.nx nx_cigar.nx nx_vcf.nx nx_sam.nx nx_sam_test.nx

imports: nx_syscalls.nxnx_const.nxnx_sequence.nxnx_cigar.nxnx_vcf.nx

imported by: nx_sam_test.nx

structs

none

consts

96const NX_SAM_FIELD_FLAG: i64 = 0
97const NX_SAM_FIELD_POS: i64 = 1
98const NX_SAM_FIELD_MAPQ: i64 = 2
99const NX_SAM_FIELD_TLEN: i64 = 3
101const NX_SAM_STR_QNAME: i64 = 0
102const NX_SAM_STR_RNAME: i64 = 1
103const NX_SAM_STR_CIGAR: i64 = 2
104const NX_SAM_STR_SEQ: i64 = 3
115const NX_SAM_PE_FIELD_FLAG: i64 = 0
116const NX_SAM_PE_FIELD_POS: i64 = 1
117const NX_SAM_PE_FIELD_MAPQ: i64 = 2
118const NX_SAM_PE_FIELD_PNEXT: i64 = 3
119const NX_SAM_PE_FIELD_TLEN: i64 = 4
121const NX_SAM_PE_STR_QNAME: i64 = 0
122const NX_SAM_PE_STR_RNAME: i64 = 1
123const NX_SAM_PE_STR_RNEXT: i64 = 2
124const NX_SAM_PE_STR_CIGAR: i64 = 3
125const NX_SAM_PE_STR_SEQ: i64 = 4
154const NX_SAM_PG_ID: i64 = 0
155const NX_SAM_PG_NAME: i64 = 1
156const NX_SAM_PG_VERSION: i64 = 2
159const NX_SAM_RG_ID: i64 = 0
160const NX_SAM_RG_SAMPLE: i64 = 1

functions

131func sam_write_hd_line(out_ascii: *u8, max_out: i64) -> i64
called by 1: main
168func sam_write_rg_line(str_buf: *u8,
called by 1: main calls 2: nx_copy_bytesnx_copy_byte
219func sam_write_pg_line(str_buf: *u8,
called by 1: main calls 2: nx_copy_bytesnx_copy_byte
287func sam_write_sq_line(chrom: *u8, chrom_len: i64,
334func nx_emit_signed_int(n: i64, dst: *u8, dst_off: i64, max_dst: i64) -> i64
360func sam_append_tag_int(out_ascii: *u8, off: i64, max_out: i64,
called by 1: main calls 1: nx_emit_signed_int
398func sam_append_tag_str(out_ascii: *u8, off: i64, max_out: i64,
called by 1: main calls 1: nx_copy_bytes
424func sam_write_line(str_buf: *u8,
560func sam_write_line_paired(str_buf: *u8,