nodes: 0, module; 1, function_definition; 2, function_name:sam_to_sortbam_cl; 3, parameters; 4, block; 5, identifier:data; 6, identifier:tx_out_file; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:name_sort; 15, False; 16, comment:"""Convert to sorted BAM output.
  
      Set name_sort to True to sort reads by queryname
      """; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, parenthesized_expression; 22, identifier:samtools; 23, call; 24, pattern_list; 25, call; 26, identifier:tmp_file; 27, binary_operator:"%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]; 28, identifier:sort_flag; 29, conditional_expression:"-n" if name_sort else ""; 30, call; 31, attribute; 32, argument_list; 33, identifier:cores; 34, identifier:mem; 35, identifier:_get_cores_memory; 36, argument_list; 37, string:"%s-sorttmp"; 38, subscript; 39, string:"-n"; 40, identifier:name_sort; 41, string:""; 42, attribute; 43, argument_list; 44, identifier:config_utils; 45, identifier:get_program; 46, string:"samtools"; 47, subscript; 48, identifier:data; 49, keyword_argument; 50, call; 51, integer:0; 52, concatenated_string; 53, identifier:format; 54, dictionary_splat; 55, identifier:data; 56, string:"config"; 57, identifier:downscale; 58, integer:2; 59, attribute; 60, argument_list; 61, string:"{samtools} sort -@ {cores} -m {mem} {sort_flag} "; 62, string:"-T {tmp_file} -o {tx_out_file} /dev/stdin"; 63, call; 64, identifier:utils; 65, identifier:splitext_plus; 66, identifier:tx_out_file; 67, identifier:locals; 68, argument_list
code: def sam_to_sortbam_cl(data, tx_out_file, name_sort=False):
      """Convert to sorted BAM output.
  
      Set name_sort to True to sort reads by queryname
      """
      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()))