nodes: 0, module; 1, function_definition; 2, function_name:intersect_range_array; 3, parameters; 4, block; 5, identifier:bed1; 6, identifier:beds2; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, for_statement; 13, if_statement; 14, return_statement; 15, identifier:payload; 16, None; 17, identifier:is_sorted; 18, False; 19, comment:""" Does not do a merge if the payload has been set
  
    :param bed1:
    :param bed2:
    :param payload: payload=1 return the payload of bed1 on each of the intersect set, payload=2 return the payload of bed2 on each of the union set, payload=3 return the payload of bed1 and bed2 on each of the union set
    :param is_sorted:
    :type bed1: GenomicRange
    :type bed2: GenomicRange
    :type payload: int
    :type is_sorted: bool
    """; 20, not_operator; 21, block; 22, assignment; 23, identifier:bed2; 24, identifier:beds2; 25, block; 26, identifier:payload; 27, block; 28, call; 29, identifier:is_sorted; 30, expression_statement; 31, identifier:output; 32, list; 33, expression_statement; 34, comment:#print str(cval)+" "+bed1.get_range_string()+" "+bed2.get_range_string(); 35, if_statement; 36, return_statement; 37, identifier:merge_ranges; 38, argument_list; 39, assignment; 40, assignment; 41, comparison_operator:cval == -1; 42, block; 43, elif_clause; 44, elif_clause; 45, call; 46, identifier:output; 47, identifier:beds2; 48, call; 49, identifier:cval; 50, call; 51, identifier:cval; 52, unary_operator; 53, continue_statement; 54, comparison_operator:cval == 0; 55, block; 56, comparison_operator:cval == 1; 57, block; 58, identifier:sort_ranges; 59, argument_list; 60, identifier:sort_ranges; 61, argument_list; 62, attribute; 63, argument_list; 64, integer:1; 65, identifier:cval; 66, integer:0; 67, expression_statement; 68, if_statement; 69, if_statement; 70, identifier:cval; 71, integer:1; 72, break_statement; 73, identifier:output; 74, identifier:beds2; 75, identifier:bed2; 76, identifier:cmp; 77, identifier:bed1; 78, call; 79, comparison_operator:payload==1; 80, block; 81, comparison_operator:payload==2; 82, block; 83, attribute; 84, argument_list; 85, identifier:payload; 86, integer:1; 87, expression_statement; 88, identifier:payload; 89, integer:2; 90, expression_statement; 91, identifier:output; 92, identifier:append; 93, call; 94, call; 95, call; 96, attribute; 97, argument_list; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, identifier:bed1; 103, identifier:intersect; 104, identifier:bed2; 105, subscript; 106, identifier:set_payload; 107, attribute; 108, subscript; 109, identifier:set_payload; 110, attribute; 111, identifier:output; 112, unary_operator; 113, identifier:bed1; 114, identifier:payload; 115, identifier:output; 116, unary_operator; 117, identifier:bed2; 118, identifier:payload; 119, integer:1; 120, integer:1
code: def intersect_range_array(bed1,beds2,payload=None,is_sorted=False):
    """ Does not do a merge if the payload has been set
  
    :param bed1:
    :param bed2:
    :param payload: payload=1 return the payload of bed1 on each of the intersect set, payload=2 return the payload of bed2 on each of the union set, payload=3 return the payload of bed1 and bed2 on each of the union set
    :param is_sorted:
    :type bed1: GenomicRange
    :type bed2: GenomicRange
    :type payload: int
    :type is_sorted: bool
    """
    if not is_sorted: beds2 = sort_ranges(beds2)
    output = []
    for bed2 in beds2:
      cval = bed2.cmp(bed1)
      #print str(cval)+" "+bed1.get_range_string()+" "+bed2.get_range_string()
      if cval == -1: continue
      elif cval == 0:
        output.append(bed1.intersect(bed2))
        if payload==1:
          output[-1].set_payload(bed1.payload)
        if payload==2:
          output[-1].set_payload(bed2.payload)
      elif cval == 1: break
    if payload: return sort_ranges(output)
    return merge_ranges(output)