let sort_bam_no_check ~(run_with:Machine.t) ~by input_bam =
let source = input_bam#product#path in
let dest_suffix =
match by with
| `Coordinate -> "sorted"
| `Read_name -> "read-name-sorted"
in
let dest_prefix =
sprintf "%s-%s" (Filename.chop_suffix source ".bam") dest_suffix in
let dest = sprintf "%s.%s" dest_prefix "bam" in
let product =
KEDSL.transform_bam ~change_sorting:by input_bam#product ~path:dest in
let processors = Machine.max_processors run_with in
let make_command src des =
let command = ["-@"; Int.to_string processors; src;
"-T"; dest_prefix; "-o"; dest] in
match by with
| `Coordinate -> "sort" :: command
| `Read_name -> "sort" :: "-n" :: command
in
do_on_bam ~run_with input_bam ~product ~make_command
~more_requirements:[`Memory `Big; `Processors processors]
~name:(sprintf "Samtools-sort %s"
Filename.(basename input_bam#product#path))