nodes: 0, module; 1, function_definition; 2, function_name:picard_sort; 3, parameters; 4, block; 5, identifier:picard; 6, identifier:align_bam; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, if_statement; 15, return_statement; 16, identifier:sort_order; 17, string:"coordinate"; 18, identifier:out_file; 19, None; 20, identifier:compression_level; 21, None; 22, identifier:pipe; 23, False; 24, comment:"""Sort a BAM file by coordinates.
      """; 25, assignment; 26, comparison_operator:out_file is None; 27, block; 28, not_operator; 29, block; 30, identifier:out_file; 31, pattern_list; 32, call; 33, identifier:out_file; 34, None; 35, expression_statement; 36, call; 37, with_statement; 38, identifier:base; 39, identifier:ext; 40, attribute; 41, argument_list; 42, assignment; 43, identifier:file_exists; 44, argument_list; 45, with_clause; 46, block; 47, attribute; 48, identifier:splitext; 49, identifier:align_bam; 50, identifier:out_file; 51, binary_operator:"%s-sort%s" % (base, ext); 52, identifier:out_file; 53, with_item; 54, with_statement; 55, identifier:os; 56, identifier:path; 57, string:"%s-sort%s"; 58, tuple; 59, as_pattern; 60, with_clause; 61, block; 62, identifier:base; 63, identifier:ext; 64, call; 65, as_pattern_target; 66, with_item; 67, expression_statement; 68, if_statement; 69, expression_statement; 70, identifier:tx_tmpdir; 71, argument_list; 72, identifier:tmp_dir; 73, as_pattern; 74, assignment; 75, identifier:compression_level; 76, block; 77, call; 78, attribute; 79, call; 80, as_pattern_target; 81, identifier:opts; 82, list; 83, expression_statement; 84, attribute; 85, argument_list; 86, identifier:picard; 87, identifier:_config; 88, identifier:file_transaction; 89, argument_list; 90, identifier:tx_out_file; 91, tuple; 92, tuple; 93, tuple; 94, tuple; 95, call; 96, identifier:picard; 97, identifier:run; 98, string:"SortSam"; 99, identifier:opts; 100, keyword_argument; 101, attribute; 102, identifier:out_file; 103, string:"INPUT"; 104, identifier:align_bam; 105, string:"OUTPUT"; 106, conditional_expression:out_file if pipe else tx_out_file; 107, string:"TMP_DIR"; 108, identifier:tmp_dir; 109, string:"SORT_ORDER"; 110, identifier:sort_order; 111, attribute; 112, argument_list; 113, identifier:pipe; 114, identifier:pipe; 115, identifier:picard; 116, identifier:_config; 117, identifier:out_file; 118, identifier:pipe; 119, identifier:tx_out_file; 120, identifier:opts; 121, identifier:append; 122, tuple; 123, string:"COMPRESSION_LEVEL"; 124, identifier:compression_level
code: def picard_sort(picard, align_bam, sort_order="coordinate",
                  out_file=None, compression_level=None, pipe=False):
      """Sort a BAM file by coordinates.
      """
      base, ext = os.path.splitext(align_bam)
      if out_file is None:
          out_file = "%s-sort%s" % (base, ext)
      if not file_exists(out_file):
          with tx_tmpdir(picard._config) as tmp_dir:
              with file_transaction(picard._config, out_file) as tx_out_file:
                  opts = [("INPUT", align_bam),
                          ("OUTPUT", out_file if pipe else tx_out_file),
                          ("TMP_DIR", tmp_dir),
                          ("SORT_ORDER", sort_order)]
                  if compression_level:
                      opts.append(("COMPRESSION_LEVEL", compression_level))
                  picard.run("SortSam", opts, pipe=pipe)
      return out_file