nodes: 0, module; 1, function_definition; 2, function_name:beds_to_boolean; 3, parameters; 4, block; 5, identifier:beds; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, dictionary_splat_pattern; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, for_statement; 20, return_statement; 21, identifier:ref; 22, None; 23, identifier:beds_sorted; 24, False; 25, identifier:ref_sorted; 26, False; 27, identifier:kwargs; 28, comment:"""
      Compare a list of bed files or BedTool objects to a reference bed file and
      create a boolean matrix where each row is an interval and each column is a 1
      if that file has an interval that overlaps the row interval and a 0
      otherwise. If no reference bed is provided, the provided bed files will be
      merged into a single bed and compared to that.
  
      Parameters
      ----------
      beds : list
          List of paths to bed files or BedTool objects.
  
      ref : str or BedTool
          Reference bed file to compare against. If no reference bed is provided,
          the provided bed files will be merged into a single bed and compared to
          that.
  
      beds_sorted : boolean
          Whether the bed files in beds are already sorted. If False, all bed
          files in beds will be sorted.
  
      ref_sorted : boolean
          Whether the reference bed file is sorted. If False, ref will be sorted.
  
      names : list of strings
          Names to use for columns of output files. Overrides define_sample_name 
          if provided.
  
      define_sample_name : function that takes string as input
          Function mapping filename to sample name (or basename). For instance,
          you may have the basename in the path and use a regex to extract it.
          The basenames will be used as the column names. If this is not provided,
          the columns will be named as the input files.
  
      Returns
      -------
      out : pandas.DataFrame
          Boolean data frame indicating whether each bed file has an interval
          that overlaps each interval in the reference bed file. 
  
      """; 29, assignment; 30, assignment; 31, pattern_list; 32, call; 33, block; 34, assignment; 35, identifier:ref; 36, block; 37, else_clause; 38, assignment; 39, identifier:r; 40, identifier:ref; 41, block; 42, assignment; 43, pattern_list; 44, call; 45, block; 46, identifier:bdf; 47, identifier:beds; 48, call; 49, identifier:fns; 50, list; 51, identifier:i; 52, identifier:v; 53, identifier:enumerate; 54, argument_list; 55, if_statement; 56, if_statement; 57, identifier:names; 58, call; 59, if_statement; 60, if_statement; 61, block; 62, identifier:ind; 63, list; 64, expression_statement; 65, identifier:bdf; 66, call; 67, identifier:i; 68, identifier:bed; 69, identifier:enumerate; 70, argument_list; 71, expression_statement; 72, expression_statement; 73, for_statement; 74, expression_statement; 75, attribute; 76, argument_list; 77, identifier:beds; 78, comparison_operator:type(v) == str; 79, block; 80, else_clause; 81, not_operator; 82, block; 83, identifier:_sample_names; 84, argument_list; 85, comparison_operator:type(ref) == str; 86, block; 87, not_operator; 88, block; 89, expression_statement; 90, call; 91, attribute; 92, argument_list; 93, identifier:beds; 94, assignment; 95, assignment; 96, identifier:r; 97, identifier:res; 98, block; 99, assignment; 100, identifier:copy; 101, identifier:deepcopy; 102, identifier:beds; 103, call; 104, identifier:str; 105, expression_statement; 106, expression_statement; 107, block; 108, identifier:beds_sorted; 109, expression_statement; 110, identifier:fns; 111, identifier:kwargs; 112, call; 113, identifier:str; 114, expression_statement; 115, identifier:ref_sorted; 116, expression_statement; 117, assignment; 118, attribute; 119, argument_list; 120, identifier:pd; 121, identifier:DataFrame; 122, integer:0; 123, keyword_argument; 124, keyword_argument; 125, identifier:res; 126, call; 127, identifier:ind; 128, list; 129, expression_statement; 130, subscript; 131, integer:1; 132, identifier:type; 133, argument_list; 134, call; 135, assignment; 136, expression_statement; 137, assignment; 138, identifier:type; 139, argument_list; 140, assignment; 141, assignment; 142, identifier:ref; 143, call; 144, identifier:ind; 145, identifier:append; 146, call; 147, identifier:index; 148, identifier:ind; 149, identifier:columns; 150, identifier:names; 151, attribute; 152, argument_list; 153, call; 154, attribute; 155, identifier:ind; 156, subscript; 157, identifier:v; 158, attribute; 159, argument_list; 160, subscript; 161, call; 162, call; 163, subscript; 164, call; 165, identifier:ref; 166, identifier:ref; 167, call; 168, identifier:ref; 169, call; 170, identifier:combine; 171, argument_list; 172, attribute; 173, argument_list; 174, identifier:ref; 175, identifier:intersect; 176, identifier:bed; 177, keyword_argument; 178, keyword_argument; 179, attribute; 180, argument_list; 181, identifier:bdf; 182, identifier:ix; 183, identifier:names; 184, identifier:i; 185, identifier:fns; 186, identifier:append; 187, identifier:v; 188, identifier:beds; 189, identifier:i; 190, attribute; 191, argument_list; 192, attribute; 193, argument_list; 194, identifier:beds; 195, identifier:i; 196, attribute; 197, argument_list; 198, attribute; 199, argument_list; 200, attribute; 201, argument_list; 202, identifier:beds; 203, string; 204, identifier:format; 205, attribute; 206, attribute; 207, attribute; 208, identifier:sorted; 209, True; 210, identifier:wa; 211, True; 212, identifier:ind; 213, identifier:append; 214, call; 215, identifier:pbt; 216, identifier:BedTool; 217, identifier:v; 218, identifier:fns; 219, identifier:append; 220, attribute; 221, subscript; 222, identifier:sort; 223, identifier:pbt; 224, identifier:BedTool; 225, identifier:ref; 226, identifier:ref; 227, identifier:sort; 228, string_content:{}:{}-{}; 229, identifier:r; 230, identifier:chrom; 231, identifier:r; 232, identifier:start; 233, identifier:r; 234, identifier:stop; 235, attribute; 236, argument_list; 237, identifier:v; 238, identifier:fn; 239, identifier:beds; 240, identifier:i; 241, string; 242, identifier:format; 243, attribute; 244, attribute; 245, attribute; 246, string_content:{}:{}-{}; 247, identifier:r; 248, identifier:chrom; 249, identifier:r; 250, identifier:start; 251, identifier:r; 252, identifier:stop
