bni builds and queries a read-name index for BAM files sorted with
samtools sort -N.
queryname:lexicographicalWith a system htslib available via pkg-config:
make
With a local htslib source/build tree:
make HTSLIB_DIR=/path/to/htslib
Build outputs:
bni
libbni.a
libbni.dylib # macOS
libbni.so # Linux
Install:
make install PREFIX=$HOME/.local
samtools sort -N -o reads.name.bam reads.bam
bni index reads.name.bam
bni get reads.name.bam 'READ_ID' > one_read.bam
Additional checks and metadata:
bni stats reads.name.bam
bni check --full reads.name.bam
Default index path:
reads.name.bam.bni
BNIv2 stores one entry per BGZF block that contains BAM record starts.
Each entry stores:
first_qname
last_qname
beg_voff
end_voff
n_records
Lookup uses the first entry whose last_qname >= target_qname, seeks to
beg_voff, and scans forward until the target QNAME is found and passed.
samtools sort -N.bni is inspired by Jared Simpson’s bri.