code: def sam_to_sortbam_cl(data, tx_out_file, name_sort=False):
      
      samtools = config_utils.get_program("samtools", data["config"])
      cores, mem = _get_cores_memory(data, downscale=2)
      tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
      sort_flag = "-n" if name_sort else ""
      return ("{samtools} sort -@ {cores} -m {mem} {sort_flag} "
              "-T {tmp_file} -o {tx_out_file} /dev/stdin".format(**locals()))
docs: Convert to sorted BAM output.
  
      Set name_sort to True to sort reads by queryname