SAM Tools is very flexible framework, that provide various utilities for manipulating alignments in the SAM format, including sorting, merging, indexing and generating alignments. This tool also allows to convert between different formats ex. .bam. It can be used from terminal or as a library. There are bindings to many popular languages: c++, python, java, perl ect.