compare pairs of sequences
9428
def compare_seqs(seqs):
    
    A, B, ignore_gaps = seqs
    a, b = A[1], B[1] # actual sequences
    if len(a) != len(b):
        print('# reads are not the same length', file=sys.stderr)
        exit()
    if ignore_gaps is True:
        pident = calc_pident_ignore_gaps(a, b)
    else:
        pident = calc_pident(a, b)
    return A[0], B[0], pident
1150462
def match(self, other):
        """"""

        if len(self) != len(other):
            raise ValueError()
        for s1, s2 in zip(self, other):
            i = s2.position - s1.position
            if i < 0:
                return False
            n = len(s1)
            while i+n > len(s2) and s1[n-1] == syntax.BLANK:
                n -= 1
            if s2.values[i:i+n] != s1.values[:n]:
                return False
        return True
260
def max_pairs(shape):
    """"""

    if not isinstance(shape, (tuple, list)):
        x = get_length(shape)
        n = int(x * (x - 1) / 2)

    elif (isinstance(shape, (tuple, list)) and len(shape) == 1):
        x = get_length(shape[0])
        n = int(x * (x - 1) / 2)

    else:
        n = numpy.prod([get_length(xi) for xi in shape])

    return n
1171228
def _is_consistent(pairs, common, clus_seen, loci_similarity):
    
    all_true1 = all([all([common and loci_similarity[(p, c)] > parameters.similar  for p in pairs if (p, c) in loci_similarity]) for c in clus_seen])
    all_true2 = all([all([common and loci_similarity[(c, p)] > parameters.similar  for p in pairs if (c, p) in loci_similarity]) for c in clus_seen])
    return all_true1 * all_true2
729489
def match_rsequence(self, tokens, item):
        """"""
        front, series_type, matches = tokens
        self.add_check("_coconut.isinstance(" + item + ", _coconut.abc.Sequence)")
        self.add_check("_coconut.len(" + item + ") >= " + str(len(matches)))
        if front != wildcard:
            if len(matches):
                splice = "[:" + str(-len(matches)) + "]"
            else:
                splice = ""
            self.assign_to_series(front, series_type, item + splice)
        for i, match in enumerate(matches):
            self.match(match, item + "[" + str(i - len(matches)) + "]")
978806
def compare(ver1, ver2):
    ''''''
    if ver1 == ver2:
        return 0
    ver1 = _cut(ver1)
    ver2 = _cut(ver2)
    # magic multiplier
    m = 1
    # if the first one is shorter, replace them
    if len(ver1) < len(ver2):
        ver1, ver2 = ver2, ver1
        # and reverse magic multiplier
        m = -1
    # compare all items that both have
    for i, part in enumerate(ver2):
        if ver1[i] > ver2[i]:
            return m * 1
        if ver1[i] < ver2[i]:
            return m * -1
    # if the first "extra" item is not negative, it's bigger
    if ver1[len(ver2)] >= 0:
        return m * 1
    else:
        return m * -1
567566
def fasta_files_equal(seq_file1, seq_file2):
    

    # Load already set representative sequence
    seq1 = SeqIO.read(open(seq_file1), 'fasta')

    # Load kegg sequence
    seq2 = SeqIO.read(open(seq_file2), 'fasta')

    # Test equality
    if str(seq1.seq) == str(seq2.seq):
        return True
    else:
        return False
676303
def subsequence?(seq1, seq2)
      i = j = 0
      loop do
        return true if i == seq1.size
        return false if j == seq2.size
        i += 1 if seq1[i] == seq2[j]
        j += 1
      end
    end
1353761
def remove_gaps(A, B):
    
    a_seq, b_seq = [], []
    for a, b in zip(list(A), list(B)):
        if a == '-' or a == '.' or b == '-' or b == '.':
            continue
        a_seq.append(a)
        b_seq.append(b)
    return ''.join(a_seq), ''.join(b_seq)
1245383
def showDifferences(seq1, seq2) :
	
	ret = []
	for i in range(max(len(seq1), len(seq2))) :

		if i >= len(seq1) :
			c1 = '#'
		else :
			c1 = seq1[i]
		if i >= len(seq2) :
			c2 = '#'
		else :
			c2 = seq2[i]

		if c1 != c2 :
			ret.append('%s|%s' % (c1, c2))
		else :
			ret.append('-')

	return ''.join(ret)
536711
def pairwise(iterable):
    ""
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)
211631
def pairwise(values):
    
    i = iter(values)
    a = next(i)

    for b in i:
        yield (a, b)
        a = b
1094875
def is_a_sequence(var, allow_none=False):
    
    return isinstance(var, (list, tuple)) or (var is None and allow_none)
1219585
def match_subgroup(sequence, pattern):
    """"""

    for element in sequence:
        match = re.match(pattern, element)

        if match:
            yield match.groupdict()
362069
def compare_values(values0, values1):
    """"""
    values0 = {v[0]: v[1:] for v in values0}
    values1 = {v[0]: v[1:] for v in values1}

    created = [(k, v[0], v[1]) for k, v in values1.items() if k not in values0]
    deleted = [(k, v[0], v[1]) for k, v in values0.items() if k not in values1]
    modified = [(k, v[0], v[1]) for k, v in values0.items()
                if v != values1.get(k, None)]

    return created, deleted, modified
599145
def get_sequences_from_cluster(c1, c2, data):
    """"""
    seqs1 = data[c1]['seqs']
    seqs2 = data[c2]['seqs']
    seqs = list(set(seqs1 + seqs2))
    names = []
    for s in seqs:
        if s in seqs1 and s in seqs2:
            names.append("both")
        elif s in seqs1:
            names.append(c1)
        else:
            names.append(c2)
    return seqs, names
140377
function compare(buf1, buf2){
    if (buf1.length !== buf2.length)
        return buf1.length - buf2.length;

    for (var i = 0; i < buf1.length; i++)
        if (buf1[i] !== buf2[i])
            return buf1[i] - buf2[i];

    return 0;
}