Yields all pairs drawn from ``seq1`` and ``seq2``.

    If ``seq2`` is ``None``, ``seq2 = seq1``.

        >>> stop_at.ed(all_pairs(xrange(100000), xrange(100000)), 8)
        ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7))
175910
def all_pairs(seq1, seq2=None):
    
    if seq2 is None: seq2 = seq1
    for item1 in seq1:
        for item2 in seq2:
            yield (item1, item2)
655258
function(seq1, seq2, eq){

    var l1 = seq1.length,
        l2 = seq2.length,
        distMap = Array.apply(null, {length: l1 + 1}).map(function(){return [];}),
        stepMap = Array.apply(null, {length: l1 + 1}).map(function(){return [];}),
        i, j;

    eq = eq || defaultEqual;

    for(i = 0; i <= l1; i++){
        for(j = 0; j <= l2; j++){

            if(i === 0 || j === 0){
                distMap[i][j] = i || j;
                stepMap[i][j] = i > 0 ? STEP_REMOVE : STEP_INSERT;

            }else{
                var equal = eq(seq1[i-1], seq2[j-1]),

                    removeDist = distMap[i-1][j] + 1,
                    insertDist = distMap[i][j-1] + 1,
                    replaceDist = distMap[i-1][j-1] + (equal ? 0 : 2),
                    dist = Math.min(replaceDist, removeDist, insertDist);

                distMap[i][j] = dist;

                switch(dist){
                
                case replaceDist:
                    stepMap[i][j] = equal ? STEP_NOCHANGE : STEP_REPLACE;
                    break;
                
                case removeDist:
                    stepMap[i][j] = STEP_REMOVE;
                    break;
                
                case insertDist:
                    stepMap[i][j] = STEP_INSERT;

                }
            }
        }
    }

    return stepMap;
}
547068
def split_by_idxs(seq, idxs):
    ''' '''
    last = 0
    for idx in idxs:
        if not (-len(seq) <= idx < len(seq)):
          raise KeyError(f'Idx {idx} is out-of-bounds')
        yield seq[last:idx]
        last = idx
    yield seq[last:]
1108972
def window(seq, n=2):

    

    it = iter(seq)
    result = tuple(islice(it, n))

    if len(result) == n:
        yield result

    for token in it:
        result = result[1:] + (token,)
        yield result
1023629
def unordered_pair_eq(pair1, pair2):
    '''
    '''
    (x1, y1), (x2, y2) = pair1, pair2
    return (x1 == x2 and y1 == y2) or (x1 == y2 and y1 == x2)
1205244
def Disjunction(expr1: Expression, expr2: Expression) -> Expression:
    """"""
    expr = Expression(ast.BoolOp(ast.Or(), [expr1.body, expr2.body]))
    return ast.fix_missing_locations(expr)
909367
def range_matches(self, other):
        
        return (
            self.begin == other.begin and 
            self.end == other.end
        )
24661
def ambiguate(sequence1, sequence2, delete_ambiguous=False):
    
    delete = False
    combination = list()
    z = list(zip(sequence1, sequence2))
    for (a, b) in z:
        if a == b:
            combination.append(a)
        else:
            if a == '-' or b == '-':
                combination.append('-')
            else:
                if delete_ambiguous:
                    delete = True
                ambig = get_ambiguity(a, b)
                combination.append(ambig)
    if delete:
        return 'X' * len(combination)
    return ''.join(combination)
211631
def pairwise(values):
    
    i = iter(values)
    a = next(i)

    for b in i:
        yield (a, b)
        a = b
527323
def split_seq(sam_num, n_tile):
    
    import math
    print(sam_num)
    print(n_tile)
    start_num = sam_num[0::int(math.ceil(len(sam_num) / (n_tile)))]
    end_num = start_num[1::]
    end_num.append(len(sam_num))
    return [[i, j] for i, j in zip(start_num, end_num)]
1348414
def reading_order(e1, e2):
    
    b1 = e1.bbox
    b2 = e2.bbox
    if round(b1[y0]) == round(b2[y0]) or round(b1[y1]) == round(b2[y1]):
        return float_cmp(b1[x0], b2[x0])
    return float_cmp(b1[y0], b2[y0])
568755
def subCell2DCoords(*args, **kwargs):
    '''
    '''
    for _, _, s0, s1 in subCell2DSlices(*args, **kwargs):
        yield ((s1.start, s1.start, s1.stop),
               (s0.start, s0.stop,  s0.stop))
20023
def truncate_seq_pair(tokens_a, tokens_b, max_num_tokens, rng):
    """"""
    while True:
        total_length = len(tokens_a) + len(tokens_b)
        if total_length <= max_num_tokens:
            break

        trunc_tokens = tokens_a if len(tokens_a) > len(tokens_b) else tokens_b
        assert len(trunc_tokens) >= 1

        # We want to sometimes truncate from the front and sometimes from the
        # back to add more randomness and avoid biases.
        if rng.random() < 0.5:
            del trunc_tokens[0]
        else:
            trunc_tokens.pop()
36388
def match(self, seq, **kwargs):
        '''
        '''
        strict = kwargs.get('strict', False)
        top_level = kwargs.get('top_level', True)
        match = kwargs.get('match', list())

        if top_level:
            kwargs['top_level'] = False
            kwargs['match'] = match

            try:
                seq = IterableList(seq)
                self.match(seq, **kwargs)

                if strict:
                    if not seq.empty():
                        raise MatchFailed('Sequence is too long', seq)

            except MatchFailed as e:
                return e.failure()

            return Match(*match)

        for elem in self.elems:
            elem.match(seq, **kwargs)
1207890
def get_pair(self, term1, term2):

        

        key = self.key(term1, term2)
        return self.pairs.get(key, None)
961494
def findCodons(seq, codons):
    
    seqLen = len(seq)
    start = 0
    while start < seqLen:
        triplet = str(seq[start:start + 3])
        if triplet in codons:
            yield start
        start = start + 3
932733
def pair_looper(iterator):
    '''
    
    '''
    left = START
    for item in iterator:
        if left is not START:
            yield (left, item)
        left = item