Skip to main content

Crate rsomics_bam_reset

Crate rsomics_bam_reset 

Source
Expand description

Revert aligner-applied changes on BAM records, like samtools reset.

Each primary record is reverted to its pre-alignment state: the FLAG is reduced to read/mate pairing + unmapped bits, RNAME/POS/MAPQ/CIGAR/RNEXT/ PNEXT/TLEN go to their unmapped defaults, aligner aux tags are dropped, and a record stored reverse-complemented (the 0x10 reverse bit) has its SEQ/QUAL restored to original read orientation. Secondary (0x100) and supplementary (0x800) records are dropped. The output header is rebuilt from scratch: @HD VN:1.6, the input @RG lines (unless --no-RG) and @PG chain (unless --reject-PG), plus a provenance @PG for this command (unless --no-PG). All @SQ lines are dropped — the reads are unmapped, so the output references nothing.

The record path never decodes CIGAR/SEQ/QUAL into typed structures: the output payload is assembled directly from the input’s raw bytes (read_name copied verbatim, SEQ nibbles relocated, only reverse-strand records repacked). This is why it beats samtools’ full RecordBuf decode + re-encode.

§Origin

This crate is an independent Rust port of samtools reset based on the samtools source (reset.c, MIT licence, commit 1.23). Specifically the FLAG reduction (reset.c:354-362), the secondary/supplementary drop (reset.c:350-352), the reverse-complement restore using the =TGKCYSBAWRDMHVN table (reset.c:377-391), the default aux-tag removal set and --keep-tag/--remove-tag interaction (reset.c:80-159), and the rebuilt-header @HD/@RG/@PG logic (reset.c:307-323, getRGlines, getPGlines). samtools source is MIT, so reading and citing it is permitted.

License: MIT OR Apache-2.0. Upstream credit: samtools https://github.com/samtools/samtools (MIT).

Structs§

ResetOpts
Options for reset.

Functions§

reset
Revert aligner changes on every primary record of input, writing the result to output_path (None = stdout). args_cl is the command-line text written into the provenance @PG line. Returns the number of records written.