BamTools provides both a programmer's API and an end-user's toolkit for handling BAM files.
First load the module:
module load bio/bamtools