nodes: 0, module; 1, function_definition; 2, function_name:_prepare_bam_file; 3, parameters; 4, block; 5, identifier:bam_file; 6, identifier:tmp_dir; 7, identifier:config; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, return_statement; 12, comment:"""
      Pipe sort by name cmd in case sort by coordinates
      """; 13, assignment; 14, comparison_operator:sort_mode != "queryname"; 15, block; 16, identifier:bam_file; 17, identifier:sort_mode; 18, call; 19, identifier:sort_mode; 20, string:"queryname"; 21, expression_statement; 22, identifier:_get_sort_order; 23, argument_list; 24, assignment; 25, identifier:bam_file; 26, identifier:config; 27, identifier:bam_file; 28, call; 29, identifier:sort; 30, argument_list; 31, identifier:bam_file; 32, identifier:config; 33, string:"queryname"
code: def _prepare_bam_file(bam_file, tmp_dir, config):
      """
      Pipe sort by name cmd in case sort by coordinates
      """
      sort_mode = _get_sort_order(bam_file, config)
      if sort_mode != "queryname":
          bam_file = sort(bam_file, config, "queryname")
      return bam_file