File: sequence.py

package info (click to toggle)
python-pbcore 1.7.1%2Bgit20200430.a127b1e%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,404 kB
  • sloc: python: 23,243; xml: 2,504; makefile: 232; sh: 66
file content (34 lines) | stat: -rw-r--r-- 918 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# sequence.py: module of basic sequence methods
# Authors: Brett Bowman, David Alexander

__all__ = ["complement",
           "reverseComplement"]

import re

DNA_COMPLEMENT = str.maketrans('agcturyswkmbdhvnAGCTURYSWKMBDHV-N',
                               'tcgannnnnnnnnnnnTCGANNNNNNNNNNN-N')


def reverse(sequence):
    """Return the reverse of any sequence
    """
    return sequence[::-1]


def complement(sequence):
    """
    Return the complement of a sequence
    """
    if re.search('[^agcturyswkmbdhvnAGCTURYSWKMBDHVN-]', sequence):
        raise ValueError("Sequence contains invalid DNA characters - "
                         "only standard IUPAC nucleotide codes allowed")
    return sequence.translate(DNA_COMPLEMENT)


def reverseComplement(sequence):
    """
    Return the reverse-complement of a sequence
    NOTE: This only currently supports DNA
    """
    return complement(sequence)[::-1]