Reverse a SeqIO sequence, but keep its name intact.
490367
def reverse_compl_with_name(old_seq):
    """"""
    new_seq = old_seq.reverse_complement()
    new_seq.id = old_seq.id
    new_seq.description = old_seq.description
    return new_seq
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()
1113394
def unrank(n, sequence=string.ascii_lowercase):
    
    return list(map(sequence.__getitem__, indexes(n)))
569030
def do_last(environment, seq):
    """"""
    try:
        return next(iter(reversed(seq)))
    except StopIteration:
        return environment.undefined('No last item, sequence was empty.')
230011
def dePrefixAndSuffixFasta(sequences):
    
    sequences = sorted(sequences, key=lambda s: len(s.seq), reverse=True)
    seen = set()
    for s in sequences:
        thisSeq = str(s.seq)
        thisHash = md5(thisSeq.encode('UTF-8')).digest()
        if thisHash not in seen:
            # Add prefixes.
            newHash = md5()
            for nucl in thisSeq:
                newHash.update(nucl.encode('UTF-8'))
                seen.add(newHash.digest())
            # Add suffixes.
            for start in range(len(thisSeq) - 1):
                seen.add(md5(thisSeq[start + 1:].encode('UTF-8')).digest())
            yield s
1221436
def subseq(start_offset=0, end_offset=None):
    
    def _(sequence):
        return sequence.subseq(start_offset, end_offset)
    return _
821694
def unique(seq):
    """"""
    cleaned = []
    for each in seq:
        if each not in cleaned:
            cleaned.append(each)
    return cleaned
1044703
def normalize(cls, name):
        """"""
        name = name.lower() # lower-case
        for _replace in [' ','-','(',')','?']:
            name = name.replace(_replace,'')
        return name
737503
def normalize(location_name, preserve_commas=False):
    """"""
    def replace(match):
        if preserve_commas and ',' in match.group(0):
            return ','
        return ' '
    return NORMALIZATION_RE.sub(replace, location_name).strip().lower()
821064
def Reverse(self, y):
        """"""
        return self._Bisect(y, self.ys, self.xs)
1006874
def prune_overridden(ansi_string):
    
    multi_seqs = set(p for p in RE_ANSI.findall(ansi_string) if ';' in p[1])  # Sequences with multiple color codes.

    for escape, codes in multi_seqs:
        r_codes = list(reversed(codes.split(';')))

        # Nuke everything before {/all}.
        try:
            r_codes = r_codes[:r_codes.index('0') + 1]
        except ValueError:
            pass

        # Thin out groups.
        for group in CODE_GROUPS:
            for pos in reversed([i for i, n in enumerate(r_codes) if n in group][1:]):
                r_codes.pop(pos)

        # Done.
        reduced_codes = ';'.join(sorted(r_codes, key=int))
        if codes != reduced_codes:
            ansi_string = ansi_string.replace(escape, '\033[' + reduced_codes + 'm')

    return ansi_string
638389
def _restrict_sequence(self):
        """"""

        if self.pathname:
            value = self.seq_path_dot if self.after_start and not self.dot else self.seq_path
            if self.after_start:
                value = self.no_dir + value
        else:
            value = _NO_DOT if self.after_start and not self.dot else ""
        self.reset_dir_track()

        return value
763663
def reverseComplement(self):
        
        quality = None if self.quality is None else self.quality[::-1]
        sequence = self.sequence.translate(self.COMPLEMENT_TABLE)[::-1]
        return self.__class__(self.id, sequence, quality)
52229
def reverse_last_first(self, name):
        
        # make sure we don't put a suffix in the middle, as in "Smith, Tom II"
        name, suffix = self.extract_suffix(name)

        split = re.split(', ?', name)

        # make sure that the comma is not just preceding a suffix, such as "Jr",
        # by checking that we have at least 2 name parts and the last doesn't match
        # our suffix regex
        if len(split) >= 2:
            split.reverse()

        if suffix:
            split.append(suffix)

        return ' '.join(split)
976019
def unconsume(self, seq):
        ''''''
        for kmer in iter_kmers(seq, self.k, canonical=self.canonical):
            self._decr(kmer)
191303
def reverse(args):
  """"""

  from .query import Database
  db = Database()

  output = sys.stdout
  if args.selftest:
    from bob.db.utils import null
    output = null()

  r = db.reverse(args.path)
  for f in r: output.write('%d\n' % f.id)

  if not r: return 1

  return 0
1361653
def _unstructure_seq(self, seq):
        """"""
        # We can reuse the sequence class, so tuples stay tuples.
        dispatch = self._unstructure_func.dispatch
        return seq.__class__(dispatch(e.__class__)(e) for e in seq)