code wiki / (root) / nx_pileup.nx

nx_pileup.nx

buildroot/runtime/nx_pileup.nx

17495 B433 linesdepth 4pulls 6 transitivereach 3 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_pileup.nx -- CIGAR walking primitives for variant-calling pileup. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/sam-spec-v1.4.6 + li-2009-samtools-pileup G2.1a of NISHI_GENOMICS_SUBSTRATE_ROADMAP.md. The math foundation for variant calling: given an aligned read's CIGAR string and its alignment ref-start, compute "what query base contributes to a specific reference position?" Aggregating this across many reads at a single ref position IS the pileup, and the pileup IS the input to germline + somatic variant callers. CIGAR walking model (SAM-spec consumption flags from nx_cigar): For each op in alignment order: - if consumes_ref: advance ref-position counter by op_len - if consumes_query: advance query-position counter by op_len Until ref-position counter reaches the target. The resulting query-position counter is the read offset of the base that aligns to the target ref position (or in_gap=1 if the target falls inside a D / N op). Why this primitive matters: - Variant calling: aggregate per-position base counts -> SNVs - Indel detection: I/D ops at specific ref positions - Coverage depth: count reads spanning a position - Quality recalibration (BQSR): per-position quality stats - Pileup visualisation (IGV / samtools tview) API: cigar_query_pos_at_ref( cigar_codes, cigar_lens, n_groups, r_start, target_r, out_q_pos, out_in_gap ) -> i64 r_start : reference start position of this alignment (the SAM POS field minus 1 if interpreting SAM 1-indexed; substrate uses 0-indexed throughout) target_r : the reference position we want the read-base for out_q_pos : query offset (0-indexed into read sequence)

dependencies 5 imports · 3 importers

nx_syscalls.nx nx_const.nx nx_cigar.nx nx_sequence.nx nx_sequence_ambig.nx nx_pileup.nx nx_pileup_test.nx nx_variant.nx nx_variant_test.nx

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

imported by: nx_pileup_test.nxnx_variant.nxnx_variant_test.nx

structs

none

consts

88const NX_PILEUP_FLAG_BASE: i64 = 0 // normal ACGT base contributed
89const NX_PILEUP_FLAG_N: i64 = 1 // ambiguous base (N) contributed
90const NX_PILEUP_FLAG_DEL: i64 = 2 // position in deletion gap, no base
91const NX_PILEUP_FLAG_OUT: i64 = 3 // target_r outside alignment region
193const NX_PILEUP_COUNT_N: i64 = 4
194const NX_PILEUP_COUNT_DEL: i64 = 5
195const NX_PILEUP_COUNT_LEN: i64 = 6

functions

95func cigar_query_pos_at_ref(cigar_codes: *u8, cigar_lens: *i64, n_groups: i64,
154func pileup_contribute_one_read(
217func pileup_insertion_after_ref(cigar_codes: *u8, cigar_lens: *i64, n_groups: i64,
285func ins_event_to_hash(read_bases: *u8, q_pos: i64, ins_len: i64) -> i64
called by 1: main calls 1: dna_get_base
304func ins_event_decode_hash(hash: i64, out_packed: *i64) -> i64
called by 1: main
328func pileup_deletion_after_ref(cigar_codes: *u8, cigar_lens: *i64, n_groups: i64,
383func indel_count_insertions_by_length(ins_lens: *i64, n_reads: i64,
called by 1: main
407func pileup_aggregate_counts(base_codes: *i64, flags: *i64, n_reads: i64,
called by 1: main