def _parse_substring(allele, pred, max_len=None):
    result = ""
    pos = 0
    if max_len is None:
        max_len = len(allele)
    else:
        max_len = min(max_len, len(allele))
    while pos < max_len and pred(allele[pos]):
        result += allele[pos]
        pos += 1
    return result, allele[pos:]
Extract substring of letters for which predicate is True
dataset/ETHPy150Open hammerlab/mhctools/mhctools/alleles.py/_parse_substring