Calculate overlap count between the values of two dictionaries

    Note: dict values must be sets
494294
def _calc_overlap_count(
    markers1: dict,
    markers2: dict,
):
    
    overlaps=np.zeros((len(markers1), len(markers2)))

    j=0
    for marker_group in markers1:
        tmp = [len(markers2[i].intersection(markers1[marker_group])) for i in markers2.keys()]
        overlaps[j,:] = tmp
        j += 1

    return overlaps
325789
def check_overlap(pos, ins, thresh):
    
    ins_pos = ins[0]
    ins_len = ins[2]
    ol = overlap(ins_pos, pos)
    feat_len = pos[1] - pos[0] + 1
#    print float(ol) / float(feat_len)
    if float(ol) / float(feat_len) >= thresh:
        return True
    return False
793459
def isetdiff_flags(list1, list2):
    
    set2 = set(list2)
    return (item not in set2 for item in list1)
834694
def _compare_match(dict1, dict2):
    '''
    
    '''
    for karg, warg in six.iteritems(dict1):
        if karg in dict2 and dict2[karg] != warg:
            return False
    return True
1150342
def merge_dict(a, b):
    
    c = a.copy()
    c.update(b)
    return c
380669
def intersects_all(self, other):
		
		return all(key in self and self[key].intersects(value) for key, value in other.iteritems()) and bool(other)
956005
def subtract(dict_a, dict_b, strict=False):
    """"""
    if not strict:
        return subtract_by_key(dict_a, dict_b)

    difference_dict = {}
    for key in dict_a:
        if key not in dict_b or dict_b[key] != dict_a[key]:
            difference_dict[key] = dict_a[key]

    return difference_dict
1241974
def intersect(d1, d2):
    """"""
    return dict((k, d1[k]) for k in d1 if k in d2 and d1[k] == d2[k])
934137
def merge_dicts(d1, d2):
    
    for k in set(d1.keys()).union(d2.keys()):
        if k in d1 and k in d2:
            if isinstance(d1[k], dict) and isinstance(d2[k], dict):
                yield (k, dict(merge_dicts(d1[k], d2[k])))
            elif isinstance(d1[k], list):
                if isinstance(d2[k], list):
                    d1[k].extend(d2[k])
                else:
                    d1[k].append(d2[k])
                yield(k, d1)
            else:
                # If one of the values is not a dict, you can't continue merging it.
                # Value from second dict overrides one in first and we move on.
                yield (k, d2[k])
                # Alternatively, replace this with exception raiser to alert you of value conflicts
        elif k in d1:
            yield (k, d1[k])
        else:
            yield (k, d2[k])
1085311
def _merge_unbound_var_dicts(src, dst):
  """"""
  for k, v in six.iteritems(src):
    if dst.get(k, v) != v:
      trace1 = ''.join(scopes.skip_common_stack_elements(v.stacktrace, dst[
          k].stacktrace))
      trace2 = ''.join(
          scopes.skip_common_stack_elements(dst[k].stacktrace, v.stacktrace))
      raise ValueError('Key conflict: %s\nDefined At:\n%s\nand\n%s' %
                       (k, trace1, trace2))
    else:
      dst[k] = v
243198
def overlap(xl1, yl1, nx1, ny1, xl2, yl2, nx2, ny2):
    
    return (xl2 < xl1+nx1 and xl2+nx2 > xl1 and
            yl2 < yl1+ny1 and yl2+ny2 > yl1)
1128455
def get_overlaps(self) -> "IntervalList":
        
        overlaps = IntervalList()
        for i in range(len(self.intervals)):
            for j in range(i + 1, len(self.intervals)):
                first = self.intervals[i]
                second = self.intervals[j]
                ol = first.intersection(second)
                if ol is not None:
                    overlaps.add(ol)
        return overlaps
371880
def overlap(intv1, intv2):
    """"""
    return max(0, min(intv1[1], intv2[1]) - max(intv1[0], intv2[0]))
571851
def intersection(self, other, ignore_conflicts=False):
        """"""
        result = self.copy()
        result.intersection_update(other, ignore_conflicts)
        return result
454437
def overlap(self, x, ctrs, kdtree=None):
        """"""

        q = len(self.within(x, ctrs, kdtree=kdtree))

        return q
88299
function(gt, or) {

		var or1 = or.values[0],
			or2 = or.values[1];
		var difference1 = set.difference(gt, or1);
		var difference2 = set.difference(gt, or2);
		return set.intersection(difference1, difference2);
	}
245256
def interval_overlap(a, b, x, y):
    """"""
    if b <= x or a >= y:
        return 0
    elif x <= a <= y:
        return min(b, y) - a
    elif x <= b <= y:
        return b - max(a, x)
    elif a >= x and b <= y:
        return b - a
    else:
        assert False