bamfreq is a small tool written in C on top of htslib. Most code written by @clwgg, with only minor tweaks of @MoisesExpositoAlonso.
It iterates through a bam alignment file and reports, at each position which is covered with at least one alignment, the total coverage and the counts of all bases present. It outputs a file as:
Several filters may be employed, like minimum mapping quality, minimum and maximum coverage, and minimum base frequency. These are documented in the usage message of the tool.
git clone --recursive https://github.com/MoisesExpositoAlonso/bamfreq
cd bamfreq
make submodules
make
Run ./freq to prompt help
Usage: freq [options] file.bam
Options:
-h only print heterozygous positions
-a only print natural bases ACTG
-f min fraction of read support
-q min map quality
-c min coverage of position to be reported
-m max coverage of position to be reported
-r only print raw counts without bases, coverage or position
Default output:
Seq Pos Cov #A #C #G #G #T #N #D