code: def beds_to_boolean(beds, ref=None, beds_sorted=False, ref_sorted=False,
                      **kwargs):
      """
      Compare a list of bed files or BedTool objects to a reference bed file and
      create a boolean matrix where each row is an interval and each column is a 1
      if that file has an interval that overlaps the row interval and a 0
      otherwise. If no reference bed is provided, the provided bed files will be
      merged into a single bed and compared to that.
  
      Parameters
      ----------
      beds : list
          List of paths to bed files or BedTool objects.
  
      ref : str or BedTool
          Reference bed file to compare against. If no reference bed is provided,
          the provided bed files will be merged into a single bed and compared to
          that.
  
      beds_sorted : boolean
          Whether the bed files in beds are already sorted. If False, all bed
          files in beds will be sorted.
  
      ref_sorted : boolean
          Whether the reference bed file is sorted. If False, ref will be sorted.
  
      names : list of strings
          Names to use for columns of output files. Overrides define_sample_name 
          if provided.
  
      define_sample_name : function that takes string as input
          Function mapping filename to sample name (or basename). For instance,
          you may have the basename in the path and use a regex to extract it.
          The basenames will be used as the column names. If this is not provided,
          the columns will be named as the input files.
  
      Returns
      -------
      out : pandas.DataFrame
          Boolean data frame indicating whether each bed file has an interval
          that overlaps each interval in the reference bed file. 
  
      """
      beds = copy.deepcopy(beds)
      fns = []
      for i,v in enumerate(beds):
          if type(v) == str:
              fns.append(v)
              beds[i] = pbt.BedTool(v)
          else:
              fns.append(v.fn)
          if not beds_sorted:
              beds[i] = beds[i].sort()
  
      names = _sample_names(fns, kwargs)
      if ref:
          if type(ref) == str:
              ref = pbt.BedTool(ref)
          if not ref_sorted:
              ref = ref.sort()
      else:
          ref = combine(beds)
      
      ind = []
      for r in ref:
          ind.append('{}:{}-{}'.format(r.chrom, r.start, r.stop))
      bdf = pd.DataFrame(0, index=ind, columns=names)
      for i,bed in enumerate(beds):
          res = ref.intersect(bed, sorted=True, wa=True)
          ind = []
          for r in res:
              ind.append('{}:{}-{}'.format(r.chrom,
                                           r.start,
                                           r.stop))
          bdf.ix[ind, names[i]] = 1
      return bdf