nodes: 0, module; 1, function_definition; 2, function_name:concat; 3, parameters; 4, block; 5, identifier:bed_files; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, identifier:catted; 13, None; 14, comment:"""
      recursively concat a set of BED files, returning a
      sorted bedtools object of the result
      """; 15, assignment; 16, comparison_operator:len(bed_files) == 0; 17, block; 18, not_operator; 19, block; 20, else_clause; 21, call; 22, identifier:bed_files; 23, list_comprehension; 24, call; 25, integer:0; 26, if_statement; 27, identifier:catted; 28, expression_statement; 29, expression_statement; 30, block; 31, identifier:concat; 32, argument_list; 33, identifier:x; 34, for_in_clause; 35, if_clause; 36, identifier:len; 37, argument_list; 38, identifier:catted; 39, comment:# move to a .bed extension for downstream tools if not already; 40, block; 41, else_clause; 42, assignment; 43, assignment; 44, expression_statement; 45, identifier:bed_files; 46, identifier:catted; 47, identifier:x; 48, identifier:bed_files; 49, identifier:x; 50, identifier:bed_files; 51, expression_statement; 52, if_statement; 53, block; 54, identifier:bed_files; 55, call; 56, identifier:catted; 57, call; 58, assignment; 59, assignment; 60, not_operator; 61, block; 62, else_clause; 63, return_statement; 64, identifier:list; 65, argument_list; 66, attribute; 67, argument_list; 68, identifier:catted; 69, call; 70, identifier:sorted_bed; 71, call; 72, call; 73, return_statement; 74, block; 75, identifier:catted; 76, identifier:bed_files; 77, identifier:bt; 78, identifier:BedTool; 79, call; 80, attribute; 81, argument_list; 82, attribute; 83, argument_list; 84, attribute; 85, argument_list; 86, call; 87, return_statement; 88, attribute; 89, argument_list; 90, identifier:catted; 91, identifier:cat; 92, call; 93, keyword_argument; 94, keyword_argument; 95, identifier:catted; 96, identifier:sort; 97, attribute; 98, identifier:endswith; 99, string:".bed"; 100, attribute; 101, argument_list; 102, identifier:sorted_bed; 103, identifier:bed_files; 104, identifier:pop; 105, attribute; 106, argument_list; 107, identifier:postmerge; 108, False; 109, identifier:force_truncate; 110, False; 111, identifier:sorted_bed; 112, identifier:fn; 113, identifier:sorted_bed; 114, identifier:moveto; 115, binary_operator:sorted_bed.fn + ".bed"; 116, identifier:bed_files; 117, identifier:pop; 118, attribute; 119, string:".bed"; 120, identifier:sorted_bed; 121, identifier:fn
code: def concat(bed_files, catted=None):
      """
      recursively concat a set of BED files, returning a
      sorted bedtools object of the result
      """
      bed_files = [x for x in bed_files if x]
      if len(bed_files) == 0:
          if catted:
              # move to a .bed extension for downstream tools if not already
              sorted_bed = catted.sort()
              if not sorted_bed.fn.endswith(".bed"):
                  return sorted_bed.moveto(sorted_bed.fn + ".bed")
              else:
                  return sorted_bed
          else:
              return catted
  
      if not catted:
          bed_files = list(bed_files)
          catted = bt.BedTool(bed_files.pop())
      else:
          catted = catted.cat(bed_files.pop(), postmerge=False,
                              force_truncate=False)
  
      return concat(bed_files, catted)