-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseqtransform.py
More file actions
32 lines (23 loc) · 863 Bytes
/
seqtransform.py
File metadata and controls
32 lines (23 loc) · 863 Bytes
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
IUPAC_DNA = 'AGRMHBSNWVDKYCT'
IUPAC_RNA = 'AGRMHBSNWVDKYCU'
# bytes translation tables can be used to translate str and bytes
DNA_TRANSLATION_TABLE = bytes.maketrans(
bytes(ord(c) for c in IUPAC_DNA+IUPAC_DNA.lower()),
bytes(ord(c) for c in IUPAC_DNA[::-1]+IUPAC_DNA[::-1].lower())
)
RNA_TRANSLATION_TABLE = bytes.maketrans(
bytes(ord(c) for c in IUPAC_RNA+IUPAC_RNA.lower()),
bytes(ord(c) for c in IUPAC_RNA[::-1]+IUPAC_RNA[::-1].lower())
)
def reverse (seq):
return seq[::-1]
def complement (seq, is_dna=True):
if is_dna:
return seq.translate(DNA_TRANSLATION_TABLE)
else:
return seq.translate(RNA_TRANSLATION_TABLE)
def reverse_complement (seq, is_dna=True):
if is_dna:
return seq[::-1].translate(DNA_TRANSLATION_TABLE)
else:
return seq[::-1].translate(RNA_TRANSLATION_TABLE)