let index_bam bam =
let input_bam = get_bam (AF.get_file bam) in
let sorted_bam = Tools.Samtools.sort_bam_if_necessary ~run_with ~by:`Coordinate input_bam in
Bai (
Tools.Samtools.index_to_bai
~run_with ~check_sorted:true sorted_bam
) |> AF.with_provenance "index-bam" ["bam", AF.get_provenance bam]