Compute absolute identity (# matching sites) between sequence strings.
425587
def identity_abs(aseq, bseq):
    """"""
    assert len(aseq) == len(bseq)
    return sum(a == b
               for a, b in zip(aseq, bseq)
               if not (a in '-.' and b in '-.'))
979082
def to_match(self):
        """"""
        self.validate()

        mark_name, field_name = self.location.get_location_name()
        validate_safe_string(mark_name)
        validate_safe_string(field_name)

        return u'%s.%s' % (mark_name, field_name)
714493
def _match(filtered, matcher):
    """"""

    def match_filtered_identities(x, ids, matcher):
        """Check if an identity matches a set of identities"""

        for y in ids:
            if x.uuid == y.uuid:
                return True
            if matcher.match_filtered_identities(x, y):
                return True
        return False

    # Find subsets of matches
    matched = []

    while filtered:
        candidates = []
        no_match = []

        x = filtered.pop(0)

        while matched:
            ids = matched.pop(0)

            if match_filtered_identities(x, ids, matcher):
                candidates += ids
            else:
                no_match.append(ids)

        candidates.append(x)

        # Generate the new list of matched subsets
        matched = [candidates] + no_match

    return matched
682911
def match_unit(data, p, m='a'):
    """"""
    if data is None:
        return p is None

    # compile search value only once for non exact search
    if m != 'e' and isinstance(p, six.string_types):
        p = re.compile(p)

    if isinstance(data, Sequence) and not isinstance(data, six.string_types):
        return any([match_unit(field, p, m=m)
                    for field in data])
    elif isinstance(data, MutableMapping):
        return any([match_unit(field, p, m=m)
                    for field in data.values()])

    # Inclusive range query
    if isinstance(p, tuple):
        left, right = p
        return (left <= data) and (data <= right)

    if m == 'e':
        return six.text_type(data) == p
    return p.search(six.text_type(data)) is not None
1217312
def similarities(string_a, *string_b)
      [*string_b].map { |word| [word, matches[word] = similarity(string_a, word)] }
    end
342942
def _namematcher(regex):
    """"""

    matcher = re_compile(regex)

    def match(target):
        target_name = getattr(target, '__name__', '')
        result = matcher.match(target_name)
        return result

    return match
282488
def matches_pattern(self, other):
        """"""
        matches = False
        if hasattr(other, 'addr'):
            if self.addr is None or other.addr is None:
                matches = True
            else:
                matches = self.addr == other.addr
        return matches
764974
def get_bool_relative(strings: Sequence[str],
                      prefix1: str,
                      delta: int,
                      prefix2: str,
                      ignoreleadingcolon: bool = False) -> Optional[bool]:
    
    return get_bool_raw(get_string_relative(
        strings, prefix1, delta, prefix2,
        ignoreleadingcolon=ignoreleadingcolon))
636723
def char_matches(s1, s2, n=3):
    
    return __matches(s1, s2, char_ngrams, n=n)
885693
def match_mstring(self, tokens, item, use_bytes=None):
        """"""
        prefix, name, suffix = tokens
        if use_bytes is None:
            if prefix.startswith("b") or suffix.startswith("b"):
                if prefix.startswith("b") and suffix.startswith("b"):
                    use_bytes = True
                else:
                    raise CoconutDeferredSyntaxError("string literals and byte literals cannot be added in patterns", self.loc)
        if use_bytes:
            self.add_check("_coconut.isinstance(" + item + ", _coconut.bytes)")
        else:
            self.add_check("_coconut.isinstance(" + item + ", _coconut.str)")
        if prefix is not None:
            self.add_check(item + ".startswith(" + prefix + ")")
        if suffix is not None:
            self.add_check(item + ".endswith(" + suffix + ")")
        if name != wildcard:
            self.add_def(
                name + " = " + item + "[" +
                ("" if prefix is None else "_coconut.len(" + prefix + ")") + ":"
                + ("" if suffix is None else "-_coconut.len(" + suffix + ")") + "]",
            )
1219585
def match_subgroup(sequence, pattern):
    """"""

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

        if match:
            yield match.groupdict()
298985
def str_matcher(mode):
    

    def f_raw(inp_str, pos):
        return unique_literal_cache_pool[mode] if inp_str.startswith(mode, pos) else None

    def f_collection(inp_str, pos):
        for each in mode:
            if inp_str.startswith(each, pos):
                return unique_literal_cache_pool[each]
        return None

    if isinstance(mode, str):
        return f_raw

    if len(mode) is 1:
        mode = mode[0]
        return f_raw

    return f_collection
604848
def locate(self, pattern):
        '''

        '''
        if self.circular:
            if len(pattern) >= 2 * len(self):
                raise ValueError('Search pattern longer than searchable ' +
                                 'sequence.')
            seq = self + self[:len(pattern) - 1]
            return super(NucleicAcid, seq).locate(pattern)
        else:
            return super(NucleicAcid, self).locate(pattern)
1239652
def find_near_matches_substitutions(subsequence, sequence, max_substitutions):
    
    _check_arguments(subsequence, sequence, max_substitutions)

    if max_substitutions == 0:
        return [
            Match(start_index, start_index + len(subsequence), 0)
            for start_index in search_exact(subsequence, sequence)
        ]

    elif len(subsequence) // (max_substitutions + 1) >= 3:
        return find_near_matches_substitutions_ngrams(
            subsequence, sequence, max_substitutions,
        )

    else:
        return find_near_matches_substitutions_lp(
            subsequence, sequence, max_substitutions,
        )
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)) + "]")
375518
def _anonymous_match(self, struct1, struct2, fu, s1_supercell=True,
                         use_rms=False, break_on_match=False, single_match=False):
        
        if not isinstance(self._comparator, SpeciesComparator):
            raise ValueError('Anonymous fitting currently requires SpeciesComparator')

        # check that species lists are comparable
        sp1 = struct1.composition.elements
        sp2 = struct2.composition.elements
        if len(sp1) != len(sp2):
            return None

        ratio = fu if s1_supercell else 1/fu
        swapped = len(struct1) * ratio < len(struct2)

        s1_comp = struct1.composition
        s2_comp = struct2.composition
        matches = []
        for perm in itertools.permutations(sp2):
            sp_mapping = dict(zip(sp1, perm))

            # do quick check that compositions are compatible
            mapped_comp = Composition({sp_mapping[k]: v
                                       for k, v in s1_comp.items()})
            if (not self._subset) and (
                    self._comparator.get_hash(mapped_comp) !=
                    self._comparator.get_hash(s2_comp)):
                continue

            mapped_struct = struct1.copy()
            mapped_struct.replace_species(sp_mapping)
            if swapped:
                m = self._strict_match(struct2, mapped_struct, fu,
                                       (not s1_supercell), use_rms,
                                       break_on_match)
            else:
                m = self._strict_match(mapped_struct, struct2, fu, s1_supercell,
                                       use_rms, break_on_match)
            if m:
                matches.append((sp_mapping, m))
                if single_match:
                    break
        return matches
288288
def ref_string_matches_ref_sequence(self, ref_sequence):
        ''''''
        # you never know what you're gonna get...
        if self.POS < 0:
            return False

        end_pos = self.ref_end_pos()
        if end_pos >= len(ref_sequence):
            return False

        return self.REF == ref_sequence[self.POS:end_pos + 1]