let sort_bam_if_necessary ~(run_with:Machine.t) ~by
    input_bam : KEDSL.bam_file KEDSL.workflow_node =
  match input_bam#product#sorting with
  | Some some when some = by -> (* Already sorted “the same way” *)
    input_bam
  | other ->
    sort_bam_no_check ~run_with input_bam ~by